From c0bb2944764b0d60b7c9e8ed3b133eb3e24a7261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 8 Aug 2013 12:18:47 +0200 Subject: IndicatorDesktopShortcuts: add support to Path key for shortcut items --- libindicator/indicator-desktop-shortcuts.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 7b43630..6148aec 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -612,6 +612,20 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * return FALSE; } + /* If possible move to the proper launch path */ + gchar * path = g_key_file_get_locale_string(priv->keyfile, + groupheader, + G_KEY_FILE_DESKTOP_KEY_PATH, + NULL, + NULL); + + if (path && *path != '\0' && chdir(path) < 0) { + g_warning ("Impossible to run action '%s' from path '%s'", nick, path); + g_free(groupheader); + g_free(path); + return FALSE; + } + /* Grab the name and the exec entries out of our current group */ gchar * name = g_key_file_get_locale_string(priv->keyfile, groupheader, @@ -625,8 +639,6 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * NULL, NULL); - g_free(groupheader); - GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE; if (launch_context) { @@ -634,7 +646,7 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * } GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error); - g_free(name); g_free(exec); + g_free(groupheader); g_free(path); g_free(name); g_free(exec); if (error != NULL) { g_warning("Unable to build Command line App info: %s", error->message); -- cgit v1.2.3 From 6d93aba85b15b6479b7344333fb62ff77dd96f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 9 Aug 2013 12:54:25 +0200 Subject: IndicatorDesktopShortcuts: use g_key_file_get_string for path --- libindicator/indicator-desktop-shortcuts.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 6148aec..ba7a35c 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -613,11 +613,8 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * } /* If possible move to the proper launch path */ - gchar * path = g_key_file_get_locale_string(priv->keyfile, - groupheader, - G_KEY_FILE_DESKTOP_KEY_PATH, - NULL, - NULL); + gchar * path = g_key_file_get_string(priv->keyfile, groupheader, + G_KEY_FILE_DESKTOP_KEY_PATH, NULL); if (path && *path != '\0' && chdir(path) < 0) { g_warning ("Impossible to run action '%s' from path '%s'", nick, path); -- cgit v1.2.3 From 427b5d56740bab68c6cf1caa29830bd309d6f968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 22 Aug 2013 18:55:46 +0200 Subject: IndicatorDesktopShortcuts: restore previous working dir if we changed it --- libindicator/indicator-desktop-shortcuts.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index ba7a35c..5c31fca 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -571,6 +571,7 @@ gboolean indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context) { GError * error = NULL; + gchar * current_dir = NULL; g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE); IndicatorDesktopShortcutsPrivate * priv = INDICATOR_DESKTOP_SHORTCUTS_GET_PRIVATE(ids); @@ -616,11 +617,16 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * gchar * path = g_key_file_get_string(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_PATH, NULL); - if (path && *path != '\0' && chdir(path) < 0) { - g_warning ("Impossible to run action '%s' from path '%s'", nick, path); - g_free(groupheader); - g_free(path); - return FALSE; + if (path && *path != '\0') { + current_dir = g_get_current_dir(); + + if (chdir(path) < 0) { + g_warning ("Impossible to run action '%s' from path '%s'", nick, path); + g_free(current_dir); + g_free(groupheader); + g_free(path); + return FALSE; + } } /* Grab the name and the exec entries out of our current group */ @@ -643,26 +649,36 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * } GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error); - g_free(groupheader); g_free(path); g_free(name); g_free(exec); + g_free(groupheader); + g_free(path); + g_free(name); + g_free(exec); if (error != NULL) { g_warning("Unable to build Command line App info: %s", error->message); + g_free(current_dir); g_error_free(error); return FALSE; } if (appinfo == NULL) { g_warning("Unable to build Command line App info (unknown)"); + g_free(current_dir); return FALSE; } gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error); + if (current_dir && chdir(current_dir) < 0) + g_warning("Impossible to switch back to default work dir"); + + if (error != NULL) { g_warning("Unable to launch file from nick '%s': %s", nick, error->message); g_clear_error(&error); } + g_free(current_dir); g_object_unref(appinfo); return launched; -- cgit v1.2.3 From 59a242dc2ec163f33639223259a368af69ce13b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 22 Aug 2013 18:57:50 +0200 Subject: IndicatorDesktopShortcut: fix indentation --- libindicator/indicator-desktop-shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator-desktop-shortcuts.c b/libindicator/indicator-desktop-shortcuts.c index 5c31fca..0806321 100644 --- a/libindicator/indicator-desktop-shortcuts.c +++ b/libindicator/indicator-desktop-shortcuts.c @@ -621,7 +621,7 @@ indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * current_dir = g_get_current_dir(); if (chdir(path) < 0) { - g_warning ("Impossible to run action '%s' from path '%s'", nick, path); + g_warning("Impossible to run action '%s' from path '%s'", nick, path); g_free(current_dir); g_free(groupheader); g_free(path); -- cgit v1.2.3