[Xfce4-commits] [apps/xfce4-taskmanager] 01/03: Add filter entry to search especific command lines. (#9856)

noreply at xfce.org noreply at xfce.org
Mon Dec 1 09:53:47 CET 2014


This is an automated email from the git hooks/post-receive script.

landry pushed a commit to branch master
in repository apps/xfce4-taskmanager.

commit 9ca4c078c63cdd95364e477a9faec0f2b53c4a49
Author: Matias De lellis <mati86dl at gmail.com>
Date:   Thu Feb 14 19:04:59 2013 -0300

    Add filter entry to search especific command lines. (#9856)
---
 src/process-tree-view.c |   42 ++++++++++++++++++++++++++++++++++++------
 src/process-tree-view.h |    1 +
 src/process-window.c    |   32 ++++++++++++++++++++++++++++++++
 src/process-window.ui   |   44 +++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/src/process-tree-view.c b/src/process-tree-view.c
index 5026679..31862c6 100644
--- a/src/process-tree-view.c
+++ b/src/process-tree-view.c
@@ -48,6 +48,7 @@ struct _XtmProcessTreeView
 	/*<private>*/
 	GtkListStore *		model;
 	GtkTreeModel *		model_filter;
+	gchar        *    cmd_filter;
 	GtkTreeViewColumn *	sort_column;
 	gushort			columns_positions[N_COLUMNS];
 	XtmSettings *		settings;
@@ -69,8 +70,6 @@ static gboolean		visible_func					(GtkTreeModel *model, GtkTreeIter *iter, XtmPr
 static gboolean		search_func					(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer user_data);
 static void		settings_changed				(GObject *object, GParamSpec *pspec, XtmProcessTreeView *treeview);
 
-
-
 static void
 xtm_process_tree_view_class_init (XtmProcessTreeViewClass *klass)
 {
@@ -110,6 +109,8 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
 
 	g_object_set (treeview, "search-column", XTM_PTV_COLUMN_COMMAND, "model", treeview->model_filter, NULL);
 
+	treeview->cmd_filter = NULL;
+
 	/* Create cell renderer for tree view columns */
 	cell_text = gtk_cell_renderer_text_new();
 
@@ -590,16 +591,45 @@ column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview)
 	treeview->sort_column = column;
 }
 
+void
+xtm_process_tree_view_set_filter(XtmProcessTreeView *treeview, const gchar *cmd_filter)
+{
+  g_free(treeview->cmd_filter);
+  treeview->cmd_filter = g_strdup(cmd_filter);
+
+	gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview->model_filter));
+}
+
 static gboolean
 visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview)
 {
+	gchar *cmdline, *cmdline_lower, *key_lower, *p = NULL;
+	gboolean  mach_filter = TRUE, match_uid = TRUE;
 	guint uid;
 
-	if (treeview->show_all_processes_cached)
-		return TRUE;
+	if(treeview->cmd_filter) {
+		gtk_tree_model_get (GTK_TREE_MODEL (model), iter, XTM_PTV_COLUMN_COMMAND, &cmdline, -1);
+		if(cmdline) {
+			cmdline_lower = g_ascii_strdown (cmdline, -1);
+			key_lower = g_ascii_strdown (treeview->cmd_filter, -1);
+
+			p = g_strrstr (cmdline_lower, key_lower);
+
+			g_free (key_lower);
+			g_free (cmdline_lower);
+			g_free (cmdline);
+		}
+
+		if(!p)
+			mach_filter = FALSE;
+	}
+	if (!treeview->show_all_processes_cached) {
+		gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1);
+		if (treeview->owner_uid != uid)
+			match_uid = FALSE;
+	}
 
-	gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1);
-	return (treeview->owner_uid == uid) ? TRUE : FALSE;
+	return (mach_filter && match_uid);
 }
 
 static gboolean
diff --git a/src/process-tree-view.h b/src/process-tree-view.h
index 8d2725e..c6dcfea 100644
--- a/src/process-tree-view.h
+++ b/src/process-tree-view.h
@@ -52,5 +52,6 @@ typedef struct _XtmProcessTreeView XtmProcessTreeView;
 GType		xtm_process_tree_view_get_type			(void);
 GtkWidget *	xtm_process_tree_view_new			(void);
 void		xtm_process_tree_view_get_sort_column_id	(XtmProcessTreeView *treeview, gint *sort_column_id, GtkSortType *sort_type);
+void    xtm_process_tree_view_set_filter           (XtmProcessTreeView *treeview, const gchar *cmd_filter);
 
 #endif /* !PROCESS_TREE_VIEW_H */
diff --git a/src/process-window.c b/src/process-window.c
index 503f5f1..99b292c 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -42,6 +42,7 @@ struct _XtmProcessWindow
 	GtkBuilder *		builder;
 	GtkWidget *		window;
 	GtkWidget *		toolbar;
+	GtkWidget *		filter_entry;
 	GtkWidget *		cpu_monitor;
 	GtkWidget *		mem_monitor;
 	GtkWidget *		treeview;
@@ -64,6 +65,33 @@ static void	monitor_update_paint_box			(XtmProcessWindow *window);
 static void	show_about_dialog				(XtmProcessWindow *window);
 
 
+static void
+filter_entry_icon_pressed_cb (GtkEntry *entry,
+                              gint position,
+                              GdkEventButton *event,
+                              gpointer data)
+{
+	if (position == GTK_ENTRY_ICON_SECONDARY) {
+		gtk_entry_set_text (entry, "");
+		gtk_widget_grab_focus(GTK_WIDGET(entry));
+	}
+}
+
+static gboolean
+filter_entry_keyrelease_handler(GtkEntry *entry,
+                                XtmProcessTreeView *treeview)
+{
+	const gchar *text;
+	gboolean has_text;
+
+	text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1);
+	xtm_process_tree_view_set_filter(treeview, text);
+
+	has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0;
+	gtk_entry_set_icon_sensitive (GTK_ENTRY(entry),
+	                              GTK_ENTRY_ICON_SECONDARY,
+	                              has_text);
+}
 
 static void
 xtm_process_window_class_init (XtmProcessWindowClass *klass)
@@ -146,6 +174,10 @@ xtm_process_window_init (XtmProcessWindow *window)
 	gtk_widget_show (window->treeview);
 	gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->builder, "scrolledwindow")), window->treeview);
 
+	window->filter_entry = GTK_WIDGET(gtk_builder_get_object (window->builder, "filter-entry"));
+	g_signal_connect (G_OBJECT(window->filter_entry), "icon-press", G_CALLBACK(filter_entry_icon_pressed_cb), NULL);
+	g_signal_connect (G_OBJECT(window->filter_entry), "changed", G_CALLBACK(filter_entry_keyrelease_handler), window->treeview);
+
 	window->statusbar = xtm_process_statusbar_new ();
 	gtk_widget_show (window->statusbar);
 	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (window->builder, "process-vbox")), window->statusbar, FALSE, FALSE, 0);
diff --git a/src/process-window.ui b/src/process-window.ui
index 81c4371..173211c 100644
--- a/src/process-window.ui
+++ b/src/process-window.ui
@@ -1,8 +1,9 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 2.12 -->
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="process-window">
+    <property name="can_focus">False</property>
     <property name="title" translatable="yes">Task Manager</property>
     <property name="default_width">490</property>
     <property name="default_height">465</property>
@@ -10,15 +11,17 @@
     <child>
       <object class="GtkVBox" id="process-vbox">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
+        <property name="can_focus">False</property>
         <child>
           <object class="GtkToolbar" id="process-toolbar">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="show_arrow">False</property>
             <property name="icon_size">1</property>
             <child>
               <object class="GtkToolItem" id="cpu-toolitem">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="border_width">2</property>
                 <child>
                   <placeholder/>
@@ -32,6 +35,7 @@
             <child>
               <object class="GtkToolItem" id="mem-toolitem">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="border_width">2</property>
                 <child>
                   <placeholder/>
@@ -45,28 +49,33 @@
             <child>
               <object class="GtkToolButton" id="toolbutton-about">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-about</property>
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="homogeneous">True</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
           <object class="GtkVBox" id="root-warning-box">
-            <property name="orientation">vertical</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkEventBox" id="root-warning-ebox">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkLabel" id="root-warning-label">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="xpad">6</property>
                     <property name="ypad">3</property>
                     <property name="label" translatable="yes">Warning, you are using the root account, you may harm your system.</property>
@@ -82,9 +91,11 @@
             <child>
               <object class="GtkHSeparator" id="root-warning-separator">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="fill">True</property>
                 <property name="position">1</property>
               </packing>
             </child>
@@ -96,9 +107,28 @@
           </packing>
         </child>
         <child>
+          <object class="GtkEntry" id="filter-entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="invisible_char">•</property>
+            <property name="primary_icon_stock">gtk-find</property>
+            <property name="secondary_icon_stock">gtk-clear</property>
+            <property name="primary_icon_activatable">False</property>
+            <property name="secondary_icon_activatable">True</property>
+            <property name="primary_icon_sensitive">True</property>
+            <property name="secondary_icon_sensitive">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">2</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkVBox" id="mainview-vbox">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
+            <property name="can_focus">False</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkScrolledWindow" id="scrolledwindow">
@@ -111,12 +141,16 @@
                 </child>
               </object>
               <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">0</property>
               </packing>
             </child>
           </object>
           <packing>
-            <property name="position">2</property>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
           </packing>
         </child>
         <child>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list