Expand ~ in launcher_item_app

git-svn-id: http://tint2.googlecode.com/svn/trunk@726 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
o9000 2015-03-01 10:33:05 +00:00 committed by mrovi9000@gmail.com
parent 0d1b78d808
commit ba40b0752f
5 changed files with 57 additions and 6 deletions

View file

@ -603,7 +603,7 @@ void add_entry (char *key, char *value)
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) {

View file

@ -1851,6 +1851,10 @@ void create_launcher(GtkWidget *parent)
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);

View file

@ -409,7 +409,9 @@ void config_write_launcher(FILE *fp)
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 @@ void add_entry(char *key, char *value)
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);

View file

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include "common.h"
#include "../server.h"
@ -95,6 +95,43 @@ void tint_exec(const char *command)
}
}
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)
{
@ -297,7 +334,6 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright
}
}
void createHeuristicMask(DATA32* data, int w, int h)
{
// first we need to find the mask color, therefore we check all 4 edge pixel and take the color which

View file

@ -43,6 +43,13 @@ int parse_line (const char *line, char **key, char **value);
// 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);