Commit c8e57bc7 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/app/App): create calls/settings windows only when it's requested

parent 3de09416
...@@ -156,9 +156,6 @@ void App::initContentApp () { ...@@ -156,9 +156,6 @@ void App::initContentApp () {
core->setParent(this); core->setParent(this);
} }
// Create sub windows.
createSubWindows();
// Load main view. // Load main view.
qInfo() << "Loading main view..."; qInfo() << "Loading main view...";
m_engine.load(QUrl(QML_VIEW_MAIN_WINDOW)); m_engine.load(QUrl(QML_VIEW_MAIN_WINDOW));
...@@ -216,7 +213,27 @@ void App::parseArgs () { ...@@ -216,7 +213,27 @@ void App::parseArgs () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QQuickWindow *App::getCallsWindow () const { inline QQuickWindow *createSubWindow (App *app, const char *path) {
QQmlEngine *engine = app->getEngine();
QQmlComponent component(engine, QUrl(path));
if (component.isError()) {
qWarning() << component.errors();
abort();
}
QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create());
QQmlEngine::setObjectOwnership(window, QQmlEngine::CppOwnership);
return window;
}
// -----------------------------------------------------------------------------
QQuickWindow *App::getCallsWindow () {
if (!m_calls_window)
m_calls_window = createSubWindow(this, QML_VIEW_CALLS_WINDOW);
return m_calls_window; return m_calls_window;
} }
...@@ -225,14 +242,28 @@ QQuickWindow *App::getMainWindow () const { ...@@ -225,14 +242,28 @@ QQuickWindow *App::getMainWindow () const {
return qobject_cast<QQuickWindow *>(engine.rootObjects().at(0)); return qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
} }
QQuickWindow *App::getSettingsWindow () const { QQuickWindow *App::getSettingsWindow () {
if (!m_settings_window) {
m_settings_window = createSubWindow(this, QML_VIEW_SETTINGS_WINDOW);
QObject::connect(
m_settings_window, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) {
if (visibility == QWindow::Hidden) {
qInfo() << "Update nat policy.";
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
core->setNatPolicy(core->getNatPolicy());
}
}
);
}
return m_settings_window; return m_settings_window;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool App::hasFocus () const { bool App::hasFocus () const {
return getMainWindow()->isActive() || m_calls_window->isActive(); return getMainWindow()->isActive() || (m_calls_window && m_calls_window->isActive());
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -334,40 +365,6 @@ void App::registerTypes () { ...@@ -334,40 +365,6 @@ void App::registerTypes () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
inline QQuickWindow *createSubWindow (App *app, const char *path) {
QQmlEngine *engine = app->getEngine();
QQmlComponent component(engine, QUrl(path));
if (component.isError()) {
qWarning() << component.errors();
abort();
}
QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create());
QQmlEngine::setObjectOwnership(window, QQmlEngine::CppOwnership);
return window;
}
void App::createSubWindows () {
qInfo() << "Create sub windows...";
m_calls_window = createSubWindow(this, QML_VIEW_CALLS_WINDOW);
m_settings_window = createSubWindow(this, QML_VIEW_SETTINGS_WINDOW);
QObject::connect(
m_settings_window, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) {
if (visibility == QWindow::Hidden) {
qInfo() << "Update nat policy.";
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
core->setNatPolicy(core->getNatPolicy());
}
}
);
}
// -----------------------------------------------------------------------------
void App::setTrayIcon () { void App::setTrayIcon () {
QQuickWindow *root = getMainWindow(); QQuickWindow *root = getMainWindow();
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
......
...@@ -57,12 +57,12 @@ public: ...@@ -57,12 +57,12 @@ public:
return m_notifier; return m_notifier;
} }
QQuickWindow *getCallsWindow () const; QQuickWindow *getCallsWindow ();
QQuickWindow *getMainWindow () const; QQuickWindow *getMainWindow () const;
bool hasFocus () const; bool hasFocus () const;
Q_INVOKABLE QQuickWindow *getSettingsWindow () const; Q_INVOKABLE QQuickWindow *getSettingsWindow ();
static App *getInstance () { static App *getInstance () {
return static_cast<App *>(QApplication::instance()); return static_cast<App *>(QApplication::instance());
...@@ -76,7 +76,6 @@ signals: ...@@ -76,7 +76,6 @@ signals:
private: private:
void registerTypes (); void registerTypes ();
void createSubWindows ();
void setTrayIcon (); void setTrayIcon ();
QString getConfigLocale () const; QString getConfigLocale () const;
......
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