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 
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 
00200   QStringList folderList() const;
00201   DCOPRef getFolder( const QString& vpath );
00202   void selectFolder( QString folder );
00203   int timeOfLastMessageCountChange() const;
00204   virtual bool showMail( Q_UINT32 serialNumber, QString messageId );
00205   virtual QString getFrom( Q_UINT32 serialNumber );
00206   virtual QString debugScheduler();
00207   virtual QString debugSernum( Q_UINT32 serialNumber );
00208   int viewMessage( const KURL & messageFile );
00209 
00214   virtual void pauseBackgroundJobs();
00215 
00220   virtual void resumeBackgroundJobs();
00221 
00226   void stopNetworkJobs();
00227 
00232   void resumeNetworkJobs();
00233 
00239   static bool askToGoOnline();
00240 
00245   static bool isOffline();
00246 
00249   static KMKernel *self() { return mySelf; }
00250   static KConfig *config();
00251 
00252   void init();
00253   void readConfig();
00254   void cleanupImapFolders();
00255   void testDir(const char *_name);
00256   void recoverDeadLetters();
00257   void initFolders(KConfig* cfg);
00258   void closeAllKMailWindows();
00259   void cleanup(void);
00260   void quit();
00266   bool transferMail( QString & destinationDir );
00267   void ungrabPtrKb(void);
00268   void kmailMsgHandler(QtMsgType aType, const char* aMsg);
00269   bool doSessionManagement();
00270   bool firstInstance() { return the_firstInstance; }
00271   void setFirstInstance(bool value) { the_firstInstance = value; }
00272   void action (bool mailto, bool check, const QString &to, const QString &cc,
00273                const QString &bcc, const QString &subj, const QString &body,
00274                const KURL &messageFile, const KURL::List &attach,
00275                const QCStringList &customHeaders);
00276   void byteArrayToRemoteFile(const QByteArray&, const KURL&,
00277                  bool overwrite = FALSE);
00278   bool folderIsDraftOrOutbox( const KMFolder * );
00279   bool folderIsDrafts( const KMFolder * );
00280   bool folderIsTemplates( const KMFolder * );
00281   bool folderIsTrash( KMFolder * );
00285   bool folderIsSentMailFolder( const KMFolder * );
00289   KMFolder* findFolderById( const QString& idString );
00290 
00291   KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00292   void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00293 
00294   KMFolder *inboxFolder() { return the_inboxFolder; }
00295   KMFolder *outboxFolder() { return the_outboxFolder; }
00296   KMFolder *sentFolder() { return the_sentFolder; }
00297   KMFolder *trashFolder() { return the_trashFolder; }
00298   KMFolder *draftsFolder() { return the_draftsFolder; }
00299   KMFolder *templatesFolder() { return the_templatesFolder; }
00300 
00301   KMFolderMgr *folderMgr() { return the_folderMgr; }
00302   KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00303   KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00304   KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00305   UndoStack *undoStack() { return the_undoStack; }
00306   AccountManager *acctMgr() { return the_acctMgr; }
00307   KMFilterMgr *filterMgr() { return the_filterMgr; }
00308   KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00309   KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00310   KMail::MessageSender *msgSender();
00311   KMMsgIndex *msgIndex();
00312 
00313   KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00315   KPIM::IdentityManager *identityManager();
00316 
00317   JobScheduler* jobScheduler() { return mJobScheduler; }
00318 
00320   void compactAllFolders();
00322   void expireAllFoldersNow();
00323 
00324   KMailICalIfaceImpl& iCalIface();
00325 
00326   bool firstStart() { return the_firstStart; }
00327   QString previousVersion() { return the_previousVersion; }
00328   bool startingUp() { return the_startingUp; }
00329   void setStartingUp (bool flag) { the_startingUp = flag; }
00330   bool shuttingDown() { return the_shuttingDown; }
00331   void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00332   void serverReady (bool flag) { the_server_is_ready = flag; }
00333 
00337   static QString localDataPath();
00338 
00343   bool haveSystemTrayApplet();
00344 
00345   bool registerSystemTrayApplet( const KSystemTray* );
00346   bool unregisterSystemTrayApplet( const KSystemTray* );
00347 
00349   bool handleCommandLine( bool noArgsOpensReader );
00350   void emergencyExit( const QString& reason );
00351 
00353   unsigned long getNextMsgSerNum();
00354   QTextCodec *networkCodec() { return netCodec; }
00355 
00357   KMainWindow* mainWin();
00358 
00359   // ### The mContextMenuShown flag is necessary to work around bug# 56693
00360   // ### (kmail freeze with the complete desktop while pinentry-qt appears)
00361   // ### FIXME: Once the encryption support is asynchron this can be removed
00362   // ### again.
00363   void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00364   bool contextMenuShown() const { return mContextMenuShown; }
00365 
00370   ::KIMProxy* imProxy();
00371 
00376   bool mailCheckAborted() const;
00380   void enableMailCheck();
00386   void abortMailCheck();
00387 
00388   bool canQueryClose();
00389 
00393   void messageCountChanged();
00394 
00396   KWallet::Wallet *wallet();
00397 
00399   KMMainWidget *getKMMainWidget();
00400 
00402   QValueList< QGuardedPtr<KMFolder> > allFolders();
00403 
00404   void raise();
00405 
00406   void loadProfile( const QString& path );
00407 
00408   void saveToProfile( const QString& path ) const;
00409 public slots:
00410 
00412   void dumpDeadLetters();
00413 
00419   void slotRequestConfigSync();
00420 
00422   void slotEmptyTrash();
00423 
00424   void slotShowConfigurationDialog();
00425   void slotRunBackgroundTasks();
00426 
00427   void slotConfigChanged();
00428 
00429 protected slots:
00430   void slotDataReq(KIO::Job*,QByteArray&);
00431   void slotResult(KIO::Job*);
00432 
00433 signals:
00434   void configChanged();
00435   void folderRemoved( KMFolder* aFolder );
00436   void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00437 
00438 private:
00439   void openReader( bool onlyCheck );
00440   KMMsgStatus strToStatus(const QString &flags);
00441   KMFolder *currentFolder();
00442 
00443   KMFolder *the_inboxFolder;
00444   KMFolder *the_outboxFolder;
00445   KMFolder *the_sentFolder;
00446   KMFolder *the_trashFolder;
00447   KMFolder *the_draftsFolder;
00448   KMFolder *the_templatesFolder;
00449 
00450   KMFolderMgr *the_folderMgr;
00451   KMFolderMgr *the_imapFolderMgr;
00452   KMFolderMgr *the_dimapFolderMgr;
00453   KMFolderMgr *the_searchFolderMgr;
00454   UndoStack *the_undoStack;
00455   AccountManager *the_acctMgr;
00456   KMFilterMgr *the_filterMgr;
00457   KMFilterMgr *the_popFilterMgr;
00458   KMFilterActionDict *the_filterActionDict;
00459   mutable KPIM::IdentityManager *mIdentityManager;
00460   KMSender *the_msgSender;
00461   KMMsgIndex *the_msgIndex;
00462   struct putData
00463   {
00464     KURL url;
00465     QByteArray data;
00466     int offset;
00467   };
00468   QMap<KIO::Job *, putData> mPutJobs;
00471   QString the_previousVersion;
00473   bool the_firstStart;
00475   bool the_startingUp;
00477   bool the_shuttingDown;
00479   bool the_server_is_ready;
00481   bool closed_by_user;
00482   bool the_firstInstance;
00483   bool mMailCheckAborted;
00484   static KMKernel *mySelf;
00485   KSharedConfig::Ptr mConfig;
00486   QTextCodec *netCodec;
00487   KInstance* mXmlGuiInstance;
00488   ConfigureDialog *mConfigureDialog;
00489 
00490   QTimer *mBackgroundTasksTimer;
00491   KMailICalIfaceImpl* mICalIface;
00492   JobScheduler* mJobScheduler;
00493   // temporary mainwin
00494   KMMainWin *mWin;
00495   MailServiceImpl *mMailService;
00496 
00497   // the time of the last change of the unread or total count of a folder;
00498   // this can be queried via DCOP in order to determine whether the counts
00499   // need to be updated (e.g. in the Summary in Kontact)
00500   int mTimeOfLastMessageCountChange;
00501 
00502   // true if the context menu of KMFolderTree or KMHeaders is shown
00503   // this is necessary to know in order to prevent a dead lock between the
00504   // context menus and the pinentry program
00505   bool mContextMenuShown;
00506 
00507   QValueList<const KSystemTray*> systemTrayApplets;
00508 
00509   /* Weaver */
00510   KPIM::ThreadWeaver::Weaver *the_weaver;
00511   KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00512 
00513   KWallet::Wallet *mWallet;
00514 
00515   // variables used by dcopAddMessage()
00516   QStringList mAddMessageMsgIds;
00517   QString     mAddMessageLastFolder;
00518   KMFolder    *mAddMsgCurrentFolder;
00519 };
00520 
00521 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys