~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/models/imagealbummodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        recurseTags         = false;
60
60
    }
61
61
 
62
 
    Album                   *currentAlbum;
63
 
    KIO::TransferJob        *job;
64
 
    QTimer                  *refreshTimer;
65
 
    QTimer                  *incrementalTimer;
 
62
    Album*                   currentAlbum;
 
63
    KIO::TransferJob*        job;
 
64
    QTimer*                  refreshTimer;
 
65
    QTimer*                  incrementalTimer;
66
66
 
67
67
    bool                     recurseAlbums;
68
68
    bool                     recurseTags;
69
69
};
70
70
 
71
 
ImageAlbumModel::ImageAlbumModel(QObject *parent)
72
 
               : ImageThumbnailModel(parent),
 
71
ImageAlbumModel::ImageAlbumModel(QObject* parent)
 
72
    : ImageThumbnailModel(parent),
73
73
      d(new ImageAlbumModelPriv)
74
74
{
75
75
    d->refreshTimer = new QTimer(this);
87
87
    connect(this, SIGNAL(readyForIncrementalRefresh()),
88
88
            this, SLOT(incrementalRefresh()));
89
89
 
90
 
    connect(DatabaseAccess::databaseWatch(), SIGNAL(collectionImageChange(const CollectionImageChangeset &)),
91
 
            this, SLOT(slotCollectionImageChange(const CollectionImageChangeset &)));
 
90
    connect(DatabaseAccess::databaseWatch(), SIGNAL(collectionImageChange(const CollectionImageChangeset&)),
 
91
            this, SLOT(slotCollectionImageChange(const CollectionImageChangeset&)));
92
92
 
93
 
    connect(DatabaseAccess::databaseWatch(), SIGNAL(searchChange(const SearchChangeset &)),
94
 
            this, SLOT(slotSearchChange(const SearchChangeset &)));
 
93
    connect(DatabaseAccess::databaseWatch(), SIGNAL(searchChange(const SearchChangeset&)),
 
94
            this, SLOT(slotSearchChange(const SearchChangeset&)));
95
95
 
96
96
    connect(AlbumManager::instance(), SIGNAL(signalAlbumAdded(Album*)),
97
97
            this, SLOT(slotAlbumAdded(Album*)));
118
118
    delete d;
119
119
}
120
120
 
121
 
Album *ImageAlbumModel::currentAlbum() const
 
121
Album* ImageAlbumModel::currentAlbum() const
122
122
{
123
123
    return d->currentAlbum;
124
124
}
151
151
    return d->recurseTags;
152
152
}
153
153
 
154
 
void ImageAlbumModel::openAlbum(Album *album)
 
154
void ImageAlbumModel::openAlbum(Album* album)
155
155
{
156
156
    if (d->currentAlbum == album)
 
157
    {
157
158
        return;
 
159
    }
158
160
 
159
161
    d->currentAlbum = album;
160
162
    emit listedAlbumChanged(d->currentAlbum);
172
174
    clearImageInfos();
173
175
 
174
176
    if (!d->currentAlbum)
 
177
    {
175
178
        return;
 
179
    }
176
180
 
177
181
    if (d->currentAlbum->isRoot())
 
182
    {
178
183
        return;
 
184
    }
179
185
 
180
186
    startRefresh();
181
187
 
190
196
    // -> to this method via SIGNAL(readyForIncrementalRefresh())
191
197
 
192
198
    if (!d->currentAlbum)
 
199
    {
193
200
        return;
 
201
    }
194
202
 
195
203
    if (d->job)
196
204
    {
220
228
void ImageAlbumModel::scheduleIncrementalRefresh()
221
229
{
222
230
    if (!hasScheduledRefresh())
 
231
    {
223
232
        d->incrementalTimer->start(100);
 
233
    }
224
234
}
225
235
 
226
236
void ImageAlbumModel::slotNextRefresh()
228
238
    // Refresh, unless job is running, then postpone restart until job is finished
229
239
    // Rationale: Let the job run, don't stop it possibly several times
230
240
    if (d->job)
 
241
    {
231
242
        d->refreshTimer->start(50);
 
243
    }
232
244
    else
 
245
    {
233
246
        refresh();
 
247
    }
234
248
}
235
249
 
236
250
void ImageAlbumModel::slotNextIncrementalRefresh()
237
251
{
238
252
    if (d->job)
 
253
    {
239
254
        d->incrementalTimer->start(50);
 
255
    }
240
256
    else
 
257
    {
241
258
        requestIncrementalRefresh();
 
259
    }
242
260
}
243
261
 
244
262
void ImageAlbumModel::startListJob(const KUrl& url)
257
275
void ImageAlbumModel::slotResult(KJob* job)
258
276
{
259
277
    if (job != d->job)
 
278
    {
260
279
        return;
 
280
    }
 
281
 
261
282
    d->job = 0;
262
283
 
263
284
    // either of the two
274
295
void ImageAlbumModel::slotData(KIO::Job*, const QByteArray& data)
275
296
{
276
297
    if (data.isEmpty())
 
298
    {
277
299
        return;
 
300
    }
278
301
 
279
302
    ImageInfoList newItemsList;
280
303
 
296
319
void ImageAlbumModel::slotImageChange(const ImageChangeset& changeset)
297
320
{
298
321
    if (!d->currentAlbum)
 
322
    {
299
323
        return;
 
324
    }
300
325
 
301
326
    // already scheduled to refresh?
302
327
    if (hasScheduledRefresh())
 
328
    {
303
329
        return;
 
330
    }
304
331
 
305
332
    if (d->currentAlbum->type() == Album::SEARCH)
306
333
    {
323
350
void ImageAlbumModel::slotImageTagChange(const ImageTagChangeset& changeset)
324
351
{
325
352
    if (!d->currentAlbum)
 
353
    {
326
354
        return;
 
355
    }
327
356
 
328
357
    bool doRefresh = false;
 
358
 
329
359
    if (d->currentAlbum->type() == Album::TAG)
330
360
    {
331
361
        doRefresh = changeset.containsTag(d->currentAlbum->id());
 
362
 
332
363
        if (!doRefresh && d->recurseTags)
333
364
        {
334
365
            foreach (int tagId, changeset.tags())
335
366
            {
336
 
                Album *a = AlbumManager::instance()->findTAlbum(tagId);
 
367
                Album* a = AlbumManager::instance()->findTAlbum(tagId);
 
368
 
337
369
                if (a && d->currentAlbum->isAncestorOf(a))
338
370
                {
339
371
                    doRefresh = true;
344
376
    }
345
377
 
346
378
    if (doRefresh)
 
379
    {
347
380
        scheduleIncrementalRefresh();
 
381
    }
348
382
 
349
383
    ImageModel::slotImageTagChange(changeset);
350
384
}
352
386
void ImageAlbumModel::slotCollectionImageChange(const CollectionImageChangeset& changeset)
353
387
{
354
388
    if (!d->currentAlbum)
 
389
    {
355
390
        return;
 
391
    }
356
392
 
357
393
    // already scheduled to refresh?
358
394
    if (d->refreshTimer->isActive())
 
395
    {
359
396
        return;
 
397
    }
360
398
 
361
399
    bool doRefresh = false;
362
400
 
363
401
    switch (changeset.operation())
364
402
    {
365
403
        case CollectionImageChangeset::Added:
366
 
            switch(d->currentAlbum->type())
 
404
 
 
405
            switch (d->currentAlbum->type())
367
406
            {
368
407
                case Album::PHYSICAL:
369
408
                    // that's easy: try if our album is affected
370
409
                    doRefresh = changeset.containsAlbum(d->currentAlbum->id());
 
410
 
371
411
                    if (!doRefresh && d->recurseAlbums)
372
412
                    {
373
413
                        foreach (int albumId, changeset.albums())
374
414
                        {
375
 
                            Album *a = AlbumManager::instance()->findPAlbum(albumId);
 
415
                            Album* a = AlbumManager::instance()->findPAlbum(albumId);
 
416
 
376
417
                            if (a && d->currentAlbum->isAncestorOf(a))
377
418
                            {
378
419
                                doRefresh = true;
380
421
                            }
381
422
                        }
382
423
                    }
 
424
 
383
425
                    break;
384
426
                default:
385
427
                    // we cannot easily know if we are affected
406
448
    }
407
449
 
408
450
    if (doRefresh)
 
451
    {
409
452
        scheduleIncrementalRefresh();
 
453
    }
410
454
}
411
455
 
412
456
void ImageAlbumModel::slotSearchChange(const SearchChangeset& changeset)
413
457
{
414
458
    if (!d->currentAlbum)
 
459
    {
415
460
        return;
 
461
    }
416
462
 
417
463
    if (changeset.operation() != SearchChangeset::Changed)
 
464
    {
418
465
        return;
 
466
    }
419
467
 
420
 
    SAlbum *album = AlbumManager::instance()->findSAlbum(changeset.searchId());
 
468
    SAlbum* album = AlbumManager::instance()->findSAlbum(changeset.searchId());
421
469
 
422
470
    if (album && d->currentAlbum == album)
 
471
    {
423
472
        scheduleIncrementalRefresh();
 
473
    }
424
474
}
425
475
 
426
476
void ImageAlbumModel::slotAlbumAdded(Album* /*album*/)
427
477
{
428
478
}
429
479
 
430
 
void ImageAlbumModel::slotAlbumDeleted(Album *album)
 
480
void ImageAlbumModel::slotAlbumDeleted(Album* album)
431
481
{
432
482
    if (d->currentAlbum == album)
433
483
    {
444
494
 
445
495
}
446
496
 
447
 
void ImageAlbumModel::slotAlbumRenamed(Album *album)
 
497
void ImageAlbumModel::slotAlbumRenamed(Album* album)
448
498
{
449
499
    // display changed names
450
500
    if (album == d->currentAlbum)
 
501
    {
451
502
        emitDataChangedForAll();
 
503
    }
452
504
}
453
505
 
454
506
void ImageAlbumModel::slotAlbumsCleared()