• 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
collectionutils_p.h
1 /*
2  Copyright (c) 2008 Tobias Koenig <tokoe@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_COLLECTIONUTILS_P_H
21 #define AKONADI_COLLECTIONUTILS_P_H
22 
23 #include <QtCore/QStringList>
24 #include <akonadi/entitydisplayattribute.h>
25 #include <akonadi/collectionstatistics.h>
26 #include <akonadi/item.h>
27 
28 namespace Akonadi {
29 
33 namespace CollectionUtils
34 {
35  inline bool isVirtualParent( const Collection &collection )
36  {
37  return ( collection.parentCollection() == Collection::root() && collection.isVirtual() );
38  }
39 
40  inline bool isReadOnly( const Collection &collection )
41  {
42  return !( collection.rights() & Collection::CanCreateItem );
43  }
44 
45  inline bool isRoot( const Collection &collection )
46  {
47  return ( collection == Collection::root() );
48  }
49 
50  inline bool isResource( const Collection &collection )
51  {
52  return ( collection.parentCollection() == Collection::root() );
53  }
54 
55  inline bool isStructural( const Collection &collection )
56  {
57  return collection.contentMimeTypes().isEmpty();
58  }
59 
60  inline bool isFolder( const Collection &collection )
61  {
62  return ( !isRoot( collection ) &&
63  !isResource( collection ) &&
64  !isStructural( collection ) &&
65  collection.resource() != QLatin1String( "akonadi_search_resource" ) &&
66  collection.resource() != QLatin1String( "akonadi_nepomuktag_resource" ) );
67  }
68 
69  inline QString defaultIconName( const Collection &col )
70  {
71  if ( CollectionUtils::isVirtualParent( col ) ) {
72  return QLatin1String( "edit-find" );
73  }
74  if ( col.isVirtual() ) {
75  return QLatin1String( "document-preview" );
76  }
77  if ( CollectionUtils::isResource( col ) ) {
78  return QLatin1String( "network-server" );
79  }
80  if ( CollectionUtils::isStructural( col ) ) {
81  return QLatin1String( "folder-grey" );
82  }
83  if ( CollectionUtils::isReadOnly( col ) ) {
84  return QLatin1String( "folder-grey" );
85  }
86 
87  const QStringList content = col.contentMimeTypes();
88  if ( ( content.size() == 1 ) ||
89  ( content.size() == 2 && content.contains( Collection::mimeType() ) ) ) {
90  if ( content.contains( QLatin1String( "text/x-vcard" ) ) ||
91  content.contains( QLatin1String( "text/directory" ) ) ||
92  content.contains( QLatin1String( "text/vcard" ) ) ) {
93  return QLatin1String( "x-office-address-book" );
94  }
95  // TODO: add all other content types and/or fix their mimetypes
96  if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) ) {
97  return QLatin1String( "view-pim-calendar" );
98  }
99  if ( content.contains( QLatin1String( "akonadi/task" ) ) ) {
100  return QLatin1String( "view-pim-tasks" );
101  }
102  } else if ( content.isEmpty() ) {
103  return QLatin1String( "folder-grey" );
104  }
105  return QLatin1String( "folder" );
106  }
107  inline QString displayIconName( const Collection &col )
108  {
109  QString iconName = defaultIconName( col );
110  if ( col.hasAttribute<EntityDisplayAttribute>() &&
111  !col.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
112  if ( !col.attribute<EntityDisplayAttribute>()->activeIconName().isEmpty() && col.statistics().unreadCount()> 0 ) {
113  iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
114  } else {
115  iconName = col.attribute<EntityDisplayAttribute>()->iconName();
116  }
117  }
118  return iconName;
119 
120  }
121  inline bool hasValidHierarchicalRID( const Collection &col )
122  {
123  if ( col == Collection::root() ) {
124  return true;
125  }
126  if ( col.remoteId().isEmpty() ) {
127  return false;
128  }
129  return hasValidHierarchicalRID( col.parentCollection() );
130  }
131  inline bool hasValidHierarchicalRID( const Item &item )
132  {
133  return !item.remoteId().isEmpty() && hasValidHierarchicalRID( item.parentCollection() );
134  }
135 }
136 
137 }
138 
139 #endif
Akonadi::EntityDisplayAttribute::activeIconName
QString activeIconName() const
Returns the icon name of an active item.
Definition: entitydisplayattribute.cpp:148
Akonadi::EntityDisplayAttribute::iconName
QString iconName() const
Returns the icon name of the icon returned by icon().
Definition: entitydisplayattribute.cpp:64
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Collection::mimeType
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:197
Akonadi::Entity::attribute
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
Definition: entity.cpp:165
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:186
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:82
Akonadi::Collection::CanCreateItem
Can create new items in this collection.
Definition: collection.h:89
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::Collection::rights
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:99
Akonadi::Entity::hasAttribute
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Definition: entity.cpp:146
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::Collection::contentMimeTypes
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:115
Akonadi::Collection::resource
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:207
Akonadi::Collection::statistics
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:238
Akonadi::EntityDisplayAttribute
Attribute that stores the properties that are used to display an entity.
Definition: entitydisplayattribute.h:39
Akonadi::Collection::isVirtual
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:261
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