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