1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2007-12-01
7  * Description : Core database recording changes.
8  *
9  * Copyright (C) 2007-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_CORE_DB_CHANGESETS_H
25 #define DIGIKAM_CORE_DB_CHANGESETS_H
26 
27 #include "digikam_config.h"
28 
29 // Qt includes
30 
31 #include <QList>
32 #include <QMetaType>
33 
34 #ifdef HAVE_DBUS
35 #   include <QDBusArgument>
36 #   include "dbenginedbusutils.h"
37 #endif
38 
39 // Local includes
40 
41 #include "digikam_export.h"
42 #include "coredbfields.h"
43 
44 namespace Digikam
45 {
46 
47 class DIGIKAM_DATABASE_EXPORT ImageChangeset
48 {
49 public:
50 
51     /**
52      * An ImageChangeset covers adding or changing any properties of an image.
53      * It is described by a list of affected image ids, and a set of affected database fields.
54      * There is no guarantee that information in the database has actually been changed.
55      */
56     ImageChangeset();
57     ImageChangeset(const QList<qlonglong>& ids, const DatabaseFields::Set& changes);
58     ImageChangeset(qlonglong id, const DatabaseFields::Set& changes);
59 
60     QList<qlonglong> ids()                                      const;
61     bool containsImage(qlonglong id)                            const;
62     DatabaseFields::Set changes()                               const;
63 
64 #ifdef HAVE_DBUS
65 
66     ImageChangeset& operator<<(const QDBusArgument& argument);
67     const ImageChangeset& operator>>(QDBusArgument& argument)   const;
68 
69 #endif // HAVE_DBUS
70 
71 private:
72 
73     QList<qlonglong>    m_ids;
74     DatabaseFields::Set m_changes;
75 };
76 
77 // ----------------------------------------------------------------------------
78 
79 class DIGIKAM_DATABASE_EXPORT ImageTagChangeset
80 {
81 public:
82 
83     /**
84      * An ImageTagChangeset covers adding and removing the association of a tag with an image.
85      * It is described by a list of affected image ids, a list of affected tags,
86      * and an operation.
87      * There is no guarantee that information in the database has actually been changed.
88      */
89     enum Operation
90     {
91         Unknown,
92         Added,
93         Moved,
94         Removed,
95         RemovedAll,
96         PropertiesChanged
97     };
98 
99 public:
100 
101     ImageTagChangeset();
102     ImageTagChangeset(const QList<qlonglong>& ids, const QList<int>& tags, Operation operation);
103     ImageTagChangeset(qlonglong id, const QList<int>& tags, Operation operation);
104     ImageTagChangeset(qlonglong id, int tag, Operation operation);
105 
106     /**
107      * Combines two ImageTagChangesets.
108      * The operations shall not differ between the two sets;
109      * the operation is set to Unknown if it differs.
110      * This is especially not suitable for RemovedAll changesets.
111      */
112     ImageTagChangeset& operator<<(const ImageTagChangeset& other);
113 
114 #ifdef HAVE_DBUS
115 
116     ImageTagChangeset& operator<<(const QDBusArgument& argument);
117     const ImageTagChangeset& operator>>(QDBusArgument& argument) const;
118 
119 #endif // HAVE_DBUS
120 
121     QList<qlonglong> ids()           const;
122     bool containsImage(qlonglong id) const;
123     QList<int> tags()                const;
124     bool containsTag(int id)         const;
125     Operation operation()            const;
126 
tagsWereAdded()127     bool tagsWereAdded() const
128     {
129         return (operation() == Added);
130     }
131 
tagsWereRemoved()132     bool tagsWereRemoved() const
133     {
134         return ((operation() == Removed) || (operation() == RemovedAll));
135     }
136 
propertiesWereChanged()137     bool propertiesWereChanged() const
138     {
139         return (operation() == PropertiesChanged);
140     }
141 
142 private:
143 
144     QList<qlonglong>    m_ids;
145     QList<int>          m_tags;
146     Operation           m_operation;
147 };
148 
149 // ----------------------------------------------------------------------------
150 
151 class DIGIKAM_DATABASE_EXPORT CollectionImageChangeset
152 {
153 public:
154 
155     enum Operation
156     {
157         Unknown,
158 
159         /**
160          * "Added" indicates that images have been added to albums.
161          */
162         Added,
163 
164         /**
165          * "Removed" indicates that an image has been removed from the given album,
166          * and has possibly set a status of Removed and a null Album (though this can
167          * already have changed to valid values), but the image-specific tables have not been removed.
168          */
169         Removed,
170 
171         /**
172          * "RemovedAll" indicates that for all entries in the specified album, the "Removed" operation
173          * has been carried out. This is equivalent to a "Removed" changesets with all image ids in the
174          * list, but for RemovedAll, the list may not be explicitly given (may be empty).
175          */
176         RemovedAll,
177 
178         /**
179          * "Deleted" indicates that the image-specific tables have been removed from the database.
180          * While "Removed" means all data is still there, though possibly not accessible from an album,
181          * this means all data has been irreversibly deleted.
182          */
183         Deleted,
184 
185         /**
186          * Special combination: Images which has the "Removed" status have now been "Delete"d.
187          * A changeset with Removed or RemovedAll is guaranteed to have been sent anytime before.
188          * Image ids nor albums ids may or may be not available in any combination.
189          */
190         RemovedDeleted,
191 
192         /**
193          * Images have been moved. This is extra information; a Removed and then an Added changeset
194          * are guaranteed to be sent subsequently.
195          * Album is the source album.
196          */
197         Moved,
198 
199         /**
200          * Images have been copied. This is extra information; an Added changeset
201          * is guaranteed to be sent subsequently.
202          * Album is the source album.
203          */
204         Copied
205     };
206 
207 public:
208 
209     /**
210      * An CollectionImageChangeset covers adding and removing an image to/from the collection.
211      * It is described by a list of affected image ids, a list of affected albums,
212      * and an operation.
213      * Special Case "RemovedAll":
214      * If all images have been removed from an album, operation is RemovedAll,
215      * the album list contains the (now empty) albums, ids() is empty,
216      * but containsImage() always returns true.
217      * Special Case "RemovedDeleted":
218      * Images with the "Removed" status are now irreversibly deleted.
219      * ids() and/or albums() may be empty (this means information is not available).
220      */
221     CollectionImageChangeset();
222     CollectionImageChangeset(const QList<qlonglong>& ids, const QList<int>& albums, Operation operation);
223     CollectionImageChangeset(const QList<qlonglong>& ids, int album, Operation operation);
224     CollectionImageChangeset(qlonglong id, int album, Operation operation);
225 
226     /**
227      * Combines two CollectionImageChangesets.
228      * The operations shall not differ between the two sets;
229      * the operation is set to Unknown if it differs.
230      * This is especially not suitable for RemovedAll changesets.
231      */
232     CollectionImageChangeset& operator<<(const CollectionImageChangeset& other);
233 
234 #ifdef HAVE_DBUS
235 
236     CollectionImageChangeset& operator<<(const QDBusArgument& argument);
237     const CollectionImageChangeset& operator>>(QDBusArgument& argument) const;
238 
239 #endif // HAVE_DBUS
240 
241     /**
242      * Specification of this changeset.
243      * All special cases where the returned list may be empty are noted above.
244      * The lists are valid unless such a case is explicitly mentioned.
245      */
246     QList<qlonglong> ids()           const;
247     bool containsImage(qlonglong id) const;
248     QList<int> albums()              const;
249     bool containsAlbum(int id)       const;
250     Operation operation()            const;
251 
252 private:
253 
254     QList<qlonglong>    m_ids;
255     QList<int>          m_albums;
256     Operation           m_operation;
257 };
258 
259 // ----------------------------------------------------------------------------
260 
261 class DIGIKAM_DATABASE_EXPORT AlbumChangeset
262 {
263 public:
264 
265     enum Operation
266     {
267         Unknown,
268         Added,
269         Deleted,
270         Renamed,
271         PropertiesChanged
272     };
273 
274 public:
275 
276     AlbumChangeset();
277     AlbumChangeset(int albumId, Operation operation);
278 
279     int albumId()                                             const;
280     Operation operation()                                     const;
281 
282 #ifdef HAVE_DBUS
283 
284     AlbumChangeset& operator<<(const QDBusArgument& argument);
285     const AlbumChangeset& operator>>(QDBusArgument& argument) const;
286 
287 #endif // HAVE_DBUS
288 
289 private:
290 
291     int       m_id;
292     Operation m_operation;
293 };
294 
295 // ----------------------------------------------------------------------------
296 
297 class DIGIKAM_DATABASE_EXPORT TagChangeset
298 {
299 public:
300 
301     enum Operation
302     {
303         Unknown,
304         Added,
305         Moved,
306         Deleted,
307         Renamed,
308         Reparented,
309         IconChanged,
310         PropertiesChanged /// ImageTagProperties Table
311     };
312 
313 public:
314 
315     TagChangeset();
316     TagChangeset(int tagId, Operation operation);
317 
318     int tagId()                                             const;
319     Operation operation()                                   const;
320 
321 #ifdef HAVE_DBUS
322 
323     TagChangeset& operator<<(const QDBusArgument& argument);
324     const TagChangeset& operator>>(QDBusArgument& argument) const;
325 
326 #endif // HAVE_DBUS
327 
328 private:
329 
330     int       m_id;
331     Operation m_operation;
332 };
333 
334 // ----------------------------------------------------------------------------
335 
336 class DIGIKAM_DATABASE_EXPORT AlbumRootChangeset
337 {
338 public:
339 
340     enum Operation
341     {
342         Unknown,
343         Added,
344         Deleted,
345         PropertiesChanged
346     };
347 
348 public:
349 
350     AlbumRootChangeset();
351     AlbumRootChangeset(int albumRootId, Operation operation);
352 
353     int albumRootId()                                             const;
354     Operation operation()                                         const;
355 
356 #ifdef HAVE_DBUS
357 
358     AlbumRootChangeset& operator<<(const QDBusArgument& argument);
359     const AlbumRootChangeset& operator>>(QDBusArgument& argument) const;
360 
361 #endif // HAVE_DBUS
362 
363 private:
364 
365     int       m_id;
366     Operation m_operation;
367 };
368 
369 // ----------------------------------------------------------------------------
370 
371 class DIGIKAM_DATABASE_EXPORT SearchChangeset
372 {
373 public:
374 
375     enum Operation
376     {
377         Unknown,
378         Added,
379         Deleted,
380         Changed
381     };
382 
383 public:
384 
385     SearchChangeset();
386     SearchChangeset(int searchId, Operation operation);
387 
388     int searchId()                                             const;
389     Operation operation()                                      const;
390 
391 #ifdef HAVE_DBUS
392 
393     SearchChangeset& operator<<(const QDBusArgument& argument);
394     const SearchChangeset& operator>>(QDBusArgument& argument) const;
395 
396 #endif // HAVE_DBUS
397 
398 private:
399 
400     int       m_id;
401     Operation m_operation;
402 };
403 
404 } // namespace Digikam
405 
406 #ifdef HAVE_DBUS
407 
408 // custom macro from our dbusutilities.h
409 DECLARE_METATYPE_FOR_DBUS(Digikam::ImageChangeset)
410 DECLARE_METATYPE_FOR_DBUS(Digikam::ImageTagChangeset)
411 DECLARE_METATYPE_FOR_DBUS(Digikam::CollectionImageChangeset)
412 DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumChangeset)
413 DECLARE_METATYPE_FOR_DBUS(Digikam::TagChangeset)
414 DECLARE_METATYPE_FOR_DBUS(Digikam::SearchChangeset)
415 DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumRootChangeset)
416 DECLARE_METATYPE_FOR_DBUS(Digikam::DatabaseFields::Set)
417 
418 #endif // HAVE_DBUS
419 
420 #endif // DIGIKAM_CORE_DB_CHANGESETS_H
421