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 #ifndef AKONADI_COLLECTIONUTILS_P_H
8 #define AKONADI_COLLECTIONUTILS_P_H
9 
10 #include <QStringList>
11 
12 #include "entitydisplayattribute.h"
13 #include "collectionstatistics.h"
14 #include "item.h"
15 
16 namespace Akonadi
17 {
18 
22 namespace CollectionUtils
23 {
24 Q_REQUIRED_RESULT inline bool isVirtualParent(const Collection &collection)
25 {
26  return (collection.parentCollection() == Collection::root() && collection.isVirtual());
27 }
28 
29 Q_REQUIRED_RESULT inline bool isReadOnly(const Collection &collection)
30 {
31  return !(collection.rights() &Collection::CanCreateItem);
32 }
33 
34 Q_REQUIRED_RESULT inline bool isRoot(const Collection &collection)
35 {
36  return (collection == Collection::root());
37 }
38 
39 Q_REQUIRED_RESULT inline bool isResource(const Collection &collection)
40 {
41  return (collection.parentCollection() == Collection::root());
42 }
43 
44 Q_REQUIRED_RESULT inline bool isStructural(const Collection &collection)
45 {
46  return collection.contentMimeTypes().isEmpty();
47 }
48 
49 Q_REQUIRED_RESULT inline bool isFolder(const Collection &collection)
50 {
51  return (!isRoot(collection) &&
52  !isResource(collection) &&
53  !isStructural(collection) &&
54  collection.resource() != QLatin1String("akonadi_search_resource"));
55 }
56 
57 Q_REQUIRED_RESULT inline bool isUnifiedMailbox(const Collection &collection)
58 {
59  return collection.resource() == QLatin1String("akonadi_unifiedmailbox_agent");
60 }
61 
62 Q_REQUIRED_RESULT inline QString defaultIconName(const Collection &col)
63 {
64  if (CollectionUtils::isVirtualParent(col)) {
65  return QStringLiteral("edit-find");
66  }
67  if (col.isVirtual()) {
68  return QStringLiteral("document-preview");
69  }
70  if (CollectionUtils::isResource(col)) {
71  return QStringLiteral("network-server");
72  }
73  if (CollectionUtils::isStructural(col)) {
74  return QStringLiteral("folder-grey");
75  }
76  if (CollectionUtils::isReadOnly(col)) {
77  return QStringLiteral("folder-grey");
78  }
79 
80  const QStringList content = col.contentMimeTypes();
81  if ((content.size() == 1) ||
82  (content.size() == 2 && content.contains(Collection::mimeType()))) {
83  if (content.contains(QLatin1String("text/x-vcard")) ||
84  content.contains(QLatin1String("text/directory")) ||
85  content.contains(QLatin1String("text/vcard"))) {
86  return QStringLiteral("x-office-address-book");
87  }
88  // TODO: add all other content types and/or fix their mimetypes
89  if (content.contains(QLatin1String("akonadi/event")) || content.contains(QLatin1String("text/ical"))) {
90  return QStringLiteral("view-pim-calendar");
91  }
92  if (content.contains(QLatin1String("akonadi/task"))) {
93  return QStringLiteral("view-pim-tasks");
94  }
95  } else if (content.isEmpty()) {
96  return QStringLiteral("folder-grey");
97  }
98  return QStringLiteral("folder");
99 }
100 Q_REQUIRED_RESULT inline QString displayIconName(const Collection &col)
101 {
102  QString iconName = defaultIconName(col);
106  iconName = col.attribute<EntityDisplayAttribute>()->activeIconName();
107  } else {
108  iconName = col.attribute<EntityDisplayAttribute>()->iconName();
109  }
110  }
111  return iconName;
112 
113 }
114 Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Collection &col)
115 {
116  if (col == Collection::root()) {
117  return true;
118  }
119  if (col.remoteId().isEmpty()) {
120  return false;
121  }
122  return hasValidHierarchicalRID(col.parentCollection());
123 }
124 Q_REQUIRED_RESULT inline bool hasValidHierarchicalRID(const Item &item)
125 {
126  return !item.remoteId().isEmpty() && hasValidHierarchicalRID(item.parentCollection());
127 }
128 }
129 
130 }
131 
132 #endif
QString activeIconName() const
Returns the icon name of an active item.
QString iconName() const
Returns the icon name of the icon returned by icon().
Represents a collection of PIM items.
Definition: collection.h:63
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
static QString mimeType()
Returns the mimetype used for collections.
Definition: collection.cpp:295
int size() const const
bool isEmpty() const const
bool isEmpty() const const
Can create new items in this collection.
Definition: collection.h:82
static Collection root()
Returns the root collection.
Definition: collection.cpp:290
Collection parentCollection() const
Returns the parent collection of this object.
Definition: collection.cpp:198
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Definition: collection.cpp:179
Rights rights() const
Returns the rights the user has on the collection.
Definition: collection.cpp:229
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:164
Helper integration between Akonadi and Qt.
QString remoteId() const
Returns the remote id of the collection.
Definition: collection.cpp:109
qint64 unreadCount() const
Returns the number of unread items in this collection or -1 if this information is not available...
QStringList contentMimeTypes() const
Returns a list of possible content mimetypes, e.g.
Definition: collection.cpp:243
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:305
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:330
Attribute that stores the properties that are used to display an entity.
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:351
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.