[totem] main: Handle the --help option locally
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] main: Handle the --help option locally
- Date: Wed, 28 Mar 2012 15:20:37 +0000 (UTC)
commit 228461c1d21389c78c1c80b16ddd70387b3e870f
Author: Bastien Nocera <hadess hadess net>
Date: Wed Mar 28 16:31:30 2012 +0200
main: Handle the --help option locally
Instead of the remote instance. Launching --help would
print the help from the server instance, and exit it, instead
of doing so in the local instance.
https://bugzilla.gnome.org/show_bug.cgi?id=669326
src/totem-object.c | 37 +++++++++++++++++++++++++++++++++++++
src/totem-options.c | 25 +++++++++++++++++++++++++
src/totem-options.h | 1 +
src/totem.c | 23 ++---------------------
4 files changed, 65 insertions(+), 21 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index bd0b923..1636736 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -57,6 +57,7 @@
#include "totem.h"
#include "totemobject-marshal.h"
#include "totem-private.h"
+#include "totem-options.h"
#include "totem-plugins-engine.h"
#include "totem-playlist.h"
#include "bacon-video-widget.h"
@@ -145,17 +146,53 @@ static int totem_table_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(TotemObject, totem_object, GTK_TYPE_APPLICATION)
+static gboolean
+totem_object_local_command_line (GApplication *application,
+ gchar ***arguments,
+ int *exit_status)
+{
+ GOptionContext *context;
+ GError *error = NULL;
+ char **argv;
+ int argc;
+
+ /* Dupe so that the remote arguments are listed, but
+ * not removed from the list */
+ argv = g_strdupv (*arguments);
+ argc = g_strv_length (argv);
+
+ context = totem_options_get_context ();
+ if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
+ g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+ error->message, argv[0]);
+ g_error_free (error);
+ *exit_status = 1;
+ goto bail;
+ }
+
+ *exit_status = 0;
+bail:
+ g_option_context_free (context);
+ g_strfreev (argv);
+
+ return FALSE;
+}
+
static void
totem_object_class_init (TotemObjectClass *klass)
{
GObjectClass *object_class;
+ GApplicationClass *app_class;
object_class = (GObjectClass *) klass;
+ app_class = (GApplicationClass *) klass;
object_class->set_property = totem_object_set_property;
object_class->get_property = totem_object_get_property;
object_class->finalize = totem_object_finalize;
+ app_class->local_command_line = totem_object_local_command_line;
+
/**
* TotemObject:fullscreen:
*
diff --git a/src/totem-options.c b/src/totem-options.c
index 43649c3..902a07b 100644
--- a/src/totem-options.c
+++ b/src/totem-options.c
@@ -70,6 +70,31 @@ const GOptionEntry all_options[] = {
{NULL} /* end the list */
};
+GOptionContext *
+totem_options_get_context (void)
+{
+ GOptionContext *context;
+ GOptionGroup *baconoptiongroup;
+
+ context = g_option_context_new (N_("- Play movies and songs"));
+ baconoptiongroup = bacon_video_widget_get_option_group ();
+ if (baconoptiongroup == NULL) {
+ g_warning ("Clutter or GTK+ failed to initialise properly");
+ g_option_context_free (context);
+ return NULL;
+ }
+ g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_group (context, baconoptiongroup);
+
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+ /* FIXME:
+ * This seems to hang on startup */
+ /* totem_session_add_options (context); */
+
+ return context;
+}
+
void
totem_options_process_late (Totem *totem, const TotemCmdLineOptions *options)
{
diff --git a/src/totem-options.h b/src/totem-options.h
index 8d59583..865ac74 100644
--- a/src/totem-options.h
+++ b/src/totem-options.h
@@ -56,6 +56,7 @@ extern const GOptionEntry all_options[];
extern TotemCmdLineOptions optionstate;
void totem_options_register_remote_commands (Totem *totem);
+GOptionContext *totem_options_get_context (void);
void totem_options_process_early (Totem *totem,
const TotemCmdLineOptions* options);
void totem_options_process_late (Totem *totem,
diff --git a/src/totem.c b/src/totem.c
index bd973fd..2de9dd8 100644
--- a/src/totem.c
+++ b/src/totem.c
@@ -188,8 +188,6 @@ app_command_line (GApplication *app,
Totem *totem)
{
GOptionContext *context;
- GOptionGroup *baconoptiongroup;
- GError *error = NULL;
int argc;
char **argv;
@@ -199,25 +197,8 @@ app_command_line (GApplication *app,
memset (&optionstate, 0, sizeof (optionstate));
/* Options parsing */
- context = g_option_context_new (N_("- Play movies and songs"));
- baconoptiongroup = bacon_video_widget_get_option_group();
- if (baconoptiongroup == NULL) {
- g_warning ("Clutter or GTK+ failed to initialise properly");
- g_option_context_free (context);
- return 1;
- }
- g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
- g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
- g_option_context_add_group (context, baconoptiongroup);
-
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
- /* Only add session options to the server process */
- if (startup_called != FALSE)
- totem_session_add_options (context);
- if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
- g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
- error->message, argv[0]);
- g_error_free (error);
+ context = totem_options_get_context ();
+ if (g_option_context_parse (context, &argc, &argv, NULL) == FALSE) {
g_option_context_free (context);
return 1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]