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 batchrenamejob.h <KIO/BatchRenameJob> |
20 | * |
21 | * A KIO job that renames multiple files in one go. |
22 | * |
23 | * @since 5.42 |
24 | */ |
25 | class KIOCORE_EXPORT BatchRenameJob : public Job |
26 | { |
27 | Q_OBJECT |
28 | |
29 | public: |
30 | ~BatchRenameJob() override; |
31 | |
32 | Q_SIGNALS: |
33 | /** |
34 | * Signals that a file was renamed. |
35 | */ |
36 | void fileRenamed(const QUrl &oldUrl, const QUrl &newUrl); |
37 | |
38 | protected Q_SLOTS: |
39 | void slotResult(KJob *job) override; |
40 | |
41 | protected: |
42 | /// @internal |
43 | KIOCORE_NO_EXPORT explicit BatchRenameJob(BatchRenameJobPrivate &dd); |
44 | |
45 | private: |
46 | Q_DECLARE_PRIVATE(BatchRenameJob) |
47 | }; |
48 | |
49 | /** |
50 | * Renames multiple files at once. |
51 | * |
52 | * The new filename is obtained by replacing the characters represented by |
53 | * @p placeHolder by the index @p index. |
54 | * E.g. Calling batchRename({"file:///Test.jpg"}, "Test #" 12, '#') renames |
55 | * the file to "Test 12.jpg". A connected sequence of placeholders results in |
56 | * leading zeros. batchRename({"file:///Test.jpg"}, "Test ####" 12, '#') renames |
57 | * the file to "Test 0012.jpg". And if no placeholder is there then @p index is |
58 | * appended to @p newName. Calling batchRename({"file:///Test.jpg"}, "NewTest" 12, '#') |
59 | * renames the file to "NewTest12.jpg". |
60 | * |
61 | * @param src The list of items to rename. |
62 | * @param newName The base name to use in all new filenames. |
63 | * @param index The integer(incremented after renaming a file) to add to the base name. |
64 | * @param placeHolder The character(s) which @p index will replace. |
65 | * |
66 | * @return A pointer to the job handling the operation. |
67 | * @since 5.42 |
68 | */ |
69 | KIOCORE_EXPORT BatchRenameJob *batchRename(const QList<QUrl> &src, const QString &newName, int index, QChar placeHolder, JobFlags flags = DefaultFlags); |
70 | |
71 | } |
72 | |
73 | #endif |
74 | |