aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-02-11 08:41:13 -0600
committerTed Gould <ted@gould.cx>2010-02-11 08:41:13 -0600
commit0e783eb26287d21359e4c23beb26601300c5b353 (patch)
tree815836f52b41fafe2844c532e55afee9c625b97d
parent07cba3340daeb169dc1e2ef28c01bafa7fb60448 (diff)
parentec5e7ea86df0da2859bfe4de9d668ce66987d8ab (diff)
downloadlibayatana-appindicator-0e783eb26287d21359e4c23beb26601300c5b353.tar.gz
libayatana-appindicator-0e783eb26287d21359e4c23beb26601300c5b353.tar.bz2
libayatana-appindicator-0e783eb26287d21359e4c23beb26601300c5b353.zip
Fix to make the dbus paths unique by using the ID of the application.
-rw-r--r--src/libappindicator/app-indicator.c53
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/test-libappindicator-dbus-client.c2
-rw-r--r--tests/test-libappindicator-dbus-server.c14
-rw-r--r--tests/test-libappindicator-status-server.c8
5 files changed, 58 insertions, 25 deletions
diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c
index 540620c..0ca68d4 100644
--- a/src/libappindicator/app-indicator.c
+++ b/src/libappindicator/app-indicator.c
@@ -59,6 +59,7 @@ License version 3 and version 2.1 along with this program. If not, see
struct _AppIndicatorPrivate {
/* Properties */
gchar *id;
+ gchar *clean_id;
AppIndicatorCategory category;
AppIndicatorStatus status;
gchar *icon_name;
@@ -115,9 +116,8 @@ enum {
#define APP_INDICATOR_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_INDICATOR_TYPE, AppIndicatorPrivate))
-/* Default Paths */
+/* Default Path */
#define DEFAULT_ITEM_PATH "/org/ayatana/NotificationItem"
-#define DEFAULT_MENU_PATH "/org/ayatana/NotificationItem/Menu"
/* More constants */
#define DEFAULT_FALLBACK_TIMER 100 /* in milliseconds */
@@ -307,6 +307,7 @@ app_indicator_init (AppIndicator *self)
AppIndicatorPrivate * priv = APP_INDICATOR_GET_PRIVATE(self);
priv->id = NULL;
+ priv->clean_id = NULL;
priv->category = APP_INDICATOR_CATEGORY_OTHER;
priv->status = APP_INDICATOR_STATUS_PASSIVE;
priv->icon_name = NULL;
@@ -332,11 +333,7 @@ app_indicator_init (AppIndicator *self)
}
dbus_g_connection_ref(priv->connection);
- dbus_g_connection_register_g_object(priv->connection,
- DEFAULT_ITEM_PATH,
- G_OBJECT(self));
-
- self->priv = priv;
+ self->priv = priv;
return;
}
@@ -413,6 +410,11 @@ app_indicator_finalize (GObject *object)
priv->id = NULL;
}
+ if (priv->clean_id != NULL) {
+ g_free(priv->clean_id);
+ priv->clean_id = NULL;
+ }
+
if (priv->icon_name != NULL) {
g_free(priv->icon_name);
priv->icon_name = NULL;
@@ -445,16 +447,23 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu
switch (prop_id) {
case PROP_ID:
- if (priv->id != NULL) {
- g_warning ("Resetting ID value when I already had a value of: %s", priv->id);
- g_free (priv->id);
- priv->id = NULL;
- }
+ if (priv->id != NULL) {
+ g_warning ("Resetting ID value when I already had a value of: %s", priv->id);
+ break;
+ }
- priv->id = g_strdup (g_value_get_string (value));
+ priv->id = g_strdup (g_value_get_string (value));
- check_connect (self);
- break;
+ priv->clean_id = g_strdup(priv->id);
+ gchar * cleaner;
+ for (cleaner = priv->clean_id; *cleaner != '\0'; cleaner++) {
+ if (!g_ascii_isalnum(*cleaner)) {
+ *cleaner = '_';
+ }
+ }
+
+ check_connect (self);
+ break;
case PROP_CATEGORY:
enum_val = g_enum_get_value_by_nick ((GEnumClass *) g_type_class_ref (APP_INDICATOR_TYPE_INDICATOR_CATEGORY),
@@ -584,6 +593,11 @@ check_connect (AppIndicator *self)
if (priv->icon_name == NULL) return;
if (priv->id == NULL) return;
+ gchar * path = g_strdup_printf(DEFAULT_ITEM_PATH "/%s", priv->clean_id);
+ dbus_g_connection_register_g_object(priv->connection,
+ path,
+ G_OBJECT(self));
+
GError * error = NULL;
priv->watcher_proxy = dbus_g_proxy_new_for_name_owner(priv->connection,
NOTIFICATION_WATCHER_DBUS_ADDR,
@@ -595,11 +609,13 @@ check_connect (AppIndicator *self)
it's not a warning anymore. */
g_error_free(error);
start_fallback_timer(self, FALSE);
+ g_free(path);
return;
}
g_signal_connect(G_OBJECT(priv->watcher_proxy), "destroy", G_CALLBACK(watcher_proxy_destroyed), self);
- org_freedesktop_StatusNotifierWatcher_register_status_notifier_item_async(priv->watcher_proxy, DEFAULT_ITEM_PATH, register_service_cb, self);
+ org_freedesktop_StatusNotifierWatcher_register_status_notifier_item_async(priv->watcher_proxy, path, register_service_cb, self);
+ g_free(path);
return;
}
@@ -1220,7 +1236,9 @@ setup_dbusmenu (AppIndicator *self)
root);
if (priv->menuservice == NULL) {
- priv->menuservice = dbusmenu_server_new (DEFAULT_MENU_PATH);
+ 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);
@@ -1244,6 +1262,7 @@ app_indicator_set_menu (AppIndicator *self, GtkMenu *menu)
g_return_if_fail (IS_APP_INDICATOR (self));
g_return_if_fail (GTK_IS_MENU (menu));
+ g_return_if_fail (self->priv->clean_id != NULL);
priv = self->priv;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 03e2091..d42ed2b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -158,14 +158,16 @@ DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) libappindicator-tests-gtester
DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
test-libappindicator-dbus: test-libappindicator-dbus-client test-libappindicator-dbus-server Makefile.am
- @echo "#!/bin/sh" > test-libappindicator-dbus
+ @echo "#!/bin/bash" > test-libappindicator-dbus
+ @echo . $(srcdir)/run-xvfb.sh >> $@
@echo $(DBUS_RUNNER) --task ./test-libappindicator-dbus-client --task-name Client --task ./test-libappindicator-dbus-server --task-name Server --ignore-return >> test-libappindicator-dbus
@chmod +x test-libappindicator-dbus
TESTS += test-libappindicator-dbus
test-libappindicator-status: test-libappindicator-status-client test-libappindicator-status-server Makefile.am
- @echo "#!/bin/sh" > test-libappindicator-status
+ @echo "#!/bin/bash" > test-libappindicator-status
+ @echo . $(srcdir)/run-xvfb.sh >> $@
@echo $(DBUS_RUNNER) --task ./test-libappindicator-status-client --task-name Client --task ./test-libappindicator-status-server --task-name Server --ignore-return >> test-libappindicator-status
@chmod +x test-libappindicator-status
diff --git a/tests/test-libappindicator-dbus-client.c b/tests/test-libappindicator-dbus-client.c
index 5a7107f..6125d36 100644
--- a/tests/test-libappindicator-dbus-client.c
+++ b/tests/test-libappindicator-dbus-client.c
@@ -200,7 +200,7 @@ main (gint argc, gchar * argv[])
DBusGProxy * props = dbus_g_proxy_new_for_name_owner(session_bus,
":1.0",
- "/org/ayatana/NotificationItem",
+ "/org/ayatana/NotificationItem/my_id",
DBUS_INTERFACE_PROPERTIES,
&error);
if (error != NULL) {
diff --git a/tests/test-libappindicator-dbus-server.c b/tests/test-libappindicator-dbus-server.c
index cc072aa..76f0e50 100644
--- a/tests/test-libappindicator-dbus-server.c
+++ b/tests/test-libappindicator-dbus-server.c
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <glib.h>
+#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>
#include "test-defines.h"
@@ -39,13 +39,19 @@ kill_func (gpointer userdata)
gint
main (gint argc, gchar * argv[])
{
- g_type_init();
+ gtk_init(&argc, &argv);
g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
AppIndicator * ci = app_indicator_new (TEST_ID, TEST_ICON_NAME, TEST_CATEGORY);
- app_indicator_set_status (ci, TEST_STATE);
- app_indicator_set_attention_icon (ci, TEST_ATTENTION_ICON_NAME);
+ app_indicator_set_status (ci, TEST_STATE);
+ app_indicator_set_attention_icon (ci, TEST_ATTENTION_ICON_NAME);
+
+ GtkMenu * menu = GTK_MENU(gtk_menu_new());
+ GtkMenuItem * item = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Label"));
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(item));
+
+ app_indicator_set_menu(ci, menu);
g_timeout_add_seconds(2, kill_func, NULL);
diff --git a/tests/test-libappindicator-status-server.c b/tests/test-libappindicator-status-server.c
index 9e58ba9..79b1759 100644
--- a/tests/test-libappindicator-status-server.c
+++ b/tests/test-libappindicator-status-server.c
@@ -55,7 +55,7 @@ toggle (gpointer userdata)
gint
main (gint argc, gchar * argv[])
{
- g_type_init();
+ gtk_init(&argc, &argv);
g_usleep(100000);
@@ -64,6 +64,12 @@ main (gint argc, gchar * argv[])
AppIndicator * ci = app_indicator_new ("my-id", "my-icon-name", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_attention_icon (ci, "my-attention-icon");
+ GtkMenu * menu = GTK_MENU(gtk_menu_new());
+ GtkMenuItem * item = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Label"));
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(item));
+
+ app_indicator_set_menu(ci, menu);
+
g_timeout_add(50, toggle, ci);
mainloop = g_main_loop_new(NULL, FALSE);