From: Peter Penz Date: Tue, 5 Dec 2006 22:48:35 +0000 (+0000) Subject: Applying view properties recursively to sub directories works again (TODO: rewrite... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/8c7e12b1f7ae0699c85c4a0cbf29265a13766d43 Applying view properties recursively to sub directories works again (TODO: rewrite ViewPropsApplier completely as KJob implementation). svn path=/trunk/playground/utils/dolphin/; revision=610887 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ee66d31a..cdec284c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,9 @@ set(dolphin_SRCS statusbarspaceinfo.cpp renamedialog.cpp filterbar.cpp - protocolcombo.cpp ) + protocolcombo.cpp + viewpropsprogressinfo.cpp + viewpropsapplier.cpp ) kde4_automoc(${dolphin_SRCS}) diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp index 594c487d2..0a4e8bd9d 100644 --- a/src/viewpropertiesdialog.cpp +++ b/src/viewpropertiesdialog.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "viewpropertiesdialog.h" +#include "viewpropsprogressinfo.h" #include #include @@ -214,11 +215,11 @@ void ViewPropertiesDialog::applyViewProperties() } } - ViewProperties props(QDir::homePath()); - props.setViewMode(m_viewProps->viewMode()); - props.setSorting(m_viewProps->sorting()); - props.setSortOrder(m_viewProps->sortOrder()); - props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled()); + //ViewProperties props(QDir::homePath()); + //props.setViewMode(m_viewProps->viewMode()); + //props.setSorting(m_viewProps->sorting()); + //props.setSortOrder(m_viewProps->sortOrder()); + //props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled()); //props.setValidForSubDirs(true); } else if (m_applyToSubFolders->isChecked() && m_isDirty) { @@ -226,6 +227,9 @@ void ViewPropertiesDialog::applyViewProperties() if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { return; } + + ViewPropsProgressInfo dlg(this, m_dolphinView->url(), m_viewProps); + dlg.exec(); } m_viewProps->save(); diff --git a/src/viewpropertiesdialog.h b/src/viewpropertiesdialog.h index adaf8f45d..79500a998 100644 --- a/src/viewpropertiesdialog.h +++ b/src/viewpropertiesdialog.h @@ -45,11 +45,9 @@ public: ViewPropertiesDialog(DolphinView* dolphinView); virtual ~ViewPropertiesDialog(); -protected slots: - virtual void slotOk(); - virtual void slotApply(); - private slots: + void slotOk(); + void slotApply(); void slotViewModeChanged(int index); void slotSortingChanged(int index); void slotSortOrderChanged(int index); diff --git a/src/viewpropsapplier.cpp b/src/viewpropsapplier.cpp new file mode 100644 index 000000000..f9992a619 --- /dev/null +++ b/src/viewpropsapplier.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 "viewpropsapplier.h" +#include "viewproperties.h" + +#include +#include +#include + +ViewPropsApplier::ViewPropsApplier(const KUrl& dir, const ViewProperties* viewProps) +{ + m_rootData = new RootData(); + m_rootData->refCount = 0; + m_rootData->viewProps = viewProps; + m_rootData->rootApplier = this; + + start(dir); +} + +ViewPropsApplier::~ViewPropsApplier() +{ + assert(m_rootData != 0); + if (m_rootData->refCount == 0) { + m_rootData->rootApplier->emitCompleted(); + delete m_rootData; + m_rootData = 0; + } + + delete m_dirLister; + m_dirLister = 0; +} + +void ViewPropsApplier::slotCompleted(const KUrl& /*dir*/) +{ + QTimer::singleShot(0, this, SLOT(countSubDirs())); +} + +void ViewPropsApplier::countSubDirs() +{ + KFileItemList list = m_dirLister->items(); + const int dirCount = list.count(); + if (dirCount > 0) { + m_rootData->rootApplier->emitProgress(m_dirLister->url(), dirCount); + + KFileItemList::const_iterator end = list.end(); + for (KFileItemList::const_iterator it = list.begin(); it != end; ++it) { + assert((*it)->isDir()); + const KUrl& subDir = (*it)->url(); + if (m_rootData->viewProps != 0) { + // TODO: provide copy constructor in ViewProperties + ViewProperties props(subDir); + props.setViewMode(m_rootData->viewProps->viewMode()); + props.setShowHiddenFilesEnabled(m_rootData->viewProps->sorting()); + props.setSorting(m_rootData->viewProps->sorting()); + props.setSortOrder(m_rootData->viewProps->sortOrder()); + } + new ViewPropsApplier(subDir, m_rootData); + } + } + + --(m_rootData->refCount); + if ((m_rootData->refCount == 0) || (m_rootData->rootApplier != this)) { + delete this; + } +} + +ViewPropsApplier::ViewPropsApplier(const KUrl& dir, + RootData* rootData) +{ + m_rootData = rootData; + assert(m_rootData != 0); + start(dir); +} + +void ViewPropsApplier::start(const KUrl& dir) +{ + m_dirLister = new KDirLister(); + m_dirLister->setDirOnlyMode(true); + m_dirLister->setAutoUpdate(false); + connect(m_dirLister, SIGNAL(completed(const KUrl&)), + this, SLOT(slotCompleted(const KUrl&))); + m_dirLister->openUrl(dir); + ++(m_rootData->refCount); +} + +void ViewPropsApplier::emitProgress(const KUrl& dir, int count) +{ + emit progress(dir, count); +} + +void ViewPropsApplier::emitCompleted() +{ + emit completed(); +} + +#include "viewpropsapplier.moc" diff --git a/src/viewpropsapplier.h b/src/viewpropsapplier.h new file mode 100644 index 000000000..f564a4fe7 --- /dev/null +++ b/src/viewpropsapplier.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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. * + ***************************************************************************/ +#ifndef VIEWPROPSAPPLIER_H +#define VIEWPROPSAPPLIER_H + +#include +#include + +class KUrl; +class KDirLister; +class ViewProperties; + +/** + * @brief Applies view properties recursively to sub directories. + * + * BIG TODO: This class must be rewritten by inheriting from KJob (see + * also KDirSize as reference). The current implementation gets nuts + * for deep directory hierarchies, as an incredible number of parallel + * KDirLister instances will be created. + * + * Anyhow when writing this class I was not aware about the capabilities + * of the KJob class -> lessons learned ;-) + */ +class ViewPropsApplier : public QObject +{ + Q_OBJECT + +public: + /** + * @param dir Directory where the view properties should be applied to + * (including sub directories). + * @param viewProps View properties for the directory \a dir including its + * sub directories. + */ + ViewPropsApplier(const KUrl& dir, + const ViewProperties* viewProps = 0); + virtual ~ViewPropsApplier(); + +signals: + void progress(const KUrl& dir, int count); + void completed(); + +private slots: + void slotCompleted(const KUrl& dir); + void countSubDirs(); + +private: + struct RootData { + int refCount; + const ViewProperties* viewProps; + ViewPropsApplier* rootApplier; + }; + + ViewPropsApplier(const KUrl& dir, + RootData* rootData); + + + void start(const KUrl& dir); + void emitProgress(const KUrl& dir, int count); + void emitCompleted(); + + RootData* m_rootData; + KDirLister* m_dirLister; +}; + +#endif diff --git a/src/viewpropsprogressinfo.cpp b/src/viewpropsprogressinfo.cpp new file mode 100644 index 000000000..680a852fc --- /dev/null +++ b/src/viewpropsprogressinfo.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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 "viewpropsprogressinfo.h" +#include "viewpropsapplier.h" +#include "viewproperties.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, + const KUrl& dir, + const ViewProperties* viewProps) : + KDialog(parent), + m_dirCount(0), + m_applyCount(0), + m_dir(dir), + m_viewProps(viewProps), + m_label(0), + m_progressBar(0), + m_dirSizeJob(0), + m_timer(0) +{ + setCaption(i18n("Applying view properties")); + setButtons(KDialog::Cancel); + + QWidget* main = new QWidget(); + QVBoxLayout* topLayout = new QVBoxLayout(); + + m_label = new QLabel(i18n("Counting folders: %1", 0), main); + m_progressBar = new QProgressBar(main); + + topLayout->addWidget(m_label); + topLayout->addWidget(m_progressBar); + + main->setLayout(topLayout); + setMainWidget(main); + + ViewPropsApplier* applier = new ViewPropsApplier(dir); + connect(applier, SIGNAL(progress(const KUrl&, int)), + this, SLOT(countDirs(const KUrl&, int))); + connect(applier, SIGNAL(completed()), + this, SLOT(applyViewProperties())); + + // TODO: use KDirSize job instead. Current issue: the signal + // 'result' is not emitted with kdelibs 2006-12-05. + + /*m_dirSizeJob = KDirSize::dirSizeJob(dir); + connect(m_dirSizeJob, SIGNAL(result(KJob*)), + this, SLOT(slotResult(KJob*))); + + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), + this, SLOT(updateDirCounter())); + m_timer->start(300);*/ +} + +ViewPropsProgressInfo::~ViewPropsProgressInfo() +{ +} + +void ViewPropsProgressInfo::countDirs(const KUrl& /*dir*/, int count) +{ + m_dirCount += count; + m_label->setText(i18n("Counting folders: %1", m_dirCount)); +} + +/*void ViewPropsProgressInfo::updateDirCounter() +{ + const int subdirs = m_dirSizeJob->totalSubdirs(); + m_label->setText(i18n("Counting folders: %1", subdirs)); +} + +void ViewPropsProgressInfo::slotResult(KJob*) +{ + QTimer::singleShot(0, this, SLOT(applyViewProperties())); +}*/ + +void ViewPropsProgressInfo::applyViewProperties() +{ + //m_timer->stop(); + //const int subdirs = m_dirSizeJob->totalSubdirs(); + //m_label->setText(i18n("Folders: %1", subdirs)); + //m_progressBar->setMaximum(subdirs); + + m_label->setText(i18n("Folders: %1", m_dirCount)); + m_progressBar->setMaximum(m_dirCount); + + ViewPropsApplier* applier = new ViewPropsApplier(m_dir, m_viewProps); + connect(applier, SIGNAL(progress(const KUrl&, int)), + this, SLOT(showProgress(const KUrl&, int))); + connect(applier, SIGNAL(completed()), + this, SLOT(close())); +} + +void ViewPropsProgressInfo::showProgress(const KUrl& url, int count) +{ + m_applyCount += count; + m_progressBar->setValue(m_applyCount); +} + +#include "viewpropsprogressinfo.moc" diff --git a/src/viewpropsprogressinfo.h b/src/viewpropsprogressinfo.h new file mode 100644 index 000000000..6d8b8f0c1 --- /dev/null +++ b/src/viewpropsprogressinfo.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * 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. * + ***************************************************************************/ +#ifndef VIEWPROPSPROGRESSINFO_H +#define VIEWPROPSPROGRESSINFO_H + +#include + +class KDirSize; +class KJob; +class KUrl; +class QLabel; +class QProgressBar; +class QTimer; +class ViewProperties; + +/** + * @brief Shows the progress when applying view properties recursively to + * sub directories. + */ +class ViewPropsProgressInfo : public KDialog +{ + Q_OBJECT + +public: + /** + * @param parent Parent widget of the dialog. + * @param dir Directory where the view properties should be applied to + * (including sub directories). + * @param viewProps View properties for the directory \a dir including its + * sub directories. + */ + ViewPropsProgressInfo(QWidget* parent, + const KUrl& dir, + const ViewProperties* viewProps); + + virtual ~ViewPropsProgressInfo(); + +private slots: + void countDirs(const KUrl& dir, int count); + //void updateDirCounter(); + //void slotResult(KJob* job); + void applyViewProperties(); + void showProgress(const KUrl& url, int count); + +private: + int m_dirCount; + int m_applyCount; + const KUrl& m_dir; + const ViewProperties* m_viewProps; + QLabel* m_label; + QProgressBar* m_progressBar; + KDirSize* m_dirSizeJob; + QTimer* m_timer; +}; + +#endif