GApplication: reduce GVariant abuse

Don't use GVariant* as the representation for the argument array.
This commit is contained in:
Ryan Lortie 2010-10-19 19:38:00 +02:00
parent a327bc51fc
commit e33deea16c
6 changed files with 40 additions and 67 deletions

View File

@ -2692,7 +2692,6 @@ g_application_activate
g_application_open
<SUBSECTION>
g_application_run
g_application_run_with_arguments
<SUBSECTION Standard>
G_TYPE_APPLICATION
G_APPLICATION

View File

@ -157,9 +157,9 @@ g_application_real_command_line (GApplication *application,
}
static gboolean
g_application_real_local_command_line (GApplication *application,
GVariant **arguments,
int *exit_status)
g_application_real_local_command_line (GApplication *application,
gchar ***arguments,
int *exit_status)
{
if (application->priv->flags & G_APPLICATION_HANDLES_COMMAND_LINE)
return FALSE;
@ -177,7 +177,7 @@ g_application_real_local_command_line (GApplication *application,
return TRUE;
}
n_args = g_variant_n_children (*arguments);
n_args = g_strv_length (*arguments);
if (application->priv->flags & G_APPLICATION_IS_SERVICE)
{
@ -213,12 +213,7 @@ g_application_real_local_command_line (GApplication *application,
files = g_new (GFile *, n_files);
for (i = 0; i < n_files; i++)
{
const gchar *arg;
g_variant_get_child (*arguments, i + 1, "^&ay", &arg);
files[i] = g_file_new_for_commandline_arg (arg);
}
files[i] = g_file_new_for_commandline_arg ((*arguments)[i + 1]);
g_application_open (application, files, n_files, "");
@ -1014,41 +1009,23 @@ g_application_run (GApplication *application,
int argc,
char **argv)
{
gchar **arguments;
int status;
gint i;
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
g_return_val_if_fail (argc == 0 || argv != NULL, 1);
return g_application_run_with_arguments (application,
g_variant_new_bytestring_array ((const gchar **) argv, argc));
}
arguments = g_new (gchar *, argc + 1);
for (i = 0; i < argc; i++)
arguments[i] = g_strdup (argv[i]);
arguments[i] = NULL;
/**
* g_application_run_with_arguments:
* @application: a #GApplication
* @arguments: a bytestring array #GVariant
* @returns: the exit status
*
* This is a bindings-friendly version of g_application_run().
*
* This function will consume @arguments if it is floating.
**/
int
g_application_run_with_arguments (GApplication *application,
GVariant *arguments)
{
int status;
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
g_variant_ref_sink (arguments);
if (g_get_prgname () == NULL && g_variant_n_children (arguments))
if (g_get_prgname () == NULL && argc > 0)
{
const gchar *argv0;
gchar *prgname;
g_variant_get_child (arguments, 0, "^&ay", &argv0);
prgname = g_path_get_basename (argv0);
prgname = g_path_get_basename (argv[0]);
g_set_prgname (prgname);
g_free (prgname);
}
@ -1086,7 +1063,7 @@ g_application_run_with_arguments (GApplication *application,
}
}
g_variant_unref (arguments);
g_strfreev (arguments);
if (application->priv->flags & G_APPLICATION_IS_SERVICE &&
!application->priv->use_count &&

View File

@ -84,31 +84,31 @@ struct _GApplicationClass
/*< public >*/
/* signals */
void (* startup) (GApplication *application);
void (* startup) (GApplication *application);
void (* activate) (GApplication *application);
void (* activate) (GApplication *application);
void (* open) (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint);
void (* open) (GApplication *application,
GFile **files,
gint n_files,
const gchar *hint);
int (* command_line) (GApplication *application,
GApplicationCommandLine *command_line);
int (* command_line) (GApplication *application,
GApplicationCommandLine *command_line);
/* vfuncs */
gboolean (* local_command_line) (GApplication *application,
GVariant **arguments,
int *exit_status);
gboolean (* local_command_line) (GApplication *application,
gchar ***arguments,
int *exit_status);
void (* before_emit) (GApplication *application,
GVariant *platform_data);
void (* after_emit) (GApplication *application,
GVariant *platform_data);
void (* add_platform_data) (GApplication *application,
GVariantBuilder *builder);
void (* quit_mainloop) (GApplication *application);
void (* run_mainloop) (GApplication *application);
void (* before_emit) (GApplication *application,
GVariant *platform_data);
void (* after_emit) (GApplication *application,
GVariant *platform_data);
void (* add_platform_data) (GApplication *application,
GVariantBuilder *builder);
void (* quit_mainloop) (GApplication *application);
void (* run_mainloop) (GApplication *application);
/*< private >*/
gpointer padding[12];

View File

@ -452,9 +452,9 @@ g_application_impl_cmdline_done (GObject *source,
}
int
g_application_impl_command_line (GApplicationImpl *impl,
GVariant *arguments,
GVariant *platform_data)
g_application_impl_command_line (GApplicationImpl *impl,
gchar **arguments,
GVariant *platform_data)
{
const static GDBusInterfaceVTable vtable = {
g_application_impl_cmdline_method_call
@ -481,7 +481,7 @@ g_application_impl_command_line (GApplicationImpl *impl,
impl->object_path,
"org.gtk.Application",
"CommandLine",
g_variant_new ("(o@aay@a{sv})", object_path,
g_variant_new ("(o^aay@a{sv})", object_path,
arguments, platform_data),
G_VARIANT_TYPE ("(i)"), 0, -1, NULL,
g_application_impl_cmdline_done, &data);

View File

@ -26,7 +26,7 @@ void g_application_impl_open (GApplic
G_GNUC_INTERNAL
int g_application_impl_command_line (GApplicationImpl *impl,
GVariant *arguments,
gchar **arguments,
GVariant *platform_data);
G_GNUC_INTERNAL

View File

@ -41,7 +41,6 @@ g_application_open
g_application_register
g_application_release
g_application_run
g_application_run_with_arguments
g_application_set_action_group
g_application_set_application_id
g_application_set_flags
@ -51,10 +50,8 @@ g_application_set_inactivity_timeout
#if IN_HEADER(__G_APPLICATION_COMMAND_LINE_H__)
#if IN_FILE(__G_APPLICATION_COMMAND_LINE_C__)
g_application_command_line_get_argc_argv
g_application_command_line_get_arguments
g_application_command_line_get_cwd
g_application_command_line_get_cwd_variant
g_application_command_line_get_exit_status
g_application_command_line_get_is_remote
g_application_command_line_get_platform_data