File indexing completed on 2024-05-19 05:11:16
0001 /* 0002 Requires the Qt and KDE widget libraries, available at no cost at 0003 http://www.trolltech.com and http://www.kde.org respectively 0004 0005 SPDX-FileCopyrightText: 2002-2004 Klarälvdalens Datakonsult AB, 0006 <info@klaralvdalens-datakonsult.se> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 #pragma once 0011 0012 #include "akonadi-calendar_export.h" 0013 #include "etmcalendar.h" 0014 0015 #include <KCalendarCore/FreeBusyCache> 0016 0017 #include <memory> 0018 0019 // TODO: document 0020 namespace Akonadi 0021 { 0022 class FreeBusyManagerPrivate; 0023 class FreeBusyManagerStatic; 0024 0025 class AKONADI_CALENDAR_EXPORT FreeBusyManager : public QObject, public KCalendarCore::FreeBusyCache 0026 { 0027 Q_OBJECT 0028 public: 0029 /** 0030 * Returns the FreeBusyManager 0031 */ 0032 static FreeBusyManager *self(); 0033 0034 void setCalendar(const Akonadi::ETMCalendar::Ptr &calendar); 0035 0036 /** 0037 Publishes the owners freebusy information from the current calendar 0038 starting from the current date/time to current date/time + freeBusyPublishDays. 0039 If an upload is already in progress nothing happens. 0040 0041 @see KCalPrefBase::freeBusyPublishUrl() 0042 @see KCalPrefBase::freeBusyPublishDays(); 0043 */ 0044 Q_INVOKABLE void publishFreeBusy(QWidget *parentWidget = nullptr); 0045 0046 /** 0047 Mail the freebusy information. 0048 */ 0049 Q_INVOKABLE void mailFreeBusy(int daysToPublish = 30, QWidget *parentWidget = nullptr); 0050 0051 /** 0052 Retrieve the freebusy information of somebody else, i.e. it will not try 0053 to download our own freebusy information. 0054 0055 This method will first try to find Akonadi resource that have the 0056 'FreeBusyProvider' capability set. If none is found then there is a fallback 0057 on the URL mechanism (see below). If at least one is found then it will 0058 be first queried over D-Bus to know if it can handle free-busy information 0059 for that email address. If true then it will be queried for the free-busy 0060 data for a period ranging from today to today plus 14 days, defined in 0061 FreeBusyManagerPrivate::FreeBusyProvidersRequestsQueue::FreeBusyProvidersRequestsQueue() 0062 as hard-coded magic value. If the Akonadi resource responds successfully 0063 (still over D-Bus) then the freeBusyRetrieved signal is emitted. If any 0064 of those steps then the URL mechanism will be used as a fallback. 0065 0066 The URL mechanism makes use of a local cache, if the information 0067 for a given email is already downloaded it will return the information 0068 from the cache. The free-busy information must be accessible using HTTP 0069 and the URL is build dynamically from the email address and the global 0070 groupware settings. 0071 0072 The call is asynchronous, a download is started in the background (if 0073 needed) and freeBusyRetrieved will be emitted when the download is finished. 0074 0075 @see KCalPrefs::thatIsMe( const QString &email ); 0076 @see Akonadi::FreeBusyProviderBase 0077 0078 @param email Address of the person for which the F/B list should be 0079 retrieved. 0080 @param forceDownload Set to true to trigger a download even when automatic 0081 retrieval of freebusy information is disabled in the configuration. 0082 @return true if a download is initiated, and false otherwise 0083 */ 0084 Q_INVOKABLE bool retrieveFreeBusy(const QString &email, bool forceDownload, QWidget *parentWidget = nullptr); 0085 0086 /** 0087 Clears the retrieval queue, i.e. all retrieval request that are not started 0088 yet will not start at all. The freebusy retrieval that currently is 0089 downloading (if one) will not be canceled. 0090 0091 @see retrieveFreeBusy 0092 */ 0093 void cancelRetrieval(); 0094 0095 /** 0096 Load freebusy information belonging to an email. The information is loaded 0097 from a local file. If the file does not exists or doesn't contain valid 0098 information 0 is returned. In that case the information should be retrieved 0099 again by calling retrieveFreeBusy. 0100 0101 Implements KCalendarCore::FreeBusyCache::loadFreeBusy 0102 0103 @param email is a QString containing a email string in the 0104 "FirstName LastName <emailaddress>" format. 0105 */ 0106 [[nodiscard]] KCalendarCore::FreeBusy::Ptr loadFreeBusy(const QString &email) override; 0107 0108 /** 0109 Save freebusy information belonging to an email. 0110 0111 Implements KCalendarCore::FreeBusyCache::saveFreeBusy 0112 0113 @param freebusy is a pointer to a valid FreeBusy instance. 0114 @param person is a valid Person instance. 0115 */ 0116 bool saveFreeBusy(const KCalendarCore::FreeBusy::Ptr &freebusy, const KCalendarCore::Person &person) override; 0117 0118 Q_SIGNALS: 0119 /** 0120 This signal is emitted to return results of free/busy requests. 0121 */ 0122 void freeBusyRetrieved(const KCalendarCore::FreeBusy::Ptr &fb, const QString &email); 0123 0124 protected: 0125 /** React on timer events, used for delayed freebusy list uploading */ 0126 void timerEvent(QTimerEvent *event) override; 0127 0128 private: 0129 /** 0130 Creates a new FreeBusyManager, private because FreeBusyManager is a 0131 Singleton 0132 */ 0133 AKONADI_CALENDAR_NO_EXPORT FreeBusyManager(); 0134 ~FreeBusyManager() override; 0135 0136 private: 0137 friend class FreeBusyManagerStatic; 0138 0139 std::unique_ptr<FreeBusyManagerPrivate> const d_ptr; 0140 Q_DECLARE_PRIVATE(FreeBusyManager) 0141 Q_DISABLE_COPY(FreeBusyManager) 0142 Q_PRIVATE_SLOT(d_ptr, void checkFreeBusyUrl()) 0143 Q_PRIVATE_SLOT(d_ptr, void processFreeBusyDownloadResult(KJob *)) 0144 Q_PRIVATE_SLOT(d_ptr, void processFreeBusyUploadResult(KJob *)) 0145 Q_PRIVATE_SLOT(d_ptr, void processRetrieveQueue()) 0146 Q_PRIVATE_SLOT(d_ptr, void uploadFreeBusy()) 0147 }; 0148 }