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

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de>
0003 
0004 #include "filedialogextwidget.h"
0005 
0006 #include <KLocalizedString>
0007 
0008 // Qt includes
0009 #include <QHBoxLayout>
0010 #include <QVBoxLayout>
0011 #include <QUrl>
0012 
0013 #include <QDialogButtonBox>
0014 #include <QPushButton>
0015 
0016 FileDialogExtWidget::FileDialogExtWidget(QWidget *parent)
0017     : QDialog(parent)
0018 {
0019     QVBoxLayout *mainLayout = new QVBoxLayout;
0020     setLayout(mainLayout);
0021 
0022     m_fileWidget = new KFileWidget(QUrl());
0023     m_fileWidget->setOperationMode(KFileWidget::Opening);
0024     m_fileWidget->setMode(KFile::Files | KFile::Directory | KFile::ExistingOnly);
0025 
0026     connect(m_fileWidget, &KFileWidget::accepted, [&]() {
0027         m_fileWidget->accept();
0028 
0029         // We have to do this manually for some reason
0030         accept();
0031     });
0032     layout()->addWidget(m_fileWidget);
0033 
0034     QWidget *extraWidget = new QWidget;
0035     QVBoxLayout *extraLayout = new QVBoxLayout;
0036     extraWidget->setLayout(extraLayout);
0037     checkDir       = new QCheckBox(i18n("Add folder names &with filenames"), this);
0038     checkRecursive = new QCheckBox(i18n("Add subfolders &recursively"), this);
0039     checkHidden    = new QCheckBox(i18n("Add &hidden folders"), this);
0040     checkOnlyDir   = new QCheckBox(i18n("Add folder names only"), this);
0041 
0042     QHBoxLayout *hbox = new QHBoxLayout;
0043     hbox->addSpacing(20);
0044     hbox->addWidget(checkHidden);
0045     hbox->setStretchFactor(checkHidden, 4);
0046 
0047     extraLayout->addWidget(checkDir);
0048     extraLayout->addWidget(checkRecursive);
0049     extraLayout->addLayout(hbox);
0050     extraLayout->addWidget(checkOnlyDir);
0051     m_fileWidget->setCustomWidget(extraWidget);
0052 
0053     connect(checkRecursive, &QCheckBox::clicked,
0054             this, &FileDialogExtWidget::enableControls);
0055 
0056     checkRecursive->setToolTip(i18n("Walk recursively through the folder tree and also add the content "
0057                                     "of all subfolders to the list of files to rename."));
0058     checkHidden->setToolTip(i18n("If not checked, KRename will ignore folders starting "
0059                                  "with a dot during recursive adding."));
0060     checkOnlyDir->setToolTip(i18n("Add only the folder names and not the names "
0061                                   "of the files in the folder to KRename."));
0062     checkDir->setToolTip(i18n("This option causes KRename to also add the name of the base "
0063                               "folder of the selected files to its list."));
0064 
0065     enableControls();
0066 
0067     QDialogButtonBox *buttonBox = new QDialogButtonBox;
0068     buttonBox->addButton(m_fileWidget->okButton(), QDialogButtonBox::AcceptRole);
0069     buttonBox->addButton(m_fileWidget->cancelButton(), QDialogButtonBox::RejectRole);
0070     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0071     connect(buttonBox, &QDialogButtonBox::accepted,
0072             m_fileWidget, &KFileWidget::slotOk);
0073     layout()->addWidget(buttonBox);
0074 }
0075 
0076 void FileDialogExtWidget::enableControls()
0077 {
0078     checkHidden->setEnabled(checkRecursive->isChecked());
0079 }