1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Applying view properties recursively to sub directories works again (TODO: rewrite ViewPropsApplier completely as KJob implementation).

svn path=/trunk/playground/utils/dolphin/; revision=610887
This commit is contained in:
Peter Penz 2006-12-05 22:48:35 +00:00
parent d567bc3aea
commit 8c7e12b1f7
7 changed files with 410 additions and 10 deletions

View File

@ -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})

View File

@ -19,6 +19,7 @@
***************************************************************************/
#include "viewpropertiesdialog.h"
#include "viewpropsprogressinfo.h"
#include <klocale.h>
#include <kiconloader.h>
@ -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();

View File

@ -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);

114
src/viewpropsapplier.cpp Normal file
View File

@ -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 <assert.h>
#include <kurl.h>
#include <kfileitem.h>
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"

83
src/viewpropsapplier.h Normal file
View File

@ -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 <QObject>
#include <kdirlister.h>
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

View File

@ -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 <QLabel>
#include <QProgressBar>
#include <QTimer>
#include <QVBoxLayout>
#include <kdirsize.h>
#include <klocale.h>
#include <kurl.h>
#include <kio/jobclasses.h>
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"

View File

@ -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 <kdialog.h>
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