***************************************************************************/
#include "viewpropsprogressinfo.h"
-#include "viewpropsapplier.h"
+#include "applyviewpropsjob.h"
#include "viewproperties.h"
#include <QLabel>
#include <QTimer>
#include <QVBoxLayout>
-#include <kdirsize.h>
+#include <assert.h>
#include <klocale.h>
#include <kurl.h>
#include <kio/jobclasses.h>
ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
const KUrl& dir,
- const ViewProperties* viewProps) :
+ const ViewProperties& viewProps) :
KDialog(parent),
- m_dirCount(0),
- m_applyCount(0),
m_dir(dir),
- m_viewProps(viewProps),
+ m_viewProps(0),
m_label(0),
m_progressBar(0),
m_dirSizeJob(0),
+ m_applyViewPropsJob(0),
m_timer(0)
{
setCaption(i18n("Applying view properties"));
setButtons(KDialog::Cancel);
+ 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());
+
+ // the view properties are stored by the ViewPropsApplierJob, so prevent
+ // that the view properties are saved twice:
+ m_viewProps->setAutoSaveEnabled(false);
+
QWidget* main = new QWidget();
QVBoxLayout* topLayout = new QVBoxLayout();
m_label = new QLabel(i18n("Counting folders: %1", 0), main);
m_progressBar = new QProgressBar(main);
+ m_progressBar->setMinimum(0);
+ m_progressBar->setMaximum(0);
+ m_progressBar->setValue(0);
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);
+ // Use the directory size job to count the number of directories first. This
+ // allows to give a progress indication for the user when applying the view
+ // properties later.
+ m_dirSizeJob = KIO::directorySize(dir);
connect(m_dirSizeJob, SIGNAL(result(KJob*)),
- this, SLOT(slotResult(KJob*)));
+ this, SLOT(applyViewProperties()));
+ // The directory size job cannot emit any progress signal, as it is not aware
+ // about the total number of directories. Therefor a timer is triggered, which
+ // periodically updates the current directory count.
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()),
- this, SLOT(updateDirCounter()));
- m_timer->start(300);*/
+ this, SLOT(updateProgress()));
+ m_timer->start(300);
+
+ connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying()));
}
ViewPropsProgressInfo::~ViewPropsProgressInfo()
{
+ delete m_viewProps;
+ m_viewProps = 0;
}
-void ViewPropsProgressInfo::countDirs(const KUrl& /*dir*/, int count)
+void ViewPropsProgressInfo::closeEvent(QCloseEvent* event)
{
- m_dirCount += count;
- m_label->setText(i18n("Counting folders: %1", m_dirCount));
+ m_timer->stop();
+ m_applyViewPropsJob = 0;
+ KDialog::closeEvent(event);
}
-/*void ViewPropsProgressInfo::updateDirCounter()
+void ViewPropsProgressInfo::updateProgress()
{
- const int subdirs = m_dirSizeJob->totalSubdirs();
- m_label->setText(i18n("Counting folders: %1", subdirs));
+ if (m_dirSizeJob != 0) {
+ const int subdirs = m_dirSizeJob->totalSubdirs();
+ m_label->setText(i18n("Counting folders: %1", subdirs));
+ }
+
+ if (m_applyViewPropsJob != 0) {
+ const int progress = m_applyViewPropsJob->progress();
+ m_progressBar->setValue(progress);
+ }
}
-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()),
+ if (m_dirSizeJob->error()) {
+ return;
+ }
+
+ const int subdirs = m_dirSizeJob->totalSubdirs();
+ m_label->setText(i18n("Folders: %1", subdirs));
+ m_progressBar->setMaximum(subdirs);
+
+ m_dirSizeJob = 0;
+
+ m_applyViewPropsJob = new ApplyViewPropsJob(m_dir, *m_viewProps);
+ connect(m_applyViewPropsJob, SIGNAL(result(KJob*)),
this, SLOT(close()));
}
-void ViewPropsProgressInfo::showProgress(const KUrl& url, int count)
+void ViewPropsProgressInfo::cancelApplying()
{
- m_applyCount += count;
- m_progressBar->setValue(m_applyCount);
+ if (m_dirSizeJob != 0) {
+ m_dirSizeJob->doKill();
+ }
+
+ if (m_applyViewPropsJob != 0) {
+ m_applyViewPropsJob->doKill();
+ }
}
#include "viewpropsprogressinfo.moc"