]>
cloud.milkyroute.net Git - dolphin.git/blob - src/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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "viewpropsprogressinfo.h"
22 #include "applyviewpropsjob.h"
23 #include "viewproperties.h"
26 #include <QProgressBar>
28 #include <QVBoxLayout>
33 #include <kio/jobclasses.h>
35 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
* parent
,
37 const ViewProperties
* viewProps
) :
40 m_viewProps(viewProps
),
44 m_applyViewPropsJob(0),
47 setCaption(i18n("Applying view properties"));
48 setButtons(KDialog::Cancel
);
50 QWidget
* main
= new QWidget();
51 QVBoxLayout
* topLayout
= new QVBoxLayout();
53 m_label
= new QLabel(i18n("Counting folders: %1", 0), main
);
54 m_progressBar
= new QProgressBar(main
);
56 topLayout
->addWidget(m_label
);
57 topLayout
->addWidget(m_progressBar
);
59 main
->setLayout(topLayout
);
62 // Use the directory size job to count the number of directories first. This
63 // allows to give a progress indication for the user when applying the view
65 m_dirSizeJob
= KIO::directorySize(dir
);
66 connect(m_dirSizeJob
, SIGNAL(result(KJob
*)),
67 this, SLOT(applyViewProperties()));
69 // The directory size job cannot emit any progress signal, as it is not aware
70 // about the total number of directories. Therefor a timer is triggered, which
71 // periodically updates the current directory count.
72 m_timer
= new QTimer(this);
73 connect(m_timer
, SIGNAL(timeout()),
74 this, SLOT(updateProgress()));
77 connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying()));
80 ViewPropsProgressInfo::~ViewPropsProgressInfo()
85 void ViewPropsProgressInfo::updateProgress()
87 if (m_dirSizeJob
!= 0) {
88 const int subdirs
= m_dirSizeJob
->totalSubdirs();
89 m_label
->setText(i18n("Counting folders: %1", subdirs
));
92 assert(m_applyViewPropsJob
!= 0);
93 const int progress
= m_applyViewPropsJob
->progress();
94 m_progressBar
->setValue(progress
);
98 void ViewPropsProgressInfo::applyViewProperties()
100 if (m_dirSizeJob
->error()) {
104 const int subdirs
= m_dirSizeJob
->totalSubdirs();
105 m_label
->setText(i18n("Folders: %1", subdirs
));
106 m_progressBar
->setMaximum(subdirs
);
110 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
111 connect(m_applyViewPropsJob
, SIGNAL(result(KJob
*)),
112 this, SLOT(close()));
115 void ViewPropsProgressInfo::cancelApplying()
117 if (m_dirSizeJob
!= 0) {
118 m_dirSizeJob
->doKill();
121 assert(m_applyViewPropsJob
!= 0);
122 m_applyViewPropsJob
->doKill();
126 #include "viewpropsprogressinfo.moc"