summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argv.cpp20
-rw-r--r--src/argv.h14
-rw-r--r--src/bacon-message-connection.c530
-rw-r--r--src/bacon-message-connection.h18
-rw-r--r--src/callbacks.cpp2
-rw-r--r--src/callbacks.h74
-rw-r--r--src/defaulttable.h56
-rw-r--r--src/disks.cpp646
-rw-r--r--src/e_date.c290
-rw-r--r--src/gsm_color_button.c1138
-rw-r--r--src/gsm_color_button.h32
-rw-r--r--src/iconthemewrapper.cpp12
-rw-r--r--src/iconthemewrapper.h18
-rw-r--r--src/interface.cpp1276
-rw-r--r--src/interface.h6
-rw-r--r--src/load-graph.cpp1136
-rw-r--r--src/load-graph.h128
-rw-r--r--src/lsof.cpp620
-rw-r--r--src/memmaps.cpp752
-rw-r--r--src/memmaps.h2
-rw-r--r--src/openfiles.cpp488
-rw-r--r--src/openfiles.h2
-rw-r--r--src/prettytable.cpp212
-rw-r--r--src/prettytable.h38
-rw-r--r--src/procactions.cpp200
-rw-r--r--src/procactions.h6
-rw-r--r--src/procdialogs.cpp1298
-rw-r--r--src/procdialogs.h18
-rw-r--r--src/procman.cpp912
-rw-r--r--src/procman.h270
-rw-r--r--src/procman_gksu.cpp40
-rw-r--r--src/procman_matesu.cpp20
-rw-r--r--src/proctable.cpp1268
-rw-r--r--src/proctable.h60
-rw-r--r--src/selection.cpp60
-rw-r--r--src/selection.h16
-rw-r--r--src/selinux.cpp50
-rw-r--r--src/settings-keys.cpp14
-rw-r--r--src/settings-keys.h14
-rw-r--r--src/smooth_refresh.cpp140
-rw-r--r--src/smooth_refresh.h116
-rw-r--r--src/sysinfo.cpp1110
-rw-r--r--src/sysinfo.h2
-rw-r--r--src/util.cpp640
-rw-r--r--src/util.h142
45 files changed, 6952 insertions, 6954 deletions
diff --git a/src/argv.cpp b/src/argv.cpp
index a81a3c0..f1a3a86 100644
--- a/src/argv.cpp
+++ b/src/argv.cpp
@@ -8,15 +8,15 @@
namespace procman
{
- OptionGroup::OptionGroup()
- : Glib::OptionGroup("", ""),
- show_system_tab(false)
- {
- Glib::OptionEntry sys_tab;
- sys_tab.set_long_name("show-system-tab");
- sys_tab.set_short_name('s');
- sys_tab.set_description(_("Show the System tab"));
- this->add_entry(sys_tab, this->show_system_tab);
- }
+ OptionGroup::OptionGroup()
+ : Glib::OptionGroup("", ""),
+ show_system_tab(false)
+ {
+ Glib::OptionEntry sys_tab;
+ sys_tab.set_long_name("show-system-tab");
+ sys_tab.set_short_name('s');
+ sys_tab.set_description(_("Show the System tab"));
+ this->add_entry(sys_tab, this->show_system_tab);
+ }
}
diff --git a/src/argv.h b/src/argv.h
index a0f7205..9a604d5 100644
--- a/src/argv.h
+++ b/src/argv.h
@@ -5,14 +5,14 @@
namespace procman
{
- class OptionGroup
- : public Glib::OptionGroup
- {
- public:
- OptionGroup();
+ class OptionGroup
+ : public Glib::OptionGroup
+ {
+ public:
+ OptionGroup();
- bool show_system_tab;
- };
+ bool show_system_tab;
+ };
}
#endif // H_PROCMAN_ARGV_1205873424
diff --git a/src/bacon-message-connection.c b/src/bacon-message-connection.c
index 7b35342..4b8014b 100644
--- a/src/bacon-message-connection.c
+++ b/src/bacon-message-connection.c
@@ -35,362 +35,362 @@
#endif
struct BaconMessageConnection {
- /* A server accepts connections */
- gboolean is_server;
+ /* A server accepts connections */
+ gboolean is_server;
- /* The socket path itself */
- char *path;
+ /* 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;
+ /* 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;
+ /* Connections accepted by this connection */
+ GSList *accepted_connections;
- /* callback */
- void (*func) (const char *message, gpointer user_data);
- gpointer data;
+ /* callback */
+ void (*func) (const char *message, gpointer user_data);
+ gpointer data;
};
static gboolean
test_is_socket (const char *path)
{
- struct stat s;
+ struct stat s;
- if (stat (path, &s) == -1)
- return FALSE;
+ if (stat (path, &s) == -1)
+ return FALSE;
- if (S_ISSOCK (s.st_mode))
- return TRUE;
+ if (S_ISSOCK (s.st_mode))
+ return TRUE;
- return FALSE;
+ return FALSE;
}
static gboolean
is_owned_by_user_and_socket (const char *path)
{
- struct stat s;
+ struct stat s;
- if (stat (path, &s) == -1)
- return FALSE;
+ if (stat (path, &s) == -1)
+ return FALSE;
- if (s.st_uid != geteuid ())
- return FALSE;
+ if (s.st_uid != geteuid ())
+ return FALSE;
- if ((s.st_mode & S_IFSOCK) != S_IFSOCK)
- return FALSE;
-
- return TRUE;
+ if ((s.st_mode & S_IFSOCK) != S_IFSOCK)
+ return FALSE;
+
+ return TRUE;
}
static gboolean server_cb (GIOChannel *source,
- GIOCondition condition, gpointer data);
+ GIOCondition condition, gpointer data);
static gboolean
setup_connection (BaconMessageConnection *conn)
{
- g_return_val_if_fail (conn->chan == NULL, FALSE);
+ 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);
+ 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;
+ return TRUE;
}
static void
accept_new_connection (BaconMessageConnection *server_conn)
{
- BaconMessageConnection *conn;
- int alen;
+ BaconMessageConnection *conn;
+ int alen;
- g_return_if_fail (server_conn->is_server);
+ 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 = 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);
+ conn->fd = accept (server_conn->fd, NULL, (guint *)&alen);
- server_conn->accepted_connections =
- g_slist_prepend (server_conn->accepted_connections, conn);
+ server_conn->accepted_connections =
+ g_slist_prepend (server_conn->accepted_connections, conn);
- setup_connection (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;
+ 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;
+ 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_tmp_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;
+ char *pattern, *newfile, *path, *filename;
+ const char *tmpdir;
+
+ pattern = g_strdup_printf ("%s.%s.*", prefix, g_get_user_name ());
+ tmpdir = g_get_tmp_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;
+ 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);
+ 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;
+ 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);
+ 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)
+ BaconMessageReceivedFunc func,
+ gpointer user_data)
{
- g_return_if_fail (conn != NULL);
+ g_return_if_fail (conn != NULL);
- conn->func = func;
- conn->data = user_data;
+ conn->func = func;
+ conn->data = user_data;
}
void
bacon_message_connection_send (BaconMessageConnection *conn,
- const char *message)
+ const char *message)
{
- g_return_if_fail (conn != NULL);
- g_return_if_fail (message != NULL);
+ 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);
+ 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);
+ g_return_val_if_fail (conn != NULL, FALSE);
- return conn->is_server;
+ return conn->is_server;
}
diff --git a/src/bacon-message-connection.h b/src/bacon-message-connection.h
index adefa62..1c70e43 100644
--- a/src/bacon-message-connection.h
+++ b/src/bacon-message-connection.h
@@ -25,18 +25,18 @@
G_BEGIN_DECLS
typedef void (*BaconMessageReceivedFunc) (const char *message,
- gpointer user_data);
+ 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);
+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
diff --git a/src/callbacks.cpp b/src/callbacks.cpp
index fbfb37d..cd42b87 100644
--- a/src/callbacks.cpp
+++ b/src/callbacks.cpp
@@ -116,7 +116,7 @@ void
cb_show_open_files (GtkAction *action, gpointer data)
{
ProcData *procdata = static_cast<ProcData*>(data);
-
+
create_openfiles_dialog (procdata);
}
diff --git a/src/callbacks.h b/src/callbacks.h
index faebbbb..35e8016 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -26,57 +26,57 @@
#include "gsm_color_button.h"
-void cb_show_memory_maps (GtkAction *action, gpointer data);
-void cb_show_open_files (GtkAction *action, gpointer data);
-void cb_show_lsof(GtkAction *action, gpointer data);
-void cb_renice (GtkAction *action, gpointer data);
-void cb_end_process (GtkAction *action, gpointer data);
-void cb_kill_process (GtkAction *action, gpointer data);
-void cb_edit_preferences (GtkAction *action, gpointer data);
+void cb_show_memory_maps (GtkAction *action, gpointer data);
+void cb_show_open_files (GtkAction *action, gpointer data);
+void cb_show_lsof(GtkAction *action, gpointer data);
+void cb_renice (GtkAction *action, gpointer data);
+void cb_end_process (GtkAction *action, gpointer data);
+void cb_kill_process (GtkAction *action, gpointer data);
+void cb_edit_preferences (GtkAction *action, gpointer data);
-void cb_help_contents (GtkAction *action, gpointer data);
-void cb_about (GtkAction *action, gpointer data);
+void cb_help_contents (GtkAction *action, gpointer data);
+void cb_about (GtkAction *action, gpointer data);
-void cb_app_exit (GtkAction *action, gpointer data);
-gboolean cb_app_delete (GtkWidget *window, GdkEventAny *event, gpointer data);
+void cb_app_exit (GtkAction *action, gpointer data);
+gboolean cb_app_delete (GtkWidget *window, GdkEventAny *event, gpointer data);
-void cb_end_process_button_pressed (GtkButton *button, gpointer data);
-void cb_logout (GtkButton *button, gpointer data);
+void cb_end_process_button_pressed (GtkButton *button, gpointer data);
+void cb_logout (GtkButton *button, gpointer data);
-void cb_info_button_pressed (GtkButton *button, gpointer user_data);
+void cb_info_button_pressed (GtkButton *button, gpointer user_data);
-void cb_cpu_color_changed (GSMColorButton *widget, gpointer user_data);
-void cb_mem_color_changed (GSMColorButton *widget, gpointer user_data);
-void cb_swap_color_changed (GSMColorButton *widget, gpointer user_data);
-void cb_net_in_color_changed (GSMColorButton *widget, gpointer user_data);
-void cb_net_out_color_changed (GSMColorButton *widget, gpointer user_data);
+void cb_cpu_color_changed (GSMColorButton *widget, gpointer user_data);
+void cb_mem_color_changed (GSMColorButton *widget, gpointer user_data);
+void cb_swap_color_changed (GSMColorButton *widget, gpointer user_data);
+void cb_net_in_color_changed (GSMColorButton *widget, gpointer user_data);
+void cb_net_out_color_changed (GSMColorButton *widget, gpointer user_data);
-void cb_row_selected (GtkTreeSelection *selection, gpointer data);
+void cb_row_selected (GtkTreeSelection *selection, gpointer data);
-gboolean cb_tree_popup_menu (GtkWidget *widget, gpointer data);
-gboolean cb_tree_button_pressed (GtkWidget *widget, GdkEventButton *event,
- gpointer data);
+gboolean cb_tree_popup_menu (GtkWidget *widget, gpointer data);
+gboolean cb_tree_button_pressed (GtkWidget *widget, GdkEventButton *event,
+ gpointer data);
-void cb_change_current_page (GtkNotebook *nb,
- gint num, gpointer data);
-void cb_switch_page (GtkNotebook *nb, GtkWidget *page,
- gint num, gpointer data);
+void cb_change_current_page (GtkNotebook *nb,
+ gint num, gpointer data);
+void cb_switch_page (GtkNotebook *nb, GtkWidget *page,
+ gint num, gpointer data);
-gint cb_update_disks (gpointer data);
-gint cb_user_refresh (GtkAction* action, gpointer data);
-gint cb_timeout (gpointer data);
+gint cb_update_disks (gpointer data);
+gint cb_user_refresh (GtkAction* action, gpointer data);
+gint cb_timeout (gpointer data);
-void cb_radio_processes(GtkAction *action,
- GtkRadioAction *current,
- gpointer data);
+void cb_radio_processes(GtkAction *action,
+ GtkRadioAction *current,
+ gpointer data);
-void cb_kill_sigstop(GtkAction *action,
- gpointer data);
+void cb_kill_sigstop(GtkAction *action,
+ gpointer data);
-void cb_kill_sigcont(GtkAction *action,
- gpointer data);
+void cb_kill_sigcont(GtkAction *action,
+ gpointer data);
#endif /* _PROCMAN_CALLBACKS_H_ */
diff --git a/src/defaulttable.h b/src/defaulttable.h
index 6b5a096..261dde5 100644
--- a/src/defaulttable.h
+++ b/src/defaulttable.h
@@ -9,41 +9,41 @@
struct PrettyTableItem
{
- Glib::RefPtr<Glib::Regex> command;
- std::string icon;
+ Glib::RefPtr<Glib::Regex> command;
+ std::string icon;
- PrettyTableItem(const std::string& a_command, const std::string& a_icon)
- : command(Glib::Regex::create("^(" + a_command + ")$")),
- icon(a_icon)
- { }
+PrettyTableItem(const std::string& a_command, const std::string& a_icon)
+: command(Glib::Regex::create("^(" + a_command + ")$")),
+ icon(a_icon)
+ { }
};
#define ITEM PrettyTableItem
/* The current table is only a test */
static const PrettyTableItem default_table[] = {
- ITEM("(ba|z|tc|c|k)?sh", "utilities-terminal"),
- ITEM("(k|sys|u)logd|logger", "internet-news-reader"),
- ITEM("X(org)?", "display"),
- ITEM("apache2?|httpd|lighttpd", "internet-web-browser"),
- ITEM(".*applet(-?2)?", "mate-applets"),
- ITEM("atd|cron|CRON|ntpd", "date"),
- ITEM("cupsd|lpd?", "printer"),
- ITEM("cvsd|mtn|git|svn", "file-manager"),
- ITEM("emacs(server|\\d+)?", "mate-emacs"),
- ITEM("evolution.*", "internet-mail"),
- ITEM("famd|gam_server", "file-manager"),
- ITEM("mateconfd-2", "preferences-desktop"),
- ITEM("getty", "input-keyboard"),
- ITEM("gdb|((gcc|g\\+\\+)(-.*)?)|ar|ld|make", "applications-development"),
- ITEM("marco", "mate-window-manager"),
- ITEM("sendmail|exim\\d?", "internet-mail"),
- ITEM("squid", "proxy"),
- ITEM("ssh(d|-agent)", "ssh-askpass-mate"),
- ITEM("top|vmstat", "system-monitor"),
- ITEM("vim?", "vim"),
- ITEM("x?inetd", "internet-web-browser"),
- ITEM("vino.*", "mate-remote-desktop")
+ ITEM("(ba|z|tc|c|k)?sh", "utilities-terminal"),
+ ITEM("(k|sys|u)logd|logger", "internet-news-reader"),
+ ITEM("X(org)?", "display"),
+ ITEM("apache2?|httpd|lighttpd", "internet-web-browser"),
+ ITEM(".*applet(-?2)?", "mate-applets"),
+ ITEM("atd|cron|CRON|ntpd", "date"),
+ ITEM("cupsd|lpd?", "printer"),
+ ITEM("cvsd|mtn|git|svn", "file-manager"),
+ ITEM("emacs(server|\\d+)?", "mate-emacs"),
+ ITEM("evolution.*", "internet-mail"),
+ ITEM("famd|gam_server", "file-manager"),
+ ITEM("mateconfd-2", "preferences-desktop"),
+ ITEM("getty", "input-keyboard"),
+ ITEM("gdb|((gcc|g\\+\\+)(-.*)?)|ar|ld|make", "applications-development"),
+ ITEM("marco", "mate-window-manager"),
+ ITEM("sendmail|exim\\d?", "internet-mail"),
+ ITEM("squid", "proxy"),
+ ITEM("ssh(d|-agent)", "ssh-askpass-mate"),
+ ITEM("top|vmstat", "system-monitor"),
+ ITEM("vim?", "vim"),
+ ITEM("x?inetd", "internet-web-browser"),
+ ITEM("vino.*", "mate-remote-desktop")
};
#undef ITEM
diff --git a/src/disks.cpp b/src/disks.cpp
index 97ac949..9b865fa 100644
--- a/src/disks.cpp
+++ b/src/disks.cpp
@@ -15,120 +15,120 @@
enum DiskColumns
{
- /* string columns* */
- DISK_DEVICE,
- DISK_DIR,
- DISK_TYPE,
- DISK_TOTAL,
- DISK_FREE,
- DISK_AVAIL,
- /* USED has to be the last column */
- DISK_USED,
- // then unvisible columns
- /* PixBuf column */
- DISK_ICON,
- /* numeric columns */
- DISK_USED_PERCENTAGE,
- DISK_N_COLUMNS
+ /* string columns* */
+ DISK_DEVICE,
+ DISK_DIR,
+ DISK_TYPE,
+ DISK_TOTAL,
+ DISK_FREE,
+ DISK_AVAIL,
+ /* USED has to be the last column */
+ DISK_USED,
+ // then unvisible columns
+ /* PixBuf column */
+ DISK_ICON,
+ /* numeric columns */
+ DISK_USED_PERCENTAGE,
+ DISK_N_COLUMNS
};
static void
fsusage_stats(const glibtop_fsusage *buf,
- guint64 *bused, guint64 *bfree, guint64 *bavail, guint64 *btotal,
- gint *percentage)
+ guint64 *bused, guint64 *bfree, guint64 *bavail, guint64 *btotal,
+ gint *percentage)
{
- guint64 total = buf->blocks * buf->block_size;
-
- if (!total) {
- /* not a real device */
- *btotal = *bfree = *bavail = *bused = 0ULL;
- *percentage = 0;
- } else {
- int percent;
- *btotal = total;
- *bfree = buf->bfree * buf->block_size;
- *bavail = buf->bavail * buf->block_size;
- *bused = *btotal - *bfree;
- /* percent = 100.0f * *bused / *btotal; */
- percent = 100 * *bused / (*bused + *bavail);
- *percentage = CLAMP(percent, 0, 100);
- }
+ guint64 total = buf->blocks * buf->block_size;
+
+ if (!total) {
+ /* not a real device */
+ *btotal = *bfree = *bavail = *bused = 0ULL;
+ *percentage = 0;
+ } else {
+ int percent;
+ *btotal = total;
+ *bfree = buf->bfree * buf->block_size;
+ *bavail = buf->bavail * buf->block_size;
+ *bused = *btotal - *bfree;
+ /* percent = 100.0f * *bused / *btotal; */
+ percent = 100 * *bused / (*bused + *bavail);
+ *percentage = CLAMP(percent, 0, 100);
+ }
}
namespace
{
- string get_icon_for_path(const std::string& path)
- {
- using namespace Glib;
- using namespace Gio;
-
- // FIXME: I don't know whether i should use Volume or Mount or UnixMount
- // all i need an icon name.
- RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
-
- std::vector<RefPtr<Mount> > mounts = monitor->get_mounts();
-
- for (size_t i = 0; i != mounts.size(); ++i) {
- if (mounts[i]->get_name() != path)
- continue;
-
- RefPtr<Icon> icon = mounts[i]->get_icon();
- RefPtr<ThemedIcon> themed_icon = RefPtr<ThemedIcon>::cast_dynamic(icon);
-
- if (themed_icon) {
- char* name = 0;
- // FIXME: not wrapped yet
- g_object_get(G_OBJECT(themed_icon->gobj()), "name", &name, NULL);
- return make_string(name);
- }
- }
+ string get_icon_for_path(const std::string& path)
+ {
+ using namespace Glib;
+ using namespace Gio;
+
+ // FIXME: I don't know whether i should use Volume or Mount or UnixMount
+ // all i need an icon name.
+ RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
+
+ std::vector<RefPtr<Mount> > mounts = monitor->get_mounts();
+
+ for (size_t i = 0; i != mounts.size(); ++i) {
+ if (mounts[i]->get_name() != path)
+ continue;
+
+ RefPtr<Icon> icon = mounts[i]->get_icon();
+ RefPtr<ThemedIcon> themed_icon = RefPtr<ThemedIcon>::cast_dynamic(icon);
+
+ if (themed_icon) {
+ char* name = 0;
+ // FIXME: not wrapped yet
+ g_object_get(G_OBJECT(themed_icon->gobj()), "name", &name, NULL);
+ return make_string(name);
+ }
+ }
- return "";
- }
+ return "";
+ }
}
static Glib::RefPtr<Gdk::Pixbuf>
get_icon_for_device(const char *mountpoint)
{
- procman::IconThemeWrapper icon_theme;
- string icon_name = get_icon_for_path(mountpoint);
- if (icon_name == "")
- // FIXME: defaults to a safe value
- icon_name = "drive-harddisk"; // get_icon_for_path("/");
- return icon_theme->load_icon(icon_name, 24, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ procman::IconThemeWrapper icon_theme;
+ string icon_name = get_icon_for_path(mountpoint);
+ if (icon_name == "")
+ // FIXME: defaults to a safe value
+ icon_name = "drive-harddisk"; // get_icon_for_path("/");
+ return icon_theme->load_icon(icon_name, 24, Gtk::ICON_LOOKUP_USE_BUILTIN);
}
static gboolean
find_disk_in_model(GtkTreeModel *model, const char *mountpoint,
- GtkTreeIter *result)
+ GtkTreeIter *result)
{
- GtkTreeIter iter;
- gboolean found = FALSE;
+ GtkTreeIter iter;
+ gboolean found = FALSE;
- if (gtk_tree_model_get_iter_first(model, &iter)) {
- do {
- char *dir;
+ if (gtk_tree_model_get_iter_first(model, &iter)) {
+ do {
+ char *dir;
- gtk_tree_model_get(model, &iter,
- DISK_DIR, &dir,
- -1);
+ gtk_tree_model_get(model, &iter,
+ DISK_DIR, &dir,
+ -1);
- if (dir && !strcmp(dir, mountpoint)) {
- *result = iter;
- found = TRUE;
- }
+ if (dir && !strcmp(dir, mountpoint)) {
+ *result = iter;
+ found = TRUE;
+ }
- g_free(dir);
+ g_free(dir);
- } while (!found && gtk_tree_model_iter_next(model, &iter));
- }
+ } while (!found && gtk_tree_model_iter_next(model, &iter));
+ }
- return found;
+ return found;
}
@@ -136,39 +136,39 @@ find_disk_in_model(GtkTreeModel *model, const char *mountpoint,
static void
remove_old_disks(GtkTreeModel *model, const glibtop_mountentry *entries, guint n)
{
- GtkTreeIter iter;
-
- if (!gtk_tree_model_get_iter_first(model, &iter))
- return;
-
- while (true) {
- char *dir;
- guint i;
- gboolean found = FALSE;
-
- gtk_tree_model_get(model, &iter,
- DISK_DIR, &dir,
- -1);
-
- for (i = 0; i != n; ++i) {
- if (!strcmp(dir, entries[i].mountdir)) {
- found = TRUE;
- break;
- }
- }
-
- g_free(dir);
-
- if (!found) {
- if (!gtk_list_store_remove(GTK_LIST_STORE(model), &iter))
- break;
- else
- continue;
- }
-
- if (!gtk_tree_model_iter_next(model, &iter))
- break;
- }
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter_first(model, &iter))
+ return;
+
+ while (true) {
+ char *dir;
+ guint i;
+ gboolean found = FALSE;
+
+ gtk_tree_model_get(model, &iter,
+ DISK_DIR, &dir,
+ -1);
+
+ for (i = 0; i != n; ++i) {
+ if (!strcmp(dir, entries[i].mountdir)) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ g_free(dir);
+
+ if (!found) {
+ if (!gtk_list_store_remove(GTK_LIST_STORE(model), &iter))
+ break;
+ else
+ continue;
+ }
+
+ if (!gtk_tree_model_iter_next(model, &iter))
+ break;
+ }
}
@@ -176,41 +176,41 @@ remove_old_disks(GtkTreeModel *model, const glibtop_mountentry *entries, guint n
static void
add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
{
- Glib::RefPtr<Gdk::Pixbuf> pixbuf;
- GtkTreeIter iter;
- glibtop_fsusage usage;
- guint64 bused, bfree, bavail, btotal;
- gint percentage;
-
- glibtop_get_fsusage(&usage, entry->mountdir);
-
- if (not show_all_fs and usage.blocks == 0) {
- if (find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
- gtk_list_store_remove(list, &iter);
- return;
- }
-
- fsusage_stats(&usage, &bused, &bfree, &bavail, &btotal, &percentage);
- pixbuf = get_icon_for_device(entry->mountdir);
-
- /* if we can find a row with the same mountpoint, we get it but we
- still need to update all the fields.
- This makes selection persistent.
- */
- if (!find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
- gtk_list_store_append(list, &iter);
-
- gtk_list_store_set(list, &iter,
- DISK_ICON, pixbuf->gobj(),
- DISK_DEVICE, entry->devname,
- DISK_DIR, entry->mountdir,
- DISK_TYPE, entry->type,
- DISK_USED_PERCENTAGE, percentage,
- DISK_TOTAL, btotal,
- DISK_FREE, bfree,
- DISK_AVAIL, bavail,
- DISK_USED, bused,
- -1);
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf;
+ GtkTreeIter iter;
+ glibtop_fsusage usage;
+ guint64 bused, bfree, bavail, btotal;
+ gint percentage;
+
+ glibtop_get_fsusage(&usage, entry->mountdir);
+
+ if (not show_all_fs and usage.blocks == 0) {
+ if (find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
+ gtk_list_store_remove(list, &iter);
+ return;
+ }
+
+ fsusage_stats(&usage, &bused, &bfree, &bavail, &btotal, &percentage);
+ pixbuf = get_icon_for_device(entry->mountdir);
+
+ /* if we can find a row with the same mountpoint, we get it but we
+ still need to update all the fields.
+ This makes selection persistent.
+ */
+ if (!find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
+ gtk_list_store_append(list, &iter);
+
+ gtk_list_store_set(list, &iter,
+ DISK_ICON, pixbuf->gobj(),
+ DISK_DEVICE, entry->devname,
+ DISK_DIR, entry->mountdir,
+ DISK_TYPE, entry->type,
+ DISK_USED_PERCENTAGE, percentage,
+ DISK_TOTAL, btotal,
+ DISK_FREE, bfree,
+ DISK_AVAIL, bavail,
+ DISK_USED, bused,
+ -1);
}
@@ -218,204 +218,204 @@ add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
int
cb_update_disks(gpointer data)
{
- ProcData *const procdata = static_cast<ProcData*>(data);
+ ProcData *const procdata = static_cast<ProcData*>(data);
- GtkListStore *list;
- glibtop_mountentry * entries;
- glibtop_mountlist mountlist;
- guint i;
+ GtkListStore *list;
+ glibtop_mountentry * entries;
+ glibtop_mountlist mountlist;
+ guint i;
- list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->disk_list)));
+ list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->disk_list)));
- entries = glibtop_get_mountlist(&mountlist, procdata->config.show_all_fs);
+ entries = glibtop_get_mountlist(&mountlist, procdata->config.show_all_fs);
- remove_old_disks(GTK_TREE_MODEL(list), entries, mountlist.number);
+ remove_old_disks(GTK_TREE_MODEL(list), entries, mountlist.number);
- for (i = 0; i < mountlist.number; i++)
- add_disk(list, &entries[i], procdata->config.show_all_fs);
+ for (i = 0; i < mountlist.number; i++)
+ add_disk(list, &entries[i], procdata->config.show_all_fs);
- g_free(entries);
+ g_free(entries);
- return TRUE;
+ return TRUE;
}
static void
cb_disk_columns_changed(GtkTreeView *treeview, gpointer user_data)
{
- ProcData * const procdata = static_cast<ProcData*>(user_data);
+ ProcData * const procdata = static_cast<ProcData*>(user_data);
- procman_save_tree_state(procdata->settings,
- GTK_WIDGET(treeview),
- "disktreenew");
+ procman_save_tree_state(procdata->settings,
+ GTK_WIDGET(treeview),
+ "disktreenew");
}
static void open_dir(GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- gpointer user_data)
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
{
- GtkTreeIter iter;
- GtkTreeModel *model;
- char *dir, *url;
-
- model = gtk_tree_view_get_model(tree_view);
-
- if (!gtk_tree_model_get_iter(model, &iter, path)) {
- char *p;
- p = gtk_tree_path_to_string(path);
- g_warning("Cannot get iter for path '%s'\n", p);
- g_free(p);
- return;
- }
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ char *dir, *url;
+
+ model = gtk_tree_view_get_model(tree_view);
+
+ if (!gtk_tree_model_get_iter(model, &iter, path)) {
+ char *p;
+ p = gtk_tree_path_to_string(path);
+ g_warning("Cannot get iter for path '%s'\n", p);
+ g_free(p);
+ return;
+ }
- gtk_tree_model_get(model, &iter, DISK_DIR, &dir, -1);
+ gtk_tree_model_get(model, &iter, DISK_DIR, &dir, -1);
- url = g_strdup_printf("file://%s", dir);
+ url = g_strdup_printf("file://%s", dir);
- GError* error = 0;
- if (!g_app_info_launch_default_for_uri(url, NULL, &error)) {
- g_warning("Cannot open '%s' : %s\n", url, error->message);
- g_error_free(error);
- }
+ GError* error = 0;
+ if (!g_app_info_launch_default_for_uri(url, NULL, &error)) {
+ g_warning("Cannot open '%s' : %s\n", url, error->message);
+ g_error_free(error);
+ }
- g_free(url);
- g_free(dir);
+ g_free(url);
+ g_free(dir);
}
GtkWidget *
create_disk_view(ProcData *procdata)
{
- GtkWidget *disk_box;
- GtkWidget *scrolled;
- GtkWidget *disk_tree;
- GtkListStore *model;
- GtkTreeViewColumn *col;
- GtkCellRenderer *cell;
- guint i;
-
- const gchar * const titles[] = {
- N_("Device"),
- N_("Directory"),
- N_("Type"),
- N_("Total"),
- N_("Free"),
- N_("Available"),
- N_("Used")
- };
-
- disk_box = gtk_vbox_new(FALSE, 6);
-
- gtk_container_set_border_width(GTK_CONTAINER(disk_box), 12);
-
- scrolled = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
- GTK_SHADOW_IN);
-
- gtk_box_pack_start(GTK_BOX(disk_box), scrolled, TRUE, TRUE, 0);
-
- model = gtk_list_store_new(DISK_N_COLUMNS, /* n columns */
- G_TYPE_STRING, /* DISK_DEVICE */
- G_TYPE_STRING, /* DISK_DIR */
- G_TYPE_STRING, /* DISK_TYPE */
- G_TYPE_UINT64, /* DISK_TOTAL */
- G_TYPE_UINT64, /* DISK_FREE */
- G_TYPE_UINT64, /* DISK_AVAIL */
- G_TYPE_UINT64, /* DISK_USED */
- GDK_TYPE_PIXBUF, /* DISK_ICON */
- G_TYPE_INT /* DISK_USED_PERCENTAGE */
- );
-
- disk_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
- g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL);
- procdata->disk_list = disk_tree;
- gtk_container_add(GTK_CONTAINER(scrolled), disk_tree);
- gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(disk_tree), TRUE);
- g_object_unref(G_OBJECT(model));
-
- /* icon + device */
-
- col = gtk_tree_view_column_new();
- cell = gtk_cell_renderer_pixbuf_new();
- gtk_tree_view_column_pack_start(col, cell, FALSE);
- gtk_tree_view_column_set_attributes(col, cell, "pixbuf", DISK_ICON,
- NULL);
-
- cell = gtk_cell_renderer_text_new();
- gtk_tree_view_column_pack_start(col, cell, FALSE);
- gtk_tree_view_column_set_attributes(col, cell, "text", DISK_DEVICE,
- NULL);
- gtk_tree_view_column_set_title(col, _(titles[DISK_DEVICE]));
- gtk_tree_view_column_set_sort_column_id(col, DISK_DEVICE);
- gtk_tree_view_column_set_reorderable(col, TRUE);
- gtk_tree_view_column_set_resizable(col, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
-
- /* sizes - used */
-
- for (i = DISK_DIR; i <= DISK_AVAIL; i++) {
- cell = gtk_cell_renderer_text_new();
- col = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start(col, cell, TRUE);
- gtk_tree_view_column_set_title(col, _(titles[i]));
- gtk_tree_view_column_set_resizable(col, TRUE);
- gtk_tree_view_column_set_sort_column_id(col, i);
- gtk_tree_view_column_set_reorderable(col, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
-
- switch (i) {
- case DISK_TOTAL:
- case DISK_FREE:
- case DISK_AVAIL:
- g_object_set(cell, "xalign", 1.0f, NULL);
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::size_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- default:
- gtk_tree_view_column_set_attributes(col, cell,
- "text", i,
- NULL);
- break;
- }
- }
-
- /* used + percentage */
-
- col = gtk_tree_view_column_new();
- cell = gtk_cell_renderer_text_new();
- g_object_set(cell, "xalign", 1.0f, NULL);
- gtk_tree_view_column_pack_start(col, cell, FALSE);
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::size_cell_data_func,
- GUINT_TO_POINTER(DISK_USED),
- NULL);
- gtk_tree_view_column_set_title(col, _(titles[DISK_USED]));
-
- cell = gtk_cell_renderer_progress_new();
- gtk_tree_view_column_pack_start(col, cell, TRUE);
- gtk_tree_view_column_set_attributes(col, cell, "value",
- DISK_USED_PERCENTAGE, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
- gtk_tree_view_column_set_resizable(col, TRUE);
- gtk_tree_view_column_set_sort_column_id(col, DISK_USED);
- gtk_tree_view_column_set_reorderable(col, TRUE);
-
- /* numeric sort */
-
- gtk_widget_show_all(disk_box);
-
- procman_get_tree_state(procdata->settings, disk_tree,
- "disktreenew");
-
- g_signal_connect (G_OBJECT(disk_tree), "columns-changed",
- G_CALLBACK(cb_disk_columns_changed), procdata);
-
- return disk_box;
+ GtkWidget *disk_box;
+ GtkWidget *scrolled;
+ GtkWidget *disk_tree;
+ GtkListStore *model;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *cell;
+ guint i;
+
+ const gchar * const titles[] = {
+ N_("Device"),
+ N_("Directory"),
+ N_("Type"),
+ N_("Total"),
+ N_("Free"),
+ N_("Available"),
+ N_("Used")
+ };
+
+ disk_box = gtk_vbox_new(FALSE, 6);
+
+ gtk_container_set_border_width(GTK_CONTAINER(disk_box), 12);
+
+ scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_SHADOW_IN);
+
+ gtk_box_pack_start(GTK_BOX(disk_box), scrolled, TRUE, TRUE, 0);
+
+ model = gtk_list_store_new(DISK_N_COLUMNS, /* n columns */
+ G_TYPE_STRING, /* DISK_DEVICE */
+ G_TYPE_STRING, /* DISK_DIR */
+ G_TYPE_STRING, /* DISK_TYPE */
+ G_TYPE_UINT64, /* DISK_TOTAL */
+ G_TYPE_UINT64, /* DISK_FREE */
+ G_TYPE_UINT64, /* DISK_AVAIL */
+ G_TYPE_UINT64, /* DISK_USED */
+ GDK_TYPE_PIXBUF, /* DISK_ICON */
+ G_TYPE_INT /* DISK_USED_PERCENTAGE */
+ );
+
+ disk_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+ g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL);
+ procdata->disk_list = disk_tree;
+ gtk_container_add(GTK_CONTAINER(scrolled), disk_tree);
+ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(disk_tree), TRUE);
+ g_object_unref(G_OBJECT(model));
+
+ /* icon + device */
+
+ col = gtk_tree_view_column_new();
+ cell = gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_column_pack_start(col, cell, FALSE);
+ gtk_tree_view_column_set_attributes(col, cell, "pixbuf", DISK_ICON,
+ NULL);
+
+ cell = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(col, cell, FALSE);
+ gtk_tree_view_column_set_attributes(col, cell, "text", DISK_DEVICE,
+ NULL);
+ gtk_tree_view_column_set_title(col, _(titles[DISK_DEVICE]));
+ gtk_tree_view_column_set_sort_column_id(col, DISK_DEVICE);
+ gtk_tree_view_column_set_reorderable(col, TRUE);
+ gtk_tree_view_column_set_resizable(col, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
+
+ /* sizes - used */
+
+ for (i = DISK_DIR; i <= DISK_AVAIL; i++) {
+ cell = gtk_cell_renderer_text_new();
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start(col, cell, TRUE);
+ gtk_tree_view_column_set_title(col, _(titles[i]));
+ gtk_tree_view_column_set_resizable(col, TRUE);
+ gtk_tree_view_column_set_sort_column_id(col, i);
+ gtk_tree_view_column_set_reorderable(col, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
+
+ switch (i) {
+ case DISK_TOTAL:
+ case DISK_FREE:
+ case DISK_AVAIL:
+ g_object_set(cell, "xalign", 1.0f, NULL);
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::size_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ default:
+ gtk_tree_view_column_set_attributes(col, cell,
+ "text", i,
+ NULL);
+ break;
+ }
+ }
+
+ /* used + percentage */
+
+ col = gtk_tree_view_column_new();
+ cell = gtk_cell_renderer_text_new();
+ g_object_set(cell, "xalign", 1.0f, NULL);
+ gtk_tree_view_column_pack_start(col, cell, FALSE);
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::size_cell_data_func,
+ GUINT_TO_POINTER(DISK_USED),
+ NULL);
+ gtk_tree_view_column_set_title(col, _(titles[DISK_USED]));
+
+ cell = gtk_cell_renderer_progress_new();
+ gtk_tree_view_column_pack_start(col, cell, TRUE);
+ gtk_tree_view_column_set_attributes(col, cell, "value",
+ DISK_USED_PERCENTAGE, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
+ gtk_tree_view_column_set_resizable(col, TRUE);
+ gtk_tree_view_column_set_sort_column_id(col, DISK_USED);
+ gtk_tree_view_column_set_reorderable(col, TRUE);
+
+ /* numeric sort */
+
+ gtk_widget_show_all(disk_box);
+
+ procman_get_tree_state(procdata->settings, disk_tree,
+ "disktreenew");
+
+ g_signal_connect (G_OBJECT(disk_tree), "columns-changed",
+ G_CALLBACK(cb_disk_columns_changed), procdata);
+
+ return disk_box;
}
diff --git a/src/e_date.c b/src/e_date.c
index 9b9a894..bca3165 100644
--- a/src/e_date.c
+++ b/src/e_date.c
@@ -17,27 +17,27 @@
static size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
{
#ifdef HAVE_LKSTRFTIME
- return strftime(s, max, fmt, tm);
+ return strftime(s, max, fmt, tm);
#else
- char *c, *ffmt, *ff;
- size_t ret;
-
- ffmt = g_strdup(fmt);
- ff = ffmt;
- while ((c = strstr(ff, "%l")) != NULL) {
- c[1] = 'I';
- ff = c;
- }
-
- ff = ffmt;
- while ((c = strstr(ff, "%k")) != NULL) {
- c[1] = 'H';
- ff = c;
- }
-
- ret = strftime(s, max, ffmt, tm);
- g_free(ffmt);
- return ret;
+ char *c, *ffmt, *ff;
+ size_t ret;
+
+ ffmt = g_strdup(fmt);
+ ff = ffmt;
+ while ((c = strstr(ff, "%l")) != NULL) {
+ c[1] = 'I';
+ ff = c;
+ }
+
+ ff = ffmt;
+ while ((c = strstr(ff, "%k")) != NULL) {
+ c[1] = 'H';
+ ff = c;
+ }
+
+ ret = strftime(s, max, ffmt, tm);
+ g_free(ffmt);
+ return ret;
#endif
}
@@ -62,146 +62,146 @@ static size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *
static size_t e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
{
- char buf[10];
- char *sp;
- char *ffmt;
- size_t ret;
-
- if (strstr(fmt, "%p")==NULL && strstr(fmt, "%P")==NULL) {
- /* No AM/PM involved - can use the fmt string directly */
- ret=e_strftime(s, max, fmt, tm);
- } else {
- /* Get the AM/PM symbol from the locale */
- e_strftime (buf, 10, "%p", tm);
-
- if (buf[0]) {
- /**
- * AM/PM have been defined in the locale
- * so we can use the fmt string directly
- **/
- ret=e_strftime(s, max, fmt, tm);
- } else {
- /**
- * No AM/PM defined by locale
- * must change to 24 hour clock
- **/
- ffmt=g_strdup(fmt);
- for (sp=ffmt; (sp=strstr(sp, "%l")); sp++) {
- /**
- * Maybe this should be 'k', but I have never
- * seen a 24 clock actually use that format
- **/
- sp[1]='H';
- }
- for (sp=ffmt; (sp=strstr(sp, "%I")); sp++) {
- sp[1]='H';
- }
- ret=e_strftime(s, max, ffmt, tm);
- g_free(ffmt);
- }
- }
- return(ret);
+ char buf[10];
+ char *sp;
+ char *ffmt;
+ size_t ret;
+
+ if (strstr(fmt, "%p")==NULL && strstr(fmt, "%P")==NULL) {
+ /* No AM/PM involved - can use the fmt string directly */
+ ret=e_strftime(s, max, fmt, tm);
+ } else {
+ /* Get the AM/PM symbol from the locale */
+ e_strftime (buf, 10, "%p", tm);
+
+ if (buf[0]) {
+ /**
+ * AM/PM have been defined in the locale
+ * so we can use the fmt string directly
+ **/
+ ret=e_strftime(s, max, fmt, tm);
+ } else {
+ /**
+ * No AM/PM defined by locale
+ * must change to 24 hour clock
+ **/
+ ffmt=g_strdup(fmt);
+ for (sp=ffmt; (sp=strstr(sp, "%l")); sp++) {
+ /**
+ * Maybe this should be 'k', but I have never
+ * seen a 24 clock actually use that format
+ **/
+ sp[1]='H';
+ }
+ for (sp=ffmt; (sp=strstr(sp, "%I")); sp++) {
+ sp[1]='H';
+ }
+ ret=e_strftime(s, max, ffmt, tm);
+ g_free(ffmt);
+ }
+ }
+ return(ret);
}
-static size_t
+static size_t
e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
{
- size_t sz, ret;
- char *locale_fmt, *buf;
-
- locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
- if (!locale_fmt)
- return 0;
-
- ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
- if (!ret) {
- g_free (locale_fmt);
- return 0;
- }
-
- buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
- if (!buf) {
- g_free (locale_fmt);
- return 0;
- }
-
- if (sz >= max) {
- char *tmp = buf + max - 1;
- tmp = g_utf8_find_prev_char(buf, tmp);
- if (tmp)
- sz = tmp - buf;
- else
- sz = 0;
- }
- memcpy(s, buf, sz);
- s[sz] = '\0';
- g_free(locale_fmt);
- g_free(buf);
- return sz;
+ size_t sz, ret;
+ char *locale_fmt, *buf;
+
+ locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+ if (!locale_fmt)
+ return 0;
+
+ ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
+ if (!ret) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
+ buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ if (!buf) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
+ if (sz >= max) {
+ char *tmp = buf + max - 1;
+ tmp = g_utf8_find_prev_char(buf, tmp);
+ if (tmp)
+ sz = tmp - buf;
+ else
+ sz = 0;
+ }
+ memcpy(s, buf, sz);
+ s[sz] = '\0';
+ g_free(locale_fmt);
+ g_free(buf);
+ return sz;
}
static char *
filter_date (time_t date)
{
- time_t nowdate = time(NULL);
- time_t yesdate;
- struct tm then, now, yesterday;
- char buf[26];
- gboolean done = FALSE;
-
- if (date == 0)
- // xgettext: ? stands for unknown
- return g_strdup (_("?"));
-
- localtime_r (&date, &then);
- localtime_r (&nowdate, &now);
- if (then.tm_mday == now.tm_mday &&
- then.tm_mon == now.tm_mon &&
- then.tm_year == now.tm_year) {
- e_utf8_strftime_fix_am_pm (buf, 26, _("Today %l:%M %p"), &then);
- done = TRUE;
- }
- if (!done) {
- yesdate = nowdate - 60 * 60 * 24;
- localtime_r (&yesdate, &yesterday);
- if (then.tm_mday == yesterday.tm_mday &&
- then.tm_mon == yesterday.tm_mon &&
- then.tm_year == yesterday.tm_year) {
- e_utf8_strftime_fix_am_pm (buf, 26, _("Yesterday %l:%M %p"), &then);
- done = TRUE;
- }
- }
- if (!done) {
- int i;
- for (i = 2; i < 7; i++) {
- yesdate = nowdate - 60 * 60 * 24 * i;
- localtime_r (&yesdate, &yesterday);
- if (then.tm_mday == yesterday.tm_mday &&
- then.tm_mon == yesterday.tm_mon &&
- then.tm_year == yesterday.tm_year) {
- e_utf8_strftime_fix_am_pm (buf, 26, _("%a %l:%M %p"), &then);
- done = TRUE;
- break;
- }
- }
- }
- if (!done) {
- if (then.tm_year == now.tm_year) {
- e_utf8_strftime_fix_am_pm (buf, 26, _("%b %d %l:%M %p"), &then);
- } else {
- e_utf8_strftime_fix_am_pm (buf, 26, _("%b %d %Y"), &then);
- }
- }
+ time_t nowdate = time(NULL);
+ time_t yesdate;
+ struct tm then, now, yesterday;
+ char buf[26];
+ gboolean done = FALSE;
+
+ if (date == 0)
+ // xgettext: ? stands for unknown
+ return g_strdup (_("?"));
+
+ localtime_r (&date, &then);
+ localtime_r (&nowdate, &now);
+ if (then.tm_mday == now.tm_mday &&
+ then.tm_mon == now.tm_mon &&
+ then.tm_year == now.tm_year) {
+ e_utf8_strftime_fix_am_pm (buf, 26, _("Today %l:%M %p"), &then);
+ done = TRUE;
+ }
+ if (!done) {
+ yesdate = nowdate - 60 * 60 * 24;
+ localtime_r (&yesdate, &yesterday);
+ if (then.tm_mday == yesterday.tm_mday &&
+ then.tm_mon == yesterday.tm_mon &&
+ then.tm_year == yesterday.tm_year) {
+ e_utf8_strftime_fix_am_pm (buf, 26, _("Yesterday %l:%M %p"), &then);
+ done = TRUE;
+ }
+ }
+ if (!done) {
+ int i;
+ for (i = 2; i < 7; i++) {
+ yesdate = nowdate - 60 * 60 * 24 * i;
+ localtime_r (&yesdate, &yesterday);
+ if (then.tm_mday == yesterday.tm_mday &&
+ then.tm_mon == yesterday.tm_mon &&
+ then.tm_year == yesterday.tm_year) {
+ e_utf8_strftime_fix_am_pm (buf, 26, _("%a %l:%M %p"), &then);
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ if (!done) {
+ if (then.tm_year == now.tm_year) {
+ e_utf8_strftime_fix_am_pm (buf, 26, _("%b %d %l:%M %p"), &then);
+ } else {
+ e_utf8_strftime_fix_am_pm (buf, 26, _("%b %d %Y"), &then);
+ }
+ }
#if 0
#ifdef CTIME_R_THREE_ARGS
- ctime_r (&date, buf, 26);
+ ctime_r (&date, buf, 26);
#else
- ctime_r (&date, buf);
+ ctime_r (&date, buf);
#endif
#endif
- return g_strdup (buf);
+ return g_strdup (buf);
}
@@ -210,5 +210,5 @@ filter_date (time_t date)
char *
procman_format_date_for_display(time_t d)
{
- return filter_date(d);
+ return filter_date(d);
}
diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c
index ffcf270..b22407c 100644
--- a/src/gsm_color_button.c
+++ b/src/gsm_color_button.c
@@ -38,33 +38,33 @@
struct _GSMColorButtonPrivate
{
- GtkWidget *cs_dialog; /* Color selection dialog */
+ GtkWidget *cs_dialog; /* Color selection dialog */
- gchar *title; /* Title for the color selection window */
+ gchar *title; /* Title for the color selection window */
- GdkColor color;
+ GdkColor color;
- gdouble fraction; /* Only used by GSMCP_TYPE_PIE */
- guint type;
- cairo_surface_t *image_buffer;
- gdouble highlight;
+ gdouble fraction; /* Only used by GSMCP_TYPE_PIE */
+ guint type;
+ cairo_surface_t *image_buffer;
+ gdouble highlight;
};
/* Properties */
enum
{
- PROP_0,
- PROP_PERCENTAGE,
- PROP_TITLE,
- PROP_COLOR,
- PROP_TYPE
+ PROP_0,
+ PROP_PERCENTAGE,
+ PROP_TITLE,
+ PROP_COLOR,
+ PROP_TYPE
};
/* Signals */
enum
{
- COLOR_SET,
- LAST_SIGNAL
+ COLOR_SET,
+ LAST_SIGNAL
};
#define GSMCP_MIN_WIDTH 15
@@ -75,52 +75,52 @@ static void gsm_color_button_class_init (GSMColorButtonClass * klass);
static void gsm_color_button_init (GSMColorButton * color_button);
static void gsm_color_button_finalize (GObject * object);
static void gsm_color_button_set_property (GObject * object, guint param_id,
- const GValue * value,
- GParamSpec * pspec);
+ const GValue * value,
+ GParamSpec * pspec);
static void gsm_color_button_get_property (GObject * object, guint param_id,
- GValue * value,
- GParamSpec * pspec);
+ GValue * value,
+ GParamSpec * pspec);
static void gsm_color_button_realize (GtkWidget * widget);
#if GTK_CHECK_VERSION(3,0,0)
static void gsm_color_button_get_preferred_width (GtkWidget * widget, gint * minimum_width, gint * natural_width);
static void gsm_color_button_get_preferred_height (GtkWidget * widget, gint * minimum_height, gint * natural_height);
#else
static void gsm_color_button_size_request (GtkWidget * widget,
- GtkRequisition * requisition);
+ GtkRequisition * requisition);
#endif
static void gsm_color_button_size_allocate (GtkWidget * widget,
- GtkAllocation * allocation);
+ GtkAllocation * allocation);
static void gsm_color_button_unrealize (GtkWidget * widget);
static void gsm_color_button_state_changed (GtkWidget * widget,
- GtkStateType previous_state);
+ GtkStateType previous_state);
static void gsm_color_button_style_set (GtkWidget * widget,
- GtkStyle * previous_style);
+ GtkStyle * previous_style);
static gint gsm_color_button_clicked (GtkWidget * widget,
- GdkEventButton * event);
+ GdkEventButton * event);
static gboolean gsm_color_button_enter_notify (GtkWidget * widget,
- GdkEventCrossing * event);
+ GdkEventCrossing * event);
static gboolean gsm_color_button_leave_notify (GtkWidget * widget,
- GdkEventCrossing * event);
+ GdkEventCrossing * event);
/* source side drag signals */
static void gsm_color_button_drag_begin (GtkWidget * widget,
- GdkDragContext * context,
- gpointer data);
+ GdkDragContext * context,
+ gpointer data);
static void gsm_color_button_drag_data_get (GtkWidget * widget,
- GdkDragContext * context,
- GtkSelectionData * selection_data,
- guint info, guint time,
- GSMColorButton * color_button);
+ GdkDragContext * context,
+ GtkSelectionData * selection_data,
+ guint info, guint time,
+ GSMColorButton * color_button);
/* target side drag signals */
static void gsm_color_button_drag_data_received (GtkWidget * widget,
- GdkDragContext * context,
- gint x,
- gint y,
- GtkSelectionData *
- selection_data, guint info,
- guint32 time,
- GSMColorButton *
- color_button);
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData *
+ selection_data, guint info,
+ guint32 time,
+ GSMColorButton *
+ color_button);
static guint color_button_signals[LAST_SIGNAL] = { 0 };
@@ -132,315 +132,315 @@ static const GtkTargetEntry drop_types[] = { {"application/x-color", 0, 0} };
GType
gsm_color_button_get_type ()
{
- static GType gsm_color_button_type = 0;
-
- if (!gsm_color_button_type)
- {
- static const GTypeInfo gsm_color_button_info = {
- sizeof (GSMColorButtonClass),
- NULL,
- NULL,
- (GClassInitFunc) gsm_color_button_class_intern_init,
- NULL,
- NULL,
- sizeof (GSMColorButton),
- 0,
- (GInstanceInitFunc) gsm_color_button_init,
- };
-
- gsm_color_button_type =
- g_type_register_static (GTK_TYPE_DRAWING_AREA, "GSMColorButton",
- &gsm_color_button_info, 0);
+ static GType gsm_color_button_type = 0;
+
+ if (!gsm_color_button_type)
+ {
+ static const GTypeInfo gsm_color_button_info = {
+ sizeof (GSMColorButtonClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gsm_color_button_class_intern_init,
+ NULL,
+ NULL,
+ sizeof (GSMColorButton),
+ 0,
+ (GInstanceInitFunc) gsm_color_button_init,
+ };
+
+ gsm_color_button_type =
+ g_type_register_static (GTK_TYPE_DRAWING_AREA, "GSMColorButton",
+ &gsm_color_button_info, 0);
}
- return gsm_color_button_type;
+ return gsm_color_button_type;
}
static void
gsm_color_button_class_intern_init (gpointer klass)
{
- gsm_color_button_parent_class = g_type_class_peek_parent (klass);
- gsm_color_button_class_init ((GSMColorButtonClass *) klass);
+ gsm_color_button_parent_class = g_type_class_peek_parent (klass);
+ gsm_color_button_class_init ((GSMColorButtonClass *) klass);
}
static void
gsm_color_button_class_init (GSMColorButtonClass * klass)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
+ GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
- gobject_class = G_OBJECT_CLASS (klass);
- widget_class = GTK_WIDGET_CLASS (klass);
+ gobject_class = G_OBJECT_CLASS (klass);
+ widget_class = GTK_WIDGET_CLASS (klass);
- gobject_class->get_property = gsm_color_button_get_property;
- gobject_class->set_property = gsm_color_button_set_property;
- gobject_class->finalize = gsm_color_button_finalize;
- widget_class->state_changed = gsm_color_button_state_changed;
+ gobject_class->get_property = gsm_color_button_get_property;
+ gobject_class->set_property = gsm_color_button_set_property;
+ gobject_class->finalize = gsm_color_button_finalize;
+ widget_class->state_changed = gsm_color_button_state_changed;
#if GTK_CHECK_VERSION(3,0,0)
- widget_class->get_preferred_width = gsm_color_button_get_preferred_width;
- widget_class->get_preferred_height = gsm_color_button_get_preferred_height;
+ widget_class->get_preferred_width = gsm_color_button_get_preferred_width;
+ widget_class->get_preferred_height = gsm_color_button_get_preferred_height;
#else
- widget_class->size_request = gsm_color_button_size_request;
+ widget_class->size_request = gsm_color_button_size_request;
#endif
- widget_class->size_allocate = gsm_color_button_size_allocate;
- widget_class->realize = gsm_color_button_realize;
- widget_class->unrealize = gsm_color_button_unrealize;
- widget_class->style_set = gsm_color_button_style_set;
- widget_class->button_release_event = gsm_color_button_clicked;
- widget_class->enter_notify_event = gsm_color_button_enter_notify;
- widget_class->leave_notify_event = gsm_color_button_leave_notify;
-
- klass->color_set = NULL;
-
- g_object_class_install_property (gobject_class,
- PROP_PERCENTAGE,
- g_param_spec_double ("fraction",
- _("Fraction"),
- _("Percentage full for pie colour pickers"),
- 0, 1, 0.5,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_TITLE,
- g_param_spec_string ("title",
- _("Title"),
- _("The title of the color selection dialog"),
- _("Pick a Color"),
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_COLOR,
- g_param_spec_boxed ("color",
- _("Current Color"),
- _("The selected color"),
- GDK_TYPE_COLOR,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_TYPE,
- g_param_spec_uint ("type", _("Type"),
- _("Type of color picker"),
- 0, 4, 0,
- G_PARAM_READWRITE));
-
- color_button_signals[COLOR_SET] = g_signal_new ("color_set",
- G_TYPE_FROM_CLASS
- (gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET
- (GSMColorButtonClass,
- color_set), NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_type_class_add_private (gobject_class, sizeof (GSMColorButtonPrivate));
+ widget_class->size_allocate = gsm_color_button_size_allocate;
+ widget_class->realize = gsm_color_button_realize;
+ widget_class->unrealize = gsm_color_button_unrealize;
+ widget_class->style_set = gsm_color_button_style_set;
+ widget_class->button_release_event = gsm_color_button_clicked;
+ widget_class->enter_notify_event = gsm_color_button_enter_notify;
+ widget_class->leave_notify_event = gsm_color_button_leave_notify;
+
+ klass->color_set = NULL;
+
+ g_object_class_install_property (gobject_class,
+ PROP_PERCENTAGE,
+ g_param_spec_double ("fraction",
+ _("Fraction"),
+ _("Percentage full for pie colour pickers"),
+ 0, 1, 0.5,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_TITLE,
+ g_param_spec_string ("title",
+ _("Title"),
+ _("The title of the color selection dialog"),
+ _("Pick a Color"),
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_COLOR,
+ g_param_spec_boxed ("color",
+ _("Current Color"),
+ _("The selected color"),
+ GDK_TYPE_COLOR,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_TYPE,
+ g_param_spec_uint ("type", _("Type"),
+ _("Type of color picker"),
+ 0, 4, 0,
+ G_PARAM_READWRITE));
+
+ color_button_signals[COLOR_SET] = g_signal_new ("color_set",
+ G_TYPE_FROM_CLASS
+ (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET
+ (GSMColorButtonClass,
+ color_set), NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (gobject_class, sizeof (GSMColorButtonPrivate));
}
static cairo_surface_t *
fill_image_buffer_from_file (cairo_t *cr, const char *filePath)
{
- GError *error = NULL;
- RsvgHandle *handle;
- cairo_surface_t *tmp_surface;
- cairo_t *tmp_cr;
+ GError *error = NULL;
+ RsvgHandle *handle;
+ cairo_surface_t *tmp_surface;
+ cairo_t *tmp_cr;
- handle = rsvg_handle_new_from_file (filePath, &error);
+ handle = rsvg_handle_new_from_file (filePath, &error);
- if (handle == NULL) {
- g_warning("rsvg_handle_new_from_file(\"%s\") failed: %s",
- filePath, (error ? error->message : "unknown error"));
+ if (handle == NULL) {
+ g_warning("rsvg_handle_new_from_file(\"%s\") failed: %s",
+ filePath, (error ? error->message : "unknown error"));
if (error)
- g_error_free(error);
+ g_error_free(error);
return NULL;
- }
+ }
- tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA,
- 32, 32);
- tmp_cr = cairo_create (tmp_surface);
- rsvg_handle_render_cairo (handle, tmp_cr);
- cairo_destroy (tmp_cr);
- g_object_unref (handle);
- return tmp_surface;
+ tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ 32, 32);
+ tmp_cr = cairo_create (tmp_surface);
+ rsvg_handle_render_cairo (handle, tmp_cr);
+ cairo_destroy (tmp_cr);
+ g_object_unref (handle);
+ return tmp_surface;
}
static void
render (GtkWidget * widget)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
- GdkColor *color, tmp_color = color_button->priv->color;
- color = &tmp_color;
- cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
- cairo_path_t *path = NULL;
- gint width, height;
- gdouble radius, arc_start, arc_end;
- gint highlight_factor;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
+ GdkColor *color, tmp_color = color_button->priv->color;
+ color = &tmp_color;
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
+ cairo_path_t *path = NULL;
+ gint width, height;
+ gdouble radius, arc_start, arc_end;
+ gint highlight_factor;
- if (color_button->priv->highlight > 0) {
- highlight_factor = 8192 * color_button->priv->highlight;
+ if (color_button->priv->highlight > 0) {
+ highlight_factor = 8192 * color_button->priv->highlight;
if (color->red + highlight_factor > 65535)
- color->red = 65535;
+ color->red = 65535;
else
- color->red = color->red + highlight_factor;
+ color->red = color->red + highlight_factor;
if (color->blue + highlight_factor > 65535)
- color->blue = 65535;
+ color->blue = 65535;
else
color->blue = color->blue + highlight_factor;
if (color->green + highlight_factor > 65535)
- color->green = 65535;
+ color->green = 65535;
else
- color->green = color->green + highlight_factor;
- }
- gdk_cairo_set_source_color (cr, color);
- width = gdk_window_get_width(gtk_widget_get_window(widget));
- height = gdk_window_get_height(gtk_widget_get_window(widget));
-
- switch (color_button->priv->type)
- {
- case GSMCP_TYPE_CPU:
- //gtk_widget_set_size_request (widget, GSMCP_MIN_WIDTH, GSMCP_MIN_HEIGHT);
- cairo_paint (cr);
- cairo_set_line_width (cr, 1);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
- cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
- cairo_stroke (cr);
- cairo_set_line_width (cr, 1);
- cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
- cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3);
- cairo_stroke (cr);
- break;
- case GSMCP_TYPE_PIE:
- if (width < 32) // 32px minimum size
- gtk_widget_set_size_request (widget, 32, 32);
- if (width < height)
- radius = width / 2;
- else
- radius = height / 2;
-
- arc_start = -G_PI_2 + 2 * G_PI * color_button->priv->fraction;
- arc_end = -G_PI_2;
-
- cairo_set_line_width (cr, 1);
-
- // Draw external stroke and fill
- if (color_button->priv->fraction < 0.01) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
- 0, 2 * G_PI);
- } else if (color_button->priv->fraction > 0.99) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- 0, 2 * G_PI);
- } else {
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- arc_start, arc_end);
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
- arc_end, arc_start);
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- arc_start, arc_start);
- }
- cairo_fill_preserve (cr);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.7);
- cairo_stroke (cr);
-
- // Draw internal highlight
- cairo_set_source_rgba (cr, 1, 1, 1, 0.45);
- cairo_set_line_width (cr, 1);
-
- if (color_button->priv->fraction < 0.03) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
- 0, 2 * G_PI);
- } else if (color_button->priv->fraction > 0.99) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
- 0, 2 * G_PI);
- } else {
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
- arc_start + (1 / (radius - 3.75)),
- arc_end - (1 / (radius - 3.75)));
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
- arc_end - (1 / (radius - 3.75)),
- arc_start + (1 / (radius - 3.75)));
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
- arc_start + (1 / (radius - 3.75)),
- arc_start + (1 / (radius - 3.75)));
- }
- cairo_stroke (cr);
-
- // Draw external shape
- cairo_set_line_width (cr, 1);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0,
- G_PI * 2);
- cairo_stroke (cr);
-
- break;
- case GSMCP_TYPE_NETWORK_IN:
- if (color_button->priv->image_buffer == NULL)
- color_button->priv->image_buffer =
- fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/download.svg");
- gtk_widget_set_size_request (widget, 32, 32);
- cairo_move_to (cr, 8.5, 1.5);
- cairo_line_to (cr, 23.5, 1.5);
- cairo_line_to (cr, 23.5, 11.5);
- cairo_line_to (cr, 29.5, 11.5);
- cairo_line_to (cr, 16.5, 27.5);
- cairo_line_to (cr, 15.5, 27.5);
- cairo_line_to (cr, 2.5, 11.5);
- cairo_line_to (cr, 8.5, 11.5);
- cairo_line_to (cr, 8.5, 1.5);
- cairo_close_path (cr);
- path = cairo_copy_path (cr);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
- cairo_set_line_width (cr, 1);
- cairo_fill_preserve (cr);
- cairo_set_miter_limit (cr, 5.0);
- cairo_stroke (cr);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
- cairo_append_path (cr, path);
- cairo_path_destroy(path);
- cairo_stroke (cr);
- cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
- 0.0);
- cairo_paint (cr);
-
- break;
- case GSMCP_TYPE_NETWORK_OUT:
- if (color_button->priv->image_buffer == NULL)
- color_button->priv->image_buffer =
- fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/upload.svg");
- gtk_widget_set_size_request (widget, 32, 32);
- cairo_move_to (cr, 16.5, 1.5);
- cairo_line_to (cr, 29.5, 17.5);
- cairo_line_to (cr, 23.5, 17.5);
- cairo_line_to (cr, 23.5, 27.5);
- cairo_line_to (cr, 8.5, 27.5);
- cairo_line_to (cr, 8.5, 17.5);
- cairo_line_to (cr, 2.5, 17.5);
- cairo_line_to (cr, 15.5, 1.5);
- cairo_line_to (cr, 16.5, 1.5);
- cairo_close_path (cr);
- path = cairo_copy_path (cr);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
- cairo_set_line_width (cr, 1);
- cairo_fill_preserve (cr);
- cairo_set_miter_limit (cr, 5.0);
- cairo_stroke (cr);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
- cairo_append_path (cr, path);
- cairo_path_destroy(path);
- cairo_stroke (cr);
- cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
- 0.0);
- cairo_paint (cr);
-
- break;
+ color->green = color->green + highlight_factor;
}
- cairo_destroy (cr);
+ gdk_cairo_set_source_color (cr, color);
+ width = gdk_window_get_width(gtk_widget_get_window(widget));
+ height = gdk_window_get_height(gtk_widget_get_window(widget));
+
+ switch (color_button->priv->type)
+ {
+ case GSMCP_TYPE_CPU:
+ //gtk_widget_set_size_request (widget, GSMCP_MIN_WIDTH, GSMCP_MIN_HEIGHT);
+ cairo_paint (cr);
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
+ cairo_stroke (cr);
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
+ cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3);
+ cairo_stroke (cr);
+ break;
+ case GSMCP_TYPE_PIE:
+ if (width < 32) // 32px minimum size
+ gtk_widget_set_size_request (widget, 32, 32);
+ if (width < height)
+ radius = width / 2;
+ else
+ radius = height / 2;
+
+ arc_start = -G_PI_2 + 2 * G_PI * color_button->priv->fraction;
+ arc_end = -G_PI_2;
+
+ cairo_set_line_width (cr, 1);
+
+ // Draw external stroke and fill
+ if (color_button->priv->fraction < 0.01) {
+ cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
+ 0, 2 * G_PI);
+ } else if (color_button->priv->fraction > 0.99) {
+ cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
+ 0, 2 * G_PI);
+ } else {
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
+ arc_start, arc_end);
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
+ arc_end, arc_start);
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
+ arc_start, arc_start);
+ }
+ cairo_fill_preserve (cr);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.7);
+ cairo_stroke (cr);
+
+ // Draw internal highlight
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.45);
+ cairo_set_line_width (cr, 1);
+
+ if (color_button->priv->fraction < 0.03) {
+ cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
+ 0, 2 * G_PI);
+ } else if (color_button->priv->fraction > 0.99) {
+ cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ 0, 2 * G_PI);
+ } else {
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ arc_start + (1 / (radius - 3.75)),
+ arc_end - (1 / (radius - 3.75)));
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
+ arc_end - (1 / (radius - 3.75)),
+ arc_start + (1 / (radius - 3.75)));
+ cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ arc_start + (1 / (radius - 3.75)),
+ arc_start + (1 / (radius - 3.75)));
+ }
+ cairo_stroke (cr);
+
+ // Draw external shape
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
+ cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0,
+ G_PI * 2);
+ cairo_stroke (cr);
+
+ break;
+ case GSMCP_TYPE_NETWORK_IN:
+ if (color_button->priv->image_buffer == NULL)
+ color_button->priv->image_buffer =
+ fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/download.svg");
+ gtk_widget_set_size_request (widget, 32, 32);
+ cairo_move_to (cr, 8.5, 1.5);
+ cairo_line_to (cr, 23.5, 1.5);
+ cairo_line_to (cr, 23.5, 11.5);
+ cairo_line_to (cr, 29.5, 11.5);
+ cairo_line_to (cr, 16.5, 27.5);
+ cairo_line_to (cr, 15.5, 27.5);
+ cairo_line_to (cr, 2.5, 11.5);
+ cairo_line_to (cr, 8.5, 11.5);
+ cairo_line_to (cr, 8.5, 1.5);
+ cairo_close_path (cr);
+ path = cairo_copy_path (cr);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+ cairo_set_line_width (cr, 1);
+ cairo_fill_preserve (cr);
+ cairo_set_miter_limit (cr, 5.0);
+ cairo_stroke (cr);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_append_path (cr, path);
+ cairo_path_destroy(path);
+ cairo_stroke (cr);
+ cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
+ 0.0);
+ cairo_paint (cr);
+
+ break;
+ case GSMCP_TYPE_NETWORK_OUT:
+ if (color_button->priv->image_buffer == NULL)
+ color_button->priv->image_buffer =
+ fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/upload.svg");
+ gtk_widget_set_size_request (widget, 32, 32);
+ cairo_move_to (cr, 16.5, 1.5);
+ cairo_line_to (cr, 29.5, 17.5);
+ cairo_line_to (cr, 23.5, 17.5);
+ cairo_line_to (cr, 23.5, 27.5);
+ cairo_line_to (cr, 8.5, 27.5);
+ cairo_line_to (cr, 8.5, 17.5);
+ cairo_line_to (cr, 2.5, 17.5);
+ cairo_line_to (cr, 15.5, 1.5);
+ cairo_line_to (cr, 16.5, 1.5);
+ cairo_close_path (cr);
+ path = cairo_copy_path (cr);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+ cairo_set_line_width (cr, 1);
+ cairo_fill_preserve (cr);
+ cairo_set_miter_limit (cr, 5.0);
+ cairo_stroke (cr);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_append_path (cr, path);
+ cairo_path_destroy(path);
+ cairo_stroke (cr);
+ cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
+ 0.0);
+ cairo_paint (cr);
+
+ break;
+ }
+ cairo_destroy (cr);
}
/* Handle exposure events for the color picker's drawing area */
@@ -450,64 +450,64 @@ static gboolean draw (GtkWidget * widget, cairo_t * cr, gpointer data)
static gboolean expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer data)
#endif
{
- render (GTK_WIDGET (data));
+ render (GTK_WIDGET (data));
- return FALSE;
+ return FALSE;
}
static void
gsm_color_button_realize (GtkWidget * widget)
{
- GTK_WIDGET_CLASS (gsm_color_button_parent_class)->realize (widget);
- render (widget);
+ GTK_WIDGET_CLASS (gsm_color_button_parent_class)->realize (widget);
+ render (widget);
}
#if GTK_CHECK_VERSION(3,0,0)
static void gsm_color_button_get_preferred_width (GtkWidget * widget, gint * minimum_width, gint * natural_width)
{
- g_return_if_fail (widget != NULL && minimum_width != NULL && natural_width != NULL);
- g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
-
- *minimum_width = GSMCP_MIN_WIDTH;
- *natural_width = GSMCP_MIN_WIDTH;
+ g_return_if_fail (widget != NULL && minimum_width != NULL && natural_width != NULL);
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
+
+ *minimum_width = GSMCP_MIN_WIDTH;
+ *natural_width = GSMCP_MIN_WIDTH;
}
static void gsm_color_button_get_preferred_height (GtkWidget * widget, gint * minimum_height, gint * natural_height)
{
- g_return_if_fail (widget != NULL && minimum_height != NULL && natural_height != NULL);
- g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
-
- *minimum_height = GSMCP_MIN_HEIGHT;
- *natural_height = GSMCP_MIN_HEIGHT;
+ g_return_if_fail (widget != NULL && minimum_height != NULL && natural_height != NULL);
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
+
+ *minimum_height = GSMCP_MIN_HEIGHT;
+ *natural_height = GSMCP_MIN_HEIGHT;
}
#else
static void
gsm_color_button_size_request (GtkWidget * widget,
- GtkRequisition * requisition)
+ GtkRequisition * requisition)
{
- g_return_if_fail (widget != NULL || requisition != NULL);
- g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
+ g_return_if_fail (widget != NULL || requisition != NULL);
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
- requisition->width = GSMCP_MIN_WIDTH;
- requisition->height = GSMCP_MIN_HEIGHT;
+ requisition->width = GSMCP_MIN_WIDTH;
+ requisition->height = GSMCP_MIN_HEIGHT;
}
#endif
static void
gsm_color_button_size_allocate (GtkWidget * widget,
- GtkAllocation * allocation)
+ GtkAllocation * allocation)
{
- GSMColorButton *color_button;
+ GSMColorButton *color_button;
- g_return_if_fail (widget != NULL || allocation != NULL);
- g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
+ g_return_if_fail (widget != NULL || allocation != NULL);
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (widget));
- gtk_widget_set_allocation (widget, allocation);
- color_button = GSM_COLOR_BUTTON (widget);
+ gtk_widget_set_allocation (widget, allocation);
+ color_button = GSM_COLOR_BUTTON (widget);
- if (gtk_widget_get_realized (widget))
+ if (gtk_widget_get_realized (widget))
{
- gdk_window_move_resize (gtk_widget_get_window (widget), allocation->x, allocation->y,
- allocation->width, allocation->height);
+ gdk_window_move_resize (gtk_widget_get_window (widget), allocation->x, allocation->y,
+ allocation->width, allocation->height);
}
}
@@ -515,434 +515,434 @@ static void
gsm_color_button_unrealize (GtkWidget * widget)
{
- GTK_WIDGET_CLASS (gsm_color_button_parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (gsm_color_button_parent_class)->unrealize (widget);
}
static void
gsm_color_button_style_set (GtkWidget * widget, GtkStyle * previous_style)
{
- GTK_WIDGET_CLASS (gsm_color_button_parent_class)->style_set (widget,
- previous_style);
+ GTK_WIDGET_CLASS (gsm_color_button_parent_class)->style_set (widget,
+ previous_style);
}
static void
gsm_color_button_state_changed (GtkWidget * widget,
- GtkStateType previous_state)
+ GtkStateType previous_state)
{
}
static void
gsm_color_button_drag_data_received (GtkWidget * widget,
- GdkDragContext * context,
- gint x,
- gint y,
- GtkSelectionData * selection_data,
- guint info,
- guint32 time,
- GSMColorButton * color_button)
-{
- gint length;
- guint16 *dropped;
-
- length = gtk_selection_data_get_length (selection_data);
-
- if (length < 0)
- return;
-
- /* We accept drops with the wrong format, since the KDE color
- * chooser incorrectly drops application/x-color with format 8.
- */
- if (length != 8)
+ GdkDragContext * context,
+ gint x,
+ gint y,
+ GtkSelectionData * selection_data,
+ guint info,
+ guint32 time,
+ GSMColorButton * color_button)
+{
+ gint length;
+ guint16 *dropped;
+
+ length = gtk_selection_data_get_length (selection_data);
+
+ if (length < 0)
+ return;
+
+ /* We accept drops with the wrong format, since the KDE color
+ * chooser incorrectly drops application/x-color with format 8.
+ */
+ if (length != 8)
{
- g_warning (_("Received invalid color data\n"));
- return;
+ g_warning (_("Received invalid color data\n"));
+ return;
}
- dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
+ dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
- color_button->priv->color.red = dropped[0];
- color_button->priv->color.green = dropped[1];
- color_button->priv->color.blue = dropped[2];
+ color_button->priv->color.red = dropped[0];
+ color_button->priv->color.green = dropped[1];
+ color_button->priv->color.blue = dropped[2];
- gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
+ gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
- g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
+ g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
- g_object_freeze_notify (G_OBJECT (color_button));
- g_object_notify (G_OBJECT (color_button), "color");
- g_object_thaw_notify (G_OBJECT (color_button));
+ g_object_freeze_notify (G_OBJECT (color_button));
+ g_object_notify (G_OBJECT (color_button), "color");
+ g_object_thaw_notify (G_OBJECT (color_button));
}
static void
set_color_icon (GdkDragContext * context, GdkColor * color)
{
- GdkPixbuf *pixbuf;
- guint32 pixel;
+ GdkPixbuf *pixbuf;
+ guint32 pixel;
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 48, 32);
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 48, 32);
- pixel = ((color->red & 0xff00) << 16) |
- ((color->green & 0xff00) << 8) | (color->blue & 0xff00);
+ pixel = ((color->red & 0xff00) << 16) |
+ ((color->green & 0xff00) << 8) | (color->blue & 0xff00);
- gdk_pixbuf_fill (pixbuf, pixel);
+ gdk_pixbuf_fill (pixbuf, pixel);
- gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
- g_object_unref (pixbuf);
+ gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
+ g_object_unref (pixbuf);
}
static void
gsm_color_button_drag_begin (GtkWidget * widget,
- GdkDragContext * context, gpointer data)
+ GdkDragContext * context, gpointer data)
{
- GSMColorButton *color_button = data;
+ GSMColorButton *color_button = data;
- set_color_icon (context, &color_button->priv->color);
+ set_color_icon (context, &color_button->priv->color);
}
static void
gsm_color_button_drag_data_get (GtkWidget * widget,
- GdkDragContext * context,
- GtkSelectionData * selection_data,
- guint info,
- guint time, GSMColorButton * color_button)
+ GdkDragContext * context,
+ GtkSelectionData * selection_data,
+ guint info,
+ guint time, GSMColorButton * color_button)
{
- guint16 dropped[4];
+ guint16 dropped[4];
- dropped[0] = color_button->priv->color.red;
- dropped[1] = color_button->priv->color.green;
- dropped[2] = color_button->priv->color.blue;
- dropped[3] = 65535; // This widget doesn't care about alpha
+ dropped[0] = color_button->priv->color.red;
+ dropped[1] = color_button->priv->color.green;
+ dropped[2] = color_button->priv->color.blue;
+ dropped[3] = 65535; // This widget doesn't care about alpha
- gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
- 16, (guchar *) dropped, 8);
+ gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
+ 16, (guchar *) dropped, 8);
}
static void
gsm_color_button_init (GSMColorButton * color_button)
{
- color_button->priv = GSM_COLOR_BUTTON_GET_PRIVATE (color_button);
-
- color_button->priv->color.red = 0;
- color_button->priv->color.green = 0;
- color_button->priv->color.blue = 0;
- color_button->priv->fraction = 0.5;
- color_button->priv->type = GSMCP_TYPE_CPU;
- color_button->priv->image_buffer = NULL;
- color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
-
- gtk_drag_dest_set (GTK_WIDGET (color_button),
- GTK_DEST_DEFAULT_MOTION |
- GTK_DEST_DEFAULT_HIGHLIGHT |
- GTK_DEST_DEFAULT_DROP, drop_types, 1, GDK_ACTION_COPY);
- gtk_drag_source_set (GTK_WIDGET (color_button),
- GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
- drop_types, 1, GDK_ACTION_COPY);
- g_signal_connect (color_button, "drag_begin",
- G_CALLBACK (gsm_color_button_drag_begin), color_button);
- g_signal_connect (color_button, "drag_data_received",
- G_CALLBACK (gsm_color_button_drag_data_received),
- color_button);
- g_signal_connect (color_button, "drag_data_get",
- G_CALLBACK (gsm_color_button_drag_data_get),
- color_button);
-
- gtk_widget_add_events (GTK_WIDGET(color_button), GDK_ENTER_NOTIFY_MASK
- | GDK_LEAVE_NOTIFY_MASK);
-
- gtk_widget_set_tooltip_text (GTK_WIDGET(color_button), _("Click to set graph colors"));
+ color_button->priv = GSM_COLOR_BUTTON_GET_PRIVATE (color_button);
+
+ color_button->priv->color.red = 0;
+ color_button->priv->color.green = 0;
+ color_button->priv->color.blue = 0;
+ color_button->priv->fraction = 0.5;
+ color_button->priv->type = GSMCP_TYPE_CPU;
+ color_button->priv->image_buffer = NULL;
+ color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
+
+ gtk_drag_dest_set (GTK_WIDGET (color_button),
+ GTK_DEST_DEFAULT_MOTION |
+ GTK_DEST_DEFAULT_HIGHLIGHT |
+ GTK_DEST_DEFAULT_DROP, drop_types, 1, GDK_ACTION_COPY);
+ gtk_drag_source_set (GTK_WIDGET (color_button),
+ GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+ drop_types, 1, GDK_ACTION_COPY);
+ g_signal_connect (color_button, "drag_begin",
+ G_CALLBACK (gsm_color_button_drag_begin), color_button);
+ g_signal_connect (color_button, "drag_data_received",
+ G_CALLBACK (gsm_color_button_drag_data_received),
+ color_button);
+ g_signal_connect (color_button, "drag_data_get",
+ G_CALLBACK (gsm_color_button_drag_data_get),
+ color_button);
+
+ gtk_widget_add_events (GTK_WIDGET(color_button), GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK);
+
+ gtk_widget_set_tooltip_text (GTK_WIDGET(color_button), _("Click to set graph colors"));
#if GTK_CHECK_VERSION(3,0,0)
- g_signal_connect (color_button, "draw", G_CALLBACK (draw), color_button);
+ g_signal_connect (color_button, "draw", G_CALLBACK (draw), color_button);
#else
- g_signal_connect (color_button, "expose-event", G_CALLBACK (expose_event), color_button);
+ g_signal_connect (color_button, "expose-event", G_CALLBACK (expose_event), color_button);
#endif
}
static void
gsm_color_button_finalize (GObject * object)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
- if (color_button->priv->cs_dialog != NULL)
- gtk_widget_destroy (color_button->priv->cs_dialog);
- color_button->priv->cs_dialog = NULL;
+ if (color_button->priv->cs_dialog != NULL)
+ gtk_widget_destroy (color_button->priv->cs_dialog);
+ color_button->priv->cs_dialog = NULL;
- g_free (color_button->priv->title);
- color_button->priv->title = NULL;
+ g_free (color_button->priv->title);
+ color_button->priv->title = NULL;
- cairo_surface_destroy (color_button->priv->image_buffer);
- color_button->priv->image_buffer = NULL;
+ cairo_surface_destroy (color_button->priv->image_buffer);
+ color_button->priv->image_buffer = NULL;
- G_OBJECT_CLASS (gsm_color_button_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gsm_color_button_parent_class)->finalize (object);
}
GtkWidget *
gsm_color_button_new (const GdkColor * color, guint type)
{
- return g_object_new (GSM_TYPE_COLOR_BUTTON, "color", color, "type", type,
- NULL);
+ return g_object_new (GSM_TYPE_COLOR_BUTTON, "color", color, "type", type,
+ NULL);
}
static void
dialog_response (GtkWidget * widget, GtkResponseType response, gpointer data)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (data);
- GtkColorSelection *color_selection;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (data);
+ GtkColorSelection *color_selection;
- if (response == GTK_RESPONSE_OK) {
- color_selection =
- GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG
- (color_button->priv->cs_dialog)));
+ if (response == GTK_RESPONSE_OK) {
+ color_selection =
+ GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG
+ (color_button->priv->cs_dialog)));
- gtk_color_selection_get_current_color (color_selection,
- &color_button->priv->color);
+ gtk_color_selection_get_current_color (color_selection,
+ &color_button->priv->color);
- gtk_widget_hide (color_button->priv->cs_dialog);
+ gtk_widget_hide (color_button->priv->cs_dialog);
- gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
+ gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
- g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
+ g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
- g_object_freeze_notify (G_OBJECT (color_button));
- g_object_notify (G_OBJECT (color_button), "color");
- g_object_thaw_notify (G_OBJECT (color_button));
- }
- else /* (response == GTK_RESPONSE_CANCEL) */
- gtk_widget_hide (color_button->priv->cs_dialog);
+ g_object_freeze_notify (G_OBJECT (color_button));
+ g_object_notify (G_OBJECT (color_button), "color");
+ g_object_thaw_notify (G_OBJECT (color_button));
+ }
+ else /* (response == GTK_RESPONSE_CANCEL) */
+ gtk_widget_hide (color_button->priv->cs_dialog);
}
static gboolean
dialog_destroy (GtkWidget * widget, gpointer data)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (data);
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (data);
- color_button->priv->cs_dialog = NULL;
+ color_button->priv->cs_dialog = NULL;
- return FALSE;
+ return FALSE;
}
static gint
gsm_color_button_clicked (GtkWidget * widget, GdkEventButton * event)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
- GtkColorSelectionDialog *color_dialog;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
+ GtkColorSelectionDialog *color_dialog;
- /* if dialog already exists, make sure it's shown and raised */
- if (!color_button->priv->cs_dialog)
+ /* if dialog already exists, make sure it's shown and raised */
+ if (!color_button->priv->cs_dialog)
{
- /* Create the dialog and connects its buttons */
- GtkWidget *parent;
+ /* Create the dialog and connects its buttons */
+ GtkWidget *parent;
- parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
- color_button->priv->cs_dialog =
- gtk_color_selection_dialog_new (color_button->priv->title);
+ color_button->priv->cs_dialog =
+ gtk_color_selection_dialog_new (color_button->priv->title);
- color_dialog =
- GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
+ color_dialog =
+ GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
- if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
- {
- if (GTK_WINDOW (parent) !=
- gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
- gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
- GTK_WINDOW (parent));
+ if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+ {
+ if (GTK_WINDOW (parent) !=
+ gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
+ gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
+ GTK_WINDOW (parent));
- gtk_window_set_modal (GTK_WINDOW (color_dialog),
- gtk_window_get_modal (GTK_WINDOW (parent)));
- }
+ gtk_window_set_modal (GTK_WINDOW (color_dialog),
+ gtk_window_get_modal (GTK_WINDOW (parent)));
+ }
- g_signal_connect (color_dialog, "response",
- G_CALLBACK (dialog_response), color_button);
+ g_signal_connect (color_dialog, "response",
+ G_CALLBACK (dialog_response), color_button);
- g_signal_connect (color_dialog, "destroy",
- G_CALLBACK (dialog_destroy), color_button);
+ g_signal_connect (color_dialog, "destroy",
+ G_CALLBACK (dialog_destroy), color_button);
}
- color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
+ color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
- gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION
- (gtk_color_selection_dialog_get_color_selection (color_dialog)),
- &color_button->priv->color);
+ gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION
+ (gtk_color_selection_dialog_get_color_selection (color_dialog)),
+ &color_button->priv->color);
- gtk_color_selection_set_current_color (GTK_COLOR_SELECTION
- (gtk_color_selection_dialog_get_color_selection (color_dialog)),
- &color_button->priv->color);
+ gtk_color_selection_set_current_color (GTK_COLOR_SELECTION
+ (gtk_color_selection_dialog_get_color_selection (color_dialog)),
+ &color_button->priv->color);
- gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
- return 0;
+ gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
+ return 0;
}
static gboolean
gsm_color_button_enter_notify (GtkWidget * widget, GdkEventCrossing * event)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
- color_button->priv->highlight = 1.0;
- gtk_widget_queue_draw(widget);
- return FALSE;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
+ color_button->priv->highlight = 1.0;
+ gtk_widget_queue_draw(widget);
+ return FALSE;
}
static gboolean
gsm_color_button_leave_notify (GtkWidget * widget, GdkEventCrossing * event)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
- color_button->priv->highlight = 0;
- gtk_widget_queue_draw(widget);
- return FALSE;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (widget);
+ color_button->priv->highlight = 0;
+ gtk_widget_queue_draw(widget);
+ return FALSE;
}
guint
gsm_color_button_get_cbtype (GSMColorButton * color_button)
{
- g_return_val_if_fail (GSM_IS_COLOR_BUTTON (color_button), 0);
+ g_return_val_if_fail (GSM_IS_COLOR_BUTTON (color_button), 0);
- return color_button->priv->type;
+ return color_button->priv->type;
}
void
gsm_color_button_set_cbtype (GSMColorButton * color_button, guint type)
{
- g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
- color_button->priv->type = type;
+ color_button->priv->type = type;
- gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
+ gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
- g_object_notify (G_OBJECT (color_button), "type");
+ g_object_notify (G_OBJECT (color_button), "type");
}
gdouble
gsm_color_button_get_fraction (GSMColorButton * color_button)
{
- g_return_val_if_fail (GSM_IS_COLOR_BUTTON (color_button), 0);
+ g_return_val_if_fail (GSM_IS_COLOR_BUTTON (color_button), 0);
- return color_button->priv->fraction;
+ return color_button->priv->fraction;
}
void
gsm_color_button_set_fraction (GSMColorButton * color_button,
- gdouble fraction)
+ gdouble fraction)
{
- g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
- color_button->priv->fraction = fraction;
+ color_button->priv->fraction = fraction;
- gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
+ gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget));
- g_object_notify (G_OBJECT (color_button), "fraction");
+ g_object_notify (G_OBJECT (color_button), "fraction");
}
void
gsm_color_button_get_color (GSMColorButton * color_button, GdkColor * color)
{
- g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
- color->red = color_button->priv->color.red;
- color->green = color_button->priv->color.green;
- color->blue = color_button->priv->color.blue;
+ color->red = color_button->priv->color.red;
+ color->green = color_button->priv->color.green;
+ color->blue = color_button->priv->color.blue;
}
void
gsm_color_button_set_color (GSMColorButton * color_button,
- const GdkColor * color)
+ const GdkColor * color)
{
- g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
- g_return_if_fail (color != NULL);
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (color != NULL);
- color_button->priv->color.red = color->red;
- color_button->priv->color.green = color->green;
- color_button->priv->color.blue = color->blue;
+ color_button->priv->color.red = color->red;
+ color_button->priv->color.green = color->green;
+ color_button->priv->color.blue = color->blue;
- gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget)); //->priv->draw_area);
+ gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget)); //->priv->draw_area);
- g_object_notify (G_OBJECT (color_button), "color");
+ g_object_notify (G_OBJECT (color_button), "color");
}
void
gsm_color_button_set_title (GSMColorButton * color_button,
- const gchar * title)
+ const gchar * title)
{
- gchar *old_title;
+ gchar *old_title;
- g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
+ g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button));
- old_title = color_button->priv->title;
- color_button->priv->title = g_strdup (title);
- g_free (old_title);
+ old_title = color_button->priv->title;
+ color_button->priv->title = g_strdup (title);
+ g_free (old_title);
- if (color_button->priv->cs_dialog)
- gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
- color_button->priv->title);
+ if (color_button->priv->cs_dialog)
+ gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
+ color_button->priv->title);
- g_object_notify (G_OBJECT (color_button), "title");
+ g_object_notify (G_OBJECT (color_button), "title");
}
const gchar* gsm_color_button_get_title(GSMColorButton* color_button)
{
- g_return_val_if_fail(GSM_IS_COLOR_BUTTON(color_button), NULL);
+ g_return_val_if_fail(GSM_IS_COLOR_BUTTON(color_button), NULL);
- return color_button->priv->title;
+ return color_button->priv->title;
}
static void
gsm_color_button_set_property (GObject * object,
- guint param_id,
- const GValue * value, GParamSpec * pspec)
+ guint param_id,
+ const GValue * value, GParamSpec * pspec)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
- switch (param_id)
+ switch (param_id)
{
- case PROP_PERCENTAGE:
- gsm_color_button_set_fraction (color_button,
- g_value_get_double (value));
- break;
- case PROP_TITLE:
- gsm_color_button_set_title (color_button, g_value_get_string (value));
- break;
- case PROP_COLOR:
- gsm_color_button_set_color (color_button, g_value_get_boxed (value));
- break;
- case PROP_TYPE:
- gsm_color_button_set_cbtype (color_button, g_value_get_uint (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
+ case PROP_PERCENTAGE:
+ gsm_color_button_set_fraction (color_button,
+ g_value_get_double (value));
+ break;
+ case PROP_TITLE:
+ gsm_color_button_set_title (color_button, g_value_get_string (value));
+ break;
+ case PROP_COLOR:
+ gsm_color_button_set_color (color_button, g_value_get_boxed (value));
+ break;
+ case PROP_TYPE:
+ gsm_color_button_set_cbtype (color_button, g_value_get_uint (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
}
}
static void
gsm_color_button_get_property (GObject * object,
- guint param_id,
- GValue * value, GParamSpec * pspec)
+ guint param_id,
+ GValue * value, GParamSpec * pspec)
{
- GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
- GdkColor color;
+ GSMColorButton *color_button = GSM_COLOR_BUTTON (object);
+ GdkColor color;
- switch (param_id)
+ switch (param_id)
{
- case PROP_PERCENTAGE:
- g_value_set_double (value,
- gsm_color_button_get_fraction (color_button));
- break;
- case PROP_TITLE:
- g_value_set_string (value, gsm_color_button_get_title (color_button));
- break;
- case PROP_COLOR:
- gsm_color_button_get_color (color_button, &color);
- g_value_set_boxed (value, &color);
- break;
- case PROP_TYPE:
- g_value_set_uint (value, gsm_color_button_get_cbtype (color_button));
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
+ case PROP_PERCENTAGE:
+ g_value_set_double (value,
+ gsm_color_button_get_fraction (color_button));
+ break;
+ case PROP_TITLE:
+ g_value_set_string (value, gsm_color_button_get_title (color_button));
+ break;
+ case PROP_COLOR:
+ gsm_color_button_get_color (color_button, &color);
+ g_value_set_boxed (value, &color);
+ break;
+ case PROP_TYPE:
+ g_value_set_uint (value, gsm_color_button_get_cbtype (color_button));
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
}
}
diff --git a/src/gsm_color_button.h b/src/gsm_color_button.h
index 0194887..bb885bc 100644
--- a/src/gsm_color_button.h
+++ b/src/gsm_color_button.h
@@ -33,7 +33,7 @@
G_BEGIN_DECLS
/* The GtkColorSelectionButton widget is a simple color picker in a button.
- * The button displays a sample of the currently selected color. When
+ * The button displays a sample of the currently selected color. When
* the user clicks on the button, a color selection dialog pops up.
* The color picker emits the "color_set" signal when the color is set.
*/
@@ -49,34 +49,34 @@ typedef struct _GSMColorButtonPrivate GSMColorButtonPrivate;
struct _GSMColorButton
{
- GtkDrawingArea widget;
+ GtkDrawingArea widget;
- /*< private > */
+ /*< private > */
- GSMColorButtonPrivate *priv;
+ GSMColorButtonPrivate *priv;
};
/* Widget types */
enum
{
- GSMCP_TYPE_CPU,
- GSMCP_TYPE_PIE,
- GSMCP_TYPE_NETWORK_IN,
- GSMCP_TYPE_NETWORK_OUT,
- GSMCP_TYPES
+ GSMCP_TYPE_CPU,
+ GSMCP_TYPE_PIE,
+ GSMCP_TYPE_NETWORK_IN,
+ GSMCP_TYPE_NETWORK_OUT,
+ GSMCP_TYPES
};
struct _GSMColorButtonClass
{
- GtkWidgetClass parent_class;
+ GtkWidgetClass parent_class;
- void (*color_set) (GSMColorButton * cp);
+ void (*color_set) (GSMColorButton * cp);
- /* Padding for future expansion */
- void (*_gtk_reserved1) (void);
- void (*_gtk_reserved2) (void);
- void (*_gtk_reserved3) (void);
- void (*_gtk_reserved4) (void);
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
};
GType gsm_color_button_get_type (void) G_GNUC_CONST;
diff --git a/src/iconthemewrapper.cpp b/src/iconthemewrapper.cpp
index 496dd45..4a66f5c 100644
--- a/src/iconthemewrapper.cpp
+++ b/src/iconthemewrapper.cpp
@@ -7,17 +7,17 @@
Glib::RefPtr<Gdk::Pixbuf>
procman::IconThemeWrapper::load_icon(const Glib::ustring& icon_name,
- int size, Gtk::IconLookupFlags flags) const
+ int size, Gtk::IconLookupFlags flags) const
{
- try
+ try
{
return Gtk::IconTheme::get_default()->load_icon(icon_name, size, flags);
}
- catch (Gtk::IconThemeError &error)
+ catch (Gtk::IconThemeError &error)
{
- if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
- g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str());
- return Glib::RefPtr<Gdk::Pixbuf>();
+ if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
+ g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str());
+ return Glib::RefPtr<Gdk::Pixbuf>();
}
}
diff --git a/src/iconthemewrapper.h b/src/iconthemewrapper.h
index 6127f01..81fb8d8 100644
--- a/src/iconthemewrapper.h
+++ b/src/iconthemewrapper.h
@@ -8,16 +8,16 @@
namespace procman
{
- class IconThemeWrapper
- {
- public:
- // returns 0 instead of raising an exception
- Glib::RefPtr<Gdk::Pixbuf>
- load_icon(const Glib::ustring& icon_name, int size, Gtk::IconLookupFlags flags) const;
+ class IconThemeWrapper
+ {
+ public:
+ // returns 0 instead of raising an exception
+ Glib::RefPtr<Gdk::Pixbuf>
+ load_icon(const Glib::ustring& icon_name, int size, Gtk::IconLookupFlags flags) const;
- const IconThemeWrapper* operator->() const
- { return this; }
- };
+ const IconThemeWrapper* operator->() const
+ { return this; }
+ };
}
#endif // H_PROCMAN_ICONTHEMEWRAPPER_H_1185707711
diff --git a/src/interface.cpp b/src/interface.cpp
index a609c7c..405f1e3 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -41,58 +41,58 @@
#include "sysinfo.h"
#include "gsm_color_button.h"
-static void cb_toggle_tree (GtkAction *action, gpointer data);
-static void cb_proc_goto_tab (gint tab);
+static void cb_toggle_tree (GtkAction *action, gpointer data);
+static void cb_proc_goto_tab (gint tab);
static const GtkActionEntry menu_entries[] =
{
- // xgettext: noun, top level menu.
- // "File" did not make sense for system-monitor
- { "Monitor", NULL, N_("_Monitor") },
- { "Edit", NULL, N_("_Edit") },
- { "View", NULL, N_("_View") },
- { "Help", NULL, N_("_Help") },
-
- { "Lsof", GTK_STOCK_FIND, N_("Search for _Open Files"), "<control>O",
- N_("Search for open files"), G_CALLBACK(cb_show_lsof) },
- { "Quit", GTK_STOCK_QUIT, NULL, NULL,
- N_("Quit the program"), G_CALLBACK (cb_app_exit) },
-
-
- { "StopProcess", NULL, N_("_Stop Process"), "<control>S",
- N_("Stop process"), G_CALLBACK(cb_kill_sigstop) },
- { "ContProcess", NULL, N_("_Continue Process"), "<control>C",
- N_("Continue process if stopped"), G_CALLBACK(cb_kill_sigcont) },
-
- { "EndProcess", NULL, N_("_End Process"), "<control>E",
- N_("Force process to finish normally"), G_CALLBACK (cb_end_process) },
- { "KillProcess", NULL, N_("_Kill Process"), "<control>K",
- N_("Force process to finish immediately"), G_CALLBACK (cb_kill_process) },
- { "ChangePriority", NULL, N_("_Change Priority..."), "<control>N",
- N_("Change the order of priority of process"), G_CALLBACK (cb_renice) },
- { "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL,
- N_("Configure the application"), G_CALLBACK (cb_edit_preferences) },
-
- { "Refresh", GTK_STOCK_REFRESH, N_("_Refresh"), "<control>R",
- N_("Refresh the process list"), G_CALLBACK(cb_user_refresh) },
-
- { "MemoryMaps", NULL, N_("_Memory Maps"), "<control>M",
- N_("Open the memory maps associated with a process"), G_CALLBACK (cb_show_memory_maps) },
- // Translators: this means 'Files that are open' (open is no verb here
- { "OpenFiles", NULL, N_("Open _Files"), "<control>F",
- N_("View the files opened by a process"), G_CALLBACK (cb_show_open_files) },
-
- { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1",
- N_("Open the manual"), G_CALLBACK (cb_help_contents) },
- { "About", GTK_STOCK_ABOUT, NULL, NULL,
- N_("About this application"), G_CALLBACK (cb_about) }
+ // xgettext: noun, top level menu.
+ // "File" did not make sense for system-monitor
+ { "Monitor", NULL, N_("_Monitor") },
+ { "Edit", NULL, N_("_Edit") },
+ { "View", NULL, N_("_View") },
+ { "Help", NULL, N_("_Help") },
+
+ { "Lsof", GTK_STOCK_FIND, N_("Search for _Open Files"), "<control>O",
+ N_("Search for open files"), G_CALLBACK(cb_show_lsof) },
+ { "Quit", GTK_STOCK_QUIT, NULL, NULL,
+ N_("Quit the program"), G_CALLBACK (cb_app_exit) },
+
+
+ { "StopProcess", NULL, N_("_Stop Process"), "<control>S",
+ N_("Stop process"), G_CALLBACK(cb_kill_sigstop) },
+ { "ContProcess", NULL, N_("_Continue Process"), "<control>C",
+ N_("Continue process if stopped"), G_CALLBACK(cb_kill_sigcont) },
+
+ { "EndProcess", NULL, N_("_End Process"), "<control>E",
+ N_("Force process to finish normally"), G_CALLBACK (cb_end_process) },
+ { "KillProcess", NULL, N_("_Kill Process"), "<control>K",
+ N_("Force process to finish immediately"), G_CALLBACK (cb_kill_process) },
+ { "ChangePriority", NULL, N_("_Change Priority..."), "<control>N",
+ N_("Change the order of priority of process"), G_CALLBACK (cb_renice) },
+ { "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL,
+ N_("Configure the application"), G_CALLBACK (cb_edit_preferences) },
+
+ { "Refresh", GTK_STOCK_REFRESH, N_("_Refresh"), "<control>R",
+ N_("Refresh the process list"), G_CALLBACK(cb_user_refresh) },
+
+ { "MemoryMaps", NULL, N_("_Memory Maps"), "<control>M",
+ N_("Open the memory maps associated with a process"), G_CALLBACK (cb_show_memory_maps) },
+ // Translators: this means 'Files that are open' (open is no verb here
+ { "OpenFiles", NULL, N_("Open _Files"), "<control>F",
+ N_("View the files opened by a process"), G_CALLBACK (cb_show_open_files) },
+
+ { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1",
+ N_("Open the manual"), G_CALLBACK (cb_help_contents) },
+ { "About", GTK_STOCK_ABOUT, NULL, NULL,
+ N_("About this application"), G_CALLBACK (cb_about) }
};
static const GtkToggleActionEntry toggle_menu_entries[] =
{
- { "ShowDependencies", NULL, N_("_Dependencies"), "<control>D",
- N_("Show parent/child relationship between processes"),
- G_CALLBACK (cb_toggle_tree), TRUE },
+ { "ShowDependencies", NULL, N_("_Dependencies"), "<control>D",
+ N_("Show parent/child relationship between processes"),
+ G_CALLBACK (cb_toggle_tree), TRUE },
};
@@ -158,418 +158,418 @@ static const char ui_info[] =
static GtkWidget *
create_proc_view (ProcData *procdata)
{
- GtkWidget *vbox1;
- GtkWidget *hbox1;
- GtkWidget *scrolled;
- GtkWidget *hbox2;
- char* string;
-
- vbox1 = gtk_vbox_new (FALSE, 18);
- gtk_container_set_border_width (GTK_CONTAINER (vbox1), 12);
-
- hbox1 = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
-
- string = make_loadavg_string ();
- procdata->loadavg = gtk_label_new (string);
- g_free (string);
- gtk_box_pack_start (GTK_BOX (hbox1), procdata->loadavg, FALSE, FALSE, 0);
-
-
- scrolled = proctable_new (procdata);
- if (!scrolled)
- return NULL;
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
-
- gtk_box_pack_start (GTK_BOX (vbox1), scrolled, TRUE, TRUE, 0);
-
-
- hbox2 = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
-
- procdata->endprocessbutton = gtk_button_new_with_mnemonic (_("End _Process"));
- gtk_box_pack_end (GTK_BOX (hbox2), procdata->endprocessbutton, FALSE, FALSE, 0);
- g_signal_connect (G_OBJECT (procdata->endprocessbutton), "clicked",
- G_CALLBACK (cb_end_process_button_pressed), procdata);
-
-
- /* create popup_menu */
- procdata->popup_menu = gtk_ui_manager_get_widget (procdata->uimanager, "/PopupMenu");
-
- return vbox1;
+ GtkWidget *vbox1;
+ GtkWidget *hbox1;
+ GtkWidget *scrolled;
+ GtkWidget *hbox2;
+ char* string;
+
+ vbox1 = gtk_vbox_new (FALSE, 18);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox1), 12);
+
+ hbox1 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
+
+ string = make_loadavg_string ();
+ procdata->loadavg = gtk_label_new (string);
+ g_free (string);
+ gtk_box_pack_start (GTK_BOX (hbox1), procdata->loadavg, FALSE, FALSE, 0);
+
+
+ scrolled = proctable_new (procdata);
+ if (!scrolled)
+ return NULL;
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_SHADOW_IN);
+
+ gtk_box_pack_start (GTK_BOX (vbox1), scrolled, TRUE, TRUE, 0);
+
+
+ hbox2 = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox1), hbox2, FALSE, FALSE, 0);
+
+ procdata->endprocessbutton = gtk_button_new_with_mnemonic (_("End _Process"));
+ gtk_box_pack_end (GTK_BOX (hbox2), procdata->endprocessbutton, FALSE, FALSE, 0);
+ g_signal_connect (G_OBJECT (procdata->endprocessbutton), "clicked",
+ G_CALLBACK (cb_end_process_button_pressed), procdata);
+
+
+ /* create popup_menu */
+ procdata->popup_menu = gtk_ui_manager_get_widget (procdata->uimanager, "/PopupMenu");
+
+ return vbox1;
}
GtkWidget *
make_title_label (const char *text)
{
- GtkWidget *label;
- char *full;
+ GtkWidget *label;
+ char *full;
- full = g_strdup_printf ("<span weight=\"bold\">%s</span>", text);
- label = gtk_label_new (full);
- g_free (full);
+ full = g_strdup_printf ("<span weight=\"bold\">%s</span>", text);
+ label = gtk_label_new (full);
+ g_free (full);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- return label;
+ return label;
}
static GtkWidget *
create_sys_view (ProcData *procdata)
{
- GtkWidget *vbox, *hbox;
- GtkWidget *cpu_box, *mem_box, *net_box;
- GtkWidget *cpu_graph_box, *mem_graph_box, *net_graph_box;
- GtkWidget *label,*cpu_label, *spacer;
- GtkWidget *table;
- GtkWidget *color_picker;
- GtkWidget *mem_legend_box, *net_legend_box;
- LoadGraph *cpu_graph, *mem_graph, *net_graph;
- gint i;
-
-
- vbox = gtk_vbox_new (FALSE, 18);
-
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
- /* The CPU BOX */
-
- cpu_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), cpu_box, TRUE, TRUE, 0);
-
- label = make_title_label (_("CPU History"));
- gtk_box_pack_start (GTK_BOX (cpu_box), label, FALSE, FALSE, 0);
-
- cpu_graph_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (cpu_box), cpu_graph_box, TRUE, TRUE, 0);
-
- cpu_graph = new LoadGraph(LOAD_GRAPH_CPU);
- gtk_box_pack_start (GTK_BOX (cpu_graph_box),
- load_graph_get_widget(cpu_graph),
- TRUE,
- TRUE,
- 0);
-
- hbox = gtk_hbox_new(FALSE, 0);
- spacer = gtk_label_new ("");
- gtk_widget_set_size_request(GTK_WIDGET(spacer), 57, -1);
- gtk_box_pack_start (GTK_BOX (hbox), spacer,
- FALSE, FALSE, 0);
-
-
- gtk_box_pack_start (GTK_BOX (cpu_graph_box), hbox,
- FALSE, FALSE, 0);
-
- /*cpu_legend_box = gtk_hbox_new(TRUE, 10);
- gtk_box_pack_start (GTK_BOX (hbox), cpu_legend_box,
- TRUE, TRUE, 0);*/
-
- GtkWidget* cpu_table = gtk_table_new(std::min(procdata->config.num_cpus / 4, 1),
- std::min(procdata->config.num_cpus, 4),
- TRUE);
- gtk_table_set_row_spacings(GTK_TABLE(cpu_table), 6);
- gtk_table_set_col_spacings(GTK_TABLE(cpu_table), 6);
- gtk_box_pack_start(GTK_BOX(hbox), cpu_table, TRUE, TRUE, 0);
-
- for (i=0;i<procdata->config.num_cpus; i++) {
- GtkWidget *temp_hbox;
- gchar *text;
-
- temp_hbox = gtk_hbox_new (FALSE, 0);
- gtk_table_attach(GTK_TABLE(cpu_table), temp_hbox,
- i % 4, i % 4 + 1,
- i / 4, i / 4 + 1,
- static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
- static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
- 0, 0);
- //gtk_size_group_add_widget (sizegroup, temp_hbox);
- /*g_signal_connect (G_OBJECT (temp_hbox), "size_request",
- G_CALLBACK(size_request), &cpu_size);
+ GtkWidget *vbox, *hbox;
+ GtkWidget *cpu_box, *mem_box, *net_box;
+ GtkWidget *cpu_graph_box, *mem_graph_box, *net_graph_box;
+ GtkWidget *label,*cpu_label, *spacer;
+ GtkWidget *table;
+ GtkWidget *color_picker;
+ GtkWidget *mem_legend_box, *net_legend_box;
+ LoadGraph *cpu_graph, *mem_graph, *net_graph;
+ gint i;
+
+
+ vbox = gtk_vbox_new (FALSE, 18);
+
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+
+ /* The CPU BOX */
+
+ cpu_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), cpu_box, TRUE, TRUE, 0);
+
+ label = make_title_label (_("CPU History"));
+ gtk_box_pack_start (GTK_BOX (cpu_box), label, FALSE, FALSE, 0);
+
+ cpu_graph_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (cpu_box), cpu_graph_box, TRUE, TRUE, 0);
+
+ cpu_graph = new LoadGraph(LOAD_GRAPH_CPU);
+ gtk_box_pack_start (GTK_BOX (cpu_graph_box),
+ load_graph_get_widget(cpu_graph),
+ TRUE,
+ TRUE,
+ 0);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ spacer = gtk_label_new ("");
+ gtk_widget_set_size_request(GTK_WIDGET(spacer), 57, -1);
+ gtk_box_pack_start (GTK_BOX (hbox), spacer,
+ FALSE, FALSE, 0);
+
+
+ gtk_box_pack_start (GTK_BOX (cpu_graph_box), hbox,
+ FALSE, FALSE, 0);
+
+ /*cpu_legend_box = gtk_hbox_new(TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (hbox), cpu_legend_box,
+ TRUE, TRUE, 0);*/
+
+ GtkWidget* cpu_table = gtk_table_new(std::min(procdata->config.num_cpus / 4, 1),
+ std::min(procdata->config.num_cpus, 4),
+ TRUE);
+ gtk_table_set_row_spacings(GTK_TABLE(cpu_table), 6);
+ gtk_table_set_col_spacings(GTK_TABLE(cpu_table), 6);
+ gtk_box_pack_start(GTK_BOX(hbox), cpu_table, TRUE, TRUE, 0);
+
+ for (i=0;i<procdata->config.num_cpus; i++) {
+ GtkWidget *temp_hbox;
+ gchar *text;
+
+ temp_hbox = gtk_hbox_new (FALSE, 0);
+ gtk_table_attach(GTK_TABLE(cpu_table), temp_hbox,
+ i % 4, i % 4 + 1,
+ i / 4, i / 4 + 1,
+ static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
+ static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
+ 0, 0);
+ //gtk_size_group_add_widget (sizegroup, temp_hbox);
+ /*g_signal_connect (G_OBJECT (temp_hbox), "size_request",
+ G_CALLBACK(size_request), &cpu_size);
*/
- color_picker = gsm_color_button_new (&cpu_graph->colors.at(i), GSMCP_TYPE_CPU);
- g_signal_connect (G_OBJECT (color_picker), "color_set",
- G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
- gtk_box_pack_start (GTK_BOX (temp_hbox), color_picker, FALSE, TRUE, 0);
- gtk_widget_set_size_request(GTK_WIDGET(color_picker), 32, -1);
- if(procdata->config.num_cpus == 1) {
- text = g_strdup (_("CPU"));
- } else {
- text = g_strdup_printf (_("CPU%d"), i+1);
- }
- label = gtk_label_new (text);
- gtk_box_pack_start (GTK_BOX (temp_hbox), label, FALSE, FALSE, 6);
- g_free (text);
-
- cpu_label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (cpu_label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (temp_hbox), cpu_label, TRUE, TRUE, 0);
- load_graph_get_labels(cpu_graph)->cpu[i] = cpu_label;
-
- }
-
- procdata->cpu_graph = cpu_graph;
-
- mem_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), mem_box, TRUE, TRUE, 0);
-
- label = make_title_label (_("Memory and Swap History"));
- gtk_box_pack_start (GTK_BOX (mem_box), label, FALSE, FALSE, 0);
-
- mem_graph_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (mem_box), mem_graph_box, TRUE, TRUE, 0);
-
-
- mem_graph = new LoadGraph(LOAD_GRAPH_MEM);
- gtk_box_pack_start (GTK_BOX (mem_graph_box),
- load_graph_get_widget(mem_graph),
- TRUE,
- TRUE,
- 0);
-
- hbox = gtk_hbox_new(FALSE, 0);
- spacer = gtk_label_new ("");
- gtk_widget_set_size_request(GTK_WIDGET(spacer), 54, -1);
- gtk_box_pack_start (GTK_BOX (hbox), spacer,
- FALSE, FALSE, 0);
-
-
- gtk_box_pack_start (GTK_BOX (mem_graph_box), hbox,
- FALSE, FALSE, 0);
-
- mem_legend_box = gtk_hbox_new(TRUE, 10);
- gtk_box_pack_start (GTK_BOX (hbox), mem_legend_box,
- TRUE, TRUE, 0);
-
- table = gtk_table_new (2, 7, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 6);
- gtk_box_pack_start (GTK_BOX (mem_legend_box), table,
- TRUE, TRUE, 0);
-
- color_picker = load_graph_get_mem_color_picker(mem_graph);
- g_signal_connect (G_OBJECT (color_picker), "color_set",
- G_CALLBACK (cb_mem_color_changed), procdata);
- gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
-
- label = gtk_label_new (_("Memory"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_table_attach (GTK_TABLE (table),
- load_graph_get_labels(mem_graph)->memory,
- 1,
- 2,
- 1,
- 2,
- GTK_FILL,
- GTK_FILL,
- 0,
- 0);
-
- table = gtk_table_new (2, 7, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 6);
- gtk_box_pack_start (GTK_BOX (mem_legend_box), table,
- TRUE, TRUE, 0);
-
- color_picker = load_graph_get_swap_color_picker(mem_graph);
- g_signal_connect (G_OBJECT (color_picker), "color_set",
- G_CALLBACK (cb_swap_color_changed), procdata);
- gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
-
- label = gtk_label_new (_("Swap"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_table_attach (GTK_TABLE (table),
- load_graph_get_labels(mem_graph)->swap,
- 1,
- 2,
- 1,
- 2,
- GTK_FILL,
- GTK_FILL,
- 0,
- 0);
-
- procdata->mem_graph = mem_graph;
-
- /* The net box */
- net_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), net_box, TRUE, TRUE, 0);
-
- label = make_title_label (_("Network History"));
- gtk_box_pack_start (GTK_BOX (net_box), label, FALSE, FALSE, 0);
-
- net_graph_box = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (net_box), net_graph_box, TRUE, TRUE, 0);
-
- net_graph = new LoadGraph(LOAD_GRAPH_NET);
- gtk_box_pack_start (GTK_BOX (net_graph_box),
- load_graph_get_widget(net_graph),
- TRUE,
- TRUE,
- 0);
-
- hbox = gtk_hbox_new(FALSE, 0);
- spacer = gtk_label_new ("");
- gtk_widget_set_size_request(GTK_WIDGET(spacer), 54, -1);
- gtk_box_pack_start (GTK_BOX (hbox), spacer,
- FALSE, FALSE, 0);
-
-
- gtk_box_pack_start (GTK_BOX (net_graph_box), hbox,
- FALSE, FALSE, 0);
-
- net_legend_box = gtk_hbox_new(TRUE, 10);
- gtk_box_pack_start (GTK_BOX (hbox), net_legend_box,
- TRUE, TRUE, 0);
-
- table = gtk_table_new (2, 4, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 6);
- gtk_box_pack_start (GTK_BOX (net_legend_box), table,
- TRUE, TRUE, 0);
-
- color_picker = gsm_color_button_new (
- &net_graph->colors.at(0), GSMCP_TYPE_NETWORK_IN);
- g_signal_connect (G_OBJECT (color_picker), "color_set",
- G_CALLBACK (cb_net_in_color_changed), procdata);
- gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
-
- label = gtk_label_new (_("Receiving"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_in),
- 1.0,
- 0.5);
+ color_picker = gsm_color_button_new (&cpu_graph->colors.at(i), GSMCP_TYPE_CPU);
+ g_signal_connect (G_OBJECT (color_picker), "color_set",
+ G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
+ gtk_box_pack_start (GTK_BOX (temp_hbox), color_picker, FALSE, TRUE, 0);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 32, -1);
+ if(procdata->config.num_cpus == 1) {
+ text = g_strdup (_("CPU"));
+ } else {
+ text = g_strdup_printf (_("CPU%d"), i+1);
+ }
+ label = gtk_label_new (text);
+ gtk_box_pack_start (GTK_BOX (temp_hbox), label, FALSE, FALSE, 6);
+ g_free (text);
+
+ cpu_label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (cpu_label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (temp_hbox), cpu_label, TRUE, TRUE, 0);
+ load_graph_get_labels(cpu_graph)->cpu[i] = cpu_label;
+
+ }
+
+ procdata->cpu_graph = cpu_graph;
+
+ mem_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), mem_box, TRUE, TRUE, 0);
+
+ label = make_title_label (_("Memory and Swap History"));
+ gtk_box_pack_start (GTK_BOX (mem_box), label, FALSE, FALSE, 0);
+
+ mem_graph_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (mem_box), mem_graph_box, TRUE, TRUE, 0);
+
+
+ mem_graph = new LoadGraph(LOAD_GRAPH_MEM);
+ gtk_box_pack_start (GTK_BOX (mem_graph_box),
+ load_graph_get_widget(mem_graph),
+ TRUE,
+ TRUE,
+ 0);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ spacer = gtk_label_new ("");
+ gtk_widget_set_size_request(GTK_WIDGET(spacer), 54, -1);
+ gtk_box_pack_start (GTK_BOX (hbox), spacer,
+ FALSE, FALSE, 0);
+
+
+ gtk_box_pack_start (GTK_BOX (mem_graph_box), hbox,
+ FALSE, FALSE, 0);
+
+ mem_legend_box = gtk_hbox_new(TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (hbox), mem_legend_box,
+ TRUE, TRUE, 0);
+
+ table = gtk_table_new (2, 7, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (mem_legend_box), table,
+ TRUE, TRUE, 0);
+
+ color_picker = load_graph_get_mem_color_picker(mem_graph);
+ g_signal_connect (G_OBJECT (color_picker), "color_set",
+ G_CALLBACK (cb_mem_color_changed), procdata);
+ gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+ label = gtk_label_new (_("Memory"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_table_attach (GTK_TABLE (table),
+ load_graph_get_labels(mem_graph)->memory,
+ 1,
+ 2,
+ 1,
+ 2,
+ GTK_FILL,
+ GTK_FILL,
+ 0,
+ 0);
+
+ table = gtk_table_new (2, 7, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (mem_legend_box), table,
+ TRUE, TRUE, 0);
+
+ color_picker = load_graph_get_swap_color_picker(mem_graph);
+ g_signal_connect (G_OBJECT (color_picker), "color_set",
+ G_CALLBACK (cb_swap_color_changed), procdata);
+ gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+ label = gtk_label_new (_("Swap"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_table_attach (GTK_TABLE (table),
+ load_graph_get_labels(mem_graph)->swap,
+ 1,
+ 2,
+ 1,
+ 2,
+ GTK_FILL,
+ GTK_FILL,
+ 0,
+ 0);
+
+ procdata->mem_graph = mem_graph;
+
+ /* The net box */
+ net_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), net_box, TRUE, TRUE, 0);
+
+ label = make_title_label (_("Network History"));
+ gtk_box_pack_start (GTK_BOX (net_box), label, FALSE, FALSE, 0);
+
+ net_graph_box = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (net_box), net_graph_box, TRUE, TRUE, 0);
+
+ net_graph = new LoadGraph(LOAD_GRAPH_NET);
+ gtk_box_pack_start (GTK_BOX (net_graph_box),
+ load_graph_get_widget(net_graph),
+ TRUE,
+ TRUE,
+ 0);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ spacer = gtk_label_new ("");
+ gtk_widget_set_size_request(GTK_WIDGET(spacer), 54, -1);
+ gtk_box_pack_start (GTK_BOX (hbox), spacer,
+ FALSE, FALSE, 0);
+
+
+ gtk_box_pack_start (GTK_BOX (net_graph_box), hbox,
+ FALSE, FALSE, 0);
+
+ net_legend_box = gtk_hbox_new(TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (hbox), net_legend_box,
+ TRUE, TRUE, 0);
+
+ table = gtk_table_new (2, 4, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (net_legend_box), table,
+ TRUE, TRUE, 0);
+
+ color_picker = gsm_color_button_new (
+ &net_graph->colors.at(0), GSMCP_TYPE_NETWORK_IN);
+ g_signal_connect (G_OBJECT (color_picker), "color_set",
+ G_CALLBACK (cb_net_in_color_changed), procdata);
+ gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+ label = gtk_label_new (_("Receiving"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_in),
+ 1.0,
+ 0.5);
/*
- hbox = gtk_hbox_new (FALSE, 0);
- g_signal_connect (G_OBJECT (hbox), "size_request",
- G_CALLBACK(size_request), &net_size);
- gtk_box_pack_start (GTK_BOX (hbox),
- load_graph_get_labels(net_graph)->net_in,
- TRUE,
- TRUE,
- 0);
+ hbox = gtk_hbox_new (FALSE, 0);
+ g_signal_connect (G_OBJECT (hbox), "size_request",
+ G_CALLBACK(size_request), &net_size);
+ gtk_box_pack_start (GTK_BOX (hbox),
+ load_graph_get_labels(net_graph)->net_in,
+ TRUE,
+ TRUE,
+ 0);
*/
- gtk_widget_set_size_request(GTK_WIDGET(load_graph_get_labels(net_graph)->net_in), 100, -1);
- gtk_table_attach (GTK_TABLE (table), load_graph_get_labels(net_graph)->net_in, 2, 3, 0, 1,
- static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-
- label = gtk_label_new (_("Total Received"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_in_total),
- 1.0,
- 0.5);
- gtk_table_attach (GTK_TABLE (table),
- load_graph_get_labels(net_graph)->net_in_total,
- 2,
- 3,
- 1,
- 2,
- GTK_FILL,
- GTK_FILL,
- 0,
- 0);
-
- spacer = gtk_label_new ("");
- gtk_widget_set_size_request(GTK_WIDGET(spacer), 38, -1);
- gtk_table_attach (GTK_TABLE (table), spacer, 3, 4, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- table = gtk_table_new (2, 3, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 6);
- gtk_box_pack_start (GTK_BOX (net_legend_box), table,
- TRUE, TRUE, 0);
-
- color_picker = gsm_color_button_new (
- &net_graph->colors.at(1), GSMCP_TYPE_NETWORK_OUT);
- g_signal_connect (G_OBJECT (color_picker), "color_set",
- G_CALLBACK (cb_net_out_color_changed), procdata);
- gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
-
- label = gtk_label_new (_("Sending"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_out),
- 1.0,
- 0.5);
+ gtk_widget_set_size_request(GTK_WIDGET(load_graph_get_labels(net_graph)->net_in), 100, -1);
+ gtk_table_attach (GTK_TABLE (table), load_graph_get_labels(net_graph)->net_in, 2, 3, 0, 1,
+ static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
+
+ label = gtk_label_new (_("Total Received"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_in_total),
+ 1.0,
+ 0.5);
+ gtk_table_attach (GTK_TABLE (table),
+ load_graph_get_labels(net_graph)->net_in_total,
+ 2,
+ 3,
+ 1,
+ 2,
+ GTK_FILL,
+ GTK_FILL,
+ 0,
+ 0);
+
+ spacer = gtk_label_new ("");
+ gtk_widget_set_size_request(GTK_WIDGET(spacer), 38, -1);
+ gtk_table_attach (GTK_TABLE (table), spacer, 3, 4, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ table = gtk_table_new (2, 3, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+ gtk_box_pack_start (GTK_BOX (net_legend_box), table,
+ TRUE, TRUE, 0);
+
+ color_picker = gsm_color_button_new (
+ &net_graph->colors.at(1), GSMCP_TYPE_NETWORK_OUT);
+ g_signal_connect (G_OBJECT (color_picker), "color_set",
+ G_CALLBACK (cb_net_out_color_changed), procdata);
+ gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+ label = gtk_label_new (_("Sending"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_out),
+ 1.0,
+ 0.5);
/*
- hbox = gtk_hbox_new (FALSE, 0);
- g_signal_connect (G_OBJECT (load_graph_get_labels(net_graph)->net_out), "size_request",
- G_CALLBACK(size_request), &net_size);
-
- gtk_box_pack_start (GTK_BOX (hbox),
- load_graph_get_labels(net_graph)->net_out,
- TRUE,
- TRUE,
- 0);
+ hbox = gtk_hbox_new (FALSE, 0);
+ g_signal_connect (G_OBJECT (load_graph_get_labels(net_graph)->net_out), "size_request",
+ G_CALLBACK(size_request), &net_size);
+
+ gtk_box_pack_start (GTK_BOX (hbox),
+ load_graph_get_labels(net_graph)->net_out,
+ TRUE,
+ TRUE,
+ 0);
*/
- gtk_widget_set_size_request(GTK_WIDGET(load_graph_get_labels(net_graph)->net_out), 100, -1);
- gtk_table_attach (GTK_TABLE (table), load_graph_get_labels(net_graph)->net_out, 2, 3, 0, 1,
- static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-
- label = gtk_label_new (_("Total Sent"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
-
- gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_out_total),
- 1.0,
- 0.5);
- gtk_table_attach (GTK_TABLE (table),
- load_graph_get_labels(net_graph)->net_out_total,
- 2,
- 3,
- 1,
- 2,
- GTK_FILL,
- GTK_FILL,
- 0,
- 0);
-
- spacer = gtk_label_new ("");
- gtk_widget_set_size_request(GTK_WIDGET(spacer), 38, -1);
- gtk_table_attach (GTK_TABLE (table), spacer, 3, 4, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
-
- procdata->net_graph = net_graph;
-
- return vbox;
+ gtk_widget_set_size_request(GTK_WIDGET(load_graph_get_labels(net_graph)->net_out), 100, -1);
+ gtk_table_attach (GTK_TABLE (table), load_graph_get_labels(net_graph)->net_out, 2, 3, 0, 1,
+ static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
+
+ label = gtk_label_new (_("Total Sent"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+
+ gtk_misc_set_alignment (GTK_MISC (load_graph_get_labels(net_graph)->net_out_total),
+ 1.0,
+ 0.5);
+ gtk_table_attach (GTK_TABLE (table),
+ load_graph_get_labels(net_graph)->net_out_total,
+ 2,
+ 3,
+ 1,
+ 2,
+ GTK_FILL,
+ GTK_FILL,
+ 0,
+ 0);
+
+ spacer = gtk_label_new ("");
+ gtk_widget_set_size_request(GTK_WIDGET(spacer), 38, -1);
+ gtk_table_attach (GTK_TABLE (table), spacer, 3, 4, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+
+ procdata->net_graph = net_graph;
+
+ return vbox;
}
static void
menu_item_select_cb (GtkMenuItem *proxy,
ProcData *procdata)
{
- GtkAction *action;
- char *message;
-
- action = gtk_activatable_get_related_action (GTK_ACTIVATABLE(proxy));
- g_assert(action);
-
- g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
- if (message)
- {
- gtk_statusbar_push (GTK_STATUSBAR (procdata->statusbar),
- procdata->tip_message_cid, message);
- g_free (message);
- }
+ GtkAction *action;
+ char *message;
+
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE(proxy));
+ g_assert(action);
+
+ g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
+ if (message)
+ {
+ gtk_statusbar_push (GTK_STATUSBAR (procdata->statusbar),
+ procdata->tip_message_cid, message);
+ g_free (message);
+ }
}
static void
menu_item_deselect_cb (GtkMenuItem *proxy,
ProcData *procdata)
{
- gtk_statusbar_pop (GTK_STATUSBAR (procdata->statusbar),
- procdata->tip_message_cid);
+ gtk_statusbar_pop (GTK_STATUSBAR (procdata->statusbar),
+ procdata->tip_message_cid);
}
static void
@@ -578,12 +578,12 @@ connect_proxy_cb (GtkUIManager *manager,
GtkWidget *proxy,
ProcData *procdata)
{
- if (GTK_IS_MENU_ITEM (proxy)) {
- g_signal_connect (proxy, "select",
- G_CALLBACK (menu_item_select_cb), procdata);
- g_signal_connect (proxy, "deselect",
- G_CALLBACK (menu_item_deselect_cb), procdata);
- }
+ if (GTK_IS_MENU_ITEM (proxy)) {
+ g_signal_connect (proxy, "select",
+ G_CALLBACK (menu_item_select_cb), procdata);
+ g_signal_connect (proxy, "deselect",
+ G_CALLBACK (menu_item_deselect_cb), procdata);
+ }
}
static void
@@ -592,241 +592,241 @@ disconnect_proxy_cb (GtkUIManager *manager,
GtkWidget *proxy,
ProcData *procdata)
{
- if (GTK_IS_MENU_ITEM (proxy)) {
- g_signal_handlers_disconnect_by_func
- (proxy, (void*)(G_CALLBACK(menu_item_select_cb)), procdata);
- g_signal_handlers_disconnect_by_func
- (proxy, (void*)(G_CALLBACK(menu_item_deselect_cb)), procdata);
- }
+ if (GTK_IS_MENU_ITEM (proxy)) {
+ g_signal_handlers_disconnect_by_func
+ (proxy, (void*)(G_CALLBACK(menu_item_select_cb)), procdata);
+ g_signal_handlers_disconnect_by_func
+ (proxy, (void*)(G_CALLBACK(menu_item_deselect_cb)), procdata);
+ }
}
void
create_main_window (ProcData *procdata)
{
- gint i;
- gint width, height;
- GtkWidget *app;
- GtkAction *action;
- GtkWidget *menubar;
- GtkWidget *main_box;
- GtkWidget *notebook;
- GtkWidget *tab_label1, *tab_label2, *tab_label3;
- GtkWidget *vbox1;
- GtkWidget *sys_box, *devices_box;
- GtkWidget *sysinfo_box, *sysinfo_label;
-
- app = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(app), _("System Monitor"));
-
- GdkScreen* screen = gtk_widget_get_screen(app);
+ gint i;
+ gint width, height;
+ GtkWidget *app;
+ GtkAction *action;
+ GtkWidget *menubar;
+ GtkWidget *main_box;
+ GtkWidget *notebook;
+ GtkWidget *tab_label1, *tab_label2, *tab_label3;
+ GtkWidget *vbox1;
+ GtkWidget *sys_box, *devices_box;
+ GtkWidget *sysinfo_box, *sysinfo_label;
+
+ app = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(app), _("System Monitor"));
+
+ GdkScreen* screen = gtk_widget_get_screen(app);
#if GTK_CHECK_VERSION(3,0,0)
- /* use visual, if available */
- GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
- if (visual)
- gtk_widget_set_visual(app, visual);
+ /* use visual, if available */
+ GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
+ if (visual)
+ gtk_widget_set_visual(app, visual);
#else
- /* use rgba colormap, if available */
- GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);
- if (colormap)
- gtk_widget_set_default_colormap(colormap);
+ /* use rgba colormap, if available */
+ GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);
+ if (colormap)
+ gtk_widget_set_default_colormap(colormap);
#endif
- main_box = gtk_vbox_new (FALSE, 0);
- gtk_container_add(GTK_CONTAINER(app), main_box);
-
- width = procdata->config.width;
- height = procdata->config.height;
- gtk_window_set_default_size (GTK_WINDOW (app), width, height);
- gtk_window_set_resizable (GTK_WINDOW (app), TRUE);
-
- /* create the menubar */
- procdata->uimanager = gtk_ui_manager_new ();
-
- /* show tooltips in the statusbar */
- g_signal_connect (procdata->uimanager, "connect_proxy",
- G_CALLBACK (connect_proxy_cb), procdata);
- g_signal_connect (procdata->uimanager, "disconnect_proxy",
- G_CALLBACK (disconnect_proxy_cb), procdata);
-
- gtk_window_add_accel_group (GTK_WINDOW (app),
- gtk_ui_manager_get_accel_group (procdata->uimanager));
-
- if (!gtk_ui_manager_add_ui_from_string (procdata->uimanager,
- ui_info,
- -1,
- NULL)) {
- g_error("building menus failed");
- }
-
- procdata->action_group = gtk_action_group_new ("ProcmanActions");
- gtk_action_group_set_translation_domain (procdata->action_group, NULL);
- gtk_action_group_add_actions (procdata->action_group,
- menu_entries,
- G_N_ELEMENTS (menu_entries),
- procdata);
- gtk_action_group_add_toggle_actions (procdata->action_group,
- toggle_menu_entries,
- G_N_ELEMENTS (toggle_menu_entries),
- procdata);
-
- gtk_action_group_add_radio_actions (procdata->action_group,
- radio_menu_entries,
- G_N_ELEMENTS (radio_menu_entries),
- procdata->config.whose_process,
- G_CALLBACK(cb_radio_processes),
- procdata);
-
- gtk_ui_manager_insert_action_group (procdata->uimanager,
- procdata->action_group,
- 0);
-
- menubar = gtk_ui_manager_get_widget (procdata->uimanager, "/MenuBar");
- gtk_box_pack_start (GTK_BOX (main_box), menubar, FALSE, FALSE, 0);
-
-
- /* create the main notebook */
- procdata->notebook = notebook = gtk_notebook_new ();
- gtk_box_pack_start (GTK_BOX (main_box),
- notebook,
- TRUE,
- TRUE,
- 0);
-
- sysinfo_box = gtk_hbox_new(TRUE, 0); // procman_create_sysinfo_view();
- sysinfo_label = gtk_label_new(_("System"));
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sysinfo_box, sysinfo_label);
-
- vbox1 = create_proc_view (procdata);
- tab_label1 = gtk_label_new (_("Processes"));
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox1, tab_label1);
-
- sys_box = create_sys_view (procdata);
- tab_label2 = gtk_label_new (_("Resources"));
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, tab_label2);
-
- devices_box = create_disk_view (procdata);
- tab_label3 = gtk_label_new (_("File Systems"));
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), devices_box, tab_label3);
-
- g_signal_connect (G_OBJECT (notebook), "switch-page",
- G_CALLBACK (cb_switch_page), procdata);
- g_signal_connect (G_OBJECT (notebook), "change-current-page",
- G_CALLBACK (cb_change_current_page), procdata);
-
- gtk_widget_show_all(notebook); // need to make page switch work
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), procdata->config.current_tab);
- cb_change_current_page (GTK_NOTEBOOK (notebook), procdata->config.current_tab, procdata);
- g_signal_connect (G_OBJECT (app), "delete_event",
- G_CALLBACK (cb_app_delete),
- procdata);
-
- GtkAccelGroup *accel_group;
- GClosure *goto_tab_closure[4];
- accel_group = gtk_accel_group_new ();
- gtk_window_add_accel_group (GTK_WINDOW(app), accel_group);
- for (i = 0; i < 4; ++i) {
- goto_tab_closure[i] = g_cclosure_new_swap (G_CALLBACK (cb_proc_goto_tab),
- (gpointer) i, NULL);
- gtk_accel_group_connect (accel_group, '0'+(i+1),
- GDK_MOD1_MASK, GTK_ACCEL_VISIBLE,
- goto_tab_closure[i]);
- }
-
- /* create the statusbar */
- procdata->statusbar = gtk_statusbar_new();
- gtk_box_pack_end(GTK_BOX(main_box), procdata->statusbar, FALSE, FALSE, 0);
- procdata->tip_message_cid = gtk_statusbar_get_context_id
- (GTK_STATUSBAR (procdata->statusbar), "tip_message");
-
-
- action = gtk_action_group_get_action (procdata->action_group, "ShowDependencies");
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- procdata->config.show_tree);
-
- gtk_widget_show_all(app);
- procdata->app = app;
+ main_box = gtk_vbox_new (FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(app), main_box);
+
+ width = procdata->config.width;
+ height = procdata->config.height;
+ gtk_window_set_default_size (GTK_WINDOW (app), width, height);
+ gtk_window_set_resizable (GTK_WINDOW (app), TRUE);
+
+ /* create the menubar */
+ procdata->uimanager = gtk_ui_manager_new ();
+
+ /* show tooltips in the statusbar */
+ g_signal_connect (procdata->uimanager, "connect_proxy",
+ G_CALLBACK (connect_proxy_cb), procdata);
+ g_signal_connect (procdata->uimanager, "disconnect_proxy",
+ G_CALLBACK (disconnect_proxy_cb), procdata);
+
+ gtk_window_add_accel_group (GTK_WINDOW (app),
+ gtk_ui_manager_get_accel_group (procdata->uimanager));
+
+ if (!gtk_ui_manager_add_ui_from_string (procdata->uimanager,
+ ui_info,
+ -1,
+ NULL)) {
+ g_error("building menus failed");
+ }
+
+ procdata->action_group = gtk_action_group_new ("ProcmanActions");
+ gtk_action_group_set_translation_domain (procdata->action_group, NULL);
+ gtk_action_group_add_actions (procdata->action_group,
+ menu_entries,
+ G_N_ELEMENTS (menu_entries),
+ procdata);
+ gtk_action_group_add_toggle_actions (procdata->action_group,
+ toggle_menu_entries,
+ G_N_ELEMENTS (toggle_menu_entries),
+ procdata);
+
+ gtk_action_group_add_radio_actions (procdata->action_group,
+ radio_menu_entries,
+ G_N_ELEMENTS (radio_menu_entries),
+ procdata->config.whose_process,
+ G_CALLBACK(cb_radio_processes),
+ procdata);
+
+ gtk_ui_manager_insert_action_group (procdata->uimanager,
+ procdata->action_group,
+ 0);
+
+ menubar = gtk_ui_manager_get_widget (procdata->uimanager, "/MenuBar");
+ gtk_box_pack_start (GTK_BOX (main_box), menubar, FALSE, FALSE, 0);
+
+
+ /* create the main notebook */
+ procdata->notebook = notebook = gtk_notebook_new ();
+ gtk_box_pack_start (GTK_BOX (main_box),
+ notebook,
+ TRUE,
+ TRUE,
+ 0);
+
+ sysinfo_box = gtk_hbox_new(TRUE, 0); // procman_create_sysinfo_view();
+ sysinfo_label = gtk_label_new(_("System"));
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sysinfo_box, sysinfo_label);
+
+ vbox1 = create_proc_view (procdata);
+ tab_label1 = gtk_label_new (_("Processes"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox1, tab_label1);
+
+ sys_box = create_sys_view (procdata);
+ tab_label2 = gtk_label_new (_("Resources"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, tab_label2);
+
+ devices_box = create_disk_view (procdata);
+ tab_label3 = gtk_label_new (_("File Systems"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), devices_box, tab_label3);
+
+ g_signal_connect (G_OBJECT (notebook), "switch-page",
+ G_CALLBACK (cb_switch_page), procdata);
+ g_signal_connect (G_OBJECT (notebook), "change-current-page",
+ G_CALLBACK (cb_change_current_page), procdata);
+
+ gtk_widget_show_all(notebook); // need to make page switch work
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), procdata->config.current_tab);
+ cb_change_current_page (GTK_NOTEBOOK (notebook), procdata->config.current_tab, procdata);
+ g_signal_connect (G_OBJECT (app), "delete_event",
+ G_CALLBACK (cb_app_delete),
+ procdata);
+
+ GtkAccelGroup *accel_group;
+ GClosure *goto_tab_closure[4];
+ accel_group = gtk_accel_group_new ();
+ gtk_window_add_accel_group (GTK_WINDOW(app), accel_group);
+ for (i = 0; i < 4; ++i) {
+ goto_tab_closure[i] = g_cclosure_new_swap (G_CALLBACK (cb_proc_goto_tab),
+ (gpointer) i, NULL);
+ gtk_accel_group_connect (accel_group, '0'+(i+1),
+ GDK_MOD1_MASK, GTK_ACCEL_VISIBLE,
+ goto_tab_closure[i]);
+ }
+
+ /* create the statusbar */
+ procdata->statusbar = gtk_statusbar_new();
+ gtk_box_pack_end(GTK_BOX(main_box), procdata->statusbar, FALSE, FALSE, 0);
+ procdata->tip_message_cid = gtk_statusbar_get_context_id
+ (GTK_STATUSBAR (procdata->statusbar), "tip_message");
+
+
+ action = gtk_action_group_get_action (procdata->action_group, "ShowDependencies");
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+ procdata->config.show_tree);
+
+ gtk_widget_show_all(app);
+ procdata->app = app;
}
void
do_popup_menu (ProcData *procdata, GdkEventButton *event)
{
- guint button;
- guint32 event_time;
-
- if (event) {
- button = event->button;
- event_time = event->time;
- }
- else {
- button = 0;
- event_time = gtk_get_current_event_time ();
- }
-
- gtk_menu_popup (GTK_MENU (procdata->popup_menu), NULL, NULL,
- NULL, NULL, button, event_time);
+ guint button;
+ guint32 event_time;
+
+ if (event) {
+ button = event->button;
+ event_time = event->time;
+ }
+ else {
+ button = 0;
+ event_time = gtk_get_current_event_time ();
+ }
+
+ gtk_menu_popup (GTK_MENU (procdata->popup_menu), NULL, NULL,
+ NULL, NULL, button, event_time);
}
void
update_sensitivity(ProcData *data)
{
- const char * const selected_actions[] = { "StopProcess",
- "ContProcess",
- "EndProcess",
- "KillProcess",
- "ChangePriority",
- "MemoryMaps",
- "OpenFiles" };
-
- const char * const processes_actions[] = { "ShowActiveProcesses",
- "ShowAllProcesses",
- "ShowMyProcesses",
- "ShowDependencies",
- "Refresh"
- };
-
- size_t i;
- gboolean processes_sensitivity, selected_sensitivity;
- GtkAction *action;
-
- processes_sensitivity = (data->config.current_tab == PROCMAN_TAB_PROCESSES);
- selected_sensitivity = (processes_sensitivity && data->selected_process != NULL);
-
- if(data->endprocessbutton) {
- /* avoid error on startup if endprocessbutton
- has not been built yet */
- gtk_widget_set_sensitive(data->endprocessbutton, selected_sensitivity);
- }
-
- for (i = 0; i != G_N_ELEMENTS(processes_actions); ++i) {
- action = gtk_action_group_get_action(data->action_group,
- processes_actions[i]);
- gtk_action_set_sensitive(action, processes_sensitivity);
- }
-
- for (i = 0; i != G_N_ELEMENTS(selected_actions); ++i) {
- action = gtk_action_group_get_action(data->action_group,
- selected_actions[i]);
- gtk_action_set_sensitive(action, selected_sensitivity);
- }
+ const char * const selected_actions[] = { "StopProcess",
+ "ContProcess",
+ "EndProcess",
+ "KillProcess",
+ "ChangePriority",
+ "MemoryMaps",
+ "OpenFiles" };
+
+ const char * const processes_actions[] = { "ShowActiveProcesses",
+ "ShowAllProcesses",
+ "ShowMyProcesses",
+ "ShowDependencies",
+ "Refresh"
+ };
+
+ size_t i;
+ gboolean processes_sensitivity, selected_sensitivity;
+ GtkAction *action;
+
+ processes_sensitivity = (data->config.current_tab == PROCMAN_TAB_PROCESSES);
+ selected_sensitivity = (processes_sensitivity && data->selected_process != NULL);
+
+ if(data->endprocessbutton) {
+ /* avoid error on startup if endprocessbutton
+ has not been built yet */
+ gtk_widget_set_sensitive(data->endprocessbutton, selected_sensitivity);
+ }
+
+ for (i = 0; i != G_N_ELEMENTS(processes_actions); ++i) {
+ action = gtk_action_group_get_action(data->action_group,
+ processes_actions[i]);
+ gtk_action_set_sensitive(action, processes_sensitivity);
+ }
+
+ for (i = 0; i != G_N_ELEMENTS(selected_actions); ++i) {
+ action = gtk_action_group_get_action(data->action_group,
+ selected_actions[i]);
+ gtk_action_set_sensitive(action, selected_sensitivity);
+ }
}
-static void
+static void
cb_toggle_tree (GtkAction *action, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
- gboolean show;
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
+ gboolean show;
- show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
- if (show == procdata->config.show_tree)
- return;
+ show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ if (show == procdata->config.show_tree)
+ return;
- g_settings_set_boolean (settings, "show-tree", show);
+ g_settings_set_boolean (settings, "show-tree", show);
}
static void
cb_proc_goto_tab (gint tab)
{
- ProcData *data = ProcData::get_instance ();
- gtk_notebook_set_current_page (GTK_NOTEBOOK (data->notebook), tab);
+ ProcData *data = ProcData::get_instance ();
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (data->notebook), tab);
}
diff --git a/src/interface.h b/src/interface.h
index 0d35544..a69574a 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -24,9 +24,9 @@
#include <gtk/gtk.h>
#include "procman.h"
-void create_main_window (ProcData *data);
-void update_sensitivity (ProcData *data);
+void create_main_window (ProcData *data);
+void update_sensitivity (ProcData *data);
void do_popup_menu(ProcData *data, GdkEventButton *event);
-GtkWidget * make_title_label (const char *text);
+GtkWidget * make_title_label (const char *text);
#endif /* _PROCMAN_INTERFACE_H_ */
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 3a387d3..fd4afc1 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -31,175 +31,175 @@
void LoadGraph::clear_background()
{
- if (this->background) {
+ if (this->background) {
#if GTK_CHECK_VERSION(3,0,0)
- cairo_surface_destroy (this->background);
+ cairo_surface_destroy (this->background);
#else
- g_object_unref(this->background);
+ g_object_unref(this->background);
#endif
- this->background = NULL;
- }
+ this->background = NULL;
+ }
}
unsigned LoadGraph::num_bars() const
{
- unsigned n;
-
- // keep 100 % num_bars == 0
- switch (static_cast<int>(this->draw_height / (this->fontsize + 14)))
- {
- case 0:
- case 1:
- n = 1;
- break;
- case 2:
- case 3:
- n = 2;
- break;
- case 4:
- n = 4;
- break;
- default:
- n = 5;
- }
-
- return n;
+ unsigned n;
+
+ // keep 100 % num_bars == 0
+ switch (static_cast<int>(this->draw_height / (this->fontsize + 14)))
+ {
+ case 0:
+ case 1:
+ n = 1;
+ break;
+ case 2:
+ case 3:
+ n = 2;
+ break;
+ case 4:
+ n = 4;
+ break;
+ default:
+ n = 5;
+ }
+
+ return n;
}
#define FRAME_WIDTH 4
static void draw_background(LoadGraph *g) {
- GtkAllocation allocation;
- double dash[2] = { 1.0, 2.0 };
- cairo_t *cr;
- guint i;
- unsigned num_bars;
- char *caption;
- cairo_text_extents_t extents;
-
- num_bars = g->num_bars();
- g->graph_dely = (g->draw_height - 15) / num_bars; /* round to int to avoid AA blur */
- g->real_draw_height = g->graph_dely * num_bars;
- g->graph_delx = (g->draw_width - 2.0 - g->rmargin - g->indent) / (LoadGraph::NUM_POINTS - 3);
- g->graph_buffer_offset = (int) (1.5 * g->graph_delx) + FRAME_WIDTH ;
-
- gtk_widget_get_allocation (g->disp, &allocation);
+ GtkAllocation allocation;
+ double dash[2] = { 1.0, 2.0 };
+ cairo_t *cr;
+ guint i;
+ unsigned num_bars;
+ char *caption;
+ cairo_text_extents_t extents;
+
+ num_bars = g->num_bars();
+ g->graph_dely = (g->draw_height - 15) / num_bars; /* round to int to avoid AA blur */
+ g->real_draw_height = g->graph_dely * num_bars;
+ g->graph_delx = (g->draw_width - 2.0 - g->rmargin - g->indent) / (LoadGraph::NUM_POINTS - 3);
+ g->graph_buffer_offset = (int) (1.5 * g->graph_delx) + FRAME_WIDTH ;
+
+ gtk_widget_get_allocation (g->disp, &allocation);
#if GTK_CHECK_VERSION(3,0,0)
- g->background = gdk_window_create_similar_surface (gtk_widget_get_window (g->disp), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
- cr = cairo_create (g->background);
+ g->background = gdk_window_create_similar_surface (gtk_widget_get_window (g->disp), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
+ cr = cairo_create (g->background);
#else
- g->background = gdk_pixmap_new (GDK_DRAWABLE (gtk_widget_get_window (g->disp)), allocation.width, allocation.height, -1);
- cr = gdk_cairo_create (g->background);
+ g->background = gdk_pixmap_new (GDK_DRAWABLE (gtk_widget_get_window (g->disp)), allocation.width, allocation.height, -1);
+ cr = gdk_cairo_create (g->background);
#endif
- // set the background colour
- GtkStyle *style = gtk_widget_get_style (ProcData::get_instance()->notebook);
- gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
- cairo_paint (cr);
-
- /* draw frame */
- cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH);
-
- /* Draw background rectangle */
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- cairo_rectangle (cr, g->rmargin + g->indent, 0,
- g->draw_width - g->rmargin - g->indent, g->real_draw_height);
- cairo_fill(cr);
-
- cairo_set_line_width (cr, 1.0);
- cairo_set_dash (cr, dash, 2, 0);
- cairo_set_font_size (cr, g->fontsize);
-
- for (i = 0; i <= num_bars; ++i) {
- double y;
-
- if (i == 0)
- y = 0.5 + g->fontsize / 2.0;
- else if (i == num_bars)
- y = i * g->graph_dely + 0.5;
- else
- y = i * g->graph_dely + g->fontsize / 2.0;
-
- gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
- if (g->type == LOAD_GRAPH_NET) {
- // operation orders matters so it's 0 if i == num_bars
- unsigned rate = g->net.max - (i * g->net.max / num_bars);
- const std::string caption(procman::format_network_rate(rate, g->net.max));
- cairo_text_extents (cr, caption.c_str(), &extents);
- cairo_move_to (cr, g->indent - extents.width + 20, y);
- cairo_show_text (cr, caption.c_str());
- } else {
- // operation orders matters so it's 0 if i == num_bars
- caption = g_strdup_printf("%d %%", 100 - i * (100 / num_bars));
- cairo_text_extents (cr, caption, &extents);
- cairo_move_to (cr, g->indent - extents.width + 20, y);
- cairo_show_text (cr, caption);
- g_free (caption);
- }
-
- cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
- cairo_move_to (cr, g->rmargin + g->indent - 3, i * g->graph_dely + 0.5);
- cairo_line_to (cr, g->draw_width - 0.5, i * g->graph_dely + 0.5);
- }
- cairo_stroke (cr);
-
- cairo_set_dash (cr, dash, 2, 1.5);
-
- const unsigned total_seconds = g->speed * (LoadGraph::NUM_POINTS - 2) / 1000;
-
- for (unsigned int i = 0; i < 7; i++) {
- double x = (i) * (g->draw_width - g->rmargin - g->indent) / 6;
- cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
- cairo_move_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, 0.5);
- cairo_line_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, g->real_draw_height + 4.5);
- cairo_stroke(cr);
- unsigned seconds = total_seconds - i * total_seconds / 6;
- const char* format;
- if (i == 0)
- format = dngettext(GETTEXT_PACKAGE, "%u second", "%u seconds", seconds);
- else
- format = "%u";
- caption = g_strdup_printf(format, seconds);
- cairo_text_extents (cr, caption, &extents);
- cairo_move_to (cr, ((ceil(x) + 0.5) + g->rmargin + g->indent) - (extents.width/2), g->draw_height);
- gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
- cairo_show_text (cr, caption);
- g_free (caption);
- }
-
- cairo_stroke (cr);
- cairo_destroy (cr);
+ // set the background colour
+ GtkStyle *style = gtk_widget_get_style (ProcData::get_instance()->notebook);
+ gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+ cairo_paint (cr);
+
+ /* draw frame */
+ cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH);
+
+ /* Draw background rectangle */
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_rectangle (cr, g->rmargin + g->indent, 0,
+ g->draw_width - g->rmargin - g->indent, g->real_draw_height);
+ cairo_fill(cr);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_dash (cr, dash, 2, 0);
+ cairo_set_font_size (cr, g->fontsize);
+
+ for (i = 0; i <= num_bars; ++i) {
+ double y;
+
+ if (i == 0)
+ y = 0.5 + g->fontsize / 2.0;
+ else if (i == num_bars)
+ y = i * g->graph_dely + 0.5;
+ else
+ y = i * g->graph_dely + g->fontsize / 2.0;
+
+ gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
+ if (g->type == LOAD_GRAPH_NET) {
+ // operation orders matters so it's 0 if i == num_bars
+ unsigned rate = g->net.max - (i * g->net.max / num_bars);
+ const std::string caption(procman::format_network_rate(rate, g->net.max));
+ cairo_text_extents (cr, caption.c_str(), &extents);
+ cairo_move_to (cr, g->indent - extents.width + 20, y);
+ cairo_show_text (cr, caption.c_str());
+ } else {
+ // operation orders matters so it's 0 if i == num_bars
+ caption = g_strdup_printf("%d %%", 100 - i * (100 / num_bars));
+ cairo_text_extents (cr, caption, &extents);
+ cairo_move_to (cr, g->indent - extents.width + 20, y);
+ cairo_show_text (cr, caption);
+ g_free (caption);
+ }
+
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
+ cairo_move_to (cr, g->rmargin + g->indent - 3, i * g->graph_dely + 0.5);
+ cairo_line_to (cr, g->draw_width - 0.5, i * g->graph_dely + 0.5);
+ }
+ cairo_stroke (cr);
+
+ cairo_set_dash (cr, dash, 2, 1.5);
+
+ const unsigned total_seconds = g->speed * (LoadGraph::NUM_POINTS - 2) / 1000;
+
+ for (unsigned int i = 0; i < 7; i++) {
+ double x = (i) * (g->draw_width - g->rmargin - g->indent) / 6;
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
+ cairo_move_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, 0.5);
+ cairo_line_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, g->real_draw_height + 4.5);
+ cairo_stroke(cr);
+ unsigned seconds = total_seconds - i * total_seconds / 6;
+ const char* format;
+ if (i == 0)
+ format = dngettext(GETTEXT_PACKAGE, "%u second", "%u seconds", seconds);
+ else
+ format = "%u";
+ caption = g_strdup_printf(format, seconds);
+ cairo_text_extents (cr, caption, &extents);
+ cairo_move_to (cr, ((ceil(x) + 0.5) + g->rmargin + g->indent) - (extents.width/2), g->draw_height);
+ gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
+ cairo_show_text (cr, caption);
+ g_free (caption);
+ }
+
+ cairo_stroke (cr);
+ cairo_destroy (cr);
}
/* Redraws the backing buffer for the load graph and updates the window */
void
load_graph_queue_draw (LoadGraph *g)
{
- /* repaint */
- gtk_widget_queue_draw (g->disp);
+ /* repaint */
+ gtk_widget_queue_draw (g->disp);
}
static int load_graph_update (gpointer user_data); // predeclare load_graph_update so we can compile ;)
static gboolean
load_graph_configure (GtkWidget *widget,
- GdkEventConfigure *event,
- gpointer data_ptr)
+ GdkEventConfigure *event,
+ gpointer data_ptr)
{
- GtkAllocation allocation;
- LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
+ GtkAllocation allocation;
+ LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
- gtk_widget_get_allocation (widget, &allocation);
- g->draw_width = allocation.width - 2 * FRAME_WIDTH;
- g->draw_height = allocation.height - 2 * FRAME_WIDTH;
+ gtk_widget_get_allocation (widget, &allocation);
+ g->draw_width = allocation.width - 2 * FRAME_WIDTH;
+ g->draw_height = allocation.height - 2 * FRAME_WIDTH;
- g->clear_background();
+ g->clear_background();
- load_graph_queue_draw (g);
+ load_graph_queue_draw (g);
- return TRUE;
+ return TRUE;
}
#if GTK_CHECK_VERSION(3,0,0)
@@ -208,119 +208,119 @@ static gboolean load_graph_draw (GtkWidget *widget, cairo_t *context, gpointer d
static gboolean load_graph_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data_ptr)
#endif
{
- LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
- GtkAllocation allocation;
- GdkWindow *window;
+ LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
+ GtkAllocation allocation;
+ GdkWindow *window;
- guint i, j;
- gdouble sample_width, x_offset;
+ guint i, j;
+ gdouble sample_width, x_offset;
- window = gtk_widget_get_window (g->disp);
- gtk_widget_get_allocation (g->disp, &allocation);
+ window = gtk_widget_get_window (g->disp);
+ gtk_widget_get_allocation (g->disp, &allocation);
- if (g->background == NULL) {
- draw_background(g);
+ if (g->background == NULL) {
+ draw_background(g);
#if GTK_CHECK_VERSION(3,0,0)
- cairo_pattern_t *pattern = cairo_pattern_create_for_surface (g->background);
- gdk_window_set_background_pattern (window, pattern);
- cairo_pattern_destroy (pattern);
+ cairo_pattern_t *pattern = cairo_pattern_create_for_surface (g->background);
+ gdk_window_set_background_pattern (window, pattern);
+ cairo_pattern_destroy (pattern);
#else
- gdk_window_set_back_pixmap (window, g->background, FALSE);
+ gdk_window_set_back_pixmap (window, g->background, FALSE);
#endif
- }
-
- /* Number of pixels wide for one graph point */
- sample_width = (float)(g->draw_width - g->rmargin - g->indent) / (float)LoadGraph::NUM_POINTS;
- /* General offset */
- x_offset = g->draw_width - g->rmargin + (sample_width*2);
-
- /* Subframe offset */
- x_offset += g->rmargin - ((sample_width / g->frames_per_unit) * g->render_counter);
-
- /* draw the graph */
- cairo_t* cr;
-
- cr = gdk_cairo_create (window);
-
- cairo_set_line_width (cr, 1);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
- cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
- cairo_rectangle (cr, g->rmargin + g->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
- g->draw_width - g->rmargin - g->indent - 1, g->real_draw_height + FRAME_WIDTH - 1);
- cairo_clip(cr);
-
- for (j = 0; j < g->n; ++j) {
- cairo_move_to (cr, x_offset, (1.0f - g->data[0][j]) * g->real_draw_height);
- gdk_cairo_set_source_color (cr, &(g->colors [j]));
-
- for (i = 1; i < LoadGraph::NUM_POINTS; ++i) {
- if (g->data[i][j] == -1.0f)
- continue;
- cairo_curve_to (cr,
- x_offset - ((i - 0.5f) * g->graph_delx),
- (1.0f - g->data[i-1][j]) * g->real_draw_height + 3.5f,
- x_offset - ((i - 0.5f) * g->graph_delx),
- (1.0f - g->data[i][j]) * g->real_draw_height + 3.5f,
- x_offset - (i * g->graph_delx),
- (1.0f - g->data[i][j]) * g->real_draw_height + 3.5f);
- }
- cairo_stroke (cr);
-
- }
-
- cairo_destroy (cr);
-
- return TRUE;
+ }
+
+ /* Number of pixels wide for one graph point */
+ sample_width = (float)(g->draw_width - g->rmargin - g->indent) / (float)LoadGraph::NUM_POINTS;
+ /* General offset */
+ x_offset = g->draw_width - g->rmargin + (sample_width*2);
+
+ /* Subframe offset */
+ x_offset += g->rmargin - ((sample_width / g->frames_per_unit) * g->render_counter);
+
+ /* draw the graph */
+ cairo_t* cr;
+
+ cr = gdk_cairo_create (window);
+
+ cairo_set_line_width (cr, 1);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ cairo_rectangle (cr, g->rmargin + g->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
+ g->draw_width - g->rmargin - g->indent - 1, g->real_draw_height + FRAME_WIDTH - 1);
+ cairo_clip(cr);
+
+ for (j = 0; j < g->n; ++j) {
+ cairo_move_to (cr, x_offset, (1.0f - g->data[0][j]) * g->real_draw_height);
+ gdk_cairo_set_source_color (cr, &(g->colors [j]));
+
+ for (i = 1; i < LoadGraph::NUM_POINTS; ++i) {
+ if (g->data[i][j] == -1.0f)
+ continue;
+ cairo_curve_to (cr,
+ x_offset - ((i - 0.5f) * g->graph_delx),
+ (1.0f - g->data[i-1][j]) * g->real_draw_height + 3.5f,
+ x_offset - ((i - 0.5f) * g->graph_delx),
+ (1.0f - g->data[i][j]) * g->real_draw_height + 3.5f,
+ x_offset - (i * g->graph_delx),
+ (1.0f - g->data[i][j]) * g->real_draw_height + 3.5f);
+ }
+ cairo_stroke (cr);
+
+ }
+
+ cairo_destroy (cr);
+
+ return TRUE;
}
static void
get_load (LoadGraph *g)
{
- guint i;
- glibtop_cpu cpu;
+ guint i;
+ glibtop_cpu cpu;
- glibtop_get_cpu (&cpu);
+ glibtop_get_cpu (&cpu);
#undef NOW
#undef LAST
#define NOW (g->cpu.times[g->cpu.now])
#define LAST (g->cpu.times[g->cpu.now ^ 1])
- if (g->n == 1) {
- NOW[0][CPU_TOTAL] = cpu.total;
- NOW[0][CPU_USED] = cpu.user + cpu.nice + cpu.sys;
- } else {
- for (i = 0; i < g->n; i++) {
- NOW[i][CPU_TOTAL] = cpu.xcpu_total[i];
- NOW[i][CPU_USED] = cpu.xcpu_user[i] + cpu.xcpu_nice[i]
- + cpu.xcpu_sys[i];
- }
- }
-
- // on the first call, LAST is 0
- // which means data is set to the average load since boot
- // that value has no meaning, we just want all the
- // graphs to be aligned, so the CPU graph needs to start
- // immediately
-
- for (i = 0; i < g->n; i++) {
- float load;
- float total, used;
- gchar *text;
-
- total = NOW[i][CPU_TOTAL] - LAST[i][CPU_TOTAL];
- used = NOW[i][CPU_USED] - LAST[i][CPU_USED];
-
- load = used / MAX(total, 1.0f);
- g->data[0][i] = load;
-
- /* Update label */
- text = g_strdup_printf("%.1f%%", load * 100.0f);
- gtk_label_set_text(GTK_LABEL(g->labels.cpu[i]), text);
- g_free(text);
- }
-
- g->cpu.now ^= 1;
+ if (g->n == 1) {
+ NOW[0][CPU_TOTAL] = cpu.total;
+ NOW[0][CPU_USED] = cpu.user + cpu.nice + cpu.sys;
+ } else {
+ for (i = 0; i < g->n; i++) {
+ NOW[i][CPU_TOTAL] = cpu.xcpu_total[i];
+ NOW[i][CPU_USED] = cpu.xcpu_user[i] + cpu.xcpu_nice[i]
+ + cpu.xcpu_sys[i];
+ }
+ }
+
+ // on the first call, LAST is 0
+ // which means data is set to the average load since boot
+ // that value has no meaning, we just want all the
+ // graphs to be aligned, so the CPU graph needs to start
+ // immediately
+
+ for (i = 0; i < g->n; i++) {
+ float load;
+ float total, used;
+ gchar *text;
+
+ total = NOW[i][CPU_TOTAL] - LAST[i][CPU_TOTAL];
+ used = NOW[i][CPU_USED] - LAST[i][CPU_USED];
+
+ load = used / MAX(total, 1.0f);
+ g->data[0][i] = load;
+
+ /* Update label */
+ text = g_strdup_printf("%.1f%%", load * 100.0f);
+ gtk_label_set_text(GTK_LABEL(g->labels.cpu[i]), text);
+ g_free(text);
+ }
+
+ g->cpu.now ^= 1;
#undef NOW
#undef LAST
@@ -330,225 +330,225 @@ get_load (LoadGraph *g)
namespace
{
- void set_memory_label_and_picker(GtkLabel* label, GSMColorButton* picker,
- guint64 used, guint64 total, double percent)
- {
- char* used_text;
- char* total_text;
- char* text;
-
- used_text = procman::format_size(used);
- total_text = procman::format_size(total);
- // xgettext: 540MiB (53 %) of 1.0 GiB
- text = g_strdup_printf(_("%s (%.1f %%) of %s"), used_text, 100.0 * percent, total_text);
- gtk_label_set_text(label, text);
- g_free(used_text);
- g_free(total_text);
- g_free(text);
-
- if (picker)
- gsm_color_button_set_fraction(picker, percent);
- }
+ void set_memory_label_and_picker(GtkLabel* label, GSMColorButton* picker,
+ guint64 used, guint64 total, double percent)
+ {
+ char* used_text;
+ char* total_text;
+ char* text;
+
+ used_text = procman::format_size(used);
+ total_text = procman::format_size(total);
+ // xgettext: 540MiB (53 %) of 1.0 GiB
+ text = g_strdup_printf(_("%s (%.1f %%) of %s"), used_text, 100.0 * percent, total_text);
+ gtk_label_set_text(label, text);
+ g_free(used_text);
+ g_free(total_text);
+ g_free(text);
+
+ if (picker)
+ gsm_color_button_set_fraction(picker, percent);
+ }
}
static void
get_memory (LoadGraph *g)
{
- float mempercent, swappercent;
+ float mempercent, swappercent;
- glibtop_mem mem;
- glibtop_swap swap;
+ glibtop_mem mem;
+ glibtop_swap swap;
- glibtop_get_mem (&mem);
- glibtop_get_swap (&swap);
+ glibtop_get_mem (&mem);
+ glibtop_get_swap (&swap);
- /* There's no swap on LiveCD : 0.0f is better than NaN :) */
- swappercent = (swap.total ? (float)swap.used / (float)swap.total : 0.0f);
- mempercent = (float)mem.user / (float)mem.total;
+ /* There's no swap on LiveCD : 0.0f is better than NaN :) */
+ swappercent = (swap.total ? (float)swap.used / (float)swap.total : 0.0f);
+ mempercent = (float)mem.user / (float)mem.total;
- set_memory_label_and_picker(GTK_LABEL(g->labels.memory),
- GSM_COLOR_BUTTON(g->mem_color_picker),
- mem.user, mem.total, mempercent);
+ set_memory_label_and_picker(GTK_LABEL(g->labels.memory),
+ GSM_COLOR_BUTTON(g->mem_color_picker),
+ mem.user, mem.total, mempercent);
- set_memory_label_and_picker(GTK_LABEL(g->labels.swap),
- GSM_COLOR_BUTTON(g->swap_color_picker),
- swap.used, swap.total, swappercent);
+ set_memory_label_and_picker(GTK_LABEL(g->labels.swap),
+ GSM_COLOR_BUTTON(g->swap_color_picker),
+ swap.used, swap.total, swappercent);
- g->data[0][0] = mempercent;
- g->data[0][1] = swappercent;
+ g->data[0][0] = mempercent;
+ g->data[0][1] = swappercent;
}
static void
net_scale (LoadGraph *g, guint64 din, guint64 dout)
{
- g->data[0][0] = 1.0f * din / g->net.max;
- g->data[0][1] = 1.0f * dout / g->net.max;
-
- guint64 dmax = std::max(din, dout);
- g->net.values[g->net.cur] = dmax;
- g->net.cur = (g->net.cur + 1) % LoadGraph::NUM_POINTS;
-
- guint64 new_max;
- // both way, new_max is the greatest value
- if (dmax >= g->net.max)
- new_max = dmax;
- else
- new_max = *std::max_element(&g->net.values[0],
- &g->net.values[LoadGraph::NUM_POINTS]);
-
- //
- // Round network maximum
- //
-
- const guint64 bak_max(new_max);
-
- if (ProcData::get_instance()->config.network_in_bits) {
- // TODO: fix logic to give a nice scale with bits
-
- // round up to get some extra space
- // yes, it can overflow
- new_max = 1.1 * new_max;
- // make sure max is not 0 to avoid / 0
- // default to 125 bytes == 1kbit
- new_max = std::max(new_max, G_GUINT64_CONSTANT(125));
-
- } else {
- // round up to get some extra space
- // yes, it can overflow
- new_max = 1.1 * new_max;
- // make sure max is not 0 to avoid / 0
- // default to 1 KiB
- new_max = std::max(new_max, G_GUINT64_CONSTANT(1024));
-
- // decompose new_max = coef10 * 2**(base10 * 10)
- // where coef10 and base10 are integers and coef10 < 2**10
- //
- // e.g: ceil(100.5 KiB) = 101 KiB = 101 * 2**(1 * 10)
- // where base10 = 1, coef10 = 101, pow2 = 16
-
- guint64 pow2 = std::floor(log2(new_max));
- guint64 base10 = pow2 / 10.0;
- guint64 coef10 = std::ceil(new_max / double(G_GUINT64_CONSTANT(1) << (base10 * 10)));
- g_assert(new_max <= (coef10 * (G_GUINT64_CONSTANT(1) << (base10 * 10))));
-
- // then decompose coef10 = x * 10**factor10
- // where factor10 is integer and x < 10
- // so we new_max has only 1 significant digit
-
- guint64 factor10 = std::pow(10.0, std::floor(std::log10(coef10)));
- coef10 = std::ceil(coef10 / double(factor10)) * factor10;
-
- // then make coef10 divisible by num_bars
- if (coef10 % g->num_bars() != 0)
- coef10 = coef10 + (g->num_bars() - coef10 % g->num_bars());
- g_assert(coef10 % g->num_bars() == 0);
- new_max = coef10 * (G_GUINT64_CONSTANT(1) << guint64(base10 * 10));
- procman_debug("bak %" G_GUINT64_FORMAT " new_max %" G_GUINT64_FORMAT
- "pow2 %" G_GUINT64_FORMAT " coef10 %" G_GUINT64_FORMAT,
- bak_max, new_max, pow2, coef10);
- }
-
- if (bak_max > new_max) {
- procman_debug("overflow detected: bak=%" G_GUINT64_FORMAT
- " new=%" G_GUINT64_FORMAT,
- bak_max, new_max);
- new_max = bak_max;
- }
-
- // if max is the same or has decreased but not so much, don't
- // do anything to avoid rescaling
- if ((0.8 * g->net.max) < new_max && new_max <= g->net.max)
- return;
-
- const double scale = 1.0f * g->net.max / new_max;
-
- for (size_t i = 0; i < LoadGraph::NUM_POINTS; i++) {
- if (g->data[i][0] >= 0.0f) {
- g->data[i][0] *= scale;
- g->data[i][1] *= scale;
- }
- }
-
- procman_debug("rescale dmax = %" G_GUINT64_FORMAT
- " max = %" G_GUINT64_FORMAT
- " new_max = %" G_GUINT64_FORMAT,
- dmax, g->net.max, new_max);
-
- g->net.max = new_max;
-
- // force the graph background to be redrawn now that scale has changed
- g->clear_background();
+ g->data[0][0] = 1.0f * din / g->net.max;
+ g->data[0][1] = 1.0f * dout / g->net.max;
+
+ guint64 dmax = std::max(din, dout);
+ g->net.values[g->net.cur] = dmax;
+ g->net.cur = (g->net.cur + 1) % LoadGraph::NUM_POINTS;
+
+ guint64 new_max;
+ // both way, new_max is the greatest value
+ if (dmax >= g->net.max)
+ new_max = dmax;
+ else
+ new_max = *std::max_element(&g->net.values[0],
+ &g->net.values[LoadGraph::NUM_POINTS]);
+
+ //
+ // Round network maximum
+ //
+
+ const guint64 bak_max(new_max);
+
+ if (ProcData::get_instance()->config.network_in_bits) {
+ // TODO: fix logic to give a nice scale with bits
+
+ // round up to get some extra space
+ // yes, it can overflow
+ new_max = 1.1 * new_max;
+ // make sure max is not 0 to avoid / 0
+ // default to 125 bytes == 1kbit
+ new_max = std::max(new_max, G_GUINT64_CONSTANT(125));
+
+ } else {
+ // round up to get some extra space
+ // yes, it can overflow
+ new_max = 1.1 * new_max;
+ // make sure max is not 0 to avoid / 0
+ // default to 1 KiB
+ new_max = std::max(new_max, G_GUINT64_CONSTANT(1024));
+
+ // decompose new_max = coef10 * 2**(base10 * 10)
+ // where coef10 and base10 are integers and coef10 < 2**10
+ //
+ // e.g: ceil(100.5 KiB) = 101 KiB = 101 * 2**(1 * 10)
+ // where base10 = 1, coef10 = 101, pow2 = 16
+
+ guint64 pow2 = std::floor(log2(new_max));
+ guint64 base10 = pow2 / 10.0;
+ guint64 coef10 = std::ceil(new_max / double(G_GUINT64_CONSTANT(1) << (base10 * 10)));
+ g_assert(new_max <= (coef10 * (G_GUINT64_CONSTANT(1) << (base10 * 10))));
+
+ // then decompose coef10 = x * 10**factor10
+ // where factor10 is integer and x < 10
+ // so we new_max has only 1 significant digit
+
+ guint64 factor10 = std::pow(10.0, std::floor(std::log10(coef10)));
+ coef10 = std::ceil(coef10 / double(factor10)) * factor10;
+
+ // then make coef10 divisible by num_bars
+ if (coef10 % g->num_bars() != 0)
+ coef10 = coef10 + (g->num_bars() - coef10 % g->num_bars());
+ g_assert(coef10 % g->num_bars() == 0);
+ new_max = coef10 * (G_GUINT64_CONSTANT(1) << guint64(base10 * 10));
+ procman_debug("bak %" G_GUINT64_FORMAT " new_max %" G_GUINT64_FORMAT
+ "pow2 %" G_GUINT64_FORMAT " coef10 %" G_GUINT64_FORMAT,
+ bak_max, new_max, pow2, coef10);
+ }
+
+ if (bak_max > new_max) {
+ procman_debug("overflow detected: bak=%" G_GUINT64_FORMAT
+ " new=%" G_GUINT64_FORMAT,
+ bak_max, new_max);
+ new_max = bak_max;
+ }
+
+ // if max is the same or has decreased but not so much, don't
+ // do anything to avoid rescaling
+ if ((0.8 * g->net.max) < new_max && new_max <= g->net.max)
+ return;
+
+ const double scale = 1.0f * g->net.max / new_max;
+
+ for (size_t i = 0; i < LoadGraph::NUM_POINTS; i++) {
+ if (g->data[i][0] >= 0.0f) {
+ g->data[i][0] *= scale;
+ g->data[i][1] *= scale;
+ }
+ }
+
+ procman_debug("rescale dmax = %" G_GUINT64_FORMAT
+ " max = %" G_GUINT64_FORMAT
+ " new_max = %" G_GUINT64_FORMAT,
+ dmax, g->net.max, new_max);
+
+ g->net.max = new_max;
+
+ // force the graph background to be redrawn now that scale has changed
+ g->clear_background();
}
static void
get_net (LoadGraph *g)
{
- glibtop_netlist netlist;
- char **ifnames;
- guint32 i;
- guint64 in = 0, out = 0;
- GTimeVal time;
- guint64 din, dout;
-
- ifnames = glibtop_get_netlist(&netlist);
-
- for (i = 0; i < netlist.number; ++i)
- {
- glibtop_netload netload;
- glibtop_get_netload (&netload, ifnames[i]);
-
- if (netload.if_flags & (1 << GLIBTOP_IF_FLAGS_LOOPBACK))
- continue;
-
- /* Skip interfaces without any IPv4/IPv6 address (or
- those with only a LINK ipv6 addr) However we need to
- be able to exclude these while still keeping the
- value so when they get online (with NetworkManager
- for example) we don't get a suddent peak. Once we're
- able to get this, ignoring down interfaces will be
- possible too. */
- if (not (netload.flags & (1 << GLIBTOP_NETLOAD_ADDRESS6)
- and netload.scope6 != GLIBTOP_IF_IN6_SCOPE_LINK)
- and not (netload.flags & (1 << GLIBTOP_NETLOAD_ADDRESS)))
- continue;
-
- /* Don't skip interfaces that are down (GLIBTOP_IF_FLAGS_UP)
- to avoid spikes when they are brought up */
-
- in += netload.bytes_in;
- out += netload.bytes_out;
- }
-
- g_strfreev(ifnames);
-
- g_get_current_time (&time);
-
- if (in >= g->net.last_in && out >= g->net.last_out &&
- g->net.time.tv_sec != 0) {
- float dtime;
- dtime = time.tv_sec - g->net.time.tv_sec +
- (double) (time.tv_usec - g->net.time.tv_usec) / G_USEC_PER_SEC;
- din = static_cast<guint64>((in - g->net.last_in) / dtime);
- dout = static_cast<guint64>((out - g->net.last_out) / dtime);
- } else {
- /* Don't calc anything if new data is less than old (interface
- removed, counters reset, ...) or if it is the first time */
- din = 0;
- dout = 0;
- }
-
- g->net.last_in = in;
- g->net.last_out = out;
- g->net.time = time;
-
- net_scale(g, din, dout);
-
-
- gtk_label_set_text (GTK_LABEL (g->labels.net_in), procman::format_network_rate(din).c_str());
- gtk_label_set_text (GTK_LABEL (g->labels.net_in_total), procman::format_network(in).c_str());
-
- gtk_label_set_text (GTK_LABEL (g->labels.net_out), procman::format_network_rate(dout).c_str());
- gtk_label_set_text (GTK_LABEL (g->labels.net_out_total), procman::format_network(out).c_str());
+ glibtop_netlist netlist;
+ char **ifnames;
+ guint32 i;
+ guint64 in = 0, out = 0;
+ GTimeVal time;
+ guint64 din, dout;
+
+ ifnames = glibtop_get_netlist(&netlist);
+
+ for (i = 0; i < netlist.number; ++i)
+ {
+ glibtop_netload netload;
+ glibtop_get_netload (&netload, ifnames[i]);
+
+ if (netload.if_flags & (1 << GLIBTOP_IF_FLAGS_LOOPBACK))
+ continue;
+
+ /* Skip interfaces without any IPv4/IPv6 address (or
+ those with only a LINK ipv6 addr) However we need to
+ be able to exclude these while still keeping the
+ value so when they get online (with NetworkManager
+ for example) we don't get a suddent peak. Once we're
+ able to get this, ignoring down interfaces will be
+ possible too. */
+ if (not (netload.flags & (1 << GLIBTOP_NETLOAD_ADDRESS6)
+ and netload.scope6 != GLIBTOP_IF_IN6_SCOPE_LINK)
+ and not (netload.flags & (1 << GLIBTOP_NETLOAD_ADDRESS)))
+ continue;
+
+ /* Don't skip interfaces that are down (GLIBTOP_IF_FLAGS_UP)
+ to avoid spikes when they are brought up */
+
+ in += netload.bytes_in;
+ out += netload.bytes_out;
+ }
+
+ g_strfreev(ifnames);
+
+ g_get_current_time (&time);
+
+ if (in >= g->net.last_in && out >= g->net.last_out &&
+ g->net.time.tv_sec != 0) {
+ float dtime;
+ dtime = time.tv_sec - g->net.time.tv_sec +
+ (double) (time.tv_usec - g->net.time.tv_usec) / G_USEC_PER_SEC;
+ din = static_cast<guint64>((in - g->net.last_in) / dtime);
+ dout = static_cast<guint64>((out - g->net.last_out) / dtime);
+ } else {
+ /* Don't calc anything if new data is less than old (interface
+ removed, counters reset, ...) or if it is the first time */
+ din = 0;
+ dout = 0;
+ }
+
+ g->net.last_in = in;
+ g->net.last_out = out;
+ g->net.time = time;
+
+ net_scale(g, din, dout);
+
+
+ gtk_label_set_text (GTK_LABEL (g->labels.net_in), procman::format_network_rate(din).c_str());
+ gtk_label_set_text (GTK_LABEL (g->labels.net_in_total), procman::format_network(in).c_str());
+
+ gtk_label_set_text (GTK_LABEL (g->labels.net_out), procman::format_network_rate(dout).c_str());
+ gtk_label_set_text (GTK_LABEL (g->labels.net_out_total), procman::format_network(out).c_str());
}
@@ -556,35 +556,35 @@ get_net (LoadGraph *g)
static gboolean
load_graph_update (gpointer user_data)
{
- LoadGraph * const g = static_cast<LoadGraph*>(user_data);
-
- if (g->render_counter == g->frames_per_unit - 1) {
- std::rotate(&g->data[0], &g->data[LoadGraph::NUM_POINTS - 1], &g->data[LoadGraph::NUM_POINTS]);
-
- switch (g->type) {
- case LOAD_GRAPH_CPU:
- get_load(g);
- break;
- case LOAD_GRAPH_MEM:
- get_memory(g);
- break;
- case LOAD_GRAPH_NET:
- get_net(g);
- break;
- default:
- g_assert_not_reached();
- }
- }
-
- if (g->draw)
- load_graph_queue_draw (g);
-
- g->render_counter++;
-
- if (g->render_counter >= g->frames_per_unit)
- g->render_counter = 0;
-
- return TRUE;
+ LoadGraph * const g = static_cast<LoadGraph*>(user_data);
+
+ if (g->render_counter == g->frames_per_unit - 1) {
+ std::rotate(&g->data[0], &g->data[LoadGraph::NUM_POINTS - 1], &g->data[LoadGraph::NUM_POINTS]);
+
+ switch (g->type) {
+ case LOAD_GRAPH_CPU:
+ get_load(g);
+ break;
+ case LOAD_GRAPH_MEM:
+ get_memory(g);
+ break;
+ case LOAD_GRAPH_NET:
+ get_net(g);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ }
+
+ if (g->draw)
+ load_graph_queue_draw (g);
+
+ g->render_counter++;
+
+ if (g->render_counter >= g->frames_per_unit)
+ g->render_counter = 0;
+
+ return TRUE;
}
@@ -604,11 +604,11 @@ LoadGraph::~LoadGraph()
static gboolean
load_graph_destroy (GtkWidget *widget, gpointer data_ptr)
{
- LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
+ LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
- delete g;
+ delete g;
- return FALSE;
+ return FALSE;
}
@@ -635,165 +635,165 @@ LoadGraph::LoadGraph(guint type)
mem_color_picker(NULL),
swap_color_picker(NULL)
{
- LoadGraph * const g = this;
-
- // FIXME:
- // on configure, g->frames_per_unit = g->draw_width/(LoadGraph::NUM_POINTS);
- // knock FRAMES down to 5 until cairo gets faster
- g->frames_per_unit = 10; // this will be changed but needs initialising
- g->fontsize = 8.0;
- g->rmargin = 3.5 * g->fontsize;
- g->indent = 24.0;
-
- g->type = type;
- switch (type) {
- case LOAD_GRAPH_CPU:
- memset(&this->cpu, 0, sizeof g->cpu);
- g->n = ProcData::get_instance()->config.num_cpus;
-
- for(guint i = 0; i < G_N_ELEMENTS(g->labels.cpu); ++i)
- g->labels.cpu[i] = gtk_label_new(NULL);
-
- break;
-
- case LOAD_GRAPH_MEM:
- g->n = 2;
- g->labels.memory = gtk_label_new(NULL);
- g->labels.swap = gtk_label_new(NULL);
- break;
-
- case LOAD_GRAPH_NET:
- memset(&this->net, 0, sizeof g->net);
- g->n = 2;
- g->net.max = 1;
- g->labels.net_in = gtk_label_new(NULL);
- g->labels.net_in_total = gtk_label_new(NULL);
- g->labels.net_out = gtk_label_new(NULL);
- g->labels.net_out_total = gtk_label_new(NULL);
- break;
- }
-
- g->speed = ProcData::get_instance()->config.graph_update_interval;
-
- g->colors.resize(g->n);
-
- switch (type) {
- case LOAD_GRAPH_CPU:
- memcpy(&g->colors[0], ProcData::get_instance()->config.cpu_color,
- g->n * sizeof g->colors[0]);
- break;
- case LOAD_GRAPH_MEM:
- g->colors[0] = ProcData::get_instance()->config.mem_color;
- g->colors[1] = ProcData::get_instance()->config.swap_color;
- g->mem_color_picker = gsm_color_button_new (&g->colors[0],
- GSMCP_TYPE_PIE);
- g->swap_color_picker = gsm_color_button_new (&g->colors[1],
- GSMCP_TYPE_PIE);
- break;
- case LOAD_GRAPH_NET:
- g->colors[0] = ProcData::get_instance()->config.net_in_color;
- g->colors[1] = ProcData::get_instance()->config.net_out_color;
- break;
- }
-
- g->timer_index = 0;
- g->render_counter = (g->frames_per_unit - 1);
- g->draw = FALSE;
-
- g->main_widget = gtk_vbox_new (FALSE, FALSE);
- gtk_widget_set_size_request(g->main_widget, -1, LoadGraph::GRAPH_MIN_HEIGHT);
- gtk_widget_show (g->main_widget);
-
- g->disp = gtk_drawing_area_new ();
- gtk_widget_show (g->disp);
+ LoadGraph * const g = this;
+
+ // FIXME:
+ // on configure, g->frames_per_unit = g->draw_width/(LoadGraph::NUM_POINTS);
+ // knock FRAMES down to 5 until cairo gets faster
+ g->frames_per_unit = 10; // this will be changed but needs initialising
+ g->fontsize = 8.0;
+ g->rmargin = 3.5 * g->fontsize;
+ g->indent = 24.0;
+
+ g->type = type;
+ switch (type) {
+ case LOAD_GRAPH_CPU:
+ memset(&this->cpu, 0, sizeof g->cpu);
+ g->n = ProcData::get_instance()->config.num_cpus;
+
+ for(guint i = 0; i < G_N_ELEMENTS(g->labels.cpu); ++i)
+ g->labels.cpu[i] = gtk_label_new(NULL);
+
+ break;
+
+ case LOAD_GRAPH_MEM:
+ g->n = 2;
+ g->labels.memory = gtk_label_new(NULL);
+ g->labels.swap = gtk_label_new(NULL);
+ break;
+
+ case LOAD_GRAPH_NET:
+ memset(&this->net, 0, sizeof g->net);
+ g->n = 2;
+ g->net.max = 1;
+ g->labels.net_in = gtk_label_new(NULL);
+ g->labels.net_in_total = gtk_label_new(NULL);
+ g->labels.net_out = gtk_label_new(NULL);
+ g->labels.net_out_total = gtk_label_new(NULL);
+ break;
+ }
+
+ g->speed = ProcData::get_instance()->config.graph_update_interval;
+
+ g->colors.resize(g->n);
+
+ switch (type) {
+ case LOAD_GRAPH_CPU:
+ memcpy(&g->colors[0], ProcData::get_instance()->config.cpu_color,
+ g->n * sizeof g->colors[0]);
+ break;
+ case LOAD_GRAPH_MEM:
+ g->colors[0] = ProcData::get_instance()->config.mem_color;
+ g->colors[1] = ProcData::get_instance()->config.swap_color;
+ g->mem_color_picker = gsm_color_button_new (&g->colors[0],
+ GSMCP_TYPE_PIE);
+ g->swap_color_picker = gsm_color_button_new (&g->colors[1],
+ GSMCP_TYPE_PIE);
+ break;
+ case LOAD_GRAPH_NET:
+ g->colors[0] = ProcData::get_instance()->config.net_in_color;
+ g->colors[1] = ProcData::get_instance()->config.net_out_color;
+ break;
+ }
+
+ g->timer_index = 0;
+ g->render_counter = (g->frames_per_unit - 1);
+ g->draw = FALSE;
+
+ g->main_widget = gtk_vbox_new (FALSE, FALSE);
+ gtk_widget_set_size_request(g->main_widget, -1, LoadGraph::GRAPH_MIN_HEIGHT);
+ gtk_widget_show (g->main_widget);
+
+ g->disp = gtk_drawing_area_new ();
+ gtk_widget_show (g->disp);
#if GTK_CHECK_VERSION(3,0,0)
- g_signal_connect (G_OBJECT (g->disp), "draw", G_CALLBACK (load_graph_draw), g);
+ g_signal_connect (G_OBJECT (g->disp), "draw", G_CALLBACK (load_graph_draw), g);
#else
- g_signal_connect (G_OBJECT (g->disp), "expose_event", G_CALLBACK (load_graph_expose), g);
+ g_signal_connect (G_OBJECT (g->disp), "expose_event", G_CALLBACK (load_graph_expose), g);
#endif
- g_signal_connect (G_OBJECT(g->disp), "configure_event",
- G_CALLBACK (load_graph_configure), g);
- g_signal_connect (G_OBJECT(g->disp), "destroy",
- G_CALLBACK (load_graph_destroy), g);
+ g_signal_connect (G_OBJECT(g->disp), "configure_event",
+ G_CALLBACK (load_graph_configure), g);
+ g_signal_connect (G_OBJECT(g->disp), "destroy",
+ G_CALLBACK (load_graph_destroy), g);
- gtk_widget_set_events (g->disp, GDK_EXPOSURE_MASK);
+ gtk_widget_set_events (g->disp, GDK_EXPOSURE_MASK);
- gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0);
- /* Allocate data in a contiguous block */
- g->data_block = std::vector<float>(g->n * LoadGraph::NUM_POINTS, -1.0f);
+ /* Allocate data in a contiguous block */
+ g->data_block = std::vector<float>(g->n * LoadGraph::NUM_POINTS, -1.0f);
- for (guint i = 0; i < LoadGraph::NUM_POINTS; ++i)
- g->data[i] = &g->data_block[0] + i * g->n;
+ for (guint i = 0; i < LoadGraph::NUM_POINTS; ++i)
+ g->data[i] = &g->data_block[0] + i * g->n;
- gtk_widget_show_all (g->main_widget);
+ gtk_widget_show_all (g->main_widget);
}
void
load_graph_start (LoadGraph *g)
{
- if(!g->timer_index) {
+ if(!g->timer_index) {
- load_graph_update(g);
+ load_graph_update(g);
- g->timer_index = g_timeout_add (g->speed / g->frames_per_unit,
- load_graph_update,
- g);
- }
+ g->timer_index = g_timeout_add (g->speed / g->frames_per_unit,
+ load_graph_update,
+ g);
+ }
- g->draw = TRUE;
+ g->draw = TRUE;
}
void
load_graph_stop (LoadGraph *g)
{
- /* don't draw anymore, but continue to poll */
- g->draw = FALSE;
+ /* don't draw anymore, but continue to poll */
+ g->draw = FALSE;
}
void
load_graph_change_speed (LoadGraph *g,
- guint new_speed)
+ guint new_speed)
{
- if (g->speed == new_speed)
- return;
+ if (g->speed == new_speed)
+ return;
- g->speed = new_speed;
+ g->speed = new_speed;
- g_assert(g->timer_index);
+ g_assert(g->timer_index);
- if(g->timer_index) {
- g_source_remove (g->timer_index);
- g->timer_index = g_timeout_add (g->speed / g->frames_per_unit,
- load_graph_update,
- g);
- }
+ if(g->timer_index) {
+ g_source_remove (g->timer_index);
+ g->timer_index = g_timeout_add (g->speed / g->frames_per_unit,
+ load_graph_update,
+ g);
+ }
- g->clear_background();
+ g->clear_background();
}
LoadGraphLabels*
load_graph_get_labels (LoadGraph *g)
{
- return &g->labels;
+ return &g->labels;
}
GtkWidget*
load_graph_get_widget (LoadGraph *g)
{
- return g->main_widget;
+ return g->main_widget;
}
GtkWidget*
load_graph_get_mem_color_picker(LoadGraph *g)
{
- return g->mem_color_picker;
+ return g->mem_color_picker;
}
GtkWidget*
load_graph_get_swap_color_picker(LoadGraph *g)
{
- return g->swap_color_picker;
+ return g->swap_color_picker;
}
diff --git a/src/load-graph.h b/src/load-graph.h
index 5164a4c..2a212fb 100644
--- a/src/load-graph.h
+++ b/src/load-graph.h
@@ -6,96 +6,96 @@
enum
{
- LOAD_GRAPH_CPU,
- LOAD_GRAPH_MEM,
- LOAD_GRAPH_NET
+ LOAD_GRAPH_CPU,
+ LOAD_GRAPH_MEM,
+ LOAD_GRAPH_NET
};
enum {
- CPU_TOTAL,
- CPU_USED,
- N_CPU_STATES
+ CPU_TOTAL,
+ CPU_USED,
+ N_CPU_STATES
};
struct LoadGraphLabels
{
- GtkWidget *cpu[GLIBTOP_NCPU];
- GtkWidget *memory;
- GtkWidget *swap;
- GtkWidget *net_in;
- GtkWidget *net_in_total;
- GtkWidget *net_out;
- GtkWidget *net_out_total;
+ GtkWidget *cpu[GLIBTOP_NCPU];
+ GtkWidget *memory;
+ GtkWidget *swap;
+ GtkWidget *net_in;
+ GtkWidget *net_in_total;
+ GtkWidget *net_out;
+ GtkWidget *net_out_total;
};
struct LoadGraph {
- static const unsigned NUM_POINTS = 60 + 2;
- static const unsigned GRAPH_MIN_HEIGHT = 40;
+ static const unsigned NUM_POINTS = 60 + 2;
+ static const unsigned GRAPH_MIN_HEIGHT = 40;
- LoadGraph(guint type);
- ~LoadGraph();
+ LoadGraph(guint type);
+ ~LoadGraph();
- unsigned num_bars() const;
- void clear_background();
+ unsigned num_bars() const;
+ void clear_background();
- double fontsize;
- double rmargin;
- double indent;
+ double fontsize;
+ double rmargin;
+ double indent;
- guint n;
- gint type;
- guint speed;
- guint draw_width, draw_height;
- guint render_counter;
- guint frames_per_unit;
- guint graph_dely;
- guint real_draw_height;
- double graph_delx;
- guint graph_buffer_offset;
+ guint n;
+ gint type;
+ guint speed;
+ guint draw_width, draw_height;
+ guint render_counter;
+ guint frames_per_unit;
+ guint graph_dely;
+ guint real_draw_height;
+ double graph_delx;
+ guint graph_buffer_offset;
- std::vector<GdkColor> colors;
+ std::vector<GdkColor> colors;
- std::vector<float> data_block;
- gfloat* data[NUM_POINTS];
+ std::vector<float> data_block;
+ gfloat* data[NUM_POINTS];
- GtkWidget *main_widget;
- GtkWidget *disp;
+ GtkWidget *main_widget;
+ GtkWidget *disp;
#if GTK_CHECK_VERSION(3,0,0)
- cairo_surface_t *background;
+ cairo_surface_t *background;
#else
- GdkDrawable *background;
+ GdkDrawable *background;
#endif
- guint timer_index;
-
- gboolean draw;
-
- LoadGraphLabels labels;
- GtkWidget *mem_color_picker;
- GtkWidget *swap_color_picker;
-
- /* union { */
- struct {
- guint now; /* 0 -> current, 1 -> last
- now ^ 1 each time */
- /* times[now], times[now ^ 1] is last */
- guint64 times[2][GLIBTOP_NCPU][N_CPU_STATES];
- } cpu;
-
- struct {
- guint64 last_in, last_out;
- GTimeVal time;
- guint64 max;
- unsigned values[NUM_POINTS];
- size_t cur;
- } net;
- /* }; */
+ guint timer_index;
+
+ gboolean draw;
+
+ LoadGraphLabels labels;
+ GtkWidget *mem_color_picker;
+ GtkWidget *swap_color_picker;
+
+ /* union { */
+ struct {
+ guint now; /* 0 -> current, 1 -> last
+ now ^ 1 each time */
+ /* times[now], times[now ^ 1] is last */
+ guint64 times[2][GLIBTOP_NCPU][N_CPU_STATES];
+ } cpu;
+
+ struct {
+ guint64 last_in, last_out;
+ GTimeVal time;
+ guint64 max;
+ unsigned values[NUM_POINTS];
+ size_t cur;
+ } net;
+ /* }; */
};
@@ -115,7 +115,7 @@ load_graph_stop (LoadGraph *g);
/* Change load graph speed and restart it if it has been previously started */
void
load_graph_change_speed (LoadGraph *g,
- guint new_speed);
+ guint new_speed);
LoadGraphLabels*
load_graph_get_labels (LoadGraph *g) G_GNUC_CONST;
diff --git a/src/lsof.cpp b/src/lsof.cpp
index 4be9405..e3305dd 100644
--- a/src/lsof.cpp
+++ b/src/lsof.cpp
@@ -28,207 +28,207 @@ using std::string;
namespace
{
- class Lsof
- {
- Glib::RefPtr<Glib::Regex> re;
-
- bool matches(const string &filename) const
+ class Lsof
{
- return this->re->match(filename);
- }
+ Glib::RefPtr<Glib::Regex> re;
- public:
+ bool matches(const string &filename) const
+ {
+ return this->re->match(filename);
+ }
- Lsof(const string &pattern, bool caseless)
- {
- Glib::RegexCompileFlags flags = static_cast<Glib::RegexCompileFlags>(0);
+ public:
- if (caseless)
- flags |= Glib::REGEX_CASELESS;
+ Lsof(const string &pattern, bool caseless)
+ {
+ Glib::RegexCompileFlags flags = static_cast<Glib::RegexCompileFlags>(0);
- this->re = Glib::Regex::create(pattern, flags);
- }
+ if (caseless)
+ flags |= Glib::REGEX_CASELESS;
+ this->re = Glib::Regex::create(pattern, flags);
+ }
- template<typename OutputIterator>
- void search(const ProcInfo &info, OutputIterator out) const
- {
- glibtop_open_files_entry *entries;
- glibtop_proc_open_files buf;
- entries = glibtop_get_proc_open_files(&buf, info.pid);
+ template<typename OutputIterator>
+ void search(const ProcInfo &info, OutputIterator out) const
+ {
+ glibtop_open_files_entry *entries;
+ glibtop_proc_open_files buf;
- for (unsigned i = 0; i != buf.number; ++i) {
- if (entries[i].type & GLIBTOP_FILE_TYPE_FILE) {
- const string filename(entries[i].info.file.name);
- if (this->matches(filename))
- *out++ = filename;
- }
- }
+ entries = glibtop_get_proc_open_files(&buf, info.pid);
- g_free(entries);
- }
- };
+ for (unsigned i = 0; i != buf.number; ++i) {
+ if (entries[i].type & GLIBTOP_FILE_TYPE_FILE) {
+ const string filename(entries[i].info.file.name);
+ if (this->matches(filename))
+ *out++ = filename;
+ }
+ }
+ g_free(entries);
+ }
+ };
- // GUI Stuff
+ // GUI Stuff
- enum ProcmanLsof {
- PROCMAN_LSOF_COL_PIXBUF,
- PROCMAN_LSOF_COL_PROCESS,
- PROCMAN_LSOF_COL_PID,
- PROCMAN_LSOF_COL_FILENAME,
- PROCMAN_LSOF_NCOLS
- };
+ enum ProcmanLsof {
+ PROCMAN_LSOF_COL_PIXBUF,
+ PROCMAN_LSOF_COL_PROCESS,
+ PROCMAN_LSOF_COL_PID,
+ PROCMAN_LSOF_COL_FILENAME,
+ PROCMAN_LSOF_NCOLS
+ };
- struct GUI {
- GtkListStore *model;
- GtkEntry *entry;
- GtkWindow *window;
- GtkLabel *count;
- ProcData *procdata;
- bool case_insensitive;
+ struct GUI {
+ GtkListStore *model;
+ GtkEntry *entry;
+ GtkWindow *window;
+ GtkLabel *count;
+ ProcData *procdata;
+ bool case_insensitive;
- GUI()
- {
- procman_debug("New Lsof GUI %p", this);
- }
+ GUI()
+ {
+ procman_debug("New Lsof GUI %p", this);
+ }
- ~GUI()
- {
- procman_debug("Destroying Lsof GUI %p", this);
- }
+ ~GUI()
+ {
+ procman_debug("Destroying Lsof GUI %p", this);
+ }
- void clear_results()
- {
- gtk_list_store_clear(this->model);
- gtk_label_set_text(this->count, "");
- }
+ void clear_results()
+ {
+ gtk_list_store_clear(this->model);
+ gtk_label_set_text(this->count, "");
+ }
- void clear()
- {
- this->clear_results();
- gtk_entry_set_text(this->entry, "");
- }
+ void clear()
+ {
+ this->clear_results();
+ gtk_entry_set_text(this->entry, "");
+ }
- void display_regex_error(const Glib::RegexError& error)
- {
- const char * msg = _("<b>Error</b>\n"
- "'%s' is not a valid Perl regular expression.\n"
- "%s");
- std::string message = make_string(g_strdup_printf(msg, this->pattern().c_str(), error.what().c_str()));
- Gtk::MessageDialog dialog(message,
- true, // use markup
- Gtk::MESSAGE_ERROR,
- Gtk::BUTTONS_OK,
- true); // modal
- dialog.run();
- }
+ void display_regex_error(const Glib::RegexError& error)
+ {
+ const char * msg = _("<b>Error</b>\n"
+ "'%s' is not a valid Perl regular expression.\n"
+ "%s");
+ std::string message = make_string(g_strdup_printf(msg, this->pattern().c_str(), error.what().c_str()));
+ Gtk::MessageDialog dialog(message,
+ true, // use markup
+ Gtk::MESSAGE_ERROR,
+ Gtk::BUTTONS_OK,
+ true); // modal
+ dialog.run();
+ }
- void update_count(unsigned count)
- {
- string s = static_cast<std::ostringstream&>(std::ostringstream() << count).str();
- gtk_label_set_text(this->count, s.c_str());
- }
+ void update_count(unsigned count)
+ {
+ string s = static_cast<std::ostringstream&>(std::ostringstream() << count).str();
+ gtk_label_set_text(this->count, s.c_str());
+ }
- string pattern() const
- {
- return gtk_entry_get_text(this->entry);
- }
+ string pattern() const
+ {
+ return gtk_entry_get_text(this->entry);
+ }
- void search()
- {
- typedef std::set<string> MatchSet;
- typedef MatchSet::const_iterator iterator;
- this->clear_results();
+ void search()
+ {
+ typedef std::set<string> MatchSet;
+ typedef MatchSet::const_iterator iterator;
+ this->clear_results();
- try {
- Lsof lsof(this->pattern(), this->case_insensitive);
- unsigned count = 0;
+ try {
+ Lsof lsof(this->pattern(), this->case_insensitive);
- for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it) {
- const ProcInfo &info(*it->second);
+ unsigned count = 0;
- MatchSet matches;
- lsof.search(info, std::inserter(matches, matches.begin()));
- count += matches.size();
+ for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it) {
+ const ProcInfo &info(*it->second);
- for (iterator it(matches.begin()), end(matches.end()); it != end; ++it) {
- GtkTreeIter file;
- gtk_list_store_append(this->model, &file);
- gtk_list_store_set(this->model, &file,
- PROCMAN_LSOF_COL_PIXBUF, info.pixbuf->gobj(),
- PROCMAN_LSOF_COL_PROCESS, info.name,
- PROCMAN_LSOF_COL_PID, info.pid,
- PROCMAN_LSOF_COL_FILENAME, it->c_str(),
- -1);
- }
- }
+ MatchSet matches;
+ lsof.search(info, std::inserter(matches, matches.begin()));
+ count += matches.size();
- this->update_count(count);
- }
- catch (Glib::RegexError& error) {
- this->display_regex_error(error);
- }
- }
+ for (iterator it(matches.begin()), end(matches.end()); it != end; ++it) {
+ GtkTreeIter file;
+ gtk_list_store_append(this->model, &file);
+ gtk_list_store_set(this->model, &file,
+ PROCMAN_LSOF_COL_PIXBUF, info.pixbuf->gobj(),
+ PROCMAN_LSOF_COL_PROCESS, info.name,
+ PROCMAN_LSOF_COL_PID, info.pid,
+ PROCMAN_LSOF_COL_FILENAME, it->c_str(),
+ -1);
+ }
+ }
+ this->update_count(count);
+ }
+ catch (Glib::RegexError& error) {
+ this->display_regex_error(error);
+ }
+ }
- static void search_button_clicked(GtkButton *, gpointer data)
- {
- static_cast<GUI*>(data)->search();
- }
+ static void search_button_clicked(GtkButton *, gpointer data)
+ {
+ static_cast<GUI*>(data)->search();
+ }
- static void search_entry_activate(GtkEntry *, gpointer data)
- {
- static_cast<GUI*>(data)->search();
- }
+ static void search_entry_activate(GtkEntry *, gpointer data)
+ {
+ static_cast<GUI*>(data)->search();
+ }
- static void clear_button_clicked(GtkButton *, gpointer data)
- {
- static_cast<GUI*>(data)->clear();
- }
+ static void clear_button_clicked(GtkButton *, gpointer data)
+ {
+ static_cast<GUI*>(data)->clear();
+ }
- static void close_button_clicked(GtkButton *, gpointer data)
- {
- GUI *gui = static_cast<GUI*>(data);
- gtk_widget_destroy(GTK_WIDGET(gui->window));
- delete gui;
- }
+ static void close_button_clicked(GtkButton *, gpointer data)
+ {
+ GUI *gui = static_cast<GUI*>(data);
+ gtk_widget_destroy(GTK_WIDGET(gui->window));
+ delete gui;
+ }
- static void case_button_toggled(GtkToggleButton *button, gpointer data)
- {
- bool state = gtk_toggle_button_get_active(button);
- static_cast<GUI*>(data)->case_insensitive = state;
- }
+ static void case_button_toggled(GtkToggleButton *button, gpointer data)
+ {
+ bool state = gtk_toggle_button_get_active(button);
+ static_cast<GUI*>(data)->case_insensitive = state;
+ }
- static gboolean window_delete_event(GtkWidget *, GdkEvent *, gpointer data)
- {
- delete static_cast<GUI*>(data);
- return FALSE;
- }
- };
+ static gboolean window_delete_event(GtkWidget *, GdkEvent *, gpointer data)
+ {
+ delete static_cast<GUI*>(data);
+ return FALSE;
+ }
+
+ };
}
@@ -236,173 +236,173 @@ namespace
void procman_lsof(ProcData *procdata)
{
- GtkListStore *model = \
- gtk_list_store_new(PROCMAN_LSOF_NCOLS,
- GDK_TYPE_PIXBUF, // PROCMAN_LSOF_COL_PIXBUF
- G_TYPE_STRING, // PROCMAN_LSOF_COL_PROCESS
- G_TYPE_UINT, // PROCMAN_LSOF_COL_PID
- G_TYPE_STRING // PROCMAN_LSOF_COL_FILENAME
- );
-
- GtkWidget *tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
- g_object_unref(model);
- gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
-
-
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
-
- // PIXBUF / PROCESS
-
- column = gtk_tree_view_column_new();
-
- renderer = gtk_cell_renderer_pixbuf_new();
- gtk_tree_view_column_pack_start(column, renderer, FALSE);
- gtk_tree_view_column_set_attributes(column, renderer,
- "pixbuf", PROCMAN_LSOF_COL_PIXBUF,
- NULL);
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_column_pack_start(column, renderer, FALSE);
- gtk_tree_view_column_set_attributes(column, renderer,
- "text", PROCMAN_LSOF_COL_PROCESS,
- NULL);
+ GtkListStore *model = \
+ gtk_list_store_new(PROCMAN_LSOF_NCOLS,
+ GDK_TYPE_PIXBUF, // PROCMAN_LSOF_COL_PIXBUF
+ G_TYPE_STRING, // PROCMAN_LSOF_COL_PROCESS
+ G_TYPE_UINT, // PROCMAN_LSOF_COL_PID
+ G_TYPE_STRING // PROCMAN_LSOF_COL_FILENAME
+ );
+
+ GtkWidget *tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+ g_object_unref(model);
+ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
+
+
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+
+ // PIXBUF / PROCESS
+
+ column = gtk_tree_view_column_new();
+
+ renderer = gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_column_pack_start(column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes(column, renderer,
+ "pixbuf", PROCMAN_LSOF_COL_PIXBUF,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes(column, renderer,
+ "text", PROCMAN_LSOF_COL_PROCESS,
+ NULL);
- gtk_tree_view_column_set_title(column, _("Process"));
- gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_PROCESS);
- gtk_tree_view_column_set_resizable(column, TRUE);
- gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
- gtk_tree_view_column_set_min_width(column, 10);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
- gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), PROCMAN_LSOF_COL_PROCESS,
- GTK_SORT_ASCENDING);
-
-
- // PID
- renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes(_("PID"), renderer,
- "text", PROCMAN_LSOF_COL_PID,
- NULL);
- gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_PID);
- gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
-
-
- // FILENAME
- renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes(_("Filename"), renderer,
- "text", PROCMAN_LSOF_COL_FILENAME,
- NULL);
- gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_FILENAME);
- gtk_tree_view_column_set_resizable(column, TRUE);
- gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
-
-
- GtkWidget *dialog; /* = gtk_dialog_new_with_buttons(_("Search for Open Files"), NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL); */
- dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(procdata->app));
- gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
- // gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
- gtk_window_set_title(GTK_WINDOW(dialog), _("Search for Open Files"));
-
- // g_signal_connect(G_OBJECT(dialog), "response",
- // G_CALLBACK(close_dialog), NULL);
- gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
- gtk_window_set_default_size(GTK_WINDOW(dialog), 575, 400);
- gtk_container_set_border_width(GTK_CONTAINER(dialog), 12);
- GtkWidget *mainbox = gtk_vbox_new(FALSE, 12);
- gtk_container_add(GTK_CONTAINER(dialog), mainbox);
- gtk_box_set_spacing(GTK_BOX(mainbox), 6);
-
-
- // Label, entry and search button
-
- GtkWidget *hbox1 = gtk_hbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(mainbox), hbox1, FALSE, FALSE, 0);
-
- GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_DIALOG);
- gtk_box_pack_start(GTK_BOX(hbox1), image, FALSE, FALSE, 0);
-
-
- GtkWidget *vbox2 = gtk_vbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(hbox1), vbox2, TRUE, TRUE, 0);
-
-
- GtkWidget *hbox = gtk_hbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(vbox2), hbox, TRUE, TRUE, 0);
- GtkWidget *label = gtk_label_new_with_mnemonic(_("_Name contains:"));
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- GtkWidget *entry = gtk_entry_new();
-
- // entry = sexy_icon_entry_new();
- // sexy_icon_entry_add_clear_button(SEXY_ICON_ENTRY(entry));
- // GtkWidget *icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
- // sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry), SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
-
- gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
- GtkWidget *search_button = gtk_button_new_from_stock(GTK_STOCK_FIND);
- gtk_box_pack_start(GTK_BOX(hbox), search_button, FALSE, FALSE, 0);
- GtkWidget *clear_button = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
- gtk_box_pack_start(GTK_BOX(hbox), clear_button, FALSE, FALSE, 0);
-
-
- GtkWidget *case_button = gtk_check_button_new_with_mnemonic(_("Case insensitive matching"));
- GtkWidget *hbox3 = gtk_hbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(hbox3), case_button, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(vbox2), hbox3, FALSE, FALSE, 0);
-
-
- GtkWidget *results_box = gtk_hbox_new(FALSE, 12);
- gtk_box_pack_start(GTK_BOX(mainbox), results_box, FALSE, FALSE, 0);
- GtkWidget *results_label = gtk_label_new_with_mnemonic(_("S_earch results:"));
- gtk_box_pack_start(GTK_BOX(results_box), results_label, FALSE, FALSE, 0);
- GtkWidget *count_label = gtk_label_new(NULL);
- gtk_box_pack_end(GTK_BOX(results_box), count_label, FALSE, FALSE, 0);
-
-
-
-
- // Scrolled TreeView
- GtkWidget *scrolled = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
- GTK_SHADOW_IN);
- gtk_container_add(GTK_CONTAINER(scrolled), tree);
- gtk_box_pack_start(GTK_BOX(mainbox), scrolled, TRUE, TRUE, 0);
-
- GtkWidget *bottom_box = gtk_hbox_new(FALSE, 12);
- GtkWidget *close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
- gtk_box_pack_start(GTK_BOX(mainbox), bottom_box, FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(bottom_box), close_button, FALSE, FALSE, 0);
-
-
- GUI *gui = new GUI; // wil be deleted by the close button or delete-event
- gui->procdata = procdata;
- gui->model = model;
- gui->window = GTK_WINDOW(dialog);
- gui->entry = GTK_ENTRY(entry);
- gui->count = GTK_LABEL(count_label);
-
- g_signal_connect(G_OBJECT(entry), "activate",
- G_CALLBACK(GUI::search_entry_activate), gui);
- g_signal_connect(G_OBJECT(clear_button), "clicked",
- G_CALLBACK(GUI::clear_button_clicked), gui);
- g_signal_connect(G_OBJECT(search_button), "clicked",
- G_CALLBACK(GUI::search_button_clicked), gui);
- g_signal_connect(G_OBJECT(close_button), "clicked",
- G_CALLBACK(GUI::close_button_clicked), gui);
- g_signal_connect(G_OBJECT(case_button), "toggled",
- G_CALLBACK(GUI::case_button_toggled), gui);
- g_signal_connect(G_OBJECT(dialog), "delete-event",
- G_CALLBACK(GUI::window_delete_event), gui);
+ gtk_tree_view_column_set_title(column, _("Process"));
+ gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_PROCESS);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+ gtk_tree_view_column_set_min_width(column, 10);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
+ gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), PROCMAN_LSOF_COL_PROCESS,
+ GTK_SORT_ASCENDING);
+
+
+ // PID
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("PID"), renderer,
+ "text", PROCMAN_LSOF_COL_PID,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_PID);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
+
+
+ // FILENAME
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("Filename"), renderer,
+ "text", PROCMAN_LSOF_COL_FILENAME,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id(column, PROCMAN_LSOF_COL_FILENAME);
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
+
+
+ GtkWidget *dialog; /* = gtk_dialog_new_with_buttons(_("Search for Open Files"), NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL); */
+ dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(procdata->app));
+ gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
+ // gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
+ gtk_window_set_title(GTK_WINDOW(dialog), _("Search for Open Files"));
+
+ // g_signal_connect(G_OBJECT(dialog), "response",
+ // G_CALLBACK(close_dialog), NULL);
+ gtk_window_set_resizable(GTK_WINDOW(dialog), TRUE);
+ gtk_window_set_default_size(GTK_WINDOW(dialog), 575, 400);
+ gtk_container_set_border_width(GTK_CONTAINER(dialog), 12);
+ GtkWidget *mainbox = gtk_vbox_new(FALSE, 12);
+ gtk_container_add(GTK_CONTAINER(dialog), mainbox);
+ gtk_box_set_spacing(GTK_BOX(mainbox), 6);
+
+
+ // Label, entry and search button
+
+ GtkWidget *hbox1 = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(mainbox), hbox1, FALSE, FALSE, 0);
+
+ GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start(GTK_BOX(hbox1), image, FALSE, FALSE, 0);
+
+
+ GtkWidget *vbox2 = gtk_vbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(hbox1), vbox2, TRUE, TRUE, 0);
+
+
+ GtkWidget *hbox = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox, TRUE, TRUE, 0);
+ GtkWidget *label = gtk_label_new_with_mnemonic(_("_Name contains:"));
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ GtkWidget *entry = gtk_entry_new();
+
+ // entry = sexy_icon_entry_new();
+ // sexy_icon_entry_add_clear_button(SEXY_ICON_ENTRY(entry));
+ // GtkWidget *icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
+ // sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(entry), SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
+
+ gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
+ GtkWidget *search_button = gtk_button_new_from_stock(GTK_STOCK_FIND);
+ gtk_box_pack_start(GTK_BOX(hbox), search_button, FALSE, FALSE, 0);
+ GtkWidget *clear_button = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
+ gtk_box_pack_start(GTK_BOX(hbox), clear_button, FALSE, FALSE, 0);
+
+
+ GtkWidget *case_button = gtk_check_button_new_with_mnemonic(_("Case insensitive matching"));
+ GtkWidget *hbox3 = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(hbox3), case_button, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox3, FALSE, FALSE, 0);
+
+
+ GtkWidget *results_box = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(mainbox), results_box, FALSE, FALSE, 0);
+ GtkWidget *results_label = gtk_label_new_with_mnemonic(_("S_earch results:"));
+ gtk_box_pack_start(GTK_BOX(results_box), results_label, FALSE, FALSE, 0);
+ GtkWidget *count_label = gtk_label_new(NULL);
+ gtk_box_pack_end(GTK_BOX(results_box), count_label, FALSE, FALSE, 0);
+
+
+
+
+ // Scrolled TreeView
+ GtkWidget *scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_SHADOW_IN);
+ gtk_container_add(GTK_CONTAINER(scrolled), tree);
+ gtk_box_pack_start(GTK_BOX(mainbox), scrolled, TRUE, TRUE, 0);
+
+ GtkWidget *bottom_box = gtk_hbox_new(FALSE, 12);
+ GtkWidget *close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+ gtk_box_pack_start(GTK_BOX(mainbox), bottom_box, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(bottom_box), close_button, FALSE, FALSE, 0);
+
+
+ GUI *gui = new GUI; // wil be deleted by the close button or delete-event
+ gui->procdata = procdata;
+ gui->model = model;
+ gui->window = GTK_WINDOW(dialog);
+ gui->entry = GTK_ENTRY(entry);
+ gui->count = GTK_LABEL(count_label);
+
+ g_signal_connect(G_OBJECT(entry), "activate",
+ G_CALLBACK(GUI::search_entry_activate), gui);
+ g_signal_connect(G_OBJECT(clear_button), "clicked",
+ G_CALLBACK(GUI::clear_button_clicked), gui);
+ g_signal_connect(G_OBJECT(search_button), "clicked",
+ G_CALLBACK(GUI::search_button_clicked), gui);
+ g_signal_connect(G_OBJECT(close_button), "clicked",
+ G_CALLBACK(GUI::close_button_clicked), gui);
+ g_signal_connect(G_OBJECT(case_button), "toggled",
+ G_CALLBACK(GUI::case_button_toggled), gui);
+ g_signal_connect(G_OBJECT(dialog), "delete-event",
+ G_CALLBACK(GUI::window_delete_event), gui);
- gtk_widget_show_all(dialog);
+ gtk_widget_show_all(dialog);
}
diff --git a/src/memmaps.cpp b/src/memmaps.cpp
index 352ed45..36b0340 100644
--- a/src/memmaps.cpp
+++ b/src/memmaps.cpp
@@ -23,172 +23,172 @@ using std::string;
/* be careful with this enum, you could break the column names */
enum
{
- MMAP_COL_FILENAME,
- MMAP_COL_VMSTART,
- MMAP_COL_VMEND,
- MMAP_COL_VMSZ,
- MMAP_COL_FLAGS,
- MMAP_COL_VMOFFSET,
- MMAP_COL_PRIVATE_CLEAN,
- MMAP_COL_PRIVATE_DIRTY,
- MMAP_COL_SHARED_CLEAN,
- MMAP_COL_SHARED_DIRTY,
- MMAP_COL_DEVICE,
- MMAP_COL_INODE,
- MMAP_COL_MAX
+ MMAP_COL_FILENAME,
+ MMAP_COL_VMSTART,
+ MMAP_COL_VMEND,
+ MMAP_COL_VMSZ,
+ MMAP_COL_FLAGS,
+ MMAP_COL_VMOFFSET,
+ MMAP_COL_PRIVATE_CLEAN,
+ MMAP_COL_PRIVATE_DIRTY,
+ MMAP_COL_SHARED_CLEAN,
+ MMAP_COL_SHARED_DIRTY,
+ MMAP_COL_DEVICE,
+ MMAP_COL_INODE,
+ MMAP_COL_MAX
};
namespace
{
- class OffsetFormater
- {
- string format;
+ class OffsetFormater
+ {
+ string format;
- public:
+ public:
- void set(const glibtop_map_entry &last_map)
- {
- this->format = (last_map.end <= G_MAXUINT32) ? "%08" G_GINT64_MODIFIER "x" : "%016" G_GINT64_MODIFIER "x";
- }
+ void set(const glibtop_map_entry &last_map)
+ {
+ this->format = (last_map.end <= G_MAXUINT32) ? "%08" G_GINT64_MODIFIER "x" : "%016" G_GINT64_MODIFIER "x";
+ }
- string operator()(guint64 v) const
- {
- char buffer[17];
- g_snprintf(buffer, sizeof buffer, this->format.c_str(), v);
- return buffer;
- }
- };
+ string operator()(guint64 v) const
+ {
+ char buffer[17];
+ g_snprintf(buffer, sizeof buffer, this->format.c_str(), v);
+ return buffer;
+ }
+ };
#if 0
- struct ColumnState
- {
- unsigned visible;
- unsigned id;
- unsigned width;
-
- int pack() const
+ struct ColumnState
{
- unsigned p = 0;
- p |= (this->visible & 0x0001) << 24;
- p |= (this->id & 0x00ff) << 16;
- p |= (this->width & 0xffff);
- return p;
- }
+ unsigned visible;
+ unsigned id;
+ unsigned width;
- void unpack(int i)
- {
- this->visible = 0x0001 & (i >> 24);
- this->id = 0x00ff & (i >> 16);
- this->width = 0xffff & i;
- }
- };
+ int pack() const
+ {
+ unsigned p = 0;
+ p |= (this->visible & 0x0001) << 24;
+ p |= (this->id & 0x00ff) << 16;
+ p |= (this->width & 0xffff);
+ return p;
+ }
+ void unpack(int i)
+ {
+ this->visible = 0x0001 & (i >> 24);
+ this->id = 0x00ff & (i >> 16);
+ this->width = 0xffff & i;
+ }
+ };
-#endif
-
+#endif
- class InodeDevices
- {
- typedef std::map<guint16, string> Map;
- Map devices;
- public:
- void update()
+ class InodeDevices
{
- this->devices.clear();
+ typedef std::map<guint16, string> Map;
+ Map devices;
- glibtop_mountlist list;
- glibtop_mountentry *entries = glibtop_get_mountlist(&list, 1);
+ public:
- for (unsigned i = 0; i != list.number; ++i) {
- struct stat buf;
+ void update()
+ {
+ this->devices.clear();
- if (stat(entries[i].devname, &buf) != -1)
- this->devices[buf.st_rdev] = entries[i].devname;
- }
+ glibtop_mountlist list;
+ glibtop_mountentry *entries = glibtop_get_mountlist(&list, 1);
- g_free(entries);
- }
+ for (unsigned i = 0; i != list.number; ++i) {
+ struct stat buf;
- string get(guint64 dev64)
- {
- if (dev64 == 0)
- return "";
+ if (stat(entries[i].devname, &buf) != -1)
+ this->devices[buf.st_rdev] = entries[i].devname;
+ }
- guint16 dev = dev64 & 0xffff;
+ g_free(entries);
+ }
- if (dev != dev64)
- g_warning("weird device %" G_GINT64_MODIFIER "x", dev64);
+ string get(guint64 dev64)
+ {
+ if (dev64 == 0)
+ return "";
- Map::iterator it(this->devices.find(dev));
+ guint16 dev = dev64 & 0xffff;
- if (it != this->devices.end())
- return it->second;
+ if (dev != dev64)
+ g_warning("weird device %" G_GINT64_MODIFIER "x", dev64);
- guint8 major, minor;
- major = dev >> 8;
- minor = dev;
+ Map::iterator it(this->devices.find(dev));
- std::ostringstream out;
- out << std::hex
- << std::setfill('0')
- << std::setw(2) << unsigned(major)
- << ':'
- << std::setw(2) << unsigned(minor);
+ if (it != this->devices.end())
+ return it->second;
- this->devices[dev] = out.str();
- return out.str();
- }
- };
+ guint8 major, minor;
+ major = dev >> 8;
+ minor = dev;
+ std::ostringstream out;
+ out << std::hex
+ << std::setfill('0')
+ << std::setw(2) << unsigned(major)
+ << ':'
+ << std::setw(2) << unsigned(minor);
- class MemMapsData
- {
- public:
- guint timer;
- GtkWidget *tree;
- GSettings *settings;
- ProcInfo *info;
- OffsetFormater format;
- mutable InodeDevices devices;
- const char * const schema;
-
- MemMapsData(GtkWidget *a_tree, GSettings *a_settings)
- : tree(a_tree),
- settings(a_settings),
- schema("memmapstree")
- {
- procman_get_tree_state(this->settings, this->tree, this->schema);
- }
+ this->devices[dev] = out.str();
+ return out.str();
+ }
+ };
- ~MemMapsData()
+
+ class MemMapsData
{
- procman_save_tree_state(this->settings, this->tree, this->schema);
- }
- };
+ public:
+ guint timer;
+ GtkWidget *tree;
+ GSettings *settings;
+ ProcInfo *info;
+ OffsetFormater format;
+ mutable InodeDevices devices;
+ const char * const schema;
+
+ MemMapsData(GtkWidget *a_tree, GSettings *a_settings)
+ : tree(a_tree),
+ settings(a_settings),
+ schema("memmapstree")
+ {
+ procman_get_tree_state(this->settings, this->tree, this->schema);
+ }
+
+ ~MemMapsData()
+ {
+ procman_save_tree_state(this->settings, this->tree, this->schema);
+ }
+ };
}
struct glibtop_map_entry_cmp
{
- bool operator()(const glibtop_map_entry &a, const guint64 start) const
- {
- return a.start < start;
- }
+ bool operator()(const glibtop_map_entry &a, const guint64 start) const
+ {
+ return a.start < start;
+ }
- bool operator()(const guint64 &start, const glibtop_map_entry &a) const
- {
- return not (*this)(a, start);
- }
+ bool operator()(const guint64 &start, const glibtop_map_entry &a) const
+ {
+ return not (*this)(a, start);
+ }
};
@@ -196,41 +196,41 @@ struct glibtop_map_entry_cmp
static void
update_row(GtkTreeModel *model, GtkTreeIter &row, const MemMapsData &mm, const glibtop_map_entry *memmaps)
{
- guint64 size;
- string filename, device;
- string vmstart, vmend, vmoffset;
- char flags[5] = "----";
-
- size = memmaps->end - memmaps->start;
-
- if(memmaps->perm & GLIBTOP_MAP_PERM_READ) flags [0] = 'r';
- if(memmaps->perm & GLIBTOP_MAP_PERM_WRITE) flags [1] = 'w';
- if(memmaps->perm & GLIBTOP_MAP_PERM_EXECUTE) flags [2] = 'x';
- if(memmaps->perm & GLIBTOP_MAP_PERM_SHARED) flags [3] = 's';
- if(memmaps->perm & GLIBTOP_MAP_PERM_PRIVATE) flags [3] = 'p';
-
- if (memmaps->flags & (1 << GLIBTOP_MAP_ENTRY_FILENAME))
- filename = memmaps->filename;
-
- vmstart = mm.format(memmaps->start);
- vmend = mm.format(memmaps->end);
- vmoffset = mm.format(memmaps->offset);
- device = mm.devices.get(memmaps->device);
-
- gtk_list_store_set (GTK_LIST_STORE (model), &row,
- MMAP_COL_FILENAME, filename.c_str(),
- MMAP_COL_VMSTART, vmstart.c_str(),
- MMAP_COL_VMEND, vmend.c_str(),
- MMAP_COL_VMSZ, size,
- MMAP_COL_FLAGS, flags,
- MMAP_COL_VMOFFSET, vmoffset.c_str(),
- MMAP_COL_PRIVATE_CLEAN, memmaps->private_clean,
- MMAP_COL_PRIVATE_DIRTY, memmaps->private_dirty,
- MMAP_COL_SHARED_CLEAN, memmaps->shared_clean,
- MMAP_COL_SHARED_DIRTY, memmaps->shared_dirty,
- MMAP_COL_DEVICE, device.c_str(),
- MMAP_COL_INODE, memmaps->inode,
- -1);
+ guint64 size;
+ string filename, device;
+ string vmstart, vmend, vmoffset;
+ char flags[5] = "----";
+
+ size = memmaps->end - memmaps->start;
+
+ if(memmaps->perm & GLIBTOP_MAP_PERM_READ) flags [0] = 'r';
+ if(memmaps->perm & GLIBTOP_MAP_PERM_WRITE) flags [1] = 'w';
+ if(memmaps->perm & GLIBTOP_MAP_PERM_EXECUTE) flags [2] = 'x';
+ if(memmaps->perm & GLIBTOP_MAP_PERM_SHARED) flags [3] = 's';
+ if(memmaps->perm & GLIBTOP_MAP_PERM_PRIVATE) flags [3] = 'p';
+
+ if (memmaps->flags & (1 << GLIBTOP_MAP_ENTRY_FILENAME))
+ filename = memmaps->filename;
+
+ vmstart = mm.format(memmaps->start);
+ vmend = mm.format(memmaps->end);
+ vmoffset = mm.format(memmaps->offset);
+ device = mm.devices.get(memmaps->device);
+
+ gtk_list_store_set (GTK_LIST_STORE (model), &row,
+ MMAP_COL_FILENAME, filename.c_str(),
+ MMAP_COL_VMSTART, vmstart.c_str(),
+ MMAP_COL_VMEND, vmend.c_str(),
+ MMAP_COL_VMSZ, size,
+ MMAP_COL_FLAGS, flags,
+ MMAP_COL_VMOFFSET, vmoffset.c_str(),
+ MMAP_COL_PRIVATE_CLEAN, memmaps->private_clean,
+ MMAP_COL_PRIVATE_DIRTY, memmaps->private_dirty,
+ MMAP_COL_SHARED_CLEAN, memmaps->shared_clean,
+ MMAP_COL_SHARED_DIRTY, memmaps->shared_dirty,
+ MMAP_COL_DEVICE, device.c_str(),
+ MMAP_COL_INODE, memmaps->inode,
+ -1);
}
@@ -239,79 +239,79 @@ update_row(GtkTreeModel *model, GtkTreeIter &row, const MemMapsData &mm, const g
static void
update_memmaps_dialog (MemMapsData *mmdata)
{
- GtkTreeModel *model;
- glibtop_map_entry *memmaps;
- glibtop_proc_map procmap;
-
- memmaps = glibtop_get_proc_map (&procmap, mmdata->info->pid);
- /* process has disappeared */
- if(!memmaps or procmap.number == 0) return;
-
- mmdata->format.set(memmaps[procmap.number - 1]);
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (mmdata->tree));
-
- GtkTreeIter iter;
-
- typedef std::map<guint64, GtkTreeIter> IterCache;
- IterCache iter_cache;
-
- /*
- removes the old maps and
- also fills a cache of start -> iter in order to speed
- up add
- */
-
- if (gtk_tree_model_get_iter_first(model, &iter)) {
- while (true) {
- char *vmstart = 0;
- guint64 start;
- gtk_tree_model_get(model, &iter,
- MMAP_COL_VMSTART, &vmstart,
- -1);
-
- try {
- std::istringstream(vmstart) >> std::hex >> start;
- } catch (std::logic_error &e) {
- g_warning("Could not parse %s", vmstart);
- start = 0;
- }
-
- g_free(vmstart);
-
- bool found = std::binary_search(memmaps, memmaps + procmap.number,
- start, glibtop_map_entry_cmp());
-
- if (found) {
- iter_cache[start] = iter;
- if (!gtk_tree_model_iter_next(model, &iter))
- break;
- } else {
- if (!gtk_list_store_remove(GTK_LIST_STORE(model), &iter))
- break;
- }
- }
- }
-
- mmdata->devices.update();
-
- /*
- add the new maps
- */
-
- for (guint i = 0; i != procmap.number; i++) {
- GtkTreeIter iter;
- IterCache::iterator it(iter_cache.find(memmaps[i].start));
-
- if (it != iter_cache.end())
- iter = it->second;
- else
- gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
-
- update_row(model, iter, *mmdata, &memmaps[i]);
- }
-
- g_free (memmaps);
+ GtkTreeModel *model;
+ glibtop_map_entry *memmaps;
+ glibtop_proc_map procmap;
+
+ memmaps = glibtop_get_proc_map (&procmap, mmdata->info->pid);
+ /* process has disappeared */
+ if(!memmaps or procmap.number == 0) return;
+
+ mmdata->format.set(memmaps[procmap.number - 1]);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (mmdata->tree));
+
+ GtkTreeIter iter;
+
+ typedef std::map<guint64, GtkTreeIter> IterCache;
+ IterCache iter_cache;
+
+ /*
+ removes the old maps and
+ also fills a cache of start -> iter in order to speed
+ up add
+ */
+
+ if (gtk_tree_model_get_iter_first(model, &iter)) {
+ while (true) {
+ char *vmstart = 0;
+ guint64 start;
+ gtk_tree_model_get(model, &iter,
+ MMAP_COL_VMSTART, &vmstart,
+ -1);
+
+ try {
+ std::istringstream(vmstart) >> std::hex >> start;
+ } catch (std::logic_error &e) {
+ g_warning("Could not parse %s", vmstart);
+ start = 0;
+ }
+
+ g_free(vmstart);
+
+ bool found = std::binary_search(memmaps, memmaps + procmap.number,
+ start, glibtop_map_entry_cmp());
+
+ if (found) {
+ iter_cache[start] = iter;
+ if (!gtk_tree_model_iter_next(model, &iter))
+ break;
+ } else {
+ if (!gtk_list_store_remove(GTK_LIST_STORE(model), &iter))
+ break;
+ }
+ }
+ }
+
+ mmdata->devices.update();
+
+ /*
+ add the new maps
+ */
+
+ for (guint i = 0; i != procmap.number; i++) {
+ GtkTreeIter iter;
+ IterCache::iterator it(iter_cache.find(memmaps[i].start));
+
+ if (it != iter_cache.end())
+ iter = it->second;
+ else
+ gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
+
+ update_row(model, iter, *mmdata, &memmaps[i]);
+ }
+
+ g_free (memmaps);
}
@@ -319,197 +319,197 @@ update_memmaps_dialog (MemMapsData *mmdata)
static void
dialog_response (GtkDialog * dialog, gint response_id, gpointer data)
{
- MemMapsData * const mmdata = static_cast<MemMapsData*>(data);
+ MemMapsData * const mmdata = static_cast<MemMapsData*>(data);
- g_source_remove (mmdata->timer);
+ g_source_remove (mmdata->timer);
- delete mmdata;
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ delete mmdata;
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static MemMapsData*
create_memmapsdata (ProcData *procdata)
{
- GtkWidget *tree;
- GtkListStore *model;
- guint i;
-
- const gchar * const titles[] = {
- N_("Filename"),
- // xgettext: virtual memory start
- N_("VM Start"),
- // xgettext: virtual memory end
- N_("VM End"),
- // xgettext: virtual memory syze
- N_("VM Size"),
- N_("Flags"),
- // xgettext: virtual memory offset
- N_("VM Offset"),
- // xgettext: memory that has not been modified since
- // it has been allocated
- N_("Private clean"),
- // xgettext: memory that has been modified since it
- // has been allocated
- N_("Private dirty"),
- // xgettext: shared memory that has not been modified
- // since it has been allocated
- N_("Shared clean"),
- // xgettext: shared memory that has been modified
- // since it has been allocated
- N_("Shared dirty"),
- N_("Device"),
- N_("Inode")
- };
-
- model = gtk_list_store_new (MMAP_COL_MAX,
- G_TYPE_STRING, /* MMAP_COL_FILENAME */
- G_TYPE_STRING, /* MMAP_COL_VMSTART */
- G_TYPE_STRING, /* MMAP_COL_VMEND */
- G_TYPE_UINT64, /* MMAP_COL_VMSZ */
- G_TYPE_STRING, /* MMAP_COL_FLAGS */
- G_TYPE_STRING, /* MMAP_COL_VMOFFSET */
- G_TYPE_UINT64, /* MMAP_COL_PRIVATE_CLEAN */
- G_TYPE_UINT64, /* MMAP_COL_PRIVATE_DIRTY */
- G_TYPE_UINT64, /* MMAP_COL_SHARED_CLEAN */
- G_TYPE_UINT64, /* MMAP_COL_SHARED_DIRTY */
- G_TYPE_STRING, /* MMAP_COL_DEVICE */
- G_TYPE_UINT64 /* MMAP_COL_INODE */
- );
-
- tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
- gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree), TRUE);
- g_object_unref (G_OBJECT (model));
-
- for (i = 0; i < MMAP_COL_MAX; i++) {
- GtkCellRenderer *cell;
- GtkTreeViewColumn *col;
-
- cell = gtk_cell_renderer_text_new();
- col = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start(col, cell, TRUE);
- gtk_tree_view_column_set_title(col, _(titles[i]));
- gtk_tree_view_column_set_resizable(col, TRUE);
- gtk_tree_view_column_set_sort_column_id(col, i);
- gtk_tree_view_column_set_reorderable(col, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col);
-
- switch (i) {
- case MMAP_COL_PRIVATE_CLEAN:
- case MMAP_COL_PRIVATE_DIRTY:
- case MMAP_COL_SHARED_CLEAN:
- case MMAP_COL_SHARED_DIRTY:
- case MMAP_COL_VMSZ:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::size_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
-
- g_object_set(cell, "xalign", 1.0f, NULL);
- break;
-
- default:
- gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
- break;
- }
-
-
- switch (i) {
- case MMAP_COL_VMSTART:
- case MMAP_COL_VMEND:
- case MMAP_COL_FLAGS:
- case MMAP_COL_VMOFFSET:
- case MMAP_COL_DEVICE:
- g_object_set(cell, "family", "monospace", NULL);
- break;
- }
- }
-
- return new MemMapsData(tree, procdata->settings);
+ GtkWidget *tree;
+ GtkListStore *model;
+ guint i;
+
+ const gchar * const titles[] = {
+ N_("Filename"),
+ // xgettext: virtual memory start
+ N_("VM Start"),
+ // xgettext: virtual memory end
+ N_("VM End"),
+ // xgettext: virtual memory syze
+ N_("VM Size"),
+ N_("Flags"),
+ // xgettext: virtual memory offset
+ N_("VM Offset"),
+ // xgettext: memory that has not been modified since
+ // it has been allocated
+ N_("Private clean"),
+ // xgettext: memory that has been modified since it
+ // has been allocated
+ N_("Private dirty"),
+ // xgettext: shared memory that has not been modified
+ // since it has been allocated
+ N_("Shared clean"),
+ // xgettext: shared memory that has been modified
+ // since it has been allocated
+ N_("Shared dirty"),
+ N_("Device"),
+ N_("Inode")
+ };
+
+ model = gtk_list_store_new (MMAP_COL_MAX,
+ G_TYPE_STRING, /* MMAP_COL_FILENAME */
+ G_TYPE_STRING, /* MMAP_COL_VMSTART */
+ G_TYPE_STRING, /* MMAP_COL_VMEND */
+ G_TYPE_UINT64, /* MMAP_COL_VMSZ */
+ G_TYPE_STRING, /* MMAP_COL_FLAGS */
+ G_TYPE_STRING, /* MMAP_COL_VMOFFSET */
+ G_TYPE_UINT64, /* MMAP_COL_PRIVATE_CLEAN */
+ G_TYPE_UINT64, /* MMAP_COL_PRIVATE_DIRTY */
+ G_TYPE_UINT64, /* MMAP_COL_SHARED_CLEAN */
+ G_TYPE_UINT64, /* MMAP_COL_SHARED_DIRTY */
+ G_TYPE_STRING, /* MMAP_COL_DEVICE */
+ G_TYPE_UINT64 /* MMAP_COL_INODE */
+ );
+
+ tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree), TRUE);
+ g_object_unref (G_OBJECT (model));
+
+ for (i = 0; i < MMAP_COL_MAX; i++) {
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *col;
+
+ cell = gtk_cell_renderer_text_new();
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start(col, cell, TRUE);
+ gtk_tree_view_column_set_title(col, _(titles[i]));
+ gtk_tree_view_column_set_resizable(col, TRUE);
+ gtk_tree_view_column_set_sort_column_id(col, i);
+ gtk_tree_view_column_set_reorderable(col, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col);
+
+ switch (i) {
+ case MMAP_COL_PRIVATE_CLEAN:
+ case MMAP_COL_PRIVATE_DIRTY:
+ case MMAP_COL_SHARED_CLEAN:
+ case MMAP_COL_SHARED_DIRTY:
+ case MMAP_COL_VMSZ:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::size_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+
+ g_object_set(cell, "xalign", 1.0f, NULL);
+ break;
+
+ default:
+ gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
+ break;
+ }
+
+
+ switch (i) {
+ case MMAP_COL_VMSTART:
+ case MMAP_COL_VMEND:
+ case MMAP_COL_FLAGS:
+ case MMAP_COL_VMOFFSET:
+ case MMAP_COL_DEVICE:
+ g_object_set(cell, "family", "monospace", NULL);
+ break;
+ }
+ }
+
+ return new MemMapsData(tree, procdata->settings);
}
static gboolean
memmaps_timer (gpointer data)
{
- MemMapsData * const mmdata = static_cast<MemMapsData*>(data);
- GtkTreeModel *model;
+ MemMapsData * const mmdata = static_cast<MemMapsData*>(data);
+ GtkTreeModel *model;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (mmdata->tree));
- g_assert(model);
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (mmdata->tree));
+ g_assert(model);
- update_memmaps_dialog (mmdata);
+ update_memmaps_dialog (mmdata);
- return TRUE;
+ return TRUE;
}
static void
create_single_memmaps_dialog (GtkTreeModel *model, GtkTreePath *path,
- GtkTreeIter *iter, gpointer data)
+ GtkTreeIter *iter, gpointer data)
{
- ProcData * const procdata = static_cast<ProcData*>(data);
- MemMapsData *mmdata;
- GtkWidget *memmapsdialog;
- GtkWidget *dialog_vbox;
- GtkWidget *label;
- GtkWidget *scrolled;
- ProcInfo *info;
+ ProcData * const procdata = static_cast<ProcData*>(data);
+ MemMapsData *mmdata;
+ GtkWidget *memmapsdialog;
+ GtkWidget *dialog_vbox;
+ GtkWidget *label;
+ GtkWidget *scrolled;
+ ProcInfo *info;
- gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
+ gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
- if (!info)
- return;
+ if (!info)
+ return;
- mmdata = create_memmapsdata (procdata);
- mmdata->info = info;
+ mmdata = create_memmapsdata (procdata);
+ mmdata->info = info;
- memmapsdialog = gtk_dialog_new_with_buttons (_("Memory Maps"), GTK_WINDOW (procdata->app),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL);
- gtk_window_set_resizable(GTK_WINDOW(memmapsdialog), TRUE);
- gtk_window_set_default_size(GTK_WINDOW(memmapsdialog), 575, 400);
- gtk_container_set_border_width(GTK_CONTAINER(memmapsdialog), 5);
+ memmapsdialog = gtk_dialog_new_with_buttons (_("Memory Maps"), GTK_WINDOW (procdata->app),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+ gtk_window_set_resizable(GTK_WINDOW(memmapsdialog), TRUE);
+ gtk_window_set_default_size(GTK_WINDOW(memmapsdialog), 575, 400);
+ gtk_container_set_border_width(GTK_CONTAINER(memmapsdialog), 5);
- dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG(memmapsdialog));
- gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
+ dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG(memmapsdialog));
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
- label = procman_make_label_for_mmaps_or_ofiles (
- _("_Memory maps for process \"%s\" (PID %u):"),
- info->name,
- info->pid);
+ label = procman_make_label_for_mmaps_or_ofiles (
+ _("_Memory maps for process \"%s\" (PID %u):"),
+ info->name,
+ info->pid);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), label, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), label, FALSE, TRUE, 0);
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (scrolled), mmdata->tree);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), mmdata->tree);
+ gtk_container_add (GTK_CONTAINER (scrolled), mmdata->tree);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), mmdata->tree);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), scrolled, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), scrolled, TRUE, TRUE, 0);
- g_signal_connect(G_OBJECT(memmapsdialog), "response",
- G_CALLBACK(dialog_response), mmdata);
+ g_signal_connect(G_OBJECT(memmapsdialog), "response",
+ G_CALLBACK(dialog_response), mmdata);
- gtk_widget_show_all (memmapsdialog);
+ gtk_widget_show_all (memmapsdialog);
- mmdata->timer = g_timeout_add_seconds (5, memmaps_timer, mmdata);
+ mmdata->timer = g_timeout_add_seconds (5, memmaps_timer, mmdata);
- update_memmaps_dialog (mmdata);
+ update_memmaps_dialog (mmdata);
}
void
create_memmaps_dialog (ProcData *procdata)
{
- /* TODO: do we really want to open multiple dialogs ? */
- gtk_tree_selection_selected_foreach (procdata->selection, create_single_memmaps_dialog,
- procdata);
+ /* TODO: do we really want to open multiple dialogs ? */
+ gtk_tree_selection_selected_foreach (procdata->selection, create_single_memmaps_dialog,
+ procdata);
}
diff --git a/src/memmaps.h b/src/memmaps.h
index f0a00cd..b79476e 100644
--- a/src/memmaps.h
+++ b/src/memmaps.h
@@ -4,6 +4,6 @@
#include <glib.h>
#include "procman.h"
-void create_memmaps_dialog (ProcData *procdata);
+void create_memmaps_dialog (ProcData *procdata);
#endif /* _PROCMAN_MEMMAPS_H_ */
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 140a97b..770f796 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -21,32 +21,32 @@
enum
{
- COL_FD,
- COL_TYPE,
- COL_OBJECT,
- COL_OPENFILE_STRUCT,
- NUM_OPENFILES_COL
+ COL_FD,
+ COL_TYPE,
+ COL_OBJECT,
+ COL_OPENFILE_STRUCT,
+ NUM_OPENFILES_COL
};
static const char*
get_type_name(enum glibtop_file_type t)
{
- switch(t)
- {
- case GLIBTOP_FILE_TYPE_FILE:
- return _("file");
- case GLIBTOP_FILE_TYPE_PIPE:
- return _("pipe");
- case GLIBTOP_FILE_TYPE_INET6SOCKET:
- return _("IPv6 network connection");
- case GLIBTOP_FILE_TYPE_INETSOCKET:
- return _("IPv4 network connection");
- case GLIBTOP_FILE_TYPE_LOCALSOCKET:
- return _("local socket");
- default:
- return _("unknown type");
- }
+ switch(t)
+ {
+ case GLIBTOP_FILE_TYPE_FILE:
+ return _("file");
+ case GLIBTOP_FILE_TYPE_PIPE:
+ return _("pipe");
+ case GLIBTOP_FILE_TYPE_INET6SOCKET:
+ return _("IPv6 network connection");
+ case GLIBTOP_FILE_TYPE_INETSOCKET:
+ return _("IPv4 network connection");
+ case GLIBTOP_FILE_TYPE_LOCALSOCKET:
+ return _("local socket");
+ default:
+ return _("unknown type");
+ }
}
@@ -54,32 +54,32 @@ get_type_name(enum glibtop_file_type t)
static char *
friendlier_hostname(const char *addr_str, int port)
{
- struct addrinfo hints = { };
- struct addrinfo *res = NULL;
- char hostname[NI_MAXHOST];
- char service[NI_MAXSERV];
- char port_str[6];
+ struct addrinfo hints = { };
+ struct addrinfo *res = NULL;
+ char hostname[NI_MAXHOST];
+ char service[NI_MAXSERV];
+ char port_str[6];
- if (!addr_str[0]) return g_strdup("");
+ if (!addr_str[0]) return g_strdup("");
- snprintf(port_str, sizeof port_str, "%d", port);
+ snprintf(port_str, sizeof port_str, "%d", port);
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
- if (getaddrinfo(addr_str, port_str, &hints, &res))
- goto failsafe;
+ if (getaddrinfo(addr_str, port_str, &hints, &res))
+ goto failsafe;
- if (getnameinfo(res->ai_addr, res->ai_addrlen, hostname,
- sizeof hostname, service, sizeof service, NI_IDN))
- goto failsafe;
+ if (getnameinfo(res->ai_addr, res->ai_addrlen, hostname,
+ sizeof hostname, service, sizeof service, NI_IDN))
+ goto failsafe;
- if (res) freeaddrinfo(res);
- return g_strdup_printf("%s, TCP port %d (%s)", hostname, port, service);
+ if (res) freeaddrinfo(res);
+ return g_strdup_printf("%s, TCP port %d (%s)", hostname, port, service);
- failsafe:
- if (res) freeaddrinfo(res);
- return g_strdup_printf("%s, TCP port %d", addr_str, port);
+ failsafe:
+ if (res) freeaddrinfo(res);
+ return g_strdup_printf("%s, TCP port %d", addr_str, port);
}
@@ -87,42 +87,42 @@ friendlier_hostname(const char *addr_str, int port)
static void
add_new_files (gpointer key, gpointer value, gpointer data)
{
- glibtop_open_files_entry *openfiles = static_cast<glibtop_open_files_entry*>(value);
-
- GtkTreeModel *model = static_cast<GtkTreeModel*>(data);
- GtkTreeIter row;
-
- char *object;
-
- switch(openfiles->type)
- {
- case GLIBTOP_FILE_TYPE_FILE:
- object = g_strdup(openfiles->info.file.name);
- break;
-
- case GLIBTOP_FILE_TYPE_INET6SOCKET:
- case GLIBTOP_FILE_TYPE_INETSOCKET:
- object = friendlier_hostname(openfiles->info.sock.dest_host,
- openfiles->info.sock.dest_port);
- break;
-
- case GLIBTOP_FILE_TYPE_LOCALSOCKET:
- object = g_strdup(openfiles->info.localsock.name);
- break;
-
- default:
- object = g_strdup("");
- }
-
- gtk_list_store_insert (GTK_LIST_STORE (model), &row, 0);
- gtk_list_store_set (GTK_LIST_STORE (model), &row,
- COL_FD, openfiles->fd,
- COL_TYPE, get_type_name(static_cast<glibtop_file_type>(openfiles->type)),
- COL_OBJECT, object,
- COL_OPENFILE_STRUCT, g_memdup(openfiles, sizeof(*openfiles)),
- -1);
-
- g_free(object);
+ glibtop_open_files_entry *openfiles = static_cast<glibtop_open_files_entry*>(value);
+
+ GtkTreeModel *model = static_cast<GtkTreeModel*>(data);
+ GtkTreeIter row;
+
+ char *object;
+
+ switch(openfiles->type)
+ {
+ case GLIBTOP_FILE_TYPE_FILE:
+ object = g_strdup(openfiles->info.file.name);
+ break;
+
+ case GLIBTOP_FILE_TYPE_INET6SOCKET:
+ case GLIBTOP_FILE_TYPE_INETSOCKET:
+ object = friendlier_hostname(openfiles->info.sock.dest_host,
+ openfiles->info.sock.dest_port);
+ break;
+
+ case GLIBTOP_FILE_TYPE_LOCALSOCKET:
+ object = g_strdup(openfiles->info.localsock.name);
+ break;
+
+ default:
+ object = g_strdup("");
+ }
+
+ gtk_list_store_insert (GTK_LIST_STORE (model), &row, 0);
+ gtk_list_store_set (GTK_LIST_STORE (model), &row,
+ COL_FD, openfiles->fd,
+ COL_TYPE, get_type_name(static_cast<glibtop_file_type>(openfiles->type)),
+ COL_OBJECT, object,
+ COL_OPENFILE_STRUCT, g_memdup(openfiles, sizeof(*openfiles)),
+ -1);
+
+ g_free(object);
}
static GList *old_maps = NULL;
@@ -130,25 +130,25 @@ static GList *old_maps = NULL;
static gboolean
classify_openfiles (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
- GHashTable *new_maps = static_cast<GHashTable*>(data);
- GtkTreeIter *old_iter;
- glibtop_open_files_entry *openfiles;
- gchar *old_name;
+ GHashTable *new_maps = static_cast<GHashTable*>(data);
+ GtkTreeIter *old_iter;
+ glibtop_open_files_entry *openfiles;
+ gchar *old_name;
- gtk_tree_model_get (model, iter, 1, &old_name, -1);
+ gtk_tree_model_get (model, iter, 1, &old_name, -1);
- openfiles = static_cast<glibtop_open_files_entry*>(g_hash_table_lookup (new_maps, old_name));
- if (openfiles) {
- g_hash_table_remove (new_maps, old_name);
- g_free (old_name);
- return FALSE;
+ openfiles = static_cast<glibtop_open_files_entry*>(g_hash_table_lookup (new_maps, old_name));
+ if (openfiles) {
+ g_hash_table_remove (new_maps, old_name);
+ g_free (old_name);
+ return FALSE;
- }
+ }
- old_iter = gtk_tree_iter_copy (iter);
- old_maps = g_list_append (old_maps, old_iter);
- g_free (old_name);
- return FALSE;
+ old_iter = gtk_tree_iter_copy (iter);
+ old_maps = g_list_append (old_maps, old_iter);
+ g_free (old_name);
+ return FALSE;
}
@@ -156,146 +156,146 @@ classify_openfiles (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g
static gboolean
compare_open_files(gconstpointer a, gconstpointer b)
{
- const glibtop_open_files_entry *o1 = static_cast<const glibtop_open_files_entry *>(a);
- const glibtop_open_files_entry *o2 = static_cast<const glibtop_open_files_entry *>(b);
+ const glibtop_open_files_entry *o1 = static_cast<const glibtop_open_files_entry *>(a);
+ const glibtop_open_files_entry *o2 = static_cast<const glibtop_open_files_entry *>(b);
- /* Falta manejar los diferentes tipos! */
- return (o1->fd == o2->fd) && (o1->type == o1->type); /* XXX! */
+ /* Falta manejar los diferentes tipos! */
+ return (o1->fd == o2->fd) && (o1->type == o1->type); /* XXX! */
}
static void
update_openfiles_dialog (GtkWidget *tree)
{
- ProcInfo *info;
- GtkTreeModel *model;
- glibtop_open_files_entry *openfiles;
- glibtop_proc_open_files procmap;
- GHashTable *new_maps;
- guint i;
+ ProcInfo *info;
+ GtkTreeModel *model;
+ glibtop_open_files_entry *openfiles;
+ glibtop_proc_open_files procmap;
+ GHashTable *new_maps;
+ guint i;
- info = static_cast<ProcInfo*>(g_object_get_data (G_OBJECT (tree), "selected_info"));
+ info = static_cast<ProcInfo*>(g_object_get_data (G_OBJECT (tree), "selected_info"));
- if (!info)
- return;
+ if (!info)
+ return;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
- openfiles = glibtop_get_proc_open_files (&procmap, info->pid);
+ openfiles = glibtop_get_proc_open_files (&procmap, info->pid);
- if (!openfiles)
- return;
+ if (!openfiles)
+ return;
- new_maps = static_cast<GHashTable *>(g_hash_table_new_full (g_str_hash, compare_open_files,
- NULL, NULL));
- for (i=0; i < procmap.number; i++)
- g_hash_table_insert (new_maps, openfiles + i, openfiles + i);
+ new_maps = static_cast<GHashTable *>(g_hash_table_new_full (g_str_hash, compare_open_files,
+ NULL, NULL));
+ for (i=0; i < procmap.number; i++)
+ g_hash_table_insert (new_maps, openfiles + i, openfiles + i);
- gtk_tree_model_foreach (model, classify_openfiles, new_maps);
+ gtk_tree_model_foreach (model, classify_openfiles, new_maps);
- g_hash_table_foreach (new_maps, add_new_files, model);
+ g_hash_table_foreach (new_maps, add_new_files, model);
- while (old_maps) {
- GtkTreeIter *iter = static_cast<GtkTreeIter*>(old_maps->data);
- glibtop_open_files_entry *openfiles = NULL;
+ while (old_maps) {
+ GtkTreeIter *iter = static_cast<GtkTreeIter*>(old_maps->data);
+ glibtop_open_files_entry *openfiles = NULL;
- gtk_tree_model_get (model, iter,
- COL_OPENFILE_STRUCT, &openfiles,
- -1);
+ gtk_tree_model_get (model, iter,
+ COL_OPENFILE_STRUCT, &openfiles,
+ -1);
- gtk_list_store_remove (GTK_LIST_STORE (model), iter);
- gtk_tree_iter_free (iter);
- g_free (openfiles);
+ gtk_list_store_remove (GTK_LIST_STORE (model), iter);
+ gtk_tree_iter_free (iter);
+ g_free (openfiles);
- old_maps = g_list_next (old_maps);
+ old_maps = g_list_next (old_maps);
- }
+ }
- g_hash_table_destroy (new_maps);
- g_free (openfiles);
+ g_hash_table_destroy (new_maps);
+ g_free (openfiles);
}
static void
close_openfiles_dialog (GtkDialog *dialog, gint id, gpointer data)
{
- GtkWidget *tree = static_cast<GtkWidget*>(data);
- GSettings *settings;
- guint timer;
+ GtkWidget *tree = static_cast<GtkWidget*>(data);
+ GSettings *settings;
+ guint timer;
- settings = static_cast<GSettings*>(g_object_get_data (G_OBJECT (tree), "settings"));
- procman_save_tree_state (settings, tree, procman::settings::open_files_tree_prefix.c_str());
+ settings = static_cast<GSettings*>(g_object_get_data (G_OBJECT (tree), "settings"));
+ procman_save_tree_state (settings, tree, procman::settings::open_files_tree_prefix.c_str());
- timer = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tree), "timer"));
- g_source_remove (timer);
+ timer = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tree), "timer"));
+ g_source_remove (timer);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
- return ;
+ return ;
}
static GtkWidget *
create_openfiles_tree (ProcData *procdata)
{
- GtkWidget *tree;
- GtkListStore *model;
- GtkTreeViewColumn *column;
- GtkCellRenderer *cell;
- gint i;
-
- const gchar * const titles[] = {
- /* Translators: "FD" here means "File Descriptor". Please use
- a very short translation if possible, and at most
- 2-3 characters for it to be able to fit in the UI. */
- N_("FD"),
- N_("Type"),
- N_("Object")
- };
-
- model = gtk_list_store_new (NUM_OPENFILES_COL,
- G_TYPE_INT, /* FD */
- G_TYPE_STRING, /* Type */
- G_TYPE_STRING, /* Object */
- G_TYPE_POINTER /* open_files_entry */
- );
-
- tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
- gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree), TRUE);
- g_object_unref (G_OBJECT (model));
-
- for (i = 0; i < NUM_OPENFILES_COL-1; i++) {
- cell = gtk_cell_renderer_text_new ();
-
- switch (i) {
- case COL_FD:
- g_object_set(cell, "xalign", 1.0f, NULL);
- break;
- }
-
- column = gtk_tree_view_column_new_with_attributes (_(titles[i]),
- cell,
- "text", i,
- NULL);
- gtk_tree_view_column_set_sort_column_id (column, i);
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
- }
+ GtkWidget *tree;
+ GtkListStore *model;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *cell;
+ gint i;
+
+ const gchar * const titles[] = {
+ /* Translators: "FD" here means "File Descriptor". Please use
+ a very short translation if possible, and at most
+ 2-3 characters for it to be able to fit in the UI. */
+ N_("FD"),
+ N_("Type"),
+ N_("Object")
+ };
+
+ model = gtk_list_store_new (NUM_OPENFILES_COL,
+ G_TYPE_INT, /* FD */
+ G_TYPE_STRING, /* Type */
+ G_TYPE_STRING, /* Object */
+ G_TYPE_POINTER /* open_files_entry */
+ );
+
+ tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree), TRUE);
+ g_object_unref (G_OBJECT (model));
+
+ for (i = 0; i < NUM_OPENFILES_COL-1; i++) {
+ cell = gtk_cell_renderer_text_new ();
+
+ switch (i) {
+ case COL_FD:
+ g_object_set(cell, "xalign", 1.0f, NULL);
+ break;
+ }
+
+ column = gtk_tree_view_column_new_with_attributes (_(titles[i]),
+ cell,
+ "text", i,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id (column, i);
+ gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
+ }
#if 0
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model),
- COL_VMSZ,
- sort_ints,
- GINT_TO_POINTER (COL_FD),
- NULL);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model),
+ COL_VMSZ,
+ sort_ints,
+ GINT_TO_POINTER (COL_FD),
+ NULL);
/*gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
0,
GTK_SORT_ASCENDING);*/
#endif
- procman_get_tree_state (procdata->settings, tree, procman::settings::open_files_tree_prefix.c_str());
+ procman_get_tree_state (procdata->settings, tree, procman::settings::open_files_tree_prefix.c_str());
- return tree;
+ return tree;
}
@@ -303,89 +303,89 @@ create_openfiles_tree (ProcData *procdata)
static gboolean
openfiles_timer (gpointer data)
{
- GtkWidget *tree = static_cast<GtkWidget*>(data);
- GtkTreeModel *model;
+ GtkWidget *tree = static_cast<GtkWidget*>(data);
+ GtkTreeModel *model;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
- g_assert(model);
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
+ g_assert(model);
- update_openfiles_dialog (tree);
+ update_openfiles_dialog (tree);
- return TRUE;
+ return TRUE;
}
static void
create_single_openfiles_dialog (GtkTreeModel *model, GtkTreePath *path,
- GtkTreeIter *iter, gpointer data)
+ GtkTreeIter *iter, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GtkWidget *openfilesdialog;
- GtkWidget *dialog_vbox, *vbox;
- GtkWidget *cmd_hbox;
- GtkWidget *label;
- GtkWidget *scrolled;
- GtkWidget *tree;
- ProcInfo *info;
- guint timer;
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GtkWidget *openfilesdialog;
+ GtkWidget *dialog_vbox, *vbox;
+ GtkWidget *cmd_hbox;
+ GtkWidget *label;
+ GtkWidget *scrolled;
+ GtkWidget *tree;
+ ProcInfo *info;
+ guint timer;
- gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
+ gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
- if (!info)
- return;
+ if (!info)
+ return;
- openfilesdialog = gtk_dialog_new_with_buttons (_("Open Files"), NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL);
- gtk_window_set_resizable (GTK_WINDOW (openfilesdialog), TRUE);
- gtk_window_set_default_size (GTK_WINDOW (openfilesdialog), 575, 400);
- gtk_container_set_border_width (GTK_CONTAINER (openfilesdialog), 5);
+ openfilesdialog = gtk_dialog_new_with_buttons (_("Open Files"), NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+ gtk_window_set_resizable (GTK_WINDOW (openfilesdialog), TRUE);
+ gtk_window_set_default_size (GTK_WINDOW (openfilesdialog), 575, 400);
+ gtk_container_set_border_width (GTK_CONTAINER (openfilesdialog), 5);
- vbox = gtk_dialog_get_content_area (GTK_DIALOG (openfilesdialog));
- gtk_box_set_spacing (GTK_BOX (vbox), 2);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+ vbox = gtk_dialog_get_content_area (GTK_DIALOG (openfilesdialog));
+ gtk_box_set_spacing (GTK_BOX (vbox), 2);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
- dialog_vbox = gtk_vbox_new (FALSE, 6);
- gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
- gtk_box_pack_start (GTK_BOX (vbox), dialog_vbox, TRUE, TRUE, 0);
+ dialog_vbox = gtk_vbox_new (FALSE, 6);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
+ gtk_box_pack_start (GTK_BOX (vbox), dialog_vbox, TRUE, TRUE, 0);
- cmd_hbox = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), cmd_hbox, FALSE, FALSE, 0);
+ cmd_hbox = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), cmd_hbox, FALSE, FALSE, 0);
- label = procman_make_label_for_mmaps_or_ofiles (
- _("_Files opened by process \"%s\" (PID %u):"),
- info->name,
- info->pid);
+ label = procman_make_label_for_mmaps_or_ofiles (
+ _("_Files opened by process \"%s\" (PID %u):"),
+ info->name,
+ info->pid);
- gtk_box_pack_start (GTK_BOX (cmd_hbox),label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (cmd_hbox),label, FALSE, FALSE, 0);
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_SHADOW_IN);
- tree = create_openfiles_tree (procdata);
- gtk_container_add (GTK_CONTAINER (scrolled), tree);
- g_object_set_data (G_OBJECT (tree), "selected_info", info);
- g_object_set_data (G_OBJECT (tree), "settings", procdata->settings);
+ tree = create_openfiles_tree (procdata);
+ gtk_container_add (GTK_CONTAINER (scrolled), tree);
+ g_object_set_data (G_OBJECT (tree), "selected_info", info);
+ g_object_set_data (G_OBJECT (tree), "settings", procdata->settings);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), scrolled, TRUE, TRUE, 0);
- gtk_widget_show_all (scrolled);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), scrolled, TRUE, TRUE, 0);
+ gtk_widget_show_all (scrolled);
- g_signal_connect (G_OBJECT (openfilesdialog), "response",
- G_CALLBACK (close_openfiles_dialog), tree);
+ g_signal_connect (G_OBJECT (openfilesdialog), "response",
+ G_CALLBACK (close_openfiles_dialog), tree);
- gtk_widget_show_all (openfilesdialog);
+ gtk_widget_show_all (openfilesdialog);
- timer = g_timeout_add_seconds (5, openfiles_timer, tree);
- g_object_set_data (G_OBJECT (tree), "timer", GUINT_TO_POINTER (timer));
+ timer = g_timeout_add_seconds (5, openfiles_timer, tree);
+ g_object_set_data (G_OBJECT (tree), "timer", GUINT_TO_POINTER (timer));
- update_openfiles_dialog (tree);
+ update_openfiles_dialog (tree);
}
@@ -393,6 +393,6 @@ create_single_openfiles_dialog (GtkTreeModel *model, GtkTreePath *path,
void
create_openfiles_dialog (ProcData *procdata)
{
- gtk_tree_selection_selected_foreach (procdata->selection, create_single_openfiles_dialog,
- procdata);
+ gtk_tree_selection_selected_foreach (procdata->selection, create_single_openfiles_dialog,
+ procdata);
}
diff --git a/src/openfiles.h b/src/openfiles.h
index a8b7b05..d135942 100644
--- a/src/openfiles.h
+++ b/src/openfiles.h
@@ -5,6 +5,6 @@
#include "procman.h"
-void create_openfiles_dialog (ProcData *procdata);
+void create_openfiles_dialog (ProcData *procdata);
#endif
diff --git a/src/prettytable.cpp b/src/prettytable.cpp
index 604ce09..5c2b571 100644
--- a/src/prettytable.cpp
+++ b/src/prettytable.cpp
@@ -24,11 +24,11 @@ namespace
PrettyTable::PrettyTable()
{
- WnckScreen* screen = wnck_screen_get_default();
- g_signal_connect(G_OBJECT(screen), "application_opened",
- G_CALLBACK(PrettyTable::on_application_opened), this);
- g_signal_connect(G_OBJECT(screen), "application_closed",
- G_CALLBACK(PrettyTable::on_application_closed), this);
+ WnckScreen* screen = wnck_screen_get_default();
+ g_signal_connect(G_OBJECT(screen), "application_opened",
+ G_CALLBACK(PrettyTable::on_application_opened), this);
+ g_signal_connect(G_OBJECT(screen), "application_closed",
+ G_CALLBACK(PrettyTable::on_application_closed), this);
}
@@ -40,35 +40,35 @@ PrettyTable::~PrettyTable()
void
PrettyTable::on_application_opened(WnckScreen* screen, WnckApplication* app, gpointer data)
{
- PrettyTable * const that = static_cast<PrettyTable*>(data);
- FILE *f;
+ PrettyTable * const that = static_cast<PrettyTable*>(data);
+ FILE *f;
- pid_t pid = wnck_application_get_pid(app);
+ pid_t pid = wnck_application_get_pid(app);
- if (pid == 0)
- return;
+ if (pid == 0)
+ return;
- const char* icon_name = wnck_application_get_icon_name(app);
+ const char* icon_name = wnck_application_get_icon_name(app);
- Glib::RefPtr<Gdk::Pixbuf> icon;
-
- // Make sure that icon_name is a valid symlink before loading.
- f = fopen (icon_name, "r");
- if (f != NULL) {
- fclose (f);
- icon = that->theme->load_icon(icon_name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
- }
+ Glib::RefPtr<Gdk::Pixbuf> icon;
- if (not icon) {
- icon = Glib::wrap(wnck_application_get_icon(app), /* take_copy */ true);
- icon = icon->scale_simple(APP_ICON_SIZE, APP_ICON_SIZE, Gdk::INTERP_HYPER);
- }
+ // Make sure that icon_name is a valid symlink before loading.
+ f = fopen (icon_name, "r");
+ if (f != NULL) {
+ fclose (f);
+ icon = that->theme->load_icon(icon_name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ }
+
+ if (not icon) {
+ icon = Glib::wrap(wnck_application_get_icon(app), /* take_copy */ true);
+ icon = icon->scale_simple(APP_ICON_SIZE, APP_ICON_SIZE, Gdk::INTERP_HYPER);
+ }
- if (not icon)
- return;
+ if (not icon)
+ return;
- that->register_application(pid, icon);
+ that->register_application(pid, icon);
}
@@ -92,12 +92,12 @@ PrettyTable::register_application(pid_t pid, Glib::RefPtr<Gdk::Pixbuf> icon)
void
PrettyTable::on_application_closed(WnckScreen* screen, WnckApplication* app, gpointer data)
{
- pid_t pid = wnck_application_get_pid(app);
+ pid_t pid = wnck_application_get_pid(app);
- if (pid == 0)
- return;
+ if (pid == 0)
+ return;
- static_cast<PrettyTable*>(data)->unregister_application(pid);
+ static_cast<PrettyTable*>(data)->unregister_application(pid);
}
@@ -105,10 +105,10 @@ PrettyTable::on_application_closed(WnckScreen* screen, WnckApplication* app, gpo
void
PrettyTable::unregister_application(pid_t pid)
{
- IconsForPID::iterator it(this->apps.find(pid));
+ IconsForPID::iterator it(this->apps.find(pid));
- if (it != this->apps.end())
- this->apps.erase(it);
+ if (it != this->apps.end())
+ this->apps.erase(it);
}
@@ -116,20 +116,20 @@ PrettyTable::unregister_application(pid_t pid)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_theme(const ProcInfo &info)
{
- return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
}
bool PrettyTable::get_default_icon_name(const string &cmd, string &name)
{
- for (size_t i = 0; i != G_N_ELEMENTS(default_table); ++i) {
- if (default_table[i].command->match(cmd)) {
- name = default_table[i].icon;
- return true;
+ for (size_t i = 0; i != G_N_ELEMENTS(default_table); ++i) {
+ if (default_table[i].command->match(cmd)) {
+ name = default_table[i].icon;
+ return true;
+ }
}
- }
- return false;
+ return false;
}
/*
@@ -142,21 +142,21 @@ bool PrettyTable::get_default_icon_name(const string &cmd, string &name)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_default(const ProcInfo &info)
{
- Glib::RefPtr<Gdk::Pixbuf> pix;
- string name;
-
- if (this->get_default_icon_name(info.name, name)) {
- IconCache::iterator it(this->defaults.find(name));
-
- if (it == this->defaults.end()) {
- pix = this->theme->load_icon(name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
- if (pix)
- this->defaults[name] = pix;
- } else
- pix = it->second;
- }
+ Glib::RefPtr<Gdk::Pixbuf> pix;
+ string name;
+
+ if (this->get_default_icon_name(info.name, name)) {
+ IconCache::iterator it(this->defaults.find(name));
+
+ if (it == this->defaults.end()) {
+ pix = this->theme->load_icon(name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ if (pix)
+ this->defaults[name] = pix;
+ } else
+ pix = it->second;
+ }
- return pix;
+ return pix;
}
@@ -164,14 +164,14 @@ PrettyTable::get_icon_from_default(const ProcInfo &info)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_wnck(const ProcInfo &info)
{
- Glib::RefPtr<Gdk::Pixbuf> icon;
+ Glib::RefPtr<Gdk::Pixbuf> icon;
- IconsForPID::iterator it(this->apps.find(info.pid));
+ IconsForPID::iterator it(this->apps.find(info.pid));
- if (it != this->apps.end())
- icon = it->second;
+ if (it != this->apps.end())
+ icon = it->second;
- return icon;
+ return icon;
}
@@ -179,42 +179,42 @@ PrettyTable::get_icon_from_wnck(const ProcInfo &info)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_name(const ProcInfo &info)
{
- return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
}
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_dummy(const ProcInfo &)
{
- return this->theme->load_icon("application-x-executable", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ return this->theme->load_icon("application-x-executable", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
}
namespace
{
- bool has_kthreadd()
- {
- glibtop_proc_state buf;
- glibtop_get_proc_state(&buf, 2);
-
- return buf.cmd == string("kthreadd");
- }
-
- // @pre: has_kthreadd
- bool is_kthread(const ProcInfo &info)
- {
- return info.pid == 2 or info.ppid == 2;
- }
+ bool has_kthreadd()
+ {
+ glibtop_proc_state buf;
+ glibtop_get_proc_state(&buf, 2);
+
+ return buf.cmd == string("kthreadd");
+ }
+
+ // @pre: has_kthreadd
+ bool is_kthread(const ProcInfo &info)
+ {
+ return info.pid == 2 or info.ppid == 2;
+ }
}
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_for_kernel(const ProcInfo &info)
{
- if (is_kthread(info))
- return this->theme->load_icon("applications-system", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
+ if (is_kthread(info))
+ return this->theme->load_icon("applications-system", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
- return Glib::RefPtr<Gdk::Pixbuf>();
+ return Glib::RefPtr<Gdk::Pixbuf>();
}
@@ -222,41 +222,41 @@ PrettyTable::get_icon_for_kernel(const ProcInfo &info)
void
PrettyTable::set_icon(ProcInfo &info)
{
- typedef Glib::RefPtr<Gdk::Pixbuf>
- (PrettyTable::*Getter)(const ProcInfo &);
+ typedef Glib::RefPtr<Gdk::Pixbuf>
+ (PrettyTable::*Getter)(const ProcInfo &);
- static std::vector<Getter> getters;
+ static std::vector<Getter> getters;
- if (getters.empty())
+ if (getters.empty())
{
- getters.push_back(&PrettyTable::get_icon_from_wnck);
- getters.push_back(&PrettyTable::get_icon_from_theme);
- getters.push_back(&PrettyTable::get_icon_from_default);
- getters.push_back(&PrettyTable::get_icon_from_name);
- if (has_kthreadd())
- {
- procman_debug("kthreadd is running with PID 2");
- getters.push_back(&PrettyTable::get_icon_for_kernel);
- }
- getters.push_back(&PrettyTable::get_icon_dummy);
+ getters.push_back(&PrettyTable::get_icon_from_wnck);
+ getters.push_back(&PrettyTable::get_icon_from_theme);
+ getters.push_back(&PrettyTable::get_icon_from_default);
+ getters.push_back(&PrettyTable::get_icon_from_name);
+ if (has_kthreadd())
+ {
+ procman_debug("kthreadd is running with PID 2");
+ getters.push_back(&PrettyTable::get_icon_for_kernel);
+ }
+ getters.push_back(&PrettyTable::get_icon_dummy);
}
- Glib::RefPtr<Gdk::Pixbuf> icon;
-
- for (size_t i = 0; not icon and i < getters.size(); ++i) {
- try {
- icon = (this->*getters[i])(info);
- }
- catch (std::exception& e) {
- g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what());
- continue;
- }
- catch (Glib::Exception& e) {
- g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what().c_str());
- continue;
+ Glib::RefPtr<Gdk::Pixbuf> icon;
+
+ for (size_t i = 0; not icon and i < getters.size(); ++i) {
+ try {
+ icon = (this->*getters[i])(info);
+ }
+ catch (std::exception& e) {
+ g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what());
+ continue;
+ }
+ catch (Glib::Exception& e) {
+ g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what().c_str());
+ continue;
+ }
}
- }
- info.set_icon(icon);
+ info.set_icon(icon);
}
diff --git a/src/prettytable.h b/src/prettytable.h
index 7884cdd..2109121 100644
--- a/src/prettytable.h
+++ b/src/prettytable.h
@@ -27,35 +27,35 @@ using std::string;
class PrettyTable
{
public:
- PrettyTable();
- ~PrettyTable();
+ PrettyTable();
+ ~PrettyTable();
- void set_icon(ProcInfo &);
+ void set_icon(ProcInfo &);
private:
- static void on_application_opened(WnckScreen* screen, WnckApplication* app, gpointer data);
- static void on_application_closed(WnckScreen* screen, WnckApplication* app, gpointer data);
+ static void on_application_opened(WnckScreen* screen, WnckApplication* app, gpointer data);
+ static void on_application_closed(WnckScreen* screen, WnckApplication* app, gpointer data);
- void register_application(pid_t pid, Glib::RefPtr<Gdk::Pixbuf> icon);
- void unregister_application(pid_t pid);
+ void register_application(pid_t pid, Glib::RefPtr<Gdk::Pixbuf> icon);
+ void unregister_application(pid_t pid);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_from_theme(const ProcInfo &);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_from_default(const ProcInfo &);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_from_wnck(const ProcInfo &);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_from_name(const ProcInfo &);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_for_kernel(const ProcInfo &);
- Glib::RefPtr<Gdk::Pixbuf> get_icon_dummy(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_from_theme(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_from_default(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_from_wnck(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_from_name(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_for_kernel(const ProcInfo &);
+ Glib::RefPtr<Gdk::Pixbuf> get_icon_dummy(const ProcInfo &);
- bool get_default_icon_name(const string &cmd, string &name);
+ bool get_default_icon_name(const string &cmd, string &name);
- typedef std::map<string, Glib::RefPtr<Gdk::Pixbuf> > IconCache;
- typedef std::map<pid_t, Glib::RefPtr<Gdk::Pixbuf> > IconsForPID;
+ typedef std::map<string, Glib::RefPtr<Gdk::Pixbuf> > IconCache;
+ typedef std::map<pid_t, Glib::RefPtr<Gdk::Pixbuf> > IconsForPID;
- IconsForPID apps;
- IconCache defaults;
- procman::IconThemeWrapper theme;
+ IconsForPID apps;
+ IconCache defaults;
+ procman::IconThemeWrapper theme;
};
diff --git a/src/procactions.cpp b/src/procactions.cpp
index 82058e9..a01c150 100644
--- a/src/procactions.cpp
+++ b/src/procactions.cpp
@@ -35,79 +35,79 @@
static void
renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
- const struct ReniceArgs * const args = static_cast<ReniceArgs*>(data);
+ const struct ReniceArgs * const args = static_cast<ReniceArgs*>(data);
- ProcInfo *info = NULL;
- gint error;
- int saved_errno;
- gchar *error_msg;
- GtkWidget *dialog;
+ ProcInfo *info = NULL;
+ gint error;
+ int saved_errno;
+ gchar *error_msg;
+ GtkWidget *dialog;
- gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
+ gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
- if (!info)
- return;
+ if (!info)
+ return;
- error = setpriority (PRIO_PROCESS, info->pid, args->nice_value);
+ error = setpriority (PRIO_PROCESS, info->pid, args->nice_value);
- /* success */
- if(error != -1) return;
+ /* success */
+ if(error != -1) return;
- saved_errno = errno;
+ saved_errno = errno;
- /* need to be root */
- if(errno == EPERM || errno == EACCES) {
- gboolean success;
+ /* need to be root */
+ if(errno == EPERM || errno == EACCES) {
+ gboolean success;
- success = procdialog_create_root_password_dialog (
- PROCMAN_ACTION_RENICE, args->procdata, info->pid,
- args->nice_value);
+ success = procdialog_create_root_password_dialog (
+ PROCMAN_ACTION_RENICE, args->procdata, info->pid,
+ args->nice_value);
- if(success) return;
+ if(success) return;
- if(errno) {
- saved_errno = errno;
- }
- }
+ if(errno) {
+ saved_errno = errno;
+ }
+ }
- /* failed */
- error_msg = g_strdup_printf (
- _("Cannot change the priority of process with pid %d to %d.\n"
- "%s"),
- info->pid, args->nice_value, g_strerror(saved_errno));
+ /* failed */
+ error_msg = g_strdup_printf (
+ _("Cannot change the priority of process with pid %d to %d.\n"
+ "%s"),
+ info->pid, args->nice_value, g_strerror(saved_errno));
- dialog = gtk_message_dialog_new (
- NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", error_msg);
+ dialog = gtk_message_dialog_new (
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", error_msg);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_free (error_msg);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_free (error_msg);
}
void
renice (ProcData *procdata, int nice)
{
- struct ReniceArgs args = { procdata, nice };
+ struct ReniceArgs args = { procdata, nice };
- /* EEEK - ugly hack - make sure the table is not updated as a crash
- ** occurs if you first kill a process and the tree node is removed while
- ** still in the foreach function
- */
- g_source_remove(procdata->timeout);
+ /* EEEK - ugly hack - make sure the table is not updated as a crash
+ ** occurs if you first kill a process and the tree node is removed while
+ ** still in the foreach function
+ */
+ g_source_remove(procdata->timeout);
- gtk_tree_selection_selected_foreach(procdata->selection, renice_single_process,
- &args);
+ gtk_tree_selection_selected_foreach(procdata->selection, renice_single_process,
+ &args);
- procdata->timeout = g_timeout_add(procdata->config.update_interval,
- cb_timeout,
- procdata);
+ procdata->timeout = g_timeout_add(procdata->config.update_interval,
+ cb_timeout,
+ procdata);
- proctable_update_all (procdata);
+ proctable_update_all (procdata);
}
@@ -116,75 +116,75 @@ renice (ProcData *procdata, int nice)
static void
kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
- const struct KillArgs * const args = static_cast<KillArgs*>(data);
- char *error_msg;
- ProcInfo *info;
- int error;
- int saved_errno;
- GtkWidget *dialog;
+ const struct KillArgs * const args = static_cast<KillArgs*>(data);
+ char *error_msg;
+ ProcInfo *info;
+ int error;
+ int saved_errno;
+ GtkWidget *dialog;
- gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
+ gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
- if (!info)
- return;
+ if (!info)
+ return;
- error = kill (info->pid, args->signal);
+ error = kill (info->pid, args->signal);
- /* success */
- if(error != -1) return;
+ /* success */
+ if(error != -1) return;
- saved_errno = errno;
+ saved_errno = errno;
- /* need to be root */
- if(errno == EPERM) {
- gboolean success;
+ /* need to be root */
+ if(errno == EPERM) {
+ gboolean success;
- success = procdialog_create_root_password_dialog (
- PROCMAN_ACTION_KILL, args->procdata, info->pid,
- args->signal);
+ success = procdialog_create_root_password_dialog (
+ PROCMAN_ACTION_KILL, args->procdata, info->pid,
+ args->signal);
- if(success) return;
+ if(success) return;
- if(errno) {
- saved_errno = errno;
- }
- }
+ if(errno) {
+ saved_errno = errno;
+ }
+ }
- /* failed */
- error_msg = g_strdup_printf (
- _("Cannot kill process with pid %d with signal %d.\n"
- "%s"),
- info->pid, args->signal, g_strerror(saved_errno));
+ /* failed */
+ error_msg = g_strdup_printf (
+ _("Cannot kill process with pid %d with signal %d.\n"
+ "%s"),
+ info->pid, args->signal, g_strerror(saved_errno));
- dialog = gtk_message_dialog_new (
- NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", error_msg);
+ dialog = gtk_message_dialog_new (
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", error_msg);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_free (error_msg);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_free (error_msg);
}
void
kill_process (ProcData *procdata, int sig)
{
- struct KillArgs args = { procdata, sig };
+ struct KillArgs args = { procdata, sig };
- /* EEEK - ugly hack - make sure the table is not updated as a crash
- ** occurs if you first kill a process and the tree node is removed while
- ** still in the foreach function
- */
- g_source_remove (procdata->timeout);
+ /* EEEK - ugly hack - make sure the table is not updated as a crash
+ ** occurs if you first kill a process and the tree node is removed while
+ ** still in the foreach function
+ */
+ g_source_remove (procdata->timeout);
- gtk_tree_selection_selected_foreach (procdata->selection, kill_single_process,
- &args);
+ gtk_tree_selection_selected_foreach (procdata->selection, kill_single_process,
+ &args);
- procdata->timeout = g_timeout_add (procdata->config.update_interval,
- cb_timeout,
- procdata);
- proctable_update_all (procdata);
+ procdata->timeout = g_timeout_add (procdata->config.update_interval,
+ cb_timeout,
+ procdata);
+ proctable_update_all (procdata);
}
diff --git a/src/procactions.h b/src/procactions.h
index 97288af..060e692 100644
--- a/src/procactions.h
+++ b/src/procactions.h
@@ -20,9 +20,9 @@
#define _PROCACTIONS_H_
#include "procman.h"
-
-void renice (ProcData *procdata, int nice);
-void kill_process (ProcData *procdata, int sig);
+
+void renice (ProcData *procdata, int nice);
+void kill_process (ProcData *procdata, int sig);
#endif
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index b61fd35..b35265d 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -43,228 +43,228 @@ static gint new_nice_value = 0;
static void
kill_dialog_button_pressed (GtkDialog *dialog, gint id, gpointer data)
{
- struct KillArgs *kargs = static_cast<KillArgs*>(data);
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ struct KillArgs *kargs = static_cast<KillArgs*>(data);
- if (id == GTK_RESPONSE_OK)
- kill_process (kargs->procdata, kargs->signal);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
- g_free (kargs);
+ if (id == GTK_RESPONSE_OK)
+ kill_process (kargs->procdata, kargs->signal);
+
+ g_free (kargs);
}
void
procdialog_create_kill_dialog (ProcData *procdata, int signal)
{
- GtkWidget *kill_alert_dialog;
- gchar *primary, *secondary, *button_text;
- struct KillArgs *kargs;
-
- kargs = g_new(KillArgs, 1);
- kargs->procdata = procdata;
- kargs->signal = signal;
-
-
- if (signal == SIGKILL) {
- /*xgettext: primary alert message*/
- primary = _("Kill the selected process?");
- /*xgettext: secondary alert message*/
- secondary = _("Killing a process may destroy data, break the "
- "session or introduce a security risk. "
- "Only unresponding processes should be killed.");
- button_text = _("_Kill Process");
- }
- else {
- /*xgettext: primary alert message*/
- primary = _("End the selected process?");
- /*xgettext: secondary alert message*/
- secondary = _("Ending a process may destroy data, break the "
- "session or introduce a security risk. "
- "Only unresponding processes should be ended.");
- button_text = _("_End Process");
- }
-
- kill_alert_dialog = gtk_message_dialog_new (GTK_WINDOW (procdata->app),
- static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_NONE,
- "%s",
- primary);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (kill_alert_dialog),
- "%s",
- secondary);
-
- gtk_dialog_add_buttons (GTK_DIALOG (kill_alert_dialog),
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- button_text, GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response (GTK_DIALOG (kill_alert_dialog),
- GTK_RESPONSE_CANCEL);
-
- g_signal_connect (G_OBJECT (kill_alert_dialog), "response",
- G_CALLBACK (kill_dialog_button_pressed), kargs);
-
- gtk_widget_show_all (kill_alert_dialog);
+ GtkWidget *kill_alert_dialog;
+ gchar *primary, *secondary, *button_text;
+ struct KillArgs *kargs;
+
+ kargs = g_new(KillArgs, 1);
+ kargs->procdata = procdata;
+ kargs->signal = signal;
+
+
+ if (signal == SIGKILL) {
+ /*xgettext: primary alert message*/
+ primary = _("Kill the selected process?");
+ /*xgettext: secondary alert message*/
+ secondary = _("Killing a process may destroy data, break the "
+ "session or introduce a security risk. "
+ "Only unresponding processes should be killed.");
+ button_text = _("_Kill Process");
+ }
+ else {
+ /*xgettext: primary alert message*/
+ primary = _("End the selected process?");
+ /*xgettext: secondary alert message*/
+ secondary = _("Ending a process may destroy data, break the "
+ "session or introduce a security risk. "
+ "Only unresponding processes should be ended.");
+ button_text = _("_End Process");
+ }
+
+ kill_alert_dialog = gtk_message_dialog_new (GTK_WINDOW (procdata->app),
+ static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ "%s",
+ primary);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (kill_alert_dialog),
+ "%s",
+ secondary);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (kill_alert_dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ button_text, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (kill_alert_dialog),
+ GTK_RESPONSE_CANCEL);
+
+ g_signal_connect (G_OBJECT (kill_alert_dialog), "response",
+ G_CALLBACK (kill_dialog_button_pressed), kargs);
+
+ gtk_widget_show_all (kill_alert_dialog);
}
static gchar *
get_nice_level (gint nice)
{
- if (nice < -7)
- return _("(Very High Priority)");
- else if (nice < -2)
- return _("(High Priority)");
- else if (nice < 3)
- return _("(Normal Priority)");
- else if (nice < 7)
- return _("(Low Priority)");
- else
- return _("(Very Low Priority)");
+ if (nice < -7)
+ return _("(Very High Priority)");
+ else if (nice < -2)
+ return _("(High Priority)");
+ else if (nice < 3)
+ return _("(Normal Priority)");
+ else if (nice < 7)
+ return _("(Low Priority)");
+ else
+ return _("(Very Low Priority)");
}
static void
renice_scale_changed (GtkAdjustment *adj, gpointer data)
{
- GtkWidget *label = GTK_WIDGET (data);
-
- new_nice_value = int(gtk_adjustment_get_value (adj));
- gtk_label_set_text (GTK_LABEL (label), get_nice_level (new_nice_value));
-
+ GtkWidget *label = GTK_WIDGET (data);
+
+ new_nice_value = int(gtk_adjustment_get_value (adj));
+ gtk_label_set_text (GTK_LABEL (label), get_nice_level (new_nice_value));
+
}
static void
renice_dialog_button_pressed (GtkDialog *dialog, gint id, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
-
- if (id == 100) {
- if (new_nice_value == -100)
- return;
- renice(procdata, new_nice_value);
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
- renice_dialog = NULL;
+ ProcData *procdata = static_cast<ProcData*>(data);
+
+ if (id == 100) {
+ if (new_nice_value == -100)
+ return;
+ renice(procdata, new_nice_value);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ renice_dialog = NULL;
}
void
procdialog_create_renice_dialog (ProcData *procdata)
{
- ProcInfo *info = procdata->selected_process;
- GtkWidget *dialog = NULL;
- GtkWidget *dialog_vbox;
- GtkWidget *vbox;
- GtkWidget *label;
- GtkWidget *priority_label;
- GtkWidget *table;
+ ProcInfo *info = procdata->selected_process;
+ GtkWidget *dialog = NULL;
+ GtkWidget *dialog_vbox;
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GtkWidget *priority_label;
+ GtkWidget *table;
#if GTK_CHECK_VERSION(3,0,0)
- GtkAdjustment *renice_adj;
+ GtkAdjustment *renice_adj;
#else
- GtkObject *renice_adj;
+ GtkObject *renice_adj;
#endif
- GtkWidget *hscale;
- GtkWidget *button;
- GtkWidget *icon;
- gchar *text;
-
- if (renice_dialog)
- return;
-
- if (!info)
- return;
-
- dialog = gtk_dialog_new_with_buttons (_("Change Priority"), NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
- renice_dialog = dialog;
- gtk_window_set_resizable (GTK_WINDOW (renice_dialog), FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (renice_dialog), 5);
-
- button = gtk_button_new_with_mnemonic (_("Change _Priority"));
- gtk_widget_set_can_default (button, TRUE);
-
- icon = gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), icon);
-
- gtk_dialog_add_action_widget (GTK_DIALOG (renice_dialog), button, 100);
- gtk_dialog_set_default_response (GTK_DIALOG (renice_dialog), 100);
- new_nice_value = -100;
-
- dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_box_set_spacing (GTK_BOX (dialog_vbox), 2);
- gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
-
- vbox = gtk_vbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (dialog_vbox), vbox, TRUE, TRUE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
- table = gtk_table_new (2, 2, FALSE);
- gtk_table_set_col_spacings (GTK_TABLE(table), 12);
- gtk_table_set_row_spacings (GTK_TABLE(table), 6);
- gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Nice value:"));
- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 2,
- GTK_FILL, GTK_FILL, 0, 0);
-
- renice_adj = gtk_adjustment_new (info->nice, RENICE_VAL_MIN, RENICE_VAL_MAX, 1, 1, 0);
- new_nice_value = 0;
+ GtkWidget *hscale;
+ GtkWidget *button;
+ GtkWidget *icon;
+ gchar *text;
+
+ if (renice_dialog)
+ return;
+
+ if (!info)
+ return;
+
+ dialog = gtk_dialog_new_with_buttons (_("Change Priority"), NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+ renice_dialog = dialog;
+ gtk_window_set_resizable (GTK_WINDOW (renice_dialog), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (renice_dialog), 5);
+
+ button = gtk_button_new_with_mnemonic (_("Change _Priority"));
+ gtk_widget_set_can_default (button, TRUE);
+
+ icon = gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (button), icon);
+
+ gtk_dialog_add_action_widget (GTK_DIALOG (renice_dialog), button, 100);
+ gtk_dialog_set_default_response (GTK_DIALOG (renice_dialog), 100);
+ new_nice_value = -100;
+
+ dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_box_set_spacing (GTK_BOX (dialog_vbox), 2);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
+
+ vbox = gtk_vbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), vbox, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+
+ table = gtk_table_new (2, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE(table), 12);
+ gtk_table_set_row_spacings (GTK_TABLE(table), 6);
+ gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Nice value:"));
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 2,
+ GTK_FILL, GTK_FILL, 0, 0);
+
+ renice_adj = gtk_adjustment_new (info->nice, RENICE_VAL_MIN, RENICE_VAL_MAX, 1, 1, 0);
+ new_nice_value = 0;
#if GTK_CHECK_VERSION (3, 0, 0)
- hscale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, renice_adj);
+ hscale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, renice_adj);
#else
- hscale = gtk_hscale_new (GTK_ADJUSTMENT (renice_adj));
+ hscale = gtk_hscale_new (GTK_ADJUSTMENT (renice_adj));
#endif
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), hscale);
- gtk_scale_set_digits (GTK_SCALE (hscale), 0);
- gtk_table_attach (GTK_TABLE (table), hscale, 1, 2, 0, 1,
- static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-
- priority_label = gtk_label_new (get_nice_level (info->nice));
- gtk_table_attach (GTK_TABLE (table), priority_label, 1, 2, 1, 2,
- GTK_FILL, GTK_FILL, 0, 0);
-
- text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
- _("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
- "</i></small>", NULL);
- label = gtk_label_new (_(text));
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- g_free (text);
-
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (renice_dialog_button_pressed), procdata);
- g_signal_connect (G_OBJECT (renice_adj), "value_changed",
- G_CALLBACK (renice_scale_changed), priority_label);
-
- gtk_widget_show_all (dialog);
-
-
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), hscale);
+ gtk_scale_set_digits (GTK_SCALE (hscale), 0);
+ gtk_table_attach (GTK_TABLE (table), hscale, 1, 2, 0, 1,
+ static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
+
+ priority_label = gtk_label_new (get_nice_level (info->nice));
+ gtk_table_attach (GTK_TABLE (table), priority_label, 1, 2, 1, 2,
+ GTK_FILL, GTK_FILL, 0, 0);
+
+ text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
+ _("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
+ "</i></small>", NULL);
+ label = gtk_label_new (_(text));
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+ g_free (text);
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (renice_dialog_button_pressed), procdata);
+ g_signal_connect (G_OBJECT (renice_adj), "value_changed",
+ G_CALLBACK (renice_scale_changed), priority_label);
+
+ gtk_widget_show_all (dialog);
+
+
}
static void
prefs_dialog_button_pressed (GtkDialog *dialog, gint id, gpointer data)
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- prefs_dialog = NULL;
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ prefs_dialog = NULL;
}
static void
show_kill_dialog_toggled (GtkToggleButton *button, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
-
- gboolean toggled;
-
- toggled = gtk_toggle_button_get_active (button);
-
- g_settings_set_boolean (settings, "kill-dialog", toggled);
-
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
+
+ gboolean toggled;
+
+ toggled = gtk_toggle_button_get_active (button);
+
+ g_settings_set_boolean (settings, "kill-dialog", toggled);
+
}
@@ -272,22 +272,22 @@ show_kill_dialog_toggled (GtkToggleButton *button, gpointer data)
static void
solaris_mode_toggled(GtkToggleButton *button, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
- gboolean toggled;
- toggled = gtk_toggle_button_get_active(button);
- g_settings_set_boolean(settings, procman::settings::solaris_mode.c_str(), toggled);
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
+ gboolean toggled;
+ toggled = gtk_toggle_button_get_active(button);
+ g_settings_set_boolean(settings, procman::settings::solaris_mode.c_str(), toggled);
}
static void
network_in_bits_toggled(GtkToggleButton *button, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
- gboolean toggled;
- toggled = gtk_toggle_button_get_active(button);
- g_settings_set_boolean(settings, procman::settings::network_in_bits.c_str(), toggled);
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
+ gboolean toggled;
+ toggled = gtk_toggle_button_get_active(button);
+ g_settings_set_boolean(settings, procman::settings::network_in_bits.c_str(), toggled);
}
@@ -295,14 +295,14 @@ network_in_bits_toggled(GtkToggleButton *button, gpointer data)
static void
smooth_refresh_toggled(GtkToggleButton *button, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
- gboolean toggled;
+ gboolean toggled;
- toggled = gtk_toggle_button_get_active(button);
+ toggled = gtk_toggle_button_get_active(button);
- g_settings_set_boolean(settings, SmoothRefresh::KEY.c_str(), toggled);
+ g_settings_set_boolean(settings, SmoothRefresh::KEY.c_str(), toggled);
}
@@ -310,43 +310,43 @@ smooth_refresh_toggled(GtkToggleButton *button, gpointer data)
static void
show_all_fs_toggled (GtkToggleButton *button, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
- GSettings *settings = procdata->settings;
+ ProcData *procdata = static_cast<ProcData*>(data);
+ GSettings *settings = procdata->settings;
- gboolean toggled;
+ gboolean toggled;
- toggled = gtk_toggle_button_get_active (button);
+ toggled = gtk_toggle_button_get_active (button);
- g_settings_set_boolean (settings, "show-all-fs", toggled);
+ g_settings_set_boolean (settings, "show-all-fs", toggled);
}
class SpinButtonUpdater
{
public:
- SpinButtonUpdater(const string& key)
- : key(key)
- { }
+ SpinButtonUpdater(const string& key)
+ : key(key)
+ { }
- static gboolean callback(GtkWidget *widget, GdkEventFocus *event, gpointer data)
- {
- SpinButtonUpdater* updater = static_cast<SpinButtonUpdater*>(data);
- updater->update(GTK_SPIN_BUTTON(widget));
- return FALSE;
- }
+ static gboolean callback(GtkWidget *widget, GdkEventFocus *event, gpointer data)
+ {
+ SpinButtonUpdater* updater = static_cast<SpinButtonUpdater*>(data);
+ updater->update(GTK_SPIN_BUTTON(widget));
+ return FALSE;
+ }
private:
- void update(GtkSpinButton* spin)
- {
- int new_value = int(1000 * gtk_spin_button_get_value(spin));
- g_settings_set_int(ProcData::get_instance()->settings,
- this->key.c_str(), new_value);
+ void update(GtkSpinButton* spin)
+ {
+ int new_value = int(1000 * gtk_spin_button_get_value(spin));
+ g_settings_set_int(ProcData::get_instance()->settings,
+ this->key.c_str(), new_value);
- procman_debug("set %s to %d", this->key.c_str(), new_value);
- }
+ procman_debug("set %s to %d", this->key.c_str(), new_value);
+ }
- const string key;
+ const string key;
};
@@ -355,445 +355,445 @@ private:
static void
field_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
{
- GtkTreeModel *model = static_cast<GtkTreeModel*>(data);
- GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
- GtkTreeIter iter;
- GtkTreeViewColumn *column;
- gboolean toggled;
-
- if (!path)
- return;
-
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, 2, &column, -1);
- toggled = gtk_cell_renderer_toggle_get_active (cell);
-
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, !toggled, -1);
- gtk_tree_view_column_set_visible (column, !toggled);
-
- gtk_tree_path_free (path);
+ GtkTreeModel *model = static_cast<GtkTreeModel*>(data);
+ GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+ GtkTreeIter iter;
+ GtkTreeViewColumn *column;
+ gboolean toggled;
+
+ if (!path)
+ return;
+
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ gtk_tree_model_get (model, &iter, 2, &column, -1);
+ toggled = gtk_cell_renderer_toggle_get_active (cell);
+
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, !toggled, -1);
+ gtk_tree_view_column_set_visible (column, !toggled);
+
+ gtk_tree_path_free (path);
}
static GtkWidget *
create_field_page(GtkWidget *tree, const char* text)
{
- GtkWidget *vbox;
- GtkWidget *scrolled;
- GtkWidget *label;
- GtkWidget *treeview;
- GList *it, *columns;
- GtkListStore *model;
- GtkTreeViewColumn *column;
- GtkCellRenderer *cell;
-
- vbox = gtk_vbox_new (FALSE, 6);
-
- label = gtk_label_new_with_mnemonic (text);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN);
- gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
-
- model = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER);
-
- treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
- gtk_container_add (GTK_CONTAINER (scrolled), treeview);
- g_object_unref (G_OBJECT (model));
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), treeview);
-
- column = gtk_tree_view_column_new ();
-
- cell = gtk_cell_renderer_toggle_new ();
- gtk_tree_view_column_pack_start (column, cell, FALSE);
- gtk_tree_view_column_set_attributes (column, cell,
- "active", 0,
- NULL);
- g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (field_toggled), model);
- gtk_tree_view_column_set_clickable (column, TRUE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
-
- column = gtk_tree_view_column_new ();
-
- cell = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, cell, FALSE);
- gtk_tree_view_column_set_attributes (column, cell,
- "text", 1,
- NULL);
-
- gtk_tree_view_column_set_title (column, "Not Shown");
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
-
- columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
-
- for(it = columns; it; it = it->next)
- {
- GtkTreeViewColumn *column = static_cast<GtkTreeViewColumn*>(it->data);
- GtkTreeIter iter;
- const gchar *title;
- gboolean visible;
-
- title = gtk_tree_view_column_get_title (column);
- if (!title)
- title = _("Icon");
-
- visible = gtk_tree_view_column_get_visible (column);
-
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter, 0, visible, 1, title, 2, column,-1);
- }
-
- g_list_free(columns);
-
- return vbox;
+ GtkWidget *vbox;
+ GtkWidget *scrolled;
+ GtkWidget *label;
+ GtkWidget *treeview;
+ GList *it, *columns;
+ GtkListStore *model;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *cell;
+
+ vbox = gtk_vbox_new (FALSE, 6);
+
+ label = gtk_label_new_with_mnemonic (text);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN);
+ gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
+
+ model = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER);
+
+ treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+ gtk_container_add (GTK_CONTAINER (scrolled), treeview);
+ g_object_unref (G_OBJECT (model));
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), treeview);
+
+ column = gtk_tree_view_column_new ();
+
+ cell = gtk_cell_renderer_toggle_new ();
+ gtk_tree_view_column_pack_start (column, cell, FALSE);
+ gtk_tree_view_column_set_attributes (column, cell,
+ "active", 0,
+ NULL);
+ g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (field_toggled), model);
+ gtk_tree_view_column_set_clickable (column, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+ column = gtk_tree_view_column_new ();
+
+ cell = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (column, cell, FALSE);
+ gtk_tree_view_column_set_attributes (column, cell,
+ "text", 1,
+ NULL);
+
+ gtk_tree_view_column_set_title (column, "Not Shown");
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
+
+ columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
+
+ for(it = columns; it; it = it->next)
+ {
+ GtkTreeViewColumn *column = static_cast<GtkTreeViewColumn*>(it->data);
+ GtkTreeIter iter;
+ const gchar *title;
+ gboolean visible;
+
+ title = gtk_tree_view_column_get_title (column);
+ if (!title)
+ title = _("Icon");
+
+ visible = gtk_tree_view_column_get_visible (column);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, visible, 1, title, 2, column,-1);
+ }
+
+ g_list_free(columns);
+
+ return vbox;
}
void
procdialog_create_preferences_dialog (ProcData *procdata)
{
- static GtkWidget *dialog = NULL;
-
- typedef SpinButtonUpdater SBU;
-
- static SBU interval_updater("update-interval");
- static SBU graph_interval_updater("graph-update-interval");
- static SBU disks_interval_updater("disks-interval");
-
- GtkWidget *notebook;
- GtkWidget *proc_box;
- GtkWidget *sys_box;
- GtkWidget *main_vbox;
- GtkWidget *vbox, *vbox2, *vbox3;
- GtkWidget *hbox, *hbox2, *hbox3;
- GtkWidget *label;
- GtkAdjustment *adjustment;
- GtkWidget *spin_button;
- GtkWidget *check_button;
- GtkWidget *tab_label;
- GtkWidget *smooth_button;
- GtkSizeGroup *size;
- gfloat update;
- gchar *tmp;
-
- if (prefs_dialog)
- return;
-
- size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-
- dialog = gtk_dialog_new_with_buttons (_("System Monitor Preferences"),
- GTK_WINDOW (procdata->app),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- NULL);
- /* FIXME: we should not declare the window size, but let it's */
- /* driven by window childs. The problem is that the fields list */
- /* have to show at least 4 items to respect HIG. I don't know */
- /* any function to set list height by contents/items inside it. */
- gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 420);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- prefs_dialog = dialog;
-
- main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_box_set_spacing (GTK_BOX (main_vbox), 2);
-
- notebook = gtk_notebook_new ();
- gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
- gtk_box_pack_start (GTK_BOX (main_vbox), notebook, TRUE, TRUE, 0);
-
- proc_box = gtk_vbox_new (FALSE, 18);
- gtk_container_set_border_width (GTK_CONTAINER (proc_box), 12);
- tab_label = gtk_label_new (_("Processes"));
- gtk_widget_show (tab_label);
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), proc_box, tab_label);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (proc_box), vbox, FALSE, FALSE, 0);
-
- tmp = g_strdup_printf ("<b>%s</b>", _("Behavior"));
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_markup (GTK_LABEL (label), tmp);
- g_free (tmp);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- vbox2 = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
-
- hbox2 = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
-
- hbox3 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
-
- update = (gfloat) procdata->config.update_interval;
- adjustment = (GtkAdjustment *) gtk_adjustment_new(update / 1000.0,
- MIN_UPDATE_INTERVAL / 1000,
- MAX_UPDATE_INTERVAL / 1000,
- 0.25,
- 1.0,
- 1.0);
-
- spin_button = gtk_spin_button_new (adjustment, 1.0, 2);
- gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
- g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
- G_CALLBACK (SBU::callback), &interval_updater);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
-
-
- hbox2 = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
-
- smooth_button = gtk_check_button_new_with_mnemonic(_("Enable _smooth refresh"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(smooth_button),
- g_settings_get_boolean(procdata->settings,
- SmoothRefresh::KEY.c_str()));
- g_signal_connect(G_OBJECT(smooth_button), "toggled",
- G_CALLBACK(smooth_refresh_toggled), procdata);
- gtk_box_pack_start(GTK_BOX(hbox2), smooth_button, TRUE, TRUE, 0);
-
-
-
- hbox2 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
-
- check_button = gtk_check_button_new_with_mnemonic (_("Alert before ending or _killing processes"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
- procdata->config.show_kill_warning);
- g_signal_connect (G_OBJECT (check_button), "toggled",
- G_CALLBACK (show_kill_dialog_toggled), procdata);
- gtk_box_pack_start (GTK_BOX (hbox2), check_button, FALSE, FALSE, 0);
-
-
-
-
- hbox2 = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
-
- GtkWidget *solaris_button = gtk_check_button_new_with_mnemonic(_("Divide CPU usage by CPU count"));
- gtk_widget_set_tooltip_text(solaris_button, _("Solaris mode"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(solaris_button),
- g_settings_get_boolean(procdata->settings,
- procman::settings::solaris_mode.c_str()));
- g_signal_connect(G_OBJECT(solaris_button), "toggled",
- G_CALLBACK(solaris_mode_toggled), procdata);
- gtk_box_pack_start(GTK_BOX(hbox2), solaris_button, TRUE, TRUE, 0);
-
-
-
-
- hbox2 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (proc_box), vbox, TRUE, TRUE, 0);
-
- tmp = g_strdup_printf ("<b>%s</b>", _("Information Fields"));
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_markup (GTK_LABEL (label), tmp);
- g_free (tmp);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- vbox2 = create_field_page (procdata->tree, _("Process i_nformation shown in list:"));
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
-
- sys_box = gtk_vbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (sys_box), 12);
- tab_label = gtk_label_new (_("Resources"));
- gtk_widget_show (tab_label);
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, tab_label);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (sys_box), vbox, FALSE, FALSE, 0);
-
- tmp = g_strdup_printf ("<b>%s</b>", _("Graphs"));
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_markup (GTK_LABEL (label), tmp);
- g_free (tmp);
- gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- vbox2 = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
-
- hbox2 = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
- gtk_size_group_add_widget (size, label);
-
- hbox3 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
-
- update = (gfloat) procdata->config.graph_update_interval;
- adjustment = (GtkAdjustment *) gtk_adjustment_new(update / 1000.0, 0.25,
- 100.0, 0.25, 1.0, 1.0);
- spin_button = gtk_spin_button_new (adjustment, 1.0, 2);
- g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
- G_CALLBACK(SBU::callback),
- &graph_interval_updater);
- gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
-
-
- GtkWidget *bits_button;
- bits_button = gtk_check_button_new_with_mnemonic(_("Show network speed in bits"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bits_button),
- g_settings_get_boolean(procdata->settings,
- procman::settings::network_in_bits.c_str()));
-
- g_signal_connect(G_OBJECT(bits_button), "toggled",
- G_CALLBACK(network_in_bits_toggled), procdata);
- gtk_box_pack_start(GTK_BOX(vbox2), bits_button, TRUE, TRUE, 0);
-
-
-
- hbox2 = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0);
-
- /*
- * Devices
- */
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
- tab_label = gtk_label_new (_("File Systems"));
- gtk_widget_show (tab_label);
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox, tab_label);
-
- tmp = g_strdup_printf ("<b>%s</b>", _("File Systems"));
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_markup (GTK_LABEL (label), tmp);
- g_free (tmp);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- vbox2 = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
-
- hbox2 = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
-
- label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
-
- hbox3 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
-
- update = (gfloat) procdata->config.disks_update_interval;
- adjustment = (GtkAdjustment *) gtk_adjustment_new (update / 1000.0, 1.0,
- 100.0, 1.0, 1.0, 1.0);
- spin_button = gtk_spin_button_new (adjustment, 1.0, 0);
- gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
- g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
- G_CALLBACK(SBU::callback),
- &disks_interval_updater);
-
-
- hbox2 = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
- check_button = gtk_check_button_new_with_mnemonic (_("Show _all filesystems"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
- procdata->config.show_all_fs);
- g_signal_connect (G_OBJECT (check_button), "toggled",
- G_CALLBACK (show_all_fs_toggled), procdata);
- gtk_box_pack_start (GTK_BOX (hbox2), check_button, FALSE, FALSE, 0);
-
-
- vbox2 = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
-
- tmp = g_strdup_printf ("<b>%s</b>", _("Information Fields"));
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_label_set_markup (GTK_LABEL (label), tmp);
- g_free (tmp);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
-
- label = gtk_label_new (" ");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- vbox3 = create_field_page (procdata->disk_list, _("File system i_nformation shown in list:"));
- gtk_box_pack_start (GTK_BOX (hbox), vbox3, TRUE, TRUE, 0);
-
- gtk_widget_show_all (dialog);
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (prefs_dialog_button_pressed), procdata);
-
- switch (procdata->config.current_tab) {
- case PROCMAN_TAB_SYSINFO:
- case PROCMAN_TAB_PROCESSES:
- gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
- break;
- case PROCMAN_TAB_RESOURCES:
- gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
- break;
- case PROCMAN_TAB_DISKS:
- gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
- break;
-
- }
+ static GtkWidget *dialog = NULL;
+
+ typedef SpinButtonUpdater SBU;
+
+ static SBU interval_updater("update-interval");
+ static SBU graph_interval_updater("graph-update-interval");
+ static SBU disks_interval_updater("disks-interval");
+
+ GtkWidget *notebook;
+ GtkWidget *proc_box;
+ GtkWidget *sys_box;
+ GtkWidget *main_vbox;
+ GtkWidget *vbox, *vbox2, *vbox3;
+ GtkWidget *hbox, *hbox2, *hbox3;
+ GtkWidget *label;
+ GtkAdjustment *adjustment;
+ GtkWidget *spin_button;
+ GtkWidget *check_button;
+ GtkWidget *tab_label;
+ GtkWidget *smooth_button;
+ GtkSizeGroup *size;
+ gfloat update;
+ gchar *tmp;
+
+ if (prefs_dialog)
+ return;
+
+ size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+ dialog = gtk_dialog_new_with_buttons (_("System Monitor Preferences"),
+ GTK_WINDOW (procdata->app),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+ /* FIXME: we should not declare the window size, but let it's */
+ /* driven by window childs. The problem is that the fields list */
+ /* have to show at least 4 items to respect HIG. I don't know */
+ /* any function to set list height by contents/items inside it. */
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 420);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ prefs_dialog = dialog;
+
+ main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_box_set_spacing (GTK_BOX (main_vbox), 2);
+
+ notebook = gtk_notebook_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
+ gtk_box_pack_start (GTK_BOX (main_vbox), notebook, TRUE, TRUE, 0);
+
+ proc_box = gtk_vbox_new (FALSE, 18);
+ gtk_container_set_border_width (GTK_CONTAINER (proc_box), 12);
+ tab_label = gtk_label_new (_("Processes"));
+ gtk_widget_show (tab_label);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), proc_box, tab_label);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (proc_box), vbox, FALSE, FALSE, 0);
+
+ tmp = g_strdup_printf ("<b>%s</b>", _("Behavior"));
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+
+ hbox2 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
+
+ hbox3 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
+
+ update = (gfloat) procdata->config.update_interval;
+ adjustment = (GtkAdjustment *) gtk_adjustment_new(update / 1000.0,
+ MIN_UPDATE_INTERVAL / 1000,
+ MAX_UPDATE_INTERVAL / 1000,
+ 0.25,
+ 1.0,
+ 1.0);
+
+ spin_button = gtk_spin_button_new (adjustment, 1.0, 2);
+ gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
+ g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
+ G_CALLBACK (SBU::callback), &interval_updater);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+
+
+ hbox2 = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
+
+ smooth_button = gtk_check_button_new_with_mnemonic(_("Enable _smooth refresh"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(smooth_button),
+ g_settings_get_boolean(procdata->settings,
+ SmoothRefresh::KEY.c_str()));
+ g_signal_connect(G_OBJECT(smooth_button), "toggled",
+ G_CALLBACK(smooth_refresh_toggled), procdata);
+ gtk_box_pack_start(GTK_BOX(hbox2), smooth_button, TRUE, TRUE, 0);
+
+
+
+ hbox2 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+
+ check_button = gtk_check_button_new_with_mnemonic (_("Alert before ending or _killing processes"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
+ procdata->config.show_kill_warning);
+ g_signal_connect (G_OBJECT (check_button), "toggled",
+ G_CALLBACK (show_kill_dialog_toggled), procdata);
+ gtk_box_pack_start (GTK_BOX (hbox2), check_button, FALSE, FALSE, 0);
+
+
+
+
+ hbox2 = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
+
+ GtkWidget *solaris_button = gtk_check_button_new_with_mnemonic(_("Divide CPU usage by CPU count"));
+ gtk_widget_set_tooltip_text(solaris_button, _("Solaris mode"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(solaris_button),
+ g_settings_get_boolean(procdata->settings,
+ procman::settings::solaris_mode.c_str()));
+ g_signal_connect(G_OBJECT(solaris_button), "toggled",
+ G_CALLBACK(solaris_mode_toggled), procdata);
+ gtk_box_pack_start(GTK_BOX(hbox2), solaris_button, TRUE, TRUE, 0);
+
+
+
+
+ hbox2 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (proc_box), vbox, TRUE, TRUE, 0);
+
+ tmp = g_strdup_printf ("<b>%s</b>", _("Information Fields"));
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ vbox2 = create_field_page (procdata->tree, _("Process i_nformation shown in list:"));
+ gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+
+ sys_box = gtk_vbox_new (FALSE, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (sys_box), 12);
+ tab_label = gtk_label_new (_("Resources"));
+ gtk_widget_show (tab_label);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, tab_label);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (sys_box), vbox, FALSE, FALSE, 0);
+
+ tmp = g_strdup_printf ("<b>%s</b>", _("Graphs"));
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+
+ hbox2 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
+ gtk_size_group_add_widget (size, label);
+
+ hbox3 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
+
+ update = (gfloat) procdata->config.graph_update_interval;
+ adjustment = (GtkAdjustment *) gtk_adjustment_new(update / 1000.0, 0.25,
+ 100.0, 0.25, 1.0, 1.0);
+ spin_button = gtk_spin_button_new (adjustment, 1.0, 2);
+ g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
+ G_CALLBACK(SBU::callback),
+ &graph_interval_updater);
+ gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+
+
+ GtkWidget *bits_button;
+ bits_button = gtk_check_button_new_with_mnemonic(_("Show network speed in bits"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bits_button),
+ g_settings_get_boolean(procdata->settings,
+ procman::settings::network_in_bits.c_str()));
+
+ g_signal_connect(G_OBJECT(bits_button), "toggled",
+ G_CALLBACK(network_in_bits_toggled), procdata);
+ gtk_box_pack_start(GTK_BOX(vbox2), bits_button, TRUE, TRUE, 0);
+
+
+
+ hbox2 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0);
+
+ /*
+ * Devices
+ */
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+ tab_label = gtk_label_new (_("File Systems"));
+ gtk_widget_show (tab_label);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox, tab_label);
+
+ tmp = g_strdup_printf ("<b>%s</b>", _("File Systems"));
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+
+ hbox2 = gtk_hbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Update interval in seconds:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
+
+ hbox3 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
+
+ update = (gfloat) procdata->config.disks_update_interval;
+ adjustment = (GtkAdjustment *) gtk_adjustment_new (update / 1000.0, 1.0,
+ 100.0, 1.0, 1.0, 1.0);
+ spin_button = gtk_spin_button_new (adjustment, 1.0, 0);
+ gtk_box_pack_start (GTK_BOX (hbox3), spin_button, FALSE, FALSE, 0);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
+ g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
+ G_CALLBACK(SBU::callback),
+ &disks_interval_updater);
+
+
+ hbox2 = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
+ check_button = gtk_check_button_new_with_mnemonic (_("Show _all filesystems"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
+ procdata->config.show_all_fs);
+ g_signal_connect (G_OBJECT (check_button), "toggled",
+ G_CALLBACK (show_all_fs_toggled), procdata);
+ gtk_box_pack_start (GTK_BOX (hbox2), check_button, FALSE, FALSE, 0);
+
+
+ vbox2 = gtk_vbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
+
+ tmp = g_strdup_printf ("<b>%s</b>", _("Information Fields"));
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), tmp);
+ g_free (tmp);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+ label = gtk_label_new (" ");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ vbox3 = create_field_page (procdata->disk_list, _("File system i_nformation shown in list:"));
+ gtk_box_pack_start (GTK_BOX (hbox), vbox3, TRUE, TRUE, 0);
+
+ gtk_widget_show_all (dialog);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (prefs_dialog_button_pressed), procdata);
+
+ switch (procdata->config.current_tab) {
+ case PROCMAN_TAB_SYSINFO:
+ case PROCMAN_TAB_PROCESSES:
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
+ break;
+ case PROCMAN_TAB_RESOURCES:
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
+ break;
+ case PROCMAN_TAB_DISKS:
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
+ break;
+
+ }
}
static char *
procman_action_to_command(ProcmanActionType type,
- gint pid,
- gint extra_value)
+ gint pid,
+ gint extra_value)
{
- switch (type) {
- case PROCMAN_ACTION_KILL:
- return g_strdup_printf("kill -s %d %d", extra_value, pid);
- case PROCMAN_ACTION_RENICE:
- return g_strdup_printf("renice %d %d", extra_value, pid);
- default:
- g_assert_not_reached();
- }
+ switch (type) {
+ case PROCMAN_ACTION_KILL:
+ return g_strdup_printf("kill -s %d %d", extra_value, pid);
+ case PROCMAN_ACTION_RENICE:
+ return g_strdup_printf("renice %d %d", extra_value, pid);
+ default:
+ g_assert_not_reached();
+ }
}
@@ -804,24 +804,24 @@ procman_action_to_command(ProcmanActionType type,
*/
gboolean
procdialog_create_root_password_dialog(ProcmanActionType type,
- ProcData *procdata,
- gint pid,
- gint extra_value)
+ ProcData *procdata,
+ gint pid,
+ gint extra_value)
{
- char * command;
- gboolean ret = FALSE;
+ char * command;
+ gboolean ret = FALSE;
- command = procman_action_to_command(type, pid, extra_value);
+ command = procman_action_to_command(type, pid, extra_value);
- procman_debug("Trying to run '%s' as root", command);
+ procman_debug("Trying to run '%s' as root", command);
- if (procman_has_gksu())
- ret = procman_gksu_create_root_password_dialog(command);
- else if (procman_has_matesu())
- ret = procman_matesu_create_root_password_dialog(command);
+ if (procman_has_gksu())
+ ret = procman_gksu_create_root_password_dialog(command);
+ else if (procman_has_matesu())
+ ret = procman_matesu_create_root_password_dialog(command);
- g_free(command);
- return ret;
+ g_free(command);
+ return ret;
}
diff --git a/src/procdialogs.h b/src/procdialogs.h
index 2a15832..60713bb 100644
--- a/src/procdialogs.h
+++ b/src/procdialogs.h
@@ -37,18 +37,18 @@
typedef enum
{
- PROCMAN_ACTION_RENICE,
- PROCMAN_ACTION_KILL
+ PROCMAN_ACTION_RENICE,
+ PROCMAN_ACTION_KILL
} ProcmanActionType;
-void procdialog_create_kill_dialog (ProcData *data, int signal);
-void procdialog_create_renice_dialog (ProcData *data);
-gboolean procdialog_create_root_password_dialog (ProcmanActionType type,
- ProcData *procdata,
- gint pid, gint extra_value);
-void procdialog_create_memmaps_dialog (ProcData *data);
-void procdialog_create_preferences_dialog (ProcData *data);
+void procdialog_create_kill_dialog (ProcData *data, int signal);
+void procdialog_create_renice_dialog (ProcData *data);
+gboolean procdialog_create_root_password_dialog (ProcmanActionType type,
+ ProcData *procdata,
+ gint pid, gint extra_value);
+void procdialog_create_memmaps_dialog (ProcData *data);
+void procdialog_create_preferences_dialog (ProcData *data);
#endif
diff --git a/src/procman.cpp b/src/procman.cpp
index 5860701..a23aded 100644
--- a/src/procman.cpp
+++ b/src/procman.cpp
@@ -62,55 +62,55 @@ ProcData::ProcData()
ProcData* ProcData::get_instance()
{
- static ProcData instance;
- return &instance;
+ static ProcData instance;
+ return &instance;
}
static gboolean
has_key (gchar **keys, const gchar *key)
{
- gchar **loop = keys;
+ gchar **loop = keys;
- while (*loop) {
- if (!strcmp (*loop++, key))
- return TRUE;
- }
+ while (*loop) {
+ if (!strcmp (*loop++, key))
+ return TRUE;
+ }
- return FALSE;
+ 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);
+ 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);
+ g_object_set(G_OBJECT(procdata->tree),
+ "show-expanders", procdata->config.show_tree,
+ NULL);
- proctable_clear_tree (procdata);
+ proctable_clear_tree (procdata);
- proctable_update_all (procdata);
+ proctable_update_all (procdata);
}
static void
solaris_mode_changed_cb(GSettings *settings, const gchar *key, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
+ ProcData *procdata = static_cast<ProcData*>(data);
- procdata->config.solaris_mode = g_settings_get_boolean(settings, key);
- proctable_update_all (procdata);
+ procdata->config.solaris_mode = g_settings_get_boolean(settings, key);
+ proctable_update_all (procdata);
}
static void
network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(data);
+ ProcData *procdata = static_cast<ProcData*>(data);
- procdata->config.network_in_bits = g_settings_get_boolean(settings, key);
- procdata->net_graph->clear_background();
+ procdata->config.network_in_bits = g_settings_get_boolean(settings, key);
+ procdata->net_graph->clear_background();
}
@@ -118,109 +118,109 @@ network_in_bits_changed_cb(GSettings *settings, const gchar *key, gpointer data)
static void
view_as_changed_cb (GSettings *settings, const gchar *key, gpointer data)
{
- ProcData *procdata = static_cast<ProcData*>(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_all (procdata);
+ 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_all (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 *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 *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.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();
- }
+ 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_color_parse (color, &procdata->config.cpu_color[i]);
- procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i];
- break;
- }
- }
- }
- else if (g_str_equal (key, "mem-color")) {
- gdk_color_parse (color, &procdata->config.mem_color);
- procdata->mem_graph->colors.at(0) = procdata->config.mem_color;
- }
- else if (g_str_equal (key, "swap-color")) {
- gdk_color_parse (color, &procdata->config.swap_color);
- procdata->mem_graph->colors.at(1) = procdata->config.swap_color;
- }
- else if (g_str_equal (key, "net-in-color")) {
- gdk_color_parse (color, &procdata->config.net_in_color);
- procdata->net_graph->colors.at(0) = procdata->config.net_in_color;
- }
- else if (g_str_equal (key, "net-out-color")) {
- gdk_color_parse (color, &procdata->config.net_out_color);
- procdata->net_graph->colors.at(1) = procdata->config.net_out_color;
- }
- else {
- g_assert_not_reached();
- }
- g_free (color);
+ 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_color_parse (color, &procdata->config.cpu_color[i]);
+ procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i];
+ break;
+ }
+ }
+ }
+ else if (g_str_equal (key, "mem-color")) {
+ gdk_color_parse (color, &procdata->config.mem_color);
+ procdata->mem_graph->colors.at(0) = procdata->config.mem_color;
+ }
+ else if (g_str_equal (key, "swap-color")) {
+ gdk_color_parse (color, &procdata->config.swap_color);
+ procdata->mem_graph->colors.at(1) = procdata->config.swap_color;
+ }
+ else if (g_str_equal (key, "net-in-color")) {
+ gdk_color_parse (color, &procdata->config.net_in_color);
+ procdata->net_graph->colors.at(0) = procdata->config.net_in_color;
+ }
+ else if (g_str_equal (key, "net-out-color")) {
+ gdk_color_parse (color, &procdata->config.net_out_color);
+ procdata->net_graph->colors.at(1) = procdata->config.net_out_color;
+ }
+ else {
+ g_assert_not_reached();
+ }
+ g_free (color);
}
@@ -228,11 +228,11 @@ color_changed_cb (GSettings *settings, const gchar *key, gpointer data)
static void
show_all_fs_changed_cb (GSettings *settings, const gchar *key, gpointer data)
{
- ProcData * const procdata = static_cast<ProcData*>(data);
+ ProcData * const procdata = static_cast<ProcData*>(data);
- procdata->config.show_all_fs = g_settings_get_boolean (settings, key);
+ procdata->config.show_all_fs = g_settings_get_boolean (settings, key);
- cb_update_disks (data);
+ cb_update_disks (data);
}
@@ -240,129 +240,129 @@ static ProcData *
procman_data_new (GSettings *settings)
{
- ProcData *pd;
- gchar *color;
- gchar **keys;
- gint swidth, sheight;
- gint i;
- glibtop_cpu cpu;
-
- pd = ProcData::get_instance();
-
- pd->config.width = g_settings_get_int (settings, "width");
- pd->config.height = g_settings_get_int (settings, "height");
- 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");
-
- /* Determinie number of cpus since libgtop doesn't really tell you*/
- pd->config.num_cpus = 0;
- glibtop_get_cpu (&cpu);
- pd->frequency = cpu.frequency;
- i=0;
- while (i < GLIBTOP_NCPU && cpu.xcpu_total[i] != 0) {
- pd->config.num_cpus ++;
- i++;
- }
- if (pd->config.num_cpus == 0)
- pd->config.num_cpus = 1;
-
- keys = g_settings_list_keys (settings);
- 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(),
+ ProcData *pd;
+ gchar *color;
+ gchar **keys;
+ gint swidth, sheight;
+ gint i;
+ glibtop_cpu cpu;
+
+ pd = ProcData::get_instance();
+
+ pd->config.width = g_settings_get_int (settings, "width");
+ pd->config.height = g_settings_get_int (settings, "height");
+ 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");
+
+ /* Determinie number of cpus since libgtop doesn't really tell you*/
+ pd->config.num_cpus = 0;
+ glibtop_get_cpu (&cpu);
+ pd->frequency = cpu.frequency;
+ i=0;
+ while (i < GLIBTOP_NCPU && cpu.xcpu_total[i] != 0) {
+ pd->config.num_cpus ++;
+ i++;
+ }
+ if (pd->config.num_cpus == 0)
+ pd->config.num_cpus = 1;
+
+ keys = g_settings_list_keys (settings);
+ 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_color_parse(color, &pd->config.cpu_color[i]);
- 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",
+ gdk_color_parse(color, &pd->config.cpu_color[i]);
+ 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_color_parse(color, &pd->config.mem_color);
+ gdk_color_parse(color, &pd->config.mem_color);
- g_free (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",
+ 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_color_parse(color, &pd->config.swap_color);
- g_free (color);
+ gdk_color_parse(color, &pd->config.swap_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",
+ 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_color_parse(color, &pd->config.net_in_color);
- g_free (color);
+ gdk_color_parse(color, &pd->config.net_in_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",
+ 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_color_parse(color, &pd->config.net_out_color);
- g_free (color);
-
- /* Sanity checks */
- swidth = gdk_screen_width ();
- sheight = gdk_screen_height ();
- 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;
+ gdk_color_parse(color, &pd->config.net_out_color);
+ g_free (color);
+
+ /* Sanity checks */
+ swidth = gdk_screen_width ();
+ sheight = gdk_screen_height ();
+ 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;
}
@@ -370,249 +370,249 @@ static void
procman_free_data (ProcData *procdata)
{
- proctable_free_table (procdata);
- delete procdata->smooth_refresh;
+ proctable_free_table (procdata);
+ delete procdata->smooth_refresh;
}
gboolean
procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child_schema)
{
- GtkTreeModel *model;
- GList *columns, *it;
- gint sort_col;
- GtkSortType order;
-
-
- g_assert(tree);
- g_assert(child_schema);
-
- GSettings *pt_settings = g_settings_get_child (settings, child_schema);
+ GtkTreeModel *model;
+ GList *columns, *it;
+ gint sort_col;
+ GtkSortType order;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
- sort_col = g_settings_get_int (pt_settings, "sort-col");
+ g_assert(tree);
+ g_assert(child_schema);
- order = static_cast<GtkSortType>(g_settings_get_int (pt_settings, "sort-order"));
+ GSettings *pt_settings = g_settings_get_child (settings, child_schema);
- if (sort_col != -1)
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
- sort_col,
- order);
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
- columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
+ sort_col = g_settings_get_int (pt_settings, "sort-col");
- if(!g_strcmp0(child_schema, "proctree"))
- {
- for(it = columns; it; it = it->next)
- {
- GtkTreeViewColumn *column;
- gint width;
- gboolean visible;
- int id;
- gchar *key;
+ order = static_cast<GtkSortType>(g_settings_get_int (pt_settings, "sort-order"));
- column = static_cast<GtkTreeViewColumn*>(it->data);
- id = gtk_tree_view_column_get_sort_column_id (column);
+ if (sort_col != -1)
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+ sort_col,
+ order);
- key = g_strdup_printf ("col-%d-width", id);
- g_settings_get (pt_settings, key, "i", &width);
- g_free (key);
+ columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
- key = g_strdup_printf ("col-%d-visible", id);
- visible = g_settings_get_boolean (pt_settings, key);
- g_free (key);
-
- column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), id);
- if(!column) continue;
- gtk_tree_view_column_set_visible (column, visible);
- if (visible) {
- /* ensure column is really visible */
- width = MAX(width, 10);
- gtk_tree_view_column_set_fixed_width(column, width);
- }
- }
+ if(!g_strcmp0(child_schema, "proctree"))
+ {
+ for(it = columns; it; it = it->next)
+ {
+ GtkTreeViewColumn *column;
+ gint width;
+ gboolean visible;
+ int id;
+ gchar *key;
+
+ column = static_cast<GtkTreeViewColumn*>(it->data);
+ id = gtk_tree_view_column_get_sort_column_id (column);
+
+ key = g_strdup_printf ("col-%d-width", id);
+ g_settings_get (pt_settings, key, "i", &width);
+ g_free (key);
+
+ key = g_strdup_printf ("col-%d-visible", id);
+ visible = g_settings_get_boolean (pt_settings, key);
+ g_free (key);
+
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), id);
+ if(!column) continue;
+ gtk_tree_view_column_set_visible (column, visible);
+ if (visible) {
+ /* ensure column is really visible */
+ width = MAX(width, 10);
+ gtk_tree_view_column_set_fixed_width(column, width);
+ }
+ }
}
if(!g_strcmp0(child_schema, "proctree") ||
!g_strcmp0(child_schema, "disktreenew"))
- {
- GVariant *value;
- GVariantIter iter;
- int sortIndex;
+ {
+ GVariant *value;
+ GVariantIter iter;
+ int sortIndex;
- GSList *order = NULL;
+ GSList *order = NULL;
- value = g_settings_get_value(pt_settings, "columns-order");
- g_variant_iter_init(&iter, value);
+ value = g_settings_get_value(pt_settings, "columns-order");
+ g_variant_iter_init(&iter, value);
- while (g_variant_iter_loop (&iter, "i", &sortIndex))
- order = g_slist_append(order, GINT_TO_POINTER(sortIndex));
+ while (g_variant_iter_loop (&iter, "i", &sortIndex))
+ order = g_slist_append(order, GINT_TO_POINTER(sortIndex));
- proctable_set_columns_order(GTK_TREE_VIEW(tree), order);
+ proctable_set_columns_order(GTK_TREE_VIEW(tree), order);
- g_variant_unref(value);
- g_slist_free(order);
- }
+ g_variant_unref(value);
+ g_slist_free(order);
+ }
g_object_unref(pt_settings);
pt_settings = NULL;
- g_list_free(columns);
+ g_list_free(columns);
- return TRUE;
+ return TRUE;
}
void
procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child_schema)
{
- GtkTreeModel *model;
- GList *it, *columns;
- gint sort_col;
- GtkSortType order;
+ GtkTreeModel *model;
+ GList *it, *columns;
+ gint sort_col;
+ GtkSortType order;
- g_assert(tree);
- g_assert(child_schema);
+ g_assert(tree);
+ g_assert(child_schema);
- GSettings *pt_settings = g_settings_get_child (settings, child_schema);
+ GSettings *pt_settings = g_settings_get_child (settings, child_schema);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
- if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model), &sort_col,
- &order)) {
- g_settings_set_int (pt_settings, "sort-col", sort_col);
- g_settings_set_int (pt_settings, "sort-order", order);
- }
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
+ if (gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model), &sort_col,
+ &order)) {
+ g_settings_set_int (pt_settings, "sort-col", sort_col);
+ g_settings_set_int (pt_settings, "sort-order", order);
+ }
- columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
+ columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));
- if(!g_strcmp0(child_schema, "proctree"))
+ if(!g_strcmp0(child_schema, "proctree"))
{
- for(it = columns; it; it = it->next)
- {
- GtkTreeViewColumn *column;
- gboolean visible;
- gint width;
- gchar *key;
- int id;
-
- column = static_cast<GtkTreeViewColumn*>(it->data);
- id = gtk_tree_view_column_get_sort_column_id (column);
- visible = gtk_tree_view_column_get_visible (column);
- width = gtk_tree_view_column_get_width (column);
-
- key = g_strdup_printf ("col-%d-width", id);
- g_settings_set_int (pt_settings, key, width);
- g_free (key);
-
- key = g_strdup_printf ("col-%d-visible", id);
- g_settings_set_boolean (pt_settings, key, visible);
- g_free (key);
- }
+ for(it = columns; it; it = it->next)
+ {
+ GtkTreeViewColumn *column;
+ gboolean visible;
+ gint width;
+ gchar *key;
+ int id;
+
+ column = static_cast<GtkTreeViewColumn*>(it->data);
+ id = gtk_tree_view_column_get_sort_column_id (column);
+ visible = gtk_tree_view_column_get_visible (column);
+ width = gtk_tree_view_column_get_width (column);
+
+ key = g_strdup_printf ("col-%d-width", id);
+ g_settings_set_int (pt_settings, key, width);
+ g_free (key);
+
+ key = g_strdup_printf ("col-%d-visible", id);
+ g_settings_set_boolean (pt_settings, key, visible);
+ g_free (key);
+ }
}
if(!g_strcmp0(child_schema, "proctree") || !g_strcmp0(child_schema, "disktreenew"))
- {
- GSList *order;
- GSList *order_node;
- GVariantBuilder *builder;
- GVariant *order_variant;
+ {
+ GSList *order;
+ GSList *order_node;
+ GVariantBuilder *builder;
+ GVariant *order_variant;
- order = proctable_get_columns_order(GTK_TREE_VIEW(tree));
+ order = proctable_get_columns_order(GTK_TREE_VIEW(tree));
- builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+ builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
- for(order_node = order; order_node; order_node = order_node->next)
- g_variant_builder_add(builder, "i", GPOINTER_TO_INT(order_node->data));
+ for(order_node = order; order_node; order_node = order_node->next)
+ g_variant_builder_add(builder, "i", GPOINTER_TO_INT(order_node->data));
- order_variant = g_variant_new("ai", builder);
- g_settings_set_value(pt_settings, "columns-order", order_variant);
+ order_variant = g_variant_new("ai", builder);
+ g_settings_set_value(pt_settings, "columns-order", order_variant);
- g_slist_free(order);
- }
+ g_slist_free(order);
+ }
- g_list_free(columns);
+ g_list_free(columns);
}
void
procman_save_config (ProcData *data)
{
- GSettings *settings = data->settings;
+ GSettings *settings = data->settings;
- g_assert(data);
+ g_assert(data);
- procman_save_tree_state (data->settings, data->tree, "proctree");
- procman_save_tree_state (data->settings, data->disk_list, "disktreenew");
+ procman_save_tree_state (data->settings, data->tree, "proctree");
+ procman_save_tree_state (data->settings, data->disk_list, "disktreenew");
- 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));
- g_settings_set_int (settings, "width", data->config.width);
- g_settings_set_int (settings, "height", data->config.height);
- g_settings_set_int (settings, "current-tab", data->config.current_tab);
+ g_settings_set_int (settings, "width", data->config.width);
+ g_settings_set_int (settings, "height", data->config.height);
+ 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;
+ 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;
+ /* 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);
+ startup_id = g_strdup (startup_id_env);
- time_str = g_strrstr (startup_id, "_TIME");
- if (time_str == NULL)
- goto out;
+ time_str = g_strrstr (startup_id, "_TIME");
+ if (time_str == NULL)
+ goto out;
- /* Skip past the "_TIME" part */
- time_str += 5;
+ /* Skip past the "_TIME" part */
+ time_str += 5;
- retval = strtoul (time_str, NULL, 0);
+ retval = strtoul (time_str, NULL, 0);
out:
- g_free (startup_id);
+ g_free (startup_id);
- return retval;
+ return retval;
}
static void
cb_server (const gchar *msg, gpointer user_data)
{
- GdkWindow *window;
- ProcData *procdata;
- guint32 timestamp = 0;
+ GdkWindow *window;
+ ProcData *procdata;
+ guint32 timestamp = 0;
- window = gdk_get_default_root_window ();
+ window = gdk_get_default_root_window ();
- procdata = *(ProcData**)user_data;
- g_assert (procdata != NULL);
+ procdata = *(ProcData**)user_data;
+ g_assert (procdata != NULL);
- procman_debug("cb_server(%s)", msg);
- if (msg != NULL && procman::SHOW_SYSTEM_TAB_CMD == msg) {
- procman_debug("Changing to PROCMAN_TAB_SYSINFO via bacon message");
- gtk_notebook_set_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO);
- cb_change_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
- } else
- timestamp = strtoul(msg, NULL, 0);
+ procman_debug("cb_server(%s)", msg);
+ if (msg != NULL && procman::SHOW_SYSTEM_TAB_CMD == msg) {
+ procman_debug("Changing to PROCMAN_TAB_SYSINFO via bacon message");
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO);
+ cb_change_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
+ } else
+ timestamp = strtoul(msg, NULL, 0);
- if (timestamp == 0)
- {
- /* fall back to rountripping to X */
- timestamp = gdk_x11_get_server_time (window);
- }
+ if (timestamp == 0)
+ {
+ /* fall back to rountripping to X */
+ timestamp = gdk_x11_get_server_time (window);
+ }
- gdk_x11_window_set_user_time (window, timestamp);
+ gdk_x11_window_set_user_time (window, timestamp);
- gtk_window_present (GTK_WINDOW(procdata->app));
+ gtk_window_present (GTK_WINDOW(procdata->app));
}
@@ -621,27 +621,27 @@ cb_server (const gchar *msg, gpointer user_data)
static void
mount_changed(const Glib::RefPtr<Gio::Mount>&)
{
- cb_update_disks(ProcData::get_instance());
+ cb_update_disks(ProcData::get_instance());
}
static void
init_volume_monitor(ProcData *procdata)
{
- using namespace Gio;
- using namespace Glib;
+ using namespace Gio;
+ using namespace Glib;
- RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
+ 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));
+ 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_SYSTEM_TAB_CMD("SHOWSYSTAB");
}
@@ -649,97 +649,97 @@ namespace procman
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());
- }
+ 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");
+ 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");
+ 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;
+ 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);
+ 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_system_tab)
+ bacon_message_connection_send(conn, procman::SHOW_SYSTEM_TAB_CMD.c_str());
- bacon_message_connection_send (conn, timestamp);
+ bacon_message_connection_send (conn, timestamp);
- gdk_notify_startup_complete ();
+ gdk_notify_startup_complete ();
- g_free (timestamp);
- bacon_message_connection_free (conn);
+ g_free (timestamp);
+ bacon_message_connection_free (conn);
- exit (0);
- }
+ exit (0);
+ }
- gtk_window_set_default_icon_name ("utilities-system-monitor");
- g_set_application_name(_("System Monitor"));
+ gtk_window_set_default_icon_name ("utilities-system-monitor");
+ g_set_application_name(_("System Monitor"));
- settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
+ settings = g_settings_new (GSM_GSETTINGS_SCHEMA);
- glibtop_init ();
+ glibtop_init ();
- procman_debug("end init");
+ procman_debug("end init");
- procdata = procman_data_new (settings);
- procdata->settings = g_settings_new(GSM_GSETTINGS_SCHEMA);
+ 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");
+ procman_debug("begin create_main_window");
+ create_main_window (procdata);
+ procman_debug("end create_main_window");
- // proctable_update_all (procdata);
+ // proctable_update_all (procdata);
- init_volume_monitor (procdata);
+ init_volume_monitor (procdata);
- g_assert(procdata->app);
+ g_assert(procdata->app);
- if (option_group.show_system_tab) {
- procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request");
- gtk_notebook_set_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO);
- cb_change_current_page (GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
- }
+ if (option_group.show_system_tab) {
+ procman_debug("Starting with PROCMAN_TAB_SYSINFO by commandline request");
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO);
+ cb_change_current_page (GTK_NOTEBOOK(procdata->notebook), PROCMAN_TAB_SYSINFO, procdata);
+ }
- gtk_widget_show(procdata->app);
+ gtk_widget_show(procdata->app);
- procman_debug("begin gtk_main");
- kit.run();
+ procman_debug("begin gtk_main");
+ kit.run();
- procman_free_data (procdata);
+ procman_free_data (procdata);
- glibtop_close ();
+ glibtop_close ();
- return 0;
+ return 0;
}
diff --git a/src/procman.h b/src/procman.h
index b838fc2..6b934e3 100644
--- a/src/procman.h
+++ b/src/procman.h
@@ -44,9 +44,9 @@ struct LoadGraph;
enum
{
- ALL_PROCESSES,
- MY_PROCESSES,
- ACTIVE_PROCESSES
+ ALL_PROCESSES,
+ MY_PROCESSES,
+ ACTIVE_PROCESSES
};
@@ -56,176 +56,176 @@ static const unsigned MAX_UPDATE_INTERVAL = 100 * 1000;
namespace procman
{
- extern const std::string SHOW_SYSTEM_TAB_CMD;
+ extern const std::string SHOW_SYSTEM_TAB_CMD;
}
enum ProcmanTab
{
- PROCMAN_TAB_SYSINFO,
- PROCMAN_TAB_PROCESSES,
- PROCMAN_TAB_RESOURCES,
- PROCMAN_TAB_DISKS
+ PROCMAN_TAB_SYSINFO,
+ PROCMAN_TAB_PROCESSES,
+ PROCMAN_TAB_RESOURCES,
+ PROCMAN_TAB_DISKS
};
struct ProcConfig
{
- gint width;
- gint height;
- gboolean show_kill_warning;
- gboolean show_tree;
- gboolean show_all_fs;
- int update_interval;
- int graph_update_interval;
- int disks_update_interval;
- gint whose_process;
- gint current_tab;
- GdkColor cpu_color[GLIBTOP_NCPU];
- GdkColor mem_color;
- GdkColor swap_color;
- GdkColor net_in_color;
- GdkColor net_out_color;
- GdkColor bg_color;
- GdkColor frame_color;
- gint num_cpus;
- bool solaris_mode;
- bool network_in_bits;
+ gint width;
+ gint height;
+ gboolean show_kill_warning;
+ gboolean show_tree;
+ gboolean show_all_fs;
+ int update_interval;
+ int graph_update_interval;
+ int disks_update_interval;
+ gint whose_process;
+ gint current_tab;
+ GdkColor cpu_color[GLIBTOP_NCPU];
+ GdkColor mem_color;
+ GdkColor swap_color;
+ GdkColor net_in_color;
+ GdkColor net_out_color;
+ GdkColor bg_color;
+ GdkColor frame_color;
+ gint num_cpus;
+ bool solaris_mode;
+ bool network_in_bits;
};
struct MutableProcInfo
{
- MutableProcInfo()
- : status(0)
- { }
-
- std::string user;
-
- gchar wchan[40];
-
- // all these members are filled with libgtop which uses
- // guint64 (to have fixed size data) but we don't need more
- // than an unsigned long (even for 32bit apps on a 64bit
- // kernel) as these data are amounts, not offsets.
- gulong vmsize;
- gulong memres;
- gulong memshared;
- gulong memwritable;
- gulong mem;
-
- // wnck gives an unsigned long
- gulong memxserver;
-
- gulong start_time;
- guint64 cpu_time;
- guint status;
- guint pcpu;
- gint nice;
+MutableProcInfo()
+ : status(0)
+ { }
+
+ std::string user;
+
+ gchar wchan[40];
+
+ // all these members are filled with libgtop which uses
+ // guint64 (to have fixed size data) but we don't need more
+ // than an unsigned long (even for 32bit apps on a 64bit
+ // kernel) as these data are amounts, not offsets.
+ gulong vmsize;
+ gulong memres;
+ gulong memshared;
+ gulong memwritable;
+ gulong mem;
+
+ // wnck gives an unsigned long
+ gulong memxserver;
+
+ gulong start_time;
+ guint64 cpu_time;
+ guint status;
+ guint pcpu;
+ gint nice;
};
class ProcInfo
- : public MutableProcInfo
+: public MutableProcInfo
{
- /* undefined */ ProcInfo& operator=(const ProcInfo&);
- /* undefined */ ProcInfo(const ProcInfo&);
+ /* undefined */ ProcInfo& operator=(const ProcInfo&);
+ /* undefined */ ProcInfo(const ProcInfo&);
- typedef std::map<guint, std::string> UserMap;
- /* cached username */
- static UserMap users;
+ typedef std::map<guint, std::string> UserMap;
+ /* cached username */
+ static UserMap users;
- public:
+ public:
- // TODO: use a set instead
- // sorted by pid. The map has a nice property : it is sorted
- // by pid so this helps a lot when looking for the parent node
- // as ppid is nearly always < pid.
- typedef std::map<pid_t, ProcInfo*> List;
- typedef List::iterator Iterator;
+ // TODO: use a set instead
+ // sorted by pid. The map has a nice property : it is sorted
+ // by pid so this helps a lot when looking for the parent node
+ // as ppid is nearly always < pid.
+ typedef std::map<pid_t, ProcInfo*> List;
+ typedef List::iterator Iterator;
- static List all;
+ static List all;
- static ProcInfo* find(pid_t pid);
- static Iterator begin() { return ProcInfo::all.begin(); }
- static Iterator end() { return ProcInfo::all.end(); }
+ static ProcInfo* find(pid_t pid);
+ static Iterator begin() { return ProcInfo::all.begin(); }
+ static Iterator end() { return ProcInfo::all.end(); }
- ProcInfo(pid_t pid);
- ~ProcInfo();
- // adds one more ref to icon
- void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
- void set_user(guint uid);
+ ProcInfo(pid_t pid);
+ ~ProcInfo();
+ // adds one more ref to icon
+ void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
+ void set_user(guint uid);
- GtkTreeIter node;
- Glib::RefPtr<Gdk::Pixbuf> pixbuf;
- gchar *tooltip;
- gchar *name;
- gchar *arguments;
+ GtkTreeIter node;
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf;
+ gchar *tooltip;
+ gchar *name;
+ gchar *arguments;
- gchar *security_context;
+ gchar *security_context;
- const guint pid;
- guint ppid;
- guint uid;
+ const guint pid;
+ guint ppid;
+ guint uid;
// private:
- // tracks cpu time per process keeps growing because if a
- // ProcInfo is deleted this does not mean that the process is
- // not going to be recreated on the next update. For example,
- // if dependencies + (My or Active), the proclist is cleared
- // on each update. This is a workaround
- static std::map<pid_t, guint64> cpu_times;
+ // tracks cpu time per process keeps growing because if a
+ // ProcInfo is deleted this does not mean that the process is
+ // not going to be recreated on the next update. For example,
+ // if dependencies + (My or Active), the proclist is cleared
+ // on each update. This is a workaround
+ static std::map<pid_t, guint64> cpu_times;
};
struct ProcData
{
- // lazy initialization
- static ProcData* get_instance();
-
- GtkUIManager *uimanager;
- GtkActionGroup *action_group;
- GtkWidget *statusbar;
- gint tip_message_cid;
- GtkWidget *tree;
- GtkWidget *loadavg;
- GtkWidget *endprocessbutton;
- GtkWidget *popup_menu;
- GtkWidget *disk_list;
- GtkWidget *notebook;
- ProcConfig config;
- LoadGraph *cpu_graph;
- LoadGraph *mem_graph;
- LoadGraph *net_graph;
- gint cpu_label_fixed_width;
- gint net_label_fixed_width;
- ProcInfo *selected_process;
- GtkTreeSelection *selection;
- guint timeout;
- guint disk_timeout;
-
- PrettyTable pretty_table;
-
- GSettings *settings;
- GtkWidget *app;
- GtkUIManager *menu;
-
- unsigned frequency;
-
- SmoothRefresh *smooth_refresh;
-
- guint64 cpu_total_time;
- guint64 cpu_total_time_last;
+ // lazy initialization
+ static ProcData* get_instance();
+
+ GtkUIManager *uimanager;
+ GtkActionGroup *action_group;
+ GtkWidget *statusbar;
+ gint tip_message_cid;
+ GtkWidget *tree;
+ GtkWidget *loadavg;
+ GtkWidget *endprocessbutton;
+ GtkWidget *popup_menu;
+ GtkWidget *disk_list;
+ GtkWidget *notebook;
+ ProcConfig config;
+ LoadGraph *cpu_graph;
+ LoadGraph *mem_graph;
+ LoadGraph *net_graph;
+ gint cpu_label_fixed_width;
+ gint net_label_fixed_width;
+ ProcInfo *selected_process;
+ GtkTreeSelection *selection;
+ guint timeout;
+ guint disk_timeout;
+
+ PrettyTable pretty_table;
+
+ GSettings *settings;
+ GtkWidget *app;
+ GtkUIManager *menu;
+
+ unsigned frequency;
+
+ SmoothRefresh *smooth_refresh;
+
+ guint64 cpu_total_time;
+ guint64 cpu_total_time_last;
private:
- ProcData();
- /* undefined */ ProcData(const ProcData &);
- /* undefined */ ProcData& operator=(const ProcData &);
+ ProcData();
+ /* undefined */ ProcData(const ProcData &);
+ /* undefined */ ProcData& operator=(const ProcData &);
};
-void procman_save_config (ProcData *data);
+void procman_save_config (ProcData *data);
void procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *prefix);
gboolean procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *prefix);
@@ -235,15 +235,15 @@ gboolean procman_get_tree_state (GSettings *settings, GtkWidget *tree, const
struct ReniceArgs
{
- ProcData *procdata;
- int nice_value;
+ ProcData *procdata;
+ int nice_value;
};
struct KillArgs
{
- ProcData *procdata;
- int signal;
+ ProcData *procdata;
+ int signal;
};
#endif /* _PROCMAN_PROCMAN_H_ */
diff --git a/src/procman_gksu.cpp b/src/procman_gksu.cpp
index d2737cc..58faa0c 100644
--- a/src/procman_gksu.cpp
+++ b/src/procman_gksu.cpp
@@ -9,16 +9,16 @@ static gboolean (*gksu_run)(const char *, GError **);
static void load_gksu(void)
{
- static gboolean init;
+ static gboolean init;
- if (init)
- return;
+ if (init)
+ return;
- init = TRUE;
+ init = TRUE;
- load_symbols("libgksu2.so",
- "gksu_run", &gksu_run,
- NULL);
+ load_symbols("libgksu2.so",
+ "gksu_run", &gksu_run,
+ NULL);
}
@@ -27,20 +27,20 @@ static void load_gksu(void)
gboolean procman_gksu_create_root_password_dialog(const char *command)
{
- GError *e = NULL;
+ GError *e = NULL;
- /* Returns FALSE or TRUE on success, depends on version ... */
- gksu_run(command, &e);
+ /* Returns FALSE or TRUE on success, depends on version ... */
+ gksu_run(command, &e);
- if (e) {
- g_critical("Could not run gksu_run(\"%s\") : %s\n",
- command, e->message);
- g_error_free(e);
- return FALSE;
- }
+ if (e) {
+ g_critical("Could not run gksu_run(\"%s\") : %s\n",
+ command, e->message);
+ g_error_free(e);
+ return FALSE;
+ }
- g_message("gksu_run did fine\n");
- return TRUE;
+ g_message("gksu_run did fine\n");
+ return TRUE;
}
@@ -48,7 +48,7 @@ gboolean procman_gksu_create_root_password_dialog(const char *command)
gboolean
procman_has_gksu(void)
{
- load_gksu();
- return gksu_run != NULL;
+ load_gksu();
+ return gksu_run != NULL;
}
diff --git a/src/procman_matesu.cpp b/src/procman_matesu.cpp
index 5bf6c59..b7c08ad 100644
--- a/src/procman_matesu.cpp
+++ b/src/procman_matesu.cpp
@@ -12,29 +12,29 @@ gboolean (*matesu_exec)(const char *commandline);
static void
load_matesu(void)
{
- static gboolean init;
+ static gboolean init;
- if (init)
- return;
+ if (init)
+ return;
- init = TRUE;
+ init = TRUE;
- load_symbols("libmatesu.so.0",
- "matesu_exec", &matesu_exec,
- NULL);
+ load_symbols("libmatesu.so.0",
+ "matesu_exec", &matesu_exec,
+ NULL);
}
gboolean
procman_matesu_create_root_password_dialog(const char *command)
{
- return matesu_exec(command);
+ return matesu_exec(command);
}
gboolean
procman_has_matesu(void)
{
- load_matesu();
- return matesu_exec != NULL;
+ load_matesu();
+ return matesu_exec != NULL;
}
diff --git a/src/proctable.cpp b/src/proctable.cpp
index b2e8d92..1304077 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -61,8 +61,8 @@ std::map<pid_t, guint64> ProcInfo::cpu_times;
ProcInfo* ProcInfo::find(pid_t pid)
{
- Iterator it(ProcInfo::all.find(pid));
- return (it == ProcInfo::all.end() ? NULL : it->second);
+ Iterator it(ProcInfo::all.find(pid));
+ return (it == ProcInfo::all.end() ? NULL : it->second);
}
@@ -71,77 +71,77 @@ ProcInfo* ProcInfo::find(pid_t pid)
static void
set_proctree_reorderable(ProcData *procdata)
{
- GList *columns, *col;
- GtkTreeView *proctree;
+ GList *columns, *col;
+ GtkTreeView *proctree;
- proctree = GTK_TREE_VIEW(procdata->tree);
+ proctree = GTK_TREE_VIEW(procdata->tree);
- columns = gtk_tree_view_get_columns (proctree);
+ columns = gtk_tree_view_get_columns (proctree);
- for(col = columns; col; col = col->next)
- gtk_tree_view_column_set_reorderable(static_cast<GtkTreeViewColumn*>(col->data), TRUE);
+ for(col = columns; col; col = col->next)
+ gtk_tree_view_column_set_reorderable(static_cast<GtkTreeViewColumn*>(col->data), TRUE);
- g_list_free(columns);
+ g_list_free(columns);
}
static void
cb_columns_changed(GtkTreeView *treeview, gpointer user_data)
{
- ProcData * const procdata = static_cast<ProcData*>(user_data);
+ ProcData * const procdata = static_cast<ProcData*>(user_data);
- procman_save_tree_state(procdata->settings,
- GTK_WIDGET(treeview),
- "proctree");
+ procman_save_tree_state(procdata->settings,
+ GTK_WIDGET(treeview),
+ "proctree");
}
static GtkTreeViewColumn*
my_gtk_tree_view_get_column_with_sort_column_id(GtkTreeView *treeview, int id)
{
- GList *columns, *it;
- GtkTreeViewColumn *col = NULL;
+ GList *columns, *it;
+ GtkTreeViewColumn *col = NULL;
- columns = gtk_tree_view_get_columns(treeview);
+ columns = gtk_tree_view_get_columns(treeview);
- for(it = columns; it; it = it->next)
- {
- if(gtk_tree_view_column_get_sort_column_id(static_cast<GtkTreeViewColumn*>(it->data)) == id)
- {
- col = static_cast<GtkTreeViewColumn*>(it->data);
- break;
- }
- }
+ for(it = columns; it; it = it->next)
+ {
+ if(gtk_tree_view_column_get_sort_column_id(static_cast<GtkTreeViewColumn*>(it->data)) == id)
+ {
+ col = static_cast<GtkTreeViewColumn*>(it->data);
+ break;
+ }
+ }
- g_list_free(columns);
+ g_list_free(columns);
- return col;
+ return col;
}
void
proctable_set_columns_order(GtkTreeView *treeview, GSList *order)
{
- GtkTreeViewColumn* last = NULL;
- GSList *it;
+ GtkTreeViewColumn* last = NULL;
+ GSList *it;
- for(it = order; it; it = it->next)
- {
- int id;
- GtkTreeViewColumn *cur;
+ for(it = order; it; it = it->next)
+ {
+ int id;
+ GtkTreeViewColumn *cur;
- id = GPOINTER_TO_INT(it->data);
+ id = GPOINTER_TO_INT(it->data);
- g_assert(id >= 0 && id < NUM_COLUMNS);
+ g_assert(id >= 0 && id < NUM_COLUMNS);
- cur = my_gtk_tree_view_get_column_with_sort_column_id(treeview, id);
+ cur = my_gtk_tree_view_get_column_with_sort_column_id(treeview, id);
- if(cur && cur != last)
- {
- gtk_tree_view_move_column_after(treeview, cur, last);
- last = cur;
- }
- }
+ if(cur && cur != last)
+ {
+ gtk_tree_view_move_column_after(treeview, cur, last);
+ last = cur;
+ }
+ }
}
@@ -149,50 +149,50 @@ proctable_set_columns_order(GtkTreeView *treeview, GSList *order)
GSList*
proctable_get_columns_order(GtkTreeView *treeview)
{
- GList *columns, *col;
- GSList *order = NULL;
+ GList *columns, *col;
+ GSList *order = NULL;
- columns = gtk_tree_view_get_columns(treeview);
+ columns = gtk_tree_view_get_columns(treeview);
- for(col = columns; col; col = col->next)
- {
- int id;
+ for(col = columns; col; col = col->next)
+ {
+ int id;
- id = gtk_tree_view_column_get_sort_column_id(static_cast<GtkTreeViewColumn*>(col->data));
- order = g_slist_prepend(order, GINT_TO_POINTER(id));
- }
+ id = gtk_tree_view_column_get_sort_column_id(static_cast<GtkTreeViewColumn*>(col->data));
+ order = g_slist_prepend(order, GINT_TO_POINTER(id));
+ }
- g_list_free(columns);
+ g_list_free(columns);
- order = g_slist_reverse(order);
+ order = g_slist_reverse(order);
- return order;
+ return order;
}
static gboolean
search_equal_func(GtkTreeModel *model,
- gint column,
- const gchar *key,
- GtkTreeIter *iter,
- gpointer search_data)
+ gint column,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer search_data)
{
- char* name;
- char* user;
- gboolean found;
+ char* name;
+ char* user;
+ gboolean found;
- gtk_tree_model_get(model, iter,
- COL_NAME, &name,
- COL_USER, &user,
- -1);
+ gtk_tree_model_get(model, iter,
+ COL_NAME, &name,
+ COL_USER, &user,
+ -1);
- found = !((name && strstr(name, key))
- || (user && strstr(user, key)));
+ found = !((name && strstr(name, key))
+ || (user && strstr(user, key)));
- g_free(name);
- g_free(user);
+ g_free(name);
+ g_free(user);
- return found;
+ return found;
}
@@ -200,253 +200,253 @@ search_equal_func(GtkTreeModel *model,
GtkWidget *
proctable_new (ProcData * const procdata)
{
- GtkWidget *proctree;
- GtkWidget *scrolled;
- GtkTreeStore *model;
- GtkTreeSelection *selection;
- GtkTreeViewColumn *column;
- GtkCellRenderer *cell_renderer;
-
- const gchar *titles[] = {
- N_("Process Name"),
- N_("User"),
- N_("Status"),
- N_("Virtual Memory"),
- N_("Resident Memory"),
- N_("Writable Memory"),
- N_("Shared Memory"),
- N_("X Server Memory"),
- /* xgettext:no-c-format */ N_("% CPU"),
- N_("CPU Time"),
- N_("Started"),
- N_("Nice"),
- N_("ID"),
- N_("Security Context"),
- N_("Command Line"),
- N_("Memory"),
- /* xgettext: wchan, see ps(1) or top(1) */
- N_("Waiting Channel"),
- NULL,
- "POINTER"
- };
-
- gint i;
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- model = gtk_tree_store_new (NUM_COLUMNS,
- G_TYPE_STRING, /* Process Name */
- G_TYPE_STRING, /* User */
- G_TYPE_UINT, /* Status */
- G_TYPE_ULONG, /* VM Size */
- G_TYPE_ULONG, /* Resident Memory */
- G_TYPE_ULONG, /* Writable Memory */
- G_TYPE_ULONG, /* Shared Memory */
- G_TYPE_ULONG, /* X Server Memory */
- G_TYPE_UINT, /* % CPU */
- G_TYPE_UINT64, /* CPU time */
- G_TYPE_ULONG, /* Started */
- G_TYPE_INT, /* Nice */
- G_TYPE_UINT, /* ID */
- G_TYPE_STRING, /* Security Context */
- G_TYPE_STRING, /* Arguments */
- G_TYPE_ULONG, /* Memory */
- G_TYPE_STRING, /* wchan */
- GDK_TYPE_PIXBUF, /* Icon */
- G_TYPE_POINTER, /* ProcInfo */
- G_TYPE_STRING /* Sexy tooltip */
- );
-
- proctree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
- gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (proctree), COL_TOOLTIP);
- g_object_set(G_OBJECT(proctree),
- "show-expanders", procdata->config.show_tree,
- NULL);
- gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (proctree),
- search_equal_func,
- NULL,
- NULL);
- gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (proctree), TRUE);
- g_object_unref (G_OBJECT (model));
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
-
- column = gtk_tree_view_column_new ();
-
- cell_renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
- gtk_tree_view_column_set_attributes (column, cell_renderer,
- "pixbuf", COL_PIXBUF,
- NULL);
-
- cell_renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
- gtk_tree_view_column_set_attributes (column, cell_renderer,
- "text", COL_NAME,
- NULL);
- gtk_tree_view_column_set_title (column, _(titles[0]));
- gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_min_width (column, 1);
- gtk_tree_view_append_column (GTK_TREE_VIEW (proctree), column);
- gtk_tree_view_set_expander_column (GTK_TREE_VIEW (proctree), column);
-
-
- for (i = COL_USER; i <= COL_WCHAN; i++) {
-
- GtkCellRenderer *cell;
- GtkTreeViewColumn *col;
-
- cell = gtk_cell_renderer_text_new();
- col = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start(col, cell, TRUE);
- gtk_tree_view_column_set_title(col, _(titles[i]));
- gtk_tree_view_column_set_resizable(col, TRUE);
- gtk_tree_view_column_set_sort_column_id(col, i);
- gtk_tree_view_column_set_reorderable(col, TRUE);
- gtk_tree_view_append_column(GTK_TREE_VIEW(proctree), col);
-
- // type
- switch (i) {
- case COL_MEMXSERVER:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::size_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- case COL_VMSIZE:
- case COL_MEMRES:
- case COL_MEMSHARED:
- case COL_MEM:
- case COL_MEMWRITABLE:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::size_na_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- case COL_CPU_TIME:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::duration_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- case COL_START_TIME:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::time_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- case COL_STATUS:
- gtk_tree_view_column_set_cell_data_func(col, cell,
- &procman::status_cell_data_func,
- GUINT_TO_POINTER(i),
- NULL);
- break;
-
- default:
- gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
- break;
- }
-
- // xaling
- switch(i)
- {
- case COL_VMSIZE:
- case COL_MEMRES:
- case COL_MEMWRITABLE:
- case COL_MEMSHARED:
- case COL_MEMXSERVER:
- case COL_CPU:
- case COL_NICE:
- case COL_PID:
- case COL_CPU_TIME:
- case COL_MEM:
- g_object_set(G_OBJECT(cell), "xalign", 1.0f, NULL);
- break;
- }
-
- // sizing
- switch (i) {
- case COL_ARGS:
- gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_min_width(col, 150);
- break;
- default:
- gtk_tree_view_column_set_min_width(column, 20);
- break;
- }
- }
-
- gtk_container_add (GTK_CONTAINER (scrolled), proctree);
-
- procdata->tree = proctree;
-
- set_proctree_reorderable(procdata);
-
- procman_get_tree_state (procdata->settings, proctree, "proctree");
-
- /* Override column settings by hiding this column if it's meaningless: */
- if (!can_show_security_context_column ()) {
- GtkTreeViewColumn *column;
- column = my_gtk_tree_view_get_column_with_sort_column_id (GTK_TREE_VIEW (proctree), COL_SECURITYCONTEXT);
- gtk_tree_view_column_set_visible (column, FALSE);
- }
-
- g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree))),
- "changed",
- G_CALLBACK (cb_row_selected), procdata);
- g_signal_connect (G_OBJECT (proctree), "popup_menu",
- G_CALLBACK (cb_tree_popup_menu), procdata);
- g_signal_connect (G_OBJECT (proctree), "button_press_event",
- G_CALLBACK (cb_tree_button_pressed), procdata);
-
- g_signal_connect (G_OBJECT(proctree), "columns-changed",
- G_CALLBACK(cb_columns_changed), procdata);
-
- return scrolled;
+ GtkWidget *proctree;
+ GtkWidget *scrolled;
+ GtkTreeStore *model;
+ GtkTreeSelection *selection;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *cell_renderer;
+
+ const gchar *titles[] = {
+ N_("Process Name"),
+ N_("User"),
+ N_("Status"),
+ N_("Virtual Memory"),
+ N_("Resident Memory"),
+ N_("Writable Memory"),
+ N_("Shared Memory"),
+ N_("X Server Memory"),
+ /* xgettext:no-c-format */ N_("% CPU"),
+ N_("CPU Time"),
+ N_("Started"),
+ N_("Nice"),
+ N_("ID"),
+ N_("Security Context"),
+ N_("Command Line"),
+ N_("Memory"),
+ /* xgettext: wchan, see ps(1) or top(1) */
+ N_("Waiting Channel"),
+ NULL,
+ "POINTER"
+ };
+
+ gint i;
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ model = gtk_tree_store_new (NUM_COLUMNS,
+ G_TYPE_STRING, /* Process Name */
+ G_TYPE_STRING, /* User */
+ G_TYPE_UINT, /* Status */
+ G_TYPE_ULONG, /* VM Size */
+ G_TYPE_ULONG, /* Resident Memory */
+ G_TYPE_ULONG, /* Writable Memory */
+ G_TYPE_ULONG, /* Shared Memory */
+ G_TYPE_ULONG, /* X Server Memory */
+ G_TYPE_UINT, /* % CPU */
+ G_TYPE_UINT64, /* CPU time */
+ G_TYPE_ULONG, /* Started */
+ G_TYPE_INT, /* Nice */
+ G_TYPE_UINT, /* ID */
+ G_TYPE_STRING, /* Security Context */
+ G_TYPE_STRING, /* Arguments */
+ G_TYPE_ULONG, /* Memory */
+ G_TYPE_STRING, /* wchan */
+ GDK_TYPE_PIXBUF, /* Icon */
+ G_TYPE_POINTER, /* ProcInfo */
+ G_TYPE_STRING /* Sexy tooltip */
+ );
+
+ proctree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+ gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (proctree), COL_TOOLTIP);
+ g_object_set(G_OBJECT(proctree),
+ "show-expanders", procdata->config.show_tree,
+ NULL);
+ gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (proctree),
+ search_equal_func,
+ NULL,
+ NULL);
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (proctree), TRUE);
+ g_object_unref (G_OBJECT (model));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+ column = gtk_tree_view_column_new ();
+
+ cell_renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
+ gtk_tree_view_column_set_attributes (column, cell_renderer,
+ "pixbuf", COL_PIXBUF,
+ NULL);
+
+ cell_renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
+ gtk_tree_view_column_set_attributes (column, cell_renderer,
+ "text", COL_NAME,
+ NULL);
+ gtk_tree_view_column_set_title (column, _(titles[0]));
+ gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
+ gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_min_width (column, 1);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (proctree), column);
+ gtk_tree_view_set_expander_column (GTK_TREE_VIEW (proctree), column);
+
+
+ for (i = COL_USER; i <= COL_WCHAN; i++) {
+
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *col;
+
+ cell = gtk_cell_renderer_text_new();
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start(col, cell, TRUE);
+ gtk_tree_view_column_set_title(col, _(titles[i]));
+ gtk_tree_view_column_set_resizable(col, TRUE);
+ gtk_tree_view_column_set_sort_column_id(col, i);
+ gtk_tree_view_column_set_reorderable(col, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(proctree), col);
+
+ // type
+ switch (i) {
+ case COL_MEMXSERVER:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::size_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ case COL_VMSIZE:
+ case COL_MEMRES:
+ case COL_MEMSHARED:
+ case COL_MEM:
+ case COL_MEMWRITABLE:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::size_na_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ case COL_CPU_TIME:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::duration_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ case COL_START_TIME:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::time_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ case COL_STATUS:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::status_cell_data_func,
+ GUINT_TO_POINTER(i),
+ NULL);
+ break;
+
+ default:
+ gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
+ break;
+ }
+
+ // xaling
+ switch(i)
+ {
+ case COL_VMSIZE:
+ case COL_MEMRES:
+ case COL_MEMWRITABLE:
+ case COL_MEMSHARED:
+ case COL_MEMXSERVER:
+ case COL_CPU:
+ case COL_NICE:
+ case COL_PID:
+ case COL_CPU_TIME:
+ case COL_MEM:
+ g_object_set(G_OBJECT(cell), "xalign", 1.0f, NULL);
+ break;
+ }
+
+ // sizing
+ switch (i) {
+ case COL_ARGS:
+ gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_min_width(col, 150);
+ break;
+ default:
+ gtk_tree_view_column_set_min_width(column, 20);
+ break;
+ }
+ }
+
+ gtk_container_add (GTK_CONTAINER (scrolled), proctree);
+
+ procdata->tree = proctree;
+
+ set_proctree_reorderable(procdata);
+
+ procman_get_tree_state (procdata->settings, proctree, "proctree");
+
+ /* Override column settings by hiding this column if it's meaningless: */
+ if (!can_show_security_context_column ()) {
+ GtkTreeViewColumn *column;
+ column = my_gtk_tree_view_get_column_with_sort_column_id (GTK_TREE_VIEW (proctree), COL_SECURITYCONTEXT);
+ gtk_tree_view_column_set_visible (column, FALSE);
+ }
+
+ g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree))),
+ "changed",
+ G_CALLBACK (cb_row_selected), procdata);
+ g_signal_connect (G_OBJECT (proctree), "popup_menu",
+ G_CALLBACK (cb_tree_popup_menu), procdata);
+ g_signal_connect (G_OBJECT (proctree), "button_press_event",
+ G_CALLBACK (cb_tree_button_pressed), procdata);
+
+ g_signal_connect (G_OBJECT(proctree), "columns-changed",
+ G_CALLBACK(cb_columns_changed), procdata);
+
+ return scrolled;
}
ProcInfo::~ProcInfo()
{
- g_free(this->name);
- g_free(this->tooltip);
- g_free(this->arguments);
- g_free(this->security_context);
+ g_free(this->name);
+ g_free(this->tooltip);
+ g_free(this->arguments);
+ g_free(this->security_context);
}
static void
get_process_name (ProcInfo *info,
- const gchar *cmd, const GStrv args)
+ const gchar *cmd, const GStrv args)
{
- if (args) {
- // look for /usr/bin/very_long_name
- // and also /usr/bin/interpreter /usr/.../very_long_name
- // which may have use prctl to alter 'cmd' name
- for (int i = 0; i != 2 && args[i]; ++i) {
- char* basename;
- basename = g_path_get_basename(args[i]);
-
- if (g_str_has_prefix(basename, cmd)) {
- info->name = basename;
- return;
- }
-
- g_free(basename);
- }
- }
-
- info->name = g_strdup (cmd);
+ if (args) {
+ // look for /usr/bin/very_long_name
+ // and also /usr/bin/interpreter /usr/.../very_long_name
+ // which may have use prctl to alter 'cmd' name
+ for (int i = 0; i != 2 && args[i]; ++i) {
+ char* basename;
+ basename = g_path_get_basename(args[i]);
+
+ if (g_str_has_prefix(basename, cmd)) {
+ info->name = basename;
+ return;
+ }
+
+ g_free(basename);
+ }
+ }
+
+ info->name = g_strdup (cmd);
}
@@ -454,82 +454,82 @@ get_process_name (ProcInfo *info,
void
ProcInfo::set_user(guint uid)
{
- if (G_LIKELY(this->uid == uid))
- return;
+ if (G_LIKELY(this->uid == uid))
+ return;
- this->uid = uid;
+ this->uid = uid;
- typedef std::pair<ProcInfo::UserMap::iterator, bool> Pair;
- ProcInfo::UserMap::value_type hint(uid, "");
- Pair p(ProcInfo::users.insert(hint));
+ typedef std::pair<ProcInfo::UserMap::iterator, bool> Pair;
+ ProcInfo::UserMap::value_type hint(uid, "");
+ Pair p(ProcInfo::users.insert(hint));
- // procman_debug("User lookup for uid %u: %s", uid, (p.second ? "MISS" : "HIT"));
+ // procman_debug("User lookup for uid %u: %s", uid, (p.second ? "MISS" : "HIT"));
- if (p.second) {
- struct passwd* pwd;
- pwd = getpwuid(uid);
+ if (p.second) {
+ struct passwd* pwd;
+ pwd = getpwuid(uid);
- if (pwd && pwd->pw_name)
- p.first->second = pwd->pw_name;
- else {
- char username[16];
- g_sprintf(username, "%u", uid);
- p.first->second = username;
- }
- }
+ if (pwd && pwd->pw_name)
+ p.first->second = pwd->pw_name;
+ else {
+ char username[16];
+ g_sprintf(username, "%u", uid);
+ p.first->second = username;
+ }
+ }
- this->user = p.first->second;
+ this->user = p.first->second;
}
static void get_process_memory_writable(ProcInfo *info)
{
- glibtop_proc_map buf;
- glibtop_map_entry *maps;
+ glibtop_proc_map buf;
+ glibtop_map_entry *maps;
- maps = glibtop_get_proc_map(&buf, info->pid);
+ maps = glibtop_get_proc_map(&buf, info->pid);
- gulong memwritable = 0;
- const unsigned number = buf.number;
+ gulong memwritable = 0;
+ const unsigned number = buf.number;
- for (unsigned i = 0; i < number; ++i) {
+ for (unsigned i = 0; i < number; ++i) {
#ifdef __linux__
- memwritable += maps[i].private_dirty;
+ memwritable += maps[i].private_dirty;
#else
- if (maps[i].perm & GLIBTOP_MAP_PERM_WRITE)
- memwritable += maps[i].size;
+ if (maps[i].perm & GLIBTOP_MAP_PERM_WRITE)
+ memwritable += maps[i].size;
#endif
- }
+ }
- info->memwritable = memwritable;
+ info->memwritable = memwritable;
- g_free(maps);
+ g_free(maps);
}
static void
get_process_memory_info(ProcInfo *info)
{
- glibtop_proc_mem procmem;
- WnckResourceUsage xresources;
+ glibtop_proc_mem procmem;
+ WnckResourceUsage xresources;
- wnck_pid_read_resource_usage (gdk_screen_get_display (gdk_screen_get_default ()),
- info->pid,
- &xresources);
+ wnck_pid_read_resource_usage (gdk_screen_get_display (gdk_screen_get_default ()),
+ info->pid,
+ &xresources);
- glibtop_get_proc_mem(&procmem, info->pid);
+ glibtop_get_proc_mem(&procmem, info->pid);
- info->vmsize = procmem.vsize;
- info->memres = procmem.resident;
- info->memshared = procmem.share;
+ info->vmsize = procmem.vsize;
+ info->memres = procmem.resident;
+ info->memshared = procmem.share;
- info->memxserver = xresources.total_bytes_estimate;
+ info->memxserver = xresources.total_bytes_estimate;
- get_process_memory_writable(info);
+ get_process_memory_writable(info);
- // fake the smart memory column if writable is not available
- info->mem = info->memxserver + (info->memwritable ? info->memwritable : info->memres);
+ // fake the smart memory column if writable is not available
+ info->mem = info->memxserver + (info->memwritable ? info->memwritable : info->memres);
}
@@ -537,25 +537,25 @@ get_process_memory_info(ProcInfo *info)
static void
update_info_mutable_cols(ProcInfo *info)
{
- ProcData * const procdata = ProcData::get_instance();
- GtkTreeModel *model;
- model = gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->tree));
-
- using procman::tree_store_update;
-
- tree_store_update(model, &info->node, COL_STATUS, info->status);
- tree_store_update(model, &info->node, COL_USER, info->user.c_str());
- tree_store_update(model, &info->node, COL_VMSIZE, info->vmsize);
- tree_store_update(model, &info->node, COL_MEMRES, info->memres);
- tree_store_update(model, &info->node, COL_MEMWRITABLE, info->memwritable);
- tree_store_update(model, &info->node, COL_MEMSHARED, info->memshared);
- tree_store_update(model, &info->node, COL_MEMXSERVER, info->memxserver);
- tree_store_update(model, &info->node, COL_CPU, info->pcpu);
- tree_store_update(model, &info->node, COL_CPU_TIME, info->cpu_time);
- tree_store_update(model, &info->node, COL_START_TIME, info->start_time);
- tree_store_update(model, &info->node, COL_NICE, info->nice);
- tree_store_update(model, &info->node, COL_MEM, info->mem);
- tree_store_update(model, &info->node, COL_WCHAN, info->wchan);
+ ProcData * const procdata = ProcData::get_instance();
+ GtkTreeModel *model;
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(procdata->tree));
+
+ using procman::tree_store_update;
+
+ tree_store_update(model, &info->node, COL_STATUS, info->status);
+ tree_store_update(model, &info->node, COL_USER, info->user.c_str());
+ tree_store_update(model, &info->node, COL_VMSIZE, info->vmsize);
+ tree_store_update(model, &info->node, COL_MEMRES, info->memres);
+ tree_store_update(model, &info->node, COL_MEMWRITABLE, info->memwritable);
+ tree_store_update(model, &info->node, COL_MEMSHARED, info->memshared);
+ tree_store_update(model, &info->node, COL_MEMXSERVER, info->memxserver);
+ tree_store_update(model, &info->node, COL_CPU, info->pcpu);
+ tree_store_update(model, &info->node, COL_CPU_TIME, info->cpu_time);
+ tree_store_update(model, &info->node, COL_START_TIME, info->start_time);
+ tree_store_update(model, &info->node, COL_NICE, info->nice);
+ tree_store_update(model, &info->node, COL_MEM, info->mem);
+ tree_store_update(model, &info->node, COL_WCHAN, info->wchan);
}
@@ -563,42 +563,42 @@ update_info_mutable_cols(ProcInfo *info)
static void
insert_info_to_tree (ProcInfo *info, ProcData *procdata, bool forced = false)
{
- GtkTreeModel *model;
+ GtkTreeModel *model;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
- if (procdata->config.show_tree) {
+ if (procdata->config.show_tree) {
- ProcInfo *parent = 0;
+ ProcInfo *parent = 0;
- if (not forced)
- parent = ProcInfo::find(info->ppid);
+ if (not forced)
+ parent = ProcInfo::find(info->ppid);
- if (parent) {
- GtkTreePath *parent_node = gtk_tree_model_get_path(model, &parent->node);
- gtk_tree_store_insert(GTK_TREE_STORE(model), &info->node, &parent->node, 0);
+ if (parent) {
+ GtkTreePath *parent_node = gtk_tree_model_get_path(model, &parent->node);
+ gtk_tree_store_insert(GTK_TREE_STORE(model), &info->node, &parent->node, 0);
- if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(procdata->tree), parent_node))
- gtk_tree_view_expand_row(GTK_TREE_VIEW(procdata->tree), parent_node, FALSE);
- gtk_tree_path_free(parent_node);
- } else
- gtk_tree_store_insert(GTK_TREE_STORE(model), &info->node, NULL, 0);
- }
- else
- gtk_tree_store_insert (GTK_TREE_STORE (model), &info->node, NULL, 0);
+ if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(procdata->tree), parent_node))
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(procdata->tree), parent_node, FALSE);
+ gtk_tree_path_free(parent_node);
+ } else
+ gtk_tree_store_insert(GTK_TREE_STORE(model), &info->node, NULL, 0);
+ }
+ else
+ gtk_tree_store_insert (GTK_TREE_STORE (model), &info->node, NULL, 0);
- gtk_tree_store_set (GTK_TREE_STORE (model), &info->node,
- COL_POINTER, info,
- COL_NAME, info->name,
- COL_ARGS, info->arguments,
- COL_TOOLTIP, info->tooltip,
- COL_PID, info->pid,
- COL_SECURITYCONTEXT, info->security_context,
- -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &info->node,
+ COL_POINTER, info,
+ COL_NAME, info->name,
+ COL_ARGS, info->arguments,
+ COL_TOOLTIP, info->tooltip,
+ COL_PID, info->pid,
+ COL_SECURITYCONTEXT, info->security_context,
+ -1);
- procdata->pretty_table.set_icon(*info);
+ procdata->pretty_table.set_icon(*info);
- procman_debug("inserted %d%s", info->pid, (forced ? " (forced)" : ""));
+ procman_debug("inserted %d%s", info->pid, (forced ? " (forced)" : ""));
}
@@ -608,36 +608,36 @@ insert_info_to_tree (ProcInfo *info, ProcData *procdata, bool forced = false)
template<typename List>
static void
remove_info_from_tree (ProcData *procdata, GtkTreeModel *model,
- ProcInfo *current, List &orphans, unsigned lvl = 0)
+ ProcInfo *current, List &orphans, unsigned lvl = 0)
{
- GtkTreeIter child_node;
+ GtkTreeIter child_node;
- if (std::find(orphans.begin(), orphans.end(), current) != orphans.end()) {
- procman_debug("[%u] %d already removed from tree", lvl, int(current->pid));
- return;
- }
+ if (std::find(orphans.begin(), orphans.end(), current) != orphans.end()) {
+ procman_debug("[%u] %d already removed from tree", lvl, int(current->pid));
+ return;
+ }
- procman_debug("[%u] pid %d, %d children", lvl, int(current->pid),
- gtk_tree_model_iter_n_children(model, &current->node));
+ procman_debug("[%u] pid %d, %d children", lvl, int(current->pid),
+ gtk_tree_model_iter_n_children(model, &current->node));
- // it is not possible to iterate&erase over a treeview so instead we
- // just pop one child after another and recursively remove it and
- // its children
+ // it is not possible to iterate&erase over a treeview so instead we
+ // just pop one child after another and recursively remove it and
+ // its children
- while (gtk_tree_model_iter_children(model, &child_node, &current->node)) {
- ProcInfo *child = 0;
- gtk_tree_model_get(model, &child_node, COL_POINTER, &child, -1);
- remove_info_from_tree(procdata, model, child, orphans, lvl + 1);
- }
+ while (gtk_tree_model_iter_children(model, &child_node, &current->node)) {
+ ProcInfo *child = 0;
+ gtk_tree_model_get(model, &child_node, COL_POINTER, &child, -1);
+ remove_info_from_tree(procdata, model, child, orphans, lvl + 1);
+ }
- g_assert(not gtk_tree_model_iter_has_child(model, &current->node));
+ g_assert(not gtk_tree_model_iter_has_child(model, &current->node));
- if (procdata->selected_process == current)
- procdata->selected_process = NULL;
+ if (procdata->selected_process == current)
+ procdata->selected_process = NULL;
- orphans.push_back(current);
- gtk_tree_store_remove(GTK_TREE_STORE(model), &current->node);
- procman::poison(current->node, 0x69);
+ orphans.push_back(current);
+ gtk_tree_store_remove(GTK_TREE_STORE(model), &current->node);
+ procman::poison(current->node, 0x69);
}
@@ -645,77 +645,77 @@ remove_info_from_tree (ProcData *procdata, GtkTreeModel *model,
static void
update_info (ProcData *procdata, ProcInfo *info)
{
- glibtop_proc_state procstate;
- glibtop_proc_uid procuid;
- glibtop_proc_time proctime;
- glibtop_proc_kernel prockernel;
+ glibtop_proc_state procstate;
+ glibtop_proc_uid procuid;
+ glibtop_proc_time proctime;
+ glibtop_proc_kernel prockernel;
- glibtop_get_proc_kernel(&prockernel, info->pid);
- g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
+ glibtop_get_proc_kernel(&prockernel, info->pid);
+ g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
- glibtop_get_proc_state (&procstate, info->pid);
- info->status = procstate.state;
+ glibtop_get_proc_state (&procstate, info->pid);
+ info->status = procstate.state;
- glibtop_get_proc_uid (&procuid, info->pid);
- glibtop_get_proc_time (&proctime, info->pid);
+ glibtop_get_proc_uid (&procuid, info->pid);
+ glibtop_get_proc_time (&proctime, info->pid);
- get_process_memory_info(info);
+ get_process_memory_info(info);
- info->set_user(procstate.uid);
+ info->set_user(procstate.uid);
- info->pcpu = (proctime.rtime - info->cpu_time) * 100 / procdata->cpu_total_time;
- info->pcpu = MIN(info->pcpu, 100);
+ info->pcpu = (proctime.rtime - info->cpu_time) * 100 / procdata->cpu_total_time;
+ info->pcpu = MIN(info->pcpu, 100);
- if (not procdata->config.solaris_mode)
- info->pcpu *= procdata->config.num_cpus;
+ if (not procdata->config.solaris_mode)
+ info->pcpu *= procdata->config.num_cpus;
- ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
- info->nice = procuid.nice;
- info->ppid = procuid.ppid;
+ ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
+ info->nice = procuid.nice;
+ info->ppid = procuid.ppid;
}
ProcInfo::ProcInfo(pid_t pid)
- : tooltip(NULL),
- name(NULL),
- arguments(NULL),
- security_context(NULL),
- pid(pid),
- uid(-1)
+ : tooltip(NULL),
+ name(NULL),
+ arguments(NULL),
+ security_context(NULL),
+ pid(pid),
+ uid(-1)
{
- ProcInfo * const info = this;
- glibtop_proc_state procstate;
- glibtop_proc_time proctime;
- glibtop_proc_args procargs;
- gchar** arguments;
-
- glibtop_get_proc_state (&procstate, pid);
- glibtop_get_proc_time (&proctime, pid);
- arguments = glibtop_get_proc_argv (&procargs, pid, 0);
-
- /* FIXME : wrong. name and arguments may change with exec* */
- get_process_name (info, procstate.cmd, static_cast<const GStrv>(arguments));
-
- std::string tooltip = make_string(g_strjoinv(" ", arguments));
- if (tooltip.empty())
- tooltip = procstate.cmd;
-
- info->tooltip = g_markup_escape_text(tooltip.c_str(), -1);
-
- info->arguments = g_strescape(tooltip.c_str(), "\\\"");
- g_strfreev(arguments);
-
- guint64 cpu_time = proctime.rtime;
- std::map<pid_t, guint64>::iterator it(ProcInfo::cpu_times.find(pid));
- if (it != ProcInfo::cpu_times.end())
- {
- if (proctime.rtime >= it->second)
- cpu_time = it->second;
- }
- info->cpu_time = cpu_time;
- info->start_time = proctime.start_time;
-
- get_process_selinux_context (info);
+ ProcInfo * const info = this;
+ glibtop_proc_state procstate;
+ glibtop_proc_time proctime;
+ glibtop_proc_args procargs;
+ gchar** arguments;
+
+ glibtop_get_proc_state (&procstate, pid);
+ glibtop_get_proc_time (&proctime, pid);
+ arguments = glibtop_get_proc_argv (&procargs, pid, 0);
+
+ /* FIXME : wrong. name and arguments may change with exec* */
+ get_process_name (info, procstate.cmd, static_cast<const GStrv>(arguments));
+
+ std::string tooltip = make_string(g_strjoinv(" ", arguments));
+ if (tooltip.empty())
+ tooltip = procstate.cmd;
+
+ info->tooltip = g_markup_escape_text(tooltip.c_str(), -1);
+
+ info->arguments = g_strescape(tooltip.c_str(), "\\\"");
+ g_strfreev(arguments);
+
+ guint64 cpu_time = proctime.rtime;
+ std::map<pid_t, guint64>::iterator it(ProcInfo::cpu_times.find(pid));
+ if (it != ProcInfo::cpu_times.end())
+ {
+ if (proctime.rtime >= it->second)
+ cpu_time = it->second;
+ }
+ info->cpu_time = cpu_time;
+ info->start_time = proctime.start_time;
+
+ get_process_selinux_context (info);
}
@@ -724,212 +724,212 @@ ProcInfo::ProcInfo(pid_t pid)
static void
refresh_list (ProcData *procdata, const pid_t* pid_list, const guint n)
{
- typedef std::list<ProcInfo*> ProcList;
- ProcList addition;
+ typedef std::list<ProcInfo*> ProcList;
+ ProcList addition;
- GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
- guint i;
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
+ guint i;
- // Add or update processes in the process list
- for(i = 0; i < n; ++i) {
- ProcInfo *info = ProcInfo::find(pid_list[i]);
-
- if (!info) {
- info = new ProcInfo(pid_list[i]);
- ProcInfo::all[info->pid] = info;
- addition.push_back(info);
- }
+ // Add or update processes in the process list
+ for(i = 0; i < n; ++i) {
+ ProcInfo *info = ProcInfo::find(pid_list[i]);
+
+ if (!info) {
+ info = new ProcInfo(pid_list[i]);
+ ProcInfo::all[info->pid] = info;
+ addition.push_back(info);
+ }
- update_info (procdata, info);
- }
+ update_info (procdata, info);
+ }
- // Remove dead processes from the process list and from the
- // tree. children are queued to be readded at the right place
- // in the tree.
+ // Remove dead processes from the process list and from the
+ // tree. children are queued to be readded at the right place
+ // in the tree.
- const std::set<pid_t> pids(pid_list, pid_list + n);
+ const std::set<pid_t> pids(pid_list, pid_list + n);
- ProcInfo::Iterator it(ProcInfo::begin());
+ ProcInfo::Iterator it(ProcInfo::begin());
- while (it != ProcInfo::end()) {
- ProcInfo * const info = it->second;
- ProcInfo::Iterator next(it);
- ++next;
+ while (it != ProcInfo::end()) {
+ ProcInfo * const info = it->second;
+ ProcInfo::Iterator next(it);
+ ++next;
- if (pids.find(info->pid) == pids.end()) {
- procman_debug("ripping %d", info->pid);
- remove_info_from_tree(procdata, model, info, addition);
- addition.remove(info);
- ProcInfo::all.erase(it);
- delete info;
- }
+ if (pids.find(info->pid) == pids.end()) {
+ procman_debug("ripping %d", info->pid);
+ remove_info_from_tree(procdata, model, info, addition);
+ addition.remove(info);
+ ProcInfo::all.erase(it);
+ delete info;
+ }
- it = next;
- }
+ it = next;
+ }
- // INVARIANT
- // pid_list == ProcInfo::all + addition
+ // INVARIANT
+ // pid_list == ProcInfo::all + addition
- if (procdata->config.show_tree) {
+ if (procdata->config.show_tree) {
- // insert process in the tree. walk through the addition list
- // (new process + process that have a new parent). This loop
- // handles the dependencies because we cannot insert a process
- // until its parent is in the tree.
+ // insert process in the tree. walk through the addition list
+ // (new process + process that have a new parent). This loop
+ // handles the dependencies because we cannot insert a process
+ // until its parent is in the tree.
- std::set<pid_t> in_tree(pids);
+ std::set<pid_t> in_tree(pids);
- for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
- in_tree.erase((*it)->pid);
+ for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
+ in_tree.erase((*it)->pid);
- while (not addition.empty()) {
- procman_debug("looking for %d parents", int(addition.size()));
- ProcList::iterator it(addition.begin());
+ while (not addition.empty()) {
+ procman_debug("looking for %d parents", int(addition.size()));
+ ProcList::iterator it(addition.begin());
- while (it != addition.end()) {
- procman_debug("looking for %d's parent with ppid %d",
- int((*it)->pid), int((*it)->ppid));
+ while (it != addition.end()) {
+ procman_debug("looking for %d's parent with ppid %d",
+ int((*it)->pid), int((*it)->ppid));
- // inserts the process in the treeview if :
- // - it is init
- // - its parent is already in tree
- // - its parent is unreachable
- //
- // rounds == 2 means that addition contains processes with
- // unreachable parents
- //
- // FIXME: this is broken if the unreachable parent becomes active
- // i.e. it gets active or changes ower
- // so we just clear the tree on __each__ update
- // see proctable_update_list (ProcData * const procdata)
+ // inserts the process in the treeview if :
+ // - it is init
+ // - its parent is already in tree
+ // - its parent is unreachable
+ //
+ // rounds == 2 means that addition contains processes with
+ // unreachable parents
+ //
+ // FIXME: this is broken if the unreachable parent becomes active
+ // i.e. it gets active or changes ower
+ // so we just clear the tree on __each__ update
+ // see proctable_update_list (ProcData * const procdata)
- if ((*it)->ppid == 0 or in_tree.find((*it)->ppid) != in_tree.end()) {
- insert_info_to_tree(*it, procdata);
- in_tree.insert((*it)->pid);
- it = addition.erase(it);
- continue;
- }
+ if ((*it)->ppid == 0 or in_tree.find((*it)->ppid) != in_tree.end()) {
+ insert_info_to_tree(*it, procdata);
+ in_tree.insert((*it)->pid);
+ it = addition.erase(it);
+ continue;
+ }
- ProcInfo *parent = ProcInfo::find((*it)->ppid);
- // if the parent is unreachable
- if (not parent) {
- // or std::find(addition.begin(), addition.end(), parent) == addition.end()) {
- insert_info_to_tree(*it, procdata, true);
- in_tree.insert((*it)->pid);
- it = addition.erase(it);
- continue;
- }
-
- ++it;
- }
- }
- }
- else {
- // don't care of the tree
- for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
- insert_info_to_tree(*it, procdata);
- }
+ ProcInfo *parent = ProcInfo::find((*it)->ppid);
+ // if the parent is unreachable
+ if (not parent) {
+ // or std::find(addition.begin(), addition.end(), parent) == addition.end()) {
+ insert_info_to_tree(*it, procdata, true);
+ in_tree.insert((*it)->pid);
+ it = addition.erase(it);
+ continue;
+ }
+
+ ++it;
+ }
+ }
+ }
+ else {
+ // don't care of the tree
+ for (ProcList::iterator it(addition.begin()); it != addition.end(); ++it)
+ insert_info_to_tree(*it, procdata);
+ }
- for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it)
- update_info_mutable_cols(it->second);
+ for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it)
+ update_info_mutable_cols(it->second);
}
void
proctable_update_list (ProcData * const procdata)
{
- pid_t* pid_list;
- glibtop_proclist proclist;
- glibtop_cpu cpu;
- gint which, arg;
- procman::SelectionMemento selection;
-
- switch (procdata->config.whose_process) {
- case ALL_PROCESSES:
- which = GLIBTOP_KERN_PROC_ALL;
- arg = 0;
- break;
-
- case ACTIVE_PROCESSES:
- which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
- arg = 0;
- if (procdata->config.show_tree)
- {
- selection.save(procdata->tree);
- proctable_clear_tree(procdata);
- }
- break;
-
- default:
- which = GLIBTOP_KERN_PROC_UID;
- arg = getuid ();
- if (procdata->config.show_tree)
- {
- selection.save(procdata->tree);
- proctable_clear_tree(procdata);
- }
- break;
- }
-
- pid_list = glibtop_get_proclist (&proclist, which, arg);
-
- /* FIXME: total cpu time elapsed should be calculated on an individual basis here
- ** should probably have a total_time_last gint in the ProcInfo structure */
- glibtop_get_cpu (&cpu);
- procdata->cpu_total_time = MAX(cpu.total - procdata->cpu_total_time_last, 1);
- procdata->cpu_total_time_last = cpu.total;
-
- refresh_list (procdata, pid_list, proclist.number);
-
- selection.restore(procdata->tree);
-
- g_free (pid_list);
-
- /* proclist.number == g_list_length(procdata->info) == g_hash_table_size(procdata->pids) */
+ pid_t* pid_list;
+ glibtop_proclist proclist;
+ glibtop_cpu cpu;
+ gint which, arg;
+ procman::SelectionMemento selection;
+
+ switch (procdata->config.whose_process) {
+ case ALL_PROCESSES:
+ which = GLIBTOP_KERN_PROC_ALL;
+ arg = 0;
+ break;
+
+ case ACTIVE_PROCESSES:
+ which = GLIBTOP_KERN_PROC_ALL | GLIBTOP_EXCLUDE_IDLE;
+ arg = 0;
+ if (procdata->config.show_tree)
+ {
+ selection.save(procdata->tree);
+ proctable_clear_tree(procdata);
+ }
+ break;
+
+ default:
+ which = GLIBTOP_KERN_PROC_UID;
+ arg = getuid ();
+ if (procdata->config.show_tree)
+ {
+ selection.save(procdata->tree);
+ proctable_clear_tree(procdata);
+ }
+ break;
+ }
+
+ pid_list = glibtop_get_proclist (&proclist, which, arg);
+
+ /* FIXME: total cpu time elapsed should be calculated on an individual basis here
+ ** should probably have a total_time_last gint in the ProcInfo structure */
+ glibtop_get_cpu (&cpu);
+ procdata->cpu_total_time = MAX(cpu.total - procdata->cpu_total_time_last, 1);
+ procdata->cpu_total_time_last = cpu.total;
+
+ refresh_list (procdata, pid_list, proclist.number);
+
+ selection.restore(procdata->tree);
+
+ g_free (pid_list);
+
+ /* proclist.number == g_list_length(procdata->info) == g_hash_table_size(procdata->pids) */
}
void
proctable_update_all (ProcData * const procdata)
{
- char* string;
+ char* string;
- string = make_loadavg_string();
- gtk_label_set_text (GTK_LABEL(procdata->loadavg), string);
- g_free (string);
+ string = make_loadavg_string();
+ gtk_label_set_text (GTK_LABEL(procdata->loadavg), string);
+ g_free (string);
- proctable_update_list (procdata);
+ proctable_update_list (procdata);
}
void
proctable_clear_tree (ProcData * const procdata)
{
- GtkTreeModel *model;
+ GtkTreeModel *model;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (procdata->tree));
- gtk_tree_store_clear (GTK_TREE_STORE (model));
+ gtk_tree_store_clear (GTK_TREE_STORE (model));
- proctable_free_table (procdata);
+ proctable_free_table (procdata);
- update_sensitivity(procdata);
+ update_sensitivity(procdata);
}
void
proctable_free_table (ProcData * const procdata)
{
- for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it)
- delete it->second;
+ for (ProcInfo::Iterator it(ProcInfo::begin()); it != ProcInfo::end(); ++it)
+ delete it->second;
- ProcInfo::all.clear();
+ ProcInfo::all.clear();
}
@@ -937,16 +937,16 @@ proctable_free_table (ProcData * const procdata)
char*
make_loadavg_string(void)
{
- glibtop_loadavg buf;
+ glibtop_loadavg buf;
- glibtop_get_loadavg(&buf);
+ glibtop_get_loadavg(&buf);
- return g_strdup_printf(
- _("Load averages for the last 1, 5, 15 minutes: "
- "%0.2f, %0.2f, %0.2f"),
- buf.loadavg[0],
- buf.loadavg[1],
- buf.loadavg[2]);
+ return g_strdup_printf(
+ _("Load averages for the last 1, 5, 15 minutes: "
+ "%0.2f, %0.2f, %0.2f"),
+ buf.loadavg[0],
+ buf.loadavg[1],
+ buf.loadavg[2]);
}
@@ -959,6 +959,6 @@ ProcInfo::set_icon(Glib::RefPtr<Gdk::Pixbuf> icon)
GtkTreeModel *model;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(ProcData::get_instance()->tree));
gtk_tree_store_set(GTK_TREE_STORE(model), &this->node,
- COL_PIXBUF, (this->pixbuf ? this->pixbuf->gobj() : NULL),
- -1);
+ COL_PIXBUF, (this->pixbuf ? this->pixbuf->gobj() : NULL),
+ -1);
}
diff --git a/src/proctable.h b/src/proctable.h
index e502ba1..9c90669 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -26,40 +26,40 @@
enum
{
- COL_NAME = 0,
- COL_USER,
- COL_STATUS,
- COL_VMSIZE,
- COL_MEMRES,
- COL_MEMWRITABLE,
- COL_MEMSHARED,
- COL_MEMXSERVER,
- COL_CPU,
- COL_CPU_TIME,
- COL_START_TIME,
- COL_NICE,
- COL_PID,
- COL_SECURITYCONTEXT,
- COL_ARGS,
- COL_MEM,
- COL_WCHAN,
- COL_PIXBUF,
- COL_POINTER,
- COL_TOOLTIP,
- NUM_COLUMNS
+ COL_NAME = 0,
+ COL_USER,
+ COL_STATUS,
+ COL_VMSIZE,
+ COL_MEMRES,
+ COL_MEMWRITABLE,
+ COL_MEMSHARED,
+ COL_MEMXSERVER,
+ COL_CPU,
+ COL_CPU_TIME,
+ COL_START_TIME,
+ COL_NICE,
+ COL_PID,
+ COL_SECURITYCONTEXT,
+ COL_ARGS,
+ COL_MEM,
+ COL_WCHAN,
+ COL_PIXBUF,
+ COL_POINTER,
+ COL_TOOLTIP,
+ NUM_COLUMNS
};
-GtkWidget* proctable_new (ProcData *data);
-void proctable_update_table (ProcData *data);
-void proctable_update_list (ProcData *data);
-void proctable_update_all (ProcData *data);
-void proctable_clear_tree (ProcData *data);
-void proctable_free_table (ProcData *data);
+GtkWidget* proctable_new (ProcData *data);
+void proctable_update_table (ProcData *data);
+void proctable_update_list (ProcData *data);
+void proctable_update_all (ProcData *data);
+void proctable_clear_tree (ProcData *data);
+void proctable_free_table (ProcData *data);
-GSList* proctable_get_columns_order(GtkTreeView *treeview);
-void proctable_set_columns_order(GtkTreeView *treeview, GSList *order);
+GSList* proctable_get_columns_order(GtkTreeView *treeview);
+void proctable_set_columns_order(GtkTreeView *treeview, GSList *order);
-char* make_loadavg_string(void);
+char* make_loadavg_string(void);
#endif /* _PROCMAN_PROCTABLE_H_ */
diff --git a/src/selection.cpp b/src/selection.cpp
index 6f293a6..7e15a9e 100644
--- a/src/selection.cpp
+++ b/src/selection.cpp
@@ -6,38 +6,38 @@
namespace procman
{
- void SelectionMemento::add_to_selected(GtkTreeModel* model, GtkTreePath*, GtkTreeIter* iter, gpointer data)
- {
- guint pid = 0;
- gtk_tree_model_get(model, iter, COL_PID, &pid, -1);
- if (pid)
- static_cast<SelectionMemento*>(data)->pids.push_back(pid);
- }
+ void SelectionMemento::add_to_selected(GtkTreeModel* model, GtkTreePath*, GtkTreeIter* iter, gpointer data)
+ {
+ guint pid = 0;
+ gtk_tree_model_get(model, iter, COL_PID, &pid, -1);
+ if (pid)
+ static_cast<SelectionMemento*>(data)->pids.push_back(pid);
+ }
- void SelectionMemento::save(GtkWidget* tree)
- {
- GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
- gtk_tree_selection_selected_foreach(selection, &SelectionMemento::add_to_selected, this);
- }
+ void SelectionMemento::save(GtkWidget* tree)
+ {
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
+ gtk_tree_selection_selected_foreach(selection, &SelectionMemento::add_to_selected, this);
+ }
- void SelectionMemento::restore(GtkWidget* tree)
- {
- if (not this->pids.empty())
- {
- GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
- typedef std::vector<pid_t>::iterator iterator;
- for (iterator it(this->pids.begin()); it != this->pids.end(); ++it)
- {
- if (ProcInfo* proc = ProcInfo::find(*it))
- {
- gtk_tree_selection_select_iter(selection, &proc->node);
- procman_debug("Re-selected process %u", unsigned(*it));
- }
- else
- procman_debug("Could not find process %u, cannot re-select it", unsigned(*it));
- }
- }
- }
+ void SelectionMemento::restore(GtkWidget* tree)
+ {
+ if (not this->pids.empty())
+ {
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
+ typedef std::vector<pid_t>::iterator iterator;
+ for (iterator it(this->pids.begin()); it != this->pids.end(); ++it)
+ {
+ if (ProcInfo* proc = ProcInfo::find(*it))
+ {
+ gtk_tree_selection_select_iter(selection, &proc->node);
+ procman_debug("Re-selected process %u", unsigned(*it));
+ }
+ else
+ procman_debug("Could not find process %u, cannot re-select it", unsigned(*it));
+ }
+ }
+ }
}
diff --git a/src/selection.h b/src/selection.h
index 1dd3470..a292205 100644
--- a/src/selection.h
+++ b/src/selection.h
@@ -7,15 +7,15 @@
namespace procman
{
- class SelectionMemento
- {
- std::vector<pid_t> pids;
- static void add_to_selected(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer data);
+ class SelectionMemento
+ {
+ std::vector<pid_t> pids;
+ static void add_to_selected(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer data);
- public:
- void save(GtkWidget* tree);
- void restore(GtkWidget* tree);
- };
+ public:
+ void save(GtkWidget* tree);
+ void restore(GtkWidget* tree);
+ };
}
#endif /* H_MATE_SYSTEM_MONITOR_SELECTION_H_1183113337 */
diff --git a/src/selinux.cpp b/src/selinux.cpp
index 6bfee5a..f9eaddf 100644
--- a/src/selinux.cpp
+++ b/src/selinux.cpp
@@ -15,11 +15,11 @@ static gboolean has_selinux;
static gboolean load_selinux(void)
{
- return load_symbols("libselinux.so.1",
- "getpidcon", &getpidcon,
- "freecon", &freecon,
- "is_selinux_enabled", &is_selinux_enabled,
- NULL);
+ return load_symbols("libselinux.so.1",
+ "getpidcon", &getpidcon,
+ "freecon", &freecon,
+ "is_selinux_enabled", &is_selinux_enabled,
+ NULL);
}
@@ -27,12 +27,12 @@ static gboolean load_selinux(void)
void
get_process_selinux_context (ProcInfo *info)
{
- char *con;
+ char *con;
- if (has_selinux && !getpidcon (info->pid, &con)) {
- info->security_context = g_strdup (con);
- freecon (con);
- }
+ if (has_selinux && !getpidcon (info->pid, &con)) {
+ info->security_context = g_strdup (con);
+ freecon (con);
+ }
}
@@ -40,25 +40,25 @@ get_process_selinux_context (ProcInfo *info)
gboolean
can_show_security_context_column (void)
{
- if (!(has_selinux = load_selinux()))
- return FALSE;
+ if (!(has_selinux = load_selinux()))
+ return FALSE;
- switch (is_selinux_enabled()) {
- case 1:
- /* We're running on an SELinux kernel */
- return TRUE;
+ switch (is_selinux_enabled()) {
+ case 1:
+ /* We're running on an SELinux kernel */
+ return TRUE;
- case -1:
- /* Error; hide the security context column */
+ case -1:
+ /* Error; hide the security context column */
- case 0:
- /* We're not running on an SELinux kernel:
- hide the security context column */
+ case 0:
+ /* We're not running on an SELinux kernel:
+ hide the security context column */
- default:
- g_warning("SELinux was found but is not enabled.\n");
- return FALSE;
- }
+ default:
+ g_warning("SELinux was found but is not enabled.\n");
+ return FALSE;
+ }
}
diff --git a/src/settings-keys.cpp b/src/settings-keys.cpp
index 7d8ef1a..62f6264 100644
--- a/src/settings-keys.cpp
+++ b/src/settings-keys.cpp
@@ -3,12 +3,12 @@
namespace procman
{
- namespace settings
- {
- const std::string root("/org/mate/mate-system-monitor");
- const std::string solaris_mode("solaris-mode");
- const std::string open_files_tree_prefix("openfilestree");
- const std::string network_in_bits("network-in-bits");
- }
+ namespace settings
+ {
+ const std::string root("/org/mate/mate-system-monitor");
+ const std::string solaris_mode("solaris-mode");
+ const std::string open_files_tree_prefix("openfilestree");
+ const std::string network_in_bits("network-in-bits");
+ }
}
diff --git a/src/settings-keys.h b/src/settings-keys.h
index 0e5f8e1..d01a33a 100644
--- a/src/settings-keys.h
+++ b/src/settings-keys.h
@@ -6,13 +6,13 @@
namespace procman
{
- namespace settings
- {
- extern const std::string root;
- extern const std::string solaris_mode;
- extern const std::string open_files_tree_prefix;
- extern const std::string network_in_bits;
- }
+ namespace settings
+ {
+ extern const std::string root;
+ extern const std::string solaris_mode;
+ extern const std::string open_files_tree_prefix;
+ extern const std::string network_in_bits;
+ }
}
diff --git a/src/smooth_refresh.cpp b/src/smooth_refresh.cpp
index 484aa67..8f6307c 100644
--- a/src/smooth_refresh.cpp
+++ b/src/smooth_refresh.cpp
@@ -20,25 +20,25 @@ const string SmoothRefresh::KEY("smooth-refresh");
unsigned SmoothRefresh::get_own_cpu_usage()
{
- glibtop_cpu cpu;
- glibtop_proc_time proctime;
- guint64 elapsed;
- unsigned usage = PCPU_LO;
+ glibtop_cpu cpu;
+ glibtop_proc_time proctime;
+ guint64 elapsed;
+ unsigned usage = PCPU_LO;
- glibtop_get_cpu (&cpu);
- elapsed = cpu.total - this->last_total_time;
+ glibtop_get_cpu (&cpu);
+ elapsed = cpu.total - this->last_total_time;
- if (elapsed) { // avoid division by 0
- glibtop_get_proc_time(&proctime, getpid());
- usage = (proctime.rtime - this->last_cpu_time) * 100 / elapsed;
- }
+ if (elapsed) { // avoid division by 0
+ glibtop_get_proc_time(&proctime, getpid());
+ usage = (proctime.rtime - this->last_cpu_time) * 100 / elapsed;
+ }
- usage = CLAMP(usage, 0, 100);
+ usage = CLAMP(usage, 0, 100);
- this->last_total_time = cpu.total;
- this->last_cpu_time = proctime.rtime;
+ this->last_total_time = cpu.total;
+ this->last_cpu_time = proctime.rtime;
- return usage;
+ return usage;
}
@@ -47,25 +47,25 @@ void SmoothRefresh::status_changed(GSettings *settings,
const gchar *key,
gpointer user_data)
{
- static_cast<SmoothRefresh*>(user_data)->load_settings_value(key);
+ static_cast<SmoothRefresh*>(user_data)->load_settings_value(key);
}
void SmoothRefresh::load_settings_value(const gchar *key)
{
- this->active = g_settings_get_boolean(settings, key);
+ this->active = g_settings_get_boolean(settings, key);
- if (this->active)
- procman_debug("smooth_refresh is enabled");
+ if (this->active)
+ procman_debug("smooth_refresh is enabled");
}
SmoothRefresh::SmoothRefresh(GSettings *a_settings)
-:
- settings(a_settings)
+ :
+ settings(a_settings)
{
- this->connection = g_signal_connect(G_OBJECT(settings),
- "changed::smooth-refresh",
- G_CALLBACK(status_changed),
- this);
+ this->connection = g_signal_connect(G_OBJECT(settings),
+ "changed::smooth-refresh",
+ G_CALLBACK(status_changed),
+ this);
this->reset();
this->load_settings_value(KEY.c_str());
@@ -75,24 +75,24 @@ SmoothRefresh::SmoothRefresh(GSettings *a_settings)
void SmoothRefresh::reset()
{
- glibtop_cpu cpu;
- glibtop_proc_time proctime;
+ glibtop_cpu cpu;
+ glibtop_proc_time proctime;
- glibtop_get_cpu(&cpu);
- glibtop_get_proc_time(&proctime, getpid());
+ glibtop_get_cpu(&cpu);
+ glibtop_get_proc_time(&proctime, getpid());
- this->interval = ProcData::get_instance()->config.update_interval;
- this->last_pcpu = PCPU_LO;
- this->last_total_time = cpu.total;
- this->last_cpu_time = proctime.rtime;
+ this->interval = ProcData::get_instance()->config.update_interval;
+ this->last_pcpu = PCPU_LO;
+ this->last_total_time = cpu.total;
+ this->last_cpu_time = proctime.rtime;
}
SmoothRefresh::~SmoothRefresh()
{
- if (this->connection)
- g_signal_handler_disconnect(G_OBJECT(settings), this->connection);
+ if (this->connection)
+ g_signal_handler_disconnect(G_OBJECT(settings), this->connection);
}
@@ -100,59 +100,59 @@ SmoothRefresh::~SmoothRefresh()
bool
SmoothRefresh::get(guint &new_interval)
{
- const unsigned config_interval = ProcData::get_instance()->config.update_interval;
+ const unsigned config_interval = ProcData::get_instance()->config.update_interval;
- g_assert(this->interval >= config_interval);
+ g_assert(this->interval >= config_interval);
- if (not this->active)
- return false;
+ if (not this->active)
+ return false;
- const unsigned pcpu = this->get_own_cpu_usage();
- /*
- invariant: MAX_UPDATE_INTERVAL >= interval >= config_interval >= MIN_UPDATE_INTERVAL
+ const unsigned pcpu = this->get_own_cpu_usage();
+ /*
+ invariant: MAX_UPDATE_INTERVAL >= interval >= config_interval >= MIN_UPDATE_INTERVAL
- i see 3 cases:
+ i see 3 cases:
- a) interval is too big (CPU usage < 10%)
- -> increase interval
+ a) interval is too big (CPU usage < 10%)
+ -> increase interval
- b) interval is too small (CPU usage > 10%) AND interval != config_interval
- >
- -> decrease interval
+ b) interval is too small (CPU usage > 10%) AND interval != config_interval
+ >
+ -> decrease interval
- c) interval is config_interval (start or interval is perfect)
+ c) interval is config_interval (start or interval is perfect)
- */
+ */
- if (pcpu > PCPU_HI && this->last_pcpu > PCPU_HI)
- new_interval = this->interval * 11 / 10;
- else if (this->interval != config_interval && pcpu < PCPU_LO && this->last_pcpu < PCPU_LO)
- new_interval = this->interval * 9 / 10;
- else
- new_interval = this->interval;
+ if (pcpu > PCPU_HI && this->last_pcpu > PCPU_HI)
+ new_interval = this->interval * 11 / 10;
+ else if (this->interval != config_interval && pcpu < PCPU_LO && this->last_pcpu < PCPU_LO)
+ new_interval = this->interval * 9 / 10;
+ else
+ new_interval = this->interval;
- new_interval = CLAMP(new_interval, config_interval, config_interval * 2);
- new_interval = CLAMP(new_interval, MIN_UPDATE_INTERVAL, MAX_UPDATE_INTERVAL);
+ new_interval = CLAMP(new_interval, config_interval, config_interval * 2);
+ new_interval = CLAMP(new_interval, MIN_UPDATE_INTERVAL, MAX_UPDATE_INTERVAL);
- bool changed = this->interval != new_interval;
+ bool changed = this->interval != new_interval;
- if (changed)
- this->interval = new_interval;
+ if (changed)
+ this->interval = new_interval;
- this->last_pcpu = pcpu;
+ this->last_pcpu = pcpu;
- if (changed) {
- procman_debug("CPU usage is %3u%%, changed refresh_interval to %u (config %u)",
- this->last_pcpu,
- this->interval,
- config_interval);
- }
+ if (changed) {
+ procman_debug("CPU usage is %3u%%, changed refresh_interval to %u (config %u)",
+ this->last_pcpu,
+ this->interval,
+ config_interval);
+ }
- g_assert(this->interval == new_interval);
- g_assert(this->interval >= config_interval);
+ g_assert(this->interval == new_interval);
+ g_assert(this->interval >= config_interval);
- return changed;
+ return changed;
}
diff --git a/src/smooth_refresh.h b/src/smooth_refresh.h
index eed5227..92039e0 100644
--- a/src/smooth_refresh.h
+++ b/src/smooth_refresh.h
@@ -11,92 +11,92 @@ using std::string;
class SmoothRefresh
{
-public:
+ public:
- /*
- smooth_refresh_new
+ /*
+ smooth_refresh_new
- @config_interval : pointer to config_interval so we can observe
- config_interval changes.
+ @config_interval : pointer to config_interval so we can observe
+ config_interval changes.
- @return : initialized SmoothRefresh
- */
- SmoothRefresh(GSettings *a_settings);
+ @return : initialized SmoothRefresh
+ */
+ SmoothRefresh(GSettings *a_settings);
- ~SmoothRefresh();
+ ~SmoothRefresh();
- /*
- smooth_refresh_reset
+ /*
+ smooth_refresh_reset
- Resets state and re-read config_interval
- */
- void reset();
+ Resets state and re-read config_interval
+ */
+ void reset();
- /*
- smooth_refresh_get
+ /*
+ smooth_refresh_get
- Computes the new refresh_interval so that CPU usage is lower than
- SMOOTH_REFRESH_PCPU.
+ Computes the new refresh_interval so that CPU usage is lower than
+ SMOOTH_REFRESH_PCPU.
- @new_interval : where the new refresh_interval is stored.
+ @new_interval : where the new refresh_interval is stored.
- @return : TRUE is refresh_interval has changed. The new refresh_interval
- is stored in @new_interval. Else FALSE;
- */
- bool get(guint &new_interval);
+ @return : TRUE is refresh_interval has changed. The new refresh_interval
+ is stored in @new_interval. Else FALSE;
+ */
+ bool get(guint &new_interval);
- static const string KEY;
- static const bool KEY_DEFAULT_VALUE;
+ static const string KEY;
+ static const bool KEY_DEFAULT_VALUE;
-private:
+ private:
- unsigned get_own_cpu_usage();
+ unsigned get_own_cpu_usage();
- static void status_changed(GSettings *settings,
- const gchar *key,
- gpointer user_data);
+ static void status_changed(GSettings *settings,
+ const gchar *key,
+ gpointer user_data);
- void load_settings_value(const gchar *key);
+ void load_settings_value(const gchar *key);
- /*
- fuzzy logic:
- - decrease refresh interval only if current CPU% and last CPU%
- are higher than PCPU_LO
- - increase refresh interval only if current CPU% and last CPU%
- are higher than PCPU_HI
+ /*
+ fuzzy logic:
+ - decrease refresh interval only if current CPU% and last CPU%
+ are higher than PCPU_LO
+ - increase refresh interval only if current CPU% and last CPU%
+ are higher than PCPU_HI
- */
+ */
- enum
+ enum
{
- PCPU_HI = 22,
- PCPU_LO = 18
+ PCPU_HI = 22,
+ PCPU_LO = 18
};
- /*
- -self : procman's PID (so we call getpid() only once)
+ /*
+ -self : procman's PID (so we call getpid() only once)
- -interval : current refresh interval
+ -interval : current refresh interval
- -config_interval : pointer to the configuration refresh interval.
- Used to watch configuration changes
+ -config_interval : pointer to the configuration refresh interval.
+ Used to watch configuration changes
- -interval >= -config_interval
+ -interval >= -config_interval
- -last_pcpu : to avoid spikes, the last CPU%. See PCPU_{LO,HI}
+ -last_pcpu : to avoid spikes, the last CPU%. See PCPU_{LO,HI}
- -last_total_time:
- -last_cpu_time: Save last cpu and process times to compute CPU%
- */
+ -last_total_time:
+ -last_cpu_time: Save last cpu and process times to compute CPU%
+ */
- GSettings *settings;
- bool active;
- guint connection;
- guint interval;
- unsigned last_pcpu;
- guint64 last_total_time;
- guint64 last_cpu_time;
+ GSettings *settings;
+ bool active;
+ guint connection;
+ guint interval;
+ unsigned last_pcpu;
+ guint64 last_total_time;
+ guint64 last_cpu_time;
};
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);
+ }
}
- }
}
diff --git a/src/sysinfo.h b/src/sysinfo.h
index 9ed9c1d..235ffee 100644
--- a/src/sysinfo.h
+++ b/src/sysinfo.h
@@ -3,7 +3,7 @@
namespace procman
{
- void build_sysinfo_ui();
+ void build_sysinfo_ui();
}
#endif /* H_MATE_SYSTEM_MONITOR_SYSINFO_H_1155594649 */
diff --git a/src/util.cpp b/src/util.cpp
index e27f43a..e991347 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -22,32 +22,32 @@ extern "C" {
static const char*
format_process_state(guint state)
{
- const char *status;
+ const char *status;
- switch (state)
- {
- case GLIBTOP_PROCESS_RUNNING:
- status = _("Running");
- break;
+ switch (state)
+ {
+ case GLIBTOP_PROCESS_RUNNING:
+ status = _("Running");
+ break;
- case GLIBTOP_PROCESS_STOPPED:
- status = _("Stopped");
- break;
+ case GLIBTOP_PROCESS_STOPPED:
+ status = _("Stopped");
+ break;
- case GLIBTOP_PROCESS_ZOMBIE:
- status = _("Zombie");
- break;
+ case GLIBTOP_PROCESS_ZOMBIE:
+ status = _("Zombie");
+ break;
- case GLIBTOP_PROCESS_UNINTERRUPTIBLE:
- status = _("Uninterruptible");
- break;
+ case GLIBTOP_PROCESS_UNINTERRUPTIBLE:
+ status = _("Uninterruptible");
+ break;
- default:
- status = _("Sleeping");
- break;
- }
+ default:
+ status = _("Sleeping");
+ break;
+ }
- return status;
+ return status;
}
@@ -55,29 +55,29 @@ format_process_state(guint state)
static char *
mnemonic_safe_process_name(const char *process_name)
{
- const char *p;
- GString *name;
+ const char *p;
+ GString *name;
- name = g_string_new ("");
+ name = g_string_new ("");
- for(p = process_name; *p; ++p)
- {
- g_string_append_c (name, *p);
+ for(p = process_name; *p; ++p)
+ {
+ g_string_append_c (name, *p);
- if(*p == '_')
- g_string_append_c (name, '_');
- }
+ if(*p == '_')
+ g_string_append_c (name, '_');
+ }
- return g_string_free (name, FALSE);
+ return g_string_free (name, FALSE);
}
static inline unsigned divide(unsigned *q, unsigned *r, unsigned d)
{
- *q = *r / d;
- *r = *r % d;
- return *q != 0;
+ *q = *r / d;
+ *r = *r % d;
+ return *q != 0;
}
@@ -88,49 +88,49 @@ static inline unsigned divide(unsigned *q, unsigned *r, unsigned d)
static char *
format_duration_for_display(unsigned centiseconds)
{
- unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
+ unsigned weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
- (void)(divide(&seconds, &centiseconds, 100)
- && divide(&minutes, &seconds, 60)
- && divide(&hours, &minutes, 60)
- && divide(&days, &hours, 24)
- && divide(&weeks, &days, 7));
+ (void)(divide(&seconds, &centiseconds, 100)
+ && divide(&minutes, &seconds, 60)
+ && divide(&hours, &minutes, 60)
+ && divide(&days, &hours, 24)
+ && divide(&weeks, &days, 7));
- if (weeks)
- /* xgettext: weeks, days */
- return g_strdup_printf(_("%uw%ud"), weeks, days);
+ if (weeks)
+ /* xgettext: weeks, days */
+ return g_strdup_printf(_("%uw%ud"), weeks, days);
- if (days)
- /* xgettext: days, hours (0 -> 23) */
- return g_strdup_printf(_("%ud%02uh"), days, hours);
+ if (days)
+ /* xgettext: days, hours (0 -> 23) */
+ return g_strdup_printf(_("%ud%02uh"), days, hours);
- if (hours)
- /* xgettext: hours (0 -> 23), minutes, seconds */
- return g_strdup_printf(_("%u:%02u:%02u"), hours, minutes, seconds);
+ if (hours)
+ /* xgettext: hours (0 -> 23), minutes, seconds */
+ return g_strdup_printf(_("%u:%02u:%02u"), hours, minutes, seconds);
- /* xgettext: minutes, seconds, centiseconds */
- return g_strdup_printf(_("%u:%02u.%02u"), minutes, seconds, centiseconds);
+ /* xgettext: minutes, seconds, centiseconds */
+ return g_strdup_printf(_("%u:%02u.%02u"), minutes, seconds, centiseconds);
}
GtkWidget*
procman_make_label_for_mmaps_or_ofiles(const char *format,
- const char *process_name,
- unsigned pid)
+ const char *process_name,
+ unsigned pid)
{
- GtkWidget *label;
- char *name, *title;
+ GtkWidget *label;
+ char *name, *title;
- name = mnemonic_safe_process_name (process_name);
- title = g_strdup_printf(format, name, pid);
- label = gtk_label_new_with_mnemonic (title);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+ name = mnemonic_safe_process_name (process_name);
+ title = g_strdup_printf(format, name, pid);
+ label = gtk_label_new_with_mnemonic (title);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
- g_free (title);
- g_free (name);
+ g_free (title);
+ g_free (name);
- return label;
+ return label;
}
@@ -138,11 +138,11 @@ procman_make_label_for_mmaps_or_ofiles(const char *format,
/**
* procman::format_size:
* @size:
- *
+ *
* Formats the file size passed in @bytes in a way that is easy for
* the user to read. Gives the size in bytes, kibibytes, mebibytes or
* gibibytes, choosing whatever is appropriate.
- *
+ *
* Returns: a newly allocated string with the size ready to be shown.
**/
@@ -150,64 +150,64 @@ gchar*
procman::format_size(guint64 size, guint64 max_size, bool want_bits)
{
- enum {
- K_INDEX,
- M_INDEX,
- G_INDEX,
+ enum {
+ K_INDEX,
+ M_INDEX,
+ G_INDEX,
T_INDEX
- };
-
- struct Format {
- guint64 factor;
- const char* string;
- };
-
- const Format all_formats[2][4] = {
- { { G_GUINT64_CONSTANT(1) << 10, N_("%.1f KiB") },
- { G_GUINT64_CONSTANT(1) << 20, N_("%.1f MiB") },
- { G_GUINT64_CONSTANT(1) << 30, N_("%.1f GiB") },
- { G_GUINT64_CONSTANT(1) << 40, N_("%.1f TiB") } },
- { { G_GUINT64_CONSTANT(1000), N_("%.1f kbit") },
- { G_GUINT64_CONSTANT(1000000), N_("%.1f Mbit") },
- { G_GUINT64_CONSTANT(1000000000), N_("%.1f Gbit") },
- { G_GUINT64_CONSTANT(1000000000000), N_("%.1f Tbit") } }
- };
-
- const Format (&formats)[4] = all_formats[want_bits ? 1 : 0];
-
- if (want_bits) {
- size *= 8;
- max_size *= 8;
- }
-
- if (max_size == 0)
- max_size = size;
-
- if (max_size < formats[K_INDEX].factor) {
- const char *format = (want_bits
- ? dngettext(GETTEXT_PACKAGE, "%u bit", "%u bits", (guint) size)
- : dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size));
- return g_strdup_printf (format, (guint) size);
- } else {
- guint64 factor;
- const char* format = NULL;
-
- if (max_size < formats[M_INDEX].factor) {
- factor = formats[K_INDEX].factor;
- format = formats[K_INDEX].string;
- } else if (max_size < formats[G_INDEX].factor) {
- factor = formats[M_INDEX].factor;
- format = formats[M_INDEX].string;
- } else if (max_size < formats[T_INDEX].factor) {
- factor = formats[G_INDEX].factor;
- format = formats[G_INDEX].string;
- } else {
- factor = formats[T_INDEX].factor;
- format = formats[T_INDEX].string;
- }
-
- return g_strdup_printf(_(format), size / (double)factor);
- }
+ };
+
+ struct Format {
+ guint64 factor;
+ const char* string;
+ };
+
+ const Format all_formats[2][4] = {
+ { { G_GUINT64_CONSTANT(1) << 10, N_("%.1f KiB") },
+ { G_GUINT64_CONSTANT(1) << 20, N_("%.1f MiB") },
+ { G_GUINT64_CONSTANT(1) << 30, N_("%.1f GiB") },
+ { G_GUINT64_CONSTANT(1) << 40, N_("%.1f TiB") } },
+ { { G_GUINT64_CONSTANT(1000), N_("%.1f kbit") },
+ { G_GUINT64_CONSTANT(1000000), N_("%.1f Mbit") },
+ { G_GUINT64_CONSTANT(1000000000), N_("%.1f Gbit") },
+ { G_GUINT64_CONSTANT(1000000000000), N_("%.1f Tbit") } }
+ };
+
+ const Format (&formats)[4] = all_formats[want_bits ? 1 : 0];
+
+ if (want_bits) {
+ size *= 8;
+ max_size *= 8;
+ }
+
+ if (max_size == 0)
+ max_size = size;
+
+ if (max_size < formats[K_INDEX].factor) {
+ const char *format = (want_bits
+ ? dngettext(GETTEXT_PACKAGE, "%u bit", "%u bits", (guint) size)
+ : dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size));
+ return g_strdup_printf (format, (guint) size);
+ } else {
+ guint64 factor;
+ const char* format = NULL;
+
+ if (max_size < formats[M_INDEX].factor) {
+ factor = formats[K_INDEX].factor;
+ format = formats[K_INDEX].string;
+ } else if (max_size < formats[G_INDEX].factor) {
+ factor = formats[M_INDEX].factor;
+ format = formats[M_INDEX].string;
+ } else if (max_size < formats[T_INDEX].factor) {
+ factor = formats[G_INDEX].factor;
+ format = formats[G_INDEX].string;
+ } else {
+ factor = formats[T_INDEX].factor;
+ format = formats[T_INDEX].string;
+ }
+
+ return g_strdup_printf(_(format), size / (double)factor);
+ }
}
@@ -215,307 +215,305 @@ procman::format_size(guint64 size, guint64 max_size, bool want_bits)
gboolean
load_symbols(const char *module, ...)
{
- GModule *mod;
- gboolean found_all = TRUE;
- va_list args;
+ GModule *mod;
+ gboolean found_all = TRUE;
+ va_list args;
- mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL));
+ mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL));
- if (!mod)
- return FALSE;
+ if (!mod)
+ return FALSE;
- procman_debug("Found %s", module);
+ procman_debug("Found %s", module);
- va_start(args, module);
+ va_start(args, module);
- while (1) {
- const char *name;
- void **symbol;
+ while (1) {
+ const char *name;
+ void **symbol;
- name = va_arg(args, char*);
+ name = va_arg(args, char*);
- if (!name)
- break;
+ if (!name)
+ break;
- symbol = va_arg(args, void**);
+ symbol = va_arg(args, void**);
- if (g_module_symbol(mod, name, symbol)) {
- procman_debug("Loaded %s from %s", name, module);
- }
- else {
- procman_debug("Could not load %s from %s", name, module);
- found_all = FALSE;
- break;
- }
- }
+ if (g_module_symbol(mod, name, symbol)) {
+ procman_debug("Loaded %s from %s", name, module);
+ }
+ else {
+ procman_debug("Could not load %s from %s", name, module);
+ found_all = FALSE;
+ break;
+ }
+ }
- va_end(args);
+ va_end(args);
- if (found_all)
- g_module_make_resident(mod);
- else
- g_module_close(mod);
+ if (found_all)
+ g_module_make_resident(mod);
+ else
+ g_module_close(mod);
- return found_all;
+ return found_all;
}
static gboolean
is_debug_enabled(void)
{
- static gboolean init;
- static gboolean enabled;
+ static gboolean init;
+ static gboolean enabled;
- if (!init) {
- enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL;
- init = TRUE;
- }
+ if (!init) {
+ enabled = g_getenv("MATE_SYSTEM_MONITOR_DEBUG") != NULL;
+ init = TRUE;
+ }
- return enabled;
+ return enabled;
}
static double get_relative_time(void)
{
- static unsigned long start_time;
- GTimeVal tv;
+ static unsigned long start_time;
+ GTimeVal tv;
- if (G_UNLIKELY(!start_time)) {
- glibtop_proc_time buf;
- glibtop_get_proc_time(&buf, getpid());
- start_time = buf.start_time;
- }
+ if (G_UNLIKELY(!start_time)) {
+ glibtop_proc_time buf;
+ glibtop_get_proc_time(&buf, getpid());
+ start_time = buf.start_time;
+ }
- g_get_current_time(&tv);
- return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec;
+ g_get_current_time(&tv);
+ return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec;
}
void
procman_debug_real(const char *file, int line, const char *func,
- const char *format, ...)
+ const char *format, ...)
{
- va_list args;
- char *msg;
+ va_list args;
+ char *msg;
- if (G_LIKELY(!is_debug_enabled()))
- return;
+ if (G_LIKELY(!is_debug_enabled()))
+ return;
- va_start(args, format);
- msg = g_strdup_vprintf(format, args);
- va_end(args);
+ va_start(args, format);
+ msg = g_strdup_vprintf(format, args);
+ va_end(args);
- g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg);
+ g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg);
- g_free(msg);
+ g_free(msg);
}
namespace procman
{
- void size_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data)
- {
- const guint index = GPOINTER_TO_UINT(user_data);
+ void size_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
- guint64 size;
- GValue value = { 0 };
+ guint64 size;
+ GValue value = { 0 };
- gtk_tree_model_get_value(model, iter, index, &value);
+ gtk_tree_model_get_value(model, iter, index, &value);
- switch (G_VALUE_TYPE(&value)) {
- case G_TYPE_ULONG:
- size = g_value_get_ulong(&value);
- break;
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_ULONG:
+ size = g_value_get_ulong(&value);
+ break;
- case G_TYPE_UINT64:
- size = g_value_get_uint64(&value);
- break;
+ case G_TYPE_UINT64:
+ size = g_value_get_uint64(&value);
+ break;
- default:
- g_assert_not_reached();
- }
+ default:
+ g_assert_not_reached();
+ }
- g_value_unset(&value);
+ g_value_unset(&value);
- char *str = procman::format_size(size);
- g_object_set(renderer, "text", str, NULL);
- g_free(str);
- }
+ char *str = procman::format_size(size);
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
+ }
- /*
- Same as above but handles size == 0 as not available
- */
- void size_na_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data)
- {
- const guint index = GPOINTER_TO_UINT(user_data);
+ /*
+ Same as above but handles size == 0 as not available
+ */
+ void size_na_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
- guint64 size;
- GValue value = { 0 };
+ guint64 size;
+ GValue value = { 0 };
- gtk_tree_model_get_value(model, iter, index, &value);
+ gtk_tree_model_get_value(model, iter, index, &value);
- switch (G_VALUE_TYPE(&value)) {
- case G_TYPE_ULONG:
- size = g_value_get_ulong(&value);
- break;
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_ULONG:
+ size = g_value_get_ulong(&value);
+ break;
- case G_TYPE_UINT64:
- size = g_value_get_uint64(&value);
- break;
+ case G_TYPE_UINT64:
+ size = g_value_get_uint64(&value);
+ break;
- default:
- g_assert_not_reached();
- }
+ default:
+ g_assert_not_reached();
+ }
- g_value_unset(&value);
+ g_value_unset(&value);
- if (size == 0)
- g_object_set(renderer, "markup", _("<i>N/A</i>"), NULL);
- else {
- char *str = procman::format_size(size);
- g_object_set(renderer, "text", str, NULL);
- g_free(str);
+ if (size == 0)
+ g_object_set(renderer, "markup", _("<i>N/A</i>"), NULL);
+ else {
+ char *str = procman::format_size(size);
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
+ }
}
- }
+ void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+ unsigned time;
+ GValue value = { 0 };
- void duration_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data)
- {
- const guint index = GPOINTER_TO_UINT(user_data);
+ gtk_tree_model_get_value(model, iter, index, &value);
- unsigned time;
- GValue value = { 0 };
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_ULONG:
+ time = g_value_get_ulong(&value);
+ break;
- gtk_tree_model_get_value(model, iter, index, &value);
+ case G_TYPE_UINT64:
+ time = g_value_get_uint64(&value);
+ break;
- switch (G_VALUE_TYPE(&value)) {
- case G_TYPE_ULONG:
- time = g_value_get_ulong(&value);
- break;
+ default:
+ g_assert_not_reached();
+ }
- case G_TYPE_UINT64:
- time = g_value_get_uint64(&value);
- break;
+ g_value_unset(&value);
- default:
- g_assert_not_reached();
+ time = 100 * time / ProcData::get_instance()->frequency;
+ char *str = format_duration_for_display(time);
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
}
- g_value_unset(&value);
- time = 100 * time / ProcData::get_instance()->frequency;
- char *str = format_duration_for_display(time);
- g_object_set(renderer, "text", str, NULL);
- g_free(str);
- }
+ void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+ time_t time;
+ GValue value = { 0 };
- void time_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data)
- {
- const guint index = GPOINTER_TO_UINT(user_data);
+ gtk_tree_model_get_value(model, iter, index, &value);
- time_t time;
- GValue value = { 0 };
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_ULONG:
+ time = g_value_get_ulong(&value);
+ break;
- gtk_tree_model_get_value(model, iter, index, &value);
+ default:
+ g_assert_not_reached();
+ }
- switch (G_VALUE_TYPE(&value)) {
- case G_TYPE_ULONG:
- time = g_value_get_ulong(&value);
- break;
+ g_value_unset(&value);
- default:
- g_assert_not_reached();
+ char *str = procman_format_date_for_display(time);
+ g_object_set(renderer, "text", str, NULL);
+ g_free(str);
}
- g_value_unset(&value);
+ void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
- char *str = procman_format_date_for_display(time);
- g_object_set(renderer, "text", str, NULL);
- g_free(str);
- }
+ guint state;
+ GValue value = { 0 };
- void status_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data)
- {
- const guint index = GPOINTER_TO_UINT(user_data);
+ gtk_tree_model_get_value(model, iter, index, &value);
- guint state;
- GValue value = { 0 };
+ switch (G_VALUE_TYPE(&value)) {
+ case G_TYPE_UINT:
+ state = g_value_get_uint(&value);
+ break;
- gtk_tree_model_get_value(model, iter, index, &value);
+ default:
+ g_assert_not_reached();
+ }
- switch (G_VALUE_TYPE(&value)) {
- case G_TYPE_UINT:
- state = g_value_get_uint(&value);
- break;
+ g_value_unset(&value);
- default:
- g_assert_not_reached();
+ const char *str = format_process_state(state);
+ g_object_set(renderer, "text", str, NULL);
}
- g_value_unset(&value);
- const char *str = format_process_state(state);
- g_object_set(renderer, "text", str, NULL);
- }
-
-
- template<>
- void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value)
- {
- char* current_value;
+ template<>
+ void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value)
+ {
+ char* current_value;
- gtk_tree_model_get(model, iter, column, &current_value, -1);
+ gtk_tree_model_get(model, iter, column, &current_value, -1);
- if (!current_value or std::strcmp(current_value, new_value) != 0)
- gtk_tree_store_set(GTK_TREE_STORE(model), iter, column, new_value, -1);
+ if (!current_value or std::strcmp(current_value, new_value) != 0)
+ gtk_tree_store_set(GTK_TREE_STORE(model), iter, column, new_value, -1);
- g_free(current_value);
- }
+ g_free(current_value);
+ }
- std::string format_rate(guint64 rate, guint64 max_rate, bool want_bits)
- {
- char* bytes = procman::format_size(rate, max_rate, want_bits);
- // xgettext: rate, 10MiB/s or 10Mbit/s
- std::string formatted_rate(make_string(g_strdup_printf(_("%s/s"), bytes)));
- g_free(bytes);
- return formatted_rate;
- }
+ std::string format_rate(guint64 rate, guint64 max_rate, bool want_bits)
+ {
+ char* bytes = procman::format_size(rate, max_rate, want_bits);
+ // xgettext: rate, 10MiB/s or 10Mbit/s
+ std::string formatted_rate(make_string(g_strdup_printf(_("%s/s"), bytes)));
+ g_free(bytes);
+ return formatted_rate;
+ }
- std::string format_network(guint64 rate, guint64 max_rate)
- {
- char* bytes = procman::format_size(rate, max_rate, ProcData::get_instance()->config.network_in_bits);
- std::string formatted(bytes);
- g_free(bytes);
- return formatted;
- }
+ std::string format_network(guint64 rate, guint64 max_rate)
+ {
+ char* bytes = procman::format_size(rate, max_rate, ProcData::get_instance()->config.network_in_bits);
+ std::string formatted(bytes);
+ g_free(bytes);
+ return formatted;
+ }
- std::string format_network_rate(guint64 rate, guint64 max_rate)
- {
- char* bytes = procman::format_size(rate, max_rate, ProcData::get_instance()->config.network_in_bits);
- std::string formatted(bytes);
- g_free(bytes);
- return formatted;
- }
+ std::string format_network_rate(guint64 rate, guint64 max_rate)
+ {
+ char* bytes = procman::format_size(rate, max_rate, ProcData::get_instance()->config.network_in_bits);
+ std::string formatted(bytes);
+ g_free(bytes);
+ return formatted;
+ }
}
diff --git a/src/util.h b/src/util.h
index 1a15b4b..6e989a9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -16,13 +16,13 @@ using std::string;
template<typename T>
inline int procman_cmp(T x, T y)
{
- if (x == y)
- return 0;
+ if (x == y)
+ return 0;
- if (x < y)
- return -1;
+ if (x < y)
+ return -1;
- return 1;
+ return 1;
}
#define PROCMAN_CMP(X, Y) procman_cmp((X), (Y))
@@ -30,8 +30,8 @@ inline int procman_cmp(T x, T y)
GtkWidget*
procman_make_label_for_mmaps_or_ofiles(const char *format,
- const char *process_name,
- unsigned pid);
+ const char *process_name,
+ unsigned pid);
gboolean
load_symbols(const char *module, ...) G_GNUC_NULL_TERMINATED;
@@ -39,20 +39,20 @@ load_symbols(const char *module, ...) G_GNUC_NULL_TERMINATED;
void
procman_debug_real(const char *file, int line, const char *func,
- const char *format, ...) G_GNUC_PRINTF(4, 5);
+ const char *format, ...) G_GNUC_PRINTF(4, 5);
#define procman_debug(FMT, ...) procman_debug_real(__FILE__, __LINE__, __func__, FMT, ##__VA_ARGS__)
inline string make_string(char *c_str)
{
- if (!c_str) {
- procman_debug("NULL string");
- return string();
- }
-
- string s(c_str);
- g_free(c_str);
- return s;
+ if (!c_str) {
+ procman_debug("NULL string");
+ return string();
+ }
+
+ string s(c_str);
+ g_free(c_str);
+ return s;
}
@@ -60,91 +60,91 @@ inline string make_string(char *c_str)
template<typename Map>
class UnrefMapValues
- : public std::unary_function<void, Map>
+ : public std::unary_function<void, Map>
{
public:
- void operator()(const typename Map::value_type &it) const
- {
- if (it.second)
- g_object_unref(it.second);
- }
+ void operator()(const typename Map::value_type &it) const
+ {
+ if (it.second)
+ g_object_unref(it.second);
+ }
};
template<typename Map>
inline void unref_map_values(Map &map)
{
- std::for_each(map.begin(), map.end(), UnrefMapValues<Map>());
+ std::for_each(map.begin(), map.end(), UnrefMapValues<Map>());
}
namespace procman
{
- void size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data);
+ void size_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
- void size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data);
+ void size_na_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
- void duration_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data);
+ void duration_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
- void time_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data);
+ void time_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
- void status_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer user_data);
+ void status_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
- template<typename T>
- void poison(T &t, char c)
- {
- memset(&t, c, sizeof t);
- }
+ template<typename T>
+ void poison(T &t, char c)
+ {
+ memset(&t, c, sizeof t);
+ }
- //
- // Stuff to update a tree_store in a smart way
- //
+ //
+ // Stuff to update a tree_store in a smart way
+ //
- template<typename T>
- void tree_store_update(GtkTreeModel* model, GtkTreeIter* iter, int column, const T& new_value)
- {
- T current_value;
+ template<typename T>
+ void tree_store_update(GtkTreeModel* model, GtkTreeIter* iter, int column, const T& new_value)
+ {
+ T current_value;
- gtk_tree_model_get(model, iter, column, &current_value, -1);
+ gtk_tree_model_get(model, iter, column, &current_value, -1);
- if (current_value != new_value)
- gtk_tree_store_set(GTK_TREE_STORE(model), iter, column, new_value, -1);
- }
+ if (current_value != new_value)
+ gtk_tree_store_set(GTK_TREE_STORE(model), iter, column, new_value, -1);
+ }
- // undefined
- // catch every thing about pointers
- // just to make sure i'm not doing anything wrong
- template<typename T>
- void tree_store_update(GtkTreeModel* model, GtkTreeIter* iter, int column, T* new_value);
+ // undefined
+ // catch every thing about pointers
+ // just to make sure i'm not doing anything wrong
+ template<typename T>
+ void tree_store_update(GtkTreeModel* model, GtkTreeIter* iter, int column, T* new_value);
- // specialized versions for strings
- template<>
- void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value);
+ // specialized versions for strings
+ template<>
+ void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value);
- template<>
- inline void tree_store_update<char>(GtkTreeModel* model, GtkTreeIter* iter, int column, char* new_value)
- {
- tree_store_update<const char>(model, iter, column, new_value);
- }
+ template<>
+ inline void tree_store_update<char>(GtkTreeModel* model, GtkTreeIter* iter, int column, char* new_value)
+ {
+ tree_store_update<const char>(model, iter, column, new_value);
+ }
- gchar* format_size(guint64 size, guint64 max = 0, bool want_bits = false);
+ gchar* format_size(guint64 size, guint64 max = 0, bool want_bits = false);
- std::string format_rate(guint64 rate, guint64 max_rate = 0, bool want_bits = false);
+ std::string format_rate(guint64 rate, guint64 max_rate = 0, bool want_bits = false);
- std::string format_network(guint64 rate, guint64 max_rate = 0);
- std::string format_network_rate(guint64 rate, guint64 max_rate = 0);
+ std::string format_network(guint64 rate, guint64 max_rate = 0);
+ std::string format_network_rate(guint64 rate, guint64 max_rate = 0);
}