Improve NotificationsModel

Don't refresh the whole notification list, if a notification is added or
removed.

REVIEW: 127565
This commit is contained in:
David Kahles 2016-04-03 16:48:28 +02:00
parent 6cc1946443
commit 12ccbaef98
3 changed files with 19 additions and 6 deletions

View file

@ -87,6 +87,7 @@ DeviceNotificationsDbusInterface::~DeviceNotificationsDbusInterface()
NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent)
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
, id(notificationId)
{
}

View file

@ -99,6 +99,10 @@ class KDECONNECTINTERFACES_EXPORT NotificationDbusInterface
public:
NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent = nullptr);
virtual ~NotificationDbusInterface();
QString notificationId() { return id; }
private:
const QString id;
};

View file

@ -95,16 +95,24 @@ void NotificationsModel::setDeviceId(const QString& deviceId)
void NotificationsModel::notificationAdded(const QString& id)
{
//TODO: Actually add instead of refresh
Q_UNUSED(id);
refreshNotificationList();
int currentSize = m_notificationList.size();
beginInsertRows(QModelIndex(), currentSize, currentSize);
NotificationDbusInterface* dbusInterface = new NotificationDbusInterface(m_deviceId, id, this);
m_notificationList.append(dbusInterface);
endInsertRows();
}
void NotificationsModel::notificationRemoved(const QString& id)
{
//TODO: Actually remove instead of refresh
Q_UNUSED(id);
refreshNotificationList();
for (int i = 0; i < m_notificationList.size(); ++i) {
if (m_notificationList[i]->notificationId() == id) {
beginRemoveRows(QModelIndex(), i, i);
m_notificationList.removeAt(i);
endRemoveRows();
return;
}
}
qCWarning(KDECONNECT_INTERFACES) << "Attempted to remove unknown notification: " << id;
}
void NotificationsModel::refreshNotificationList()