Moved DevicesModel and DBusInterfaces to libkdeconnect
Added NotificationsModel to libkdeconnect
This commit is contained in:
parent
a58057118c
commit
1cb1b26415
15 changed files with 400 additions and 62 deletions
|
@ -1,4 +1,5 @@
|
||||||
project(kdeconnect)
|
project(kdeconnect)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
|
||||||
find_package(KDE4 REQUIRED)
|
find_package(KDE4 REQUIRED)
|
||||||
|
@ -12,6 +13,9 @@ include_directories(${KDE4_INCLUDES})
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_subdirectory(daemon)
|
add_subdirectory(daemon)
|
||||||
|
add_subdirectory(libkdeconnect)
|
||||||
add_subdirectory(kcm)
|
add_subdirectory(kcm)
|
||||||
|
#add_subdirectory(kioslave)
|
||||||
|
add_subdirectory(plasmoid)
|
||||||
|
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
|
@ -46,8 +46,8 @@ public Q_SLOTS:
|
||||||
void dismissRequested(Notification* notification);
|
void dismissRequested(Notification* notification);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void notificationPosted(const QString& publicId);
|
Q_SCRIPTABLE void notificationPosted(const QString& publicId);
|
||||||
void notificationRemoved(const QString& publicId);
|
Q_SCRIPTABLE void notificationRemoved(const QString& publicId);
|
||||||
|
|
||||||
private /*methods*/:
|
private /*methods*/:
|
||||||
void addNotification(Notification* noti);
|
void addNotification(Notification* noti);
|
||||||
|
|
|
@ -1,36 +1,26 @@
|
||||||
|
|
||||||
set(kcm_SRCS devicessortproxymodel.cpp devicesmodel.cpp
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}
|
||||||
|
${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
set(kcm_SRCS devicessortproxymodel.cpp
|
||||||
kcm.cpp
|
kcm.cpp
|
||||||
#wizard.cpp
|
#wizard.cpp
|
||||||
dbusinterfaces.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
qt4_add_dbus_interface(
|
|
||||||
kcm_SRCS
|
|
||||||
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.daemon.xml
|
|
||||||
daemoninterface
|
|
||||||
)
|
|
||||||
|
|
||||||
qt4_add_dbus_interface(
|
|
||||||
kcm_SRCS
|
|
||||||
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.device.xml
|
|
||||||
deviceinterface
|
|
||||||
)
|
)
|
||||||
|
|
||||||
kde4_add_ui_files(kcm_SRCS kcm.ui wizard.ui)
|
kde4_add_ui_files(kcm_SRCS kcm.ui wizard.ui)
|
||||||
|
|
||||||
kde4_add_plugin(kcm_kdeconnect ${kcm_SRCS})
|
kde4_add_plugin(kcm_kdeconnect ${kcm_SRCS})
|
||||||
|
|
||||||
|
add_dependencies(kcm_kdeconnect libkdeconnect)
|
||||||
|
|
||||||
target_link_libraries(kcm_kdeconnect
|
target_link_libraries(kcm_kdeconnect
|
||||||
${QT_QTCORE_LIBRARY}
|
${QT_QTCORE_LIBRARY}
|
||||||
${QT_QTGUI_LIBRARY}
|
${QT_QTGUI_LIBRARY}
|
||||||
${KDE4_KDEUI_LIBRARY}
|
${KDE4_KDEUI_LIBRARY}
|
||||||
${KDE4_KCMUTILS_LIBS}
|
${KDE4_KCMUTILS_LIBS}
|
||||||
)
|
kdeconnect
|
||||||
|
|
||||||
add_dependencies(kcm_kdeconnect
|
|
||||||
org.kde.kdeconnect.daemon.xml
|
|
||||||
org.kde.kdeconnect.device.xml
|
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS kcm_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
|
install(TARGETS kcm_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "devicessortproxymodel.h"
|
#include "devicessortproxymodel.h"
|
||||||
#include "devicesmodel.h"
|
|
||||||
|
#include "libkdeconnect/dbusinterfaces.h"
|
||||||
|
#include "libkdeconnect/devicesmodel.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "kcm.h"
|
#include "kcm.h"
|
||||||
#include "ui_kcm.h"
|
#include "ui_kcm.h"
|
||||||
#include "ui_wizard.h"
|
#include "ui_wizard.h"
|
||||||
#include "dbusinterfaces.h"
|
#include "libkdeconnect/dbusinterfaces.h"
|
||||||
|
|
||||||
#include <QtGui/QLabel>
|
#include <QtGui/QLabel>
|
||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <ksharedconfig.h>
|
#include <ksharedconfig.h>
|
||||||
|
|
||||||
#include "wizard.h"
|
#include "wizard.h"
|
||||||
#include "devicesmodel.h"
|
#include "libkdeconnect/devicesmodel.h"
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class AccountsModel;
|
class AccountsModel;
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <QWizard>
|
#include <QWizard>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "dbusinterfaces.h"
|
#include "../libkdeconnect/dbusinterfaces.h"
|
||||||
#include "devicesmodel.h"
|
#include "../libkdeconnect/devicesmodel.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Wizard;
|
class Wizard;
|
||||||
|
|
53
libkdeconnect/CMakeLists.txt
Normal file
53
libkdeconnect/CMakeLists.txt
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
set(likdeconnect_VERSION_MAJOR 1)
|
||||||
|
set(likdeconnect_VERSION_MINOR 0)
|
||||||
|
set(likdeconnect_VERSION_RELEASE 1)
|
||||||
|
set(likdeconnect_VERSION "${likdeconnect_VERSION_MAJOR}.${likdeconnect_VERSION_MINOR}.${likdeconnect_VERSION_RELEASE}")
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
set(libkdeconnect_SRC
|
||||||
|
dbusinterfaces.cpp
|
||||||
|
devicesmodel.cpp
|
||||||
|
notificationsmodel.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set_source_files_properties(
|
||||||
|
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.daemon.xml
|
||||||
|
${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.device.xml
|
||||||
|
${CMAKE_BINARY_DIR}/daemon/plugins/battery/org.kde.kdeconnect.device.battery.xml
|
||||||
|
${CMAKE_BINARY_DIR}/daemon/plugins/notifications/org.kde.kdeconnect.device.notifications.xml
|
||||||
|
${CMAKE_BINARY_DIR}/daemon/plugins/notifications/org.kde.kdeconnect.device.notifications.notification.xml
|
||||||
|
PROPERTIES NO_NAMESPACE true
|
||||||
|
)
|
||||||
|
qt4_add_dbus_interface(libkdeconnect_SRC ${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.daemon.xml daemoninterface)
|
||||||
|
qt4_add_dbus_interface(libkdeconnect_SRC ${CMAKE_BINARY_DIR}/daemon/org.kde.kdeconnect.device.xml deviceinterface)
|
||||||
|
qt4_add_dbus_interface(libkdeconnect_SRC ${CMAKE_BINARY_DIR}/daemon/plugins/battery/org.kde.kdeconnect.device.battery.xml devicebatteryinterface )
|
||||||
|
qt4_add_dbus_interface(libkdeconnect_SRC ${CMAKE_BINARY_DIR}/daemon/plugins/notifications/org.kde.kdeconnect.device.notifications.xml devicenotificationsinterface )
|
||||||
|
qt4_add_dbus_interface(libkdeconnect_SRC ${CMAKE_BINARY_DIR}/daemon/plugins/notifications/org.kde.kdeconnect.device.notifications.notification.xml notificationinterface )
|
||||||
|
|
||||||
|
kde4_add_library(kdeconnect SHARED ${libkdeconnect_SRC})
|
||||||
|
set_target_properties(kdeconnect PROPERTIES
|
||||||
|
VERSION ${likdeconnect_VERSION}
|
||||||
|
SOVERSION ${likdeconnect_VERSION_MAJOR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(kdeconnect
|
||||||
|
org.kde.kdeconnect.daemon.xml
|
||||||
|
org.kde.kdeconnect.device.xml
|
||||||
|
org.kde.kdeconnect.device.battery.xml
|
||||||
|
org.kde.kdeconnect.device.notifications.xml
|
||||||
|
org.kde.kdeconnect.device.notifications.notification.xml
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(kdeconnect
|
||||||
|
${KDE4_KDEUI_LIBS}
|
||||||
|
${QT_QTCORE_LIBRARY}
|
||||||
|
${QT_QTDBUS_LIBRARY}
|
||||||
|
${KDE4_KDECORE_LIBS}
|
||||||
|
${QJSON_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS kdeconnect EXPORT kdeconnectLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
|
52
libkdeconnect/dbusinterfaces.cpp
Normal file
52
libkdeconnect/dbusinterfaces.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* 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 "dbusinterfaces.h"
|
||||||
|
|
||||||
|
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
|
||||||
|
: OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent)
|
||||||
|
: OrgKdeKdeconnectDeviceInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceBatteryDbusInterface::DeviceBatteryDbusInterface(const QString& id, QObject* parent)
|
||||||
|
: OrgKdeKdeconnectDeviceBatteryInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString& id, QObject* parent)
|
||||||
|
: OrgKdeKdeconnectDeviceNotificationsInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent)
|
||||||
|
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -18,17 +18,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "daemoninterface.h"
|
#ifndef DBUSINTERFACES_H
|
||||||
#include "deviceinterface.h"
|
#define DBUSINTERFACES_H
|
||||||
|
|
||||||
#ifndef DbusInterfaces_H_
|
#include "kdeconnect_export.h"
|
||||||
#define DbusInterfaces_H_
|
|
||||||
|
#include "libkdeconnect/daemoninterface.h"
|
||||||
|
#include "libkdeconnect/deviceinterface.h"
|
||||||
|
#include "libkdeconnect/devicebatteryinterface.h"
|
||||||
|
#include "libkdeconnect/devicenotificationsinterface.h"
|
||||||
|
#include "libkdeconnect/notificationinterface.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using these "proxy" classes just in case we need to rename the
|
* Using these "proxy" classes just in case we need to rename the
|
||||||
* interface, so we can change the class name in a single place.
|
* interface, so we can change the class name in a single place.
|
||||||
*/
|
*/
|
||||||
class DaemonDbusInterface
|
class KDECONNECT_EXPORT DaemonDbusInterface
|
||||||
: public OrgKdeKdeconnectDaemonInterface
|
: public OrgKdeKdeconnectDaemonInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -37,7 +42,7 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceDbusInterface
|
class KDECONNECT_EXPORT DeviceDbusInterface
|
||||||
: public OrgKdeKdeconnectDeviceInterface
|
: public OrgKdeKdeconnectDeviceInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -46,4 +51,32 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
class KDECONNECT_EXPORT DeviceBatteryDbusInterface
|
||||||
|
: public OrgKdeKdeconnectDeviceBatteryInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DeviceBatteryDbusInterface(const QString& id, QObject* parent);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class KDECONNECT_EXPORT DeviceNotificationsDbusInterface
|
||||||
|
: public OrgKdeKdeconnectDeviceNotificationsInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DeviceNotificationsDbusInterface(const QString& id, QObject* parent);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class KDECONNECT_EXPORT NotificationDbusInterface
|
||||||
|
: public OrgKdeKdeconnectDeviceNotificationsNotificationInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DEVICEINTERFACE_H
|
|
@ -22,18 +22,17 @@
|
||||||
#include <ksharedconfig.h>
|
#include <ksharedconfig.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <qdbusinterface.h>
|
#include <QDBusInterface>
|
||||||
|
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#include <kicon.h>
|
#include <KIcon>
|
||||||
|
|
||||||
|
bool fetchNotifications = true;
|
||||||
|
|
||||||
DevicesModel::DevicesModel(QObject *parent)
|
DevicesModel::DevicesModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_dbusInterface(new DaemonDbusInterface(this))
|
, m_dbusInterface(new DaemonDbusInterface(this))
|
||||||
{
|
{
|
||||||
QList<QString> deviceIds = m_dbusInterface->devices();
|
|
||||||
Q_FOREACH(const QString& id, deviceIds) {
|
|
||||||
deviceAdded(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_dbusInterface, SIGNAL(deviceAdded(QString)),
|
connect(m_dbusInterface, SIGNAL(deviceAdded(QString)),
|
||||||
this, SLOT(deviceAdded(QString)));
|
this, SLOT(deviceAdded(QString)));
|
||||||
|
@ -41,6 +40,9 @@ DevicesModel::DevicesModel(QObject *parent)
|
||||||
this, SLOT(deviceStatusChanged(QString)));
|
this, SLOT(deviceStatusChanged(QString)));
|
||||||
connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)),
|
connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)),
|
||||||
this, SLOT(deviceRemoved(QString)));
|
this, SLOT(deviceRemoved(QString)));
|
||||||
|
|
||||||
|
refreshDeviceList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesModel::~DevicesModel()
|
DevicesModel::~DevicesModel()
|
||||||
|
@ -49,18 +51,14 @@ DevicesModel::~DevicesModel()
|
||||||
|
|
||||||
void DevicesModel::deviceAdded(const QString& id)
|
void DevicesModel::deviceAdded(const QString& id)
|
||||||
{
|
{
|
||||||
/*
|
//TODO: Actually add instead of refresh
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount() + 1);
|
|
||||||
m_deviceList.append(new DeviceDbusInterface(id,this));
|
|
||||||
endInsertRows();
|
|
||||||
*/
|
|
||||||
|
|
||||||
Q_UNUSED(id);
|
Q_UNUSED(id);
|
||||||
refreshDeviceList();
|
refreshDeviceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesModel::deviceRemoved(const QString& id)
|
void DevicesModel::deviceRemoved(const QString& id)
|
||||||
{
|
{
|
||||||
|
//TODO: Actually remove instead of refresh
|
||||||
Q_UNUSED(id);
|
Q_UNUSED(id);
|
||||||
refreshDeviceList();
|
refreshDeviceList();
|
||||||
}
|
}
|
||||||
|
@ -77,17 +75,19 @@ void DevicesModel::refreshDeviceList()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_deviceList.count() > 0) {
|
if (m_deviceList.count() > 0) {
|
||||||
beginRemoveRows(QModelIndex(), 0, m_deviceList.count() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
|
||||||
m_deviceList.clear();
|
m_deviceList.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> deviceIds = m_dbusInterface->devices();
|
QList<QString> deviceIds = m_dbusInterface->devices();
|
||||||
|
beginInsertRows(QModelIndex(), 0, deviceIds.size()-1);
|
||||||
Q_FOREACH(const QString& id, deviceIds) {
|
Q_FOREACH(const QString& id, deviceIds) {
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
DeviceDbusInterface* deviceDbusInterface = new DeviceDbusInterface(id,this);
|
||||||
m_deviceList.append(new DeviceDbusInterface(id,this));
|
m_deviceList.append(deviceDbusInterface);
|
||||||
endInsertRows();
|
|
||||||
}
|
}
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
|
||||||
Q_EMIT dataChanged(index(0), index(deviceIds.count()));
|
Q_EMIT dataChanged(index(0), index(deviceIds.count()));
|
||||||
|
|
||||||
|
@ -128,6 +128,8 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
||||||
return QString(device->id());
|
return QString(device->id());
|
||||||
case NameModelRole:
|
case NameModelRole:
|
||||||
return QString(device->name());
|
return QString(device->name());
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
return QVariant(); //To implement
|
||||||
case StatusModelRole: {
|
case StatusModelRole: {
|
||||||
int status = StatusUnknown;
|
int status = StatusUnknown;
|
||||||
if (device->reachable()) {
|
if (device->reachable()) {
|
|
@ -26,9 +26,10 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "dbusinterfaces.h"
|
|
||||||
|
|
||||||
class DevicesModel
|
#include "libkdeconnect/dbusinterfaces.h"
|
||||||
|
|
||||||
|
class KDECONNECT_EXPORT DevicesModel
|
||||||
: public QAbstractListModel
|
: public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -43,7 +44,6 @@ public:
|
||||||
StatusUnknown = 0x00,
|
StatusUnknown = 0x00,
|
||||||
StatusPaired = 0x01,
|
StatusPaired = 0x01,
|
||||||
StatusReachable = 0x10,
|
StatusReachable = 0x10,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DevicesModel(QObject *parent = 0);
|
DevicesModel(QObject *parent = 0);
|
|
@ -18,16 +18,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dbusinterfaces.h"
|
#ifndef KDECONNECT_EXPORT_H
|
||||||
|
#define KDECONNECT_EXPORT_H
|
||||||
|
|
||||||
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
|
#include <QtCore/QtGlobal>
|
||||||
: OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
#define KDECONNECT_EXPORT Q_DECL_EXPORT
|
||||||
|
|
||||||
DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent)
|
#endif
|
||||||
: OrgKdeKdeconnectDeviceInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
145
libkdeconnect/notificationsmodel.cpp
Normal file
145
libkdeconnect/notificationsmodel.cpp
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
/**
|
||||||
|
* 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 "notificationsmodel.h"
|
||||||
|
#include <ksharedconfig.h>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
|
||||||
|
#include <KConfigGroup>
|
||||||
|
#include <KIcon>
|
||||||
|
|
||||||
|
NotificationsModel::NotificationsModel(const QString& deviceId, QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
, m_dbusInterface(new DeviceNotificationsDbusInterface(deviceId, this))
|
||||||
|
, m_deviceId(deviceId)
|
||||||
|
{
|
||||||
|
|
||||||
|
connect(m_dbusInterface, SIGNAL(notificationPosted(QString)),
|
||||||
|
this, SLOT(notificationAdded(QString)));
|
||||||
|
connect(m_dbusInterface, SIGNAL(notificationRemoved(QString)),
|
||||||
|
this, SLOT(notificationRemoved(QString)));
|
||||||
|
|
||||||
|
refreshNotificationList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationsModel::~NotificationsModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationsModel::notificationAdded(const QString& id)
|
||||||
|
{
|
||||||
|
//TODO: Actually add instead of refresh
|
||||||
|
Q_UNUSED(id);
|
||||||
|
refreshNotificationList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationsModel::notificationRemoved(const QString& id)
|
||||||
|
{
|
||||||
|
//TODO: Actually remove instead of refresh
|
||||||
|
Q_UNUSED(id);
|
||||||
|
refreshNotificationList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationsModel::refreshNotificationList()
|
||||||
|
{
|
||||||
|
if (m_notificationList.count() > 0) {
|
||||||
|
beginRemoveRows(QModelIndex(), 0, m_notificationList.size() - 1);
|
||||||
|
m_notificationList.clear();
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QString> notificationIds = m_dbusInterface->activeNotifications();
|
||||||
|
beginInsertRows(QModelIndex(), 0, notificationIds.size()-1);
|
||||||
|
Q_FOREACH(const QString& notificationId, notificationIds) {
|
||||||
|
NotificationDbusInterface* dbusInterface = new NotificationDbusInterface(m_deviceId,notificationId,this);
|
||||||
|
m_notificationList.append(dbusInterface);
|
||||||
|
}
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
|
||||||
|
Q_EMIT dataChanged(index(0), index(notificationIds.count()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant NotificationsModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!m_dbusInterface->isValid()) {
|
||||||
|
switch (role) {
|
||||||
|
case IconModelRole:
|
||||||
|
return KIcon("dialog-close").pixmap(32, 32);
|
||||||
|
case NameModelRole:
|
||||||
|
return QString("KDED not running");
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!index.isValid()
|
||||||
|
|| index.row() < 0
|
||||||
|
|| index.row() >= m_notificationList.count()
|
||||||
|
|| !m_notificationList[index.row()]->isValid())
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDbusInterface* notification = m_notificationList[index.row()];
|
||||||
|
|
||||||
|
//FIXME: This function gets called lots of times, producing lots of dbus calls. Add a cache.
|
||||||
|
switch (role) {
|
||||||
|
case IconModelRole:
|
||||||
|
return KIcon("device-notifier").pixmap(32, 32);
|
||||||
|
case IdModelRole:
|
||||||
|
return QString(notification->internalId());
|
||||||
|
case NameModelRole:
|
||||||
|
return QString(notification->ticker());
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
return QVariant(); //To implement
|
||||||
|
case ContentModelRole: {
|
||||||
|
return QString("AAAAAA"); //To implement
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDbusInterface* NotificationsModel::getNotification(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int row = index.row();
|
||||||
|
if (row < 0 || row >= m_notificationList.size()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_notificationList[row];
|
||||||
|
}
|
||||||
|
|
||||||
|
int NotificationsModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent);
|
||||||
|
|
||||||
|
return m_notificationList.count();
|
||||||
|
}
|
||||||
|
|
62
libkdeconnect/notificationsmodel.h
Normal file
62
libkdeconnect/notificationsmodel.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* 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 NOTIFICATIONSMODEL_H
|
||||||
|
#define NOTIFICATIONSMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
#include "libkdeconnect/dbusinterfaces.h"
|
||||||
|
|
||||||
|
class KDECONNECT_EXPORT NotificationsModel
|
||||||
|
: public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum ModelRoles {
|
||||||
|
IconModelRole = Qt::DecorationRole,
|
||||||
|
NameModelRole = Qt::DisplayRole,
|
||||||
|
ContentModelRole = Qt::UserRole,
|
||||||
|
IdModelRole = Qt::UserRole + 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationsModel(const QString& deviceId = "", QObject *parent = 0);
|
||||||
|
virtual ~NotificationsModel();
|
||||||
|
|
||||||
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
|
NotificationDbusInterface* getNotification(const QModelIndex&);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void notificationAdded(const QString& id);
|
||||||
|
void notificationRemoved(const QString& id);
|
||||||
|
void refreshNotificationList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceNotificationsDbusInterface* m_dbusInterface;
|
||||||
|
QList<NotificationDbusInterface*> m_notificationList;
|
||||||
|
QString m_deviceId;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICESMODEL_H
|
Loading…
Reference in a new issue