[Xfce4-commits] <exo:exo-helper-overhaul> Remove exo-url functions and move dialog hook to gtk extensions.
Nick Schermer
nick at xfce.org
Wed Aug 26 18:44:06 CEST 2009
Updating branch refs/heads/exo-helper-overhaul
to e09d4bcc06dcd32a135b98b2ddca98e5d2e4e079 (commit)
from c07a72487229b8ab3b75326dd1a29211b9455914 (commit)
commit e09d4bcc06dcd32a135b98b2ddca98e5d2e4e079
Author: Nick Schermer <nick at xfce.org>
Date: Wed Aug 26 18:37:03 2009 +0200
Remove exo-url functions and move dialog hook to gtk extensions.
exo/Makefile.am | 2 -
exo/exo-execute.c | 2 +-
exo/exo-gtk-extensions.c | 89 ++++++++++
exo/exo-gtk-extensions.h | 4 +
exo/exo-url.c | 408 ----------------------------------------------
exo/exo-url.h | 62 -------
exo/exo.h | 1 -
exo/exo.symbols | 10 +-
8 files changed, 95 insertions(+), 483 deletions(-)
diff --git a/exo/Makefile.am b/exo/Makefile.am
index 187788d..a823edb 100644
--- a/exo/Makefile.am
+++ b/exo/Makefile.am
@@ -31,7 +31,6 @@ libexo_headers = \
exo-toolbars-model.h \
exo-toolbars-view.h \
exo-tree-view.h \
- exo-url.h \
exo-utils.h \
exo-wrap-table.h \
exo-xsession-client.h
@@ -89,7 +88,6 @@ libexo_1_la_SOURCES = \
exo-toolbars-private.h \
exo-toolbars-view.c \
exo-tree-view.c \
- exo-url.c \
exo-utils.c \
exo-wrap-table.c \
exo-xsession-client.c
diff --git a/exo/exo-execute.c b/exo/exo-execute.c
index 7a0b85c..7965982 100644
--- a/exo/exo-execute.c
+++ b/exo/exo-execute.c
@@ -106,7 +106,7 @@ exo_execute_preferred_application_on_screen (const gchar *category,
GError **error)
{
gchar *argv[5];
- gint argc = 0;
+ gint argc = 0;
g_return_val_if_fail (category != NULL, FALSE);
g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
diff --git a/exo/exo-gtk-extensions.c b/exo/exo-gtk-extensions.c
index 805fc40..baf7e6b 100644
--- a/exo/exo-gtk-extensions.c
+++ b/exo/exo-gtk-extensions.c
@@ -24,6 +24,10 @@
#include <config.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
#include <exo/exo-gtk-extensions.h>
#include <exo/exo-private.h>
#include <exo/exo-thumbnail-preview.h>
@@ -131,5 +135,90 @@ exo_gtk_file_chooser_add_thumbnail_preview (GtkFileChooser *chooser)
+/**
+ * exo_gtk_url_about_dialog_hook:
+ * @about_dialog : the #GtkAboutDialog in which the user activated a link.
+ * @link : the link, mail or web address, to open.
+ * @user_data : user data that was passed when the function was
+ * registered with gtk_about_dialog_set_email_hook()
+ * or gtk_about_dialog_set_url_hook(). This is currently
+ * unused within the context of this function, so you
+ * can safely pass %NULL when registering this hook
+ * with #GtkAboutDialog.
+ *
+ * This is a convenience function, which can be registered with #GtkAboutDialog,
+ * to open links clicked by the user in #GtkAboutDialog<!---->s.
+ *
+ * All you need to do is to register this hook with gtk_about_dialog_set_url_hook()
+ * and gtk_about_dialog_set_email_hook(). This can be done prior to calling
+ * gtk_show_about_dialog(), for example:
+ *
+ * <informalexample><programlisting>
+ * static void show_about_dialog (void)
+ * {
+ * gtk_about_dialog_set_email_hook (exo_gtk_url_about_dialog_hook, NULL, NULL);
+ * gtk_about_dialog_set_url_hook (exo_gtk_url_about_dialog_hook, NULL, NULL);
+ * gtk_show_about_dialog (.....);
+ * }
+ * </programlisting></informalexample>
+ *
+ * This function is not needed when you use Gtk 2.18 or later, because from
+ * that version this is implemented by default.
+ *
+ * Since: 0.5.0
+ **/
+void
+exo_gtk_url_about_dialog_hook (GtkAboutDialog *about_dialog,
+ const gchar *link,
+ gpointer user_data)
+{
+ GtkWidget *message;
+ GdkScreen *screen;
+ GError *error = NULL;
+ gchar *uri, *escaped;
+
+ g_return_if_fail (GTK_IS_ABOUT_DIALOG (about_dialog));
+ g_return_if_fail (link != NULL);
+
+ /* simple check if this is an email address */
+ if (!g_str_has_prefix (link, "mailto:") && strchr (link, '@') != NULL)
+ {
+ escaped = g_uri_escape_string (link, NULL, FALSE);
+ uri = g_strdup_printf ("mailto:%s", escaped);
+ g_free (escaped);
+ }
+ else
+ {
+ uri = g_strdup (link);
+ }
+
+ /* determine the screen from the about dialog */
+ screen = gtk_widget_get_screen (GTK_WIDGET (about_dialog));
+
+ /* try to open the url on the given screen */
+ if (!gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error))
+ {
+ /* make sure to initialize i18n support first,
+ * so we'll see a translated message.
+ */
+ _exo_i18n_init ();
+
+ /* display an error message to tell the user that we were unable to open the link */
+ message = gtk_message_dialog_new (GTK_WINDOW (about_dialog),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ _("Failed to open \"%s\"."), uri);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", error->message);
+ gtk_dialog_run (GTK_DIALOG (message));
+ gtk_widget_destroy (message);
+ g_error_free (error);
+ }
+
+ /* cleanup */
+ g_free (uri);
+}
+
+
+
#define __EXO_GTK_EXTENSIONS_C__
#include <exo/exo-aliasdef.c>
diff --git a/exo/exo-gtk-extensions.h b/exo/exo-gtk-extensions.h
index 8cae715..4a2e6f2 100644
--- a/exo/exo-gtk-extensions.h
+++ b/exo/exo-gtk-extensions.h
@@ -35,6 +35,10 @@ void exo_gtk_object_destroy_later (GtkObject *object);
void exo_gtk_file_chooser_add_thumbnail_preview (GtkFileChooser *chooser);
+void exo_gtk_url_about_dialog_hook (GtkAboutDialog *about,
+ const gchar *link,
+ gpointer data);
+
G_END_DECLS
#endif /* !__EXO_GTK_EXTENSIONS_H__ */
diff --git a/exo/exo-url.c b/exo/exo-url.c
deleted file mode 100644
index 0ee56b4..0000000
--- a/exo/exo-url.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/* $Id$ */
-/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; 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
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_FNMATCH_H
-#include <fnmatch.h>
-#endif
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#ifdef HAVE_REGEX_H
-#include <regex.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-/* define FNM_CASEFOLD for systems that don't have it */
-#ifndef FNM_CASEFOLD
-#define FNM_CASEFOLD 0
-#endif
-
-#include <exo/exo-execute.h>
-#include <exo/exo-private.h>
-#include <exo/exo-url.h>
-#include <exo/exo-alias.h>
-
-
-
-/* regular expressions for exo_url_show_on_screen() */
-#define USERCHARS "-A-Za-z0-9"
-#define PASSCHARS "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
-#define HOSTCHARS "-A-Za-z0-9"
-#define USER "[" USERCHARS "]+(:["PASSCHARS "]+)?"
-#define MATCH_BROWSER "^(([^:/?#]+)://)?([^/?#])([^?#]*)(\\?([^#]*))?(#(.*))?"
-#if !defined(__GLIBC__)
-#define MATCH_MAILER "^[a-z0-9][a-z0-9_.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$"
-#else
-#define MATCH_MAILER "^\\<[a-z0-9][a-z0-9_.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+\\>$"
-#endif
-
-
-
-/**
- * exo_url_error_quark:
- *
- * Returns the #GError domain used for #ExoUrlError<!---->s
- * returned from exo_url_show() and exo_url_show_on_screen().
- *
- * Return value: the #GError domain used for #ExoUrlError<!---->s.
- *
- * Since: 0.3.1.3
- **/
-GQuark
-exo_url_error_quark (void)
-{
- static GQuark quark = 0;
-
- if (G_UNLIKELY (quark == 0))
- quark = g_quark_from_static_string ("exo-url-error-quark");
-
- return quark;
-}
-
-
-
-/**
- * exo_url_show:
- * @url : the URL that should be shown.
- * @envp : child environment for the url handler or
- * %NULL to inherit parent's environment.
- * @error : return location for errors or %NULL.
- *
- * Convenience wrapper to exo_url_show_on_screen(), which
- * shows the @url on the default #GdkScreen.
- *
- * Return value: %TRUE on success, %FALSE on error.
- *
- * Since: 0.3.1.3
- **/
-gboolean
-exo_url_show (const gchar *url,
- gchar **envp,
- GError **error)
-{
- g_return_val_if_fail (url != NULL, FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- return exo_url_show_on_screen (url, envp, gdk_screen_get_default (), error);
-}
-
-
-
-static gboolean
-_exo_url_match (const gchar *pattern, const gchar *url)
-{
-#ifdef HAVE_REGEXEC
- regex_t regex;
- gint result = -1;
-
- if (regcomp (®ex, pattern, REG_EXTENDED) == 0)
- {
- result = regexec (®ex, url, 0, NULL, 0);
- regfree (®ex);
- }
-
- return (result == 0);
-#else
-#error "No POSIX regular expressions available, please report this to thunar-dev at xfce.org"
-#endif
-}
-
-
-
-static gchar*
-_exo_url_to_local_path (const gchar *url)
-{
- gchar *current_dir;
- gchar *path = NULL;
-
- if (g_str_has_prefix (url, "file://"))
- {
- /* transform a file:-URI to a local path */
- path = g_filename_from_uri (url, NULL, NULL);
- }
- else
- {
- /* check if url is an absolute path */
- if (g_path_is_absolute (url))
- {
- /* well, we got our path then */
- path = g_strdup (url);
- }
- else
- {
- /* treat it like a relative path */
- current_dir = g_get_current_dir ();
- path = g_build_filename (current_dir, url, NULL);
- g_free (current_dir);
-
- /* verify that a file of the given name exists */
- if (!g_file_test (path, G_FILE_TEST_EXISTS))
- {
- /* no local path then! */
- g_free (path);
- path = NULL;
- }
- }
- }
-
- return path;
-}
-
-
-
-/**
- * exo_url_show_on_screen:
- * @url : the URL that should be shown.
- * @envp : child environment for the url handler or
- * %NULL to inherit parent's environment.
- * @screen : the #GdkScreen on which to open the
- * URL handler for @url.
- * @error : return location for errors or %NULL.
- *
- * Tries to find a suitable handler for @url in the list of
- * preferred application categories and runs that handler
- * with @url on @screen.
- *
- * Return value: %TRUE on success, %FALSE on error.
- *
- * Since: 0.3.1.3
- **/
-gboolean
-exo_url_show_on_screen (const gchar *url,
- gchar **envp,
- GdkScreen *screen,
- GError **error)
-{
- const gchar *category = NULL;
- gboolean result = FALSE;
- gchar *display_name;
- gchar *local_path;
- gchar *command;
- gchar *uri;
- gchar *quoted_url;
- gint status;
-
- g_return_val_if_fail (url != NULL, FALSE);
- g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- /* be sure to initialize i18n support first,
- * so we get a translated error message.
- */
- _exo_i18n_init ();
-
- /* try to conver the URL into a local path */
- local_path = _exo_url_to_local_path (url);
-
- /* now, let's see what we have here */
- if (local_path != NULL)
- {
- /* determine the display name for the screen */
- display_name = gdk_screen_make_display_name (screen);
-
- /* check if we have a local HTML file here */
- if (fnmatch ("*.xhtml", local_path, FNM_CASEFOLD) == 0
- || fnmatch ("*.htm", local_path, FNM_CASEFOLD) == 0
- || fnmatch ("*.html", local_path, FNM_CASEFOLD) == 0)
- {
- /* transform the path to a file:-URI */
- uri = g_filename_to_uri (local_path, NULL, error);
- if (G_LIKELY (uri != NULL))
- {
- /* try to execute the file:-URI in a web browser */
- result = exo_execute_preferred_application_on_screen ("WebBrowser", uri, NULL, envp, screen, error);
- g_free (uri);
- }
- }
- else
- {
- /* make a shell quoted url to pass to other applications */
- quoted_url = g_shell_quote(local_path);
-
- /* but since we have a local file here, maybe the org.xfce.FileManager can open it? */
- command = g_strdup_printf ("dbus-send --print-reply --dest=org.xfce.FileManager "
- "/org/xfce/FileManager org.xfce.FileManager.Launch "
- "string:%s string:\"%s\"", quoted_url, display_name);
- result = (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0);
- g_free (command);
-
- /* check if it's handled now */
- if (G_UNLIKELY (!result))
- {
- /* but hey, we know that Thunar can open local files, so give it a go */
- command = g_strdup_printf ("Thunar --display=\"%s\" %s", display_name, quoted_url);
- result = g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
-
- /* check if it's handled now */
- if (G_UNLIKELY (!result))
- {
- /* gnome-open is also worth a try, since it uses the standard applications database */
- command = g_strdup_printf ("env DISPLAY=\"%s\" gnome-open %s", display_name, quoted_url);
- result = (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0);
- g_free (command);
- }
-
- /* check if it's handled now */
- if (G_UNLIKELY (!result))
- {
- /* ok, we tried everything, but no luck, tell the user that we failed */
- g_set_error (error, EXO_URL_ERROR, EXO_URL_ERROR_NOT_SUPPORTED,
- _("Unable to open \"%s\""), local_path);
- }
-
- /* release the quoted_url as it is no longer needed */
- g_free(quoted_url);
- }
-
- /* release the local path and the display name */
- g_free (display_name);
- g_free (local_path);
-
- /* and we're done */
- return result;
- }
- else if (strncmp (url, "mailto:", 7) == 0 || _exo_url_match (MATCH_MAILER, url))
- {
- /* ignore mailto: prefix, as not all mailers can handle it */
- if (strncmp (url, "mailto:", 7) == 0)
- url += 7;
- category = "MailReader";
- }
- else if (_exo_url_match (MATCH_BROWSER, url))
- {
- category = "WebBrowser";
- }
- else
- {
- /* determine the display name for the screen */
- display_name = gdk_screen_make_display_name (screen);
-
- /* make a shell quoted url to pass to other applications */
- quoted_url = g_shell_quote(url);
-
- /* not a local path, and not something that we support, but maybe gnome-open knows what to do */
- command = g_strdup_printf ("env DISPLAY=\"%s\" gnome-open %s", display_name, quoted_url);
- result = (g_spawn_command_line_sync (command, NULL, NULL, &status, NULL) && status == 0);
- g_free (command);
-
- /* release the quoted_url as it is no longer needed */
- g_free(quoted_url);
-
- /* check if gnome-open handled the URL */
- if (G_UNLIKELY (!result))
- {
- /* no options left, we have to tell the user that we failed */
- g_set_error (error, EXO_URL_ERROR, EXO_URL_ERROR_NOT_SUPPORTED,
- _("The URL \"%s\" is not supported"), url);
- }
-
- /* release the display name */
- g_free (display_name);
-
- return result;
- }
-
- /* oki doki then, let's open it */
- return exo_execute_preferred_application_on_screen (category, url, NULL, envp, screen, error);
-}
-
-
-
-/**
- * exo_url_about_dialog_hook:
- * @about_dialog : the #GtkAboutDialog in which the user activated a link.
- * @link : the link, mail or web address, to open.
- * @user_data : user data that was passed when the function was
- * registered with gtk_about_dialog_set_email_hook()
- * or gtk_about_dialog_set_url_hook(). This is currently
- * unused within the context of this function, so you
- * can safely pass %NULL when registering this hook
- * with #GtkAboutDialog.
- *
- * This is a convenience function, which can be registered with #GtkAboutDialog,
- * to have the <link linkend="exo-Opening-URLs">exo-url</link> module open links
- * clicked by the user in #GtkAboutDialog<!---->s.
- *
- * All you need to do is to register this hook with gtk_about_dialog_set_url_hook()
- * and gtk_about_dialog_set_email_hook(). This can be done prior to calling
- * gtk_show_about_dialog(), for example:
- *
- * <informalexample><programlisting>
- * static void show_about_dialog (void)
- * {
- * gtk_about_dialog_set_email_hook (exo_url_about_dialog_hook, NULL, NULL);
- * gtk_about_dialog_set_url_hook (exo_url_about_dialog_hook, NULL, NULL);
- * gtk_show_about_dialog (.....);
- * }
- * </programlisting></informalexample>
- *
- * Since: 0.3.1.3
- **/
-void
-exo_url_about_dialog_hook (GtkAboutDialog *about_dialog,
- const gchar *link,
- gpointer user_data)
-{
- GtkWidget *message;
- GdkScreen *screen;
- GError *error = NULL;
-
- g_return_if_fail (GTK_IS_ABOUT_DIALOG (about_dialog));
- g_return_if_fail (link != NULL);
-
- /* determine the screen from the about dialog */
- screen = gtk_widget_get_screen (GTK_WIDGET (about_dialog));
-
- /* try to open the url on the given screen */
- if (!exo_url_show_on_screen (link, NULL, screen, &error))
- {
- /* make sure to initialize i18n support first,
- * so we'll see a translated message.
- */
- _exo_i18n_init ();
-
- /* display an error message to tell the user that we were unable to open the link */
- message = gtk_message_dialog_new (GTK_WINDOW (about_dialog),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- _("Failed to open \"%s\"."), link);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", error->message);
- gtk_dialog_run (GTK_DIALOG (message));
- gtk_widget_destroy (message);
- g_error_free (error);
- }
-}
-
-
-
-#define __EXO_URL_C__
-#include <exo/exo-aliasdef.c>
diff --git a/exo/exo-url.h b/exo/exo-url.h
deleted file mode 100644
index 3abc709..0000000
--- a/exo/exo-url.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $Id$ */
-/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#if !defined (EXO_INSIDE_EXO_H) && !defined (EXO_COMPILATION)
-#error "Only <exo/exo.h> can be included directly, this file may disappear or change contents."
-#endif
-
-#ifndef __EXO_URL_H__
-#define __EXO_URL_H__
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-#define EXO_URL_ERROR (exo_url_error_quark ())
-GQuark exo_url_error_quark (void) G_GNUC_CONST;
-
-/**
- * ExoUrlError:
- * @EXO_URL_ERROR_NOT_SUPPORTED : a given URL is not supported.
- *
- * The errors that can be returned due to bad parameters being
- * passed to exo_url_show() or exo_url_show_on_screen().
- **/
-typedef enum /*< skip >*/
-{
- EXO_URL_ERROR_NOT_SUPPORTED,
-} ExoUrlError;
-
-gboolean exo_url_show (const gchar *url,
- gchar **envp,
- GError **error);
-
-gboolean exo_url_show_on_screen (const gchar *url,
- gchar **envp,
- GdkScreen *screen,
- GError **error);
-
-void exo_url_about_dialog_hook (GtkAboutDialog *about_dialog,
- const gchar *link,
- gpointer user_data);
-
-G_END_DECLS
-
-#endif /* !__EXO_URL_H__ */
diff --git a/exo/exo.h b/exo/exo.h
index de05b69..0084f08 100644
--- a/exo/exo.h
+++ b/exo/exo.h
@@ -56,7 +56,6 @@
#include <exo/exo-toolbars-model.h>
#include <exo/exo-toolbars-view.h>
#include <exo/exo-tree-view.h>
-#include <exo/exo-url.h>
#include <exo/exo-utils.h>
#include <exo/exo-wrap-table.h>
#include <exo/exo-xsession-client.h>
diff --git a/exo/exo.symbols b/exo/exo.symbols
index 210b72a..baeb58e 100644
--- a/exo/exo.symbols
+++ b/exo/exo.symbols
@@ -120,6 +120,7 @@ exo_g_value_transform_negate
#if IN_SOURCE(__EXO_GTK_EXTENSIONS_C__)
exo_gtk_object_destroy_later
exo_gtk_file_chooser_add_thumbnail_preview
+exo_gtk_url_about_dialog_hook
#endif
#endif
@@ -359,15 +360,6 @@ exo_tree_view_set_single_click_timeout
#endif
#endif
-#if IN_HEADER(__EXO_URL_H__)
-#if IN_SOURCE(__EXO_URL_C__)
-exo_url_error_quark G_GNUC_CONST
-exo_url_show
-exo_url_show_on_screen
-exo_url_about_dialog_hook
-#endif
-#endif
-
#if IN_HEADER(__EXO_WRAP_TABLE_H__)
#if IN_SOURCE(__EXO_WRAP_TABLE_C__)
exo_wrap_table_get_type G_GNUC_CONST
More information about the Xfce4-commits
mailing list