File indexing completed on 2024-11-10 04:40:29
0001 /* 0002 SPDX-FileCopyrightText: 2006-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 #include "job.h" 0011 0012 namespace Akonadi 0013 { 0014 class Collection; 0015 class CollectionStatistics; 0016 class CollectionStatisticsJobPrivate; 0017 0018 /** 0019 * @short Job that fetches collection statistics from the Akonadi storage. 0020 * 0021 * This class fetches the CollectionStatistics object for a given collection. 0022 * 0023 * Example: 0024 * 0025 * @code 0026 * 0027 * Akonadi::Collection collection = ... 0028 * 0029 * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection ); 0030 * connect( job, SIGNAL(result(KJob*)), SLOT(jobFinished(KJob*)) ); 0031 * 0032 * ... 0033 * 0034 * MyClass::jobFinished( KJob *job ) 0035 * { 0036 * if ( job->error() ) { 0037 * qDebug() << "Error occurred"; 0038 * return; 0039 * } 0040 * 0041 * CollectionStatisticsJob *statisticsJob = qobject_cast<CollectionStatisticsJob*>( job ); 0042 * 0043 * const Akonadi::CollectionStatistics statistics = statisticsJob->statistics(); 0044 * qDebug() << "Unread items:" << statistics.unreadCount(); 0045 * } 0046 * 0047 * @endcode 0048 * 0049 * @author Volker Krause <vkrause@kde.org> 0050 */ 0051 class AKONADICORE_EXPORT CollectionStatisticsJob : public Job 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 /** 0057 * Creates a new collection statistics job. 0058 * 0059 * @param collection The collection to fetch the statistics from. 0060 * @param parent The parent object. 0061 */ 0062 explicit CollectionStatisticsJob(const Collection &collection, QObject *parent = nullptr); 0063 0064 /** 0065 * Destroys the collection statistics job. 0066 */ 0067 ~CollectionStatisticsJob() override; 0068 0069 /** 0070 * Returns the fetched collection statistics. 0071 */ 0072 [[nodiscard]] CollectionStatistics statistics() const; 0073 0074 /** 0075 * Returns the corresponding collection, if the job was executed successfully, 0076 * the collection is already updated. 0077 */ 0078 [[nodiscard]] Collection collection() const; 0079 0080 protected: 0081 void doStart() override; 0082 bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override; 0083 0084 private: 0085 Q_DECLARE_PRIVATE(CollectionStatisticsJob) 0086 }; 0087 0088 }