annotate src/skins/util.c @ 3203:f5456241bff9 default tip

changed include path from audacious to audlegacy.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 10 Nov 2009 05:19:25 +0900
parents f7613eafe9f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2573
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1 /* Audacious - Cross-platform multimedia player
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
2 * Copyright (C) 2005-2008 Audacious development team
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
3 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
4 * Based on BMP:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2003-2004 BMP development team.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
6 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
7 * Based on XMMS:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
8 * Copyright (C) 1998-2003 XMMS development team.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
9 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
12 * the Free Software Foundation; under version 3 of the License.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
13 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
17 * GNU General Public License for more details.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
18 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses>.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
21 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
22 * The Audacious team does not consider modular code linking to
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
23 * Audacious or using our public API to be a derived work.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
24 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
25
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
26 /*#define AUD_DEBUG*/
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
27
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
28 #ifdef HAVE_CONFIG_H
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
29 # include "config.h"
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
30 #endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
31
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
32 #include "util.h"
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
33
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
34 #include <glib.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
35 #include <glib/gi18n.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
36 #include <gtk/gtk.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
37 #include <stdlib.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
38 #include <string.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
39 #include <ctype.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
40 #include <math.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
41
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
42 #include "platform/smartinclude.h"
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
43 #include <errno.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
44
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
45 #ifdef HAVE_FTS_H
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
46 # include <sys/types.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
47 # include <sys/stat.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
48 # include <fts.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
49 #endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
50
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2586
diff changeset
51 #include <audlegacy/input.h>
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2586
diff changeset
52 #include <audlegacy/playback.h>
2573
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
53
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
54 #ifdef USE_CHARDET
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
55 # include "../libguess/libguess.h"
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
56 # ifdef HAVE_UDET
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
57 # include <libudet_c.h>
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
58 # endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
59 #endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
60
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
61 #include "plugin.h"
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
62
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
63 /*
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
64 * find <file> in directory <dirname> or subdirectories. return
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
65 * pointer to complete filename which has to be freed by calling
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
66 * "g_free()" after use. Returns NULL if file could not be found.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
67 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
68
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
69 /* somebody tell me how to make use of those funcs from string.h that are in core... */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
70 gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
71 str_has_suffix_nocase(const gchar * str, const gchar * suffix)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
72 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
73 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
74 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
75
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
76 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
77 str_replace_char(gchar * str, gchar old, gchar new)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
78 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
79 gchar *match;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
80
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
81 g_return_val_if_fail(str != NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
82
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
83 match = str;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
84 while ((match = strchr(match, old)))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
85 *match = new;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
86
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
87 return str;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
88 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
89
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
90 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
91 str_replace_drive_letter(gchar * str)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
92 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
93 gchar *match, *match_end;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
94
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
95 g_return_val_if_fail(str != NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
96
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
97 while ((match = strstr(str, ":\\"))) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
98 match--;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
99 match_end = match + 3;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
100 *match++ = '/';
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
101 while (*match_end)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
102 *match++ = *match_end++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
103 *match = 0; /* the end of line */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
104 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
105
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
106 return str;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
107 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
108
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
109 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
110 convert_dos_path(gchar * path)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
111 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
112 g_return_val_if_fail(path != NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
113
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
114 /* replace drive letter with '/' */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
115 str_replace_drive_letter(path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
116
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
117 /* replace '\' with '/' */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
118 str_replace_char(path, '\\', '/');
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
119
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
120 return path;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
121 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
122
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
123 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
124 escape_shell_chars(const gchar * string)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
125 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
126 const gchar *special = "$`\"\\"; /* Characters to escape */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
127 const gchar *in = string;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
128 gchar *out, *escaped;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
129 gint num = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
130
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
131 while (*in != '\0')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
132 if (strchr(special, *in++))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
133 num++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
134
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
135 escaped = g_malloc(strlen(string) + num + 1);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
136
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
137 in = string;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
138 out = escaped;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
139
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
140 while (*in != '\0') {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
141 if (strchr(special, *in))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
142 *out++ = '\\';
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
143 *out++ = *in++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
144 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
145 *out = '\0';
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
146
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
147 return escaped;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
148 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
149
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
150
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
151 typedef struct {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
152 const gchar *to_match;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
153 gchar *match;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
154 gboolean found;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
155 } FindFileContext;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
156
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
157 static const struct {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
158 AFormat afmt;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
159 SAD_sample_format sadfmt;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
160 } format_table[] = {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
161 {FMT_U8, SAD_SAMPLE_U8},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
162 {FMT_S8, SAD_SAMPLE_S8},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
163
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
164 {FMT_S16_LE, SAD_SAMPLE_S16_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
165 {FMT_S16_BE, SAD_SAMPLE_S16_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
166 {FMT_S16_NE, SAD_SAMPLE_S16},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
167
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
168 {FMT_U16_LE, SAD_SAMPLE_U16_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
169 {FMT_U16_BE, SAD_SAMPLE_U16_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
170 {FMT_U16_NE, SAD_SAMPLE_U16},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
171
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
172 {FMT_S24_LE, SAD_SAMPLE_S24_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
173 {FMT_S24_BE, SAD_SAMPLE_S24_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
174 {FMT_S24_NE, SAD_SAMPLE_S24},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
175
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
176 {FMT_U24_LE, SAD_SAMPLE_U24_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
177 {FMT_U24_BE, SAD_SAMPLE_U24_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
178 {FMT_U24_NE, SAD_SAMPLE_U24},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
179
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
180 {FMT_S32_LE, SAD_SAMPLE_S32_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
181 {FMT_S32_BE, SAD_SAMPLE_S32_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
182 {FMT_S32_NE, SAD_SAMPLE_S32},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
183
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
184 {FMT_U32_LE, SAD_SAMPLE_U32_LE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
185 {FMT_U32_BE, SAD_SAMPLE_U32_BE},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
186 {FMT_U32_NE, SAD_SAMPLE_U32},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
187
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
188 {FMT_FLOAT, SAD_SAMPLE_FLOAT},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
189 {FMT_FIXED32, SAD_SAMPLE_FIXED32},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
190 };
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
191
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
192 SAD_sample_format
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
193 sadfmt_from_afmt(AFormat fmt)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
194 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
195 int i;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
196 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
197 if (format_table[i].afmt == fmt) return format_table[i].sadfmt;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
198 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
199
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
200 return -1;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
201 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
202
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
203
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
204 static gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
205 find_file_func(const gchar * path, const gchar * basename, gpointer data)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
206 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
207 FindFileContext *context = data;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
208
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
209 if (strlen(path) > FILENAME_MAX) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
210 AUDDBG("Ignoring path: name too long (%s)\n", path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
211 return TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
212 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
213
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
214 if (aud_vfs_file_test(path, G_FILE_TEST_IS_REGULAR)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
215 if (!strcasecmp(basename, context->to_match)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
216 context->match = g_strdup(path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
217 context->found = TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
218 return TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
219 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
220 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
221 else if (aud_vfs_file_test(path, G_FILE_TEST_IS_DIR)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
222 dir_foreach(path, find_file_func, context, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
223 if (context->found)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
224 return TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
225 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
226
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
227 return FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
228 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
229
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
230 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
231 find_file_recursively(const gchar * path, const gchar * filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
232 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
233 FindFileContext context;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
234 gchar *out = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
235
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
236 context.to_match = filename;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
237 context.match = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
238 context.found = FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
239
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
240 dir_foreach(path, find_file_func, &context, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
241
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
242 if (context.match)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
243 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
244 out = g_filename_to_uri(context.match, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
245 g_free(context.match);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
246 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
247
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
248 return out;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
249 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
250
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
251 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
252 find_path_recursively(const gchar * path, const gchar * filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
253 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
254 FindFileContext context;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
255
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
256 context.to_match = filename;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
257 context.match = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
258 context.found = FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
259
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
260 dir_foreach(path, find_file_func, &context, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
261
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
262 return context.match;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
263 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
264
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
265
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
266 typedef enum {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
267 ARCHIVE_UNKNOWN = 0,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
268 ARCHIVE_DIR,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
269 ARCHIVE_TAR,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
270 ARCHIVE_TGZ,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
271 ARCHIVE_ZIP,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
272 ARCHIVE_TBZ2
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
273 } ArchiveType;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
274
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
275 typedef gchar *(*ArchiveExtractFunc) (const gchar *, const gchar *);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
276
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
277 typedef struct {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
278 ArchiveType type;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
279 const gchar *ext;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
280 } ArchiveExtensionType;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
281
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
282 static ArchiveExtensionType archive_extensions[] = {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
283 {ARCHIVE_TAR, ".tar"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
284 {ARCHIVE_ZIP, ".wsz"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
285 {ARCHIVE_ZIP, ".zip"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
286 {ARCHIVE_TGZ, ".tar.gz"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
287 {ARCHIVE_TGZ, ".tgz"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
288 {ARCHIVE_TBZ2, ".tar.bz2"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
289 {ARCHIVE_TBZ2, ".bz2"},
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
290 {ARCHIVE_UNKNOWN, NULL}
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
291 };
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
292
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
293 static gchar *archive_extract_tar(const gchar * archive, const gchar * dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
294 static gchar *archive_extract_zip(const gchar * archive, const gchar * dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
295 static gchar *archive_extract_tgz(const gchar * archive, const gchar * dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
296 static gchar *archive_extract_tbz2(const gchar * archive, const gchar * dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
297
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
298 static ArchiveExtractFunc archive_extract_funcs[] = {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
299 NULL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
300 NULL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
301 archive_extract_tar,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
302 archive_extract_tgz,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
303 archive_extract_zip,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
304 archive_extract_tbz2
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
305 };
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
306
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
307
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
308 /* FIXME: these functions can be generalised into a function using a
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
309 * command lookup table */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
310
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
311 static const gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
312 get_tar_command(void)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
313 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
314 static const gchar *command = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
315
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
316 if (!command) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
317 if (!(command = getenv("TARCMD")))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
318 command = "tar";
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
319 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
320
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
321 return command;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
322 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
323
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
324 static const gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
325 get_unzip_command(void)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
326 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
327 static const gchar *command = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
328
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
329 if (!command) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
330 if (!(command = getenv("UNZIPCMD")))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
331 command = "unzip";
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
332 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
333
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
334 return command;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
335 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
336
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
337
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
338 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
339 archive_extract_tar(const gchar * archive, const gchar * dest)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
340 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
341 return g_strdup_printf("%s >/dev/null xf \"%s\" -C %s",
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
342 get_tar_command(), archive, dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
343 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
344
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
345 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
346 archive_extract_zip(const gchar * archive, const gchar * dest)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
347 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
348 return g_strdup_printf("%s >/dev/null -o -j \"%s\" -d %s",
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
349 get_unzip_command(), archive, dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
350 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
351
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
352 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
353 archive_extract_tgz(const gchar * archive, const gchar * dest)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
354 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
355 return g_strdup_printf("%s >/dev/null xzf \"%s\" -C %s",
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
356 get_tar_command(), archive, dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
357 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
358
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
359 static gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
360 archive_extract_tbz2(const gchar * archive, const gchar * dest)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
361 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
362 return g_strdup_printf("bzip2 -dc \"%s\" | %s >/dev/null xf - -C %s",
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
363 archive, get_tar_command(), dest);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
364 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
365
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
366
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
367 ArchiveType
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
368 archive_get_type(const gchar * filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
369 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
370 gint i = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
371
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
372 if (g_file_test(filename, G_FILE_TEST_IS_DIR))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
373 return ARCHIVE_DIR;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
374
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
375 while (archive_extensions[i].ext) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
376 if (g_str_has_suffix(filename, archive_extensions[i].ext)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
377 return archive_extensions[i].type;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
378 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
379 i++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
380 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
381
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
382 return ARCHIVE_UNKNOWN;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
383 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
384
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
385 gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
386 file_is_archive(const gchar * filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
387 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
388 return (archive_get_type(filename) > ARCHIVE_DIR);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
389 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
390
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
391 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
392 archive_basename(const gchar * str)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
393 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
394 gint i = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
395
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
396 while (archive_extensions[i].ext) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
397 if (str_has_suffix_nocase(str, archive_extensions[i].ext)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
398 const gchar *end = g_strrstr(str, archive_extensions[i].ext);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
399 if (end) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
400 return g_strndup(str, end - str);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
401 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
402 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
403 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
404 i++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
405 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
406
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
407 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
408 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
409
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
410 /*
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
411 decompress_archive
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
412
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
413 Decompresses the archive "filename" to a temporary directory,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
414 returns the path to the temp dir, or NULL if failed,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
415 watch out tho, doesn't actually check if the system command succeeds :-|
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
416 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
417
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
418 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
419 archive_decompress(const gchar * filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
420 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
421 gchar *tmpdir, *cmd, *escaped_filename;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
422 ArchiveType type;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
423 #ifndef HAVE_MKDTEMP
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
424 mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
425 #endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
426
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
427 if ((type = archive_get_type(filename)) <= ARCHIVE_DIR)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
428 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
429
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
430 #ifdef HAVE_MKDTEMP
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
431 tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
432 if (!mkdtemp(tmpdir)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
433 g_free(tmpdir);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
434 AUDDBG("Unable to load skin: Failed to create temporary "
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
435 "directory: %s\n", g_strerror(errno));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
436 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
437 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
438 #else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
439 tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), (long) rand());
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
440 make_directory(tmpdir, mode755);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
441 #endif
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
442
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
443 escaped_filename = escape_shell_chars(filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
444 cmd = archive_extract_funcs[type] (escaped_filename, tmpdir);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
445 g_free(escaped_filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
446
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
447 if (!cmd) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
448 AUDDBG("extraction function is NULL!\n");
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
449 g_free(tmpdir);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
450 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
451 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
452
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
453 AUDDBG("Attempt to execute \"%s\"\n", cmd);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
454
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
455 if(system(cmd) != 0)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
456 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
457 AUDDBG("could not execute cmd %s\n",cmd);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
458 g_free(cmd);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
459 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
460 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
461 g_free(cmd);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
462
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
463 return tmpdir;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
464 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
465
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
466
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
467 #ifdef HAVE_FTS_H
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
468
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
469 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
470 del_directory(const gchar * dirname)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
471 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
472 gchar *const argv[2] = { (gchar *) dirname, NULL };
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
473 FTS *fts;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
474 FTSENT *p;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
475
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
476 fts = fts_open(argv, FTS_PHYSICAL, (gint(*)())NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
477 while ((p = fts_read(fts))) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
478 switch (p->fts_info) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
479 case FTS_D:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
480 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
481 case FTS_DNR:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
482 case FTS_ERR:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
483 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
484 case FTS_DP:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
485 rmdir(p->fts_accpath);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
486 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
487 default:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
488 unlink(p->fts_accpath);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
489 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
490 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
491 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
492 fts_close(fts);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
493 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
494
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
495 #else /* !HAVE_FTS */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
496
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
497 gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
498 del_directory_func(const gchar * path, const gchar * basename,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
499 gpointer params)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
500 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
501 if (!strcmp(basename, ".") || !strcmp(path, ".."))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
502 return FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
503
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
504 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
505 dir_foreach(path, del_directory_func, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
506 rmdir(path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
507 return FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
508 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
509
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
510 unlink(path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
511
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
512 return FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
513 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
514
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
515 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
516 del_directory(const gchar * path)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
517 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
518 dir_foreach(path, del_directory_func, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
519 rmdir(path);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
520 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
521
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
522 #endif /* ifdef HAVE_FTS */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
523
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
524 static void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
525 strip_string(GString *string)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
526 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
527 while (string->len > 0 && string->str[0] == ' ')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
528 g_string_erase(string, 0, 1);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
529
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
530 while (string->len > 0 && string->str[string->len - 1] == ' ')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
531 g_string_erase(string, string->len - 1, 1);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
532 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
533
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
534 static void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
535 strip_lower_string(GString *string)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
536 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
537 gchar *lower;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
538 strip_string(string);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
539
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
540 lower = g_ascii_strdown(string->str, -1);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
541 g_free(string->str);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
542 string->str = lower;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
543 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
544
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
545 static void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
546 close_ini_file_free_value(gpointer value)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
547 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
548 g_free((gchar*)value);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
549 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
550
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
551 static void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
552 close_ini_file_free_section(gpointer section)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
553 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
554 g_hash_table_destroy((GHashTable*)section);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
555 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
556
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
557 INIFile *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
558 open_ini_file(const gchar *filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
559 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
560 GHashTable *ini_file = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
561 GHashTable *section = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
562 GString *section_name, *key_name, *value;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
563 gpointer section_hash, key_hash;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
564 gchar *buffer = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
565 gsize off = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
566 gsize filesize = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
567
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
568 unsigned char x[] = { 0xff, 0xfe, 0x00 };
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
569
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
570 g_return_val_if_fail(filename, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
571 aud_vfs_file_get_contents(filename, &buffer, &filesize);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
572 if (buffer == NULL)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
573 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
574
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
575 /*
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
576 * Convert UTF-16 into something useful. Original implementation
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
577 * by incomp@#audacious. Cleanups \nenolod
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
578 * FIXME: can't we use a GLib function for that? -- 01mf02
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
579 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
580 if (filesize > 2 && !memcmp(&buffer[0],&x,2))
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
581 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
582 gchar *outbuf = g_malloc (filesize); /* it's safe to waste memory. */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
583 guint counter;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
584
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
585 for (counter = 2; counter < filesize; counter += 2)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
586 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
587 if (!memcmp(&buffer[counter+1], &x[2], 1)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
588 outbuf[(counter-2)/2] = buffer[counter];
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
589 } else {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
590 g_free(buffer);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
591 g_free(outbuf);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
592 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
593 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
594 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
595
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
596 outbuf[(counter-2)/2] = '\0';
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
597
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
598 if ((filesize - 2) / 2 == (counter - 2) / 2)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
599 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
600 g_free(buffer);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
601 buffer = outbuf;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
602 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
603 else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
604 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
605 g_free(buffer);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
606 g_free(outbuf);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
607 return NULL; /* XXX wrong encoding */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
608 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
609 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
610
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
611 section_name = g_string_new("");
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
612 key_name = g_string_new(NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
613 value = g_string_new(NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
614
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
615 ini_file = g_hash_table_new_full(NULL, NULL, NULL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
616 close_ini_file_free_section);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
617 section = g_hash_table_new_full(NULL, NULL, NULL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
618 close_ini_file_free_value);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
619 /* make a nameless section which should store all entries that are not
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
620 * embedded in a section */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
621 section_hash = GINT_TO_POINTER(g_string_hash(section_name));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
622 g_hash_table_insert(ini_file, section_hash, section);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
623
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
624 while (off < filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
625 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
626 /* ignore the following characters */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
627 if (buffer[off] == '\r' || buffer[off] == '\n' ||
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
628 buffer[off] == ' ' || buffer[off] == '\t')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
629 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
630 if (buffer[off] == '\n')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
631 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
632 g_string_free(key_name, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
633 g_string_free(value, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
634 key_name = g_string_new(NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
635 value = g_string_new(NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
636 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
637
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
638 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
639 continue;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
640 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
641
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
642 /* if we encounter a possible section statement */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
643 if (buffer[off] == '[')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
644 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
645 g_string_free(section_name, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
646 section_name = g_string_new(NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
647 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
648
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
649 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
650 goto return_sequence;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
651
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
652 while (buffer[off] != ']')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
653 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
654 /* if the section statement has not been closed before a
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
655 * linebreak */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
656 if (buffer[off] == '\n')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
657 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
658
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
659 g_string_append_c(section_name, buffer[off]);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
660 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
661 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
662 goto return_sequence;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
663 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
664 if (buffer[off] == '\n')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
665 continue;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
666 if (buffer[off] == ']')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
667 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
668 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
669 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
670 goto return_sequence;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
671
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
672 strip_lower_string(section_name);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
673 section_hash = GINT_TO_POINTER(g_string_hash(section_name));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
674
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
675 /* if this section already exists, we don't make a new one,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
676 * but reuse the old one */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
677 if (g_hash_table_lookup(ini_file, section_hash) != NULL)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
678 section = g_hash_table_lookup(ini_file, section_hash);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
679 else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
680 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
681 section = g_hash_table_new_full(NULL, NULL, NULL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
682 close_ini_file_free_value);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
683 g_hash_table_insert(ini_file, section_hash, section);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
684 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
685
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
686 continue;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
687 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
688 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
689
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
690 if (buffer[off] == '=')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
691 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
692 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
693 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
694 goto return_sequence;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
695
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
696 while (buffer[off] != '\n' && buffer[off] != '\r')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
697 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
698 g_string_append_c(value, buffer[off]);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
699 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
700 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
701 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
702 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
703
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
704 strip_lower_string(key_name);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
705 key_hash = GINT_TO_POINTER(g_string_hash(key_name));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
706 strip_string(value);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
707
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
708 if (key_name->len > 0 && value->len > 0)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
709 g_hash_table_insert(section, key_hash, g_strdup(value->str));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
710 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
711 else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
712 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
713 g_string_append_c(key_name, buffer[off]);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
714 off++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
715 if (off >= filesize)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
716 goto return_sequence;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
717 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
718 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
719
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
720 return_sequence:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
721 g_string_free(section_name, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
722 g_string_free(key_name, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
723 g_string_free(value, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
724 g_free(buffer);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
725 return ini_file;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
726 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
727
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
728 /**
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
729 * Frees the memory allocated for inifile.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
730 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
731 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
732 close_ini_file(INIFile *inifile)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
733 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
734 g_return_if_fail(inifile);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
735 g_hash_table_destroy(inifile);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
736 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
737
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
738 /**
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
739 * Returns a string that corresponds to correct section and key in inifile.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
740 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
741 * Returns NULL if value was not found in inifile. Otherwise returns a copy
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
742 * of string pointed by "section" and "key". Returned string should be freed
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
743 * after use.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
744 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
745 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
746 read_ini_string(INIFile *inifile, const gchar *section, const gchar *key)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
747 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
748 GString *section_string;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
749 GString *key_string;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
750 gchar *value = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
751 gpointer section_hash, key_hash;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
752 GHashTable *section_table;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
753
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
754 g_return_val_if_fail(inifile, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
755
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
756 section_string = g_string_new(section);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
757 key_string = g_string_new(key);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
758 value = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
759
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
760 strip_lower_string(section_string);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
761 strip_lower_string(key_string);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
762 section_hash = GINT_TO_POINTER(g_string_hash(section_string));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
763 key_hash = GINT_TO_POINTER(g_string_hash(key_string));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
764 section_table = g_hash_table_lookup(inifile, section_hash);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
765
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
766 if (section_table) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
767 value = g_strdup(g_hash_table_lookup(section_table,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
768 GINT_TO_POINTER(key_hash)));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
769 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
770
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
771 g_string_free(section_string, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
772 g_string_free(key_string, TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
773
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
774 g_return_val_if_fail(value, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
775 return value;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
776 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
777
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
778 GArray *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
779 read_ini_array(INIFile *inifile, const gchar *section, const gchar *key)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
780 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
781 gchar *temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
782 GArray *a;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
783
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
784 g_return_val_if_fail((temp = read_ini_string(inifile, section, key)), NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
785
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
786 a = string_to_garray(temp);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
787 g_free(temp);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
788 return a;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
789 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
790
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
791 GArray *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
792 string_to_garray(const gchar * str)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
793 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
794 GArray *array;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
795 gint temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
796 const gchar *ptr = str;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
797 gchar *endptr;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
798
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
799 array = g_array_new(FALSE, TRUE, sizeof(gint));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
800 for (;;) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
801 temp = strtol(ptr, &endptr, 10);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
802 if (ptr == endptr)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
803 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
804 g_array_append_val(array, temp);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
805 ptr = endptr;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
806 while (!isdigit((int) *ptr) && (*ptr) != '\0')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
807 ptr++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
808 if (*ptr == '\0')
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
809 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
810 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
811 return (array);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
812 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
813
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
814 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
815 glist_movedown(GList * list)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
816 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
817 gpointer temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
818
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
819 if (g_list_next(list)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
820 temp = list->data;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
821 list->data = list->next->data;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
822 list->next->data = temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
823 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
824 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
825
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
826 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
827 glist_moveup(GList * list)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
828 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
829 gpointer temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
830
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
831 if (g_list_previous(list)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
832 temp = list->data;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
833 list->data = list->prev->data;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
834 list->prev->data = temp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
835 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
836 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
837
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
838 /* text_get_extents() taken from The GIMP (C) Spencer Kimball, Peter
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
839 * Mattis et al */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
840 gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
841 text_get_extents(const gchar * fontname,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
842 const gchar * text,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
843 gint * width, gint * height, gint * ascent, gint * descent)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
844 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
845 PangoFontDescription *font_desc;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
846 PangoLayout *layout;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
847 PangoRectangle rect;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
848
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
849 g_return_val_if_fail(fontname != NULL, FALSE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
850 g_return_val_if_fail(text != NULL, FALSE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
851
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
852 /* FIXME: resolution */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
853 layout = gtk_widget_create_pango_layout(GTK_WIDGET(mainwin), text);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
854
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
855 font_desc = pango_font_description_from_string(fontname);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
856 pango_layout_set_font_description(layout, font_desc);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
857 pango_font_description_free(font_desc);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
858 pango_layout_get_pixel_extents(layout, NULL, &rect);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
859
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
860 if (width)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
861 *width = rect.width;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
862 if (height)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
863 *height = rect.height;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
864
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
865 if (ascent || descent) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
866 PangoLayoutIter *iter;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
867 PangoLayoutLine *line;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
868
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
869 iter = pango_layout_get_iter(layout);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
870 line = pango_layout_iter_get_line(iter);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
871 pango_layout_iter_free(iter);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
872
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
873 pango_layout_line_get_pixel_extents(line, NULL, &rect);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
874
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
875 if (ascent)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
876 *ascent = PANGO_ASCENT(rect);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
877 if (descent)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
878 *descent = -PANGO_DESCENT(rect);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
879 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
880
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
881 g_object_unref(layout);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
882
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
883 return TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
884 }
2586
88009fb3fbe6 add ui_skinned_textbox
Tomasz Mon <desowin@gmail.com>
parents: 2573
diff changeset
885
2573
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
886 /* counts number of digits in a gint */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
887 guint
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
888 gint_count_digits(gint n)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
889 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
890 guint count = 0;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
891
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
892 n = ABS(n);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
893 do {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
894 count++;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
895 n /= 10;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
896 } while (n > 0);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
897
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
898 return count;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
899 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
900
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
901 gboolean
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
902 dir_foreach(const gchar * path, DirForeachFunc function,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
903 gpointer user_data, GError ** error)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
904 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
905 GError *error_out = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
906 GDir *dir;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
907 const gchar *entry;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
908 gchar *entry_fullpath;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
909
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
910 if (!(dir = g_dir_open(path, 0, &error_out))) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
911 g_propagate_error(error, error_out);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
912 return FALSE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
913 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
914
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
915 while ((entry = g_dir_read_name(dir))) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
916 entry_fullpath = g_build_filename(path, entry, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
917
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
918 if ((*function) (entry_fullpath, entry, user_data)) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
919 g_free(entry_fullpath);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
920 break;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
921 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
922
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
923 g_free(entry_fullpath);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
924 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
925
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
926 g_dir_close(dir);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
927
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
928 return TRUE;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
929 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
930
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
931 GtkWidget *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
932 make_filebrowser(const gchar *title, gboolean save)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
933 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
934 GtkWidget *dialog;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
935 GtkWidget *button;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
936
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
937 g_return_val_if_fail(title != NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
938
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
939 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin),
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
940 save ?
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
941 GTK_FILE_CHOOSER_ACTION_SAVE :
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
942 GTK_FILE_CHOOSER_ACTION_OPEN,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
943 NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
944
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
945 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
946 GTK_RESPONSE_REJECT);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
947
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
948 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
949 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
950
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
951 button = gtk_dialog_add_button(GTK_DIALOG(dialog), save ?
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
952 GTK_STOCK_SAVE : GTK_STOCK_OPEN,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
953 GTK_RESPONSE_ACCEPT);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
954
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
955 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
956 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
957 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
958
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
959 return dialog;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
960 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
961
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
962 /**
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
963 * util_info_dialog:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
964 * @title: The title of the message to show.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
965 * @text: The text of the message to show.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
966 * @button_text: The text of the button which will close the messagebox.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
967 * @modal: Whether or not the messagebox should be modal.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
968 * @button_action: Code to execute on when the messagebox is closed, or %NULL.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
969 * @action_data: Optional opaque data to pass to @button_action.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
970 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
971 * Displays a message box.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
972 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
973 * Return value: A GTK widget handle for the message box.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
974 **/
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
975 GtkWidget *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
976 util_info_dialog(const gchar * title, const gchar * text,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
977 const gchar * button_text, gboolean modal,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
978 GCallback button_action, gpointer action_data)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
979 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
980 GtkWidget *dialog;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
981 GtkWidget *dialog_vbox, *dialog_hbox, *dialog_bbox;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
982 GtkWidget *dialog_bbox_b1;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
983 GtkWidget *dialog_textlabel;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
984 GtkWidget *dialog_icon;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
985
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
986 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
987 gtk_window_set_type_hint( GTK_WINDOW(dialog) , GDK_WINDOW_TYPE_HINT_DIALOG );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
988 gtk_window_set_modal( GTK_WINDOW(dialog) , modal );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
989 gtk_window_set_title( GTK_WINDOW(dialog) , title );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
990 gtk_container_set_border_width( GTK_CONTAINER(dialog) , 10 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
991
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
992 dialog_vbox = gtk_vbox_new( FALSE , 0 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
993 dialog_hbox = gtk_hbox_new( FALSE , 0 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
994
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
995 /* icon */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
996 dialog_icon = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO , GTK_ICON_SIZE_DIALOG );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
997 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_icon , FALSE , FALSE , 2 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
998
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
999 /* label */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1000 dialog_textlabel = gtk_label_new( text );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1001 /* gtk_label_set_selectable( GTK_LABEL(dialog_textlabel) , TRUE ); */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1002 gtk_box_pack_start( GTK_BOX(dialog_hbox) , dialog_textlabel , TRUE , TRUE , 2 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1003
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1004 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_hbox , FALSE , FALSE , 2 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1005 gtk_box_pack_start( GTK_BOX(dialog_vbox) , gtk_hseparator_new() , FALSE , FALSE , 4 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1006
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1007 dialog_bbox = gtk_hbutton_box_new();
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1008 gtk_button_box_set_layout( GTK_BUTTON_BOX(dialog_bbox) , GTK_BUTTONBOX_END );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1009 dialog_bbox_b1 = gtk_button_new_with_label( button_text );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1010 g_signal_connect_swapped( G_OBJECT(dialog_bbox_b1) , "clicked" ,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1011 G_CALLBACK(gtk_widget_destroy) , dialog );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1012 if ( button_action )
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1013 g_signal_connect( G_OBJECT(dialog_bbox_b1) , "clicked" ,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1014 button_action , action_data );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1015
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1016 gtk_container_add( GTK_CONTAINER(dialog_bbox) , dialog_bbox_b1 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1017 gtk_box_pack_start( GTK_BOX(dialog_vbox) , dialog_bbox , FALSE , FALSE , 0 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1018
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1019 gtk_container_add( GTK_CONTAINER(dialog) , dialog_vbox );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1020
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1021 GTK_WIDGET_SET_FLAGS( dialog_bbox_b1 , GTK_CAN_DEFAULT);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1022 gtk_widget_grab_default( dialog_bbox_b1 );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1023
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1024 gtk_widget_show_all(dialog);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1025
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1026 return dialog;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1027 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1028
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1029
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1030 /**
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1031 * util_get_localdir:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1032 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1033 * Returns a string with the full path of Audacious local datadir (where config files are placed).
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1034 * It's useful in order to put in the right place custom config files for audacious plugins.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1035 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1036 * Return value: a string with full path of Audacious local datadir (should be freed after use)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1037 **/
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1038 gchar*
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1039 util_get_localdir(void)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1040 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1041 gchar *datadir;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1042 gchar *tmp;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1043
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1044 if ( (tmp = getenv("XDG_CONFIG_HOME")) == NULL )
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1045 datadir = g_build_filename( g_get_home_dir() , ".config" , "audacious" , NULL );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1046 else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1047 datadir = g_build_filename( tmp , "audacious" , NULL );
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1048
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1049 return datadir;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1050 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1051
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1052
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1053 gchar *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1054 construct_uri(gchar *string, const gchar *playlist_name) // uri, path and anything else
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1055 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1056 gchar *filename = g_strdup(string);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1057 gchar *tmp, *path;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1058 gchar *uri = NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1059
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1060 /* try to translate dos path */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1061 convert_dos_path(filename); /* in place replacement */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1062
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1063 // make full path uri here
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1064 // case 1: filename is raw full path or uri
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1065 if (filename[0] == '/' || strstr(filename, "://")) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1066 uri = g_filename_to_uri(filename, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1067 if(!uri) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1068 uri = g_strdup(filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1069 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1070 g_free(filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1071 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1072 // case 2: filename is not raw full path nor uri, playlist path is full path
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1073 // make full path by replacing last part of playlist path with filename. (using g_build_filename)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1074 else if (playlist_name[0] == '/' || strstr(playlist_name, "://")) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1075 path = g_filename_from_uri(playlist_name, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1076 if (!path) {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1077 path = g_strdup(playlist_name);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1078 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1079 tmp = strrchr(path, '/'); *tmp = '\0';
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1080 tmp = g_build_filename(path, filename, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1081 g_free(path); g_free(filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1082 uri = g_filename_to_uri(tmp, NULL, NULL);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1083 g_free(tmp);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1084 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1085 // case 3: filename is not raw full path nor uri, playlist path is not full path
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1086 // just abort.
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1087 else {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1088 g_free(filename);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1089 return NULL;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1090 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1091
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1092 AUDDBG("uri=%s\n", uri);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1093 return uri;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1094 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1095
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1096 /*
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1097 * minimize number of realloc's:
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1098 * - set N to nearest power of 2 not less then N
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1099 * - double it
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1100 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1101 * -- asphyx
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1102 *
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1103 * XXX: what's so smart about this?? seems wasteful and silly. --nenolod
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1104 */
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1105 gpointer
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1106 smart_realloc(gpointer ptr, gsize *size)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1107 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1108 *size = (size_t)pow(2, ceil(log(*size) / log(2)) + 1);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1109 if (ptr != NULL) free(ptr);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1110 ptr = malloc(*size);
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1111 return ptr;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1112 }
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1113
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1114 void
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1115 make_directory(const gchar * path, mode_t mode)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1116 {
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1117 if (g_mkdir_with_parents(path, mode) == 0)
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1118 return;
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1119
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1120 g_printerr(_("Could not create directory (%s): %s\n"), path,
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1121 g_strerror(errno));
c0b08527b121 allow loading compressed skins
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1122 }