Expand ~ in launcher_item_app git-svn-id: http://tint2.googlecode.com/svn/trunk@726 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
o9000 o9000
5 files changed,
57 insertions(+),
6 deletions(-)
M
src/config.c
→
src/config.c
@@ -603,7 +603,7 @@ else if (strcmp(key, "launcher_icon_size") == 0) {
launcher_max_icon_size = atoi(value); } else if (strcmp(key, "launcher_item_app") == 0) { - char *app = strdup(value); + char *app = expand_tilde(value); panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app); } else if (strcmp(key, "launcher_icon_theme") == 0) {
M
src/tint2conf/properties.c
→
src/tint2conf/properties.c
@@ -1851,6 +1851,10 @@ fprintf(stderr, "Icon themes loaded\n"); fflush(stderr);
fprintf(stderr, "Loading .desktop files\n"); fflush(stderr); load_desktop_files("/usr/share/applications"); + gchar *path = g_build_filename(g_get_home_dir(), ".local/share/applications", NULL); + load_desktop_files(path); + g_free(path); + load_icons(launcher_apps); load_icons(all_apps); fprintf(stderr, "Desktop files loaded\n"); fflush(stderr);
M
src/tint2conf/properties_rw.c
→
src/tint2conf/properties_rw.c
@@ -409,7 +409,9 @@ gchar *app_path;
gtk_tree_model_get(GTK_TREE_MODEL(launcher_apps), &iter, appsColPath, &app_path, -1); - fprintf(fp, "launcher_item_app = %s\n", app_path); + char *contracted = contract_tilde(app_path); + fprintf(fp, "launcher_item_app = %s\n", contracted); + free(contracted); g_free(app_path); }@@ -1079,8 +1081,10 @@ else if (strcmp(key, "launcher_icon_size") == 0) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(launcher_icon_size), atoi(value)); } else if (strcmp(key, "launcher_item_app") == 0) { - load_desktop_file(value, TRUE); - load_desktop_file(value, FALSE); + char *path = expand_tilde(value); + load_desktop_file(path, TRUE); + load_desktop_file(path, FALSE); + free(path); } else if (strcmp(key, "launcher_icon_theme") == 0) { set_current_icon_theme(value);
M
src/util/common.c
→
src/util/common.c
@@ -26,7 +26,7 @@ #include <stdio.h>
#include <stdlib.h> #include <string.h> #include <unistd.h> - +#include <glib.h> #include "common.h" #include "../server.h"@@ -95,6 +95,43 @@ }
} } +char *expand_tilde(char *s) +{ + const gchar *home = g_get_home_dir(); + if (home && + (strcmp(s, "~") == 0 || + strstr(s, "~/") == s)) { + char *result = calloc(strlen(home) + strlen(s), 1); + strcat(result, home); + strcat(result, s + 1); + return result; + } else { + return strdup(s); + } +} + +char *contract_tilde(char *s) +{ + const gchar *home = g_get_home_dir(); + if (!home) + return strdup(s); + + char *home_slash = calloc(strlen(home) + 1, 1); + strcat(home_slash, home); + strcat(home_slash, "/"); + + if ((strcmp(s, home) == 0 || + strstr(s, home_slash) == s)) { + char *result = calloc(strlen(s) - strlen(home) + 1, 1); + strcat(result, "~"); + strcat(result, s + strlen(home)); + free(home_slash); + return result; + } else { + free(home_slash); + return strdup(s); + } +} int hex_char_to_int (char c) {@@ -296,7 +333,6 @@ data[id] = argb;
} } } - void createHeuristicMask(DATA32* data, int w, int h) {
M
src/util/common.h
→
src/util/common.h
@@ -43,6 +43,13 @@
// execute a command by calling fork void tint_exec(const char* command); +// Returns a copy of s in which "~" is expanded to the path to the user's home directory. +// The returned string must be freed by the caller. +char *expand_tilde(char *s); + +// The opposite of expand_tilde: replaces the path to the user's home directory with "~". +// The returned string must be freed by the caller. +char *contract_tilde(char *s); // conversion int hex_char_to_int (char c);