[gnome-shell/gnome-3-6] App search: Match GenericName too



commit d1242e9ae7220f6f230a306f6b9eb1908cbf7ce2
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 29 11:12:55 2012 -0400

    App search: Match GenericName too
    
    This is making shell search results more useful in many cases,
    such as 'web', 'browser', spreadsheet'.
    https://bugzilla.gnome.org/show_bug.cgi?id=687121

 src/shell-app.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index 51a2524..8ff53ec 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -73,6 +73,7 @@ struct _ShellApp
   char *window_id_string;
 
   char *casefolded_name;
+  char *casefolded_generic_name;
   char *name_collation_key;
   char *casefolded_exec;
   char **casefolded_keywords;
@@ -1310,6 +1311,7 @@ static void
 shell_app_init_search_data (ShellApp *app)
 {
   const char *name;
+  const char *generic_name;
   const char *exec;
   const char * const *keywords;
   char *normalized_exec;
@@ -1319,6 +1321,12 @@ shell_app_init_search_data (ShellApp *app)
   name = g_app_info_get_name (G_APP_INFO (appinfo));
   app->casefolded_name = shell_util_normalize_and_casefold (name);
 
+  generic_name = g_desktop_app_info_get_generic_name (appinfo);
+  if (generic_name)
+    app->casefolded_generic_name = shell_util_normalize_and_casefold (generic_name);
+  else
+    app->casefolded_generic_name = NULL;
+
   exec = g_app_info_get_executable (G_APP_INFO (appinfo));
   normalized_exec = shell_util_normalize_and_casefold (exec);
   app->casefolded_exec = trim_exec_line (normalized_exec);
@@ -1388,6 +1396,18 @@ _shell_app_match_search_terms (ShellApp  *app,
             current_match = MATCH_SUBSTRING;
         }
 
+      if (app->casefolded_generic_name)
+        {
+          p = strstr (app->casefolded_generic_name, term);
+          if (p != NULL)
+            {
+              if (p == app->casefolded_generic_name || *(p - 1) == ' ')
+                current_match = MATCH_PREFIX;
+              else if (current_match < MATCH_PREFIX)
+                current_match = MATCH_SUBSTRING;
+            }
+        }
+
       if (app->casefolded_exec)
         {
           p = strstr (app->casefolded_exec, term);
@@ -1497,6 +1517,7 @@ shell_app_finalize (GObject *object)
   g_free (app->window_id_string);
 
   g_free (app->casefolded_name);
+  g_free (app->casefolded_generic_name);
   g_free (app->name_collation_key);
   g_free (app->casefolded_exec);
   g_strfreev (app->casefolded_keywords);



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