Commit a14c2657 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/app/App): do not delete explicitly calls/settings windows, set parent to tray icon

parent 206f31c3
...@@ -88,9 +88,6 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true) { ...@@ -88,9 +88,6 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true) {
App::~App () { App::~App () {
qInfo() << "Destroying app..."; qInfo() << "Destroying app...";
delete m_calls_window;
delete m_settings_window;
delete m_system_tray_icon;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -221,10 +218,11 @@ inline QQuickWindow *createSubWindow (App *app, const char *path) { ...@@ -221,10 +218,11 @@ inline QQuickWindow *createSubWindow (App *app, const char *path) {
abort(); abort();
} }
QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create()); QObject *object = component.create();
QQmlEngine::setObjectOwnership(window, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
object->setParent(app->getMainWindow());
return window; return qobject_cast<QQuickWindow *>(object);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -329,8 +327,8 @@ void App::registerTypes () { ...@@ -329,8 +327,8 @@ void App::registerTypes () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void App::setTrayIcon () { void App::setTrayIcon () {
QSystemTrayIcon *m_system_tray_icon = new QSystemTrayIcon();
QQuickWindow *root = getMainWindow(); QQuickWindow *root = getMainWindow();
QSystemTrayIcon *system_tray_icon = new QSystemTrayIcon(root);
// trayIcon: Right click actions. // trayIcon: Right click actions.
QAction *quit_action = new QAction("Quit", root); QAction *quit_action = new QAction("Quit", root);
...@@ -342,7 +340,7 @@ void App::setTrayIcon () { ...@@ -342,7 +340,7 @@ void App::setTrayIcon () {
// trayIcon: Left click actions. // trayIcon: Left click actions.
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
root->connect( root->connect(
m_system_tray_icon, &QSystemTrayIcon::activated, [root]( system_tray_icon, &QSystemTrayIcon::activated, [root](
QSystemTrayIcon::ActivationReason reason QSystemTrayIcon::ActivationReason reason
) { ) {
if (reason == QSystemTrayIcon::Trigger) { if (reason == QSystemTrayIcon::Trigger) {
...@@ -359,10 +357,10 @@ void App::setTrayIcon () { ...@@ -359,10 +357,10 @@ void App::setTrayIcon () {
menu->addSeparator(); menu->addSeparator();
menu->addAction(quit_action); menu->addAction(quit_action);
m_system_tray_icon->setContextMenu(menu); system_tray_icon->setContextMenu(menu);
m_system_tray_icon->setIcon(QIcon(WINDOW_ICON_PATH)); system_tray_icon->setIcon(QIcon(WINDOW_ICON_PATH));
m_system_tray_icon->setToolTip("Linphone"); system_tray_icon->setToolTip("Linphone");
m_system_tray_icon->show(); system_tray_icon->show();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
// ============================================================================= // =============================================================================
class DefaultTranslator; class DefaultTranslator;
class QSystemTrayIcon;
class App : public SingleApplication { class App : public SingleApplication {
Q_OBJECT; Q_OBJECT;
...@@ -101,8 +100,6 @@ private: ...@@ -101,8 +100,6 @@ private:
QQuickWindow *m_calls_window = nullptr; QQuickWindow *m_calls_window = nullptr;
QQuickWindow *m_settings_window = nullptr; QQuickWindow *m_settings_window = nullptr;
QSystemTrayIcon *m_system_tray_icon = nullptr;
}; };
#endif // APP_H_ #endif // APP_H_
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