• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • kmime
specialmailcollections.cpp
1/*
2 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "specialmailcollections.h"
21#include "akonadi/specialcollectionattribute_p.h"
22#include "akonadi/entitydisplayattribute.h"
23#include "akonadi/collectionmodifyjob.h"
24#include "specialmailcollectionssettings.h"
25
26#include <KGlobal>
27#include <KLocalizedString>
28#include "akonadi/agentinstance.h"
29#include "akonadi/servermanager.h"
30
31using namespace Akonadi;
32
33class Akonadi::SpecialMailCollectionsPrivate
34{
35public:
36 SpecialMailCollectionsPrivate();
37 ~SpecialMailCollectionsPrivate();
38
39 SpecialMailCollections *mInstance;
40};
41
42typedef SpecialMailCollectionsSettings Settings;
43
44K_GLOBAL_STATIC(SpecialMailCollectionsPrivate, sInstance)
45
46static const char s_specialCollectionTypes[SpecialMailCollections::LastType][11] = {
47 "local-mail",
48 "inbox",
49 "outbox",
50 "sent-mail",
51 "trash",
52 "drafts",
53 "templates"
54};
55
56static const int s_numTypes = sizeof s_specialCollectionTypes / sizeof * s_specialCollectionTypes;
57
58BOOST_STATIC_ASSERT(s_numTypes == SpecialMailCollections::LastType);
59
60static inline QByteArray enumToType(SpecialMailCollections::Type value)
61{
62 return s_specialCollectionTypes[value];
63}
64
65static inline SpecialMailCollections::Type typeToEnum(const QByteArray &type)
66{
67 for (int i = 0; i < s_numTypes; ++i) {
68 if (type == s_specialCollectionTypes[i]) {
69 return static_cast<SpecialMailCollections::Type>(i);
70 }
71 }
72 return SpecialMailCollections::Invalid;
73}
74
75SpecialMailCollectionsPrivate::SpecialMailCollectionsPrivate()
76 : mInstance(new SpecialMailCollections(this))
77{
78}
79
80SpecialMailCollectionsPrivate::~SpecialMailCollectionsPrivate()
81{
82 delete mInstance;
83}
84
85static KCoreConfigSkeleton *getConfig(const QString &filename)
86{
87 Settings::instance(ServerManager::addNamespace(filename));
88 return Settings::self();
89}
90
91SpecialMailCollections::SpecialMailCollections(SpecialMailCollectionsPrivate *dd)
92 : SpecialCollections(getConfig(QLatin1String("specialmailcollectionsrc")))
93 , d(dd)
94{
95}
96
97SpecialMailCollections *SpecialMailCollections::self()
98{
99 return sInstance->mInstance;
100}
101
102bool SpecialMailCollections::hasCollection(Type type, const AgentInstance &instance) const
103{
104 return SpecialCollections::hasCollection(enumToType(type), instance);
105}
106
107Collection SpecialMailCollections::collection(Type type, const AgentInstance &instance) const
108{
109 return SpecialCollections::collection(enumToType(type), instance);
110}
111
112bool SpecialMailCollections::registerCollection(Type type, const Collection &collection)
113{
114 return SpecialCollections::registerCollection(enumToType(type), collection);
115}
116
117bool SpecialMailCollections::unregisterCollection(const Collection &collection)
118{
119 if (collection != Akonadi::SpecialMailCollections::self()->defaultCollection(Akonadi::SpecialMailCollections::Trash)) {
120 return SpecialCollections::unregisterCollection(collection);
121 } else {
122 return false;
123 }
124}
125
126bool SpecialMailCollections::hasDefaultCollection(Type type) const
127{
128 return SpecialCollections::hasDefaultCollection(enumToType(type));
129}
130
131Collection SpecialMailCollections::defaultCollection(Type type) const
132{
133 return SpecialCollections::defaultCollection(enumToType(type));
134}
135
136void SpecialMailCollections::verifyI18nDefaultCollection(Type type)
137{
138 Collection collection = defaultCollection(type);
139 QString defaultI18n;
140
141 switch (type) {
142 case SpecialMailCollections::Inbox:
143 defaultI18n = i18nc("local mail folder", "inbox");
144 break;
145 case SpecialMailCollections::Outbox:
146 defaultI18n = i18nc("local mail folder", "outbox");
147 break;
148 case SpecialMailCollections::SentMail:
149 defaultI18n = i18nc("local mail folder", "sent-mail");
150 break;
151 case SpecialMailCollections::Trash:
152 defaultI18n = i18nc("local mail folder", "trash");
153 break;
154 case SpecialMailCollections::Drafts:
155 defaultI18n = i18nc("local mail folder", "drafts");
156 break;
157 case SpecialMailCollections::Templates:
158 defaultI18n = i18nc("local mail folder", "templates");
159 break;
160 default:
161 break;
162 }
163 if (!defaultI18n.isEmpty()) {
164 if (collection.hasAttribute<Akonadi::EntityDisplayAttribute>()) {
165 if (collection.attribute<Akonadi::EntityDisplayAttribute>()->displayName() != defaultI18n) {
166 collection.attribute<Akonadi::EntityDisplayAttribute>()->setDisplayName(defaultI18n);
167 Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob(collection, this);
168 connect(job, SIGNAL(result(KJob*)), this, SLOT(slotCollectionModified(KJob*)));
169 }
170 }
171 }
172}
173
174void SpecialMailCollections::slotCollectionModified(KJob *job)
175{
176 if (job->error()) {
177 kDebug() << " Error when we modified collection";
178 return;
179 }
180}
181
182SpecialMailCollections::Type SpecialMailCollections::specialCollectionType(const Akonadi::Collection &collection)
183{
184 if (!collection.hasAttribute<SpecialCollectionAttribute>()) {
185 return Invalid;
186 } else {
187 return typeToEnum(collection.attribute<SpecialCollectionAttribute>()->collectionType());
188 }
189}
Akonadi::AgentInstance
A representation of an agent instance.
Definition agentinstance.h:63
Akonadi::CollectionModifyJob
Job that modifies a collection in the Akonadi storage.
Definition collectionmodifyjob.h:83
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::EntityDisplayAttribute
Attribute that stores the properties that are used to display an entity.
Definition entitydisplayattribute.h:40
Akonadi::EntityDisplayAttribute::displayName
QString displayName() const
Returns the name that should be used for display.
Definition entitydisplayattribute.cpp:52
Akonadi::Entity::hasAttribute
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Definition entity.cpp:148
Akonadi::Entity::attribute
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
Definition entity.cpp:167
Akonadi::ServerManager::addNamespace
static QString addNamespace(const QString &string)
Adds the multi-instance namespace to string if required (with '_' as separator).
Definition servermanager.cpp:337
Akonadi::SpecialCollectionAttribute
An Attribute that stores the special collection type of a collection.
Definition specialcollectionattribute_p.h:40
Akonadi::SpecialCollectionAttribute::collectionType
QByteArray collectionType() const
Returns the special collections type of the collection.
Definition specialcollectionattribute.cpp:74
Akonadi::SpecialCollections
An interface to special collections.
Definition specialcollections.h:66
Akonadi::SpecialCollections::hasCollection
bool hasCollection(const QByteArray &type, const AgentInstance &instance) const
Returns whether the given agent instance has a special collection of the given type.
Definition specialcollections.cpp:194
Akonadi::SpecialCollections::hasDefaultCollection
bool hasDefaultCollection(const QByteArray &type) const
Returns whether the default resource has a special collection of the given type.
Definition specialcollections.cpp:272
Akonadi::SpecialCollections::collection
Akonadi::Collection collection(const QByteArray &type, const AgentInstance &instance) const
Returns the special collection of the given type in the given agent instance, or an invalid collectio...
Definition specialcollections.cpp:199
Akonadi::SpecialCollections::unregisterCollection
bool unregisterCollection(const Collection &collection)
Unregisters the given collection as a spec ial collection.
Definition specialcollections.cpp:223
Akonadi::SpecialCollections::registerCollection
bool registerCollection(const QByteArray &type, const Akonadi::Collection &collection)
Registers the given collection as a special collection with the given type.
Definition specialcollections.cpp:244
Akonadi::SpecialCollections::defaultCollection
Akonadi::Collection defaultCollection(const QByteArray &type) const
Returns the special collection of given type in the default resource, or an invalid collection if suc...
Definition specialcollections.cpp:277
Akonadi::SpecialMailCollections
Interface to special mail collections such as inbox, outbox etc.
Definition specialmailcollections.h:68
Akonadi::SpecialMailCollections::Type
Type
Describes the possible types of special mail collections.
Definition specialmailcollections.h:78
Akonadi::SpecialMailCollections::Invalid
@ Invalid
An invalid special collection.
Definition specialmailcollections.h:79
Akonadi::SpecialMailCollections::Inbox
@ Inbox
The inbox collection.
Definition specialmailcollections.h:81
Akonadi::SpecialMailCollections::Drafts
@ Drafts
The drafts collection.
Definition specialmailcollections.h:85
Akonadi::SpecialMailCollections::SentMail
@ SentMail
The sent-mail collection.
Definition specialmailcollections.h:83
Akonadi::SpecialMailCollections::LastType
@ LastType
Definition specialmailcollections.h:87
Akonadi::SpecialMailCollections::Trash
@ Trash
The trash collection.
Definition specialmailcollections.h:84
Akonadi::SpecialMailCollections::Outbox
@ Outbox
The outbox collection.
Definition specialmailcollections.h:82
Akonadi::SpecialMailCollections::Templates
@ Templates
The templates collection.
Definition specialmailcollections.h:86
Akonadi::SpecialMailCollections::unregisterCollection
bool unregisterCollection(const Collection &collection)
Unregisters the given collection as a special mail collection.
Definition specialmailcollections.cpp:117
Akonadi::SpecialMailCollections::registerCollection
bool registerCollection(Type type, const Akonadi::Collection &collection)
Registers the given collection as a special mail collection with the given type.
Definition specialmailcollections.cpp:112
Akonadi::SpecialMailCollections::hasDefaultCollection
bool hasDefaultCollection(Type type) const
Returns whether the default resource has a special mail collection of the given type.
Definition specialmailcollections.cpp:126
Akonadi::SpecialMailCollections::specialCollectionType
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...
Definition specialmailcollections.cpp:182
Akonadi::SpecialMailCollections::self
static SpecialMailCollections * self()
Returns the global SpecialMailCollections instance.
Definition specialmailcollections.cpp:97
Akonadi::SpecialMailCollections::collection
Akonadi::Collection collection(Type type, const AgentInstance &instance) const
Returns the special mail collection of the given type in the given agent instance,...
Definition specialmailcollections.cpp:107
Akonadi::SpecialMailCollections::defaultCollection
Akonadi::Collection defaultCollection(Type type) const
Returns the special mail collection of given type in the default resource, or an invalid collection i...
Definition specialmailcollections.cpp:131
Akonadi::SpecialMailCollections::hasCollection
bool hasCollection(Type type, const AgentInstance &instance) const
Returns whether the given agent instance has a special collection of the given type.
Definition specialmailcollections.cpp:102
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal