annotate src/audacious/util.c @ 2529:299be5908480 trunk

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