[gnome-panel] add hibernate, suspend, hybrid sleep and restart to user menu
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] add hibernate, suspend, hybrid sleep and restart to user menu
- Date: Tue, 28 Oct 2014 15:56:58 +0000 (UTC)
commit 4ed46751373193c10c0dd001013c396d3ced3118
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Oct 28 17:41:04 2014 +0200
add hibernate, suspend, hybrid sleep and restart to user menu
gnome-panel/panel-action-button.c | 116 +++++++++++++++++++++++++++++++++++++
gnome-panel/panel-enums.h | 4 +
gnome-panel/panel-menu-items.c | 88 ++++++++++++++++++++++++----
3 files changed, 195 insertions(+), 13 deletions(-)
---
diff --git a/gnome-panel/panel-action-button.c b/gnome-panel/panel-action-button.c
index 38d8a22..25e7cfe 100644
--- a/gnome-panel/panel-action-button.c
+++ b/gnome-panel/panel-action-button.c
@@ -34,6 +34,7 @@
#include <libpanel-util/panel-glib.h>
#include <libpanel-util/panel-launch.h>
#include <libpanel-util/panel-screensaver.h>
+#include <libpanel-util/panel-end-session-dialog.h>
#include <libpanel-util/panel-session-manager.h>
#include <libpanel-util/panel-show.h>
@@ -79,6 +80,10 @@ static PanelEnumStringPair panel_action_type_map [] = {
{ PANEL_ACTION_SEARCH, "search" },
{ PANEL_ACTION_FORCE_QUIT, "force-quit" },
{ PANEL_ACTION_CONNECT_SERVER, "connect-server" },
+ { PANEL_ACTION_HIBERNATE, "hibernate" },
+ { PANEL_ACTION_SUSPEND, "suspend" },
+ { PANEL_ACTION_HYBRID_SLEEP, "hybrid-sleep" },
+ { PANEL_ACTION_REBOOT, "reboot" },
{ PANEL_ACTION_SHUTDOWN, "shutdown" },
{ 0, NULL },
};
@@ -200,6 +205,81 @@ panel_action_logout (GtkWidget *widget)
}
static void
+panel_action_hibernate (GtkWidget *widget)
+{
+ PanelEndSessionDialog *dialog;
+
+ dialog = panel_end_session_dialog_get ();
+ panel_end_session_dialog_request_hibernate (dialog);
+}
+
+static gboolean
+panel_action_hibernate_is_disabled (void)
+{
+ PanelEndSessionDialog *dialog;
+
+ if (panel_lockdown_get_disable_log_out_s ())
+ return TRUE;
+
+ dialog = panel_end_session_dialog_get ();
+
+ return (!panel_end_session_dialog_is_hibernate_available (dialog));
+}
+
+static void
+panel_action_suspend (GtkWidget *widget)
+{
+ PanelEndSessionDialog *dialog;
+
+ dialog = panel_end_session_dialog_get ();
+ panel_end_session_dialog_request_suspend (dialog);
+}
+
+static gboolean
+panel_action_suspend_is_disabled (void)
+{
+ PanelEndSessionDialog *dialog;
+
+ if (panel_lockdown_get_disable_log_out_s ())
+ return TRUE;
+
+ dialog = panel_end_session_dialog_get ();
+
+ return (!panel_end_session_dialog_is_suspend_available (dialog));
+}
+
+static void
+panel_action_hybrid_sleep (GtkWidget *widget)
+{
+ PanelEndSessionDialog *dialog;
+
+ dialog = panel_end_session_dialog_get ();
+ panel_end_session_dialog_request_hybrid_sleep (dialog);
+}
+
+static gboolean
+panel_action_hybrid_sleep_is_disabled (void)
+{
+ PanelEndSessionDialog *dialog;
+
+ if (panel_lockdown_get_disable_log_out_s ())
+ return TRUE;
+
+ dialog = panel_end_session_dialog_get ();
+
+ return (!panel_end_session_dialog_is_hybrid_sleep_available (dialog));
+}
+
+static void
+panel_action_reboot (GtkWidget *widget)
+{
+ PanelSessionManager *manager;
+
+ manager = panel_session_manager_get ();
+ panel_session_manager_request_reboot (manager);
+}
+
+static void
panel_action_shutdown (GtkWidget *widget)
{
PanelSessionManager *manager;
@@ -373,6 +453,42 @@ static PanelAction actions [] = {
panel_action_connect_server, NULL, NULL, NULL
},
{
+ PANEL_ACTION_HIBERNATE,
+ NULL,
+ N_("Hibernate"),
+ NULL,
+ "ACTION:hibernate:NEW",
+ panel_action_hibernate, NULL, NULL,
+ panel_action_hibernate_is_disabled
+ },
+ {
+ PANEL_ACTION_SUSPEND,
+ NULL,
+ N_("Suspend"),
+ NULL,
+ "ACTION:suspend:NEW",
+ panel_action_suspend, NULL, NULL,
+ panel_action_suspend_is_disabled
+ },
+ {
+ PANEL_ACTION_HYBRID_SLEEP,
+ NULL,
+ N_("Hybrid sleep"),
+ NULL,
+ "ACTION:hybrid-sleep:NEW",
+ panel_action_hybrid_sleep, NULL, NULL,
+ panel_action_hybrid_sleep_is_disabled
+ },
+ {
+ PANEL_ACTION_REBOOT,
+ NULL,
+ N_("Restart"),
+ N_("Restart the computer"),
+ "ACTION:reboot:NEW",
+ panel_action_reboot, NULL, NULL,
+ panel_action_shutdown_reboot_is_disabled
+ },
+ {
PANEL_ACTION_SHUTDOWN,
PANEL_ICON_SHUTDOWN,
N_("Power Off"),
diff --git a/gnome-panel/panel-enums.h b/gnome-panel/panel-enums.h
index 86be2f7..3d6c0cc 100644
--- a/gnome-panel/panel-enums.h
+++ b/gnome-panel/panel-enums.h
@@ -66,6 +66,10 @@ typedef enum {
PANEL_ACTION_SEARCH,
PANEL_ACTION_FORCE_QUIT,
PANEL_ACTION_CONNECT_SERVER,
+ PANEL_ACTION_HIBERNATE,
+ PANEL_ACTION_SUSPEND,
+ PANEL_ACTION_HYBRID_SLEEP,
+ PANEL_ACTION_REBOOT,
PANEL_ACTION_SHUTDOWN,
#define PANEL_ACTION_LAST_NON_DEPRECATED PANEL_ACTION_SHUTDOWN
PANEL_ACTION_LAST
diff --git a/gnome-panel/panel-menu-items.c b/gnome-panel/panel-menu-items.c
index 74c30e1..6340a87 100644
--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -47,6 +47,7 @@
#include <libpanel-util/panel-gtk.h>
#include <libpanel-util/panel-keyfile.h>
#include <libpanel-util/panel-launch.h>
+#include <libpanel-util/panel-end-session-dialog.h>
#include <libpanel-util/panel-session-manager.h>
#include <libpanel-util/panel-show.h>
@@ -1777,6 +1778,8 @@ panel_menu_items_append_lock_logout (GtkWidget *menu)
GList *children;
GList *last;
GtkWidget *item;
+ GtkWidget *separator;
+ gboolean hide_separator;
children = gtk_container_get_children (GTK_CONTAINER (menu));
last = g_list_last (children);
@@ -1829,29 +1832,88 @@ panel_menu_items_append_lock_logout (GtkWidget *menu)
G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
}
+ /* Separator */
+ separator = add_menu_separator (menu);
+ hide_separator = TRUE;
+
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ separator, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
+ /* Hibernate */
+ if (panel_end_session_dialog_is_hibernate_available (panel_end_session_dialog_get ())) {
+ item = panel_menu_items_create_action_item_full (PANEL_ACTION_HIBERNATE,
+ NULL, NULL, TRUE);
+ if (item != NULL) {
+ hide_separator = FALSE;
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ item, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+ }
+ }
+
+ /* Suspend */
+ if (panel_end_session_dialog_is_suspend_available (panel_end_session_dialog_get ())) {
+ item = panel_menu_items_create_action_item_full (PANEL_ACTION_SUSPEND,
+ NULL, NULL, TRUE);
+ if (item != NULL) {
+ hide_separator = FALSE;
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ item, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+ }
+ }
+
+ /* Hubrid Sleep */
+ if (panel_end_session_dialog_is_hybrid_sleep_available (panel_end_session_dialog_get ())) {
+ item = panel_menu_items_create_action_item_full (PANEL_ACTION_HYBRID_SLEEP,
+ NULL, NULL, TRUE);
+ if (item != NULL) {
+ hide_separator = FALSE;
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ item, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+ }
+ }
+
/* FIXME: should be dynamic */
if (panel_session_manager_is_shutdown_available (panel_session_manager_get ())) {
+ item = panel_menu_items_create_action_item_full (PANEL_ACTION_REBOOT,
+ NULL, NULL, TRUE);
+ if (item != NULL) {
+ hide_separator = FALSE;
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ item, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+ }
+
item = panel_menu_items_create_action_item_full (PANEL_ACTION_SHUTDOWN,
NULL, NULL, TRUE);
if (item != NULL) {
- GtkWidget *sep;
-
- sep = add_menu_separator (menu);
+ hide_separator = FALSE;
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- g_object_bind_property (panel_lockdown_get (),
- "disable-log-out",
- sep,
- "visible",
- G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
- g_object_bind_property (panel_lockdown_get (),
- "disable-log-out",
- item,
- "visible",
- G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
+ g_object_bind_property (panel_lockdown_get (), "disable-log-out",
+ item, "visible",
+ G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
}
}
+
+ if (hide_separator)
+ g_object_set (separator, "visible", FALSE, NULL);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]