diff --git a/plasmoid/declarativeplugin/CMakeLists.txt b/plasmoid/declarativeplugin/CMakeLists.txt index ec99225a3..9e5f10ab1 100644 --- a/plasmoid/declarativeplugin/CMakeLists.txt +++ b/plasmoid/declarativeplugin/CMakeLists.txt @@ -3,8 +3,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) set(kdeconnectdeclarativeplugin_SRC + batteryinterface.cpp kdeconnectdeclarativeplugin.cpp ) + kde4_add_library(kdeconnectdeclarativeplugin SHARED ${kdeconnectdeclarativeplugin_SRC}) add_dependencies(kdeconnectdeclarativeplugin libkdeconnect) target_link_libraries(kdeconnectdeclarativeplugin diff --git a/plasmoid/declarativeplugin/batteryinterface.cpp b/plasmoid/declarativeplugin/batteryinterface.cpp new file mode 100644 index 000000000..4b8d0c9f3 --- /dev/null +++ b/plasmoid/declarativeplugin/batteryinterface.cpp @@ -0,0 +1,73 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#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()); + } + +} diff --git a/plasmoid/declarativeplugin/batteryinterface.h b/plasmoid/declarativeplugin/batteryinterface.h new file mode 100644 index 000000000..daf1c0d0c --- /dev/null +++ b/plasmoid/declarativeplugin/batteryinterface.h @@ -0,0 +1,65 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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 . + */ + +#ifndef BATTERYINTERFACE_H +#define BATTERYINTERFACE_H + +#include +#include +#include +#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 diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index 94c66eeee..bf3c54edb 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -24,10 +24,12 @@ #include "libkdeconnect/devicesmodel.h" #include "libkdeconnect/notificationsmodel.h" +#include "batteryinterface.h" void KdeConnectDeclarativePlugin::registerTypes(const char* uri) { Q_UNUSED(uri); qmlRegisterType("org.kde.kdeconnect", 1, 0, "DevicesModel"); qmlRegisterType("org.kde.kdeconnect", 1, 0, "NotificationsModel"); + qmlRegisterType("org.kde.kdeconnect", 1, 0, "BatteryInterface"); } diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 0ba38e6b8..fd5e97b2f 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -37,12 +37,33 @@ PlasmaComponents.ListItem 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 PlasmaComponents.ListItem { visible: notificationsModel.count>0 enabled: true sectionDelegate: true - PlasmaComponents.Label { text: i18n("Notifications") } + PlasmaComponents.Label { + //font.bold: true + text: i18n("Notifications") + } PlasmaComponents.ToolButton { enabled: true visible: notificationsModel.isAnyDimissable; @@ -79,11 +100,7 @@ PlasmaComponents.ListItem //Repeater.onItemAdded: plasmoid.status = "NeedsAttentionStatus"; } - //Other information could be here (battery, etc.) - /*PlasmaComponents.ListItem { - sectionDelegate: true - PlasmaComponents.Label { text: "This is some random info about the device" } - }*/ + //TODO: Other information could be displayed here } } diff --git a/plasmoid/package/contents/ui/kdeconnect.qml b/plasmoid/package/contents/ui/kdeconnect.qml index 4037a86b0..889afad32 100644 --- a/plasmoid/package/contents/ui/kdeconnect.qml +++ b/plasmoid/package/contents/ui/kdeconnect.qml @@ -35,18 +35,25 @@ Item { property Component compactRepresentation: CompactRepresentation { } PlasmaComponents.Label { - id: header visible: devicesView.count==0 text: i18n("No paired devices available") anchors.fill: parent horizontalAlignment: Text.AlignHCenter } + /* + //Startup arguments + PlasmaComponents.Label { + visible: (startupArguments.length > 0) + text: (""+startupArguments) + anchors.fill: parent + } + */ + PlasmaExtras.ScrollArea { id: dialogItem anchors.fill: parent - flickableItem: ListView { id: devicesView anchors.fill: parent