1/*
2 Copyright (c) 2006 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef AKONADI_COLLECTIONSTATISTICS_H
21#define AKONADI_COLLECTIONSTATISTICS_H
22
23#include "akonadi_export.h"
24#include <QtCore/QMetaType>
25#include <QtCore/QSharedDataPointer>
26
27namespace Akonadi {
28
29/**
30 * @short Provides statistics information of a Collection.
31 *
32 * This class contains information such as total number of items,
33 * number of new and unread items, etc.
34 *
35 * This information might be expensive to obtain and is thus
36 * not included when fetching collections with a CollectionFetchJob.
37 * It can be retrieved separately using CollectionStatisticsJob.
38 *
39 * Example:
40 *
41 * @code
42 *
43 * Akonadi::Collection collection = ...
44 *
45 * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection );
46 * connect( job, SIGNAL(result(KJob*)), SLOT(jobFinished(KJob*)) );
47 *
48 * ...
49 *
50 * MyClass::jobFinished( KJob *job )
51 * {
52 * if ( job->error() ) {
53 * qDebug() << "Error occurred";
54 * return;
55 * }
56 *
57 * CollectionStatisticsJob *statisticsJob = qobject_cast<CollectionStatisticsJob*>( job );
58 *
59 * const Akonadi::CollectionStatistics statistics = statisticsJob->statistics();
60 * qDebug() << "Unread items:" << statistics.unreadCount();
61 * }
62 *
63 * @endcode
64 *
65 * This class is implicitly shared.
66 *
67 * @author Volker Krause <vkrause@kde.org>
68 */
69class AKONADI_EXPORT CollectionStatistics
70{
71public:
72 /**
73 * Creates a new collection statistics object.
74 */
75 CollectionStatistics();
76
77 /**
78 * Creates a collection statistics object from an @p other one.
79 */
80 CollectionStatistics(const CollectionStatistics &other);
81
82 /**
83 * Destroys the collection statistics object.
84 */
85 ~CollectionStatistics();
86
87 /**
88 * Returns the number of items in this collection or @c -1 if
89 * this information is not available.
90 *
91 * @see setCount()
92 * @see unreadCount()
93 */
94 qint64 count() const;
95
96 /**
97 * Sets the number of items in this collection.
98 *
99 * @param count The number of items.
100 * @see count()
101 */
102 void setCount(qint64 count);
103
104 /**
105 * Returns the number of unread items in this collection or @c -1 if
106 * this information is not available.
107 *
108 * @see setUnreadCount()
109 * @see count()
110 */
111 qint64 unreadCount() const;
112
113 /**
114 * Sets the number of unread items in this collection.
115 *
116 * @param count The number of unread messages.
117 * @see unreadCount()
118 */
119 void setUnreadCount(qint64 count);
120
121 /**
122 * Returns the total size of the items in this collection or @c -1 if
123 * this information is not available.
124 *
125 * @see setSize()
126 * @since 4.3
127 */
128 qint64 size() const;
129
130 /**
131 * Sets the total size of the items in this collection.
132 *
133 * @param size The total size of the items
134 * @see size()
135 * @since 4.3
136 */
137 void setSize(qint64 size);
138
139 /**
140 * Assigns @p other to this statistics object and returns a reference to this one.
141 */
142 CollectionStatistics &operator=(const CollectionStatistics &other);
143
144private:
145 //@cond PRIVATE
146 class Private;
147 QSharedDataPointer<Private> d;
148 //@endcond
149};
150
151}
152
153/**
154 * Allows to output the collection statistics for debugging purposes.
155 */
156AKONADI_EXPORT QDebug operator<<(QDebug d, const Akonadi::CollectionStatistics &);
157
158Q_DECLARE_METATYPE(Akonadi::CollectionStatistics)
159
160#endif
161