]>
cloud.milkyroute.net Git - dolphin.git/blob - src/viewpropsprogressinfo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "viewpropsprogressinfo.h"
22 #include "applyviewpropsjob.h"
23 #include "viewproperties.h"
26 #include <QProgressBar>
28 #include <QVBoxLayout>
33 #include <kio/jobclasses.h>
35 ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget
* parent
,
37 const ViewProperties
& viewProps
) :
44 m_applyViewPropsJob(0),
47 setCaption(i18n("Applying view properties"));
48 setButtons(KDialog::Cancel
);
50 m_viewProps
= new ViewProperties(dir
);
51 m_viewProps
->setViewMode(viewProps
.viewMode());
52 m_viewProps
->setShowHiddenFilesEnabled(viewProps
.isShowHiddenFilesEnabled());
53 m_viewProps
->setSorting(viewProps
.sorting());
54 m_viewProps
->setSortOrder(viewProps
.sortOrder());
56 // the view properties are stored by the ViewPropsApplierJob, so prevent
57 // that the view properties are saved twice:
58 m_viewProps
->setAutoSaveEnabled(false);
60 QWidget
* main
= new QWidget();
61 QVBoxLayout
* topLayout
= new QVBoxLayout();
63 m_label
= new QLabel(i18n("Counting folders: %1", 0), main
);
64 m_progressBar
= new QProgressBar(main
);
65 m_progressBar
->setMinimum(0);
66 m_progressBar
->setMaximum(0);
67 m_progressBar
->setValue(0);
69 topLayout
->addWidget(m_label
);
70 topLayout
->addWidget(m_progressBar
);
72 main
->setLayout(topLayout
);
75 // Use the directory size job to count the number of directories first. This
76 // allows to give a progress indication for the user when applying the view
78 m_dirSizeJob
= KIO::directorySize(dir
);
79 connect(m_dirSizeJob
, SIGNAL(result(KJob
*)),
80 this, SLOT(applyViewProperties()));
82 // The directory size job cannot emit any progress signal, as it is not aware
83 // about the total number of directories. Therefor a timer is triggered, which
84 // periodically updates the current directory count.
85 m_timer
= new QTimer(this);
86 connect(m_timer
, SIGNAL(timeout()),
87 this, SLOT(updateProgress()));
90 connect(this, SIGNAL(cancelClicked()), this, SLOT(cancelApplying()));
93 ViewPropsProgressInfo::~ViewPropsProgressInfo()
99 void ViewPropsProgressInfo::closeEvent(QCloseEvent
* event
)
102 m_applyViewPropsJob
= 0;
103 KDialog::closeEvent(event
);
106 void ViewPropsProgressInfo::updateProgress()
108 if (m_dirSizeJob
!= 0) {
109 const int subdirs
= m_dirSizeJob
->totalSubdirs();
110 m_label
->setText(i18n("Counting folders: %1", subdirs
));
113 if (m_applyViewPropsJob
!= 0) {
114 const int progress
= m_applyViewPropsJob
->progress();
115 m_progressBar
->setValue(progress
);
119 void ViewPropsProgressInfo::applyViewProperties()
121 if (m_dirSizeJob
->error()) {
125 const int subdirs
= m_dirSizeJob
->totalSubdirs();
126 m_label
->setText(i18n("Folders: %1", subdirs
));
127 m_progressBar
->setMaximum(subdirs
);
131 m_applyViewPropsJob
= new ApplyViewPropsJob(m_dir
, *m_viewProps
);
132 connect(m_applyViewPropsJob
, SIGNAL(result(KJob
*)),
133 this, SLOT(close()));
136 void ViewPropsProgressInfo::cancelApplying()
138 if (m_dirSizeJob
!= 0) {
139 m_dirSizeJob
->doKill();
142 if (m_applyViewPropsJob
!= 0) {
143 m_applyViewPropsJob
->doKill();
147 #include "viewpropsprogressinfo.moc"