util to get a desktop by file id.

SVN revision: 29052
This commit is contained in:
Sebastian Dransfeld 2007-03-24 21:59:34 +00:00
parent 5ebad1b1d6
commit 870067d6a9
3 changed files with 55 additions and 11 deletions

View File

@ -5,24 +5,32 @@
int
ef_cb_utils(void)
{
Efreet_Desktop *desktop;
char *tmp;
tmp = efreet_util_path_in_default("applications",
"/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;
}
free(tmp);
if (tmp) free(tmp);
tmp = efreet_util_path_to_file_id("/usr/share/applications",
"/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;
}
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;
}

View File

@ -36,10 +36,8 @@ efreet_util_path_to_file_id(const char *base, const char *path)
char *id, *p;
len = strlen(base);
#if 0
if (strlen(path) <= len) return NULL;
if (!strncmp(path, base, len)) return NULL;
#endif
if (strncmp(path, base, len)) return NULL;
id = strdup(path + len + 1);
p = id;
@ -50,3 +48,40 @@ efreet_util_path_to_file_id(const char *base, const char *path)
}
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;
}

View File

@ -2,7 +2,8 @@
#ifndef EFREET_UTILS_H
#define EFREET_UTILS_H
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_in_default(const char *section, 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