┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/applyviewpropsjob.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2006-12-07 17:22:51 +0000
committerPeter Penz <[email protected]>2006-12-07 17:22:51 +0000
commitced7cbd022b68c8dedd61b5d34d27b9c1296df15 (patch)
tree96b3098444d38fa84675364ee25cb4a033bf2c43 /src/applyviewpropsjob.cpp
parentd3611c41f4c453c81d95e013c68ddf65c94e9bc0 (diff)
Use a KIO Job for applying the view properties recursively to sub directories.
svn path=/trunk/playground/utils/dolphin/; revision=611325
Diffstat (limited to 'src/applyviewpropsjob.cpp')
-rw-r--r--src/applyviewpropsjob.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/applyviewpropsjob.cpp b/src/applyviewpropsjob.cpp
new file mode 100644
index 000000000..539c52ee1
--- /dev/null
+++ b/src/applyviewpropsjob.cpp
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Peter Penz <[email protected]> *
+ * *
+ * The code is based on kdelibs/kio/directorysizejob.* *
+ * (C) 2006 by David Faure <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "applyviewpropsjob.h"
+#include "viewproperties.h"
+
+#include <kdebug.h>
+
+ApplyViewPropsJob::ApplyViewPropsJob(const KUrl& dir,
+ const ViewProperties& viewProps) :
+ KIO::Job(false),
+ m_viewProps(0),
+ m_progress(0),
+ m_dir(dir)
+{
+ m_viewProps = new ViewProperties(dir);
+ m_viewProps->setViewMode(viewProps.viewMode());
+ m_viewProps->setShowHiddenFilesEnabled(viewProps.isShowHiddenFilesEnabled());
+ m_viewProps->setSorting(viewProps.sorting());
+ m_viewProps->setSortOrder(viewProps.sortOrder());
+
+ startNextJob(dir, viewProps);
+}
+
+ApplyViewPropsJob::~ApplyViewPropsJob()
+{
+ delete m_viewProps; // the properties are written by the destructor
+ m_viewProps = 0;
+}
+
+void ApplyViewPropsJob::processNextItem()
+{
+ emitResult();
+}
+
+void ApplyViewPropsJob::startNextJob(const KUrl& url,
+ const ViewProperties& viewProps)
+{
+ KIO::ListJob* listJob = KIO::listRecursive(url, false);
+ connect(listJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
+ SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&)));
+ addSubjob(listJob);
+}
+
+void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
+{
+ KIO::UDSEntryList::ConstIterator it = list.begin();
+ const KIO::UDSEntryList::ConstIterator end = list.end();
+ for (; it != end; ++it) {
+ const KIO::UDSEntry& entry = *it;
+ const QString name = entry.stringValue(KIO::UDS_NAME);
+ if ((name != ".") && (name != ".." ) && entry.isDir()) {
+ ++m_progress;
+
+ KUrl url(m_dir);
+ url.addPath(name);
+
+ ViewProperties props(url);
+ props.setViewMode(m_viewProps->viewMode());
+ props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled());
+ props.setSorting(m_viewProps->sorting());
+ props.setSortOrder(m_viewProps->sortOrder());
+ }
+ }
+}
+
+void ApplyViewPropsJob::slotResult(KJob* job)
+{
+ if (job->error()) {
+ setError( job->error() );
+ setErrorText( job->errorText() );
+ }
+ emitResult();
+}
+
+#include "applyviewpropsjob.moc"