Mercurial > audlegacy
diff src/audacious/tuple.c @ 3489:9580bb3e58fa trunk
Tuple handling API changed to include support for "hardcoded" fields.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Sat, 01 Sep 2007 07:08:21 +0300 |
| parents | 86dafe2300f7 |
| children | 899a7ed37a70 |
line wrap: on
line diff
--- a/src/audacious/tuple.c Fri Aug 31 22:54:13 2007 +0100 +++ b/src/audacious/tuple.c Sat Sep 01 07:08:21 2007 +0300 @@ -23,6 +23,33 @@ #include "tuple.h" + +const gchar *tuple_fields[FIELD_LAST] = { + "artist", + "title", + "album", + "comment", + "genre", + + "track", + "track-number", + "length", + "year", + "quality", + + "codec", + "file-name", + "file-path", + "file-ext", + "song-artist", + + "mtime", + "formatter", + "performer", + "copyright", +}; + + static mowgli_heap_t *tuple_heap = NULL; static mowgli_heap_t *tuple_value_heap = NULL; static mowgli_object_class_t tuple_klass; @@ -55,7 +82,7 @@ if (tuple_heap == NULL) { - tuple_heap = mowgli_heap_create(sizeof(Tuple), 256, BH_NOW); + tuple_heap = mowgli_heap_create(sizeof(Tuple), 32, BH_NOW); tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW); mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE); } @@ -85,11 +112,11 @@ realfn = g_filename_from_uri(filename, NULL, NULL); scratch = g_path_get_basename(realfn ? realfn : filename); - tuple_associate_string(tuple, "file-name", scratch); + tuple_associate_string(tuple, FIELD_FILE_NAME, NULL, scratch); g_free(scratch); scratch = g_path_get_dirname(realfn ? realfn : filename); - tuple_associate_string(tuple, "file-path", scratch); + tuple_associate_string(tuple, FIELD_FILE_PATH, NULL, scratch); g_free(scratch); g_free(realfn); realfn = NULL; @@ -97,21 +124,29 @@ ext = strrchr(filename, '.'); if (ext != NULL) { ++ext; - tuple_associate_string(tuple, "file-ext", scratch); + tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, scratch); } return tuple; } gboolean -tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string) +tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string) { TupleValue *value; + const gchar *tfield; g_return_val_if_fail(tuple != NULL, FALSE); - g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(nfield < FIELD_LAST, FALSE); - if ((value = mowgli_dictionary_delete(tuple->dict, field))) + if (nfield < 0) + tfield = field; + else { + tfield = tuple_fields[nfield]; + tuple->values[nfield] = NULL; + } + + if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) tuple_disassociate_now(value); if (string == NULL) @@ -121,27 +156,41 @@ value->type = TUPLE_STRING; value->value.string = g_strdup(string); - mowgli_dictionary_add(tuple->dict, field, value); + mowgli_dictionary_add(tuple->dict, tfield, value); + + if (nfield >= 0) + tuple->values[nfield] = value; return TRUE; } gboolean -tuple_associate_int(Tuple *tuple, const gchar *field, gint integer) +tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer) { TupleValue *value; + const gchar *tfield; g_return_val_if_fail(tuple != NULL, FALSE); - g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(nfield < FIELD_LAST, FALSE); - if ((value = mowgli_dictionary_delete(tuple->dict, field))) + if (nfield < 0) + tfield = field; + else { + tfield = tuple_fields[nfield]; + tuple->values[nfield] = NULL; + } + + if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) tuple_disassociate_now(value); value = mowgli_heap_alloc(tuple_value_heap); value->type = TUPLE_INT; value->value.integer = integer; - mowgli_dictionary_add(tuple->dict, field, value); + mowgli_dictionary_add(tuple->dict, tfield, value); + + if (nfield >= 0) + tuple->values[nfield] = value; return TRUE; } @@ -156,44 +205,64 @@ } void -tuple_disassociate(Tuple *tuple, const gchar *field) +tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field) { TupleValue *value; + const gchar *tfield; g_return_if_fail(tuple != NULL); - g_return_if_fail(field != NULL); + g_return_if_fail(nfield < FIELD_LAST); + + if (nfield < 0) + tfield = field; + else { + tfield = tuple_fields[nfield]; + tuple->values[nfield] = NULL; + } /* why _delete()? because _delete() returns the dictnode's data on success */ - if ((value = mowgli_dictionary_delete(tuple->dict, field)) == NULL) + if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL) return; - + tuple_disassociate_now(value); } TupleValueType -tuple_get_value_type(Tuple *tuple, const gchar *field) +tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field) { TupleValue *value; g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN); - g_return_val_if_fail(field != NULL, TUPLE_UNKNOWN); + g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN); + + if (nfield < 0) { + if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL) + return value->type; + } else { + if (tuple->values[nfield]) + return tuple->values[nfield]->type; + } - if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) - return TUPLE_UNKNOWN; - - return value->type; + return TUPLE_UNKNOWN; } const gchar * -tuple_get_string(Tuple *tuple, const gchar *field) +tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field) { TupleValue *value; g_return_val_if_fail(tuple != NULL, NULL); - g_return_val_if_fail(field != NULL, NULL); + g_return_val_if_fail(nfield < FIELD_LAST, NULL); - if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) - return NULL; + if (nfield < 0) { + if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) + return NULL; + } else { + if (tuple->values[nfield]) + value = tuple->values[nfield]; + else + return NULL; + } if (value->type != TUPLE_STRING) mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL); @@ -201,16 +270,23 @@ return value->value.string; } -int -tuple_get_int(Tuple *tuple, const gchar *field) +gint +tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field) { TupleValue *value; g_return_val_if_fail(tuple != NULL, 0); - g_return_val_if_fail(field != NULL, 0); + g_return_val_if_fail(nfield < FIELD_LAST, 0); - if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) - return 0; + if (nfield < 0) { + if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL) + return 0; + } else { + if (tuple->values[nfield]) + value = tuple->values[nfield]; + else + return 0; + } if (value->type != TUPLE_INT) mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
