File indexing completed on 2025-01-05 03:56:11
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-07-27 0007 * Description : Special digiKam trash implementation 0008 * 0009 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_DTRASH_H 0016 #define DIGIKAM_DTRASH_H 0017 0018 // Qt includes 0019 0020 #include <QObject> 0021 #include <QFileInfo> 0022 0023 // Local includes 0024 0025 #include "dtrashiteminfo.h" 0026 0027 namespace Digikam 0028 { 0029 0030 class DTrash 0031 { 0032 0033 public: 0034 0035 const static QString TRASH_FOLDER; 0036 const static QString FILES_FOLDER; 0037 const static QString INFO_FOLDER; 0038 const static QString INFO_FILE_EXTENSION; 0039 const static QString PATH_JSON_KEY; 0040 const static QString DELETIONTIMESTAMP_JSON_KEY; 0041 const static QString IMAGEID_JSON_KEY; 0042 0043 public: 0044 0045 /** 0046 * @brief Deletes image to the trash of a particular collection 0047 * @param imagePath: path to image 0048 * @return true if the image was deleted 0049 */ 0050 static bool deleteImage(const QString& imagePath, const QDateTime& deleteTime); 0051 0052 /** 0053 * @brief Deletes a whole folder from the collection 0054 * @param dirToDelete: path to folder 0055 * @return true if folder was deleted 0056 */ 0057 static bool deleteDirRecursivley(const QString& dirToDelete, const QDateTime& deleteTime); 0058 0059 /** 0060 * @brief Extracts the data from json file and gives it to DTrashItemInfo 0061 * @param collPath: path to collection 0062 * @param baseName: name of the file inside the trash 0063 * @param itemInfo: item to extract data to it 0064 */ 0065 static void extractJsonForItem(const QString& collPath, const QString& baseName, DTrashItemInfo& itemInfo); 0066 0067 private: 0068 0069 /** 0070 * @brief Ensures that the trash caching folder exists before moving items to trash 0071 * @param collectionPath: the full path to the collection to prepare the trash for 0072 * @return true if the trash is prepared successfully 0073 */ 0074 static bool prepareCollectionTrash(const QString& collectionPath); 0075 0076 /** 0077 * @brief Creates a json file containing the image path and deletion timestamp 0078 * and return the baseName for this json file 0079 * @param imageId: the image id for the file 0080 * @param imagePath: path of image to create json file for 0081 * @param deleteTime: delete time from the image 0082 * @param collectionPath: path of collection that the image belongs to 0083 * 0084 * @example createJsonRecordForFile("home/user/Pics", "/home/user/Pics/cats/cute/katy.jpg") 0085 * returns => "katy" 0086 */ 0087 static QString createJsonRecordForFile(qlonglong imageId, 0088 const QString& imagePath, 0089 const QDateTime& deleteTime, 0090 const QString& collectionPath); 0091 0092 /** 0093 * @brief Checks for duplicates of files names inside the trash and if there is 0094 * a duplication it does a simple versioning recursively 0095 * @param collectionPath: path of collection that the image belongs to 0096 * @param baseName: the baseName of the image 0097 * @param version: a digit to append to the image baseName 0098 * 0099 * @example getAvialableJsonFilePathInTrash("home/user/Pics", "katy", 0) 0100 * return => "home/user/Pics/.trash/info/katy.dtrashInfo" 0101 * if this name was available, if not 0102 * returns => "home/user/Pics/.trash/info/katy{version}.dtrashInfo" 0103 * where {version} is a integer number that is available in trash 0104 */ 0105 static QString getAvialableJsonFilePathInTrash(const QString& collectionPath, 0106 const QString& baseName, int version = 0); 0107 0108 private: 0109 0110 DTrash(); 0111 }; 0112 0113 } // namespace Digikam 0114 0115 #endif // DIGIKAM_DTRASH_H