Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1cb1b264 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Moved DevicesModel and DBusInterfaces to libkdeconnect

Added NotificationsModel to libkdeconnect
parent a5805711
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)
......@@ -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);
......
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})
......
......@@ -19,7 +19,9 @@
*/
#include "devicessortproxymodel.h"
#include "devicesmodel.h"
#include "libkdeconnect/dbusinterfaces.h"
#include "libkdeconnect/devicesmodel.h"
#include <QDebug>
......
......@@ -21,7 +21,7 @@
#include "kcm.h"
#include "ui_kcm.h"
#include "ui_wizard.h"
#include "dbusinterfaces.h"
#include "libkdeconnect/dbusinterfaces.h"
#include <QtGui/QLabel>
#include <QtGui/QMenu>
......
......@@ -28,7 +28,7 @@
#include <ksharedconfig.h>
#include "wizard.h"
#include "devicesmodel.h"
#include "libkdeconnect/devicesmodel.h"
class QModelIndex;
class AccountsModel;
......
......@@ -24,8 +24,8 @@
#include <QWizard>
#include <QObject>
#include "dbusinterfaces.h"
#include "devicesmodel.h"
#include "../libkdeconnect/dbusinterfaces.h"
#include "../libkdeconnect/devicesmodel.h"
namespace Ui {
class Wizard;
......
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})
/**
* 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)
{
}
\ No newline at end of file
......@@ -18,17 +18,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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
......@@ -22,18 +22,17 @@
#include <ksharedconfig.h>
#include <QDebug>
#include <qdbusinterface.h>
#include <QDBusInterface>
#include <KConfigGroup>
#include <kicon.h>
#include <KIcon>
bool fetchNotifications = true;
DevicesModel::DevicesModel(QObject *parent)
: QAbstractListModel(parent)
, 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)),
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<QString> 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()) {
......
......@@ -26,9 +26,10 @@
#include <QAbstractListModel>
#include <QPixmap>
#include <QList>
#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);
......
......@@ -18,16 +18,11 @@
* 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)
: OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
{
#include <QtCore/QtGlobal>
}
#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
/**
* 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();
}
/**
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment