1 // -*- mode: C++; c-file-style: "gnu" -*-
6 #include "mailinterfaces.h"
13 #include <QDBusObjectPath>
18 #include "kmail_export.h"
19 #include "globalsettings.h"
20 #include <kcomponentdata.h>
21 #include <akonadi/kmime/specialmailcollections.h>
22 #include <akonadi/servermanager.h>
24 #define kmkernel KMKernel::self()
25 #define kmconfig KMKernel::config()
31 class EntityTreeModel
;
32 class EntityMimeTypeFilterModel
;
46 /** The KMail namespace contains classes used for KMail.
47 * This is to keep them out of the way from all the other
48 * un-namespaced classes in libs and the rest of PIM.
51 class MailServiceImpl
;
54 namespace KPIM
{ class ProgressDialog
; }
55 using KMail::MailServiceImpl
;
56 using KMail::UndoStack
;
57 using KPIM::ProgressDialog
;
60 namespace KPIMIdentities
{
62 class IdentityManager
;
70 class ConfigureDialog
;
73 namespace MailCommon
{
76 class FilterActionDict
;
77 class FolderCollection
;
78 class FolderCollectionMonitor
;
83 * @short Central point of coordination in KMail
85 * The KMKernel class represents the core of KMail, where the different parts
86 * come together and are coordinated. It is currently also the class which exports
87 * KMail's main D-BUS interfaces.
89 * The kernel is responsible for creating various
90 * (singleton) objects such as the identity manager and the message sender.
92 * The kernel also creates an Akonadi Session, Monitor and EntityTreeModel. These
93 * are shared so that other objects in KMail have access to it. Having only one EntityTreeModel
94 * instead of many reduces the overall communication with the Akonadi server.
96 * The kernel also manages some stuff that should be factored out:
97 * - default collection handling, like inboxCollectionFolder()
98 * - job handling, like jobScheduler()
99 * - handling of some config settings, like wrapCol()
100 * - various other stuff
102 class KMAIL_EXPORT KMKernel
: public QObject
, public MailCommon::IKernel
, public MailCommon::ISettings
, public MailCommon::IFilter
105 Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.kmail")
108 explicit KMKernel (QObject
*parent
=0, const char *name
=0);
112 * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
113 * otherwise they can't be accessed.
117 Q_SCRIPTABLE
void checkMail();
118 Q_SCRIPTABLE
void openReader() { openReader( false ); }
121 * Pauses all background jobs and does not
122 * allow new background jobs to be started.
124 Q_SCRIPTABLE
void pauseBackgroundJobs();
127 * Resumes all background jobs and allows
128 * new jobs to be started.
130 Q_SCRIPTABLE
void resumeBackgroundJobs();
133 * Stops all network related jobs and enter offline mode
134 * New network jobs cannot be started.
136 Q_SCRIPTABLE
void stopNetworkJobs();
139 * Resumes all network related jobs and enter online mode
140 * New network jobs can be started.
142 Q_SCRIPTABLE
void resumeNetworkJobs();
144 Q_SCRIPTABLE QStringList
accounts();
147 * Checks the account with the specified name for new mail.
148 * If the account name is empty, all accounts not excluded from manual
149 * mail check will be checked.
151 Q_SCRIPTABLE
void checkAccount( const QString
& account
);
153 Q_SCRIPTABLE
void selectFolder( const QString
& folder
);
155 Q_SCRIPTABLE
bool canQueryClose();
157 Q_SCRIPTABLE
bool handleCommandLine( bool noArgsOpensReader
);
160 * Opens a composer window and prefills it with different
163 * @returns The id of composer if more are opened.
165 * @param to A comma separated list of To addresses.
166 * @param cc A comma separated list of CC addresses.
167 * @param bcc A comma separated list of BCC addresses.
168 * @param subject The message subject.
169 * @param body The message body.
170 * @param hidden Whether the composer window shall initially be hidden.
171 * @param messageFile A message file that will be used as message body.
172 * @param attachmentPaths A list of files that will be attached to the message.
173 * @param customHeaders A list of custom headers.
175 Q_SCRIPTABLE
int openComposer( const QString
& to
,
178 const QString
& subject
,
179 const QString
& body
,
181 const QString
& messageFile
,
182 const QStringList
& attachmentPaths
,
183 const QStringList
& customHeaders
);
186 * Opens a composer window and prefills it with different
189 * @returns The id of composer if more are opened.
191 * @param to A comma separated list of To addresses.
192 * @param cc A comma separated list of CC addresses.
193 * @param bcc A comma separated list of BCC addresses.
194 * @param subject The message subject.
195 * @param body The message body.
196 * @param hidden Whether the composer window shall initially be hidden.
197 * @param attachName The name of the attachment.
198 * @param attachCte The content transfer encoding of the attachment.
199 * @param attachData The raw data of the attachment.
200 * @param attachType The mime type of the attachment.
201 * @param attachSubType The sub mime type of the attachment.
202 * @param attachParamAttr The parameter attribute of the attachment.
203 * @param attachParamValue The parameter value of the attachment.
204 * @param attachContDisp The content display type of the attachment.
205 * @param attachCharset The charset of the attachment.
206 * @param identity The identity identifier which will be used as sender identity.
208 Q_SCRIPTABLE
int openComposer( const QString
& to
,
211 const QString
& subject
,
212 const QString
& body
,
214 const QString
& attachName
,
215 const QByteArray
& attachCte
,
216 const QByteArray
&attachData
,
217 const QByteArray
& attachType
,
218 const QByteArray
& attachSubType
,
219 const QByteArray
& attachParamAttr
,
220 const QString
& attachParamValue
,
221 const QByteArray
& attachContDisp
,
222 const QByteArray
& attachCharset
,
223 unsigned int identity
);
226 * Opens a composer window and prefills it with different
229 * @returns The DBus object path for the composer.
231 * @param to A comma separated list of To addresses.
232 * @param cc A comma separated list of CC addresses.
233 * @param bcc A comma separated list of BCC addresses.
234 * @param subject The message subject.
235 * @param body The message body.
236 * @param hidden Whether the composer window shall initially be hidden.
238 Q_SCRIPTABLE QDBusObjectPath
openComposer( const QString
& to
,
241 const QString
& subject
,
242 const QString
& body
,
246 * Opens a composer window and prefills it with different
249 * @returns The DBus object path for the composer.
251 * @param to A comma separated list of To addresses.
252 * @param cc A comma separated list of CC addresses.
253 * @param bcc A comma separated list of BCC addresses.
254 * @param subject The message subject.
255 * @param body The message body.
256 * @param hidden Whether the composer window shall initially be hidden.
257 * @param useFolderId The id of the folder whose associated identity will be used.
258 * @param messageFile A message file that will be used as message body.
259 * @param attachURL The URL to the file that will be attached to the message.
261 Q_SCRIPTABLE QDBusObjectPath
newMessage( const QString
& to
,
266 const QString
& messageFile
,
267 const QString
& attachURL
);
269 Q_SCRIPTABLE
bool showMail( quint32 serialNumber
, const QString
& messageId
);
271 Q_SCRIPTABLE
int viewMessage( const KUrl
& messageFile
);
274 * End of D-Bus callable stuff
279 void checkMailOnStartup();
281 /** A static helper function that asks the user
282 * if they want to go online.
283 * @return true if the user wants to go online
284 * @return false if the user wants to stay offline
286 static bool askToGoOnline();
288 /** Checks if the current network state is online or offline
289 * @return true if the network state is offline
290 * @return false if the network state is online
292 static bool isOffline();
294 /** normal control stuff */
296 static KMKernel
*self();
297 /*reimp*/ KSharedConfig::Ptr
config();
298 /*reimp*/ void syncConfig();
304 /*reimp*/ Akonadi::ChangeRecorder
*folderCollectionMonitor() const;
307 * Returns the main model, which contains all folders and the items of recently opened folders.
309 Akonadi::EntityTreeModel
*entityTreeModel() const;
312 * Returns a model of all folders in KMail. This is basically the same as entityTreeModel(),
313 * but with items filtered out, the model contains only collections.
315 /*reimp*/ Akonadi::EntityMimeTypeFilterModel
*collectionModel() const;
317 void recoverDeadLetters();
318 void closeAllKMailWindows();
321 bool doSessionManagement();
322 bool firstInstance() const { return the_firstInstance
; }
323 void setFirstInstance(bool value
) { the_firstInstance
= value
; }
324 void action( bool mailto
, bool check
, const QString
&to
, const QString
&cc
,
325 const QString
&bcc
, const QString
&subj
, const QString
&body
,
326 const KUrl
&messageFile
, const KUrl::List
&attach
,
327 const QStringList
&customHeaders
);
329 bool isImapFolder( const Akonadi::Collection
& ) const;
331 const KComponentData
&xmlGuiInstance() { return mXmlGuiInstance
; }
332 void setXmlGuiInstance( const KComponentData
&instance
) { mXmlGuiInstance
= instance
; }
334 UndoStack
*undoStack() { return the_undoStack
; }
335 MailCommon::FilterManager
*filterManager() const { return the_filterMgr
; }
336 MailCommon::FilterActionDict
*filterActionDict() const { return the_filterActionDict
; }
337 MessageSender
*msgSender();
339 /*reimp*/ void openFilterDialog(bool createDummyFilter
= true);
340 /*reimp*/ void createFilter(const QByteArray
& field
, const QString
& value
);
342 /** return the pointer to the identity manager */
343 /*reimp*/ KPIMIdentities::IdentityManager
*identityManager();
345 /*reimp*/ MailCommon::JobScheduler
* jobScheduler() const { return mJobScheduler
; }
347 /** Expire all folders, used for the gui action */
348 void expireAllFoldersNow();
350 int wrapCol() const { return mWrapCol
;}
352 bool firstStart() const { return the_firstStart
; }
353 /** Mark first start as done */
354 void firstStartDone() { the_firstStart
= false; }
355 QString
previousVersion() const { return the_previousVersion
; }
356 bool startingUp() const { return the_startingUp
; }
357 void setStartingUp (bool flag
) { the_startingUp
= flag
; }
358 bool shuttingDown() const { return the_shuttingDown
; }
359 void setShuttingDown(bool flag
) { the_shuttingDown
= flag
; }
361 /** Returns the full path of the user's local data directory for KMail.
362 The path ends with '/'.
364 static QString
localDataPath();
366 /** Returns true if we have a system tray applet. This is needed in order
367 * to know whether the application should be allowed to exit in case the
368 * last visible composer or separate message window is closed.
370 bool haveSystemTrayApplet();
372 bool registerSystemTrayApplet( KMSystemTray
* );
373 bool unregisterSystemTrayApplet( KMSystemTray
* );
375 QTextCodec
*networkCodec() { return netCodec
; }
377 /** returns a reference to the first Mainwin or a temporary Mainwin */
378 KMainWindow
* mainWin();
380 /** Get first mainwidget */
381 KMMainWidget
*getKMMainWidget();
384 * Returns a list of all currently loaded folders. Since folders are loaded async, this
385 * is empty at startup.
387 Akonadi::Collection::List
allFolders() const;
389 void selectCollectionFromId( const Akonadi::Collection::Id id
);
393 void stopAgentInstance();
396 /*reimp*/ bool showPopupAfterDnD();
398 /*reimp*/ bool excludeImportantMailFromExpiry();
400 /*reimp*/ qreal
closeToQuotaThreshold();
402 /*reimp*/ Akonadi::Collection::Id
lastSelectedFolder();
403 /*reimp*/ void setLastSelectedFolder( const Akonadi::Collection::Id
&col
);
405 /*reimp*/ QStringList
customTemplates();
407 void checkFolderFromResources( const Akonadi::Collection::Id
& collectionId
);
411 /*reimp*/ void updateSystemTray();
413 /** Custom templates have changed, so all windows using them need
414 to regenerate their menus */
415 void updatedTemplates();
417 /// Save contents of all open composer widnows to ~/dead.letter
418 void dumpDeadLetters();
420 /** Call this slot instead of directly KConfig::sync() to
421 minimize the overall config writes. Calling this slot will
422 schedule a sync of the application config file using a timer, so
423 that many consecutive calls can be condensed into a single
424 sync, which is more efficient. */
425 void slotRequestConfigSync();
428 * Sync the config immediatley
430 void slotSyncConfig();
432 void slotShowConfigurationDialog();
433 void slotRunBackgroundTasks();
435 void slotConfigChanged();
436 void slotCollectionMoved( const Akonadi::Collection
&collection
, const Akonadi::Collection
&source
, const Akonadi::Collection
&destination
);
439 void configChanged();
440 void onlineStatusChanged( GlobalSettings::EnumNetworkState::type
);
441 void customTemplatesChanged();
443 void startCheckMail();
448 /** Updates identities when a transport has been deleted. */
449 void transportRemoved( int id
, const QString
&name
);
450 /** Updates identities when a transport has been renamed. */
451 void transportRenamed( int id
, const QString
&oldName
, const QString
&newName
);
452 void itemDispatchStarted();
453 void instanceStatusChanged( Akonadi::AgentInstance
);
455 void akonadiStateChanged( Akonadi::ServerManager::State
);
456 void slotProgressItemCompletedOrCanceled( KPIM::ProgressItem
* item
);
458 void migrateFromKMail1();
459 void openReader( bool onlyCheck
);
460 QSharedPointer
<MailCommon::FolderCollection
> currentFolderCollection();
462 UndoStack
*the_undoStack
;
463 MailCommon::FilterManager
*the_filterMgr
;
464 MailCommon::FilterActionDict
*the_filterActionDict
;
465 mutable KPIMIdentities::IdentityManager
*mIdentityManager
;
466 AkonadiSender
*the_msgSender
;
467 /** previous KMail version. If different from current,
468 the user has just updated. read from config */
469 QString the_previousVersion
;
470 /** is this the first start? read from config */
472 /** are we starting up? set in main.cpp directly before kapp->exec() */
474 /** are we going down? set from here */
475 bool the_shuttingDown
;
476 /** true unles kmail is closed by session management */
478 bool the_firstInstance
;
480 KSharedConfig::Ptr mConfig
;
481 QTextCodec
*netCodec
;
482 KComponentData mXmlGuiInstance
;
483 ConfigureDialog
*mConfigureDialog
;
485 QTimer
*mBackgroundTasksTimer
;
486 MailCommon::JobScheduler
* mJobScheduler
;
489 MailServiceImpl
*mMailService
;
491 QList
<KMSystemTray
*> systemTrayApplets
;
493 MailCommon::FolderCollectionMonitor
*mFolderCollectionMonitor
;
494 Akonadi::EntityTreeModel
*mEntityTreeModel
;
495 Akonadi::EntityMimeTypeFilterModel
*mCollectionModel
;
497 /// List of Akonadi resources that are currently being checked.
498 QList
<QString
> mResourcesBeingChecked
;
502 QPointer
<KMFilterDlg
> mFilterEditDialog
;
505 #endif // _KMKERNEL_H