SF.net SVN: geany-plugins:[612] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Apr 29 18:07:44 UTC 2009


Revision: 612
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=612&view=rev
Author:   eht16
Date:     2009-04-29 18:07:43 +0000 (Wed, 29 Apr 2009)

Log Message:
-----------
Implement a notification area icon (systray) as part of the Addons plugin.

Modified Paths:
--------------
    trunk/addons/po/POTFILES.in
    trunk/addons/src/Makefile.am
    trunk/addons/src/addons.c
    trunk/wscript

Added Paths:
-----------
    trunk/addons/src/ao_systray.c
    trunk/addons/src/ao_systray.h

Modified: trunk/addons/po/POTFILES.in
===================================================================
--- trunk/addons/po/POTFILES.in	2009-04-27 16:34:51 UTC (rev 611)
+++ trunk/addons/po/POTFILES.in	2009-04-29 18:07:43 UTC (rev 612)
@@ -3,4 +3,5 @@
 src/addons.c
 src/ao_openuri.c
 src/ao_doclist.c
+src/ao_systray.c
 src/tasks.c

Modified: trunk/addons/src/Makefile.am
===================================================================
--- trunk/addons/src/Makefile.am	2009-04-27 16:34:51 UTC (rev 611)
+++ trunk/addons/src/Makefile.am	2009-04-29 18:07:43 UTC (rev 612)
@@ -1,6 +1,11 @@
 
 lib_LTLIBRARIES = addons.la
-addons_la_SOURCES = addons.c addons.h ao_doclist.c ao_doclist.h ao_openuri.c ao_openuri.h tasks.c tasks.h
+addons_la_SOURCES = \
+	addons.c addons.h \
+	ao_doclist.c ao_doclist.h \
+	ao_openuri.c ao_openuri.h \
+	ao_systray.c ao_systray.h \
+	tasks.c tasks.h
 addons_la_LDFLAGS = -module -avoid-version
 addons_la_LIBADD  = @GEANY_LIBS@  $(INTLLIBS)
 

Modified: trunk/addons/src/addons.c
===================================================================
--- trunk/addons/src/addons.c	2009-04-27 16:34:51 UTC (rev 611)
+++ trunk/addons/src/addons.c	2009-04-29 18:07:43 UTC (rev 612)
@@ -41,6 +41,7 @@
 
 #include "ao_doclist.h"
 #include "ao_openuri.h"
+#include "ao_systray.h"
 #include "tasks.h"
 
 
@@ -62,10 +63,12 @@
 	gboolean show_toolbar_doclist_item;
 	gboolean enable_openuri;
 	gboolean enable_tasks;
+	gboolean enable_systray;
 
 	/* instances and variables of components */
 	AoDocList *doclist;
 	AoOpenUri *openuri;
+	AoSystray *systray;
 } AddonsInfo;
 static AddonsInfo *ao_info = NULL;
 
@@ -124,12 +127,15 @@
 		"addons", "enable_openuri", FALSE);
 	ao_info->enable_tasks = utils_get_setting_boolean(config,
 		"addons", "enable_tasks", TRUE);
+	ao_info->enable_systray = utils_get_setting_boolean(config,
+		"addons", "enable_systray", FALSE);
 
 	main_locale_init(LOCALEDIR, GETTEXT_PACKAGE);
 	plugin_module_make_resident(geany_plugin);
 
 	ao_info->doclist = ao_doc_list_new(ao_info->show_toolbar_doclist_item);
 	ao_info->openuri = ao_open_uri_new(ao_info->enable_openuri);
+	ao_info->systray = ao_systray_new(ao_info->enable_systray);
 
 	tasks_set_enable(ao_info->enable_tasks);
 }
@@ -149,16 +155,19 @@
 			g_object_get_data(G_OBJECT(dialog), "check_openuri"))));
 		ao_info->enable_tasks = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
 			g_object_get_data(G_OBJECT(dialog), "check_tasks"))));
+		ao_info->enable_systray = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
+			g_object_get_data(G_OBJECT(dialog), "check_systray"))));
 
 		g_key_file_load_from_file(config, ao_info->config_file, G_KEY_FILE_NONE, NULL);
 		g_key_file_set_boolean(config, "addons",
 			"show_toolbar_doclist_item", ao_info->show_toolbar_doclist_item);
 		g_key_file_set_boolean(config, "addons", "enable_openuri", ao_info->enable_openuri);
 		g_key_file_set_boolean(config, "addons", "enable_tasks", ao_info->enable_tasks);
+		g_key_file_set_boolean(config, "addons", "enable_systray", ao_info->enable_systray);
 
 		g_object_set(ao_info->doclist, "enable-doclist", ao_info->show_toolbar_doclist_item, NULL);
 		g_object_set(ao_info->openuri, "enable-openuri", ao_info->enable_openuri, NULL);
-
+		g_object_set(ao_info->systray, "enable-systray", ao_info->enable_systray, NULL);
 		tasks_set_enable(ao_info->enable_tasks);
 
 		if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0)
@@ -181,7 +190,7 @@
 
 GtkWidget *plugin_configure(GtkDialog *dialog)
 {
-	GtkWidget *vbox, *check_doclist, *check_openuri, *check_tasks;
+	GtkWidget *vbox, *check_doclist, *check_openuri, *check_tasks, *check_systray;
 
 	vbox = gtk_vbox_new(FALSE, 6);
 
@@ -204,13 +213,24 @@
 		ao_info->enable_tasks);
 	gtk_box_pack_start(GTK_BOX(vbox), check_tasks, FALSE, FALSE, 3);
 
+	check_systray = gtk_check_button_new_with_label(
+		_("Show status icon in the Notification Area"));
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_systray),
+		ao_info->enable_systray);
+	gtk_box_pack_start(GTK_BOX(vbox), check_systray, FALSE, FALSE, 3);
+
 	g_object_set_data(G_OBJECT(dialog), "check_doclist", check_doclist);
 	g_object_set_data(G_OBJECT(dialog), "check_openuri", check_openuri);
 	g_object_set_data(G_OBJECT(dialog), "check_tasks", check_tasks);
+	g_object_set_data(G_OBJECT(dialog), "check_systray", check_systray);
 	g_signal_connect(dialog, "response", G_CALLBACK(ao_configure_response_cb), NULL);
 
 	gtk_widget_show_all(vbox);
 
+#if ! GTK_CHECK_VERSION(2, 10, 0)
+	gtk_widget_hide(check_systray);
+#endif
+
 	return vbox;
 }
 
@@ -219,6 +239,7 @@
 {
 	g_object_unref(ao_info->doclist);
 	g_object_unref(ao_info->openuri);
+	g_object_unref(ao_info->systray);
 
 	tasks_set_enable(FALSE);
 

Added: trunk/addons/src/ao_systray.c
===================================================================
--- trunk/addons/src/ao_systray.c	                        (rev 0)
+++ trunk/addons/src/ao_systray.c	2009-04-29 18:07:43 UTC (rev 612)
@@ -0,0 +1,234 @@
+/*
+ *      ao_systray.c - this file is part of Addons, a Geany plugin
+ *
+ *      Copyright 2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+ *
+ *      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.
+ */
+
+
+#include "geany.h"
+#include "support.h"
+
+#include "ui_utils.h"
+
+#include "plugindata.h"
+#include "geanyfunctions.h"
+
+#include "addons.h"
+#include "ao_systray.h"
+
+
+typedef struct _AoSystrayPrivate			AoSystrayPrivate;
+
+#define AO_SYSTRAY_GET_PRIVATE(obj)		(G_TYPE_INSTANCE_GET_PRIVATE((obj),\
+			AO_SYSTRAY_TYPE, AoSystrayPrivate))
+
+struct _AoSystray
+{
+	GObject parent;
+};
+
+struct _AoSystrayClass
+{
+	GObjectClass parent_class;
+};
+
+struct _AoSystrayPrivate
+{
+	gboolean enable_systray;
+
+	GtkStatusIcon *icon;
+	GtkWidget *popup_menu;
+};
+
+enum
+{
+	PROP_0,
+	PROP_ENABLE_SYSTRAY,
+};
+
+G_DEFINE_TYPE(AoSystray, ao_systray, G_TYPE_OBJECT);
+
+
+static void ao_systray_finalize(GObject *object)
+{
+#if GTK_CHECK_VERSION(2, 10, 0)
+	AoSystrayPrivate *priv = AO_SYSTRAY_GET_PRIVATE(object);
+
+	g_object_unref(priv->icon);
+	gtk_widget_destroy(priv->popup_menu);
+#endif
+
+	G_OBJECT_CLASS(ao_systray_parent_class)->finalize(object);
+}
+
+
+static void ao_systray_set_property(GObject *object, guint prop_id,
+									const GValue *value, GParamSpec *pspec)
+{
+	AoSystrayPrivate *priv = AO_SYSTRAY_GET_PRIVATE(object);
+
+	switch (prop_id)
+	{
+		case PROP_ENABLE_SYSTRAY:
+			priv->enable_systray = g_value_get_boolean(value);
+#if GTK_CHECK_VERSION(2, 10, 0)
+			gtk_status_icon_set_visible(priv->icon, priv->enable_systray);
+#endif
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+			break;
+	}
+}
+
+
+static void ao_systray_class_init(AoSystrayClass *klass)
+{
+	GObjectClass *g_object_class;
+
+	g_object_class = G_OBJECT_CLASS(klass);
+
+	g_object_class->finalize = ao_systray_finalize;
+	g_object_class->set_property = ao_systray_set_property;
+
+	g_type_class_add_private((gpointer)klass, sizeof(AoSystrayPrivate));
+
+	g_object_class_install_property(g_object_class,
+									PROP_ENABLE_SYSTRAY,
+									g_param_spec_boolean(
+									"enable-systray",
+									"enable-systray",
+									"Whether to show an icon in the notification area",
+									TRUE,
+									G_PARAM_WRITABLE));
+}
+
+
+#if GTK_CHECK_VERSION(2, 10, 0)
+static void icon_activate_cb(GtkStatusIcon *status_icon, gpointer data)
+{
+	if (gtk_window_is_active(GTK_WINDOW(geany->main_widgets->window)))
+	{
+		gtk_window_iconify(GTK_WINDOW(geany->main_widgets->window));
+		gtk_window_set_skip_taskbar_hint(GTK_WINDOW(geany->main_widgets->window), TRUE);
+		gtk_window_set_skip_pager_hint(GTK_WINDOW(geany->main_widgets->window), TRUE);
+	}
+	else
+	{
+		gtk_window_present(GTK_WINDOW(geany->main_widgets->window));
+		gtk_window_set_skip_taskbar_hint(GTK_WINDOW(geany->main_widgets->window), FALSE);
+		gtk_window_set_skip_pager_hint(GTK_WINDOW(geany->main_widgets->window), FALSE);
+#ifdef G_OS_WIN32
+		// ensure that the window is displayed at the top
+		gdk_window_show(geany->main_widgets->window->window);
+#endif
+	}
+}
+
+
+static void icon_popup_menu_cmd_clicked_cb(GtkMenuItem *item, gpointer data)
+{
+	g_signal_emit_by_name(ui_lookup_widget(geany->main_widgets->window, data), "activate");
+}
+
+
+static gboolean icon_quit_cb(gpointer data)
+{
+	g_signal_emit_by_name(geany->main_widgets->window, "delete-event", NULL);
+
+	return FALSE;
+}
+
+
+static void icon_popup_quit_clicked_cb(GtkMenuItem *item, gpointer data)
+{
+	/* We need to delay emitting the "delete-event" signal a bit to give GTK a chance to finish
+	 * processing this signal otherwise we would crash. */
+	g_idle_add(icon_quit_cb, NULL);
+}
+
+
+static void icon_popup_menu_cb(GtkStatusIcon *status_icon, guint button, guint activate_time,
+							   gpointer data)
+{
+	AoSystrayPrivate *priv = AO_SYSTRAY_GET_PRIVATE(data);
+
+	if (button == 3)
+		gtk_menu_popup(GTK_MENU(priv->popup_menu), NULL, NULL, NULL, NULL, button, activate_time);
+}
+#endif
+
+
+static void ao_systray_init(AoSystray *self)
+{
+#if GTK_CHECK_VERSION(2, 10, 0)
+	AoSystrayPrivate *priv = AO_SYSTRAY_GET_PRIVATE(self);
+	GtkWidget *item;
+
+	priv->icon = gtk_status_icon_new_from_pixbuf(gtk_window_get_icon(
+		GTK_WINDOW(geany->main_widgets->window)));
+
+#if GTK_CHECK_VERSION(2, 16, 0)
+	gtk_status_icon_set_tooltip(priv->icon, "Geany");
+#else
+	gtk_status_icon_set_tooltip_text(priv->icon, "Geany");
+#endif
+
+	priv->popup_menu = gtk_menu_new();
+
+	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, NULL);
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+	g_signal_connect((gpointer) item, "activate",
+		G_CALLBACK(icon_popup_menu_cmd_clicked_cb), "menu_open1");
+
+	item = gtk_image_menu_item_new_from_stock(GEANY_STOCK_SAVE_ALL, NULL);
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+	g_signal_connect((gpointer) item, "activate",
+		G_CALLBACK(icon_popup_menu_cmd_clicked_cb), "menu_save_all1");
+
+	item = gtk_separator_menu_item_new();
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+
+	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES, NULL);
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+	g_signal_connect((gpointer) item, "activate",
+		G_CALLBACK(icon_popup_menu_cmd_clicked_cb), "preferences1");
+
+	item = gtk_separator_menu_item_new();
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+
+	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
+	gtk_widget_show(item);
+	gtk_container_add(GTK_CONTAINER(priv->popup_menu), item);
+	g_signal_connect((gpointer) item, "activate", G_CALLBACK(icon_popup_quit_clicked_cb), NULL);
+
+	g_signal_connect(priv->icon, "activate", G_CALLBACK(icon_activate_cb), NULL);
+	g_signal_connect(priv->icon, "popup-menu", G_CALLBACK(icon_popup_menu_cb), self);
+#endif
+}
+
+
+AoSystray *ao_systray_new(gboolean enable)
+{
+	return g_object_new(AO_SYSTRAY_TYPE, "enable-systray", enable, NULL);
+}
+


Property changes on: trunk/addons/src/ao_systray.c
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: trunk/addons/src/ao_systray.h
===================================================================
--- trunk/addons/src/ao_systray.h	                        (rev 0)
+++ trunk/addons/src/ao_systray.h	2009-04-29 18:07:43 UTC (rev 612)
@@ -0,0 +1,46 @@
+/*
+ *      ao_systray.h - this file is part of Addons, a Geany plugin
+ *
+ *      Copyright 2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+ *
+ *      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 __AO_SYSTRAY_H__
+#define __AO_SYSTRAY_H__
+
+
+G_BEGIN_DECLS
+
+#define AO_SYSTRAY_TYPE				(ao_systray_get_type())
+#define AO_SYSTRAY(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj),\
+			AO_SYSTRAY_TYPE, AoSystray))
+#define AO_SYSTRAY_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass),\
+			AO_SYSTRAY_TYPE, AoSystrayClass))
+#define IS_AO_SYSTRAY(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj),\
+			AO_SYSTRAY_TYPE))
+#define IS_AO_SYSTRAY_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass),\
+			AO_SYSTRAY_TYPE))
+
+typedef struct _AoSystray			AoSystray;
+typedef struct _AoSystrayClass		AoSystrayClass;
+
+GType		ao_systray_get_type		(void);
+AoSystray*	ao_systray_new			(gboolean enable);
+
+G_END_DECLS
+
+#endif /* __AO_SYSTRAY_H__ */


Property changes on: trunk/addons/src/ao_systray.h
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Modified: trunk/wscript
===================================================================
--- trunk/wscript	2009-04-27 16:34:51 UTC (rev 611)
+++ trunk/wscript	2009-04-29 18:07:43 UTC (rev 612)
@@ -62,7 +62,7 @@
 plugins = [
 	Plugin('addons',
 		 [ 'addons/src/addons.c', 'addons/src/ao_doclist.c', 'addons/src/ao_openuri.c',
-		   'addons/src/tasks.c' ],
+		   'addons/src/ao_systray.c', 'addons/src/tasks.c' ],
 		 [ 'addons', 'addons/src' ],
 		 '0.2'),
 	Plugin('externdbg',


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list