"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/batchrenamer.h" between
krename-4.0.9.tar.gz and krename-4.90.90.tar.gz

About: KRename is a batch file-renamer (KDE).

batchrenamer.h  (krename-4.0.9):batchrenamer.h  (krename-4.90.90)
skipping to change at line 21 skipping to change at line 21
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
***************************************************************************/ ***************************************************************************/
#ifndef BATCHRENAMER_H #ifndef BATCHRENAMER_H
#define BATCHRENAMER_H #define BATCHRENAMER_H
#include <QDateTime>
#include <QList> #include <QList>
#include <QObject> #include <QObject>
#include "krenamefile.h" #include "krenamefile.h"
class QFile; class QFile;
class QProgressDialog; class QProgressDialog;
class QString; class QString;
class QTextStream; class QTextStream;
skipping to change at line 59 skipping to change at line 58
/** An enum to set the renaming mode of KRename /** An enum to set the renaming mode of KRename
*/ */
enum ERenameMode { enum ERenameMode {
eRenameMode_Rename, ///< All files are renamed in place eRenameMode_Rename, ///< All files are renamed in place
eRenameMode_Move, ///< All files are moved to a new directory and renamed eRenameMode_Move, ///< All files are moved to a new directory and renamed
eRenameMode_Copy, ///< Only copies of the files are renamed eRenameMode_Copy, ///< Only copies of the files are renamed
eRenameMode_Link ///< Symbolic links are created and renamed eRenameMode_Link ///< Symbolic links are created and renamed
}; };
class QObject; class QObject;
class QListView;
class ProgressDialog; class ProgressDialog;
/** This is the core class for renaming. /** This is the core class for renaming.
* *
* It transforms the filenames according to * It transforms the filenames according to
* the users settings using custom functions * the users settings using custom functions
* and external plugins. * and external plugins.
* Also the actual renaming, copying or moving * Also the actual renaming, copying or moving
* of the files is done by this class * of the files is done by this class
* *
* @author Dominik Seichter * @author Dominik Seichter
*/ */
class BatchRenamer : public QObject { class BatchRenamer : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
BatchRenamer(); BatchRenamer();
~BatchRenamer(); ~BatchRenamer();
/** Sets the list of files /** Sets the list of files
* which contains all filenames which should be transformed. * which contains all filenames which should be transformed.
* *
* The renamed filenames are stored in this list, too,. * The renamed filenames are stored in this list, too,.
* *
* @param list a list of KRenameFile objects * @param list a list of KRenameFile objects
*/ */
inline void setFiles( KRenameFile::List* list ); inline void setFiles(KRenameFile::List *list);
/** Get access to the list of files used for renaming. /** Get access to the list of files used for renaming.
* @returns the list of files or NULL if none was set. * @returns the list of files or NULL if none was set.
*/ */
inline const KRenameFile::List* files() const; inline const KRenameFile::List *files() const;
/** /**
* @returns the current renaming mode * @returns the current renaming mode
*/ */
inline ERenameMode renameMode() const; inline ERenameMode renameMode() const;
/** /**
* @returns the current start index for counters * @returns the current start index for counters
*/ */
inline int numberStartIndex() const; inline int numberStartIndex() const;
/** /**
* @returns the stepping for counters * @returns the stepping for counters
*/ */
inline int numberStepping() const; inline int numberStepping() const;
/** /**
* @returns if counters are reset on new directories * @returns if counters are reset on new directories
*/ */
inline int numberReset() const; inline int numberReset() const;
/** /**
* @returns the list of numbers that are skipped during renaming * @returns the list of numbers that are skipped during renaming
*/ */
inline QList<int> numberSkipList() const; inline QList<int> numberSkipList() const;
/** Does the actuall renaming, /** Does the actuall renaming,
* transforming all source filenames in the file list * transforming all source filenames in the file list
* to the new destination filenames. * to the new destination filenames.
* *
* No actuall renaming is done, only the new filenames * No actuall renaming is done, only the new filenames
* are calculated. * are calculated.
*/ */
void processFilenames(); void processFilenames();
/** Process all files /** Process all files
* *
* processFilenames has to be called before * processFilenames has to be called before
* *
* All files will be renamed according to the users settings. * All files will be renamed according to the users settings.
* *
* Output will be reported through a progress dialog * Output will be reported through a progress dialog
* *
* @param p use this dialog to report progress to the user * @param p use this dialog to report progress to the user
*/ */
void processFiles( ProgressDialog* p ); void processFiles(ProgressDialog *p);
/** undo all files /** undo all files
* *
* processFiles has to be called before * processFiles has to be called before
* *
* A previous renaming operation will be undone. * A previous renaming operation will be undone.
* *
* Output will be reported through a progress dialog * Output will be reported through a progress dialog
* *
* @param p use this dialog to report progress to the user * @param p use this dialog to report progress to the user
*/ */
void undoFiles( ProgressDialog* p ); void undoFiles(ProgressDialog *p);
/** Build the destination url from a KRenameFile /** Build the destination url from a KRenameFile
* *
* @param file a KRenameFile * @param file a KRenameFile
* @returns a valid KUrl * @returns a valid QUrl
*/ */
const KUrl buildDestinationUrl( const KRenameFile & file ) const; const QUrl buildDestinationUrl(const KRenameFile &file) const;
inline void setUndoScript( const QString & t ) { m_undoScript = t; } inline void setUndoScript(const QString &t)
inline void setUndo( bool b ) { undo = b; } {
m_undoScript = t;
inline void setReplaceList( const QList<TReplaceItem> & r ) { m_replace }
= r; } inline void setUndo(bool b)
inline const QList<TReplaceItem> & replaceList() const { return m_replac {
e; } undo = b;
}
inline void setMode( int m) { m_mode = m; }
inline int mode() const { return m_mode; } inline void setReplaceList(const QList<TReplaceItem> &r)
{
QString findToken( const QString & oldname, QString token, int i ); m_replace = r;
QString findPartStrings( QString oldname, QString token ); }
static QString findDirName( QString token, QString path ); inline const QList<TReplaceItem> &replaceList() const
{
/** return m_replace;
* Replace the token [dirsep] with a slash "/". }
* This token is useful to create directories from within regular expres
sions. inline void setMode(int m)
*/ {
static QString findDirSep( const QString & token, const QString & path ) m_mode = m;
; }
inline int mode() const
static QString & doEscape( QString & text ); {
static QString & unEscape( QString & text ); return m_mode;
static void escape( QString & text, const QString & token, const QString }
& sequence );
QString findToken(const QString &oldname, QString token, int i);
/** Capitalize a string. QString findPartStrings(QString oldname, QString token);
* static QString findDirName(QString token, QString path);
* Used to implement the * token.
* /**
* @param a text string * Replace the token [dirsep] with a slash "/".
* @return a capitalized version of this string (every first letter is * This token is useful to create directories from within regular expression
a capital letter now) s.
*/ */
QString capitalize( const QString & text ) const; static QString findDirSep(const QString &token, const QString &path);
/** Handle the [length] tokens static QString &doEscape(QString &text);
* static QString &unEscape(QString &text);
* @param token a token found in square brackets static void escape(QString &text, const QString &token, const QString &seque
* @param name the filename of the current file nce);
*
* @return QString::null if no length token was found or the a new stri /** Capitalize a string.
ng *
*/ * Used to implement the * token.
QString findLength( const QString & token, const QString & name ); *
* @param a text string
/** Handle the [trimmed] token * @return a capitalized version of this string (every first letter is a ca
* pital letter now)
* @param token a token found in square brackets */
* @param name the filename of the current file QString capitalize(const QString &text) const;
* @param index index of the current file
* /** Handle the [length] tokens
* @return QString::null if no length token was found or the a new stri *
ng * @param token a token found in square brackets
*/ * @param name the filename of the current file
QString findTrimmed( const QString & token, const QString & name, int in *
dex ); * @return QString::null if no length token was found or the a new string
*/
QString processString( QString text, const QString & originalName, int i QString findLength(const QString &token, const QString &name);
, bool doFindReplace = true );
QString processBrackets( QString text, int* length, const QString & oldn /** Handle the [trimmed] token
ame, int index ); *
QString processNumber( int length, const QString & appendix ); * @param token a token found in square brackets
QString processToken( QString token, QString oldname, int i ); * @param name the filename of the current file
* @param index index of the current file
public slots: *
* @return QString::null if no length token was found or the a new st
/** Sets the current mode of renaming. ring
* KRename can rename files, move them while */
* renaming to another directory, rename copies QString findTrimmed(const QString &token, const QString &name, int index);
* or create renamed sym-links.
* QString processString(QString text, const QString &originalName, int i, bool
* This mode specifies what should be done with the files. doFindReplace = true);
* QString processBrackets(QString text, int *length, const QString &oldname, i
* @param mode the renaming mode. nt index);
*/ QString processNumber(int length, const QString &appendix);
inline void setRenameMode( ERenameMode mode ); QString processToken(QString token, QString oldname, int i);
/** Sets the template for the filename that is used public Q_SLOTS:
* to transform the filename to its final representation.
* /** Sets the current mode of renaming.
* @param t the new template * KRename can rename files, move them while
*/ * renaming to another directory, rename copies
inline void setFilenameTemplate( const QString & t ); * or create renamed sym-links.
*
/** Sets the template for the filename that is used * This mode specifies what should be done with the files.
* to transform the filename to its final representation. *
* * @param mode the renaming mode.
* @param t the new template */
*/ inline void setRenameMode(ERenameMode mode);
inline void setExtensionTemplate( const QString & t );
/** Sets the template for the filename that is used
/** Set the start index for the basic counters * to transform the filename to its final representation.
* which do not specify an own start index in their *
* appendiy (e.g. ###{7}, means 7 is the start index * @param t the new template
* */
* @param i start index inline void setFilenameTemplate(const QString &t);
*/
inline void setNumberStartIndex( int i ) { m_index = i; } /** Sets the template for the filename that is used
* to transform the filename to its final representation.
/** Set the stepping for the basic counters *
* which do not specify an own stepping in their * @param t the new template
* appendiy (e.g. ###{1,2}, means 2 is the stepping */
* inline void setExtensionTemplate(const QString &t);
* @param s stepping
*/ /** Set the start index for the basic counters
inline void setNumberStepping( int s ) { m_step = s; } * which do not specify an own start index in their
* appendiy (e.g. ###{7}, means 7 is the start index
/** Sets wether all counters should be reset for new *
* directories * @param i start index
* */
* @param r if true counters will be reset inline void setNumberStartIndex(int i)
*/ {
inline void setNumberReset( bool r ) { m_reset = r; } m_index = i;
}
/** Sets the list of numbers that are skipped by counters
* /** Set the stepping for the basic counters
* @param s a list of numbers that is skipped * which do not specify an own stepping in their
*/ * appendiy (e.g. ###{1,2}, means 2 is the stepping
inline void setNumberSkipList( const QList<int> & s ) { m_skip = s; } *
* @param s stepping
/** Sets if existing files maybe overwritten during renaming */
* inline void setNumberStepping(int s)
* @param overwrite if true existing files will be overwritten {
*/ m_step = s;
inline void setOverwriteExistingFiles( bool overwrite ) { m_overwrite = }
overwrite; }
/** Sets whether all counters should be reset for new
/** Sets the destination url (a directory) for copy, move and link opera * directories
tions *
* * @param r if true counters will be reset
* @param url destination directory */
*/ inline void setNumberReset(bool r)
inline void setDestinationDir( const KUrl & url ) { m_destination = url; {
} m_reset = r;
}
private:
/** Do find and replace on the final resulting filename. /** Sets the list of numbers that are skipped by counters
* *
* \param text the new final filename with all other changes applied. * @param s a list of numbers that is skipped
* */
* \returns the new filename with all find and replace being done. inline void setNumberSkipList(const QList<int> &s)
* {
* \see m_replace m_skip = s;
*/ }
QString findReplace( const QString & text, const QString & origFilename,
int index ); /** Sets if existing files maybe overwritten during renaming
*
/** * @param overwrite if true existing files will be overwritten
* Replace one string (which might be a regular expression) in the final */
filename inline void setOverwriteExistingFiles(bool overwrite)
* with another string and return a new filename. {
* m_overwrite = overwrite;
* \param text the new final filename with all other changes applied. }
* \param find the string or regular expression to find
* \param replace replace a matched string with this value /** Sets the destination url (a directory) for copy, move and link operation
* \param reg if true treat find as regular expression s
* \param doProcessTokens process tokens in replaced results *
* \param originalName original filename for replacing tokens * @param url destination directory
* \param index current index */
* inline void setDestinationDir(const QUrl &url)
* \returns the new filename with find and replace being done. {
*/ m_destination = url;
QString doReplace( const QString & text, const QString & find, const QSt }
ring & replace,
bool reg, bool doProcessTokens, const QString & origF private:
ilename, int index ); /** Do find and replace on the final resulting filename.
*
private: * \param text the new final filename with all other changes applied.
/** Execute all plugins of a certain type *
* * \returns the new filename with all find and replace being done.
* @param index the current index *
* @param filenameOrPath the current filename or path * \see m_replace
* @param type the type of the plugins to run */
* @param errorCount the number of errors will be written to this value QString findReplace(const QString &text, const QString &origFilename, int in
* @param p dialog for error reporting (maybe NULL) dex);
*
* @returns either a new filename or an error message (depends on plugi /**
n type) * Replace one string (which might be a regular expression) in the final fil
*/ ename
QString executePlugin( int index, const QString & filenameOrPath, int ty * with another string and return a new filename.
pe, int & errorCount, ProgressDialog* p ); *
* \param text the new final filename with all other changes applied.
void work( ProgressDialog* p ); * \param find the string or regular expression to find
void writeUndoScript( QTextStream* t ); * \param replace replace a matched string with this value
* \param reg if true treat find as regular expression
/** * \param doProcessTokens process tokens in replaced results
* Parse a new filename and create missing subdirectories. * \param originalName original filename for replacing tokens
* * \param index current index
* This will look for '/' and create all not existing directories *
* * \returns the new filename with find and replace being done.
* @param file to check for not existing directories */
* @param p ProgressDialog for error reporting QString doReplace(const QString &text, const QString &find, const QString &r
*/ eplace,
void createMissingSubDirs( const KRenameFile & file, ProgressDialog* p bool reg, bool doProcessTokens, const QString &origFilenam
); e, int index);
/** resets all counters to there start value if the directory name a private:
t @p i /** Execute all plugins of a certain type
* in m_files changes. *
* The caller has to check m_reset before calling this function. * @param index the current index
*/ * @param filenameOrPath the current filename or path
void findCounterReset( int i ); * @param type the type of the plugins to run
* @param errorCount the number of errors will be written to this value
QString text; // template * @param p dialog for error reporting (maybe NULL)
QString extext; // Extension template *
QString m_undoScript; // Filename of undoscript * @returns either a new filename or an error message (depends on plugin ty
bool undo; // create an undo script pe)
bool m_reset; // reset counter on new directories */
int m_mode; // renaming mode QString executePlugin(int index, const QString &filenameOrPath, int type, in
QList<int> m_skip; // Numbers to skip t &errorCount, ProgressDialog *p);
// a is used in find number and void work(ProgressDialog *p);
// required for skipping. void writeUndoScript(QTextStream *t);
int m_counter_index;
int m_index; // index for numbers /**
int m_step; // step for numbers * Parse a new filename and create missing subdirectories.
*
QList<tCounterValues> m_counters; * This will look for '/' and create all not existing directories
*
private: * @param file to check for not existing directories
KRenameFile::List* m_files; ///< The list of files to rename and t * @param p ProgressDialog for error reporting
he resulting renamed filenames */
ERenameMode m_renameMode; ///< The rename mode specifies if file void createMissingSubDirs(const KRenameFile &file, ProgressDialog *dialog);
s are renamed, copied or moved (or linked)
bool m_overwrite; ///< Overwrite existing files /** resets all counters to there start value if the directory name at @p i
KUrl m_destination; ///< Destination directory for copy, m * in m_files changes.
ove and link * The caller has to check m_reset before calling this function.
*/
QList<TReplaceItem> m_replace; ///< List of strings for find and repl void findCounterReset(int i);
ace
QString text; // template
protected: QString extext; // Extension template
QFile* f; QString m_undoScript; // Filename of undoscript
QTime t; bool undo; // create an undo script
QProgressDialog* progress; bool m_reset; // reset counter on new directories
int m_mode; // renaming mode
QList<int> m_skip; // Numbers to skip
// a is used in find number and
// required for skipping.
int m_counter_index;
int m_index; // index for numbers
int m_step; // step for numbers
QList<tCounterValues> m_counters;
private:
KRenameFile::List *m_files; ///< The list of files to rename and the r
esulting renamed filenames
ERenameMode m_renameMode; ///< The rename mode specifies if files ar
e renamed, copied or moved (or linked)
bool m_overwrite; ///< Overwrite existing files
QUrl m_destination; ///< Destination directory for copy, move
and link
QList<TReplaceItem> m_replace; ///< List of strings for find and replace
protected:
QFile *f;
QTime t;
QProgressDialog *progress;
}; };
void BatchRenamer::setFiles( KRenameFile::List* list ) void BatchRenamer::setFiles(KRenameFile::List *list)
{ {
m_files = list; m_files = list;
} }
const KRenameFile::List* BatchRenamer::files() const const KRenameFile::List *BatchRenamer::files() const
{ {
return m_files; return m_files;
} }
void BatchRenamer::setRenameMode( ERenameMode mode ) void BatchRenamer::setRenameMode(ERenameMode mode)
{ {
m_renameMode = mode; m_renameMode = mode;
} }
ERenameMode BatchRenamer::renameMode() const ERenameMode BatchRenamer::renameMode() const
{ {
return m_renameMode; return m_renameMode;
} }
void BatchRenamer::setFilenameTemplate( const QString & t ) void BatchRenamer::setFilenameTemplate(const QString &t)
{ {
text = t; text = t;
} }
void BatchRenamer::setExtensionTemplate( const QString & t ) void BatchRenamer::setExtensionTemplate(const QString &t)
{ {
extext = t; extext = t;
} }
int BatchRenamer::numberStartIndex() const int BatchRenamer::numberStartIndex() const
{ {
return m_index; return m_index;
} }
int BatchRenamer::numberStepping() const int BatchRenamer::numberStepping() const
 End of changes. 9 change blocks. 
329 lines changed or deleted 354 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)