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,35 +41,42 @@ NotificationPopup::~NotificationPopup()
}
void NotificationPopup::show() {
QRect screenGeometry = QApplication::desktop()->screenGeometry();
this->move(screenGeometry.topLeft().x(), screenGeometry.top() - this->height());
this->setFixedWidth(screenGeometry.width());
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());
textHeight = ui->bodyLabel->fontMetrics().boundingRect(QRect(0, 0, screenGeometry.width() - this->layout()->contentsMargins().left() - this->layout()->contentsMargins().right(), 10000), Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, ui->bodyLabel->text()).height();
textHeight = ui->bodyLabel->fontMetrics().boundingRect(QRect(0, 0, screenGeometry.width() - this->layout()->contentsMargins().left() - this->layout()->contentsMargins().right(), 10000), Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, ui->bodyLabel->text()).height();
bool showDownArrow = false;
if (textHeight > ui->bodyLabel->fontMetrics().height()) {
showDownArrow = true;
bool showDownArrow = false;
if (textHeight > ui->bodyLabel->fontMetrics().height()) {
showDownArrow = true;
}
if (actions.count() > 0) {
showDownArrow = true;
}
ui->downContainer->setVisible(showDownArrow);
this->setFixedHeight(this->sizeHint().height());
QDialog::show();
tPropertyAnimation* anim = new tPropertyAnimation(this, "geometry");
anim->setStartValue(this->geometry());
anim->setEndValue(QRect(this->x(), screenGeometry.y(), this->width(), this->height()));
anim->setDuration(500);
anim->setEasingCurve(QEasingCurve::OutCubic);
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
anim->start();
dismisser->start();
mouseEvents = true;
}
if (actions.count() > 0) {
showDownArrow = true;
}
ui->downContainer->setVisible(showDownArrow);
this->setFixedHeight(this->sizeHint().height());
QDialog::show();
tPropertyAnimation* anim = new tPropertyAnimation(this, "geometry");
anim->setStartValue(this->geometry());
anim->setEndValue(QRect(this->x(), screenGeometry.y(), this->width(), this->height()));
anim->setDuration(500);
anim->setEasingCurve(QEasingCurve::OutCubic);
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
anim->start();
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);
this->close();
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);
notification->post();
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();
}