]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewpropsprogressinfo.cpp
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "viewpropsprogressinfo.h"
9 #include "applyviewpropsjob.h"
10 #include "views/viewproperties.h"
12 #include <KConfigGroup>
13 #include <KLocalizedString>
15 #include <QDialogButtonBox>
17 #include <QProgressBar>
18 #include <QPushButton>
20 #include <QVBoxLayout>
22 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
* parent
,
24 const ViewProperties
& viewProps
) :
29 m_progressBar(nullptr),
30 m_dirSizeJob(nullptr),
31 m_applyViewPropsJob(nullptr),
34 const QSize minSize
= minimumSize();
35 setMinimumSize(QSize(320, minSize
.height()));
36 setWindowTitle(i18nc("@title:window", "Applying View Properties"));
37 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
39 m_viewProps
= new ViewProperties(dir
);
40 m_viewProps
->setDirProperties(viewProps
);
42 // the view properties are stored by the ApplyViewPropsJob, so prevent
43 // that the view properties are saved twice:
44 m_viewProps
->setAutoSaveEnabled(false);
46 auto layout
= new QVBoxLayout(this);
48 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
49 layout
->addWidget(m_label
);
51 m_progressBar
= new QProgressBar(this);
52 m_progressBar
->setMinimum(0);
53 m_progressBar
->setMaximum(0);
54 m_progressBar
->setValue(0);
55 layout
->addWidget(m_progressBar
);
59 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
60 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
61 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
62 layout
->addWidget(buttonBox
);
64 // Use the directory size job to count the number of directories first. This
65 // allows to give a progress indication for the user when applying the view
67 m_dirSizeJob
= KIO::directorySize(dir
);
68 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
,
69 this, &ViewPropsProgressInfo::applyViewProperties
);
71 // The directory size job cannot emit any progress signal, as it is not aware
72 // about the total number of directories. Therefor a timer is triggered, which
73 // periodically updates the current directory count.
74 m_timer
= new QTimer(this);
75 connect(m_timer
, &QTimer::timeout
,
76 this, &ViewPropsProgressInfo::updateProgress
);
80 ViewPropsProgressInfo::~ViewPropsProgressInfo()
83 m_viewProps
= nullptr;
86 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
89 m_applyViewPropsJob
= nullptr;
90 QDialog::closeEvent(event
);
93 void ViewPropsProgressInfo::reject()
97 m_dirSizeJob
= nullptr;
100 if (m_applyViewPropsJob
) {
101 m_applyViewPropsJob
->kill();
102 m_applyViewPropsJob
= nullptr;
108 void ViewPropsProgressInfo::updateProgress()
111 const int subdirs
= m_dirSizeJob
->totalSubdirs();
112 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
115 if (m_applyViewPropsJob
) {
116 const int progress
= m_applyViewPropsJob
->progress();
117 m_progressBar
->setValue(progress
);
121 void ViewPropsProgressInfo::applyViewProperties()
123 if (m_dirSizeJob
->error()) {
127 const int subdirs
= m_dirSizeJob
->totalSubdirs();
128 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
129 m_progressBar
->setMaximum(subdirs
);
131 m_dirSizeJob
= nullptr;
133 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
134 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
,
135 this, &ViewPropsProgressInfo::close
);