annotate src/skins/ui_skinselector.c @ 3112:0d47d41b39ec

Remove debug g_print; the crasher has been identified.
author Tony Vroon <chainsaw@gentoo.org>
date Sun, 03 May 2009 22:47:38 +0100
parents 4beebb0e82f8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2675
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
3 *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
4 * Based on XMMS:
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
6 *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
9 * the Free Software Foundation; under version 3 of the License.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
10 *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
14 * GNU General Public License for more details.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
15 *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
17 * along with this program. If not, see <http://www.gnu.org/licenses>.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
18 *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
19 * The Audacious team does not consider modular code linking to
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
20 * Audacious or using our public API to be a derived work.
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
21 */
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
22
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
24 # include "config.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
25 #endif
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
26
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
27 #include "ui_skinselector.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
28
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
29 #include <glib.h>
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
30 #include <glib/gi18n.h>
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
31 #include <gtk/gtk.h>
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
32
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
33 #include "platform/smartinclude.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
34
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
35 #include <stdlib.h>
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
36 #include <string.h>
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
37
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
38 #include "plugin.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
39 #include "ui_skin.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
40 #include "util.h"
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
41
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
42 #define EXTENSION_TARGETS 7
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
43
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
44 static gchar *ext_targets[EXTENSION_TARGETS] = { "bmp", "xpm", "png", "svg",
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
45 "gif", "jpg", "jpeg" };
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
46
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
47 #define THUMBNAIL_WIDTH 90
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
48 #define THUMBNAIL_HEIGHT 40
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
49
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
50
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
51 enum SkinViewCols {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
52 SKIN_VIEW_COL_PREVIEW,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
53 SKIN_VIEW_COL_FORMATTEDNAME,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
54 SKIN_VIEW_COL_NAME,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
55 SKIN_VIEW_N_COLS
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
56 };
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
57
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
58
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
59 GList *skinlist = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
60
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
61
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
62
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
63 static gchar *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
64 get_thumbnail_filename(const gchar * path)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
65 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
66 gchar *basename, *pngname, *thumbname;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
67
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
68 g_return_val_if_fail(path != NULL, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
69
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
70 basename = g_path_get_basename(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
71 pngname = g_strconcat(basename, ".png", NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
72
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
73 thumbname = g_build_filename(skins_paths[SKINS_PATH_SKIN_THUMB_DIR],
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
74 pngname, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
75
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
76 g_free(basename);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
77 g_free(pngname);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
78
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
79 return thumbname;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
80 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
81
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
82
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
83 static GdkPixbuf *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
84 skin_get_preview(const gchar * path)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
85 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
86 GdkPixbuf *preview = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
87 gchar *dec_path, *preview_path;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
88 gboolean is_archive = FALSE;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
89 gint i = 0;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
90 gchar buf[60]; /* gives us lots of room */
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
91
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
92 if (file_is_archive(path))
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
93 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
94 if (!(dec_path = archive_decompress(path)))
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
95 return NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
96
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
97 is_archive = TRUE;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
98 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
99 else
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
100 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
101 dec_path = g_strdup(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
102 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
103
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
104 for (i = 0; i < EXTENSION_TARGETS; i++)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
105 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
106 sprintf(buf, "main.%s", ext_targets[i]);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
107
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
108 if ((preview_path = find_path_recursively(dec_path, buf)) != NULL)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
109 break;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
110 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
111
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
112 if (preview_path)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
113 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
114 preview = gdk_pixbuf_new_from_file(preview_path, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
115 g_free(preview_path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
116 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
117
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
118 if (is_archive)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
119 del_directory(dec_path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
120
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
121 g_free(dec_path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
122
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
123 return preview;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
124 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
125
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
126
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
127 static GdkPixbuf *
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
128 skin_get_thumbnail(const gchar * path)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
129 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
130 GdkPixbuf *scaled = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
131 GdkPixbuf *preview;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
132 gchar *thumbname;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
133
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
134 g_return_val_if_fail(path != NULL, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
135
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
136 if (g_str_has_suffix(path, "thumbs"))
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
137 return NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
138
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
139 thumbname = get_thumbnail_filename(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
140
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
141 if (g_file_test(thumbname, G_FILE_TEST_EXISTS)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
142 scaled = gdk_pixbuf_new_from_file(thumbname, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
143 g_free(thumbname);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
144 return scaled;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
145 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
146
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
147 if (!(preview = skin_get_preview(path))) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
148 g_free(thumbname);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
149 return NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
150 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
151
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
152 scaled = gdk_pixbuf_scale_simple(preview,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
153 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
154 GDK_INTERP_BILINEAR);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
155 g_object_unref(preview);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
156
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
157 gdk_pixbuf_save(scaled, thumbname, "png", NULL, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
158 g_free(thumbname);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
159
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
160 return scaled;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
161 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
162
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
163 static void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
164 skinlist_add(const gchar * filename)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
165 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
166 SkinNode *node;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
167 gchar *basename;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
168
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
169 g_return_if_fail(filename != NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
170
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
171 node = g_slice_new0(SkinNode);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
172 node->path = g_strdup(filename);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
173
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
174 basename = g_path_get_basename(filename);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
175
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
176 if (file_is_archive(filename)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
177 node->name = archive_basename(basename);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
178 node->desc = _("Archived Winamp 2.x skin");
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
179 g_free(basename);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
180 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
181 else {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
182 node->name = basename;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
183 node->desc = _("Unarchived Winamp 2.x skin");
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
184 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
185
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
186 skinlist = g_list_prepend(skinlist, node);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
187 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
188
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
189 static gboolean
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
190 scan_skindir_func(const gchar * path, const gchar * basename, gpointer data)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
191 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
192 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
193 if (file_is_archive(path)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
194 skinlist_add(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
195 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
196 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
197 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
198 skinlist_add(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
199 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
200
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
201 return FALSE;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
202 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
203
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
204 static void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
205 scan_skindir(const gchar * path)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
206 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
207 GError *error = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
208
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
209 g_return_if_fail(path != NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
210
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
211 if (path[0] == '.')
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
212 return;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
213
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
214 if (!dir_foreach(path, scan_skindir_func, NULL, &error)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
215 g_warning("Failed to open directory (%s): %s", path, error->message);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
216 g_error_free(error);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
217 return;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
218 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
219 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
220
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
221 static gint
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
222 skinlist_compare_func(gconstpointer a, gconstpointer b)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
223 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
224 g_return_val_if_fail(a != NULL && SKIN_NODE(a)->name != NULL, 1);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
225 g_return_val_if_fail(b != NULL && SKIN_NODE(b)->name != NULL, 1);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
226 return strcasecmp(SKIN_NODE(a)->name, SKIN_NODE(b)->name);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
227 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
228
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
229 static void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
230 skin_free_func(gpointer data)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
231 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
232 g_return_if_fail(data != NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
233 g_free(SKIN_NODE(data)->name);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
234 g_free(SKIN_NODE(data)->path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
235 g_slice_free(SkinNode, data);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
236 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
237
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
238
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
239 static void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
240 skinlist_clear(void)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
241 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
242 if (!skinlist)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
243 return;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
244
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
245 g_list_foreach(skinlist, (GFunc) skin_free_func, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
246 g_list_free(skinlist);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
247 skinlist = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
248 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
249
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
250 void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
251 skinlist_update(void)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
252 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
253 gchar *skinsdir;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
254
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
255 skinlist_clear();
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
256
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
257 scan_skindir(skins_paths[SKINS_PATH_USER_SKIN_DIR]);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
258 scan_skindir(DATA_DIR G_DIR_SEPARATOR_S "Skins");
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
259
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
260 skinsdir = getenv("SKINSDIR");
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
261 if (skinsdir) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
262 gchar **dir_list = g_strsplit(skinsdir, ":", 0);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
263 gchar **dir;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
264
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
265 for (dir = dir_list; *dir; dir++)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
266 scan_skindir(*dir);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
267 g_strfreev(dir_list);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
268 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
269
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
270 skinlist = g_list_sort(skinlist, skinlist_compare_func);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
271
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
272 g_assert(skinlist != NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
273 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
274
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
275 void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
276 skin_view_update(GtkTreeView * treeview, GtkWidget * refresh_button)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
277 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
278 GtkTreeSelection *selection = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
279 GtkListStore *store;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
280 GtkTreeIter iter, iter_current_skin;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
281 gboolean have_current_skin = FALSE;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
282 GtkTreePath *path;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
283
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
284 GdkPixbuf *thumbnail;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
285 gchar *formattedname;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
286 gchar *name;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
287 GList *entry;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
288
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
289 gtk_widget_set_sensitive(GTK_WIDGET(treeview), FALSE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
290 gtk_widget_set_sensitive(GTK_WIDGET(refresh_button), FALSE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
291
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
292 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
293
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
294 gtk_list_store_clear(store);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
295
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
296 skinlist_update();
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
297
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
298 for (entry = skinlist; entry; entry = g_list_next(entry)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
299 thumbnail = skin_get_thumbnail(SKIN_NODE(entry->data)->path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
300
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
301 formattedname = g_strdup_printf("<big><b>%s</b></big>\n<i>%s</i>",
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
302 SKIN_NODE(entry->data)->name, SKIN_NODE(entry->data)->desc);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
303 name = SKIN_NODE(entry->data)->name;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
304
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
305 gtk_list_store_append(store, &iter);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
306 gtk_list_store_set(store, &iter,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
307 SKIN_VIEW_COL_PREVIEW, thumbnail,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
308 SKIN_VIEW_COL_FORMATTEDNAME, formattedname,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
309 SKIN_VIEW_COL_NAME, name, -1);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
310 if (thumbnail)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
311 g_object_unref(thumbnail);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
312 g_free(formattedname);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
313
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
314 if (g_strstr_len(aud_active_skin->path,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
315 strlen(aud_active_skin->path), name) ) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
316 iter_current_skin = iter;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
317 have_current_skin = TRUE;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
318 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
319 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
320
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
321 if (have_current_skin) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
322 selection = gtk_tree_view_get_selection(treeview);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
323 gtk_tree_selection_select_iter(selection, &iter_current_skin);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
324
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
325 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store),
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
326 &iter_current_skin);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
327 gtk_tree_view_scroll_to_cell(treeview, path, NULL, TRUE, 0.5, 0.5);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
328 gtk_tree_path_free(path);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
329 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
330
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
331 gtk_widget_set_sensitive(GTK_WIDGET(treeview), TRUE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
332 gtk_widget_set_sensitive(GTK_WIDGET(refresh_button), TRUE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
333 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
334
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
335
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
336 static void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
337 skin_view_on_cursor_changed(GtkTreeView * treeview,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
338 gpointer data)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
339 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
340 GtkTreeModel *model;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
341 GtkTreeSelection *selection;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
342 GtkTreeIter iter;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
343
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
344 GList *node;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
345 gchar *name;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
346 gchar *comp = NULL;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
347
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
348 selection = gtk_tree_view_get_selection(treeview);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
349 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
350 return;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
351
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
352 gtk_tree_model_get(model, &iter, SKIN_VIEW_COL_NAME, &name, -1);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
353
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
354 for (node = skinlist; node; node = g_list_next(node)) {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
355 comp = SKIN_NODE(node->data)->path;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
356 if (g_strrstr(comp, name))
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
357 break;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
358 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
359
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
360 g_free(name);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
361
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
362 aud_active_skin_load(comp);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
363 }
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
364
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
365
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
366 void
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
367 skin_view_realize(GtkTreeView * treeview)
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
368 {
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
369 GtkListStore *store;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
370 GtkTreeViewColumn *column;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
371 GtkCellRenderer *renderer;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
372 GtkTreeSelection *selection;
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
373
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
374 gtk_widget_show_all(GTK_WIDGET(treeview));
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
375
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
376 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
377 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
378
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
379 store = gtk_list_store_new(SKIN_VIEW_N_COLS, GDK_TYPE_PIXBUF,
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
380 G_TYPE_STRING , G_TYPE_STRING);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
381 gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store));
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
382
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
383 column = gtk_tree_view_column_new();
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
384 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
385 gtk_tree_view_column_set_spacing(column, 16);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
386 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
387 GTK_TREE_VIEW_COLUMN(column));
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
388
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
389 renderer = gtk_cell_renderer_pixbuf_new();
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
390 gtk_tree_view_column_pack_start(column, renderer, FALSE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
391 gtk_tree_view_column_set_attributes(column, renderer, "pixbuf",
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
392 SKIN_VIEW_COL_PREVIEW, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
393
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
394 renderer = gtk_cell_renderer_text_new();
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
395 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
396 gtk_tree_view_column_set_attributes(column, renderer, "markup",
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
397 SKIN_VIEW_COL_FORMATTEDNAME, NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
398
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
399 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
400 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
401
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
402 g_signal_connect(treeview, "cursor-changed",
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
403 G_CALLBACK(skin_view_on_cursor_changed), NULL);
4beebb0e82f8 add ui_skinselector
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
404 }