9
* Copyright (C) 2011 Urs Fleisch
11
* This file is part of Kid3.
13
* Kid3 is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2 of the License, or
16
* (at your option) any later version.
18
* Kid3 is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
32
#include "trackdata.h"
39
class DirRenamer : public QObject {
43
* @param parent parent object
45
explicit DirRenamer(QObject* parent = 0);
50
virtual ~DirRenamer();
53
* Set version of tags used to get rename information.
54
* @param tagVersion tag version
56
void setTagVersion(TrackData::TagVersion tagVersion) {
57
m_tagVersion = tagVersion;
61
* Set action to be performed.
62
* @param create true for create action
64
void setAction(bool create) { m_actionCreate = create; }
67
* Set format to generate directory names.
68
* @param format format
70
void setFormat(const QString& format) { m_format = format; }
73
* Generate new directory name according to current settings.
75
* @param taggedFile file to get information from
76
* @param olddir pointer to QString to place old directory name into,
79
* @return new directory name.
81
QString generateNewDirname(TaggedFile* taggedFile, QString* olddir);
84
* Clear the rename actions.
85
* This method has to be called before scheduling new actions.
90
* Schedule the actions necessary to rename the directory containing a file.
92
* @param taggedFile file in directory
94
void scheduleAction(TaggedFile* taggedFile);
97
* Perform the scheduled rename actions.
99
* @param errorMsg if not 0 and an error occurred, a message is appended here,
100
* otherwise it is not touched
102
void performActions(QString* errorMsg);
105
* Get description of actions to be performed.
106
* @return list of (action, [src,] dst) lists describing the actions to be
109
QList<QStringList> describeActions() const;
112
* Check if dialog was aborted.
113
* @return true if aborted.
115
bool getAbortFlag() const { return m_aborted; }
120
void setAbortFlag() { m_aborted = true; }
123
* Set directory name.
124
* This should be done before calling performActions(), so that the directory
125
* name is changed when the application directory is renamed.
127
* @param dirName directory name
129
void setDirName(const QString& dirName) { m_dirName = dirName; }
132
* Get directory name.
133
* The directory name should be initialized with the value of
134
* Kid3Application::getDirName() before performActions() is started and will
135
* be updated if it is renamed while performing the actions. If it is
136
* different from the application directory name after performActions(), the
137
* new directory should be opened.
141
QString getDirName() const { return m_dirName; }
145
* An action performed while renaming a directory.
160
* @param type type of action
161
* @param src source file or directory name
162
* @param dest destination file or directory name
164
RenameAction(Type type, const QString& src, const QString& dest) :
165
m_type(type), m_src(src), m_dest(dest) {}
170
RenameAction() : m_type(ReportError) {}
179
* @param rhs right hand side
180
* @return true if equal.
182
bool operator==(const RenameAction& rhs) const {
183
return m_type == rhs.m_type && m_src == rhs.m_src && m_dest == rhs.m_dest;
186
Type m_type; /**< type of action */
187
QString m_src; /**< source file or directory name */
188
QString m_dest; /**< destination file or directory name */
191
/** List of rename actions. */
192
typedef QList<RenameAction> RenameActionList;
195
* Create a directory if it does not exist.
197
* @param dir directory path
198
* @param errorMsg if not NULL and an error occurred, a message is appended here,
199
* otherwise it is not touched
201
* @return true if directory exists or was created successfully.
203
bool createDirectory(const QString& dir, QString* errorMsg) const;
206
* Rename a directory.
208
* @param olddir old directory name
209
* @param newdir new directory name
210
* @param errorMsg if not NULL and an error occurred, a message is
211
* appended here, otherwise it is not touched
213
* @return true if rename successful.
215
bool renameDirectory(
216
const QString& olddir, const QString& newdir, QString* errorMsg) const;
221
* @param oldfn old file name
222
* @param newfn new file name
223
* @param errorMsg if not NULL and an error occurred, a message is
224
* appended here, otherwise it is not touched
226
* @return true if rename successful or newfn already exists.
228
bool renameFile(const QString& oldfn, const QString& newfn,
229
QString* errorMsg) const;
232
* Add a rename action.
234
* @param type type of action
235
* @param src source file or directory name
236
* @param dest destination file or directory name
238
void addAction(RenameAction::Type type, const QString& src,
239
const QString& dest);
242
* Add a rename action.
244
* @param type type of action
245
* @param dest destination file or directory name
247
void addAction(RenameAction::Type type, const QString& dest);
250
* Check if there is already an action scheduled for this source.
252
* @return true if a rename action for the source exists.
254
bool actionHasSource(const QString& src) const;
257
* Check if there is already an action scheduled for this destination.
259
* @return true if a rename or create action for the destination exists.
261
bool actionHasDestination(const QString& dest) const;
264
* Replace directory name if there is already a rename action.
266
* @param src directory name, will be replaced if there is a rename action
268
void replaceIfAlreadyRenamed(QString& src) const;
270
RenameActionList m_actions;
272
TrackData::TagVersion m_tagVersion;
278
#endif // DIRRENAMER_H