~unity-api-team/unity-notifications/trunk

« back to all changes in this revision

Viewing changes to src/NotificationModel.cpp

  • Committer: CI Train Bot
  • Author(s): Pete Woods
  • Date: 2015-06-23 15:50:29 UTC
  • mfrom: (224.1.13 trunk)
  • Revision ID: ci-train-bot@canonical.com-20150623155029-o48xv2ezqp357q9k
Handle client death by cleaning up notifications
Approved by: Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
    return !(getNotification(id).isNull());
221
221
}
222
222
 
 
223
QList<QSharedPointer<Notification>> NotificationModel::removeAllNotificationsForClient(const QString& clientId)
 
224
{
 
225
    QList<QSharedPointer<Notification>> notifications;
 
226
 
 
227
    for(int i=0; i<p->ephemeralQueue.size();) {
 
228
        if(p->ephemeralQueue[i]->getClientId() == clientId) {
 
229
            notifications << p->ephemeralQueue.takeAt(i);
 
230
            Q_EMIT queueSizeChanged(queued());
 
231
        } else {
 
232
            ++i;
 
233
        }
 
234
    }
 
235
 
 
236
    for(int i=0; i<p->snapQueue.size();) {
 
237
        if(p->snapQueue[i]->getClientId() == clientId) {
 
238
            notifications << p->snapQueue.takeAt(i);
 
239
            Q_EMIT queueSizeChanged(queued());
 
240
        } else {
 
241
            ++i;
 
242
        }
 
243
    }
 
244
 
 
245
    for(int i=0; i<p->interactiveQueue.size();) {
 
246
        if(p->interactiveQueue[i]->getClientId() == clientId) {
 
247
            notifications << p->interactiveQueue.takeAt(i);
 
248
            Q_EMIT queueSizeChanged(queued());
 
249
        } else {
 
250
            ++i;
 
251
        }
 
252
    }
 
253
 
 
254
    bool needToTimeout = false;
 
255
    for(int i=0; i<p->displayedNotifications.size();) {
 
256
        if(p->displayedNotifications[i]->getClientId() == clientId) {
 
257
            notifications << deleteFromVisible(i);
 
258
            needToTimeout = true;
 
259
        } else {
 
260
            ++i;
 
261
        }
 
262
    }
 
263
 
 
264
    if (needToTimeout) {
 
265
        timeout(); // Simulate a timeout so visual state is updated.
 
266
    }
 
267
 
 
268
    return notifications;
 
269
}
 
270
 
223
271
void NotificationModel::removeNotification(const NotificationID id) {
224
272
    for(int i=0; i<p->ephemeralQueue.size(); i++) {
225
273
        if(p->ephemeralQueue[i]->getID() == id) {
261
309
    deleteFromVisible(0);
262
310
}
263
311
 
264
 
void NotificationModel::deleteFromVisible(int loc) {
 
312
QSharedPointer<Notification> NotificationModel::deleteFromVisible(int loc) {
265
313
    QModelIndex deletePoint = QModelIndex();
266
314
    beginRemoveRows(deletePoint, loc, loc);
267
315
    QSharedPointer<Notification> n = p->displayedNotifications[loc];
268
316
    p->displayTimes.erase(p->displayTimes.find(n->getID()));
269
 
    p->displayedNotifications.erase(p->displayedNotifications.begin() + loc);
 
317
    auto notification = p->displayedNotifications.takeAt(loc);
270
318
    endRemoveRows();
 
319
    return notification;
271
320
}
272
321
 
273
322
void NotificationModel::timeout() {