certmanager/lib

progressbar.cpp
1/*
2 progressbar.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 Copyright (c) 2004 Klarälvdalens Datakonsult AB
6
7 Libkleopatra is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 Libkleopatra is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the TQt library by Trolltech AS, Norway (or with modified versions
24 of TQt that use the same license as TQt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 TQt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
31*/
32
33#include "config.h"
34#include "progressbar.h"
35
36#include <tqtimer.h>
37#include <kdebug.h>
38
39static const int busyTimerTickInterval = 100;
40static const int busyTimerTickIncrement = 5;
41
42Kleo::ProgressBar::ProgressBar( TQWidget * parent, const char * name, WFlags f )
43 : TQProgressBar( 0, parent, name, f ),
44 mRealProgress( -1 )
45{
46 mBusyTimer = new TQTimer( this );
47 connect( mBusyTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotBusyTimerTick()) );
48 fixup( true );
49}
50
51void Kleo::ProgressBar::slotProgress( const TQString &, int cur, int tot ) {
52 setProgress( cur, tot );
53}
54
55void Kleo::ProgressBar::slotProgress( const TQString &, int, int cur, int tot ) {
56 setProgress( cur, tot );
57}
58
60 kdDebug() << "Kleo::ProgressBar::setTotalSteps( " << total << " )" << endl;
61 if ( total == totalSteps() )
62 return;
63 TQProgressBar::setTotalSteps( 0 );
64 fixup( false );
65}
66
68 kdDebug() << "Kleo::ProgressBar::setProgress( " << p << " )" << endl;
69 mRealProgress = p;
70 fixup( true );
71}
72
74 mRealProgress = -1;
75 fixup( true );
76}
77
78void Kleo::ProgressBar::slotBusyTimerTick() {
79 fixup( false );
80 if ( mBusyTimer->isActive() )
81 TQProgressBar::setProgress( TQProgressBar::progress() + busyTimerTickIncrement );
82}
83
84void Kleo::ProgressBar::fixup( bool newValue ) {
85 const int cur = TQProgressBar::progress();
86 const int tot = TQProgressBar::totalSteps();
87
88 kdDebug() << "Kleo::ProgressBar::startStopBusyTimer() cur = " << cur << "; tot = " << tot << "; real = " << mRealProgress << endl;
89
90 if ( ( newValue && mRealProgress < 0 ) || ( !newValue && cur < 0 ) ) {
91 kdDebug() << "(new value) switch to reset" << endl;
92 mBusyTimer->stop();
93 if ( newValue )
94 TQProgressBar::reset();
95 mRealProgress = -1;
96 } else if ( tot == 0 ) {
97 kdDebug() << "(new value) switch or stay in busy" << endl;
98 if ( !mBusyTimer->isActive() ) {
99 mBusyTimer->start( busyTimerTickInterval );
100 if ( newValue )
101 TQProgressBar::setProgress( mRealProgress );
102 }
103 } else {
104 kdDebug() << "(new value) normal progress" << endl;
105 mBusyTimer->stop();
106 if ( TQProgressBar::progress() != mRealProgress )
107 TQProgressBar::setProgress( mRealProgress );
108 }
109}
110
111#include "progressbar.moc"
void setProgress(int progress)
Definition: progressbar.cpp:67
void setTotalSteps(int total)
Definition: progressbar.cpp:59