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