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

0001 /***************************************************************************
0002                     filedialogextwidget.cpp -  description
0003                              -------------------
0004     begin                : Tue Apr 17 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 "filedialogextwidget.h"
0019 
0020 #include <KLocalizedString>
0021 
0022 // Qt includes
0023 #include <QHBoxLayout>
0024 #include <QVBoxLayout>
0025 #include <QUrl>
0026 
0027 #include <QDialogButtonBox>
0028 #include <QPushButton>
0029 
0030 FileDialogExtWidget::FileDialogExtWidget(QWidget *parent)
0031     : QDialog(parent)
0032 {
0033     QVBoxLayout *mainLayout = new QVBoxLayout;
0034     setLayout(mainLayout);
0035 
0036     m_fileWidget = new KFileWidget(QUrl());
0037     m_fileWidget->setOperationMode(KFileWidget::Opening);
0038     m_fileWidget->setMode(KFile::Files | KFile::Directory | KFile::ExistingOnly);
0039 
0040     connect(m_fileWidget, &KFileWidget::accepted, [&]() {
0041         m_fileWidget->accept();
0042 
0043         // We have to do this manually for some reason
0044         accept();
0045     });
0046     layout()->addWidget(m_fileWidget);
0047 
0048     QWidget *extraWidget = new QWidget;
0049     QVBoxLayout *extraLayout = new QVBoxLayout;
0050     extraWidget->setLayout(extraLayout);
0051     checkDir       = new QCheckBox(i18n("Add folder names &with filenames"), this);
0052     checkRecursive = new QCheckBox(i18n("Add subfolders &recursively"), this);
0053     checkHidden    = new QCheckBox(i18n("Add &hidden folders"), this);
0054     checkOnlyDir   = new QCheckBox(i18n("Add folder names only"), this);
0055 
0056     QHBoxLayout *hbox = new QHBoxLayout;
0057     hbox->addSpacing(20);
0058     hbox->addWidget(checkHidden);
0059     hbox->setStretchFactor(checkHidden, 4);
0060 
0061     extraLayout->addWidget(checkDir);
0062     extraLayout->addWidget(checkRecursive);
0063     extraLayout->addLayout(hbox);
0064     extraLayout->addWidget(checkOnlyDir);
0065     m_fileWidget->setCustomWidget(extraWidget);
0066 
0067     connect(checkRecursive, &QCheckBox::clicked,
0068             this, &FileDialogExtWidget::enableControls);
0069 
0070     checkRecursive->setToolTip(i18n("Walk recursively through the folder tree and also add the content "
0071                                     "of all subfolders to the list of files to rename."));
0072     checkHidden->setToolTip(i18n("If not checked, KRename will ignore folders starting "
0073                                  "with a dot during recursive adding."));
0074     checkOnlyDir->setToolTip(i18n("Add only the folder names and not the names "
0075                                   "of the files in the folder to KRename."));
0076     checkDir->setToolTip(i18n("This option causes KRename to also add the name of the base "
0077                               "folder of the selected files to its list."));
0078 
0079     enableControls();
0080 
0081     QDialogButtonBox *buttonBox = new QDialogButtonBox;
0082     buttonBox->addButton(m_fileWidget->okButton(), QDialogButtonBox::AcceptRole);
0083     buttonBox->addButton(m_fileWidget->cancelButton(), QDialogButtonBox::RejectRole);
0084     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0085     connect(buttonBox, &QDialogButtonBox::accepted,
0086             m_fileWidget, &KFileWidget::slotOk);
0087     layout()->addWidget(buttonBox);
0088 }
0089 
0090 void FileDialogExtWidget::enableControls()
0091 {
0092     checkHidden->setEnabled(checkRecursive->isChecked());
0093 }