6 #include "interfaces/mailinterfaces.h"
11 #include <QDBusObjectPath>
12 #include <Solid/Networking>
16 #include "kmail_export.h"
17 #include "settings/globalsettings.h"
18 #include <AkonadiCore/servermanager.h>
19 #include "messageviewer/viewer/viewer.h"
20 #include "progresswidget/progressmanager.h"
22 #define kmkernel KMKernel::self()
23 #define kmconfig KMKernel::config()
25 class QAbstractItemModel
;
30 class EntityTreeModel
;
31 class EntityMimeTypeFilterModel
;
39 namespace MessageComposer
46 class StorageServiceManager
;
49 /** The KMail namespace contains classes used for KMail.
50 * This is to keep them out of the way from all the other
51 * un-namespaced classes in libs and the rest of PIM.
55 class MailServiceImpl
;
59 using KMail::MailServiceImpl
;
60 using KMail::UndoStack
;
61 namespace MessageComposer
66 namespace KIdentityManagement
69 class IdentityManager
;
75 class FolderCollection
;
76 class FolderCollectionMonitor
;
85 class ConfigureDialog
;
86 class FolderArchiveManager
;
89 * @short Central point of coordination in KMail
91 * The KMKernel class represents the core of KMail, where the different parts
92 * come together and are coordinated. It is currently also the class which exports
93 * KMail's main D-BUS interfaces.
95 * The kernel is responsible for creating various
96 * (singleton) objects such as the identity manager and the message sender.
98 * The kernel also creates an Akonadi Session, Monitor and EntityTreeModel. These
99 * are shared so that other objects in KMail have access to it. Having only one EntityTreeModel
100 * instead of many reduces the overall communication with the Akonadi server.
102 * The kernel also manages some stuff that should be factored out:
103 * - default collection handling, like inboxCollectionFolder()
104 * - job handling, like jobScheduler()
105 * - handling of some config settings, like wrapCol()
106 * - various other stuff
108 class KMAIL_EXPORT KMKernel
: public QObject
, public MailCommon::IKernel
, public MailCommon::ISettings
, public MailCommon::IFilter
111 Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.kmail")
114 explicit KMKernel(QObject
*parent
= Q_NULLPTR
);
118 * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
119 * otherwise they can't be accessed.
123 Q_SCRIPTABLE
void checkMail();
124 Q_SCRIPTABLE
void openReader()
130 * Enables/disables systray icon changing when mail arrives.
131 * With this disabled the systray icon will always be the same.
133 Q_SCRIPTABLE
void setSystrayIconNotificationsEnabled(bool enabled
);
136 * Pauses all background jobs and does not
137 * allow new background jobs to be started.
139 Q_SCRIPTABLE
void pauseBackgroundJobs();
142 * Resumes all background jobs and allows
143 * new jobs to be started.
145 Q_SCRIPTABLE
void resumeBackgroundJobs();
148 * Stops all network related jobs and enter offline mode
149 * New network jobs cannot be started.
151 Q_SCRIPTABLE
void stopNetworkJobs();
154 * Resumes all network related jobs and enter online mode
155 * New network jobs can be started.
157 Q_SCRIPTABLE
void resumeNetworkJobs();
159 Q_SCRIPTABLE QStringList
accounts();
161 Q_SCRIPTABLE
void makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode mode
);
164 * Checks the account with the specified name for new mail.
165 * If the account name is empty, all accounts not excluded from manual
166 * mail check will be checked.
168 Q_SCRIPTABLE
void checkAccount(const QString
&account
);
170 Q_SCRIPTABLE
bool selectFolder(const QString
&folder
);
172 Q_SCRIPTABLE
bool canQueryClose();
174 Q_SCRIPTABLE
bool handleCommandLine(bool noArgsOpensReader
, const QStringList
&args
);
177 * Opens a composer window and prefills it with different
180 * @returns The id of composer if more are opened.
182 * @param to A comma separated list of To addresses.
183 * @param cc A comma separated list of CC addresses.
184 * @param bcc A comma separated list of BCC addresses.
185 * @param subject The message subject.
186 * @param body The message body.
187 * @param hidden Whether the composer window shall initially be hidden.
188 * @param messageFile A message file that will be used as message body.
189 * @param attachmentPaths A list of files that will be attached to the message.
190 * @param customHeaders A list of custom headers.
192 Q_SCRIPTABLE
int openComposer(const QString
&to
,
195 const QString
&subject
,
198 const QString
&messageFile
,
199 const QStringList
&attachmentPaths
,
200 const QStringList
&customHeaders
, const QString
&replyTo
= QString(), const QString
&inReplyTo
= QString());
203 * Opens a composer window and prefills it with different
206 * @returns The id of composer if more are opened.
208 * @param to A comma separated list of To addresses.
209 * @param cc A comma separated list of CC addresses.
210 * @param bcc A comma separated list of BCC addresses.
211 * @param subject The message subject.
212 * @param body The message body.
213 * @param hidden Whether the composer window shall initially be hidden.
214 * @param attachName The name of the attachment.
215 * @param attachCte The content transfer encoding of the attachment.
216 * @param attachData The raw data of the attachment.
217 * @param attachType The mime type of the attachment.
218 * @param attachSubType The sub mime type of the attachment.
219 * @param attachParamAttr The parameter attribute of the attachment.
220 * @param attachParamValue The parameter value of the attachment.
221 * @param attachContDisp The content display type of the attachment.
222 * @param attachCharset The charset of the attachment.
223 * @param identity The identity identifier which will be used as sender identity.
225 Q_SCRIPTABLE
int openComposer(const QString
&to
,
228 const QString
&subject
,
231 const QString
&attachName
,
232 const QByteArray
&attachCte
,
233 const QByteArray
&attachData
,
234 const QByteArray
&attachType
,
235 const QByteArray
&attachSubType
,
236 const QByteArray
&attachParamAttr
,
237 const QString
&attachParamValue
,
238 const QByteArray
&attachContDisp
,
239 const QByteArray
&attachCharset
,
240 unsigned int identity
);
243 * Opens a composer window and prefills it with different
247 * @returns The id of composer if more are opened.
249 * @param to A comma separated list of To addresses.
250 * @param cc A comma separated list of CC addresses.
251 * @param bcc A comma separated list of BCC addresses.
252 * @param subject The message subject.
253 * @param body The message body.
254 * @param attachName The name of the attachment.
255 * @param attachCte The content transfer encoding of the attachment.
256 * @param attachData The raw data of the attachment.
257 * @param attachType The mime type of the attachment.
258 * @param attachSubType The sub mime type of the attachment.
259 * @param attachParamAttr The parameter attribute of the attachment.
260 * @param attachParamValue The parameter value of the attachment.
261 * @param attachContDisp The content display type of the attachment.
262 * @param attachCharset The charset of the attachment.
263 * @param identity The identity identifier which will be used as sender identity.
265 Q_SCRIPTABLE
int openComposer(const QString
&to
,
268 const QString
&subject
,
270 const QString
&attachName
,
271 const QByteArray
&attachCte
,
272 const QByteArray
&attachData
,
273 const QByteArray
&attachType
,
274 const QByteArray
&attachSubType
,
275 const QByteArray
&attachParamAttr
,
276 const QString
&attachParamValue
,
277 const QByteArray
&attachContDisp
,
278 const QByteArray
&attachCharset
,
279 unsigned int identity
);
282 * Opens a composer window and prefills it with different
285 * @returns The DBus object path for the composer.
287 * @param to A comma separated list of To addresses.
288 * @param cc A comma separated list of CC addresses.
289 * @param bcc A comma separated list of BCC addresses.
290 * @param subject The message subject.
291 * @param body The message body.
292 * @param hidden Whether the composer window shall initially be hidden.
294 Q_SCRIPTABLE QDBusObjectPath
openComposer(const QString
&to
,
297 const QString
&subject
,
302 * Opens a composer window and prefills it with different
305 * @returns The DBus object path for the composer.
307 * @param to A comma separated list of To addresses.
308 * @param cc A comma separated list of CC addresses.
309 * @param bcc A comma separated list of BCC addresses.
310 * @param subject The message subject.
311 * @param body The message body.
312 * @param hidden Whether the composer window shall initially be hidden.
313 * @param useFolderId The id of the folder whose associated identity will be used.
314 * @param messageFile A message file that will be used as message body.
315 * @param attachURL The URL to the file that will be attached to the message.
317 Q_SCRIPTABLE QDBusObjectPath
newMessage(const QString
&to
,
322 const QString
&messageFile
,
323 const QString
&attachURL
);
325 Q_SCRIPTABLE
bool showMail(qint64 serialNumber
);
327 Q_SCRIPTABLE
int viewMessage(const QString
&messageFile
);
329 Q_SCRIPTABLE
void updateConfig();
331 Q_SCRIPTABLE
void showFolder(const QString
&collectionId
);
333 Q_SCRIPTABLE
void reloadFolderArchiveConfig();
336 * End of D-Bus callable stuff
340 void checkMailOnStartup();
342 /** A static helper function that asks the user
343 * if they want to go online.
344 * @return true if the user wants to go online
345 * @return false if the user wants to stay offline
347 static bool askToGoOnline();
349 /** Checks if the current network state is online or offline
350 * @return true if the network state is offline
351 * @return false if the network state is online
353 static bool isOffline();
355 /** normal control stuff */
357 static KMKernel
*self();
358 KSharedConfig::Ptr
config() Q_DECL_OVERRIDE
;
359 void syncConfig() Q_DECL_OVERRIDE
;
364 Akonadi::ChangeRecorder
*folderCollectionMonitor() const Q_DECL_OVERRIDE
;
367 * Returns the main model, which contains all folders and the items of recently opened folders.
369 Akonadi::EntityTreeModel
*entityTreeModel() const;
372 * Returns a model of all folders in KMail. This is basically the same as entityTreeModel(),
373 * but with items filtered out, the model contains only collections.
375 Akonadi::EntityMimeTypeFilterModel
*collectionModel() const Q_DECL_OVERRIDE
;
377 void recoverDeadLetters();
378 void closeAllKMailWindows();
381 bool doSessionManagement();
382 bool firstInstance() const;
383 void setFirstInstance(bool value
);
384 void action(bool mailto
, bool check
, const QString
&to
, const QString
&cc
,
385 const QString
&bcc
, const QString
&subj
, const QString
&body
,
386 const QUrl
&messageFile
, const QList
<QUrl
> &attach
,
387 const QStringList
&customHeaders
, const QString
&replyTo
, const QString
&inReplyTo
);
389 //sets online status for akonadi accounts. true for online, false for offline
390 void setAccountStatus(bool);
392 const QString
xmlGuiInstanceName() const
394 return mXmlGuiInstance
;
396 void setXmlGuiInstanceName(const QString
&instance
)
398 mXmlGuiInstance
= instance
;
401 UndoStack
*undoStack() const
403 return the_undoStack
;
405 MessageComposer::MessageSender
*msgSender() Q_DECL_OVERRIDE
;
407 void openFilterDialog(bool createDummyFilter
= true) Q_DECL_OVERRIDE
;
408 void createFilter(const QByteArray
&field
, const QString
&value
) Q_DECL_OVERRIDE
;
410 /** return the pointer to the identity manager */
411 KIdentityManagement::IdentityManager
*identityManager() Q_DECL_OVERRIDE
;
413 MailCommon::JobScheduler
*jobScheduler() const Q_DECL_OVERRIDE
415 return mJobScheduler
;
418 /** Expire all folders, used for the gui action */
419 void expireAllFoldersNow();
421 bool firstStart() const
423 return the_firstStart
;
425 QString
previousVersion() const
427 return the_previousVersion
;
429 bool shuttingDown() const
431 return the_shuttingDown
;
433 void setShuttingDown(bool flag
)
435 the_shuttingDown
= flag
;
438 /** Returns the full path of the user's local data directory for KMail.
439 The path ends with '/'.
441 static QString
localDataPath();
443 /** Returns true if we have a system tray applet. This is needed in order
444 * to know whether the application should be allowed to exit in case the
445 * last visible composer or separate message window is closed.
447 bool haveSystemTrayApplet() const;
449 QTextCodec
*networkCodec() const
454 /** returns a reference to the first Mainwin or a temporary Mainwin */
455 KMainWindow
*mainWin();
457 /** Get first mainwidget */
458 KMMainWidget
*getKMMainWidget();
461 * Returns a list of all currently loaded folders. Since folders are loaded async, this
462 * is empty at startup.
464 Akonadi::Collection::List
allFolders() const;
466 void selectCollectionFromId(const Akonadi::Collection::Id id
);
470 void stopAgentInstance();
473 bool showPopupAfterDnD() Q_DECL_OVERRIDE
;
475 bool excludeImportantMailFromExpiry() Q_DECL_OVERRIDE
;
477 qreal
closeToQuotaThreshold() Q_DECL_OVERRIDE
;
479 Akonadi::Collection::Id
lastSelectedFolder() Q_DECL_OVERRIDE
;
480 void setLastSelectedFolder(const Akonadi::Collection::Id
&col
) Q_DECL_OVERRIDE
;
482 QStringList
customTemplates() Q_DECL_OVERRIDE
;
484 void checkFolderFromResources(const Akonadi::Collection::List
&collectionList
);
486 const QAbstractItemModel
*treeviewModelSelection();
488 void savePaneSelection();
490 void updatePaneTagComboBox();
492 PimCommon::AutoCorrection
*composerAutoCorrection();
494 void toggleSystemTray();
495 FolderArchiveManager
*folderArchiveManager() const;
496 PimCommon::StorageServiceManager
*storageServiceManager() const;
498 bool allowToDebugBalooSupport() const;
501 void agentInstanceBroken(const Akonadi::AgentInstance
&instance
);
505 void updateSystemTray() Q_DECL_OVERRIDE
;
507 /** Custom templates have changed, so all windows using them need
508 to regenerate their menus */
509 void updatedTemplates();
511 /// Save contents of all open composer widnows to ~/dead.letter
512 void dumpDeadLetters();
514 /** Call this slot instead of directly KConfig::sync() to
515 minimize the overall config writes. Calling this slot will
516 schedule a sync of the application config file using a timer, so
517 that many consecutive calls can be condensed into a single
518 sync, which is more efficient. */
519 void slotRequestConfigSync();
522 * Sync the config immediatley
524 void slotSyncConfig();
526 void slotShowConfigurationDialog();
527 void slotRunBackgroundTasks();
529 void slotConfigChanged();
532 void configChanged();
533 void onlineStatusChanged(GlobalSettings::EnumNetworkState::type
);
534 void customTemplatesChanged();
536 void startCheckMail();
540 /** Updates identities when a transport has been deleted. */
541 void transportRemoved(int id
, const QString
&name
);
542 /** Updates identities when a transport has been renamed. */
543 void transportRenamed(int id
, const QString
&oldName
, const QString
&newName
);
544 void itemDispatchStarted();
545 void instanceStatusChanged(const Akonadi::AgentInstance
&);
547 void akonadiStateChanged(Akonadi::ServerManager::State
);
548 void slotProgressItemCompletedOrCanceled(KPIM::ProgressItem
*item
);
549 void slotInstanceError(const Akonadi::AgentInstance
&instance
, const QString
&message
);
550 void slotInstanceWarning(const Akonadi::AgentInstance
&instance
, const QString
&message
);
551 void slotCollectionRemoved(const Akonadi::Collection
&col
);
552 void slotDeleteIdentity(uint identity
);
553 void slotInstanceRemoved(const Akonadi::AgentInstance
&);
554 void slotSystemNetworkStatusChanged(Solid::Networking::Status
);
555 void slotCollectionChanged(const Akonadi::Collection
&, const QSet
<QByteArray
> &set
);
557 void slotCheckAccount(Akonadi::ServerManager::State state
);
560 * Fills a composer cWin
562 * @returns true if attached message is a valid iCal message
564 bool fillComposer(KMail::Composer
*&cWin
,
565 const QString
&to
, const QString
&cc
,
566 const QString
&bcc
, const QString
&subject
,
568 const QString
&attachName
,
569 const QByteArray
&attachCte
,
570 const QByteArray
&attachData
,
571 const QByteArray
&attachType
,
572 const QByteArray
&attachSubType
,
573 const QByteArray
&attachParamAttr
,
574 const QString
&attachParamValue
,
575 const QByteArray
&attachContDisp
,
576 const QByteArray
&attachCharset
,
577 unsigned int identity
);
579 void verifyAccount();
580 void resourceGoOnLine();
581 void openReader(bool onlyCheck
);
582 QSharedPointer
<MailCommon::FolderCollection
> currentFolderCollection();
584 UndoStack
*the_undoStack
;
585 mutable KIdentityManagement::IdentityManager
*mIdentityManager
;
586 MessageComposer::AkonadiSender
*the_msgSender
;
587 /** previous KMail version. If different from current,
588 the user has just updated. read from config */
589 QString the_previousVersion
;
590 /** is this the first start? read from config */
592 /** are we going down? set from here */
593 bool the_shuttingDown
;
594 /** true unles kmail is closed by session management */
595 bool the_firstInstance
;
597 KSharedConfig::Ptr mConfig
;
598 QTextCodec
*mNetCodec
;
599 QString mXmlGuiInstance
;
600 ConfigureDialog
*mConfigureDialog
;
602 QTimer
*mBackgroundTasksTimer
;
603 MailCommon::JobScheduler
*mJobScheduler
;
606 MailServiceImpl
*mMailService
;
608 Solid::Networking::Status mSystemNetworkStatus
;
610 KMail::KMSystemTray
*mSystemTray
;
611 QHash
<QString
, KPIM::ProgressItem::CryptoStatus
> mResourceCryptoSettingCache
;
612 MailCommon::FolderCollectionMonitor
*mFolderCollectionMonitor
;
613 Akonadi::EntityTreeModel
*mEntityTreeModel
;
614 Akonadi::EntityMimeTypeFilterModel
*mCollectionModel
;
616 /// List of Akonadi resources that are currently being checked.
617 QList
<QString
> mResourcesBeingChecked
;
619 QPointer
<MailCommon::KMFilterDialog
> mFilterEditDialog
;
620 PimCommon::AutoCorrection
*mAutoCorrection
;
621 FolderArchiveManager
*mFolderArchiveManager
;
622 PimCommon::StorageServiceManager
*mStorageManager
;
626 #endif // _KMKERNEL_H