annotate audacious/util.c @ 430:67cd014f35a2 trunk

[svn] This commit rips out the old equalization engine with a dynamic engine that can be extended all the way up to 128 bands.
author nenolod
date Sat, 14 Jan 2006 16:49:00 -0800
parents 5c457dac866a
children e4e897d20791
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"
284
763afa52f416 [svn] Update header locations.
nenolod
parents: 245
diff changeset
55 #include "libaudcore/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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 static GQuark quark_popup_data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 * escape_shell_chars()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 * Escapes characters that are special to the shell inside double quotes.
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 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 escape_shell_chars(const gchar * string)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 const gchar *special = "$`\"\\"; /* Characters to escape */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 const gchar *in = string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 gchar *out, *escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 gint num = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 while (*in != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 if (strchr(special, *in++))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 num++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 escaped = g_malloc(strlen(string) + num + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 in = string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 out = escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 while (*in != '\0') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 if (strchr(special, *in))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 *out++ = '\\';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 *out++ = *in++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 *out = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 return escaped;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 * find <file> in directory <dirname> or subdirectories. return
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 * pointer to complete filename which has to be freed by calling
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 * "g_free()" after use. Returns NULL if file could not be found.
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 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 const gchar *to_match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 gchar *match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 gboolean found;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 } FindFileContext;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 find_file_func(const gchar * path, const gchar * basename, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 FindFileContext *context = data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 if (strlen(path) > FILENAME_MAX) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 g_warning("Ignoring path: name too long (%s)", path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 if (!strcasecmp(basename, context->to_match)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 context->match = g_strdup(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 context->found = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 dir_foreach(path, find_file_func, context, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 if (context->found)
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 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 find_file_recursively(const gchar * path, const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 FindFileContext context;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 context.to_match = filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 context.match = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 context.found = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 dir_foreach(path, find_file_func, &context, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 return context.match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 typedef enum {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 ARCHIVE_UNKNOWN = 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 ARCHIVE_DIR,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 ARCHIVE_TAR,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 ARCHIVE_TGZ,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 ARCHIVE_ZIP,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 ARCHIVE_TBZ2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 } ArchiveType;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 typedef struct {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 ArchiveType type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 const gchar *ext;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 } ArchiveExtensionType;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 static ArchiveExtensionType archive_extensions[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 {ARCHIVE_TAR, ".tar"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 {ARCHIVE_ZIP, ".wsz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 {ARCHIVE_ZIP, ".zip"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 {ARCHIVE_TGZ, ".tar.gz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 {ARCHIVE_TGZ, ".tgz"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 {ARCHIVE_TBZ2, ".tar.bz2"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 {ARCHIVE_TBZ2, ".bz2"},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 {ARCHIVE_UNKNOWN, NULL}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 static ArchiveExtractFunc archive_extract_funcs[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 archive_extract_tar,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 archive_extract_tgz,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 archive_extract_zip,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 archive_extract_tbz2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 /* FIXME: these functions can be generalised into a function using a
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 * command lookup table */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 static const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 get_tar_command(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 static const gchar *command = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 if (!command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 if (!(command = getenv("TARCMD")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 command = "tar";
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 return command;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 static const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 get_unzip_command(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 static const gchar *command = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 if (!command) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 if (!(command = getenv("UNZIPCMD")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 command = "unzip";
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 return command;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 archive_extract_tar(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 get_tar_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 archive_extract_zip(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 get_unzip_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 archive_extract_tgz(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 get_tar_command(), archive, dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 archive_extract_tbz2(const gchar * archive, const gchar * dest)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 archive, get_tar_command(), dest);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 ArchiveType
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 archive_get_type(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 return ARCHIVE_DIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 while (archive_extensions[i].ext) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 if (g_str_has_suffix(filename, archive_extensions[i].ext)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 return archive_extensions[i].type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 return ARCHIVE_UNKNOWN;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 file_is_archive(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 return (archive_get_type(filename) > ARCHIVE_DIR);
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 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 archive_basename(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 gint i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 while (archive_extensions[i].ext) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 const gchar *end = g_strrstr(str, archive_extensions[i].ext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 if (end) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 return g_strndup(str, end - str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 decompress_archive
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 Decompresses the archive "filename" to a temporary directory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 returns the path to the temp dir, or NULL if failed,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 watch out tho, doesn't actually check if the system command succeeds :-|
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 archive_decompress(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 gchar *tmpdir, *cmd, *escaped_filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 ArchiveType type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 tmpdir = g_build_filename(g_get_tmp_dir(), "bmp.XXXXXXXX", NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 if (!mkdtemp(tmpdir)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 g_message("Unable to load skin: Failed to create temporary "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 "directory: %s", g_strerror(errno));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 escaped_filename = escape_shell_chars(filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 g_free(escaped_filename);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 if (!cmd) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 g_message("extraction function is NULL!");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 g_free(tmpdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 system(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 g_free(cmd);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 return tmpdir;
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 #ifdef HAVE_FTS_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 del_directory(const gchar * dirname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 gchar *const argv[2] = { (gchar *) dirname, NULL };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 FTS *fts;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 FTSENT *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 while ((p = fts_read(fts))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 switch (p->fts_info) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 case FTS_D:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 case FTS_DNR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 case FTS_ERR:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 case FTS_DP:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 rmdir(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 unlink(p->fts_accpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 fts_close(fts);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 #else /* !HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 del_directory_func(const gchar * path, const gchar * basename,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 gpointer params)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 if (!strcmp(basename, ".") || !strcmp(path, ".."))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 unlink(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 del_directory(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 dir_foreach(path, del_directory_func, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 rmdir(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 #endif /* ifdef HAVE_FTS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 read_ini_string(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 gchar *buffer, *ret_buffer = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 gint found_section = 0, off = 0, len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 gsize filesize;
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
399 gchar *outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
400 unsigned char x[] = { 0xff, 0xfe, 0x00 };
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
401 int counter;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 if (!g_file_get_contents(filename, &buffer, &filesize, NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408
245
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
409 /*
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
410 * 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
411 * 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
412 */
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
413 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
414 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
415
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
416 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
417 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
418 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
419 else
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
420 return NULL;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
421
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
422 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
423
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
424 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
425 g_free(buffer);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
426 buffer = outbuf;
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
427 } else {
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
428 g_free(outbuf);
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
429 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
430 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
431 }
1d8012046612 [svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents: 86
diff changeset
432
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 while (!ret_buffer && off < filesize) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 (buffer[off] == '\r' || buffer[off] == '\n' ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 if (buffer[off] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 gint slen = strlen(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 found_section = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 if (off + slen + 1 < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 !strncasecmp(section, &buffer[off], slen)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 off += slen;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 if (buffer[off] == ']') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 found_section = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 else if (found_section && off + strlen(key) < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 !strncasecmp(key, &buffer[off], strlen(key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 off += strlen(key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 if (buffer[off] == '=') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 while (off < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 (buffer[off] == ' ' || buffer[off] == '\t'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 if (off >= filesize)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 len = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 while (off + len < filesize &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 buffer[off + len] != '\r' &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 buffer[off + len] != '\n' && buffer[off + len] != ';')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 len++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 ret_buffer = g_strndup(&buffer[off], len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 off += len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 off++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 return ret_buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 string_to_garray(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 GArray *array;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 gint temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 const gchar *ptr = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 gchar *endptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 array = g_array_new(FALSE, TRUE, sizeof(gint));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 for (;;) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 temp = strtol(ptr, &endptr, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 if (ptr == endptr)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 g_array_append_val(array, temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 ptr = endptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 while (!isdigit(*ptr) && (*ptr) != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 ptr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 if (*ptr == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 return (array);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 GArray *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 read_ini_array(const gchar * filename, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 gchar *temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 GArray *a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 if ((temp = read_ini_string(filename, section, key)) == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 a = string_to_garray(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 g_free(temp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 return a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 glist_movedown(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 if (g_list_next(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 list->data = list->next->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 list->next->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 glist_moveup(GList * list)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 gpointer temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 if (g_list_previous(list)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 temp = list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 list->data = list->prev->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 list->prev->data = temp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 util_menu_position(GtkMenu * menu, gint * x, gint * y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 gboolean * push_in, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 GtkRequisition requisition;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 gint screen_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 gint screen_height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 MenuPos *pos = data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 screen_width = gdk_screen_width();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 screen_height = gdk_screen_height();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
566
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
567 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
568 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
569 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
570 gtk_signal_disconnect_by_func(object,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
571 GTK_SIGNAL_FUNC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
572 (util_menu_delete_popup_data), ifactory);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
573 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
574 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
575
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
576
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
577 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
578 * util_item_factory_popup[_with_data]() is a replacement for
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
579 * gtk_item_factory_popup[_with_data]().
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
580 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
581 * The difference is that the menu is always popped up whithin the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
582 * screen. This means it does not neccesarily pop up at (x,y).
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
583 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
584
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
585 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
586 util_item_factory_popup_with_data(GtkItemFactory * ifactory,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
587 gpointer data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
588 GtkDestroyNotify destroy, guint x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
589 guint y, guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
590 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
591 static GQuark quark_user_menu_pos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
592 MenuPos *pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
593
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
594 if (!quark_user_menu_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
595 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
596
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
597 if (!quark_popup_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
598 quark_popup_data =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
599 g_quark_from_static_string("GtkItemFactory-popup-data");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
600
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
601 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
602 if (!pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
603 pos = g_new0(MenuPos, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
604
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
605 g_object_set_qdata_full(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
606 quark_user_menu_pos, pos, g_free);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
607 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
608 pos->x = x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
609 pos->y = y;
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 if (data != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
613 g_object_set_qdata_full(G_OBJECT(ifactory),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
614 quark_popup_data, data, destroy);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
615 g_signal_connect(G_OBJECT(ifactory->widget),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
616 "selection-done",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
617 G_CALLBACK(util_menu_delete_popup_data), ifactory);
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 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
621 (GtkMenuPositionFunc) util_menu_position,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
622 pos, mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
623 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
624
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
625 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
626 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
627 guint mouse_button, guint32 time)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
628 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
629 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
630 mouse_button, time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
631 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
632
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
633
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
634 #define URL_HISTORY_MAX_SIZE 30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
635
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
636 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
637 util_add_url_callback(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
638 GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
639 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
640 const gchar *text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
641
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
642 text = gtk_entry_get_text(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
643 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
644 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
645
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
646 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
647
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
648 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
649 GList *node = g_list_last(cfg.url_history);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
650 g_free(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
651 cfg.url_history = g_list_delete_link(cfg.url_history, node);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
652 }
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 GtkWidget *
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
656 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
657 GCallback enqueue_func)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
658 {
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
659 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
660 GList *url;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
661
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
662 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
663 gtk_window_set_title(GTK_WINDOW(win), caption);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
664 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
665 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
666 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
667 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
668
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
669 vbox = gtk_vbox_new(FALSE, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
670 gtk_container_add(GTK_CONTAINER(win), vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
671
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
672 combo = gtk_combo_box_entry_new_text();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
673 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
674
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
675 entry = gtk_bin_get_child(GTK_BIN(combo));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
676 gtk_window_set_focus(GTK_WINDOW(win), entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
677 gtk_entry_set_text(GTK_ENTRY(entry), "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
678
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
679 for (url = cfg.url_history; url; url = g_list_next(url))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
680 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
681
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
682 g_signal_connect(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
683 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
684 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
685 g_signal_connect(entry, "activate",
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
686 G_CALLBACK(ok_func),
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
687 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
688 g_signal_connect_swapped(entry, "activate",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
689 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
690 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
691
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
692 bbox = gtk_hbutton_box_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
693 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
694 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
695 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
696
86
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
697 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
698 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
699 G_CALLBACK(util_add_url_callback), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
700 g_signal_connect(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
701 G_CALLBACK(ok_func), entry);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
702 g_signal_connect_swapped(ok, "clicked",
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
703 G_CALLBACK(gtk_widget_destroy),
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
704 win);
2d8234ea45e8 [svn] - Add a few things to the main menu.
nenolod
parents: 0
diff changeset
705 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
706
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
707 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
708 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
709
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
710 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
711 G_CALLBACK(util_add_url_callback),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
712 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
713 g_signal_connect(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
714 G_CALLBACK(enqueue_func),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
715 entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
716 g_signal_connect_swapped(enqueue, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
717 G_CALLBACK(gtk_widget_destroy),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
718 win);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
719
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
720 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
721 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
722
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
723 g_signal_connect_swapped(cancel, "clicked",
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 gtk_widget_show_all(vbox);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
728
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
729 return win;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
730 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
731
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
732 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
733 filebrowser_add_files(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
734 GSList * files)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
735 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
736 GSList *cur;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
737 gchar *ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
738 guint ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
739
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
740 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
741 gtk_widget_set_sensitive(mainwin_jtf, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
742
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
743 for (cur = files; cur; cur = g_slist_next(cur)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
744
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
745 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
746 playlist_add_dir((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
747 } else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
748 playlist_add((const gchar *) cur->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
749 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
750
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
751 if (++ctr == 20) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
752 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
753 ctr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
754 while (gtk_events_pending() ) gtk_main_iteration();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
755 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
756 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
757
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
758 playlistwin_update_list();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
759
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
760 if (GTK_IS_WIDGET(mainwin_jtf))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
761 gtk_widget_set_sensitive(mainwin_jtf, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
762
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
763 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
764 ptr = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
765 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
766 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
767 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
768
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
769 g_free(cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
770 cfg.filesel_path = ptr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
771 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
772
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
773 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
774 filebrowser_add(GtkFileChooser * browser)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
775 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
776 GSList *files;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
777
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
778 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
779 files = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
780 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
781 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
782 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
783
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
784 if (!files) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
785 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
786 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
787
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
788 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
789 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
790 g_slist_free(files);
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 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
794 filebrowser_play(GtkFileChooser * browser)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
795 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
796 GSList *files;
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 files = gtk_file_chooser_get_uris(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 files = gtk_file_chooser_get_filenames(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 if (!files) return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
805
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
806 playlist_clear();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
807
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
808 filebrowser_add_files(browser, files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
809 g_slist_foreach(files, (GFunc) g_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
810 g_slist_free(files);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
811
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
812 bmp_playback_initiate();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
813 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
814
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
815
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
816 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
817 _filebrowser_add(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
818 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
819 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
820 filebrowser_add(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
821 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
822 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
823
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
824 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
825 _filebrowser_play(GtkWidget *widget, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
826 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
827 filebrowser_play(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
828 gtk_file_chooser_unselect_all(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
829 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
830
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
831 #if 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
832 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
833 filebrowser_on_response(GtkFileChooser * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
834 gint response,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
835 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
836 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
837 gtk_widget_hide(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
838 switch (response) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
839 case GTK_RESPONSE_OK:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
840 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
841 case GTK_RESPONSE_ACCEPT:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
842 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
843 case GTK_RESPONSE_CLOSE:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
844 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
845 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
846 gtk_widget_destroy(GTK_WIDGET(browser));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
847
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 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
851
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
852 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
853 _filebrowser_check_hide_add(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
854 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
855 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
856 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
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_check_hide_open(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
861 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
862 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
863 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
867
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
868 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
869 filebrowser_on_keypress(GtkWidget * browser,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
870 GdkEventKey * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
871 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
872 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
873 if (event->keyval == GDK_Escape) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
874 /* FIXME: this crashes BMP for some reason */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
875 /* g_signal_emit_by_name(browser, "delete-event"); */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
876 gtk_widget_hide(browser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
877 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
878 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
879
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
880 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
881 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
882
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
883 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
884 _filebrowser_do_hide_add(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
885 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
886 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
887 if (cfg.close_dialog_add)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
888 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
889 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
890
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
891 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
892 _filebrowser_do_hide_open(GtkWidget *widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
893 gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
894 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
895 if (cfg.close_dialog_open)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
896 gtk_widget_hide(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
897 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
898
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
899 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
900 util_run_filebrowser(gboolean play_button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
901 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
902 static GladeXML *xml = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
903 static GtkWidget *dialog = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
904 static GtkWidget *chooser = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
905
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
906 static GtkWidget *button_add;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
907 static GtkWidget *button_select_all, *button_deselect_all;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
908 static GtkWidget *toggle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
909
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
910 static gulong handlerid, handlerid_check, handlerid_do;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
911 static gulong handlerid_activate, handlerid_do_activate;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
912
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
913 if (!xml) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
914 /* FIXME: Creating a file chooser dialog manually using
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
915 libglade because there's no way to stop
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
916 GtkFileChooserDialog from resizing the buttons to the same
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
917 size. The long toggle button title causes the buttons to
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
918 turn unnecessarily elongated and fugly. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
919
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
920 GtkWidget *alignment;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
921
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
922 xml = glade_xml_new_or_die(_("Add/Open Files dialog"),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
923 DATA_DIR "/glade/addfiles.glade",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
924 NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
925 glade_xml_signal_autoconnect(xml);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
926
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
927 dialog = glade_xml_get_widget(xml, "add_files_dialog");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
928
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
929 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
930 not support GtkFileChooserWidget */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
931
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
932 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
933 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
934
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
935 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
936 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(chooser), FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
937 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
938
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
939 if (cfg.filesel_path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
940 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
941 gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(chooser),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
942 cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
943 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
944 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
945 cfg.filesel_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
946 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
947
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
948 alignment = glade_xml_get_widget(xml, "alignment2");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
949 gtk_container_add(GTK_CONTAINER(alignment), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
950
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
951 toggle = glade_xml_get_widget(xml, "close_on_action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
952 button_select_all = glade_xml_get_widget(xml, "select_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
953 button_deselect_all = glade_xml_get_widget(xml, "deselect_all");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
954 button_add = glade_xml_get_widget(xml, "action");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
955
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
956 g_signal_connect_swapped(button_select_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
957 G_CALLBACK(gtk_file_chooser_select_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
958 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
959 g_signal_connect_swapped(button_deselect_all, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
960 G_CALLBACK(gtk_file_chooser_unselect_all),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
961 chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
962
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
963 g_signal_connect(dialog, "key_press_event",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
964 G_CALLBACK(filebrowser_on_keypress),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
965 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
966
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
967 gtk_widget_show_all(dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
968 } /* !xml */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
969 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
970 g_signal_handler_disconnect(button_add, handlerid);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
971 g_signal_handler_disconnect(toggle, handlerid_check);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
972 g_signal_handler_disconnect(chooser, handlerid_activate);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
973 g_signal_handler_disconnect(button_add, handlerid_do);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
974 g_signal_handler_disconnect(chooser, handlerid_do_activate);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
975 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
976
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
977 if (play_button) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
978 cfg.close_dialog_open = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
979
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
980 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
981
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
982 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
983
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
984 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
985 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
986
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
987 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
988 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
989 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
990 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
991 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
992 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
993 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
994 cfg.close_dialog_add = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
995
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
996 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
997
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
998 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
999
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1000 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1001 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1002
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1003 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1004 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1005 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
1006 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add), chooser);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1007 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
1008 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1009
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1010 gtk_window_present(GTK_WINDOW(dialog));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1011 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1012
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1013 GdkFont *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1014 util_font_load(const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1015 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1016 GdkFont *font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1017 PangoFontDescription *desc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1018
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1019 desc = pango_font_description_from_string(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1020 font = gdk_font_from_description(desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1021
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1022 return font;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1023 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1024
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1025 #ifdef ENABLE_NLS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1026 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1027 bmp_menu_translate(const gchar * path, gpointer func_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1028 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1029 gchar *translation = gettext(path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1030
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1031 if (!translation || *translation != '/') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1032 g_warning("Bad translation for menupath: %s", path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1033 translation = (gchar *) path;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1034 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1035
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1036 return translation;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1037 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1038 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1039
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1040 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1041 util_set_cursor(GtkWidget * window)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1042 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1043 static GdkCursor *cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1044
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1045 if (!window) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1046 if (cursor) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1047 gdk_cursor_destroy(cursor);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1048 cursor = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1049 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1050 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1051 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1052
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1053 if (!cursor)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1054 cursor = gdk_cursor_new(GDK_LEFT_PTR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1055
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1056 gdk_window_set_cursor(window->window, cursor);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1057 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1058
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1059 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1060 * Mattis et al */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1061 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1062 text_get_extents(const gchar * fontname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1063 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1064 gint * width, gint * height, gint * ascent, gint * descent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1065 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1066 PangoFontDescription *font_desc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1067 PangoLayout *layout;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1068 PangoRectangle rect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1069
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1070 g_return_val_if_fail(fontname != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1071 g_return_val_if_fail(text != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1072
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1073 /* FIXME: resolution */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1074 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1075
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1076 font_desc = pango_font_description_from_string(fontname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1077 pango_layout_set_font_description(layout, font_desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1078 pango_font_description_free(font_desc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1079 pango_layout_get_pixel_extents(layout, NULL, &rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1080
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1081 if (width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1082 *width = rect.width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1083 if (height)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1084 *height = rect.height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1085
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1086 if (ascent || descent) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1087 PangoLayoutIter *iter;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1088 PangoLayoutLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1089
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1090 iter = pango_layout_get_iter(layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1091 line = pango_layout_iter_get_line(iter);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1092 pango_layout_iter_free(iter);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1093
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1094 pango_layout_line_get_pixel_extents(line, NULL, &rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1095
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1096 if (ascent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1097 *ascent = PANGO_ASCENT(rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1098 if (descent)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1099 *descent = -PANGO_DESCENT(rect);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1102 g_object_unref(layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1104 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1105 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1107 /* counts number of digits in a gint */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1108 guint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1109 gint_count_digits(gint n)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1110 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1111 guint count = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1113 n = ABS(n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1114 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1115 count++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1116 n /= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1117 } while (n > 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1119 return count;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1120 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1121
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1122 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1123 str_twenty_to_space(gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1124 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1125 gchar *match, *match_end;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1127 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1129 while ((match = strstr(str, "%20"))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1130 match_end = match + 3;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1131 *match++ = ' ';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1132 while (*match_end)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1133 *match++ = *match_end++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1134 *match = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1137 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1138 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1139
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1140 static gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1141 str_replace_char(gchar * str, gchar old, gchar new)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1142 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1143 gchar *match;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1144
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1145 g_return_val_if_fail(str != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1147 match = str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1148 while ((match = strchr(match, old)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1149 *match = new;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1150
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1151 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1152 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1154 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1155 str_append(gchar * str, const gchar * add_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1156 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1157 return str_replace(str, g_strconcat(str, add_str, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1158 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1159
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1160 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1161 str_replace(gchar * str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1162 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1163 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1164 return new_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1165 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1166
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1167 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1168 str_replace_in(gchar ** str, gchar * new_str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1169 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1170 *str = str_replace(*str, new_str);
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1174 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1175 str_has_prefix_nocase(const gchar * str, const gchar * prefix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1176 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1177 return (strncasecmp(str, prefix, strlen(prefix)) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1178 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1179
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1180 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1181 str_has_suffix_nocase(const gchar * str, const gchar * suffix)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1182 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1183 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1184 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1186 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1187 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1188 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1189 gchar *const *suffix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1191 g_return_val_if_fail(str != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1192 g_return_val_if_fail(suffixes != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1193
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1194 for (suffix = suffixes; *suffix; suffix++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1195 if (str_has_suffix_nocase(str, *suffix))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1196 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1197
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1198 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1199 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1201 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1202 str_to_utf8_fallback(const gchar * str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1203 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1204 gchar *out_str, *convert_str, *chr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1205
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1206 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1207 if (!str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1208 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1210 convert_str = g_strdup(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1211 for (chr = convert_str; *chr; chr++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1212 if (*chr & 0x80)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1213 *chr = '?';
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 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1217 g_free(convert_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1218
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1219 return out_str;
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 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1223 filename_to_utf8(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1224 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1225 gchar *out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1227 /* NULL in NULL out */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1228 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1229 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1231 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1232 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1233
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1234 return str_to_utf8_fallback(filename);
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(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;
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 /* already UTF-8? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1247 if (g_utf8_validate(str, -1, NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1248 return g_strdup(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1249
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1250 /* assume encoding associated with locale */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1251 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1252 return out_str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1253
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1254 /* all else fails, we mask off character codes >= 128,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1255 replace with '?' */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1256 return str_to_utf8_fallback(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1257 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1258
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1259
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1260 const gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1261 str_skip_chars(const gchar * str, const gchar * chars)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1262 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1263 while (strchr(chars, *str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1264 str++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1265 return str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1268 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1269 convert_title_text(gchar * title)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1270 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1271 g_return_val_if_fail(title != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1273 if (cfg.convert_underscore)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1274 str_replace_char(title, '_', ' ');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1276 if (cfg.convert_twenty)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1277 str_twenty_to_space(title);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1278
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1279 return title;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1280 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1281
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1282
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1283 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1284 dir_foreach(const gchar * path, DirForeachFunc function,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1285 gpointer user_data, GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1286 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1287 GError *error_out = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1288 GDir *dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1289 const gchar *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1290 gchar *entry_fullpath;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1291
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1292 if (!(dir = g_dir_open(path, 0, &error_out))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1293 g_propagate_error(error, error_out);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1294 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1295 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1296
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1297 while ((entry = g_dir_read_name(dir))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1298 entry_fullpath = g_build_filename(path, entry, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1299
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1300 if ((*function) (entry_fullpath, entry, user_data)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1301 g_free(entry_fullpath);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1302 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1303 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1304
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1305 g_free(entry_fullpath);
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 g_dir_close(dir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1310 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1311 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1312
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1313 GtkWidget *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1314 make_filebrowser(const gchar * title,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1315 gboolean save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1316 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1317 GtkWidget *dialog;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1318 GtkWidget *button;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1319 GtkWidget *button_close;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1321 g_return_val_if_fail(title != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1323 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
376
94507b102cdb [svn] Sentinel fix; extra NULL required.
chainsaw
parents: 287
diff changeset
1324 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1325 if (save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1326 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1327 GTK_FILE_CHOOSER_ACTION_SAVE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1328
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1329 if (!save)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1330 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1332 g_signal_connect(dialog, "destroy",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1333 G_CALLBACK(gtk_widget_destroyed), &dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1334
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1335 #ifdef HAVE_GNOME_VFS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1336 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1337 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1338
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1339 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1340 GTK_RESPONSE_REJECT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1341 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1342 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1343 g_signal_connect_swapped(button_close, "clicked",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1344 G_CALLBACK(gtk_widget_destroy), dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1345
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1346 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1347 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1348 GTK_RESPONSE_ACCEPT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1349 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1350 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1351 gtk_window_set_default(GTK_WINDOW(dialog), button);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1352
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1353 gtk_widget_show(dialog);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1354
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1355 return dialog;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1356 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1359 GtkItemFactory *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1360 create_menu(GtkItemFactoryEntry *entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1361 guint n_entries,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1362 GtkAccelGroup *accel)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1363 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1364 GtkItemFactory *menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1365
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1366 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1367 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1368 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1369 gtk_item_factory_create_items(menu, n_entries, entries, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1370
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1371 return menu;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1372 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1373
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1374
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1375 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1376 make_submenu(GtkItemFactory *menu,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1377 const gchar *item_path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1378 GtkItemFactory *submenu)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1379 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1380 GtkWidget *item, *menu_;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1381
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1382 item = gtk_item_factory_get_widget(menu, item_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1383 menu_ = gtk_item_factory_get_widget(submenu, "");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1384 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1385 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1386
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1387
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1388
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1389
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1390
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1392