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 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 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