File indexing completed on 2024-05-26 05:14:17

0001 /*
0002   SPDX-FileCopyrightText: 2015 Sandro Knauß <knauss@kolabsys.com>
0003   SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QObject>
0012 
0013 #include <Akonadi/Tag>
0014 
0015 #include <memory>
0016 
0017 class QColor;
0018 
0019 namespace Akonadi
0020 {
0021 
0022 class TagCachePrivate;
0023 
0024 /**
0025  * Client-side cache of all exist tags.
0026  *
0027  * This can be instantiated explicitly or used as a singleton for
0028  * process-wide sharing.
0029  *
0030  * @since 5.20.43
0031  */
0032 class AKONADICORE_EXPORT TagCache : public QObject
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit TagCache(QObject *parent = nullptr);
0037     ~TagCache();
0038 
0039     /** Returns the tag with the GID @p gid, if available. */
0040     [[nodiscard]] Akonadi::Tag tagByGid(const QByteArray &gid) const;
0041     /** Returns the tag with the name @p name, if available. */
0042     [[nodiscard]] Akonadi::Tag tagByName(const QString &name) const;
0043 
0044     /** Returns the (background) color of the tag named @p tagName.
0045      *  If there is no such tag, or the tag has no color associated,
0046      *  an invalid QColor value is returned.
0047      */
0048     [[nodiscard]] QColor tagColor(const QString &tagName) const;
0049 
0050     /** Sets the (background) color of the tag named @p tagName to @p color. */
0051     void setTagColor(const QString &tagName, const QColor &color);
0052 
0053     /** Returns the singleton instance. */
0054     static TagCache *instance();
0055 
0056 private:
0057     std::unique_ptr<TagCachePrivate> d;
0058 };
0059 }