summaryrefslogtreecommitdiffstats
path: root/src/projects/k3bencodingconverter.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-03 02:15:56 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-03 02:15:56 +0000
commit50b48aec6ddd451a6d1709c0942477b503457663 (patch)
treea9ece53ec06fd0a2819de7a2a6de997193566626 /src/projects/k3bencodingconverter.cpp
downloadk3b-50b48aec6ddd451a6d1709c0942477b503457663.tar.gz
k3b-50b48aec6ddd451a6d1709c0942477b503457663.zip
Added abandoned KDE3 version of K3B
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k3b@1084400 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/projects/k3bencodingconverter.cpp')
-rw-r--r--src/projects/k3bencodingconverter.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/projects/k3bencodingconverter.cpp b/src/projects/k3bencodingconverter.cpp
new file mode 100644
index 0000000..460abbe
--- /dev/null
+++ b/src/projects/k3bencodingconverter.cpp
@@ -0,0 +1,130 @@
+/*
+ *
+ * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
+ * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+#include <config.h>
+
+#include "k3bencodingconverter.h"
+
+#include <qwidget.h>
+#include <qlayout.h>
+
+#include <kdebug.h>
+
+#ifdef HAVE_ICONV_H
+#include <langinfo.h>
+#include <iconv.h>
+#endif
+
+
+class K3bEncodingConverter::Private
+{
+ public:
+ iconv_t ic;
+ QString localEncoding;
+ QString lastEncoding;
+};
+
+
+K3bEncodingConverter::K3bEncodingConverter()
+{
+ d = new Private;
+#ifdef HAVE_ICONV_H
+ char* codec = nl_langinfo( CODESET );
+ d->localEncoding = QString::fromLocal8Bit( codec );
+ kdDebug() << "(K3bDataUrlAddingDialog) using locale codec: " << codec << endl;
+ d->ic = ::iconv_open( "UCS-2BE", codec );
+#endif
+}
+
+
+K3bEncodingConverter::~K3bEncodingConverter()
+{
+#ifdef HAVE_ICONV_H
+ ::iconv_close( d->ic );
+#endif
+ delete d;
+}
+
+
+bool K3bEncodingConverter::encodedLocally( const QCString& s )
+{
+#ifdef HAVE_ICONV_H
+ QCString utf8Encoded( s.length()*2 );
+#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ const char* in = s.data();
+#else
+ char* in = s.data();
+#endif
+ char* out = utf8Encoded.data();
+ size_t inSize = s.length();
+ size_t outSize = utf8Encoded.size();
+ return( (size_t)-1 != ::iconv( d->ic, &in, &inSize, &out, &outSize ) );
+#else
+ return true;
+#endif
+}
+
+
+bool K3bEncodingConverter::fixEncoding( const QCString& s, QCString& result, QWidget* parent, bool cache )
+{
+#ifdef IMPLEMENT_THIS_METHOD // HAVE_ICONV_H
+ if( !d->lastEncoding.isEmpty() ) {
+ //
+ // try converting with the last encoding
+ //
+ if( convert( s, result, d->lastEncoding, d->localEncoding )
+ && encodedLocally( result ) ) {
+ return true;
+ }
+ }
+
+
+
+ if( cache ) {
+
+ }
+ else
+ d->lastEncoding = QString::null;
+#else
+ return false;
+#endif
+}
+
+
+bool K3bEncodingConverter::convert( const QCString& s, QCString& result, const QString& from, const QString& to )
+{
+ bool r = false;
+
+#ifdef HAVE_ICONV_H
+ iconv_t ic = ::iconv_open( to.local8Bit(), from.local8Bit() );
+
+ result.resize( s.length() * 2 );
+#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ const char* in = s.data();
+#else
+ char* in = s.data();
+#endif
+ char* out = result.data();
+ size_t inSize = s.length();
+ size_t outSize = result.size();
+
+ if( (size_t)-1 != ::iconv( ic, &in, &inSize, &out, &outSize ) )
+ r = true;
+
+ ::iconv_close( ic );
+#endif
+
+ return r;
+}