20 #include "erroroverlay_p.h"
21 #include "ui_erroroverlay.h"
22 #include "selftestdialog_p.h"
26 #include <KLocalizedString>
28 #include <QtCore/QEvent>
33 using namespace Akonadi;
37 class ErrorOverlayStatic
40 QVector<QPair<QPointer<QWidget>, QPointer<QWidget> > > baseWidgets;
43 K_GLOBAL_STATIC( ErrorOverlayStatic, sInstanceOverlay )
45 static
bool isParentOf( QObject* o1, QObject* o2 )
51 return isParentOf( o1, o2->parent() );
55 QWidget( parent ? parent : baseWidget->window() ),
56 mBaseWidget( baseWidget ),
57 mBaseWidgetIsParent( false ),
60 Q_ASSERT( baseWidget );
62 mBaseWidgetIsParent = isParentOf( mBaseWidget,
this );
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 ) {
69 it = sInstanceOverlay->baseWidgets.erase( it );
72 if ( isParentOf( ( *it ).first, baseWidget ) ) {
79 if ( isParentOf( baseWidget, ( *it ).first ) ) {
81 delete ( *it ).second;
82 it = sInstanceOverlay->baseWidgets.erase( it );
87 sInstanceOverlay->baseWidgets.append( qMakePair( mBaseWidget, QPointer<QWidget>(
this ) ) );
89 connect( baseWidget, SIGNAL(destroyed()), SLOT(deleteLater()) );
90 mPreviousState = mBaseWidget->isEnabled();
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() );
99 #ifndef KDEPIM_MOBILE_UI
100 ui->quitButton->hide();
101 ui->detailsQuitButton->hide();
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()) );
111 serverStateChanged( state );
116 QPalette p = palette();
117 p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
118 p.setColor( foregroundRole(), Qt::white );
120 setAutoFillBackground(
true );
122 mBaseWidget->installEventFilter(
this );
127 ErrorOverlay::~ ErrorOverlay()
129 if ( mBaseWidget && !mBaseWidgetIsParent )
130 mBaseWidget->setEnabled( mPreviousState );
133 void ErrorOverlay::reposition()
140 if ( parentWidget() != mBaseWidget->window() )
141 setParent( mBaseWidget->window() );
145 if ( !mBaseWidget->isVisible() ) {
149 if ( mOverlayActive )
153 const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
154 const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
159 resize( mBaseWidget->size() );
162 bool ErrorOverlay::eventFilter(QObject *
object, QEvent * event)
164 if (
object == mBaseWidget && mOverlayActive &&
165 ( event->type() == QEvent::Move ||
event->type() == QEvent::Resize ||
166 event->type() == QEvent::Show ||
event->type() == QEvent::Hide ||
167 event->type() == QEvent::ParentChange ) ) {
170 return QWidget::eventFilter(
object, event );
173 void ErrorOverlay::startClicked()
177 serverStateChanged( state );
183 void ErrorOverlay::quitClicked()
188 void ErrorOverlay::selfTestClicked()
200 mOverlayActive =
false;
202 if ( !mBaseWidgetIsParent )
203 mBaseWidget->setEnabled( mPreviousState );
204 }
else if ( !mOverlayActive ) {
205 mOverlayActive =
true;
206 if ( mBaseWidget->isVisible() )
209 if ( !mBaseWidgetIsParent ) {
210 mPreviousState = mBaseWidget->isEnabled();
211 mBaseWidget->setEnabled(
false );
217 if ( mOverlayActive ) {
220 ui->stackWidget->setCurrentWidget( ui->notRunningPage );
223 ui->stackWidget->setCurrentWidget( ui->brokenPage );
226 ui->progressPage->setToolTip( i18n(
"Personal information management service is starting..." ) );
227 ui->progressDescription->setText( i18n(
"Personal information management service is starting..." ) );
228 ui->stackWidget->setCurrentWidget( ui->progressPage );
231 ui->progressPage->setToolTip( i18n(
"Personal information management service is shutting down..." ) );
232 ui->progressDescription->setText( i18n(
"Personal information management service is shutting down..." ) );
233 ui->stackWidget->setCurrentWidget( ui->progressPage );
236 ui->progressPage->setToolTip( i18n(
"Personal information management service is performing a database upgrade." ) );
237 ui->progressDescription->setText( i18n(
"Personal information management service is performing a database upgrade. "
238 "This happens after a software update and is necessary to optimize performance. "
239 "Depending on the amount of personal information, this might take a few minutes.") );
240 ui->stackWidget->setCurrentWidget( ui->progressPage );
250 #include "moc_erroroverlay_p.cpp"
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
ErrorOverlay(QWidget *baseWidget, QWidget *parent=0)
Create an overlay widget for baseWidget.
static State state()
Returns the state of the server.
Server is performing a database upgrade as part of a new startup.
Server is not running, could be no one started it yet or it failed to start.
static bool start()
Starts the server.
Server was started but is not yet running.
Server is running and operational.
State
Enum for the various states the server can be in.
A dialog that checks the current status of the Akonadi system.
Server is not operational and an error has been detected.