annotate src/audacious/util.c @ 3478:481a4a88d3ec trunk

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