efl

Форк
0
/
ef_icon_theme.c 
610 строк · 13.7 Кб
1
#ifdef HAVE_CONFIG_H
2
#include "config.h"
3
#endif
4

5
#include <stdlib.h>
6
#include <stdio.h>
7
#include <string.h>
8
#include <limits.h>
9

10
#ifdef _WIN32
11
# include <evil_private.h> /* unsetenv */
12
#endif
13

14
#include <Ecore.h>
15
#include <Ecore_File.h>
16
#include <Efreet.h>
17

18
#define SIZE 128
19
#define THEME "Tango"
20
#define FREE(x) do { free(x); x = NULL; } while (0);
21

22
static Eina_Bool _hash_keys(Eina_Hash *hash, const char *key, void *list);
23
static void ef_icon_theme_themes_find(const char *search_dir,
24
                                      Eina_Hash *themes);
25
static void ef_icons_find(Efreet_Icon_Theme *theme, Eina_Hash *icons);
26
static void ef_read_dir(const char *dir, Eina_Hash *icons);
27

28
int
29
ef_cb_efreet_icon_theme(void)
30
{
31
   int ret = 1;
32
   const char *tmp;
33

34
   unsetenv("XDG_DATA_HOME");
35
   efreet_shutdown();
36
   putenv("HOME=/var/tmp");
37
   efreet_init();
38

39
   tmp = efreet_icon_user_dir_get();
40
   if (strcmp(tmp, "/var/tmp/.local/share/icons"))
41
     {
42
        printf("efreet_icon_user_dir_get() returned incorrect "
43
               "value (%s) on HOME=/var/tmp\n", tmp);
44
        ret = 0;
45
     }
46

47
   efreet_shutdown();
48
   unsetenv("HOME");
49
#ifdef _WIN32
50
   unsetenv("USERPROFILE");
51
#endif
52
   efreet_init();
53

54
   tmp = efreet_icon_user_dir_get();
55
   if (strcmp(tmp, "/tmp/.local/share/icons"))
56
     {
57
        printf("efreet_icon_user_dir_get() returned incorrect "
58
               "value (%s) on HOME=\n", tmp);
59
        ret = 0;
60
     }
61

62
   return ret;
63
}
64

65
static Eina_Bool
66
_hash_keys(Eina_Hash *hash EINA_UNUSED, const char *key, void *list)
67
{
68
   Eina_List **l = list;
69

70
   *l = eina_list_append(*l, key);
71
   return EINA_TRUE;
72
}
73

74
int
75
ef_cb_efreet_icon_theme_list(void)
76
{
77
   int ret = 1;
78
   Eina_List *themes;
79
   Eina_List *icon_dirs;
80
   Eina_List *l;
81
   Eina_Hash *dirs;
82
   Eina_Iterator *it;
83
   Efreet_Icon_Theme *theme;
84
   const char *dir;
85
   char buf[PATH_MAX];
86

87
   dirs = eina_hash_string_superfast_new(free);
88

89
   icon_dirs = efreet_data_dirs_get();
90

91
   ef_icon_theme_themes_find(efreet_icon_user_dir_get(), dirs);
92
   EINA_LIST_FOREACH(icon_dirs, l, dir)
93
     {
94
        snprintf(buf, sizeof(buf), "%s/icons", dir);
95
        ef_icon_theme_themes_find(buf, dirs);
96
     }
97
   EINA_LIST_FOREACH(icon_dirs, l, dir)
98
     {
99
        snprintf(buf, sizeof(buf), "%s/pixmaps", dir);
100
        ef_icon_theme_themes_find(buf, dirs);
101
     }
102
   ef_icon_theme_themes_find("/usr/share/pixmaps", dirs);
103

104
   themes = efreet_icon_theme_list_get();
105
   EINA_LIST_FOREACH(themes, l, theme)
106
     {
107
        if ((eina_hash_find(dirs, theme->name.internal)))
108
          eina_hash_del(dirs, theme->name.internal, NULL);
109
        else
110
          {
111
             printf("efreet_icon_theme_list_get() returned %s which we didn't "
112
                    "see when scanning the directories.\n", theme->name.internal);
113
             ret = 0;
114
          }
115
     }
116
   while (themes)
117
     {
118
        themes = eina_list_remove_list(themes, themes);
119
     }
120

121
   themes = NULL;
122
   it = eina_hash_iterator_key_new(dirs);
123
   eina_iterator_foreach(it, EINA_EACH_CB(_hash_keys), &themes);
124
   eina_iterator_free(it);
125

126
   if (eina_list_count(themes) > 0)
127
     {
128
        printf("efreet_icon_theme_list_get() missed: ");
129
        EINA_LIST_FOREACH(themes, l, dir)
130
          printf("%s ", dir);
131
        printf("\n");
132

133
        ret = 0;
134
     }
135
   while (themes)
136
     {
137
        themes = eina_list_remove_list(themes, themes);
138
     }
139
   eina_hash_free(dirs);
140

141
   return ret;
142
}
143

144
static void
145
ef_icon_theme_themes_find(const char *search_dir, Eina_Hash *themes)
146
{
147
   Eina_List *dirs;
148
   char *dir;
149

150
   if (!search_dir || !themes) return;
151

152
   dirs = ecore_file_ls(search_dir);
153
   if (!dirs) return;
154

155
   while ((dir = eina_list_data_get(dirs)))
156
     {
157
        char p[PATH_MAX];
158

159
        dirs = eina_list_remove_list(dirs, dirs);
160
        /* if we've already added the theme we're done */
161
        if (eina_hash_find(themes, dir))
162
          {
163
             free(dir);
164
             continue;
165
          }
166

167
        /* if the index.theme file exists we open it and look for the hidden
168
         * flag. */
169
        snprintf(p, sizeof(p), "%s/%s/index.theme", search_dir, dir);
170
        if (ecore_file_exists(p))
171
          {
172
             Efreet_Ini *ini;
173
             char *d;
174
             int skip = 0;
175

176
             ini = efreet_ini_new(p);
177
             efreet_ini_section_set(ini, "Icon Theme");
178

179
             //if (efreet_ini_boolean_get(ini, "Hidden")) skip = 1;
180
             if (!efreet_ini_localestring_get(ini, "Name")) skip = 1;
181
             efreet_ini_free(ini);
182

183
             if (!skip)
184
               {
185
                  d = strdup(dir);
186
                  eina_hash_add(themes, dir, d);
187
               }
188
          }
189
        free(dir);
190
     }
191
}
192

193
const char *system_icons[] =
194
{
195
   "address-book-new",
196
   "application-exit",
197
   "appointment-new",
198
   "contact-new",
199
   "dialog-apply",
200
   "dialog-cancel",
201
   "dialog-close",
202
   "dialog-ok",
203
   "document-new",
204
   "document-open",
205
   "document-open-recent",
206
   "document-page-setup",
207
   "document-print",
208
   "document-print-preview",
209
   "document-properties",
210
   "document-revert",
211
   "document-save",
212
   "document-save-as",
213
   "edit-copy",
214
   "edit-cut",
215
   "edit-delete",
216
   "edit-find",
217
   "edit-find-replace",
218
   "edit-paste",
219
   "edit-redo",
220
   "edit-select-all",
221
   "edit-undo",
222
   "format-indent-less",
223
   "format-indent-more",
224
   "format-justify-center",
225
   "format-justify-fill",
226
   "format-justify-left",
227
   "format-justify-right",
228
   "format-text-direction-ltr",
229
   "format-text-direction-rtl",
230
   "format-text-bold",
231
   "format-text-italic",
232
   "format-text-underline",
233
   "format-text-strikethrough",
234
   "go-bottom",
235
   "go-down",
236
   "go-first",
237
   "go-home",
238
   "go-jump",
239
   "go-last",
240
   "go-next",
241
   "go-previous",
242
   "go-top",
243
   "go-up",
244
   "help-about",
245
   "help-contents",
246
   "help-faq",
247
   "insert-image",
248
   "insert-link",
249
   "insert-object",
250
   "insert-text",
251
   "list-add",
252
   "list-remove",
253
   "mail-forward",
254
   "mail-mark-important",
255
   "mail-mark-junk",
256
   "mail-mark-notjunk",
257
   "mail-mark-read",
258
   "mail-mark-unread",
259
   "mail-message-new",
260
   "mail-reply-all",
261
   "mail-reply-sender",
262
   "mail-send-receive",
263
   "media-eject",
264
   "media-playback-pause",
265
   "media-playback-start",
266
   "media-playback-stop",
267
   "media-record",
268
   "media-seek-backward",
269
   "media-seek-forward",
270
   "media-skip-backward",
271
   "media-skip-forward",
272
   "system-lock-screen",
273
   "system-log-out",
274
   "system-run",
275
   "system-search",
276
   "system-search",
277
   "tools-check-spelling",
278
   "view-fullscreen",
279
   "view-refresh",
280
   "view-sort-ascending",
281
   "view-sort-descending",
282
   "window-close",
283
   "window-new",
284
   "zoom-best-fit",
285
   "zoom-in",
286
   "zoom-original",
287
   "zoom-out",
288
   "process-working",
289
   "accessories-calculator",
290
   "accessories-character-map",
291
   "accessories-dictionary",
292
   "accessories-text-editor",
293
   "help-browser",
294
   "multimedia-volume-control",
295
#if 0
296
   "preferences-desktop-accessibility",
297
   "preferences-desktop-font",
298
   "preferences-desktop-keyboard",
299
   "preferences-desktop-locale",
300
   "preferences-desktop-multimedia",
301
   "preferences-desktop-screensaver",
302
   "preferences-desktop-theme",
303
   "preferences-desktop-wallpaper",
304
   "system-file-manager",
305
   "system-software-update",
306
   "utilities-terminal",
307
   "applications-accessories",
308
   "applications-development",
309
   "applications-games",
310
   "applications-graphics",
311
   "applications-internet",
312
   "applications-multimedia",
313
   "applications-office",
314
   "applications-other",
315
   "applications-system",
316
   "applications-utilities",
317
   "preferences-desktop",
318
   "preferences-desktop-accessibility",
319
   "preferences-desktop-peripherals",
320
   "preferences-desktop-personal",
321
   "preferences-other",
322
   "preferences-system",
323
   "preferences-system-network",
324
   "system-help",
325
   "audio-card",
326
   "audio-input-microphone",
327
   "battery",
328
   "camera-photo",
329
   "camera-video",
330
   "computer",
331
   "drive-cdrom",
332
   "drive-harddisk",
333
   "drive-removable-media",
334
   "input-gaming",
335
   "input-keyboard",
336
   "input-mouse",
337
   "media-cdrom",
338
   "media-floppy",
339
   "multimedia-player",
340
   "multimedia-player",
341
   "network-wired",
342
   "network-wireless",
343
   "printer",
344
   "emblem-default",
345
   "emblem-documents",
346
   "emblem-downloads",
347
   "emblem-favorite",
348
   "emblem-important",
349
   "emblem-mail",
350
   "emblem-photos",
351
   "emblem-readonly",
352
   "emblem-shared",
353
   "emblem-symbolic-link",
354
   "emblem-synchronized",
355
   "emblem-system",
356
   "emblem-unreadable",
357
   "face-angel",
358
   "face-crying",
359
   "face-devil-grin",
360
   "face-devil-sad",
361
   "face-glasses",
362
   "face-kiss",
363
   "face-monkey",
364
   "face-plain",
365
   "face-sad",
366
   "face-smile",
367
   "face-smile-big",
368
   "face-smirk",
369
   "face-surprise",
370
   "face-wink",
371
   "application-x-executable",
372
   "audio-x-generic",
373
   "font-x-generic",
374
   "image-x-generic",
375
   "package-x-generic",
376
   "text-html",
377
   "text-x-generic",
378
   "text-x-generic-template",
379
   "text-x-script",
380
   "video-x-generic",
381
   "x-office-address-book",
382
   "x-office-calendar",
383
   "x-office-document",
384
   "x-office-presentation",
385
   "x-office-spreadsheet",
386
   "folder",
387
   "folder-remote",
388
   "network-server",
389
   "network-workgroup",
390
   "start-here",
391
   "user-desktop",
392
   "user-home",
393
   "user-trash",
394
   "appointment-missed",
395
   "appointment-soon",
396
   "audio-volume-high",
397
   "audio-volume-low",
398
   "audio-volume-medium",
399
   "audio-volume-muted",
400
   "battery-caution",
401
   "battery-low",
402
   "dialog-error",
403
   "dialog-information",
404
   "dialog-password",
405
   "dialog-question",
406
   "dialog-warning",
407
   "folder-drag-accept",
408
   "folder-open",
409
   "folder-visiting",
410
   "image-loading",
411
   "image-missing",
412
   "mail-attachment",
413
   "mail-unread",
414
   "mail-read",
415
   "mail-replied",
416
   "mail-signed",
417
   "mail-signed-verified",
418
   "media-playlist-repeat",
419
   "media-playlist-shuffle",
420
   "network-error",
421
   "network-idle",
422
   "network-offline",
423
   "network-receive",
424
   "network-transmit",
425
   "network-transmit-receive",
426
   "printer-error",
427
   "printer-printing",
428
   "software-update-available",
429
   "software-update-urgent",
430
   "sync-error",
431
   "sync-synchronizing",
432
   "task-due",
433
   "task-passed-due",
434
   "user-away",
435
   "user-idle",
436
   "user-offline",
437
   "user-online",
438
   "user-trash-full",
439
   "weather-clear",
440
   "weather-clear-night",
441
   "weather-few-clouds",
442
   "weather-few-clouds-night",
443
   "weather-fog",
444
   "weather-overcast",
445
   "weather-severe-alert",
446
   "weather-showers",
447
   "weather-showers-scattered",
448
   "weather-snow",
449
   "weather-storm",
450
#endif
451
   NULL
452
};
453

454
int
455
ef_cb_efreet_icon_match(void)
456
{
457
   int i, ret = 1;
458
   Eina_Hash *icon_hash;
459
   Efreet_Icon_Theme *theme;
460

461
   theme = efreet_icon_theme_find(THEME);
462
   icon_hash = eina_hash_string_superfast_new(free);
463

464
   ef_icons_find(theme, icon_hash);
465

466
   double start = ecore_time_get();
467
   for (i = 0; system_icons[i]; i++)
468
     {
469
        const char *path;
470
        char *p, *s;
471

472
        path = efreet_icon_path_find(THEME, system_icons[i], SIZE);
473

474
        if (!path)
475
          {
476
#if 1
477
             if (eina_hash_find(icon_hash, system_icons[i]))
478
               {
479
                  printf("NOT FOUND %s\n", system_icons[i]);
480
                  ret = 0;
481
               }
482
#endif
483
             continue;
484
          }
485
        else if (!eina_hash_find(icon_hash, system_icons[i]))
486
          {
487
             printf("Found icon not in hash: %s\n", system_icons[i]);
488
          }
489

490
        p = strdup(path);
491
        s = strrchr(p, '.');
492
        if (s) *s = '\0';
493
        s = strrchr(p, '/');
494
        if (s) s++;
495

496
        if (s && strcmp(s, system_icons[i]))
497
          {
498
             printf("Name mismatch name (%s) vs ef (%s)\n", system_icons[i], s);
499
             ret = 0;
500
          }
501
        free(p);
502
     }
503
   printf("Time: %f\n", (ecore_time_get() - start));
504
   eina_hash_free(icon_hash);
505

506
   start = ecore_time_get();
507
   for (i = 0; system_icons[i]; i++)
508
     {
509
        const char *path;
510
        char *p, *s;
511

512
        path = efreet_icon_path_find(THEME, system_icons[i], SIZE);
513

514
        if (!path) continue;
515
        p = strdup(path);
516

517
        s = strrchr(p, '.');
518
        if (s) *s = '\0';
519
        s = strrchr(p, '/');
520
        if (s) s++;
521

522
        if (s && strcmp(s, system_icons[i]))
523
          {
524
             printf("Name mismatch name (%s) vs ef (%s)\n", system_icons[i], s);
525
             ret = 0;
526
          }
527
        free(p);
528
     }
529
   printf("Time: %f\n", (ecore_time_get() - start));
530

531
   return ret;
532
}
533

534
static void
535
ef_icons_find(Efreet_Icon_Theme *theme, Eina_Hash *icons)
536
{
537
   Eina_List *l, *ll;
538
   char path[PATH_MAX];
539
   const char *theme_path;
540

541
   if (!theme || !icons) return;
542

543
   EINA_LIST_FOREACH(theme->paths, l, theme_path)
544
     {
545
        Efreet_Icon_Theme_Directory *dir;
546

547
        EINA_LIST_FOREACH(theme->directories, ll, dir)
548
          {
549
             snprintf(path, sizeof(path), "%s/%s/", theme_path, dir->name);
550
             ef_read_dir(path, icons);
551
          }
552
     }
553

554
   if (theme->inherits)
555
     {
556
        Efreet_Icon_Theme *parent_theme;
557
        char *parent;
558

559
        EINA_LIST_FOREACH(theme->inherits, l, parent)
560
          {
561
             parent_theme = efreet_icon_theme_find(parent);
562
             if (parent_theme)
563
               ef_icons_find(parent_theme, icons);
564
          }
565
     }
566
   else if (strcmp(theme->name.internal, "hicolor"))
567
     {
568
        Efreet_Icon_Theme *parent_theme;
569

570
        parent_theme = efreet_icon_theme_find("hicolor");
571
        if (parent_theme)
572
          ef_icons_find(parent_theme, icons);
573
     }
574

575
   ef_read_dir("/usr/share/pixmaps", icons);
576
}
577

578
static void
579
ef_read_dir(const char *dir, Eina_Hash *icons)
580
{
581
   Eina_List *files;
582
   char *file;
583

584
   if (!dir || !icons) return;
585

586
   files = ecore_file_ls(dir);
587
   if (!files) return;
588

589
   while ((file = eina_list_data_get(files)))
590
     {
591
        char *p;
592

593
        files = eina_list_remove_list(files, files);
594
        p = strrchr(file, '.');
595
        if (!p)
596
          {
597
             FREE(file);
598
             continue;
599
          }
600

601
        if (!strcmp(p, ".png") || !strcmp(p, ".xpm"))
602
          {
603
             *p = '\0';
604

605
             eina_hash_add(icons, file, strdup(file));
606
          }
607

608
        FREE(file);
609
     }
610
}
611

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.