File indexing completed on 2024-03-24 17:25:13

0001 /***************************************************************************
0002                           krenameimpl.cpp  -  description
0003                              -------------------
0004     begin                : Die Mai 20 2003
0005     copyright            : (C) 2003 by Dominik Seichter
0006     email                : domseichter@web.de
0007 ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "krenameimpl.h"
0019 #include "filedialogextwidget.h"
0020 #include "krenamemodel.h"
0021 #include "krenametest.h"
0022 #include "krenamewindow.h"
0023 #include "krenamefile.h"
0024 
0025 #include "numberdialog.h"
0026 #include "insertpartfilenamedlg.h"
0027 #include "plugin.h"
0028 #include "pluginloader.h"
0029 #include "progressdialog.h"
0030 #include "replacedialog.h"
0031 #include "threadedlister.h"
0032 #include "tokenhelpdialog.h"
0033 
0034 #include "modeltest.h"
0035 
0036 #include <kconfig.h>
0037 #include <kiconloader.h>
0038 #include <KFileWidget>
0039 #include <kmessagebox.h>
0040 #include <kstandardaction.h>
0041 #include <KJobWidgets>
0042 #include <KIO/MkdirJob>
0043 #include <KIO/StatJob>
0044 
0045 #include <KHelpMenu>
0046 
0047 #include <QTimer>
0048 #include <QCommandLineParser>
0049 #include <QDebug>
0050 #include <QMenuBar>
0051 #include <QPointer>
0052 
0053 KRenameImpl::KRenameImpl(KRenameWindow *window, const KRenameFile::List &list, QCommandLineParser *commandLine)
0054     : QObject((QObject *)window), m_window(window),
0055       m_lastSplitMode(eSplitMode_LastDot), m_lastDot(0),
0056       m_runningThreadedListersCount(0)
0057 {
0058     setupSlots();
0059 
0060     m_model = new KRenameModel(&m_vector);
0061     m_window->setModel(m_model);
0062 
0063     connect(m_model, &KRenameModel::filesDropped,
0064             this, &KRenameImpl::slotUpdateCount);
0065 
0066     m_previewModel = new KRenamePreviewModel(&m_vector);
0067     m_window->setPreviewModel(m_previewModel);
0068 
0069     m_renamer.setFiles(&m_vector);
0070     m_model->setRenamer(&m_renamer);
0071     m_model->addFiles(list);
0072 
0073     m_pluginLoader = PluginLoader::Instance();
0074     m_pluginLoader->registerForUpdates(this);
0075 
0076     loadConfig();
0077 
0078     if (commandLine) {
0079         parseCmdLineOptions(commandLine);
0080     }
0081 
0082     slotUpdateCount();
0083 
0084     connect(qApp, &QApplication::aboutToQuit, this, &KRenameImpl::saveConfig);
0085 }
0086 
0087 KRenameImpl::~KRenameImpl()
0088 {
0089     m_pluginLoader->deregisterForUpdates(this);
0090     delete m_model;
0091 }
0092 
0093 QWidget *KRenameImpl::launch(const QRect &rect, const KRenameFile::List &list, QCommandLineParser *commandLine)
0094 {
0095     KSharedConfigPtr config = KSharedConfig::openConfig();
0096 
0097     KConfigGroup groupGui = config->group(QString("GUISettings"));
0098     bool firststart  = groupGui.readEntry("firststart4", QVariant(true)).toBool();
0099 
0100     if (firststart) {
0101         // WELCOME TO KRENAME
0102     }
0103 
0104     KRenameWindow *w  = new KRenameWindow(nullptr);
0105     //KRenameImpl* impl = new KRenameImpl( w, list );
0106     new KRenameImpl(w, list, commandLine);
0107     // Windows shows KRename otherwise outside of the visible
0108     // screen area
0109     if (!rect.isNull()) {
0110         w->setGeometry(rect);
0111     }
0112 
0113     /*
0114     // it is time to load a default profile now (if the user has specified one)
0115     if( loadprofile && !k->hasCommandlineProfile() && ProfileManager::hasDefaultProfile() )
0116     ProfileManager::loadDefaultProfile( k );
0117     else if ( !k->hasCommandlineProfile() )
0118         w->show();
0119     */
0120 
0121     w->show();
0122 
0123     return w;
0124 }
0125 
0126 void KRenameImpl::setupSlots()
0127 {
0128     connect(m_window, &KRenameWindow::addFiles,
0129             this, &KRenameImpl::slotAddFiles);
0130     connect(m_window, &KRenameWindow::removeFiles,
0131             this, &KRenameImpl::slotRemoveFiles);
0132     connect(m_window, &KRenameWindow::removeAllFiles,
0133             this, &KRenameImpl::slotRemoveAllFiles);
0134 
0135     connect(m_window, &KRenameWindow::updatePreview,
0136             this, &KRenameImpl::slotUpdatePreview);
0137     connect(m_window, &KRenameWindow::updateCount,
0138             this, &KRenameImpl::slotUpdateCount);
0139 
0140     connect(m_window, &KRenameWindow::accepted,
0141             this, &KRenameImpl::slotStart);
0142 
0143     QObject::connect(m_window, &KRenameWindow::renameModeChanged,
0144                      &m_renamer, &BatchRenamer::setRenameMode);
0145     QObject::connect(m_window, &KRenameWindow::filenameTemplateChanged,
0146                      &m_renamer, &BatchRenamer::setFilenameTemplate);
0147     QObject::connect(m_window, &KRenameWindow::extensionTemplateChanged,
0148                      &m_renamer, &BatchRenamer::setExtensionTemplate);
0149     QObject::connect(m_window, &KRenameWindow::overwriteFilesChanged,
0150                      &m_renamer, &BatchRenamer::setOverwriteExistingFiles);
0151 
0152     QObject::connect(m_window, &KRenameWindow::startIndexChanged,
0153                      &m_renamer, &BatchRenamer::setNumberStartIndex);
0154 
0155     connect(m_window, &KRenameWindow::extensionSplitModeChanged,
0156             this, &KRenameImpl::slotExtensionSplitModeChanged);
0157 
0158     connect(m_window, &KRenameWindow::showAdvancedNumberingDialog,
0159             this, &KRenameImpl::slotAdvancedNumberingDlg);
0160     connect(m_window, &KRenameWindow::showInsertPartFilenameDialog,
0161             this, &KRenameImpl::slotInsertPartFilenameDlg);
0162     connect(m_window, &KRenameWindow::showFindReplaceDialog,
0163             this, &KRenameImpl::slotFindReplaceDlg);
0164     connect(m_window, &KRenameWindow::showTokenHelpDialog,
0165             this, &KRenameImpl::slotTokenHelpDialog);
0166 }
0167 
0168 void KRenameImpl::addFileOrDir(const QUrl &url)
0169 {
0170     KRenameFile       item(url, m_lastSplitMode, m_lastDot);
0171     KRenameFile::List list;
0172 
0173     list.append(item);
0174 
0175     m_model->addFiles(list);
0176 
0177     this->slotUpdateCount();
0178 }
0179 
0180 void KRenameImpl::addFilesOrDirs(const QList<QUrl> &list, const QString &filter,
0181                                  bool recursively, bool dirsWithFiles, bool dirsOnly, bool hidden)
0182 {
0183     QList<QUrl>::ConstIterator it   = list.begin();
0184 
0185     while (it != list.end()) {
0186         KRenameFile item(*it, m_lastSplitMode, m_lastDot);
0187         if (item.isDirectory()) {
0188             QApplication::setOverrideCursor(Qt::BusyCursor);
0189 
0190             ThreadedLister *thl = new ThreadedLister(*it, m_window, m_model);
0191             connect(thl, &ThreadedLister::listerDone,
0192                     this, &KRenameImpl::slotListerDone);
0193 
0194             thl->setFilter(filter);
0195             thl->setListDirnamesOnly(dirsOnly);
0196             thl->setListHidden(hidden);
0197             thl->setListRecursively(recursively);
0198             thl->setListDirnames(dirsWithFiles);
0199 
0200             m_runningThreadedListersCount++;
0201             thl->start();
0202         } else {
0203             if (!dirsOnly) {
0204                 KRenameFile::List list;
0205                 list.append(item);
0206 
0207                 m_model->addFiles(list);
0208             }
0209         }
0210 
0211         ++it;
0212     }
0213 
0214     this->slotUpdateCount();
0215 }
0216 
0217 void KRenameImpl::parseCmdLineOptions(QCommandLineParser *parser)
0218 {
0219     bool gotFilenames = false;
0220 
0221     if (parser->isSet("test")) {
0222         QTimer::singleShot(0, this, SLOT(selfTest()));
0223     }
0224 
0225     // Add all recursive directoris
0226     QList<QUrl> recursiveList;
0227     QStringList directories = parser->values("r");
0228     foreach (const QString &directory, directories) {
0229         QUrl url = QUrl::fromUserInput(directory, QDir::currentPath());
0230 
0231         qDebug() << "Adding recursive:" << directory;
0232         recursiveList.append(url);
0233     }
0234 
0235     if (!recursiveList.isEmpty()) {
0236         gotFilenames = true;
0237         // Add all directories recursive, but no hiden files
0238         this->addFilesOrDirs(recursiveList, "*", true, false, false, false);
0239     }
0240 
0241     // Add all files from the commandline options
0242     QList<QUrl> list;
0243     foreach (const QString &url, parser->positionalArguments()) {
0244         list.append(QUrl::fromUserInput(url, QDir::currentPath()));
0245     }
0246 
0247     if (!list.isEmpty()) {
0248         gotFilenames = true;
0249     }
0250 
0251     this->addFilesOrDirs(list);
0252 
0253     /*
0254     // load the profile first, so that we do not overwrite other
0255     // commandline settings
0256     QCString templ = parser.value( "profile" );
0257     if( !templ.isEmpty() )
0258     {
0259         m_hasCommandlineProfile = true;
0260         ProfileManager::loadProfile( QString( templ ), this );
0261     }
0262     */
0263 
0264     QString templ = parser->value("template");
0265     if (!templ.isEmpty()) {
0266         m_window->setFilenameTemplate(templ, false);
0267     }
0268 
0269     QString extension = parser->value("extension");
0270     if (!extension.isEmpty()) {
0271         m_window->setExtensionTemplate(extension, false);
0272     }
0273 
0274     QString copyDir = parser->value("copy");
0275     if (!copyDir.isEmpty()) {
0276         m_window->setRenameMode(eRenameMode_Copy);
0277         m_window->setDestinationUrl(QUrl(copyDir));
0278     }
0279 
0280     QString moveDir = parser->value("move");
0281     if (!moveDir.isEmpty()) {
0282         m_window->setRenameMode(eRenameMode_Move);
0283         m_window->setDestinationUrl(QUrl(moveDir));
0284     }
0285 
0286     QString linkDir = parser->value("link");
0287     if (!linkDir.isEmpty()) {
0288         m_window->setRenameMode(eRenameMode_Link);
0289         m_window->setDestinationUrl(QUrl(linkDir));
0290     }
0291 
0292     /*
0293         QCStringList uselist = parser.values ( "use-plugin" );
0294         if( !uselist.isEmpty() )
0295         {
0296             for(unsigned int i = 0; i < uselist.count(); i++ )
0297                 uselist[i] = uselist[i].lower();
0298 
0299             QPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs );
0300             while ( it.current() )
0301             {
0302                 if( uselist.contains( (*it)->plugin->getName().lower().utf8() ) )
0303                     (*it)->check->setChecked( true );
0304 
0305                 ++it;
0306             }
0307 
0308             pluginHelpChanged();
0309         }
0310 
0311     */
0312     bool startnow = parser->isSet("start");
0313 
0314     // Free some memory
0315 
0316     if (gotFilenames) {
0317         // we got already filenames over the commandline, so show directly the last
0318         // page of the wizard
0319         m_window->showFilenameTab();
0320     }
0321 
0322     if (startnow) {
0323         qDebug("Waiting for listenters: %i\n", m_runningThreadedListersCount);
0324         // As file adding runs in a another trhread,
0325         // there might be adding in progress but not yet
0326         // all files in the list.
0327         // so let's wait for file adding to finish first
0328         // before starting.
0329         while (m_runningThreadedListersCount > 0) {
0330             qApp->processEvents();
0331         }
0332 
0333         if (m_vector.count() > 0)
0334             // start renaming
0335         {
0336             QTimer::singleShot(200, this, SLOT(slotStart()));
0337         }
0338     }
0339 }
0340 
0341 void KRenameImpl::slotAddFiles()
0342 {
0343     QPointer<FileDialogExtWidget> dialog = new FileDialogExtWidget(m_window);
0344 
0345     if (dialog->exec() == QDialog::Accepted) {
0346         this->addFilesOrDirs(dialog->selectedUrls(), dialog->currentFilter(),
0347                              dialog->addRecursively(), dialog->addDirsWithFiles(),
0348                              dialog->addDirsOnly(), dialog->addHidden());
0349     } else {
0350         qWarning() << "Dialog not accepted";
0351     }
0352 
0353     delete dialog;
0354 }
0355 
0356 void KRenameImpl::slotRemoveFiles()
0357 {
0358     if (m_window->selectedFileItems().count()) {
0359         m_model->removeFiles(m_window->selectedFileItems());
0360         this->slotUpdateCount();
0361     }
0362 }
0363 
0364 void KRenameImpl::slotRemoveAllFiles()
0365 {
0366     // TODO: Show message box: Do you really want to remove all files.
0367     if (KMessageBox::questionYesNo(m_window, i18n("Do you really want to remove all files from the list?"),
0368                                    i18n("KRename"), KStandardGuiItem::remove(), KStandardGuiItem::cancel(),
0369                                    "KRenameRemoveAllFromFileList") == KMessageBox::Yes) {
0370         m_vector.clear();
0371         m_window->resetFileList();
0372 
0373         this->slotUpdateCount();
0374     }
0375 }
0376 
0377 void KRenameImpl::selfTest()
0378 {
0379     KRenameTest *test = new KRenameTest();
0380     test->startTest();
0381 
0382     new ModelTest(m_model);
0383     //new ModelTest( m_previewModel );
0384 
0385     // Make _really_ sure it comes to front
0386     test->show();
0387     test->raise();
0388     test->activateWindow();
0389 }
0390 
0391 void KRenameImpl::slotUpdateCount()
0392 {
0393     m_window->setCount(m_vector.size());
0394     m_window->slotEnableControls();
0395 
0396     this->slotUpdatePreview();
0397 }
0398 
0399 void KRenameImpl::slotUpdatePreview()
0400 {
0401     QApplication::setOverrideCursor(Qt::WaitCursor);
0402     m_renamer.processFilenames();
0403     QApplication::restoreOverrideCursor();
0404 
0405     m_previewModel->refresh();
0406     //m_window->m_pageSimple->listPreview->reset();
0407 }
0408 
0409 void KRenameImpl::slotAdvancedNumberingDlg()
0410 {
0411     QPointer<NumberDialog> dialog = new NumberDialog(
0412         m_renamer.numberStartIndex(), m_renamer.numberStepping(),
0413         m_renamer.numberReset(), m_renamer.numberSkipList(), m_window);
0414 
0415     if (dialog->exec() == QDialog::Accepted) {
0416         m_renamer.setNumberStartIndex(dialog->startIndex());
0417         m_renamer.setNumberStepping(dialog->numberStepping());
0418         m_renamer.setNumberReset(dialog->resetCounter());
0419         m_renamer.setNumberSkipList(dialog->skipNumbers());
0420 
0421         m_window->setNumberStartIndex(dialog->startIndex());
0422 
0423         slotUpdatePreview();
0424     }
0425 
0426     delete dialog;
0427 }
0428 
0429 void KRenameImpl::slotInsertPartFilenameDlg()
0430 {
0431     QPointer<InsertPartFilenameDlg> dialog = new InsertPartFilenameDlg(m_vector.first().srcFilename());
0432 
0433     if (dialog->exec() == QDialog::Accepted) {
0434         m_window->setFilenameTemplate(dialog->command(), true);
0435 
0436         // Update preview will called from KRenameWindow because of the changed template
0437         // slotUpdatePreview();s
0438     }
0439 
0440     delete dialog;
0441 }
0442 
0443 void KRenameImpl::slotFindReplaceDlg()
0444 {
0445     QPointer<ReplaceDialog> dialog = new ReplaceDialog(m_renamer.replaceList(), m_window);
0446 
0447     if (dialog->exec() == QDialog::Accepted) {
0448         m_renamer.setReplaceList(dialog->replaceList());
0449         slotUpdatePreview();
0450     }
0451 
0452     delete dialog;
0453 }
0454 
0455 void KRenameImpl::slotListerDone(ThreadedLister *lister)
0456 {
0457     // Delete the listener
0458     delete lister;
0459 
0460     // restore cursor
0461     QApplication::restoreOverrideCursor();
0462 
0463     // update preview
0464     slotUpdateCount();
0465     slotUpdatePreview();
0466 
0467     qDebug("Listener Done ListenersCount: %i", m_runningThreadedListersCount);
0468 
0469     m_runningThreadedListersCount--;
0470 
0471     if (m_runningThreadedListersCount < 0) {
0472         // To be safe
0473         qDebug("m_runningThreadedListersCount=%i", m_runningThreadedListersCount);
0474         m_runningThreadedListersCount = 0;
0475     }
0476 }
0477 
0478 void KRenameImpl::slotTokenHelpDialog(QLineEdit *edit)
0479 {
0480     TokenHelpDialog dialog(m_model, &m_renamer, edit, m_window);
0481 
0482     // add built-in tokens
0483     QStringList help;
0484     help.append('$' + TokenHelpDialog::getTokenSeparator() + i18n("old filename"));
0485     help.append('%' + TokenHelpDialog::getTokenSeparator() + i18n("old filename converted to lower case"));
0486     help.append('&' + TokenHelpDialog::getTokenSeparator() + i18n("old filename converted to upper case"));
0487     help.append('*' + TokenHelpDialog::getTokenSeparator() + i18n("first letter of every word upper case"));
0488     help.append("[&1][%2-]" + TokenHelpDialog::getTokenSeparator() + i18n("first letter of filename upper case"));
0489     help.append('#' + TokenHelpDialog::getTokenSeparator() + i18n("number (try also ##, ###, ... for leading zeros)"));
0490     help.append("#{0;1}" + TokenHelpDialog::getTokenSeparator() + i18n("counter with custom start value 0 and custom stepping 1"));
0491     help.append('/' + TokenHelpDialog::getTokenSeparator() + i18n("create a subdfolder"));
0492     help.append("[$x-y]" + TokenHelpDialog::getTokenSeparator() + i18n("character x to y of old filename"));
0493     help.append("[$x;y]" + TokenHelpDialog::getTokenSeparator() + i18n("y characters of old filename starting at x"));
0494     help.append("[$dirname]" + TokenHelpDialog::getTokenSeparator() + i18n("insert name of folder"));
0495     help.append("[$dirname.]" + TokenHelpDialog::getTokenSeparator() + i18n("insert name of parent folder"));
0496     help.append("[dirsep]" + TokenHelpDialog::getTokenSeparator() + i18n("insert a '/' to create a new subfolder (useful from within regular expressions)"));
0497     help.append("[#length-0]" + TokenHelpDialog::getTokenSeparator() + i18n("insert the length of the input filename"));
0498     help.append("[trimmed]" + TokenHelpDialog::getTokenSeparator() + i18n("strip whitespaces leading and trailing"));
0499     help.append("[trimmed;.*]" + TokenHelpDialog::getTokenSeparator() + i18n("strip whitespaces leading and trailing of an arbitrary string"));
0500     dialog.add(i18n("Built-in Functions"), help, SmallIcon("krename"), true);
0501 
0502     help.clear();
0503     help.append("\\$" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '$'"));
0504     help.append("\\%" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '%'"));
0505     help.append("\\&" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '&'"));
0506     help.append("\\*" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '*'"));
0507     help.append("\\/" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '/'"));
0508     help.append("\\\\" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '\\\\'"));
0509     help.append("\\[" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '['"));
0510     help.append("\\]" + TokenHelpDialog::getTokenSeparator() + i18n("Insert ']'"));
0511     help.append("\\#" + TokenHelpDialog::getTokenSeparator() + i18n("Insert '#'"));
0512     dialog.add(i18n("Special Characters"), help, SmallIcon("krename"));
0513 
0514     // add plugin tokens
0515     QList<Plugin *>::const_iterator it = m_pluginLoader->plugins().begin();
0516     while (it != m_pluginLoader->plugins().end()) {
0517         help.clear();
0518         help = (*it)->help();
0519         if (!help.isEmpty()) {
0520             dialog.add((*it)->name(), help, (*it)->icon());
0521         }
0522 
0523         ++it;
0524     }
0525 
0526     dialog.exec();
0527 }
0528 
0529 void KRenameImpl::slotExtensionSplitModeChanged(ESplitMode splitMode, int dot)
0530 {
0531     // only change the splitMode if it has really change since the last time
0532     if (splitMode != m_lastSplitMode ||
0533             dot != m_lastDot) {
0534         KRenameFile::List::iterator it = m_vector.begin();
0535 
0536         while (it != m_vector.end()) {
0537             (*it).setCurrentSplitMode(splitMode, dot);
0538             ++it;
0539         }
0540 
0541         slotUpdatePreview();
0542     }
0543 
0544     m_lastSplitMode = splitMode;
0545     m_lastDot       = dot;
0546 
0547     m_model->setExtensionSplitMode(m_lastSplitMode, m_lastDot);
0548 }
0549 
0550 void KRenameImpl::slotStart()
0551 {
0552     ProgressDialog *progress = new ProgressDialog(m_lastSplitMode, m_lastDot);
0553     progress->print(i18np("Starting conversion of %1 file.", "Starting conversion of %1 files.", m_vector.count()));
0554 
0555     // Get some properties from the gui and initialize BatchRenamer
0556     const QUrl &destination = m_window->destinationUrl();
0557     if (m_renamer.renameMode() != eRenameMode_Rename) {
0558         KIO::StatJob *statJob = KIO::stat(destination, KIO::StatJob::DestinationSide, 0);
0559         statJob->exec();
0560         if (statJob->error() == KIO::ERR_DOES_NOT_EXIST) {
0561             int m = KMessageBox::warningContinueCancel(m_window, i18n("The folder %1 does not exist. "
0562                     "Do you want KRename to create it for you?",
0563                     destination.toDisplayString(QUrl::PreferLocalFile)));
0564             if (m == KMessageBox::Cancel) {
0565                 return;
0566             }
0567 
0568             KIO::MkdirJob *job = KIO::mkdir(destination);
0569             KJobWidgets::setWindow(job, m_window);
0570             if (!job->exec()) {
0571                 KMessageBox::error(m_window, i18n("The folder %1 could not be created.", destination.toDisplayString(QUrl::PreferLocalFile)));
0572                 return;
0573             }
0574         }
0575     }
0576 
0577     m_renamer.setDestinationDir(destination);
0578 
0579     // save the configuration
0580     // requires access to the window
0581     saveConfig();
0582 
0583     // Make sure the GUI will not delete our models
0584     m_window->setModel(nullptr);
0585     m_window->setPreviewModel(nullptr);
0586 
0587     // show the progress dialog
0588     progress->show();
0589     progress->raise();
0590     progress->activateWindow();
0591 
0592     // delete the GUI
0593     //delete m_window;
0594     //m_window = NULL;
0595     m_window->hide();
0596     m_window = nullptr;
0597 
0598     // Process files with additional properties which were not
0599     // necessary or available in the preview
0600     m_renamer.processFilenames();
0601 
0602     // Do the actual renaming
0603     m_renamer.processFiles(progress);
0604 
0605     // We are done - ProgressDialog will restart us if necessary
0606     //delete this;
0607 }
0608 
0609 void KRenameImpl::loadConfig()
0610 {
0611     KSharedConfigPtr config = KSharedConfig::openConfig();
0612 
0613     KConfigGroup groupGui = config->group(QString("GUISettings"));
0614     //groupGui.readEntry( "firststart4", QVariant(true) ).toBool();
0615     m_window->setPreviewEnabled(
0616         groupGui.readEntry("ImagePreview2", QVariant(true)).toBool());
0617 
0618     m_window->setPreviewNamesEnabled(
0619         groupGui.readEntry("ImagePreviewName2", QVariant(true)).toBool());
0620 
0621     KRenameFile::setIconSize(groupGui.readEntry("ImagePreviewSize", QVariant(64)).toInt());
0622 
0623     m_window->setAdvancedMode(
0624         groupGui.readEntry("Advanced", QVariant(false)).toBool());
0625 
0626     int index = groupGui.readEntry("StartIndex", QVariant(1)).toInt();
0627     int step  = groupGui.readEntry("Stepping", QVariant(1)).toInt();
0628 
0629     m_renamer.setNumberStepping(step);
0630     // Will call batch renamer
0631     m_window->setNumberStartIndex(index);
0632 
0633     int sortMode = groupGui.readEntry("FileListSorting", QVariant(0)).toInt();
0634     QString customToken = groupGui.readEntry("FileListSortingCustomToken",
0635                           m_model->getSortModeCustomToken());
0636     int customSortModel = groupGui.readEntry("FileListSortingCustomMode",
0637                           QVariant(static_cast<int>(m_model->getSortModeCustomMode()))).toInt();
0638 
0639     m_window->setSortMode(sortMode, customToken, customSortModel);
0640 
0641     ESplitMode lastSplitMode = static_cast<ESplitMode>(groupGui.readEntry("ExtensionSplitMode", static_cast<int>(m_lastSplitMode)));
0642     int lastDot = groupGui.readEntry("ExtensionSplitDot", m_lastDot);
0643     m_window->setExtensionSplitMode(lastSplitMode, lastDot);
0644     this->slotExtensionSplitModeChanged(lastSplitMode, lastDot);
0645 
0646     // load Plugin configuration
0647     KConfigGroup groupPlugins = config->group(QString("PluginSettings"));
0648     m_pluginLoader->loadConfig(groupPlugins);
0649 
0650     m_window->loadConfig();
0651 }
0652 
0653 void KRenameImpl::saveConfig()
0654 {
0655     // Me might get a saveConfig signal because of signals and slots
0656     // even if m_window was already delted. So ignore these events
0657     if (!m_window) {
0658         return;
0659     }
0660 
0661     m_window->saveConfig();
0662 
0663     KSharedConfigPtr config = KSharedConfig::openConfig();
0664 
0665     KConfigGroup groupGui = config->group(QString("GUISettings"));
0666     groupGui.writeEntry("firststart4", false);
0667     groupGui.writeEntry("ImagePreview2", m_window->isPreviewEnabled());
0668     groupGui.writeEntry("ImagePreviewName2", m_window->isPreviewNamesEnabled());
0669     groupGui.writeEntry("StartIndex", m_window->numberStartIndex());
0670     groupGui.writeEntry("Stepping", m_renamer.numberStepping());
0671     groupGui.writeEntry("FileListSorting", m_window->sortMode());
0672     groupGui.writeEntry("FileListSortingCustomToken", m_model->getSortModeCustomToken());
0673     groupGui.writeEntry("FileListSortingCustomMode", static_cast<int>(m_model->getSortModeCustomMode()));
0674     groupGui.writeEntry("Advanced", m_window->isAdvancedMode());
0675     groupGui.writeEntry("ExtensionSplitMode", static_cast<int>(m_lastSplitMode));
0676     groupGui.writeEntry("ExtensionSplitDot", m_lastDot);
0677 
0678     // save Plugin configuration
0679     KConfigGroup groupPlugins = config->group(QString("PluginSettings"));
0680     m_pluginLoader->saveConfig(groupPlugins);
0681 
0682     config->sync();
0683 }
0684