Merge lp:~3v1n0/libindicator/shortcut-path-key into lp:libindicator/13.10

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Charles Kerr
Approved revision: 512
Merged at revision: 509
Proposed branch: lp:~3v1n0/libindicator/shortcut-path-key
Merge into: lp:libindicator/13.10
Diff against target: 81 lines (+28/-3)
1 file modified
libindicator/indicator-desktop-shortcuts.c (+28/-3)
To merge this branch: bzr merge lp:~3v1n0/libindicator/shortcut-path-key
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Needs Fixing
Review via email: mp+179149@code.launchpad.net

Commit message

IndicatorDesktopShortcuts: add support to Path key for shortcut items

Description of the change

If the .desktop action provides a Path key, change working directory
to that before executing the action. Unfortunately GAppInfo doesn't
provide a such facility when creating command line applications, but
it does exactly like this internally.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

I don't think that the path can be translated, so this should be g_key_file_get_string().

review: Needs Fixing
510. By Marco Trevisan (Treviño)

IndicatorDesktopShortcuts: use g_key_file_get_string for path

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> I don't think that the path can be translated, so this should be
> g_key_file_get_string().

Oh My... Right sorry. Blind copy&paste! :P

Fixed...

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks for writing this patch. I see one minor problem and also have a question:

Needs Fixing:

1. This patch introduces a side-effect to the function: the cwd is still changed when the function returns. It would be safer to remove this side-effect by wrapping the block in

  char * current_dir = g_get_current_dir();

  ...

  g_chdir (current_dir);
  g_free (current_dir);

Comment only:

2. Putting four g_free() statements on a single line really itches. :-) Please use a newline between each.

3. Should the chdir() call in the patch be a g_chdir()? I think the answer is 'no' but I'm unsure.

review: Needs Fixing
511. By Marco Trevisan (Treviño)

IndicatorDesktopShortcuts: restore previous working dir if we changed it

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Thanks for writing this patch. I see one minor problem and also have a
> question:
>
> Needs Fixing:
>
> 1. This patch introduces a side-effect to the function: the cwd is still
> changed when the function returns. It would be safer to remove this side-
> effect by wrapping the block in
>
> char * current_dir = g_get_current_dir();
>
> ...
>
> g_chdir (current_dir);
> g_free (current_dir);

Yes, I thought about that... But I didn't do that as it was the same way as g_spawn* does for example... However, it also sounds better to me. So here it is!

> 2. Putting four g_free() statements on a single line really itches. :-) Please
> use a newline between each.

Yes, right... I just kept the old style.

> 3. Should the chdir() call in the patch be a g_chdir()? I think the answer is
> 'no' but I'm unsure.

It's just the same, and AFAIK we won't use this but in linux, it should be the same :)
(it also would need to include something else).

512. By Marco Trevisan (Treviño)

IndicatorDesktopShortcut: fix indentation

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

>> 2. Putting four g_free() statements on a single line really itches. :-) Please use a newline between each.
>
> Yes, right... I just kept the old style.

Right, I didn't mean to imply you started it. IIRC I may have added a g_free() at the end of that line too. If so, I was wrong. :-)

Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libindicator/indicator-desktop-shortcuts.c'
2--- libindicator/indicator-desktop-shortcuts.c 2013-07-17 19:47:48 +0000
3+++ libindicator/indicator-desktop-shortcuts.c 2013-08-22 16:58:11 +0000
4@@ -571,6 +571,7 @@
5 indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context)
6 {
7 GError * error = NULL;
8+ gchar * current_dir = NULL;
9
10 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
11 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
12@@ -612,6 +613,22 @@
13 return FALSE;
14 }
15
16+ /* If possible move to the proper launch path */
17+ gchar * path = g_key_file_get_string(priv->keyfile, groupheader,
18+ G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
19+
20+ if (path && *path != '\0') {
21+ current_dir = g_get_current_dir();
22+
23+ if (chdir(path) < 0) {
24+ g_warning("Impossible to run action '%s' from path '%s'", nick, path);
25+ g_free(current_dir);
26+ g_free(groupheader);
27+ g_free(path);
28+ return FALSE;
29+ }
30+ }
31+
32 /* Grab the name and the exec entries out of our current group */
33 gchar * name = g_key_file_get_locale_string(priv->keyfile,
34 groupheader,
35@@ -625,8 +642,6 @@
36 NULL,
37 NULL);
38
39- g_free(groupheader);
40-
41 GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
42
43 if (launch_context) {
44@@ -634,26 +649,36 @@
45 }
46
47 GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error);
48- g_free(name); g_free(exec);
49+ g_free(groupheader);
50+ g_free(path);
51+ g_free(name);
52+ g_free(exec);
53
54 if (error != NULL) {
55 g_warning("Unable to build Command line App info: %s", error->message);
56+ g_free(current_dir);
57 g_error_free(error);
58 return FALSE;
59 }
60
61 if (appinfo == NULL) {
62 g_warning("Unable to build Command line App info (unknown)");
63+ g_free(current_dir);
64 return FALSE;
65 }
66
67 gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error);
68
69+ if (current_dir && chdir(current_dir) < 0)
70+ g_warning("Impossible to switch back to default work dir");
71+
72+
73 if (error != NULL) {
74 g_warning("Unable to launch file from nick '%s': %s", nick, error->message);
75 g_clear_error(&error);
76 }
77
78+ g_free(current_dir);
79 g_object_unref(appinfo);
80
81 return launched;

Subscribers

People subscribed via source and target branches