00001
00002
00003 #ifndef _KMCONTROL
00004 #define _KMCONTROL
00005
00006 #include <qobject.h>
00007 #include <qstring.h>
00008 #include <qguardedptr.h>
00009 #include <weaver.h>
00010 #include <weaverlogger.h>
00011
00012 #include <kconfig.h>
00013 #include <kdeversion.h>
00014 #include <kimproxy.h>
00015 #include <kdepimmacros.h>
00016
00017 #include "kmailIface.h"
00018 #include "kmmsgbase.h"
00019 #include "globalsettings.h"
00020
00021 #define kmkernel KMKernel::self()
00022 #define kmconfig KMKernel::config()
00023
00024 namespace KIO {
00025 class Job;
00026 }
00027 namespace KWallet {
00028 class Wallet;
00029 }
00030
00035 namespace KMail {
00036 class MailServiceImpl;
00037 class UndoStack;
00038 class JobScheduler;
00039 class MessageSender;
00040 class AccountManager;
00041 }
00042 namespace KPIM { class ProgressDialog; }
00043 using KMail::MailServiceImpl;
00044 using KMail::AccountManager;
00045 using KMail::UndoStack;
00046 using KMail::JobScheduler;
00047 using KPIM::ProgressDialog;
00048 class KMMsgIndex;
00049 class QLabel;
00050 class KMFolder;
00051 class KMFolderMgr;
00052 class KMFilterMgr;
00053 class KMFilterActionDict;
00054 class KMSender;
00055 namespace KPIM {
00056 class Identity;
00057 class IdentityManager;
00058 }
00059 class KMKernel;
00060 class KProcess;
00061 class KProgressDialog;
00062 class KInstance;
00063 class QTimer;
00064 class KProgress;
00065 class KPassivePopup;
00066 class KMMainWin;
00067 class KMainWindow;
00068 class KMailICalIfaceImpl;
00069 class KMReaderWin;
00070 class KSystemTray;
00071 class KMMainWidget;
00072 class ConfigureDialog;
00073
00083 class KDE_EXPORT KMKernel : public QObject, virtual public KMailIface
00084 {
00085 Q_OBJECT
00086
00087 public:
00088 KMKernel (QObject *parent=0, const char *name=0);
00089 ~KMKernel ();
00090
00093 void checkMail ();
00094 QStringList accounts();
00095 void checkAccount (const QString &account);
00097 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00098 const QString &subject, const QString &body, int hidden,
00099 const KURL &messageFile, const KURL::List &attachURLs,
00100 const QCStringList &customHeaders);
00102 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00103 const QString &subject, const QString &body, int hidden,
00104 const KURL &messageFile, const KURL::List &attachURLs)
00105 {
00106 QCStringList noCustomHeaders;
00107 return openComposer(to, cc, bcc, subject, body, hidden, messageFile, attachURLs, noCustomHeaders);
00108 }
00110 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00111 const QString &subject, const QString &body, int hidden,
00112 const KURL &messageFile, const KURL& attachURL)
00113 {
00114 return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List(attachURL));
00115 }
00117 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00118 const QString &subject, const QString &body, int hidden,
00119 const KURL &messageFile)
00120 {
00121 return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List());
00122 }
00126 int openComposer (const QString &to, const QString &cc,
00127 const QString &bcc, const QString &subject,
00128 const QString &body, int hidden,
00129 const QString &attachName,
00130 const QCString &attachCte,
00131 const QCString &attachData,
00132 const QCString &attachType,
00133 const QCString &attachSubType,
00134 const QCString &attachParamAttr,
00135 const QString &attachParamValue,
00136 const QCString &attachContDisp);
00137
00138 int openComposer (const QString &to, const QString &cc,
00139 const QString &bcc, const QString &subject,
00140 const QString &body, int hidden,
00141 const QString &attachName,
00142 const QCString &attachCte,
00143 const QCString &attachData,
00144 const QCString &attachType,
00145 const QCString &attachSubType,
00146 const QCString &attachParamAttr,
00147 const QString &attachParamValue,
00148 const QCString &attachContDisp,
00149 const QCString &attachCharset);
00150
00151 DCOPRef openComposer(const QString &to, const QString &cc,
00152 const QString &bcc, const QString &subject,
00153 const QString &body,bool hidden);
00154
00157 void setDefaultTransport( const QString & transport );
00158
00160 DCOPRef newMessage(const QString &to,
00161 const QString &cc,
00162 const QString &bcc,
00163 bool hidden,
00164 bool useFolderId,
00165 const KURL &messageFile,
00166 const KURL &attachURL);
00167
00168 int sendCertificate( const QString& to, const QByteArray& certData );
00169
00170 void openReader() { openReader( false ); }
00171
00172 int dcopAddMessage(const QString & foldername, const QString & messagefile,
00173 const QString & MsgStatusFlags = QString());
00174 int dcopAddMessage(const QString & foldername, const KURL & messagefile,
00175 const QString & MsgStatusFlags = QString());
00176 void dcopResetAddMessage();
00178 int dcopAddMessage_fastImport(const QString & foldername, const QString & messagefile,
00179 const QString & MsgStatusFlags = QString());
00180 int dcopAddMessage_fastImport(const QString & foldername, const KURL & messagefile,
00181 const QString & MsgStatusFlags = QString());
00182
00183 QStringList folderList() const;
00184 DCOPRef getFolder( const QString& vpath );
00185 void selectFolder( QString folder );
00186 int timeOfLastMessageCountChange() const;
00187 virtual bool showMail( Q_UINT32 serialNumber, QString messageId );
00188 virtual QString getFrom( Q_UINT32 serialNumber );
00189 virtual QString debugScheduler();
00190 virtual QString debugSernum( Q_UINT32 serialNumber );
00191 int viewMessage( const KURL & messageFile );
00192
00197 virtual void pauseBackgroundJobs();
00198
00203 virtual void resumeBackgroundJobs();
00204
00209 void stopNetworkJobs();
00210
00215 void resumeNetworkJobs();
00216
00222 static bool askToGoOnline();
00223
00228 static bool isOffline();
00229
00232 static KMKernel *self() { return mySelf; }
00233 static KConfig *config();
00234
00235 void init();
00236 void readConfig();
00237 void cleanupImapFolders();
00238 void testDir(const char *_name);
00239 void recoverDeadLetters();
00240 void initFolders(KConfig* cfg, bool _firstMessage = false);
00241 void closeAllKMailWindows();
00242 void cleanup(void);
00243 void quit();
00249 bool transferMail( QString & destinationDir );
00250 void ungrabPtrKb(void);
00251 void kmailMsgHandler(QtMsgType aType, const char* aMsg);
00252 bool doSessionManagement();
00253 bool firstInstance() { return the_firstInstance; }
00254 void setFirstInstance(bool value) { the_firstInstance = value; }
00255 void action (bool mailto, bool check, const QString &to, const QString &cc,
00256 const QString &bcc, const QString &subj, const QString &body,
00257 const KURL &messageFile, const KURL::List &attach,
00258 const QCStringList &customHeaders);
00259 void byteArrayToRemoteFile(const QByteArray&, const KURL&,
00260 bool overwrite = FALSE);
00261 bool folderIsDraftOrOutbox( const KMFolder * );
00262 bool folderIsDrafts( const KMFolder * );
00263 bool folderIsTemplates( const KMFolder * );
00264 bool folderIsTrash( KMFolder * );
00268 bool folderIsSentMailFolder( const KMFolder * );
00272 KMFolder* findFolderById( const QString& idString );
00273
00274 KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00275 void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00276
00277 KMFolder *inboxFolder() { return the_inboxFolder; }
00278 KMFolder *outboxFolder() { return the_outboxFolder; }
00279 KMFolder *sentFolder() { return the_sentFolder; }
00280 KMFolder *trashFolder() { return the_trashFolder; }
00281 KMFolder *draftsFolder() { return the_draftsFolder; }
00282 KMFolder *templatesFolder() { return the_templatesFolder; }
00283
00284 KMFolderMgr *folderMgr() { return the_folderMgr; }
00285 KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00286 KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00287 KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00288 UndoStack *undoStack() { return the_undoStack; }
00289 AccountManager *acctMgr() { return the_acctMgr; }
00290 KMFilterMgr *filterMgr() { return the_filterMgr; }
00291 KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00292 KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00293 KMail::MessageSender *msgSender();
00294 KMMsgIndex *msgIndex();
00295
00296 KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00298 KPIM::IdentityManager *identityManager();
00299 QString firstMessage();
00300 JobScheduler* jobScheduler() { return mJobScheduler; }
00301
00303 void compactAllFolders();
00305 void expireAllFoldersNow();
00306
00307 KMailICalIfaceImpl& iCalIface();
00308
00309 bool firstStart() { return the_firstStart; }
00310 QString previousVersion() { return the_previousVersion; }
00311 bool startingUp() { return the_startingUp; }
00312 void setStartingUp (bool flag) { the_startingUp = flag; }
00313 bool shuttingDown() { return the_shuttingDown; }
00314 void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00315 void serverReady (bool flag) { the_server_is_ready = flag; }
00316
00320 static QString localDataPath();
00321
00326 bool haveSystemTrayApplet();
00327
00328 bool registerSystemTrayApplet( const KSystemTray* );
00329 bool unregisterSystemTrayApplet( const KSystemTray* );
00330
00332 bool handleCommandLine( bool noArgsOpensReader );
00333 void emergencyExit( const QString& reason );
00334
00336 unsigned long getNextMsgSerNum();
00337 QTextCodec *networkCodec() { return netCodec; }
00338
00340 KMainWindow* mainWin();
00341
00342
00343
00344
00345
00346 void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00347 bool contextMenuShown() const { return mContextMenuShown; }
00348
00353 ::KIMProxy* imProxy();
00354
00359 bool mailCheckAborted() const;
00363 void enableMailCheck();
00369 void abortMailCheck();
00370
00371 bool canQueryClose();
00372
00376 void messageCountChanged();
00377
00379 KWallet::Wallet *wallet();
00380
00382 KMMainWidget *getKMMainWidget();
00383
00385 QValueList< QGuardedPtr<KMFolder> > allFolders();
00386
00387 void raise();
00388
00389 public slots:
00390
00392 void dumpDeadLetters();
00393
00399 void slotRequestConfigSync();
00400
00402 void slotEmptyTrash();
00403
00404 void slotShowConfigurationDialog();
00405 void slotRunBackgroundTasks();
00406
00407 void slotConfigChanged();
00408
00409 protected slots:
00410 void slotDataReq(KIO::Job*,QByteArray&);
00411 void slotResult(KIO::Job*);
00412
00413 signals:
00414 void configChanged();
00415 void folderRemoved( KMFolder* aFolder );
00416 void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00417
00418 private:
00419 void openReader( bool onlyCheck );
00420 KMMsgStatus strToStatus(const QString &flags);
00421 KMFolder *currentFolder();
00422
00423 KMFolder *the_inboxFolder;
00424 KMFolder *the_outboxFolder;
00425 KMFolder *the_sentFolder;
00426 KMFolder *the_trashFolder;
00427 KMFolder *the_draftsFolder;
00428 KMFolder *the_templatesFolder;
00429
00430 KMFolderMgr *the_folderMgr;
00431 KMFolderMgr *the_imapFolderMgr;
00432 KMFolderMgr *the_dimapFolderMgr;
00433 KMFolderMgr *the_searchFolderMgr;
00434 UndoStack *the_undoStack;
00435 AccountManager *the_acctMgr;
00436 KMFilterMgr *the_filterMgr;
00437 KMFilterMgr *the_popFilterMgr;
00438 KMFilterActionDict *the_filterActionDict;
00439 mutable KPIM::IdentityManager *mIdentityManager;
00440 KMSender *the_msgSender;
00441 KMMsgIndex *the_msgIndex;
00442 struct putData
00443 {
00444 KURL url;
00445 QByteArray data;
00446 int offset;
00447 };
00448 QMap<KIO::Job *, putData> mPutJobs;
00451 QString the_previousVersion;
00453 bool the_firstStart;
00455 bool the_startingUp;
00457 bool the_shuttingDown;
00459 bool the_server_is_ready;
00461 bool closed_by_user;
00462 bool the_firstInstance;
00463 bool mMailCheckAborted;
00464 static KMKernel *mySelf;
00465 KSharedConfig::Ptr mConfig;
00466 QTextCodec *netCodec;
00467 KInstance* mXmlGuiInstance;
00468 ConfigureDialog *mConfigureDialog;
00469
00470 QTimer *mBackgroundTasksTimer;
00471 KMailICalIfaceImpl* mICalIface;
00472 JobScheduler* mJobScheduler;
00473
00474 KMMainWin *mWin;
00475 MailServiceImpl *mMailService;
00476
00477
00478
00479
00480 int mTimeOfLastMessageCountChange;
00481
00482
00483
00484
00485 bool mContextMenuShown;
00486
00487 QValueList<const KSystemTray*> systemTrayApplets;
00488
00489
00490 KPIM::ThreadWeaver::Weaver *the_weaver;
00491 KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00492
00493 KWallet::Wallet *mWallet;
00494
00495
00496 QStringList mAddMessageMsgIds;
00497 QString mAddMessageLastFolder;
00498 KMFolder *mAddMsgCurrentFolder;
00499 };
00500
00501 #endif