Plasmoid now displays the devices' battery
BUG: 326883
This commit is contained in:
parent
193f460d84
commit
553a6c518e
6 changed files with 174 additions and 8 deletions
|
@ -3,8 +3,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_BINARY_DIR})
|
${CMAKE_BINARY_DIR})
|
||||||
set(kdeconnectdeclarativeplugin_SRC
|
set(kdeconnectdeclarativeplugin_SRC
|
||||||
|
batteryinterface.cpp
|
||||||
kdeconnectdeclarativeplugin.cpp
|
kdeconnectdeclarativeplugin.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
kde4_add_library(kdeconnectdeclarativeplugin SHARED ${kdeconnectdeclarativeplugin_SRC})
|
kde4_add_library(kdeconnectdeclarativeplugin SHARED ${kdeconnectdeclarativeplugin_SRC})
|
||||||
add_dependencies(kdeconnectdeclarativeplugin libkdeconnect)
|
add_dependencies(kdeconnectdeclarativeplugin libkdeconnect)
|
||||||
target_link_libraries(kdeconnectdeclarativeplugin
|
target_link_libraries(kdeconnectdeclarativeplugin
|
||||||
|
|
73
plasmoid/declarativeplugin/batteryinterface.cpp
Normal file
73
plasmoid/declarativeplugin/batteryinterface.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||||
|
*
|
||||||
|
* 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) version 3 or any later version
|
||||||
|
* accepted by the membership of KDE e.V. (or its successor approved
|
||||||
|
* by the membership of KDE e.V.), which shall act as a proxy
|
||||||
|
* defined in Section 14 of version 3 of the license.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "batteryinterface.h"
|
||||||
|
|
||||||
|
BatteryInterface::BatteryInterface(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_device(0)
|
||||||
|
, m_battery(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryInterface::setDevice(const QString& deviceId)
|
||||||
|
{
|
||||||
|
if (m_device) {
|
||||||
|
delete m_device;
|
||||||
|
}
|
||||||
|
m_device = new DeviceDbusInterface(deviceId, this);
|
||||||
|
connect(m_device, SIGNAL(pluginsChanged()), this, SLOT(devicePluginsChanged()));
|
||||||
|
devicePluginsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryInterface::devicePluginsChanged()
|
||||||
|
{
|
||||||
|
if (m_device->hasPlugin("kdeconnect_battery")) {
|
||||||
|
m_battery = new DeviceBatteryDbusInterface(m_device->id(), this);
|
||||||
|
connect(m_battery, SIGNAL(chargingChange()), this, SIGNAL(infoChanged()));
|
||||||
|
Q_EMIT infoChanged();
|
||||||
|
} else {
|
||||||
|
delete m_battery;
|
||||||
|
m_battery = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_EMIT availableChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BatteryInterface::available() const
|
||||||
|
{
|
||||||
|
return m_battery && m_battery->isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BatteryInterface::displayString() const
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!m_battery) {
|
||||||
|
return i18n("No info");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCharging()) {
|
||||||
|
return i18n("Charging, %1%", chargePercent());
|
||||||
|
} else {
|
||||||
|
return i18n("Discharging, %1%", chargePercent());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
plasmoid/declarativeplugin/batteryinterface.h
Normal file
65
plasmoid/declarativeplugin/batteryinterface.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||||
|
*
|
||||||
|
* 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) version 3 or any later version
|
||||||
|
* accepted by the membership of KDE e.V. (or its successor approved
|
||||||
|
* by the membership of KDE e.V.), which shall act as a proxy
|
||||||
|
* defined in Section 14 of version 3 of the license.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BATTERYINTERFACE_H
|
||||||
|
#define BATTERYINTERFACE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <KLocalizedString>
|
||||||
|
#include "libkdeconnect/dbusinterfaces.h"
|
||||||
|
|
||||||
|
//Wrapper to use it from QML
|
||||||
|
class BatteryInterface
|
||||||
|
: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString device READ device WRITE setDevice NOTIFY deviceChanged)
|
||||||
|
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||||
|
Q_PROPERTY(QString displayString READ displayString NOTIFY infoChanged)
|
||||||
|
//Q_PROPERTY(bool displayString READ isCharging NOTIFY infoChanged)
|
||||||
|
//Q_PROPERTY(int chargePercent READ chargePercent NOTIFY infoChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
BatteryInterface(QObject* parent = 0);
|
||||||
|
void setDevice(const QString& deviceId);
|
||||||
|
QString device() const { return m_device->id(); }
|
||||||
|
|
||||||
|
bool available() const; //True if the interface is accessible
|
||||||
|
|
||||||
|
QString displayString() const; //Human readable string with the battery status
|
||||||
|
bool isCharging() const { return m_battery->isCharging(); }
|
||||||
|
int chargePercent() const { return m_battery->charge(); }
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void availableChanged();
|
||||||
|
void infoChanged();
|
||||||
|
void deviceChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceDbusInterface* m_device;
|
||||||
|
mutable DeviceBatteryDbusInterface* m_battery;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void devicePluginsChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BATTERYINTERFACE_H
|
|
@ -24,10 +24,12 @@
|
||||||
|
|
||||||
#include "libkdeconnect/devicesmodel.h"
|
#include "libkdeconnect/devicesmodel.h"
|
||||||
#include "libkdeconnect/notificationsmodel.h"
|
#include "libkdeconnect/notificationsmodel.h"
|
||||||
|
#include "batteryinterface.h"
|
||||||
|
|
||||||
void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
||||||
{
|
{
|
||||||
Q_UNUSED(uri);
|
Q_UNUSED(uri);
|
||||||
qmlRegisterType<DevicesModel>("org.kde.kdeconnect", 1, 0, "DevicesModel");
|
qmlRegisterType<DevicesModel>("org.kde.kdeconnect", 1, 0, "DevicesModel");
|
||||||
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
||||||
|
qmlRegisterType<BatteryInterface>("org.kde.kdeconnect", 1, 0, "BatteryInterface");
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,33 @@ PlasmaComponents.ListItem
|
||||||
text: display
|
text: display
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Battery
|
||||||
|
PlasmaComponents.ListItem {
|
||||||
|
BatteryInterface {
|
||||||
|
id: batteryInterface
|
||||||
|
device: root.deviceId
|
||||||
|
}
|
||||||
|
sectionDelegate: true
|
||||||
|
visible: batteryInterface.available
|
||||||
|
PlasmaComponents.Label {
|
||||||
|
//font.bold: true
|
||||||
|
text: i18n("Battery")
|
||||||
|
}
|
||||||
|
PlasmaComponents.Label {
|
||||||
|
text: batteryInterface.displayString
|
||||||
|
anchors.right: parent.right
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
PlasmaComponents.ListItem {
|
PlasmaComponents.ListItem {
|
||||||
visible: notificationsModel.count>0
|
visible: notificationsModel.count>0
|
||||||
enabled: true
|
enabled: true
|
||||||
sectionDelegate: true
|
sectionDelegate: true
|
||||||
PlasmaComponents.Label { text: i18n("Notifications") }
|
PlasmaComponents.Label {
|
||||||
|
//font.bold: true
|
||||||
|
text: i18n("Notifications")
|
||||||
|
}
|
||||||
PlasmaComponents.ToolButton {
|
PlasmaComponents.ToolButton {
|
||||||
enabled: true
|
enabled: true
|
||||||
visible: notificationsModel.isAnyDimissable;
|
visible: notificationsModel.isAnyDimissable;
|
||||||
|
@ -79,11 +100,7 @@ PlasmaComponents.ListItem
|
||||||
//Repeater.onItemAdded: plasmoid.status = "NeedsAttentionStatus";
|
//Repeater.onItemAdded: plasmoid.status = "NeedsAttentionStatus";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Other information could be here (battery, etc.)
|
//TODO: Other information could be displayed here
|
||||||
/*PlasmaComponents.ListItem {
|
|
||||||
sectionDelegate: true
|
|
||||||
PlasmaComponents.Label { text: "This is some random info about the device" }
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,18 +35,25 @@ Item {
|
||||||
property Component compactRepresentation: CompactRepresentation { }
|
property Component compactRepresentation: CompactRepresentation { }
|
||||||
|
|
||||||
PlasmaComponents.Label {
|
PlasmaComponents.Label {
|
||||||
id: header
|
|
||||||
visible: devicesView.count==0
|
visible: devicesView.count==0
|
||||||
text: i18n("No paired devices available")
|
text: i18n("No paired devices available")
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
//Startup arguments
|
||||||
|
PlasmaComponents.Label {
|
||||||
|
visible: (startupArguments.length > 0)
|
||||||
|
text: (""+startupArguments)
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
PlasmaExtras.ScrollArea {
|
PlasmaExtras.ScrollArea {
|
||||||
id: dialogItem
|
id: dialogItem
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
|
||||||
flickableItem: ListView {
|
flickableItem: ListView {
|
||||||
id: devicesView
|
id: devicesView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
Loading…
Reference in a new issue