annotate audacious/util.c @ 96:8dbd2d31c1f7 trunk

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