summaryrefslogtreecommitdiffstats
path: root/nautilus
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-01-14 00:27:48 +0100
committerGravatar Martin Szulecki2010-01-14 01:00:07 +0100
commita340c7548c33018798021b6f71d25e6761eaf6a0 (patch)
treed02314f230651f87a765c0a4794ece2df5913c87 /nautilus
parentc9b0721d65834ab6cf22453c39d6b9e97bd9db25 (diff)
downloadsbmanager-a340c7548c33018798021b6f71d25e6761eaf6a0.tar.gz
sbmanager-a340c7548c33018798021b6f71d25e6761eaf6a0.tar.bz2
nautilus-sbmanager: adds a 'launch sbmanager' entry to nautilus' context menu
Diffstat (limited to 'nautilus')
-rw-r--r--nautilus/Makefile.am22
-rw-r--r--nautilus/nautilus-sbmanager.c180
-rw-r--r--nautilus/nautilus-sbmanager.h54
-rw-r--r--nautilus/nautilus-sbmgr.c57
4 files changed, 313 insertions, 0 deletions
diff --git a/nautilus/Makefile.am b/nautilus/Makefile.am
new file mode 100644
index 0000000..8a43af8
--- /dev/null
+++ b/nautilus/Makefile.am
@@ -0,0 +1,22 @@
+INCLUDES = \
+ -DG_LOG_DOMAIN=\"Nautilus-SBManager\" \
+ -DDATADIR=\"$(datadir)\" \
+ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -Werror \
+ $(libglib2_CFLAGS) \
+ $(libgtk_CFLAGS) \
+ $(libnautilusextension_CFLAGS)
+
+nautilus_extensiondir=$(NAUTILUS_EXTENSION_DIR)
+
+nautilus_extension_LTLIBRARIES=libnautilus-sbmanager.la
+
+libnautilus_sbmanager_la_SOURCES = \
+ nautilus-sbmanager.h \
+ nautilus-sbmanager.c \
+ nautilus-sbmgr.c
+
+libnautilus_sbmanager_la_LDFLAGS = -module -avoid-version
+libnautilus_sbmanager_la_LIBADD = $(libglib2_LIBS) $(libgtk_LIBS) $(libnautilusextension_LIBS)
diff --git a/nautilus/nautilus-sbmanager.c b/nautilus/nautilus-sbmanager.c
new file mode 100644
index 0000000..302d98e
--- /dev/null
+++ b/nautilus/nautilus-sbmanager.c
@@ -0,0 +1,180 @@
+/*
+ * nautilus-sbmanager.c
+ *
+ * Copyright (C) 2010 Nikias Bassen <nikias@gmx.li>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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 profile.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+#ifdef HAVE_CONFIG_H
+ #include <config.h> /* for GETTEXT_PACKAGE */
+#endif
+
+#include "nautilus-sbmanager.h"
+
+#include <libnautilus-extension/nautilus-menu-provider.h>
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h> /* for atoi */
+#include <string.h> /* for strcmp */
+#include <unistd.h> /* for chdir */
+#include <sys/stat.h>
+
+static void nautilus_sbmanager_instance_init (NautilusSBManager *cvs);
+static void nautilus_sbmanager_class_init (NautilusSBManagerClass *class);
+
+static GType sbmanager_type = 0;
+
+static void launch_sbmanager (NautilusMenuItem *item)
+{
+ GdkScreen *screen;
+ GError *error = NULL;
+ gchar *argvp[4] = {(char*)"sbmanager", (char*)"-u", NULL, NULL};
+ argvp[2] = g_object_get_data (G_OBJECT (item), "NautilusSBManager::uuid");
+
+ screen = g_object_get_data (G_OBJECT (item), "NautilusSBManager::screen");
+ gdk_spawn_on_screen(screen, NULL, argvp, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
+ if (error) {
+ g_error_free(error);
+ }
+}
+
+static void launch_sbmanager_callback (NautilusMenuItem *item, const char *uuid)
+{
+ launch_sbmanager (item);
+}
+
+static NautilusMenuItem *launch_sbmanager_menu_item_new (const char *uuid, GdkScreen *screen)
+{
+ NautilusMenuItem *ret = NULL;
+ char *action_name = g_strdup_printf("NautilusSBManager::launch_sbmanager");
+ const char *name = _("Manage _SpringBoard");
+ const char *tooltip = _("Launch SBManager to manage the SpringBoard of this device");
+
+ ret = nautilus_menu_item_new (action_name, name, tooltip, "phone-apple-iphone");
+ g_free (action_name);
+
+ g_object_set_data (G_OBJECT (ret),
+ "NautilusSBManager::screen",
+ screen);
+ g_object_set_data (G_OBJECT (ret),
+ "NautilusSBManager::uuid",
+ (gpointer)g_strdup(uuid));
+ g_signal_connect (ret, "activate",
+ G_CALLBACK (launch_sbmanager_callback),
+ NULL);
+
+ return ret;
+}
+
+GList *
+nautilus_launch_sbmanager_get_file_items (NautilusMenuProvider *provider,
+ GtkWidget *window,
+ GList *files)
+{
+ gchar *uri;
+ gchar *uri_scheme;
+ GList *items;
+ NautilusMenuItem *item;
+
+ if (g_list_length (files) != 1
+ || ((nautilus_file_info_get_file_type (files->data) != G_FILE_TYPE_SHORTCUT)
+ && (nautilus_file_info_get_file_type (files->data) != G_FILE_TYPE_MOUNTABLE))) {
+ return NULL;
+ }
+
+ items = NULL;
+ uri = nautilus_file_info_get_activation_uri (files->data);
+ uri_scheme = g_uri_parse_scheme (uri);
+ if ((strcmp(uri_scheme, "afc") == 0) && g_find_program_in_path("sbmanager")) {
+ gchar *uuid = g_strndup(uri + 6, 40);
+ item = launch_sbmanager_menu_item_new (uuid, gtk_widget_get_screen (window));
+ g_free(uuid);
+ items = g_list_append (items, item);
+ }
+ g_free(uri_scheme);
+ g_free (uri);
+
+ return items;
+}
+
+static void
+nautilus_launch_sbmanager_menu_provider_iface_init (NautilusMenuProviderIface *iface)
+{
+ iface->get_background_items = NULL;
+ iface->get_file_items = nautilus_launch_sbmanager_get_file_items;
+}
+
+static void
+nautilus_sbmanager_instance_init (NautilusSBManager *cvs)
+{
+}
+
+static void
+nautilus_sbmanager_class_init (NautilusSBManagerClass *class)
+{
+}
+
+static void
+nautilus_sbmanager_class_finalize (NautilusSBManagerClass *class)
+{
+}
+
+GType
+nautilus_sbmanager_get_type (void)
+{
+ return sbmanager_type;
+}
+
+void
+nautilus_sbmanager_register_type (GTypeModule *module)
+{
+ static const GTypeInfo info = {
+ sizeof (NautilusSBManagerClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) nautilus_sbmanager_class_init,
+ (GClassFinalizeFunc) nautilus_sbmanager_class_finalize,
+ NULL,
+ sizeof (NautilusSBManager),
+ 0,
+ (GInstanceInitFunc) nautilus_sbmanager_instance_init,
+ NULL
+ };
+
+ static const GInterfaceInfo menu_provider_iface_info = {
+ (GInterfaceInitFunc) nautilus_launch_sbmanager_menu_provider_iface_init,
+ NULL,
+ NULL
+ };
+
+ sbmanager_type = g_type_module_register_type (module,
+ G_TYPE_OBJECT,
+ "NautilusSBManager",
+ &info, 0);
+
+ g_type_module_add_interface (module,
+ sbmanager_type,
+ NAUTILUS_TYPE_MENU_PROVIDER,
+ &menu_provider_iface_info);
+}
diff --git a/nautilus/nautilus-sbmanager.h b/nautilus/nautilus-sbmanager.h
new file mode 100644
index 0000000..d3179f8
--- /dev/null
+++ b/nautilus/nautilus-sbmanager.h
@@ -0,0 +1,54 @@
+/*
+ * nautilus-sbmanager.h
+ *
+ * Copyright (C) 2010 Nikias Bassen <nikias@gmx.li>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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 profile.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+#ifndef NAUTILUS_SBMANAGER_H
+#define NAUTILUS_SBMANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Declarations for the open terminal extension object. This object will be
+ * instantiated by nautilus. It implements the GInterfaces
+ * exported by libnautilus. */
+
+
+#define NAUTILUS_TYPE_SBMANAGER (nautilus_sbmanager_get_type ())
+#define NAUTILUS_SBMANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_SBMANAGER, NautilusSBManager))
+#define NAUTILUS_IS_SBMANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_SBMANAGER))
+typedef struct _NautilusSBManager NautilusSBManager;
+typedef struct _NautilusSBManagerClass NautilusSBManagerClass;
+
+struct _NautilusSBManager {
+ GObject parent_slot;
+};
+
+struct _NautilusSBManagerClass {
+ GObjectClass parent_slot;
+};
+
+GType nautilus_sbmanager_get_type (void);
+void nautilus_sbmanager_register_type (GTypeModule *module);
+
+G_END_DECLS
+
+#endif
diff --git a/nautilus/nautilus-sbmgr.c b/nautilus/nautilus-sbmgr.c
new file mode 100644
index 0000000..7bff0d0
--- /dev/null
+++ b/nautilus/nautilus-sbmgr.c
@@ -0,0 +1,57 @@
+/*
+ * nautilus-sbmgr.c
+ *
+ * Copyright (C) 2010 Nikias Bassen <nikias@gmx.li>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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 profile.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include "nautilus-sbmanager.h"
+
+#include <libintl.h>
+
+static GType type_list[1];
+
+void nautilus_module_initialize (GTypeModule *module);
+void nautilus_module_shutdown (void);
+void nautilus_module_list_types (const GType **types, int *num_types);
+
+void nautilus_module_initialize (GTypeModule *module)
+{
+ g_print ("Initializing nautilus-sbmanager extension\n");
+
+ nautilus_sbmanager_register_type (module);
+ type_list[0] = NAUTILUS_TYPE_SBMANAGER;
+
+ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void nautilus_module_shutdown (void)
+{
+ g_print ("Shutting down nautilus-sbmanager extension\n");
+}
+
+void nautilus_module_list_types (const GType **types, int *num_types)
+{
+ *types = type_list;
+ *num_types = G_N_ELEMENTS (type_list);
+}