]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropsprogressinfo.cpp
Applying view properties recursively to sub directories works again (TODO: rewrite...
[dolphin.git] / src / viewpropsprogressinfo.cpp
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "viewpropsprogressinfo.h"
22 #include "viewpropsapplier.h"
23 #include "viewproperties.h"
24
25 #include <QLabel>
26 #include <QProgressBar>
27 #include <QTimer>
28 #include <QVBoxLayout>
29
30 #include <kdirsize.h>
31 #include <klocale.h>
32 #include <kurl.h>
33 #include <kio/jobclasses.h>
34
35 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
36 const KUrl& dir,
37 const ViewProperties* viewProps) :
38 KDialog(parent),
39 m_dirCount(0),
40 m_applyCount(0),
41 m_dir(dir),
42 m_viewProps(viewProps),
43 m_label(0),
44 m_progressBar(0),
45 m_dirSizeJob(0),
46 m_timer(0)
47 {
48 setCaption(i18n("Applying view properties"));
49 setButtons(KDialog::Cancel);
50
51 QWidget* main = new QWidget();
52 QVBoxLayout* topLayout = new QVBoxLayout();
53
54 m_label = new QLabel(i18n("Counting folders: %1", 0), main);
55 m_progressBar = new QProgressBar(main);
56
57 topLayout->addWidget(m_label);
58 topLayout->addWidget(m_progressBar);
59
60 main->setLayout(topLayout);
61 setMainWidget(main);
62
63 ViewPropsApplier* applier = new ViewPropsApplier(dir);
64 connect(applier, SIGNAL(progress(const KUrl&, int)),
65 this, SLOT(countDirs(const KUrl&, int)));
66 connect(applier, SIGNAL(completed()),
67 this, SLOT(applyViewProperties()));
68
69 // TODO: use KDirSize job instead. Current issue: the signal
70 // 'result' is not emitted with kdelibs 2006-12-05.
71
72 /*m_dirSizeJob = KDirSize::dirSizeJob(dir);
73 connect(m_dirSizeJob, SIGNAL(result(KJob*)),
74 this, SLOT(slotResult(KJob*)));
75
76 m_timer = new QTimer(this);
77 connect(m_timer, SIGNAL(timeout()),
78 this, SLOT(updateDirCounter()));
79 m_timer->start(300);*/
80 }
81
82 ViewPropsProgressInfo::~ViewPropsProgressInfo()
83 {
84 }
85
86 void ViewPropsProgressInfo::countDirs(const KUrl& /*dir*/, int count)
87 {
88 m_dirCount += count;
89 m_label->setText(i18n("Counting folders: %1", m_dirCount));
90 }
91
92 /*void ViewPropsProgressInfo::updateDirCounter()
93 {
94 const int subdirs = m_dirSizeJob->totalSubdirs();
95 m_label->setText(i18n("Counting folders: %1", subdirs));
96 }
97
98 void ViewPropsProgressInfo::slotResult(KJob*)
99 {
100 QTimer::singleShot(0, this, SLOT(applyViewProperties()));
101 }*/
102
103 void ViewPropsProgressInfo::applyViewProperties()
104 {
105 //m_timer->stop();
106 //const int subdirs = m_dirSizeJob->totalSubdirs();
107 //m_label->setText(i18n("Folders: %1", subdirs));
108 //m_progressBar->setMaximum(subdirs);
109
110 m_label->setText(i18n("Folders: %1", m_dirCount));
111 m_progressBar->setMaximum(m_dirCount);
112
113 ViewPropsApplier* applier = new ViewPropsApplier(m_dir, m_viewProps);
114 connect(applier, SIGNAL(progress(const KUrl&, int)),
115 this, SLOT(showProgress(const KUrl&, int)));
116 connect(applier, SIGNAL(completed()),
117 this, SLOT(close()));
118 }
119
120 void ViewPropsProgressInfo::showProgress(const KUrl& url, int count)
121 {
122 m_applyCount += count;
123 m_progressBar->setValue(m_applyCount);
124 }
125
126 #include "viewpropsprogressinfo.moc"