Mercurial > audlegacy
annotate audacious/skinwin.c @ 1557:dc3ae578e7b6 trunk
[svn] - make it compile
author | nenolod |
---|---|
date | Thu, 10 Aug 2006 19:21:37 -0700 |
parents | 697a073fd4f5 |
children | 6e477dd65024 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 20 */ |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include "skinwin.h" | |
27 | |
28 #include <glib.h> | |
452
623391b6463b
[svn] Make "Unarchived Winamp 2.x skin" &c translatable.
nenolod
parents:
451
diff
changeset
|
29 #include <glib/gi18n.h> |
0 | 30 #include <gtk/gtk.h> |
31 #include <gdk/gdk.h> | |
32 #include <gdk/gdkkeysyms.h> | |
33 #include <stdlib.h> | |
34 #include <string.h> | |
35 | |
36 #include "main.h" | |
1547 | 37 #include "widgets/widgetcore.h" |
0 | 38 #include "util.h" |
39 | |
40 #include <gdk/gdkx.h> | |
41 | |
653 | 42 #define EXTENSION_TARGETS 7 |
43 | |
44 static gchar *ext_targets[EXTENSION_TARGETS] = { "bmp", "xpm", "png", "svg", | |
45 "gif", "jpg", "jpeg" }; | |
0 | 46 |
47 #define THUMBNAIL_WIDTH 90 | |
48 #define THUMBNAIL_HEIGHT 40 | |
49 | |
50 | |
51 enum SkinViewCols { | |
52 SKIN_VIEW_COL_PREVIEW, | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
53 SKIN_VIEW_COL_FORMATTEDNAME, |
0 | 54 SKIN_VIEW_COL_NAME, |
55 SKIN_VIEW_N_COLS | |
56 }; | |
57 | |
58 | |
59 GList *skinlist = NULL; | |
60 | |
61 | |
62 | |
63 static gchar * | |
64 get_thumbnail_filename(const gchar * path) | |
65 { | |
66 gchar *basename, *pngname, *thumbname; | |
67 | |
68 g_return_val_if_fail(path != NULL, NULL); | |
69 | |
70 basename = g_path_get_basename(path); | |
71 pngname = g_strconcat(basename, ".png", NULL); | |
72 | |
73 thumbname = g_build_filename(bmp_paths[BMP_PATH_SKIN_THUMB_DIR], | |
74 pngname, NULL); | |
75 | |
76 g_free(basename); | |
77 g_free(pngname); | |
78 | |
79 return thumbname; | |
80 } | |
81 | |
82 | |
83 static GdkPixbuf * | |
84 skin_get_preview(const gchar * path) | |
85 { | |
86 GdkPixbuf *preview = NULL; | |
87 gchar *dec_path, *preview_path; | |
88 gboolean is_archive = FALSE; | |
653 | 89 gint i = 0; |
90 gchar buf[60]; /* gives us lots of room */ | |
0 | 91 |
653 | 92 if (file_is_archive(path)) |
93 { | |
0 | 94 if (!(dec_path = archive_decompress(path))) |
95 return NULL; | |
96 | |
97 is_archive = TRUE; | |
98 } | |
653 | 99 else |
100 { | |
0 | 101 dec_path = g_strdup(path); |
102 } | |
103 | |
653 | 104 for (i = 0; i < EXTENSION_TARGETS; i++) |
105 { | |
106 sprintf(buf, "main.%s", ext_targets[i]); | |
0 | 107 |
674
9e553cf3d756
[svn] - Really fix preview generation for PNG/SVG based skins.
nenolod
parents:
653
diff
changeset
|
108 if ((preview_path = find_file_recursively(dec_path, buf)) != NULL) |
653 | 109 break; |
110 } | |
111 | |
112 if (preview_path) | |
113 { | |
0 | 114 preview = gdk_pixbuf_new_from_file(preview_path, NULL); |
115 g_free(preview_path); | |
116 } | |
117 | |
118 if (is_archive) | |
119 del_directory(dec_path); | |
120 | |
121 g_free(dec_path); | |
122 | |
123 return preview; | |
124 } | |
125 | |
126 | |
127 static GdkPixbuf * | |
128 skin_get_thumbnail(const gchar * path) | |
129 { | |
130 GdkPixbuf *scaled = NULL; | |
131 GdkPixbuf *preview; | |
132 gchar *thumbname; | |
133 | |
134 g_return_val_if_fail(path != NULL, NULL); | |
135 | |
136 if (g_str_has_suffix(path, BMP_SKIN_THUMB_DIR_BASENAME)) | |
137 return NULL; | |
138 | |
139 thumbname = get_thumbnail_filename(path); | |
140 | |
141 if (g_file_test(thumbname, G_FILE_TEST_EXISTS)) { | |
142 scaled = gdk_pixbuf_new_from_file(thumbname, NULL); | |
143 g_free(thumbname); | |
144 return scaled; | |
145 } | |
146 | |
147 if (!(preview = skin_get_preview(path))) { | |
148 g_free(thumbname); | |
149 return NULL; | |
150 } | |
151 | |
152 scaled = gdk_pixbuf_scale_simple(preview, | |
153 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, | |
154 GDK_INTERP_BILINEAR); | |
155 g_object_unref(preview); | |
156 | |
157 gdk_pixbuf_save(scaled, thumbname, "png", NULL, NULL); | |
158 g_free(thumbname); | |
159 | |
160 return scaled; | |
161 } | |
162 | |
163 static void | |
164 skinlist_add(const gchar * filename) | |
165 { | |
166 SkinNode *node; | |
167 gchar *basename; | |
168 | |
169 g_return_if_fail(filename != NULL); | |
170 | |
171 node = g_new0(SkinNode, 1); | |
172 node->path = g_strdup(filename); | |
173 | |
174 basename = g_path_get_basename(filename); | |
175 | |
176 if (file_is_archive(filename)) { | |
177 node->name = archive_basename(basename); | |
452
623391b6463b
[svn] Make "Unarchived Winamp 2.x skin" &c translatable.
nenolod
parents:
451
diff
changeset
|
178 node->desc = _("Archived Winamp 2.x skin"); |
0 | 179 g_free(basename); |
180 } | |
181 else { | |
182 node->name = basename; | |
452
623391b6463b
[svn] Make "Unarchived Winamp 2.x skin" &c translatable.
nenolod
parents:
451
diff
changeset
|
183 node->desc = _("Unarchived Winamp 2.x skin"); |
0 | 184 } |
185 | |
186 skinlist = g_list_prepend(skinlist, node); | |
187 } | |
188 | |
189 static gboolean | |
190 scan_skindir_func(const gchar * path, const gchar * basename, gpointer data) | |
191 { | |
192 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
193 if (file_is_archive(path)) { | |
194 skinlist_add(path); | |
195 } | |
196 } | |
197 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
198 skinlist_add(path); | |
199 } | |
200 | |
201 return FALSE; | |
202 } | |
203 | |
204 static void | |
205 scan_skindir(const gchar * path) | |
206 { | |
207 GError *error = NULL; | |
208 | |
209 g_return_if_fail(path != NULL); | |
210 | |
211 if (path[0] == '.') | |
212 return; | |
213 | |
214 if (!dir_foreach(path, scan_skindir_func, NULL, &error)) { | |
215 g_warning("Failed to open directory (%s): %s", path, error->message); | |
216 g_error_free(error); | |
217 return; | |
218 } | |
219 } | |
220 | |
221 static gint | |
222 skinlist_compare_func(gconstpointer a, gconstpointer b) | |
223 { | |
224 g_return_val_if_fail(a != NULL && SKIN_NODE(a)->name != NULL, 1); | |
225 g_return_val_if_fail(b != NULL && SKIN_NODE(b)->name != NULL, 1); | |
226 return strcasecmp(SKIN_NODE(a)->name, SKIN_NODE(b)->name); | |
227 } | |
228 | |
229 static void | |
230 skin_free_func(gpointer data) | |
231 { | |
232 g_return_if_fail(data != NULL); | |
233 g_free(SKIN_NODE(data)->name); | |
234 g_free(SKIN_NODE(data)->path); | |
235 g_free(data); | |
236 } | |
237 | |
238 | |
239 static void | |
240 skinlist_clear(void) | |
241 { | |
242 if (!skinlist) | |
243 return; | |
244 | |
245 g_list_foreach(skinlist, (GFunc) skin_free_func, NULL); | |
246 g_list_free(skinlist); | |
247 skinlist = NULL; | |
248 } | |
249 | |
250 void | |
251 skinlist_update(void) | |
252 { | |
253 gchar *skinsdir; | |
254 | |
255 skinlist_clear(); | |
256 | |
257 scan_skindir(bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
258 scan_skindir(DATA_DIR G_DIR_SEPARATOR_S BMP_SKIN_DIR_BASENAME); | |
259 | |
260 skinsdir = getenv("SKINSDIR"); | |
261 if (skinsdir) { | |
262 gchar **dir_list = g_strsplit(skinsdir, ":", 0); | |
263 gchar **dir; | |
264 | |
265 for (dir = dir_list; *dir; dir++) | |
266 scan_skindir(*dir); | |
267 g_strfreev(dir_list); | |
268 } | |
269 | |
270 skinlist = g_list_sort(skinlist, skinlist_compare_func); | |
271 | |
272 g_assert(skinlist != NULL); | |
273 } | |
274 | |
275 void | |
962
a341792533a6
[svn] - Let's not let the user press the skin refresh button while already refreshing ;)
nhjm449
parents:
674
diff
changeset
|
276 skin_view_update(GtkTreeView * treeview, GtkWidget * refresh_button) |
0 | 277 { |
278 GtkTreeSelection *selection = NULL; | |
279 GtkListStore *store; | |
280 GtkTreeIter iter, iter_current_skin; | |
642
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
281 gboolean have_current_skin = FALSE; |
0 | 282 GtkTreePath *path; |
283 | |
284 GdkPixbuf *thumbnail; | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
285 gchar *formattedname; |
0 | 286 gchar *name; |
287 GList *entry; | |
288 | |
289 gtk_widget_set_sensitive(GTK_WIDGET(treeview), FALSE); | |
962
a341792533a6
[svn] - Let's not let the user press the skin refresh button while already refreshing ;)
nhjm449
parents:
674
diff
changeset
|
290 gtk_widget_set_sensitive(GTK_WIDGET(refresh_button), FALSE); |
0 | 291 |
292 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); | |
293 | |
294 gtk_list_store_clear(store); | |
295 | |
296 skinlist_update(); | |
297 | |
298 for (entry = skinlist; entry; entry = g_list_next(entry)) { | |
299 thumbnail = skin_get_thumbnail(SKIN_NODE(entry->data)->path); | |
300 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
301 formattedname = g_strdup_printf("<big><b>%s</b></big>\n<i>%s</i>", |
449 | 302 SKIN_NODE(entry->data)->name, SKIN_NODE(entry->data)->desc); |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
303 name = SKIN_NODE(entry->data)->name; |
0 | 304 |
305 gtk_list_store_append(store, &iter); | |
306 gtk_list_store_set(store, &iter, | |
307 SKIN_VIEW_COL_PREVIEW, thumbnail, | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
308 SKIN_VIEW_COL_FORMATTEDNAME, formattedname, |
0 | 309 SKIN_VIEW_COL_NAME, name, -1); |
639
9d2c175e458e
[svn] More skin-related fixups. One segfault fix by Michael Hanselmann and a fix by Daniel Drake to also display skins that lack a thumbnail.
chainsaw
parents:
453
diff
changeset
|
310 if (thumbnail) |
9d2c175e458e
[svn] More skin-related fixups. One segfault fix by Michael Hanselmann and a fix by Daniel Drake to also display skins that lack a thumbnail.
chainsaw
parents:
453
diff
changeset
|
311 g_object_unref(thumbnail); |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
312 g_free(formattedname); |
0 | 313 |
314 if (g_strstr_len(bmp_active_skin->path, | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
315 strlen(bmp_active_skin->path), name) ) { |
642
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
316 iter_current_skin = iter; |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
317 have_current_skin = TRUE; |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
318 } |
0 | 319 |
320 while (gtk_events_pending()) | |
321 gtk_main_iteration(); | |
322 } | |
323 | |
642
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
324 if (have_current_skin) { |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
325 selection = gtk_tree_view_get_selection(treeview); |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
326 gtk_tree_selection_select_iter(selection, &iter_current_skin); |
0 | 327 |
642
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
328 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
329 &iter_current_skin); |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
330 gtk_tree_view_scroll_to_cell(treeview, path, NULL, TRUE, 0.5, 0.5); |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
331 gtk_tree_path_free(path); |
880cd914c3fd
[svn] Robustness fix; skinning dialog should deal with incorrect current skin setting gracefully. By external contributor Daniel Drake (Gentoo).
chainsaw
parents:
639
diff
changeset
|
332 } |
0 | 333 |
334 gtk_widget_set_sensitive(GTK_WIDGET(treeview), TRUE); | |
962
a341792533a6
[svn] - Let's not let the user press the skin refresh button while already refreshing ;)
nhjm449
parents:
674
diff
changeset
|
335 gtk_widget_set_sensitive(GTK_WIDGET(refresh_button), TRUE); |
0 | 336 } |
337 | |
338 | |
339 static void | |
340 skin_view_on_cursor_changed(GtkTreeView * treeview, | |
341 gpointer data) | |
342 { | |
343 GtkTreeModel *model; | |
344 GtkTreeSelection *selection; | |
345 GtkTreeIter iter; | |
346 | |
347 GList *node; | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
348 gchar *name; |
0 | 349 gchar *comp = NULL; |
350 | |
351 selection = gtk_tree_view_get_selection(treeview); | |
352 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) | |
353 return; | |
354 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
355 gtk_tree_model_get(model, &iter, SKIN_VIEW_COL_NAME, &name, -1); |
450
dd84f79979b4
[svn] Dissect the pango markup using scanf and various string delimiter hacks.
nenolod
parents:
449
diff
changeset
|
356 |
0 | 357 for (node = skinlist; node; node = g_list_next(node)) { |
358 comp = SKIN_NODE(node->data)->path; | |
359 if (g_strrstr(comp, name)) | |
360 break; | |
361 } | |
362 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
363 g_free(name); |
0 | 364 |
365 bmp_active_skin_load(comp); | |
366 } | |
367 | |
368 | |
369 void | |
370 skin_view_realize(GtkTreeView * treeview) | |
371 { | |
372 GtkListStore *store; | |
373 GtkTreeViewColumn *column; | |
374 GtkCellRenderer *renderer; | |
375 GtkTreeSelection *selection; | |
376 | |
377 gtk_widget_show_all(GTK_WIDGET(treeview)); | |
378 | |
379 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
380 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
381 | |
382 store = gtk_list_store_new(SKIN_VIEW_N_COLS, GDK_TYPE_PIXBUF, | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
383 G_TYPE_STRING , G_TYPE_STRING); |
0 | 384 gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store)); |
385 | |
386 column = gtk_tree_view_column_new(); | |
387 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
388 gtk_tree_view_column_set_spacing(column, 16); | |
389 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), | |
390 GTK_TREE_VIEW_COLUMN(column)); | |
391 | |
392 renderer = gtk_cell_renderer_pixbuf_new(); | |
393 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
394 gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", | |
395 SKIN_VIEW_COL_PREVIEW, NULL); | |
396 | |
397 renderer = gtk_cell_renderer_text_new(); | |
398 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
449 | 399 gtk_tree_view_column_set_attributes(column, renderer, "markup", |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
400 SKIN_VIEW_COL_FORMATTEDNAME, NULL); |
0 | 401 |
402 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
403 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); | |
404 | |
405 g_signal_connect(treeview, "cursor-changed", | |
406 G_CALLBACK(skin_view_on_cursor_changed), NULL); | |
407 } |