X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a5cf21ff06aff44cde563eaceae3c6cef452ee48..44a21ea51a055c7429ddee866e35b0a5a21c072b:/src/settings/viewpropsprogressinfo.cpp diff --git a/src/settings/viewpropsprogressinfo.cpp b/src/settings/viewpropsprogressinfo.cpp index 436dcdef6..a6c0c6d58 100644 --- a/src/settings/viewpropsprogressinfo.cpp +++ b/src/settings/viewpropsprogressinfo.cpp @@ -19,35 +19,36 @@ ***************************************************************************/ #include "viewpropsprogressinfo.h" -#include "applyviewpropsjob.h" -#include -#include -#include -#include +#include "applyviewpropsjob.h" +#include "views/viewproperties.h" -#include -#include +#include +#include -#include +#include +#include +#include +#include +#include +#include ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, - const KUrl& dir, + const QUrl& dir, const ViewProperties& viewProps) : - KDialog(parent), + QDialog(parent), m_dir(dir), - m_viewProps(0), - m_label(0), - m_progressBar(0), - m_dirSizeJob(0), - m_applyViewPropsJob(0), - m_timer(0) + m_viewProps(nullptr), + m_label(nullptr), + m_progressBar(nullptr), + m_dirSizeJob(nullptr), + m_applyViewPropsJob(nullptr), + m_timer(nullptr) { const QSize minSize = minimumSize(); setMinimumSize(QSize(320, minSize.height())); - - setCaption(i18nc("@title:window", "Applying View Properties")); - setButtons(KDialog::Cancel); + setWindowTitle(i18nc("@title:window", "Applying View Properties")); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); m_viewProps = new ViewProperties(dir); m_viewProps->setDirProperties(viewProps); @@ -56,60 +57,77 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, // that the view properties are saved twice: m_viewProps->setAutoSaveEnabled(false); - QWidget* main = new QWidget(); - QVBoxLayout* topLayout = new QVBoxLayout(); + auto layout = new QVBoxLayout(this); + setLayout(layout); - m_label = new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), main); - m_progressBar = new QProgressBar(main); + m_label = new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this); + layout->addWidget(m_label); + + m_progressBar = new QProgressBar(this); m_progressBar->setMinimum(0); m_progressBar->setMaximum(0); m_progressBar->setValue(0); + layout->addWidget(m_progressBar); - topLayout->addWidget(m_label); - topLayout->addWidget(m_progressBar); + layout->addStretch(); - main->setLayout(topLayout); - setMainWidget(main); + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this); + connect(buttonBox, &QDialogButtonBox::accepted, this, &ViewPropsProgressInfo::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &ViewPropsProgressInfo::reject); + layout->addWidget(buttonBox); // Use the directory size job to count the number of directories first. This // allows to give a progress indication for the user when applying the view // properties later. m_dirSizeJob = KIO::directorySize(dir); - connect(m_dirSizeJob, SIGNAL(result(KJob*)), - this, SLOT(applyViewProperties())); + connect(m_dirSizeJob, &KIO::DirectorySizeJob::result, + this, &ViewPropsProgressInfo::applyViewProperties); // The directory size job cannot emit any progress signal, as it is not aware // about the total number of directories. Therefor a timer is triggered, which // periodically updates the current directory count. m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(updateProgress())); + connect(m_timer, &QTimer::timeout, + this, &ViewPropsProgressInfo::updateProgress); m_timer->start(300); - - connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying())); } ViewPropsProgressInfo::~ViewPropsProgressInfo() { delete m_viewProps; - m_viewProps = 0; + m_viewProps = nullptr; } void ViewPropsProgressInfo::closeEvent(QCloseEvent* event) { m_timer->stop(); - m_applyViewPropsJob = 0; - KDialog::closeEvent(event); + m_applyViewPropsJob = nullptr; + QDialog::closeEvent(event); +} + +void ViewPropsProgressInfo::reject() +{ + if (m_dirSizeJob) { + m_dirSizeJob->kill(); + m_dirSizeJob = nullptr; + } + + if (m_applyViewPropsJob) { + m_applyViewPropsJob->kill(); + m_applyViewPropsJob = nullptr; + } + + QDialog::reject(); } void ViewPropsProgressInfo::updateProgress() { - if (m_dirSizeJob != 0) { + if (m_dirSizeJob) { const int subdirs = m_dirSizeJob->totalSubdirs(); m_label->setText(i18nc("@info:progress", "Counting folders: %1", subdirs)); } - if (m_applyViewPropsJob != 0) { + if (m_applyViewPropsJob) { const int progress = m_applyViewPropsJob->progress(); m_progressBar->setValue(progress); } @@ -125,24 +143,10 @@ void ViewPropsProgressInfo::applyViewProperties() m_label->setText(i18nc("@info:progress", "Folders: %1", subdirs)); m_progressBar->setMaximum(subdirs); - m_dirSizeJob = 0; + m_dirSizeJob = nullptr; m_applyViewPropsJob = new ApplyViewPropsJob(m_dir, *m_viewProps); - connect(m_applyViewPropsJob, SIGNAL(result(KJob*)), - this, SLOT(close())); -} - -void ViewPropsProgressInfo::cancelApplying() -{ - if (m_dirSizeJob != 0) { - m_dirSizeJob->kill(); - m_dirSizeJob = 0; - } - - if (m_applyViewPropsJob != 0) { - m_applyViewPropsJob->kill(); - m_applyViewPropsJob = 0; - } + connect(m_applyViewPropsJob, &ApplyViewPropsJob::result, + this, &ViewPropsProgressInfo::close); } -#include "viewpropsprogressinfo.moc"