fix errors found while translating
[kdepim.git] / kmail / kmkernel.h
blob1c48d791f109ed5f85a8c755e0495d3b9a6538bc
1 // -*- mode: C++; c-file-style: "gnu" -*-
3 #ifndef _KMKERNEL_H
4 #define _KMKERNEL_H
6 #include <QByteArray>
7 #include <QList>
8 #include <QObject>
9 #include <QString>
10 #include <QPointer>
11 #include <QDBusObjectPath>
12 #include <threadweaver/ThreadWeaver.h>
14 #include <kconfig.h>
15 #include <kurl.h>
17 #include "kmail_export.h"
18 #include "kmmsgbase.h"
19 #include "kmmessagetag.h"
20 #include "globalsettings.h"
21 #include <kcomponentdata.h>
23 #define kmkernel KMKernel::self()
24 #define kmconfig KMKernel::config()
26 namespace KIO {
27 class Job;
29 namespace KWallet {
30 class Wallet;
33 class KJob;
34 /** The KMail namespace contains classes used for KMail.
35 * This is to keep them out of the way from all the other
36 * un-namespaced classes in libs and the rest of PIM.
38 namespace KMail {
39 class MailServiceImpl;
40 class UndoStack;
41 class JobScheduler;
42 class MessageSender;
43 class AccountManager;
44 class FolderAdaptor;
46 namespace KPIM { class ProgressDialog; }
47 using KMail::MailServiceImpl;
48 using KMail::AccountManager;
49 using KMail::UndoStack;
50 using KMail::JobScheduler;
51 using KPIM::ProgressDialog;
52 class QLabel;
53 class KMFolder;
54 class KMFolderMgr;
55 class KMFilterMgr;
56 class KMFilterActionDict;
57 class KMSender;
58 namespace KPIMIdentities {
59 class Identity;
60 class IdentityManager;
62 class KMKernel;
63 class KComponentData;
64 class QTimer;
65 class KMMainWin;
66 class KMainWindow;
67 class KMailICalIfaceImpl;
68 class KSystemTrayIcon;
69 class KMMainWidget;
70 class ConfigureDialog;
71 class KMMessageTagMgr;
73 /**
74 * @short Central point of coordination in KMail
76 * The KMKernel class represents the core of KMail, where the different parts
77 * come together and are coordinated. It is currently also the class which exports
78 * KMail's main D-BUS interfaces. The kernel is responsible for creating various
79 * (singleton) objects such as the UndoStack, the folder managers and filter
80 * manager, etc.
82 class KMAIL_EXPORT KMKernel : public QObject
84 Q_OBJECT
85 Q_CLASSINFO("D-Bus Interface", "org.kde.kmail.kmail")
87 public:
88 explicit KMKernel (QObject *parent=0, const char *name=0);
89 ~KMKernel ();
91 /**
92 * Start of D-Bus callable stuff. The D-Bus methods need to be public slots,
93 * otherwise they can't be accessed.
95 public Q_SLOTS:
97 Q_SCRIPTABLE void checkMail();
98 Q_SCRIPTABLE void openReader() { openReader( false ); }
101 * Compact all folders, used for the GUI action (and from D-Bus)
103 Q_SCRIPTABLE void compactAllFolders();
106 * Pauses all background jobs and does not
107 * allow new background jobs to be started.
109 Q_SCRIPTABLE void pauseBackgroundJobs();
112 * Resumes all background jobs and allows
113 * new jobs to be started.
115 Q_SCRIPTABLE void resumeBackgroundJobs();
118 * Stops all network related jobs and enter offline mode
119 * New network jobs cannot be started.
121 Q_SCRIPTABLE void stopNetworkJobs();
124 * Resumes all network related jobs and enter online mode
125 * New network jobs can be started.
127 Q_SCRIPTABLE void resumeNetworkJobs();
129 Q_SCRIPTABLE QStringList folderList() const;
131 Q_SCRIPTABLE QStringList accounts();
134 * Checks the account with the specified name for new mail.
135 * If the account name is empty, all accounts not excluded from manual
136 * mail check will be checked.
138 Q_SCRIPTABLE void checkAccount( const QString & account );
140 Q_SCRIPTABLE void selectFolder( const QString & folder );
142 Q_SCRIPTABLE QString getFolder( const QString & vpath );
144 Q_SCRIPTABLE bool canQueryClose();
147 * D-Bus call used to set the default transport.
149 Q_SCRIPTABLE void setDefaultTransport( const QString & transport );
151 Q_SCRIPTABLE int timeOfLastMessageCountChange() const;
153 Q_SCRIPTABLE int dbusAddMessage( const QString & foldername,
154 const QString & messageFile,
155 const QString & MsgStatusFlags = QString() );
158 * Add messages without rejecting duplicates
160 Q_SCRIPTABLE int dbusAddMessage_fastImport( const QString & foldername,
161 const QString & messageFile,
162 const QString & MsgStatusFlags = QString() );
164 Q_SCRIPTABLE void dbusResetAddMessage();
166 Q_SCRIPTABLE int sendCertificate( const QString & to,
167 const QByteArray & certData );
169 Q_SCRIPTABLE bool handleCommandLine( bool noArgsOpensReader );
171 Q_SCRIPTABLE QString debugScheduler();
174 * returns id of composer if more are opened
176 Q_SCRIPTABLE int openComposer( const QString & to,
177 const QString & cc,
178 const QString & bcc,
179 const QString & subject,
180 const QString & body,
181 bool hidden,
182 const QString & messageFile,
183 const QStringList & attachmentPaths,
184 const QStringList & customHeaders );
186 Q_SCRIPTABLE int openComposer( const QString & to,
187 const QString & cc,
188 const QString & bcc,
189 const QString & subject,
190 const QString & body,
191 bool hidden,
192 const QString & attachName,
193 const QByteArray & attachCte,
194 const QByteArray &attachData,
195 const QByteArray & attachType,
196 const QByteArray & attachSubType,
197 const QByteArray & attachParamAttr,
198 const QString & attachParamValue,
199 const QByteArray & attachContDisp,
200 const QByteArray & attachCharset,
201 unsigned int identity );
203 Q_SCRIPTABLE QDBusObjectPath openComposer( const QString & to,
204 const QString & cc,
205 const QString & bcc,
206 const QString & subject,
207 const QString & body,
208 bool hidden );
211 * D-Bus call used by the Kontact plugin to create a new message.
213 Q_SCRIPTABLE QDBusObjectPath newMessage( const QString & to,
214 const QString & cc,
215 const QString & bcc,
216 bool hidden,
217 bool useFolderId,
218 const QString & messageFile,
219 const QString & attachURL );
221 Q_SCRIPTABLE bool showMail( quint32 serialNumber, const QString & messageId );
223 Q_SCRIPTABLE QString getFrom( quint32 serialNumber );
225 Q_SCRIPTABLE QString debugSernum( quint32 serialNumber );
227 Q_SCRIPTABLE int viewMessage( const KUrl & messageFile );
229 Q_SIGNALS:
231 Q_SCRIPTABLE void unreadCountChanged();
234 * End of D-Bus callable stuff
238 public:
240 /** A static helper function that asks the user
241 * if they want to go online.
242 * @return true if the user wants to go online
243 * @return false if the user wants to stay offline
245 static bool askToGoOnline();
247 /** Checks if the current network state is online or offline
248 * @return true if the network state is offline
249 * @return false if the network state is online
251 static bool isOffline();
253 /** normal control stuff */
255 static KMKernel *self();
256 static KConfig *config();
258 void init();
259 void setupDBus();
260 void readConfig();
261 void cleanupImapFolders();
262 void testDir(const char *_name);
263 void recoverDeadLetters();
264 void initFolders(KConfig* cfg);
265 void closeAllKMailWindows();
266 void cleanup(void);
267 void quit();
269 * Returns true if the transfer was successful, otherwise false. In any case
270 * destinationDir contains the path to the current mail storage when the
271 * method returns.
273 bool transferMail( QString & destinationDir );
274 bool doSessionManagement();
275 bool firstInstance() { return the_firstInstance; }
276 void setFirstInstance(bool value) { the_firstInstance = value; }
277 void action( bool mailto, bool check, const QString &to, const QString &cc,
278 const QString &bcc, const QString &subj, const QString &body,
279 const KUrl &messageFile, const KUrl::List &attach,
280 const QStringList &customHeaders );
281 void byteArrayToRemoteFile( const QByteArray&, const KUrl&,
282 bool overwrite = false );
283 bool folderIsDraftOrOutbox(const KMFolder *);
284 bool folderIsDrafts(const KMFolder *);
285 bool folderIsTemplates(const KMFolder *);
286 bool folderIsTrash(KMFolder *);
288 * Returns true if the folder is one of the sent-mail folders.
290 bool folderIsSentMailFolder( const KMFolder * );
292 * Find a folder by ID string in all folder managers
294 KMFolder* findFolderById( const QString& idString );
296 const KComponentData &xmlGuiInstance() { return mXmlGuiInstance; }
297 void setXmlGuiInstance( const KComponentData &instance ) { mXmlGuiInstance = instance; }
299 KMFolder *inboxFolder() { return the_inboxFolder; }
300 KMFolder *outboxFolder() { return the_outboxFolder; }
301 KMFolder *sentFolder() { return the_sentFolder; }
302 KMFolder *trashFolder() { return the_trashFolder; }
303 KMFolder *draftsFolder() { return the_draftsFolder; }
304 KMFolder *templatesFolder() { return the_templatesFolder; }
306 KMFolderMgr *folderMgr() { return the_folderMgr; }
307 KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
308 KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
309 KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
310 UndoStack *undoStack() { return the_undoStack; }
311 AccountManager *acctMgr() { return the_acctMgr; }
312 KMFilterMgr *filterMgr() { return the_filterMgr; }
313 KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
314 KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
315 KMail::MessageSender *msgSender();
316 KMMessageTagMgr *msgTagMgr() { return the_msgTagMgr; }
318 ThreadWeaver::Weaver *weaver() { return the_weaver; }
319 /** return the pointer to the identity manager */
320 KPIMIdentities::IdentityManager *identityManager();
322 JobScheduler* jobScheduler() { return mJobScheduler; }
324 /** Expire all folders, used for the gui action */
325 void expireAllFoldersNow();
327 KMailICalIfaceImpl& iCalIface();
329 bool firstStart() const { return the_firstStart; }
330 /** Mark first start as done */
331 void firstStartDone() { the_firstStart = false; }
332 QString previousVersion() const { return the_previousVersion; }
333 bool startingUp() const { return the_startingUp; }
334 void setStartingUp (bool flag) { the_startingUp = flag; }
335 bool shuttingDown() const { return the_shuttingDown; }
336 void setShuttingDown(bool flag) { the_shuttingDown = flag; }
337 void serverReady (bool flag) { the_server_is_ready = flag; }
339 /** Returns the full path of the user's local data directory for KMail.
340 The path ends with '/'.
342 static QString localDataPath();
344 /** Returns true if we have a system tray applet. This is needed in order
345 * to know whether the application should be allowed to exit in case the
346 * last visible composer or separate message window is closed.
348 bool haveSystemTrayApplet();
350 bool registerSystemTrayApplet( const KSystemTrayIcon* );
351 bool unregisterSystemTrayApplet( const KSystemTrayIcon* );
353 /// Reimplemented from KMailIface
354 void emergencyExit( const QString& reason );
356 /** Returns a message serial number that hasn't been used yet. */
357 unsigned long getNextMsgSerNum();
358 QTextCodec *networkCodec() { return netCodec; }
360 /** returns a reference to the first Mainwin or a temporary Mainwin */
361 KMainWindow* mainWin();
363 // ### The mContextMenuShown flag is necessary to work around bug# 56693
364 // ### (kmail freeze with the complete desktop while pinentry-qt appears)
365 // ### FIXME: Once the encryption support is asynchron this can be removed
366 // ### again.
367 void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
368 bool contextMenuShown() const { return mContextMenuShown; }
371 * Returns true IFF the user has requested that the current mail checks
372 * should be aborted. Needs to be periodically polled.
374 bool mailCheckAborted() const;
375 /** Set the state of the abort requested variable to false,
376 * i.e. enable mail checking again
378 void enableMailCheck();
380 * Set the state of the abort requested variable to true,
381 * (to let the current jobs run, but stop when possible).
382 * This is used to cancel mail checks when closing the last mainwindow
384 void abortMailCheck();
387 * Called by the folder tree if the count of unread/total messages changed.
389 void messageCountChanged();
391 /** Open KDE wallet and set it to kmail folder */
392 KWallet::Wallet *wallet();
394 /** Get first mainwidget */
395 KMMainWidget *getKMMainWidget();
397 /** @return a list of all folders from all folder managers. */
398 QList< QPointer<KMFolder> > allFolders();
400 void raise();
402 /** Custom templates have changed, so all windows using them need
403 to regenerate their menus */
404 void updatedTemplates();
406 public slots:
408 /// Save contents of all open composer widnows to ~/dead.letter
409 void dumpDeadLetters();
411 /** Call this slot instead of directly KConfig::sync() to
412 minimize the overall config writes. Calling this slot will
413 schedule a sync of the application config file using a timer, so
414 that many consecutive calls can be condensed into a single
415 sync, which is more efficient. */
416 void slotRequestConfigSync();
418 /** empty all the trash bins */
419 void slotEmptyTrash();
421 void slotShowConfigurationDialog();
422 void slotRunBackgroundTasks();
424 void slotConfigChanged();
426 protected slots:
427 void slotDataReq(KIO::Job*,QByteArray&);
428 void slotResult(KJob*);
430 signals:
431 void configChanged();
432 void folderRemoved( KMFolder* aFolder );
433 void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
434 void customTemplatesChanged();
436 private slots:
437 /** Updates identities when a transport has been deleted. */
438 void transportRemoved( int id, const QString &name );
439 /** Updates identities when a transport has been renamed. */
440 void transportRenamed( int id, const QString &oldName, const QString &newName );
442 private:
443 void openReader( bool onlyCheck );
444 KMFolder *currentFolder();
446 KMFolder *the_inboxFolder;
447 KMFolder *the_outboxFolder;
448 KMFolder *the_sentFolder;
449 KMFolder *the_trashFolder;
450 KMFolder *the_draftsFolder;
451 KMFolder *the_templatesFolder;
453 KMFolderMgr *the_folderMgr;
454 KMFolderMgr *the_imapFolderMgr;
455 KMFolderMgr *the_dimapFolderMgr;
456 KMFolderMgr *the_searchFolderMgr;
457 UndoStack *the_undoStack;
458 AccountManager *the_acctMgr;
459 KMFilterMgr *the_filterMgr;
460 KMFilterMgr *the_popFilterMgr;
461 KMFilterActionDict *the_filterActionDict;
462 mutable KPIMIdentities::IdentityManager *mIdentityManager;
463 KMSender *the_msgSender;
464 KMMessageTagMgr *the_msgTagMgr;
465 struct putData
467 KUrl url;
468 QByteArray data;
469 int offset;
471 QMap<KIO::Job *, putData> mPutJobs;
472 /** previous KMail version. If different from current,
473 the user has just updated. read from config */
474 QString the_previousVersion;
475 /** is this the first start? read from config */
476 bool the_firstStart;
477 /** are we starting up? set in main.cpp directly before kapp->exec() */
478 bool the_startingUp;
479 /** are we going down? set from here */
480 bool the_shuttingDown;
481 /** are we in the middle of network operations (needed?) */
482 bool the_server_is_ready;
483 /** true unles kmail is closed by session management */
484 bool closed_by_user;
485 bool the_firstInstance;
486 bool mMailCheckAborted;
488 KSharedConfig::Ptr mConfig;
489 QTextCodec *netCodec;
490 KComponentData mXmlGuiInstance;
491 ConfigureDialog *mConfigureDialog;
493 QTimer *mBackgroundTasksTimer;
494 KMailICalIfaceImpl* mICalIface;
495 JobScheduler* mJobScheduler;
496 // temporary mainwin
497 KMMainWin *mWin;
498 MailServiceImpl *mMailService;
500 // the time of the last change of the unread or total count of a folder;
501 // this can be queried via D-Bus in order to determine whether the counts
502 // need to be updated (e.g. in the Summary in Kontact)
503 int mTimeOfLastMessageCountChange;
505 // true if the context menu of KMFolderTree or KMHeaders is shown
506 // this is necessary to know in order to prevent a dead lock between the
507 // context menus and the pinentry program
508 bool mContextMenuShown;
510 QList<const KSystemTrayIcon*> systemTrayApplets;
512 /* Weaver */
513 ThreadWeaver::Weaver *the_weaver;
515 KWallet::Wallet *mWallet;
517 // variables used by dbusAddMessage()
518 QStringList mAddMessageMsgIds;
519 QString mAddMessageLastFolder;
520 KMFolder *mAddMsgCurrentFolder;
521 KMail::FolderAdaptor *folderAdaptor;
524 #endif // _KMKERNEL_H