diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 44e7caca1..d3df558a3 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -1099,28 +1099,30 @@ bool App::notify(QObject *receiver, QEvent *event) { return done; } +void App::handleAccountActivity(QSharedPointer accountCore) { + if (!accountCore) return; + auto accountPresence = accountCore->getPresence(); + if ((mMainWindow && mMainWindow->isActive() || (mCallsWindow && mCallsWindow->isActive())) && + accountPresence == LinphoneEnums::Presence::Away) { + accountCore->lSetPresence(LinphoneEnums::Presence::Online, false); + } else if (((!mMainWindow || !mMainWindow->isActive() || !mMainWindow->isVisible()) && + (!mCallsWindow || !mCallsWindow->isActive() || !mCallsWindow->isVisible())) && + accountPresence == LinphoneEnums::Presence::Online) { + accountCore->lSetPresence(LinphoneEnums::Presence::Away, false); + } +} + void App::handleAppActivity() { - auto handle = [this](QSharedPointer accountCore) { - if (!accountCore) return; - auto accountPresence = accountCore->getPresence(); - if ((mMainWindow && mMainWindow->isActive() || (mCallsWindow && mCallsWindow->isActive())) && - accountPresence == LinphoneEnums::Presence::Away) - accountCore->lSetPresence(LinphoneEnums::Presence::Online, false); - else if (((!mMainWindow || !mMainWindow->isActive() || !mMainWindow->isVisible()) && - (!mCallsWindow || !mCallsWindow->isActive() || !mCallsWindow->isVisible())) && - accountPresence == LinphoneEnums::Presence::Online) - accountCore->lSetPresence(LinphoneEnums::Presence::Away, false); - }; if (mAccountList) { for (auto &account : mAccountList->getSharedList()) - handle(account); + handleAccountActivity(account); } else { connect( this, &App::accountsChanged, this, - [this, &handle] { + [this] { if (mAccountList) { for (auto &account : mAccountList->getSharedList()) - handle(account); + handleAccountActivity(account); } }, Qt::SingleShotConnection); @@ -1441,12 +1443,12 @@ bool App::event(QEvent *event) { } else if (event->type() == QEvent::ApplicationActivate) { for (int i = 0; i < getAccountList()->rowCount(); ++i) { auto accountCore = getAccountList()->getAt(i); - emit accountCore->lSetPresence(LinphoneEnums::Presence::Online, false, false); + handleAccountActivity(accountCore); } } else if (event->type() == QEvent::ApplicationDeactivate) { for (int i = 0; i < getAccountList()->rowCount(); ++i) { auto accountCore = getAccountList()->getAt(i); - emit accountCore->lSetPresence(LinphoneEnums::Presence::Away, false, false); + handleAccountActivity(accountCore); } } diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index f699856de..8de4ce16f 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -145,6 +145,7 @@ public: void setCoreStarted(bool started); QQuickWindow *getCallsWindow(); + void handleAccountActivity(QSharedPointer accountCore); Q_INVOKABLE void handleAppActivity(); QQuickWindow *getOrCreateCallsWindow(QVariant callGui = QVariant()); void setCallsWindowProperty(const char *id, QVariant property);