A bit of refactoring
This commit is contained in:
parent
f4384b786c
commit
5dd814773a
2 changed files with 30 additions and 15 deletions
|
@ -535,18 +535,33 @@ gint compare_theme_directories(gconstpointer a, gconstpointer b, gpointer size_q
|
||||||
return abs(da->size - size) - abs(db->size - size);
|
return abs(da->size - size) - abs(db->size - size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bool is_full_path(const char *s)
|
||||||
|
{
|
||||||
|
if (!s)
|
||||||
|
return FALSE;
|
||||||
|
return s[0] == '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool file_exists(const char *path)
|
||||||
|
{
|
||||||
|
return g_file_test(path, G_FILE_TEST_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *icon_path_from_full_path(const char *s)
|
||||||
|
{
|
||||||
|
if (is_full_path(s) && file_exists(s))
|
||||||
|
return strdup(s);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
||||||
{
|
{
|
||||||
if (icon_name == NULL)
|
if (!icon_name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// If the icon_name is already a path and the file exists, return it
|
char *result = icon_path_from_full_path(icon_name);
|
||||||
if (strstr(icon_name, "/") == icon_name) {
|
if (result)
|
||||||
if (g_file_test(icon_name, G_FILE_TEST_EXISTS))
|
return result;
|
||||||
return strdup(icon_name);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const GSList *basenames = get_icon_locations();
|
const GSList *basenames = get_icon_locations();
|
||||||
GSList *extensions = NULL;
|
GSList *extensions = NULL;
|
||||||
|
@ -679,10 +694,10 @@ char *get_icon_path_helper(GSList *themes, const char *icon_name, int size)
|
||||||
for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) {
|
for (GSList *ext = extensions; ext; ext = g_slist_next(ext)) {
|
||||||
char *base_name = (char *)base->data;
|
char *base_name = (char *)base->data;
|
||||||
char *extension = (char *)ext->data;
|
char *extension = (char *)ext->data;
|
||||||
size_t file_name_size = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100;
|
size_t file_name_size2 = strlen(base_name) + strlen(icon_name) + strlen(extension) + 100;
|
||||||
file_name = calloc(file_name_size, 1);
|
file_name = calloc(file_name_size2, 1);
|
||||||
// filename = directory/iconname.extension
|
// filename = directory/iconname.extension
|
||||||
snprintf(file_name, file_name_size, "%s/%s%s", base_name, icon_name, extension);
|
snprintf(file_name, file_name_size2, "%s/%s%s", base_name, icon_name, extension);
|
||||||
if (debug_icons)
|
if (debug_icons)
|
||||||
fprintf(stderr, "tint2: Checking %s\n", file_name);
|
fprintf(stderr, "tint2: Checking %s\n", file_name);
|
||||||
if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
|
if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
|
||||||
|
|
|
@ -483,10 +483,10 @@ char *contract_tilde(const char *s)
|
||||||
strlcat(home_slash, "/", buf_size);
|
strlcat(home_slash, "/", buf_size);
|
||||||
|
|
||||||
if ((strcmp(s, home) == 0 || strstr(s, home_slash) == s)) {
|
if ((strcmp(s, home) == 0 || strstr(s, home_slash) == s)) {
|
||||||
size_t buf_size = strlen(s) - strlen(home) + 2;
|
size_t buf_size2 = strlen(s) - strlen(home) + 2;
|
||||||
char *result = calloc(buf_size, 1);
|
char *result = calloc(buf_size2, 1);
|
||||||
strlcat(result, "~", buf_size);
|
strlcat(result, "~", buf_size2);
|
||||||
strlcat(result, s + strlen(home), buf_size);
|
strlcat(result, s + strlen(home), buf_size2);
|
||||||
free(home_slash);
|
free(home_slash);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue