[Goodies-commits] r7839 - in xfmpc/branches/xfmpc-plugins: . plugins plugins/artwork plugins/lyrics src

Mike Massonnet mmassonnet at xfce.org
Sun Jul 26 12:41:23 CEST 2009


Author: mmassonnet
Date: 2009-07-26 10:41:23 +0000 (Sun, 26 Jul 2009)
New Revision: 7839

Added:
   xfmpc/branches/xfmpc-plugins/plugins/
   xfmpc/branches/xfmpc-plugins/plugins/Makefile.am
   xfmpc/branches/xfmpc-plugins/plugins/artwork/
   xfmpc/branches/xfmpc-plugins/plugins/artwork/Makefile.am
   xfmpc/branches/xfmpc-plugins/plugins/artwork/artwork.vala
   xfmpc/branches/xfmpc-plugins/plugins/lyrics/
   xfmpc/branches/xfmpc-plugins/plugins/lyrics/Makefile.am
   xfmpc/branches/xfmpc-plugins/plugins/lyrics/lyrics.vala
   xfmpc/branches/xfmpc-plugins/src/paned-interface.vala
   xfmpc/branches/xfmpc-plugins/src/plugin-interfaces.vala
   xfmpc/branches/xfmpc-plugins/src/plugin-loader.vala
Modified:
   xfmpc/branches/xfmpc-plugins/ChangeLog
   xfmpc/branches/xfmpc-plugins/Makefile.am
   xfmpc/branches/xfmpc-plugins/configure.in.in
   xfmpc/branches/xfmpc-plugins/src/Makefile.am
   xfmpc/branches/xfmpc-plugins/src/config.vapi
   xfmpc/branches/xfmpc-plugins/src/main-window.vala
   xfmpc/branches/xfmpc-plugins/src/main.vala
Log:
Add initial code to load plugins

Modified: xfmpc/branches/xfmpc-plugins/ChangeLog
===================================================================
--- xfmpc/branches/xfmpc-plugins/ChangeLog	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/ChangeLog	2009-07-26 10:41:23 UTC (rev 7839)
@@ -1,5 +1,13 @@
+2009-07-26	Mike Massonnet <mmassonnet at xfce.org>
+
+Add initial code to load plugins
+
 2009-07-23	Mike Massonnet <mmassonnet at xfce.org>
 
+New branch xfmpc-plugins
+
+2009-07-23	Mike Massonnet <mmassonnet at xfce.org>
+
 Update NEWS and AUTHORS
 
 2009-07-23	Mike Massonnet <mmassonnet at xfce.org>

Modified: xfmpc/branches/xfmpc-plugins/Makefile.am
===================================================================
--- xfmpc/branches/xfmpc-plugins/Makefile.am	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/Makefile.am	2009-07-26 10:41:23 UTC (rev 7839)
@@ -1,5 +1,6 @@
 SUBDIRS =								\
 	src								\
+	plugins								\
 	po
 
 dist_man_MANS = xfmpc.1

Modified: xfmpc/branches/xfmpc-plugins/configure.in.in
===================================================================
--- xfmpc/branches/xfmpc-plugins/configure.in.in	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/configure.in.in	2009-07-26 10:41:23 UTC (rev 7839)
@@ -60,6 +60,8 @@
 dnl *** Check for required packages ***
 dnl ***********************************
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
+XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [2.12.0])
+XDT_CHECK_PACKAGE([GEE], [gee-1.0], [0.1.5])
 XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.12.0])
 XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
@@ -85,9 +87,20 @@
 dnl ***********************************
 XDT_FEATURE_DEBUG()
 
+dnl ************************
+dnl *** Define plugindir ***
+dnl ************************
+AC_SUBST([plugindir], [${libdir}/xfmpc])
+
+dnl **************
+dnl *** Output ***
+dnl **************
 AC_OUTPUT([
 Makefile
 src/Makefile
+plugins/Makefile
+plugins/lyrics/Makefile
+plugins/artwork/Makefile
 po/Makefile.in
 ])
 

Added: xfmpc/branches/xfmpc-plugins/plugins/Makefile.am
===================================================================
--- xfmpc/branches/xfmpc-plugins/plugins/Makefile.am	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/plugins/Makefile.am	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,5 @@
+SUBDIRS =								\
+	lyrics								\
+	artwork
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:

Added: xfmpc/branches/xfmpc-plugins/plugins/artwork/Makefile.am
===================================================================
--- xfmpc/branches/xfmpc-plugins/plugins/artwork/Makefile.am	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/plugins/artwork/Makefile.am	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,39 @@
+INCLUDES =								\
+	-I${top_srcdir}							\
+	-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\"				\
+	-DLOCALEDIR=\""$(localedir)"\"					\
+	-DDATADIR=\""$(datadir)"\"
+
+plugin_LTLIBRARIES = libartwork.la
+
+plugin_VALASOURCES =							\
+	artwork.vala
+
+vala_built_SOURCES = 							\
+	$(plugin_VALASOURCES:.vala=.c)
+
+if MAINTAINER_MODE
+
+BUILT_SOURCES =	vala.stamp
+vala.stamp: $(plugin_VALASOURCES)
+	$(VALAC) --pkg=gtk+-2.0 --pkg=gmodule-2.0 $(top_srcdir)/src/plugin-interfaces.vala $^ -C
+	touch $@
+
+endif
+
+libartwork_la_SOURCES = $(vala_built_SOURCES)
+libartwork_la_SOURCES += plugin-interfaces.c
+
+libartwork_la_CFLAGS =							\
+	@GTK_CFLAGS@							\
+	@GMODULE_CFLAGS@
+
+libartwork_la_LIBDADD =							\
+	@GTK_LIBS@							\
+	@GMODULE_LIBS@
+
+EXTRA_DIST = $(plugin_VALASOURCES)
+CLEANFILES = $(BUILT_SOURCES)
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:

Added: xfmpc/branches/xfmpc-plugins/plugins/artwork/artwork.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/plugins/artwork/artwork.vala	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/plugins/artwork/artwork.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,32 @@
+using Gtk;
+
+namespace Xfmpc {
+
+        class ArtworkPlugin : PanedPlugin {
+	        construct {
+		        name = _("Artwork");
+			icon_name = "unknown";
+		        description = _("Displays artist/album artwork from the current playing song");
+		        version = "0.1";
+		        author = "Joe";
+	        }
+
+		public override void create_paned_widget (Gtk.Bin bin) {
+			var vbox = new Gtk.VBox (false, 2);
+			var label = new Gtk.Label ("1");
+			vbox.pack_start (label, true, true, 0);
+			var label2 = new Gtk.Label ("2");
+			vbox.pack_start (label2, true, true, 0);
+			var label3 = new Gtk.Label ("3");
+			vbox.pack_start (label3, true, true, 0);
+			var label4 = new Gtk.Label ("4");
+			vbox.pack_start (label4, true, true, 0);
+			bin.add (vbox);
+		}
+        }
+
+        [ModuleInit]
+        public Type register_plugin () {
+	        return typeof (ArtworkPlugin);
+        }
+}

Added: xfmpc/branches/xfmpc-plugins/plugins/lyrics/Makefile.am
===================================================================
--- xfmpc/branches/xfmpc-plugins/plugins/lyrics/Makefile.am	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/plugins/lyrics/Makefile.am	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,39 @@
+INCLUDES =								\
+	-I${top_srcdir}							\
+	-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\"				\
+	-DLOCALEDIR=\""$(localedir)"\"					\
+	-DDATADIR=\""$(datadir)"\"
+
+plugin_LTLIBRARIES = liblyrics.la
+
+plugin_VALASOURCES =							\
+	lyrics.vala
+
+vala_built_SOURCES = 							\
+	$(plugin_VALASOURCES:.vala=.c)
+
+if MAINTAINER_MODE
+
+BUILT_SOURCES =	vala.stamp
+vala.stamp: $(plugin_VALASOURCES)
+	$(VALAC) --pkg=gtk+-2.0 --pkg=gmodule-2.0 $(top_srcdir)/src/plugin-interfaces.vala $^ -C
+	touch $@
+
+endif
+
+liblyrics_la_SOURCES = $(vala_built_SOURCES)
+liblyrics_la_SOURCES += plugin-interfaces.c
+
+liblyrics_la_CFLAGS =							\
+	@GTK_CFLAGS@							\
+	@GMODULE_CFLAGS@
+
+liblyrics_la_LIBDADD =							\
+	@GTK_LIBS@							\
+	@GMODULE_LIBS@
+
+EXTRA_DIST = $(plugin_VALASOURCES)
+CLEANFILES = $(BUILT_SOURCES)
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:

Added: xfmpc/branches/xfmpc-plugins/plugins/lyrics/lyrics.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/plugins/lyrics/lyrics.vala	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/plugins/lyrics/lyrics.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
+ *
+ *  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.
+ */
+
+using Gtk;
+
+namespace Xfmpc {
+
+	class LyricsPlugin : PanedPlugin {
+		construct {
+			name = _("Lyrics");
+			icon_name = "";
+			description = _("Display lyrics from the current playing song");
+			version = "0.1";
+			author = "Joe";
+		}
+
+		public override void create_paned_widget (Gtk.Bin bin) {
+			var vbox = new Gtk.VBox (false, 2);
+			var label = new Gtk.Label ("1");
+			vbox.pack_start (label, true, true, 0);
+			var label2 = new Gtk.Label ("2");
+			vbox.pack_start (label2, true, true, 0);
+			var label3 = new Gtk.Label ("3");
+			vbox.pack_start (label3, true, true, 0);
+			var label4 = new Gtk.Label ("4");
+			vbox.pack_start (label4, true, true, 0);
+			bin.add (vbox);
+		}
+	}
+
+	[ModuleInit]
+	public Type register_plugin () {
+		return typeof (LyricsPlugin);
+	}
+
+}

Modified: xfmpc/branches/xfmpc-plugins/src/Makefile.am
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/Makefile.am	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/src/Makefile.am	2009-07-26 10:41:23 UTC (rev 7839)
@@ -1,25 +1,36 @@
+INCLUDES =								\
+	-I${top_srcdir}							\
+	-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\"			\
+	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\"				\
+	-DLOCALEDIR=\""$(localedir)"\"					\
+	-DDATADIR=\""$(datadir)"\"					\
+	-DSRCDIR=\""$(top_srcdir)"\"					\
+	-DPLUGINDIR=\""$(plugindir)"\"
+
 bin_PROGRAMS = xfmpc
 
 xfmpc_VALASOURCES =							\
-	preferences-dialog.vala						\
-	song-dialog.vala						\
+	main-window.vala						\
 	statusbar.vala							\
-	dbbrowser.vala							\
+	interface.vala							\
 	extended-interface.vala						\
-	interface.vala							\
-	main-window.vala						\
+	paned-interface.vala						\
 	playlist.vala							\
+	dbbrowser.vala							\
+	song-dialog.vala						\
+	preferences-dialog.vala						\
 	preferences.vala						\
-	main.vala
+	main.vala							\
+	plugin-loader.vala						\
+	plugin-interfaces.vala
 
-vala_built_SOURCES =							\
-	$(xfmpc_VALASOURCES:.vala=.c)
+vala_built_SOURCES = $(xfmpc_VALASOURCES:.vala=.c) xfmpc.h
 
 if MAINTAINER_MODE
 
 BUILT_SOURCES =	vala.stamp
 vala.stamp: $(xfmpc_VALASOURCES)
-	$(VALAC) --vapidir=. --pkg=libxfcegui4-1.0 --pkg=config --pkg=mpdclient --pkg=xfce-arrow-button $^ -C -H xfmpc.h
+	$(VALAC) --vapidir=. --pkg=gee-1.0 --pkg=gmodule-2.0 --pkg=libxfcegui4-1.0 --pkg=config --pkg=mpdclient --pkg=xfce-arrow-button $^ -C -H xfmpc.h
 	touch $@
 
 endif
@@ -29,11 +40,12 @@
 	mpdclient.h							\
 	xfce-arrow-button.c						\
 	xfce-arrow-button.h						\
-	xfmpc.h
-xfmpc_SOURCES += $(vala_built_SOURCES)
+	$(vala_built_SOURCES)
 
 xfmpc_CFLAGS =								\
 	@GTK_CFLAGS@							\
+	@GMODULE_CFLAGS@						\
+	@GEE_CFLAGS@							\
 	@LIBXFCEGUI4_CFLAGS@						\
 	@LIBXFCE4UTIL_CFLAGS@						\
 	@LIBMPD_CFLAGS@							\
@@ -41,22 +53,17 @@
 
 xfmpc_LDADD =								\
 	@GTK_LIBS@							\
+	@GMODULE_LIBS@ 							\
+	@GEE_LIBS@							\
 	@LIBXFCEGUI4_LIBS@						\
 	@LIBXFCE4UTIL_LIBS@						\
 	@LIBMPD_LIBS@							\
 	@GTHREAD_LIBS@
 
-INCLUDES =								\
-	-I${top_srcdir}							\
-	-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\"			\
-	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\"				\
-	-DLOCALEDIR=\""$(localedir)"\"					\
-	-DDATADIR=\""$(datadir)"\"					\
-	-DSRCDIR=\""$(top_srcdir)"\"
-
 EXTRA_DIST =								\
 	$(xfmpc_VALASOURCES)
 
 CLEANFILES =								\
 	$(BUILT_SOURCES)
 
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:

Modified: xfmpc/branches/xfmpc-plugins/src/config.vapi
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/config.vapi	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/src/config.vapi	2009-07-26 10:41:23 UTC (rev 7839)
@@ -29,4 +29,6 @@
 	public const string PACKAGE_STRING;
 	[CCode (cname = "PACKAGE_NAME")]
 	public const string PACKAGE_NAME;
+	[CCode (cname = "PLUGINDIR")]
+	public const string PLUGINDIR;
 }

Modified: xfmpc/branches/xfmpc-plugins/src/main-window.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/main-window.vala	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/src/main-window.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -28,7 +28,9 @@
 
 		private Xfmpc.Interface @interface;
 		private Xfmpc.ExtendedInterface extended_interface;
+		private Xfmpc.PanedInterface paned_interface;
 
+		private Gtk.HPaned paned_box;
 		private Gtk.VBox vbox;
 		private Gtk.ActionGroup action_group;
 		private Gtk.UIManager ui_manager;
@@ -59,12 +61,11 @@
 </ui>
 """;
 
-		construct {
-			mpdclient = Xfmpc.Mpdclient.get ();
-			preferences = Xfmpc.Preferences.get ();
-			unowned Preferences preferences1 = Xfmpc.Preferences.get ();
+		public MainWindow () {
+			this.mpdclient = Xfmpc.Mpdclient.get ();
+			this.preferences = Xfmpc.Preferences.get ();
 
-  	  	  	/* Window */
+			/* Window */
 			set_default_icon_name ("xfmpc");
 			set_icon_name ("stock_volume");
 			set_title (Config.PACKAGE_NAME);
@@ -72,9 +73,6 @@
 			this.delete_event.connect (cb_window_closed);
 			this.window_state_event.connect (cb_window_state_event);
 
-			this.vbox = new Gtk.VBox (false, 0);
-			add (vbox);
-
 			if (this.preferences.last_window_posx != -1 && this.preferences.last_window_posy != -1)
 				move (this.preferences.last_window_posx, this.preferences.last_window_posy);
 			if (this.preferences.last_window_width != -1 && this.preferences.last_window_height != -1)
@@ -82,22 +80,35 @@
 			if (this.preferences.last_window_state_sticky == true)
 				stick ();
 
-  	  	  	/* Interface */
+			/* Paned */
+			paned_box = new Gtk.HPaned ();
+			//paned_box.position = this.preferences.last_window_width;
+			add (paned_box);
+
+			/* VBox */
+			this.vbox = new Gtk.VBox (false, 0);
+			paned_box.pack1 (vbox, false, false);
+
+			/* Interface */
 			this. at interface = new Xfmpc.Interface ();
 			this.vbox.pack_start (this. at interface, false, false, 4);
 
-  	  	  	/* Separator */
+			/* Separator */
 			var separator = new Gtk.HSeparator ();
 			this.vbox.pack_start (separator, false, false, 0);
 
-  	  	  	/* ExtendedInterface */
+			/* ExtendedInterface */
 			this.extended_interface = new Xfmpc.ExtendedInterface ();
 			this.vbox.pack_start (this.extended_interface, true, true, 0);
 
-  	  	  	/* Accelerators */
+			/* PanedInterface */
+			paned_interface = new Xfmpc.PanedInterface ();
+			this.paned_box.add2 (paned_interface);
+
+			/* Accelerators */
 			this.ui_manager = new Gtk.UIManager ();
 
-  	  	  	/* Action group */
+			/* Action group */
 			this.action_group = new Gtk.ActionGroup ("XfmpcMainWindow");
 			this.action_group.add_actions (this.action_entries, this);
 			this.action_group.add_toggle_actions (this.toggle_action_entries, this);
@@ -108,18 +119,18 @@
 				warning (e.message);
 			}
 
-  	  	  	/* Accel group */
+			/* Accel group */
 			var accel_group = this.ui_manager.get_accel_group ();
 			add_accel_group (accel_group);
 
-  	  	  	/* show-statusbar action */
+			/* show-statusbar action */
 			((Gtk.ToggleAction )(this.action_group.get_action ("view-statusbar"))).set_active (this.preferences.show_statusbar);
 
-  	  	  	/* === Signals === */
+			/* === Signals === */
 			this.mpdclient.playlist_changed.connect (cb_playlist_changed);
 			this.preferences.notify["show-statusbar"].connect (cb_show_statusbar_changed);
 
-  	  	  	/* === Timeout === */
+			/* === Timeout === */
 			Timeout.add (1000, refresh);
 		}
 
@@ -143,11 +154,11 @@
 			if (event.type != Gdk.EventType.WINDOW_STATE)
 				return false;
 
-  	  	  	/**
-   	   	   	 * Hiding the top level window will unstick it too, and send a
-   	   	   	 * window-state-event signal, so here we take the value only if
-   	   	   	 * the window is visible
-   	   	   	 **/
+			/**
+			 * Hiding the top level window will unstick it too, and send a
+			 * window-state-event signal, so here we take the value only if
+			 * the window is visible
+			 **/
 			if ((bool) event.changed_mask & Gdk.WindowState.STICKY && this.visible){
 				bool sticky;
 				if (((bool) event.new_window_state & Gdk.WindowState.STICKY) == false)
@@ -252,6 +263,30 @@
 			((Gtk.ToggleAction) action).set_active (active);
 			update_statusbar ();
 		}
+
+		/*private void add_paned_plugin (string name) {
+			PanedPlugin lyrics_plugin = this.registrar.load (name);
+			var vbox = new Gtk.VBox (true, 0);
+
+			if (lyrics_plugin == null) {
+				debug ("Can't load the plugin %s", name);
+				return;
+			}
+
+			plugins.set (name, vbox);
+
+			this.notebook.append_page (vbox, new Gtk.Label (lyrics_plugin.title));
+			lyrics_plugin.create_paned_widget (vbox);
+		}
+
+		private void remove_paned_plugin (string name) {
+			int i = this.notebook.page_num (this.plugins.get (name));
+
+			if (i == -1)
+				debug ("Can't remove the plugin %s", name);
+
+			this.notebook.remove_page (i);
+		}*/
 	}
 }
 

Modified: xfmpc/branches/xfmpc-plugins/src/main.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/main.vala	2009-07-26 10:21:25 UTC (rev 7838)
+++ xfmpc/branches/xfmpc-plugins/src/main.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -42,20 +42,21 @@
 		}
 
 		dst.set_enum (enum_value.value);
-  	}
+	}
 
 	public static int main (string[] args) {
 		Xfce.textdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALE_DIR, "UTF-8");
 
 		Gtk.init (ref args);
 
-  		GLib.Value.register_transform_func (typeof (string),
+
+		GLib.Value.register_transform_func (typeof (string),
 						    typeof (int),
 						    (GLib.ValueTransform) transform_string_to_int);
-  		GLib.Value.register_transform_func (typeof (string),
+		GLib.Value.register_transform_func (typeof (string),
 						    typeof (bool),
 						    (GLib.ValueTransform) transform_string_to_boolean);
-  		GLib.Value.register_transform_func (typeof (string),
+		GLib.Value.register_transform_func (typeof (string),
 						    typeof (Xfmpc.Preferences.SongFormat),
 						    (GLib.ValueTransform) transform_string_to_enum);
 

Added: xfmpc/branches/xfmpc-plugins/src/paned-interface.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/paned-interface.vala	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/src/paned-interface.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,69 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
+ *
+ *  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.
+ */
+
+using Gtk;
+
+namespace Xfmpc {
+
+	public class PanedInterface : VBox {
+
+		private unowned Xfmpc.Preferences preferences;
+		private unowned Xfmpc.PluginLoader plugin_loader;
+		private List<string> plugins;
+
+		private Gtk.Notebook notebook;
+
+		public PanedInterface () {
+			preferences = Xfmpc.Preferences.get ();
+			plugin_loader = Xfmpc.PluginLoader.get_default ();
+
+			notebook = new Gtk.Notebook ();
+			notebook.show_border = false;
+			//notebook.show_tabs = false;
+			base.add (notebook);
+
+			plugins = plugin_loader.list_plugins (typeof (Xfmpc.PanedPlugin));
+			foreach (string path in plugins) {
+				Xfmpc.PanedPlugin plugin = (Xfmpc.PanedPlugin)plugin_loader.new_object (path);
+				debug ("Load plugin %s", plugin.name);
+				var viewport = new Gtk.Viewport (null, null);
+				plugin.create_paned_widget (viewport);
+				add (viewport);
+			}
+		}
+
+		public new void add (Gtk.Widget widget) {
+			var scrolled_window = new Gtk.ScrolledWindow (null, null);
+			scrolled_window.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
+			scrolled_window.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
+			scrolled_window.shadow_type = Gtk.ShadowType.NONE;
+			scrolled_window.add (widget);
+			notebook.add (scrolled_window);
+			scrolled_window.show_all ();
+		}
+
+		public new void remove (Gtk.Widget widget) {
+			var scrolled_window = widget.get_parent ();
+			notebook.remove (scrolled_window);
+			scrolled_window.destroy ();
+		}
+
+	}
+
+}

Added: xfmpc/branches/xfmpc-plugins/src/plugin-interfaces.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/plugin-interfaces.vala	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/src/plugin-interfaces.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
+ *
+ *  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.
+ */
+
+using Gtk;
+
+namespace Xfmpc {
+
+	public abstract class BasePlugin : GLib.Object {
+		public unowned string name { get; set; }
+		public unowned string icon_name { get; set; }
+		public unowned string description { get; set; }
+		public unowned string version { get; set; }
+		public unowned string author { get; set; }
+		public unowned string title { get; set; }
+	}
+
+	public abstract class PanedPlugin : BasePlugin {
+		public abstract void create_paned_widget (Gtk.Bin bin);
+	}
+
+}

Added: xfmpc/branches/xfmpc-plugins/src/plugin-loader.vala
===================================================================
--- xfmpc/branches/xfmpc-plugins/src/plugin-loader.vala	                        (rev 0)
+++ xfmpc/branches/xfmpc-plugins/src/plugin-loader.vala	2009-07-26 10:41:23 UTC (rev 7839)
@@ -0,0 +1,116 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *  Copyright (c) 2009 Vincent Legout <vincent at xfce.org>
+ *
+ *  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.
+ */
+
+namespace Xfmpc {
+
+	public class PluginLoader : GLib.Object {
+
+		private List<string> plugin_paths;
+		private HashTable<string, Type> registered_types;
+
+		private delegate Type RegisterPluginFunction ();
+
+		construct {
+			assert (Module.supported ());
+
+			registered_types = new HashTable<string, Type> (GLib.str_hash, GLib.str_equal);
+
+			try {
+				string name;
+				var dir = Dir.open (Config.PLUGINDIR, 0);
+				while ((name = dir.read_name ()) != null) {
+					if (!name.has_suffix (Module.SUFFIX))
+						continue;
+
+					string path = "%s/%s".printf (Config.PLUGINDIR, name);
+					Module module = Module.open (path, ModuleFlags.BIND_LAZY);
+					if (module == null)
+						continue;
+
+					void* function;
+					module.symbol ("xfmpc_register_plugin", out function);
+					if (function == null) {
+						warning ("%s: Unable to lookup symbol xfmpc_register_function", path);
+						continue;
+					}
+
+					plugin_paths.append (path);
+				}
+			}
+			catch (Error e) {
+			}
+		}
+
+		private static PluginLoader singleton;
+		public static unowned PluginLoader get_default () {
+			if (singleton == null) {
+				singleton = new PluginLoader ();
+				singleton.add_weak_pointer (singleton);
+			}
+			else
+				singleton.ref ();
+
+			return singleton;
+		}
+
+		public List<string> list_plugins (GLib.Type type) {
+			List<string> list = null;
+			foreach (string path in plugin_paths) {
+				Type plugin_type = get_plugin_type (path);
+				if (plugin_type.parent () == type) {
+					list.append (path);
+				}
+			}
+			return list;
+		}
+
+		public Type get_plugin_type (string path) {
+			Type type = registered_types.lookup (path);
+			if (type != Type.INVALID)
+				return type;
+
+			Module module = Module.open (path, ModuleFlags.BIND_LAZY);
+			if (module == null)
+				return Type.INVALID;
+
+			void* function;
+			module.symbol ("xfmpc_register_plugin", out function);
+			if (function == null)
+				return Type.INVALID;
+
+			RegisterPluginFunction register_plugin = (RegisterPluginFunction)function;
+			type = register_plugin ();
+
+			if (type == Type.INVALID)
+				return Type.INVALID;
+
+			module.make_resident (); // Avoid module from getting closed
+			registered_types.insert (path, type);
+
+			return type;
+		}
+
+		public Xfmpc.BasePlugin? new_object (string path) {
+			Type type = get_plugin_type (path);
+			if (type == Type.INVALID)
+				return null;
+			return (Xfmpc.BasePlugin)GLib.Object.new (type);
+		}
+	}
+}




More information about the Goodies-commits mailing list