diff --git a/src/callwidget.cpp b/src/callwidget.cpp index e5c7a97623dbc988536977302d1d3dd6cf594547..45b42b14648be9ca8f26aba3950368ca9c36dc00 100644 --- a/src/callwidget.cpp +++ b/src/callwidget.cpp @@ -278,6 +278,18 @@ CallWidget::navigated(bool to) if (index != -1) { slotAccountChanged(index); } + } else if (!GlobalSystemTray::instance().getTriggeredAccountId().isEmpty()) { + slotAccountChanged(accountList.indexOf(GlobalSystemTray::instance().getTriggeredAccountId())); + // one shot connect + Utils::oneShotConnect(this, &CallWidget::slotAccountChangedFinished, + [this] { + if (!GlobalSystemTray::instance().getPossibleOnGoingConversationInfo().callId.isEmpty()) { + slotShowIncomingCallView(GlobalSystemTray::instance().getTriggeredAccountId(), GlobalSystemTray::instance().getPossibleOnGoingConversationInfo()); + lrc::api::conversation::Info convInfo; + GlobalSystemTray::instance().setPossibleOnGoingConversationInfo(convInfo); + } + GlobalSystemTray::instance().setTriggeredAccountId(""); + }); } } catch (...) {} ui->currentAccountComboBox->updateComboBoxDisplay(); @@ -330,7 +342,7 @@ CallWidget::onNewInteraction(const QString& accountId, const QString& convUid, if (!interaction.authorUri.isEmpty() && (!QApplication::focusWidget() || LRCInstance::getCurrAccId() != accountId)) { auto bestName = Utils::bestNameForConversation(conversation, *convModel); - Utils::showSystemNotification(this, bestName,interaction.body); + Utils::showSystemNotification(this, bestName,interaction.body, 5000, accountId); } updateConversationsFilterWidget(); if (convUid != LRCInstance::getCurrentConvUid()) { @@ -668,12 +680,24 @@ void CallWidget::slotShowIncomingCallView(const QString& accountId, const conversation::Info& convInfo) { - Q_UNUSED(accountId); qDebug() << "slotShowIncomingCallView"; auto callModel = LRCInstance::getCurrentCallModel(); if (!callModel->hasCall(convInfo.callId)) { + auto convModel = LRCInstance::getAccountInfo(accountId).conversationModel.get(); + auto formattedName = Utils::bestNameForConversation(convInfo, *convModel); + if (GlobalSystemTray::instance().getTriggeredAccountId() != accountId) { + GlobalSystemTray::instance().setPossibleOnGoingConversationInfo(convInfo); + Utils::showSystemNotification( + this, + QString(tr("Call incoming from %1 to %2")) + .arg(formattedName) + .arg(Utils::bestNameForAccount(LRCInstance::getAccountInfo(accountId))), + 5000, + accountId + ); + } return; } @@ -696,7 +720,7 @@ CallWidget::slotShowIncomingCallView(const QString& accountId, setCallPanelVisibility(true); } } else { - if (!QApplication::focusWidget()) { + if (!QApplication::focusWidget() && GlobalSystemTray::instance().getTriggeredAccountId().isEmpty()) { auto formattedName = Utils::bestNameForConversation(convInfo, *convModel); Utils::showSystemNotification(this, QString(tr("Call incoming from %1")).arg(formattedName)); } @@ -763,7 +787,7 @@ CallWidget::slotNewTrustRequest(const QString& accountId, const QString& contact try { auto contactInfo = contactModel->getContact(contactUri); auto bestName = Utils::bestNameForContact(contactInfo); - Utils::showSystemNotification(this, bestName, QObject::tr("Contact request")); + Utils::showSystemNotification(this, bestName, QObject::tr("Contact request"), 5000, accountId); } catch (...) { qDebug() << "Can't get contact: ", contactUri; return; @@ -837,6 +861,7 @@ CallWidget::setSelectedAccount(const QString& accountId) updateConversationsFilterWidget(); connectConversationModel(); connectAccount(accountId); + emit slotAccountChangedFinished(); } void CallWidget::setConversationFilter(lrc::api::profile::Type filter) diff --git a/src/callwidget.h b/src/callwidget.h index d87a52ba7c7920c5a6e990296098a1e8f92b37ba..91b193d531213d57726e620ec761d42cf568964a 100644 --- a/src/callwidget.h +++ b/src/callwidget.h @@ -62,6 +62,10 @@ public: // NavWidget virtual void navigated(bool to); virtual void updateCustomUI(); + +signals: + void slotAccountChangedFinished(); + public slots: virtual void slotAccountListChanged(); diff --git a/src/globalsystemtray.cpp b/src/globalsystemtray.cpp index 54ba4dc52c41e08b4149b738a1ea092d6eb65cc5..439d7985fb10236162142d01285985181d1e664f 100644 --- a/src/globalsystemtray.cpp +++ b/src/globalsystemtray.cpp @@ -22,3 +22,26 @@ GlobalSystemTray::GlobalSystemTray() { } +void +GlobalSystemTray::setTriggeredAccountId(const QString& accountId) +{ + triggeredAccountId_ = accountId; +} + +const QString& +GlobalSystemTray::getTriggeredAccountId() +{ + return triggeredAccountId_; +} + +void +GlobalSystemTray::setPossibleOnGoingConversationInfo(const lrc::api::conversation::Info& convInfo) +{ + triggeredOnGoingConvInfo_ = convInfo; +} + +const lrc::api::conversation::Info& +GlobalSystemTray::getPossibleOnGoingConversationInfo() +{ + return triggeredOnGoingConvInfo_; +} diff --git a/src/globalsystemtray.h b/src/globalsystemtray.h index f74ef5cea6fc20e059c52f88a25b789908a1c291..bcaf57d0040b5bd9f8efc6806e063a85fb193a6d 100644 --- a/src/globalsystemtray.h +++ b/src/globalsystemtray.h @@ -18,6 +18,8 @@ #pragma once +#include "lrcinstance.h" + #include <QSystemTrayIcon> class GlobalSystemTray : public QSystemTrayIcon @@ -32,6 +34,19 @@ public: return *instance_; } + // remember the last triggering account for the notification + // safe since user cannot activate previous notifications + void setTriggeredAccountId(const QString& accountId); + + const QString& getTriggeredAccountId(); + + void setPossibleOnGoingConversationInfo(const lrc::api::conversation::Info& convInfo); + + const lrc::api::conversation::Info& getPossibleOnGoingConversationInfo(); + private: GlobalSystemTray(); + + QString triggeredAccountId_; + lrc::api::conversation::Info triggeredOnGoingConvInfo_; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b53ac7c3aedff4039c69dcde30562a16097d1175..a8d23af1f4f5c8878ba7b54f81a9cfd7f5c097a7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -298,6 +298,7 @@ MainWindow::lighten() void MainWindow::notificationClicked() { + // Note: this slot will only be triggered by the last notification if (auto currentWidget = dynamic_cast<NavWidget*>(ui->navStack->currentWidget())) { emit currentWidget->NavigationRequested(ScreenEnum::CallScreen); setWindowState(Qt::WindowActive); diff --git a/src/utils.cpp b/src/utils.cpp index 4253d666c142ce5dec946b52f544e84cdb5da191..c4322012fe75940deb28acde71cf34236a913e8f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -273,10 +273,14 @@ Utils::setStackWidget(QStackedWidget* stack, QWidget* widget) } } -void Utils::showSystemNotification(QWidget* widget, const QString& message, long delay) +void Utils::showSystemNotification(QWidget* widget, + const QString& message, + long delay, + const QString& triggeredAccountId) { QSettings settings("jami.net", "Jami"); if (settings.value(SettingsKey::enableNotifications).toBool()) { + GlobalSystemTray::instance().setTriggeredAccountId(triggeredAccountId); GlobalSystemTray::instance().showMessage(message, "", QIcon(":images/jami.png")); QApplication::alert(widget, delay); } @@ -285,10 +289,12 @@ void Utils::showSystemNotification(QWidget* widget, const QString& message, long void Utils::showSystemNotification(QWidget* widget, const QString & sender, const QString & message, - long delay) + long delay, + const QString& triggeredAccountId) { QSettings settings("jami.net", "Jami"); if (settings.value(SettingsKey::enableNotifications).toBool()) { + GlobalSystemTray::instance().setTriggeredAccountId(triggeredAccountId); GlobalSystemTray::instance().showMessage(sender, message, QIcon(":images/jami.png")); QApplication::alert(widget, delay); } diff --git a/src/utils.h b/src/utils.h index c9f4076fd64d8a468e867314c3e20f89b95126bf..b5710ad3e138b08ae47bffd989c4caa465bc3bcd 100644 --- a/src/utils.h +++ b/src/utils.h @@ -71,8 +71,8 @@ QString GenGUID(); QString GetISODate(); void InvokeMailto(const QString& subject, const QString& body, const QString& attachement = QString()); void setStackWidget(QStackedWidget *stack, QWidget *widget); -void showSystemNotification(QWidget* widget, const QString& message, long delay = 5000); -void showSystemNotification(QWidget* widget, const QString& sender, const QString& message, long delay = 5000); +void showSystemNotification(QWidget* widget, const QString& message, long delay = 5000, const QString& triggeredAccountId = ""); +void showSystemNotification(QWidget* widget, const QString& sender, const QString& message, long delay = 5000, const QString& triggeredAccountId = ""); QSize getRealSize(QScreen* screen); void forceDeleteAsync(const QString& path); QString getChangeLog();