File indexing completed on 2025-01-05 04:47:08
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 "akonadiwidgets_export.h" 0010 0011 #include <QObject> 0012 0013 #include <memory> 0014 0015 namespace Akonadi 0016 { 0017 class ControlGuiPrivate; 0018 0019 /** 0020 * @short Provides methods to ControlGui the Akonadi server process. 0021 * 0022 * This class provides synchronous methods (ie. use a sub-eventloop) 0023 * to ControlGui 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::ControlGui::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 AKONADIWIDGETS_EXPORT ControlGui : public QObject 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 /** 0059 * Destroys the ControlGui object. 0060 */ 0061 ~ControlGui() 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 * Same as start(), but with GUI feedback. 0072 * @param parent The parent widget. 0073 * @since 4.2 0074 */ 0075 static bool start(QWidget *parent); 0076 0077 /** 0078 * Stops the Akonadi server synchronously if it is currently running. 0079 * @return @c true if the server was shutdown successfully or was 0080 * not running at all, @c false otherwise. 0081 * @since 4.2 0082 */ 0083 static bool stop(); 0084 0085 /** 0086 * Same as stop(), but with GUI feedback. 0087 * @param parent The parent widget. 0088 * @since 4.2 0089 */ 0090 static bool stop(QWidget *parent); 0091 0092 /** 0093 * Restarts the Akonadi server synchronously. 0094 * @return @c true if the restart was successful, @c false otherwise, 0095 * the server state is undefined in this case. 0096 * @since 4.2 0097 */ 0098 static bool restart(); 0099 0100 /** 0101 * Same as restart(), but with GUI feedback. 0102 * @param parent The parent widget. 0103 * @since 4.2 0104 */ 0105 static bool restart(QWidget *parent); 0106 0107 /** 0108 * Disable the given widget when Akonadi is not operational and show 0109 * an error overlay (given enough space). Cascading use is automatically 0110 * detected and resolved. 0111 * @param widget The widget depending on Akonadi being operational. 0112 * @since 4.2 0113 */ 0114 static void widgetNeedsAkonadi(QWidget *widget); 0115 0116 protected: 0117 /** 0118 * Creates the ControlGui object. 0119 */ 0120 ControlGui(); 0121 0122 private: 0123 /// @cond PRIVATE 0124 std::unique_ptr<ControlGuiPrivate> const d; 0125 /// @endcond 0126 }; 0127 0128 }