| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2017 Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef BATCHRENAMEJOB_H |
| 9 | #define BATCHRENAMEJOB_H |
| 10 | |
| 11 | #include "job_base.h" |
| 12 | #include "kiocore_export.h" |
| 13 | |
| 14 | namespace KIO |
| 15 | { |
| 16 | class BatchRenameJobPrivate; |
| 17 | |
| 18 | /*! |
| 19 | * \class KIO::BatchRenameJob |
| 20 | * \inheaderfile KIO/BatchRenameJob |
| 21 | * \inmodule KIOCore |
| 22 | * |
| 23 | * \brief A KIO job that renames multiple files in one go. |
| 24 | * |
| 25 | * \since 5.42 |
| 26 | */ |
| 27 | class KIOCORE_EXPORT BatchRenameJob : public Job |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | public: |
| 32 | ~BatchRenameJob() override; |
| 33 | |
| 34 | Q_SIGNALS: |
| 35 | /*! |
| 36 | * Signals that a file was renamed. |
| 37 | */ |
| 38 | void fileRenamed(const QUrl &oldUrl, const QUrl &newUrl); |
| 39 | |
| 40 | protected Q_SLOTS: |
| 41 | /*! |
| 42 | * \reimp |
| 43 | */ |
| 44 | void slotResult(KJob *job) override; |
| 45 | |
| 46 | protected: |
| 47 | /*! |
| 48 | * \internal |
| 49 | */ |
| 50 | KIOCORE_NO_EXPORT explicit BatchRenameJob(BatchRenameJobPrivate &dd); |
| 51 | |
| 52 | private: |
| 53 | Q_DECLARE_PRIVATE(BatchRenameJob) |
| 54 | }; |
| 55 | |
| 56 | /*! |
| 57 | * \relates KIO::BatchRenameJob |
| 58 | * |
| 59 | * Renames multiple files at once. |
| 60 | * |
| 61 | * The new filename is obtained by replacing the characters represented by |
| 62 | * \a placeHolder by the index \a index. |
| 63 | * |
| 64 | * E.g. Calling batchRename({"file:///Test.jpg"}, "Test #" 12, '#') renames |
| 65 | * the file to "Test 12.jpg". A connected sequence of placeholders results in |
| 66 | * leading zeros. batchRename({"file:///Test.jpg"}, "Test ####" 12, '#') renames |
| 67 | * the file to "Test 0012.jpg". And if no placeholder is there then \a index is |
| 68 | * appended to \a newName. Calling batchRename({"file:///Test.jpg"}, "NewTest" 12, '#') |
| 69 | * renames the file to "NewTest12.jpg". |
| 70 | * |
| 71 | * \a srcList The list of items to rename. |
| 72 | * |
| 73 | * \a newName The base name to use in all new filenames. |
| 74 | * |
| 75 | * \a startIndex The integer(incremented after renaming a file) to add to the base name. |
| 76 | * |
| 77 | * \a placeHolder The character(s) which \a index will replace. |
| 78 | * |
| 79 | * Returns a pointer to the job handling the operation. |
| 80 | * \since 5.42 |
| 81 | */ |
| 82 | // TODO KF7 remove, replaces by batchRenameWithFunction |
| 83 | KIOCORE_EXPORT BatchRenameJob * |
| 84 | batchRename(const QList<QUrl> &srcList, const QString &newName, int startIndex, QChar placeHolder, JobFlags flags = DefaultFlags); |
| 85 | |
| 86 | using renameFunctionType = std::function<QString(QStringView currentFileNameWithoutExtension)>; |
| 87 | /*! |
| 88 | * \relates KIO::BatchRenameJob |
| 89 | * |
| 90 | * Renames multiple files at once. The new names are generated by the passed-in function \p renameFunction. |
| 91 | * |
| 92 | * \a srcList The list of items to rename. |
| 93 | * |
| 94 | * \a renameFunction A function used to find the new name of each input files |
| 95 | * |
| 96 | * Returns a pointer to the job handling the operation. |
| 97 | * |
| 98 | * \since 6.16 |
| 99 | */ |
| 100 | KIOCORE_EXPORT BatchRenameJob *batchRenameWithFunction(const QList<QUrl> &srcList, const renameFunctionType renameFunction, KIO::JobFlags flags = DefaultFlags); |
| 101 | } |
| 102 | |
| 103 | #endif |
| 104 | |