1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
-579
-580
-581
-582
-583
-584
-585
-586
-587
-588
-589
-590
-591
-592
-593 | /* ============================================================
+579 | /* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
- * Date : 2009-05-04
- * Description : Various operations on images
+ * Date : 2008-05-12
+ * Description : Access to copy-right info of an item in the database
*
- * Copyright (C) 2002-2005 by Renchi Raju <renchi dot raju at gmail dot com>
- * Copyright (C) 2002-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
- * Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
- * Copyright (C) 2009-2010 by Andi Clemens <andi dot clemens at gmail dot com>
- *
- * This program is free software; you can redistribute it
- * and/or modify it under the terms of the GNU General
- * Public License as published by the Free Software Foundation;
- * either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * ============================================================ */
+ * Copyright (C) 2008-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Copyright (C) 2009-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "itemcopyright.h"
-#include "imageviewutilities.h"
+// Qt includes
-// Qt includes
+#include <QLocale>
-#include <QFileInfo>
-#include <QStringRef>
-#include <QUrl>
-
-// KDE includes
-
-#include <kwindowsystem.h>
-
-// Local includes
+// Local includes
+
+#include "coredb.h"
+#include "coredbaccess.h"
+#include "itemscanner.h"
+#include "template.h"
+
+namespace Digikam
+{
-#include "digikam_debug.h"
-#include "album.h"
-#include "albummanager.h"
-#include "albumselectdialog.h"
-#include "applicationsettings.h"
-#include "deletedialog.h"
-#include "dio.h"
-#include "iteminfo.h"
-#include "imagewindow.h"
-#include "lighttablewindow.h"
-#include "loadingcacheinterface.h"
-#include "queuemgrwindow.h"
-#include "thumbnailloadthread.h"
-#include "fileactionmngr.h"
-#include "dfileoperations.h"
-#include "coredb.h"
-#include "coredbaccess.h"
+class Q_DECL_HIDDEN ItemCopyrightCache
+{
+public:
+
+ explicit ItemCopyrightCache(ItemCopyright* const object)
+ : object(object)
+ {
+ // set this as cache
+ object->m_cache = this;
+ // read all properties
+ infos = CoreDbAccess().db()->getItemCopyright(object->m_id, QString());
+ }
+
+ ~ItemCopyrightCache()
+ {
+ object->m_cache = 0;
+ }
-namespace Digikam
-{
-
-ImageViewUtilities::ImageViewUtilities(QWidget* const parentWidget)
- : QObject(parentWidget)
-{
- m_widget = parentWidget;
-
- connect(this, SIGNAL(signalImagesDeleted(QList<qlonglong>)),
- AlbumManager::instance(), SLOT(slotImagesDeleted(QList<qlonglong>)));
-}
-
-void ImageViewUtilities::setAsAlbumThumbnail(Album* album,
- const ItemInfo& itemInfo)
-{
- if (!album)
- {
- return;
- }
-
- if (album->type() == Album::PHYSICAL)
- {
- PAlbum* const palbum = static_cast<PAlbum*>(album);
-
- QString err;
- AlbumManager::instance()->updatePAlbumIcon(palbum, itemInfo.id(), err);
- }
- else if (album->type() == Album::TAG)
- {
- TAlbum* const talbum = static_cast<TAlbum*>(album);
-
- QString err;
- AlbumManager::instance()->updateTAlbumIcon(talbum, QString(), itemInfo.id(), err);
- }
-}
-
-void ImageViewUtilities::rename(const QUrl& imageUrl,
- const QString& newName,
- bool overwrite)
-{
- if (imageUrl.isEmpty() || !imageUrl.isLocalFile() || newName.isEmpty())
- {
- return;
- }
-
- DIO::rename(imageUrl, newName, overwrite);
-}
-
-bool ImageViewUtilities::deleteImages(const QList<ItemInfo>& infos,
- const DeleteMode deleteMode)
-{
- if (infos.isEmpty())
- {
- return false;
- }
-
- QList<ItemInfo> deleteInfos = infos;
+ QList<CopyrightInfo> infos;
+
+private:
+
+ ItemCopyright* object;
+};
+
+// -------------------------------------------------------------------------------------------
+
+ItemCopyright::ItemCopyright(qlonglong imageid)
+ : m_id(imageid),
+ m_cache(0)
+{
+}
+
+ItemCopyright::ItemCopyright()
+ : m_id(0),
+ m_cache(0)
+{
+}
+
+ItemCopyright::ItemCopyright(const ItemCopyright& other)
+ : m_id(other.m_id),
+ m_cache(0)
+{
+ // the cache is only short-lived, to keep complexity low
+}
+
+ItemCopyright::~ItemCopyright()
+{
+ delete m_cache;
+ m_cache = 0;
+}
+
+ItemCopyright& ItemCopyright::operator=(const ItemCopyright& other)<--- 'operator=' should check for assignment to self to avoid problems with dynamic memory. [+]'operator=' should check for assignment to self to ensure that each block of dynamically allocated memory is owned and managed by only one instance of the class.
+{
+ delete m_cache;
+ m_cache = 0;
+
+ m_id = other.m_id;
+ return *this;
+}
+
+void ItemCopyright::replaceFrom(const ItemCopyright& source)
+{
+ if (!m_id)
+ {
+ return;
+ }
+
+ CoreDbAccess access;
+ access.db()->removeItemCopyrightProperties(m_id);
+
+ if (!source.m_id)
+ {
+ return;
+ }
- QList<QUrl> urlList;
- QList<qlonglong> imageIds;
-
- // Buffer the urls for deletion and imageids for notification of the AlbumManager
- foreach (const ItemInfo& info, deleteInfos)
- {
- urlList << info.fileUrl();
- imageIds << info.id();
- }
-
- DeleteDialog dialog(m_widget);
-
- DeleteDialogMode::DeleteMode deleteDialogMode = DeleteDialogMode::NoChoiceTrash;
+ QList<CopyrightInfo> infos = access.db()->getItemCopyright(source.m_id, QString());
+
+ foreach (const CopyrightInfo& info, infos)
+ {
+ access.db()->setItemCopyrightProperty(m_id, info.property, info.value,
+ info.extraValue, CoreDB::PropertyNoConstraint);
+ }
+}
+
+QStringList ItemCopyright::creator() const
+{
+ QList<CopyrightInfo> infos = copyrightInfos(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreator));
+ QStringList list;
- if (deleteMode == ImageViewUtilities::DeletePermanently)
+ foreach (const CopyrightInfo& info, infos)
{
- deleteDialogMode = DeleteDialogMode::NoChoiceDeletePermanently;
+ list << info.value;
}
- if (!dialog.confirmDeleteList(urlList, DeleteDialogMode::Files, deleteDialogMode))
- {
- return false;
- }
-
- const bool useTrash = !dialog.shouldDelete();
+ return list;
+}
+
+void ItemCopyright::setCreator(const QString& creator, ReplaceMode mode)
+{
+ CoreDB::CopyrightPropertyUnique uniqueness;
- DIO::del(deleteInfos, useTrash);
-
- // Signal the Albummanager about the ids of the deleted images.
- emit signalImagesDeleted(imageIds);
-
- return true;
-}
-
-void ImageViewUtilities::deleteImagesDirectly(const QList<ItemInfo>& infos,
- const DeleteMode deleteMode)
-{
- // This method deletes the selected items directly, without confirmation.
- // It is not used in the default setup.
-
- if (infos.isEmpty())
- {
- return;
- }
-
- QList<qlonglong> imageIds;
-
- foreach (const ItemInfo& info, infos)
- {
- imageIds << info.id();
- }
-
- const bool useTrash = (deleteMode == ImageViewUtilities::DeleteUseTrash);
+ if (mode == ReplaceAllEntries)
+ {
+ uniqueness = CoreDB::PropertyUnique;
+ }
+ else
+ {
+ uniqueness = CoreDB::PropertyNoConstraint;
+ }
+
+ CoreDbAccess().db()->setItemCopyrightProperty(m_id, ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreator),
+ creator, QString(), uniqueness);
+}
+
+void ItemCopyright::removeCreators()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreator));
+}
+
+QString ItemCopyright::provider() const
+{
+ return readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreProvider));
+}
+
+void ItemCopyright::setProvider(const QString& provider)
+{
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreProvider), provider);
+}
- DIO::del(infos, useTrash);
-
- // Signal the Albummanager about the ids of the deleted images.
- emit signalImagesDeleted(imageIds);
-}
-
-void ImageViewUtilities::notifyFileContentChanged(const QList<QUrl>& urls)
-{
- foreach (const QUrl& url, urls)
- {
- QString path = url.toLocalFile();
- ThumbnailLoadThread::deleteThumbnail(path);
- // clean LoadingCache as well - be pragmatic, do it here.
- LoadingCacheInterface::fileChanged(path);
- }
-}
-
-void ImageViewUtilities::createNewAlbumForInfos(const QList<ItemInfo>& infos,
- Album* currentAlbum)
-{
- if (infos.isEmpty())
- {
- return;
- }
+void ItemCopyright::removeProvider()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreProvider));
+}
+
+QString ItemCopyright::copyrightNotice(const QString& languageCode)
+{
+ return readLanguageProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCopyrightNotice), languageCode);
+}
+
+MetaEngine::AltLangMap ItemCopyright::allCopyrightNotices()
+{
+ return readLanguageProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCopyrightNotice));
+}
+
+void ItemCopyright::setCopyrightNotice(const QString& notice, const QString& languageCode, ReplaceMode mode)
+{
+ setLanguageProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCopyrightNotice), notice, languageCode, mode);
+}
+
+void ItemCopyright::removeCopyrightNotices()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCopyrightNotice));
+}
- if (currentAlbum && currentAlbum->type() != Album::PHYSICAL)
- {
- currentAlbum = 0;
- }
+QString ItemCopyright::rightsUsageTerms(const QString& languageCode)
+{
+ return readLanguageProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreRightsUsageTerms), languageCode);
+}
- QString header(i18n("<p>Please select the destination album from the digiKam library to "
- "move the selected images into.</p>"));
-
- Album* const album = AlbumSelectDialog::selectAlbum(m_widget, static_cast<PAlbum*>(currentAlbum), header);
+MetaEngine::AltLangMap ItemCopyright::allRightsUsageTerms()
+{
+ return readLanguageProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreRightsUsageTerms));
+}
- if (!album)
- {
- return;
- }
+void ItemCopyright::setRightsUsageTerms(const QString& term, const QString& languageCode, ReplaceMode mode)
+{
+ setLanguageProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreRightsUsageTerms), term, languageCode, mode);
+}
- DIO::move(infos, (PAlbum*)album);
-}
-
-void ImageViewUtilities::insertToLightTableAuto(const QList<ItemInfo>& all,
- const QList<ItemInfo>& selected,
- const ItemInfo& current)
+void ItemCopyright::removeRightsUsageTerms()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreRightsUsageTerms));
+}
+
+QString ItemCopyright::source()
{
- ItemInfoList list = ItemInfoList(selected);
- ItemInfo singleInfo = current;
+ return readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreSource));
+}
- if (list.isEmpty() || (list.size() == 1 && LightTableWindow::lightTableWindow()->isEmpty()))
- {
- list = ItemInfoList(all);
- }
+void ItemCopyright::setSource(const QString& source)
+{
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreSource), source);
+}
- if (singleInfo.isNull() && !list.isEmpty())
- {
- singleInfo = list.first();
- }
+void ItemCopyright::removeSource()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreSource));
+}
- insertToLightTable(list, current, list.size() <= 1);
-}
-
-void ImageViewUtilities::insertToLightTable(const QList<ItemInfo>& list,
- const ItemInfo& current,
- bool addTo)
+QString ItemCopyright::creatorJobTitle() const
+{
+ return readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreatorJobTitle));
+}
+
+void ItemCopyright::setCreatorJobTitle(const QString& title)
{
- LightTableWindow* const ltview = LightTableWindow::lightTableWindow();
-
- // If addTo is false, the light table will be emptied before adding
- // the images.
- ltview->loadItemInfos(ItemInfoList(list), current, addTo);
- ltview->setLeftRightItems(ItemInfoList(list), addTo);
-
- if (ltview->isHidden())
- {
- ltview->show();
- }
-
- if (ltview->isMinimized())
- {
- KWindowSystem::unminimizeWindow(ltview->winId());
- }
-
- KWindowSystem::activateWindow(ltview->winId());
-}
-
-void ImageViewUtilities::insertToQueueManager(const QList<ItemInfo>& list, const ItemInfo& current, bool newQueue)
-{
- Q_UNUSED(current);
-
- QueueMgrWindow* const bqmview = QueueMgrWindow::queueManagerWindow();
-
- if (bqmview->isHidden())
- {
- bqmview->show();
- }
-
- if (bqmview->isMinimized())
- {
- KWindowSystem::unminimizeWindow(bqmview->winId());
- }
-
- KWindowSystem::activateWindow(bqmview->winId());
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreatorJobTitle), title);
+}
+
+void ItemCopyright::removeCreatorJobTitle()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreCreatorJobTitle));
+}
+
+QString ItemCopyright::instructions()
+{
+ return readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreInstructions));
+}
+
+void ItemCopyright::setInstructions(const QString& instructions)
+{
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreInstructions), instructions);
+}
+
+void ItemCopyright::removeInstructions()
+{
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreInstructions));
+}
+
+IptcCoreContactInfo ItemCopyright::contactInfo()
+{
+ IptcCoreContactInfo info;
+ info.city = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCity));
+ info.country = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCountry));
+ info.address = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoAddress));
+ info.postalCode = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPostalCode));
+ info.provinceState = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoProvinceState));
+ info.email = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoEmail));
+ info.phone = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPhone));
+ info.webUrl = readSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoWebUrl));
+
+ return info;
+}
- if (newQueue)
- {
- bqmview->loadItemInfosToNewQueue(ItemInfoList(list));
- }
- else
- {
- bqmview->loadItemInfosToCurrentQueue(ItemInfoList(list));
- }
-}
-
-void ImageViewUtilities::insertSilentToQueueManager(const QList<ItemInfo>& list,
- const ItemInfo& /*current*/,
- int queueid)
+void ItemCopyright::setContactInfo(const IptcCoreContactInfo& info)
+{
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCity), info.city);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCountry), info.country);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoAddress), info.address);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPostalCode), info.postalCode);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoProvinceState), info.provinceState);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoEmail), info.email);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPhone), info.phone);
+ setSimpleProperty(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoWebUrl), info.webUrl);
+}
+
+void ItemCopyright::removeContactInfo()
{
- QueueMgrWindow* const bqmview = QueueMgrWindow::queueManagerWindow();
- bqmview->loadItemInfos(ItemInfoList(list), queueid);
-}
-
-void ImageViewUtilities::openInfos(const ItemInfo& info,
- const QList<ItemInfo>& allInfosToOpen,
- Album* currentAlbum)
-{
- if (info.isNull())
- {
- return;
- }
-
- QFileInfo fi(info.filePath());
- QString imagefilter = ApplicationSettings::instance()->getImageFileFilter();
- imagefilter += ApplicationSettings::instance()->getRawFileFilter();
-
- // If the current item is not an image file.
- if ( !imagefilter.contains(fi.suffix().toLower()) )
- {
- // Openonly the first one from the list.
- openInfosWithDefaultApplication(QList<ItemInfo>() << info);
- return;
- }
-
- // Run digiKam ImageEditor with all image from current Album.
-
- ImageWindow* const imview = ImageWindow::imageWindow();
-
- imview->disconnect(this);
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCity));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoCountry));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoAddress));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPostalCode));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoProvinceState));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoEmail));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoPhone));
+ removeProperties(ItemScanner::iptcCorePropertyName(MetadataInfo::IptcCoreContactInfoWebUrl));
+}
+
+void ItemCopyright::fillTemplate(Template& t)
+{
+ ItemCopyrightCache cache(this);
+
+ t.setAuthors(author());
+ t.setAuthorsPosition(authorsPosition());
+ t.setCredit(credit());
+ t.setCopyright(allCopyrightNotices());
+ t.setRightUsageTerms(allRightsUsageTerms());
+ t.setSource(source());
+ t.setInstructions(instructions());
+ t.setContactInfo(contactInfo());
+}
+
+void ItemCopyright::setFromTemplate(const Template& t)
+{
+ foreach (const QString& author, t.authors()) // krazy:exclude=foreach
+ {
+ setAuthor(author, ItemCopyright::AddEntryToExisting);
+ }
- connect(imview, SIGNAL(signalURLChanged(QUrl)),
- this, SIGNAL(editorCurrentUrlChanged(QUrl)));
-
- imview->loadItemInfos(ItemInfoList(allInfosToOpen), info,
- currentAlbum ? i18n("Album \"%1\"", currentAlbum->title())
- : QString());
-
- if (imview->isHidden())
- {
- imview->show();
- }
-
- if (imview->isMinimized())
- {
- KWindowSystem::unminimizeWindow(imview->winId());
- }
-
- KWindowSystem::activateWindow(imview->winId());
-}
-
-void ImageViewUtilities::openInfosWithDefaultApplication(const QList<ItemInfo>& infos)
-{
- if (infos.isEmpty())
- {
- return;
- }
-
- QList<QUrl> urls;
-
- foreach (const ItemInfo& inf, infos)
- {
- urls << inf.fileUrl();
- }
-
- DFileOperations::openFilesWithDefaultApplication(urls);
-}
-
-namespace
-{
-
-bool lessThanByTimeForItemInfo(const ItemInfo& a, const ItemInfo& b)
-{
- return a.dateTime() < b.dateTime();
-}
-
-bool lowerThanByNameForItemInfo(const ItemInfo& a, const ItemInfo& b)
-{
- return a.name() < b.name();
-}
-
-bool lowerThanBySizeForItemInfo(const ItemInfo& a, const ItemInfo& b)
-{
- return a.fileSize() < b.fileSize();
-}
-
-} // namespace
-
-void ImageViewUtilities::createGroupByTimeFromInfoList(const ItemInfoList& itemInfoList)
-{
- QList<ItemInfo> groupingList = itemInfoList;
- // sort by time
- std::stable_sort(groupingList.begin(), groupingList.end(), lessThanByTimeForItemInfo);
+ setCredit(t.credit());
+
+ MetaEngine::AltLangMap copyrights = t.copyright();
+ MetaEngine::AltLangMap::const_iterator it;
+
+ for (it = copyrights.constBegin() ; it != copyrights.constEnd() ; ++it)
+ {
+ setRights(it.value(), it.key(), ItemCopyright::AddEntryToExisting);
+ }
+
+ MetaEngine::AltLangMap usages = t.rightUsageTerms();
+ MetaEngine::AltLangMap::const_iterator it2;
+
+ for (it2 = usages.constBegin() ; it2 != usages.constEnd() ; ++it2)
+ {
+ setRightsUsageTerms(it2.value(), it2.key(), ItemCopyright::AddEntryToExisting);
+ }
+
+ setSource(t.source());
+ setAuthorsPosition(t.authorsPosition());
+ setInstructions(t.instructions());
+ setContactInfo(t.contactInfo());
+}
+
+void ItemCopyright::removeAll()
+{
+ ItemCopyrightCache cache(this);
+
+ removeCreators();
+ removeProvider();
+ removeCopyrightNotices();
+ removeRightsUsageTerms();
+ removeSource();
+ removeCreatorJobTitle();
+ removeInstructions();
+ removeContactInfo();
+}
+
+CopyrightInfo ItemCopyright::copyrightInfo(const QString& property) const
+{
+ if (m_cache)
+ {
+ foreach (const CopyrightInfo& info, m_cache->infos)
+ {
+ if (info.property == property)
+ {
+ return info;
+ }
+ }
+ }
+ else
+ {
+ QList<CopyrightInfo> infos = CoreDbAccess().db()->getItemCopyright(m_id, property);
+
+ if (!infos.isEmpty())
+ {
+ return infos.first();
+ }
+ }
+
+ return CopyrightInfo();
+}
- QList<ItemInfo>::iterator it, it2;
-
- for (it = groupingList.begin() ; it != groupingList.end() ; )
+QList<CopyrightInfo> ItemCopyright::copyrightInfos(const QString& property) const
+{
+ if (m_cache)
{
- const ItemInfo& leader = *it;
- QList<ItemInfo> group;
- QDateTime time = it->dateTime();
-
- if (time.isValid())
- {
- for (it2 = it + 1 ; it2 != groupingList.end() ; ++it2)
- {
- if (qAbs(time.secsTo(it2->dateTime())) < 2)
- {
- group << *it2;
- }
- else
- {
- break;
- }
- }
- }
- else
- {
- ++it;
- continue;
- }
-
- // increment to next item not put in the group
- it = it2;
-
- if (!group.isEmpty())
- {
- FileActionMngr::instance()->addToGroup(leader, group);
- }
- }
-}
-
-void ImageViewUtilities::createGroupByFilenameFromInfoList(const ItemInfoList& itemInfoList)
-{
- QList<ItemInfo> groupingList = itemInfoList;
- // sort by Name
- std::stable_sort(groupingList.begin(), groupingList.end(), lowerThanByNameForItemInfo);
-
- QList<ItemInfo>::iterator it, it2;
-
- for (it = groupingList.begin() ; it != groupingList.end() ; )
- {
- QList<ItemInfo> group;
- QString fname = it->name().left(it->name().lastIndexOf(QLatin1Char('.')));
- // don't know the leader yet so put first element also in group
- group << *it;
-
- for (it2 = it + 1 ; it2 != groupingList.end() ; ++it2)
- {
- QString fname2 = it2->name().left(it2->name().lastIndexOf(QLatin1Char('.')));
+ QList<CopyrightInfo> infos;
+
+ foreach (const CopyrightInfo& info, m_cache->infos)
+ {
+ if (info.property == property)
+ {
+ infos << info;
+ }
+ }
+
+ return infos;
+ }
+ else
+ {
+ return CoreDbAccess().db()->getItemCopyright(m_id, property);
+ }
+}
+
+QString ItemCopyright::readSimpleProperty(const QString& property) const
+{
+ return copyrightInfo(property).value;
+}
+
+void ItemCopyright::setSimpleProperty(const QString& property, const QString& value)
+{
+ CoreDbAccess().db()->setItemCopyrightProperty(m_id, property, value, QString(), CoreDB::PropertyUnique);
+}
+
+QString ItemCopyright::readLanguageProperty(const QString& property, const QString& languageCode)
+{
+ QList<CopyrightInfo> infos = copyrightInfos(property);
+ int index = languageMatch(infos, languageCode);
+
+ if (index == -1)
+ {
+ return QString();
+ }
+ else
+ {
+ return infos.at(index).value;
+ }
+}
+
+MetaEngine::AltLangMap ItemCopyright::readLanguageProperties(const QString& property)
+{
+ MetaEngine::AltLangMap map;
+ QList<CopyrightInfo> infos = copyrightInfos(property);
+
+ foreach (const CopyrightInfo& info, infos)
+ {
+ map[info.extraValue] = info.value;
+ }
- if (fname == fname2)
- {
- group << *it2;
- }
- else
- {
- break;
- }
- }
-
- // increment to next item not put in the group
- it = it2;
-
- if (group.count() > 1)
- {
- // sort by filesize and take smallest as leader
- std::stable_sort(group.begin(), group.end(), lowerThanBySizeForItemInfo);
- const ItemInfo& leader = group.takeFirst();
- FileActionMngr::instance()->addToGroup(leader, group);
- }
- }
-}
+ return map;
+}
+
+void ItemCopyright::setLanguageProperty(const QString& property, const QString& value,
+ const QString& languageCode, ReplaceMode mode)
+{
+ CoreDB::CopyrightPropertyUnique uniqueness;
+
+ if (mode == ReplaceAllEntries)
+ {
+ uniqueness = CoreDB::PropertyUnique;
+ }
+ else if (mode == ReplaceLanguageEntry)
+ {
+ uniqueness = CoreDB::PropertyExtraValueUnique;
+ }
+ else
+ {
+ uniqueness = CoreDB::PropertyNoConstraint;
+ }
+
+ QString language = languageCode;
-namespace
-{
-
-struct NumberInFilenameMatch
-{
- NumberInFilenameMatch()
- : value(0),
- containsValue(false)
- {
- }
-
- NumberInFilenameMatch(const QString& filename)<--- Struct 'NumberInFilenameMatch' has a constructor with 1 argument that is not explicit. [+]Struct 'NumberInFilenameMatch' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
- : NumberInFilenameMatch()
- {
- if (filename.isEmpty())
- {
- return;
- }
+ if (language.isNull())
+ {
+ language = QLatin1String("x-default");
+ }
+
+ CoreDbAccess().db()->setItemCopyrightProperty(m_id, property, value, language, uniqueness);
+}
+
+void ItemCopyright::removeProperties(const QString& property)
+{
+ // if we have a cache, find out if anything need to be done at all
+ if (m_cache && copyrightInfo(property).isNull())
+ {
+ return;
+ }
+
+ CoreDbAccess().db()->removeItemCopyrightProperties(m_id, property);
+}
- auto firstDigit = std::find_if(filename.begin(), filename.end(),
- [](const QChar& c)
- {
- return c.isDigit();
- });
-
- prefix = filename.leftRef(std::distance(filename.begin(), firstDigit));
-
- if (firstDigit == filename.end())
- {
- return;
- }
-
- auto lastDigit = std::find_if(firstDigit, filename.end(),
- [](const QChar& c)
- {
- return !c.isDigit();
- });
+void ItemCopyright::removeLanguageProperty(const QString& property, const QString& languageCode)
+{
+ if (m_cache && copyrightInfo(property).isNull())
+ {
+ return;
+ }
+
+ CoreDbAccess().db()->removeItemCopyrightProperties(m_id, property, languageCode);
+}
+
+int ItemCopyright::languageMatch(const QList<CopyrightInfo> infos, const QString& languageCode) const
+{
+ QString langCode;
+ QString fullCode = languageCode;
+
+ if (languageCode.isNull())
+ {
+ // find local language
- value = filename.midRef(prefix.size(),
- std::distance(firstDigit,
- lastDigit)).toULongLong(&containsValue);
-
- suffix = filename.midRef(std::distance(lastDigit, filename.end()));
- }
-
- bool directlyPreceeds(NumberInFilenameMatch const& other) const
- {
- if (!containsValue || !other.containsValue)
- {
- return false;
- }
+ QString spec = QLocale().name().toLower();
+ QString langCode = spec.left(spec.indexOf(QLatin1Char('_'))) + QLatin1Char('-');
+ QString fullCode = spec.replace(QLatin1Char('_'), QLatin1Char('-'));
+ }
+ else if (languageCode == QLatin1String("x-default"))
+ {
+ langCode = languageCode;
+ }
+ else
+ {
+ // en-us => en-
+ langCode = languageCode.section(QLatin1Char('-'), 0, 0, QString::SectionIncludeTrailingSep);
+ }
- if (prefix != other.prefix)
- {
- return false;
- }
-
- if (suffix != other.suffix)
- {
- return false;
- }
-
- return value+1 == other.value;
+ int fullCodeMatch, langCodeMatch, defaultCodeMatch, firstMatch;
+ fullCodeMatch = -1;
+ langCodeMatch = -1;
+ defaultCodeMatch = -1;
+ firstMatch = -1;
+
+ (void)firstMatch; // Remove clang warning.
+
+ if (infos.isEmpty())
+ {
+ return -1;
}
-
- qulonglong value;
- QStringRef prefix;
- QStringRef suffix;
- bool containsValue;
-};
-
-bool imageMatchesTimelapseGroup(const ItemInfoList& group, const ItemInfo& itemInfo)
-{
- if (group.size() < 2)
- {
- return true;
- }
-
- auto const timeBetweenPhotos = qAbs(group.first().dateTime()
- .secsTo(group.last()
- .dateTime())) / (group.size()-1);
-
- auto const predictedNextTimestamp = group.last().dateTime()
- .addSecs(timeBetweenPhotos);
-
- return (qAbs(itemInfo.dateTime().secsTo(predictedNextTimestamp)) <= 1);
-}
-
-} // namespace
-
-void ImageViewUtilities::createGroupByTimelapseFromInfoList(const ItemInfoList& itemInfoList)
-{
- if (itemInfoList.size() < 3)
- {
- return;
- }
+ else
+ {
+ firstMatch = 0; // index of first entry - at least we have one
+ }
+
+ // First we search for a full match
+ // Second for a match of the language code
+ // Third for the default code
+ // Fourth we return the first comment
+
+ QLatin1String defaultCode("x-default");
+
+ for (int i = 0 ; i < infos.size() ; ++i)
+ {
+ const CopyrightInfo& info = infos.at(i);
+
+ if (info.extraValue == fullCode)
+ {
+ fullCodeMatch = i;
+ break;
+ }
+ else if (info.extraValue.startsWith(langCode) && langCodeMatch == -1)
+ {
+ langCodeMatch = i;
+ }
+ else if (info.extraValue == defaultCode)
+ {
+ defaultCodeMatch = i;
+ }
+ }
+
+ int chosen = fullCodeMatch;
- ItemInfoList groupingList = itemInfoList;
-
- std::stable_sort(groupingList.begin(), groupingList.end(), lowerThanByNameForItemInfo);
-
- NumberInFilenameMatch previousNumberMatch;
- ItemInfoList group;
-
- for (const auto& itemInfo : groupingList)
- {
- NumberInFilenameMatch numberMatch(itemInfo.name());
-
- // if this is an end of currently processed group
- if (!previousNumberMatch.directlyPreceeds(numberMatch) || !imageMatchesTimelapseGroup(group, itemInfo))
- {
- if (group.size() > 2)
- {
- FileActionMngr::instance()->addToGroup(group.takeFirst(), group);
- }
-
- group.clear();
- }
-
- group.append(itemInfo);
- previousNumberMatch = std::move(numberMatch);
- }
-
- if (group.size() > 2)
- {
- FileActionMngr::instance()->addToGroup(group.takeFirst(), group);
- }
-}
-
-} // namespace Digikam
+ if (chosen == -1)
+ {
+ chosen = langCodeMatch;
+ }
+
+ if (chosen == -1)
+ {
+ chosen = defaultCodeMatch;
+ }
+
+ if (chosen == -1)
+ {
+ chosen = firstMatch;
+ }
+
+ return chosen;
+}
+
+} // namespace Digikam
|