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
This commit is contained in:
parent
87a7db3063
commit
605ab0f130
@ -47,6 +47,7 @@ add_executable(plasma-shell
|
|||||||
shellcorona.cpp
|
shellcorona.cpp
|
||||||
shellpluginloader.cpp
|
shellpluginloader.cpp
|
||||||
shellmanager.cpp
|
shellmanager.cpp
|
||||||
|
osd.cpp
|
||||||
${scripting_SRC}
|
${scripting_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
117
src/shell/osd.cpp
Normal file
117
src/shell/osd.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 (c) Martin Klapetek <mklapetek@kde.org>
|
||||||
|
*
|
||||||
|
* 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 <QDBusConnection>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QWindow>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <Plasma/Package>
|
||||||
|
#include <KDeclarative/QmlObject>
|
||||||
|
#include <klocalizedstring.h>
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
61
src/shell/osd.h
Normal file
61
src/shell/osd.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 (c) Martin Klapetek <mklapetek@kde.org>
|
||||||
|
*
|
||||||
|
* 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 <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
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
|
@ -45,6 +45,7 @@
|
|||||||
#include "widgetexplorer/widgetexplorer.h"
|
#include "widgetexplorer/widgetexplorer.h"
|
||||||
#include "configview.h"
|
#include "configview.h"
|
||||||
#include "shellpluginloader.h"
|
#include "shellpluginloader.h"
|
||||||
|
#include "osd.h"
|
||||||
|
|
||||||
static const int s_configSyncDelay = 10000; // 10 seconds
|
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(currentActivityChanged(QString)), this, SLOT(currentActivityChanged(QString)));
|
||||||
connect(d->activityConsumer, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString)));
|
connect(d->activityConsumer, SIGNAL(activityAdded(QString)), this, SLOT(activityAdded(QString)));
|
||||||
connect(d->activityConsumer, SIGNAL(activityRemoved(QString)), this, SLOT(activityRemoved(QString)));
|
connect(d->activityConsumer, SIGNAL(activityRemoved(QString)), this, SLOT(activityRemoved(QString)));
|
||||||
|
|
||||||
|
new Osd(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellCorona::~ShellCorona()
|
ShellCorona::~ShellCorona()
|
||||||
@ -659,7 +662,6 @@ Plasma::Package ShellCorona::lookAndFeelPackage() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Desktop corona handler
|
// Desktop corona handler
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user