38 #include "progressmanager.h"
39 using KPIM::ProgressItem;
42 #include <kprogress.h>
43 #include <kiconloader.h>
48 #include <tqpushbutton.h>
49 #include <tqtooltip.h>
50 #include <tdelocale.h>
52 #include <tqwidgetstack.h>
55 #include "progressdialog.h"
56 #include "statusbarprogresswidget.h"
61 StatusbarProgressWidget::StatusbarProgressWidget( ProgressDialog* progressDialog, TQWidget* parent,
bool button )
62 : TQFrame( parent ), mCurrentItem( 0 ), mProgressDialog( progressDialog ),
63 mDelayTimer( 0 ), mBusyTimer( 0 )
65 m_bShowButton = button;
66 int w = fontMetrics().width(
" 999.9 kB/s 00:00:01 " ) + 8;
67 box =
new TQHBoxLayout(
this, 0, 0 );
69 m_pButton =
new TQPushButton(
this );
70 m_pButton->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum,
71 TQSizePolicy::Minimum ) );
72 m_pButton->setPixmap( SmallIcon(
"go-up" ) );
73 box->addWidget( m_pButton );
74 stack =
new TQWidgetStack(
this );
75 stack->setMaximumHeight( fontMetrics().height() );
76 box->addWidget( stack );
78 m_sslLabel =
new SSLLabel(
this );
79 box->addWidget( m_sslLabel );
81 TQToolTip::add( m_pButton, i18n(
"Open detailed progress dialog") );
83 m_pProgressBar =
new KProgress(
this );
84 m_pProgressBar->setLineWidth( 1 );
85 m_pProgressBar->setFrameStyle( TQFrame::Box );
86 m_pProgressBar->installEventFilter(
this );
87 m_pProgressBar->setMinimumWidth( w );
88 stack->addWidget( m_pProgressBar, 1 );
90 m_pLabel =
new TQLabel( TQString(),
this );
91 m_pLabel->setAlignment( AlignHCenter | AlignVCenter );
92 m_pLabel->installEventFilter(
this );
93 m_pLabel->setMinimumWidth( w );
94 stack->addWidget( m_pLabel, 2 );
95 m_pButton->setMaximumHeight( fontMetrics().height() );
96 setMinimumWidth( minimumSizeHint().width() );
101 connect( m_pButton, TQ_SIGNAL( clicked() ),
102 progressDialog, TQ_SLOT( slotToggleVisibility() ) );
104 connect ( ProgressManager::instance(), TQ_SIGNAL( progressItemAdded( KPIM::ProgressItem * ) ),
105 this, TQ_SLOT( slotProgressItemAdded( KPIM::ProgressItem * ) ) );
106 connect ( ProgressManager::instance(), TQ_SIGNAL( progressItemCompleted( KPIM::ProgressItem * ) ),
107 this, TQ_SLOT( slotProgressItemCompleted( KPIM::ProgressItem * ) ) );
108 connect ( ProgressManager::instance(), TQ_SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,
bool)),
109 this, TQ_SLOT( updateBusyMode() ) );
111 connect ( progressDialog, TQ_SIGNAL( visibilityChanged(
bool )),
112 this, TQ_SLOT( slotProgressDialogVisible(
bool ) ) );
114 mDelayTimer =
new TQTimer(
this );
115 connect ( mDelayTimer, TQ_SIGNAL( timeout() ),
116 this, TQ_SLOT( slotShowItemDelayed() ) );
124 void StatusbarProgressWidget::updateBusyMode()
127 if ( mCurrentItem ) {
130 mDelayTimer->start( 1000,
true );
134 mBusyTimer =
new TQTimer(
this );
135 connect( mBusyTimer, TQ_SIGNAL( timeout() ),
136 this, TQ_SLOT( slotBusyIndicator() ) );
137 mDelayTimer->start( 1000,
true );
142 void StatusbarProgressWidget::slotProgressItemAdded( ProgressItem *item )
144 if ( item->parent() )
150 void StatusbarProgressWidget::slotProgressItemCompleted( ProgressItem *item )
152 if ( item->parent() )
return;
154 if ( ProgressManager::instance()->isEmpty() ) {
156 TQTimer::singleShot( 5000,
this, TQ_SLOT( slotClean() ) );
157 }
else if ( mCurrentItem ) {
160 activateSingleItemMode();
164 void StatusbarProgressWidget::connectSingleItem()
166 if ( mCurrentItem ) {
167 disconnect ( mCurrentItem, TQ_SIGNAL( progressItemProgress( KPIM::ProgressItem *,
unsigned int ) ),
168 this, TQ_SLOT( slotProgressItemProgress( KPIM::ProgressItem *,
unsigned int ) ) );
171 mCurrentItem = ProgressManager::instance()->singleItem();
172 if ( mCurrentItem ) {
173 connect ( mCurrentItem, TQ_SIGNAL( progressItemProgress( KPIM::ProgressItem *,
unsigned int ) ),
174 this, TQ_SLOT( slotProgressItemProgress( KPIM::ProgressItem *,
unsigned int ) ) );
178 void StatusbarProgressWidget::activateSingleItemMode()
180 m_pProgressBar->setTotalSteps( 100 );
181 m_pProgressBar->setProgress( mCurrentItem->progress() );
182 m_pProgressBar->setPercentageVisible(
true );
185 void StatusbarProgressWidget::slotShowItemDelayed()
187 bool noItems = ProgressManager::instance()->isEmpty();
188 if ( mCurrentItem ) {
189 activateSingleItemMode();
190 }
else if ( !noItems ) {
191 m_pProgressBar->setTotalSteps( 0 );
192 m_pProgressBar->setPercentageVisible(
false );
193 Q_ASSERT( mBusyTimer );
195 mBusyTimer->start( 100 );
198 if ( !noItems && mode == None ) {
204 void StatusbarProgressWidget::slotBusyIndicator()
206 int p = m_pProgressBar->progress();
207 m_pProgressBar->setProgress( p + 10 );
210 void StatusbarProgressWidget::slotProgressItemProgress( ProgressItem *item,
unsigned int value )
212 Q_ASSERT( item == mCurrentItem);
213 m_pProgressBar->setProgress( value );
216 void StatusbarProgressWidget::slotSetSSL(
bool ssl )
218 m_sslLabel->setEncrypted( ssl );
221 void StatusbarProgressWidget::setMode() {
224 if ( m_bShowButton ) {
227 m_sslLabel->setState( SSLLabel::Done );
230 stack->raiseWidget( m_pLabel );
235 if ( m_bShowButton ) {
238 m_sslLabel->setState( m_sslLabel->lastState() );
240 stack->raiseWidget( m_pLabel );
246 stack->raiseWidget( m_pProgressBar );
247 if ( m_bShowButton ) {
250 m_sslLabel->setState( m_sslLabel->lastState() );
255 void StatusbarProgressWidget::slotClean()
258 if ( ProgressManager::instance()->isEmpty() ) {
259 m_pProgressBar->setProgress( 0 );
266 bool StatusbarProgressWidget::eventFilter( TQObject *, TQEvent *ev )
268 if ( ev->type() == TQEvent::MouseButtonPress ) {
269 TQMouseEvent *e = (TQMouseEvent*)ev;
271 if ( e->button() == TQt::LeftButton && mode != None ) {
274 mProgressDialog->slotToggleVisibility();
281 void StatusbarProgressWidget::slotProgressDialogVisible(
bool b )
285 m_pButton->setPixmap( SmallIcon(
"go-down" ) );
286 TQToolTip::remove( m_pButton );
287 TQToolTip::add( m_pButton, i18n(
"Hide detailed progress window") );
290 m_pButton->setPixmap( SmallIcon(
"go-up" ) );
291 TQToolTip::remove( m_pButton );
292 TQToolTip::add( m_pButton, i18n(
"Show detailed progress window") );
296 #include "statusbarprogresswidget.moc"
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
TDEPIM classes for drag and drop of mails.