summaryrefslogtreecommitdiff
path: root/src/sysinfo.cpp
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-12-18 00:23:57 +0100
committerinfirit <[email protected]>2014-12-18 00:23:57 +0100
commit12975909c589880030db6125ad6dcbea889edcdc (patch)
treefc374a8a3b855b5024d09f9edb2e47ca755cb7ac /src/sysinfo.cpp
parent0dea7ab1931fb33f35eceab66dffcd56f4550f68 (diff)
downloadmate-system-monitor-12975909c589880030db6125ad6dcbea889edcdc.tar.bz2
mate-system-monitor-12975909c589880030db6125ad6dcbea889edcdc.tar.xz
Make indentation uniform across source files
No more tabs, 4 spaces instead. And remove trailing whitespace.
Diffstat (limited to 'src/sysinfo.cpp')
-rw-r--r--src/sysinfo.cpp1110
1 files changed, 555 insertions, 555 deletions
diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp
index c24acb1..70275eb 100644
--- a/src/sysinfo.cpp
+++ b/src/sysinfo.cpp
@@ -39,439 +39,439 @@ using std::vector;
namespace {
- class SysInfo
- {
- public:
- string hostname;
- string distro_name;
- string distro_release;
- string kernel;
- string mate_version;
- guint64 memory_bytes;
- guint64 free_space_bytes;
-
- guint n_processors;
- vector<string> processors;
-
-
- SysInfo()
+ class SysInfo
{
- this->load_processors_info();
- this->load_memory_info();
- this->load_disk_info();
- this->load_uname_info();
- this->load_mate_version();
- }
+ public:
+ string hostname;
+ string distro_name;
+ string distro_release;
+ string kernel;
+ string mate_version;
+ guint64 memory_bytes;
+ guint64 free_space_bytes;
+
+ guint n_processors;
+ vector<string> processors;
+
+
+ SysInfo()
+ {
+ this->load_processors_info();
+ this->load_memory_info();
+ this->load_disk_info();
+ this->load_uname_info();
+ this->load_mate_version();
+ }
- virtual ~SysInfo()
- { }
+ virtual ~SysInfo()
+ { }
- virtual void set_distro_labels(GtkWidget* name, GtkWidget* release)
- {
- g_object_set(G_OBJECT(name),
- "label",
- ("<big><big><b>" + this->distro_name + "</b></big></big>").c_str(),
- NULL);
+ virtual void set_distro_labels(GtkWidget* name, GtkWidget* release)
+ {
+ g_object_set(G_OBJECT(name),
+ "label",
+ ("<big><big><b>" + this->distro_name + "</b></big></big>").c_str(),
+ NULL);
- char* markup = g_strdup_printf(_("Release %s"), this->distro_release.c_str());
+ char* markup = g_strdup_printf(_("Release %s"), this->distro_release.c_str());
- g_object_set(G_OBJECT(release),
- "label",
- markup,
- NULL);
+ g_object_set(G_OBJECT(release),
+ "label",
+ markup,
+ NULL);
- g_free(markup);
- }
+ g_free(markup);
+ }
- static string system()
- {
- return uname().sysname;
- }
+ static string system()
+ {
+ return uname().sysname;
+ }
- private:
+ private:
- void load_memory_info()
- {
- glibtop_mem mem;
+ void load_memory_info()
+ {
+ glibtop_mem mem;
- glibtop_get_mem(&mem);
- this->memory_bytes = mem.total;
- }
+ glibtop_get_mem(&mem);
+ this->memory_bytes = mem.total;
+ }
- void load_processors_info()
- {
- const glibtop_sysinfo *info = glibtop_get_sysinfo();
-
- for (guint i = 0; i != info->ncpu; ++i) {
- const char * const keys[] = { "model name", "cpu", "Processor" };
- gchar *model = 0, *clock = 0;
- guint last;
-
- for (guint j = 0; !model && j != G_N_ELEMENTS(keys); ++j) {
- last = j;
- model = static_cast<char*>(g_hash_table_lookup(info->cpuinfo[i].values,
- keys[j]));
- }
-
- if (!model)
- continue;
-
- if (!strcmp(keys[last], "cpu"))
- clock = static_cast<char*>(g_hash_table_lookup(info->cpuinfo[i].values,
- "clock"));
- if (clock)
- this->processors.push_back(string(model) + " " + string(clock));
- else
- this->processors.push_back(model);
- }
- }
+ void load_processors_info()
+ {
+ const glibtop_sysinfo *info = glibtop_get_sysinfo();
+
+ for (guint i = 0; i != info->ncpu; ++i) {
+ const char * const keys[] = { "model name", "cpu", "Processor" };
+ gchar *model = 0, *clock = 0;
+ guint last;
+
+ for (guint j = 0; !model && j != G_N_ELEMENTS(keys); ++j) {
+ last = j;
+ model = static_cast<char*>(g_hash_table_lookup(info->cpuinfo[i].values,
+ keys[j]));
+ }
+
+ if (!model)
+ continue;
+
+ if (!strcmp(keys[last], "cpu"))
+ clock = static_cast<char*>(g_hash_table_lookup(info->cpuinfo[i].values,
+ "clock"));
+ if (clock)
+ this->processors.push_back(string(model) + " " + string(clock));
+ else
+ this->processors.push_back(model);
+ }
+ }
- void load_disk_info()
- {
- glibtop_mountentry *entries;
- glibtop_mountlist mountlist;
+ void load_disk_info()
+ {
+ glibtop_mountentry *entries;
+ glibtop_mountlist mountlist;
- entries = glibtop_get_mountlist(&mountlist, 0);
+ entries = glibtop_get_mountlist(&mountlist, 0);
- this->free_space_bytes = 0;
+ this->free_space_bytes = 0;
- for (guint i = 0; i != mountlist.number; ++i) {
+ for (guint i = 0; i != mountlist.number; ++i) {
- if (string(entries[i].devname).find("/dev/") != 0)
- continue;
+ if (string(entries[i].devname).find("/dev/") != 0)
+ continue;
- if (string(entries[i].mountdir).find("/media/") == 0)
- continue;
+ if (string(entries[i].mountdir).find("/media/") == 0)
+ continue;
- glibtop_fsusage usage;
- glibtop_get_fsusage(&usage, entries[i].mountdir);
- this->free_space_bytes += usage.bavail * usage.block_size;
- }
+ glibtop_fsusage usage;
+ glibtop_get_fsusage(&usage, entries[i].mountdir);
+ this->free_space_bytes += usage.bavail * usage.block_size;
+ }
- g_free(entries);
- }
+ g_free(entries);
+ }
- static const struct utsname & uname()
- {
- static struct utsname name;
+ static const struct utsname & uname()
+ {
+ static struct utsname name;
- if (!name.sysname[0]) {
- ::uname(&name);
- }
+ if (!name.sysname[0]) {
+ ::uname(&name);
+ }
- return name;
- }
+ return name;
+ }
- void load_uname_info()
- {
- this->hostname = uname().nodename;
- this->kernel = string(uname().sysname) + ' ' + uname().release;
- }
+ void load_uname_info()
+ {
+ this->hostname = uname().nodename;
+ this->kernel = string(uname().sysname) + ' ' + uname().release;
+ }
- void load_mate_version()
- {
- xmlDocPtr document;
- xmlXPathContextPtr context;
- const string nodes[3] = { "string(/mate-version/platform)",
- "string(/mate-version/minor)",
- "string(/mate-version/micro)" };
- string values[3];
-
- if (not (document = xmlParseFile(DATADIR "/mate-about/mate-version.xml")))
- return;
-
- if (not (context = xmlXPathNewContext(document)))
- return;
-
- for (size_t i = 0; i != 3; ++i)
- {
- xmlXPathObjectPtr xpath;
- xpath = xmlXPathEvalExpression(BAD_CAST nodes[i].c_str(), context);
-
- if (xpath and xpath->type == XPATH_STRING)
- values[i] = reinterpret_cast<const char*>(xpath->stringval);
-
- xmlXPathFreeObject(xpath);
- }
-
- xmlXPathFreeContext(context);
- xmlFreeDoc(document);
-
- this->mate_version = values[0] + '.' + values[1] + '.' + values[2];
- }
- };
+ void load_mate_version()
+ {
+ xmlDocPtr document;
+ xmlXPathContextPtr context;
+ const string nodes[3] = { "string(/mate-version/platform)",
+ "string(/mate-version/minor)",
+ "string(/mate-version/micro)" };
+ string values[3];
+ if (not (document = xmlParseFile(DATADIR "/mate-about/mate-version.xml")))
+ return;
+ if (not (context = xmlXPathNewContext(document)))
+ return;
- class SolarisSysInfo
- : public SysInfo
- {
- public:
- SolarisSysInfo()
- {
- this->load_solaris_info();
- }
+ for (size_t i = 0; i != 3; ++i)
+ {
+ xmlXPathObjectPtr xpath;
+ xpath = xmlXPathEvalExpression(BAD_CAST nodes[i].c_str(), context);
- private:
- void load_solaris_info()
- {
- this->distro_name = "Solaris";
+ if (xpath and xpath->type == XPATH_STRING)
+ values[i] = reinterpret_cast<const char*>(xpath->stringval);
- std::ifstream input("/etc/release");
+ xmlXPathFreeObject(xpath);
+ }
- if (input)
- std::getline(input, this->distro_release);
- }
- };
+ xmlXPathFreeContext(context);
+ xmlFreeDoc(document);
+
+ this->mate_version = values[0] + '.' + values[1] + '.' + values[2];
+ }
+ };
- class LSBSysInfo
- : public SysInfo
- {
- public:
- LSBSysInfo()
- : re(Glib::Regex::create("^.+?:\\s*(.+)\\s*$"))
- {
- // start();
- }
- virtual void set_distro_labels(GtkWidget* name, GtkWidget* release)
+ class SolarisSysInfo
+ : public SysInfo
{
- this->name = name;
- this->release = release;
+ public:
+ SolarisSysInfo()
+ {
+ this->load_solaris_info();
+ }
- this->start();
- }
+ private:
+ void load_solaris_info()
+ {
+ this->distro_name = "Solaris";
+ std::ifstream input("/etc/release");
- private:
+ if (input)
+ std::getline(input, this->distro_release);
+ }
+ };
- sigc::connection child_watch;
- int lsb_fd;
- GtkWidget* name;
- GtkWidget* release;
- void strip_description(string &s) const
+ class LSBSysInfo
+ : public SysInfo
{
- const GRegexMatchFlags flags = static_cast<GRegexMatchFlags>(0);
- GMatchInfo* info = 0;
+ public:
+ LSBSysInfo()
+ : re(Glib::Regex::create("^.+?:\\s*(.+)\\s*$"))
+ {
+ // start();
+ }
- if (g_regex_match(this->re->gobj(), s.c_str(), flags, &info)) {
- s = make_string(g_match_info_fetch(info, 1));
- g_match_info_free(info);
- }
- }
+ virtual void set_distro_labels(GtkWidget* name, GtkWidget* release)
+ {
+ this->name = name;
+ this->release = release;
- std::istream& get_value(std::istream &is, string &s) const
- {
- if (std::getline(is, s))
- this->strip_description(s);
- return is;
- }
+ this->start();
+ }
- void read_lsb(Glib::Pid pid, int status)
- {
- this->child_watch.disconnect();
+ private:
- if (!WIFEXITED(status) or WEXITSTATUS(status) != 0) {
- g_error("Child %d failed with status %d", int(pid), status);
- return;
- }
+ sigc::connection child_watch;
+ int lsb_fd;
+ GtkWidget* name;
+ GtkWidget* release;
- Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_fd(this->lsb_fd);
- Glib::ustring content;
+ void strip_description(string &s) const
+ {
+ const GRegexMatchFlags flags = static_cast<GRegexMatchFlags>(0);
+ GMatchInfo* info = 0;
- while (channel->read_to_end(content) == Glib::IO_STATUS_AGAIN)
- ;
+ if (g_regex_match(this->re->gobj(), s.c_str(), flags, &info)) {
+ s = make_string(g_match_info_fetch(info, 1));
+ g_match_info_free(info);
+ }
+ }
- channel->close();
- Glib::spawn_close_pid(pid);
+ std::istream& get_value(std::istream &is, string &s) const
+ {
+ if (std::getline(is, s))
+ this->strip_description(s);
+ return is;
+ }
- procman_debug("lsb_release output = '%s'", content.c_str());
- string release, codename;
- std::istringstream input(content);
+ void read_lsb(Glib::Pid pid, int status)
+ {
+ this->child_watch.disconnect();
- this->get_value(input, this->distro_name)
- and this->get_value(input, release)
- and this->get_value(input, codename);
+ if (!WIFEXITED(status) or WEXITSTATUS(status) != 0) {
+ g_error("Child %d failed with status %d", int(pid), status);
+ return;
+ }
- this->distro_release = release;
- if (codename != "" && codename != "n/a")
- this->distro_release += " (" + codename + ')';
+ Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_fd(this->lsb_fd);
+ Glib::ustring content;
- this->SysInfo::set_distro_labels(this->name, this->release);
- }
+ while (channel->read_to_end(content) == Glib::IO_STATUS_AGAIN)
+ ;
+ channel->close();
+ Glib::spawn_close_pid(pid);
- void start()
- {
- std::vector<string> argv(2);
- argv[0] = "lsb_release";
- argv[1] = "-irc";
-
- Glib::SpawnFlags flags = Glib::SPAWN_DO_NOT_REAP_CHILD
- | Glib::SPAWN_SEARCH_PATH
- | Glib::SPAWN_STDERR_TO_DEV_NULL;
-
- Glib::Pid child;
-
- try {
- Glib::spawn_async_with_pipes("/", // wd
- argv,
- flags,
- sigc::slot<void>(), // child setup
- &child,
- 0, // stdin
- &this->lsb_fd); // stdout
- } catch (Glib::SpawnError &e) {
- g_error("g_spawn_async_with_pipes error: %s", e.what().c_str());
- return;
- }
-
- sigc::slot<void,GPid, int> slot = sigc::mem_fun(this, &LSBSysInfo::read_lsb);
- this->child_watch = Glib::signal_child_watch().connect(slot, child);
- }
+ procman_debug("lsb_release output = '%s'", content.c_str());
+ string release, codename;
+ std::istringstream input(content);
- void sync_lsb_release()
- {
- char *out= 0;
- GError *error = 0;
- int status;
-
- if (g_spawn_command_line_sync("lsb_release -irc",
- &out,
- 0,
- &status,
- &error)) {
- string release, codename;
- if (!error and WIFEXITED(status) and WEXITSTATUS(status) == 0) {
- std::istringstream input(out);
- this->get_value(input, this->distro_name)
- and this->get_value(input, release)
- and this->get_value(input, codename);
- this->distro_release = release;
- if (codename != "" && codename != "n/a")
- this->distro_release += " (" + codename + ')';
- }
- }
-
- if (error)
- g_error_free(error);
-
- g_free(out);
- }
+ this->get_value(input, this->distro_name)
+ and this->get_value(input, release)
+ and this->get_value(input, codename);
- private:
- Glib::RefPtr<Glib::Regex> re;
- };
+ this->distro_release = release;
+ if (codename != "" && codename != "n/a")
+ this->distro_release += " (" + codename + ')';
+ this->SysInfo::set_distro_labels(this->name, this->release);
+ }
- class NetBSDSysInfo
- : public SysInfo
- {
- public:
- NetBSDSysInfo()
- {
- this->load_netbsd_info();
- }
- private:
- void load_netbsd_info()
- {
- this->distro_name = "NetBSD";
+ void start()
+ {
+ std::vector<string> argv(2);
+ argv[0] = "lsb_release";
+ argv[1] = "-irc";
+
+ Glib::SpawnFlags flags = Glib::SPAWN_DO_NOT_REAP_CHILD
+ | Glib::SPAWN_SEARCH_PATH
+ | Glib::SPAWN_STDERR_TO_DEV_NULL;
+
+ Glib::Pid child;
+
+ try {
+ Glib::spawn_async_with_pipes("/", // wd
+ argv,
+ flags,
+ sigc::slot<void>(), // child setup
+ &child,
+ 0, // stdin
+ &this->lsb_fd); // stdout
+ } catch (Glib::SpawnError &e) {
+ g_error("g_spawn_async_with_pipes error: %s", e.what().c_str());
+ return;
+ }
+
+ sigc::slot<void,GPid, int> slot = sigc::mem_fun(this, &LSBSysInfo::read_lsb);
+ this->child_watch = Glib::signal_child_watch().connect(slot, child);
+ }
- std::ifstream input("/etc/release");
- if (input)
- std::getline(input, this->distro_release);
- }
- };
+ void sync_lsb_release()
+ {
+ char *out= 0;
+ GError *error = 0;
+ int status;
+
+ if (g_spawn_command_line_sync("lsb_release -irc",
+ &out,
+ 0,
+ &status,
+ &error)) {
+ string release, codename;
+ if (!error and WIFEXITED(status) and WEXITSTATUS(status) == 0) {
+ std::istringstream input(out);
+ this->get_value(input, this->distro_name)
+ and this->get_value(input, release)
+ and this->get_value(input, codename);
+ this->distro_release = release;
+ if (codename != "" && codename != "n/a")
+ this->distro_release += " (" + codename + ')';
+ }
+ }
+
+ if (error)
+ g_error_free(error);
+
+ g_free(out);
+ }
+ private:
+ Glib::RefPtr<Glib::Regex> re;
+ };
- class GenericSysInfo
- : public SysInfo
- {
- public:
- GenericSysInfo()
- {
- this->load_os_release();
- }
- private:
- void load_os_release()
+ class NetBSDSysInfo
+ : public SysInfo
{
- std::ifstream input("/etc/os-release");
-
- if (input) {
- while (!input.eof()) {
- string s;
- int len;
- std::getline(input, s);
- if (s.find("NAME=") == 0) {
- len = strlen("NAME=");
- this->distro_name = s.substr(len);
- } else if (s.find("VERSION=") == 0) {
- len = strlen("VERSION=");
- // also strip the surrounding quotes
- this->distro_release = s.substr(len + 1, s.size() - len - 2);
- }
- }
- }
- }
- };
+ public:
+ NetBSDSysInfo()
+ {
+ this->load_netbsd_info();
+ }
+ private:
+ void load_netbsd_info()
+ {
+ this->distro_name = "NetBSD";
- class OpenBSDSysInfo
- : public SysInfo
- {
- public:
- OpenBSDSysInfo()
+ std::ifstream input("/etc/release");
+
+ if (input)
+ std::getline(input, this->distro_release);
+ }
+ };
+
+
+ class GenericSysInfo
+ : public SysInfo
{
- this->load_openbsd_info();
- }
+ public:
+ GenericSysInfo()
+ {
+ this->load_os_release();
+ }
- private:
- void load_openbsd_info()
+ private:
+ void load_os_release()
+ {
+ std::ifstream input("/etc/os-release");
+
+ if (input) {
+ while (!input.eof()) {
+ string s;
+ int len;
+ std::getline(input, s);
+ if (s.find("NAME=") == 0) {
+ len = strlen("NAME=");
+ this->distro_name = s.substr(len);
+ } else if (s.find("VERSION=") == 0) {
+ len = strlen("VERSION=");
+ // also strip the surrounding quotes
+ this->distro_release = s.substr(len + 1, s.size() - len - 2);
+ }
+ }
+ }
+ }
+ };
+
+
+ class OpenBSDSysInfo
+ : public SysInfo
{
- this->distro_name = "OpenBSD";
- this->distro_release = this->kernel;
+ public:
+ OpenBSDSysInfo()
+ {
+ this->load_openbsd_info();
+ }
- std::ifstream input("/etc/motd");
+ private:
+ void load_openbsd_info()
+ {
+ this->distro_name = "OpenBSD";
+ this->distro_release = this->kernel;
- if (input)
- std::getline(input, this->kernel);
- }
- };
+ std::ifstream input("/etc/motd");
- SysInfo* get_sysinfo()
- {
- if (g_file_test ("/etc/os-release", G_FILE_TEST_EXISTS)) {
- return new GenericSysInfo;
- }
- else if (char *p = g_find_program_in_path("lsb_release")) {
- g_free(p);
- return new LSBSysInfo;
- }
- else if (SysInfo::system() == "SunOS") {
- return new SolarisSysInfo;
- }
- else if (SysInfo::system() == "NetBSD") {
- return new NetBSDSysInfo;
- }
- else if (SysInfo::system() == "OpenBSD") {
- return new OpenBSDSysInfo;
- }
+ if (input)
+ std::getline(input, this->kernel);
+ }
+ };
+
+ SysInfo* get_sysinfo()
+ {
+ if (g_file_test ("/etc/os-release", G_FILE_TEST_EXISTS)) {
+ return new GenericSysInfo;
+ }
+ else if (char *p = g_find_program_in_path("lsb_release")) {
+ g_free(p);
+ return new LSBSysInfo;
+ }
+ else if (SysInfo::system() == "SunOS") {
+ return new SolarisSysInfo;
+ }
+ else if (SysInfo::system() == "NetBSD") {
+ return new NetBSDSysInfo;
+ }
+ else if (SysInfo::system() == "OpenBSD") {
+ return new OpenBSDSysInfo;
+ }
- return new SysInfo;
- }
+ return new SysInfo;
+ }
}
@@ -487,256 +487,256 @@ static gboolean sysinfo_logo_draw (GtkWidget *widget, cairo_t *context, gpointer
static gboolean sysinfo_logo_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data_ptr)
#endif
{
- GtkAllocation allocation;
- GtkStyle *style;
- cairo_t *cr;
- cairo_pattern_t *cp;
-
- cr = gdk_cairo_create(gtk_widget_get_window(widget));
-
- gtk_widget_get_allocation (widget, &allocation);
- cairo_translate(cr, allocation.x, allocation.y);
-
- cairo_move_to(cr, X_PAD + RADIUS, Y_PAD);
- cairo_line_to(cr, X_PAD + LOGO_W - RADIUS, Y_PAD);
- cairo_arc(cr, X_PAD + LOGO_W - RADIUS, Y_PAD + RADIUS, RADIUS, -0.5 * M_PI, 0);
- cairo_line_to(cr, X_PAD + LOGO_W, Y_PAD + LOGO_H - RADIUS);
- cairo_arc(cr, X_PAD + LOGO_W - RADIUS, Y_PAD + LOGO_H - RADIUS, RADIUS, 0, 0.5 * M_PI);
- cairo_line_to(cr, X_PAD + RADIUS, Y_PAD + LOGO_H);
- cairo_arc(cr, X_PAD + RADIUS, Y_PAD + LOGO_H - RADIUS, RADIUS, 0.5 * M_PI, -1.0 * M_PI);
- cairo_line_to(cr, X_PAD, Y_PAD + RADIUS);
- cairo_arc(cr, X_PAD + RADIUS, Y_PAD + RADIUS, RADIUS, -1.0 * M_PI, -0.5 * M_PI);
-
- cp = cairo_pattern_create_linear(0, Y_PAD, 0, Y_PAD + LOGO_H);
- style = gtk_widget_get_style (widget);
- cairo_pattern_add_color_stop_rgba(cp, 0.0,
- style->base[GTK_STATE_SELECTED].red / 65535.0,
- style->base[GTK_STATE_SELECTED].green / 65535.0,
- style->base[GTK_STATE_SELECTED].blue / 65535.0,
- 1.0);
+ GtkAllocation allocation;
+ GtkStyle *style;
+ cairo_t *cr;
+ cairo_pattern_t *cp;
+
+ cr = gdk_cairo_create(gtk_widget_get_window(widget));
+
+ gtk_widget_get_allocation (widget, &allocation);
+ cairo_translate(cr, allocation.x, allocation.y);
+
+ cairo_move_to(cr, X_PAD + RADIUS, Y_PAD);
+ cairo_line_to(cr, X_PAD + LOGO_W - RADIUS, Y_PAD);
+ cairo_arc(cr, X_PAD + LOGO_W - RADIUS, Y_PAD + RADIUS, RADIUS, -0.5 * M_PI, 0);
+ cairo_line_to(cr, X_PAD + LOGO_W, Y_PAD + LOGO_H - RADIUS);
+ cairo_arc(cr, X_PAD + LOGO_W - RADIUS, Y_PAD + LOGO_H - RADIUS, RADIUS, 0, 0.5 * M_PI);
+ cairo_line_to(cr, X_PAD + RADIUS, Y_PAD + LOGO_H);
+ cairo_arc(cr, X_PAD + RADIUS, Y_PAD + LOGO_H - RADIUS, RADIUS, 0.5 * M_PI, -1.0 * M_PI);
+ cairo_line_to(cr, X_PAD, Y_PAD + RADIUS);
+ cairo_arc(cr, X_PAD + RADIUS, Y_PAD + RADIUS, RADIUS, -1.0 * M_PI, -0.5 * M_PI);
+
+ cp = cairo_pattern_create_linear(0, Y_PAD, 0, Y_PAD + LOGO_H);
+ style = gtk_widget_get_style (widget);
+ cairo_pattern_add_color_stop_rgba(cp, 0.0,
+ style->base[GTK_STATE_SELECTED].red / 65535.0,
+ style->base[GTK_STATE_SELECTED].green / 65535.0,
+ style->base[GTK_STATE_SELECTED].blue / 65535.0,
+ 1.0);
cairo_pattern_add_color_stop_rgba(cp, 1.0,
- style->base[GTK_STATE_SELECTED].red / 65535.0,
- style->base[GTK_STATE_SELECTED].green / 65535.0,
- style->base[GTK_STATE_SELECTED].blue / 65535.0,
- 0.0);
- cairo_set_source(cr, cp);
- cairo_fill(cr);
+ style->base[GTK_STATE_SELECTED].red / 65535.0,
+ style->base[GTK_STATE_SELECTED].green / 65535.0,
+ style->base[GTK_STATE_SELECTED].blue / 65535.0,
+ 0.0);
+ cairo_set_source(cr, cp);
+ cairo_fill(cr);
- cairo_pattern_destroy(cp);
- cairo_destroy(cr);
+ cairo_pattern_destroy(cp);
+ cairo_destroy(cr);
- return FALSE;
+ return FALSE;
}
static GtkWidget*
add_section(GtkBox *vbox , const char * title, int num_row, int num_col, GtkWidget **out_frame)
{
- GtkWidget *table;
-
- GtkWidget *frame = gtk_frame_new(title);
- gtk_frame_set_label_align(GTK_FRAME(frame), 0.0, 0.5);
- gtk_label_set_use_markup(
- GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(frame))),
- TRUE
- );
- gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
-
- GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
- gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 12, 0);
- gtk_container_add(GTK_CONTAINER(frame), alignment);
-
- table = gtk_table_new(num_row, num_col, FALSE);
- gtk_table_set_row_spacings(GTK_TABLE(table), 6);
- gtk_table_set_col_spacings(GTK_TABLE(table), 6);
- gtk_container_set_border_width(GTK_CONTAINER(table), 6);
- gtk_container_add(GTK_CONTAINER(alignment), table);
-
- if(out_frame)
- *out_frame = frame;
-
- return table;
+ GtkWidget *table;
+
+ GtkWidget *frame = gtk_frame_new(title);
+ gtk_frame_set_label_align(GTK_FRAME(frame), 0.0, 0.5);
+ gtk_label_set_use_markup(
+ GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(frame))),
+ TRUE
+ );
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
+
+ GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
+ gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, 12, 0);
+ gtk_container_add(GTK_CONTAINER(frame), alignment);
+
+ table = gtk_table_new(num_row, num_col, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+ gtk_container_set_border_width(GTK_CONTAINER(table), 6);
+ gtk_container_add(GTK_CONTAINER(alignment), table);
+
+ if(out_frame)
+ *out_frame = frame;
+
+ return table;
}
-static GtkWidget*
+static GtkWidget*
add_row(GtkTable * table, const char * label, const char * value, int row)
{
- GtkWidget *header = gtk_label_new(label);
- gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
- gtk_table_attach(
- table, header,
- 0, 1, row, row + 1,
- GTK_FILL, GTK_FILL, 0, 0
- );
-
- GtkWidget *label_widget = gtk_label_new(value);
- gtk_misc_set_alignment(GTK_MISC(label_widget), 0.0, 0.5);
- gtk_table_attach(
- table, label_widget,
- 1, 2, row, row + 1,
- GTK_FILL, GTK_FILL, 0, 0
- );
- return label_widget;
+ GtkWidget *header = gtk_label_new(label);
+ gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
+ gtk_table_attach(
+ table, header,
+ 0, 1, row, row + 1,
+ GTK_FILL, GTK_FILL, 0, 0
+ );
+
+ GtkWidget *label_widget = gtk_label_new(value);
+ gtk_misc_set_alignment(GTK_MISC(label_widget), 0.0, 0.5);
+ gtk_table_attach(
+ table, label_widget,
+ 1, 2, row, row + 1,
+ GTK_FILL, GTK_FILL, 0, 0
+ );
+ return label_widget;
}
static GtkWidget *
procman_create_sysinfo_view(void)
{
- GtkWidget *hbox;
- GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
- SysInfo *data = get_sysinfo();;
+ SysInfo *data = get_sysinfo();;
- GtkWidget * logo;
+ GtkWidget * logo;
- GtkWidget *distro_frame;
- GtkWidget *distro_release_label;
- GtkWidget *distro_table;
+ GtkWidget *distro_frame;
+ GtkWidget *distro_release_label;
+ GtkWidget *distro_table;
- GtkWidget *hardware_table;
- GtkWidget *disk_space_table;
+ GtkWidget *hardware_table;
+ GtkWidget *disk_space_table;
- GtkWidget *header;
+ GtkWidget *header;
- gchar *markup;
+ gchar *markup;
- hbox = gtk_hbox_new(FALSE, 12);
- gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
+ hbox = gtk_hbox_new(FALSE, 12);
+ gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
- /* left-side logo */
+ /* left-side logo */
- logo = gtk_image_new_from_file(DATADIR "/pixmaps/mate-system-monitor/side.png");
- gtk_misc_set_alignment(GTK_MISC(logo), 0.5, 0.0);
- gtk_misc_set_padding(GTK_MISC(logo), 5, 12);
- gtk_box_pack_start(GTK_BOX(hbox), logo, FALSE, FALSE, 0);
+ logo = gtk_image_new_from_file(DATADIR "/pixmaps/mate-system-monitor/side.png");
+ gtk_misc_set_alignment(GTK_MISC(logo), 0.5, 0.0);
+ gtk_misc_set_padding(GTK_MISC(logo), 5, 12);
+ gtk_box_pack_start(GTK_BOX(hbox), logo, FALSE, FALSE, 0);
#if GTK_CHECK_VERSION(3,0,0)
- g_signal_connect(G_OBJECT(logo), "draw", G_CALLBACK(sysinfo_logo_draw), NULL);
+ g_signal_connect(G_OBJECT(logo), "draw", G_CALLBACK(sysinfo_logo_draw), NULL);
#else
- g_signal_connect(G_OBJECT(logo), "expose-event", G_CALLBACK(sysinfo_logo_expose), NULL);
+ g_signal_connect(G_OBJECT(logo), "expose-event", G_CALLBACK(sysinfo_logo_expose), NULL);
#endif
- vbox = gtk_vbox_new(FALSE, 12);
- gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
- gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
-
- // hostname
-
- markup = g_strdup_printf("<big><big><b><u>%s</u></b></big></big>",
- data->hostname.c_str());
- GtkWidget *hostname_frame = gtk_frame_new(markup);
- g_free(markup);
- gtk_frame_set_label_align(GTK_FRAME(hostname_frame), 0.0, 0.5);
- gtk_label_set_use_markup(
- GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(hostname_frame))),
- TRUE
- );
- gtk_frame_set_shadow_type(GTK_FRAME(hostname_frame), GTK_SHADOW_NONE);
- gtk_box_pack_start(GTK_BOX(vbox), hostname_frame, FALSE, FALSE, 0);
-
-
- /* distro section */
-
- unsigned table_size = 2;
- if (data->mate_version != "")
- table_size++;
- distro_table = add_section(GTK_BOX(vbox), "???", table_size, 1, &distro_frame);
-
- unsigned table_count = 0;
-
- distro_release_label = gtk_label_new("???");
- gtk_misc_set_alignment(GTK_MISC(distro_release_label), 0.0, 0.5);
- gtk_table_attach(
- GTK_TABLE(distro_table), distro_release_label,
- 0, 1, table_count, table_count+1,
- GTK_FILL, GTK_FILL, 0, 0
- );
- table_count++;
- data->set_distro_labels(gtk_frame_get_label_widget(GTK_FRAME(distro_frame)), distro_release_label);
-
- markup = g_strdup_printf(_("Kernel %s"), data->kernel.c_str());
- header = gtk_label_new(markup);
- g_free(markup);
- gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
- gtk_table_attach(
- GTK_TABLE(distro_table), header,
- 0, 1, table_count, table_count + 1,
- GTK_FILL, GTK_FILL, 0, 0
- );
- table_count++;
-
- if (data->mate_version != "")
+ vbox = gtk_vbox_new(FALSE, 12);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
+ gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
+
+ // hostname
+
+ markup = g_strdup_printf("<big><big><b><u>%s</u></b></big></big>",
+ data->hostname.c_str());
+ GtkWidget *hostname_frame = gtk_frame_new(markup);
+ g_free(markup);
+ gtk_frame_set_label_align(GTK_FRAME(hostname_frame), 0.0, 0.5);
+ gtk_label_set_use_markup(
+ GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(hostname_frame))),
+ TRUE
+ );
+ gtk_frame_set_shadow_type(GTK_FRAME(hostname_frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start(GTK_BOX(vbox), hostname_frame, FALSE, FALSE, 0);
+
+
+ /* distro section */
+
+ unsigned table_size = 2;
+ if (data->mate_version != "")
+ table_size++;
+ distro_table = add_section(GTK_BOX(vbox), "???", table_size, 1, &distro_frame);
+
+ unsigned table_count = 0;
+
+ distro_release_label = gtk_label_new("???");
+ gtk_misc_set_alignment(GTK_MISC(distro_release_label), 0.0, 0.5);
+ gtk_table_attach(
+ GTK_TABLE(distro_table), distro_release_label,
+ 0, 1, table_count, table_count+1,
+ GTK_FILL, GTK_FILL, 0, 0
+ );
+ table_count++;
+ data->set_distro_labels(gtk_frame_get_label_widget(GTK_FRAME(distro_frame)), distro_release_label);
+
+ markup = g_strdup_printf(_("Kernel %s"), data->kernel.c_str());
+ header = gtk_label_new(markup);
+ g_free(markup);
+ gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
+ gtk_table_attach(
+ GTK_TABLE(distro_table), header,
+ 0, 1, table_count, table_count + 1,
+ GTK_FILL, GTK_FILL, 0, 0
+ );
+ table_count++;
+
+ if (data->mate_version != "")
{
- markup = g_strdup_printf(_("MATE %s"), data->mate_version.c_str());
- header = gtk_label_new(markup);
- g_free(markup);
- gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
- gtk_table_attach(
- GTK_TABLE(distro_table), header,
- 0, 1, table_count, table_count + 1,
- GTK_FILL, GTK_FILL, 0, 0
- );
- table_count++;
- }
-
- /* hardware section */
-
- markup = g_strdup_printf(_("<b>Hardware</b>"));
- hardware_table = add_section(GTK_BOX(vbox), markup, data->processors.size(), 2, NULL);
- g_free(markup);
+ markup = g_strdup_printf(_("MATE %s"), data->mate_version.c_str());
+ header = gtk_label_new(markup);
+ g_free(markup);
+ gtk_misc_set_alignment(GTK_MISC(header), 0.0, 0.5);
+ gtk_table_attach(
+ GTK_TABLE(distro_table), header,
+ 0, 1, table_count, table_count + 1,
+ GTK_FILL, GTK_FILL, 0, 0
+ );
+ table_count++;
+ }
+
+ /* hardware section */
+
+ markup = g_strdup_printf(_("<b>Hardware</b>"));
+ hardware_table = add_section(GTK_BOX(vbox), markup, data->processors.size(), 2, NULL);
+ g_free(markup);
+
+ markup = procman::format_size(data->memory_bytes);
+ add_row(GTK_TABLE(hardware_table), _("Memory:"), markup, 0);
+ g_free(markup);
+
+ for (guint i = 0; i < data->processors.size(); ++i) {
+ const gchar * t;
+ if (data->processors.size() > 1) {
+ markup = g_strdup_printf(_("Processor %d:"), i);
+ t = markup;
+ }
+ else {
+ markup = NULL;
+ t = _("Processor:");
+ }
- markup = procman::format_size(data->memory_bytes);
- add_row(GTK_TABLE(hardware_table), _("Memory:"), markup, 0);
- g_free(markup);
+ add_row(GTK_TABLE(hardware_table), t, data->processors[i].c_str(), 1 + i);
- for (guint i = 0; i < data->processors.size(); ++i) {
- const gchar * t;
- if (data->processors.size() > 1) {
- markup = g_strdup_printf(_("Processor %d:"), i);
- t = markup;
+ if(markup)
+ g_free(markup);
}
- else {
- markup = NULL;
- t = _("Processor:");
- }
-
- add_row(GTK_TABLE(hardware_table), t, data->processors[i].c_str(), 1 + i);
-
- if(markup)
- g_free(markup);
- }
- /* disk space section */
+ /* disk space section */
- markup = g_strdup_printf(_("<b>System Status</b>"));
- disk_space_table = add_section(GTK_BOX(vbox), markup, 1, 2, NULL);
- g_free(markup);
+ markup = g_strdup_printf(_("<b>System Status</b>"));
+ disk_space_table = add_section(GTK_BOX(vbox), markup, 1, 2, NULL);
+ g_free(markup);
- markup = procman::format_size(data->free_space_bytes);
- add_row(GTK_TABLE(disk_space_table), _("Available disk space:"), markup, 0);
- g_free(markup);
+ markup = procman::format_size(data->free_space_bytes);
+ add_row(GTK_TABLE(disk_space_table), _("Available disk space:"), markup, 0);
+ g_free(markup);
- return hbox;
+ return hbox;
}
namespace procman
{
- void build_sysinfo_ui()
- {
- static GtkWidget* ui;
-
- if (!ui) {
- ProcData* procdata = ProcData::get_instance();
- ui = procman_create_sysinfo_view();
- GtkBox* box = GTK_BOX(gtk_notebook_get_nth_page(GTK_NOTEBOOK(procdata->notebook),
- PROCMAN_TAB_SYSINFO));
- gtk_box_pack_start(box, ui, TRUE, TRUE, 0);
- gtk_widget_show_all(ui);
+ void build_sysinfo_ui()
+ {
+ static GtkWidget* ui;
+
+ if (!ui) {
+ ProcData* procdata = ProcData::get_instance();
+ ui = procman_create_sysinfo_view();
+ GtkBox* box = GTK_BOX(gtk_notebook_get_nth_page(GTK_NOTEBOOK(procdata->notebook),
+ PROCMAN_TAB_SYSINFO));
+ gtk_box_pack_start(box, ui, TRUE, TRUE, 0);
+ gtk_widget_show_all(ui);
+ }
}
- }
}