Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
74639a7d
Commit
74639a7d
authored
Jan 26, 2018
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): replace some define by constexpr (modern cpp syntax)
parent
e122e04b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
58 deletions
+68
-58
App.cpp
src/app/App.cpp
+20
-18
AppController.cpp
src/app/AppController.cpp
+13
-11
ImageProvider.cpp
src/app/providers/ImageProvider.cpp
+6
-4
Colors.cpp
src/components/other/colors/Colors.cpp
+6
-6
SipAddressesProxyModel.cpp
src/components/sip-addresses/SipAddressesProxyModel.cpp
+13
-11
SoundPlayer.cpp
src/components/sound-player/SoundPlayer.cpp
+5
-3
Utils.cpp
src/utils/Utils.cpp
+5
-5
No files found.
src/app/App.cpp
View file @
74639a7d
...
...
@@ -45,25 +45,27 @@
#include "App.hpp"
#define DEFAULT_LOCALE "en"
using
namespace
std
;
#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"
namespace
{
constexpr
char
cDefaultLocale
[]
=
"en"
;
#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
)
{
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
();
...
...
src/app/AppController.cpp
View file @
74639a7d
...
...
@@ -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
()
{
...
...
src/app/providers/ImageProvider.cpp
View file @
74639a7d
...
...
@@ -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
();
}
...
...
src/components/other/colors/Colors.cpp
View file @
74639a7d
...
...
@@ -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
)));
...
...
src/components/sip-addresses/SipAddressesProxyModel.cpp
View file @
74639a7d
...
...
@@ -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
cWeightPos
0
;
case
1
:
return
cWeightPos
1
;
case
2
:
return
cWeightPos
2
;
case
3
:
return
cWeightPos
3
;
default:
break
;
}
return
WEIGHT_POS_OTHER
;
return
cWeightPosOther
;
}
src/components/sound-player/SoundPlayer.cpp
View file @
74639a7d
...
...
@@ -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
);
...
...
src/utils/Utils.cpp
View file @
74639a7d
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment