[Xfce4-commits] <xfce4-notes-plugin:master> Do as for Clipman, let the plugin be a standalone app

Mike Massonnet noreply at xfce.org
Tue Dec 1 23:04:01 CET 2009


Updating branch refs/heads/master
         to 65ef5662c844a5b01b7c9b3ca438d88abe1bd0e1 (commit)
       from 6940936c4ff4927315fd79a39769e49dcf9a4a31 (commit)

commit 65ef5662c844a5b01b7c9b3ca438d88abe1bd0e1
Author: Mike Massonnet <mmassonnet at gmail.com>
Date:   Tue Dec 1 21:35:31 2009 +0100

    Do as for Clipman, let the plugin be a standalone app

 ChangeLog                                          |   13 ++
 panel-plugin/Makefile.am                           |   62 ++++++++--
 panel-plugin/application.vala                      |   42 ++++++
 panel-plugin/{main.vala => main-panel-plugin.vala} |    4 +
 panel-plugin/main-status-icon.vala                 |  139 ++++++++++++++++++++
 5 files changed, 251 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ac07cdf..6661699 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-12-01  Mike Massonnet <mmassonnet at xfce.org>
 
+Do as for Clipman, let the plugin be a standalone app
+	* panel-plugin/Makefile.am:
+	  - Update Makefile to build both plugin and binary C.
+	* panel-plugin/application.vala(open_about_dialog):
+	  - Add public dialog to show an about dialog.
+	* panel-plugin/main-panel-plugin.vala:
+	  - Rename main.vala to main-panel-plugin.vala.
+	  - Show about item in panel plugin context menu.
+	* panel-plugin/main-status-icon.vala:
+	  - New main source to build binary xfce4-notes.
+
+2009-12-01  Mike Massonnet <mmassonnet at xfce.org>
+
 Add context menu for quick access to window list
 	* panel-plugin/application.vala:
 	  - New public function context_menu. It builds a menu to be used for
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 320121b..0a3057f 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -58,26 +58,38 @@ notes_VALASOURCES =							\
 	hypertextview.vala						\
 	note.vala							\
 	window.vala							\
-	application.vala						\
-	main.vala
+	application.vala
+
+notes_panel_plugin_VALASOURCES =					\
+	main-panel-plugin.vala
+
+notes_status_icon_VALASOURCES =						\
+	main-status-icon.vala
 
 notes_VALABUILTSOURCES = $(notes_VALASOURCES:.vala=.c)
+notes_panel_plugin_VALABUILTSOURCES = $(notes_panel_plugin_VALASOURCES:.vala=.c)
+notes_status_icon_VALABUILTSOURCES = $(notes_status_icon_VALASOURCES:.vala=.c)
 
 if MAINTAINER_MODE
 if HAVE_LIBXFCE4PANEL47
 DEFINES=-D HAVE_LIBXFCE4PANEL47
-PACKAGES=--pkg=libxfcegui4-1.0 --pkg=libxfce4panel-1.0
+PACKAGES=--pkg=libxfcegui4-1.0 --pkg=gtk+-2.0
 else
-PACKAGES=--pkg=libxfce4panel-1.0
+PACKAGES=--pkg=gtk+-2.0
 endif
 BUILT_SOURCES = vala.stamp
-vala.stamp: $(notes_VALASOURCES)
-	$(VALAC) $(DEFINES) --vapidir=$(srcdir) --pkg=config --pkg=color --pkg=popup --pkg=libxfconf-0 $(PACKAGES) $^ -C
+vala.stamp: $(notes_VALASOURCES) $(notes_panel_plugin_VALASOURCES) $(notes_status_icon_VALASOURCES)
+	$(VALAC) $(DEFINES) --vapidir=$(srcdir) --pkg=config --pkg=color --pkg=popup	\
+		 --pkg=libxfconf-0 $(PACKAGES) --pkg=libxfce4panel-1.0			\
+		 $(notes_VALASOURCES) $(notes_panel_plugin_VALASOURCES) -C
+	$(VALAC) $(DEFINES) --vapidir=$(srcdir) --pkg=config --pkg=color --pkg=popup	\
+		 --pkg=libxfconf-0 --pkg=libxfce4util-1.0 $(PACKAGES)						\
+		 $(notes_VALASOURCES) $(notes_status_icon_VALASOURCES) -C
 	touch $@
 endif
 
 #
-# Plugin
+# Panel plugin
 #
 
 if HAVE_LIBXFCE4PANEL47
@@ -90,7 +102,8 @@ libnotes_la_SOURCES =							\
 	color.h								\
 	popup.c								\
 	popup.h								\
-	$(notes_VALABUILTSOURCES)
+	$(notes_VALABUILTSOURCES)					\
+	$(notes_panel_plugin_VALABUILTSOURCES)
 
 libnotes_la_CFLAGS =							\
 	@LIBX11_CFLAGS@							\
@@ -116,7 +129,8 @@ xfce4_notes_plugin_SOURCES =						\
 	color.h								\
 	popup.c								\
 	popup.h								\
-	$(notes_VALABUILTSOURCES)
+	$(notes_VALABUILTSOURCES)					\
+	$(notes_panel_plugin_VALABUILTSOURCES)
 
 xfce4_notes_plugin_CFLAGS =						\
 	@LIBX11_CFLAGS@							\
@@ -135,6 +149,34 @@ xfce4_notes_plugin_LDADD =						\
 endif
 
 #
+# Status icon
+#
+
+bin_PROGRAMS += xfce4-notes
+
+xfce4_notes_SOURCES =							\
+	color.c								\
+	color.h								\
+	popup.c								\
+	popup.h								\
+	$(notes_VALABUILTSOURCES)					\
+	$(notes_status_icon_VALABUILTSOURCES)
+
+xfce4_notes_CFLAGS =							\
+	@LIBX11_CFLAGS@							\
+	@GTK_CFLAGS@							\
+	@LIBXFCE4UTIL_CFLAGS@						\
+	@LIBXFCEGUI4_CFLAGS@						\
+	@XFCONF_CFLAGS@
+
+xfce4_notes_LDADD =							\
+	@LIBX11_LIBS@							\
+	@GTK_LIBS@							\
+	@LIBXFCE4UTIL_LIBS@						\
+	@LIBXFCEGUI4_LIBS@						\
+	@XFCONF_LIBS@
+
+#
 # Plugin desktop file
 #
 
@@ -162,6 +204,8 @@ endif
 EXTRA_DIST =								\
 	$(notes_VAPISOURCES)						\
 	$(notes_VALASOURCES)						\
+	$(notes_panel_plugin_VALASOURCES)				\
+	$(notes_status_icon_VALASOURCES)				\
 	$(desktop_in_in_files)
 
 if MAINTAINER_MODE
diff --git a/panel-plugin/application.vala b/panel-plugin/application.vala
index 19f4f6d..38032ac 100644
--- a/panel-plugin/application.vala
+++ b/panel-plugin/application.vala
@@ -494,6 +494,48 @@ namespace Xnp {
 		}
 
 		/**
+		 * open_about_dialog:
+		 *
+		 * Open the about dialog.
+		 */
+		public void open_about_dialog () {
+			Gtk.AboutDialog.set_url_hook ((dialog, uri) => {
+					string command;
+					try {
+						command = "exo-open %s".printf (uri);
+						Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), command);
+						return;
+					} catch (GLib.Error e) {
+					}
+					try {
+						command = "firefox %s".printf (uri);
+						Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), command);
+						return;
+					} catch (GLib.Error e) {
+					}
+				});
+
+			string[] authors = {
+					"(c) 2006-2009 Mike Massonnet",
+					"(c) 2003 Jakob Henriksson",
+					null
+				};
+
+			Gtk.show_about_dialog (null,
+				"program-name", _("Notes"),
+				"logo-icon-name", "xfce4-notes-plugin",
+				"comments", _("Ideal for your quick notes"),
+				"version", Config.PACKAGE_VERSION,
+				"copyright", "Copyright © 2003-2009 The Xfce development team",
+				"license", Xfce.get_license_text (Xfce.LicenseTextType.GPL),
+				"website", "http://goodies.xfce.org/projects/panel-plugins/xfce4-notes-plugin",
+				"website-label", "goodies.xfce.org",
+				"authors", authors,
+				"translator-credits", _("translator-credits"),
+				null);
+		}
+
+		/**
 		 * context_menu:
 		 *
 		 * Provides a GtkMenu to be used for right click context menus
diff --git a/panel-plugin/main.vala b/panel-plugin/main-panel-plugin.vala
similarity index 97%
rename from panel-plugin/main.vala
rename to panel-plugin/main-panel-plugin.vala
index 7da7847..ba83fc9 100644
--- a/panel-plugin/main.vala
+++ b/panel-plugin/main-panel-plugin.vala
@@ -71,6 +71,7 @@ public class NotesPlugin : GLib.Object {
 		panel_plugin.add_action_widget (button);
 		panel_plugin.set_tooltip_text (_("Notes"));
 		panel_plugin.menu_show_configure ();
+		panel_plugin.menu_show_about ();
 
 		var mi = new Gtk.MenuItem.with_mnemonic (_("_Go"));
 		var menu = application.context_menu ();
@@ -99,6 +100,9 @@ public class NotesPlugin : GLib.Object {
 		panel_plugin.configure_plugin += () => {
 			application.open_settings_dialog ();
 		};
+		panel_plugin.about += () => {
+			application.open_about_dialog ();
+		};
 	}
 
 	/**
diff --git a/panel-plugin/main-status-icon.vala b/panel-plugin/main-status-icon.vala
new file mode 100644
index 0000000..66dd058
--- /dev/null
+++ b/panel-plugin/main-status-icon.vala
@@ -0,0 +1,139 @@
+/*
+ *  Notes - panel plugin for Xfce Desktop Environment
+ *  Copyright (C) 2009  Mike Massonnet <mmassonnet 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 St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+using Config;
+using Xfconf;
+using Xfce;
+using Gtk;
+
+public class Notes : GLib.Object {
+
+	private Gtk.Invisible invisible;
+	private Gtk.StatusIcon status_icon;
+	private Xnp.Application application;
+	private Gtk.Menu context_menu;
+
+	~NotesPlugin () {
+		application.save_windows_configuration ();
+		application.save_notes ();
+		// Destroy application before calling Xfconf.shutdown()
+		application = null;
+		Xfconf.shutdown ();
+	}
+
+	public Notes () {
+		Xfce.textdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALE_DIR);
+		try {
+			Xfconf.init ();
+		}
+		catch (Xfconf.Error e) {
+			warning ("%s", e.message);
+		}
+
+		var save_location = Xfce.Resource.save_location (Xfce.ResourceType.CONFIG, "xfce4/xfce4-notes.rc", true);
+		application = new Xnp.Application (save_location);
+
+		status_icon = new Gtk.StatusIcon.from_icon_name ("xfce4-notes-plugin");
+		status_icon.set_tooltip_text (_("Notes"));
+		Timeout.add_seconds (60, () => {
+				if (!status_icon.is_embedded ()) {
+					warning ("Status Icon is not embedded");
+					Gtk.main_quit ();
+				}
+				return false;
+			});
+		status_icon.activate += () => { application.show_hide_notes (); };
+		context_menu = build_context_menu ();
+		status_icon.popup_menu += () => {
+			context_menu.popup (null, null, status_icon.position_menu, 0, Gtk.get_current_event_time ());
+		};
+
+		set_x_selection ();
+	}
+
+	/**
+	 * set_x_selection:
+	 *
+	 * Set an X selection to listen to for the popup command.
+	 */
+	private bool set_x_selection () {
+		invisible = new Gtk.Invisible ();
+		if (!Xnp.Popup.set_x_selection (invisible)) {
+			return false;
+		}
+		invisible.client_event += (w, event) => {
+			if (Xnp.Popup.get_message_from_event (event) == "SHOW_HIDE") {
+				application.show_hide_notes ();
+				return true;
+			}
+			return false;
+		};
+		return true;
+	}
+
+	/**
+	 * build_context_menu:
+	 *
+	 * Builds the context menu for right click on status icon.
+	 */
+	private Gtk.Menu build_context_menu () {
+		var menu = new Gtk.Menu ();
+
+                var mi = new Gtk.MenuItem.with_mnemonic (_("_Go"));
+                var menu_go = application.context_menu ();
+                mi.set_submenu (menu_go);
+                menu.append (mi);
+
+		mi = new Gtk.SeparatorMenuItem ();
+		menu.append (mi);
+
+		mi = new Gtk.ImageMenuItem.from_stock (Gtk.STOCK_PROPERTIES, null);
+		mi.activate += () => { application.open_settings_dialog (); };
+		menu.append (mi);
+
+		mi = new Gtk.ImageMenuItem.from_stock (Gtk.STOCK_ABOUT, null);
+		mi.activate += () => { application.open_about_dialog (); };
+		menu.append (mi);
+
+		mi = new Gtk.SeparatorMenuItem ();
+		menu.append (mi);
+
+		mi = new Gtk.ImageMenuItem.from_stock (Gtk.STOCK_REMOVE, null);
+		mi.activate += () => {
+			// Set autostart file hidden
+			Gtk.main_quit ();
+		};
+		menu.append (mi);
+
+		menu.show_all ();
+
+		return menu;
+	}
+
+	public static int main (string[] args) {
+		Gtk.init (ref args);
+		GLib.Environment.set_application_name (_("Notes"));
+		var notes = new Notes ();
+		// Install initial autostart file
+		//Xfce.Autostart.set ("Notes", "xfce4-notes", true);
+		Gtk.main ();
+		notes = null;
+		return 0;
+	}
+}



More information about the Xfce4-commits mailing list