summaryrefslogtreecommitdiff
path: root/src/tests/efreet/ef_icon_theme.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-29 23:04:40 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-29 23:04:40 +0000
commit4bc0210bd31ed1de6554441562bd93ea863ee9d9 (patch)
tree5d83be12538f8c8d3816bbf65916ce383d050c2e /src/tests/efreet/ef_icon_theme.c
parent727ddbeaf0c53f31cd62c254fdebe26823d537eb (diff)
efl: merge efreet.
seems to be fine, pass distcheck and friends. please report. changes: - documentation hierarchy fixes - replaced __UNUSED__ with EINA_UNUSED - replaced PKG_DATA_DIR with PACKAGE_DATA_DIR"/efreet" SVN revision: 81889
Diffstat (limited to 'src/tests/efreet/ef_icon_theme.c')
-rw-r--r--src/tests/efreet/ef_icon_theme.c605
1 files changed, 605 insertions, 0 deletions
diff --git a/src/tests/efreet/ef_icon_theme.c b/src/tests/efreet/ef_icon_theme.c
new file mode 100644
index 0000000000..6c531db36a
--- /dev/null
+++ b/src/tests/efreet/ef_icon_theme.c
@@ -0,0 +1,605 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include "Efreet.h"
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9#include <limits.h>
10#include <Ecore.h>
11#include <Ecore_File.h>
12
13#define SIZE 128
14#define THEME "Tango"
15#define FREE(x) do { free(x); x = NULL; } while (0);
16
17static Eina_Bool _hash_keys(Eina_Hash *hash, const char *key, void *list);
18static void ef_icon_theme_themes_find(const char *search_dir,
19 Eina_Hash *themes);
20static void ef_icons_find(Efreet_Icon_Theme *theme, Eina_Hash *icons);
21static void ef_read_dir(const char *dir, Eina_Hash *icons);
22
23int
24ef_cb_efreet_icon_theme(void)
25{
26 int ret = 1;
27 const char *tmp;
28
29 unsetenv("XDG_DATA_HOME");
30 efreet_shutdown();
31 putenv("HOME=/var/tmp");
32 efreet_init();
33
34 tmp = efreet_icon_user_dir_get();
35 if (strcmp(tmp, "/var/tmp/.local/share/icons"))
36 {
37 printf("efreet_icon_user_dir_get() returned incorrect "
38 "value (%s) on HOME=/var/tmp\n", tmp);
39 ret = 0;
40 }
41
42 efreet_shutdown();
43 unsetenv("HOME");
44#ifdef _WIN32
45 unsetenv("USERPROFILE");
46#endif
47 efreet_init();
48
49 tmp = efreet_icon_user_dir_get();
50 if (strcmp(tmp, "/tmp/.local/share/icons"))
51 {
52 printf("efreet_icon_user_dir_get() returned incorrect "
53 "value (%s) on HOME=\n", tmp);
54 ret = 0;
55 }
56
57 return ret;
58}
59
60static Eina_Bool
61_hash_keys(Eina_Hash *hash EINA_UNUSED, const char *key, void *list)
62{
63 Eina_List **l = list;
64
65 *l = eina_list_append(*l, key);
66 return EINA_TRUE;
67}
68
69int
70ef_cb_efreet_icon_theme_list(void)
71{
72 int ret = 1;
73 Eina_List *themes;
74 Eina_List *icon_dirs;
75 Eina_List *l;
76 Eina_Hash *dirs;
77 Eina_Iterator *it;
78 Efreet_Icon_Theme *theme;
79 const char *dir;
80 char buf[PATH_MAX];
81
82 dirs = eina_hash_string_superfast_new(free);
83
84 icon_dirs = efreet_data_dirs_get();
85
86 ef_icon_theme_themes_find(efreet_icon_user_dir_get(), dirs);
87 EINA_LIST_FOREACH(icon_dirs, l, dir)
88 {
89 snprintf(buf, sizeof(buf), "%s/icons", dir);
90 ef_icon_theme_themes_find(buf, dirs);
91 }
92 EINA_LIST_FOREACH(icon_dirs, l, dir)
93 {
94 snprintf(buf, sizeof(buf), "%s/pixmaps", dir);
95 ef_icon_theme_themes_find(buf, dirs);
96 }
97 ef_icon_theme_themes_find("/usr/share/pixmaps", dirs);
98
99 themes = efreet_icon_theme_list_get();
100 EINA_LIST_FOREACH(themes, l, theme)
101 {
102 if ((eina_hash_find(dirs, theme->name.internal)))
103 eina_hash_del(dirs, theme->name.internal, NULL);
104 else
105 {
106 printf("efreet_icon_theme_list_get() returned %s which we didn't "
107 "see when scanning the directories.\n", theme->name.internal);
108 ret = 0;
109 }
110 }
111 while (themes)
112 {
113 themes = eina_list_remove_list(themes, themes);
114 }
115
116 themes = NULL;
117 it = eina_hash_iterator_key_new(dirs);
118 eina_iterator_foreach(it, EINA_EACH_CB(_hash_keys), &themes);
119 eina_iterator_free(it);
120
121 if (eina_list_count(themes) > 0)
122 {
123 printf("efreet_icon_theme_list_get() missed: ");
124 EINA_LIST_FOREACH(themes, l, dir)
125 printf("%s ", dir);
126 printf("\n");
127
128 ret = 0;
129 }
130 while (themes)
131 {
132 themes = eina_list_remove_list(themes, themes);
133 }
134 eina_hash_free(dirs);
135
136 return ret;
137}
138
139static void
140ef_icon_theme_themes_find(const char *search_dir, Eina_Hash *themes)
141{
142 Eina_List *dirs;
143 char *dir;
144
145 if (!search_dir || !themes) return;
146
147 dirs = ecore_file_ls(search_dir);
148 if (!dirs) return;
149
150 while ((dir = eina_list_data_get(dirs)))
151 {
152 char p[PATH_MAX];
153
154 dirs = eina_list_remove_list(dirs, dirs);
155 /* if we've already added the theme we're done */
156 if (eina_hash_find(themes, dir))
157 {
158 free(dir);
159 continue;
160 }
161
162 /* if the index.theme file exists we open it and look for the hidden
163 * flag. */
164 snprintf(p, sizeof(p), "%s/%s/index.theme", search_dir, dir);
165 if (ecore_file_exists(p))
166 {
167 Efreet_Ini *ini;
168 char *d;
169 int skip = 0;
170
171 ini = efreet_ini_new(p);
172 efreet_ini_section_set(ini, "Icon Theme");
173
174 //if (efreet_ini_boolean_get(ini, "Hidden")) skip = 1;
175 if (!efreet_ini_localestring_get(ini, "Name")) skip = 1;
176 efreet_ini_free(ini);
177
178 if (!skip)
179 {
180 d = strdup(dir);
181 eina_hash_add(themes, dir, d);
182 }
183 }
184 free(dir);
185 }
186}
187
188const char *system_icons[] =
189{
190 "address-book-new",
191 "application-exit",
192 "appointment-new",
193 "contact-new",
194 "dialog-apply",
195 "dialog-cancel",
196 "dialog-close",
197 "dialog-ok",
198 "document-new",
199 "document-open",
200 "document-open-recent",
201 "document-page-setup",
202 "document-print",
203 "document-print-preview",
204 "document-properties",
205 "document-revert",
206 "document-save",
207 "document-save-as",
208 "edit-copy",
209 "edit-cut",
210 "edit-delete",
211 "edit-find",
212 "edit-find-replace",
213 "edit-paste",
214 "edit-redo",
215 "edit-select-all",
216 "edit-undo",
217 "format-indent-less",
218 "format-indent-more",
219 "format-justify-center",
220 "format-justify-fill",
221 "format-justify-left",
222 "format-justify-right",
223 "format-text-direction-ltr",
224 "format-text-direction-rtl",
225 "format-text-bold",
226 "format-text-italic",
227 "format-text-underline",
228 "format-text-strikethrough",
229 "go-bottom",
230 "go-down",
231 "go-first",
232 "go-home",
233 "go-jump",
234 "go-last",
235 "go-next",
236 "go-previous",
237 "go-top",
238 "go-up",
239 "help-about",
240 "help-contents",
241 "help-faq",
242 "insert-image",
243 "insert-link",
244 "insert-object",
245 "insert-text",
246 "list-add",
247 "list-remove",
248 "mail-forward",
249 "mail-mark-important",
250 "mail-mark-junk",
251 "mail-mark-notjunk",
252 "mail-mark-read",
253 "mail-mark-unread",
254 "mail-message-new",
255 "mail-reply-all",
256 "mail-reply-sender",
257 "mail-send-receive",
258 "media-eject",
259 "media-playback-pause",
260 "media-playback-start",
261 "media-playback-stop",
262 "media-record",
263 "media-seek-backward",
264 "media-seek-forward",
265 "media-skip-backward",
266 "media-skip-forward",
267 "system-lock-screen",
268 "system-log-out",
269 "system-run",
270 "system-search",
271 "system-search",
272 "tools-check-spelling",
273 "view-fullscreen",
274 "view-refresh",
275 "view-sort-ascending",
276 "view-sort-descending",
277 "window-close",
278 "window-new",
279 "zoom-best-fit",
280 "zoom-in",
281 "zoom-original",
282 "zoom-out",
283 "process-working",
284 "accessories-calculator",
285 "accessories-character-map",
286 "accessories-dictionary",
287 "accessories-text-editor",
288 "help-browser",
289 "multimedia-volume-control",
290#if 0
291 "preferences-desktop-accessibility",
292 "preferences-desktop-font",
293 "preferences-desktop-keyboard",
294 "preferences-desktop-locale",
295 "preferences-desktop-multimedia",
296 "preferences-desktop-screensaver",
297 "preferences-desktop-theme",
298 "preferences-desktop-wallpaper",
299 "system-file-manager",
300 "system-software-update",
301 "utilities-terminal",
302 "applications-accessories",
303 "applications-development",
304 "applications-games",
305 "applications-graphics",
306 "applications-internet",
307 "applications-multimedia",
308 "applications-office",
309 "applications-other",
310 "applications-system",
311 "applications-utilities",
312 "preferences-desktop",
313 "preferences-desktop-accessibility",
314 "preferences-desktop-peripherals",
315 "preferences-desktop-personal",
316 "preferences-other",
317 "preferences-system",
318 "preferences-system-network",
319 "system-help",
320 "audio-card",
321 "audio-input-microphone",
322 "battery",
323 "camera-photo",
324 "camera-video",
325 "computer",
326 "drive-cdrom",
327 "drive-harddisk",
328 "drive-removable-media",
329 "input-gaming",
330 "input-keyboard",
331 "input-mouse",
332 "media-cdrom",
333 "media-floppy",
334 "multimedia-player",
335 "multimedia-player",
336 "network-wired",
337 "network-wireless",
338 "printer",
339 "emblem-default",
340 "emblem-documents",
341 "emblem-downloads",
342 "emblem-favorite",
343 "emblem-important",
344 "emblem-mail",
345 "emblem-photos",
346 "emblem-readonly",
347 "emblem-shared",
348 "emblem-symbolic-link",
349 "emblem-synchronized",
350 "emblem-system",
351 "emblem-unreadable",
352 "face-angel",
353 "face-crying",
354 "face-devil-grin",
355 "face-devil-sad",
356 "face-glasses",
357 "face-kiss",
358 "face-monkey",
359 "face-plain",
360 "face-sad",
361 "face-smile",
362 "face-smile-big",
363 "face-smirk",
364 "face-surprise",
365 "face-wink",
366 "application-x-executable",
367 "audio-x-generic",
368 "font-x-generic",
369 "image-x-generic",
370 "package-x-generic",
371 "text-html",
372 "text-x-generic",
373 "text-x-generic-template",
374 "text-x-script",
375 "video-x-generic",
376 "x-office-address-book",
377 "x-office-calendar",
378 "x-office-document",
379 "x-office-presentation",
380 "x-office-spreadsheet",
381 "folder",
382 "folder-remote",
383 "network-server",
384 "network-workgroup",
385 "start-here",
386 "user-desktop",
387 "user-home",
388 "user-trash",
389 "appointment-missed",
390 "appointment-soon",
391 "audio-volume-high",
392 "audio-volume-low",
393 "audio-volume-medium",
394 "audio-volume-muted",
395 "battery-caution",
396 "battery-low",
397 "dialog-error",
398 "dialog-information",
399 "dialog-password",
400 "dialog-question",
401 "dialog-warning",
402 "folder-drag-accept",
403 "folder-open",
404 "folder-visiting",
405 "image-loading",
406 "image-missing",
407 "mail-attachment",
408 "mail-unread",
409 "mail-read",
410 "mail-replied",
411 "mail-signed",
412 "mail-signed-verified",
413 "media-playlist-repeat",
414 "media-playlist-shuffle",
415 "network-error",
416 "network-idle",
417 "network-offline",
418 "network-receive",
419 "network-transmit",
420 "network-transmit-receive",
421 "printer-error",
422 "printer-printing",
423 "software-update-available",
424 "software-update-urgent",
425 "sync-error",
426 "sync-synchronizing",
427 "task-due",
428 "task-passed-due",
429 "user-away",
430 "user-idle",
431 "user-offline",
432 "user-online",
433 "user-trash-full",
434 "weather-clear",
435 "weather-clear-night",
436 "weather-few-clouds",
437 "weather-few-clouds-night",
438 "weather-fog",
439 "weather-overcast",
440 "weather-severe-alert",
441 "weather-showers",
442 "weather-showers-scattered",
443 "weather-snow",
444 "weather-storm",
445#endif
446 NULL
447};
448
449int
450ef_cb_efreet_icon_match(void)
451{
452 int i, ret = 1;
453 Eina_Hash *icon_hash;
454 Efreet_Icon_Theme *theme;
455
456 theme = efreet_icon_theme_find(THEME);
457 icon_hash = eina_hash_string_superfast_new(free);
458
459 ef_icons_find(theme, icon_hash);
460
461 double start = ecore_time_get();
462 for (i = 0; system_icons[i]; i++)
463 {
464 const char *path;
465 char *p, *s;
466
467 path = efreet_icon_path_find(THEME, system_icons[i], SIZE);
468
469 if (!path)
470 {
471#if 1
472 if (eina_hash_find(icon_hash, system_icons[i]))
473 {
474 printf("NOT FOUND %s\n", system_icons[i]);
475 ret = 0;
476 }
477#endif
478 continue;
479 }
480 else if (!eina_hash_find(icon_hash, system_icons[i]))
481 {
482 printf("Found icon not in hash: %s\n", system_icons[i]);
483 }
484
485 p = strdup(path);
486 s = strrchr(p, '.');
487 if (s) *s = '\0';
488 s = strrchr(p, '/');
489 if (s) s++;
490
491 if (s && strcmp(s, system_icons[i]))
492 {
493 printf("Name mismatch name (%s) vs ef (%s)\n", system_icons[i], s);
494 ret = 0;
495 }
496 free(p);
497 }
498 printf("Time: %f\n", (ecore_time_get() - start));
499 eina_hash_free(icon_hash);
500
501 start = ecore_time_get();
502 for (i = 0; system_icons[i]; i++)
503 {
504 const char *path;
505 char *p, *s;
506
507 path = efreet_icon_path_find(THEME, system_icons[i], SIZE);
508
509 if (!path) continue;
510 p = strdup(path);
511
512 s = strrchr(p, '.');
513 if (s) *s = '\0';
514 s = strrchr(p, '/');
515 if (s) s++;
516
517 if (s && strcmp(s, system_icons[i]))
518 {
519 printf("Name mismatch name (%s) vs ef (%s)\n", system_icons[i], s);
520 ret = 0;
521 }
522 free(p);
523 }
524 printf("Time: %f\n", (ecore_time_get() - start));
525
526 return ret;
527}
528
529static void
530ef_icons_find(Efreet_Icon_Theme *theme, Eina_Hash *icons)
531{
532 Eina_List *l, *ll;
533 char path[PATH_MAX];
534 const char *theme_path;
535
536 if (!theme || !icons) return;
537
538 EINA_LIST_FOREACH(theme->paths, l, theme_path)
539 {
540 Efreet_Icon_Theme_Directory *dir;
541
542 EINA_LIST_FOREACH(theme->directories, ll, dir)
543 {
544 snprintf(path, sizeof(path), "%s/%s/", theme_path, dir->name);
545 ef_read_dir(path, icons);
546 }
547 }
548
549 if (theme->inherits)
550 {
551 Efreet_Icon_Theme *parent_theme;
552 char *parent;
553
554 EINA_LIST_FOREACH(theme->inherits, l, parent)
555 {
556 parent_theme = efreet_icon_theme_find(parent);
557 if (parent_theme)
558 ef_icons_find(parent_theme, icons);
559 }
560 }
561 else if (strcmp(theme->name.internal, "hicolor"))
562 {
563 Efreet_Icon_Theme *parent_theme;
564
565 parent_theme = efreet_icon_theme_find("hicolor");
566 if (parent_theme)
567 ef_icons_find(parent_theme, icons);
568 }
569
570 ef_read_dir("/usr/share/pixmaps", icons);
571}
572
573static void
574ef_read_dir(const char *dir, Eina_Hash *icons)
575{
576 Eina_List *files;
577 char *file;
578
579 if (!dir || !icons) return;
580
581 files = ecore_file_ls(dir);
582 if (!files) return;
583
584 while ((file = eina_list_data_get(files)))
585 {
586 char *p;
587
588 files = eina_list_remove_list(files, files);
589 p = strrchr(file, '.');
590 if (!p)
591 {
592 FREE(file);
593 continue;
594 }
595
596 if (!strcmp(p, ".png") || !strcmp(p, ".xpm"))
597 {
598 *p = '\0';
599
600 eina_hash_add(icons, file, strdup(file));
601 }
602
603 FREE(file);
604 }
605}