annotate audacious/util.c @ 1409:0f6573c34500 trunk

[svn] - properly hook up mms
author nenolod
date Sat, 15 Jul 2006 16:52:52 -0700
parents 99454d030722
children f12d7e208b43
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 <gdk/gdk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #include <ctype.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #include <gdk/gdkx.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 #include <gdk/gdkkeysyms.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 #include <X11/Xlib.h>
287
2d919c756941 [svn] - attach -Iaudacious to libaudcore build crap.
nenolod
parents: 284
diff changeset
44 //#include <sys/ipc.h>
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 #include <errno.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 #ifdef HAVE_FTS_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 # include <fts.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 #include "glade.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #include "input.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 #include "main.h"
538
e4e897d20791 [svn] remove libaudcore, we never did anything with it
nenolod
parents: 383
diff changeset
55 #include "playback.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 #include "playlist.h"
383
5c457dac866a [svn] - Rename playlistwin stuff to ui_playlist.*
nenolod
parents: 376
diff changeset
57 #include "ui_playlist.h"
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
59 #ifdef USE_CHARDET
1106
f12a2a0556cf [svn] chardet build error fix.
yaz
parents: 1105
diff changeset
60 #include "../libguess/libguess.h"
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;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 tmpdir = g_build_filename(g_get_tmp_dir(), "bmp.XXXXXXXX", NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 if (!mkdtemp(tmpdir)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 g_message("Unable to load skin: Failed to create temporary "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 "directory: %s", g_strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 escaped_filename = escape_shell_chars(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 g_free(escaped_filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 if (!cmd) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 g_message("extraction function is NULL!");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 system(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 g_free(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 return tmpdir;
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 #ifdef HAVE_FTS_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 del_directory(const gchar * dirname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 gchar *const argv[2] = { (gchar *) dirname, NULL };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 FTS *fts;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 FTSENT *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 while ((p = fts_read(fts))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 switch (p->fts_info) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 case FTS_D:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 case FTS_DNR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 case FTS_ERR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 case FTS_DP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 rmdir(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 unlink(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 fts_close(fts);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 #else /* !HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 del_directory_func(const gchar * path, const gchar * basename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 gpointer params)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 if (!strcmp(basename, ".") || !strcmp(path, ".."))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 unlink(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 del_directory(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 #endif /* ifdef HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 read_ini_string(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 {
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
402 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
403 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
404 gchar *ret_buffer = NULL;
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 538
diff changeset
405 gint found_section = 0, len = 0;
1193
03414b9d2507 [svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents: 1166
diff changeset
406 static gsize filesize = 0;
03414b9d2507 [svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents: 1166
diff changeset
407 gsize off = 0;
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
408 gchar *outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
409 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
410 guint counter;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414
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
415 /*
36e8431d8e19 [svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents: 1123
diff changeset
416 * 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
417 * 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
418 * 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
419 * 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
420 *
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 * 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
422 * 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
423 * - 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
424 */
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 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
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 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
428 {
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 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
430 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
431 }
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 (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
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(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
436 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
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 (!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
440 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
441
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 = 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
443 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
445 /*
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
446 * 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
447 * 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
448 */
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
449 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
450 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
451
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
452 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
453 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
454 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
455 else
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
456 return NULL;
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 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
459
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
460 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
461 g_free(buffer);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
462 buffer = outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
463 } else {
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
464 g_free(outbuf);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
465 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
466 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
467 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
468
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 while (!ret_buffer && off < filesize) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 (buffer[off] == '\r' || buffer[off] == '\n' ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 if (buffer[off] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 gint slen = strlen(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 found_section = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 if (off + slen + 1 < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 !strncasecmp(section, &buffer[off], slen)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 off += slen;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 if (buffer[off] == ']') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 found_section = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 else if (found_section && off + strlen(key) < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 !strncasecmp(key, &buffer[off], strlen(key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 off += strlen(key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 if (buffer[off] == '=') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 while (off + len < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 buffer[off + len] != '\r' &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 buffer[off + len] != '\n' && buffer[off + len] != ';')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 len++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 ret_buffer = g_strndup(&buffer[off], len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 off += len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 return ret_buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 string_to_garray(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 GArray *array;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 gint temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 const gchar *ptr = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 gchar *endptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 array = g_array_new(FALSE, TRUE, sizeof(gint));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 for (;;) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 temp = strtol(ptr, &endptr, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 if (ptr == endptr)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 g_array_append_val(array, temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 ptr = endptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 while (!isdigit(*ptr) && (*ptr) != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 ptr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 if (*ptr == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 return (array);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 read_ini_array(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 gchar *temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 GArray *a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 if ((temp = read_ini_string(filename, section, key)) == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 a = string_to_garray(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 return a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 glist_movedown(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 if (g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566 list->data = list->next->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 list->next->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 glist_moveup(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576 if (g_list_previous(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 list->data = list->prev->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 list->prev->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 util_menu_position(GtkMenu * menu, gint * x, gint * y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 gboolean * push_in, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 GtkRequisition requisition;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 gint screen_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 gint screen_height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 MenuPos *pos = data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 screen_width = gdk_screen_width();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596 screen_height = gdk_screen_height();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 gtk_signal_disconnect_by_func(object,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 GTK_SIGNAL_FUNC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 (util_menu_delete_popup_data), ifactory);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
610
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
611
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
612 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 * util_item_factory_popup[_with_data]() is a replacement for
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614 * gtk_item_factory_popup[_with_data]().
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616 * The difference is that the menu is always popped up whithin the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 * screen. This means it does not neccesarily pop up at (x,y).
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
618 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
619
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
620 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 util_item_factory_popup_with_data(GtkItemFactory * ifactory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 gpointer data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 GtkDestroyNotify destroy, guint x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624 guint y, guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 static GQuark quark_user_menu_pos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 MenuPos *pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 if (!quark_user_menu_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632 if (!quark_popup_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633 quark_popup_data =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 g_quark_from_static_string("GtkItemFactory-popup-data");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 if (!pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 pos = g_new0(MenuPos, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 g_object_set_qdata_full(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641 quark_user_menu_pos, pos, g_free);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 pos->x = x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 pos->y = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647 if (data != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 g_object_set_qdata_full(G_OBJECT(ifactory),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 quark_popup_data, data, destroy);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 g_signal_connect(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651 "selection-done",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 G_CALLBACK(util_menu_delete_popup_data), ifactory);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
653 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
654
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
655 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
656 (GtkMenuPositionFunc) util_menu_position,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
657 pos, mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
659
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665 mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 #define URL_HISTORY_MAX_SIZE 30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 util_add_url_callback(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 const gchar *text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 text = gtk_entry_get_text(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 GList *node = g_list_last(cfg.url_history);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
686 cfg.url_history = g_list_delete_link(cfg.url_history, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 GtkWidget *
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
691 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
692 GCallback enqueue_func)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 {
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
694 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 GList *url;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
697 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
698 gtk_window_set_title(GTK_WINDOW(win), caption);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
699 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
700 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
701 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
702 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
703
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
704 vbox = gtk_vbox_new(FALSE, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
705 gtk_container_add(GTK_CONTAINER(win), vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
706
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 combo = gtk_combo_box_entry_new_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 entry = gtk_bin_get_child(GTK_BIN(combo));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 gtk_window_set_focus(GTK_WINDOW(win), entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712 gtk_entry_set_text(GTK_ENTRY(entry), "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714 for (url = cfg.url_history; url; url = g_list_next(url))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 g_signal_connect(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 g_signal_connect(entry, "activate",
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
721 G_CALLBACK(ok_func),
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 g_signal_connect_swapped(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
724 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
725 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
726
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
727 bbox = gtk_hbutton_box_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
732 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
733 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
734 G_CALLBACK(util_add_url_callback), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
735 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
736 G_CALLBACK(ok_func), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
737 g_signal_connect_swapped(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
738 G_CALLBACK(gtk_widget_destroy),
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
739 win);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
740 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
741
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
746 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
747 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 G_CALLBACK(enqueue_func),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
750 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 g_signal_connect_swapped(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758 g_signal_connect_swapped(cancel, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762 gtk_widget_show_all(vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
763
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
764 return win;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
765 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
766
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
767 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
768 filebrowser_add_files(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
769 GSList * files)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
770 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
771 GSList *cur;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
772 gchar *ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
773 guint ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
774
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
775 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
776 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
777
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
778 for (cur = files; cur; cur = g_slist_next(cur)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
779
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
780 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
781 playlist_add_dir((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
782 } else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
783 playlist_add((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
784 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
785
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
786 if (++ctr == 20) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
787 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
788 ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
789 while (gtk_events_pending() ) gtk_main_iteration();
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
793 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
794
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
795 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
796 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
797
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
798 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
799 ptr = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
800 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
801 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
802 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
803
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
804 g_free(cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
805 cfg.filesel_path = ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
806 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
807
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
808 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
809 filebrowser_add(GtkFileChooser * browser)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
810 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
811 GSList *files;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
812
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
813 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
814 files = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
815 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
816 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
817 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
818
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
819 if (!files) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
820 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
821 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
822
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
823 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
824 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
825 g_slist_free(files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
826 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
827
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
828 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
829 filebrowser_play(GtkFileChooser * browser)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
830 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
831 GSList *files;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
832
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
833 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
834 files = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
835 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
836 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
837 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
838
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
839 if (!files) return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
840
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
841 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
842
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
843 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
844 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
845 g_slist_free(files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
846
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
847 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
848 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
849
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
850
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
851 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
852 _filebrowser_add(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
853 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
854 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
855 filebrowser_add(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
856 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
857 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
858
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
859 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
860 _filebrowser_play(GtkWidget *widget, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
861 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
862 filebrowser_play(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
863 gtk_file_chooser_unselect_all(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
864 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
865
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
866 #if 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
867 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
868 filebrowser_on_response(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
869 gint response,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
870 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
871 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
872 gtk_widget_hide(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
873 switch (response) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
874 case GTK_RESPONSE_OK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
875 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
876 case GTK_RESPONSE_ACCEPT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
877 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
878 case GTK_RESPONSE_CLOSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
879 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
880 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
881 gtk_widget_destroy(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
882
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
883 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
884
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
885 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
886
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
887 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
888 _filebrowser_check_hide_add(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
889 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
890 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
891 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
892 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
893
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
894 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
895 _filebrowser_check_hide_open(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
896 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
897 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
898 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
899 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
900
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
901
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
902
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
903 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
904 filebrowser_on_keypress(GtkWidget * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
905 GdkEventKey * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
906 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
907 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
908 if (event->keyval == GDK_Escape) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
909 /* FIXME: this crashes BMP for some reason */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
910 /* g_signal_emit_by_name(browser, "delete-event"); */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
911 gtk_widget_hide(browser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
912 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
913 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
914
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
915 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
916 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
917
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
918 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
919 _filebrowser_do_hide_add(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
920 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
921 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
922 if (cfg.close_dialog_add)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
923 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
924 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
925
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
926 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
927 _filebrowser_do_hide_open(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
928 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
929 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
930 if (cfg.close_dialog_open)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
931 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
932 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
933
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
934 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
935 util_run_filebrowser(gboolean play_button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
936 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
937 static GladeXML *xml = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
938 static GtkWidget *dialog = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
939 static GtkWidget *chooser = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
940
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
941 static GtkWidget *button_add;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
942 static GtkWidget *button_select_all, *button_deselect_all;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
943 static GtkWidget *toggle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
944
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
945 static gulong handlerid, handlerid_check, handlerid_do;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
946 static gulong handlerid_activate, handlerid_do_activate;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
947
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
948 if (!xml) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
949 /* FIXME: Creating a file chooser dialog manually using
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
950 libglade because there's no way to stop
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
951 GtkFileChooserDialog from resizing the buttons to the same
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
952 size. The long toggle button title causes the buttons to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
953 turn unnecessarily elongated and fugly. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
954
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
955 GtkWidget *alignment;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
956
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
957 xml = glade_xml_new_or_die(_("Add/Open Files dialog"),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
958 DATA_DIR "/glade/addfiles.glade",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
959 NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
960 glade_xml_signal_autoconnect(xml);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
961
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
962 dialog = glade_xml_get_widget(xml, "add_files_dialog");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
963
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
964 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
965 not support GtkFileChooserWidget */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
966
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
967 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
968 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
969
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
970 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
971 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(chooser), FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
972 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
973
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
974 if (cfg.filesel_path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
975 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
976 gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(chooser),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
977 cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
978 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
979 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
980 cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
981 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
982
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
983 alignment = glade_xml_get_widget(xml, "alignment2");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
984 gtk_container_add(GTK_CONTAINER(alignment), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
985
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
986 toggle = glade_xml_get_widget(xml, "close_on_action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
987 button_select_all = glade_xml_get_widget(xml, "select_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
988 button_deselect_all = glade_xml_get_widget(xml, "deselect_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
989 button_add = glade_xml_get_widget(xml, "action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
990
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
991 g_signal_connect_swapped(button_select_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
992 G_CALLBACK(gtk_file_chooser_select_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
993 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
994 g_signal_connect_swapped(button_deselect_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
995 G_CALLBACK(gtk_file_chooser_unselect_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
996 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
997
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
998 g_signal_connect(dialog, "key_press_event",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
999 G_CALLBACK(filebrowser_on_keypress),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1000 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1001
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1002 gtk_widget_show_all(dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1003 } /* !xml */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1004 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1005 g_signal_handler_disconnect(button_add, handlerid);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1006 g_signal_handler_disconnect(toggle, handlerid_check);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1007 g_signal_handler_disconnect(chooser, handlerid_activate);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1008 g_signal_handler_disconnect(button_add, handlerid_do);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1009 g_signal_handler_disconnect(chooser, handlerid_do_activate);
893
6afdd0d7e1e1 [svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents: 879
diff changeset
1010 if (cfg.refresh_file_list) {
6afdd0d7e1e1 [svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents: 879
diff changeset
1011 // *sigh* force a refresh
6afdd0d7e1e1 [svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents: 879
diff changeset
1012 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser)));
6afdd0d7e1e1 [svn] Make refreshing optional, default to disabled if Gnome VFS available.
nemo
parents: 879
diff changeset
1013 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1014 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1015
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1016 if (play_button) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1017 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1018
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1019 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1020
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1021 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1022 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1023
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1024 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1025 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1026 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1027 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1028 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
1029 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1030 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1031 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1032
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1033 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1034
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1035 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1036 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1037
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1038 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1039 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1040 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1041 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1042 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
1043 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1044
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1045 gtk_window_present(GTK_WINDOW(dialog));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1046 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1047
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1048 GdkFont *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1049 util_font_load(const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1050 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1051 GdkFont *font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1052 PangoFontDescription *desc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1053
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1054 desc = pango_font_description_from_string(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1055 font = gdk_font_from_description(desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1056
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1057 return font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1058 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1059
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1060 #ifdef ENABLE_NLS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1061 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1062 bmp_menu_translate(const gchar * path, gpointer func_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1063 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1064 gchar *translation = gettext(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1065
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1066 if (!translation || *translation != '/') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1067 g_warning("Bad translation for menupath: %s", path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1068 translation = (gchar *) path;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1069 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1070
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1071 return translation;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1072 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1073 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1074
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1075 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1076 util_set_cursor(GtkWidget * window)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1077 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1078 static GdkCursor *cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1079
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1080 if (!window) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1081 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
1082 gdk_cursor_unref(cursor);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1083 cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1084 }
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
1085
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1086 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1087 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1088
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1089 if (!cursor)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1090 cursor = gdk_cursor_new(GDK_LEFT_PTR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1091
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1092 gdk_window_set_cursor(window->window, cursor);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1093 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1094
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1095 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1096 * Mattis et al */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1097 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1098 text_get_extents(const gchar * fontname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1099 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1100 gint * width, gint * height, gint * ascent, gint * descent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1101 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1102 PangoFontDescription *font_desc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1103 PangoLayout *layout;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1104 PangoRectangle rect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1106 g_return_val_if_fail(fontname != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1107 g_return_val_if_fail(text != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1109 /* FIXME: resolution */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1110 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1111
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1112 font_desc = pango_font_description_from_string(fontname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1113 pango_layout_set_font_description(layout, font_desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1114 pango_font_description_free(font_desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1115 pango_layout_get_pixel_extents(layout, NULL, &rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1117 if (width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1118 *width = rect.width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1119 if (height)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1120 *height = rect.height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1121
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1122 if (ascent || descent) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1123 PangoLayoutIter *iter;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1124 PangoLayoutLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1125
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1126 iter = pango_layout_get_iter(layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1127 line = pango_layout_iter_get_line(iter);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1128 pango_layout_iter_free(iter);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1129
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1130 pango_layout_line_get_pixel_extents(line, NULL, &rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1131
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1132 if (ascent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1133 *ascent = PANGO_ASCENT(rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1134 if (descent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1135 *descent = -PANGO_DESCENT(rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1137
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1138 g_object_unref(layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1139
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1140 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1141 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1143 /* counts number of digits in a gint */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1144 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1145 gint_count_digits(gint n)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1146 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1147 guint count = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1148
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1149 n = ABS(n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1150 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1151 count++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1152 n /= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1153 } while (n > 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1155 return count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1158 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1159 str_twenty_to_space(gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1161 gchar *match, *match_end;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1163 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1164
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1165 while ((match = strstr(str, "%20"))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1166 match_end = match + 3;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1167 *match++ = ' ';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1168 while (*match_end)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1169 *match++ = *match_end++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1170 *match = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1171 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1172
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1173 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1174 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1175
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1176 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1177 str_replace_char(gchar * str, gchar old, gchar new)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1178 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1179 gchar *match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1180
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1181 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1183 match = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1184 while ((match = strchr(match, old)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1185 *match = new;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1186
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1187 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1188 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1189
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1190 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1191 str_append(gchar * str, const gchar * add_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1192 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1193 return str_replace(str, g_strconcat(str, add_str, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1194 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1196 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1197 str_replace(gchar * str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1198 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1199 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1200 return new_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1201 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1202
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1203 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1204 str_replace_in(gchar ** str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1205 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1206 *str = str_replace(*str, new_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1207 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1208
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1210 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1211 str_has_prefix_nocase(const gchar * str, const gchar * prefix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1212 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1213 return (strncasecmp(str, prefix, strlen(prefix)) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1214 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1215
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1216 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1217 str_has_suffix_nocase(const gchar * str, const gchar * suffix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1218 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1219 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1220 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1221
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1222 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1223 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1224 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1225 gchar *const *suffix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1227 g_return_val_if_fail(str != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1228 g_return_val_if_fail(suffixes != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1229
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1230 for (suffix = suffixes; *suffix; suffix++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1231 if (str_has_suffix_nocase(str, *suffix))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1232 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1233
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1234 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1235 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1236
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1237 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1238 str_to_utf8_fallback(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1239 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1240 gchar *out_str, *convert_str, *chr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1241
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1242 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1243 if (!str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1244 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1245
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1246 convert_str = g_strdup(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1247 for (chr = convert_str; *chr; chr++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1248 if (*chr & 0x80)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1249 *chr = '?';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1250 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1251
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1252 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1253 g_free(convert_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1255 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1256 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1258 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1259 filename_to_utf8(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1260 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1261 gchar *out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1263 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1264 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1265 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1267 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1268 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1269
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1270 return str_to_utf8_fallback(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1271 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1273 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1274 str_to_utf8(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1275 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1276 gchar *out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1278 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1279 if (!str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1280 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1281
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1282 /* 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
1283 * 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
1284 * 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
1285 * 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
1286 * 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
1287 * 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
1288 * 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
1289 */
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1290 /* already UTF-8? */
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1291 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
1292 return g_strdup(str);
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1293
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1294 /* chardet encoding detector */
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1295 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL)))
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1296 return out_str;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1297
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1298 /* assume encoding associated with locale */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1299 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1300 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1302 /* all else fails, we mask off character codes >= 128,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1303 replace with '?' */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1304 return str_to_utf8_fallback(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1305 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1307
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1308 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1309 str_skip_chars(const gchar * str, const gchar * chars)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1310 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1311 while (strchr(chars, *str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1312 str++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1313 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1314 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1316 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1317 convert_title_text(gchar * title)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1318 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1319 g_return_val_if_fail(title != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1321 if (cfg.convert_underscore)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1322 str_replace_char(title, '_', ' ');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1323
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1324 if (cfg.convert_twenty)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1325 str_twenty_to_space(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1326
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1327 return title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1328 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1329
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1330
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1331 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1332 dir_foreach(const gchar * path, DirForeachFunc function,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1333 gpointer user_data, GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1334 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1335 GError *error_out = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1336 GDir *dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1337 const gchar *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1338 gchar *entry_fullpath;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1339
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1340 if (!(dir = g_dir_open(path, 0, &error_out))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1341 g_propagate_error(error, error_out);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1342 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1343 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1344
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1345 while ((entry = g_dir_read_name(dir))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1346 entry_fullpath = g_build_filename(path, entry, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1348 if ((*function) (entry_fullpath, entry, user_data)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1349 g_free(entry_fullpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1350 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1351 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1352
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1353 g_free(entry_fullpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1354 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1356 g_dir_close(dir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1358 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1359 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1360
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1361 GtkWidget *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1362 make_filebrowser(const gchar * title,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1363 gboolean save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1364 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1365 GtkWidget *dialog;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1366 GtkWidget *button;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1367 GtkWidget *button_close;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1368
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1369 g_return_val_if_fail(title != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1370
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1371 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
376
94507b102cdb [svn] Sentinel fix; extra NULL required.
chainsaw
parents: 287
diff changeset
1372 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1373 if (save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1374 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1375 GTK_FILE_CHOOSER_ACTION_SAVE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1376
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1377 if (!save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1378 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1379
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1380 g_signal_connect(dialog, "destroy",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1381 G_CALLBACK(gtk_widget_destroyed), &dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1382
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1383 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1384 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1385 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1386
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1387 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1388 GTK_RESPONSE_REJECT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1389 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1390 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1391 g_signal_connect_swapped(button_close, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1392 G_CALLBACK(gtk_widget_destroy), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1393
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1394 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1395 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1396 GTK_RESPONSE_ACCEPT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1397 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1398 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1399 gtk_window_set_default(GTK_WINDOW(dialog), button);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1400
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1401 gtk_widget_show(dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1402
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1403 return dialog;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1404 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1405
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1406
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1407 GtkItemFactory *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1408 create_menu(GtkItemFactoryEntry *entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1409 guint n_entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1410 GtkAccelGroup *accel)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1411 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1412 GtkItemFactory *menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1413
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1414 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1415 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1416 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1417 gtk_item_factory_create_items(menu, n_entries, entries, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1418
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1419 return menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1420 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1421
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1422
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1423 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1424 make_submenu(GtkItemFactory *menu,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1425 const gchar *item_path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1426 GtkItemFactory *submenu)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1427 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1428 GtkWidget *item, *menu_;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1429
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1430 item = gtk_item_factory_get_widget(menu, item_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1431 menu_ = gtk_item_factory_get_widget(submenu, "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1432 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1433 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1434
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1435
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1436 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
1437 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
1438 {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1439 #ifdef USE_CHARDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1440 char *det = NULL, *encoding = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1441 #endif
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1442 gchar *ret = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1443 gsize *bytes_read, *bytes_write;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1444 GError **error;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1445 gsize my_bytes_read, my_bytes_write;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1446
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1447 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
1448 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
1449 error = arg_error ? arg_error : NULL;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1450
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1451 #ifdef USE_CHARDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1452 if(cfg.chardet_detector)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1453 det = cfg.chardet_detector;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1454
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1455 if(det){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1456 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
1457 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
1458 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1459 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1460 } 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
1461 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
1462 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1463 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1464 } 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
1465 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
1466 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1467 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1468 } 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
1469 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
1470 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1471 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1472 #ifdef HAVE_UDET
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1473 } 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
1474 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
1475 if (!encoding)
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1476 goto fallback;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1477 #endif
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1478 } else /* none, invalid */
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1479 goto fallback;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1480
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1481 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
1482 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1483
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1484 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
1485 #endif
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1486 if(!ret && cfg.chardet_fallback){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1487 gchar **encs=NULL, **enc=NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1488 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
1489
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1490 if(encs){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1491 enc = encs;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1492 for(enc=encs; *enc ; enc++){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1493 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
1494 if(len == *bytes_read){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1495 break;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1496 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1497 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1498 g_strfreev(encs);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1499 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1500 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1501
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1502 #ifdef USE_CHARDET
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1503 /* 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
1504 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
1505 latin1 string.
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1506 */
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1507 if(!ret){
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1508 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
1509 }
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1510 #endif
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1511
1105
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1512 if(ret){
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1513 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
1514 return ret;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1515 else {
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1516 g_free(ret);
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1517 ret = NULL;
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1518 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1519 }
4be4d74db123 [svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents: 1067
diff changeset
1520
1324
99454d030722 [svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents: 1193
diff changeset
1521 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
1522 }