Commit 41e92823 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/app/App): avoid memory leaks (system tray icon, qml file selector)

parent 9d1f1d37
......@@ -90,6 +90,7 @@ App::~App () {
qInfo() << "Destroying app...";
delete m_calls_window;
delete m_settings_window;
delete m_system_tray_icon;
}
// -----------------------------------------------------------------------------
......@@ -100,11 +101,7 @@ void App::initContentApp () {
qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors();
// Provide `+custom` folders for custom components.
{
QQmlFileSelector *file_selector = new QQmlFileSelector(&m_engine);
file_selector = new QQmlFileSelector(&m_engine);
file_selector->setExtraSelectors(QStringList("custom"));
}
(new QQmlFileSelector(&m_engine, this))->setExtraSelectors(QStringList("custom"));
// Set modules paths.
m_engine.addImportPath(":/ui/modules");
......@@ -332,10 +329,8 @@ void App::registerTypes () {
// -----------------------------------------------------------------------------
void App::setTrayIcon () {
QSystemTrayIcon *m_system_tray_icon = new QSystemTrayIcon();
QQuickWindow *root = getMainWindow();
QMenu *menu = new QMenu();
QSystemTrayIcon *system_tray_icon = new QSystemTrayIcon(root);
// trayIcon: Right click actions.
QAction *quit_action = new QAction("Quit", root);
......@@ -345,8 +340,9 @@ void App::setTrayIcon () {
root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal);
// trayIcon: Left click actions.
QMenu *menu = new QMenu();
root->connect(
system_tray_icon, &QSystemTrayIcon::activated, [root](
m_system_tray_icon, &QSystemTrayIcon::activated, [root](
QSystemTrayIcon::ActivationReason reason
) {
if (reason == QSystemTrayIcon::Trigger) {
......@@ -363,10 +359,10 @@ void App::setTrayIcon () {
menu->addSeparator();
menu->addAction(quit_action);
system_tray_icon->setContextMenu(menu);
system_tray_icon->setIcon(QIcon(WINDOW_ICON_PATH));
system_tray_icon->setToolTip("Linphone");
system_tray_icon->show();
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();
}
// -----------------------------------------------------------------------------
......
......@@ -33,6 +33,7 @@
// =============================================================================
class DefaultTranslator;
class QSystemTrayIcon;
class App : public SingleApplication {
Q_OBJECT;
......@@ -100,6 +101,8 @@ private:
QQuickWindow *m_calls_window = nullptr;
QQuickWindow *m_settings_window = nullptr;
QSystemTrayIcon *m_system_tray_icon = nullptr;
};
#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