13
13
14
14
struct icon_theme * icon_themes = NULL ;
15
15
int icon_themes_count = 0 ;
16
- int default_theme_index = -1 ;
16
+ int * default_themes_index = NULL ;
17
+ int default_themes_count = 0 ;
17
18
18
19
static bool is_readable_file (const char * filename )
19
20
{
@@ -29,13 +30,6 @@ int get_icon_theme(char *name) {
29
30
return -1 ;
30
31
}
31
32
32
- void print_all_dir_counts (char * theme_name , char * msg ) {
33
- printf ("%s: %s\n" , theme_name , msg );
34
- for (int i = 0 ; i < icon_themes_count ; i ++ ) {
35
- printf ("Dir count %s: %i\n" , icon_themes [i ].name , icon_themes [i ].dirs_count );
36
- }
37
- }
38
-
39
33
/**
40
34
* Load a theme from a directory. Don't call this function if the theme is
41
35
* already loaded. It also loads the inherited themes. If there are no
@@ -50,7 +44,7 @@ void print_all_dir_counts(char *theme_name, char *msg) {
50
44
* @retval -1 means no index was found
51
45
*/
52
46
int load_icon_theme_from_dir (const char * icon_dir , const char * subdir_theme ) {
53
- printf ("Loading theme %s/%s\n" , icon_dir , subdir_theme );
47
+ LOG_D ("Loading theme %s/%s\n" , icon_dir , subdir_theme );
54
48
char * theme_index_dir = g_build_filename (icon_dir , subdir_theme , "index.theme" , NULL );
55
49
FILE * theme_index = fopen (theme_index_dir , "r" );
56
50
g_free (theme_index_dir );
@@ -76,7 +70,6 @@ int load_icon_theme_from_dir(const char *icon_dir, const char *subdir_theme) {
76
70
77
71
// load theme directories
78
72
icon_themes [index ].dirs_count = ini -> section_count - 1 ;
79
- print_all_dir_counts (icon_themes [index ].name , "First" );
80
73
icon_themes [index ].dirs = calloc (icon_themes [index ].dirs_count , sizeof (struct icon_theme_dir ));
81
74
82
75
for (int i = 0 ; i < icon_themes [index ].dirs_count ; i ++ ) {
@@ -129,15 +122,14 @@ int load_icon_theme_from_dir(const char *icon_dir, const char *subdir_theme) {
129
122
}
130
123
}
131
124
}
132
- print_all_dir_counts (icon_themes [index ].name , "Second" );
133
125
134
126
135
127
// load inherited themes
136
128
if (!STR_EQ (icon_themes [index ].name , "Hicolor" ))
137
129
{
138
130
char * * inherits = string_to_array (get_value (ini , "Icon Theme" , "Inherits" ), "," );
139
131
icon_themes [index ].inherits_count = string_array_length (inherits );
140
- printf ("Theme has %i inherited themes\n" , icon_themes [index ].inherits_count );
132
+ LOG_D ("Theme has %i inherited themes\n" , icon_themes [index ].inherits_count );
141
133
if (icon_themes [index ].inherits_count <= 0 ) {
142
134
// set fallback theme to hicolor if there are no inherits
143
135
g_strfreev (inherits );
@@ -150,15 +142,13 @@ int load_icon_theme_from_dir(const char *icon_dir, const char *subdir_theme) {
150
142
icon_themes [index ].inherits_index = calloc (icon_themes [index ].inherits_count , sizeof (int ));
151
143
152
144
for (int i = 0 ; inherits [i ] != NULL ; i ++ ) {
153
- printf ("inherits: %s\n" , inherits [i ]);
145
+ LOG_D ("inherits: %s\n" , inherits [i ]);
154
146
icon_themes [index ].inherits_index [i ] = get_icon_theme (inherits [i ]);
155
147
if (icon_themes [index ].inherits_index [i ] == -1 ) {
156
- printf ("Loading inherited theme\n" );
157
- print_all_dir_counts (icon_themes [index ].name , "Third" );
148
+ LOG_D ("Loading inherited theme\n" );
158
149
// FIXME don't use a pointer to the theme,
159
150
// since it may be invalidated after realloc. Use an index instead
160
151
icon_themes [index ].inherits_index [i ] = load_icon_theme (inherits [i ]);
161
- print_all_dir_counts ("unknown" , "Fourth" );
162
152
}
163
153
}
164
154
g_strfreev (inherits );
@@ -168,10 +158,6 @@ int load_icon_theme_from_dir(const char *icon_dir, const char *subdir_theme) {
168
158
169
159
finish_ini (ini );
170
160
free (ini );
171
-
172
- print_all_dir_counts ("unknown" , "End" );
173
- printf ("Othere dirs count %i\n" , icon_themes [0 ].dirs_count );
174
- printf ("index %i\n" , index );
175
161
return index ;
176
162
}
177
163
@@ -215,7 +201,7 @@ void get_theme_path() {
215
201
add_paths_from_env (theme_path , "XDG_DATA_DIRS" , "icons" , "/usr/local/share/:/usr/share/" );
216
202
g_ptr_array_add (theme_path , g_strdup ("/usr/share/pixmaps" ));
217
203
for (int i = 0 ; i < theme_path -> len ; i ++ ) {
218
- printf ("Theme locations: %s\n" , (char * )theme_path -> pdata [i ]);
204
+ LOG_D ("Theme locations: %s\n" , (char * )theme_path -> pdata [i ]);
219
205
}
220
206
}
221
207
@@ -244,7 +230,6 @@ void finish_icon_theme_dir(struct icon_theme_dir *dir) {
244
230
void finish_icon_theme (struct icon_theme * theme ) {
245
231
if (!theme )
246
232
return ;
247
- printf ("Finishing %i dirs\n" , theme -> dirs_count );
248
233
for (int i = 0 ; i < theme -> dirs_count ; i ++ ) {
249
234
finish_icon_theme_dir (& theme -> dirs [i ]);
250
235
}
@@ -256,9 +241,8 @@ void finish_icon_theme(struct icon_theme *theme) {
256
241
}
257
242
258
243
void free_all_themes () {
259
- printf ("Finishing %i themes\n" , icon_themes_count );
244
+ LOG_D ("Finishing %i themes\n" , icon_themes_count );
260
245
for (int i = 0 ; i < icon_themes_count ; i ++ ) {
261
- printf ("Theme dirs %i\n" , icon_themes [i ].dirs_count );
262
246
finish_icon_theme (& icon_themes [i ]);
263
247
}
264
248
free (icon_themes );
@@ -269,7 +253,7 @@ void free_all_themes() {
269
253
}
270
254
271
255
// see icon-lookup.h
272
- void set_default_theme (int theme_index ) {
256
+ void add_default_theme (int theme_index ) {
273
257
if (theme_index < 0 ) {
274
258
LOG_W ("Invalid theme index: %i" , theme_index );
275
259
return ;
@@ -279,13 +263,16 @@ void set_default_theme(int theme_index) {
279
263
theme_index );
280
264
return ;
281
265
}
282
- default_theme_index = theme_index ;
266
+ default_themes_count ++ ;
267
+ default_themes_index = realloc (default_themes_index ,
268
+ default_themes_count * sizeof (int ));
269
+ default_themes_index [default_themes_count - 1 ] = theme_index ;
283
270
}
284
271
285
272
// see icon-lookup.h
286
273
char * find_icon_in_theme (const char * name , int theme_index , int size ) {
287
274
struct icon_theme * theme = & icon_themes [theme_index ];
288
- printf ("Finding icon %s in theme %s\n" , name , theme -> name );
275
+ LOG_D ("Finding icon %s in theme %s\n" , name , theme -> name );
289
276
for (int i = 0 ; i < theme -> dirs_count ; i ++ ) {
290
277
bool match_size = false;
291
278
struct icon_theme_dir dir = theme -> dirs [i ];
@@ -362,9 +349,16 @@ char *find_icon_path(const char *name, int size) {
362
349
return NULL ;
363
350
}
364
351
365
- if (default_theme_index == -1 ) {
366
- printf ("No icon theme has been set.\n" );
352
+ if (! default_themes_index ) {
353
+ LOG_W ("No icon theme has been set.\n" );
367
354
return NULL ;
368
355
}
369
- return find_icon_in_theme_with_inherit (name , default_theme_index , size );
356
+ for (int i = 0 ; i < default_themes_count ; i ++ ) {
357
+ char * icon = find_icon_in_theme_with_inherit (name ,
358
+ default_themes_index [i ], size );
359
+ if (icon )
360
+ return icon ;
361
+
362
+ }
363
+ return NULL ;
370
364
}
0 commit comments