← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-application/build-menu-from-desktop into lp:indicator-application

 

Ted Gould has proposed merging lp:~ted/indicator-application/build-menu-from-desktop into lp:indicator-application with lp:~ted/indicator-application/property-for-dbus-stuff as a prerequisite.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


A function to pull the desktop file entries and make them into a menu so that applications can easily replace their static items with "dynamic" ones if they don't want them to change.
-- 
https://code.launchpad.net/~ted/indicator-application/build-menu-from-desktop/+merge/40689
Your team ayatana-commits is subscribed to branch lp:indicator-application.
=== modified file 'configure.ac'
--- configure.ac	2010-09-22 16:13:14 +0000
+++ configure.ac	2010-11-12 04:42:06 +0000
@@ -52,6 +52,14 @@
 AC_SUBST(INDICATOR_CFLAGS)
 AC_SUBST(INDICATOR_LIBS)
 
+PKG_CHECK_MODULES(LIBRARY, gtk+-2.0 >= $GTK_REQUIRED_VERSION
+                           indicator >= $INDICATOR_REQUIRED_VERSION
+                           dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION
+                           dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION)
+
+AC_SUBST(LIBRARY_CFLAGS)
+AC_SUBST(LIBRARY_LIBS)
+
 ###########################
 # GObject Introspection
 ###########################

=== modified file 'docs/reference/libappindicator-sections.txt'
--- docs/reference/libappindicator-sections.txt	2010-08-10 20:33:09 +0000
+++ docs/reference/libappindicator-sections.txt	2010-11-12 04:42:06 +0000
@@ -38,5 +38,6 @@
 app_indicator_get_label
 app_indicator_get_label_guide
 app_indicator_get_ordering_index
+app_indicator_build_menu_from_desktop
 </SECTION>
 

=== modified file 'src/Makefile.am'
--- src/Makefile.am	2010-08-10 21:59:25 +0000
+++ src/Makefile.am	2010-11-12 04:42:06 +0000
@@ -108,12 +108,12 @@
 	-export-symbols-regex "^[^_d].*"
 
 libappindicator_la_CFLAGS = \
-	$(INDICATOR_CFLAGS) \
+	$(LIBRARY_CFLAGS) \
 	-Wall -Werror \
 	-DG_LOG_DOMAIN=\"libappindicator\"
 
 libappindicator_la_LIBADD = \
-	$(INDICATOR_LIBS)
+	$(LIBRARY_LIBS)
 
 ##################################
 # DBus Specs

=== modified file 'src/app-indicator.c'
--- src/app-indicator.c	2010-11-12 04:42:06 +0000
+++ src/app-indicator.c	2010-11-12 04:42:06 +0000
@@ -38,6 +38,8 @@
 #include <libdbusmenu-glib/server.h>
 #include <libdbusmenu-gtk/client.h>
 
+#include <libindicator/indicator-desktop-shortcuts.h>
+
 #include "app-indicator.h"
 #include "app-indicator-enum-types.h"
 #include "application-service-marshal.h"
@@ -89,6 +91,9 @@
 	DBusGProxy           *watcher_proxy;
 	DBusGConnection      *connection;
 	DBusGProxy *          dbus_proxy;
+
+	/* Might be used */
+	IndicatorDesktopShortcuts * shorties;
 };
 
 /* Signals Stuff */
@@ -566,6 +571,8 @@
 	priv->status_icon = NULL;
 	priv->fallback_timer = 0;
 
+	priv->shorties = NULL;
+
 	/* Put the object on DBus */
 	GError * error = NULL;
 	priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
@@ -592,6 +599,11 @@
 	AppIndicator *self = APP_INDICATOR (object);
 	AppIndicatorPrivate *priv = self->priv;
 
+	if (priv->shorties != NULL) {
+		g_object_unref(G_OBJECT(priv->shorties));
+		priv->shorties = NULL;
+	}
+
 	if (priv->status != APP_INDICATOR_STATUS_PASSIVE) {
 		app_indicator_set_status(self, APP_INDICATOR_STATUS_PASSIVE);
 	}
@@ -2134,3 +2146,82 @@
 	}
 }
 
+#define APP_INDICATOR_SHORTY_NICK "app-indicator-shorty-nick"
+
+/* Callback when an item from the desktop shortcuts gets
+   called. */
+static void
+shorty_activated_cb (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data)
+{
+	gchar * nick = g_object_get_data(G_OBJECT(mi), APP_INDICATOR_SHORTY_NICK);
+	g_return_if_fail(nick != NULL);
+
+	g_return_if_fail(IS_APP_INDICATOR(user_data));
+	AppIndicator * self = APP_INDICATOR(user_data);
+	AppIndicatorPrivate *priv = self->priv;
+
+	g_return_if_fail(priv->shorties != NULL);
+
+	indicator_desktop_shortcuts_nick_exec(priv->shorties, nick);
+
+	return;
+}
+
+/**
+	app_indicator_build_menu_from_desktop:
+	@self: The #AppIndicator object to use
+	@desktop_file: A path to the desktop file to build the menu from
+	@desktop_profile: Which entries should be used from the desktop file
+
+	This function allows for building the Application Indicator menu
+	from a static desktop file.
+*/
+void
+app_indicator_build_menu_from_desktop (AppIndicator * self, const gchar * desktop_file, const gchar * desktop_profile)
+{
+	g_return_if_fail(IS_APP_INDICATOR(self));
+	AppIndicatorPrivate *priv = self->priv;
+
+	/* Build a new shortcuts object */
+	if (priv->shorties != NULL) {
+		g_object_unref(priv->shorties);
+		priv->shorties = NULL;
+	}
+	priv->shorties = indicator_desktop_shortcuts_new(desktop_file, desktop_profile);
+	g_return_if_fail(priv->shorties != NULL);
+
+	const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(priv->shorties);
+	int nick_num;
+
+	/* Place the items on a dbusmenu */
+	DbusmenuMenuitem * root = dbusmenu_menuitem_new();
+
+	for (nick_num = 0; nicks[nick_num] != NULL; nick_num++) {
+		DbusmenuMenuitem * item = dbusmenu_menuitem_new();
+		g_object_set_data(G_OBJECT(item), APP_INDICATOR_SHORTY_NICK, (gpointer)nicks[nick_num]);
+
+		gchar * name = indicator_desktop_shortcuts_nick_get_name(priv->shorties, nicks[nick_num]);
+		dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, name);
+		g_free(name);
+
+		g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(shorty_activated_cb), self);
+
+		dbusmenu_menuitem_child_append(root, item);
+	}
+
+	/* Swap it if needed */
+	if (priv->menuservice == NULL) {
+		gchar * path = g_strdup_printf(DEFAULT_ITEM_PATH "/%s/Menu", priv->clean_id);
+		priv->menuservice = dbusmenu_server_new (path);
+		g_free(path);
+	}
+
+	dbusmenu_server_set_root (priv->menuservice, root);
+
+	if (priv->menu != NULL) {
+		g_object_unref(G_OBJECT(priv->menu));
+		priv->menu = NULL;
+	}
+
+	return;
+}

=== modified file 'src/app-indicator.h'
--- src/app-indicator.h	2010-08-10 19:17:42 +0000
+++ src/app-indicator.h	2010-11-12 04:42:06 +0000
@@ -280,6 +280,11 @@
 const gchar *                   app_indicator_get_label_guide    (AppIndicator *self);
 guint32                         app_indicator_get_ordering_index (AppIndicator *self);
 
+/* Helpers */
+void                            app_indicator_build_menu_from_desktop (AppIndicator * self,
+                                                                  const gchar * desktop_file,
+                                                                  const gchar * desktop_profile);
+
 G_END_DECLS
 
 /**

=== modified file 'tests/Makefile.am'
--- tests/Makefile.am	2010-07-12 18:55:08 +0000
+++ tests/Makefile.am	2010-11-12 04:42:06 +0000
@@ -13,7 +13,9 @@
 TESTS =
 DISTCLEANFILES = $(TESTS)
 
-EXTRA_DIST = run-xvfb.sh
+EXTRA_DIST = \
+	run-xvfb.sh \
+	test-libappindicator.desktop
 
 #########################################
 ##  test-libappindicator
@@ -24,6 +26,7 @@
 
 test_libappindicator_CFLAGS = \
 	$(INDICATOR_CFLAGS) \
+	-DSRCDIR="\"$(srcdir)\"" \
 	-Wall -Werror \
 	-I$(top_srcdir)/src
 

=== modified file 'tests/test-libappindicator.c'
--- tests/test-libappindicator.c	2010-11-12 04:42:06 +0000
+++ tests/test-libappindicator.c	2010-11-12 04:42:06 +0000
@@ -348,6 +348,75 @@
 }
 
 void
+test_libappindicator_desktop_menu (void)
+{
+	AppIndicator * ci = app_indicator_new ("my-id-desktop-menu",
+	                                       "my-name",
+	                                       APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
+
+	g_assert(ci != NULL);
+	g_assert(app_indicator_get_label(ci) == NULL);
+	g_assert(app_indicator_get_label_guide(ci) == NULL);
+
+	app_indicator_build_menu_from_desktop(ci, SRCDIR "/test-libappindicator.desktop", "Test Program");
+
+	GValue serverval = {0};
+	g_value_init(&serverval, DBUSMENU_TYPE_SERVER);
+	g_object_get_property(G_OBJECT(ci), "dbus-menu-server", &serverval);
+
+	DbusmenuServer * server = DBUSMENU_SERVER(g_value_get_object(&serverval));
+	g_assert(server != NULL);
+
+	GValue rootval = {0};
+	g_value_init(&rootval, DBUSMENU_TYPE_MENUITEM);
+	g_object_get_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_ROOT_NODE, &rootval);
+	DbusmenuMenuitem * root = DBUSMENU_MENUITEM(g_value_get_object(&rootval));
+	g_assert(root != NULL);
+
+	GList * children = dbusmenu_menuitem_get_children(root);
+	g_assert(children != NULL);
+	g_assert(g_list_length(children) == 3);
+
+
+
+	g_object_unref(G_OBJECT(ci));
+	return;
+}
+
+void
+test_libappindicator_desktop_menu_bad (void)
+{
+	AppIndicator * ci = app_indicator_new ("my-id-desktop-menu-bad",
+	                                       "my-name",
+	                                       APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
+
+	g_assert(ci != NULL);
+	g_assert(app_indicator_get_label(ci) == NULL);
+	g_assert(app_indicator_get_label_guide(ci) == NULL);
+
+	app_indicator_build_menu_from_desktop(ci, SRCDIR "/test-libappindicator.desktop", "Not Test Program");
+
+	GValue serverval = {0};
+	g_value_init(&serverval, DBUSMENU_TYPE_SERVER);
+	g_object_get_property(G_OBJECT(ci), "dbus-menu-server", &serverval);
+
+	DbusmenuServer * server = DBUSMENU_SERVER(g_value_get_object(&serverval));
+	g_assert(server != NULL);
+
+	GValue rootval = {0};
+	g_value_init(&rootval, DBUSMENU_TYPE_MENUITEM);
+	g_object_get_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_ROOT_NODE, &rootval);
+	DbusmenuMenuitem * root = DBUSMENU_MENUITEM(g_value_get_object(&rootval));
+	g_assert(root != NULL);
+
+	GList * children = dbusmenu_menuitem_get_children(root);
+	g_assert(g_list_length(children) == 0);
+
+	g_object_unref(G_OBJECT(ci));
+	return;
+}
+
+void
 test_libappindicator_props_suite (void)
 {
 	g_test_add_func ("/indicator-application/libappindicator/init",            test_libappindicator_init);
@@ -357,6 +426,8 @@
 	g_test_add_func ("/indicator-application/libappindicator/set_label",       test_libappindicator_set_label);
 	g_test_add_func ("/indicator-application/libappindicator/set_menu",        test_libappindicator_set_menu);
 	g_test_add_func ("/indicator-application/libappindicator/label_signals",   test_libappindicator_label_signals);
+	g_test_add_func ("/indicator-application/libappindicator/desktop_menu",    test_libappindicator_desktop_menu);
+	g_test_add_func ("/indicator-application/libappindicator/desktop_menu_bad",test_libappindicator_desktop_menu_bad);
 
 	return;
 }

=== added file 'tests/test-libappindicator.desktop'
--- tests/test-libappindicator.desktop	1970-01-01 00:00:00 +0000
+++ tests/test-libappindicator.desktop	2010-11-12 04:42:06 +0000
@@ -0,0 +1,23 @@
+[Desktop Entry]
+Name=AppIndicator Test
+GenericName=Test
+Comment=This is only a test
+Exec=/usr/bin/false
+Terminal=false
+Type=Application
+X-Ayatana-Desktop-Shortcuts=Short1;Short2;Short3;
+
+[Short1 Shortcut Group]
+Name=Shortcut 1
+Exec=/usr/bin/true
+OnlyShowIn=Test Program;
+
+[Short2 Shortcut Group]
+Name=Shortcut 2
+Exec=/usr/bin/true
+OnlyShowIn=Test Program;
+
+[Short3 Shortcut Group]
+Name=Shortcut 3
+Exec=/usr/bin/true
+OnlyShowIn=Test Program;


Follow ups