]> cloud.milkyroute.net Git - dolphin.git/blob - src/progressindicator.cpp
Fixed issue in method naturalCompare: strings having numbers with the same amount...
[dolphin.git] / src / progressindicator.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "progressindicator.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinstatusbar.h"
24 #include <QApplication>
25
26 ProgressIndicator::ProgressIndicator(DolphinMainWindow* mainWindow,
27 const QString& progressText,
28 const QString& finishedText,
29 int operationsCount)
30 : m_mainWindow(mainWindow),
31 m_showProgress(false),
32 m_operationsCount(operationsCount),
33 m_operationsIndex(0),
34 m_startTime(QTime::currentTime()),
35 m_finishedText(finishedText)
36 {
37 DolphinStatusBar* statusBar = mainWindow->activeView()->statusBar();
38 statusBar->clear();
39 statusBar->setProgressText(progressText);
40 statusBar->setProgress(0);
41 }
42
43
44 ProgressIndicator::~ProgressIndicator()
45 {
46 DolphinStatusBar* statusBar = m_mainWindow->activeView()->statusBar();
47 statusBar->setProgressText(QString::null);
48 statusBar->setProgress(100);
49 statusBar->setMessage(m_finishedText, DolphinStatusBar::OperationCompleted);
50
51 if (m_showProgress) {
52 m_mainWindow->setEnabled(true);
53 }
54 }
55
56 void ProgressIndicator::execOperation()
57 {
58 ++m_operationsIndex;
59
60 if (!m_showProgress) {
61 const int elapsed = m_startTime.msecsTo(QTime::currentTime());
62 if (elapsed > 500) {
63 // the operations took already more than 500 milliseconds,
64 // therefore show a progress indication
65 m_mainWindow->setEnabled(false);
66 m_showProgress = true;
67 }
68 }
69
70 if (m_showProgress) {
71 const QTime currentTime = QTime::currentTime();
72 if (m_startTime.msecsTo(currentTime) > 100) {
73 m_startTime = currentTime;
74
75 DolphinStatusBar* statusBar = m_mainWindow->activeView()->statusBar();
76 statusBar->setProgress((m_operationsIndex * 100) / m_operationsCount);
77 #warning "EVIL, DANGER, FIRE"
78 qApp->processEvents();
79 statusBar->repaint();
80 }
81 }
82 }
83
84