[gnome-control-center] shell: Add keyword search



commit aef85137520d6f45a8696b613d887c7ebce051c9
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Nov 15 13:16:25 2010 -0500

    shell: Add keyword search
    
    This commit makes search look at the X-GNOME-Keywords key. The key
    is expected to hold a list of strings, and is translatable.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=634926

 shell/cc-shell-model.c       |   10 +++++++++-
 shell/cc-shell-model.h       |    1 +
 shell/gnome-control-center.c |   20 +++++++++++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/shell/cc-shell-model.c b/shell/cc-shell-model.c
index 4ed559b..a986d6d 100644
--- a/shell/cc-shell-model.c
+++ b/shell/cc-shell-model.c
@@ -24,6 +24,7 @@
 
 #define GNOME_SETTINGS_PANEL_ID_KEY "X-GNOME-Settings-Panel"
 #define GNOME_SETTINGS_PANEL_CATEGORY GNOME_SETTINGS_PANEL_ID_KEY
+#define GNOME_SETTINGS_PANEL_ID_KEYWORDS "X-GNOME-Keywords"
 
 
 G_DEFINE_TYPE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
@@ -38,7 +39,7 @@ static void
 cc_shell_model_init (CcShellModel *self)
 {
   GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
-      GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING};
+      GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRV};
 
   gtk_list_store_set_column_types (GTK_LIST_STORE (self),
                                    N_COLS, types);
@@ -95,6 +96,7 @@ cc_shell_model_add_item (CcShellModel   *model,
   GError *err = NULL;
   gchar *search_target;
   GKeyFile *key_file;
+  gchar **keywords;
 
   /* load the .desktop file since gnome-menus doesn't have a way to read
    * custom properties from desktop files */
@@ -121,6 +123,10 @@ cc_shell_model_add_item (CcShellModel   *model,
       id = g_strdup (gmenu_tree_entry_get_desktop_file_id (item));
     }
 
+  keywords = g_key_file_get_locale_string_list (key_file, "Desktop Entry",
+                                                GNOME_SETTINGS_PANEL_ID_KEYWORDS,
+                                                NULL, NULL, NULL);
+
   g_key_file_free (key_file);
   key_file = NULL;
 
@@ -159,8 +165,10 @@ cc_shell_model_add_item (CcShellModel   *model,
                                      COL_CATEGORY, category_name,
                                      COL_SEARCH_TARGET, search_target,
                                      COL_ICON_NAME, icon,
+                                     COL_KEYWORDS, keywords,
                                      -1);
 
   g_free (id);
   g_free (search_target);
+  g_strfreev (keywords);
 }
diff --git a/shell/cc-shell-model.h b/shell/cc-shell-model.h
index 4ba9a36..6208e43 100644
--- a/shell/cc-shell-model.h
+++ b/shell/cc-shell-model.h
@@ -62,6 +62,7 @@ enum
   COL_CATEGORY,
   COL_SEARCH_TARGET,
   COL_ICON_NAME,
+  COL_KEYWORDS,
 
   N_COLS
 };
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index 73b4d4b..4ea6a78 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -400,14 +400,18 @@ model_filter_func (GtkTreeModel              *model,
   gchar *name, *target;
   gchar *needle, *haystack;
   gboolean result;
+  gchar **keywords;
 
   gtk_tree_model_get (model, iter, COL_NAME, &name,
-                      COL_SEARCH_TARGET, &target, -1);
+                      COL_SEARCH_TARGET, &target,
+                      COL_KEYWORDS, &keywords,
+                      -1);
 
   if (!priv->filter_string || !name || !target)
     {
       g_free (name);
       g_free (target);
+      g_strfreev (keywords);
       return FALSE;
     }
 
@@ -416,10 +420,24 @@ model_filter_func (GtkTreeModel              *model,
 
   result = (strstr (haystack, needle) != NULL);
 
+  if (!result && keywords)
+    {
+      gint i;
+      gchar *keyword;
+
+      for (i = 0; !result && keywords[i]; i++)
+        {
+          keyword = g_utf8_casefold (keywords[i], -1);
+          result = strstr (keyword, needle) == keyword;
+          g_free (keyword);
+        }
+    }
+
   g_free (name);
   g_free (target);
   g_free (haystack);
   g_free (needle);
+  g_strfreev (keywords);
 
   return result;
 }



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