Mailcommon

mailkernel.h
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 SPDX-FileCopyrightText: 2010 Andras Mantia <andras@kdab.com>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "config-mailcommon.h"
11#include "mailcommon/mailinterfaces.h"
12#include "mailcommon_export.h"
13
14#include <Akonadi/Collection>
15#include <Akonadi/SpecialMailCollections>
16#include <KSharedConfig>
17
18#include <QObject>
19namespace PimCommon
20{
22}
23
24#if MAILCOMMON_HAVE_ACTIVITY_SUPPORT
25namespace PimCommonActivities
26{
27class ActivitiesBaseManager;
28}
29#endif
30
31namespace MailCommon
32{
33/**
34 * Deals with common mail application related operations. The required interfaces
35 * MUST be registered before using it!
36 * Be careful when using in multi-threaded applications, as Kernel is a QObject
37 * singleton, created in the main thread, thus event handling for Kernel::self()
38 * will happen in the main thread.
39 */
40
41class MAILCOMMON_EXPORT Kernel : public QObject
42{
44public:
45 ~Kernel() override;
46
47 static Kernel *self();
48
49 /**
50 * Registers the interface dealing with main mail functionality. This function
51 * MUST be called with a valid interface pointer, before any Kernel::self()
52 * method is used. The pointer ownership will not be transferred to Kernel.
53 */
54 void registerKernelIf(IKernel *kernelIf);
55
56 [[nodiscard]] bool kernelIsRegistered() const;
57
58 IKernel *kernelIf() const;
59
60 /**
61 * Registers the interface dealing with mail settings. This function
62 * MUST be called with a valid interface pointer, before any Kernel::self()
63 * method is used. The pointer ownership will not be transferred to Kernel.
64 */
65 void registerSettingsIf(ISettings *settingsIf);
66
67 ISettings *settingsIf() const;
68
69 /**
70 * Registers the interface dealing with mail settings. This function
71 * MUST be called with a valid interface pointer, before any Kernel::self()
72 * method is used. The pointer ownership will not be transferred to Kernel.
73 */
74 void registerFilterIf(IFilter *filterIf);
75
76 IFilter *filterIf() const;
77
78 /**
79 * Returns the collection associated with the given @p id, or an invalid
80 * collection if not found. The EntityTreeModel of the kernel is searched for
81 * the collection. Since the ETM is loaded async, this method will not find
82 * the collection right after startup, when the ETM is not yet fully loaded.
83 */
85
86 [[nodiscard]] Akonadi::Collection inboxCollectionFolder();
87 [[nodiscard]] Akonadi::Collection outboxCollectionFolder();
88 [[nodiscard]] Akonadi::Collection sentCollectionFolder();
89 [[nodiscard]] Akonadi::Collection trashCollectionFolder();
90 [[nodiscard]] Akonadi::Collection draftsCollectionFolder();
91 [[nodiscard]] Akonadi::Collection templatesCollectionFolder();
92
93 [[nodiscard]] Akonadi::Collection spamsCollectionFolder();
94
95 [[nodiscard]] bool isSystemFolderCollection(const Akonadi::Collection &col);
96
97 /**
98 * Returns true if this folder is the inbox on the local disk
99 */
100 [[nodiscard]] bool isMainFolderCollection(const Akonadi::Collection &col);
101
102 /**
103 * Returns true if the folder is either the outbox or one of the drafts-folders.
104 */
105 [[nodiscard]] bool folderIsDraftOrOutbox(const Akonadi::Collection &collection);
106
107 [[nodiscard]] bool folderIsDrafts(const Akonadi::Collection &);
108
109 [[nodiscard]] bool folderIsTemplates(const Akonadi::Collection &collection);
110
111 [[nodiscard]] bool folderIsSpams(const Akonadi::Collection &collection);
112
113 /**
114 * Returns true if the folder is a trash folder.
115 *
116 * When calling this too early (before the SpecialMailCollectionsDiscoveryJob from initFolders finishes),
117 * it will say false erroneously. However you can connect to SpecialMailCollections::collectionsChanged
118 * to react on dynamic changes and call this again.
119 */
120 [[nodiscard]] bool folderIsTrash(const Akonadi::Collection &collection);
121
122 /**
123 * Returns the trash folder for the resource which @p col belongs to.
124 *
125 * When calling this too early (before the SpecialMailCollectionsDiscoveryJob from initFolders finishes),
126 * it will return an invalid collection erroneously. However you can connect to SpecialMailCollections::collectionsChanged
127 * to react on dynamic changes and call this again.
128 */
130
131 /**
132 * Returns true if the folder is one of the sent-mail folders.
133 */
134 [[nodiscard]] bool folderIsSentMailFolder(const Akonadi::Collection &);
135
136 static bool folderIsInbox(const Akonadi::Collection &);
137
138 void initFolders();
139
140 void emergencyExit(const QString &reason);
141
142 PimCommon::ImapResourceCapabilitiesManager *imapResourceManager() const;
143
144 static QMap<QString, Akonadi::Collection::Id> pop3ResourceTargetCollection();
145
146#if MAILCOMMON_HAVE_ACTIVITY_SUPPORT
147 PimCommonActivities::ActivitiesBaseManager *activitiesBaseManager() const;
148 void registerActivitiesBaseManager(PimCommonActivities::ActivitiesBaseManager *manager);
149#endif
150
151private:
152 void findCreateDefaultCollection(Akonadi::SpecialMailCollections::Type);
153
154private Q_SLOTS:
155 void createDefaultCollectionDone(KJob *job);
156 void slotDefaultCollectionsChanged();
157
159 void requestConfigSync();
160 void requestSystemTrayUpdate();
161
162private:
163 Kernel(QObject *parent = nullptr);
164 friend class KernelPrivate;
165
166 IKernel *mKernelIf = nullptr;
167 IFilter *mFilterIf = nullptr;
168 ISettings *mSettingsIf = nullptr;
169 PimCommon::ImapResourceCapabilitiesManager *mImapResourceManager = nullptr;
170#if MAILCOMMON_HAVE_ACTIVITY_SUPPORT
171 PimCommonActivities::ActivitiesBaseManager *mActivitiesBaseManager = nullptr;
172#endif
173};
174}
175
176#define KernelIf MailCommon::Kernel::self()->kernelIf()
177#define FilterIf MailCommon::Kernel::self()->filterIf()
178#define SettingsIf MailCommon::Kernel::self()->settingsIf()
179#define CommonKernel MailCommon::Kernel::self()
Filter related interface.
Generic interface for mail kernels.
Interface to access some settings.
void registerSettingsIf(ISettings *settingsIf)
Registers the interface dealing with mail settings.
Akonadi::Collection trashCollectionFromResource(const Akonadi::Collection &col)
Returns the trash folder for the resource which col belongs to.
bool folderIsDraftOrOutbox(const Akonadi::Collection &collection)
Returns true if the folder is either the outbox or one of the drafts-folders.
Akonadi::Collection collectionFromId(Akonadi::Collection::Id id) const
Returns the collection associated with the given id, or an invalid collection if not found.
void registerKernelIf(IKernel *kernelIf)
Registers the interface dealing with main mail functionality.
bool folderIsTrash(const Akonadi::Collection &collection)
Returns true if the folder is a trash folder.
bool isMainFolderCollection(const Akonadi::Collection &col)
Returns true if this folder is the inbox on the local disk.
bool folderIsSentMailFolder(const Akonadi::Collection &)
Returns true if the folder is one of the sent-mail folders.
void registerFilterIf(IFilter *filterIf)
Registers the interface dealing with mail settings.
The filter dialog.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:50:55 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.