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 634990 - integration with GOptionContext
integration with GOptionContext
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: gapplication
2.27.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 624280 (view as bug list)
Depends on:
Blocks: 622876
 
 
Reported: 2010-11-16 15:46 UTC by Jonh Wendell
Modified: 2013-05-24 02:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
initial proposal (2.86 KB, patch)
2010-11-16 15:50 UTC, Jonh Wendell
none Details | Review
draft of a simple use case (3.14 KB, text/plain)
2010-11-16 16:52 UTC, Jonh Wendell
  Details

Description Jonh Wendell 2010-11-16 15:46:31 UTC
GApplication needs more integration with GOptionContext.

background: http://mail.gnome.org/archives/gtk-devel-list/2010-November/msg00067.html
Comment 1 Jonh Wendell 2010-11-16 15:50:45 UTC
Created attachment 174604 [details] [review]
initial proposal

this adds g_application_set_option_context() API to GApplication.

It should be used in main(), right after the creation of the GApplication object. If the app has a context, the default local_command_line handler tries to parse the arguments.

I've tried it here while migrating vinagre to the new GApplication API and it worked fine.

It still needs polishing, like documentation and perhaps a property.

Comments?
Comment 2 Allison Karlitskaya (desrt) 2010-11-16 16:03:27 UTC
+1 to the general idea

i'll try to review the patch in the next week
Comment 3 Jonh Wendell 2010-11-16 16:52:18 UTC
Created attachment 174611 [details]
draft of a simple use case
Comment 4 Allison Karlitskaya (desrt) 2010-11-17 01:24:12 UTC
your "simple use case" is a bit broken -- it should use the 'startup' and 'activate' signals to accomplish the logic of what you're trying to deal with in 'command-line'.  also: don't use HANDLE_COMMAND_LINE flag.

it is also possible that there are errors since the commandline message is just coming randomly over the bus...
Comment 5 Allison Karlitskaya (desrt) 2010-11-17 01:26:19 UTC
also: the way in which you use the option context (with the global variables) is a bit distressing.  that clearly won't map very nicely into remote activations...
Comment 6 Claudio Saavedra 2011-01-21 08:53:48 UTC
This is really necessary. We need a way to make GApplication to be easy to use together with GOptionContext.

eog's use case has a mix of requeriments. We need to handle:

1) --version (which only runs locally and then exits)
2) --new-instance, which will not connect to the remote instance and create a new one instead.
3) --help *must* run locally and show *all* the options.
4) all the other options must be passed to the remote instance.

Right now I can't find a simple way to do this without adding a lot of crap to the code.

For one, if I parse GOptionContext in main(), before running g_application_run(), then all the arguments are consumed and the only way I can pass the remote parameters is by somehow manually doing it through the bus, which is definitely not friendly to do.

Another option is to create locally a GOptionContext with the local options only (--version and --new-instance) and then remotely a GOptionContext with the other options. But the problem with that is that --help (which runs locally) will only display these and not the remote ones, unless I do it manually, which I don't want to.

I don't think this is an exceptionally strange use case, and somehow we need to support it.
Comment 7 Matthias Clasen 2011-12-17 05:07:10 UTC
*** Bug 624280 has been marked as a duplicate of this bug. ***
Comment 8 Murray Cumming 2012-02-10 09:54:55 UTC
Has there been any progress on this? It's still a rather obvious problem when people start using GtkApplication.

(In reply to comment #6)
> Another option is to create locally a GOptionContext with the local options
> only (--version and --new-instance) and then remotely a GOptionContext with the
> other options. But the problem with that is that --help (which runs locally)
> will only display these and not the remote ones, unless I do it manually, which I don't want to.

And there will be no way to provide stdout/stderr feedback about those options, such as complaining about invalid combinations of options or invalid values.

By the way, using G_APPLICATION_NON_UNIQUE seems to avoid this problem, because the GApplication::command_line signal handler then runs in the local instance. However, I am still finding out what else I lose by using that flag.
Comment 9 Matthias Clasen 2013-05-24 02:38:55 UTC
This is probably WONTFIX. See bug 699893 for current thinking about minimal cmdline support in GApplication