• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
collectionstatisticsmodel.cpp
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#include "collectionstatisticsmodel.h"
21
22#include "collection.h"
23#include "collectionmodel_p.h"
24#include "collectionstatistics.h"
25
26#include <kdebug.h>
27#include <KGlobal>
28#include <klocale.h>
29#include <klocalizedstring.h>
30
31using namespace Akonadi;
32
33namespace Akonadi {
34
35class CollectionStatisticsModelPrivate : public CollectionModelPrivate
36{
37public:
38 enum CountType {
39 Total,
40 Unread,
41 Size
42 };
43 Q_DECLARE_PUBLIC(CollectionStatisticsModel)
44 CollectionStatisticsModelPrivate(CollectionStatisticsModel *parent)
45 : CollectionModelPrivate(parent)
46 {}
47
48 qint64 countRecursive(Collection::Id collection, CountType type) const;
49};
50
51}
52
53qint64 CollectionStatisticsModelPrivate::countRecursive(Collection::Id collection,
54 CountType type) const
55{
56 qint64 result = -1;
57 switch (type) {
58 case Unread:
59 result = collections.value(collection).statistics().unreadCount();
60 break;
61 case Total:
62 result = collections.value(collection).statistics().count();
63 break;
64 case Size:
65 result = collections.value(collection).statistics().size();
66 break;
67 default:
68 Q_ASSERT(false);
69 break;
70 }
71
72 const QVector<Collection::Id> children = childCollections.value(collection);
73 foreach (Collection::Id currentCollection, children) {
74 result += countRecursive(currentCollection, type);
75 }
76 return result;
77}
78
79CollectionStatisticsModel::CollectionStatisticsModel(QObject *parent)
80 : CollectionModel(new CollectionStatisticsModelPrivate(this), parent)
81{
82 fetchCollectionStatistics(true);
83}
84
85int CollectionStatisticsModel::columnCount(const QModelIndex &parent) const
86{
87 if (parent.isValid() && parent.column() != 0) {
88 return 0;
89 }
90 return 4;
91}
92
93QVariant CollectionStatisticsModel::data(const QModelIndex &index, int role) const
94{
95 Q_D(const CollectionStatisticsModel);
96 if (!index.isValid()) {
97 return QVariant();
98 }
99
100 Collection col = collectionForId(CollectionModel::data(index, CollectionIdRole).toLongLong());
101 if (!col.isValid()) {
102 return QVariant();
103 }
104 CollectionStatistics statistics = col.statistics();
105
106 qint64 total = statistics.count();
107 qint64 unread = statistics.unreadCount();
108 qint64 size = statistics.size();
109 qint64 totalRecursive = d->countRecursive(col.id(),
110 CollectionStatisticsModelPrivate::Total);
111 qint64 unreadRecursive = d->countRecursive(col.id(),
112 CollectionStatisticsModelPrivate::Unread);
113 qint64 sizeRecursive = d->countRecursive(col.id(),
114 CollectionStatisticsModelPrivate::Size);
115
116 if (role == TotalRole) {
117 return total;
118 } else if (role == UnreadRole) {
119 return unread;
120 } else if (role == SizeRole) {
121 return size;
122 } else if (role == RecursiveUnreadRole) {
123 return unreadRecursive;
124 } else if (role == RecursiveTotalRole) {
125 return totalRecursive;
126 } else if (role == RecursiveSizeRole) {
127 return sizeRecursive;
128 } else if (role == StatisticsRole) {
129 QVariant var;
130 var.setValue(statistics);
131 return var;
132 } else if (role == RecursiveStatisticsRole) {
133 QVariant var;
134 var.setValue(statistics); //FIXME:(tmg) returns a recursive statistic object here
135 return var;
136 }
137
138 if (role == Qt::DisplayRole &&
139 (index.column() == 1 || index.column() == 2 || index.column() == 3)) {
140
141 qint64 value = -1;
142 switch (index.column()) {
143 case 1:
144 value = unread;
145 break;
146 case 2:
147 value = total;
148 break;
149 case 3:
150 value = size;
151 break;
152 }
153 if (value < 0) {
154 return QString();
155 } else if (value == 0) {
156 return QLatin1String("-");
157 } else if (index.column() == 3) {
158 return KGlobal::locale()->formatByteSize(value);
159 } else {
160 return QString::number(value);
161 }
162 }
163
164 if (role == Qt::TextAlignmentRole && (index.column() == 1 || index.column() == 2 || index.column() == 3)) {
165 return Qt::AlignRight;
166 }
167
168 return CollectionModel::data(index, role);
169}
170
171QVariant CollectionStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
172{
173 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
174 switch (section) {
175 case 1:
176 return i18nc("@title:column, number of unread messages", "Unread");
177 case 2:
178 return i18nc("@title:column, total number of messages", "Total");
179 case 3:
180 return i18nc("@title:column, total size (in bytes) of the collection", "Size");
181 }
182 }
183
184 return CollectionModel::headerData(section, orientation, role);
185}
Akonadi::CollectionModelPrivate
Definition collectionmodel_p.h:45
Akonadi::CollectionModel
A model for collections.
Definition collectionmodel.h:55
Akonadi::CollectionModel::CollectionIdRole
@ CollectionIdRole
The collection identifier.
Definition collectionmodel.h:65
Akonadi::CollectionModel::fetchCollectionStatistics
void fetchCollectionStatistics(bool enable)
Sets whether collection statistics information shall be provided by the model.
Definition collectionmodel.cpp:313
Akonadi::CollectionModel::collectionForId
Collection collectionForId(Collection::Id id) const
Returns the collection for a given collection id.
Definition collectionmodel.cpp:307
Akonadi::CollectionStatisticsModel
A model that provides statistics for collections.
Definition collectionstatisticsmodel.h:53
Akonadi::CollectionStatisticsModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition collectionstatisticsmodel.cpp:85
Akonadi::CollectionStatisticsModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition collectionstatisticsmodel.cpp:171
Akonadi::CollectionStatisticsModel::CollectionStatisticsModel
CollectionStatisticsModel(QObject *parent=0)
Creates a new collection statistics model.
Definition collectionstatisticsmodel.cpp:79
Akonadi::CollectionStatisticsModel::UnreadRole
@ UnreadRole
The number of unread items in this collection.
Definition collectionstatisticsmodel.h:62
Akonadi::CollectionStatisticsModel::RecursiveTotalRole
@ RecursiveTotalRole
The number of items in this collection and its children.
Definition collectionstatisticsmodel.h:66
Akonadi::CollectionStatisticsModel::TotalRole
@ TotalRole
The number of items in this collection.
Definition collectionstatisticsmodel.h:63
Akonadi::CollectionStatisticsModel::RecursiveUnreadRole
@ RecursiveUnreadRole
The number of unread items in this collection and its children.
Definition collectionstatisticsmodel.h:65
Akonadi::CollectionStatisticsModel::StatisticsRole
@ StatisticsRole
A statistics object of this collection.
Definition collectionstatisticsmodel.h:64
Akonadi::CollectionStatisticsModel::RecursiveStatisticsRole
@ RecursiveStatisticsRole
A statistics object of this collection and its children.
Definition collectionstatisticsmodel.h:67
Akonadi::CollectionStatisticsModel::RecursiveSizeRole
@ RecursiveSizeRole
The total size of the items in this collection and its children.
Definition collectionstatisticsmodel.h:69
Akonadi::CollectionStatisticsModel::SizeRole
@ SizeRole
The total size of the items in this collection.
Definition collectionstatisticsmodel.h:68
Akonadi::CollectionStatisticsModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition collectionstatisticsmodel.cpp:93
Akonadi::CollectionStatistics
Provides statistics information of a Collection.
Definition collectionstatistics.h:70
Akonadi::CollectionStatistics::unreadCount
qint64 unreadCount() const
Returns the number of unread items in this collection or -1 if this information is not available.
Definition collectionstatistics.cpp:77
Akonadi::CollectionStatistics::count
qint64 count() const
Returns the number of items in this collection or -1 if this information is not available.
Definition collectionstatistics.cpp:67
Akonadi::CollectionStatistics::size
qint64 size() const
Returns the total size of the items in this collection or -1 if this information is not available.
Definition collectionstatistics.cpp:87
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::Collection::statistics
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition collection.cpp:238
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition entity.cpp:97
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition entity.cpp:72
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition entity.h:65
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal