Mercurial > audlegacy
annotate audacious/skinwin.c @ 512:1cab8be8af51 trunk
[svn] Indentation changes.
author | nenolod |
---|---|
date | Thu, 26 Jan 2006 10:47:47 -0800 |
parents | 257a8d2047fb |
children | 9d2c175e458e |
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 | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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" | |
37 #include "skin.h" | |
38 #include "util.h" | |
39 | |
40 #include <gdk/gdkx.h> | |
41 | |
42 | |
43 #define THUMBNAIL_WIDTH 90 | |
44 #define THUMBNAIL_HEIGHT 40 | |
45 | |
46 | |
47 enum SkinViewCols { | |
48 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
|
49 SKIN_VIEW_COL_FORMATTEDNAME, |
0 | 50 SKIN_VIEW_COL_NAME, |
51 SKIN_VIEW_N_COLS | |
52 }; | |
53 | |
54 | |
55 GList *skinlist = NULL; | |
56 | |
57 | |
58 | |
59 static gchar * | |
60 get_thumbnail_filename(const gchar * path) | |
61 { | |
62 gchar *basename, *pngname, *thumbname; | |
63 | |
64 g_return_val_if_fail(path != NULL, NULL); | |
65 | |
66 basename = g_path_get_basename(path); | |
67 pngname = g_strconcat(basename, ".png", NULL); | |
68 | |
69 thumbname = g_build_filename(bmp_paths[BMP_PATH_SKIN_THUMB_DIR], | |
70 pngname, NULL); | |
71 | |
72 g_free(basename); | |
73 g_free(pngname); | |
74 | |
75 return thumbname; | |
76 } | |
77 | |
78 | |
79 static GdkPixbuf * | |
80 skin_get_preview(const gchar * path) | |
81 { | |
82 GdkPixbuf *preview = NULL; | |
83 gchar *dec_path, *preview_path; | |
84 gboolean is_archive = FALSE; | |
85 | |
86 if (file_is_archive(path)) { | |
87 if (!(dec_path = archive_decompress(path))) | |
88 return NULL; | |
89 | |
90 is_archive = TRUE; | |
91 } | |
92 else { | |
93 dec_path = g_strdup(path); | |
94 } | |
95 | |
96 preview_path = find_file_recursively(dec_path, "main.bmp"); | |
97 | |
98 if (preview_path) { | |
99 preview = gdk_pixbuf_new_from_file(preview_path, NULL); | |
100 g_free(preview_path); | |
101 } | |
102 | |
103 if (is_archive) | |
104 del_directory(dec_path); | |
105 | |
106 g_free(dec_path); | |
107 | |
108 return preview; | |
109 } | |
110 | |
111 | |
112 static GdkPixbuf * | |
113 skin_get_thumbnail(const gchar * path) | |
114 { | |
115 GdkPixbuf *scaled = NULL; | |
116 GdkPixbuf *preview; | |
117 gchar *thumbname; | |
118 | |
119 g_return_val_if_fail(path != NULL, NULL); | |
120 | |
121 if (g_str_has_suffix(path, BMP_SKIN_THUMB_DIR_BASENAME)) | |
122 return NULL; | |
123 | |
124 thumbname = get_thumbnail_filename(path); | |
125 | |
126 if (g_file_test(thumbname, G_FILE_TEST_EXISTS)) { | |
127 scaled = gdk_pixbuf_new_from_file(thumbname, NULL); | |
128 g_free(thumbname); | |
129 return scaled; | |
130 } | |
131 | |
132 if (!(preview = skin_get_preview(path))) { | |
133 g_free(thumbname); | |
134 return NULL; | |
135 } | |
136 | |
137 scaled = gdk_pixbuf_scale_simple(preview, | |
138 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, | |
139 GDK_INTERP_BILINEAR); | |
140 g_object_unref(preview); | |
141 | |
142 gdk_pixbuf_save(scaled, thumbname, "png", NULL, NULL); | |
143 g_free(thumbname); | |
144 | |
145 return scaled; | |
146 } | |
147 | |
148 static void | |
149 skinlist_add(const gchar * filename) | |
150 { | |
151 SkinNode *node; | |
152 gchar *basename; | |
153 | |
154 g_return_if_fail(filename != NULL); | |
155 | |
156 node = g_new0(SkinNode, 1); | |
157 node->path = g_strdup(filename); | |
158 | |
159 basename = g_path_get_basename(filename); | |
160 | |
161 if (file_is_archive(filename)) { | |
162 node->name = archive_basename(basename); | |
452
623391b6463b
[svn] Make "Unarchived Winamp 2.x skin" &c translatable.
nenolod
parents:
451
diff
changeset
|
163 node->desc = _("Archived Winamp 2.x skin"); |
0 | 164 g_free(basename); |
165 } | |
166 else { | |
167 node->name = basename; | |
452
623391b6463b
[svn] Make "Unarchived Winamp 2.x skin" &c translatable.
nenolod
parents:
451
diff
changeset
|
168 node->desc = _("Unarchived Winamp 2.x skin"); |
0 | 169 } |
170 | |
171 skinlist = g_list_prepend(skinlist, node); | |
172 } | |
173 | |
174 static gboolean | |
175 scan_skindir_func(const gchar * path, const gchar * basename, gpointer data) | |
176 { | |
177 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
178 if (file_is_archive(path)) { | |
179 skinlist_add(path); | |
180 } | |
181 } | |
182 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
183 skinlist_add(path); | |
184 } | |
185 | |
186 return FALSE; | |
187 } | |
188 | |
189 static void | |
190 scan_skindir(const gchar * path) | |
191 { | |
192 GError *error = NULL; | |
193 | |
194 g_return_if_fail(path != NULL); | |
195 | |
196 if (path[0] == '.') | |
197 return; | |
198 | |
199 if (!dir_foreach(path, scan_skindir_func, NULL, &error)) { | |
200 g_warning("Failed to open directory (%s): %s", path, error->message); | |
201 g_error_free(error); | |
202 return; | |
203 } | |
204 } | |
205 | |
206 static gint | |
207 skinlist_compare_func(gconstpointer a, gconstpointer b) | |
208 { | |
209 g_return_val_if_fail(a != NULL && SKIN_NODE(a)->name != NULL, 1); | |
210 g_return_val_if_fail(b != NULL && SKIN_NODE(b)->name != NULL, 1); | |
211 return strcasecmp(SKIN_NODE(a)->name, SKIN_NODE(b)->name); | |
212 } | |
213 | |
214 static void | |
215 skin_free_func(gpointer data) | |
216 { | |
217 g_return_if_fail(data != NULL); | |
218 g_free(SKIN_NODE(data)->name); | |
219 g_free(SKIN_NODE(data)->path); | |
220 g_free(data); | |
221 } | |
222 | |
223 | |
224 static void | |
225 skinlist_clear(void) | |
226 { | |
227 if (!skinlist) | |
228 return; | |
229 | |
230 g_list_foreach(skinlist, (GFunc) skin_free_func, NULL); | |
231 g_list_free(skinlist); | |
232 skinlist = NULL; | |
233 } | |
234 | |
235 void | |
236 skinlist_update(void) | |
237 { | |
238 gchar *skinsdir; | |
239 | |
240 skinlist_clear(); | |
241 | |
242 scan_skindir(bmp_paths[BMP_PATH_USER_SKIN_DIR]); | |
243 scan_skindir(DATA_DIR G_DIR_SEPARATOR_S BMP_SKIN_DIR_BASENAME); | |
244 | |
245 skinsdir = getenv("SKINSDIR"); | |
246 if (skinsdir) { | |
247 gchar **dir_list = g_strsplit(skinsdir, ":", 0); | |
248 gchar **dir; | |
249 | |
250 for (dir = dir_list; *dir; dir++) | |
251 scan_skindir(*dir); | |
252 g_strfreev(dir_list); | |
253 } | |
254 | |
255 skinlist = g_list_sort(skinlist, skinlist_compare_func); | |
256 | |
257 g_assert(skinlist != NULL); | |
258 } | |
259 | |
260 void | |
261 skin_view_update(GtkTreeView * treeview) | |
262 { | |
263 GtkTreeSelection *selection = NULL; | |
264 GtkListStore *store; | |
265 GtkTreeIter iter, iter_current_skin; | |
266 GtkTreePath *path; | |
267 | |
268 GdkPixbuf *thumbnail; | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
269 gchar *formattedname; |
0 | 270 gchar *name; |
271 GList *entry; | |
272 | |
273 gtk_widget_set_sensitive(GTK_WIDGET(treeview), FALSE); | |
274 | |
275 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); | |
276 | |
277 gtk_list_store_clear(store); | |
278 | |
279 skinlist_update(); | |
280 | |
281 for (entry = skinlist; entry; entry = g_list_next(entry)) { | |
282 thumbnail = skin_get_thumbnail(SKIN_NODE(entry->data)->path); | |
283 | |
284 if (!thumbnail) | |
285 continue; | |
286 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
287 formattedname = g_strdup_printf("<big><b>%s</b></big>\n<i>%s</i>", |
449 | 288 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
|
289 name = SKIN_NODE(entry->data)->name; |
0 | 290 |
291 gtk_list_store_append(store, &iter); | |
292 gtk_list_store_set(store, &iter, | |
293 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
|
294 SKIN_VIEW_COL_FORMATTEDNAME, formattedname, |
0 | 295 SKIN_VIEW_COL_NAME, name, -1); |
296 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
|
297 g_free(formattedname); |
0 | 298 |
299 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
|
300 strlen(bmp_active_skin->path), name) ) { |
0 | 301 iter_current_skin = iter; |
302 } | |
303 | |
304 while (gtk_events_pending()) | |
305 gtk_main_iteration(); | |
306 } | |
307 | |
308 selection = gtk_tree_view_get_selection(treeview); | |
309 gtk_tree_selection_select_iter(selection, &iter_current_skin); | |
310 | |
311 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter_current_skin); | |
312 gtk_tree_view_scroll_to_cell(treeview, path, NULL, TRUE, 0.5, 0.5); | |
313 gtk_tree_path_free(path); | |
314 | |
315 gtk_widget_set_sensitive(GTK_WIDGET(treeview), TRUE); | |
316 } | |
317 | |
318 | |
319 static void | |
320 skin_view_on_cursor_changed(GtkTreeView * treeview, | |
321 gpointer data) | |
322 { | |
323 GtkTreeModel *model; | |
324 GtkTreeSelection *selection; | |
325 GtkTreeIter iter; | |
326 | |
327 GList *node; | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
328 gchar *name; |
0 | 329 gchar *comp = NULL; |
330 | |
331 selection = gtk_tree_view_get_selection(treeview); | |
332 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) | |
333 return; | |
334 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
335 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
|
336 |
0 | 337 for (node = skinlist; node; node = g_list_next(node)) { |
338 comp = SKIN_NODE(node->data)->path; | |
339 if (g_strrstr(comp, name)) | |
340 break; | |
341 } | |
342 | |
453
257a8d2047fb
[svn] added a new column in the treeview model to store the skin name
giacomo
parents:
452
diff
changeset
|
343 g_free(name); |
0 | 344 |
345 bmp_active_skin_load(comp); | |
346 } | |
347 | |
348 | |
349 void | |
350 skin_view_realize(GtkTreeView * treeview) | |
351 { | |
352 GtkListStore *store; | |
353 GtkTreeViewColumn *column; | |
354 GtkCellRenderer *renderer; | |
355 GtkTreeSelection *selection; | |
356 | |
357 gtk_widget_show_all(GTK_WIDGET(treeview)); | |
358 | |
359 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
360 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
361 | |
362 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
|
363 G_TYPE_STRING , G_TYPE_STRING); |
0 | 364 gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store)); |
365 | |
366 column = gtk_tree_view_column_new(); | |
367 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
368 gtk_tree_view_column_set_spacing(column, 16); | |
369 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), | |
370 GTK_TREE_VIEW_COLUMN(column)); | |
371 | |
372 renderer = gtk_cell_renderer_pixbuf_new(); | |
373 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
374 gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", | |
375 SKIN_VIEW_COL_PREVIEW, NULL); | |
376 | |
377 renderer = gtk_cell_renderer_text_new(); | |
378 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
449 | 379 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
|
380 SKIN_VIEW_COL_FORMATTEDNAME, NULL); |
0 | 381 |
382 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | |
383 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); | |
384 | |
385 g_signal_connect(treeview, "cursor-changed", | |
386 G_CALLBACK(skin_view_on_cursor_changed), NULL); | |
387 } |