[gnome-software] Allow setting the search term on the command line



commit c636accdc698ef6996504fff39f33d8566bea87e
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 14 20:46:35 2013 +0100

    Allow setting the search term on the command line

 src/gs-application.c |   12 +++++++++++-
 src/gs-shell.c       |   21 +++++++++++++++++++--
 src/gs-shell.h       |    2 ++
 3 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 1d20273..41393fe 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -189,13 +189,18 @@ gs_application_command_line (GApplication      *application,
        GsApplication *app = GS_APPLICATION (application);
        GOptionContext *context;
        gchar *mode = NULL;
+       gchar *search_value = NULL;
        gboolean help = FALSE;
        gboolean verbose = FALSE;
        const GOptionEntry options[] = {
                { "mode", '\0', 0, G_OPTION_ARG_STRING, &mode,
                  /* TRANSLATORS: this is a command line option, please don't
                   * translate the option names between ‘’ */
-                 _("Start up mode: either ‘updates’, ‘updated’, ‘installed’ or ‘overview’"), _("MODE") },
+                 _("Start up mode: either ‘updates’, ‘updated’, ‘search’, ‘installed’ or ‘overview’"), 
_("MODE") },
+               { "search-value", '\0', 0, G_OPTION_ARG_STRING, &search_value,
+                 /* TRANSLATORS: this is a command line option, please don't
+                  * translate the option names between ‘’ */
+                 _("The search term to use when starting the UI"), _("SEARCH") },
                { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, NULL, NULL },
                { "help", '?', 0, G_OPTION_ARG_NONE, &help, NULL, NULL },
 
@@ -241,6 +246,10 @@ gs_application_command_line (GApplication       *application,
                        gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
                } else if (g_strcmp0 (mode, "updated") == 0) {
                        gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATED);
+               } else if (g_strcmp0 (mode, "search") == 0) {
+                       if (search_value != NULL)
+                               gs_shell_set_search_value (app->shell, search_value);
+                       gs_shell_set_mode (app->shell, GS_SHELL_MODE_SEARCH);
                } else {
                        g_warning ("Mode '%s' not recognised", mode);
                }
@@ -249,6 +258,7 @@ gs_application_command_line (GApplication        *application,
                gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
        }
 
+       g_free (search_value);
        g_free (argv);
        g_strfreev (args);
 
diff --git a/src/gs-shell.c b/src/gs-shell.c
index b208820..2c4ea4e 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -91,7 +91,11 @@ gs_shell_activate (GsShell *shell)
 }
 
 static void
-gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *category, gboolean scroll_up)
+gs_shell_change_mode (GsShell *shell,
+                     GsShellMode mode,
+                     GsApp *app,
+                     gpointer data,
+                     gboolean scroll_up)
 {
        GsShellPrivate *priv = shell->priv;
        GtkWidget *widget;
@@ -168,7 +172,8 @@ gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *
                gs_shell_details_refresh (priv->shell_details);
                break;
        case GS_SHELL_MODE_CATEGORY:
-               gs_shell_category_set_category (priv->shell_category, category);
+               gs_shell_category_set_category (priv->shell_category,
+                                               GS_CATEGORY (data));
                gs_shell_category_refresh (priv->shell_category);
                break;
        default:
@@ -550,6 +555,18 @@ gs_shell_set_mode (GsShell *shell, GsShellMode mode)
        gs_shell_change_mode (shell, mode, NULL, NULL, TRUE);
 }
 
+/**
+ * gs_shell_set_search_value:
+ **/
+void
+gs_shell_set_search_value (GsShell *shell, const gchar *search_value)
+{
+       GsShellPrivate *priv = shell->priv;
+       GtkWidget *widget;
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
+       gtk_entry_set_text (GTK_ENTRY (widget), search_value);
+}
+
 GsShellMode
 gs_shell_get_mode (GsShell *shell)
 {
diff --git a/src/gs-shell.h b/src/gs-shell.h
index d56e1c7..a2beb7e 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -72,6 +72,8 @@ void           gs_shell_refresh               (GsShell        *shell,
                                                 GCancellable   *cancellable);
 void            gs_shell_set_mode              (GsShell        *shell,
                                                 GsShellMode     mode);
+void            gs_shell_set_search_value      (GsShell        *shell,
+                                                const gchar    *search_value);
 GsShellMode     gs_shell_get_mode              (GsShell        *shell);
 void            gs_shell_show_app              (GsShell        *shell,
                                                 GsApp          *app);


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