|
Packit |
76ec6a |
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
Packit |
76ec6a |
/* Process properties dialog
|
|
Packit |
76ec6a |
* Copyright (C) 2010 Krishnan Parthasarathi <krishnan.parthasarathi@gmail.com>
|
|
Packit |
76ec6a |
* Robert Ancell <robert.ancell@canonical.com>
|
|
Packit |
76ec6a |
*
|
|
Packit |
76ec6a |
* This program is free software; you can redistribute it and/or
|
|
Packit |
76ec6a |
* modify it under the terms of the GNU General Public License
|
|
Packit |
76ec6a |
* as published by the Free Software Foundation; either version 2
|
|
Packit |
76ec6a |
* of the License, or (at your option) any later version.
|
|
Packit |
76ec6a |
*
|
|
Packit |
76ec6a |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
76ec6a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
76ec6a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
76ec6a |
* GNU General Public License for more details.
|
|
Packit |
76ec6a |
*
|
|
Packit |
76ec6a |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
76ec6a |
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
76ec6a |
*
|
|
Packit |
76ec6a |
*/
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
#include <config.h>
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
#include <glib/gi18n.h>
|
|
Packit |
76ec6a |
#include <glibtop/procmem.h>
|
|
Packit |
76ec6a |
#include <glibtop/procmap.h>
|
|
Packit |
76ec6a |
#include <glibtop/procstate.h>
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
#include "application.h"
|
|
Packit |
76ec6a |
#include "procproperties.h"
|
|
Packit |
76ec6a |
#include "proctable.h"
|
|
Packit |
76ec6a |
#include "util.h"
|
|
Packit |
76ec6a |
#include "legacy/e_date.h"
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
enum
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
COL_PROP = 0,
|
|
Packit |
76ec6a |
COL_VAL,
|
|
Packit |
76ec6a |
NUM_COLS,
|
|
Packit |
76ec6a |
};
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
typedef struct _proc_arg {
|
|
Packit |
76ec6a |
const gchar *prop;
|
|
Packit |
76ec6a |
gchar *val;
|
|
Packit |
76ec6a |
} proc_arg;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static gchar*
|
|
Packit |
76ec6a |
format_memsize(guint64 size)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
if (size == 0)
|
|
Packit |
76ec6a |
return g_strdup(_("N/A"));
|
|
Packit |
76ec6a |
else
|
|
Packit |
76ec6a |
return g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static void
|
|
Packit |
76ec6a |
fill_proc_properties (GtkTreeView *tree, ProcInfo *info)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
guint i;
|
|
Packit |
76ec6a |
GtkListStore *store;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
if (!info)
|
|
Packit |
76ec6a |
return;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
get_process_memory_writable (info);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
proc_arg proc_props[] = {
|
|
Packit |
76ec6a |
{ N_("Process Name"), g_strdup_printf("%s", info->name.c_str())},
|
|
Packit |
76ec6a |
{ N_("User"), g_strdup_printf("%s (%d)", info->user.c_str(), info->uid)},
|
|
Packit |
76ec6a |
{ N_("Status"), g_strdup(format_process_state(info->status))},
|
|
Packit |
76ec6a |
{ N_("Memory"), format_memsize(info->mem)},
|
|
Packit |
76ec6a |
{ N_("Virtual Memory"), format_memsize(info->vmsize)},
|
|
Packit |
76ec6a |
{ N_("Resident Memory"), format_memsize(info->memres)},
|
|
Packit |
76ec6a |
{ N_("Writable Memory"), format_memsize(info->memwritable)},
|
|
Packit |
76ec6a |
{ N_("Shared Memory"), format_memsize(info->memshared)},
|
|
Packit |
76ec6a |
#ifdef HAVE_WNCK
|
|
Packit |
76ec6a |
{ N_("X Server Memory"), format_memsize(info->memxserver)},
|
|
Packit |
76ec6a |
#endif
|
|
Packit |
76ec6a |
{ N_("CPU"), g_strdup_printf("%d%%", info->pcpu)},
|
|
Packit |
76ec6a |
{ N_("CPU Time"), procman::format_duration_for_display(100 * info->cpu_time / GsmApplication::get()->frequency) },
|
|
Packit |
76ec6a |
{ N_("Started"), procman_format_date_for_display(info->start_time) },
|
|
Packit |
76ec6a |
{ N_("Nice"), g_strdup_printf("%d", info->nice)},
|
|
Packit |
76ec6a |
{ N_("Priority"), g_strdup_printf("%s", procman::get_nice_level(info->nice)) },
|
|
Packit |
76ec6a |
{ N_("ID"), g_strdup_printf("%d", info->pid)},
|
|
Packit |
76ec6a |
{ N_("Security Context"), not info->security_context.empty()?g_strdup_printf("%s", info->security_context.c_str()):g_strdup(_("N/A"))},
|
|
Packit |
76ec6a |
{ N_("Command Line"), g_strdup_printf("%s", info->arguments.c_str())},
|
|
Packit |
76ec6a |
{ N_("Waiting Channel"), g_strdup_printf("%s", info->wchan.c_str())},
|
|
Packit |
76ec6a |
{ N_("Control Group"), not info->cgroup_name.empty()?g_strdup_printf("%s", info->cgroup_name.c_str()):g_strdup(_("N/A"))},
|
|
Packit |
76ec6a |
{ NULL, NULL}
|
|
Packit |
76ec6a |
};
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
store = GTK_LIST_STORE(gtk_tree_view_get_model(tree));
|
|
Packit |
76ec6a |
for (i = 0; proc_props[i].prop; i++) {
|
|
Packit |
76ec6a |
GtkTreeIter iter;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(store), &iter, NULL, i)) {
|
|
Packit |
76ec6a |
gtk_list_store_append(store, &iter);
|
|
Packit |
76ec6a |
gtk_list_store_set(store, &iter, COL_PROP, gettext(proc_props[i].prop), -1);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_list_store_set(store, &iter, COL_VAL, g_strstrip(proc_props[i].val), -1);
|
|
Packit |
76ec6a |
g_free(proc_props[i].val);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static void
|
|
Packit |
76ec6a |
update_procproperties_dialog (GtkTreeView *tree)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
ProcInfo *info;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
pid_t pid = GPOINTER_TO_UINT(static_cast<pid_t*>(g_object_get_data (G_OBJECT (tree), "selected_info")));
|
|
Packit |
76ec6a |
info = GsmApplication::get()->processes.find(pid);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
fill_proc_properties(tree, info);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static void
|
|
Packit |
76ec6a |
close_procprop_dialog (GtkDialog *dialog, gint id, gpointer data)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
GtkTreeView *tree = static_cast<GtkTreeView*>(data);
|
|
Packit |
76ec6a |
guint timer;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
timer = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tree), "timer"));
|
|
Packit |
76ec6a |
g_source_remove (timer);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static GtkTreeView *
|
|
Packit |
76ec6a |
create_procproperties_tree (GsmApplication *app, ProcInfo *info)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
GtkTreeView *tree;
|
|
Packit |
76ec6a |
GtkListStore *model;
|
|
Packit |
76ec6a |
GtkTreeViewColumn *column;
|
|
Packit |
76ec6a |
GtkCellRenderer *cell;
|
|
Packit |
76ec6a |
gint i;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
model = gtk_list_store_new (NUM_COLS,
|
|
Packit |
76ec6a |
G_TYPE_STRING, /* Property */
|
|
Packit |
76ec6a |
G_TYPE_STRING /* Value */
|
|
Packit |
76ec6a |
);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
tree = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)));
|
|
Packit |
76ec6a |
g_object_unref (G_OBJECT (model));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
for (i = 0; i < NUM_COLS; i++) {
|
|
Packit |
76ec6a |
cell = gtk_cell_renderer_text_new ();
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
column = gtk_tree_view_column_new_with_attributes (NULL,
|
|
Packit |
76ec6a |
cell,
|
|
Packit |
76ec6a |
"text", i,
|
|
Packit |
76ec6a |
NULL);
|
|
Packit |
76ec6a |
gtk_tree_view_column_set_resizable (column, TRUE);
|
|
Packit |
76ec6a |
gtk_tree_view_append_column (tree, column);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_tree_view_set_headers_visible (tree, FALSE);
|
|
Packit |
76ec6a |
fill_proc_properties(tree, info);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
return tree;
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static gboolean
|
|
Packit |
76ec6a |
procprop_timer (gpointer data)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
GtkTreeView *tree = static_cast<GtkTreeView*>(data);
|
|
Packit |
76ec6a |
GtkTreeModel *model;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
model = gtk_tree_view_get_model (tree);
|
|
Packit |
76ec6a |
g_assert(model);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
update_procproperties_dialog (tree);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
return TRUE;
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
static void
|
|
Packit |
76ec6a |
create_single_procproperties_dialog (GtkTreeModel *model, GtkTreePath *path,
|
|
Packit |
76ec6a |
GtkTreeIter *iter, gpointer data)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
GsmApplication *app = static_cast<GsmApplication *>(data);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
GtkDialog *procpropdialog;
|
|
Packit |
76ec6a |
GtkBox *dialog_vbox, *vbox;
|
|
Packit |
76ec6a |
GtkBox *cmd_hbox;
|
|
Packit |
76ec6a |
gchar *label;
|
|
Packit |
76ec6a |
GtkScrolledWindow *scrolled;
|
|
Packit |
76ec6a |
GtkTreeView *tree;
|
|
Packit |
76ec6a |
ProcInfo *info;
|
|
Packit |
76ec6a |
guint timer;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
if (!info)
|
|
Packit |
76ec6a |
return;
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
procpropdialog = GTK_DIALOG (g_object_new (GTK_TYPE_DIALOG,
|
|
Packit |
76ec6a |
"use-header-bar", TRUE, NULL));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
label = g_strdup_printf( _("%s (PID %u)"), info->name.c_str(), info->pid);
|
|
Packit |
76ec6a |
gtk_window_set_title (GTK_WINDOW (procpropdialog), label);
|
|
Packit |
76ec6a |
g_free (label);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_window_set_destroy_with_parent (GTK_WINDOW (procpropdialog), TRUE);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_window_set_resizable (GTK_WINDOW (procpropdialog), TRUE);
|
|
Packit |
76ec6a |
gtk_window_set_default_size (GTK_WINDOW (procpropdialog), 575, 400);
|
|
Packit |
76ec6a |
gtk_container_set_border_width (GTK_CONTAINER (procpropdialog), 5);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
vbox = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (procpropdialog)));
|
|
Packit |
76ec6a |
gtk_box_set_spacing (vbox, 2);
|
|
Packit |
76ec6a |
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
dialog_vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 6));
|
|
Packit |
76ec6a |
gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
|
|
Packit |
76ec6a |
gtk_box_pack_start (vbox, GTK_WIDGET (dialog_vbox), TRUE, TRUE, 0);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
cmd_hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12));
|
|
Packit |
76ec6a |
gtk_box_pack_start (dialog_vbox, GTK_WIDGET (cmd_hbox), FALSE, FALSE, 0);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
|
|
Packit |
76ec6a |
gtk_scrolled_window_set_policy (scrolled,
|
|
Packit |
76ec6a |
GTK_POLICY_AUTOMATIC,
|
|
Packit |
76ec6a |
GTK_POLICY_AUTOMATIC);
|
|
Packit |
76ec6a |
gtk_scrolled_window_set_shadow_type (scrolled,
|
|
Packit |
76ec6a |
GTK_SHADOW_IN);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
tree = create_procproperties_tree (app, info);
|
|
Packit |
76ec6a |
gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (tree));
|
|
Packit |
76ec6a |
g_object_set_data (G_OBJECT (tree), "selected_info", GUINT_TO_POINTER (info->pid));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_box_pack_start (dialog_vbox, GTK_WIDGET (scrolled), TRUE, TRUE, 0);
|
|
Packit |
76ec6a |
gtk_widget_show_all (GTK_WIDGET (scrolled));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
g_signal_connect (G_OBJECT (procpropdialog), "response",
|
|
Packit |
76ec6a |
G_CALLBACK (close_procprop_dialog), tree);
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
gtk_window_set_transient_for (GTK_WINDOW (procpropdialog), GTK_WINDOW (GsmApplication::get()->main_window));
|
|
Packit |
76ec6a |
gtk_widget_show_all (GTK_WIDGET (procpropdialog));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
timer = g_timeout_add_seconds (5, procprop_timer, tree);
|
|
Packit |
76ec6a |
g_object_set_data (G_OBJECT (tree), "timer", GUINT_TO_POINTER (timer));
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
update_procproperties_dialog (tree);
|
|
Packit |
76ec6a |
}
|
|
Packit |
76ec6a |
|
|
Packit |
76ec6a |
void
|
|
Packit |
76ec6a |
create_procproperties_dialog (GsmApplication *app)
|
|
Packit |
76ec6a |
{
|
|
Packit |
76ec6a |
gtk_tree_selection_selected_foreach (app->selection, create_single_procproperties_dialog,
|
|
Packit |
76ec6a |
app);
|
|
Packit |
76ec6a |
}
|