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

tdeio/tdeio

  • tdeio
  • tdeio
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 <tdeapplication.h>
26 #include <tdelocale.h>
27 #include <kdebug.h>
28 #include <kprogress.h>
29 
30 #include "jobclasses.h"
31 #include "statusbarprogress.h"
32 
33 namespace TDEIO {
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( TDEIO::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( TDEIO::Job*, TDEIO::filesize_t size ) {
122  m_iTotalSize = size; // size is measured in bytes
123 }
124 
125 void StatusbarProgress::slotPercent( TDEIO::Job*, unsigned long percent ) {
126  m_pProgressBar->setValue( percent );
127 }
128 
129 
130 void StatusbarProgress::slotSpeed( TDEIO::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( TDEIO::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"
TDEIO::convertSize
TDEIO_EXPORT TQString convertSize(TDEIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53
TDEIO::ProgressBase
This class does all initialization stuff for progress, like connecting signals to slots...
Definition: progressbase.h:70
TDEIO::filesize_t
TQ_ULLONG filesize_t
64-bit file size
Definition: global.h:39
TDEIO::StatusbarProgress::StatusbarProgress
StatusbarProgress(TQWidget *parent, bool button=true)
Creates a new StatusbarProgress.
Definition: statusbarprogress.cpp:35
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::StatusbarProgress::setJob
void setJob(TDEIO::Job *job)
Sets the job to monitor.
Definition: statusbarprogress.cpp:74
TDEIO::Job
The base class for all jobs.
Definition: jobclasses.h:67
TDEIO::ProgressBase::setOnlyClean
void setOnlyClean(bool onlyClean)
This controls whether the dialog should be deleted or only cleaned when the TDEIO::Job is finished (o...
Definition: progressbase.h:115
TDEIO::ProgressBase::slotStop
void slotStop()
This method should be called for correct cancellation of IO operation Connect this to the progress wi...
Definition: progressbase.cpp:158
TDEIO::ProgressBase::setJob
void setJob(TDEIO::Job *job)
Assign a TDEIO::Job to this progress dialog.
Definition: progressbase.cpp:37

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.