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