]>
cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropsapplier.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 "viewpropsapplier.h"
22 #include "viewproperties.h"
26 #include <kfileitem.h>
28 ViewPropsApplier::ViewPropsApplier(const KUrl
& dir
, const ViewProperties
* viewProps
)
30 m_rootData
= new RootData();
31 m_rootData
->refCount
= 0;
32 m_rootData
->viewProps
= viewProps
;
33 m_rootData
->rootApplier
= this;
38 ViewPropsApplier::~ViewPropsApplier()
40 assert(m_rootData
!= 0);
41 if (m_rootData
->refCount
== 0) {
42 m_rootData
->rootApplier
->emitCompleted();
51 void ViewPropsApplier::slotCompleted(const KUrl
& /*dir*/)
53 QTimer::singleShot(0, this, SLOT(countSubDirs()));
56 void ViewPropsApplier::countSubDirs()
58 KFileItemList list
= m_dirLister
->items();
59 const int dirCount
= list
.count();
61 m_rootData
->rootApplier
->emitProgress(m_dirLister
->url(), dirCount
);
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());
75 new ViewPropsApplier(subDir
, m_rootData
);
79 --(m_rootData
->refCount
);
80 if ((m_rootData
->refCount
== 0) || (m_rootData
->rootApplier
!= this)) {
85 ViewPropsApplier::ViewPropsApplier(const KUrl
& dir
,
88 m_rootData
= rootData
;
89 assert(m_rootData
!= 0);
93 void ViewPropsApplier::start(const KUrl
& dir
)
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
);
104 void ViewPropsApplier::emitProgress(const KUrl
& dir
, int count
)
106 emit
progress(dir
, count
);
109 void ViewPropsApplier::emitCompleted()
114 #include "viewpropsapplier.moc"