Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Verified Commit d96291ec authored by Linus Jahn's avatar Linus Jahn

Clean up: use more globals, use QT_VERSION_CHECK & more

parent 3a7b0bb0
......@@ -51,7 +51,7 @@
ClientWorker::ClientWorker(Caches *caches, Kaidan *kaidan, bool enableLogging, QGuiApplication *app,
QObject* parent)
: QObject(parent), caches(caches), kaidan(kaidan), enableLogging(enableLogging), app(app)
: QObject(parent), caches(caches), kaidan(kaidan), enableLogging(enableLogging), app(app)
{
client = new QXmppClient(this);
logger = new LogHandler(client, this);
......@@ -135,8 +135,8 @@ void ClientWorker::onConnect()
// accept credentials and save them
creds.isFirstTry = false;
caches->settings->setValue("auth/jid", creds.jid);
caches->settings->setValue("auth/password",
caches->settings->setValue(KAIDAN_SETTINGS_AUTH_JID, creds.jid);
caches->settings->setValue(KAIDAN_SETTINGS_AUTH_PASSWD,
QString::fromUtf8(creds.password.toUtf8().toBase64()));
// after first log in we always want to automatically reconnect
......@@ -188,16 +188,10 @@ void ClientWorker::onConnectionError(QXmppClient::Error error)
QString ClientWorker::generateRandomString(unsigned int length) const
{
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
"nopqrstuvwxyz0123456789");
const int numOfChars = possibleCharacters.length();
QString randomString;
for (unsigned int i = 0; i < length; ++i) {
int index = qrand() % numOfChars;
QChar nextChar = possibleCharacters.at(index);
randomString.append(nextChar);
}
for (int i = 0; i < length; ++i)
randomString.append(KAIDAN_RESOURCE_RANDOM_CHARS.at(
qrand() % KAIDAN_RESOURCE_RANDOM_CHARS.length()));
return randomString;
}
......
......@@ -38,49 +38,49 @@ QVariantMap EmojiModel::getModel() {
QVariantList EmojiModel::filterModel(const QString& filter) {
QVariantList result;
for (QVariant e : people) {
for (const QVariant &e : people) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : nature) {
for (const QVariant &e : nature) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : food) {
for (const QVariant &e : food) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : activity) {
for (const QVariant &e : activity) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : travel) {
for (const QVariant &e : travel) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : objects) {
for (const QVariant &e : objects) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : symbols) {
for (const QVariant &e : symbols) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
}
}
for (QVariant e : flags) {
for (const QVariant &e : flags) {
Emoji emoji = qvariant_cast<Emoji>(e);
if (emoji.shortname.startsWith(filter)) {
result.append(e);
......
......@@ -49,8 +49,12 @@
#define KAIDAN_SETTINGS_AUTH_RESOURCE "auth/resource"
#define KAIDAN_SETTINGS_AUTH_PASSWD "auth/password"
const QString KAIDAN_RESOURCE_RANDOM_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"
"qrstuvwxyz0123456789";
// XML namespaces
#define NS_SPOILERS "urn:xmpp:spoiler:0"
#define NS_CARBONS "urn:xmpp:carbons:2"
/**
* Map of JIDs to contact names
......
......@@ -31,16 +31,9 @@
#include "Kaidan.h"
// Qt
#include <QClipboard>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QGuiApplication>
#include <QMimeDatabase>
#include <QMimeType>
#include <QSettings>
#include <QStandardPaths>
#include <QUrl>
// QXmpp
#include <QXmppClient.h>
#include "qxmpp-exts/QXmppColorGenerator.h"
......@@ -132,7 +125,7 @@ void Kaidan::mainDisconnect(bool openLogInPage)
if (openLogInPage) {
// clear password
caches->settings->remove("auth/password");
caches->settings->remove(KAIDAN_SETTINGS_AUTH_PASSWD);
setPassword(QString());
// trigger log in page
emit newCredentialsNeeded();
......@@ -174,7 +167,7 @@ void Kaidan::setJidResource(const QString &jidResource)
// to set the first try flag and can save it.
creds.jidResource = jidResource;
caches->settings->setValue("auth/resource", jidResource);
caches->settings->setValue(KAIDAN_SETTINGS_AUTH_RESOURCE, jidResource);
}
void Kaidan::setPassword(const QString &password)
......@@ -197,7 +190,7 @@ void Kaidan::setChatPartner(const QString &chatPartner)
quint8 Kaidan::getDisconnReason() const
{
return (quint8) disconnReason;
return static_cast<quint8>(disconnReason);
}
void Kaidan::addOpenUri(const QByteArray &uri)
......
......@@ -39,7 +39,7 @@
#include <QXmppUtils.h>
#include <QXmppRosterManager.h>
#include <QXmppDiscoveryManager.h>
#if QXMPP_VERSION >= 0x000904
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
#include <QXmppCarbonManager.h>
#endif
// Kaidan
......@@ -61,7 +61,7 @@ MessageHandler::MessageHandler(Kaidan *kaidan, QXmppClient *client, MessageModel
emit model->setMessageAsDeliveredRequested(id);
});
#if QXMPP_VERSION >= 0x000904 // QXmppCarbonManager was added in v0.9.4
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
carbonManager = new QXmppCarbonManager();
client->addExtension(carbonManager);
......@@ -84,7 +84,7 @@ MessageHandler::MessageHandler(Kaidan *kaidan, QXmppClient *client, MessageModel
MessageHandler::~MessageHandler()
{
#if QXMPP_VERSION >= 0x000904
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
delete carbonManager;
#endif
}
......@@ -266,11 +266,11 @@ void MessageHandler::correctMessage(QString toJid, QString msgId, QString body)
void MessageHandler::handleDiscoInfo(const QXmppDiscoveryIq &info)
{
#if QXMPP_VERSION >= 0x000904
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
if (info.from() != client->configuration().domain())
return;
// enable carbons, if feature found
if (info.features().contains(QString("urn:xmpp:carbons:2")))
if (info.features().contains(NS_CARBONS))
carbonManager->setCarbonsEnabled(true);
#endif
}
......@@ -44,7 +44,7 @@ class Kaidan;
class MessageModel;
class QMimeType;
class QXmppDiscoveryIq;
#if QXMPP_VERSION >= 0x000904
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
class QXmppCarbonManager;
#endif
......@@ -89,7 +89,7 @@ private:
QXmppClient *client;
QXmppMessageReceiptManager receiptManager;
MessageModel *model;
#if QXMPP_VERSION >= 0x000904
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
QXmppCarbonManager *carbonManager;
#endif
QString chatPartner;
......
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