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

akonadi

  • 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() &&
38  ( collection.resource() == QLatin1String( "akonadi_search_resource" ) || collection.resource() == QLatin1String( "akonadi_nepomuktag_resource" ) ) );
39  }
40 
41  inline bool isVirtual( const Collection &collection )
42  {
43  return ( (collection.resource() == QLatin1String( "akonadi_search_resource" ) || collection.resource() == QLatin1String( "akonadi_nepomuktag_resource" ) ) );
44  }
45 
46  inline bool isReadOnly( const Collection &collection )
47  {
48  return !(collection.rights() & Collection::CanCreateItem);
49  }
50 
51  inline bool isRoot( const Collection &collection )
52  {
53  return (collection == Collection::root());
54  }
55 
56  inline bool isResource( const Collection &collection )
57  {
58  return (collection.parentCollection() == Collection::root());
59  }
60 
61  inline bool isStructural( const Collection &collection )
62  {
63  return collection.contentMimeTypes().isEmpty();
64  }
65 
66  inline bool isFolder( const Collection &collection )
67  {
68  return (!isRoot( collection ) &&
69  !isResource( collection ) &&
70  !isStructural( collection ) &&
71  collection.resource() != QLatin1String( "akonadi_search_resource" ) &&
72  collection.resource() != QLatin1String( "akonadi_nepomuktag_resource" ));
73  }
74 
75  inline QString defaultIconName( const Collection &col )
76  {
77  if ( CollectionUtils::isVirtualParent( col ) )
78  return QLatin1String( "edit-find" );
79  if ( CollectionUtils::isVirtual( col ) )
80  return QLatin1String( "document-preview" );
81  if ( CollectionUtils::isResource( col ) )
82  return QLatin1String( "network-server" );
83  if ( CollectionUtils::isStructural( col ) )
84  return QLatin1String( "folder-grey" );
85  if ( CollectionUtils::isReadOnly( col ) )
86  return QLatin1String( "folder-grey" );
87 
88  const QStringList content = col.contentMimeTypes();
89  if ( content.size() == 1 || (content.size() == 2 && content.contains( Collection::mimeType() )) ) {
90  if ( content.contains( QLatin1String( "text/x-vcard" ) ) || content.contains( QLatin1String( "text/directory" ) )
91  || content.contains( QLatin1String( "text/vcard" ) ) )
92  return QLatin1String( "x-office-address-book" );
93  // TODO: add all other content types and/or fix their mimetypes
94  if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) )
95  return QLatin1String( "view-pim-calendar" );
96  if ( content.contains( QLatin1String( "akonadi/task" ) ) )
97  return QLatin1String( "view-pim-tasks" );
98  } else if ( content.isEmpty() ) {
99  return QLatin1String( "folder-grey" );
100  }
101  return QLatin1String( "folder" );
102  }
103  inline QString displayIconName( const Collection &col )
104  {
105  QString iconName = defaultIconName( col );
106  if ( col.hasAttribute<EntityDisplayAttribute>() &&
107  !col.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
108  if ( !col.attribute<EntityDisplayAttribute>()->activeIconName().isEmpty() && col.statistics().unreadCount()> 0) {
109  iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
110  }
111  else
112  iconName = col.attribute<EntityDisplayAttribute>()->iconName();
113  }
114  return iconName;
115 
116  }
117  inline bool hasValidHierarchicalRID( const Collection &col )
118  {
119  if ( col == Collection::root() )
120  return true;
121  if ( col.remoteId().isEmpty() )
122  return false;
123  return hasValidHierarchicalRID( col.parentCollection() );
124  }
125  inline bool hasValidHierarchicalRID( const Item &item )
126  {
127  return !item.remoteId().isEmpty() && hasValidHierarchicalRID( item.parentCollection() );
128  }
129 }
130 
131 }
132 
133 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:06:25 by doxygen 1.8.1.1 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-4.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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