]> cloud.milkyroute.net Git - dolphin.git/blob - src/applyviewpropsjob.cpp
As requested by Peter: upgrade version to 1.0
[dolphin.git] / src / applyviewpropsjob.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * The code is based on kdelibs/kio/directorysizejob.* *
5 * (C) 2006 by David Faure <faure@kde.org> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #include "applyviewpropsjob.h"
24 #include "viewproperties.h"
25
26 #include <assert.h>
27 #include <kdebug.h>
28
29 ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir,
30 const ViewProperties& viewProps) :
31 KIO::Job(),
32 m_viewProps(0),
33 m_progress(0),
34 m_dir(dir)
35 {
36 m_viewProps = new ViewProperties(dir);
37 m_viewProps->setViewMode(viewProps.viewMode());
38 m_viewProps->setShowPreview(viewProps.showPreview());
39 m_viewProps->setShowHiddenFiles(viewProps.showHiddenFiles());
40 m_viewProps->setSorting(viewProps.sorting());
41 m_viewProps->setSortOrder(viewProps.sortOrder());
42
43 startNextJob(dir);
44 }
45
46 ApplyViewPropsJob::~ApplyViewPropsJob()
47 {
48 delete m_viewProps; // the properties are written by the destructor
49 m_viewProps = 0;
50 }
51
52 void ApplyViewPropsJob::processNextItem()
53 {
54 emitResult();
55 }
56
57 void ApplyViewPropsJob::startNextJob(const KUrl& url)
58 {
59 KIO::ListJob* listJob = KIO::listRecursive(url, KIO::HideProgressInfo);
60 connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
61 SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&)));
62 addSubjob(listJob);
63 }
64
65 void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
66 {
67 KIO::UDSEntryList::ConstIterator it = list.begin();
68 const KIO::UDSEntryList::ConstIterator end = list.end();
69 for (; it != end; ++it) {
70 const KIO::UDSEntry& entry = *it;
71 const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
72 if ((name != ".") && (name != "..") && entry.isDir()) {
73 ++m_progress;
74
75 KUrl url(m_dir);
76 url.addPath(name);
77
78 assert(m_viewProps != 0);
79
80 ViewProperties props(url);
81 props.setDirProperties(*m_viewProps);
82 }
83 }
84 }
85
86 void ApplyViewPropsJob::slotResult(KJob* job)
87 {
88 if (job->error()) {
89 setError(job->error());
90 setErrorText(job->errorText());
91 }
92 emitResult();
93 }
94
95 #include "applyviewpropsjob.moc"