• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kio

statusbarprogress.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000 Matej Koss <koss@miesto.sk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include <qtooltip.h>
00020 #include <qlayout.h>
00021 #include <qwidgetstack.h>
00022 #include <qpushbutton.h>
00023 #include <qlabel.h>
00024 
00025 #include <kapplication.h>
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 #include <kprogress.h>
00029 
00030 #include "jobclasses.h"
00031 #include "statusbarprogress.h"
00032 
00033 namespace KIO {
00034 
00035 StatusbarProgress::StatusbarProgress( QWidget* parent, bool button )
00036   : ProgressBase( parent ) {
00037 
00038   m_bShowButton = button;
00039 
00040   // only clean this dialog
00041   setOnlyClean(true);
00042   // TODO : is this really needed ?
00043   setStopOnClose(false);
00044 
00045   int w = fontMetrics().width( " 999.9 kB/s 00:00:01 " ) + 8;
00046   box = new QHBoxLayout( this, 0, 0 );
00047 
00048   m_pButton = new QPushButton( "X", this );
00049   box->addWidget( m_pButton  );
00050   stack = new QWidgetStack( this );
00051   box->addWidget( stack );
00052   connect( m_pButton, SIGNAL( clicked() ), this, SLOT( slotStop() ) );
00053 
00054   m_pProgressBar = new KProgress( this );
00055   m_pProgressBar->setFrameStyle( QFrame::Box | QFrame::Raised );
00056   m_pProgressBar->setLineWidth( 1 );
00057   m_pProgressBar->setBackgroundMode( QWidget::PaletteBackground );
00058   m_pProgressBar->installEventFilter( this );
00059   m_pProgressBar->setMinimumWidth( w );
00060   stack->addWidget( m_pProgressBar, 1 );
00061 
00062   m_pLabel = new QLabel( "", this );
00063   m_pLabel->setAlignment( AlignHCenter | AlignVCenter );
00064   m_pLabel->installEventFilter( this );
00065   m_pLabel->setMinimumWidth( w );
00066   stack->addWidget( m_pLabel, 2 );
00067   setMinimumSize( sizeHint() );
00068 
00069   mode = None;
00070   setMode();
00071 }
00072 
00073 
00074 void StatusbarProgress::setJob( KIO::Job *job )
00075 {
00076   ProgressBase::setJob( job );
00077 
00078   mode = Progress;
00079   setMode();
00080 }
00081 
00082 
00083 void StatusbarProgress::setMode() {
00084   switch ( mode ) {
00085   case None:
00086     if ( m_bShowButton ) {
00087       m_pButton->hide();
00088     }
00089     stack->hide();
00090     break;
00091 
00092   case Label:
00093     if ( m_bShowButton ) {
00094       m_pButton->show();
00095     }
00096     stack->show();
00097     stack->raiseWidget( m_pLabel );
00098     break;
00099 
00100   case Progress:
00101     if ( m_bShowButton ) {
00102       m_pButton->show();
00103     }
00104     stack->show();
00105     stack->raiseWidget( m_pProgressBar );
00106     break;
00107   }
00108 }
00109 
00110 
00111 void StatusbarProgress::slotClean() {
00112   // we don't want to delete this widget, only clean
00113   m_pProgressBar->setValue( 0 );
00114   m_pLabel->clear();
00115 
00116   mode = None;
00117   setMode();
00118 }
00119 
00120 
00121 void StatusbarProgress::slotTotalSize( KIO::Job*, KIO::filesize_t size ) {
00122   m_iTotalSize = size;  // size is measured in bytes
00123 }
00124 
00125 void StatusbarProgress::slotPercent( KIO::Job*, unsigned long percent ) {
00126   m_pProgressBar->setValue( percent );
00127 }
00128 
00129 
00130 void StatusbarProgress::slotSpeed( KIO::Job*, unsigned long speed ) {
00131   if ( speed == 0 ) { // spped is measured in bytes-per-second
00132     m_pLabel->setText( i18n( " Stalled ") );
00133   } else {
00134     m_pLabel->setText( i18n( " %1/s ").arg( KIO::convertSize( speed )) );
00135   }
00136 }
00137 
00138 
00139 bool StatusbarProgress::eventFilter( QObject *, QEvent *ev ) {
00140   if ( ! m_pJob ) { // don't react when there isn't any job doing IO
00141     return true;
00142   }
00143 
00144   if ( ev->type() == QEvent::MouseButtonPress ) {
00145     QMouseEvent *e = (QMouseEvent*)ev;
00146 
00147     if ( e->button() == LeftButton ) {    // toggle view on left mouse button
00148       if ( mode == Label ) {
00149     mode = Progress;
00150       } else if ( mode == Progress ) {
00151     mode = Label;
00152       }
00153       setMode();
00154       return true;
00155 
00156     }
00157   }
00158 
00159   return false;
00160 }
00161 
00162 void StatusbarProgress::virtual_hook( int id, void* data )
00163 { ProgressBase::virtual_hook( id, data ); }
00164 
00165 } /* namespace */
00166 #include "statusbarprogress.moc"

kio

Skip menu "kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal