Akonadi

collectionutils.h
1 /*
2  SPDX-FileCopyrightText: 2008 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QStringList>
10 
11 #include "collectionstatistics.h"
12 #include "entitydisplayattribute.h"
13 #include "item.h"
14 
15 namespace Akonadi
16 {
17 /**
18  * @internal
19  */
20 namespace CollectionUtils
21 {
22 Q_REQUIRED_RESULT inline bool isVirtualParent(const Collection &collection)
23 {
24  return (collection.parentCollection() == Collection::root() && collection.isVirtual());
25 }
26 
27 Q_REQUIRED_RESULT inline bool isReadOnly(const Collection &collection)
28 {
29  return !(collection.rights() & Collection::CanCreateItem);
30 }
31 
32 Q_REQUIRED_RESULT inline bool isRoot(const Collection &collection)
33 {
34  return (collection == Collection::root());
35 }
36 
37 Q_REQUIRED_RESULT inline bool isResource(const Collection &collection)
38 {
39  return (collection.parentCollection() == Collection::root());
40 }
41 
42 Q_REQUIRED_RESULT inline bool isStructural(const Collection &collection)
43 {
44  return collection.contentMimeTypes().isEmpty();
45 }
46 
47 Q_REQUIRED_RESULT inline bool isFolder(const Collection &collection)
48 {
49  return (!isRoot(collection) && !isResource(collection) && !isStructural(collection) && collection.resource() != QLatin1String("akonadi_search_resource"));
50 }
51 
52 Q_REQUIRED_RESULT inline bool isUnifiedMailbox(const Collection &collection)
53 {
54  return collection.resource() == QLatin1String("akonadi_unifiedmailbox_agent");
55 }
56 
57 Q_REQUIRED_RESULT inline QString defaultIconName(const Collection &col)
58 {
59  if (CollectionUtils::isVirtualParent(col)) {
60  return QStringLiteral("edit-find");
61  }
62  if (col.isVirtual()) {
63  return QStringLiteral("document-preview");
64  }
65  if (CollectionUtils::isResource(col)) {
66  return QStringLiteral("network-server");
67  }
68  if (CollectionUtils::isStructural(col)) {
69  return QStringLiteral("folder-grey");
70  }
71  if (CollectionUtils::isReadOnly(col)) {
72  return QStringLiteral("folder-grey");
73  }
74 
75  const QStringList content = col.contentMimeTypes();
76  if ((content.size() == 1) || (content.size() == 2 && content.contains(Collection::mimeType()))) {
77  if (content.contains(QLatin1String("text/x-vcard")) || content.contains(QLatin1String("text/directory"))
78  || content.contains(QLatin1String("text/vcard"))) {
79  return QStringLiteral("x-office-address-book");
80  }
81  // TODO: add all other content types and/or fix their mimetypes
82  if (content.contains(QLatin1String("akonadi/event")) || content.contains(QLatin1String("text/ical"))) {
83  return QStringLiteral("view-pim-calendar");
84  }
85  if (content.contains(QLatin1String("akonadi/task"))) {
86  return QStringLiteral("view-pim-tasks");
87  }
88  } else if (content.isEmpty()) {
89  return QStringLiteral("folder-grey");
90  }
91  return QStringLiteral("folder");
92 }
93 Q_REQUIRED_RESULT inline QString displayIconName(const Collection &col)
94 {
95  QString iconName = defaultIconName(col);
98  iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
99  } else {
100  iconName = col.attribute<EntityDisplayAttribute>()->iconName();
101  }
102  }
103  return iconName;
104 }
105 Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Collection &col)
106 {
107  if (col == Collection::root()) {
108  return true;
109  }
110  if (col.remoteId().isEmpty()) {
111  return false;
112  }
113  return hasValidHierarchicalRID(col.parentCollection());
114 }
115 Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Item &item)
116 {
117  return !item.remoteId().isEmpty() && hasValidHierarchicalRID(item.parentCollection());
118 }
119 
120 /** Returns the collection represented by @p index.
121  * @param index has to be provided by an EntityTreeModel instance or a proxy model on top of one.
122  */
123 Q_REQUIRED_RESULT AKONADICORE_EXPORT Collection fromIndex(const QModelIndex &index);
124 }
125 
126 }
127 
AKONADICORE_EXPORT Collection fromIndex(const QModelIndex &index)
Returns the collection represented by index.
@ CanCreateItem
Can create new items in this collection.
Definition: collection.h:92
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
Represents a collection of PIM items.
Definition: collection.h:61
Attribute that stores the properties that are used to display an entity.
QString iconName() const
Returns the icon name of the icon returned by icon().
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Definition: collection.cpp:176
int size() const const
bool isEmpty() const const
qint64 unreadCount() const
Returns the number of unread items in this collection or -1 if this information is not available.
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:161
Collection parentCollection() const
Returns the parent collection of this object.
Definition: item.cpp:153
QString activeIconName() const
Returns the icon name of an active item.
bool isEmpty() const const
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:292
static Collection root()
Returns the root collection.
Definition: collection.cpp:287
QString remoteId() const
Returns the remote id of the collection.
Definition: collection.cpp:106
Collection parentCollection() const
Returns the parent collection of this object.
Definition: collection.cpp:187
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:326
QString remoteId() const
Returns the remote id of the item.
Definition: item.cpp:73
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.