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
4ef9e4c7
Commit
4ef9e4c7
authored
Nov 14, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): move code from `main.cpp` in `app/App.xpp`
parent
8c723cdc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
123 deletions
+124
-123
App.cpp
tests/src/app/App.cpp
+114
-6
App.hpp
tests/src/app/App.hpp
+10
-0
main.cpp
tests/src/main.cpp
+0
-117
No files found.
tests/src/app/App.cpp
View file @
4ef9e4c7
#include <cstdlib>
#include <QIcon>
#include <QMenu>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQuickView>
#include <QSystemTrayIcon>
#include <QtDebug>
#include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/linphone/LinphoneCore.hpp"
#include "../components/notification/Notification.hpp"
#include "../components/settings/AccountSettingsModel.hpp"
#include "../components/timeline/TimelineModel.hpp"
#include "App.hpp"
#define LANGUAGES_PATH ":/languages/"
#define WINDOW_ICON_PATH ":/assets/images/linphone.png"
// ===================================================================
...
...
@@ -13,10 +22,109 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
// Try to use default locale. Otherwise use english.
if
(
m_translator
.
load
(
QString
(
LANGUAGES_PATH
)
+
QLocale
::
system
().
name
())
||
m_translator
.
load
(
LANGUAGES_PATH
"en"
))
{
this
->
installTranslator
(
&
m_translator
);
installTranslator
(
&
m_translator
);
}
else
{
qWarning
(
)
<<
"No translation found."
;
qWarning
(
"No translation found."
)
;
}
this
->
setWindowIcon
(
QIcon
(
":/assets/images/linphone.png"
));
setWindowIcon
(
QIcon
(
WINDOW_ICON_PATH
));
// Provide `+custom` folders for custom components.
m_file_selector
=
new
QQmlFileSelector
(
&
m_engine
);
m_file_selector
->
setExtraSelectors
(
QStringList
(
"custom"
));
// Set modules paths.
m_engine
.
addImportPath
(
":/ui/modules"
);
m_engine
.
addImportPath
(
":/ui/scripts"
);
m_engine
.
addImportPath
(
":/ui/views"
);
// Register types and load context properties.
registerTypes
();
addContextProperties
();
// Load main view.
m_engine
.
load
(
QUrl
(
"qrc:/ui/views/App/MainWindow/MainWindow.qml"
));
if
(
m_engine
.
rootObjects
().
isEmpty
())
qFatal
(
"Unable to open main window."
);
// Enable TrayIconSystem.
if
(
!
QSystemTrayIcon
::
isSystemTrayAvailable
())
qWarning
(
"System tray not found on this system."
);
else
setTrayIcon
();
}
// -------------------------------------------------------------------
void
App
::
registerTypes
()
{
qmlRegisterUncreatableType
<
Presence
>
(
"Linphone"
,
1
,
0
,
"Presence"
,
"Presence is uncreatable"
);
ContactsListProxyModel
::
initContactsListModel
(
new
ContactsListModel
());
qmlRegisterType
<
ContactsListProxyModel
>
(
"Linphone"
,
1
,
0
,
"ContactsListProxyModel"
);
// Expose the static functions of ContactsListModel.
qmlRegisterSingletonType
<
ContactsListModel
>
(
"Linphone"
,
1
,
0
,
"ContactsListModel"
,
[](
QQmlEngine
*
engine
,
QJSEngine
*
scriptEngine
)
->
QObject
*
{
Q_UNUSED
(
engine
);
Q_UNUSED
(
scriptEngine
);
return
ContactsListProxyModel
::
getContactsListModel
();
}
);
}
void
App
::
addContextProperties
()
{
QQmlContext
*
context
=
m_engine
.
rootContext
();
QQmlComponent
component
(
&
m_engine
,
QUrl
(
"qrc:/ui/views/App/Calls/Calls.qml"
));
// Windows.
if
(
component
.
isError
())
{
qWarning
()
<<
component
.
errors
();
}
else
{
// context->setContextProperty("CallsWindow", component.create());
}
// Models.
context
->
setContextProperty
(
"AccountSettingsModel"
,
new
AccountSettingsModel
());
context
->
setContextProperty
(
"TimelineModel"
,
new
TimelineModel
());
// Other.
context
->
setContextProperty
(
"LinphoneCore"
,
LinphoneCore
::
getInstance
());
context
->
setContextProperty
(
"Notification"
,
new
Notification
());
}
void
App
::
setTrayIcon
()
{
QQuickWindow
*
root
=
qobject_cast
<
QQuickWindow
*>
(
m_engine
.
rootObjects
().
at
(
0
));
QMenu
*
menu
=
new
QMenu
();
QSystemTrayIcon
*
tray_icon
=
new
QSystemTrayIcon
(
root
);
// trayIcon: Right click actions.
QAction
*
quit_action
=
new
QAction
(
"Quit"
,
root
);
root
->
connect
(
quit_action
,
&
QAction
::
triggered
,
qApp
,
&
QCoreApplication
::
quit
);
QAction
*
restore_action
=
new
QAction
(
"Restore"
,
root
);
root
->
connect
(
restore_action
,
&
QAction
::
triggered
,
root
,
&
QQuickWindow
::
showNormal
);
// trayIcon: Left click actions.
root
->
connect
(
tray_icon
,
&
QSystemTrayIcon
::
activated
,
[
root
](
QSystemTrayIcon
::
ActivationReason
reason
)
{
if
(
reason
==
QSystemTrayIcon
::
Trigger
)
{
if
(
root
->
visibility
()
==
QWindow
::
Hidden
)
root
->
showNormal
();
else
root
->
hide
();
}
});
// Build trayIcon menu.
menu
->
addAction
(
restore_action
);
menu
->
addSeparator
();
menu
->
addAction
(
quit_action
);
tray_icon
->
setContextMenu
(
menu
);
tray_icon
->
setIcon
(
QIcon
(
WINDOW_ICON_PATH
));
tray_icon
->
setToolTip
(
"Linphone"
);
tray_icon
->
show
();
}
tests/src/app/App.hpp
View file @
4ef9e4c7
...
...
@@ -2,14 +2,24 @@
#define APP_H_
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlFileSelector>
#include <QTranslator>
// ===================================================================
class
App
:
public
QApplication
{
public:
App
(
int
&
argc
,
char
**
argv
);
virtual
~
App
()
{}
private:
void
registerTypes
();
void
addContextProperties
();
void
setTrayIcon
();
QQmlApplicationEngine
m_engine
;
QQmlFileSelector
*
m_file_selector
;
QTranslator
m_translator
;
};
...
...
tests/src/main.cpp
View file @
4ef9e4c7
#include <QMenu>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlFileSelector>
#include <QQuickView>
#include <QSystemTrayIcon>
#include <QtDebug>
#include "app/App.hpp"
#include "app/Logger.hpp"
#include "components/contacts/ContactsListProxyModel.hpp"
#include "components/linphone/LinphoneCore.hpp"
#include "components/notification/Notification.hpp"
#include "components/settings/AccountSettingsModel.hpp"
#include "components/timeline/TimelineModel.hpp"
// ===================================================================
void
setTrayIcon
(
QQmlApplicationEngine
&
engine
)
{
QQuickWindow
*
root
=
qobject_cast
<
QQuickWindow
*>
(
engine
.
rootObjects
().
at
(
0
));
QMenu
*
menu
=
new
QMenu
();
QSystemTrayIcon
*
tray_icon
=
new
QSystemTrayIcon
(
root
);
// trayIcon: Right click actions.
QAction
*
quit_action
=
new
QAction
(
"Quit"
,
root
);
root
->
connect
(
quit_action
,
&
QAction
::
triggered
,
qApp
,
&
QCoreApplication
::
quit
);
QAction
*
restore_action
=
new
QAction
(
"Restore"
,
root
);
root
->
connect
(
restore_action
,
&
QAction
::
triggered
,
root
,
&
QQuickWindow
::
showNormal
);
// trayIcon: Left click actions.
root
->
connect
(
tray_icon
,
&
QSystemTrayIcon
::
activated
,
[
root
](
QSystemTrayIcon
::
ActivationReason
reason
)
{
if
(
reason
==
QSystemTrayIcon
::
Trigger
)
{
if
(
root
->
visibility
()
==
QWindow
::
Hidden
)
root
->
showNormal
();
else
root
->
hide
();
}
});
// Build trayIcon menu.
menu
->
addAction
(
restore_action
);
menu
->
addSeparator
();
menu
->
addAction
(
quit_action
);
tray_icon
->
setContextMenu
(
menu
);
tray_icon
->
setIcon
(
QIcon
(
":/assets/images/linphone.png"
));
tray_icon
->
setToolTip
(
"Linphone"
);
tray_icon
->
show
();
}
void
registerTypes
()
{
qmlRegisterUncreatableType
<
Presence
>
(
"Linphone"
,
1
,
0
,
"Presence"
,
"Presence is uncreatable"
);
ContactsListProxyModel
::
initContactsListModel
(
new
ContactsListModel
());
qmlRegisterType
<
ContactsListProxyModel
>
(
"Linphone"
,
1
,
0
,
"ContactsListProxyModel"
);
// Expose the static functions of ContactsListModel.
qmlRegisterSingletonType
<
ContactsListModel
>
(
"Linphone"
,
1
,
0
,
"ContactsListModel"
,
[](
QQmlEngine
*
engine
,
QJSEngine
*
scriptEngine
)
->
QObject
*
{
Q_UNUSED
(
engine
);
Q_UNUSED
(
scriptEngine
);
return
ContactsListProxyModel
::
getContactsListModel
();
}
);
}
void
addContextProperties
(
QQmlApplicationEngine
&
engine
)
{
QQmlContext
*
context
=
engine
.
rootContext
();
QQmlComponent
component
(
&
engine
,
QUrl
(
"qrc:/ui/views/App/Calls/Calls.qml"
));
// Windows.
if
(
component
.
isError
())
{
qWarning
()
<<
component
.
errors
();
}
else
{
// context->setContextProperty("CallsWindow", component.create());
}
// Models.
context
->
setContextProperty
(
"AccountSettingsModel"
,
new
AccountSettingsModel
());
context
->
setContextProperty
(
"TimelineModel"
,
new
TimelineModel
());
// Other.
context
->
setContextProperty
(
"LinphoneCore"
,
LinphoneCore
::
getInstance
());
context
->
setContextProperty
(
"Notification"
,
new
Notification
());
}
// ===================================================================
int
main
(
int
argc
,
char
*
argv
[])
{
qInstallMessageHandler
(
qmlLogger
);
registerTypes
();
QGuiApplication
::
setAttribute
(
Qt
::
AA_EnableHighDpiScaling
);
App
app
(
argc
,
argv
);
QQmlApplicationEngine
engine
;
// Provide `+custom` folders for custom components.
QQmlFileSelector
*
selector
=
new
QQmlFileSelector
(
&
engine
);
selector
->
setExtraSelectors
(
QStringList
(
"custom"
));
// Set modules paths.
engine
.
addImportPath
(
":/ui/modules"
);
engine
.
addImportPath
(
":/ui/scripts"
);
engine
.
addImportPath
(
":/ui/views"
);
// Load context properties.
addContextProperties
(
engine
);
// Load main view.
engine
.
load
(
QUrl
(
"qrc:/ui/views/App/MainWindow/MainWindow.qml"
));
if
(
engine
.
rootObjects
().
isEmpty
())
{
qWarning
()
<<
"Unable to open main window."
;
return
EXIT_FAILURE
;
}
// Enable TrayIconSystem.
if
(
!
QSystemTrayIcon
::
isSystemTrayAvailable
())
qWarning
()
<<
"System tray not found on this system."
;
else
setTrayIcon
(
engine
);
// Run!
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