From f665589cc13b738077003641360968f6e04f3e64 Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Wed, 14 Dec 2016 16:10:16 +1100 Subject: [PATCH] Timer now sent to lock screen --- infopanedropdown.cpp | 58 ++++++++++++++++++++++++++++++++++----- infopanedropdown.h | 6 ++++ infopanedropdown.ui | 49 +++++++++++++++++++++++++++++---- notificationdbus.cpp | 1 + notifications_adaptor.cpp | 2 +- notifications_adaptor.h | 10 +++---- onboarding.h | 3 ++ theShell.pro | 4 +++ upowerdbus.cpp | 22 ++++++++------- 9 files changed, 126 insertions(+), 29 deletions(-) diff --git a/infopanedropdown.cpp b/infopanedropdown.cpp index 3cb5267..dfde29a 100644 --- a/infopanedropdown.cpp +++ b/infopanedropdown.cpp @@ -368,6 +368,7 @@ void InfoPaneDropdown::timerTick() { stopwatchTime = stopwatchTime.addMSecs(this->stopwatchTime.elapsed()); } ui->stopwatchLabel->setText(stopwatchTime.toString("hh:mm:ss.zzz")); + updateTimers(); } void InfoPaneDropdown::show(dropdownType showWith) { @@ -998,12 +999,14 @@ void InfoPaneDropdown::startTimer(QTime time) { connect(timer, &QTimer::timeout, [=]() { timeUntilTimeout = timeUntilTimeout.addSecs(-1); if (timeUntilTimeout == QTime(0, 0, 0)) { - if (timerNotificationId != 0 ) { + if (timerNotificationId != 0) { notificationEngine->CloseNotification(timerNotificationId); } + QVariantMap hints; + hints.insert("x-thesuite-timercomplete", true); timerNotificationId = notificationEngine->Notify("theShell", 0, "", "Timer Elapsed", "Your timer has completed.", - QStringList(), QVariantMap(), 0); + QStringList(), hints, 0); ui->timeEdit->setVisible(true); ui->label_7->setVisible(false); ui->pushButton_2->setText("Start"); @@ -1029,13 +1032,35 @@ void InfoPaneDropdown::startTimer(QTime time) { playlist->setPlaybackMode(QMediaPlaylist::Loop); ringtone->setPlaylist(playlist); ringtone->play(); + updateTimers(); } else { ui->label_7->setText(timeUntilTimeout.toString("HH:mm:ss")); - emit timerChanged(timeUntilTimeout.toString("HH:mm:ss")); + updateTimers(); } }); timer->start(); - emit timerChanged(timeUntilTimeout.toString("HH:mm:ss")); + updateTimers(); +} + +void InfoPaneDropdown::updateTimers() { + QStringList parts; + if (timer != NULL) { + parts.append(timeUntilTimeout.toString("HH:mm:ss")); + } + + if (stopwatchRunning) { + QTime stopwatchTime = QTime::fromMSecsSinceStartOfDay(0); + stopwatchTime = stopwatchTime.addMSecs(stopwatchTimeAdd); + stopwatchTime = stopwatchTime.addMSecs(this->stopwatchTime.elapsed()); + parts.append(stopwatchTime.toString("hh:mm:ss")); + } + + if (parts.count() != 0) { + emit timerVisibleChanged(true); + emit timerChanged(parts.join(" ยท ")); + } else { + emit timerVisibleChanged(false); + } } void InfoPaneDropdown::notificationClosed(uint id, uint reason) { @@ -1055,13 +1080,11 @@ void InfoPaneDropdown::on_pushButton_2_clicked() ui->pushButton_3->setVisible(true); ui->label_7->setEnabled(false); ui->pushButton_2->setText("Resume"); - emit timerEnabledChanged(false); } else { timer->start(); ui->pushButton_3->setVisible(false); ui->label_7->setEnabled(true); ui->pushButton_2->setText("Pause"); - emit timerEnabledChanged(true); } } } @@ -1481,8 +1504,9 @@ void InfoPaneDropdown::updateKdeconnect() { QListWidgetItem* item = new QListWidgetItem; item->setText(deviceInterface.property("name").toString()); item->setIcon(QIcon::fromTheme(deviceInterface.property("iconName").toString())); + item->setData(Qt::UserRole, device); if (!isReachable) { - item->setTextColor(ui->kdeconnectDevices->palette().color(QPalette::Disabled, QPalette::Text)); + item->setForeground(ui->kdeconnectDevices->palette().brush(QPalette::Disabled, QPalette::Text)); } ui->kdeconnectDevices->addItem(item); } @@ -1618,3 +1642,23 @@ void InfoPaneDropdown::on_systemFont_currentFontChanged(const QFont &f) themeSettings->setValue("fonts/smallFamily", f.family()); //ui->systemFont->setFont(QFont(themeSettings->value("font/defaultFamily", defaultFont).toString(), themeSettings->value("font/defaultSize", 10).toInt())); } + +void InfoPaneDropdown::on_locateDeviceButton_clicked() +{ + if (ui->kdeconnectDevices->selectedItems().count() != 0) { + if (QMessageBox::question(this, "Locate Device", "Your device will ring at full volume. Tap the button on the screen of the device to silence it.", QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok) == QMessageBox::Ok) { + QString device = ui->kdeconnectDevices->selectedItems().first()->data(Qt::UserRole).toString(); + QDBusInterface findPhone("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device + "/findmyphone", "org.kde.kdeconnect.device.findmyphone"); + findPhone.call("ring"); + } + } +} + +void InfoPaneDropdown::on_pingDeviceButton_clicked() +{ + if (ui->kdeconnectDevices->selectedItems().count() != 0) { + QString device = ui->kdeconnectDevices->selectedItems().first()->data(Qt::UserRole).toString(); + QDBusInterface findPhone("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device + "/ping", "org.kde.kdeconnect.device.ping"); + findPhone.call("sendPing"); + } +} diff --git a/infopanedropdown.h b/infopanedropdown.h index 79cfd3f..7f3c196 100644 --- a/infopanedropdown.h +++ b/infopanedropdown.h @@ -208,6 +208,12 @@ private slots: void on_systemFont_currentFontChanged(const QFont &f); + void on_locateDeviceButton_clicked(); + + void on_pingDeviceButton_clicked(); + + void updateTimers(); + public slots: void getNetworks(); diff --git a/infopanedropdown.ui b/infopanedropdown.ui index 59c66c1..4f7645e 100644 --- a/infopanedropdown.ui +++ b/infopanedropdown.ui @@ -321,7 +321,7 @@ - 6 + 0 @@ -546,14 +546,14 @@ 0 1969 11 - 11 + 10 1969 11 - 11 + 10 @@ -1184,8 +1184,8 @@ 0 0 - 165 - 59 + 928 + 620 @@ -1366,10 +1366,47 @@ - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ping + + + + + + + + + + Locate + + + + + + + + diff --git a/notificationdbus.cpp b/notificationdbus.cpp index ab397a5..3310965 100644 --- a/notificationdbus.cpp +++ b/notificationdbus.cpp @@ -95,6 +95,7 @@ uint NotificationDBus::Notify(QString app_name, uint replaces_id, NotificationArgs.append(replaces_id); NotificationArgs.append(QStringList()); } + NotificationArgs.append(hints); NotificationEmit.setArguments(NotificationArgs); QDBusConnection::sessionBus().call(NotificationEmit, QDBus::NoBlock); diff --git a/notifications_adaptor.cpp b/notifications_adaptor.cpp index 2813631..4476626 100644 --- a/notifications_adaptor.cpp +++ b/notifications_adaptor.cpp @@ -34,7 +34,7 @@ NotificationsAdaptor::~NotificationsAdaptor() // destructor } -void NotificationsAdaptor::CloseNotification(int id) +void NotificationsAdaptor::CloseNotification(uint id) { // handle method call org.freedesktop.Notifications.CloseNotification parent()->CloseNotification(id); diff --git a/notifications_adaptor.h b/notifications_adaptor.h index 583c5b8..59b494f 100644 --- a/notifications_adaptor.h +++ b/notifications_adaptor.h @@ -36,8 +36,8 @@ class NotificationsAdaptor: public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" -" \n" -" \n" +" \n" +" \n" " \n" " \n" " \n" @@ -59,7 +59,7 @@ class NotificationsAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" -" \n" +" \n" " \n" " \n" " \n" @@ -78,13 +78,13 @@ public: public: // PROPERTIES public Q_SLOTS: // METHODS - void CloseNotification(int id); + void CloseNotification(uint id); QStringList GetCapabilities(); QString GetServerInformation(QString &vendor, QString &version, QString &spec_version); uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout); Q_SIGNALS: // SIGNALS void ActionInvoked(uint id, const QString &action_key); - void NotificationClosed(int id, int reason); + void NotificationClosed(uint id, uint reason); }; #endif diff --git a/onboarding.h b/onboarding.h index d594b6c..fae230f 100644 --- a/onboarding.h +++ b/onboarding.h @@ -9,6 +9,9 @@ #define ChangelogOnbording "New in theShell 5.3:\n"\ "- Default system font can be set in theme settings."\ + "- Battery indicator now shows battery for devices connected over KDE Connect\n"\ + "- Added some KDE Connect actions in the status center\n"\ + "- The stopwatch is now shown on the bar when being used."\ "\n"\ "New in theShell 5.2: \n"\ "- New Onboarding experience. Every time theShell updates, you'll get a changelog.\n" \ diff --git a/theShell.pro b/theShell.pro index 7b53612..fa3adeb 100644 --- a/theShell.pro +++ b/theShell.pro @@ -19,6 +19,10 @@ QDBUSXML2CPP_ADAPTOR_SOURCE_FLAGS = -l NotificationDBus -i notificationdbus.h #appMenuRegistrar.files = com.canonical.AppMenu.Registrar.xml #appMenuRegistrar.header_flags = -l DBusMenuRegistrar -i dbusmenuregistrar.h +#notifications.files = org.freedesktop.Notifications.xml +#notifications.header_flags = -l NotificationDBus -i notificationdbus.h +#DBUS_ADAPTORS += notifications + #DBUS_ADAPTORS += com.canonical.AppMenu.Registrar.xml SOURCES += main.cpp\ diff --git a/upowerdbus.cpp b/upowerdbus.cpp index 9a5f268..d2f8714 100644 --- a/upowerdbus.cpp +++ b/upowerdbus.cpp @@ -256,20 +256,22 @@ void UPowerDBus::DeviceChanged() { QDBusInterface interface("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device"); QString name = interface.property("name").toString(); QDBusInterface batteryInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device.battery"); - QDBusReply currentCharge = batteryInterface.call("charge"); - QDBusReply charging = batteryInterface.call("isCharging"); + if (batteryInterface.isValid()) { + QDBusReply currentCharge = batteryInterface.call("charge"); + QDBusReply charging = batteryInterface.call("isCharging"); - QString batteryText; - if (charging) { - if (currentCharge == 100) { - batteryText = QString::number(currentCharge) + "% battery on " + name + " (Full)"; + QString batteryText; + if (charging) { + if (currentCharge == 100) { + batteryText = QString::number(currentCharge) + "% battery on " + name + " (Full)"; + } else { + batteryText = QString::number(currentCharge) + "% battery on " + name + " (Charging)"; + } } else { - batteryText = QString::number(currentCharge) + "% battery on " + name + " (Charging)"; + batteryText = QString::number(currentCharge) + "% battery on " + name + " (Discharging)"; } - } else { - batteryText = QString::number(currentCharge) + "% battery on " + name + " (Discharging)"; + displayOutput.append(batteryText); } - displayOutput.append(batteryText); } }