[gnome-system-monitor] Simplified search for open files dialog



commit 293bf2942ade413761c103b11e6af1de36bc5d2d
Author: Robert Roth <robert roth off gmail com>
Date:   Tue Apr 15 14:15:53 2014 +0300

    Simplified search for open files dialog

 data/lsof.ui |  163 ++++++++++------------------------------------------------
 src/lsof.cpp |   61 +++++----------------
 2 files changed, 42 insertions(+), 182 deletions(-)
---
diff --git a/data/lsof.ui b/data/lsof.ui
index 090816b..3dbf8ae 100644
--- a/data/lsof.ui
+++ b/data/lsof.ui
@@ -3,60 +3,42 @@
   <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkWindow" id="lsof_dialog">
     <property name="can_focus">False</property>
-    <property name="border_width">12</property>
+    <property name="border_width">0</property>
     <property name="title" translatable="yes" context="Window title for 'Search for Open Files' 
dialog">Search for Open Files</property>
     <property name="default_width">575</property>
     <property name="default_height">400</property>
     <property name="destroy_with_parent">True</property>
-    <child>
-      <object class="GtkGrid" id="mainbox">
+    <child >
+      <object class="GtkBox" id="mainbox">
         <property name="visible">True</property>
+        <property name="border_width">0</property>
         <property name="can_focus">False</property>
+        <property name="spacing">0</property>
         <property name="orientation">vertical</property>
-        <property name="row_spacing">6</property>
-        <property name="column_spacing">6</property>
         <child>
-          <object class="GtkGrid" id="header_grid">
+          <object class="GtkBox" id="search_box">
             <property name="visible">True</property>
+            <property name="border_width">6</property>
             <property name="can_focus">False</property>
-            <property name="row_spacing">6</property>
-            <property name="column_spacing">6</property>
+            <property name="orientation">vertical</property>
             <child>
-              <object class="GtkLabel" id="label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">0.51999998092651367</property>
-                <property name="label" translatable="yes">_Name contains:</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="search_button">
-                <property name="label" translatable="yes">_Find</property>
-                <property name="use_underline">True</property>
-                <property name="use_action_appearance">False</property>
+              <object class="GtkSearchEntry" id="entry">
                 <property name="visible">True</property>
+                <property name="width_request">300</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">False</property>
+                <property name="hexpand">True</property>
+                <property name="invisible_char">•</property>
+                <property name="placeholder-text" translatable="yes">Filter files by name</property>
               </object>
               <packing>
-                <property name="left_attach">3</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
               </packing>
             </child>
             <child>
               <object class="GtkCheckButton" id="case_button">
-                <property name="label" translatable="yes">Case insensitive matching</property>
+                <property name="label" translatable="yes">Case insensitive</property>
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -66,107 +48,16 @@
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">1</property>
-                <property name="width">4</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkSearchEntry" id="entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hexpand">True</property>
-                <property name="invisible_char">•</property>
-              </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="results_box">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="hexpand">True</property>
-            <property name="column_spacing">6</property>
-            <child>
-              <object class="GtkLabel" id="results_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">S_earch results:</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="count_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">end</property>
-                <property name="hexpand">True</property>
-                <property name="use_underline">True</property>
-                <property name="justify">right</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">1</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="bottom_box">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">end</property>
-            <child>
-              <object class="GtkButton" id="close_button">
-                <property name="label" translatable="yes">_Close</property>
-                <property name="use_underline">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">False</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </object>
           <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">3</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
           </packing>
         </child>
         <child>
@@ -181,10 +72,10 @@
             </child>
           </object>
           <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">2</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
+            <property name="padding">0</property>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
           </packing>
         </child>
       </object>
diff --git a/src/lsof.cpp b/src/lsof.cpp
index e0de9cb..9f6a3ec 100644
--- a/src/lsof.cpp
+++ b/src/lsof.cpp
@@ -103,20 +103,6 @@ namespace
         }
 
 
-        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 display_regex_error(const Glib::RegexError& error)
         {
             char * msg = g_strdup_printf ("<b>%s</b>\n%s\n%s",
@@ -137,8 +123,14 @@ namespace
 
         void update_count(unsigned count)
         {
-            string s = static_cast<std::ostringstream&>(std::ostringstream() << count).str();
-            gtk_label_set_text(this->count, s.c_str());
+            gchar *title;
+            if (this->pattern().length() == 0) {
+                title = g_strdup_printf (_("%d open files"), count);
+            } else {
+                title = g_strdup_printf (_("%d matching open files"), count);
+            }
+            gtk_window_set_title(this->window, title);
+            g_free (title);
         }
 
 
@@ -153,9 +145,7 @@ namespace
             typedef std::set<string> MatchSet;
             typedef MatchSet::const_iterator iterator;
 
-            this->clear_results();
-
-
+            gtk_list_store_clear(this->model);
             try {
                 Lsof lsof(this->pattern(), this->case_insensitive);
 
@@ -188,24 +178,12 @@ namespace
         }
 
 
-        static void search_button_clicked(GtkButton *, gpointer data)
-        {
-            static_cast<GUI*>(data)->search();
-        }
-
-
-        static void search_entry_activate(GtkEntry *, gpointer data)
+        static void search_changed(GtkSearchEntry *, gpointer data)
         {
             static_cast<GUI*>(data)->search();
         }
 
 
-        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);
@@ -308,12 +286,8 @@ void procman_lsof(GsmApplication *app)
     gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(app->main_window));
 
     GtkWidget *entry =  GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
-    GtkWidget *search_button =  GTK_WIDGET (gtk_builder_get_object (builder, "search_button"));
-    GtkWidget *clear_button =  GTK_WIDGET (gtk_builder_get_object (builder, "clear_button"));
 
     GtkWidget *case_button =  GTK_WIDGET (gtk_builder_get_object (builder, "case_button"));
-    GtkWidget *count_label =  GTK_WIDGET (gtk_builder_get_object (builder, "count_label"));
-    GtkWidget *close_button =  GTK_WIDGET (gtk_builder_get_object (builder, "close_button"));
 
     // Scrolled TreeView
     GtkWidget *scrolled = GTK_WIDGET (gtk_builder_get_object (builder, "scrolled"));
@@ -325,16 +299,10 @@ void procman_lsof(GsmApplication *app)
     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);
+    gui->case_insensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (case_button));
+
+    g_signal_connect(G_OBJECT(entry), "search-changed",
+                     G_CALLBACK(GUI::search_changed), gui);
     g_signal_connect(G_OBJECT(case_button), "toggled",
                      G_CALLBACK(GUI::case_button_toggled), gui);
     g_signal_connect(G_OBJECT(dialog), "delete-event",
@@ -343,6 +311,7 @@ void procman_lsof(GsmApplication *app)
     gtk_builder_connect_signals (builder, NULL);
 
     gtk_widget_show_all(dialog);
+    gui->search ();
     
     g_object_unref (G_OBJECT (builder));
 }


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