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
=== modified file 'libindicator/indicator-desktop-shortcuts.c'
--- libindicator/indicator-desktop-shortcuts.c 2013-07-17 19:47:48 +0000
+++ libindicator/indicator-desktop-shortcuts.c 2013-08-22 16:58:11 +0000
@@ -571,6 +571,7 @@
571indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context)571indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context)
572{572{
573 GError * error = NULL;573 GError * error = NULL;
574 gchar * current_dir = NULL;
574575
575 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);576 g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
576 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);577 IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids);
@@ -612,6 +613,22 @@
612 return FALSE;613 return FALSE;
613 }614 }
614615
616 /* If possible move to the proper launch path */
617 gchar * path = g_key_file_get_string(priv->keyfile, groupheader,
618 G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
619
620 if (path && *path != '\0') {
621 current_dir = g_get_current_dir();
622
623 if (chdir(path) < 0) {
624 g_warning("Impossible to run action '%s' from path '%s'", nick, path);
625 g_free(current_dir);
626 g_free(groupheader);
627 g_free(path);
628 return FALSE;
629 }
630 }
631
615 /* Grab the name and the exec entries out of our current group */632 /* Grab the name and the exec entries out of our current group */
616 gchar * name = g_key_file_get_locale_string(priv->keyfile,633 gchar * name = g_key_file_get_locale_string(priv->keyfile,
617 groupheader,634 groupheader,
@@ -625,8 +642,6 @@
625 NULL,642 NULL,
626 NULL);643 NULL);
627644
628 g_free(groupheader);
629
630 GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;645 GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
631646
632 if (launch_context) {647 if (launch_context) {
@@ -634,26 +649,36 @@
634 }649 }
635650
636 GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error);651 GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error);
637 g_free(name); g_free(exec);652 g_free(groupheader);
653 g_free(path);
654 g_free(name);
655 g_free(exec);
638656
639 if (error != NULL) {657 if (error != NULL) {
640 g_warning("Unable to build Command line App info: %s", error->message);658 g_warning("Unable to build Command line App info: %s", error->message);
659 g_free(current_dir);
641 g_error_free(error);660 g_error_free(error);
642 return FALSE;661 return FALSE;
643 }662 }
644663
645 if (appinfo == NULL) {664 if (appinfo == NULL) {
646 g_warning("Unable to build Command line App info (unknown)");665 g_warning("Unable to build Command line App info (unknown)");
666 g_free(current_dir);
647 return FALSE;667 return FALSE;
648 }668 }
649669
650 gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error);670 gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error);
651671
672 if (current_dir && chdir(current_dir) < 0)
673 g_warning("Impossible to switch back to default work dir");
674
675
652 if (error != NULL) {676 if (error != NULL) {
653 g_warning("Unable to launch file from nick '%s': %s", nick, error->message);677 g_warning("Unable to launch file from nick '%s': %s", nick, error->message);
654 g_clear_error(&error);678 g_clear_error(&error);
655 }679 }
656680
681 g_free(current_dir);
657 g_object_unref(appinfo);682 g_object_unref(appinfo);
658683
659 return launched;684 return launched;

Subscribers

People subscribed via source and target branches