forked from enlightenment/efl
parent
23bf91c0a7
commit
22394f127f
|
@ -8,23 +8,21 @@ ef_cb_utils(void)
|
|||
Efreet_Desktop *desktop;
|
||||
char *tmp;
|
||||
|
||||
printf("\n");
|
||||
tmp = efreet_util_path_in_default("applications",
|
||||
"/usr/share/applications/test.desktop");
|
||||
if (!tmp || strcmp(tmp, "/usr/share/applications"))
|
||||
if (tmp)
|
||||
{
|
||||
if (tmp) free(tmp);
|
||||
return 0;
|
||||
printf("%s\n", tmp);
|
||||
free(tmp);
|
||||
}
|
||||
if (tmp) free(tmp);
|
||||
|
||||
tmp = efreet_util_path_to_file_id("/usr/share/applications",
|
||||
"/usr/share/applications/this/tmp/test.desktop");
|
||||
if (!tmp || strcmp(tmp, "this-tmp-test.desktop"))
|
||||
tmp = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop");
|
||||
if (tmp)
|
||||
{
|
||||
if (tmp) free(tmp);
|
||||
return 0;
|
||||
printf("%s\n", tmp);
|
||||
free(tmp);
|
||||
}
|
||||
if (tmp) free(tmp);
|
||||
|
||||
desktop = efreet_util_desktop_by_file_id_get("kde-kresources.desktop");
|
||||
printf("kde-kresources.desktop: %p\n", desktop);
|
||||
|
|
|
@ -803,13 +803,10 @@ int
|
|||
efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos)
|
||||
{
|
||||
Efreet_Menu *entry;
|
||||
char *path;
|
||||
char *id;
|
||||
|
||||
if (!desktop || !menu) return 0;
|
||||
path = efreet_util_path_in_default("applications", desktop->orig_path);
|
||||
if (!path) return 0;
|
||||
id = efreet_util_path_to_file_id(path, desktop->orig_path);
|
||||
id = efreet_util_path_to_file_id(desktop->orig_path);
|
||||
|
||||
entry = efreet_menu_entry_new();
|
||||
entry->type = EFREET_MENU_ENTRY_DESKTOP;
|
||||
|
@ -833,7 +830,6 @@ efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos)
|
|||
}
|
||||
|
||||
free(id);
|
||||
free(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,14 +41,27 @@ 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_util_path_to_file_id(const char *path)
|
||||
{
|
||||
size_t len;
|
||||
char *id, *p;
|
||||
char *base;
|
||||
|
||||
if (!path) return NULL;
|
||||
base = efreet_util_path_in_default("applications", path);
|
||||
if (!base) return NULL;
|
||||
|
||||
len = strlen(base);
|
||||
if (strlen(path) <= len) return NULL;
|
||||
if (strncmp(path, base, len)) return NULL;
|
||||
if (strlen(path) <= len)
|
||||
{
|
||||
free(base);
|
||||
return NULL;
|
||||
}
|
||||
if (strncmp(path, base, len))
|
||||
{
|
||||
free(base);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
id = strdup(path + len + 1);
|
||||
p = id;
|
||||
|
@ -57,6 +70,7 @@ efreet_util_path_to_file_id(const char *base, const char *path)
|
|||
if (*p == '/') *p = '-';
|
||||
p++;
|
||||
}
|
||||
free(base);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#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_to_file_id(const char *path);
|
||||
Efreet_Desktop *efreet_util_desktop_by_file_id_get(const char *file_id);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue