]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropsapplier.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / viewpropsapplier.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 "viewpropsapplier.h"
22 #include "viewproperties.h"
23
24 #include <assert.h>
25 #include <kurl.h>
26 #include <kfileitem.h>
27
28 ViewPropsApplier::ViewPropsApplier(const KUrl& dir, const ViewProperties* viewProps)
29 {
30 m_rootData = new RootData();
31 m_rootData->refCount = 0;
32 m_rootData->viewProps = viewProps;
33 m_rootData->rootApplier = this;
34
35 start(dir);
36 }
37
38 ViewPropsApplier::~ViewPropsApplier()
39 {
40 assert(m_rootData != 0);
41 if (m_rootData->refCount == 0) {
42 m_rootData->rootApplier->emitCompleted();
43 delete m_rootData;
44 m_rootData = 0;
45 }
46
47 delete m_dirLister;
48 m_dirLister = 0;
49 }
50
51 void ViewPropsApplier::slotCompleted(const KUrl& /*dir*/)
52 {
53 QTimer::singleShot(0, this, SLOT(countSubDirs()));
54 }
55
56 void ViewPropsApplier::countSubDirs()
57 {
58 KFileItemList list = m_dirLister->items();
59 const int dirCount = list.count();
60 if (dirCount > 0) {
61 m_rootData->rootApplier->emitProgress(m_dirLister->url(), dirCount);
62
63 KFileItemList::const_iterator end = list.end();
64 for (KFileItemList::const_iterator it = list.begin(); it != end; ++it) {
65 assert((*it)->isDir());
66 const KUrl& subDir = (*it)->url();
67 if (m_rootData->viewProps != 0) {
68 // TODO: provide copy constructor in ViewProperties
69 ViewProperties props(subDir);
70 props.setViewMode(m_rootData->viewProps->viewMode());
71 props.setShowHiddenFilesEnabled(m_rootData->viewProps->sorting());
72 props.setSorting(m_rootData->viewProps->sorting());
73 props.setSortOrder(m_rootData->viewProps->sortOrder());
74 }
75 new ViewPropsApplier(subDir, m_rootData);
76 }
77 }
78
79 --(m_rootData->refCount);
80 if ((m_rootData->refCount == 0) || (m_rootData->rootApplier != this)) {
81 delete this;
82 }
83 }
84
85 ViewPropsApplier::ViewPropsApplier(const KUrl& dir,
86 RootData* rootData)
87 {
88 m_rootData = rootData;
89 assert(m_rootData != 0);
90 start(dir);
91 }
92
93 void ViewPropsApplier::start(const KUrl& dir)
94 {
95 m_dirLister = new KDirLister();
96 m_dirLister->setDirOnlyMode(true);
97 m_dirLister->setAutoUpdate(false);
98 connect(m_dirLister, SIGNAL(completed(const KUrl&)),
99 this, SLOT(slotCompleted(const KUrl&)));
100 m_dirLister->openUrl(dir);
101 ++(m_rootData->refCount);
102 }
103
104 void ViewPropsApplier::emitProgress(const KUrl& dir, int count)
105 {
106 emit progress(dir, count);
107 }
108
109 void ViewPropsApplier::emitCompleted()
110 {
111 emit completed();
112 }
113
114 #include "viewpropsapplier.moc"