mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(app): replace some define by constexpr (modern cpp syntax)
This commit is contained in:
parent
e122e04b59
commit
74639a7d3d
7 changed files with 71 additions and 61 deletions
|
|
@ -45,25 +45,27 @@
|
|||
|
||||
#include "App.hpp"
|
||||
|
||||
#define DEFAULT_LOCALE "en"
|
||||
|
||||
#define LANGUAGES_PATH ":/languages/"
|
||||
|
||||
// The main windows of Linphone desktop.
|
||||
#define QML_VIEW_MAIN_WINDOW "qrc:/ui/views/App/Main/MainWindow.qml"
|
||||
#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"
|
||||
|
||||
#define VERSION_UPDATE_CHECK_INTERVAL 86400000 // 24 hours in milliseconds.
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace {
|
||||
constexpr char cDefaultLocale[] = "en";
|
||||
|
||||
constexpr char cLanguagePath[] = ":/languages/";
|
||||
|
||||
// The main windows of Linphone desktop.
|
||||
constexpr char cQmlViewMainWindow[] = "qrc:/ui/views/App/Main/MainWindow.qml";
|
||||
constexpr char cQmlViewCallsWindow[] = "qrc:/ui/views/App/Calls/CallsWindow.qml";
|
||||
constexpr char cQmlViewSettingsWindow[] = "qrc:/ui/views/App/Settings/SettingsWindow.qml";
|
||||
|
||||
constexpr char 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) {
|
||||
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) {
|
||||
|
|
@ -89,7 +91,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
|
|||
Logger::getInstance()->setVerbose(true);
|
||||
|
||||
// List available locales.
|
||||
for (const auto &locale : QDir(LANGUAGES_PATH).entryList())
|
||||
for (const auto &locale : QDir(cLanguagePath).entryList())
|
||||
mAvailableLocales << QLocale(locale);
|
||||
|
||||
// Init locale.
|
||||
|
|
@ -138,7 +140,7 @@ static QQuickWindow *createSubWindow (QQmlApplicationEngine *engine, const char
|
|||
|
||||
static void activeSplashScreen (QQmlApplicationEngine *engine) {
|
||||
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] {
|
||||
splashScreen->close();
|
||||
splashScreen->deleteLater();
|
||||
|
|
@ -240,7 +242,7 @@ void App::initContentApp () {
|
|||
|
||||
// Load main view.
|
||||
qInfo() << QStringLiteral("Loading main view...");
|
||||
mEngine->load(QUrl(QML_VIEW_MAIN_WINDOW));
|
||||
mEngine->load(QUrl(cQmlViewMainWindow));
|
||||
if (mEngine->rootObjects().isEmpty())
|
||||
qFatal("Unable to open main window.");
|
||||
|
||||
|
|
@ -281,7 +283,7 @@ QString App::getCommandArgument () {
|
|||
|
||||
QQuickWindow *App::getCallsWindow () {
|
||||
if (!mCallsWindow)
|
||||
mCallsWindow = ::createSubWindow(mEngine, QML_VIEW_CALLS_WINDOW);
|
||||
mCallsWindow = ::createSubWindow(mEngine, cQmlViewCallsWindow);
|
||||
|
||||
return mCallsWindow;
|
||||
}
|
||||
|
|
@ -294,7 +296,7 @@ QQuickWindow *App::getMainWindow () const {
|
|||
|
||||
QQuickWindow *App::getSettingsWindow () {
|
||||
if (!mSettingsWindow) {
|
||||
mSettingsWindow = ::createSubWindow(mEngine, QML_VIEW_SETTINGS_WINDOW);
|
||||
mSettingsWindow = ::createSubWindow(mEngine, cQmlViewSettingsWindow);
|
||||
QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) {
|
||||
if (visibility == QWindow::Hidden) {
|
||||
qInfo() << QStringLiteral("Update nat policy.");
|
||||
|
|
@ -514,7 +516,7 @@ void App::initLocale (const shared_ptr<linphone::Config> &config) {
|
|||
}
|
||||
|
||||
// Use english.
|
||||
mLocale = DEFAULT_LOCALE;
|
||||
mLocale = cDefaultLocale;
|
||||
if (!::installLocale(*this, *mTranslator, QLocale(mLocale)))
|
||||
qFatal("Unable to install default translator.");
|
||||
}
|
||||
|
|
@ -570,7 +572,7 @@ void App::openAppAfterInit (bool mustBeIconified) {
|
|||
|
||||
#ifdef ENABLE_UPDATE_CHECK
|
||||
QTimer *timer = new QTimer(mEngine);
|
||||
timer->setInterval(VERSION_UPDATE_CHECK_INTERVAL);
|
||||
timer->setInterval(cVersionUpdateCheckInterval);
|
||||
|
||||
QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate);
|
||||
timer->start();
|
||||
|
|
|
|||
|
|
@ -29,19 +29,21 @@
|
|||
|
||||
#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;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
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[]) {
|
||||
QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION);
|
||||
QT_REQUIRE_VERSION(argc, argv, cApplicationMinimalQtVersion);
|
||||
Q_ASSERT(!mApp);
|
||||
|
||||
// Disable QML cache. Avoid malformed cache.
|
||||
|
|
@ -82,8 +84,8 @@ AppController::AppController (int &argc, char *argv[]) {
|
|||
// App creation.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
QCoreApplication::setApplicationName(APPLICATION_NAME);
|
||||
QCoreApplication::setApplicationVersion(APPLICATION_VERSION);
|
||||
QCoreApplication::setApplicationName(cApplicationName);
|
||||
QCoreApplication::setApplicationVersion(cApplicationVersion);
|
||||
|
||||
mApp = new App(argc, argv);
|
||||
QQuickStyle::setStyle("Default");
|
||||
|
|
@ -113,7 +115,7 @@ AppController::AppController (int &argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
mApp->setFont(QFont(DEFAULT_FONT));
|
||||
mApp->setFont(QFont(cDefaultFont));
|
||||
}
|
||||
|
||||
AppController::~AppController () {
|
||||
|
|
|
|||
|
|
@ -29,13 +29,15 @@
|
|||
|
||||
#include "ImageProvider.hpp"
|
||||
|
||||
// Max image size in bytes. (100Kb)
|
||||
#define MAX_IMAGE_SIZE 102400
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace {
|
||||
// Max image size in bytes. (100Kb)
|
||||
constexpr size_t cMaxImageSize = 102400;
|
||||
}
|
||||
|
||||
static void removeAttribute (QXmlStreamAttributes &readerAttributes, const QString &name) {
|
||||
auto it = find_if(readerAttributes.cbegin(), readerAttributes.cend(), [&name](const QXmlStreamAttribute &attribute) {
|
||||
return name == attribute.name() && !attribute.prefix().length();
|
||||
|
|
@ -250,7 +252,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize
|
|||
|
||||
// 1. Read and update XML content.
|
||||
QFile file(path);
|
||||
if (Q_UNLIKELY(QFileInfo(file).size() > MAX_IMAGE_SIZE)) {
|
||||
if (Q_UNLIKELY(QFileInfo(file).size() > cMaxImageSize)) {
|
||||
qWarning() << QStringLiteral("Unable to open large file: `%1`.").arg(path);
|
||||
return QImage();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,22 +26,22 @@
|
|||
|
||||
#include "Colors.hpp"
|
||||
|
||||
#define COLORS_SECTION "ui_colors"
|
||||
|
||||
#if LINPHONE_FRIDAY
|
||||
#include <QDate>
|
||||
#include <QDate>
|
||||
#endif // if LINPHONE_FRIDAY
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
#if LINPHONE_FRIDAY
|
||||
namespace {
|
||||
constexpr char cColorsSection[] = "ui_colors";
|
||||
}
|
||||
|
||||
#if LINPHONE_FRIDAY
|
||||
static inline bool isLinphoneFriday () {
|
||||
return QDate::currentDate().dayOfWeek() == 5;
|
||||
}
|
||||
|
||||
#endif // if LINPHONE_FRIDAY
|
||||
|
||||
Colors::Colors (QObject *parent) : QObject(parent) {
|
||||
|
|
@ -74,7 +74,7 @@ void Colors::overrideColors (const shared_ptr<linphone::Config> &config) {
|
|||
for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) {
|
||||
const QMetaProperty metaProperty = info->property(i);
|
||||
const string colorName = metaProperty.name();
|
||||
const string colorValue = config->getString(COLORS_SECTION, colorName, "");
|
||||
const string colorValue = config->getString(cColorsSection, colorName, "");
|
||||
|
||||
if (!colorValue.empty())
|
||||
setProperty(colorName.c_str(), QColor(::Utils::coreStringToAppString(colorValue)));
|
||||
|
|
|
|||
|
|
@ -24,14 +24,16 @@
|
|||
|
||||
#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("^[^_.-;@ ][_.-;@ ]");
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -116,12 +118,12 @@ int SipAddressesProxyModel::computeStringWeight (const QString &string) const {
|
|||
|
||||
switch (offset) {
|
||||
case -1: return 0;
|
||||
case 0: return WEIGHT_POS_0;
|
||||
case 1: return WEIGHT_POS_1;
|
||||
case 2: return WEIGHT_POS_2;
|
||||
case 3: return WEIGHT_POS_3;
|
||||
case 0: return cWeightPos0;
|
||||
case 1: return cWeightPos1;
|
||||
case 2: return cWeightPos2;
|
||||
case 3: return cWeightPos3;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return WEIGHT_POS_OTHER;
|
||||
return cWeightPosOther;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,14 @@
|
|||
|
||||
#include "SoundPlayer.hpp"
|
||||
|
||||
#define FORCE_CLOSE_TIMER_INTERVAL 20
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace {
|
||||
int cForceCloseTimerInterval = 20;
|
||||
}
|
||||
|
||||
class SoundPlayer::Handlers : public linphone::PlayerListener {
|
||||
public:
|
||||
Handlers (SoundPlayer *soundPlayer) {
|
||||
|
|
@ -58,7 +60,7 @@ private:
|
|||
|
||||
SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) {
|
||||
mForceCloseTimer = new QTimer(this);
|
||||
mForceCloseTimer->setInterval(FORCE_CLOSE_TIMER_INTERVAL);
|
||||
mForceCloseTimer->setInterval(cForceCloseTimerInterval);
|
||||
|
||||
QObject::connect(mForceCloseTimer, &QTimer::timeout, this, &SoundPlayer::handleEof);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
namespace {
|
||||
constexpr int cSafeFilePathLimit = 100;
|
||||
}
|
||||
|
||||
char *Utils::rstrstr (const char *a, const char *b) {
|
||||
size_t a_len = strlen(a);
|
||||
size_t b_len = strlen(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) {
|
||||
if (soFarSoGood)
|
||||
*soFarSoGood = true;
|
||||
|
|
@ -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 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);
|
||||
if (!QFileInfo::exists(safePath))
|
||||
return safePath;
|
||||
|
|
@ -67,5 +69,3 @@ QString Utils::getSafeFilePath (const QString &filePath, bool *soFarSoGood) {
|
|||
|
||||
return QString("");
|
||||
}
|
||||
|
||||
#undef SAFE_FILE_PATH_LIMIT
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue