@ -33,8 +33,8 @@
# include <sys/stat.h>
# include <sys/stat.h>
// QT includes
// QT includes
# include < qdir.h>
# include < t qdir.h>
# include < qregexp.h>
# include < t qregexp.h>
// KDE includes
// KDE includes
# include <kapplication.h>
# include <kapplication.h>
@ -62,7 +62,7 @@ BatchRenamer::~BatchRenamer()
{
{
}
}
void BatchRenamer : : processFiles ( ProgressDialog * p , QObject* object )
void BatchRenamer : : processFiles ( ProgressDialog * p , T QObject* object )
{
{
delete object ;
delete object ;
t . start ( ) ;
t . start ( ) ;
@ -76,7 +76,7 @@ void BatchRenamer::processFiles( ProgressDialog* p, QObject* object )
if ( m_mode = = RENAME ) { // final Path = source Path
if ( m_mode = = RENAME ) { // final Path = source Path
m_files [ i ] . dst . directory = m_files [ i ] . src . directory ;
m_files [ i ] . dst . directory = m_files [ i ] . src . directory ;
m_files [ i ] . dst . url = m_files [ i ] . src . url ;
m_files [ i ] . dst . url = m_files [ i ] . src . url ;
m_files [ i ] . dst . url . setFileName ( QString: : null ) ;
m_files [ i ] . dst . url . setFileName ( TQString( ) ) ;
} else {
} else {
m_files [ i ] . dst . directory = dirname . path ( ) ;
m_files [ i ] . dst . directory = dirname . path ( ) ;
m_files [ i ] . dst . url = dirname ;
m_files [ i ] . dst . url = dirname ;
@ -118,19 +118,19 @@ void BatchRenamer::processFiles( ProgressDialog* p, QObject* object )
if ( m_files [ c ] . src . directory . left ( m_files [ i ] . src . name . length ( ) + 1 )
if ( m_files [ c ] . src . directory . left ( m_files [ i ] . src . name . length ( ) + 1 )
= = ( m_files [ i ] . src . name + " / " ) ) {
= = ( m_files [ i ] . src . name + " / " ) ) {
m_files [ c ] . src . directory . replace( 0 , m_files [ i ] . src . name . length ( ) , m_files [ i ] . dst . name ) ;
m_files [ c ] . src . directory . tq replace( 0 , m_files [ i ] . src . name . length ( ) , m_files [ i ] . dst . name ) ;
m_files [ c ] . src . url . setPath ( BatchRenamer : : buildFilename ( & m_files [ c ] . src , true ) ) ;
m_files [ c ] . src . url . setPath ( BatchRenamer : : buildFilename ( & m_files [ c ] . src , true ) ) ;
}
}
}
}
}
}
}
}
p - > print ( QString( i18n ( " Filenames Processed after %1 seconds. " ) ) . arg( t . elapsed ( ) / 1000 ) ) ;
p - > print ( T QString( i18n ( " Filenames Processed after %1 seconds. " ) ) . tq arg( t . elapsed ( ) / 1000 ) ) ;
work ( p ) ;
work ( p ) ;
}
}
QString BatchRenamer : : processString ( QString text , QString oldname , int i )
T QString BatchRenamer : : processString ( T QString text , T QString oldname , int i )
{
{
/*
/*
* Come on ! Grep for this text and help me !
* Come on ! Grep for this text and help me !
@ -140,7 +140,7 @@ QString BatchRenamer::processString( QString text, QString oldname, int i )
*
*
* Krename will have problems with files
* Krename will have problems with files
* which contain one of the following
* which contain one of the following
* unicode characters : 60000 , 60001 , 60002
* tq unicode characters : 60000 , 60001 , 60002
* 60003 , 60004 , 60005 , 60006.
* 60003 , 60004 , 60005 , 60006.
*
*
* This is not a good solution , if you have a
* This is not a good solution , if you have a
@ -180,10 +180,10 @@ QString BatchRenamer::processString( QString text, QString oldname, int i )
return text ;
return text ;
}
}
QString BatchRenamer : : parsePlugins ( int i , const QString& text , int type )
T QString BatchRenamer : : parsePlugins ( int i , const T QString& text , int type )
{
{
QPtrListIterator< PluginLoader : : PluginLibrary > it ( plug - > libs ) ;
T QPtrListIterator< PluginLoader : : PluginLibrary > it ( plug - > libs ) ;
QString ret = text ;
T QString ret = text ;
if ( type = = TYPE_FINAL_FILE )
if ( type = = TYPE_FINAL_FILE )
ret = " " ;
ret = " " ;
@ -198,10 +198,10 @@ QString BatchRenamer::parsePlugins( int i, const QString& text, int type )
return ret ;
return ret ;
}
}
void BatchRenamer : : createPreview ( QListView* list )
void BatchRenamer : : createPreview ( T QListView* list )
{
{
KMyListViewItem * item1 = NULL ;
KMyListViewItem * item1 = NULL ;
QString tmp ;
T QString tmp ;
m_counters . clear ( ) ;
m_counters . clear ( ) ;
for ( unsigned int i = 0 ; i < m_files . count ( ) ; i + + )
for ( unsigned int i = 0 ; i < m_files . count ( ) ; i + + )
@ -218,12 +218,12 @@ void BatchRenamer::createPreview( QListView* list )
bool modified = applyManualChanges ( i ) ;
bool modified = applyManualChanges ( i ) ;
QString sname = BatchRenamer : : buildFilename ( & m_files [ i ] . src , false ) ;
T QString sname = BatchRenamer : : buildFilename ( & m_files [ i ] . src , false ) ;
// Let's run the plugins that change the final filename,
// Let's run the plugins that change the final filename,
// i.e the encodingsplugin
// i.e the encodingsplugin
m_files [ i ] . dst . name = parsePlugins ( i , m_files [ i ] . dst . name , TYPE_FINAL_FILENAME ) ;
m_files [ i ] . dst . name = parsePlugins ( i , m_files [ i ] . dst . name , TYPE_FINAL_FILENAME ) ;
QString dname = BatchRenamer : : buildFilename ( & m_files [ i ] . dst , false ) ;
T QString dname = BatchRenamer : : buildFilename ( & m_files [ i ] . dst , false ) ;
item1 = new KMyListViewItem ( modified , list , item1 , sname , dname ) ;
item1 = new KMyListViewItem ( modified , list , item1 , sname , dname ) ;
}
}
@ -234,14 +234,14 @@ void BatchRenamer::work( ProgressDialog* p )
// TODO: use CopyJob here
// TODO: use CopyJob here
FileOperation fop ;
FileOperation fop ;
QFile* fundo ( NULL ) ;
T QFile* fundo ( NULL ) ;
QTextStream* tundo ( NULL ) ;
T QTextStream* tundo ( NULL ) ;
if ( undo ) {
if ( undo ) {
// Create header for undo script
// Create header for undo script
fundo = new QFile( m_undoScript ) ;
fundo = new T QFile( m_undoScript ) ;
if ( fundo - > open ( IO_WriteOnly ) ) {
if ( fundo - > open ( IO_WriteOnly ) ) {
tundo = new QTextStream( fundo ) ;
tundo = new T QTextStream( fundo ) ;
writeUndoScript ( tundo ) ;
writeUndoScript ( tundo ) ;
} else {
} else {
undo = false ;
undo = false ;
@ -258,11 +258,11 @@ void BatchRenamer::work( ProgressDialog* p )
* Give the user some information . . .
* Give the user some information . . .
*/
*/
if ( m_mode = = COPY )
if ( m_mode = = COPY )
p - > print ( QString( i18n ( " Files will be copied to: %1 " ) ) . arg( m_files [ 0 ] . dst . directory ) ) ;
p - > print ( T QString( i18n ( " Files will be copied to: %1 " ) ) . tq arg( m_files [ 0 ] . dst . directory ) ) ;
else if ( m_mode = = MOVE )
else if ( m_mode = = MOVE )
p - > print ( QString( i18n ( " Files will be moved to: %1 " ) ) . arg( m_files [ 0 ] . dst . directory ) ) ;
p - > print ( T QString( i18n ( " Files will be moved to: %1 " ) ) . tq arg( m_files [ 0 ] . dst . directory ) ) ;
else if ( m_mode = = LINK )
else if ( m_mode = = LINK )
p - > print ( QString( i18n ( " Symbolic links will be created in: %1 " ) ) . arg( m_files [ 0 ] . dst . directory ) ) ;
p - > print ( T QString( i18n ( " Symbolic links will be created in: %1 " ) ) . tq arg( m_files [ 0 ] . dst . directory ) ) ;
else if ( m_mode = = RENAME )
else if ( m_mode = = RENAME )
p - > print ( i18n ( " Input files will be renamed. " ) ) ;
p - > print ( i18n ( " Input files will be renamed. " ) ) ;
@ -302,7 +302,7 @@ void BatchRenamer::work( ProgressDialog* p )
* The plugin should return an error message in this case !
* The plugin should return an error message in this case !
*/
*/
QString eplug = parsePlugins ( i , QString: : null , TYPE_FINAL_FILE ) ;
T QString eplug = parsePlugins ( i , TQString( ) , TYPE_FINAL_FILE ) ;
if ( ! eplug . isEmpty ( ) ) {
if ( ! eplug . isEmpty ( ) ) {
p - > error ( eplug ) ;
p - > error ( eplug ) ;
error + + ;
error + + ;
@ -317,25 +317,25 @@ void BatchRenamer::work( ProgressDialog* p )
( * tundo ) < < " mv --force -b --suffix=.krename_ \" " < < m_files [ i ] . dst . name
( * tundo ) < < " mv --force -b --suffix=.krename_ \" " < < m_files [ i ] . dst . name
< < " \" \" " < < m_files [ i ] . src . name < < " \" " < < endl ;
< < " \" \" " < < m_files [ i ] . src . name < < " \" " < < endl ;
} else
} else
p - > warning ( QString( i18n ( " Undo is not possible for remote file: %1 " ) ) . arg( dst . prettyURL ( ) ) ) ;
p - > warning ( T QString( i18n ( " Undo is not possible for remote file: %1 " ) ) . tq arg( dst . prettyURL ( ) ) ) ;
}
}
if ( ! p - > wasCancelled ( ) ) {
if ( ! p - > wasCancelled ( ) ) {
QPtrListIterator< PluginLoader : : PluginLibrary > it ( plug - > libs ) ;
T QPtrListIterator< PluginLoader : : PluginLibrary > it ( plug - > libs ) ;
for ( ; it . current ( ) ; + + it ) {
for ( ; it . current ( ) ; + + it ) {
if ( ( * it ) - > usePlugin )
if ( ( * it ) - > usePlugin )
( * it ) - > plugin - > finished ( ) ;
( * it ) - > plugin - > finished ( ) ;
}
}
}
}
const QString m = QString( i18n ( " Renamed %1 files successfully. " ) ) . arg( i - error ) ;
const T QString m = T QString( i18n ( " Renamed %1 files successfully. " ) ) . tq arg( i - error ) ;
( i - error ) ? p - > print ( m ) : p - > warning ( m ) ;
( i - error ) ? p - > print ( m ) : p - > warning ( m ) ;
if ( error > 0 )
if ( error > 0 )
p - > warning ( QString( i18n ( " %2 errors occurred! " ) ) . arg( error ) ) ;
p - > warning ( T QString( i18n ( " %2 errors occurred! " ) ) . tq arg( error ) ) ;
p - > print ( QString( i18n ( " Elapsed time: %1 seconds " ) ) . arg( t . elapsed ( ) / 1000 ) , " kalarm " ) ;
p - > print ( T QString( i18n ( " Elapsed time: %1 seconds " ) ) . tq arg( t . elapsed ( ) / 1000 ) , " kalarm " ) ;
p - > print ( i18n ( " KRename finished the renaming process. " ) , " krename " ) ;
p - > print ( i18n ( " KRename finished the renaming process. " ) , " krename " ) ;
p - > print ( i18n ( " Press close to quit! " ) ) ;
p - > print ( i18n ( " Press close to quit! " ) ) ;
p - > setRenamedFiles ( renamedFiles , m_files . count ( ) ) ;
p - > setRenamedFiles ( renamedFiles , m_files . count ( ) ) ;
@ -356,105 +356,81 @@ void BatchRenamer::work( ProgressDialog* p )
delete this ;
delete this ;
}
}
void BatchRenamer : : escape ( QString & text , const QString & token , const QString & sequence )
void BatchRenamer : : escape ( T QString & text , const T QString & token , const T QString & sequence )
{
{
/*
text . tqreplace ( token , sequence ) ;
* NEVER , ABSOLUTELY NEVER change pos = 0
* to pos = - 1 , it won ' t work !
* This bug took hours to find and was
* a serious bug in 1.7 .
*/
# if QT_VERSION >= 0x030100
text . replace ( token , sequence ) ;
# else
int pos = 0 ;
do {
pos = text . find ( token , pos ) ;
if ( pos > = 0 )
text . replace ( pos , token . length ( ) , sequence ) ;
} while ( pos > = 0 ) ;
# endif
}
}
QString & BatchRenamer : : doEscape ( QString & text , bool filename )
TQString & BatchRenamer : : doEscape ( TQString text , bool filename )
{
{
if ( filename ) {
if ( filename ) {
BatchRenamer : : escape ( text , " & " , QChar( 60000 ) ) ;
BatchRenamer : : escape ( text , " & " , TQChar ( 60000 ) ) ;
BatchRenamer : : escape ( text , " $ " , QChar( 60001 ) ) ;
BatchRenamer : : escape ( text , " $ " , TQChar ( 60001 ) ) ;
BatchRenamer : : escape ( text , " % " , QChar( 60002 ) ) ;
BatchRenamer : : escape ( text , " % " , TQChar ( 60002 ) ) ;
BatchRenamer : : escape ( text , " # " , QChar( 60004 ) ) ;
BatchRenamer : : escape ( text , " # " , TQChar ( 60004 ) ) ;
BatchRenamer : : escape ( text , " [ " , QChar( 60005 ) ) ;
BatchRenamer : : escape ( text , " [ " , TQChar ( 60005 ) ) ;
BatchRenamer : : escape ( text , " ] " , QChar( 60006 ) ) ;
BatchRenamer : : escape ( text , " ] " , TQChar ( 60006 ) ) ;
BatchRenamer : : escape ( text , " \\ " , QChar( 60007 ) ) ;
BatchRenamer : : escape ( text , " \\ " , TQChar ( 60007 ) ) ;
BatchRenamer : : escape ( text , " / " , QChar( 60008 ) ) ;
BatchRenamer : : escape ( text , " / " , TQChar ( 60008 ) ) ;
BatchRenamer : : escape ( text , " { " , QChar( 60009 ) ) ;
BatchRenamer : : escape ( text , " { " , TQChar ( 60009 ) ) ;
BatchRenamer : : escape ( text , " } " , QChar( 60010 ) ) ;
BatchRenamer : : escape ( text , " } " , TQChar ( 60010 ) ) ;
BatchRenamer : : escape ( text , " * " , QChar( 60011 ) ) ;
BatchRenamer : : escape ( text , " * " , T QChar( 60011 ) ) ;
} else {
} else {
BatchRenamer : : escape ( text , " \\ & " , QChar( 60000 ) ) ;
BatchRenamer : : escape ( text , " \\ & " , T QChar( 60000 ) ) ;
BatchRenamer : : escape ( text , " \\ $ " , QChar( 60001 ) ) ;
BatchRenamer : : escape ( text , " \\ $ " , T QChar( 60001 ) ) ;
BatchRenamer : : escape ( text , " \\ % " , QChar( 60002 ) ) ;
BatchRenamer : : escape ( text , " \\ % " , T QChar( 60002 ) ) ;
BatchRenamer : : escape ( text , " \\ # " , QChar( 60004 ) ) ;
BatchRenamer : : escape ( text , " \\ # " , T QChar( 60004 ) ) ;
BatchRenamer : : escape ( text , " \\ [ " , QChar( 60005 ) ) ;
BatchRenamer : : escape ( text , " \\ [ " , T QChar( 60005 ) ) ;
BatchRenamer : : escape ( text , " \\ ] " , QChar( 60006 ) ) ;
BatchRenamer : : escape ( text , " \\ ] " , T QChar( 60006 ) ) ;
BatchRenamer : : escape ( text , " \\ \\ " , QChar( 60007 ) ) ;
BatchRenamer : : escape ( text , " \\ \\ " , T QChar( 60007 ) ) ;
BatchRenamer : : escape ( text , " \\ / " , QChar( 60008 ) ) ;
BatchRenamer : : escape ( text , " \\ / " , T QChar( 60008 ) ) ;
BatchRenamer : : escape ( text , " \\ { " , QChar( 60009 ) ) ;
BatchRenamer : : escape ( text , " \\ { " , T QChar( 60009 ) ) ;
BatchRenamer : : escape ( text , " \\ } " , QChar( 60010 ) ) ;
BatchRenamer : : escape ( text , " \\ } " , T QChar( 60010 ) ) ;
BatchRenamer : : escape ( text , " \\ * " , QChar( 60011 ) ) ;
BatchRenamer : : escape ( text , " \\ * " , T QChar( 60011 ) ) ;
}
}
return text ;
return text ;
}
}
QString & BatchRenamer : : unEscape ( QString & text )
T QString & BatchRenamer : : unEscape ( T QString & text )
{
{
BatchRenamer : : escape ( text , QChar( 60000 ) , " & " ) ;
BatchRenamer : : escape ( text , T QChar( 60000 ) , " & " ) ;
BatchRenamer : : escape ( text , QChar( 60001 ) , " $ " ) ;
BatchRenamer : : escape ( text , T QChar( 60001 ) , " $ " ) ;
BatchRenamer : : escape ( text , QChar( 60002 ) , " % " ) ;
BatchRenamer : : escape ( text , T QChar( 60002 ) , " % " ) ;
BatchRenamer : : escape ( text , QChar( 60004 ) , " # " ) ;
BatchRenamer : : escape ( text , T QChar( 60004 ) , " # " ) ;
BatchRenamer : : escape ( text , QChar( 60005 ) , " [ " ) ;
BatchRenamer : : escape ( text , T QChar( 60005 ) , " [ " ) ;
BatchRenamer : : escape ( text , QChar( 60006 ) , " ] " ) ;
BatchRenamer : : escape ( text , T QChar( 60006 ) , " ] " ) ;
BatchRenamer : : escape ( text , QChar( 60007 ) , " \\ " ) ;
BatchRenamer : : escape ( text , T QChar( 60007 ) , " \\ " ) ;
// %252f == /, it seems that filenames on unix cannot contain
// %252f == /, it seems that filenames on unix cannot contain
// a /. So I use %252f, at least konqui displays it correctly
// a /. So I use %252f, at least konqui displays it correctly
// this was needed, so that plugins that return a slash do not cause errors
// this was needed, so that plugins that return a slash do not cause errors
BatchRenamer : : escape ( text , QChar( 60008 ) , " %2f " ) ;
BatchRenamer : : escape ( text , T QChar( 60008 ) , " %2f " ) ;
BatchRenamer : : escape ( text , QChar( 60009 ) , " { " ) ;
BatchRenamer : : escape ( text , T QChar( 60009 ) , " { " ) ;
BatchRenamer : : escape ( text , QChar( 60010 ) , " } " ) ;
BatchRenamer : : escape ( text , T QChar( 60010 ) , " } " ) ;
BatchRenamer : : escape ( text , QChar( 60011 ) , " * " ) ;
BatchRenamer : : escape ( text , T QChar( 60011 ) , " * " ) ;
return text ;
return text ;
}
}
int BatchRenamer : : getCharacters ( int n )
int BatchRenamer : : getCharacters ( int n )
{
{
QString s ;
T QString s ;
s . sprintf ( " %i " , n ) ;
s . sprintf ( " %i " , n ) ;
return s . length ( ) ;
return s . length ( ) ;
}
}
QString BatchRenamer : : findAndProcess ( const QString & token , QString text , const QString & replace )
T QString BatchRenamer : : findAndProcess ( const T QString & token , T QString text , const T QString & tq replace )
{
{
/*
/*
* pos can here be - 1 because
* pos can here be - 1 because
* findRev is called with it as a
* tq findRev is called with it as a
* value !
* value !
*/
*/
# if QT_VERSION >= 0x030100
text . tqreplace ( token , tqreplace ) ;
text . replace ( token , replace ) ;
# else
int pos = - 1 ;
do {
pos = text . findRev ( token , pos ) ;
if ( pos > = 0 )
text . replace ( pos , token . length ( ) , replace ) ;
} while ( pos > = 0 ) ;
# endif
return text ;
return text ;
}
}
QString BatchRenamer : : findNumbers ( QString text , int count , int i )
TQString BatchRenamer : : findNumbers ( TQString text , int count , int i )
{
{
// Rewritten in Version 0.8
// Rewritten in Version 0.8
// Added numbers skipping in 1.3
// Added numbers skipping in 1.3
@ -464,10 +440,10 @@ QString BatchRenamer::findNumbers( QString text, int count, int i )
countervalues . start = m_index ;
countervalues . start = m_index ;
countervalues . step = m_step ;
countervalues . step = m_step ;
if ( text . contains( " # " , FALSE ) < = 0 )
if ( text . tq contains( " # " , FALSE ) < = 0 )
return text ;
return text ;
pos = text . find( " # " , pos ) ;
pos = text . tq find( " # " , pos ) ;
pos + + ;
pos + + ;
while ( text [ pos ] = = ' # ' ) {
while ( text [ pos ] = = ' # ' ) {
text . remove ( pos , 1 ) ;
text . remove ( pos , 1 ) ;
@ -476,7 +452,7 @@ QString BatchRenamer::findNumbers( QString text, int count, int i )
findNumberAppendix ( text , pos , & countervalues . start , & countervalues . step ) ;
findNumberAppendix ( text , pos , & countervalues . start , & countervalues . step ) ;
pos = text . find( " # " , 0 ) ;
pos = text . tq find( " # " , 0 ) ;
if ( ( signed int ) m_counters . count ( ) < = m_counter_index )
if ( ( signed int ) m_counters . count ( ) < = m_counter_index )
{
{
@ -488,7 +464,7 @@ QString BatchRenamer::findNumbers( QString text, int count, int i )
do {
do {
m_counters [ m_counter_index ] . value + = m_counters [ m_counter_index ] . step ;
m_counters [ m_counter_index ] . value + = m_counters [ m_counter_index ] . step ;
} while ( m_skip . contains( m_counters [ m_counter_index ] . value ) ) ;
} while ( m_skip . tq contains( m_counters [ m_counter_index ] . value ) ) ;
/*
/*
int v = start + ( i * step ) + m_skip_add [ m_counter_index ] ;
int v = start + ( i * step ) + m_skip_add [ m_counter_index ] ;
@ -500,22 +476,22 @@ QString BatchRenamer::findNumbers( QString text, int count, int i )
}
}
*/
*/
QString temp ;
T QString temp ;
temp . sprintf ( " %0*i " , counter , m_counters [ m_counter_index ] . value ) ;
temp . sprintf ( " %0*i " , counter , m_counters [ m_counter_index ] . value ) ;
text . replace( pos , 1 , temp ) ;
text . tq replace( pos , 1 , temp ) ;
+ + m_counter_index ;
+ + m_counter_index ;
return findNumbers ( text , count , i ) ;
return findNumbers ( text , count , i ) ;
}
}
void BatchRenamer : : findNumberAppendix ( QString & text , int pos , int * start , int * step )
void BatchRenamer : : findNumberAppendix ( T QString & text , int pos , int * start , int * step )
{
{
QString appendix = QString : : null ;
TQString appendix = TQString ( ) ;
int tmp = 0 ;
int tmp = 0 ;
int end = 0 ;
int end = 0 ;
bool ok = false ;
bool ok = false ;
if ( text [ pos ] = = ' { ' & & ( end = text . find( " } " , pos ) ) > - 1 )
if ( text [ pos ] = = ' { ' & & ( end = text . tq find( " } " , pos ) ) > - 1 )
{
{
//qDebug("Found an appendix:" + appendix );
//qDebug("Found an appendix:" + appendix );
appendix = text . mid ( pos + 1 , end - pos - 1 ) ;
appendix = text . mid ( pos + 1 , end - pos - 1 ) ;
@ -531,13 +507,13 @@ void BatchRenamer::findNumberAppendix( QString & text, int pos, int* start, int*
}
}
}
}
QString BatchRenamer : : findStar ( const QString & oldname , QString text )
T QString BatchRenamer : : findStar ( const T QString & oldname , T QString text )
{
{
int pos = - 1 ;
int pos = - 1 ;
do {
do {
pos = text . findRev( " * " , pos ) ;
pos = text . tq findRev( " * " , pos ) ;
if ( pos > = 0 ) {
if ( pos > = 0 ) {
QString tmp = oldname . lower ( ) ;
T QString tmp = oldname . lower ( ) ;
if ( tmp [ 0 ] . isLetter ( ) )
if ( tmp [ 0 ] . isLetter ( ) )
tmp [ 0 ] = tmp [ 0 ] . upper ( ) ;
tmp [ 0 ] = tmp [ 0 ] . upper ( ) ;
@ -546,13 +522,13 @@ QString BatchRenamer::findStar( const QString & oldname, QString text )
tmp [ i ] ! = ' \' ' & & tmp [ i ] ! = ' ? ' & & tmp [ i ] ! = ' ` ' )
tmp [ i ] ! = ' \' ' & & tmp [ i ] ! = ' ? ' & & tmp [ i ] ! = ' ` ' )
tmp [ i + 1 ] = tmp [ i + 1 ] . upper ( ) ;
tmp [ i + 1 ] = tmp [ i + 1 ] . upper ( ) ;
text . replace( pos , 1 , tmp ) ;
text . tq replace( pos , 1 , tmp ) ;
}
}
} while ( pos > = 0 ) ;
} while ( pos > = 0 ) ;
return text ;
return text ;
}
}
QString BatchRenamer : : findBrackets ( QString oldname , QString text , int i )
T QString BatchRenamer : : findBrackets ( T QString oldname , T QString text , int i )
{
{
/*
/*
* looks for a statement in brackets [ ]
* looks for a statement in brackets [ ]
@ -560,17 +536,17 @@ QString BatchRenamer::findBrackets( QString oldname, QString text, int i )
*/
*/
int num , pos = - 1 , a ;
int num , pos = - 1 , a ;
QString token ;
T QString token ;
if ( text . contains( " ] " , FALSE ) < = 0 | | text . isEmpty ( ) )
if ( text . tq contains( " ] " , FALSE ) < = 0 | | text . isEmpty ( ) )
return text ;
return text ;
num = text . contains( " [ " , FALSE ) ;
num = text . tq contains( " [ " , FALSE ) ;
if ( num < = 0 )
if ( num < = 0 )
return text ;
return text ;
pos = text . findRev( " [ " , pos ) ;
pos = text . tq findRev( " [ " , pos ) ;
a = text . find( " ] " , pos ) ;
a = text . tq find( " ] " , pos ) ;
if ( a < 0 & & pos > = 0 )
if ( a < 0 & & pos > = 0 )
return text ;
return text ;
@ -589,9 +565,9 @@ QString BatchRenamer::findBrackets( QString oldname, QString text, int i )
return findBrackets ( oldname , text , i ) ;
return findBrackets ( oldname , text , i ) ;
}
}
QString BatchRenamer : : processToken ( QString token , QString oldname , int i )
T QString BatchRenamer : : processToken ( T QString token , T QString oldname , int i )
{
{
QString tmp ;
T QString tmp ;
/*
/*
* Call here all functions that handle
* Call here all functions that handle
@ -625,10 +601,10 @@ QString BatchRenamer::processToken( QString token, QString oldname, int i )
* Krename simply ignores unknown tokens !
* Krename simply ignores unknown tokens !
* Usefull for the MP3 Plugin !
* Usefull for the MP3 Plugin !
*/
*/
return QString : : null ;
return TQString ( ) ;
}
}
QString BatchRenamer : : findToken ( QString oldname , QString token , int i )
T QString BatchRenamer : : findToken ( T QString oldname , T QString token , int i )
{
{
enum conversion { LOWER , UPPER , MIXED , STAR , STRIP , NONE , EMPTY , NUMBER } ;
enum conversion { LOWER , UPPER , MIXED , STAR , STRIP , NONE , EMPTY , NUMBER } ;
unsigned int numwidth = 0 ;
unsigned int numwidth = 0 ;
@ -658,7 +634,7 @@ QString BatchRenamer::findToken( QString oldname, QString token, int i )
if ( c ! = EMPTY & & c ! = NUMBER )
if ( c ! = EMPTY & & c ! = NUMBER )
token . remove ( 0 , 1 ) ;
token . remove ( 0 , 1 ) ;
QString save = token ;
T QString save = token ;
token = processToken ( token , oldname , i ) ;
token = processToken ( token , oldname , i ) ;
switch ( c ) {
switch ( c ) {
@ -670,7 +646,7 @@ QString BatchRenamer::findToken( QString oldname, QString token, int i )
break ;
break ;
case MIXED :
case MIXED :
token = token . lower ( ) ;
token = token . lower ( ) ;
token . replace( 0 , 1 , token [ 0 ] . upper ( ) ) ;
token . tq replace( 0 , 1 , token [ 0 ] . upper ( ) ) ;
break ;
break ;
case STAR :
case STAR :
token = findStar ( token , " * " ) ;
token = findStar ( token , " * " ) ;
@ -694,20 +670,20 @@ QString BatchRenamer::findToken( QString oldname, QString token, int i )
return token ;
return token ;
}
}
QString BatchRenamer : : findPartStrings ( QString oldname , QString token )
T QString BatchRenamer : : findPartStrings ( T QString oldname , T QString token )
{
{
QString first , second ;
T QString first , second ;
int pos = - 1 ;
int pos = - 1 ;
// parse things like [2;4{[dirname]}]
// parse things like [2;4{[dirname]}]
if ( token . contains( " { " ) > = 1 & & token . contains( " } " ) > = 1 ) {
if ( token . tq contains( " { " ) > = 1 & & token . tq contains( " } " ) > = 1 ) {
int pos = token . find( " { " ) ;
int pos = token . tq find( " { " ) ;
oldname = token . mid ( pos + 1 , token . findRev( " } " ) - pos - 1 ) ;
oldname = token . mid ( pos + 1 , token . tq findRev( " } " ) - pos - 1 ) ;
token = token . left ( pos ) ;
token = token . left ( pos ) ;
}
}
if ( token . contains( " - " ) ) {
if ( token . tq contains( " - " ) ) {
pos = token . find( " - " , 0 ) ;
pos = token . tq find( " - " , 0 ) ;
first = token . left ( pos ) ;
first = token . left ( pos ) ;
// ------- Code OK ^ !
// ------- Code OK ^ !
@ -741,8 +717,8 @@ QString BatchRenamer::findPartStrings( QString oldname, QString token )
x + + ;
x + + ;
return oldname . mid ( first . toInt ( ) - 1 , x ) ;
return oldname . mid ( first . toInt ( ) - 1 , x ) ;
} else if ( token . contains( " ; " ) ) {
} else if ( token . tq contains( " ; " ) ) {
pos = token . find( " ; " , 0 ) ;
pos = token . tq find( " ; " , 0 ) ;
first = token . left ( pos ) ;
first = token . left ( pos ) ;
second = token . mid ( pos + 1 , token . length ( ) ) ;
second = token . mid ( pos + 1 , token . length ( ) ) ;
@ -753,13 +729,13 @@ QString BatchRenamer::findPartStrings( QString oldname, QString token )
int number = token . toInt ( & ok ) ;
int number = token . toInt ( & ok ) ;
if ( ok & & ( number < = ( signed int ) oldname . length ( ) & & number > 0 ) )
if ( ok & & ( number < = ( signed int ) oldname . length ( ) & & number > 0 ) )
return QString( oldname [ number - 1 ] ) ;
return T QString( oldname [ number - 1 ] ) ;
else
else
return QString : : null ;
return TQString ( ) ;
}
}
}
}
QString BatchRenamer : : findDirName ( QString token , QString path )
T QString BatchRenamer : : findDirName ( T QString token , T QString path )
{
{
if ( token . left ( 7 ) . lower ( ) = = " dirname " ) {
if ( token . left ( 7 ) . lower ( ) = = " dirname " ) {
if ( path . right ( 1 ) = = " / " )
if ( path . right ( 1 ) = = " / " )
@ -768,9 +744,9 @@ QString BatchRenamer::findDirName( QString token, QString path )
int recursion = 1 ;
int recursion = 1 ;
if ( token . length ( ) > 7 ) {
if ( token . length ( ) > 7 ) {
token = token . right ( token . length ( ) - 7 ) ;
token = token . right ( token . length ( ) - 7 ) ;
recursion = token . contains( " . " ) ;
recursion = token . tq contains( " . " ) ;
if ( recursion ! = ( signed int ) token . length ( ) )
if ( recursion ! = ( signed int ) token . length ( ) )
return QString : : null ;
return TQString ( ) ;
recursion + + ;
recursion + + ;
}
}
@ -778,10 +754,10 @@ QString BatchRenamer::findDirName( QString token, QString path )
return path . section ( " / " , recursion * - 1 , recursion * - 1 ) ;
return path . section ( " / " , recursion * - 1 , recursion * - 1 ) ;
}
}
return QString : : null ;
return TQString ( ) ;
}
}
QString BatchRenamer : : findLength ( const QString & token , const QString & name )
T QString BatchRenamer : : findLength ( const T QString & token , const T QString & name )
{
{
if ( token . lower ( ) . startsWith ( " length " ) ) {
if ( token . lower ( ) . startsWith ( " length " ) ) {
int minus = 0 ;
int minus = 0 ;
@ -792,67 +768,41 @@ QString BatchRenamer::findLength( const QString & token, const QString & name )
minus = 0 ;
minus = 0 ;
}
}
return QString: : number ( name . length ( ) - minus ) ;
return T QString: : number ( name . length ( ) - minus ) ;
}
}
return QString : : null ;
return TQString ( ) ;
}
}
QString BatchRenamer : : findReplace ( QString text )
T QString BatchRenamer : : findReplace ( T QString text )
{
{
// Call for each element in replace strings doReplace with correct values
// Call for each element in replace strings doReplace with correct values
for ( unsigned int i = 0 ; i < m_ replace. count ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < m_ tq replace. count ( ) ; i + + ) {
replacestrings s = m_ replace[ i ] ;
replacestrings s = m_ tq replace[ i ] ;
text = doReplace ( text , unEscape ( s . find ) , s . replace, s . reg ) ;
text = doReplace ( text , unEscape ( s . tq find ) , s . tq replace, s . reg ) ;
}
}
return text ;
return text ;
}
}
QString BatchRenamer : : doReplace ( QString text , QString find, QString replace, bool reg )
T QString BatchRenamer : : doReplace ( T QString text , T QString tq find, T QString tq replace, bool reg )
{
{
if ( ! reg )
if ( ! reg )
{
{
# if QT_VERSION >= 0x030100
// we use the escaped text here because the user might want
// we use the escaped text here because the user might want
// to find a "&" and replace it
// to find a "&" and replace it
text . replace ( doEscape ( find ) , replace ) ;
text . tqreplace ( doEscape ( tqfind ) , tqreplace ) ;
# else
int pos = 0 ;
QString f = doEscape ( find ) ;
do {
pos = text . find ( f , pos ) ;
if ( pos > = 0 ) {
text . replace ( pos , f . length ( ) , replace ) ;
pos + = replace . length ( ) ;
}
} while ( pos > = 0 ) ;
# endif
}
}
else
else
{
{
# if QT_VERSION >= 0x030100
// no doEscape() here for the regexp, because it would destroy our regular expression
// no doEscape() here for the regexp, because it would destroy our regular expression
// other wise we will not find stuff like $, [ in the text
// other wise we will not find stuff like $, [ in the text
text = doEscape ( unEscape ( text ) . replace ( QRegExp ( find ) , replace ) ) ;
text = doEscape ( unEscape ( text ) . tqreplace ( TQRegExp ( tqfind ) , tqreplace ) ) ;
# else
// Test this code more!
pos = 0 ;
do {
QRegExp exp ( find ) ;
pos = exp . search ( text , pos ) ;
if ( pos > = 0 ) {
text = doEscape ( unEscape ( text ) . replace ( pos , exp . matchedLength ( ) , replace ) ) ;
pos + = replace . length ( ) ;
}
} while ( pos > = 0 ) ;
# endif
}
}
return text ;
return text ;
}
}
void BatchRenamer : : writeUndoScript ( QTextStream* t )
void BatchRenamer : : writeUndoScript ( TQTextStream * t )
{
{
// write header comments
// write header comments
( * t ) < < " #!/bin/bash " < < endl
( * t ) < < " #!/bin/bash " < < endl
@ -882,15 +832,15 @@ void BatchRenamer::writeUndoScript( QTextStream* t )
void BatchRenamer : : parseSubdirs ( data * f )
void BatchRenamer : : parseSubdirs ( data * f )
{
{
int pos = 0 ;
int pos = 0 ;
if ( ( pos = f - > dst . name . findRev( " / " , - 1 ) ) > 0 ) {
if ( ( pos = f - > dst . name . tq findRev( " / " , - 1 ) ) > 0 ) {
QString dirs = f - > dst . name . left ( pos ) ;
T QString dirs = f - > dst . name . left ( pos ) ;
f - > dst . name = f - > dst . name . right ( f - > dst . name . length ( ) - pos - 1 ) ;
f - > dst . name = f - > dst . name . right ( f - > dst . name . length ( ) - pos - 1 ) ;
f - > dst . directory + = ( f - > dst . directory . right ( 1 ) = = " / " ) ? " " : " / " ;
f - > dst . directory + = ( f - > dst . directory . right ( 1 ) = = " / " ) ? " " : " / " ;
// create the missing subdir now
// create the missing subdir now
int i = 0 ;
int i = 0 ;
QString d = " " ;
T QString d = " " ;
while ( ( d = dirs . section ( " / " , i , i , QString: : SectionSkipEmpty ) ) & & ! d . isEmpty ( ) ) { // asignment here!
while ( ( d = dirs . section ( " / " , i , i , T QString: : SectionSkipEmpty ) ) & & ! d . isEmpty ( ) ) { // asignment here!
KURL url = f - > dst . url ;
KURL url = f - > dst . url ;
// it is important to unescape here
// it is important to unescape here
// to support dirnames containing "&" or
// to support dirnames containing "&" or
@ -907,9 +857,9 @@ void BatchRenamer::parseSubdirs( data* f )
}
}
}
}
QString BatchRenamer : : buildFilename ( fileentry * entry , bool dir )
T QString BatchRenamer : : buildFilename ( fileentry * entry , bool dir )
{
{
QString filename = ( dir ? entry - > directory : QString: : null ) + entry - > name + ( entry - > extension . isEmpty ( ) ? QString: : null : QString( " . " ) ) + entry - > extension ;
T QString filename = ( dir ? entry - > directory : TQString( ) ) + entry - > name + ( entry - > extension . isEmpty ( ) ? TQString( ) : T QString( " . " ) ) + entry - > extension ;
// unescape here as filename is still escaped
// unescape here as filename is still escaped
unEscape ( filename ) ;
unEscape ( filename ) ;
return filename ;
return filename ;
@ -929,7 +879,7 @@ bool BatchRenamer::applyManualChanges( int i )
m_files [ i ] . dst . name = m_changes [ z ] . user ;
m_files [ i ] . dst . name = m_changes [ z ] . user ;
// the file extension is already included
// the file extension is already included
// in the users name
// in the users name
m_files [ i ] . dst . extension = QString: : null ;
m_files [ i ] . dst . extension = TQString( ) ;
return true ;
return true ;
}
}
}
}