[hotssh] Add DBus activation as a search provider



commit 399b185573b48d60db354aee752bc8a6272923ef
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Nov 26 13:45:42 2013 -0500

    Add DBus activation as a search provider
    
    Apparently in some cases GNOME Shell will traceback if a search provider
    is not activatable. Provide a DBus service file for ourselves and a
    --no-default-window command line option to support that. Activating
    when we're not running may eventually be useful for searching across
    history.
    
    Consistently use org.gnome.hotssh as a namespace, not org.gnome.HotSsh.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712345

 Makefile-src.am                             |    3 +++
 src/hotssh-app.c                            |   22 ++++++++++++++++++----
 src/hotssh-search-provider.c                |   13 +++++++++++--
 src/hotssh-search-provider.ini              |    2 +-
 src/org.gnome.hotssh.SearchProvider.service |    3 +++
 5 files changed, 36 insertions(+), 7 deletions(-)
---
diff --git a/Makefile-src.am b/Makefile-src.am
index 582f81c..ed2cf73 100644
--- a/Makefile-src.am
+++ b/Makefile-src.am
@@ -59,6 +59,9 @@ desktop_DATA = src/hotssh.desktop
 searchproviderdir = $(datadir)/gnome-shell/search-providers
 searchprovider_DATA = src/hotssh-search-provider.ini
 
+servicedir = $(datadir)/dbus-1/services
+service_DATA = src/org.gnome.hotssh.SearchProvider.service
+
 # Don't install this, it's large.
 # scalableiconsdir = $(datadir)/icons/hicolor/scalable/apps/
 # dist_scalableicons_DATA = src/icons/hotssh.svg
diff --git a/src/hotssh-app.c b/src/hotssh-app.c
index bf73bbf..32e05fe 100644
--- a/src/hotssh-app.c
+++ b/src/hotssh-app.c
@@ -112,6 +112,7 @@ hotssh_app_command_line (GApplication              *app,
   gint i;
   GError *error = NULL;
   gint argc;
+  gboolean no_default_window = FALSE;
   char *host = NULL;
   char *username = NULL;
   gboolean help = FALSE;
@@ -120,6 +121,7 @@ hotssh_app_command_line (GApplication              *app,
     { "host", 'h', 0, G_OPTION_ARG_STRING, &host, NULL, NULL },
     { "username", 'u', 0, G_OPTION_ARG_STRING, &username, NULL, NULL },
     { "help", '?', 0, G_OPTION_ARG_NONE, &help, NULL, NULL },
+    { "no-default-window", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &no_default_window, NULL, NULL },
     { NULL } 
   };
 
@@ -146,10 +148,21 @@ hotssh_app_command_line (GApplication              *app,
 
   g_strfreev (args);
   g_option_context_free (context);
-      
-  win = hotssh_window_new (HOTSSH_APP (app));
-  gtk_widget_show_all ((GtkWidget*)win);
-  gtk_window_present (GTK_WINDOW (win));
+
+  if (no_default_window)
+    {
+      /* By calling hold() and release() we trigger the inactivity timeout,
+       * so that we stick around until a D-Bus method call can be made.
+       */
+      g_application_hold (app);
+      g_application_release (app);
+    }
+  else
+    {
+      win = hotssh_window_new (HOTSSH_APP (app));
+      gtk_widget_show_all ((GtkWidget*)win);
+      gtk_window_present (GTK_WINDOW (win));
+    }
 
   return 0;
 }
@@ -168,5 +181,6 @@ hotssh_app_new (void)
   return g_object_new (HOTSSH_TYPE_APP,
                        "application-id", "org.gnome.hotssh",
                        "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
+                       "inactivity-timeout", 120000, /* 2 minutes */
                        NULL);
 }
diff --git a/src/hotssh-search-provider.c b/src/hotssh-search-provider.c
index 2062f30..21c4c9c 100644
--- a/src/hotssh-search-provider.c
+++ b/src/hotssh-search-provider.c
@@ -130,7 +130,16 @@ handle_get_initial_result_set (HotSshSearchShellSearchProvider2 *skeleton,
                                char                            **terms,
                                HotSshSearchProvider             *search_provider)
 {
-  gs_strfreev char **results = get_results (search_provider, terms);
+  HotSshSearchProviderPrivate *priv = hotssh_search_provider_get_instance_private (search_provider);
+  gs_strfreev char **results;
+
+  /* By calling hold() and release() we trigger the inactivity timeout, so that we stick around
+   * for a few minutes in case the user searches again.
+   */
+  g_application_hold (G_APPLICATION (priv->app));
+  g_application_release (G_APPLICATION (priv->app));
+
+  results = get_results (search_provider, terms);
   hot_ssh_search_shell_search_provider2_complete_get_initial_result_set (skeleton, invocation, (const char * 
const *)results);
 
   return TRUE;
@@ -292,7 +301,7 @@ hotssh_search_provider_init (HotSshSearchProvider *search_provider)
   HotSshSearchProviderPrivate *priv = hotssh_search_provider_get_instance_private (search_provider);
 
   priv->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
-                                   "org.gnome.HotSsh.SearchProvider",
+                                   "org.gnome.hotssh.SearchProvider",
                                    G_BUS_NAME_OWNER_FLAGS_NONE,
                                    on_bus_acquired,
                                    on_name_acquired,
diff --git a/src/hotssh-search-provider.ini b/src/hotssh-search-provider.ini
index 0615303..f19aa5a 100644
--- a/src/hotssh-search-provider.ini
+++ b/src/hotssh-search-provider.ini
@@ -1,5 +1,5 @@
 [Shell Search Provider]
 DesktopId=hotssh.desktop
-BusName=org.gnome.HotSsh.SearchProvider
+BusName=org.gnome.hotssh.SearchProvider
 ObjectPath=/org/gnome/hotssh/SearchProvider
 Version=2
diff --git a/src/org.gnome.hotssh.SearchProvider.service b/src/org.gnome.hotssh.SearchProvider.service
new file mode 100644
index 0000000..d5396d8
--- /dev/null
+++ b/src/org.gnome.hotssh.SearchProvider.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.hotssh.SearchProvider
+Exec=hotssh --no-default-window


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