Mercurial > audlegacy
annotate src/audacious/tuple.c @ 3414:e45ad1bc06fa trunk
update Japanese translation
| author | VDR dai (audacious) <d+audacious@vdr.jp> |
|---|---|
| date | Fri, 31 Aug 2007 10:34:53 +0900 |
| parents | 86dafe2300f7 |
| children | 7c2e63c5a001 9580bb3e58fa |
| rev | line source |
|---|---|
| 3278 | 1 /* |
| 2 * Audacious | |
| 3 * Copyright (c) 2006-2007 Audacious team | |
| 4 * | |
| 5 * This program is free software; you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License as published by | |
| 7 * the Free Software Foundation; under version 3 of the License. | |
| 8 * | |
| 9 * This program is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
| 16 * | |
| 17 * The Audacious team does not consider modular code linking to | |
| 18 * Audacious or using our public API to be a derived work. | |
| 19 */ | |
| 20 | |
| 21 #include <glib.h> | |
| 22 #include <mowgli.h> | |
| 23 | |
| 24 #include "tuple.h" | |
| 25 | |
| 26 static mowgli_heap_t *tuple_heap = NULL; | |
| 27 static mowgli_heap_t *tuple_value_heap = NULL; | |
| 28 static mowgli_object_class_t tuple_klass; | |
| 29 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
30 /* iterative destructor of tuple values. */ |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
31 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
32 tuple_value_destroy(mowgli_dictionary_elem_t *delem, gpointer privdata) |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
33 { |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
34 TupleValue *value = (TupleValue *) delem->data; |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
35 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
36 if (value->type == TUPLE_STRING) |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
37 g_free(value->value.string); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
38 |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
39 mowgli_heap_free(tuple_value_heap, value); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
40 } |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
41 |
| 3278 | 42 static void |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
43 tuple_destroy(gpointer data) |
| 3278 | 44 { |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
45 Tuple *tuple = (Tuple *) data; |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
46 |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
47 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL); |
| 3278 | 48 mowgli_heap_free(tuple_heap, tuple); |
| 49 } | |
| 50 | |
| 51 Tuple * | |
| 52 tuple_new(void) | |
| 53 { | |
| 54 Tuple *tuple; | |
| 55 | |
| 56 if (tuple_heap == NULL) | |
| 57 { | |
| 3281 | 58 tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW); |
| 59 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); | |
| 3278 | 60 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); |
| 61 } | |
| 62 | |
| 63 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4 | |
| 64 when it is released --nenolod */ | |
| 65 tuple = mowgli_heap_alloc(tuple_heap); | |
| 66 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL); | |
| 67 | |
| 68 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp); | |
| 69 | |
| 70 return tuple; | |
| 71 } | |
| 72 | |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
73 Tuple * |
|
3304
00286cde2485
Make filename a const
Christian Birchinger <joker@netswarm.net>
parents:
3303
diff
changeset
|
74 tuple_new_from_filename(const gchar *filename) |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
75 { |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
76 gchar *scratch, *ext, *realfn; |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
77 Tuple *tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
78 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
79 g_return_val_if_fail(filename != NULL, NULL); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
80 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
81 tuple = tuple_new(); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
82 |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
83 g_return_val_if_fail(tuple != NULL, NULL); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
84 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
85 realfn = g_filename_from_uri(filename, NULL, NULL); |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
86 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
87 scratch = g_path_get_basename(realfn ? realfn : filename); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
88 tuple_associate_string(tuple, "file-name", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
89 g_free(scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
90 |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
91 scratch = g_path_get_dirname(realfn ? realfn : filename); |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
92 tuple_associate_string(tuple, "file-path", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
93 g_free(scratch); |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
94 |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
95 g_free(realfn); realfn = NULL; |
|
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
96 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
97 ext = strrchr(filename, '.'); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
98 if (ext != NULL) { |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
99 ++ext; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
100 tuple_associate_string(tuple, "file-ext", scratch); |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
101 } |
|
3303
eaf68ed98166
Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents:
3301
diff
changeset
|
102 |
|
3301
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
103 return tuple; |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
104 } |
|
008530664ba1
Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents:
3282
diff
changeset
|
105 |
| 3278 | 106 gboolean |
| 107 tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string) | |
| 108 { | |
| 109 TupleValue *value; | |
| 110 | |
| 111 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 112 g_return_val_if_fail(field != NULL, FALSE); | |
| 113 | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
114 if ((value = mowgli_dictionary_delete(tuple->dict, field))) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
115 tuple_disassociate_now(value); |
| 3278 | 116 |
|
3329
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
117 if (string == NULL) |
|
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
118 return TRUE; |
|
70149c3555f4
For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents:
3304
diff
changeset
|
119 |
| 3278 | 120 value = mowgli_heap_alloc(tuple_value_heap); |
| 121 value->type = TUPLE_STRING; | |
| 122 value->value.string = g_strdup(string); | |
| 123 | |
| 124 mowgli_dictionary_add(tuple->dict, field, value); | |
| 125 | |
| 126 return TRUE; | |
| 127 } | |
| 128 | |
| 129 gboolean | |
| 130 tuple_associate_int(Tuple *tuple, const gchar *field, gint integer) | |
| 131 { | |
| 132 TupleValue *value; | |
| 133 | |
| 134 g_return_val_if_fail(tuple != NULL, FALSE); | |
| 135 g_return_val_if_fail(field != NULL, FALSE); | |
| 136 | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
137 if ((value = mowgli_dictionary_delete(tuple->dict, field))) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
138 tuple_disassociate_now(value); |
| 3278 | 139 |
| 140 value = mowgli_heap_alloc(tuple_value_heap); | |
| 141 value->type = TUPLE_INT; | |
| 142 value->value.integer = integer; | |
| 143 | |
| 144 mowgli_dictionary_add(tuple->dict, field, value); | |
| 145 | |
| 146 return TRUE; | |
| 147 } | |
| 148 | |
| 149 void | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
150 tuple_disassociate_now(TupleValue *value) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
151 { |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
152 if (value->type == TUPLE_STRING) |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
153 g_free(value->value.string); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
154 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
155 mowgli_heap_free(tuple_value_heap, value); |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
156 } |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
157 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
158 void |
| 3278 | 159 tuple_disassociate(Tuple *tuple, const gchar *field) |
| 160 { | |
| 161 TupleValue *value; | |
| 162 | |
| 163 g_return_if_fail(tuple != NULL); | |
| 164 g_return_if_fail(field != NULL); | |
| 165 | |
| 166 /* why _delete()? because _delete() returns the dictnode's data on success */ | |
| 167 if ((value = mowgli_dictionary_delete(tuple->dict, field)) == NULL) | |
| 168 return; | |
|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
169 |
|
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
3329
diff
changeset
|
170 tuple_disassociate_now(value); |
| 3278 | 171 } |
| 172 | |
| 173 TupleValueType | |
| 174 tuple_get_value_type(Tuple *tuple, const gchar *field) | |
| 175 { | |
| 176 TupleValue *value; | |
| 177 | |
|
3280
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
178 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); |
|
a26138e391ee
Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3278
diff
changeset
|
179 g_return_val_if_fail(field != NULL, TUPLE_UNKNOWN); |
| 3278 | 180 |
| 181 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) | |
| 182 return TUPLE_UNKNOWN; | |
| 183 | |
| 184 return value->type; | |
| 185 } | |
| 186 | |
| 187 const gchar * | |
| 188 tuple_get_string(Tuple *tuple, const gchar *field) | |
| 189 { | |
| 190 TupleValue *value; | |
| 191 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
192 g_return_val_if_fail(tuple != NULL, NULL); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
193 g_return_val_if_fail(field != NULL, NULL); |
| 3278 | 194 |
| 195 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) | |
| 196 return NULL; | |
| 197 | |
| 198 if (value->type != TUPLE_STRING) | |
| 199 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); | |
| 200 | |
| 201 return value->value.string; | |
| 202 } | |
| 203 | |
| 204 int | |
| 205 tuple_get_int(Tuple *tuple, const gchar *field) | |
| 206 { | |
| 207 TupleValue *value; | |
| 208 | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
209 g_return_val_if_fail(tuple != NULL, 0); |
|
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
210 g_return_val_if_fail(field != NULL, 0); |
| 3278 | 211 |
| 212 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
213 return 0; |
| 3278 | 214 |
| 215 if (value->type != TUPLE_INT) | |
|
3282
b78d3197c70d
Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents:
3281
diff
changeset
|
216 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0); |
| 3278 | 217 |
| 218 return value->value.integer; | |
| 219 } |
