File indexing completed on 2022-11-29 20:25:15

0001 /***************************************************************************
0002                        krenamewindow.cpp  -  description
0003                              -------------------
0004     begin                : Sat Mar 24 2007
0005     copyright            : (C) 2007 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 "krenamewindow.h"
0019 
0020 #include "krenamemodel.h"
0021 #include "plugin.h"
0022 #include "pluginloader.h"
0023 #include "richtextitemdelegate.h"
0024 #include "startupinfo.h"
0025 #include "tokensortmodedialog.h"
0026 
0027 #include "ui_krenamefiles.h"
0028 #include "ui_krenamedestination.h"
0029 //#include "ui_krenamesimple.h"
0030 #include "ui_krenameplugins.h"
0031 #include "ui_krenamefilename.h"
0032 
0033 #include <QAction>
0034 #include <QIcon>
0035 #include <QMenu>
0036 #include <QPushButton>
0037 #include <kseparator.h>
0038 
0039 #include <QDialogButtonBox>
0040 #include <QStackedWidget>
0041 #include <QTabBar>
0042 #include <QVBoxLayout>
0043 
0044 #include <KHelpMenu>
0045 
0046 static const KRenameWindow::TGuiMode tAdvancedMode = {
0047     4,
0048     {
0049         I18N_NOOP("&1. Files"),
0050         I18N_NOOP("&2. Destination"),
0051         I18N_NOOP("&3. Plugins"),
0052         I18N_NOOP("&4. Filename")
0053     },
0054     {
0055         0, 1, 2, 3
0056     },
0057     {
0058         "document-open-folder",
0059         "document-save",
0060         "configure",
0061         "edit-rename"
0062     }
0063 };
0064 
0065 KRenameWindow::KRenameWindow(QWidget *parent)
0066     : KMainWindow(parent),
0067       m_curPage(0), m_guiMode(nullptr),
0068       m_fileCount(0)
0069 {
0070     QWidget     *center = new QWidget();
0071     QVBoxLayout *layout = new QVBoxLayout(center);
0072 
0073     m_delegate = new RichTextItemDelegate(this);
0074     m_tabBar  = new QTabBar(center);
0075     m_stack   = new QStackedWidget(center);
0076     m_buttons = new QDialogButtonBox(center);
0077 
0078     layout->addWidget(m_tabBar);
0079     layout->addWidget(m_stack);
0080     layout->addWidget(new KSeparator(Qt::Horizontal, center));
0081     layout->addWidget(m_buttons);
0082     layout->setStretchFactor(m_stack, 2);
0083 
0084     this->setCentralWidget(center);
0085 
0086     for (int i = 0; i < tAdvancedMode.numPages; i++) {
0087         const QIcon &icon = QIcon::fromTheme(tAdvancedMode.pageIcons[i]);
0088         m_tabBar->addTab(icon, i18n(tAdvancedMode.pageTitles[i]));
0089     }
0090 
0091     m_pageFiles    = new Ui::KRenameFiles();
0092     m_pageDests    = new Ui::KRenameDestination();
0093     m_pagePlugins  = new Ui::KRenamePlugins();
0094     m_pageFilename = new Ui::KRenameFilename();
0095 
0096     // add files page
0097     QWidget *page = new QWidget(m_stack);
0098     m_pageFiles->setupUi(page);
0099     m_stack->addWidget(page);
0100 
0101     // add destination page
0102     page = new QWidget(m_stack);
0103     m_pageDests->setupUi(page);
0104     m_stack->addWidget(page);
0105 
0106     // add plugin page
0107     page = new QWidget(m_stack);
0108     m_pagePlugins->setupUi(page);
0109     m_stack->addWidget(page);
0110 
0111     // add filename page
0112     page = new QWidget(m_stack);
0113     m_pageFilename->setupUi(page);
0114     m_stack->addWidget(page);
0115 
0116     setupGui();
0117     setupPlugins();
0118     setupIcons();
0119 
0120     StartUpInfo *startUp = new StartUpInfo();
0121     connect(startUp, &StartUpInfo::addFiles, this, &KRenameWindow::addFiles);
0122     connect(startUp, &StartUpInfo::enterTemplate,
0123             this, &KRenameWindow::slotGotoTemplatesPage);
0124 
0125     m_pageDests->urlrequester->setMode(KFile::Directory | KFile::ExistingOnly);
0126     m_pageFiles->fileList->setItemDelegate(m_delegate);
0127     m_pageFiles->fileList->setInfoWidget(startUp);
0128 
0129     // Make sure that now signal occurs before setupGui was called
0130     connect(m_tabBar, &QTabBar::currentChanged,
0131             this, &KRenameWindow::showPage);
0132     connect(m_buttonClose, &QPushButton::clicked,
0133             this, &KRenameWindow::close);
0134     connect(m_buttons, &QDialogButtonBox::accepted,
0135             this, &KRenameWindow::slotFinish);
0136 
0137     this->setAutoSaveSettings("KRenameWindowSettings", true);
0138 
0139     // If there is a huge entry in the history of filenameTemplate that size
0140     // apparently gets used as minimal size of the window. Setting it to some
0141     // value here works around that.
0142     // https://bugs.kde.org/show_bug.cgi?id=398980
0143     // TODO: Find a solution without a magic number
0144     setMinimumWidth(200);
0145 
0146     // Show the first page in any mode
0147     showPage(0);
0148 }
0149 
0150 KRenameWindow::~KRenameWindow()
0151 {
0152 }
0153 
0154 void KRenameWindow::loadConfig()
0155 {
0156     // ExtHistoryCombo needs an object name
0157     m_pageFilename->filenameTemplate->setObjectName("FILENAME_TEMPLATE");
0158     m_pageFilename->extensionTemplate->setObjectName("EXTENSION_TEMPLATE");
0159     m_pageFilename->comboFilenameCustom->setObjectName("FILENAME_CUSTOM_TEMPLATE");
0160     m_pageFilename->comboExtensionCustom->setObjectName("EXTENSION_CUSTOM_TEMPLATE");
0161     m_pageFilename->comboPrefixCustom->setObjectName("PREVIX_CUSTOM_TEMPLATE");
0162     m_pageFilename->comboSuffixCustom->setObjectName("SUFFIX_CUSTOM_TEMPLATE");
0163 
0164     m_pageFilename->filenameTemplate->loadConfig();
0165     m_pageFilename->extensionTemplate->loadConfig();
0166     m_pageFilename->comboFilenameCustom->loadConfig();
0167     m_pageFilename->comboExtensionCustom->loadConfig();
0168     m_pageFilename->comboPrefixCustom->loadConfig();
0169     m_pageFilename->comboSuffixCustom->loadConfig();
0170 
0171     KSharedConfigPtr config = KSharedConfig::openConfig();
0172     KConfigGroup groupGui = config->group(QString("GUISettings"));
0173 
0174     int width = groupGui.readEntry("Column0", QVariant(this->previewColumnWidth(0))).toInt();
0175     if (width > 0) {
0176         this->setPreviewColumnWidth(0, width);
0177     }
0178 
0179     width = groupGui.readEntry("Column1", QVariant(this->previewColumnWidth(1))).toInt();
0180     if (width > 0) {
0181         this->setPreviewColumnWidth(1, width);
0182     }
0183 }
0184 
0185 void KRenameWindow::saveConfig()
0186 {
0187     m_pageFilename->filenameTemplate->saveConfig();
0188     m_pageFilename->extensionTemplate->saveConfig();
0189     m_pageFilename->comboFilenameCustom->saveConfig();
0190     m_pageFilename->comboExtensionCustom->saveConfig();
0191     m_pageFilename->comboPrefixCustom->saveConfig();
0192     m_pageFilename->comboSuffixCustom->saveConfig();
0193 
0194     KSharedConfigPtr config = KSharedConfig::openConfig();
0195     KConfigGroup groupGui = config->group(QString("GUISettings"));
0196 
0197     groupGui.writeEntry("Column0", this->previewColumnWidth(0));
0198     groupGui.writeEntry("Column1", this->previewColumnWidth(1));
0199 }
0200 
0201 void KRenameWindow::setupGui()
0202 {
0203     m_buttons->clear();
0204 
0205     m_guiMode    = &tAdvancedMode;
0206 
0207     m_buttonFinish = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-ok")),    i18n("&Finish"));
0208 
0209     m_buttons->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Close);
0210     m_buttons->addButton(m_buttonFinish, QDialogButtonBox::AcceptRole);
0211     m_buttonClose = m_buttons->button(QDialogButtonBox::Close);
0212     m_buttonClose->setShortcut(QKeySequence(QKeySequence::Quit));
0213 
0214     KHelpMenu *helpMenu = new KHelpMenu(this, QString(), false);
0215     helpMenu->menu()->removeAction(helpMenu->action(KHelpMenu::menuHelpContents));
0216     m_buttons->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu());
0217 
0218     setupSlots();
0219     slotEnableControls();
0220 }
0221 
0222 void KRenameWindow::setupPlugins()
0223 {
0224     PluginLoader *loader = PluginLoader::Instance();
0225 
0226     const QList<Plugin *> &list = loader->plugins();
0227     QList<Plugin *>::const_iterator it = list.begin();
0228 
0229     m_pluginsWidgetHash.reserve(list.count());
0230     m_pluginsHash.reserve(list.count());
0231 
0232     m_pagePlugins->searchPlugins->searchLine()->setTreeWidget(m_pagePlugins->listPlugins);
0233 
0234     while (it != list.end()) {
0235         // create plugin gui
0236         QWidget *widget = new QWidget(m_pagePlugins->stackPlugins);
0237         (*it)->createUI(widget);
0238         int idx = m_pagePlugins->stackPlugins->addWidget(widget);
0239         m_pagePlugins->stackPlugins->setCurrentIndex(idx);
0240 
0241         m_pluginsHash[(*it)->name()] = (*it);
0242         m_pluginsWidgetHash[(*it)->name()] = widget;
0243 
0244         // add to list of all plugins
0245         QTreeWidgetItem *item = new QTreeWidgetItem(m_pagePlugins->listPlugins);
0246         item->setText(0, (*it)->name());
0247         item->setIcon(0, (*it)->icon());
0248 
0249         slotPluginChanged(item);
0250 
0251         ++it;
0252     }
0253 
0254     m_pagePlugins->splitter->setStretchFactor(0, 0);
0255     m_pagePlugins->splitter->setStretchFactor(1, 8);
0256     m_pagePlugins->listPlugins->sortColumn();
0257 }
0258 
0259 void KRenameWindow::setupIcons()
0260 {
0261     QPixmap upIcon = QIcon::fromTheme("arrow-up").pixmap(KIconLoader::SizeSmall);
0262     QPixmap downIcon = QIcon::fromTheme("arrow-down").pixmap(KIconLoader::SizeSmall);
0263 
0264     // Page 1 icons
0265 
0266     QPixmap openIcon = QIcon::fromTheme("document-open").pixmap(KIconLoader::SizeSmall);
0267     QPixmap removeIcon = QIcon::fromTheme("list-remove").pixmap(KIconLoader::SizeSmall);
0268 
0269     m_pageFiles->buttonAdd->setIcon(openIcon);
0270     m_pageFiles->buttonRemove->setIcon(removeIcon);
0271     m_pageFiles->buttonUp->setIcon(upIcon);
0272     m_pageFiles->buttonDown->setIcon(downIcon);
0273 
0274     // Page 4 icons
0275 
0276     QPixmap helpIcon = QIcon::fromTheme("help-hint").pixmap(KIconLoader::SizeSmall);
0277     QPixmap findIcon = QIcon::fromTheme("edit-find").pixmap(KIconLoader::SizeSmall);
0278 
0279     m_pageFilename->buttonHelp1->setIcon(helpIcon);
0280     m_pageFilename->buttonHelp2->setIcon(helpIcon);
0281     m_pageFilename->buttonHelp3->setIcon(helpIcon);
0282     m_pageFilename->buttonHelp4->setIcon(helpIcon);
0283     m_pageFilename->buttonFunctions->setIcon(helpIcon);
0284 
0285     m_pageFilename->buttonFind->setIcon(findIcon);
0286     m_pageFilename->buttonFindSimple->setIcon(findIcon);
0287 
0288     m_pageFilename->buttonUp->setIcon(upIcon);
0289     m_pageFilename->buttonDown->setIcon(downIcon);
0290 
0291 }
0292 
0293 void KRenameWindow::setupSlots()
0294 {
0295     connect(m_pageFiles->buttonAdd, &QPushButton::clicked,
0296             this, &KRenameWindow::addFiles);
0297     connect(m_pageFiles->buttonRemove, &QPushButton::clicked,
0298             this, &KRenameWindow::removeFiles);
0299     connect(m_pageFiles->buttonRemoveAll, &QPushButton::clicked,
0300             this, &KRenameWindow::removeAllFiles);
0301     connect(m_pageFiles->checkPreview, &QCheckBox::clicked,
0302             this, &KRenameWindow::slotPreviewChanged);
0303     connect(m_pageFiles->checkName, &QCheckBox::clicked,
0304             this, &KRenameWindow::slotPreviewChanged);
0305     connect(m_pageFiles->comboSort, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0306             this, &KRenameWindow::slotSortChanged);
0307     connect(m_pageFiles->fileList, &KRenameListView::doubleClicked,
0308             this, &KRenameWindow::slotOpenFile);
0309     connect(m_pageFiles->buttonUp, &QPushButton::clicked,
0310             this, &KRenameWindow::slotMoveUp);
0311     connect(m_pageFiles->buttonDown, &QPushButton::clicked,
0312             this, &KRenameWindow::slotMoveDown);
0313 
0314     connect(m_pageDests->optionRename, &QRadioButton::clicked,
0315             this, &KRenameWindow::slotRenameModeChanged);
0316     connect(m_pageDests->optionCopy, &QRadioButton::clicked,
0317             this, &KRenameWindow::slotRenameModeChanged);
0318     connect(m_pageDests->optionMove, &QRadioButton::clicked,
0319             this, &KRenameWindow::slotRenameModeChanged);
0320     connect(m_pageDests->optionLink, &QRadioButton::clicked,
0321             this, &KRenameWindow::slotRenameModeChanged);
0322     connect(m_pageDests->checkOverwrite, &QCheckBox::clicked,
0323             this, &KRenameWindow::overwriteFilesChanged);
0324 
0325     connect(m_pagePlugins->listPlugins, &QTreeWidget::currentItemChanged,
0326             this, &KRenameWindow::slotPluginChanged);
0327     connect(m_pagePlugins->checkEnablePlugin, &QCheckBox::clicked,
0328             this, &KRenameWindow::slotPluginEnabled);
0329 
0330     connect(m_pageFilename->checkExtension, &QCheckBox::clicked,
0331             this, &KRenameWindow::slotEnableControls);
0332     connect(m_pageFilename->buttonNumbering, &QPushButton::clicked,
0333             this, &KRenameWindow::showAdvancedNumberingDialog);
0334     connect(m_pageFilename->buttonInsert, &QPushButton::clicked,
0335             this, &KRenameWindow::showInsertPartFilenameDialog);
0336     connect(m_pageFilename->buttonFind, &QPushButton::clicked,
0337             this, &KRenameWindow::showFindReplaceDialog);
0338 
0339     connect(m_pageFilename->filenameTemplate, &ExtHistoryCombo::delayedTextChanged,
0340             this, &KRenameWindow::slotTemplateChanged);
0341     connect(m_pageFilename->extensionTemplate, &ExtHistoryCombo::delayedTextChanged,
0342             this, &KRenameWindow::slotTemplateChanged);
0343     connect(m_pageFilename->checkExtension, &QCheckBox::clicked,
0344             this, &KRenameWindow::slotTemplateChanged);
0345     connect(m_pageFilename->buttonFunctions, &QPushButton::clicked,
0346             this, &KRenameWindow::slotTokenHelpRequested);
0347     connect(m_pageFilename->comboExtension, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0348             this, &KRenameWindow::slotExtensionSplitModeChanged);
0349 
0350     connect(m_pageFilename->buttonUp, &QPushButton::clicked,
0351             this, &KRenameWindow::slotMoveUpPreview);
0352     connect(m_pageFilename->buttonDown, &QPushButton::clicked,
0353             this, &KRenameWindow::slotMoveDownPreview);
0354 
0355     connect(m_pageFilename->listPreview, &PreviewList::addFiles,
0356             this, &KRenameWindow::addFiles);
0357     connect(m_pageFilename->listPreview, &PreviewList::updateCount,
0358             this, &KRenameWindow::updateCount);
0359 
0360     connect(m_pageFilename->comboFilenameCustom, &ExtHistoryCombo::delayedTextChanged,
0361             this, &KRenameWindow::slotSimpleTemplateChanged);
0362     connect(m_pageFilename->comboSuffixCustom, &ExtHistoryCombo::delayedTextChanged,
0363             this, &KRenameWindow::slotSimpleTemplateChanged);
0364     connect(m_pageFilename->comboPrefixCustom, &ExtHistoryCombo::delayedTextChanged,
0365             this, &KRenameWindow::slotSimpleTemplateChanged);
0366     connect(m_pageFilename->comboExtensionCustom, &ExtHistoryCombo::delayedTextChanged,
0367             this, &KRenameWindow::slotSimpleTemplateChanged);
0368 
0369     connect(m_pageFilename->comboPrefix, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0370             this, &KRenameWindow::slotSimpleTemplateChanged);
0371     connect(m_pageFilename->comboSuffix, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0372             this, &KRenameWindow::slotSimpleTemplateChanged);
0373     connect(m_pageFilename->comboFilenameSimple, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0374             this, &KRenameWindow::slotSimpleTemplateChanged);
0375     connect(m_pageFilename->comboExtensionSimple, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0376             this, &KRenameWindow::slotSimpleTemplateChanged);
0377 
0378     connect(m_pageFilename->comboExtensionSimple, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0379             this, &KRenameWindow::slotEnableControls);
0380     connect(m_pageFilename->comboFilenameSimple, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
0381             this, &KRenameWindow::slotEnableControls);
0382 
0383     connect(m_pageFilename->buttonHelp1, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard1);
0384     connect(m_pageFilename->buttonHelp2, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard2);
0385     connect(m_pageFilename->buttonHelp3, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard3);
0386     connect(m_pageFilename->buttonHelp4, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard4);
0387     connect(m_pageFilename->buttonFindSimple, &QPushButton::clicked,
0388             this, &KRenameWindow::showFindReplaceDialog);
0389 
0390     connect(m_pageFilename->spinDigits, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
0391             this, &KRenameWindow::slotSimpleTemplateChanged);
0392     connect(m_pageFilename->spinIndex, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
0393             this, &KRenameWindow::slotSimpleStartIndexChanged);
0394 }
0395 
0396 void KRenameWindow::showPage(int index)
0397 {
0398     if (index >= 0 && index < m_guiMode->numPages) {
0399         m_curPage = index;
0400         m_stack->setCurrentIndex(m_guiMode->mapIndex[index]);
0401 
0402         slotEnableControls();
0403     }
0404 }
0405 
0406 void KRenameWindow::slotEnableControls()
0407 {
0408     // TODO:
0409     // Disable all extension widgets
0410     // if splitMode is NOEXTENSION
0411 
0412     if (m_buttonFinish) {
0413         bool enable = (m_curPage == m_guiMode->numPages - 1)
0414                       && m_fileCount > 0;
0415         m_buttonFinish->setEnabled(enable);
0416     }
0417 
0418     // enable gui controls
0419     m_pageFiles->buttonRemove->setEnabled(m_fileCount);
0420     m_pageFiles->buttonRemoveAll->setEnabled(m_fileCount);
0421     m_pageFiles->checkName->setEnabled(m_pageFiles->checkPreview->isChecked());
0422 
0423     m_pageFiles->buttonUp->setEnabled(m_fileCount);
0424     m_pageFiles->buttonDown->setEnabled(m_fileCount);
0425 
0426     m_pageDests->urlrequester->setEnabled(!m_pageDests->optionRename->isChecked());
0427 
0428     m_pageFilename->extensionTemplate->setEnabled(!m_pageFilename->checkExtension->isChecked());
0429     m_pageFilename->buttonFind->setEnabled(m_fileCount != 0);
0430     m_pageFilename->buttonNumbering->setEnabled(m_fileCount != 0);
0431     m_pageFilename->buttonInsert->setEnabled(m_fileCount != 0);
0432 
0433     m_pageFilename->buttonFindSimple->setEnabled(m_fileCount != 0);
0434     m_pageFilename->buttonHelp3->setEnabled(m_pageFilename->comboFilenameSimple->currentIndex() ==
0435                                             m_pageFilename->comboFilenameSimple->count() - 1);
0436     m_pageFilename->comboFilenameCustom->setEnabled(m_pageFilename->comboFilenameSimple->currentIndex() ==
0437             m_pageFilename->comboFilenameSimple->count() - 1);
0438 
0439     m_pageFilename->buttonHelp4->setEnabled(m_pageFilename->comboExtensionSimple->currentIndex() ==
0440                                             m_pageFilename->comboExtensionSimple->count() - 1);
0441     m_pageFilename->comboExtensionCustom->setEnabled(m_pageFilename->comboExtensionSimple->currentIndex() ==
0442             m_pageFilename->comboExtensionSimple->count() - 1);
0443 
0444     m_pageFilename->buttonUp->setEnabled(m_fileCount);
0445     m_pageFilename->buttonDown->setEnabled(m_fileCount);
0446 }
0447 
0448 void KRenameWindow::setCount(unsigned int count)
0449 {
0450     m_fileCount = count;
0451     m_pageFiles->labelCount->setText(i18n("<b>Files:</b> %1", m_fileCount));
0452 
0453     m_pageFiles->fileList->slotUpdateCount();
0454     this->slotEnableControls();
0455 }
0456 
0457 void KRenameWindow::setFilenameTemplate(const QString &templ, bool insert)
0458 {
0459     if (insert) {
0460         m_pageFilename->filenameTemplate->lineEdit()->insert(templ);
0461     } else {
0462         m_pageFilename->filenameTemplate->lineEdit()->setText(templ);
0463     }
0464 }
0465 
0466 void KRenameWindow::setExtensionTemplate(const QString &templ, bool insert)
0467 {
0468     m_pageFilename->checkExtension->setChecked(true);
0469     m_pageFilename->comboExtensionSimple->setCurrentIndex(
0470         m_pageFilename->comboExtensionSimple->count() - 1);
0471 
0472     if (insert) {
0473         m_pageFilename->extensionTemplate->lineEdit()->insert(templ);
0474     } else {
0475         m_pageFilename->extensionTemplate->lineEdit()->setText(templ);
0476     }
0477 }
0478 
0479 void KRenameWindow::setRenameMode(ERenameMode eMode)
0480 {
0481     m_pageDests->optionRename->setChecked(false);
0482     m_pageDests->optionCopy->setChecked(false);
0483     m_pageDests->optionMove->setChecked(false);
0484     m_pageDests->optionLink->setChecked(false);
0485 
0486     switch (eMode) {
0487     case eRenameMode_Rename:
0488         m_pageDests->optionRename->setChecked(true);
0489         break;
0490     case eRenameMode_Copy:
0491         m_pageDests->optionCopy->setChecked(true);
0492         break;
0493     case eRenameMode_Move:
0494         m_pageDests->optionMove->setChecked(true);
0495         break;
0496     case eRenameMode_Link:
0497         m_pageDests->optionLink->setChecked(true);
0498         break;
0499     default:
0500         // Default
0501         m_pageDests->optionRename->setChecked(true);
0502         break;
0503     }
0504 
0505     this->slotEnableControls();
0506     emit renameModeChanged(eMode);
0507 }
0508 
0509 void KRenameWindow::setDestinationUrl(const QUrl &url)
0510 {
0511     m_pageDests->urlrequester->setUrl(url);
0512 }
0513 
0514 void KRenameWindow::resetFileList()
0515 {
0516     m_pageFiles->fileList->reset();
0517 }
0518 
0519 void KRenameWindow::setModel(KRenameModel *model)
0520 {
0521     m_pageFiles->fileList->setModel(model);
0522 
0523     m_pageFilename->listPreview->setKRenameModel(model);
0524 
0525     connect(model, &KRenameModel::maxDotsChanged,
0526             this, &KRenameWindow::slotMaxDotsChanged);
0527 }
0528 
0529 void KRenameWindow::setPreviewModel(KRenamePreviewModel *model)
0530 {
0531     m_pageFilename->listPreview->setModel(model);
0532 }
0533 
0534 const QUrl KRenameWindow::destinationUrl() const
0535 {
0536     return m_pageDests->urlrequester->url();
0537 }
0538 
0539 QList<int> KRenameWindow::selectedFileItems() const
0540 {
0541     QList<int> selected;
0542 
0543     QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel();
0544     QModelIndexList      indices = selection->selectedIndexes();
0545     QModelIndexList::const_iterator it = indices.constBegin();
0546 
0547     while (it != indices.constEnd()) {
0548         selected.append((*it).row());
0549         ++it;
0550     }
0551 
0552     return selected;
0553 }
0554 
0555 QList<int> KRenameWindow::selectedFileItemsPreview() const
0556 {
0557     QList<int> selected;
0558 
0559     QItemSelectionModel *selection = m_pageFilename->listPreview->selectionModel();
0560 
0561     QModelIndexList      indices = selection->selectedIndexes();
0562     QModelIndexList::const_iterator it = indices.constBegin();
0563 
0564     while (it != indices.constEnd()) {
0565         selected.append((*it).row());
0566         ++it;
0567     }
0568 
0569     return selected;
0570 }
0571 
0572 bool KRenameWindow::isPreviewEnabled() const
0573 {
0574     return m_pageFiles->checkPreview->isChecked();
0575 }
0576 
0577 void KRenameWindow::setPreviewEnabled(bool bPreview)
0578 {
0579     m_pageFiles->checkPreview->setChecked(bPreview);
0580 
0581     slotPreviewChanged();
0582 }
0583 
0584 bool KRenameWindow::isPreviewNamesEnabled() const
0585 {
0586     return m_pageFiles->checkName->isChecked();
0587 }
0588 
0589 void KRenameWindow::setPreviewNamesEnabled(bool bPreview)
0590 {
0591     m_pageFiles->checkName->setChecked(bPreview);
0592 
0593     slotPreviewChanged();
0594 }
0595 
0596 int KRenameWindow::numberStartIndex() const
0597 {
0598     return m_pageFilename->spinIndex->value();
0599 }
0600 
0601 void KRenameWindow::setNumberStartIndex(int index)
0602 {
0603     m_pageFilename->spinIndex->setValue(index);
0604 }
0605 
0606 int KRenameWindow::sortMode() const
0607 {
0608     return m_pageFiles->comboSort->currentIndex();
0609 }
0610 
0611 void KRenameWindow::setSortMode(int sortMode, const QString &customToken, int customSortMode)
0612 {
0613     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
0614     bool bPrevious = m_pageFiles->comboSort->blockSignals(true);
0615 
0616     QString customTokenText;
0617     if (sortMode == eSortMode_Token) {
0618         customTokenText = customToken;
0619     }
0620 
0621     m_pageFiles->comboSort->setCurrentIndex(sortMode);
0622     m_pageFiles->labelCustomSort->setText(customTokenText);
0623 
0624     model->sortFiles(static_cast<ESortMode>(sortMode),
0625                      customToken,
0626                      static_cast<KRenameTokenSorter::ESimpleSortMode>(customSortMode));
0627 
0628     m_pageFiles->comboSort->blockSignals(bPrevious);
0629 }
0630 
0631 int KRenameWindow::previewColumnWidth(int index)
0632 {
0633     return m_pageFilename->listPreview->columnWidth(index);
0634 }
0635 
0636 void KRenameWindow::setPreviewColumnWidth(int index, int width)
0637 {
0638     m_pageFilename->listPreview->setColumnWidth(index, width);
0639 }
0640 
0641 bool KRenameWindow::isAdvancedMode() const
0642 {
0643     return (m_pageFilename->tabWidget->currentIndex() == 0);
0644 }
0645 
0646 void KRenameWindow::setAdvancedMode(bool bAdvanced)
0647 {
0648     m_pageFilename->tabWidget->setCurrentIndex(bAdvanced ? 0 : 1);
0649 }
0650 
0651 void KRenameWindow::showFilenameTab()
0652 {
0653     m_tabBar->setCurrentIndex(MAX_PAGES - 1);
0654     if (this->isAdvancedMode()) {
0655         m_pageFilename->filenameTemplate->setFocus();
0656         m_pageFilename->filenameTemplate->selectAll();
0657     } else {
0658         m_pageFilename->comboPrefixCustom->setFocus();
0659         m_pageFilename->comboPrefixCustom->selectAll();
0660     }
0661 }
0662 
0663 void KRenameWindow::setPrefixSuffixSimple(QComboBox *combo, QComboBox *comboCustom, const QString &templ)
0664 {
0665     if (templ.isEmpty()) {
0666         comboCustom->lineEdit()->setText(templ);
0667         combo->setCurrentIndex(0);
0668     } else {
0669         QString number('#');
0670         int c = m_pageFilename->spinDigits->value() - 1;
0671 
0672         while (c-- > 0) {
0673             number += '#';
0674         }
0675 
0676         number += QString("{%1}").arg(m_pageFilename->spinIndex->value());
0677 
0678         if (templ.startsWith(number)) {
0679             QString value = templ.right(templ.length() - number.length());
0680             combo->setCurrentIndex(1);
0681             comboCustom->lineEdit()->setText(value);
0682         } else if (templ.startsWith(QLatin1String("[date]"))) {
0683             QString value = templ.right(templ.length() - 6);
0684             combo->setCurrentIndex(2);
0685             comboCustom->lineEdit()->setText(value);
0686         } else {
0687             combo->setCurrentIndex(0);
0688             comboCustom->lineEdit()->setText(templ);
0689         }
0690     }
0691 }
0692 
0693 QString KRenameWindow::getPrefixSuffixSimple(QComboBox *combo, QComboBox *comboCustom)
0694 {
0695     QString str;
0696     QString number('#');
0697     int c = m_pageFilename->spinDigits->value() - 1;
0698 
0699     while (c-- > 0) {
0700         number += '#';
0701     }
0702 
0703     number += QString("{%1}").arg(m_pageFilename->spinIndex->value());
0704 
0705     if (combo->currentIndex() == 1) {
0706         str = number;
0707     } else if (combo->currentIndex() == 2) {
0708         str = "[date]";    // TODO date
0709     }
0710 
0711     str += comboCustom->currentText();
0712 
0713     return str;
0714 }
0715 
0716 QString KRenameWindow::getFilenameSimple(QComboBox *combo, QComboBox *comboCustom)
0717 {
0718     QString str;
0719 
0720     // TODO: Replace strings with constants
0721     switch (combo->currentIndex()) {
0722     default:
0723     case 0:
0724         str = '$'; break;
0725     case 1:
0726         str = '%'; break;
0727     case 2:
0728         str = '&'; break;
0729     case 3:
0730         str = '*'; break;
0731     case 4:
0732         str = comboCustom->currentText();
0733     }
0734 
0735     return str;
0736 }
0737 
0738 void KRenameWindow::slotBack()
0739 {
0740     this->showPage(m_curPage - 1);
0741 }
0742 
0743 void KRenameWindow::slotNext()
0744 {
0745     this->showPage(m_curPage + 1);
0746 }
0747 
0748 void KRenameWindow::slotFinish()
0749 {
0750     emit accepted();
0751 }
0752 
0753 void KRenameWindow::slotRenameModeChanged()
0754 {
0755     ERenameMode mode = eRenameMode_Rename;
0756 
0757     if (m_pageDests->optionRename->isChecked()) {
0758         mode = eRenameMode_Rename;
0759     } else if (m_pageDests->optionCopy->isChecked()) {
0760         mode = eRenameMode_Copy;
0761     } else if (m_pageDests->optionMove->isChecked()) {
0762         mode = eRenameMode_Move;
0763     } else if (m_pageDests->optionLink->isChecked()) {
0764         mode = eRenameMode_Link;
0765     }
0766 
0767     emit renameModeChanged(mode);
0768 
0769     this->slotEnableControls();
0770 }
0771 
0772 void KRenameWindow::slotGotoTemplatesPage()
0773 {
0774     m_tabBar->setCurrentIndex(3);
0775 }
0776 
0777 void KRenameWindow::slotSimpleStartIndexChanged()
0778 {
0779     emit startIndexChanged(m_pageFilename->spinIndex->value());
0780 
0781     slotSimpleTemplateChanged();
0782 }
0783 
0784 void KRenameWindow::slotTemplateChanged()
0785 {
0786     QString filename;
0787     QString extension;
0788 
0789     filename  = m_pageFilename->filenameTemplate->currentText();
0790     extension = m_pageFilename->checkExtension->isChecked() ? "$" :
0791                 m_pageFilename->extensionTemplate->currentText();
0792 
0793     // set the new templates also for simple mode
0794     blockSignalsRecursive(this, true);
0795     this->setSimpleTemplate(filename, extension);
0796     blockSignalsRecursive(this, false);
0797 
0798     this->templatesChanged(filename, extension);
0799 }
0800 
0801 void KRenameWindow::slotSimpleTemplateChanged()
0802 {
0803     QString filename  = getFilenameSimple(m_pageFilename->comboFilenameSimple, m_pageFilename->comboFilenameCustom);
0804     QString extension = getFilenameSimple(m_pageFilename->comboExtensionSimple, m_pageFilename->comboExtensionCustom);
0805     QString prefix    = getPrefixSuffixSimple(m_pageFilename->comboPrefix, m_pageFilename->comboPrefixCustom);
0806     QString suffix    = getPrefixSuffixSimple(m_pageFilename->comboSuffix, m_pageFilename->comboSuffixCustom);
0807 
0808     filename = prefix + filename + suffix;
0809 
0810     // set the new templates, but make sure signals
0811     // are blockes so that slotTemplateChanged emits updatePreview()
0812     // which is calculation intensive only once!
0813     blockSignalsRecursive(this, true);
0814     m_pageFilename->filenameTemplate->lineEdit()->setText(filename);
0815     m_pageFilename->extensionTemplate->lineEdit()->setText(extension);
0816     m_pageFilename->checkExtension->setChecked(false);
0817     blockSignalsRecursive(this, false);
0818 
0819     this->templatesChanged(filename, extension);
0820 }
0821 
0822 void KRenameWindow::templatesChanged(const QString &filename, const QString &extension)
0823 {
0824     emit filenameTemplateChanged(filename);
0825     emit extensionTemplateChanged(extension);
0826 
0827     emit updatePreview();
0828 
0829     m_pageFilename->buttonNumbering->setEnabled(filename.contains('#') || extension.contains('#'));
0830     this->slotEnableControls();
0831 }
0832 
0833 void KRenameWindow::setSimpleTemplate(const QString &filename, const QString &extension)
0834 {
0835     // First set the simple extension from a template string
0836     if (extension == "$") {
0837         m_pageFilename->comboExtensionSimple->setCurrentIndex(0);
0838     } else if (extension == "%") {
0839         m_pageFilename->comboExtensionSimple->setCurrentIndex(1);
0840     } else if (extension == "&") {
0841         m_pageFilename->comboExtensionSimple->setCurrentIndex(2);
0842     } else if (extension == "*") {
0843         m_pageFilename->comboExtensionSimple->setCurrentIndex(3);
0844     } else {
0845         m_pageFilename->comboExtensionSimple->setCurrentIndex(4);
0846         m_pageFilename->comboExtensionCustom->lineEdit()->setText(extension);
0847     }
0848 
0849     // Now split the filename in prefix and suffix and set it as template
0850     // TODO: Make sure we do not find something like [*5-] or \$
0851     int index = 4;
0852     int pos   = filename.indexOf("$");
0853     if (pos == -1) {
0854         pos = filename.indexOf("%");
0855         if (pos == -1) {
0856             pos = filename.indexOf("&");
0857             if (pos == -1) {
0858                 pos = filename.indexOf("*");
0859                 if (pos != -1) {
0860                     index = 3;
0861                 }
0862             } else {
0863                 index = 2;
0864             }
0865         } else {
0866             index = 1;
0867         }
0868     } else {
0869         index = 0;
0870     }
0871 
0872     m_pageFilename->comboFilenameSimple->setCurrentIndex(index);
0873     if (pos == -1) {
0874         // No token found, so we have no prefix or suffix but
0875         // a custom name.
0876         m_pageFilename->comboPrefixCustom->lineEdit()->setText(QString());
0877         m_pageFilename->comboPrefix->setCurrentIndex(0);
0878 
0879         m_pageFilename->comboSuffixCustom->lineEdit()->setText(QString());
0880         m_pageFilename->comboSuffix->setCurrentIndex(0);
0881 
0882         m_pageFilename->comboFilenameCustom->lineEdit()->setText(filename);
0883     } else {
0884         QString prefix = (pos > 0 ? filename.left(pos) : QString());
0885         QString suffix = (pos < filename.length() ? filename.right(filename.length() - pos - 1) : QString());
0886 
0887         setPrefixSuffixSimple(m_pageFilename->comboPrefix, m_pageFilename->comboPrefixCustom, prefix);
0888         setPrefixSuffixSimple(m_pageFilename->comboSuffix, m_pageFilename->comboSuffixCustom, suffix);
0889     }
0890 }
0891 
0892 void KRenameWindow::slotTokenHelpRequested()
0893 {
0894     emit showTokenHelpDialog(m_pageFilename->filenameTemplate->lineEdit());
0895 }
0896 
0897 void KRenameWindow::slotTokenHelpRequestedWizard1()
0898 {
0899     emit showTokenHelpDialog(m_pageFilename->comboPrefixCustom->lineEdit());
0900 }
0901 
0902 void KRenameWindow::slotTokenHelpRequestedWizard2()
0903 {
0904     emit showTokenHelpDialog(m_pageFilename->comboSuffixCustom->lineEdit());
0905 }
0906 
0907 void KRenameWindow::slotTokenHelpRequestedWizard3()
0908 {
0909     emit showTokenHelpDialog(m_pageFilename->comboFilenameCustom->lineEdit());
0910 }
0911 
0912 void KRenameWindow::slotTokenHelpRequestedWizard4()
0913 {
0914     emit showTokenHelpDialog(m_pageFilename->comboExtensionCustom->lineEdit());
0915 }
0916 
0917 void KRenameWindow::setExtensionSplitMode(ESplitMode splitMode, int dot)
0918 {
0919     int index;
0920     switch (splitMode) {
0921     default:
0922     case eSplitMode_FirstDot:
0923         index = 0;
0924         break;
0925     case eSplitMode_LastDot:
0926         index = 1;
0927         break;
0928     case eSplitMode_NoExtension:
0929         index = 2;
0930         break;
0931     case eSplitMode_CustomDot:
0932         index = dot + 1;
0933         break;
0934     }
0935 
0936     m_pageFilename->comboExtension->setCurrentIndex(index);
0937 }
0938 
0939 void KRenameWindow::slotExtensionSplitModeChanged(int index)
0940 {
0941     ESplitMode splitMode;
0942     switch (index) {
0943     case 0:
0944         splitMode = eSplitMode_FirstDot;
0945         break;
0946     case 1:
0947         splitMode = eSplitMode_LastDot;
0948         break;
0949     case 2:
0950         splitMode = eSplitMode_NoExtension;
0951         break;
0952     default:
0953         splitMode = eSplitMode_CustomDot;
0954         break;
0955     }
0956 
0957     emit extensionSplitModeChanged(splitMode, index - 1);
0958 }
0959 
0960 void KRenameWindow::slotPreviewChanged()
0961 {
0962     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
0963 
0964     if (m_pageFiles->checkPreview->isChecked() && !m_pageFiles->checkName->isChecked()) {
0965         m_pageFiles->fileList->setViewMode(QListView::IconMode);
0966     } else {
0967         m_pageFiles->fileList->setViewMode(QListView::ListMode);
0968     }
0969 
0970     model->setEnablePreview(m_pageFiles->checkPreview->isChecked(), m_pageFiles->checkName->isChecked());
0971     emit filePreviewChanged(m_pageFiles->checkPreview->isChecked(), m_pageFiles->checkName->isChecked());
0972 
0973     m_pageFiles->fileList->setAcceptDrops(true);
0974     m_pageFiles->fileList->repaint();
0975     this->slotEnableControls();
0976 }
0977 
0978 void KRenameWindow::slotSortChanged(int index)
0979 {
0980     ESortMode eMode;
0981     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
0982     KRenameTokenSorter::ESimpleSortMode eCustomSortMode = model->getSortModeCustomMode();
0983     QString customToken;
0984 
0985     switch (index) {
0986     default:
0987     case 0:
0988         eMode = eSortMode_Unsorted;  break;
0989     case 1:
0990         eMode = eSortMode_Ascending; break;
0991     case 2:
0992         eMode = eSortMode_Descending; break;
0993     case 3:
0994         eMode = eSortMode_Numeric; break;
0995     case 4:
0996         eMode = eSortMode_Random; break;
0997     case 5:
0998         eMode = eSortMode_AscendingDate; break;
0999     case 6:
1000         eMode = eSortMode_DescendingDate; break;
1001     case 7: {
1002         eMode = eSortMode_Token;
1003         QPointer<TokenSortModeDialog> dlg = new TokenSortModeDialog(eCustomSortMode, this);
1004         if (dlg->exec() == QDialog::Accepted) {
1005             customToken = dlg->getToken();
1006             eCustomSortMode = dlg->getSortMode();
1007         } else {
1008             eMode = model->getSortMode();
1009             // Do not change anything
1010             // Reset combo box
1011             m_pageFiles->comboSort->setCurrentIndex(eMode);
1012             return;
1013         }
1014         delete dlg;
1015         break;
1016     }
1017     }
1018 
1019     m_pageFiles->labelCustomSort->setText(customToken);
1020     model->sortFiles(eMode, customToken, eCustomSortMode);
1021 }
1022 
1023 void KRenameWindow::slotMaxDotsChanged(int dots)
1024 {
1025     int i;
1026     const int FILE_EXTENSION_VARIABLE_ITEMS_START = 3;
1027 
1028     for (i = FILE_EXTENSION_VARIABLE_ITEMS_START;
1029             i < m_pageFilename->comboExtension->count();
1030             i++) {
1031         m_pageFilename->comboExtension->removeItem(i);
1032     }
1033 
1034     for (i = 1; i <= dots; ++i) {
1035         m_pageFilename->comboExtension->addItem(QString::number(i));
1036     }
1037 }
1038 
1039 void KRenameWindow::slotOpenFile(const QModelIndex &index)
1040 {
1041     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
1042     model->run(index, this);
1043 }
1044 
1045 void KRenameWindow::slotMoveUp()
1046 {
1047     QList<int> sel = this->selectedFileItems();
1048 
1049     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
1050     model->moveFilesUp(sel);
1051 
1052     QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel();
1053     QList<int>::const_iterator it  = sel.constBegin();
1054     while (it != sel.constEnd()) {
1055         if (*it - 1 > 0) {
1056             selection->select(model->createIndex(*it - 1), QItemSelectionModel::Select);
1057         }
1058 
1059         ++it;
1060     }
1061 
1062     // make sure that the first item is visible
1063     // TODO: Maybe it is better to calculate the minimum index here
1064     if (sel.size()) {
1065         m_pageFiles->fileList->scrollTo(model->createIndex(sel.front() - 1), QAbstractItemView::EnsureVisible);
1066     }
1067 }
1068 
1069 void KRenameWindow::slotMoveDown()
1070 {
1071     QList<int> sel = this->selectedFileItems();
1072 
1073     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
1074     model->moveFilesDown(sel);
1075 
1076     QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel();
1077     QList<int>::const_iterator it  = sel.constBegin();
1078     while (it != sel.constEnd()) {
1079         if (*it + 1 < model->rowCount()) {
1080             selection->select(model->createIndex(*it + 1), QItemSelectionModel::Select);
1081         }
1082 
1083         ++it;
1084     }
1085 
1086     // make sure that the last item is visible
1087     // TODO: Maybe it is better to calculate the maximum index here
1088     if (sel.size()) {
1089         m_pageFiles->fileList->scrollTo(model->createIndex(sel.back() + 1), QAbstractItemView::EnsureVisible);
1090     }
1091 }
1092 
1093 void KRenameWindow::slotMoveUpPreview()
1094 {
1095     QList<int>         sel  = this->selectedFileItemsPreview();
1096     QAbstractItemView *view = m_pageFilename->listPreview;
1097 
1098     moveUp(sel, view);
1099 }
1100 
1101 void KRenameWindow::slotMoveDownPreview()
1102 {
1103     QList<int>         sel  = this->selectedFileItemsPreview();
1104     QAbstractItemView *view = m_pageFilename->listPreview;
1105 
1106     moveDown(sel, view);
1107 }
1108 
1109 void KRenameWindow::moveUp(const QList<int> &selected, QAbstractItemView *view)
1110 {
1111     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
1112     model->moveFilesUp(selected);
1113 
1114     updatePreview();
1115 
1116     QItemSelectionModel *selection = view->selectionModel();
1117     QList<int>::const_iterator it  = selected.begin();
1118     while (it != selected.end()) {
1119         if (*it - 1 > 0) {
1120             selection->select(model->createIndex(*it - 1), QItemSelectionModel::Select);
1121         }
1122 
1123         ++it;
1124     }
1125 
1126     // make sure that the first item is visible
1127     // TODO: Maybe it is better to calculate the minimum index here
1128     if (selected.size()) {
1129         view->scrollTo(model->createIndex(selected.front() - 1), QAbstractItemView::EnsureVisible);
1130     }
1131 }
1132 
1133 void KRenameWindow::moveDown(const QList<int> &selected, QAbstractItemView *view)
1134 {
1135     KRenameModel *model = static_cast<KRenameModel *>(m_pageFiles->fileList->model());
1136     model->moveFilesDown(selected);
1137 
1138     updatePreview();
1139 
1140     QItemSelectionModel *selection = view->selectionModel();
1141     QList<int>::const_iterator it  = selected.begin();
1142     while (it != selected.end()) {
1143         if (*it + 1 < model->rowCount()) {
1144             selection->select(model->createIndex(*it + 1), QItemSelectionModel::Select);
1145         }
1146 
1147         ++it;
1148     }
1149 
1150     // make sure that the last item is visible
1151     // TODO: Maybe it is better to calculate the maximum index here
1152     if (selected.size()) {
1153         view->scrollTo(model->createIndex(selected.back() + 1), QAbstractItemView::EnsureVisible);
1154     }
1155 }
1156 
1157 void KRenameWindow::slotPluginChanged(QTreeWidgetItem *selected)
1158 {
1159     QWidget *w = m_pluginsWidgetHash[selected->text(0)];
1160     Plugin  *p = m_pluginsHash[selected->text(0)];
1161 
1162     if (p->alwaysEnabled()) {
1163         m_pagePlugins->checkEnablePlugin->setChecked(true);
1164     } else {
1165         m_pagePlugins->checkEnablePlugin->setChecked(p->isEnabled());
1166     }
1167 
1168     m_pagePlugins->checkEnablePlugin->setEnabled(!p->alwaysEnabled());
1169     m_pagePlugins->stackPlugins->setCurrentWidget(w);
1170 
1171     slotPluginEnabled();
1172 }
1173 
1174 void KRenameWindow::slotPluginEnabled()
1175 {
1176     QTreeWidgetItem *selected = m_pagePlugins->listPlugins->currentItem();
1177     if (selected) {
1178         QWidget *w = m_pluginsWidgetHash[selected->text(0)];
1179         Plugin  *p = m_pluginsHash[selected->text(0)];
1180 
1181         p->setEnabled(m_pagePlugins->checkEnablePlugin->isChecked());
1182         w->setEnabled(p->alwaysEnabled() || m_pagePlugins->checkEnablePlugin->isChecked());
1183     }
1184 }
1185 
1186 void KRenameWindow::blockSignalsRecursive(QObject *obj, bool b)
1187 {
1188     if (obj) {
1189         obj->blockSignals(b);
1190 
1191         QList<QObject *> list = obj->children();
1192         QList<QObject *>::iterator it = list.begin();
1193         QObject *o = nullptr;
1194 
1195         while (it != list.end()) {
1196             o = *it;
1197             if (o && o != obj) {
1198                 blockSignalsRecursive(o, b);
1199             }
1200 
1201             ++it;
1202         }
1203     }
1204 }