• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <KLocalizedString>
27
28#include <QtCore/QEvent>
29#include <QPalette>
30
31using namespace Akonadi;
32
33//@cond PRIVATE
34
35class ErrorOverlayStatic
36{
37public:
38 QVector<QPair<QPointer<QWidget>, QPointer<QWidget> > > baseWidgets;
39};
40
41K_GLOBAL_STATIC(ErrorOverlayStatic, sInstanceOverlay)
42
43// return true if o1 is a parent of o2
44static bool isParentOf(QWidget *o1, QWidget *o2)
45{
46 if (!o1 || !o2) {
47 return false;
48 }
49 if (o1 == o2) {
50 return true;
51 }
52 if (o2->isWindow()) {
53 return false;
54 }
55 return isParentOf(o1, o2->parentWidget());
56}
57
58ErrorOverlay::ErrorOverlay(QWidget *baseWidget, QWidget *parent)
59 : QWidget(parent ? parent : baseWidget->window())
60 , mBaseWidget(baseWidget)
61 , mOverlayActive(false)
62 , mBaseWidgetIsParent(false)
63 , ui(new Ui::ErrorOverlay)
64{
65 Q_ASSERT(baseWidget);
66
67 mBaseWidgetIsParent = isParentOf(mBaseWidget, this);
68
69 // check existing overlays to detect cascading
70 for (QVector<QPair< QPointer<QWidget>, QPointer<QWidget> > >::Iterator it = sInstanceOverlay->baseWidgets.begin();
71 it != sInstanceOverlay->baseWidgets.end();) {
72 if ((*it).first == 0 || (*it).second == 0) {
73 // garbage collection
74 it = sInstanceOverlay->baseWidgets.erase(it);
75 continue;
76 }
77 if (isParentOf((*it).first, baseWidget)) {
78 // parent already has an overlay, kill ourselves
79 mBaseWidget = 0;
80 hide();
81 deleteLater();
82 return;
83 }
84 if (isParentOf(baseWidget, (*it).first)) {
85 // child already has overlay, kill that one
86 delete(*it).second;
87 it = sInstanceOverlay->baseWidgets.erase(it);
88 continue;
89 }
90 ++it;
91 }
92 sInstanceOverlay->baseWidgets.append(qMakePair(mBaseWidget, QPointer<QWidget>(this)));
93
94 connect(baseWidget, SIGNAL(destroyed()), SLOT(deleteLater()));
95 mPreviousState = mBaseWidget->isEnabled();
96
97 ui->setupUi(this);
98 ui->notRunningIcon->setPixmap(KIcon(QLatin1String("akonadi")).pixmap(64));
99 ui->brokenIcon->setPixmap(KIcon(QString::fromLatin1("dialog-error")).pixmap(64));
100 ui->progressIcon->setPixmap(KIcon(QLatin1String("akonadi")).pixmap(32));
101 ui->quitButton->setText(KStandardGuiItem::quit().text());
102 ui->detailsQuitButton->setText(KStandardGuiItem::quit().text());
103
104#ifndef KDEPIM_MOBILE_UI
105 ui->quitButton->hide();
106 ui->detailsQuitButton->hide();
107#endif
108
109 connect(ui->startButton, SIGNAL(clicked()), SLOT(startClicked()));
110 connect(ui->quitButton, SIGNAL(clicked()), SLOT(quitClicked()));
111 connect(ui->detailsQuitButton, SIGNAL(clicked()), SLOT(quitClicked()));
112 connect(ui->selfTestButton, SIGNAL(clicked()), SLOT(selfTestClicked()));
113
114 const ServerManager::State state = ServerManager::state();
115 mOverlayActive = (state == ServerManager::Running);
116 serverStateChanged(state);
117
118 connect(ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)),
119 SLOT(serverStateChanged(Akonadi::ServerManager::State)));
120
121 QPalette p = palette();
122 p.setColor(backgroundRole(), QColor(0, 0, 0, 128));
123 p.setColor(foregroundRole(), Qt::white);
124 setPalette(p);
125 setAutoFillBackground(true);
126
127 mBaseWidget->installEventFilter(this);
128
129 reposition();
130}
131
132ErrorOverlay::~ ErrorOverlay()
133{
134 if (mBaseWidget && !mBaseWidgetIsParent) {
135 mBaseWidget->setEnabled(mPreviousState);
136 }
137}
138
139void ErrorOverlay::reposition()
140{
141 if (!mBaseWidget) {
142 return;
143 }
144
145 // reparent to the current top level widget of the base widget if needed
146 // needed eg. in dock widgets
147 if (parentWidget() != mBaseWidget->window()) {
148 setParent(mBaseWidget->window());
149 }
150
151 // follow base widget visibility
152 // needed eg. in tab widgets
153 if (!mBaseWidget->isVisible()) {
154 hide();
155 return;
156 }
157 if (mOverlayActive) {
158 show();
159 }
160
161 // follow position changes
162 const QPoint topLevelPos = mBaseWidget->mapTo(window(), QPoint(0, 0));
163 const QPoint parentPos = parentWidget()->mapFrom(window(), topLevelPos);
164 move(parentPos);
165
166 // follow size changes
167 // TODO: hide/scale icon if we don't have enough space
168 resize(mBaseWidget->size());
169}
170
171bool ErrorOverlay::eventFilter(QObject *object, QEvent *event)
172{
173 if (object == mBaseWidget && mOverlayActive &&
174 (event->type() == QEvent::Move || event->type() == QEvent::Resize ||
175 event->type() == QEvent::Show || event->type() == QEvent::Hide ||
176 event->type() == QEvent::ParentChange)) {
177 reposition();
178 }
179 return QWidget::eventFilter(object, event);
180}
181
182void ErrorOverlay::startClicked()
183{
184 const ServerManager::State state = ServerManager::state();
185 if (state == ServerManager::Running) {
186 serverStateChanged(state);
187 } else {
188 ServerManager::start();
189 }
190}
191
192void ErrorOverlay::quitClicked()
193{
194 qApp->quit();
195}
196
197void ErrorOverlay::selfTestClicked()
198{
199 SelfTestDialog dlg;
200 dlg.exec();
201}
202
203void ErrorOverlay::serverStateChanged(ServerManager::State state)
204{
205 if (!mBaseWidget) {
206 return;
207 }
208
209 if (state == ServerManager::Running && mOverlayActive) {
210 mOverlayActive = false;
211 hide();
212 if (!mBaseWidgetIsParent) {
213 mBaseWidget->setEnabled(mPreviousState);
214 }
215 } else if (!mOverlayActive) {
216 mOverlayActive = true;
217 if (mBaseWidget->isVisible()) {
218 show();
219 }
220
221 if (!mBaseWidgetIsParent) {
222 mPreviousState = mBaseWidget->isEnabled();
223 mBaseWidget->setEnabled(false);
224 }
225
226 reposition();
227 }
228
229 if (mOverlayActive) {
230 switch (state) {
231 case ServerManager::NotRunning:
232 ui->stackWidget->setCurrentWidget(ui->notRunningPage);
233 break;
234 case ServerManager::Broken:
235 ui->stackWidget->setCurrentWidget(ui->brokenPage);
236 break;
237 case ServerManager::Starting:
238 ui->progressPage->setToolTip(i18n("Personal information management service is starting..."));
239 ui->progressDescription->setText(i18n("Personal information management service is starting..."));
240 ui->stackWidget->setCurrentWidget(ui->progressPage);
241 break;
242 case ServerManager::Stopping:
243 ui->progressPage->setToolTip(i18n("Personal information management service is shutting down..."));
244 ui->progressDescription->setText(i18n("Personal information management service is shutting down..."));
245 ui->stackWidget->setCurrentWidget(ui->progressPage);
246 break;
247 case ServerManager::Upgrading:
248 ui->progressPage->setToolTip(i18n("Personal information management service is performing a database upgrade."));
249 ui->progressDescription->setText(i18n("Personal information management service is performing a database upgrade.\n"
250 "This happens after a software update and is necessary to optimize performance.\n"
251 "Depending on the amount of personal information, this might take a few minutes."));
252 ui->stackWidget->setCurrentWidget(ui->progressPage);
253 break;
254 case ServerManager::Running:
255 break;
256 }
257 }
258}
259
260//@endcond
261
262#include "moc_erroroverlay_p.cpp"
Akonadi::ErrorOverlay
Definition: erroroverlay_p.h:44
Akonadi::ErrorOverlay::ErrorOverlay
ErrorOverlay(QWidget *baseWidget, QWidget *parent=0)
Create an overlay widget for baseWidget.
Akonadi::SelfTestDialog
A dialog that checks the current status of the Akonadi system.
Definition: selftestdialog_p.h:45
Akonadi::ServerManager::self
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
Definition: servermanager.cpp:161
Akonadi::ServerManager::state
static State state()
Returns the state of the server.
Definition: servermanager.cpp:226
Akonadi::ServerManager::start
static bool start()
Starts the server.
Definition: servermanager.cpp:166
Akonadi::ServerManager::State
State
Enum for the various states the server can be in.
Definition: servermanager.h:50
Akonadi::ServerManager::Running
@ Running
Server is running and operational.
Definition: servermanager.h:53
Akonadi::ServerManager::Starting
@ Starting
Server was started but is not yet running.
Definition: servermanager.h:52
Akonadi::ServerManager::Broken
@ Broken
Server is not operational and an error has been detected.
Definition: servermanager.h:55
Akonadi::ServerManager::Upgrading
@ Upgrading
Server is performing a database upgrade as part of a new startup.
Definition: servermanager.h:56
Akonadi::ServerManager::NotRunning
@ NotRunning
Server is not running, could be no one started it yet or it failed to start.
Definition: servermanager.h:51
Akonadi::ServerManager::Stopping
@ Stopping
Server is shutting down.
Definition: servermanager.h:54
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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