improve bloom filter on send
[platform/upstream/glib.git] / gio / gapplicationcommandline.c
index 258baa7..d5e508a 100644 (file)
@@ -57,7 +57,8 @@
  * The GApplicationCommandLine object can provide the @argc and @argv
  * parameters for use with the #GOptionContext command-line parsing API,
  * with the g_application_command_line_get_arguments() function. See
- * <xref linkend="gapplication-example-cmdline3"/> for an example.
+ * [gapplication-example-cmdline3.c][gapplication-example-cmdline3]
+ * for an example.
  *
  * The exit status of the originally-invoked process may be set and
  * messages can be printed to stdout or stderr of that process.  The
  * }
  * ]|
  * In this example of split commandline handling, options that start
- * with <literal>--local-</literal> are handled locally, all other
- * options are passed to the #GApplication::command-line handler
- * which runs in the primary instance.
+ * with `--local-` are handled locally, all other options are passed
+ * to the #GApplication::command-line handler which runs in the primary
+ * instance.
  *
  * The complete example can be found here:
  * [gapplication-example-cmdline2.c](https://git.gnome.org/browse/glib/tree/gio/tests/gapplication-example-cmdline2.c)
  * {
  *   GApplicationCommandLine *cmdline = data;
  *
- *   /&ast; do the heavy lifting in an idle &ast;/
+ *   // do the heavy lifting in an idle
  *
  *   g_application_command_line_set_exit_status (cmdline, 0);
- *   g_object_unref (cmdline); /&ast; this releases the application &ast;/
+ *   g_object_unref (cmdline); // this releases the application
  *
  *   return G_SOURCE_REMOVE;
  * }
  * command_line (GApplication            *application,
  *               GApplicationCommandLine *cmdline)
  * {
- *   /&ast; keep the application running until we are done with this commandline &ast;/
+ *   // keep the application running until we are done with this commandline
  *   g_application_hold (application);
  *
  *   g_object_set_data_full (G_OBJECT (cmdline),
@@ -211,6 +212,7 @@ enum
 {
   PROP_NONE,
   PROP_ARGUMENTS,
+  PROP_OPTIONS,
   PROP_PLATFORM_DATA,
   PROP_IS_REMOTE
 };
@@ -219,6 +221,8 @@ struct _GApplicationCommandLinePrivate
 {
   GVariant *platform_data;
   GVariant *arguments;
+  GVariant *options;
+  GVariantDict *options_dict;
   gchar *cwd;
 
   gchar **environ;
@@ -253,6 +257,12 @@ grok_platform_data (GApplicationCommandLine *cmdline)
           cmdline->priv->environ =
             g_variant_dup_bytestring_array (value, NULL);
       }
+
+    else if (strcmp (key, "options") == 0)
+      {
+        if (!cmdline->priv->options)
+          cmdline->priv->options = g_variant_ref (value);
+      }
 }
 
 static void
@@ -321,6 +331,11 @@ g_application_command_line_set_property (GObject      *object,
       cmdline->priv->arguments = g_value_dup_variant (value);
       break;
 
+    case PROP_OPTIONS:
+      g_assert (cmdline->priv->options == NULL);
+      cmdline->priv->options = g_value_dup_variant (value);
+      break;
+
     case PROP_PLATFORM_DATA:
       g_assert (cmdline->priv->platform_data == NULL);
       cmdline->priv->platform_data = g_value_dup_variant (value);
@@ -338,6 +353,12 @@ g_application_command_line_finalize (GObject *object)
 {
   GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
 
+  if (cmdline->priv->options_dict)
+    g_variant_dict_unref (cmdline->priv->options_dict);
+
+  if (cmdline->priv->options)
+      g_variant_unref (cmdline->priv->options);
+
   if (cmdline->priv->platform_data)
     g_variant_unref (cmdline->priv->platform_data);
   if (cmdline->priv->arguments)
@@ -394,6 +415,13 @@ g_application_command_line_class_init (GApplicationCommandLineClass *class)
                           G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
                           G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_OPTIONS,
+    g_param_spec_variant ("options",
+                          P_("Options"),
+                          P_("The options sent along with the commandline"),
+                          G_VARIANT_TYPE_VARDICT, 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",
                           P_("Platform data"),
@@ -451,6 +479,35 @@ g_application_command_line_get_arguments (GApplicationCommandLine *cmdline,
 }
 
 /**
+ * g_application_command_line_get_options_dict:
+ * @cmdline: a #GApplicationCommandLine
+ *
+ * Gets the options there were passed to g_application_command_line().
+ *
+ * If you did not override local_command_line() then these are the same
+ * options that were parsed according to the #GOptionEntrys added to the
+ * application with g_application_add_main_option_entries() and possibly
+ * modified from your GApplication::handle-local-options handler.
+ *
+ * If no options were sent then an empty dictionary is returned so that
+ * you don't need to check for %NULL.
+ *
+ * Returns: (transfer none): a #GVariantDict with the options
+ *
+ * Since: 2.40
+ **/
+GVariantDict *
+g_application_command_line_get_options_dict (GApplicationCommandLine *cmdline)
+{
+  g_return_val_if_fail (G_IS_APPLICATION_COMMAND_LINE (cmdline), NULL);
+
+  if (!cmdline->priv->options_dict)
+    cmdline->priv->options_dict = g_variant_dict_new (cmdline->priv->options);
+
+  return cmdline->priv->options_dict;
+}
+
+/**
  * g_application_command_line_get_stdin:
  * @cmdline: a #GApplicationCommandLine
  *
@@ -723,7 +780,7 @@ g_application_command_line_get_exit_status (GApplicationCommandLine *cmdline)
  *
  * For local invocation, it will be %NULL.
  *
- * Returns: (allow-none): the platform data, or %NULL
+ * Returns: (nullable): the platform data, or %NULL
  *
  * Since: 2.28
  **/