36 #include <tqapplication.h>
38 #include <tqprogressbar.h>
42 #include <tqscrollview.h>
43 #include <tqtoolbutton.h>
44 #include <tqpushbutton.h>
46 #include <tqtooltip.h>
48 #include <tdelocale.h>
50 #include <kstdguiitem.h>
51 #include <kiconloader.h>
54 #include "progressdialog.h"
55 #include "progressmanager.h"
57 #include <tqwhatsthis.h>
61 class TransactionItem;
63 TransactionItemView::TransactionItemView( TQWidget * parent,
66 : TQScrollView( parent, name, f ) {
67 setFrameStyle( NoFrame );
68 mBigBox =
new TQVBox( viewport() );
69 mBigBox->setSpacing( 5 );
71 setResizePolicy( TQScrollView::AutoOneFit );
74 TransactionItem* TransactionItemView::addTransactionItem( ProgressItem* item,
bool first )
76 TransactionItem *ti =
new TransactionItem( mBigBox, item, first );
78 TQTimer::singleShot( 1000, ti, TQ_SLOT( show() ) );
82 void TransactionItemView::resizeContents(
int w,
int h )
86 TQScrollView::resizeContents( w, h );
92 TQApplication::sendPostedEvents( 0, TQEvent::ChildInserted );
93 TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
94 TQSize sz = parentWidget()->sizeHint();
95 int currentWidth = parentWidget()->width();
97 if ( currentWidth < sz.width() || currentWidth > sz.width() + 100 )
98 currentWidth = sz.width();
99 parentWidget()->resize( currentWidth, sz.height() );
102 TQSize TransactionItemView::sizeHint()
const
104 return minimumSizeHint();
107 TQSize TransactionItemView::minimumSizeHint()
const
109 int f = 2 * frameWidth();
111 int vsbExt = verticalScrollBar()->sizeHint().width();
112 int minw = topLevelWidget()->width() / 3;
113 int maxh = topLevelWidget()->height() / 2;
114 TQSize sz( mBigBox->minimumSizeHint() );
115 sz.setWidth( TQMAX( sz.width(), minw ) + f + vsbExt );
116 sz.setHeight( TQMIN( sz.height(), maxh ) + f );
121 void TransactionItemView::slotLayoutFirstItem()
132 TQObject *o = mBigBox->child(
"TransactionItem",
"KPIM::TransactionItem" );
133 TransactionItem *ti =
dynamic_cast<TransactionItem*
>( o );
142 TransactionItem::TransactionItem( TQWidget* parent,
143 ProgressItem *item,
bool first )
144 : TQVBox( parent,
"TransactionItem" ), mCancelButton( 0 ), mItem( item )
149 setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
151 mFrame =
new TQFrame(
this );
152 mFrame->setFrameShape( TQFrame::HLine );
153 mFrame->setFrameShadow( TQFrame::Raised );
155 setStretchFactor( mFrame, 3 );
157 TQHBox *h =
new TQHBox(
this );
160 mItemLabel =
new TQLabel( item->label(), h );
162 mItemLabel->setTextFormat( TQt::RichText );
163 mItemLabel->setAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine );
164 h->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
166 mProgress =
new TQProgressBar( 100, h );
167 mProgress->setProgress( item->progress() );
169 if ( item->canBeCanceled() ) {
170 mCancelButton =
new TQPushButton( SmallIcon(
"cancel" ), TQString(), h );
171 TQToolTip::add( mCancelButton, i18n(
"Cancel this operation.") );
172 connect ( mCancelButton, TQ_SIGNAL( clicked() ),
173 this, TQ_SLOT( slotItemCanceled() ));
176 h =
new TQHBox(
this );
178 h->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
179 mSSLLabel =
new SSLLabel( h );
180 mSSLLabel->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
181 mItemStatus =
new TQLabel( item->status(), h );
183 mItemStatus->setTextFormat( TQt::RichText );
184 mItemStatus->setAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::SingleLine );
187 mItemStatus->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Ignored ) );
188 mItemStatus->setFixedHeight( mItemLabel->sizeHint().height() );
189 setCrypto( item->usesCrypto() );
190 if( first ) hideHLine();
193 TransactionItem::~TransactionItem()
197 void TransactionItem::hideHLine()
202 void TransactionItem::setProgress(
int progress )
204 mProgress->setProgress( progress );
207 void TransactionItem::setLabel(
const TQString& label )
209 mItemLabel->setText( label );
212 void TransactionItem::setStatus(
const TQString& status )
214 mItemStatus->setText( status );
217 void TransactionItem::setCrypto(
bool on )
220 mSSLLabel->setEncrypted(
true );
222 mSSLLabel->setEncrypted(
false );
224 mSSLLabel->setState( mSSLLabel->lastState() );
227 void TransactionItem::setTotalSteps(
int totalSteps )
229 mProgress->setTotalSteps( totalSteps );
232 void TransactionItem::slotItemCanceled()
239 void TransactionItem::addSubTransaction( ProgressItem* )
247 ProgressDialog::ProgressDialog( TQWidget* alignWidget, TQWidget* parent,
const char* name )
248 : OverlayWidget( alignWidget, parent, name ), mWasLastShown( false )
250 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
254 mScrollView =
new TransactionItemView(
this,
"ProgressScrollView" );
274 ProgressManager *pm = ProgressManager::instance();
275 connect ( pm, TQ_SIGNAL( progressItemAdded( KPIM::ProgressItem* ) ),
276 this, TQ_SLOT( slotTransactionAdded( KPIM::ProgressItem* ) ) );
277 connect ( pm, TQ_SIGNAL( progressItemCompleted( KPIM::ProgressItem* ) ),
278 this, TQ_SLOT( slotTransactionCompleted( KPIM::ProgressItem* ) ) );
279 connect ( pm, TQ_SIGNAL( progressItemProgress( KPIM::ProgressItem*,
unsigned int ) ),
280 this, TQ_SLOT( slotTransactionProgress( KPIM::ProgressItem*,
unsigned int ) ) );
281 connect ( pm, TQ_SIGNAL( progressItemStatus( KPIM::ProgressItem*,
const TQString& ) ),
282 this, TQ_SLOT( slotTransactionStatus( KPIM::ProgressItem*,
const TQString& ) ) );
283 connect ( pm, TQ_SIGNAL( progressItemLabel( KPIM::ProgressItem*,
const TQString& ) ),
284 this, TQ_SLOT( slotTransactionLabel( KPIM::ProgressItem*,
const TQString& ) ) );
285 connect ( pm, TQ_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*,
bool) ),
286 this, TQ_SLOT( slotTransactionUsesCrypto( KPIM::ProgressItem*,
bool ) ) );
287 connect ( pm, TQ_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*,
bool) ),
288 this, TQ_SLOT( slotTransactionUsesBusyIndicator( KPIM::ProgressItem*,
bool ) ) );
289 connect ( pm, TQ_SIGNAL( showProgressDialog() ),
290 this, TQ_SLOT( slotShow() ) );
293 void ProgressDialog::closeEvent( TQCloseEvent* e )
303 ProgressDialog::~ProgressDialog()
308 void ProgressDialog::slotTransactionAdded( ProgressItem *item )
310 TransactionItem *parent = 0;
311 if ( item->parent() ) {
312 if ( mTransactionsToListviewItems.contains( item->parent() ) ) {
313 parent = mTransactionsToListviewItems[ item->parent() ];
314 parent->addSubTransaction( item );
317 const bool first = mTransactionsToListviewItems.empty();
318 TransactionItem *ti = mScrollView->addTransactionItem( item, first );
320 mTransactionsToListviewItems.replace( item, ti );
321 if ( first && mWasLastShown )
322 TQTimer::singleShot( 1000,
this, TQ_SLOT( slotShow() ) );
327 void ProgressDialog::slotTransactionCompleted( ProgressItem *item )
329 if ( mTransactionsToListviewItems.contains( item ) ) {
330 TransactionItem *ti = mTransactionsToListviewItems[ item ];
331 mTransactionsToListviewItems.remove( item );
332 ti->setItemComplete();
333 TQTimer::singleShot( 3000, ti, TQ_SLOT( deleteLater() ) );
335 connect ( ti, TQ_SIGNAL( destroyed() ),
336 mScrollView, TQ_SLOT( slotLayoutFirstItem() ) );
339 if ( mTransactionsToListviewItems.empty() )
340 TQTimer::singleShot( 3000,
this, TQ_SLOT( slotHide() ) );
343 void ProgressDialog::slotTransactionCanceled( ProgressItem* )
347 void ProgressDialog::slotTransactionProgress( ProgressItem *item,
348 unsigned int progress )
350 if ( mTransactionsToListviewItems.contains( item ) ) {
351 TransactionItem *ti = mTransactionsToListviewItems[ item ];
352 ti->setProgress( progress );
356 void ProgressDialog::slotTransactionStatus( ProgressItem *item,
357 const TQString& status )
359 if ( mTransactionsToListviewItems.contains( item ) ) {
360 TransactionItem *ti = mTransactionsToListviewItems[ item ];
361 ti->setStatus( status );
365 void ProgressDialog::slotTransactionLabel( ProgressItem *item,
366 const TQString& label )
368 if ( mTransactionsToListviewItems.contains( item ) ) {
369 TransactionItem *ti = mTransactionsToListviewItems[ item ];
370 ti->setLabel( label );
375 void ProgressDialog::slotTransactionUsesCrypto( ProgressItem *item,
378 if ( mTransactionsToListviewItems.contains( item ) ) {
379 TransactionItem *ti = mTransactionsToListviewItems[ item ];
380 ti->setCrypto( value );
384 void ProgressDialog::slotTransactionUsesBusyIndicator( KPIM::ProgressItem *item,
bool value )
386 if ( mTransactionsToListviewItems.contains( item ) ) {
387 TransactionItem *ti = mTransactionsToListviewItems[ item ];
389 ti->setTotalSteps( 0 );
391 ti->setTotalSteps( 100 );
395 void ProgressDialog::slotShow()
400 void ProgressDialog::slotHide()
403 if ( mTransactionsToListviewItems.isEmpty() ) {
408 void ProgressDialog::slotClose()
410 mWasLastShown =
false;
414 void ProgressDialog::setVisible(
bool b )
420 emit visibilityChanged( b );
423 void ProgressDialog::slotToggleVisibility()
430 mWasLastShown = !isShown();
431 if ( isShown() || !mTransactionsToListviewItems.isEmpty() )
432 setVisible( !isShown() );
437 #include "progressdialog.moc"
TDEPIM classes for drag and drop of mails.