* Authors: Ryan Lortie <desrt@desrt.ca>
*/
+#include "config.h"
+
#include "gapplicationcommandline.h"
+#include "glibintl.h"
+
#include <string.h>
#include <stdio.h>
/**
* SECTION:gapplicationcommandline
* @title: GApplicationCommandLine
- * @short_description: A class representing a command-line invocation of
- * this application.
+ * @short_description: A command-line invocation of an application
* @see_also: #GApplication
*
* #GApplicationCommandLine represents a command-line invocation of
- * containing application. It is created by #GApplication and emitted
- * in the <varname>command-line</varname> signal and virtual function.
+ * an application. It is created by #GApplication and emitted
+ * in the #GApplication::command-line signal and virtual function.
*
* The class contains the list of arguments that the program was invoked
* with. It is also possible to query if the commandline invocation was
* lifecycle of the originally-invoked process is tied to the lifecycle
* of this object (ie: the process exits when the last reference is
* dropped).
+ *
+ * <example id="gapplication-example-cmdline"><title>Handling commandline arguments with GApplication</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-cmdline.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
+ *
+ * <example id="gapplication-example-cmdline2"><title>Complicated commandline handling</title>
+ * <programlisting>
+ * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-cmdline2.c">
+ * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
+ * </xi:include>
+ * </programlisting>
+ * </example>
**/
enum
GVariant *platform_data;
GVariant *arguments;
GVariant *cwd;
+
+ const gchar **environ;
gint exit_status;
};
if (!cmdline->priv->cwd)
cmdline->priv->cwd = g_variant_ref (value);
}
+
+ else if (strcmp (key, "environ") == 0)
+ {
+ if (!cmdline->priv->environ)
+ cmdline->priv->environ =
+ g_variant_get_bytestring_array (value, NULL);
+ }
}
static void
}
static void
-g_application_command_line_get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
+g_application_command_line_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
class->print_literal = g_application_command_line_real_print_literal;
g_object_class_install_property (object_class, PROP_ARGUMENTS,
- g_param_spec_variant ("arguments", "commandline arguments",
- "the commandline that caused this cmdline",
+ g_param_spec_variant ("arguments",
+ P_("Commandline arguments"),
+ P_("The commandline that caused this ::command-line signal emission"),
G_VARIANT_TYPE_BYTESTRING_ARRAY, NULL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PLATFORM_DATA,
- g_param_spec_variant ("platform-data", "platform data",
- "platform-specific data for the cmdline",
+ g_param_spec_variant ("platform-data",
+ P_("Platform data"),
+ P_("Platform-specific data for the commandline"),
G_VARIANT_TYPE ("a{sv}"), NULL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_IS_REMOTE,
- g_param_spec_boolean ("is-remote", "is remote",
- "TRUE if this is a remote cmdline", FALSE,
+ g_param_spec_boolean ("is-remote",
+ P_("Is remote"),
+ P_("TRUE if this is a remote commandline"),
+ FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_type_class_add_private (class, sizeof (GApplicationCommandLinePrivate));
* Since: 2.28
**/
gchar **
-g_application_command_line_get_arguments (GApplicationCommandLine *cmdline,
- int *argc)
+g_application_command_line_get_arguments (GApplicationCommandLine *cmdline,
+ int *argc)
{
gchar **argv;
gsize len;
/**
* g_application_command_line_get_cwd:
* @cmdline: a #GApplicationCommandLine
- *
+ *
* Gets the working directory of the command line invocation. The
* string may contain non-utf8 data.
*
}
/**
+ * g_application_command_line_get_environ:
+ * @cmdline: a #GApplicationCommandLine
+ *
+ * Gets the contents of the 'environ' variable of the command line
+ * invocation, as would be returned by g_get_environ(). The strings may
+ * contain non-utf8 data.
+ *
+ * The remote application usually does not send an environment. Use
+ * %G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
+ * set it is possible that the environment is still not available (due
+ * to invocation messages from other applications).
+ *
+ * The return value should not be modified or freed and is valid for as
+ * long as @cmdline exists.
+ *
+ * Returns: the environment strings, or %NULL if they were not sent
+ *
+ * Since: 2.28
+ **/
+const gchar * const *
+g_application_command_line_get_environ (GApplicationCommandLine *cmdline)
+{
+ return cmdline->priv->environ;
+}
+
+/**
+ * g_application_command_line_getenv:
+ * @cmdline: a #GApplicationCommandLine
+ * @name: the environment variable to get
+ *
+ * Gets the value of a particular environment variable of the command
+ * line invocation, as would be returned by g_getenv(). The strings may
+ * contain non-utf8 data.
+ *
+ * The remote application usually does not send an environment. Use
+ * %G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
+ * set it is possible that the environment is still not available (due
+ * to invocation messages from other applications).
+ *
+ * The return value should not be modified or freed and is valid for as
+ * long as @cmdline exists.
+ *
+ * Returns: the value of the variable, or %NULL if unset or unsent
+ *
+ * Since: 2.28
+ **/
+const gchar *
+g_application_command_line_getenv (GApplicationCommandLine *cmdline,
+ const gchar *name)
+{
+ gint length = strlen (name);
+ gint i;
+
+ /* TODO: expand on windows */
+ if (cmdline->priv->environ)
+ for (i = 0; cmdline->priv->environ[i]; i++)
+ if (strncmp (cmdline->priv->environ[i], name, length) == 0 &&
+ cmdline->priv->environ[i][length] == '=')
+ return cmdline->priv->environ[i] + length + 1;
+
+ return NULL;
+}
+
+/**
* g_application_command_line_get_is_remote:
* @cmdline: a #GApplicationCommandLine
*
* Sets the exit status that will be used when the invoking process
* exits.
*
- * The return value of the <varname>command-line</varname> signal is
+ * The return value of the #GApplication::command-line signal is
* passed to this function when the handler returns. This is the usual
* way of setting the exit status.
*