File indexing completed on 2025-04-27 03:58:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-12-10
0007  * Description : misc file operation methods
0008  *
0009  * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DFILE_OPERATIONS_H
0016 #define DIGIKAM_DFILE_OPERATIONS_H
0017 
0018 // Qt includes
0019 
0020 #include <QUrl>
0021 #include <QString>
0022 #include <QDateTime>
0023 #include <QStringList>
0024 
0025 // Local includes
0026 
0027 #include "digikam_export.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class DIGIKAM_EXPORT DFileOperations
0033 {
0034 
0035 public:
0036 
0037     enum SidecarAction
0038     {
0039         Rename = 0,
0040         Copy
0041     };
0042 
0043 public:
0044 
0045     /**
0046      * This method rename a local file 'orgPath' to 'destPath' with all ACL properties
0047      * restoration taken from 'source' file.
0048      * Return true if operation is completed.
0049      */
0050     static bool localFileRename(const QString& source,
0051                                 const QString& orgPath,
0052                                 const QString& destPath,
0053                                 bool ignoreSettings = false);
0054 
0055     /**
0056      * Open file urls to default application relevant of
0057      * file type-mimes desktop configuration.
0058      */
0059     static void openFilesWithDefaultApplication(const QList<QUrl>& urls);
0060 
0061     /**
0062      * Get unique file url if file exist by appending a counter suffix
0063      * or return original url.
0064      */
0065     static QUrl getUniqueFileUrl(const QUrl& orgUrl, bool* const newurl = nullptr);
0066 
0067     /**
0068      * Get unique folder url if folder exist by appending a counter suffix
0069      * or return original url.
0070      */
0071     static QUrl getUniqueFolderUrl(const QUrl& orgUrl);
0072 
0073     /**
0074      * Open system file manager and select the item.
0075      */
0076     static void openInFileManager(const QList<QUrl>& urls);
0077 
0078     /**
0079      * Copy recursively a directory contents to another one.
0080      */
0081     static bool copyFolderRecursively(const QString& srcPath,
0082                                       const QString& dstPath,
0083                                       const QString& itemId = QString(),
0084                                       bool* const cancel = nullptr,
0085                                       bool useDstPath = false);
0086 
0087     /**
0088      * Copy a list of files to another place.
0089      */
0090     static bool copyFiles(const QStringList& srcPaths,
0091                           const QString& dstPath);
0092 
0093     /**
0094      * Rename or move file and keep the source file modification time.
0095      */
0096     static bool renameFile(const QString& srcFile,
0097                            const QString& dstFile);
0098 
0099     /**
0100      * Copy file and keep the source file modification time.
0101      */
0102     static bool copyFile(const QString& srcFile,
0103                          const QString& dstFile,
0104                          const bool* const cancel = nullptr);
0105 
0106     /**
0107      * Copy file modification time from source to destination file.
0108      */
0109     static bool copyModificationTime(const QString& srcFile,
0110                                      const QString& dstFile);
0111     /**
0112      * Set file modification time from QDateTime.
0113      * Keep access time from source file.
0114      */
0115     static bool setModificationTime(const QString& srcFile,
0116                                     const QDateTime& dateTime);
0117     /**
0118      * Returns the path to a program under Windows by searching
0119      * in the Windows registry.
0120      * If the path is empty, QStandardPaths::findExecutable()
0121      * is used as under Linux and macOS.
0122      */
0123     static QString findExecutable(const QString& name);
0124 
0125     /**
0126      * Rename/move or copy all possible sidecar files
0127      * and keep the source file modification time.
0128      */
0129     static bool sidecarFiles(const QString& srcFile,
0130                              const QString& dstFile,
0131                              SidecarAction action);
0132 };
0133 
0134 } // namespace Digikam
0135 
0136 #endif // DIGIKAM_DFILE_OPERATIONS_H