summaryrefslogtreecommitdiffstats
path: root/src/progressindicator.h
blob: 7889607f74dc2fcc9766e169df89cdeba58ab6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/***************************************************************************
 *   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.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#ifndef PROGRESSINDICATOR_H
#define PROGRESSINDICATOR_H

#include <qdatetime.h>

/**
 * Allows to show a progress of synchronous operations. Sample code:
 * \code
 * const int operationsCount = 100;
 * ProgressIndicator progressIndicator(i18n("Loading..."),
 *                                     i18n("Loading finished."),
 *                                     operationsCount);
 * for (int i = 0; i < operationsCount; ++i) {
 *     progressIndicator.execOperation();
 *     // do synchronous operation...
 * }
 * \endcode
 * The progress indicator takes care to show the progress bar only after
 * a delay of around 500 milliseconds. This means if all operations are
 * executing within 500 milliseconds, no progress bar is shown at all.
 * As soon as the progress bar is shown, the application still may process
 * events, but the the Dolphin main widget is disabled.
 *
 *	@author Peter Penz <peter.penz@gmx.at>
 */
class ProgressIndicator
{
public:
    /**
     * @param progressText      Text for the progress bar (e. g. "Loading...").
     * @param finishedText      Text which is displayed after the operations have been finished
     *                          (e. g. "Loading finished.").
     * @param operationsCount   Number of operations.
     */
    ProgressIndicator(const QString& progressText,
                      const QString& finishedText,
                      int operationsCount);

    /**
     * Sets the progress to 100 % and displays the 'finishedText' property
     *  in the status bar.
     */
    ~ProgressIndicator();

    /**
     * Increases the progress and should be invoked
     * before each operation.
     */
    void execOperation();

private:
    bool m_showProgress;
    int m_operationsCount;
    int m_operationsIndex;
    QTime m_startTime;
    QString m_finishedText;
};

#endif