mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-22 06:08:07 +00:00
feat(src/app/App): create calls/settings windows only when it's requested
This commit is contained in:
parent
3de094165f
commit
c8e57bc7ed
2 changed files with 39 additions and 43 deletions
|
|
@ -156,9 +156,6 @@ void App::initContentApp () {
|
|||
core->setParent(this);
|
||||
}
|
||||
|
||||
// Create sub windows.
|
||||
createSubWindows();
|
||||
|
||||
// Load main view.
|
||||
qInfo() << "Loading main view...";
|
||||
m_engine.load(QUrl(QML_VIEW_MAIN_WINDOW));
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -225,14 +242,28 @@ QQuickWindow *App::getMainWindow () const {
|
|||
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;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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 () {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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 () {
|
||||
QQuickWindow *root = getMainWindow();
|
||||
QMenu *menu = new QMenu();
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ public:
|
|||
return m_notifier;
|
||||
}
|
||||
|
||||
QQuickWindow *getCallsWindow () const;
|
||||
QQuickWindow *getCallsWindow ();
|
||||
QQuickWindow *getMainWindow () const;
|
||||
|
||||
bool hasFocus () const;
|
||||
|
||||
Q_INVOKABLE QQuickWindow *getSettingsWindow () const;
|
||||
Q_INVOKABLE QQuickWindow *getSettingsWindow ();
|
||||
|
||||
static App *getInstance () {
|
||||
return static_cast<App *>(QApplication::instance());
|
||||
|
|
@ -76,7 +76,6 @@ signals:
|
|||
|
||||
private:
|
||||
void registerTypes ();
|
||||
void createSubWindows ();
|
||||
void setTrayIcon ();
|
||||
|
||||
QString getConfigLocale () const;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue