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

libkdepim

  • sources
  • kde-4.14
  • 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 ),
64  mShowTypeProgressItem( 0 ),
65  mCurrentItem( 0 ),
66  mProgressDialog( progressDialog ),
67  mDelayTimer( 0 ),
68  mBusyTimer( 0 ),
69  mCleanTimer( 0 )
70 {
71  m_bShowButton = button;
72  int w = fontMetrics().width( QLatin1String(" 999.9 kB/s 00:00:01 ") ) + 8;
73  QHBoxLayout *box = new QHBoxLayout( this );
74  box->setMargin(0);
75  box->setSpacing(0);
76 
77  m_pButton = new QPushButton( this );
78  m_pButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,
79  QSizePolicy::Minimum ) );
80  QPixmap smallIcon = SmallIcon( QLatin1String("go-up") );
81  m_pButton->setIcon( smallIcon );
82  box->addWidget( m_pButton );
83  stack = new QStackedWidget( this );
84  int maximumHeight = qMax( smallIcon.height(), fontMetrics().height() );
85  stack->setMaximumHeight( maximumHeight );
86  box->addWidget( stack );
87 
88  m_sslLabel = new SSLLabel( this );
89  box->addWidget( m_sslLabel );
90 
91  m_pButton->setToolTip( i18n("Open detailed progress dialog") );
92 
93  m_pProgressBar = new QProgressBar( this );
94  m_pProgressBar->installEventFilter( this );
95  m_pProgressBar->setMinimumWidth( w );
96  stack->insertWidget( 1,m_pProgressBar );
97 
98  m_pLabel = new QLabel( QString(), this );
99  m_pLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
100  m_pLabel->installEventFilter( this );
101  m_pLabel->setMinimumWidth( w );
102  stack->insertWidget( 2, m_pLabel );
103  m_pButton->setMaximumHeight( maximumHeight );
104  setMinimumWidth( minimumSizeHint().width() );
105 
106  mode = None;
107  setMode();
108 
109  connect( m_pButton, SIGNAL(clicked()),
110  progressDialog, SLOT(slotToggleVisibility()) );
111 
112  connect ( ProgressManager::instance(), SIGNAL(progressItemAdded(KPIM::ProgressItem*)),
113  this, SLOT(slotProgressItemAdded(KPIM::ProgressItem*)) );
114  connect ( ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*)),
115  this, SLOT(slotProgressItemCompleted(KPIM::ProgressItem*)) );
116  connect ( ProgressManager::instance(), SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)),
117  this, SLOT(updateBusyMode(KPIM::ProgressItem*)) );
118 
119  connect ( progressDialog, SIGNAL(visibilityChanged(bool)),
120  this, SLOT(slotProgressDialogVisible(bool)) );
121 
122  mDelayTimer = new QTimer( this );
123  mDelayTimer->setSingleShot( true );
124  connect ( mDelayTimer, SIGNAL(timeout()),
125  this, SLOT(slotShowItemDelayed()) );
126 
127  mCleanTimer = new QTimer( this );
128  mCleanTimer->setSingleShot( true );
129  connect ( mCleanTimer, SIGNAL(timeout()),
130  this, SLOT(slotClean()) );
131 }
132 
133 void StatusbarProgressWidget::setShowTypeProgressItem(unsigned int type)
134 {
135  mShowTypeProgressItem = type;
136 }
137 
138 // There are three cases: no progressitem, one progressitem (connect to it directly),
139 // or many progressitems (display busy indicator). Let's call them 0,1,N.
140 // In slot..Added we can only end up in 1 or N.
141 // In slot..Removed we can end up in 0, 1, or we can stay in N if we were already.
142 
143 void StatusbarProgressWidget::updateBusyMode(KPIM::ProgressItem *item)
144 {
145  if (item->typeProgressItem() == mShowTypeProgressItem) {
146  connectSingleItem(); // if going to 1 item
147  if ( mCurrentItem ) { // Exactly one item
148  delete mBusyTimer;
149  mBusyTimer = 0;
150  mDelayTimer->start( 1000 );
151  } else { // N items
152  if ( !mBusyTimer ) {
153  mBusyTimer = new QTimer( this );
154  connect( mBusyTimer, SIGNAL(timeout()),
155  this, SLOT(slotBusyIndicator()) );
156  mDelayTimer->start( 1000 );
157  }
158  }
159  }
160 }
161 
162 void StatusbarProgressWidget::slotProgressItemAdded( ProgressItem *item )
163 {
164  if ( item->parent() )
165  return; // we are only interested in top level items
166 
167  updateBusyMode(item);
168 }
169 
170 void StatusbarProgressWidget::slotProgressItemCompleted( ProgressItem *item )
171 {
172  if ( item->parent() ) {
173  item->deleteLater();
174  item = 0;
175  return; // we are only interested in top level items
176  }
177  item->deleteLater();
178  item = 0;
179  connectSingleItem(); // if going back to 1 item
180  if ( ProgressManager::instance()->isEmpty() ) { // No item
181  // Done. In 5s the progress-widget will close, then we can clean up the statusbar
182  mCleanTimer->start( 5000 );
183  } else if ( mCurrentItem ) { // Exactly one item
184  delete mBusyTimer;
185  mBusyTimer = 0;
186  activateSingleItemMode();
187  }
188 }
189 
190 void StatusbarProgressWidget::connectSingleItem()
191 {
192  if ( mCurrentItem ) {
193  disconnect ( mCurrentItem, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)),
194  this, SLOT(slotProgressItemProgress(KPIM::ProgressItem*,uint)) );
195  mCurrentItem = 0;
196  }
197  mCurrentItem = ProgressManager::instance()->singleItem();
198  if ( mCurrentItem ) {
199  connect ( mCurrentItem, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)),
200  this, SLOT(slotProgressItemProgress(KPIM::ProgressItem*,uint)) );
201  }
202 }
203 
204 void StatusbarProgressWidget::activateSingleItemMode()
205 {
206  m_pProgressBar->setMaximum( 100 );
207  m_pProgressBar->setValue( mCurrentItem->progress() );
208  m_pProgressBar->setTextVisible( true );
209 }
210 
211 void StatusbarProgressWidget::slotShowItemDelayed()
212 {
213  bool noItems = ProgressManager::instance()->isEmpty();
214  if ( mCurrentItem ) {
215  activateSingleItemMode();
216  } else if ( !noItems ) { // N items
217  m_pProgressBar->setMaximum( 0 );
218  m_pProgressBar->setTextVisible( false );
219  Q_ASSERT( mBusyTimer );
220  if ( mBusyTimer )
221  mBusyTimer->start( 100 );
222  }
223 
224  if ( !noItems && mode == None ) {
225  mode = Progress;
226  setMode();
227  }
228 }
229 
230 void StatusbarProgressWidget::slotBusyIndicator()
231 {
232  const int p = m_pProgressBar->value();
233  m_pProgressBar->setValue( p + 10 );
234 }
235 
236 void StatusbarProgressWidget::slotProgressItemProgress( ProgressItem *item, unsigned int value )
237 {
238  Q_ASSERT( item == mCurrentItem); // the only one we should be connected to
239  Q_UNUSED( item );
240  m_pProgressBar->setValue( value );
241 }
242 
243 void StatusbarProgressWidget::setMode() {
244  switch ( mode ) {
245  case None:
246  if ( m_bShowButton ) {
247  m_pButton->hide();
248  }
249  m_sslLabel->setState( SSLLabel::Done );
250  // show the empty label in order to make the status bar look better
251  stack->show();
252  stack->setCurrentWidget( m_pLabel );
253  break;
254 
255  case Progress:
256  stack->show();
257  stack->setCurrentWidget( m_pProgressBar );
258  if ( m_bShowButton ) {
259  m_pButton->show();
260  }
261  m_sslLabel->setState( m_sslLabel->lastState() );
262  break;
263  }
264 }
265 
266 void StatusbarProgressWidget::slotClean()
267 {
268  // check if a new item showed up since we started the timer. If not, clear
269  if ( ProgressManager::instance()->isEmpty() ) {
270  m_pProgressBar->setValue( 0 );
271  //m_pLabel->clear();
272  mode = None;
273  setMode();
274  }
275 }
276 
277 bool StatusbarProgressWidget::eventFilter( QObject *, QEvent *ev )
278 {
279  if ( ev->type() == QEvent::MouseButtonPress ) {
280  QMouseEvent *e = (QMouseEvent*)ev;
281 
282  if ( e->button() == Qt::LeftButton && mode != None ) { // toggle view on left mouse button
283  // Consensus seems to be that we should show/hide the fancy dialog when the user
284  // clicks anywhere in the small one.
285  mProgressDialog->slotToggleVisibility();
286  return true;
287  }
288  }
289  return false;
290 }
291 
292 void StatusbarProgressWidget::slotProgressDialogVisible( bool b )
293 {
294  // Update the hide/show button when the detailed one is shown/hidden
295  if ( b ) {
296  m_pButton->setIcon( SmallIcon( QLatin1String("go-down" )) );
297  m_pButton->setToolTip( i18n("Hide detailed progress window") );
298  setMode();
299  } else {
300  m_pButton->setIcon( SmallIcon( QLatin1String("go-up") ) );
301  m_pButton->setToolTip( i18n("Show detailed progress window") );
302  }
303 }
304 
KPIM::StatusbarProgressWidget::slotClean
void slotClean()
Definition: statusbarprogresswidget.cpp:266
QProgressBar
KPIM::SSLLabel::setState
void setState(State state)
Definition: ssllabel.cpp:58
KPIM::StatusbarProgressWidget::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: statusbarprogresswidget.cpp:277
QEvent
QWidget
KPIM::ProgressManager::instance
static ProgressManager * instance()
Definition: progressmanager.cpp:199
QProgressBar::setMaximum
void setMaximum(int maximum)
KPIM::SSLLabel
Definition: ssllabel.h:39
QEvent::type
Type type() const
KPIM::ProgressManager::isEmpty
bool isEmpty() const
Definition: progressmanager.cpp:209
KPIM::SSLLabel::Done
Definition: ssllabel.h:46
KPIM::StatusbarProgressWidget::updateBusyMode
void updateBusyMode(KPIM::ProgressItem *)
Definition: statusbarprogresswidget.cpp:143
KPIM::ProgressDialog::slotToggleVisibility
void slotToggleVisibility()
Definition: progressdialog.cpp:422
KPIM::StatusbarProgressWidget::setShowTypeProgressItem
void setShowTypeProgressItem(unsigned int type)
Definition: statusbarprogresswidget.cpp:133
QWidget::setMinimumWidth
void setMinimumWidth(int minw)
QSizePolicy
ssllabel.h
KPIM::StatusbarProgressWidget::StatusbarProgressWidget
StatusbarProgressWidget(ProgressDialog *progressDialog, QWidget *parent, bool button=true)
Definition: statusbarprogresswidget.cpp:62
QHBoxLayout
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
QWidget::minimumSizeHint
virtual QSize minimumSizeHint() const
QMouseEvent
KPIM::ProgressItem::parent
ProgressItem * parent() const
Definition: progressmanager.h:67
statusbarprogresswidget.h
QProgressBar::setValue
void setValue(int value)
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
QWidget::width
int width() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QStackedWidget::setCurrentWidget
void setCurrentWidget(QWidget *widget)
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
QTimer
KPIM::ProgressManager
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
Definition: progressmanager.h:285
KPIM::StatusbarProgressWidget::slotProgressItemCompleted
void slotProgressItemCompleted(KPIM::ProgressItem *i)
Definition: statusbarprogresswidget.cpp:170
QObject
QMouseEvent::button
Qt::MouseButton button() const
progressmanager.h
KPIM::StatusbarProgressWidget::slotProgressItemProgress
void slotProgressItemProgress(KPIM::ProgressItem *i, unsigned int value)
Definition: statusbarprogresswidget.cpp:236
KPIM::StatusbarProgressWidget::setMode
void setMode()
Definition: statusbarprogresswidget.cpp:243
QStackedWidget
QObject::deleteLater
void deleteLater()
KPIM::StatusbarProgressWidget::slotProgressDialogVisible
void slotProgressDialogVisible(bool)
Definition: statusbarprogresswidget.cpp:292
QString
QWidget::hide
void hide()
QLayout::setMargin
void setMargin(int margin)
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
KPIM::StatusbarProgressWidget::slotProgressItemAdded
void slotProgressItemAdded(KPIM::ProgressItem *i)
Definition: statusbarprogresswidget.cpp:162
QPixmap
KPIM::StatusbarProgressWidget::slotBusyIndicator
void slotBusyIndicator()
Definition: statusbarprogresswidget.cpp:230
QPixmap::height
int height() const
QFrame
QFontMetrics::width
int width(const QString &text, int len) const
KPIM::ProgressDialog
Definition: progressdialog.h:118
KPIM::ProgressItem::progress
unsigned int progress() const
Definition: progressmanager.h:127
KPIM::ProgressItem::typeProgressItem
unsigned int typeProgressItem() const
Definition: progressmanager.cpp:107
KPIM::StatusbarProgressWidget::connectSingleItem
void connectSingleItem()
Definition: statusbarprogresswidget.cpp:190
KPIM::StatusbarProgressWidget::slotShowItemDelayed
void slotShowItemDelayed()
Definition: statusbarprogresswidget.cpp:211
QWidget::fontMetrics
QFontMetrics fontMetrics() const
KPIM::SSLLabel::lastState
State lastState() const
Definition: ssllabel.cpp:53
QStackedWidget::insertWidget
int insertWidget(int index, QWidget *widget)
QLatin1String
QWidget::maximumHeight
int maximumHeight() const
KPIM::ProgressItem
Definition: progressmanager.h:45
QFontMetrics::height
int height() const
QTimer::start
void start(int msec)
QPushButton
QWidget::show
void show()
QWidget::setToolTip
void setToolTip(const QString &)
progressdialog.h
KPIM::StatusbarProgressWidget::activateSingleItemMode
void activateSingleItemMode()
Definition: statusbarprogresswidget.cpp:204
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QProgressBar::setTextVisible
void setTextVisible(bool visible)
QBoxLayout::setSpacing
void setSpacing(int spacing)
KPIM::ProgressManager::singleItem
ProgressItem * singleItem() const
Definition: progressmanager.cpp:319
QTimer::setSingleShot
void setSingleShot(bool singleShot)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:50 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
  • pimprint

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