• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
erroroverlay.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "erroroverlay_p.h"
21 #include "ui_erroroverlay.h"
22 #include "selftestdialog_p.h"
23 
24 #include <KDebug>
25 #include <KIcon>
26 #include <KLocale>
27 
28 #include <QtCore/QEvent>
29 #include <QBoxLayout>
30 #include <QLabel>
31 #include <QPalette>
32 
33 using namespace Akonadi;
34 
35 //@cond PRIVATE
36 
37 class ErrorOverlayStatic
38 {
39  public:
40  QVector<QPair<QPointer<QWidget>, QPointer<QWidget> > > baseWidgets;
41 };
42 
43 K_GLOBAL_STATIC( ErrorOverlayStatic, sInstanceOverlay )
44 
45 static bool isParentOf( QObject* o1, QObject* o2 )
46 {
47  if ( !o1 || !o2 )
48  return false;
49  if ( o1 == o2 )
50  return true;
51  return isParentOf( o1, o2->parent() );
52 }
53 
54 ErrorOverlay::ErrorOverlay( QWidget *baseWidget, QWidget * parent ) :
55  QWidget( parent ? parent : baseWidget->window() ),
56  mBaseWidget( baseWidget ),
57  mBaseWidgetIsParent( false ),
58  ui( new Ui::ErrorOverlay )
59 {
60  Q_ASSERT( baseWidget );
61 
62  mBaseWidgetIsParent = isParentOf( mBaseWidget, this );
63 
64  // check existing overlays to detect cascading
65  for ( QVector<QPair< QPointer<QWidget>, QPointer<QWidget> > >::Iterator it = sInstanceOverlay->baseWidgets.begin();
66  it != sInstanceOverlay->baseWidgets.end(); ) {
67  if ( ( *it ).first == 0 || ( *it ).second == 0 ) {
68  // garbage collection
69  it = sInstanceOverlay->baseWidgets.erase( it );
70  continue;
71  }
72  if ( isParentOf( ( *it ).first, baseWidget ) ) {
73  // parent already has an overlay, kill ourselves
74  mBaseWidget = 0;
75  hide();
76  deleteLater();
77  return;
78  }
79  if ( isParentOf( baseWidget, ( *it ).first ) ) {
80  // child already has overlay, kill that one
81  delete ( *it ).second;
82  it = sInstanceOverlay->baseWidgets.erase( it );
83  continue;
84  }
85  ++it;
86  }
87  sInstanceOverlay->baseWidgets.append( qMakePair( mBaseWidget, QPointer<QWidget>( this ) ) );
88 
89  connect( baseWidget, SIGNAL(destroyed()), SLOT(deleteLater()) );
90  mPreviousState = mBaseWidget->isEnabled();
91 
92  ui->setupUi( this );
93  ui->notRunningIcon->setPixmap( KIcon( QLatin1String( "akonadi" ) ).pixmap( 64 ) );
94  ui->brokenIcon->setPixmap( KIcon( QString::fromLatin1( "dialog-error" ) ).pixmap( 64 ) );
95  ui->progressIcon->setPixmap( KIcon( QLatin1String( "akonadi" ) ).pixmap( 32 ) );
96  ui->quitButton->setText( KStandardGuiItem::quit().text() );
97  ui->detailsQuitButton->setText( KStandardGuiItem::quit().text() );
98 
99 #ifndef KDEPIM_MOBILE_UI
100  ui->quitButton->hide();
101  ui->detailsQuitButton->hide();
102 #endif
103 
104  connect( ui->startButton, SIGNAL(clicked()), SLOT(startClicked()) );
105  connect( ui->quitButton, SIGNAL(clicked()), SLOT(quitClicked()) );
106  connect( ui->detailsQuitButton, SIGNAL(clicked()), SLOT(quitClicked()) );
107  connect( ui->selfTestButton, SIGNAL(clicked()), SLOT(selfTestClicked()) );
108 
109  const ServerManager::State state = ServerManager::state();
110  mOverlayActive = (state == ServerManager::Running);
111  serverStateChanged( state );
112 
113  connect( ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)),
114  SLOT(serverStateChanged(Akonadi::ServerManager::State)) );
115 
116 
117 
118  QPalette p = palette();
119  p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
120  p.setColor( foregroundRole(), Qt::white );
121  setPalette( p );
122  setAutoFillBackground( true );
123 
124  mBaseWidget->installEventFilter( this );
125 
126  reposition();
127 }
128 
129 ErrorOverlay::~ ErrorOverlay()
130 {
131  if ( mBaseWidget && !mBaseWidgetIsParent )
132  mBaseWidget->setEnabled( mPreviousState );
133 }
134 
135 void ErrorOverlay::reposition()
136 {
137  if ( !mBaseWidget )
138  return;
139 
140  // reparent to the current top level widget of the base widget if needed
141  // needed eg. in dock widgets
142  if ( parentWidget() != mBaseWidget->window() )
143  setParent( mBaseWidget->window() );
144 
145  // follow base widget visibility
146  // needed eg. in tab widgets
147  if ( !mBaseWidget->isVisible() ) {
148  hide();
149  return;
150  }
151  if ( mOverlayActive )
152  show();
153 
154  // follow position changes
155  const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
156  const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
157  move( parentPos );
158 
159  // follow size changes
160  // TODO: hide/scale icon if we don't have enough space
161  resize( mBaseWidget->size() );
162 }
163 
164 bool ErrorOverlay::eventFilter(QObject * object, QEvent * event)
165 {
166  if ( object == mBaseWidget && mOverlayActive &&
167  ( event->type() == QEvent::Move || event->type() == QEvent::Resize ||
168  event->type() == QEvent::Show || event->type() == QEvent::Hide ||
169  event->type() == QEvent::ParentChange ) ) {
170  reposition();
171  }
172  return QWidget::eventFilter( object, event );
173 }
174 
175 void ErrorOverlay::startClicked()
176 {
177  const ServerManager::State state = ServerManager::state();
178  if( state == ServerManager::Running ) {
179  serverStateChanged( state );
180  } else {
181  ServerManager::start();
182  }
183 }
184 
185 void ErrorOverlay::quitClicked()
186 {
187  qApp->quit();
188 }
189 
190 void ErrorOverlay::selfTestClicked()
191 {
192  SelfTestDialog dlg;
193  dlg.exec();
194 }
195 
196 void ErrorOverlay::serverStateChanged( ServerManager::State state )
197 {
198  if ( !mBaseWidget )
199  return;
200 
201  if ( state == ServerManager::Running && mOverlayActive ) {
202  mOverlayActive = false;
203  hide();
204  if ( !mBaseWidgetIsParent )
205  mBaseWidget->setEnabled( mPreviousState );
206  } else if ( !mOverlayActive ) {
207  mOverlayActive = true;
208  if ( mBaseWidget->isVisible() )
209  show();
210 
211  if ( !mBaseWidgetIsParent ) {
212  mPreviousState = mBaseWidget->isEnabled();
213  mBaseWidget->setEnabled( false );
214  }
215 
216  reposition();
217  }
218 
219  if ( mOverlayActive ) {
220  switch ( state ) {
221  case ServerManager::NotRunning:
222  ui->stackWidget->setCurrentWidget( ui->notRunningPage );
223  break;
224  case ServerManager::Broken:
225  ui->stackWidget->setCurrentWidget( ui->brokenPage );
226  break;
227  case ServerManager::Starting:
228  ui->progressPage->setToolTip( i18n( "Personal information management service is starting..." ) );
229  ui->progressDescription->setText( i18n( "Personal information management service is starting..." ) );
230  ui->stackWidget->setCurrentWidget( ui->progressPage );
231  break;
232  case ServerManager::Stopping:
233  ui->progressPage->setToolTip( i18n( "Personal information management service is shutting down..." ) );
234  ui->progressDescription->setText( i18n( "Personal information management service is shutting down..." ) );
235  ui->stackWidget->setCurrentWidget( ui->progressPage );
236  break;
237  case ServerManager::Upgrading:
238  ui->progressPage->setToolTip( i18n( "Personal information management service is performing a database upgrade." ) );
239  ui->progressDescription->setText( i18n( "Personal information management service is performing a database upgrade. "
240  "This happens after a software update and is necessary to optimize performance. "
241  "Depending on the amount of personal information, this might take a few minutes.") );
242  ui->stackWidget->setCurrentWidget( ui->progressPage );
243  break;
244  case ServerManager::Running:
245  break;
246  }
247  }
248 }
249 
250 //@endcond
251 
252 #include "moc_erroroverlay_p.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:36 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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