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);
00101 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00102 const QString &subject, const QString &body, int hidden,
00103 const KURL &messageFile, const KURL& attachURL)
00104 {
00105 return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List(attachURL));
00106 }
00108 int openComposer (const QString &to, const QString &cc, const QString &bcc,
00109 const QString &subject, const QString &body, int hidden,
00110 const KURL &messageFile)
00111 {
00112 return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List());
00113 }
00117 int openComposer (const QString &to, const QString &cc,
00118 const QString &bcc, const QString &subject,
00119 const QString &body, int hidden,
00120 const QString &attachName,
00121 const QCString &attachCte,
00122 const QCString &attachData,
00123 const QCString &attachType,
00124 const QCString &attachSubType,
00125 const QCString &attachParamAttr,
00126 const QString &attachParamValue,
00127 const QCString &attachContDisp);
00128
00129 int openComposer (const QString &to, const QString &cc,
00130 const QString &bcc, const QString &subject,
00131 const QString &body, int hidden,
00132 const QString &attachName,
00133 const QCString &attachCte,
00134 const QCString &attachData,
00135 const QCString &attachType,
00136 const QCString &attachSubType,
00137 const QCString &attachParamAttr,
00138 const QString &attachParamValue,
00139 const QCString &attachContDisp,
00140 const QCString &attachCharset);
00141
00142 DCOPRef openComposer(const QString &to, const QString &cc,
00143 const QString &bcc, const QString &subject,
00144 const QString &body,bool hidden);
00145
00148 void setDefaultTransport( const QString & transport );
00149
00151 DCOPRef newMessage(const QString &to,
00152 const QString &cc,
00153 const QString &bcc,
00154 bool hidden,
00155 bool useFolderId,
00156 const KURL &messageFile,
00157 const KURL &attachURL);
00158
00159 int sendCertificate( const QString& to, const QByteArray& certData );
00160
00161 void openReader() { openReader( false ); }
00162
00163 int dcopAddMessage(const QString & foldername, const QString & messagefile,
00164 const QString & MsgStatusFlags = QString());
00165 int dcopAddMessage(const QString & foldername, const KURL & messagefile,
00166 const QString & MsgStatusFlags = QString());
00167 void dcopResetAddMessage();
00169 int dcopAddMessage_fastImport(const QString & foldername, const QString & messagefile,
00170 const QString & MsgStatusFlags = QString());
00171 int dcopAddMessage_fastImport(const QString & foldername, const KURL & messagefile,
00172 const QString & MsgStatusFlags = QString());
00173
00174 QStringList folderList() const;
00175 DCOPRef getFolder( const QString& vpath );
00176 void selectFolder( QString folder );
00177 int timeOfLastMessageCountChange() const;
00178 virtual bool showMail( Q_UINT32 serialNumber, QString messageId );
00179 virtual QString getFrom( Q_UINT32 serialNumber );
00180 virtual QString debugScheduler();
00181 virtual QString debugSernum( Q_UINT32 serialNumber );
00182 int viewMessage( const KURL & messageFile );
00183
00188 virtual void pauseBackgroundJobs();
00189
00194 virtual void resumeBackgroundJobs();
00195
00200 void stopNetworkJobs();
00201
00206 void resumeNetworkJobs();
00207
00213 static bool askToGoOnline();
00214
00219 static bool isOffline();
00220
00223 static KMKernel *self() { return mySelf; }
00224 static KConfig *config();
00225
00226 void init();
00227 void readConfig();
00228 void cleanupImapFolders();
00229 void testDir(const char *_name);
00230 void recoverDeadLetters();
00231 void initFolders(KConfig* cfg);
00232 void closeAllKMailWindows();
00233 void cleanup(void);
00234 void quit();
00240 bool transferMail( QString & destinationDir );
00241 void ungrabPtrKb(void);
00242 void kmailMsgHandler(QtMsgType aType, const char* aMsg);
00243 bool doSessionManagement();
00244 bool firstInstance() { return the_firstInstance; }
00245 void setFirstInstance(bool value) { the_firstInstance = value; }
00246 void action (bool mailto, bool check, const QString &to, const QString &cc,
00247 const QString &bcc, const QString &subj, const QString &body,
00248 const KURL &messageFile, const KURL::List &attach);
00249 void byteArrayToRemoteFile(const QByteArray&, const KURL&,
00250 bool overwrite = FALSE);
00251 bool folderIsDraftOrOutbox(const KMFolder *);
00252 bool folderIsDrafts(const KMFolder *);
00253 bool folderIsTrash(KMFolder *);
00257 bool folderIsSentMailFolder( const KMFolder * );
00261 KMFolder* findFolderById( const QString& idString );
00262
00263 KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00264 void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00265
00266 KMFolder *inboxFolder() { return the_inboxFolder; }
00267 KMFolder *outboxFolder() { return the_outboxFolder; }
00268 KMFolder *sentFolder() { return the_sentFolder; }
00269 KMFolder *trashFolder() { return the_trashFolder; }
00270 KMFolder *draftsFolder() { return the_draftsFolder; }
00271
00272 KMFolderMgr *folderMgr() { return the_folderMgr; }
00273 KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00274 KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00275 KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00276 UndoStack *undoStack() { return the_undoStack; }
00277 AccountManager *acctMgr() { return the_acctMgr; }
00278 KMFilterMgr *filterMgr() { return the_filterMgr; }
00279 KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00280 KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00281 KMail::MessageSender *msgSender();
00282 KMMsgIndex *msgIndex();
00283
00284 KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00286 KPIM::IdentityManager *identityManager();
00287
00288 JobScheduler* jobScheduler() { return mJobScheduler; }
00289
00291 void compactAllFolders();
00293 void expireAllFoldersNow();
00294
00295 KMailICalIfaceImpl& iCalIface();
00296
00297 bool firstStart() { return the_firstStart; }
00298 QString previousVersion() { return the_previousVersion; }
00299 bool startingUp() { return the_startingUp; }
00300 void setStartingUp (bool flag) { the_startingUp = flag; }
00301 bool shuttingDown() { return the_shuttingDown; }
00302 void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00303 void serverReady (bool flag) { the_server_is_ready = flag; }
00304
00308 static QString localDataPath();
00309
00314 bool haveSystemTrayApplet();
00315
00316 bool registerSystemTrayApplet( const KSystemTray* );
00317 bool unregisterSystemTrayApplet( const KSystemTray* );
00318
00320 bool handleCommandLine( bool noArgsOpensReader );
00321 void emergencyExit( const QString& reason );
00322
00324 unsigned long getNextMsgSerNum();
00325 QTextCodec *networkCodec() { return netCodec; }
00326
00328 KMainWindow* mainWin();
00329
00330
00331
00332
00333
00334 void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00335 bool contextMenuShown() const { return mContextMenuShown; }
00336
00341 ::KIMProxy* imProxy();
00342
00347 bool mailCheckAborted() const;
00351 void enableMailCheck();
00357 void abortMailCheck();
00358
00359 bool canQueryClose();
00360
00364 void messageCountChanged();
00365
00367 KWallet::Wallet *wallet();
00368
00370 KMMainWidget *getKMMainWidget();
00371
00373 QValueList< QGuardedPtr<KMFolder> > allFolders();
00374
00375 void raise();
00376
00377 public slots:
00378
00380 void dumpDeadLetters();
00381
00387 void slotRequestConfigSync();
00388
00390 void slotEmptyTrash();
00391
00392 void slotShowConfigurationDialog();
00393 void slotRunBackgroundTasks();
00394
00395 void slotConfigChanged();
00396
00397 protected slots:
00398 void slotDataReq(KIO::Job*,QByteArray&);
00399 void slotResult(KIO::Job*);
00400
00401 signals:
00402 void configChanged();
00403 void folderRemoved( KMFolder* aFolder );
00404 void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00405
00406 private:
00407 void openReader( bool onlyCheck );
00408 KMMsgStatus strToStatus(const QString &flags);
00409 KMFolder *currentFolder();
00410
00411 KMFolder *the_inboxFolder;
00412 KMFolder *the_outboxFolder;
00413 KMFolder *the_sentFolder;
00414 KMFolder *the_trashFolder;
00415 KMFolder *the_draftsFolder;
00416
00417 KMFolderMgr *the_folderMgr;
00418 KMFolderMgr *the_imapFolderMgr;
00419 KMFolderMgr *the_dimapFolderMgr;
00420 KMFolderMgr *the_searchFolderMgr;
00421 UndoStack *the_undoStack;
00422 AccountManager *the_acctMgr;
00423 KMFilterMgr *the_filterMgr;
00424 KMFilterMgr *the_popFilterMgr;
00425 KMFilterActionDict *the_filterActionDict;
00426 mutable KPIM::IdentityManager *mIdentityManager;
00427 KMSender *the_msgSender;
00428 KMMsgIndex *the_msgIndex;
00429 struct putData
00430 {
00431 KURL url;
00432 QByteArray data;
00433 int offset;
00434 };
00435 QMap<KIO::Job *, putData> mPutJobs;
00438 QString the_previousVersion;
00440 bool the_firstStart;
00442 bool the_startingUp;
00444 bool the_shuttingDown;
00446 bool the_server_is_ready;
00448 bool closed_by_user;
00449 bool the_firstInstance;
00450 bool mMailCheckAborted;
00451 static KMKernel *mySelf;
00452 KSharedConfig::Ptr mConfig;
00453 QTextCodec *netCodec;
00454 KInstance* mXmlGuiInstance;
00455 ConfigureDialog *mConfigureDialog;
00456
00457 QTimer *mBackgroundTasksTimer;
00458 KMailICalIfaceImpl* mICalIface;
00459 JobScheduler* mJobScheduler;
00460
00461 KMMainWin *mWin;
00462 MailServiceImpl *mMailService;
00463
00464
00465
00466
00467 int mTimeOfLastMessageCountChange;
00468
00469
00470
00471
00472 bool mContextMenuShown;
00473
00474 QValueList<const KSystemTray*> systemTrayApplets;
00475
00476
00477 KPIM::ThreadWeaver::Weaver *the_weaver;
00478 KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00479
00480 KWallet::Wallet *mWallet;
00481
00482
00483 QStringList mAddMessageMsgIds;
00484 QString mAddMessageLastFolder;
00485 KMFolder *mAddMsgCurrentFolder;
00486 };
00487
00488 #endif