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

akonadi

collectionutils_p.h
00001 /*
00002     Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #ifndef AKONADI_COLLECTIONUTILS_P_H
00021 #define AKONADI_COLLECTIONUTILS_P_H
00022 
00023 #include <QtCore/QStringList>
00024 #include <akonadi/entitydisplayattribute.h>
00025 #include <akonadi/collectionstatistics.h>
00026 #include <akonadi/item.h>
00027 
00028 namespace Akonadi {
00029 
00033 namespace CollectionUtils
00034 {
00035   inline bool isVirtualParent( const Collection &collection )
00036   {
00037     return (collection.parentCollection() == Collection::root() &&
00038             ( collection.resource() == QLatin1String( "akonadi_search_resource" ) || collection.resource() == QLatin1String( "akonadi_nepomuktag_resource" ) ) );
00039   }
00040 
00041   inline bool isVirtual( const Collection &collection )
00042   {
00043     return ( (collection.resource() == QLatin1String( "akonadi_search_resource" ) || collection.resource() == QLatin1String( "akonadi_nepomuktag_resource" ) ) );
00044   }
00045 
00046   inline bool isReadOnly( const Collection &collection )
00047   {
00048     return !(collection.rights() & Collection::CanCreateItem);
00049   }
00050 
00051   inline bool isRoot( const Collection &collection )
00052   {
00053     return (collection == Collection::root());
00054   }
00055 
00056   inline bool isResource( const Collection &collection )
00057   {
00058     return (collection.parentCollection() == Collection::root());
00059   }
00060 
00061   inline bool isStructural( const Collection &collection )
00062   {
00063     return collection.contentMimeTypes().isEmpty();
00064   }
00065 
00066   inline bool isFolder( const Collection &collection )
00067   {
00068     return (!isRoot( collection ) &&
00069             !isResource( collection ) &&
00070             !isStructural( collection ) &&
00071             collection.resource() != QLatin1String( "akonadi_search_resource" ) &&
00072             collection.resource() != QLatin1String( "akonadi_nepomuktag_resource" ));
00073   }
00074 
00075   inline QString defaultIconName( const Collection &col )
00076   {
00077     if ( CollectionUtils::isVirtualParent( col ) )
00078       return QLatin1String( "edit-find" );
00079     if ( CollectionUtils::isVirtual( col ) )
00080       return QLatin1String( "document-preview" );
00081     if ( CollectionUtils::isResource( col ) )
00082       return QLatin1String( "network-server" );
00083     if ( CollectionUtils::isStructural( col ) )
00084       return QLatin1String( "folder-grey" );
00085     if ( CollectionUtils::isReadOnly( col ) )
00086       return QLatin1String( "folder-grey" );
00087 
00088     const QStringList content = col.contentMimeTypes();
00089     if ( content.size() == 1 || (content.size() == 2 && content.contains( Collection::mimeType() )) ) {
00090       if ( content.contains( QLatin1String( "text/x-vcard" ) ) || content.contains( QLatin1String( "text/directory" ) )
00091                                                                || content.contains( QLatin1String( "text/vcard" ) ) )
00092         return QLatin1String( "x-office-address-book" );
00093       // TODO: add all other content types and/or fix their mimetypes
00094       if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) )
00095         return QLatin1String( "view-pim-calendar" );
00096       if ( content.contains( QLatin1String( "akonadi/task" ) ) )
00097         return QLatin1String( "view-pim-tasks" );
00098     } else if ( content.isEmpty() ) {
00099       return QLatin1String( "folder-grey" );
00100     }
00101     return QLatin1String( "folder" );
00102   }
00103   inline QString displayIconName( const Collection &col )
00104   {
00105     QString iconName = defaultIconName( col );
00106     if ( col.hasAttribute<EntityDisplayAttribute>() &&
00107          !col.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
00108       if ( !col.attribute<EntityDisplayAttribute>()->activeIconName().isEmpty() && col.statistics().unreadCount()> 0) {
00109         iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
00110       }
00111       else
00112         iconName = col.attribute<EntityDisplayAttribute>()->iconName();
00113       }
00114     return iconName;
00115 
00116   }
00117   inline bool hasValidHierarchicalRID( const Collection &col )
00118   {
00119     if ( col == Collection::root() )
00120       return true;
00121     if ( col.remoteId().isEmpty() )
00122       return false;
00123     return hasValidHierarchicalRID( col.parentCollection() );
00124   }
00125   inline bool hasValidHierarchicalRID( const Item &item )
00126   {
00127     return !item.remoteId().isEmpty() && hasValidHierarchicalRID( item.parentCollection() );
00128   }
00129 }
00130 
00131 }
00132 
00133 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:15 by doxygen 1.8.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
  • Modules
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 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