]>
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
,
23 const ViewProperties
& viewProps
) :
28 m_progressBar(nullptr),
29 m_dirSizeJob(nullptr),
30 m_applyViewPropsJob(nullptr),
33 const QSize minSize
= minimumSize();
34 setMinimumSize(QSize(320, minSize
.height()));
35 setWindowTitle(i18nc("@title:window", "Applying View Properties"));
36 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
38 m_viewProps
= new ViewProperties(dir
);
39 m_viewProps
->setDirProperties(viewProps
);
41 // the view properties are stored by the ApplyViewPropsJob, so prevent
42 // that the view properties are saved twice:
43 m_viewProps
->setAutoSaveEnabled(false);
45 auto layout
= new QVBoxLayout(this);
47 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
48 layout
->addWidget(m_label
);
50 m_progressBar
= new QProgressBar(this);
51 m_progressBar
->setMinimum(0);
52 m_progressBar
->setMaximum(0);
53 m_progressBar
->setValue(0);
54 layout
->addWidget(m_progressBar
);
58 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
59 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
60 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
61 layout
->addWidget(buttonBox
);
63 // Use the directory size job to count the number of directories first. This
64 // allows to give a progress indication for the user when applying the view
66 m_dirSizeJob
= KIO::directorySize(dir
);
67 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
,
68 this, &ViewPropsProgressInfo::applyViewProperties
);
70 // The directory size job cannot emit any progress signal, as it is not aware
71 // about the total number of directories. Therefor a timer is triggered, which
72 // periodically updates the current directory count.
73 m_timer
= new QTimer(this);
74 connect(m_timer
, &QTimer::timeout
,
75 this, &ViewPropsProgressInfo::updateProgress
);
79 ViewPropsProgressInfo::~ViewPropsProgressInfo()
82 m_viewProps
= nullptr;
85 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
88 m_applyViewPropsJob
= nullptr;
89 QDialog::closeEvent(event
);
92 void ViewPropsProgressInfo::reject()
96 m_dirSizeJob
= nullptr;
99 if (m_applyViewPropsJob
) {
100 m_applyViewPropsJob
->kill();
101 m_applyViewPropsJob
= nullptr;
107 void ViewPropsProgressInfo::updateProgress()
110 const int subdirs
= m_dirSizeJob
->totalSubdirs();
111 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
114 if (m_applyViewPropsJob
) {
115 const int progress
= m_applyViewPropsJob
->progress();
116 m_progressBar
->setValue(progress
);
120 void ViewPropsProgressInfo::applyViewProperties()
122 if (m_dirSizeJob
->error()) {
126 const int subdirs
= m_dirSizeJob
->totalSubdirs();
127 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
128 m_progressBar
->setMaximum(subdirs
);
130 m_dirSizeJob
= nullptr;
132 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
133 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
,
134 this, &ViewPropsProgressInfo::close
);