ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #02748
[Branch ~indicator-applet-developers/indicator-me/trunk] Rev 118: Properly query for username and icon after connecting to the proxy
------------------------------------------------------------
revno: 118
committer: Ken VanDine <ken.vandine@xxxxxxxxxxxxx>
branch nick: indicator-me-gdbus
timestamp: Thu 2011-01-13 10:28:28 -0600
message:
Properly query for username and icon after connecting to the proxy
modified:
src/Makefile.am
src/indicator-me.c
--
lp:indicator-me
https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk
Your team ayatana-commits is subscribed to branch lp:indicator-me.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk/+edit-subscription
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-01-12 22:40:11 +0000
+++ src/Makefile.am 2011-01-13 16:28:28 +0000
@@ -12,7 +12,6 @@
about-me-menu-item.h \
indicator-me.c \
dbus-shared-names.h \
- me-service-server.h \
gen-me-service.xml.h \
gen-me-service.xml.c
libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror
@@ -29,6 +28,7 @@
me-service.c \
me-service-dbus.h \
me-service-dbus.c \
+ me-service-server.h \
me-service-gwibber.c \
me-service-gwibber.h \
status-provider.h \
@@ -55,9 +55,6 @@
--output=me-service-server.h \
$(srcdir)/me-service.xml
-DBUS_SPECS = \
- me-service.xml
-
gen-%.xml.h: %.xml
@echo "Building $@ from $<"
@echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c 2011-01-12 22:40:11 +0000
+++ src/indicator-me.c 2011-01-13 16:28:28 +0000
@@ -71,6 +71,7 @@
static GtkImage * status_image = NULL;
static GtkLabel *label = NULL;
static GDBusProxy * status_proxy = NULL;
+
static GCancellable * status_proxy_cancel = NULL;
static IdoEntryMenuItem *ido_entry = NULL;
@@ -85,7 +86,8 @@
static void indicator_me_dispose (GObject *object);
static void indicator_me_finalize (GObject *object);
static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata);
-static void status_icon_cb (GDBusProxy * proxy, char * icons, GError *error, gpointer userdata);
+static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
+
static gboolean new_entry_item (DbusmenuMenuitem * newitem,
DbusmenuMenuitem * parent,
DbusmenuClient * client);
@@ -93,6 +95,10 @@
static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry);
static gboolean entry_hint_is_shown (GtkWidget *widget);
static void status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
+static void status_icon_changed (IndicatorMe * self, char * icon);
+static void status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data);
+static void username_changed (IndicatorMe * self, char * username);
+static void username_cb (GObject * object, GAsyncResult * res, gpointer user_data);
G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE);
@@ -129,21 +135,65 @@
static void
indicator_me_dispose (GObject *object)
{
+ IndicatorMe * self = INDICATOR_ME(object);
+
+ if (self->service != NULL) {
+ g_object_unref(G_OBJECT(self->service));
+ self->service = NULL;
+ }
+
+ if (status_proxy != NULL) {
+ g_object_unref(status_proxy);
+ status_proxy = NULL;
+ }
+
+ if (status_proxy_cancel != NULL) {
+ g_cancellable_cancel(status_proxy_cancel);
+ g_object_unref(status_proxy_cancel);
+ status_proxy_cancel = NULL;
+ }
G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object);
+
return;
}
static void
indicator_me_finalize (GObject *object)
{
-
G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object);
return;
}
static void
-username_cb (GDBusProxy * proxy, char * username, GError *error, gpointer userdata)
+username_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+ char * username;
+ GVariant * result;
+
+ IndicatorMe * self = INDICATOR_ME (user_data);
+ g_return_if_fail(self != NULL);
+
+ result = g_dbus_proxy_call_finish(status_proxy, res, &error);
+ g_return_if_fail(status_proxy != NULL);
+
+ if (error != NULL) {
+ g_error("Could not get the username %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ g_variant_get(result, "(&s)", &username);
+
+ if (username != NULL) {
+ username_changed (self, username);
+ }
+
+}
+
+static void
+username_changed (IndicatorMe * self, char * username)
{
if (label == NULL) {
label = GTK_LABEL(gtk_label_new(NULL));
@@ -160,20 +210,13 @@
}
-static void
-username_changed (GDBusProxy * proxy, char * username, GError *error, gpointer userdata)
-{
- return username_cb(proxy, username, error, userdata);
-}
-
static GtkLabel *
get_label (IndicatorObject * io)
{
- if (label == NULL) {
+ if (label == NULL) {
/* Create the label if it doesn't exist already */
- username_cb (NULL, NULL, NULL, NULL);
- }
-
+ username_changed (NULL, NULL);
+ }
return label;
}
@@ -182,35 +225,74 @@
{
if (status_image == NULL) {
/* Will create the status icon if it doesn't exist already */
- status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL);
+ status_icon_changed(NULL, DEFAULT_ICON);
}
return status_image;
}
static void
-status_icon_cb (GDBusProxy * proxy, char * icons, GError *error, gpointer userdata)
-{
- g_return_if_fail(icons != NULL);
- g_return_if_fail(icons[0] != '\0');
+status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+ char * icon;
+ GVariant * result;
+
+ IndicatorMe * self = INDICATOR_ME (user_data);
+ g_return_if_fail(self != NULL);
+
+ result = g_dbus_proxy_call_finish(status_proxy, res, &error);
+ g_return_if_fail(status_proxy != NULL);
+
+ if (error != NULL) {
+ g_error("Could not get the username %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ g_variant_get(result, "(&s)", &icon);
+
+ if (icon != NULL) {
+ status_icon_changed (self, icon);
+ }
+
+}
+
+static void
+status_icon_changed (IndicatorMe * self, char * icon)
+{
+ g_return_if_fail(icon != NULL);
+ g_return_if_fail(icon[0] != '\0');
if (status_image == NULL) {
- status_image = indicator_image_helper (DEFAULT_ICON "-panel");
+ status_image = indicator_image_helper (DEFAULT_ICON "-panel");
gtk_widget_show(GTK_WIDGET(status_image));
}
- gchar *panel_icon = g_strconcat (icons, "-panel", NULL);
- indicator_image_helper_update (status_image, panel_icon);
- g_free (panel_icon);
+ gchar *panel_icon = g_strconcat (icon, "-panel", NULL);
+ indicator_image_helper_update (status_image, panel_icon);
+ g_free (panel_icon);
return;
}
+/* Receives all signals from the service, routed to the appropriate functions */
static void
-status_icon_changed (GDBusProxy * proxy, gchar * icon, gpointer userdata)
+receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
+ GVariant * parameters, gpointer user_data)
{
- g_debug("Changing status icon: '%s'", icon);
+ IndicatorMe * self = INDICATOR_ME(user_data);
- return status_icon_cb(proxy, icon, NULL, NULL);
+ if (g_strcmp0(signal_name, "StatusIconsChanged") == 0) {
+ char * icon;
+ g_variant_get (parameters, "(&s)", &icon);
+ status_icon_changed (self, icon);
+ }
+ else if (g_strcmp0(signal_name, "UserChanged") == 0) {
+ char * username;
+ g_variant_get (parameters, "(&s)", &username);
+ username_changed(self, username);
+ }
+ return;
}
static void
@@ -231,8 +313,6 @@
{
if (connected) {
if (status_proxy == NULL) {
- GError * error = NULL;
-
status_proxy_cancel = g_cancellable_new();
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
@@ -243,28 +323,9 @@
INDICATOR_ME_SERVICE_DBUS_INTERFACE,
status_proxy_cancel,
status_proxy_cb,
- self);
-
-
- if (error != NULL) {
- g_warning("Unable to get status proxy: %s", error->message);
- g_error_free(error);
- }
-
- if (status_proxy == NULL) return;
-
- g_signal_connect(status_proxy, "g-signal", G_CALLBACK(status_icon_changed), self);
- g_signal_connect(status_proxy, "g-signal", G_CALLBACK(username_changed), self);
+ userdata);
+
}
-
- /* KEN REMOVED
- org_ayatana_indicator_me_service_status_icons_async(status_proxy, status_icon_cb, NULL);
- */
-
- /* query the service for the username to display */
- /* KEN REMOVED
- org_ayatana_indicator_me_service_pretty_user_name_async(status_proxy, username_cb, NULL);
- */
} else {
DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry),
"dbusmenuitem");
@@ -278,7 +339,7 @@
mi);
/* If we're disconnecting, go back to offline */
- status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL);
+ status_icon_changed(NULL, DEFAULT_ICON);
g_object_unref (status_proxy);
status_proxy = NULL;
@@ -296,11 +357,13 @@
could include starting the service. Sometimes it'll fail and
we'll try to start that dang service again! */
static void
-status_proxy_cb (GObject * self, GAsyncResult * res, gpointer user_data)
+status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
{
GError * error = NULL;
- g_return_if_fail(self != NULL);
+ g_return_if_fail(object != NULL);
+
+ IndicatorMe * self = INDICATOR_ME (user_data);
GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
@@ -319,6 +382,20 @@
sure that it's ours. */
status_proxy = proxy;
+ g_signal_connect(status_proxy, "g-signal", G_CALLBACK(receive_signal), self);
+
+ /* Query to get the username */
+ g_debug("Get the username");
+ g_dbus_proxy_call(status_proxy, "PrettyUserName", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ (GAsyncReadyCallback) username_cb, self);
+
+ /* Query to get the status icon */
+ g_debug("Get the status icon");
+ g_dbus_proxy_call(status_proxy, "StatusIcon", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ (GAsyncReadyCallback) status_icon_cb, self);
+
return;
}