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