X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8c7e12b1f7ae0699c85c4a0cbf29265a13766d43..6f5f07d391043175d955d62bd09c77af14164faf:/src/viewpropsprogressinfo.cpp diff --git a/src/viewpropsprogressinfo.cpp b/src/viewpropsprogressinfo.cpp index 680a852fc..8011dd301 100644 --- a/src/viewpropsprogressinfo.cpp +++ b/src/viewpropsprogressinfo.cpp @@ -15,44 +15,55 @@ * 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. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "viewpropsprogressinfo.h" -#include "viewpropsapplier.h" +#include "applyviewpropsjob.h" #include "viewproperties.h" -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include #include -#include #include 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")); + const QSize minSize = minimumSize(); + setMinimumSize(QSize(320, minSize.height())); + + setCaption(i18n("Applying View Properties")); setButtons(KDialog::Cancel); + m_viewProps = new ViewProperties(dir); + m_viewProps->setDirProperties(viewProps); + + // 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); @@ -60,67 +71,76 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, 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"