summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBenedikt Meurer <benny@xfce.org>2005-11-21 20:58:54 +0000
committerBenedikt Meurer <benny@xfce.org>2005-11-21 20:58:54 +0000
commitf6eae23de9952d963265e8b58351bcebae610937 (patch)
tree98447a2cda940169218b56c4c4f4103b2e349e6c /examples
parent5dcf7a66f0735f4b006edefea0fc3dc95d1d0e77 (diff)
downloadthunar-f6eae23de9952d963265e8b58351bcebae610937.tar.gz
2005-11-21 Benedikt Meurer <benny@xfce.org>
* thunarx/thunarx-provider-plugin.{c,h}, thunarx/Makefile.am, thunarx/thunarx.h, thunarx/thunarx.symbols: Add ThunarxProviderPlugin interface, which abstracts from the details of the dynamic type registration, and is accessible to the extensions. * thunarx/thunarx-provider-module.{c,h}, thunarx/Makefile.am: Add implementation for the ThunarxProviderPlugin interface, based on GTypeModule, which is used on the file manager's side to manage the type plugins. * thunarx/thunarx-provider-factory.{c,h}, thunarx/Makefile.am, thunarx/thunarx.h, thunarx/thunarx.symbols: Add ThunarxProviderFactory based on the ThunarExtensionManager as public interface to the provider plugin mechanism. This may also be used by other applications in the future. * thunarx/thunarx.h: Provide convenience macros ala G_DEFINE_TYPE() to ease type registration for plugin writers. * examples/, configure.in.in: Update the "Open Terminal Here" example. * docs/reference/thunarx/: Update the thunarx reference manual to include the new classes and interfaces. * thunar/thunar-extension-manager.{c,h}: Drop the old extension manager class in favour of the new provider factory class. * thunar/thunar-properties-dialog.c, thunar/thunar-standard-view.c: Use ThunarxProviderFactory to load the providers from the installed extensions. * po/POTFILES.in: Update with new file list. * thunar/thunar-file.{c,h}: Implement thunar_file_list_copy() using thunarx_file_info_list_copy() and thunar_file_list_free() using thunarx_file_info_list_free(). * docs/reference/thunar-vfs/thunar-vfs-overrides.txt, docs/reference/thunarx/thunarx-overrides.txt: Fix build error with older gtk-doc versions. (Old svn revision: 18919)
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/open-terminal-here/open-terminal-here.c244
-rw-r--r--examples/tex-open-terminal/Makefile.am (renamed from examples/open-terminal-here/Makefile.am)19
-rw-r--r--examples/tex-open-terminal/README (renamed from examples/open-terminal-here/README)0
-rw-r--r--examples/tex-open-terminal/tex-open-terminal-plugin.c72
-rw-r--r--examples/tex-open-terminal/tex-open-terminal.c180
-rw-r--r--examples/tex-open-terminal/tex-open-terminal.h43
7 files changed, 307 insertions, 253 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0811c7e9..38697d19 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,6 +1,6 @@
# $Id$
SUBDIRS = \
- open-terminal-here
+ tex-open-terminal
# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/examples/open-terminal-here/open-terminal-here.c b/examples/open-terminal-here/open-terminal-here.c
deleted file mode 100644
index 55b4198e..00000000
--- a/examples/open-terminal-here/open-terminal-here.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/* $Id$ */
-/*-
- * Copyright (c) 2005 Benedikt Meurer <benny@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_MEMORY_H
-#include <memory.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <thunarx/thunarx.h>
-
-
-
-/* make sure to export the required public functions */
-#ifdef HAVE_GNUC_VISIBILITY
-extern void thunar_extension_initialize (GTypeModule *module) __attribute__((visibility("default")));
-extern void thunar_extension_shutdown (void) __attribute__((visibility("default")));
-extern void thunar_extension_list_types (const GType **types, gint *n_types) __attribute__((visibility("default")));
-#else
-extern G_MODULE_EXPORT void thunar_extension_initialize (GTypeModule *module);
-extern G_MODULE_EXPORT void thunar_extension_shutdown (void);
-extern G_MODULE_EXPORT void thunar_extension_list_types (const GType **types, gint *n_types);
-#endif
-
-
-
-static GType type_list[1];
-
-
-
-typedef struct _OpenTerminalHereClass OpenTerminalHereClass;
-typedef struct _OpenTerminalHere OpenTerminalHere;
-
-
-
-static void open_terminal_here_register_type (GTypeModule *module);
-static void open_terminal_here_menu_provider_init (ThunarxMenuProviderIface *iface);
-static GList *open_terminal_here_get_file_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- GList *files);
-static GList *open_terminal_here_get_folder_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder);
-static void open_terminal_here_activated (GtkAction *action,
- GtkWidget *window);
-
-
-
-struct _OpenTerminalHereClass
-{
- GObjectClass __parent__;
-};
-
-struct _OpenTerminalHere
-{
- GObject __parent__;
-};
-
-
-
-static void
-open_terminal_here_register_type (GTypeModule *module)
-{
- static const GTypeInfo info =
- {
- sizeof (OpenTerminalHereClass),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- sizeof (OpenTerminalHere),
- 0,
- NULL,
- NULL,
- };
-
- static const GInterfaceInfo menu_provider_info =
- {
- (GInterfaceInitFunc) open_terminal_here_menu_provider_init,
- NULL,
- NULL,
- };
-
- type_list[0] = g_type_module_register_type (module, G_TYPE_OBJECT, "OpenTerminalHere", &info, 0);
- g_type_module_add_interface (module, type_list[0], THUNARX_TYPE_MENU_PROVIDER, &menu_provider_info);
-}
-
-
-
-static void
-open_terminal_here_menu_provider_init (ThunarxMenuProviderIface *iface)
-{
- iface->get_file_actions = open_terminal_here_get_file_actions;
- iface->get_folder_actions = open_terminal_here_get_folder_actions;
-}
-
-
-
-static GList*
-open_terminal_here_get_file_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- GList *files)
-{
- /* check if we have a directory here */
- if (G_LIKELY (files != NULL && files->next == NULL && thunarx_file_info_is_directory (files->data)))
- return open_terminal_here_get_folder_actions (provider, window, files->data);
-
- return NULL;
-}
-
-
-
-static GList*
-open_terminal_here_get_folder_actions (ThunarxMenuProvider *provider,
- GtkWidget *window,
- ThunarxFileInfo *folder)
-{
- GtkAction *action = NULL;
- gchar *scheme;
- gchar *path;
- gchar *uri;
-
- /* determine the uri scheme of the folder and check if we support it */
- scheme = thunarx_file_info_get_uri_scheme (folder);
- if (G_LIKELY (strcmp (scheme, "file") == 0))
- {
- /* determine the local path to the folder */
- uri = thunarx_file_info_get_uri (folder);
- path = g_filename_from_uri (uri, NULL, NULL);
- g_free (uri);
-
- /* check if we have a valid path here */
- if (G_LIKELY (path != NULL))
- {
- action = gtk_action_new ("OpenTerminalHere::open-terminal-here", "Open Terminal Here", "Open Terminal in this folder", NULL);
- g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (open_terminal_here_activated), window);
- g_object_set_data_full (G_OBJECT (action), "open-terminal-here-path", path, g_free);
- }
- }
- g_free (scheme);
-
- return (action != NULL) ? g_list_prepend (NULL, action) : NULL;
-}
-
-
-
-static void
-open_terminal_here_activated (GtkAction *action,
- GtkWidget *window)
-{
- const gchar *path;
- GtkWidget *dialog;
- GError *error = NULL;
- gchar *command;
-
- /* determine the folder path */
- path = g_object_get_data (G_OBJECT (action), "open-terminal-here-path");
- if (G_UNLIKELY (path == NULL))
- return;
-
- /* build up the command line for the terminal */
- command = g_strdup_printf ("Terminal --working-directory \"%s\"", path);
-
- /* try to run the terminal command */
- if (!gdk_spawn_command_line_on_screen (gtk_widget_get_screen (window), command, &error))
- {
- /* display an error dialog */
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "Failed to open terminal in folder %s.",
- path);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_error_free (error);
- }
-
- /* cleanup */
- g_free (command);
-}
-
-
-
-void
-thunar_extension_initialize (GTypeModule *module)
-{
- const gchar *mismatch;
-
- /* verify that the thunarx versions are compatible */
- mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
- if (G_UNLIKELY (mismatch != NULL))
- {
- g_warning ("Version mismatch: %s", mismatch);
- return;
- }
-
- g_message ("Initializing OpenTerminalHere extension");
-
- open_terminal_here_register_type (module);
-}
-
-
-
-void
-thunar_extension_shutdown (void)
-{
- g_message ("Shutting down OpenTerminalHere extension");
-}
-
-
-
-void
-thunar_extension_list_types (const GType **types,
- gint *n_types)
-{
- *types = type_list;
- *n_types = G_N_ELEMENTS (type_list);
-}
-
diff --git a/examples/open-terminal-here/Makefile.am b/examples/tex-open-terminal/Makefile.am
index fc50b8f1..01ab1b00 100644
--- a/examples/open-terminal-here/Makefile.am
+++ b/examples/tex-open-terminal/Makefile.am
@@ -3,28 +3,31 @@
INCLUDES = \
-I$(top_builddir) \
-I$(top_srcdir) \
- -DG_LOG_DOMAIN=\"OpenTerminalHere\" \
+ -I$(top_srcdir)/examples \
+ -DG_LOG_DOMAIN=\"TexOpenTerminal\" \
$(PLATFORM_CPPFLAGS)
extensionsdir = $(libdir)/thunarx-$(THUNAR_VERSION_API)
extensions_LTLIBRARIES = \
- open-terminal-here.la
+ tex-open-terminal.la
-open_terminal_here_la_SOURCES = \
- open-terminal-here.c
+tex_open_terminal_la_SOURCES = \
+ tex-open-terminal-plugin.c \
+ tex-open-terminal.c \
+ tex-open-terminal.h
-open_terminal_here_la_CFLAGS = \
+tex_open_terminal_la_CFLAGS = \
$(GTK_CFLAGS) \
$(PLATFORM_CFLAGS)
-open_terminal_here_la_DEPENDENCIES = \
+tex_open_terminal_la_DEPENDENCIES = \
$(top_builddir)/thunarx/libthunarx-$(THUNAR_VERSION_API).la
-open_terminal_here_la_LIBADD = \
+tex_open_terminal_la_LIBADD = \
$(top_builddir)/thunarx/libthunarx-$(THUNAR_VERSION_API).la \
$(GTK_LIBS)
-open_terminal_here_la_LDFLAGS = \
+tex_open_terminal_la_LDFLAGS = \
-avoid-version \
-export-dynamic \
-module \
diff --git a/examples/open-terminal-here/README b/examples/tex-open-terminal/README
index d56759f0..d56759f0 100644
--- a/examples/open-terminal-here/README
+++ b/examples/tex-open-terminal/README
diff --git a/examples/tex-open-terminal/tex-open-terminal-plugin.c b/examples/tex-open-terminal/tex-open-terminal-plugin.c
new file mode 100644
index 00000000..aa8525f9
--- /dev/null
+++ b/examples/tex-open-terminal/tex-open-terminal-plugin.c
@@ -0,0 +1,72 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005 Benedikt Meurer <benny@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
+
+#include <tex-open-terminal/tex-open-terminal.h>
+
+
+
+static GType type_list[1];
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_initialize (ThunarxProviderPlugin *plugin)
+{
+ const gchar *mismatch;
+
+ /* verify that the thunarx versions are compatible */
+ mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
+ if (G_UNLIKELY (mismatch != NULL))
+ {
+ g_warning ("Version mismatch: %s", mismatch);
+ return;
+ }
+
+ g_message ("Initializing TexOpenTerminal extension");
+
+ /* register the types provided by this plugin */
+ tex_open_terminal_register_type (plugin);
+
+ /* setup the plugin type list */
+ type_list[0] = TEX_TYPE_OPEN_TERMINAL;
+}
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_shutdown (void)
+{
+ g_message ("Shutting down TexOpenTerminal extension");
+}
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_list_types (const GType **types,
+ gint *n_types)
+{
+ *types = type_list;
+ *n_types = G_N_ELEMENTS (type_list);
+}
+
diff --git a/examples/tex-open-terminal/tex-open-terminal.c b/examples/tex-open-terminal/tex-open-terminal.c
new file mode 100644
index 00000000..950614b6
--- /dev/null
+++ b/examples/tex-open-terminal/tex-open-terminal.c
@@ -0,0 +1,180 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005 Benedikt Meurer <benny@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_MEMORY_H
+#include <memory.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <tex-open-terminal/tex-open-terminal.h>
+
+
+
+static void tex_open_terminal_class_init (TexOpenTerminalClass *klass);
+static void tex_open_terminal_menu_provider_init (ThunarxMenuProviderIface *iface);
+static void tex_open_terminal_init (TexOpenTerminal *open_terminal);
+static GList *tex_open_terminal_get_file_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ GList *files);
+static GList *tex_open_terminal_get_folder_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ ThunarxFileInfo *folder);
+static void tex_open_terminal_activated (GtkAction *action,
+ GtkWidget *window);
+
+
+
+struct _TexOpenTerminalClass
+{
+ GObjectClass __parent__;
+};
+
+struct _TexOpenTerminal
+{
+ GObject __parent__;
+};
+
+
+
+THUNARX_DEFINE_TYPE_WITH_CODE (TexOpenTerminal,
+ tex_open_terminal,
+ G_TYPE_OBJECT,
+ THUNARX_IMPLEMENT_INTERFACE (THUNARX_TYPE_MENU_PROVIDER,
+ tex_open_terminal_menu_provider_init));
+
+
+
+static void
+tex_open_terminal_class_init (TexOpenTerminalClass *klass)
+{
+ /* nothing to do here */
+}
+
+
+
+static void
+tex_open_terminal_init (TexOpenTerminal *open_terminal)
+{
+ /* nothing to do here */
+}
+
+
+
+static void
+tex_open_terminal_menu_provider_init (ThunarxMenuProviderIface *iface)
+{
+ iface->get_file_actions = tex_open_terminal_get_file_actions;
+ iface->get_folder_actions = tex_open_terminal_get_folder_actions;
+}
+
+
+
+static GList*
+tex_open_terminal_get_file_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ GList *files)
+{
+ /* check if we have a directory here */
+ if (G_LIKELY (files != NULL && files->next == NULL && thunarx_file_info_is_directory (files->data)))
+ return tex_open_terminal_get_folder_actions (provider, window, files->data);
+
+ return NULL;
+}
+
+
+
+static GList*
+tex_open_terminal_get_folder_actions (ThunarxMenuProvider *provider,
+ GtkWidget *window,
+ ThunarxFileInfo *folder)
+{
+ GtkAction *action = NULL;
+ gchar *scheme;
+ gchar *path;
+ gchar *uri;
+
+ /* determine the uri scheme of the folder and check if we support it */
+ scheme = thunarx_file_info_get_uri_scheme (folder);
+ if (G_LIKELY (strcmp (scheme, "file") == 0))
+ {
+ /* determine the local path to the folder */
+ uri = thunarx_file_info_get_uri (folder);
+ path = g_filename_from_uri (uri, NULL, NULL);
+ g_free (uri);
+
+ /* check if we have a valid path here */
+ if (G_LIKELY (path != NULL))
+ {
+ action = gtk_action_new ("TexOpenTerminal::open-terminal-here", "Open Terminal Here", "Open Terminal in this folder", NULL);
+ g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (tex_open_terminal_activated), window);
+ g_object_set_data_full (G_OBJECT (action), "open-terminal-here-path", path, g_free);
+ }
+ }
+ g_free (scheme);
+
+ return (action != NULL) ? g_list_prepend (NULL, action) : NULL;
+}
+
+
+
+static void
+tex_open_terminal_activated (GtkAction *action,
+ GtkWidget *window)
+{
+ const gchar *path;
+ GtkWidget *dialog;
+ GError *error = NULL;
+ gchar *command;
+
+ /* determine the folder path */
+ path = g_object_get_data (G_OBJECT (action), "open-terminal-here-path");
+ if (G_UNLIKELY (path == NULL))
+ return;
+
+ /* build up the command line for the terminal */
+ command = g_strdup_printf ("Terminal --working-directory \"%s\"", path);
+
+ /* try to run the terminal command */
+ if (!gdk_spawn_command_line_on_screen (gtk_widget_get_screen (window), command, &error))
+ {
+ /* display an error dialog */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Failed to open terminal in folder %s.",
+ path);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_error_free (error);
+ }
+
+ /* cleanup */
+ g_free (command);
+}
+
+
diff --git a/examples/tex-open-terminal/tex-open-terminal.h b/examples/tex-open-terminal/tex-open-terminal.h
new file mode 100644
index 00000000..0d630a35
--- /dev/null
+++ b/examples/tex-open-terminal/tex-open-terminal.h
@@ -0,0 +1,43 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005 Benedikt Meurer <benny@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.
+ */
+
+#ifndef __TEX_OPEN_TERMINAL_H__
+#define __TEX_OPEN_TERMINAL_H__
+
+#include <thunarx/thunarx.h>
+
+G_BEGIN_DECLS;
+
+typedef struct _TexOpenTerminalClass TexOpenTerminalClass;
+typedef struct _TexOpenTerminal TexOpenTerminal;
+
+#define TEX_TYPE_OPEN_TERMINAL (tex_open_terminal_get_type ())
+#define TEX_OPEN_TERMINAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEX_TYPE_OPEN_TERMINAL, TexOpenTerminal))
+#define TEX_OPEN_TERMINAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEX_TYPE_OPEN_TERMINAL, TexOpenTerminalClass))
+#define TEX_IS_OPEN_TERMINAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEX_TYPE_OPEN_TERMINAL))
+#define TEX_IS_OPEN_TERMINAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEX_TYPE_OPEN_TERMINAL))
+#define TEX_OPEN_TERMINAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEX_TYPE_OPEN_TERMINAL, TexOpenTerminalClass))
+
+GType tex_open_terminal_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
+void tex_open_terminal_register_type (ThunarxProviderPlugin *plugin) G_GNUC_INTERNAL;
+
+G_END_DECLS;
+
+#endif /* !__TEX_OPEN_TERMINAL_H__ */