• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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" ));
00039   }
00040 
00041   inline bool isVirtual( const Collection &collection )
00042   {
00043     return (collection.resource() == QLatin1String( "akonadi_search_resource" ));
00044   }
00045 
00046   inline bool isReadOnly( const Collection &collection )
00047   {
00048     return !(collection.rights() & Collection::CanCreateItem);
00049   }
00050 
00051   inline bool isResource( const Collection &collection )
00052   {
00053     return (collection.parentCollection() == Collection::root());
00054   }
00055 
00056   inline bool isStructural( const Collection &collection )
00057   {
00058     return collection.contentMimeTypes().isEmpty();
00059   }
00060 
00061   inline bool isFolder( const Collection &collection )
00062   {
00063     return (collection.parentCollection() != Collection::root() &&
00064             collection.resource() != QLatin1String( "akonadi_search_resource" ) &&
00065             !collection.contentMimeTypes().isEmpty());
00066   }
00067   inline QString defaultIconName( const Collection &col )
00068   {
00069     if ( CollectionUtils::isVirtualParent( col ) )
00070       return QLatin1String( "edit-find" );
00071     if ( CollectionUtils::isVirtual( col ) )
00072       return QLatin1String( "document-preview" );
00073     if ( CollectionUtils::isResource( col ) )
00074       return QLatin1String( "network-server" );
00075     if ( CollectionUtils::isStructural( col ) )
00076       return QLatin1String( "folder-grey" );
00077     if ( CollectionUtils::isReadOnly( col ) )
00078       return QLatin1String( "folder-grey" );
00079 
00080     const QStringList content = col.contentMimeTypes();
00081     if ( content.size() == 1 || (content.size() == 2 && content.contains( Collection::mimeType() )) ) {
00082       if ( content.contains( QLatin1String( "text/x-vcard" ) ) || content.contains( QLatin1String( "text/directory" ) )
00083                                                                || content.contains( QLatin1String( "text/vcard" ) ) )
00084         return QLatin1String( "x-office-address-book" );
00085       // TODO: add all other content types and/or fix their mimetypes
00086       if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) )
00087         return QLatin1String( "view-pim-calendar" );
00088       if ( content.contains( QLatin1String( "akonadi/task" ) ) )
00089         return QLatin1String( "view-pim-tasks" );
00090     } else if ( content.isEmpty() ) {
00091       return QLatin1String( "folder-grey" );
00092     }
00093     return QLatin1String( "folder" );
00094   }
00095   inline QString displayIconName( const Collection &col )
00096   {
00097     QString iconName = defaultIconName( col );
00098     if ( col.hasAttribute<EntityDisplayAttribute>() &&
00099          !col.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
00100       if ( !col.attribute<EntityDisplayAttribute>()->activeIconName().isEmpty() && col.statistics().unreadCount()> 0) {
00101         iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
00102       }
00103       else
00104         iconName = col.attribute<EntityDisplayAttribute>()->iconName();
00105       }
00106     return iconName;
00107 
00108   }
00109   inline bool hasValidHierarchicalRID( const Collection &col )
00110   {
00111     if ( col == Collection::root() )
00112       return true;
00113     if ( col.remoteId().isEmpty() )
00114       return false;
00115     return hasValidHierarchicalRID( col.parentCollection() );
00116   }
00117   inline bool hasValidHierarchicalRID( const Item &item )
00118   {
00119     return !item.remoteId().isEmpty() && hasValidHierarchicalRID( item.parentCollection() );
00120   }
00121 }
00122 
00123 }
00124 
00125 #endif

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal