GNOME Bugzilla – Bug 689037
need helper for creating a GFile from a remote commandline arg
Last modified: 2012-11-27 15:10:56 UTC
something like g_application_command_line_create_file_for_arg() that calls a variant of g_file_new_for_commandline_arg() that takes the cwd from the GApplicationCommandLine instead of the process cwd. blocking the gedit port.
Created attachment 229832 [details] [review] gio: New API for GFile from remote commandline arg Add a pair of new APIs: one to GFile to create a new file from a commandline arg relative to a given cwd and one to GApplicationCommandLine to create a GFile from an arg, relative to the cwd of the invoking commandline.
Review of attachment 229832 [details] [review]: "create file" sounds a bit strange in the name... Apart from that, these API would work for me (I can also just settle for the gfile one and just get the cwd from the command line object)
Review of attachment 229832 [details] [review]: ::: gio/gapplicationcommandline.c @@ +642,3 @@ + const gchar *arg) +{ + return g_file_new_for_commandline_arg_and_cwd (arg, cmdline->priv->cwd); Dunno why, but one-line functions that just call other public API don't really turn me on. ::: gio/gfile.c @@ +6219,3 @@ + * g_file_new_for_commandline_arg_and_cwd: + * @arg: a command line string + * @cwd: (allow none): the current working directory of the commandline Why allow none here ? It would seem more natural to me to pass the current cwd in in g_file_new_for_commandline_arg, instead of passing NULL and having this extra special case in this function.
The NULL thing is an optimisation: if we want to pass the cwd in explicitly then we need to query is ahead of time and that would be wasteful in the case that the filename is absolute or a URI. I like the idea of having the API on GApplicationCommandLine on the principle of making it easy to do the right thing (and making the right thing visible). If anything I'd consider making the _and_cwd variant in GFile private... would also address your complaint about the oddity with the NULL thing.
Creating a GFile from a cmdline arg and chosen cwd is an operation not limited to cases using gapplication+gapplicationcommandline, so IMHO it would be good to keep the _and_cwd variant public.
Created attachment 230008 [details] [review] gio: New API for GFile from remote commandline arg Add a pair of new APIs: one to GFile to create a new file from a commandline arg relative to a given cwd and one to GApplicationCommandLine to create a GFile from an arg, relative to the cwd of the invoking commandline.
Attachment 230008 [details] pushed as 3baf256 - gio: New API for GFile from remote commandline arg