Skip to content

Commit

Permalink
[GUI] move 'Start daemon' button to an InfoBar
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTumultuousUnicornOfDarkness committed Oct 8, 2024
1 parent e5acf29 commit 47ef0aa
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 9 deletions.
74 changes: 70 additions & 4 deletions data/cpu-x-gtk-3.12.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,72 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkInfoBar" id="daemoninfobar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="message-type">warning</property>
<property name="show-close-button">True</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="spacing">6</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="daemonbutton">
<property name="label">Start daemon</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="border-width">8</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="spacing">16</property>
<child>
<object class="GtkLabel" id="daemonlab">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Privileges are required to gather some information</property>
<property name="wrap">True</property>
<property name="ellipsize">end</property>
<property name="max-width-chars">30</property>
<property name="lines">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="header_notebook">
<property name="visible">True</property>
Expand Down Expand Up @@ -5748,7 +5814,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -5791,8 +5857,8 @@
</packing>
</child>
<child>
<object class="GtkButton" id="daemonbutton">
<property name="label">Start daemon</property>
<object class="GtkButton" id="closebutton">
<property name="label">Close</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
Expand All @@ -5808,7 +5874,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
Expand Down
33 changes: 28 additions & 5 deletions src/gui_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ void GtkData::get_widgets(Glib::RefPtr<Gtk::Builder> builder)
{
/* Common */
builder->get_widget("mainwindow", this->mainwindow);
builder->get_widget("daemoninfobar", this->daemoninfobar);
builder->get_widget("daemonbutton", this->daemonbutton);
builder->get_widget("labprgver", this->labprgver);
builder->get_widget("closebutton", this->closebutton);
builder->get_widget("header_notebook", this->notebook);

/* Settings */
Expand Down Expand Up @@ -430,12 +432,14 @@ void GtkData::set_all_labels()
notebook->set_current_page(Options::get_selected_page());
this->labprgver->set_text(this->data.about.about.version);
this->daemonbutton->set_label(_("Start daemon"));
this->daemonbutton->set_sensitive(false);
if(DAEMON_UP)
this->daemonbutton->set_tooltip_text(_("Connected to daemon"));
this->daemoninfobar->hide();
#ifndef FLATPAK
else if(WEXITSTATUS(pkcheck) > 2)
{
this->daemonbutton->set_sensitive(false);
this->daemonbutton->set_tooltip_text(_("No polkit authentication agent found"));
}
#endif /* !FLATPAK */
else
{
Expand Down Expand Up @@ -509,10 +513,17 @@ void GtkData::set_signals()
Options::set_selected_page(static_cast<TabNumber>(page_number));
});

/* Show settings window */
this->settingsbutton->signal_clicked().connect([this]
/* Handle daemon InfoBar buttons */
this->daemoninfobar->signal_response().connect([this](int response_id)
{
this->settingswindow->show();
switch(response_id)
{
case Gtk::ResponseType::RESPONSE_CLOSE:
this->daemoninfobar->hide();
break;
default:
break;
}
});

/* Start daemon and reload CPU-X */
Expand All @@ -533,6 +544,18 @@ void GtkData::set_signals()
}
});

/* Show settings window */
this->settingsbutton->signal_clicked().connect([this]
{
this->settingswindow->show();
});

/* Exit CPU-X */
this->closebutton->signal_clicked().connect([this]
{
app->quit();
});

EXT_TAB_CPU(this->data.cpu)->activetype->signal_changed().connect(sigc::mem_fun(*this, &GtkData::change_active_type));
EXT_TAB_CPU(this->data.cpu)->activecore->signal_changed().connect(sigc::mem_fun(*this, &GtkData::change_active_core));
EXT_TAB_CACHES(this->data.caches)->activetest->signal_changed().connect(sigc::mem_fun(*this, &GtkData::change_active_test));
Expand Down
3 changes: 3 additions & 0 deletions src/gui_gtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <gtkmm/builder.h>
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/infobar.h>
#include <gtkmm/label.h>
#include <gtkmm/drawingarea.h>
#include "data.hpp"
Expand Down Expand Up @@ -79,8 +80,10 @@ struct GtkData

/* Common */
Gtk::Window *mainwindow = nullptr;
Gtk::InfoBar *daemoninfobar = nullptr;
Gtk::Button *daemonbutton = nullptr;
Gtk::Label *labprgver = nullptr;
Gtk::Button *closebutton = nullptr;
Gtk::Notebook *notebook = nullptr;
sigc::connection refresh_handle;

Expand Down

0 comments on commit 47ef0aa

Please sign in to comment.