[eog] Add new plugin hook for per-application plugins



commit cdfe77e18b7510e51546b869343f3feda4c541bf
Author: Felix Riemann <friemann gnome org>
Date:   Sun Aug 12 15:53:18 2012 +0200

    Add new plugin hook for per-application plugins
    
    These will be loaded on application initialization and disabled
    once the application is disposed.

 src/Makefile.am                   |    2 +
 src/eog-application-activatable.c |   85 +++++++++++++++++++++++++++++++++++++
 src/eog-application-activatable.h |   69 ++++++++++++++++++++++++++++++
 src/eog-application.c             |   33 ++++++++++++++
 src/eog-application.h             |    4 ++
 5 files changed, 193 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5540401..969465b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,7 @@ NOINST_H_FILES =			\
 
 INST_H_FILES =				\
 	eog-application.h		\
+	eog-application-activatable.h	\
 	eog-clipboard-handler.h		\
 	eog-debug.h			\
 	eog-dialog.h			\
@@ -64,6 +65,7 @@ INST_H_FILES =				\
 
 libeog_c_files = 			\
 	eog-application.c		\
+	eog-application-activatable.c	\
 	eog-clipboard-handler.c		\
 	eog-close-confirmation-dialog.c \
 	eog-debug.c			\
diff --git a/src/eog-application-activatable.c b/src/eog-application-activatable.c
new file mode 100644
index 0000000..638410a
--- /dev/null
+++ b/src/eog-application-activatable.c
@@ -0,0 +1,85 @@
+/*
+ * eog-application-activatable.c
+ * This file is part of eog
+ *
+ * Author: Felix Riemann <friemann gnome org>
+ *
+ * Copyright (C) 2012 Felix Riemann
+ * 
+ * Base on code by:
+ * 	- Steve FrÃcinaux <code istique net>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "eog-application-activatable.h"
+
+#include <glib-object.h>
+#include "eog-application.h"
+
+G_DEFINE_INTERFACE(EogApplicationActivatable, eog_application_activatable, G_TYPE_OBJECT)
+
+void
+eog_application_activatable_default_init (EogApplicationActivatableInterface *iface)
+{
+	static gboolean initialized = FALSE;
+
+	if (!initialized) {
+		/**
+         * EogApplicationActivatable:app:
+		 *
+         * This is the #EogApplication this #EogApplicationActivatable instance
+		 * should be attached to.
+		 */
+		g_object_interface_install_property (iface,
+                g_param_spec_object ("app", "Application",
+                             "The EogApplication this instance it attached to",
+                             EOG_TYPE_APPLICATION,
+						     G_PARAM_READWRITE |
+						     G_PARAM_CONSTRUCT_ONLY |
+						     G_PARAM_STATIC_STRINGS));
+		initialized = TRUE;
+	}
+}
+
+void
+eog_application_activatable_activate (EogApplicationActivatable *activatable)
+{
+    EogApplicationActivatableInterface *iface;
+
+    g_return_if_fail (EOG_IS_APPLICATION_ACTIVATABLE (activatable));
+
+    iface = EOG_APPLICATION_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (G_LIKELY (iface->activate != NULL))
+		iface->activate (activatable);
+}
+
+void
+eog_application_activatable_deactivate (EogApplicationActivatable *activatable)
+{
+    EogApplicationActivatableInterface *iface;
+
+    g_return_if_fail (EOG_IS_APPLICATION_ACTIVATABLE (activatable));
+
+    iface = EOG_APPLICATION_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (G_LIKELY (iface->deactivate != NULL))
+		iface->deactivate (activatable);
+}
diff --git a/src/eog-application-activatable.h b/src/eog-application-activatable.h
new file mode 100644
index 0000000..4045981
--- /dev/null
+++ b/src/eog-application-activatable.h
@@ -0,0 +1,69 @@
+/*
+ * eog-application-activatable.h
+ * This file is part of eog
+ *
+ * Author: Felix Riemann <friemann gnome org>
+ *
+ * Copyright (C) 2012 Felix Riemann
+ * 
+ * Base on code by:
+ * 	- Steve FrÃcinaux <code istique net>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __EOG_APPLICATION_ACTIVATABLE_H__
+#define __EOG_APPLICATION_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EOG_TYPE_APPLICATION_ACTIVATABLE (eog_application_activatable_get_type ())
+#define EOG_APPLICATION_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                          EOG_TYPE_APPLICATION_ACTIVATABLE, \
+                                          EogApplicationActivatable))
+#define EOG_APPLICATION_ACTIVATABLE_IFACE(obj) \
+                                          (G_TYPE_CHECK_CLASS_CAST ((obj), \
+                                           EOG_TYPE_APPLICATION_ACTIVATABLE, \
+                                           EogApplicationActivatableInterface))
+#define EOG_IS_APPLICATION_ACTIVATABLE(obj) \
+                                          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                                           EOG_TYPE_APPLICATION_ACTIVATABLE))
+#define EOG_APPLICATION_ACTIVATABLE_GET_IFACE(obj) \
+                                        (G_TYPE_INSTANCE_GET_INTERFACE ((obj), \
+                                         EOG_TYPE_APPLICATION_ACTIVATABLE, \
+                                         EogApplicationActivatableInterface))
+
+typedef struct _EogApplicationActivatable		EogApplicationActivatable;
+typedef struct _EogApplicationActivatableInterface	EogApplicationActivatableInterface;
+
+struct _EogApplicationActivatableInterface
+{
+	GTypeInterface g_iface;
+
+	/* vfuncs */
+
+    void	(*activate)	(EogApplicationActivatable *activatable);
+    void	(*deactivate)	(EogApplicationActivatable *activatable);
+};
+
+GType	eog_application_activatable_get_type     (void) G_GNUC_CONST;
+
+void	eog_application_activatable_activate     (EogApplicationActivatable *activatable);
+void	eog_application_activatable_deactivate   (EogApplicationActivatable *activatable);
+
+G_END_DECLS
+#endif /* __EOG_APPLICATION_ACTIVATABLE_H__ */
diff --git a/src/eog-application.c b/src/eog-application.c
index a97658a..0716d8e 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -31,6 +31,7 @@
 #include "eog-session.h"
 #include "eog-window.h"
 #include "eog-application.h"
+#include "eog-application-activatable.h"
 #include "eog-util.h"
 
 #include "totem-scrsaver.h"
@@ -266,6 +267,9 @@ eog_application_finalize (GObject *object)
 		g_free (application->toolbars_file);
 		application->toolbars_file = NULL;
 	}
+
+	g_clear_object (&application->extensions);
+
 	if (application->plugin_engine) {
 		g_object_unref (application->plugin_engine);
 		application->plugin_engine = NULL;
@@ -331,6 +335,24 @@ eog_application_class_init (EogApplicationClass *eog_application_class)
 }
 
 static void
+on_extension_added (PeasExtensionSet *set,
+                    PeasPluginInfo   *info,
+                    PeasExtension    *exten,
+                    EogApplication   *app)
+{
+	eog_application_activatable_activate (EOG_APPLICATION_ACTIVATABLE (exten));
+}
+
+static void
+on_extension_removed (PeasExtensionSet *set,
+                      PeasPluginInfo   *info,
+                      PeasExtension    *exten,
+                      EogApplication   *app)
+{
+	eog_application_activatable_deactivate (EOG_APPLICATION_ACTIVATABLE (exten));
+}
+
+static void
 eog_application_init (EogApplication *eog_application)
 {
 	const gchar *dot_dir = eog_util_dot_dir ();
@@ -361,6 +383,17 @@ eog_application_init (EogApplication *eog_application)
 				      EGG_TB_MODEL_NOT_REMOVABLE);
 
 	eog_application_load_accelerators ();
+
+	eog_application->extensions = peas_extension_set_new (
+	                           PEAS_ENGINE (eog_application->plugin_engine),
+	                           EOG_TYPE_APPLICATION_ACTIVATABLE,
+	                           "app",  EOG_APPLICATION (eog_application),
+	                           NULL);
+	peas_extension_set_call (eog_application->extensions, "activate");
+	g_signal_connect (eog_application->extensions, "extension-added",
+	                  G_CALLBACK (on_extension_added), eog_application);
+	g_signal_connect (eog_application->extensions, "extension-removed",
+	                  G_CALLBACK (on_extension_removed), eog_application);
 }
 
 /**
diff --git a/src/eog-application.h b/src/eog-application.h
index b93688c..36122d5 100644
--- a/src/eog-application.h
+++ b/src/eog-application.h
@@ -34,6 +34,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <libpeas/peas-extension-set.h>
+
 G_BEGIN_DECLS
 
 typedef struct _EogApplication EogApplication;
@@ -60,6 +62,8 @@ struct _EogApplication {
 	EogStartupFlags   flags;
 
 	GSettings        *ui_settings;
+
+	PeasExtensionSet *extensions;
 };
 
 struct _EogApplicationClass {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]