00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 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.resource() != QLatin1String( "akonadi_nepomuktag_resource" ) &&
00066 !collection.contentMimeTypes().isEmpty());
00067 }
00068 inline QString defaultIconName( const Collection &col )
00069 {
00070 if ( CollectionUtils::isVirtualParent( col ) )
00071 return QLatin1String( "edit-find" );
00072 if ( CollectionUtils::isVirtual( col ) )
00073 return QLatin1String( "document-preview" );
00074 if ( CollectionUtils::isResource( col ) )
00075 return QLatin1String( "network-server" );
00076 if ( CollectionUtils::isStructural( col ) )
00077 return QLatin1String( "folder-grey" );
00078 if ( CollectionUtils::isReadOnly( col ) )
00079 return QLatin1String( "folder-grey" );
00080
00081 const QStringList content = col.contentMimeTypes();
00082 if ( content.size() == 1 || (content.size() == 2 && content.contains( Collection::mimeType() )) ) {
00083 if ( content.contains( QLatin1String( "text/x-vcard" ) ) || content.contains( QLatin1String( "text/directory" ) )
00084 || content.contains( QLatin1String( "text/vcard" ) ) )
00085 return QLatin1String( "x-office-address-book" );
00086
00087 if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) )
00088 return QLatin1String( "view-pim-calendar" );
00089 if ( content.contains( QLatin1String( "akonadi/task" ) ) )
00090 return QLatin1String( "view-pim-tasks" );
00091 } else if ( content.isEmpty() ) {
00092 return QLatin1String( "folder-grey" );
00093 }
00094 return QLatin1String( "folder" );
00095 }
00096 inline QString displayIconName( const Collection &col )
00097 {
00098 QString iconName = defaultIconName( col );
00099 if ( col.hasAttribute<EntityDisplayAttribute>() &&
00100 !col.attribute<EntityDisplayAttribute>()->iconName().isEmpty() ) {
00101 if ( !col.attribute<EntityDisplayAttribute>()->activeIconName().isEmpty() && col.statistics().unreadCount()> 0) {
00102 iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
00103 }
00104 else
00105 iconName = col.attribute<EntityDisplayAttribute>()->iconName();
00106 }
00107 return iconName;
00108
00109 }
00110 inline bool hasValidHierarchicalRID( const Collection &col )
00111 {
00112 if ( col == Collection::root() )
00113 return true;
00114 if ( col.remoteId().isEmpty() )
00115 return false;
00116 return hasValidHierarchicalRID( col.parentCollection() );
00117 }
00118 inline bool hasValidHierarchicalRID( const Item &item )
00119 {
00120 return !item.remoteId().isEmpty() && hasValidHierarchicalRID( item.parentCollection() );
00121 }
00122 }
00123
00124 }
00125
00126 #endif