libkdeconnect: Fixed some style issues.
Conflicts: libkdeconnect/devicesmodel.cpp libkdeconnect/devicesmodel.h libkdeconnect/notificationsmodel.cpp libkdeconnect/notificationsmodel.h
This commit is contained in:
parent
384b6d8be0
commit
8777cc9d76
4 changed files with 42 additions and 36 deletions
|
@ -55,7 +55,6 @@ DevicesModel::DevicesModel(QObject *parent)
|
||||||
QHash<int, QByteArray> names = roleNames();
|
QHash<int, QByteArray> names = roleNames();
|
||||||
names.insert(IdModelRole, "deviceId");
|
names.insert(IdModelRole, "deviceId");
|
||||||
setRoleNames(names);
|
setRoleNames(names);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesModel::~DevicesModel()
|
DevicesModel::~DevicesModel()
|
||||||
|
@ -83,6 +82,7 @@ void DevicesModel::deviceStatusChanged(const QString& id)
|
||||||
//Q_EMIT dataChanged(index(0),index(rowCount()));
|
//Q_EMIT dataChanged(index(0),index(rowCount()));
|
||||||
refreshDeviceList();
|
refreshDeviceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesModel::StatusFlags DevicesModel::displayFilter() const
|
DevicesModel::StatusFlags DevicesModel::displayFilter() const
|
||||||
{
|
{
|
||||||
return m_displayFilter;
|
return m_displayFilter;
|
||||||
|
@ -101,7 +101,6 @@ void DevicesModel::setDisplayFilter(DevicesModel::StatusFlags flags)
|
||||||
|
|
||||||
void DevicesModel::refreshDeviceList()
|
void DevicesModel::refreshDeviceList()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_deviceList.isEmpty()) {
|
if (!m_deviceList.isEmpty()) {
|
||||||
beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
|
||||||
m_deviceList.clear();
|
m_deviceList.clear();
|
||||||
|
@ -130,10 +129,9 @@ void DevicesModel::refreshDeviceList()
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
|
Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
QVariant DevicesModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
if (!m_dbusInterface->isValid()
|
if (!m_dbusInterface->isValid()
|
||||||
|| !index.isValid()
|
|| !index.isValid()
|
||||||
|
@ -173,7 +171,7 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceDbusInterface *DevicesModel::getDevice(const QModelIndex &index) const
|
DeviceDbusInterface* DevicesModel::getDevice(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -187,7 +185,7 @@ DeviceDbusInterface *DevicesModel::getDevice(const QModelIndex &index) const
|
||||||
return m_deviceList[row];
|
return m_deviceList[row];
|
||||||
}
|
}
|
||||||
|
|
||||||
int DevicesModel::rowCount(const QModelIndex &parent) const
|
int DevicesModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if(parent.isValid()) {
|
if(parent.isValid()) {
|
||||||
//Return size 0 if we are a child because this is not a tree
|
//Return size 0 if we are a child because this is not a tree
|
||||||
|
@ -196,4 +194,3 @@ int DevicesModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
return m_deviceList.size();
|
return m_deviceList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#ifndef DEVICESMODEL_H
|
#ifndef DEVICESMODEL_H
|
||||||
#define DEVICESMODEL_H
|
#define DEVICESMODEL_H
|
||||||
|
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
@ -56,10 +55,10 @@ public:
|
||||||
void setDisplayFilter(int flags);
|
void setDisplayFilter(int flags);
|
||||||
StatusFlags displayFilter() const;
|
StatusFlags displayFilter() const;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
|
|
||||||
DeviceDbusInterface *getDevice(const QModelIndex &index) const;
|
DeviceDbusInterface* getDevice(const QModelIndex& index) const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void deviceStatusChanged(const QString& id);
|
void deviceStatusChanged(const QString& id);
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "modeltest.h"
|
#include "modeltest.h"
|
||||||
#include "kdebugnamespace.h"
|
#include "kdebugnamespace.h"
|
||||||
|
|
||||||
NotificationsModel::NotificationsModel(QObject *parent)
|
NotificationsModel::NotificationsModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_dbusInterface(0)
|
, m_dbusInterface(0)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ NotificationsModel::NotificationsModel(QObject *parent)
|
||||||
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
||||||
this, SIGNAL(rowsChanged()));
|
this, SIGNAL(rowsChanged()));
|
||||||
|
|
||||||
connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
||||||
this, SIGNAL(anyDismissableChanged()));
|
this, SIGNAL(anyDismissableChanged()));
|
||||||
|
|
||||||
//Role names for QML
|
//Role names for QML
|
||||||
|
@ -66,7 +66,10 @@ void NotificationsModel::setDeviceId(const QString& deviceId)
|
||||||
{
|
{
|
||||||
m_deviceId = deviceId;
|
m_deviceId = deviceId;
|
||||||
|
|
||||||
if (m_dbusInterface) delete m_dbusInterface;
|
if (m_dbusInterface) {
|
||||||
|
delete m_dbusInterface;
|
||||||
|
}
|
||||||
|
|
||||||
m_dbusInterface = new DeviceNotificationsDbusInterface(deviceId, this);
|
m_dbusInterface = new DeviceNotificationsDbusInterface(deviceId, this);
|
||||||
|
|
||||||
connect(m_dbusInterface, SIGNAL(notificationPosted(QString)),
|
connect(m_dbusInterface, SIGNAL(notificationPosted(QString)),
|
||||||
|
@ -95,7 +98,9 @@ void NotificationsModel::notificationRemoved(const QString& id)
|
||||||
|
|
||||||
void NotificationsModel::refreshNotificationList()
|
void NotificationsModel::refreshNotificationList()
|
||||||
{
|
{
|
||||||
if (!m_dbusInterface) return;
|
if (!m_dbusInterface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_notificationList.isEmpty()) {
|
if (!m_notificationList.isEmpty()) {
|
||||||
beginRemoveRows(QModelIndex(), 0, m_notificationList.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_notificationList.size() - 1);
|
||||||
|
@ -104,28 +109,33 @@ void NotificationsModel::refreshNotificationList()
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_dbusInterface->isValid()) return;
|
if (!m_dbusInterface->isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QDBusPendingReply<QStringList> pendingNotificationIds = m_dbusInterface->activeNotifications();
|
QDBusPendingReply<QStringList> pendingNotificationIds = m_dbusInterface->activeNotifications();
|
||||||
pendingNotificationIds.waitForFinished();
|
pendingNotificationIds.waitForFinished();
|
||||||
if (pendingNotificationIds.isError()) return;
|
if (pendingNotificationIds.isError()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const QStringList& notificationIds = pendingNotificationIds.value();
|
const QStringList& notificationIds = pendingNotificationIds.value();
|
||||||
|
|
||||||
if (notificationIds.isEmpty()) return;
|
if (notificationIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), 0, notificationIds.size()-1);
|
beginInsertRows(QModelIndex(), 0, notificationIds.size() - 1);
|
||||||
Q_FOREACH(const QString& notificationId, notificationIds) {
|
Q_FOREACH (const QString& notificationId, notificationIds) {
|
||||||
NotificationDbusInterface* dbusInterface = new NotificationDbusInterface(m_deviceId, notificationId, this);
|
NotificationDbusInterface* dbusInterface = new NotificationDbusInterface(m_deviceId, notificationId, this);
|
||||||
m_notificationList.append(dbusInterface);
|
m_notificationList.append(dbusInterface);
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
Q_EMIT dataChanged(index(0), index(notificationIds.size()-1));
|
Q_EMIT dataChanged(index(0), index(notificationIds.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant NotificationsModel::data(const QModelIndex &index, int role) const
|
QVariant NotificationsModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!index.isValid()
|
if (!index.isValid()
|
||||||
|| index.row() < 0
|
|| index.row() < 0
|
||||||
|| index.row() >= m_notificationList.count()
|
|| index.row() >= m_notificationList.count()
|
||||||
|
@ -161,7 +171,7 @@ QVariant NotificationsModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationDbusInterface *NotificationsModel::getNotification(const QModelIndex &index) const
|
NotificationDbusInterface* NotificationsModel::getNotification(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -175,9 +185,9 @@ NotificationDbusInterface *NotificationsModel::getNotification(const QModelIndex
|
||||||
return m_notificationList[row];
|
return m_notificationList[row];
|
||||||
}
|
}
|
||||||
|
|
||||||
int NotificationsModel::rowCount(const QModelIndex &parent) const
|
int NotificationsModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if(parent.isValid()) {
|
if (parent.isValid()) {
|
||||||
//Return size 0 if we are a child because this is not a tree
|
//Return size 0 if we are a child because this is not a tree
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +197,7 @@ int NotificationsModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
bool NotificationsModel::isAnyDimissable() const
|
bool NotificationsModel::isAnyDimissable() const
|
||||||
{
|
{
|
||||||
Q_FOREACH(NotificationDbusInterface* notification, m_notificationList) {
|
Q_FOREACH (NotificationDbusInterface* notification, m_notificationList) {
|
||||||
if (notification->dismissable()) {
|
if (notification->dismissable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +208,7 @@ bool NotificationsModel::isAnyDimissable() const
|
||||||
|
|
||||||
void NotificationsModel::dismissAll()
|
void NotificationsModel::dismissAll()
|
||||||
{
|
{
|
||||||
Q_FOREACH(NotificationDbusInterface* notification, m_notificationList) {
|
Q_FOREACH (NotificationDbusInterface* notification, m_notificationList) {
|
||||||
if (notification->dismissable()) {
|
if (notification->dismissable()) {
|
||||||
notification->dismiss();
|
notification->dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,16 +38,16 @@ class KDECONNECT_EXPORT NotificationsModel
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ModelRoles {
|
enum ModelRoles {
|
||||||
IconModelRole = Qt::DecorationRole,
|
IconModelRole = Qt::DecorationRole,
|
||||||
NameModelRole = Qt::DisplayRole,
|
NameModelRole = Qt::DisplayRole,
|
||||||
ContentModelRole = Qt::UserRole,
|
ContentModelRole = Qt::UserRole,
|
||||||
AppNameModelRole = Qt::UserRole+1,
|
AppNameModelRole = Qt::UserRole + 1,
|
||||||
IdModelRole = Qt::UserRole+2,
|
IdModelRole = Qt::UserRole + 2,
|
||||||
DismissableModelRole = Qt::UserRole+3,
|
DismissableModelRole = Qt::UserRole + 3,
|
||||||
DbusInterfaceRole = Qt::UserRole+4,
|
DbusInterfaceRole = Qt::UserRole + 4
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationsModel(QObject *parent = 0);
|
NotificationsModel(QObject* parent = 0);
|
||||||
virtual ~NotificationsModel();
|
virtual ~NotificationsModel();
|
||||||
|
|
||||||
QString deviceId() const;
|
QString deviceId() const;
|
||||||
|
|
Loading…
Reference in a new issue