diff --git a/shell/osd.cpp b/shell/osd.cpp index 290a661ce..b2996d5b3 100644 --- a/shell/osd.cpp +++ b/shell/osd.cpp @@ -1,189 +1,225 @@ /* * Copyright 2014 (c) Martin Klapetek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "osd.h" #include "shellcorona.h" #include #include #include #include #include #include #include #include Osd::Osd(ShellCorona *corona) : QObject(corona) , m_osdPath(corona->lookAndFeelPackage().filePath("osdmainscript")) { QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/osdService"), this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals); } Osd::~Osd() { } void Osd::brightnessChanged(int percent) { showProgress(QStringLiteral("video-display-brightness"), percent); } void Osd::keyboardBrightnessChanged(int percent) { showProgress(QStringLiteral("input-keyboard-brightness"), percent); } void Osd::volumeChanged(int percent) { QString icon; if (percent >= 75) { icon = QStringLiteral("audio-volume-high"); } else if (percent < 75 && percent >= 25) { icon = QStringLiteral("audio-volume-medium"); } else if (percent < 25 && percent > 0) { icon = QStringLiteral("audio-volume-low"); } else if (percent == 0) { icon = QStringLiteral("audio-volume-muted"); showText(icon, i18nc("OSD informing that the system is muted, keep short", "Audio Muted")); return; } showProgress(icon, percent); } void Osd::mediaPlayerVolumeChanged(int percent, const QString &playerName, const QString &playerIconName) { if (percent == 0) { showText(playerIconName, i18nc("OSD informing that some media app is muted, eg. Amarok Muted", "%1 Muted", playerName)); } else { showProgress(playerIconName, percent, playerName); } } void Osd::kbdLayoutChanged(const QString &layoutName) { showText(QStringLiteral("keyboard-layout"), layoutName); } void Osd::virtualDesktopChanged(const QString ¤tVirtualDesktopName) { //FIXME: need a VD icon showText(QString(), currentVirtualDesktopName); } +void Osd::touchpadEnabledChanged(bool touchpadEnabled) +{ + if (touchpadEnabled) { + showText(QStringLiteral("input-touchpad-on"), i18nc("touchpad was enabled, keep short", "Touchpad On")); + } else { + showText(QStringLiteral("input-touchpad-off"), i18nc("touchpad was disabled, keep short", "Touchpad Off")); + } +} + +void Osd::wifiEnabledChanged(bool wifiEnabled) +{ + if (wifiEnabled) { + showText(QStringLiteral("network-wireless-on"), i18nc("wireless lan was enabled, keep short", "Wifi On")); + } else { + showText(QStringLiteral("network-wireless-off"), i18nc("wireless lan was disabled, keep short", "Wifi Off")); + } +} + +void Osd::bluetoothEnabledChanged(bool bluetoothEnabled) +{ + if (bluetoothEnabled) { + showText(QStringLiteral("preferences-system-bluetooth"), i18nc("Bluetooth was enabled, keep short", "Bluetooth On")); + } else { + showText(QStringLiteral("preferences-system-bluetooth-inactive"), i18nc("Bluetooth was disabled, keep short", "Bluetooth Off")); + } +} + +void Osd::wwanEnabledChanged(bool wwanEnabled) +{ + if (wwanEnabled) { + showText(QStringLiteral("network-mobile-on"), i18nc("mobile internet was enabled, keep short", "Mobile Internet On")); + } else { + showText(QStringLiteral("network-mobile-off"), i18nc("mobile internet was disabled, keep short", "Mobile Internet Off")); + } +} + bool Osd::init() { if (m_osdObject && m_osdObject->rootObject()) { return true; } if (m_osdPath.isEmpty()) { return false; } if (!m_osdObject) { m_osdObject = new KDeclarative::QmlObject(this); } m_osdObject->setSource(QUrl::fromLocalFile(m_osdPath)); if (m_osdObject->status() != QQmlComponent::Ready) { qWarning() << "Failed to load OSD QML file" << m_osdPath; return false; } m_timeout = m_osdObject->rootObject()->property("timeout").toInt(); if (!m_osdTimer) { m_osdTimer = new QTimer(this); m_osdTimer->setSingleShot(true); connect(m_osdTimer, &QTimer::timeout, this, &Osd::hideOsd); } return true; } void Osd::showProgress(const QString &icon, const int percent, const QString &additionalText) { if (!init()) { return; } auto *rootObject = m_osdObject->rootObject(); int value = qBound(0, percent, 100); rootObject->setProperty("osdValue", value); rootObject->setProperty("osdAdditionalText", additionalText); rootObject->setProperty("showingProgress", true); rootObject->setProperty("icon", icon); emit osdProgress(icon, value, additionalText); showOsd(); } void Osd::showText(const QString &icon, const QString &text) { if (!init()) { return; } auto *rootObject = m_osdObject->rootObject(); rootObject->setProperty("showingProgress", false); rootObject->setProperty("osdValue", text); rootObject->setProperty("icon", icon); emit osdText(icon, text); showOsd(); } void Osd::showOsd() { m_osdTimer->stop(); auto *rootObject = m_osdObject->rootObject(); // if our OSD understands animating the opacity, do it; // otherwise just show it to not break existing lnf packages if (rootObject->property("animateOpacity").isValid()) { rootObject->setProperty("animateOpacity", false); rootObject->setProperty("opacity", 1); rootObject->setProperty("visible", true); rootObject->setProperty("animateOpacity", true); rootObject->setProperty("opacity", 0); } else { rootObject->setProperty("visible", true); } m_osdTimer->start(m_timeout); } void Osd::hideOsd() { auto *rootObject = m_osdObject->rootObject(); if (!rootObject) { return; } rootObject->setProperty("visible", false); // this is needed to prevent fading from "old" values when the OSD shows up rootObject->setProperty("osdValue", 0); } diff --git a/shell/osd.h b/shell/osd.h index 9cc54acd7..120d87c64 100644 --- a/shell/osd.h +++ b/shell/osd.h @@ -1,69 +1,73 @@ /* * Copyright 2014 (c) Martin Klapetek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OSD_H #define OSD_H #include #include namespace KDeclarative { class QmlObject; } namespace Plasma { } class QTimer; class ShellCorona; class Osd : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.osdService") public: Osd(ShellCorona *corona); ~Osd() override; public Q_SLOTS: void brightnessChanged(int percent); void keyboardBrightnessChanged(int percent); void volumeChanged(int percent); void mediaPlayerVolumeChanged(int percent, const QString &playerName, const QString &playerIconName); void kbdLayoutChanged(const QString &layoutName); void virtualDesktopChanged(const QString ¤tVirtualDesktopName); + void touchpadEnabledChanged(bool touchpadEnabled); + void wifiEnabledChanged(bool wifiEnabled); + void bluetoothEnabledChanged(bool bluetoothEnabled); + void wwanEnabledChanged(bool wwanEnabled); Q_SIGNALS: void osdProgress(const QString &icon, const int percent, const QString &additionalText); void osdText(const QString &icon, const QString &text); private Q_SLOTS: void hideOsd(); private: bool init(); void showProgress(const QString &icon, const int percent, const QString &additionalText = QString()); void showText(const QString &icon, const QString &text); void showOsd(); QString m_osdPath; KDeclarative::QmlObject *m_osdObject = nullptr; QTimer *m_osdTimer = nullptr; int m_timeout = 0; }; #endif // OSD_H