Commit 4ed46751 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels
Browse files

add hibernate, suspend, hybrid sleep and restart to user menu

parent f8792337
......@@ -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 },
};
......@@ -199,6 +204,81 @@ panel_action_logout (GtkWidget *widget)
PANEL_SESSION_MANAGER_LOGOUT_MODE_NORMAL);
}
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)
{
......@@ -372,6 +452,42 @@ static PanelAction actions [] = {
"ACTION:connect-server:NEW",
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,
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment