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
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2007-12-01
 * Description : Core database recording changes.
 *
 * SPDX-FileCopyrightText: 2007-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#pragma once

#include "digikam_config.h"

// Qt includes

#include <QList>
#include <QMetaType>

#ifdef HAVE_DBUS
#   include <QDBusArgument>
#   include "dbenginedbusutils.h"
#endif

// Local includes

#include "digikam_export.h"
#include "coredbfields.h"

namespace Digikam
{

class DIGIKAM_DATABASE_EXPORT ImageChangeset
{
public:

    /**
     * An ImageChangeset covers adding or changing any properties of an image.
     * It is described by a list of affected image ids, and a set of affected database fields.
     * There is no guarantee that information in the database has actually been changed.
     */
    ImageChangeset() = default;
    ImageChangeset(const QList<qlonglong>& ids, const DatabaseFields::Set& changes);
    ImageChangeset(qlonglong id, const DatabaseFields::Set& changes);

    QList<qlonglong> ids()                                      const;<--- Function 'ids()' should return member 'm_ids' by const reference.
    bool containsImage(qlonglong id)                            const;
    DatabaseFields::Set changes()                               const;

#ifdef HAVE_DBUS

    ImageChangeset& operator<<(const QDBusArgument& argument);
    const ImageChangeset& operator>>(QDBusArgument& argument)   const;

#endif // HAVE_DBUS

private:

    QList<qlonglong>    m_ids;
    DatabaseFields::Set m_changes;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT ImageTagChangeset
{
public:

    /**
     * An ImageTagChangeset covers adding and removing the association of a tag with an image.
     * It is described by a list of affected image ids, a list of affected tags,
     * and an operation.
     * There is no guarantee that information in the database has actually been changed.
     */
    enum Operation
    {
        Unknown,
        Added,
        Moved,
        Removed,
        RemovedAll,
        PropertiesChanged
    };

public:

    ImageTagChangeset() = default;
    ImageTagChangeset(const QList<qlonglong>& ids, const QList<int>& tags, Operation operation);
    ImageTagChangeset(qlonglong id, const QList<int>& tags, Operation operation);
    ImageTagChangeset(qlonglong id, int tag, Operation operation);

    /**
     * Combines two ImageTagChangesets.
     * The operations shall not differ between the two sets;
     * the operation is set to Unknown if it differs.
     * This is especially not suitable for RemovedAll changesets.
     */
    ImageTagChangeset& operator<<(const ImageTagChangeset& other);

#ifdef HAVE_DBUS

    ImageTagChangeset& operator<<(const QDBusArgument& argument);
    const ImageTagChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

    QList<qlonglong> ids()           const;<--- Function 'ids()' should return member 'm_ids' by const reference.
    bool containsImage(qlonglong id) const;
    QList<int> tags()                const;<--- Function 'tags()' should return member 'm_tags' by const reference.
    bool containsTag(int id)         const;
    Operation operation()            const;

    bool tagsWereAdded() const
    {
        return (operation() == Added);
    }

    bool tagsWereRemoved() const
    {
        return ((operation() == Removed) || (operation() == RemovedAll));
    }

    bool propertiesWereChanged() const
    {
        return (operation() == PropertiesChanged);
    }

private:

    QList<qlonglong>    m_ids;
    QList<int>          m_tags;
    Operation           m_operation = Unknown;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT CollectionImageChangeset
{
public:

    enum Operation
    {
        Unknown,

        /**
         * "Added" indicates that images have been added to albums.
         */
        Added,

        /**
         * "Removed" indicates that an image has been removed from the given album,
         * and has possibly set a status of Removed and a null Album (though this can
         * already have changed to valid values), but the image-specific tables have not been removed.
         */
        Removed,

        /**
         * "RemovedAll" indicates that for all entries in the specified album, the "Removed" operation
         * has been carried out. This is equivalent to a "Removed" changesets with all image ids in the
         * list, but for RemovedAll, the list may not be explicitly given (may be empty).
         */
        RemovedAll,

        /**
         * "Deleted" indicates that the image-specific tables have been removed from the database.
         * While "Removed" means all data is still there, though possibly not accessible from an album,
         * this means all data has been irreversibly deleted.
         */
        Deleted,

        /**
         * Special combination: Images which has the "Removed" status have now been "Delete"d.
         * A changeset with Removed or RemovedAll is guaranteed to have been sent anytime before.
         * Image ids nor albums ids may or may be not available in any combination.
         */
        RemovedDeleted,

        /**
         * Images have been moved. This is extra information; a Removed and then an Added changeset
         * are guaranteed to be sent subsequently.
         * Album is the source album.
         */
        Moved,

        /**
         * Images have been copied. This is extra information; an Added changeset
         * is guaranteed to be sent subsequently.
         * Album is the source album.
         */
        Copied
    };

public:

    /**
     * An CollectionImageChangeset covers adding and removing an image to/from the collection.
     * It is described by a list of affected image ids, a list of affected albums,
     * and an operation.
     * Special Case "RemovedAll":
     * If all images have been removed from an album, operation is RemovedAll,
     * the album list contains the (now empty) albums, ids() is empty,
     * but containsImage() always returns true.
     * Special Case "RemovedDeleted":
     * Images with the "Removed" status are now irreversibly deleted.
     * ids() and/or albums() may be empty (this means information is not available).
     */
    CollectionImageChangeset() = default;
    CollectionImageChangeset(const QList<qlonglong>& ids, const QList<int>& albums, Operation operation);
    CollectionImageChangeset(const QList<qlonglong>& ids, int album, Operation operation);
    CollectionImageChangeset(qlonglong id, int album, Operation operation);

    /**
     * Combines two CollectionImageChangesets.
     * The operations shall not differ between the two sets;
     * the operation is set to Unknown if it differs.
     * This is especially not suitable for RemovedAll changesets.
     */
    CollectionImageChangeset& operator<<(const CollectionImageChangeset& other);

#ifdef HAVE_DBUS

    CollectionImageChangeset& operator<<(const QDBusArgument& argument);
    const CollectionImageChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

    /**
     * Specification of this changeset.
     * All special cases where the returned list may be empty are noted above.
     * The lists are valid unless such a case is explicitly mentioned.
     */
    QList<qlonglong> ids()           const;<--- Function 'ids()' should return member 'm_ids' by const reference.
    bool containsImage(qlonglong id) const;
    QList<int> albums()              const;<--- Function 'albums()' should return member 'm_albums' by const reference.
    bool containsAlbum(int id)       const;
    Operation operation()            const;

private:

    QList<qlonglong>    m_ids;
    QList<int>          m_albums;
    Operation           m_operation = Unknown;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT AlbumChangeset
{
public:

    enum Operation
    {
        Unknown,
        Added,
        Deleted,
        Renamed,
        PropertiesChanged
    };

public:

    AlbumChangeset() = default;
    AlbumChangeset(int albumId, Operation operation);

    int albumId()                                             const;
    Operation operation()                                     const;

#ifdef HAVE_DBUS

    AlbumChangeset& operator<<(const QDBusArgument& argument);
    const AlbumChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

private:

    int       m_id          = -1;
    Operation m_operation   = Unknown;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT TagChangeset
{
public:

    enum Operation
    {
        Unknown,
        Added,
        Moved,
        Deleted,
        Renamed,
        Reparented,
        IconChanged,
        PropertiesChanged /// ImageTagProperties Table
    };

public:

    TagChangeset() = default;
    TagChangeset(int tagId, Operation operation);

    int tagId()                                             const;
    Operation operation()                                   const;

#ifdef HAVE_DBUS

    TagChangeset& operator<<(const QDBusArgument& argument);
    const TagChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

private:

    int       m_id          = -1;
    Operation m_operation   = Unknown;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT AlbumRootChangeset
{
public:

    enum Operation
    {
        Unknown,
        Added,
        Deleted,
        PropertiesChanged
    };

public:

    AlbumRootChangeset() = default;
    AlbumRootChangeset(int albumRootId, Operation operation);

    int albumRootId()                                             const;
    Operation operation()                                         const;

#ifdef HAVE_DBUS

    AlbumRootChangeset& operator<<(const QDBusArgument& argument);
    const AlbumRootChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

private:

    int       m_id          = -1;
    Operation m_operation   = Unknown;
};

// ----------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT SearchChangeset
{
public:

    enum Operation
    {
        Unknown,
        Added,
        Deleted,
        Changed
    };

public:

    SearchChangeset() = default;
    SearchChangeset(int searchId, Operation operation);

    int searchId()                                             const;
    Operation operation()                                      const;

#ifdef HAVE_DBUS

    SearchChangeset& operator<<(const QDBusArgument& argument);
    const SearchChangeset& operator>>(QDBusArgument& argument) const;

#endif // HAVE_DBUS

private:

    int       m_id          = -1;
    Operation m_operation   = Unknown;
};

} // namespace Digikam

#ifdef HAVE_DBUS

// custom macro from our dbusutilities.h
DECLARE_METATYPE_FOR_DBUS(Digikam::ImageChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::ImageTagChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::CollectionImageChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::TagChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::SearchChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumRootChangeset)
DECLARE_METATYPE_FOR_DBUS(Digikam::DatabaseFields::Set)

#endif // HAVE_DBUS