certmanager/lib
progressbar.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "config.h"
00034 #include "progressbar.h"
00035
00036 #include <qtimer.h>
00037 #include <kdebug.h>
00038
00039 static const int busyTimerTickInterval = 100;
00040 static const int busyTimerTickIncrement = 5;
00041
00042 Kleo::ProgressBar::ProgressBar( QWidget * parent, const char * name, WFlags f )
00043 : QProgressBar( 0, parent, name, f ),
00044 mRealProgress( -1 )
00045 {
00046 mBusyTimer = new QTimer( this );
00047 connect( mBusyTimer, SIGNAL(timeout()), SLOT(slotBusyTimerTick()) );
00048 fixup( true );
00049 }
00050
00051 void Kleo::ProgressBar::slotProgress( const QString &, int cur, int tot ) {
00052 setProgress( cur, tot );
00053 }
00054
00055 void Kleo::ProgressBar::slotProgress( const QString &, int, int cur, int tot ) {
00056 setProgress( cur, tot );
00057 }
00058
00059 void Kleo::ProgressBar::setTotalSteps( int total ) {
00060 kdDebug() << "Kleo::ProgressBar::setTotalSteps( " << total << " )" << endl;
00061 if ( total == totalSteps() )
00062 return;
00063 QProgressBar::setTotalSteps( 0 );
00064 fixup( false );
00065 }
00066
00067 void Kleo::ProgressBar::setProgress( int p ) {
00068 kdDebug() << "Kleo::ProgressBar::setProgress( " << p << " )" << endl;
00069 mRealProgress = p;
00070 fixup( true );
00071 }
00072
00073 void Kleo::ProgressBar::reset() {
00074 mRealProgress = -1;
00075 fixup( true );
00076 }
00077
00078 void Kleo::ProgressBar::slotBusyTimerTick() {
00079 fixup( false );
00080 if ( mBusyTimer->isActive() )
00081 QProgressBar::setProgress( QProgressBar::progress() + busyTimerTickIncrement );
00082 }
00083
00084 void Kleo::ProgressBar::fixup( bool newValue ) {
00085 const int cur = QProgressBar::progress();
00086 const int tot = QProgressBar::totalSteps();
00087
00088 kdDebug() << "Kleo::ProgressBar::startStopBusyTimer() cur = " << cur << "; tot = " << tot << "; real = " << mRealProgress << endl;
00089
00090 if ( ( newValue && mRealProgress < 0 ) || ( !newValue && cur < 0 ) ) {
00091 kdDebug() << "(new value) switch to reset" << endl;
00092 mBusyTimer->stop();
00093 if ( newValue )
00094 QProgressBar::reset();
00095 mRealProgress = -1;
00096 } else if ( tot == 0 ) {
00097 kdDebug() << "(new value) switch or stay in busy" << endl;
00098 if ( !mBusyTimer->isActive() ) {
00099 mBusyTimer->start( busyTimerTickInterval );
00100 if ( newValue )
00101 QProgressBar::setProgress( mRealProgress );
00102 }
00103 } else {
00104 kdDebug() << "(new value) normal progress" << endl;
00105 mBusyTimer->stop();
00106 if ( QProgressBar::progress() != mRealProgress )
00107 QProgressBar::setProgress( mRealProgress );
00108 }
00109 }
00110
00111 #include "progressbar.moc"
|