Fix Quiet Mode

This commit is contained in:
Victor Tran 2017-09-15 12:27:32 +10:00
parent 9b8b16b6b0
commit d98a155465
3 changed files with 73 additions and 29 deletions

View file

@ -6,6 +6,9 @@
extern float getDPIScaling();
extern NotificationsDBusAdaptor* ndbus;
NotificationPopup* NotificationPopup::currentlyShowingPopup = NULL;
QList<NotificationPopup*> NotificationPopup::pendingPopups = QList<NotificationPopup*>();
NotificationPopup::NotificationPopup(int id, QWidget *parent) :
QDialog(parent),
ui(new Ui::NotificationPopup)
@ -38,6 +41,12 @@ NotificationPopup::~NotificationPopup()
}
void NotificationPopup::show() {
if (currentlyShowingPopup != NULL) {
currentlyShowingPopup->close();
emit currentlyShowingPopup->notificationClosed(NotificationObject::Undefined);
pendingPopups.append(this);
} else {
currentlyShowingPopup = this;
QRect screenGeometry = QApplication::desktop()->screenGeometry();
this->move(screenGeometry.topLeft().x(), screenGeometry.top() - this->height());
this->setFixedWidth(screenGeometry.width());
@ -67,6 +76,7 @@ void NotificationPopup::show() {
dismisser->start();
mouseEvents = true;
}
}
void NotificationPopup::close() {
@ -82,6 +92,11 @@ void NotificationPopup::close() {
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
connect(anim, &tPropertyAnimation::finished, [=] {
QDialog::close();
currentlyShowingPopup = NULL;
if (pendingPopups.count() > 0) {
pendingPopups.takeFirst()->show();
}
});
anim->start();
@ -209,7 +224,10 @@ void NotificationPopup::setActions(QStringList actions) {
button->setText(value);
connect(button, &QPushButton::clicked, [=] {
emit actionClicked(key);
if (!this->hints.value("resident", false).toBool()) {
this->close();
}
});
((QBoxLayout*) ui->actionsWidget->layout())->addWidget(button);

View file

@ -59,6 +59,9 @@ private:
int timeoutLeft;
QMap<QString, QString> actions;
QVariantMap hints;
static NotificationPopup* currentlyShowingPopup;
static QList<NotificationPopup*> pendingPopups;
};
#endif // NOTIFICATIONPOPUP_H

View file

@ -1,6 +1,10 @@
#include "notificationsdbusadaptor.h"
#include "notificationswidget.h"
#include "notificationobject.h"
#include "audiomanager.h"
#include "internationalisation.h"
extern AudioManager* AudioMan;
NotificationsDBusAdaptor::NotificationsDBusAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
@ -18,6 +22,8 @@ void NotificationsDBusAdaptor::CloseNotification(uint id)
if (this->parentWidget()->hasNotificationId(id)) {
NotificationObject* notification = this->parentWidget()->getNotification(id);
notification->dismiss();
} else {
}
}
@ -29,7 +35,7 @@ QStringList NotificationsDBusAdaptor::GetCapabilities()
QString NotificationsDBusAdaptor::GetServerInformation(QString &vendor, QString &version, QString &spec_version)
{
vendor = "theSuite";
version = "2.0";
version = TS_VERSION;
spec_version = "1.2";
return "theShell";
}
@ -45,7 +51,24 @@ uint NotificationsDBusAdaptor::Notify(const QString &app_name, uint replaces_id,
}
this->parentWidget()->addNotification(notification);
bool postNotification = true;
if (AudioMan->QuietMode() == AudioManager::notifications) {
QStringList allowedCategories;
allowedCategories.append("battery.low");
allowedCategories.append("battery.critical");
allowedCategories.append("reminder.activate");
if (!allowedCategories.contains(hints.value("category").toString()) && !hints.value("x-thesuite-timercomplete", false).toBool()) {
postNotification = false;
emit NotificationClosed(notification->getId(), NotificationObject::Undefined);
}
} else if (AudioMan->QuietMode() == AudioManager::mute) {
postNotification = false;
emit NotificationClosed(notification->getId(), NotificationObject::Undefined);
}
if (postNotification) {
notification->post();
}
return notification->getId();
}