[totem/gnome-2-32] Backport chapters plugin to old build plugin system



commit d5fabd98a1f6e2f74907bfbcbb8558b2b7523d89
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Aug 9 16:37:10 2010 +0100

    Backport chapters plugin to old build plugin system
    
    Also fix a number of compile-time warnings, and the inability
    to load UI files from the uninstalled directory.

 configure.in                              |    4 +-
 src/plugins/chapters/totem-chapters.c     |   69 +++++++++++++++-------------
 src/plugins/chapters/totem-cmml-parser.c  |    2 +-
 src/plugins/chapters/totem-edit-chapter.c |   61 +++++++++++++++++++++++++-
 4 files changed, 100 insertions(+), 36 deletions(-)
---
diff --git a/configure.in b/configure.in
index 91254ee..03be727 100644
--- a/configure.in
+++ b/configure.in
@@ -562,10 +562,10 @@ for plugin in ${used_plugins}; do
 			fi
 		;;
 		chapters)
-			PKG_CHECK_MODULES(CHAPTERS, libxml-2.0 >= 2.6.0 gtk+-3.0 glib-2.0 >= 2.15.0,
+			PKG_CHECK_MODULES(CHAPTERS, libxml-2.0 >= 2.6.0 gtk+-2.0 glib-2.0 >= 2.15.0,
 				[BUILD_CHAPTERS=yes], [BUILD_CHAPTERS=no])
 			if test "${BUILD_CHAPTERS}" != "yes" ; then
-				plugin_error_or_ignore "you need gtk+-3.0, glib-2.0 >= 2.15.0 and libxml-2.0 >= 2.6.0 to use the chapters plugin"
+				plugin_error_or_ignore "you need gtk+-2.0, glib-2.0 >= 2.15.0 and libxml-2.0 >= 2.6.0 to use the chapters plugin"
 				add_plugin="0"
 			fi
 		;;
diff --git a/src/plugins/chapters/totem-chapters.c b/src/plugins/chapters/totem-chapters.c
index 6ea0173..418fad7 100644
--- a/src/plugins/chapters/totem-chapters.c
+++ b/src/plugins/chapters/totem-chapters.c
@@ -85,14 +85,14 @@ typedef struct {
 } TotemChaptersPluginPrivate;
 
 typedef struct {
-	PeasExtensionBase		parent;
+	TotemPlugin			 parent;
 	TotemObject			*totem;
 	TotemEditChapter		*edit_chapter;
 	TotemChaptersPluginPrivate	*priv;
 } TotemChaptersPlugin;
 
 typedef struct {
-	PeasExtensionBaseClass		parent_class;
+	TotemPluginClass		parent_class;
 } TotemChaptersPluginClass;
 
 enum {
@@ -106,6 +106,8 @@ enum {
 
 G_MODULE_EXPORT GType register_totem_plugin (GTypeModule *module);
 GType totem_chapters_plugin_get_type (void) G_GNUC_CONST;
+static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error);
+static void impl_deactivate (TotemPlugin *plugin, TotemObject *totem);
 static void totem_chapters_plugin_finalize (GObject *object);
 static void totem_file_opened_async_cb (TotemObject *totem, const gchar *uri, TotemChaptersPlugin *plugin);
 static void totem_file_opened_result_cb (gpointer data, gpointer user_data);
@@ -140,16 +142,20 @@ void popup_goto_action_cb (GtkAction *action, TotemChaptersPlugin *plugin);
 void load_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
 void continue_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
 
-TOTEM_PLUGIN_REGISTER (TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPlugin, totem_chapters_plugin)
+TOTEM_PLUGIN_REGISTER (TotemChaptersPlugin, totem_chapters_plugin)
 
 static void
 totem_chapters_plugin_class_init (TotemChaptersPluginClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (TotemChaptersPluginPrivate));
 
 	object_class->finalize = totem_chapters_plugin_finalize;
+
+	plugin_class->activate = impl_activate;
+	plugin_class->deactivate = impl_deactivate;
 }
 
 static void
@@ -250,13 +256,13 @@ add_chapter_to_the_list_new (TotemChaptersPlugin	*plugin,
 			     const gchar		*title,
 			     gint64			time)
 {
-	GdkPixbuf		*pixbuf;
-	GtkTreeIter		iter, cur_iter, res_iter;
-	GtkTreeModel		*store;
-	gchar 			*text, *start, *tip;
-	gboolean		valid;
-	gint64			cur_time, prev_time = 0;
-	gint			iter_count = 0;
+	GdkPixbuf	*pixbuf;
+	GtkTreeIter	iter, cur_iter, res_iter;
+	GtkTreeModel	*store;
+	gchar		*text, *start, *tip;
+	gboolean	valid;
+	gint64		cur_time, prev_time = 0;
+	gint		iter_count = 0;
 
 	g_return_if_fail (TOTEM_IS_CHAPTERS_PLUGIN (plugin));
 	g_return_if_fail (title != NULL);
@@ -361,8 +367,8 @@ totem_file_opened_result_cb (gpointer	data,
 			g_free (adata);
 			return;
 		} else
-			totem_action_error (plugin->totem, _("Error while reading file with chapters"),
-					    adata->error);
+			totem_action_error (_("Error while reading file with chapters"),
+					    adata->error, plugin->totem);
 	}
 
 	if (adata->is_exists && adata->from_dialog) {
@@ -751,8 +757,8 @@ save_chapters_result_cb (gpointer	data,
 	plugin = TOTEM_CHAPTERS_PLUGIN (adata->user_data);
 
 	if (G_UNLIKELY (!adata->successful && !g_cancellable_is_cancelled (adata->cancellable))) {
-		totem_action_error (plugin->totem, _("Error while writing file with chapters"),
-				    adata->error);
+		totem_action_error (_("Error while writing file with chapters"),
+				    adata->error, plugin->totem);
 		gtk_widget_set_sensitive (plugin->priv->save_button, TRUE);
 	}
 
@@ -876,8 +882,8 @@ save_button_clicked_cb (GtkButton		*button,
 				   (gpointer *) &(plugin->priv->cancellable[1]));
 
 	if (G_UNLIKELY (totem_cmml_write_file_async (data) < 0)) {
-		totem_action_error (plugin->totem, _("Error occurred while saving chapters"),
-				    _("Please check you rights and free space"));
+		totem_action_error (_("Error occurred while saving chapters"),
+				    _("Please check you rights and free space"), plugin->totem);
 		g_free (data);
 		g_object_unref (plugin->priv->cancellable);
 	} else
@@ -1091,11 +1097,11 @@ goto_button_clicked_cb (GtkButton		*button,
 	g_list_free (list);
 }
 
-static void
-impl_activate (PeasActivatable	*plugin,
-	       GObject		*object)
+static gboolean
+impl_activate (TotemPlugin *plugin,
+	       TotemObject *totem,
+	       GError **error)
 {
-	TotemObject		*totem;
 	GtkWindow		*main_window;
 	GConfClient		*gconf;
 	GtkBuilder		*builder;
@@ -1106,19 +1112,19 @@ impl_activate (PeasActivatable	*plugin,
 	GtkTreeViewColumn	*column;
 	gchar			*mrl;
 
-	g_return_if_fail (TOTEM_IS_OBJECT (object));
-	g_return_if_fail (TOTEM_IS_CHAPTERS_PLUGIN (plugin));
+	g_return_val_if_fail (TOTEM_IS_CHAPTERS_PLUGIN (plugin), FALSE);
 
 	cplugin = TOTEM_CHAPTERS_PLUGIN (plugin);
-	totem = TOTEM_OBJECT (object);
 	main_window = totem_get_main_window (totem);
 
-	builder = totem_interface_load ("chapters-list.ui", TRUE,
-					main_window, cplugin);
+	builder = totem_plugin_load_interface (plugin, "chapters-list.ui", TRUE,
+					       main_window, cplugin);
 	g_object_unref (main_window);
 
-	if (builder == NULL)
-		return;
+	if (builder == NULL) {
+		//FIXME set error
+		return FALSE;
+	}
 
 	gconf = gconf_client_get_default ();
 	if (G_LIKELY (gconf != NULL)) {
@@ -1205,19 +1211,18 @@ impl_activate (PeasActivatable	*plugin,
 
 	g_object_unref (builder);
 	g_free (mrl);
+
+	return TRUE;
 }
 
 static void
-impl_deactivate (PeasActivatable	*plugin,
-		 GObject		*object)
+impl_deactivate (TotemPlugin *plugin,
+		 TotemObject *totem)
 {
-	TotemObject		*totem;
 	TotemChaptersPlugin	*cplugin;
 
-	g_return_if_fail (TOTEM_IS_OBJECT (object));
 	g_return_if_fail (TOTEM_IS_CHAPTERS_PLUGIN (plugin));
 
-	totem = TOTEM_OBJECT (object);
 	cplugin = TOTEM_CHAPTERS_PLUGIN (plugin);
 
 	/* FIXME: do not cancel async operation if any */
diff --git a/src/plugins/chapters/totem-cmml-parser.c b/src/plugins/chapters/totem-cmml-parser.c
index 691f90c..d8eea27 100644
--- a/src/plugins/chapters/totem-cmml-parser.c
+++ b/src/plugins/chapters/totem-cmml-parser.c
@@ -134,7 +134,7 @@ totem_cmml_clip_insert_img_attr (TotemCmmlClip	*clip,
 	GdkPixdata	*pixdata;
 	GdkPixbuf	*pixbuf;
 	guchar		*base64_dec;
-	guint		st_len;
+	gsize		st_len;
 	GError		*error = NULL;
 
 	g_return_if_fail (clip != NULL);
diff --git a/src/plugins/chapters/totem-edit-chapter.c b/src/plugins/chapters/totem-edit-chapter.c
index aa0fd14..e90f69e 100644
--- a/src/plugins/chapters/totem-edit-chapter.c
+++ b/src/plugins/chapters/totem-edit-chapter.c
@@ -35,6 +35,7 @@
 
 #include "totem.h"
 #include "totem-interface.h"
+#include "totem-plugin.h"
 #include "totem-edit-chapter.h"
 #include <string.h>
 
@@ -57,13 +58,71 @@ totem_edit_chapter_class_init (TotemEditChapterClass *klass)
 	g_type_class_add_private (klass, sizeof (TotemEditChapterPrivate));
 }
 
+static char *
+find_file (const char *name,
+	   const char *file)
+{
+	GList *paths;
+	GList *l;
+	char *ret = NULL;
+
+	paths = totem_get_plugin_paths ();
+
+	for (l = paths; l != NULL; l = l->next) {
+		if (ret == NULL && name) {
+			char *tmp;
+
+			tmp = g_build_filename (l->data, name, file, NULL);
+
+			if (g_file_test (tmp, G_FILE_TEST_EXISTS)) {
+				ret = tmp;
+				break;
+			}
+			g_free (tmp);
+		}
+	}
+
+	g_list_foreach (paths, (GFunc)g_free, NULL);
+	g_list_free (paths);
+
+	/* global data files */
+	if (ret == NULL)
+		ret = totem_interface_get_full_path (file);
+
+	/* ensure it's an absolute path, so doesn't confuse rb_glade_new et al */
+	if (ret && ret[0] != '/') {
+		char *pwd = g_get_current_dir ();
+		char *path = g_strconcat (pwd, G_DIR_SEPARATOR_S, ret, NULL);
+		g_free (ret);
+		g_free (pwd);
+		ret = path;
+	}
+	return ret;
+}
+
+static GtkBuilder *
+load_interface (const char *pname, const char *name,
+		gboolean fatal, GtkWindow *parent,
+		gpointer user_data)
+{
+	GtkBuilder *builder = NULL;
+	char *filename;
+
+	filename = find_file (pname, name);
+	builder = totem_interface_load_with_full_path (filename, fatal, parent,
+						       user_data);
+	g_free (filename);
+
+	return builder;
+}
+
 static void
 totem_edit_chapter_init (TotemEditChapter *self)
 {
 	GtkBuilder	*builder;
 
 	self->priv = TOTEM_EDIT_CHAPTER_GET_PRIVATE (self);
-	builder = totem_interface_load ("chapters-edit.ui", FALSE, NULL, self);
+	builder = load_interface ("chapters", "chapters-edit.ui", FALSE, NULL, self);
 
 	if (builder == NULL) {
 		self->priv->container = NULL;



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