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
00141 int openComposer (const QString &to, const QString &cc,
00142 const QString &bcc, const QString &subject,
00143 const QString &body, int hidden,
00144 const QString &attachName,
00145 const QCString &attachCte,
00146 const QCString &attachData,
00147 const QCString &attachType,
00148 const QCString &attachSubType,
00149 const QCString &attachParamAttr,
00150 const QString &attachParamValue,
00151 const QCString &attachContDisp,
00152 const QCString &attachCharset);
00153
00154 int openComposer (const QString &to, const QString &cc,
00155 const QString &bcc, const QString &subject,
00156 const QString &body, int hidden,
00157 const QString &attachName,
00158 const QCString &attachCte,
00159 const QCString &attachData,
00160 const QCString &attachType,
00161 const QCString &attachSubType,
00162 const QCString &attachParamAttr,
00163 const QString &attachParamValue,
00164 const QCString &attachContDisp,
00165 const QCString &attachCharset,
00166 unsigned int identity);
00167
00168 DCOPRef openComposer(const QString &to, const QString &cc,
00169 const QString &bcc, const QString &subject,
00170 const QString &body,bool hidden);
00171
00174 void setDefaultTransport( const QString & transport );
00175
00177 DCOPRef newMessage(const QString &to,
00178 const QString &cc,
00179 const QString &bcc,
00180 bool hidden,
00181 bool useFolderId,
00182 const KURL &messageFile,
00183 const KURL &attachURL);
00184
00185 int sendCertificate( const QString& to, const QByteArray& certData );
00186
00187 void openReader() { openReader( false ); }
00188
00189 int dcopAddMessage(const QString & foldername, const QString & messagefile,
00190 const QString & MsgStatusFlags = QString());
00191 int dcopAddMessage(const QString & foldername, const KURL & messagefile,
00192 const QString & MsgStatusFlags = QString());
00193 void dcopResetAddMessage();
00195 int dcopAddMessage_fastImport(const QString & foldername, const QString & messagefile,
00196 const QString & MsgStatusFlags = QString());
00197 int dcopAddMessage_fastImport(const QString & foldername, const KURL & messagefile,
00198 const QString & MsgStatusFlags = QString());
00199 void showImportArchiveDialog();
00200
00201 QStringList folderList() const;
00202 DCOPRef getFolder( const QString& vpath );
00203 void selectFolder( QString folder );
00204 int timeOfLastMessageCountChange() const;
00205 virtual bool showMail( Q_UINT32 serialNumber, QString messageId );
00206 virtual QString getFrom( Q_UINT32 serialNumber );
00207 virtual QString debugScheduler();
00208 virtual QString debugSernum( Q_UINT32 serialNumber );
00209 int viewMessage( const KURL & messageFile );
00210
00215 virtual void pauseBackgroundJobs();
00216
00221 virtual void resumeBackgroundJobs();
00222
00227 void stopNetworkJobs();
00228
00233 void resumeNetworkJobs();
00234
00240 static bool askToGoOnline();
00241
00246 static bool isOffline();
00247
00250 static KMKernel *self() { return mySelf; }
00251 static KConfig *config();
00252
00253 void init();
00254 void readConfig();
00255 void cleanupImapFolders();
00256 void testDir(const char *_name);
00257 void recoverDeadLetters();
00258 void initFolders(KConfig* cfg);
00259 void closeAllKMailWindows();
00260 void cleanup(void);
00261 void quit();
00267 bool transferMail( QString & destinationDir );
00268 void ungrabPtrKb(void);
00269 void kmailMsgHandler(QtMsgType aType, const char* aMsg);
00270 bool doSessionManagement();
00271 bool firstInstance() { return the_firstInstance; }
00272 void setFirstInstance(bool value) { the_firstInstance = value; }
00273 void action (bool mailto, bool check, const QString &to, const QString &cc,
00274 const QString &bcc, const QString &subj, const QString &body,
00275 const KURL &messageFile, const KURL::List &attach,
00276 const QCStringList &customHeaders);
00277 void byteArrayToRemoteFile(const QByteArray&, const KURL&,
00278 bool overwrite = FALSE);
00279 bool folderIsDraftOrOutbox( const KMFolder * );
00280 bool folderIsDrafts( const KMFolder * );
00281 bool folderIsTemplates( const KMFolder * );
00282 bool folderIsTrash( KMFolder * );
00286 bool folderIsSentMailFolder( const KMFolder * );
00290 KMFolder* findFolderById( const QString& idString );
00291
00292 KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00293 void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00294
00295 KMFolder *inboxFolder() { return the_inboxFolder; }
00296 KMFolder *outboxFolder() { return the_outboxFolder; }
00297 KMFolder *sentFolder() { return the_sentFolder; }
00298 KMFolder *trashFolder() { return the_trashFolder; }
00299 KMFolder *draftsFolder() { return the_draftsFolder; }
00300 KMFolder *templatesFolder() { return the_templatesFolder; }
00301
00302 KMFolderMgr *folderMgr() { return the_folderMgr; }
00303 KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00304 KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00305 KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00306 UndoStack *undoStack() { return the_undoStack; }
00307 AccountManager *acctMgr() { return the_acctMgr; }
00308 KMFilterMgr *filterMgr() { return the_filterMgr; }
00309 KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00310 KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00311 KMail::MessageSender *msgSender();
00312 KMMsgIndex *msgIndex();
00313
00314 KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00316 KPIM::IdentityManager *identityManager();
00317
00318 JobScheduler* jobScheduler() { return mJobScheduler; }
00319
00321 void compactAllFolders();
00323 void expireAllFoldersNow();
00324
00325 KMailICalIfaceImpl& iCalIface();
00326
00327 bool firstStart() { return the_firstStart; }
00328 QString previousVersion() { return the_previousVersion; }
00329 bool startingUp() { return the_startingUp; }
00330 void setStartingUp (bool flag) { the_startingUp = flag; }
00331 bool shuttingDown() { return the_shuttingDown; }
00332 void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00333 void serverReady (bool flag) { the_server_is_ready = flag; }
00334
00338 static QString localDataPath();
00339
00344 bool haveSystemTrayApplet();
00345
00346 bool registerSystemTrayApplet( const KSystemTray* );
00347 bool unregisterSystemTrayApplet( const KSystemTray* );
00348
00350 bool handleCommandLine( bool noArgsOpensReader );
00351 void emergencyExit( const QString& reason );
00352
00354 unsigned long getNextMsgSerNum();
00355 QTextCodec *networkCodec() { return netCodec; }
00356
00358 KMainWindow* mainWin();
00359
00360
00361
00362
00363
00364 void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00365 bool contextMenuShown() const { return mContextMenuShown; }
00366
00371 ::KIMProxy* imProxy();
00372
00377 bool mailCheckAborted() const;
00381 void enableMailCheck();
00387 void abortMailCheck();
00388
00389 bool canQueryClose();
00390
00394 void messageCountChanged();
00395
00397 KWallet::Wallet *wallet();
00398
00400 KMMainWidget *getKMMainWidget();
00401
00403 QValueList< QGuardedPtr<KMFolder> > allFolders();
00404
00405 void raise();
00406
00407 void loadProfile( const QString& path );
00408
00409 void saveToProfile( const QString& path ) const;
00410 public slots:
00411
00413 void dumpDeadLetters();
00414
00420 void slotRequestConfigSync();
00421
00423 void slotEmptyTrash();
00424
00425 void slotShowConfigurationDialog();
00426 void slotRunBackgroundTasks();
00427
00428 void slotConfigChanged();
00429
00430 protected slots:
00431 void slotDataReq(KIO::Job*,QByteArray&);
00432 void slotResult(KIO::Job*);
00433
00434 signals:
00435 void configChanged();
00436 void folderRemoved( KMFolder* aFolder );
00437 void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00438
00439 private:
00440 void openReader( bool onlyCheck );
00441 KMMsgStatus strToStatus(const QString &flags);
00442 KMFolder *currentFolder();
00443
00444 KMFolder *the_inboxFolder;
00445 KMFolder *the_outboxFolder;
00446 KMFolder *the_sentFolder;
00447 KMFolder *the_trashFolder;
00448 KMFolder *the_draftsFolder;
00449 KMFolder *the_templatesFolder;
00450
00451 KMFolderMgr *the_folderMgr;
00452 KMFolderMgr *the_imapFolderMgr;
00453 KMFolderMgr *the_dimapFolderMgr;
00454 KMFolderMgr *the_searchFolderMgr;
00455 UndoStack *the_undoStack;
00456 AccountManager *the_acctMgr;
00457 KMFilterMgr *the_filterMgr;
00458 KMFilterMgr *the_popFilterMgr;
00459 KMFilterActionDict *the_filterActionDict;
00460 mutable KPIM::IdentityManager *mIdentityManager;
00461 KMSender *the_msgSender;
00462 KMMsgIndex *the_msgIndex;
00463 struct putData
00464 {
00465 KURL url;
00466 QByteArray data;
00467 int offset;
00468 };
00469 QMap<KIO::Job *, putData> mPutJobs;
00472 QString the_previousVersion;
00474 bool the_firstStart;
00476 bool the_startingUp;
00478 bool the_shuttingDown;
00480 bool the_server_is_ready;
00482 bool closed_by_user;
00483 bool the_firstInstance;
00484 bool mMailCheckAborted;
00485 static KMKernel *mySelf;
00486 KSharedConfig::Ptr mConfig;
00487 QTextCodec *netCodec;
00488 KInstance* mXmlGuiInstance;
00489 ConfigureDialog *mConfigureDialog;
00490
00491 QTimer *mBackgroundTasksTimer;
00492 KMailICalIfaceImpl* mICalIface;
00493 JobScheduler* mJobScheduler;
00494
00495 KMMainWin *mWin;
00496 MailServiceImpl *mMailService;
00497
00498
00499
00500
00501 int mTimeOfLastMessageCountChange;
00502
00503
00504
00505
00506 bool mContextMenuShown;
00507
00508 QValueList<const KSystemTray*> systemTrayApplets;
00509
00510
00511 KPIM::ThreadWeaver::Weaver *the_weaver;
00512 KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00513
00514 KWallet::Wallet *mWallet;
00515
00516
00517 QStringList mAddMessageMsgIds;
00518 QString mAddMessageLastFolder;
00519 KMFolder *mAddMsgCurrentFolder;
00520 };
00521
00522 #endif