From f1d1577aa0b6ac173a7e6e0028f5b3046bc1049d Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 18 Jun 2018 14:27:50 +0200 Subject: [PATCH] feat(app): clean code => use forward declarations when possible, avoid include with relative paths, improve compile time... --- src/app/App.cpp | 79 ++++++----- src/app/App.hpp | 21 +-- src/app/AppController.cpp | 20 +-- src/app/AppController.hpp | 5 + src/app/cli/Cli.cpp | 7 +- src/app/cli/Cli.hpp | 6 +- src/app/logger/Logger.cpp | 20 +-- src/app/logger/Logger.hpp | 2 - src/app/main.cpp | 2 +- src/app/paths/Paths.cpp | 62 ++++---- src/app/providers/AvatarProvider.cpp | 2 +- src/app/providers/AvatarProvider.hpp | 3 +- src/app/providers/ImageProvider.cpp | 9 +- src/app/providers/ImageProvider.hpp | 3 +- src/app/providers/ThumbnailProvider.cpp | 2 +- src/app/providers/ThumbnailProvider.hpp | 3 +- .../single-application/SingleApplication.cpp | 42 +++--- .../SingleApplicationDBusPrivate.hpp | 1 - .../SingleApplicationPrivate.hpp | 4 +- src/app/translator/DefaultTranslator.hpp | 1 - src/components/Components.hpp | 8 ++ src/components/assistant/AssistantModel.cpp | 64 +++++---- .../authentication/AuthenticationNotifier.cpp | 17 +-- .../authentication/AuthenticationNotifier.hpp | 11 +- src/components/call/CallModel.cpp | 60 ++++---- src/components/call/CallModel.hpp | 2 - src/components/calls/CallsListModel.cpp | 43 +++--- src/components/calls/CallsListModel.hpp | 5 +- src/components/calls/CallsListProxyModel.cpp | 12 +- src/components/calls/CallsListProxyModel.hpp | 5 +- src/components/camera/Camera.cpp | 11 +- src/components/camera/Camera.hpp | 7 +- src/components/camera/CameraPreview.cpp | 12 +- src/components/camera/MSFunctions.cpp | 2 +- src/components/chat/ChatModel.cpp | 109 +++++++------- src/components/chat/ChatModel.hpp | 5 +- src/components/chat/ChatProxyModel.cpp | 12 +- src/components/chat/ChatProxyModel.hpp | 4 +- src/components/codecs/AbstractCodecsModel.hpp | 3 +- src/components/codecs/AudioCodecsModel.cpp | 2 +- src/components/codecs/VideoCodecsModel.cpp | 26 ++-- .../conference/ConferenceAddModel.cpp | 23 +-- .../conference/ConferenceAddModel.hpp | 3 +- .../conference/ConferenceHelperModel.cpp | 25 ++-- .../conference/ConferenceHelperModel.hpp | 9 +- src/components/conference/ConferenceModel.cpp | 16 ++- src/components/conference/ConferenceModel.hpp | 1 - src/components/contact/ContactModel.cpp | 15 +- src/components/contact/ContactModel.hpp | 16 +-- src/components/contact/VcardModel.cpp | 134 +++++++++--------- src/components/contact/VcardModel.hpp | 7 +- src/components/contacts/ContactsListModel.cpp | 36 ++--- src/components/contacts/ContactsListModel.hpp | 13 +- .../contacts/ContactsListProxyModel.cpp | 51 ++++--- .../contacts/ContactsListProxyModel.hpp | 3 +- src/components/core/CoreHandlers.cpp | 20 +-- src/components/core/CoreManager.cpp | 46 +++--- src/components/core/CoreManager.hpp | 23 ++- .../AbstractMessagesCountNotifier.cpp | 9 +- .../AbstractMessagesCountNotifier.hpp | 1 - .../MessagesCountNotifierLinux.cpp | 41 +++--- .../MessagesCountNotifierMacOs.hpp | 2 +- src/components/file/FileDownloader.cpp | 1 + src/components/file/FileExtractor.cpp | 1 + src/components/file/FileExtractor.hpp | 3 +- src/components/notifier/Notifier.cpp | 101 +++++++------ src/components/notifier/Notifier.hpp | 10 +- src/components/other/clipboard/Clipboard.cpp | 2 +- src/components/other/clipboard/Clipboard.hpp | 1 - src/components/other/colors/Colors.cpp | 21 +-- src/components/other/colors/Colors.hpp | 6 +- .../other/text-to-speech/TextToSpeech.hpp | 1 - src/components/other/units/Units.hpp | 1 - src/components/presence/OwnPresenceModel.cpp | 14 +- src/components/presence/OwnPresenceModel.hpp | 2 +- src/components/presence/Presence.hpp | 4 - .../settings/AccountSettingsModel.cpp | 88 ++++++------ .../settings/AccountSettingsModel.hpp | 4 +- src/components/settings/SettingsModel.cpp | 93 ++++++------ src/components/settings/SettingsModel.hpp | 6 +- .../sip-addresses/SipAddressObserver.hpp | 5 +- .../sip-addresses/SipAddressesModel.cpp | 51 ++++--- .../sip-addresses/SipAddressesModel.hpp | 4 +- .../sip-addresses/SipAddressesProxyModel.cpp | 29 ++-- .../sip-addresses/SipAddressesProxyModel.hpp | 3 +- src/components/sound-player/SoundPlayer.cpp | 19 +-- src/components/sound-player/SoundPlayer.hpp | 1 - .../TelephoneNumbersModel.cpp | 14 +- .../TelephoneNumbersModel.hpp | 3 +- src/components/timeline/TimelineModel.cpp | 3 +- src/components/timeline/TimelineModel.hpp | 1 - src/components/url-handlers/UrlHandlers.cpp | 2 +- src/components/url-handlers/UrlHandlers.hpp | 1 - src/utils/LinphoneUtils.cpp | 2 + src/utils/LinphoneUtils.hpp | 20 ++- src/utils/Utils.cpp | 4 +- 96 files changed, 902 insertions(+), 827 deletions(-) diff --git a/src/app/App.cpp b/src/app/App.cpp index 75e372342..36b68590c 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -25,45 +25,46 @@ #include #include #include +#include #include +#include #include #include #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; - // ============================================================================= -namespace { - constexpr char cDefaultLocale[] = "en"; +using namespace std; - constexpr char cLanguagePath[] = ":/languages/"; +namespace { + constexpr char DefaultLocale[] = "en"; + + 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 getConfigIfExists (const QCommandLineParser &parser) { @@ -77,19 +78,19 @@ static inline shared_ptr 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 config = ::getConfigIfExists(*mParser); + shared_ptr 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 config = ::getConfigIfExists(*mParser); + shared_ptr 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 >(); + qRegisterMetaType>(); qRegisterMetaType(); registerType("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 &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 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()) ); } diff --git a/src/app/App.hpp b/src/app/App.hpp index d4f8f3418..cdae4a068 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -23,21 +23,24 @@ #ifndef APP_H_ #define APP_H_ -#include -#include +#include -#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(QApplication::instance()); } + static constexpr int RestartCode = 1000; + Q_INVOKABLE void restart () { - exit(APP_CODE_RESTART); + exit(RestartCode); } Q_INVOKABLE QQuickWindow *getCallsWindow (); diff --git a/src/app/AppController.cpp b/src/app/AppController.cpp index 70550af21..ecdbe208a 100644 --- a/src/app/AppController.cpp +++ b/src/app/AppController.cpp @@ -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 () { diff --git a/src/app/AppController.hpp b/src/app/AppController.hpp index b5f541079..9f0a4aaed 100644 --- a/src/app/AppController.hpp +++ b/src/app/AppController.hpp @@ -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_ diff --git a/src/app/cli/Cli.cpp b/src/app/cli/Cli.cpp index 6f46c1b35..efb269c86 100644 --- a/src/app/cli/Cli.cpp +++ b/src/app/cli/Cli.cpp @@ -23,6 +23,8 @@ #include #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: diff --git a/src/app/cli/Cli.hpp b/src/app/cli/Cli.hpp index f89d0fcb1..04ef41006 100644 --- a/src/app/cli/Cli.hpp +++ b/src/app/cli/Cli.hpp @@ -41,11 +41,11 @@ class Cli : public QObject { typedef void (*Function)(QHash &); 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, diff --git a/src/app/logger/Logger.cpp b/src/app/logger/Logger.cpp index a9ac6f328..e13181fc4 100644 --- a/src/app/logger/Logger.cpp +++ b/src/app/logger/Logger.cpp @@ -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 &config) { } linphone::Core::setLogCollectionPath(Utils::appStringToCoreString(folder)); - linphone::Core::setLogCollectionMaxFileSize(cMaxLogsCollectionSize); + linphone::Core::setLogCollectionMaxFileSize(MaxLogsCollectionSize); mInstance->enable(SettingsModel::getLogsEnabled(config)); } diff --git a/src/app/logger/Logger.hpp b/src/app/logger/Logger.hpp index 2b01861f7..b55c484db 100644 --- a/src/app/logger/Logger.hpp +++ b/src/app/logger/Logger.hpp @@ -36,8 +36,6 @@ namespace linphone { class Logger { public: - ~Logger () = default; - bool isVerbose () const { return mVerbose; } diff --git a/src/app/main.cpp b/src/app/main.cpp index c9427c039..8b936d4ae 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -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; } diff --git a/src/app/paths/Paths.cpp b/src/app/paths/Paths.cpp index 4eddcb3c0..3b234e1b7 100644 --- a/src/app/paths/Paths.cpp +++ b/src/app/paths/Paths.cpp @@ -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 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 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 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); } // ----------------------------------------------------------------------------- diff --git a/src/app/providers/AvatarProvider.cpp b/src/app/providers/AvatarProvider.cpp index 49a94dc39..8045d6795 100644 --- a/src/app/providers/AvatarProvider.cpp +++ b/src/app/providers/AvatarProvider.cpp @@ -27,7 +27,7 @@ // ============================================================================= -const QString AvatarProvider::PROVIDER_ID = "avatar"; +const QString AvatarProvider::ProviderId = "avatar"; AvatarProvider::AvatarProvider () : QQuickImageProvider( QQmlImageProviderBase::Image, diff --git a/src/app/providers/AvatarProvider.hpp b/src/app/providers/AvatarProvider.hpp index 6e1564773..273a68e93 100644 --- a/src/app/providers/AvatarProvider.hpp +++ b/src/app/providers/AvatarProvider.hpp @@ -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; diff --git a/src/app/providers/ImageProvider.cpp b/src/app/providers/ImageProvider.cpp index 58dedde77..9780814b3 100644 --- a/src/app/providers/ImageProvider.cpp +++ b/src/app/providers/ImageProvider.cpp @@ -26,6 +26,7 @@ #include #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(); diff --git a/src/app/providers/ImageProvider.hpp b/src/app/providers/ImageProvider.hpp index 871415bab..327dd3a60 100644 --- a/src/app/providers/ImageProvider.hpp +++ b/src/app/providers/ImageProvider.hpp @@ -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_ diff --git a/src/app/providers/ThumbnailProvider.cpp b/src/app/providers/ThumbnailProvider.cpp index c5b2b6adb..9a516681a 100644 --- a/src/app/providers/ThumbnailProvider.cpp +++ b/src/app/providers/ThumbnailProvider.cpp @@ -27,7 +27,7 @@ // ============================================================================= -const QString ThumbnailProvider::PROVIDER_ID = "thumbnail"; +const QString ThumbnailProvider::ProviderId = "thumbnail"; ThumbnailProvider::ThumbnailProvider () : QQuickImageProvider( QQmlImageProviderBase::Image, diff --git a/src/app/providers/ThumbnailProvider.hpp b/src/app/providers/ThumbnailProvider.hpp index 7d09eb5cb..899fd7b73 100644 --- a/src/app/providers/ThumbnailProvider.hpp +++ b/src/app/providers/ThumbnailProvider.hpp @@ -30,11 +30,10 @@ class ThumbnailProvider : public QQuickImageProvider { public: ThumbnailProvider (); - ~ThumbnailProvider () = default; QImage requestImage (const QString &id, QSize *size, const QSize &requestedSize) override; - static const QString PROVIDER_ID; + static const QString ProviderId; private: QString mThumbnailsPath; diff --git a/src/app/single-application/SingleApplication.cpp b/src/app/single-application/SingleApplication.cpp index f5549488c..b7945944d 100644 --- a/src/app/single-application/SingleApplication.cpp +++ b/src/app/single-application/SingleApplication.cpp @@ -43,20 +43,22 @@ #include #endif // ifdef Q_OS_WIN -#include "../../utils/Utils.hpp" +#include "utils/Utils.hpp" #include "SingleApplication.hpp" #include "SingleApplicationPrivate.hpp" // ============================================================================= -static const char NewInstance = 'N'; -static const char SecondaryInstance = 'S'; -static const char Reconnect = 'R'; -static const char InvalidConnection = '\0'; - using namespace std; +namespace { + constexpr char NewInstance = 'N'; + constexpr char SecondaryInstance = 'S'; + constexpr char Reconnect = 'R'; + constexpr char InvalidConnection = '\0'; +} + // ----------------------------------------------------------------------------- SingleApplicationPrivate::SingleApplicationPrivate (SingleApplication *q_ptr) : q_ptr(q_ptr) { @@ -234,20 +236,20 @@ void SingleApplicationPrivate::connectToPrimary (int msecs, char connectionType) // Handle any further termination signals to ensure the // QSharedMemory block is deleted even if the process crashes - signal(SIGHUP, SingleApplicationPrivate::terminate); // 1 - signal(SIGINT, SingleApplicationPrivate::terminate); // 2 - signal(SIGQUIT, SingleApplicationPrivate::terminate); // 3 - signal(SIGILL, SingleApplicationPrivate::terminate); // 4 - signal(SIGABRT, SingleApplicationPrivate::terminate); // 6 - signal(SIGFPE, SingleApplicationPrivate::terminate); // 8 - signal(SIGBUS, SingleApplicationPrivate::terminate); // 10 - signal(SIGSEGV, SingleApplicationPrivate::terminate); // 11 - signal(SIGSYS, SingleApplicationPrivate::terminate); // 12 - signal(SIGPIPE, SingleApplicationPrivate::terminate); // 13 - signal(SIGALRM, SingleApplicationPrivate::terminate); // 14 - signal(SIGTERM, SingleApplicationPrivate::terminate); // 15 - signal(SIGXCPU, SingleApplicationPrivate::terminate); // 24 - signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25 + signal(SIGHUP, SingleApplicationPrivate::terminate); // 1 + signal(SIGINT, SingleApplicationPrivate::terminate); // 2 + signal(SIGQUIT, SingleApplicationPrivate::terminate); // 3 + signal(SIGILL, SingleApplicationPrivate::terminate); // 4 + signal(SIGABRT, SingleApplicationPrivate::terminate); // 6 + signal(SIGFPE, SingleApplicationPrivate::terminate); // 8 + signal(SIGBUS, SingleApplicationPrivate::terminate); // 10 + signal(SIGSEGV, SingleApplicationPrivate::terminate); // 11 + signal(SIGSYS, SingleApplicationPrivate::terminate); // 12 + signal(SIGPIPE, SingleApplicationPrivate::terminate); // 13 + signal(SIGALRM, SingleApplicationPrivate::terminate); // 14 + signal(SIGTERM, SingleApplicationPrivate::terminate); // 15 + signal(SIGXCPU, SingleApplicationPrivate::terminate); // 24 + signal(SIGXFSZ, SingleApplicationPrivate::terminate); // 25 } void SingleApplicationPrivate::terminate (int signum) { diff --git a/src/app/single-application/SingleApplicationDBusPrivate.hpp b/src/app/single-application/SingleApplicationDBusPrivate.hpp index 6c504e6a8..5248e940c 100644 --- a/src/app/single-application/SingleApplicationDBusPrivate.hpp +++ b/src/app/single-application/SingleApplicationDBusPrivate.hpp @@ -40,7 +40,6 @@ class SingleApplicationPrivate : public QDBusAbstractAdaptor { public: Q_DECLARE_PUBLIC(SingleApplication) SingleApplicationPrivate (SingleApplication *q_ptr); - ~SingleApplicationPrivate () = default; QDBusConnection getBus () const; diff --git a/src/app/single-application/SingleApplicationPrivate.hpp b/src/app/single-application/SingleApplicationPrivate.hpp index d0dfc10ea..532182d70 100644 --- a/src/app/single-application/SingleApplicationPrivate.hpp +++ b/src/app/single-application/SingleApplicationPrivate.hpp @@ -75,8 +75,8 @@ public: public Q_SLOTS: void slotConnectionEstablished (); - void slotDataAvailable(QLocalSocket *, quint32); - void slotClientConnectionClosed(QLocalSocket *, quint32); + void slotDataAvailable (QLocalSocket *, quint32); + void slotClientConnectionClosed (QLocalSocket *, quint32); }; #endif // SINGLE_APPLICATION_PRIVATE_H_ diff --git a/src/app/translator/DefaultTranslator.hpp b/src/app/translator/DefaultTranslator.hpp index be5842665..7c2583a2b 100644 --- a/src/app/translator/DefaultTranslator.hpp +++ b/src/app/translator/DefaultTranslator.hpp @@ -31,7 +31,6 @@ class DefaultTranslator : public QTranslator { public: DefaultTranslator (QObject *parent = Q_NULLPTR); - ~DefaultTranslator () = default; QString translate ( const char *context, diff --git a/src/components/Components.hpp b/src/components/Components.hpp index 7de432886..7738bda1a 100644 --- a/src/components/Components.hpp +++ b/src/components/Components.hpp @@ -25,6 +25,7 @@ #include "assistant/AssistantModel.hpp" #include "authentication/AuthenticationNotifier.hpp" +#include "call/CallModel.hpp" #include "calls/CallsListModel.hpp" #include "calls/CallsListProxyModel.hpp" #include "camera/Camera.hpp" @@ -34,12 +35,19 @@ #include "codecs/VideoCodecsModel.hpp" #include "conference/ConferenceAddModel.hpp" #include "conference/ConferenceModel.hpp" +#include "contact/ContactModel.hpp" +#include "contact/VcardModel.hpp" +#include "contacts/ContactsListModel.hpp" #include "contacts/ContactsListProxyModel.hpp" +#include "core/CoreHandlers.hpp" #include "core/CoreManager.hpp" #include "file/FileDownloader.hpp" #include "file/FileExtractor.hpp" +#include "notifier/Notifier.hpp" #include "presence/OwnPresenceModel.hpp" #include "settings/AccountSettingsModel.hpp" +#include "settings/SettingsModel.hpp" +#include "sip-addresses/SipAddressesModel.hpp" #include "sip-addresses/SipAddressesProxyModel.hpp" #include "sound-player/SoundPlayer.hpp" #include "telephone-numbers/TelephoneNumbersModel.hpp" diff --git a/src/components/assistant/AssistantModel.cpp b/src/components/assistant/AssistantModel.cpp index 0852087fb..1460a0c5e 100644 --- a/src/components/assistant/AssistantModel.cpp +++ b/src/components/assistant/AssistantModel.cpp @@ -20,18 +20,22 @@ * Author: Ronan Abhamon */ -#include "../../app/paths/Paths.hpp" -#include "../../utils/LinphoneUtils.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "app/paths/Paths.hpp" +#include "components/core/CoreManager.hpp" +#include "components/settings/AccountSettingsModel.hpp" +#include "components/settings/SettingsModel.hpp" +#include "utils/LinphoneUtils.hpp" +#include "utils/Utils.hpp" #include "AssistantModel.hpp" -#define DEFAULT_XMLRPC_URL "https://subscribe.linphone.org:444/wizard.php" +// ============================================================================= using namespace std; -// ============================================================================= +namespace { + constexpr char DefaultXmlrpcUri[] = "https://subscribe.linphone.org:444/wizard.php"; +} class AssistantModel::Handlers : public linphone::AccountCreatorListener { public: @@ -144,7 +148,7 @@ AssistantModel::AssistantModel (QObject *parent) : QObject(parent) { shared_ptr core = CoreManager::getInstance()->getCore(); mAccountCreator = core->createAccountCreator( - core->getConfig()->getString("assistant", "xmlrpc_url", DEFAULT_XMLRPC_URL) + core->getConfig()->getString("assistant", "xmlrpc_url", DefaultXmlrpcUri) ); mAccountCreator->setListener(mHandlers); } @@ -196,25 +200,25 @@ bool AssistantModel::addOtherSipAccount (const QVariantMap &map) { // Server address. { shared_ptr address = factory->createAddress( - ::Utils::appStringToCoreString(QStringLiteral("sip:%1").arg(domain)) - ); + Utils::appStringToCoreString(QStringLiteral("sip:%1").arg(domain)) + ); address->setTransport(LinphoneUtils::stringToTransportType(map["transport"].toString())); if (proxyConfig->setServerAddr(address->asString())) { qWarning() << QStringLiteral("Unable to add server address: `%1`.") - .arg(::Utils::coreStringToAppString(address->asString())); + .arg(Utils::coreStringToAppString(address->asString())); return false; } } // Sip Address. - shared_ptr address = factory->createAddress(::Utils::appStringToCoreString(sipAddress)); + shared_ptr address = factory->createAddress(Utils::appStringToCoreString(sipAddress)); if (!address) { qWarning() << QStringLiteral("Unable to create sip address object from: `%1`.").arg(sipAddress); return false; } - address->setDisplayName(::Utils::appStringToCoreString(map["displayName"].toString())); + address->setDisplayName(Utils::appStringToCoreString(map["displayName"].toString())); proxyConfig->setIdentityAddress(address); // AuthInfo. @@ -222,7 +226,7 @@ bool AssistantModel::addOtherSipAccount (const QVariantMap &map) { factory->createAuthInfo( address->getUsername(), // Username. "", // User ID. - ::Utils::appStringToCoreString(map["password"].toString()), // Password. + Utils::appStringToCoreString(map["password"].toString()), // Password. "", // HA1. "", // Realm. address->getDomain() // Domain. @@ -235,14 +239,14 @@ bool AssistantModel::addOtherSipAccount (const QVariantMap &map) { // ----------------------------------------------------------------------------- QString AssistantModel::getEmail () const { - return ::Utils::coreStringToAppString(mAccountCreator->getEmail()); + return Utils::coreStringToAppString(mAccountCreator->getEmail()); } void AssistantModel::setEmail (const QString &email) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; - switch (mAccountCreator->setEmail(::Utils::appStringToCoreString(email))) { + switch (mAccountCreator->setEmail(Utils::appStringToCoreString(email))) { case linphone::AccountCreatorEmailStatusOk: break; case linphone::AccountCreatorEmailStatusMalformed: @@ -259,14 +263,14 @@ void AssistantModel::setEmail (const QString &email) { // ----------------------------------------------------------------------------- QString AssistantModel::getPassword () const { - return ::Utils::coreStringToAppString(mAccountCreator->getPassword()); + return Utils::coreStringToAppString(mAccountCreator->getPassword()); } void AssistantModel::setPassword (const QString &password) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; - switch (mAccountCreator->setPassword(::Utils::appStringToCoreString(password))) { + switch (mAccountCreator->setPassword(Utils::appStringToCoreString(password))) { case linphone::AccountCreatorPasswordStatusOk: break; case linphone::AccountCreatorPasswordStatusTooShort: @@ -277,11 +281,11 @@ void AssistantModel::setPassword (const QString &password) { break; case linphone::AccountCreatorPasswordStatusInvalidCharacters: error = tr("passwordStatusInvalidCharacters") - .arg(::Utils::coreStringToAppString(config->getString("assistant", "password_regex", ""))); + .arg(Utils::coreStringToAppString(config->getString("assistant", "password_regex", ""))); break; case linphone::AccountCreatorPasswordStatusMissingCharacters: error = tr("passwordStatusMissingCharacters") - .arg(::Utils::coreStringToAppString(config->getString("assistant", "missing_characters", ""))); + .arg(Utils::coreStringToAppString(config->getString("assistant", "missing_characters", ""))); break; } @@ -302,14 +306,14 @@ void AssistantModel::setCountryCode (const QString &countryCode) { // ----------------------------------------------------------------------------- QString AssistantModel::getPhoneNumber () const { - return ::Utils::coreStringToAppString(mAccountCreator->getPhoneNumber()); + return Utils::coreStringToAppString(mAccountCreator->getPhoneNumber()); } void AssistantModel::setPhoneNumber (const QString &phoneNumber) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; - switch (mAccountCreator->setPhoneNumber(::Utils::appStringToCoreString(phoneNumber), ::Utils::appStringToCoreString(mCountryCode))) { + switch (mAccountCreator->setPhoneNumber(Utils::appStringToCoreString(phoneNumber), Utils::appStringToCoreString(mCountryCode))) { case linphone::AccountCreatorPhoneNumberStatusOk: break; case linphone::AccountCreatorPhoneNumberStatusInvalid: @@ -334,14 +338,14 @@ void AssistantModel::setPhoneNumber (const QString &phoneNumber) { // ----------------------------------------------------------------------------- QString AssistantModel::getUsername () const { - return ::Utils::coreStringToAppString(mAccountCreator->getUsername()); + return Utils::coreStringToAppString(mAccountCreator->getUsername()); } void AssistantModel::setUsername (const QString &username) { emit usernameChanged( username, mapAccountCreatorUsernameStatusToString( - mAccountCreator->setUsername(::Utils::appStringToCoreString(username)) + mAccountCreator->setUsername(Utils::appStringToCoreString(username)) ) ); } @@ -349,14 +353,14 @@ void AssistantModel::setUsername (const QString &username) { // ----------------------------------------------------------------------------- QString AssistantModel::getDisplayName () const { - return ::Utils::coreStringToAppString(mAccountCreator->getDisplayName()); + return Utils::coreStringToAppString(mAccountCreator->getDisplayName()); } void AssistantModel::setDisplayName (const QString &displayName) { emit displayNameChanged( displayName, mapAccountCreatorUsernameStatusToString( - mAccountCreator->setDisplayName(::Utils::appStringToCoreString(displayName)) + mAccountCreator->setDisplayName(Utils::appStringToCoreString(displayName)) ) ); } @@ -364,11 +368,11 @@ void AssistantModel::setDisplayName (const QString &displayName) { // ----------------------------------------------------------------------------- QString AssistantModel::getActivationCode () const { - return ::Utils::coreStringToAppString(mAccountCreator->getActivationCode()); + return Utils::coreStringToAppString(mAccountCreator->getActivationCode()); } void AssistantModel::setActivationCode (const QString &activationCode) { - mAccountCreator->setActivationCode(::Utils::appStringToCoreString(activationCode)); + mAccountCreator->setActivationCode(Utils::appStringToCoreString(activationCode)); emit activationCodeChanged(activationCode); } @@ -381,11 +385,11 @@ QString AssistantModel::getConfigFilename () const { void AssistantModel::setConfigFilename (const QString &configFilename) { mConfigFilename = configFilename; - QString configPath = ::Utils::coreStringToAppString(Paths::getAssistantConfigDirPath()) + configFilename; + QString configPath = Utils::coreStringToAppString(Paths::getAssistantConfigDirPath()) + configFilename; qInfo() << QStringLiteral("Set config on assistant: `%1`.").arg(configPath); CoreManager::getInstance()->getCore()->getConfig()->loadFromXmlFile( - ::Utils::appStringToCoreString(configPath) + Utils::appStringToCoreString(configPath) ); emit configFilenameChanged(configFilename); @@ -408,7 +412,7 @@ QString AssistantModel::mapAccountCreatorUsernameStatusToString (linphone::Accou break; case linphone::AccountCreatorUsernameStatusInvalidCharacters: error = tr("usernameStatusInvalidCharacters") - .arg(::Utils::coreStringToAppString(config->getString("assistant", "username_regex", ""))); + .arg(Utils::coreStringToAppString(config->getString("assistant", "username_regex", ""))); break; case linphone::AccountCreatorUsernameStatusInvalid: error = tr("usernameStatusInvalid"); diff --git a/src/components/authentication/AuthenticationNotifier.cpp b/src/components/authentication/AuthenticationNotifier.cpp index 5933e303d..b0caa193c 100644 --- a/src/components/authentication/AuthenticationNotifier.cpp +++ b/src/components/authentication/AuthenticationNotifier.cpp @@ -20,15 +20,16 @@ * Author: Ronan Abhamon */ -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/Utils.hpp" #include "AuthenticationNotifier.hpp" -using namespace std; - // ============================================================================= +using namespace std; + AuthenticationNotifier::AuthenticationNotifier (QObject *parent) : QObject(parent) { QObject::connect( CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::authenticationRequested, @@ -39,12 +40,12 @@ AuthenticationNotifier::AuthenticationNotifier (QObject *parent) : QObject(paren void AuthenticationNotifier::handleAuthenticationRequested (const shared_ptr &authInfo) { emit authenticationRequested( QVariant::fromValue(authInfo), - ::Utils::coreStringToAppString(authInfo->getRealm()), + Utils::coreStringToAppString(authInfo->getRealm()), QStringLiteral("%1@%2").arg( - ::Utils::coreStringToAppString(authInfo->getUsername()) + Utils::coreStringToAppString(authInfo->getUsername()) ).arg( - ::Utils::coreStringToAppString(authInfo->getDomain()) + Utils::coreStringToAppString(authInfo->getDomain()) ), - ::Utils::coreStringToAppString(authInfo->getUserid()) + Utils::coreStringToAppString(authInfo->getUserid()) ); } diff --git a/src/components/authentication/AuthenticationNotifier.hpp b/src/components/authentication/AuthenticationNotifier.hpp index 49c4b026c..0d934820d 100644 --- a/src/components/authentication/AuthenticationNotifier.hpp +++ b/src/components/authentication/AuthenticationNotifier.hpp @@ -23,19 +23,22 @@ #ifndef AUTHENTICATION_NOTIFIER_H_ #define AUTHENTICATION_NOTIFIER_H_ -#include +#include + #include // ============================================================================= +namespace linphone { + class AuthInfo; +} + class AuthenticationNotifier : public QObject { Q_OBJECT; public: AuthenticationNotifier (QObject *parent = Q_NULLPTR); - ~AuthenticationNotifier () = default; - signals: void authenticationRequested (const QVariant &authInfo, const QString &realm, const QString &sipAddress, const QString &userId); @@ -43,6 +46,6 @@ private: void handleAuthenticationRequested (const std::shared_ptr &authInfo); }; -Q_DECLARE_METATYPE(std::shared_ptr ); +Q_DECLARE_METATYPE(std::shared_ptr); #endif // AUTHENTICATION_NOTIFIER_H_ diff --git a/src/components/call/CallModel.cpp b/src/components/call/CallModel.cpp index da9f759a5..262cee53a 100644 --- a/src/components/call/CallModel.cpp +++ b/src/components/call/CallModel.cpp @@ -24,7 +24,11 @@ #include #include "app/App.hpp" +#include "components/calls/CallsListModel.hpp" +#include "components/core/CoreHandlers.hpp" #include "components/core/CoreManager.hpp" +#include "components/notifier/Notifier.hpp" +#include "components/settings/SettingsModel.hpp" #include "utils/LinphoneUtils.hpp" #include "utils/Utils.hpp" @@ -35,8 +39,8 @@ using namespace std; namespace { - constexpr char cAutoAnswerObjectName[] = "auto-answer-timer"; - constexpr int cDtmfSoundDelay = 200; + constexpr char AutoAnswerObjectName[] = "auto-answer-timer"; + constexpr int DtmfSoundDelay = 200; } CallModel::CallModel (shared_ptr call) { @@ -56,7 +60,7 @@ CallModel::CallModel (shared_ptr call) { QTimer *timer = new QTimer(this); timer->setInterval(settings->getAutoAnswerDelay()); timer->setSingleShot(true); - timer->setObjectName(cAutoAnswerObjectName); + timer->setObjectName(AutoAnswerObjectName); QObject::connect(timer, &QTimer::timeout, this, &CallModel::acceptWithAutoAnswerDelay); timer->start(); @@ -81,14 +85,14 @@ CallModel::~CallModel () { // ----------------------------------------------------------------------------- QString CallModel::getSipAddress () const { - return ::Utils::coreStringToAppString(mCall->getRemoteAddress()->asString()); + return Utils::coreStringToAppString(mCall->getRemoteAddress()->asString()); } // ----------------------------------------------------------------------------- void CallModel::setRecordFile (shared_ptr &callParams) { callParams->setRecordFile( - ::Utils::appStringToCoreString( + Utils::appStringToCoreString( QStringLiteral("%1%2.mkv") .arg(CoreManager::getInstance()->getSettingsModel()->getSavedVideosFolder()) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")) @@ -185,7 +189,7 @@ void CallModel::askForTransfer () { } bool CallModel::transferTo (const QString &sipAddress) { - bool status = !!mCall->transfer(::Utils::appStringToCoreString(sipAddress)); + bool status = !!mCall->transfer(Utils::appStringToCoreString(sipAddress)); if (status) qWarning() << QStringLiteral("Unable to transfer: `%1`.").arg(sipAddress); return status; @@ -219,7 +223,7 @@ void CallModel::takeSnapshot () { qInfo() << QStringLiteral("Take snapshot of call:") << this; const QString filePath = CoreManager::getInstance()->getSettingsModel()->getSavedScreenshotsFolder() + newName; - mCall->takeVideoSnapshot(::Utils::appStringToCoreString(filePath)); + mCall->takeVideoSnapshot(Utils::appStringToCoreString(filePath)); App::getInstance()->getNotifier()->notifySnapshotWasTaken(filePath); } @@ -245,7 +249,7 @@ void CallModel::stopRecording () { mCall->stopRecording(); App::getInstance()->getNotifier()->notifyRecordingCompleted( - ::Utils::coreStringToAppString(mCall->getParams()->getRecordFile()) + Utils::coreStringToAppString(mCall->getParams()->getRecordFile()) ); emit recordingChanged(false); @@ -253,7 +257,7 @@ void CallModel::stopRecording () { // ----------------------------------------------------------------------------- -void CallModel::handleCallEncryptionChanged (const std::shared_ptr &call) { +void CallModel::handleCallEncryptionChanged (const shared_ptr &call) { if (call == mCall) emit securityUpdated(); } @@ -330,7 +334,7 @@ void CallModel::updateIsInConference () { // ----------------------------------------------------------------------------- void CallModel::stopAutoAnswerTimer () const { - QTimer *timer = findChild(cAutoAnswerObjectName, Qt::FindDirectChildrenOnly); + QTimer *timer = findChild(AutoAnswerObjectName, Qt::FindDirectChildrenOnly); if (timer) { timer->stop(); timer->deleteLater(); @@ -552,7 +556,7 @@ void CallModel::sendDtmf (const QString &dtmf) { const char key = dtmf.constData()[0].toLatin1(); qInfo() << QStringLiteral("Send dtmf: `%1`.").arg(key); mCall->sendDtmf(key); - CoreManager::getInstance()->getCore()->playDtmf(key, cDtmfSoundDelay); + CoreManager::getInstance()->getCore()->playDtmf(key, DtmfSoundDelay); } // ----------------------------------------------------------------------------- @@ -579,12 +583,12 @@ bool CallModel::isSecured () const { // ----------------------------------------------------------------------------- QString CallModel::getLocalSas () const { - QString token = ::Utils::coreStringToAppString(mCall->getAuthenticationToken()); + QString token = Utils::coreStringToAppString(mCall->getAuthenticationToken()); return mCall->getDir() == linphone::CallDirIncoming ? token.left(2).toUpper() : token.right(2).toUpper(); } QString CallModel::getRemoteSas () const { - QString token = ::Utils::coreStringToAppString(mCall->getAuthenticationToken()); + QString token = Utils::coreStringToAppString(mCall->getAuthenticationToken()); return mCall->getDir() != linphone::CallDirIncoming ? token.left(2).toUpper() : token.right(2).toUpper(); } @@ -654,42 +658,42 @@ void CallModel::updateStats (const shared_ptr &callSt statsList.clear(); - statsList << ::createStat(tr("callStatsCodec"), payloadType + statsList << createStat(tr("callStatsCodec"), payloadType ? QStringLiteral("%1 / %2kHz").arg(Utils::coreStringToAppString(payloadType->getMimeType())).arg(payloadType->getClockRate() / 1000) : QString("")); - statsList << ::createStat(tr("callStatsUploadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getUploadBandwidth()))); - statsList << ::createStat(tr("callStatsDownloadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getDownloadBandwidth()))); - statsList << ::createStat(tr("callStatsIceState"), iceStateToString(callStats->getIceState())); - statsList << ::createStat(tr("callStatsIpFamily"), family); - statsList << ::createStat(tr("callStatsSenderLossRate"), QStringLiteral("%1 %").arg(callStats->getSenderLossRate())); - statsList << ::createStat(tr("callStatsReceiverLossRate"), QStringLiteral("%1 %").arg(callStats->getReceiverLossRate())); + statsList << createStat(tr("callStatsUploadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getUploadBandwidth()))); + statsList << createStat(tr("callStatsDownloadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getDownloadBandwidth()))); + statsList << createStat(tr("callStatsIceState"), iceStateToString(callStats->getIceState())); + statsList << createStat(tr("callStatsIpFamily"), family); + statsList << createStat(tr("callStatsSenderLossRate"), QStringLiteral("%1 %").arg(callStats->getSenderLossRate())); + statsList << createStat(tr("callStatsReceiverLossRate"), QStringLiteral("%1 %").arg(callStats->getReceiverLossRate())); switch (callStats->getType()) { case linphone::StreamTypeAudio: - statsList << ::createStat(tr("callStatsJitterBuffer"), QStringLiteral("%1 ms").arg(callStats->getJitterBufferSizeMs())); + statsList << createStat(tr("callStatsJitterBuffer"), QStringLiteral("%1 ms").arg(callStats->getJitterBufferSizeMs())); break; case linphone::StreamTypeVideo: { - statsList << ::createStat(tr("callStatsEstimatedDownloadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getEstimatedDownloadBandwidth()))); - const QString sentVideoDefinitionName = ::Utils::coreStringToAppString(params->getSentVideoDefinition()->getName()); + statsList << createStat(tr("callStatsEstimatedDownloadBandwidth"), QStringLiteral("%1 kbits/s").arg(int(callStats->getEstimatedDownloadBandwidth()))); + const QString sentVideoDefinitionName = Utils::coreStringToAppString(params->getSentVideoDefinition()->getName()); const QString sentVideoDefinition = QStringLiteral("%1x%2") .arg(params->getSentVideoDefinition()->getWidth()) .arg(params->getSentVideoDefinition()->getHeight()); - statsList << ::createStat(tr("callStatsSentVideoDefinition"), sentVideoDefinition == sentVideoDefinitionName + statsList << createStat(tr("callStatsSentVideoDefinition"), sentVideoDefinition == sentVideoDefinitionName ? sentVideoDefinition : QStringLiteral("%1 (%2)").arg(sentVideoDefinition).arg(sentVideoDefinitionName)); - const QString receivedVideoDefinitionName = ::Utils::coreStringToAppString(params->getReceivedVideoDefinition()->getName()); + const QString receivedVideoDefinitionName = Utils::coreStringToAppString(params->getReceivedVideoDefinition()->getName()); const QString receivedVideoDefinition = QString("%1x%2") .arg(params->getReceivedVideoDefinition()->getWidth()) .arg(params->getReceivedVideoDefinition()->getHeight()); - statsList << ::createStat(tr("callStatsReceivedVideoDefinition"), receivedVideoDefinition == receivedVideoDefinitionName + statsList << createStat(tr("callStatsReceivedVideoDefinition"), receivedVideoDefinition == receivedVideoDefinitionName ? receivedVideoDefinition : QString("%1 (%2)").arg(receivedVideoDefinition).arg(receivedVideoDefinitionName)); - statsList << ::createStat(tr("callStatsReceivedFramerate"), QStringLiteral("%1 FPS").arg(params->getReceivedFramerate())); - statsList << ::createStat(tr("callStatsSentFramerate"), QStringLiteral("%1 FPS").arg(params->getSentFramerate())); + statsList << createStat(tr("callStatsReceivedFramerate"), QStringLiteral("%1 FPS").arg(params->getReceivedFramerate())); + statsList << createStat(tr("callStatsSentFramerate"), QStringLiteral("%1 FPS").arg(params->getSentFramerate())); } break; default: diff --git a/src/components/call/CallModel.hpp b/src/components/call/CallModel.hpp index 51f905982..fd882dcca 100644 --- a/src/components/call/CallModel.hpp +++ b/src/components/call/CallModel.hpp @@ -74,7 +74,6 @@ public: CallStatusOutgoing, CallStatusPaused }; - Q_ENUM(CallStatus); enum CallEncryption { @@ -83,7 +82,6 @@ public: CallEncryptionSrtp = linphone::MediaEncryptionSRTP, CallEncryptionZrtp = linphone::MediaEncryptionZRTP }; - Q_ENUM(CallEncryption); CallModel (std::shared_ptr call); diff --git a/src/components/calls/CallsListModel.cpp b/src/components/calls/CallsListModel.cpp index 5e0cfe0a0..0d961e8a3 100644 --- a/src/components/calls/CallsListModel.cpp +++ b/src/components/calls/CallsListModel.cpp @@ -21,22 +21,25 @@ */ #include +#include -#include "../../app/App.hpp" -#include "../../utils/Utils.hpp" -#include "../conference/ConferenceAddModel.hpp" -#include "../conference/ConferenceHelperModel.hpp" -#include "../core/CoreManager.hpp" +#include "app/App.hpp" +#include "components/call/CallModel.hpp" +#include "components/conference/ConferenceAddModel.hpp" +#include "components/conference/ConferenceHelperModel.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/Utils.hpp" #include "CallsListModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + namespace { - /* Delay before removing call in ms. */ - constexpr int cDelayBeforeRemoveCall = 3000; + // Delay before removing call in ms. + constexpr int DelayBeforeRemoveCall = 3000; } static inline int findCallIndex (QList &list, const shared_ptr &call) { @@ -96,7 +99,7 @@ void CallsListModel::askForTransfer (CallModel *callModel) { void CallsListModel::launchAudioCall (const QString &sipAddress, const QHash &headers) const { shared_ptr core = CoreManager::getInstance()->getCore(); - shared_ptr address = core->interpretUrl(::Utils::appStringToCoreString(sipAddress)); + shared_ptr address = core->interpretUrl(Utils::appStringToCoreString(sipAddress)); if (!address) return; @@ -107,7 +110,7 @@ void CallsListModel::launchAudioCall (const QString &sipAddress, const QHash iterator(headers); while (iterator.hasNext()) { iterator.next(); - params->addCustomHeader(::Utils::appStringToCoreString(iterator.key()), ::Utils::appStringToCoreString(iterator.value())); + params->addCustomHeader(Utils::appStringToCoreString(iterator.key()), Utils::appStringToCoreString(iterator.value())); } core->inviteAddressWithParams(address, params); @@ -121,7 +124,7 @@ void CallsListModel::launchVideoCall (const QString &sipAddress) const { return; } - shared_ptr address = core->interpretUrl(::Utils::appStringToCoreString(sipAddress)); + shared_ptr address = core->interpretUrl(Utils::appStringToCoreString(sipAddress)); if (!address) return; @@ -156,9 +159,9 @@ static void joinConference (const shared_ptr &call) { } shared_ptr conference = core->getConference(); - const QString conferenceId = ::Utils::coreStringToAppString(call->getToHeader("conference-id")); + const QString conferenceId = Utils::coreStringToAppString(call->getToHeader("conference-id")); - if (conference->getId() != ::Utils::appStringToCoreString(conferenceId)) { + if (conference->getId() != Utils::appStringToCoreString(conferenceId)) { qWarning() << QStringLiteral("Trying to join conference with an invalid conference id: `%1`. Responding as a simple call...") .arg(conferenceId); return; @@ -178,7 +181,7 @@ void CallsListModel::handleCallStateChanged (const shared_ptr &c switch (state) { case linphone::CallStateIncomingReceived: addCall(call); - ::joinConference(call); + joinConference(call); break; case linphone::CallStateOutgoingInit: @@ -191,7 +194,7 @@ void CallsListModel::handleCallStateChanged (const shared_ptr &c break; case linphone::CallStateStreamsRunning: { - int index = ::findCallIndex(mList, call); + int index = findCallIndex(mList, call); emit callRunning(index, &call->getData("call-model")); } break; @@ -232,9 +235,9 @@ void CallsListModel::addCall (const shared_ptr &call) { // This connection is (only) useful for `CallsListProxyModel`. QObject::connect(callModel, &CallModel::isInConferenceChanged, this, [this, callModel](bool) { - int id = ::findCallIndex(mList, *callModel); - emit dataChanged(index(id, 0), index(id, 0)); - }); + int id = findCallIndex(mList, *callModel); + emit dataChanged(index(id, 0), index(id, 0)); + }); int row = mList.count(); @@ -255,7 +258,7 @@ void CallsListModel::removeCall (const shared_ptr &call) { return; } - QTimer::singleShot(cDelayBeforeRemoveCall, this, [this, callModel] { + QTimer::singleShot(DelayBeforeRemoveCall, this, [this, callModel] { removeCallCb(callModel); }); } diff --git a/src/components/calls/CallsListModel.hpp b/src/components/calls/CallsListModel.hpp index daa2b5a7e..004b573e0 100644 --- a/src/components/calls/CallsListModel.hpp +++ b/src/components/calls/CallsListModel.hpp @@ -23,12 +23,12 @@ #ifndef CALLS_LIST_MODEL_H_ #define CALLS_LIST_MODEL_H_ +#include #include -#include "../call/CallModel.hpp" - // ============================================================================= +class CallModel; class CoreHandlers; class CallsListModel : public QAbstractListModel { @@ -36,7 +36,6 @@ class CallsListModel : public QAbstractListModel { public: CallsListModel (QObject *parent = Q_NULLPTR); - ~CallsListModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; diff --git a/src/components/calls/CallsListProxyModel.cpp b/src/components/calls/CallsListProxyModel.cpp index d0e324ea8..40fa13e15 100644 --- a/src/components/calls/CallsListProxyModel.cpp +++ b/src/components/calls/CallsListProxyModel.cpp @@ -20,20 +20,22 @@ * Author: Ronan Abhamon */ -#include "../core/CoreManager.hpp" +#include "components/call/CallModel.hpp" +#include "components/core/CoreManager.hpp" +#include "CallsListModel.hpp" #include "CallsListProxyModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + CallsListProxyModel::CallsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { CallsListModel *callsListModel = CoreManager::getInstance()->getCallsListModel(); QObject::connect(callsListModel, &CallsListModel::callRunning, this, [this](int index, CallModel *callModel) { - emit callRunning(index, callModel); - }); + emit callRunning(index, callModel); + }); setSourceModel(callsListModel); sort(0); diff --git a/src/components/calls/CallsListProxyModel.hpp b/src/components/calls/CallsListProxyModel.hpp index af90da05c..87429f085 100644 --- a/src/components/calls/CallsListProxyModel.hpp +++ b/src/components/calls/CallsListProxyModel.hpp @@ -25,16 +25,15 @@ #include -#include "../call/CallModel.hpp" - // ============================================================================= +class CallModel; + class CallsListProxyModel : public QSortFilterProxyModel { Q_OBJECT; public: CallsListProxyModel (QObject *parent = Q_NULLPTR); - ~CallsListProxyModel () = default; signals: void callRunning (int index, CallModel *callModel); diff --git a/src/components/camera/Camera.cpp b/src/components/camera/Camera.cpp index f5fbc8a02..be23f6613 100644 --- a/src/components/camera/Camera.cpp +++ b/src/components/camera/Camera.cpp @@ -25,17 +25,18 @@ #include #include -#include "../core/CoreManager.hpp" +#include "components/call/CallModel.hpp" +#include "components/core/CoreManager.hpp" #include "MSFunctions.hpp" #include "Camera.hpp" -using namespace std; - // ============================================================================= +using namespace std; + namespace { - constexpr int cMaxFps = 30; + constexpr int MaxFps = 30; } struct ContextInfo { @@ -186,7 +187,7 @@ Camera::Camera (QQuickItem *parent) : QQuickFramebufferObject(parent) { setMirrorVertically(true); mRefreshTimer = new QTimer(this); - mRefreshTimer->setInterval(1000 / cMaxFps); + mRefreshTimer->setInterval(1000 / MaxFps); QObject::connect( mRefreshTimer, &QTimer::timeout, diff --git a/src/components/camera/Camera.hpp b/src/components/camera/Camera.hpp index aba4eec3b..a87c90124 100644 --- a/src/components/camera/Camera.hpp +++ b/src/components/camera/Camera.hpp @@ -29,13 +29,13 @@ // ============================================================================= -class CallModel; -struct ContextInfo; - namespace linphone { class Call; } +class CallModel; +struct ContextInfo; + class CameraRenderer : public QQuickFramebufferObject::Renderer { public: CameraRenderer (); @@ -72,7 +72,6 @@ class Camera : public QQuickFramebufferObject { public: Camera (QQuickItem *parent = Q_NULLPTR); - ~Camera () = default; QQuickFramebufferObject::Renderer *createRenderer () const override; diff --git a/src/components/camera/CameraPreview.cpp b/src/components/camera/CameraPreview.cpp index 845b5b974..7acc534d6 100644 --- a/src/components/camera/CameraPreview.cpp +++ b/src/components/camera/CameraPreview.cpp @@ -25,17 +25,17 @@ #include #include -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" #include "MSFunctions.hpp" #include "CameraPreview.hpp" -using namespace std; - // ============================================================================= +using namespace std; + namespace { - constexpr int cMaxFps = 30; + constexpr int MaxFps = 30; } struct ContextInfo { @@ -130,7 +130,7 @@ void CameraPreviewRenderer::updateWindowId () { // ----------------------------------------------------------------------------- QMutex CameraPreview::mCounterMutex; -int CameraPreview::mCounter = 0; +int CameraPreview::mCounter; // ----------------------------------------------------------------------------- @@ -144,7 +144,7 @@ CameraPreview::CameraPreview (QQuickItem *parent) : QQuickFramebufferObject(pare setMirrorVertically(true); mRefreshTimer = new QTimer(this); - mRefreshTimer->setInterval(1000 / cMaxFps); + mRefreshTimer->setInterval(1000 / MaxFps); QObject::connect( mRefreshTimer, &QTimer::timeout, diff --git a/src/components/camera/MSFunctions.cpp b/src/components/camera/MSFunctions.cpp index 1ac60a040..f06d51665 100644 --- a/src/components/camera/MSFunctions.cpp +++ b/src/components/camera/MSFunctions.cpp @@ -27,7 +27,7 @@ // ============================================================================= -MSFunctions *MSFunctions::mInstance = nullptr; +MSFunctions *MSFunctions::mInstance; // ----------------------------------------------------------------------------- diff --git a/src/components/chat/ChatModel.cpp b/src/components/chat/ChatModel.cpp index 2f13f8bdf..b7dc7075d 100644 --- a/src/components/chat/ChatModel.cpp +++ b/src/components/chat/ChatModel.cpp @@ -25,59 +25,59 @@ #include #include #include +#include #include #include -#include -#include "../../app/App.hpp" -#include "../../app/paths/Paths.hpp" -#include "../../app/providers/ThumbnailProvider.hpp" -#include "../../utils/Utils.hpp" -#include "../../utils/QExifImageHeader.h" -#include "../core/CoreManager.hpp" +#include "app/App.hpp" +#include "app/paths/Paths.hpp" +#include "app/providers/ThumbnailProvider.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "components/notifier/Notifier.hpp" +#include "components/settings/SettingsModel.hpp" +#include "utils/QExifImageHeader.h" +#include "utils/Utils.hpp" #include "ChatModel.hpp" -#define THUMBNAIL_IMAGE_FILE_HEIGHT 100 -#define THUMBNAIL_IMAGE_FILE_WIDTH 100 - -// Not enabled by default. -#ifndef LIMIT_FILE_SIZE - #define LIMIT_FILE_SIZE 0 -#endif - -// In Bytes. (500) -#define FILE_SIZE_LIMIT 524288000 +// ============================================================================= using namespace std; -// ============================================================================= +namespace { + constexpr int ThumbnailImageFileWidth = 100; + constexpr int ThumbnailImageFileHeight = 100; + + // In Bytes. + constexpr qint64 FileSizeLimit = 524288000; +} static inline QString getFileId (const shared_ptr &message) { - return ::Utils::coreStringToAppString(message->getAppdata()).section(':', 0, 0); + return Utils::coreStringToAppString(message->getAppdata()).section(':', 0, 0); } static inline QString getDownloadPath (const shared_ptr &message) { - return ::Utils::coreStringToAppString(message->getAppdata()).section(':', 1); + return Utils::coreStringToAppString(message->getAppdata()).section(':', 1); } static inline bool fileWasDownloaded (const shared_ptr &message) { - const QString path = ::getDownloadPath(message); + const QString path = getDownloadPath(message); return !path.isEmpty() && QFileInfo(path).isFile(); } static inline void fillThumbnailProperty (QVariantMap &dest, const shared_ptr &message) { - QString fileId = ::getFileId(message); + QString fileId = getFileId(message); if (!fileId.isEmpty() && !dest.contains("thumbnail")) dest["thumbnail"] = QStringLiteral("image://%1/%2") - .arg(ThumbnailProvider::PROVIDER_ID).arg(fileId); + .arg(ThumbnailProvider::ProviderId).arg(fileId); } static inline void createThumbnail (const shared_ptr &message) { if (!message->getAppdata().empty()) return; - QString thumbnailPath = ::Utils::coreStringToAppString(message->getFileTransferFilepath()); + QString thumbnailPath = Utils::coreStringToAppString(message->getFileTransferFilepath()); QImage image(thumbnailPath); if (image.isNull()) return; @@ -88,9 +88,9 @@ static inline void createThumbnail (const shared_ptr &mes rotation = int(exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort()); QImage thumbnail = image.scaled( - THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT, - Qt::KeepAspectRatio, Qt::SmoothTransformation - ); + ThumbnailImageFileWidth, ThumbnailImageFileHeight, + Qt::KeepAspectRatio, Qt::SmoothTransformation + ); if (rotation != 0) { QTransform transform; @@ -109,12 +109,12 @@ static inline void createThumbnail (const shared_ptr &mes QString uuid = QUuid::createUuid().toString(); QString fileId = QStringLiteral("%1.jpg").arg(uuid.mid(1, uuid.length() - 2)); - if (!thumbnail.save(::Utils::coreStringToAppString(Paths::getThumbnailsDirPath()) + fileId, "jpg", 100)) { + if (!thumbnail.save(Utils::coreStringToAppString(Paths::getThumbnailsDirPath()) + fileId, "jpg", 100)) { qWarning() << QStringLiteral("Unable to create thumbnail of: `%1`.").arg(thumbnailPath); return; } - message->setAppdata(::Utils::appStringToCoreString(fileId)); + message->setAppdata(Utils::appStringToCoreString(fileId)); } static inline void removeFileMessageThumbnail (const shared_ptr &message) { @@ -123,7 +123,7 @@ static inline void removeFileMessageThumbnail (const shared_ptrgetAppdata(); if (!fileId.empty()) { - QString thumbnailPath = ::Utils::coreStringToAppString(Paths::getThumbnailsDirPath() + fileId); + QString thumbnailPath = Utils::coreStringToAppString(Paths::getThumbnailsDirPath() + fileId); if (!QFile::remove(thumbnailPath)) qWarning() << QStringLiteral("Unable to remove `%1`.").arg(thumbnailPath); } @@ -138,8 +138,6 @@ class ChatModel::MessageHandlers : public linphone::ChatMessageListener { public: MessageHandlers (ChatModel *chatModel) : mChatModel(chatModel) {} - ~MessageHandlers () = default; - private: QList::iterator findMessageEntry (const shared_ptr &message) { return find_if(mChatModel->mEntries.begin(), mChatModel->mEntries.end(), [&message](const ChatEntryData &pair) { @@ -190,11 +188,11 @@ private: // File message downloaded. if (state == linphone::ChatMessageStateFileTransferDone && !message->isOutgoing()) { - ::createThumbnail(message); - ::fillThumbnailProperty((*it).first, message); + createThumbnail(message); + fillThumbnailProperty((*it).first, message); message->setAppdata( - ::Utils::appStringToCoreString(::getFileId(message)) + ':' + message->getFileTransferFilepath() + Utils::appStringToCoreString(getFileId(message)) + ':' + message->getFileTransferFilepath() ); (*it).first["wasDownloaded"] = true; @@ -284,7 +282,7 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) { } QString ChatModel::getSipAddress () const { - return ::Utils::coreStringToAppString( + return Utils::coreStringToAppString( mChatRoom->getPeerAddress()->asStringUriOnly() ); } @@ -292,7 +290,7 @@ QString ChatModel::getSipAddress () const { void ChatModel::setSipAddress (const QString &sipAddress) { shared_ptr core = CoreManager::getInstance()->getCore(); - mChatRoom = core->getChatRoomFromUri(::Utils::appStringToCoreString(sipAddress)); + mChatRoom = core->getChatRoomFromUri(Utils::appStringToCoreString(sipAddress)); Q_CHECK_PTR(mChatRoom.get()); handleIsComposingChanged(mChatRoom); @@ -348,7 +346,7 @@ void ChatModel::removeAllEntries () { // ----------------------------------------------------------------------------- void ChatModel::sendMessage (const QString &message) { - shared_ptr _message = mChatRoom->createMessage(::Utils::appStringToCoreString(message)); + shared_ptr _message = mChatRoom->createMessage(Utils::appStringToCoreString(message)); _message->setListener(mMessageHandlers); insertMessageAtEnd(_message); @@ -392,13 +390,10 @@ void ChatModel::sendFileMessage (const QString &path) { return; qint64 fileSize = file.size(); - - #if LIMIT_FILE_SIZE - if (fileSize > FILE_SIZE_LIMIT) { - qWarning() << QStringLiteral("Unable to send file. (Size limit=%1)").arg(FILE_SIZE_LIMIT); - return; - } - #endif + if (fileSize > FileSizeLimit) { + qWarning() << QStringLiteral("Unable to send file. (Size limit=%1)").arg(FileSizeLimit); + return; + } shared_ptr content = CoreManager::getInstance()->getCore()->createContent(); { @@ -407,18 +402,18 @@ void ChatModel::sendFileMessage (const QString &path) { qWarning() << QStringLiteral("Unable to get supported mime type for: `%1`.").arg(path); return; } - content->setType(::Utils::appStringToCoreString(mimeType[0])); - content->setSubtype(::Utils::appStringToCoreString(mimeType[1])); + content->setType(Utils::appStringToCoreString(mimeType[0])); + content->setSubtype(Utils::appStringToCoreString(mimeType[1])); } content->setSize(size_t(fileSize)); - content->setName(::Utils::appStringToCoreString(QFileInfo(file).fileName())); + content->setName(Utils::appStringToCoreString(QFileInfo(file).fileName())); shared_ptr message = mChatRoom->createFileTransferMessage(content); - message->setFileTransferFilepath(::Utils::appStringToCoreString(path)); + message->setFileTransferFilepath(Utils::appStringToCoreString(path)); message->setListener(mMessageHandlers); - ::createThumbnail(message); + createThumbnail(message); insertMessageAtEnd(message); mChatRoom->sendChatMessage(message); @@ -448,7 +443,7 @@ void ChatModel::downloadFile (int id) { } bool soFarSoGood; - const QString safeFilePath = ::Utils::getSafeFilePath( + const QString safeFilePath = Utils::getSafeFilePath( QStringLiteral("%1%2") .arg(CoreManager::getInstance()->getSettingsModel()->getDownloadFolder()) .arg(entry.first["fileName"].toString()), @@ -460,7 +455,7 @@ void ChatModel::downloadFile (int id) { return; } - message->setFileTransferFilepath(::Utils::appStringToCoreString(safeFilePath)); + message->setFileTransferFilepath(Utils::appStringToCoreString(safeFilePath)); message->setListener(mMessageHandlers); if (message->downloadFile() < 0) @@ -478,7 +473,7 @@ void ChatModel::openFile (int id, bool showDirectory) { return; } - QFileInfo info(::getDownloadPath(message)); + QFileInfo info(getDownloadPath(message)); QDesktopServices::openUrl( QUrl(QStringLiteral("file:///%1").arg(showDirectory ? info.absolutePath() : info.absoluteFilePath())) ); @@ -528,17 +523,17 @@ const ChatModel::ChatEntryData ChatModel::getFileMessageEntry (int id) { void ChatModel::fillMessageEntry (QVariantMap &dest, const shared_ptr &message) { dest["type"] = EntryType::MessageEntry; dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000); - dest["content"] = ::Utils::coreStringToAppString(message->getText()); + dest["content"] = Utils::coreStringToAppString(message->getText()); dest["isOutgoing"] = message->isOutgoing() || message->getState() == linphone::ChatMessageStateIdle; dest["status"] = message->getState(); shared_ptr content = message->getFileTransferInformation(); if (content) { dest["fileSize"] = quint64(content->getSize()); - dest["fileName"] = ::Utils::coreStringToAppString(content->getName()); + dest["fileName"] = Utils::coreStringToAppString(content->getName()); dest["wasDownloaded"] = ::fileWasDownloaded(message); - ::fillThumbnailProperty(dest, message); + fillThumbnailProperty(dest, message); } } @@ -570,7 +565,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) { switch (type) { case ChatModel::MessageEntry: { shared_ptr message = static_pointer_cast(pair.second); - ::removeFileMessageThumbnail(message); + removeFileMessageThumbnail(message); mChatRoom->deleteMessage(message); break; } diff --git a/src/components/chat/ChatModel.hpp b/src/components/chat/ChatModel.hpp index 7d646e061..0d36dcc6d 100644 --- a/src/components/chat/ChatModel.hpp +++ b/src/components/chat/ChatModel.hpp @@ -48,7 +48,6 @@ public: MessageEntry, CallEntry }; - Q_ENUM(EntryType); enum CallStatus { @@ -56,7 +55,6 @@ public: CallStatusMissed = linphone::CallStatusMissed, CallStatusSuccess = linphone::CallStatusSuccess }; - Q_ENUM(CallStatus); enum MessageStatus { @@ -69,7 +67,6 @@ public: MessageStatusInProgress = linphone::ChatMessageStateInProgress, MessageStatusNotDelivered = linphone::ChatMessageStateNotDelivered }; - Q_ENUM(MessageStatus); ChatModel (const QString &sipAddress); @@ -119,7 +116,7 @@ signals: void messagesCountReset (); private: - typedef QPair > ChatEntryData; + typedef QPair> ChatEntryData; void setSipAddress (const QString &sipAddress); diff --git a/src/components/chat/ChatProxyModel.cpp b/src/components/chat/ChatProxyModel.cpp index 8449b0631..ed9b6bea7 100644 --- a/src/components/chat/ChatProxyModel.cpp +++ b/src/components/chat/ChatProxyModel.cpp @@ -20,14 +20,14 @@ * Author: Ronan Abhamon */ -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" #include "ChatProxyModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + // Fetch the L last filtered chat entries. class ChatProxyModel::ChatModelFilter : public QSortFilterProxyModel { public: @@ -59,8 +59,6 @@ private: // ============================================================================= -const int ChatProxyModel::ENTRIES_CHUNK_SIZE = 50; - ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(new ChatModelFilter(this)); } @@ -117,7 +115,7 @@ void ChatProxyModel::loadMoreEntries () { // Do not increase `mMaxDisplayedEntries` if it's not necessary... // Limit qml calls. if (count == mMaxDisplayedEntries) - mMaxDisplayedEntries += ENTRIES_CHUNK_SIZE; + mMaxDisplayedEntries += EntriesChunkSize; invalidateFilter(); @@ -149,7 +147,7 @@ QString ChatProxyModel::getSipAddress () const { } void ChatProxyModel::setSipAddress (const QString &sipAddress) { - mMaxDisplayedEntries = ENTRIES_CHUNK_SIZE; + mMaxDisplayedEntries = EntriesChunkSize; if (mChatModel) { ChatModel *chatModel = mChatModel.get(); diff --git a/src/components/chat/ChatProxyModel.hpp b/src/components/chat/ChatProxyModel.hpp index 1bb693f3b..285647f44 100644 --- a/src/components/chat/ChatProxyModel.hpp +++ b/src/components/chat/ChatProxyModel.hpp @@ -78,11 +78,11 @@ private: void handleMessageReceived (const std::shared_ptr &message); void handleMessageSent (const std::shared_ptr &message); - int mMaxDisplayedEntries = ENTRIES_CHUNK_SIZE; + int mMaxDisplayedEntries = EntriesChunkSize; std::shared_ptr mChatModel; - static const int ENTRIES_CHUNK_SIZE; + static constexpr int EntriesChunkSize = 50; }; #endif // CHAT_PROXY_MODEL_H_ diff --git a/src/components/codecs/AbstractCodecsModel.hpp b/src/components/codecs/AbstractCodecsModel.hpp index a8b98b979..bb5ce75a2 100644 --- a/src/components/codecs/AbstractCodecsModel.hpp +++ b/src/components/codecs/AbstractCodecsModel.hpp @@ -40,7 +40,6 @@ class AbstractCodecsModel : public QAbstractListModel { public: AbstractCodecsModel (QObject *parent = Q_NULLPTR); - virtual ~AbstractCodecsModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; @@ -81,6 +80,6 @@ protected: QList mCodecs; }; -Q_DECLARE_METATYPE(std::shared_ptr ); +Q_DECLARE_METATYPE(std::shared_ptr); #endif // ABSTRACT_CODECS_MODEL_H_ diff --git a/src/components/codecs/AudioCodecsModel.cpp b/src/components/codecs/AudioCodecsModel.cpp index 8f2e19981..5ceba7524 100644 --- a/src/components/codecs/AudioCodecsModel.cpp +++ b/src/components/codecs/AudioCodecsModel.cpp @@ -20,7 +20,7 @@ * Author: Ronan Abhamon */ -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" #include "AudioCodecsModel.hpp" diff --git a/src/components/codecs/VideoCodecsModel.cpp b/src/components/codecs/VideoCodecsModel.cpp index 0c3932a35..119dac005 100644 --- a/src/components/codecs/VideoCodecsModel.cpp +++ b/src/components/codecs/VideoCodecsModel.cpp @@ -37,23 +37,23 @@ using namespace std; namespace { - constexpr char cH264Description[] = "Provided by CISCO SYSTEM,INC"; + constexpr char H264Description[] = "Provided by CISCO SYSTEM,INC"; #ifdef Q_OS_LINUX - constexpr char cLibraryExtension[] = "so"; - constexpr char cH264InstallName[] = "libopenh264.so"; + constexpr char LibraryExtension[] = "so"; + constexpr char H264InstallName[] = "libopenh264.so"; #ifdef Q_PROCESSOR_X86_64 - constexpr char cPluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-1.7.0-linux64.4.so.bz2"; + constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-1.7.0-linux64.4.so.bz2"; #else - constexpr char cPluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-1.7.0-linux32.4.so.bz2"; + constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-1.7.0-linux32.4.so.bz2"; #endif // ifdef Q_PROCESSOR_X86_64 #elif defined(Q_OS_WIN) - constexpr char cLibraryExtension[] = "dll"; - constexpr char cH264InstallName[] = "openh264.dll"; + constexpr char LibraryExtension[] = "dll"; + constexpr char H264InstallName[] = "openh264.dll"; #ifdef Q_OS_WIN64 - constexpr char cPluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-1.7.0-win64.dll.bz2"; + constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-1.7.0-win64.dll.bz2"; #else - constexpr char cPluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-1.7.0-win32.dll.bz2"; + constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-1.7.0-win32.dll.bz2"; #endif // ifdef Q_OS_WIN64 #endif // ifdef Q_OS_LINUX } @@ -127,7 +127,7 @@ static bool downloadUpdatableCodec ( void VideoCodecsModel::updateCodecs () { #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - static const QString codecSuffix = QStringLiteral(".%1").arg(cLibraryExtension); + static const QString codecSuffix = QStringLiteral(".%1").arg(LibraryExtension); QDirIterator it(Utils::coreStringToAppString(Paths::getCodecsDirPath())); while (it.hasNext()) { @@ -147,7 +147,7 @@ void VideoCodecsModel::updateCodecs () { void VideoCodecsModel::downloadUpdatableCodecs (QObject *parent) { #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) QString codecsFolder = Utils::coreStringToAppString(Paths::getCodecsDirPath()); - downloadUpdatableCodec(parent, codecsFolder, "H264", cPluginUrlH264, cH264InstallName); + downloadUpdatableCodec(parent, codecsFolder, "H264", PluginUrlH264, H264InstallName); #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) } @@ -165,7 +165,7 @@ void VideoCodecsModel::load () { QDirIterator it(Utils::coreStringToAppString(Paths::getCodecsDirPath())); while (it.hasNext()) { QFileInfo info(it.next()); - if (info.suffix() == cLibraryExtension) + if (info.suffix() == LibraryExtension) QLibrary(info.filePath()).load(); } core->reloadMsPlugins(""); @@ -181,7 +181,7 @@ void VideoCodecsModel::load () { if (find_if(codecs.begin(), codecs.end(), [](const shared_ptr &codec) { return codec->getMimeType() == "H264"; }) == codecs.end()) - addDownloadableCodec("H264", cH264Description, cPluginUrlH264, cH264InstallName); + addDownloadableCodec("H264", H264Description, PluginUrlH264, H264InstallName); #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) } diff --git a/src/components/conference/ConferenceAddModel.cpp b/src/components/conference/ConferenceAddModel.cpp index cd59690ac..1e3bea103 100644 --- a/src/components/conference/ConferenceAddModel.cpp +++ b/src/components/conference/ConferenceAddModel.cpp @@ -20,15 +20,16 @@ * Author: Ronan Abhamon */ -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" +#include "components/sip-addresses/SipAddressesModel.hpp" +#include "utils/Utils.hpp" #include "ConferenceAddModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + ConferenceHelperModel::ConferenceAddModel::ConferenceAddModel (QObject *parent) : QAbstractListModel(parent) { mConferenceHelperModel = qobject_cast(parent); Q_CHECK_PTR(mConferenceHelperModel); @@ -71,7 +72,7 @@ QVariant ConferenceHelperModel::ConferenceAddModel::data (const QModelIndex &ind // ----------------------------------------------------------------------------- bool ConferenceHelperModel::ConferenceAddModel::addToConference (const shared_ptr &linphoneAddress) { - const QString sipAddress = ::Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); + const QString sipAddress = Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); if (mSipAddresses.contains(sipAddress)) return false; @@ -91,8 +92,8 @@ bool ConferenceHelperModel::ConferenceAddModel::addToConference (const QString & return false; shared_ptr address = CoreManager::getInstance()->getCore()->interpretUrl( - ::Utils::appStringToCoreString(sipAddress) - ); + Utils::appStringToCoreString(sipAddress) + ); if (!address) return false; @@ -133,9 +134,9 @@ bool ConferenceHelperModel::ConferenceAddModel::removeFromConference (const QStr // ----------------------------------------------------------------------------- void ConferenceHelperModel::ConferenceAddModel::update () { - list > linphoneAddresses; + list> linphoneAddresses; for (const auto &map : mRefs) { - shared_ptr linphoneAddress = map->value("__linphoneAddress").value >(); + shared_ptr linphoneAddress = map->value("__linphoneAddress").value>(); Q_CHECK_PTR(linphoneAddress); linphoneAddresses.push_back(linphoneAddress); } @@ -147,7 +148,7 @@ void ConferenceHelperModel::ConferenceAddModel::update () { if (!call->getParams()->getLocalConferenceMode()) continue; - const QString sipAddress = ::Utils::coreStringToAppString(call->getRemoteAddress()->asStringUriOnly()); + const QString sipAddress = Utils::coreStringToAppString(call->getRemoteAddress()->asStringUriOnly()); if (!mSipAddresses.contains(sipAddress)) call->terminate(); } @@ -161,7 +162,7 @@ void ConferenceHelperModel::ConferenceAddModel::update () { // ----------------------------------------------------------------------------- void ConferenceHelperModel::ConferenceAddModel::addToConferencePrivate (const shared_ptr &linphoneAddress) { - QString sipAddress = ::Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); + QString sipAddress = Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); QVariantMap map = CoreManager::getInstance()->getSipAddressesModel()->find(sipAddress); map["sipAddress"] = sipAddress; diff --git a/src/components/conference/ConferenceAddModel.hpp b/src/components/conference/ConferenceAddModel.hpp index 9503063b0..6854f0666 100644 --- a/src/components/conference/ConferenceAddModel.hpp +++ b/src/components/conference/ConferenceAddModel.hpp @@ -38,7 +38,6 @@ class ConferenceHelperModel::ConferenceAddModel : public QAbstractListModel { public: ConferenceAddModel (QObject *parent = Q_NULLPTR); - ~ConferenceAddModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; @@ -71,6 +70,6 @@ private: ConferenceHelperModel *mConferenceHelperModel = nullptr; }; -Q_DECLARE_METATYPE(std::shared_ptr ); +Q_DECLARE_METATYPE(std::shared_ptr); #endif // CONFERENCE_ADD_MODEL_H_ diff --git a/src/components/conference/ConferenceHelperModel.cpp b/src/components/conference/ConferenceHelperModel.cpp index efae2990a..45c519f46 100644 --- a/src/components/conference/ConferenceHelperModel.cpp +++ b/src/components/conference/ConferenceHelperModel.cpp @@ -20,18 +20,21 @@ * Author: Ronan Abhamon */ -#include "../../app/App.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" -#include "../sip-addresses/SipAddressesProxyModel.hpp" -#include "ConferenceAddModel.hpp" +#include +#include "app/App.hpp" +#include "components/calls/CallsListModel.hpp" +#include "components/core/CoreManager.hpp" +#include "components/sip-addresses/SipAddressesProxyModel.hpp" +#include "utils/Utils.hpp" + +#include "ConferenceAddModel.hpp" #include "ConferenceHelperModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + ConferenceHelperModel::ConferenceHelperModel (QObject *parent) : QSortFilterProxyModel(parent) { mCore = CoreManager::getInstance()->getCore(); mConference = mCore->getConference(); @@ -77,11 +80,11 @@ bool ConferenceHelperModel::filterAcceptsRow (int sourceRow, const QModelIndex & bool ConferenceHelperModel::lessThan (const QModelIndex &left, const QModelIndex &right) const { shared_ptr callA = mCore->findCallFromUri( - ::Utils::appStringToCoreString(left.data().toMap()["sipAddress"].toString()) - ); + Utils::appStringToCoreString(left.data().toMap()["sipAddress"].toString()) + ); shared_ptr callB = mCore->findCallFromUri( - ::Utils::appStringToCoreString(right.data().toMap()["sipAddress"].toString()) - ); + Utils::appStringToCoreString(right.data().toMap()["sipAddress"].toString()) + ); return callA && !callB; } diff --git a/src/components/conference/ConferenceHelperModel.hpp b/src/components/conference/ConferenceHelperModel.hpp index cc0e1a20e..93fa8aa7d 100644 --- a/src/components/conference/ConferenceHelperModel.hpp +++ b/src/components/conference/ConferenceHelperModel.hpp @@ -32,13 +32,13 @@ // Can filter the sip addresses with a pattern. // ============================================================================= -class CallModel; - namespace linphone { -class Conference; -class Core; + class Conference; + class Core; } +class CallModel; + class ConferenceHelperModel : public QSortFilterProxyModel { Q_OBJECT; @@ -48,7 +48,6 @@ public: class ConferenceAddModel; ConferenceHelperModel (QObject *parent = Q_NULLPTR); - ~ConferenceHelperModel () = default; QHash roleNames () const override; diff --git a/src/components/conference/ConferenceModel.cpp b/src/components/conference/ConferenceModel.cpp index 0f7805077..ba751ccea 100644 --- a/src/components/conference/ConferenceModel.cpp +++ b/src/components/conference/ConferenceModel.cpp @@ -22,16 +22,20 @@ #include -#include "../../utils/LinphoneUtils.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/call/CallModel.hpp" +#include "components/calls/CallsListModel.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "components/settings/SettingsModel.hpp" +#include "utils/LinphoneUtils.hpp" +#include "utils/Utils.hpp" #include "ConferenceModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + ConferenceModel::ConferenceModel (QObject *parent) : QSortFilterProxyModel(parent) { QObject::connect(this, &ConferenceModel::rowsRemoved, [this] { emit countChanged(rowCount()); @@ -77,7 +81,7 @@ void ConferenceModel::startRecording () { CoreManager *coreManager = CoreManager::getInstance(); coreManager->getCore()->startConferenceRecording( - ::Utils::appStringToCoreString( + Utils::appStringToCoreString( QStringLiteral("%1%2.mkv") .arg(coreManager->getSettingsModel()->getSavedVideosFolder()) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")) diff --git a/src/components/conference/ConferenceModel.hpp b/src/components/conference/ConferenceModel.hpp index ea5e2f1a6..25f1ed385 100644 --- a/src/components/conference/ConferenceModel.hpp +++ b/src/components/conference/ConferenceModel.hpp @@ -42,7 +42,6 @@ class ConferenceModel : public QSortFilterProxyModel { public: ConferenceModel (QObject *parent = Q_NULLPTR); - ~ConferenceModel () = default; protected: bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override; diff --git a/src/components/contact/ContactModel.cpp b/src/components/contact/ContactModel.cpp index 7913f068b..c1ad21576 100644 --- a/src/components/contact/ContactModel.cpp +++ b/src/components/contact/ContactModel.cpp @@ -20,14 +20,17 @@ * Author: Ronan Abhamon */ -#include "../../app/App.hpp" +#include + +#include "app/App.hpp" #include "ContactModel.hpp" - -using namespace std; +#include "VcardModel.hpp" // ============================================================================= +using namespace std; + ContactModel::ContactModel (QObject *parent, shared_ptr linphoneFriend) : QObject(parent) { Q_CHECK_PTR(linphoneFriend); @@ -53,8 +56,8 @@ ContactModel::ContactModel (QObject *parent, VcardModel *vcardModel) : QObject(p void ContactModel::refreshPresence () { Presence::PresenceStatus status = static_cast( - mLinphoneFriend->getConsolidatedPresence() - ); + mLinphoneFriend->getConsolidatedPresence() + ); emit presenceStatusChanged(status); emit presenceLevelChanged(Presence::getPresenceLevel(status)); @@ -160,7 +163,7 @@ void ContactModel::mergeVcardModel (VcardModel *vcardModel) { const QVariantMap oldAddress = vcardModel->getAddress(); QVariantMap newAddress = vcardModel->getAddress(); - static const char *attributes[4] = { "street", "locality", "postalCode", "country" }; + constexpr const char *attributes[4] = { "street", "locality", "postalCode", "country" }; bool needMerge = true; for (const auto &attribute : attributes) diff --git a/src/components/contact/ContactModel.hpp b/src/components/contact/ContactModel.hpp index c35d97f93..46c109b62 100644 --- a/src/components/contact/ContactModel.hpp +++ b/src/components/contact/ContactModel.hpp @@ -23,27 +23,27 @@ #ifndef CONTACT_MODEL_H_ #define CONTACT_MODEL_H_ -#include "../presence/Presence.hpp" -#include "VcardModel.hpp" +#include "components/presence/Presence.hpp" // ============================================================================= +class VcardModel; + class ContactModel : public QObject { + // Grant access to `mLinphoneFriend`. + friend class ContactsListModel; + friend class ContactsListProxyModel; + friend class SipAddressesProxyModel; + Q_OBJECT; Q_PROPERTY(Presence::PresenceStatus presenceStatus READ getPresenceStatus NOTIFY presenceStatusChanged); Q_PROPERTY(Presence::PresenceLevel presenceLevel READ getPresenceLevel NOTIFY presenceLevelChanged); Q_PROPERTY(VcardModel * vcard READ getVcardModel WRITE setVcardModel NOTIFY contactUpdated); - // Grant access to `mLinphoneFriend`. - friend class ContactsListModel; - friend class ContactsListProxyModel; - friend class SipAddressesProxyModel; - public: ContactModel (QObject *parent, std::shared_ptr linphoneFriend); ContactModel (QObject *parent, VcardModel *vcardModel); - ~ContactModel () = default; void refreshPresence (); diff --git a/src/components/contact/VcardModel.cpp b/src/components/contact/VcardModel.cpp index 943cfa64c..1a8c729c5 100644 --- a/src/components/contact/VcardModel.cpp +++ b/src/components/contact/VcardModel.cpp @@ -25,43 +25,45 @@ #include #include -#include "../../app/App.hpp" -#include "../../app/paths/Paths.hpp" -#include "../../app/providers/AvatarProvider.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "app/App.hpp" +#include "app/paths/Paths.hpp" +#include "app/providers/AvatarProvider.hpp" +#include "components/core/CoreManager.hpp" +#include "components/sip-addresses/SipAddressesModel.hpp" +#include "utils/Utils.hpp" #include "VcardModel.hpp" -#define VCARD_SCHEME "linphone-desktop:/" - -#define CHECK_VCARD_IS_WRITABLE(VCARD) Q_ASSERT(VCARD->mIsReadOnly == false) +// ============================================================================= using namespace std; -// ============================================================================= +#define CHECK_VCARD_IS_WRITABLE(VCARD) Q_ASSERT(VCARD->mIsReadOnly == false) + +namespace { + constexpr char VcardScheme[] = "linphone-desktop:/"; +} template -static inline shared_ptr findBelCardValue (const list > &list, const string &value) { +static inline shared_ptr findBelCardValue (const list> &list, const string &value) { auto it = find_if(list.cbegin(), list.cend(), [&value](const shared_ptr &entry) { - return value == entry->getValue(); - }); - + return value == entry->getValue(); + }); return it != list.cend() ? *it : nullptr; } template -static inline shared_ptr findBelCardValue (const list > &list, const QString &value) { - return ::findBelCardValue(list, ::Utils::appStringToCoreString(value)); +static inline shared_ptr findBelCardValue (const list> &list, const QString &value) { + return findBelCardValue(list, Utils::appStringToCoreString(value)); } static inline bool isLinphoneDesktopPhoto (const shared_ptr &photo) { - return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME); + return !photo->getValue().compare(0, sizeof(VcardScheme) - 1, VcardScheme); } static shared_ptr findBelcardPhoto (const shared_ptr &belcard) { - const list > &photos = belcard->getPhotos(); - auto it = find_if(photos.cbegin(), photos.cend(), ::isLinphoneDesktopPhoto); + const list> &photos = belcard->getPhotos(); + auto it = find_if(photos.cbegin(), photos.cend(), isLinphoneDesktopPhoto); if (it != photos.cend()) return *it; @@ -69,16 +71,16 @@ static shared_ptr findBelcardPhoto (const shared_ptr &belcard, bool cleanPathsOnly = false) { - list > photos; + list> photos; for (const auto photo : belcard->getPhotos()) { - if (::isLinphoneDesktopPhoto(photo)) + if (isLinphoneDesktopPhoto(photo)) photos.push_back(photo); } for (const auto photo : photos) { QString imagePath( - ::Utils::coreStringToAppString( - Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(VCARD_SCHEME) - 1) + Utils::coreStringToAppString( + Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(VcardScheme) - 1) ) ); @@ -105,7 +107,7 @@ VcardModel::~VcardModel () { if (!mIsReadOnly) { qInfo() << QStringLiteral("Destroy detached vcard:") << this; if (!mAvatarIsReadOnly) - ::removeBelcardPhoto(mVcard->getVcard()); + removeBelcardPhoto(mVcard->getVcard()); } else qInfo() << QStringLiteral("Destroy attached vcard:") << this; } @@ -114,20 +116,20 @@ VcardModel::~VcardModel () { QString VcardModel::getAvatar () const { // Find desktop avatar. - shared_ptr photo = ::findBelcardPhoto(mVcard->getVcard()); + shared_ptr photo = findBelcardPhoto(mVcard->getVcard()); // No path found. if (!photo) return QString(""); // Returns right path. - return QStringLiteral("image://%1/%2").arg(AvatarProvider::PROVIDER_ID).arg( - ::Utils::coreStringToAppString(photo->getValue().substr(sizeof(VCARD_SCHEME) - 1)) + return QStringLiteral("image://%1/%2").arg(AvatarProvider::ProviderId).arg( + Utils::coreStringToAppString(photo->getValue().substr(sizeof(VcardScheme) - 1)) ); } static inline QString getFileIdFromAppPath (const QString &path) { - const static QString appPrefix = QStringLiteral("image://%1/").arg(AvatarProvider::PROVIDER_ID); + const static QString appPrefix = QStringLiteral("image://%1/").arg(AvatarProvider::ProviderId); return path.mid(appPrefix.length()); } @@ -142,7 +144,7 @@ bool VcardModel::setAvatar (const QString &path) { // not an application path like `image:`. if (!path.isEmpty()) { if (path.startsWith("image:")) - fileId = ::getFileIdFromAppPath(path); + fileId = getFileIdFromAppPath(path); else { file.setFileName(path); @@ -155,7 +157,7 @@ bool VcardModel::setAvatar (const QString &path) { .arg(uuid.mid(1, uuid.length() - 2)) // Remove `{}`. .arg(info.suffix()); - QString dest = ::Utils::coreStringToAppString(Paths::getAvatarsDirPath()) + fileId; + QString dest = Utils::coreStringToAppString(Paths::getAvatarsDirPath()) + fileId; if (!file.copy(dest)) return false; @@ -165,13 +167,13 @@ bool VcardModel::setAvatar (const QString &path) { } // 2. Remove oldest photo. - ::removeBelcardPhoto(belcard, mAvatarIsReadOnly); + removeBelcardPhoto(belcard, mAvatarIsReadOnly); mAvatarIsReadOnly = false; // 3. Update new photo. if (!path.isEmpty()) { shared_ptr photo = belcard::BelCardGeneric::create(); - photo->setValue(VCARD_SCHEME + ::Utils::appStringToCoreString(fileId)); + photo->setValue(VcardScheme + Utils::appStringToCoreString(fileId)); if (!belcard->addPhoto(photo)) { file.remove(); @@ -187,7 +189,7 @@ bool VcardModel::setAvatar (const QString &path) { // ----------------------------------------------------------------------------- QString VcardModel::getUsername () const { - return ::Utils::coreStringToAppString(mVcard->getFullName()); + return Utils::coreStringToAppString(mVcard->getFullName()); } void VcardModel::setUsername (const QString &username) { @@ -196,14 +198,14 @@ void VcardModel::setUsername (const QString &username) { if (username.length() == 0 || username == getUsername()) return; - mVcard->setFullName(::Utils::appStringToCoreString(username)); + mVcard->setFullName(Utils::appStringToCoreString(username)); emit vcardUpdated(); } // ----------------------------------------------------------------------------- static inline shared_ptr getOrCreateBelCardAddress (shared_ptr belcard) { - list > addresses = belcard->getAddresses(); + list> addresses = belcard->getAddresses(); shared_ptr address; if (addresses.empty()) { @@ -217,17 +219,17 @@ static inline shared_ptr getOrCreateBelCardAddress (sha } QVariantMap VcardModel::getAddress () const { - list > addresses = mVcard->getVcard()->getAddresses(); + list> addresses = mVcard->getVcard()->getAddresses(); QVariantMap map; if (addresses.empty()) return map; shared_ptr address = addresses.front(); - map["street"] = ::Utils::coreStringToAppString(address->getStreet()); - map["locality"] = ::Utils::coreStringToAppString(address->getLocality()); - map["postalCode"] = ::Utils::coreStringToAppString(address->getPostalCode()); - map["country"] = ::Utils::coreStringToAppString(address->getCountry()); + map["street"] = Utils::coreStringToAppString(address->getStreet()); + map["locality"] = Utils::coreStringToAppString(address->getLocality()); + map["postalCode"] = Utils::coreStringToAppString(address->getPostalCode()); + map["country"] = Utils::coreStringToAppString(address->getCountry()); return map; } @@ -235,32 +237,32 @@ QVariantMap VcardModel::getAddress () const { void VcardModel::setStreet (const QString &street) { CHECK_VCARD_IS_WRITABLE(this); - shared_ptr address = ::getOrCreateBelCardAddress(mVcard->getVcard()); - address->setStreet(::Utils::appStringToCoreString(street)); + shared_ptr address = getOrCreateBelCardAddress(mVcard->getVcard()); + address->setStreet(Utils::appStringToCoreString(street)); emit vcardUpdated(); } void VcardModel::setLocality (const QString &locality) { CHECK_VCARD_IS_WRITABLE(this); - shared_ptr address = ::getOrCreateBelCardAddress(mVcard->getVcard()); - address->setLocality(::Utils::appStringToCoreString(locality)); + shared_ptr address = getOrCreateBelCardAddress(mVcard->getVcard()); + address->setLocality(Utils::appStringToCoreString(locality)); emit vcardUpdated(); } void VcardModel::setPostalCode (const QString &postalCode) { CHECK_VCARD_IS_WRITABLE(this); - shared_ptr address = ::getOrCreateBelCardAddress(mVcard->getVcard()); - address->setPostalCode(::Utils::appStringToCoreString(postalCode)); + shared_ptr address = getOrCreateBelCardAddress(mVcard->getVcard()); + address->setPostalCode(Utils::appStringToCoreString(postalCode)); emit vcardUpdated(); } void VcardModel::setCountry (const QString &country) { CHECK_VCARD_IS_WRITABLE(this); - shared_ptr address = ::getOrCreateBelCardAddress(mVcard->getVcard()); - address->setCountry(::Utils::appStringToCoreString(country)); + shared_ptr address = getOrCreateBelCardAddress(mVcard->getVcard()); + address->setCountry(Utils::appStringToCoreString(country)); emit vcardUpdated(); } @@ -275,10 +277,10 @@ QVariantList VcardModel::getSipAddresses () const { shared_ptr linphoneAddress = core->createAddress(value); if (linphoneAddress) - list << ::Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); + list << Utils::coreStringToAppString(linphoneAddress->asStringUriOnly()); else qWarning() << QStringLiteral("Unable to parse sip address: `%1`") - .arg(::Utils::coreStringToAppString(value)); + .arg(Utils::coreStringToAppString(value)); } return list; @@ -287,13 +289,13 @@ QVariantList VcardModel::getSipAddresses () const { bool VcardModel::addSipAddress (const QString &sipAddress) { CHECK_VCARD_IS_WRITABLE(this); - string interpretedSipAddress = ::Utils::appStringToCoreString(SipAddressesModel::interpretSipAddress(sipAddress)); + string interpretedSipAddress = Utils::appStringToCoreString(SipAddressesModel::interpretSipAddress(sipAddress)); if (interpretedSipAddress.empty()) return false; // Add sip address in belcard. shared_ptr belcard = mVcard->getVcard(); - if (::findBelCardValue(belcard->getImpp(), interpretedSipAddress)) + if (findBelCardValue(belcard->getImpp(), interpretedSipAddress)) return false; shared_ptr value = belcard::BelCardGeneric::create(); @@ -314,9 +316,9 @@ void VcardModel::removeSipAddress (const QString &sipAddress) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - list > addresses = belcard->getImpp(); - shared_ptr value = ::findBelCardValue( - addresses, ::Utils::appStringToCoreString(SipAddressesModel::interpretSipAddress(sipAddress)) + list> addresses = belcard->getImpp(); + shared_ptr value = findBelCardValue( + addresses, Utils::appStringToCoreString(SipAddressesModel::interpretSipAddress(sipAddress)) ); if (!value) { @@ -348,7 +350,7 @@ QVariantList VcardModel::getCompanies () const { QVariantList list; for (const auto &company : mVcard->getVcard()->getRoles()) - list.append(::Utils::coreStringToAppString(company->getValue())); + list.append(Utils::coreStringToAppString(company->getValue())); return list; } @@ -357,11 +359,11 @@ bool VcardModel::addCompany (const QString &company) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - if (::findBelCardValue(belcard->getRoles(), company)) + if (findBelCardValue(belcard->getRoles(), company)) return false; shared_ptr value = belcard::BelCardGeneric::create(); - value->setValue(::Utils::appStringToCoreString(company)); + value->setValue(Utils::appStringToCoreString(company)); if (!belcard->addRole(value)) { qWarning() << QStringLiteral("Unable to add company on vcard: `%1`.").arg(company); @@ -378,7 +380,7 @@ void VcardModel::removeCompany (const QString &company) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - shared_ptr value = ::findBelCardValue(belcard->getRoles(), company); + shared_ptr value = findBelCardValue(belcard->getRoles(), company); if (!value) { qWarning() << QStringLiteral("Unable to remove company on vcard: `%1`.").arg(company); @@ -402,7 +404,7 @@ QVariantList VcardModel::getEmails () const { QVariantList list; for (const auto &email : mVcard->getVcard()->getEmails()) - list.append(::Utils::coreStringToAppString(email->getValue())); + list.append(Utils::coreStringToAppString(email->getValue())); return list; } @@ -411,11 +413,11 @@ bool VcardModel::addEmail (const QString &email) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - if (::findBelCardValue(belcard->getEmails(), email)) + if (findBelCardValue(belcard->getEmails(), email)) return false; shared_ptr value = belcard::BelCardGeneric::create(); - value->setValue(::Utils::appStringToCoreString(email)); + value->setValue(Utils::appStringToCoreString(email)); if (!belcard->addEmail(value)) { qWarning() << QStringLiteral("Unable to add email on vcard: `%1`.").arg(email); @@ -433,7 +435,7 @@ void VcardModel::removeEmail (const QString &email) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - shared_ptr value = ::findBelCardValue(belcard->getEmails(), email); + shared_ptr value = findBelCardValue(belcard->getEmails(), email); if (!value) { qWarning() << QStringLiteral("Unable to remove email on vcard: `%1`.").arg(email); @@ -457,7 +459,7 @@ QVariantList VcardModel::getUrls () const { QVariantList list; for (const auto &url : mVcard->getVcard()->getURLs()) - list.append(::Utils::coreStringToAppString(url->getValue())); + list.append(Utils::coreStringToAppString(url->getValue())); return list; } @@ -466,11 +468,11 @@ bool VcardModel::addUrl (const QString &url) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - if (::findBelCardValue(belcard->getURLs(), url)) + if (findBelCardValue(belcard->getURLs(), url)) return false; shared_ptr value = belcard::BelCardGeneric::create(); - value->setValue(::Utils::appStringToCoreString(url)); + value->setValue(Utils::appStringToCoreString(url)); if (!belcard->addURL(value)) { qWarning() << QStringLiteral("Unable to add url on vcard: `%1`.").arg(url); @@ -488,7 +490,7 @@ void VcardModel::removeUrl (const QString &url) { CHECK_VCARD_IS_WRITABLE(this); shared_ptr belcard = mVcard->getVcard(); - shared_ptr value = ::findBelCardValue(belcard->getURLs(), url); + shared_ptr value = findBelCardValue(belcard->getURLs(), url); if (!value) { qWarning() << QStringLiteral("Unable to remove url on vcard: `%1`.").arg(url); diff --git a/src/components/contact/VcardModel.hpp b/src/components/contact/VcardModel.hpp index feae47033..e87ae3449 100644 --- a/src/components/contact/VcardModel.hpp +++ b/src/components/contact/VcardModel.hpp @@ -23,11 +23,16 @@ #ifndef VCARD_MODEL_H_ #define VCARD_MODEL_H_ -#include +#include + #include // ============================================================================= +namespace linphone { + class Vcard; +} + class VcardModel : public QObject { friend class ContactModel; // Grant access to `mVcard`. diff --git a/src/components/contacts/ContactsListModel.cpp b/src/components/contacts/ContactsListModel.cpp index 63cd52be7..5bebb4b08 100644 --- a/src/components/contacts/ContactsListModel.cpp +++ b/src/components/contacts/ContactsListModel.cpp @@ -20,21 +20,25 @@ * Author: Ronan Abhamon */ -#include "../../app/App.hpp" -#include "../core/CoreManager.hpp" +#include + +#include "app/App.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/core/CoreManager.hpp" #include "ContactsListModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(parent) { mLinphoneFriends = CoreManager::getInstance()->getCore()->getFriendsLists().front(); // Clean friends. { - list > toRemove; + list> toRemove; for (const auto &linphoneFriend : mLinphoneFriends->getFriends()) { if (!linphoneFriend->getVcard()) toRemove.push_back(linphoneFriend); @@ -111,17 +115,15 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ContactModel *ContactsListModel::findContactModelFromSipAddress (const QString &sipAddress) const { auto it = find_if(mList.begin(), mList.end(), [&sipAddress](ContactModel *contactModel) { - return contactModel->getVcardModel()->getSipAddresses().contains(sipAddress); - }); - + return contactModel->getVcardModel()->getSipAddresses().contains(sipAddress); + }); return it != mList.end() ? *it : nullptr; } ContactModel *ContactsListModel::findContactModelFromUsername (const QString &username) const { auto it = find_if(mList.begin(), mList.end(), [&username](ContactModel *contactModel) { - return contactModel->getVcardModel()->getUsername() == username; - }); - + return contactModel->getVcardModel()->getUsername() == username; + }); return it != mList.end() ? *it : nullptr; } @@ -187,14 +189,14 @@ void ContactsListModel::cleanAvatars () { void ContactsListModel::addContact (ContactModel *contact) { QObject::connect(contact, &ContactModel::contactUpdated, this, [this, contact]() { - emit contactUpdated(contact); - }); + emit contactUpdated(contact); + }); QObject::connect(contact, &ContactModel::sipAddressAdded, this, [this, contact](const QString &sipAddress) { - emit sipAddressAdded(contact, sipAddress); - }); + emit sipAddressAdded(contact, sipAddress); + }); QObject::connect(contact, &ContactModel::sipAddressRemoved, this, [this, contact](const QString &sipAddress) { - emit sipAddressRemoved(contact, sipAddress); - }); + emit sipAddressRemoved(contact, sipAddress); + }); mList << contact; } diff --git a/src/components/contacts/ContactsListModel.hpp b/src/components/contacts/ContactsListModel.hpp index f09391859..6b2858c37 100644 --- a/src/components/contacts/ContactsListModel.hpp +++ b/src/components/contacts/ContactsListModel.hpp @@ -23,13 +23,19 @@ #ifndef CONTACTS_LIST_MODEL_H_ #define CONTACTS_LIST_MODEL_H_ -#include +#include + #include -#include "../contact/ContactModel.hpp" - // ============================================================================= +namespace linphone { + class FriendList; +} + +class ContactModel; +class VcardModel; + class ContactsListModel : public QAbstractListModel { friend class SipAddressesModel; @@ -37,7 +43,6 @@ class ContactsListModel : public QAbstractListModel { public: ContactsListModel (QObject *parent = Q_NULLPTR); - ~ContactsListModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; diff --git a/src/components/contacts/ContactsListProxyModel.cpp b/src/components/contacts/ContactsListProxyModel.cpp index 0b109e88e..48e831e1c 100644 --- a/src/components/contacts/ContactsListProxyModel.cpp +++ b/src/components/contacts/ContactsListProxyModel.cpp @@ -22,23 +22,28 @@ #include -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/Utils.hpp" +#include "ContactsListModel.hpp" #include "ContactsListProxyModel.hpp" -#define USERNAME_WEIGHT 50.f -#define SIP_ADDRESSES_WEIGHT 50.f - -#define FACTOR_POS_0 1.0f -#define FACTOR_POS_1 0.9f -#define FACTOR_POS_2 0.8f -#define FACTOR_POS_3 0.7f -#define FACTOR_POS_OTHER 0.6f +// ============================================================================= using namespace std; -// ============================================================================= +namespace { + constexpr float UsernameWeight = 50.f; + constexpr float SipAddressWeight = 50.f; + + constexpr float FactorPos0 = 1.0f; + constexpr float FactorPos1 = 0.9f; + constexpr float FactorPos2 = 0.8f; + constexpr float FactorPos3 = 0.7f; + constexpr float FactorPosOther = 0.6f; +} // Notes: // @@ -49,7 +54,7 @@ using namespace std; // a separator like ` word`. // // - [_.-;@ ] is the main pattern (a separator). -const QRegExp ContactsListProxyModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]"); +const QRegExp ContactsListProxyModel::SearchSeparators("^[^_.-;@ ][_.-;@ ]"); // ----------------------------------------------------------------------------- @@ -105,7 +110,7 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float // Search pattern. while ((index = string.indexOf(mFilter, index + 1, Qt::CaseInsensitive)) != -1) { // Search n chars between one separator and index. - int tmpOffset = index - string.lastIndexOf(mSearchSeparators, index) - 1; + int tmpOffset = index - string.lastIndexOf(SearchSeparators, index) - 1; if ((tmpOffset != -1 && tmpOffset < offset) || offset == -1) if ((offset = tmpOffset) == 0) break; @@ -113,28 +118,28 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float switch (offset) { case -1: return 0; - case 0: return percentage * FACTOR_POS_0; - case 1: return percentage * FACTOR_POS_1; - case 2: return percentage * FACTOR_POS_2; - case 3: return percentage * FACTOR_POS_3; + case 0: return percentage *FactorPos0; + case 1: return percentage *FactorPos1; + case 2: return percentage *FactorPos2; + case 3: return percentage *FactorPos3; default: break; } - return percentage * FACTOR_POS_OTHER; + return percentage *FactorPosOther; } float ContactsListProxyModel::computeContactWeight (const ContactModel *contact) const { - float weight = computeStringWeight(contact->getVcardModel()->getUsername(), USERNAME_WEIGHT); + float weight = computeStringWeight(contact->getVcardModel()->getUsername(), UsernameWeight); // Get all contact's addresses. - const list > addresses = contact->mLinphoneFriend->getAddresses(); + const list> addresses = contact->mLinphoneFriend->getAddresses(); float size = float(addresses.size()); for (auto it = addresses.cbegin(); it != addresses.cend(); ++it) weight += computeStringWeight( - ::Utils::coreStringToAppString((*it)->asStringUriOnly()), - SIP_ADDRESSES_WEIGHT / size - ); + Utils::coreStringToAppString((*it)->asStringUriOnly()), + SipAddressWeight / size + ); return weight; } diff --git a/src/components/contacts/ContactsListProxyModel.hpp b/src/components/contacts/ContactsListProxyModel.hpp index fc7e8b607..5cb243d4c 100644 --- a/src/components/contacts/ContactsListProxyModel.hpp +++ b/src/components/contacts/ContactsListProxyModel.hpp @@ -41,7 +41,6 @@ class ContactsListProxyModel : public QSortFilterProxyModel { public: ContactsListProxyModel (QObject *parent = Q_NULLPTR); - ~ContactsListProxyModel () = default; Q_INVOKABLE void setFilter (const QString &pattern); @@ -66,7 +65,7 @@ private: // and reused by `lessThan`. mutable QHash mWeights; - static const QRegExp mSearchSeparators; + static const QRegExp SearchSeparators; }; #endif // CONTACTS_LIST_PROXY_MODEL_H_ diff --git a/src/components/core/CoreHandlers.cpp b/src/components/core/CoreHandlers.cpp index 81d3d48a8..d987b2deb 100644 --- a/src/components/core/CoreHandlers.cpp +++ b/src/components/core/CoreHandlers.cpp @@ -25,16 +25,20 @@ #include #include -#include "../../app/App.hpp" -#include "../../utils/Utils.hpp" -#include "CoreManager.hpp" +#include "app/App.hpp" +#include "components/call/CallModel.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/notifier/Notifier.hpp" +#include "components/settings/SettingsModel.hpp" +#include "utils/Utils.hpp" #include "CoreHandlers.hpp" - -using namespace std; +#include "CoreManager.hpp" // ============================================================================= +using namespace std; + // Schedule a function in app context. void scheduleFunctionInApp (function func) { App *app = App::getInstance(); @@ -199,7 +203,7 @@ void CoreHandlers::onNotifyPresenceReceivedForUriOrTel ( const string &uriOrTel, const shared_ptr &presenceModel ) { - emit presenceReceived(::Utils::coreStringToAppString(uriOrTel), presenceModel); + emit presenceReceived(Utils::coreStringToAppString(uriOrTel), presenceModel); } void CoreHandlers::onNotifyPresenceReceived ( @@ -277,7 +281,7 @@ void CoreHandlers::onVersionUpdateCheckResultReceived ( ) { if (result == linphone::VersionUpdateCheckResultNewVersionAvailable) App::getInstance()->getNotifier()->notifyNewVersionAvailable( - ::Utils::coreStringToAppString(version), - ::Utils::coreStringToAppString(url) + Utils::coreStringToAppString(version), + Utils::coreStringToAppString(url) ); } diff --git a/src/components/core/CoreManager.cpp b/src/components/core/CoreManager.cpp index f34a1f958..813ce18c2 100644 --- a/src/components/core/CoreManager.cpp +++ b/src/components/core/CoreManager.cpp @@ -26,6 +26,13 @@ #include #include "app/paths/Paths.hpp" +#include "components/calls/CallsListModel.hpp" +#include "components/chat/ChatModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/contacts/ContactsListModel.hpp" +#include "components/settings/AccountSettingsModel.hpp" +#include "components/settings/SettingsModel.hpp" +#include "components/sip-addresses/SipAddressesModel.hpp" #include "utils/Utils.hpp" #if defined(Q_OS_LINUX) @@ -36,6 +43,7 @@ #include "messages-count-notifier/MessagesCountNotifierWindows.hpp" #endif // if defined(Q_OS_LINUX) +#include "CoreHandlers.hpp" #include "CoreManager.hpp" // ============================================================================= @@ -43,21 +51,21 @@ using namespace std; namespace { - constexpr int cCbsCallInterval = 20; + constexpr int CbsCallInterval = 20; - constexpr char cRcVersionName[] = "rc_version"; - constexpr int cRcVersionCurrent = 1; + constexpr char RcVersionName[] = "rc_version"; + constexpr int RcVersionCurrent = 1; // TODO: Remove hardcoded values. Use config directly. - constexpr char cLinphoneDomain[] = "sip.linphone.org"; - constexpr char cDefaultContactParameters[] = "message-expires=604800"; - constexpr int cDefaultExpires = 3600; - constexpr char cDownloadUrl[] = "https://www.linphone.org/technical-corner/linphone/downloads"; + constexpr char LinphoneDomain[] = "sip.linphone.org"; + constexpr char DefaultContactParameters[] = "message-expires=604800"; + constexpr int DefaultExpires = 3600; + constexpr char DownloadUrl[] = "https://www.linphone.org/technical-corner/linphone/downloads"; } // ----------------------------------------------------------------------------- -CoreManager *CoreManager::mInstance = nullptr; +CoreManager *CoreManager::mInstance; CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject(parent), mHandlers(make_shared(this)) { @@ -140,7 +148,7 @@ void CoreManager::init (QObject *parent, const QString &configPath) { mInstance = new CoreManager(parent, configPath); QTimer *timer = mInstance->mCbsTimer = new QTimer(mInstance); - timer->setInterval(cCbsCallInterval); + timer->setInterval(CbsCallInterval); QObject::connect(timer, &QTimer::timeout, mInstance, &CoreManager::iterate); } @@ -253,27 +261,27 @@ void CoreManager::createLinphoneCore (const QString &configPath) { void CoreManager::migrate () { shared_ptr config = mCore->getConfig(); - int rcVersion = config->getInt(SettingsModel::UI_SECTION, cRcVersionName, 0); - if (rcVersion == cRcVersionCurrent) + int rcVersion = config->getInt(SettingsModel::UiSection, RcVersionName, 0); + if (rcVersion == RcVersionCurrent) return; - if (rcVersion > cRcVersionCurrent) { + if (rcVersion > RcVersionCurrent) { qWarning() << QStringLiteral("RC file version (%1) is more recent than app rc file version (%2)!!!") - .arg(rcVersion).arg(cRcVersionCurrent); + .arg(rcVersion).arg(RcVersionCurrent); return; } qInfo() << QStringLiteral("Migrate from old rc file (%1 to %2).") - .arg(rcVersion).arg(cRcVersionCurrent); + .arg(rcVersion).arg(RcVersionCurrent); // Add message_expires param on old proxy configs. for (const auto &proxyConfig : mCore->getProxyConfigList()) { - if (proxyConfig->getDomain() == cLinphoneDomain) { - proxyConfig->setContactParameters(cDefaultContactParameters); - proxyConfig->setExpires(cDefaultExpires); + if (proxyConfig->getDomain() == LinphoneDomain) { + proxyConfig->setContactParameters(DefaultContactParameters); + proxyConfig->setExpires(DefaultExpires); proxyConfig->done(); } } - config->setInt(SettingsModel::UI_SECTION, cRcVersionName, cRcVersionCurrent); + config->setInt(SettingsModel::UiSection, RcVersionName, RcVersionCurrent); } // ----------------------------------------------------------------------------- @@ -307,5 +315,5 @@ void CoreManager::handleLogsUploadStateChanged (linphone::CoreLogCollectionUploa // ----------------------------------------------------------------------------- QString CoreManager::getDownloadUrl () { - return cDownloadUrl; + return DownloadUrl; } diff --git a/src/components/core/CoreManager.hpp b/src/components/core/CoreManager.hpp index 6e607c273..d05f3b3e4 100644 --- a/src/components/core/CoreManager.hpp +++ b/src/components/core/CoreManager.hpp @@ -23,21 +23,22 @@ #ifndef CORE_MANAGER_H_ #define CORE_MANAGER_H_ +#include #include -#include "../calls/CallsListModel.hpp" -#include "../chat/ChatModel.hpp" -#include "../contacts/ContactsListModel.hpp" -#include "../settings/AccountSettingsModel.hpp" -#include "../settings/SettingsModel.hpp" -#include "../sip-addresses/SipAddressesModel.hpp" - -#include "CoreHandlers.hpp" - // ============================================================================= class QTimer; +class AccountSettingsModel; +class CallsListModel; +class ChatModel; +class ContactsListModel; +class CoreHandlers; +class SettingsModel; +class SipAddressesModel; +class VcardModel; + class CoreManager : public QObject { Q_OBJECT; @@ -45,8 +46,6 @@ class CoreManager : public QObject { Q_PROPERTY(QString downloadUrl READ getDownloadUrl CONSTANT); public: - ~CoreManager () = default; - bool started () const { return mStarted; } @@ -165,7 +164,7 @@ private: SettingsModel *mSettingsModel = nullptr; AccountSettingsModel *mAccountSettingsModel = nullptr; - QHash > mChatModels; + QHash> mChatModels; QTimer *mCbsTimer = nullptr; diff --git a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp index 58ef47a30..ce35a5340 100644 --- a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp +++ b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp @@ -20,14 +20,17 @@ * Author: Ronan Abhamon */ -#include "../CoreManager.hpp" +#include "components/chat/ChatModel.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "components/settings/SettingsModel.hpp" #include "AbstractMessagesCountNotifier.hpp" -using namespace std; - // ============================================================================= +using namespace std; + AbstractMessagesCountNotifier::AbstractMessagesCountNotifier (QObject *parent) : QObject(parent) { CoreManager *coreManager = CoreManager::getInstance(); QObject::connect( diff --git a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp index 269fe7aca..a268dfd83 100644 --- a/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp +++ b/src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp @@ -37,7 +37,6 @@ class AbstractMessagesCountNotifier : public QObject { public: AbstractMessagesCountNotifier (QObject *parent = Q_NULLPTR); - virtual ~AbstractMessagesCountNotifier () = default; void updateUnreadMessagesCount (); diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp index 2b227a67b..3c33e74fe 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp @@ -25,30 +25,33 @@ #include #include #include +#include -#include "../../../app/App.hpp" -#include "../../../utils/LinphoneUtils.hpp" -#include "../../../utils/Utils.hpp" +#include "app/App.hpp" +#include "utils/LinphoneUtils.hpp" +#include "utils/Utils.hpp" #include "MessagesCountNotifierLinux.hpp" -#define ICON_WIDTH 256 -#define ICON_HEIGHT 256 - -#define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31" -#define ICON_COUNTER_BACKGROUND_RADIUS 100 -#define ICON_COUNTER_BLINK_INTERVAL 1000 -#define ICON_COUNTER_TEXT_COLOR "#FFFBFA" -#define ICON_COUNTER_TEXT_PIXEL_SIZE 144 - // ============================================================================= +namespace { + constexpr int IconWidth = 256; + constexpr int IconHeight = 256; + + constexpr char IconCounterBackgroundColor[] = "#FF3C31"; + constexpr int IconCounterBackgroundRadius = 100; + constexpr int IconCounterBlinkInterval = 1000; + constexpr char IconCounterTextColor[] = "#FFFBFA"; + constexpr int IconCounterTextPixelSize = 144; +} + MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessagesCountNotifier(parent) { - QSvgRenderer renderer(QStringLiteral(WINDOW_ICON_PATH)); + QSvgRenderer renderer((QString(LinphoneUtils::WindowIconPath))); if (!renderer.isValid()) qFatal("Invalid SVG Image."); - QPixmap buf(ICON_WIDTH, ICON_HEIGHT); + QPixmap buf(IconWidth, IconHeight); buf.fill(QColor(Qt::transparent)); QPainter painter(&buf); @@ -58,7 +61,7 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessage mBufWithCounter = new QPixmap(); mBlinkTimer = new QTimer(this); - mBlinkTimer->setInterval(ICON_COUNTER_BLINK_INTERVAL); + mBlinkTimer->setInterval(IconCounterBlinkInterval); QObject::connect(mBlinkTimer, &QTimer::timeout, this, &MessagesCountNotifier::update); Utils::connectOnce( @@ -91,17 +94,17 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { // Draw background. { - p.setBrush(QColor(ICON_COUNTER_BACKGROUND_COLOR)); - p.drawEllipse(QPointF(width / 2, height / 2), ICON_COUNTER_BACKGROUND_RADIUS, ICON_COUNTER_BACKGROUND_RADIUS); + p.setBrush(QColor(IconCounterBackgroundColor)); + p.drawEllipse(QPointF(width / 2, height / 2), IconCounterBackgroundRadius, IconCounterBackgroundRadius); } // Draw text. { QFont font = p.font(); - font.setPixelSize(ICON_COUNTER_TEXT_PIXEL_SIZE); + font.setPixelSize(IconCounterTextPixelSize); p.setFont(font); - p.setPen(QPen(QColor(ICON_COUNTER_TEXT_COLOR), 1)); + p.setPen(QPen(QColor(IconCounterTextColor), 1)); p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n)); } diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp index 3997486e7..31c009a5d 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.hpp @@ -31,6 +31,6 @@ public: MessagesCountNotifier (QObject *parent = Q_NULLPTR) : AbstractMessagesCountNotifier(parent) {} void notifyUnreadMessagesCount (int n) override { - ::notifyUnreadMessagesCountMacOS(n); + notifyUnreadMessagesCountMacOS(n); } }; diff --git a/src/components/file/FileDownloader.cpp b/src/components/file/FileDownloader.cpp index 5681e2301..ff4f45f4d 100644 --- a/src/components/file/FileDownloader.cpp +++ b/src/components/file/FileDownloader.cpp @@ -22,6 +22,7 @@ #include "app/paths/Paths.hpp" #include "components/core/CoreManager.hpp" +#include "components/settings/SettingsModel.hpp" #include "utils/Utils.hpp" #include "FileDownloader.hpp" diff --git a/src/components/file/FileExtractor.cpp b/src/components/file/FileExtractor.cpp index 1e6b997a1..2d12ec86d 100644 --- a/src/components/file/FileExtractor.cpp +++ b/src/components/file/FileExtractor.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "FileExtractor.hpp" diff --git a/src/components/file/FileExtractor.hpp b/src/components/file/FileExtractor.hpp index 026580fd8..b38925237 100644 --- a/src/components/file/FileExtractor.hpp +++ b/src/components/file/FileExtractor.hpp @@ -24,10 +24,11 @@ #define FILE_EXTRACTOR_H_ #include -#include // ============================================================================= +class QTimer; + // Supports only bzip file. class FileExtractor : public QObject { class ExtractStream; diff --git a/src/components/notifier/Notifier.cpp b/src/components/notifier/Notifier.cpp index 099c73991..08ae420a0 100644 --- a/src/components/notifier/Notifier.cpp +++ b/src/components/notifier/Notifier.cpp @@ -20,43 +20,50 @@ * Author: Ronan Abhamon */ +#include #include +#include #include #include -#include "../../app/App.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "app/App.hpp" +#include "components/call/CallModel.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/Utils.hpp" #include "Notifier.hpp" -#define NOTIFICATIONS_PATH "qrc:/ui/modules/Linphone/Notifications/" - -// ----------------------------------------------------------------------------- -// Notifications QML properties/methods. -// ----------------------------------------------------------------------------- - -#define NOTIFICATION_SHOW_METHOD_NAME "open" - -#define NOTIFICATION_PROPERTY_DATA "notificationData" - -#define NOTIFICATION_PROPERTY_X "popupX" -#define NOTIFICATION_PROPERTY_Y "popupY" - -#define NOTIFICATION_PROPERTY_WINDOW "__internalWindow" - -#define NOTIFICATION_PROPERTY_TIMER "__timer" - -// ----------------------------------------------------------------------------- -// Arbitrary hardcoded values. -// ----------------------------------------------------------------------------- - -#define NOTIFICATION_SPACING 10 -#define N_MAX_NOTIFICATIONS 5 -#define MAX_TIMEOUT 30000 +// ============================================================================= using namespace std; +namespace { + constexpr char NotificationsPath[] = "qrc:/ui/modules/Linphone/Notifications/"; + + // --------------------------------------------------------------------------- + // Notifications QML properties/methods. + // --------------------------------------------------------------------------- + + constexpr char NotificationShowMethodName[] = "open"; + + constexpr char NotificationPropertyData[] = "notificationData"; + + constexpr char NotificationPropertyX[] = "popupX"; + constexpr char NotificationPropertyY[] = "popupY"; + + constexpr char NotificationPropertyWindow[] = "__internalWindow"; + + constexpr char NotificationPropertyTimer[] = "__timer"; + + // --------------------------------------------------------------------------- + // Arbitrary hardcoded values. + // --------------------------------------------------------------------------- + + constexpr int NotificationSpacing = 10; + constexpr int MaxNotificationsNumber = 5; + constexpr int MaxTimeout = 30000; +} + // ============================================================================= template @@ -71,7 +78,7 @@ void setProperty (QObject &object, const char *property, const T &value) { // Available notifications. // ============================================================================= -const QHash Notifier::mNotifications = { +const QHash Notifier::Notifications = { { Notifier::ReceivedMessage, { "NotificationReceivedMessage.qml", 10 } }, { Notifier::ReceivedFileMessage, { "NotificationReceivedFileMessage.qml", 10 } }, { Notifier::ReceivedCall, { "NotificationReceivedCall.qml", 30 } }, @@ -83,12 +90,12 @@ const QHash Notifier::mNotifications = { // ----------------------------------------------------------------------------- Notifier::Notifier (QObject *parent) : QObject(parent) { - const int nComponents = mNotifications.size(); + const int nComponents = Notifications.size(); mComponents = new QQmlComponent *[nComponents]; QQmlEngine *engine = App::getInstance()->getEngine(); - for (const auto &key : mNotifications.keys()) { - QQmlComponent *component = new QQmlComponent(engine, QUrl(NOTIFICATIONS_PATH + Notifier::mNotifications[key].filename)); + for (const auto &key : Notifications.keys()) { + QQmlComponent *component = new QQmlComponent(engine, QUrl(NotificationsPath + Notifier::Notifications[key].filename)); if (Q_UNLIKELY(component->isError())) { qWarning() << QStringLiteral("Errors found in `Notification` component %1:").arg(key) << component->errors(); abort(); @@ -102,7 +109,7 @@ Notifier::Notifier (QObject *parent) : QObject(parent) { Notifier::~Notifier () { delete mMutex; - const int nComponents = mNotifications.size(); + const int nComponents = Notifications.size(); for (int i = 0; i < nComponents; ++i) delete mComponents[i]; delete[] mComponents; @@ -113,10 +120,10 @@ Notifier::~Notifier () { QObject *Notifier::createNotification (Notifier::NotificationType type) { mMutex->lock(); - Q_ASSERT(mInstancesNumber <= N_MAX_NOTIFICATIONS); + Q_ASSERT(mInstancesNumber <= MaxNotificationsNumber); // Check existing instances. - if (mInstancesNumber == N_MAX_NOTIFICATIONS) { + if (mInstancesNumber == MaxNotificationsNumber) { qWarning() << QStringLiteral("Unable to create another notification."); mMutex->unlock(); return nullptr; @@ -129,7 +136,7 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { mInstancesNumber++; { - QQuickWindow *window = instance->findChild(NOTIFICATION_PROPERTY_WINDOW); + QQuickWindow *window = instance->findChild(NotificationPropertyWindow); Q_CHECK_PTR(window); QScreen *screen = window->screen(); @@ -141,11 +148,11 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { int windowHeight = window->height(); int offset = geometry.y() + geometry.height() - windowHeight; - ::setProperty(*instance, NOTIFICATION_PROPERTY_X, geometry.x() + geometry.width() - window->width()); - ::setProperty(*instance, NOTIFICATION_PROPERTY_Y, offset - (mOffset % offset)); + ::setProperty(*instance, NotificationPropertyX, geometry.x() + geometry.width() - window->width()); + ::setProperty(*instance, NotificationPropertyY, offset - (mOffset % offset)); // Update offset. - mOffset = (windowHeight + mOffset) + NOTIFICATION_SPACING; + mOffset = (windowHeight + mOffset) + NotificationSpacing; if (mOffset - offset + geometry.y() >= 0) mOffset = 0; } @@ -159,12 +166,12 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { void Notifier::showNotification (QObject *notification, int timeout) { // Display notification. - QMetaObject::invokeMethod(notification, NOTIFICATION_SHOW_METHOD_NAME, Qt::DirectConnection); + QMetaObject::invokeMethod(notification, NotificationShowMethodName, Qt::DirectConnection); QTimer *timer = new QTimer(notification); - timer->setInterval(timeout > MAX_TIMEOUT ? MAX_TIMEOUT : timeout); + timer->setInterval(timeout > MaxTimeout ? MaxTimeout : timeout); timer->setSingleShot(true); - notification->setProperty(NOTIFICATION_PROPERTY_TIMER, QVariant::fromValue(timer)); + notification->setProperty(NotificationPropertyTimer, QVariant::fromValue(timer)); // Destroy it after timeout. QObject::connect(timer, &QTimer::timeout, this, [this, notification]() { @@ -193,7 +200,7 @@ void Notifier::deleteNotification (QVariant notification) { qInfo() << QStringLiteral("Delete notification:") << instance; instance->setProperty("__valid", true); - instance->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); + instance->property(NotificationPropertyTimer).value()->stop(); mInstancesNumber--; Q_ASSERT(mInstancesNumber >= 0); @@ -212,10 +219,10 @@ void Notifier::deleteNotification (QVariant notification) { QObject * notification = createNotification(TYPE); \ if (!notification) \ return; \ - const int timeout = mNotifications[TYPE].timeout * 1000; + const int timeout = Notifications[TYPE].timeout * 1000; #define SHOW_NOTIFICATION(DATA) \ - ::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, DATA); \ + ::setProperty(*notification, NotificationPropertyData, DATA); \ showNotification(notification, timeout); // ----------------------------------------------------------------------------- @@ -228,9 +235,9 @@ void Notifier::notifyReceivedMessage (const shared_ptr &m QVariantMap map; map["message"] = message->getFileTransferInformation() ? tr("newFileMessage") - : ::Utils::coreStringToAppString(message->getText()); + : Utils::coreStringToAppString(message->getText()); - map["sipAddress"] = ::Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly()); + map["sipAddress"] = Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly()); map["window"].setValue(App::getInstance()->getMainWindow()); SHOW_NOTIFICATION(map); @@ -240,7 +247,7 @@ void Notifier::notifyReceivedFileMessage (const shared_ptrgetFileTransferFilepath()); + map["fileUri"] = Utils::coreStringToAppString(message->getFileTransferFilepath()); map["fileSize"] = quint64(message->getFileTransferInformation()->getSize()); SHOW_NOTIFICATION(map); diff --git a/src/components/notifier/Notifier.hpp b/src/components/notifier/Notifier.hpp index 68f267b2d..352f00e52 100644 --- a/src/components/notifier/Notifier.hpp +++ b/src/components/notifier/Notifier.hpp @@ -23,7 +23,8 @@ #ifndef NOTIFIER_H_ #define NOTIFIER_H_ -#include +#include + #include // ============================================================================= @@ -31,6 +32,11 @@ class QMutex; class QQmlComponent; +namespace linphone { + class Call; + class ChatMessage; +} + class Notifier : public QObject { Q_OBJECT; @@ -77,7 +83,7 @@ private: QMutex *mMutex = nullptr; QQmlComponent **mComponents = nullptr; - static const QHash mNotifications; + static const QHash Notifications; }; #endif // NOTIFIER_H_ diff --git a/src/components/other/clipboard/Clipboard.cpp b/src/components/other/clipboard/Clipboard.cpp index 6949303e1..146b4b05c 100644 --- a/src/components/other/clipboard/Clipboard.cpp +++ b/src/components/other/clipboard/Clipboard.cpp @@ -28,7 +28,7 @@ // ============================================================================= Clipboard::Clipboard (QObject *parent) : QObject(parent) { - connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &Clipboard::textChanged); + QObject::connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &Clipboard::textChanged); } QString Clipboard::getText () const { diff --git a/src/components/other/clipboard/Clipboard.hpp b/src/components/other/clipboard/Clipboard.hpp index 7e4c10841..cc5e01c29 100644 --- a/src/components/other/clipboard/Clipboard.hpp +++ b/src/components/other/clipboard/Clipboard.hpp @@ -34,7 +34,6 @@ class Clipboard : public QObject { public: Clipboard (QObject *parent = Q_NULLPTR); - ~Clipboard () = default; signals: void textChanged (); diff --git a/src/components/other/colors/Colors.cpp b/src/components/other/colors/Colors.cpp index dfb4f7984..2d68f0aa3 100644 --- a/src/components/other/colors/Colors.cpp +++ b/src/components/other/colors/Colors.cpp @@ -20,22 +20,23 @@ * Author: Ronan Abhamon */ +#include #include -#include "../../../utils/Utils.hpp" - -#include "Colors.hpp" - #if LINPHONE_FRIDAY #include #endif // if LINPHONE_FRIDAY -using namespace std; +#include "utils/Utils.hpp" + +#include "Colors.hpp" // ============================================================================= +using namespace std; + namespace { - constexpr char cColorsSection[] = "ui_colors"; + constexpr char ColorsSection[] = "ui_colors"; } #if LINPHONE_FRIDAY @@ -46,7 +47,7 @@ namespace { Colors::Colors (QObject *parent) : QObject(parent) { #if LINPHONE_FRIDAY - if (::isLinphoneFriday()) { + if (isLinphoneFriday()) { setProperty("i", QColor("#F48D8D")); setProperty("s", QColor("#F58585")); setProperty("t", QColor("#FFC5C5")); @@ -56,7 +57,7 @@ Colors::Colors (QObject *parent) : QObject(parent) { void Colors::useConfig (const shared_ptr &config) { #if LINPHONE_FRIDAY - if (!::isLinphoneFriday()) + if (!isLinphoneFriday()) overrideColors(config); #else overrideColors(config); @@ -74,10 +75,10 @@ void Colors::overrideColors (const shared_ptr &config) { for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) { const QMetaProperty metaProperty = info->property(i); const string colorName = metaProperty.name(); - const string colorValue = config->getString(cColorsSection, colorName, ""); + const string colorValue = config->getString(ColorsSection, colorName, ""); if (!colorValue.empty()) - setProperty(colorName.c_str(), QColor(::Utils::coreStringToAppString(colorValue))); + setProperty(colorName.c_str(), QColor(Utils::coreStringToAppString(colorValue))); } } diff --git a/src/components/other/colors/Colors.hpp b/src/components/other/colors/Colors.hpp index 30811db17..cd9849b1e 100644 --- a/src/components/other/colors/Colors.hpp +++ b/src/components/other/colors/Colors.hpp @@ -23,7 +23,8 @@ #ifndef COLORS_H_ #define COLORS_H_ -#include +#include + #include #include @@ -49,7 +50,7 @@ // ----------------------------------------------------------------------------- namespace linphone { -class Config; + class Config; } class Colors : public QObject { @@ -97,7 +98,6 @@ class Colors : public QObject { public: Colors (QObject *parent = Q_NULLPTR); - ~Colors () = default; void useConfig (const std::shared_ptr &config); diff --git a/src/components/other/text-to-speech/TextToSpeech.hpp b/src/components/other/text-to-speech/TextToSpeech.hpp index a58884795..75ae5d0a4 100644 --- a/src/components/other/text-to-speech/TextToSpeech.hpp +++ b/src/components/other/text-to-speech/TextToSpeech.hpp @@ -36,7 +36,6 @@ class TextToSpeech : public QObject { public: TextToSpeech (QObject *parent = Q_NULLPTR); - ~TextToSpeech () = default; Q_INVOKABLE void say (const QString &text); diff --git a/src/components/other/units/Units.hpp b/src/components/other/units/Units.hpp index 3aec64803..118400d26 100644 --- a/src/components/other/units/Units.hpp +++ b/src/components/other/units/Units.hpp @@ -34,7 +34,6 @@ class Units : public QObject { public: Units (QObject *parent = Q_NULLPTR); - ~Units () = default; private: float getDp () const; diff --git a/src/components/presence/OwnPresenceModel.cpp b/src/components/presence/OwnPresenceModel.cpp index c76dc1cb4..c3e42e3ef 100644 --- a/src/components/presence/OwnPresenceModel.cpp +++ b/src/components/presence/OwnPresenceModel.cpp @@ -20,14 +20,14 @@ * Author: Ghislain MARY */ -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" #include "OwnPresenceModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + Presence::PresenceLevel OwnPresenceModel::getPresenceLevel () const { return Presence::getPresenceLevel(getPresenceStatus()); } @@ -60,10 +60,10 @@ static inline void addBuildStatus (QVariantList &list, Presence::PresenceStatus QVariantList OwnPresenceModel::getStatuses () const { QVariantList statuses; - ::addBuildStatus(statuses, Presence::Online); - ::addBuildStatus(statuses, Presence::Busy); - ::addBuildStatus(statuses, Presence::DoNotDisturb); - ::addBuildStatus(statuses, Presence::Offline); + addBuildStatus(statuses, Presence::Online); + addBuildStatus(statuses, Presence::Busy); + addBuildStatus(statuses, Presence::DoNotDisturb); + addBuildStatus(statuses, Presence::Offline); return statuses; } diff --git a/src/components/presence/OwnPresenceModel.hpp b/src/components/presence/OwnPresenceModel.hpp index 3f0e26538..889f54798 100644 --- a/src/components/presence/OwnPresenceModel.hpp +++ b/src/components/presence/OwnPresenceModel.hpp @@ -23,7 +23,7 @@ #ifndef OWN_PRESENCE_MODEL_H_ #define OWN_PRESENCE_MODEL_H_ -#include "../presence/Presence.hpp" +#include "Presence.hpp" // ============================================================================= // Gives the statuses list informations (icons, label, level, status). diff --git a/src/components/presence/Presence.hpp b/src/components/presence/Presence.hpp index 6405fd86f..fc1db18c5 100644 --- a/src/components/presence/Presence.hpp +++ b/src/components/presence/Presence.hpp @@ -41,7 +41,6 @@ public: DoNotDisturb = linphone::ConsolidatedPresenceDoNotDisturb, Offline = linphone::ConsolidatedPresenceOffline }; - Q_ENUM(PresenceStatus); enum PresenceLevel { @@ -50,13 +49,10 @@ public: Red, White }; - Q_ENUM(PresenceLevel); Presence (QObject *parent = Q_NULLPTR) : QObject(parent) {} - ~Presence () = default; - Q_INVOKABLE static PresenceLevel getPresenceLevel (const PresenceStatus &status); Q_INVOKABLE static QString getPresenceStatusAsString (const PresenceStatus &status); diff --git a/src/components/settings/AccountSettingsModel.cpp b/src/components/settings/AccountSettingsModel.cpp index bb93114eb..e8bffe252 100644 --- a/src/components/settings/AccountSettingsModel.cpp +++ b/src/components/settings/AccountSettingsModel.cpp @@ -20,16 +20,18 @@ * Author: Ronan Abhamon */ -#include "../../app/paths/Paths.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "app/paths/Paths.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/Utils.hpp" #include "AccountSettingsModel.hpp" - -using namespace std; +#include "SettingsModel.hpp" // ============================================================================= +using namespace std; + static inline AccountSettingsModel::RegistrationState mapLinphoneRegistrationStateToUi (linphone::RegistrationState state) { switch (state) { case linphone::RegistrationStateNone: @@ -64,18 +66,18 @@ bool AccountSettingsModel::addOrUpdateProxyConfig (const shared_ptr core = coreManager->getCore(); - list > proxyConfigs = core->getProxyConfigList(); + list> proxyConfigs = core->getProxyConfigList(); if (find(proxyConfigs.cbegin(), proxyConfigs.cend(), proxyConfig) != proxyConfigs.cend()) { if (proxyConfig->done() == -1) { qWarning() << QStringLiteral("Unable to update proxy config: `%1`.") - .arg(::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); + .arg(Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); return false; } coreManager->getSettingsModel()->configureRlsUri(); } else { if (core->addProxyConfig(proxyConfig) == -1) { qWarning() << QStringLiteral("Unable to add proxy config: `%1`.") - .arg(::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); + .arg(Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); return false; } coreManager->getSettingsModel()->configureRlsUri(proxyConfig); @@ -93,29 +95,29 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr
  • address = proxyConfig->getIdentityAddress(); map["sipAddress"] = address - ? ::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString()) + ? Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString()) : QString(""); } - map["serverAddress"] = ::Utils::coreStringToAppString(proxyConfig->getServerAddr()); + map["serverAddress"] = Utils::coreStringToAppString(proxyConfig->getServerAddr()); map["registrationDuration"] = proxyConfig->getPublishExpires(); - map["transport"] = ::Utils::coreStringToAppString(proxyConfig->getTransport()); - map["route"] = ::Utils::coreStringToAppString(proxyConfig->getRoute()); - map["contactParams"] = ::Utils::coreStringToAppString(proxyConfig->getContactParameters()); + map["transport"] = Utils::coreStringToAppString(proxyConfig->getTransport()); + map["route"] = Utils::coreStringToAppString(proxyConfig->getRoute()); + map["contactParams"] = Utils::coreStringToAppString(proxyConfig->getContactParameters()); map["avpfInterval"] = proxyConfig->getAvpfRrInterval(); map["registerEnabled"] = proxyConfig->registerEnabled(); map["publishPresence"] = proxyConfig->publishEnabled(); map["avpfEnabled"] = proxyConfig->getAvpfMode() == linphone::AVPFMode::AVPFModeEnabled; - map["registrationState"] = ::mapLinphoneRegistrationStateToUi(proxyConfig->getState()); + map["registrationState"] = mapLinphoneRegistrationStateToUi(proxyConfig->getState()); shared_ptr natPolicy = proxyConfig->getNatPolicy(); if (!natPolicy) natPolicy = proxyConfig->getCore()->createNatPolicy(); map["iceEnabled"] = natPolicy->iceEnabled(); map["turnEnabled"] = natPolicy->turnEnabled(); - map["stunServer"] = ::Utils::coreStringToAppString(natPolicy->getStunServer()); - map["turnUser"] = ::Utils::coreStringToAppString(natPolicy->getStunServerUsername()); + map["stunServer"] = Utils::coreStringToAppString(natPolicy->getStunServer()); + map["turnUser"] = Utils::coreStringToAppString(natPolicy->getStunServerUsername()); shared_ptr authInfo = proxyConfig->findAuthInfo(); - map["turnPassword"] = authInfo ? ::Utils::coreStringToAppString(authInfo->getPasswd()) : QString(""); + map["turnPassword"] = authInfo ? Utils::coreStringToAppString(authInfo->getPasswd()) : QString(""); return map; } @@ -146,8 +148,8 @@ bool AccountSettingsModel::addOrUpdateProxyConfig ( // Sip address. { shared_ptr address = linphone::Factory::get()->createAddress( - ::Utils::appStringToCoreString(literal) - ); + Utils::appStringToCoreString(literal) + ); if (!address) { qWarning() << QStringLiteral("Unable to create sip address object from: `%1`.").arg(literal); return false; @@ -155,7 +157,7 @@ bool AccountSettingsModel::addOrUpdateProxyConfig ( if (proxyConfig->setIdentityAddress(address)) { qWarning() << QStringLiteral("Unable to set identity address: `%1`.") - .arg(::Utils::coreStringToAppString(address->asStringUriOnly())); + .arg(Utils::coreStringToAppString(address->asStringUriOnly())); return false; } } @@ -164,15 +166,15 @@ bool AccountSettingsModel::addOrUpdateProxyConfig ( { QString serverAddress = data["serverAddress"].toString(); - if (proxyConfig->setServerAddr(::Utils::appStringToCoreString(serverAddress))) { + if (proxyConfig->setServerAddr(Utils::appStringToCoreString(serverAddress))) { qWarning() << QStringLiteral("Unable to add server address: `%1`.").arg(serverAddress); return false; } } proxyConfig->setPublishExpires(data["registrationDuration"].toInt()); - proxyConfig->setRoute(::Utils::appStringToCoreString(data["route"].toString())); - proxyConfig->setContactParameters(::Utils::appStringToCoreString(data["contactParams"].toString())); + proxyConfig->setRoute(Utils::appStringToCoreString(data["route"].toString())); + proxyConfig->setContactParameters(Utils::appStringToCoreString(data["contactParams"].toString())); proxyConfig->setAvpfRrInterval(uint8_t(data["avpfInterval"].toInt())); proxyConfig->enableRegister(data["registerEnabled"].toBool()); proxyConfig->enablePublish(data["publishPresence"].toBool()); @@ -187,22 +189,22 @@ bool AccountSettingsModel::addOrUpdateProxyConfig ( natPolicy->enableIce(data["iceEnabled"].toBool()); natPolicy->enableStun(data["iceEnabled"].toBool()); natPolicy->enableTurn(data["turnEnabled"].toBool()); - natPolicy->setStunServer(::Utils::appStringToCoreString(data["stunServer"].toString())); - natPolicy->setStunServerUsername(::Utils::appStringToCoreString(data["turnUser"].toString())); + natPolicy->setStunServer(Utils::appStringToCoreString(data["stunServer"].toString())); + natPolicy->setStunServerUsername(Utils::appStringToCoreString(data["turnUser"].toString())); shared_ptr authInfo = proxyConfig->findAuthInfo(); shared_ptr core = proxyConfig->getCore(); if (authInfo) { shared_ptr clonedAuthInfo = authInfo->clone(); - clonedAuthInfo->setPasswd(::Utils::appStringToCoreString(data["turnPassword"].toString())); + clonedAuthInfo->setPasswd(Utils::appStringToCoreString(data["turnPassword"].toString())); core->removeAuthInfo(authInfo); core->addAuthInfo(clonedAuthInfo); } else { authInfo = linphone::Factory::get()->createAuthInfo( - ::Utils::appStringToCoreString(data["turnUser"].toString()), - ::Utils::appStringToCoreString(data["turnUser"].toString()), - ::Utils::appStringToCoreString(data["turnPassword"].toString()), + Utils::appStringToCoreString(data["turnUser"].toString()), + Utils::appStringToCoreString(data["turnUser"].toString()), + Utils::appStringToCoreString(data["turnPassword"].toString()), "", "", "" @@ -228,8 +230,8 @@ void AccountSettingsModel::addAuthInfo ( const QString &password, const QString &userId ) { - authInfo->setPasswd(::Utils::appStringToCoreString(password)); - authInfo->setUserid(::Utils::appStringToCoreString(userId)); + authInfo->setPasswd(Utils::appStringToCoreString(password)); + authInfo->setUserid(Utils::appStringToCoreString(userId)); CoreManager::getInstance()->getCore()->addAuthInfo(authInfo); } @@ -244,7 +246,7 @@ QString AccountSettingsModel::getUsername () const { shared_ptr address = getUsedSipAddress(); const string displayName = address->getDisplayName(); - return ::Utils::coreStringToAppString( + return Utils::coreStringToAppString( displayName.empty() ? address->getUsername() : displayName ); } @@ -253,9 +255,9 @@ void AccountSettingsModel::setUsername (const QString &username) { shared_ptr address = getUsedSipAddress(); shared_ptr newAddress = address->clone(); - if (newAddress->setDisplayName(::Utils::appStringToCoreString(username))) { + if (newAddress->setDisplayName(Utils::appStringToCoreString(username))) { qWarning() << QStringLiteral("Unable to set displayName on sip address: `%1`.") - .arg(::Utils::coreStringToAppString(newAddress->asStringUriOnly())); + .arg(Utils::coreStringToAppString(newAddress->asStringUriOnly())); } else { setUsedSipAddress(newAddress); } @@ -264,18 +266,18 @@ void AccountSettingsModel::setUsername (const QString &username) { } QString AccountSettingsModel::getSipAddress () const { - return ::Utils::coreStringToAppString(getUsedSipAddress()->asStringUriOnly()); + return Utils::coreStringToAppString(getUsedSipAddress()->asStringUriOnly()); } AccountSettingsModel::RegistrationState AccountSettingsModel::getRegistrationState () const { shared_ptr proxyConfig = CoreManager::getInstance()->getCore()->getDefaultProxyConfig(); - return proxyConfig ? ::mapLinphoneRegistrationStateToUi(proxyConfig->getState()) : RegistrationStateNotRegistered; + return proxyConfig ? mapLinphoneRegistrationStateToUi(proxyConfig->getState()) : RegistrationStateNotRegistered; } // ----------------------------------------------------------------------------- QString AccountSettingsModel::getPrimaryUsername () const { - return ::Utils::coreStringToAppString( + return Utils::coreStringToAppString( CoreManager::getInstance()->getCore()->getPrimaryContactParsed()->getUsername() ); } @@ -285,7 +287,7 @@ void AccountSettingsModel::setPrimaryUsername (const QString &username) { shared_ptr primary = core->getPrimaryContactParsed(); primary->setUsername( - username.isEmpty() ? "linphone" : ::Utils::appStringToCoreString(username) + username.isEmpty() ? "linphone" : Utils::appStringToCoreString(username) ); core->setPrimaryContact(primary->asString()); @@ -293,7 +295,7 @@ void AccountSettingsModel::setPrimaryUsername (const QString &username) { } QString AccountSettingsModel::getPrimaryDisplayName () const { - return ::Utils::coreStringToAppString( + return Utils::coreStringToAppString( CoreManager::getInstance()->getCore()->getPrimaryContactParsed()->getDisplayName() ); } @@ -302,14 +304,14 @@ void AccountSettingsModel::setPrimaryDisplayName (const QString &displayName) { shared_ptr core = CoreManager::getInstance()->getCore(); shared_ptr primary = core->getPrimaryContactParsed(); - primary->setDisplayName(::Utils::appStringToCoreString(displayName)); + primary->setDisplayName(Utils::appStringToCoreString(displayName)); core->setPrimaryContact(primary->asString()); emit accountSettingsUpdated(); } QString AccountSettingsModel::getPrimarySipAddress () const { - return ::Utils::coreStringToAppString( + return Utils::coreStringToAppString( CoreManager::getInstance()->getCore()->getPrimaryContactParsed()->asString() ); } @@ -322,13 +324,13 @@ QVariantList AccountSettingsModel::getAccounts () const { { QVariantMap account; - account["sipAddress"] = ::Utils::coreStringToAppString(core->getPrimaryContactParsed()->asStringUriOnly()); + account["sipAddress"] = Utils::coreStringToAppString(core->getPrimaryContactParsed()->asStringUriOnly()); accounts << account; } for (const auto &proxyConfig : core->getProxyConfigList()) { QVariantMap account; - account["sipAddress"] = ::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asStringUriOnly()); + account["sipAddress"] = Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asStringUriOnly()); account["proxyConfig"].setValue(proxyConfig); accounts << account; } diff --git a/src/components/settings/AccountSettingsModel.hpp b/src/components/settings/AccountSettingsModel.hpp index f27c659fb..32e5ff3fa 100644 --- a/src/components/settings/AccountSettingsModel.hpp +++ b/src/components/settings/AccountSettingsModel.hpp @@ -49,11 +49,9 @@ public: RegistrationStateNotRegistered, RegistrationStateInProgress }; - Q_ENUM(RegistrationState); AccountSettingsModel (QObject *parent = Q_NULLPTR); - ~AccountSettingsModel () = default; bool addOrUpdateProxyConfig (const std::shared_ptr &proxyConfig); @@ -110,6 +108,6 @@ private: ); }; -Q_DECLARE_METATYPE(std::shared_ptr ); +Q_DECLARE_METATYPE(std::shared_ptr); #endif // ACCOUNT_SETTINGS_MODEL_H_ diff --git a/src/components/settings/SettingsModel.cpp b/src/components/settings/SettingsModel.cpp index ecc96438a..f7494b2dc 100644 --- a/src/components/settings/SettingsModel.cpp +++ b/src/components/settings/SettingsModel.cpp @@ -34,11 +34,11 @@ using namespace std; namespace { - constexpr char cDefaultRlsUri[] = "sips:rls@sip.linphone.org"; - constexpr char cDefaultLogsEmail[] = "linphone-desktop@belledonne-communications.com"; + constexpr char DefaultRlsUri[] = "sips:rls@sip.linphone.org"; + constexpr char DefaultLogsEmail[] = "linphone-desktop@belledonne-communications.com"; } -const string SettingsModel::UI_SECTION("ui"); +const string SettingsModel::UiSection("ui"); SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { mConfig = CoreManager::getInstance()->getCore()->getConfig(); @@ -65,10 +65,9 @@ QStringList SettingsModel::getPlaybackDevices () const { shared_ptr core = CoreManager::getInstance()->getCore(); QStringList list; - for (const auto &device : core->getSoundDevices()) { + for (const auto &device : core->getSoundDevices()) if (core->soundDeviceCanPlayback(device)) list << Utils::coreStringToAppString(device); - } return list; } @@ -225,17 +224,17 @@ static inline QVariantMap createMapFromVideoDefinition (const shared_ptrgetSupportedVideoDefinitions()) - list << ::createMapFromVideoDefinition(definition); + list << createMapFromVideoDefinition(definition); return list; } QVariantMap SettingsModel::getVideoDefinition () const { - return ::createMapFromVideoDefinition(CoreManager::getInstance()->getCore()->getPreferredVideoDefinition()); + return createMapFromVideoDefinition(CoreManager::getInstance()->getCore()->getPreferredVideoDefinition()); } void SettingsModel::setVideoDefinition (const QVariantMap &definition) { CoreManager::getInstance()->getCore()->setPreferredVideoDefinition( - definition.value("__definition").value >()->clone() + definition.value("__definition").value>()->clone() ); emit videoDefinitionChanged(definition); @@ -250,66 +249,66 @@ bool SettingsModel::getVideoSupported () const { // ============================================================================= int SettingsModel::getAutoAnswerDelay () const { - return mConfig->getInt(UI_SECTION, "auto_answer_delay", 0); + return mConfig->getInt(UiSection, "auto_answer_delay", 0); } void SettingsModel::setAutoAnswerDelay (int delay) { - mConfig->setInt(UI_SECTION, "auto_answer_delay", delay); + mConfig->setInt(UiSection, "auto_answer_delay", delay); emit autoAnswerDelayChanged(delay); } // ----------------------------------------------------------------------------- bool SettingsModel::getAutoAnswerStatus () const { - return !!mConfig->getInt(UI_SECTION, "auto_answer", 0); + return !!mConfig->getInt(UiSection, "auto_answer", 0); } void SettingsModel::setAutoAnswerStatus (bool status) { - mConfig->setInt(UI_SECTION, "auto_answer", status); + mConfig->setInt(UiSection, "auto_answer", status); emit autoAnswerStatusChanged(status); } // ----------------------------------------------------------------------------- bool SettingsModel::getAutoAnswerVideoStatus () const { - return !!mConfig->getInt(UI_SECTION, "auto_answer_with_video", 0); + return !!mConfig->getInt(UiSection, "auto_answer_with_video", 0); } void SettingsModel::setAutoAnswerVideoStatus (bool status) { - mConfig->setInt(UI_SECTION, "auto_answer_with_video", status); + mConfig->setInt(UiSection, "auto_answer_with_video", status); emit autoAnswerVideoStatusChanged(status); } // ----------------------------------------------------------------------------- bool SettingsModel::getCallRecorderEnabled () const { - return !!mConfig->getInt(UI_SECTION, "call_recorder_enabled", 1); + return !!mConfig->getInt(UiSection, "call_recorder_enabled", 1); } void SettingsModel::setCallRecorderEnabled (bool status) { - mConfig->setInt(UI_SECTION, "call_recorder_enabled", status); + mConfig->setInt(UiSection, "call_recorder_enabled", status); emit callRecorderEnabledChanged(status); } // ----------------------------------------------------------------------------- bool SettingsModel::getChatEnabled () const { - return !!mConfig->getInt(UI_SECTION, "chat_enabled", 1); + return !!mConfig->getInt(UiSection, "chat_enabled", 1); } void SettingsModel::setChatEnabled (bool status) { - mConfig->setInt(UI_SECTION, "chat_enabled", status); + mConfig->setInt(UiSection, "chat_enabled", status); emit chatEnabledChanged(status); } // ----------------------------------------------------------------------------- bool SettingsModel::getChatNotificationSoundEnabled () const { - return !!mConfig->getInt(UI_SECTION, "chat_sound_notification_enabled", 1); + return !!mConfig->getInt(UiSection, "chat_sound_notification_enabled", 1); } void SettingsModel::setChatNotificationSoundEnabled (bool status) { - mConfig->setInt(UI_SECTION, "chat_sound_notification_enabled", status); + mConfig->setInt(UiSection, "chat_sound_notification_enabled", status); emit chatNotificationSoundEnabledChanged(status); } @@ -317,12 +316,12 @@ void SettingsModel::setChatNotificationSoundEnabled (bool status) { QString SettingsModel::getChatNotificationSoundPath () const { static const string defaultFile = linphone::Factory::get()->getSoundResourcesDir() + "/incoming_chat.wav"; - return Utils::coreStringToAppString(mConfig->getString(UI_SECTION, "chat_sound_notification_file", defaultFile)); + return Utils::coreStringToAppString(mConfig->getString(UiSection, "chat_sound_notification_file", defaultFile)); } void SettingsModel::setChatNotificationSoundPath (const QString &path) { QString cleanedPath = QDir::cleanPath(path); - mConfig->setString(UI_SECTION, "chat_sound_notification_file", Utils::appStringToCoreString(cleanedPath)); + mConfig->setString(UiSection, "chat_sound_notification_file", Utils::appStringToCoreString(cleanedPath)); emit chatNotificationSoundPathChanged(cleanedPath); } @@ -358,13 +357,13 @@ QVariantList SettingsModel::getSupportedMediaEncryptions () const { QVariantList list; if (core->mediaEncryptionSupported(linphone::MediaEncryptionDTLS)) - list << ::buildEncryptionDescription(MediaEncryptionDtls, "DTLS"); + list << buildEncryptionDescription(MediaEncryptionDtls, "DTLS"); if (core->mediaEncryptionSupported(linphone::MediaEncryptionSRTP)) - list << ::buildEncryptionDescription(MediaEncryptionSrtp, "SRTP"); + list << buildEncryptionDescription(MediaEncryptionSrtp, "SRTP"); if (core->mediaEncryptionSupported(linphone::MediaEncryptionZRTP)) - list << ::buildEncryptionDescription(MediaEncryptionZrtp, "ZRTP"); + list << buildEncryptionDescription(MediaEncryptionZrtp, "ZRTP"); return list; } @@ -706,12 +705,12 @@ void SettingsModel::setDscpVideo (int dscp) { // ----------------------------------------------------------------------------- bool SettingsModel::getRlsUriEnabled () const { - return !!mConfig->getInt(UI_SECTION, "rls_uri_enabled", true); + return !!mConfig->getInt(UiSection, "rls_uri_enabled", true); } void SettingsModel::setRlsUriEnabled (bool status) { - mConfig->setInt(UI_SECTION, "rls_uri_enabled", status); - mConfig->setString("sip", "rls_uri", status ? cDefaultRlsUri : ""); + mConfig->setInt(UiSection, "rls_uri_enabled", status); + mConfig->setString("sip", "rls_uri", status ? DefaultRlsUri : ""); emit rlsUriEnabledChanged(status); } @@ -720,7 +719,7 @@ static string getRlsUriDomain () { if (!domain.empty()) return domain; - shared_ptr linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(cDefaultRlsUri); + shared_ptr linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(DefaultRlsUri); Q_CHECK_PTR(linphoneAddress); domain = linphoneAddress->getDomain(); return domain; @@ -737,7 +736,7 @@ void SettingsModel::configureRlsUri () { const string domain = getRlsUriDomain(); for (const auto &proxyConfig : CoreManager::getInstance()->getCore()->getProxyConfigList()) if (proxyConfig->getDomain() == domain) { - mConfig->setString("sip", "rls_uri", cDefaultRlsUri); + mConfig->setString("sip", "rls_uri", DefaultRlsUri); return; } @@ -752,7 +751,7 @@ void SettingsModel::configureRlsUri (const shared_ptrgetDomain() == domain) { - mConfig->setString("sip", "rls_uri", cDefaultRlsUri); + mConfig->setString("sip", "rls_uri", DefaultRlsUri); return; } @@ -766,14 +765,14 @@ void SettingsModel::configureRlsUri (const shared_ptrgetString(UI_SECTION, "saved_screenshots_folder", Paths::getCapturesDirPath()) + mConfig->getString(UiSection, "saved_screenshots_folder", Paths::getCapturesDirPath()) ) ) + QDir::separator(); } void SettingsModel::setSavedScreenshotsFolder (const QString &folder) { QString cleanedFolder = QDir::cleanPath(folder) + QDir::separator(); - mConfig->setString(UI_SECTION, "saved_screenshots_folder", Utils::appStringToCoreString(cleanedFolder)); + mConfig->setString(UiSection, "saved_screenshots_folder", Utils::appStringToCoreString(cleanedFolder)); emit savedScreenshotsFolderChanged(cleanedFolder); } @@ -782,14 +781,14 @@ void SettingsModel::setSavedScreenshotsFolder (const QString &folder) { QString SettingsModel::getSavedVideosFolder () const { return QDir::cleanPath( Utils::coreStringToAppString( - mConfig->getString(UI_SECTION, "saved_videos_folder", Paths::getCapturesDirPath()) + mConfig->getString(UiSection, "saved_videos_folder", Paths::getCapturesDirPath()) ) ) + QDir::separator(); } void SettingsModel::setSavedVideosFolder (const QString &folder) { QString cleanedFolder = QDir::cleanPath(folder) + QDir::separator(); - mConfig->setString(UI_SECTION, "saved_videos_folder", Utils::appStringToCoreString(cleanedFolder)); + mConfig->setString(UiSection, "saved_videos_folder", Utils::appStringToCoreString(cleanedFolder)); emit savedVideosFolderChanged(cleanedFolder); } @@ -798,14 +797,14 @@ void SettingsModel::setSavedVideosFolder (const QString &folder) { QString SettingsModel::getDownloadFolder () const { return QDir::cleanPath( Utils::coreStringToAppString( - mConfig->getString(UI_SECTION, "download_folder", Paths::getDownloadDirPath()) + mConfig->getString(UiSection, "download_folder", Paths::getDownloadDirPath()) ) ) + QDir::separator(); } void SettingsModel::setDownloadFolder (const QString &folder) { QString cleanedFolder = QDir::cleanPath(folder) + QDir::separator(); - mConfig->setString(UI_SECTION, "download_folder", Utils::appStringToCoreString(cleanedFolder)); + mConfig->setString(UiSection, "download_folder", Utils::appStringToCoreString(cleanedFolder)); emit downloadFolderChanged(cleanedFolder); } @@ -825,11 +824,11 @@ void SettingsModel::setRemoteProvisioning (const QString &remoteProvisioning) { // ----------------------------------------------------------------------------- bool SettingsModel::getExitOnClose () const { - return !!mConfig->getInt(UI_SECTION, "exit_on_close", 0); + return !!mConfig->getInt(UiSection, "exit_on_close", 0); } void SettingsModel::setExitOnClose (bool value) { - mConfig->setInt(UI_SECTION, "exit_on_close", value); + mConfig->setInt(UiSection, "exit_on_close", value); emit exitOnCloseChanged(value); } @@ -844,7 +843,7 @@ QString SettingsModel::getLogsFolder () const { void SettingsModel::setLogsFolder (const QString &folder) { // Do not update path in linphone core. // Just update the config file. - mConfig->setString(UI_SECTION, "logs_folder", Utils::appStringToCoreString(folder)); + mConfig->setString(UiSection, "logs_folder", Utils::appStringToCoreString(folder)); emit logsFolderChanged(folder); } @@ -872,7 +871,7 @@ bool SettingsModel::getLogsEnabled () const { } void SettingsModel::setLogsEnabled (bool status) { - mConfig->setInt(UI_SECTION, "logs_enabled", status); + mConfig->setInt(UiSection, "logs_enabled", status); Logger::getInstance()->enable(status); emit logsEnabledChanged(status); } @@ -881,12 +880,12 @@ void SettingsModel::setLogsEnabled (bool status) { QString SettingsModel::getLogsEmail () const { return Utils::coreStringToAppString( - mConfig->getString(UI_SECTION, "logs_email", cDefaultLogsEmail) + mConfig->getString(UiSection, "logs_email", DefaultLogsEmail) ); } void SettingsModel::setLogsEmail (const QString &email) { - mConfig->setString(UI_SECTION, "logs_email", Utils::appStringToCoreString(email)); + mConfig->setString(UiSection, "logs_email", Utils::appStringToCoreString(email)); emit logsEmailChanged(email); } @@ -894,19 +893,19 @@ void SettingsModel::setLogsEmail (const QString &email) { QString SettingsModel::getLogsFolder (const shared_ptr &config) { return Utils::coreStringToAppString(config - ? config->getString(UI_SECTION, "logs_folder", Paths::getLogsDirPath()) + ? config->getString(UiSection, "logs_folder", Paths::getLogsDirPath()) : Paths::getLogsDirPath()); } bool SettingsModel::getLogsEnabled (const shared_ptr &config) { - return config ? config->getInt(UI_SECTION, "logs_enabled", false) : false; + return config ? config->getInt(UiSection, "logs_enabled", false) : false; } // --------------------------------------------------------------------------- bool SettingsModel::getDeveloperSettingsEnabled () const { #ifdef DEBUG - return !!mConfig->getInt(UI_SECTION, "developer_settings", 0); + return !!mConfig->getInt(UiSection, "developer_settings", 0); #else return false; #endif // ifdef DEBUG @@ -914,7 +913,7 @@ bool SettingsModel::getDeveloperSettingsEnabled () const { void SettingsModel::setDeveloperSettingsEnabled (bool status) { #ifdef DEBUG - mConfig->setInt(UI_SECTION, "developer_settings", status); + mConfig->setInt(UiSection, "developer_settings", status); emit developerSettingsEnabledChanged(status); #else qWarning() << QStringLiteral("Unable to change developer settings mode in release version."); diff --git a/src/components/settings/SettingsModel.hpp b/src/components/settings/SettingsModel.hpp index ed6112193..99fa927ed 100644 --- a/src/components/settings/SettingsModel.hpp +++ b/src/components/settings/SettingsModel.hpp @@ -148,7 +148,6 @@ public: MediaEncryptionSrtp = linphone::MediaEncryptionSRTP, MediaEncryptionZrtp = linphone::MediaEncryptionZRTP }; - Q_ENUM(MediaEncryption); enum LimeState { @@ -156,7 +155,6 @@ public: LimeStateMandatory = linphone::LimeStateMandatory, LimeStatePreferred = linphone::LimeStatePreferred }; - Q_ENUM(LimeState); SettingsModel (QObject *parent = Q_NULLPTR); @@ -346,7 +344,7 @@ public: bool getDeveloperSettingsEnabled () const; void setDeveloperSettingsEnabled (bool status); - static const std::string UI_SECTION; + static const std::string UiSection; // =========================================================================== // SIGNALS. @@ -446,6 +444,6 @@ private: std::shared_ptr mConfig; }; -Q_DECLARE_METATYPE(std::shared_ptr ); +Q_DECLARE_METATYPE(std::shared_ptr); #endif // SETTINGS_MODEL_H_ diff --git a/src/components/sip-addresses/SipAddressObserver.hpp b/src/components/sip-addresses/SipAddressObserver.hpp index 24bf2a533..0cf5e5b32 100644 --- a/src/components/sip-addresses/SipAddressObserver.hpp +++ b/src/components/sip-addresses/SipAddressObserver.hpp @@ -23,10 +23,12 @@ #ifndef SIP_ADDRESS_OBSERVER_H_ #define SIP_ADDRESS_OBSERVER_H_ -#include "../contact/ContactModel.hpp" +#include "components/presence/Presence.hpp" // ============================================================================= +class ContactModel; + class SipAddressObserver : public QObject { friend class SipAddressesModel; @@ -40,7 +42,6 @@ class SipAddressObserver : public QObject { public: SipAddressObserver (const QString &sipAddress); - ~SipAddressObserver () = default; signals: void contactChanged (ContactModel *contact); diff --git a/src/components/sip-addresses/SipAddressesModel.cpp b/src/components/sip-addresses/SipAddressesModel.cpp index f75b4ac1b..cf17d06a1 100644 --- a/src/components/sip-addresses/SipAddressesModel.cpp +++ b/src/components/sip-addresses/SipAddressesModel.cpp @@ -21,17 +21,24 @@ */ #include +#include -#include "../../utils/LinphoneUtils.hpp" -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/call/CallModel.hpp" +#include "components/chat/ChatModel.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/contacts/ContactsListModel.hpp" +#include "components/core/CoreHandlers.hpp" +#include "components/core/CoreManager.hpp" +#include "utils/LinphoneUtils.hpp" +#include "utils/Utils.hpp" #include "SipAddressesModel.hpp" -using namespace std; - // ============================================================================= +using namespace std; + SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(parent) { initSipAddresses(); @@ -129,7 +136,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip QString SipAddressesModel::getTransportFromSipAddress (const QString &sipAddress) const { const shared_ptr address = linphone::Factory::get()->createAddress( - ::Utils::appStringToCoreString(sipAddress) + Utils::appStringToCoreString(sipAddress) ); if (!address) @@ -151,26 +158,26 @@ QString SipAddressesModel::getTransportFromSipAddress (const QString &sipAddress QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress, const QString &transport) const { shared_ptr address = linphone::Factory::get()->createAddress( - ::Utils::appStringToCoreString(sipAddress) - ); + Utils::appStringToCoreString(sipAddress) + ); if (!address) return QString(""); address->setTransport(LinphoneUtils::stringToTransportType(transport.toUpper())); - return ::Utils::coreStringToAppString(address->asString()); + return Utils::coreStringToAppString(address->asString()); } // ----------------------------------------------------------------------------- QString SipAddressesModel::interpretSipAddress (const QString &sipAddress, bool checkUsername) { shared_ptr lAddress = CoreManager::getInstance()->getCore()->interpretUrl( - ::Utils::appStringToCoreString(sipAddress) - ); + Utils::appStringToCoreString(sipAddress) + ); if (lAddress && (!checkUsername || !lAddress->getUsername().empty())) - return ::Utils::coreStringToAppString(lAddress->asStringUriOnly()); + return Utils::coreStringToAppString(lAddress->asStringUriOnly()); return QString(""); } @@ -180,14 +187,14 @@ QString SipAddressesModel::interpretSipAddress (const QUrl &sipAddress) { bool SipAddressesModel::addressIsValid (const QString &address) { return !!linphone::Factory::get()->createAddress( - ::Utils::appStringToCoreString(address) + Utils::appStringToCoreString(address) ); } bool SipAddressesModel::sipAddressIsValid (const QString &sipAddress) { shared_ptr address = linphone::Factory::get()->createAddress( - ::Utils::appStringToCoreString(sipAddress) - ); + Utils::appStringToCoreString(sipAddress) + ); return address && !address->getUsername().empty(); } @@ -272,7 +279,7 @@ void SipAddressesModel::handleSipAddressRemoved (ContactModel *contact, const QS } void SipAddressesModel::handleMessageReceived (const shared_ptr &message) { - const QString sipAddress = ::Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly()); + const QString sipAddress = Utils::coreStringToAppString(message->getFromAddress()->asStringUriOnly()); addOrUpdateSipAddress(sipAddress, message); } @@ -286,7 +293,7 @@ void SipAddressesModel::handleCallStateChanged ( if (state == linphone::CallStateEnd || state == linphone::CallStateError) addOrUpdateSipAddress( - ::Utils::coreStringToAppString(call->getRemoteAddress()->asStringUriOnly()), call + Utils::coreStringToAppString(call->getRemoteAddress()->asStringUriOnly()), call ); } @@ -347,7 +354,7 @@ void SipAddressesModel::handleAllEntriesRemoved (const QString &sipAddress) { void SipAddressesModel::handleMessageSent (const shared_ptr &message) { addOrUpdateSipAddress( - ::Utils::coreStringToAppString(message->getToAddress()->asStringUriOnly()), + Utils::coreStringToAppString(message->getToAddress()->asStringUriOnly()), message ); } @@ -366,7 +373,7 @@ void SipAddressesModel::handleMessagesCountReset (const QString &sipAddress) { } void SipAddressesModel::handlerIsComposingChanged (const shared_ptr &chatRoom) { - auto it = mSipAddresses.find(::Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly())); + auto it = mSipAddresses.find(Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly())); if (it != mSipAddresses.end()) { (*it)["isComposing"] = chatRoom->isRemoteComposing(); @@ -469,12 +476,12 @@ void SipAddressesModel::initSipAddresses () { // Get sip addresses from chatrooms. for (const auto &chatRoom : core->getChatRooms()) { - list > history = chatRoom->getHistory(0); + list> history = chatRoom->getHistory(0); if (history.size() == 0) continue; - QString sipAddress = ::Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()); + QString sipAddress = Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()); QVariantMap map; map["sipAddress"] = sipAddress; @@ -487,7 +494,7 @@ void SipAddressesModel::initSipAddresses () { // Get sip addresses from calls. QSet addressDone; for (const auto &callLog : core->getCallLogs()) { - const QString sipAddress = ::Utils::coreStringToAppString(callLog->getRemoteAddress()->asStringUriOnly()); + const QString sipAddress = Utils::coreStringToAppString(callLog->getRemoteAddress()->asStringUriOnly()); if (addressDone.contains(sipAddress)) continue; // Already used. diff --git a/src/components/sip-addresses/SipAddressesModel.hpp b/src/components/sip-addresses/SipAddressesModel.hpp index 52ee2e7c1..a12cf0ea0 100644 --- a/src/components/sip-addresses/SipAddressesModel.hpp +++ b/src/components/sip-addresses/SipAddressesModel.hpp @@ -24,12 +24,13 @@ #define SIP_ADDRESSES_MODEL_H_ #include -#include #include "SipAddressObserver.hpp" // ============================================================================= +class QUrl; + class ChatModel; class CoreHandlers; @@ -38,7 +39,6 @@ class SipAddressesModel : public QAbstractListModel { public: SipAddressesModel (QObject *parent = Q_NULLPTR); - ~SipAddressesModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; diff --git a/src/components/sip-addresses/SipAddressesProxyModel.cpp b/src/components/sip-addresses/SipAddressesProxyModel.cpp index 563ae3a5b..61034dfe7 100644 --- a/src/components/sip-addresses/SipAddressesProxyModel.cpp +++ b/src/components/sip-addresses/SipAddressesProxyModel.cpp @@ -20,21 +20,24 @@ * Author: Ronan Abhamon */ -#include "../core/CoreManager.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/core/CoreManager.hpp" +#include "SipAddressesModel.hpp" #include "SipAddressesProxyModel.hpp" // ============================================================================= namespace { - constexpr int cWeightPos0 = 5; - constexpr int cWeightPos1 = 4; - constexpr int cWeightPos2 = 3; - constexpr int cWeightPos3 = 2; - constexpr int cWeightPosOther = 1; + constexpr int WeightPos0 = 5; + constexpr int WeightPos1 = 4; + constexpr int WeightPos2 = 3; + constexpr int WeightPos3 = 2; + constexpr int WeightPosOther = 1; } -const QRegExp SipAddressesProxyModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]"); +const QRegExp SipAddressesProxyModel::SearchSeparators("^[^_.-;@ ][_.-;@ ]"); // ----------------------------------------------------------------------------- @@ -111,19 +114,19 @@ int SipAddressesProxyModel::computeStringWeight (const QString &string) const { int offset = -1; while ((index = string.indexOf(mFilter, index + 1, Qt::CaseInsensitive)) != -1) { - int tmpOffset = index - string.lastIndexOf(mSearchSeparators, index) - 1; + int tmpOffset = index - string.lastIndexOf(SearchSeparators, index) - 1; if ((tmpOffset != -1 && tmpOffset < offset) || offset == -1) if ((offset = tmpOffset) == 0) break; } switch (offset) { case -1: return 0; - case 0: return cWeightPos0; - case 1: return cWeightPos1; - case 2: return cWeightPos2; - case 3: return cWeightPos3; + case 0: return WeightPos0; + case 1: return WeightPos1; + case 2: return WeightPos2; + case 3: return WeightPos3; default: break; } - return cWeightPosOther; + return WeightPosOther; } diff --git a/src/components/sip-addresses/SipAddressesProxyModel.hpp b/src/components/sip-addresses/SipAddressesProxyModel.hpp index 89a47e4c6..7b4e97a15 100644 --- a/src/components/sip-addresses/SipAddressesProxyModel.hpp +++ b/src/components/sip-addresses/SipAddressesProxyModel.hpp @@ -32,7 +32,6 @@ class SipAddressesProxyModel : public QSortFilterProxyModel { public: SipAddressesProxyModel (QObject *parent = Q_NULLPTR); - ~SipAddressesProxyModel () = default; Q_INVOKABLE void setFilter (const QString &pattern); @@ -46,7 +45,7 @@ private: QString mFilter; - static const QRegExp mSearchSeparators; + static const QRegExp SearchSeparators; }; #endif // SIP_ADDRESSES_PROXY_MODEL_H_ diff --git a/src/components/sound-player/SoundPlayer.cpp b/src/components/sound-player/SoundPlayer.cpp index 58f839ecd..7c02401a9 100644 --- a/src/components/sound-player/SoundPlayer.cpp +++ b/src/components/sound-player/SoundPlayer.cpp @@ -22,17 +22,18 @@ #include -#include "../../utils/Utils.hpp" -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" +#include "components/settings/SettingsModel.hpp" +#include "utils/Utils.hpp" #include "SoundPlayer.hpp" -using namespace std; - // ============================================================================= +using namespace std; + namespace { - int cForceCloseTimerInterval = 20; + int ForceCloseTimerInterval = 20; } class SoundPlayer::Handlers : public linphone::PlayerListener { @@ -60,7 +61,7 @@ private: SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) { mForceCloseTimer = new QTimer(this); - mForceCloseTimer->setInterval(cForceCloseTimerInterval); + mForceCloseTimer->setInterval(ForceCloseTimerInterval); QObject::connect(mForceCloseTimer, &QTimer::timeout, this, &SoundPlayer::handleEof); @@ -98,7 +99,7 @@ void SoundPlayer::play () { if ( (mPlaybackState == SoundPlayer::StoppedState || mPlaybackState == SoundPlayer::ErrorState) && - mInternalPlayer->open(::Utils::appStringToCoreString(mSource)) + mInternalPlayer->open(Utils::appStringToCoreString(mSource)) ) { qWarning() << QStringLiteral("Unable to open: `%1`").arg(mSource); return; @@ -140,8 +141,8 @@ void SoundPlayer::buildInternalPlayer () { SettingsModel *settingsModel = coreManager->getSettingsModel(); mInternalPlayer = coreManager->getCore()->createLocalPlayer( - ::Utils::appStringToCoreString(settingsModel->getRingerDevice()), "", nullptr - ); + Utils::appStringToCoreString(settingsModel->getRingerDevice()), "", nullptr + ); mInternalPlayer->setListener(mHandlers); QObject::connect(settingsModel, &SettingsModel::ringerDeviceChanged, this, [this] { diff --git a/src/components/sound-player/SoundPlayer.hpp b/src/components/sound-player/SoundPlayer.hpp index 1f5d3e4c4..9d68f2bdb 100644 --- a/src/components/sound-player/SoundPlayer.hpp +++ b/src/components/sound-player/SoundPlayer.hpp @@ -52,7 +52,6 @@ public: StoppedState, ErrorState }; - Q_ENUM(PlaybackState); SoundPlayer (QObject *parent = Q_NULLPTR); diff --git a/src/components/telephone-numbers/TelephoneNumbersModel.cpp b/src/components/telephone-numbers/TelephoneNumbersModel.cpp index 2afb3a39c..8aefd1a6c 100644 --- a/src/components/telephone-numbers/TelephoneNumbersModel.cpp +++ b/src/components/telephone-numbers/TelephoneNumbersModel.cpp @@ -22,11 +22,11 @@ #include "TelephoneNumbersModel.hpp" -using namespace std; - // ============================================================================= -const QList > TelephoneNumbersModel::mCountryCodes = { +using namespace std; + +const QList> TelephoneNumbersModel::mCountryCodes = { { QLocale::Afghanistan, "93" }, { QLocale::Albania, "355" }, { QLocale::Algeria, "213" }, @@ -289,9 +289,9 @@ QVariant TelephoneNumbersModel::data (const QModelIndex &index, int role) const int TelephoneNumbersModel::getDefaultIndex () const { QLocale::Country country = QLocale().country(); const auto it = find_if( - mCountryCodes.cbegin(), mCountryCodes.cend(), [&country](const QPair &pair) { - return country == pair.first; - } - ); + mCountryCodes.cbegin(), mCountryCodes.cend(), [&country](const QPair &pair) { + return country == pair.first; + } + ); return it != mCountryCodes.cend() ? int(distance(mCountryCodes.cbegin(), it)) : 0; } diff --git a/src/components/telephone-numbers/TelephoneNumbersModel.hpp b/src/components/telephone-numbers/TelephoneNumbersModel.hpp index 8be6722b8..4918f038d 100644 --- a/src/components/telephone-numbers/TelephoneNumbersModel.hpp +++ b/src/components/telephone-numbers/TelephoneNumbersModel.hpp @@ -35,7 +35,6 @@ class TelephoneNumbersModel : public QAbstractListModel { public: TelephoneNumbersModel (QObject *parent = Q_NULLPTR); - ~TelephoneNumbersModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; @@ -45,7 +44,7 @@ public: private: int getDefaultIndex () const; - static const QList > mCountryCodes; + static const QList> mCountryCodes; }; #endif // ifndef TELEPHONE_NUMBERS_MODEL_H_ diff --git a/src/components/timeline/TimelineModel.cpp b/src/components/timeline/TimelineModel.cpp index 5386adaa6..d8513bca4 100644 --- a/src/components/timeline/TimelineModel.cpp +++ b/src/components/timeline/TimelineModel.cpp @@ -20,7 +20,8 @@ * Author: Ronan Abhamon */ -#include "../core/CoreManager.hpp" +#include "components/core/CoreManager.hpp" +#include "components/sip-addresses/SipAddressesModel.hpp" #include "TimelineModel.hpp" diff --git a/src/components/timeline/TimelineModel.hpp b/src/components/timeline/TimelineModel.hpp index 394ee68a4..b8e778da5 100644 --- a/src/components/timeline/TimelineModel.hpp +++ b/src/components/timeline/TimelineModel.hpp @@ -32,7 +32,6 @@ class TimelineModel : public QSortFilterProxyModel { public: TimelineModel (QObject *parent = Q_NULLPTR); - ~TimelineModel () = default; QHash roleNames () const override; diff --git a/src/components/url-handlers/UrlHandlers.cpp b/src/components/url-handlers/UrlHandlers.cpp index 1e9c6116b..0023dcab2 100644 --- a/src/components/url-handlers/UrlHandlers.cpp +++ b/src/components/url-handlers/UrlHandlers.cpp @@ -22,7 +22,7 @@ #include -#include "../sip-addresses/SipAddressesModel.hpp" +#include "components/sip-addresses/SipAddressesModel.hpp" #include "UrlHandlers.hpp" diff --git a/src/components/url-handlers/UrlHandlers.hpp b/src/components/url-handlers/UrlHandlers.hpp index beded2ee5..5d976cb1a 100644 --- a/src/components/url-handlers/UrlHandlers.hpp +++ b/src/components/url-handlers/UrlHandlers.hpp @@ -32,7 +32,6 @@ class UrlHandlers : public QObject { public: UrlHandlers (QObject *parent = Q_NULLPTR); - ~UrlHandlers () = default; public slots: void handleSip (const QUrl &url); diff --git a/src/utils/LinphoneUtils.cpp b/src/utils/LinphoneUtils.cpp index dce537b4b..02f99d234 100644 --- a/src/utils/LinphoneUtils.cpp +++ b/src/utils/LinphoneUtils.cpp @@ -20,6 +20,8 @@ * Author: Ronan Abhamon */ +#include + #include "LinphoneUtils.hpp" // ============================================================================= diff --git a/src/utils/LinphoneUtils.hpp b/src/utils/LinphoneUtils.hpp index ed1773174..bb0a7518a 100644 --- a/src/utils/LinphoneUtils.hpp +++ b/src/utils/LinphoneUtils.hpp @@ -24,29 +24,27 @@ #define LINPHONE_UTILS_H_ #include -#include // ============================================================================= -#define WINDOW_ICON_PATH ":/assets/images/linphone_logo.svg" - -#define VU_MIN (-20.f) -#define VU_MAX (4.f) +class QString; namespace LinphoneUtils { inline float computeVu (float volume) { - if (volume < VU_MIN) + constexpr float VuMin = -20.f; + constexpr float VuMax = 4.f; + + if (volume < VuMin) return 0.f; - if (volume > VU_MAX) + if (volume > VuMax) return 1.f; - return (volume - VU_MIN) / (VU_MAX - VU_MIN); + return (volume - VuMin) / (VuMax - VuMin); } linphone::TransportType stringToTransportType (const QString &transport); + + static constexpr char WindowIconPath[] = ":/assets/images/linphone_logo.svg"; } -#undef VU_MIN -#undef VU_MAX - #endif // ifndef LINPHONE_UTILS_H_ diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index c8b3603bd..db9ff3270 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -27,7 +27,7 @@ // ============================================================================= namespace { - constexpr int cSafeFilePathLimit = 100; + constexpr int SafeFilePathLimit = 100; } char *Utils::rstrstr (const char *a, const char *b) { @@ -58,7 +58,7 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) { const QString prefix = QStringLiteral("%1/%2").arg(info.absolutePath()).arg(info.baseName()); const QString ext = info.completeSuffix(); - for (int i = 1; i < cSafeFilePathLimit; ++i) { + for (int i = 1; i < SafeFilePathLimit; ++i) { QString safePath = QStringLiteral("%1 (%3).%4").arg(prefix).arg(i).arg(ext); if (!QFileInfo::exists(safePath)) return safePath;