Verified Commit edd75216 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Refactor Kaidan.{cpp,h}

The changes in other files than Kaidan.cpp and Kaidan.h are just fallout from renaming some functions in the api of the Kaidan class.
parent 78b18d3e
Pipeline #25264 passed with stages
in 34 minutes and 51 seconds
......@@ -1501,7 +1501,7 @@ QHash<int, QByteArray> EmojiModel::roleNames() const
EmojiProxyModel::EmojiProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
QSettings *settings = Kaidan::instance()->getSettings();
QSettings *settings = Kaidan::instance()->settings();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QStringList list = settings->value(QLatin1String(FAVORITES_EMOJIS_SETTINGS_PATH)).toStringList();
m_favoriteEmojis = QSet<QString>(list.begin(), list.end());
......@@ -1557,7 +1557,7 @@ void EmojiProxyModel::addFavoriteEmoji(int proxyRow)
invalidateFilter();
}
QSettings *settings = Kaidan::instance()->getSettings();
QSettings *settings = Kaidan::instance()->settings();
settings->setValue(QLatin1String(FAVORITES_EMOJIS_SETTINGS_PATH), QStringList(m_favoriteEmojis.values()));
}
}
......
......@@ -93,16 +93,16 @@ Kaidan::Kaidan(QGuiApplication *app, bool enableLogging, QObject *parent)
m_caches->settings->value(KAIDAN_SETTINGS_AUTH_PASSWD).toString().toUtf8()
));
// Use a default prefix for the JID's resource part if no prefix is already set.
if (creds.jidResourcePrefix.isEmpty())
if (m_creds.jidResourcePrefix.isEmpty())
setJidResourcePrefix(KAIDAN_JID_RESOURCE_DEFAULT_PREFIX);
creds.isFirstTry = false;
m_creds.isFirstTry = false;
//
// Start ClientWorker on new thread
//
m_client = new ClientWorker(m_caches, this, enableLogging);
m_client->setCredentials(creds);
m_client->setCredentials(m_creds);
m_client->moveToThread(m_cltThrd);
connect(m_client, &ClientWorker::connectionErrorChanged, this, &Kaidan::setConnectionError);
......@@ -124,7 +124,7 @@ Kaidan::~Kaidan()
void Kaidan::start()
{
if (creds.jid.isEmpty() || creds.password.isEmpty())
if (m_creds.jid.isEmpty() || m_creds.password.isEmpty())
emit newCredentialsNeeded();
else
mainConnect();
......@@ -132,20 +132,20 @@ void Kaidan::start()
void Kaidan::mainConnect()
{
emit m_client->credentialsUpdated(creds);
emit m_client->credentialsUpdated(m_creds);
emit m_client->connectRequested();
}
void Kaidan::requestRegistrationForm()
{
emit m_client->credentialsUpdated(creds);
emit m_client->credentialsUpdated(m_creds);
emit m_client->registrationFormRequested();
}
void Kaidan::mainDisconnect()
{
// disconnect the client if connected or connecting
if (connectionState != ConnectionState::StateDisconnected)
if (m_connectionState != ConnectionState::StateDisconnected)
emit m_client->disconnectRequested();
}
......@@ -159,17 +159,17 @@ void Kaidan::handleApplicationStateChanged(Qt::ApplicationState applicationState
void Kaidan::setConnectionState(QXmppClient::State state)
{
if (this->connectionState != static_cast<ConnectionState>(state)) {
this->connectionState = static_cast<ConnectionState>(state);
if (m_connectionState != static_cast<ConnectionState>(state)) {
m_connectionState = static_cast<ConnectionState>(state);
emit connectionStateChanged();
// Open the possibly cached URI when connected.
// This is needed because the XMPP URIs can't be opened when Kaidan is not connected.
if (connectionState == ConnectionState::StateConnected && !openUriCache.isEmpty()) {
if (m_connectionState == ConnectionState::StateConnected && !m_openUriCache.isEmpty()) {
// delay is needed because sometimes the RosterPage needs to be loaded first
QTimer::singleShot(300, [=] () {
emit xmppUriReceived(openUriCache);
openUriCache = "";
emit xmppUriReceived(m_openUriCache);
m_openUriCache = "";
});
}
}
......@@ -177,7 +177,7 @@ void Kaidan::setConnectionState(QXmppClient::State state)
void Kaidan::setConnectionError(ClientWorker::ConnectionError error)
{
connectionError = error;
m_connectionError = error;
emit connectionErrorChanged(error);
}
......@@ -207,9 +207,9 @@ void Kaidan::setNotificationsMuted(const QString &jid, bool muted)
void Kaidan::setJid(const QString &jid)
{
creds.jid = jid;
m_creds.jid = jid;
// credentials were modified -> first try
creds.isFirstTry = true;
m_creds.isFirstTry = true;
emit jidChanged();
}
......@@ -217,7 +217,7 @@ void Kaidan::setJidResourcePrefix(const QString &jidResourcePrefix)
{
// JID resource won't influence the authentication, so we don't need
// to set the first try flag and can save it.
creds.jidResourcePrefix = jidResourcePrefix;
m_creds.jidResourcePrefix = jidResourcePrefix;
m_caches->settings->setValue(KAIDAN_SETTINGS_AUTH_JID_RESOURCE_PREFIX, jidResourcePrefix);
emit jidResourcePrefixChanged();
......@@ -225,15 +225,15 @@ void Kaidan::setJidResourcePrefix(const QString &jidResourcePrefix)
void Kaidan::setPassword(const QString &password)
{
creds.password = password;
m_creds.password = password;
// credentials were modified -> first try
creds.isFirstTry = true;
m_creds.isFirstTry = true;
emit passwordChanged();
}
quint8 Kaidan::getConnectionError() const
ClientWorker::ConnectionError Kaidan::connectionError() const
{
return static_cast<quint8>(connectionError);
return m_connectionError;
}
void Kaidan::addOpenUri(const QString &uri)
......@@ -241,12 +241,12 @@ void Kaidan::addOpenUri(const QString &uri)
if (!QXmppUri::isXmppUri(uri))
return;
if (connectionState == ConnectionState::StateConnected) {
if (m_connectionState == ConnectionState::StateConnected) {
emit xmppUriReceived(uri);
} else {
//: The link is an XMPP-URI (i.e. 'xmpp:kaidan@muc.kaidan.im?join' for joining a chat)
emit passiveNotificationRequested(tr("The link will be opened after you have connected."));
openUriCache = uri;
m_openUriCache = uri;
}
}
......@@ -279,7 +279,7 @@ void Kaidan::notifyForInvalidLoginUri()
emit passiveNotificationRequested(tr("No valid login QR code found."));
}
ClientWorker *Kaidan::getClient() const
ClientWorker *Kaidan::client() const
{
return m_client;
}
......
......@@ -58,18 +58,18 @@ class Kaidan : public QObject
{
Q_OBJECT
Q_PROPERTY(RosterModel* rosterModel READ getRosterModel CONSTANT)
Q_PROPERTY(MessageModel* messageModel READ getMessageModel CONSTANT)
Q_PROPERTY(AvatarFileStorage* avatarStorage READ getAvatarStorage NOTIFY avatarStorageChanged)
Q_PROPERTY(PresenceCache* presenceCache READ getPresenceCache CONSTANT)
Q_PROPERTY(TransferCache* transferCache READ getTransferCache CONSTANT)
Q_PROPERTY(RosterModel* rosterModel READ rosterModel CONSTANT)
Q_PROPERTY(MessageModel* messageModel READ messageModel CONSTANT)
Q_PROPERTY(AvatarFileStorage* avatarStorage READ avatarStorage NOTIFY avatarStorageChanged)
Q_PROPERTY(PresenceCache* presenceCache READ presenceCache CONSTANT)
Q_PROPERTY(TransferCache* transferCache READ transferCache CONSTANT)
Q_PROPERTY(ServerFeaturesCache* serverFeaturesCache READ serverFeaturesCache CONSTANT)
Q_PROPERTY(QSettings* settings READ getSettings CONSTANT)
Q_PROPERTY(quint8 connectionState READ getConnectionState NOTIFY connectionStateChanged)
Q_PROPERTY(quint8 connectionError READ getConnectionError NOTIFY connectionErrorChanged)
Q_PROPERTY(QString jid READ getJid WRITE setJid NOTIFY jidChanged)
Q_PROPERTY(QString jidResourcePrefix READ getJidResourcePrefix WRITE setJidResourcePrefix NOTIFY jidResourcePrefixChanged)
Q_PROPERTY(QString password READ getPassword WRITE setPassword NOTIFY passwordChanged)
Q_PROPERTY(QSettings* settings READ settings CONSTANT)
Q_PROPERTY(Enums::ConnectionState connectionState READ connectionState NOTIFY connectionStateChanged)
Q_PROPERTY(ClientWorker::ConnectionError connectionError READ connectionError NOTIFY connectionErrorChanged)
Q_PROPERTY(QString jid READ jid WRITE setJid NOTIFY jidChanged)
Q_PROPERTY(QString jidResourcePrefix READ jidResourcePrefix WRITE setJidResourcePrefix NOTIFY jidResourcePrefixChanged)
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
public:
static Kaidan *instance();
......@@ -105,15 +105,15 @@ public:
/**
* Returns the current ConnectionState
*/
Q_INVOKABLE quint8 getConnectionState() const
Enums::ConnectionState connectionState() const
{
return (quint8) connectionState;
return m_connectionState;
}
/**
* Returns the last connection error.
*/
Q_INVOKABLE quint8 getConnectionError() const;
ClientWorker::ConnectionError connectionError() const;
/**
* Set own JID used for connection
......@@ -126,9 +126,9 @@ public:
/**
* Get the current JID
*/
QString getJid() const
QString jid() const
{
return creds.jid;
return m_creds.jid;
}
/**
......@@ -141,9 +141,9 @@ public:
/**
* Provides the prefix of the JID's resource part.
*/
QString getJidResourcePrefix() const
QString jidResourcePrefix() const
{
return creds.jidResourcePrefix;
return m_creds.jidResourcePrefix;
}
/**
......@@ -154,32 +154,32 @@ public:
/**
* Get the currently used password
*/
QString getPassword() const
QString password() const
{
return creds.password;
return m_creds.password;
}
RosterModel* getRosterModel() const
RosterModel* rosterModel() const
{
return m_caches->rosterModel;
}
MessageModel* getMessageModel() const
MessageModel* messageModel() const
{
return m_caches->msgModel;
}
AvatarFileStorage* getAvatarStorage() const
AvatarFileStorage* avatarStorage() const
{
return m_caches->avatarStorage;
}
PresenceCache* getPresenceCache() const
PresenceCache* presenceCache() const
{
return m_caches->presCache;
}
TransferCache* getTransferCache() const
TransferCache* transferCache() const
{
return m_caches->transferCache;
}
......@@ -189,12 +189,12 @@ public:
return m_caches->serverFeaturesCache;
}
QSettings* getSettings() const
QSettings* settings() const
{
return m_caches->settings;
}
ClientWorker *getClient() const;
ClientWorker *client() const;
RosterDb *rosterDb() const;
......@@ -466,10 +466,10 @@ private:
ClientWorker::Caches *m_caches;
ClientWorker *m_client;
ClientWorker::Credentials creds;
QString openUriCache;
ConnectionState connectionState = ConnectionState::StateDisconnected;
ClientWorker::ConnectionError connectionError = ClientWorker::NoError;
ClientWorker::Credentials m_creds;
QString m_openUriCache;
ConnectionState m_connectionState = ConnectionState::StateDisconnected;
ClientWorker::ConnectionError m_connectionError = ClientWorker::NoError;
static Kaidan *s_instance;
};
......
......@@ -773,7 +773,7 @@ void MediaRecorder::saveUserSettings()
Q_UNREACHABLE();
break;
case MediaRecorder::Type::Image: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
settings.setValue(SETTING_DEFAULT_CAMERA_DEVICE_NAME, m_mediaSettings.camera.deviceName());
......@@ -788,7 +788,7 @@ void MediaRecorder::saveUserSettings()
break;
}
case MediaRecorder::Type::Audio: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
settings.setValue(SETTING_DEFAULT_AUDIO_INPUT_DEVICE_NAME, m_mediaSettings.audioInputDevice.deviceName());
......@@ -801,7 +801,7 @@ void MediaRecorder::saveUserSettings()
break;
}
case MediaRecorder::Type::Video: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
settings.setValue(SETTING_DEFAULT_CAMERA_DEVICE_NAME, m_mediaSettings.camera.deviceName());
......@@ -930,7 +930,7 @@ CameraInfo MediaRecorder::userDefaultCamera() const
return CameraInfo();
}
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
CameraInfo cameraInfo = m_cameraModel->defaultCamera();
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
......@@ -954,7 +954,7 @@ AudioDeviceInfo MediaRecorder::userDefaultAudioInput() const
return AudioDeviceInfo();
}
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
AudioDeviceInfo audioInput = m_audioDeviceModel->defaultAudioInputDevice();
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
......@@ -986,7 +986,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
m_videoEncoderSettings = VideoEncoderSettings();
break;
case MediaRecorder::Type::Image: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
MediaSettings mediaSettings(camera, AudioDeviceInfo());
ImageEncoderSettings imageSettings;
......@@ -1000,7 +1000,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
break;
}
case MediaRecorder::Type::Audio: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
MediaSettings mediaSettings(CameraInfo(), audioInput);
AudioEncoderSettings audioSettings;
......@@ -1014,7 +1014,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
break;
}
case MediaRecorder::Type::Video: {
QSettings &settings(*Kaidan::instance()->getSettings());
QSettings &settings(*Kaidan::instance()->settings());
MediaSettings mediaSettings(camera, AudioDeviceInfo());
AudioEncoderSettings audioSettings;
VideoEncoderSettings videoSettings;
......
......@@ -196,7 +196,7 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
: message.spoilerHint()
: msg.body();
emit kaidan->getRosterModel()->setLastMessageRequested(contactJid, lastMessage);
emit kaidan->rosterModel()->setLastMessageRequested(contactJid, lastMessage);
}
void MessageHandler::sendMessage(const QString& toJid,
......
......@@ -178,7 +178,7 @@ QVariant MessageModel::data(const QModelIndex &index, int role) const
void MessageModel::fetchMore(const QModelIndex &)
{
emit msgDb->fetchMessagesRequested(kaidan->getJid(), m_currentChatJid, m_messages.size());
emit msgDb->fetchMessagesRequested(kaidan->jid(), m_currentChatJid, m_messages.size());
}
bool MessageModel::canFetchMore(const QModelIndex &) const
......@@ -207,7 +207,7 @@ bool MessageModel::canCorrectMessage(const QString &msgId) const
{
// Only allow correction of the latest message sent by us
for (const auto &msg : m_messages) {
if (msg.from() == kaidan->getJid())
if (msg.from() == kaidan->jid())
return msg.id() == msgId;
}
return false;
......@@ -220,7 +220,7 @@ void MessageModel::handleMessagesFetched(const QVector<Message> &msgs)
beginInsertRows(QModelIndex(), rowCount(), rowCount() + msgs.length() - 1);
for (auto msg : msgs) {
msg.setSentByMe(kaidan->getJid() == msg.from());
msg.setSentByMe(kaidan->jid() == msg.from());
processMessage(msg);
m_messages << msg;
}
......@@ -350,5 +350,5 @@ void MessageModel::processMessage(Message &msg)
void MessageModel::sendPendingMessages()
{
emit msgDb->fetchPendingMessagesRequested(kaidan->getJid());
emit msgDb->fetchPendingMessagesRequested(kaidan->jid());
}
......@@ -57,7 +57,7 @@ void Notifications::sendMessageNotification(const QString &senderJid, const QStr
emit Kaidan::instance()->raiseWindowRequested();
});
QObject::connect(notification, &KNotification::action1Activated, [=] {
emit Kaidan::instance()->getRosterModel()->updateItemRequested(senderJid, [=](RosterItem &item) {
emit Kaidan::instance()->rosterModel()->updateItemRequested(senderJid, [=](RosterItem &item) {
item.setUnreadMessages(0);
});
});
......
......@@ -49,9 +49,9 @@ QImage QrCodeGenerator::generateLoginUriQrCode(int edgePixelCount)
{
QXmppUri uri;
uri.setJid(Kaidan::instance()->getJid());
uri.setJid(Kaidan::instance()->jid());
uri.setAction(QXmppUri::Login);
uri.setPassword(Kaidan::instance()->getPassword());
uri.setPassword(Kaidan::instance()->password());
return generateQrCode(uri.toString(), edgePixelCount);
}
......
......@@ -91,7 +91,7 @@ RosterManager::RosterManager(Kaidan *kaidan,
}
});
connect(kaidan->getMessageModel(), &MessageModel::currentChatJidChanged, this, &RosterManager::setCurrentChatJid);
connect(kaidan->messageModel(), &MessageModel::currentChatJidChanged, this, &RosterManager::setCurrentChatJid);
// user actions
connect(kaidan, &Kaidan::addContact, this, &RosterManager::addContact);
......
......@@ -78,7 +78,7 @@ RosterModel::RosterModel(RosterDb *rosterDb, QObject *parent)
m_items.clear();
endResetModel();
emit rosterDb->fetchItemsRequested(Kaidan::instance()->getJid());
emit rosterDb->fetchItemsRequested(Kaidan::instance()->jid());
});
}
......
......@@ -99,10 +99,10 @@ void UploadManager::sendFile(const QString &jid, const QUrl &fileUrl, const QStr
msg->setMediaLocation(file.filePath());
// cache message and upload
emit Kaidan::instance()->getTransferCache()->addJobRequested(msgId, upload->bytesTotal());
emit Kaidan::instance()->transferCache()->addJobRequested(msgId, upload->bytesTotal());
messages.insert(upload->id(), msg);
emit Kaidan::instance()->getMessageModel()->addMessageRequested(*msg);
emit Kaidan::instance()->messageModel()->addMessageRequested(*msg);
// update last message
QString lastMessage = tr("File");
......@@ -112,7 +112,7 @@ void UploadManager::sendFile(const QString &jid, const QUrl &fileUrl, const QStr
rosterManager->handleSendMessage(jid, lastMessage);
connect(upload, &QXmppHttpUpload::bytesSentChanged, this, [=] () {
emit Kaidan::instance()->getTransferCache()->setJobBytesSentRequested(
emit Kaidan::instance()->transferCache()->setJobBytesSentRequested(
msgId, upload->bytesSent());
});
}
......@@ -128,7 +128,7 @@ void UploadManager::handleUploadSucceeded(const QXmppHttpUpload *upload)
? oobUrl
: originalMsg->body() + "\n" + oobUrl;
emit Kaidan::instance()->getMessageModel()->updateMessageRequested(originalMsg->id(), [=] (Message &msg) {
emit Kaidan::instance()->messageModel()->updateMessageRequested(originalMsg->id(), [=] (Message &msg) {
msg.setOutOfBandUrl(oobUrl);
msg.setBody(body);
});
......@@ -142,15 +142,15 @@ void UploadManager::handleUploadSucceeded(const QXmppHttpUpload *upload)
bool success = client->sendPacket(m);
if (success) {
emit Kaidan::instance()->getMessageModel()->setMessageDeliveryStateRequested(
emit Kaidan::instance()->messageModel()->setMessageDeliveryStateRequested(
originalMsg->id(), Enums::DeliveryState::Sent);
} else {
emit Kaidan::instance()->passiveNotificationRequested(tr("Message could not be sent."));
emit Kaidan::instance()->getMessageModel()->setMessageDeliveryStateRequested(originalMsg->id(), Enums::DeliveryState::Error, "Message could not be sent.");
emit Kaidan::instance()->messageModel()->setMessageDeliveryStateRequested(originalMsg->id(), Enums::DeliveryState::Error, "Message could not be sent.");
}
messages.remove(upload->id());
emit Kaidan::instance()->getTransferCache()->removeJobRequested(originalMsg->id());
emit Kaidan::instance()->transferCache()->removeJobRequested(originalMsg->id());
}
void UploadManager::handleUploadFailed(const QXmppHttpUpload *upload)
......@@ -158,5 +158,5 @@ void UploadManager::handleUploadFailed(const QXmppHttpUpload *upload)
qDebug() << "[client] [UploadManager] A file upload has failed.";
const QString &msgId = messages.value(upload->id())->id();
messages.remove(upload->id());
emit Kaidan::instance()->getTransferCache()->removeJobRequested(msgId);
emit Kaidan::instance()->transferCache()->removeJobRequested(msgId);
}
......@@ -37,7 +37,7 @@ VCardModel::VCardModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(
Kaidan::instance()->getClient()->getVCardManager(),
Kaidan::instance()->client()->getVCardManager(),
&VCardManager::vCardReceived,
this,
&VCardModel::handleVCardReceived
......
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