]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewpropsprogressinfo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "viewpropsprogressinfo.h"
23 #include "applyviewpropsjob.h"
24 #include "views/viewproperties.h"
26 #include <KConfigGroup>
27 #include <KLocalizedString>
29 #include <QDialogButtonBox>
31 #include <QProgressBar>
32 #include <QPushButton>
34 #include <QVBoxLayout>
36 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
* parent
,
38 const ViewProperties
& viewProps
) :
43 m_progressBar(nullptr),
44 m_dirSizeJob(nullptr),
45 m_applyViewPropsJob(nullptr),
48 const QSize minSize
= minimumSize();
49 setMinimumSize(QSize(320, minSize
.height()));
50 setWindowTitle(i18nc("@title:window", "Applying View Properties"));
51 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
53 m_viewProps
= new ViewProperties(dir
);
54 m_viewProps
->setDirProperties(viewProps
);
56 // the view properties are stored by the ViewPropsApplierJob, so prevent
57 // that the view properties are saved twice:
58 m_viewProps
->setAutoSaveEnabled(false);
60 auto layout
= new QVBoxLayout(this);
63 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
64 layout
->addWidget(m_label
);
66 m_progressBar
= new QProgressBar(this);
67 m_progressBar
->setMinimum(0);
68 m_progressBar
->setMaximum(0);
69 m_progressBar
->setValue(0);
70 layout
->addWidget(m_progressBar
);
74 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
75 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
76 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
77 layout
->addWidget(buttonBox
);
79 // Use the directory size job to count the number of directories first. This
80 // allows to give a progress indication for the user when applying the view
82 m_dirSizeJob
= KIO::directorySize(dir
);
83 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
,
84 this, &ViewPropsProgressInfo::applyViewProperties
);
86 // The directory size job cannot emit any progress signal, as it is not aware
87 // about the total number of directories. Therefor a timer is triggered, which
88 // periodically updates the current directory count.
89 m_timer
= new QTimer(this);
90 connect(m_timer
, &QTimer::timeout
,
91 this, &ViewPropsProgressInfo::updateProgress
);
95 ViewPropsProgressInfo::~ViewPropsProgressInfo()
98 m_viewProps
= nullptr;
101 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
104 m_applyViewPropsJob
= nullptr;
105 QDialog::closeEvent(event
);
108 void ViewPropsProgressInfo::reject()
111 m_dirSizeJob
->kill();
112 m_dirSizeJob
= nullptr;
115 if (m_applyViewPropsJob
) {
116 m_applyViewPropsJob
->kill();
117 m_applyViewPropsJob
= nullptr;
123 void ViewPropsProgressInfo::updateProgress()
126 const int subdirs
= m_dirSizeJob
->totalSubdirs();
127 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
130 if (m_applyViewPropsJob
) {
131 const int progress
= m_applyViewPropsJob
->progress();
132 m_progressBar
->setValue(progress
);
136 void ViewPropsProgressInfo::applyViewProperties()
138 if (m_dirSizeJob
->error()) {
142 const int subdirs
= m_dirSizeJob
->totalSubdirs();
143 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
144 m_progressBar
->setMaximum(subdirs
);
146 m_dirSizeJob
= nullptr;
148 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
149 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
,
150 this, &ViewPropsProgressInfo::close
);