File indexing completed on 2022-09-27 16:33:52

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