Skip to content

Commit

Permalink
Remove 'Compiler' label and rename 'Distribution' label in System tab
Browse files Browse the repository at this point in the history
Fix #293
  • Loading branch information
TheTumultuousUnicornOfDarkness committed Sep 17, 2023
1 parent acb2a0b commit 242380d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 105 deletions.
79 changes: 17 additions & 62 deletions data/cpu-x-gtk-3.12.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3184,49 +3184,21 @@
<property name="margin-end">6</property>
<property name="margin-bottom">6</property>
<child>
<!-- n-columns=2 n-rows=5 -->
<!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid" id="os_grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<child>
<object class="GtkAspectFrame" id="os_framkern">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkLabel" id="os_valkern">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="justify">center</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="width-chars">40</property>
<property name="single-line-mode">True</property>
<property name="max-width-chars">40</property>
<property name="lines">1</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkAspectFrame" id="os_framdistro">
<object class="GtkAspectFrame" id="os_framkernel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkLabel" id="os_valdistro">
<object class="GtkLabel" id="os_valkernel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
Expand All @@ -3246,15 +3218,15 @@
</packing>
</child>
<child>
<object class="GtkAspectFrame" id="os_framhost">
<object class="GtkAspectFrame" id="os_framname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkLabel" id="os_valhost">
<object class="GtkLabel" id="os_valname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
Expand All @@ -3270,19 +3242,19 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkAspectFrame" id="os_framcomp">
<object class="GtkAspectFrame" id="os_framhostname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkLabel" id="os_valcomp">
<object class="GtkLabel" id="os_valhostname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
Expand All @@ -3298,35 +3270,18 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="os_labkern">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-end">4</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="mnemonic-widget">os_valkern</property>
<property name="single-line-mode">True</property>
<property name="lines">1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="os_labdistro">
<object class="GtkLabel" id="os_labkernel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-end">4</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="mnemonic-widget">os_valdistro</property>
<property name="mnemonic-widget">os_valkernel</property>
<property name="single-line-mode">True</property>
<property name="lines">1</property>
</object>
Expand All @@ -3336,37 +3291,37 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="os_labhost">
<object class="GtkLabel" id="os_labname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-end">4</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="mnemonic-widget">os_valhost</property>
<property name="mnemonic-widget">os_valname</property>
<property name="single-line-mode">True</property>
<property name="lines">1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="os_labcomp">
<object class="GtkLabel" id="os_labhostname">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="margin-end">4</property>
<property name="margin-top">1</property>
<property name="margin-bottom">1</property>
<property name="mnemonic-widget">os_valcomp</property>
<property name="mnemonic-widget">os_valhostname</property>
<property name="single-line-mode">True</property>
<property name="lines">1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
Expand Down
29 changes: 13 additions & 16 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,16 +1689,10 @@ static int system_static(Data &data)
if(err)
MSG_ERRNO("%s", _("failed to identify running system"));
else
{
data.system.os.kernel.value = string_format("%s %s", name.sysname, name.release); /* Kernel label */
data.system.os.hostname.value = Options::get_issue() ? "sensitive data" : name.nodename; /* Hostname label */
}

/* Compiler label */
err += popen_to_str(data.system.os.compiler.value, "cc --version | head --lines=1");

#ifdef __linux__
/* Distribution label */
/* Name label */
std::string line;
std::ifstream stream("/etc/os-release");
std::regex regex("^PRETTY_NAME=\"(.*?)\"$");
Expand All @@ -1708,22 +1702,25 @@ static int system_static(Data &data)
{
if(std::regex_search(line, match, regex))
{
data.system.os.distribution.value = match[1].str();
data.system.os.name.value = match[1].str();
break;
}
}

/* Kernel label */
if(!err)
data.system.os.kernel.value = string_format("%s %s", name.sysname, name.release);

#else /* __linux__ */
char tmp[MAXSTR];
size_t len = sizeof(tmp);
if(!err)
{
/* Name label */
data.system.os.kernel.value = string_format("%s %s", name.sysname, name.release);

/* Overwrite Kernel label */
err += sysctlbyname("kern.osrelease", &tmp, &len, NULL, 0);
data.system.os.kernel.value = tmp;
/* Kernel label */
data.system.os.kernel.value = string_format("%s", name.version);
}

/* Distribution label */
err += sysctlbyname("kern.ostype", &tmp, &len, NULL, 0);
data.system.os.distribution.value = tmp;
#endif /* __linux__ */

return err;
Expand Down
3 changes: 1 addition & 2 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,10 @@ Data::System::OperatingSystem::OperatingSystem() : Frame(_("Operating System"))
std::ostream& operator<<(std::ostream& os, const Data::System::OperatingSystem& operatingsystem)
{
os << static_cast<const Frame&>(operatingsystem);
os << static_cast<const Label&>(operatingsystem.name);
os << static_cast<const Label&>(operatingsystem.kernel);
os << static_cast<const Label&>(operatingsystem.distribution);
os << static_cast<const Label&>(operatingsystem.hostname);
os << static_cast<const Label&>(operatingsystem.uptime);
os << static_cast<const Label&>(operatingsystem.compiler);
os << std::endl;
return os;
}
Expand Down
3 changes: 1 addition & 2 deletions src/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@ struct Data
{
struct OperatingSystem : public Frame
{
Label name {_("Name")};
Label kernel {_("Kernel")};
Label distribution {_("Distribution")};
Label hostname {_("Hostname")};
Label uptime {_("Uptime")};
Label compiler {_("Compiler")};

OperatingSystem();
friend std::ostream& operator<<(std::ostream& os, const OperatingSystem& operatingsystem);
Expand Down
14 changes: 6 additions & 8 deletions src/gui_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ void GtkData::get_widgets(Glib::RefPtr<Gtk::Builder> builder)
this->data.system.extend(new GtkData::ExtTabSystem(builder));
/* Operating System frame */
this->data.system.os.extend(new ExtFrame(builder, "os_lab"));
this->data.system.os.kernel. extend(new ExtLabel<Gtk::Label>(builder, "os_kern"));
this->data.system.os.distribution.extend(new ExtLabel<Gtk::Label>(builder, "os_distro"));
this->data.system.os.hostname. extend(new ExtLabel<Gtk::Label>(builder, "os_host"));
this->data.system.os.uptime. extend(new ExtLabel<Gtk::Label>(builder, "os_uptime"));
this->data.system.os.compiler. extend(new ExtLabel<Gtk::Label>(builder, "os_comp"));
this->data.system.os.name. extend(new ExtLabel<Gtk::Label>(builder, "os_name"));
this->data.system.os.kernel. extend(new ExtLabel<Gtk::Label>(builder, "os_kernel"));
this->data.system.os.hostname.extend(new ExtLabel<Gtk::Label>(builder, "os_hostname"));
this->data.system.os.uptime. extend(new ExtLabel<Gtk::Label>(builder, "os_uptime"));
/* Memory frame */
this->data.system.memory.extend(new ExtFrame(builder, "mem_lab"));
this->data.system.memory.used. extend(new ExtLabel<Gtk::Label>(builder, "mem_used"));
Expand Down Expand Up @@ -359,7 +358,7 @@ void GtkData::set_all_labels()
{
Gtk::Requisition minimum_size, natural_size;
const auto margin = 6;
const auto width_full = EXT_LABEL(this->data.system.os.compiler)->value->get_allocated_width();
const auto width_full = EXT_LABEL(this->data.system.os.hostname)->value->get_allocated_width();
const auto width_half = width_full - EXT_LABEL(this->data.system.memory.used)->value->get_allocated_width() - margin;
const int pkcheck = run_command("pkcheck --action-id org.freedesktop.policykit.exec --process %u > /dev/null 2>&1", getpid());

Expand Down Expand Up @@ -863,11 +862,10 @@ void GtkData::gtab_system()

/* Operating System frame */
set_frame_name(this->data.system.os);
set_label_name_and_value(this->data.system.os.name);
set_label_name_and_value(this->data.system.os.kernel);
set_label_name_and_value(this->data.system.os.distribution);
set_label_name_and_value(this->data.system.os.hostname);
set_label_name_and_value(this->data.system.os.uptime);
set_label_name_and_value(this->data.system.os.compiler);

/* Memory frame */
set_frame_name(this->data.system.memory);
Expand Down
29 changes: 14 additions & 15 deletions src/tui_ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,24 @@ static void draw_bar(WINDOW *win, int line, Pairs::Colors pair, bool start_left,
static void ntab_system(WINDOW *win, Data &data)
{
/* OS frame */
draw_frame(win, LINE_0, SizeInfo::start , LINE_6, SizeInfo::width - 1, data.system.os);
mvwprintw2c(win, LINE_1, SizeInfo::tb, "%13s", "%s", data.system.os.kernel);
mvwprintw2c(win, LINE_2, SizeInfo::tb, "%13s", "%s", data.system.os.distribution);
draw_frame(win, LINE_0, SizeInfo::start , LINE_5, SizeInfo::width - 1, data.system.os);
mvwprintw2c(win, LINE_1, SizeInfo::tb, "%13s", "%s", data.system.os.name);
mvwprintw2c(win, LINE_2, SizeInfo::tb, "%13s", "%s", data.system.os.kernel);
mvwprintw2c(win, LINE_3, SizeInfo::tb, "%13s", "%s", data.system.os.hostname);
mvwprintw2c(win, LINE_4, SizeInfo::tb, "%13s", "%s", data.system.os.uptime);
mvwprintw2c(win, LINE_5, SizeInfo::tb, "%13s", "%s", data.system.os.compiler);

/* Memory frame */
draw_frame(win, LINE_7, SizeInfo::start , LINE_13, SizeInfo::width - 1, data.system.memory);
mvwprintw2c(win, LINE_8, SizeInfo::tb, "%13s", "%s", data.system.memory.used);
draw_bar(win, LINE_8, Pairs::Colors::YELLOW_BAR_COLOR, true, data.system.memory.mem_used, data.system.memory.mem_total);
mvwprintw2c(win, LINE_9, SizeInfo::tb, "%13s", "%s", data.system.memory.buffers);
draw_bar(win, LINE_9, Pairs::Colors::BLUE_BAR_COLOR, false, data.system.memory.mem_buffers, data.system.memory.mem_total);
mvwprintw2c(win, LINE_10, SizeInfo::tb, "%13s", "%s", data.system.memory.cached);
draw_bar(win, LINE_10, Pairs::Colors::MAGENTA_BAR_COLOR, false, data.system.memory.mem_cached, data.system.memory.mem_total);
mvwprintw2c(win, LINE_11, SizeInfo::tb, "%13s", "%s", data.system.memory.free);
draw_bar(win, LINE_11, Pairs::Colors::GREEN_BAR_COLOR, false, data.system.memory.mem_free, data.system.memory.mem_total);
mvwprintw2c(win, LINE_12, SizeInfo::tb, "%13s", "%s", data.system.memory.swap);
draw_bar(win, LINE_12, Pairs::Colors::RED_BAR_COLOR, true, data.system.memory.swap_used, data.system.memory.swap_total);
draw_frame(win, LINE_6, SizeInfo::start , LINE_12, SizeInfo::width - 1, data.system.memory);
mvwprintw2c(win, LINE_7, SizeInfo::tb, "%13s", "%s", data.system.memory.used);
draw_bar(win, LINE_7, Pairs::Colors::YELLOW_BAR_COLOR, true, data.system.memory.mem_used, data.system.memory.mem_total);
mvwprintw2c(win, LINE_8, SizeInfo::tb, "%13s", "%s", data.system.memory.buffers);
draw_bar(win, LINE_8, Pairs::Colors::BLUE_BAR_COLOR, false, data.system.memory.mem_buffers, data.system.memory.mem_total);
mvwprintw2c(win, LINE_9, SizeInfo::tb, "%13s", "%s", data.system.memory.cached);
draw_bar(win, LINE_9, Pairs::Colors::MAGENTA_BAR_COLOR, false, data.system.memory.mem_cached, data.system.memory.mem_total);
mvwprintw2c(win, LINE_10, SizeInfo::tb, "%13s", "%s", data.system.memory.free);
draw_bar(win, LINE_10, Pairs::Colors::GREEN_BAR_COLOR, false, data.system.memory.mem_free, data.system.memory.mem_total);
mvwprintw2c(win, LINE_11, SizeInfo::tb, "%13s", "%s", data.system.memory.swap);
draw_bar(win, LINE_11, Pairs::Colors::RED_BAR_COLOR, true, data.system.memory.swap_used, data.system.memory.swap_total);
}

/* Graphics tab */
Expand Down

0 comments on commit 242380d

Please sign in to comment.