[gnome-system-monitor/wip/tty] Added tty column, but names are not properly displayed yet



commit 0972503813aa85f66c0043d91fbc9513a2f9d5fb
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Aug 9 01:07:07 2013 +0300

    Added tty column, but names are not properly displayed yet

 src/application.h                                 |    3 +-
 src/org.gnome.gnome-system-monitor.gschema.xml.in |   14 +++++++++++++
 src/proctable.cpp                                 |   15 ++++++++++++-
 src/proctable.h                                   |    1 +
 src/util.cpp                                      |   22 +++++++++++++++++++++
 src/util.h                                        |    5 ++++
 6 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/src/application.h b/src/application.h
index 0780edd..44a17e7 100644
--- a/src/application.h
+++ b/src/application.h
@@ -73,12 +73,13 @@ MutableProcInfo()
     guint status;
     guint pcpu;
     gint nice;
+    gint tty;
     gchar *cgroup_name;
 
     gchar *unit;
     gchar *session;
     gchar *seat;
-
+    
     std::string owner;
 };
 
diff --git a/src/org.gnome.gnome-system-monitor.gschema.xml.in 
b/src/org.gnome.gnome-system-monitor.gschema.xml.in
index d182804..568f41d 100644
--- a/src/org.gnome.gnome-system-monitor.gschema.xml.in
+++ b/src/org.gnome.gnome-system-monitor.gschema.xml.in
@@ -511,6 +511,20 @@
       <_summary>Show process 'Priority' column on startup
       </_summary>
     </key>
+    
+    <key name="col-23-width" type="i">
+      <default>50
+      </default>
+      <_summary>Width of process 'TTY' column
+      </_summary>
+    </key>
+
+    <key name="col-23-visible" type="b">
+      <default>false
+      </default>
+      <_summary>Show process 'TTY' column on startup
+      </_summary>
+    </key>
 
   </schema>
 
diff --git a/src/proctable.cpp b/src/proctable.cpp
index bc38d9e..b0b6258 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -405,6 +405,7 @@ proctable_new (GsmApplication * const app)
         N_("Seat"),
         N_("Owner"),
         N_("Priority"),
+        N_("TTY"),
         NULL,
         "POINTER"
     };
@@ -435,6 +436,7 @@ proctable_new (GsmApplication * const app)
                                 G_TYPE_STRING,      /* Seat         */
                                 G_TYPE_STRING,      /* Owner        */
                                 G_TYPE_STRING,      /* Priority     */
+                                G_TYPE_INT,         /* TTY          */
                                 GDK_TYPE_PIXBUF,    /* Icon         */
                                 G_TYPE_POINTER,     /* ProcInfo     */
                                 G_TYPE_STRING       /* Sexy tooltip */
@@ -478,7 +480,7 @@ proctable_new (GsmApplication * const app)
     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_PRIORITY; i++) {
+    for (i = COL_USER; i <= COL_TTY; i++) {
         GtkTreeViewColumn *col;
         GtkCellRenderer *cell;
 
@@ -546,6 +548,13 @@ proctable_new (GsmApplication * const app)
                                                         GUINT_TO_POINTER(COL_NICE),
                                                         NULL);
                 break;
+            case COL_TTY:
+                gtk_tree_view_column_set_cell_data_func(col, cell,
+                                                        &procman::tty_cell_data_func,
+                                                        GUINT_TO_POINTER(i),
+                                                        NULL);
+                break;
+                
             default:
                 gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
                 break;
@@ -880,6 +889,7 @@ insert_info_to_tree (ProcInfo *info, GsmApplication *app, bool forced = false)
                         COL_TOOLTIP, info->tooltip,
                         COL_PID, info->pid,
                         COL_SECURITYCONTEXT, info->security_context,
+                        COL_TTY, info->tty,
                         -1);
 
     app->pretty_table->set_icon(*info);
@@ -987,7 +997,8 @@ update_info (GsmApplication *app, ProcInfo *info)
     ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
     info->nice = procuid.nice;
     info->ppid = procuid.ppid;
-
+    info->tty = procuid.tty;
+    
     /* get cgroup data */
     get_process_cgroup_info(info);
 
diff --git a/src/proctable.h b/src/proctable.h
index 9b0cc6c..a552a8a 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -50,6 +50,7 @@ enum
     COL_SEAT,
     COL_OWNER,
     COL_PRIORITY,
+    COL_TTY,
     COL_PIXBUF,
     COL_POINTER,
     COL_TOOLTIP,
diff --git a/src/util.cpp b/src/util.cpp
index 71d9e78..cb8b7ec 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -581,6 +581,28 @@ namespace procman
         g_object_set(renderer, "text", procman::get_nice_level(priority), NULL);
 
     }
+    
+    void tty_cell_data_func (GtkTreeViewColumn *, GtkCellRenderer *renderer,
+                             GtkTreeModel *model, GtkTreeIter *iter,
+                             gpointer user_data)
+    {
+        const guint index = GPOINTER_TO_UINT(user_data);
+
+        GValue value = { 0 };
+
+        gtk_tree_model_get_value(model, iter, index, &value);
+
+        gint tty = g_value_get_int(&value);
+
+        g_value_unset(&value);
+        
+        gchar *tty_name = g_strdup_printf ("%s (%d)", ttyname(tty), tty);
+        
+        g_object_set(renderer, "text", tty_name, NULL);
+        
+        g_free (tty_name);
+
+    }
 
     gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
                             GtkTreeIter* second, gpointer user_data)
diff --git a/src/util.h b/src/util.h
index 28fdc62..235a5b3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -74,6 +74,11 @@ namespace procman
     void priority_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
                                GtkTreeModel *model, GtkTreeIter *iter,
                                gpointer user_data);
+                               
+    void tty_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+                               GtkTreeModel *model, GtkTreeIter *iter,
+                               gpointer user_data);
+                               
     gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
                             GtkTreeIter* second, gpointer user_data);
     gint number_compare_func(GtkTreeModel* model, GtkTreeIter* first,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]