File indexing completed on 2022-10-04 17:30:19

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