[vinagre] Adapt to the new G[tk]Application API
- From: Jonh Wendell <jwendell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vinagre] Adapt to the new G[tk]Application API
- Date: Tue, 16 Nov 2010 17:39:06 +0000 (UTC)
commit e9a2f99361d935d266df75ed2e6ed1dba0614c45
Author: Jonh Wendell <jwendell gnome org>
Date: Tue Nov 16 14:36:05 2010 -0300
Adapt to the new G[tk]Application API
vinagre/vinagre-main.c | 180 ++++++++++++++++++++++++++-------------------
vinagre/vinagre-options.c | 101 +------------------------
vinagre/vinagre-options.h | 10 +--
3 files changed, 111 insertions(+), 180 deletions(-)
---
diff --git a/vinagre/vinagre-main.c b/vinagre/vinagre-main.c
index 4760d5b..f1ca31f 100644
--- a/vinagre/vinagre-main.c
+++ b/vinagre/vinagre-main.c
@@ -47,44 +47,107 @@
#include "vinagre-mdns.h"
#endif
-int main (int argc, char **argv) {
- GOptionContext *context;
- GError *error = NULL;
- GtkWindow *window;
- GtkApplication *app;
- GHashTable *extensions;
- GHashTableIter iter;
- VinagreProtocol *extension;
+static gboolean startup_called = FALSE;
+static GtkWindow *window = NULL;
+static GOptionContext *context = NULL;
+
#ifdef HAVE_TELEPATHY
- VinagreTubesManager *vinagre_tubes_manager;
+static VinagreTubesManager *vinagre_tubes_manager = NULL;
#endif
- g_type_init();
- g_set_application_name (_("Remote Desktop Viewer"));
-
- /* Setup debugging */
+static void
+app_init (GtkApplication *app)
+{
vinagre_debug_init ();
vinagre_debug_message (DEBUG_APP, "Startup");
+ vinagre_cache_prefs_init ();
+
+ window = GTK_WINDOW (vinagre_window_new ());
+ gtk_window_set_application (window, app);
+ gtk_widget_show (GTK_WIDGET (window));
+
+ vinagre_utils_handle_debug ();
+
+#ifdef HAVE_TELEPATHY
+ vinagre_tubes_manager = vinagre_tubes_manager_new (window);
+#endif
+
+ /* fake call, just to ensure this symbol will be present at vinagre.so */
+ vinagre_ssh_connect (NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL);
+}
+
+static void
+app_startup (GApplication *app,
+ void *user_data)
+{
+ /* We don't do anything here, as we need to know the options
+ * when we set everything up.
+ * Note that this will break D-Bus activation of the application */
+ startup_called = TRUE;
+}
+
+static int
+app_command_line (GApplication *app,
+ GApplicationCommandLine *command_line,
+ void *user_data)
+{
+ GError *error = NULL;
+ int argc;
+ char **argv;
+
+ argv = g_application_command_line_get_arguments (command_line, &argc);
+
+ g_option_context_parse (context, &argc, &argv, &error);
+
+ /* Don't create another window if we're remote.
+ * We can't use g_application_get_is_remote() because it's not registered yet */
+ if (startup_called != FALSE)
+ {
+ app_init (GTK_APPLICATION (app));
+ startup_called = FALSE;
+ }
+ else
+ {
+ gtk_window_present_with_time (window, GDK_CURRENT_TIME);
+ }
+
+ vinagre_options_process_command_line (GTK_APPLICATION (app), window, &optionstate);
+
+ g_strfreev (argv);
+ return 0;
+}
+
+int main (int argc, char **argv) {
+ GtkApplication *app;
+ VinagreProtocol *extension;
+ GHashTable *extensions;
+ GHashTableIter iter;
+ int res;
+
+ g_set_prgname ("vinagre");
+ g_type_init ();
+ g_set_application_name (_("Remote Desktop Viewer"));
+ optionstate.new_window = FALSE;
+
/* i18n */
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- /* Init plugins engine */
- vinagre_debug_message (DEBUG_APP, "Init plugins");
- extensions = vinagre_plugins_engine_get_plugins_by_protocol (vinagre_plugins_engine_get_default ());
-
/* Setup command line options */
context = g_option_context_new (_("- Remote Desktop Viewer"));
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, gtk_get_option_group (TRUE));
#ifdef ENABLE_INTROSPECTION
g_option_context_add_group (context, g_irepository_get_option_group ());
#endif
+ extensions = vinagre_plugins_engine_get_plugins_by_protocol (vinagre_plugins_engine_get_default ());
+
g_hash_table_iter_init (&iter, extensions);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&extension))
{
@@ -96,70 +159,37 @@ int main (int argc, char **argv) {
g_slist_free (groups);
}
- g_option_context_parse (context, &argc, &argv, &error);
- g_option_context_free (context);
- if (error)
- {
- g_print ("%s\n%s\n",
- error->message,
- _("Run 'vinagre --help' to see a full list of available command line options"));
- g_error_free (error);
- return 1;
- }
+ app = gtk_application_new ("org.gnome.vinagre", G_APPLICATION_HANDLES_COMMAND_LINE);
+ /* https://bugzilla.gnome.org/show_bug.cgi?id=634990 */
+ g_application_set_option_context (G_APPLICATION (app), context);
+ g_signal_connect (app,
+ "command-line",
+ G_CALLBACK (app_command_line),
+ NULL);
+ g_signal_connect (app,
+ "startup",
+ G_CALLBACK (app_startup),
+ NULL);
+ res = g_application_run (G_APPLICATION (app), argc, argv);
- g_clear_error (&error);
- app = g_initable_new (GTK_TYPE_APPLICATION,
- NULL,
- &error,
- "application-id", "org.gnome.Vinagre",
- "argv", g_variant_new_bytestring_array ((const gchar * const*)argv, argc),
- "default-quit", FALSE,
- NULL);
- if (!app)
- g_error ("%s", error->message);
-
- if (g_application_get_is_remote (G_APPLICATION (app)))
+ if (res == 0)
{
- vinagre_options_invoke_remote_instance (app, &optionstate);
- return 0;
- }
+ #ifdef HAVE_TELEPATHY
+ g_object_unref (vinagre_tubes_manager);
+ #endif
- vinagre_options_register_actions (app);
- vinagre_cache_prefs_init ();
+ g_object_unref (vinagre_bookmarks_get_default ());
+ g_object_unref (vinagre_prefs_get_default ());
+ vinagre_cache_prefs_finalize ();
- window = GTK_WINDOW (vinagre_window_new ());
- gtk_application_add_window (app, window);
- gtk_widget_show (GTK_WIDGET (window));
-
- vinagre_utils_handle_debug ();
- optionstate.new_window = FALSE;
- vinagre_options_process_command_line (window, &optionstate);
-
-#ifdef HAVE_TELEPATHY
- vinagre_tubes_manager = vinagre_tubes_manager_new (window);
-#endif
-
- /* fake call, just to ensure this symbol will be present at vinagre.so */
- vinagre_ssh_connect (NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL);
-
- g_signal_connect (app,
- "action-with-data",
- G_CALLBACK (vinagre_options_handle_action),
- NULL);
- gtk_application_run (app);
+ #ifdef VINAGRE_ENABLE_AVAHI
+ g_object_unref (vinagre_mdns_get_default ());
+ #endif
+ }
-#ifdef HAVE_TELEPATHY
- g_object_unref (vinagre_tubes_manager);
-#endif
- g_object_unref (vinagre_bookmarks_get_default ());
- g_object_unref (vinagre_prefs_get_default ());
- vinagre_cache_prefs_finalize ();
g_object_unref (app);
-#ifdef VINAGRE_ENABLE_AVAHI
- g_object_unref (vinagre_mdns_get_default ());
-#endif
-
+ g_option_context_free (context);
- return 0;
+ return res;
}
/* vim: set ts=8: */
diff --git a/vinagre/vinagre-options.c b/vinagre/vinagre-options.c
index 65e47f9..139da7d 100644
--- a/vinagre/vinagre-options.c
+++ b/vinagre/vinagre-options.c
@@ -49,21 +49,15 @@ const GOptionEntry all_options [] =
VinagreCmdLineOptions optionstate;
void
-vinagre_options_register_actions (GtkApplication *app)
-{
- GApplication *g_app = G_APPLICATION (app);
- g_application_add_action (g_app, "uris", "List of machines to connect to");
-}
-
-void
-vinagre_options_process_command_line (GtkWindow *window, const VinagreCmdLineOptions *options)
+vinagre_options_process_command_line (GtkApplication *app,
+ GtkWindow *window,
+ const VinagreCmdLineOptions *options)
{
gint i;
VinagreConnection *conn;
gchar *error;
GSList *errors, *servers, *l;
VinagreWindow *v_window;
- GtkApplication *app;
errors = servers = NULL;
@@ -104,13 +98,12 @@ vinagre_options_process_command_line (GtkWindow *window, const VinagreCmdLineOpt
g_strfreev (options->uris);
}
- app = GTK_APPLICATION (g_application_get_instance ());
if (servers &&
options->new_window)
{
v_window = vinagre_window_new ();
gtk_widget_show (GTK_WIDGET (v_window));
- gtk_application_add_window (app, GTK_WINDOW (v_window));
+ gtk_window_set_application (GTK_WINDOW (v_window), app);
}
else
{
@@ -140,90 +133,4 @@ vinagre_options_process_command_line (GtkWindow *window, const VinagreCmdLineOpt
gtk_window_present (GTK_WINDOW (v_window));
}
-void
-vinagre_options_invoke_remote_instance (GtkApplication *app, const VinagreCmdLineOptions *options)
-{
- GVariantBuilder builder;
- GVariant *data;
-
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
-
- if (options->files)
- {
- g_variant_builder_add (&builder,
- "{sv}",
- "files",
- g_variant_new_bytestring_array ((const gchar * const*)options->files, -1));
- g_strfreev (options->files);
- }
-
- if (options->uris)
- {
- g_variant_builder_add (&builder,
- "{sv}",
- "args",
- g_variant_new_bytestring_array ((const gchar * const*)options->uris, -1));
- g_strfreev (options->uris);
- }
-
- g_variant_builder_add (&builder,
- "{sv}",
- "new_window",
- g_variant_new_boolean (options->new_window));
-
- g_variant_builder_add (&builder,
- "{sv}",
- "fullscreen",
- g_variant_new_boolean (options->fullscreen));
-
-
- data = g_variant_builder_end (&builder);
- g_application_invoke_action (G_APPLICATION (app), "uris", data);
- g_variant_unref (data);
-}
-
-void
-vinagre_options_handle_action (GApplication *app,
- gchar *action,
- GVariant *data,
- gpointer user_data)
-{
- GVariantIter iter;
- gchar *key;
- GVariant *value;
- const gchar **files, **uris;
-
- if (g_strcmp0 (action, "uris") != 0)
- {
- g_message ("Received an unknown action: %s", action);
- return;
- }
-
- files = uris = NULL;
- memset (&optionstate, 0, sizeof optionstate);
-
- g_variant_iter_init (&iter, data);
- while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
- {
- if (g_strcmp0 (key, "files") == 0)
- {
- optionstate.files = (gchar **) g_variant_dup_bytestring_array (value, NULL);
- }
- else if (g_strcmp0 (key, "args") == 0)
- {
- optionstate.uris = (gchar **) g_variant_dup_bytestring_array (value, NULL);
- }
- else if (g_strcmp0 (key, "new_window") == 0)
- {
- optionstate.new_window = g_variant_get_boolean (value);
- }
- else if (g_strcmp0 (key, "fullscreen") == 0)
- {
- optionstate.fullscreen = g_variant_get_boolean (value);
- }
- }
-
- vinagre_options_process_command_line (gtk_application_get_window (GTK_APPLICATION (app)),
- &optionstate);
-}
/* vim: set ts=8: */
diff --git a/vinagre/vinagre-options.h b/vinagre/vinagre-options.h
index dcc11df..dfb00f5 100644
--- a/vinagre/vinagre-options.h
+++ b/vinagre/vinagre-options.h
@@ -34,15 +34,9 @@ typedef struct {
extern const GOptionEntry all_options[];
extern VinagreCmdLineOptions optionstate;
-void vinagre_options_register_actions (GtkApplication *app);
-void vinagre_options_process_command_line (GtkWindow *window,
+void vinagre_options_process_command_line (GtkApplication *app,
+ GtkWindow *window,
const VinagreCmdLineOptions *options);
-void vinagre_options_invoke_remote_instance (GtkApplication *app,
- const VinagreCmdLineOptions *options);
-void vinagre_options_handle_action (GApplication *app,
- gchar *action,
- GVariant *data,
- gpointer user_data);
#endif /* __VINAGRE_OPTIONS_H__ */
/* vim: set ts=8: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]