Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

qt4-gui: Drop deprecated user codec functions

  • Loading branch information...
commit 32d5d2f0f2463d4e690552f065e51cd9d901c6b6 1 parent 7b505e0
@flynd flynd authored
View
185 qt4-gui/src/helpers/usercodec.cpp
@@ -1,6 +1,6 @@
/*
* This file is part of Licq, an instant messaging client for UNIX.
- * Copyright (C) 2001-2011 Licq developers
+ * Copyright (C) 2001-2012 Licq developers <licq-dev@googlegroups.com>
*
* Licq is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,177 +20,70 @@
#include "usercodec.h"
#include <QApplication>
-#include <QTextCodec>
-
-#include <licq/contactlist/user.h>
-#include <licq/contactlist/usermanager.h>
-#include <licq/icq/chat.h>
using namespace LicqQtGui;
/* TRANSLATOR LicqQtGui::UserCodec */
UserCodec::encoding_t UserCodec::m_encodings[] = {
- { QT_TR_NOOP("Unicode"), "UTF-8", 106, ENCODING_DEFAULT, true },
- { QT_TR_NOOP("Unicode-16"), "ISO-10646-UCS-2", 1000 , ENCODING_DEFAULT, true },
+ { QT_TR_NOOP("Unicode"), "UTF-8", true },
+ { QT_TR_NOOP("Unicode-16"), "ISO-10646-UCS-2", true },
- { QT_TR_NOOP("Arabic"), "ISO 8859-6", 82, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Arabic"), "CP 1256", 2256, ENCODING_ARABIC, true },
+ { QT_TR_NOOP("Arabic"), "ISO 8859-6", false },
+ { QT_TR_NOOP("Arabic"), "CP 1256", true },
- { QT_TR_NOOP("Baltic"), "ISO 8859-13", 109, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Baltic"), "CP 1257", 2257, ENCODING_BALTIC, true },
+ { QT_TR_NOOP("Baltic"), "ISO 8859-13", false },
+ { QT_TR_NOOP("Baltic"), "CP 1257", true },
- { QT_TR_NOOP("Central European"), "ISO 8859-2", 5, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Central European"), "CP 1250", 2250, ENCODING_EASTEUROPE, true },
+ { QT_TR_NOOP("Central European"), "ISO 8859-2", false },
+ { QT_TR_NOOP("Central European"), "CP 1250", true },
- { QT_TR_NOOP("Chinese"), "GBK", -2025, ENCODING_GB2312, false },
- { QT_TR_NOOP("Chinese Traditional"), "Big5", 2026, ENCODING_CHINESEBIG5, true },
+ { QT_TR_NOOP("Chinese"), "GBK", false },
+ { QT_TR_NOOP("Chinese Traditional"), "Big5", true },
- { QT_TR_NOOP("Cyrillic"), "ISO 8859-5", 8, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Cyrillic"), "KOI8-R", 2084, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Cyrillic"), "CP 1251", 2251, ENCODING_RUSSIAN, true },
+ { QT_TR_NOOP("Cyrillic"), "ISO 8859-5", false },
+ { QT_TR_NOOP("Cyrillic"), "KOI8-R", false },
+ { QT_TR_NOOP("Cyrillic"), "CP 1251", true },
- { QT_TR_NOOP("Esperanto"), "ISO 8859-3", 6, ENCODING_DEFAULT, false },
+ { QT_TR_NOOP("Esperanto"), "ISO 8859-3", false },
- { QT_TR_NOOP("Greek"), "ISO 8859-7", 10, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Greek"), "CP 1253", 2253, ENCODING_GREEK, true },
+ { QT_TR_NOOP("Greek"), "ISO 8859-7", false },
+ { QT_TR_NOOP("Greek"), "CP 1253", true },
// Visual Hebrew is avoided on purpose -- its not usable for communications
- { QT_TR_NOOP("Hebrew"), "ISO 8859-8-I", 85, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Hebrew"), "CP 1255", 2255, ENCODING_HEBREW, true },
+ { QT_TR_NOOP("Hebrew"), "ISO 8859-8-I", false },
+ { QT_TR_NOOP("Hebrew"), "CP 1255", true },
- { QT_TR_NOOP("Japanese"), "Shift-JIS", 17, ENCODING_SHIFTJIS, true },
- { QT_TR_NOOP("Japanese"), "JIS7", 16, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Japanese"), "eucJP", 18, ENCODING_DEFAULT, false },
+ { QT_TR_NOOP("Japanese"), "Shift-JIS", true },
+ { QT_TR_NOOP("Japanese"), "JIS7", false },
+ { QT_TR_NOOP("Japanese"), "eucJP", false },
- { QT_TR_NOOP("Korean"), "eucKR", 38, ENCODING_DEFAULT, true },
+ { QT_TR_NOOP("Korean"), "eucKR", true },
- { QT_TR_NOOP("Western European"), "ISO 8859-1", 4, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Western European"), "ISO 8859-15", 111, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Western European"), "CP 1252", 2252, ENCODING_ANSI, true },
+ { QT_TR_NOOP("Western European"), "ISO 8859-1", false },
+ { QT_TR_NOOP("Western European"), "ISO 8859-15", false },
+ { QT_TR_NOOP("Western European"), "CP 1252", true },
- { QT_TR_NOOP("Tamil"), "TSCII", 2028, ENCODING_DEFAULT, true },
+ { QT_TR_NOOP("Tamil"), "TSCII", true },
- { QT_TR_NOOP("Thai"), "TIS-620", 2259, ENCODING_THAI, true },
+ { QT_TR_NOOP("Thai"), "TIS-620", true },
- { QT_TR_NOOP("Turkish"), "ISO 8859-9", 12, ENCODING_DEFAULT, false },
- { QT_TR_NOOP("Turkish"), "CP 1254", 2254, ENCODING_TURKISH, true },
+ { QT_TR_NOOP("Turkish"), "ISO 8859-9", false },
+ { QT_TR_NOOP("Turkish"), "CP 1254", true },
- { QT_TR_NOOP("Ukrainian"), "KOI8-U", 2088, ENCODING_DEFAULT, false },
+ { QT_TR_NOOP("Ukrainian"), "KOI8-U", false },
- { 0, 0, 0, 0, false } // end marker
+ { 0, 0, false } // end marker
};
-const QTextCodec* UserCodec::defaultEncoding()
+QString UserCodec::nameForEncoding(int i)
{
- const QTextCodec* codec = QTextCodec::codecForName(Licq::gUserManager.defaultUserEncoding().c_str());
-
- if (codec != NULL)
- return codec;
-
- return QTextCodec::codecForLocale();
+ return qApp->translate("UserCodec", m_encodings[i].script) + " ( " + m_encodings[i].encoding + " )";
}
-const QTextCodec* UserCodec::codecForUser(const Licq::User* u)
+int UserCodec::encodingForName(const QString& name)
{
- const char* preferred_encoding = u->userEncoding().c_str();
-
- if (preferred_encoding && *preferred_encoding)
- {
- const QTextCodec* codec = QTextCodec::codecForName(preferred_encoding);
-
- if (codec != NULL)
- return codec;
- }
-
- return defaultEncoding();
-}
-
-const QTextCodec* UserCodec::codecForUserId(const Licq::UserId& userId)
-{
- const QTextCodec* codec = defaultEncoding();
-
- Licq::UserReadGuard u(userId);
- if (u.isLocked())
- codec = UserCodec::codecForUser(*u);
-
- return codec;
-}
-
-const QTextCodec* UserCodec::codecForCChatUser(CChatUser* u)
-{
- if (u == NULL)
- return defaultEncoding();
-
- QByteArray name = nameForCharset(u->FontEncoding());
-
- if (!name.isNull())
- return QTextCodec::codecForName(name);
-
- // return default encoding
- return codecForUserId(u->userId());
-}
-
-QByteArray UserCodec::encodingForMib(int mib)
-{
- encoding_t* it = m_encodings;
-
- while (it->encoding != NULL)
- {
- if (it->mib == mib)
- return it->encoding;
- it++;
- }
-
- return QByteArray();
-}
-
-QString UserCodec::nameForEncoding(const QByteArray& encoding)
-{
- encoding_t* it = m_encodings;
-
- while (it->encoding != NULL)
- {
- if (it->encoding == encoding)
- return qApp->translate("UserCodec", it->script) + " ( " + it->encoding + " )";
- it++;
- }
-
- return QString::null;
-}
-
-QByteArray UserCodec::encodingForName(const QString& descriptiveName)
-{
- int left = descriptiveName.indexOf(" ( ");
- return descriptiveName.mid(left + 3, descriptiveName.indexOf(" )", left) - left - 3).toAscii();
-}
-
-unsigned char UserCodec::charsetForName(QByteArray name)
-{
- encoding_t* it = m_encodings;
-
- while (it->encoding != NULL)
- {
- if (it->encoding == name)
- return it->charset;
- it++;
- }
-
- return ENCODING_DEFAULT;
-}
-
-QByteArray UserCodec::nameForCharset(unsigned char charset)
-{
- if (charset == ENCODING_DEFAULT)
- return QByteArray();
-
- encoding_t* it = m_encodings;
-
- while (it->encoding != NULL)
- {
- if (it->charset == charset)
- return it->encoding;
- it++;
- }
-
- return QByteArray();
+ for (int i = 0; m_encodings[i].encoding != NULL; ++i)
+ if (m_encodings[i].encoding == name)
+ return i;
+ return 0;
}
View
32 qt4-gui/src/helpers/usercodec.h
@@ -1,6 +1,6 @@
/*
* This file is part of Licq, an instant messaging client for UNIX.
- * Copyright (C) 2001-2010 Licq developers
+ * Copyright (C) 2001-2010,2012 Licq developers <licq-dev@googlegroups.com>
*
* Licq is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,17 +20,7 @@
#ifndef USERCODEC_H
#define USERCODEC_H
-#include <QObject>
-
-class QTextCodec;
-
-class CChatUser;
-
-namespace Licq
-{
-class User;
-class UserId;
-}
+#include <QString>
namespace LicqQtGui
{
@@ -41,26 +31,12 @@ class UserCodec
{
const char* script;
const char* encoding;
- int mib;
- unsigned char charset;
bool isMinimal;
};
static encoding_t m_encodings[];
- // Retrieves the default codec
- static const QTextCodec* defaultEncoding();
- // Retrieves the codec for an LicqUser object
- static const QTextCodec* codecForUser(const Licq::User* u);
- // Retrieves the codec for an CChatUser object
- static const QTextCodec* codecForCChatUser(CChatUser* u);
- // Retrieves the codec for a proto user
- static const QTextCodec* codecForUserId(const Licq::UserId& userId);
-
- static QByteArray encodingForMib(int mib);
- static QString nameForEncoding(const QByteArray& encoding);
- static QByteArray encodingForName(const QString& descriptiveName);
- static unsigned char charsetForName(QByteArray name);
- static QByteArray nameForCharset(unsigned char charset);
+ static QString nameForEncoding(int index);
+ static int encodingForName(const QString& descriptiveName);
};
} // namespace LicqQtGui
View
30 qt4-gui/src/settings/chat.cpp
@@ -1,6 +1,6 @@
/*
* This file is part of Licq, an instant messaging client for UNIX.
- * Copyright (C) 2007-2011 Licq developers
+ * Copyright (C) 2007-2012 Licq developers <licq-dev@googlegroups.com>
*
* Licq is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -175,14 +175,8 @@ QWidget* Settings::Chat::createPageChat(QWidget* parent)
myDefaultEncodingCombo = new QComboBox();
myDefaultEncodingCombo->addItem(tr("System default (%1)").arg(
QString(QTextCodec::codecForLocale()->name())));
- {
- UserCodec::encoding_t* it = &UserCodec::m_encodings[0];
- while (it->encoding != NULL)
- {
- myDefaultEncodingCombo->addItem(UserCodec::nameForEncoding(it->encoding));
- ++it;
- }
- }
+ for (int i = 0; UserCodec::m_encodings[i].encoding != NULL; ++i)
+ myDefaultEncodingCombo->addItem(UserCodec::nameForEncoding(i));
myDefaultEncodingCombo->setToolTip(myDefaultEncodingLabel->toolTip());
myDefaultEncodingLabel->setBuddy(myDefaultEncodingCombo);
defaultEncodingLayout->addWidget(myDefaultEncodingCombo);
@@ -577,20 +571,11 @@ void Settings::Chat::load()
mySendTNCheck->setChecked(Licq::gDaemon.sendTypingNotification());
- QByteArray defaultEncoding = Licq::gUserManager.defaultUserEncoding().c_str();
+ QString defaultEncoding = Licq::gUserManager.defaultUserEncoding().c_str();
if (defaultEncoding.isEmpty())
myDefaultEncodingCombo->setCurrentIndex(0);
else
- {
- for (int i = 1; i < myDefaultEncodingCombo->count(); i++)
- {
- if (UserCodec::encodingForName(myDefaultEncodingCombo->itemText(i)) == defaultEncoding)
- {
- myDefaultEncodingCombo->setCurrentIndex(i);
- break;
- }
- }
- }
+ myDefaultEncodingCombo->setCurrentIndex(1 + UserCodec::encodingForName(defaultEncoding));
myShowAllEncodingsCheck->setChecked(chatConfig->showAllEncodings());
myTerminalEdit->setText(Licq::gDaemon.terminal().empty() ?
@@ -649,8 +634,9 @@ void Settings::Chat::apply()
Licq::gDaemon.setTerminal(myTerminalEdit->text().toLocal8Bit().constData());
- if (myDefaultEncodingCombo->currentIndex() > 0)
- Licq::gUserManager.setDefaultUserEncoding(UserCodec::encodingForName(myDefaultEncodingCombo->currentText()).data());
+ int encIndex = myDefaultEncodingCombo->currentIndex();
+ if (encIndex > 0)
+ Licq::gUserManager.setDefaultUserEncoding(UserCodec::m_encodings[encIndex-1].encoding);
else
Licq::gUserManager.setDefaultUserEncoding("");
chatConfig->setShowAllEncodings(myShowAllEncodingsCheck->isChecked());
View
11 qt4-gui/src/userevents/usereventcommon.cpp
@@ -166,16 +166,17 @@ UserEventCommon::UserEventCommon(const Licq::UserId& userId, QWidget* parent, co
connect(myEncodingsGroup, SIGNAL(triggered(QAction*)), SLOT(setEncoding(QAction*)));
// populate the popup menu
- for (UserCodec::encoding_t* it = &UserCodec::m_encodings[0]; it->encoding != NULL; ++it)
+ for (int i = 0; UserCodec::m_encodings[i].encoding != NULL; ++i)
{
+ UserCodec::encoding_t* it = &UserCodec::m_encodings[i];
bool currentCodec = it->encoding == userEncoding;
if (!currentCodec && !Config::Chat::instance()->showAllEncodings() && !it->isMinimal)
continue;
- QAction* a = new QAction(UserCodec::nameForEncoding(it->encoding), myEncodingsGroup);
+ QAction* a = new QAction(UserCodec::nameForEncoding(i), myEncodingsGroup);
a->setCheckable(true);
- a->setData(it->mib);
+ a->setData(i);
if (currentCodec)
a->setChecked(true);
@@ -354,10 +355,10 @@ void UserEventCommon::connectSignal()
void UserEventCommon::setEncoding(QAction* action)
{
- int encodingMib = action->data().toUInt();
+ int index = action->data().toUInt();
/* initialize a codec according to the encoding menu item id */
- QString encoding(UserCodec::encodingForMib(encodingMib));
+ QString encoding = UserCodec::nameForEncoding(index);
if (!encoding.isNull())
{
Please sign in to comment.
Something went wrong with that request. Please try again.