Improve NotificationsModel
Don't refresh the whole notification list, if a notification is added or removed. REVIEW: 127565
This commit is contained in:
parent
6cc1946443
commit
12ccbaef98
3 changed files with 19 additions and 6 deletions
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue