1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* icon-themes.c
* Copyright (C) 2015 Benoit Touchette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdlib.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "icon-themes.h"
#include "gimp-intl.h"
static void icons_apply_theme (Gimp *gimp,
const gchar *icon_theme_name);
static void icons_list_icons_foreach (gpointer key,
gpointer value,
gpointer data);
static gint icons_name_compare (const void *p1,
const void *p2);
static void icons_theme_change_notify (GimpGuiConfig *config,
GParamSpec *pspec,
Gimp *gimp);
static GHashTable *icon_themes_hash = NULL;
void
icon_themes_init (Gimp *gimp)
{
GimpGuiConfig *config;
g_return_if_fail (GIMP_IS_GIMP (gimp));
config = GIMP_GUI_CONFIG (gimp->config);
icon_themes_hash = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
if (config->icon_theme_path)
{
GList *path;
GList *list;
path = gimp_config_path_expand_to_files (config->icon_theme_path, NULL);
for (list = path; list; list = g_list_next (list))
{
GFile *dir = list->data;
GFileEnumerator *enumerator;
enumerator =
g_file_enumerate_children (dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
if (enumerator)
{
GFileInfo *info;
while ((info = g_file_enumerator_next_file (enumerator,
NULL, NULL)))
{
if (! g_file_info_get_is_hidden (info) &&
g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{
GFile *file;
GFile *index_theme;
file = g_file_enumerator_get_child (enumerator, info);
/* make sure there is a hicolor/index.theme file */
index_theme = g_file_get_child (file, "index.theme");
if (g_file_query_exists (index_theme, NULL))
{
const gchar *name;
gchar *basename;
name = gimp_file_get_utf8_name (file);
basename = g_path_get_basename (name);
if (strcmp ("hicolor", basename))
{
if (gimp->be_verbose)
g_print ("Adding icon theme '%s' (%s)\n",
basename, name);
g_hash_table_insert (icon_themes_hash, basename,
g_object_ref (file));
}
else
{
g_free (basename);
}
}
g_object_unref (index_theme);
g_object_unref (file);
}
g_object_unref (info);
}
g_object_unref (enumerator);
}
}
g_list_free_full (path, (GDestroyNotify) g_object_unref);
}
g_signal_connect (config, "notify::icon-theme",
G_CALLBACK (icons_theme_change_notify),
gimp);
icons_theme_change_notify (config, NULL, gimp);
}
void
icon_themes_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (icon_themes_hash)
{
g_signal_handlers_disconnect_by_func (gimp->config,
icons_theme_change_notify,
gimp);
g_hash_table_destroy (icon_themes_hash);
icon_themes_hash = NULL;
}
}
gchar **
icon_themes_list_themes (Gimp *gimp,
gint *n_icon_themes)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (n_icon_themes != NULL, NULL);
*n_icon_themes = g_hash_table_size (icon_themes_hash);
if (*n_icon_themes > 0)
{
gchar **icon_themes;
gchar **index;
icon_themes = g_new0 (gchar *, *n_icon_themes + 1);
index = icon_themes;
g_hash_table_foreach (icon_themes_hash, icons_list_icons_foreach, &index);
qsort (icon_themes, *n_icon_themes, sizeof (gchar *), icons_name_compare);
return icon_themes;
}
return NULL;
}
GFile *
icon_themes_get_theme_dir (Gimp *gimp,
const gchar *icon_theme_name)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
if (! icon_theme_name)
icon_theme_name = GIMP_CONFIG_DEFAULT_ICON_THEME;
return g_hash_table_lookup (icon_themes_hash, icon_theme_name);
}
static void
icons_apply_theme (Gimp *gimp,
const gchar *icon_theme_name)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (! icon_theme_name)
icon_theme_name = GIMP_CONFIG_DEFAULT_ICON_THEME;
if (gimp->be_verbose)
g_print ("Loading icon theme '%s'\n", icon_theme_name);
gimp_icons_set_icon_theme (icon_themes_get_theme_dir (gimp, icon_theme_name));
}
static void
icons_list_icons_foreach (gpointer key,
gpointer value,
gpointer data)
{
gchar ***index = data;
**index = g_strdup ((gchar *) key);
(*index)++;
}
static gint
icons_name_compare (const void *p1,
const void *p2)
{
return strcmp (* (char **) p1, * (char **) p2);
}
static void
icons_theme_change_notify (GimpGuiConfig *config,
GParamSpec *pspec,
Gimp *gimp)
{
icons_apply_theme (gimp, config->icon_theme);
}
|