Added preliminary way to suspend the device/computer
This commit is contained in:
parent
c2b12f4d8d
commit
312e929ddd
|
@ -41,7 +41,7 @@ typedef struct _PanelAppletHelper
|
||||||
void (*position_menu)(GtkMenu * menu, gint * x, gint * y,
|
void (*position_menu)(GtkMenu * menu, gint * x, gint * y,
|
||||||
gboolean * push_in, gpointer data);
|
gboolean * push_in, gpointer data);
|
||||||
void (*preferences_dialog)(Panel * panel);
|
void (*preferences_dialog)(Panel * panel);
|
||||||
int (*shutdown_dialog)(void);
|
int (*shutdown_dialog)(Panel * panel);
|
||||||
} PanelAppletHelper;
|
} PanelAppletHelper;
|
||||||
|
|
||||||
typedef enum _PanelAppletPosition
|
typedef enum _PanelAppletPosition
|
||||||
|
|
36
po/fr.po
36
po/fr.po
|
@ -7,7 +7,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Panel 0.0.5\n"
|
"Project-Id-Version: Panel 0.0.5\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2011-02-05 09:31+0100\n"
|
"POT-Creation-Date: 2011-02-05 12:22+0100\n"
|
||||||
"PO-Revision-Date: 2010-04-22 12:45+0200\n"
|
"PO-Revision-Date: 2010-04-22 12:45+0200\n"
|
||||||
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
|
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
|
||||||
"Language-Team: French\n"
|
"Language-Team: French\n"
|
||||||
|
@ -20,7 +20,7 @@ msgstr ""
|
||||||
msgid "Unknown"
|
msgid "Unknown"
|
||||||
msgstr "Inconnu"
|
msgstr "Inconnu"
|
||||||
|
|
||||||
#: ../src/applets/battery.c:186 ../src/panel.c:375 ../src/panel.c:379
|
#: ../src/applets/battery.c:186 ../src/panel.c:380 ../src/panel.c:384
|
||||||
#: ../src/run.c:200 ../src/run.c:206
|
#: ../src/run.c:200 ../src/run.c:206
|
||||||
msgid "Error"
|
msgid "Error"
|
||||||
msgstr "Erreur"
|
msgstr "Erreur"
|
||||||
|
@ -83,8 +83,8 @@ msgstr "Verrouiller l'écran"
|
||||||
msgid "Logging out is disabled"
|
msgid "Logging out is disabled"
|
||||||
msgstr "Se déconnecter est désactivé"
|
msgstr "Se déconnecter est désactivé"
|
||||||
|
|
||||||
#: ../src/applets/logout.c:70 ../src/panel.c:669 ../src/panel.c:676
|
#: ../src/applets/logout.c:70 ../src/panel.c:674 ../src/panel.c:681
|
||||||
#: ../src/panel.c:684
|
#: ../src/panel.c:689
|
||||||
msgid "Logout"
|
msgid "Logout"
|
||||||
msgstr "Déconnexion"
|
msgstr "Déconnexion"
|
||||||
|
|
||||||
|
@ -168,35 +168,35 @@ msgid ""
|
||||||
" -x\tUse icons the size of menus\n"
|
" -x\tUse icons the size of menus\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../src/panel.c:88
|
#: ../src/panel.c:93
|
||||||
msgid "large"
|
msgid "large"
|
||||||
msgstr "grande"
|
msgstr "grande"
|
||||||
|
|
||||||
#: ../src/panel.c:89
|
#: ../src/panel.c:94
|
||||||
msgid "small"
|
msgid "small"
|
||||||
msgstr "petite"
|
msgstr "petite"
|
||||||
|
|
||||||
#: ../src/panel.c:90
|
#: ../src/panel.c:95
|
||||||
msgid "smaller"
|
msgid "smaller"
|
||||||
msgstr "très petite"
|
msgstr "très petite"
|
||||||
|
|
||||||
#: ../src/panel.c:458
|
#: ../src/panel.c:463
|
||||||
msgid "Panel preferences"
|
msgid "Panel preferences"
|
||||||
msgstr "Préférences du Panel"
|
msgstr "Préférences du Panel"
|
||||||
|
|
||||||
#: ../src/panel.c:473
|
#: ../src/panel.c:478
|
||||||
msgid "Top size:"
|
msgid "Top size:"
|
||||||
msgstr "Taille du haut :"
|
msgstr "Taille du haut :"
|
||||||
|
|
||||||
#: ../src/panel.c:484
|
#: ../src/panel.c:489
|
||||||
msgid "Bottom size:"
|
msgid "Bottom size:"
|
||||||
msgstr "Taille du bas :"
|
msgstr "Taille du bas :"
|
||||||
|
|
||||||
#: ../src/panel.c:495
|
#: ../src/panel.c:500
|
||||||
msgid "General"
|
msgid "General"
|
||||||
msgstr "Générales"
|
msgstr "Générales"
|
||||||
|
|
||||||
#: ../src/panel.c:659
|
#: ../src/panel.c:664
|
||||||
msgid ""
|
msgid ""
|
||||||
"This will log you out of the current session, therefore closing any "
|
"This will log you out of the current session, therefore closing any "
|
||||||
"application currently opened and losing any unsaved data.\n"
|
"application currently opened and losing any unsaved data.\n"
|
||||||
|
@ -207,7 +207,7 @@ msgstr ""
|
||||||
"sauvegardées.\n"
|
"sauvegardées.\n"
|
||||||
"Voulez-vous continuer?"
|
"Voulez-vous continuer?"
|
||||||
|
|
||||||
#: ../src/panel.c:753
|
#: ../src/panel.c:760
|
||||||
msgid ""
|
msgid ""
|
||||||
"This will shutdown your device, therefore closing any application currently "
|
"This will shutdown your device, therefore closing any application currently "
|
||||||
"opened and losing any unsaved data.\n"
|
"opened and losing any unsaved data.\n"
|
||||||
|
@ -218,7 +218,7 @@ msgstr ""
|
||||||
"sauvegardées.\n"
|
"sauvegardées.\n"
|
||||||
"Voulez-vous continuer?"
|
"Voulez-vous continuer?"
|
||||||
|
|
||||||
#: ../src/panel.c:758
|
#: ../src/panel.c:765
|
||||||
msgid ""
|
msgid ""
|
||||||
"This will shutdown your computer, therefore closing any application "
|
"This will shutdown your computer, therefore closing any application "
|
||||||
"currently opened and losing any unsaved data.\n"
|
"currently opened and losing any unsaved data.\n"
|
||||||
|
@ -229,14 +229,18 @@ msgstr ""
|
||||||
"sauvegardées.\n"
|
"sauvegardées.\n"
|
||||||
"Voulez-vous continuer?"
|
"Voulez-vous continuer?"
|
||||||
|
|
||||||
#: ../src/panel.c:775 ../src/panel.c:780 ../src/panel.c:787
|
#: ../src/panel.c:790 ../src/panel.c:805 ../src/panel.c:812
|
||||||
msgid "Shutdown"
|
msgid "Shutdown"
|
||||||
msgstr "Arrêter"
|
msgstr "Arrêter"
|
||||||
|
|
||||||
#: ../src/panel.c:779
|
#: ../src/panel.c:797
|
||||||
msgid "Restart"
|
msgid "Restart"
|
||||||
msgstr "Redémarrer"
|
msgstr "Redémarrer"
|
||||||
|
|
||||||
|
#: ../src/panel.c:801
|
||||||
|
msgid "Suspend"
|
||||||
|
msgstr "Suspendre"
|
||||||
|
|
||||||
#: ../src/run.c:101 ../src/run.c:113
|
#: ../src/run.c:101 ../src/run.c:113
|
||||||
msgid "Run program..."
|
msgid "Run program..."
|
||||||
msgstr "Exécuter..."
|
msgstr "Exécuter..."
|
||||||
|
|
|
@ -469,7 +469,7 @@ static void _on_shutdown(gpointer data)
|
||||||
{
|
{
|
||||||
Main * main = data;
|
Main * main = data;
|
||||||
|
|
||||||
main->helper->shutdown_dialog();
|
main->helper->shutdown_dialog(main->helper->panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
71
src/panel.c
71
src/panel.c
|
@ -19,6 +19,11 @@ static char const _license[] =
|
||||||
|
|
||||||
#include <System.h>
|
#include <System.h>
|
||||||
#include <Desktop.h>
|
#include <Desktop.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
# include <sys/param.h>
|
||||||
|
# include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -109,7 +114,7 @@ static void _panel_helper_position_menu_bottom(GtkMenu * menu, gint * x,
|
||||||
static void _panel_helper_position_menu_top(GtkMenu * menu, gint * x, gint * y,
|
static void _panel_helper_position_menu_top(GtkMenu * menu, gint * x, gint * y,
|
||||||
gboolean * push_in, gpointer data);
|
gboolean * push_in, gpointer data);
|
||||||
static void _panel_helper_preferences_dialog(Panel * panel);
|
static void _panel_helper_preferences_dialog(Panel * panel);
|
||||||
static int _panel_helper_shutdown_dialog(void);
|
static int _panel_helper_shutdown_dialog(Panel * panel);
|
||||||
|
|
||||||
static char * _config_get_filename(void);
|
static char * _config_get_filename(void);
|
||||||
|
|
||||||
|
@ -745,7 +750,9 @@ static void _panel_helper_preferences_dialog(Panel * panel)
|
||||||
|
|
||||||
|
|
||||||
/* panel_helper_shutdown_dialog */
|
/* panel_helper_shutdown_dialog */
|
||||||
static int _panel_helper_shutdown_dialog(void)
|
static int _helper_shutdown_dialog_can_suspend(void);
|
||||||
|
|
||||||
|
static int _panel_helper_shutdown_dialog(Panel * panel)
|
||||||
{
|
{
|
||||||
GtkWidget * dialog;
|
GtkWidget * dialog;
|
||||||
GtkWidget * widget;
|
GtkWidget * widget;
|
||||||
|
@ -760,7 +767,7 @@ static int _panel_helper_shutdown_dialog(void)
|
||||||
" and losing any unsaved data.\n"
|
" and losing any unsaved data.\n"
|
||||||
"Do you really want to proceed?");
|
"Do you really want to proceed?");
|
||||||
#endif
|
#endif
|
||||||
enum { RES_CANCEL, RES_REBOOT, RES_SHUTDOWN };
|
enum { RES_CANCEL, RES_REBOOT, RES_SHUTDOWN, RES_SUSPEND };
|
||||||
int res;
|
int res;
|
||||||
char * reboot[] = { "/sbin/shutdown", "shutdown", "-r", "now", NULL };
|
char * reboot[] = { "/sbin/shutdown", "shutdown", "-r", "now", NULL };
|
||||||
char * shutdown[] = { "/sbin/shutdown", "shutdown",
|
char * shutdown[] = { "/sbin/shutdown", "shutdown",
|
||||||
|
@ -770,13 +777,31 @@ static int _panel_helper_shutdown_dialog(void)
|
||||||
"-h",
|
"-h",
|
||||||
#endif
|
#endif
|
||||||
"now", NULL };
|
"now", NULL };
|
||||||
|
char * suspend[] = { "/sbin/apm", "apm", "-s", NULL };
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
int sleep_state = 3;
|
||||||
|
#endif
|
||||||
|
char ** argv;
|
||||||
|
GError * error = NULL;
|
||||||
|
|
||||||
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO,
|
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO,
|
||||||
GTK_BUTTONS_NONE, "%s", _("Shutdown"));
|
GTK_BUTTONS_NONE, "%s",
|
||||||
|
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||||
|
_("Shutdown"));
|
||||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
|
||||||
"%s", message);
|
"%s",
|
||||||
|
#endif
|
||||||
|
message);
|
||||||
|
/* reboot */
|
||||||
gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, RES_CANCEL,
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, RES_CANCEL,
|
||||||
_("Restart"), RES_REBOOT, NULL);
|
_("Restart"), RES_REBOOT, NULL);
|
||||||
|
/* suspend */
|
||||||
|
if(_helper_shutdown_dialog_can_suspend())
|
||||||
|
{
|
||||||
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Suspend"),
|
||||||
|
RES_SUSPEND, NULL);
|
||||||
|
}
|
||||||
|
/* shutdown */
|
||||||
widget = gtk_button_new_with_label(_("Shutdown"));
|
widget = gtk_button_new_with_label(_("Shutdown"));
|
||||||
gtk_button_set_image(GTK_BUTTON(widget), gtk_image_new_from_icon_name(
|
gtk_button_set_image(GTK_BUTTON(widget), gtk_image_new_from_icon_name(
|
||||||
"gnome-shutdown", GTK_ICON_SIZE_BUTTON));
|
"gnome-shutdown", GTK_ICON_SIZE_BUTTON));
|
||||||
|
@ -788,12 +813,40 @@ static int _panel_helper_shutdown_dialog(void)
|
||||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
if(res == RES_SHUTDOWN)
|
if(res == RES_SHUTDOWN)
|
||||||
g_spawn_async(NULL, shutdown, NULL, G_SPAWN_FILE_AND_ARGV_ZERO,
|
argv = shutdown;
|
||||||
NULL, NULL, NULL, NULL);
|
else if(res == RES_SUSPEND)
|
||||||
|
argv = suspend;
|
||||||
else if(res == RES_REBOOT)
|
else if(res == RES_REBOOT)
|
||||||
g_spawn_async(NULL, reboot, NULL, G_SPAWN_FILE_AND_ARGV_ZERO,
|
argv = reboot;
|
||||||
NULL, NULL, NULL, NULL);
|
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
if(res == RES_SUSPEND && sysctlbyname("machdep.sleep_state", NULL, NULL,
|
||||||
|
&sleep_state, sizeof(sleep_state)) != 0)
|
||||||
|
return panel_error(panel, "sysctl", 1);
|
||||||
|
#endif
|
||||||
|
if(g_spawn_async(NULL, argv, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL,
|
||||||
|
NULL, NULL, &error) != TRUE)
|
||||||
|
return panel_error(panel, error->message, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _helper_shutdown_dialog_can_suspend(void)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
int sleep_state = -1;
|
||||||
|
size_t size = sizeof(sleep_state);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(lstat("/proc/apm", &st) == 0)
|
||||||
|
return 1;
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
if(sysctlbyname("machdep.sleep_state", &sleep_state, &size, NULL, 0)
|
||||||
|
== 0 && sleep_state == 0
|
||||||
|
&& sysctlbyname("machdep.sleep_state", &sleep_state,
|
||||||
|
&size, &sleep_state, size) == 0)
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user