diff --git a/CMakeLists.txt b/CMakeLists.txt index e0feb636f..85de77dbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ project(kdeconnect) + cmake_minimum_required(VERSION 2.6) find_package(KDE4 REQUIRED) @@ -12,6 +13,9 @@ include_directories(${KDE4_INCLUDES}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(daemon) +add_subdirectory(libkdeconnect) add_subdirectory(kcm) +#add_subdirectory(kioslave) +add_subdirectory(plasmoid) add_subdirectory(test) diff --git a/daemon/plugins/notifications/notificationsdbusinterface.h b/daemon/plugins/notifications/notificationsdbusinterface.h index cd722ab65..38e42fbb0 100644 --- a/daemon/plugins/notifications/notificationsdbusinterface.h +++ b/daemon/plugins/notifications/notificationsdbusinterface.h @@ -46,8 +46,8 @@ public Q_SLOTS: void dismissRequested(Notification* notification); Q_SIGNALS: - void notificationPosted(const QString& publicId); - void notificationRemoved(const QString& publicId); + Q_SCRIPTABLE void notificationPosted(const QString& publicId); + Q_SCRIPTABLE void notificationRemoved(const QString& publicId); private /*methods*/: void addNotification(Notification* noti); diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt index 7796122bf..1afe7e2f9 100644 --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -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 #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_plugin(kcm_kdeconnect ${kcm_SRCS}) +add_dependencies(kcm_kdeconnect libkdeconnect) + target_link_libraries(kcm_kdeconnect ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDEUI_LIBRARY} ${KDE4_KCMUTILS_LIBS} -) - -add_dependencies(kcm_kdeconnect - org.kde.kdeconnect.daemon.xml - org.kde.kdeconnect.device.xml + kdeconnect ) install(TARGETS kcm_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/kcm/devicessortproxymodel.cpp b/kcm/devicessortproxymodel.cpp index d1d5cea16..d1041ce00 100644 --- a/kcm/devicessortproxymodel.cpp +++ b/kcm/devicessortproxymodel.cpp @@ -19,7 +19,9 @@ */ #include "devicessortproxymodel.h" -#include "devicesmodel.h" + +#include "libkdeconnect/dbusinterfaces.h" +#include "libkdeconnect/devicesmodel.h" #include diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 983cbdfc9..8d97e0ee0 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -21,7 +21,7 @@ #include "kcm.h" #include "ui_kcm.h" #include "ui_wizard.h" -#include "dbusinterfaces.h" +#include "libkdeconnect/dbusinterfaces.h" #include #include diff --git a/kcm/kcm.h b/kcm/kcm.h index 81a46aa81..2fc8fd1e8 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -28,7 +28,7 @@ #include #include "wizard.h" -#include "devicesmodel.h" +#include "libkdeconnect/devicesmodel.h" class QModelIndex; class AccountsModel; diff --git a/kcm/wizard.h b/kcm/wizard.h index 6f559aafc..41db776e7 100644 --- a/kcm/wizard.h +++ b/kcm/wizard.h @@ -24,8 +24,8 @@ #include #include -#include "dbusinterfaces.h" -#include "devicesmodel.h" +#include "../libkdeconnect/dbusinterfaces.h" +#include "../libkdeconnect/devicesmodel.h" namespace Ui { class Wizard; diff --git a/libkdeconnect/CMakeLists.txt b/libkdeconnect/CMakeLists.txt new file mode 100644 index 000000000..3710fb2a7 --- /dev/null +++ b/libkdeconnect/CMakeLists.txt @@ -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}) diff --git a/libkdeconnect/dbusinterfaces.cpp b/libkdeconnect/dbusinterfaces.cpp new file mode 100644 index 000000000..14ab9f092 --- /dev/null +++ b/libkdeconnect/dbusinterfaces.cpp @@ -0,0 +1,52 @@ +/** + * 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 "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) +{ + +} \ No newline at end of file diff --git a/kcm/dbusinterfaces.h b/libkdeconnect/dbusinterfaces.h similarity index 53% rename from kcm/dbusinterfaces.h rename to libkdeconnect/dbusinterfaces.h index 1a9fd3319..31472b03e 100644 --- a/kcm/dbusinterfaces.h +++ b/libkdeconnect/dbusinterfaces.h @@ -18,17 +18,22 @@ * along with this program. If not, see . */ -#include "daemoninterface.h" -#include "deviceinterface.h" +#ifndef DBUSINTERFACES_H +#define DBUSINTERFACES_H -#ifndef DbusInterfaces_H_ -#define DbusInterfaces_H_ +#include "kdeconnect_export.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 * interface, so we can change the class name in a single place. */ -class DaemonDbusInterface +class KDECONNECT_EXPORT DaemonDbusInterface : public OrgKdeKdeconnectDaemonInterface { Q_OBJECT @@ -37,7 +42,7 @@ public: }; -class DeviceDbusInterface +class KDECONNECT_EXPORT DeviceDbusInterface : public OrgKdeKdeconnectDeviceInterface { Q_OBJECT @@ -46,4 +51,32 @@ public: }; -#endif \ No newline at end of file +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 diff --git a/kcm/devicesmodel.cpp b/libkdeconnect/devicesmodel.cpp similarity index 88% rename from kcm/devicesmodel.cpp rename to libkdeconnect/devicesmodel.cpp index dc01bea5e..a1f08d671 100644 --- a/kcm/devicesmodel.cpp +++ b/libkdeconnect/devicesmodel.cpp @@ -22,18 +22,17 @@ #include #include -#include +#include + #include -#include +#include + +bool fetchNotifications = true; DevicesModel::DevicesModel(QObject *parent) : QAbstractListModel(parent) , m_dbusInterface(new DaemonDbusInterface(this)) { - QList deviceIds = m_dbusInterface->devices(); - Q_FOREACH(const QString& id, deviceIds) { - deviceAdded(id); - } connect(m_dbusInterface, SIGNAL(deviceAdded(QString)), this, SLOT(deviceAdded(QString))); @@ -41,6 +40,9 @@ DevicesModel::DevicesModel(QObject *parent) this, SLOT(deviceStatusChanged(QString))); connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString))); + + refreshDeviceList(); + } DevicesModel::~DevicesModel() @@ -49,18 +51,14 @@ DevicesModel::~DevicesModel() void DevicesModel::deviceAdded(const QString& id) { - /* - beginInsertRows(QModelIndex(), rowCount(), rowCount() + 1); - m_deviceList.append(new DeviceDbusInterface(id,this)); - endInsertRows(); - */ - + //TODO: Actually add instead of refresh Q_UNUSED(id); refreshDeviceList(); } void DevicesModel::deviceRemoved(const QString& id) { + //TODO: Actually remove instead of refresh Q_UNUSED(id); refreshDeviceList(); } @@ -77,17 +75,19 @@ void DevicesModel::refreshDeviceList() { if (m_deviceList.count() > 0) { - beginRemoveRows(QModelIndex(), 0, m_deviceList.count() - 1); + beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1); m_deviceList.clear(); endRemoveRows(); } QList deviceIds = m_dbusInterface->devices(); + beginInsertRows(QModelIndex(), 0, deviceIds.size()-1); Q_FOREACH(const QString& id, deviceIds) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_deviceList.append(new DeviceDbusInterface(id,this)); - endInsertRows(); + DeviceDbusInterface* deviceDbusInterface = new DeviceDbusInterface(id,this); + m_deviceList.append(deviceDbusInterface); } + endInsertRows(); + 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()); case NameModelRole: return QString(device->name()); + case Qt::ToolTipRole: + return QVariant(); //To implement case StatusModelRole: { int status = StatusUnknown; if (device->reachable()) { diff --git a/kcm/devicesmodel.h b/libkdeconnect/devicesmodel.h similarity index 96% rename from kcm/devicesmodel.h rename to libkdeconnect/devicesmodel.h index 3271a738c..189c2ff1b 100644 --- a/kcm/devicesmodel.h +++ b/libkdeconnect/devicesmodel.h @@ -26,9 +26,10 @@ #include #include #include -#include "dbusinterfaces.h" -class DevicesModel +#include "libkdeconnect/dbusinterfaces.h" + +class KDECONNECT_EXPORT DevicesModel : public QAbstractListModel { Q_OBJECT @@ -43,7 +44,6 @@ public: StatusUnknown = 0x00, StatusPaired = 0x01, StatusReachable = 0x10, - }; DevicesModel(QObject *parent = 0); diff --git a/kcm/dbusinterfaces.cpp b/libkdeconnect/kdeconnect_export.h similarity index 68% rename from kcm/dbusinterfaces.cpp rename to libkdeconnect/kdeconnect_export.h index 70b6df40e..56c2459ec 100644 --- a/kcm/dbusinterfaces.cpp +++ b/libkdeconnect/kdeconnect_export.h @@ -18,16 +18,11 @@ * along with this program. If not, see . */ -#include "dbusinterfaces.h" +#ifndef KDECONNECT_EXPORT_H +#define KDECONNECT_EXPORT_H -DaemonDbusInterface::DaemonDbusInterface(QObject* parent) - : OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent) -{ +#include -} +#define KDECONNECT_EXPORT Q_DECL_EXPORT -DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) -{ - -} \ No newline at end of file +#endif diff --git a/libkdeconnect/notificationsmodel.cpp b/libkdeconnect/notificationsmodel.cpp new file mode 100644 index 000000000..0f946d115 --- /dev/null +++ b/libkdeconnect/notificationsmodel.cpp @@ -0,0 +1,145 @@ +/** + * 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 "notificationsmodel.h" +#include + +#include +#include + +#include +#include + +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 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(); +} + diff --git a/libkdeconnect/notificationsmodel.h b/libkdeconnect/notificationsmodel.h new file mode 100644 index 000000000..0b47cf6b3 --- /dev/null +++ b/libkdeconnect/notificationsmodel.h @@ -0,0 +1,62 @@ +/** + * 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 NOTIFICATIONSMODEL_H +#define NOTIFICATIONSMODEL_H + +#include +#include +#include +#include + +#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 m_notificationList; + QString m_deviceId; +}; + +#endif // DEVICESMODEL_H