delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / dolphin / src / settings / viewpropsprogressinfo.cpp
blobc073d3d46885e74616413a360643a2d1dd8b899e
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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"
23 #include "viewproperties.h"
25 #include <QtGui/QLabel>
26 #include <QtGui/QProgressBar>
27 #include <QtCore/QTimer>
28 #include <QtGui/QBoxLayout>
30 #include <assert.h>
31 #include <klocale.h>
32 #include <kio/jobclasses.h>
34 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
35 const KUrl& dir,
36 const ViewProperties& viewProps) :
37 KDialog(parent),
38 m_dir(dir),
39 m_viewProps(0),
40 m_label(0),
41 m_progressBar(0),
42 m_dirSizeJob(0),
43 m_applyViewPropsJob(0),
44 m_timer(0)
46 const QSize minSize = minimumSize();
47 setMinimumSize(QSize(320, minSize.height()));
49 setCaption(i18nc("@title:window", "Applying View Properties"));
50 setButtons(KDialog::Cancel);
52 m_viewProps = new ViewProperties(dir);
53 m_viewProps->setDirProperties(viewProps);
55 // the view properties are stored by the ViewPropsApplierJob, so prevent
56 // that the view properties are saved twice:
57 m_viewProps->setAutoSaveEnabled(false);
59 QWidget* main = new QWidget();
60 QVBoxLayout* topLayout = new QVBoxLayout();
62 m_label = new QLabel(i18nc("@info:progress", "Counting folders: %1", 0), main);
63 m_progressBar = new QProgressBar(main);
64 m_progressBar->setMinimum(0);
65 m_progressBar->setMaximum(0);
66 m_progressBar->setValue(0);
68 topLayout->addWidget(m_label);
69 topLayout->addWidget(m_progressBar);
71 main->setLayout(topLayout);
72 setMainWidget(main);
74 // Use the directory size job to count the number of directories first. This
75 // allows to give a progress indication for the user when applying the view
76 // properties later.
77 m_dirSizeJob = KIO::directorySize(dir);
78 connect(m_dirSizeJob, SIGNAL(result(KJob*)),
79 this, SLOT(applyViewProperties()));
81 // The directory size job cannot emit any progress signal, as it is not aware
82 // about the total number of directories. Therefor a timer is triggered, which
83 // periodically updates the current directory count.
84 m_timer = new QTimer(this);
85 connect(m_timer, SIGNAL(timeout()),
86 this, SLOT(updateProgress()));
87 m_timer->start(300);
89 connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying()));
92 ViewPropsProgressInfo::~ViewPropsProgressInfo()
94 delete m_viewProps;
95 m_viewProps = 0;
98 void ViewPropsProgressInfo::closeEvent(QCloseEvent* event)
100 m_timer->stop();
101 m_applyViewPropsJob = 0;
102 KDialog::closeEvent(event);
105 void ViewPropsProgressInfo::updateProgress()
107 if (m_dirSizeJob != 0) {
108 const int subdirs = m_dirSizeJob->totalSubdirs();
109 m_label->setText(i18nc("@info:progress", "Counting folders: %1", subdirs));
112 if (m_applyViewPropsJob != 0) {
113 const int progress = m_applyViewPropsJob->progress();
114 m_progressBar->setValue(progress);
118 void ViewPropsProgressInfo::applyViewProperties()
120 if (m_dirSizeJob->error()) {
121 return;
124 const int subdirs = m_dirSizeJob->totalSubdirs();
125 m_label->setText(i18nc("@info:progress", "Folders: %1", subdirs));
126 m_progressBar->setMaximum(subdirs);
128 m_dirSizeJob = 0;
130 m_applyViewPropsJob = new ApplyViewPropsJob(m_dir, *m_viewProps);
131 connect(m_applyViewPropsJob, SIGNAL(result(KJob*)),
132 this, SLOT(close()));
135 void ViewPropsProgressInfo::cancelApplying()
137 if (m_dirSizeJob != 0) {
138 m_dirSizeJob->kill();
139 m_dirSizeJob = 0;
142 if (m_applyViewPropsJob != 0) {
143 m_applyViewPropsJob->kill();
144 m_applyViewPropsJob = 0;
148 #include "viewpropsprogressinfo.moc"