Commit f1d1577a authored by Ronan's avatar Ronan

feat(app): clean code => use forward declarations when possible, avoid include...

feat(app): clean code => use forward declarations when possible, avoid include with relative paths, improve compile time...
parent 5d1ef1c2
Pipeline #84 failed with stage
in 0 seconds
......@@ -25,45 +25,46 @@
#include <QFileSelector>
#include <QLibraryInfo>
#include <QMenu>
#include <QQmlApplicationEngine>
#include <QQmlFileSelector>
#include <QQuickWindow>
#include <QSystemTrayIcon>
#include <QTimer>
#include "config.h"
#include "../components/Components.hpp"
#include "../utils/LinphoneUtils.hpp"
#include "../utils/Utils.hpp"
#include "cli/Cli.hpp"
#include "components/Components.hpp"
#include "logger/Logger.hpp"
#include "paths/Paths.hpp"
#include "providers/AvatarProvider.hpp"
#include "providers/ImageProvider.hpp"
#include "providers/ThumbnailProvider.hpp"
#include "translator/DefaultTranslator.hpp"
#include "utils/LinphoneUtils.hpp"
#include "utils/Utils.hpp"
#include "App.hpp"
using namespace std;
// =============================================================================
using namespace std;
namespace {
constexpr char cDefaultLocale[] = "en";
constexpr char DefaultLocale[] = "en";
constexpr char cLanguagePath[] = ":/languages/";
constexpr char LanguagePath[] = ":/languages/";
// The main windows of Linphone desktop.
constexpr char cQmlViewMainWindow[] = "qrc:/ui/views/App/Main/MainWindow.qml";
constexpr char cQmlViewCallsWindow[] = "qrc:/ui/views/App/Calls/CallsWindow.qml";
constexpr char cQmlViewSettingsWindow[] = "qrc:/ui/views/App/Settings/SettingsWindow.qml";
constexpr char QmlViewMainWindow[] = "qrc:/ui/views/App/Main/MainWindow.qml";
constexpr char QmlViewCallsWindow[] = "qrc:/ui/views/App/Calls/CallsWindow.qml";
constexpr char QmlViewSettingsWindow[] = "qrc:/ui/views/App/Settings/SettingsWindow.qml";
constexpr int cVersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds.
constexpr int VersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds.
}
static inline bool installLocale (App &app, QTranslator &translator, const QLocale &locale) {
return translator.load(locale, cLanguagePath) && app.installTranslator(&translator);
return translator.load(locale, LanguagePath) && app.installTranslator(&translator);
}
static inline shared_ptr<linphone::Config> getConfigIfExists (const QCommandLineParser &parser) {
......@@ -77,19 +78,19 @@ static inline shared_ptr<linphone::Config> getConfigIfExists (const QCommandLine
// -----------------------------------------------------------------------------
App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::User | Mode::ExcludeAppPath | Mode::ExcludeAppVersion) {
setWindowIcon(QIcon(WINDOW_ICON_PATH));
setWindowIcon(QIcon(LinphoneUtils::WindowIconPath));
createParser();
mParser->process(*this);
// Initialize logger.
shared_ptr<linphone::Config> config = ::getConfigIfExists(*mParser);
shared_ptr<linphone::Config> config = getConfigIfExists(*mParser);
Logger::init(config);
if (mParser->isSet("verbose"))
Logger::getInstance()->setVerbose(true);
// List available locales.
for (const auto &locale : QDir(cLanguagePath).entryList())
for (const auto &locale : QDir(LanguagePath).entryList())
mAvailableLocales << QLocale(locale);
// Init locale.
......@@ -137,7 +138,7 @@ static QQuickWindow *createSubWindow (QQmlApplicationEngine *engine, const char
// -----------------------------------------------------------------------------
void App::initContentApp () {
shared_ptr<linphone::Config> config = ::getConfigIfExists(*mParser);
shared_ptr<linphone::Config> config = getConfigIfExists(*mParser);
bool mustBeIconified = false;
// Destroy qml components and linphone core if necessary.
......@@ -206,9 +207,9 @@ void App::initContentApp () {
mEngine->addImportPath(":/ui/views");
// Provide avatars/thumbnails providers.
mEngine->addImageProvider(AvatarProvider::PROVIDER_ID, new AvatarProvider());
mEngine->addImageProvider(ImageProvider::PROVIDER_ID, new ImageProvider());
mEngine->addImageProvider(ThumbnailProvider::PROVIDER_ID, new ThumbnailProvider());
mEngine->addImageProvider(AvatarProvider::ProviderId, new AvatarProvider());
mEngine->addImageProvider(ImageProvider::ProviderId, new ImageProvider());
mEngine->addImageProvider(ThumbnailProvider::ProviderId, new ThumbnailProvider());
mColors = new Colors(this);
mColors->useConfig(config);
......@@ -223,7 +224,7 @@ void App::initContentApp () {
// Load main view.
qInfo() << QStringLiteral("Loading main view...");
mEngine->load(QUrl(cQmlViewMainWindow));
mEngine->load(QUrl(QmlViewMainWindow));
if (mEngine->rootObjects().isEmpty())
qFatal("Unable to open main window.");
......@@ -264,12 +265,12 @@ QString App::getCommandArgument () {
QQuickWindow *App::getCallsWindow () {
if (CoreManager::getInstance()->getCore()->getConfig()->getInt(
SettingsModel::UI_SECTION, "disable_calls_window", 0
SettingsModel::UiSection, "disable_calls_window", 0
))
return nullptr;
if (!mCallsWindow)
mCallsWindow = ::createSubWindow(mEngine, cQmlViewCallsWindow);
mCallsWindow = createSubWindow(mEngine, QmlViewCallsWindow);
return mCallsWindow;
}
......@@ -282,7 +283,7 @@ QQuickWindow *App::getMainWindow () const {
QQuickWindow *App::getSettingsWindow () {
if (!mSettingsWindow) {
mSettingsWindow = ::createSubWindow(mEngine, cQmlViewSettingsWindow);
mSettingsWindow = createSubWindow(mEngine, QmlViewSettingsWindow);
QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) {
if (visibility == QWindow::Hidden) {
qInfo() << QStringLiteral("Update nat policy.");
......@@ -382,7 +383,7 @@ void registerToolType (const char *name) {
void App::registerTypes () {
qInfo() << QStringLiteral("Registering types...");
qRegisterMetaType<std::shared_ptr<linphone::ProxyConfig> >();
qRegisterMetaType<shared_ptr<linphone::ProxyConfig>>();
qRegisterMetaType<ChatModel::EntryType>();
registerType<AssistantModel>("AssistantModel");
......@@ -479,7 +480,7 @@ void App::setTrayIcon () {
menu->addAction(quitAction);
systemTrayIcon->setContextMenu(menu);
systemTrayIcon->setIcon(QIcon(WINDOW_ICON_PATH));
systemTrayIcon->setIcon(QIcon(LinphoneUtils::WindowIconPath));
systemTrayIcon->setToolTip("Linphone");
systemTrayIcon->show();
......@@ -492,37 +493,37 @@ void App::initLocale (const shared_ptr<linphone::Config> &config) {
// Try to use preferred locale.
QString locale;
if (config)
locale = ::Utils::coreStringToAppString(config->getString(SettingsModel::UI_SECTION, "locale", ""));
locale = Utils::coreStringToAppString(config->getString(SettingsModel::UiSection, "locale", ""));
if (!locale.isEmpty() && ::installLocale(*this, *mTranslator, QLocale(locale))) {
if (!locale.isEmpty() && installLocale(*this, *mTranslator, QLocale(locale))) {
mLocale = locale;
return;
}
// Try to use system locale.
QLocale sysLocale = QLocale::system();
if (::installLocale(*this, *mTranslator, sysLocale)) {
if (installLocale(*this, *mTranslator, sysLocale)) {
mLocale = sysLocale.name();
return;
}
// Use english.
mLocale = cDefaultLocale;
if (!::installLocale(*this, *mTranslator, QLocale(mLocale)))
mLocale = DefaultLocale;
if (!installLocale(*this, *mTranslator, QLocale(mLocale)))
qFatal("Unable to install default translator.");
}
QString App::getConfigLocale () const {
return ::Utils::coreStringToAppString(
return Utils::coreStringToAppString(
CoreManager::getInstance()->getCore()->getConfig()->getString(
SettingsModel::UI_SECTION, "locale", ""
SettingsModel::UiSection, "locale", ""
)
);
}
void App::setConfigLocale (const QString &locale) {
CoreManager::getInstance()->getCore()->getConfig()->setString(
SettingsModel::UI_SECTION, "locale", ::Utils::appStringToCoreString(locale)
SettingsModel::UiSection, "locale", Utils::appStringToCoreString(locale)
);
emit configLocaleChanged(locale);
......@@ -555,15 +556,15 @@ void App::openAppAfterInit (bool mustBeIconified) {
// Display Assistant if it's the first time app launch.
{
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
if (config->getInt(SettingsModel::UI_SECTION, "force_assistant_at_startup", 1)) {
if (config->getInt(SettingsModel::UiSection, "force_assistant_at_startup", 1)) {
QMetaObject::invokeMethod(mainWindow, "setView", Q_ARG(QVariant, "Assistant"), Q_ARG(QVariant, QString("")));
config->setInt(SettingsModel::UI_SECTION, "force_assistant_at_startup", 0);
config->setInt(SettingsModel::UiSection, "force_assistant_at_startup", 0);
}
}
#ifdef ENABLE_UPDATE_CHECK
QTimer *timer = new QTimer(mEngine);
timer->setInterval(cVersionUpdateCheckInterval);
timer->setInterval(VersionUpdateCheckInterval);
QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate);
timer->start();
......@@ -576,6 +577,6 @@ void App::openAppAfterInit (bool mustBeIconified) {
void App::checkForUpdate () {
CoreManager::getInstance()->getCore()->checkForUpdate(
::Utils::appStringToCoreString(applicationVersion())
Utils::appStringToCoreString(applicationVersion())
);
}
......@@ -23,21 +23,24 @@
#ifndef APP_H_
#define APP_H_
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <memory>
#include "../components/notifier/Notifier.hpp"
#include "../components/other/colors/Colors.hpp"
#include "single-application/SingleApplication.hpp"
#define APP_CODE_RESTART 1000
// =============================================================================
class QCommandLineParser;
class QQmlApplicationEngine;
class QQuickWindow;
class QSystemTrayIcon;
namespace linphone {
class Config;
}
class Colors;
class DefaultTranslator;
class Notifier;
class App : public SingleApplication {
Q_OBJECT;
......@@ -59,7 +62,7 @@ public:
bool event (QEvent *event) override;
#endif // ifdef Q_OS_MACOS
QQmlEngine *getEngine () {
QQmlApplicationEngine *getEngine () {
return mEngine;
}
......@@ -83,8 +86,10 @@ public:
return static_cast<App *>(QApplication::instance());
}
static constexpr int RestartCode = 1000;
Q_INVOKABLE void restart () {
exit(APP_CODE_RESTART);
exit(RestartCode);
}
Q_INVOKABLE QQuickWindow *getCallsWindow ();
......
......@@ -29,21 +29,21 @@
#include "AppController.hpp"
using namespace std;
// =============================================================================
using namespace std;
namespace {
// Must be unique. Used by `SingleApplication` and `Paths`.
constexpr char cApplicationName[] = "linphone";
constexpr char cApplicationVersion[] = LINPHONE_QT_GIT_VERSION;
constexpr char cApplicationMinimalQtVersion[] = "5.9.0";
constexpr char ApplicationName[] = "linphone";
constexpr char ApplicationVersion[] = LINPHONE_QT_GIT_VERSION;
constexpr char ApplicationMinimalQtVersion[] = "5.9.0";
constexpr char cDefaultFont[] = "Noto Sans";
constexpr char DefaultFont[] = "Noto Sans";
}
AppController::AppController (int &argc, char *argv[]) {
QT_REQUIRE_VERSION(argc, argv, cApplicationMinimalQtVersion);
QT_REQUIRE_VERSION(argc, argv, ApplicationMinimalQtVersion);
Q_ASSERT(!mApp);
// Disable QML cache. Avoid malformed cache.
......@@ -57,8 +57,8 @@ AppController::AppController (int &argc, char *argv[]) {
// App creation.
// ---------------------------------------------------------------------------
QCoreApplication::setApplicationName(cApplicationName);
QCoreApplication::setApplicationVersion(cApplicationVersion);
QCoreApplication::setApplicationName(ApplicationName);
QCoreApplication::setApplicationVersion(ApplicationVersion);
mApp = new App(argc, argv);
QQuickStyle::setStyle("Default");
......@@ -88,7 +88,7 @@ AppController::AppController (int &argc, char *argv[]) {
}
}
mApp->setFont(QFont(cDefaultFont));
mApp->setFont(QFont(DefaultFont));
}
AppController::~AppController () {
......
......@@ -20,6 +20,9 @@
* Author: Ronan Abhamon
*/
#ifndef APP_CONTROLLER_H_
#define APP_CONTROLLER_H_
#include "App.hpp"
// =============================================================================
......@@ -37,3 +40,5 @@ public:
private:
App *mApp = nullptr;
};
#endif // APP_CONTROLLER_H_
......@@ -23,6 +23,8 @@
#include <iostream>
#include "app/App.hpp"
#include "components/calls/CallsListModel.hpp"
#include "components/core/CoreHandlers.hpp"
#include "components/core/CoreManager.hpp"
#include "utils/Utils.hpp"
......@@ -181,7 +183,8 @@ static QString indentedWord (QString word, int &curPos, const int lineLength, co
}
static string multilineIndent (const QString &str, int indentationNumber = 0) {
static const int lineLength(80);
constexpr int lineLength(80);
static const QRegExp spaceRegexp("(\\s)");
const QString padding(indentationNumber * 2, ' ');
......@@ -294,7 +297,7 @@ QString Cli::Command::getFunctionSyntax () const {
functionSyntax += argName;
functionSyntax += QStringLiteral("=<");
switch (mArgsScheme[argName].type) {
case STRING :
case String:
functionSyntax += QStringLiteral("str");
break;
default:
......
......@@ -41,11 +41,11 @@ class Cli : public QObject {
typedef void (*Function)(QHash<QString, QString> &);
enum ArgumentType {
STRING
String
};
struct Argument {
Argument (ArgumentType type = STRING, bool isOptional = false) {
Argument (ArgumentType type = String, bool isOptional = false) {
this->type = type;
this->isOptional = isOptional;
}
......@@ -81,8 +81,6 @@ class Cli : public QObject {
};
public:
~Cli () = default;
enum CommandFormat {
UnknownFormat,
CliFormat,
......
......@@ -30,6 +30,8 @@
#include "Logger.hpp"
// =============================================================================
#if defined(__linux__) || defined(__APPLE__)
#define BLUE "\x1B[1;34m"
#define YELLOW "\x1B[1;33m"
......@@ -46,19 +48,17 @@
#define RESET ""
#endif // if defined(__linux__) || defined(__APPLE__)
// =============================================================================
using namespace std;
namespace {
constexpr char cQtDomain[] = "qt";
constexpr size_t cMaxLogsCollectionSize = 10485760; // 10MB.
constexpr char cSrcPattern[] = "/linphone-desktop/src/";
constexpr char QtDomain[] = "qt";
constexpr size_t MaxLogsCollectionSize = 10485760; // 10MB.
constexpr char SrcPattern[] = "/linphone-desktop/src/";
}
QMutex Logger::mMutex;
Logger *Logger::mInstance = nullptr;
Logger *Logger::mInstance;
// -----------------------------------------------------------------------------
......@@ -150,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
QByteArray contextArr;
{
const char *file = context.file;
const char *pos = file ? Utils::rstrstr(file, cSrcPattern) : file;
const char *pos = file ? Utils::rstrstr(file, SrcPattern) : file;
contextArr = QStringLiteral("%1:%2: ")
.arg(pos ? pos + sizeof(cSrcPattern) - 1 : file)
.arg(pos ? pos + sizeof(SrcPattern) - 1 : file)
.arg(context.line)
.toLocal8Bit();
contextStr = contextArr.constData();
......@@ -168,7 +168,7 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
mMutex.lock();
fprintf(stderr, format, dateTime.constData(), QThread::currentThread(), contextStr, localMsg.constData());
bctbx_log(cQtDomain, level, "QT: %s%s", contextStr, localMsg.constData());
bctbx_log(QtDomain, level, "QT: %s%s", contextStr, localMsg.constData());
mMutex.unlock();
......@@ -204,7 +204,7 @@ void Logger::init (const shared_ptr<linphone::Config> &config) {
}
linphone::Core::setLogCollectionPath(Utils::appStringToCoreString(folder));
linphone::Core::setLogCollectionMaxFileSize(cMaxLogsCollectionSize);
linphone::Core::setLogCollectionMaxFileSize(MaxLogsCollectionSize);
mInstance->enable(SettingsModel::getLogsEnabled(config));
}
......@@ -36,8 +36,6 @@ namespace linphone {
class Logger {
public:
~Logger () = default;
bool isVerbose () const {
return mVerbose;
}
......
......@@ -36,6 +36,6 @@ int main (int argc, char *argv[]) {
do {
app->initContentApp();
ret = app->exec();
} while (ret == APP_CODE_RESTART);
} while (ret == App::RestartCode);
return ret;
}
......@@ -37,22 +37,22 @@
using namespace std;
namespace {
constexpr char cPathAssistantConfig[] = "/linphone/assistant/";
constexpr char cPathAvatars[] = "/avatars/";
constexpr char cPathCaptures[] = "/Linphone/captures/";
constexpr char cPathCodecs[] = "/codecs/";
constexpr char cPathLogs[] = "/logs/";
constexpr char cPathPlugins[] = "/plugins/";
constexpr char cPathThumbnails[] = "/thumbnails/";
constexpr char cPathUserCertificates[] = "/usr-crt/";
constexpr char cPathCallHistoryList[] = "/call-history.db";
constexpr char cPathConfig[] = "/linphonerc";
constexpr char cPathFactoryConfig[] = "/linphone/linphonerc-factory";
constexpr char cPathRootCa[] = "/linphone/rootca.pem";
constexpr char cPathFriendsList[] = "/friends.db";
constexpr char cPathMessageHistoryList[] = "/message-history.db";
constexpr char cPathZrtpSecrets[] = "/zidcache";
constexpr char PathAssistantConfig[] = "/linphone/assistant/";
constexpr char PathAvatars[] = "/avatars/";
constexpr char PathCaptures[] = "/Linphone/captures/";
constexpr char PathCodecs[] = "/codecs/";
constexpr char PathLogs[] = "/logs/";
constexpr char PathPlugins[] = "/plugins/";
constexpr char PathThumbnails[] = "/thumbnails/";
constexpr char PathUserCertificates[] = "/usr-crt/";
constexpr char PathCallHistoryList[] = "/call-history.db";
constexpr char PathConfig[] = "/linphonerc";
constexpr char PathFactoryConfig[] = "/linphone/linphonerc-factory";
constexpr char PathRootCa[] = "/linphone/rootca.pem";
constexpr char PathFriendsList[] = "/friends.db";
constexpr char PathMessageHistoryList[] = "/message-history.db";
constexpr char PathZrtpSecrets[] = "/zidcache";
}
static inline bool dirPathExists (const QString &path) {
......@@ -127,35 +127,35 @@ static inline QString getAppPackageMsPluginsDirPath () {
}
static inline QString getAppAssistantConfigDirPath () {
return getAppPackageDataDirPath() + cPathAssistantConfig;
return getAppPackageDataDirPath() + PathAssistantConfig;
}
static inline QString getAppConfigFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + cPathConfig;
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PathConfig;
}
static inline QString getAppCallHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathCallHistoryList;
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathCallHistoryList;
}
static inline QString getAppFactoryConfigFilePath () {
return getAppPackageDataDirPath() + cPathFactoryConfig;
return getAppPackageDataDirPath() + PathFactoryConfig;
}
static inline QString getAppPluginsDirPath () {
return getAppPackageDataDirPath() + cPathPlugins;
return getAppPackageDataDirPath() + PathPlugins;
}
static inline QString getAppRootCaFilePath () {
return getAppPackageDataDirPath() + cPathRootCa;
return getAppPackageDataDirPath() + PathRootCa;
}
static inline QString getAppFriendsFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathFriendsList;
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathFriendsList;
}
static inline QString getAppMessageHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathMessageHistoryList;
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathMessageHistoryList;
}
// -----------------------------------------------------------------------------
......@@ -171,7 +171,7 @@ string Paths::getAssistantConfigDirPath () {
}
string Paths::getAvatarsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathAvatars);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathAvatars);
}
string Paths::getCallHistoryFilePath () {
......@@ -179,11 +179,11 @@ string Paths::getCallHistoryFilePath () {
}
string Paths::getCapturesDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + cPathCaptures);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + PathCaptures);
}
string Paths::getCodecsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathCodecs);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathCodecs);
}
string Paths::getConfigFilePath (const QString &configPath, bool writable) {
......@@ -191,7 +191,7 @@ string Paths::getConfigFilePath (const QString &configPath, bool writable) {
? getAppConfigFilePath()
: QFileInfo(configPath).absoluteFilePath();
return writable ? ::getWritableFilePath(path) : ::getReadableFilePath(path);
return writable ? getWritableFilePath(path) : getReadableFilePath(path);
}
string Paths::getFactoryConfigFilePath () {
......@@ -207,7 +207,7 @@ string Paths::getDownloadDirPath () {
}
string Paths::getLogsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathLogs);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathLogs);
}
string Paths::getMessageHistoryFilePath () {
......@@ -227,15 +227,15 @@ string Paths::getRootCaFilePath () {
}
string Paths::getThumbnailsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathThumbnails);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathThumbnails);
}
string Paths::getUserCertificatesDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathUserCertificates);
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathUserCertificates);
}
string Paths::getZrtpSecretsFilePath () {
return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathZrtpSecrets);
return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathZrtpSecrets);
}
// -----------------------------------------------------------------------------
......
......@@ -27,7 +27,7 @@
// =============================================================================
const QString AvatarProvider::PROVIDER_ID = "avatar";
const QString AvatarProvider::ProviderId = "avatar";
AvatarProvider::AvatarProvider () : QQuickImageProvider(
QQmlImageProviderBase::Image,
......
......@@ -30,11 +30,10 @@
class AvatarProvider : public QQuickImageProvider {
public:
AvatarProvider ();
~AvatarProvider () = default;
QImage requestImage (const QString &id, QSize *size, const QSize &requestedSize) override;
static const QString PROVIDER_ID;
static const QString ProviderId;
private:
QString mAvatarsPath;
......
......@@ -26,6 +26,7 @@
#include <QSvgRenderer>
#include "app/App.hpp"
#include "components/other/colors/Colors.hpp"
#include "ImageProvider.hpp"
......@@ -35,7 +36,7 @@ using namespace std;
namespace {
// Max image size in bytes. (100Kb)
constexpr qint64 cMaxImageSize = 102400;
constexpr qint64 MaxImageSize = 102400;
}
static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QString &name) {
......@@ -234,7 +235,7 @@ static QByteArray computeContent (QFile &file) {
// -----------------------------------------------------------------------------
const QString ImageProvider::PROVIDER_ID = "internal";
const QString ImageProvider::ProviderId = "internal";
ImageProvider::ImageProvider () : QQuickImageProvider(
QQmlImageProviderBase::Image,
......@@ -252,7 +253,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize
// 1. Read and update XML content.
QFile file(path);
if (Q_UNLIKELY(QFileInfo(file).size() > cMaxImageSize)) {
if (Q_UNLIKELY(QFileInfo(file).size() > MaxImageSize)) {
qWarning() << QStringLiteral("Unable to open large file: `%1`.").arg(path);
return QImage();
}
......@@ -262,7 +263,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize
return QImage();
}
const QByteArray content = ::computeContent(file);
const QByteArray content = computeContent(file);
if (Q_UNLIKELY(!content.length())) {
qWarning() << QStringLiteral("Unable to parse file: `%1`.").arg(path);
return QImage();
......
......@@ -30,11 +30,10 @@
class ImageProvider : public QQuickImageProvider {
public:
ImageProvider ();
~ImageProvider () = default;
QImage requestImage (const QString &id, QSize *size, const QSize &requestedSize) override;
static const QString PROVIDER_ID;
static const QString ProviderId;
};
#endif // IMAGE_PROVIDER_H_
......@@ -27,7 +27,7 @@
// =============================================================================
const QString ThumbnailProvider::PROVIDER_ID = "thumbnail";
const QString ThumbnailProvider::ProviderId = "thumbnail";