"Fossies" - the Fresh Open Source Software Archive  

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

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

krenametokensorter.cpp  (krename-4.0.9):krenametokensorter.cpp  (krename-4.90.90)
skipping to change at line 26 skipping to change at line 26
***************************************************************************/ ***************************************************************************/
#include "krenametokensorter.h" #include "krenametokensorter.h"
#include "plugin.h" #include "plugin.h"
#include "pluginloader.h" #include "pluginloader.h"
#include <krandom.h> #include <krandom.h>
// Helper functions for sorting // Helper functions for sorting
static const QString findNumInString( unsigned int pos, const QString & s ) static const QString findNumInString(unsigned int pos, const QString &s)
{ {
QString num; QString num;
for( int i = static_cast<int>(pos); i >= 0; i-- ) for (int i = static_cast<int>(pos); i >= 0; i--)
if( s[i].isDigit() ) if (s[i].isDigit()) {
num.prepend( s[i] ); num.prepend(s[i]);
else } else {
break; break;
}
for( int i = pos + 1; i < s.length(); i++ ) for (int i = pos + 1; i < s.length(); i++)
if( s[i].isDigit() ) if (s[i].isDigit()) {
num.append( s[i] ); num.append(s[i]);
else } else {
break; break;
}
return num; return num;
} }
static int compareNummeric( const QString & s1, const QString & s2 ) static int compareNummeric(const QString &s1, const QString &s2)
{ {
int z = 0; int z = 0;
int max = ( s1.length() > s2.length() ? s1.length() : s2.length() ); int max = (s1.length() > s2.length() ? s1.length() : s2.length());
QString num1; QString num1;
QString num2; QString num2;
for( z=0;z<max;z++) for (z = 0; z < max; z++) {
{
//if( z >= s1.length() || z >= s2.length() ) //if( z >= s1.length() || z >= s2.length() )
// break; // break;
if( (z < s1.length() && z < s2.length() && s1[z] != s2[z]) ) if ((z < s1.length() && z < s2.length() && s1[z] != s2[z])) {
{ if (z < s1.length() && s1[z].isDigit()) {
if( z < s1.length() && s1[z].isDigit() ) num1 = findNumInString(z, s1);
num1 = findNumInString( z, s1 ); }
if( z < s2.length() && s2[z].isDigit() ) if (z < s2.length() && s2[z].isDigit()) {
num2 = findNumInString( z, s2 ); num2 = findNumInString(z, s2);
}
if( num1.isNull() && num2.isNull() ) if (num1.isNull() && num2.isNull()) {
break; break;
}
int a = num1.toInt(); int a = num1.toInt();
int b = num2.toInt(); int b = num2.toInt();
if( a == b ) if (a == b) {
return s1.compare( s2 ); return s1.compare(s2);
else } else {
return ( a > b ) ? 1 : -1; return (a > b) ? 1 : -1;
}
} }
} }
return s1.compare( s2 ); return s1.compare(s2);
} }
// Less than functions for sorting // Less than functions for sorting
bool ascendingKRenameFileLessThan( const KRenameFile & file1, const KRenameFile & file2 ) bool ascendingKRenameFileLessThan(const KRenameFile &file1, const KRenameFile &f ile2)
{ {
return file1.srcUrl() < file2.srcUrl(); return file1.srcUrl() < file2.srcUrl();
} }
bool descendingKRenameFileLessThan( const KRenameFile & file1, const KRenameFile & file2 ) bool descendingKRenameFileLessThan(const KRenameFile &file1, const KRenameFile & file2)
{ {
return !(file1.srcUrl() < file2.srcUrl()); return !(file1.srcUrl() < file2.srcUrl());
} }
bool numericKRenameFileLessThan( const KRenameFile & file1, const KRenameFile & file2 ) bool numericKRenameFileLessThan(const KRenameFile &file1, const KRenameFile &fil e2)
{ {
KUrl url1 = file1.srcUrl(); QUrl url1 = file1.srcUrl();
KUrl url2 = file2.srcUrl(); QUrl url2 = file2.srcUrl();
if( url1.directory() != url2.directory() ) QString directory1 = url1.adjusted(QUrl::RemoveFilename | QUrl::StripTrailin
{ gSlash).path();
QString directory2 = url2.adjusted(QUrl::RemoveFilename | QUrl::StripTrailin
gSlash).path();
if (directory1 != directory2) {
// not in the same directory so do lexical comparison // not in the same directory so do lexical comparison
return url1 < url2; return url1 < url2;
} else {
return (compareNummeric(file1.srcFilename(), file2.srcFilename()) < 0);
} }
else
return (compareNummeric( file1.srcFilename(), file2.srcFilename() ) < 0)
;
return false; return false;
} }
bool randomKRenameFileLessThan( const KRenameFile &, const KRenameFile & ) bool randomKRenameFileLessThan(const KRenameFile &, const KRenameFile &)
{ {
return static_cast<double>(KRandom::random()) / static_cast<double>(RAND_MAX ) < 0.5; return static_cast<double>(KRandom::random()) / static_cast<double>(RAND_MAX ) < 0.5;
} }
KRenameTokenSorter::KRenameTokenSorter(BatchRenamer* renamer, const QString & to KRenameTokenSorter::KRenameTokenSorter(BatchRenamer *renamer, const QString &tok
ken, en,
const KRenameFile::List & list, ESimpleSo const KRenameFile::List &list, ESimpleSor
rtMode eSortMode) tMode eSortMode)
: m_renamer(renamer), m_token(token), m_list(list), m_eSortMode(eSortMode) : m_renamer(renamer), m_token(token), m_list(list), m_eSortMode(eSortMode)
{ {
m_plugin = PluginLoader::Instance()->findPlugin( token ); m_plugin = PluginLoader::Instance()->findPlugin(token);
KRenameFile::List::ConstIterator it = list.begin(); KRenameFile::List::ConstIterator it = list.begin();
int index = 0; int index = 0;
while( it != list.end() ) while (it != list.end()) {
{ QString value = processString(index++);
QString value = processString( index++ ); m_values.insert((*it).srcUrl(), value);
m_values.insert( (*it).srcUrl(), value );
++it; ++it;
} }
} }
bool KRenameTokenSorter::operator()( const KRenameFile & file1, const KRenameFil e & file2 ) bool KRenameTokenSorter::operator()(const KRenameFile &file1, const KRenameFile &file2)
{ {
QString str1, str2; QString str1, str2;
str1 = m_values.value( file1.srcUrl() ); str1 = m_values.value(file1.srcUrl());
str2 = m_values.value( file2.srcUrl() ); str2 = m_values.value(file2.srcUrl());
if( m_eSortMode == eSimpleSortMode_Ascending ) if (m_eSortMode == eSimpleSortMode_Ascending) {
{
return str1 < str2; return str1 < str2;
} } else if (m_eSortMode == eSimpleSortMode_Descending) {
else if( m_eSortMode == eSimpleSortMode_Descending )
{
return !(str1 < str2); return !(str1 < str2);
} } else if (m_eSortMode == eSimpleSortMode_Numeric) {
else if( m_eSortMode == eSimpleSortMode_Numeric ) return compareNummeric(str1, str2) < 0;
{
return compareNummeric( str1, str2 ) < 0;
} }
// Default, should never be reached // Default, should never be reached
return (str1 < str2); return (str1 < str2);
} }
QString KRenameTokenSorter::processString( int index ) const QString KRenameTokenSorter::processString(int index) const
{ {
QString ret = m_token; QString ret = m_token;
if( m_plugin != NULL ) if (m_plugin != nullptr) {
{ ret = m_plugin->processFile(m_renamer, index, ret, ePluginType_Token);
ret = m_plugin->processFile( m_renamer, index, ret, ePluginType_Token );
} }
return ret; return ret;
} }
 End of changes. 30 change blocks. 
62 lines changed or deleted 61 lines changed or added

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