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
16ae7c20
Commit
16ae7c20
authored
Feb 27, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(src/app/App): destroy correctly app
parent
b11088db
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
86 additions
and
63 deletions
+86
-63
App.cpp
linphone-desktop/src/app/App.cpp
+52
-30
App.hpp
linphone-desktop/src/app/App.hpp
+4
-22
VcardModel.cpp
linphone-desktop/src/components/contact/VcardModel.cpp
+1
-0
CoreHandlers.cpp
linphone-desktop/src/components/core/CoreHandlers.cpp
+9
-0
CoreHandlers.hpp
linphone-desktop/src/components/core/CoreHandlers.hpp
+7
-0
CoreManager.cpp
linphone-desktop/src/components/core/CoreManager.cpp
+4
-4
CoreManager.hpp
linphone-desktop/src/components/core/CoreManager.hpp
+2
-2
main.cpp
linphone-desktop/src/main.cpp
+7
-5
No files found.
linphone-desktop/src/app/App.cpp
View file @
16ae7c20
...
...
@@ -31,14 +31,18 @@
#include "../utils.hpp"
#include "App.hpp"
#include "AvatarProvider.hpp"
#include "DefaultTranslator.hpp"
#include "Logger.hpp"
#include "ThumbnailProvider.hpp"
#include <QDir>
#include <QFileSelector>
#include <QMenu>
#include <QTimer>
#include <QQmlFileSelector>
#include <QSystemTrayIcon>
#include <QtDebug>
#include <QTimer>
#define DEFAULT_LOCALE "en"
...
...
@@ -52,14 +56,13 @@
// =============================================================================
App
*
App
::
m_instance
=
nullptr
;
inline
bool
installLocale
(
App
&
app
,
QTranslator
&
translator
,
const
QLocale
&
locale
)
{
return
translator
.
load
(
locale
,
LANGUAGES_PATH
)
&&
app
.
installTranslator
(
&
translator
);
}
App
::
App
(
int
&
argc
,
char
**
argv
)
:
QApplication
(
argc
,
argv
)
{
setApplicationVersion
(
"4.0"
);
setWindowIcon
(
QIcon
(
WINDOW_ICON_PATH
));
// List available locales.
for
(
const
auto
&
locale
:
QDir
(
LANGUAGES_PATH
).
entryList
())
...
...
@@ -82,29 +85,37 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
qInfo
()
<<
QStringLiteral
(
"Use default locale: %1"
).
arg
(
m_locale
);
}
App
::~
App
()
{
qInfo
()
<<
"Destroying app..."
;
}
// -----------------------------------------------------------------------------
void
App
::
initContentApp
()
{
// Provide avatars/thumbnails providers.
m_engine
.
addImageProvider
(
AvatarProvider
::
PROVIDER_ID
,
&
m_avatar_provider
);
m_engine
.
addImageProvider
(
ThumbnailProvider
::
PROVIDER_ID
,
&
m_thumbnail_provider
);
setWindowIcon
(
QIcon
(
WINDOW_ICON_PATH
));
// Avoid double free.
m_engine
.
setObjectOwnership
(
this
,
QQmlEngine
::
CppOwnership
);
// Provide `+custom` folders for custom components.
m_file_selector
=
new
QQmlFileSelector
(
&
m_engine
);
m_file_selector
->
setExtraSelectors
(
QStringList
(
"custom"
));
{
QQmlFileSelector
*
file_selector
=
new
QQmlFileSelector
(
&
m_engine
);
file_selector
=
new
QQmlFileSelector
(
&
m_engine
);
file_selector
->
setExtraSelectors
(
QStringList
(
"custom"
));
}
// Set modules paths.
m_engine
.
addImportPath
(
":/ui/modules"
);
m_engine
.
addImportPath
(
":/ui/scripts"
);
m_engine
.
addImportPath
(
":/ui/views"
);
// Provide avatars/thumbnails providers.
m_engine
.
addImageProvider
(
AvatarProvider
::
PROVIDER_ID
,
new
AvatarProvider
());
m_engine
.
addImageProvider
(
ThumbnailProvider
::
PROVIDER_ID
,
new
ThumbnailProvider
());
// Don't quit if last window is closed!!!
setQuitOnLastWindowClosed
(
false
);
// Init core.
CoreManager
::
init
(
m_parser
.
value
(
"config"
));
CoreManager
::
init
(
nullptr
,
m_parser
.
value
(
"config"
));
qInfo
()
<<
"Core manager initialized."
;
qInfo
()
<<
"Activated selectors:"
<<
QQmlFileSelector
::
get
(
&
m_engine
)
->
selector
()
->
allSelectors
();
...
...
@@ -130,14 +141,17 @@ void App::initContentApp () {
}
}
// Register types an
s make sub
windows.
// Register types an
d create sub-
windows.
registerTypes
();
createSubWindows
();
// Enable notifications.
m_notifier
=
new
Notifier
();
m_notifier
=
new
Notifier
(
this
);
CoreManager
::
getInstance
()
->
enableHandlers
();
{
CoreManager
*
core
=
CoreManager
::
getInstance
();
core
->
enableHandlers
();
core
->
setParent
(
this
);
}
// Load main view.
qInfo
()
<<
"Loading main view..."
;
...
...
@@ -145,6 +159,8 @@ void App::initContentApp () {
if
(
m_engine
.
rootObjects
().
isEmpty
())
qFatal
(
"Unable to open main window."
);
createSubWindows
();
#ifndef __APPLE__
// Enable TrayIconSystem.
if
(
!
QSystemTrayIcon
::
isSystemTrayAvailable
())
...
...
@@ -293,22 +309,28 @@ void App::registerTypes () {
// -----------------------------------------------------------------------------
inline
QQuickWindow
*
createSubWindow
(
QQmlApplicationEngine
&
engine
,
const
char
*
path
)
{
QQmlComponent
component
(
&
engine
,
QUrl
(
path
));
inline
QQuickWindow
*
createSubWindow
(
App
*
app
,
const
char
*
path
)
{
QQmlEngine
*
engine
=
app
->
getEngine
();
QQmlComponent
component
(
engine
,
QUrl
(
path
));
if
(
component
.
isError
())
{
qWarning
()
<<
component
.
errors
();
abort
();
}
// Default Ownership is Cpp: http://doc.qt.io/qt-5/qqmlengine.html#ObjectOwnership-enum
return
qobject_cast
<
QQuickWindow
*>
(
component
.
create
());
QQuickWindow
*
window
=
qobject_cast
<
QQuickWindow
*>
(
component
.
create
());
QQmlEngine
::
setObjectOwnership
(
window
,
QQmlEngine
::
CppOwnership
);
window
->
setParent
(
app
->
getMainWindow
());
return
window
;
}
void
App
::
createSubWindows
()
{
qInfo
()
<<
"Create sub windows..."
;
m_calls_window
=
createSubWindow
(
m_engine
,
QML_VIEW_CALLS_WINDOW
);
m_settings_window
=
createSubWindow
(
m_engine
,
QML_VIEW_SETTINGS_WINDOW
);
m_calls_window
=
createSubWindow
(
this
,
QML_VIEW_CALLS_WINDOW
);
m_settings_window
=
createSubWindow
(
this
,
QML_VIEW_SETTINGS_WINDOW
);
}
// -----------------------------------------------------------------------------
...
...
@@ -317,7 +339,7 @@ void App::setTrayIcon () {
QQuickWindow
*
root
=
getMainWindow
();
QMenu
*
menu
=
new
QMenu
();
m_
system_tray_icon
=
new
QSystemTrayIcon
(
root
);
QSystemTrayIcon
*
system_tray_icon
=
new
QSystemTrayIcon
(
root
);
// trayIcon: Right click actions.
QAction
*
quit_action
=
new
QAction
(
"Quit"
,
root
);
...
...
@@ -328,7 +350,7 @@ void App::setTrayIcon () {
// trayIcon: Left click actions.
root
->
connect
(
m_
system_tray_icon
,
&
QSystemTrayIcon
::
activated
,
[
root
](
system_tray_icon
,
&
QSystemTrayIcon
::
activated
,
[
root
](
QSystemTrayIcon
::
ActivationReason
reason
)
{
if
(
reason
==
QSystemTrayIcon
::
Trigger
)
{
...
...
@@ -345,10 +367,10 @@ void App::setTrayIcon () {
menu
->
addSeparator
();
menu
->
addAction
(
quit_action
);
m_
system_tray_icon
->
setContextMenu
(
menu
);
m_
system_tray_icon
->
setIcon
(
QIcon
(
WINDOW_ICON_PATH
));
m_
system_tray_icon
->
setToolTip
(
"Linphone"
);
m_
system_tray_icon
->
show
();
system_tray_icon
->
setContextMenu
(
menu
);
system_tray_icon
->
setIcon
(
QIcon
(
WINDOW_ICON_PATH
));
system_tray_icon
->
setToolTip
(
"Linphone"
);
system_tray_icon
->
show
();
}
// -----------------------------------------------------------------------------
...
...
@@ -376,8 +398,8 @@ QString App::getLocale () const {
// -----------------------------------------------------------------------------
void
App
::
quit
()
{
if
(
m_parser
.
isSet
(
"selftest"
))
{
if
(
m_parser
.
isSet
(
"selftest"
))
cout
<<
tr
(
"selftestResult"
).
toStdString
()
<<
endl
;
}
Q
Core
Application
::
quit
();
QApplication
::
quit
();
}
linphone-desktop/src/app/App.hpp
View file @
16ae7c20
...
...
@@ -24,15 +24,11 @@
#define APP_H_
#include "../components/notifier/Notifier.hpp"
#include "AvatarProvider.hpp"
#include "ThumbnailProvider.hpp"
#include <QApplication>
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QQmlFileSelector>
#include <QQuickWindow>
#include <QSystemTrayIcon>
// =============================================================================
...
...
@@ -46,6 +42,9 @@ class App : public QApplication {
Q_PROPERTY
(
QVariantList
availableLocales
READ
getAvailableLocales
CONSTANT
);
public:
App
(
int
&
argc
,
char
**
argv
);
~
App
();
void
initContentApp
();
void
parseArgs
();
...
...
@@ -64,15 +63,8 @@ public:
Q_INVOKABLE
QQuickWindow
*
getSettingsWindow
()
const
;
static
void
create
(
int
&
argc
,
char
**
argv
)
{
if
(
!
m_instance
)
{
// Instance must be exists before content.
m_instance
=
new
App
(
argc
,
argv
);
}
}
static
App
*
getInstance
()
{
return
m_instance
;
return
static_cast
<
App
*>
(
QApplication
::
instance
())
;
}
public
slots
:
...
...
@@ -82,9 +74,6 @@ signals:
void
configLocaleChanged
(
const
QString
&
locale
);
private:
App
(
int
&
argc
,
char
**
argv
);
~
App
()
=
default
;
void
registerTypes
();
void
createSubWindows
();
void
setTrayIcon
();
...
...
@@ -100,11 +89,6 @@ private:
QCommandLineParser
m_parser
;
QQmlApplicationEngine
m_engine
;
QQmlFileSelector
*
m_file_selector
=
nullptr
;
QSystemTrayIcon
*
m_system_tray_icon
=
nullptr
;
AvatarProvider
m_avatar_provider
;
ThumbnailProvider
m_thumbnail_provider
;
DefaultTranslator
*
m_translator
=
nullptr
;
...
...
@@ -115,8 +99,6 @@ private:
QQuickWindow
*
m_calls_window
=
nullptr
;
QQuickWindow
*
m_settings_window
=
nullptr
;
static
App
*
m_instance
;
};
#endif // APP_H_
linphone-desktop/src/components/contact/VcardModel.cpp
View file @
16ae7c20
...
...
@@ -27,6 +27,7 @@
#include <QUuid>
#include "../../app/App.hpp"
#include "../../app/AvatarProvider.hpp"
#include "../../app/Paths.hpp"
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
...
...
linphone-desktop/src/components/core/CoreHandlers.cpp
View file @
16ae7c20
...
...
@@ -62,3 +62,12 @@ void CoreHandlers::onMessageReceived (
if
(
!
app
->
hasFocus
())
app
->
getNotifier
()
->
notifyReceivedMessage
(
message
);
}
void
CoreHandlers
::
onRegistrationStateChanged
(
const
shared_ptr
<
linphone
::
Core
>
&
core
,
const
shared_ptr
<
linphone
::
ProxyConfig
>
&
config
,
linphone
::
RegistrationState
state
,
const
string
&
message
)
{
// TODO.
}
linphone-desktop/src/components/core/CoreHandlers.hpp
View file @
16ae7c20
...
...
@@ -56,6 +56,13 @@ private:
const
std
::
shared_ptr
<
linphone
::
ChatRoom
>
&
room
,
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
override
;
void
onRegistrationStateChanged
(
const
std
::
shared_ptr
<
linphone
::
Core
>
&
core
,
const
std
::
shared_ptr
<
linphone
::
ProxyConfig
>
&
config
,
linphone
::
RegistrationState
state
,
const
std
::
string
&
message
)
override
;
};
#endif // CORE_HANDLERS_H_
linphone-desktop/src/components/core/CoreManager.cpp
View file @
16ae7c20
...
...
@@ -35,10 +35,10 @@ using namespace std;
CoreManager
*
CoreManager
::
m_instance
=
nullptr
;
CoreManager
::
CoreManager
(
const
QString
&
configPath
,
QObject
*
parent
)
:
QObject
(
parent
),
m_handlers
(
make_shared
<
CoreHandlers
>
())
{
CoreManager
::
CoreManager
(
QObject
*
parent
,
const
QString
&
config_path
)
:
QObject
(
parent
),
m_handlers
(
make_shared
<
CoreHandlers
>
())
{
setResourcesPaths
();
m_core
=
linphone
::
Factory
::
get
()
->
createCore
(
m_handlers
,
Paths
::
getConfigFilepath
(
config
P
ath
),
""
);
m_core
=
linphone
::
Factory
::
get
()
->
createCore
(
m_handlers
,
Paths
::
getConfigFilepath
(
config
_p
ath
),
""
);
m_core
->
setVideoDisplayFilter
(
"MSOGL"
);
m_core
->
usePreviewWindow
(
true
);
...
...
@@ -50,9 +50,9 @@ void CoreManager::enableHandlers () {
m_cbs_timer
->
start
();
}
void
CoreManager
::
init
(
const
QString
&
configP
ath
)
{
void
CoreManager
::
init
(
QObject
*
parent
,
const
QString
&
config_p
ath
)
{
if
(
!
m_instance
)
{
m_instance
=
new
CoreManager
(
configP
ath
);
m_instance
=
new
CoreManager
(
parent
,
config_p
ath
);
m_instance
->
m_calls_list_model
=
new
CallsListModel
(
m_instance
);
m_instance
->
m_contacts_list_model
=
new
ContactsListModel
(
m_instance
);
...
...
linphone-desktop/src/components/core/CoreManager.hpp
View file @
16ae7c20
...
...
@@ -73,7 +73,7 @@ public:
// Initialization.
// ---------------------------------------------------------------------------
static
void
init
(
const
QString
&
configP
ath
);
static
void
init
(
QObject
*
parent
,
const
QString
&
config_p
ath
);
static
CoreManager
*
getInstance
()
{
return
m_instance
;
...
...
@@ -86,7 +86,7 @@ public:
Q_INVOKABLE
VcardModel
*
createDetachedVcardModel
();
private:
CoreManager
(
const
QString
&
configPath
,
QObject
*
parent
=
Q_NULLPTR
);
CoreManager
(
QObject
*
parent
,
const
QString
&
config_path
);
void
setDatabasesPaths
();
void
setResourcesPaths
();
...
...
linphone-desktop/src/main.cpp
View file @
16ae7c20
...
...
@@ -20,9 +20,12 @@
* Author: Ronan Abhamon
*/
#include <iostream>
#include "app/App.hpp"
#include "app/Logger.hpp"
using
namespace
std
;
// =============================================================================
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -42,12 +45,11 @@ int main (int argc, char *argv[]) {
* QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
*/
App
::
create
(
argc
,
argv
);
App
app
(
argc
,
argv
);
App
*
app
=
App
::
getInstance
();
app
->
parseArgs
();
app
->
initContentApp
();
app
.
parseArgs
();
app
.
initContentApp
();
// Run!
return
app
->
exec
();
return
app
.
exec
();
}
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