• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 <QtGui/QBoxLayout>
30 #include <QtGui/QLabel>
31 #include <QtGui/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  connect( ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)),
113  SLOT(serverStateChanged(Akonadi::ServerManager::State)) );
114 
115  QPalette p = palette();
116  p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
117  p.setColor( foregroundRole(), Qt::white );
118  setPalette( p );
119  setAutoFillBackground( true );
120 
121  mBaseWidget->installEventFilter( this );
122 
123  reposition();
124 }
125 
126 ErrorOverlay::~ ErrorOverlay()
127 {
128  if ( mBaseWidget && !mBaseWidgetIsParent )
129  mBaseWidget->setEnabled( mPreviousState );
130 }
131 
132 void ErrorOverlay::reposition()
133 {
134  if ( !mBaseWidget )
135  return;
136 
137  // reparent to the current top level widget of the base widget if needed
138  // needed eg. in dock widgets
139  if ( parentWidget() != mBaseWidget->window() )
140  setParent( mBaseWidget->window() );
141 
142  // follow base widget visibility
143  // needed eg. in tab widgets
144  if ( !mBaseWidget->isVisible() ) {
145  hide();
146  return;
147  }
148  if ( mOverlayActive )
149  show();
150 
151  // follow position changes
152  const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
153  const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
154  move( parentPos );
155 
156  // follow size changes
157  // TODO: hide/scale icon if we don't have enough space
158  resize( mBaseWidget->size() );
159 }
160 
161 bool ErrorOverlay::eventFilter(QObject * object, QEvent * event)
162 {
163  if ( object == mBaseWidget && mOverlayActive &&
164  ( event->type() == QEvent::Move || event->type() == QEvent::Resize ||
165  event->type() == QEvent::Show || event->type() == QEvent::Hide ||
166  event->type() == QEvent::ParentChange ) ) {
167  reposition();
168  }
169  return QWidget::eventFilter( object, event );
170 }
171 
172 void ErrorOverlay::startClicked()
173 {
174  ServerManager::start();
175 }
176 
177 void ErrorOverlay::quitClicked()
178 {
179  qApp->quit();
180 }
181 
182 void ErrorOverlay::selfTestClicked()
183 {
184  SelfTestDialog dlg;
185  dlg.exec();
186 }
187 
188 void ErrorOverlay::serverStateChanged( ServerManager::State state )
189 {
190  if ( !mBaseWidget )
191  return;
192 
193  if ( state == ServerManager::Running && mOverlayActive ) {
194  mOverlayActive = false;
195  hide();
196  if ( !mBaseWidgetIsParent )
197  mBaseWidget->setEnabled( mPreviousState );
198  } else if ( !mOverlayActive ) {
199  mOverlayActive = true;
200  if ( mBaseWidget->isVisible() )
201  show();
202 
203  if ( !mBaseWidgetIsParent ) {
204  mPreviousState = mBaseWidget->isEnabled();
205  mBaseWidget->setEnabled( false );
206  }
207 
208  reposition();
209  }
210 
211  if ( mOverlayActive ) {
212  switch ( state ) {
213  case ServerManager::NotRunning:
214  ui->stackWidget->setCurrentWidget( ui->notRunningPage );
215  break;
216  case ServerManager::Broken:
217  ui->stackWidget->setCurrentWidget( ui->brokenPage );
218  break;
219  case ServerManager::Starting:
220  ui->progressPage->setToolTip( i18n( "Personal information management service is starting..." ) );
221  ui->progressDescription->setText( i18n( "Personal information management service is starting..." ) );
222  ui->stackWidget->setCurrentWidget( ui->progressPage );
223  break;
224  case ServerManager::Stopping:
225  ui->progressPage->setToolTip( i18n( "Personal information management service is shutting down..." ) );
226  ui->progressDescription->setText( i18n( "Personal information management service is shutting down..." ) );
227  ui->stackWidget->setCurrentWidget( ui->progressPage );
228  break;
229  case ServerManager::Running:
230  break;
231  }
232  }
233 }
234 
235 //@endcond
236 
237 #include "erroroverlay_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:14:32 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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