File indexing completed on 2024-06-16 04:50:13

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QObject>
0012 
0013 #include <memory>
0014 
0015 namespace Akonadi
0016 {
0017 class ControlPrivate;
0018 
0019 /**
0020  * @short Provides methods to control the Akonadi server process.
0021  *
0022  * This class provides synchronous methods (ie. use a sub-eventloop)
0023  * to control the Akonadi service. For asynchronous methods see
0024  * Akonadi::ServerManager.
0025  *
0026  * The most important method in here is widgetNeedsAkonadi(). It is
0027  * recommended to call it with every top-level widget of your application
0028  * as argument, assuming your application relies on Akonadi being operational
0029  * of course.
0030  *
0031  * While the Akonadi server automatically started by Akonadi::Session
0032  * on first use, it might be necessary for some use-cases to guarantee
0033  * a running Akonadi service at some point. This can be done using
0034  * start().
0035  *
0036  * Example:
0037  *
0038  * @code
0039  *
0040  * if ( !Akonadi::Control::start() ) {
0041  *   qDebug() << "Unable to start Akonadi server, exit application";
0042  *   return 1;
0043  * } else {
0044  *   ...
0045  * }
0046  *
0047  * @endcode
0048  *
0049  * @author Volker Krause <vkrause@kde.org>
0050  *
0051  * @see Akonadi::ServerManager
0052  */
0053 class AKONADICORE_EXPORT Control : public QObject
0054 {
0055     Q_OBJECT
0056 
0057 public:
0058     /**
0059      * Destroys the control object.
0060      */
0061     ~Control() override;
0062 
0063     /**
0064      * Starts the Akonadi server synchronously if it is not already running.
0065      * @return @c true if the server was started successfully or was already
0066      * running, @c false otherwise
0067      */
0068     static bool start();
0069 
0070     /**
0071      * Stops the Akonadi server synchronously if it is currently running.
0072      * @return @c true if the server was shutdown successfully or was
0073      * not running at all, @c false otherwise.
0074      * @since 4.2
0075      */
0076     static bool stop();
0077 
0078     /**
0079      * Restarts the Akonadi server synchronously.
0080      * @return @c true if the restart was successful, @c false otherwise,
0081      * the server state is undefined in this case.
0082      * @since 4.2
0083      */
0084     static bool restart();
0085 
0086 protected:
0087     /**
0088      * Creates the control object.
0089      */
0090     Control();
0091 
0092 private:
0093     /// @cond PRIVATE
0094     std::unique_ptr<ControlPrivate> const d;
0095     /// @endcond
0096 };
0097 
0098 }