Mercurial > audlegacy
annotate src/audacious/util.c @ 2423:3a41eba0ef5d trunk
[svn] - indentation cleanups
| author | nenolod |
|---|---|
| date | Sat, 27 Jan 2007 04:39:43 -0800 |
| parents | b31111934cd3 |
| children | 3e3d34173207 |
| 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 | |
| 368 gchar * | |
| 369 read_ini_string(const gchar * filename, const gchar * section, | |
| 370 const gchar * key) | |
| 371 { | |
| 372 static gchar *buffer = NULL; | |
| 373 static gchar *open_buffer = NULL; | |
| 374 gchar *ret_buffer = NULL; | |
| 375 gint found_section = 0, len = 0; | |
| 376 static gsize filesize = 0; | |
| 377 gsize off = 0; | |
| 378 gchar *outbuf; | |
| 379 unsigned char x[] = { 0xff, 0xfe, 0x00 }; | |
| 380 guint counter; | |
| 381 | |
| 382 if (!filename) | |
| 383 return NULL; | |
| 384 | |
| 385 /* | |
| 386 * We optimise for the condition that we may be reading from the | |
| 387 * same ini-file multiple times. This is fairly common; it happens | |
| 388 * on .pls playlist loads. To do otherwise would take entirely too | |
| 389 * long, as fstat() can be very slow when done 21,000 times too many. | |
| 390 * | |
| 391 * Therefore, we optimise by keeping the last ini file in memory. | |
| 392 * Yes, this is a memory leak, but it is not too bad, hopefully. | |
| 393 * - nenolod | |
| 394 */ | |
| 395 if (open_buffer == NULL || strcasecmp(filename, open_buffer)) | |
| 396 { | |
| 397 if (buffer != NULL) | |
| 2423 | 398 { |
| 2313 | 399 g_free(buffer); |
| 400 buffer = NULL; | |
| 401 } | |
| 402 | |
| 2423 | 403 if (open_buffer != NULL) |
| 2313 | 404 { |
| 2423 | 405 g_free(open_buffer); |
| 2313 | 406 open_buffer = NULL; |
| 407 } | |
| 408 | |
| 409 if (!g_file_get_contents(filename, &buffer, &filesize, NULL)) | |
| 410 return NULL; | |
| 411 | |
| 412 open_buffer = g_strdup(filename); | |
| 413 } | |
| 414 | |
| 415 /* | |
| 416 * Convert UTF-16 into something useful. Original implementation | |
| 417 * by incomp@#audacious. Cleanups \nenolod | |
| 418 */ | |
| 419 if (!memcmp(&buffer[0],&x,2)) { | |
| 2402 | 420 outbuf = g_malloc (filesize); /* it's safe to waste memory. */ |
| 2313 | 421 |
| 422 for (counter = 2; counter < filesize; counter += 2) | |
| 423 if (!memcmp(&buffer[counter+1], &x[2], 1)) | |
| 424 outbuf[(counter-2)/2] = buffer[counter]; | |
| 425 else | |
| 2402 | 426 return NULL; |
| 2313 | 427 |
| 428 outbuf[(counter-2)/2] = '\0'; | |
| 429 | |
| 430 if ((filesize - 2) / 2 == (counter - 2) / 2) { | |
| 431 g_free(buffer); | |
| 432 buffer = outbuf; | |
| 433 } else { | |
| 434 g_free(outbuf); | |
| 2402 | 435 return NULL; /* XXX wrong encoding */ |
| 2313 | 436 } |
| 437 } | |
| 438 | |
| 439 while (!ret_buffer && off < filesize) { | |
| 440 while (off < filesize && | |
| 441 (buffer[off] == '\r' || buffer[off] == '\n' || | |
| 442 buffer[off] == ' ' || buffer[off] == '\t')) | |
| 443 off++; | |
| 444 if (off >= filesize) | |
| 445 break; | |
| 446 if (buffer[off] == '[') { | |
| 447 gint slen = strlen(section); | |
| 448 off++; | |
| 449 found_section = 0; | |
| 450 if (off + slen + 1 < filesize && | |
| 451 !strncasecmp(section, &buffer[off], slen)) { | |
| 452 off += slen; | |
| 453 if (buffer[off] == ']') { | |
| 454 off++; | |
| 455 found_section = 1; | |
| 456 } | |
| 457 } | |
| 458 } | |
| 459 else if (found_section && off + strlen(key) < filesize && | |
| 460 !strncasecmp(key, &buffer[off], strlen(key))) { | |
| 461 off += strlen(key); | |
| 462 while (off < filesize && | |
| 463 (buffer[off] == ' ' || buffer[off] == '\t')) | |
| 464 off++; | |
| 465 if (off >= filesize) | |
| 466 break; | |
| 467 if (buffer[off] == '=') { | |
| 468 off++; | |
| 469 while (off < filesize && | |
| 470 (buffer[off] == ' ' || buffer[off] == '\t')) | |
| 471 off++; | |
| 472 if (off >= filesize) | |
| 473 break; | |
| 474 len = 0; | |
| 475 while (off + len < filesize && | |
| 476 buffer[off + len] != '\r' && | |
| 477 buffer[off + len] != '\n' && buffer[off + len] != ';') | |
| 478 len++; | |
| 479 ret_buffer = g_strndup(&buffer[off], len); | |
| 480 off += len; | |
| 481 } | |
| 482 } | |
| 483 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n') | |
| 484 off++; | |
| 485 } | |
| 486 | |
| 487 return ret_buffer; | |
| 488 } | |
| 489 | |
| 490 GArray * | |
| 491 string_to_garray(const gchar * str) | |
| 492 { | |
| 493 GArray *array; | |
| 494 gint temp; | |
| 495 const gchar *ptr = str; | |
| 496 gchar *endptr; | |
| 497 | |
| 498 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
| 499 for (;;) { | |
| 500 temp = strtol(ptr, &endptr, 10); | |
| 501 if (ptr == endptr) | |
| 502 break; | |
| 503 g_array_append_val(array, temp); | |
| 504 ptr = endptr; | |
| 505 while (!isdigit((int) *ptr) && (*ptr) != '\0') | |
| 506 ptr++; | |
| 507 if (*ptr == '\0') | |
| 508 break; | |
| 509 } | |
| 510 return (array); | |
| 511 } | |
| 512 | |
| 513 GArray * | |
| 514 read_ini_array(const gchar * filename, const gchar * section, | |
| 515 const gchar * key) | |
| 516 { | |
| 517 gchar *temp; | |
| 518 GArray *a; | |
| 519 | |
| 520 if ((temp = read_ini_string(filename, section, key)) == NULL) { | |
| 521 g_free(temp); | |
| 522 return NULL; | |
| 523 } | |
| 524 a = string_to_garray(temp); | |
| 525 g_free(temp); | |
| 526 return a; | |
| 527 } | |
| 528 | |
| 529 void | |
| 530 glist_movedown(GList * list) | |
| 531 { | |
| 532 gpointer temp; | |
| 533 | |
| 534 if (g_list_next(list)) { | |
| 535 temp = list->data; | |
| 536 list->data = list->next->data; | |
| 537 list->next->data = temp; | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 void | |
| 542 glist_moveup(GList * list) | |
| 543 { | |
| 544 gpointer temp; | |
| 545 | |
| 546 if (g_list_previous(list)) { | |
| 547 temp = list->data; | |
| 548 list->data = list->prev->data; | |
| 549 list->prev->data = temp; | |
| 550 } | |
| 551 } | |
| 552 | |
| 553 | |
| 554 void | |
| 555 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
| 556 gboolean * push_in, gpointer data) | |
| 557 { | |
| 558 GtkRequisition requisition; | |
| 559 gint screen_width; | |
| 560 gint screen_height; | |
| 561 MenuPos *pos = data; | |
| 562 | |
| 563 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
| 564 | |
| 565 screen_width = gdk_screen_width(); | |
| 566 screen_height = gdk_screen_height(); | |
| 567 | |
| 568 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
| 569 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
| 570 } | |
| 571 | |
| 572 GdkFont * | |
| 573 util_font_load(const gchar * name) | |
| 574 { | |
| 575 GdkFont *font; | |
| 576 PangoFontDescription *desc; | |
| 577 | |
| 578 desc = pango_font_description_from_string(name); | |
| 579 font = gdk_font_from_description(desc); | |
| 580 | |
| 581 return font; | |
| 582 } | |
| 583 | |
| 584 #ifdef ENABLE_NLS | |
| 585 gchar * | |
| 586 bmp_menu_translate(const gchar * path, gpointer func_data) | |
| 587 { | |
| 588 gchar *translation = gettext(path); | |
| 589 | |
| 590 if (!translation || *translation != '/') { | |
| 591 g_warning("Bad translation for menupath: %s", path); | |
| 592 translation = (gchar *) path; | |
| 593 } | |
| 594 | |
| 595 return translation; | |
| 596 } | |
| 597 #endif | |
| 598 | |
| 599 void | |
| 600 util_set_cursor(GtkWidget * window) | |
| 601 { | |
| 602 static GdkCursor *cursor = NULL; | |
| 603 | |
| 604 if (!window) { | |
| 605 if (cursor) { | |
| 606 gdk_cursor_unref(cursor); | |
| 607 cursor = NULL; | |
| 608 } | |
| 609 | |
| 610 return; | |
| 611 } | |
| 612 | |
| 613 if (!cursor) | |
| 614 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
| 615 | |
| 616 gdk_window_set_cursor(window->window, cursor); | |
| 617 } | |
| 618 | |
| 619 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter | |
| 620 * Mattis et al */ | |
| 621 gboolean | |
| 622 text_get_extents(const gchar * fontname, | |
| 623 const gchar * text, | |
| 624 gint * width, gint * height, gint * ascent, gint * descent) | |
| 625 { | |
| 626 PangoFontDescription *font_desc; | |
| 627 PangoLayout *layout; | |
| 628 PangoRectangle rect; | |
| 629 | |
| 630 g_return_val_if_fail(fontname != NULL, FALSE); | |
| 631 g_return_val_if_fail(text != NULL, FALSE); | |
| 632 | |
| 633 /* FIXME: resolution */ | |
| 634 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
| 635 | |
| 636 font_desc = pango_font_description_from_string(fontname); | |
| 637 pango_layout_set_font_description(layout, font_desc); | |
| 638 pango_font_description_free(font_desc); | |
| 639 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
| 640 | |
| 641 if (width) | |
| 642 *width = rect.width; | |
| 643 if (height) | |
| 644 *height = rect.height; | |
| 645 | |
| 646 if (ascent || descent) { | |
| 647 PangoLayoutIter *iter; | |
| 648 PangoLayoutLine *line; | |
| 649 | |
| 650 iter = pango_layout_get_iter(layout); | |
| 651 line = pango_layout_iter_get_line(iter); | |
| 652 pango_layout_iter_free(iter); | |
| 653 | |
| 654 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
| 655 | |
| 656 if (ascent) | |
| 657 *ascent = PANGO_ASCENT(rect); | |
| 658 if (descent) | |
| 659 *descent = -PANGO_DESCENT(rect); | |
| 660 } | |
| 661 | |
| 662 g_object_unref(layout); | |
| 663 | |
| 664 return TRUE; | |
| 665 } | |
| 666 | |
| 667 /* counts number of digits in a gint */ | |
| 668 guint | |
| 669 gint_count_digits(gint n) | |
| 670 { | |
| 671 guint count = 0; | |
| 672 | |
| 673 n = ABS(n); | |
| 674 do { | |
| 675 count++; | |
| 676 n /= 10; | |
| 677 } while (n > 0); | |
| 678 | |
| 679 return count; | |
| 680 } | |
| 681 | |
| 682 gboolean | |
| 683 dir_foreach(const gchar * path, DirForeachFunc function, | |
| 684 gpointer user_data, GError ** error) | |
| 685 { | |
| 686 GError *error_out = NULL; | |
| 687 GDir *dir; | |
| 688 const gchar *entry; | |
| 689 gchar *entry_fullpath; | |
| 690 | |
| 691 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
| 692 g_propagate_error(error, error_out); | |
| 693 return FALSE; | |
| 694 } | |
| 695 | |
| 696 while ((entry = g_dir_read_name(dir))) { | |
| 697 entry_fullpath = g_build_filename(path, entry, NULL); | |
| 698 | |
| 699 if ((*function) (entry_fullpath, entry, user_data)) { | |
| 700 g_free(entry_fullpath); | |
| 701 break; | |
| 702 } | |
| 703 | |
| 704 g_free(entry_fullpath); | |
| 705 } | |
| 706 | |
| 707 g_dir_close(dir); | |
| 708 | |
| 709 return TRUE; | |
| 710 } | |
| 711 | |
| 712 GtkWidget * | |
| 713 make_filebrowser(const gchar * title, | |
| 714 gboolean save) | |
| 715 { | |
| 716 GtkWidget *dialog; | |
| 717 GtkWidget *button; | |
| 718 GtkWidget *button_close; | |
| 719 | |
| 720 g_return_val_if_fail(title != NULL, NULL); | |
| 721 | |
| 722 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
| 723 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); | |
| 724 if (save) | |
| 725 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), | |
| 726 GTK_FILE_CHOOSER_ACTION_SAVE); | |
| 727 | |
| 728 if (!save) | |
| 729 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
| 730 | |
| 731 g_signal_connect(dialog, "destroy", | |
| 732 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
| 733 | |
| 734 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
| 735 GTK_RESPONSE_REJECT); | |
| 736 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
| 737 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT); | |
| 738 g_signal_connect_swapped(button_close, "clicked", | |
| 739 G_CALLBACK(gtk_widget_destroy), dialog); | |
| 740 | |
| 741 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
| 742 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
| 743 GTK_RESPONSE_ACCEPT); | |
| 744 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
| 745 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
| 746 gtk_window_set_default(GTK_WINDOW(dialog), button); | |
| 747 | |
| 748 gtk_widget_show(dialog); | |
| 749 | |
| 750 return dialog; | |
| 751 } | |
| 752 | |
| 753 /* | |
| 754 * Resizes a GDK pixmap. | |
| 755 */ | |
| 756 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height) | |
| 757 { | |
| 2402 | 758 GdkPixmap *out; |
| 759 gint owidth, oheight; | |
| 2313 | 760 |
| 2402 | 761 g_return_val_if_fail(src != NULL, NULL); |
| 762 g_return_val_if_fail(src_gc != NULL, NULL); | |
| 763 g_return_val_if_fail(in != NULL, NULL); | |
| 764 g_return_val_if_fail(width > 0 && height > 0, NULL); | |
| 2313 | 765 |
| 2402 | 766 gdk_drawable_get_size(in, &owidth, &oheight); |
| 2313 | 767 |
| 2402 | 768 if (oheight == height && owidth == width) |
| 769 return NULL; | |
| 2313 | 770 |
| 2402 | 771 out = gdk_pixmap_new(src, width, height, -1); |
| 2313 | 772 |
| 2402 | 773 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height); |
| 2313 | 774 |
| 2402 | 775 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight); |
| 776 g_object_unref(src); | |
| 2313 | 777 |
| 2402 | 778 return out; |
| 2313 | 779 } |
| 780 | |
| 781 GdkImage *create_dblsize_image(GdkImage * img) | |
| 782 { | |
| 783 GdkImage *dblimg; | |
| 784 register guint x, y; | |
| 785 | |
| 786 /* | |
| 787 * This needs to be optimized | |
| 788 */ | |
| 789 | |
| 790 dblimg = | |
| 2402 | 791 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), |
| 792 img->width << 1, img->height << 1); | |
| 2313 | 793 if (dblimg->bpp == 1) { |
| 2402 | 794 register guint8 *srcptr, *ptr, *ptr2, pix; |
| 2313 | 795 |
| 2402 | 796 srcptr = GDK_IMAGE(img)->mem; |
| 797 ptr = GDK_IMAGE(dblimg)->mem; | |
| 798 ptr2 = ptr + dblimg->bpl; | |
| 2313 | 799 |
| 2402 | 800 for (y = 0; y < img->height; y++) { |
| 801 for (x = 0; x < img->width; x++) { | |
| 802 pix = *srcptr++; | |
| 803 *ptr++ = pix; | |
| 804 *ptr++ = pix; | |
| 805 *ptr2++ = pix; | |
| 806 *ptr2++ = pix; | |
| 807 } | |
| 808 srcptr += img->bpl - img->width; | |
| 809 ptr += (dblimg->bpl << 1) - dblimg->width; | |
| 810 ptr2 += (dblimg->bpl << 1) - dblimg->width; | |
| 811 } | |
| 2313 | 812 } |
| 813 if (dblimg->bpp == 2) { | |
| 2402 | 814 guint16 *srcptr, *ptr, *ptr2, pix; |
| 2313 | 815 |
| 2402 | 816 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data; |
| 817 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
| 818 ptr2 = ptr + (dblimg->bpl >> 1); | |
| 2313 | 819 |
| 2402 | 820 for (y = 0; y < img->height; y++) { |
| 821 for (x = 0; x < img->width; x++) { | |
| 822 pix = *srcptr++; | |
| 823 *ptr++ = pix; | |
| 824 *ptr++ = pix; | |
| 825 *ptr2++ = pix; | |
| 826 *ptr2++ = pix; | |
| 827 } | |
| 828 srcptr += (img->bpl >> 1) - img->width; | |
| 829 ptr += (dblimg->bpl) - dblimg->width; | |
| 830 ptr2 += (dblimg->bpl) - dblimg->width; | |
| 831 } | |
| 2313 | 832 } |
| 833 if (dblimg->bpp == 3) { | |
| 2402 | 834 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3; |
| 2313 | 835 |
| 2402 | 836 srcptr = GDK_IMAGE(img)->mem; |
| 837 ptr = GDK_IMAGE(dblimg)->mem; | |
| 838 ptr2 = ptr + dblimg->bpl; | |
| 2313 | 839 |
| 2402 | 840 for (y = 0; y < img->height; y++) { |
| 841 for (x = 0; x < img->width; x++) { | |
| 842 pix1 = *srcptr++; | |
| 843 pix2 = *srcptr++; | |
| 844 pix3 = *srcptr++; | |
| 845 *ptr++ = pix1; | |
| 846 *ptr++ = pix2; | |
| 847 *ptr++ = pix3; | |
| 848 *ptr++ = pix1; | |
| 849 *ptr++ = pix2; | |
| 850 *ptr++ = pix3; | |
| 851 *ptr2++ = pix1; | |
| 852 *ptr2++ = pix2; | |
| 853 *ptr2++ = pix3; | |
| 854 *ptr2++ = pix1; | |
| 855 *ptr2++ = pix2; | |
| 856 *ptr2++ = pix3; | |
| 2313 | 857 |
| 2402 | 858 } |
| 859 srcptr += img->bpl - (img->width * 3); | |
| 860 ptr += (dblimg->bpl << 1) - (dblimg->width * 3); | |
| 861 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3); | |
| 862 } | |
| 2313 | 863 } |
| 864 if (dblimg->bpp == 4) { | |
| 2402 | 865 register guint32 *srcptr, *ptr, *ptr2, pix; |
| 2313 | 866 |
| 2402 | 867 srcptr = (guint32 *) GDK_IMAGE(img)->mem; |
| 868 ptr = (guint32 *) GDK_IMAGE(dblimg)->mem; | |
| 869 ptr2 = ptr + (dblimg->bpl >> 2); | |
| 2313 | 870 |
| 2402 | 871 for (y = 0; y < img->height; y++) { |
| 872 for (x = 0; x < img->width; x++) { | |
| 873 pix = *srcptr++; | |
| 874 *ptr++ = pix; | |
| 875 *ptr++ = pix; | |
| 876 *ptr2++ = pix; | |
| 877 *ptr2++ = pix; | |
| 878 } | |
| 879 srcptr += (img->bpl >> 2) - img->width; | |
| 880 ptr += (dblimg->bpl >> 1) - dblimg->width; | |
| 881 ptr2 += (dblimg->bpl >> 1) - dblimg->width; | |
| 882 } | |
| 2313 | 883 } |
| 884 return dblimg; | |
| 885 } | |
| 886 | |
| 887 /* URL-decode a file: URL path, return NULL if it's not what we expect */ | |
| 888 gchar * | |
| 889 xmms_urldecode_path(const gchar * encoded_path) | |
| 890 { | |
| 891 const gchar *cur, *ext; | |
| 892 gchar *path, *tmp; | |
| 893 gint realchar; | |
| 894 | |
| 895 if (!encoded_path) | |
| 896 return NULL; | |
| 897 | |
| 898 if (!str_has_prefix_nocase(encoded_path, "file:")) | |
| 899 return NULL; | |
| 900 | |
| 901 cur = encoded_path + 5; | |
| 902 | |
| 903 if (str_has_prefix_nocase(cur, "//localhost")) | |
| 904 cur += 11; | |
| 905 | |
| 906 if (*cur == '/') | |
| 907 while (cur[1] == '/') | |
| 908 cur++; | |
| 909 | |
| 910 tmp = g_malloc0(strlen(cur) + 1); | |
| 911 | |
| 912 while ((ext = strchr(cur, '%')) != NULL) { | |
| 913 strncat(tmp, cur, ext - cur); | |
| 914 ext++; | |
| 915 cur = ext + 2; | |
| 916 if (!sscanf(ext, "%2x", &realchar)) { | |
| 917 /* Assume it is a literal '%'. Several file | |
| 918 * managers send unencoded file: urls on drag | |
| 919 * and drop. */ | |
| 920 realchar = '%'; | |
| 921 cur -= 2; | |
| 922 } | |
| 923 tmp[strlen(tmp)] = realchar; | |
| 924 } | |
| 925 | |
| 926 path = g_strconcat(tmp, cur, NULL); | |
| 927 g_free(tmp); | |
| 928 return path; | |
| 929 } | |
| 930 | |
|
2421
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
931 /** |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
932 * xmms_show_message: |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
933 * @title: The title of the message to show. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
934 * @text: The text of the message to show. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
935 * @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
|
936 * @modal: Whether or not the messagebox should be modal. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
937 * @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
|
938 * @action_data: Optional opaque data to pass to @button_action. |
|
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 * Displays a message box. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
941 * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
942 * Return value: A GTK widget handle for the message box. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
943 **/ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
944 GtkWidget * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
945 xmms_show_message(const gchar * title, const gchar * text, |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
946 const gchar * button_text, gboolean modal, |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
947 GtkSignalFunc button_action, gpointer action_data) |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
948 { |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
949 GtkWidget *dialog; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
950 GtkWidget *dialog_vbox, *dialog_hbox, *dialog_bbox; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
951 GtkWidget *dialog_bbox_b1; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
952 GtkWidget *dialog_textlabel; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
953 GtkWidget *dialog_icon; |
|
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 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
956 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
|
957 gtk_window_set_modal( GTK_WINDOW(dialog) , modal ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
958 gtk_window_set_title( GTK_WINDOW(dialog) , title ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
959 gtk_container_set_border_width( GTK_CONTAINER(dialog) , 10 ); |
|
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 dialog_vbox = gtk_vbox_new( FALSE , 0 ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
962 dialog_hbox = gtk_hbox_new( FALSE , 0 ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
963 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
964 /* icon */ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
965 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
|
966 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
|
967 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
968 /* label */ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
969 dialog_textlabel = gtk_label_new( text ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
970 /* gtk_label_set_selectable( GTK_LABEL(dialog_textlabel) , TRUE ); */ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
971 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
|
972 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
973 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
|
974 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
|
975 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
976 dialog_bbox = gtk_hbutton_box_new(); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
977 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
|
978 dialog_bbox_b1 = gtk_button_new_with_label( button_text ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
979 g_signal_connect_swapped( G_OBJECT(dialog_bbox_b1) , "clicked" , |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
980 G_CALLBACK(gtk_widget_destroy) , dialog ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
981 if ( button_action ) |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
982 g_signal_connect( G_OBJECT(dialog_bbox_b1) , "clicked" , |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
983 button_action , action_data ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
984 GTK_WIDGET_SET_FLAGS( dialog_bbox_b1 , GTK_CAN_DEFAULT); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
985 gtk_widget_grab_default( dialog_bbox_b1 ); |
|
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 gtk_container_add( GTK_CONTAINER(dialog_bbox) , dialog_bbox_b1 ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
988 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
|
989 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
990 gtk_container_add( GTK_CONTAINER(dialog) , dialog_vbox ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
991 gtk_widget_show_all(dialog); |
|
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 return dialog; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
994 } |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
995 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
996 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
997 /** |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
998 * audacious_get_localdir: |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
999 * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1000 * 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
|
1001 * 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
|
1002 * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1003 * 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
|
1004 **/ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1005 gchar* |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1006 audacious_get_localdir(void) |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1007 { |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1008 gchar *datadir; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1009 gchar *tmp; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1010 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1011 if ( (tmp = getenv("XDG_CONFIG_HOME")) == NULL ) |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1012 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
|
1013 else |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1014 datadir = g_build_filename( tmp , "audacious" , NULL ); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1015 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1016 return datadir; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1017 } |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1018 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1019 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1020 /** |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1021 * xmms_check_realtime_priority: |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1022 * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1023 * Legacy function included for compatibility with XMMS. |
|
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 * Return value: FALSE |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1026 **/ |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1027 gboolean |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1028 xmms_check_realtime_priority(void) |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1029 { |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1030 return FALSE; |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1031 } |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1032 |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1033 /** |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1034 * xmms_usleep: |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1035 * @usec: The amount of microseconds to sleep. |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1036 * |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1037 * Legacy function included for compatibility with XMMS. |
|
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 void |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1040 xmms_usleep(gint usec) |
|
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 g_usleep(usec); |
|
74ec16ef847b
[svn] - fix accidental removal of xmms_show_message
nenolod
parents:
2416
diff
changeset
|
1043 } |
