diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2012-09-05 11:51:50 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2012-09-06 09:49:08 -0400 |
commit | 8e491b6492e4cc0e608faab35c865fd5fd98a416 (patch) | |
tree | 2b3f391529e0289a994767840bf68e54b0f71f9f /src | |
parent | c68654c1a018faf5e55dee71c45617cd8e248855 (diff) | |
download | nautilus-8e491b6492e4cc0e608faab35c865fd5fd98a416.tar.gz |
shell-provider: add a first skeleton of the shell search provider
It's not wired in yet.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 39 | ||||
-rw-r--r-- | src/nautilus-shell-search-provider.c | 204 |
2 files changed, 238 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 10e576d43..3319877a4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,7 @@ bin_PROGRAMS= \ libexec_PROGRAMS= \ nautilus-convert-metadata \ + nautilus-shell-search-provider \ $(NULL) INCLUDES = \ @@ -43,8 +44,11 @@ LDADD =\ $(POPT_LIBS) \ $(NULL) -dbus_built_sources = nautilus-freedesktop-generated.c nautilus-freedesktop-generated.h -$(dbus_built_sources) : Makefile.am $(top_srcdir)/data/freedesktop-dbus-interfaces.xml +dbus_freedesktop_built_sources = \ + nautilus-freedesktop-generated.c \ + nautilus-freedesktop-generated.h + +$(dbus_freedesktop_built_sources) : Makefile.am $(top_srcdir)/data/freedesktop-dbus-interfaces.xml gdbus-codegen \ --interface-prefix org.freedesktop. \ --c-namespace NautilusFreedesktop \ @@ -113,8 +117,8 @@ nautilus-enum-types.c: $(headers) Makefile && cp xgen-gtc $(@F) \ && rm -f xgen-gtc -BUILT_SOURCES = \ - $(dbus_built_sources) \ +nautilus_built_sources = \ + $(dbus_freedesktop_built_sources) \ nautilus-resources.c \ nautilus-resources.h \ nautilus-enum-types.h \ @@ -209,7 +213,7 @@ nautilus_SOURCES = \ $(NULL) nodist_nautilus_SOURCES = \ - $(BUILT_SOURCES) \ + $(nautilus_built_sources) \ $(NULL) EMPTY_VIEW_SOURCES = \ @@ -234,6 +238,31 @@ nautilus_convert_metadata_SOURCES= \ nautilus-convert-metadata.c \ $(NULL) +dbus_shell_search_provider_built_sources = \ + nautilus-shell-search-provider-generated.c \ + nautilus-shell-search-provider-generated.h + +$(dbus_shell_search_provider_built_sources) : Makefile.am $(top_srcdir)/data/shell-search-provider-dbus-interfaces.xml + gdbus-codegen \ + --interface-prefix org.gnome. \ + --c-namespace Nautilus \ + --generate-c-code nautilus-shell-search-provider-generated \ + $(top_srcdir)/data/shell-search-provider-dbus-interfaces.xml \ + $(NULL) + +nautilus_shell_search_provider_SOURCES = \ + nautilus-shell-search-provider.c \ + $(NULL) + +nodist_nautilus_shell_search_provider_SOURCES = \ + $(dbus_shell_search_provider_built_sources) \ + $(NULL) + +BUILT_SOURCES = \ + $(nautilus_built_sources) \ + $(dbus_shell_search_provider_built_sources) \ + $(NULL) + TESTS=check-nautilus @INTLTOOL_SERVER_RULE@ diff --git a/src/nautilus-shell-search-provider.c b/src/nautilus-shell-search-provider.c new file mode 100644 index 000000000..cc626e778 --- /dev/null +++ b/src/nautilus-shell-search-provider.c @@ -0,0 +1,204 @@ +/* + * nautilus-shell-search-provider.c - Implementation of a GNOME Shell + * search provider + * + * Copyright (C) 2012 Red Hat, Inc. + * + * Nautilus 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 2 of the + * License, or (at your option) any later version. + * + * Nautilus 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Authors: Cosimo Cecchi <cosimoc@gnome.org> + * + */ + +#include <config.h> + +#include <gio/gio.h> + +#include "nautilus-shell-search-provider-generated.h" + +#define SEARCH_PROVIDER_INACTIVITY_TIMEOUT 12000 /* milliseconds */ + +typedef struct { + GApplication parent; + + guint name_owner_id; + + GDBusObjectManagerServer *object_manager; + NautilusShellSearchProvider *skeleton; +} NautilusShellSearchProviderApp; + +typedef GApplicationClass NautilusShellSearchProviderAppClass; + +GType nautilus_shell_search_provider_app_get_type (void); + +#define NAUTILUS_TYPE_SHELL_SEARCH_PROVIDER_APP nautilus_shell_search_provider_app_get_type() +#define NAUTILUS_SHELL_SEARCH_PROVIDER_APP(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_SHELL_SEARCH_PROVIDER_APP, NautilusShellSearchProviderApp)) + +G_DEFINE_TYPE (NautilusShellSearchProviderApp, nautilus_shell_search_provider_app, G_TYPE_APPLICATION) + +static void +handle_get_initial_result_set (GDBusMethodInvocation *invocation, + gchar **terms) +{ + +} + +static void +handle_get_subsearch_result_set (GDBusMethodInvocation *invocation, + gchar **previous_results, + gchar **terms) +{ + +} + +static void +handle_get_result_metas (GDBusMethodInvocation *invocation, + gchar **results) +{ + +} + +static void +handle_activate_result (GDBusMethodInvocation *invocation, + gchar *result) +{ + +} + +static void +search_provider_name_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_debug ("Search provider name acquired: %s\n", name); +} + +static void +search_provider_name_lost_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_debug ("Search provider name lost: %s\n", name); +} + +static void +search_provider_bus_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + NautilusShellSearchProviderApp *self = user_data; + + self->object_manager = g_dbus_object_manager_server_new ("/org/gnome/Nautilus/SearchProvider"); + self->skeleton = nautilus_shell_search_provider_skeleton_new (); + + g_signal_connect (self->skeleton, "handle-get-initial-result-set", + G_CALLBACK (handle_get_initial_result_set), self); + g_signal_connect (self->skeleton, "handle-get-subsearch-result-set", + G_CALLBACK (handle_get_subsearch_result_set), self); + g_signal_connect (self->skeleton, "handle-get-result-metas", + G_CALLBACK (handle_get_result_metas), self); + g_signal_connect (self->skeleton, "handle-activate-result", + G_CALLBACK (handle_activate_result), self); + + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton), + connection, + "/org/gnome/Nautilus/SearchProvider", NULL); + g_dbus_object_manager_server_set_connection (self->object_manager, connection); +} + +static void +search_provider_app_dispose (GObject *obj) +{ + NautilusShellSearchProviderApp *self = NAUTILUS_SHELL_SEARCH_PROVIDER_APP (obj); + + if (self->name_owner_id != 0) { + g_bus_unown_name (self->name_owner_id); + self->name_owner_id = 0; + } + + if (self->skeleton != NULL) { + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->skeleton)); + g_clear_object (&self->skeleton); + } + + g_clear_object (&self->object_manager); + + G_OBJECT_CLASS (nautilus_shell_search_provider_app_parent_class)->dispose (obj); +} + +static void +search_provider_app_startup (GApplication *app) +{ + NautilusShellSearchProviderApp *self = NAUTILUS_SHELL_SEARCH_PROVIDER_APP (app); + + G_APPLICATION_CLASS (nautilus_shell_search_provider_app_parent_class)->startup (app); + + /* hold indefinitely if we're asked to persist */ + if (g_getenv ("NAUTILUS_SEARCH_PROVIDER_PERSIST") != NULL) + g_application_hold (app); + + self->name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, + "org.gnome.Nautilus.SearchProvider", + G_BUS_NAME_OWNER_FLAGS_NONE, + search_provider_bus_acquired_cb, + search_provider_name_acquired_cb, + search_provider_name_lost_cb, + app, NULL); +} + +static void +nautilus_shell_search_provider_app_init (NautilusShellSearchProviderApp *self) +{ + GApplication *app = G_APPLICATION (self); + + g_application_set_inactivity_timeout (app, SEARCH_PROVIDER_INACTIVITY_TIMEOUT); + g_application_set_application_id (app, "org.gnome.Nautilus.SearchProvider"); + g_application_set_flags (app, G_APPLICATION_IS_SERVICE); +} + +static void +nautilus_shell_search_provider_app_class_init (NautilusShellSearchProviderAppClass *klass) +{ + GApplicationClass *aclass = G_APPLICATION_CLASS (klass); + GObjectClass *oclass = G_OBJECT_CLASS (klass); + + aclass->startup = search_provider_app_startup; + oclass->dispose = search_provider_app_dispose; +} + +static GApplication * +nautilus_shell_search_provider_app_new (void) +{ + g_type_init (); + + return g_object_new (nautilus_shell_search_provider_app_get_type (), + NULL); +} + +int +main (int argc, + char *argv[]) +{ + GApplication *app; + gint res; + + app = nautilus_shell_search_provider_app_new (); + res = g_application_run (app, argc, argv); + g_object_unref (app); + + return res; +} + |