File indexing completed on 2025-01-19 03:53:29
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-12-01 0007 * Description : Core database recording changes. 0008 * 0009 * SPDX-FileCopyrightText: 2007-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_CORE_DB_CHANGESETS_H 0016 #define DIGIKAM_CORE_DB_CHANGESETS_H 0017 0018 #include "digikam_config.h" 0019 0020 // Qt includes 0021 0022 #include <QList> 0023 #include <QMetaType> 0024 0025 #ifdef HAVE_DBUS 0026 # include <QDBusArgument> 0027 # include "dbenginedbusutils.h" 0028 #endif 0029 0030 // Local includes 0031 0032 #include "digikam_export.h" 0033 #include "coredbfields.h" 0034 0035 namespace Digikam 0036 { 0037 0038 class DIGIKAM_DATABASE_EXPORT ImageChangeset 0039 { 0040 public: 0041 0042 /** 0043 * An ImageChangeset covers adding or changing any properties of an image. 0044 * It is described by a list of affected image ids, and a set of affected database fields. 0045 * There is no guarantee that information in the database has actually been changed. 0046 */ 0047 ImageChangeset(); 0048 ImageChangeset(const QList<qlonglong>& ids, const DatabaseFields::Set& changes); 0049 ImageChangeset(qlonglong id, const DatabaseFields::Set& changes); 0050 0051 QList<qlonglong> ids() const; 0052 bool containsImage(qlonglong id) const; 0053 DatabaseFields::Set changes() const; 0054 0055 #ifdef HAVE_DBUS 0056 0057 ImageChangeset& operator<<(const QDBusArgument& argument); 0058 const ImageChangeset& operator>>(QDBusArgument& argument) const; 0059 0060 #endif // HAVE_DBUS 0061 0062 private: 0063 0064 QList<qlonglong> m_ids; 0065 DatabaseFields::Set m_changes; 0066 }; 0067 0068 // ---------------------------------------------------------------------------- 0069 0070 class DIGIKAM_DATABASE_EXPORT ImageTagChangeset 0071 { 0072 public: 0073 0074 /** 0075 * An ImageTagChangeset covers adding and removing the association of a tag with an image. 0076 * It is described by a list of affected image ids, a list of affected tags, 0077 * and an operation. 0078 * There is no guarantee that information in the database has actually been changed. 0079 */ 0080 enum Operation 0081 { 0082 Unknown, 0083 Added, 0084 Moved, 0085 Removed, 0086 RemovedAll, 0087 PropertiesChanged 0088 }; 0089 0090 public: 0091 0092 ImageTagChangeset(); 0093 ImageTagChangeset(const QList<qlonglong>& ids, const QList<int>& tags, Operation operation); 0094 ImageTagChangeset(qlonglong id, const QList<int>& tags, Operation operation); 0095 ImageTagChangeset(qlonglong id, int tag, Operation operation); 0096 0097 /** 0098 * Combines two ImageTagChangesets. 0099 * The operations shall not differ between the two sets; 0100 * the operation is set to Unknown if it differs. 0101 * This is especially not suitable for RemovedAll changesets. 0102 */ 0103 ImageTagChangeset& operator<<(const ImageTagChangeset& other); 0104 0105 #ifdef HAVE_DBUS 0106 0107 ImageTagChangeset& operator<<(const QDBusArgument& argument); 0108 const ImageTagChangeset& operator>>(QDBusArgument& argument) const; 0109 0110 #endif // HAVE_DBUS 0111 0112 QList<qlonglong> ids() const; 0113 bool containsImage(qlonglong id) const; 0114 QList<int> tags() const; 0115 bool containsTag(int id) const; 0116 Operation operation() const; 0117 0118 bool tagsWereAdded() const 0119 { 0120 return (operation() == Added); 0121 } 0122 0123 bool tagsWereRemoved() const 0124 { 0125 return ((operation() == Removed) || (operation() == RemovedAll)); 0126 } 0127 0128 bool propertiesWereChanged() const 0129 { 0130 return (operation() == PropertiesChanged); 0131 } 0132 0133 private: 0134 0135 QList<qlonglong> m_ids; 0136 QList<int> m_tags; 0137 Operation m_operation; 0138 }; 0139 0140 // ---------------------------------------------------------------------------- 0141 0142 class DIGIKAM_DATABASE_EXPORT CollectionImageChangeset 0143 { 0144 public: 0145 0146 enum Operation 0147 { 0148 Unknown, 0149 0150 /** 0151 * "Added" indicates that images have been added to albums. 0152 */ 0153 Added, 0154 0155 /** 0156 * "Removed" indicates that an image has been removed from the given album, 0157 * and has possibly set a status of Removed and a null Album (though this can 0158 * already have changed to valid values), but the image-specific tables have not been removed. 0159 */ 0160 Removed, 0161 0162 /** 0163 * "RemovedAll" indicates that for all entries in the specified album, the "Removed" operation 0164 * has been carried out. This is equivalent to a "Removed" changesets with all image ids in the 0165 * list, but for RemovedAll, the list may not be explicitly given (may be empty). 0166 */ 0167 RemovedAll, 0168 0169 /** 0170 * "Deleted" indicates that the image-specific tables have been removed from the database. 0171 * While "Removed" means all data is still there, though possibly not accessible from an album, 0172 * this means all data has been irreversibly deleted. 0173 */ 0174 Deleted, 0175 0176 /** 0177 * Special combination: Images which has the "Removed" status have now been "Delete"d. 0178 * A changeset with Removed or RemovedAll is guaranteed to have been sent anytime before. 0179 * Image ids nor albums ids may or may be not available in any combination. 0180 */ 0181 RemovedDeleted, 0182 0183 /** 0184 * Images have been moved. This is extra information; a Removed and then an Added changeset 0185 * are guaranteed to be sent subsequently. 0186 * Album is the source album. 0187 */ 0188 Moved, 0189 0190 /** 0191 * Images have been copied. This is extra information; an Added changeset 0192 * is guaranteed to be sent subsequently. 0193 * Album is the source album. 0194 */ 0195 Copied 0196 }; 0197 0198 public: 0199 0200 /** 0201 * An CollectionImageChangeset covers adding and removing an image to/from the collection. 0202 * It is described by a list of affected image ids, a list of affected albums, 0203 * and an operation. 0204 * Special Case "RemovedAll": 0205 * If all images have been removed from an album, operation is RemovedAll, 0206 * the album list contains the (now empty) albums, ids() is empty, 0207 * but containsImage() always returns true. 0208 * Special Case "RemovedDeleted": 0209 * Images with the "Removed" status are now irreversibly deleted. 0210 * ids() and/or albums() may be empty (this means information is not available). 0211 */ 0212 CollectionImageChangeset(); 0213 CollectionImageChangeset(const QList<qlonglong>& ids, const QList<int>& albums, Operation operation); 0214 CollectionImageChangeset(const QList<qlonglong>& ids, int album, Operation operation); 0215 CollectionImageChangeset(qlonglong id, int album, Operation operation); 0216 0217 /** 0218 * Combines two CollectionImageChangesets. 0219 * The operations shall not differ between the two sets; 0220 * the operation is set to Unknown if it differs. 0221 * This is especially not suitable for RemovedAll changesets. 0222 */ 0223 CollectionImageChangeset& operator<<(const CollectionImageChangeset& other); 0224 0225 #ifdef HAVE_DBUS 0226 0227 CollectionImageChangeset& operator<<(const QDBusArgument& argument); 0228 const CollectionImageChangeset& operator>>(QDBusArgument& argument) const; 0229 0230 #endif // HAVE_DBUS 0231 0232 /** 0233 * Specification of this changeset. 0234 * All special cases where the returned list may be empty are noted above. 0235 * The lists are valid unless such a case is explicitly mentioned. 0236 */ 0237 QList<qlonglong> ids() const; 0238 bool containsImage(qlonglong id) const; 0239 QList<int> albums() const; 0240 bool containsAlbum(int id) const; 0241 Operation operation() const; 0242 0243 private: 0244 0245 QList<qlonglong> m_ids; 0246 QList<int> m_albums; 0247 Operation m_operation; 0248 }; 0249 0250 // ---------------------------------------------------------------------------- 0251 0252 class DIGIKAM_DATABASE_EXPORT AlbumChangeset 0253 { 0254 public: 0255 0256 enum Operation 0257 { 0258 Unknown, 0259 Added, 0260 Deleted, 0261 Renamed, 0262 PropertiesChanged 0263 }; 0264 0265 public: 0266 0267 AlbumChangeset(); 0268 AlbumChangeset(int albumId, Operation operation); 0269 0270 int albumId() const; 0271 Operation operation() const; 0272 0273 #ifdef HAVE_DBUS 0274 0275 AlbumChangeset& operator<<(const QDBusArgument& argument); 0276 const AlbumChangeset& operator>>(QDBusArgument& argument) const; 0277 0278 #endif // HAVE_DBUS 0279 0280 private: 0281 0282 int m_id; 0283 Operation m_operation; 0284 }; 0285 0286 // ---------------------------------------------------------------------------- 0287 0288 class DIGIKAM_DATABASE_EXPORT TagChangeset 0289 { 0290 public: 0291 0292 enum Operation 0293 { 0294 Unknown, 0295 Added, 0296 Moved, 0297 Deleted, 0298 Renamed, 0299 Reparented, 0300 IconChanged, 0301 PropertiesChanged /// ImageTagProperties Table 0302 }; 0303 0304 public: 0305 0306 TagChangeset(); 0307 TagChangeset(int tagId, Operation operation); 0308 0309 int tagId() const; 0310 Operation operation() const; 0311 0312 #ifdef HAVE_DBUS 0313 0314 TagChangeset& operator<<(const QDBusArgument& argument); 0315 const TagChangeset& operator>>(QDBusArgument& argument) const; 0316 0317 #endif // HAVE_DBUS 0318 0319 private: 0320 0321 int m_id; 0322 Operation m_operation; 0323 }; 0324 0325 // ---------------------------------------------------------------------------- 0326 0327 class DIGIKAM_DATABASE_EXPORT AlbumRootChangeset 0328 { 0329 public: 0330 0331 enum Operation 0332 { 0333 Unknown, 0334 Added, 0335 Deleted, 0336 PropertiesChanged 0337 }; 0338 0339 public: 0340 0341 AlbumRootChangeset(); 0342 AlbumRootChangeset(int albumRootId, Operation operation); 0343 0344 int albumRootId() const; 0345 Operation operation() const; 0346 0347 #ifdef HAVE_DBUS 0348 0349 AlbumRootChangeset& operator<<(const QDBusArgument& argument); 0350 const AlbumRootChangeset& operator>>(QDBusArgument& argument) const; 0351 0352 #endif // HAVE_DBUS 0353 0354 private: 0355 0356 int m_id; 0357 Operation m_operation; 0358 }; 0359 0360 // ---------------------------------------------------------------------------- 0361 0362 class DIGIKAM_DATABASE_EXPORT SearchChangeset 0363 { 0364 public: 0365 0366 enum Operation 0367 { 0368 Unknown, 0369 Added, 0370 Deleted, 0371 Changed 0372 }; 0373 0374 public: 0375 0376 SearchChangeset(); 0377 SearchChangeset(int searchId, Operation operation); 0378 0379 int searchId() const; 0380 Operation operation() const; 0381 0382 #ifdef HAVE_DBUS 0383 0384 SearchChangeset& operator<<(const QDBusArgument& argument); 0385 const SearchChangeset& operator>>(QDBusArgument& argument) const; 0386 0387 #endif // HAVE_DBUS 0388 0389 private: 0390 0391 int m_id; 0392 Operation m_operation; 0393 }; 0394 0395 } // namespace Digikam 0396 0397 #ifdef HAVE_DBUS 0398 0399 // custom macro from our dbusutilities.h 0400 DECLARE_METATYPE_FOR_DBUS(Digikam::ImageChangeset) 0401 DECLARE_METATYPE_FOR_DBUS(Digikam::ImageTagChangeset) 0402 DECLARE_METATYPE_FOR_DBUS(Digikam::CollectionImageChangeset) 0403 DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumChangeset) 0404 DECLARE_METATYPE_FOR_DBUS(Digikam::TagChangeset) 0405 DECLARE_METATYPE_FOR_DBUS(Digikam::SearchChangeset) 0406 DECLARE_METATYPE_FOR_DBUS(Digikam::AlbumRootChangeset) 0407 DECLARE_METATYPE_FOR_DBUS(Digikam::DatabaseFields::Set) 0408 0409 #endif // HAVE_DBUS 0410 0411 #endif // DIGIKAM_CORE_DB_CHANGESETS_H