]>
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 <KLocalizedString>
14 #include <QDialogButtonBox>
16 #include <QProgressBar>
17 #include <QPushButton>
19 #include <QVBoxLayout>
21 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
*parent
, const QUrl
&dir
, const ViewProperties
&viewProps
)
24 , m_viewProps(nullptr)
26 , m_progressBar(nullptr)
27 , m_dirSizeJob(nullptr)
28 , m_applyViewPropsJob(nullptr)
31 const QSize minSize
= minimumSize();
32 setMinimumSize(QSize(320, minSize
.height()));
33 setWindowTitle(i18nc("@title:window", "Applying View Properties"));
34 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
36 m_viewProps
= new ViewProperties(dir
);
37 m_viewProps
->setDirProperties(viewProps
);
39 // the view properties are stored by the ApplyViewPropsJob, so prevent
40 // that the view properties are saved twice:
41 m_viewProps
->setAutoSaveEnabled(false);
43 auto layout
= new QVBoxLayout(this);
45 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
46 layout
->addWidget(m_label
);
48 m_progressBar
= new QProgressBar(this);
49 m_progressBar
->setMinimum(0);
50 m_progressBar
->setMaximum(0);
51 m_progressBar
->setValue(0);
52 layout
->addWidget(m_progressBar
);
56 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
57 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
58 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
59 layout
->addWidget(buttonBox
);
61 // Use the directory size job to count the number of directories first. This
62 // allows to give a progress indication for the user when applying the view
64 m_dirSizeJob
= KIO::directorySize(dir
);
65 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
, this, &ViewPropsProgressInfo::applyViewProperties
);
67 // The directory size job cannot emit any progress signal, as it is not aware
68 // about the total number of directories. Therefor a timer is triggered, which
69 // periodically updates the current directory count.
70 m_timer
= new QTimer(this);
71 connect(m_timer
, &QTimer::timeout
, this, &ViewPropsProgressInfo::updateProgress
);
75 ViewPropsProgressInfo::~ViewPropsProgressInfo()
78 m_viewProps
= nullptr;
81 void ViewPropsProgressInfo::closeEvent(QCloseEvent
*event
)
84 m_applyViewPropsJob
= nullptr;
85 QDialog::closeEvent(event
);
88 void ViewPropsProgressInfo::reject()
92 m_dirSizeJob
= nullptr;
95 if (m_applyViewPropsJob
) {
96 m_applyViewPropsJob
->kill();
97 m_applyViewPropsJob
= nullptr;
103 void ViewPropsProgressInfo::updateProgress()
106 const int subdirs
= m_dirSizeJob
->totalSubdirs();
107 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
110 if (m_applyViewPropsJob
) {
111 const int progress
= m_applyViewPropsJob
->progress();
112 m_progressBar
->setValue(progress
);
116 void ViewPropsProgressInfo::applyViewProperties()
118 if (m_dirSizeJob
->error()) {
122 const int subdirs
= m_dirSizeJob
->totalSubdirs();
123 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
124 m_progressBar
->setMaximum(subdirs
);
126 m_dirSizeJob
= nullptr;
128 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
129 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
, this, &ViewPropsProgressInfo::close
);
132 #include "moc_viewpropsprogressinfo.cpp"