Commit 32580b69 authored by Aleksander Morgado's avatar Aleksander Morgado Committed by Philip Van Hoof

libtracker-common: New meegotouch-based encoding detector

parent 0dac6bff
......@@ -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"
......
......@@ -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
......
/*
* 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;
}
/*
* 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__ */
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment