]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/applyviewpropsjob.cpp
183c85225822af51e25644620c5845f46da98a01
[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
25 #include "views/viewproperties.h"
26
27 ApplyViewPropsJob::ApplyViewPropsJob(const QUrl& dir,
28 const ViewProperties& viewProps) :
29 KIO::Job(),
30 m_viewProps(nullptr),
31 m_progress(0),
32 m_dir(dir)
33 {
34 m_viewProps = new ViewProperties(dir);
35 m_viewProps->setViewMode(viewProps.viewMode());
36 m_viewProps->setPreviewsShown(viewProps.previewsShown());
37 m_viewProps->setHiddenFilesShown(viewProps.hiddenFilesShown());
38 m_viewProps->setSortRole(viewProps.sortRole());
39 m_viewProps->setSortOrder(viewProps.sortOrder());
40
41 KIO::ListJob* listJob = KIO::listRecursive(dir, KIO::HideProgressInfo);
42 connect(listJob, &KIO::ListJob::entries,
43 this, &ApplyViewPropsJob::slotEntries);
44 addSubjob(listJob);
45 }
46
47 ApplyViewPropsJob::~ApplyViewPropsJob()
48 {
49 delete m_viewProps; // the properties are written by the destructor
50 m_viewProps = nullptr;
51 }
52
53 void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
54 {
55 foreach (const KIO::UDSEntry& entry, list) {
56 const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
57 if (name != QLatin1Char('.') && name != QLatin1String("..") && entry.isDir()) {
58 ++m_progress;
59
60 QUrl url(m_dir);
61 url = url.adjusted(QUrl::StripTrailingSlash);
62 url.setPath(url.path() + '/' + name);
63
64 Q_ASSERT(m_viewProps);
65
66 ViewProperties props(url);
67 props.setDirProperties(*m_viewProps);
68 }
69 }
70 }
71
72 void ApplyViewPropsJob::slotResult(KJob* job)
73 {
74 if (job->error()) {
75 setError(job->error());
76 setErrorText(job->errorText());
77 }
78 emitResult();
79 }
80