From 1967b9c58fd2727733fb38c10d610eb80e365ae3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 13 Jul 2011 13:12:00 +0100 Subject: tidied up signals and methods for the session service so as the users real name should be available and not the icon, icon should not change on the panel --- src/session-dbus.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/session-dbus.xml') diff --git a/src/session-dbus.xml b/src/session-dbus.xml index ee724f5..82c8dc8 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -3,11 +3,11 @@ - + - + -- cgit v1.2.3 From d8eae0b9560084bc68781d73c14fcb54cd53fd02 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 14 Jul 2011 13:06:38 +0100 Subject: dynamic user menu hiding on the way# --- src/indicator-session.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++--- src/session-dbus.c | 42 +++++++++++++++++++++++++++++++---- src/session-dbus.h | 1 + src/session-dbus.xml | 9 +++++--- src/session-service.c | 4 ++++ 5 files changed, 104 insertions(+), 10 deletions(-) (limited to 'src/session-dbus.xml') diff --git a/src/indicator-session.c b/src/indicator-session.c index ab3e87a..704e959 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -65,6 +65,7 @@ struct _IndicatorSession { IndicatorServiceManager * service; IndicatorObjectEntry users; IndicatorObjectEntry devices; + gboolean show_users_entry; GCancellable * service_proxy_cancel; GDBusProxy * service_proxy; }; @@ -94,6 +95,7 @@ static void service_connection_cb (IndicatorServiceManager * sm, gboolean connec static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data); +static void user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -122,6 +124,7 @@ indicator_session_init (IndicatorSession *self) self->service = NULL; self->service_proxy_cancel = NULL; self->service_proxy = NULL; + self->show_users_entry = FALSE; /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, @@ -244,8 +247,10 @@ indicator_session_get_entries (IndicatorObject* obj) IndicatorSession* self = INDICATOR_SESSION (obj); GList * retval = NULL; - - retval = g_list_prepend (retval, &self->users); + // Only show the users menu if we have more than one + if (self->show_users_entry == TRUE){ + retval = g_list_prepend (retval, &self->users); + } retval = g_list_prepend (retval, &self->devices); if (retval != NULL) { @@ -263,7 +268,15 @@ service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointe if (connected) { if (self->service_proxy != NULL){ // Its a reconnect ! - // fetch the users's real name and return + // Fetch synchronisation data and return (proxy is still legit) + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); g_dbus_proxy_call (self->service_proxy, "GetUserRealName", NULL, @@ -317,6 +330,16 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + // Figure out whether we should show the user menu at all. + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); + // Fetch the user's real name for the user entry label g_dbus_proxy_call (self->service_proxy, "GetUserRealName", @@ -382,6 +405,31 @@ user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) return; } +static void +user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data) +{ + IndicatorSession * self = INDICATOR_SESSION(user_data); + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->service_proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete real name dbus query"); + g_error_free (error); + return; + } + gboolean update; + g_variant_get (result, "(b)", &update); + g_debug ("GET VISIBILITY CB: NEW VALUE = %i", update); + self->show_users_entry = update; + g_signal_emit_by_name (user_data, + "entry-added", + self->parent, + self->users); + return; +} + /* Receives all signals from the service, routed to the appropriate functions */ static void @@ -397,6 +445,10 @@ receive_signal (GDBusProxy * proxy, const gchar* username = NULL; g_variant_get (parameters, "(s)", &username); indicator_session_update_users_label (self, username); + } + else if (g_strcmp0(signal_name, "UserMenuIsVisible") == 0) { + gboolean result = g_variant_get_boolean (parameters); + g_debug ("GET VISIBILITY signal: NEW VALUE = %i", result); } return; } diff --git a/src/session-dbus.c b/src/session-dbus.c index d28629b..9e24141 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -38,6 +38,7 @@ static void bus_method_call (GDBusConnection * connection, const gchar * sender, typedef struct _SessionDbusPrivate SessionDbusPrivate; struct _SessionDbusPrivate { gchar * name; + gboolean user_menu_is_visible; GDBusConnection * bus; GCancellable * bus_cancel; guint dbus_registration; @@ -103,6 +104,7 @@ session_dbus_init (SessionDbus *self) priv->bus = NULL; priv->bus_cancel = NULL; priv->dbus_registration = 0; + priv->user_menu_is_visible = FALSE; priv->bus_cancel = g_cancellable_new(); g_bus_get(G_BUS_TYPE_SESSION, @@ -161,15 +163,20 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) { - SessionDbus * service = SESSION_DBUS(user_data); + SessionDbus * service = SESSION_DBUS (user_data); + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE (service); + GVariant * retval = NULL; if (g_strcmp0(method, "GetUserRealName") == 0) { retval = get_users_real_name (service); - } else { - g_warning("Calling method '%s' on the indicator service and it's unknown", method); } - + else if (g_strcmp0 (method, "GetUserMenuVisibility") == 0){ + retval = g_variant_new ("(b)", priv->user_menu_is_visible); + } + else { + g_warning("Calling method '%s' on the indicator service and it's unknown", method); + } g_dbus_method_invocation_return_value(invocation, retval); return; } @@ -264,3 +271,30 @@ session_dbus_set_users_real_name (SessionDbus * session, const gchar * name) } return; } + +void +session_dbus_set_user_menu_visibility (SessionDbus* session, + gboolean visible) +{ + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); + GError * error = NULL; + + g_debug ("sesssion dbus set user visibility - %i", visible); + + priv->user_menu_is_visible = visible; + + if (priv->bus != NULL) { + g_dbus_connection_emit_signal (priv->bus, + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "UserMenuIsVisible", + g_variant_new ("(b)", priv->user_menu_is_visible), + &error); + + if (error != NULL) { + g_warning("Unable to send UserMenuIsVisible signal: %s", error->message); + g_error_free(error); + } + } +} diff --git a/src/session-dbus.h b/src/session-dbus.h index 377212b..45ebae2 100644 --- a/src/session-dbus.h +++ b/src/session-dbus.h @@ -50,6 +50,7 @@ GType session_dbus_get_type (void); SessionDbus * session_dbus_new (void); void session_dbus_set_name (SessionDbus * session, const gchar * name); void session_dbus_set_users_real_name (SessionDbus * session, const gchar * name); +void session_dbus_set_user_menu_visibility (SessionDbus* session, gboolean visible); G_END_DECLS diff --git a/src/session-dbus.xml b/src/session-dbus.xml index 82c8dc8..f496ff1 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -2,14 +2,17 @@ - - + + + - + + + diff --git a/src/session-service.c b/src/session-service.c index 2110241..812769e 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -490,6 +490,10 @@ rebuild_user_items (DbusmenuMenuitem *root, GList * users = NULL; users = users_service_dbus_get_user_list (service); guint user_count = g_list_length(users); + g_debug ("USER COUNT = %i", user_count); + // We only want to show this menu when we have more than one registered + // user + session_dbus_set_user_menu_visibility (session_dbus, user_count > 1); if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { users = g_list_sort (users, (GCompareFunc)compare_users_by_username); -- cgit v1.2.3 From ec2941976b938e93fc94cdc4309a221b3194c881 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 20 Jul 2011 18:17:49 +0100 Subject: apt watcher now controlling menuitem with signals and methods in place --- src/apt-watcher.c | 40 +++++++++++++++++++++++++++++++++++++--- src/apt-watcher.h | 7 +++++++ src/dbus-shared-names.h | 7 +++++++ src/device-menu-mgr.c | 23 +++++++---------------- src/device-menu-mgr.h | 1 - src/indicator-session.c | 4 ++-- src/session-dbus.xml | 6 ++++++ src/session-service.c | 5 ----- 8 files changed, 66 insertions(+), 27 deletions(-) (limited to 'src/session-dbus.xml') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index daab2ee..bc012ed 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -17,9 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "apt-watcher.h" #include +#include "apt-watcher.h" + static guint watcher_id; struct _AptWatcher @@ -27,6 +28,8 @@ struct _AptWatcher GObject parent_instance; GCancellable * proxy_cancel; GDBusProxy * proxy; + SessionDbus* session_dbus_interface; + DbusmenuMenuitem* apt_item; }; static void @@ -47,6 +50,10 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); +static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi, + guint timestamp, + gchar * type); + G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); static void @@ -159,11 +166,16 @@ apt_watcher_get_active_transactions_cb (GObject * obj, g_error_free (error); return; } - g_debug ("WE GOT SOME ACTIVE TRANSACTIONS TO EXAMINE, type is %s", g_variant_get_type_string (result)); - //gchar ** transactions = g_variant_get_strv (result); + //g_variant_get (result, "(sas)"); + gchar* first_param = NULL; + gchar ** transactions = NULL; + g_variant_get (result, "(sas)", first_param, transactions); + g_debug ("And the size is the string array %u", + g_strv_length (transactions)); + g_debug ("first param = %s", first_param); } static void @@ -175,3 +187,25 @@ apt_watcher_on_name_vanished (GDBusConnection *connection, name, "the system bus"); } + +static void +apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + +} + + +AptWatcher* apt_watcher_new (SessionDbus* session_dbus, + DbusmenuMenuitem* item) +{ + AptWatcher* watcher = g_object_new (APT_TYPE_WATCHER, NULL); + watcher->session_dbus_interface = session_dbus; + watcher->apt_item = item; + g_signal_connect (G_OBJECT(watcher->apt_item), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(apt_watcher_show_apt_dialog), watcher); + return watcher; +} + diff --git a/src/apt-watcher.h b/src/apt-watcher.h index 148072f..cbe0e29 100644 --- a/src/apt-watcher.h +++ b/src/apt-watcher.h @@ -21,6 +21,10 @@ with this program. If not, see . #define _APT_WATCHER_H_ #include +#include +#include + +#include "session-dbus.h" G_BEGIN_DECLS @@ -41,6 +45,9 @@ struct _AptWatcherClass GType apt_watcher_get_type (void) G_GNUC_CONST; +AptWatcher* apt_watcher_new (SessionDbus* session_dbus, + DbusmenuMenuitem* apt_item); + G_END_DECLS #endif /* _APT_WATCHER_H_ */ diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index c4ccd05..f2dbede 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -20,6 +20,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +typedef enum { + RESTART_NEEDED, + UPDATES_IN_PROGRESS, + UPDATES_AVAILABLE, + UP_TO_DATE, +}AptState; + #ifndef __DBUS_SHARED_NAMES_H__ #define __DBUS_SHARED_NAMES_H__ 1 diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index a3cea61..9c54ef3 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -18,6 +18,7 @@ with this program. If not, see . */ #include +#include #include "device-menu-mgr.h" #include "gconf-helper.h" @@ -39,6 +40,7 @@ struct _DeviceMenuMgr GObject parent_instance; DbusmenuMenuitem* root_item; SessionDbus* session_dbus_interface; + AptWatcher* apt_watcher; }; static GConfClient *gconf_client = NULL; @@ -79,16 +81,12 @@ static void machine_sleep_with_context (DeviceMenuMgr* self, gchar* type); static void show_system_settings_with_context (DbusmenuMenuitem * mi, guint timestamp, - gchar * type); -static void show_apt_dialog (DbusmenuMenuitem* mi, - guint timestamp, - gchar * type); + gchar * type); static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static AptWatcher* watcher = NULL; /*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, @@ -99,11 +97,11 @@ G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); static void device_menu_mgr_init (DeviceMenuMgr *self) { + self->apt_watcher = NULL; self->root_item = dbusmenu_menuitem_new (); setup_restart_watch(self); setup_up(self); g_idle_add(lock_screen_setup, NULL); - } static void @@ -120,7 +118,6 @@ device_menu_mgr_class_init (DeviceMenuMgrClass *klass) GObjectClass* object_class = G_OBJECT_CLASS (klass); //GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = device_menu_mgr_finalize; - watcher = g_object_new (APT_TYPE_WATCHER, NULL); } // TODO @@ -437,11 +434,6 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) g_free(dialog_line); } -static void -show_apt_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) -{ -} - static void show_system_settings_with_context (DbusmenuMenuitem * mi, guint timestamp, @@ -513,9 +505,6 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) dbusmenu_menuitem_property_set (software_updates_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); - g_signal_connect (G_OBJECT(login_settings_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_apt_dialog), NULL); dbusmenu_menuitem_child_add_position(self->root_item, software_updates_menuitem, 4); @@ -870,6 +859,8 @@ DeviceMenuMgr* device_menu_mgr_new (SessionDbus* session_dbus) { DeviceMenuMgr* device_mgr = g_object_new (DEVICE_TYPE_MENU_MGR, NULL); device_mgr->session_dbus_interface = session_dbus; - device_menu_mgr_build_static_items (device_mgr); + device_menu_mgr_build_static_items (device_mgr); + device_mgr->apt_watcher = apt_watcher_new (session_dbus, + software_updates_menuitem); return device_mgr; } diff --git a/src/device-menu-mgr.h b/src/device-menu-mgr.h index caa9aee..503b36a 100644 --- a/src/device-menu-mgr.h +++ b/src/device-menu-mgr.h @@ -22,7 +22,6 @@ with this program. If not, see . #define _DEVICE_MENU_MGR_H_ #include -#include #include "session-dbus.h" diff --git a/src/indicator-session.c b/src/indicator-session.c index 068ffef..df8cbdf 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -6,7 +6,8 @@ Copyright 2009 Canonical Ltd. Authors: Ted Gould - + Conor Curran + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. @@ -20,7 +21,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -//TODO - remember to reinsert Ted's comments. #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/src/session-dbus.xml b/src/session-dbus.xml index f496ff1..c42aca8 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -8,11 +8,17 @@ + + + + + + diff --git a/src/session-service.c b/src/session-service.c index e043d65..22552dc 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -52,12 +52,7 @@ with this program. If not, see . #include "users-service-dbus.h" #include "user-menu-mgr.h" #include "device-menu-mgr.h" - -//#include "gconf-helper.h" - #include "session-dbus.h" -//#include "lock-helper.h" - typedef struct _ActivateData ActivateData; struct _ActivateData -- cgit v1.2.3 From 853ad495b863c179792044f1a74e8556d04e32db Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 9 Aug 2011 09:59:20 +0100 Subject: and the actual code --- src/apt-watcher.c | 20 ++++++++++++++++---- src/indicator-session.c | 5 +++++ src/session-dbus.c | 22 ++++++++++++++++++++++ src/session-dbus.h | 2 +- src/session-dbus.xml | 3 +-- 5 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src/session-dbus.xml') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 285eb81..72a63ac 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -266,11 +266,23 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, _("Updates Installing…")); } else if (state == FINISHED){ - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Software Up to Date")); + GVariant* reboot_result = g_dbus_proxy_get_cached_property (self->proxy, + "RebootRequired"); + gboolean reboot; + g_variant_get (reboot_result, "b", &reboot); + if (reboot == FALSE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + } + else{ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Reboot Required")); + session_dbus_restart_required (self->session_dbus_interface); + } g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; + self->current_transaction = NULL; } self->current_state = state; } diff --git a/src/indicator-session.c b/src/indicator-session.c index d7155f6..bfe0b75 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -491,6 +491,7 @@ receive_signal (GDBusProxy * proxy, g_signal_emit_by_name ((gpointer)self, "entry-added", &self->users); + } else{ g_signal_emit_by_name ((gpointer)self, @@ -498,6 +499,10 @@ receive_signal (GDBusProxy * proxy, &self->users); } } + else if (g_strcmp0(signal_name, "RebootRequired") == 0) { + // TODO waiting on design to give me a name. + self->devices.image = indicator_image_helper (ICON_DEFAULT); + } } diff --git a/src/session-dbus.c b/src/session-dbus.c index 9aa75ef..1cf73ac 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -293,3 +293,25 @@ session_dbus_set_user_menu_visibility (SessionDbus* session, } } } + +void session_dbus_restart_required (SessionDbus* session) +{ + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); + GError * error = NULL; + + if (priv->bus != NULL) { + g_dbus_connection_emit_signal (priv->bus, + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "RebootRequired", + NULL, + &error); + + if (error != NULL) { + g_warning("Unable to send reboot-required signal: %s", error->message); + g_error_free(error); + } + } + +} diff --git a/src/session-dbus.h b/src/session-dbus.h index 45ebae2..4dc340a 100644 --- a/src/session-dbus.h +++ b/src/session-dbus.h @@ -51,7 +51,7 @@ SessionDbus * session_dbus_new (void); void session_dbus_set_name (SessionDbus * session, const gchar * name); void session_dbus_set_users_real_name (SessionDbus * session, const gchar * name); void session_dbus_set_user_menu_visibility (SessionDbus* session, gboolean visible); - +void session_dbus_restart_required (SessionDbus* session); G_END_DECLS #endif diff --git a/src/session-dbus.xml b/src/session-dbus.xml index c42aca8..fd1859f 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -17,8 +17,7 @@ - - + -- cgit v1.2.3