kio Library API Documentation

statusbarprogress.cpp

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., 59 Temple Place - Suite 330, 00016 Boston, MA 02111-1307, 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; 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 bytes_per_second ) { 00131 if ( bytes_per_second == 0 ) { 00132 m_pLabel->setText( i18n( " Stalled ") ); 00133 } else { 00134 m_pLabel->setText( i18n( " %1/s ").arg( KIO::convertSize( bytes_per_second )) ); 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"
KDE Logo
This file is part of the documentation for kio Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:29:32 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003