diff --git a/statuscenter/OverviewPane/OverviewPane.pro b/statuscenter/OverviewPane/OverviewPane.pro index d7f7dda..cf026f6 100644 --- a/statuscenter/OverviewPane/OverviewPane.pro +++ b/statuscenter/OverviewPane/OverviewPane.pro @@ -39,16 +39,19 @@ HEADERS += \ plugin.h \ overview.h \ overviewsettings.h \ - Timers/timerpage.h + Timers/timerpage.h \ + Timers/timeritem.h SOURCES += \ plugin.cpp \ overview.cpp \ overviewsettings.cpp \ - Timers/timerpage.cpp + Timers/timerpage.cpp \ + Timers/timeritem.cpp FORMS += \ overview.ui \ overviewsettings.ui \ - Timers/timerpage.ui + Timers/timerpage.ui \ + Timers/timeritem.ui diff --git a/statuscenter/OverviewPane/Timers/timeritem.cpp b/statuscenter/OverviewPane/Timers/timeritem.cpp new file mode 100644 index 0000000..732ab79 --- /dev/null +++ b/statuscenter/OverviewPane/Timers/timeritem.cpp @@ -0,0 +1,98 @@ +#include "timeritem.h" +#include "ui_timeritem.h" + +#include +#include + +TimerItem::TimerItem(QString timerName, int seconds, QWidget *parent) : + QWidget(parent), + ui(new Ui::TimerItem) +{ + ui->setupUi(this); + + ui->timerName->setText(timerName); + + progressAnim = new tVariantAnimation(); + progressAnim->setForceAnimation(true); + progressAnim->setStartValue(0); + progressAnim->setEndValue(this->width()); + progressAnim->setDuration(seconds * 1000); + connect(progressAnim, &tVariantAnimation::valueChanged, [=](QVariant value) { + int msecsElapsed = progressAnim->currentTime(); + + QTime time = QTime::fromMSecsSinceStartOfDay(progressAnim->duration() - msecsElapsed); + + ui->timeLeftLabel->setText(time.toString("HH:mm:ss")); + this->update(); + }); + connect(progressAnim, &tVariantAnimation::finished, [=] { + emit elapsed(timerName); + //if (AudioMan->QuietMode() != AudioManager::notifications && AudioMan->QuietMode() != AudioManager::mute) { //Check if we should show the notification so the user isn't stuck listening to the tone + + /*tNotification* notification = new tNotification(timerName, tr("Time's up!")); + + QStringList actions; + actions << "restart" << "Restart Timer"; + actions << "+0.5" << "+30 sec"; + actions << "+1" << "+1 min"; + actions << "+2" << "+2 min"; + actions << "+5" << "+5 min"; + actions << "+10" << "+10 min"; + + notification->insertHint("x-thesuite-timercomplete", true); + notification->setSoundOn(false); + + /*QVariantMap hints; + hints.insert("x-thesuite-timercomplete", true); + hints.insert("suppress-sound", true); + timerNotificationId = ndbus->Notify("theShell", 0, "", tr("Timer Elapsed"), + tr("Your timer has completed."), + actions, hints, 0);*/ + + //notification->setTimeout(0); + //notification->post(); + + /*QMediaPlaylist* playlist = new QMediaPlaylist(); + + #ifdef BLUEPRINT + QString ringtonesPath = "/usr/share/sounds/theshellb/tones/"; + #else + QString ringtonesPath = "/usr/share/sounds/theshell/tones/"; + #endif + + /*if (ui->timerToneSelect->currentText() == tr("Happy Bee")) { + playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "happybee.ogg"))); + } else if (ui->timerToneSelect->currentText() == tr("Playing in the Dark")) { + playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "playinginthedark.ogg"))); + } else if (ui->timerToneSelect->currentText() == tr("Ice Cream Truck")) { + playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "icecream.ogg"))); + } else if (ui->timerToneSelect->currentText() == tr("Party Complex")) { + playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "party.ogg"))); + } else if (ui->timerToneSelect->currentText() == tr("Salty Ditty")) { + playlist->addMedia(QMediaContent(QUrl::fromLocalFile(ringtonesPath + "saltyditty.ogg"))); + } + playlist->setPlaybackMode(QMediaPlaylist::Loop); + ringtone->setPlaylist(playlist); + ringtone->play();*/ + + //AudioMan->attenuateStreams(); + //} + }); + progressAnim->start(); +} + +TimerItem::~TimerItem() +{ + delete ui; +} + +void TimerItem::paintEvent(QPaintEvent* event) { + QPainter painter(this); + painter.setBrush(this->palette().brush(QPalette::Highlight)); + painter.setPen(Qt::transparent); + painter.drawRect(0, this->height() - 2 * theLibsGlobal::instance()->getDPIScaling(), progressAnim->currentValue().toInt(), 2 * theLibsGlobal::instance()->getDPIScaling()); +} + +void TimerItem::resizeEvent(QResizeEvent* event) { + progressAnim->setEndValue(this->width()); +} diff --git a/statuscenter/OverviewPane/Timers/timeritem.h b/statuscenter/OverviewPane/Timers/timeritem.h new file mode 100644 index 0000000..ad3bb31 --- /dev/null +++ b/statuscenter/OverviewPane/Timers/timeritem.h @@ -0,0 +1,32 @@ +#ifndef TIMERITEM_H +#define TIMERITEM_H + +#include +#include +#include + +namespace Ui { + class TimerItem; +} + +class TimerItem : public QWidget +{ + Q_OBJECT + + public: + explicit TimerItem(QString timerName, int seconds, QWidget *parent = nullptr); + ~TimerItem(); + + signals: + void elapsed(QString timerName); + + private: + Ui::TimerItem *ui; + + tVariantAnimation* progressAnim; + + void paintEvent(QPaintEvent* event); + void resizeEvent(QResizeEvent* event); +}; + +#endif // TIMERITEM_H diff --git a/statuscenter/OverviewPane/Timers/timeritem.ui b/statuscenter/OverviewPane/Timers/timeritem.ui new file mode 100644 index 0000000..f54b12e --- /dev/null +++ b/statuscenter/OverviewPane/Timers/timeritem.ui @@ -0,0 +1,40 @@ + + + TimerItem + + + + 0 + 0 + 400 + 229 + + + + Form + + + + + + Timer 1 + + + + + + + + 50 + + + + TextLabel + + + + + + + + diff --git a/statuscenter/OverviewPane/Timers/timerpage.cpp b/statuscenter/OverviewPane/Timers/timerpage.cpp index ff12a8a..7aa340b 100644 --- a/statuscenter/OverviewPane/Timers/timerpage.cpp +++ b/statuscenter/OverviewPane/Timers/timerpage.cpp @@ -1,11 +1,20 @@ #include "timerpage.h" #include "ui_timerpage.h" +#include +#include + TimerPage::TimerPage(QWidget *parent) : QStackedWidget(parent), ui(new Ui::TimerPage) { ui->setupUi(this); + + this->setCurrentWidget(ui->noTimersPage); + QScroller::grabGesture(ui->timersScroll->viewport(), QScroller::LeftMouseButtonGesture); + + notificationInterface = new QDBusInterface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); + QDBusConnection::sessionBus().connect(notificationInterface->service(), notificationInterface->path(), notificationInterface->interface(), "NotificationClosed", this, SLOT(notificationClosed(uint,uint))); } TimerPage::~TimerPage() @@ -15,10 +24,71 @@ TimerPage::~TimerPage() void TimerPage::on_backButton_clicked() { - this->setCurrentWidget(ui->noTimersPage); + if (timersCreated == 0) { + this->setCurrentWidget(ui->noTimersPage); + } else { + this->setCurrentWidget(ui->timersList); + } } void TimerPage::on_newTimerButton_clicked() { this->setCurrentWidget(ui->newTimerPage); + + ui->newTimerBox->setTime(QTime::fromMSecsSinceStartOfDay(0)); + + ui->newTimerName->setText(tr("Timer %n", nullptr, timersCreated + 1)); +} + +void TimerPage::on_setTimerButton_clicked() +{ + TimerItem* item = new TimerItem(ui->newTimerName->text(), ui->newTimerBox->time().msecsSinceStartOfDay() / 1000, this); + ui->timersLayout->addWidget(item); + connect(item, SIGNAL(elapsed(QString)), this, SLOT(timerElapsed(QString))); + this->setCurrentWidget(ui->timersList); + timersCreated++; +} + +void TimerPage::timerElapsed(QString timerName) { + timersElapsed.append(timerName); + + if (timersElapsed.count() > 1) { + QVariantMap hints; + hints.insert("x-thesuite-timercomplete", true); + hints.insert("suppress-sound", true); + + QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(notificationInterface->asyncCall("Notify", "theShell", currentTimerId, "", tr("%n timers elapsed", nullptr, timersElapsed.count()), timersElapsed.join(" ยท "), QStringList(), hints, 0)); + connect(watcher, &QDBusPendingCallWatcher::finished, [=] { + currentTimerId = watcher->reply().arguments().first().toUInt(); + }); + } else { + QStringList actions; + actions << "restart" << "Restart Timer"; + actions << "+0.5" << "+30 sec"; + actions << "+1" << "+1 min"; + actions << "+2" << "+2 min"; + actions << "+5" << "+5 min"; + actions << "+10" << "+10 min"; + + QVariantMap hints; + hints.insert("x-thesuite-timercomplete", true); + hints.insert("suppress-sound", true); + + QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(notificationInterface->asyncCall("Notify", "theShell", currentTimerId, "", timerName, tr("Time's up!"), actions, hints, 0)); + connect(watcher, &QDBusPendingCallWatcher::finished, [=] { + currentTimerId = watcher->reply().arguments().first().toUInt(); + }); + } +} + +void TimerPage::notificationClosed(uint id, uint reason) { + if (id == currentTimerId) { + currentTimerId = 0; + timersElapsed.clear(); + } +} + +void TimerPage::on_newTimerButtonTop_clicked() +{ + ui->newTimerButton->click(); } diff --git a/statuscenter/OverviewPane/Timers/timerpage.h b/statuscenter/OverviewPane/Timers/timerpage.h index d47c796..45a0516 100644 --- a/statuscenter/OverviewPane/Timers/timerpage.h +++ b/statuscenter/OverviewPane/Timers/timerpage.h @@ -2,6 +2,7 @@ #define TIMERPAGE_H #include +#include "timeritem.h" namespace Ui { class TimerPage; @@ -20,8 +21,22 @@ class TimerPage : public QStackedWidget void on_newTimerButton_clicked(); + void on_setTimerButton_clicked(); + + void on_newTimerButtonTop_clicked(); + + void timerElapsed(QString timerName); + + void notificationClosed(uint id, uint reason); + private: Ui::TimerPage *ui; + + int timersCreated = 0; + uint currentTimerId = 0; + QStringList timersElapsed; + + QDBusInterface* notificationInterface; }; #endif // TIMERPAGE_H diff --git a/statuscenter/OverviewPane/Timers/timerpage.ui b/statuscenter/OverviewPane/Timers/timerpage.ui index c265558..0ac81bb 100644 --- a/statuscenter/OverviewPane/Timers/timerpage.ui +++ b/statuscenter/OverviewPane/Timers/timerpage.ui @@ -14,7 +14,7 @@ StackedWidget - 2 + 1 @@ -77,7 +77,8 @@ New Timer - + + .. @@ -111,7 +112,135 @@ - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 0 + + + + + 15 + + + + Timers + + + 9 + + + + + + + + 0 + 0 + + + + + + + + + + true + + + + + + + + + + 16777215 + 1 + + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + true + + + + + 0 + 0 + 400 + 386 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Vertical + + + + 20 + 381 + + + + + + + + + + @@ -146,7 +275,8 @@ - + + .. true @@ -204,6 +334,22 @@ + + + + + + + false + + + Qt::AlignCenter + + + Timer Name + + + @@ -272,7 +418,8 @@ Set - + + .. diff --git a/theShell.pro.user b/theShell.pro.user index 73e1ebe..4303ada 100644 --- a/theShell.pro.user +++ b/theShell.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId