kmail

kmkernel.h

00001 // -*- mode: C++; c-file-style: "gnu" -*-
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);
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 folderIsTrash(KMFolder *);
00267   bool folderIsSentMailFolder( const KMFolder * );
00271   KMFolder* findFolderById( const QString& idString );
00272 
00273   KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00274   void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00275 
00276   KMFolder *inboxFolder() { return the_inboxFolder; }
00277   KMFolder *outboxFolder() { return the_outboxFolder; }
00278   KMFolder *sentFolder() { return the_sentFolder; }
00279   KMFolder *trashFolder() { return the_trashFolder; }
00280   KMFolder *draftsFolder() { return the_draftsFolder; }
00281 
00282   KMFolderMgr *folderMgr() { return the_folderMgr; }
00283   KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00284   KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00285   KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00286   UndoStack *undoStack() { return the_undoStack; }
00287   AccountManager *acctMgr() { return the_acctMgr; }
00288   KMFilterMgr *filterMgr() { return the_filterMgr; }
00289   KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00290   KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00291   KMail::MessageSender *msgSender();
00292   KMMsgIndex *msgIndex();
00293 
00294   KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00296   KPIM::IdentityManager *identityManager();
00297 
00298   JobScheduler* jobScheduler() { return mJobScheduler; }
00299 
00301   void compactAllFolders();
00303   void expireAllFoldersNow();
00304 
00305   KMailICalIfaceImpl& iCalIface();
00306 
00307   bool firstStart() { return the_firstStart; }
00308   QString previousVersion() { return the_previousVersion; }
00309   bool startingUp() { return the_startingUp; }
00310   void setStartingUp (bool flag) { the_startingUp = flag; }
00311   bool shuttingDown() { return the_shuttingDown; }
00312   void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00313   void serverReady (bool flag) { the_server_is_ready = flag; }
00314 
00318   static QString localDataPath();
00319 
00324   bool haveSystemTrayApplet();
00325 
00326   bool registerSystemTrayApplet( const KSystemTray* );
00327   bool unregisterSystemTrayApplet( const KSystemTray* );
00328 
00330   bool handleCommandLine( bool noArgsOpensReader );
00331   void emergencyExit( const QString& reason );
00332 
00334   unsigned long getNextMsgSerNum();
00335   QTextCodec *networkCodec() { return netCodec; }
00336 
00338   KMainWindow* mainWin();
00339 
00340   // ### The mContextMenuShown flag is necessary to work around bug# 56693
00341   // ### (kmail freeze with the complete desktop while pinentry-qt appears)
00342   // ### FIXME: Once the encryption support is asynchron this can be removed
00343   // ### again.
00344   void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00345   bool contextMenuShown() const { return mContextMenuShown; }
00346 
00351   ::KIMProxy* imProxy();
00352 
00357   bool mailCheckAborted() const;
00361   void enableMailCheck();
00367   void abortMailCheck();
00368 
00369   bool canQueryClose();
00370 
00374   void messageCountChanged();
00375 
00377   KWallet::Wallet *wallet();
00378 
00380   KMMainWidget *getKMMainWidget();
00381 
00383   QValueList< QGuardedPtr<KMFolder> > allFolders();
00384 
00385   void raise();
00386 
00387 public slots:
00388 
00390   void dumpDeadLetters();
00391 
00397   void slotRequestConfigSync();
00398 
00400   void slotEmptyTrash();
00401 
00402   void slotShowConfigurationDialog();
00403   void slotRunBackgroundTasks();
00404   
00405   void slotConfigChanged();
00406 
00407 protected slots:
00408   void slotDataReq(KIO::Job*,QByteArray&);
00409   void slotResult(KIO::Job*);
00410 
00411 signals:
00412   void configChanged();
00413   void folderRemoved( KMFolder* aFolder );
00414   void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00415 
00416 private:
00417   void openReader( bool onlyCheck );
00418   KMMsgStatus strToStatus(const QString &flags);
00419   KMFolder *currentFolder();
00420 
00421   KMFolder *the_inboxFolder;
00422   KMFolder *the_outboxFolder;
00423   KMFolder *the_sentFolder;
00424   KMFolder *the_trashFolder;
00425   KMFolder *the_draftsFolder;
00426 
00427   KMFolderMgr *the_folderMgr;
00428   KMFolderMgr *the_imapFolderMgr;
00429   KMFolderMgr *the_dimapFolderMgr;
00430   KMFolderMgr *the_searchFolderMgr;
00431   UndoStack *the_undoStack;
00432   AccountManager *the_acctMgr;
00433   KMFilterMgr *the_filterMgr;
00434   KMFilterMgr *the_popFilterMgr;
00435   KMFilterActionDict *the_filterActionDict;
00436   mutable KPIM::IdentityManager *mIdentityManager;
00437   KMSender *the_msgSender;
00438   KMMsgIndex *the_msgIndex;
00439   struct putData
00440   {
00441     KURL url;
00442     QByteArray data;
00443     int offset;
00444   };
00445   QMap<KIO::Job *, putData> mPutJobs;
00448   QString the_previousVersion;
00450   bool the_firstStart;
00452   bool the_startingUp;
00454   bool the_shuttingDown;
00456   bool the_server_is_ready;
00458   bool closed_by_user;
00459   bool the_firstInstance;
00460   bool mMailCheckAborted;
00461   static KMKernel *mySelf;
00462   KSharedConfig::Ptr mConfig;
00463   QTextCodec *netCodec;
00464   KInstance* mXmlGuiInstance;
00465   ConfigureDialog *mConfigureDialog;
00466 
00467   QTimer *mBackgroundTasksTimer;
00468   KMailICalIfaceImpl* mICalIface;
00469   JobScheduler* mJobScheduler;
00470   // temporary mainwin
00471   KMMainWin *mWin;
00472   MailServiceImpl *mMailService;
00473 
00474   // the time of the last change of the unread or total count of a folder;
00475   // this can be queried via DCOP in order to determine whether the counts
00476   // need to be updated (e.g. in the Summary in Kontact)
00477   int mTimeOfLastMessageCountChange;
00478 
00479   // true if the context menu of KMFolderTree or KMHeaders is shown
00480   // this is necessary to know in order to prevent a dead lock between the
00481   // context menus and the pinentry program
00482   bool mContextMenuShown;
00483 
00484   QValueList<const KSystemTray*> systemTrayApplets;
00485 
00486   /* Weaver */
00487   KPIM::ThreadWeaver::Weaver *the_weaver;
00488   KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00489 
00490   KWallet::Wallet *mWallet;
00491 
00492   // variables used by dcopAddMessage()
00493   QStringList mAddMessageMsgIds;
00494   QString     mAddMessageLastFolder;
00495   KMFolder    *mAddMsgCurrentFolder;
00496 };
00497 
00498 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys