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

akonadi

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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