]>
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
) :
44 m_applyViewPropsJob(0),
47 setCaption(i18n("Applying view properties"));
48 setButtons(KDialog::Cancel
);
50 m_viewProps
= new ViewProperties(dir
);
51 m_viewProps
->setDirProperties(viewProps
);
53 // the view properties are stored by the ViewPropsApplierJob, so prevent
54 // that the view properties are saved twice:
55 m_viewProps
->setAutoSaveEnabled(false);
57 QWidget
* main
= new QWidget();
58 QVBoxLayout
* topLayout
= new QVBoxLayout();
60 m_label
= new QLabel(i18n("Counting folders: %1", 0), main
);
61 m_progressBar
= new QProgressBar(main
);
62 m_progressBar
->setMinimum(0);
63 m_progressBar
->setMaximum(0);
64 m_progressBar
->setValue(0);
66 topLayout
->addWidget(m_label
);
67 topLayout
->addWidget(m_progressBar
);
69 main
->setLayout(topLayout
);
72 // Use the directory size job to count the number of directories first. This
73 // allows to give a progress indication for the user when applying the view
75 m_dirSizeJob
= KIO::directorySize(dir
);
76 connect(m_dirSizeJob
, SIGNAL(result(KJob
*)),
77 this, SLOT(applyViewProperties()));
79 // The directory size job cannot emit any progress signal, as it is not aware
80 // about the total number of directories. Therefor a timer is triggered, which
81 // periodically updates the current directory count.
82 m_timer
= new QTimer(this);
83 connect(m_timer
, SIGNAL(timeout()),
84 this, SLOT(updateProgress()));
87 connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying()));
90 ViewPropsProgressInfo::~ViewPropsProgressInfo()
96 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
99 m_applyViewPropsJob
= 0;
100 KDialog::closeEvent(event
);
103 void ViewPropsProgressInfo::updateProgress()
105 if (m_dirSizeJob
!= 0) {
106 const int subdirs
= m_dirSizeJob
->totalSubdirs();
107 m_label
->setText(i18n("Counting folders: %1", subdirs
));
110 if (m_applyViewPropsJob
!= 0) {
111 const int progress
= m_applyViewPropsJob
->progress();
112 m_progressBar
->setValue(progress
);
116 void ViewPropsProgressInfo::applyViewProperties()
118 if (m_dirSizeJob
->error()) {
122 const int subdirs
= m_dirSizeJob
->totalSubdirs();
123 m_label
->setText(i18n("Folders: %1", subdirs
));
124 m_progressBar
->setMaximum(subdirs
);
128 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
129 connect(m_applyViewPropsJob
, SIGNAL(result(KJob
*)),
130 this, SLOT(close()));
133 void ViewPropsProgressInfo::cancelApplying()
135 if (m_dirSizeJob
!= 0) {
136 m_dirSizeJob
->doKill();
139 if (m_applyViewPropsJob
!= 0) {
140 m_applyViewPropsJob
->doKill();
144 #include "viewpropsprogressinfo.moc"