[Xfce4-commits] <xfce4-session:master> Use gtk_init_with_args in xfce4-session-logout.
Jérôme Guelfucci
noreply at xfce.org
Mon Mar 8 00:14:01 CET 2010
Updating branch refs/heads/master
to 1f4f562ef94b695134d1cf64bc14dc22cf8f1074 (commit)
from 986dff39372c50578009d94abdd18475df63b65a (commit)
commit 1f4f562ef94b695134d1cf64bc14dc22cf8f1074
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Mon Mar 8 00:12:50 2010 +0100
Use gtk_init_with_args in xfce4-session-logout.
xfce4-session-logout/Makefile.am | 3 +-
xfce4-session-logout/main.c | 150 +++++++++++++++++++++-----------------
2 files changed, 86 insertions(+), 67 deletions(-)
diff --git a/xfce4-session-logout/Makefile.am b/xfce4-session-logout/Makefile.am
index 2e73c3d..b393ed8 100644
--- a/xfce4-session-logout/Makefile.am
+++ b/xfce4-session-logout/Makefile.am
@@ -10,7 +10,8 @@ xfce4_session_logout_SOURCES = \
xfce4_session_logout_CFLAGS = \
-I$(top_srcdir) \
$(DBUS_CFLAGS) \
- $(LIBXFCE4UI_CFLAGS)
+ $(LIBXFCE4UI_CFLAGS) \
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
xfce4_session_logout_LDFLAGS = \
$(DBUS_LIBS) \
diff --git a/xfce4-session-logout/main.c b/xfce4-session-logout/main.c
index a0765dc..6cf8c2c 100644
--- a/xfce4-session-logout/main.c
+++ b/xfce4-session-logout/main.c
@@ -39,6 +39,7 @@
#include <gtk/gtk.h>
#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4util/libxfce4util.h>
/* copied from xfce4-session/shutdown.h -- ORDER MATTERS. The numbers
@@ -54,6 +55,51 @@ typedef enum
XFSM_SHUTDOWN_HIBERNATE,
} XfsmShutdownType;
+gboolean logout = FALSE;
+gboolean halt = FALSE;
+gboolean reboot = FALSE;
+gboolean suspend = FALSE;
+gboolean hibernate = FALSE;
+gboolean fast = FALSE;
+gboolean version = FALSE;
+
+static GOptionEntry option_entries[] =
+{
+ { "logout", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &logout,
+ N_("Log out without displaying the logout dialog"),
+ NULL
+ },
+ { "halt", 'h', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &halt,
+ N_("Halt without displaying the logout dialog"),
+ NULL
+ },
+ { "reboot", 'r', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reboot,
+ N_("Reboot without displaying the logout dialog"),
+ NULL
+ },
+ { "suspend", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &suspend,
+ N_("Suspend without displaying the logout dialog"),
+ NULL
+ },
+ { "hibernate", 'h', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &hibernate,
+ N_("Hibernate without displaying the logout dialog"),
+ NULL
+ },
+ { "fast", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &fast,
+ N_("Log out quickly; don't save the session"),
+ NULL
+ },
+ { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
+ N_("Print version information and exit"),
+ NULL
+ },
+ {
+ NULL, ' ', 0, 0, NULL,
+ NULL,
+ NULL
+ }
+};
+
static void
xfce_session_logout_notify_error (const gchar *primary_message,
@@ -77,31 +123,6 @@ xfce_session_logout_notify_error (const gchar *primary_message,
}
-G_GNUC_NORETURN static void
-usage (int exit_code)
-{
- fprintf (stderr,
- "Usage: %s [OPTION...]\n"
- "\n"
- "GTK+\n"
- " --display=DISPLAY X display to use\n"
- "\n"
- "Application options\n"
- " --logout Log out without displaying the logout dialog\n"
- " --halt Halt without displaing the logout dialog\n"
- " --reboot Reboot without displaying the logout dialog\n"
- " --suspend Suspend without displaying the logout dialog\n"
- " --hibernate Hibernate without displaying the logout dialog\n"
- " --fast Log out quickly; don't save the session\n"
- "\n"
- " --help Print this help message and exit\n"
- " --version Print version information and exit\n"
- "\n",
- PACKAGE_STRING);
- exit (exit_code);
-}
-
-
int
main (int argc, char **argv)
@@ -111,49 +132,46 @@ main (int argc, char **argv)
DBusConnection *dbus_conn;
DBusMessage *message, *reply;
DBusError derror;
- gboolean have_display = gtk_init_check (&argc, &argv);
+ gboolean have_display;
+
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+ have_display = gtk_init_with_args (&argc, &argv, "", option_entries, PACKAGE, NULL);
- for (++argv; --argc > 0; ++argv)
+ if (logout)
+ {
+ shutdown_type = XFSM_SHUTDOWN_LOGOUT;
+ }
+ else if (halt)
+ {
+ shutdown_type = XFSM_SHUTDOWN_HALT;
+ }
+ else if (reboot)
+ {
+ shutdown_type = XFSM_SHUTDOWN_REBOOT;
+ }
+ else if (suspend)
+ {
+ shutdown_type = XFSM_SHUTDOWN_SUSPEND;
+ }
+ else if (hibernate)
+ {
+ shutdown_type = XFSM_SHUTDOWN_HIBERNATE;
+ }
+ else if (fast)
+ {
+ allow_save = FALSE;
+ }
+ else if (version)
{
- if (strcmp (*argv, "--logout") == 0)
- {
- shutdown_type = XFSM_SHUTDOWN_LOGOUT;
- }
- else if (strcmp (*argv, "--halt") == 0)
- {
- shutdown_type = XFSM_SHUTDOWN_HALT;
- }
- else if (strcmp (*argv, "--reboot") == 0)
- {
- shutdown_type = XFSM_SHUTDOWN_REBOOT;
- }
- else if (strcmp (*argv, "--suspend") == 0)
- {
- shutdown_type = XFSM_SHUTDOWN_SUSPEND;
- }
- else if (strcmp (*argv, "--hibernate") == 0)
- {
- shutdown_type = XFSM_SHUTDOWN_HIBERNATE;
- }
- else if (strcmp (*argv, "--fast") == 0)
- {
- allow_save = FALSE;
- }
- else if (strcmp (*argv, "--version") == 0)
- {
- printf ("%s (Xfce %s)\n\n"
- "Copyright (c) 2004\n"
- " The Xfce development team. All rights reserved.\n\n"
- "Written for Xfce by Brian Tarricone <kelnos at xfce.org> and\n"
- "Benedikt Meurer <benny at xfce.org>.\n\n"
- "Please report bugs to <%s>.\n",
- PACKAGE_STRING, xfce_version_string(), PACKAGE_BUGREPORT);
- return EXIT_SUCCESS;
- }
- else
- {
- usage (strcmp (*argv, "--help") == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
- }
+ printf ("%s (Xfce %s)\n\n"
+ "Copyright (c) 2010\n"
+ " The Xfce development team. All rights reserved.\n\n"
+ "Written for Xfce by Brian Tarricone <kelnos at xfce.org> and\n"
+ "Benedikt Meurer <benny at xfce.org>.\n\n"
+ "Please report bugs to <%s>.\n",
+ PACKAGE_STRING, xfce_version_string(), PACKAGE_BUGREPORT);
+ return EXIT_SUCCESS;
}
dbus_error_init (&derror);
More information about the Xfce4-commits
mailing list