File indexing completed on 2024-12-01 03:40:34

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2017 Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef BATCHRENAMEJOB_H
0009 #define BATCHRENAMEJOB_H
0010 
0011 #include "job_base.h"
0012 #include "kiocore_export.h"
0013 
0014 namespace KIO
0015 {
0016 class BatchRenameJobPrivate;
0017 
0018 /**
0019  * @class KIO::BatchRenameJob batchrenamejob.h <KIO/BatchRenameJob>
0020  *
0021  * A KIO job that renames multiple files in one go.
0022  *
0023  * @since 5.42
0024  */
0025 class KIOCORE_EXPORT BatchRenameJob : public Job
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     ~BatchRenameJob() override;
0031 
0032 Q_SIGNALS:
0033     /**
0034      * Signals that a file was renamed.
0035      */
0036     void fileRenamed(const QUrl &oldUrl, const QUrl &newUrl);
0037 
0038 protected Q_SLOTS:
0039     void slotResult(KJob *job) override;
0040 
0041 protected:
0042     /// @internal
0043     KIOCORE_NO_EXPORT explicit BatchRenameJob(BatchRenameJobPrivate &dd);
0044 
0045 private:
0046     Q_DECLARE_PRIVATE(BatchRenameJob)
0047 };
0048 
0049 /**
0050  * Renames multiple files at once.
0051  *
0052  * The new filename is obtained by replacing the characters represented by
0053  * @p placeHolder by the index @p index.
0054  * E.g. Calling batchRename({"file:///Test.jpg"}, "Test #" 12, '#') renames
0055  * the file to "Test 12.jpg". A connected sequence of placeholders results in
0056  * leading zeros. batchRename({"file:///Test.jpg"}, "Test ####" 12, '#') renames
0057  * the file to "Test 0012.jpg". And if no placeholder is there then @p index is
0058  * appended to @p newName. Calling batchRename({"file:///Test.jpg"}, "NewTest" 12, '#')
0059  * renames the file to "NewTest12.jpg".
0060  *
0061  * @param src The list of items to rename.
0062  * @param newName The base name to use in all new filenames.
0063  * @param index The integer(incremented after renaming a file) to add to the base name.
0064  * @param placeHolder The character(s) which @p index will replace.
0065  *
0066  * @return A pointer to the job handling the operation.
0067  * @since 5.42
0068  */
0069 KIOCORE_EXPORT BatchRenameJob *batchRename(const QList<QUrl> &src, const QString &newName, int index, QChar placeHolder, JobFlags flags = DefaultFlags);
0070 
0071 }
0072 
0073 #endif