media-export: Use libunistring for collation
authorJens Georg <mail@jensge.org>
Sun, 6 May 2012 20:15:12 +0000 (22:15 +0200)
committerJens Georg <mail@jensge.org>
Wed, 13 Jun 2012 19:51:10 +0000 (21:51 +0200)
configure.ac
src/plugins/media-export/Makefile.am
src/plugins/media-export/rygel-media-export-collate.c [new file with mode: 0644]
src/plugins/media-export/rygel-media-export-database.vala

index 797c5e6..06d1447 100644 (file)
@@ -173,6 +173,17 @@ then
     PKG_CHECK_MODULES(GSTREAMER_TAG, gstreamer-tag-0.10 >= $GSTREAMER_TAG_REQUIRED);
     PKG_CHECK_MODULES(GSTREAMER_APP, gstreamer-app-0.10 >= $GSTREAMER_APP_REQUIRED);
     RYGEL_CHECK_PACKAGES([sqlite3 gstreamer-tag-0.10 gstreamer-app-0.10])
+    AC_CHECK_HEADER([unistr.h],
+                    AC_CHECK_LIB([unistring],
+                                 [u8_strcoll],
+                                 [have_unistring=yes],[have_unistring=no]))
+    if test "x$have_unistring" = "xyes"; then
+        AC_DEFINE([HAVE_UNISTRING],[1],[Use libunistring for collation])
+        COLLATION_CFLAGS=
+        COLLATION_LIBS=-lunistring
+        AC_SUBST([COLLATION_CFLAGS])
+        AC_SUBST([COLLATION_LIBS])
+    fi
 fi
 
 dnl Gettext
index 2a3a153..75c9561 100644 (file)
@@ -35,7 +35,8 @@ librygel_media_export_la_SOURCES = \
        rygel-media-export-item.vala \
        rygel-media-export-jpeg-writer.vala \
        rygel-media-export-object-factory.vala \
-       rygel-media-export-writable-db-container.vala
+       rygel-media-export-writable-db-container.vala \
+       rygel-media-export-collate.c
 
 librygel_media_export_la_VALAFLAGS = \
        --pkg gupnp-dlna-1.0 \
@@ -49,7 +50,8 @@ librygel_media_export_la_LIBADD = \
        $(LIBGUPNP_DLNA_LIBS) \
        $(GSTREAMER_TAG_LIBS) \
        $(GSTREAMER_APP_LIBS) \
-       $(LIBSQLITE3_LIBS)
+       $(LIBSQLITE3_LIBS) \
+       $(COLLATION_LIBS)
 
 librygel_media_export_la_LDFLAGS = $(RYGEL_PLUGIN_LINKER_FLAGS)
 
diff --git a/src/plugins/media-export/rygel-media-export-collate.c b/src/plugins/media-export/rygel-media-export-collate.c
new file mode 100644 (file)
index 0000000..eccf527
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 Jens Georg <mail@jensge.org>.
+ *
+ * Author: Jens Georg <mail@jensge.org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+
+#ifdef HAVE_UNISTRING
+#include <unistr.h>
+gint rygel_media_export_utf8_collate_str (const char *a, const char *b)
+{
+    return u8_strcoll (a, b);
+}
+
+#else
+
+gint rygel_media_export_utf8_collate_str (const char *a, const char *b)
+{
+    return g_utf8_collate (a, b);
+}
+#endif
index 5dea5fa..16c007d 100644 (file)
@@ -27,6 +27,10 @@ public errordomain Rygel.MediaExport.DatabaseError {
     SQLITE_ERROR
 }
 
+namespace Rygel.MediaExport {
+    extern static int utf8_collate_str (string a, string b);
+}
+
 /**
  * This class is a thin wrapper around SQLite's database object.
  *
@@ -70,10 +74,10 @@ internal class Rygel.MediaExport.Database : SqliteWrapper {
         unowned uint8[] _b = (uint8[]) b;
         _b.length = blen;
 
-        var str_a = ((string) _a).casefold ();
-        var str_b = ((string) _b).casefold ();
+        var str_a = ((string) _a);
+        var str_b = ((string) _b);
 
-        return str_a.collate (str_b);
+        return utf8_collate_str (str_a, str_b);
     }
 
     /**