Akonadi

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

KDE's Doxygen guidelines are available online.