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>
36 using namespace Akonadi;
41 class 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;
64 class StaticControl :
public Control
72 K_GLOBAL_STATIC( Internal::StaticControl, s_instance )
81 : mParent( parent ), mEventLoop( 0 ),
82 mProgressIndicator( 0 ),
84 mStarting( false ), mStopping( false )
90 delete mProgressIndicator;
93 void setupProgressIndicator(
const QString &msg, QWidget *parent = 0 )
95 if ( !mProgressIndicator ) {
96 mProgressIndicator =
new Internal::ControlProgressIndicator( parent );
99 mProgressIndicator->setMessage( msg );
102 void createErrorOverlays()
104 foreach ( QWidget *widget, mPendingOverlays ) {
109 mPendingOverlays.clear();
114 s_instance.destroy();
120 QPointer<Control> mParent;
121 QEventLoop *mEventLoop;
122 QPointer<Internal::ControlProgressIndicator> mProgressIndicator;
123 QList<QPointer<QWidget> > mPendingOverlays;
130 bool Control::Private::exec()
132 if ( mProgressIndicator ) {
133 mProgressIndicator->show();
136 kDebug() <<
"Starting/Stopping Akonadi (using an event loop).";
137 mEventLoop =
new QEventLoop( mParent );
139 mEventLoop->deleteLater();
143 kWarning() <<
"Could not start/stop Akonadi!";
144 if ( mProgressIndicator && mStarting ) {
145 QPointer<SelfTestDialog> dlg =
new SelfTestDialog( mProgressIndicator->parentWidget() );
154 delete mProgressIndicator;
155 mProgressIndicator = 0;
159 const bool rv = mSuccess;
167 if ( mEventLoop && mEventLoop->isRunning() ) {
178 : d( new Private( this ) )
184 if ( QCoreApplication::instance() ) {
185 connect( QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(cleanup()) );
197 kDebug() <<
"Server is currently being stopped, wont try to start it now";
201 kDebug() <<
"Server is already running";
204 s_instance->d->mStarting =
true;
206 kDebug() <<
"ServerManager::start failed -> return false";
209 return s_instance->d->exec();
220 s_instance->d->mStopping =
true;
224 return s_instance->d->exec();
239 s_instance->d->setupProgressIndicator( i18n(
"Starting Akonadi server..." ), parent );
245 s_instance->d->setupProgressIndicator( i18n(
"Stopping Akonadi server..." ), parent );
252 if ( !
stop( parent ) ) {
256 return start( parent );
261 s_instance->d->mPendingOverlays.append( widget );
264 QTimer::singleShot( 0, s_instance, SLOT(createErrorOverlays()) );
269 #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.