[tracker] libtracker-common: New meegotouch-based encoding detector



commit 32580b69d5fe89a413f5087a0095ee9a358e9abf
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Feb 25 12:33:27 2011 +0100

    libtracker-common: New meegotouch-based encoding detector

 configure.ac                                       |    3 +
 src/libtracker-common/Makefile.am                  |    5 ++
 .../tracker-encoding-meegotouch.cpp                |   59 ++++++++++++++++++++
 .../tracker-encoding-meegotouch.h                  |   33 +++++++++++
 src/libtracker-common/tracker-encoding.c           |   11 +++-
 5 files changed, 109 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 076c9a7..1f0c943 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1031,6 +1031,9 @@ if test "x$enable_maemo" != "xno"; then
                      [have_meegotouch=yes],
                      [have_meegotouch=no])
 
+   LIBTRACKER_COMMON_CFLAGS="$LIBTRACKER_COMMON_CFLAGS $MEEGOTOUCH_CFLAGS"
+   LIBTRACKER_COMMON_LIBS="$LIBTRACKER_COMMON_LIBS $MEEGOTOUCH_LIBS"
+
    TRACKER_MINER_FS_CFLAGS="$TRACKER_MINER_FS_CFLAGS $MEEGOTOUCH_CFLAGS"
    TRACKER_MINER_FS_LIBS="$TRACKER_MINER_FS_LIBS $MEEGOTOUCH_LIBS"
 
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index a77387d..eeaabe3 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -53,6 +53,11 @@ libtracker_common_la_SOURCES += tracker-encoding-enca.c
 noinst_HEADERS += tracker-encoding-enca.h
 endif
 
+if HAVE_MEEGOTOUCH
+libtracker_common_la_SOURCES += tracker-encoding-meegotouch.cpp
+noinst_HEADERS += tracker-encoding-meegotouch.h
+endif
+
 if HAVE_TRACKER_FTS
 libtracker_common_la_SOURCES += tracker-language.c
 noinst_HEADERS += tracker-language.h
diff --git a/src/libtracker-common/tracker-encoding-meegotouch.cpp b/src/libtracker-common/tracker-encoding-meegotouch.cpp
new file mode 100644
index 0000000..9c3a086
--- /dev/null
+++ b/src/libtracker-common/tracker-encoding-meegotouch.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 Nokia <ivan frade nokia com>
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <MCharsetDetector>
+#include <MCharsetMatch>
+
+#include <glib.h>
+#include "tracker-encoding-meegotouch.h"
+
+/*
+ * See http://apidocs.meego.com/git-tip/mtf/class_m_charset_detector.html
+ */
+
+gchar *
+tracker_encoding_guess_meegotouch (const gchar *buffer,
+                                   gsize        size)
+{
+	/* Initialize detector */
+	MCharsetDetector detector ((const char *)buffer, (int)size);
+
+	if (detector.hasError ()) {
+		g_warning ("Charset detector error when creating: %s",
+		           detector.errorString ().toUtf8 (). data ());
+		return NULL;
+	}
+
+	MCharsetMatch bestMatch = detector.detect ();
+
+	if (detector.hasError ()) {
+		g_warning ("Charset detector error when detecting: %s",
+		           detector.errorString ().toUtf8 (). data ());
+		return NULL;
+	}
+
+	gchar *encoding = g_strdup (bestMatch.name ().toUtf8 ().data ());
+
+	g_debug ("Guessing charset as '%s' with %d confidence",
+	         encoding, bestMatch.confidence ());
+
+	return encoding;
+}
diff --git a/src/libtracker-common/tracker-encoding-meegotouch.h b/src/libtracker-common/tracker-encoding-meegotouch.h
new file mode 100644
index 0000000..7ae95df
--- /dev/null
+++ b/src/libtracker-common/tracker-encoding-meegotouch.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 Nokia <ivan frade nokia com>
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_COMMON_ENCODING_MEEGOTOUCH_H__
+#define __LIBTRACKER_COMMON_ENCODING_MEEGOTOUCH_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+gchar *tracker_encoding_guess_meegotouch (const gchar *buffer,
+                                          gsize        size);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_COMMON_ENCODING_MEEGOTOUCH_H__ */
diff --git a/src/libtracker-common/tracker-encoding.c b/src/libtracker-common/tracker-encoding.c
index 9a9ee07..dba19ee 100644
--- a/src/libtracker-common/tracker-encoding.c
+++ b/src/libtracker-common/tracker-encoding.c
@@ -23,14 +23,17 @@
 #include "tracker-encoding.h"
 
 #ifdef HAVE_ENCA
-#include <tracker-encoding-enca.h>
+#include "tracker-encoding-enca.h"
 #endif
 
+#ifdef HAVE_MEEGOTOUCH
+#include "tracker-encoding-meegotouch.h"
+#endif
 
 gboolean
 tracker_encoding_can_guess (void)
 {
-#ifdef HAVE_ENCA
+#if defined (HAVE_ENCA) || defined (HAVE_MEEGOTOUCH)
 	return TRUE;
 #else
 	return FALSE;
@@ -43,6 +46,10 @@ tracker_encoding_guess (const gchar *buffer,
 {
 	gchar *encoding = NULL;
 
+#ifdef HAVE_MEEGOTOUCH
+	encoding = tracker_encoding_guess_meegotouch (buffer, size);
+#endif /* HAVE_MEEGOTOUCH */
+
 #ifdef HAVE_ENCA
 	if (!encoding)
 		encoding = tracker_encoding_guess_enca (buffer, size);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]