• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • progresswidget
statusbarprogresswidget.cpp
Go to the documentation of this file.
1 /*
2  statusbarprogresswidget.cpp
3 
4  (C) 2004 Till Adam <adam@kde.org>
5  Don Sanders
6  David Faure <dfaure@kde.org>
7 
8  Copyright 2004 David Faure <faure@kde.org>
9  Includes StatusbarProgressWidget which is based on KIOLittleProgressDlg
10  by Matt Koss <koss@miesto.sk>
11 
12  KMail is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License, version 2 or above,
14  as published by the Free Software Foundation.
15 
16  KMail is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 
25  In addition, as a special exception, the copyright holders give
26  permission to link the code of this program with any edition of
27  the Qt library by Trolltech AS, Norway (or with modified versions
28  of Qt that use the same license as Qt), and distribute linked
29  combinations including the two. You must obey the GNU General
30  Public License in all respects for all of the code used other than
31  Qt. If you modify this file, you may extend this exception to
32  your version of the file, but you are not obligated to do so. If
33  you do not wish to do so, delete this exception statement from
34  your version.
35 */
36 
37 #include "statusbarprogresswidget.h"
38 #include "progressdialog.h"
39 #include "ssllabel.h"
40 using KPIM::SSLLabel;
41 #include "progressmanager.h"
42 using KPIM::ProgressItem;
43 using KPIM::ProgressManager;
44 
45 #include <KLocale>
46 #include <KIconLoader>
47 #include <KDebug>
48 
49 #include <QEvent>
50 #include <QFrame>
51 #include <QHBoxLayout>
52 #include <QLabel>
53 #include <QMouseEvent>
54 #include <QProgressBar>
55 #include <QPushButton>
56 #include <QStackedWidget>
57 #include <QTimer>
58 
59 using namespace KPIM;
60 
61 //-----------------------------------------------------------------------------
62 StatusbarProgressWidget::StatusbarProgressWidget( ProgressDialog* progressDialog, QWidget* parent, bool button )
63  : QFrame( parent ), mCurrentItem( 0 ), mProgressDialog( progressDialog ),
64  mDelayTimer( 0 ), mBusyTimer( 0 ), mCleanTimer( 0 )
65 {
66  m_bShowButton = button;
67  int w = fontMetrics().width( QLatin1String(" 999.9 kB/s 00:00:01 ") ) + 8;
68  box = new QHBoxLayout( this );
69  box->setMargin(0);
70  box->setSpacing(0);
71 
72  m_pButton = new QPushButton( this );
73  m_pButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,
74  QSizePolicy::Minimum ) );
75  QPixmap smallIcon = SmallIcon( QLatin1String("go-up") );
76  m_pButton->setIcon( smallIcon );
77  box->addWidget( m_pButton );
78  stack = new QStackedWidget( this );
79  int maximumHeight = qMax( smallIcon.height(), fontMetrics().height() );
80  stack->setMaximumHeight( maximumHeight );
81  box->addWidget( stack );
82 
83  m_sslLabel = new SSLLabel( this );
84  box->addWidget( m_sslLabel );
85 
86  m_pButton->setToolTip( i18n("Open detailed progress dialog") );
87 
88  m_pProgressBar = new QProgressBar( this );
89  m_pProgressBar->installEventFilter( this );
90  m_pProgressBar->setMinimumWidth( w );
91  stack->insertWidget( 1,m_pProgressBar );
92 
93  m_pLabel = new QLabel( QString(), this );
94  m_pLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
95  m_pLabel->installEventFilter( this );
96  m_pLabel->setMinimumWidth( w );
97  stack->insertWidget( 2, m_pLabel );
98  m_pButton->setMaximumHeight( maximumHeight );
99  setMinimumWidth( minimumSizeHint().width() );
100 
101  mode = None;
102  setMode();
103 
104  connect( m_pButton, SIGNAL(clicked()),
105  progressDialog, SLOT(slotToggleVisibility()) );
106 
107  connect ( ProgressManager::instance(), SIGNAL(progressItemAdded(KPIM::ProgressItem*)),
108  this, SLOT(slotProgressItemAdded(KPIM::ProgressItem*)) );
109  connect ( ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*)),
110  this, SLOT(slotProgressItemCompleted(KPIM::ProgressItem*)) );
111  connect ( ProgressManager::instance(), SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)),
112  this, SLOT(updateBusyMode()) );
113 
114  connect ( progressDialog, SIGNAL(visibilityChanged(bool)),
115  this, SLOT(slotProgressDialogVisible(bool)) );
116 
117  mDelayTimer = new QTimer( this );
118  mDelayTimer->setSingleShot( true );
119  connect ( mDelayTimer, SIGNAL(timeout()),
120  this, SLOT(slotShowItemDelayed()) );
121 
122  mCleanTimer = new QTimer( this );
123  mCleanTimer->setSingleShot( true );
124  connect ( mCleanTimer, SIGNAL(timeout()),
125  this, SLOT(slotClean()) );
126 }
127 
128 // There are three cases: no progressitem, one progressitem (connect to it directly),
129 // or many progressitems (display busy indicator). Let's call them 0,1,N.
130 // In slot..Added we can only end up in 1 or N.
131 // In slot..Removed we can end up in 0, 1, or we can stay in N if we were already.
132 
133 void StatusbarProgressWidget::updateBusyMode()
134 {
135  connectSingleItem(); // if going to 1 item
136  if ( mCurrentItem ) { // Exactly one item
137  delete mBusyTimer;
138  mBusyTimer = 0;
139  mDelayTimer->start( 1000 );
140  } else { // N items
141  if ( !mBusyTimer ) {
142  mBusyTimer = new QTimer( this );
143  connect( mBusyTimer, SIGNAL(timeout()),
144  this, SLOT(slotBusyIndicator()) );
145  mDelayTimer->start( 1000 );
146  }
147  }
148 }
149 
150 void StatusbarProgressWidget::slotProgressItemAdded( ProgressItem *item )
151 {
152  if ( item->parent() )
153  return; // we are only interested in top level items
154 
155  updateBusyMode();
156 }
157 
158 void StatusbarProgressWidget::slotProgressItemCompleted( ProgressItem *item )
159 {
160  if ( item->parent() ) {
161  item->deleteLater();
162  item = 0;
163  return; // we are only interested in top level items
164  }
165  item->deleteLater();
166  item = 0;
167  connectSingleItem(); // if going back to 1 item
168  if ( ProgressManager::instance()->isEmpty() ) { // No item
169  // Done. In 5s the progress-widget will close, then we can clean up the statusbar
170  mCleanTimer->start( 5000 );
171  } else if ( mCurrentItem ) { // Exactly one item
172  delete mBusyTimer;
173  mBusyTimer = 0;
174  activateSingleItemMode();
175  }
176 }
177 
178 void StatusbarProgressWidget::connectSingleItem()
179 {
180  if ( mCurrentItem ) {
181  disconnect ( mCurrentItem, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)),
182  this, SLOT(slotProgressItemProgress(KPIM::ProgressItem*,uint)) );
183  mCurrentItem = 0;
184  }
185  mCurrentItem = ProgressManager::instance()->singleItem();
186  if ( mCurrentItem ) {
187  connect ( mCurrentItem, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)),
188  this, SLOT(slotProgressItemProgress(KPIM::ProgressItem*,uint)) );
189  }
190 }
191 
192 void StatusbarProgressWidget::activateSingleItemMode()
193 {
194  m_pProgressBar->setMaximum( 100 );
195  m_pProgressBar->setValue( mCurrentItem->progress() );
196  m_pProgressBar->setTextVisible( true );
197 }
198 
199 void StatusbarProgressWidget::slotShowItemDelayed()
200 {
201  bool noItems = ProgressManager::instance()->isEmpty();
202  if ( mCurrentItem ) {
203  activateSingleItemMode();
204  } else if ( !noItems ) { // N items
205  m_pProgressBar->setMaximum( 0 );
206  m_pProgressBar->setTextVisible( false );
207  Q_ASSERT( mBusyTimer );
208  if ( mBusyTimer )
209  mBusyTimer->start( 100 );
210  }
211 
212  if ( !noItems && mode == None ) {
213  mode = Progress;
214  setMode();
215  }
216 }
217 
218 void StatusbarProgressWidget::slotBusyIndicator()
219 {
220  int p = m_pProgressBar->value();
221  m_pProgressBar->setValue( p + 10 );
222 }
223 
224 void StatusbarProgressWidget::slotProgressItemProgress( ProgressItem *item, unsigned int value )
225 {
226  Q_ASSERT( item == mCurrentItem); // the only one we should be connected to
227  Q_UNUSED( item );
228  m_pProgressBar->setValue( value );
229 }
230 
231 void StatusbarProgressWidget::slotSetSSL( bool ssl )
232 {
233  m_sslLabel->setEncrypted( ssl );
234 }
235 
236 void StatusbarProgressWidget::setMode() {
237  switch ( mode ) {
238  case None:
239  if ( m_bShowButton ) {
240  m_pButton->hide();
241  }
242  m_sslLabel->setState( SSLLabel::Done );
243  // show the empty label in order to make the status bar look better
244  stack->show();
245  stack->setCurrentWidget( m_pLabel );
246  break;
247 
248 #if 0
249  case Label:
250  if ( m_bShowButton ) {
251  m_pButton->show();
252  }
253  m_sslLabel->setState( m_sslLabel->lastState() );
254  stack->show();
255  stack->raiseWidget( m_pLabel );
256  break;
257 #endif
258 
259  case Progress:
260  stack->show();
261  stack->setCurrentWidget( m_pProgressBar );
262  if ( m_bShowButton ) {
263  m_pButton->show();
264  }
265  m_sslLabel->setState( m_sslLabel->lastState() );
266  break;
267  }
268 }
269 
270 void StatusbarProgressWidget::slotClean()
271 {
272  // check if a new item showed up since we started the timer. If not, clear
273  if ( ProgressManager::instance()->isEmpty() ) {
274  m_pProgressBar->setValue( 0 );
275  //m_pLabel->clear();
276  mode = None;
277  setMode();
278  }
279 }
280 
281 bool StatusbarProgressWidget::eventFilter( QObject *, QEvent *ev )
282 {
283  if ( ev->type() == QEvent::MouseButtonPress ) {
284  QMouseEvent *e = (QMouseEvent*)ev;
285 
286  if ( e->button() == Qt::LeftButton && mode != None ) { // toggle view on left mouse button
287  // Consensus seems to be that we should show/hide the fancy dialog when the user
288  // clicks anywhere in the small one.
289  mProgressDialog->slotToggleVisibility();
290  return true;
291  }
292  }
293  return false;
294 }
295 
296 void StatusbarProgressWidget::slotProgressDialogVisible( bool b )
297 {
298  // Update the hide/show button when the detailed one is shown/hidden
299  if ( b ) {
300  m_pButton->setIcon( SmallIcon( QLatin1String("go-down" )) );
301  m_pButton->setToolTip( i18n("Hide detailed progress window") );
302  setMode();
303  } else {
304  m_pButton->setIcon( SmallIcon( QLatin1String("go-up") ) );
305  m_pButton->setToolTip( i18n("Show detailed progress window") );
306  }
307 }
308 
309 #include "statusbarprogresswidget.moc"
KPIM::StatusbarProgressWidget::slotClean
void slotClean()
Definition: statusbarprogresswidget.cpp:270
KPIM::StatusbarProgressWidget::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: statusbarprogresswidget.cpp:281
KPIM::ProgressManager::instance
static ProgressManager * instance()
Definition: progressmanager.cpp:159
KPIM::SSLLabel
Definition: ssllabel.h:39
KPIM::SSLLabel::setState
void setState(State state)
Definition: ssllabel.cpp:62
KPIM::ProgressManager::isEmpty
bool isEmpty() const
Definition: progressmanager.h:388
KPIM::SSLLabel::Done
Definition: ssllabel.h:46
KPIM::ProgressDialog::slotToggleVisibility
void slotToggleVisibility()
Definition: progressdialog.cpp:425
QWidget
ssllabel.h
KPIM::StatusbarProgressWidget::StatusbarProgressWidget
StatusbarProgressWidget(ProgressDialog *progressDialog, QWidget *parent, bool button=true)
Definition: statusbarprogresswidget.cpp:62
KPIM::StatusbarProgressWidget::slotSetSSL
void slotSetSSL(bool)
Definition: statusbarprogresswidget.cpp:231
KPIM::ProgressItem::parent
ProgressItem * parent() const
Definition: progressmanager.h:61
statusbarprogresswidget.h
QObject
KPIM::ProgressManager
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
Definition: progressmanager.h:278
KPIM::StatusbarProgressWidget::slotProgressItemCompleted
void slotProgressItemCompleted(KPIM::ProgressItem *i)
Definition: statusbarprogresswidget.cpp:158
KPIM::SSLLabel::lastState
State lastState() const
Definition: ssllabel.cpp:57
progressmanager.h
KPIM::StatusbarProgressWidget::slotProgressItemProgress
void slotProgressItemProgress(KPIM::ProgressItem *i, unsigned int value)
Definition: statusbarprogresswidget.cpp:224
KPIM::StatusbarProgressWidget::setMode
void setMode()
Definition: statusbarprogresswidget.cpp:236
KPIM::StatusbarProgressWidget::updateBusyMode
void updateBusyMode()
Definition: statusbarprogresswidget.cpp:133
KPIM::StatusbarProgressWidget::slotProgressDialogVisible
void slotProgressDialogVisible(bool)
Definition: statusbarprogresswidget.cpp:296
KPIM::StatusbarProgressWidget::slotProgressItemAdded
void slotProgressItemAdded(KPIM::ProgressItem *i)
Definition: statusbarprogresswidget.cpp:150
KPIM::StatusbarProgressWidget::slotBusyIndicator
void slotBusyIndicator()
Definition: statusbarprogresswidget.cpp:218
KPIM::ProgressDialog
Definition: progressdialog.h:116
KPIM::ProgressItem::progress
unsigned int progress() const
Definition: progressmanager.h:116
KPIM::StatusbarProgressWidget::connectSingleItem
void connectSingleItem()
Definition: statusbarprogresswidget.cpp:178
KPIM::StatusbarProgressWidget::slotShowItemDelayed
void slotShowItemDelayed()
Definition: statusbarprogresswidget.cpp:199
QLabel
KPIM::ProgressItem
Definition: progressmanager.h:45
KPIM::SSLLabel::setEncrypted
void setEncrypted(bool enc=true)
Definition: ssllabel.cpp:48
progressdialog.h
KPIM::StatusbarProgressWidget::activateSingleItemMode
void activateSingleItemMode()
Definition: statusbarprogresswidget.cpp:192
QFrame
KPIM::ProgressManager::singleItem
ProgressItem * singleItem() const
Definition: progressmanager.cpp:236
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal