Add doc comment about uris vs GFiles to g_app_info_launch()

2008-01-30  Alexander Larsson  <alexl@redhat.com>

        * gappinfo.c:
	Add doc comment about uris vs GFiles to
	g_app_info_launch()
	
        * gdesktopappinfo.c:
	Ensure uris passed to g_app_info_launch_uris()
	are not roundtriped through GFile (as that
	may be slightly destructive for e.g. mailto: links)



svn path=/trunk/; revision=6424
This commit is contained in:
Alexander Larsson 2008-01-30 11:27:02 +00:00 committed by Alexander Larsson
parent fc93e63edd
commit 692e9086b4
3 changed files with 68 additions and 51 deletions

View File

@ -1,3 +1,14 @@
2008-01-30 Alexander Larsson <alexl@redhat.com>
* gappinfo.c:
Add doc comment about uris vs GFiles to
g_app_info_launch()
* gdesktopappinfo.c:
Ensure uris passed to g_app_info_launch_uris()
are not roundtriped through GFile (as that
may be slightly destructive for e.g. mailto: links)
2008-01-30 Alexander Larsson <alexl@redhat.com> 2008-01-30 Alexander Larsson <alexl@redhat.com>
* tests/data-input-stream.c: * tests/data-input-stream.c:

View File

@ -406,6 +406,11 @@ g_app_info_get_icon (GAppInfo *appinfo)
* can fail to start if it runs into problems during startup. There is * can fail to start if it runs into problems during startup. There is
* no way to detect this. * no way to detect this.
* *
* Some URIs can be changed when passed through a GFile (for instance
* unsupported uris with strange formats like mailto:), so if you have
* a textual uri you want to pass in as argument, consider using
* g_app_info_launch_uris() instead.
*
* Returns: %TRUE on successful launch, %FALSE otherwise. * Returns: %TRUE on successful launch, %FALSE otherwise.
**/ **/
gboolean gboolean

View File

@ -169,7 +169,7 @@ g_desktop_app_info_init (GDesktopAppInfo *local)
static char * static char *
binary_from_exec (const char *exec) binary_from_exec (const char *exec)
{ {
char *p, *start; const char *p, *start;
p = exec; p = exec;
while (*p == ' ') while (*p == ' ')
@ -451,13 +451,15 @@ g_desktop_app_info_get_icon (GAppInfo *appinfo)
} }
static char * static char *
expand_macro_single (char macro, GFile *file) expand_macro_single (char macro, char *uri)
{ {
GFile *file;
char *result = NULL; char *result = NULL;
char *uri, *path; char *path;
file = g_file_new_for_uri (uri);
path = g_file_get_path (file); path = g_file_get_path (file);
uri = g_file_get_uri (file); g_object_unref (file);
switch (macro) switch (macro)
{ {
@ -483,7 +485,6 @@ expand_macro_single (char macro, GFile *file)
} }
g_free (path); g_free (path);
g_free (uri);
return result; return result;
} }
@ -492,9 +493,9 @@ static void
expand_macro (char macro, expand_macro (char macro,
GString *exec, GString *exec,
GDesktopAppInfo *info, GDesktopAppInfo *info,
GList **file_list) GList **uri_list)
{ {
GList *files = *file_list; GList *uris = *uri_list;
char *expanded; char *expanded;
g_return_if_fail (exec != NULL); g_return_if_fail (exec != NULL);
@ -505,15 +506,15 @@ expand_macro (char macro,
case 'f': case 'f':
case 'd': case 'd':
case 'n': case 'n':
if (files) if (uris)
{ {
expanded = expand_macro_single (macro, files->data); expanded = expand_macro_single (macro, uris->data);
if (expanded) if (expanded)
{ {
g_string_append (exec, expanded); g_string_append (exec, expanded);
g_free (expanded); g_free (expanded);
} }
files = files->next; uris = uris->next;
} }
break; break;
@ -522,18 +523,18 @@ expand_macro (char macro,
case 'F': case 'F':
case 'D': case 'D':
case 'N': case 'N':
while (files) while (uris)
{ {
expanded = expand_macro_single (macro, files->data); expanded = expand_macro_single (macro, uris->data);
if (expanded) if (expanded)
{ {
g_string_append (exec, expanded); g_string_append (exec, expanded);
g_free (expanded); g_free (expanded);
} }
files = files->next; uris = uris->next;
if (files != NULL && expanded) if (uris != NULL && expanded)
g_string_append_c (exec, ' '); g_string_append_c (exec, ' ');
} }
@ -565,17 +566,17 @@ expand_macro (char macro,
break; break;
} }
*file_list = files; *uri_list = uris;
} }
static gboolean static gboolean
expand_application_parameters (GDesktopAppInfo *info, expand_application_parameters (GDesktopAppInfo *info,
GList **files, GList **uris,
int *argc, int *argc,
char ***argv, char ***argv,
GError **error) GError **error)
{ {
GList *file_list = *files; GList *uri_list = *uris;
const char *p = info->exec; const char *p = info->exec;
GString *expanded_exec = g_string_new (NULL); GString *expanded_exec = g_string_new (NULL);
gboolean res; gboolean res;
@ -591,7 +592,7 @@ expand_application_parameters (GDesktopAppInfo *info,
{ {
if (p[0] == '%' && p[1] != '\0') if (p[0] == '%' && p[1] != '\0')
{ {
expand_macro (p[1], expanded_exec, info, files); expand_macro (p[1], expanded_exec, info, uris);
p++; p++;
} }
else else
@ -601,11 +602,11 @@ expand_application_parameters (GDesktopAppInfo *info,
} }
/* No file substitutions */ /* No file substitutions */
if (file_list == *files && file_list != NULL) if (uri_list == *uris && uri_list != NULL)
{ {
/* If there is no macro default to %f. This is also what KDE does */ /* If there is no macro default to %f. This is also what KDE does */
g_string_append_c (expanded_exec, ' '); g_string_append_c (expanded_exec, ' ');
expand_macro ('f', expanded_exec, info, files); expand_macro ('f', expanded_exec, info, uris);
} }
res = g_shell_parse_argv (expanded_exec->str, argc, argv, error); res = g_shell_parse_argv (expanded_exec->str, argc, argv, error);
@ -819,15 +820,17 @@ replace_env_var (char **old_environ,
} }
static GList * static GList *
dup_list_segment (GList *start, uri_list_segment_to_files (GList *start,
GList *end) GList *end)
{ {
GList *res; GList *res;
GFile *file;
res = NULL; res = NULL;
while (start != NULL && start != end) while (start != NULL && start != end)
{ {
res = g_list_prepend (res, start->data); file = g_file_new_for_uri ((char *)start->data);
res = g_list_prepend (res, file);
start = start->next; start = start->next;
} }
@ -845,14 +848,14 @@ extern char **environ;
#endif #endif
static gboolean static gboolean
g_desktop_app_info_launch (GAppInfo *appinfo, g_desktop_app_info_launch_uris (GAppInfo *appinfo,
GList *files, GList *uris,
GAppLaunchContext *launch_context, GAppLaunchContext *launch_context,
GError **error) GError **error)
{ {
GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo); GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
gboolean completed = FALSE; gboolean completed = FALSE;
GList *old_files; GList *old_uris;
GList *launched_files; GList *launched_files;
char **envp; char **envp;
char **argv; char **argv;
@ -867,8 +870,8 @@ g_desktop_app_info_launch (GAppInfo *appinfo,
do do
{ {
old_files = files; old_uris = uris;
if (!expand_application_parameters (info, &files, if (!expand_application_parameters (info, &uris,
&argc, &argv, error)) &argc, &argv, error))
goto out; goto out;
@ -882,7 +885,7 @@ g_desktop_app_info_launch (GAppInfo *appinfo,
sn_id = NULL; sn_id = NULL;
if (launch_context) if (launch_context)
{ {
launched_files = dup_list_segment (old_files, files); launched_files = uri_list_segment_to_files (old_uris, uris);
display = g_app_launch_context_get_display (launch_context, display = g_app_launch_context_get_display (launch_context,
appinfo, appinfo,
@ -916,6 +919,7 @@ g_desktop_app_info_launch (GAppInfo *appinfo,
g_free (display); g_free (display);
g_list_foreach (launched_files, (GFunc)g_object_unref, NULL);
g_list_free (launched_files); g_list_free (launched_files);
} }
@ -944,7 +948,7 @@ g_desktop_app_info_launch (GAppInfo *appinfo,
envp = NULL; envp = NULL;
argv = NULL; argv = NULL;
} }
while (files != NULL); while (uris != NULL);
completed = TRUE; completed = TRUE;
@ -976,32 +980,29 @@ g_desktop_app_info_supports_files (GAppInfo *appinfo)
} }
static gboolean static gboolean
g_desktop_app_info_launch_uris (GAppInfo *appinfo, g_desktop_app_info_launch (GAppInfo *appinfo,
GList *uris, GList *files,
GAppLaunchContext *launch_context, GAppLaunchContext *launch_context,
GError **error) GError **error)
{ {
GList *files; GList *uris;
GFile *file; char *uri;
gboolean res; gboolean res;
files = NULL; uris = NULL;
while (uris) while (files)
{ {
file = g_file_new_for_uri (uris->data); uri = g_file_get_uri (files->data);
if (file == NULL) uris = g_list_prepend (uris, uri);
g_warning ("Invalid uri passed to g_desktop_app_info_launch_uris"); files = files->next;
if (file)
files = g_list_prepend (files, file);
} }
files = g_list_reverse (files); uris = g_list_reverse (uris);
res = g_desktop_app_info_launch (appinfo, files, launch_context, error); res = g_desktop_app_info_launch_uris (appinfo, uris, launch_context, error);
g_list_foreach (files, (GFunc)g_object_unref, NULL); g_list_foreach (uris, (GFunc)g_free, NULL);
g_list_free (files); g_list_free (uris);
return res; return res;
} }
@ -1394,7 +1395,7 @@ g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
{ {
GKeyFile *key_file; GKeyFile *key_file;
char *dirname; char *dirname;
char *basename, *filename; char *filename;
char *data, *desktop_id; char *data, *desktop_id;
gsize data_size; gsize data_size;
int fd; int fd;