1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-23 22:52:34 +01:00

Function get_name_for_icon splitted

The function get_name_for_icon returns now the name of the icon,
without the full icon path and without extension (.xpm). Now is
not static.

The full path, including the folder creation, is done now by
wmkdirhier() (WINGs). This function is much better, because
supports "infinite" folders, not like the old get_name_for_icon
which could only create the specific folder for Cache Icons.

Using this functions, wIconStore() do the same work, but in a better
way, more clear.
This commit is contained in:
Rodolfo García Peñas (kix)
2012-06-10 00:59:17 +02:00
committed by Carlos R. Mafra
parent 7ef416f8ac
commit f8291de919

View File

@@ -398,57 +398,28 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
return !error;
}
static char *get_name_for_icon(WWindow * wwin)
char *get_name_for_icon(WWindow *wwin)
{
char *prefix, *suffix;
char *path;
char *suffix;
int len;
if (wwin->wm_class && wwin->wm_instance) {
int len = strlen(wwin->wm_class) + strlen(wwin->wm_instance) + 2;
len = strlen(wwin->wm_class) + strlen(wwin->wm_instance) + 2;
suffix = wmalloc(len);
snprintf(suffix, len, "%s.%s", wwin->wm_instance, wwin->wm_class);
} else if (wwin->wm_class) {
int len = strlen(wwin->wm_class) + 1;
len = strlen(wwin->wm_class) + 1;
suffix = wmalloc(len);
snprintf(suffix, len, "%s", wwin->wm_class);
} else if (wwin->wm_instance) {
int len = strlen(wwin->wm_instance) + 1;
len = strlen(wwin->wm_instance) + 1;
suffix = wmalloc(len);
snprintf(suffix, len, "%s", wwin->wm_instance);
} else {
return NULL;
}
prefix = wusergnusteppath();
len = strlen(prefix) + 64 + strlen(suffix);
path = wmalloc(len + 1);
snprintf(path, len, "%s/Library/WindowMaker", prefix);
if (access(path, F_OK) != 0) {
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
werror(_("could not create directory %s"), path);
wfree(path);
wfree(suffix);
return NULL;
}
}
strcat(path, "/CachedPixmaps");
if (access(path, F_OK) != 0) {
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
werror(_("could not create directory %s"), path);
wfree(path);
wfree(suffix);
return NULL;
}
}
strcat(path, "/");
strcat(path, suffix);
strcat(path, ".xpm");
wfree(suffix);
return path;
return suffix;
}
static char *get_icon_cache_path(void)
@@ -502,17 +473,30 @@ static RImage *get_wwindow_image_from_wmhints(WWindow *wwin, WIcon *icon)
*/
char *wIconStore(WIcon * icon)
{
char *path;
char *path, *dir_path, *file;
int len = 0;
RImage *image = NULL;
WWindow *wwin = icon->owner;
if (!wwin)
return NULL;
path = get_name_for_icon(wwin);
if (!path)
dir_path = get_icon_cache_path();
if (!dir_path)
return NULL;
file = get_name_for_icon(wwin);
if (!file) {
wfree(dir_path);
return NULL;
}
len = strlen(dir_path) + strlen(file) + 5;
path = wmalloc(len);
snprintf(path, len, "%s%s.xpm", dir_path, file);
wfree(dir_path);
wfree(file);
/* If icon exists, exit */
if (access(path, F_OK) == 0)
return path;