Signed-off-by: Eduardo Lima (Etrunko) <etrunko@xxxxxxxxxx> --- src/virt-glib-compat.c | 97 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/src/virt-glib-compat.c b/src/virt-glib-compat.c index a61a3a6..0118e45 100644 --- a/src/virt-glib-compat.c +++ b/src/virt-glib-compat.c @@ -34,6 +34,33 @@ GByteArray *g_byte_array_new_take (guint8 *data, gsize len) #endif #ifndef GLIB_VERSION_2_40 +#include <glib.h> +#include <glib/gi18n.h> + +typedef struct _GApplicationOptionsPrivate GApplicationOptionsPrivate; +struct _GApplicationOptionsPrivate +{ + GApplicationFlags flags; + GOptionGroup *main_options; + GSList *option_groups; + GHashTable *packed_options; + gboolean options_parsed; +}; + +static GApplicationOptionsPrivate * +get_options_private(GApplication *application) +{ + GApplicationOptionsPrivate *priv = g_object_get_data(G_OBJECT(application), "options_private"); + + if (priv == NULL) { + priv = g_new0(GApplicationOptionsPrivate, 1); + priv->flags = g_application_get_flags(application); + g_object_set_data_full(G_OBJECT(application), "options_private", priv, g_free); + } + + return priv; +} + static void free_option_entry (gpointer data) { @@ -68,8 +95,9 @@ g_application_pack_option_entries (GApplication *application, { GHashTableIter iter; gpointer item; + GApplicationOptionsPrivate *priv = get_options_private(application); - g_hash_table_iter_init (&iter, application->priv->packed_options); + g_hash_table_iter_init (&iter, priv->packed_options); while (g_hash_table_iter_next (&iter, NULL, &item)) { GOptionEntry *entry = item; @@ -134,6 +162,7 @@ g_application_parse_command_line (GApplication *application, gboolean become_service = FALSE; GVariantDict *dict = NULL; GOptionContext *context; + GApplicationOptionsPrivate *priv = get_options_private(application); /* Due to the memory management of GOptionGroup we can only parse * options once. That's because once you add a group to the @@ -141,7 +170,7 @@ g_application_parse_command_line (GApplication *application, * local_command_line() should never get invoked more than once * anyway. Add a sanity check just to be sure. */ - g_return_val_if_fail (!application->priv->options_parsed, NULL); + g_return_val_if_fail (!priv->options_parsed, NULL); context = g_option_context_new (NULL); @@ -153,40 +182,40 @@ g_application_parse_command_line (GApplication *application, * We must also ignore --help in this case since some applications * will try to handle this from the remote side. See #737869. */ - if (application->priv->main_options == NULL && (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)) + if (priv->main_options == NULL && (priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)) { g_option_context_set_ignore_unknown_options (context, TRUE); g_option_context_set_help_enabled (context, FALSE); } /* Add the main option group, if it exists */ - if (application->priv->main_options) + if (priv->main_options) { /* This consumes the main_options */ - g_option_context_set_main_group (context, application->priv->main_options); - application->priv->main_options = NULL; + g_option_context_set_main_group (context, priv->main_options); + priv->main_options = NULL; } /* Add any other option groups if they exist. Adding them to the * context will consume them, so we free the list as we go... */ - while (application->priv->option_groups) + while (priv->option_groups) { - g_option_context_add_group (context, application->priv->option_groups->data); - application->priv->option_groups = g_slist_delete_link (application->priv->option_groups, - application->priv->option_groups); + g_option_context_add_group (context, priv->option_groups->data); + priv->option_groups = g_slist_delete_link (priv->option_groups, + priv->option_groups); } /* In the case that we are not explicitly marked as a service or a * launcher then we want to add the "--gapplication-service" option to * allow the process to be made into a service. */ - if ((application->priv->flags & (G_APPLICATION_IS_SERVICE | G_APPLICATION_IS_LAUNCHER)) == 0) + if ((priv->flags & (G_APPLICATION_IS_SERVICE | G_APPLICATION_IS_LAUNCHER)) == 0) { GOptionGroup *option_group; GOptionEntry entries[] = { { "gapplication-service", '\0', 0, G_OPTION_ARG_NONE, &become_service, - N_("Enter GApplication service mode (use from D-Bus service files)") }, + _("Enter GApplication service mode (use from D-Bus service files)"), NULL }, { NULL } }; @@ -200,24 +229,26 @@ g_application_parse_command_line (GApplication *application, } /* Now we parse... */ +#if 0 if (!g_option_context_parse_strv (context, arguments, error)) goto out; +#endif /* Check for --gapplication-service */ if (become_service) - application->priv->flags |= G_APPLICATION_IS_SERVICE; + priv->flags |= G_APPLICATION_IS_SERVICE; dict = g_variant_dict_new (NULL); - if (application->priv->packed_options) + if (priv->packed_options) { g_application_pack_option_entries (application, dict); - g_hash_table_unref (application->priv->packed_options); - application->priv->packed_options = NULL; + g_hash_table_unref (priv->packed_options); + priv->packed_options = NULL; } out: /* Make sure we don't run again */ - application->priv->options_parsed = TRUE; + priv->options_parsed = TRUE; g_option_context_free (context); @@ -228,6 +259,7 @@ static void add_packed_option (GApplication *application, GOptionEntry *entry) { + GApplicationOptionsPrivate *priv = get_options_private(application); switch (entry->arg) { case G_OPTION_ARG_NONE: @@ -258,10 +290,10 @@ add_packed_option (GApplication *application, g_return_if_reached (); } - if (!application->priv->packed_options) - application->priv->packed_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_option_entry); + if (!priv->packed_options) + priv->packed_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_option_entry); - g_hash_table_insert (application->priv->packed_options, + g_hash_table_insert (priv->packed_options, g_strdup (entry->long_name), g_slice_dup (GOptionEntry, entry)); } @@ -271,14 +303,15 @@ g_application_add_main_option_entries (GApplication *application, const GOptionEntry *entries) { gint i; + GApplicationOptionsPrivate *priv = get_options_private(application); g_return_if_fail (G_IS_APPLICATION (application)); g_return_if_fail (entries != NULL); - if (!application->priv->main_options) + if (!priv->main_options) { - application->priv->main_options = g_option_group_new (NULL, NULL, NULL, NULL, NULL); - g_option_group_set_translation_domain (application->priv->main_options, NULL); + priv->main_options = g_option_group_new (NULL, NULL, NULL, NULL, NULL); + g_option_group_set_translation_domain (priv->main_options, NULL); } for (i = 0; entries[i].long_name; i++) @@ -289,7 +322,7 @@ g_application_add_main_option_entries (GApplication *application, if (!my_entries[0].arg_data) add_packed_option (application, &my_entries[0]); - g_option_group_add_entries (application->priv->main_options, my_entries); + g_option_group_add_entries (priv->main_options, my_entries); } } @@ -297,10 +330,11 @@ void g_application_add_option_group (GApplication *application, GOptionGroup *group) { + GApplicationOptionsPrivate *priv = get_options_private(application); g_return_if_fail (G_IS_APPLICATION (application)); g_return_if_fail (group != NULL); - application->priv->option_groups = g_slist_prepend (application->priv->option_groups, group); + priv->option_groups = g_slist_prepend (priv->option_groups, group); } gboolean @@ -311,6 +345,7 @@ g_application_real_local_command_line (GApplication *application, GError *error = NULL; GVariantDict *options; gint n_args; + GApplicationOptionsPrivate *priv = get_options_private(application); options = g_application_parse_command_line (application, arguments, &error); if (!options) @@ -320,7 +355,9 @@ g_application_real_local_command_line (GApplication *application, return TRUE; } +#if 0 g_signal_emit (application, g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS], 0, options, exit_status); +#endif if (*exit_status >= 0) { @@ -339,24 +376,26 @@ g_application_real_local_command_line (GApplication *application, n_args = g_strv_length (*arguments); - if (application->priv->flags & G_APPLICATION_IS_SERVICE) + if (priv->flags & G_APPLICATION_IS_SERVICE) { if ((*exit_status = n_args > 1)) { g_printerr ("GApplication service mode takes no arguments.\n"); - application->priv->flags &= ~G_APPLICATION_IS_SERVICE; + priv->flags &= ~G_APPLICATION_IS_SERVICE; *exit_status = 1; } else *exit_status = 0; } - else if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE) +#if 0 + else if (priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE) { g_application_call_command_line (application, (const gchar **) *arguments, g_variant_dict_end (options), exit_status); } +#endif else { if (n_args <= 1) @@ -367,7 +406,7 @@ g_application_real_local_command_line (GApplication *application, else { - if (~application->priv->flags & G_APPLICATION_HANDLES_OPEN) + if (~priv->flags & G_APPLICATION_HANDLES_OPEN) { g_critical ("This application can not open files."); *exit_status = 1; -- 2.5.0 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list