changeset 2196:dfa3c3aa2dc7

switched to mowgli_dictionary from GHashTable
author Eugene Zagidullin <e.asphyx@gmail.com>
date Thu, 29 Nov 2007 03:09:13 +0300
parents 9773d2c69857
children c8d558dab2a7
files src/demac/Makefile src/demac/apev2.c src/demac/apev2.h src/demac/plugin.c
diffstat 4 files changed, 23 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/demac/Makefile	Wed Nov 28 18:15:40 2007 +0100
+++ b/src/demac/Makefile	Thu Nov 29 03:09:13 2007 +0300
@@ -12,4 +12,4 @@
 
 CFLAGS += ${PLUGIN_CFLAGS}
 CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} -I../../intl -I../..
-LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS}
+LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${MOWGLI_LIBS}
--- a/src/demac/apev2.c	Wed Nov 28 18:15:40 2007 +0100
+++ b/src/demac/apev2.c	Thu Nov 29 03:09:13 2007 +0300
@@ -25,6 +25,7 @@
 #include <string.h> 
 
 #include <glib.h>
+#include <mowgli.h>
 #include <audacious/vfs.h>
 #include <audacious/plugin.h> 
 
@@ -36,22 +37,7 @@
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
-static gboolean strcase_equal (gconstpointer v1, gconstpointer v2) {
-  return (g_ascii_strcasecmp((gchar *)v1, (gchar *)v2) == 0);
-}
-
-static guint strcase_hash (gconstpointer v) {
-  gchar *tmp;
-  gchar buf[TMP_BUFSIZE+1];
-  gchar *p = buf;
-  
-  for(tmp=(gchar*)v; (*tmp && (p < buf+TMP_BUFSIZE)); tmp++)
-    *(p++) = g_ascii_toupper(*tmp);
-  *p = '\0';
-  return g_str_hash((gconstpointer)buf);
-}
-
-GHashTable* parse_apev2_tag(VFSFile *vfd) {
+mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd) {
   unsigned char tmp[TMP_BUFSIZE+1];
   unsigned char tmp2[TMP_BUFSIZE+1];
   guint64 signature;
@@ -59,7 +45,7 @@
   guint32 tag_size, item_size, item_flags;
   guint32 tag_items;
   guint32 tag_flags;
-  GHashTable *hash;
+  mowgli_dictionary_t *dict;
 
   aud_vfs_fseek(vfd, -32, SEEK_END);
   signature = get_le64(vfd);
@@ -84,7 +70,7 @@
     return NULL;
   }
   
-  hash = g_hash_table_new_full(strcase_hash, strcase_equal, g_free, g_free); /* string-keyed table with dynamically allocated keys and items */
+  dict = mowgli_dictionary_create(g_ascii_strcasecmp);
 
   aud_vfs_fseek(vfd, -tag_size, SEEK_END);
   int i;
@@ -109,8 +95,8 @@
       /* APEv2 stores all items in utf-8 */
       gchar *item = ((tag_version == 1000 ) ? aud_str_to_utf8((gchar*)tmp2) : g_strdup((gchar*)tmp2));
       
-      g_hash_table_insert (hash, g_strdup((gchar*)tmp), item);
+      mowgli_dictionary_add(dict, (char*)tmp, item);
   }
   
-  return hash;
+  return dict;
 }
--- a/src/demac/apev2.h	Wed Nov 28 18:15:40 2007 +0100
+++ b/src/demac/apev2.h	Thu Nov 29 03:09:13 2007 +0300
@@ -1,9 +1,9 @@
 #ifndef APEV2_H
 #define APEV2_H
 
-#include <glib.h>
+#include <mowgli.h>
 #include <audacious/vfs.h>
 
-GHashTable* parse_apev2_tag(VFSFile *vfd);
+mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd);
 
 #endif
--- a/src/demac/plugin.c	Wed Nov 28 18:15:40 2007 +0100
+++ b/src/demac/plugin.c	Thu Nov 29 03:09:13 2007 +0300
@@ -39,6 +39,7 @@
 #include <glib.h> 
 #include <gtk/gtk.h>
 #include <glib/gprintf.h>
+#include <mowgli.h>
 
 #include <audacious/i18n.h> 
 
@@ -293,6 +294,10 @@
     pb->output->pause(paused);
 }
 
+static void destroy_cb(mowgli_dictionary_elem_t *delem, void *privdata) {
+    g_free(delem->data);
+}
+
 Tuple *demac_probe_for_tuple (gchar *uri, VFSFile *vfd) {
 #ifdef DEBUG
     fprintf(stderr, "** demac: plugin.c: demac_probe_for_tuple()\n");
@@ -300,16 +305,16 @@
     Tuple *tpl = aud_tuple_new_from_filename(uri);
     gchar codec_string[32];
 
-    GHashTable *tag = NULL;
+    mowgli_dictionary_t *tag = NULL;
     gchar *item;
     if ((tag = parse_apev2_tag(vfd)) != NULL) {
-        if((item = g_hash_table_lookup (tag, "Artist")) != NULL) aud_tuple_associate_string(tpl, FIELD_ARTIST, NULL, item);
-        if((item = g_hash_table_lookup (tag, "Title")) != NULL) aud_tuple_associate_string(tpl, FIELD_TITLE, NULL, item);
-        if((item = g_hash_table_lookup (tag, "Album")) != NULL) aud_tuple_associate_string(tpl, FIELD_ALBUM, NULL, item);
-        if((item = g_hash_table_lookup (tag, "Comment")) != NULL) aud_tuple_associate_string(tpl, FIELD_COMMENT, NULL, item);
-        if((item = g_hash_table_lookup (tag, "Genre")) != NULL) aud_tuple_associate_string(tpl, FIELD_GENRE, NULL, item);
-        if((item = g_hash_table_lookup (tag, "Track")) != NULL) aud_tuple_associate_int(tpl, FIELD_TRACK_NUMBER, NULL, atoi(item));
-        if((item = g_hash_table_lookup (tag, "Year")) != NULL) aud_tuple_associate_int(tpl, FIELD_YEAR, NULL, atoi(item));
+        if((item = mowgli_dictionary_retrieve(tag, "Artist")) != NULL) aud_tuple_associate_string(tpl, FIELD_ARTIST, NULL, item);
+        if((item = mowgli_dictionary_retrieve(tag, "Title")) != NULL) aud_tuple_associate_string(tpl, FIELD_TITLE, NULL, item);
+        if((item = mowgli_dictionary_retrieve(tag, "Album")) != NULL) aud_tuple_associate_string(tpl, FIELD_ALBUM, NULL, item);
+        if((item = mowgli_dictionary_retrieve(tag, "Comment")) != NULL) aud_tuple_associate_string(tpl, FIELD_COMMENT, NULL, item);
+        if((item = mowgli_dictionary_retrieve(tag, "Genre")) != NULL) aud_tuple_associate_string(tpl, FIELD_GENRE, NULL, item);
+        if((item = mowgli_dictionary_retrieve(tag, "Track")) != NULL) aud_tuple_associate_int(tpl, FIELD_TRACK_NUMBER, NULL, atoi(item));
+        if((item = mowgli_dictionary_retrieve(tag, "Year")) != NULL) aud_tuple_associate_int(tpl, FIELD_YEAR, NULL, atoi(item));
     }
 
     APEContext *ctx = calloc(sizeof(APEContext), 1);
@@ -319,7 +324,7 @@
     ape_read_close(ctx);
     free(ctx);
 
-    if (tag) g_hash_table_remove_all(tag);
+    if (tag) mowgli_dictionary_destroy(tag, destroy_cb, NULL);
     
     g_sprintf(codec_string, "Monkey's Audio v%4.2f", (float)ctx->fileversion/1000.0);
 #ifdef DEBUG