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.

https://bugzilla.gnome.org/show_bug.cgi?id=689037
This commit is contained in:
Ryan Lortie
2012-11-25 14:25:59 -05:00
parent 4e7161ce20
commit 3baf256a2c
6 changed files with 103 additions and 16 deletions

View File

@@ -24,6 +24,7 @@
#include "gapplicationcommandline.h"
#include "glibintl.h"
#include "gfile.h"
#include <string.h>
#include <stdio.h>
@@ -619,3 +620,34 @@ g_application_command_line_get_platform_data (GApplicationCommandLine *cmdline)
else
return NULL;
}
/**
* g_application_command_line_create_file_for_arg:
* @cmdline: a #GApplicationCommandLine
* @arg: an argument from @cmdline
*
* Creates a #GFile corresponding to a filename that was given as part
* of the invocation of @cmdline.
*
* This differs from g_file_new_for_commandline_arg() in that it
* resolves relative pathnames using the current working directory of
* the invoking process rather than the local process.
*
* Returns: (transfer full): a new #GFile
*
* Since: 2.36
**/
GFile *
g_application_command_line_create_file_for_arg (GApplicationCommandLine *cmdline,
const gchar *arg)
{
g_return_val_if_fail (arg != NULL, NULL);
if (cmdline->priv->cwd)
return g_file_new_for_commandline_arg_and_cwd (arg, cmdline->priv->cwd);
g_warning ("Requested creation of GFile for commandline invocation that did not send cwd. "
"Using cwd of local process to resolve relative path names.");
return g_file_new_for_commandline_arg (arg);
}