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();
notify = s.value("notify", true).toBool();
desktopNotify = s.value("desktopNotify", false).toBool();
desktopNotify = s.value("desktopNotify", true).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
separateWindow = s.value("separateWindow", false).toBool();

View File

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

View File

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

View File

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

View File

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