]> cloud.milkyroute.net Git - dolphin.git/blob - src/applyviewpropsjob.cpp
make it compile
[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 <kdebug.h>
27
28 ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir,
29 const ViewProperties& viewProps) :
30 KIO::Job(false),
31 m_viewProps(0),
32 m_progress(0),
33 m_dir(dir)
34 {
35 m_viewProps = new ViewProperties(dir);
36 m_viewProps->setViewMode(viewProps.viewMode());
37 m_viewProps->setShowPreview(viewProps.showPreview());
38 m_viewProps->setShowHiddenFiles(viewProps.showHiddenFiles());
39 m_viewProps->setSorting(viewProps.sorting());
40 m_viewProps->setSortOrder(viewProps.sortOrder());
41
42 startNextJob(dir);
43 }
44
45 ApplyViewPropsJob::~ApplyViewPropsJob()
46 {
47 delete m_viewProps; // the properties are written by the destructor
48 m_viewProps = 0;
49 }
50
51 void ApplyViewPropsJob::processNextItem()
52 {
53 emitResult();
54 }
55
56 void ApplyViewPropsJob::startNextJob(const KUrl& url)
57 {
58 KIO::ListJob* listJob = KIO::listRecursive(url, false);
59 connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
60 SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&)));
61 addSubjob(listJob);
62 }
63
64 void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
65 {
66 KIO::UDSEntryList::ConstIterator it = list.begin();
67 const KIO::UDSEntryList::ConstIterator end = list.end();
68 for (; it != end; ++it) {
69 const KIO::UDSEntry& entry = *it;
70 const QString name = entry.stringValue(KIO::UDS_NAME);
71 if ((name != ".") && (name != ".." ) && entry.isDir()) {
72 ++m_progress;
73
74 KUrl url(m_dir);
75 url.addPath(name);
76
77 ViewProperties props(url);
78 props.setViewMode(m_viewProps->viewMode());
79 props.setShowPreview(m_viewProps->showPreview());
80 props.setShowHiddenFiles(m_viewProps->showHiddenFiles());
81 props.setSorting(m_viewProps->sorting());
82 props.setSortOrder(m_viewProps->sortOrder());
83 }
84 }
85 }
86
87 void ApplyViewPropsJob::slotResult(KJob* job)
88 {
89 if (job->error()) {
90 setError( job->error() );
91 setErrorText( job->errorText() );
92 }
93 emitResult();
94 }
95
96 #include "applyviewpropsjob.moc"