Commit a6ba2a0a authored by LNJ's avatar LNJ 💬

Rename Utils to QmlUtils

parent f9a4bc85
......@@ -20,7 +20,7 @@ set(KAIDAN_SOURCES
src/EmojiModel.cpp
src/TransferCache.cpp
src/DownloadManager.cpp
src/Utils.cpp
src/QmlUtils.cpp
# needed to trigger moc generation
src/Enums.h
......
......@@ -43,12 +43,12 @@
#include "RosterModel.h"
#include "MessageModel.h"
#include "PresenceCache.h"
#include "Utils.h"
#include "QmlUtils.h"
Kaidan *Kaidan::s_instance = nullptr;
Kaidan::Kaidan(QGuiApplication *app, bool enableLogging, QObject *parent)
: QObject(parent), utils(new Utils(this)), database(new Database())
: QObject(parent), m_utils(new QmlUtils(this)), database(new Database())
{
Q_ASSERT(!Kaidan::s_instance);
Kaidan::s_instance = this;
......
......@@ -43,7 +43,7 @@
class QGuiApplication;
class Database;
class QXmppClient;
class Utils;
class QmlUtils;
using namespace Enums;
......@@ -60,7 +60,7 @@ class Kaidan : public QObject
{
Q_OBJECT
Q_PROPERTY(Utils* utils READ getUtils CONSTANT)
Q_PROPERTY(QmlUtils* utils READ getUtils CONSTANT)
Q_PROPERTY(RosterModel* rosterModel READ getRosterModel CONSTANT)
Q_PROPERTY(MessageModel* messageModel READ getMessageModel CONSTANT)
Q_PROPERTY(AvatarFileStorage* avatarStorage READ getAvatarStorage NOTIFY avatarStorageChanged)
......@@ -203,9 +203,9 @@ public:
return caches->settings;
}
Utils* getUtils() const
QmlUtils* getUtils() const
{
return utils;
return m_utils;
}
/**
......@@ -406,7 +406,7 @@ public slots:
private:
void connectDatabases();
Utils *utils;
QmlUtils *m_utils;
Database *database;
ClientWorker::Caches *caches;
ClientThread *cltThrd;
......
......@@ -28,7 +28,7 @@
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Utils.h"
#include "QmlUtils.h"
#include <QColor>
#include <QClipboard>
#include <QDebug>
......@@ -41,12 +41,12 @@
#include <QStandardPaths>
#include "qxmpp-exts/QXmppColorGenerator.h"
Utils::Utils(QObject *parent)
QmlUtils::QmlUtils(QObject *parent)
: QObject(parent)
{
}
QString Utils::getResourcePath(const QString &name) const
QString QmlUtils::getResourcePath(const QString &name) const
{
// We generally prefer to first search for files in application resources
if (QFile::exists(":/" + name))
......@@ -84,23 +84,23 @@ QString Utils::getResourcePath(const QString &name) const
return "";
}
bool Utils::isImageFile(const QUrl &fileUrl) const
bool QmlUtils::isImageFile(const QUrl &fileUrl) const
{
QMimeType type = QMimeDatabase().mimeTypeForUrl(fileUrl);
return type.inherits("image/jpeg") || type.inherits("image/png");
}
void Utils::copyToClipboard(const QString &text) const
void QmlUtils::copyToClipboard(const QString &text) const
{
QGuiApplication::clipboard()->setText(text);
}
QString Utils::fileNameFromUrl(const QUrl &url) const
QString QmlUtils::fileNameFromUrl(const QUrl &url) const
{
return QUrl(url).fileName();
}
QString Utils::fileSizeFromUrl(const QUrl &url) const
QString QmlUtils::fileSizeFromUrl(const QUrl &url) const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) // Qt 5.10 or later
return QLocale::system().formattedDataSize(QFileInfo(QUrl(url).toLocalFile())
......@@ -113,20 +113,20 @@ QString Utils::fileSizeFromUrl(const QUrl &url) const
#endif
}
QString Utils::formatMessage(const QString &message) const
QString QmlUtils::formatMessage(const QString &message) const
{
// escape all special XML chars (like '<' and '>')
// and spilt into words for processing
return processMsgFormatting(message.toHtmlEscaped().split(" "));
}
QColor Utils::getUserColor(const QString &nickName) const
QColor QmlUtils::getUserColor(const QString &nickName) const
{
QXmppColorGenerator::RGBColor color = QXmppColorGenerator::generateColor(nickName);
return QColor(color.red, color.green, color.blue);
}
QString Utils::processMsgFormatting(const QStringList &list, bool isFirst) const
QString QmlUtils::processMsgFormatting(const QStringList &list, bool isFirst) const
{
if (list.isEmpty())
return "";
......
......@@ -40,12 +40,12 @@
* The methods are not static, because they need to be used from QML and registered in
* Qt.
*/
class Utils : public QObject
class QmlUtils : public QObject
{
Q_OBJECT
public:
Utils(QObject *parent = nullptr);
QmlUtils(QObject *parent = nullptr);
public slots:
/**
......
......@@ -55,7 +55,7 @@
#include "Enums.h"
#include "StatusBar.h"
#include "EmojiModel.h"
#include "Utils.h"
#include "QmlUtils.h"
#ifdef STATIC_BUILD
#include "static_plugins.h"
......@@ -169,7 +169,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qRegisterMetaType<MessageType>("MessageType");
qRegisterMetaType<DisconnectionReason>("DisconnectionReason");
qRegisterMetaType<TransferJob*>("TransferJob*");
qRegisterMetaType<Utils*>("Utils*");
qRegisterMetaType<QmlUtils*>("QmlUtils*");
// Qt-Translator
QTranslator qtTranslator;
......
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