aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-11-11 21:07:35 -0600
committerTed Gould <ted@gould.cx>2010-11-11 21:07:35 -0600
commit5a29eceb8e560ce4319924094dcdbc6d157153c8 (patch)
treebf6500919a106a2eb2b5e1f4144dbfbf9e6f0588
parent9f0ec1f915156311d8de7a629782252a4bce6e41 (diff)
parent8b57d12c54ec1befb09711439e40eac7ed93dbcd (diff)
downloadlibayatana-appindicator-5a29eceb8e560ce4319924094dcdbc6d157153c8.tar.gz
libayatana-appindicator-5a29eceb8e560ce4319924094dcdbc6d157153c8.tar.bz2
libayatana-appindicator-5a29eceb8e560ce4319924094dcdbc6d157153c8.zip
Adding a property for getting the dbusmenu server
-rw-r--r--src/app-indicator.c30
-rw-r--r--tests/test-libappindicator.c48
2 files changed, 77 insertions, 1 deletions
diff --git a/src/app-indicator.c b/src/app-indicator.c
index dc88e9b..318a056 100644
--- a/src/app-indicator.c
+++ b/src/app-indicator.c
@@ -34,6 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
+#include <libdbusmenu-glib/menuitem.h>
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-gtk/client.h>
@@ -123,7 +124,8 @@ enum {
PROP_X_LABEL,
PROP_X_LABEL_GUIDE,
PROP_ORDERING_INDEX,
- PROP_X_ORDERING_INDEX
+ PROP_X_ORDERING_INDEX,
+ PROP_DBUS_MENU_SERVER
};
/* The strings so that they can be slowly looked up. */
@@ -141,6 +143,7 @@ enum {
#define PROP_X_LABEL_GUIDE_S ("x-ayatana-" PROP_LABEL_GUIDE_S)
#define PROP_ORDERING_INDEX_S "ordering-index"
#define PROP_X_ORDERING_INDEX_S ("x-ayatana-" PROP_ORDERING_INDEX_S)
+#define PROP_DBUS_MENU_SERVER_S "dbus-menu-server"
/* Private macro, shhhh! */
#define APP_INDICATOR_GET_PRIVATE(o) \
@@ -408,6 +411,19 @@ app_indicator_class_init (AppIndicatorClass *klass)
"A wrapper, please don't use.",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /**
+ AppIndicator:dbus-menu-server:
+
+ A way to get the internal dbusmenu server if it is available.
+ This should only be used for testing.
+ */
+ g_object_class_install_property(object_class,
+ PROP_DBUS_MENU_SERVER,
+ g_param_spec_object (PROP_DBUS_MENU_SERVER_S,
+ "The internal DBusmenu Server",
+ "DBusmenu server which is available for testing the application indicators.",
+ DBUSMENU_TYPE_SERVER,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/* Signals */
@@ -796,6 +812,14 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu
priv->ordering_index = g_value_get_uint(value);
break;
+ case PROP_DBUS_MENU_SERVER:
+ if (priv->menuservice != NULL) {
+ g_object_unref (priv->menuservice);
+ }
+ gpointer val = g_value_dup_object(value);
+ priv->menuservice = DBUSMENU_SERVER(val);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -868,6 +892,10 @@ app_indicator_get_property (GObject * object, guint prop_id, GValue * value, GPa
g_value_set_uint(value, priv->ordering_index);
break;
+ case PROP_DBUS_MENU_SERVER:
+ g_value_set_object(value, priv->menuservice);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c
index f340a67..82f3d05 100644
--- a/tests/test-libappindicator.c
+++ b/tests/test-libappindicator.c
@@ -25,6 +25,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <app-indicator.h>
+#include <libdbusmenu-glib/menuitem.h>
+#include <libdbusmenu-glib/server.h>
+
void
test_libappindicator_prop_signals_status_helper (AppIndicator * ci, gchar * status, gboolean * signalactivated)
{
@@ -225,6 +228,50 @@ test_libappindicator_set_label (void)
}
void
+test_libappindicator_set_menu (void)
+{
+ AppIndicator * ci = app_indicator_new ("my-id",
+ "my-name",
+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
+
+ g_assert(ci != NULL);
+
+ GtkMenu * menu = GTK_MENU(gtk_menu_new());
+
+ GtkMenuItem * item = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Test Label"));
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(item));
+ gtk_widget_show(GTK_WIDGET(item));
+
+ app_indicator_set_menu(ci, menu);
+
+ g_assert(app_indicator_get_menu(ci) != NULL);
+
+ 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) == 1);
+
+ const gchar * label = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(children->data), DBUSMENU_MENUITEM_PROP_LABEL);
+ g_assert(label != NULL);
+ g_assert(g_strcmp0(label, "Test Label") == 0);
+
+ g_object_unref(G_OBJECT(ci));
+ return;
+}
+
+void
label_signals_cb (AppIndicator * appindicator, gchar * label, gchar * guide, gpointer user_data)
{
gint * label_signals_count = (gint *)user_data;
@@ -334,6 +381,7 @@ test_libappindicator_props_suite (void)
g_test_add_func ("/indicator-application/libappindicator/init_set_props", test_libappindicator_init_set_props);
g_test_add_func ("/indicator-application/libappindicator/prop_signals", test_libappindicator_prop_signals);
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);