diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-06-05 15:58:03 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-06-05 15:58:03 -0500 |
commit | f6a082bcac4299ca82dadb623b497226140bbad1 (patch) | |
tree | 58292e2340ee9429d4e83e04a459d4f8d617ca08 | |
parent | a535ab4cae4cb2471f1733fe5bc0bcc2249b5dda (diff) | |
download | ayatana-indicator-session-f6a082bcac4299ca82dadb623b497226140bbad1.tar.gz ayatana-indicator-session-f6a082bcac4299ca82dadb623b497226140bbad1.tar.bz2 ayatana-indicator-session-f6a082bcac4299ca82dadb623b497226140bbad1.zip |
fix tab damage in device-menu-mgr.c
-rw-r--r-- | src/device-menu-mgr.c | 390 |
1 files changed, 166 insertions, 224 deletions
diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 80e3b0a..039b68d 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -249,88 +249,76 @@ hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) static void up_changed_cb (DBusGProxy * proxy, gpointer user_data) { - DeviceMenuMgr * self = DEVICE_MENU_MGR(user_data); - - /* Start Async call to see if we can hibernate */ - if (self->suspend_call == NULL) { - self->suspend_call = dbus_g_proxy_begin_call(self->up_prop_proxy, - "Get", - suspend_prop_cb, - user_data, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanSuspend", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } - - /* Start Async call to see if we can suspend */ - if (self->hibernate_call == NULL) { - self->hibernate_call = dbus_g_proxy_begin_call(self->up_prop_proxy, - "Get", - hibernate_prop_cb, - user_data, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanHibernate", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } + DeviceMenuMgr * self = DEVICE_MENU_MGR(user_data); + + if (self->suspend_call == NULL) + { + /* start async call to see if we can hibernate */ + self->suspend_call = dbus_g_proxy_begin_call (self->up_prop_proxy, + "Get", + suspend_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanSuspend", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } + + if (self->hibernate_call == NULL) + { + /* start async call to see if we can suspend */ + self->hibernate_call = dbus_g_proxy_begin_call (self->up_prop_proxy, + "Get", + hibernate_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanHibernate", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } } -/* This function goes through and sets up what we need for - DKp checking. We're even setting up the calls for the props - we need */ +/* This function goes through and sets up what we need for DKp checking. + We're even setting up the calls for the props we need */ static void -setup_up (DeviceMenuMgr* self) { - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - g_return_if_fail(bus != NULL); - - if (self->up_main_proxy == NULL) { - self->up_main_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - UP_INTERFACE); - } - g_return_if_fail(self->up_main_proxy != NULL); - - if (self->up_prop_proxy == NULL) { - self->up_prop_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - DBUS_INTERFACE_PROPERTIES); - /* Connect to changed signal */ - dbus_g_proxy_add_signal(self->up_main_proxy, - "Changed", - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal(self->up_main_proxy, - "Changed", - G_CALLBACK(up_changed_cb), - self, - NULL); - } - g_return_if_fail(self->up_prop_proxy != NULL); - - - /* Force an original "changed" event */ - up_changed_cb(self->up_main_proxy, self); - - /* Check to see if these are getting blocked by PolicyKit */ - org_freedesktop_UPower_suspend_allowed_async(self->up_main_proxy, - allowed_suspend_cb, - self); - org_freedesktop_UPower_hibernate_allowed_async(self->up_main_proxy, - allowed_hibernate_cb, - self); - - return; +setup_up (DeviceMenuMgr* self) +{ + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); + g_return_if_fail (bus != NULL); + + if (self->up_main_proxy == NULL) + { + self->up_main_proxy = dbus_g_proxy_new_for_name (bus, + UP_ADDRESS, + UP_OBJECT, + UP_INTERFACE); + } + + if (self->up_prop_proxy == NULL) + { + self->up_prop_proxy = dbus_g_proxy_new_for_name(bus, + UP_ADDRESS, + UP_OBJECT, + DBUS_INTERFACE_PROPERTIES); + /* Connect to changed signal */ + dbus_g_proxy_add_signal(self->up_main_proxy, "Changed", G_TYPE_INVALID); + dbus_g_proxy_connect_signal(self->up_main_proxy, "Changed", G_CALLBACK(up_changed_cb), self, NULL); + } + + /* Force an original "changed" event */ + up_changed_cb(self->up_main_proxy, self); + + /* Check to see if these are getting blocked by PolicyKit */ + org_freedesktop_UPower_suspend_allowed_async(self->up_main_proxy, allowed_suspend_cb, self); + org_freedesktop_UPower_hibernate_allowed_async(self->up_main_proxy, allowed_hibernate_cb, self); } /* This is the function to show a dialog on actions that @@ -340,23 +328,24 @@ setup_up (DeviceMenuMgr* self) { static void show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) { - #ifdef HAVE_GTKLOGOUTHELPER - gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); + gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); #else - gchar * helper = g_build_filename("gnome-session-quit", NULL); + gchar * helper = g_build_filename("gnome-session-quit", NULL); #endif /* HAVE_GTKLOGOUTHELPER */ - gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); - g_free(helper); + gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); - g_debug("Showing dialog '%s'", dialog_line); + g_debug ("Showing dialog '%s'", dialog_line); + + GError * error = NULL; + if (!g_spawn_command_line_async(dialog_line, &error)) + { + g_warning ("Unable to show dialog: %s", error->message); + g_clear_error (&error); + } - GError * error = NULL; - if (!g_spawn_command_line_async(dialog_line, &error)) { - g_warning("Unable to show dialog: %s", error->message); - g_error_free(error); - } - g_free(dialog_line); + g_free (dialog_line); + g_free (helper); } static void @@ -368,163 +357,116 @@ show_system_settings (DbusmenuMenuitem * mi G_GNUC_UNUSED, GError * error = NULL; if (!g_spawn_command_line_async (cmd, &error)) - { - g_warning("Unable to show dialog: %s", error->message); - g_error_free(error); - } -} - -static void -device_menu_mgr_build_settings_items (DeviceMenuMgr* self) -{ - DbusmenuMenuitem * mi; - - /* system settings... */ - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("System Settingsā¦")); - dbusmenu_menuitem_child_add_position(self->root_item, mi, 0); - g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(show_system_settings), NULL); - - /* separator */ - mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_add_position (self->root_item, mi, 1); -} - -static void -device_menu_mgr_build_devices_items (DeviceMenuMgr* self) -{ - 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, - 5); - - 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, 6); + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } } static void device_menu_mgr_build_static_items (DeviceMenuMgr* self, gboolean greeter_mode) { + DbusmenuMenuitem * mi; DbusmenuMenuitem * logout_mi = NULL; DbusmenuMenuitem * shutdown_mi = NULL; // Static Setting items - if (!greeter_mode) { - device_menu_mgr_build_settings_items (self); - } + if (!greeter_mode) + { + /* system settings... */ + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("System Settingsā¦")); + dbusmenu_menuitem_child_add_position(self->root_item, mi, 0); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings), NULL); + + /* separator */ + mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position (self->root_item, mi, 1); + } // Devices control - if (!greeter_mode) { - device_menu_mgr_build_devices_items (self); - } + if (!greeter_mode) + { + /* attached devices... */ + mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Attached Devices")); + dbusmenu_menuitem_property_set_bool (mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_child_add_position (self->root_item, mi, 5); + + /* separator */ + mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position (self->root_item, mi, 6); + } // Session control - if (!greeter_mode) { - gboolean can_lockscreen; - - /* Make sure we have a valid GConf client, and build one - if needed */ - can_lockscreen = !g_settings_get_boolean (self->lockdown_settings, - LOCKDOWN_KEY_SCREENSAVER); - /* Lock screen item */ - if (can_lockscreen) { - self->lock_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (self->lock_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Lock Screen")); - - update_screensaver_shortcut (self->lock_mi, self->keybinding_settings); - - g_signal_connect (G_OBJECT(self->lock_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(lock_screen), NULL); - dbusmenu_menuitem_child_append(self->root_item, self->lock_mi); + if (!greeter_mode) + { + const gboolean can_lockscreen = !g_settings_get_boolean (self->lockdown_settings, LOCKDOWN_KEY_SCREENSAVER); + + /* lock screen */ + if (can_lockscreen) + { + self->lock_mi = mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); + update_screensaver_shortcut (mi, self->keybinding_settings); + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), NULL); + } + + /* logout */ + logout_mi = mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, + supress_confirmations() ? _("Log Out") + : _("Log Out\342\200\246")); + dbusmenu_menuitem_property_set_bool (mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_logout()); + dbusmenu_menuitem_child_append(self->root_item, mi); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "logout"); } - logout_mi = dbusmenu_menuitem_new(); - - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out")); + /* suspend */ + if (self->can_suspend && self->allow_suspend) + { + self->suspend_mi = mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Suspend")); + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_suspend), self); } - else { - dbusmenu_menuitem_property_set (logout_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Log Out\342\200\246")); + + /* hibernate */ + if (self->can_hibernate && self->allow_hibernate) + { + self->hibernate_mi = mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate")); + dbusmenu_menuitem_child_append(self->root_item, mi); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_hibernate), self); } - 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 (self->can_suspend && self->allow_suspend) { - self->suspend_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (self->suspend_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Suspend")); - dbusmenu_menuitem_child_append (self->root_item, self->suspend_mi); - g_signal_connect( G_OBJECT(self->suspend_mi), - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK(machine_sleep_from_suspend), - self); - } - - if (self->can_hibernate && self->allow_hibernate) { - self->hibernate_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (self->hibernate_mi, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Hibernate")); - dbusmenu_menuitem_child_append(self->root_item, self->hibernate_mi); - g_signal_connect (G_OBJECT(self->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, + + /* shut down */ + shutdown_mi = mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, + supress_confirmations() ? _("Shut Down") + : _("Shut Down\342\200\246")); + dbusmenu_menuitem_property_set_bool (mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_shutdown()); + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, #ifdef HAVE_GTKLOGOUTHELPER G_CALLBACK(show_dialog), "shutdown"); #else G_CALLBACK(show_dialog), "power-off"); #endif /* HAVE_GTKLOGOUTHELPER */ - 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; + 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); + update_menu_entries(restart_shutdown_logout_mi); } static void |