21 #include "servermanager.h"
22 #include "ui_controlprogressindicator.h"
24 #include "selftestdialog_p.h"
25 #include "erroroverlay_p.h"
30 #include <klocalizedstring.h>
32 #include <QtCore/QEventLoop>
33 #include <QtCore/QCoreApplication>
34 #include <QtCore/QTimer>
35 #include <QtCore/QPointer>
38 using namespace Akonadi;
43 class ControlProgressIndicator :
public QFrame
46 ControlProgressIndicator( QWidget *parent = 0 ) :
49 setWindowModality( Qt::ApplicationModal );
51 setWindowFlags( Qt::FramelessWindowHint | Qt::Dialog );
54 setFrameShadow( QFrame::Plain );
55 setFrameShape( QFrame::Box );
58 void setMessage(
const QString &msg )
60 ui.statusLabel->setText( msg );
63 Ui::ControlProgressIndicator ui;
66 class StaticControl :
public Control
74 K_GLOBAL_STATIC( Internal::StaticControl, s_instance )
83 : mParent( parent ), mEventLoop( 0 ),
84 mProgressIndicator( 0 ),
86 mStarting( false ), mStopping( false )
92 delete mProgressIndicator;
95 void setupProgressIndicator(
const QString &msg, QWidget *parent = 0 )
97 if ( !mProgressIndicator ) {
98 mProgressIndicator =
new Internal::ControlProgressIndicator( parent );
101 mProgressIndicator->setMessage( msg );
104 void createErrorOverlays()
107 foreach ( QWidget *widget, mPendingOverlays ) {
113 mPendingOverlays.clear();
118 s_instance.destroy();
124 QPointer<Control> mParent;
125 QEventLoop *mEventLoop;
126 QPointer<Internal::ControlProgressIndicator> mProgressIndicator;
127 QList<QPointer<QWidget> > mPendingOverlays;
134 bool Control::Private::exec()
136 if ( mProgressIndicator ) {
137 mProgressIndicator->show();
140 kDebug() <<
"Starting/Stopping Akonadi (using an event loop).";
141 mEventLoop =
new QEventLoop( mParent );
143 mEventLoop->deleteLater();
147 kWarning() <<
"Could not start/stop Akonadi!";
149 if ( mProgressIndicator && mStarting ) {
150 QPointer<SelfTestDialog> dlg =
new SelfTestDialog( mProgressIndicator->parentWidget() );
160 delete mProgressIndicator;
161 mProgressIndicator = 0;
165 const bool rv = mSuccess;
173 if ( mEventLoop && mEventLoop->isRunning() ) {
180 : d( new Private( this ) )
186 if ( QCoreApplication::instance() ) {
187 connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(cleanup()) );
199 kDebug() <<
"Server is currently being stopped, wont try to start it now";
203 kDebug() <<
"Server is already running";
206 s_instance->d->mStarting =
true;
208 kDebug() <<
"ServerManager::start failed -> return false";
211 return s_instance->d->exec();
222 s_instance->d->mStopping =
true;
226 return s_instance->d->exec();
241 s_instance->d->setupProgressIndicator( i18n(
"Starting Akonadi server..." ), parent );
247 s_instance->d->setupProgressIndicator( i18n(
"Stopping Akonadi server..." ), parent );
254 if ( !
stop( parent ) ) {
258 return start( parent );
263 s_instance->d->mPendingOverlays.append( widget );
266 QTimer::singleShot( 0, s_instance, SLOT(createErrorOverlays()) );
271 #include "moc_control.cpp"
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
Provides methods to control the Akonadi server process.
static bool stop()
Stops the Akonadi server synchronously if it is currently running.
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
static State state()
Returns the state of the server.
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.
static bool start()
Starts the Akonadi server synchronously if it is not already running.
Control()
Creates the control object.
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.
~Control()
Destroys the control object.
static bool stop()
Stops the server.
static bool isRunning()
Checks if the server is available currently.
static bool restart()
Restarts the Akonadi server synchronously.