File indexing completed on 2025-01-05 04:59:50

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Kevin Ottens <ervin@kde.org>
0003  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 
0007 #include "gencollection.h"
0008 
0009 #include <Akonadi/EntityDisplayAttribute>
0010 
0011 #include <KCalendarCore/Todo>
0012 
0013 #include "akonadi/akonadiapplicationselectedattribute.h"
0014 
0015 using namespace Testlib;
0016 
0017 GenCollection::GenCollection(const Akonadi::Collection &collection)
0018     : m_collection(collection)
0019 {
0020 }
0021 
0022 GenCollection::operator Akonadi::Collection()
0023 {
0024     return m_collection;
0025 }
0026 
0027 GenCollection &GenCollection::withId(Akonadi::Collection::Id id)
0028 {
0029     m_collection.setId(id);
0030     return *this;
0031 }
0032 
0033 GenCollection &GenCollection::withParent(Akonadi::Collection::Id id)
0034 {
0035     m_collection.setParentCollection(Akonadi::Collection(id));
0036     return *this;
0037 }
0038 
0039 GenCollection &GenCollection::withRootAsParent()
0040 {
0041     m_collection.setParentCollection(Akonadi::Collection::root());
0042     return *this;
0043 }
0044 
0045 GenCollection &GenCollection::withName(const QString &name)
0046 {
0047     m_collection.setName(name);
0048     return *this;
0049 }
0050 
0051 GenCollection &GenCollection::withIcon(const QString &iconName)
0052 {
0053     auto attr = m_collection.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing);
0054     attr->setIconName(iconName);
0055     return *this;
0056 }
0057 
0058 GenCollection &GenCollection::selected(bool value)
0059 {
0060     if (!value) {
0061         auto attr = m_collection.attribute<Akonadi::ApplicationSelectedAttribute>(Akonadi::Collection::AddIfMissing);
0062         attr->setSelected(false);
0063     } else {
0064         m_collection.removeAttribute<Akonadi::ApplicationSelectedAttribute>();
0065     }
0066     return *this;
0067 }
0068 
0069 GenCollection &GenCollection::withTaskContent(bool value)
0070 {
0071     auto mimeTypes = m_collection.contentMimeTypes();
0072     if (!value) {
0073         mimeTypes.removeAll(KCalendarCore::Todo::todoMimeType());
0074     } else if (!mimeTypes.contains(KCalendarCore::Todo::todoMimeType())) {
0075         mimeTypes.append(KCalendarCore::Todo::todoMimeType());
0076     }
0077     m_collection.setContentMimeTypes(mimeTypes);
0078     return *this;
0079 }
0080 
0081 GenCollection &GenCollection::withNoteContent(bool value)
0082 {
0083     const auto noteMime = QString("text/x-vnd.akonadi.note");
0084     auto mimeTypes = m_collection.contentMimeTypes();
0085     if (!value) {
0086         mimeTypes.removeAll(noteMime);
0087     } else if (!mimeTypes.contains(noteMime)) {
0088         mimeTypes.append(noteMime);
0089     }
0090     m_collection.setContentMimeTypes(mimeTypes);
0091     return *this;
0092 }