Akonadi Mime

specialmailcollections.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "specialmailcollections.h"
8#include "akonadi_mime_debug.h"
9#include "specialmailcollectionssettings.h"
10
11#include <Akonadi/AgentInstance>
12#include <Akonadi/CollectionModifyJob>
13#include <Akonadi/EntityDisplayAttribute>
14#include <Akonadi/ServerManager>
15#include <Akonadi/SpecialCollectionAttribute>
16
17#include <KLocalizedString>
18
19using namespace Akonadi;
20
21class Akonadi::SpecialMailCollectionsPrivate
22{
23public:
24 SpecialMailCollectionsPrivate();
25 ~SpecialMailCollectionsPrivate();
26
27 SpecialMailCollections *mInstance = nullptr;
28};
29
30using Settings = SpecialMailCollectionsSettings;
31
32Q_GLOBAL_STATIC(SpecialMailCollectionsPrivate, sInstance)
33
34static const char s_specialCollectionTypes[SpecialMailCollections::LastType][11] =
35 {"local-mail", "inbox", "outbox", "sent-mail", "trash", "drafts", "templates"};
36
37static const int s_numTypes = sizeof s_specialCollectionTypes / sizeof *s_specialCollectionTypes;
38
39static inline QByteArray enumToByteArray(SpecialMailCollections::Type value)
40{
41 return s_specialCollectionTypes[value];
42}
43
44static inline SpecialMailCollections::Type typeToEnum(const QByteArray &type)
45{
46 for (int i = 0; i < s_numTypes; ++i) {
47 if (type == s_specialCollectionTypes[i]) {
48 return static_cast<SpecialMailCollections::Type>(i);
49 }
50 }
52}
53
54SpecialMailCollectionsPrivate::SpecialMailCollectionsPrivate()
55 : mInstance(new SpecialMailCollections(this))
56{
57}
58
59SpecialMailCollectionsPrivate::~SpecialMailCollectionsPrivate()
60{
61 delete mInstance;
62}
63
64static KCoreConfigSkeleton *getConfig(const QString &filename)
65{
66 Settings::instance(ServerManager::addNamespace(filename));
67 return Settings::self();
68}
69
70SpecialMailCollections::SpecialMailCollections(SpecialMailCollectionsPrivate *dd)
71 : SpecialCollections(getConfig(QStringLiteral("specialmailcollectionsrc")))
72 , d(dd)
73{
74}
75
77{
78 return sInstance->mInstance;
79}
80
82{
83 return SpecialCollections::hasCollection(enumToByteArray(type), instance);
84}
85
87{
88 return SpecialCollections::collection(enumToByteArray(type), instance);
89}
90
92{
93 return SpecialCollections::registerCollection(enumToByteArray(type), collection);
94}
95
104
106{
107 return SpecialCollections::hasDefaultCollection(enumToByteArray(type));
108}
109
114
115void SpecialMailCollections::verifyI18nDefaultCollection(Type type)
116{
118 QString defaultI18n;
119
120 switch (type) {
122 defaultI18n = i18nc("local mail folder", "inbox");
123 break;
125 defaultI18n = i18nc("local mail folder", "outbox");
126 break;
128 defaultI18n = i18nc("local mail folder", "sent-mail");
129 break;
131 defaultI18n = i18nc("local mail folder", "trash");
132 break;
134 defaultI18n = i18nc("local mail folder", "drafts");
135 break;
137 defaultI18n = i18nc("local mail folder", "templates");
138 break;
140 defaultI18n = i18nc("local mail folder", "spam");
141 break;
142 default:
143 break;
144 }
145 if (!defaultI18n.isEmpty()) {
148 collection.attribute<Akonadi::EntityDisplayAttribute>()->setDisplayName(defaultI18n);
149 auto job = new Akonadi::CollectionModifyJob(collection, this);
150 connect(job, &Akonadi::CollectionModifyJob::result, this, &SpecialMailCollections::slotCollectionModified);
151 }
152 }
153 }
154}
155
156void SpecialMailCollections::slotCollectionModified(KJob *job)
157{
158 if (job->error()) {
159 qCDebug(AKONADIMIME_LOG) << " Error when we modified collection";
160 return;
161 }
162}
163
172
173#include "moc_specialmailcollections.cpp"
const T * attribute() const
bool hasAttribute() const
static QString addNamespace(const QString &string)
bool hasCollection(const QByteArray &type, const AgentInstance &instance) const
bool hasDefaultCollection(const QByteArray &type) const
Akonadi::Collection collection(const QByteArray &type, const AgentInstance &instance) const
bool unregisterCollection(const Collection &collection)
bool registerCollection(const QByteArray &type, const Akonadi::Collection &collection)
Akonadi::Collection defaultCollection(const QByteArray &type) const
Interface to special mail collections such as inbox, outbox etc.
Type
Describes the possible types of special mail collections.
@ Invalid
An invalid special collection.
@ SentMail
The sent-mail collection.
@ Templates
The templates collection.
bool unregisterCollection(const Collection &collection)
Unregisters the given collection as a special mail collection.
bool registerCollection(Type type, const Akonadi::Collection &collection)
Registers the given collection as a special mail collection with the given type.
bool hasDefaultCollection(Type type) const
Returns whether the default resource has a special mail collection of the given type.
static Type specialCollectionType(const Akonadi::Collection &collection)
Returns the special collection type for a given collection, or empty if the collection doesn't have a...
static SpecialMailCollections * self()
Returns the global SpecialMailCollections instance.
Akonadi::Collection collection(Type type, const AgentInstance &instance) const
Returns the special mail collection of the given type in the given agent instance,...
Akonadi::Collection defaultCollection(Type type) const
Returns the special mail collection of given type in the default resource, or an invalid collection i...
bool hasCollection(Type type, const AgentInstance &instance) const
Returns whether the given agent instance has a special collection of the given type.
int error() const
void result(KJob *job)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.