[Xfce4-commits] <exo:exo-helper-overhaul> Add a GIO module to handle known exo helper URIs.

Nick Schermer nick at xfce.org
Wed Aug 26 18:44:02 CEST 2009


Updating branch refs/heads/exo-helper-overhaul
         to 48e3c3f52d41cc4da1b5d85d93990e205f5b13a1 (commit)
       from 54edd5fd5a501db44084a29eccde2851a82302b9 (commit)

commit 48e3c3f52d41cc4da1b5d85d93990e205f5b13a1
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Aug 26 18:02:02 2009 +0200

    Add a GIO module to handle known exo helper URIs.

 Makefile.am                 |    1 +
 configure.in.in             |   17 ++++
 exo-gio-module/Makefile.am  |   42 ++++++++++
 exo-gio-module/exo-module.c |  181 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 241 insertions(+), 0 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index dc1b9f0..abc19cf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,6 +13,7 @@ SUBDIRS =								\
 	exo-csource							\
 	exo-support							\
 	exo-desktop-item-edit						\
+	exo-gio-module							\
 	exo-hal								\
 	exo-helper							\
 	exo-mount							\
diff --git a/configure.in.in b/configure.in.in
index 11545d9..14dc330 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -157,10 +157,25 @@ dnl *** Check for required packages ***
 dnl ***********************************
 XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.16.0])
+XDT_CHECK_PACKAGE([GIO_UNIX], [gio-unix-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.14.0])
 XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.2.2])
 
+dnl ****************************
+dnl *** GIO modules location ***
+dnl ****************************
+AC_ARG_WITH([gio-module-dir],
+            [AC_HELP_STRING([--with-gio-module-dir=PATH],
+                            [Specify where to install the exo gio module (default=autodetect)])],
+            [gio_module_dir="$withval"])
+if test "x$gio_module_dir" = "x"; then
+  GIOMODULEDIR="`$PKG_CONFIG gio-2.0 --variable giomoduledir`"
+else
+  GIOMODULEDIR="$gio_module_dir"
+fi
+AC_SUBST([GIOMODULEDIR])
+
 dnl **************************************
 dnl *** Check for libnotify (optional) ***
 dnl **************************************
@@ -427,6 +442,7 @@ exo/exo-1.pc
 exo/exo-config.h
 exo-csource/Makefile
 exo-desktop-item-edit/Makefile
+exo-gio-module/Makefile
 exo-hal/Makefile
 exo-hal/exo-hal-1.pc
 exo-helper/Makefile
@@ -458,6 +474,7 @@ echo "* HAL support:    yes"
 else
 echo "* HAL support:    no"
 fi
+echo "* GIO Module Dir: $GIOMODULEDIR"
 echo "* Debug Support:  $enable_debug"
 echo "* Python Support: $have_python"
 echo
diff --git a/exo-gio-module/Makefile.am b/exo-gio-module/Makefile.am
new file mode 100644
index 0000000..0e34f5f
--- /dev/null
+++ b/exo-gio-module/Makefile.am
@@ -0,0 +1,42 @@
+# $Id$
+
+INCLUDES = 								\
+	-I$(top_srcdir)							\
+	-DG_LOG_DOMAIN=\"exo-gio-module\"				\
+	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
+	-DLIBEXECDIR=\"$(libexecdir)\"					\
+	-DLIBEXO_VERSION_API=\"$(LIBEXO_VERSION_API)\"
+
+exomoduledir =								\
+	$(GIOMODULEDIR)
+
+exomodule_LTLIBRARIES =							\
+	libexo-module-1.la
+
+libexo_module_1_la_SOURCES =						\
+	exo-module.c
+
+libexo_module_1_la_CFLAGS =						\
+	$(GIO_CFLAGS)							\
+	$(GIO_UNIX_CFLAGS) \
+	$(GTK_CFLAGS)							\
+	$(LIBXFCE4UTIL_CFLAGS)
+
+libexo_module_1_la_LDFLAGS =						\
+	-export_dynamic							\
+	-avoid-version							\
+	-module								\
+	-no-undefined							\
+	-export-symbols-regex '^g_io_module_(load|unload)'
+
+libexo_module_1_la_DEPENDENCIES =					\
+	$(top_builddir)/exo/libexo-$(LIBEXO_VERSION_API).la
+
+libexo_module_1_la_LIBADD =						\
+	$(GIO_LIBS)							\
+	$(GIO_UNIX_LIBS) \
+	$(GTK_LIBS)							\
+	$(LIBXFCE4UTIL_LIBS)						\
+	$(top_builddir)/exo/libexo-$(LIBEXO_VERSION_API).la
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/exo-gio-module/exo-module.c b/exo-gio-module/exo-module.c
new file mode 100644
index 0000000..2b954ed
--- /dev/null
+++ b/exo-gio-module/exo-module.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2009 Nick Schermer <nick at xfce.org>.
+ *
+ * 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 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., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <exo/exo.h>
+#include <gio/gio.h>
+#include <gio/gdesktopappinfo.h>
+
+#define EXO_HELPER_LAUNCH LIBEXECDIR "/exo-helper-" LIBEXO_VERSION_API " --launch "
+
+
+
+
+#define EXO_TYPE_GIO_MODULE        (exo_gio_module_get_type ())
+#define EXO_GIO_MODULE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_GIO_MODULE, ExoGioModule))
+#define EXO_GIO_MODULE_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_GIO_MODULE, ExoGioModuleClass))
+#define EXO_IS_GIO_MODULE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_GIO_MODULE))
+#define EXO_IS_GIO_MODULE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_GIO_MODULE))
+
+
+
+GType            exo_gio_module_get_type                   (void);
+static void      exo_gio_module_app_info_lookup_iface_init (GDesktopAppInfoLookupIface *iface);
+static GAppInfo *exo_gio_module_get_default_for_uri_scheme (GDesktopAppInfoLookup      *lookup,
+                                                            const gchar                *uri_scheme);
+
+
+
+
+typedef struct _ExoGioModuleClass ExoGioModuleClass;
+typedef struct _ExoGioModule      ExoGioModule;
+typedef struct _KnownSchemes      KnownSchemes;
+
+struct _ExoGioModuleClass
+{
+  GObjectClass __parent__;
+};
+
+struct _ExoGioModule
+{
+  GObject __parent__;
+};
+
+struct _KnownSchemes
+{
+  const gchar *pattern;
+  const gchar *category;
+};
+
+static KnownSchemes known_schemes[] =
+{
+  { "^(https?|ftps)$", "WebBrowser" },
+  { "^mailto$",        "MailReader" },
+  { "^(file|trash)$",  "FileManager" }
+};
+
+
+
+#define _G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) \
+{ \
+  const GInterfaceInfo g_implement_interface_info = { \
+    (GInterfaceInitFunc) iface_init, NULL, NULL \
+  }; \
+  g_type_module_add_interface (type_module, g_define_type_id, \
+                               TYPE_IFACE, &g_implement_interface_info); \
+}
+
+
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (ExoGioModule, exo_gio_module, G_TYPE_OBJECT, 0,
+    _G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_DESKTOP_APP_INFO_LOOKUP,
+                                    exo_gio_module_app_info_lookup_iface_init))
+
+
+
+static void
+exo_gio_module_class_init (ExoGioModuleClass *klass)
+{
+}
+
+
+
+static void
+exo_gio_module_init (ExoGioModule *module)
+{
+}
+
+
+
+static void
+exo_gio_module_class_finalize (ExoGioModuleClass *klass)
+{
+}
+
+
+
+static void
+exo_gio_module_app_info_lookup_iface_init (GDesktopAppInfoLookupIface *iface)
+{
+  iface->get_default_for_uri_scheme = exo_gio_module_get_default_for_uri_scheme;
+}
+
+
+
+static GAppInfo *
+exo_gio_module_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup,
+                                           const gchar           *uri_scheme)
+{
+  GAppInfo *info = NULL;
+  GError   *error = NULL;
+  gchar    *command;
+  gboolean  found;
+  guint     i;
+
+  /* do nothing when there is no scheme defined */
+  if (G_UNLIKELY (uri_scheme == NULL))
+    return NULL;
+
+  for (i = 0, found = FALSE; !found && i < G_N_ELEMENTS (known_schemes); i++)
+    {
+      /* see if the scheme matches */
+      found = g_regex_match_simple (known_schemes[i].pattern, uri_scheme, G_REGEX_CASELESS, 0);
+      if (found)
+        {
+          /* use the exo-helper directly here to avoid possible roundtrips with exo-open */
+          command = g_strconcat (EXO_HELPER_LAUNCH, known_schemes[i].category, NULL);
+          info = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_SUPPORTS_URIS, &error);
+          if (G_UNLIKELY (info == NULL))
+            {
+              /* show error */
+              g_critical ("Failed to create GAppInfo from \"%s\" for URI-scheme \"%s\": %s.",
+                          command, uri_scheme, error->message);
+              g_error_free (error);
+            }
+
+          /* cleanup */
+          g_free (command);
+        }
+    }
+
+  /* print debug message if scheme is not recognized by exo */
+  if (!found)
+    g_debug ("Unknown URI-scheme \"%s\".", uri_scheme);
+
+  return info;
+}
+
+
+
+G_MODULE_EXPORT void
+g_io_module_load (GIOModule *module)
+{
+  exo_gio_module_register_type (G_TYPE_MODULE (module));
+  g_io_extension_point_implement (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME,
+                                  EXO_TYPE_GIO_MODULE, "ExoGioModule", 10);
+}
+
+
+
+G_MODULE_EXPORT void
+g_io_module_unload (GIOModule   *module)
+{
+}



More information about the Xfce4-commits mailing list