dirsortplugin.cpp (krename-4.0.9) | : | dirsortplugin.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
***************************************************************************/ | ***************************************************************************/ | |||
// Own includes | // Own includes | |||
#include "dirsortplugin.h" | #include "dirsortplugin.h" | |||
#include "batchrenamer.h" | #include "batchrenamer.h" | |||
// KDE includes | // KDE includes | |||
#include <kiconloader.h> | #include <kiconloader.h> | |||
#include <kio/job.h> | #include <kio/job.h> | |||
#include <kio/netaccess.h> | ||||
#include <klocale.h> | ||||
#include <kmessagebox.h> | #include <kmessagebox.h> | |||
#include <KJobWidgets> | ||||
DirSortPlugin::DirSortPlugin( PluginLoader* loader ) | DirSortPlugin::DirSortPlugin(PluginLoader *loader) | |||
: Plugin( loader ) | : Plugin(loader) | |||
{ | { | |||
m_widget = new Ui::DirSortPluginWidget(); | m_widget = new Ui::DirSortPluginWidget(); | |||
} | } | |||
DirSortPlugin::~DirSortPlugin() | DirSortPlugin::~DirSortPlugin() | |||
{ | { | |||
delete m_widget; | delete m_widget; | |||
} | } | |||
const QString DirSortPlugin::name() const | const QString DirSortPlugin::name() const | |||
{ | { | |||
return i18n("Subdirectory-Sort Plugin"); | return i18n("Subfolder-Sort Plugin"); | |||
} | } | |||
int DirSortPlugin::type() const | int DirSortPlugin::type() const | |||
{ | { | |||
return ePluginType_File; | return ePluginType_File; | |||
} | } | |||
bool DirSortPlugin::alwaysEnabled() const | bool DirSortPlugin::alwaysEnabled() const | |||
{ | { | |||
return false; | return false; | |||
} | } | |||
const QPixmap DirSortPlugin::icon() const | const QPixmap DirSortPlugin::icon() const | |||
{ | { | |||
return KIconLoader::global()->loadIcon( "folder", KIconLoader::NoGroup, KIco nLoader::SizeSmall ); | return KIconLoader::global()->loadIcon("folder", KIconLoader::NoGroup, KIcon Loader::SizeSmall); | |||
} | } | |||
void DirSortPlugin::createUI( QWidget* parent ) const | void DirSortPlugin::createUI(QWidget *parent) const | |||
{ | { | |||
m_widget->setupUi( parent ); | m_widget->setupUi(parent); | |||
m_widget->outputUrl->setMode( KFile::Directory | KFile::ExistingOnly ); | m_widget->outputUrl->setMode(KFile::Directory | KFile::ExistingOnly); | |||
} | } | |||
/* | /* | |||
void DirSortPlugin::fillStructure() | void DirSortPlugin::fillStructure() | |||
{ | { | |||
fpd = spinFiles->value(); | fpd = spinFiles->value(); | |||
fpd--; | fpd--; | |||
dir = outputdir->text(); | dir = outputdir->text(); | |||
filecounter = 0; | filecounter = 0; | |||
dircounter = spinStart->value(); | dircounter = spinStart->value(); | |||
curdir = dir + QString("/%1/").arg( dircounter ); | curdir = dir + QString("/%1/").arg( dircounter ); | |||
d = new QDir( dir ); | d = new QDir( dir ); | |||
d->mkdir( curdir ); | d->mkdir( curdir ); | |||
} | } | |||
*/ | */ | |||
QString DirSortPlugin::processFile( BatchRenamer* b, int index, const QString &, EPluginType ) | QString DirSortPlugin::processFile(BatchRenamer *b, int index, const QString &, EPluginType) | |||
{ | { | |||
QString errorMsg = QString::null; | QString errorMsg; | |||
if( index == 0 ) | if (index == 0) { | |||
{ | ||||
// Initialize plugin | // Initialize plugin | |||
m_dirCounter = m_widget->spinStart->value(); | m_dirCounter = m_widget->spinStart->value(); | |||
m_fileCounter = 0; | m_fileCounter = 0; | |||
m_filesPerDir = m_widget->spinFiles->value(); | m_filesPerDir = m_widget->spinFiles->value(); | |||
m_digits = m_widget->spinDigits->value(); | m_digits = m_widget->spinDigits->value(); | |||
m_baseDirectory = m_widget->outputUrl->url(); | m_baseDirectory = m_widget->outputUrl->url(); | |||
if( !KIO::NetAccess::exists( m_baseDirectory, true, m_widget->spinStart | KIO::StatJob *statJob = KIO::stat(m_baseDirectory, KIO::StatJob::Destina | |||
) ) | tionSide, 2); | |||
{ | KJobWidgets::setWindow(statJob, m_widget->spinStart); | |||
statJob->exec(); | ||||
if (statJob->error()) { | ||||
m_valid = false; | m_valid = false; | |||
return this->name() + | return | |||
i18n(": The output directory %1 does not exist.", | i18n("%1: The output folder %2 does not exist.", | |||
m_baseDirectory.prettyUrl() ); | this->name(), | |||
} | m_baseDirectory.toDisplayString(QUrl::PreferLocalFile)); | |||
else | } else { | |||
{ | ||||
m_valid = true; | m_valid = true; | |||
m_currentDirectory = createNewSubdirectory(); | m_currentDirectory = createNewSubdirectory(); | |||
} | } | |||
} | } | |||
if( !m_valid ) | if (!m_valid) { | |||
return errorMsg; | return errorMsg; | |||
} | ||||
if( m_fileCounter == m_filesPerDir ) | if (m_fileCounter == m_filesPerDir) { | |||
{ | ||||
m_fileCounter = 0; | m_fileCounter = 0; | |||
m_dirCounter++; | m_dirCounter++; | |||
m_currentDirectory = createNewSubdirectory(); | m_currentDirectory = createNewSubdirectory(); | |||
} | } | |||
KUrl srcUrl = b->buildDestinationUrl( (*b->files())[index] ); | QUrl srcUrl = b->buildDestinationUrl((*b->files())[index]); | |||
KUrl dstUrl = m_currentDirectory; | QUrl dstUrl = m_currentDirectory; | |||
dstUrl.addPath( srcUrl.fileName() ); | dstUrl = dstUrl.adjusted(QUrl::StripTrailingSlash); | |||
dstUrl.setPath(dstUrl.path() + '/' + (srcUrl.fileName())); | ||||
KIO::JobFlags flags = KIO::DefaultFlags | KIO::HideProgressInfo; | KIO::JobFlags flags = KIO::DefaultFlags | KIO::HideProgressInfo; | |||
KIO::Job* job = KIO::file_move( srcUrl, dstUrl, -1, flags ); | KIO::Job *job = KIO::file_move(srcUrl, dstUrl, -1, flags); | |||
m_fileCounter++; | m_fileCounter++; | |||
if( m_valid && job && !KIO::NetAccess::synchronousRun( job, m_widget->spinSt | KJobWidgets::setWindow(job, m_widget->spinStart); | |||
art ) ) | job->exec(); | |||
{ | if (!job->exec()) { | |||
errorMsg = i18n("Error renaming %2 (to %1)", | errorMsg = i18n("Error renaming %2 (to %1)", | |||
dstUrl.prettyUrl(), | dstUrl.toDisplayString(QUrl::PreferLocalFile), | |||
srcUrl.prettyUrl()); | srcUrl.toDisplayString(QUrl::PreferLocalFile)); | |||
} | } | |||
return errorMsg; | return errorMsg; | |||
} | } | |||
const QStringList & DirSortPlugin::supportedTokens() const | const QStringList &DirSortPlugin::supportedTokens() const | |||
{ | { | |||
return m_emptyList; | return m_emptyList; | |||
} | } | |||
const QStringList & DirSortPlugin::help() const | const QStringList &DirSortPlugin::help() const | |||
{ | { | |||
return m_emptyList; | return m_emptyList; | |||
} | } | |||
KUrl DirSortPlugin::createNewSubdirectory() const | QUrl DirSortPlugin::createNewSubdirectory() const | |||
{ | { | |||
KUrl url = m_baseDirectory; | QUrl url = m_baseDirectory; | |||
QString dir; | QString dir; | |||
dir.sprintf("%0*i", m_digits, m_dirCounter ); | dir.sprintf("%0*i", m_digits, m_dirCounter); | |||
url.addPath( dir ); | url = url.adjusted(QUrl::StripTrailingSlash); | |||
url.setPath(url.path() + '/' + (dir)); | ||||
if( !KIO::NetAccess::mkdir( url, m_widget->spinStart ) ) { | ||||
KMessageBox::error( m_widget->spinStart, | KIO::MkdirJob *job = KIO::mkdir(url); | |||
i18n("Cannot create directory %1", url.prettyUrl()) | KJobWidgets::setWindow(job, m_widget->groupBox); // we just need a random wi | |||
); | dget, FIXME use the proper parent | |||
if (!job->exec()) { | ||||
KMessageBox::error(m_widget->groupBox, | ||||
i18n("Cannot create folder %1", url.toDisplayString(Q | ||||
Url::PreferLocalFile))); | ||||
} | } | |||
return url; | return url; | |||
} | } | |||
End of changes. 25 change blocks. | ||||
45 lines changed or deleted | 50 lines changed or added |