From 52b1ce5ecff5a64dacf787c3f8a38a03284da2c4 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 3 Oct 2023 15:57:21 +0200 Subject: [PATCH] Add clang-format and active utils string conversion. --- .clang-format | 31 + .gitignore | 10 +- CMakeLists.txt | 1 + Linphone/core/App.cpp | 30 +- Linphone/core/App.hpp | 12 +- Linphone/core/path/Paths.cpp | 190 ++-- Linphone/core/path/Paths.hpp | 64 +- Linphone/core/setting/Settings.cpp | 15 +- Linphone/core/setting/Settings.hpp | 9 +- Linphone/main.cpp | 2 +- Linphone/model/core/CoreListener.cpp | 151 ++- Linphone/model/core/CoreListener.hpp | 208 +++- Linphone/model/core/CoreModel.cpp | 18 +- Linphone/model/core/CoreModel.hpp | 19 +- Linphone/model/setting/SettingsModel.cpp | 13 +- Linphone/model/setting/SettingsModel.hpp | 21 +- Linphone/tool/Constants.cpp | 5 +- Linphone/tool/Constants.hpp | 106 +- Linphone/tool/Utils.cpp | 1325 +++++++++++----------- Linphone/tool/Utils.hpp | 241 ++-- Linphone/view/Page/LoginPage.cpp | 6 +- Linphone/view/Page/LoginPage.hpp | 12 +- cmake/hook/pre-commit | 27 + 23 files changed, 1385 insertions(+), 1131 deletions(-) create mode 100644 .clang-format create mode 100755 cmake/hook/pre-commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..fe663f18f --- /dev/null +++ b/.clang-format @@ -0,0 +1,31 @@ +# Copyright (c) 2010-2023 Belledonne Communications SARL. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +--- +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AlwaysBreakTemplateDeclarations: Yes +BinPackParameters: false +ColumnLimit: 120 +PointerAlignment: Right +IndentCaseLabels: true +IndentWidth: 4 +Standard: c++14 +TabWidth: 4 +UseTab: ForIndentation +... diff --git a/.gitignore b/.gitignore index 2ff15b576..a4251bc93 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,6 @@ .* \#*\# .#.* -!.gitignore -!.gitlab-ci* -!.gitmodules # Project configuration -------------------------------------------------------- *.pro.user @@ -44,3 +41,10 @@ rpm-*/ vgcore.* linphone.spec + +# Exceptions ------------------------------------------------------------------- + +!.clang-format +!.gitignore +!.gitlab-ci* +!.gitmodules \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e4e5edd0c..b1185914e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,3 +251,4 @@ else() include(cmake/TasksMacos.cmake) endif() +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/hook/pre-commit" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/") \ No newline at end of file diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 357f6afd8..ecbdffaa1 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -5,8 +5,7 @@ #include "tool/Constants.hpp" #include "view/Page/LoginPage.hpp" - -App::App(QObject * parent) : QObject(parent) { +App::App(QObject *parent) : QObject(parent) { init(); } @@ -15,26 +14,27 @@ App::App(QObject * parent) : QObject(parent) { //----------------------------------------------------------- void App::init() { -// Core + // Core mCoreModel = QSharedPointer::create("", this); mCoreModel->start(); -// QML + // QML mEngine = new QQmlApplicationEngine(this); mEngine->addImportPath(":/"); - + initCppInterfaces(); - + const QUrl url(u"qrc:/Linphone/view/App/Main.qml"_qs); - QObject::connect(mEngine, &QQmlApplicationEngine::objectCreated, - this, [url](QObject *obj, const QUrl &objUrl) { - if (!obj && url == objUrl) - QCoreApplication::exit(-1); - }, Qt::QueuedConnection); + QObject::connect( + mEngine, &QQmlApplicationEngine::objectCreated, this, + [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) QCoreApplication::exit(-1); + }, + Qt::QueuedConnection); mEngine->load(url); } void App::initCppInterfaces() { - qmlRegisterSingletonType(Constants::MainQmlUri, 1, 0, "LoginPageCpp", [](QQmlEngine *engine, QJSEngine *) -> QObject *{ - return new LoginPage(engine); - }); -} \ No newline at end of file + qmlRegisterSingletonType( + Constants::MainQmlUri, 1, 0, "LoginPageCpp", + [](QQmlEngine *engine, QJSEngine *) -> QObject * { return new LoginPage(engine); }); +} diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index 5a1603d02..8b169fa40 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -1,16 +1,16 @@ -#include #include +#include #include "model/core/CoreModel.hpp" -class App : public QObject{ +class App : public QObject { public: - App(QObject * parent = nullptr); - + App(QObject *parent = nullptr); + void init(); void initCppInterfaces(); - - QQmlApplicationEngine * mEngine = nullptr; + + QQmlApplicationEngine *mEngine = nullptr; QSharedPointer mCoreModel; }; \ No newline at end of file diff --git a/Linphone/core/path/Paths.cpp b/Linphone/core/path/Paths.cpp index 3c83cd906..17810dec5 100644 --- a/Linphone/core/path/Paths.cpp +++ b/Linphone/core/path/Paths.cpp @@ -31,50 +31,49 @@ // ============================================================================= -static inline bool dirPathExists (const QString &path) { +static inline bool dirPathExists(const QString &path) { QDir dir(path); return dir.exists(); } /* static inline bool filePathExists (const QString &path, const bool& isWritable) { - QFileInfo info(path); - if (!dirPathExists(info.path())) - return false; - if( isWritable && !info.isWritable()) - return false; - QFile file(path); - return file.exists(); + QFileInfo info(path); + if (!dirPathExists(info.path())) + return false; + if( isWritable && !info.isWritable()) + return false; + QFile file(path); + return file.exists(); } */ -static inline void ensureDirPathExists (const QString &path) { +static inline void ensureDirPathExists(const QString &path) { QDir dir(path); - if (!dir.exists() && !dir.mkpath(path)) - qFatal("Unable to access at directory: `%s`", path.toStdString().c_str()); + if (!dir.exists() && !dir.mkpath(path)) qFatal("Unable to access at directory: `%s`", path.toStdString().c_str()); } -static inline void ensureFilePathExists (const QString &path) { +static inline void ensureFilePathExists(const QString &path) { QFileInfo info(path); ensureDirPathExists(info.path()); - + QFile file(path); if (!file.exists() && !file.open(QIODevice::ReadWrite)) qFatal("Unable to access at path: `%s`", path.toStdString().c_str()); } -static inline QString getReadableDirPath (const QString &dirname) { +static inline QString getReadableDirPath(const QString &dirname) { return QDir::toNativeSeparators(dirname); } -static inline QString getWritableDirPath (const QString &dirname) { +static inline QString getWritableDirPath(const QString &dirname) { ensureDirPathExists(dirname); return getReadableDirPath(dirname); } -static inline QString getReadableFilePath (const QString &filename) { +static inline QString getReadableFilePath(const QString &filename) { return QDir::toNativeSeparators(filename); } -static inline QString getWritableFilePath (const QString &filename) { +static inline QString getWritableFilePath(const QString &filename) { ensureFilePathExists(filename); return getReadableFilePath(filename); } @@ -87,7 +86,6 @@ static inline QString getWritableFilePath (const QString &filename) { // plugins/ // share/ - // But in some cases, it can be : // /linphone // lib/ @@ -102,14 +100,15 @@ static inline QString getWritableFilePath (const QString &filename) { // Resources/ // share/ -static inline QDir getAppPackageDir () { +static inline QDir getAppPackageDir() { QDir dir(QCoreApplication::applicationDirPath()); if (dir.dirName() == QLatin1String("MacOS")) { dir.cdUp(); - } else if( !dir.exists("lib") && !dir.exists("lib64")){// Check if these folders are in the current path + } else if (!dir.exists("lib") && !dir.exists("lib64")) { // Check if these folders are in the current path dir.cdUp(); - if(!dir.exists("lib") && !dir.exists("lib64") && !dir.exists("plugins")) - qWarning() <<"The application's location is not correct: You have to put your 'bin/' folder next to 'lib/' or 'plugins/' folder."; + if (!dir.exists("lib") && !dir.exists("lib64") && !dir.exists("plugins")) + qWarning() << "The application's location is not correct: You have to put your 'bin/' folder next to " + "'lib/' or 'plugins/' folder."; } return dir; } @@ -117,175 +116,177 @@ static inline QDir getAppPackageDir () { static inline QString getAppPackageDataDirPath() { QDir dir = getAppPackageDir(); #ifdef __APPLE__ - if (!dir.cd("Resources")) - { + if (!dir.cd("Resources")) { dir.mkdir("Resources"); dir.cd("Resources"); } #endif - if (!dir.cd("share")) - { + if (!dir.cd("share")) { dir.mkdir("share"); dir.cd("share"); } return dir.absolutePath(); } -static inline QString getAppPackageMsPluginsDirPath () { +static inline QString getAppPackageMsPluginsDirPath() { QDir dir = getAppPackageDir(); dir.cd(MSPLUGINS_DIR); return dir.absolutePath(); } -static inline QString getAppPackagePluginsDirPath () { +static inline QString getAppPackagePluginsDirPath() { return getAppPackageDir().absolutePath() + Constants::PathPlugins; } -static inline QString getAppAssistantConfigDirPath () { +static inline QString getAppAssistantConfigDirPath() { return getAppPackageDataDirPath() + Constants::PathAssistantConfig; } -static inline QString getAppConfigFilePath () { +static inline QString getAppConfigFilePath() { return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + Constants::PathConfig; } -static inline QString getAppCallHistoryFilePath () { +static inline QString getAppCallHistoryFilePath() { return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathCallHistoryList; } -static inline QString getAppFactoryConfigFilePath () { +static inline QString getAppFactoryConfigFilePath() { return getAppPackageDataDirPath() + Constants::PathFactoryConfig; } -static inline QString getAppRootCaFilePath () { +static inline QString getAppRootCaFilePath() { QString rootca = getAppPackageDataDirPath() + Constants::PathRootCa; - if(Paths::filePathExists(rootca)){// Packaged + if (Paths::filePathExists(rootca)) { // Packaged return rootca; } return ""; } -static inline QString getAppFriendsFilePath () { +static inline QString getAppFriendsFilePath() { return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathFriendsList; } -static inline QString getAppMessageHistoryFilePath () { +static inline QString getAppMessageHistoryFilePath() { return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathMessageHistoryList; } -static inline QString getAppPluginsDirPath () { - return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+ Constants::PathPlugins; +static inline QString getAppPluginsDirPath() { + return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathPlugins; } // ----------------------------------------------------------------------------- -bool Paths::filePathExists (const QString &path, const bool isWritable) { +bool Paths::filePathExists(const QString &path, const bool isWritable) { QFileInfo info(path); - if (!dirPathExists(info.path())) - return false; - if( isWritable && !info.isWritable()) - return false; + if (!dirPathExists(info.path())) return false; + if (isWritable && !info.isWritable()) return false; QFile file(path); return file.exists(); } - // ----------------------------------------------------------------------------- -QString Paths::getAppLocalDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) +"/"); +QString Paths::getAppLocalDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/"); } -QString Paths::getAssistantConfigDirPath () { +QString Paths::getAssistantConfigDirPath() { return getReadableDirPath(getAppAssistantConfigDirPath()); } -QString Paths::getAvatarsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathAvatars); +QString Paths::getAvatarsDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathAvatars); } -QString Paths::getCallHistoryFilePath () { +QString Paths::getCallHistoryFilePath() { return getWritableFilePath(getAppCallHistoryFilePath()); } -QString Paths::getCapturesDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + Constants::PathCaptures); +QString Paths::getCapturesDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + + Constants::PathCaptures); } -QString Paths::getCodecsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathCodecs); +QString Paths::getCodecsDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathCodecs); } -QString Paths::getConfigDirPath (bool writable) { - return writable ? getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)+QDir::separator()) : getReadableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)+QDir::separator()); +QString Paths::getConfigDirPath(bool writable) { + return writable ? getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + + QDir::separator()) + : getReadableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + + QDir::separator()); } -QString Paths::getConfigFilePath (const QString &configPath, bool writable) { +QString Paths::getConfigFilePath(const QString &configPath, bool writable) { QString path; - if( !configPath.isEmpty()){ + if (!configPath.isEmpty()) { QFileInfo file(configPath); - if( !writable && (!file.exists() || !file.isFile())){// This file cannot be found. Check if it exists in standard folder + if (!writable && + (!file.exists() || !file.isFile())) { // This file cannot be found. Check if it exists in standard folder QString defaultConfigPath = getConfigDirPath(false); - file = QFileInfo(defaultConfigPath+QDir::separator()+configPath); - if( !file.exists() || !file.isFile()) - path = ""; - else - path = file.absoluteFilePath(); - }else - path = file.absoluteFilePath(); - }else - path = getAppConfigFilePath(); + file = QFileInfo(defaultConfigPath + QDir::separator() + configPath); + if (!file.exists() || !file.isFile()) path = ""; + else path = file.absoluteFilePath(); + } else path = file.absoluteFilePath(); + } else path = getAppConfigFilePath(); return writable ? getWritableFilePath(path) : getReadableFilePath(path); } -QString Paths::getDatabaseFilePath (){ - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)) + Constants::PathDatabase; +QString Paths::getDatabaseFilePath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)) + + Constants::PathDatabase; } -QString Paths::getFactoryConfigFilePath () { +QString Paths::getFactoryConfigFilePath() { return getReadableFilePath(getAppFactoryConfigFilePath()); } -QString Paths::getFriendsListFilePath () { +QString Paths::getFriendsListFilePath() { return getWritableFilePath(getAppFriendsFilePath()); } -QString Paths::getDownloadDirPath () { +QString Paths::getDownloadDirPath() { return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + QDir::separator()); } -QString Paths::getLimeDatabasePath (){ - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)) + Constants::PathLimeDatabase; +QString Paths::getLimeDatabasePath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)) + + Constants::PathLimeDatabase; } -QString Paths::getLogsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathLogs); +QString Paths::getLogsDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathLogs); } -QString Paths::getMessageHistoryFilePath () { - return getReadableFilePath(getAppMessageHistoryFilePath());// No need to ensure that the file exists as this DB is deprecated +QString Paths::getMessageHistoryFilePath() { + return getReadableFilePath( + getAppMessageHistoryFilePath()); // No need to ensure that the file exists as this DB is deprecated } -QString Paths::getPackageDataDirPath () { +QString Paths::getPackageDataDirPath() { return getReadableDirPath(getAppPackageDataDirPath() + Constants::PathData); } -QString Paths::getPackageMsPluginsDirPath () { +QString Paths::getPackageMsPluginsDirPath() { return getReadableDirPath(getAppPackageMsPluginsDirPath()); } -QString Paths::getPackagePluginsAppDirPath () { +QString Paths::getPackagePluginsAppDirPath() { return getReadableDirPath(getAppPackagePluginsDirPath() + Constants::PathPluginsApp); } -QString Paths::getPackageSoundsResourcesDirPath (){ +QString Paths::getPackageSoundsResourcesDirPath() { return getReadableDirPath(getAppPackageDataDirPath() + Constants::PathSounds); } -QString Paths::getPackageTopDirPath (){ +QString Paths::getPackageTopDirPath() { return getReadableDirPath(getAppPackageDataDirPath()); } -QString Paths::getPluginsAppDirPath () { +QString Paths::getPluginsAppDirPath() { return getWritableDirPath(getAppPluginsDirPath() + Constants::PathPluginsApp); } @@ -296,22 +297,25 @@ QStringList Paths::getPluginsAppFolders() { return pluginPaths; } -QString Paths::getRootCaFilePath () { +QString Paths::getRootCaFilePath() { return getReadableFilePath(getAppRootCaFilePath()); } -QString Paths::getToolsDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathTools); +QString Paths::getToolsDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathTools); } -QString Paths::getUserCertificatesDirPath () { - return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathUserCertificates); +QString Paths::getUserCertificatesDirPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathUserCertificates); } -QString Paths::getZrtpSecretsFilePath () { - return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + Constants::PathZrtpSecrets); +QString Paths::getZrtpSecretsFilePath() { + return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathZrtpSecrets); } // ----------------------------------------------------------------------------- -void Paths::migrate () { +void Paths::migrate() { } diff --git a/Linphone/core/path/Paths.hpp b/Linphone/core/path/Paths.hpp index 42fb9842f..1af71671a 100644 --- a/Linphone/core/path/Paths.hpp +++ b/Linphone/core/path/Paths.hpp @@ -26,37 +26,37 @@ // ============================================================================= namespace Paths { - bool filePathExists (const QString &path, const bool isWritable = false); - - QString getAppLocalDirPath (); - QString getAssistantConfigDirPath (); - QString getAvatarsDirPath (); - QString getCallHistoryFilePath (); - QString getCapturesDirPath (); - QString getCodecsDirPath (); - QString getConfigDirPath (bool writable = true); - QString getConfigFilePath (const QString &configPath = QString(), bool writable = true); - QString getDatabaseFilePath (); - QString getDownloadDirPath (); - QString getFactoryConfigFilePath (); - QString getFriendsListFilePath (); - QString getLimeDatabasePath (); - QString getLogsDirPath (); - QString getMessageHistoryFilePath (); - QString getPackageDataDirPath (); - QString getPackageMsPluginsDirPath (); - QString getPackagePluginsAppDirPath (); - QString getPackageSoundsResourcesDirPath (); - QString getPackageTopDirPath (); - QString getPluginsAppDirPath (); - QStringList getPluginsAppFolders(); - QString getRootCaFilePath (); - QString getToolsDirPath (); - QString getUserCertificatesDirPath (); - QString getZrtpDataFilePath (); - QString getZrtpSecretsFilePath (); - - void migrate (); -} +bool filePathExists(const QString &path, const bool isWritable = false); + +QString getAppLocalDirPath(); +QString getAssistantConfigDirPath(); +QString getAvatarsDirPath(); +QString getCallHistoryFilePath(); +QString getCapturesDirPath(); +QString getCodecsDirPath(); +QString getConfigDirPath(bool writable = true); +QString getConfigFilePath(const QString &configPath = QString(), bool writable = true); +QString getDatabaseFilePath(); +QString getDownloadDirPath(); +QString getFactoryConfigFilePath(); +QString getFriendsListFilePath(); +QString getLimeDatabasePath(); +QString getLogsDirPath(); +QString getMessageHistoryFilePath(); +QString getPackageDataDirPath(); +QString getPackageMsPluginsDirPath(); +QString getPackagePluginsAppDirPath(); +QString getPackageSoundsResourcesDirPath(); +QString getPackageTopDirPath(); +QString getPluginsAppDirPath(); +QStringList getPluginsAppFolders(); +QString getRootCaFilePath(); +QString getToolsDirPath(); +QString getUserCertificatesDirPath(); +QString getZrtpDataFilePath(); +QString getZrtpSecretsFilePath(); + +void migrate(); +} // namespace Paths #endif // PATHS_H_ diff --git a/Linphone/core/setting/Settings.cpp b/Linphone/core/setting/Settings.cpp index 7826aee8c..99c69273e 100644 --- a/Linphone/core/setting/Settings.cpp +++ b/Linphone/core/setting/Settings.cpp @@ -18,17 +18,15 @@ * along with this program. If not, see . */ - #include "Settings.hpp" #include #include "core/path/Paths.hpp" - // ============================================================================= -Settings::Settings (QObject *parent) : QObject(parent) { +Settings::Settings(QObject *parent) : QObject(parent) { } Settings::~Settings() { @@ -37,12 +35,11 @@ Settings::~Settings() { QString Settings::getConfigPath(const QCommandLineParser &parser) { QString filePath = parser.isSet("config") ? parser.value("config") : ""; QString configPath; - if(!QUrl(filePath).isRelative()){ - //configPath = FileDownloader::synchronousDownload(filePath, Utils::coreStringToAppString(Paths::getConfigDirPath(false)), true)); + if (!QUrl(filePath).isRelative()) { + // configPath = FileDownloader::synchronousDownload(filePath, + // Utils::coreStringToAppString(Paths::getConfigDirPath(false)), true)); } - if( configPath == "") - configPath = Paths::getConfigFilePath(filePath, false); - if( configPath == "" ) - configPath = Paths::getConfigFilePath("", false); + if (configPath == "") configPath = Paths::getConfigFilePath(filePath, false); + if (configPath == "") configPath = Paths::getConfigFilePath("", false); return configPath; } \ No newline at end of file diff --git a/Linphone/core/setting/Settings.hpp b/Linphone/core/setting/Settings.hpp index 9570ce4bb..5e5985f2e 100644 --- a/Linphone/core/setting/Settings.hpp +++ b/Linphone/core/setting/Settings.hpp @@ -21,17 +21,16 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ +#include #include #include -#include - class Settings : public QObject { Q_OBJECT public: - Settings (QObject *parent = Q_NULLPTR); - virtual ~Settings (); - + Settings(QObject *parent = Q_NULLPTR); + virtual ~Settings(); + QString getConfigPath(const QCommandLineParser &parser = QCommandLineParser()); }; #endif diff --git a/Linphone/main.cpp b/Linphone/main.cpp index f00f4f0be..2a5f39e3d 100644 --- a/Linphone/main.cpp +++ b/Linphone/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - + QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); for (const QString &locale : uiLanguages) { diff --git a/Linphone/model/core/CoreListener.cpp b/Linphone/model/core/CoreListener.cpp index d65d90d99..545242c44 100644 --- a/Linphone/model/core/CoreListener.cpp +++ b/Linphone/model/core/CoreListener.cpp @@ -22,89 +22,140 @@ // ============================================================================= - // ----------------------------------------------------------------------------- -CoreListener::CoreListener(QObject * parent): QObject(parent){ +CoreListener::CoreListener(QObject *parent) : QObject(parent) { } -CoreListener::~CoreListener(){ +CoreListener::~CoreListener() { } -void CoreListener::onAccountRegistrationStateChanged(const std::shared_ptr & core,const std::shared_ptr & account,linphone::RegistrationState state,const std::string & message){ - emit accountRegistrationStateChanged(core,account,state,message); +void CoreListener::onAccountRegistrationStateChanged(const std::shared_ptr &core, + const std::shared_ptr &account, + linphone::RegistrationState state, + const std::string &message) { + emit accountRegistrationStateChanged(core, account, state, message); } -void CoreListener::onAuthenticationRequested (const std::shared_ptr &core,const std::shared_ptr &authInfo,linphone::AuthMethod method){ - emit authenticationRequested (core,authInfo,method); +void CoreListener::onAuthenticationRequested(const std::shared_ptr &core, + const std::shared_ptr &authInfo, + linphone::AuthMethod method) { + emit authenticationRequested(core, authInfo, method); } -void CoreListener::onCallEncryptionChanged (const std::shared_ptr &core,const std::shared_ptr &call,bool on,const std::string &authenticationToken){ - emit callEncryptionChanged (core,call,on,authenticationToken); +void CoreListener::onCallEncryptionChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + bool on, + const std::string &authenticationToken) { + emit callEncryptionChanged(core, call, on, authenticationToken); } -void CoreListener::onCallLogUpdated(const std::shared_ptr & core, const std::shared_ptr & callLog){ +void CoreListener::onCallLogUpdated(const std::shared_ptr &core, + const std::shared_ptr &callLog) { emit callLogUpdated(core, callLog); } -void CoreListener::onCallStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state,const std::string &message){ - emit callStateChanged (core,call,state,message); +void CoreListener::onCallStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state, + const std::string &message) { + emit callStateChanged(core, call, state, message); } -void CoreListener::onCallStatsUpdated (const std::shared_ptr &core,const std::shared_ptr &call,const std::shared_ptr &stats){ - emit callStatsUpdated (core,call,stats); +void CoreListener::onCallStatsUpdated(const std::shared_ptr &core, + const std::shared_ptr &call, + const std::shared_ptr &stats) { + emit callStatsUpdated(core, call, stats); } -void CoreListener::onCallCreated(const std::shared_ptr & lc,const std::shared_ptr & call){ - emit callCreated(lc,call); +void CoreListener::onCallCreated(const std::shared_ptr &lc, + const std::shared_ptr &call) { + emit callCreated(lc, call); } -void CoreListener::onChatRoomRead(const std::shared_ptr & core, const std::shared_ptr & chatRoom){ +void CoreListener::onChatRoomRead(const std::shared_ptr &core, + const std::shared_ptr &chatRoom) { emit chatRoomRead(core, chatRoom); } -void CoreListener::onChatRoomStateChanged(const std::shared_ptr & core, const std::shared_ptr & chatRoom,linphone::ChatRoom::State state){ - emit chatRoomStateChanged(core, chatRoom,state); +void CoreListener::onChatRoomStateChanged(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + linphone::ChatRoom::State state) { + emit chatRoomStateChanged(core, chatRoom, state); } -void CoreListener::onConferenceInfoReceived(const std::shared_ptr & core, const std::shared_ptr & conferenceInfo){ +void CoreListener::onConferenceInfoReceived(const std::shared_ptr &core, + const std::shared_ptr &conferenceInfo) { emit conferenceInfoReceived(core, conferenceInfo); } -void CoreListener::onConfiguringStatus(const std::shared_ptr & core,linphone::Config::ConfiguringState status,const std::string & message){ - emit configuringStatus(core,status,message); +void CoreListener::onConfiguringStatus(const std::shared_ptr &core, + linphone::Config::ConfiguringState status, + const std::string &message) { + emit configuringStatus(core, status, message); } -void CoreListener::onDtmfReceived(const std::shared_ptr & lc,const std::shared_ptr & call,int dtmf){ - emit dtmfReceived(lc,call,dtmf); +void CoreListener::onDtmfReceived(const std::shared_ptr &lc, + const std::shared_ptr &call, + int dtmf) { + emit dtmfReceived(lc, call, dtmf); } -void CoreListener::onEcCalibrationResult(const std::shared_ptr & core,linphone::EcCalibratorStatus status,int delayMs){ - emit ecCalibrationResult(core,status,delayMs); +void CoreListener::onEcCalibrationResult(const std::shared_ptr &core, + linphone::EcCalibratorStatus status, + int delayMs) { + emit ecCalibrationResult(core, status, delayMs); } -void CoreListener::onGlobalStateChanged (const std::shared_ptr &core,linphone::GlobalState gstate,const std::string &message){ - emit globalStateChanged (core,gstate,message); +void CoreListener::onGlobalStateChanged(const std::shared_ptr &core, + linphone::GlobalState gstate, + const std::string &message) { + emit globalStateChanged(core, gstate, message); } -void CoreListener::onIsComposingReceived (const std::shared_ptr &core,const std::shared_ptr &room){ - emit isComposingReceived (core,room); +void CoreListener::onIsComposingReceived(const std::shared_ptr &core, + const std::shared_ptr &room) { + emit isComposingReceived(core, room); } -void CoreListener::onLogCollectionUploadStateChanged (const std::shared_ptr &core,linphone::Core::LogCollectionUploadState state,const std::string &info){ - emit logCollectionUploadStateChanged (core,state,info); +void CoreListener::onLogCollectionUploadStateChanged(const std::shared_ptr &core, + linphone::Core::LogCollectionUploadState state, + const std::string &info) { + emit logCollectionUploadStateChanged(core, state, info); } -void CoreListener::onLogCollectionUploadProgressIndication (const std::shared_ptr &lc,size_t offset,size_t total){ - emit logCollectionUploadProgressIndication (lc,offset,total); +void CoreListener::onLogCollectionUploadProgressIndication(const std::shared_ptr &lc, + size_t offset, + size_t total) { + emit logCollectionUploadProgressIndication(lc, offset, total); } -void CoreListener::onMessageReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::shared_ptr &message){ - emit messageReceived (core,room,message); +void CoreListener::onMessageReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::shared_ptr &message) { + emit messageReceived(core, room, message); } -void CoreListener::onMessagesReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::list> &messages){ - emit messagesReceived (core,room,messages); +void CoreListener::onMessagesReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::list> &messages) { + emit messagesReceived(core, room, messages); } -void CoreListener::onNewMessageReaction(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & reaction){ - emit newMessageReaction (core,chatRoom,message, reaction); +void CoreListener::onNewMessageReaction(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &reaction) { + emit newMessageReaction(core, chatRoom, message, reaction); } -void CoreListener::onNotifyPresenceReceivedForUriOrTel (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend,const std::string &uriOrTel,const std::shared_ptr &presenceModel){ - emit notifyPresenceReceivedForUriOrTel (core,linphoneFriend,uriOrTel,presenceModel); +void CoreListener::onNotifyPresenceReceivedForUriOrTel( + const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend, + const std::string &uriOrTel, + const std::shared_ptr &presenceModel) { + emit notifyPresenceReceivedForUriOrTel(core, linphoneFriend, uriOrTel, presenceModel); } -void CoreListener::onNotifyPresenceReceived (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend){ - emit notifyPresenceReceived (core,linphoneFriend); +void CoreListener::onNotifyPresenceReceived(const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend) { + emit notifyPresenceReceived(core, linphoneFriend); } -void CoreListener::onQrcodeFound(const std::shared_ptr & core, const std::string & result){ +void CoreListener::onQrcodeFound(const std::shared_ptr &core, const std::string &result) { emit qrcodeFound(core, result); } -void CoreListener::onReactionRemoved(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & address) { +void CoreListener::onReactionRemoved(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &address) { emit reactionRemoved(core, chatRoom, message, address); } -void CoreListener::onTransferStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state){ - emit transferStateChanged (core,call,state); +void CoreListener::onTransferStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state) { + emit transferStateChanged(core, call, state); } -void CoreListener::onVersionUpdateCheckResultReceived (const std::shared_ptr & core,linphone::VersionUpdateCheckResult result,const std::string &version,const std::string &url){ - emit versionUpdateCheckResultReceived (core,result,version,url); +void CoreListener::onVersionUpdateCheckResultReceived(const std::shared_ptr &core, + linphone::VersionUpdateCheckResult result, + const std::string &version, + const std::string &url) { + emit versionUpdateCheckResultReceived(core, result, version, url); } diff --git a/Linphone/model/core/CoreListener.hpp b/Linphone/model/core/CoreListener.hpp index a156b9245..4a6aaf883 100644 --- a/Linphone/model/core/CoreListener.hpp +++ b/Linphone/model/core/CoreListener.hpp @@ -21,71 +21,167 @@ #ifndef CORE_LISTENER_H_ #define CORE_LISTENER_H_ -#include #include +#include // ============================================================================= class CoreListener : public QObject, public linphone::CoreListener { Q_OBJECT public: - CoreListener (QObject * parent = nullptr); - virtual ~CoreListener (); + CoreListener(QObject *parent = nullptr); + virtual ~CoreListener(); + + virtual void onAccountRegistrationStateChanged(const std::shared_ptr &core, + const std::shared_ptr &account, + linphone::RegistrationState state, + const std::string &message) override; + virtual void onAuthenticationRequested(const std::shared_ptr &core, + const std::shared_ptr &authInfo, + linphone::AuthMethod method) override; + virtual void onCallEncryptionChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + bool on, + const std::string &authenticationToken) override; + virtual void onCallLogUpdated(const std::shared_ptr &core, + const std::shared_ptr &callLog) override; + virtual void onCallStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state, + const std::string &message) override; + virtual void onCallStatsUpdated(const std::shared_ptr &core, + const std::shared_ptr &call, + const std::shared_ptr &stats) override; + virtual void onCallCreated(const std::shared_ptr &lc, + const std::shared_ptr &call) override; + virtual void onChatRoomRead(const std::shared_ptr &core, + const std::shared_ptr &chatRoom) override; + virtual void onChatRoomStateChanged(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + linphone::ChatRoom::State state) override; + virtual void + onConferenceInfoReceived(const std::shared_ptr &core, + const std::shared_ptr &conferenceInfo) override; + virtual void onConfiguringStatus(const std::shared_ptr &core, + linphone::Config::ConfiguringState status, + const std::string &message) override; + virtual void onDtmfReceived(const std::shared_ptr &lc, + const std::shared_ptr &call, + int dtmf) override; + virtual void onEcCalibrationResult(const std::shared_ptr &core, + linphone::EcCalibratorStatus status, + int delayMs) override; + virtual void onGlobalStateChanged(const std::shared_ptr &core, + linphone::GlobalState gstate, + const std::string &message) override; + virtual void onIsComposingReceived(const std::shared_ptr &core, + const std::shared_ptr &room) override; + virtual void onLogCollectionUploadStateChanged(const std::shared_ptr &core, + linphone::Core::LogCollectionUploadState state, + const std::string &info) override; + virtual void onLogCollectionUploadProgressIndication(const std::shared_ptr &lc, + size_t offset, + size_t total) override; + virtual void onMessageReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::shared_ptr &message) override; + virtual void onMessagesReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::list> &messages) override; + virtual void onNewMessageReaction(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &reaction) override; + virtual void + onNotifyPresenceReceivedForUriOrTel(const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend, + const std::string &uriOrTel, + const std::shared_ptr &presenceModel) override; + virtual void onNotifyPresenceReceived(const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend) override; + virtual void onQrcodeFound(const std::shared_ptr &core, const std::string &result) override; + virtual void onReactionRemoved(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &address) override; + virtual void onTransferStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state) override; + virtual void onVersionUpdateCheckResultReceived(const std::shared_ptr &core, + linphone::VersionUpdateCheckResult result, + const std::string &version, + const std::string &url) override; - virtual void onAccountRegistrationStateChanged(const std::shared_ptr & core,const std::shared_ptr & account,linphone::RegistrationState state,const std::string & message) override; - virtual void onAuthenticationRequested (const std::shared_ptr &core,const std::shared_ptr &authInfo,linphone::AuthMethod method) override; - virtual void onCallEncryptionChanged (const std::shared_ptr &core,const std::shared_ptr &call,bool on,const std::string &authenticationToken) override; - virtual void onCallLogUpdated(const std::shared_ptr & core, const std::shared_ptr & callLog) override; - virtual void onCallStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state,const std::string &message) override; - virtual void onCallStatsUpdated (const std::shared_ptr &core,const std::shared_ptr &call,const std::shared_ptr &stats) override; - virtual void onCallCreated(const std::shared_ptr & lc,const std::shared_ptr & call) override; - virtual void onChatRoomRead(const std::shared_ptr & core, const std::shared_ptr & chatRoom) override; - virtual void onChatRoomStateChanged(const std::shared_ptr & core, const std::shared_ptr & chatRoom,linphone::ChatRoom::State state) override; - virtual void onConferenceInfoReceived(const std::shared_ptr & core, const std::shared_ptr & conferenceInfo) override; - virtual void onConfiguringStatus(const std::shared_ptr & core,linphone::Config::ConfiguringState status,const std::string & message) override; - virtual void onDtmfReceived(const std::shared_ptr & lc,const std::shared_ptr & call,int dtmf) override; - virtual void onEcCalibrationResult(const std::shared_ptr & core,linphone::EcCalibratorStatus status,int delayMs) override; - virtual void onGlobalStateChanged (const std::shared_ptr &core,linphone::GlobalState gstate,const std::string &message) override; - virtual void onIsComposingReceived (const std::shared_ptr &core,const std::shared_ptr &room) override; - virtual void onLogCollectionUploadStateChanged (const std::shared_ptr &core,linphone::Core::LogCollectionUploadState state,const std::string &info) override; - virtual void onLogCollectionUploadProgressIndication (const std::shared_ptr &lc,size_t offset,size_t total) override; - virtual void onMessageReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::shared_ptr &message) override; - virtual void onMessagesReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::list> &messages) override; - virtual void onNewMessageReaction(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & reaction) override; - virtual void onNotifyPresenceReceivedForUriOrTel (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend,const std::string &uriOrTel,const std::shared_ptr &presenceModel) override; - virtual void onNotifyPresenceReceived (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend) override; - virtual void onQrcodeFound(const std::shared_ptr & core, const std::string & result) override; - virtual void onReactionRemoved(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & address) override; - virtual void onTransferStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state) override; - virtual void onVersionUpdateCheckResultReceived (const std::shared_ptr & core,linphone::VersionUpdateCheckResult result,const std::string &version,const std::string &url) override; - signals: - void accountRegistrationStateChanged(const std::shared_ptr & core,const std::shared_ptr & account,linphone::RegistrationState state,const std::string & message); - void authenticationRequested (const std::shared_ptr &core,const std::shared_ptr &authInfo,linphone::AuthMethod method); - void callEncryptionChanged (const std::shared_ptr &core,const std::shared_ptr &call,bool on,const std::string &authenticationToken); - void callLogUpdated(const std::shared_ptr & core, const std::shared_ptr & callLog); - void callStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state,const std::string &message); - void callStatsUpdated (const std::shared_ptr &core,const std::shared_ptr &call,const std::shared_ptr &stats); - void callCreated(const std::shared_ptr & lc,const std::shared_ptr & call); - void chatRoomRead(const std::shared_ptr & core, const std::shared_ptr & chatRoom); - void chatRoomStateChanged(const std::shared_ptr & core, const std::shared_ptr & chatRoom,linphone::ChatRoom::State state); - void conferenceInfoReceived(const std::shared_ptr & core, const std::shared_ptr & conferenceInfo); - void configuringStatus(const std::shared_ptr & core,linphone::Config::ConfiguringState status,const std::string & message); - void dtmfReceived(const std::shared_ptr & lc,const std::shared_ptr & call,int dtmf); - void ecCalibrationResult(const std::shared_ptr & core,linphone::EcCalibratorStatus status,int delayMs); - void globalStateChanged (const std::shared_ptr &core,linphone::GlobalState gstate,const std::string &message); - void isComposingReceived (const std::shared_ptr &core,const std::shared_ptr &room); - void logCollectionUploadStateChanged (const std::shared_ptr &core,linphone::Core::LogCollectionUploadState state,const std::string &info); - void logCollectionUploadProgressIndication (const std::shared_ptr &lc,size_t offset,size_t total); - void messageReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::shared_ptr &message); - void messagesReceived (const std::shared_ptr &core,const std::shared_ptr &room,const std::list> &messages); - void newMessageReaction(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & reaction); - void notifyPresenceReceivedForUriOrTel (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend,const std::string &uriOrTel,const std::shared_ptr &presenceModel); - void notifyPresenceReceived (const std::shared_ptr &core,const std::shared_ptr &linphoneFriend); - void qrcodeFound(const std::shared_ptr & core, const std::string & result); - void reactionRemoved(const std::shared_ptr & core, const std::shared_ptr & chatRoom, const std::shared_ptr & message, const std::shared_ptr & address); - void transferStateChanged (const std::shared_ptr &core,const std::shared_ptr &call,linphone::Call::State state); - void versionUpdateCheckResultReceived (const std::shared_ptr & core,linphone::VersionUpdateCheckResult result,const std::string &version,const std::string &url); + void accountRegistrationStateChanged(const std::shared_ptr &core, + const std::shared_ptr &account, + linphone::RegistrationState state, + const std::string &message); + void authenticationRequested(const std::shared_ptr &core, + const std::shared_ptr &authInfo, + linphone::AuthMethod method); + void callEncryptionChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + bool on, + const std::string &authenticationToken); + void callLogUpdated(const std::shared_ptr &core, const std::shared_ptr &callLog); + void callStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state, + const std::string &message); + void callStatsUpdated(const std::shared_ptr &core, + const std::shared_ptr &call, + const std::shared_ptr &stats); + void callCreated(const std::shared_ptr &lc, const std::shared_ptr &call); + void chatRoomRead(const std::shared_ptr &core, const std::shared_ptr &chatRoom); + void chatRoomStateChanged(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + linphone::ChatRoom::State state); + void conferenceInfoReceived(const std::shared_ptr &core, + const std::shared_ptr &conferenceInfo); + void configuringStatus(const std::shared_ptr &core, + linphone::Config::ConfiguringState status, + const std::string &message); + void dtmfReceived(const std::shared_ptr &lc, const std::shared_ptr &call, int dtmf); + void + ecCalibrationResult(const std::shared_ptr &core, linphone::EcCalibratorStatus status, int delayMs); + void globalStateChanged(const std::shared_ptr &core, + linphone::GlobalState gstate, + const std::string &message); + void isComposingReceived(const std::shared_ptr &core, + const std::shared_ptr &room); + void logCollectionUploadStateChanged(const std::shared_ptr &core, + linphone::Core::LogCollectionUploadState state, + const std::string &info); + void logCollectionUploadProgressIndication(const std::shared_ptr &lc, size_t offset, size_t total); + void messageReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::shared_ptr &message); + void messagesReceived(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::list> &messages); + void newMessageReaction(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &reaction); + void notifyPresenceReceivedForUriOrTel(const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend, + const std::string &uriOrTel, + const std::shared_ptr &presenceModel); + void notifyPresenceReceived(const std::shared_ptr &core, + const std::shared_ptr &linphoneFriend); + void qrcodeFound(const std::shared_ptr &core, const std::string &result); + void reactionRemoved(const std::shared_ptr &core, + const std::shared_ptr &chatRoom, + const std::shared_ptr &message, + const std::shared_ptr &address); + void transferStateChanged(const std::shared_ptr &core, + const std::shared_ptr &call, + linphone::Call::State state); + void versionUpdateCheckResultReceived(const std::shared_ptr &core, + linphone::VersionUpdateCheckResult result, + const std::string &version, + const std::string &url); }; #endif diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 2262173a9..dcc107237 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -22,25 +22,26 @@ #include #include +#include #include #include -#include + +#include "tool/Utils.hpp" // ============================================================================= -CoreModel::CoreModel (const QString &configPath, QObject *parent) : - QThread(parent) { +CoreModel::CoreModel(const QString &configPath, QObject *parent) : QThread(parent) { mConfigPath = configPath; } -CoreModel::~CoreModel(){ +CoreModel::~CoreModel() { } void CoreModel::run() { - mCore = linphone::Factory::get()->createCore("","",nullptr); - + mCore = linphone::Factory::get()->createCore(Utils::appStringToCoreString(mConfigPath), "", nullptr); + mCore->start(); - while(!mEnd){ + while (!mEnd) { mCore->iterate(); } mCore->stop(); @@ -49,7 +50,6 @@ void CoreModel::run() { // ----------------------------------------------------------------------------- -std::shared_ptr CoreModel::getCore () { +std::shared_ptr CoreModel::getCore() { return mCore; } - diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 691606798..f9904e039 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -21,30 +21,29 @@ #ifndef CORE_MODEL_H_ #define CORE_MODEL_H_ -#include #include -#include #include +#include #include +#include // ============================================================================= - class CoreModel : public QThread { Q_OBJECT public: CoreModel(const QString &configPath, QObject *parent); ~CoreModel(); - - std::shared_ptr getCore (); - + + std::shared_ptr getCore(); + virtual void run(); - - static CoreModel *getInstance (); - + + static CoreModel *getInstance(); + bool mEnd = false; QString mConfigPath; - + std::shared_ptr mCore; }; diff --git a/Linphone/model/setting/SettingsModel.cpp b/Linphone/model/setting/SettingsModel.cpp index 383d2dcdd..bb8f34a65 100644 --- a/Linphone/model/setting/SettingsModel.cpp +++ b/Linphone/model/setting/SettingsModel.cpp @@ -18,25 +18,22 @@ * along with this program. If not, see . */ - #include "SettingsModel.hpp" - // ============================================================================= const std::string SettingsModel::UiSection("ui"); -SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { +SettingsModel::SettingsModel(QObject *parent) : QObject(parent) { } SettingsModel::~SettingsModel() { } - -bool SettingsModel::isReadOnly(const std::string& section, const std::string& name) const { - return mConfig->hasEntry(section, name+"/readonly"); +bool SettingsModel::isReadOnly(const std::string §ion, const std::string &name) const { + return mConfig->hasEntry(section, name + "/readonly"); } -std::string SettingsModel::getEntryFullName(const std::string& section, const std::string& name) const { - return isReadOnly(section, name)?name+"/readonly" : name; +std::string SettingsModel::getEntryFullName(const std::string §ion, const std::string &name) const { + return isReadOnly(section, name) ? name + "/readonly" : name; } diff --git a/Linphone/model/setting/SettingsModel.hpp b/Linphone/model/setting/SettingsModel.hpp index 6ab059a19..e828d0e4b 100644 --- a/Linphone/model/setting/SettingsModel.hpp +++ b/Linphone/model/setting/SettingsModel.hpp @@ -21,23 +21,24 @@ #ifndef SETTINGS_MODEL_H_ #define SETTINGS_MODEL_H_ -#include +#include #include #include -#include - +#include class SettingsModel : public QObject { Q_OBJECT public: - SettingsModel (QObject *parent = Q_NULLPTR); - virtual ~SettingsModel (); - - bool isReadOnly(const std::string& section, const std::string& name) const; - std::string getEntryFullName(const std::string& section, const std::string& name) const; // Return the full name of the entry : 'name/readonly' or 'name' - + SettingsModel(QObject *parent = Q_NULLPTR); + virtual ~SettingsModel(); + + bool isReadOnly(const std::string §ion, const std::string &name) const; + std::string + getEntryFullName(const std::string §ion, + const std::string &name) const; // Return the full name of the entry : 'name/readonly' or 'name' + static const std::string UiSection; - + std::shared_ptr mConfig; }; #endif // SETTINGS_MODEL_H_ diff --git a/Linphone/tool/Constants.cpp b/Linphone/tool/Constants.cpp index d5fa461d0..700b5253e 100644 --- a/Linphone/tool/Constants.cpp +++ b/Linphone/tool/Constants.cpp @@ -26,7 +26,7 @@ constexpr char Constants::DefaultFont[]; constexpr int Constants::DefaultFontPointSize; constexpr char Constants::DefaultEmojiFont[]; constexpr int Constants::DefaultEmojiFontPointSize; -QStringList Constants::getReactionsList(){ +QStringList Constants::getReactionsList() { return {"❤️", "👍", "😂", "😮", "😢"}; } constexpr char Constants::QtDomain[]; @@ -88,8 +88,6 @@ constexpr char Constants::OAuth2Password[]; constexpr char Constants::OAuth2Scope[]; constexpr char Constants::DefaultOAuth2RemoteProvisioningHeader[]; - - #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) constexpr char Constants::H264Description[]; #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) @@ -143,4 +141,3 @@ constexpr char Constants::LinphoneBZip2_exe[]; constexpr char Constants::LinphoneBZip2_dll[]; constexpr char Constants::DefaultRlsUri[]; constexpr char Constants::DefaultLogsEmail[]; - diff --git a/Linphone/tool/Constants.hpp b/Linphone/tool/Constants.hpp index 25cb2a5a6..d4791012c 100644 --- a/Linphone/tool/Constants.hpp +++ b/Linphone/tool/Constants.hpp @@ -21,21 +21,22 @@ #ifndef CONSTANTS_H_ #define CONSTANTS_H_ +#include #include #include -#include #include "config.h" // ============================================================================= -class Constants : public QObject{ +class Constants : public QObject { Q_OBJECT public: - Constants(QObject * parent = nullptr) : QObject(parent){} - - //---------------------------------------------------------------------------------- - + Constants(QObject *parent = nullptr) : QObject(parent) { + } + + //---------------------------------------------------------------------------------- + static constexpr char DefaultLocale[] = "en"; static constexpr char DefaultFont[] = "Noto Sans"; static constexpr int DefaultFontPointSize = 10; @@ -46,13 +47,13 @@ public: #endif static constexpr int DefaultEmojiFontPointSize = 10; static QStringList getReactionsList(); - - static constexpr size_t MaxLogsCollectionSize = 10485760*5; // 50MB. - + + static constexpr size_t MaxLogsCollectionSize = 10485760 * 5; // 50MB. + #ifdef ENABLE_UPDATE_CHECK static constexpr int VersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds. -#endif // ifdef ENABLE_UPDATE_CHECK - +#endif // ifdef ENABLE_UPDATE_CHECK + static constexpr char DefaultXmlrpcUri[] = "https://subscribe.linphone.org:444/wizard.php"; static constexpr char DefaultUploadLogsServer[] = "https://www.linphone.org:444/lft.php"; static constexpr char DefaultContactParameters[] = "message-expires=2419200"; @@ -67,18 +68,19 @@ public: static constexpr char PrivatePolicyUrl[] = "https://www.linphone.org/privacy-policy"; static constexpr char ContactUrl[] = "https://www.linphone.org/contact"; static constexpr char TranslationUrl[] = "https://weblate.linphone.org/projects/linphone-desktop/"; - - static constexpr int MaxMosaicParticipants = 6;// From 7, the mosaic quality will be limited to avoid useless computations - + + static constexpr int MaxMosaicParticipants = + 6; // From 7, the mosaic quality will be limited to avoid useless computations + static constexpr char LinphoneBZip2_exe[] = "https://www.linphone.org/releases/windows/tools/bzip2/bzip2.exe"; static constexpr char LinphoneBZip2_dll[] = "https://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 DefaultFlexiAPIURL[] = "https://subscribe.linphone.org/api/";// Need "/" at the end + + static constexpr char DefaultFlexiAPIURL[] = "https://subscribe.linphone.org/api/"; // Need "/" at the end static constexpr char RemoteProvisioningURL[] = "https://subscribe.linphone.org/api/provisioning"; static constexpr char RemoteProvisioningBasicAuth[] = ""; -// OAuth2 settings + // OAuth2 settings static constexpr char OAuth2AuthorizationUrl[] = ""; static constexpr char OAuth2AccessTokenUrl[] = ""; static constexpr char OAuth2RedirectUri[] = ""; @@ -86,8 +88,7 @@ public: static constexpr char OAuth2Password[] = ""; static constexpr char OAuth2Scope[] = ""; static constexpr char DefaultOAuth2RemoteProvisioningHeader[] = "x-linphone-oauth2-token"; - - + Q_PROPERTY(QString PasswordRecoveryUrl MEMBER PasswordRecoveryUrl CONSTANT) Q_PROPERTY(QString CguUrl MEMBER CguUrl CONSTANT) Q_PROPERTY(QString PrivatePolicyUrl MEMBER PrivatePolicyUrl CONSTANT) @@ -96,35 +97,38 @@ public: Q_PROPERTY(int maxMosaicParticipants MEMBER MaxMosaicParticipants CONSTANT) Q_PROPERTY(QStringList reactionsList READ getReactionsList CONSTANT) -// For Webviews + // For Webviews static constexpr char DefaultAssistantRegistrationUrl[] = "https://subscribe.linphone.org/register"; static constexpr char DefaultAssistantLoginUrl[] = "https://subscribe.linphone.org/login"; static constexpr char DefaultAssistantLogoutUrl[] = "https://subscribe.linphone.org/logout"; -//-------------- + //-------------- // Max image size in bytes. (1Mb) - static constexpr qint64 MaxImageSize = 1024000;// In Bytes. - static constexpr qint64 FileSizeLimit = 524288000;// In Bytes. + static constexpr qint64 MaxImageSize = 1024000; // In Bytes. + static constexpr qint64 FileSizeLimit = 524288000; // In Bytes. static constexpr int ThumbnailImageFileWidth = 100; static constexpr int ThumbnailImageFileHeight = 100; - -//-------------------------------------------------------------------------------- -// LINPHONE -//-------------------------------------------------------------------------------- - static constexpr char LinphoneDomain[] = "sip.linphone.org"; // Use for checking if config are a Linphone + //-------------------------------------------------------------------------------- + // LINPHONE + //-------------------------------------------------------------------------------- + + static constexpr char LinphoneDomain[] = "sip.linphone.org"; // Use for checking if config are a Linphone static constexpr char WindowIconPath[] = ":/assets/images/linphone_logo.svg"; static constexpr char ApplicationMinimalQtVersion[] = "5.10.0"; - static constexpr char DefaultConferenceURI[] = "sip:conference-factory@sip.linphone.org"; // Default for a Linphone account - static constexpr char DefaultVideoConferenceURI[] = "sip:videoconference-factory@sip.linphone.org"; // Default for a Linphone account - static constexpr char DefaultLimeServerURL[] = "https://lime.linphone.org/lime-server/lime-server.php"; // Default for a Linphone account - + static constexpr char DefaultConferenceURI[] = + "sip:conference-factory@sip.linphone.org"; // Default for a Linphone account + static constexpr char DefaultVideoConferenceURI[] = + "sip:videoconference-factory@sip.linphone.org"; // Default for a Linphone account + static constexpr char DefaultLimeServerURL[] = + "https://lime.linphone.org/lime-server/lime-server.php"; // Default for a Linphone account + 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 PathData[] = "/" EXECUTABLE_NAME; - static constexpr char PathTools[] = "/tools/"; + static constexpr char PathCodecs[] = "/codecs/"; + static constexpr char PathData[] = "/" EXECUTABLE_NAME; + static constexpr char PathTools[] = "/tools/"; static constexpr char PathLogs[] = "/logs/"; #ifdef APPLE static constexpr char PathPlugins[] = "/Plugins/"; @@ -134,7 +138,7 @@ public: static constexpr char PathPluginsApp[] = "app/"; static constexpr char PathSounds[] = "/sounds/" EXECUTABLE_NAME; static constexpr char PathUserCertificates[] = "/usr-crt/"; - + static constexpr char PathCallHistoryList[] = "/call-history.db"; static constexpr char PathConfig[] = "/linphonerc"; static constexpr char PathDatabase[] = "/linphone.db"; @@ -144,39 +148,39 @@ public: static constexpr char PathLimeDatabase[] = "/x3dh.c25519.sqlite3"; 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 LinphoneLocaleEncoding[] = "UTF-8";// Alternative is to use "locale" + static constexpr char LinphoneLocaleEncoding[] = "UTF-8"; // Alternative is to use "locale" static constexpr char VcardScheme[] = EXECUTABLE_NAME "-desktop:/"; static constexpr int CbsCallInterval = 20; static constexpr char RcVersionName[] = "rc_version"; - static constexpr int RcVersionCurrent = 6; // 2 = Conference URI - // 3 = CPIM on basic chat rooms - // 4 = RTP bundle mode - // 5 = Video Conference URI - // 6 = Publish expires -//-------------------------------------------------------------------------------- + static constexpr int RcVersionCurrent = 6; // 2 = Conference URI + // 3 = CPIM on basic chat rooms + // 4 = RTP bundle mode + // 5 = Video Conference URI + // 6 = Publish expires +//-------------------------------------------------------------------------------- // 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"; @@ -199,7 +203,7 @@ public: #endif // ifdef Q_OS_WIN64 #endif // ifdef Q_OS_LINUX -//-------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------- }; #endif diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 7d6697ac0..c091798a9 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -20,14 +20,14 @@ #include #include -#include #include #include #include +#include #include #include +#include #include -#include #include #include #include @@ -35,29 +35,27 @@ #include "config.h" #ifdef PDF_ENABLED +#include "components/pdf/PdfWidget.hpp" #include #include -#include "components/pdf/PdfWidget.hpp" #endif - -#include "Utils.hpp" #include "UriTools.hpp" +#include "Utils.hpp" #include "app/App.hpp" #include "app/paths/Paths.hpp" #include "app/providers/ImageProvider.hpp" +#include "components/contact/ContactModel.hpp" +#include "components/contact/VcardModel.hpp" +#include "components/contacts/ContactsListModel.hpp" #include "components/core/CoreManager.hpp" #include "components/other/colors/ColorListModel.hpp" #include "components/other/colors/ColorModel.hpp" #include "components/other/date/DateModel.hpp" -#include "components/contacts/ContactsListModel.hpp" -#include "components/contact/ContactModel.hpp" -#include "components/contact/VcardModel.hpp" #include "components/settings/AccountSettingsModel.hpp" #include "components/settings/SettingsModel.hpp" #include "components/sip-addresses/SipAddressesModel.hpp" - #ifdef _WIN32 #include #endif @@ -70,693 +68,742 @@ constexpr int SafeFilePathLimit = 100; } std::shared_ptr Utils::interpretUrl(const QString& address){ - bool usePrefix = CoreManager::getInstance()->getAccountSettingsModel()->getUseInternationalPrefixForCallsAndChats(); - auto interpretedAddress = CoreManager::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(address), usePrefix); - if(!interpretedAddress){// Try by removing scheme. - QStringList splitted = address.split(":"); - if(splitted.size() > 0 && splitted[0] == "sip"){ - splitted.removeFirst(); - interpretedAddress = CoreManager::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(splitted.join(":")), usePrefix); - } - } - return interpretedAddress; + bool usePrefix = CoreManager::getInstance()->getAccountSettingsModel()->getUseInternationalPrefixForCallsAndChats(); + auto interpretedAddress = CoreManager::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(address), +usePrefix); if(!interpretedAddress){// Try by removing scheme. QStringList splitted = address.split(":"); + if(splitted.size() > 0 && splitted[0] == "sip"){ + splitted.removeFirst(); + interpretedAddress = +CoreManager::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(splitted.join(":")), usePrefix); + } + } + return interpretedAddress; } char *Utils::rstrstr (const char *a, const char *b) { - size_t a_len = strlen(a); - size_t b_len = strlen(b); - - if (b_len > a_len) - return nullptr; - - for (const char *s = a + a_len - b_len; s >= a; --s) { - if (!strncmp(s, b, b_len)) - return const_cast(s); - } - - return nullptr; + size_t a_len = strlen(a); + size_t b_len = strlen(b); + + if (b_len > a_len) + return nullptr; + + for (const char *s = a + a_len - b_len; s >= a; --s) { + if (!strncmp(s, b, b_len)) + return const_cast(s); + } + + return nullptr; } // ----------------------------------------------------------------------------- -bool Utils::hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability, bool defaultCapability){ - auto addressCleaned = cleanSipAddress(address); - auto contact = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(addressCleaned); - if(contact) - return contact->hasCapability(capability); - else - return defaultCapability; +bool Utils::hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability, bool +defaultCapability){ auto addressCleaned = cleanSipAddress(address); auto contact = +CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(addressCleaned); if(contact) return +contact->hasCapability(capability); else return defaultCapability; } //-------------------------------------------------------------------------------------- QDateTime Utils::addMinutes(QDateTime date, const int& min){ - return date.addSecs(min*60); + return date.addSecs(min*60); } QDateTime Utils::getOffsettedUTC(const QDateTime& date){ - QDateTime utc = date.toUTC();// Get a date free of any offsets. - auto timezone = date.timeZone(); - utc = utc.addSecs(timezone.offsetFromUtc(date));// add offset from date timezone - utc.setTimeSpec(Qt::OffsetFromUTC);// ensure to have an UTC date - return utc; + QDateTime utc = date.toUTC();// Get a date free of any offsets. + auto timezone = date.timeZone(); + utc = utc.addSecs(timezone.offsetFromUtc(date));// add offset from date timezone + utc.setTimeSpec(Qt::OffsetFromUTC);// ensure to have an UTC date + return utc; } QString Utils::toDateTimeString(QDateTime date, const QString& format){ - if(date.date() == QDate::currentDate()) - return toTimeString(date); - else{ - return getOffsettedUTC(date).toString(format); - } + if(date.date() == QDate::currentDate()) + return toTimeString(date); + else{ + return getOffsettedUTC(date).toString(format); + } } QString Utils::toTimeString(QDateTime date, const QString& format){ // Issue : date.toString() will not print the good time in timezones. Get it from date and add ourself the offset. - return getOffsettedUTC(date).toString(format); + return getOffsettedUTC(date).toString(format); } QString Utils::toDateString(QDateTime date, const QString& format){ - return QLocale().toString(getOffsettedUTC(date), (!format.isEmpty() ? format : QLocale().dateFormat()) ); + return QLocale().toString(getOffsettedUTC(date), (!format.isEmpty() ? format : QLocale().dateFormat()) ); } QString Utils::toDateString(QDate date, const QString& format){ - return QLocale().toString(date, (!format.isEmpty() ? format : QLocale().dateFormat()) ); + return QLocale().toString(date, (!format.isEmpty() ? format : QLocale().dateFormat()) ); } // Return custom address to be displayed on UI. // In order to return only the username and to remove all domains from the GUI, you may just change the default mode. QString Utils::toDisplayString(const QString& str, SipDisplayMode displayMode){ - if(displayMode == SIP_DISPLAY_ALL) return str; - std::shared_ptr addr = linphone::Factory::get()->createAddress(str.toStdString()); - QString displayString; - if( addr && ( (displayMode & SIP_DISPLAY_USERNAME) == SIP_DISPLAY_USERNAME)) - displayString = Utils::coreStringToAppString(addr->getUsername()); - if(displayString.isEmpty()) - return str; - else - return displayString; + if(displayMode == SIP_DISPLAY_ALL) return str; + std::shared_ptr addr = linphone::Factory::get()->createAddress(str.toStdString()); + QString displayString; + if( addr && ( (displayMode & SIP_DISPLAY_USERNAME) == SIP_DISPLAY_USERNAME)) + displayString = Utils::coreStringToAppString(addr->getUsername()); + if(displayString.isEmpty()) + return str; + else + return displayString; } QDate Utils::getCurrentDate() { - return QDate::currentDate(); + return QDate::currentDate(); } DateModel* Utils::getCurrentDateModel() { - return new DateModel(QDate::currentDate()); + return new DateModel(QDate::currentDate()); } QDate Utils::getMinDate() { - return QDate(1,1,1); + return QDate(1,1,1); } DateModel* Utils::getMinDateModel() { - return new DateModel(QDate(1,1,1)); + return new DateModel(QDate(1,1,1)); } QDate Utils::toDate(const QString& str, const QString& format) { - return QDate::fromString(str, format); + return QDate::fromString(str, format); } DateModel* Utils::toDateModel(const QString& str, const QString& format) { - return new DateModel(toDate(str, format)); + return new DateModel(toDate(str, format)); } QDate Utils::getDate(int year, int month, int day) { - auto d = QDate(year, month, day); - if(!d.isValid() ){ - auto first = QDate(year, month, 1); - if(first.isValid()) { - d = first.addDays(day-1); - } - } - return d; + auto d = QDate(year, month, day); + if(!d.isValid() ){ + auto first = QDate(year, month, 1); + if(first.isValid()) { + d = first.addDays(day-1); + } + } + return d; } DateModel* Utils::getDateModel(int year, int month, int day) { - auto d = QDate(year, month, day); - if(!d.isValid() ){ - auto first = QDate(year, month, 1); - if(first.isValid()) { - d = first.addDays(day-1); - } - } - return new DateModel(d); + auto d = QDate(year, month, day); + if(!d.isValid() ){ + auto first = QDate(year, month, 1); + if(first.isValid()) { + d = first.addDays(day-1); + } + } + return new DateModel(d); } int Utils::getFullYear(const QDate& date) { - return date.year(); + return date.year(); } int Utils::getMonth(const QDate& date) { - return date.month(); + return date.month(); } int Utils::getDay(const QDate& date) { - return date.day(); + return date.day(); } int Utils::getDayOfWeek(const QDate& date) { - return date.dayOfWeek(); + return date.dayOfWeek(); } bool Utils::equals(const QDate& d1, const QDate& d2){ - return d1 == d2; + return d1 == d2; } bool Utils::isGreatherThan(const QDate& d1, const QDate& d2) { - return d1 >= d2; + return d1 >= d2; } //-------------------------------------------------------------------------------------- QString Utils::getDisplayName(const QString& address){ - QString displayName = getDisplayName(interpretUrl(address)); - return displayName.isEmpty() ? address : displayName; + QString displayName = getDisplayName(interpretUrl(address)); + return displayName.isEmpty() ? address : displayName; } QString Utils::getInitials(const QString& username){ - if(username.isEmpty()) return ""; - - QRegularExpression regex("[\\s\\.]+"); - QStringList words = username.split(regex);// Qt 5.14: Qt::SkipEmptyParts - QStringList initials; - auto str32 = words[0].toStdU32String(); - std::u32string char32; - char32 += str32[0]; - initials << QString::fromStdU32String(char32); - for(int i = 1; i < words.size() && initials.size() <= 1 ; ++i) { - if( words[i].size() > 0){ - str32 = words[i].toStdU32String(); - char32[0] = str32[0]; - initials << QString::fromStdU32String(char32); - } - } - return App::getInstance()->getLocale().toUpper(initials.join("")); + if(username.isEmpty()) return ""; + + QRegularExpression regex("[\\s\\.]+"); + QStringList words = username.split(regex);// Qt 5.14: Qt::SkipEmptyParts + QStringList initials; + auto str32 = words[0].toStdU32String(); + std::u32string char32; + char32 += str32[0]; + initials << QString::fromStdU32String(char32); + for(int i = 1; i < words.size() && initials.size() <= 1 ; ++i) { + if( words[i].size() > 0){ + str32 = words[i].toStdU32String(); + char32[0] = str32[0]; + initials << QString::fromStdU32String(char32); + } + } + return App::getInstance()->getLocale().toUpper(initials.join("")); } QString Utils::toString(const LinphoneEnums::TunnelMode& mode){ - switch(mode){ - case LinphoneEnums::TunnelMode::TunnelModeEnable : - //: 'Enable' : One word for button action to enable tunnel mode. - return QObject::tr("LinphoneEnums_TunnelModeEnable"); - case LinphoneEnums::TunnelMode::TunnelModeDisable : - //: 'Disable' : One word for button action to disable tunnel mode. - return QObject::tr("LinphoneEnums_TunnelModeDisable"); - case LinphoneEnums::TunnelMode::TunnelModeAuto : - //: 'Auto' : One word for button action to set the auto tunnel mode. - return QObject::tr("LinphoneEnums_TunnelModeAuto"); - default: - return ""; - } + switch(mode){ + case LinphoneEnums::TunnelMode::TunnelModeEnable : + //: 'Enable' : One word for button action to enable tunnel mode. + return QObject::tr("LinphoneEnums_TunnelModeEnable"); + case LinphoneEnums::TunnelMode::TunnelModeDisable : + //: 'Disable' : One word for button action to disable tunnel mode. + return QObject::tr("LinphoneEnums_TunnelModeDisable"); + case LinphoneEnums::TunnelMode::TunnelModeAuto : + //: 'Auto' : One word for button action to set the auto tunnel mode. + return QObject::tr("LinphoneEnums_TunnelModeAuto"); + default: + return ""; + } } QImage Utils::getImage(const QString &pUri) { - QImage image(pUri); - QImageReader reader(pUri); - reader.setAutoTransform(true); - if(image.isNull()){// Try to determine format from headers instead of using suffix - reader.setDecideFormatFromContent(true); - } - return reader.read(); + QImage image(pUri); + QImageReader reader(pUri); + reader.setAutoTransform(true); + if(image.isNull()){// Try to determine format from headers instead of using suffix + reader.setDecideFormatFromContent(true); + } + return reader.read(); } QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) { - if (soFarSoGood) - *soFarSoGood = true; - - QFileInfo info(filePath); - if (!info.exists()) - return filePath; - - const QString prefix = QStringLiteral("%1/%2").arg(info.absolutePath()).arg(info.baseName()); - const QString ext = info.completeSuffix(); - - 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; - } - - if (soFarSoGood) - *soFarSoGood = false; - - return QString(""); + if (soFarSoGood) + *soFarSoGood = true; + + QFileInfo info(filePath); + if (!info.exists()) + return filePath; + + const QString prefix = QStringLiteral("%1/%2").arg(info.absolutePath()).arg(info.baseName()); + const QString ext = info.completeSuffix(); + + 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; + } + + if (soFarSoGood) + *soFarSoGood = false; + + return QString(""); } std::shared_ptr Utils::getMatchingLocalAddress(std::shared_ptr p_localAddress){ - QVector > addresses; - // Get default account - addresses.push_back(CoreManager::getInstance()->getCore()->createPrimaryContactParsed()); - auto accounts = CoreManager::getInstance()->getAccountList(); - foreach(auto account, accounts) - addresses.push_back(account->getParams()->getIdentityAddress()->clone()); - foreach(auto address, addresses){ - if( address->getUsername() == p_localAddress->getUsername() && address->getDomain() == p_localAddress->getDomain()) - return address; - } - return p_localAddress; + QVector > addresses; + // Get default account + addresses.push_back(CoreManager::getInstance()->getCore()->createPrimaryContactParsed()); + auto accounts = CoreManager::getInstance()->getAccountList(); + foreach(auto account, accounts) + addresses.push_back(account->getParams()->getIdentityAddress()->clone()); + foreach(auto address, addresses){ + if( address->getUsername() == p_localAddress->getUsername() && address->getDomain() == +p_localAddress->getDomain()) return address; + } + return p_localAddress; } // Return at most : sip:username@domain QString Utils::cleanSipAddress (const QString &sipAddress) { - std::shared_ptr addr = linphone::Factory::get()->createAddress(sipAddress.toStdString()); - if( addr) { - addr->clean(); - QStringList fields = Utils::coreStringToAppString(addr->asStringUriOnly()).split('@'); - if(fields.size() > 0){// maybe useless but it's just to be sure to have a domain - fields.removeLast(); - QString domain = Utils::coreStringToAppString(addr->getDomain()); - if( domain.count(':')>1) - fields.append('['+domain+']'); - else - fields.append(domain); - return fields.join('@'); - } - } - return sipAddress; + std::shared_ptr addr = linphone::Factory::get()->createAddress(sipAddress.toStdString()); + if( addr) { + addr->clean(); + QStringList fields = Utils::coreStringToAppString(addr->asStringUriOnly()).split('@'); + if(fields.size() > 0){// maybe useless but it's just to be sure to have a domain + fields.removeLast(); + QString domain = Utils::coreStringToAppString(addr->getDomain()); + if( domain.count(':')>1) + fields.append('['+domain+']'); + else + fields.append(domain); + return fields.join('@'); + } + } + return sipAddress; } // Data to retrieve WIN32 process #ifdef _WIN32 #include struct EnumData { - DWORD dwProcessId; - HWND hWnd; + DWORD dwProcessId; + HWND hWnd; }; // Application-defined callback for EnumWindows BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam) { - // Retrieve storage location for communication data - EnumData& ed = *(EnumData*)lParam; - DWORD dwProcessId = 0x0; - // Query process ID for hWnd - GetWindowThreadProcessId(hWnd, &dwProcessId); - // Apply filter - if you want to implement additional restrictions, - // this is the place to do so. - if (ed.dwProcessId == dwProcessId) { - // Found a window matching the process ID - ed.hWnd = hWnd; - // Report success - SetLastError(ERROR_SUCCESS); - // Stop enumeration - return FALSE; - } - // Continue enumeration - return TRUE; + // Retrieve storage location for communication data + EnumData& ed = *(EnumData*)lParam; + DWORD dwProcessId = 0x0; + // Query process ID for hWnd + GetWindowThreadProcessId(hWnd, &dwProcessId); + // Apply filter - if you want to implement additional restrictions, + // this is the place to do so. + if (ed.dwProcessId == dwProcessId) { + // Found a window matching the process ID + ed.hWnd = hWnd; + // Report success + SetLastError(ERROR_SUCCESS); + // Stop enumeration + return FALSE; + } + // Continue enumeration + return TRUE; } // Main entry HWND FindWindowFromProcessId(DWORD dwProcessId) { - EnumData ed = { dwProcessId }; - if (!EnumWindows(EnumProc, (LPARAM)&ed) && - (GetLastError() == ERROR_SUCCESS)) { - return ed.hWnd; - } - return NULL; + EnumData ed = { dwProcessId }; + if (!EnumWindows(EnumProc, (LPARAM)&ed) && + (GetLastError() == ERROR_SUCCESS)) { + return ed.hWnd; + } + return NULL; } // Helper method for convenience HWND FindWindowFromProcess(HANDLE hProcess) { - return FindWindowFromProcessId(GetProcessId(hProcess)); + return FindWindowFromProcessId(GetProcessId(hProcess)); } #endif bool Utils::processExists(const quint64& p_processId) { #ifdef _WIN32 - return FindWindowFromProcessId(p_processId) != NULL; + return FindWindowFromProcessId(p_processId) != NULL; #else - return true; + return true; #endif } QString Utils::getCountryName(const QLocale::Country& p_country) { - QString countryName; - switch(p_country) - { - case QLocale::Afghanistan: if((countryName = QCoreApplication::translate("country", "Afghanistan"))== "Afghanistan") countryName = "";break; - case QLocale::Albania: if((countryName = QCoreApplication::translate("country", "Albania"))== "Albania") countryName = "";break; - case QLocale::Algeria: if((countryName = QCoreApplication::translate("country", "Algeria"))== "Algeria") countryName = "";break; - case QLocale::AmericanSamoa: if((countryName = QCoreApplication::translate("country", "AmericanSamoa"))== "AmericanSamoa") countryName = "";break; - case QLocale::Andorra: if((countryName = QCoreApplication::translate("country", "Andorra"))== "Andorra") countryName = "";break; - case QLocale::Angola: if((countryName = QCoreApplication::translate("country", "Angola"))== "Angola") countryName = "";break; - case QLocale::Anguilla: if((countryName = QCoreApplication::translate("country", "Anguilla"))== "Anguilla") countryName = "";break; - case QLocale::AntiguaAndBarbuda: if((countryName = QCoreApplication::translate("country", "AntiguaAndBarbuda"))== "AntiguaAndBarbuda") countryName = "";break; - case QLocale::Argentina: if((countryName = QCoreApplication::translate("country", "Argentina"))== "Argentina") countryName = "";break; - case QLocale::Armenia: if((countryName = QCoreApplication::translate("country", "Armenia"))== "Armenia") countryName = "";break; - case QLocale::Aruba: if((countryName = QCoreApplication::translate("country", "Aruba"))== "Aruba") countryName = "";break; - case QLocale::Australia: if((countryName = QCoreApplication::translate("country", "Australia"))== "Australia") countryName = "";break; - case QLocale::Austria: if((countryName = QCoreApplication::translate("country", "Austria"))== "Austria") countryName = "";break; - case QLocale::Azerbaijan: if((countryName = QCoreApplication::translate("country", "Azerbaijan"))== "Azerbaijan") countryName = "";break; - case QLocale::Bahamas: if((countryName = QCoreApplication::translate("country", "Bahamas"))== "Bahamas") countryName = "";break; - case QLocale::Bahrain: if((countryName = QCoreApplication::translate("country", "Bahrain"))== "Bahrain") countryName = "";break; - case QLocale::Bangladesh: if((countryName = QCoreApplication::translate("country", "Bangladesh"))== "Bangladesh") countryName = "";break; - case QLocale::Barbados: if((countryName = QCoreApplication::translate("country", "Barbados"))== "Barbados") countryName = "";break; - case QLocale::Belarus: if((countryName = QCoreApplication::translate("country", "Belarus"))== "Belarus") countryName = "";break; - case QLocale::Belgium: if((countryName = QCoreApplication::translate("country", "Belgium"))== "Belgium") countryName = "";break; - case QLocale::Belize: if((countryName = QCoreApplication::translate("country", "Belize"))== "Belize") countryName = "";break; - case QLocale::Benin: if((countryName = QCoreApplication::translate("country", "Benin"))== "Benin") countryName = "";break; - case QLocale::Bermuda: if((countryName = QCoreApplication::translate("country", "Bermuda"))== "Bermuda") countryName = "";break; - case QLocale::Bhutan: if((countryName = QCoreApplication::translate("country", "Bhutan"))== "Bhutan") countryName = "";break; - case QLocale::Bolivia: if((countryName = QCoreApplication::translate("country", "Bolivia"))== "Bolivia") countryName = "";break; - case QLocale::BosniaAndHerzegowina: if((countryName = QCoreApplication::translate("country", "BosniaAndHerzegowina"))== "BosniaAndHerzegowina") countryName = "";break; - case QLocale::Botswana: if((countryName = QCoreApplication::translate("country", "Botswana"))== "Botswana") countryName = "";break; - case QLocale::Brazil: if((countryName = QCoreApplication::translate("country", "Brazil"))== "Brazil") countryName = "";break; - case QLocale::Brunei: if((countryName = QCoreApplication::translate("country", "Brunei"))== "Brunei") countryName = "";break; - case QLocale::Bulgaria: if((countryName = QCoreApplication::translate("country", "Bulgaria"))== "Bulgaria") countryName = "";break; - case QLocale::BurkinaFaso: if((countryName = QCoreApplication::translate("country", "BurkinaFaso"))== "BurkinaFaso") countryName = "";break; - case QLocale::Burundi: if((countryName = QCoreApplication::translate("country", "Burundi"))== "Burundi") countryName = "";break; - case QLocale::Cambodia: if((countryName = QCoreApplication::translate("country", "Cambodia"))== "Cambodia") countryName = "";break; - case QLocale::Cameroon: if((countryName = QCoreApplication::translate("country", "Cameroon"))== "Cameroon") countryName = "";break; - case QLocale::Canada: if((countryName = QCoreApplication::translate("country", "Canada"))== "Canada") countryName = "";break; - case QLocale::CapeVerde: if((countryName = QCoreApplication::translate("country", "CapeVerde"))== "CapeVerde") countryName = "";break; - case QLocale::CaymanIslands: if((countryName = QCoreApplication::translate("country", "CaymanIslands"))== "CaymanIslands") countryName = "";break; - case QLocale::CentralAfricanRepublic: if((countryName = QCoreApplication::translate("country", "CentralAfricanRepublic"))== "CentralAfricanRepublic") countryName = "";break; - case QLocale::Chad: if((countryName = QCoreApplication::translate("country", "Chad"))== "Chad") countryName = "";break; - case QLocale::Chile: if((countryName = QCoreApplication::translate("country", "Chile"))== "Chile") countryName = "";break; - case QLocale::China: if((countryName = QCoreApplication::translate("country", "China"))== "China") countryName = "";break; - case QLocale::Colombia: if((countryName = QCoreApplication::translate("country", "Colombia"))== "Colombia") countryName = "";break; - case QLocale::Comoros: if((countryName = QCoreApplication::translate("country", "Comoros"))== "Comoros") countryName = "";break; - case QLocale::PeoplesRepublicOfCongo: if((countryName = QCoreApplication::translate("country", "PeoplesRepublicOfCongo"))== "PeoplesRepublicOfCongo") countryName = "";break; - case QLocale::DemocraticRepublicOfCongo: if((countryName = QCoreApplication::translate("country", "DemocraticRepublicOfCongo"))== "DemocraticRepublicOfCongo") countryName = "";break; - case QLocale::CookIslands: if((countryName = QCoreApplication::translate("country", "CookIslands"))== "CookIslands") countryName = "";break; - case QLocale::CostaRica: if((countryName = QCoreApplication::translate("country", "CostaRica"))== "CostaRica") countryName = "";break; - case QLocale::IvoryCoast: if((countryName = QCoreApplication::translate("country", "IvoryCoast"))== "IvoryCoast") countryName = "";break; - case QLocale::Croatia: if((countryName = QCoreApplication::translate("country", "Croatia"))== "Croatia") countryName = "";break; - case QLocale::Cuba: if((countryName = QCoreApplication::translate("country", "Cuba"))== "Cuba") countryName = "";break; - case QLocale::Cyprus: if((countryName = QCoreApplication::translate("country", "Cyprus"))== "Cyprus") countryName = "";break; - case QLocale::CzechRepublic: if((countryName = QCoreApplication::translate("country", "CzechRepublic"))== "CzechRepublic") countryName = "";break; - case QLocale::Denmark: if((countryName = QCoreApplication::translate("country", "Denmark"))== "Denmark") countryName = "";break; - case QLocale::Djibouti: if((countryName = QCoreApplication::translate("country", "Djibouti"))== "Djibouti") countryName = "";break; - case QLocale::Dominica: if((countryName = QCoreApplication::translate("country", "Dominica"))== "Dominica") countryName = "";break; - case QLocale::DominicanRepublic: if((countryName = QCoreApplication::translate("country", "DominicanRepublic"))== "DominicanRepublic") countryName = "";break; - case QLocale::Ecuador: if((countryName = QCoreApplication::translate("country", "Ecuador"))== "Ecuador") countryName = "";break; - case QLocale::Egypt: if((countryName = QCoreApplication::translate("country", "Egypt"))== "Egypt") countryName = "";break; - case QLocale::ElSalvador: if((countryName = QCoreApplication::translate("country", "ElSalvador"))== "ElSalvador") countryName = "";break; - case QLocale::EquatorialGuinea: if((countryName = QCoreApplication::translate("country", "EquatorialGuinea"))== "EquatorialGuinea") countryName = "";break; - case QLocale::Eritrea: if((countryName = QCoreApplication::translate("country", "Eritrea"))== "Eritrea") countryName = "";break; - case QLocale::Estonia: if((countryName = QCoreApplication::translate("country", "Estonia"))== "Estonia") countryName = "";break; - case QLocale::Ethiopia: if((countryName = QCoreApplication::translate("country", "Ethiopia"))== "Ethiopia") countryName = "";break; - case QLocale::FalklandIslands: if((countryName = QCoreApplication::translate("country", "FalklandIslands"))== "FalklandIslands") countryName = "";break; - case QLocale::FaroeIslands: if((countryName = QCoreApplication::translate("country", "FaroeIslands"))== "FaroeIslands") countryName = "";break; - case QLocale::Fiji: if((countryName = QCoreApplication::translate("country", "Fiji"))== "Fiji") countryName = "";break; - case QLocale::Finland: if((countryName = QCoreApplication::translate("country", "Finland"))== "Finland") countryName = "";break; - case QLocale::France: if((countryName = QCoreApplication::translate("country", "France"))== "France") countryName = "";break; - case QLocale::FrenchGuiana: if((countryName = QCoreApplication::translate("country", "FrenchGuiana"))== "FrenchGuiana") countryName = "";break; - case QLocale::FrenchPolynesia: if((countryName = QCoreApplication::translate("country", "FrenchPolynesia"))== "FrenchPolynesia") countryName = "";break; - case QLocale::Gabon: if((countryName = QCoreApplication::translate("country", "Gabon"))== "Gabon") countryName = "";break; - case QLocale::Gambia: if((countryName = QCoreApplication::translate("country", "Gambia"))== "Gambia") countryName = "";break; - case QLocale::Georgia: if((countryName = QCoreApplication::translate("country", "Georgia"))== "Georgia") countryName = "";break; - case QLocale::Germany: if((countryName = QCoreApplication::translate("country", "Germany"))== "Germany") countryName = "";break; - case QLocale::Ghana: if((countryName = QCoreApplication::translate("country", "Ghana"))== "Ghana") countryName = "";break; - case QLocale::Gibraltar: if((countryName = QCoreApplication::translate("country", "Gibraltar"))== "Gibraltar") countryName = "";break; - case QLocale::Greece: if((countryName = QCoreApplication::translate("country", "Greece"))== "Greece") countryName = "";break; - case QLocale::Greenland: if((countryName = QCoreApplication::translate("country", "Greenland"))== "Greenland") countryName = "";break; - case QLocale::Grenada: if((countryName = QCoreApplication::translate("country", "Grenada"))== "Grenada") countryName = "";break; - case QLocale::Guadeloupe: if((countryName = QCoreApplication::translate("country", "Guadeloupe"))== "Guadeloupe") countryName = "";break; - case QLocale::Guam: if((countryName = QCoreApplication::translate("country", "Guam"))== "Guam") countryName = "";break; - case QLocale::Guatemala: if((countryName = QCoreApplication::translate("country", "Guatemala"))== "Guatemala") countryName = "";break; - case QLocale::Guinea: if((countryName = QCoreApplication::translate("country", "Guinea"))== "Guinea") countryName = "";break; - case QLocale::GuineaBissau: if((countryName = QCoreApplication::translate("country", "GuineaBissau"))== "GuineaBissau") countryName = "";break; - case QLocale::Guyana: if((countryName = QCoreApplication::translate("country", "Guyana"))== "Guyana") countryName = "";break; - case QLocale::Haiti: if((countryName = QCoreApplication::translate("country", "Haiti"))== "Haiti") countryName = "";break; - case QLocale::Honduras: if((countryName = QCoreApplication::translate("country", "Honduras"))== "Honduras") countryName = "";break; - case QLocale::HongKong: if((countryName = QCoreApplication::translate("country", "HongKong"))== "HongKong") countryName = "";break; - case QLocale::Hungary: if((countryName = QCoreApplication::translate("country", "Hungary"))== "Hungary") countryName = "";break; - case QLocale::Iceland: if((countryName = QCoreApplication::translate("country", "Iceland"))== "Iceland") countryName = "";break; - case QLocale::India: if((countryName = QCoreApplication::translate("country", "India"))== "India") countryName = "";break; - case QLocale::Indonesia: if((countryName = QCoreApplication::translate("country", "Indonesia"))== "Indonesia") countryName = "";break; - case QLocale::Iran: if((countryName = QCoreApplication::translate("country", "Iran"))== "Iran") countryName = "";break; - case QLocale::Iraq: if((countryName = QCoreApplication::translate("country", "Iraq"))== "Iraq") countryName = "";break; - case QLocale::Ireland: if((countryName = QCoreApplication::translate("country", "Ireland"))== "Ireland") countryName = "";break; - case QLocale::Israel: if((countryName = QCoreApplication::translate("country", "Israel"))== "Israel") countryName = "";break; - case QLocale::Italy: if((countryName = QCoreApplication::translate("country", "Italy"))== "Italy") countryName = "";break; - case QLocale::Jamaica: if((countryName = QCoreApplication::translate("country", "Jamaica"))== "Jamaica") countryName = "";break; - case QLocale::Japan: if((countryName = QCoreApplication::translate("country", "Japan"))== "Japan") countryName = "";break; - case QLocale::Jordan: if((countryName = QCoreApplication::translate("country", "Jordan"))== "Jordan") countryName = "";break; - case QLocale::Kazakhstan: if((countryName = QCoreApplication::translate("country", "Kazakhstan"))== "Kazakhstan") countryName = "";break; - case QLocale::Kenya: if((countryName = QCoreApplication::translate("country", "Kenya"))== "Kenya") countryName = "";break; - case QLocale::Kiribati: if((countryName = QCoreApplication::translate("country", "Kiribati"))== "Kiribati") countryName = "";break; - case QLocale::DemocraticRepublicOfKorea: if((countryName = QCoreApplication::translate("country", "DemocraticRepublicOfKorea"))== "DemocraticRepublicOfKorea") countryName = "";break; - case QLocale::RepublicOfKorea: if((countryName = QCoreApplication::translate("country", "RepublicOfKorea"))== "RepublicOfKorea") countryName = "";break; - case QLocale::Kuwait: if((countryName = QCoreApplication::translate("country", "Kuwait"))== "Kuwait") countryName = "";break; - case QLocale::Kyrgyzstan: if((countryName = QCoreApplication::translate("country", "Kyrgyzstan"))== "Kyrgyzstan") countryName = "";break; - case QLocale::Laos: if((countryName = QCoreApplication::translate("country", "Laos"))== "Laos") countryName = "";break; - case QLocale::Latvia: if((countryName = QCoreApplication::translate("country", "Latvia"))== "Latvia") countryName = "";break; - case QLocale::Lebanon: if((countryName = QCoreApplication::translate("country", "Lebanon"))== "Lebanon") countryName = "";break; - case QLocale::Lesotho: if((countryName = QCoreApplication::translate("country", "Lesotho"))== "Lesotho") countryName = "";break; - case QLocale::Liberia: if((countryName = QCoreApplication::translate("country", "Liberia"))== "Liberia") countryName = "";break; - case QLocale::Libya: if((countryName = QCoreApplication::translate("country", "Libya"))== "Libya") countryName = "";break; - case QLocale::Liechtenstein: if((countryName = QCoreApplication::translate("country", "Liechtenstein"))== "Liechtenstein") countryName = "";break; - case QLocale::Lithuania: if((countryName = QCoreApplication::translate("country", "Lithuania"))== "Lithuania") countryName = "";break; - case QLocale::Luxembourg: if((countryName = QCoreApplication::translate("country", "Luxembourg"))== "Luxembourg") countryName = "";break; - case QLocale::Macau: if((countryName = QCoreApplication::translate("country", "Macau"))== "Macau") countryName = "";break; - case QLocale::Macedonia: if((countryName = QCoreApplication::translate("country", "Macedonia"))== "Macedonia") countryName = "";break; - case QLocale::Madagascar: if((countryName = QCoreApplication::translate("country", "Madagascar"))== "Madagascar") countryName = "";break; - case QLocale::Malawi: if((countryName = QCoreApplication::translate("country", "Malawi"))== "Malawi") countryName = "";break; - case QLocale::Malaysia: if((countryName = QCoreApplication::translate("country", "Malaysia"))== "Malaysia") countryName = "";break; - case QLocale::Maldives: if((countryName = QCoreApplication::translate("country", "Maldives"))== "Maldives") countryName = "";break; - case QLocale::Mali: if((countryName = QCoreApplication::translate("country", "Mali"))== "Mali") countryName = "";break; - case QLocale::Malta: if((countryName = QCoreApplication::translate("country", "Malta"))== "Malta") countryName = "";break; - case QLocale::MarshallIslands: if((countryName = QCoreApplication::translate("country", "MarshallIslands"))== "MarshallIslands") countryName = "";break; - case QLocale::Martinique: if((countryName = QCoreApplication::translate("country", "Martinique"))== "Martinique") countryName = "";break; - case QLocale::Mauritania: if((countryName = QCoreApplication::translate("country", "Mauritania"))== "Mauritania") countryName = "";break; - case QLocale::Mauritius: if((countryName = QCoreApplication::translate("country", "Mauritius"))== "Mauritius") countryName = "";break; - case QLocale::Mayotte: if((countryName = QCoreApplication::translate("country", "Mayotte"))== "Mayotte") countryName = "";break; - case QLocale::Mexico: if((countryName = QCoreApplication::translate("country", "Mexico"))== "Mexico") countryName = "";break; - case QLocale::Micronesia: if((countryName = QCoreApplication::translate("country", "Micronesia"))== "Micronesia") countryName = "";break; - case QLocale::Moldova: if((countryName = QCoreApplication::translate("country", "Moldova"))== "Moldova") countryName = "";break; - case QLocale::Monaco: if((countryName = QCoreApplication::translate("country", "Monaco"))== "Monaco") countryName = "";break; - case QLocale::Mongolia: if((countryName = QCoreApplication::translate("country", "Mongolia"))== "Mongolia") countryName = "";break; - case QLocale::Montenegro: if((countryName = QCoreApplication::translate("country", "Montenegro"))== "Montenegro") countryName = "";break; - case QLocale::Montserrat: if((countryName = QCoreApplication::translate("country", "Montserrat"))== "Montserrat") countryName = "";break; - case QLocale::Morocco: if((countryName = QCoreApplication::translate("country", "Morocco"))== "Morocco") countryName = "";break; - case QLocale::Mozambique: if((countryName = QCoreApplication::translate("country", "Mozambique"))== "Mozambique") countryName = "";break; - case QLocale::Myanmar: if((countryName = QCoreApplication::translate("country", "Myanmar"))== "Myanmar") countryName = "";break; - case QLocale::Namibia: if((countryName = QCoreApplication::translate("country", "Namibia"))== "Namibia") countryName = "";break; - case QLocale::NauruCountry: if((countryName = QCoreApplication::translate("country", "NauruCountry"))== "NauruCountry") countryName = "";break; - case QLocale::Nepal: if((countryName = QCoreApplication::translate("country", "Nepal"))== "Nepal") countryName = "";break; - case QLocale::Netherlands: if((countryName = QCoreApplication::translate("country", "Netherlands"))== "Netherlands") countryName = "";break; - case QLocale::NewCaledonia: if((countryName = QCoreApplication::translate("country", "NewCaledonia"))== "NewCaledonia") countryName = "";break; - case QLocale::NewZealand: if((countryName = QCoreApplication::translate("country", "NewZealand"))== "NewZealand") countryName = "";break; - case QLocale::Nicaragua: if((countryName = QCoreApplication::translate("country", "Nicaragua"))== "Nicaragua") countryName = "";break; - case QLocale::Niger: if((countryName = QCoreApplication::translate("country", "Niger"))== "Niger") countryName = "";break; - case QLocale::Nigeria: if((countryName = QCoreApplication::translate("country", "Nigeria"))== "Nigeria") countryName = "";break; - case QLocale::Niue: if((countryName = QCoreApplication::translate("country", "Niue"))== "Niue") countryName = "";break; - case QLocale::NorfolkIsland: if((countryName = QCoreApplication::translate("country", "NorfolkIsland"))== "NorfolkIsland") countryName = "";break; - case QLocale::NorthernMarianaIslands: if((countryName = QCoreApplication::translate("country", "NorthernMarianaIslands"))== "NorthernMarianaIslands") countryName = "";break; - case QLocale::Norway: if((countryName = QCoreApplication::translate("country", "Norway"))== "Norway") countryName = "";break; - case QLocale::Oman: if((countryName = QCoreApplication::translate("country", "Oman"))== "Oman") countryName = "";break; - case QLocale::Pakistan: if((countryName = QCoreApplication::translate("country", "Pakistan"))== "Pakistan") countryName = "";break; - case QLocale::Palau: if((countryName = QCoreApplication::translate("country", "Palau"))== "Palau") countryName = "";break; - case QLocale::PalestinianTerritories: if((countryName = QCoreApplication::translate("country", "PalestinianTerritories"))== "PalestinianTerritories") countryName = "";break; - case QLocale::Panama: if((countryName = QCoreApplication::translate("country", "Panama"))== "Panama") countryName = "";break; - case QLocale::PapuaNewGuinea: if((countryName = QCoreApplication::translate("country", "PapuaNewGuinea"))== "PapuaNewGuinea") countryName = "";break; - case QLocale::Paraguay: if((countryName = QCoreApplication::translate("country", "Paraguay"))== "Paraguay") countryName = "";break; - case QLocale::Peru: if((countryName = QCoreApplication::translate("country", "Peru"))== "Peru") countryName = "";break; - case QLocale::Philippines: if((countryName = QCoreApplication::translate("country", "Philippines"))== "Philippines") countryName = "";break; - case QLocale::Poland: if((countryName = QCoreApplication::translate("country", "Poland"))== "Poland") countryName = "";break; - case QLocale::Portugal: if((countryName = QCoreApplication::translate("country", "Portugal"))== "Portugal") countryName = "";break; - case QLocale::PuertoRico: if((countryName = QCoreApplication::translate("country", "PuertoRico"))== "PuertoRico") countryName = "";break; - case QLocale::Qatar: if((countryName = QCoreApplication::translate("country", "Qatar"))== "Qatar") countryName = "";break; - case QLocale::Reunion: if((countryName = QCoreApplication::translate("country", "Reunion"))== "Reunion") countryName = "";break; - case QLocale::Romania: if((countryName = QCoreApplication::translate("country", "Romania"))== "Romania") countryName = "";break; - case QLocale::RussianFederation: if((countryName = QCoreApplication::translate("country", "RussianFederation"))== "RussianFederation") countryName = "";break; - case QLocale::Rwanda: if((countryName = QCoreApplication::translate("country", "Rwanda"))== "Rwanda") countryName = "";break; - case QLocale::SaintHelena: if((countryName = QCoreApplication::translate("country", "SaintHelena"))== "SaintHelena") countryName = "";break; - case QLocale::SaintKittsAndNevis: if((countryName = QCoreApplication::translate("country", "SaintKittsAndNevis"))== "SaintKittsAndNevis") countryName = "";break; - case QLocale::SaintLucia: if((countryName = QCoreApplication::translate("country", "SaintLucia"))== "SaintLucia") countryName = "";break; - case QLocale::SaintPierreAndMiquelon: if((countryName = QCoreApplication::translate("country", "SaintPierreAndMiquelon"))== "SaintPierreAndMiquelon") countryName = "";break; - case QLocale::SaintVincentAndTheGrenadines: if((countryName = QCoreApplication::translate("country", "SaintVincentAndTheGrenadines"))== "SaintVincentAndTheGrenadines") countryName = "";break; - case QLocale::Samoa: if((countryName = QCoreApplication::translate("country", "Samoa"))== "Samoa") countryName = "";break; - case QLocale::SanMarino: if((countryName = QCoreApplication::translate("country", "SanMarino"))== "SanMarino") countryName = "";break; - case QLocale::SaoTomeAndPrincipe: if((countryName = QCoreApplication::translate("country", "SaoTomeAndPrincipe"))== "SaoTomeAndPrincipe") countryName = "";break; - case QLocale::SaudiArabia: if((countryName = QCoreApplication::translate("country", "SaudiArabia"))== "SaudiArabia") countryName = "";break; - case QLocale::Senegal: if((countryName = QCoreApplication::translate("country", "Senegal"))== "Senegal") countryName = "";break; - case QLocale::Serbia: if((countryName = QCoreApplication::translate("country", "Serbia"))== "Serbia") countryName = "";break; - case QLocale::Seychelles: if((countryName = QCoreApplication::translate("country", "Seychelles"))== "Seychelles") countryName = "";break; - case QLocale::SierraLeone: if((countryName = QCoreApplication::translate("country", "SierraLeone"))== "SierraLeone") countryName = "";break; - case QLocale::Singapore: if((countryName = QCoreApplication::translate("country", "Singapore"))== "Singapore") countryName = "";break; - case QLocale::Slovakia: if((countryName = QCoreApplication::translate("country", "Slovakia"))== "Slovakia") countryName = "";break; - case QLocale::Slovenia: if((countryName = QCoreApplication::translate("country", "Slovenia"))== "Slovenia") countryName = "";break; - case QLocale::SolomonIslands: if((countryName = QCoreApplication::translate("country", "SolomonIslands"))== "SolomonIslands") countryName = "";break; - case QLocale::Somalia: if((countryName = QCoreApplication::translate("country", "Somalia"))== "Somalia") countryName = "";break; - case QLocale::SouthAfrica: if((countryName = QCoreApplication::translate("country", "SouthAfrica"))== "SouthAfrica") countryName = "";break; - case QLocale::Spain: if((countryName = QCoreApplication::translate("country", "Spain"))== "Spain") countryName = "";break; - case QLocale::SriLanka: if((countryName = QCoreApplication::translate("country", "SriLanka"))== "SriLanka") countryName = "";break; - case QLocale::Sudan: if((countryName = QCoreApplication::translate("country", "Sudan"))== "Sudan") countryName = "";break; - case QLocale::Suriname: if((countryName = QCoreApplication::translate("country", "Suriname"))== "Suriname") countryName = "";break; - case QLocale::Swaziland: if((countryName = QCoreApplication::translate("country", "Swaziland"))== "Swaziland") countryName = "";break; - case QLocale::Sweden: if((countryName = QCoreApplication::translate("country", "Sweden"))== "Sweden") countryName = "";break; - case QLocale::Switzerland: if((countryName = QCoreApplication::translate("country", "Switzerland"))== "Switzerland") countryName = "";break; - case QLocale::Syria: if((countryName = QCoreApplication::translate("country", "Syria"))== "Syria") countryName = "";break; - case QLocale::Taiwan: if((countryName = QCoreApplication::translate("country", "Taiwan"))== "Taiwan") countryName = "";break; - case QLocale::Tajikistan: if((countryName = QCoreApplication::translate("country", "Tajikistan"))== "Tajikistan") countryName = "";break; - case QLocale::Tanzania: if((countryName = QCoreApplication::translate("country", "Tanzania"))== "Tanzania") countryName = "";break; - case QLocale::Thailand: if((countryName = QCoreApplication::translate("country", "Thailand"))== "Thailand") countryName = "";break; - case QLocale::Togo: if((countryName = QCoreApplication::translate("country", "Togo"))== "Togo") countryName = "";break; - case QLocale::Tokelau: if((countryName = QCoreApplication::translate("country", "Tokelau"))== "Tokelau") countryName = "";break; - case QLocale::Tonga: if((countryName = QCoreApplication::translate("country", "Tonga"))== "Tonga") countryName = "";break; - case QLocale::TrinidadAndTobago: if((countryName = QCoreApplication::translate("country", "TrinidadAndTobago"))== "TrinidadAndTobago") countryName = "";break; - case QLocale::Tunisia: if((countryName = QCoreApplication::translate("country", "Tunisia"))== "Tunisia") countryName = "";break; - case QLocale::Turkey: if((countryName = QCoreApplication::translate("country", "Turkey"))== "Turkey") countryName = "";break; - case QLocale::Turkmenistan: if((countryName = QCoreApplication::translate("country", "Turkmenistan"))== "Turkmenistan") countryName = "";break; - case QLocale::TurksAndCaicosIslands: if((countryName = QCoreApplication::translate("country", "TurksAndCaicosIslands"))== "TurksAndCaicosIslands") countryName = "";break; - case QLocale::Tuvalu: if((countryName = QCoreApplication::translate("country", "Tuvalu"))== "Tuvalu") countryName = "";break; - case QLocale::Uganda: if((countryName = QCoreApplication::translate("country", "Uganda"))== "Uganda") countryName = "";break; - case QLocale::Ukraine: if((countryName = QCoreApplication::translate("country", "Ukraine"))== "Ukraine") countryName = "";break; - case QLocale::UnitedArabEmirates: if((countryName = QCoreApplication::translate("country", "UnitedArabEmirates"))== "UnitedArabEmirates") countryName = "";break; - case QLocale::UnitedKingdom: if((countryName = QCoreApplication::translate("country", "UnitedKingdom"))== "UnitedKingdom") countryName = "";break; - case QLocale::UnitedStates: if((countryName = QCoreApplication::translate("country", "UnitedStates"))== "UnitedStates") countryName = "";break; - case QLocale::Uruguay: if((countryName = QCoreApplication::translate("country", "Uruguay"))== "Uruguay") countryName = "";break; - case QLocale::Uzbekistan: if((countryName = QCoreApplication::translate("country", "Uzbekistan"))== "Uzbekistan") countryName = "";break; - case QLocale::Vanuatu: if((countryName = QCoreApplication::translate("country", "Vanuatu"))== "Vanuatu") countryName = "";break; - case QLocale::Venezuela: if((countryName = QCoreApplication::translate("country", "Venezuela"))== "Venezuela") countryName = "";break; - case QLocale::Vietnam: if((countryName = QCoreApplication::translate("country", "Vietnam"))== "Vietnam") countryName = "";break; - case QLocale::WallisAndFutunaIslands: if((countryName = QCoreApplication::translate("country", "WallisAndFutunaIslands"))== "WallisAndFutunaIslands") countryName = "";break; - case QLocale::Yemen: if((countryName = QCoreApplication::translate("country", "Yemen"))== "Yemen") countryName = "";break; - case QLocale::Zambia: if((countryName = QCoreApplication::translate("country", "Zambia"))== "Zambia") countryName = "";break; - case QLocale::Zimbabwe: if((countryName = QCoreApplication::translate("country", "Zimbabwe"))== "Zimbabwe") countryName = "";break; - default: { - countryName = QLocale::countryToString(p_country); - } - } - if( countryName == "") - countryName = QLocale::countryToString(p_country); - return countryName; + QString countryName; + switch(p_country) + { + case QLocale::Afghanistan: if((countryName = QCoreApplication::translate("country", "Afghanistan"))== +"Afghanistan") countryName = "";break; case QLocale::Albania: if((countryName = QCoreApplication::translate("country", +"Albania"))== "Albania") countryName = "";break; case QLocale::Algeria: if((countryName = +QCoreApplication::translate("country", "Algeria"))== "Algeria") countryName = "";break; case QLocale::AmericanSamoa: +if((countryName = QCoreApplication::translate("country", "AmericanSamoa"))== "AmericanSamoa") countryName = "";break; + case QLocale::Andorra: if((countryName = QCoreApplication::translate("country", "Andorra"))== "Andorra") +countryName = "";break; case QLocale::Angola: if((countryName = QCoreApplication::translate("country", "Angola"))== +"Angola") countryName = "";break; case QLocale::Anguilla: if((countryName = QCoreApplication::translate("country", +"Anguilla"))== "Anguilla") countryName = "";break; case QLocale::AntiguaAndBarbuda: if((countryName = +QCoreApplication::translate("country", "AntiguaAndBarbuda"))== "AntiguaAndBarbuda") countryName = "";break; case +QLocale::Argentina: if((countryName = QCoreApplication::translate("country", "Argentina"))== "Argentina") countryName = +"";break; case QLocale::Armenia: if((countryName = QCoreApplication::translate("country", "Armenia"))== "Armenia") +countryName = "";break; case QLocale::Aruba: if((countryName = QCoreApplication::translate("country", "Aruba"))== +"Aruba") countryName = "";break; case QLocale::Australia: if((countryName = QCoreApplication::translate("country", +"Australia"))== "Australia") countryName = "";break; case QLocale::Austria: if((countryName = +QCoreApplication::translate("country", "Austria"))== "Austria") countryName = "";break; case QLocale::Azerbaijan: +if((countryName = QCoreApplication::translate("country", "Azerbaijan"))== "Azerbaijan") countryName = "";break; case +QLocale::Bahamas: if((countryName = QCoreApplication::translate("country", "Bahamas"))== "Bahamas") countryName = +"";break; case QLocale::Bahrain: if((countryName = QCoreApplication::translate("country", "Bahrain"))== "Bahrain") +countryName = "";break; case QLocale::Bangladesh: if((countryName = QCoreApplication::translate("country", +"Bangladesh"))== "Bangladesh") countryName = "";break; case QLocale::Barbados: if((countryName = +QCoreApplication::translate("country", "Barbados"))== "Barbados") countryName = "";break; case QLocale::Belarus: +if((countryName = QCoreApplication::translate("country", "Belarus"))== "Belarus") countryName = "";break; case +QLocale::Belgium: if((countryName = QCoreApplication::translate("country", "Belgium"))== "Belgium") countryName = +"";break; case QLocale::Belize: if((countryName = QCoreApplication::translate("country", "Belize"))== "Belize") +countryName = "";break; case QLocale::Benin: if((countryName = QCoreApplication::translate("country", "Benin"))== +"Benin") countryName = "";break; case QLocale::Bermuda: if((countryName = QCoreApplication::translate("country", +"Bermuda"))== "Bermuda") countryName = "";break; case QLocale::Bhutan: if((countryName = +QCoreApplication::translate("country", "Bhutan"))== "Bhutan") countryName = "";break; case QLocale::Bolivia: +if((countryName = QCoreApplication::translate("country", "Bolivia"))== "Bolivia") countryName = "";break; case +QLocale::BosniaAndHerzegowina: if((countryName = QCoreApplication::translate("country", "BosniaAndHerzegowina"))== +"BosniaAndHerzegowina") countryName = "";break; case QLocale::Botswana: if((countryName = +QCoreApplication::translate("country", "Botswana"))== "Botswana") countryName = "";break; case QLocale::Brazil: +if((countryName = QCoreApplication::translate("country", "Brazil"))== "Brazil") countryName = "";break; case +QLocale::Brunei: if((countryName = QCoreApplication::translate("country", "Brunei"))== "Brunei") countryName = "";break; + case QLocale::Bulgaria: if((countryName = QCoreApplication::translate("country", "Bulgaria"))== "Bulgaria") +countryName = "";break; case QLocale::BurkinaFaso: if((countryName = QCoreApplication::translate("country", +"BurkinaFaso"))== "BurkinaFaso") countryName = "";break; case QLocale::Burundi: if((countryName = +QCoreApplication::translate("country", "Burundi"))== "Burundi") countryName = "";break; case QLocale::Cambodia: +if((countryName = QCoreApplication::translate("country", "Cambodia"))== "Cambodia") countryName = "";break; case +QLocale::Cameroon: if((countryName = QCoreApplication::translate("country", "Cameroon"))== "Cameroon") countryName = +"";break; case QLocale::Canada: if((countryName = QCoreApplication::translate("country", "Canada"))== "Canada") +countryName = "";break; case QLocale::CapeVerde: if((countryName = QCoreApplication::translate("country", +"CapeVerde"))== "CapeVerde") countryName = "";break; case QLocale::CaymanIslands: if((countryName = +QCoreApplication::translate("country", "CaymanIslands"))== "CaymanIslands") countryName = "";break; case +QLocale::CentralAfricanRepublic: if((countryName = QCoreApplication::translate("country", "CentralAfricanRepublic"))== +"CentralAfricanRepublic") countryName = "";break; case QLocale::Chad: if((countryName = +QCoreApplication::translate("country", "Chad"))== "Chad") countryName = "";break; case QLocale::Chile: if((countryName = +QCoreApplication::translate("country", "Chile"))== "Chile") countryName = "";break; case QLocale::China: if((countryName += QCoreApplication::translate("country", "China"))== "China") countryName = "";break; case QLocale::Colombia: +if((countryName = QCoreApplication::translate("country", "Colombia"))== "Colombia") countryName = "";break; case +QLocale::Comoros: if((countryName = QCoreApplication::translate("country", "Comoros"))== "Comoros") countryName = +"";break; case QLocale::PeoplesRepublicOfCongo: if((countryName = QCoreApplication::translate("country", +"PeoplesRepublicOfCongo"))== "PeoplesRepublicOfCongo") countryName = "";break; case QLocale::DemocraticRepublicOfCongo: +if((countryName = QCoreApplication::translate("country", "DemocraticRepublicOfCongo"))== "DemocraticRepublicOfCongo") +countryName = "";break; case QLocale::CookIslands: if((countryName = QCoreApplication::translate("country", +"CookIslands"))== "CookIslands") countryName = "";break; case QLocale::CostaRica: if((countryName = +QCoreApplication::translate("country", "CostaRica"))== "CostaRica") countryName = "";break; case QLocale::IvoryCoast: +if((countryName = QCoreApplication::translate("country", "IvoryCoast"))== "IvoryCoast") countryName = "";break; case +QLocale::Croatia: if((countryName = QCoreApplication::translate("country", "Croatia"))== "Croatia") countryName = +"";break; case QLocale::Cuba: if((countryName = QCoreApplication::translate("country", "Cuba"))== "Cuba") countryName = +"";break; case QLocale::Cyprus: if((countryName = QCoreApplication::translate("country", "Cyprus"))== "Cyprus") +countryName = "";break; case QLocale::CzechRepublic: if((countryName = QCoreApplication::translate("country", +"CzechRepublic"))== "CzechRepublic") countryName = "";break; case QLocale::Denmark: if((countryName = +QCoreApplication::translate("country", "Denmark"))== "Denmark") countryName = "";break; case QLocale::Djibouti: +if((countryName = QCoreApplication::translate("country", "Djibouti"))== "Djibouti") countryName = "";break; case +QLocale::Dominica: if((countryName = QCoreApplication::translate("country", "Dominica"))== "Dominica") countryName = +"";break; case QLocale::DominicanRepublic: if((countryName = QCoreApplication::translate("country", +"DominicanRepublic"))== "DominicanRepublic") countryName = "";break; case QLocale::Ecuador: if((countryName = +QCoreApplication::translate("country", "Ecuador"))== "Ecuador") countryName = "";break; case QLocale::Egypt: +if((countryName = QCoreApplication::translate("country", "Egypt"))== "Egypt") countryName = "";break; case +QLocale::ElSalvador: if((countryName = QCoreApplication::translate("country", "ElSalvador"))== "ElSalvador") countryName += "";break; case QLocale::EquatorialGuinea: if((countryName = QCoreApplication::translate("country", +"EquatorialGuinea"))== "EquatorialGuinea") countryName = "";break; case QLocale::Eritrea: if((countryName = +QCoreApplication::translate("country", "Eritrea"))== "Eritrea") countryName = "";break; case QLocale::Estonia: +if((countryName = QCoreApplication::translate("country", "Estonia"))== "Estonia") countryName = "";break; case +QLocale::Ethiopia: if((countryName = QCoreApplication::translate("country", "Ethiopia"))== "Ethiopia") countryName = +"";break; case QLocale::FalklandIslands: if((countryName = QCoreApplication::translate("country", "FalklandIslands"))== +"FalklandIslands") countryName = "";break; case QLocale::FaroeIslands: if((countryName = +QCoreApplication::translate("country", "FaroeIslands"))== "FaroeIslands") countryName = "";break; case QLocale::Fiji: +if((countryName = QCoreApplication::translate("country", "Fiji"))== "Fiji") countryName = "";break; case +QLocale::Finland: if((countryName = QCoreApplication::translate("country", "Finland"))== "Finland") countryName = +"";break; case QLocale::France: if((countryName = QCoreApplication::translate("country", "France"))== "France") +countryName = "";break; case QLocale::FrenchGuiana: if((countryName = QCoreApplication::translate("country", +"FrenchGuiana"))== "FrenchGuiana") countryName = "";break; case QLocale::FrenchPolynesia: if((countryName = +QCoreApplication::translate("country", "FrenchPolynesia"))== "FrenchPolynesia") countryName = "";break; case +QLocale::Gabon: if((countryName = QCoreApplication::translate("country", "Gabon"))== "Gabon") countryName = "";break; + case QLocale::Gambia: if((countryName = QCoreApplication::translate("country", "Gambia"))== "Gambia") +countryName = "";break; case QLocale::Georgia: if((countryName = QCoreApplication::translate("country", "Georgia"))== +"Georgia") countryName = "";break; case QLocale::Germany: if((countryName = QCoreApplication::translate("country", +"Germany"))== "Germany") countryName = "";break; case QLocale::Ghana: if((countryName = +QCoreApplication::translate("country", "Ghana"))== "Ghana") countryName = "";break; case QLocale::Gibraltar: +if((countryName = QCoreApplication::translate("country", "Gibraltar"))== "Gibraltar") countryName = "";break; case +QLocale::Greece: if((countryName = QCoreApplication::translate("country", "Greece"))== "Greece") countryName = "";break; + case QLocale::Greenland: if((countryName = QCoreApplication::translate("country", "Greenland"))== "Greenland") +countryName = "";break; case QLocale::Grenada: if((countryName = QCoreApplication::translate("country", "Grenada"))== +"Grenada") countryName = "";break; case QLocale::Guadeloupe: if((countryName = QCoreApplication::translate("country", +"Guadeloupe"))== "Guadeloupe") countryName = "";break; case QLocale::Guam: if((countryName = +QCoreApplication::translate("country", "Guam"))== "Guam") countryName = "";break; case QLocale::Guatemala: +if((countryName = QCoreApplication::translate("country", "Guatemala"))== "Guatemala") countryName = "";break; case +QLocale::Guinea: if((countryName = QCoreApplication::translate("country", "Guinea"))== "Guinea") countryName = "";break; + case QLocale::GuineaBissau: if((countryName = QCoreApplication::translate("country", "GuineaBissau"))== +"GuineaBissau") countryName = "";break; case QLocale::Guyana: if((countryName = QCoreApplication::translate("country", +"Guyana"))== "Guyana") countryName = "";break; case QLocale::Haiti: if((countryName = +QCoreApplication::translate("country", "Haiti"))== "Haiti") countryName = "";break; case QLocale::Honduras: +if((countryName = QCoreApplication::translate("country", "Honduras"))== "Honduras") countryName = "";break; case +QLocale::HongKong: if((countryName = QCoreApplication::translate("country", "HongKong"))== "HongKong") countryName = +"";break; case QLocale::Hungary: if((countryName = QCoreApplication::translate("country", "Hungary"))== "Hungary") +countryName = "";break; case QLocale::Iceland: if((countryName = QCoreApplication::translate("country", "Iceland"))== +"Iceland") countryName = "";break; case QLocale::India: if((countryName = QCoreApplication::translate("country", +"India"))== "India") countryName = "";break; case QLocale::Indonesia: if((countryName = +QCoreApplication::translate("country", "Indonesia"))== "Indonesia") countryName = "";break; case QLocale::Iran: +if((countryName = QCoreApplication::translate("country", "Iran"))== "Iran") countryName = "";break; case QLocale::Iraq: +if((countryName = QCoreApplication::translate("country", "Iraq"))== "Iraq") countryName = "";break; case +QLocale::Ireland: if((countryName = QCoreApplication::translate("country", "Ireland"))== "Ireland") countryName = +"";break; case QLocale::Israel: if((countryName = QCoreApplication::translate("country", "Israel"))== "Israel") +countryName = "";break; case QLocale::Italy: if((countryName = QCoreApplication::translate("country", "Italy"))== +"Italy") countryName = "";break; case QLocale::Jamaica: if((countryName = QCoreApplication::translate("country", +"Jamaica"))== "Jamaica") countryName = "";break; case QLocale::Japan: if((countryName = +QCoreApplication::translate("country", "Japan"))== "Japan") countryName = "";break; case QLocale::Jordan: +if((countryName = QCoreApplication::translate("country", "Jordan"))== "Jordan") countryName = "";break; case +QLocale::Kazakhstan: if((countryName = QCoreApplication::translate("country", "Kazakhstan"))== "Kazakhstan") countryName += "";break; case QLocale::Kenya: if((countryName = QCoreApplication::translate("country", "Kenya"))== "Kenya") +countryName = "";break; case QLocale::Kiribati: if((countryName = QCoreApplication::translate("country", "Kiribati"))== +"Kiribati") countryName = "";break; case QLocale::DemocraticRepublicOfKorea: if((countryName = +QCoreApplication::translate("country", "DemocraticRepublicOfKorea"))== "DemocraticRepublicOfKorea") countryName = +"";break; case QLocale::RepublicOfKorea: if((countryName = QCoreApplication::translate("country", "RepublicOfKorea"))== +"RepublicOfKorea") countryName = "";break; case QLocale::Kuwait: if((countryName = +QCoreApplication::translate("country", "Kuwait"))== "Kuwait") countryName = "";break; case QLocale::Kyrgyzstan: +if((countryName = QCoreApplication::translate("country", "Kyrgyzstan"))== "Kyrgyzstan") countryName = "";break; case +QLocale::Laos: if((countryName = QCoreApplication::translate("country", "Laos"))== "Laos") countryName = "";break; case +QLocale::Latvia: if((countryName = QCoreApplication::translate("country", "Latvia"))== "Latvia") countryName = "";break; + case QLocale::Lebanon: if((countryName = QCoreApplication::translate("country", "Lebanon"))== "Lebanon") +countryName = "";break; case QLocale::Lesotho: if((countryName = QCoreApplication::translate("country", "Lesotho"))== +"Lesotho") countryName = "";break; case QLocale::Liberia: if((countryName = QCoreApplication::translate("country", +"Liberia"))== "Liberia") countryName = "";break; case QLocale::Libya: if((countryName = +QCoreApplication::translate("country", "Libya"))== "Libya") countryName = "";break; case QLocale::Liechtenstein: +if((countryName = QCoreApplication::translate("country", "Liechtenstein"))== "Liechtenstein") countryName = "";break; + case QLocale::Lithuania: if((countryName = QCoreApplication::translate("country", "Lithuania"))== "Lithuania") +countryName = "";break; case QLocale::Luxembourg: if((countryName = QCoreApplication::translate("country", +"Luxembourg"))== "Luxembourg") countryName = "";break; case QLocale::Macau: if((countryName = +QCoreApplication::translate("country", "Macau"))== "Macau") countryName = "";break; case QLocale::Macedonia: +if((countryName = QCoreApplication::translate("country", "Macedonia"))== "Macedonia") countryName = "";break; case +QLocale::Madagascar: if((countryName = QCoreApplication::translate("country", "Madagascar"))== "Madagascar") countryName += "";break; case QLocale::Malawi: if((countryName = QCoreApplication::translate("country", "Malawi"))== "Malawi") +countryName = "";break; case QLocale::Malaysia: if((countryName = QCoreApplication::translate("country", "Malaysia"))== +"Malaysia") countryName = "";break; case QLocale::Maldives: if((countryName = QCoreApplication::translate("country", +"Maldives"))== "Maldives") countryName = "";break; case QLocale::Mali: if((countryName = +QCoreApplication::translate("country", "Mali"))== "Mali") countryName = "";break; case QLocale::Malta: if((countryName = +QCoreApplication::translate("country", "Malta"))== "Malta") countryName = "";break; case QLocale::MarshallIslands: +if((countryName = QCoreApplication::translate("country", "MarshallIslands"))== "MarshallIslands") countryName = +"";break; case QLocale::Martinique: if((countryName = QCoreApplication::translate("country", "Martinique"))== +"Martinique") countryName = "";break; case QLocale::Mauritania: if((countryName = QCoreApplication::translate("country", +"Mauritania"))== "Mauritania") countryName = "";break; case QLocale::Mauritius: if((countryName = +QCoreApplication::translate("country", "Mauritius"))== "Mauritius") countryName = "";break; case QLocale::Mayotte: +if((countryName = QCoreApplication::translate("country", "Mayotte"))== "Mayotte") countryName = "";break; case +QLocale::Mexico: if((countryName = QCoreApplication::translate("country", "Mexico"))== "Mexico") countryName = "";break; + case QLocale::Micronesia: if((countryName = QCoreApplication::translate("country", "Micronesia"))== +"Micronesia") countryName = "";break; case QLocale::Moldova: if((countryName = QCoreApplication::translate("country", +"Moldova"))== "Moldova") countryName = "";break; case QLocale::Monaco: if((countryName = +QCoreApplication::translate("country", "Monaco"))== "Monaco") countryName = "";break; case QLocale::Mongolia: +if((countryName = QCoreApplication::translate("country", "Mongolia"))== "Mongolia") countryName = "";break; case +QLocale::Montenegro: if((countryName = QCoreApplication::translate("country", "Montenegro"))== "Montenegro") countryName += "";break; case QLocale::Montserrat: if((countryName = QCoreApplication::translate("country", "Montserrat"))== +"Montserrat") countryName = "";break; case QLocale::Morocco: if((countryName = QCoreApplication::translate("country", +"Morocco"))== "Morocco") countryName = "";break; case QLocale::Mozambique: if((countryName = +QCoreApplication::translate("country", "Mozambique"))== "Mozambique") countryName = "";break; case QLocale::Myanmar: +if((countryName = QCoreApplication::translate("country", "Myanmar"))== "Myanmar") countryName = "";break; case +QLocale::Namibia: if((countryName = QCoreApplication::translate("country", "Namibia"))== "Namibia") countryName = +"";break; case QLocale::NauruCountry: if((countryName = QCoreApplication::translate("country", "NauruCountry"))== +"NauruCountry") countryName = "";break; case QLocale::Nepal: if((countryName = QCoreApplication::translate("country", +"Nepal"))== "Nepal") countryName = "";break; case QLocale::Netherlands: if((countryName = +QCoreApplication::translate("country", "Netherlands"))== "Netherlands") countryName = "";break; case +QLocale::NewCaledonia: if((countryName = QCoreApplication::translate("country", "NewCaledonia"))== "NewCaledonia") +countryName = "";break; case QLocale::NewZealand: if((countryName = QCoreApplication::translate("country", +"NewZealand"))== "NewZealand") countryName = "";break; case QLocale::Nicaragua: if((countryName = +QCoreApplication::translate("country", "Nicaragua"))== "Nicaragua") countryName = "";break; case QLocale::Niger: +if((countryName = QCoreApplication::translate("country", "Niger"))== "Niger") countryName = "";break; case +QLocale::Nigeria: if((countryName = QCoreApplication::translate("country", "Nigeria"))== "Nigeria") countryName = +"";break; case QLocale::Niue: if((countryName = QCoreApplication::translate("country", "Niue"))== "Niue") countryName = +"";break; case QLocale::NorfolkIsland: if((countryName = QCoreApplication::translate("country", "NorfolkIsland"))== +"NorfolkIsland") countryName = "";break; case QLocale::NorthernMarianaIslands: if((countryName = +QCoreApplication::translate("country", "NorthernMarianaIslands"))== "NorthernMarianaIslands") countryName = "";break; + case QLocale::Norway: if((countryName = QCoreApplication::translate("country", "Norway"))== "Norway") +countryName = "";break; case QLocale::Oman: if((countryName = QCoreApplication::translate("country", "Oman"))== "Oman") +countryName = "";break; case QLocale::Pakistan: if((countryName = QCoreApplication::translate("country", "Pakistan"))== +"Pakistan") countryName = "";break; case QLocale::Palau: if((countryName = QCoreApplication::translate("country", +"Palau"))== "Palau") countryName = "";break; case QLocale::PalestinianTerritories: if((countryName = +QCoreApplication::translate("country", "PalestinianTerritories"))== "PalestinianTerritories") countryName = "";break; + case QLocale::Panama: if((countryName = QCoreApplication::translate("country", "Panama"))== "Panama") +countryName = "";break; case QLocale::PapuaNewGuinea: if((countryName = QCoreApplication::translate("country", +"PapuaNewGuinea"))== "PapuaNewGuinea") countryName = "";break; case QLocale::Paraguay: if((countryName = +QCoreApplication::translate("country", "Paraguay"))== "Paraguay") countryName = "";break; case QLocale::Peru: +if((countryName = QCoreApplication::translate("country", "Peru"))== "Peru") countryName = "";break; case +QLocale::Philippines: if((countryName = QCoreApplication::translate("country", "Philippines"))== "Philippines") +countryName = "";break; case QLocale::Poland: if((countryName = QCoreApplication::translate("country", "Poland"))== +"Poland") countryName = "";break; case QLocale::Portugal: if((countryName = QCoreApplication::translate("country", +"Portugal"))== "Portugal") countryName = "";break; case QLocale::PuertoRico: if((countryName = +QCoreApplication::translate("country", "PuertoRico"))== "PuertoRico") countryName = "";break; case QLocale::Qatar: +if((countryName = QCoreApplication::translate("country", "Qatar"))== "Qatar") countryName = "";break; case +QLocale::Reunion: if((countryName = QCoreApplication::translate("country", "Reunion"))== "Reunion") countryName = +"";break; case QLocale::Romania: if((countryName = QCoreApplication::translate("country", "Romania"))== "Romania") +countryName = "";break; case QLocale::RussianFederation: if((countryName = QCoreApplication::translate("country", +"RussianFederation"))== "RussianFederation") countryName = "";break; case QLocale::Rwanda: if((countryName = +QCoreApplication::translate("country", "Rwanda"))== "Rwanda") countryName = "";break; case QLocale::SaintHelena: +if((countryName = QCoreApplication::translate("country", "SaintHelena"))== "SaintHelena") countryName = "";break; case +QLocale::SaintKittsAndNevis: if((countryName = QCoreApplication::translate("country", "SaintKittsAndNevis"))== +"SaintKittsAndNevis") countryName = "";break; case QLocale::SaintLucia: if((countryName = +QCoreApplication::translate("country", "SaintLucia"))== "SaintLucia") countryName = "";break; case +QLocale::SaintPierreAndMiquelon: if((countryName = QCoreApplication::translate("country", "SaintPierreAndMiquelon"))== +"SaintPierreAndMiquelon") countryName = "";break; case QLocale::SaintVincentAndTheGrenadines: if((countryName = +QCoreApplication::translate("country", "SaintVincentAndTheGrenadines"))== "SaintVincentAndTheGrenadines") countryName = +"";break; case QLocale::Samoa: if((countryName = QCoreApplication::translate("country", "Samoa"))== "Samoa") countryName += "";break; case QLocale::SanMarino: if((countryName = QCoreApplication::translate("country", "SanMarino"))== +"SanMarino") countryName = "";break; case QLocale::SaoTomeAndPrincipe: if((countryName = +QCoreApplication::translate("country", "SaoTomeAndPrincipe"))== "SaoTomeAndPrincipe") countryName = "";break; case +QLocale::SaudiArabia: if((countryName = QCoreApplication::translate("country", "SaudiArabia"))== "SaudiArabia") +countryName = "";break; case QLocale::Senegal: if((countryName = QCoreApplication::translate("country", "Senegal"))== +"Senegal") countryName = "";break; case QLocale::Serbia: if((countryName = QCoreApplication::translate("country", +"Serbia"))== "Serbia") countryName = "";break; case QLocale::Seychelles: if((countryName = +QCoreApplication::translate("country", "Seychelles"))== "Seychelles") countryName = "";break; case QLocale::SierraLeone: +if((countryName = QCoreApplication::translate("country", "SierraLeone"))== "SierraLeone") countryName = "";break; case +QLocale::Singapore: if((countryName = QCoreApplication::translate("country", "Singapore"))== "Singapore") countryName = +"";break; case QLocale::Slovakia: if((countryName = QCoreApplication::translate("country", "Slovakia"))== "Slovakia") +countryName = "";break; case QLocale::Slovenia: if((countryName = QCoreApplication::translate("country", "Slovenia"))== +"Slovenia") countryName = "";break; case QLocale::SolomonIslands: if((countryName = +QCoreApplication::translate("country", "SolomonIslands"))== "SolomonIslands") countryName = "";break; case +QLocale::Somalia: if((countryName = QCoreApplication::translate("country", "Somalia"))== "Somalia") countryName = +"";break; case QLocale::SouthAfrica: if((countryName = QCoreApplication::translate("country", "SouthAfrica"))== +"SouthAfrica") countryName = "";break; case QLocale::Spain: if((countryName = QCoreApplication::translate("country", +"Spain"))== "Spain") countryName = "";break; case QLocale::SriLanka: if((countryName = +QCoreApplication::translate("country", "SriLanka"))== "SriLanka") countryName = "";break; case QLocale::Sudan: +if((countryName = QCoreApplication::translate("country", "Sudan"))== "Sudan") countryName = "";break; case +QLocale::Suriname: if((countryName = QCoreApplication::translate("country", "Suriname"))== "Suriname") countryName = +"";break; case QLocale::Swaziland: if((countryName = QCoreApplication::translate("country", "Swaziland"))== "Swaziland") +countryName = "";break; case QLocale::Sweden: if((countryName = QCoreApplication::translate("country", "Sweden"))== +"Sweden") countryName = "";break; case QLocale::Switzerland: if((countryName = QCoreApplication::translate("country", +"Switzerland"))== "Switzerland") countryName = "";break; case QLocale::Syria: if((countryName = +QCoreApplication::translate("country", "Syria"))== "Syria") countryName = "";break; case QLocale::Taiwan: +if((countryName = QCoreApplication::translate("country", "Taiwan"))== "Taiwan") countryName = "";break; case +QLocale::Tajikistan: if((countryName = QCoreApplication::translate("country", "Tajikistan"))== "Tajikistan") countryName += "";break; case QLocale::Tanzania: if((countryName = QCoreApplication::translate("country", "Tanzania"))== "Tanzania") +countryName = "";break; case QLocale::Thailand: if((countryName = QCoreApplication::translate("country", "Thailand"))== +"Thailand") countryName = "";break; case QLocale::Togo: if((countryName = QCoreApplication::translate("country", +"Togo"))== "Togo") countryName = "";break; case QLocale::Tokelau: if((countryName = +QCoreApplication::translate("country", "Tokelau"))== "Tokelau") countryName = "";break; case QLocale::Tonga: +if((countryName = QCoreApplication::translate("country", "Tonga"))== "Tonga") countryName = "";break; case +QLocale::TrinidadAndTobago: if((countryName = QCoreApplication::translate("country", "TrinidadAndTobago"))== +"TrinidadAndTobago") countryName = "";break; case QLocale::Tunisia: if((countryName = +QCoreApplication::translate("country", "Tunisia"))== "Tunisia") countryName = "";break; case QLocale::Turkey: +if((countryName = QCoreApplication::translate("country", "Turkey"))== "Turkey") countryName = "";break; case +QLocale::Turkmenistan: if((countryName = QCoreApplication::translate("country", "Turkmenistan"))== "Turkmenistan") +countryName = "";break; case QLocale::TurksAndCaicosIslands: if((countryName = QCoreApplication::translate("country", +"TurksAndCaicosIslands"))== "TurksAndCaicosIslands") countryName = "";break; case QLocale::Tuvalu: if((countryName = +QCoreApplication::translate("country", "Tuvalu"))== "Tuvalu") countryName = "";break; case QLocale::Uganda: +if((countryName = QCoreApplication::translate("country", "Uganda"))== "Uganda") countryName = "";break; case +QLocale::Ukraine: if((countryName = QCoreApplication::translate("country", "Ukraine"))== "Ukraine") countryName = +"";break; case QLocale::UnitedArabEmirates: if((countryName = QCoreApplication::translate("country", +"UnitedArabEmirates"))== "UnitedArabEmirates") countryName = "";break; case QLocale::UnitedKingdom: if((countryName = +QCoreApplication::translate("country", "UnitedKingdom"))== "UnitedKingdom") countryName = "";break; case +QLocale::UnitedStates: if((countryName = QCoreApplication::translate("country", "UnitedStates"))== "UnitedStates") +countryName = "";break; case QLocale::Uruguay: if((countryName = QCoreApplication::translate("country", "Uruguay"))== +"Uruguay") countryName = "";break; case QLocale::Uzbekistan: if((countryName = QCoreApplication::translate("country", +"Uzbekistan"))== "Uzbekistan") countryName = "";break; case QLocale::Vanuatu: if((countryName = +QCoreApplication::translate("country", "Vanuatu"))== "Vanuatu") countryName = "";break; case QLocale::Venezuela: +if((countryName = QCoreApplication::translate("country", "Venezuela"))== "Venezuela") countryName = "";break; case +QLocale::Vietnam: if((countryName = QCoreApplication::translate("country", "Vietnam"))== "Vietnam") countryName = +"";break; case QLocale::WallisAndFutunaIslands: if((countryName = QCoreApplication::translate("country", +"WallisAndFutunaIslands"))== "WallisAndFutunaIslands") countryName = "";break; case QLocale::Yemen: if((countryName = +QCoreApplication::translate("country", "Yemen"))== "Yemen") countryName = "";break; case QLocale::Zambia: +if((countryName = QCoreApplication::translate("country", "Zambia"))== "Zambia") countryName = "";break; case +QLocale::Zimbabwe: if((countryName = QCoreApplication::translate("country", "Zimbabwe"))== "Zimbabwe") countryName = +"";break; default: { countryName = QLocale::countryToString(p_country); + } + } + if( countryName == "") + countryName = QLocale::countryToString(p_country); + return countryName; } // Copy a folder recursively without erasing old file void Utils::copyDir(QString from, QString to) { - QDir dir; - dir.setPath(from); - from += QDir::separator(); - to += QDir::separator(); - foreach (QString copyFile, dir.entryList(QDir::Files)) {// Copy each files - QString toFile = to + copyFile; - if (!QFile::exists(toFile)) - QFile::copy(from+copyFile, toFile); - } - foreach (QString nextDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {// Copy folder - QString toDir = to + nextDir; - QDir().mkpath(toDir);// no need to check if dir exists - copyDir(from + nextDir, toDir);//Go up - } + QDir dir; + dir.setPath(from); + from += QDir::separator(); + to += QDir::separator(); + foreach (QString copyFile, dir.entryList(QDir::Files)) {// Copy each files + QString toFile = to + copyFile; + if (!QFile::exists(toFile)) + QFile::copy(from+copyFile, toFile); + } + foreach (QString nextDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {// Copy folder + QString toDir = to + nextDir; + QDir().mkpath(toDir);// no need to check if dir exists + copyDir(from + nextDir, toDir);//Go up + } } QString Utils::getDisplayName(const std::shared_ptr& address){ - QString displayName; - if(address){ - displayName = CoreManager::getInstance()->getSipAddressesModel()->getDisplayName(address); - } - return displayName; + QString displayName; + if(address){ + displayName = CoreManager::getInstance()->getSipAddressesModel()->getDisplayName(address); + } + return displayName; } std::shared_ptr Utils::getConfigIfExists (const QString &configPath) { - std::string factoryPath(Paths::getFactoryConfigFilePath()); - if (!Paths::filePathExists(factoryPath)) - factoryPath.clear(); - - return linphone::Config::newWithFactory(configPath.toStdString(), factoryPath); + std::string factoryPath(Paths::getFactoryConfigFilePath()); + if (!Paths::filePathExists(factoryPath)) + factoryPath.clear(); + + return linphone::Config::newWithFactory(configPath.toStdString(), factoryPath); } QString Utils::getApplicationProduct(){ // Note: Keep '-' as a separator between application name and application type - return QString(APPLICATION_NAME"-Desktop").remove(' ')+"/"+QCoreApplication::applicationVersion(); + return QString(APPLICATION_NAME"-Desktop").remove(' ')+"/"+QCoreApplication::applicationVersion(); } QString Utils::getOsProduct(){ - QString version = QSysInfo::productVersion().remove(' ');// A version can be "Server 2016" (for Windows Server 2016) - QString product = QSysInfo::productType().replace(' ', '-'); // Just in case - return product+"/"+version; + QString version = QSysInfo::productVersion().remove(' ');// A version can be "Server 2016" (for Windows Server 2016) + QString product = QSysInfo::productType().replace(' ', '-'); // Just in case + return product+"/"+version; } QString Utils::computeUserAgent(const std::shared_ptr& config){ - return QStringLiteral("%1 (%2) %3 Qt/%4 LinphoneSDK") - .arg(Utils::getApplicationProduct()) - .arg(SettingsModel::getDeviceName(config) - .replace('\\', "\\\\") - .replace('(', "\\(") - .replace(')', "\\)") - ) - .arg(Utils::getOsProduct()) - .arg(qVersion()); + return QStringLiteral("%1 (%2) %3 Qt/%4 LinphoneSDK") + .arg(Utils::getApplicationProduct()) + .arg(SettingsModel::getDeviceName(config) + .replace('\\', "\\\\") + .replace('(', "\\(") + .replace(')', "\\)") + ) + .arg(Utils::getOsProduct()) + .arg(qVersion()); } bool Utils::isMe(const QString& address){ - return !address.isEmpty() ? CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress()->weakEqual(Utils::interpretUrl(address)) : false; + return !address.isEmpty() ? +CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress()->weakEqual(Utils::interpretUrl(address)) : +false; } bool Utils::isMe(const std::shared_ptr& address){ - return address ? CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress()->weakEqual(address) : false; + return address ? CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress()->weakEqual(address) : +false; } bool Utils::isAnimatedImage(const QString& path){ - if(path.isEmpty()) return false; - QFileInfo info(path); - if( !info.exists() || !QMimeDatabase().mimeTypeForFile(info).name().contains("image/")) - return false; - QImageReader reader(path); - return reader.canRead() && reader.supportsAnimation() && reader.imageCount() > 1; + if(path.isEmpty()) return false; + QFileInfo info(path); + if( !info.exists() || !QMimeDatabase().mimeTypeForFile(info).name().contains("image/")) + return false; + QImageReader reader(path); + return reader.canRead() && reader.supportsAnimation() && reader.imageCount() > 1; } bool Utils::isImage(const QString& path){ - if(path.isEmpty()) return false; - QFileInfo info(path); - if( !info.exists() || CoreManager::getInstance()->getSettingsModel()->getVfsEncrypted()){ - return QMimeDatabase().mimeTypeForFile(info, QMimeDatabase::MatchExtension).name().contains("image/"); - }else if(!QMimeDatabase().mimeTypeForFile(info).name().contains("image/")) - return false; - QImageReader reader(path); - return reader.canRead() && reader.imageCount() == 1; + if(path.isEmpty()) return false; + QFileInfo info(path); + if( !info.exists() || CoreManager::getInstance()->getSettingsModel()->getVfsEncrypted()){ + return QMimeDatabase().mimeTypeForFile(info, QMimeDatabase::MatchExtension).name().contains("image/"); + }else if(!QMimeDatabase().mimeTypeForFile(info).name().contains("image/")) + return false; + QImageReader reader(path); + return reader.canRead() && reader.imageCount() == 1; } bool Utils::isVideo(const QString& path){ - if(path.isEmpty()) return false; - return QMimeDatabase().mimeTypeForFile(path).name().contains("video/"); + if(path.isEmpty()) return false; + return QMimeDatabase().mimeTypeForFile(path).name().contains("video/"); } bool Utils::isPdf(const QString& path){ - if(path.isEmpty()) return false; - return QMimeDatabase().mimeTypeForFile(path).name().contains("application/pdf"); + if(path.isEmpty()) return false; + return QMimeDatabase().mimeTypeForFile(path).name().contains("application/pdf"); } bool Utils::isSupportedForDisplay(const QString& path){ - if(path.isEmpty()) return false; - return !QMimeDatabase().mimeTypeForFile(path).name().contains("application");// "for pdf : "application/pdf". Note : Make an exception when supported. + if(path.isEmpty()) return false; + return !QMimeDatabase().mimeTypeForFile(path).name().contains("application");// "for pdf : "application/pdf". Note : +Make an exception when supported. } bool Utils::canHaveThumbnail(const QString& path){ - if(path.isEmpty()) return false; - return isImage(path) || isAnimatedImage(path) || isPdf(path) || isVideo(path); + if(path.isEmpty()) return false; + return isImage(path) || isAnimatedImage(path) || isPdf(path) || isVideo(path); } bool Utils::isPhoneNumber(const QString& txt){ - auto core = CoreManager::getInstance()->getCore(); - if(!core) - return false; - auto account = core->getDefaultAccount(); - return account && account->isPhoneNumber(Utils::appStringToCoreString(txt)); + auto core = CoreManager::getInstance()->getCore(); + if(!core) + return false; + auto account = core->getDefaultAccount(); + return account && account->isPhoneNumber(Utils::appStringToCoreString(txt)); } bool Utils::isUsername(const QString& txt){ - QRegularExpression regex("^(?$"); - QRegularExpressionMatch match = regex.match(txt); - return match.hasMatch(); // true + QRegularExpression regex("^(?$"); + QRegularExpressionMatch match = regex.match(txt); + return match.hasMatch(); // true } bool Utils::isValidUrl(const QString& url){ - return QUrl(url).isValid(); + return QUrl(url).isValid(); } QSize Utils::getImageSize(const QString& url){ - QString path; - QUrl urlDecode(url); - if(urlDecode.isLocalFile()) - path = QDir::toNativeSeparators(urlDecode.toLocalFile()); - else - path = url; - QFileInfo info(path); - if( !info.exists()) - return QSize(0,0); - QImageReader reader(path); - QSize s = reader.size(); - if( s.isValid()) - return s; - else - return QSize(0,0); + QString path; + QUrl urlDecode(url); + if(urlDecode.isLocalFile()) + path = QDir::toNativeSeparators(urlDecode.toLocalFile()); + else + path = url; + QFileInfo info(path); + if( !info.exists()) + return QSize(0,0); + QImageReader reader(path); + QSize s = reader.size(); + if( s.isValid()) + return s; + else + return QSize(0,0); } QPoint Utils::getCursorPosition(){ - return QCursor::pos(); + return QCursor::pos(); } QString Utils::getFileChecksum(const QString& filePath){ @@ -775,161 +822,161 @@ bool Utils::codepointIsEmoji(uint code){ } bool Utils::codepointIsVisible(uint code) { - return code > 0x00020; + return code > 0x00020; } QString Utils::encodeEmojiToQmlRichFormat(const QString &body){ - QString fmtBody = ""; - QVector utf32_string = body.toUcs4(); - - bool insideFontBlock = false; - for (auto &code : utf32_string) { - if (Utils::codepointIsEmoji(code)) { - if (!insideFontBlock) { - fmtBody += QString("getSettingsModel()->getEmojiFont().family() + "\">"); - insideFontBlock = true; - } - } else { - if (insideFontBlock) { - fmtBody += ""; - insideFontBlock = false; - } - } - fmtBody += QString::fromUcs4(&code, 1); - } - if (insideFontBlock) { - fmtBody += ""; - } - return fmtBody; + QString fmtBody = ""; + QVector utf32_string = body.toUcs4(); + + bool insideFontBlock = false; + for (auto &code : utf32_string) { + if (Utils::codepointIsEmoji(code)) { + if (!insideFontBlock) { + fmtBody += QString("getSettingsModel()->getEmojiFont().family() + "\">"); + insideFontBlock = true; + } + } else { + if (insideFontBlock) { + fmtBody += ""; + insideFontBlock = false; + } + } + fmtBody += QString::fromUcs4(&code, 1); + } + if (insideFontBlock) { + fmtBody += ""; + } + return fmtBody; } bool Utils::isOnlyEmojis(const QString& text){ - if(text.isEmpty()) return false; - QVector utf32_string = text.toUcs4(); - for (auto &code : utf32_string) - if(codepointIsVisible(code) && !Utils::codepointIsEmoji(code)) - return false; - return true; + if(text.isEmpty()) return false; + QVector utf32_string = text.toUcs4(); + for (auto &code : utf32_string) + if(codepointIsVisible(code) && !Utils::codepointIsEmoji(code)) + return false; + return true; } QString Utils::encodeTextToQmlRichFormat(const QString& text, const QVariantMap& options){ - //QString images; - //QStringList imageFormat; - //for(auto format : QImageReader::supportedImageFormats()) + //QString images; + //QStringList imageFormat; + //for(auto format : QImageReader::supportedImageFormats()) // imageFormat.append(QString::fromLatin1(format).toUpper()); - - QStringList formattedText; - bool lastWasUrl = false; - - if(options.contains("noLink") && options["noLink"].toBool()){ - formattedText.append(encodeEmojiToQmlRichFormat(text)); - }else{ - auto primaryColor = App::getInstance()->getColorListModel()->getColor("i")->getColor(); - auto iriParsed = UriTools::parseIri(text); - - for(int i = 0 ; i < iriParsed.size() ; ++i){ - QString iri = iriParsed[i].second.replace('&', "&") - .replace('<', "\u2063<") - .replace('>', "\u2063>") - .replace('"', """) - .replace('\'', "'"); - if(!iriParsed[i].first){ - if(lastWasUrl){ - lastWasUrl = false; - if(iri.front() != ' ') - iri.push_front(' '); - } - formattedText.append(encodeEmojiToQmlRichFormat(iri)); - }else{ - QString uri = iriParsed[i].second.left(3) == "www" ? "http://"+iriParsed[i].second : iriParsed[i].second ; - /* TODO : preview from link - //int extIndex = iriParsed[i].second.lastIndexOf('.'); - //QString ext; - //if( extIndex >= 0) - // ext = iriParsed[i].second.mid(extIndex+1).toUpper(); - //if(imageFormat.contains(ext.toLatin1())){// imagesHeight is not used because of bugs on display (blank image if set without width) - // images += ""+uri+""; - //}else{ - formattedText.append( "" + iri + ""); - lastWasUrl = true; - //} - } - } - } - if(lastWasUrl && formattedText.last().back() != ' '){ - formattedText.push_back(" "); - } - return "

" + formattedText.join("") + "

"; + + QStringList formattedText; + bool lastWasUrl = false; + + if(options.contains("noLink") && options["noLink"].toBool()){ + formattedText.append(encodeEmojiToQmlRichFormat(text)); + }else{ + auto primaryColor = App::getInstance()->getColorListModel()->getColor("i")->getColor(); + auto iriParsed = UriTools::parseIri(text); + + for(int i = 0 ; i < iriParsed.size() ; ++i){ + QString iri = iriParsed[i].second.replace('&', "&") + .replace('<', "\u2063<") + .replace('>', "\u2063>") + .replace('"', """) + .replace('\'', "'"); + if(!iriParsed[i].first){ + if(lastWasUrl){ + lastWasUrl = false; + if(iri.front() != ' ') + iri.push_front(' '); + } + formattedText.append(encodeEmojiToQmlRichFormat(iri)); + }else{ + QString uri = iriParsed[i].second.left(3) == "www" ? "http://"+iriParsed[i].second : iriParsed[i].second +; + /* TODO : preview from link + //int extIndex = iriParsed[i].second.lastIndexOf('.'); + //QString ext; + //if( extIndex >= 0) + // ext = iriParsed[i].second.mid(extIndex+1).toUpper(); + //if(imageFormat.contains(ext.toLatin1())){// imagesHeight is not used because of bugs on display (blank +image if set without width) + // images += ""+uri+""; + //}else{ + formattedText.append( "" + iri + +""); lastWasUrl = true; + //} + } + } + } + if(lastWasUrl && formattedText.last().back() != ' '){ + formattedText.push_back(" "); + } + return "

" + formattedText.join("") + "

"; } QString Utils::getFileContent(const QString& filePath){ - QString contents; - QFile file(filePath); - if (!file.open(QFile::ReadOnly | QFile::Text)) - return ""; - return file.readAll(); + QString contents; + QFile file(filePath); + if (!file.open(QFile::ReadOnly | QFile::Text)) + return ""; + return file.readAll(); } static QStringList gDbPaths; void Utils::deleteAllUserData(){ // Store usable data like custom folders - gDbPaths.clear(); - gDbPaths.append(Utils::coreStringToAppString(linphone::Factory::get()->getDataDir(nullptr))); - gDbPaths.append(Utils::coreStringToAppString(linphone::Factory::get()->getConfigDir(nullptr))); + gDbPaths.clear(); + gDbPaths.append(Utils::coreStringToAppString(linphone::Factory::get()->getDataDir(nullptr))); + gDbPaths.append(Utils::coreStringToAppString(linphone::Factory::get()->getConfigDir(nullptr))); // Exit with a delete code - App::getInstance()->exit(App::DeleteDataCode); + App::getInstance()->exit(App::DeleteDataCode); } void Utils::deleteAllUserDataOffline(){ - qWarning() << "Deleting all data! "; - for(int i = 0 ; i < gDbPaths.size() ; ++i){ - QDir dir(gDbPaths[i]); - qWarning() << "Deleting " << gDbPaths[i] << " : " << (dir.removeRecursively() ? "Successfully" : "Failed"); - } + qWarning() << "Deleting all data! "; + for(int i = 0 ; i < gDbPaths.size() ; ++i){ + QDir dir(gDbPaths[i]); + qWarning() << "Deleting " << gDbPaths[i] << " : " << (dir.removeRecursively() ? "Successfully" : "Failed"); + } } //------------------------------------------------------------------------------------------------------- // WIDGETS //------------------------------------------------------------------------------------------------------- -bool Utils::openWithPdfViewer(ContentModel * contentModel, const QString& filePath, const int& width, const int& height) { -#ifdef PDF_ENABLED - PdfWidget *view = new PdfWidget(contentModel); - view->setMinimumSize(QSize(width, height)); - view->show(); - view->open(filePath); - return true; +bool Utils::openWithPdfViewer(ContentModel * contentModel, const QString& filePath, const int& width, const int& height) +{ #ifdef PDF_ENABLED PdfWidget *view = new PdfWidget(contentModel); view->setMinimumSize(QSize(width, height)); + view->show(); + view->open(filePath); + return true; #else - return false; + return false; #endif } void Utils::setFamilyFont(QAction * dest, const QString& family){ - QFont font(dest->font()); - font.setFamily(family); - dest->setFont(font); + QFont font(dest->font()); + font.setFamily(family); + dest->setFont(font); } void Utils::setFamilyFont(QWidget * dest, const QString& family){ - QFont font(dest->font()); - font.setFamily(family); - dest->setFont(font); + QFont font(dest->font()); + font.setFamily(family); + dest->setFont(font); } QPixmap Utils::getMaskedPixmap(const QString& name, const QColor& color){ - QSize size; - QPixmap img = ImageProvider::computePixmap(name, &size); - QPixmap pxr( img.size() ); - pxr.fill( color ); - pxr.setMask( img.createMaskFromColor( Qt::transparent ) ); - return pxr; + QSize size; + QPixmap img = ImageProvider::computePixmap(name, &size); + QPixmap pxr( img.size() ); + pxr.fill( color ); + pxr.setMask( img.createMaskFromColor( Qt::transparent ) ); + return pxr; } */ diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 1e59055c4..f246ae325 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -21,11 +21,11 @@ #ifndef UTILS_H_ #define UTILS_H_ +#include +#include +#include #include #include -#include -#include -#include #include "Constants.hpp" @@ -49,84 +49,86 @@ class DateModel; class ContentModel; -class Utils : public QObject{ +class Utils : public QObject { Q_OBJECT public: - Utils(QObject * parent = nullptr) : QObject(parent){} -/* - typedef enum{ - SIP_DISPLAY_USERNAME = 0, - SIP_DISPLAY_ALL = -1 - }SipDisplayMode; - Q_ENUM(SipDisplayMode) - - // Qt interfaces - Q_INVOKABLE static bool hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability, bool defaultCapability = true); -// ***** DATE TIME - Q_INVOKABLE static QDateTime addMinutes(QDateTime date, const int& min); - static QDateTime getOffsettedUTC(const QDateTime& date); - Q_INVOKABLE static QString toDateTimeString(QDateTime date, const QString& format = "yyyy/MM/dd hh:mm:ss"); - Q_INVOKABLE static QString toTimeString(QDateTime date, const QString& format = "hh:mm:ss"); - Q_INVOKABLE static QString toDateString(QDateTime date, const QString& format = ""); - Q_INVOKABLE static QString toDateString(QDate date, const QString& format = ""); - Q_INVOKABLE static QString toDisplayString(const QString& str, SipDisplayMode displayMode = SIP_DISPLAY_ALL); - Q_INVOKABLE static QDate getCurrentDate(); - Q_INVOKABLE static DateModel* getCurrentDateModel(); - Q_INVOKABLE static QDate getMinDate(); - Q_INVOKABLE static DateModel* getMinDateModel(); - Q_INVOKABLE static QDate toDate(const QString& str, const QString& format = "yyyy/MM/dd"); - Q_INVOKABLE static QDate getDate(int year, int month, int day); - Q_INVOKABLE static DateModel* toDateModel(const QString& str, const QString& format = "yyyy/MM/dd"); - Q_INVOKABLE static DateModel* getDateModel(int year, int month, int day); - Q_INVOKABLE static int getFullYear(const QDate& date); - Q_INVOKABLE static int getMonth(const QDate& date); - Q_INVOKABLE static int getDay(const QDate& date); - Q_INVOKABLE static int getDayOfWeek(const QDate& date); - Q_INVOKABLE static bool equals(const QDate& d1, const QDate& d2); // Override JS '==' operator - Q_INVOKABLE static bool isGreatherThan(const QDate& d1, const QDate& d2); // Override JS '>=' operator -//***** - static void cleanDisplayNameCache(const QString& address = "");// if "", clean all cache - Q_INVOKABLE static QString getDisplayName(const QString& address); - Q_INVOKABLE static QString getInitials(const QString& username); // Support UTF32 - Q_INVOKABLE static QString toString(const LinphoneEnums::TunnelMode& mode); - Q_INVOKABLE static bool isMe(const QString& address); - Q_INVOKABLE static bool isAnimatedImage(const QString& path); - Q_INVOKABLE static bool isImage(const QString& path); - Q_INVOKABLE static bool isVideo(const QString& path); - Q_INVOKABLE static bool isPdf(const QString& path); - Q_INVOKABLE static bool isSupportedForDisplay(const QString& path); - Q_INVOKABLE static bool canHaveThumbnail(const QString& path); - Q_INVOKABLE static bool isPhoneNumber(const QString& txt); - Q_INVOKABLE static bool isUsername(const QString& txt); // Check with Regex - Q_INVOKABLE static bool isValidUrl(const QString& url); - Q_INVOKABLE QSize getImageSize(const QString& url); - Q_INVOKABLE static QPoint getCursorPosition(); - Q_INVOKABLE static QString getFileChecksum(const QString& filePath); - static bool codepointIsEmoji(uint code); - static bool codepointIsVisible(uint code); - Q_INVOKABLE static bool isOnlyEmojis(const QString& text); - Q_INVOKABLE static QString encodeEmojiToQmlRichFormat(const QString &body); - Q_INVOKABLE static QString encodeTextToQmlRichFormat(const QString& text, const QVariantMap& options = QVariantMap()); - Q_INVOKABLE static QString getFileContent(const QString& filePath); - - Q_INVOKABLE static bool openWithPdfViewer(ContentModel *contentModel, const QString& filePath, const int& width, const int& height); // return true if PDF is enabled - -//---------------------------------------------------------------------------------- - - static inline QString coreStringToAppString (const std::string &str) { - if(Constants::LinphoneLocaleEncoding == QString("UTF-8")) - return QString::fromStdString(str); - else - return QString::fromLocal8Bit(str.c_str(), int(str.size()));// When using Locale. Be careful about conversion bijection with UTF-8, you may loss characters + Utils(QObject *parent = nullptr) : QObject(parent) { } - - static inline std::string appStringToCoreString (const QString &str) { - if(Constants::LinphoneLocaleEncoding == QString("UTF-8")) - return str.toStdString(); + /* + typedef enum{ + SIP_DISPLAY_USERNAME = 0, + SIP_DISPLAY_ALL = -1 + }SipDisplayMode; + Q_ENUM(SipDisplayMode) + + // Qt interfaces + Q_INVOKABLE static bool hasCapability(const QString& address, const LinphoneEnums::FriendCapability& capability, + bool defaultCapability = true); + // ***** DATE TIME + Q_INVOKABLE static QDateTime addMinutes(QDateTime date, const int& min); + static QDateTime getOffsettedUTC(const QDateTime& date); + Q_INVOKABLE static QString toDateTimeString(QDateTime date, const QString& format = "yyyy/MM/dd hh:mm:ss"); + Q_INVOKABLE static QString toTimeString(QDateTime date, const QString& format = "hh:mm:ss"); + Q_INVOKABLE static QString toDateString(QDateTime date, const QString& format = ""); + Q_INVOKABLE static QString toDateString(QDate date, const QString& format = ""); + Q_INVOKABLE static QString toDisplayString(const QString& str, SipDisplayMode displayMode = SIP_DISPLAY_ALL); + Q_INVOKABLE static QDate getCurrentDate(); + Q_INVOKABLE static DateModel* getCurrentDateModel(); + Q_INVOKABLE static QDate getMinDate(); + Q_INVOKABLE static DateModel* getMinDateModel(); + Q_INVOKABLE static QDate toDate(const QString& str, const QString& format = "yyyy/MM/dd"); + Q_INVOKABLE static QDate getDate(int year, int month, int day); + Q_INVOKABLE static DateModel* toDateModel(const QString& str, const QString& format = "yyyy/MM/dd"); + Q_INVOKABLE static DateModel* getDateModel(int year, int month, int day); + Q_INVOKABLE static int getFullYear(const QDate& date); + Q_INVOKABLE static int getMonth(const QDate& date); + Q_INVOKABLE static int getDay(const QDate& date); + Q_INVOKABLE static int getDayOfWeek(const QDate& date); + Q_INVOKABLE static bool equals(const QDate& d1, const QDate& d2); // Override JS '==' operator + Q_INVOKABLE static bool isGreatherThan(const QDate& d1, const QDate& d2); // Override JS '>=' operator + //***** + static void cleanDisplayNameCache(const QString& address = "");// if "", clean all cache + Q_INVOKABLE static QString getDisplayName(const QString& address); + Q_INVOKABLE static QString getInitials(const QString& username); // Support UTF32 + Q_INVOKABLE static QString toString(const LinphoneEnums::TunnelMode& mode); + Q_INVOKABLE static bool isMe(const QString& address); + Q_INVOKABLE static bool isAnimatedImage(const QString& path); + Q_INVOKABLE static bool isImage(const QString& path); + Q_INVOKABLE static bool isVideo(const QString& path); + Q_INVOKABLE static bool isPdf(const QString& path); + Q_INVOKABLE static bool isSupportedForDisplay(const QString& path); + Q_INVOKABLE static bool canHaveThumbnail(const QString& path); + Q_INVOKABLE static bool isPhoneNumber(const QString& txt); + Q_INVOKABLE static bool isUsername(const QString& txt); // Check with Regex + Q_INVOKABLE static bool isValidUrl(const QString& url); + Q_INVOKABLE QSize getImageSize(const QString& url); + Q_INVOKABLE static QPoint getCursorPosition(); + Q_INVOKABLE static QString getFileChecksum(const QString& filePath); + static bool codepointIsEmoji(uint code); + static bool codepointIsVisible(uint code); + Q_INVOKABLE static bool isOnlyEmojis(const QString& text); + Q_INVOKABLE static QString encodeEmojiToQmlRichFormat(const QString &body); + Q_INVOKABLE static QString encodeTextToQmlRichFormat(const QString& text, const QVariantMap& options = + QVariantMap()); Q_INVOKABLE static QString getFileContent(const QString& filePath); + + Q_INVOKABLE static bool openWithPdfViewer(ContentModel *contentModel, const QString& filePath, const int& width, + const int& height); // return true if PDF is enabled + + //---------------------------------------------------------------------------------- + */ + static inline QString coreStringToAppString(const std::string &str) { + if (Constants::LinphoneLocaleEncoding == QString("UTF-8")) return QString::fromStdString(str); else - return qPrintable(str); + return QString::fromLocal8Bit(str.c_str(), + int(str.size())); // When using Locale. Be careful about conversion bijection + // with UTF-8, you may loss characters } - + + static inline std::string appStringToCoreString(const QString &str) { + if (Constants::LinphoneLocaleEncoding == QString("UTF-8")) return str.toStdString(); + else return qPrintable(str); + } + /* // Reverse function of strstr. static char *rstrstr (const char *a, const char *b); // Return the path if it is an image else an empty path. @@ -134,66 +136,65 @@ public: // Returns the same path given in parameter if `filePath` exists. // Otherwise returns a safe path with a unique number before the extension. static QString getSafeFilePath (const QString &filePath, bool *soFarSoGood = nullptr); - static std::shared_ptr getMatchingLocalAddress(std::shared_ptr p_localAddress); - static QString cleanSipAddress (const QString &sipAddress);// Return at most : sip:username@domain + static std::shared_ptr getMatchingLocalAddress(std::shared_ptr + p_localAddress); static QString cleanSipAddress (const QString &sipAddress);// Return at most : sip:username@domain // Test if the process exists static bool processExists(const quint64& p_processId); - + // Connect once to a member function. template static inline QMetaObject::Connection connectOnce ( - typename QtPrivate::FunctionPointer::Object *sender, - Func1 signal, - typename QtPrivate::FunctionPointer::Object *receiver, - Func2 slot - ) { - QMetaObject::Connection connection = QObject::connect(sender, signal, receiver, slot); - QMetaObject::Connection *deleter = new QMetaObject::Connection(); - - *deleter = QObject::connect(sender, signal, [connection, deleter] { - QObject::disconnect(connection); - QObject::disconnect(*deleter); - delete deleter; - }); - - return connection; + typename QtPrivate::FunctionPointer::Object *sender, + Func1 signal, + typename QtPrivate::FunctionPointer::Object *receiver, + Func2 slot + ) { + QMetaObject::Connection connection = QObject::connect(sender, signal, receiver, slot); + QMetaObject::Connection *deleter = new QMetaObject::Connection(); + + *deleter = QObject::connect(sender, signal, [connection, deleter] { + QObject::disconnect(connection); + QObject::disconnect(*deleter); + delete deleter; + }); + + return connection; } - + // Connect once to a function. template static inline QMetaObject::Connection connectOnce ( - typename QtPrivate::FunctionPointer::Object *sender, - Func1 signal, - const QObject *receiver, - Func2 slot - ) { - QMetaObject::Connection connection = QObject::connect(sender, signal, receiver, slot); - QMetaObject::Connection *deleter = new QMetaObject::Connection(); - - *deleter = QObject::connect(sender, signal, [connection, deleter] { - QObject::disconnect(connection); - QObject::disconnect(*deleter); - delete deleter; - }); - - return connection; + typename QtPrivate::FunctionPointer::Object *sender, + Func1 signal, + const QObject *receiver, + Func2 slot + ) { + QMetaObject::Connection connection = QObject::connect(sender, signal, receiver, slot); + QMetaObject::Connection *deleter = new QMetaObject::Connection(); + + *deleter = QObject::connect(sender, signal, [connection, deleter] { + QObject::disconnect(connection); + QObject::disconnect(*deleter); + delete deleter; + }); + + return connection; } static std::shared_ptr interpretUrl(const QString& address); - - + + static QString getCountryName(const QLocale::Country& country); static void copyDir(QString from, QString to);// Copy a folder recursively without erasing old file - static QString getDisplayName(const std::shared_ptr& address); // Get the displayname from addres in this order : Friends, Contact, Display address, Username address - static std::shared_ptr getConfigIfExists (const QString& configPath); - static QString getApplicationProduct(); - static QString getOsProduct(); - static QString computeUserAgent(const std::shared_ptr& config); - + static QString getDisplayName(const std::shared_ptr& address); // Get the displayname from + addres in this order : Friends, Contact, Display address, Username address static std::shared_ptr + getConfigIfExists (const QString& configPath); static QString getApplicationProduct(); static QString + getOsProduct(); static QString computeUserAgent(const std::shared_ptr& config); + static bool isMe(const std::shared_ptr& address); - + static void deleteAllUserData(); static void deleteAllUserDataOffline();// When we are out of all events and core is not running (aka in main()) - + static void setFamilyFont(QAction * dest, const QString& family); static void setFamilyFont(QWidget * dest, const QString& family); static QPixmap getMaskedPixmap(const QString& name, const QColor& color); diff --git a/Linphone/view/Page/LoginPage.cpp b/Linphone/view/Page/LoginPage.cpp index ae3d75207..8fc20f1d5 100644 --- a/Linphone/view/Page/LoginPage.cpp +++ b/Linphone/view/Page/LoginPage.cpp @@ -1,14 +1,12 @@ #include "LoginPage.hpp" #include - -LoginPage::LoginPage(QObject * parent) : QObject(parent){ - +LoginPage::LoginPage(QObject *parent) : QObject(parent) { } bool LoginPage::isLogged() { static bool testLog = false; - QTimer::singleShot(2000, [&]() mutable{ + QTimer::singleShot(2000, [&]() mutable { testLog = true; emit isLoggedChanged(); }); diff --git a/Linphone/view/Page/LoginPage.hpp b/Linphone/view/Page/LoginPage.hpp index e1238b368..a0476d4d2 100644 --- a/Linphone/view/Page/LoginPage.hpp +++ b/Linphone/view/Page/LoginPage.hpp @@ -2,16 +2,16 @@ #include -class LoginPage : public QObject{ -Q_OBJECT +class LoginPage : public QObject { + Q_OBJECT public: - LoginPage(QObject * parent = nullptr); - + LoginPage(QObject *parent = nullptr); + Q_PROPERTY(bool isLogged READ isLogged NOTIFY isLoggedChanged) - + bool isLogged(); - + signals: void isLoggedChanged(); }; \ No newline at end of file diff --git a/cmake/hook/pre-commit b/cmake/hook/pre-commit new file mode 100755 index 000000000..f64c4cc1c --- /dev/null +++ b/cmake/hook/pre-commit @@ -0,0 +1,27 @@ +#!/bin/bash + +# This hook verifies that the changes are formatted using clang-format. +# It has to be installed in: +# - .git/hooks/pre-commit for a root project +# - .git/modules//hooks/pre-commit for a submodule + +if ! [ -x "$(command -v clang-format)" ]; then + echo "Pre commit hook: Please install clang-format (coding style checker) - could not find clang-format in PATH." + exit 1 +fi + +CHANGED_FILES="$(git diff --name-only --cached --diff-filter=ACMR | grep -E '\.(c|cc|cpp|h|hh)$')" + +if [[ -n "$CHANGED_FILES" ]]; then + if ! clang-format --style=file -Werror -n $CHANGED_FILES > /dev/null 2>&1; then + echo "*****************" + echo "" + echo "Pre commit hook: Staged file(s) contains non correctly formatted code. Please correct it using one of the following:" + echo "1) Configure your IDE to format automatically on save (entire file)" + echo "2) Use clang-format to correctly format source code using:" + echo " clang-format --style=file -i " + echo "" + echo "*** Aborting commit.***" + exit 1 + fi +fi