summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2007-03-24 21:59:34 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2007-03-24 21:59:34 +0000
commit870067d6a93a2fb60606d57fc775112e963205fd (patch)
treea436d79aece71498048e91a6886837a5a51ce1d9 /legacy/efreet
parent5ebad1b1d6198237e9ad51470c0ed9f4dae1c22d (diff)
util to get a desktop by file id.
SVN revision: 29052
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/bin/ef_utils.c20
-rw-r--r--legacy/efreet/src/lib/efreet_utils.c41
-rw-r--r--legacy/efreet/src/lib/efreet_utils.h5
3 files changed, 55 insertions, 11 deletions
diff --git a/legacy/efreet/src/bin/ef_utils.c b/legacy/efreet/src/bin/ef_utils.c
index 8e8f75f340..f26f504bb1 100644
--- a/legacy/efreet/src/bin/ef_utils.c
+++ b/legacy/efreet/src/bin/ef_utils.c
@@ -5,24 +5,32 @@
5int 5int
6ef_cb_utils(void) 6ef_cb_utils(void)
7{ 7{
8 Efreet_Desktop *desktop;
8 char *tmp; 9 char *tmp;
9 10
10 tmp = efreet_util_path_in_default("applications", 11 tmp = efreet_util_path_in_default("applications",
11 "/usr/share/applications/test.desktop"); 12 "/usr/share/applications/test.desktop");
12 if (strcmp(tmp, "/usr/share/applications")) 13 if (!tmp || strcmp(tmp, "/usr/share/applications"))
13 { 14 {
14 free(tmp); 15 if (tmp) free(tmp);
15 return 0; 16 return 0;
16 } 17 }
17 free(tmp); 18 if (tmp) free(tmp);
18 19
19 tmp = efreet_util_path_to_file_id("/usr/share/applications", 20 tmp = efreet_util_path_to_file_id("/usr/share/applications",
20 "/usr/share/applications/this/tmp/test.desktop"); 21 "/usr/share/applications/this/tmp/test.desktop");
21 if (strcmp(tmp, "this-tmp-test.desktop")) 22 if (!tmp || strcmp(tmp, "this-tmp-test.desktop"))
22 { 23 {
23 free(tmp); 24 if (tmp) free(tmp);
24 return 0; 25 return 0;
25 } 26 }
26 free(tmp); 27 if (tmp) free(tmp);
28
29 desktop = efreet_util_desktop_by_file_id_get("kde-kresources.desktop");
30 printf("kde-kresources.desktop: %p\n", desktop);
31 desktop = efreet_util_desktop_by_file_id_get("mplayer.desktop");
32 printf("mplayer.desktop: %p\n", desktop);
33 desktop = efreet_util_desktop_by_file_id_get("nautilus-computer.desktop");
34 printf("nautilus-computer.desktop: %p\n", desktop);
27 return 1; 35 return 1;
28} 36}
diff --git a/legacy/efreet/src/lib/efreet_utils.c b/legacy/efreet/src/lib/efreet_utils.c
index 6d387e664a..ef8f87942c 100644
--- a/legacy/efreet/src/lib/efreet_utils.c
+++ b/legacy/efreet/src/lib/efreet_utils.c
@@ -36,10 +36,8 @@ efreet_util_path_to_file_id(const char *base, const char *path)
36 char *id, *p; 36 char *id, *p;
37 37
38 len = strlen(base); 38 len = strlen(base);
39#if 0
40 if (strlen(path) <= len) return NULL; 39 if (strlen(path) <= len) return NULL;
41 if (!strncmp(path, base, len)) return NULL; 40 if (strncmp(path, base, len)) return NULL;
42#endif
43 41
44 id = strdup(path + len + 1); 42 id = strdup(path + len + 1);
45 p = id; 43 p = id;
@@ -50,3 +48,40 @@ efreet_util_path_to_file_id(const char *base, const char *path)
50 } 48 }
51 return id; 49 return id;
52} 50}
51
52Efreet_Desktop *
53efreet_util_desktop_by_file_id_get(const char *file_id)
54{
55 Efreet_Desktop *desktop = NULL;
56 Ecore_List *dirs;
57 const char *dir;
58
59 if (!file_id) return NULL;
60
61 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
62 "applications");
63 if (!dirs) return NULL;
64
65 ecore_list_goto_first(dirs);
66 while ((dir = ecore_list_next(dirs)))
67 {
68 char *tmp, *p;
69 char buf[PATH_MAX];
70
71 tmp = strdup(file_id);
72 p = tmp;
73
74 while (p)
75 {
76 snprintf(buf, sizeof(buf), "%s/%s", dir, file_id);
77 desktop = efreet_desktop_get(buf);
78 if (desktop) break;
79 p = strchr(p, '-');
80 if (p) *p = '/';
81 }
82 free(tmp);
83 if (desktop) break;
84 }
85 ecore_list_destroy(dirs);
86 return desktop;
87}
diff --git a/legacy/efreet/src/lib/efreet_utils.h b/legacy/efreet/src/lib/efreet_utils.h
index c28aa1c6da..0c790d0157 100644
--- a/legacy/efreet/src/lib/efreet_utils.h
+++ b/legacy/efreet/src/lib/efreet_utils.h
@@ -2,7 +2,8 @@
2#ifndef EFREET_UTILS_H 2#ifndef EFREET_UTILS_H
3#define EFREET_UTILS_H 3#define EFREET_UTILS_H
4 4
5char *efreet_util_path_in_default(const char *section, const char *path); 5char *efreet_util_path_in_default(const char *section, const char *path);
6char *efreet_util_path_to_file_id(const char *base, const char *path); 6char *efreet_util_path_to_file_id(const char *base, const char *path);
7Efreet_Desktop *efreet_util_desktop_by_file_id_get(const char *file_id);
7 8
8#endif 9#endif