]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewpropsprogressinfo.cpp
489cc1d8c5b2bbb33b0087aa3759022bf23f1e80
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"
22 #include "applyviewpropsjob.h"
25 #include <QProgressBar>
27 #include <QVBoxLayout>
28 #include <QDialogButtonBox>
29 #include <QPushButton>
31 #include <KConfigGroup>
32 #include <KLocalizedString>
33 #include <KIO/JobClasses>
35 #include <views/viewproperties.h>
37 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
* parent
,
39 const ViewProperties
& viewProps
) :
46 m_applyViewPropsJob(0),
49 const QSize minSize
= minimumSize();
50 setMinimumSize(QSize(320, minSize
.height()));
51 setWindowTitle(i18nc("@title:window", "Applying View Properties"));
52 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
54 m_viewProps
= new ViewProperties(dir
);
55 m_viewProps
->setDirProperties(viewProps
);
57 // the view properties are stored by the ViewPropsApplierJob, so prevent
58 // that the view properties are saved twice:
59 m_viewProps
->setAutoSaveEnabled(false);
61 auto layout
= new QVBoxLayout(this);
64 m_label
= new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), this);
65 layout
->addWidget(m_label
);
67 m_progressBar
= new QProgressBar(this);
68 m_progressBar
->setMinimum(0);
69 m_progressBar
->setMaximum(0);
70 m_progressBar
->setValue(0);
71 layout
->addWidget(m_progressBar
);
75 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Cancel
, this);
76 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &ViewPropsProgressInfo::accept
);
77 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &ViewPropsProgressInfo::reject
);
78 layout
->addWidget(buttonBox
);
80 // Use the directory size job to count the number of directories first. This
81 // allows to give a progress indication for the user when applying the view
83 m_dirSizeJob
= KIO::directorySize(dir
);
84 connect(m_dirSizeJob
, &KIO::DirectorySizeJob::result
,
85 this, &ViewPropsProgressInfo::applyViewProperties
);
87 // The directory size job cannot emit any progress signal, as it is not aware
88 // about the total number of directories. Therefor a timer is triggered, which
89 // periodically updates the current directory count.
90 m_timer
= new QTimer(this);
91 connect(m_timer
, &QTimer::timeout
,
92 this, &ViewPropsProgressInfo::updateProgress
);
96 ViewPropsProgressInfo::~ViewPropsProgressInfo()
102 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
105 m_applyViewPropsJob
= 0;
106 QDialog::closeEvent(event
);
109 void ViewPropsProgressInfo::reject()
112 m_dirSizeJob
->kill();
116 if (m_applyViewPropsJob
) {
117 m_applyViewPropsJob
->kill();
118 m_applyViewPropsJob
= 0;
124 void ViewPropsProgressInfo::updateProgress()
127 const int subdirs
= m_dirSizeJob
->totalSubdirs();
128 m_label
->setText(i18nc("@info:progress", "Counting folders: %1", subdirs
));
131 if (m_applyViewPropsJob
) {
132 const int progress
= m_applyViewPropsJob
->progress();
133 m_progressBar
->setValue(progress
);
137 void ViewPropsProgressInfo::applyViewProperties()
139 if (m_dirSizeJob
->error()) {
143 const int subdirs
= m_dirSizeJob
->totalSubdirs();
144 m_label
->setText(i18nc("@info:progress", "Folders: %1", subdirs
));
145 m_progressBar
->setMaximum(subdirs
);
149 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
150 connect(m_applyViewPropsJob
, &ApplyViewPropsJob::result
,
151 this, &ViewPropsProgressInfo::close
);