aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-06-19 07:21:36 -0500
committerTed Gould <ted@canonical.com>2009-06-19 07:21:36 -0500
commit377777d3cde780875ab39ffb647e4009153365bc (patch)
tree2f3654aa307a6437b595c4662095110ceb424871 /src
parent080aa534c8a204cb8a22c71059c9e4f681c5668f (diff)
downloadayatana-indicator-session-377777d3cde780875ab39ffb647e4009153365bc.tar.gz
ayatana-indicator-session-377777d3cde780875ab39ffb647e4009153365bc.tar.bz2
ayatana-indicator-session-377777d3cde780875ab39ffb647e4009153365bc.zip
Splitting out the menu loading and process starting code to make it lazy and push it into the idle loop. No blocking DBus on startup.
Diffstat (limited to 'src')
-rw-r--r--src/indicator-sus.c66
1 files changed, 56 insertions, 10 deletions
diff --git a/src/indicator-sus.c b/src/indicator-sus.c
index 5d6c219..15d4e5a 100644
--- a/src/indicator-sus.c
+++ b/src/indicator-sus.c
@@ -17,6 +17,9 @@ static GtkMenu * users_menu = NULL;
static GtkMenu * session_menu = NULL;
static GtkMenu * main_menu = NULL;
+static DBusGConnection * connection = NULL;
+static DBusGProxy * proxy = NULL;
+
GtkLabel *
get_label (void)
{
@@ -30,54 +33,97 @@ get_icon (void)
return NULL;
}
-GtkMenu *
-get_menu (void)
+static gboolean
+build_status_menu (gpointer userdata)
{
guint returnval = 0;
GError * error = NULL;
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- DBusGProxy * proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ if (proxy == NULL) {
+ /* If we don't have DBus, let's stay in the idle loop */
+ return TRUE;
+ }
if (!org_freedesktop_DBus_start_service_by_name (proxy, INDICATOR_STATUS_DBUS_NAME, 0, &returnval, &error)) {
g_error("Unable to send message to DBus to start service: %s", error != NULL ? error->message : "(NULL error)" );
g_error_free(error);
- return NULL;
+ return FALSE;
}
if (returnval != DBUS_START_REPLY_SUCCESS && returnval != DBUS_START_REPLY_ALREADY_RUNNING) {
g_error("Return value isn't indicative of success: %d", returnval);
- return NULL;
+ return FALSE;
}
status_menu = GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_STATUS_DBUS_NAME, INDICATOR_STATUS_DBUS_OBJECT));
+ return FALSE;
+}
+
+static gboolean
+build_users_menu (gpointer userdata)
+{
+ guint returnval = 0;
+ GError * error = NULL;
+
+ if (proxy == NULL) {
+ /* If we don't have DBus, let's stay in the idle loop */
+ return TRUE;
+ }
+
if (!org_freedesktop_DBus_start_service_by_name (proxy, INDICATOR_USERS_DBUS_NAME, 0, &returnval, &error)) {
g_error("Unable to send message to DBus to start service: %s", error != NULL ? error->message : "(NULL error)" );
g_error_free(error);
- return NULL;
+ return FALSE;
}
if (returnval != DBUS_START_REPLY_SUCCESS && returnval != DBUS_START_REPLY_ALREADY_RUNNING) {
g_error("Return value isn't indicative of success: %d", returnval);
- return NULL;
+ return FALSE;
}
users_menu = GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_USERS_DBUS_NAME, INDICATOR_USERS_DBUS_OBJECT));
+ return FALSE;
+}
+
+static gboolean
+build_session_menu (gpointer userdata)
+{
+ guint returnval = 0;
+ GError * error = NULL;
+
+ if (proxy == NULL) {
+ /* If we don't have DBus, let's stay in the idle loop */
+ return TRUE;
+ }
+
if (!org_freedesktop_DBus_start_service_by_name (proxy, INDICATOR_SESSION_DBUS_NAME, 0, &returnval, &error)) {
g_error("Unable to send message to DBus to start service: %s", error != NULL ? error->message : "(NULL error)" );
g_error_free(error);
- return NULL;
+ return FALSE;
}
if (returnval != DBUS_START_REPLY_SUCCESS && returnval != DBUS_START_REPLY_ALREADY_RUNNING) {
g_error("Return value isn't indicative of success: %d", returnval);
- return NULL;
+ return FALSE;
}
session_menu = GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT));
+ return FALSE;
+}
+
+GtkMenu *
+get_menu (void)
+{
+ connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+ g_idle_add(build_status_menu, NULL);
+ g_idle_add(build_users_menu, NULL);
+ g_idle_add(build_session_menu, NULL);
+
main_menu = GTK_MENU(gtk_menu_new());
return main_menu;