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

« back to all changes in this revision

Viewing changes to libs/database/imagecopyright.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:
44
44
{
45
45
public:
46
46
 
47
 
    ImageCopyrightCache(ImageCopyright *object)
48
 
                : object(object)
 
47
    ImageCopyrightCache(ImageCopyright* object)
 
48
        : object(object)
49
49
    {
50
50
        // set this as cache
51
51
        object->m_cache = this;
61
61
 
62
62
private:
63
63
 
64
 
    ImageCopyright *object;
 
64
    ImageCopyright* object;
65
65
};
66
66
 
67
67
ImageCopyright::ImageCopyright(qlonglong imageid)
68
 
              : m_id(imageid), m_cache(0)
 
68
    : m_id(imageid), m_cache(0)
69
69
{
70
70
}
71
71
 
72
72
ImageCopyright::ImageCopyright()
73
 
              : m_id(0), m_cache(0)
 
73
    : m_id(0), m_cache(0)
74
74
{
75
75
}
76
76
 
77
77
ImageCopyright::ImageCopyright(const ImageCopyright& other)
78
 
              : m_id(other.m_id), m_cache(0)
 
78
    : m_id(other.m_id), m_cache(0)
79
79
{
80
80
    // the cache is only short-lived, to keep complexity low
81
81
}
89
89
    }
90
90
}
91
91
 
92
 
ImageCopyright &ImageCopyright::operator=(const ImageCopyright& other)
 
92
ImageCopyright& ImageCopyright::operator=(const ImageCopyright& other)
93
93
{
94
94
    if (m_cache)
95
95
    {
96
96
        delete m_cache;
97
97
        m_cache = 0;
98
98
    }
 
99
 
99
100
    m_id = other.m_id;
100
101
    return *this;
101
102
}
103
104
void ImageCopyright::replaceFrom(const ImageCopyright& source)
104
105
{
105
106
    if (!m_id)
 
107
    {
106
108
        return;
 
109
    }
107
110
 
108
111
    DatabaseAccess access;
109
112
    access.db()->removeImageCopyrightProperties(m_id);
110
113
 
111
114
    if (!source.m_id)
 
115
    {
112
116
        return;
 
117
    }
113
118
 
114
119
    QList<CopyrightInfo> infos = access.db()->getImageCopyright(source.m_id, QString());
115
120
    foreach (const CopyrightInfo& info, infos)
133
138
void ImageCopyright::setCreator(const QString& creator, ReplaceMode mode)
134
139
{
135
140
    AlbumDB::CopyrightPropertyUnique uniqueness;
 
141
 
136
142
    if (mode == ReplaceAllEntries)
 
143
    {
137
144
        uniqueness = AlbumDB::PropertyUnique;
 
145
    }
138
146
    else
 
147
    {
139
148
        uniqueness = AlbumDB::PropertyNoConstraint;
 
149
    }
140
150
 
141
151
    DatabaseAccess().db()->setImageCopyrightProperty(m_id, ImageScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreator),
142
 
                                                     creator, QString(), uniqueness);
 
152
            creator, QString(), uniqueness);
143
153
}
144
154
 
145
155
void ImageCopyright::removeCreators()
285
295
    removeProperties(ImageScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoWebUrl));
286
296
}
287
297
 
288
 
void ImageCopyright::fillTemplate(Template &t)
 
298
void ImageCopyright::fillTemplate(Template& t)
289
299
{
290
300
    ImageCopyrightCache cache(this);
291
301
 
299
309
    t.setContactInfo(contactInfo());
300
310
}
301
311
 
302
 
void ImageCopyright::setFromTemplate(const Template &t)
 
312
void ImageCopyright::setFromTemplate(const Template& t)
303
313
{
304
314
    foreach(QString author, t.authors()) // krazy:exclude=foreach
305
315
    {
310
320
 
311
321
    KExiv2::AltLangMap copyrights = t.copyright();
312
322
    KExiv2::AltLangMap::const_iterator it;
 
323
 
313
324
    for (it = copyrights.constBegin() ; it != copyrights.constEnd() ; ++it)
 
325
    {
314
326
        setRights(it.value(), it.key(), ImageCopyright::AddEntryToExisting);
 
327
    }
315
328
 
316
329
    KExiv2::AltLangMap usages = t.rightUsageTerms();
317
330
    KExiv2::AltLangMap::const_iterator it2;
 
331
 
318
332
    for (it2 = usages.constBegin() ; it2 != usages.constEnd() ; ++it2)
 
333
    {
319
334
        setRightsUsageTerms(it2.value(), it2.key(), ImageCopyright::AddEntryToExisting);
 
335
    }
320
336
 
321
337
    setSource(t.source());
322
338
    setAuthorsPosition(t.authorsPosition());
342
358
{
343
359
    if (m_cache)
344
360
    {
345
 
        foreach (const CopyrightInfo &info, m_cache->infos)
 
361
        foreach (const CopyrightInfo& info, m_cache->infos)
346
362
        {
347
363
            if (info.property == property)
348
364
            {
353
369
    else
354
370
    {
355
371
        QList<CopyrightInfo> infos = DatabaseAccess().db()->getImageCopyright(m_id, property);
 
372
 
356
373
        if (!infos.isEmpty())
 
374
        {
357
375
            return infos.first();
 
376
        }
358
377
    }
 
378
 
359
379
    return CopyrightInfo();
360
380
}
361
381
 
364
384
    if (m_cache)
365
385
    {
366
386
        QList<CopyrightInfo> infos;
367
 
        foreach (const CopyrightInfo &info, m_cache->infos)
 
387
        foreach (const CopyrightInfo& info, m_cache->infos)
368
388
        {
369
389
            if (info.property == property)
370
390
            {
393
413
{
394
414
    QList<CopyrightInfo> infos = copyrightInfos(property);
395
415
    int index = languageMatch(infos, languageCode);
 
416
 
396
417
    if (index == -1)
 
418
    {
397
419
        return QString();
 
420
    }
398
421
    else
 
422
    {
399
423
        return infos[index].value;
 
424
    }
400
425
}
401
426
 
402
427
KExiv2Iface::KExiv2::AltLangMap ImageCopyright::readLanguageProperties(const QString& property)
403
428
{
404
429
    KExiv2Iface::KExiv2::AltLangMap map;
405
430
    QList<CopyrightInfo> infos = copyrightInfos(property);
406
 
    foreach (const CopyrightInfo &info, infos)
 
431
    foreach (const CopyrightInfo& info, infos)
407
432
    {
408
433
        map[info.extraValue] = info.value;
409
434
    }
411
436
}
412
437
 
413
438
void ImageCopyright::setLanguageProperty(const QString& property, const QString& value,
414
 
                                         const QString& languageCode, ReplaceMode mode)
 
439
        const QString& languageCode, ReplaceMode mode)
415
440
{
416
441
    AlbumDB::CopyrightPropertyUnique uniqueness;
 
442
 
417
443
    if (mode == ReplaceAllEntries)
 
444
    {
418
445
        uniqueness = AlbumDB::PropertyUnique;
 
446
    }
419
447
    else if (mode == ReplaceLanguageEntry)
 
448
    {
420
449
        uniqueness = AlbumDB::PropertyExtraValueUnique;
 
450
    }
421
451
    else
 
452
    {
422
453
        uniqueness = AlbumDB::PropertyNoConstraint;
 
454
    }
423
455
 
424
456
    QString language = languageCode;
 
457
 
425
458
    if (language.isNull())
 
459
    {
426
460
        language = "x-default";
 
461
    }
427
462
 
428
463
    DatabaseAccess().db()->setImageCopyrightProperty(m_id, property, value, language, uniqueness);
429
464
}
432
467
{
433
468
    // if we have a cache, find out if anything need to be done at all
434
469
    if (m_cache && copyrightInfo(property).isNull())
 
470
    {
435
471
        return;
 
472
    }
 
473
 
436
474
    DatabaseAccess().db()->removeImageCopyrightProperties(m_id, property);
437
475
}
438
476
 
439
477
void ImageCopyright::removeLanguageProperty(const QString& property, const QString& languageCode)
440
478
{
441
479
    if (m_cache && copyrightInfo(property).isNull())
 
480
    {
442
481
        return;
 
482
    }
 
483
 
443
484
    DatabaseAccess().db()->removeImageCopyrightProperties(m_id, property, languageCode);
444
485
}
445
486
 
447
488
{
448
489
    QString langCode;
449
490
    QString fullCode = languageCode;
 
491
 
450
492
    if (languageCode.isNull())
451
493
    {
452
494
        // find local language
453
 
        KLocale *locale = KGlobal::locale();
 
495
        KLocale* locale = KGlobal::locale();
454
496
        langCode = locale->language().toLower() + '-';
455
497
        fullCode = langCode + locale->country().toLower();
456
498
    }
506
548
    }
507
549
 
508
550
    int chosen = fullCodeMatch;
 
551
 
509
552
    if (chosen == -1)
 
553
    {
510
554
        chosen = langCodeMatch;
 
555
    }
 
556
 
511
557
    if (chosen == -1)
 
558
    {
512
559
        chosen = defaultCodeMatch;
 
560
    }
 
561
 
513
562
    if (chosen == -1)
 
563
    {
514
564
        chosen = firstMatch;
 
565
    }
515
566
 
516
567
    return chosen;
517
568
}