20 #include "collectionstatisticsmodel.h"
22 #include "collection.h"
23 #include "collectionmodel_p.h"
24 #include "collectionstatistics.h"
32 using namespace Akonadi;
39 enum CountType { Total, Unread, Size };
45 qint64 countRecursive(
Collection::Id collection, CountType type )
const;
50 qint64 CollectionStatisticsModelPrivate::countRecursive(
Collection::Id collection,
51 CountType type )
const
55 case Unread: result = collections.value( collection ).statistics().unreadCount();
57 case Total: result = collections.value( collection ).statistics().count();
59 case Size: result = collections.value( collection ).statistics().size();
61 default: Q_ASSERT(
false );
65 const QVector<Collection::Id> children = childCollections.value( collection );
67 result += countRecursive( currentCollection, type );
78 int CollectionStatisticsModel::columnCount(
const QModelIndex & parent )
const
80 if ( parent.isValid() && parent.column() != 0 ) {
86 QVariant CollectionStatisticsModel::data(
const QModelIndex & index,
int role )
const
89 if ( !index.isValid() ) {
99 qint64 total = statistics.
count();
101 qint64 size = statistics.
size();
102 qint64 totalRecursive = d->countRecursive( col.
id(),
103 CollectionStatisticsModelPrivate::Total );
104 qint64 unreadRecursive = d->countRecursive( col.
id(),
105 CollectionStatisticsModelPrivate::Unread );
106 qint64 sizeRecursive = d->countRecursive( col.
id(),
107 CollectionStatisticsModelPrivate::Size );
116 return unreadRecursive;
118 return totalRecursive;
120 return sizeRecursive;
123 var.setValue( statistics );
127 var.setValue( statistics );
131 if ( role == Qt::DisplayRole &&
132 ( index.column() == 1 || index.column() == 2 || index.column() == 3 ) ) {
135 switch ( index.column() ) {
136 case 1 : value = unread;
break;
137 case 2 : value = total;
break;
138 case 3 : value = size;
break;
142 }
else if ( value == 0 ) {
143 return QLatin1String(
"-" );
144 }
else if ( index.column() == 3 ) {
145 return KGlobal::locale()->formatByteSize( value );
147 return QString::number( value );
151 if ( role == Qt::TextAlignmentRole && ( index.column() == 1 || index.column() == 2 || index.column() == 3 ) ) {
152 return Qt::AlignRight;
155 return CollectionModel::data( index, role );
158 QVariant CollectionStatisticsModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
160 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
162 case 1:
return i18nc(
"@title:column, number of unread messages",
"Unread" );
163 case 2:
return i18nc(
"@title:column, total number of messages",
"Total" );
164 case 3:
return i18nc(
"@title:column, total size (in bytes) of the collection",
"Size" );
168 return CollectionModel::headerData( section, orientation, role );