1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(notification): implement review comments

This commit is contained in:
sudden6 2019-03-22 17:55:27 +01:00
parent 9f8d0915f2
commit cd50376c2f
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
5 changed files with 20 additions and 68 deletions

View File

@ -188,7 +188,7 @@ void Settings::loadGlobal()
{ {
showWindow = s.value("showWindow", true).toBool(); showWindow = s.value("showWindow", true).toBool();
notify = s.value("notify", true).toBool(); notify = s.value("notify", true).toBool();
desktopNotify = s.value("desktopNotify", false).toBool(); desktopNotify = s.value("desktopNotify", true).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool(); groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool();
separateWindow = s.value("separateWindow", false).toBool(); separateWindow = s.value("separateWindow", false).toBool();

View File

@ -19,85 +19,37 @@ DesktopNotify::DesktopNotify()
notifyCore.registerApplication(snoreApp); notifyCore.registerApplication(snoreApp);
} }
DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& title, void DesktopNotify::createNotification(const QString& title)
const QString& text,
Snore::Notification* old)
{ {
if (old == nullptr) { const Settings& s = Settings::getInstance();
return NotificationPtr( if(!(s.getNotify() && s.getDesktopNotify())) {
new Snore::Notification(snoreApp, Snore::Alert(), title, text, snoreIcon)); return;
} else {
return NotificationPtr(new Snore::Notification(*old, title, text, snoreIcon));
} }
Snore::Notification notify{snoreApp, Snore::Alert(), title, {}, snoreIcon};
notifyCore.broadcastNotification(notify);
} }
void DesktopNotify::notifyGroupMessage() void DesktopNotify::notifyGroupMessage()
{ {
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}
const QString text{};
const QString title = tr("New group message received"); const QString title = tr("New group message received");
NotificationPtr newNote = createNotification(title, text); createNotification(title);
if (!newNote) {
qDebug() << "Failed to allocate group message notification";
return;
}
groupInvite = std::move(newNote);
} }
void DesktopNotify::notifyFriendRequest() void DesktopNotify::notifyFriendRequest()
{ {
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}
const QString title = tr("New friend request received"); const QString title = tr("New friend request received");
const QString text{}; createNotification(title);
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
} }
void DesktopNotify::notifyGroupInvite() void DesktopNotify::notifyGroupInvite()
{ {
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}
const QString title = tr("New group invite received"); const QString title = tr("New group invite received");
const QString text{}; createNotification(title);
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
} }
void DesktopNotify::notifyFriendMessage() void DesktopNotify::notifyFriendMessage()
{ {
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}
const QString title = tr("New message received"); const QString title = tr("New message received");
const QString text{}; createNotification(title);
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
} }

View File

@ -19,17 +19,10 @@ public slots:
void notifyGroupInvite(); void notifyGroupInvite();
private: private:
using NotificationPtr = std::unique_ptr<Snore::Notification>; void createNotification(const QString& title);
NotificationPtr createNotification(const QString& title, const QString& text,
Snore::Notification* old = nullptr);
private: private:
Snore::SnoreCore& notifyCore; Snore::SnoreCore& notifyCore;
NotificationPtr groupInvite = {nullptr};
NotificationPtr groupMessage = {nullptr};
NotificationPtr friendRequest = {nullptr};
NotificationPtr friendMessage = {nullptr};
Snore::Application snoreApp; Snore::Application snoreApp;
Snore::Icon snoreIcon; Snore::Icon snoreIcon;
}; };

View File

@ -275,6 +275,7 @@ void UserInterfaceForm::on_notify_stateChanged()
bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(notify); bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(notify);
bodyUI->notifySound->setEnabled(notify); bodyUI->notifySound->setEnabled(notify);
bodyUI->busySound->setEnabled(notify && bodyUI->notifySound->isChecked()); bodyUI->busySound->setEnabled(notify && bodyUI->notifySound->isChecked());
bodyUI->desktopNotify->setEnabled(notify);
} }
void UserInterfaceForm::on_notifySound_stateChanged() void UserInterfaceForm::on_notifySound_stateChanged()

View File

@ -1446,7 +1446,13 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound,
if (settings.getNotify()) { if (settings.getNotify()) {
if (inactiveWindow) { if (inactiveWindow) {
#if DESKTOP_NOTIFICATIONS
if (!settings.getDesktopNotify()) {
QApplication::alert(currentWindow);
}
#else
QApplication::alert(currentWindow); QApplication::alert(currentWindow);
#endif
eventFlag = true; eventFlag = true;
} }
bool isBusy = Nexus::getCore()->getStatus() == Status::Busy; bool isBusy = Nexus::getCore()->getStatus() == Status::Busy;