1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2004-06-18
7  * Description : Core database interface.
8  *
9  * Copyright (C) 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2006-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  * Copyright (C) 2012      by Andi Clemens <andi dot clemens at gmail dot com>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_CORE_DB_H
28 #define DIGIKAM_CORE_DB_H
29 
30 // Qt includes
31 
32 #include <QStringList>
33 #include <QDateTime>
34 #include <QVariant>
35 #include <QString>
36 #include <QList>
37 #include <QPair>
38 #include <QUuid>
39 #include <QMap>
40 
41 // Local includes
42 
43 #include "coredbalbuminfo.h"
44 #include "coredbfields.h"
45 #include "coredbaccess.h"
46 #include "coredbconstants.h"
47 #include "digikam_export.h"
48 #include "dbenginesqlquery.h"
49 #include "album.h"
50 
51 namespace Digikam
52 {
53 
54 class CoreDbBackend;
55 
56 class DIGIKAM_DATABASE_EXPORT CoreDB
57 {
58 public:
59 
60     /**
61      * This adds a keyword-value combination to the database Settings table
62      * if the keyword already exists, the value will be replaced with the new
63      * value.
64      * @param keyword The keyword
65      * @param value The value
66      */
67     void setSetting(const QString& keyword, const QString& value);
68 
69     /**
70      * This function returns the value which is stored in the database
71      * (table Settings).
72      * @param keyword The keyword for which the value has to be returned.
73      * @return The values which belongs to the keyword, or a null string if
74      *         no value is set.
75      */
76     QString getSetting(const QString& keyword)                                                                      const;
77 
78     /**
79      * Get the settings for the file name filters of this database.
80      * Returns a list with lowercase suffixes only, no wildcards added ("png", not "*.png")
81      * Returned is a joint result of main and user settings.
82      * If you are not interested in a specific value, pass 0.
83      */
84     void getFilterSettings(QStringList* imageFilter, QStringList* videoFilter, QStringList* audioFilter);
85 
86     /**
87      * Returns the user-configurable filter settings.
88      * If you are not interested in a specific value, pass 0.
89      */
90     void getUserFilterSettings(QString* imageFilterString, QString* videoFilterString, QString* audioFilterString);
91 
92     /**
93      * Sets the main filter settings of the database. Should only be called at schema update.
94      */
95     void setFilterSettings(const QStringList& imageFilter, const QStringList& videoFilter, const QStringList& audioFilter);
96 
97     /**
98      * Sets the user-configurable filter settings. The lists shall be as specified for getFilterSettings.
99      * They may include entries starting with "-", which indicates that this format shall be removed from
100      * the list, if it is included in the main settings list.
101      */
102     void setUserFilterSettings(const QStringList& imageFilter, const QStringList& videoFilter, const QStringList& audioFilter);
103 
104     void setIgnoreDirectoryFilterSettings(const QStringList& ignoreDirectoryFilter);
105 
106     void setUserIgnoreDirectoryFilterSettings(const QStringList& ignoreDirectoryFilters);
107 
108     void getUserIgnoreDirectoryFilterSettings(QString* ignoreDirectoryFilterString);
109 
110     void getIgnoreDirectoryFilterSettings(QStringList* ignoreDirectoryFilter);
111 
112     /**
113      * Returns a UUID for the database file.
114      * This UUID is kept stable over schema updates.
115      */
116     QUuid databaseUuid();
117 
118     /**
119      * Returns the version used for the unique hash in this database.
120      * The value is cached.
121      */
122     int getUniqueHashVersion()                                                                                      const;
123 
124     void setUniqueHashVersion(int version);
125 
126     bool isUniqueHashV2()                                                                                           const;
127 
128     // ----------- AlbumRoot operations -----------
129 
130     /**
131      * Returns all albums and their attributes in the database
132      * @return a list of albums and their attributes
133      */
134     QList<AlbumRootInfo> getAlbumRoots()                                                                            const;
135 
136     /**
137      * Add a new album to the database with the given attributes
138      * @param type The type of the album root
139      * @param specificPath The path specific to volume
140      * @param label        An (optional) user-visible label
141      * @returns the album root id of the newly created root
142      */
143     int addAlbumRoot(AlbumRoot::Type type, const QString& identifier,
144                      const QString& specificPath, const QString& label)                                             const;
145 
146     /**
147      * Deletes an album  root from the database.
148      * @param rootId the id of the album root
149      */
150     void deleteAlbumRoot(int rootId);
151 
152     /**
153      * Migrates a given album root to a new disk location. This only changes the values
154      * in the AlbumRoots table. It is expected that this merely reflects underlying partition changes,
155      * still pointing to the same data.
156      */
157     void migrateAlbumRoot(int rootId, const QString& identifier);
158 
159     /**
160      * Changes the label of the specified album root
161      * @param rootId the id of the album root
162      * @param newLabel new label for the album root
163      */
164     void setAlbumRootLabel(int rootId, const QString& newLabel);
165 
166     /**
167      * Changes the specificPath of the specified album root
168      * @param rootId the id of the album root
169      * @param newPath new path for the album root
170      */
171     void setAlbumRootPath(int rootId, const QString& newPath);
172 
173     /**
174      * Sets the type of the specified album root to a new value.
175      */
176     void changeAlbumRootType(int rootId, AlbumRoot::Type newType);
177 
178     // ----------- Album Listing operations -----------
179     /**
180      * Returns all albums and their attributes in the database
181      * @return a list of albums and their attributes
182      */
183     AlbumInfo::List scanAlbums()                                                                                    const;
184 
185     /**
186      * Returns all tags and their attributes in the database
187      * @return a list of tags and their attributes
188      */
189     TagInfo::List scanTags()                                                                                        const;
190     TagInfo getTagInfo(int tagId)                                                                                   const;
191 
192     /**
193      * Returns all searches from the database
194      * @return a list of searches from the database
195      */
196     SearchInfo::List scanSearches()                                                                                 const;
197 
198     /**
199      * Returns all albums in the database with their albumRoot and ID,
200      * ordered by id.
201      */
202     QList<AlbumShortInfo> getAlbumShortInfos()                                                                      const;
203 
204     /**
205      * Returns all tags in the database with their parent id and name,
206      * ordered by id.
207      */
208     QList<TagShortInfo> getTagShortInfos()                                                                          const;
209 
210     // ----------- Operations on PAlbums -----------
211 
212     /**
213      * Add a new album to the database with the given attributes
214      * @param albumRootId   id of the album root of the new album
215      * @param relativePath  url of the album
216      * @param caption       the album caption
217      * @param date          the date for the album
218      * @param collection    the album collection
219      * @return the id of the album added or -1 if it failed
220      */
221     int addAlbum(int albumRootId, const QString& relativePath,
222                  const QString& caption,
223                  const QDate& date, const QString& collection)                                                      const;
224 
225     /**
226      * Find out the album for a given folder.
227      * @param albumRootId  id of the album root of the album
228      * @param relativePath The relative path for which you want the albumID relative to the album root
229      * @param create       If true, an album is newly created if it does not yet exist.
230      *                     If false, -1 is returned if no album exists.
231      * @return The albumID for that folder,
232      *         or -1 if it does not exist and create is false.
233      */
234     int  getAlbumForPath(int albumRootId, const QString& relativePath, bool create = true)                          const;
235 
236     /**
237      * Find out the album ids for a given relative path, including the subalbums.
238      * @param albumRootId  id of the album root of the album
239      * @param relativePath The path for which you want the albumIDs relative to the album root
240      * @return a list of album ids. The list is empty if no albums are found.
241      */
242     QList<int> getAlbumAndSubalbumsForPath(int albumRootId, const QString& relativePath)                            const;
243 
244     /**
245      * Find out all album ids of a given album root
246      * @return a list of album ids.
247      */
248     QList<int> getAlbumsOnAlbumRoot(int albumRootId)                                                                const;
249 
250     /**
251      * Deletes an album from the database. This will not delete the
252      * subalbums of the album.
253      * @param albumID the id of the album
254      */
255     void deleteAlbum(int albumID);
256 
257     /** Makes the album a stale entry by setting the albumRoot to 0.
258      *  Emits the same changeset as deleteAlbum()
259      */
260     void makeStaleAlbum(int albumID);
261 
262     /**
263      * Deletes albums from the database that were previously removed
264      * with makeStaleAlbum()
265      */
266     void deleteStaleAlbums();
267 
268     /**
269      * Copy the properties of the given srcAlbum to the dstAlbum.
270      * Both albums must exist.
271      * @return true if the operations succeeds
272      */
273     bool copyAlbumProperties(int srcAlbumID, int dstAlbumID)                                                        const;
274 
275     /**
276      * Give an existing album a new relativePath and a newAlbumRootId
277      */
278     void renameAlbum(int albumID, int newAlbumRootId, const QString& newRelativePath);
279 
280     /**
281      * Set a caption for the album.
282      * @param albumID the id of the album
283      * @param caption the new caption for the album
284      */
285     void setAlbumCaption(int albumID, const QString& caption);
286 
287     /**
288      * Set a category for the album.
289      * @param albumID  the id of the album
290      * @param category the new category for the album
291      */
292     void setAlbumCategory(int albumID, const QString& category);
293 
294     /**
295      * Set a date for the album.
296      * @param albumID  the id of the album
297      * @param date     the date for the album
298      */
299     void setAlbumDate(int albumID, const QDate& date);
300 
301     /**
302      * Set the modification date time for the album.
303      * @param albumID  the id of the album
304      * @param dateTime the modification date time for the album
305      */
306     void setAlbumModificationDate(int albumID, const QDateTime& modificationDate);
307 
308     /**
309      * Set the icon for the album.
310      * @param albumID the id of the album
311      * @param iconID  the id of the icon file
312      */
313     void setAlbumIcon(int albumID, qlonglong iconID);
314 
315     /**
316      * Given an albumid, this returns the album root id for that album
317      * @param albumID the id of the albumdb
318      * @return the id of the album root of this album
319      */
320     int getAlbumRootId(int albumID)                                                                                 const;
321 
322     /**
323      * Given an albumid, this returns the relative path for that album
324      * (the path below the album root, starting with a slash)
325      * @param albumID the id of the album
326      * @return the url of the album
327      */
328     QString getAlbumRelativePath(int albumID)                                                                       const;
329 
330     /**
331      * Returns the lowest/oldest date of all images for that album.
332      * @param albumID the id of the album to calculate
333      * @return the date.
334      */
335     QDate getAlbumLowestDate(int albumID)                                                                           const;
336 
337     /**
338      * Returns the highest/newest date of all images for that album.
339      * @param albumID the id of the album to calculate
340      * @return the date.
341      */
342     QDate getAlbumHighestDate(int albumID)                                                                          const;
343 
344     /**
345      * Returns the average date of all images for that album.
346      * @param albumID the id of the album to calculate
347      * @return the date.
348      */
349     QDate getAlbumAverageDate(int albumID)                                                                          const;
350 
351     /**
352      * Returns the QPair<int, int> of all items (first)
353      * and albums (second) as a counter in the album.
354      * @param albumID the id of the album
355      */
356     QPair<int, int> getNumberOfAllItemsAndAlbums(int albumID)                                                       const;
357 
358     /**
359      * Returns the number of items in the album.
360      * @param albumID the id of the album
361      */
362     int getNumberOfItemsInAlbum(int albumID)                                                                        const;
363 
364     /**
365      * Returns the QDateTime of the album modification date.
366      * @param albumID the id of the album
367      */
368     QDateTime getAlbumModificationDate(int albumID)                                                                 const;
369 
370     /**
371      * Returns a QMap with relative path and the album modification date.
372      * @param albumRootID id of the album root of the album
373      */
374     QMap<QString, QDateTime> getAlbumModificationMap(int albumRootId)                                               const;
375 
376     /**
377      * Returns a QMap<int, int> of album id -> count of items
378      * in the album
379      */
380     QMap<int, int> getNumberOfImagesInAlbums()                                                                      const;
381 
382     // ----------- Operations on TAlbums -----------
383 
384     /**
385      * Adds a new tag to the database with given name, icon and parent id.
386      * @param parentTagID the id of the tag which will become the new tags parent
387      * @param name        the name of the tag
388      * @param iconKDE     the name of the icon file (this is filename which kde
389      * iconloader can load up)
390      * @param iconID      the id of the icon file
391      * Note: if the iconKDE parameter is empty, then the iconID parameter is used
392      * @return the id of the tag added or -1 if it failed
393      */
394     int addTag(int parentTagID, const QString& name,
395                const QString& iconKDE, qlonglong iconID)                                                            const;
396 
397     /**
398      * Get a list of recently assigned tags (only last 6 tags are listed)
399      * @return the list of recently assigned tags
400      */
401     // TODO move to other place (AlbumManager)
402     QList<int> getRecentlyAssignedTags()                                                                            const;
403 
404     /**
405      * Deletes a tag from the database. This will not delete the
406      * subtags of the tag.
407      * @param tagID the id of the tag
408      */
409     void deleteTag(int tagID);
410 
411     /**
412      * Set a new name for the tag.
413      * @param tagID the id of the tag
414      * @param name  the new name for the tag
415      */
416     void setTagName(int tagID, const QString& name);
417 
418     /**
419      * Set the icon for the tag.
420      * @param tagID the id of the tag
421      * @param iconKDE the filename for the kde icon file
422      * @param iconID the id of the icon file
423      * Note: Only one of the iconKDE or iconID parameters is used.
424      * if the iconKDE parameter is empty, then the iconID parameter is used
425      */
426     void setTagIcon(int tagID, const QString& iconKDE, qlonglong iconID);
427 
428     /**
429      * Set the parent tagid for the tag. This is equivalent to reparenting
430      * the tag
431      * @param tagID          the id of the tag
432      * @param newParentTagID the new parentid for the tag
433      */
434     void setTagParentID(int tagID, int newParentTagID);
435 
436     /**
437      * Returns the list of all tag properties (ordered by tag id, then property).
438      */
439     QList<TagProperty> getTagProperties()                                                                           const;
440 
441     /**
442      * Returns the list of tag properties of the given tag.
443      */
444     QList<TagProperty> getTagProperties(int tagID)                                                                  const;
445 
446     /**
447      * Returns the list of tag properties with the given attribute.
448      */
449     QList<TagProperty> getTagProperties(const QString& property)                                                    const;
450 
451     /**
452      * Adds a tag property. Note that this never replaces existing entries.
453      * It is also all right to add multiple entries for a tag with the same property.
454      * To replace an existing entry, remove the entry before.
455      */
456     void addTagProperty(int tagId, const QString& property, const QString& value);
457     void addTagProperty(const TagProperty& property);
458 
459     /**
460      * Removes properties for the given tag. If the value is given, removes only
461      * the entries with the given property/value pair. If only property is given,
462      * removes all properties with the given name. If property is null,
463      * removes all properties for the given tag.
464      */
465     void removeTagProperties(int tagId, const QString& property = QString(), const QString& value = QString());
466 
467     /**
468      * Returns a list of tag ids with the specified property.
469      * FIXME: Not tested, might not work at all.
470      */
471     QList<int> getTagsWithProperty(const QString& property)                                                         const;
472 
473     // ----------- Operations on SAlbums -----------
474 
475     /**
476      * Add a new search to the database with the given attributes
477      * @param type       search type
478      * @param name       name of the search
479      * @param query      search query to use
480      * @return the id of the album added or -1 if it failed
481      */
482     int addSearch(DatabaseSearch::Type type, const QString& name, const QString& query)                             const;
483 
484     /**
485      * Updates Search with new attributes
486      * @param searchID   the id of the search
487      * @param type       type of the search
488      * @param query      database query of the search
489      */
490     void updateSearch(int searchID, DatabaseSearch::Type type,
491                       const QString& name, const QString& query);
492 
493     /**
494      * Delete a search from the database.
495      * @param searchID the id of the search
496      */
497     void deleteSearch(int searchID);
498 
499     /**
500      * Delete all search with the given type
501      */
502     void deleteSearches(DatabaseSearch::Type type);
503 
504     /**
505      * Get information about the specified search
506      */
507     SearchInfo getSearchInfo(int searchId)                                                                          const;
508 
509     /**
510      * Get the query for the search specified by its id
511      */
512     QString getSearchQuery(int searchId)                                                                            const;
513 
514     // ----------- Adding and deleting Items -----------
515     /**
516      * Put a new item in the database or replace an existing one.
517      * @return the id of item added or -1 if it fails
518      */
519     qlonglong addItem(int albumID, const QString& name,
520                       DatabaseItem::Status status,
521                       DatabaseItem::Category category,
522                       const QDateTime& modificationDate,
523                       qlonglong fileSize,
524                       const QString& uniqueHash)                                                                    const;
525 
526     /**
527      * Deletes an item from the database.
528      * @param albumID The id of the album.
529      * @param file The filename of the file to delete.
530      */
531     void deleteItem(int albumID, const QString& file);
532 
533     /**
534      * Deletes an item from the database if it does not belong to an album.
535      * This method can only be used if the album of the image is NULL!
536      * @param imageId The id of the image.
537      */
538     void deleteItem(qlonglong imageId);
539 
540     /**
541      * Marks all items in the specified album as removed,
542      * resets their dirids.
543      * The album can be deleted afterwards without removing
544      * the entries for the items, which
545      * can later be removed by deleteRemovedItems().
546      * @param albumID The id of the album
547      * @param ids Fully optional: The image ids in the album, if you know them anyway.
548      *            This parameter is only used for distributing the change notification.
549      */
550     void removeItemsFromAlbum(int albumID, const QList<qlonglong>& ids_forInformation = QList<qlonglong>());
551 
552     /**
553      * Marks all items in the list as removed,
554      * resets their dirids.
555      * The items can later be removed by deleteRemovedItems().
556      * @param itemIDs a list of item IDs to be marked
557      * @param albumIDs this parameter is purely informational.
558      *                 it shall contain the albums that the items are removed from.
559      */
560     void removeItems(QList<qlonglong> itemIDs, const QList<int>& albumIDs = QList<int>());
561 
562     /**
563      * Marks all items in the list as obsolete,
564      * resets their dirids.
565      * The items can later be removed by deleteRemovedItems().
566      * @param itemIDs a list of item IDs to be marked
567      * @param albumIDs this parameter is purely informational.
568      *                 it shall contain the albums that the items are removed from.
569      */
570     void removeItemsPermanently(QList<qlonglong> itemIDs, const QList<int>& albumIDs = QList<int>());
571 
572     /**
573      * Delete all items from the database that are marked as removed.
574      * Use with care!
575      */
576     void deleteRemovedItems();
577 
578     // ----------- Finding items -----------
579 
580     /**
581      * Get the imageId of the item
582      * @param albumID the albumID of the item
583      * @param name the name of the item
584      * @return the ImageId for the item, or -1 if it does not exist
585      */
586     qlonglong getImageId(int albumID, const QString& name)                                                          const;
587 
588     /**
589      * Get the imageId fitting to the information given for the item
590      * @param albumID the albumID of the item (-1 means NULL)
591      * @param name the name of the item
592      * @param status the status of the item
593      * @return the ImageIds for the item, or an empty list if there are no matching entries.
594      */
595     QList<qlonglong> getImageIds(int albumID, const QString& name,
596                                  DatabaseItem::Status status)                                                       const;
597 
598     /**
599      * Returns all image ids with the given status.
600      * @param status The status.
601      * @return The ids of the images that have the given status.
602      */
603     QList<qlonglong> getImageIds(DatabaseItem::Status status)                                                       const;
604 
605     /**
606      * Returns all image ids with the given status and category.
607      * @param status The status.
608      * @param category The category.
609      * @return The ids of the images that have the given status.
610      */
611     QList<qlonglong> getImageIds(DatabaseItem::Status status,
612                                  DatabaseItem::Category category)                                                   const;
613 
614     /**
615      * Find the imageId fitting to the information given for the item
616      * @param albumID the albumID of the item (-1 means NULL)
617      * @param name the name of the item
618      * @param status the status of the item
619      * @param category the category of the item
620      * @param fileSize the file size
621      * @param uniqueHash the unique hash
622      * @return the ImageId for the item, or -1 if no matching or more than one infos were found.
623      */
624     qlonglong findImageId(int albumID, const QString& name,
625                           DatabaseItem::Status status,
626                           DatabaseItem::Category category,
627                           qlonglong fileSize,
628                           const QString& uniqueHash)                                                                const;
629 
630     enum ItemSortOrder
631     {
632         NoItemSorting,
633         ByItemName,
634         ByItemPath,
635         ByItemDate,
636         ByItemRating
637     };
638 
639     /**
640      * Returns all items for a given albumid. This is used to
641      * verify if all items on disk are consistent with the database
642      * in the CollectionScanner class.
643      * @param albumID The albumID for which you want all items.
644      * @param recursive perform a recursive folder hierarchy parsing
645      * @return It returns a QStringList with the filenames.
646      */
647     QStringList getItemNamesInAlbum(int albumID, bool recursive = false)                                            const;
648 
649     /**
650      * Returns all ids of items in images table.
651      */
652     QList<qlonglong> getAllItems()                                                                                  const;
653 
654     /**
655      * Returns all ids of items with album ids in images table.
656      * QPair.first  == albumRootID
657      * QPair.second == albumID
658      */
659     QHash<qlonglong, QPair<int, int> > getAllItemsWithAlbum()                                                       const;
660 
661     /**
662      * Returns the id of the item with the given filename in
663      * the album with the given id.
664      * @param albumId The albumId in which we search the item.
665      * @param fileName The name of the item file.
666      * @return The item id or -1 if not existent.
667      */
668     qlonglong getItemFromAlbum(int albumID, const QString& fileName)                                                const;
669 
670     /**
671      * Returns an ItemScanInfo object for each item in the album
672      * with the specified album id.
673      */
674     QList<ItemScanInfo> getItemScanInfos(int albumID)                                                               const;
675 
676     /**
677      * Given a albumID, get a list of the url of all items in the album
678      * NOTE: Uses the CollectionManager
679      * @param  albumID the id of the album
680      * @param  order   order for the returned items to use
681      * @return a list of urls for the items in the album. The urls are the
682      * absolute path of the items
683      */
684     QStringList getItemURLsInAlbum(int albumID, ItemSortOrder order = NoItemSorting)                                const;
685 
686     /**
687      * Given a albumID, get a list of Ids of all items in the album
688      * @param  albumID the id of the album
689      * @return a list of Ids for the items in the album.
690      */
691     QList<qlonglong> getItemIDsInAlbum(int albumID)                                                                 const;
692 
693     /**
694      * Given a albumID, get a map of Ids and urls of all items in the album
695      * NOTE: Uses the CollectionManager
696      * @param  albumID the id of the album
697      * @return a map of Ids and urls for the items in the album. The urls are the
698      * absolute path of the items
699      */
700     QMap<qlonglong, QString> getItemIDsAndURLsInAlbum(int albumID)                                                  const;
701 
702     /**
703      * Given a tagid, get a list of the url of all items in the tag
704      * NOTE: Uses the CollectionManager
705      * @param  tagID the id of the tag
706      * @param  recursive perform a recursive folder hierarchy parsing
707      * @return a list of urls for the items in the tag. The urls are the
708      * absolute path of the items
709      */
710     QStringList getItemURLsInTag(int tagID, bool recursive = false)                                                 const;
711 
712     /**
713      * Given a tagID, get a list of Ids of all items in the tag
714      * @param  tagID the id of the tag
715      * @param  recursive perform a recursive folder hierarchy parsing
716      * @return a list of Ids for the items in the tag.
717      */
718     QList<qlonglong> getItemIDsInTag(int tagID, bool recursive = false)                                             const;
719 
720     /**
721      * Returns a QVariantList of creationDate of all items
722      */
723     QVariantList getAllCreationDates()                                                                              const;
724 
725     // ----------- Item properties -----------
726 
727     /**
728      * Find the album of an item
729      * @param imageID The ID of the item
730      * @return The ID of the PAlbum of the item, or -1 if not found
731      */
732     int getItemAlbum(qlonglong imageID)                                                                             const;
733 
734     /**
735      * Retrieve the name of the item
736      * @param imageID The ID of the item
737      * @return The name of the item, or a null string if not found
738      */
739     QString getItemName(qlonglong imageID)                                                                          const;
740 
741     /**
742      * Get item and album info from the image ID
743      */
744     ItemShortInfo getItemShortInfo(qlonglong imageID)                                                               const;
745 
746     /**
747      * Get item and album if from albumRootId, album path and file name.
748      */
749     ItemShortInfo getItemShortInfo(int albumRootId, const QString& relativePath,
750                                    const QString& name)                                                             const;
751 
752     /**
753      * Get scan info from the image ID
754      */
755     ItemScanInfo getItemScanInfo(qlonglong imageID)                                                                 const;
756 
757     /**
758      * Update the fields of the Images table that have changed when
759      * the file has been modified on disk.
760      * @param imageID the image that has been modified
761      */
762     void updateItem(qlonglong imageID,
763                     DatabaseItem::Category category,
764                     const QDateTime& modificationDate,
765                     qlonglong fileSize,
766                     const QString& uniqueHash);
767 
768     /**
769      * Updates the status field for the item.
770      * Note: Do not use this to set to the Removed status, see removeItems().
771      */
772     void setItemStatus(qlonglong imageID, DatabaseItem::Status status);
773 
774     /**
775      * Updates the album field for the item.
776      * Note: Do not use this to move the item. This function only has the purpose to
777      * reuse image infos for restored images from trash.
778      */
779     void setItemAlbum(qlonglong imageID, qlonglong albumId);
780 
781     /**
782      * Updates the manualOrder field for the item.
783      */
784     void setItemManualOrder(qlonglong imageID, qlonglong value);
785 
786     /**
787      * Updates the modification date field for the item.
788      */
789     void setItemModificationDate(qlonglong imageID, const QDateTime& modificationDate);
790 
791     /**
792      * Rename the item.
793      * Note: we not use here ImageChangeset.
794      */
795     void renameItem(qlonglong imageID, const QString& newName);
796 
797     /**
798      * Returns the requested fields from the Images table.
799      * Choose the fields with the mask.
800      * The fields will be returned in the following order and type:
801      * 0) Int       Album
802      * 1) String    Name
803      * 2) Int       Status
804      * 3) Int       Category
805      * 4) DateTime  ModificationDate
806      * 5) int       FileSize
807      * 6) String    uniqueHash
808      */
809     QVariantList getImagesFields(qlonglong imageID,
810                                  DatabaseFields::Images imagesFields)                                               const;
811 
812     /**
813      * Add (or replace) the ItemInformation of the specified item.
814      * If there is already an entry, it will be discarded.
815      * The QVariantList shall have 9 entries, of types in this order:
816      * 0) Int       rating
817      * 1) DateTime* creationDate
818      * 2) DateTime* digitizationDate
819      * 3) Int       orientation
820      * 4) Int       width
821      * 5) Int       height
822      * 6) String    format
823      * 7) Int       colorDepth
824      * 8) Int       colorModel
825      * ( (*) You can provide the date also as a string in the format Qt::IsoDate)
826      * You can leave out entries from this list, which will then be filled with null values.
827      * Indicate the values that you have passed in the ItemInformation flag in the third parameters.
828      */
829     void addItemInformation(qlonglong imageID, const QVariantList& infos,
830                             DatabaseFields::ItemInformation fields = DatabaseFields::ItemInformationAll);
831 
832     /**
833      * Change the indicated fields of the image information for the specified item.
834      * Fields not indicated by the fields parameter will not be touched.
835      * This method does nothing if the item does not yet have an entry in the ItemInformation table.
836      * The parameters are as for the method above.
837      */
838     void changeItemInformation(qlonglong imageID, const QVariantList& infos,
839                                DatabaseFields::ItemInformation fields = DatabaseFields::ItemInformationAll);
840 
841     /**
842      * Read image information. Parameters as above.
843      */
844     QVariantList getItemInformation(qlonglong imageID,
845                                     DatabaseFields::ItemInformation infoFields
846                                         = DatabaseFields::ItemInformationAll)                                       const;
847 
848     /**
849      * Add (or replace) the ImageMetadata of the specified item.
850      * If there is already an entry, it will be discarded.
851      * The QVariantList shall have at most 16 entries, of types as defined
852      * in the DBSCHEMA and in metadatainfo.h, in this order:
853      *  0) String    make
854      *  1) String    model
855      *  2) String    lens
856      *  3) Double    aperture
857      *  4) Double    focalLength
858      *  5) Double    focalLength35
859      *  6) Double    exposureTime
860      *  7) Int       exposureProgram
861      *  8) Int       exposureMode
862      *  9) Int       sensitivity
863      * 10) Int       flash
864      * 11) Int       WhiteBalance
865      * 12) Int       WhiteBalanceColorTemperature
866      * 13) Int       meteringMode
867      * 14) Double    subjectDistance
868      * 15) Double    subjectDistanceCategory
869      * You can leave out entries from this list. Indicate the values that you have
870      * passed in the ImageMetadata flag in the third parameters.
871      */
872     void addImageMetadata(qlonglong imageID, const QVariantList& infos,
873                           DatabaseFields::ImageMetadata fields = DatabaseFields::ImageMetadataAll);
874 
875     /**
876      * Change the indicated fields of the image information for the specified item.
877      * This method does nothing if the item does not yet have an entry in the ItemInformation table.
878      * The parameters are as for the method above.
879      */
880     void changeImageMetadata(qlonglong imageID, const QVariantList& infos,
881                              DatabaseFields::ImageMetadata fields = DatabaseFields::ImageMetadataAll);
882 
883     /**
884      * Read image metadata. Parameters as above.
885      */
886     QVariantList getImageMetadata(qlonglong imageID,
887                                   DatabaseFields::ImageMetadata metadataFields = DatabaseFields::ImageMetadataAll) const;
888 
889     /**
890      * Add (or replace) the VideoMetadata of the specified item.
891      * If there is already an entry, it will be discarded.
892      * The QVariantList shall have 8 entries, of types in this order:
893      * 0) String    AspectRatio
894      * 1) String    AudioBitRate
895      * 2) String    AudioChannelType
896      * 3) String    AudioCodec
897      * 4) String    Duration
898      * 5) String    FrameRate
899      * 6) String    VideoCodec
900      * You can leave out entries from this list, which will then be filled with null values.
901      * Indicate the values that you have passed in the VideoMetadata flag in the third parameters.
902      */
903     void addVideoMetadata(qlonglong imageID, const QVariantList& infos,
904                           DatabaseFields::VideoMetadata fields = DatabaseFields::VideoMetadataAll);
905 
906     /**
907      * Change the indicated fields of the video information for the specified item.
908      * This method does nothing if the item does not yet have an entry in the ItemInformation table.
909      * The parameters are as for the method above.
910      */
911     void changeVideoMetadata(qlonglong imageID, const QVariantList& infos,
912                              DatabaseFields::VideoMetadata fields = DatabaseFields::VideoMetadataAll);
913 
914     /**
915      * Read video metadata. Parameters as above.
916      */
917     QVariantList getVideoMetadata(qlonglong imageID,
918                                   DatabaseFields::VideoMetadata metadataFields = DatabaseFields::VideoMetadataAll)  const;
919 
920     /**
921      * Add (or replace) the ItemPosition of the specified item.
922      * If there is already an entry, it will be discarded.
923      * The QVariantList shall have at most 10 entries, of types in this order:
924      * 0) String    Latitude
925      * 1) Double    LatitudeNumber
926      * 2) String    Longitude
927      * 3) Double    LongitudeNumber
928      * 4) Double    Altitude
929      * 5) Double    Orientation
930      * 6) Double    Tilt
931      * 7) Double    Roll
932      * 8) Double    Accuracy
933      * 9) String    Description
934      * You can leave out entries from this list. Indicate the values that you have
935      * passed in the ItemInfo flag in the third parameters.
936      */
937     void addItemPosition(qlonglong imageID, const QVariantList& infos,
938                           DatabaseFields::ItemPositions fields = DatabaseFields::ItemPositionsAll);
939 
940     /**
941      * Change the indicated fields of the image information for the specified item.
942      * This method does nothing if the item does not yet have an entry in the ItemInformation table.
943      * The parameters are as for the method above.
944      */
945     void changeItemPosition(qlonglong imageID, const QVariantList& infos,
946                             DatabaseFields::ItemPositions fields = DatabaseFields::ItemPositionsAll);
947 
948     /**
949      * Read image metadata. Parameters as above.
950      */
951     QVariantList getItemPosition(qlonglong imageID,
952                                  DatabaseFields::ItemPositions positionFields = DatabaseFields::ItemPositionsAll)   const;
953 
954     QVariantList getItemPositions(QList<qlonglong> imageIDs, DatabaseFields::ItemPositions fields)                  const;
955 
956     /**
957      * Remove the entry in ItemPositions for the given image
958      */
959     void removeItemPosition(qlonglong imageid);
960 
961     /**
962      * Remove the altitude in ItemPositions for the given image
963      */
964     void removeItemPositionAltitude(qlonglong imageid);
965 
966     /**
967      * Retrieves all available comments for the specified item.
968      */
969     QList<CommentInfo> getItemComments(qlonglong imageID)                                                           const;
970 
971     /**
972      * Sets the comments for the image. A comment for the image with the same
973      * source, language and author will be overwritten.
974      * @param imageID  The imageID of the image
975      * @param comment  The comment string
976      * @param type     The type of the comment
977      * @param language Information about the language of the comment. A null string shall be used
978      *                 if language information is not available from the source, or if
979      *                 the comment is in the default language.
980      * @param author   Optional information about the author who wrote the comment.
981      *                 If not supported by the source, pass a null string.
982      * @param date     Optional information about the date when the comment was written
983      *                 If not supported by the source, pass a null string.
984      * @returns the comment ID of the comment
985      */
986     int setImageComment(qlonglong imageID, const QString& comment, DatabaseComment::Type type,
987                         const QString& language = QString(), const QString& author = QString(),
988                         const QDateTime& date = QDateTime())                                                        const;
989 
990     /**
991      * Changes the properties of a comment.
992      * The QVariantList shall have at most 5 entries, of types in this order:
993      * 0) Int       Type
994      * 1) String    Language
995      * 2) String    Author
996      * 3) DateTime  Date
997      * 4) String    Comment
998      */
999     void changeImageComment(int commentId, qlonglong imageID, const QVariantList& infos,
1000                             DatabaseFields::ItemComments fields = DatabaseFields::ItemCommentsAll);
1001 
1002     /**
1003      * Remove the specified entry in ItemComments
1004      */
1005     void removeImageComment(int commentId, qlonglong imageid);
1006 
1007     /**
1008      * Returns the property with the specified name for the specified image
1009      */
1010     QString getImageProperty(qlonglong imageID, const QString& property)                                            const;
1011 
1012     /**
1013      * Sets the property with the given name for the given image to the specified value
1014      */
1015     void setImageProperty(qlonglong imageID, const QString& property, const QString& value);
1016     void removeImageProperty(qlonglong imageID, const QString& property);
1017     void removeImagePropertyByName(const QString& property);
1018 
1019     /**
1020      * Returns the copyright properties of the specified image.
1021      * If property is not null, only the given property is returned.
1022      */
1023     QList<CopyrightInfo> getItemCopyright(qlonglong imageID, const QString& property = QString())                   const;
1024 
1025     enum CopyrightPropertyUnique
1026     {
1027         PropertyUnique,
1028         PropertyExtraValueUnique,
1029         PropertyNoConstraint
1030     };
1031 
1032     /**
1033      * Sets the property with the given name for the given image to the specified value and extraValue
1034      */
1035     void setItemCopyrightProperty(qlonglong imageID, const QString& property,
1036                                    const QString& value, const QString& extraValue = QString(),
1037                                    CopyrightPropertyUnique uniqueness = PropertyUnique);
1038 
1039     /**
1040      * Removes copyright properties for the given image id. All values after the first null value,
1041      * in order of parameters, are treated as wild cards (you can give value as wildcard; value and
1042      * extraValue; or property, extraValue and value).
1043      * Note that extraValue is ordered before value in this method!
1044      */
1045     void removeItemCopyrightProperties(qlonglong imageID, const QString& property = QString(),
1046                                         const QString& extraValue = QString(),
1047                                         const QString& value = QString() /* NOTE parameter order */);
1048 
1049     /**
1050      * Returns all items with the given file name and creation date.
1051      */
1052     QList<qlonglong> findByNameAndCreationDate(const QString& fileName, const QDateTime& creationDate)              const;
1053 
1054     /**
1055      * Retrieves the history entry for the given image.
1056      */
1057     ImageHistoryEntry getItemHistory(qlonglong imageId)                                                             const;
1058 
1059     /**
1060      * Retrieves the image UUID
1061      */
1062     QString getImageUuid(qlonglong imageId)                                                                         const;
1063 
1064     /**
1065      * Retrieves the images with the given UUID
1066      */
1067     QList<qlonglong> getItemsForUuid(const QString& uuid)                                                           const;
1068 
1069     /**
1070      * Changes (adds or updates) the image history
1071      */
1072     void setItemHistory(qlonglong imageId, const QString& history);
1073     void setImageUuid(qlonglong imageId, const QString& uuid);
1074 
1075     /**
1076      * Returns true if the image has a history stored in DB
1077      * If not, it returns false
1078      */
1079     bool hasImageHistory(qlonglong imageId)                                                                         const;
1080 
1081     /**
1082      * Adds an image relation entry.
1083      */
1084     void addImageRelation(qlonglong subjectId, qlonglong objectId, DatabaseRelation::Type type);
1085     void addImageRelation(const ImageRelation& relation);
1086 
1087     /**
1088      * This method requires two lists of same size and will add list1[0]->list2[0],...,list1[n]->list2[n]
1089      */
1090     void addImageRelations(const QList<qlonglong>& subjectIds, const QList<qlonglong>& objectIds,
1091                            DatabaseRelation::Type type);
1092 
1093     /**
1094      * Removes image relations.
1095      * The batch methods return all removed partners.
1096      */
1097     void removeImageRelation(qlonglong subjectId, qlonglong objectId, DatabaseRelation::Type type);
1098     void removeImageRelation(const ImageRelation& relation);
1099 
1100     QList<qlonglong> removeAllImageRelationsTo(qlonglong objectId, DatabaseRelation::Type type)                     const;
1101     QList<qlonglong> removeAllImageRelationsFrom(qlonglong subjectId, DatabaseRelation::Type type)                  const;
1102 
1103     /**
1104      * Retrieves all images that the given image is related to (retrieves objects, given image is subject)
1105      * If type is given, filters by type, otherwise returns all types.
1106      * "Get images related to from this"
1107      */
1108     QList<qlonglong> getImagesRelatedFrom(qlonglong subjectId,
1109                                           DatabaseRelation::Type type = DatabaseRelation::UndefinedType)            const;
1110     bool hasImagesRelatedFrom(qlonglong subjectId,
1111                               DatabaseRelation::Type type = DatabaseRelation::UndefinedType)                        const;
1112     QVector<QList<qlonglong> > getImagesRelatedFrom(const QList<qlonglong>& subjectIds,
1113                                                     DatabaseRelation::Type type = DatabaseRelation::UndefinedType)  const;
1114     /**
1115      * Retrieves all images that relate to the given image (retrieves subject, given image is object)
1116      * If type is given, filters by type, otherwise returns all types.
1117      * "Get images this image is relating to"
1118      */
1119     QList<qlonglong> getImagesRelatingTo(qlonglong objectId,
1120                                          DatabaseRelation::Type type = DatabaseRelation::UndefinedType)             const;
1121     bool hasImagesRelatingTo(qlonglong objectId,
1122                              DatabaseRelation::Type type = DatabaseRelation::UndefinedType)                         const;
1123     QVector<QList<qlonglong> > getImagesRelatingTo(const QList<qlonglong>& objectIds,
1124                                                    DatabaseRelation::Type type = DatabaseRelation::UndefinedType)   const;
1125 
1126     /**
1127      * For the given image id, retrieves all relations of all related images:
1128      * Each pair (a,b) means "a is related to b".
1129      * Each a and b in the list will have a direct or indirect relation to the initial imageId.
1130      * If type is given, filters by type, otherwise returns all types.
1131      */
1132     QList<QPair<qlonglong, qlonglong> > getRelationCloud(qlonglong imageId,
1133                                                          DatabaseRelation::Type type
1134                                                              = DatabaseRelation::UndefinedType)                     const;
1135 
1136     /**
1137      * For each of the given ids, find one single related image (direction does not matter).
1138      * Ids are unique in the returned list, and do not correspond by index to the given list.
1139      */
1140     QList<qlonglong> getOneRelatedImageEach(const QList<qlonglong>& ids,
1141                                             DatabaseRelation::Type type = DatabaseRelation::UndefinedType)          const;
1142 
1143     /**
1144      * Retrieves all images that related to (retrieves objects) by given type.
1145      */
1146     QList<qlonglong> getRelatedImagesToByType(DatabaseRelation::Type type)                                          const;
1147 
1148     /**
1149      * Returns a list of all images where the Faces have either not been detected
1150      * yet, or is outdated because the file is identified as changed since
1151      * the generation of the fingerprint.
1152      * Return image ids or item URLs.
1153      */
1154     QStringList getDirtyOrMissingFaceImageUrls()                                                                    const;
1155 
1156     /**
1157      * Find items that are, with reasonable certainty, identical
1158      * to the file pointed to by id.
1159      * Criteria: Unique Hash, file size and album non-null.
1160      * The first variant will not return an ItemScanInfo for id.
1161      * The second allows to pass one id as source id for exclusion from the list.
1162      * If this is -1, no id is excluded.
1163      */
1164     QList<ItemScanInfo> getIdenticalFiles(qlonglong id)                                                             const;
1165     QList<ItemScanInfo> getIdenticalFiles(const QString& uniqueHash, qlonglong fileSize, qlonglong sourceId = -1)   const;
1166 
1167     /**
1168      * Returns a list of all images where tagId is assigned
1169      * Return item URLs.
1170      */
1171     QStringList getItemsURLsWithTag(int tagId)                                                                      const;
1172 
1173     // ----------- Items and their tags -----------
1174 
1175     /**
1176      * Add a tag for the item
1177      * @param imageID the ID of the item
1178      * @param tagID   the tagID for the tag
1179      * @param newTag  add to last assigned tag list
1180      */
1181     void addItemTag(qlonglong imageID, int tagID, bool newTag = false);
1182 
1183     /**
1184      * Add a tag for the item
1185      * @param albumID the albumID of the item
1186      * @param name    the name of the item
1187      * @param tagID   the tagID for the tag
1188      */
1189     void addItemTag(int albumID, const QString& name, int tagID);
1190 
1191     /**
1192      * Add each tag of a list of tags
1193      * to each member of a list of items.
1194      */
1195     void addTagsToItems(QList<qlonglong> imageIDs, QList<int> tagIDs);
1196 
1197     /**
1198      * Remove a specific tag for the item
1199      * @param imageID the ID of the item
1200      * @param tagID   the tagID for the tag
1201      */
1202     void removeItemTag(qlonglong imageID, int tagID);
1203 
1204     /**
1205      * Remove all tags for the item
1206      * @param imageID the ID of the item
1207      * @param currentTagIds the current tags ids assigned to the item
1208      */
1209     void removeItemAllTags(qlonglong imageID, const QList<int>& currentTagIds);
1210 
1211     /**
1212      * Remove each tag from a list of tags
1213      * from a each member of a list of items.
1214      */
1215     void removeTagsFromItems(QList<qlonglong> imageIDs, const QList<int>& tagIDs);
1216 
1217     /**
1218      * Get a list of names of all the tags for the item
1219      * @param imageID the ID of the item
1220      * @return the list of names of all tags for the item
1221      */
1222     QStringList getItemTagNames(qlonglong imageID)                                                                  const;
1223 
1224     /**
1225      * Get a list of IDs of all the tags for the item
1226      * @param imageID the ID of the item
1227      * @return the list of IDs of all tags for the item
1228      */
1229     QList<int> getItemTagIDs(qlonglong imageID)                                                                     const;
1230 
1231     /**
1232      * For a list of items, return the tag ids associated with the item.
1233      * Amounts to calling getItemTagIDs for each id in imageIds, but is optimized.
1234      */
1235     QVector<QList<int> > getItemsTagIDs(const QList<qlonglong>& imageIds)                                           const;
1236 
1237     /**
1238      * Get the properties for the given image/tag pair.
1239      * If the tagID is -1, returns the ImageTagProperties for all tagIds of the given image.
1240      */
1241     QList<ImageTagProperty> getImageTagProperties(qlonglong imageId, int tagId = -1)                                const;
1242 
1243     /**
1244      * Get all tagIds for which ImageTagProperties exist for the given image.
1245      */
1246     QList<int> getTagIdsWithProperties(qlonglong imageId)                                                           const;
1247 
1248     /**
1249      * Adds a tag property. Note that this never replaces existing entries.
1250      * It is also all right to add multiple entries for a tag with the same property.
1251      * To replace an existing entry, remove the entry before.
1252      */
1253     void addImageTagProperty(qlonglong imageId, int tagId, const QString& property, const QString& value);
1254     void addImageTagProperty(const ImageTagProperty& property);
1255 
1256     /**
1257      * Removes properties for the given tag. If the value is given, removes only
1258      * the entries with the given property/value pair. If only property is given,
1259      * removes all properties with the given name. If property is null,
1260      * removes all properties for the given tag.
1261      * If tagId is -1, removes all image tag properties for the given image.
1262      * Note: After the first parameter you give as a wildcard, the following will be ignored and taken as wildcard as well.
1263      */
1264     void removeImageTagProperties(qlonglong imageId, int tagId = -1, const QString& property = QString(),
1265                                   const QString& value = QString());
1266 
1267     /**
1268      * Given a set of items (identified by their IDs),
1269      * this will see if any of the items has a tag.
1270      * @param imageIDList a list of IDs of the items
1271      * @return true if at least one of the items has a tag
1272      */
1273     bool hasTags(const QList<qlonglong>& imageIDList)                                                               const;
1274 
1275     /**
1276      * Given a set of items (identified by their IDs),
1277      * get a list of ID of all common tags
1278      * @param imageIDList a list of IDs of the items
1279      * @return the list of common IDs of the given items
1280      */
1281     QList<int> getItemCommonTagIDs(const QList<qlonglong>& imageIDList)                                             const;
1282 
1283     /**
1284      * Returns a QMap<int,int> of tag id -> count of items
1285      * with the tag
1286      */
1287     QMap<int, int> getNumberOfImagesInTags()                                                                        const;
1288 
1289     /**
1290      * Returns a QMap<int,int> of tag id -> count of items
1291      * with the given tag property
1292      */
1293     QMap<int, int> getNumberOfImagesInTagProperties(const QString& property)                                        const;
1294 
1295     /**
1296      * Returns the count of images that have a tag property for the given tag.
1297      */
1298     int getNumberOfImagesInTagProperties(int tagId, const QString& property)                                        const;
1299 
1300     /**
1301      * Returns all image ids that are associated to the tag with the given property.
1302      */
1303     QList<qlonglong> getImagesWithImageTagProperty(int tagId, const QString& property)                              const;
1304 
1305     /**
1306      * Returns all image ids that are associated to the given property.
1307      */
1308     QList<qlonglong> getImagesWithProperty(const QString& property)                                                 const;
1309 
1310     /**
1311      * Returns a QMap<QString,int> of ItemInformation.format
1312      * -> count of items with that format.
1313      */
1314     QMap<QString, int> getFormatStatistics()                                                                        const;
1315     QMap<QString, int> getFormatStatistics(DatabaseItem::Category category)                                         const;
1316 
1317     /**
1318      * Return a list from a field from imageMetadata
1319      */
1320     QStringList getListFromImageMetadata(DatabaseFields::ImageMetadata field)                                       const;
1321 
1322     // ----------- Moving and Copying Items -----------
1323 
1324     /**
1325      * Move the attributes of an item to a different item. Useful when
1326      * say a file is renamed
1327      * @param  srcAlbumID the id of the source album
1328      * @param  dstAlbumID the id of the destination album
1329      * @param  srcName    the name of the source file
1330      * @param  dstName    the name of the destination file
1331      */
1332     void moveItem(int srcAlbumID, const QString& srcName,
1333                   int dstAlbumID, const QString& dstName);
1334 
1335     /**
1336      * Copy the attributes of an item to a different item. Useful when
1337      * say a file is copied.
1338      * The operation fails (returns -1) of src and dest are identical.
1339      * @param  srcAlbumID the id of the source album
1340      * @param  dstAlbumID the id of the destination album
1341      * @param  srcName    the name of the source file
1342      * @param  dstName    the name of the destination file
1343      * @return the id of item added or -1 if it fails
1344      */
1345     int copyItem(int srcAlbumID, const QString& srcName,
1346                  int dstAlbumID, const QString& dstName);
1347 
1348     /**
1349      * Copies all image-specific information, in all tables, from image srcId to destId.
1350      */
1351     void copyImageAttributes(qlonglong srcId, qlonglong destId);
1352 
1353     /**
1354      * Copies all entries in the ImageProperties table.
1355      */
1356     void copyImageProperties(qlonglong srcId, qlonglong dstId);
1357 
1358     /**
1359      * Copies all entries in the ImageTags table.
1360      */
1361     void copyImageTags(qlonglong srcId, qlonglong dstId);
1362 
1363     // ------------ Clear all Item Metadata -----------
1364 
1365     /**
1366      * Clear all metadata of an item
1367      * @param  imageID the ID of the item
1368      */
1369     void clearMetadataFromImage(qlonglong imageID);
1370 
1371     // ----------- Download history methods -----------
1372 
1373     /**
1374      * Search for the specified fingerprint in the download history table.
1375      * Returns the id of the entry, or -1 if not found.
1376      */
1377     int findInDownloadHistory(const QString& identifier, const QString& name,
1378                               qlonglong fileSize, const QDateTime& date)                                            const;
1379 
1380     /**
1381      * Add the specified fingerprint to the download history table.
1382      * Returns the id of the entry.
1383      */
1384     int addToDownloadHistory(const QString& identifier, const QString& name,
1385                              qlonglong fileSize, const QDateTime& date)                                             const;
1386 
1387     QList<QVariant> getImageIdsFromArea(qreal lat1, qreal lat2, qreal lng1, qreal lng2,
1388                                         int sortMode, const QString& sortBy)                                        const;
1389 
1390     // ----------- Database shrinking methods ----------
1391 
1392     /**
1393      * Returns true if the integrity of the database is preserved.
1394      */
1395     bool integrityCheck()                                                                                           const;
1396 
1397     /**
1398      * Shrinks the database.
1399      */
1400     void vacuum();
1401 
1402     // ----------- Static helper methods for constructing SQL queries -----------
1403 
1404     static QStringList imagesFieldList(DatabaseFields::Images fields);
1405     static QStringList imageInformationFieldList(DatabaseFields::ItemInformation fields);
1406     static QStringList videoMetadataFieldList(DatabaseFields::VideoMetadata fields);
1407     static QStringList imageMetadataFieldList(DatabaseFields::ImageMetadata fields);
1408     static QStringList imagePositionsFieldList(DatabaseFields::ItemPositions fields);
1409     static QStringList imageCommentsFieldList(DatabaseFields::ItemComments fields);
1410     static void addBoundValuePlaceholders(QString& query, int count);
1411 
1412 public:
1413 
1414     friend class Digikam::CoreDbAccess;
1415 
1416     /**
1417      * Constructor
1418      */
1419     explicit CoreDB(CoreDbBackend* const backend);
1420 
1421     /**
1422      * Destructor
1423      */
1424     ~CoreDB();
1425 
1426 protected:
1427 
1428     QList<qlonglong> getRelatedImages(qlonglong id, bool fromOrTo,
1429                                       DatabaseRelation::Type type, bool boolean)                                    const;
1430     QVector<QList<qlonglong> > getRelatedImages(QList<qlonglong> ids, bool fromOrTo,
1431                                                 DatabaseRelation::Type type, bool boolean)                          const;
1432 
1433 private:
1434 
1435     // Disable
1436     CoreDB(const CoreDB&)            = delete;
1437     CoreDB& operator=(const CoreDB&) = delete;
1438 
1439     void readSettings();
1440     void writeSettings();
1441 
1442 private:
1443 
1444     class Private;
1445     Private* const d;
1446 };
1447 
1448 } // namespace Digikam
1449 
1450 #endif // DIGIKAM_CORE_DB_H
1451