Mercurial > audlegacy
changeset 4631:6cda48638a58
Remove code repetition by using a function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 11 Jun 2008 18:02:53 +0300 |
parents | 64c40b3e69f4 |
children | f733f3d75850 |
files | src/audacious/dbus.c |
diffstat | 1 files changed, 15 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/dbus.c Wed Jun 11 18:01:33 2008 +0300 +++ b/src/audacious/dbus.c Wed Jun 11 18:02:53 2008 +0300 @@ -211,8 +211,14 @@ return NULL; } -static void -remove_metadata_value(gpointer value) +static void tuple_insert_to_hash(GHashTable *md, Tuple *tuple, const gchar *key) +{ + GValue *value = tuple_value_to_gvalue(tuple, key); + if (value != NULL) + g_hash_table_insert(md, key, value); +} + +static void remove_metadata_value(gpointer value) { g_value_unset((GValue*)value); g_free((GValue*)value); @@ -228,40 +234,13 @@ md = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, remove_metadata_value); - value = tuple_value_to_gvalue(tuple, "length"); - if (value != NULL) { - g_hash_table_insert(md, "length", value); - } - - value = tuple_value_to_gvalue(tuple, "title"); - if (value != NULL) { - g_hash_table_insert(md, "title", value); - } - - value = tuple_value_to_gvalue(tuple, "artist"); - if (value != NULL) { - g_hash_table_insert(md, "artist", value); - } - - value = tuple_value_to_gvalue(tuple, "album"); - if (value != NULL) { - g_hash_table_insert(md, "album", value); - } - - value = tuple_value_to_gvalue(tuple, "genre"); - if (value != NULL) { - g_hash_table_insert(md, "genre", value); - } - - value = tuple_value_to_gvalue(tuple, "codec"); - if (value != NULL) { - g_hash_table_insert(md, "codec", value); - } - - value = tuple_value_to_gvalue(tuple, "quality"); - if (value != NULL) { - g_hash_table_insert(md, "quality", value); - } + tuple_insert_to_hash(md, tuple, "length"); + tuple_insert_to_hash(md, tuple, "title"); + tuple_insert_to_hash(md, tuple, "artist"); + tuple_insert_to_hash(md, tuple, "album"); + tuple_insert_to_hash(md, tuple, "genre"); + tuple_insert_to_hash(md, tuple, "codec"); + tuple_insert_to_hash(md, tuple, "quality"); return md; }