• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kio
 

kio/kio

  • kio
  • kio
statusbarprogress.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Matej Koss <koss@miesto.sk>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include <tqtooltip.h>
20 #include <tqlayout.h>
21 #include <tqwidgetstack.h>
22 #include <tqpushbutton.h>
23 #include <tqlabel.h>
24 
25 #include <kapplication.h>
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <kprogress.h>
29 
30 #include "jobclasses.h"
31 #include "statusbarprogress.h"
32 
33 namespace KIO {
34 
35 StatusbarProgress::StatusbarProgress( TQWidget* parent, bool button )
36  : ProgressBase( parent ) {
37 
38  m_bShowButton = button;
39 
40  // only clean this dialog
41  setOnlyClean(true);
42  // TODO : is this really needed ?
43  setStopOnClose(false);
44 
45  int w = fontMetrics().width( " 999.9 kB/s 00:00:01 " ) + 8;
46  box = new TQHBoxLayout( this, 0, 0 );
47 
48  m_pButton = new TQPushButton( "X", this );
49  box->addWidget( m_pButton );
50  stack = new TQWidgetStack( this );
51  box->addWidget( stack );
52  connect( m_pButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotStop() ) );
53 
54  m_pProgressBar = new KProgress( this );
55  m_pProgressBar->setFrameStyle( TQFrame::Box | TQFrame::Raised );
56  m_pProgressBar->setLineWidth( 1 );
57  m_pProgressBar->setBackgroundMode( TQWidget::PaletteBackground );
58  m_pProgressBar->installEventFilter( this );
59  m_pProgressBar->setMinimumWidth( w );
60  stack->addWidget( m_pProgressBar, 1 );
61 
62  m_pLabel = new TQLabel( "", this );
63  m_pLabel->setAlignment( AlignHCenter | AlignVCenter );
64  m_pLabel->installEventFilter( this );
65  m_pLabel->setMinimumWidth( w );
66  stack->addWidget( m_pLabel, 2 );
67  setMinimumSize( sizeHint() );
68 
69  mode = None;
70  setMode();
71 }
72 
73 
74 void StatusbarProgress::setJob( KIO::Job *job )
75 {
76  ProgressBase::setJob( job );
77 
78  mode = Progress;
79  setMode();
80 }
81 
82 
83 void StatusbarProgress::setMode() {
84  switch ( mode ) {
85  case None:
86  if ( m_bShowButton ) {
87  m_pButton->hide();
88  }
89  stack->hide();
90  break;
91 
92  case Label:
93  if ( m_bShowButton ) {
94  m_pButton->show();
95  }
96  stack->show();
97  stack->raiseWidget( m_pLabel );
98  break;
99 
100  case Progress:
101  if ( m_bShowButton ) {
102  m_pButton->show();
103  }
104  stack->show();
105  stack->raiseWidget( m_pProgressBar );
106  break;
107  }
108 }
109 
110 
111 void StatusbarProgress::slotClean() {
112  // we don't want to delete this widget, only clean
113  m_pProgressBar->setValue( 0 );
114  m_pLabel->clear();
115 
116  mode = None;
117  setMode();
118 }
119 
120 
121 void StatusbarProgress::slotTotalSize( KIO::Job*, KIO::filesize_t size ) {
122  m_iTotalSize = size; // size is measured in bytes
123 }
124 
125 void StatusbarProgress::slotPercent( KIO::Job*, unsigned long percent ) {
126  m_pProgressBar->setValue( percent );
127 }
128 
129 
130 void StatusbarProgress::slotSpeed( KIO::Job*, unsigned long speed ) {
131  if ( speed == 0 ) { // spped is measured in bytes-per-second
132  m_pLabel->setText( i18n( " Stalled ") );
133  } else {
134  m_pLabel->setText( i18n( " %1/s ").arg( KIO::convertSize( speed )) );
135  }
136 }
137 
138 
139 bool StatusbarProgress::eventFilter( TQObject *, TQEvent *ev ) {
140  if ( ! m_pJob ) { // don't react when there isn't any job doing IO
141  return true;
142  }
143 
144  if ( ev->type() == TQEvent::MouseButtonPress ) {
145  TQMouseEvent *e = (TQMouseEvent*)ev;
146 
147  if ( e->button() == Qt::LeftButton ) { // toggle view on left mouse button
148  if ( mode == Label ) {
149  mode = Progress;
150  } else if ( mode == Progress ) {
151  mode = Label;
152  }
153  setMode();
154  return true;
155 
156  }
157  }
158 
159  return false;
160 }
161 
162 void StatusbarProgress::virtual_hook( int id, void* data )
163 { ProgressBase::virtual_hook( id, data ); }
164 
165 } /* namespace */
166 #include "statusbarprogress.moc"

kio/kio

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

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |