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

Add ServerFeaturesCache to temp. store server information

We will need to add more properties for supported features of the server
in the future. This thread-safe class can be used to not mess up the
Kaidan main class with it.

Currently it only stores whether HTTP File Upload is supported by the
server.
parent 0be73063
Pipeline #16947 passed with stages
in 101 minutes and 18 seconds
......@@ -26,6 +26,7 @@ set(KAIDAN_SOURCES
src/EmojiModel.cpp
src/TransferCache.cpp
src/DownloadManager.cpp
src/ServerFeaturesCache.cpp
src/QmlUtils.cpp
src/Utils.cpp
src/QrCodeDecoder.cpp
......
......@@ -46,6 +46,7 @@ class QGuiApplication;
#include "MessageModel.h"
#include "PresenceCache.h"
#include "RosterModel.h"
#include "ServerFeaturesCache.h"
#include "TransferCache.h"
class LogHandler;
class Kaidan;
......@@ -87,9 +88,10 @@ public:
struct Caches {
Caches(Kaidan *kaidan, RosterDb *rosterDb, MessageDb *msgDb,
QObject *parent = nullptr)
: msgModel(new MessageModel(kaidan, msgDb, parent)),
rosterModel(new RosterModel(rosterDb, parent)),
: msgModel(new MessageModel(kaidan, msgDb, parent)),
rosterModel(new RosterModel(rosterDb, parent)),
avatarStorage(new AvatarFileStorage(parent)),
serverFeaturesCache(new ServerFeaturesCache(parent)),
presCache(new PresenceCache(parent)),
transferCache(new TransferCache(parent)),
settings(new QSettings(APPLICATION_NAME, APPLICATION_NAME))
......@@ -110,6 +112,7 @@ public:
MessageModel *msgModel;
RosterModel *rosterModel;
AvatarFileStorage *avatarStorage;
ServerFeaturesCache *serverFeaturesCache;
PresenceCache *presCache;
TransferCache* transferCache;
QSettings *settings;
......
......@@ -62,13 +62,13 @@ class Kaidan : public QObject
Q_PROPERTY(AvatarFileStorage* avatarStorage READ getAvatarStorage NOTIFY avatarStorageChanged)
Q_PROPERTY(PresenceCache* presenceCache READ getPresenceCache CONSTANT)
Q_PROPERTY(TransferCache* transferCache READ getTransferCache 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 jidResource READ getJidResource WRITE setJidResource NOTIFY jidResourceChanged)
Q_PROPERTY(QString password READ getPassword WRITE setPassword NOTIFY passwordChanged)
Q_PROPERTY(bool uploadServiceFound READ getUploadServiceFound NOTIFY uploadServiceFoundChanged)
public:
static Kaidan *instance();
......@@ -175,6 +175,11 @@ public:
return m_caches->transferCache;
}
ServerFeaturesCache *serverFeaturesCache() const
{
return m_caches->serverFeaturesCache;
}
QSettings* getSettings() const
{
return m_caches->settings;
......@@ -198,14 +203,6 @@ public:
*/
Q_INVOKABLE void loginByUri(const QString &uri);
/**
* Returns whether an HTTP File Upload service has been found
*/
bool getUploadServiceFound() const
{
return uploadServiceFound;
}
signals:
void avatarStorageChanged();
......@@ -284,11 +281,6 @@ signals:
*/
void uploadProgressMade(QString msgId, quint64 sent, quint64 total);
/**
* An HTTP File Upload service was discovered
*/
void uploadServiceFoundChanged();
/**
* Send a text message to any JID
*
......@@ -396,15 +388,6 @@ public slots:
addOpenUri(msg);
}
/**
* Enables HTTP File Upload to be used (will be called from UploadManager)
*/
void setUploadServiceFound(bool enabled)
{
uploadServiceFound = enabled;
emit uploadServiceFoundChanged();
}
/**
* Returns whether notifications are enabled for the given contact.
*/
......@@ -436,7 +419,6 @@ private:
ClientWorker::Credentials creds;
QString openUriCache;
bool uploadServiceFound = false;
ConnectionState connectionState = ConnectionState::StateDisconnected;
ClientWorker::ConnectionError connectionError = ClientWorker::NoError;
......
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2020 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan 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 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ServerFeaturesCache.h"
// Qt
#include <QMutexLocker>
ServerFeaturesCache::ServerFeaturesCache(QObject *parent)
: QObject(parent)
{
}
bool ServerFeaturesCache::httpUploadSupported()
{
QMutexLocker locker(&m_mutex);
return m_httpUploadSupported;
}
void ServerFeaturesCache::setHttpUploadSupported(bool supported)
{
QMutexLocker locker(&m_mutex);
if (m_httpUploadSupported != supported) {
m_httpUploadSupported = supported;
locker.unlock();
emit httpUploadSupportedChanged();
}
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2020 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan 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 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SERVERFEATURESCACHE_H
#define SERVERFEATURESCACHE_H
#include <QObject>
#include <QMutex>
/**
* @brief The ServerFeaturesCache class temporarily stores the features of a server. This
* can be used to for example enable or disable certain features in the UI.
*
* All methods in the class are thread-safe.
*/
class ServerFeaturesCache : public QObject
{
Q_OBJECT
Q_PROPERTY(bool httpUploadSupported READ httpUploadSupported NOTIFY httpUploadSupportedChanged)
public:
explicit ServerFeaturesCache(QObject *parent = nullptr);
/**
* Returns whether HTTP File Upload is available and can be currently be used.
*/
bool httpUploadSupported();
void setHttpUploadSupported(bool supported);
signals:
void httpUploadSupportedChanged();
private:
QMutex m_mutex;
bool m_httpUploadSupported = false;
};
#endif // SERVERFEATURESCACHE_H
......@@ -55,10 +55,8 @@ UploadManager::UploadManager(QXmppClient *client, RosterManager* rosterManager,
connect(Kaidan::instance(), &Kaidan::sendFile, this, &UploadManager::sendFile);
connect(&manager, &QXmppUploadManager::serviceFoundChanged, [=]() {
// needed because kaidan is in main thread
QMetaObject::invokeMethod(Kaidan::instance(), "setUploadServiceFound", Qt::QueuedConnection,
Q_ARG(bool, manager.serviceFound()));
connect(&manager, &QXmppUploadManager::serviceFoundChanged, this, [=]() {
Kaidan::instance()->serverFeaturesCache()->setHttpUploadSupported(manager.serviceFound());
});
connect(&manager, &QXmppUploadManager::uploadSucceeded,
this, &UploadManager::handleUploadSucceeded);
......
......@@ -480,7 +480,7 @@ ChatPageBase {
Controls.ToolButton {
id: attachButton
visible: Kaidan.uploadServiceFound
visible: Kaidan.serverFeaturesCache.httpUploadSupported
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
padding: 0
......
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