parent
5ebad1b1d6
commit
870067d6a9
|
@ -5,24 +5,32 @@
|
||||||
int
|
int
|
||||||
ef_cb_utils(void)
|
ef_cb_utils(void)
|
||||||
{
|
{
|
||||||
|
Efreet_Desktop *desktop;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = efreet_util_path_in_default("applications",
|
tmp = efreet_util_path_in_default("applications",
|
||||||
"/usr/share/applications/test.desktop");
|
"/usr/share/applications/test.desktop");
|
||||||
if (strcmp(tmp, "/usr/share/applications"))
|
if (!tmp || strcmp(tmp, "/usr/share/applications"))
|
||||||
{
|
{
|
||||||
free(tmp);
|
if (tmp) free(tmp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
free(tmp);
|
if (tmp) free(tmp);
|
||||||
|
|
||||||
tmp = efreet_util_path_to_file_id("/usr/share/applications",
|
tmp = efreet_util_path_to_file_id("/usr/share/applications",
|
||||||
"/usr/share/applications/this/tmp/test.desktop");
|
"/usr/share/applications/this/tmp/test.desktop");
|
||||||
if (strcmp(tmp, "this-tmp-test.desktop"))
|
if (!tmp || strcmp(tmp, "this-tmp-test.desktop"))
|
||||||
{
|
{
|
||||||
free(tmp);
|
if (tmp) free(tmp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
free(tmp);
|
if (tmp) free(tmp);
|
||||||
|
|
||||||
|
desktop = efreet_util_desktop_by_file_id_get("kde-kresources.desktop");
|
||||||
|
printf("kde-kresources.desktop: %p\n", desktop);
|
||||||
|
desktop = efreet_util_desktop_by_file_id_get("mplayer.desktop");
|
||||||
|
printf("mplayer.desktop: %p\n", desktop);
|
||||||
|
desktop = efreet_util_desktop_by_file_id_get("nautilus-computer.desktop");
|
||||||
|
printf("nautilus-computer.desktop: %p\n", desktop);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,8 @@ efreet_util_path_to_file_id(const char *base, const char *path)
|
||||||
char *id, *p;
|
char *id, *p;
|
||||||
|
|
||||||
len = strlen(base);
|
len = strlen(base);
|
||||||
#if 0
|
|
||||||
if (strlen(path) <= len) return NULL;
|
if (strlen(path) <= len) return NULL;
|
||||||
if (!strncmp(path, base, len)) return NULL;
|
if (strncmp(path, base, len)) return NULL;
|
||||||
#endif
|
|
||||||
|
|
||||||
id = strdup(path + len + 1);
|
id = strdup(path + len + 1);
|
||||||
p = id;
|
p = id;
|
||||||
|
@ -50,3 +48,40 @@ efreet_util_path_to_file_id(const char *base, const char *path)
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Efreet_Desktop *
|
||||||
|
efreet_util_desktop_by_file_id_get(const char *file_id)
|
||||||
|
{
|
||||||
|
Efreet_Desktop *desktop = NULL;
|
||||||
|
Ecore_List *dirs;
|
||||||
|
const char *dir;
|
||||||
|
|
||||||
|
if (!file_id) return NULL;
|
||||||
|
|
||||||
|
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
|
||||||
|
"applications");
|
||||||
|
if (!dirs) return NULL;
|
||||||
|
|
||||||
|
ecore_list_goto_first(dirs);
|
||||||
|
while ((dir = ecore_list_next(dirs)))
|
||||||
|
{
|
||||||
|
char *tmp, *p;
|
||||||
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
|
tmp = strdup(file_id);
|
||||||
|
p = tmp;
|
||||||
|
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf), "%s/%s", dir, file_id);
|
||||||
|
desktop = efreet_desktop_get(buf);
|
||||||
|
if (desktop) break;
|
||||||
|
p = strchr(p, '-');
|
||||||
|
if (p) *p = '/';
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
|
if (desktop) break;
|
||||||
|
}
|
||||||
|
ecore_list_destroy(dirs);
|
||||||
|
return desktop;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#ifndef EFREET_UTILS_H
|
#ifndef EFREET_UTILS_H
|
||||||
#define EFREET_UTILS_H
|
#define EFREET_UTILS_H
|
||||||
|
|
||||||
char *efreet_util_path_in_default(const char *section, const char *path);
|
char *efreet_util_path_in_default(const char *section, const char *path);
|
||||||
char *efreet_util_path_to_file_id(const char *base, const char *path);
|
char *efreet_util_path_to_file_id(const char *base, const char *path);
|
||||||
|
Efreet_Desktop *efreet_util_desktop_by_file_id_get(const char *file_id);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue