Mercurial > audlegacy
annotate src/audacious/util.c @ 2989:15f6c9949cde trunk
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Thu, 05 Jul 2007 01:40:11 -0500 |
parents | 43a075cb5c81 |
children | 3a907327e228 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 2 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #define NEED_GLADE | |
29 #include "util.h" | |
30 | |
31 #include <glib.h> | |
32 #include <glib/gi18n.h> | |
33 #include <glade/glade.h> | |
34 #include <gtk/gtk.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <ctype.h> | |
38 | |
39 #include "platform/smartinclude.h" | |
40 #include <errno.h> | |
41 | |
42 #ifdef HAVE_FTS_H | |
43 # include <fts.h> | |
44 #endif | |
45 | |
46 #include "glade.h" | |
47 #include "input.h" | |
48 #include "main.h" | |
49 #include "playback.h" | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2365
diff
changeset
|
50 #include "strings.h" |
2313 | 51 #include "ui_playlist.h" |
52 | |
53 #ifdef USE_CHARDET | |
54 #include "../librcd/librcd.h" | |
55 #ifdef HAVE_UDET | |
56 #include <libudet_c.h> | |
57 #endif | |
58 #endif | |
59 | |
60 /* | |
61 * find <file> in directory <dirname> or subdirectories. return | |
62 * pointer to complete filename which has to be freed by calling | |
63 * "g_free()" after use. Returns NULL if file could not be found. | |
64 */ | |
65 | |
66 typedef struct { | |
67 const gchar *to_match; | |
68 gchar *match; | |
69 gboolean found; | |
70 } FindFileContext; | |
71 | |
72 static gboolean | |
73 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
74 { | |
75 FindFileContext *context = data; | |
76 | |
77 if (strlen(path) > FILENAME_MAX) { | |
78 g_warning("Ignoring path: name too long (%s)", path); | |
79 return TRUE; | |
80 } | |
81 | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
82 if (vfs_file_test(path, G_FILE_TEST_IS_REGULAR)) { |
2313 | 83 if (!strcasecmp(basename, context->to_match)) { |
84 context->match = g_strdup(path); | |
85 context->found = TRUE; | |
86 return TRUE; | |
87 } | |
88 } | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
89 else if (vfs_file_test(path, G_FILE_TEST_IS_DIR)) { |
2313 | 90 dir_foreach(path, find_file_func, context, NULL); |
91 if (context->found) | |
92 return TRUE; | |
93 } | |
94 | |
95 return FALSE; | |
96 } | |
97 | |
98 gchar * | |
99 find_file_recursively(const gchar * path, const gchar * filename) | |
100 { | |
101 FindFileContext context; | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
102 gchar *out = NULL; |
2313 | 103 |
104 context.to_match = filename; | |
105 context.match = NULL; | |
106 context.found = FALSE; | |
107 | |
108 dir_foreach(path, find_file_func, &context, NULL); | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
109 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
110 if (context.match) |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
111 { |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
112 out = g_filename_to_uri(context.match, NULL, NULL); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
113 g_free(context.match); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
114 } |
2988
43a075cb5c81
find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents:
2977
diff
changeset
|
115 |
43a075cb5c81
find_file_recursively(): Return a valid URI instead of a literal path.
William Pitcock <nenolod@atheme-project.org>
parents:
2977
diff
changeset
|
116 return out; |
2313 | 117 } |
118 | |
2989
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
119 gchar * |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
120 find_path_recursively(const gchar * path, const gchar * filename) |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
121 { |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
122 FindFileContext context; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
123 gchar *out = NULL; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
124 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
125 context.to_match = filename; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
126 context.match = NULL; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
127 context.found = FALSE; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
128 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
129 dir_foreach(path, find_file_func, &context, NULL); |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
130 |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
131 return context.match; |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
132 } |
15f6c9949cde
Add and use find_path_recursively() which search the FS without using VFS (for GTK).
William Pitcock <nenolod@atheme-project.org>
parents:
2988
diff
changeset
|
133 |
2313 | 134 |
135 typedef enum { | |
136 ARCHIVE_UNKNOWN = 0, | |
137 ARCHIVE_DIR, | |
138 ARCHIVE_TAR, | |
139 ARCHIVE_TGZ, | |
140 ARCHIVE_ZIP, | |
141 ARCHIVE_TBZ2 | |
142 } ArchiveType; | |
143 | |
144 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
145 | |
146 typedef struct { | |
147 ArchiveType type; | |
148 const gchar *ext; | |
149 } ArchiveExtensionType; | |
150 | |
151 static ArchiveExtensionType archive_extensions[] = { | |
152 {ARCHIVE_TAR, ".tar"}, | |
153 {ARCHIVE_ZIP, ".wsz"}, | |
154 {ARCHIVE_ZIP, ".zip"}, | |
155 {ARCHIVE_TGZ, ".tar.gz"}, | |
156 {ARCHIVE_TGZ, ".tgz"}, | |
157 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
158 {ARCHIVE_TBZ2, ".bz2"}, | |
159 {ARCHIVE_UNKNOWN, NULL} | |
160 }; | |
161 | |
162 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
163 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
164 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
165 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
166 | |
167 static ArchiveExtractFunc archive_extract_funcs[] = { | |
168 NULL, | |
169 NULL, | |
170 archive_extract_tar, | |
171 archive_extract_tgz, | |
172 archive_extract_zip, | |
173 archive_extract_tbz2 | |
174 }; | |
175 | |
176 | |
177 /* FIXME: these functions can be generalised into a function using a | |
178 * command lookup table */ | |
179 | |
180 static const gchar * | |
181 get_tar_command(void) | |
182 { | |
183 static const gchar *command = NULL; | |
184 | |
185 if (!command) { | |
186 if (!(command = getenv("TARCMD"))) | |
187 command = "tar"; | |
188 } | |
189 | |
190 return command; | |
191 } | |
192 | |
193 static const gchar * | |
194 get_unzip_command(void) | |
195 { | |
196 static const gchar *command = NULL; | |
197 | |
198 if (!command) { | |
199 if (!(command = getenv("UNZIPCMD"))) | |
200 command = "unzip"; | |
201 } | |
202 | |
203 return command; | |
204 } | |
205 | |
206 | |
207 static gchar * | |
208 archive_extract_tar(const gchar * archive, const gchar * dest) | |
209 { | |
210 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
211 get_tar_command(), archive, dest); | |
212 } | |
213 | |
214 static gchar * | |
215 archive_extract_zip(const gchar * archive, const gchar * dest) | |
216 { | |
217 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
218 get_unzip_command(), archive, dest); | |
219 } | |
220 | |
221 static gchar * | |
222 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
223 { | |
224 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
225 get_tar_command(), archive, dest); | |
226 } | |
227 | |
228 static gchar * | |
229 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
230 { | |
231 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
232 archive, get_tar_command(), dest); | |
233 } | |
234 | |
235 | |
236 ArchiveType | |
237 archive_get_type(const gchar * filename) | |
238 { | |
239 gint i = 0; | |
240 | |
241 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
242 return ARCHIVE_DIR; | |
243 | |
244 while (archive_extensions[i].ext) { | |
245 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
246 return archive_extensions[i].type; | |
247 } | |
248 i++; | |
249 } | |
250 | |
251 return ARCHIVE_UNKNOWN; | |
252 } | |
253 | |
254 gboolean | |
255 file_is_archive(const gchar * filename) | |
256 { | |
257 return (archive_get_type(filename) > ARCHIVE_DIR); | |
258 } | |
259 | |
260 gchar * | |
261 archive_basename(const gchar * str) | |
262 { | |
263 gint i = 0; | |
264 | |
265 while (archive_extensions[i].ext) { | |
266 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
267 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
268 if (end) { | |
269 return g_strndup(str, end - str); | |
270 } | |
271 break; | |
272 } | |
273 i++; | |
274 } | |
275 | |
276 return NULL; | |
277 } | |
278 | |
279 /* | |
280 decompress_archive | |
281 | |
282 Decompresses the archive "filename" to a temporary directory, | |
283 returns the path to the temp dir, or NULL if failed, | |
284 watch out tho, doesn't actually check if the system command succeeds :-| | |
285 */ | |
286 | |
287 gchar * | |
288 archive_decompress(const gchar * filename) | |
289 { | |
290 gchar *tmpdir, *cmd, *escaped_filename; | |
291 ArchiveType type; | |
2328 | 292 #ifndef HAVE_MKDTEMP |
2313 | 293 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
2328 | 294 #endif |
2313 | 295 |
296 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
297 return NULL; | |
298 | |
299 #ifdef HAVE_MKDTEMP | |
300 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); | |
301 if (!mkdtemp(tmpdir)) { | |
302 g_free(tmpdir); | |
303 g_message("Unable to load skin: Failed to create temporary " | |
304 "directory: %s", g_strerror(errno)); | |
305 return NULL; | |
306 } | |
307 #else | |
308 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand()); | |
309 make_directory(tmpdir, mode755); | |
310 #endif | |
311 | |
312 escaped_filename = escape_shell_chars(filename); | |
313 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
314 g_free(escaped_filename); | |
315 | |
316 if (!cmd) { | |
317 g_message("extraction function is NULL!"); | |
318 g_free(tmpdir); | |
319 return NULL; | |
320 } | |
321 | |
2361
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
322 if(system(cmd) == -1) |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
323 { |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
324 g_message("could not execute cmd %s",cmd); |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
325 g_free(cmd); |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
326 return NULL; |
f24ae4f40e29
[svn] - security and warning fixes from ssommer@suse
nenolod
parents:
2332
diff
changeset
|
327 } |
2313 | 328 g_free(cmd); |
329 | |
330 return tmpdir; | |
331 } | |
332 | |
333 | |
334 #ifdef HAVE_FTS_H | |
335 | |
336 void | |
337 del_directory(const gchar * dirname) | |
338 { | |
339 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
340 FTS *fts; | |
341 FTSENT *p; | |
342 | |
343 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
344 while ((p = fts_read(fts))) { | |
345 switch (p->fts_info) { | |
346 case FTS_D: | |
347 break; | |
348 case FTS_DNR: | |
349 case FTS_ERR: | |
350 break; | |
351 case FTS_DP: | |
352 rmdir(p->fts_accpath); | |
353 break; | |
354 default: | |
355 unlink(p->fts_accpath); | |
356 break; | |
357 } | |
358 } | |
359 fts_close(fts); | |
360 } | |
361 | |
362 #else /* !HAVE_FTS */ | |
363 | |
364 gboolean | |
365 del_directory_func(const gchar * path, const gchar * basename, | |
366 gpointer params) | |
367 { | |
368 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
369 return FALSE; | |
370 | |
371 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
372 dir_foreach(path, del_directory_func, NULL, NULL); | |
373 rmdir(path); | |
374 return FALSE; | |
375 } | |
376 | |
377 unlink(path); | |
378 | |
379 return FALSE; | |
380 } | |
381 | |
382 void | |
383 del_directory(const gchar * path) | |
384 { | |
385 dir_foreach(path, del_directory_func, NULL, NULL); | |
386 rmdir(path); | |
387 } | |
388 | |
389 #endif /* ifdef HAVE_FTS */ | |
390 | |
2529 | 391 static void |
392 strip_string(GString *string) | |
393 { | |
394 while (string->len > 0 && string->str[0] == ' ') | |
395 g_string_erase(string, 0, 1); | |
396 | |
397 while (string->len > 0 && string->str[string->len - 1] == ' ') | |
398 g_string_erase(string, string->len - 1, 1); | |
399 } | |
400 | |
401 static void | |
402 strip_lower_string(GString *string) | |
403 { | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
404 gchar *lower; |
2529 | 405 strip_string(string); |
2609 | 406 |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
407 lower = g_ascii_strdown(string->str, -1); |
2529 | 408 g_free(string->str); |
409 string->str = lower; | |
410 } | |
411 | |
412 INIFile * | |
413 open_ini_file(const gchar *filename) | |
2313 | 414 { |
2529 | 415 GHashTable *ini_file = g_hash_table_new(NULL, NULL); |
416 GHashTable *section = g_hash_table_new(NULL, NULL); | |
417 GString *section_name, *key_name, *value; | |
418 gpointer section_hash, key_hash; | |
419 gchar *buffer = NULL; | |
2313 | 420 gsize off = 0; |
2529 | 421 gsize filesize = 0; |
422 | |
2313 | 423 unsigned char x[] = { 0xff, 0xfe, 0x00 }; |
2529 | 424 |
425 | |
426 g_return_val_if_fail(filename, NULL); | |
427 | |
428 section_name = g_string_new(""); | |
429 key_name = g_string_new(NULL); | |
430 value = g_string_new(NULL); | |
2313 | 431 |
2529 | 432 /* make a nameless section which should store all entries that are not |
433 * embedded in a section */ | |
434 section_hash = GINT_TO_POINTER(g_string_hash(section_name)); | |
435 g_hash_table_insert(ini_file, section_hash, section); | |
436 | |
437 vfs_file_get_contents(filename, &buffer, &filesize); | |
438 if (buffer == NULL) | |
2313 | 439 return NULL; |
440 | |
441 | |
442 /* | |
443 * Convert UTF-16 into something useful. Original implementation | |
444 * by incomp@#audacious. Cleanups \nenolod | |
2529 | 445 * FIXME: can't we use a GLib function for that? -- 01mf02 |
2313 | 446 */ |
2607
65543c999c7e
[svn] Check filesize before doing memcmp (potential sigsegv).
hansmi
parents:
2556
diff
changeset
|
447 if (filesize > 2 && !memcmp(&buffer[0],&x,2)) |
2529 | 448 { |
449 gchar *outbuf = g_malloc (filesize); /* it's safe to waste memory. */ | |
450 guint counter; | |
2313 | 451 |
452 for (counter = 2; counter < filesize; counter += 2) | |
2529 | 453 { |
2313 | 454 if (!memcmp(&buffer[counter+1], &x[2], 1)) |
455 outbuf[(counter-2)/2] = buffer[counter]; | |
456 else | |
2529 | 457 return NULL; |
458 } | |
2313 | 459 |
460 outbuf[(counter-2)/2] = '\0'; | |
461 | |
2529 | 462 if ((filesize - 2) / 2 == (counter - 2) / 2) |
463 { | |
2313 | 464 g_free(buffer); |
465 buffer = outbuf; | |
2529 | 466 } |
467 else | |
468 { | |
2313 | 469 g_free(outbuf); |
2529 | 470 return NULL; /* XXX wrong encoding */ |
2313 | 471 } |
472 } | |
473 | |
2529 | 474 while (off < filesize) |
475 { | |
476 /* ignore the following characters */ | |
477 if (buffer[off] == '\r' || buffer[off] == '\n' || | |
478 buffer[off] == ' ' || buffer[off] == '\t') | |
479 { | |
480 if (buffer[off] == '\n') | |
481 { | |
482 g_string_free(key_name, TRUE); | |
483 g_string_free(value, FALSE); | |
484 key_name = g_string_new(NULL); | |
485 value = g_string_new(NULL); | |
486 } | |
487 | |
488 off++; | |
489 continue; | |
490 } | |
491 | |
492 /* if we encounter a possible section statement */ | |
493 if (buffer[off] == '[') | |
494 { | |
495 g_string_free(section_name, TRUE); | |
496 section_name = g_string_new(NULL); | |
2313 | 497 off++; |
2529 | 498 |
499 if (off >= filesize) | |
500 goto return_sequence; | |
501 | |
502 while (buffer[off] != ']') | |
503 { | |
504 /* if the section statement has not been closed before a | |
505 * linebreak */ | |
506 if (buffer[off] == '\n') | |
507 break; | |
508 | |
509 g_string_append_c(section_name, buffer[off]); | |
510 off++; | |
511 if (off >= filesize) | |
512 goto return_sequence; | |
513 } | |
514 if (buffer[off] == '\n') | |
515 continue; | |
516 if (buffer[off] == ']') | |
517 { | |
518 off++; | |
519 if (off >= filesize) | |
520 goto return_sequence; | |
521 | |
522 strip_lower_string(section_name); | |
523 section_hash = GINT_TO_POINTER(g_string_hash(section_name)); | |
524 | |
525 /* if this section already exists, we don't make a new one, | |
526 * but reuse the old one */ | |
527 if (g_hash_table_lookup(ini_file, section_hash) != NULL) | |
528 section = g_hash_table_lookup(ini_file, section_hash); | |
529 else | |
530 { | |
531 section = g_hash_table_new(NULL, NULL); | |
532 g_hash_table_insert(ini_file, section_hash, section); | |
2313 | 533 } |
2529 | 534 |
535 continue; | |
2313 | 536 } |
537 } | |
2529 | 538 |
539 if (buffer[off] == '=') | |
540 { | |
541 off++; | |
2313 | 542 if (off >= filesize) |
2529 | 543 goto return_sequence; |
544 | |
2556 | 545 while (buffer[off] != '\n' && buffer[off] != '\r') |
2529 | 546 { |
547 g_string_append_c(value, buffer[off]); | |
2313 | 548 off++; |
549 if (off >= filesize) | |
550 break; | |
551 } | |
2529 | 552 |
553 strip_lower_string(key_name); | |
554 key_hash = GINT_TO_POINTER(g_string_hash(key_name)); | |
555 strip_string(value); | |
556 | |
557 if (key_name->len > 0 && value->len > 0) | |
2609 | 558 g_hash_table_insert(section, key_hash, g_strdup(value->str)); |
2313 | 559 } |
2529 | 560 else |
561 { | |
562 g_string_append_c(key_name, buffer[off]); | |
2313 | 563 off++; |
2529 | 564 if (off >= filesize) |
565 goto return_sequence; | |
566 } | |
2313 | 567 } |
568 | |
2529 | 569 return_sequence: |
570 g_string_free(section_name, TRUE); | |
571 g_string_free(key_name, TRUE); | |
572 g_string_free(value, TRUE); | |
573 g_free(buffer); | |
574 return ini_file; | |
575 } | |
576 | |
577 void | |
578 close_ini_file(INIFile *inifile) | |
579 { | |
580 g_return_if_fail(inifile); | |
581 | |
582 /* we don't have to destroy anything in the hash table manually, as the | |
583 * keys are represented as integers and the string values may be used in | |
584 * functions which have read the strings from the hash table | |
585 */ | |
586 g_hash_table_destroy(inifile); | |
587 } | |
588 | |
589 gchar * | |
590 read_ini_string(INIFile *inifile, const gchar *section, const gchar *key) | |
591 { | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
592 GString *section_string; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
593 GString *key_string; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
594 gchar *value = NULL; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
595 gpointer section_hash, key_hash; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
596 GHashTable *section_table; |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
597 |
2529 | 598 g_return_val_if_fail(inifile, NULL); |
599 | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
600 section_string = g_string_new(section); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
601 key_string = g_string_new(key); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
602 value = NULL; |
2529 | 603 |
604 strip_lower_string(section_string); | |
605 strip_lower_string(key_string); | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
606 section_hash = GINT_TO_POINTER(g_string_hash(section_string)); |
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
607 key_hash = GINT_TO_POINTER(g_string_hash(key_string)); |
2529 | 608 g_string_free(section_string, FALSE); |
609 g_string_free(key_string, FALSE); | |
610 | |
2660
8d0b89db56e5
[svn] - fixed c++ish declaration in a c file (part 7)
giacomo
parents:
2635
diff
changeset
|
611 section_table = g_hash_table_lookup(inifile, section_hash); |
2529 | 612 g_return_val_if_fail(section_table, NULL); |
613 | |
614 value = g_hash_table_lookup(section_table, GINT_TO_POINTER(key_hash)); | |
615 return value; | |
2313 | 616 } |
617 | |
618 GArray * | |
2529 | 619 read_ini_array(INIFile *inifile, const gchar *section, const gchar *key) |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
620 { |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
621 gchar *temp; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
622 GArray *a; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
623 |
2529 | 624 g_return_val_if_fail((temp = read_ini_string(inifile, section, key)), NULL); |
625 | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
626 a = string_to_garray(temp); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
627 g_free(temp); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
628 return a; |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
629 } |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
630 |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
631 GArray * |
2313 | 632 string_to_garray(const gchar * str) |
633 { | |
634 GArray *array; | |
635 gint temp; | |
636 const gchar *ptr = str; | |
637 gchar *endptr; | |
638 | |
639 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
640 for (;;) { | |
641 temp = strtol(ptr, &endptr, 10); | |
642 if (ptr == endptr) | |
643 break; | |
644 g_array_append_val(array, temp); | |
645 ptr = endptr; | |
646 while (!isdigit((int) *ptr) && (*ptr) != '\0') | |
647 ptr++; | |
648 if (*ptr == '\0') | |
649 break; | |
650 } | |
651 return (array); | |
652 } | |
653 | |
654 void | |
655 glist_movedown(GList * list) | |
656 { | |
657 gpointer temp; | |
658 | |
659 if (g_list_next(list)) { | |
660 temp = list->data; | |
661 list->data = list->next->data; | |
662 list->next->data = temp; | |
663 } | |
664 } | |
665 | |
666 void | |
667 glist_moveup(GList * list) | |
668 { | |
669 gpointer temp; | |
670 | |
671 if (g_list_previous(list)) { | |
672 temp = list->data; | |
673 list->data = list->prev->data; | |
674 list->prev->data = temp; | |
675 } | |
676 } | |
677 | |
678 | |
679 void | |
680 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
681 gboolean * push_in, gpointer data) | |
682 { | |
683 GtkRequisition requisition; | |
684 gint screen_width; | |
685 gint screen_height; | |
686 MenuPos *pos = data; | |
687 | |
688 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
689 | |
690 screen_width = gdk_screen_width(); | |
691 screen_height = gdk_screen_height(); | |
692 | |
693 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
694 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
695 } | |
696 | |
697 GdkFont * | |
698 util_font_load(const gchar * name) | |
699 { | |
700 GdkFont *font; | |
701 PangoFontDescription *desc; | |
702 | |
703 desc = pango_font_description_from_string(name); | |
704 font = gdk_font_from_description(desc); | |
705 | |
706 return font; | |
707 } | |
708 | |
709 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter | |
710 * Mattis et al */ | |
711 gboolean | |
712 text_get_extents(const gchar * fontname, | |
713 const gchar * text, | |
714 gint * width, gint * height, gint * ascent, gint * descent) | |
715 { | |
716 PangoFontDescription *font_desc; | |
717 PangoLayout *layout; | |
718 PangoRectangle rect; | |
719 | |
720 g_return_val_if_fail(fontname != NULL, FALSE); | |
721 g_return_val_if_fail(text != NULL, FALSE); | |
722 | |
723 /* FIXME: resolution */ | |
724 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
725 | |
726 font_desc = pango_font_description_from_string(fontname); | |
727 pango_layout_set_font_description(layout, font_desc); | |
728 pango_font_description_free(font_desc); | |
729 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
730 | |
731 if (width) | |
732 *width = rect.width; | |
733 if (height) | |
734 *height = rect.height; | |
735 | |
736 if (ascent || descent) { | |
737 PangoLayoutIter *iter; | |
738 PangoLayoutLine *line; | |
739 | |
740 iter = pango_layout_get_iter(layout); | |
741 line = pango_layout_iter_get_line(iter); | |
742 pango_layout_iter_free(iter); | |
743 | |
744 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
745 | |
746 if (ascent) | |
747 *ascent = PANGO_ASCENT(rect); | |
748 if (descent) | |
749 *descent = -PANGO_DESCENT(rect); | |
750 } | |
751 | |
752 g_object_unref(layout); | |
753 | |
754 return TRUE; | |
755 } | |
756 | |
757 /* counts number of digits in a gint */ | |
758 guint | |
759 gint_count_digits(gint n) | |
760 { | |
761 guint count = 0; | |
762 | |
763 n = ABS(n); | |
764 do { | |
765 count++; | |
766 n /= 10; | |
767 } while (n > 0); | |
768 | |
769 return count; | |
770 } | |
771 | |
772 gboolean | |
773 dir_foreach(const gchar * path, DirForeachFunc function, | |
774 gpointer user_data, GError ** error) | |
775 { | |
776 GError *error_out = NULL; | |
777 GDir *dir; | |
778 const gchar *entry; | |
779 gchar *entry_fullpath; | |
780 | |
781 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
782 g_propagate_error(error, error_out); | |
783 return FALSE; | |
784 } | |
785 | |
786 while ((entry = g_dir_read_name(dir))) { | |
787 entry_fullpath = g_build_filename(path, entry, NULL); | |
788 | |
789 if ((*function) (entry_fullpath, entry, user_data)) { | |
790 g_free(entry_fullpath); | |
791 break; | |
792 } | |
793 | |
794 g_free(entry_fullpath); | |
795 } | |
796 | |
797 g_dir_close(dir); | |
798 | |
799 return TRUE; | |
800 } | |
801 | |
802 GtkWidget * | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
803 make_filebrowser(const gchar *title, gboolean save) |
2313 | 804 { |
805 GtkWidget *dialog; | |
806 GtkWidget *button; | |
807 | |
808 g_return_val_if_fail(title != NULL, NULL); | |
809 | |
810 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
811 save ? |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
812 GTK_FILE_CHOOSER_ACTION_SAVE : |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
813 GTK_FILE_CHOOSER_ACTION_OPEN, |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
814 NULL, NULL); |
2313 | 815 |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
816 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
817 GTK_RESPONSE_REJECT); |
2313 | 818 |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
819 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); |
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
820 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
2313 | 821 |
822 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
823 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
824 GTK_RESPONSE_ACCEPT); | |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
825 |
2313 | 826 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); |
2514
7934ac463591
[svn] - removed unused function bmp_menu_translate()
mf0102
parents:
2494
diff
changeset
|
827 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); |
2635 | 828 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ |
2313 | 829 |
830 return dialog; | |
831 } | |
832 | |
833 /* | |
834 * Resizes a GDK pixmap. | |
835 */ | |
836 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height) | |
837 { | |
2402 | 838 GdkPixmap *out; |
839 gint owidth, oheight; | |
2313 | 840 |
2402 | 841 g_return_val_if_fail(src != NULL, NULL); |
842 g_return_val_if_fail(src_gc != NULL, NULL); | |
843 g_return_val_if_fail(in != NULL, NULL); | |
844 g_return_val_if_fail(width > 0 && height > 0, NULL); | |
2313 | 845 |
2402 | 846 gdk_drawable_get_size(in, &owidth, &oheight); |
2313 | 847 |
2402 | 848 if (oheight == height && owidth == width) |
849 return NULL; | |
2313 | 850 |
2402 | 851 out = gdk_pixmap_new(src, width, height, -1); |
2313 | 852 |
2402 | 853 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height); |
2313 | 854 |
2402 | 855 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight); |
856 g_object_unref(src); | |
2313 | 857 |
2402 | 858 return out; |
2313 | 859 } |
860 | |
861 GdkImage *create_dblsize_image(GdkImage * img) | |
862 { | |
863 GdkImage *dblimg; | |
864 register guint x, y; | |
865 | |
866 /* | |
867 * This needs to be optimized | |
868 */ | |
869 | |
870 dblimg = | |
2402 | 871 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), |
872 img->width << 1, img->height << 1); | |
2313 | 873 if (dblimg->bpp == 1) { |
2402 | 874 register guint8 *srcptr, *ptr, *ptr2, pix; |
2313 | 875 |
2402 | 876 srcptr = GDK_IMAGE(img)->mem; |
877 ptr = GDK_IMAGE(dblimg)->mem; | |
878 ptr2 = ptr + dblimg->bpl; | |
2313 | 879 |
2402 | 880 for (y = 0; y < img->height; y++) { |
881 for (x = 0; x < img->width; x++) { | |
882 pix = *srcptr++; | |
883 *ptr++ = pix; | |
884 *ptr++ = pix; | |
885 *ptr2++ = pix; | |
886 *ptr2++ = pix; | |
887 } | |
888 srcptr += img->bpl - img->width; | |
889 ptr += (dblimg->bpl << 1) - dblimg->width; | |
890 ptr2 += (dblimg->bpl << 1) - dblimg->width; | |
891 } | |
2313 | 892 } |
893 if (dblimg->bpp == 2) { | |
2402 | 894 guint16 *srcptr, *ptr, *ptr2, pix; |
2313 | 895 |
2402 | 896 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data; |
897 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
898 ptr2 = ptr + (dblimg->bpl >> 1); | |
2313 | 899 |
2402 | 900 for (y = 0; y < img->height; y++) { |
901 for (x = 0; x < img->width; x++) { | |
902 pix = *srcptr++; | |
903 *ptr++ = pix; | |
904 *ptr++ = pix; | |
905 *ptr2++ = pix; | |
906 *ptr2++ = pix; | |
907 } | |
908 srcptr += (img->bpl >> 1) - img->width; | |
909 ptr += (dblimg->bpl) - dblimg->width; | |
910 ptr2 += (dblimg->bpl) - dblimg->width; | |
911 } | |
2313 | 912 } |
913 if (dblimg->bpp == 3) { | |
2402 | 914 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3; |
2313 | 915 |
2402 | 916 srcptr = GDK_IMAGE(img)->mem; |
917 ptr = GDK_IMAGE(dblimg)->mem; | |
918 ptr2 = ptr + dblimg->bpl; | |
2313 | 919 |
2402 | 920 for (y = 0; y < img->height; y++) { |
921 for (x = 0; x < img->width; x++) { | |
922 pix1 = *srcptr++; | |
923 pix2 = *srcptr++; | |
924 pix3 = *srcptr++; | |
925 *ptr++ = pix1; | |
926 *ptr++ = pix2; | |
927 *ptr++ = pix3; | |
928 *ptr++ = pix1; | |
929 *ptr++ = pix2; | |
930 *ptr++ = pix3; | |
931 *ptr2++ = pix1; | |
932 *ptr2++ = pix2; | |
933 *ptr2++ = pix3; | |
934 *ptr2++ = pix1; | |
935 *ptr2++ = pix2; | |
936 *ptr2++ = pix3; | |
2313 | 937 |
2402 | 938 } |
939 srcptr += img->bpl - (img->width * 3); | |
940 ptr += (dblimg->bpl << 1) - (dblimg->width * 3); | |
941 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3); | |
942 } | |
2313 | 943 } |
944 if (dblimg->bpp == 4) { | |
2402 | 945 register guint32 *srcptr, *ptr, *ptr2, pix; |
2313 | 946 |
2402 | 947 srcptr = (guint32 *) GDK_IMAGE(img)->mem; |
948 ptr = (guint32 *) GDK_IMAGE(dblimg)->mem; | |
949 ptr2 = ptr + (dblimg->bpl >> 2); | |
2313 | 950 |
2402 | 951 for (y = 0; y < img->height; y++) { |
952 for (x = 0; x < img->width; x++) { | |
953 pix = *srcptr++; | |
954 *ptr++ = pix; | |
955 *ptr++ = pix; | |
956 *ptr2++ = pix; | |
957 *ptr2++ = pix; | |
958 } | |
959 srcptr += (img->bpl >> 2) - img->width; | |
960 ptr += (dblimg->bpl >> 1) - dblimg->width; | |
961 ptr2 += (dblimg->bpl >> 1) - dblimg->width; | |
962 } | |
2313 | 963 } |
964 return dblimg; | |
965 } | |
966 | |
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
967 /** |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
968 * xmms_show_message: |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
969 * @title: The title of the message to show. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
970 * @text: The text of the message to show. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
971 * @button_text: The text of the button which will close the messagebox. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
972 * @modal: Whether or not the messagebox should be modal. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
973 * @button_action: Code to execute on when the messagebox is closed, or %NULL. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
974 * @action_data: Optional opaque data to pass to @button_action. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
975 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
976 * Displays a message box. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
977 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
978 * Return value: A GTK widget handle for the message box. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
979 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
980 GtkWidget * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
981 xmms_show_message(const gchar * title, const gchar * text, |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
982 const gchar * button_text, gboolean modal, |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
983 GtkSignalFunc button_action, gpointer action_data) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
984 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
985 GtkWidget *dialog; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
986 GtkWidget *dialog_vbox, *dialog_hbox, *dialog_bbox; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
987 GtkWidget *dialog_bbox_b1; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
988 GtkWidget *dialog_textlabel; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
989 GtkWidget *dialog_icon; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
990 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
991 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
992 gtk_window_set_type_hint( GTK_WINDOW(dialog) , GDK_WINDOW_TYPE_HINT_DIALOG ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
993 gtk_window_set_modal( GTK_WINDOW(dialog) , modal ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
994 gtk_window_set_title( GTK_WINDOW(dialog) , title ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
995 gtk_container_set_border_width( GTK_CONTAINER(dialog) , 10 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
996 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
997 dialog_vbox = gtk_vbox_new( FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
998 dialog_hbox = gtk_hbox_new( FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
999 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1000 /* icon */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1001 dialog_icon = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO , GTK_ICON_SIZE_DIALOG ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1002 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_icon , FALSE , FALSE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1003 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1004 /* label */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1005 dialog_textlabel = gtk_label_new( text ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1006 /* gtk_label_set_selectable( GTK_LABEL(dialog_textlabel) , TRUE ); */ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1007 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_textlabel , TRUE , TRUE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1008 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1009 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_hbox , FALSE , FALSE , 2 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1010 gtk_box_pack_start( GTK_BOX(dialog_vbox) , gtk_hseparator_new() , FALSE , FALSE , 4 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1011 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1012 dialog_bbox = gtk_hbutton_box_new(); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1013 gtk_button_box_set_layout( GTK_BUTTON_BOX(dialog_bbox) , GTK_BUTTONBOX_END ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1014 dialog_bbox_b1 = gtk_button_new_with_label( button_text ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1015 g_signal_connect_swapped( G_OBJECT(dialog_bbox_b1) , "clicked" , |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1016 G_CALLBACK(gtk_widget_destroy) , dialog ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1017 if ( button_action ) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1018 g_signal_connect( G_OBJECT(dialog_bbox_b1) , "clicked" , |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1019 button_action , action_data ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1020 GTK_WIDGET_SET_FLAGS( dialog_bbox_b1 , GTK_CAN_DEFAULT); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1021 gtk_widget_grab_default( dialog_bbox_b1 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1022 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1023 gtk_container_add( GTK_CONTAINER(dialog_bbox) , dialog_bbox_b1 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1024 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_bbox , FALSE , FALSE , 0 ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1025 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1026 gtk_container_add( GTK_CONTAINER(dialog) , dialog_vbox ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1027 gtk_widget_show_all(dialog); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1028 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1029 return dialog; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1030 } |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1031 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1032 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1033 /** |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1034 * audacious_get_localdir: |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1035 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1036 * Returns a string with the full path of Audacious local datadir (where config files are placed). |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1037 * It's useful in order to put in the right place custom config files for audacious plugins. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1038 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1039 * Return value: a string with full path of Audacious local datadir (should be freed after use) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1040 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1041 gchar* |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1042 audacious_get_localdir(void) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1043 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1044 gchar *datadir; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1045 gchar *tmp; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1046 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1047 if ( (tmp = getenv("XDG_CONFIG_HOME")) == NULL ) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1048 datadir = g_build_filename( g_get_home_dir() , ".config" , "audacious" , NULL ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1049 else |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1050 datadir = g_build_filename( tmp , "audacious" , NULL ); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1051 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1052 return datadir; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1053 } |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1054 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1055 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1056 /** |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1057 * xmms_check_realtime_priority: |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1058 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1059 * Legacy function included for compatibility with XMMS. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1060 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1061 * Return value: FALSE |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1062 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1063 gboolean |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1064 xmms_check_realtime_priority(void) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1065 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1066 return FALSE; |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1067 } |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1068 |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1069 /** |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1070 * xmms_usleep: |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1071 * @usec: The amount of microseconds to sleep. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1072 * |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1073 * Legacy function included for compatibility with XMMS. |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1074 **/ |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1075 void |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1076 xmms_usleep(gint usec) |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1077 { |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1078 g_usleep(usec); |
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1079 } |