summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am13
-rw-r--r--src/bacon-message-connection.c396
-rw-r--r--src/bacon-message-connection.h43
-rw-r--r--src/callbacks.cpp22
-rw-r--r--src/procman-app.cpp428
-rw-r--r--src/procman-app.h23
-rw-r--r--src/procman.cpp584
-rw-r--r--src/procman.h12
8 files changed, 490 insertions, 1031 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b001757..6811bba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,7 +37,8 @@ mate_system_monitor_cpp_files = \
lsof.cpp \
selection.cpp \
settings-keys.cpp \
- iconthemewrapper.cpp
+ iconthemewrapper.cpp \
+ procman-app.cpp
mate_system_monitor_c_files = \
gsm_color_button.c
@@ -59,15 +60,7 @@ mate_system_monitor_CXXFLAGS = \
mate_system_monitor_CFLAGS = \
$(WARN_CFLAGS)
-mate_system_monitor_LDADD = @PROCMAN_LIBS@ @SYSTEMD_LIBS@ libbacon.la
-
-
-noinst_LTLIBRARIES = libbacon.la
-libbacon_la_SOURCES = \
- bacon-message-connection.c \
- bacon-message-connection.h
-libbacon_la_CFLAGS = \
- $(WARN_CFLAGS)
+mate_system_monitor_LDADD = @PROCMAN_LIBS@ @SYSTEMD_LIBS@
specdir = $(datadir)/procman
diff --git a/src/bacon-message-connection.c b/src/bacon-message-connection.c
deleted file mode 100644
index be50d87..0000000
--- a/src/bacon-message-connection.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * Copyright (C) 2003 Bastien Nocera <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <errno.h>
-
-#include "bacon-message-connection.h"
-
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX 108
-#endif
-
-struct BaconMessageConnection {
- /* A server accepts connections */
- gboolean is_server;
-
- /* The socket path itself */
- char *path;
-
- /* File descriptor of the socket */
- int fd;
- /* Channel to watch */
- GIOChannel *chan;
- /* Event id returned by g_io_add_watch() */
- int conn_id;
-
- /* Connections accepted by this connection */
- GSList *accepted_connections;
-
- /* callback */
- void (*func) (const char *message, gpointer user_data);
- gpointer data;
-};
-
-static gboolean
-test_is_socket (const char *path)
-{
- struct stat s;
-
- if (stat (path, &s) == -1)
- return FALSE;
-
- if (S_ISSOCK (s.st_mode))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-is_owned_by_user_and_socket (const char *path)
-{
- struct stat s;
-
- if (stat (path, &s) == -1)
- return FALSE;
-
- if (s.st_uid != geteuid ())
- return FALSE;
-
- if ((s.st_mode & S_IFSOCK) != S_IFSOCK)
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean server_cb (GIOChannel *source,
- GIOCondition condition, gpointer data);
-
-static gboolean
-setup_connection (BaconMessageConnection *conn)
-{
- g_return_val_if_fail (conn->chan == NULL, FALSE);
-
- conn->chan = g_io_channel_unix_new (conn->fd);
- if (!conn->chan) {
- return FALSE;
- }
- g_io_channel_set_line_term (conn->chan, "\n", 1);
- conn->conn_id = g_io_add_watch (conn->chan, G_IO_IN, server_cb, conn);
-
- return TRUE;
-}
-
-static void
-accept_new_connection (BaconMessageConnection *server_conn)
-{
- BaconMessageConnection *conn;
- int alen;
-
- g_return_if_fail (server_conn->is_server);
-
- conn = g_new0 (BaconMessageConnection, 1);
- conn->is_server = FALSE;
- conn->func = server_conn->func;
- conn->data = server_conn->data;
-
- conn->fd = accept (server_conn->fd, NULL, (guint *)&alen);
-
- server_conn->accepted_connections =
- g_slist_prepend (server_conn->accepted_connections, conn);
-
- setup_connection (conn);
-}
-
-static gboolean
-server_cb (GIOChannel *source, GIOCondition condition, gpointer data)
-{
- BaconMessageConnection *conn = (BaconMessageConnection *)data;
- char *message, *subs, buf;
- int cd, rc, offset;
- gboolean finished;
-
- offset = 0;
- if (conn->is_server && conn->fd == g_io_channel_unix_get_fd (source)) {
- accept_new_connection (conn);
- return TRUE;
- }
- message = g_malloc (1);
- cd = conn->fd;
- rc = read (cd, &buf, 1);
- while (rc > 0 && buf != '\n')
- {
- message = g_realloc (message, rc + offset + 1);
- message[offset] = buf;
- offset = offset + rc;
- rc = read (cd, &buf, 1);
- }
- if (rc <= 0) {
- g_io_channel_shutdown (conn->chan, FALSE, NULL);
- g_io_channel_unref (conn->chan);
- conn->chan = NULL;
- close (conn->fd);
- conn->fd = -1;
- g_free (message);
- conn->conn_id = 0;
-
- return FALSE;
- }
- message[offset] = '\0';
-
- subs = message;
- finished = FALSE;
-
- while (finished == FALSE && *subs != '\0')
- {
- if (conn->func != NULL)
- (*conn->func) (subs, conn->data);
-
- subs += strlen (subs) + 1;
- if (subs - message >= offset)
- finished = TRUE;
- }
-
- g_free (message);
-
- return TRUE;
-}
-
-static char *
-find_file_with_pattern (const char *dir, const char *pattern)
-{
- GDir *filedir;
- char *found_filename;
- const char *filename;
- GPatternSpec *pat;
-
- filedir = g_dir_open (dir, 0, NULL);
- if (filedir == NULL)
- return NULL;
-
- pat = g_pattern_spec_new (pattern);
- if (pat == NULL)
- {
- g_dir_close (filedir);
- return NULL;
- }
-
- found_filename = NULL;
-
- while ((filename = g_dir_read_name (filedir)))
- {
- if (g_pattern_match_string (pat, filename))
- {
- char *tmp = g_build_filename (dir, filename, NULL);
- if (is_owned_by_user_and_socket (tmp))
- found_filename = g_strdup (filename);
- g_free (tmp);
- }
-
- if (found_filename != NULL)
- break;
- }
-
- g_pattern_spec_free (pat);
- g_dir_close (filedir);
-
- return found_filename;
-}
-
-static char *
-socket_filename (const char *prefix)
-{
- char *pattern, *newfile, *path, *filename;
- const char *tmpdir;
-
- pattern = g_strdup_printf ("%s.%s.*", prefix, g_get_user_name ());
- tmpdir = g_get_user_runtime_dir ();
- filename = find_file_with_pattern (tmpdir, pattern);
- if (filename == NULL)
- {
- newfile = g_strdup_printf ("%s.%s.%u", prefix,
- g_get_user_name (), g_random_int ());
- path = g_build_filename (tmpdir, newfile, NULL);
- g_free (newfile);
- } else {
- path = g_build_filename (tmpdir, filename, NULL);
- g_free (filename);
- }
-
- g_free (pattern);
- return path;
-}
-
-static gboolean
-try_server (BaconMessageConnection *conn)
-{
- struct sockaddr_un uaddr;
-
- uaddr.sun_family = AF_UNIX;
- strncpy (uaddr.sun_path, conn->path,
- MIN (strlen(conn->path)+1, UNIX_PATH_MAX));
- conn->fd = socket (PF_UNIX, SOCK_STREAM, 0);
- if (bind (conn->fd, (struct sockaddr *) &uaddr, sizeof (uaddr)) == -1)
- {
- conn->fd = -1;
- return FALSE;
- }
- listen (conn->fd, 5);
-
- if (!setup_connection (conn))
- return FALSE;
- return TRUE;
-}
-
-static gboolean
-try_client (BaconMessageConnection *conn)
-{
- struct sockaddr_un uaddr;
-
- uaddr.sun_family = AF_UNIX;
- strncpy (uaddr.sun_path, conn->path,
- MIN(strlen(conn->path)+1, UNIX_PATH_MAX));
- conn->fd = socket (PF_UNIX, SOCK_STREAM, 0);
- if (connect (conn->fd, (struct sockaddr *) &uaddr,
- sizeof (uaddr)) == -1)
- {
- conn->fd = -1;
- return FALSE;
- }
-
- return setup_connection (conn);
-}
-
-BaconMessageConnection *
-bacon_message_connection_new (const char *prefix)
-{
- BaconMessageConnection *conn;
-
- g_return_val_if_fail (prefix != NULL, NULL);
-
- conn = g_new0 (BaconMessageConnection, 1);
- conn->path = socket_filename (prefix);
-
- if (test_is_socket (conn->path) == FALSE)
- {
- if (!try_server (conn))
- {
- bacon_message_connection_free (conn);
- return NULL;
- }
-
- conn->is_server = TRUE;
- return conn;
- }
-
- if (try_client (conn) == FALSE)
- {
- unlink (conn->path);
- try_server (conn);
- if (conn->fd == -1)
- {
- bacon_message_connection_free (conn);
- return NULL;
- }
-
- conn->is_server = TRUE;
- return conn;
- }
-
- conn->is_server = FALSE;
- return conn;
-}
-
-void
-bacon_message_connection_free (BaconMessageConnection *conn)
-{
- GSList *child_conn;
-
- g_return_if_fail (conn != NULL);
- /* Only servers can accept other connections */
- g_return_if_fail (conn->is_server != FALSE ||
- conn->accepted_connections == NULL);
-
- child_conn = conn->accepted_connections;
- while (child_conn != NULL) {
- bacon_message_connection_free (child_conn->data);
- child_conn = g_slist_next (child_conn);
- }
- g_slist_free (conn->accepted_connections);
-
- if (conn->conn_id) {
- g_source_remove (conn->conn_id);
- conn->conn_id = 0;
- }
- if (conn->chan) {
- g_io_channel_shutdown (conn->chan, FALSE, NULL);
- g_io_channel_unref (conn->chan);
- }
-
- if (conn->is_server != FALSE) {
- unlink (conn->path);
- }
- if (conn->fd != -1) {
- close (conn->fd);
- }
-
- g_free (conn->path);
- g_free (conn);
-}
-
-void
-bacon_message_connection_set_callback (BaconMessageConnection *conn,
- BaconMessageReceivedFunc func,
- gpointer user_data)
-{
- g_return_if_fail (conn != NULL);
-
- conn->func = func;
- conn->data = user_data;
-}
-
-void
-bacon_message_connection_send (BaconMessageConnection *conn,
- const char *message)
-{
- g_return_if_fail (conn != NULL);
- g_return_if_fail (message != NULL);
-
- g_io_channel_write_chars (conn->chan, message, strlen (message),
- NULL, NULL);
- g_io_channel_write_chars (conn->chan, "\n", 1, NULL, NULL);
- g_io_channel_flush (conn->chan, NULL);
-}
-
-gboolean
-bacon_message_connection_get_is_server (BaconMessageConnection *conn)
-{
- g_return_val_if_fail (conn != NULL, FALSE);
-
- return conn->is_server;
-}
-
diff --git a/src/bacon-message-connection.h b/src/bacon-message-connection.h
deleted file mode 100644
index 1c70e43..0000000
--- a/src/bacon-message-connection.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2003 Bastien Nocera <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef BACON_MESSAGE_CONNECTION_H
-#define BACON_MESSAGE_CONNECTION_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef void (*BaconMessageReceivedFunc) (const char *message,
- gpointer user_data);
-
-typedef struct BaconMessageConnection BaconMessageConnection;
-
-BaconMessageConnection *bacon_message_connection_new (const char *prefix);
-void bacon_message_connection_free (BaconMessageConnection *conn);
-void bacon_message_connection_set_callback (BaconMessageConnection *conn,
- BaconMessageReceivedFunc func,
- gpointer user_data);
-void bacon_message_connection_send (BaconMessageConnection *conn,
- const char *message);
-gboolean bacon_message_connection_get_is_server (BaconMessageConnection *conn);
-
-G_END_DECLS
-
-#endif /* BACON_MESSAGE_CONNECTION_H */
diff --git a/src/callbacks.cpp b/src/callbacks.cpp
index 090f1e5..852a1e0 100644
--- a/src/callbacks.cpp
+++ b/src/callbacks.cpp
@@ -264,6 +264,7 @@ cb_app_exit (GtkAction *action, gpointer data)
ProcData * const procdata = static_cast<ProcData*>(data);
cb_app_delete (NULL, NULL, procdata);
+ gtk_widget_destroy (procdata->app);
}
@@ -278,9 +279,9 @@ cb_app_delete (GtkWidget *window, GdkEventAny *event, gpointer data)
if (procdata->disk_timeout)
g_source_remove (procdata->disk_timeout);
- gtk_main_quit ();
+ procdata->terminating = TRUE;
- return TRUE;
+ return FALSE;
}
@@ -497,16 +498,17 @@ cb_timeout (gpointer data)
ProcData * const procdata = static_cast<ProcData*>(data);
guint new_interval;
- proctable_update (procdata);
+ if (!procdata->terminating) {
+ proctable_update (procdata);
- if (procdata->smooth_refresh->get(new_interval))
- {
- procdata->timeout = g_timeout_add(new_interval,
- cb_timeout,
- procdata);
- return FALSE;
+ if (procdata->smooth_refresh->get(new_interval))
+ {
+ procdata->timeout = g_timeout_add(new_interval,
+ cb_timeout,
+ procdata);
+ return FALSE;
+ }
}
-
return TRUE;
}
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
new file mode 100644
index 0000000..3a0c10a
--- /dev/null
+++ b/src/procman-app.cpp
@@ -0,0 +1,428 @@
+#include <glib/gi18n.h>
+#include <glibtop.h>
+#include <glibtop/close.h>
+#include <glibtop/cpu.h>
+#include <glibtop/sysinfo.h>
+
+#include "procman-app.h"
+#include "procman.h"
+#include "interface.h"
+#include "proctable.h"
+#include "callbacks.h"
+#include "load-graph.h"
+#include "settings-keys.h"
+#include "argv.h"
+#include "util.h"
+
+static void
+mount_changed(const Glib::RefPtr<Gio::Mount>&)
+{
+ cb_update_disks(ProcData::get_instance());
+}
+
+
+static void
+init_volume_monitor(ProcData *procdata)
+{
+ using namespace Gio;
+ using namespace Glib;
+
+ RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
+
+ monitor->signal_mount_added().connect(sigc::ptr_fun(&mount_changed));
+ monitor->signal_mount_changed().connect(sigc::ptr_fun(&mount_changed));
+ monitor->signal_mount_removed().connect(sigc::ptr_fun(&mount_changed));
+}
+
+static gboolean
+has_key (gchar **keys, const gchar *key)
+{
+ gchar **loop = keys;
+
+ while (*loop) {
+ if (!strcmp (*loop++, key))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+tree_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ procdata->config.show_tree = g_settings_get_boolean(settings, key);
+
+ g_object_set(G_OBJECT(procdata->tree),
+ "show-expanders", procdata->config.show_tree,
+ NULL);
+
+ proctable_clear_tree (procdata);
+ proctable_update (procdata);
+}
+
+static void
+solaris_mode_changed_cb(GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ procdata->config.solaris_mode = g_settings_get_boolean(settings, key);
+ proctable_update (procdata);
+}
+
+
+static void
+network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ procdata->config.network_in_bits = g_settings_get_boolean(settings, key);
+ // force scale to be redrawn
+ procdata->net_graph->clear_background();
+}
+
+static void
+view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ procdata->config.whose_process = g_settings_get_int (settings, key);
+ procdata->config.whose_process = CLAMP (procdata->config.whose_process, 0, 2);
+ proctable_clear_tree (procdata);
+ proctable_update (procdata);
+}
+
+static void
+warning_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ if (g_str_equal (key, "kill-dialog")) {
+ procdata->config.show_kill_warning = g_settings_get_boolean (settings, key);
+ }
+}
+
+static void
+timeouts_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ if (g_str_equal (key, "update-interval")) {
+ procdata->config.update_interval = g_settings_get_int (settings, key);
+ procdata->config.update_interval =
+ MAX (procdata->config.update_interval, 1000);
+
+ procdata->smooth_refresh->reset();
+
+ if(procdata->timeout) {
+ g_source_remove (procdata->timeout);
+ procdata->timeout = g_timeout_add (procdata->config.update_interval,
+ cb_timeout,
+ procdata);
+ }
+ }
+ else if (g_str_equal (key, "graph-update-interval")){
+ procdata->config.graph_update_interval = g_settings_get_int (settings, key);
+ procdata->config.graph_update_interval =
+ MAX (procdata->config.graph_update_interval,
+ 250);
+ load_graph_change_speed(procdata->cpu_graph,
+ procdata->config.graph_update_interval);
+ load_graph_change_speed(procdata->mem_graph,
+ procdata->config.graph_update_interval);
+ load_graph_change_speed(procdata->net_graph,
+ procdata->config.graph_update_interval);
+ }
+ else if (g_str_equal(key, "disks-interval")) {
+ procdata->config.disks_update_interval = g_settings_get_int (settings, key);
+ procdata->config.disks_update_interval =
+ MAX (procdata->config.disks_update_interval, 1000);
+
+ if(procdata->disk_timeout) {
+ g_source_remove (procdata->disk_timeout);
+ procdata->disk_timeout = \
+ g_timeout_add (procdata->config.disks_update_interval,
+ cb_update_disks,
+ procdata);
+ }
+ }
+ else {
+ g_assert_not_reached();
+ }
+}
+
+static void
+color_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData * const procdata = static_cast<ProcData*>(data);
+ gchar *color = g_settings_get_string (settings, key);
+
+ if (g_str_has_prefix (key, "cpu-color")) {
+ for (int i = 0; i < procdata->config.num_cpus; i++) {
+ string cpu_key = make_string(g_strdup_printf("cpu-color%d", i));
+ if (cpu_key == key) {
+ gdk_rgba_parse (&procdata->config.cpu_color[i], color);
+ procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i];
+ break;
+ }
+ }
+ }
+ else if (g_str_equal (key, "mem-color")) {
+ gdk_rgba_parse (&procdata->config.mem_color, color);
+ procdata->mem_graph->colors.at(0) = procdata->config.mem_color;
+ }
+ else if (g_str_equal (key, "swap-color")) {
+ gdk_rgba_parse (&procdata->config.swap_color, color);
+ procdata->mem_graph->colors.at(1) = procdata->config.swap_color;
+ }
+ else if (g_str_equal (key, "net-in-color")) {
+ gdk_rgba_parse (&procdata->config.net_in_color, color);
+ procdata->net_graph->colors.at(0) = procdata->config.net_in_color;
+ }
+ else if (g_str_equal (key, "net-out-color")) {
+ gdk_rgba_parse (&procdata->config.net_out_color, color);
+ procdata->net_graph->colors.at(1) = procdata->config.net_out_color;
+ }
+ else {
+ g_assert_not_reached();
+ }
+ g_free(color);
+}
+
+static void
+show_all_fs_changed_cb (GSettings *settings, const gchar *key, gpointer data)
+{
+ ProcData * const procdata = static_cast<ProcData*>(data);
+
+ procdata->config.show_all_fs = g_settings_get_boolean (settings, key);
+
+ cb_update_disks (data);
+}
+
+static ProcData *
+procman_data_new (GSettings *settings)
+{
+ GSettingsSchema *schema;
+ ProcData *pd;
+ gchar *color;
+ gchar **keys;
+ gint swidth, sheight;
+ glibtop_cpu cpu;
+
+ pd = ProcData::get_instance();
+
+ g_settings_get (settings, "window-state", "(iiii)",
+ &pd->config.width, &pd->config.height,
+ &pd->config.xpos, &pd->config.ypos);
+
+ pd->config.maximized = g_settings_get_boolean(settings, "maximized");
+
+ pd->config.show_tree = g_settings_get_boolean (settings, "show-tree");
+ g_signal_connect (G_OBJECT(settings), "changed::show-tree", G_CALLBACK(tree_changed_cb), pd);
+
+ pd->config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str());
+ std::string detail_string("changed::" + procman::settings::solaris_mode);
+ g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(solaris_mode_changed_cb), pd);
+
+ pd->config.network_in_bits = g_settings_get_boolean(settings, procman::settings::network_in_bits.c_str());
+ detail_string = "changed::" + procman::settings::network_in_bits;
+ g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(network_in_bits_changed_cb), pd);
+
+ pd->config.show_kill_warning = g_settings_get_boolean (settings, "kill-dialog");
+ g_signal_connect (G_OBJECT(settings), "changed::kill-dialog", G_CALLBACK(warning_changed_cb), pd);
+ pd->config.update_interval = g_settings_get_int (settings, "update-interval");
+ g_signal_connect (G_OBJECT(settings), "changed::update-interval", G_CALLBACK(timeouts_changed_cb), pd);
+ pd->config.graph_update_interval = g_settings_get_int (settings,
+ "graph-update-interval");
+ g_signal_connect (G_OBJECT(settings), "changed::graph-update-interval",
+ G_CALLBACK(timeouts_changed_cb), pd);
+ pd->config.disks_update_interval = g_settings_get_int (settings, "disks-interval");
+ g_signal_connect (G_OBJECT(settings), "changed::disks-interval", G_CALLBACK(timeouts_changed_cb), pd);
+
+
+ /* show_all_fs */
+ pd->config.show_all_fs = g_settings_get_boolean (settings, "show-all-fs");
+ g_signal_connect (settings, "changed::show-all-fs", G_CALLBACK(show_all_fs_changed_cb), pd);
+
+
+ pd->config.whose_process = g_settings_get_int (settings, "view-as");
+ g_signal_connect (G_OBJECT(settings), "changed::view-as", G_CALLBACK(view_as_changed_cb),pd);
+ pd->config.current_tab = g_settings_get_int (settings, "current-tab");
+
+ glibtop_get_cpu (&cpu);
+ pd->frequency = cpu.frequency;
+ pd->config.num_cpus = glibtop_get_sysinfo()->ncpu; // or server->ncpu + 1
+
+ g_object_get (settings, "settings-schema", &schema, NULL);
+ keys = g_settings_schema_list_keys (schema);
+ g_settings_schema_unref (schema);
+
+ for (int i = 0; i < pd->config.num_cpus; i++) {
+ gchar *key;
+ key = g_strdup_printf ("cpu-color%d", i);
+
+ if (has_key (keys, key))
+ color = g_settings_get_string (settings, key);
+ else
+ color = g_strdup ("#f25915e815e8");
+ detail_string = std::string("changed::") + std::string(key);
+ g_signal_connect (G_OBJECT(settings), detail_string.c_str(),
+ G_CALLBACK(color_changed_cb), pd);
+ gdk_rgba_parse (&pd->config.cpu_color[i], color);
+ g_free (color);
+ g_free (key);
+ }
+ g_strfreev (keys);
+
+ color = g_settings_get_string (settings, "mem-color");
+ if (!color)
+ color = g_strdup ("#000000ff0082");
+ g_signal_connect (G_OBJECT(settings), "changed::mem-color",
+ G_CALLBACK(color_changed_cb), pd);
+ gdk_rgba_parse(&pd->config.mem_color, color);
+ g_free (color);
+
+ color = g_settings_get_string (settings, "swap-color");
+ if (!color)
+ color = g_strdup ("#00b6000000ff");
+ g_signal_connect (G_OBJECT(settings), "changed::swap-color",
+ G_CALLBACK(color_changed_cb), pd);
+ gdk_rgba_parse(&pd->config.swap_color, color);
+ g_free (color);
+
+ color = g_settings_get_string (settings, "net-in-color");
+ if (!color)
+ color = g_strdup ("#000000f200f2");
+ g_signal_connect (G_OBJECT(settings), "changed::net-in-color",
+ G_CALLBACK(color_changed_cb), pd);
+ gdk_rgba_parse(&pd->config.net_in_color, color);
+ g_free (color);
+
+ color = g_settings_get_string (settings, "net-out-color");
+ if (!color)
+ color = g_strdup ("#00f2000000c1");
+ g_signal_connect (G_OBJECT(settings), "changed::net-out-color",
+ G_CALLBACK(color_changed_cb), pd);
+ gdk_rgba_parse(&pd->config.net_out_color, color);
+ g_free (color);
+
+ /* Sanity checks */
+ swidth = WidthOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()));
+ sheight = HeightOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()));
+ pd->config.width = CLAMP (pd->config.width, 50, swidth);
+ pd->config.height = CLAMP (pd->config.height, 50, sheight);
+ pd->config.update_interval = MAX (pd->config.update_interval, 1000);
+ pd->config.graph_update_interval = MAX (pd->config.graph_update_interval, 250);
+ pd->config.disks_update_interval = MAX (pd->config.disks_update_interval, 1000);
+ pd->config.whose_process = CLAMP (pd->config.whose_process, 0, 2);
+ pd->config.current_tab = CLAMP(pd->config.current_tab,
+ PROCMAN_TAB_SYSINFO,
+ PROCMAN_TAB_DISKS);
+
+ // delayed initialization as SmoothRefresh() needs ProcData
+ // i.e. we can't call ProcData::get_instance
+ pd->smooth_refresh = new SmoothRefresh(settings);
+
+ pd->terminating = FALSE;
+
+ return pd;
+}
+
+static void
+procman_free_data (ProcData *procdata)
+{
+
+ proctable_free_table (procdata);
+ delete procdata->smooth_refresh;
+}
+
+ProcmanApp::ProcmanApp() : Gtk::Application("org.mate.SystemMonitor", Gio::APPLICATION_HANDLES_COMMAND_LINE)
+{
+ Glib::set_application_name(_("System Monitor"));
+}
+
+Glib::RefPtr<ProcmanApp> ProcmanApp::create ()
+{
+ return Glib::RefPtr<ProcmanApp>(new ProcmanApp());
+}
+
+void ProcmanApp::on_activate()
+{
+ gtk_window_present (GTK_WINDOW (procdata->app));
+}
+
+static void
+set_tab(GtkNotebook* notebook, gint tab, ProcData* procdata)
+{
+ gtk_notebook_set_current_page(notebook, tab);
+ cb_change_current_page(notebook, tab, procdata);
+}
+
+int ProcmanApp::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line)
+{
+ int argc = 0;
+ char** argv = command_line->get_arguments(argc);
+
+ Glib::OptionContext context;
+ context.set_summary(_("A simple process and system monitor."));
+ context.set_ignore_unknown_options(true);
+ procman::OptionGroup option_group;
+ context.set_main_group(option_group);
+
+ try {
+ context.parse(argc, argv);
+ } catch (const Glib::Error& ex) {
+ g_error("Arguments parse error : %s", ex.what().c_str());
+ }
+
+ if (option_group.show_system_tab) {
+ procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request");
+ set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
+ } else if (option_group.show_processes_tab) {
+ procman_debug("Starting with PROCMAN_TAB_PROCESSES by commandline request");
+ set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_PROCESSES, procdata);
+ } else if (option_group.show_resources_tab) {
+ procman_debug("Starting with PROCMAN_TAB_RESOURCES by commandline request");
+ set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_RESOURCES, procdata);
+ } else if (option_group.show_file_systems_tab) {
+ procman_debug("Starting with PROCMAN_TAB_DISKS by commandline request");
+ set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_DISKS, procdata);
+ }
+
+ on_activate ();
+
+ return 0;
+}
+
+void ProcmanApp::on_startup()
+{
+ Gtk::Application::on_startup();
+
+ GSettings *settings;
+
+ Gtk::Window::set_default_icon_name ("utilities-system-monitor");
+
+ settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
+
+ glibtop_init ();
+
+ procdata = procman_data_new (settings);
+ procdata->settings = g_settings_new(GSM_GSETTINGS_SCHEMA);
+
+ create_main_window (procdata);
+ init_volume_monitor (procdata);
+
+ Gtk::Window *window = Glib::wrap(GTK_WINDOW(procdata->app));
+ window->show();
+ window->set_name ("mate-system-monitor");
+
+ add_window (*window);
+}
+
+void ProcmanApp::on_shutdown()
+{
+ procman_free_data(procdata);
+ glibtop_close();
+}
+
diff --git a/src/procman-app.h b/src/procman-app.h
new file mode 100644
index 0000000..50a9666
--- /dev/null
+++ b/src/procman-app.h
@@ -0,0 +1,23 @@
+#ifndef _PROCMAN_PROCMAN_APP_H_
+#define _PROCMAN_PROCMAN_APP_H_
+
+#include <gtkmm.h>
+#include <gdk/gdkx.h>
+
+#include "procman.h"
+
+class ProcmanApp : public Gtk::Application
+{
+ ProcData *procdata;
+protected:
+ ProcmanApp();
+public:
+ static Glib::RefPtr<ProcmanApp> create ();
+protected:
+ virtual void on_activate();
+ virtual int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line);
+ virtual void on_startup();
+ virtual void on_shutdown();
+};
+
+#endif /* _PROCMAN_PROCMAN_APP_H_ */
diff --git a/src/procman.cpp b/src/procman.cpp
index 09ddc38..32e47e6 100644
--- a/src/procman.cpp
+++ b/src/procman.cpp
@@ -23,359 +23,31 @@
#include <locale.h>
-#include <gtkmm/main.h>
-#include <giomm/volumemonitor.h>
-#include <giomm/init.h>
-#include <glib.h>
+#include <gtkmm.h>
#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-#include <bacon-message-connection.h>
-#include <glibtop.h>
-#include <glibtop/close.h>
-#include <glibtop/cpu.h>
-#include <glibtop/sysinfo.h>
-#include <glibtop/loadavg.h>
-
-#include "load-graph.h"
+
+#include "procman-app.h"
#include "procman.h"
-#include "interface.h"
#include "proctable.h"
-#include "prettytable.h"
-#include "callbacks.h"
-#include "smooth_refresh.h"
-#include "util.h"
-#include "settings-keys.h"
-#include "argv.h"
-
ProcData::ProcData()
- : tree(NULL),
- cpu_graph(NULL),
- mem_graph(NULL),
- net_graph(NULL),
- selected_process(NULL),
- timeout(0),
- disk_timeout(0),
- cpu_total_time(1),
- cpu_total_time_last(1)
+ : tree(NULL),
+ cpu_graph(NULL),
+ mem_graph(NULL),
+ net_graph(NULL),
+ selected_process(NULL),
+ timeout(0),
+ disk_timeout(0),
+ cpu_total_time(1),
+ cpu_total_time_last(1)
{ }
-
ProcData* ProcData::get_instance()
{
static ProcData instance;
return &instance;
}
-static gboolean
-has_key (gchar **keys, const gchar *key)
-{
- gchar **loop = keys;
-
- while (*loop) {
- if (!strcmp (*loop++, key))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-tree_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
- procdata->config.show_tree = g_settings_get_boolean(settings, key);
-
- g_object_set(G_OBJECT(procdata->tree),
- "show-expanders", procdata->config.show_tree,
- NULL);
-
- proctable_clear_tree (procdata);
-
- proctable_update (procdata);
-}
-
-static void
-solaris_mode_changed_cb(GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
-
- procdata->config.solaris_mode = g_settings_get_boolean(settings, key);
- proctable_update (procdata);
-}
-
-
-static void
-network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
-
- procdata->config.network_in_bits = g_settings_get_boolean(settings, key);
- procdata->net_graph->clear_background();
-}
-
-
-
-static void
-view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
-
- procdata->config.whose_process = g_settings_get_int (settings, key);
- procdata->config.whose_process = CLAMP (procdata->config.whose_process, 0, 2);
- proctable_clear_tree (procdata);
- proctable_update (procdata);
-
-}
-
-static void
-warning_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
- if (g_str_equal (key, "kill-dialog")) {
- procdata->config.show_kill_warning = g_settings_get_boolean (settings, key);
- }
-}
-
-static void
-timeouts_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData *procdata = static_cast<ProcData*>(data);
- if (g_str_equal (key, "update-interval")) {
- procdata->config.update_interval = g_settings_get_int (settings, key);
- procdata->config.update_interval =
- MAX (procdata->config.update_interval, 1000);
-
- procdata->smooth_refresh->reset();
-
- if(procdata->timeout) {
- g_source_remove (procdata->timeout);
- procdata->timeout = g_timeout_add (procdata->config.update_interval,
- cb_timeout,
- procdata);
- }
- }
- else if (g_str_equal (key, "graph-update-interval")){
- procdata->config.graph_update_interval = g_settings_get_int (settings, key);
- procdata->config.graph_update_interval =
- MAX (procdata->config.graph_update_interval,
- 250);
- load_graph_change_speed(procdata->cpu_graph,
- procdata->config.graph_update_interval);
- load_graph_change_speed(procdata->mem_graph,
- procdata->config.graph_update_interval);
- load_graph_change_speed(procdata->net_graph,
- procdata->config.graph_update_interval);
- }
- else if (g_str_equal(key, "disks-interval")) {
-
- procdata->config.disks_update_interval = g_settings_get_int (settings, key);
- procdata->config.disks_update_interval =
- MAX (procdata->config.disks_update_interval, 1000);
-
- if(procdata->disk_timeout) {
- g_source_remove (procdata->disk_timeout);
- procdata->disk_timeout = \
- g_timeout_add (procdata->config.disks_update_interval,
- cb_update_disks,
- procdata);
- }
- }
- else {
- g_assert_not_reached();
- }
-}
-
-static void
-color_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData * const procdata = static_cast<ProcData*>(data);
- gchar *color = g_settings_get_string (settings, key);
-
- if (g_str_has_prefix (key, "cpu-color")) {
- for (int i = 0; i < procdata->config.num_cpus; i++) {
- string cpu_key = make_string(g_strdup_printf("cpu-color%d", i));
- if (cpu_key == key) {
- gdk_rgba_parse (&procdata->config.cpu_color[i], color);
- procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i];
- break;
- }
- }
- }
- else if (g_str_equal (key, "mem-color")) {
- gdk_rgba_parse (&procdata->config.mem_color, color);
- procdata->mem_graph->colors.at(0) = procdata->config.mem_color;
- }
- else if (g_str_equal (key, "swap-color")) {
- gdk_rgba_parse (&procdata->config.swap_color, color);
- procdata->mem_graph->colors.at(1) = procdata->config.swap_color;
- }
- else if (g_str_equal (key, "net-in-color")) {
- gdk_rgba_parse (&procdata->config.net_in_color, color);
- procdata->net_graph->colors.at(0) = procdata->config.net_in_color;
- }
- else if (g_str_equal (key, "net-out-color")) {
- gdk_rgba_parse (&procdata->config.net_out_color, color);
- procdata->net_graph->colors.at(1) = procdata->config.net_out_color;
- }
- else {
- g_assert_not_reached();
- }
- g_free (color);
-}
-
-
-
-static void
-show_all_fs_changed_cb (GSettings *settings, const gchar *key, gpointer data)
-{
- ProcData * const procdata = static_cast<ProcData*>(data);
-
- procdata->config.show_all_fs = g_settings_get_boolean (settings, key);
-
- cb_update_disks (data);
-}
-
-
-static ProcData *
-procman_data_new (GSettings *settings)
-{
- GSettingsSchema *schema;
- ProcData *pd;
- gchar *color;
- gchar **keys;
- gint swidth, sheight;
- glibtop_cpu cpu;
-
- pd = ProcData::get_instance();
-
- g_settings_get (settings, "window-state", "(iiii)",
- &pd->config.width, &pd->config.height,
- &pd->config.xpos, &pd->config.ypos);
-
- pd->config.maximized = g_settings_get_boolean(settings, "maximized");
-
- pd->config.show_tree = g_settings_get_boolean (settings, "show-tree");
- g_signal_connect (G_OBJECT(settings), "changed::show-tree", G_CALLBACK(tree_changed_cb), pd);
-
- pd->config.solaris_mode = g_settings_get_boolean(settings, procman::settings::solaris_mode.c_str());
- std::string detail_string("changed::" + procman::settings::solaris_mode);
- g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(solaris_mode_changed_cb), pd);
-
- pd->config.network_in_bits = g_settings_get_boolean(settings, procman::settings::network_in_bits.c_str());
- detail_string = "changed::" + procman::settings::network_in_bits;
- g_signal_connect(G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(network_in_bits_changed_cb), pd);
-
- pd->config.show_kill_warning = g_settings_get_boolean (settings, "kill-dialog");
- g_signal_connect (G_OBJECT(settings), "changed::kill-dialog", G_CALLBACK(warning_changed_cb), pd);
- pd->config.update_interval = g_settings_get_int (settings, "update-interval");
- g_signal_connect (G_OBJECT(settings), "changed::update-interval", G_CALLBACK(timeouts_changed_cb), pd);
- pd->config.graph_update_interval = g_settings_get_int (settings,
- "graph-update-interval");
- g_signal_connect (G_OBJECT(settings), "changed::graph-update-interval",
- G_CALLBACK(timeouts_changed_cb), pd);
- pd->config.disks_update_interval = g_settings_get_int (settings, "disks-interval");
- g_signal_connect (G_OBJECT(settings), "changed::disks-interval", G_CALLBACK(timeouts_changed_cb), pd);
-
-
- /* show_all_fs */
- pd->config.show_all_fs = g_settings_get_boolean (settings, "show-all-fs");
- g_signal_connect (settings, "changed::show-all-fs", G_CALLBACK(show_all_fs_changed_cb), pd);
-
-
- pd->config.whose_process = g_settings_get_int (settings, "view-as");
- g_signal_connect (G_OBJECT(settings), "changed::view-as", G_CALLBACK(view_as_changed_cb),pd);
- pd->config.current_tab = g_settings_get_int (settings, "current-tab");
-
- glibtop_get_cpu (&cpu);
- pd->frequency = cpu.frequency;
-
- pd->config.num_cpus = glibtop_get_sysinfo()->ncpu; // or server->ncpu + 1
-
- g_object_get (settings, "settings-schema", &schema, NULL);
- keys = g_settings_schema_list_keys (schema);
- g_settings_schema_unref (schema);
-
- for (int i = 0; i < pd->config.num_cpus; i++) {
- gchar *key;
- key = g_strdup_printf ("cpu-color%d", i);
-
- if (has_key (keys, key))
- color = g_settings_get_string (settings, key);
- else
- color = g_strdup ("#f25915e815e8");
- detail_string = std::string("changed::") + std::string(key);
- g_signal_connect (G_OBJECT(settings), detail_string.c_str(),
- G_CALLBACK(color_changed_cb), pd);
- gdk_rgba_parse (&pd->config.cpu_color[i], color);
- g_free (color);
- g_free (key);
- }
- g_strfreev (keys);
- color = g_settings_get_string (settings, "mem-color");
- if (!color)
- color = g_strdup ("#000000ff0082");
- g_signal_connect (G_OBJECT(settings), "changed::mem-color",
- G_CALLBACK(color_changed_cb), pd);
- gdk_rgba_parse (&pd->config.mem_color, color);
-
- g_free (color);
-
- color = g_settings_get_string (settings, "swap-color");
- if (!color)
- color = g_strdup ("#00b6000000ff");
- g_signal_connect (G_OBJECT(settings), "changed::swap-color",
- G_CALLBACK(color_changed_cb), pd);
- gdk_rgba_parse (&pd->config.swap_color, color);
- g_free (color);
-
- color = g_settings_get_string (settings, "net-in-color");
- if (!color)
- color = g_strdup ("#000000f200f2");
- g_signal_connect (G_OBJECT(settings), "changed::net-in-color",
- G_CALLBACK(color_changed_cb), pd);
- gdk_rgba_parse (&pd->config.net_in_color, color);
- g_free (color);
-
- color = g_settings_get_string (settings, "net-out-color");
- if (!color)
- color = g_strdup ("#00f2000000c1");
- g_signal_connect (G_OBJECT(settings), "changed::net-out-color",
- G_CALLBACK(color_changed_cb), pd);
- gdk_rgba_parse (&pd->config.net_out_color, color);
- g_free (color);
-
- /* Sanity checks */
- swidth = WidthOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()));
- sheight = HeightOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()));
- pd->config.width = CLAMP (pd->config.width, 50, swidth);
- pd->config.height = CLAMP (pd->config.height, 50, sheight);
- pd->config.update_interval = MAX (pd->config.update_interval, 1000);
- pd->config.graph_update_interval = MAX (pd->config.graph_update_interval, 250);
- pd->config.disks_update_interval = MAX (pd->config.disks_update_interval, 1000);
- pd->config.whose_process = CLAMP (pd->config.whose_process, 0, 2);
- pd->config.current_tab = CLAMP(pd->config.current_tab,
- PROCMAN_TAB_SYSINFO,
- PROCMAN_TAB_DISKS);
-
- // delayed initialization as SmoothRefresh() needs ProcData
- // i.e. we can't call ProcData::get_instance
- pd->smooth_refresh = new SmoothRefresh(settings);
-
- return pd;
-
-}
-
-static void
-procman_free_data (ProcData *procdata)
-{
-
- proctable_free_table (procdata);
- delete procdata->smooth_refresh;
-}
-
-
gboolean
procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child_schema)
{
@@ -384,7 +56,6 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
gint sort_col;
GtkSortType order;
-
g_assert(tree);
g_assert(child_schema);
@@ -437,9 +108,9 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
}
}
- GVariant *value;
+ GVariant *value;
GVariantIter iter;
- int sortIndex;
+ int sortIndex;
GSList *order = NULL;
@@ -447,7 +118,7 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
g_variant_iter_init(&iter, value);
while (g_variant_iter_loop (&iter, "i", &sortIndex))
- order = g_slist_append(order, GINT_TO_POINTER(sortIndex));
+ order = g_slist_append(order, GINT_TO_POINTER(sortIndex));
proctable_set_columns_order(GTK_TREE_VIEW(tree), order);
@@ -471,6 +142,9 @@ procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *chil
gint sort_col;
GtkSortType order;
+ if (ProcData::get_instance()->terminating)
+ return;
+
g_assert(tree);
g_assert(child_schema);
@@ -503,7 +177,6 @@ procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *chil
order_variant = g_variant_new("ai", builder);
g_settings_set_value(pt_settings, "columns-order", order_variant);
-
g_slist_free(order);
}
@@ -520,8 +193,8 @@ procman_save_config (ProcData *data)
data->config.maximized = gdk_window_get_state(gtk_widget_get_window (data->app)) & GDK_WINDOW_STATE_MAXIMIZED;
if (!data->config.maximized) {
// we only want to store/overwrite size and position info with non-maximized state info
- data->config.width = gdk_window_get_width(gtk_widget_get_window(data->app));
- data->config.height = gdk_window_get_height(gtk_widget_get_window(data->app));
+ data->config.width = gdk_window_get_width (gtk_widget_get_window (data->app));
+ data->config.height = gdk_window_get_height(gtk_widget_get_window (data->app));
gtk_window_get_position(GTK_WINDOW(data->app), &data->config.xpos, &data->config.ypos);
@@ -529,232 +202,19 @@ procman_save_config (ProcData *data)
data->config.width, data->config.height,
data->config.xpos, data->config.ypos);
}
-
g_settings_set_boolean (settings, "maximized", data->config.maximized);
g_settings_set_int (settings, "current-tab", data->config.current_tab);
}
-static guint32
-get_startup_timestamp ()
-{
- const gchar *startup_id_env;
- gchar *startup_id = NULL;
- gchar *time_str;
- gulong retval = 0;
-
- /* we don't unset the env, since startup-notification
- * may still need it */
- startup_id_env = g_getenv ("DESKTOP-STARTUP-ID");
- if (startup_id_env == NULL)
- goto out;
-
- startup_id = g_strdup (startup_id_env);
-
- time_str = g_strrstr (startup_id, "_TIME");
- if (time_str == NULL)
- goto out;
-
- /* Skip past the "_TIME" part */
- time_str += 5;
-
- retval = strtoul (time_str, NULL, 0);
-
- out:
- g_free (startup_id);
-
- return retval;
-}
-
-static void
-set_tab(GtkNotebook* notebook, gint tab, ProcData* procdata)
-{
- gtk_notebook_set_current_page(notebook, tab);
- cb_change_current_page(notebook, tab, procdata);
-}
-
-static void
-cb_server (const gchar *msg, gpointer user_data)
-{
- GdkWindow *window;
- ProcData *procdata;
- guint32 timestamp = 0;
-
- window = gdk_get_default_root_window ();
-
- procdata = *(ProcData**)user_data;
- g_assert (procdata != NULL);
-
- procman_debug("cb_server(%s)", msg);
- if (msg != NULL) {
- if (procman::SHOW_SYSTEM_TAB_CMD == msg) {
- procman_debug("Changing to PROCMAN_TAB_SYSINFO via bacon message");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
- } else if (procman::SHOW_PROCESSES_TAB_CMD == msg) {
- procman_debug("Changing to PROCMAN_TAB_PROCESSES via bacon message");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_PROCESSES, procdata);
- } else if (procman::SHOW_RESOURCES_TAB_CMD == msg) {
- procman_debug("Changing to PROCMAN_TAB_RESOURCES via bacon message");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_RESOURCES, procdata);
- } else if (procman::SHOW_FILE_SYSTEMS_TAB_CMD == msg) {
- procman_debug("Changing to PROCMAN_TAB_DISKS via bacon message");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_DISKS, procdata);
- }
- }
-
- /* fall back to rountripping to X */
- timestamp = gdk_x11_get_server_time (window);
-
- gdk_x11_window_set_user_time (window, timestamp);
-
- gtk_window_present (GTK_WINDOW(procdata->app));
-}
-
-
-
-
-static void
-mount_changed(const Glib::RefPtr<Gio::Mount>&)
-{
- cb_update_disks(ProcData::get_instance());
-}
-
-
-static void
-init_volume_monitor(ProcData *procdata)
-{
- using namespace Gio;
- using namespace Glib;
-
- RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
-
- monitor->signal_mount_added().connect(sigc::ptr_fun(&mount_changed));
- monitor->signal_mount_changed().connect(sigc::ptr_fun(&mount_changed));
- monitor->signal_mount_removed().connect(sigc::ptr_fun(&mount_changed));
-}
-
-
-namespace procman
-{
- const std::string SHOW_SYSTEM_TAB_CMD("SHOWSYSTAB");
- const std::string SHOW_PROCESSES_TAB_CMD("SHOWPROCTAB");
- const std::string SHOW_RESOURCES_TAB_CMD("SHOWRESTAB");
- const std::string SHOW_FILE_SYSTEMS_TAB_CMD("SHOWFSTAB");
-}
-
-
int
main (int argc, char *argv[])
{
- guint32 startup_timestamp;
- GSettings *settings;
- ProcData *procdata;
- BaconMessageConnection *conn;
-
bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
setlocale (LC_ALL, "");
- startup_timestamp = get_startup_timestamp();
-
- Glib::OptionContext context;
- context.set_summary(_("A simple process and system monitor."));
- context.set_ignore_unknown_options(true);
- procman::OptionGroup option_group;
- context.set_main_group(option_group);
-
- try {
- context.parse(argc, argv);
- } catch (const Glib::Error& ex) {
- g_error("Arguments parse error : %s", ex.what().c_str());
- }
-
- Gio::init();
- Gtk::Main kit(&argc, &argv);
- procman_debug("post gtk_init");
-
- conn = bacon_message_connection_new ("mate-system-monitor");
- if (!conn) g_error("Couldn't connect to mate-system-monitor");
-
- if (bacon_message_connection_get_is_server (conn))
- {
- bacon_message_connection_set_callback (conn, cb_server, &procdata);
- }
- else /* client */
- {
- char *timestamp;
-
- timestamp = g_strdup_printf ("%" G_GUINT32_FORMAT, startup_timestamp);
-
- if (option_group.show_system_tab)
- bacon_message_connection_send(conn, procman::SHOW_SYSTEM_TAB_CMD.c_str());
-
- if (option_group.show_processes_tab)
- bacon_message_connection_send(conn, procman::SHOW_PROCESSES_TAB_CMD.c_str());
-
- if (option_group.show_resources_tab)
- bacon_message_connection_send(conn, procman::SHOW_RESOURCES_TAB_CMD.c_str());
-
- if (option_group.show_file_systems_tab)
- bacon_message_connection_send(conn, procman::SHOW_FILE_SYSTEMS_TAB_CMD.c_str());
-
- bacon_message_connection_send (conn, timestamp);
-
- gdk_notify_startup_complete ();
-
- g_free (timestamp);
- bacon_message_connection_free (conn);
-
- exit (0);
- }
-
- gtk_window_set_default_icon_name ("utilities-system-monitor");
- g_set_application_name(_("System Monitor"));
-
- settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
-
- glibtop_init ();
-
- procman_debug("end init");
-
- procdata = procman_data_new (settings);
- procdata->settings = g_settings_new(GSM_GSETTINGS_SCHEMA);
-
- procman_debug("begin create_main_window");
- create_main_window (procdata);
- procman_debug("end create_main_window");
-
- // proctable_update (procdata);
-
- init_volume_monitor (procdata);
-
- g_assert(procdata->app);
-
- if (option_group.show_system_tab) {
- procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
- } else if (option_group.show_processes_tab) {
- procman_debug("Starting with PROCMAN_TAB_PROCESSES by commandline request");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_PROCESSES, procdata);
- } else if (option_group.show_resources_tab) {
- procman_debug("Starting with PROCMAN_TAB_RESOURCES by commandline request");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_RESOURCES, procdata);
- } else if (option_group.show_file_systems_tab) {
- procman_debug("Starting with PROCMAN_TAB_DISKS by commandline request");
- set_tab(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_DISKS, procdata);
- }
-
- gtk_widget_set_name(procdata->app, "mate-system-monitor");
- gtk_widget_show(procdata->app);
-
- procman_debug("begin gtk_main");
- kit.run();
-
- procman_free_data (procdata);
-
- glibtop_close ();
-
- return 0;
+ Glib::RefPtr<ProcmanApp> application = ProcmanApp::create();
+ return application->run (argc, argv);
}
-
diff --git a/src/procman.h b/src/procman.h
index ca58cbf..176df7a 100644
--- a/src/procman.h
+++ b/src/procman.h
@@ -64,16 +64,6 @@ static const unsigned MIN_UPDATE_INTERVAL = 1 * 1000;
static const unsigned MAX_UPDATE_INTERVAL = 100 * 1000;
-namespace procman
-{
- extern const std::string SHOW_SYSTEM_TAB_CMD;
- extern const std::string SHOW_PROCESSES_TAB_CMD;
- extern const std::string SHOW_RESOURCES_TAB_CMD;
- extern const std::string SHOW_FILE_SYSTEMS_TAB_CMD;
-}
-
-
-
enum ProcmanTab
{
PROCMAN_TAB_SYSINFO,
@@ -250,6 +240,8 @@ struct ProcData
guint64 cpu_total_time;
guint64 cpu_total_time_last;
+ gboolean terminating;
+
private:
ProcData();
/* undefined */ ProcData(const ProcData &);