Fixed Q_ASSERT in model.
+ small change to the dimsiss buttons of the plasmoid
This commit is contained in:
parent
71f9f9dc07
commit
802bb26a2c
4 changed files with 54 additions and 27 deletions
|
@ -28,8 +28,6 @@
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#include <KIcon>
|
#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))
|
||||||
|
@ -103,7 +101,7 @@ void DevicesModel::setDisplayFilter(DevicesModel::StatusFlags flags)
|
||||||
void DevicesModel::refreshDeviceList()
|
void DevicesModel::refreshDeviceList()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_deviceList.count() > 0) {
|
if (!m_deviceList.isEmpty()) {
|
||||||
beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_deviceList.size() - 1);
|
||||||
m_deviceList.clear();
|
m_deviceList.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
@ -113,11 +111,12 @@ void DevicesModel::refreshDeviceList()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusPendingReply<QStringList> deviceIds = m_dbusInterface->devices();
|
QDBusPendingReply<QStringList> pendingDeviceIds = m_dbusInterface->devices();
|
||||||
deviceIds.waitForFinished();
|
pendingDeviceIds.waitForFinished();
|
||||||
if (deviceIds.isError()) return;
|
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);
|
DeviceDbusInterface* deviceDbusInterface = new DeviceDbusInterface(id,this);
|
||||||
|
|
||||||
|
@ -126,15 +125,16 @@ void DevicesModel::refreshDeviceList()
|
||||||
bool onlyReachable = (m_displayFilter & StatusReachable);
|
bool onlyReachable = (m_displayFilter & StatusReachable);
|
||||||
if (onlyReachable && !deviceDbusInterface->reachable()) continue;
|
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);
|
m_deviceList.append(deviceDbusInterface);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
|
||||||
|
|
||||||
Q_EMIT dataChanged(index(0), index(deviceIds.count()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
||||||
if (!m_dbusInterface->isValid()
|
if (!m_dbusInterface->isValid()
|
||||||
|| !index.isValid()
|
|| !index.isValid()
|
||||||
|| index.row() < 0
|
|| index.row() < 0
|
||||||
|| index.row() >= m_deviceList.count()
|
|| index.row() >= m_deviceList.size()
|
||||||
|| !m_deviceList[index.row()]->isValid())
|
|| !m_deviceList[index.row()]->isValid())
|
||||||
{
|
{
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -199,6 +199,6 @@ int DevicesModel::rowCount(const QModelIndex &parent) const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_deviceList.count();
|
return m_deviceList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,13 @@ NotificationsModel::NotificationsModel(QObject *parent)
|
||||||
|
|
||||||
//new ModelTest(this, this);
|
//new ModelTest(this, this);
|
||||||
|
|
||||||
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
||||||
this, SIGNAL(rowsChanged()));
|
|
||||||
connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
||||||
this, SIGNAL(rowsChanged()));
|
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
|
//Role names for QML
|
||||||
QHash<int, QByteArray> names = roleNames();
|
QHash<int, QByteArray> names = roleNames();
|
||||||
|
@ -102,16 +105,21 @@ void NotificationsModel::refreshNotificationList()
|
||||||
|
|
||||||
if (!m_dbusInterface->isValid()) return;
|
if (!m_dbusInterface->isValid()) return;
|
||||||
|
|
||||||
QDBusPendingReply<QStringList> notificationIds = m_dbusInterface->activeNotifications();
|
QDBusPendingReply<QStringList> pendingNotificationIds = m_dbusInterface->activeNotifications();
|
||||||
notificationIds.waitForFinished();
|
pendingNotificationIds.waitForFinished();
|
||||||
if (notificationIds.isError()) return;
|
if (pendingNotificationIds.isError()) return;
|
||||||
|
const QStringList& notificationIds = pendingNotificationIds.value();
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), 0, notificationIds.value().size()-1);
|
if (notificationIds.isEmpty()) return;
|
||||||
Q_FOREACH(const QString& notificationId, notificationIds.value()) {
|
|
||||||
|
beginInsertRows(QModelIndex(), 0, notificationIds.size()-1);
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant NotificationsModel::data(const QModelIndex &index, int role) const
|
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());
|
return QString(notification->internalId());
|
||||||
case NameModelRole:
|
case NameModelRole:
|
||||||
return QString(notification->ticker());
|
return QString(notification->ticker());
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return QVariant(); //To implement
|
|
||||||
case ContentModelRole:
|
case ContentModelRole:
|
||||||
return QString("AAAAAA"); //To implement
|
return QString(); //To implement in the Android side
|
||||||
case AppNameModelRole:
|
case AppNameModelRole:
|
||||||
return QString(notification->appName());
|
return QString(notification->appName());
|
||||||
case DbusInterfaceRole:
|
case DbusInterfaceRole:
|
||||||
|
@ -178,7 +184,20 @@ int NotificationsModel::rowCount(const QModelIndex &parent) const
|
||||||
return m_notificationList.count();
|
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) {
|
Q_FOREACH(NotificationDbusInterface* notification, m_notificationList) {
|
||||||
if (notification->dismissable()) {
|
if (notification->dismissable()) {
|
||||||
|
|
|
@ -34,6 +34,8 @@ class KDECONNECT_EXPORT NotificationsModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged)
|
||||||
|
Q_PROPERTY(bool isAnyDimissable READ isAnyDimissable NOTIFY anyDismissableChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ModelRoles {
|
enum ModelRoles {
|
||||||
IconModelRole = Qt::DecorationRole,
|
IconModelRole = Qt::DecorationRole,
|
||||||
|
@ -57,7 +59,8 @@ public:
|
||||||
NotificationDbusInterface* getNotification(const QModelIndex&);
|
NotificationDbusInterface* getNotification(const QModelIndex&);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void clear();
|
void dismissAll();
|
||||||
|
bool isAnyDimissable();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void notificationAdded(const QString& id);
|
void notificationAdded(const QString& id);
|
||||||
|
@ -66,6 +69,7 @@ private Q_SLOTS:
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void deviceIdChanged(const QString& value);
|
void deviceIdChanged(const QString& value);
|
||||||
|
void anyDismissableChanged();
|
||||||
void rowsChanged();
|
void rowsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -40,12 +40,15 @@ PlasmaComponents.ListItem
|
||||||
//Notifications
|
//Notifications
|
||||||
PlasmaComponents.ListItem {
|
PlasmaComponents.ListItem {
|
||||||
visible: notificationsModel.count>0
|
visible: notificationsModel.count>0
|
||||||
|
enabled: true
|
||||||
sectionDelegate: true
|
sectionDelegate: true
|
||||||
PlasmaComponents.Label { text: i18n("Notifications") }
|
PlasmaComponents.Label { text: i18n("Notifications") }
|
||||||
PlasmaComponents.ToolButton {
|
PlasmaComponents.ToolButton {
|
||||||
|
enabled: true
|
||||||
|
visible: notificationsModel.isAnyDimissable;
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
iconSource: "window-close"
|
iconSource: "window-close"
|
||||||
onClicked: notificationsModel.clear();
|
onClicked: notificationsModel.dismissAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Repeater {
|
Repeater {
|
||||||
|
@ -59,7 +62,8 @@ PlasmaComponents.ListItem
|
||||||
text: appName + ": " + display
|
text: appName + ": " + display
|
||||||
}
|
}
|
||||||
PlasmaComponents.ToolButton {
|
PlasmaComponents.ToolButton {
|
||||||
visible: dismissable
|
visible: notificationsModel.isAnyDimissable;
|
||||||
|
enabled: dismissable
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
iconSource: "window-close"
|
iconSource: "window-close"
|
||||||
onClicked: dbusInterface.dismiss();
|
onClicked: dbusInterface.dismiss();
|
||||||
|
|
Loading…
Reference in a new issue