From c596a941fd9dd70a49f5eb541ffe33d4e5bc7f53 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Fri, 8 Jul 2011 15:01:04 +0800 Subject: Keep Log Out / Restart / Shut Down dialogs on top (LP: #807357) --- src/dialog.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dialog.c b/src/dialog.c index 9633224..d38f8bf 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -183,6 +183,8 @@ logout_dialog_new (LogoutDialogType type) "text", _(body_strings[type]), NULL)); + gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); + gboolean allowed = FALSE; if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART); -- cgit v1.2.3 From 8ab26b1cd3f1a5e67c6f06adf59d3de8c9bb14d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 9 Jul 2011 05:42:45 +0200 Subject: Get support for gtk+2.0 back indicator-session can still be compiled with gtk, using the --with-gtk=2 configure flag (I've changed it to match the other indicators). --- configure.ac | 45 +++++++++++++++++++++++++++++++-------------- src/session-service.c | 6 ++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 4f2cb04..f3a9039 100644 --- a/configure.ac +++ b/configure.ac @@ -31,18 +31,18 @@ INDICATOR_REQUIRED_VERSION=0.3.19 DBUSMENUGTK_REQUIRED_VERSION=0.3.91 POLKIT_REQUIRED_VERSION=0.92 -AC_ARG_WITH([indicator-gtk], - [AS_HELP_STRING([--with-indicator-gtk], +AC_ARG_WITH([gtk], + [AS_HELP_STRING([--with-gtk], [Which version of gtk to use for the indicator @<:@default=3@:>@])], [], - [with_indicator_gtk=3]) + [with_gtk=3]) -AS_IF([test "x$with_indicator_gtk" = x3], +AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= $GTK3_REQUIRED_VERSION indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) ], - [test "x$with_indicator_gtk" = x2], + [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION indicator-0.4 >= $INDICATOR_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) @@ -54,17 +54,34 @@ AC_SUBST(APPLET_LIBS) DBUSMENUGLIB_REQUIRED_VERSION=0.1.1 -PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION - dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION - dbus-glib-1 - gio-unix-2.0 - indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION) +AS_IF([test "x$with_gtk" = x3], + [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + dbus-glib-1 + gio-unix-2.0 + indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION) + ], + [test "x$with_gtk" = x2], + [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + dbus-glib-1 + gio-unix-2.0 + indicator-0.4 >= $INDICATOR_REQUIRED_VERSION) + ] +) AC_SUBST(SESSIONERVICE_CFLAGS) AC_SUBST(SESSIONERVICE_LIBS) -PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-3.0 >= $GTK3_REQUIRED_VERSION - polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) +AS_IF([test "x$with_gtk" = x3], + [PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-3.0 >= $GTK3_REQUIRED_VERSION + polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) + ], + [test "x$with_gtk" = x2], + [PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-2.0 >= $GTK_REQUIRED_VERSION + polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) + ] +) AC_SUBST(GTKLOGOUTHELPER_CFLAGS) @@ -94,7 +111,7 @@ AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall], [install all if test "x$with_localinstall" = "xyes"; then INDICATORDIR="${libdir}/indicators/2/" INDICATORICONSDIR="${datadir}/indicator-applet/icons/" -elif test "x$with_indicator_gtk" = x2; then +elif test "x$with_gtk" = x2; then INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator-0.4` INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator-0.4` else @@ -179,5 +196,5 @@ AC_MSG_NOTICE([ SUS Indicator Configuration: Prefix: $prefix - Indicator GTK: $with_indicator_gtk + Indicator GTK: $with_gtk ]) diff --git a/src/session-service.c b/src/session-service.c index dfc3805..424a3ac 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -36,7 +36,13 @@ with this program. If not, see . #include #include #include + +#include +#if GTK_CHECK_VERSION(3, 0, 0) #include +#else +#include +#endif #include -- cgit v1.2.3 From ff7cd22d1cc2ff22dc35dc7c0e513bd3423020ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 9 Jul 2011 05:57:42 +0200 Subject: configure.ac: include the indicator dir in output --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index f3a9039..c03639e 100644 --- a/configure.ac +++ b/configure.ac @@ -196,5 +196,6 @@ AC_MSG_NOTICE([ SUS Indicator Configuration: Prefix: $prefix + Indicator Dir: $INDICATORDIR Indicator GTK: $with_gtk ]) -- cgit v1.2.3 From f32ca6117a1313f39baa317900e9a297d167a479 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 15 Jul 2011 12:06:53 +0100 Subject: please tidy up that user manager --- src/Makefile.am | 4 +- src/gconf-helper.h | 6 + src/session-service.c | 269 ++++---------------------------------------- src/users-menu-mgr.c | 303 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/users-menu-mgr.h | 55 +++++++++ 5 files changed, 388 insertions(+), 249 deletions(-) create mode 100644 src/users-menu-mgr.c create mode 100644 src/users-menu-mgr.h diff --git a/src/Makefile.am b/src/Makefile.am index 71537c5..17dd041 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -91,7 +91,9 @@ indicator_session_service_SOURCES = \ dbusmenu-shared.h \ gconf-helper.c \ users-service-dbus.h \ - users-service-dbus.c + users-service-dbus.c \ + users_menu_mgr.h \ + users_menu_mgr.c indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ $(GCONF_CFLAGS) \ diff --git a/src/gconf-helper.h b/src/gconf-helper.h index 505c24f..039b309 100644 --- a/src/gconf-helper.h +++ b/src/gconf-helper.h @@ -39,6 +39,12 @@ with this program. If not, see . #define RESTART_KEY GLOBAL_DIR "/suppress_restart_menuitem" #define SHUTDOWN_KEY GLOBAL_DIR "/suppress_shutdown_menuitem" +#define LOCKDOWN_DIR "/desktop/gnome/lockdown" +#define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" +#define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" +#define KEYBINDING_DIR "/apps/gnome_settings_daemon/keybindings" +#define KEY_LOCK_SCREEN KEYBINDING_DIR "/screensaver" + typedef struct _RestartShutdownLogoutMenuItems { DbusmenuMenuitem * logout_mi; diff --git a/src/session-service.c b/src/session-service.c index fb6ce37..78cd9ae 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -43,26 +43,22 @@ with this program. If not, see . #include "dbus-shared-names.h" #include "dbusmenu-shared.h" +#include "users-service-dbus.h" +#include "users-menu-mgr.h" #include "gconf-helper.h" #include "session-dbus.h" -#include "users-service-dbus.h" #include "lock-helper.h" #include "upower-client.h" + #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" #define UP_INTERFACE "org.freedesktop.UPower" #define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" -#define LOCKDOWN_DIR "/desktop/gnome/lockdown" -#define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" -#define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" - -#define KEYBINDING_DIR "/apps/gnome_settings_daemon/keybindings" -#define KEY_LOCK_SCREEN KEYBINDING_DIR "/screensaver" typedef struct _ActivateData ActivateData; struct _ActivateData @@ -71,14 +67,10 @@ struct _ActivateData UserData *user; }; -static UsersServiceDbus *dbus_interface = NULL; +//static UsersServiceDbus *dbus_interface = NULL; static SessionDbus *session_dbus = NULL; - static DbusmenuMenuitem *lock_menuitem = NULL; -static DbusmenuMenuitem *switch_menuitem = NULL; - static DbusmenuMenuitem * session_root_menuitem = NULL; -static DbusmenuMenuitem * users_root_menuitem = NULL; static GMainLoop * mainloop = NULL; static DBusGProxy * up_main_proxy = NULL; @@ -100,9 +92,7 @@ static gboolean allow_suspend = TRUE; static GConfClient * gconf_client = NULL; -static void rebuild_session_items (DbusmenuMenuitem *root, UsersServiceDbus *service); -static void rebuild_user_items (DbusmenuMenuitem *root, UsersServiceDbus *service); -static void activate_online_accounts (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data); +static void rebuild_session_items (DbusmenuMenuitem *root); static void lockdown_changed (GConfClient *client, @@ -118,7 +108,7 @@ lockdown_changed (GConfClient *client, } if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { - rebuild_session_items(session_root_menuitem, dbus_interface); + rebuild_session_items(session_root_menuitem); } return; @@ -228,7 +218,7 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) gboolean local_can_suspend = g_value_get_boolean(&candoit); if (local_can_suspend != can_suspend) { can_suspend = local_can_suspend; - rebuild_session_items(session_root_menuitem, dbus_interface); + rebuild_session_items(session_root_menuitem); } return; @@ -253,7 +243,7 @@ hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) gboolean local_can_hibernate = g_value_get_boolean(&candoit); if (local_can_hibernate != can_hibernate) { can_hibernate = local_can_hibernate; - rebuild_session_items(session_root_menuitem, dbus_interface); + rebuild_session_items(session_root_menuitem); } return; @@ -314,7 +304,7 @@ allowed_cb (DBusGProxy *proxy, gboolean OUT_allowed, GError *error, gpointer use if (OUT_allowed != *can_do) { *can_do = OUT_allowed; - rebuild_session_items (session_root_menuitem, dbus_interface); + rebuild_session_items (session_root_menuitem); } } @@ -391,216 +381,10 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) return; } -/* Checks to see if we can create sessions */ -static gboolean -check_new_session (void) -{ - return TRUE; -} - -/* Starts a new generic session */ -static void -activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) -{ - lock_if_possible(); - - users_service_dbus_show_greeter (USERS_SERVICE_DBUS(user_data)); - - return; -} -/* Activates a session for a particular user. */ static void -activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) -{ - UserData *user = (UserData *)user_data; - UsersServiceDbus *service = user->service; - - lock_if_possible(); - - users_service_dbus_activate_user_session (service, user); -} - -/* Comparison function to look into the UserData struct - to compare by using the username value */ -static gint -compare_users_by_username (const gchar *a, - const gchar *b) -{ - UserData *user1 = (UserData *)a; - UserData *user2 = (UserData *)b; - - gint retval = g_strcmp0 (user1->real_name, user2->real_name); - - /* If they're the same, they're both in conflict. */ - if (retval == 0) { - user1->real_name_conflict = TRUE; - user2->real_name_conflict = TRUE; - } - - return retval; -} - -/* Builds up the menu for us */ -static void -rebuild_user_items (DbusmenuMenuitem *root, - UsersServiceDbus *service) -{ - DbusmenuMenuitem *mi = NULL; - DbusmenuMenuitem *guest_mi = NULL; - GList *u; - UserData *user; - gboolean can_activate; - GList *children; - - /* Make sure we have a valid GConf client, and build one - if needed */ - ensure_gconf_client (); - - /* Check to see which menu items we're allowed to have */ - can_activate = users_service_dbus_can_activate_session (service) && - !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); - - /* Remove the old menu items if that makes sense */ - children = dbusmenu_menuitem_take_children (root); - g_list_foreach (children, (GFunc)g_object_unref, NULL); - g_list_free (children); - - /* Set to NULL just incase we don't end up building one */ - users_service_dbus_set_guest_item(service, NULL); - - /* Build all of the user switching items */ - if (can_activate == TRUE) - { - if (check_new_session ()){ - switch_menuitem = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (switch_menuitem, - DBUSMENU_MENUITEM_PROP_TYPE, - MENU_SWITCH_TYPE); - dbusmenu_menuitem_property_set (switch_menuitem, - MENU_SWITCH_USER, - g_get_user_name()); - dbusmenu_menuitem_child_append (root, switch_menuitem); - g_signal_connect (G_OBJECT (switch_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_new_session), - service); - } - - 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); - } - - for (u = users; u != NULL; u = g_list_next (u)) { - user = u->data; - user->service = service; - - g_debug ("%i %s", (gint)user->uid, user->user_name); - - if (g_strcmp0(user->user_name, "guest") == 0) { - /* Check to see if the guest has sessions and so therefore should - get a check mark. */ - if (user->sessions != NULL) { - dbusmenu_menuitem_property_set_bool (guest_mi, - USER_ITEM_PROP_LOGGED_IN, - TRUE); - } - /* If we're showing user accounts, keep going through the list */ - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - continue; - } - /* If not, we can stop here */ - break; - } - - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - if (user->real_name_conflict) { - gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); - g_free(conflictedname); - } else { - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); - } - dbusmenu_menuitem_property_set_bool (mi, - USER_ITEM_PROP_LOGGED_IN, - user->sessions != NULL); - if (user->icon_file != NULL && user->icon_file[0] != '\0') { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_file); - } else { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); - } - - gboolean logged_in = g_strcmp0 (user->user_name, g_get_user_name()) == 0; - dbusmenu_menuitem_property_set_bool (mi, - USER_ITEM_PROP_IS_CURRENT_USER, - logged_in); - if (logged_in == TRUE){ - g_debug ("about to set the users real name to %s for user %s", - user->real_name, user->user_name); - session_dbus_set_users_real_name (session_dbus, user->real_name); - } - - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_user_session), - user); - user->menuitem = mi; - } - } - g_list_free(users); - } - // Add the online accounts and separator - DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (separator1, - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append (root, separator1); - DbusmenuMenuitem * online_accounts_item = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (online_accounts_item, - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_CLIENT_TYPES_DEFAULT); - dbusmenu_menuitem_property_set (online_accounts_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Online Accounts...")); - - g_signal_connect (G_OBJECT (online_accounts_item), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_online_accounts), - NULL); - - dbusmenu_menuitem_child_append (root, online_accounts_item); -} - -// TODO -// Wait until dialog is complete to find out name to pass -// to the control centre. -static void -activate_online_accounts (DbusmenuMenuitem *mi, - guint timestamp, - gpointer user_data) -{ - GError * error = NULL; - if (!g_spawn_command_line_async("gnome-control-center online-accounts", &error)) - { - g_warning("Unable to show control centre: %s", error->message); - g_error_free(error); - } -} - -static void -rebuild_session_items (DbusmenuMenuitem *root, - UsersServiceDbus *service) +rebuild_session_items (DbusmenuMenuitem *root) + { gboolean can_lockscreen; @@ -725,17 +509,6 @@ rebuild_session_items (DbusmenuMenuitem *root, return; } -/* Signal called when a user is added. It updates the count and - rebuilds the menu */ -static void -user_change (UsersServiceDbus *service, - const gchar *user_id, - gpointer user_data) -{ - DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - rebuild_user_items (root, service); - return; -} /* When the service interface starts to shutdown, we should follow it. */ @@ -819,18 +592,18 @@ main (int argc, char ** argv) g_idle_add(lock_screen_setup, NULL); session_root_menuitem = dbusmenu_menuitem_new(); - g_debug("Session Root ID: %d", dbusmenu_menuitem_get_id(session_root_menuitem)); - - dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); - - rebuild_session_items (session_root_menuitem, dbus_interface); + rebuild_session_items (session_root_menuitem); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); dbusmenu_server_set_root(server, session_root_menuitem); - users_root_menuitem = dbusmenu_menuitem_new(); - rebuild_user_items (users_root_menuitem, dbus_interface); - g_signal_connect (G_OBJECT (dbus_interface), + + // Users + UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL); + + //users_root_menuitem = dbusmenu_menuitem_new(); + //rebuild_user_items (users_root_menuitem, dbus_interface); + /*g_signal_connect (G_OBJECT (dbus_interface), "user-added", G_CALLBACK (user_change), users_root_menuitem); @@ -838,13 +611,13 @@ main (int argc, char ** argv) "user-removed", G_CALLBACK (user_change), users_root_menuitem); + */ setup_restart_watch(); - setup_up(); DbusmenuServer * users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); - dbusmenu_server_set_root (users_server, users_root_menuitem); + dbusmenu_server_set_root (users_server, user_mgr->root_item); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/src/users-menu-mgr.c b/src/users-menu-mgr.c new file mode 100644 index 0000000..a736dfd --- /dev/null +++ b/src/users-menu-mgr.c @@ -0,0 +1,303 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * user-menu-mgr.c + * Copyright (C) Conor Curran 2011 + * + * user-menu-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * user-menu-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#include "user-menu-mgr.h" +#include "gconf-helper.h" +#include "users-service-dbus.h" + +static GConfClient * gconf_client = NULL; +static DbusmenuMenuitem *switch_menuitem = NULL; + +G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); + +static void activate_new_session (DbusmenuMenuitem * mi, + guint timestamp, + gpointer user_data); +static void activate_user_session (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data) +static gint compare_users_by_username (const gchar *a, + const gchar *b); +static void activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data); + +static void +user_menu_mgr_init (UserMenuMgr *self) +{ + self->users_dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); + self->root_item = dbusmenu_menuitem_new (); + user_menu_mgr_rebuild_items (self); +} + +static void +user_menu_mgr_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + G_OBJECT_CLASS (user_menu_mgr_parent_class)->finalize (object); +} + +static void +user_menu_mgr_class_init (UserMenuMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + object_class->finalize = user_menu_mgr_finalize; +} + +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +ensure_gconf_client () +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); + gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL); + } +} + +/* Builds up the menu for us */ +static void +user_menu_mgr_rebuild_items (UserMenuMgr *self) +{ + DbusmenuMenuitem *mi = NULL; + DbusmenuMenuitem *guest_mi = NULL; + GList *u; + UserData *user; + gboolean can_activate; + GList *children; + + /* Make sure we have a valid GConf client, and build one + if needed */ + ensure_gconf_client (); + + /* Check to see which menu items we're allowed to have */ + can_activate = users_service_dbus_can_activate_session (service) && + !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); + + /* Remove the old menu items if that makes sense */ + children = dbusmenu_menuitem_take_children (root); + g_list_foreach (children, (GFunc)g_object_unref, NULL); + g_list_free (children); + + /* Set to NULL just incase we don't end up building one */ + users_service_dbus_set_guest_item(service, NULL); + + /* Build all of the user switching items */ + if (can_activate == TRUE) + { + if (check_new_session ()){ + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, + DBUSMENU_MENUITEM_PROP_TYPE, + MENU_SWITCH_TYPE); + dbusmenu_menuitem_property_set (switch_menuitem, + MENU_SWITCH_USER, + g_get_user_name()); + dbusmenu_menuitem_child_append (self->root, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_new_session), + service); + } + + GList * users = NULL; + users = users_service_dbus_get_user_list (service); + self->user_count = g_list_length(users); + + // TODO !!!!! + // 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 (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + } + + for (u = users; u != NULL; u = g_list_next (u)) { + user = u->data; + user->service = service; + + g_debug ("%i %s", (gint)user->uid, user->user_name); + + if (g_strcmp0(user->user_name, "guest") == 0) { + /* Check to see if the guest has sessions and so therefore should + get a check mark. */ + if (user->sessions != NULL) { + dbusmenu_menuitem_property_set_bool (guest_mi, + USER_ITEM_PROP_LOGGED_IN, + TRUE); + } + /* If we're showing user accounts, keep going through the list */ + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + continue; + } + /* If not, we can stop here */ + break; + } + + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); + if (user->real_name_conflict) { + gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); + g_free(conflictedname); + } else { + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); + } + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_LOGGED_IN, + user->sessions != NULL); + if (user->icon_file != NULL && user->icon_file[0] != '\0') { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_file); + } else { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); + } + + gboolean logged_in = g_strcmp0 (user->user_name, g_get_user_name()) == 0; + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_IS_CURRENT_USER, + logged_in); + // TODO + // Figure where this lives. + if (logged_in == TRUE){ + g_debug ("about to set the users real name to %s for user %s", + user->real_name, user->user_name); + session_dbus_set_users_real_name (session_dbus, user->real_name); + } + + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_user_session), + user); + user->menuitem = mi; + } + } + g_list_free(users); + } + // Add the online accounts and separator + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (self->root_item, separator1); + DbusmenuMenuitem * online_accounts_item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_DEFAULT); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Online Accounts...")); + + g_signal_connect (G_OBJECT (online_accounts_item), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_online_accounts), + NULL); + + dbusmenu_menuitem_child_append (self->root_item, online_accounts_item); +} + +/* Checks to see if we can create sessions */ +// TODO what is this ? +static gboolean +check_new_session (void) +{ + return TRUE; +} + +/* Starts a new generic session */ +static void +activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) +{ + lock_if_possible(); + + users_service_dbus_show_greeter (USERS_SERVICE_DBUS(user_data)); + + return; +} + +/* Activates a session for a particular user. */ +static void +activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) +{ + UserData *user = (UserData *)user_data; + UsersServiceDbus *service = user->service; + + lock_if_possible(); + + users_service_dbus_activate_user_session (service, user); +} + +/* Comparison function to look into the UserData struct + to compare by using the username value */ +static gint +compare_users_by_username (const gchar *a, + const gchar *b) +{ + UserData *user1 = (UserData *)a; + UserData *user2 = (UserData *)b; + + gint retval = g_strcmp0 (user1->real_name, user2->real_name); + + /* If they're the same, they're both in conflict. */ + if (retval == 0) { + user1->real_name_conflict = TRUE; + user2->real_name_conflict = TRUE; + } + + return retval; +} + +// TODO +// Wait until dialog is complete to find out name to pass +// to the control centre. +static void +activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("gnome-control-center online-accounts", &error)) + { + g_warning("Unable to show control centre: %s", error->message); + g_error_free(error); + } +} + +/* Signal called when a user is added. It updates the count and + rebuilds the menu */ +static void +user_change (UsersServiceDbus *service, + const gchar *user_id, + gpointer user_data) +{ + DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + rebuild_user_items (root, service); + return; +} + + diff --git a/src/users-menu-mgr.h b/src/users-menu-mgr.h new file mode 100644 index 0000000..c573b91 --- /dev/null +++ b/src/users-menu-mgr.h @@ -0,0 +1,55 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * user-menu-mgr.c + * Copyright (C) Conor Curran 2011 + * + * user-menu-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * user-menu-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#ifndef _USER_MENU_MGR_H_ +#define _USER_MENU_MGR_H_ + +#include + +G_BEGIN_DECLS + +#define USER_TYPE_MENU_MGR (user_menu_mgr_get_type ()) +#define USER_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USER_TYPE_MENU_MGR, UserMenuMgr)) +#define USER_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USER_TYPE_MENU_MGR, UserMenuMgrClass)) +#define USER_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USER_TYPE_MENU_MGR)) +#define USER_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USER_TYPE_MENU_MGR)) +#define USER_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USER_TYPE_MENU_MGR, UserMenuMgrClass)) + +typedef struct _UserMenuMgrClass UserMenuMgrClass; +typedef struct _UserMenuMgr UserMenuMgr; + +struct _UserMenuMgrClass +{ + GObjectClass parent_class; +}; + +struct _UserMenuMgr +{ + GObject parent_instance; + UsersServiceDbus* users_dbus_interface; + DbusmenuMenuitem* root_item; + gint user_count; +}; + +GType user_menu_mgr_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _USER_MENU_MGR_H_ */ -- cgit v1.2.3 From a25c68ce0d98e56921f38683a81e6d996446f744 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 15 Jul 2011 12:07:46 +0100 Subject: please tidy up that user manager --- src/users-menu-mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/users-menu-mgr.c b/src/users-menu-mgr.c index a736dfd..baf08ab 100644 --- a/src/users-menu-mgr.c +++ b/src/users-menu-mgr.c @@ -18,7 +18,7 @@ */ -#include "user-menu-mgr.h" +#include "users-menu-mgr.h" #include "gconf-helper.h" #include "users-service-dbus.h" -- cgit v1.2.3 From 019030dc92107fb553e1f791cc2225b67b74968b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 15 Jul 2011 12:54:17 +0100 Subject: first step - it compiles --- src/Makefile.am | 4 +- src/session-service.c | 20 +-- src/user-menu-mgr.c | 336 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/user-menu-mgr.h | 56 +++++++++ src/users-menu-mgr.c | 303 --------------------------------------------- src/users-menu-mgr.h | 55 --------- 6 files changed, 397 insertions(+), 377 deletions(-) create mode 100644 src/user-menu-mgr.c create mode 100644 src/user-menu-mgr.h delete mode 100644 src/users-menu-mgr.c delete mode 100644 src/users-menu-mgr.h diff --git a/src/Makefile.am b/src/Makefile.am index 17dd041..9bf43cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -92,8 +92,8 @@ indicator_session_service_SOURCES = \ gconf-helper.c \ users-service-dbus.h \ users-service-dbus.c \ - users_menu_mgr.h \ - users_menu_mgr.c + user-menu-mgr.h \ + user-menu-mgr.c indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ $(GCONF_CFLAGS) \ diff --git a/src/session-service.c b/src/session-service.c index 78cd9ae..6095838 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -44,7 +44,7 @@ with this program. If not, see . #include "dbus-shared-names.h" #include "dbusmenu-shared.h" #include "users-service-dbus.h" -#include "users-menu-mgr.h" +#include "user-menu-mgr.h" #include "gconf-helper.h" @@ -52,7 +52,6 @@ with this program. If not, see . #include "lock-helper.h" #include "upower-client.h" - #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" #define UP_INTERFACE "org.freedesktop.UPower" @@ -160,9 +159,8 @@ lock_if_possible (void) { ensure_gconf_client (); if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { - lock_screen(NULL, 0, NULL); + lock_screen (NULL, 0, NULL); } - return; } @@ -600,19 +598,7 @@ main (int argc, char ** argv) // Users UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL); - - //users_root_menuitem = dbusmenu_menuitem_new(); - //rebuild_user_items (users_root_menuitem, dbus_interface); - /*g_signal_connect (G_OBJECT (dbus_interface), - "user-added", - G_CALLBACK (user_change), - users_root_menuitem); - g_signal_connect (G_OBJECT (dbus_interface), - "user-removed", - G_CALLBACK (user_change), - users_root_menuitem); - */ - + setup_restart_watch(); setup_up(); diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c new file mode 100644 index 0000000..404114a --- /dev/null +++ b/src/user-menu-mgr.c @@ -0,0 +1,336 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * user-menu-mgr.c + * Copyright (C) Conor Curran 2011 + * + * user-menu-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * user-menu-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#include +#include + +#include "user-menu-mgr.h" +#include "gconf-helper.h" +#include "dbus-shared-names.h" +#include "dbusmenu-shared.h" +#include "lock-helper.h" + + +static GConfClient * gconf_client = NULL; +static DbusmenuMenuitem *switch_menuitem = NULL; + +G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); + +static void activate_new_session (DbusmenuMenuitem * mi, + guint timestamp, + gpointer user_data); +static void activate_user_session (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data); +static gint compare_users_by_username (const gchar *a, + const gchar *b); +static void activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data); +static void user_menu_mgr_rebuild_items (UserMenuMgr *self); +static gboolean check_new_session (); +static void user_change (UsersServiceDbus *service, + const gchar *user_id, + gpointer user_data); + + +static void +user_menu_mgr_init (UserMenuMgr *self) +{ + self->users_dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); + self->root_item = dbusmenu_menuitem_new (); + user_menu_mgr_rebuild_items (self); + g_signal_connect (G_OBJECT (self->users_dbus_interface), + "user-added", + G_CALLBACK (user_change), + self); + g_signal_connect (G_OBJECT (self->users_dbus_interface), + "user-removed", + G_CALLBACK (user_change), + self); +} + +static void +user_menu_mgr_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + G_OBJECT_CLASS (user_menu_mgr_parent_class)->finalize (object); +} + +static void +user_menu_mgr_class_init (UserMenuMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + //GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + object_class->finalize = user_menu_mgr_finalize; +} + +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +ensure_gconf_client () +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir (gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_add_dir (gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + } +} + +/* Builds up the menu for us */ +static void +user_menu_mgr_rebuild_items (UserMenuMgr *self) +{ + DbusmenuMenuitem *mi = NULL; + DbusmenuMenuitem *guest_mi = NULL; + GList *u; + UserData *user; + gboolean can_activate; + GList *children; + + /* Make sure we have a valid GConf client, and build one + if needed */ + ensure_gconf_client (); + + /* Check to see which menu items we're allowed to have */ + can_activate = users_service_dbus_can_activate_session (self->users_dbus_interface) && + !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); + + /* Remove the old menu items if that makes sense */ + children = dbusmenu_menuitem_take_children (self->root_item); + g_list_foreach (children, (GFunc)g_object_unref, NULL); + g_list_free (children); + + /* Set to NULL just incase we don't end up building one */ + users_service_dbus_set_guest_item(self->users_dbus_interface, NULL); + + /* Build all of the user switching items */ + if (can_activate == TRUE) + { + if (check_new_session ()){ + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, + DBUSMENU_MENUITEM_PROP_TYPE, + MENU_SWITCH_TYPE); + dbusmenu_menuitem_property_set (switch_menuitem, + MENU_SWITCH_USER, + g_get_user_name()); + dbusmenu_menuitem_child_append (self->root_item, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_new_session), + self->users_dbus_interface); + } + + GList * users = NULL; + users = users_service_dbus_get_user_list (self->users_dbus_interface); + self->user_count = g_list_length(users); + + // TODO !!!!! + // 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 (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + } + + for (u = users; u != NULL; u = g_list_next (u)) { + user = u->data; + user->service = self->users_dbus_interface; + + g_debug ("%i %s", (gint)user->uid, user->user_name); + + if (g_strcmp0(user->user_name, "guest") == 0) { + /* Check to see if the guest has sessions and so therefore should + get a check mark. */ + if (user->sessions != NULL) { + dbusmenu_menuitem_property_set_bool (guest_mi, + USER_ITEM_PROP_LOGGED_IN, + TRUE); + } + /* If we're showing user accounts, keep going through the list */ + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + continue; + } + /* If not, we can stop here */ + break; + } + + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); + if (user->real_name_conflict) { + gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); + g_free(conflictedname); + } else { + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); + } + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_LOGGED_IN, + user->sessions != NULL); + if (user->icon_file != NULL && user->icon_file[0] != '\0') { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_file); + } else { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); + } + + gboolean logged_in = g_strcmp0 (user->user_name, g_get_user_name()) == 0; + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_IS_CURRENT_USER, + logged_in); + // TODO + // Figure where this lives. + /*if (logged_in == TRUE){ + g_debug ("about to set the users real name to %s for user %s", + user->real_name, user->user_name); + session_dbus_set_users_real_name (session_dbus, user->real_name); + }*/ + + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_user_session), + user); + user->menuitem = mi; + } + } + g_list_free(users); + } + // Add the online accounts and separator + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (self->root_item, separator1); + DbusmenuMenuitem * online_accounts_item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_DEFAULT); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Online Accounts...")); + + g_signal_connect (G_OBJECT (online_accounts_item), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_online_accounts), + NULL); + + dbusmenu_menuitem_child_append (self->root_item, online_accounts_item); +} + +/* Checks to see if we can create sessions */ +// TODO what is this ? +static gboolean +check_new_session () +{ + return TRUE; +} + +/* Check to see if the lockdown key is protecting from + locking the screen. If not, lock it. */ +static void +lock_if_possible (void) { + ensure_gconf_client (); + + if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { + lock_screen(NULL, 0, NULL); + } + + return; +} + + +/* Starts a new generic session */ +static void +activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) +{ + lock_if_possible(); + + users_service_dbus_show_greeter (USERS_SERVICE_DBUS(user_data)); + + return; +} + +/* Activates a session for a particular user. */ +static void +activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) +{ + UserData *user = (UserData *)user_data; + UsersServiceDbus *service = user->service; + + lock_if_possible(); + + users_service_dbus_activate_user_session (service, user); +} + +/* Comparison function to look into the UserData struct + to compare by using the username value */ +static gint +compare_users_by_username (const gchar *a, + const gchar *b) +{ + UserData *user1 = (UserData *)a; + UserData *user2 = (UserData *)b; + + gint retval = g_strcmp0 (user1->real_name, user2->real_name); + + /* If they're the same, they're both in conflict. */ + if (retval == 0) { + user1->real_name_conflict = TRUE; + user2->real_name_conflict = TRUE; + } + + return retval; +} + +// TODO +// Wait until dialog is complete to find out name to pass +// to the control centre. +static void +activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("gnome-control-center online-accounts", &error)) + { + g_warning("Unable to show control centre: %s", error->message); + g_error_free(error); + } +} + +/* Signal called when a user is added. It updates the count and + rebuilds the menu */ +static void +user_change (UsersServiceDbus *service, + const gchar *user_id, + gpointer user_data) +{ + //DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + // TODO sort this out. + //rebuild_user_items (root, service); + return; +} + + diff --git a/src/user-menu-mgr.h b/src/user-menu-mgr.h new file mode 100644 index 0000000..214c9c7 --- /dev/null +++ b/src/user-menu-mgr.h @@ -0,0 +1,56 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * user-menu-mgr.c + * Copyright (C) Conor Curran 2011 + * + * user-menu-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * user-menu-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#ifndef _USER_MENU_MGR_H_ +#define _USER_MENU_MGR_H_ + +#include +#include "users-service-dbus.h" + +G_BEGIN_DECLS + +#define USER_TYPE_MENU_MGR (user_menu_mgr_get_type ()) +#define USER_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USER_TYPE_MENU_MGR, UserMenuMgr)) +#define USER_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USER_TYPE_MENU_MGR, UserMenuMgrClass)) +#define USER_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USER_TYPE_MENU_MGR)) +#define USER_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USER_TYPE_MENU_MGR)) +#define USER_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USER_TYPE_MENU_MGR, UserMenuMgrClass)) + +typedef struct _UserMenuMgrClass UserMenuMgrClass; +typedef struct _UserMenuMgr UserMenuMgr; + +struct _UserMenuMgrClass +{ + GObjectClass parent_class; +}; + +struct _UserMenuMgr +{ + GObject parent_instance; + UsersServiceDbus* users_dbus_interface; + DbusmenuMenuitem* root_item; + gint user_count; +}; + +GType user_menu_mgr_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _USER_MENU_MGR_H_ */ diff --git a/src/users-menu-mgr.c b/src/users-menu-mgr.c deleted file mode 100644 index baf08ab..0000000 --- a/src/users-menu-mgr.c +++ /dev/null @@ -1,303 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ -/* - * user-menu-mgr.c - * Copyright (C) Conor Curran 2011 - * - * user-menu-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * user-menu-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - - */ - -#include "users-menu-mgr.h" -#include "gconf-helper.h" -#include "users-service-dbus.h" - -static GConfClient * gconf_client = NULL; -static DbusmenuMenuitem *switch_menuitem = NULL; - -G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); - -static void activate_new_session (DbusmenuMenuitem * mi, - guint timestamp, - gpointer user_data); -static void activate_user_session (DbusmenuMenuitem *mi, - guint timestamp, - gpointer user_data) -static gint compare_users_by_username (const gchar *a, - const gchar *b); -static void activate_online_accounts (DbusmenuMenuitem *mi, - guint timestamp, - gpointer user_data); - -static void -user_menu_mgr_init (UserMenuMgr *self) -{ - self->users_dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); - self->root_item = dbusmenu_menuitem_new (); - user_menu_mgr_rebuild_items (self); -} - -static void -user_menu_mgr_finalize (GObject *object) -{ - /* TODO: Add deinitalization code here */ - G_OBJECT_CLASS (user_menu_mgr_parent_class)->finalize (object); -} - -static void -user_menu_mgr_class_init (UserMenuMgrClass *klass) -{ - GObjectClass* object_class = G_OBJECT_CLASS (klass); - GObjectClass* parent_class = G_OBJECT_CLASS (klass); - - object_class->finalize = user_menu_mgr_finalize; -} - -/* Ensures that we have a GConf client and if we build one - set up the signal handler. */ -static void -ensure_gconf_client () -{ - if (!gconf_client) { - gconf_client = gconf_client_get_default (); - gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); - gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL); - } -} - -/* Builds up the menu for us */ -static void -user_menu_mgr_rebuild_items (UserMenuMgr *self) -{ - DbusmenuMenuitem *mi = NULL; - DbusmenuMenuitem *guest_mi = NULL; - GList *u; - UserData *user; - gboolean can_activate; - GList *children; - - /* Make sure we have a valid GConf client, and build one - if needed */ - ensure_gconf_client (); - - /* Check to see which menu items we're allowed to have */ - can_activate = users_service_dbus_can_activate_session (service) && - !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); - - /* Remove the old menu items if that makes sense */ - children = dbusmenu_menuitem_take_children (root); - g_list_foreach (children, (GFunc)g_object_unref, NULL); - g_list_free (children); - - /* Set to NULL just incase we don't end up building one */ - users_service_dbus_set_guest_item(service, NULL); - - /* Build all of the user switching items */ - if (can_activate == TRUE) - { - if (check_new_session ()){ - switch_menuitem = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (switch_menuitem, - DBUSMENU_MENUITEM_PROP_TYPE, - MENU_SWITCH_TYPE); - dbusmenu_menuitem_property_set (switch_menuitem, - MENU_SWITCH_USER, - g_get_user_name()); - dbusmenu_menuitem_child_append (self->root, switch_menuitem); - g_signal_connect (G_OBJECT (switch_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_new_session), - service); - } - - GList * users = NULL; - users = users_service_dbus_get_user_list (service); - self->user_count = g_list_length(users); - - // TODO !!!!! - // 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 (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { - users = g_list_sort (users, (GCompareFunc)compare_users_by_username); - } - - for (u = users; u != NULL; u = g_list_next (u)) { - user = u->data; - user->service = service; - - g_debug ("%i %s", (gint)user->uid, user->user_name); - - if (g_strcmp0(user->user_name, "guest") == 0) { - /* Check to see if the guest has sessions and so therefore should - get a check mark. */ - if (user->sessions != NULL) { - dbusmenu_menuitem_property_set_bool (guest_mi, - USER_ITEM_PROP_LOGGED_IN, - TRUE); - } - /* If we're showing user accounts, keep going through the list */ - if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { - continue; - } - /* If not, we can stop here */ - break; - } - - if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - if (user->real_name_conflict) { - gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); - g_free(conflictedname); - } else { - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); - } - dbusmenu_menuitem_property_set_bool (mi, - USER_ITEM_PROP_LOGGED_IN, - user->sessions != NULL); - if (user->icon_file != NULL && user->icon_file[0] != '\0') { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_file); - } else { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); - } - - gboolean logged_in = g_strcmp0 (user->user_name, g_get_user_name()) == 0; - dbusmenu_menuitem_property_set_bool (mi, - USER_ITEM_PROP_IS_CURRENT_USER, - logged_in); - // TODO - // Figure where this lives. - if (logged_in == TRUE){ - g_debug ("about to set the users real name to %s for user %s", - user->real_name, user->user_name); - session_dbus_set_users_real_name (session_dbus, user->real_name); - } - - dbusmenu_menuitem_child_append (self->root_item, mi); - g_signal_connect (G_OBJECT (mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_user_session), - user); - user->menuitem = mi; - } - } - g_list_free(users); - } - // Add the online accounts and separator - DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (separator1, - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append (self->root_item, separator1); - DbusmenuMenuitem * online_accounts_item = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (online_accounts_item, - DBUSMENU_MENUITEM_PROP_TYPE, - DBUSMENU_CLIENT_TYPES_DEFAULT); - dbusmenu_menuitem_property_set (online_accounts_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Online Accounts...")); - - g_signal_connect (G_OBJECT (online_accounts_item), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_online_accounts), - NULL); - - dbusmenu_menuitem_child_append (self->root_item, online_accounts_item); -} - -/* Checks to see if we can create sessions */ -// TODO what is this ? -static gboolean -check_new_session (void) -{ - return TRUE; -} - -/* Starts a new generic session */ -static void -activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) -{ - lock_if_possible(); - - users_service_dbus_show_greeter (USERS_SERVICE_DBUS(user_data)); - - return; -} - -/* Activates a session for a particular user. */ -static void -activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) -{ - UserData *user = (UserData *)user_data; - UsersServiceDbus *service = user->service; - - lock_if_possible(); - - users_service_dbus_activate_user_session (service, user); -} - -/* Comparison function to look into the UserData struct - to compare by using the username value */ -static gint -compare_users_by_username (const gchar *a, - const gchar *b) -{ - UserData *user1 = (UserData *)a; - UserData *user2 = (UserData *)b; - - gint retval = g_strcmp0 (user1->real_name, user2->real_name); - - /* If they're the same, they're both in conflict. */ - if (retval == 0) { - user1->real_name_conflict = TRUE; - user2->real_name_conflict = TRUE; - } - - return retval; -} - -// TODO -// Wait until dialog is complete to find out name to pass -// to the control centre. -static void -activate_online_accounts (DbusmenuMenuitem *mi, - guint timestamp, - gpointer user_data) -{ - GError * error = NULL; - if (!g_spawn_command_line_async("gnome-control-center online-accounts", &error)) - { - g_warning("Unable to show control centre: %s", error->message); - g_error_free(error); - } -} - -/* Signal called when a user is added. It updates the count and - rebuilds the menu */ -static void -user_change (UsersServiceDbus *service, - const gchar *user_id, - gpointer user_data) -{ - DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - rebuild_user_items (root, service); - return; -} - - diff --git a/src/users-menu-mgr.h b/src/users-menu-mgr.h deleted file mode 100644 index c573b91..0000000 --- a/src/users-menu-mgr.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ -/* - * user-menu-mgr.c - * Copyright (C) Conor Curran 2011 - * - * user-menu-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * user-menu-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - - */ - -#ifndef _USER_MENU_MGR_H_ -#define _USER_MENU_MGR_H_ - -#include - -G_BEGIN_DECLS - -#define USER_TYPE_MENU_MGR (user_menu_mgr_get_type ()) -#define USER_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USER_TYPE_MENU_MGR, UserMenuMgr)) -#define USER_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USER_TYPE_MENU_MGR, UserMenuMgrClass)) -#define USER_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USER_TYPE_MENU_MGR)) -#define USER_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USER_TYPE_MENU_MGR)) -#define USER_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USER_TYPE_MENU_MGR, UserMenuMgrClass)) - -typedef struct _UserMenuMgrClass UserMenuMgrClass; -typedef struct _UserMenuMgr UserMenuMgr; - -struct _UserMenuMgrClass -{ - GObjectClass parent_class; -}; - -struct _UserMenuMgr -{ - GObject parent_instance; - UsersServiceDbus* users_dbus_interface; - DbusmenuMenuitem* root_item; - gint user_count; -}; - -GType user_menu_mgr_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* _USER_MENU_MGR_H_ */ -- cgit v1.2.3 From 797cf05a2f643dfed7b70db6abf2095f1216aa89 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 15 Jul 2011 16:26:37 +0100 Subject: user menu nicely separated for now, next the session menu --- src/session-service.c | 8 +++--- src/user-menu-mgr.c | 74 +++++++++++++++++++++++++++++++++------------------ src/user-menu-mgr.h | 15 +++++------ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 6095838..23cb6ab 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -595,15 +595,15 @@ main (int argc, char ** argv) DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); dbusmenu_server_set_root(server, session_root_menuitem); - // Users - UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL); + UserMenuMgr* user_mgr = user_menu_mgr_new (session_dbus); setup_restart_watch(); setup_up(); - DbusmenuServer * users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); - dbusmenu_server_set_root (users_server, user_mgr->root_item); + DbusmenuServer* users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); + + dbusmenu_server_set_root (users_server, user_mgr_get_root_item (user_mgr)); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c index 404114a..8338739 100644 --- a/src/user-menu-mgr.c +++ b/src/user-menu-mgr.c @@ -18,7 +18,6 @@ */ -#include #include #include "user-menu-mgr.h" @@ -26,12 +25,19 @@ #include "dbus-shared-names.h" #include "dbusmenu-shared.h" #include "lock-helper.h" - +#include "users-service-dbus.h" static GConfClient * gconf_client = NULL; static DbusmenuMenuitem *switch_menuitem = NULL; -G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); +struct _UserMenuMgr +{ + GObject parent_instance; + UsersServiceDbus* users_dbus_interface; + DbusmenuMenuitem* root_item; + gint user_count; + SessionDbus* session_dbus_interface; +}; static void activate_new_session (DbusmenuMenuitem * mi, guint timestamp, @@ -50,13 +56,16 @@ static void user_change (UsersServiceDbus *service, const gchar *user_id, gpointer user_data); +static void ensure_gconf_client (); + +G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); + static void user_menu_mgr_init (UserMenuMgr *self) { self->users_dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); self->root_item = dbusmenu_menuitem_new (); - user_menu_mgr_rebuild_items (self); g_signal_connect (G_OBJECT (self->users_dbus_interface), "user-added", G_CALLBACK (user_change), @@ -83,18 +92,6 @@ user_menu_mgr_class_init (UserMenuMgrClass *klass) object_class->finalize = user_menu_mgr_finalize; } -/* Ensures that we have a GConf client and if we build one - set up the signal handler. */ -static void -ensure_gconf_client () -{ - if (!gconf_client) { - gconf_client = gconf_client_get_default (); - gconf_client_add_dir (gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_add_dir (gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - } -} - /* Builds up the menu for us */ static void user_menu_mgr_rebuild_items (UserMenuMgr *self) @@ -144,11 +141,8 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self) users = users_service_dbus_get_user_list (self->users_dbus_interface); self->user_count = g_list_length(users); - // TODO !!!!! - // 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); + g_debug ("USER COUNT = %i", self->user_count); + session_dbus_set_user_menu_visibility (self->session_dbus_interface, self->user_count > 1); if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { users = g_list_sort (users, (GCompareFunc)compare_users_by_username); @@ -199,13 +193,11 @@ user_menu_mgr_rebuild_items (UserMenuMgr *self) dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_IS_CURRENT_USER, logged_in); - // TODO - // Figure where this lives. - /*if (logged_in == TRUE){ + if (logged_in == TRUE){ g_debug ("about to set the users real name to %s for user %s", user->real_name, user->user_name); - session_dbus_set_users_real_name (session_dbus, user->real_name); - }*/ + session_dbus_set_users_real_name (self->session_dbus_interface, user->real_name); + } dbusmenu_menuitem_child_append (self->root_item, mi); g_signal_connect (G_OBJECT (mi), @@ -333,4 +325,34 @@ user_change (UsersServiceDbus *service, return; } +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +ensure_gconf_client () +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir (gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_add_dir (gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + } +} + +DbusmenuMenuitem* +user_mgr_get_root_item (UserMenuMgr* self) +{ + return self->root_item; +} + + +/* + * Clean Entry Point + */ +UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus) +{ + UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL); + user_mgr->session_dbus_interface = session_dbus; + user_menu_mgr_rebuild_items (user_mgr); + return user_mgr; +} + diff --git a/src/user-menu-mgr.h b/src/user-menu-mgr.h index 214c9c7..16ac055 100644 --- a/src/user-menu-mgr.h +++ b/src/user-menu-mgr.h @@ -21,8 +21,11 @@ #ifndef _USER_MENU_MGR_H_ #define _USER_MENU_MGR_H_ + #include -#include "users-service-dbus.h" +#include + +#include "session-dbus.h" G_BEGIN_DECLS @@ -41,16 +44,10 @@ struct _UserMenuMgrClass GObjectClass parent_class; }; -struct _UserMenuMgr -{ - GObject parent_instance; - UsersServiceDbus* users_dbus_interface; - DbusmenuMenuitem* root_item; - gint user_count; -}; - GType user_menu_mgr_get_type (void) G_GNUC_CONST; +UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus); +DbusmenuMenuitem* user_mgr_get_root_item (UserMenuMgr* self); G_END_DECLS #endif /* _USER_MENU_MGR_H_ */ -- cgit v1.2.3 From 21edabb3c895ebb60e2ef125d94ca58e256bdb03 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 18 Jul 2011 12:19:38 +0100 Subject: session menu mgr in progress --- src/Makefile.am | 4 ++- src/device-menu-mgr.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/device-menu-mgr.h | 54 ++++++++++++++++++++++++++++++++++++++++ src/user-menu-mgr.c | 33 ++++++++++++------------ src/user-menu-mgr.h | 36 +++++++++++++-------------- 5 files changed, 160 insertions(+), 36 deletions(-) create mode 100644 src/device-menu-mgr.c create mode 100644 src/device-menu-mgr.h diff --git a/src/Makefile.am b/src/Makefile.am index 9bf43cd..2230910 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -93,7 +93,9 @@ indicator_session_service_SOURCES = \ users-service-dbus.h \ users-service-dbus.c \ user-menu-mgr.h \ - user-menu-mgr.c + user-menu-mgr.c \ + device-menu-mgr.h \ + device-menu-mgr.c indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ $(GCONF_CFLAGS) \ diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c new file mode 100644 index 0000000..2bddbb3 --- /dev/null +++ b/src/device-menu-mgr.c @@ -0,0 +1,69 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#include "device-menu-mgr.h" + +struct _DeviceMenuMgr +{ + GObject parent_instance; + DbusmenuMenuitem* root_item; + SessionDbus* session_dbus_interface; +}; + +G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); + +static void +device_menu_mgr_init (DeviceMenuMgr *object) +{ + /* TODO: Add initialization code here */ +} + +static void +device_menu_mgr_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + + G_OBJECT_CLASS (device_menu_mgr_parent_class)->finalize (object); +} + +static void +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; +} + +DbusmenuMenuitem* +device_mgr_get_root_item (DeviceMenuMgr* self) +{ + return self->root_item; +} + +/* + * Clean Entry Point + */ +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_rebuild_items (device_mgr); + return device_mgr; +} diff --git a/src/device-menu-mgr.h b/src/device-menu-mgr.h new file mode 100644 index 0000000..caa9aee --- /dev/null +++ b/src/device-menu-mgr.h @@ -0,0 +1,54 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#ifndef _DEVICE_MENU_MGR_H_ +#define _DEVICE_MENU_MGR_H_ + +#include +#include + +#include "session-dbus.h" + +G_BEGIN_DECLS + +#define DEVICE_TYPE_MENU_MGR (device_menu_mgr_get_type ()) +#define DEVICE_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEVICE_TYPE_MENU_MGR, DeviceMenuMgr)) +#define DEVICE_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEVICE_TYPE_MENU_MGR, DeviceMenuMgrClass)) +#define DEVICE_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEVICE_TYPE_MENU_MGR)) +#define DEVICE_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEVICE_TYPE_MENU_MGR)) +#define DEVICE_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEVICE_TYPE_MENU_MGR, DeviceMenuMgrClass)) + +typedef struct _DeviceMenuMgrClass DeviceMenuMgrClass; +typedef struct _DeviceMenuMgr DeviceMenuMgr; + +struct _DeviceMenuMgrClass +{ + GObjectClass parent_class; +}; + +GType device_menu_mgr_get_type (void) G_GNUC_CONST; + +DeviceMenuMgr* device_menu_mgr_new (SessionDbus* session_dbus); + +DbusmenuMenuitem* device_mgr_get_root_item (DeviceMenuMgr* self); + +G_END_DECLS + +#endif /* _DEVICE_MENU_MGR_H_ */ diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c index 8338739..611bcc7 100644 --- a/src/user-menu-mgr.c +++ b/src/user-menu-mgr.c @@ -1,22 +1,21 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * user-menu-mgr.c - * Copyright (C) Conor Curran 2011 - * - * user-menu-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * user-menu-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . +Copyright 2011 Canonical Ltd. - */ +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ #include diff --git a/src/user-menu-mgr.h b/src/user-menu-mgr.h index 16ac055..ff2cb77 100644 --- a/src/user-menu-mgr.h +++ b/src/user-menu-mgr.h @@ -1,22 +1,22 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * user-menu-mgr.c - * Copyright (C) Conor Curran 2011 - * - * user-menu-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * user-menu-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - - */ +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + #ifndef _USER_MENU_MGR_H_ #define _USER_MENU_MGR_H_ -- cgit v1.2.3 From 5762761151a8a8168c7bf0281d83682a260cbcce Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 18 Jul 2011 18:17:37 +0100 Subject: device menu has been isolated --- src/device-menu-mgr.c | 577 +++++++++++++++++++++++++++++++++++++++++++++++++- src/session-service.c | 517 +------------------------------------------- 2 files changed, 582 insertions(+), 512 deletions(-) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 2bddbb3..0114b92 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -17,8 +17,18 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - #include "device-menu-mgr.h" +#include "gconf-helper.h" +#include "dbus-shared-names.h" +#include "dbusmenu-shared.h" +#include "lock-helper.h" +#include "upower-client.h" + +#define UP_ADDRESS "org.freedesktop.UPower" +#define UP_OBJECT "/org/freedesktop/UPower" +#define UP_INTERFACE "org.freedesktop.UPower" + +#define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" struct _DeviceMenuMgr { @@ -27,22 +37,61 @@ struct _DeviceMenuMgr SessionDbus* session_dbus_interface; }; +static GConfClient *gconf_client = NULL; +static DbusmenuMenuitem *lock_menuitem = NULL; + +static DBusGProxyCall * suspend_call = NULL; +static DBusGProxyCall * hibernate_call = NULL; + +static DbusmenuMenuitem * hibernate_mi = NULL; +static DbusmenuMenuitem * suspend_mi = NULL; +static DbusmenuMenuitem * logout_mi = NULL; +static DbusmenuMenuitem * restart_mi = NULL; +static DbusmenuMenuitem * shutdown_mi = NULL; + +static gboolean can_hibernate = TRUE; +static gboolean can_suspend = TRUE; +static gboolean allow_hibernate = TRUE; +static gboolean allow_suspend = TRUE; + +static DBusGProxy * up_main_proxy = NULL; +static DBusGProxy * up_prop_proxy = NULL; + +static void device_menu_mgr_ensure_gconf_client (DeviceMenuMgr* self); +static void setup_restart_watch (DeviceMenuMgr* self); +static void setup_up (DeviceMenuMgr* self); +static void device_menu_mgr_rebuild_items (DeviceMenuMgr *self); +static void lock_if_possible (DeviceMenuMgr* self); +static void machine_sleep_with_context (DeviceMenuMgr* self, + gchar* type); +static void +machine_sleep_from_hibernate (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata); +static void +machine_sleep_from_suspend (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata); + G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); static void -device_menu_mgr_init (DeviceMenuMgr *object) +device_menu_mgr_init (DeviceMenuMgr *self) { - /* TODO: Add initialization code here */ + self->root_item = dbusmenu_menuitem_new (); + setup_restart_watch(self); + setup_up(self); + g_idle_add(lock_screen_setup, NULL); } static void device_menu_mgr_finalize (GObject *object) { /* TODO: Add deinitalization code here */ - G_OBJECT_CLASS (device_menu_mgr_parent_class)->finalize (object); } +// TODO refactor into one helper method for both menu mgrs. static void device_menu_mgr_class_init (DeviceMenuMgrClass *klass) { @@ -51,6 +100,524 @@ device_menu_mgr_class_init (DeviceMenuMgrClass *klass) object_class->finalize = device_menu_mgr_finalize; } + +static void +lockdown_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (user_data); + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (value == NULL || key == NULL) { + return; + } + + if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || + g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { + device_menu_mgr_rebuild_items(self); + } + + return; +} + +static void +keybinding_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (value == NULL || key == NULL) { + return; + } + + if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) { + g_debug("Keybinding changed to: %s", gconf_value_get_string(value)); + if (lock_menuitem != NULL) { + dbusmenu_menuitem_property_set_shortcut_string (lock_menuitem, + gconf_value_get_string(value)); + } + } + return; +} + +/* Check to see if the lockdown key is protecting from + locking the screen. If not, lock it. */ +static void +lock_if_possible (DeviceMenuMgr* self) { + device_menu_mgr_ensure_gconf_client (self); + + if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { + lock_screen (NULL, 0, NULL); + } + return; +} + +/* A return from the command to sleep the system. Make sure + that we unthrottle the screensaver. */ +static void +sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) +{ + screensaver_unthrottle(); + return; +} + +static void +machine_sleep_from_suspend (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + machine_sleep_with_context (self, "Suspend"); +} + +static void +machine_sleep_from_hibernate (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + machine_sleep_with_context (self, "Hibernate"); +} + +/* Let's put this machine to sleep, with some info on how + it should sleep. */ +static void +machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) +{ + if (up_main_proxy == NULL) { + g_warning("Can not %s as no upower proxy", type); + } + + screensaver_throttle(type); + lock_if_possible (self); + + dbus_g_proxy_begin_call(up_main_proxy, + type, + sleep_response, + NULL, + NULL, + G_TYPE_INVALID); + + return; +} + +/* A response to getting the suspend property */ +static void +suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + suspend_call = NULL; + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + + GValue candoit = {0}; + GError * error = NULL; + dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); + if (error != NULL) { + g_warning("Unable to check suspend: %s", error->message); + g_error_free(error); + return; + } + g_debug("Got Suspend: %s", g_value_get_boolean(&candoit) ? "true" : "false"); + + gboolean local_can_suspend = g_value_get_boolean(&candoit); + if (local_can_suspend != can_suspend) { + can_suspend = local_can_suspend; + device_menu_mgr_rebuild_items(self); + } + + return; +} + +/* Response to getting the hibernate property */ +static void +hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + hibernate_call = NULL; + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + + GValue candoit = {0}; + GError * error = NULL; + dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); + if (error != NULL) { + g_warning("Unable to check hibernate: %s", error->message); + g_error_free(error); + return; + } + g_debug("Got Hibernate: %s", g_value_get_boolean(&candoit) ? "true" : "false"); + + gboolean local_can_hibernate = g_value_get_boolean(&candoit); + if (local_can_hibernate != can_hibernate) { + can_hibernate = local_can_hibernate; + device_menu_mgr_rebuild_items(self); + } +} + +/* A signal that we need to recheck to ensure we can still + hibernate and/or suspend */ +static void +up_changed_cb (DBusGProxy * proxy, gpointer user_data) +{ + /* Start Async call to see if we can hibernate */ + if (suspend_call == NULL) { + suspend_call = dbus_g_proxy_begin_call(up_prop_proxy, + "Get", + suspend_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanSuspend", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } + + /* Start Async call to see if we can suspend */ + if (hibernate_call == NULL) { + hibernate_call = dbus_g_proxy_begin_call(up_prop_proxy, + "Get", + hibernate_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanHibernate", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } +} +/* Handle the callback from the allow functions to check and + see if we're changing the value, and if so, rebuilding the + menus based on that info. */ +static void +allowed_suspend_cb (DBusGProxy *proxy, + gboolean OUT_allowed, + GError *error, + gpointer userdata) +{ + if (error != NULL) { + g_warning("Unable to get information on what is allowed from UPower: %s", + error->message); + return; + } + + if (OUT_allowed != allow_suspend) { + allow_suspend = OUT_allowed; + device_menu_mgr_rebuild_items(DEVICE_MENU_MGR (userdata)); + } +} + +/* Handle the callback from the allow functions to check and + see if we're changing the value, and if so, rebuilding the + menus based on that info. */ +static void +allowed_hibernate_cb (DBusGProxy *proxy, + gboolean OUT_allowed, + GError *error, + gpointer userdata) +{ + if (error != NULL) { + g_warning("Unable to get information on what is allowed from UPower: %s", + error->message); + return; + } + + if (OUT_allowed != allow_hibernate) { + allow_hibernate = OUT_allowed; + device_menu_mgr_rebuild_items(DEVICE_MENU_MGR (userdata)); + } +} + +/* This function goes through and sets up what we need for + DKp checking. We're even setting up the calls for the props + we need */ +static void +setup_up (DeviceMenuMgr* self) { + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); + g_return_if_fail(bus != NULL); + + if (up_main_proxy == NULL) { + up_main_proxy = dbus_g_proxy_new_for_name(bus, + UP_ADDRESS, + UP_OBJECT, + UP_INTERFACE); + } + g_return_if_fail(up_main_proxy != NULL); + + if (up_prop_proxy == NULL) { + up_prop_proxy = dbus_g_proxy_new_for_name(bus, + UP_ADDRESS, + UP_OBJECT, + DBUS_INTERFACE_PROPERTIES); + /* Connect to changed signal */ + dbus_g_proxy_add_signal(up_main_proxy, + "Changed", + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal(up_main_proxy, + "Changed", + G_CALLBACK(up_changed_cb), + self, + NULL); + } + g_return_if_fail(up_prop_proxy != NULL); + + + /* Force an original "changed" event */ + up_changed_cb(up_main_proxy, self); + + /* Check to see if these are getting blocked by PolicyKit */ + org_freedesktop_UPower_suspend_allowed_async(up_main_proxy, + allowed_suspend_cb, + self); + org_freedesktop_UPower_hibernate_allowed_async(up_main_proxy, + allowed_hibernate_cb, + self); + + return; +} + +/* This is the function to show a dialog on actions that + can destroy data. Currently it just calls the GTK version + but it seems that in the future it should figure out + what's going on and something better. */ +static void +show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) +{ + gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); + gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); + g_free(helper); + + g_debug("Showing dialog '%s'", dialog_line); + + GError * error = NULL; + if (!g_spawn_command_line_async(dialog_line, &error)) { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + + g_free(dialog_line); + + return; +} + + +static void +device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +{ + gboolean can_lockscreen; + + /* Make sure we have a valid GConf client, and build one + if needed */ + device_menu_mgr_ensure_gconf_client (self); + + can_lockscreen = !gconf_client_get_bool ( gconf_client, + LOCKDOWN_KEY_SCREENSAVER, + NULL); + /* Lock screen item */ + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (lock_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Lock Screen")); + + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); + } else { + g_debug("Unable to get lock screen shortcut."); + } + + g_signal_connect (G_OBJECT(lock_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); + } + + /* Start going through the session based items. */ + + logout_mi = dbusmenu_menuitem_new(); + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out")); + } else { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (logout_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_logout()); + dbusmenu_menuitem_child_append(self->root_item, logout_mi); + g_signal_connect( G_OBJECT(logout_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "logout"); + + if (can_suspend && allow_suspend) { + suspend_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (suspend_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Suspend")); + dbusmenu_menuitem_child_append (self->root_item, suspend_mi); + g_signal_connect( G_OBJECT(suspend_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_suspend), + self); + } + + if (can_hibernate && allow_hibernate) { + hibernate_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (hibernate_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Hibernate")); + dbusmenu_menuitem_child_append(self->root_item, hibernate_mi); + g_signal_connect (G_OBJECT(hibernate_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_hibernate), self); + } + + restart_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (restart_mi, + DBUSMENU_MENUITEM_PROP_TYPE, + RESTART_ITEM_TYPE); + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart")); + } else { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (restart_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_restart()); + dbusmenu_menuitem_child_append(self->root_item, restart_mi); + g_signal_connect (G_OBJECT(restart_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "restart"); + + shutdown_mi = dbusmenu_menuitem_new(); + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down")); + } else { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (shutdown_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_shutdown()); + dbusmenu_menuitem_child_append (self->root_item, shutdown_mi); + g_signal_connect (G_OBJECT(shutdown_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "shutdown"); + + RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); + restart_shutdown_logout_mi->logout_mi = logout_mi; + restart_shutdown_logout_mi->restart_mi = restart_mi; + restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; + + update_menu_entries(restart_shutdown_logout_mi); + + return; +} + +/* When the directory changes we need to figure out how our menu + item should look. */ +static void +restart_dir_changed (gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); + + if (restart_required) { + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart to Complete Update")); + } else { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart to Complete Update\342\200\246")); + } + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_ICON, + "system-restart-panel"); + if (self->session_dbus_interface != NULL) { + session_dbus_set_name (self->session_dbus_interface, ICON_RESTART); + } + } else { + if (supress_confirmations()) { + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); + } else { + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); + } + dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); + if (self->session_dbus_interface != NULL) { + session_dbus_set_name(self->session_dbus_interface, ICON_DEFAULT); + } + } + return; +} + +/* Buids a file watcher for the directory so that when it + changes we can check to see if our reboot-required is + there. */ +static void +setup_restart_watch (DeviceMenuMgr* self) +{ + GFile * filedir = g_file_new_for_path("/var/run"); + GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); + if (filemon != NULL) { + g_signal_connect (G_OBJECT(filemon), + "changed", + G_CALLBACK(restart_dir_changed), + self); + } + restart_dir_changed(self); + return; +} + +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +device_menu_mgr_ensure_gconf_client (DeviceMenuMgr* self) +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + + gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add (gconf_client, + LOCKDOWN_DIR, + lockdown_changed, + self, + NULL, + NULL); + + gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add (gconf_client, + KEYBINDING_DIR, + keybinding_changed, + self, + NULL, + NULL); + } +} + DbusmenuMenuitem* device_mgr_get_root_item (DeviceMenuMgr* self) { @@ -64,6 +631,6 @@ 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_rebuild_items (device_mgr); + device_menu_mgr_rebuild_items (device_mgr); return device_mgr; } diff --git a/src/session-service.c b/src/session-service.c index 23cb6ab..fc7983d 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -45,18 +45,12 @@ with this program. If not, see . #include "dbusmenu-shared.h" #include "users-service-dbus.h" #include "user-menu-mgr.h" +#include "device-menu-mgr.h" -#include "gconf-helper.h" +//#include "gconf-helper.h" #include "session-dbus.h" -#include "lock-helper.h" -#include "upower-client.h" - -#define UP_ADDRESS "org.freedesktop.UPower" -#define UP_OBJECT "/org/freedesktop/UPower" -#define UP_INTERFACE "org.freedesktop.UPower" - -#define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" +//#include "lock-helper.h" typedef struct _ActivateData ActivateData; @@ -68,444 +62,7 @@ struct _ActivateData //static UsersServiceDbus *dbus_interface = NULL; static SessionDbus *session_dbus = NULL; -static DbusmenuMenuitem *lock_menuitem = NULL; -static DbusmenuMenuitem * session_root_menuitem = NULL; - static GMainLoop * mainloop = NULL; -static DBusGProxy * up_main_proxy = NULL; -static DBusGProxy * up_prop_proxy = NULL; - -static DBusGProxyCall * suspend_call = NULL; -static DBusGProxyCall * hibernate_call = NULL; - -static DbusmenuMenuitem * hibernate_mi = NULL; -static DbusmenuMenuitem * suspend_mi = NULL; -static DbusmenuMenuitem * logout_mi = NULL; -static DbusmenuMenuitem * restart_mi = NULL; -static DbusmenuMenuitem * shutdown_mi = NULL; - -static gboolean can_hibernate = TRUE; -static gboolean can_suspend = TRUE; -static gboolean allow_hibernate = TRUE; -static gboolean allow_suspend = TRUE; - -static GConfClient * gconf_client = NULL; - -static void rebuild_session_items (DbusmenuMenuitem *root); - -static void -lockdown_changed (GConfClient *client, - guint cnxd_id, - GConfEntry *entry, - gpointer user_data) -{ - GConfValue *value = gconf_entry_get_value (entry); - const gchar *key = gconf_entry_get_key (entry); - - if (value == NULL || key == NULL) { - return; - } - - if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { - rebuild_session_items(session_root_menuitem); - } - - return; -} - -static void -keybinding_changed (GConfClient *client, - guint cnxd_id, - GConfEntry *entry, - gpointer user_data) -{ - GConfValue *value = gconf_entry_get_value (entry); - const gchar *key = gconf_entry_get_key (entry); - - if (value == NULL || key == NULL) { - return; - } - - if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) { - g_debug("Keybinding changed to: %s", gconf_value_get_string(value)); - if (lock_menuitem != NULL) { - dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, gconf_value_get_string(value)); - } - } - return; -} - -/* Ensures that we have a GConf client and if we build one - set up the signal handler. */ -static void -ensure_gconf_client (void) -{ - if (!gconf_client) { - gconf_client = gconf_client_get_default (); - - gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); - - gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL); - } - return; -} - -/* Check to see if the lockdown key is protecting from - locking the screen. If not, lock it. */ -static void -lock_if_possible (void) { - ensure_gconf_client (); - - if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { - lock_screen (NULL, 0, NULL); - } - return; -} - -/* A return from the command to sleep the system. Make sure - that we unthrottle the screensaver. */ -static void -sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) -{ - screensaver_unthrottle(); - return; -} - -/* Let's put this machine to sleep, with some info on how - it should sleep. */ -static void -machine_sleep (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) -{ - gchar * type = (gchar *)userdata; - - if (up_main_proxy == NULL) { - g_warning("Can not %s as no upower proxy", type); - } - - screensaver_throttle(type); - lock_if_possible(); - - dbus_g_proxy_begin_call(up_main_proxy, - type, - sleep_response, - NULL, - NULL, - G_TYPE_INVALID); - - return; -} - -/* A response to getting the suspend property */ -static void -suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) -{ - suspend_call = NULL; - - GValue candoit = {0}; - GError * error = NULL; - dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); - if (error != NULL) { - g_warning("Unable to check suspend: %s", error->message); - g_error_free(error); - return; - } - g_debug("Got Suspend: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - - gboolean local_can_suspend = g_value_get_boolean(&candoit); - if (local_can_suspend != can_suspend) { - can_suspend = local_can_suspend; - rebuild_session_items(session_root_menuitem); - } - - return; -} - -/* Response to getting the hibernate property */ -static void -hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) -{ - hibernate_call = NULL; - - GValue candoit = {0}; - GError * error = NULL; - dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); - if (error != NULL) { - g_warning("Unable to check hibernate: %s", error->message); - g_error_free(error); - return; - } - g_debug("Got Hibernate: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - - gboolean local_can_hibernate = g_value_get_boolean(&candoit); - if (local_can_hibernate != can_hibernate) { - can_hibernate = local_can_hibernate; - rebuild_session_items(session_root_menuitem); - } - - return; -} - -/* A signal that we need to recheck to ensure we can still - hibernate and/or suspend */ -static void -up_changed_cb (DBusGProxy * proxy, gpointer user_data) -{ - /* Start Async call to see if we can hibernate */ - if (suspend_call == NULL) { - suspend_call = dbus_g_proxy_begin_call(up_prop_proxy, - "Get", - suspend_prop_cb, - NULL, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanSuspend", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } - - /* Start Async call to see if we can suspend */ - if (hibernate_call == NULL) { - hibernate_call = dbus_g_proxy_begin_call(up_prop_proxy, - "Get", - hibernate_prop_cb, - NULL, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanHibernate", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } - - return; -} - -/* Handle the callback from the allow functions to check and - see if we're changing the value, and if so, rebuilding the - menus based on that info. */ -static void -allowed_cb (DBusGProxy *proxy, gboolean OUT_allowed, GError *error, gpointer userdata) -{ - if (error != NULL) { - g_warning("Unable to get information on what is allowed from UPower: %s", error->message); - return; - } - - gboolean * can_do = (gboolean *)userdata; - - if (OUT_allowed != *can_do) { - *can_do = OUT_allowed; - rebuild_session_items (session_root_menuitem); - } -} - -/* This function goes through and sets up what we need for - DKp checking. We're even setting up the calls for the props - we need */ -static void -setup_up (void) { - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - g_return_if_fail(bus != NULL); - - if (up_main_proxy == NULL) { - up_main_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - UP_INTERFACE); - } - g_return_if_fail(up_main_proxy != NULL); - - if (up_prop_proxy == NULL) { - up_prop_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - DBUS_INTERFACE_PROPERTIES); - /* Connect to changed signal */ - dbus_g_proxy_add_signal(up_main_proxy, - "Changed", - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal(up_main_proxy, - "Changed", - G_CALLBACK(up_changed_cb), - NULL, - NULL); - } - g_return_if_fail(up_prop_proxy != NULL); - - - /* Force an original "changed" event */ - up_changed_cb(up_main_proxy, NULL); - - /* Check to see if these are getting blocked by PolicyKit */ - org_freedesktop_UPower_suspend_allowed_async(up_main_proxy, - allowed_cb, - &allow_suspend); - org_freedesktop_UPower_hibernate_allowed_async(up_main_proxy, - allowed_cb, - &allow_hibernate); - - return; -} - -/* This is the function to show a dialog on actions that - can destroy data. Currently it just calls the GTK version - but it seems that in the future it should figure out - what's going on and something better. */ -static void -show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) -{ - gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); - gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); - g_free(helper); - - g_debug("Showing dialog '%s'", dialog_line); - - GError * error = NULL; - if (!g_spawn_command_line_async(dialog_line, &error)) { - g_warning("Unable to show dialog: %s", error->message); - g_error_free(error); - } - - g_free(dialog_line); - - return; -} - - -static void -rebuild_session_items (DbusmenuMenuitem *root) - -{ - gboolean can_lockscreen; - - /* Make sure we have a valid GConf client, and build one - if needed */ - ensure_gconf_client (); - - can_lockscreen = !gconf_client_get_bool ( gconf_client, - LOCKDOWN_KEY_SCREENSAVER, - NULL); - /* Lock screen item */ - if (can_lockscreen) { - lock_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (lock_menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Lock Screen")); - - gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); - if (shortcut != NULL) { - g_debug("Lock screen shortcut: %s", shortcut); - dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); - g_free(shortcut); - } else { - g_debug("Unable to get lock screen shortcut."); - } - - g_signal_connect (G_OBJECT(lock_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(lock_screen), NULL); - dbusmenu_menuitem_child_append(root, lock_menuitem); - } - - /* Start going through the session based items. */ - - logout_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out")); - } else { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (logout_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_logout()); - dbusmenu_menuitem_child_append(root, logout_mi); - g_signal_connect( G_OBJECT(logout_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "logout"); - - if (can_suspend && allow_suspend) { - suspend_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (suspend_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Suspend")); - dbusmenu_menuitem_child_append (root, suspend_mi); - g_signal_connect( G_OBJECT(suspend_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(machine_sleep), - "Suspend"); - } - - if (can_hibernate && allow_hibernate) { - hibernate_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (hibernate_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Hibernate")); - dbusmenu_menuitem_child_append(root, hibernate_mi); - g_signal_connect (G_OBJECT(hibernate_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(machine_sleep), "Hibernate"); - } - - restart_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (restart_mi, - DBUSMENU_MENUITEM_PROP_TYPE, - RESTART_ITEM_TYPE); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart")); - } else { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (restart_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_restart()); - dbusmenu_menuitem_child_append(root, restart_mi); - g_signal_connect (G_OBJECT(restart_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "restart"); - - shutdown_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (shutdown_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Shut Down")); - } else { - dbusmenu_menuitem_property_set (shutdown_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Shut Down\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (shutdown_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_shutdown()); - dbusmenu_menuitem_child_append (root, shutdown_mi); - g_signal_connect (G_OBJECT(shutdown_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "shutdown"); - - RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); - restart_shutdown_logout_mi->logout_mi = logout_mi; - restart_shutdown_logout_mi->restart_mi = restart_mi; - restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; - - update_menu_entries(restart_shutdown_logout_mi); - - return; -} /* When the service interface starts to shutdown, we @@ -520,52 +77,6 @@ service_shutdown (IndicatorService * service, gpointer user_data) return; } -/* When the directory changes we need to figure out how our menu - item should look. */ -static void -restart_dir_changed (void) -{ - gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); - - if (restart_required) { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart to Complete Update")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart to Complete Update\342\200\246")); - } - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_ICON, "system-restart-panel"); - if (session_dbus != NULL) { - session_dbus_set_name(session_dbus, ICON_RESTART); - } - } else { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); - if (session_dbus != NULL) { - session_dbus_set_name(session_dbus, ICON_DEFAULT); - } - } - return; -} - -/* Buids a file watcher for the directory so that when it - changes we can check to see if our reboot-required is - there. */ -static void -setup_restart_watch (void) -{ - GFile * filedir = g_file_new_for_path("/var/run"); - GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); - if (filemon != NULL) { - g_signal_connect(G_OBJECT(filemon), "changed", G_CALLBACK(restart_dir_changed), NULL); - } - restart_dir_changed(); - return; -} - /* Main, is well, main. It brings everything up and throws us into the mainloop of no return. */ int @@ -581,28 +92,20 @@ main (int argc, char ** argv) IndicatorService * service = indicator_service_new_version (INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); - g_signal_connect(G_OBJECT(service), - INDICATOR_SERVICE_SIGNAL_SHUTDOWN, - G_CALLBACK(service_shutdown), NULL); + g_signal_connect (G_OBJECT(service), + INDICATOR_SERVICE_SIGNAL_SHUTDOWN, + G_CALLBACK(service_shutdown), NULL); session_dbus = session_dbus_new(); - g_idle_add(lock_screen_setup, NULL); - - session_root_menuitem = dbusmenu_menuitem_new(); - rebuild_session_items (session_root_menuitem); - + // Devices + DeviceMenuMgr* device_mgr = device_menu_mgr_new (session_dbus); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); - dbusmenu_server_set_root(server, session_root_menuitem); + dbusmenu_server_set_root(server, device_mgr_get_root_item (device_mgr)); // Users - UserMenuMgr* user_mgr = user_menu_mgr_new (session_dbus); - - setup_restart_watch(); - setup_up(); - + UserMenuMgr* user_mgr = user_menu_mgr_new (session_dbus); DbusmenuServer* users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); - dbusmenu_server_set_root (users_server, user_mgr_get_root_item (user_mgr)); mainloop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3 From 76d7de16d24e97aa6b58472b21b3a8e8bb795af5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 11:21:02 +0100 Subject: add the udev mgr files --- src/udev-mgr.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/udev-mgr.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/udev-mgr.c create mode 100644 src/udev-mgr.h diff --git a/src/udev-mgr.c b/src/udev-mgr.c new file mode 100644 index 0000000..045c603 --- /dev/null +++ b/src/udev-mgr.c @@ -0,0 +1,49 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * udev-mgr.c + * Copyright (C) Conor Curran 2011 + * + * udev-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * udev-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#include "udev-mgr.h" + + + +G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); + +static void +udev_mgr_init (UdevMgr *object) +{ + /* TODO: Add initialization code here */ +} + +static void +udev_mgr_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + + G_OBJECT_CLASS (udev_mgr_parent_class)->finalize (object); +} + +static void +udev_mgr_class_init (UdevMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + object_class->finalize = udev_mgr_finalize; +} + diff --git a/src/udev-mgr.h b/src/udev-mgr.h new file mode 100644 index 0000000..77d62f1 --- /dev/null +++ b/src/udev-mgr.h @@ -0,0 +1,52 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * udev-mgr.c + * Copyright (C) Conor Curran 2011 + * + * udev-mgr.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * udev-mgr.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + + */ + +#ifndef _UDEV_MGR_H_ +#define _UDEV_MGR_H_ + +#include + +G_BEGIN_DECLS + +#define UDEV_TYPE_MGR (udev_mgr_get_type ()) +#define UDEV_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UDEV_TYPE_MGR, UdevMgr)) +#define UDEV_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UDEV_TYPE_MGR, UdevMgrClass)) +#define UDEV_IS_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UDEV_TYPE_MGR)) +#define UDEV_IS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UDEV_TYPE_MGR)) +#define UDEV_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UDEV_TYPE_MGR, UdevMgrClass)) + +typedef struct _UdevMgrClass UdevMgrClass; +typedef struct _UdevMgr UdevMgr; + +struct _UdevMgrClass +{ + GObjectClass parent_class; +}; + +struct _UdevMgr +{ + GObject parent_instance; +}; + +GType udev_mgr_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _UDEV_MGR_H_ */ -- cgit v1.2.3 From 66af46666904be8c2b056fc32d2bf258bf31b91f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 13:18:54 +0100 Subject: system added to device menu, more tidying as we go --- src/device-menu-mgr.c | 185 ++++++++++++++++++++++++++++++++++++++++++-------- src/session-service.c | 4 +- src/udev-mgr.c | 36 +++++----- src/udev-mgr.h | 35 +++++----- 4 files changed, 191 insertions(+), 69 deletions(-) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 0114b92..b8a2050 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + #include "device-menu-mgr.h" #include "gconf-helper.h" #include "dbus-shared-names.h" @@ -24,6 +26,7 @@ with this program. If not, see . #include "lock-helper.h" #include "upower-client.h" + #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" #define UP_INTERFACE "org.freedesktop.UPower" @@ -39,12 +42,13 @@ struct _DeviceMenuMgr static GConfClient *gconf_client = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; +static DbusmenuMenuitem *system_settings_menuitem = NULL; static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; static DbusmenuMenuitem * hibernate_mi = NULL; -static DbusmenuMenuitem * suspend_mi = NULL; +//static DbusmenuMenuitem * suspend_mi = NULL; static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; @@ -64,15 +68,19 @@ static void device_menu_mgr_rebuild_items (DeviceMenuMgr *self); static void lock_if_possible (DeviceMenuMgr* self); 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 machine_sleep_from_hibernate (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static void +/*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); - +*/ G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); static void @@ -100,7 +108,8 @@ device_menu_mgr_class_init (DeviceMenuMgrClass *klass) object_class->finalize = device_menu_mgr_finalize; } - +// TODO +// Is this needed anymore static void lockdown_changed (GConfClient *client, guint cnxd_id, @@ -167,14 +176,14 @@ sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) return; } -static void +/*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); machine_sleep_with_context (self, "Suspend"); -} +}*/ static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, @@ -208,6 +217,9 @@ machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) } /* A response to getting the suspend property */ +// TODO +// Is this needed anymore + static void suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -234,6 +246,9 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) } /* Response to getting the hibernate property */ +// TODO +// Is this needed anymore + static void hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -392,6 +407,7 @@ setup_up (DeviceMenuMgr* self) { static void show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) { + gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); g_free(helper); @@ -403,16 +419,50 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) g_warning("Unable to show dialog: %s", error->message); g_error_free(error); } + g_free(dialog_line); +} + +static void +show_system_settings_with_context (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + gchar * control_centre_command = g_strdup_printf("%s %s", + "gnome-control-center", + type); - g_free(dialog_line); + g_debug("Command centre exec call '%s'", control_centre_command); - return; + GError * error = NULL; + if (!g_spawn_command_line_async(control_centre_command, &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + g_free(control_centre_command); } - static void -device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +device_menu_mgr_build_static_items (DeviceMenuMgr* self) { + system_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (system_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("System Settings...")); + g_signal_connect (G_OBJECT(system_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), ""); + + dbusmenu_menuitem_child_add_position(self->root_item, + system_settings_menuitem, + 0); + + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (self->root_item, separator1); + gboolean can_lockscreen; /* Make sure we have a valid GConf client, and build one @@ -423,6 +473,99 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) LOCKDOWN_KEY_SCREENSAVER, NULL); /* Lock screen item */ + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (lock_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Lock Screen")); + + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); + } + else { + g_debug("Unable to get lock screen shortcut."); + } + + g_signal_connect (G_OBJECT(lock_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); + } + + logout_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out")); + } + else { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (logout_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_logout()); + dbusmenu_menuitem_child_append(self->root_item, logout_mi); + g_signal_connect( G_OBJECT(logout_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "logout"); + + if (can_hibernate && allow_hibernate) { + hibernate_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (hibernate_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Hibernate")); + dbusmenu_menuitem_child_append(self->root_item, hibernate_mi); + g_signal_connect (G_OBJECT(hibernate_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_hibernate), self); + } + + shutdown_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down")); + } + else { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (shutdown_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_shutdown()); + dbusmenu_menuitem_child_append (self->root_item, shutdown_mi); + g_signal_connect (G_OBJECT(shutdown_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "shutdown"); + + RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); + restart_shutdown_logout_mi->logout_mi = logout_mi; + restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; + + update_menu_entries(restart_shutdown_logout_mi); +} + + +static void +device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +{ + //gboolean can_lockscreen; + + /* Make sure we have a valid GConf client, and build one + if needed */ + //device_menu_mgr_ensure_gconf_client (self); + + /*can_lockscreen = !gconf_client_get_bool ( gconf_client, + LOCKDOWN_KEY_SCREENSAVER, + NULL); if (can_lockscreen) { lock_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (lock_menuitem, @@ -444,8 +587,6 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); } - /* Start going through the session based items. */ - logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { dbusmenu_menuitem_property_set (logout_mi, @@ -487,22 +628,6 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) G_CALLBACK(machine_sleep_from_hibernate), self); } - restart_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (restart_mi, - DBUSMENU_MENUITEM_PROP_TYPE, - RESTART_ITEM_TYPE); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart")); - } else { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (restart_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_restart()); dbusmenu_menuitem_child_append(self->root_item, restart_mi); g_signal_connect (G_OBJECT(restart_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, @@ -533,7 +658,7 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) update_menu_entries(restart_shutdown_logout_mi); - return; + return;*/ } /* When the directory changes we need to figure out how our menu @@ -631,6 +756,6 @@ 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_rebuild_items (device_mgr); + device_menu_mgr_build_static_items (device_mgr); return device_mgr; } diff --git a/src/session-service.c b/src/session-service.c index 8bdd0c1..e043d65 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -76,10 +76,10 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - if (mainloop != NULL) { + /*if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); - } + }*/ return; } diff --git a/src/udev-mgr.c b/src/udev-mgr.c index 045c603..75f760d 100644 --- a/src/udev-mgr.c +++ b/src/udev-mgr.c @@ -1,25 +1,23 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * udev-mgr.c - * Copyright (C) Conor Curran 2011 - * - * udev-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * udev-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - - */ +Copyright 2011 Canonical Ltd. -#include "udev-mgr.h" +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include "udev-mgr.h" G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); diff --git a/src/udev-mgr.h b/src/udev-mgr.h index 77d62f1..1c5ae73 100644 --- a/src/udev-mgr.h +++ b/src/udev-mgr.h @@ -1,22 +1,21 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * udev-mgr.c - * Copyright (C) Conor Curran 2011 - * - * udev-mgr.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * udev-mgr.c is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - - */ +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ #ifndef _UDEV_MGR_H_ #define _UDEV_MGR_H_ -- cgit v1.2.3 From 04b9f0bc0b0b7715b9a261ceae059a8b7ba69ced Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 16:08:27 +0100 Subject: settings dialog in place --- src/device-menu-mgr.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index b8a2050..49dfad7 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -43,6 +43,10 @@ struct _DeviceMenuMgr static GConfClient *gconf_client = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; static DbusmenuMenuitem *system_settings_menuitem = NULL; +static DbusmenuMenuitem *display_settings_menuitem = NULL; +static DbusmenuMenuitem *bluetooth_settings_menuitem = NULL; +static DbusmenuMenuitem *login_settings_menuitem = NULL; +static DbusmenuMenuitem *software_updates_menuitem = NULL; static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; @@ -71,6 +75,9 @@ static void machine_sleep_with_context (DeviceMenuMgr* self, static void show_system_settings_with_context (DbusmenuMenuitem * mi, guint timestamp, gchar * type); +static void show_apt_dialog (DbusmenuMenuitem* mi, + guint timestamp, + gchar * type); static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, @@ -422,6 +429,11 @@ 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, @@ -445,6 +457,7 @@ show_system_settings_with_context (DbusmenuMenuitem * mi, static void device_menu_mgr_build_static_items (DeviceMenuMgr* self) { + // Static Setting items system_settings_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (system_settings_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, @@ -452,17 +465,63 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) g_signal_connect (G_OBJECT(system_settings_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_system_settings_with_context), ""); - + dbusmenu_menuitem_child_add_position(self->root_item, system_settings_menuitem, 0); + + + display_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (display_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Displays...")); + g_signal_connect (G_OBJECT(display_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), "display"); + dbusmenu_menuitem_child_add_position(self->root_item, + display_settings_menuitem, + 1); + + bluetooth_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (bluetooth_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Bluetooth...")); + g_signal_connect (G_OBJECT(bluetooth_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), "bluetooth"); + dbusmenu_menuitem_child_add_position(self->root_item, + bluetooth_settings_menuitem, + 2); + + login_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (login_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Login Items...")); + g_signal_connect (G_OBJECT(login_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), "login"); + dbusmenu_menuitem_child_add_position(self->root_item, + login_settings_menuitem, + 3); + + software_updates_menuitem = dbusmenu_menuitem_new(); + 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); DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append (self->root_item, separator1); - + + // Devices gboolean can_lockscreen; /* Make sure we have a valid GConf client, and build one -- cgit v1.2.3 From 123c9776b0a67b8dd8a58b8295c3356b1f8be606 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 16:58:33 +0100 Subject: all items in place, now for the gudev backend --- src/device-menu-mgr.c | 69 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 49dfad7..ccb4523 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -47,6 +47,10 @@ static DbusmenuMenuitem *display_settings_menuitem = NULL; static DbusmenuMenuitem *bluetooth_settings_menuitem = NULL; static DbusmenuMenuitem *login_settings_menuitem = NULL; static DbusmenuMenuitem *software_updates_menuitem = NULL; +static DbusmenuMenuitem *printers_menuitem = NULL; +static DbusmenuMenuitem *scanners_menuitem = NULL; +static DbusmenuMenuitem *webcam_menuitem = NULL; + static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; @@ -465,12 +469,10 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) g_signal_connect (G_OBJECT(system_settings_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_system_settings_with_context), ""); - dbusmenu_menuitem_child_add_position(self->root_item, system_settings_menuitem, 0); - display_settings_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (display_settings_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, @@ -481,7 +483,6 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) dbusmenu_menuitem_child_add_position(self->root_item, display_settings_menuitem, 1); - bluetooth_settings_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (bluetooth_settings_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, @@ -499,11 +500,11 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) _("Login Items...")); g_signal_connect (G_OBJECT(login_settings_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_system_settings_with_context), "login"); + G_CALLBACK(show_system_settings_with_context), + "login"); dbusmenu_menuitem_child_add_position(self->root_item, login_settings_menuitem, 3); - software_updates_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (software_updates_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, @@ -519,15 +520,65 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) dbusmenu_menuitem_property_set (separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append (self->root_item, separator1); - - // Devices + dbusmenu_menuitem_child_add_position (self->root_item, separator1, 5); + + // Devices control + DbusmenuMenuitem * device_heading = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (device_heading, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Attached Devices")); + dbusmenu_menuitem_property_set_bool (device_heading, + DBUSMENU_MENUITEM_PROP_ENABLED, + FALSE); + dbusmenu_menuitem_child_add_position (self->root_item, + device_heading, + 6); + + printers_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (printers_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Printers")); + g_signal_connect (G_OBJECT(printers_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), + "printers"); + dbusmenu_menuitem_child_add_position(self->root_item, + printers_menuitem, + 7); + scanners_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (scanners_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("HP Scanners")); + g_signal_connect (G_OBJECT(scanners_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), + "scanners"); + dbusmenu_menuitem_child_add_position (self->root_item, + scanners_menuitem, + 8); + webcam_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (webcam_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("HP Webcam")); + g_signal_connect (G_OBJECT(webcam_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), + "HP Webcam"); + dbusmenu_menuitem_child_add_position (self->root_item, + webcam_menuitem, + 10); + DbusmenuMenuitem * separator3 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator3, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position (self->root_item, separator3, 11); + + // Session control gboolean can_lockscreen; /* Make sure we have a valid GConf client, and build one if needed */ device_menu_mgr_ensure_gconf_client (self); - can_lockscreen = !gconf_client_get_bool ( gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); -- cgit v1.2.3 From 34a5a7289ede2d662d6c64457afcd1c22354d21b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 19:53:15 +0100 Subject: apt watcher coming along nicely --- src/Makefile.am | 6 +- src/apt-watcher.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/apt-watcher.h | 46 +++++++++++++ src/device-menu-mgr.c | 4 ++ src/udev-mgr.c | 1 - 5 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 src/apt-watcher.c create mode 100644 src/apt-watcher.h diff --git a/src/Makefile.am b/src/Makefile.am index 2230910..753b71d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -95,7 +95,11 @@ indicator_session_service_SOURCES = \ user-menu-mgr.h \ user-menu-mgr.c \ device-menu-mgr.h \ - device-menu-mgr.c + device-menu-mgr.c \ + apt-watcher.h \ + apt-watcher.c \ + udev-mgr.h \ + udev-mgr.c indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ $(GCONF_CFLAGS) \ diff --git a/src/apt-watcher.c b/src/apt-watcher.c new file mode 100644 index 0000000..daab2ee --- /dev/null +++ b/src/apt-watcher.c @@ -0,0 +1,177 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include "apt-watcher.h" +#include + +static guint watcher_id; + +struct _AptWatcher +{ + GObject parent_instance; + GCancellable * proxy_cancel; + GDBusProxy * proxy; +}; + +static void +apt_watcher_on_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data); +static void +apt_watcher_on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data); +static void +apt_watcher_get_active_transactions_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); +static void +fetch_proxy_cb (GObject * object, + GAsyncResult * res, + gpointer user_data); + +G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); + +static void +apt_watcher_init (AptWatcher *self) +{ + self->proxy_cancel = g_cancellable_new(); + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.debian.apt", + "/org/debian/apt", + "org.debian.apt", + self->proxy_cancel, + fetch_proxy_cb, + self); +} + +static void +apt_watcher_finalize (GObject *object) +{ + g_bus_unwatch_name (watcher_id); + + G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object); +} + +static void +apt_watcher_class_init (AptWatcherClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + object_class->finalize = apt_watcher_finalize; +} + +static void +fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + + AptWatcher* self = APT_WATCHER(user_data); + g_return_if_fail(self != NULL); + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (self->proxy_cancel != NULL) { + g_object_unref(self->proxy_cancel); + self->proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", + "org.debian.apt", error->message); + g_error_free(error); + return; + } + + self->proxy = proxy; + // Set up the watch. + watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, + "org.debian.apt", + G_BUS_NAME_WATCHER_FLAGS_NONE, + apt_watcher_on_name_appeared, + apt_watcher_on_name_vanished, + self, + NULL); + + //We'll need to connect to the state changed signal + //g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); +} + + +static void +apt_watcher_on_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* watcher = APT_WATCHER (user_data); + + g_print ("Name %s on %s is owned by %s\n", + name, + "the system bus", + name_owner); + + + g_dbus_proxy_call (watcher->proxy, + "GetActiveTransactions", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_get_active_transactions_cb, + user_data); +} + +static void +apt_watcher_get_active_transactions_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete the fetching of active transactions"); + 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); + +} + +static void +apt_watcher_on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_print ("Name %s does not exist on %s\n", + name, + "the system bus"); +} diff --git a/src/apt-watcher.h b/src/apt-watcher.h new file mode 100644 index 0000000..148072f --- /dev/null +++ b/src/apt-watcher.h @@ -0,0 +1,46 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifndef _APT_WATCHER_H_ +#define _APT_WATCHER_H_ + +#include + +G_BEGIN_DECLS + +#define APT_TYPE_WATCHER (apt_watcher_get_type ()) +#define APT_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_WATCHER, AptWatcher)) +#define APT_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_WATCHER, AptWatcherClass)) +#define APT_IS_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_WATCHER)) +#define APT_IS_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_WATCHER)) +#define APT_WATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_WATCHER, AptWatcherClass)) + +typedef struct _AptWatcherClass AptWatcherClass; +typedef struct _AptWatcher AptWatcher; + +struct _AptWatcherClass +{ + GObjectClass parent_class; +}; + +GType apt_watcher_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _APT_WATCHER_H_ */ diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index ccb4523..a3cea61 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -25,6 +25,7 @@ with this program. If not, see . #include "dbusmenu-shared.h" #include "lock-helper.h" #include "upower-client.h" +#include "apt-watcher.h" #define UP_ADDRESS "org.freedesktop.UPower" @@ -87,6 +88,7 @@ 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, @@ -101,6 +103,7 @@ device_menu_mgr_init (DeviceMenuMgr *self) setup_restart_watch(self); setup_up(self); g_idle_add(lock_screen_setup, NULL); + } static void @@ -117,6 +120,7 @@ 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 diff --git a/src/udev-mgr.c b/src/udev-mgr.c index 75f760d..6575ca5 100644 --- a/src/udev-mgr.c +++ b/src/udev-mgr.c @@ -40,7 +40,6 @@ static void udev_mgr_class_init (UdevMgrClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = udev_mgr_finalize; } -- 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(-) 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 1ac92fe1d81c7d7180d44fb0a22339b09600b2af Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 20 Jul 2011 20:04:10 +0100 Subject: signals and methods from apt are working somewhat --- src/apt-watcher.c | 82 +++++++++++++++++++++++++++++++++++++++++-------- src/dbus-shared-names.h | 4 +-- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/apt-watcher.c b/src/apt-watcher.c index bc012ed..703137a 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -18,8 +18,10 @@ with this program. If not, see . */ #include +#include #include "apt-watcher.h" +#include "dbus-shared-names.h" static guint watcher_id; @@ -30,6 +32,7 @@ struct _AptWatcher GDBusProxy * proxy; SessionDbus* session_dbus_interface; DbusmenuMenuitem* apt_item; + gint current_state; }; static void @@ -49,16 +52,23 @@ static void fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); - static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi, guint timestamp, gchar * type); +static void apt_watcher_signal_cb (GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data); +static void apt_watcher_determine_state (AptWatcher* self, + GVariant* update); G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); static void apt_watcher_init (AptWatcher *self) { + self->current_state = UP_TO_DATE; self->proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, @@ -119,7 +129,10 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) NULL); //We'll need to connect to the state changed signal - //g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + g_signal_connect (self->proxy, + "g-signal", + G_CALLBACK(apt_watcher_signal_cb), + self); } @@ -136,7 +149,6 @@ apt_watcher_on_name_appeared (GDBusConnection *connection, name, "the system bus", name_owner); - g_dbus_proxy_call (watcher->proxy, "GetActiveTransactions", @@ -166,16 +178,7 @@ 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)); - //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); + apt_watcher_determine_state (self, result); } static void @@ -188,6 +191,41 @@ apt_watcher_on_name_vanished (GDBusConnection *connection, "the system bus"); } +static void +apt_watcher_determine_state (AptWatcher* self, + GVariant* update) +{ + g_debug ("WE GOT SOME ACTIVE TRANSACTIONS TO EXAMINE, type is %s", + g_variant_get_type_string (update)); + + gchar* first_param = NULL; + gchar ** transactions = NULL; + + g_variant_get (update, "(sas)", &first_param, &transactions); + + g_debug ("apt_watcher_determine_state - the size is the string array %u", + g_strv_length (transactions)); + g_debug ("apt_watcher_determine_state - first param = %s", first_param); + + if (first_param == NULL){ + if (self->current_state != UP_TO_DATE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + } + } + else{ + gboolean updating = g_str_has_prefix (first_param, + "/org/debian/apt/transaction/"); + if (updating == TRUE){ + self->current_state = UPDATES_IN_PROGRESS; + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Installing...")); + } + } +} + static void apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, guint timestamp, @@ -195,7 +233,25 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, { } +// TODO signal is of type s not sas which is on d-feet !!! +static void apt_watcher_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + g_variant_ref (parameters); + GVariant *value = g_variant_get_child_value (parameters, 0); + + if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ + g_debug ("Active Transactions signal received"); + apt_watcher_determine_state (self, value); + } + g_variant_unref (parameters); +} AptWatcher* apt_watcher_new (SessionDbus* session_dbus, DbusmenuMenuitem* item) diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index f2dbede..8d0c6db 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -21,10 +21,10 @@ with this program. If not, see . */ typedef enum { - RESTART_NEEDED, + UP_TO_DATE, UPDATES_IN_PROGRESS, UPDATES_AVAILABLE, - UP_TO_DATE, + RESTART_NEEDED }AptState; -- cgit v1.2.3 From c6687bb3bc9e34b20da5c77a5adf42afb4a168f9 Mon Sep 17 00:00:00 2001 From: Neil Jagdish Patel Date: Thu, 21 Jul 2011 13:18:47 +0100 Subject: Always send the actual pointers to the entry not pointers to copies --- src/indicator-session.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/indicator-session.c b/src/indicator-session.c index 068ffef..af4e2eb 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -449,17 +449,15 @@ user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data //Otherwise self->show_users_entry = update; - IndicatorObjectEntry user_entry = self->users; - if (self->show_users_entry == TRUE){ g_signal_emit_by_name ((gpointer)self, "entry-added", - &user_entry); + &self->users); } else{ g_signal_emit_by_name ((gpointer)self, "entry-removed", - &user_entry); + &self->users); } } @@ -489,18 +487,16 @@ receive_signal (GDBusProxy * proxy, //Otherwise self->show_users_entry = update; - - IndicatorObjectEntry user_entry = self->users; if (self->show_users_entry == TRUE){ g_signal_emit_by_name ((gpointer)self, "entry-added", - &user_entry); + &self->users); } else{ g_signal_emit_by_name ((gpointer)self, "entry-removed", - &user_entry); + &self->users); } } } -- cgit v1.2.3 From dfa3b112e2b9c303102cf3805aa2e8f77f9aaffe Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 21 Jul 2011 14:03:09 +0100 Subject: trying to figure out if upgrades are needed in progress --- src/apt-watcher.c | 150 +++++++++++++++++++++++++++++++++++++++++++----- src/indicator-session.c | 6 +- 2 files changed, 139 insertions(+), 17 deletions(-) diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 703137a..d02203b 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -19,7 +19,6 @@ with this program. If not, see . #include #include - #include "apt-watcher.h" #include "dbus-shared-names.h" @@ -30,6 +29,7 @@ struct _AptWatcher GObject parent_instance; GCancellable * proxy_cancel; GDBusProxy * proxy; + GDBusProxy * transaction_proxy; SessionDbus* session_dbus_interface; DbusmenuMenuitem* apt_item; gint current_state; @@ -44,25 +44,42 @@ static void apt_watcher_on_name_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data); -static void +/*static void apt_watcher_get_active_transactions_cb (GObject * obj, GAsyncResult * res, gpointer user_data); -static void -fetch_proxy_cb (GObject * object, - GAsyncResult * res, - gpointer user_data); + * */ +static void fetch_proxy_cb (GObject * object, + GAsyncResult * res, + gpointer user_data); + +static void apt_watcher_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); + +static void apt_watcher_upgrade_system_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); + + static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi, guint timestamp, gchar * type); + static void apt_watcher_signal_cb (GDBusProxy* proxy, gchar* sender_name, gchar* signal_name, GVariant* parameters, gpointer user_data); + static void apt_watcher_determine_state (AptWatcher* self, GVariant* update); +static void transaction_on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data); + G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); static void @@ -70,6 +87,8 @@ apt_watcher_init (AptWatcher *self) { self->current_state = UP_TO_DATE; self->proxy_cancel = g_cancellable_new(); + self->proxy = NULL; + self->transaction_proxy = NULL; g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -149,18 +168,41 @@ apt_watcher_on_name_appeared (GDBusConnection *connection, name, "the system bus", name_owner); - + g_dbus_proxy_call (watcher->proxy, + "UpgradeSystem", + g_variant_new_boolean (TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_upgrade_system_cb, + user_data); + + /*g_dbus_proxy_call (watcher->proxy, "GetActiveTransactions", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, apt_watcher_get_active_transactions_cb, - user_data); + user_data);*/ } static void +apt_watcher_on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_debug ("Name %s does not exist or has just vanished", + name); + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + if (self->proxy != NULL) + g_object_unref (self->proxy); +} + +/*static void apt_watcher_get_active_transactions_cb (GObject * obj, GAsyncResult * res, gpointer user_data) @@ -179,16 +221,96 @@ apt_watcher_get_active_transactions_cb (GObject * obj, return; } apt_watcher_determine_state (self, result); +}*/ + +static void +apt_watcher_upgrade_system_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete the UpgradeSystem apt call"); + g_error_free (error); + return; + } + + gchar* transaction_id = NULL; + g_variant_get (result, "(s)", &transaction_id); + + if (transaction_id != NULL){ + if (self->transaction_proxy != NULL){ + g_object_unref (self->transaction_proxy); + self->transaction_proxy = NULL; + } + self->transaction_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.debian.apt", + transaction_id, + "org.debian.apt", + NULL, /* GCancellable */ + &error); + if (error != NULL) { + g_warning ("unable to fetch proxy for transaction object path"); + g_error_free (error); + return; + } + g_signal_connect (self->transaction_proxy, + "g-properties-changed", + G_CALLBACK (transaction_on_properties_changed), + self); + + g_dbus_proxy_call (self->transaction_proxy, + "Simulate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_simulate_transaction_cb, + self); + } } static void -apt_watcher_on_name_vanished (GDBusConnection *connection, - const gchar *name, - gpointer user_data) +apt_watcher_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) { - g_print ("Name %s does not exist on %s\n", - name, - "the system bus"); +} + +static void +transaction_on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data) +{ + if (g_variant_n_children (changed_properties) > 0) + { + GVariantIter *iter; + const gchar *key; + GVariant *value; + + g_print (" *** Properties Changed:\n"); + g_variant_get (changed_properties, + "a{sv}", + &iter); + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) + { + gchar *value_str; + value_str = g_variant_print (value, TRUE); + g_print (" %s -> %s\n", key, value_str); + g_free (value_str); + } + g_variant_iter_free (iter); + } } static void diff --git a/src/indicator-session.c b/src/indicator-session.c index df8cbdf..990140a 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -449,17 +449,17 @@ user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data //Otherwise self->show_users_entry = update; - IndicatorObjectEntry user_entry = self->users; + //IndicatorObjectEntry user_entry = self->users; if (self->show_users_entry == TRUE){ g_signal_emit_by_name ((gpointer)self, "entry-added", - &user_entry); + &self->users); } else{ g_signal_emit_by_name ((gpointer)self, "entry-removed", - &user_entry); + &self->users); } } -- cgit v1.2.3 From d89b98ffa2abc0c38dea6d30399073d239a66ce1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 21 Jul 2011 16:38:44 +0100 Subject: transaction object in place --- src/Makefile.am | 2 + src/apt-transaction.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/apt-transaction.h | 48 +++++++++++++++ src/apt-watcher.c | 118 ++++++++++------------------------- 4 files changed, 250 insertions(+), 85 deletions(-) create mode 100644 src/apt-transaction.c create mode 100644 src/apt-transaction.h diff --git a/src/Makefile.am b/src/Makefile.am index 753b71d..83d12bb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,6 +98,8 @@ indicator_session_service_SOURCES = \ device-menu-mgr.c \ apt-watcher.h \ apt-watcher.c \ + apt-transaction.h \ + apt-transaction.c \ udev-mgr.h \ udev-mgr.c indicator_session_service_CFLAGS = \ diff --git a/src/apt-transaction.c b/src/apt-transaction.c new file mode 100644 index 0000000..68e1f6b --- /dev/null +++ b/src/apt-transaction.c @@ -0,0 +1,167 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include + +#include "apt-transaction.h" + + +static void apt_transaction_on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data); + +static void apt_transaction_investigate (AptTransaction* self); +static void apt_transaction_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); + +struct _AptTransaction +{ + GObject parent_instance; + GDBusProxy * proxy; + gchar* id; +}; + +G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT); + +static void +apt_transaction_init (AptTransaction *self) +{ + self->proxy = NULL; + self->id = NULL; +} + +static void +apt_transaction_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + AptTransaction* self = APT_TRANSACTION(object); + if (self->proxy != NULL){ + g_object_unref (self->proxy); + self->proxy = NULL; + } + g_free (self->id); + G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object); +} + +static void +apt_transaction_class_init (AptTransactionClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + //GObjectClass* parent_class = G_OBJECT_CLASS (klass); + object_class->finalize = apt_transaction_finalize; +} + +static void +apt_transaction_investigate(AptTransaction* self) +{ + GError * error = NULL; + + self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.debian.apt", + self->id, + "org.debian.apt.transaction", + NULL, /* GCancellable */ + &error); + if (error != NULL) { + g_warning ("unable to fetch proxy for transaction object path %s", self->id); + g_error_free (error); + return; + } + g_debug ("connecting to the properties changed signal on the transaction object"); + g_signal_connect (self->proxy, + "g-properties-changed", + G_CALLBACK (apt_transaction_on_properties_changed), + self); + + g_debug ("calling simulate on the transaction object"); + g_dbus_proxy_call (self->proxy, + "Simulate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_transaction_simulate_transaction_cb, + self); +} + +static void +apt_transaction_on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data) +{ + if (g_variant_n_children (changed_properties) > 0) + { + GVariantIter *iter; + const gchar *key; + GVariant *value; + + g_print (" *** Apt Transaction Properties Changed:\n"); + g_variant_get (changed_properties, + "a{sv}", + &iter); + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) + { + gchar *value_str; + value_str = g_variant_print (value, TRUE); + g_print (" %s -> %s\n", key, value_str); + g_free (value_str); + } + g_variant_iter_free (iter); + } +} + +static void +apt_transaction_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) +{ + g_debug ("Simulate return"); + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION (user_data); + + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete the simulate call"); + g_error_free (error); + return; + } + + g_debug ("simulate returned a %s", + g_variant_get_type_string (result)); + +} + + +AptTransaction* apt_transaction_new (gchar* transaction_id) +{ + AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL); + tr->id = transaction_id; + g_debug ("Apt transaction new"); + apt_transaction_investigate (tr); + return tr; +} diff --git a/src/apt-transaction.h b/src/apt-transaction.h new file mode 100644 index 0000000..dec62ef --- /dev/null +++ b/src/apt-transaction.h @@ -0,0 +1,48 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + 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. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifndef _APT_TRANSACTION_H_ +#define _APT_TRANSACTION_H_ + +#include + +G_BEGIN_DECLS + +#define APT_TYPE_TRANSACTION (apt_transaction_get_type ()) +#define APT_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_TRANSACTION, AptTransaction)) +#define APT_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_TRANSACTION, AptTransactionClass)) +#define APT_IS_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_TRANSACTION)) +#define APT_IS_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_TRANSACTION)) +#define APT_TRANSACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_TRANSACTION, AptTransactionClass)) + +typedef struct _AptTransactionClass AptTransactionClass; +typedef struct _AptTransaction AptTransaction; + +struct _AptTransactionClass +{ + GObjectClass parent_class; +}; + +AptTransaction* apt_transaction_new (gchar* transaction_id); + +GType apt_transaction_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _APT_TRANSACTION_H_ */ diff --git a/src/apt-watcher.c b/src/apt-watcher.c index d02203b..7553f6e 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -21,6 +21,7 @@ with this program. If not, see . #include #include "apt-watcher.h" #include "dbus-shared-names.h" +#include "apt-transaction.h" static guint watcher_id; @@ -29,10 +30,10 @@ struct _AptWatcher GObject parent_instance; GCancellable * proxy_cancel; GDBusProxy * proxy; - GDBusProxy * transaction_proxy; SessionDbus* session_dbus_interface; DbusmenuMenuitem* apt_item; gint current_state; + AptTransaction* current_transaction; }; static void @@ -53,10 +54,6 @@ static void fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); -static void apt_watcher_simulate_transaction_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data); - static void apt_watcher_upgrade_system_cb (GObject * obj, GAsyncResult * res, gpointer user_data); @@ -72,13 +69,9 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy, GVariant* parameters, gpointer user_data); -static void apt_watcher_determine_state (AptWatcher* self, - GVariant* update); +/*static void apt_watcher_determine_state (AptWatcher* self, + GVariant* update);*/ -static void transaction_on_properties_changed (GDBusProxy *proxy, - GVariant *changed_properties, - const gchar* const *invalidated_properties, - gpointer user_data); G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); @@ -88,7 +81,7 @@ apt_watcher_init (AptWatcher *self) self->current_state = UP_TO_DATE; self->proxy_cancel = g_cancellable_new(); self->proxy = NULL; - self->transaction_proxy = NULL; + self->current_transaction = NULL; g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -104,6 +97,10 @@ static void apt_watcher_finalize (GObject *object) { g_bus_unwatch_name (watcher_id); + AptWatcher* self = APT_WATCHER (object); + + if (self->proxy != NULL) + g_object_unref (self->proxy); G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object); } @@ -171,13 +168,15 @@ apt_watcher_on_name_appeared (GDBusConnection *connection, g_dbus_proxy_call (watcher->proxy, "UpgradeSystem", - g_variant_new_boolean (TRUE), + g_variant_new("(b)", TRUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, apt_watcher_upgrade_system_cb, user_data); + g_debug ("UpgradeSystem apt call made"); + /*g_dbus_proxy_call (watcher->proxy, "GetActiveTransactions", NULL, @@ -196,10 +195,6 @@ apt_watcher_on_name_vanished (GDBusConnection *connection, g_debug ("Name %s does not exist or has just vanished", name); g_return_if_fail (APT_IS_WATCHER (user_data)); - AptWatcher* self = APT_WATCHER (user_data); - - if (self->proxy != NULL) - g_object_unref (self->proxy); } /*static void @@ -228,6 +223,8 @@ apt_watcher_upgrade_system_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { + g_debug ("UpgradeSystem apt callback"); + g_return_if_fail (APT_IS_WATCHER (user_data)); AptWatcher* self = APT_WATCHER (user_data); @@ -244,76 +241,21 @@ apt_watcher_upgrade_system_cb (GObject * obj, gchar* transaction_id = NULL; g_variant_get (result, "(s)", &transaction_id); + + if (transaction_id == NULL){ + g_debug ("apt_watcher_upgrade_system_cb - transaction id is null"); + return; + } - if (transaction_id != NULL){ - if (self->transaction_proxy != NULL){ - g_object_unref (self->transaction_proxy); - self->transaction_proxy = NULL; - } - self->transaction_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, /* GDBusInterfaceInfo */ - "org.debian.apt", - transaction_id, - "org.debian.apt", - NULL, /* GCancellable */ - &error); - if (error != NULL) { - g_warning ("unable to fetch proxy for transaction object path"); - g_error_free (error); - return; - } - g_signal_connect (self->transaction_proxy, - "g-properties-changed", - G_CALLBACK (transaction_on_properties_changed), - self); - - g_dbus_proxy_call (self->transaction_proxy, - "Simulate", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - apt_watcher_simulate_transaction_cb, - self); - } -} + if (self->current_transaction == NULL){ + self->current_transaction = apt_transaction_new (transaction_id); + } -static void -apt_watcher_simulate_transaction_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data) -{ } -static void -transaction_on_properties_changed (GDBusProxy *proxy, - GVariant *changed_properties, - const gchar* const *invalidated_properties, - gpointer user_data) -{ - if (g_variant_n_children (changed_properties) > 0) - { - GVariantIter *iter; - const gchar *key; - GVariant *value; - - g_print (" *** Properties Changed:\n"); - g_variant_get (changed_properties, - "a{sv}", - &iter); - while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) - { - gchar *value_str; - value_str = g_variant_print (value, TRUE); - g_print (" %s -> %s\n", key, value_str); - g_free (value_str); - } - g_variant_iter_free (iter); - } -} -static void + +/*static void apt_watcher_determine_state (AptWatcher* self, GVariant* update) { @@ -346,7 +288,7 @@ apt_watcher_determine_state (AptWatcher* self, _("Updates Installing...")); } } -} +}*/ static void apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, @@ -355,7 +297,8 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, { } -// TODO signal is of type s not sas which is on d-feet !!! +// TODO - Ask MVO about this. +// Signal is of type s not sas which is on d-feet !!! static void apt_watcher_signal_cb ( GDBusProxy* proxy, gchar* sender_name, gchar* signal_name, @@ -370,7 +313,12 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ g_debug ("Active Transactions signal received"); - apt_watcher_determine_state (self, value); + gchar* input = NULL; + g_variant_get(value, "s", & input); + g_debug ("Active Transactions signal - input = %s", input); + if (self->current_transaction == NULL){ + self->current_transaction = apt_transaction_new (input); + } } g_variant_unref (parameters); } -- cgit v1.2.3 From c3a8c16fbfed17d6c3f8a3cae0a6f6abe5194eaa Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 21 Jul 2011 17:00:41 +0100 Subject: properties changed signal is being triggered --- src/apt-transaction.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index 68e1f6b..89a62af 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -110,6 +110,8 @@ apt_transaction_on_properties_changed (GDBusProxy *proxy, const gchar* const *invalidated_properties, gpointer user_data) { + g_print (" *** Apt Transaction Properties Changed:\n"); + if (g_variant_n_children (changed_properties) > 0) { GVariantIter *iter; @@ -156,12 +158,11 @@ apt_transaction_simulate_transaction_cb (GObject * obj, } - AptTransaction* apt_transaction_new (gchar* transaction_id) { AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL); tr->id = transaction_id; - g_debug ("Apt transaction new"); + g_debug ("Apt transaction new id = %s", tr->id); apt_transaction_investigate (tr); return tr; } -- cgit v1.2.3 From 7e6cf4cec8da62fc8e784d183af0baed8e7f905c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 21 Jul 2011 20:23:22 +0100 Subject: apt item now sensitive to updates available --- src/apt-transaction.c | 128 +++++++++++++++++++++++++++++++----------------- src/apt-watcher.c | 93 ++++++++++++++++------------------- src/dbus-shared-names.h | 4 +- src/device-menu-mgr.c | 122 ++++++--------------------------------------- 4 files changed, 146 insertions(+), 201 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index 89a62af..1a4aa47 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -20,25 +20,33 @@ with this program. If not, see . #include #include "apt-transaction.h" - - -static void apt_transaction_on_properties_changed (GDBusProxy *proxy, - GVariant *changed_properties, - const gchar* const *invalidated_properties, - gpointer user_data); +#include "dbus-shared-names.h" static void apt_transaction_investigate (AptTransaction* self); static void apt_transaction_simulate_transaction_cb (GObject * obj, GAsyncResult * res, gpointer user_data); +static void apt_transaction_receive_signal (GDBusProxy * proxy, + gchar * sender_name, + gchar * signal_name, + GVariant * parameters, + gpointer user_data); struct _AptTransaction { GObject parent_instance; GDBusProxy * proxy; gchar* id; + AptState current_state; }; +enum { + UPDATE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT); static void @@ -46,6 +54,7 @@ apt_transaction_init (AptTransaction *self) { self->proxy = NULL; self->id = NULL; + } static void @@ -67,6 +76,14 @@ apt_transaction_class_init (AptTransactionClass *klass) GObjectClass* object_class = G_OBJECT_CLASS (klass); //GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = apt_transaction_finalize; + + signals[UPDATE] = g_signal_new("state-update", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); } static void @@ -75,22 +92,24 @@ apt_transaction_investigate(AptTransaction* self) GError * error = NULL; self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, /* GDBusInterfaceInfo */ "org.debian.apt", self->id, "org.debian.apt.transaction", NULL, /* GCancellable */ &error); + g_debug ("Just after creating the proxy for the transaction - id = %s", + self->id); if (error != NULL) { g_warning ("unable to fetch proxy for transaction object path %s", self->id); g_error_free (error); return; } g_debug ("connecting to the properties changed signal on the transaction object"); - g_signal_connect (self->proxy, - "g-properties-changed", - G_CALLBACK (apt_transaction_on_properties_changed), + g_signal_connect (G_OBJECT(self->proxy), + "g-signal", + G_CALLBACK (apt_transaction_receive_signal), self); g_debug ("calling simulate on the transaction object"); @@ -105,32 +124,64 @@ apt_transaction_investigate(AptTransaction* self) } static void -apt_transaction_on_properties_changed (GDBusProxy *proxy, - GVariant *changed_properties, - const gchar* const *invalidated_properties, - gpointer user_data) +apt_transaction_receive_signal (GDBusProxy * proxy, + gchar * sender_name, + gchar * signal_name, + GVariant * parameters, + gpointer user_data) { - g_print (" *** Apt Transaction Properties Changed:\n"); - - if (g_variant_n_children (changed_properties) > 0) + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION(user_data); + + if (g_strcmp0 (signal_name, "Finished") == 0){ + g_signal_emit (self, + signals[UPDATE], + 0, + FINISHED_CHECKING); + + } + else if (g_strcmp0(signal_name, "PropertyChanged") == 0) { - GVariantIter *iter; - const gchar *key; - GVariant *value; - - g_print (" *** Apt Transaction Properties Changed:\n"); - g_variant_get (changed_properties, - "a{sv}", - &iter); - while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) - { - gchar *value_str; - value_str = g_variant_print (value, TRUE); - g_print (" %s -> %s\n", key, value_str); - g_free (value_str); + gchar* prop_name= NULL; + GVariant* value = NULL; + g_variant_get (parameters, "(sv)", &prop_name, &value); + + if (g_strcmp0 (prop_name, "Dependencies") == 0){ + + + gchar** install = NULL; + gchar** reinstall = NULL; + gchar** remove = NULL; + gchar** purge = NULL; + gchar** upgrade = NULL; + gchar** downgrade = NULL; + gchar** keep = NULL; + g_variant_get (value, "(asasasasasasas)", &install, + &reinstall, &remove, &purge, &upgrade, &downgrade, + &keep); + + //g_debug ("Seemed to uppack dependencies without any warnings"); + //g_debug ("Upgrade quantity : %u", g_strv_length(upgrade)); + gboolean upgrade_needed = (g_strv_length(upgrade) > 0) || + (g_strv_length(install) > 0) || + (g_strv_length(reinstall) > 0) || + (g_strv_length(remove) > 0) || + (g_strv_length(purge) > 0); + if (upgrade_needed == TRUE){ + g_signal_emit (self, + signals[UPDATE], + 0, + UPDATES_AVAILABLE); + + } + else{ + g_signal_emit (self, + signals[UPDATE], + 0, + UP_TO_DATE); + } } - g_variant_iter_free (iter); - } + } } static void @@ -138,24 +189,13 @@ apt_transaction_simulate_transaction_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { - g_debug ("Simulate return"); - g_return_if_fail (APT_IS_TRANSACTION (user_data)); - AptTransaction* self = APT_TRANSACTION (user_data); - GError * error = NULL; - GVariant * result; - - result = g_dbus_proxy_call_finish(self->proxy, res, &error); if (error != NULL) { g_warning ("unable to complete the simulate call"); g_error_free (error); return; } - - g_debug ("simulate returned a %s", - g_variant_get_type_string (result)); - } AptTransaction* apt_transaction_new (gchar* transaction_id) diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 7553f6e..844e273 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -32,7 +32,7 @@ struct _AptWatcher GDBusProxy * proxy; SessionDbus* session_dbus_interface; DbusmenuMenuitem* apt_item; - gint current_state; + AptState current_state; AptTransaction* current_transaction; }; @@ -45,11 +45,6 @@ static void apt_watcher_on_name_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data); -/*static void -apt_watcher_get_active_transactions_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data); - * */ static void fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); @@ -68,9 +63,9 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy, gchar* signal_name, GVariant* parameters, gpointer user_data); - -/*static void apt_watcher_determine_state (AptWatcher* self, - GVariant* update);*/ +static void apt_watcher_manage_transactions (AptWatcher* self, + gchar* transaction_id); + G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); @@ -144,7 +139,6 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) self, NULL); - //We'll need to connect to the state changed signal g_signal_connect (self->proxy, "g-signal", G_CALLBACK(apt_watcher_signal_cb), @@ -174,17 +168,6 @@ apt_watcher_on_name_appeared (GDBusConnection *connection, NULL, apt_watcher_upgrade_system_cb, user_data); - - g_debug ("UpgradeSystem apt call made"); - - /*g_dbus_proxy_call (watcher->proxy, - "GetActiveTransactions", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - apt_watcher_get_active_transactions_cb, - user_data);*/ } static void @@ -197,27 +180,6 @@ apt_watcher_on_name_vanished (GDBusConnection *connection, g_return_if_fail (APT_IS_WATCHER (user_data)); } -/*static void -apt_watcher_get_active_transactions_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data) -{ - g_return_if_fail (APT_IS_WATCHER (user_data)); - AptWatcher* self = APT_WATCHER (user_data); - - GError * error = NULL; - GVariant * result; - - result = g_dbus_proxy_call_finish(self->proxy, res, &error); - - if (error != NULL) { - g_warning ("unable to complete the fetching of active transactions"); - g_error_free (error); - return; - } - apt_watcher_determine_state (self, result); -}*/ - static void apt_watcher_upgrade_system_cb (GObject * obj, GAsyncResult * res, @@ -247,10 +209,8 @@ apt_watcher_upgrade_system_cb (GObject * obj, return; } - if (self->current_transaction == NULL){ - self->current_transaction = apt_transaction_new (transaction_id); - } - + apt_watcher_manage_transactions (self, transaction_id); + } @@ -297,6 +257,42 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, { } + +static void +apt_watcher_transaction_state_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) +{ + g_debug ("apt-watcher -transaction update %i", update); + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + AptState state = (AptState)update; + + if ( state == UP_TO_DATE ){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + } + else if ( state == UPDATES_AVAILABLE ){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Available…")); + } + self->current_state = state; +} + +static void +apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) +{ + if (self->current_transaction == NULL){ + self->current_transaction = apt_transaction_new (transaction_id); + g_signal_connect (G_OBJECT(self->current_transaction), + "state-update", + G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + } +} + // TODO - Ask MVO about this. // Signal is of type s not sas which is on d-feet !!! static void apt_watcher_signal_cb ( GDBusProxy* proxy, @@ -312,13 +308,10 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, GVariant *value = g_variant_get_child_value (parameters, 0); if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ - g_debug ("Active Transactions signal received"); gchar* input = NULL; g_variant_get(value, "s", & input); g_debug ("Active Transactions signal - input = %s", input); - if (self->current_transaction == NULL){ - self->current_transaction = apt_transaction_new (input); - } + apt_watcher_manage_transactions (self, input); } g_variant_unref (parameters); } diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 8d0c6db..13ad227 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -22,8 +22,10 @@ with this program. If not, see . typedef enum { UP_TO_DATE, - UPDATES_IN_PROGRESS, + CHECKING_FOR_UPDATES, UPDATES_AVAILABLE, + FINISHED_CHECKING, + UPDATING, RESTART_NEEDED }AptState; diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 9c54ef3..b13b2fa 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -54,7 +54,6 @@ static DbusmenuMenuitem *printers_menuitem = NULL; static DbusmenuMenuitem *scanners_menuitem = NULL; static DbusmenuMenuitem *webcam_menuitem = NULL; - static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; @@ -188,6 +187,7 @@ sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) return; } + /*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, @@ -251,16 +251,15 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) gboolean local_can_suspend = g_value_get_boolean(&candoit); if (local_can_suspend != can_suspend) { can_suspend = local_can_suspend; + // TODO figure out what needs updating on the menu device_menu_mgr_rebuild_items(self); } - return; } /* Response to getting the hibernate property */ // TODO // Is this needed anymore - static void hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -434,6 +433,19 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) g_free(dialog_line); } +static void +show_session_properties (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("gnome-session-properties", &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } +} + static void show_system_settings_with_context (DbusmenuMenuitem * mi, guint timestamp, @@ -496,7 +508,7 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) _("Login Items...")); g_signal_connect (G_OBJECT(login_settings_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_system_settings_with_context), + G_CALLBACK(show_session_properties), "login"); dbusmenu_menuitem_child_add_position(self->root_item, login_settings_menuitem, @@ -660,108 +672,6 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) static void device_menu_mgr_rebuild_items (DeviceMenuMgr* self) { - //gboolean can_lockscreen; - - /* Make sure we have a valid GConf client, and build one - if needed */ - //device_menu_mgr_ensure_gconf_client (self); - - /*can_lockscreen = !gconf_client_get_bool ( gconf_client, - LOCKDOWN_KEY_SCREENSAVER, - NULL); - if (can_lockscreen) { - lock_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (lock_menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Lock Screen")); - - gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); - if (shortcut != NULL) { - g_debug("Lock screen shortcut: %s", shortcut); - dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); - g_free(shortcut); - } else { - g_debug("Unable to get lock screen shortcut."); - } - - g_signal_connect (G_OBJECT(lock_menuitem), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(lock_screen), NULL); - dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); - } - - logout_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out")); - } else { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (logout_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_logout()); - dbusmenu_menuitem_child_append(self->root_item, logout_mi); - g_signal_connect( G_OBJECT(logout_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "logout"); - - if (can_suspend && allow_suspend) { - suspend_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (suspend_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Suspend")); - dbusmenu_menuitem_child_append (self->root_item, suspend_mi); - g_signal_connect( G_OBJECT(suspend_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(machine_sleep_from_suspend), - self); - } - - if (can_hibernate && allow_hibernate) { - hibernate_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (hibernate_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Hibernate")); - dbusmenu_menuitem_child_append(self->root_item, hibernate_mi); - g_signal_connect (G_OBJECT(hibernate_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(machine_sleep_from_hibernate), self); - } - - dbusmenu_menuitem_child_append(self->root_item, restart_mi); - g_signal_connect (G_OBJECT(restart_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "restart"); - - shutdown_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (shutdown_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Shut Down")); - } else { - dbusmenu_menuitem_property_set (shutdown_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Shut Down\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (shutdown_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_shutdown()); - dbusmenu_menuitem_child_append (self->root_item, shutdown_mi); - g_signal_connect (G_OBJECT(shutdown_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_dialog), "shutdown"); - - RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); - restart_shutdown_logout_mi->logout_mi = logout_mi; - restart_shutdown_logout_mi->restart_mi = restart_mi; - restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; - - update_menu_entries(restart_shutdown_logout_mi); - - return;*/ } /* When the directory changes we need to figure out how our menu -- cgit v1.2.3 From f94d6c4fe9c1ccb5a5e731b327fd57635c0ce326 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 21 Jul 2011 20:48:52 +0100 Subject: apt transactions working nicely --- src/apt-transaction.c | 15 ++---------- src/apt-watcher.c | 64 +++++++++++++++++---------------------------------- src/session-service.c | 4 ++-- 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index 1a4aa47..e613507 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -74,7 +74,6 @@ static void apt_transaction_class_init (AptTransactionClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - //GObjectClass* parent_class = G_OBJECT_CLASS (klass); object_class->finalize = apt_transaction_finalize; signals[UPDATE] = g_signal_new("state-update", @@ -99,20 +98,17 @@ apt_transaction_investigate(AptTransaction* self) "org.debian.apt.transaction", NULL, /* GCancellable */ &error); - g_debug ("Just after creating the proxy for the transaction - id = %s", - self->id); if (error != NULL) { g_warning ("unable to fetch proxy for transaction object path %s", self->id); g_error_free (error); return; } - g_debug ("connecting to the properties changed signal on the transaction object"); + g_signal_connect (G_OBJECT(self->proxy), "g-signal", G_CALLBACK (apt_transaction_receive_signal), self); - g_debug ("calling simulate on the transaction object"); g_dbus_proxy_call (self->proxy, "Simulate", NULL, @@ -133,14 +129,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, g_return_if_fail (APT_IS_TRANSACTION (user_data)); AptTransaction* self = APT_TRANSACTION(user_data); - if (g_strcmp0 (signal_name, "Finished") == 0){ - g_signal_emit (self, - signals[UPDATE], - 0, - FINISHED_CHECKING); - - } - else if (g_strcmp0(signal_name, "PropertyChanged") == 0) + if (g_strcmp0(signal_name, "PropertyChanged") == 0) { gchar* prop_name= NULL; GVariant* value = NULL; diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 844e273..546c733 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -185,8 +185,6 @@ apt_watcher_upgrade_system_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { - g_debug ("UpgradeSystem apt callback"); - g_return_if_fail (APT_IS_WATCHER (user_data)); AptWatcher* self = APT_WATCHER (user_data); @@ -205,7 +203,7 @@ apt_watcher_upgrade_system_cb (GObject * obj, g_variant_get (result, "(s)", &transaction_id); if (transaction_id == NULL){ - g_debug ("apt_watcher_upgrade_system_cb - transaction id is null"); + g_warning ("apt_watcher_upgrade_system_cb - transaction id is null"); return; } @@ -213,49 +211,17 @@ apt_watcher_upgrade_system_cb (GObject * obj, } - - -/*static void -apt_watcher_determine_state (AptWatcher* self, - GVariant* update) -{ - g_debug ("WE GOT SOME ACTIVE TRANSACTIONS TO EXAMINE, type is %s", - g_variant_get_type_string (update)); - - gchar* first_param = NULL; - gchar ** transactions = NULL; - - g_variant_get (update, "(sas)", &first_param, &transactions); - - g_debug ("apt_watcher_determine_state - the size is the string array %u", - g_strv_length (transactions)); - g_debug ("apt_watcher_determine_state - first param = %s", first_param); - - if (first_param == NULL){ - if (self->current_state != UP_TO_DATE){ - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Software Up to Date")); - } - } - else{ - gboolean updating = g_str_has_prefix (first_param, - "/org/debian/apt/transaction/"); - if (updating == TRUE){ - self->current_state = UPDATES_IN_PROGRESS; - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Updates Installing...")); - } - } -}*/ - static void apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) { - + GError * error = NULL; + if (!g_spawn_command_line_async("update-manager", &error)) + { + g_warning("Unable to show update-manager: %s", error->message); + g_error_free(error); + } } static void @@ -280,6 +246,8 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, _("Updates Available…")); } self->current_state = state; + g_object_unref (self->current_transaction); + self->current_transaction = NULL; } static void @@ -287,6 +255,7 @@ apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) { if (self->current_transaction == NULL){ self->current_transaction = apt_transaction_new (transaction_id); + g_object_ref (self->current_transaction); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", G_CALLBACK(apt_watcher_transaction_state_update_cb), self); @@ -310,8 +279,17 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ gchar* input = NULL; g_variant_get(value, "s", & input); - g_debug ("Active Transactions signal - input = %s", input); - apt_watcher_manage_transactions (self, input); + + g_debug ("Active Transactions signal - input is null = %i", input == NULL); + // TODO don't call on null terminated input + g_dbus_proxy_call (self->proxy, + "UpgradeSystem", + g_variant_new("(b)", TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_upgrade_system_cb, + user_data); } g_variant_unref (parameters); } diff --git a/src/session-service.c b/src/session-service.c index 22552dc..bb473e9 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -71,10 +71,10 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - /*if (mainloop != NULL) { + if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); - }*/ + } return; } -- cgit v1.2.3 From 3bfa1c305fbba42c48ed7338e5064745bb122a91 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 11:59:15 +0100 Subject: suspend plugged back in plus both it and hibernate menuitems should now be sensitive to changes coming from upower --- src/device-menu-mgr.c | 40 ++++++++++++++++++++++++++-------------- src/session-service.c | 4 ++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index b13b2fa..22e970f 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -58,7 +58,7 @@ static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; static DbusmenuMenuitem * hibernate_mi = NULL; -//static DbusmenuMenuitem * suspend_mi = NULL; +static DbusmenuMenuitem * suspend_mi = NULL; static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; @@ -86,11 +86,11 @@ static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -/*static void +static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -*/ + G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); static void @@ -106,7 +106,6 @@ device_menu_mgr_init (DeviceMenuMgr *self) static void device_menu_mgr_finalize (GObject *object) { - /* TODO: Add deinitalization code here */ G_OBJECT_CLASS (device_menu_mgr_parent_class)->finalize (object); } @@ -115,7 +114,6 @@ static void 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; } @@ -187,15 +185,14 @@ sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) return; } - -/*static void +static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); machine_sleep_with_context (self, "Suspend"); -}*/ +} static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, @@ -229,9 +226,6 @@ machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) } /* A response to getting the suspend property */ -// TODO -// Is this needed anymore - static void suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -252,14 +246,14 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) if (local_can_suspend != can_suspend) { can_suspend = local_can_suspend; // TODO figure out what needs updating on the menu + // And add or remove it but just don't rebuild the whole menu + // a waste device_menu_mgr_rebuild_items(self); } return; } /* Response to getting the hibernate property */ -// TODO -// Is this needed anymore static void hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -630,6 +624,18 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "logout"); + if (can_suspend && allow_suspend) { + suspend_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (suspend_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Suspend")); + dbusmenu_menuitem_child_append (self->root_item, suspend_mi); + g_signal_connect( G_OBJECT(suspend_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_suspend), + self); + } + if (can_hibernate && allow_hibernate) { hibernate_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (hibernate_mi, @@ -672,7 +678,13 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) static void device_menu_mgr_rebuild_items (DeviceMenuMgr* self) { -} + dbusmenu_menuitem_property_set_bool (hibernate_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + can_hibernate && allow_hibernate); + dbusmenu_menuitem_property_set_bool (suspend_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + can_suspend && allow_suspend); +} /* When the directory changes we need to figure out how our menu item should look. */ diff --git a/src/session-service.c b/src/session-service.c index bb473e9..74fe5b0 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -71,11 +71,11 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - if (mainloop != NULL) { + /*if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); } - return; + return;*/ } /* Main, is well, main. It brings everything up and throws -- cgit v1.2.3 From bc829db4eb65f7373b2ff13cd5dc8ce96a469af3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 13:37:16 +0100 Subject: transaction object now properly disposed of --- src/apt-transaction.c | 40 +++++++++++++++++++++++++++++++++++----- src/apt-watcher.c | 13 +++++++++---- src/dbus-shared-names.h | 3 +-- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index e613507..4f800ad 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -54,14 +54,16 @@ apt_transaction_init (AptTransaction *self) { self->proxy = NULL; self->id = NULL; - } static void apt_transaction_finalize (GObject *object) { - /* TODO: Add deinitalization code here */ AptTransaction* self = APT_TRANSACTION(object); + g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy), + G_CALLBACK (apt_transaction_receive_signal), + self); + if (self->proxy != NULL){ g_object_unref (self->proxy); self->proxy = NULL; @@ -91,7 +93,7 @@ apt_transaction_investigate(AptTransaction* self) GError * error = NULL; self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + G_DBUS_PROXY_FLAGS_NONE, NULL, /* GDBusInterfaceInfo */ "org.debian.apt", self->id, @@ -127,14 +129,42 @@ apt_transaction_receive_signal (GDBusProxy * proxy, gpointer user_data) { g_return_if_fail (APT_IS_TRANSACTION (user_data)); - AptTransaction* self = APT_TRANSACTION(user_data); - + AptTransaction* self = APT_TRANSACTION(user_data); + + GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, + "Role"); + g_debug ("Role variant type = %s", g_variant_get_type_string (role)); + if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* current_role = NULL; + g_variant_get (role, "s", ¤t_role); + g_debug ("Current transaction role = %s", current_role); + if (g_strcmp0 (current_role, "role-commit-packages") == 0 || + g_strcmp0 (current_role, "role-upgrade-system") == 0){ + g_debug ("UPGRADE IN PROGRESS"); + g_signal_emit (self, + signals[UPDATE], + 0, + UPGRADE_IN_PROGRESS); + // Return from here because an upgrade is in progress so + // any other information is irrelevant. + return; + } + } + if (g_strcmp0(signal_name, "PropertyChanged") == 0) { gchar* prop_name= NULL; GVariant* value = NULL; g_variant_get (parameters, "(sv)", &prop_name, &value); + g_debug ("transaction prop update - prop = %s", prop_name); + + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* key = NULL; + g_variant_get (value, "s", &key); + g_debug ("transaction prop update - value = %s", key); + } + if (g_strcmp0 (prop_name, "Dependencies") == 0){ diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 546c733..c7238ec 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -235,18 +235,23 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, AptState state = (AptState)update; - if ( state == UP_TO_DATE ){ + if (state == UP_TO_DATE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); } - else if ( state == UPDATES_AVAILABLE ){ + else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); + } + else if (state == UPGRADE_IN_PROGRESS){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Installing…")); } self->current_state = state; - g_object_unref (self->current_transaction); + g_object_unref (G_OBJECT(self->current_transaction)); self->current_transaction = NULL; } @@ -255,7 +260,7 @@ apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) { if (self->current_transaction == NULL){ self->current_transaction = apt_transaction_new (transaction_id); - g_object_ref (self->current_transaction); + //g_object_ref (self->current_transaction); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", G_CALLBACK(apt_watcher_transaction_state_update_cb), self); diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 13ad227..7c6c14f 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -24,8 +24,7 @@ typedef enum { UP_TO_DATE, CHECKING_FOR_UPDATES, UPDATES_AVAILABLE, - FINISHED_CHECKING, - UPDATING, + UPGRADE_IN_PROGRESS, RESTART_NEEDED }AptState; -- cgit v1.2.3 From 13452b541f9aabf229f16a029a4c823c76e2b1f0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 15:36:59 +0100 Subject: apt progress now reflected dynamically in the menu --- src/apt-transaction.c | 107 +++++++++++++++++++++++++----------------------- src/apt-transaction.h | 5 ++- src/apt-watcher.c | 60 +++++++++++++++++++-------- src/dbus-shared-names.h | 13 ++++-- src/device-menu-mgr.c | 14 ++++++- src/session-service.c | 4 +- 6 files changed, 123 insertions(+), 80 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index 4f800ad..61868a3 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -34,10 +34,10 @@ static void apt_transaction_receive_signal (GDBusProxy * proxy, struct _AptTransaction { - GObject parent_instance; - GDBusProxy * proxy; - gchar* id; - AptState current_state; + GObject parent_instance; + GDBusProxy * proxy; + gchar* id; + TransactionType type; }; enum { @@ -63,11 +63,10 @@ apt_transaction_finalize (GObject *object) g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy), G_CALLBACK (apt_transaction_receive_signal), self); - if (self->proxy != NULL){ g_object_unref (self->proxy); self->proxy = NULL; - } + } g_free (self->id); G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object); } @@ -111,14 +110,16 @@ apt_transaction_investigate(AptTransaction* self) G_CALLBACK (apt_transaction_receive_signal), self); - g_dbus_proxy_call (self->proxy, - "Simulate", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - apt_transaction_simulate_transaction_cb, - self); + if (self->type == SIMULATION){ + g_dbus_proxy_call (self->proxy, + "Simulate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_transaction_simulate_transaction_cb, + self); + } } static void @@ -130,33 +131,13 @@ apt_transaction_receive_signal (GDBusProxy * proxy, { g_return_if_fail (APT_IS_TRANSACTION (user_data)); AptTransaction* self = APT_TRANSACTION(user_data); + AptState current_state = UP_TO_DATE; - GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, - "Role"); - g_debug ("Role variant type = %s", g_variant_get_type_string (role)); - if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ - gchar* current_role = NULL; - g_variant_get (role, "s", ¤t_role); - g_debug ("Current transaction role = %s", current_role); - if (g_strcmp0 (current_role, "role-commit-packages") == 0 || - g_strcmp0 (current_role, "role-upgrade-system") == 0){ - g_debug ("UPGRADE IN PROGRESS"); - g_signal_emit (self, - signals[UPDATE], - 0, - UPGRADE_IN_PROGRESS); - // Return from here because an upgrade is in progress so - // any other information is irrelevant. - return; - } - } - - if (g_strcmp0(signal_name, "PropertyChanged") == 0) + if (g_strcmp0(signal_name, "PropertyChanged") == 0 && self->type == SIMULATION) { gchar* prop_name= NULL; GVariant* value = NULL; - g_variant_get (parameters, "(sv)", &prop_name, &value); - + g_variant_get (parameters, "(sv)", &prop_name, &value); g_debug ("transaction prop update - prop = %s", prop_name); if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){ @@ -166,8 +147,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, } if (g_strcmp0 (prop_name, "Dependencies") == 0){ - - + gchar** install = NULL; gchar** reinstall = NULL; gchar** remove = NULL; @@ -177,8 +157,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, gchar** keep = NULL; g_variant_get (value, "(asasasasasasas)", &install, &reinstall, &remove, &purge, &upgrade, &downgrade, - &keep); - + &keep); //g_debug ("Seemed to uppack dependencies without any warnings"); //g_debug ("Upgrade quantity : %u", g_strv_length(upgrade)); gboolean upgrade_needed = (g_strv_length(upgrade) > 0) || @@ -187,20 +166,39 @@ apt_transaction_receive_signal (GDBusProxy * proxy, (g_strv_length(remove) > 0) || (g_strv_length(purge) > 0); if (upgrade_needed == TRUE){ - g_signal_emit (self, - signals[UPDATE], - 0, - UPDATES_AVAILABLE); - + current_state = UPDATES_AVAILABLE; } else{ - g_signal_emit (self, - signals[UPDATE], - 0, - UP_TO_DATE); + current_state = UP_TO_DATE; + } + } + } + else if (g_strcmp0(signal_name, "PropertyChanged") == 0 && + self->type == REAL) + { + GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, + "Role"); + if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* current_role = NULL; + g_variant_get (role, "s", ¤t_role); + g_debug ("Current transaction role = %s", current_role); + if (g_strcmp0 (current_role, "role-commit-packages") == 0 || + g_strcmp0 (current_role, "role-upgrade-system") == 0){ + g_debug ("UPGRADE IN PROGRESS"); + current_state = UPGRADE_IN_PROGRESS; } } + } + else if (g_strcmp0(signal_name, "Finished") == 0) + { + g_debug ("TRANSACTION Finished"); + current_state = FINISHED; } + // Finally send out the state update + g_signal_emit (self, + signals[UPDATE], + 0, + current_state); } static void @@ -209,18 +207,23 @@ apt_transaction_simulate_transaction_cb (GObject * obj, gpointer user_data) { GError * error = NULL; - if (error != NULL) { g_warning ("unable to complete the simulate call"); g_error_free (error); return; } } +TransactionType +apt_transaction_get_transaction_type (AptTransaction* self) +{ + return self->type; +} -AptTransaction* apt_transaction_new (gchar* transaction_id) +AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t) { AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL); tr->id = transaction_id; + tr->type = t; g_debug ("Apt transaction new id = %s", tr->id); apt_transaction_investigate (tr); return tr; diff --git a/src/apt-transaction.h b/src/apt-transaction.h index dec62ef..9e4370d 100644 --- a/src/apt-transaction.h +++ b/src/apt-transaction.h @@ -21,6 +21,7 @@ with this program. If not, see . #define _APT_TRANSACTION_H_ #include +#include "dbus-shared-names.h" G_BEGIN_DECLS @@ -39,8 +40,8 @@ struct _AptTransactionClass GObjectClass parent_class; }; -AptTransaction* apt_transaction_new (gchar* transaction_id); - +AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t); +TransactionType apt_transaction_get_transaction_type (AptTransaction* self); GType apt_transaction_get_type (void) G_GNUC_CONST; G_END_DECLS diff --git a/src/apt-watcher.c b/src/apt-watcher.c index c7238ec..285eb81 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -20,7 +20,6 @@ with this program. If not, see . #include #include #include "apt-watcher.h" -#include "dbus-shared-names.h" #include "apt-transaction.h" static guint watcher_id; @@ -238,33 +237,53 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, if (state == UP_TO_DATE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, - _("Software Up to Date")); + _("Software Up to Date")); + // Simulations don't send a finished signal for some reason + // Anyway from a simulation we just need one state update + // (updates available or not) + if (apt_transaction_get_transaction_type (self->current_transaction) + == SIMULATION){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } } else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Available…")); + // Simulations don't send a finished signal for some reason + // Anyway from a simulation we just need one state update + // (updates available or not) + if (apt_transaction_get_transaction_type (self->current_transaction) + == SIMULATION){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } } else if (state == UPGRADE_IN_PROGRESS){ dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Updates Installing…")); } + else if (state == FINISHED){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } self->current_state = state; - g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; } static void apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) { if (self->current_transaction == NULL){ - self->current_transaction = apt_transaction_new (transaction_id); - //g_object_ref (self->current_transaction); + self->current_transaction = apt_transaction_new (transaction_id, SIMULATION); g_signal_connect (G_OBJECT(self->current_transaction), "state-update", G_CALLBACK(apt_watcher_transaction_state_update_cb), self); - } + } } // TODO - Ask MVO about this. @@ -284,17 +303,22 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ gchar* input = NULL; g_variant_get(value, "s", & input); - - g_debug ("Active Transactions signal - input is null = %i", input == NULL); - // TODO don't call on null terminated input - g_dbus_proxy_call (self->proxy, - "UpgradeSystem", - g_variant_new("(b)", TRUE), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - apt_watcher_upgrade_system_cb, - user_data); + if (g_str_has_prefix (input, "/org/debian/apt/transaction/") == TRUE){ + g_debug ("Active Transactions signal - input is null = %i", input == NULL); + + if (self->current_transaction != NULL) + { + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } + + self->current_transaction = apt_transaction_new (input, REAL); + g_signal_connect (G_OBJECT(self->current_transaction), + "state-update", + G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + + + } } g_variant_unref (parameters); } diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 7c6c14f..2114332 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -20,17 +20,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef __DBUS_SHARED_NAMES_H__ +#define __DBUS_SHARED_NAMES_H__ + typedef enum { UP_TO_DATE, CHECKING_FOR_UPDATES, UPDATES_AVAILABLE, - UPGRADE_IN_PROGRESS, + UPGRADE_IN_PROGRESS, + FINISHED, RESTART_NEEDED }AptState; - -#ifndef __DBUS_SHARED_NAMES_H__ -#define __DBUS_SHARED_NAMES_H__ 1 +typedef enum { + SIMULATION, + REAL +}TransactionType; #define INDICATOR_USERS_DBUS_NAME INDICATOR_SESSION_DBUS_NAME #define INDICATOR_USERS_DBUS_OBJECT "/com/canonical/indicator/users/menu" diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 22e970f..324b3f1 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -499,13 +499,13 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) login_settings_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (login_settings_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, - _("Login Items...")); + _("Startup Applications...")); g_signal_connect (G_OBJECT(login_settings_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_session_properties), "login"); dbusmenu_menuitem_child_add_position(self->root_item, - login_settings_menuitem, + login_settings_menuitem, 3); software_updates_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (software_updates_menuitem, @@ -555,6 +555,11 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) dbusmenu_menuitem_child_add_position (self->root_item, scanners_menuitem, 8); + //tmp + dbusmenu_menuitem_property_set_bool (scanners_menuitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + webcam_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (webcam_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, @@ -566,6 +571,11 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) dbusmenu_menuitem_child_add_position (self->root_item, webcam_menuitem, 10); + //tmp + dbusmenu_menuitem_property_set_bool (webcam_menuitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + DbusmenuMenuitem * separator3 = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (separator3, DBUSMENU_MENUITEM_PROP_TYPE, diff --git a/src/session-service.c b/src/session-service.c index 74fe5b0..bb473e9 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -71,11 +71,11 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - /*if (mainloop != NULL) { + if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); } - return;*/ + return; } /* Main, is well, main. It brings everything up and throws -- cgit v1.2.3 From ae4e70778e02f44c68a5860d701f216cefe58cd3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 17:40:20 +0100 Subject: fixed issues --- src/apt-transaction.c | 63 ++++++++++++++++++++++++++++++++++++--------------- src/apt-watcher.h | 7 ++++++ 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/apt-transaction.c b/src/apt-transaction.c index e613507..51a5ce9 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -31,11 +31,15 @@ static void apt_transaction_receive_signal (GDBusProxy * proxy, gchar * signal_name, GVariant * parameters, gpointer user_data); +static void apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data); struct _AptTransaction { GObject parent_instance; GDBusProxy * proxy; + GCancellable * proxy_cancel; gchar* id; AptState current_state; }; @@ -54,7 +58,7 @@ apt_transaction_init (AptTransaction *self) { self->proxy = NULL; self->id = NULL; - + self->proxy_cancel = g_cancellable_new(); } static void @@ -84,25 +88,46 @@ apt_transaction_class_init (AptTransactionClass *klass) g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); } +// TODO: you don't need this additional helper +// Just GObject properties properly +static void +apt_transaction_investigate (AptTransaction* self) +{ + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.debian.apt", + self->id, + "org.debian.apt.transaction", + self->proxy_cancel, + apt_transaction_finish_proxy_setup, + self); +} static void -apt_transaction_investigate(AptTransaction* self) +apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - GError * error = NULL; - - self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, /* GDBusInterfaceInfo */ - "org.debian.apt", - self->id, - "org.debian.apt.transaction", - NULL, /* GCancellable */ - &error); - if (error != NULL) { - g_warning ("unable to fetch proxy for transaction object path %s", self->id); - g_error_free (error); - return; - } + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION(user_data); + GError * error = NULL; + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (self->proxy_cancel != NULL) { + g_object_unref(self->proxy_cancel); + self->proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", + "org.debian.apt", error->message); + g_error_free(error); + return; + } + + self->proxy = proxy; g_signal_connect (G_OBJECT(self->proxy), "g-signal", @@ -117,7 +142,8 @@ apt_transaction_investigate(AptTransaction* self) NULL, apt_transaction_simulate_transaction_cb, self); -} + +} static void apt_transaction_receive_signal (GDBusProxy * proxy, @@ -171,6 +197,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, } } } + g_variant_unref (parameters); } static void diff --git a/src/apt-watcher.h b/src/apt-watcher.h index cbe0e29..7b98a44 100644 --- a/src/apt-watcher.h +++ b/src/apt-watcher.h @@ -21,8 +21,15 @@ with this program. If not, see . #define _APT_WATCHER_H_ #include + #include + +#include +#if GTK_CHECK_VERSION(3, 0, 0) #include +#else +#include +#endif #include "session-dbus.h" -- cgit v1.2.3 From 92208b4e83ca7d486aa65ebc4b80e0d36e94095f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 18:07:00 +0100 Subject: bumped version in configure ac in prep for release --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2c4c867..17f5c55 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-session.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-session, 0.2.93) +AM_INIT_AUTOMAKE(indicator-session, 0.2.94) AM_MAINTAINER_MODE -- cgit v1.2.3 From 213927976eb58fe6c3cc26d5426ad6e3e2d69c14 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 18:12:20 +0100 Subject: added new files to the po index --- po/POTFILES.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/po/POTFILES.in b/po/POTFILES.in index c2256c1..08eff5f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,3 +7,6 @@ src/gtk-logout-helper.c src/dialog.c src/indicator-session.c src/session-service.c +src/apt-watcher.c +src/device-menu-mgr.c +src/user-menu-mgr.c -- cgit v1.2.3 From df0f2927babbf31d51b8a33fcf744d2a92e70ac5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 18:15:55 +0100 Subject: moving to 0.3.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 17f5c55..369f12b 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-session.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-session, 0.2.94) +AM_INIT_AUTOMAKE(indicator-session, 0.3.0) AM_MAINTAINER_MODE -- cgit v1.2.3 From a1a7357b58d182e077ebfe8fb11c083e5eb18839 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 22 Jul 2011 18:22:37 +0100 Subject: uncomment the disconnect method --- src/session-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 22552dc..bb473e9 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -71,10 +71,10 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - /*if (mainloop != NULL) { + if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); - }*/ + } return; } -- cgit v1.2.3