Fixed Q_ASSERT in model.

+ small change to the dimsiss buttons of the plasmoid
This commit is contained in:
Albert Vaca 2013-08-28 19:33:46 +02:00
parent 71f9f9dc07
commit 802bb26a2c
4 changed files with 54 additions and 27 deletions

View file

@ -28,8 +28,6 @@
#include <KConfigGroup>
#include <KIcon>
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<QStringList> deviceIds = m_dbusInterface->devices();
deviceIds.waitForFinished();
if (deviceIds.isError()) return;
QDBusPendingReply<QStringList> 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();
}

View file

@ -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<int, QByteArray> names = roleNames();
@ -102,16 +105,21 @@ void NotificationsModel::refreshNotificationList()
if (!m_dbusInterface->isValid()) return;
QDBusPendingReply<QStringList> notificationIds = m_dbusInterface->activeNotifications();
notificationIds.waitForFinished();
if (notificationIds.isError()) return;
QDBusPendingReply<QStringList> 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()) {

View file

@ -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:

View file

@ -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();