Fixed encoding bugs for good, this time.

This commit is contained in:
Olivier Teulière 2010-01-23 23:34:48 +00:00
parent 51b0197afd
commit 41b0d38c8f
3 changed files with 59 additions and 15 deletions

View file

@ -63,7 +63,7 @@ BUILT_SOURCES = \
resources.cpp
eliot_SOURCES = \
qtcommon.h \
qtcommon.h qtcommon.cpp \
coord_model.h coord_model.cpp \
bag_widget.cpp bag_widget.h \
dic_tools_widget.cpp dic_tools_widget.h \

48
qt/qtcommon.cpp Normal file
View file

@ -0,0 +1,48 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2010 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include "qtcommon.h"
using namespace std;
wstring qtw(const QString &q)
{
#ifdef QT_NO_STL
wchar_t *array = new wchar_t[q.size()];
int size = q.toWCharArray(array);
wstring ws(array, size);
delete[] array;
return ws;
#else
return q.toStdWString();
#endif
}
QString qfw(const wstring &wstr)
{
#ifdef QT_NO_STL
return QString::fromWCharArray(wstr.c_str());
#else
return QString::fromStdWString(wstr);
#endif
}

View file

@ -1,7 +1,7 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2008 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
* Copyright (C) 2010 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* 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
@ -22,7 +22,9 @@
#define QT_COMMON_H_
#include "config.h"
#include <string>
#include <QtCore/QString>
#include "encoding.h"
#if ENABLE_NLS
# include <libintl.h>
@ -34,21 +36,15 @@
# define _(String) String
#endif
// Convert to/from std::wstring
std::wstring qtw(const QString &q);
QString qfw(const wstring &wstr);
// Convert to/from local encoding
#define qfl(s) qfw(convertToWc(s))
#define qtl(s) convertToMb(qtw(s))
// Convert to/from utf-8 char*
#define qfu(s) QString::fromUtf8(s)
#define qtu(s) (s).toUtf8().data()
// Convert to/from local encoding
#define qfl(s) QString::fromLocal8Bit(s)
#define qtl(s) (s).toLocal8Bit().data()
// Convert to/from std::wstring
#ifdef QT_NO_STL
# include "encoding.h"
# define qfw(s) QString::fromWCharArray(wstring(s).c_str())
# define qtw(s) convertToWc(qtl(s))
#else
# define qfw(s) QString::fromStdWString(s)
# define qtw(s) (s).toStdWString().data()
#endif
// Translation macro to use gettext
#define _q(s) qfl(_(s))