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