[eog-plugins] [exif-display] Move configuration UI into its own class



commit 8cc99eba076618f3b5da6854828be493c9e7a5e6
Author: Felix Riemann <friemann gnome org>
Date:   Tue Feb 8 13:42:00 2011 +0100

    [exif-display] Move configuration UI into its own class

 plugins/exif-display/Makefile.am                   |    5 +-
 .../exif-display/eog-exif-display-plugin-setup.c   |  197 ++++++++++++++++++++
 .../exif-display/eog-exif-display-plugin-setup.h   |   83 ++++++++
 plugins/exif-display/eog-exif-display-plugin.c     |   96 +---------
 4 files changed, 289 insertions(+), 92 deletions(-)
---
diff --git a/plugins/exif-display/Makefile.am b/plugins/exif-display/Makefile.am
index b5569fe..d6cd327 100644
--- a/plugins/exif-display/Makefile.am
+++ b/plugins/exif-display/Makefile.am
@@ -13,7 +13,10 @@ plugin_LTLIBRARIES = libexif-display.la
 
 libexif_display_la_SOURCES = \
 	eog-exif-display-plugin.h			\
-	eog-exif-display-plugin.c
+	eog-exif-display-plugin.c			\
+	eog-exif-display-plugin-settings.h		\
+	eog-exif-display-plugin-setup.c			\
+	eog-exif-display-plugin-setup.h
 
 libexif_display_la_LDFLAGS = \
 	-avoid-version -module
diff --git a/plugins/exif-display/eog-exif-display-plugin-setup.c b/plugins/exif-display/eog-exif-display-plugin-setup.c
new file mode 100644
index 0000000..e9e1c8e
--- /dev/null
+++ b/plugins/exif-display/eog-exif-display-plugin-setup.c
@@ -0,0 +1,197 @@
+/* Exif-display Plugin - Configuration Interface
+ *
+ * Copyright (C) 2009-2011 The Free Software Foundation
+ *
+ * Author: Felix Riemann  <friemann gnome org>
+ * Based on code by Emmanuel Touzery  <emmanuel touzery free fr>
+ *
+ * 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 <gtk/gtk.h>
+
+#include <gconf/gconf-client.h>
+
+#include <glib/gi18n-lib.h>
+#include <eog/eog-debug.h>
+
+#include <libpeas-gtk/peas-gtk-configurable.h>
+
+#include "eog-exif-display-plugin-setup.h"
+
+#define EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_CHANNELS_HISTOGRAM "/apps/eog/plugins/exif_display/display_channels_histogram"
+#define EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_RGB_HISTOGRAM "/apps/eog/plugins/exif_display/display_rgb_histogram"
+#define EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_EXIF_STATUSBAR "/apps/eog/plugins/exif_display/display_exif_in_statusbar"
+
+/* copy-pasted from eog-preferences-dialog.c */
+#define GCONF_OBJECT_KEY	"GCONF_KEY"
+
+/* copy-pasted from eog-preferences-dialog.c */
+#define TOGGLE_INVERT_VALUE	"TOGGLE_INVERT_VALUE"
+
+static GConfClient *gconf_client = NULL;
+
+#define GTKBUILDER_CONFIG_FILE EOG_PLUGINDIR"/exif-display/exif-display-config.ui"
+
+static void
+peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogExifDisplayPluginSetup,
+		eog_exif_display_plugin_setup, PEAS_TYPE_EXTENSION_BASE, 0,
+		G_IMPLEMENT_INTERFACE_DYNAMIC(PEAS_GTK_TYPE_CONFIGURABLE,
+					peas_gtk_configurable_iface_init))
+
+
+static void
+eog_exif_display_plugin_setup_init (EogExifDisplayPluginSetup *setup)
+{
+	setup->vbox = NULL;
+}
+
+/* copy-pasted from eog-preferences-dialog.c */
+static void
+pd_check_toggle_cb (GtkWidget *widget, gpointer data)
+{
+	char *key = NULL;
+	gboolean invert = FALSE;
+	gboolean value;
+
+	key = g_object_get_data (G_OBJECT (widget), GCONF_OBJECT_KEY);
+	invert = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), TOGGLE_INVERT_VALUE));
+
+	value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+
+	if (key == NULL) return;
+
+	gconf_client_set_bool (GCONF_CLIENT (data),
+			       key,
+			       (invert) ? !value : value,
+			       NULL);
+}
+
+static void
+close_config_window_cb(GtkWidget *widget, gpointer _data)
+{
+	GtkWidget *data = GTK_WIDGET (_data);
+
+	gtk_widget_destroy (GTK_WIDGET (gtk_widget_get_toplevel (data)));
+}
+
+static void
+connect_checkbox_to_gconf_setting (GtkToggleButton *checkbox, char *gconf_key)
+{
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox),
+				      gconf_client_get_bool (gconf_client,
+							     gconf_key,
+							     NULL));
+
+	g_object_set_data (G_OBJECT (checkbox),
+			   GCONF_OBJECT_KEY,
+			   gconf_key);
+
+	g_signal_connect (G_OBJECT (checkbox),
+			  "toggled",
+			  G_CALLBACK (pd_check_toggle_cb),
+			  gconf_client);
+}
+
+static GtkWidget *
+impl_create_config_widget (PeasGtkConfigurable *configurable)
+{
+	EogExifDisplayPluginSetup *setup;
+	GtkBuilder *config_builder;
+	GError *error = NULL;
+	GtkWidget *display_channels_histogram_widget, *display_rgb_histogram_widget;
+	GtkWidget *close_button, *display_camera_settings_in_statusbar;
+	GtkWidget *result;
+
+	setup = EOG_EXIF_DISPLAY_PLUGIN_SETUP (configurable);
+
+	config_builder = gtk_builder_new ();
+	gtk_builder_set_translation_domain (config_builder, GETTEXT_PACKAGE);
+	if (!gtk_builder_add_from_file (config_builder, GTKBUILDER_CONFIG_FILE, &error))
+	{
+		g_warning ("Couldn't load builder file: %s", error->message);
+		g_error_free (error);
+	}
+	result = GTK_WIDGET (gtk_builder_get_object (config_builder, "vbox1"));
+	gtk_widget_unparent (result);
+	display_channels_histogram_widget = GTK_WIDGET (
+			gtk_builder_get_object (config_builder, "display_per_channel_histogram"));
+	display_rgb_histogram_widget = GTK_WIDGET (
+			gtk_builder_get_object (config_builder, "display_rgb_histogram"));
+	display_camera_settings_in_statusbar = GTK_WIDGET (
+			gtk_builder_get_object (config_builder, "display_camerasettings_statusbar"));
+
+	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_channels_histogram_widget),
+			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_CHANNELS_HISTOGRAM);
+	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_rgb_histogram_widget),
+			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_RGB_HISTOGRAM);
+	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_camera_settings_in_statusbar),
+			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_EXIF_STATUSBAR);
+	return result;
+}
+
+
+static void
+eog_exif_display_plugin_setup_dispose (GObject *object)
+{
+	EogExifDisplayPluginSetup *setup = EOG_EXIF_DISPLAY_PLUGIN_SETUP (object);
+
+	eog_debug_message (DEBUG_PLUGINS,
+			   "EogExifDisplayPluginSetup disposing");
+
+	if (setup->vbox != NULL) {
+		g_object_unref (setup->vbox);
+		setup->vbox = NULL;
+	}
+
+	G_OBJECT_CLASS (eog_exif_display_plugin_setup_parent_class)->dispose (object);
+}
+
+static void
+eog_exif_display_plugin_setup_class_init (EogExifDisplayPluginSetupClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	gconf_client = gconf_client_get_default ();
+
+	object_class->dispose = eog_exif_display_plugin_setup_dispose;
+}
+
+static void
+peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface)
+{
+	iface->create_configure_widget = impl_create_config_widget;
+}
+
+static void
+eog_exif_display_plugin_setup_class_finalize (EogExifDisplayPluginSetupClass *klass)
+{
+	/* Dummy needed for G_DEFINE_DYNAMIC_TYPE_EXTENDED */
+}
+
+void
+eog_exif_display_plugin_setup_register_types (PeasObjectModule *module)
+{
+	eog_exif_display_plugin_setup_register_type (G_TYPE_MODULE (module));
+	peas_object_module_register_extension_type (module,
+						    PEAS_GTK_TYPE_CONFIGURABLE,
+						    EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP);
+}
diff --git a/plugins/exif-display/eog-exif-display-plugin-setup.h b/plugins/exif-display/eog-exif-display-plugin-setup.h
new file mode 100644
index 0000000..366191a
--- /dev/null
+++ b/plugins/exif-display/eog-exif-display-plugin-setup.h
@@ -0,0 +1,83 @@
+/* Exif-display Plugin - Configuration Interface
+ *
+ * Copyright (C) 2009-2011 The Free Software Foundation
+ *
+ * Author: Felix Riemann  <friemann gnome org>
+ * Based on code by Emmanuel Touzery  <emmanuel touzery free fr>
+ *
+ * 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_EXIF_DISPLAY_PLUGIN_SETUP_H__
+#define __EOG_EXIF_DISPLAY_PLUGIN_SETUP_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <eog/eog-thumb-view.h>
+#include <eog/eog-window.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP	(eog_exif_display_plugin_setup_get_type ())
+#define EOG_EXIF_DISPLAY_PLUGIN_SETUP(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP, EogExifDisplayPluginSetup))
+#define EOG_EXIF_DISPLAY_PLUGIN_SETUP_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k),      EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP, EogExifDisplayPluginSetupClass))
+#define EOG_IS_EXIF_DISPLAY_PLUGIN_SETUP(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP))
+#define EOG_IS_EXIF_DISPLAY_PLUGIN_SETUP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP))
+#define EOG_EXIF_DISPLAY_PLUGIN_SETUP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),  EOG_TYPE_EXIF_DISPLAY_PLUGIN_SETUP, EogExifDisplayPluginSetupClass))
+
+/* Private structure type */
+typedef struct _EogExifDisplayPluginSetupPrivate EogExifDisplayPluginSetupPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _EogExifDisplayPluginSetup	EogExifDisplayPluginSetup;
+
+struct _EogExifDisplayPluginSetup
+{
+	PeasExtensionBase parent_instance;
+
+	GtkWidget *vbox;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _EogExifDisplayPluginSetupClass	EogExifDisplayPluginSetupClass;
+
+struct _EogExifDisplayPluginSetupClass
+{
+	PeasExtensionBaseClass parent_class;
+};
+
+/*
+ * Public methods
+ */
+GType	eog_exif_display_plugin_setup_get_type		(void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+void	eog_exif_display_plugin_setup_register_types	(PeasObjectModule *module);
+
+
+G_END_DECLS
+
+#endif /* __EOG_EXIF_DISPLAY_PLUGIN_SETUP_H__ */
diff --git a/plugins/exif-display/eog-exif-display-plugin.c b/plugins/exif-display/eog-exif-display-plugin.c
index 5f930cd..2a9f71e 100644
--- a/plugins/exif-display/eog-exif-display-plugin.c
+++ b/plugins/exif-display/eog-exif-display-plugin.c
@@ -42,6 +42,7 @@
 #include <eog/eog-sidebar.h>
 #include <eog/eog-window-activatable.h>
 
+#include "eog-exif-display-plugin-setup.h"
 #include "eog-exif-display-plugin.h"
 
 #define EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_CHANNELS_HISTOGRAM "/apps/eog/plugins/exif_display/display_channels_histogram"
@@ -67,10 +68,12 @@ enum {
 static void
 eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);
 
+
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogExifDisplayPlugin, eog_exif_display_plugin,
                 PEAS_TYPE_EXTENSION_BASE, 0,
                 G_IMPLEMENT_INTERFACE_DYNAMIC(EOG_TYPE_WINDOW_ACTIVATABLE,
                                         eog_window_activatable_iface_init))
+
 #if 0
 static void
 free_window_data (WindowData *data)
@@ -775,96 +778,7 @@ impl_deactivate	(EogWindowActivatable *activatable)
 
 //	g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
 }
-#if 0
-/* copy-pasted from eog-preferences-dialog.c */
-static void
-pd_check_toggle_cb (GtkWidget *widget, gpointer data)
-{
-	char *key = NULL;
-	gboolean invert = FALSE;
-	gboolean value;
-
-	key = g_object_get_data (G_OBJECT (widget), GCONF_OBJECT_KEY);
-	invert = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), TOGGLE_INVERT_VALUE));
-
-	value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
-
-	if (key == NULL) return;
-
-	gconf_client_set_bool (GCONF_CLIENT (data),
-			       key,
-			       (invert) ? !value : value,
-			       NULL);
-}
-
-static void
-close_config_window_cb(GtkWidget *widget, gpointer _data)
-{
-	GtkWidget *data = GTK_WIDGET (_data);
-
-	gtk_widget_destroy (GTK_WIDGET (gtk_widget_get_toplevel (data)));
-}
-
-static void
-connect_checkbox_to_gconf_setting (GtkToggleButton *checkbox, char *gconf_key)
-{
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox),
-				      gconf_client_get_bool (gconf_client,
-							     gconf_key,
-							     NULL));
-
-	g_object_set_data (G_OBJECT (checkbox),
-			   GCONF_OBJECT_KEY,
-			   gconf_key);
-
-	g_signal_connect (G_OBJECT (checkbox),
-			  "toggled",
-			  G_CALLBACK (pd_check_toggle_cb),
-			  gconf_client);
-}
 
-static GtkWidget *
-impl_create_config_dialog (EogPlugin *plugin)
-{
-	GtkBuilder *config_builder;
-	GError *error = NULL;
-	GtkWidget *display_channels_histogram_widget, *display_rgb_histogram_widget;
-	GtkWidget *close_button, *display_camera_settings_in_statusbar;
-	GtkWidget *result;
-
-	config_builder = gtk_builder_new ();
-	gtk_builder_set_translation_domain (config_builder, GETTEXT_PACKAGE);
-	if (!gtk_builder_add_from_file (config_builder, GTKBUILDER_CONFIG_FILE, &error))
-	{
-		g_warning ("Couldn't load builder file: %s", error->message);
-		g_error_free (error);
-	}
-	result = GTK_WIDGET (gtk_builder_get_object (config_builder, "config_dialog"));
-	display_channels_histogram_widget = GTK_WIDGET (
-			gtk_builder_get_object (config_builder, "display_per_channel_histogram"));
-	display_rgb_histogram_widget = GTK_WIDGET (
-			gtk_builder_get_object (config_builder, "display_rgb_histogram"));
-	display_camera_settings_in_statusbar = GTK_WIDGET (
-			gtk_builder_get_object (config_builder, "display_camerasettings_statusbar"));
-	close_button = GTK_WIDGET (
-			gtk_builder_get_object (config_builder, "close_button"));
-	g_object_unref (config_builder);
-
-	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_channels_histogram_widget),
-			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_CHANNELS_HISTOGRAM);
-	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_rgb_histogram_widget),
-			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_RGB_HISTOGRAM);
-	connect_checkbox_to_gconf_setting (GTK_TOGGLE_BUTTON (display_camera_settings_in_statusbar),
-			EOG_EXIF_DISPLAY_CONF_UI_DISPLAY_EXIF_STATUSBAR);
-
-	g_signal_connect (G_OBJECT (close_button),
-			  "clicked",
-			  G_CALLBACK (close_config_window_cb),
-			  GTK_WINDOW (result));
-
-	return result;
-}
-#endif
 static void
 eog_exif_display_plugin_get_property (GObject    *object,
 				      guint       prop_id,
@@ -929,8 +843,6 @@ eog_exif_display_plugin_class_init (EogExifDisplayPluginClass *klass)
 	object_class->get_property = eog_exif_display_plugin_get_property;
 
 	g_object_class_override_property (object_class, PROP_WINDOW, "window");
-
-//	plugin_class->create_configure_dialog = impl_create_config_dialog;
 }
 
 static void
@@ -953,4 +865,6 @@ peas_register_types (PeasObjectModule *module)
         peas_object_module_register_extension_type (module,
                                                     EOG_TYPE_WINDOW_ACTIVATABLE,
                                                     EOG_TYPE_EXIF_DISPLAY_PLUGIN);
+
+	eog_exif_display_plugin_setup_register_types (module);
 }



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