Commit bdb6f441 authored by Ming Rui Zhang's avatar Ming Rui Zhang

systemtrayicon: jump between accounts once receiving notifications from other accounts

Change-Id: I7682b6f5368a7030f6fa294cc428e70da50aae37
parent a1e5b845
......@@ -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)
......
......@@ -62,6 +62,10 @@ public:
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
signals:
void slotAccountChangedFinished();
public slots:
virtual void slotAccountListChanged();
......
......@@ -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_;
}
......@@ -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_;
};
......@@ -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);
......
......@@ -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);
}
......
......@@ -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();
......
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