annotate audacious/util.c @ 2055:8feb3d69b5be trunk

[svn] - cleanups from oliver@freebsd.org
author nenolod
date Mon, 04 Dec 2006 15:03:22 -0800
parents d3a62e1075e2
children c725daec3849
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
22 #define WEIRD_UTF_16_PLAYLIST_ENCODING
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
23
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #define NEED_GLADE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "util.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <glib/gi18n.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <glade/glade.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #include <ctype.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
1640
6e477dd65024 [svn] - gtkquartz compatibility, pass 1
nenolod
parents: 1613
diff changeset
40 #include "platform/smartinclude.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #include <gdk/gdkkeysyms.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 #include <X11/Xlib.h>
287
2d919c756941 [svn] - attach -Iaudacious to libaudcore build crap.
nenolod
parents: 284
diff changeset
43 //#include <sys/ipc.h>
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 #include <errno.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #ifdef HAVE_FTS_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 # include <fts.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 #include "glade.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 #include "input.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #include "main.h"
538
e4e897d20791 [svn] remove libaudcore, we never did anything with it
nenolod
parents: 383
diff changeset
54 #include "playback.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 #include "playlist.h"
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
56 #include "ui_playlist.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
58 #ifdef USE_CHARDET
1106
f12a2a0556cf [svn] chardet build error fix.
yaz
parents: 1105
diff changeset
59 #include "../libguess/libguess.h"
1613
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
60 #include "../librcd/librcd.h"
1106
f12a2a0556cf [svn] chardet build error fix.
yaz
parents: 1105
diff changeset
61 #ifdef HAVE_UDET
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
62 #include <libudet_c.h>
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
63 #endif
1106
f12a2a0556cf [svn] chardet build error fix.
yaz
parents: 1105
diff changeset
64 #endif
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 static GQuark quark_popup_data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 * escape_shell_chars()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 * Escapes characters that are special to the shell inside double quotes.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 escape_shell_chars(const gchar * string)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 const gchar *special = "$`\"\\"; /* Characters to escape */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 const gchar *in = string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 gchar *out, *escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 gint num = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 while (*in != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 if (strchr(special, *in++))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 num++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 escaped = g_malloc(strlen(string) + num + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 in = string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 out = escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 while (*in != '\0') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 if (strchr(special, *in))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 *out++ = '\\';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 *out++ = *in++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 *out = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 return escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 * find <file> in directory <dirname> or subdirectories. return
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 * pointer to complete filename which has to be freed by calling
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 * "g_free()" after use. Returns NULL if file could not be found.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 const gchar *to_match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 gchar *match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 gboolean found;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 } FindFileContext;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 find_file_func(const gchar * path, const gchar * basename, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 FindFileContext *context = data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 if (strlen(path) > FILENAME_MAX) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 g_warning("Ignoring path: name too long (%s)", path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 if (!strcasecmp(basename, context->to_match)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 context->match = g_strdup(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 context->found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 dir_foreach(path, find_file_func, context, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 if (context->found)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 find_file_recursively(const gchar * path, const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 FindFileContext context;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 context.to_match = filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 context.match = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 context.found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 dir_foreach(path, find_file_func, &context, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 return context.match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 typedef enum {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 ARCHIVE_UNKNOWN = 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 ARCHIVE_DIR,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 ARCHIVE_TAR,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 ARCHIVE_TGZ,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 ARCHIVE_ZIP,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 ARCHIVE_TBZ2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 } ArchiveType;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 ArchiveType type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 const gchar *ext;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 } ArchiveExtensionType;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 static ArchiveExtensionType archive_extensions[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 {ARCHIVE_TAR, ".tar"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 {ARCHIVE_ZIP, ".wsz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 {ARCHIVE_ZIP, ".zip"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 {ARCHIVE_TGZ, ".tar.gz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 {ARCHIVE_TGZ, ".tgz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 {ARCHIVE_TBZ2, ".tar.bz2"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 {ARCHIVE_TBZ2, ".bz2"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 {ARCHIVE_UNKNOWN, NULL}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 static ArchiveExtractFunc archive_extract_funcs[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 archive_extract_tar,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 archive_extract_tgz,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 archive_extract_zip,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 archive_extract_tbz2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 /* FIXME: these functions can be generalised into a function using a
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 * command lookup table */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 static const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 get_tar_command(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 static const gchar *command = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 if (!command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 if (!(command = getenv("TARCMD")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 command = "tar";
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 return command;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 static const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 get_unzip_command(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 static const gchar *command = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 if (!command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 if (!(command = getenv("UNZIPCMD")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 command = "unzip";
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 return command;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 archive_extract_tar(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 get_tar_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 archive_extract_zip(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 get_unzip_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 archive_extract_tgz(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 get_tar_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 archive_extract_tbz2(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 archive, get_tar_command(), dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 ArchiveType
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 archive_get_type(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 return ARCHIVE_DIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 while (archive_extensions[i].ext) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 if (g_str_has_suffix(filename, archive_extensions[i].ext)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 return archive_extensions[i].type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 return ARCHIVE_UNKNOWN;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 file_is_archive(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 return (archive_get_type(filename) > ARCHIVE_DIR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 archive_basename(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 while (archive_extensions[i].ext) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 const gchar *end = g_strrstr(str, archive_extensions[i].ext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 if (end) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 return g_strndup(str, end - str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 decompress_archive
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 Decompresses the archive "filename" to a temporary directory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 returns the path to the temp dir, or NULL if failed,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 watch out tho, doesn't actually check if the system command succeeds :-|
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 archive_decompress(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 gchar *tmpdir, *cmd, *escaped_filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 ArchiveType type;
1890
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
312 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316
1890
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
317 #ifdef HAVE_MKDTEMP
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
318 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 if (!mkdtemp(tmpdir)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 g_message("Unable to load skin: Failed to create temporary "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 "directory: %s", g_strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 }
1890
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
325 #else
1891
46576f74b3a1 [svn] - use rand() instead
nenolod
parents: 1890
diff changeset
326 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand());
1890
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
327 make_directory(tmpdir, mode755);
90d95cd7edb5 [svn] - remove mkdtemp().
nenolod
parents: 1887
diff changeset
328 #endif
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 escaped_filename = escape_shell_chars(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 g_free(escaped_filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 if (!cmd) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 g_message("extraction function is NULL!");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 system(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 g_free(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 return tmpdir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 #ifdef HAVE_FTS_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 del_directory(const gchar * dirname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 gchar *const argv[2] = { (gchar *) dirname, NULL };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 FTS *fts;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 FTSENT *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 while ((p = fts_read(fts))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 switch (p->fts_info) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 case FTS_D:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 case FTS_DNR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 case FTS_ERR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 case FTS_DP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 rmdir(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 unlink(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 fts_close(fts);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 #else /* !HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 del_directory_func(const gchar * path, const gchar * basename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 gpointer params)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 if (!strcmp(basename, ".") || !strcmp(path, ".."))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 unlink(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 del_directory(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 #endif /* ifdef HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 read_ini_string(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 {
1166
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
408 static gchar *buffer = NULL;
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
409 static gchar *open_buffer = NULL;
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
410 gchar *ret_buffer = NULL;
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
411 gint found_section = 0, len = 0;
1193
03414b9d2507 [svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents: 1166
diff changeset
412 static gsize filesize = 0;
03414b9d2507 [svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents: 1166
diff changeset
413 gsize off = 0;
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
414 gchar *outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
415 unsigned char x[] = { 0xff, 0xfe, 0x00 };
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
416 guint counter;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420
1166
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
421 /*
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
422 * We optimise for the condition that we may be reading from the
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
423 * same ini-file multiple times. This is fairly common; it happens
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
424 * on .pls playlist loads. To do otherwise would take entirely too
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
425 * long, as fstat() can be very slow when done 21,000 times too many.
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
426 *
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
427 * Therefore, we optimise by keeping the last ini file in memory.
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
428 * Yes, this is a memory leak, but it is not too bad, hopefully.
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
429 * - nenolod
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
430 */
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
431 if (open_buffer == NULL || strcasecmp(filename, open_buffer))
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
432 {
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
433 if (buffer != NULL)
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
434 {
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
435 g_free(buffer);
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
436 buffer = NULL;
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
437 }
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
438
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
439 if (open_buffer != NULL)
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
440 {
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
441 g_free(open_buffer);
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
442 open_buffer = NULL;
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
443 }
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
444
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
445 if (!g_file_get_contents(filename, &buffer, &filesize, NULL))
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
446 return NULL;
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
447
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
448 open_buffer = g_strdup(filename);
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
449 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
451 /*
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
452 * Convert UTF-16 into something useful. Original implementation
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
453 * by incomp@#audacious. Cleanups \nenolod
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
454 */
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
455 if (!memcmp(&buffer[0],&x,2)) {
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
456 outbuf = g_malloc (filesize); /* it's safe to waste memory. */
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
457
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
458 for (counter = 2; counter < filesize; counter += 2)
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
459 if (!memcmp(&buffer[counter+1], &x[2], 1))
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
460 outbuf[(counter-2)/2] = buffer[counter];
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
461 else
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
462 return NULL;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
463
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
464 outbuf[(counter-2)/2] = '\0';
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
465
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
466 if ((filesize - 2) / 2 == (counter - 2) / 2) {
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
467 g_free(buffer);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
468 buffer = outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
469 } else {
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
470 g_free(outbuf);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
471 return NULL; /* XXX wrong encoding */
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
472 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
473 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
474
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 while (!ret_buffer && off < filesize) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 (buffer[off] == '\r' || buffer[off] == '\n' ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 if (buffer[off] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 gint slen = strlen(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 found_section = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 if (off + slen + 1 < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 !strncasecmp(section, &buffer[off], slen)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 off += slen;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 if (buffer[off] == ']') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 found_section = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 else if (found_section && off + strlen(key) < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 !strncasecmp(key, &buffer[off], strlen(key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 off += strlen(key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 if (buffer[off] == '=') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 while (off + len < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 buffer[off + len] != '\r' &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 buffer[off + len] != '\n' && buffer[off + len] != ';')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 len++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 ret_buffer = g_strndup(&buffer[off], len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 off += len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 return ret_buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 string_to_garray(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 GArray *array;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 gint temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 const gchar *ptr = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 gchar *endptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 array = g_array_new(FALSE, TRUE, sizeof(gint));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 for (;;) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 temp = strtol(ptr, &endptr, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 if (ptr == endptr)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 g_array_append_val(array, temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 ptr = endptr;
1717
837983bac90f [svn] Fixed a lot of warnings that only showed up on *BSD.
js
parents: 1653
diff changeset
541 while (!isdigit((int) *ptr) && (*ptr) != '\0')
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 ptr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 if (*ptr == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 return (array);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 read_ini_array(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 gchar *temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 GArray *a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 if ((temp = read_ini_string(filename, section, key)) == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 a = string_to_garray(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 return a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 glist_movedown(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 if (g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 list->data = list->next->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 list->next->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 glist_moveup(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 if (g_list_previous(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 list->data = list->prev->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 list->prev->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 util_menu_position(GtkMenu * menu, gint * x, gint * y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592 gboolean * push_in, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594 GtkRequisition requisition;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 gint screen_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 gint screen_height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 MenuPos *pos = data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 screen_width = gdk_screen_width();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 screen_height = gdk_screen_height();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611 gtk_signal_disconnect_by_func(object,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 GTK_SIGNAL_FUNC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 (util_menu_delete_popup_data), ifactory);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619 * util_item_factory_popup[_with_data]() is a replacement for
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 * gtk_item_factory_popup[_with_data]().
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 * The difference is that the menu is always popped up whithin the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 * screen. This means it does not neccesarily pop up at (x,y).
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 util_item_factory_popup_with_data(GtkItemFactory * ifactory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 gpointer data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 GtkDestroyNotify destroy, guint x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 guint y, guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 static GQuark quark_user_menu_pos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 MenuPos *pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635 if (!quark_user_menu_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 if (!quark_popup_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 quark_popup_data =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 g_quark_from_static_string("GtkItemFactory-popup-data");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 if (!pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 pos = g_new0(MenuPos, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 g_object_set_qdata_full(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 quark_user_menu_pos, pos, g_free);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 pos->x = x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 pos->y = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 if (data != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654 g_object_set_qdata_full(G_OBJECT(ifactory),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 quark_popup_data, data, destroy);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 g_signal_connect(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 "selection-done",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658 G_CALLBACK(util_menu_delete_popup_data), ifactory);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 (GtkMenuPositionFunc) util_menu_position,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 pos, mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668 guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 #define URL_HISTORY_MAX_SIZE 30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 util_add_url_callback(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 const gchar *text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 text = gtk_entry_get_text(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 GList *node = g_list_last(cfg.url_history);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 cfg.url_history = g_list_delete_link(cfg.url_history, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696 GtkWidget *
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
697 util_add_url_dialog_new(const gchar * caption, GCallback ok_func,
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
698 GCallback enqueue_func)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 {
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
700 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
701 GList *url;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 gtk_window_set_title(GTK_WINDOW(win), caption);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 vbox = gtk_vbox_new(FALSE, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 gtk_container_add(GTK_CONTAINER(win), vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 combo = gtk_combo_box_entry_new_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 entry = gtk_bin_get_child(GTK_BIN(combo));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 gtk_window_set_focus(GTK_WINDOW(win), entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 gtk_entry_set_text(GTK_ENTRY(entry), "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 for (url = cfg.url_history; url; url = g_list_next(url))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 g_signal_connect(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726 g_signal_connect(entry, "activate",
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
727 G_CALLBACK(ok_func),
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 g_signal_connect_swapped(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733 bbox = gtk_hbutton_box_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
738 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
739 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
740 G_CALLBACK(util_add_url_callback), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
741 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
742 G_CALLBACK(ok_func), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
743 g_signal_connect_swapped(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
744 G_CALLBACK(gtk_widget_destroy),
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
745 win);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
746 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
747
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
750
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 G_CALLBACK(enqueue_func),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757 g_signal_connect_swapped(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
763
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
764 g_signal_connect_swapped(cancel, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
765 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
766 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
767
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
768 gtk_widget_show_all(vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
769
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
770 return win;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
771 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
772
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
773 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
774 filebrowser_add_files(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
775 GSList * files)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
776 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
777 GSList *cur;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
778 gchar *ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
779 guint ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
780
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
781 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
782 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
783
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
784 for (cur = files; cur; cur = g_slist_next(cur)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
785
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
786 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
787 playlist_add_dir((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
788 } else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
789 playlist_add((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
790 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
791
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
792 if (++ctr == 20) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
793 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
794 ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
795 while (gtk_events_pending() ) gtk_main_iteration();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
796 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
797 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
798
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
799 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
800
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
801 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
802 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
803
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
804 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
805
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
806 g_free(cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
807 cfg.filesel_path = ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
808 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
809
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
810 static void
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
811 filebrowser_add(GtkFileChooser *browser)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
812 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
813 GSList *files;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
814
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
815 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
816
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
817 if (!files) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
818 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
819 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
820
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
821 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
822 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
823 g_slist_free(files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
824 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
825
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
826 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
827 filebrowser_play(GtkFileChooser * browser)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
828 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
829 GSList *files;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
830
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
831 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
832
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
833 if (!files) return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
834
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
835 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
836
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
837 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
838 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
839 g_slist_free(files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
840
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
841 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
842 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
843
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
844
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
845 static void
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
846 _filebrowser_add_gtk2(GtkWidget *widget,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
847 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
848 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
849 filebrowser_add(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
850 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
851 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
852
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
853 static void
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
854 _filebrowser_play_gtk2(GtkWidget *widget, gpointer data)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
855 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
856 filebrowser_play(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
857 gtk_file_chooser_unselect_all(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
858 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
859
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
860 #if 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
861 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
862 filebrowser_on_response(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
863 gint response,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
864 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
865 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
866 gtk_widget_hide(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
867 switch (response) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
868 case GTK_RESPONSE_OK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
869 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
870 case GTK_RESPONSE_ACCEPT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
871 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
872 case GTK_RESPONSE_CLOSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
873 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
874 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
875 gtk_widget_destroy(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
876
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
877 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
878
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
879 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
880
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
881 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
882 _filebrowser_check_hide_add(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
883 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
884 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
885 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
886 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
887
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
888 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
889 _filebrowser_check_hide_open(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
890 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
891 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
892 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
893 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
894
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
895
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
896
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
897 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
898 filebrowser_on_keypress(GtkWidget * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
899 GdkEventKey * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
900 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
901 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
902 if (event->keyval == GDK_Escape) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
903 /* FIXME: this crashes BMP for some reason */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
904 /* g_signal_emit_by_name(browser, "delete-event"); */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
905 gtk_widget_hide(browser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
906 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
907 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
908
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
909 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
910 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
911
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
912 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
913 _filebrowser_do_hide_add(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
914 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
915 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
916 if (cfg.close_dialog_add)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
917 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
918 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
919
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
920 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
921 _filebrowser_do_hide_open(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
922 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
923 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
924 if (cfg.close_dialog_open)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
925 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
926 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
927
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
928 void
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
929 util_run_filebrowser_gtk2style(gboolean play_button)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
930 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
931 static GladeXML *xml = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
932 static GtkWidget *dialog = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
933 static GtkWidget *chooser = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
934
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
935 static GtkWidget *button_add;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
936 static GtkWidget *button_select_all, *button_deselect_all;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
937 static GtkWidget *toggle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
938
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
939 static gulong handlerid, handlerid_check, handlerid_do;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
940 static gulong handlerid_activate, handlerid_do_activate;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
941
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
942 if (!xml) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
943 /* FIXME: Creating a file chooser dialog manually using
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
944 libglade because there's no way to stop
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
945 GtkFileChooserDialog from resizing the buttons to the same
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
946 size. The long toggle button title causes the buttons to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
947 turn unnecessarily elongated and fugly. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
948
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
949 GtkWidget *alignment;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
950
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
951 xml = glade_xml_new_or_die(_("Add/Open Files dialog"),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
952 DATA_DIR "/glade/addfiles.glade",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
953 NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
954 glade_xml_signal_autoconnect(xml);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
955
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
956 dialog = glade_xml_get_widget(xml, "add_files_dialog");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
957
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
958 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
959 not support GtkFileChooserWidget */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
960
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
961 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
962 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
963
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
964 if (cfg.filesel_path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
965 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
966 cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
967
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
968 alignment = glade_xml_get_widget(xml, "alignment2");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
969 gtk_container_add(GTK_CONTAINER(alignment), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
970
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
971 toggle = glade_xml_get_widget(xml, "close_on_action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
972 button_select_all = glade_xml_get_widget(xml, "select_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
973 button_deselect_all = glade_xml_get_widget(xml, "deselect_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
974 button_add = glade_xml_get_widget(xml, "action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
975
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
976 g_signal_connect_swapped(button_select_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
977 G_CALLBACK(gtk_file_chooser_select_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
978 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
979 g_signal_connect_swapped(button_deselect_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
980 G_CALLBACK(gtk_file_chooser_unselect_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
981 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
982
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
983 g_signal_connect(dialog, "key_press_event",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
984 G_CALLBACK(filebrowser_on_keypress),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
985 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
986
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
987 gtk_widget_show_all(dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
988 } /* !xml */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
989 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
990 g_signal_handler_disconnect(button_add, handlerid);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
991 g_signal_handler_disconnect(toggle, handlerid_check);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
992 g_signal_handler_disconnect(chooser, handlerid_activate);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
993 g_signal_handler_disconnect(button_add, handlerid_do);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
994 g_signal_handler_disconnect(chooser, handlerid_do_activate);
1752
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
995
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
996 if (cfg.refresh_file_list)
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
997 {
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
998 gchar *tmp = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser));
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
999 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), tmp);
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
1000
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
1001 g_free(tmp);
be1c5774f675 [svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents: 1717
diff changeset
1002 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1003 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1004
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1005 if (play_button) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1006 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1007
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1008 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1009
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1010 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1011 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1012
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1013 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play_gtk2), chooser);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1014 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1015 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog);
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1016 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play_gtk2), chooser);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1017 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1018 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1019 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1020 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1021
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1022 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1023
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1024 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1025 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1026
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1027 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add_gtk2), chooser);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1028 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1029 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog);
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1030 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add_gtk2), chooser);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1031 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1032 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1033
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1034 gtk_window_present(GTK_WINDOW(dialog));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1035 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1036
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1037 /*
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1038 * Derived from Beep Media Player 0.9.6.1.
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1039 * Which is (C) 2003 - 2006 Milosz Derezynski &c
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1040 *
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1041 * Although I changed it quite a bit. -nenolod
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1042 */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1043 static void filebrowser_changed_classic(GtkFileSelection * filesel)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1044 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1045 GList *list;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1046 GList *node;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1047 char *filename = (char *)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1048 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1049 GtkListStore *store;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1050 GtkTreeIter iter;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1051
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1052 if ((list = input_scan_dir(filename)) != NULL) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1053 /*
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1054 * We enter a directory that has been "hijacked" by an
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1055 * input-plugin. This is used by the CDDA plugin
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1056 */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1057 store =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1058 GTK_LIST_STORE(gtk_tree_view_get_model
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1059 (GTK_TREE_VIEW(filesel->file_list)));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1060 gtk_list_store_clear(store);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1061
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1062 node = list;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1063 while (node) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1064
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1065 gtk_list_store_append(store, &iter);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1066 gtk_list_store_set(store, &iter, 0, node->data, -1);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1067 g_free(node->data);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1068 node = g_list_next(node);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1069 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1070 g_list_free(list);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1071 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1072 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1073
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1074 static void filebrowser_entry_changed_classic(GtkEditable * entry, gpointer data)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1075 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1076 filebrowser_changed_classic(GTK_FILE_SELECTION(data));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1077 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1078
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1079 gboolean util_filebrowser_is_dir_classic(GtkFileSelection * filesel)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1080 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1081 char *text;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1082 struct stat buf;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1083 gboolean retv = FALSE;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1084
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1085 text = g_strdup(gtk_file_selection_get_filename(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1086
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1087 if (stat(text, &buf) == 0 && S_ISDIR(buf.st_mode)) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1088 /* Selected directory */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1089 int len = strlen(text);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1090 if (len > 3 && !strcmp(text + len - 4, "/../")) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1091 if (len == 4)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1092 /* At the root already */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1093 *(text + len - 3) = '\0';
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1094 else {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1095 char *ptr;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1096 *(text + len - 4) = '\0';
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1097 ptr = strrchr(text, '/');
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1098 *(ptr + 1) = '\0';
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1099 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1100 } else if (len > 2 && !strcmp(text + len - 3, "/./"))
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1101 *(text + len - 2) = '\0';
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1102 gtk_file_selection_set_filename(filesel, text);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1103 retv = TRUE;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1104 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1105 g_free(text);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1106 return retv;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1107 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1108
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1109 static void filebrowser_add_files_classic(gchar ** files,
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1110 GtkFileSelection * filesel)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1111 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1112 int ctr = 0;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1113 char *ptr;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1114
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1115 if (GTK_IS_WIDGET(mainwin_jtf))
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1116 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1117
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1118 while (files[ctr] != NULL) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1119 playlist_add(files[ctr++]);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1120 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1121 playlistwin_update_list();
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1122
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1123 if (GTK_IS_WIDGET(mainwin_jtf))
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1124 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1125
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1126 gtk_label_get(GTK_LABEL(GTK_BIN(filesel->history_pulldown)->child),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1127 &ptr);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1128
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1129 /* This will give an extra slash if the current dir is the root. */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1130 cfg.filesel_path = g_strconcat(ptr, "/", NULL);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1131 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1132
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1133 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1134 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1135 gchar **files;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1136
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1137 if (util_filebrowser_is_dir_classic(GTK_FILE_SELECTION(filesel)))
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1138 return;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1139 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1140 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1141 gtk_widget_destroy(filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1142 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1143
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1144 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1145 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1146 gchar **files;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1147
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1148 if (util_filebrowser_is_dir_classic
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1149 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel))))
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1150 return;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1151 playlist_clear();
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1152 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1153 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1154 gtk_widget_destroy(filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1155 bmp_playback_initiate();
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1156 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1157
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1158 static void filebrowser_add_selected_files_classic(GtkWidget * w, gpointer data)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1159 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1160 gchar **files;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1161
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1162 GtkFileSelection *filesel = GTK_FILE_SELECTION(data);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1163 files = gtk_file_selection_get_selections(filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1164
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1165 filebrowser_add_files_classic(files, filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1166 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1167 (GTK_TREE_VIEW(filesel->file_list)));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1168
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1169 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), "");
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1170 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1171
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1172 static void filebrowser_add_all_files_classic(GtkWidget * w, gpointer data)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1173 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1174 gchar **files;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1175 GtkFileSelection *filesel;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1176
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1177 filesel = data;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1178 gtk_tree_selection_select_all(gtk_tree_view_get_selection
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1179 (GTK_TREE_VIEW(filesel->file_list)));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1180 files = gtk_file_selection_get_selections(filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1181 filebrowser_add_files_classic(files, filesel);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1182 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1183 (GTK_TREE_VIEW(filesel->file_list)));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1184 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), "");
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1185 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1186
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1187 void
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1188 util_run_filebrowser_classic(gboolean play_button)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1189 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1190 static GtkWidget *dialog;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1191 GtkWidget *button_add_selected, *button_add_all, *button_close,
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1192 *button_add;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1193 char *title;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1194
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1195 if (dialog != NULL) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1196 gtk_window_present(GTK_WINDOW(dialog));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1197 return;
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1198 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1199
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1200 if (play_button)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1201 title = _("Play files");
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1202 else
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1203 title = _("Load files");
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1204
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1205 dialog = gtk_file_selection_new(title);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1206
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1207 gtk_file_selection_set_select_multiple
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1208 (GTK_FILE_SELECTION(dialog), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1209
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1210 if (cfg.filesel_path)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1211 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1212 cfg.filesel_path);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1213
1907
d7301ba54f70 [svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents: 1905
diff changeset
1214 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(dialog));
d7301ba54f70 [svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents: 1905
diff changeset
1215 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
d7301ba54f70 [svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents: 1905
diff changeset
1216
1905
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1217 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1218 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1219
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1220 /*
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1221 * The mnemonics are quite unorthodox, but that should guarantee they're unique in any locale
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1222 * plus kinda easy to use
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1223 */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1224 button_add_selected =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1225 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1226 GTK_RESPONSE_NONE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1227 gtk_button_set_use_underline(GTK_BUTTON(button_add_selected), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1228 g_signal_connect(G_OBJECT(button_add_selected), "clicked",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1229 G_CALLBACK(filebrowser_add_selected_files_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1230
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1231 button_add_all =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1232 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1233 GTK_RESPONSE_NONE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1234 gtk_button_set_use_underline(GTK_BUTTON(button_add_all), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1235 g_signal_connect(G_OBJECT(button_add_all), "clicked",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1236 G_CALLBACK(filebrowser_add_all_files_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1237
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1238 if (play_button) {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1239 button_add =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1240 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_MEDIA_PLAY,
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1241 GTK_RESPONSE_NONE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1242 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1243 g_signal_connect(G_OBJECT(button_add), "clicked",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1244 G_CALLBACK(filebrowser_play_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1245 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1246 "clicked", G_CALLBACK(filebrowser_play_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1247 } else {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1248 button_add =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1249 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ADD,
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1250 GTK_RESPONSE_NONE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1251 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1252 g_signal_connect(G_OBJECT(button_add), "clicked",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1253 G_CALLBACK(filebrowser_ok_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1254 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1255 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1256 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1257
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1258 button_close =
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1259 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE,
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1260 GTK_RESPONSE_NONE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1261 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1262 g_signal_connect_swapped(G_OBJECT(button_close), "clicked",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1263 G_CALLBACK(gtk_widget_destroy),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1264 G_OBJECT(dialog));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1265
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1266 gtk_widget_set_size_request(dialog, 600, 450);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1267 gtk_widget_realize(dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1268
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1269 g_signal_connect(G_OBJECT
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1270 (GTK_FILE_SELECTION(dialog)->history_pulldown),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1271 "changed", G_CALLBACK(filebrowser_entry_changed_classic),
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1272 dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1273
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1274 g_signal_connect(G_OBJECT(dialog), "destroy",
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1275 G_CALLBACK(gtk_widget_destroyed), &dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1276
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1277 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog));
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1278
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1279 gtk_widget_show(dialog);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1280 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1281
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1282 /*
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1283 * util_run_filebrowser(gboolean play_button)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1284 *
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1285 * Inputs:
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1286 * - whether or not a play button should be used
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1287 *
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1288 * Outputs:
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1289 * - none
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1290 *
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1291 * Side Effects:
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1292 * - either a GTK1 or a GTK2 fileselector is launched
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1293 */
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1294 void
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1295 util_run_filebrowser(gboolean play_button)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1296 {
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1297 if (!cfg.use_xmms_style_fileselector)
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1298 util_run_filebrowser_gtk2style(play_button);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1299 else
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1300 util_run_filebrowser_classic(play_button);
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1301 }
6b4116c34489 [svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents: 1891
diff changeset
1302
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1303 GdkFont *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1304 util_font_load(const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1305 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1306 GdkFont *font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1307 PangoFontDescription *desc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1309 desc = pango_font_description_from_string(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1310 font = gdk_font_from_description(desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1311
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1312 return font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1313 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1314
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1315 #ifdef ENABLE_NLS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1316 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1317 bmp_menu_translate(const gchar * path, gpointer func_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1318 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1319 gchar *translation = gettext(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1321 if (!translation || *translation != '/') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1322 g_warning("Bad translation for menupath: %s", path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1323 translation = (gchar *) path;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1324 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1325
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1326 return translation;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1327 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1328 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1329
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1330 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1331 util_set_cursor(GtkWidget * window)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1332 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1333 static GdkCursor *cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1334
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1335 if (!window) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1336 if (cursor) {
813
c8cf439179b8 [svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents: 625
diff changeset
1337 gdk_cursor_unref(cursor);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1338 cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1339 }
813
c8cf439179b8 [svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents: 625
diff changeset
1340
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1341 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1342 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1344 if (!cursor)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1345 cursor = gdk_cursor_new(GDK_LEFT_PTR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1346
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1347 gdk_window_set_cursor(window->window, cursor);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1348 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1349
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1350 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1351 * Mattis et al */
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1352 gboolean
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1353 text_get_extents(const gchar * fontname,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1354 const gchar * text,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1355 gint * width, gint * height, gint * ascent, gint * descent)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1356 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1357 PangoFontDescription *font_desc;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1358 PangoLayout *layout;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1359 PangoRectangle rect;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1360
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1361 g_return_val_if_fail(fontname != NULL, FALSE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1362 g_return_val_if_fail(text != NULL, FALSE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1363
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1364 /* FIXME: resolution */
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1365 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1366
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1367 font_desc = pango_font_description_from_string(fontname);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1368 pango_layout_set_font_description(layout, font_desc);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1369 pango_font_description_free(font_desc);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1370 pango_layout_get_pixel_extents(layout, NULL, &rect);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1371
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1372 if (width)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1373 *width = rect.width;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1374 if (height)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1375 *height = rect.height;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1376
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1377 if (ascent || descent) {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1378 PangoLayoutIter *iter;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1379 PangoLayoutLine *line;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1380
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1381 iter = pango_layout_get_iter(layout);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1382 line = pango_layout_iter_get_line(iter);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1383 pango_layout_iter_free(iter);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1384
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1385 pango_layout_line_get_pixel_extents(line, NULL, &rect);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1386
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1387 if (ascent)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1388 *ascent = PANGO_ASCENT(rect);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1389 if (descent)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1390 *descent = -PANGO_DESCENT(rect);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1391 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1392
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1393 g_object_unref(layout);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1394
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1395 return TRUE;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1396 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1397
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1398 /* counts number of digits in a gint */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1399 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1400 gint_count_digits(gint n)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1401 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1402 guint count = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1403
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1404 n = ABS(n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1405 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1406 count++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1407 n /= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1408 } while (n > 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1409
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1410 return count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1411 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1412
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1413 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1414 str_twenty_to_space(gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1415 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1416 gchar *match, *match_end;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1417
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1418 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1419
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1420 while ((match = strstr(str, "%20"))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1421 match_end = match + 3;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1422 *match++ = ' ';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1423 while (*match_end)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1424 *match++ = *match_end++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1425 *match = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1426 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1427
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1428 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1429 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1430
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1431 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1432 str_replace_char(gchar * str, gchar old, gchar new)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1433 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1434 gchar *match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1435
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1436 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1437
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1438 match = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1439 while ((match = strchr(match, old)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1440 *match = new;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1441
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1442 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1443 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1444
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1445 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1446 str_append(gchar * str, const gchar * add_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1447 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1448 return str_replace(str, g_strconcat(str, add_str, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1449 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1450
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1451 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1452 str_replace(gchar * str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1453 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1454 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1455 return new_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1456 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1457
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1458 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1459 str_replace_in(gchar ** str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1460 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1461 *str = str_replace(*str, new_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1462 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1463
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1464
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1465 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1466 str_has_prefix_nocase(const gchar * str, const gchar * prefix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1467 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1468 return (strncasecmp(str, prefix, strlen(prefix)) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1469 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1470
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1471 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1472 str_has_suffix_nocase(const gchar * str, const gchar * suffix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1473 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1474 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1475 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1476
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1477 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1478 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1479 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1480 gchar *const *suffix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1481
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1482 g_return_val_if_fail(str != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1483 g_return_val_if_fail(suffixes != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1484
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1485 for (suffix = suffixes; *suffix; suffix++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1486 if (str_has_suffix_nocase(str, *suffix))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1487 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1488
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1489 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1490 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1491
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1492 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1493 str_to_utf8_fallback(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1494 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1495 gchar *out_str, *convert_str, *chr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1496
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1497 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1498 if (!str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1499 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1500
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1501 convert_str = g_strdup(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1502 for (chr = convert_str; *chr; chr++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1503 if (*chr & 0x80)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1504 *chr = '?';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1505 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1506
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1507 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1508 g_free(convert_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1509
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1510 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1511 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1512
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1513 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1514 filename_to_utf8(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1515 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1516 gchar *out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1517
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1518 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1519 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1520 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1521
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1522 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1523 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1524
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1525 return str_to_utf8_fallback(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1526 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1527
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1528 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1529 str_to_utf8(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1530 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1531 gchar *out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1532
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1533 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1534 if (!str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1535 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1536
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1537 /* Note: Currently, playlist calls this function repeatedly, even
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1538 * if the string is already converted into utf-8.
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1539 * chardet_to_utf8() would convert a valid utf-8 string into a
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1540 * different utf-8 string, if fallback encodings were supplied and
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1541 * the given string could be treated as a string in one of fallback
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1542 * encodings. To avoid this, the order of evaluation has been
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1543 * changed. (It might cause a drawback?)
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1544 */
2015
200970e7a3b1 [svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents: 1972
diff changeset
1545 /* chardet encoding detector */
200970e7a3b1 [svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents: 1972
diff changeset
1546 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL)))
200970e7a3b1 [svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents: 1972
diff changeset
1547 return out_str;
200970e7a3b1 [svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents: 1972
diff changeset
1548
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1549 /* already UTF-8? */
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1550 if (g_utf8_validate(str, -1, NULL))
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1551 return g_strdup(str);
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1552
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1553 /* assume encoding associated with locale */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1554 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1555 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1556
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1557 /* all else fails, we mask off character codes >= 128,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1558 replace with '?' */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1559 return str_to_utf8_fallback(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1560 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1561
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1562
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1563 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1564 str_skip_chars(const gchar * str, const gchar * chars)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1565 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1566 while (strchr(chars, *str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1567 str++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1568 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1569 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1570
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1571 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1572 convert_title_text(gchar * title)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1573 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1574 g_return_val_if_fail(title != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1575
2019
d3a62e1075e2 [svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents: 2015
diff changeset
1576 if (cfg.convert_slash)
d3a62e1075e2 [svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents: 2015
diff changeset
1577 str_replace_char(title, '\\', '/');
d3a62e1075e2 [svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents: 2015
diff changeset
1578
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1579 if (cfg.convert_underscore)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1580 str_replace_char(title, '_', ' ');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1581
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1582 if (cfg.convert_twenty)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1583 str_twenty_to_space(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1584
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1585 return title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1586 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1587
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1588
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1589 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1590 dir_foreach(const gchar * path, DirForeachFunc function,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1591 gpointer user_data, GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1592 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1593 GError *error_out = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1594 GDir *dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1595 const gchar *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1596 gchar *entry_fullpath;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1597
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1598 if (!(dir = g_dir_open(path, 0, &error_out))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1599 g_propagate_error(error, error_out);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1600 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1601 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1602
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1603 while ((entry = g_dir_read_name(dir))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1604 entry_fullpath = g_build_filename(path, entry, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1605
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1606 if ((*function) (entry_fullpath, entry, user_data)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1607 g_free(entry_fullpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1608 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1609 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1610
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1611 g_free(entry_fullpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1612 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1613
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1614 g_dir_close(dir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1615
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1616 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1617 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1618
1653
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1619 GtkWidget *
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1620 make_filebrowser(const gchar * title,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1621 gboolean save)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1622 {
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1623 GtkWidget *dialog;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1624 GtkWidget *button;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1625 GtkWidget *button_close;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1626
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1627 g_return_val_if_fail(title != NULL, NULL);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1628
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1629 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1630 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1631 if (save)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1632 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog),
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1633 GTK_FILE_CHOOSER_ACTION_SAVE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1634
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1635 if (!save)
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1636 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1637
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1638 g_signal_connect(dialog, "destroy",
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1639 G_CALLBACK(gtk_widget_destroyed), &dialog);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1640
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1641 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1642 GTK_RESPONSE_REJECT);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1643 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1644 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1645 g_signal_connect_swapped(button_close, "clicked",
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1646 G_CALLBACK(gtk_widget_destroy), dialog);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1647
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1648 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1649 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1650 GTK_RESPONSE_ACCEPT);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1651 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1652 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1653 gtk_window_set_default(GTK_WINDOW(dialog), button);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1654
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1655 gtk_widget_show(dialog);
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1656
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1657 return dialog;
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1658 }
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1659
a6e6d3500c13 [svn] - revert back to r2216
nenolod
parents: 1649
diff changeset
1660
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1661 GtkItemFactory *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1662 create_menu(GtkItemFactoryEntry *entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1663 guint n_entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1664 GtkAccelGroup *accel)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1665 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1666 GtkItemFactory *menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1667
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1668 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1669 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1670 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1671 gtk_item_factory_create_items(menu, n_entries, entries, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1672
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1673 return menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1674 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1675
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1676
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1677 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1678 make_submenu(GtkItemFactory *menu,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1679 const gchar *item_path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1680 GtkItemFactory *submenu)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1681 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1682 GtkWidget *item, *menu_;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1683
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1684 item = gtk_item_factory_get_widget(menu, item_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1685 menu_ = gtk_item_factory_get_widget(submenu, "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1686 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1687 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1688
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1689
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1690 gchar *chardet_to_utf8(const gchar *str, gssize len,
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1691 gsize *arg_bytes_read, gsize *arg_bytes_write, GError **arg_error)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1692 {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1693 #ifdef USE_CHARDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1694 char *det = NULL, *encoding = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1695 #endif
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1696 gchar *ret = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1697 gsize *bytes_read, *bytes_write;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1698 GError **error;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1699 gsize my_bytes_read, my_bytes_write;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1700
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1701 bytes_read = arg_bytes_read ? arg_bytes_read : &my_bytes_read;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1702 bytes_write = arg_bytes_write ? arg_bytes_write : &my_bytes_write;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1703 error = arg_error ? arg_error : NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1704
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1705 #ifdef USE_CHARDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1706 if(cfg.chardet_detector)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1707 det = cfg.chardet_detector;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1708
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1709 if(det){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1710 if(!strncasecmp("japanese", det, sizeof("japanese"))) {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1711 encoding = (char *)guess_jp(str, strlen(str));
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1712 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1713 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1714 } else if(!strncasecmp("taiwanese", det, sizeof("taiwanese"))) {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1715 encoding = (char *)guess_tw(str, strlen(str));
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1716 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1717 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1718 } else if(!strncasecmp("chinese", det, sizeof("chinese"))) {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1719 encoding = (char *)guess_cn(str, strlen(str));
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1720 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1721 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1722 } else if(!strncasecmp("korean", det, sizeof("korean"))) {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1723 encoding = (char *)guess_kr(str, strlen(str));
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1724 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1725 goto fallback;
1613
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1726 } else if(!strncasecmp("russian", det, sizeof("russian"))) {
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1727 rcd_russian_charset res = rcdGetRussianCharset(str, strlen(str));
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1728 switch(res) {
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1729 case RUSSIAN_CHARSET_WIN:
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1730 encoding = "CP1251";
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1731 break;
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1732 case RUSSIAN_CHARSET_ALT:
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1733 encoding = "CP866";
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1734 break;
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1735 case RUSSIAN_CHARSET_KOI:
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1736 encoding = "KOI8-R";
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1737 break;
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1738 case RUSSIAN_CHARSET_UTF8:
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1739 encoding = "UTF-8";
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1740 break;
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1741 }
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1742 if (!encoding)
9becbe564217 [svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents: 1459
diff changeset
1743 goto fallback;
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1744 #ifdef HAVE_UDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1745 } else if (!strncasecmp("universal", det, sizeof("universal"))) {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1746 encoding = (char *)detectCharset((char *)str, strlen(str));
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1747 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1748 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1749 #endif
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1750 } else /* none, invalid */
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1751 goto fallback;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1752
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1753 ret = g_convert(str, len, "UTF-8", encoding, bytes_read, bytes_write, error);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1754 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1755
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1756 fallback:
1123
170f9b68dd03 [svn] The fallback label is not used unless detection is defined. Move endif down to reflect that.
chainsaw
parents: 1106
diff changeset
1757 #endif
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1758 if(!ret && cfg.chardet_fallback){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1759 gchar **encs=NULL, **enc=NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1760 encs = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1761
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1762 if(encs){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1763 enc = encs;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1764 for(enc=encs; *enc ; enc++){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1765 ret = g_convert(str, len, "UTF-8", *enc, bytes_read, bytes_write, error);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1766 if(len == *bytes_read){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1767 break;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1768 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1769 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1770 g_strfreev(encs);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1771 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1772 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1773
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1774 #ifdef USE_CHARDET
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1775 /* many tag libraries return 2byte latin1 utf8 character as
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1776 converted 8bit iso-8859-1 character, if they are asked to return
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1777 latin1 string.
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1778 */
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1779 if(!ret){
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1780 ret = g_convert(str, len, "UTF-8", "ISO-8859-1", bytes_read, bytes_write, error);
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1781 }
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1782 #endif
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1783
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1784 if(ret){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1785 if(g_utf8_validate(ret, -1, NULL))
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1786 return ret;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1787 else {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1788 g_free(ret);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1789 ret = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1790 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1791 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1792
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1793 return NULL; /* if I have no idea, return NULL. */
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1794 }
1851
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1795
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1796 /*
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1797 * Resizes a GDK pixmap.
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1798 */
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1799 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height)
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1800 {
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1801 GdkPixmap *out;
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1802 gint owidth, oheight;
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1803
1887
94795106c541 [svn] - icc warning fixes (pass 1)
nenolod
parents: 1852
diff changeset
1804 g_return_val_if_fail(src != NULL, NULL);
94795106c541 [svn] - icc warning fixes (pass 1)
nenolod
parents: 1852
diff changeset
1805 g_return_val_if_fail(src_gc != NULL, NULL);
94795106c541 [svn] - icc warning fixes (pass 1)
nenolod
parents: 1852
diff changeset
1806 g_return_val_if_fail(in != NULL, NULL);
94795106c541 [svn] - icc warning fixes (pass 1)
nenolod
parents: 1852
diff changeset
1807 g_return_val_if_fail(width > 0 && height > 0, NULL);
1851
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1808
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1809 gdk_drawable_get_size(in, &owidth, &oheight);
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1810
1852
01103f911aa5 [svn] - avoid unnecessary resizing
nenolod
parents: 1851
diff changeset
1811 if (oheight == height && owidth == width)
1887
94795106c541 [svn] - icc warning fixes (pass 1)
nenolod
parents: 1852
diff changeset
1812 return NULL;
1852
01103f911aa5 [svn] - avoid unnecessary resizing
nenolod
parents: 1851
diff changeset
1813
1851
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1814 out = gdk_pixmap_new(src, width, height, -1);
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1815
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1816 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height);
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1817
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1818 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight);
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1819 g_object_unref(src);
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1820
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1821 return out;
aceb472cce6c [svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents: 1752
diff changeset
1822 }
1938
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1823
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1824 GdkImage *create_dblsize_image(GdkImage * img)
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1825 {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1826 GdkImage *dblimg;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1827 register guint x, y;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1828
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1829 /*
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1830 * This needs to be optimized
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1831 */
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1832
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1833 dblimg =
1972
edc01e85648d [svn] - in particular X environment, double size caused a bad match X error.
yaz
parents: 1938
diff changeset
1834 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(),
1938
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1835 img->width << 1, img->height << 1);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1836 if (dblimg->bpp == 1) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1837 register guint8 *srcptr, *ptr, *ptr2, pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1838
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1839 srcptr = GDK_IMAGE_XIMAGE(img)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1840 ptr = GDK_IMAGE_XIMAGE(dblimg)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1841 ptr2 = ptr + dblimg->bpl;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1842
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1843 for (y = 0; y < img->height; y++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1844 for (x = 0; x < img->width; x++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1845 pix = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1846 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1847 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1848 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1849 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1850 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1851 srcptr += img->bpl - img->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1852 ptr += (dblimg->bpl << 1) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1853 ptr2 += (dblimg->bpl << 1) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1854 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1855 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1856 if (dblimg->bpp == 2) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1857 guint16 *srcptr, *ptr, *ptr2, pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1858
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1859 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1860 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1861 ptr2 = ptr + (dblimg->bpl >> 1);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1862
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1863 for (y = 0; y < img->height; y++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1864 for (x = 0; x < img->width; x++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1865 pix = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1866 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1867 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1868 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1869 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1870 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1871 srcptr += (img->bpl >> 1) - img->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1872 ptr += (dblimg->bpl) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1873 ptr2 += (dblimg->bpl) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1874 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1875 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1876 if (dblimg->bpp == 3) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1877 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1878
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1879 srcptr = GDK_IMAGE_XIMAGE(img)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1880 ptr = GDK_IMAGE_XIMAGE(dblimg)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1881 ptr2 = ptr + dblimg->bpl;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1882
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1883 for (y = 0; y < img->height; y++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1884 for (x = 0; x < img->width; x++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1885 pix1 = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1886 pix2 = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1887 pix3 = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1888 *ptr++ = pix1;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1889 *ptr++ = pix2;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1890 *ptr++ = pix3;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1891 *ptr++ = pix1;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1892 *ptr++ = pix2;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1893 *ptr++ = pix3;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1894 *ptr2++ = pix1;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1895 *ptr2++ = pix2;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1896 *ptr2++ = pix3;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1897 *ptr2++ = pix1;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1898 *ptr2++ = pix2;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1899 *ptr2++ = pix3;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1900
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1901 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1902 srcptr += img->bpl - (img->width * 3);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1903 ptr += (dblimg->bpl << 1) - (dblimg->width * 3);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1904 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1905 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1906 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1907 if (dblimg->bpp == 4) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1908 register guint32 *srcptr, *ptr, *ptr2, pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1909
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1910 srcptr = (guint32 *) GDK_IMAGE_XIMAGE(img)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1911 ptr = (guint32 *) GDK_IMAGE_XIMAGE(dblimg)->data;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1912 ptr2 = ptr + (dblimg->bpl >> 2);
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1913
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1914 for (y = 0; y < img->height; y++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1915 for (x = 0; x < img->width; x++) {
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1916 pix = *srcptr++;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1917 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1918 *ptr++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1919 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1920 *ptr2++ = pix;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1921 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1922 srcptr += (img->bpl >> 2) - img->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1923 ptr += (dblimg->bpl >> 1) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1924 ptr2 += (dblimg->bpl >> 1) - dblimg->width;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1925 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1926 }
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1927 return dblimg;
1d9c1026d9f8 [svn] - DoubleSize support.
nenolod
parents: 1936
diff changeset
1928 }