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