Re: GtkApplication and argc/arv

On Wed, Mar 2, 2011 at 9:30 AM, Murray Cumming <murrayc murrayc com> wrote:
> On Thu, 2011-02-24 at 23:41 +0000, Emmanuele Bassi wrote:
>> On 2011-02-21 at 21:57, Murray Cumming wrote:
>> I'll leave the other points, as they've received a reply already.
>> > 2.
>> > How should we use GOptionContext to parse command line arguments from
>> > argc/argv when using GtkApplication. Is this the ideal way, using the
>> > command-line signal?
>> >
>> > It seems a little long-winded.
>> Totem's usage is not entirely trivial: it requires argument parsing in
>> the local (i.e. the just executed) and remote (i.e. the currently
>> running) instances.
>> simpler cases are:
>>   • you can just parse all arguments in the local instance, which means
>>     using g_option_context_parse() prior to creating the G(tk)Application
>>     instance; in this case, the command line arguments can be used to
>>     parametrize the Application instance, e.g via GObject properties,
>>     direct access to instance members, or even GApplication actions (as
>>     soon as they get more functionality).
>>   • you can defer all command line parsing to the remote instance, by
>>     passing the G_APPLICATION_HANDLES_COMMAND_LINE flag to the
>>     constructor and by connecting to the ::command-line signal; and
>>     example is in the Dictionary:
>> probably the latter case is a more direct map of what you'd have done
>> with libunique or the Bacon copy-and-paste API.

Just be aware that you should generate a new GOptionContext at each
parsing. I tried to keep one around for performance reason and soon
discovered that GOption is not really reentrant (use of global targets
variables and GOptionGroup hooks abused as init entry point by libs).
Next pass, I'd probably do the parsing in each secondary instances and
communicate to the primary using open and customs action.

>> in general, and if at all possible, I'd strongly advise to use the first
>> approach (local parsing), and keep an eye out as soon as the GAction API
>> gets more love and functionality.
> Thanks for the suggestion, but why wouldn't you use the
> GApplication::local_command_line vfunc for local command-line parsing?
> --
> murrayc murrayc com
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org

"If you open your mind too much, you brain will fall out"
Tim Minchin

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]