]>
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);
49 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
50 layout
->addWidget(m_label
);
52 m_progressBar
= new QProgressBar(this);
53 m_progressBar
->setMinimum(0);
54 m_progressBar
->setMaximum(0);
55 m_progressBar
->setValue(0);
56 layout
->addWidget(m_progressBar
);
60 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
61 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
62 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
63 layout
->addWidget(buttonBox
);
65 // Use the directory size job to count the number of directories first. This
66 // allows to give a progress indication for the user when applying the view
68 m_dirSizeJob
= KIO::directorySize(dir
);
69 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
,
70 this, &ViewPropsProgressInfo::applyViewProperties
);
72 // The directory size job cannot emit any progress signal, as it is not aware
73 // about the total number of directories. Therefor a timer is triggered, which
74 // periodically updates the current directory count.
75 m_timer
= new QTimer(this);
76 connect(m_timer
, &QTimer::timeout
,
77 this, &ViewPropsProgressInfo::updateProgress
);
81 ViewPropsProgressInfo::~ViewPropsProgressInfo()
84 m_viewProps
= nullptr;
87 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
90 m_applyViewPropsJob
= nullptr;
91 QDialog::closeEvent(event
);
94 void ViewPropsProgressInfo::reject()
98 m_dirSizeJob
= nullptr;
101 if (m_applyViewPropsJob
) {
102 m_applyViewPropsJob
->kill();
103 m_applyViewPropsJob
= nullptr;
109 void ViewPropsProgressInfo::updateProgress()
112 const int subdirs
= m_dirSizeJob
->totalSubdirs();
113 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
116 if (m_applyViewPropsJob
) {
117 const int progress
= m_applyViewPropsJob
->progress();
118 m_progressBar
->setValue(progress
);
122 void ViewPropsProgressInfo::applyViewProperties()
124 if (m_dirSizeJob
->error()) {
128 const int subdirs
= m_dirSizeJob
->totalSubdirs();
129 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
130 m_progressBar
->setMaximum(subdirs
);
132 m_dirSizeJob
= nullptr;
134 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
135 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
,
136 this, &ViewPropsProgressInfo::close
);