Mercurial > audlegacy
annotate audacious/util.c @ 2065:598564ddc4e9 trunk
[svn] - no, this is not going to work
| author | nenolod |
|---|---|
| date | Thu, 07 Dec 2006 00:22:55 -0800 |
| parents | d3a62e1075e2 |
| children | c725daec3849 |
| rev | line source |
|---|---|
| 0 | 1 /* BMP - Cross-platform multimedia player |
| 2 * Copyright (C) 2003-2004 BMP development team. | |
| 3 * | |
| 4 * Based on XMMS: | |
| 5 * Copyright (C) 1998-2003 XMMS development team. | |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 0 | 20 */ |
| 21 | |
|
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
22 #define WEIRD_UTF_16_PLAYLIST_ENCODING |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
23 |
| 0 | 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 <stdio.h> | |
| 36 #include <stdlib.h> | |
| 37 #include <string.h> | |
| 38 #include <ctype.h> | |
| 39 | |
| 1640 | 40 #include "platform/smartinclude.h" |
| 0 | 41 #include <gdk/gdkkeysyms.h> |
| 42 #include <X11/Xlib.h> | |
|
287
2d919c756941
[svn] - attach -Iaudacious to libaudcore build crap.
nenolod
parents:
284
diff
changeset
|
43 //#include <sys/ipc.h> |
| 0 | 44 #include <unistd.h> |
| 45 #include <errno.h> | |
| 46 | |
| 47 #ifdef HAVE_FTS_H | |
| 48 # include <fts.h> | |
| 49 #endif | |
| 50 | |
| 51 #include "glade.h" | |
| 52 #include "input.h" | |
| 53 #include "main.h" | |
|
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
383
diff
changeset
|
54 #include "playback.h" |
| 0 | 55 #include "playlist.h" |
| 1653 | 56 #include "ui_playlist.h" |
| 0 | 57 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
58 #ifdef USE_CHARDET |
| 1106 | 59 #include "../libguess/libguess.h" |
|
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
60 #include "../librcd/librcd.h" |
| 1106 | 61 #ifdef HAVE_UDET |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
62 #include <libudet_c.h> |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
63 #endif |
| 1106 | 64 #endif |
| 0 | 65 |
| 66 static GQuark quark_popup_data; | |
| 67 | |
| 68 | |
| 69 /* | |
| 70 * escape_shell_chars() | |
| 71 * | |
| 72 * Escapes characters that are special to the shell inside double quotes. | |
| 73 */ | |
| 74 | |
| 75 gchar * | |
| 76 escape_shell_chars(const gchar * string) | |
| 77 { | |
| 78 const gchar *special = "$`\"\\"; /* Characters to escape */ | |
| 79 const gchar *in = string; | |
| 80 gchar *out, *escaped; | |
| 81 gint num = 0; | |
| 82 | |
| 83 while (*in != '\0') | |
| 84 if (strchr(special, *in++)) | |
| 85 num++; | |
| 86 | |
| 87 escaped = g_malloc(strlen(string) + num + 1); | |
| 88 | |
| 89 in = string; | |
| 90 out = escaped; | |
| 91 | |
| 92 while (*in != '\0') { | |
| 93 if (strchr(special, *in)) | |
| 94 *out++ = '\\'; | |
| 95 *out++ = *in++; | |
| 96 } | |
| 97 *out = '\0'; | |
| 98 | |
| 99 return escaped; | |
| 100 } | |
| 101 | |
| 102 | |
| 103 /* | |
| 104 * find <file> in directory <dirname> or subdirectories. return | |
| 105 * pointer to complete filename which has to be freed by calling | |
| 106 * "g_free()" after use. Returns NULL if file could not be found. | |
| 107 */ | |
| 108 | |
| 109 typedef struct { | |
| 110 const gchar *to_match; | |
| 111 gchar *match; | |
| 112 gboolean found; | |
| 113 } FindFileContext; | |
| 114 | |
| 115 static gboolean | |
| 116 find_file_func(const gchar * path, const gchar * basename, gpointer data) | |
| 117 { | |
| 118 FindFileContext *context = data; | |
| 119 | |
| 120 if (strlen(path) > FILENAME_MAX) { | |
| 121 g_warning("Ignoring path: name too long (%s)", path); | |
| 122 return TRUE; | |
| 123 } | |
| 124 | |
| 125 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { | |
| 126 if (!strcasecmp(basename, context->to_match)) { | |
| 127 context->match = g_strdup(path); | |
| 128 context->found = TRUE; | |
| 129 return TRUE; | |
| 130 } | |
| 131 } | |
| 132 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
| 133 dir_foreach(path, find_file_func, context, NULL); | |
| 134 if (context->found) | |
| 135 return TRUE; | |
| 136 } | |
| 137 | |
| 138 return FALSE; | |
| 139 } | |
| 140 | |
| 141 gchar * | |
| 142 find_file_recursively(const gchar * path, const gchar * filename) | |
| 143 { | |
| 144 FindFileContext context; | |
| 145 | |
| 146 context.to_match = filename; | |
| 147 context.match = NULL; | |
| 148 context.found = FALSE; | |
| 149 | |
| 150 dir_foreach(path, find_file_func, &context, NULL); | |
| 151 return context.match; | |
| 152 } | |
| 153 | |
| 154 | |
| 155 typedef enum { | |
| 156 ARCHIVE_UNKNOWN = 0, | |
| 157 ARCHIVE_DIR, | |
| 158 ARCHIVE_TAR, | |
| 159 ARCHIVE_TGZ, | |
| 160 ARCHIVE_ZIP, | |
| 161 ARCHIVE_TBZ2 | |
| 162 } ArchiveType; | |
| 163 | |
| 164 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *); | |
| 165 | |
| 166 typedef struct { | |
| 167 ArchiveType type; | |
| 168 const gchar *ext; | |
| 169 } ArchiveExtensionType; | |
| 170 | |
| 171 static ArchiveExtensionType archive_extensions[] = { | |
| 172 {ARCHIVE_TAR, ".tar"}, | |
| 173 {ARCHIVE_ZIP, ".wsz"}, | |
| 174 {ARCHIVE_ZIP, ".zip"}, | |
| 175 {ARCHIVE_TGZ, ".tar.gz"}, | |
| 176 {ARCHIVE_TGZ, ".tgz"}, | |
| 177 {ARCHIVE_TBZ2, ".tar.bz2"}, | |
| 178 {ARCHIVE_TBZ2, ".bz2"}, | |
| 179 {ARCHIVE_UNKNOWN, NULL} | |
| 180 }; | |
| 181 | |
| 182 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest); | |
| 183 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest); | |
| 184 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest); | |
| 185 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest); | |
| 186 | |
| 187 static ArchiveExtractFunc archive_extract_funcs[] = { | |
| 188 NULL, | |
| 189 NULL, | |
| 190 archive_extract_tar, | |
| 191 archive_extract_tgz, | |
| 192 archive_extract_zip, | |
| 193 archive_extract_tbz2 | |
| 194 }; | |
| 195 | |
| 196 | |
| 197 /* FIXME: these functions can be generalised into a function using a | |
| 198 * command lookup table */ | |
| 199 | |
| 200 static const gchar * | |
| 201 get_tar_command(void) | |
| 202 { | |
| 203 static const gchar *command = NULL; | |
| 204 | |
| 205 if (!command) { | |
| 206 if (!(command = getenv("TARCMD"))) | |
| 207 command = "tar"; | |
| 208 } | |
| 209 | |
| 210 return command; | |
| 211 } | |
| 212 | |
| 213 static const gchar * | |
| 214 get_unzip_command(void) | |
| 215 { | |
| 216 static const gchar *command = NULL; | |
| 217 | |
| 218 if (!command) { | |
| 219 if (!(command = getenv("UNZIPCMD"))) | |
| 220 command = "unzip"; | |
| 221 } | |
| 222 | |
| 223 return command; | |
| 224 } | |
| 225 | |
| 226 | |
| 227 static gchar * | |
| 228 archive_extract_tar(const gchar * archive, const gchar * dest) | |
| 229 { | |
| 230 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s", | |
| 231 get_tar_command(), archive, dest); | |
| 232 } | |
| 233 | |
| 234 static gchar * | |
| 235 archive_extract_zip(const gchar * archive, const gchar * dest) | |
| 236 { | |
| 237 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s", | |
| 238 get_unzip_command(), archive, dest); | |
| 239 } | |
| 240 | |
| 241 static gchar * | |
| 242 archive_extract_tgz(const gchar * archive, const gchar * dest) | |
| 243 { | |
| 244 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s", | |
| 245 get_tar_command(), archive, dest); | |
| 246 } | |
| 247 | |
| 248 static gchar * | |
| 249 archive_extract_tbz2(const gchar * archive, const gchar * dest) | |
| 250 { | |
| 251 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s", | |
| 252 archive, get_tar_command(), dest); | |
| 253 } | |
| 254 | |
| 255 | |
| 256 ArchiveType | |
| 257 archive_get_type(const gchar * filename) | |
| 258 { | |
| 259 gint i = 0; | |
| 260 | |
| 261 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) | |
| 262 return ARCHIVE_DIR; | |
| 263 | |
| 264 while (archive_extensions[i].ext) { | |
| 265 if (g_str_has_suffix(filename, archive_extensions[i].ext)) { | |
| 266 return archive_extensions[i].type; | |
| 267 } | |
| 268 i++; | |
| 269 } | |
| 270 | |
| 271 return ARCHIVE_UNKNOWN; | |
| 272 } | |
| 273 | |
| 274 gboolean | |
| 275 file_is_archive(const gchar * filename) | |
| 276 { | |
| 277 return (archive_get_type(filename) > ARCHIVE_DIR); | |
| 278 } | |
| 279 | |
| 280 gchar * | |
| 281 archive_basename(const gchar * str) | |
| 282 { | |
| 283 gint i = 0; | |
| 284 | |
| 285 while (archive_extensions[i].ext) { | |
| 286 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) { | |
| 287 const gchar *end = g_strrstr(str, archive_extensions[i].ext); | |
| 288 if (end) { | |
| 289 return g_strndup(str, end - str); | |
| 290 } | |
| 291 break; | |
| 292 } | |
| 293 i++; | |
| 294 } | |
| 295 | |
| 296 return NULL; | |
| 297 } | |
| 298 | |
| 299 /* | |
| 300 decompress_archive | |
| 301 | |
| 302 Decompresses the archive "filename" to a temporary directory, | |
| 303 returns the path to the temp dir, or NULL if failed, | |
| 304 watch out tho, doesn't actually check if the system command succeeds :-| | |
| 305 */ | |
| 306 | |
| 307 gchar * | |
| 308 archive_decompress(const gchar * filename) | |
| 309 { | |
| 310 gchar *tmpdir, *cmd, *escaped_filename; | |
| 311 ArchiveType type; | |
| 1890 | 312 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
| 0 | 313 |
| 314 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) | |
| 315 return NULL; | |
| 316 | |
| 1890 | 317 #ifdef HAVE_MKDTEMP |
| 318 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); | |
| 0 | 319 if (!mkdtemp(tmpdir)) { |
| 320 g_free(tmpdir); | |
| 321 g_message("Unable to load skin: Failed to create temporary " | |
| 322 "directory: %s", g_strerror(errno)); | |
| 323 return NULL; | |
| 324 } | |
| 1890 | 325 #else |
| 1891 | 326 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), rand()); |
| 1890 | 327 make_directory(tmpdir, mode755); |
| 328 #endif | |
| 0 | 329 |
| 330 escaped_filename = escape_shell_chars(filename); | |
| 331 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); | |
| 332 g_free(escaped_filename); | |
| 333 | |
| 334 if (!cmd) { | |
| 335 g_message("extraction function is NULL!"); | |
| 336 g_free(tmpdir); | |
| 337 return NULL; | |
| 338 } | |
| 339 | |
| 340 system(cmd); | |
| 341 g_free(cmd); | |
| 342 | |
| 343 return tmpdir; | |
| 344 } | |
| 345 | |
| 346 | |
| 347 #ifdef HAVE_FTS_H | |
| 348 | |
| 349 void | |
| 350 del_directory(const gchar * dirname) | |
| 351 { | |
| 352 gchar *const argv[2] = { (gchar *) dirname, NULL }; | |
| 353 FTS *fts; | |
| 354 FTSENT *p; | |
| 355 | |
| 356 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL); | |
| 357 while ((p = fts_read(fts))) { | |
| 358 switch (p->fts_info) { | |
| 359 case FTS_D: | |
| 360 break; | |
| 361 case FTS_DNR: | |
| 362 case FTS_ERR: | |
| 363 break; | |
| 364 case FTS_DP: | |
| 365 rmdir(p->fts_accpath); | |
| 366 break; | |
| 367 default: | |
| 368 unlink(p->fts_accpath); | |
| 369 break; | |
| 370 } | |
| 371 } | |
| 372 fts_close(fts); | |
| 373 } | |
| 374 | |
| 375 #else /* !HAVE_FTS */ | |
| 376 | |
| 377 gboolean | |
| 378 del_directory_func(const gchar * path, const gchar * basename, | |
| 379 gpointer params) | |
| 380 { | |
| 381 if (!strcmp(basename, ".") || !strcmp(path, "..")) | |
| 382 return FALSE; | |
| 383 | |
| 384 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
| 385 dir_foreach(path, del_directory_func, NULL, NULL); | |
| 386 rmdir(path); | |
| 387 return FALSE; | |
| 388 } | |
| 389 | |
| 390 unlink(path); | |
| 391 | |
| 392 return FALSE; | |
| 393 } | |
| 394 | |
| 395 void | |
| 396 del_directory(const gchar * path) | |
| 397 { | |
| 398 dir_foreach(path, del_directory_func, NULL, NULL); | |
| 399 rmdir(path); | |
| 400 } | |
| 401 | |
| 402 #endif /* ifdef HAVE_FTS */ | |
| 403 | |
| 404 gchar * | |
| 405 read_ini_string(const gchar * filename, const gchar * section, | |
| 406 const gchar * key) | |
| 407 { | |
|
1166
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
408 static gchar *buffer = NULL; |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
409 static gchar *open_buffer = NULL; |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
410 gchar *ret_buffer = NULL; |
|
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
411 gint found_section = 0, len = 0; |
|
1193
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
412 static gsize filesize = 0; |
|
03414b9d2507
[svn] filesize must be cached, otherwise lookup loop will crash.
yaz
parents:
1166
diff
changeset
|
413 gsize off = 0; |
|
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
414 gchar *outbuf; |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
415 unsigned char x[] = { 0xff, 0xfe, 0x00 }; |
|
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
416 guint counter; |
| 0 | 417 |
| 418 if (!filename) | |
| 419 return NULL; | |
| 420 | |
|
1166
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
421 /* |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
422 * We optimise for the condition that we may be reading from the |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
423 * same ini-file multiple times. This is fairly common; it happens |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
424 * on .pls playlist loads. To do otherwise would take entirely too |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
425 * long, as fstat() can be very slow when done 21,000 times too many. |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
426 * |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
427 * Therefore, we optimise by keeping the last ini file in memory. |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
428 * Yes, this is a memory leak, but it is not too bad, hopefully. |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
429 * - nenolod |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
430 */ |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
431 if (open_buffer == NULL || strcasecmp(filename, open_buffer)) |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
432 { |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
433 if (buffer != NULL) |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
434 { |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
435 g_free(buffer); |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
436 buffer = NULL; |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
437 } |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
438 |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
439 if (open_buffer != NULL) |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
440 { |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
441 g_free(open_buffer); |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
442 open_buffer = NULL; |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
443 } |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
444 |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
445 if (!g_file_get_contents(filename, &buffer, &filesize, NULL)) |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
446 return NULL; |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
447 |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
448 open_buffer = g_strdup(filename); |
|
36e8431d8e19
[svn] - optimise for multiple lookups of a single INI file, by caching the contents of the INI file.
nenolod
parents:
1123
diff
changeset
|
449 } |
| 0 | 450 |
|
245
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
451 /* |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
452 * Convert UTF-16 into something useful. Original implementation |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
453 * by incomp@#audacious. Cleanups \nenolod |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
454 */ |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
455 if (!memcmp(&buffer[0],&x,2)) { |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
456 outbuf = g_malloc (filesize); /* it's safe to waste memory. */ |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
457 |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
458 for (counter = 2; counter < filesize; counter += 2) |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
459 if (!memcmp(&buffer[counter+1], &x[2], 1)) |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
460 outbuf[(counter-2)/2] = buffer[counter]; |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
461 else |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
462 return NULL; |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
463 |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
464 outbuf[(counter-2)/2] = '\0'; |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
465 |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
466 if ((filesize - 2) / 2 == (counter - 2) / 2) { |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
467 g_free(buffer); |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
468 buffer = outbuf; |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
469 } else { |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
470 g_free(outbuf); |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
471 return NULL; /* XXX wrong encoding */ |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
472 } |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
473 } |
|
1d8012046612
[svn] Convert UTF-16 (windows-1252) into something useful. Original patch by incomp@#audacious,
nenolod
parents:
86
diff
changeset
|
474 |
| 0 | 475 while (!ret_buffer && off < filesize) { |
| 476 while (off < filesize && | |
| 477 (buffer[off] == '\r' || buffer[off] == '\n' || | |
| 478 buffer[off] == ' ' || buffer[off] == '\t')) | |
| 479 off++; | |
| 480 if (off >= filesize) | |
| 481 break; | |
| 482 if (buffer[off] == '[') { | |
| 483 gint slen = strlen(section); | |
| 484 off++; | |
| 485 found_section = 0; | |
| 486 if (off + slen + 1 < filesize && | |
| 487 !strncasecmp(section, &buffer[off], slen)) { | |
| 488 off += slen; | |
| 489 if (buffer[off] == ']') { | |
| 490 off++; | |
| 491 found_section = 1; | |
| 492 } | |
| 493 } | |
| 494 } | |
| 495 else if (found_section && off + strlen(key) < filesize && | |
| 496 !strncasecmp(key, &buffer[off], strlen(key))) { | |
| 497 off += strlen(key); | |
| 498 while (off < filesize && | |
| 499 (buffer[off] == ' ' || buffer[off] == '\t')) | |
| 500 off++; | |
| 501 if (off >= filesize) | |
| 502 break; | |
| 503 if (buffer[off] == '=') { | |
| 504 off++; | |
| 505 while (off < filesize && | |
| 506 (buffer[off] == ' ' || buffer[off] == '\t')) | |
| 507 off++; | |
| 508 if (off >= filesize) | |
| 509 break; | |
| 510 len = 0; | |
| 511 while (off + len < filesize && | |
| 512 buffer[off + len] != '\r' && | |
| 513 buffer[off + len] != '\n' && buffer[off + len] != ';') | |
| 514 len++; | |
| 515 ret_buffer = g_strndup(&buffer[off], len); | |
| 516 off += len; | |
| 517 } | |
| 518 } | |
| 519 while (off < filesize && buffer[off] != '\r' && buffer[off] != '\n') | |
| 520 off++; | |
| 521 } | |
| 522 | |
| 523 return ret_buffer; | |
| 524 } | |
| 525 | |
| 526 GArray * | |
| 527 string_to_garray(const gchar * str) | |
| 528 { | |
| 529 GArray *array; | |
| 530 gint temp; | |
| 531 const gchar *ptr = str; | |
| 532 gchar *endptr; | |
| 533 | |
| 534 array = g_array_new(FALSE, TRUE, sizeof(gint)); | |
| 535 for (;;) { | |
| 536 temp = strtol(ptr, &endptr, 10); | |
| 537 if (ptr == endptr) | |
| 538 break; | |
| 539 g_array_append_val(array, temp); | |
| 540 ptr = endptr; | |
|
1717
837983bac90f
[svn] Fixed a lot of warnings that only showed up on *BSD.
js
parents:
1653
diff
changeset
|
541 while (!isdigit((int) *ptr) && (*ptr) != '\0') |
| 0 | 542 ptr++; |
| 543 if (*ptr == '\0') | |
| 544 break; | |
| 545 } | |
| 546 return (array); | |
| 547 } | |
| 548 | |
| 549 GArray * | |
| 550 read_ini_array(const gchar * filename, const gchar * section, | |
| 551 const gchar * key) | |
| 552 { | |
| 553 gchar *temp; | |
| 554 GArray *a; | |
| 555 | |
| 556 if ((temp = read_ini_string(filename, section, key)) == NULL) { | |
| 557 g_free(temp); | |
| 558 return NULL; | |
| 559 } | |
| 560 a = string_to_garray(temp); | |
| 561 g_free(temp); | |
| 562 return a; | |
| 563 } | |
| 564 | |
| 565 void | |
| 566 glist_movedown(GList * list) | |
| 567 { | |
| 568 gpointer temp; | |
| 569 | |
| 570 if (g_list_next(list)) { | |
| 571 temp = list->data; | |
| 572 list->data = list->next->data; | |
| 573 list->next->data = temp; | |
| 574 } | |
| 575 } | |
| 576 | |
| 577 void | |
| 578 glist_moveup(GList * list) | |
| 579 { | |
| 580 gpointer temp; | |
| 581 | |
| 582 if (g_list_previous(list)) { | |
| 583 temp = list->data; | |
| 584 list->data = list->prev->data; | |
| 585 list->prev->data = temp; | |
| 586 } | |
| 587 } | |
| 588 | |
| 589 | |
| 590 void | |
| 591 util_menu_position(GtkMenu * menu, gint * x, gint * y, | |
| 592 gboolean * push_in, gpointer data) | |
| 593 { | |
| 594 GtkRequisition requisition; | |
| 595 gint screen_width; | |
| 596 gint screen_height; | |
| 597 MenuPos *pos = data; | |
| 598 | |
| 599 gtk_widget_size_request(GTK_WIDGET(menu), &requisition); | |
| 600 | |
| 601 screen_width = gdk_screen_width(); | |
| 602 screen_height = gdk_screen_height(); | |
| 603 | |
| 604 *x = CLAMP(pos->x - 2, 0, MAX(0, screen_width - requisition.width)); | |
| 605 *y = CLAMP(pos->y - 2, 0, MAX(0, screen_height - requisition.height)); | |
| 606 } | |
| 607 | |
| 608 static void | |
| 609 util_menu_delete_popup_data(GtkObject * object, GtkItemFactory * ifactory) | |
| 610 { | |
| 611 gtk_signal_disconnect_by_func(object, | |
| 612 GTK_SIGNAL_FUNC | |
| 613 (util_menu_delete_popup_data), ifactory); | |
| 614 gtk_object_remove_data_by_id(GTK_OBJECT(ifactory), quark_popup_data); | |
| 615 } | |
| 616 | |
| 617 | |
| 618 /* | |
| 619 * util_item_factory_popup[_with_data]() is a replacement for | |
| 620 * gtk_item_factory_popup[_with_data](). | |
| 621 * | |
| 622 * The difference is that the menu is always popped up whithin the | |
| 623 * screen. This means it does not neccesarily pop up at (x,y). | |
| 624 */ | |
| 625 | |
| 626 void | |
| 627 util_item_factory_popup_with_data(GtkItemFactory * ifactory, | |
| 628 gpointer data, | |
| 629 GtkDestroyNotify destroy, guint x, | |
| 630 guint y, guint mouse_button, guint32 time) | |
| 631 { | |
| 632 static GQuark quark_user_menu_pos = 0; | |
| 633 MenuPos *pos; | |
| 634 | |
| 635 if (!quark_user_menu_pos) | |
| 636 quark_user_menu_pos = g_quark_from_static_string("user_menu_pos"); | |
| 637 | |
| 638 if (!quark_popup_data) | |
| 639 quark_popup_data = | |
| 640 g_quark_from_static_string("GtkItemFactory-popup-data"); | |
| 641 | |
| 642 pos = g_object_get_qdata(G_OBJECT(ifactory), quark_user_menu_pos); | |
| 643 if (!pos) { | |
| 644 pos = g_new0(MenuPos, 1); | |
| 645 | |
| 646 g_object_set_qdata_full(G_OBJECT(ifactory->widget), | |
| 647 quark_user_menu_pos, pos, g_free); | |
| 648 } | |
| 649 pos->x = x; | |
| 650 pos->y = y; | |
| 651 | |
| 652 | |
| 653 if (data != NULL) { | |
| 654 g_object_set_qdata_full(G_OBJECT(ifactory), | |
| 655 quark_popup_data, data, destroy); | |
| 656 g_signal_connect(G_OBJECT(ifactory->widget), | |
| 657 "selection-done", | |
| 658 G_CALLBACK(util_menu_delete_popup_data), ifactory); | |
| 659 } | |
| 660 | |
| 661 gtk_menu_popup(GTK_MENU(ifactory->widget), NULL, NULL, | |
| 662 (GtkMenuPositionFunc) util_menu_position, | |
| 663 pos, mouse_button, time); | |
| 664 } | |
| 665 | |
| 666 void | |
| 667 util_item_factory_popup(GtkItemFactory * ifactory, guint x, guint y, | |
| 668 guint mouse_button, guint32 time) | |
| 669 { | |
| 670 util_item_factory_popup_with_data(ifactory, NULL, NULL, x, y, | |
| 671 mouse_button, time); | |
| 672 } | |
| 673 | |
| 674 | |
| 675 #define URL_HISTORY_MAX_SIZE 30 | |
| 676 | |
| 677 static void | |
| 678 util_add_url_callback(GtkWidget * widget, | |
| 679 GtkEntry * entry) | |
| 680 { | |
| 681 const gchar *text; | |
| 682 | |
| 683 text = gtk_entry_get_text(entry); | |
| 684 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp)) | |
| 685 return; | |
| 686 | |
| 687 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text)); | |
| 688 | |
| 689 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) { | |
| 690 GList *node = g_list_last(cfg.url_history); | |
| 691 g_free(node->data); | |
| 692 cfg.url_history = g_list_delete_link(cfg.url_history, node); | |
| 693 } | |
| 694 } | |
| 695 | |
| 696 GtkWidget * | |
| 86 | 697 util_add_url_dialog_new(const gchar * caption, GCallback ok_func, |
| 698 GCallback enqueue_func) | |
| 0 | 699 { |
| 86 | 700 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry; |
| 0 | 701 GList *url; |
| 702 | |
| 703 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 704 gtk_window_set_title(GTK_WINDOW(win), caption); | |
| 705 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG); | |
| 706 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER); | |
| 707 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1); | |
| 708 gtk_container_set_border_width(GTK_CONTAINER(win), 12); | |
| 709 | |
| 710 vbox = gtk_vbox_new(FALSE, 10); | |
| 711 gtk_container_add(GTK_CONTAINER(win), vbox); | |
| 712 | |
| 713 combo = gtk_combo_box_entry_new_text(); | |
| 714 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); | |
| 715 | |
| 716 entry = gtk_bin_get_child(GTK_BIN(combo)); | |
| 717 gtk_window_set_focus(GTK_WINDOW(win), entry); | |
| 718 gtk_entry_set_text(GTK_ENTRY(entry), ""); | |
| 719 | |
| 720 for (url = cfg.url_history; url; url = g_list_next(url)) | |
| 721 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data); | |
| 722 | |
| 723 g_signal_connect(entry, "activate", | |
| 724 G_CALLBACK(util_add_url_callback), | |
| 725 entry); | |
| 726 g_signal_connect(entry, "activate", | |
| 86 | 727 G_CALLBACK(ok_func), |
| 0 | 728 entry); |
| 729 g_signal_connect_swapped(entry, "activate", | |
| 730 G_CALLBACK(gtk_widget_destroy), | |
| 731 win); | |
| 732 | |
| 733 bbox = gtk_hbutton_box_new(); | |
| 734 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 735 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
| 736 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 737 | |
| 86 | 738 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN); |
| 739 g_signal_connect(ok, "clicked", | |
| 740 G_CALLBACK(util_add_url_callback), entry); | |
| 741 g_signal_connect(ok, "clicked", | |
| 742 G_CALLBACK(ok_func), entry); | |
| 743 g_signal_connect_swapped(ok, "clicked", | |
| 744 G_CALLBACK(gtk_widget_destroy), | |
| 745 win); | |
| 746 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0); | |
| 747 | |
| 0 | 748 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD); |
| 749 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0); | |
| 750 | |
| 751 g_signal_connect(enqueue, "clicked", | |
| 752 G_CALLBACK(util_add_url_callback), | |
| 753 entry); | |
| 754 g_signal_connect(enqueue, "clicked", | |
| 755 G_CALLBACK(enqueue_func), | |
| 756 entry); | |
| 757 g_signal_connect_swapped(enqueue, "clicked", | |
| 758 G_CALLBACK(gtk_widget_destroy), | |
| 759 win); | |
| 760 | |
| 761 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 762 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); | |
| 763 | |
| 764 g_signal_connect_swapped(cancel, "clicked", | |
| 765 G_CALLBACK(gtk_widget_destroy), | |
| 766 win); | |
| 767 | |
| 768 gtk_widget_show_all(vbox); | |
| 769 | |
| 770 return win; | |
| 771 } | |
| 772 | |
| 773 static void | |
| 774 filebrowser_add_files(GtkFileChooser * browser, | |
| 775 GSList * files) | |
| 776 { | |
| 777 GSList *cur; | |
| 778 gchar *ptr; | |
| 779 guint ctr = 0; | |
| 780 | |
| 781 if (GTK_IS_WIDGET(mainwin_jtf)) | |
| 782 gtk_widget_set_sensitive(mainwin_jtf, FALSE); | |
| 783 | |
| 784 for (cur = files; cur; cur = g_slist_next(cur)) { | |
| 785 | |
| 786 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) { | |
| 787 playlist_add_dir((const gchar *) cur->data); | |
| 788 } else { | |
| 789 playlist_add((const gchar *) cur->data); | |
| 790 } | |
| 791 | |
| 792 if (++ctr == 20) { | |
| 793 playlistwin_update_list(); | |
| 794 ctr = 0; | |
| 795 while (gtk_events_pending() ) gtk_main_iteration(); | |
| 796 } | |
| 797 } | |
| 798 | |
| 799 playlistwin_update_list(); | |
| 800 | |
| 801 if (GTK_IS_WIDGET(mainwin_jtf)) | |
| 802 gtk_widget_set_sensitive(mainwin_jtf, TRUE); | |
| 803 | |
| 804 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
| 805 | |
| 806 g_free(cfg.filesel_path); | |
| 807 cfg.filesel_path = ptr; | |
| 808 } | |
| 809 | |
| 810 static void | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
811 filebrowser_add(GtkFileChooser *browser) |
| 0 | 812 { |
| 813 GSList *files; | |
| 814 | |
| 815 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
| 816 | |
| 817 if (!files) { | |
| 818 return; | |
| 819 } | |
| 820 | |
| 821 filebrowser_add_files(browser, files); | |
| 822 g_slist_foreach(files, (GFunc) g_free, NULL); | |
| 823 g_slist_free(files); | |
| 824 } | |
| 825 | |
| 826 static void | |
| 827 filebrowser_play(GtkFileChooser * browser) | |
| 828 { | |
| 829 GSList *files; | |
| 830 | |
| 831 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(browser)); | |
| 832 | |
| 833 if (!files) return; | |
| 834 | |
| 835 playlist_clear(); | |
| 836 | |
| 837 filebrowser_add_files(browser, files); | |
| 838 g_slist_foreach(files, (GFunc) g_free, NULL); | |
| 839 g_slist_free(files); | |
| 840 | |
| 841 bmp_playback_initiate(); | |
| 842 } | |
| 843 | |
| 844 | |
| 845 static void | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
846 _filebrowser_add_gtk2(GtkWidget *widget, |
| 0 | 847 gpointer data) |
| 848 { | |
| 849 filebrowser_add(data); | |
| 850 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(data)); | |
| 851 } | |
| 852 | |
| 853 static void | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
854 _filebrowser_play_gtk2(GtkWidget *widget, gpointer data) |
| 0 | 855 { |
| 856 filebrowser_play(data); | |
| 857 gtk_file_chooser_unselect_all(data); | |
| 858 } | |
| 859 | |
| 860 #if 0 | |
| 861 static void | |
| 862 filebrowser_on_response(GtkFileChooser * browser, | |
| 863 gint response, | |
| 864 gpointer data) | |
| 865 { | |
| 866 gtk_widget_hide(GTK_WIDGET(browser)); | |
| 867 switch (response) { | |
| 868 case GTK_RESPONSE_OK: | |
| 869 break; | |
| 870 case GTK_RESPONSE_ACCEPT: | |
| 871 break; | |
| 872 case GTK_RESPONSE_CLOSE: | |
| 873 break; | |
| 874 } | |
| 875 gtk_widget_destroy(GTK_WIDGET(browser)); | |
| 876 | |
| 877 } | |
| 878 | |
| 879 #endif | |
| 880 | |
| 881 static void | |
| 882 _filebrowser_check_hide_add(GtkWidget * widget, | |
| 883 gpointer data) | |
| 884 { | |
| 885 cfg.close_dialog_add = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
| 886 } | |
| 887 | |
| 888 static void | |
| 889 _filebrowser_check_hide_open(GtkWidget * widget, | |
| 890 gpointer data) | |
| 891 { | |
| 892 cfg.close_dialog_open = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
| 893 } | |
| 894 | |
| 895 | |
| 896 | |
| 897 static gboolean | |
| 898 filebrowser_on_keypress(GtkWidget * browser, | |
| 899 GdkEventKey * event, | |
| 900 gpointer data) | |
| 901 { | |
| 902 if (event->keyval == GDK_Escape) { | |
| 903 /* FIXME: this crashes BMP for some reason */ | |
| 904 /* g_signal_emit_by_name(browser, "delete-event"); */ | |
| 905 gtk_widget_hide(browser); | |
| 906 return TRUE; | |
| 907 } | |
| 908 | |
| 909 return FALSE; | |
| 910 } | |
| 911 | |
| 912 static void | |
| 913 _filebrowser_do_hide_add(GtkWidget *widget, | |
| 914 gpointer data) | |
| 915 { | |
| 916 if (cfg.close_dialog_add) | |
| 917 gtk_widget_hide(data); | |
| 918 } | |
| 919 | |
| 920 static void | |
| 921 _filebrowser_do_hide_open(GtkWidget *widget, | |
| 922 gpointer data) | |
| 923 { | |
| 924 if (cfg.close_dialog_open) | |
| 925 gtk_widget_hide(data); | |
| 926 } | |
| 927 | |
| 928 void | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
929 util_run_filebrowser_gtk2style(gboolean play_button) |
| 0 | 930 { |
| 931 static GladeXML *xml = NULL; | |
| 932 static GtkWidget *dialog = NULL; | |
| 933 static GtkWidget *chooser = NULL; | |
| 934 | |
| 935 static GtkWidget *button_add; | |
| 936 static GtkWidget *button_select_all, *button_deselect_all; | |
| 937 static GtkWidget *toggle; | |
| 938 | |
| 939 static gulong handlerid, handlerid_check, handlerid_do; | |
| 940 static gulong handlerid_activate, handlerid_do_activate; | |
| 941 | |
| 942 if (!xml) { | |
| 943 /* FIXME: Creating a file chooser dialog manually using | |
| 944 libglade because there's no way to stop | |
| 945 GtkFileChooserDialog from resizing the buttons to the same | |
| 946 size. The long toggle button title causes the buttons to | |
| 947 turn unnecessarily elongated and fugly. */ | |
| 948 | |
| 949 GtkWidget *alignment; | |
| 950 | |
| 951 xml = glade_xml_new_or_die(_("Add/Open Files dialog"), | |
| 952 DATA_DIR "/glade/addfiles.glade", | |
| 953 NULL, NULL); | |
| 954 glade_xml_signal_autoconnect(xml); | |
| 955 | |
| 956 dialog = glade_xml_get_widget(xml, "add_files_dialog"); | |
| 957 | |
| 958 /* FIXME: Creating file chooser widget here because libglade <= 2.4.0 does | |
| 959 not support GtkFileChooserWidget */ | |
| 960 | |
| 961 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
| 962 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
| 963 | |
| 964 if (cfg.filesel_path) | |
| 965 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
| 966 cfg.filesel_path); | |
| 967 | |
| 968 alignment = glade_xml_get_widget(xml, "alignment2"); | |
| 969 gtk_container_add(GTK_CONTAINER(alignment), chooser); | |
| 970 | |
| 971 toggle = glade_xml_get_widget(xml, "close_on_action"); | |
| 972 button_select_all = glade_xml_get_widget(xml, "select_all"); | |
| 973 button_deselect_all = glade_xml_get_widget(xml, "deselect_all"); | |
| 974 button_add = glade_xml_get_widget(xml, "action"); | |
| 975 | |
| 976 g_signal_connect_swapped(button_select_all, "clicked", | |
| 977 G_CALLBACK(gtk_file_chooser_select_all), | |
| 978 chooser); | |
| 979 g_signal_connect_swapped(button_deselect_all, "clicked", | |
| 980 G_CALLBACK(gtk_file_chooser_unselect_all), | |
| 981 chooser); | |
| 982 | |
| 983 g_signal_connect(dialog, "key_press_event", | |
| 984 G_CALLBACK(filebrowser_on_keypress), | |
| 985 NULL); | |
| 986 | |
| 987 gtk_widget_show_all(dialog); | |
| 988 } /* !xml */ | |
| 989 else { | |
| 990 g_signal_handler_disconnect(button_add, handlerid); | |
| 991 g_signal_handler_disconnect(toggle, handlerid_check); | |
| 992 g_signal_handler_disconnect(chooser, handlerid_activate); | |
| 993 g_signal_handler_disconnect(button_add, handlerid_do); | |
| 994 g_signal_handler_disconnect(chooser, handlerid_do_activate); | |
|
1752
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
995 |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
996 if (cfg.refresh_file_list) |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
997 { |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
998 gchar *tmp = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser)); |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
999 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), tmp); |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1000 |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1001 g_free(tmp); |
|
be1c5774f675
[svn] - fix a memory leak in util_run_filebrowser()
nenolod
parents:
1717
diff
changeset
|
1002 } |
| 0 | 1003 } |
| 1004 | |
| 1005 if (play_button) { | |
| 1006 gtk_window_set_title(GTK_WINDOW(dialog), _("Open Files")); | |
| 1007 | |
| 1008 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_OPEN); | |
| 1009 | |
| 1010 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Open")); | |
| 1011 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_open); | |
| 1012 | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1013 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
| 0 | 1014 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_open), NULL); |
| 1015 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_open), dialog); | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1016 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_play_gtk2), chooser); |
| 0 | 1017 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_open), dialog); |
| 1018 } | |
| 1019 else { | |
| 1020 gtk_window_set_title(GTK_WINDOW(dialog), _("Add Files")); | |
| 1021 | |
| 1022 gtk_button_set_label(GTK_BUTTON(button_add), GTK_STOCK_ADD); | |
| 1023 | |
| 1024 gtk_button_set_label(GTK_BUTTON(toggle), _("Close dialog on Add")); | |
| 1025 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), cfg.close_dialog_add); | |
| 1026 | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1027 handlerid = g_signal_connect(button_add, "clicked", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
| 0 | 1028 handlerid_check = g_signal_connect(toggle, "toggled", G_CALLBACK(_filebrowser_check_hide_add), NULL); |
| 1029 handlerid_do = g_signal_connect_after(button_add, "clicked", G_CALLBACK(_filebrowser_do_hide_add), dialog); | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1030 handlerid_activate = g_signal_connect(chooser, "file-activated", G_CALLBACK(_filebrowser_add_gtk2), chooser); |
| 0 | 1031 handlerid_do_activate = g_signal_connect_after(chooser,"file_activated", G_CALLBACK(_filebrowser_do_hide_add), dialog); |
| 1032 } | |
| 1033 | |
| 1034 gtk_window_present(GTK_WINDOW(dialog)); | |
| 1035 } | |
| 1036 | |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1037 /* |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1038 * Derived from Beep Media Player 0.9.6.1. |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1039 * Which is (C) 2003 - 2006 Milosz Derezynski &c |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1040 * |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1041 * Although I changed it quite a bit. -nenolod |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1042 */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1043 static void filebrowser_changed_classic(GtkFileSelection * filesel) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1044 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1045 GList *list; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1046 GList *node; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1047 char *filename = (char *) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1048 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1049 GtkListStore *store; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1050 GtkTreeIter iter; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1051 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1052 if ((list = input_scan_dir(filename)) != NULL) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1053 /* |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1054 * We enter a directory that has been "hijacked" by an |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1055 * input-plugin. This is used by the CDDA plugin |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1056 */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1057 store = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1058 GTK_LIST_STORE(gtk_tree_view_get_model |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1059 (GTK_TREE_VIEW(filesel->file_list))); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1060 gtk_list_store_clear(store); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1061 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1062 node = list; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1063 while (node) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1064 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1065 gtk_list_store_append(store, &iter); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1066 gtk_list_store_set(store, &iter, 0, node->data, -1); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1067 g_free(node->data); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1068 node = g_list_next(node); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1069 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1070 g_list_free(list); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1071 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1072 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1073 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1074 static void filebrowser_entry_changed_classic(GtkEditable * entry, gpointer data) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1075 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1076 filebrowser_changed_classic(GTK_FILE_SELECTION(data)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1077 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1078 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1079 gboolean util_filebrowser_is_dir_classic(GtkFileSelection * filesel) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1080 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1081 char *text; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1082 struct stat buf; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1083 gboolean retv = FALSE; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1084 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1085 text = g_strdup(gtk_file_selection_get_filename(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1086 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1087 if (stat(text, &buf) == 0 && S_ISDIR(buf.st_mode)) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1088 /* Selected directory */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1089 int len = strlen(text); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1090 if (len > 3 && !strcmp(text + len - 4, "/../")) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1091 if (len == 4) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1092 /* At the root already */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1093 *(text + len - 3) = '\0'; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1094 else { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1095 char *ptr; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1096 *(text + len - 4) = '\0'; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1097 ptr = strrchr(text, '/'); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1098 *(ptr + 1) = '\0'; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1099 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1100 } else if (len > 2 && !strcmp(text + len - 3, "/./")) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1101 *(text + len - 2) = '\0'; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1102 gtk_file_selection_set_filename(filesel, text); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1103 retv = TRUE; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1104 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1105 g_free(text); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1106 return retv; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1107 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1108 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1109 static void filebrowser_add_files_classic(gchar ** files, |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1110 GtkFileSelection * filesel) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1111 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1112 int ctr = 0; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1113 char *ptr; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1114 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1115 if (GTK_IS_WIDGET(mainwin_jtf)) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1116 gtk_widget_set_sensitive(mainwin_jtf, FALSE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1117 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1118 while (files[ctr] != NULL) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1119 playlist_add(files[ctr++]); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1120 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1121 playlistwin_update_list(); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1122 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1123 if (GTK_IS_WIDGET(mainwin_jtf)) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1124 gtk_widget_set_sensitive(mainwin_jtf, TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1125 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1126 gtk_label_get(GTK_LABEL(GTK_BIN(filesel->history_pulldown)->child), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1127 &ptr); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1128 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1129 /* This will give an extra slash if the current dir is the root. */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1130 cfg.filesel_path = g_strconcat(ptr, "/", NULL); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1131 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1132 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1133 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1134 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1135 gchar **files; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1136 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1137 if (util_filebrowser_is_dir_classic(GTK_FILE_SELECTION(filesel))) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1138 return; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1139 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1140 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1141 gtk_widget_destroy(filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1142 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1143 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1144 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1145 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1146 gchar **files; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1147 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1148 if (util_filebrowser_is_dir_classic |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1149 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel)))) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1150 return; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1151 playlist_clear(); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1152 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1153 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1154 gtk_widget_destroy(filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1155 bmp_playback_initiate(); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1156 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1157 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1158 static void filebrowser_add_selected_files_classic(GtkWidget * w, gpointer data) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1159 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1160 gchar **files; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1161 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1162 GtkFileSelection *filesel = GTK_FILE_SELECTION(data); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1163 files = gtk_file_selection_get_selections(filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1164 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1165 filebrowser_add_files_classic(files, filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1166 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1167 (GTK_TREE_VIEW(filesel->file_list))); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1168 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1169 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1170 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1171 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1172 static void filebrowser_add_all_files_classic(GtkWidget * w, gpointer data) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1173 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1174 gchar **files; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1175 GtkFileSelection *filesel; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1176 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1177 filesel = data; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1178 gtk_tree_selection_select_all(gtk_tree_view_get_selection |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1179 (GTK_TREE_VIEW(filesel->file_list))); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1180 files = gtk_file_selection_get_selections(filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1181 filebrowser_add_files_classic(files, filesel); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1182 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1183 (GTK_TREE_VIEW(filesel->file_list))); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1184 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1185 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1186 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1187 void |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1188 util_run_filebrowser_classic(gboolean play_button) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1189 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1190 static GtkWidget *dialog; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1191 GtkWidget *button_add_selected, *button_add_all, *button_close, |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1192 *button_add; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1193 char *title; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1194 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1195 if (dialog != NULL) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1196 gtk_window_present(GTK_WINDOW(dialog)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1197 return; |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1198 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1199 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1200 if (play_button) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1201 title = _("Play files"); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1202 else |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1203 title = _("Load files"); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1204 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1205 dialog = gtk_file_selection_new(title); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1206 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1207 gtk_file_selection_set_select_multiple |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1208 (GTK_FILE_SELECTION(dialog), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1209 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1210 if (cfg.filesel_path) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1211 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1212 cfg.filesel_path); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1213 |
|
1907
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1214 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(dialog)); |
|
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1215 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); |
|
d7301ba54f70
[svn] - remove useless fileop buttons from the GTK1-like dialog.
nenolod
parents:
1905
diff
changeset
|
1216 |
|
1905
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1217 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1218 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1219 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1220 /* |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1221 * The mnemonics are quite unorthodox, but that should guarantee they're unique in any locale |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1222 * plus kinda easy to use |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1223 */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1224 button_add_selected = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1225 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1226 GTK_RESPONSE_NONE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1227 gtk_button_set_use_underline(GTK_BUTTON(button_add_selected), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1228 g_signal_connect(G_OBJECT(button_add_selected), "clicked", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1229 G_CALLBACK(filebrowser_add_selected_files_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1230 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1231 button_add_all = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1232 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1233 GTK_RESPONSE_NONE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1234 gtk_button_set_use_underline(GTK_BUTTON(button_add_all), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1235 g_signal_connect(G_OBJECT(button_add_all), "clicked", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1236 G_CALLBACK(filebrowser_add_all_files_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1237 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1238 if (play_button) { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1239 button_add = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1240 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_MEDIA_PLAY, |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1241 GTK_RESPONSE_NONE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1242 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1243 g_signal_connect(G_OBJECT(button_add), "clicked", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1244 G_CALLBACK(filebrowser_play_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1245 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1246 "clicked", G_CALLBACK(filebrowser_play_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1247 } else { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1248 button_add = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1249 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ADD, |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1250 GTK_RESPONSE_NONE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1251 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1252 g_signal_connect(G_OBJECT(button_add), "clicked", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1253 G_CALLBACK(filebrowser_ok_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1254 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1255 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1256 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1257 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1258 button_close = |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1259 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE, |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1260 GTK_RESPONSE_NONE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1261 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1262 g_signal_connect_swapped(G_OBJECT(button_close), "clicked", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1263 G_CALLBACK(gtk_widget_destroy), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1264 G_OBJECT(dialog)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1265 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1266 gtk_widget_set_size_request(dialog, 600, 450); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1267 gtk_widget_realize(dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1268 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1269 g_signal_connect(G_OBJECT |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1270 (GTK_FILE_SELECTION(dialog)->history_pulldown), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1271 "changed", G_CALLBACK(filebrowser_entry_changed_classic), |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1272 dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1273 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1274 g_signal_connect(G_OBJECT(dialog), "destroy", |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1275 G_CALLBACK(gtk_widget_destroyed), &dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1276 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1277 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog)); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1278 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1279 gtk_widget_show(dialog); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1280 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1281 |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1282 /* |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1283 * util_run_filebrowser(gboolean play_button) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1284 * |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1285 * Inputs: |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1286 * - whether or not a play button should be used |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1287 * |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1288 * Outputs: |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1289 * - none |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1290 * |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1291 * Side Effects: |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1292 * - either a GTK1 or a GTK2 fileselector is launched |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1293 */ |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1294 void |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1295 util_run_filebrowser(gboolean play_button) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1296 { |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1297 if (!cfg.use_xmms_style_fileselector) |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1298 util_run_filebrowser_gtk2style(play_button); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1299 else |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1300 util_run_filebrowser_classic(play_button); |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1301 } |
|
6b4116c34489
[svn] - change "Transparency" to "Miscillaneous UI Features" in prefswin
nenolod
parents:
1891
diff
changeset
|
1302 |
| 0 | 1303 GdkFont * |
| 1304 util_font_load(const gchar * name) | |
| 1305 { | |
| 1306 GdkFont *font; | |
| 1307 PangoFontDescription *desc; | |
| 1308 | |
| 1309 desc = pango_font_description_from_string(name); | |
| 1310 font = gdk_font_from_description(desc); | |
| 1311 | |
| 1312 return font; | |
| 1313 } | |
| 1314 | |
| 1315 #ifdef ENABLE_NLS | |
| 1316 gchar * | |
| 1317 bmp_menu_translate(const gchar * path, gpointer func_data) | |
| 1318 { | |
| 1319 gchar *translation = gettext(path); | |
| 1320 | |
| 1321 if (!translation || *translation != '/') { | |
| 1322 g_warning("Bad translation for menupath: %s", path); | |
| 1323 translation = (gchar *) path; | |
| 1324 } | |
| 1325 | |
| 1326 return translation; | |
| 1327 } | |
| 1328 #endif | |
| 1329 | |
| 1330 void | |
| 1331 util_set_cursor(GtkWidget * window) | |
| 1332 { | |
| 1333 static GdkCursor *cursor = NULL; | |
| 1334 | |
| 1335 if (!window) { | |
| 1336 if (cursor) { | |
|
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
625
diff
changeset
|
1337 gdk_cursor_unref(cursor); |
| 0 | 1338 cursor = NULL; |
| 1339 } | |
|
813
c8cf439179b8
[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
nenolod
parents:
625
diff
changeset
|
1340 |
| 0 | 1341 return; |
| 1342 } | |
| 1343 | |
| 1344 if (!cursor) | |
| 1345 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
| 1346 | |
| 1347 gdk_window_set_cursor(window->window, cursor); | |
| 1348 } | |
| 1349 | |
| 1653 | 1350 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter |
| 1351 * Mattis et al */ | |
| 1352 gboolean | |
| 1353 text_get_extents(const gchar * fontname, | |
| 1354 const gchar * text, | |
| 1355 gint * width, gint * height, gint * ascent, gint * descent) | |
| 1356 { | |
| 1357 PangoFontDescription *font_desc; | |
| 1358 PangoLayout *layout; | |
| 1359 PangoRectangle rect; | |
| 1360 | |
| 1361 g_return_val_if_fail(fontname != NULL, FALSE); | |
| 1362 g_return_val_if_fail(text != NULL, FALSE); | |
| 1363 | |
| 1364 /* FIXME: resolution */ | |
| 1365 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text); | |
| 1366 | |
| 1367 font_desc = pango_font_description_from_string(fontname); | |
| 1368 pango_layout_set_font_description(layout, font_desc); | |
| 1369 pango_font_description_free(font_desc); | |
| 1370 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
| 1371 | |
| 1372 if (width) | |
| 1373 *width = rect.width; | |
| 1374 if (height) | |
| 1375 *height = rect.height; | |
| 1376 | |
| 1377 if (ascent || descent) { | |
| 1378 PangoLayoutIter *iter; | |
| 1379 PangoLayoutLine *line; | |
| 1380 | |
| 1381 iter = pango_layout_get_iter(layout); | |
| 1382 line = pango_layout_iter_get_line(iter); | |
| 1383 pango_layout_iter_free(iter); | |
| 1384 | |
| 1385 pango_layout_line_get_pixel_extents(line, NULL, &rect); | |
| 1386 | |
| 1387 if (ascent) | |
| 1388 *ascent = PANGO_ASCENT(rect); | |
| 1389 if (descent) | |
| 1390 *descent = -PANGO_DESCENT(rect); | |
| 1391 } | |
| 1392 | |
| 1393 g_object_unref(layout); | |
| 1394 | |
| 1395 return TRUE; | |
| 1396 } | |
| 1397 | |
| 0 | 1398 /* counts number of digits in a gint */ |
| 1399 guint | |
| 1400 gint_count_digits(gint n) | |
| 1401 { | |
| 1402 guint count = 0; | |
| 1403 | |
| 1404 n = ABS(n); | |
| 1405 do { | |
| 1406 count++; | |
| 1407 n /= 10; | |
| 1408 } while (n > 0); | |
| 1409 | |
| 1410 return count; | |
| 1411 } | |
| 1412 | |
| 1413 static gchar * | |
| 1414 str_twenty_to_space(gchar * str) | |
| 1415 { | |
| 1416 gchar *match, *match_end; | |
| 1417 | |
| 1418 g_return_val_if_fail(str != NULL, NULL); | |
| 1419 | |
| 1420 while ((match = strstr(str, "%20"))) { | |
| 1421 match_end = match + 3; | |
| 1422 *match++ = ' '; | |
| 1423 while (*match_end) | |
| 1424 *match++ = *match_end++; | |
| 1425 *match = 0; | |
| 1426 } | |
| 1427 | |
| 1428 return str; | |
| 1429 } | |
| 1430 | |
| 1431 static gchar * | |
| 1432 str_replace_char(gchar * str, gchar old, gchar new) | |
| 1433 { | |
| 1434 gchar *match; | |
| 1435 | |
| 1436 g_return_val_if_fail(str != NULL, NULL); | |
| 1437 | |
| 1438 match = str; | |
| 1439 while ((match = strchr(match, old))) | |
| 1440 *match = new; | |
| 1441 | |
| 1442 return str; | |
| 1443 } | |
| 1444 | |
| 1445 gchar * | |
| 1446 str_append(gchar * str, const gchar * add_str) | |
| 1447 { | |
| 1448 return str_replace(str, g_strconcat(str, add_str, NULL)); | |
| 1449 } | |
| 1450 | |
| 1451 gchar * | |
| 1452 str_replace(gchar * str, gchar * new_str) | |
| 1453 { | |
| 1454 g_free(str); | |
| 1455 return new_str; | |
| 1456 } | |
| 1457 | |
| 1458 void | |
| 1459 str_replace_in(gchar ** str, gchar * new_str) | |
| 1460 { | |
| 1461 *str = str_replace(*str, new_str); | |
| 1462 } | |
| 1463 | |
| 1464 | |
| 1465 gboolean | |
| 1466 str_has_prefix_nocase(const gchar * str, const gchar * prefix) | |
| 1467 { | |
| 1468 return (strncasecmp(str, prefix, strlen(prefix)) == 0); | |
| 1469 } | |
| 1470 | |
| 1471 gboolean | |
| 1472 str_has_suffix_nocase(const gchar * str, const gchar * suffix) | |
| 1473 { | |
| 1474 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0); | |
| 1475 } | |
| 1476 | |
| 1477 gboolean | |
| 1478 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes) | |
| 1479 { | |
| 1480 gchar *const *suffix; | |
| 1481 | |
| 1482 g_return_val_if_fail(str != NULL, FALSE); | |
| 1483 g_return_val_if_fail(suffixes != NULL, FALSE); | |
| 1484 | |
| 1485 for (suffix = suffixes; *suffix; suffix++) | |
| 1486 if (str_has_suffix_nocase(str, *suffix)) | |
| 1487 return TRUE; | |
| 1488 | |
| 1489 return FALSE; | |
| 1490 } | |
| 1491 | |
| 1492 gchar * | |
| 1493 str_to_utf8_fallback(const gchar * str) | |
| 1494 { | |
| 1495 gchar *out_str, *convert_str, *chr; | |
| 1496 | |
| 1497 /* NULL in NULL out */ | |
| 1498 if (!str) | |
| 1499 return NULL; | |
| 1500 | |
| 1501 convert_str = g_strdup(str); | |
| 1502 for (chr = convert_str; *chr; chr++) { | |
| 1503 if (*chr & 0x80) | |
| 1504 *chr = '?'; | |
| 1505 } | |
| 1506 | |
| 1507 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL); | |
| 1508 g_free(convert_str); | |
| 1509 | |
| 1510 return out_str; | |
| 1511 } | |
| 1512 | |
| 1513 gchar * | |
| 1514 filename_to_utf8(const gchar * filename) | |
| 1515 { | |
| 1516 gchar *out_str; | |
| 1517 | |
| 1518 /* NULL in NULL out */ | |
| 1519 if (!filename) | |
| 1520 return NULL; | |
| 1521 | |
| 1522 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL))) | |
| 1523 return out_str; | |
| 1524 | |
| 1525 return str_to_utf8_fallback(filename); | |
| 1526 } | |
| 1527 | |
| 1528 gchar * | |
| 1529 str_to_utf8(const gchar * str) | |
| 1530 { | |
| 1531 gchar *out_str; | |
| 1532 | |
| 1533 /* NULL in NULL out */ | |
| 1534 if (!str) | |
| 1535 return NULL; | |
| 1536 | |
|
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1537 /* Note: Currently, playlist calls this function repeatedly, even |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1538 * if the string is already converted into utf-8. |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1539 * chardet_to_utf8() would convert a valid utf-8 string into a |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1540 * different utf-8 string, if fallback encodings were supplied and |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1541 * the given string could be treated as a string in one of fallback |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1542 * encodings. To avoid this, the order of evaluation has been |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1543 * changed. (It might cause a drawback?) |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1544 */ |
|
2015
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1545 /* chardet encoding detector */ |
|
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1546 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL))) |
|
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1547 return out_str; |
|
200970e7a3b1
[svn] - run chardet against even valid UTF-8 strings, as they may be non-UTF-8
nenolod
parents:
1972
diff
changeset
|
1548 |
|
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1549 /* already UTF-8? */ |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1550 if (g_utf8_validate(str, -1, NULL)) |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1551 return g_strdup(str); |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1552 |
| 0 | 1553 /* assume encoding associated with locale */ |
| 1554 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) | |
| 1555 return out_str; | |
| 1556 | |
| 1557 /* all else fails, we mask off character codes >= 128, | |
| 1558 replace with '?' */ | |
| 1559 return str_to_utf8_fallback(str); | |
| 1560 } | |
| 1561 | |
| 1562 | |
| 1563 const gchar * | |
| 1564 str_skip_chars(const gchar * str, const gchar * chars) | |
| 1565 { | |
| 1566 while (strchr(chars, *str)) | |
| 1567 str++; | |
| 1568 return str; | |
| 1569 } | |
| 1570 | |
| 1571 gchar * | |
| 1572 convert_title_text(gchar * title) | |
| 1573 { | |
| 1574 g_return_val_if_fail(title != NULL, NULL); | |
| 1575 | |
|
2019
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1576 if (cfg.convert_slash) |
|
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1577 str_replace_char(title, '\\', '/'); |
|
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2015
diff
changeset
|
1578 |
| 0 | 1579 if (cfg.convert_underscore) |
| 1580 str_replace_char(title, '_', ' '); | |
| 1581 | |
| 1582 if (cfg.convert_twenty) | |
| 1583 str_twenty_to_space(title); | |
| 1584 | |
| 1585 return title; | |
| 1586 } | |
| 1587 | |
| 1588 | |
| 1589 gboolean | |
| 1590 dir_foreach(const gchar * path, DirForeachFunc function, | |
| 1591 gpointer user_data, GError ** error) | |
| 1592 { | |
| 1593 GError *error_out = NULL; | |
| 1594 GDir *dir; | |
| 1595 const gchar *entry; | |
| 1596 gchar *entry_fullpath; | |
| 1597 | |
| 1598 if (!(dir = g_dir_open(path, 0, &error_out))) { | |
| 1599 g_propagate_error(error, error_out); | |
| 1600 return FALSE; | |
| 1601 } | |
| 1602 | |
| 1603 while ((entry = g_dir_read_name(dir))) { | |
| 1604 entry_fullpath = g_build_filename(path, entry, NULL); | |
| 1605 | |
| 1606 if ((*function) (entry_fullpath, entry, user_data)) { | |
| 1607 g_free(entry_fullpath); | |
| 1608 break; | |
| 1609 } | |
| 1610 | |
| 1611 g_free(entry_fullpath); | |
| 1612 } | |
| 1613 | |
| 1614 g_dir_close(dir); | |
| 1615 | |
| 1616 return TRUE; | |
| 1617 } | |
| 1618 | |
| 1653 | 1619 GtkWidget * |
| 1620 make_filebrowser(const gchar * title, | |
| 1621 gboolean save) | |
| 1622 { | |
| 1623 GtkWidget *dialog; | |
| 1624 GtkWidget *button; | |
| 1625 GtkWidget *button_close; | |
| 1626 | |
| 1627 g_return_val_if_fail(title != NULL, NULL); | |
| 1628 | |
| 1629 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
| 1630 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL); | |
| 1631 if (save) | |
| 1632 gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), | |
| 1633 GTK_FILE_CHOOSER_ACTION_SAVE); | |
| 1634 | |
| 1635 if (!save) | |
| 1636 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
| 1637 | |
| 1638 g_signal_connect(dialog, "destroy", | |
| 1639 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
| 1640 | |
| 1641 button_close = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
| 1642 GTK_RESPONSE_REJECT); | |
| 1643 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
| 1644 GTK_WIDGET_SET_FLAGS(button_close, GTK_CAN_DEFAULT); | |
| 1645 g_signal_connect_swapped(button_close, "clicked", | |
| 1646 G_CALLBACK(gtk_widget_destroy), dialog); | |
| 1647 | |
| 1648 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ? | |
| 1649 GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
| 1650 GTK_RESPONSE_ACCEPT); | |
| 1651 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
| 1652 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
| 1653 gtk_window_set_default(GTK_WINDOW(dialog), button); | |
| 1654 | |
| 1655 gtk_widget_show(dialog); | |
| 1656 | |
| 1657 return dialog; | |
| 1658 } | |
| 1659 | |
| 1660 | |
| 0 | 1661 GtkItemFactory * |
| 1662 create_menu(GtkItemFactoryEntry *entries, | |
| 1663 guint n_entries, | |
| 1664 GtkAccelGroup *accel) | |
| 1665 { | |
| 1666 GtkItemFactory *menu; | |
| 1667 | |
| 1668 menu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", accel); | |
| 1669 gtk_item_factory_set_translate_func(menu, bmp_menu_translate, NULL, | |
| 1670 NULL); | |
| 1671 gtk_item_factory_create_items(menu, n_entries, entries, NULL); | |
| 1672 | |
| 1673 return menu; | |
| 1674 } | |
| 1675 | |
| 1676 | |
| 1677 void | |
| 1678 make_submenu(GtkItemFactory *menu, | |
| 1679 const gchar *item_path, | |
| 1680 GtkItemFactory *submenu) | |
| 1681 { | |
| 1682 GtkWidget *item, *menu_; | |
| 1683 | |
| 1684 item = gtk_item_factory_get_widget(menu, item_path); | |
| 1685 menu_ = gtk_item_factory_get_widget(submenu, ""); | |
| 1686 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_); | |
| 1687 } | |
| 1688 | |
| 1689 | |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1690 gchar *chardet_to_utf8(const gchar *str, gssize len, |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1691 gsize *arg_bytes_read, gsize *arg_bytes_write, GError **arg_error) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1692 { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1693 #ifdef USE_CHARDET |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1694 char *det = NULL, *encoding = NULL; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1695 #endif |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1696 gchar *ret = NULL; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1697 gsize *bytes_read, *bytes_write; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1698 GError **error; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1699 gsize my_bytes_read, my_bytes_write; |
| 0 | 1700 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1701 bytes_read = arg_bytes_read ? arg_bytes_read : &my_bytes_read; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1702 bytes_write = arg_bytes_write ? arg_bytes_write : &my_bytes_write; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1703 error = arg_error ? arg_error : NULL; |
| 0 | 1704 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1705 #ifdef USE_CHARDET |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1706 if(cfg.chardet_detector) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1707 det = cfg.chardet_detector; |
| 0 | 1708 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1709 if(det){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1710 if(!strncasecmp("japanese", det, sizeof("japanese"))) { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1711 encoding = (char *)guess_jp(str, strlen(str)); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1712 if (!encoding) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1713 goto fallback; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1714 } else if(!strncasecmp("taiwanese", det, sizeof("taiwanese"))) { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1715 encoding = (char *)guess_tw(str, strlen(str)); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1716 if (!encoding) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1717 goto fallback; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1718 } else if(!strncasecmp("chinese", det, sizeof("chinese"))) { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1719 encoding = (char *)guess_cn(str, strlen(str)); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1720 if (!encoding) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1721 goto fallback; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1722 } else if(!strncasecmp("korean", det, sizeof("korean"))) { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1723 encoding = (char *)guess_kr(str, strlen(str)); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1724 if (!encoding) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1725 goto fallback; |
|
1613
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1726 } else if(!strncasecmp("russian", det, sizeof("russian"))) { |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1727 rcd_russian_charset res = rcdGetRussianCharset(str, strlen(str)); |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1728 switch(res) { |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1729 case RUSSIAN_CHARSET_WIN: |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1730 encoding = "CP1251"; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1731 break; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1732 case RUSSIAN_CHARSET_ALT: |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1733 encoding = "CP866"; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1734 break; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1735 case RUSSIAN_CHARSET_KOI: |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1736 encoding = "KOI8-R"; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1737 break; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1738 case RUSSIAN_CHARSET_UTF8: |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1739 encoding = "UTF-8"; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1740 break; |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1741 } |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1742 if (!encoding) |
|
9becbe564217
[svn] - chardet patch for Russian language witten by Valentine Sinitsyn.
yaz
parents:
1459
diff
changeset
|
1743 goto fallback; |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1744 #ifdef HAVE_UDET |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1745 } else if (!strncasecmp("universal", det, sizeof("universal"))) { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1746 encoding = (char *)detectCharset((char *)str, strlen(str)); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1747 if (!encoding) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1748 goto fallback; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1749 #endif |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1750 } else /* none, invalid */ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1751 goto fallback; |
| 0 | 1752 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1753 ret = g_convert(str, len, "UTF-8", encoding, bytes_read, bytes_write, error); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1754 } |
| 0 | 1755 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1756 fallback: |
|
1123
170f9b68dd03
[svn] The fallback label is not used unless detection is defined. Move endif down to reflect that.
chainsaw
parents:
1106
diff
changeset
|
1757 #endif |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1758 if(!ret && cfg.chardet_fallback){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1759 gchar **encs=NULL, **enc=NULL; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1760 encs = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1761 |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1762 if(encs){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1763 enc = encs; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1764 for(enc=encs; *enc ; enc++){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1765 ret = g_convert(str, len, "UTF-8", *enc, bytes_read, bytes_write, error); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1766 if(len == *bytes_read){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1767 break; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1768 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1769 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1770 g_strfreev(encs); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1771 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1772 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1773 |
|
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1774 #ifdef USE_CHARDET |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1775 /* many tag libraries return 2byte latin1 utf8 character as |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1776 converted 8bit iso-8859-1 character, if they are asked to return |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1777 latin1 string. |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1778 */ |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1779 if(!ret){ |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1780 ret = g_convert(str, len, "UTF-8", "ISO-8859-1", bytes_read, bytes_write, error); |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1781 } |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1782 #endif |
|
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1783 |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1784 if(ret){ |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1785 if(g_utf8_validate(ret, -1, NULL)) |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1786 return ret; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1787 else { |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1788 g_free(ret); |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1789 ret = NULL; |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1790 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1791 } |
|
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1792 |
|
1324
99454d030722
[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
yaz
parents:
1193
diff
changeset
|
1793 return NULL; /* if I have no idea, return NULL. */ |
|
1105
4be4d74db123
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
yaz
parents:
1067
diff
changeset
|
1794 } |
|
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1795 |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1796 /* |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1797 * Resizes a GDK pixmap. |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1798 */ |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1799 GdkPixmap *audacious_pixmap_resize(GdkWindow *src, GdkGC *src_gc, GdkPixmap *in, gint width, gint height) |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1800 { |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1801 GdkPixmap *out; |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1802 gint owidth, oheight; |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1803 |
| 1887 | 1804 g_return_val_if_fail(src != NULL, NULL); |
| 1805 g_return_val_if_fail(src_gc != NULL, NULL); | |
| 1806 g_return_val_if_fail(in != NULL, NULL); | |
| 1807 g_return_val_if_fail(width > 0 && height > 0, NULL); | |
|
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1808 |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1809 gdk_drawable_get_size(in, &owidth, &oheight); |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1810 |
| 1852 | 1811 if (oheight == height && owidth == width) |
| 1887 | 1812 return NULL; |
| 1852 | 1813 |
|
1851
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1814 out = gdk_pixmap_new(src, width, height, -1); |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1815 |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1816 gdk_draw_rectangle(out, src_gc, TRUE, 0, 0, width, height); |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1817 |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1818 gdk_window_copy_area(out, src_gc, 0, 0, in, 0, 0, owidth, oheight); |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1819 g_object_unref(src); |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1820 |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1821 return out; |
|
aceb472cce6c
[svn] - add audacious_pixmap_resize() for resizing a skin pixmap on demand.
nenolod
parents:
1752
diff
changeset
|
1822 } |
| 1938 | 1823 |
| 1824 GdkImage *create_dblsize_image(GdkImage * img) | |
| 1825 { | |
| 1826 GdkImage *dblimg; | |
| 1827 register guint x, y; | |
| 1828 | |
| 1829 /* | |
| 1830 * This needs to be optimized | |
| 1831 */ | |
| 1832 | |
| 1833 dblimg = | |
|
1972
edc01e85648d
[svn] - in particular X environment, double size caused a bad match X error.
yaz
parents:
1938
diff
changeset
|
1834 gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), |
| 1938 | 1835 img->width << 1, img->height << 1); |
| 1836 if (dblimg->bpp == 1) { | |
| 1837 register guint8 *srcptr, *ptr, *ptr2, pix; | |
| 1838 | |
| 1839 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
| 1840 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
| 1841 ptr2 = ptr + dblimg->bpl; | |
| 1842 | |
| 1843 for (y = 0; y < img->height; y++) { | |
| 1844 for (x = 0; x < img->width; x++) { | |
| 1845 pix = *srcptr++; | |
| 1846 *ptr++ = pix; | |
| 1847 *ptr++ = pix; | |
| 1848 *ptr2++ = pix; | |
| 1849 *ptr2++ = pix; | |
| 1850 } | |
| 1851 srcptr += img->bpl - img->width; | |
| 1852 ptr += (dblimg->bpl << 1) - dblimg->width; | |
| 1853 ptr2 += (dblimg->bpl << 1) - dblimg->width; | |
| 1854 } | |
| 1855 } | |
| 1856 if (dblimg->bpp == 2) { | |
| 1857 guint16 *srcptr, *ptr, *ptr2, pix; | |
| 1858 | |
| 1859 srcptr = (guint16 *) GDK_IMAGE_XIMAGE(img)->data; | |
| 1860 ptr = (guint16 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
| 1861 ptr2 = ptr + (dblimg->bpl >> 1); | |
| 1862 | |
| 1863 for (y = 0; y < img->height; y++) { | |
| 1864 for (x = 0; x < img->width; x++) { | |
| 1865 pix = *srcptr++; | |
| 1866 *ptr++ = pix; | |
| 1867 *ptr++ = pix; | |
| 1868 *ptr2++ = pix; | |
| 1869 *ptr2++ = pix; | |
| 1870 } | |
| 1871 srcptr += (img->bpl >> 1) - img->width; | |
| 1872 ptr += (dblimg->bpl) - dblimg->width; | |
| 1873 ptr2 += (dblimg->bpl) - dblimg->width; | |
| 1874 } | |
| 1875 } | |
| 1876 if (dblimg->bpp == 3) { | |
| 1877 register guint8 *srcptr, *ptr, *ptr2, pix1, pix2, pix3; | |
| 1878 | |
| 1879 srcptr = GDK_IMAGE_XIMAGE(img)->data; | |
| 1880 ptr = GDK_IMAGE_XIMAGE(dblimg)->data; | |
| 1881 ptr2 = ptr + dblimg->bpl; | |
| 1882 | |
| 1883 for (y = 0; y < img->height; y++) { | |
| 1884 for (x = 0; x < img->width; x++) { | |
| 1885 pix1 = *srcptr++; | |
| 1886 pix2 = *srcptr++; | |
| 1887 pix3 = *srcptr++; | |
| 1888 *ptr++ = pix1; | |
| 1889 *ptr++ = pix2; | |
| 1890 *ptr++ = pix3; | |
| 1891 *ptr++ = pix1; | |
| 1892 *ptr++ = pix2; | |
| 1893 *ptr++ = pix3; | |
| 1894 *ptr2++ = pix1; | |
| 1895 *ptr2++ = pix2; | |
| 1896 *ptr2++ = pix3; | |
| 1897 *ptr2++ = pix1; | |
| 1898 *ptr2++ = pix2; | |
| 1899 *ptr2++ = pix3; | |
| 1900 | |
| 1901 } | |
| 1902 srcptr += img->bpl - (img->width * 3); | |
| 1903 ptr += (dblimg->bpl << 1) - (dblimg->width * 3); | |
| 1904 ptr2 += (dblimg->bpl << 1) - (dblimg->width * 3); | |
| 1905 } | |
| 1906 } | |
| 1907 if (dblimg->bpp == 4) { | |
| 1908 register guint32 *srcptr, *ptr, *ptr2, pix; | |
| 1909 | |
| 1910 srcptr = (guint32 *) GDK_IMAGE_XIMAGE(img)->data; | |
| 1911 ptr = (guint32 *) GDK_IMAGE_XIMAGE(dblimg)->data; | |
| 1912 ptr2 = ptr + (dblimg->bpl >> 2); | |
| 1913 | |
| 1914 for (y = 0; y < img->height; y++) { | |
| 1915 for (x = 0; x < img->width; x++) { | |
| 1916 pix = *srcptr++; | |
| 1917 *ptr++ = pix; | |
| 1918 *ptr++ = pix; | |
| 1919 *ptr2++ = pix; | |
| 1920 *ptr2++ = pix; | |
| 1921 } | |
| 1922 srcptr += (img->bpl >> 2) - img->width; | |
| 1923 ptr += (dblimg->bpl >> 1) - dblimg->width; | |
| 1924 ptr2 += (dblimg->bpl >> 1) - dblimg->width; | |
| 1925 } | |
| 1926 } | |
| 1927 return dblimg; | |
| 1928 } |
