From 605ab0f130128d0fa1d265a9da989296a54b4395 Mon Sep 17 00:00:00 2001 From: Martin Klapetek Date: Mon, 27 Jan 2014 14:38:01 +0100 Subject: [PATCH] Add OSD notifications to plasma-shell As we decided to make the OSD available only for certain things, the API is intentionally limited to very particular set of things. The list is not complete yet I believe, but it's definitely a finite and a small set Also as it's not a public service, I left it under org.kde.plasma_shell on D-Bus. And we're still missing all the icons except volume, but Jens is on it. REVIEW: 115301 --- src/shell/CMakeLists.txt | 1 + src/shell/osd.cpp | 117 ++++++++++++++++++++++++++++++++++++++ src/shell/osd.h | 61 ++++++++++++++++++++ src/shell/shellcorona.cpp | 4 +- 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/shell/osd.cpp create mode 100644 src/shell/osd.h diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 5c4b36022..7119f64e5 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -47,6 +47,7 @@ add_executable(plasma-shell shellcorona.cpp shellpluginloader.cpp shellmanager.cpp + osd.cpp ${scripting_SRC} ) diff --git a/src/shell/osd.cpp b/src/shell/osd.cpp new file mode 100644 index 000000000..cefddb81f --- /dev/null +++ b/src/shell/osd.cpp @@ -0,0 +1,117 @@ +/* + * 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 "shellpluginloader.h" +#include "shellcorona.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + + +Osd::Osd(ShellCorona *corona) + : QObject(corona) +{ + m_osdObject = new KDeclarative::QmlObject(this); + + m_osdObject->setSource(QUrl::fromLocalFile(corona->lookAndFeelPackage().filePath("osdmainscript"))); + m_timeout = m_osdObject->rootObject()->property("timeout").toInt(); + + QDBusConnection::sessionBus().registerObject("/org/kde/osdService", this, QDBusConnection::ExportAllSlots); + + m_osdTimer = new QTimer(this); + m_osdTimer->setSingleShot(true); + connect(m_osdTimer, SIGNAL(timeout()), + this, SLOT(hideOsd())); +} + +Osd::~Osd() +{ +} + +void Osd::brightnessChanged(int percent) +{ + // FIXME: need brightness icon + showProgress(QString(), 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, i18n("Audio Muted")); + return; + } + + showProgress(icon, percent); +} + +void Osd::kbdLayoutChanged(const QString &layoutName) +{ + //FIXME: need a kbd icon + showText(QString(), layoutName); +} + +void Osd::virtualDesktopChanged(const QString ¤tVirtualDesktopName) +{ + //FIXME: need a VD icon + showText(QString(), currentVirtualDesktopName); +} + +void Osd::showProgress(const QString &icon, const int percent) +{ + m_osdObject->rootObject()->setProperty("osdValue", percent); + m_osdObject->rootObject()->setProperty("showingProgress", true); + m_osdObject->rootObject()->setProperty("icon", icon); + + showOsd(); +} + +void Osd::showText(const QString &icon, const QString &text) +{ + m_osdObject->rootObject()->setProperty("osdValue", text); + m_osdObject->rootObject()->setProperty("showingProgress", false); + m_osdObject->rootObject()->setProperty("icon", icon); + + showOsd(); +} + +void Osd::showOsd() +{ + m_osdObject->rootObject()->setProperty("visible", true); + m_osdTimer->start(m_timeout); +} + +void Osd::hideOsd() +{ + m_osdObject->rootObject()->setProperty("visible", false); +} diff --git a/src/shell/osd.h b/src/shell/osd.h new file mode 100644 index 000000000..68d52430f --- /dev/null +++ b/src/shell/osd.h @@ -0,0 +1,61 @@ +/* + * 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 Package; +} + +class QTimer; +class ShellCorona; + +class Osd : public QObject { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.osdService") +public: + Osd(ShellCorona *corona); + ~Osd(); + +public Q_SLOTS: + void brightnessChanged(int percent); + void volumeChanged(int percent); + void kbdLayoutChanged(const QString &layoutName); + void virtualDesktopChanged(const QString ¤tVirtualDesktopName); + +private Q_SLOTS: + void hideOsd(); + +private: + void showProgress(const QString &icon, const int percent); + void showText(const QString &icon, const QString &text); + void showOsd(); + + KDeclarative::QmlObject *m_osdObject; + QTimer *m_osdTimer; + int m_timeout; +}; + +#endif // OSD_H diff --git a/src/shell/shellcorona.cpp b/src/shell/shellcorona.cpp index f565d79ed..92307268b 100644 --- a/src/shell/shellcorona.cpp +++ b/src/shell/shellcorona.cpp @@ -45,6 +45,7 @@ #include "widgetexplorer/widgetexplorer.h" #include "configview.h" #include "shellpluginloader.h" +#include "osd.h" static const int s_configSyncDelay = 10000; // 10 seconds @@ -140,6 +141,8 @@ ShellCorona::ShellCorona(QObject *parent) connect(d->activityConsumer, SIGNAL(currentActivityChanged(QString)), this, SLOT(currentActivityChanged(QString))); connect(d->activityConsumer, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString))); connect(d->activityConsumer, SIGNAL(activityRemoved(QString)), this, SLOT(activityRemoved(QString))); + + new Osd(this); } ShellCorona::~ShellCorona() @@ -659,7 +662,6 @@ Plasma::Package ShellCorona::lookAndFeelPackage() const } - // Desktop corona handler