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() ) {
184 : d( new Private( this ) )
190 if ( QCoreApplication::instance() ) {
191 connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(cleanup()) );
203 kDebug() <<
"Server is currently being stopped, wont try to start it now";
207 kDebug() <<
"Server is already running";
210 s_instance->d->mStarting =
true;
212 kDebug() <<
"ServerManager::start failed -> return false";
215 return s_instance->d->exec();
226 s_instance->d->mStopping =
true;
230 return s_instance->d->exec();
245 s_instance->d->setupProgressIndicator( i18n(
"Starting Akonadi server..." ), parent );
251 s_instance->d->setupProgressIndicator( i18n(
"Stopping Akonadi server..." ), parent );
258 if ( !
stop( parent ) ) {
262 return start( parent );
267 s_instance->d->mPendingOverlays.append( widget );
270 QTimer::singleShot( 0, s_instance, SLOT(createErrorOverlays()) );
275 #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 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.
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.