[eog] Add our own activatable interface to EogWindow



commit 397a6a5399aa7e68469e18387de5e40f3875c440
Author: Felix Riemann <friemann gnome org>
Date:   Sun Jan 2 23:54:13 2011 +0100

    Add our own activatable interface to EogWindow
    
    Improves typesafety by explicitly passing the EogWindow and allows
    us to extend the interface if necessary.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=626091

 src/Makefile.am              |    2 +
 src/eog-window-activatable.c |   86 ++++++++++++++++++++++++++++++++++++++++++
 src/eog-window-activatable.h |   68 +++++++++++++++++++++++++++++++++
 src/eog-window.c             |    6 ++-
 4 files changed, 160 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a6672fc..e995e8b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,6 +49,7 @@ INST_H_FILES =				\
 	eog-application.h		\
 	eog-debug.h			\
 	eog-window.h			\
+	eog-window-activatable.h	\
 	eog-sidebar.h			\
 	eog-dialog.h			\
 	eog-properties-dialog.h		\
@@ -74,6 +75,7 @@ libeog_c_files = 			\
 	eog-util.c			\
 	eog-pixbuf-util.c		\
 	eog-window.c			\
+	eog-window-activatable.c	\
 	eog-sidebar.c			\
 	eog-dialog.c			\
 	eog-preferences-dialog.c	\
diff --git a/src/eog-window-activatable.c b/src/eog-window-activatable.c
new file mode 100644
index 0000000..3221ab7
--- /dev/null
+++ b/src/eog-window-activatable.c
@@ -0,0 +1,86 @@
+/*
+ * eog-window-activatable.c
+ * This file is part of eog
+ *
+ * Author: Felix Riemann <friemann gnome org>
+ *
+ * Copyright (C) 2011 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-window-activatable.h"
+
+#include <glib-object.h>
+#include "eog-window.h"
+
+G_DEFINE_INTERFACE(EogWindowActivatable, eog_window_activatable, G_TYPE_OBJECT)
+
+void
+eog_window_activatable_default_init (EogWindowActivatableInterface *iface)
+{
+	static gboolean initialized = FALSE;
+
+	if (!initialized) {
+		/**
+		 * EogWindowActivatable:window:
+		 *
+		 * This is the #EogWindow this #EogWindowActivatable instance
+		 * should be attached to.
+		 */
+		g_object_interface_install_property (iface,
+				g_param_spec_object ("window", "Window",
+						     "The EogWindow this "
+						     "instance it attached to",
+						     EOG_TYPE_WINDOW,
+						     G_PARAM_READWRITE |
+						     G_PARAM_CONSTRUCT_ONLY |
+						     G_PARAM_STATIC_STRINGS));
+		initialized = TRUE;
+	}
+}
+
+void
+eog_window_activatable_activate (EogWindowActivatable *activatable)
+{
+	EogWindowActivatableInterface *iface;
+
+	g_return_if_fail (EOG_IS_WINDOW_ACTIVATABLE (activatable));
+
+	iface = EOG_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (G_LIKELY (iface->activate != NULL))
+		iface->activate (activatable);
+}
+
+void
+eog_window_activatable_deactivate (EogWindowActivatable *activatable)
+{
+	EogWindowActivatableInterface *iface;
+
+	g_return_if_fail (EOG_IS_WINDOW_ACTIVATABLE (activatable));
+
+	iface = EOG_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (G_LIKELY (iface->deactivate != NULL))
+		iface->deactivate (activatable);
+}
diff --git a/src/eog-window-activatable.h b/src/eog-window-activatable.h
new file mode 100644
index 0000000..6209633
--- /dev/null
+++ b/src/eog-window-activatable.h
@@ -0,0 +1,68 @@
+/*
+ * eog-window-activatable.h
+ * This file is part of eog
+ *
+ * Author: Felix Riemann <friemann gnome org>
+ *
+ * Copyright (C) 2011 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_WINDOW_ACTIVATABLE_H__
+#define __EOG_WINDOW_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EOG_TYPE_WINDOW_ACTIVATABLE	(eog_window_activatable_get_type ())
+#define EOG_WINDOW_ACTIVATABLE(obj) 	(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+					 EOG_TYPE_WINDOW_ACTIVATABLE, \
+					 EogWindowActivatable))
+#define EOG_WINDOW_ACTIVATABLE_IFACE(obj) \
+					(G_TYPE_CHECK_CLASS_CAST ((obj), \
+					 EOG_TYPE_WINDOW_ACTIVATABLE, \
+					 EogWindowActivatableInterface))
+#define EOG_IS_WINDOW_ACTIVATABLE(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+					 EOG_TYPE_WINDOW_ACTIVATABLE))
+#define EOG_WINDOW_ACTIVATABLE_GET_IFACE(obj) \
+					(G_TYPE_INSTANCE_GET_INTERFACE ((obj), \
+					 EOG_TYPE_WINDOW_ACTIVATABLE, \
+					 EogWindowActivatableInterface))
+
+typedef struct _EogWindowActivatable		EogWindowActivatable;
+typedef struct _EogWindowActivatableInterface	EogWindowActivatableInterface;
+
+struct _EogWindowActivatableInterface
+{
+	GTypeInterface g_iface;
+
+	/* vfuncs */
+
+	void	(*activate)	(EogWindowActivatable *activatable);
+	void	(*deactivate)	(EogWindowActivatable *activatable);
+};
+
+GType	eog_window_activatable_get_type	(void) G_GNUC_CONST;
+
+void	eog_window_activatable_activate	    (EogWindowActivatable *activatable);
+void	eog_window_activatable_deactivate   (EogWindowActivatable *activatable);
+
+G_END_DECLS
+#endif /* __EOG_WINDOW_ACTIVATABLE_H__ */
diff --git a/src/eog-window.c b/src/eog-window.c
index f28f1e2..f5f19c2 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -53,6 +53,7 @@
 #include "eog-plugin-engine.h"
 #include "eog-close-confirmation-dialog.h"
 #include "eog-clipboard-handler.h"
+#include "eog-window-activatable.h"
 
 #include "eog-enum-types.h"
 
@@ -5096,8 +5097,9 @@ eog_window_constructor (GType type,
 	eog_window_construct_ui (EOG_WINDOW (object));
 
 	priv->extensions = peas_extension_set_new (PEAS_ENGINE (EOG_APP->plugin_engine),
-						   PEAS_TYPE_ACTIVATABLE,
-						   "object", object, NULL);
+						   EOG_TYPE_WINDOW_ACTIVATABLE,
+						   "window",
+						   EOG_WINDOW (object), NULL);
 	peas_extension_set_call (priv->extensions, "activate");
 	g_signal_connect (priv->extensions, "extension-added",
 			  G_CALLBACK (on_extension_added), object);



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