From 802bb26a2c7023cc4231039a78fdeff6837a9eb2 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Wed, 28 Aug 2013 19:33:46 +0200 Subject: [PATCH] Fixed Q_ASSERT in model. + small change to the dimsiss buttons of the plasmoid --- libkdeconnect/devicesmodel.cpp | 26 ++++++------ libkdeconnect/notificationsmodel.cpp | 41 ++++++++++++++----- libkdeconnect/notificationsmodel.h | 6 ++- .../package/contents/ui/DeviceDelegate.qml | 8 +++- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/libkdeconnect/devicesmodel.cpp b/libkdeconnect/devicesmodel.cpp index c978695fb..1fc81ec3d 100644 --- a/libkdeconnect/devicesmodel.cpp +++ b/libkdeconnect/devicesmodel.cpp @@ -28,8 +28,6 @@ #include #include -bool fetchNotifications = true; - DevicesModel::DevicesModel(QObject *parent) : QAbstractListModel(parent) , m_dbusInterface(new DaemonDbusInterface(this)) @@ -103,7 +101,7 @@ void DevicesModel::setDisplayFilter(DevicesModel::StatusFlags flags) void DevicesModel::refreshDeviceList() { - if (m_deviceList.count() > 0) { + if (!m_deviceList.isEmpty()) { beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1); m_deviceList.clear(); endRemoveRows(); @@ -113,11 +111,12 @@ void DevicesModel::refreshDeviceList() return; } - QDBusPendingReply deviceIds = m_dbusInterface->devices(); - deviceIds.waitForFinished(); - if (deviceIds.isError()) return; + QDBusPendingReply pendingDeviceIds = m_dbusInterface->devices(); + pendingDeviceIds.waitForFinished(); + if (pendingDeviceIds.isError()) return; + const QStringList& deviceIds = pendingDeviceIds.value(); - Q_FOREACH(const QString& id, deviceIds.value()) { + Q_FOREACH(const QString& id, deviceIds) { DeviceDbusInterface* deviceDbusInterface = new DeviceDbusInterface(id,this); @@ -126,15 +125,16 @@ void DevicesModel::refreshDeviceList() bool onlyReachable = (m_displayFilter & StatusReachable); if (onlyReachable && !deviceDbusInterface->reachable()) continue; - beginInsertRows(QModelIndex(), rowCount(), rowCount()); + int firstRow = m_deviceList.size(); + int lastRow = firstRow; + + beginInsertRows(QModelIndex(), firstRow, lastRow); m_deviceList.append(deviceDbusInterface); endInsertRows(); } - - - Q_EMIT dataChanged(index(0), index(deviceIds.count())); + Q_EMIT dataChanged(index(0), index(m_deviceList.size())); } @@ -143,7 +143,7 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const if (!m_dbusInterface->isValid() || !index.isValid() || index.row() < 0 - || index.row() >= m_deviceList.count() + || index.row() >= m_deviceList.size() || !m_deviceList[index.row()]->isValid()) { return QVariant(); @@ -199,6 +199,6 @@ int DevicesModel::rowCount(const QModelIndex &parent) const return 0; } - return m_deviceList.count(); + return m_deviceList.size(); } diff --git a/libkdeconnect/notificationsmodel.cpp b/libkdeconnect/notificationsmodel.cpp index 03b8b8d3b..c006029ec 100644 --- a/libkdeconnect/notificationsmodel.cpp +++ b/libkdeconnect/notificationsmodel.cpp @@ -35,10 +35,13 @@ NotificationsModel::NotificationsModel(QObject *parent) //new ModelTest(this, this); - connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), - this, SIGNAL(rowsChanged())); connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SIGNAL(rowsChanged())); + connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), + this, SIGNAL(rowsChanged())); + + connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SIGNAL(anyDismissableChanged())); //Role names for QML QHash names = roleNames(); @@ -102,16 +105,21 @@ void NotificationsModel::refreshNotificationList() if (!m_dbusInterface->isValid()) return; - QDBusPendingReply notificationIds = m_dbusInterface->activeNotifications(); - notificationIds.waitForFinished(); - if (notificationIds.isError()) return; + QDBusPendingReply pendingNotificationIds = m_dbusInterface->activeNotifications(); + pendingNotificationIds.waitForFinished(); + if (pendingNotificationIds.isError()) return; + const QStringList& notificationIds = pendingNotificationIds.value(); - beginInsertRows(QModelIndex(), 0, notificationIds.value().size()-1); - Q_FOREACH(const QString& notificationId, notificationIds.value()) { + if (notificationIds.isEmpty()) return; + + 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.size()-1)); } QVariant NotificationsModel::data(const QModelIndex &index, int role) const @@ -139,10 +147,8 @@ QVariant NotificationsModel::data(const QModelIndex &index, int role) const return QString(notification->internalId()); case NameModelRole: return QString(notification->ticker()); - case Qt::ToolTipRole: - return QVariant(); //To implement case ContentModelRole: - return QString("AAAAAA"); //To implement + return QString(); //To implement in the Android side case AppNameModelRole: return QString(notification->appName()); case DbusInterfaceRole: @@ -178,7 +184,20 @@ int NotificationsModel::rowCount(const QModelIndex &parent) const return m_notificationList.count(); } -void NotificationsModel::clear() +bool NotificationsModel::isAnyDimissable() +{ + Q_FOREACH(NotificationDbusInterface* notification, m_notificationList) { + if (notification->dismissable()) { + qDebug() << "Dismisable true"; + return true; + } + } + qDebug() << "Dismisable false"; + return false; +} + + +void NotificationsModel::dismissAll() { Q_FOREACH(NotificationDbusInterface* notification, m_notificationList) { if (notification->dismissable()) { diff --git a/libkdeconnect/notificationsmodel.h b/libkdeconnect/notificationsmodel.h index 324a51f74..a79c06329 100644 --- a/libkdeconnect/notificationsmodel.h +++ b/libkdeconnect/notificationsmodel.h @@ -34,6 +34,8 @@ class KDECONNECT_EXPORT NotificationsModel Q_OBJECT Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged) + Q_PROPERTY(bool isAnyDimissable READ isAnyDimissable NOTIFY anyDismissableChanged) + public: enum ModelRoles { IconModelRole = Qt::DecorationRole, @@ -57,7 +59,8 @@ public: NotificationDbusInterface* getNotification(const QModelIndex&); public Q_SLOTS: - void clear(); + void dismissAll(); + bool isAnyDimissable(); private Q_SLOTS: void notificationAdded(const QString& id); @@ -66,6 +69,7 @@ private Q_SLOTS: Q_SIGNALS: void deviceIdChanged(const QString& value); + void anyDismissableChanged(); void rowsChanged(); private: diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index b31baa898..cd4784950 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -40,12 +40,15 @@ PlasmaComponents.ListItem //Notifications PlasmaComponents.ListItem { visible: notificationsModel.count>0 + enabled: true sectionDelegate: true PlasmaComponents.Label { text: i18n("Notifications") } PlasmaComponents.ToolButton { + enabled: true + visible: notificationsModel.isAnyDimissable; anchors.right: parent.right iconSource: "window-close" - onClicked: notificationsModel.clear(); + onClicked: notificationsModel.dismissAll(); } } Repeater { @@ -59,7 +62,8 @@ PlasmaComponents.ListItem text: appName + ": " + display } PlasmaComponents.ToolButton { - visible: dismissable + visible: notificationsModel.isAnyDimissable; + enabled: dismissable anchors.right: parent.right iconSource: "window-close" onClicked: dbusInterface.dismiss();