[gnome-terminal/wip/search: 2/2] server: Add a search provider



commit 0b123c7f4c6e907ea15c0d1649862f2a7c3c852d
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 4 17:05:05 2013 +0100

    server: Add a search provider
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711075

 src/Makefile.am                        |   14 ++
 src/gnome-terminal-search-provider.ini |   20 ++
 src/org.gnome.ShellSearchProvider2.xml |   87 ++++++++
 src/terminal-app.c                     |   12 +
 src/terminal-debug.c                   |    1 +
 src/terminal-debug.h                   |    3 +-
 src/terminal-search-provider.c         |  355 ++++++++++++++++++++++++++++++++
 src/terminal-search-provider.h         |   51 +++++
 8 files changed, 542 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 48c3ad3..22a2128 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,9 @@ endif # WITH_NAUTILUS_EXTENSION
 
 dbusservice_DATA = org.gnome.Terminal.service
 
+searchproviderdir = $(datadir)/gnome-shell/search-providers
+searchprovider_DATA = gnome-terminal-search-provider.ini
+
 BUILT_SOURCES = \
        terminal-marshal.c \
        terminal-marshal.h \
@@ -19,6 +22,8 @@ BUILT_SOURCES = \
        terminal-type-builtins.h \
        terminal-gdbus-generated.c \
        terminal-gdbus-generated.h \
+       terminal-search-provider-gdbus-generated.c \
+       terminal-search-provider-gdbus-generated.h \
        terminal-resources.c \
        terminal-resources.h \
        $(NULL)
@@ -66,6 +71,8 @@ gnome_terminal_server_SOURCES = \
        terminal-screen-container.h \
        terminal-search-dialog.c \
        terminal-search-dialog.h \
+       terminal-search-provider.c \
+       terminal-search-provider.h \
        terminal-tab-label.c \
        terminal-tab-label.h \
        terminal-tabs-menu.c \
@@ -143,6 +150,13 @@ terminal-gdbus-generated.c terminal-gdbus-generated.h: org.gnome.Terminal.xml Ma
                        --generate-c-code terminal-gdbus-generated \
                        $<
 
+terminal-search-provider-gdbus-generated.c terminal-search-provider-gdbus-generated.h: 
org.gnome.ShellSearchProvider2.xml Makefile
+       $(AM_V_GEN) $(GDBUS_CODEGEN) \
+                       --interface-prefix=org.gnome.Shell \
+                       --c-namespace=Terminal \
+                       --generate-c-code terminal-search-provider-gdbus-generated \
+                       $<
+
 terminal-resources.h terminal-resources.c: terminal.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies --sourcedir $(srcdir) $(srcdir)/terminal.gresource.xml)
        $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate 
--c-name terminal $<
 
diff --git a/src/gnome-terminal-search-provider.ini b/src/gnome-terminal-search-provider.ini
new file mode 100644
index 0000000..09c26bc
--- /dev/null
+++ b/src/gnome-terminal-search-provider.ini
@@ -0,0 +1,20 @@
+# Copyright © 2013 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+[Shell Search Provider]
+DesktopId=gnome-terminal.desktop
+BusName=org.gnome.Terminal
+ObjectPath=/org/gnome/Terminal
+Version=2
diff --git a/src/org.gnome.ShellSearchProvider2.xml b/src/org.gnome.ShellSearchProvider2.xml
new file mode 100644
index 0000000..9502340
--- /dev/null
+++ b/src/org.gnome.ShellSearchProvider2.xml
@@ -0,0 +1,87 @@
+<!DOCTYPE node PUBLIC
+'-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
+'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
+<node>
+
+  <!--
+      org.gnome.Shell.SearchProvider2:
+      @short_description: Search provider interface
+
+      The interface used for integrating into GNOME Shell's search
+      interface (version 2).
+  -->
+  <interface name="org.gnome.Shell.SearchProvider2">
+
+    <!--
+        GetInitialResultSet:
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @results: An array of result identifier strings representing items which match the given search 
terms. Identifiers must be unique within the provider's domain, but other than that may be chosen freely by 
the provider.
+
+        Called when the user first begins a search.
+    -->
+    <method name="GetInitialResultSet">
+      <arg type="as" name="terms" direction="in" />
+      <arg type="as" name="results" direction="out" />
+    </method>
+
+    <!--
+        GetSubsearchResultSet:
+        @previous_results: Array of results previously returned by GetInitialResultSet().
+        @terms: Array of updated search terms, which the provider should treat as logical AND.
+        @results: An array of result identifier strings representing items which match the given search 
terms. Identifiers must be unique within the provider's domain, but other than that may be chosen freely by 
the provider.
+
+        Called when a search is performed which is a "subsearch" of
+        the previous search, e.g. the method may return less results, but
+        not more or different results.
+
+        This allows search providers to only search through the previous
+        result set, rather than possibly performing a full re-query.
+    -->
+    <method name="GetSubsearchResultSet">
+      <arg type="as" name="previous_results" direction="in" />
+      <arg type="as" name="terms" direction="in" />
+      <arg type="as" name="results" direction="out" />
+    </method>
+
+    <!--
+        GetResultMetas:
+        @identifiers: An array of result identifiers as returned by GetInitialResultSet() or 
GetSubsearchResultSet()
+        @metas: A dictionary describing the given search result, containing a human-readable 'name' 
(string), along with the result identifier this meta is for, 'id' (string). Optionally, 'icon' (a serialized 
GIcon as obtained by g_icon_serialize) can be specified if the result can be better served with a thumbnail 
of the content (such as with images). 'gicon' (a serialized GIcon as obtained by g_icon_to_string) or 
'icon-data' (raw image data as (iiibiiay) - width, height, rowstride, has-alpha, bits per sample, channels, 
data) are deprecated values that can also be used for that purpose. A 'description' field (string) may also 
be specified if more context would help the user find the desired result.
+
+        Return an array of meta data used to display each given result
+    -->
+    <method name="GetResultMetas">
+      <arg type="as" name="identifiers" direction="in" />
+      <arg type="aa{sv}" name="metas" direction="out" />
+    </method>
+
+    <!--
+        ActivateResult:
+        @identifier: A result identifier as returned by GetInitialResultSet() or GetSubsearchResultSet()
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @timestamp: A timestamp of the user interaction that triggered this call
+
+        Called when the users chooses a given result. The result should
+        be displayed in the application associated with the corresponding
+        provider. The provided search terms can be used to allow launching a full search in
+        the application.
+    -->
+    <method name="ActivateResult">
+      <arg type="s" name="identifier" direction="in" />
+      <arg type="as" name="terms" direction="in" />
+      <arg type="u" name="timestamp" direction="in" />
+    </method>
+
+    <!--
+        LaunchSearch:
+        @terms: Array of search terms, which the provider should treat as logical AND.
+        @timestamp: A timestamp of the user interaction that triggered this call
+
+        Asks the search provider to launch a full search in the application for the provided terms.
+    -->
+    <method name="LaunchSearch">
+      <arg type="as" name="terms" direction="in" />
+      <arg type="u" name="timestamp" direction="in" />
+    </method>
+  </interface>
+</node>
diff --git a/src/terminal-app.c b/src/terminal-app.c
index c06c454..282db14 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -31,6 +31,7 @@
 #include "terminal-accels.h"
 #include "terminal-screen.h"
 #include "terminal-screen-container.h"
+#include "terminal-search-provider.h"
 #include "terminal-window.h"
 #include "terminal-profiles-list.h"
 #include "terminal-util.h"
@@ -72,6 +73,7 @@ struct _TerminalApp
   GtkApplication parent_instance;
 
   GDBusObjectManagerServer *object_manager;
+  TerminalSearchProvider *search_provider;
 
   TerminalSettingsList *profiles_list;
 
@@ -345,6 +347,9 @@ terminal_app_init (TerminalApp *app)
 
   gtk_window_set_default_icon_name (GNOME_TERMINAL_ICON_NAME);
 
+  /* Search provider */
+  app->search_provider = terminal_search_provider_new ();
+
   /* Desktop proxy settings */
   app->system_proxy_settings = g_settings_new (SYSTEM_PROXY_SETTINGS_SCHEMA);
 
@@ -389,6 +394,7 @@ terminal_app_finalize (GObject *object)
   g_object_unref (app->global_settings);
   g_object_unref (app->desktop_interface_settings);
   g_object_unref (app->system_proxy_settings);
+  g_object_unref (app->search_provider);
 
   terminal_accels_shutdown ();
 
@@ -411,6 +417,9 @@ terminal_app_dbus_register (GApplication    *application,
                                                                        error))
     return FALSE;
 
+  if (!terminal_search_provider_dbus_register (app->search_provider, connection, object_path, error))
+    return FALSE;
+
   object = terminal_object_skeleton_new (TERMINAL_FACTORY_OBJECT_PATH);
   factory = terminal_factory_impl_new ();
   terminal_object_skeleton_set_factory (object, factory);
@@ -420,6 +429,7 @@ terminal_app_dbus_register (GApplication    *application,
 
   /* And export the object */
   g_dbus_object_manager_server_set_connection (app->object_manager, connection);
+
   return TRUE;
 }
 
@@ -436,6 +446,8 @@ terminal_app_dbus_unregister (GApplication    *application,
     app->object_manager = NULL;
   }
 
+  terminal_search_provider_dbus_unregister (app->search_provider, connection, object_path);
+
   G_APPLICATION_CLASS (terminal_app_parent_class)->dbus_unregister (application,
                                                                     connection,
                                                                     object_path);
diff --git a/src/terminal-debug.c b/src/terminal-debug.c
index c525cdf..9325c88 100644
--- a/src/terminal-debug.c
+++ b/src/terminal-debug.c
@@ -37,6 +37,7 @@ _terminal_debug_init(void)
     { "profile",       TERMINAL_DEBUG_PROFILE       },
     { "settings-list", TERMINAL_DEBUG_SETTINGS_LIST },
     { "appmenu",       TERMINAL_DEBUG_APPMENU       },
+    { "search",        TERMINAL_DEBUG_SEARCH        },
   };
 
   _terminal_debug_flags = g_parse_debug_string (g_getenv ("GNOME_TERMINAL_DEBUG"),
diff --git a/src/terminal-debug.h b/src/terminal-debug.h
index aec9c54..ab47975 100644
--- a/src/terminal-debug.h
+++ b/src/terminal-debug.h
@@ -33,7 +33,8 @@ typedef enum {
   TERMINAL_DEBUG_PROCESSES     = 1 << 5,
   TERMINAL_DEBUG_PROFILE       = 1 << 6,
   TERMINAL_DEBUG_SETTINGS_LIST = 1 << 7,
-  TERMINAL_DEBUG_APPMENU       = 1 << 8
+  TERMINAL_DEBUG_APPMENU       = 1 << 8,
+  TERMINAL_DEBUG_SEARCH        = 1 << 9
 } TerminalDebugFlags;
 
 void _terminal_debug_init(void);
diff --git a/src/terminal-search-provider.c b/src/terminal-search-provider.c
new file mode 100644
index 0000000..a2f3a25
--- /dev/null
+++ b/src/terminal-search-provider.c
@@ -0,0 +1,355 @@
+/*
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include "terminal-app.h"
+#include "terminal-debug.h"
+#include "terminal-libgsystem.h"
+#include "terminal-screen-container.h"
+#include "terminal-search-provider.h"
+#include "terminal-search-provider-gdbus-generated.h"
+#include "terminal-window.h"
+
+struct _TerminalSearchProvider
+{
+  GObject parent;
+
+  GHashTable *hash;
+  TerminalSearchProvider2 *skeleton;
+};
+
+struct _TerminalSearchProviderClass
+{
+  GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (TerminalSearchProvider, terminal_search_provider, G_TYPE_OBJECT)
+
+static gboolean
+match_terms (const char        *str,
+             char             **terms)
+{
+  gboolean matches = TRUE;
+  guint i;
+
+  if (str == NULL)
+    {
+      matches = FALSE;
+      goto out;
+    }
+
+  for (i = 0; terms[i] != NULL; i++)
+    {
+      if (strstr (str, terms[i]) == NULL)
+        {
+          matches = FALSE;
+          break;
+        }
+    }
+
+ out:
+  return matches;
+}
+
+static gboolean
+handle_get_initial_result_set_cb (TerminalSearchProvider2  *skeleton,
+                                  GDBusMethodInvocation    *invocation,
+                                  char                    **terms,
+                                  gpointer                  user_data)
+{
+  TerminalSearchProvider *provider = TERMINAL_SEARCH_PROVIDER (user_data);
+  GList *l, *screens = NULL, *windows;
+  GPtrArray *results;
+  TerminalApp *app;
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetInitialResultSet started\n");
+
+  app = terminal_app_get ();
+  windows = gtk_application_get_windows (GTK_APPLICATION (app));
+  for (l = windows; l != NULL; l = l->next)
+    {
+      TerminalWindow *window = TERMINAL_WINDOW (l->data);
+      GList *c, *containers;
+
+      containers = terminal_window_list_screen_containers (window);
+      for (c = containers; c != NULL; c = c->next)
+        {
+          TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (c->data);
+          TerminalScreen *screen;
+
+          screen = terminal_screen_container_get_screen (container);
+          screens = g_list_prepend (screens, screen);
+        }
+    }
+
+  results = g_ptr_array_new ();
+  g_hash_table_remove_all (provider->hash);
+
+  for (l = screens; l != NULL; l = l->next)
+    {
+      TerminalScreen *screen = TERMINAL_SCREEN (l->data);
+      gs_free char *cmdline = NULL, *cwd = NULL, *process = NULL;
+      const char *title;
+
+      cwd = terminal_screen_get_current_dir (screen);
+      title = terminal_screen_get_title (screen);
+      terminal_screen_has_foreground_process (screen, &process, &cmdline);
+      if (match_terms (cwd, terms) ||
+          match_terms (title, terms) ||
+          match_terms (process, terms) ||
+          match_terms (cmdline, terms))
+        {
+          gs_free gchar *key = NULL;
+
+          key = g_strdup_printf ("%p", screen);
+          g_hash_table_insert (provider->hash, g_strdup (key), screen);
+          g_ptr_array_add (results, g_strdup (key));
+
+          _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "Search hit: %s\n", key);
+        }
+    }
+
+  g_ptr_array_add (results, NULL);
+  terminal_search_provider2_complete_get_initial_result_set (skeleton,
+                                                             invocation,
+                                                             (const char *const *) results->pdata);
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetInitialResultSet completed\n");
+
+  g_strfreev ((gchar **) results->pdata);
+  g_ptr_array_free (results, FALSE);
+  return TRUE;
+}
+
+static gboolean
+handle_get_subsearch_result_set_cb (TerminalSearchProvider2  *skeleton,
+                                    GDBusMethodInvocation    *invocation,
+                                    char                    **previous_results,
+                                    char                    **terms,
+                                    gpointer                  user_data)
+{
+  TerminalSearchProvider *provider = TERMINAL_SEARCH_PROVIDER (user_data);
+  GPtrArray *results;
+  guint i;
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetSubsearchResultSet started\n");
+
+  results = g_ptr_array_new ();
+
+  for (i = 0; previous_results[i] != NULL; i++)
+    {
+      TerminalScreen *screen;
+      gs_free char *cmdline = NULL, *cwd = NULL, *process = NULL;
+      const char *title;
+      gpointer value;
+
+      value = g_hash_table_lookup (provider->hash, previous_results[i]);
+      if (!TERMINAL_IS_SCREEN (value))
+        {
+          _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "Not a screen: %s\n", previous_results[i]);
+          continue;
+        }
+
+      screen = TERMINAL_SCREEN (value);
+      cwd = terminal_screen_get_current_dir (screen);
+      title = terminal_screen_get_title (screen);
+      terminal_screen_has_foreground_process (screen, &process, &cmdline);
+      if (match_terms (cwd, terms) ||
+          match_terms (title, terms) ||
+          match_terms (process, terms) ||
+          match_terms (cmdline, terms))
+        {
+          g_ptr_array_add (results, g_strdup (previous_results[i]));
+          _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "Search hit: %s\n", previous_results[i]);
+        }
+    }
+
+  g_ptr_array_add (results, NULL);
+  terminal_search_provider2_complete_get_subsearch_result_set (skeleton,
+                                                               invocation,
+                                                               (const char *const *) results->pdata);
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetSubsearchResultSet completed\n");
+
+  g_strfreev ((gchar **) results->pdata);
+  g_ptr_array_free (results, FALSE);
+  return TRUE;
+}
+
+static gboolean
+text_is_selected_cb (VteTerminal *terminal,
+                     glong        column,
+                     glong        row,
+                     gpointer     user_data)
+{
+  glong cursor_row;
+
+  vte_terminal_get_cursor_position (terminal, NULL, &cursor_row);
+  if (cursor_row - 1 <= row && row <= cursor_row + 1)
+    return TRUE;
+  return FALSE;
+}
+
+static gboolean
+handle_get_result_metas_cb (TerminalSearchProvider2  *skeleton,
+                            GDBusMethodInvocation    *invocation,
+                            char                    **results,
+                            gpointer                  user_data)
+{
+  TerminalSearchProvider *provider = TERMINAL_SEARCH_PROVIDER (user_data);
+  GVariantBuilder builder;
+  guint i;
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetResultMetas started\n");
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
+
+  for (i = 0; results[i] != NULL; i++)
+    {
+      TerminalScreen *screen;
+      const char *title;
+      gs_free char *escaped_text = NULL;
+      gs_free char *text = NULL;
+      gpointer value;
+
+      value = g_hash_table_lookup (provider->hash, results[i]);
+      if (!TERMINAL_IS_SCREEN (value))
+        {
+          _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "Not a screen: %s\n", results[i]);
+          continue;
+        }
+
+      screen = TERMINAL_SCREEN (value);
+      title = terminal_screen_get_title (screen);
+      if (terminal_screen_has_foreground_process (screen, NULL, NULL))
+        text = vte_terminal_get_text (VTE_TERMINAL (screen), text_is_selected_cb, NULL, NULL);
+
+      g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
+      g_variant_builder_add (&builder, "{sv}", "id", g_variant_new_string (results[i]));
+      g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (title));
+      if (text != NULL)
+        {
+          escaped_text = g_markup_escape_text (text, -1);
+          g_variant_builder_add (&builder, "{sv}", "description", g_variant_new_string (escaped_text));
+        }
+      g_variant_builder_close (&builder);
+
+      _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "Meta for %s: %s\n", results[i], title);
+    }
+
+  terminal_search_provider2_complete_get_result_metas (skeleton, invocation, g_variant_builder_end 
(&builder));
+
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "GetResultMetas completed\n");
+
+  return TRUE;
+}
+
+static gboolean
+handle_activate_result_cb (TerminalSearchProvider2  *skeleton,
+                           GDBusMethodInvocation    *invocation,
+                           char                     *identifier,
+                           char                    **terms,
+                           guint                     timestamp,
+                           gpointer                  user_data)
+{
+  TerminalSearchProvider *provider = TERMINAL_SEARCH_PROVIDER (user_data);
+  GtkWidget *toplevel;
+  TerminalScreen *screen;
+  gpointer value;
+
+  value = g_hash_table_lookup (provider->hash, identifier);
+  if (!TERMINAL_IS_SCREEN (value))
+    goto out;
+
+  screen = TERMINAL_SCREEN (value);
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (screen));
+  if (!gtk_widget_is_toplevel (toplevel))
+    goto out;
+
+  gtk_window_present_with_time (GTK_WINDOW (toplevel), timestamp);
+  _terminal_debug_print (TERMINAL_DEBUG_SEARCH, "ActivateResult: %s\n", identifier);
+
+ out:
+  terminal_search_provider2_complete_activate_result (skeleton, invocation);
+  return TRUE;
+}
+
+static void
+terminal_search_provider_init (TerminalSearchProvider *provider)
+{
+  provider->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+  provider->skeleton = terminal_search_provider2_skeleton_new ();
+
+  g_signal_connect (provider->skeleton, "handle-get-initial-result-set",
+                    G_CALLBACK (handle_get_initial_result_set_cb), provider);
+  g_signal_connect (provider->skeleton, "handle-get-subsearch-result-set",
+                    G_CALLBACK (handle_get_subsearch_result_set_cb), provider);
+  g_signal_connect (provider->skeleton, "handle-get-result-metas",
+                    G_CALLBACK (handle_get_result_metas_cb), provider);
+  g_signal_connect (provider->skeleton, "handle-activate-result",
+                    G_CALLBACK (handle_activate_result_cb), provider);
+}
+
+static void
+terminal_search_provider_dispose (GObject *object)
+{
+  TerminalSearchProvider *provider = TERMINAL_SEARCH_PROVIDER (object);
+
+  g_clear_object (&provider->skeleton);
+  g_clear_pointer (&provider->hash, (GDestroyNotify) g_hash_table_unref);
+
+  G_OBJECT_CLASS (terminal_search_provider_parent_class)->dispose (object);
+}
+
+static void
+terminal_search_provider_class_init (TerminalSearchProviderClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->dispose = terminal_search_provider_dispose;
+}
+
+TerminalSearchProvider *
+terminal_search_provider_new (void)
+{
+  return g_object_new (TERMINAL_TYPE_SEARCH_PROVIDER, NULL);
+}
+
+gboolean
+terminal_search_provider_dbus_register (TerminalSearchProvider  *provider,
+                                        GDBusConnection         *connection,
+                                        const char              *object_path,
+                                        GError                 **error)
+{
+  return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (provider->skeleton),
+                                           connection,
+                                           object_path,
+                                           error);
+}
+
+void
+terminal_search_provider_dbus_unregister (TerminalSearchProvider  *provider,
+                                          GDBusConnection         *connection,
+                                          const char              *object_path)
+{
+  if (g_dbus_interface_skeleton_has_connection (G_DBUS_INTERFACE_SKELETON (provider->skeleton), connection))
+    g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (provider->skeleton),
+                                                        connection);
+}
diff --git a/src/terminal-search-provider.h b/src/terminal-search-provider.h
new file mode 100644
index 0000000..719bd3e
--- /dev/null
+++ b/src/terminal-search-provider.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TERMINAL_SEARCH_PROVIDER_H
+#define TERMINAL_SEARCH_PROVIDER_H
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_SEARCH_PROVIDER              (terminal_search_provider_get_type ())
+#define TERMINAL_SEARCH_PROVIDER(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), 
TERMINAL_TYPE_SEARCH_PROVIDER, TerminalSearchProvider))
+#define TERMINAL_SEARCH_PROVIDER_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), 
TERMINAL_TYPE_SEARCH_PROVIDER, TerminalSearchProviderClass))
+#define TERMINAL_IS_SEARCH_PROVIDER(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), 
TERMINAL_TYPE_SEARCH_PROVIDER))
+#define TERMINAL_IS_SEARCH_PROVIDER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), 
TERMINAL_TYPE_SEARCH_PROVIDER))
+#define TERMINAL_SEARCH_PROVIDER_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), 
TERMINAL_TYPE_SEARCH_PROVIDER, TerminalSearchProviderClass))
+
+typedef struct _TerminalSearchProvider      TerminalSearchProvider;
+typedef struct _TerminalSearchProviderClass TerminalSearchProviderClass;
+
+GType terminal_search_provider_get_type (void);
+
+TerminalSearchProvider *terminal_search_provider_new (void);
+
+gboolean terminal_search_provider_dbus_register (TerminalSearchProvider  *provider,
+                                                 GDBusConnection         *connection,
+                                                 const char              *object_path,
+                                                 GError                 **error);
+
+void terminal_search_provider_dbus_unregister (TerminalSearchProvider  *provider,
+                                               GDBusConnection         *connection,
+                                               const char              *object_path);
+
+G_END_DECLS
+
+#endif /* !TERMINAL_SEARCH_PROVIDER_H */


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