21#include "servermanager.h"
22#include "ui_controlprogressindicator.h"
23#include "selftestdialog_p.h"
24#include "erroroverlay_p.h"
28#include <klocalizedstring.h>
30#include <QtCore/QEventLoop>
31#include <QtCore/QCoreApplication>
32#include <QtCore/QTimer>
33#include <QtCore/QPointer>
41class ControlProgressIndicator :
public QFrame
44 ControlProgressIndicator(QWidget *parent = 0)
47 setWindowModality(Qt::ApplicationModal);
49 setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
52 setFrameShadow(QFrame::Plain);
53 setFrameShape(QFrame::Box);
56 void setMessage(
const QString &msg)
58 ui.statusLabel->setText(msg);
61 Ui::ControlProgressIndicator ui;
64class StaticControl :
public Control
75K_GLOBAL_STATIC(Internal::StaticControl, s_instance)
86 , mProgressIndicator(0)
95 delete mProgressIndicator;
98 void setupProgressIndicator(
const QString &msg, QWidget *parent = 0)
100 if (!mProgressIndicator) {
101 mProgressIndicator =
new Internal::ControlProgressIndicator(parent);
104 mProgressIndicator->setMessage(msg);
107 void createErrorOverlays()
109 foreach (QWidget *widget, mPendingOverlays) {
114 mPendingOverlays.clear();
119 s_instance.destroy();
125 QPointer<Control> mParent;
126 QEventLoop *mEventLoop;
127 QPointer<Internal::ControlProgressIndicator> mProgressIndicator;
128 QList<QPointer<QWidget> > mPendingOverlays;
135bool Control::Private::exec()
137 if (mProgressIndicator) {
138 mProgressIndicator->show();
141 kDebug() <<
"Starting/Stopping Akonadi (using an event loop).";
142 mEventLoop =
new QEventLoop(mParent);
144 mEventLoop->deleteLater();
148 kWarning() <<
"Could not start/stop Akonadi!";
149 if (mProgressIndicator && mStarting) {
150 QPointer<SelfTestDialog> dlg =
new SelfTestDialog(mProgressIndicator->parentWidget());
159 delete mProgressIndicator;
160 mProgressIndicator = 0;
164 const bool rv = mSuccess;
172 if (mEventLoop && mEventLoop->isRunning()) {
183 : d(new Private(this))
189 if (QCoreApplication::instance()) {
190 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(cleanup()));
202 kDebug() <<
"Server is currently being stopped, wont try to start it now";
206 kDebug() <<
"Server is already running";
209 s_instance->d->mStarting =
true;
211 kDebug() <<
"ServerManager::start failed -> return false";
214 return s_instance->d->exec();
225 s_instance->d->mStopping =
true;
229 return s_instance->d->exec();
244 s_instance->d->setupProgressIndicator(i18n(
"Starting Akonadi server..."), parent);
250 s_instance->d->setupProgressIndicator(i18n(
"Stopping Akonadi server..."), parent);
261 return start(parent);
266 s_instance->d->mPendingOverlays.append(widget);
269 QTimer::singleShot(0, s_instance, SLOT(createErrorOverlays()));
274#include "moc_control.cpp"
Provides methods to control the Akonadi server process.
static bool start()
Starts the Akonadi server synchronously if it is not already running.
static bool restart()
Restarts the Akonadi server synchronously.
static bool stop()
Stops the Akonadi server synchronously if it is currently running.
Control()
Creates the control object.
~Control()
Destroys the control object.
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
A dialog that checks the current status of the Akonadi system.
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
static State state()
Returns the state of the server.
static bool isRunning()
Checks if the server is available currently.
static bool start()
Starts the server.
static bool stop()
Stops the server.
State
Enum for the various states the server can be in.
@ Running
Server is running and operational.
@ Starting
Server was started but is not yet running.
@ Upgrading
Server is performing a database upgrade as part of a new startup.
@ NotRunning
Server is not running, could be no one started it yet or it failed to start.
@ Stopping
Server is shutting down.
FreeBusyManager::Singleton.