]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/applyviewpropsjob.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[dolphin.git] / src / settings / applyviewpropsjob.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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 <views/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->setPreviewsShown(viewProps.previewsShown());
36 m_viewProps->setHiddenFilesShown(viewProps.hiddenFilesShown());
37 m_viewProps->setSortRole(viewProps.sortRole());
38 m_viewProps->setSortOrder(viewProps.sortOrder());
39
40 KIO::ListJob* listJob = KIO::listRecursive(dir, KIO::HideProgressInfo);
41 connect(listJob, &KIO::ListJob::entries,
42 this, &ApplyViewPropsJob::slotEntries);
43 addSubjob(listJob);
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::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
53 {
54 foreach (const KIO::UDSEntry& entry, list) {
55 const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
56 if (name != QLatin1String(".") && name != QLatin1String("..") && entry.isDir()) {
57 ++m_progress;
58
59 KUrl url(m_dir);
60 url.addPath(name);
61
62 Q_ASSERT(m_viewProps);
63
64 ViewProperties props(url);
65 props.setDirProperties(*m_viewProps);
66 }
67 }
68 }
69
70 void ApplyViewPropsJob::slotResult(KJob* job)
71 {
72 if (job->error()) {
73 setError(job->error());
74 setErrorText(job->errorText());
75 }
76 emitResult();
77 }
78