File indexing completed on 2024-06-16 04:50:12
0001 /* 0002 SPDX-FileCopyrightText: 2006 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 <QMetaType> 0012 #include <QSharedDataPointer> 0013 0014 namespace Akonadi 0015 { 0016 class CollectionStatisticsPrivate; 0017 0018 /** 0019 * @short Provides statistics information of a Collection. 0020 * 0021 * This class contains information such as total number of items, 0022 * number of new and unread items, etc. 0023 * 0024 * This information might be expensive to obtain and is thus 0025 * not included when fetching collections with a CollectionFetchJob. 0026 * It can be retrieved separately using CollectionStatisticsJob. 0027 * 0028 * Example: 0029 * 0030 * @code 0031 * 0032 * Akonadi::Collection collection = ... 0033 * 0034 * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection ); 0035 * connect( job, SIGNAL(result(KJob*)), SLOT(jobFinished(KJob*)) ); 0036 * 0037 * ... 0038 * 0039 * MyClass::jobFinished( KJob *job ) 0040 * { 0041 * if ( job->error() ) { 0042 * qDebug() << "Error occurred"; 0043 * return; 0044 * } 0045 * 0046 * CollectionStatisticsJob *statisticsJob = qobject_cast<CollectionStatisticsJob*>( job ); 0047 * 0048 * const Akonadi::CollectionStatistics statistics = statisticsJob->statistics(); 0049 * qDebug() << "Unread items:" << statistics.unreadCount(); 0050 * } 0051 * 0052 * @endcode 0053 * 0054 * This class is implicitly shared. 0055 * 0056 * @author Volker Krause <vkrause@kde.org> 0057 */ 0058 class AKONADICORE_EXPORT CollectionStatistics 0059 { 0060 public: 0061 /** 0062 * Creates a new collection statistics object. 0063 */ 0064 CollectionStatistics(); 0065 0066 /** 0067 * Creates a collection statistics object from an @p other one. 0068 */ 0069 CollectionStatistics(const CollectionStatistics &other); 0070 0071 /** 0072 * Destroys the collection statistics object. 0073 */ 0074 ~CollectionStatistics(); 0075 0076 /** 0077 * Returns the number of items in this collection or @c -1 if 0078 * this information is not available. 0079 * 0080 * @see setCount() 0081 * @see unreadCount() 0082 */ 0083 [[nodiscard]] qint64 count() const; 0084 0085 /** 0086 * Sets the number of items in this collection. 0087 * 0088 * @param count The number of items. 0089 * @see count() 0090 */ 0091 void setCount(qint64 count); 0092 0093 /** 0094 * Returns the number of unread items in this collection or @c -1 if 0095 * this information is not available. 0096 * 0097 * @see setUnreadCount() 0098 * @see count() 0099 */ 0100 [[nodiscard]] qint64 unreadCount() const; 0101 0102 /** 0103 * Sets the number of unread items in this collection. 0104 * 0105 * @param count The number of unread messages. 0106 * @see unreadCount() 0107 */ 0108 void setUnreadCount(qint64 count); 0109 0110 /** 0111 * Returns the total size of the items in this collection or @c -1 if 0112 * this information is not available. 0113 * 0114 * @see setSize() 0115 * @since 4.3 0116 */ 0117 [[nodiscard]] qint64 size() const; 0118 0119 /** 0120 * Sets the total size of the items in this collection. 0121 * 0122 * @param size The total size of the items 0123 * @see size() 0124 * @since 4.3 0125 */ 0126 void setSize(qint64 size); 0127 0128 /** 0129 * Assigns @p other to this statistics object and returns a reference to this one. 0130 */ 0131 CollectionStatistics &operator=(const CollectionStatistics &other); 0132 0133 private: 0134 /// @cond PRIVATE 0135 QSharedDataPointer<CollectionStatisticsPrivate> d; 0136 /// @endcond 0137 }; 0138 0139 } 0140 0141 /** 0142 * Allows to output the collection statistics for debugging purposes. 0143 */ 0144 AKONADICORE_EXPORT QDebug operator<<(QDebug d, const Akonadi::CollectionStatistics &); 0145 0146 Q_DECLARE_METATYPE(Akonadi::CollectionStatistics)