After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 624280 - Incompatible with GOptionContext
Incompatible with GOptionContext
Status: RESOLVED DUPLICATE of bug 634990
Product: glib
Classification: Platform
Component: gapplication
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-07-13 20:34 UTC by Jonh Wendell
Modified: 2011-12-17 05:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use case (2.16 KB, text/x-csrc)
2010-07-13 20:34 UTC, Jonh Wendell
  Details
Proposed patch (3.27 KB, patch)
2010-07-14 18:24 UTC, Jonh Wendell
none Details | Review
Use case #2 (3.00 KB, text/x-csrc)
2010-07-14 18:26 UTC, Jonh Wendell
  Details

Description Jonh Wendell 2010-07-13 20:34:41 UTC
Created attachment 165830 [details]
Use case

It seems to be impossible to mix GOptionContext and GtkApplication in an application, because both modify argc and argv.

I've attached a typical use case, where the cmd line args are processed by GOptionContext - it needs to be the first, to catch thinks like --help, etc - and then I create a GtkApplication. In the second instance, nothing is passed to the first one, because argv was modified by GOptionContext.
Comment 1 Jonh Wendell 2010-07-14 12:44:25 UTC
If gtk_application_new doesn't exit if it's the second instance, we could work around this problem easily.

app = gtk_application_try_new (...);
if (g_application_is_remote (app))
  send_actions ()...
else
  register_actions()...
  continue_everything()...
Comment 2 Jonh Wendell 2010-07-14 18:24:25 UTC
Created attachment 165899 [details] [review]
Proposed patch

With this new function, gtk_application_new_without_quit(), users have an alternative approach for automatic activation in GtkApplication.

It will allow users to manually invoke actions on the remote instance and exit.

I'm not good at names, I agree the suffix "_without_quit" is weird. Also, I've tried by best at writing the documentation. Suggestions are welcome!
Comment 3 Jonh Wendell 2010-07-14 18:26:31 UTC
Created attachment 165900 [details]
Use case #2 

This is a bit modified version of my use case. It's using the new API and works fine.

Now, I'm able to use GOptionContext and GtkApplication at the same app.
Comment 4 Emmanuele Bassi (:ebassi) 2010-07-15 12:04:40 UTC
the way to create a remote application proxy should be:

  GtkApplication *gtk_application_try_new_remote (...)

also, the various GVariant usage should be reduced to a convenience function, like:

  GVariant *variant_from_argv (const int argc, const char *argv[])
  gboolean  variant_to_argv   (GVariant *variant, int *argc, char ***argv);

where this convenience function should live, I honestly don't know. maybe with GVariant itself - might be worth to ask Ryan.
Comment 5 Jonh Wendell 2010-07-16 15:11:30 UTC
FWIW, I'm doing this in vinagre:

...
  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_is_remote (G_APPLICATION (app)))
    {
      vinagre_options_invoke_remote_instance (app, &optionstate);
      return 0;
    }
...

Once a new constructor land in gtk, I'll use it.
Comment 6 Matthias Clasen 2010-10-30 02:10:41 UTC
These things have all changed considerably in the GtkApplication rewrite.
I'm tempted to close this as obsolete, but I'll move it to GApplication instead, since Ryan was considering adding some kind of easy option context suppport there.
Comment 7 Murray Cumming 2011-03-04 09:07:20 UTC
In bug #643650, Matthias mentioned that "there is currently no good way to do 'split handling' with GOption. Either --help only works for local options, or it only gives you docs for the remote options...", so that's maybe something that this could fix.
Comment 8 Matthias Clasen 2011-12-17 05:07:10 UTC

*** This bug has been marked as a duplicate of bug 634990 ***