Commit 74639a7d authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): replace some define by constexpr (modern cpp syntax)

parent e122e04b
...@@ -45,25 +45,27 @@ ...@@ -45,25 +45,27 @@
#include "App.hpp" #include "App.hpp"
#define DEFAULT_LOCALE "en" using namespace std;
#define LANGUAGES_PATH ":/languages/" // =============================================================================
// The main windows of Linphone desktop. namespace {
#define QML_VIEW_MAIN_WINDOW "qrc:/ui/views/App/Main/MainWindow.qml" constexpr char cDefaultLocale[] = "en";
#define QML_VIEW_CALLS_WINDOW "qrc:/ui/views/App/Calls/CallsWindow.qml"
#define QML_VIEW_SETTINGS_WINDOW "qrc:/ui/views/App/Settings/SettingsWindow.qml"
#define QML_VIEW_SPLASH_SCREEN "qrc:/ui/views/App/SplashScreen/SplashScreen.qml" constexpr char cLanguagePath[] = ":/languages/";
#define VERSION_UPDATE_CHECK_INTERVAL 86400000 // 24 hours in milliseconds. // The main windows of Linphone desktop.
constexpr char cQmlViewMainWindow[] = "qrc:/ui/views/App/Main/MainWindow.qml";
constexpr char cQmlViewCallsWindow[] = "qrc:/ui/views/App/Calls/CallsWindow.qml";
constexpr char cQmlViewSettingsWindow[] = "qrc:/ui/views/App/Settings/SettingsWindow.qml";
using namespace std; constexpr char cQmlViewSplashScreen[] = "qrc:/ui/views/App/SplashScreen/SplashScreen.qml";
// ============================================================================= constexpr int cVersionUpdateCheckInterval = 86400000; // 24 hours in milliseconds.
}
static inline bool installLocale (App &app, QTranslator &translator, const QLocale &locale) { static inline bool installLocale (App &app, QTranslator &translator, const QLocale &locale) {
return translator.load(locale, LANGUAGES_PATH) && app.installTranslator(&translator); return translator.load(locale, cLanguagePath) && app.installTranslator(&translator);
} }
static inline shared_ptr<linphone::Config> getConfigIfExists (const QCommandLineParser &parser) { static inline shared_ptr<linphone::Config> getConfigIfExists (const QCommandLineParser &parser) {
...@@ -89,7 +91,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U ...@@ -89,7 +91,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
Logger::getInstance()->setVerbose(true); Logger::getInstance()->setVerbose(true);
// List available locales. // List available locales.
for (const auto &locale : QDir(LANGUAGES_PATH).entryList()) for (const auto &locale : QDir(cLanguagePath).entryList())
mAvailableLocales << QLocale(locale); mAvailableLocales << QLocale(locale);
// Init locale. // Init locale.
...@@ -138,7 +140,7 @@ static QQuickWindow *createSubWindow (QQmlApplicationEngine *engine, const char ...@@ -138,7 +140,7 @@ static QQuickWindow *createSubWindow (QQmlApplicationEngine *engine, const char
static void activeSplashScreen (QQmlApplicationEngine *engine) { static void activeSplashScreen (QQmlApplicationEngine *engine) {
qInfo() << QStringLiteral("Open splash screen..."); qInfo() << QStringLiteral("Open splash screen...");
QQuickWindow *splashScreen = ::createSubWindow(engine, QML_VIEW_SPLASH_SCREEN); QQuickWindow *splashScreen = ::createSubWindow(engine, cQmlViewSplashScreen);
QObject::connect(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted, splashScreen, [splashScreen] { QObject::connect(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted, splashScreen, [splashScreen] {
splashScreen->close(); splashScreen->close();
splashScreen->deleteLater(); splashScreen->deleteLater();
...@@ -240,7 +242,7 @@ void App::initContentApp () { ...@@ -240,7 +242,7 @@ void App::initContentApp () {
// Load main view. // Load main view.
qInfo() << QStringLiteral("Loading main view..."); qInfo() << QStringLiteral("Loading main view...");
mEngine->load(QUrl(QML_VIEW_MAIN_WINDOW)); mEngine->load(QUrl(cQmlViewMainWindow));
if (mEngine->rootObjects().isEmpty()) if (mEngine->rootObjects().isEmpty())
qFatal("Unable to open main window."); qFatal("Unable to open main window.");
...@@ -281,7 +283,7 @@ QString App::getCommandArgument () { ...@@ -281,7 +283,7 @@ QString App::getCommandArgument () {
QQuickWindow *App::getCallsWindow () { QQuickWindow *App::getCallsWindow () {
if (!mCallsWindow) if (!mCallsWindow)
mCallsWindow = ::createSubWindow(mEngine, QML_VIEW_CALLS_WINDOW); mCallsWindow = ::createSubWindow(mEngine, cQmlViewCallsWindow);
return mCallsWindow; return mCallsWindow;
} }
...@@ -294,7 +296,7 @@ QQuickWindow *App::getMainWindow () const { ...@@ -294,7 +296,7 @@ QQuickWindow *App::getMainWindow () const {
QQuickWindow *App::getSettingsWindow () { QQuickWindow *App::getSettingsWindow () {
if (!mSettingsWindow) { if (!mSettingsWindow) {
mSettingsWindow = ::createSubWindow(mEngine, QML_VIEW_SETTINGS_WINDOW); mSettingsWindow = ::createSubWindow(mEngine, cQmlViewSettingsWindow);
QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) { QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) {
if (visibility == QWindow::Hidden) { if (visibility == QWindow::Hidden) {
qInfo() << QStringLiteral("Update nat policy."); qInfo() << QStringLiteral("Update nat policy.");
...@@ -514,7 +516,7 @@ void App::initLocale (const shared_ptr<linphone::Config> &config) { ...@@ -514,7 +516,7 @@ void App::initLocale (const shared_ptr<linphone::Config> &config) {
} }
// Use english. // Use english.
mLocale = DEFAULT_LOCALE; mLocale = cDefaultLocale;
if (!::installLocale(*this, *mTranslator, QLocale(mLocale))) if (!::installLocale(*this, *mTranslator, QLocale(mLocale)))
qFatal("Unable to install default translator."); qFatal("Unable to install default translator.");
} }
...@@ -570,7 +572,7 @@ void App::openAppAfterInit (bool mustBeIconified) { ...@@ -570,7 +572,7 @@ void App::openAppAfterInit (bool mustBeIconified) {
#ifdef ENABLE_UPDATE_CHECK #ifdef ENABLE_UPDATE_CHECK
QTimer *timer = new QTimer(mEngine); QTimer *timer = new QTimer(mEngine);
timer->setInterval(VERSION_UPDATE_CHECK_INTERVAL); timer->setInterval(cVersionUpdateCheckInterval);
QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate); QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate);
timer->start(); timer->start();
......
...@@ -29,19 +29,21 @@ ...@@ -29,19 +29,21 @@
#include "AppController.hpp" #include "AppController.hpp"
// Must be unique. Used by `SingleApplication` and `Paths`.
#define APPLICATION_NAME "linphone"
#define APPLICATION_VERSION LINPHONE_QT_GIT_VERSION
#define APPLICATION_MINIMAL_QT_VERSION "5.9.0"
#define DEFAULT_FONT "Noto Sans"
using namespace std; using namespace std;
// ============================================================================= // =============================================================================
namespace {
// Must be unique. Used by `SingleApplication` and `Paths`.
constexpr char cApplicationName[] = "linphone";
constexpr char cApplicationVersion[] = LINPHONE_QT_GIT_VERSION;
constexpr char cApplicationMinimalQtVersion[] = "5.9.0";
constexpr char cDefaultFont[] = "Noto Sans";
}
AppController::AppController (int &argc, char *argv[]) { AppController::AppController (int &argc, char *argv[]) {
QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION); QT_REQUIRE_VERSION(argc, argv, cApplicationMinimalQtVersion);
Q_ASSERT(!mApp); Q_ASSERT(!mApp);
// Disable QML cache. Avoid malformed cache. // Disable QML cache. Avoid malformed cache.
...@@ -82,8 +84,8 @@ AppController::AppController (int &argc, char *argv[]) { ...@@ -82,8 +84,8 @@ AppController::AppController (int &argc, char *argv[]) {
// App creation. // App creation.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
QCoreApplication::setApplicationName(APPLICATION_NAME); QCoreApplication::setApplicationName(cApplicationName);
QCoreApplication::setApplicationVersion(APPLICATION_VERSION); QCoreApplication::setApplicationVersion(cApplicationVersion);
mApp = new App(argc, argv); mApp = new App(argc, argv);
QQuickStyle::setStyle("Default"); QQuickStyle::setStyle("Default");
...@@ -113,7 +115,7 @@ AppController::AppController (int &argc, char *argv[]) { ...@@ -113,7 +115,7 @@ AppController::AppController (int &argc, char *argv[]) {
} }
} }
mApp->setFont(QFont(DEFAULT_FONT)); mApp->setFont(QFont(cDefaultFont));
} }
AppController::~AppController () { AppController::~AppController () {
......
...@@ -29,13 +29,15 @@ ...@@ -29,13 +29,15 @@
#include "ImageProvider.hpp" #include "ImageProvider.hpp"
// Max image size in bytes. (100Kb)
#define MAX_IMAGE_SIZE 102400
using namespace std; using namespace std;
// ============================================================================= // =============================================================================
namespace {
// Max image size in bytes. (100Kb)
constexpr size_t cMaxImageSize = 102400;
}
static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QString &name) { static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QString &name) {
auto it = find_if(readerAttributes.cbegin(), readerAttributes.cend(), [&name](const QXmlStreamAttribute &attribute) { auto it = find_if(readerAttributes.cbegin(), readerAttributes.cend(), [&name](const QXmlStreamAttribute &attribute) {
return name == attribute.name() && !attribute.prefix().length(); return name == attribute.name() && !attribute.prefix().length();
...@@ -250,7 +252,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize ...@@ -250,7 +252,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize
// 1. Read and update XML content. // 1. Read and update XML content.
QFile file(path); QFile file(path);
if (Q_UNLIKELY(QFileInfo(file).size() > MAX_IMAGE_SIZE)) { if (Q_UNLIKELY(QFileInfo(file).size() > cMaxImageSize)) {
qWarning() << QStringLiteral("Unable to open large file: `%1`.").arg(path); qWarning() << QStringLiteral("Unable to open large file: `%1`.").arg(path);
return QImage(); return QImage();
} }
......
...@@ -26,22 +26,22 @@ ...@@ -26,22 +26,22 @@
#include "Colors.hpp" #include "Colors.hpp"
#define COLORS_SECTION "ui_colors"
#if LINPHONE_FRIDAY #if LINPHONE_FRIDAY
#include <QDate> #include <QDate>
#endif // if LINPHONE_FRIDAY #endif // if LINPHONE_FRIDAY
using namespace std; using namespace std;
// ============================================================================= // =============================================================================
#if LINPHONE_FRIDAY namespace {
constexpr char cColorsSection[] = "ui_colors";
}
#if LINPHONE_FRIDAY
static inline bool isLinphoneFriday () { static inline bool isLinphoneFriday () {
return QDate::currentDate().dayOfWeek() == 5; return QDate::currentDate().dayOfWeek() == 5;
} }
#endif // if LINPHONE_FRIDAY #endif // if LINPHONE_FRIDAY
Colors::Colors (QObject *parent) : QObject(parent) { Colors::Colors (QObject *parent) : QObject(parent) {
...@@ -74,7 +74,7 @@ void Colors::overrideColors (const shared_ptr<linphone::Config> &config) { ...@@ -74,7 +74,7 @@ void Colors::overrideColors (const shared_ptr<linphone::Config> &config) {
for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) { for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) {
const QMetaProperty metaProperty = info->property(i); const QMetaProperty metaProperty = info->property(i);
const string colorName = metaProperty.name(); const string colorName = metaProperty.name();
const string colorValue = config->getString(COLORS_SECTION, colorName, ""); const string colorValue = config->getString(cColorsSection, colorName, "");
if (!colorValue.empty()) if (!colorValue.empty())
setProperty(colorName.c_str(), QColor(::Utils::coreStringToAppString(colorValue))); setProperty(colorName.c_str(), QColor(::Utils::coreStringToAppString(colorValue)));
......
...@@ -24,14 +24,16 @@ ...@@ -24,14 +24,16 @@
#include "SipAddressesProxyModel.hpp" #include "SipAddressesProxyModel.hpp"
#define WEIGHT_POS_0 5
#define WEIGHT_POS_1 4
#define WEIGHT_POS_2 3
#define WEIGHT_POS_3 2
#define WEIGHT_POS_OTHER 1
// ============================================================================= // =============================================================================
namespace {
constexpr int cWeightPos0 = 5;
constexpr int cWeightPos1 = 4;
constexpr int cWeightPos2 = 3;
constexpr int cWeightPos3 = 2;
constexpr int cWeightPosOther = 1;
}
const QRegExp SipAddressesProxyModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]"); const QRegExp SipAddressesProxyModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]");
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -116,12 +118,12 @@ int SipAddressesProxyModel::computeStringWeight (const QString &string) const { ...@@ -116,12 +118,12 @@ int SipAddressesProxyModel::computeStringWeight (const QString &string) const {
switch (offset) { switch (offset) {
case -1: return 0; case -1: return 0;
case 0: return WEIGHT_POS_0; case 0: return cWeightPos0;
case 1: return WEIGHT_POS_1; case 1: return cWeightPos1;
case 2: return WEIGHT_POS_2; case 2: return cWeightPos2;
case 3: return WEIGHT_POS_3; case 3: return cWeightPos3;
default: break; default: break;
} }
return WEIGHT_POS_OTHER; return cWeightPosOther;
} }
...@@ -27,12 +27,14 @@ ...@@ -27,12 +27,14 @@
#include "SoundPlayer.hpp" #include "SoundPlayer.hpp"
#define FORCE_CLOSE_TIMER_INTERVAL 20
using namespace std; using namespace std;
// ============================================================================= // =============================================================================
namespace {
int cForceCloseTimerInterval = 20;
}
class SoundPlayer::Handlers : public linphone::PlayerListener { class SoundPlayer::Handlers : public linphone::PlayerListener {
public: public:
Handlers (SoundPlayer *soundPlayer) { Handlers (SoundPlayer *soundPlayer) {
...@@ -58,7 +60,7 @@ private: ...@@ -58,7 +60,7 @@ private:
SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) { SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) {
mForceCloseTimer = new QTimer(this); mForceCloseTimer = new QTimer(this);
mForceCloseTimer->setInterval(FORCE_CLOSE_TIMER_INTERVAL); mForceCloseTimer->setInterval(cForceCloseTimerInterval);
QObject::connect(mForceCloseTimer, &QTimer::timeout, this, &SoundPlayer::handleEof); QObject::connect(mForceCloseTimer, &QTimer::timeout, this, &SoundPlayer::handleEof);
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
// ============================================================================= // =============================================================================
namespace {
constexpr int cSafeFilePathLimit = 100;
}
char *Utils::rstrstr (const char *a, const char *b) { char *Utils::rstrstr (const char *a, const char *b) {
size_t a_len = strlen(a); size_t a_len = strlen(a);
size_t b_len = strlen(b); size_t b_len = strlen(b);
...@@ -43,8 +47,6 @@ char *Utils::rstrstr (const char *a, const char *b) { ...@@ -43,8 +47,6 @@ char *Utils::rstrstr (const char *a, const char *b) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define SAFE_FILE_PATH_LIMIT 100
QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) { QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) {
if (soFarSoGood) if (soFarSoGood)
*soFarSoGood = true; *soFarSoGood = true;
...@@ -56,7 +58,7 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) { ...@@ -56,7 +58,7 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) {
const QString prefix = QStringLiteral("%1/%2").arg(info.absolutePath()).arg(info.baseName()); const QString prefix = QStringLiteral("%1/%2").arg(info.absolutePath()).arg(info.baseName());
const QString ext = info.completeSuffix(); const QString ext = info.completeSuffix();
for (int i = 1; i < SAFE_FILE_PATH_LIMIT; ++i) { for (int i = 1; i < cSafeFilePathLimit; ++i) {
QString safePath = QStringLiteral("%1 (%3).%4").arg(prefix).arg(i).arg(ext); QString safePath = QStringLiteral("%1 (%3).%4").arg(prefix).arg(i).arg(ext);
if (!QFileInfo::exists(safePath)) if (!QFileInfo::exists(safePath))
return safePath; return safePath;
...@@ -67,5 +69,3 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) { ...@@ -67,5 +69,3 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) {
return QString(""); return QString("");
} }
#undef SAFE_FILE_PATH_LIMIT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment