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{
21class ImapResourceCapabilitiesManager;
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{
43 Q_OBJECT
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 */
84 [[nodiscard]] Akonadi::Collection collectionFromId(Akonadi::Collection::Id id) const;
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]] bool isSystemFolderCollection(const Akonadi::Collection &col);
94
95 /**
96 * Returns true if this folder is the inbox on the local disk
97 */
98 [[nodiscard]] bool isMainFolderCollection(const Akonadi::Collection &col);
99
100 /**
101 * Returns true if the folder is either the outbox or one of the drafts-folders.
102 */
103 [[nodiscard]] bool folderIsDraftOrOutbox(const Akonadi::Collection &collection);
104
105 [[nodiscard]] bool folderIsDrafts(const Akonadi::Collection &);
106
107 [[nodiscard]] bool folderIsTemplates(const Akonadi::Collection &collection);
108
109 /**
110 * Returns true if the folder is a trash folder.
111 *
112 * When calling this too early (before the SpecialMailCollectionsDiscoveryJob from initFolders finishes),
113 * it will say false erroneously. However you can connect to SpecialMailCollections::collectionsChanged
114 * to react on dynamic changes and call this again.
115 */
116 [[nodiscard]] bool folderIsTrash(const Akonadi::Collection &collection);
117
118 /**
119 * Returns the trash folder for the resource which @p col belongs to.
120 *
121 * When calling this too early (before the SpecialMailCollectionsDiscoveryJob from initFolders finishes),
122 * it will return an invalid collection erroneously. However you can connect to SpecialMailCollections::collectionsChanged
123 * to react on dynamic changes and call this again.
124 */
125 [[nodiscard]] Akonadi::Collection trashCollectionFromResource(const Akonadi::Collection &col);
126
127 /**
128 * Returns true if the folder is one of the sent-mail folders.
129 */
130 [[nodiscard]] bool folderIsSentMailFolder(const Akonadi::Collection &);
131
132 static bool folderIsInbox(const Akonadi::Collection &);
133
134 void initFolders();
135
136 void emergencyExit(const QString &reason);
137
138 PimCommon::ImapResourceCapabilitiesManager *imapResourceManager() const;
139
140 static QMap<QString, Akonadi::Collection::Id> pop3ResourceTargetCollection();
141
142#if MAILCOMMON_HAVE_ACTIVITY_SUPPORT
143 PimCommonActivities::ActivitiesBaseManager *activitiesBaseManager() const;
144 void registerActivitiesBaseManager(PimCommonActivities::ActivitiesBaseManager *manager);
145#endif
146
147private:
148 void findCreateDefaultCollection(Akonadi::SpecialMailCollections::Type);
149
150private Q_SLOTS:
151 void createDefaultCollectionDone(KJob *job);
152 void slotDefaultCollectionsChanged();
153
154Q_SIGNALS:
155 void requestConfigSync();
156 void requestSystemTrayUpdate();
157
158private:
159 Kernel(QObject *parent = nullptr);
160 friend class KernelPrivate;
161
162 IKernel *mKernelIf = nullptr;
163 IFilter *mFilterIf = nullptr;
164 ISettings *mSettingsIf = nullptr;
165 PimCommon::ImapResourceCapabilitiesManager *mImapResourceManager = nullptr;
166#if MAILCOMMON_HAVE_ACTIVITY_SUPPORT
167 PimCommonActivities::ActivitiesBaseManager *mActivitiesBaseManager = nullptr;
168#endif
169};
170}
171
172#define KernelIf MailCommon::Kernel::self()->kernelIf()
173#define FilterIf MailCommon::Kernel::self()->filterIf()
174#define SettingsIf MailCommon::Kernel::self()->settingsIf()
175#define CommonKernel MailCommon::Kernel::self()
Filter related interface.
Generic interface for mail kernels.
Interface to access some settings.
Deals with common mail application related operations.
Definition mailkernel.h:42
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:18:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.