From 4d375b1f3535008f001feb708979e7999839bcff Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 24 Aug 2021 18:55:14 +0200 Subject: [PATCH] Centralize constants + fix on conference URI by using defaults --- linphone-app/CMakeLists.txt | 20 +-- linphone-app/src/app/App.cpp | 55 +++---- linphone-app/src/app/AppController.cpp | 10 +- linphone-app/src/app/logger/Logger.cpp | 18 +-- linphone-app/src/app/paths/Paths.cpp | 64 +++----- .../src/app/providers/ImageProvider.cpp | 9 +- .../components/assistant/AssistantModel.cpp | 7 +- .../chat-events/ChatMessageModel.cpp | 28 +--- .../components/chat-room/ChatRoomModel.cpp | 13 +- .../components/codecs/VideoCodecsModel.cpp | 31 +--- .../src/components/contact/VcardModel.cpp | 13 +- .../src/components/core/CoreManager.cpp | 42 ++--- .../EventCountNotifierSystemTrayIcon.cpp | 3 +- .../src/components/file/FileExtractor.cpp | 7 +- .../settings/AccountSettingsModel.cpp | 7 +- .../src/components/settings/SettingsModel.cpp | 16 +- linphone-app/src/utils/Constants.cpp | 105 +++++++++++++ linphone-app/src/utils/Constants.hpp | 144 ++++++++++++++++++ linphone-app/src/utils/LinphoneUtils.cpp | 55 ------- linphone-app/src/utils/LinphoneUtils.hpp | 41 ----- linphone-app/src/utils/Utils.cpp | 1 - linphone-app/src/utils/Utils.hpp | 4 +- .../ui/views/App/Main/Dialogs/NewChatRoom.qml | 4 +- 23 files changed, 360 insertions(+), 337 deletions(-) create mode 100644 linphone-app/src/utils/Constants.cpp create mode 100644 linphone-app/src/utils/Constants.hpp delete mode 100644 linphone-app/src/utils/LinphoneUtils.cpp delete mode 100644 linphone-app/src/utils/LinphoneUtils.hpp diff --git a/linphone-app/CMakeLists.txt b/linphone-app/CMakeLists.txt index ef18d84a3..050c052ef 100644 --- a/linphone-app/CMakeLists.txt +++ b/linphone-app/CMakeLists.txt @@ -190,15 +190,16 @@ set(SOURCES src/components/timeline/TimelineListModel.cpp src/components/timeline/TimelineProxyModel.cpp src/components/url-handlers/UrlHandlers.cpp - src/utils/LinphoneEnums.cpp + src/utils/Constants.cpp + src/utils/LinphoneEnums.cpp src/utils/MediastreamerUtils.cpp src/utils/QExifImageHeader.cpp src/utils/Utils.cpp - src/utils/hacks/ChatRoomInitializer.cpp - src/utils/plugins/PluginsManager.cpp + src/utils/hacks/ChatRoomInitializer.cpp + src/utils/plugins/PluginsManager.cpp ) set(PLUGIN_SOURCES src/utils/plugins/PluginDataAPI.cpp - src/utils/plugins/PluginNetworkHelper.cpp + src/utils/plugins/PluginNetworkHelper.cpp src/utils/plugins/LinphonePlugin.cpp ) @@ -283,7 +284,7 @@ set(HEADERS src/components/settings/SettingsModel.hpp src/components/sip-addresses/SipAddressesModel.hpp src/components/sip-addresses/SipAddressesProxyModel.hpp - src/components/sip-addresses/SipAddressesSorter.hpp + src/components/sip-addresses/SipAddressesSorter.hpp src/components/sip-addresses/SipAddressObserver.hpp src/components/sound-player/SoundPlayer.hpp src/components/telephone-numbers/TelephoneNumbersModel.hpp @@ -291,17 +292,18 @@ set(HEADERS src/components/timeline/TimelineListModel.hpp src/components/timeline/TimelineProxyModel.hpp src/components/url-handlers/UrlHandlers.hpp - src/utils/LinphoneEnums.hpp + src/utils/Constants.hpp + src/utils/LinphoneEnums.hpp src/utils/MediastreamerUtils.hpp src/utils/QExifImageHeader.hpp src/utils/Utils.hpp - src/utils/hacks/ChatRoomInitializer.hpp + src/utils/hacks/ChatRoomInitializer.hpp src/utils/plugins/PluginsManager.hpp ) set(PLUGIN_HEADERS - include/LinphoneApp/PluginDataAPI.hpp + include/LinphoneApp/PluginDataAPI.hpp include/LinphoneApp/PluginNetworkHelper.hpp - include/LinphoneApp/LinphonePlugin.hpp) + include/LinphoneApp/LinphonePlugin.hpp) list(APPEND SOURCES include/LinphoneApp/PluginExample.json) set(MAIN_FILE src/app/main.cpp) diff --git a/linphone-app/src/app/App.cpp b/linphone-app/src/app/App.cpp index f7a49385e..9e410cea8 100644 --- a/linphone-app/src/app/App.cpp +++ b/linphone-app/src/app/App.cpp @@ -45,6 +45,7 @@ #include "providers/ThumbnailProvider.hpp" #include "translator/DefaultTranslator.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "components/other/desktop-tools/DesktopTools.hpp" #include "components/timeline/TimelineModel.hpp" @@ -60,26 +61,6 @@ using namespace std; namespace { - constexpr char DefaultLocale[] = "en"; - - constexpr char LanguagePath[] = ":/languages/"; - - // The main windows of Linphone desktop. - 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"; - - #ifdef ENABLE_UPDATE_CHECK - constexpr int VersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds. - #endif // ifdef ENABLE_UPDATE_CHECK - - constexpr char MainQmlUri[] = "Linphone"; - - constexpr char AttachVirtualWindowMethodName[] = "attachVirtualWindow"; - constexpr char AboutPath[] = "qrc:/ui/views/App/Main/Dialogs/About.qml"; - - constexpr char AssistantViewName[] = "Assistant"; - #ifdef Q_OS_LINUX const QString AutoStartDirectory(QDir::homePath().append(QStringLiteral("/.config/autostart/"))); #elif defined(Q_OS_MACOS) @@ -160,7 +141,7 @@ namespace { // ----------------------------------------------------------------------------- static inline bool installLocale (App &app, QTranslator &translator, const QLocale &locale) { - return translator.load(locale, LanguagePath) && app.installTranslator(&translator); + return translator.load(locale, Constants::LanguagePath) && app.installTranslator(&translator); } static inline string getConfigPathIfExists (const QCommandLineParser &parser) { @@ -221,7 +202,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U connect(this, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(stateChanged(Qt::ApplicationState))); - setWindowIcon(QIcon(Utils::WindowIconPath)); + setWindowIcon(QIcon(Constants::WindowIconPath)); createParser(); mParser->process(*this); @@ -233,7 +214,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U Logger::getInstance()->setVerbose(true); // List available locales. - for (const auto &locale : QDir(LanguagePath).entryList()) + for (const auto &locale : QDir(Constants::LanguagePath).entryList()) mAvailableLocales << QLocale(locale); // Init locale. @@ -409,7 +390,7 @@ void App::initContentApp () { // Load main view. qInfo() << QStringLiteral("Loading main view..."); - mEngine->load(QUrl(QmlViewMainWindow)); + mEngine->load(QUrl(Constants::QmlViewMainWindow)); if (mEngine->rootObjects().isEmpty()) qFatal("Unable to open main window."); @@ -535,7 +516,7 @@ static QObject *makeSharedSingleton (QQmlEngine *, QJSEngine *) { template static inline void registerSharedSingletonType (const char *name) { - qmlRegisterSingletonType(MainQmlUri, 1, 0, name, makeSharedSingleton); + qmlRegisterSingletonType(Constants::MainQmlUri, 1, 0, name, makeSharedSingleton); } template @@ -547,24 +528,24 @@ static QObject *makeSharedSingleton (QQmlEngine *, QJSEngine *) { template static inline void registerSharedSingletonType (const char *name) { - qmlRegisterSingletonType(MainQmlUri, 1, 0, name, makeSharedSingleton); + qmlRegisterSingletonType(Constants::MainQmlUri, 1, 0, name, makeSharedSingleton); } template static inline void registerUncreatableType (const char *name) { - qmlRegisterUncreatableType(MainQmlUri, 1, 0, name, QLatin1String("Uncreatable")); + qmlRegisterUncreatableType(Constants::MainQmlUri, 1, 0, name, QLatin1String("Uncreatable")); } template static inline void registerSingletonType (const char *name) { - qmlRegisterSingletonType(MainQmlUri, 1, 0, name, [](QQmlEngine *engine, QJSEngine *) -> QObject *{ + qmlRegisterSingletonType(Constants::MainQmlUri, 1, 0, name, [](QQmlEngine *engine, QJSEngine *) -> QObject *{ return new T(engine); }); } template static inline void registerType (const char *name) { - qmlRegisterType(MainQmlUri, 1, 0, name); + qmlRegisterType(Constants::MainQmlUri, 1, 0, name); } template @@ -718,8 +699,8 @@ void App::setTrayIcon () { root->connect(aboutAction, &QAction::triggered, root, [root] { App::smartShowWindow(root); QMetaObject::invokeMethod( - root, AttachVirtualWindowMethodName, Qt::DirectConnection, - Q_ARG(QVariant, QUrl(AboutPath)), Q_ARG(QVariant, QVariant()), Q_ARG(QVariant, QVariant()) + root, Constants::AttachVirtualWindowMethodName, Qt::DirectConnection, + Q_ARG(QVariant, QUrl(Constants::AboutPath)), Q_ARG(QVariant, QVariant()), Q_ARG(QVariant, QVariant()) ); }); @@ -755,7 +736,7 @@ void App::setTrayIcon () { systemTrayIcon->setContextMenu(menu); - systemTrayIcon->setIcon(QIcon(Utils::WindowIconPath)); + systemTrayIcon->setIcon(QIcon(Constants::WindowIconPath)); systemTrayIcon->setToolTip(APPLICATION_NAME); systemTrayIcon->show(); mSystemTrayIcon = systemTrayIcon; @@ -770,7 +751,7 @@ void App::initLocale (const shared_ptr &config) { QString locale; // Use english. This default translator is used if there are no found translations in others loads - mLocale = DefaultLocale; + mLocale = Constants::DefaultLocale; if (!installLocale(*this, *mDefaultTranslator, QLocale(mLocale))) qFatal("Unable to install default translator."); @@ -929,8 +910,8 @@ void App::openAppAfterInit (bool mustBeIconified) { qInfo() << QStringLiteral("Open " APPLICATION_NAME " app."); auto coreManager = CoreManager::getInstance(); // Create other windows. - mCallsWindow = createSubWindow(mEngine, QmlViewCallsWindow); - mSettingsWindow = createSubWindow(mEngine, QmlViewSettingsWindow); + mCallsWindow = createSubWindow(mEngine, Constants::QmlViewCallsWindow); + mSettingsWindow = createSubWindow(mEngine, Constants::QmlViewSettingsWindow); QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [coreManager](QWindow::Visibility visibility) { if (visibility == QWindow::Hidden) { qInfo() << QStringLiteral("Update nat policy."); @@ -951,11 +932,11 @@ void App::openAppAfterInit (bool mustBeIconified) { // Display Assistant if it does not exist proxy config. if (coreManager->getCore()->getAccountList().empty()) - QMetaObject::invokeMethod(mainWindow, "setView", Q_ARG(QVariant, AssistantViewName), Q_ARG(QVariant, QString(""))); + QMetaObject::invokeMethod(mainWindow, "setView", Q_ARG(QVariant, Constants::AssistantViewName), Q_ARG(QVariant, QString(""))); #ifdef ENABLE_UPDATE_CHECK QTimer *timer = new QTimer(mEngine); - timer->setInterval(VersionUpdateCheckInterval); + timer->setInterval(Constants::VersionUpdateCheckInterval); QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate); timer->start(); diff --git a/linphone-app/src/app/AppController.cpp b/linphone-app/src/app/AppController.cpp index aea9bddb9..95423c241 100644 --- a/linphone-app/src/app/AppController.cpp +++ b/linphone-app/src/app/AppController.cpp @@ -29,18 +29,14 @@ #include "AppController.hpp" #include "components/other/desktop-tools/DesktopTools.hpp" +#include "utils/Constants.hpp" // ============================================================================= using namespace std; -namespace { - constexpr char ApplicationMinimalQtVersion[] = "5.9.0"; - constexpr char DefaultFont[] = "Noto Sans"; -} - AppController::AppController (int &argc, char *argv[]) { DesktopTools::init(); - QT_REQUIRE_VERSION(argc, argv, ApplicationMinimalQtVersion) + QT_REQUIRE_VERSION(argc, argv, Constants::ApplicationMinimalQtVersion) Q_ASSERT(!mApp); // Disable QML cache. Avoid malformed cache. qputenv("QML_DISABLE_DISK_CACHE", "true"); @@ -99,7 +95,7 @@ AppController::AppController (int &argc, char *argv[]) { } qInfo() << "Available fonts : " << QFontDatabase().families(); - mApp->setFont(QFont(DefaultFont)); + mApp->setFont(QFont(Constants::DefaultFont)); } AppController::~AppController () { diff --git a/linphone-app/src/app/logger/Logger.cpp b/linphone-app/src/app/logger/Logger.cpp index f66363d14..e75c9a32f 100644 --- a/linphone-app/src/app/logger/Logger.cpp +++ b/linphone-app/src/app/logger/Logger.cpp @@ -29,7 +29,7 @@ #include "components/settings/SettingsModel.hpp" #include "utils/Utils.hpp" - +#include "utils/Constants.hpp" #include "Logger.hpp" // ============================================================================= @@ -52,12 +52,6 @@ using namespace std; -namespace { - constexpr char QtDomain[] = "qt"; - constexpr size_t MaxLogsCollectionSize = 10485760; // 10MB. - constexpr char SrcPattern[] = "/src/"; -} - QMutex Logger::mMutex; Logger *Logger::mInstance; @@ -152,10 +146,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, SrcPattern) : file; + const char *pos = file ? Utils::rstrstr(file, Constants::SrcPattern) : file; contextArr = QStringLiteral("%1:%2: ") - .arg(pos ? pos + sizeof(SrcPattern) - 1 : file) + .arg(pos ? pos + sizeof(Constants::SrcPattern) - 1 : file) .arg(context.line) .toLocal8Bit(); contextStr = contextArr.constData(); @@ -172,7 +166,7 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri fprintf(stdout, format, dateTime.constData(), QThread::currentThread(), contextStr, localMsg.constData()); if( level == BCTBX_LOG_FATAL) QMessageBox::critical(nullptr, "Linphone will crash", msg); // Print an error message before sending msg to bctoolbox - bctbx_log(QtDomain, level, "QT: %s%s", contextStr, localMsg.constData()); + bctbx_log(Constants::QtDomain, level, "QT: %s%s", contextStr, localMsg.constData()); mMutex.unlock(); @@ -203,14 +197,14 @@ void Logger::init (const shared_ptr &config) { { shared_ptr loggingService = mInstance->mLoggingService = linphone::LoggingService::get(); - loggingService->setDomain(QtDomain); + loggingService->setDomain(Constants::QtDomain); loggingService->setLogLevel(linphone::LogLevel::Message); loggingService->addListener(make_shared(mInstance)); } linphone::Core::setLogCollectionPath(Utils::appStringToCoreString(folder)); linphone::Core::setLogCollectionPrefix(EXECUTABLE_NAME); - linphone::Core::setLogCollectionMaxFileSize(MaxLogsCollectionSize); + linphone::Core::setLogCollectionMaxFileSize(Constants::MaxLogsCollectionSize); mInstance->enable(SettingsModel::getLogsEnabled(config)); } diff --git a/linphone-app/src/app/paths/Paths.cpp b/linphone-app/src/app/paths/Paths.cpp index bcefcf272..91ec227c6 100644 --- a/linphone-app/src/app/paths/Paths.cpp +++ b/linphone-app/src/app/paths/Paths.cpp @@ -27,6 +27,7 @@ #include "config.h" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "Paths.hpp" @@ -34,31 +35,6 @@ using namespace std; -namespace { - constexpr char PathAssistantConfig[] = "/" EXECUTABLE_NAME "/assistant/"; - constexpr char PathAvatars[] = "/avatars/"; - constexpr char PathCaptures[] = "/" EXECUTABLE_NAME "/captures/"; - constexpr char PathCodecs[] = "/codecs/"; - constexpr char PathTools[] = "/tools/"; - constexpr char PathLogs[] = "/logs/"; -#ifdef APPLE - constexpr char PathPlugins[] = "/Plugins/"; -#else - constexpr char PathPlugins[] = "/plugins/"; -#endif - constexpr char PathPluginsApp[] = "app/"; - constexpr char PathThumbnails[] = "/thumbnails/"; - constexpr char PathUserCertificates[] = "/usr-crt/"; - - constexpr char PathCallHistoryList[] = "/call-history.db"; - constexpr char PathConfig[] = "/linphonerc"; - constexpr char PathFactoryConfig[] = "/" EXECUTABLE_NAME "/linphonerc-factory"; - constexpr char PathRootCa[] = "/" EXECUTABLE_NAME "/rootca.pem"; - constexpr char PathFriendsList[] = "/friends.db"; - constexpr char PathMessageHistoryList[] = "/message-history.db"; - constexpr char PathZrtpSecrets[] = "/zidcache"; -} - static inline bool dirPathExists (const QString &path) { QDir dir(path); return dir.exists(); @@ -165,39 +141,39 @@ static inline QString getAppPackageMsPluginsDirPath () { } static inline QString getAppPackagePluginsDirPath () { - return getAppPackageDir().absolutePath() + PathPlugins; + return getAppPackageDir().absolutePath() + Constants::PathPlugins; } static inline QString getAppAssistantConfigDirPath () { - return getAppPackageDataDirPath() + PathAssistantConfig; + return getAppPackageDataDirPath() + Constants::PathAssistantConfig; } static inline QString getAppConfigFilePath () { - return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PathConfig; + return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + Constants::PathConfig; } static inline QString getAppCallHistoryFilePath () { - return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathCallHistoryList; + return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathCallHistoryList; } static inline QString getAppFactoryConfigFilePath () { - return getAppPackageDataDirPath() + PathFactoryConfig; + return getAppPackageDataDirPath() + Constants::PathFactoryConfig; } static inline QString getAppRootCaFilePath () { - return getAppPackageDataDirPath() + PathRootCa; + return getAppPackageDataDirPath() + Constants::PathRootCa; } static inline QString getAppFriendsFilePath () { - return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathFriendsList; + return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathFriendsList; } static inline QString getAppMessageHistoryFilePath () { - return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathMessageHistoryList; + return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathMessageHistoryList; } static inline QString getAppPluginsDirPath () { - return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+ PathPlugins; + return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+ Constants::PathPlugins; } // ----------------------------------------------------------------------------- @@ -212,7 +188,7 @@ string Paths::getAssistantConfigDirPath () { } string Paths::getAvatarsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathAvatars); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathAvatars); } string Paths::getCallHistoryFilePath () { @@ -220,11 +196,11 @@ string Paths::getCallHistoryFilePath () { } string Paths::getCapturesDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + PathCaptures); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + Constants::PathCaptures); } string Paths::getCodecsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathCodecs); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathCodecs); } string Paths::getConfigDirPath (bool writable) { @@ -262,7 +238,7 @@ string Paths::getDownloadDirPath () { } string Paths::getLogsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathLogs); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathLogs); } string Paths::getMessageHistoryFilePath () { @@ -278,11 +254,11 @@ string Paths::getPackageMsPluginsDirPath () { } string Paths::getPackagePluginsAppDirPath () { - return getReadableDirPath(getAppPackagePluginsDirPath()+PathPluginsApp); + return getReadableDirPath(getAppPackagePluginsDirPath() + Constants::PathPluginsApp); } string Paths::getPluginsAppDirPath () { - return getWritableDirPath(getAppPluginsDirPath()+PathPluginsApp); + return getWritableDirPath(getAppPluginsDirPath() + Constants::PathPluginsApp); } QStringList Paths::getPluginsAppFolders() { @@ -297,17 +273,17 @@ string Paths::getRootCaFilePath () { } string Paths::getThumbnailsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathThumbnails); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathThumbnails); } string Paths::getToolsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathTools); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathTools); } string Paths::getUserCertificatesDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathUserCertificates); + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathUserCertificates); } string Paths::getZrtpSecretsFilePath () { - return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PathZrtpSecrets); + return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathZrtpSecrets); } // ----------------------------------------------------------------------------- diff --git a/linphone-app/src/app/providers/ImageProvider.cpp b/linphone-app/src/app/providers/ImageProvider.cpp index a12d39fbe..8c0c96340 100644 --- a/linphone-app/src/app/providers/ImageProvider.cpp +++ b/linphone-app/src/app/providers/ImageProvider.cpp @@ -33,15 +33,12 @@ #include "components/other/images/ImageListModel.hpp" #include "components/other/images/ImageModel.hpp" +#include "utils/Constants.hpp" + // ============================================================================= using namespace std; -namespace { -// Max image size in bytes. (100Kb) -constexpr qint64 MaxImageSize = 102400; -} - static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QString &name) { auto it = find_if(readerAttributes.cbegin(), readerAttributes.cend(), [&name](const QXmlStreamAttribute &attribute) { return name == attribute.name() && !attribute.prefix().length(); @@ -267,7 +264,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize return QImage(); } - if (Q_UNLIKELY(QFileInfo(file).size() > MaxImageSize)) { + if (Q_UNLIKELY(QFileInfo(file).size() > Constants::MaxImageSize)) { qWarning() << QStringLiteral("Unable to open large file: `%1`.").arg(path); return QImage(); } diff --git a/linphone-app/src/components/assistant/AssistantModel.cpp b/linphone-app/src/components/assistant/AssistantModel.cpp index 6f3b8e8dc..e26b7d8a4 100644 --- a/linphone-app/src/components/assistant/AssistantModel.cpp +++ b/linphone-app/src/components/assistant/AssistantModel.cpp @@ -24,6 +24,7 @@ #include "components/settings/SettingsModel.hpp" #include "components/sip-addresses/SipAddressesModel.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "AssistantModel.hpp" @@ -33,10 +34,6 @@ using namespace std; -namespace { - constexpr char DefaultXmlrpcUri[] = "https://subscribe.linphone.org:444/wizard.php"; -} - class AssistantModel::Handlers : public linphone::AccountCreatorListener { public: Handlers (AssistantModel *assistant) { @@ -151,7 +148,7 @@ AssistantModel::AssistantModel (QObject *parent) : QObject(parent) { shared_ptr core = CoreManager::getInstance()->getCore(); mAccountCreator = core->createAccountCreator( - core->getConfig()->getString("assistant", "xmlrpc_url", DefaultXmlrpcUri) + core->getConfig()->getString("assistant", "xmlrpc_url", Constants::DefaultXmlrpcUri) ); mAccountCreator->addListener(mHandlers); } diff --git a/linphone-app/src/components/chat-events/ChatMessageModel.cpp b/linphone-app/src/components/chat-events/ChatMessageModel.cpp index 5d86af197..f976496f4 100644 --- a/linphone-app/src/components/chat-events/ChatMessageModel.cpp +++ b/linphone-app/src/components/chat-events/ChatMessageModel.cpp @@ -46,33 +46,9 @@ #include "components/settings/SettingsModel.hpp" #include "utils/QExifImageHeader.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" // ============================================================================= -namespace { -constexpr int ThumbnailImageFileWidth = 100; -constexpr int ThumbnailImageFileHeight = 100; - -// In Bytes. -constexpr qint64 FileSizeLimit = 524288000; -} -/* -std::shared_ptr ChatMessageModel::ChatMessageListener::create(ChatMessageModel * model, std::shared_ptr chatMessage, QObject * parent){// Call it instead constructor - auto listener = std::shared_ptr(new ChatMessageModel::ChatMessageListener::ChatMessageListener(model,chatMessage, parent), [model](ChatMessageModel::ChatMessageListener::ChatMessageListener * listener){ - chatMessage->removeListener(model->getHandler()); - }); - chatMessage->addListener(listener); - return model; -} - -ChatMessageModel::ChatMessageListener::ChatMessageListener(ChatMessageModel * model, std::shared_ptr chatMessage, QObject * parent){ - connect(this, &ChatMessageModel::ChatMessageListener::onFileTransferSend, model, ChatMessageModel::onFileTransferSend); - connect(this, &ChatMessageModel::ChatMessageListener::onFileTransferProgressIndication, model, ChatMessageModel::onFileTransferProgressIndication); - connect(this, &ChatMessageModel::ChatMessageListener::onMsgStateChanged, model, ChatMessageModel::onMsgStateChanged); -} -ChatMessageModel::ChatMessageListener::~ChatMessageListener(){ - -} -*/ // Warning : isFileTransfer/isFile/getpath cannot be used for Content that comes from linphone::ChatMessage::getContents(). That lead to a crash. // in SDK there is this note : return c->isFile(); // TODO FIXME this doesn't work when Content is from linphone_chat_message_get_contents() list @@ -169,7 +145,7 @@ void ContentModel::createThumbnail () { if (exifImageHeader.loadFromJpeg(path)) rotation = int(exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort()); QImage thumbnail = image.scaled( - ThumbnailImageFileWidth, ThumbnailImageFileHeight, + Constants::ThumbnailImageFileWidth, Constants::ThumbnailImageFileHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 43f4b94c2..0f0a19df5 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -57,6 +57,7 @@ #include "components/core/event-count-notifier/AbstractEventCountNotifier.hpp" #include "utils/QExifImageHeader.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "utils/LinphoneEnums.hpp" @@ -65,14 +66,6 @@ using namespace std; -namespace { -constexpr int ThumbnailImageFileWidth = 100; -constexpr int ThumbnailImageFileHeight = 100; - -// In Bytes. -constexpr qint64 FileSizeLimit = 524288000; -} - // ----------------------------------------------------------------------------- @@ -629,8 +622,8 @@ void ChatRoomModel::sendFileMessage (const QString &path) { return; qint64 fileSize = file.size(); - if (fileSize > FileSizeLimit) { - qWarning() << QStringLiteral("Unable to send file. (Size limit=%1)").arg(FileSizeLimit); + if (fileSize > Constants::FileSizeLimit) { + qWarning() << QStringLiteral("Unable to send file. (Size limit=%1)").arg(Constants::FileSizeLimit); return; } diff --git a/linphone-app/src/components/codecs/VideoCodecsModel.cpp b/linphone-app/src/components/codecs/VideoCodecsModel.cpp index a2d5d1d36..c840e67fe 100644 --- a/linphone-app/src/components/codecs/VideoCodecsModel.cpp +++ b/linphone-app/src/components/codecs/VideoCodecsModel.cpp @@ -27,6 +27,7 @@ #include "components/file/FileDownloader.hpp" #include "components/file/FileExtractor.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "VideoCodecsModel.hpp" #include @@ -35,30 +36,6 @@ using namespace std; -namespace { - #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - constexpr char H264Description[] = "Provided by CISCO SYSTEM,INC"; - #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - - #ifdef Q_OS_LINUX - constexpr char LibraryExtension[] = "so"; - constexpr char H264InstallName[] = "libopenh264.so"; - #ifdef Q_PROCESSOR_X86_64 - constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-2.1.0-linux64.5.so.bz2"; - #else - constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-2.1-0-linux32.5.so.bz2"; - #endif // ifdef Q_PROCESSOR_X86_64 - #elif defined(Q_OS_WIN) - constexpr char LibraryExtension[] = "dll"; - constexpr char H264InstallName[] = "openh264.dll"; - #ifdef Q_OS_WIN64 - constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-2.1.0-win64.dll.bz2"; - #else - constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-2.1.0-win32.dll.bz2"; - #endif // ifdef Q_OS_WIN64 - #endif // ifdef Q_OS_LINUX -} - VideoCodecsModel::VideoCodecsModel (QObject *parent) : AbstractCodecsModel(parent) { load(); } @@ -132,7 +109,7 @@ static bool downloadUpdatableCodec ( void VideoCodecsModel::updateCodecs () { #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - static const QString codecSuffix = QStringLiteral(".%1").arg(LibraryExtension); + static const QString codecSuffix = QStringLiteral(".%1").arg(Constants::LibraryExtension); QDirIterator it(getCodecsFolder()); while (it.hasNext()) { @@ -151,7 +128,7 @@ void VideoCodecsModel::updateCodecs () { void VideoCodecsModel::downloadUpdatableCodecs (QObject *parent) { #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) - downloadUpdatableCodec(parent, getCodecsFolder(), "H264", PluginUrlH264, H264InstallName); + downloadUpdatableCodec(parent, getCodecsFolder(), "H264", Constants::PluginUrlH264, Constants::H264InstallName); #else Q_UNUSED(parent); #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) @@ -192,7 +169,7 @@ void VideoCodecsModel::load () { if (find_if(codecs.begin(), codecs.end(), [](const shared_ptr &codec) { return codec->getMimeType() == "H264"; }) == codecs.end()) - addDownloadableCodec("H264", H264Description, PluginUrlH264, H264InstallName); + addDownloadableCodec("H264", Constants::H264Description, Constants::PluginUrlH264, Constants::H264InstallName); #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) } diff --git a/linphone-app/src/components/contact/VcardModel.cpp b/linphone-app/src/components/contact/VcardModel.cpp index 79dd30907..1b41a8275 100644 --- a/linphone-app/src/components/contact/VcardModel.cpp +++ b/linphone-app/src/components/contact/VcardModel.cpp @@ -29,6 +29,7 @@ #include "components/core/CoreManager.hpp" #include "components/sip-addresses/SipAddressesModel.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "VcardModel.hpp" @@ -38,10 +39,6 @@ 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) { auto it = find_if(list.cbegin(), list.cend(), [&value](const shared_ptr &entry) { @@ -56,7 +53,7 @@ static inline shared_ptr findBelCardValue (const list> &list, c } static inline bool isLinphoneDesktopPhoto (const shared_ptr &photo) { - return !photo->getValue().compare(0, sizeof(VcardScheme) - 1, VcardScheme); + return !photo->getValue().compare(0, sizeof(Constants::VcardScheme) - 1, Constants::VcardScheme); } static shared_ptr findBelcardPhoto (const shared_ptr &belcard) { @@ -78,7 +75,7 @@ static void removeBelcardPhoto (const shared_ptr &belcard, boo for (const auto photo : photos) { QString imagePath( Utils::coreStringToAppString( - Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(VcardScheme) - 1) + Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(Constants::VcardScheme) - 1) ) ); @@ -122,7 +119,7 @@ QString VcardModel::getAvatar () const { // Returns right path. return QStringLiteral("image://%1/%2").arg(AvatarProvider::ProviderId).arg( - Utils::coreStringToAppString(photo->getValue().substr(sizeof(VcardScheme) - 1)) + Utils::coreStringToAppString(photo->getValue().substr(sizeof(Constants::VcardScheme) - 1)) ); } @@ -171,7 +168,7 @@ bool VcardModel::setAvatar (const QString &path) { // 3. Update new photo. if (!path.isEmpty()) { shared_ptr photo = belcard::BelCardGeneric::create(); - photo->setValue(VcardScheme + Utils::appStringToCoreString(fileId)); + photo->setValue(Constants::VcardScheme + Utils::appStringToCoreString(fileId)); if (!belcard->addPhoto(photo)) { file.remove(); diff --git a/linphone-app/src/components/core/CoreManager.cpp b/linphone-app/src/components/core/CoreManager.cpp index 5e2904dae..9d999c1ac 100644 --- a/linphone-app/src/components/core/CoreManager.cpp +++ b/linphone-app/src/components/core/CoreManager.cpp @@ -42,6 +42,7 @@ #include "components/timeline/TimelineListModel.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #if defined(Q_OS_MACOS) #include "event-count-notifier/EventCountNotifierMacOs.hpp" @@ -59,19 +60,6 @@ using namespace std; -namespace { - constexpr int CbsCallInterval = 20; - - constexpr char RcVersionName[] = "rc_version"; - constexpr int RcVersionCurrent = 1; - - // TODO: Remove hardcoded values. Use config directly. - 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"; -} - // ----------------------------------------------------------------------------- CoreManager *CoreManager::mInstance=nullptr; @@ -286,38 +274,38 @@ void CoreManager::handleChatRoomCreated(const std::shared_ptr &ch void CoreManager::migrate () { shared_ptr config = mCore->getConfig(); - int rcVersion = config->getInt(SettingsModel::UiSection, RcVersionName, 0); - if (rcVersion == RcVersionCurrent) + int rcVersion = config->getInt(SettingsModel::UiSection, Constants::RcVersionName, 0); + if (rcVersion == Constants::RcVersionCurrent) return; - if (rcVersion > RcVersionCurrent) { + if (rcVersion > Constants::RcVersionCurrent) { qWarning() << QStringLiteral("RC file version (%1) is more recent than app rc file version (%2)!!!") - .arg(rcVersion).arg(RcVersionCurrent); + .arg(rcVersion).arg(Constants::RcVersionCurrent); return; } qInfo() << QStringLiteral("Migrate from old rc file (%1 to %2).") - .arg(rcVersion).arg(RcVersionCurrent); + .arg(rcVersion).arg(Constants::RcVersionCurrent); // Add message_expires param on old proxy configs. /* for (const auto &proxyConfig : mCore->getProxyConfigList()) { - if (proxyConfig->getDomain() == LinphoneDomain) { - proxyConfig->setContactParameters(DefaultContactParameters); - proxyConfig->setExpires(DefaultExpires); + if (proxyConfig->getDomain() == Constants::LinphoneDomain) { + proxyConfig->setContactParameters(Constants::DefaultContactParameters); + proxyConfig->setExpires(Constants::DefaultExpires); proxyConfig->done(); } }*/ for(const auto &account : mCore->getAccountList()){ auto params = account->getParams(); - if( params->getDomain() == LinphoneDomain) { + if( params->getDomain() == Constants::LinphoneDomain) { auto newParams = params->clone(); - newParams->setContactParameters(DefaultContactParameters); - newParams->setExpires(DefaultExpires); + newParams->setContactParameters(Constants::DefaultContactParameters); + newParams->setExpires(Constants::DefaultExpires); account->setParams(newParams); } } - config->setInt(SettingsModel::UiSection, RcVersionName, RcVersionCurrent); + config->setInt(SettingsModel::UiSection, Constants::RcVersionName, Constants::RcVersionCurrent); } // ----------------------------------------------------------------------------- @@ -342,7 +330,7 @@ int CoreManager::getMissedCallCountFromLocal( const QString &localAddress)const{ void CoreManager::startIterate(){ mCbsTimer = new QTimer(this); - mCbsTimer->setInterval(CbsCallInterval); + mCbsTimer->setInterval(Constants::CbsCallInterval); QObject::connect(mCbsTimer, &QTimer::timeout, this, &CoreManager::iterate); qInfo() << QStringLiteral("Start iterate"); mCbsTimer->start(); @@ -379,7 +367,7 @@ void CoreManager::handleLogsUploadStateChanged (linphone::Core::LogCollectionUpl // ----------------------------------------------------------------------------- QString CoreManager::getDownloadUrl () { - return DownloadUrl; + return Constants::DownloadUrl; } void CoreManager::setLastRemoteProvisioningState(const linphone::ConfiguringState& state){ diff --git a/linphone-app/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp b/linphone-app/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp index 2a4398f03..97135d07d 100644 --- a/linphone-app/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp +++ b/linphone-app/src/components/core/event-count-notifier/EventCountNotifierSystemTrayIcon.cpp @@ -27,6 +27,7 @@ #include "app/App.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "EventCountNotifierSystemTrayIcon.hpp" @@ -44,7 +45,7 @@ namespace { } EventCountNotifier::EventCountNotifier (QObject *parent) : AbstractEventCountNotifier(parent) { - QSvgRenderer renderer((QString(Utils::WindowIconPath))); + QSvgRenderer renderer((QString(Constants::WindowIconPath))); if (!renderer.isValid()) qFatal("Invalid SVG Image."); diff --git a/linphone-app/src/components/file/FileExtractor.cpp b/linphone-app/src/components/file/FileExtractor.cpp index 0dd103d16..877a81f45 100644 --- a/linphone-app/src/components/file/FileExtractor.cpp +++ b/linphone-app/src/components/file/FileExtractor.cpp @@ -32,9 +32,6 @@ using namespace std; -constexpr char LinphoneBZip2_exe[] = "http://www.linphone.org/releases/windows/tools/bzip2/bzip2.exe"; -constexpr char LinphoneBZip2_dll[] = "http://www.linphone.org/releases/windows/tools/bzip2/bzip2.dll"; - FileExtractor::FileExtractor (QObject *parent) : QObject(parent) {} FileExtractor::~FileExtractor () {} @@ -69,14 +66,14 @@ void FileExtractor::extract () { QTimer * timer = mTimer; FileDownloader * fileDownloader = new FileDownloader(); int downloadStep = 0; - fileDownloader->setUrl(QUrl(LinphoneBZip2_exe)); + fileDownloader->setUrl(QUrl(Constants::LinphoneBZip2_exe)); fileDownloader->setDownloadFolder(Utils::coreStringToAppString(Paths::getToolsDirPath())); QObject::connect(fileDownloader, &FileDownloader::totalBytesChanged, this, &FileExtractor::setTotalBytes); QObject::connect(fileDownloader, &FileDownloader::readBytesChanged, this, &FileExtractor::setReadBytes); QObject::connect(fileDownloader, &FileDownloader::downloadFinished, [fileDownloader, timer, downloadStep ]()mutable { if( downloadStep++ == 0){ - fileDownloader->setUrl(QUrl(LinphoneBZip2_dll)); + fileDownloader->setUrl(QUrl(Constants::LinphoneBZip2_dll)); fileDownloader->download(); }else { fileDownloader->deleteLater(); diff --git a/linphone-app/src/components/settings/AccountSettingsModel.cpp b/linphone-app/src/components/settings/AccountSettingsModel.cpp index d4ce0cda2..951d05876 100644 --- a/linphone-app/src/components/settings/AccountSettingsModel.cpp +++ b/linphone-app/src/components/settings/AccountSettingsModel.cpp @@ -26,6 +26,7 @@ #include "components/core/CoreHandlers.hpp" #include "components/core/CoreManager.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "AccountSettingsModel.hpp" #include "SettingsModel.hpp" @@ -138,6 +139,8 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr
  • getConferenceFactoryUri()); + if(map["conferenceUri"] == "") + map["conferenceUri"] = Constants::DefaultConferenceURI; map["contactParams"] = Utils::coreStringToAppString(proxyConfig->getContactParameters()); map["avpfInterval"] = proxyConfig->getAvpfRrInterval(); map["registerEnabled"] = proxyConfig->registerEnabled(); @@ -172,7 +175,9 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr
  • core = CoreManager::getInstance()->getCore(); shared_ptr proxyConfig = core->getDefaultProxyConfig(); - return proxyConfig ? Utils::coreStringToAppString(proxyConfig->getConferenceFactoryUri()) : ""; + if( proxyConfig && proxyConfig->getConferenceFactoryUri() == "") + proxyConfig->setConferenceFactoryUri(Utils::appStringToCoreString(Constants::DefaultConferenceURI)); + return proxyConfig ? Utils::coreStringToAppString(proxyConfig->getConferenceFactoryUri()) : Constants::DefaultConferenceURI; } void AccountSettingsModel::setDefaultProxyConfig (const shared_ptr &proxyConfig) { diff --git a/linphone-app/src/components/settings/SettingsModel.cpp b/linphone-app/src/components/settings/SettingsModel.cpp index 412944668..a72a5cf02 100644 --- a/linphone-app/src/components/settings/SettingsModel.cpp +++ b/linphone-app/src/components/settings/SettingsModel.cpp @@ -31,6 +31,7 @@ #include "components/core/CoreManager.hpp" #include "include/LinphoneApp/PluginNetworkHelper.hpp" #include "utils/Utils.hpp" +#include "utils/Constants.hpp" #include "utils/MediastreamerUtils.hpp" #include "SettingsModel.hpp" @@ -38,11 +39,6 @@ using namespace std; -namespace { - constexpr char DefaultRlsUri[] = "sips:rls@sip.linphone.org"; - constexpr char DefaultLogsEmail[] = "linphone-desktop@belledonne-communications.com"; -} - const string SettingsModel::UiSection("ui"); const string SettingsModel::ContactsSection("contacts_import"); @@ -1084,7 +1080,7 @@ bool SettingsModel::getRlsUriEnabled () const { void SettingsModel::setRlsUriEnabled (bool status) { mConfig->setInt(UiSection, "rls_uri_enabled", status); - mConfig->setString("sip", "rls_uri", status ? DefaultRlsUri : ""); + mConfig->setString("sip", "rls_uri", status ? Constants::DefaultRlsUri : ""); emit rlsUriEnabledChanged(status); } @@ -1093,7 +1089,7 @@ static string getRlsUriDomain () { if (!domain.empty()) return domain; - shared_ptr linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(DefaultRlsUri); + shared_ptr linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(Constants::DefaultRlsUri); Q_CHECK_PTR(linphoneAddress); domain = linphoneAddress->getDomain(); return domain; @@ -1110,7 +1106,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", DefaultRlsUri); + mConfig->setString("sip", "rls_uri", Constants::DefaultRlsUri); return; } @@ -1125,7 +1121,7 @@ void SettingsModel::configureRlsUri (const shared_ptrgetDomain() == domain) { - mConfig->setString("sip", "rls_uri", DefaultRlsUri); + mConfig->setString("sip", "rls_uri", Constants::DefaultRlsUri); return; } @@ -1288,7 +1284,7 @@ void SettingsModel::setLogsEnabled (bool status) { QString SettingsModel::getLogsEmail () const { return Utils::coreStringToAppString( - mConfig->getString(UiSection, "logs_email", DefaultLogsEmail) + mConfig->getString(UiSection, "logs_email", Constants::DefaultLogsEmail) ); } diff --git a/linphone-app/src/utils/Constants.cpp b/linphone-app/src/utils/Constants.cpp new file mode 100644 index 000000000..3f857c53c --- /dev/null +++ b/linphone-app/src/utils/Constants.cpp @@ -0,0 +1,105 @@ +#include "Constants.hpp" + +constexpr char Constants::WindowIconPath[]; +constexpr char Constants::DefaultLocale[]; + +constexpr char Constants::LanguagePath[]; + +// The main windows of Linphone desktop. +constexpr char Constants::QmlViewMainWindow[]; +constexpr char Constants::QmlViewCallsWindow[]; +constexpr char Constants::QmlViewSettingsWindow[]; + +#ifdef ENABLE_UPDATE_CHECK +constexpr int Constants::VersionUpdateCheckInterval; +#endif // ifdef ENABLE_UPDATE_CHECK + +constexpr char Constants::MainQmlUri[]; + +constexpr char Constants::AttachVirtualWindowMethodName[]; +constexpr char Constants::AboutPath[]; + +constexpr char Constants::AssistantViewName[]; + +constexpr char Constants::ApplicationMinimalQtVersion[]; +constexpr char Constants::DefaultFont[]; + +constexpr char Constants::QtDomain[]; +constexpr size_t Constants::MaxLogsCollectionSize; +constexpr char Constants::SrcPattern[]; + +constexpr char Constants::PathAssistantConfig[]; +constexpr char Constants::PathAvatars[]; +constexpr char Constants::PathCaptures[]; +constexpr char Constants::PathCodecs[]; +constexpr char Constants::PathTools[]; +constexpr char Constants::PathLogs[]; +#ifdef APPLE +constexpr char Constants::PathPlugins[]; +#else +constexpr char Constants::PathPlugins[]; +#endif +constexpr char Constants::PathPluginsApp[]; +constexpr char Constants::PathThumbnails[]; +constexpr char Constants::PathUserCertificates[]; + +constexpr char Constants::PathCallHistoryList[]; +constexpr char Constants::PathConfig[]; +constexpr char Constants::PathFactoryConfig[]; +constexpr char Constants::PathRootCa[]; +constexpr char Constants::PathFriendsList[]; +constexpr char Constants::PathMessageHistoryList[]; +constexpr char Constants::PathZrtpSecrets[]; + +// Max image size in bytes. (100Kb) +constexpr qint64 Constants::MaxImageSize; +constexpr int Constants::ThumbnailImageFileWidth; +constexpr int Constants::ThumbnailImageFileHeight; + +// In Bytes. +constexpr qint64 Constants::FileSizeLimit; + +constexpr char Constants::DefaultXmlrpcUri[]; +constexpr char Constants::DefaultConferenceURI[]; + + +#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) +constexpr char Constants::H264Description[]; +#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) + +#ifdef Q_OS_LINUX +constexpr char Constants::LibraryExtension[]; +constexpr char Constants::H264InstallName[]; +#ifdef Q_PROCESSOR_X86_64 +constexpr char Constants::PluginUrlH264[]; +#else +constexpr char Constants::PluginUrlH264[]; +#endif // ifdef Q_PROCESSOR_X86_64 +#elif defined(Q_OS_WIN) +constexpr char Constants::LibraryExtension[]; +constexpr char Constants::H264InstallName[]; +#ifdef Q_OS_WIN64 +constexpr char Constants::PluginUrlH264[]; +#else +constexpr char Constants::PluginUrlH264[]; +#endif // ifdef Q_OS_WIN64 +#endif // ifdef Q_OS_LINUX +constexpr char Constants::VcardScheme[]; + +constexpr int Constants::CbsCallInterval; + +constexpr char Constants::RcVersionName[]; +constexpr int Constants::RcVersionCurrent; + +// TODO: Remove hardcoded values. Use config directly. +constexpr char Constants::LinphoneDomain[]; +constexpr char Constants::DefaultContactParameters[]; +constexpr int Constants::DefaultExpires; +constexpr char Constants::DownloadUrl[]; + + +constexpr char Constants::LinphoneBZip2_exe[]; +constexpr char Constants::LinphoneBZip2_dll[]; +constexpr char Constants::DefaultRlsUri[]; +constexpr char Constants::DefaultLogsEmail[]; + diff --git a/linphone-app/src/utils/Constants.hpp b/linphone-app/src/utils/Constants.hpp new file mode 100644 index 000000000..20a55647c --- /dev/null +++ b/linphone-app/src/utils/Constants.hpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2021 Belledonne Communications SARL. + * + * This file is part of linphone-desktop + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef CONSTANTS_H_ +#define CONSTANTS_H_ + +#include +#include +#include + +#include "config.h" + +// ============================================================================= + +class Constants : public QObject{ + Q_OBJECT +public: + Constants(QObject * parent = nullptr) : QObject(parent){} + + //---------------------------------------------------------------------------------- + + static constexpr char WindowIconPath[] = ":/assets/images/linphone_logo.svg"; + static constexpr char DefaultLocale[] = "en"; + + static constexpr char ApplicationMinimalQtVersion[] = "5.9.0"; + static constexpr char DefaultFont[] = "Noto Sans"; + + static constexpr size_t MaxLogsCollectionSize = 10485760; // 10MB. + + +#ifdef ENABLE_UPDATE_CHECK + static constexpr int VersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds. +#endif // ifdef ENABLE_UPDATE_CHECK + + static constexpr char DefaultXmlrpcUri[] = "https://subscribe.linphone.org:444/wizard.php"; + static constexpr char LinphoneDomain[] = "sip.linphone.org"; + static constexpr char DefaultContactParameters[] = "message-expires=604800"; + static constexpr int DefaultExpires = 3600; + static constexpr char DownloadUrl[] = "https://www.linphone.org/technical-corner/linphone"; + + + static constexpr char LinphoneBZip2_exe[] = "http://www.linphone.org/releases/windows/tools/bzip2/bzip2.exe"; + static constexpr char LinphoneBZip2_dll[] = "http://www.linphone.org/releases/windows/tools/bzip2/bzip2.dll"; + static constexpr char DefaultRlsUri[] = "sips:rls@sip.linphone.org"; + static constexpr char DefaultLogsEmail[] = "linphone-desktop@belledonne-communications.com"; + static constexpr char DefaultConferenceURI[] = "sip:conference-factory@sip.linphone.org"; + + // Max image size in bytes. (100Kb) + static constexpr qint64 MaxImageSize = 102400;// In Bytes. + static constexpr qint64 FileSizeLimit = 524288000;// In Bytes. + static constexpr int ThumbnailImageFileWidth = 100; + static constexpr int ThumbnailImageFileHeight = 100; + + static constexpr char PathAssistantConfig[] = "/" EXECUTABLE_NAME "/assistant/"; + static constexpr char PathAvatars[] = "/avatars/"; + static constexpr char PathCaptures[] = "/" EXECUTABLE_NAME "/captures/"; + static constexpr char PathCodecs[] = "/codecs/"; + static constexpr char PathTools[] = "/tools/"; + static constexpr char PathLogs[] = "/logs/"; +#ifdef APPLE + static constexpr char PathPlugins[] = "/Plugins/"; +#else + static constexpr char PathPlugins[] = "/plugins/"; +#endif + static constexpr char PathPluginsApp[] = "app/"; + static constexpr char PathThumbnails[] = "/thumbnails/"; + static constexpr char PathUserCertificates[] = "/usr-crt/"; + + static constexpr char PathCallHistoryList[] = "/call-history.db"; + static constexpr char PathConfig[] = "/linphonerc"; + static constexpr char PathFactoryConfig[] = "/" EXECUTABLE_NAME "/linphonerc-factory"; + static constexpr char PathRootCa[] = "/" EXECUTABLE_NAME "/rootca.pem"; + static constexpr char PathFriendsList[] = "/friends.db"; + static constexpr char PathMessageHistoryList[] = "/message-history.db"; + static constexpr char PathZrtpSecrets[] = "/zidcache"; + + static constexpr char LanguagePath[] = ":/languages/"; + + // The main windows of Linphone desktop. + static constexpr char QmlViewMainWindow[] = "qrc:/ui/views/App/Main/MainWindow.qml"; + static constexpr char QmlViewCallsWindow[] = "qrc:/ui/views/App/Calls/CallsWindow.qml"; + static constexpr char QmlViewSettingsWindow[] = "qrc:/ui/views/App/Settings/SettingsWindow.qml"; + + static constexpr char MainQmlUri[] = "Linphone"; + + static constexpr char AttachVirtualWindowMethodName[] = "attachVirtualWindow"; + static constexpr char AboutPath[] = "qrc:/ui/views/App/Main/Dialogs/About.qml"; + + static constexpr char AssistantViewName[] = "Assistant"; + + static constexpr char QtDomain[] = "qt"; + static constexpr char SrcPattern[] = "/src/"; + + static constexpr char VcardScheme[] = "linphone-desktop:/"; + static constexpr int CbsCallInterval = 20; + static constexpr char RcVersionName[] = "rc_version"; + static constexpr int RcVersionCurrent = 1; + +//-------------------------------------------------------------------------------- +// CISCO +//-------------------------------------------------------------------------------- +#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) + static constexpr char H264Description[] = "Provided by CISCO SYSTEM,INC"; +#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) + +#ifdef Q_OS_LINUX + static constexpr char LibraryExtension[] = "so"; + static constexpr char H264InstallName[] = "libopenh264.so"; +#ifdef Q_PROCESSOR_X86_64 + static constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-2.1.0-linux64.5.so.bz2"; +#else + static constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/libopenh264-2.1-0-linux32.5.so.bz2"; +#endif // ifdef Q_PROCESSOR_X86_64 +#elif defined(Q_OS_WIN) + static constexpr char LibraryExtension[] = "dll"; + static constexpr char H264InstallName[] = "openh264.dll"; +#ifdef Q_OS_WIN64 + static constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-2.1.0-win64.dll.bz2"; +#else + static constexpr char PluginUrlH264[] = "http://ciscobinary.openh264.org/openh264-2.1.0-win32.dll.bz2"; +#endif // ifdef Q_OS_WIN64 +#endif // ifdef Q_OS_LINUX + +//-------------------------------------------------------------------------------- +}; + +#endif diff --git a/linphone-app/src/utils/LinphoneUtils.cpp b/linphone-app/src/utils/LinphoneUtils.cpp deleted file mode 100644 index 50bb01c38..000000000 --- a/linphone-app/src/utils/LinphoneUtils.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010-2020 Belledonne Communications SARL. - * - * This file is part of linphone-desktop - * (see https://www.linphone.org). - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "LinphoneUtils.hpp" -#include "utils/Utils.hpp" -#include "components/core/CoreManager.hpp" - -#include "components/contacts/ContactsListModel.hpp" -#include "components/contact/ContactModel.hpp" - -// ============================================================================= - -linphone::TransportType LinphoneUtils::stringToTransportType (const QString &transport) { - if (transport == QLatin1String("TCP")) - return linphone::TransportType::Tcp; - if (transport == QLatin1String("UDP")) - return linphone::TransportType::Udp; - if (transport == QLatin1String("TLS")) - return linphone::TransportType::Tls; - - return linphone::TransportType::Dtls; -} - -std::shared_ptr LinphoneUtils::interpretUrl(const QString& address){ - return CoreManager::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(address)); -} -/* -bool LinphoneUtils::hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability){ - auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(address); - if(contact) - return contact->hasCapability(capability); - else - return false; -} -*/ \ No newline at end of file diff --git a/linphone-app/src/utils/LinphoneUtils.hpp b/linphone-app/src/utils/LinphoneUtils.hpp deleted file mode 100644 index a7773d04e..000000000 --- a/linphone-app/src/utils/LinphoneUtils.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2010-2020 Belledonne Communications SARL. - * - * This file is part of linphone-desktop - * (see https://www.linphone.org). - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LINPHONE_UTILS_H_ -#define LINPHONE_UTILS_H_ - -#include - -#include "LinphoneEnums.hpp" - -// ============================================================================= - -class QString; - -namespace LinphoneUtils { - linphone::TransportType stringToTransportType (const QString &transport); - - std::shared_ptr interpretUrl(const QString& address); - - static constexpr char WindowIconPath[] = ":/assets/images/linphone_logo.svg"; -} - - -#endif // ifndef LINPHONE_UTILS_H_ diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index 205d5e8c4..55e51b3c8 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -37,7 +37,6 @@ namespace { } -constexpr char Utils::WindowIconPath[]; linphone::TransportType Utils::stringToTransportType (const QString &transport) { if (transport == QLatin1String("TCP")) return linphone::TransportType::Tcp; diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp index 034d2002e..b4aa6b009 100644 --- a/linphone-app/src/utils/Utils.hpp +++ b/linphone-app/src/utils/Utils.hpp @@ -56,9 +56,7 @@ public: Q_INVOKABLE static QString toDateTimeString(QDateTime date); Q_INVOKABLE static QString toTimeString(QDateTime date); Q_INVOKABLE static QString toDateString(QDateTime date); -//---------------------------------------------------------------------------------- - - static constexpr char WindowIconPath[] = ":/assets/images/linphone_logo.svg"; +//---------------------------------------------------------------------------------- static inline QString coreStringToAppString (const std::string &str) { return QString::fromLocal8Bit(str.c_str(), int(str.size())); diff --git a/linphone-app/ui/views/App/Main/Dialogs/NewChatRoom.qml b/linphone-app/ui/views/App/Main/Dialogs/NewChatRoom.qml index 1ae0c851f..0570c209b 100644 --- a/linphone-app/ui/views/App/Main/Dialogs/NewChatRoom.qml +++ b/linphone-app/ui/views/App/Main/Dialogs/NewChatRoom.qml @@ -155,7 +155,7 @@ DialogPlus { Layout.fillWidth: true Layout.rightMargin: 15 //: 'Give a subject' : Placeholder in a form about setting a subject - placeholderText :'Give a subject' + placeholderText : qsTr('subjectPlaceholder') text:(chatRoomModel?chatRoomModel.getSubject():'') Keys.onReturnPressed: nextItemInFocusChain().forceActiveFocus() TooltipArea{ @@ -175,7 +175,7 @@ DialogPlus { spacing:20 Text{ //: 'Last contacts' : Header for showing last contacts - text :'Last contacts' + text : qsTr('LastContactsTitle') color: Colors.g.color font.pointSize: Units.dp * 11 font.weight: Font.DemiBold