kmail

kmkernel.h

00001 // -*- mode: C++; c-file-style: "gnu" -*-
00002 
00003 #ifndef _KMCONTROL
00004 #define _KMCONTROL
00005 
00006 #include <tqobject.h>
00007 #include <tqstring.h>
00008 #include <tqguardedptr.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 TQLabel;
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 TQTimer;
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 TQObject, virtual public KMailIface
00084 {
00085   Q_OBJECT
00086 
00087 public:
00088   KMKernel (TQObject *parent=0, const char *name=0);
00089   ~KMKernel ();
00090 
00093   void checkMail ();
00094   TQStringList accounts();
00095   void checkAccount (const TQString &account);
00097   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00098                     const TQString &subject, const TQString &body, int hidden,
00099                     const KURL &messageFile, const KURL::List &attachURLs,
00100                     const QCStringList &customHeaders);
00102   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00103                     const TQString &subject, const TQString &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 TQString &to, const TQString &cc, const TQString &bcc,
00111                     const TQString &subject, const TQString &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 TQString &to, const TQString &cc, const TQString &bcc,
00118                     const TQString &subject, const TQString &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 TQString &to, const TQString &cc,
00127                     const TQString &bcc, const TQString &subject,
00128                     const TQString &body, int hidden,
00129                     const TQString &attachName,
00130                     const TQCString &attachCte,
00131                     const TQCString &attachData,
00132                     const TQCString &attachType,
00133                     const TQCString &attachSubType,
00134                     const TQCString &attachParamAttr,
00135                     const TQString &attachParamValue,
00136                     const TQCString &attachContDisp);
00137 
00141   int openComposer (const TQString &to, const TQString &cc,
00142                     const TQString &bcc, const TQString &subject,
00143                     const TQString &body, int hidden,
00144                     const TQString &attachName,
00145                     const TQCString &attachCte,
00146                     const TQCString &attachData,
00147                     const TQCString &attachType,
00148                     const TQCString &attachSubType,
00149                     const TQCString &attachParamAttr,
00150                     const TQString &attachParamValue,
00151                     const TQCString &attachContDisp,
00152                     const TQCString &attachCharset);
00153 
00154   int openComposer (const TQString &to, const TQString &cc,
00155                     const TQString &bcc, const TQString &subject,
00156                     const TQString &body, int hidden,
00157                     const TQString &attachName,
00158                     const TQCString &attachCte,
00159                     const TQCString &attachData,
00160                     const TQCString &attachType,
00161                     const TQCString &attachSubType,
00162                     const TQCString &attachParamAttr,
00163                     const TQString &attachParamValue,
00164                     const TQCString &attachContDisp,
00165                     const TQCString &attachCharset,
00166                     unsigned int identity);
00167 
00168   DCOPRef openComposer(const TQString &to, const TQString &cc,
00169                        const TQString &bcc, const TQString &subject,
00170                        const TQString &body,bool hidden);
00171 
00174   void setDefaultTransport( const TQString & transport );
00175 
00177   DCOPRef newMessage(const TQString &to,
00178                      const TQString &cc,
00179                      const TQString &bcc,
00180                      bool hidden,
00181                      bool useFolderId,
00182                      const KURL &messageFile,
00183                      const KURL &attachURL);
00184 
00185   int sendCertificate( const TQString& to, const TQByteArray& certData );
00186 
00187   void openReader() { openReader( false ); }
00188 
00189   int dcopAddMessage(const TQString & foldername, const TQString & messagefile,
00190                      const TQString & MsgStatusFlags = TQString());
00191   int dcopAddMessage(const TQString & foldername, const KURL & messagefile,
00192                      const TQString & MsgStatusFlags = TQString());
00193   void dcopResetAddMessage();
00195   int dcopAddMessage_fastImport(const TQString & foldername, const TQString & messagefile,
00196                                 const TQString & MsgStatusFlags = TQString());
00197   int dcopAddMessage_fastImport(const TQString & foldername, const KURL & messagefile,
00198                                 const TQString & MsgStatusFlags = TQString());
00199   void showImportArchiveDialog();
00200 
00201   TQStringList folderList() const;
00202   DCOPRef getFolder( const TQString& vpath );
00203   void selectFolder( TQString folder );
00204   int timeOfLastMessageCountChange() const;
00205   virtual bool showMail( Q_UINT32 serialNumber, TQString messageId );
00206   virtual TQString getFrom( Q_UINT32 serialNumber );
00207   virtual TQString debugScheduler();
00208   virtual TQString 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 recreateCorruptIndexFiles();
00257   void testDir(const char *_name);
00258   void recoverDeadLetters();
00259   void initFolders(KConfig* cfg);
00260   void closeAllKMailWindows();
00261   void cleanup(void);
00262   void quit();
00268   bool transferMail( TQString & destinationDir );
00269   void ungrabPtrKb(void);
00270   void kmailMsgHandler(QtMsgType aType, const char* aMsg);
00271   bool doSessionManagement();
00272   bool firstInstance() { return the_firstInstance; }
00273   void setFirstInstance(bool value) { the_firstInstance = value; }
00274   void action (bool mailto, bool check, const TQString &to, const TQString &cc,
00275                const TQString &bcc, const TQString &subj, const TQString &body,
00276                const KURL &messageFile, const KURL::List &attach,
00277                const QCStringList &customHeaders);
00278   void byteArrayToRemoteFile(const TQByteArray&, const KURL&,
00279                  bool overwrite = FALSE);
00280   bool folderIsDraftOrOutbox( const KMFolder * );
00281   bool folderIsDrafts( const KMFolder * );
00282   bool folderIsTemplates( const KMFolder * );
00283   bool folderIsTrash( KMFolder * );
00287   bool folderIsSentMailFolder( const KMFolder * );
00291   KMFolder* findFolderById( const TQString& idString );
00292 
00293   KInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00294   void setXmlGuiInstance( KInstance *instance ) { mXmlGuiInstance = instance; }
00295 
00296   KMFolder *inboxFolder() { return the_inboxFolder; }
00297   KMFolder *outboxFolder() { return the_outboxFolder; }
00298   KMFolder *sentFolder() { return the_sentFolder; }
00299   KMFolder *trashFolder() { return the_trashFolder; }
00300   KMFolder *draftsFolder() { return the_draftsFolder; }
00301   KMFolder *templatesFolder() { return the_templatesFolder; }
00302 
00303   KMFolderMgr *folderMgr() { return the_folderMgr; }
00304   KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00305   KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00306   KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00307   UndoStack *undoStack() { return the_undoStack; }
00308   AccountManager *acctMgr() { return the_acctMgr; }
00309   KMFilterMgr *filterMgr() { return the_filterMgr; }
00310   KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00311   KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00312   KMail::MessageSender *msgSender();
00313   KMMsgIndex *msgIndex();
00314 
00315   KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00317   KPIM::IdentityManager *identityManager();
00318 
00319   JobScheduler* jobScheduler() { return mJobScheduler; }
00320 
00322   void compactAllFolders();
00324   void expireAllFoldersNow();
00325 
00326   KMailICalIfaceImpl& iCalIface();
00327 
00328   bool firstStart() { return the_firstStart; }
00329   TQString previousVersion() { return the_previousVersion; }
00330   bool startingUp() { return the_startingUp; }
00331   void setStartingUp (bool flag) { the_startingUp = flag; }
00332   bool shuttingDown() { return the_shuttingDown; }
00333   void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00334   void serverReady (bool flag) { the_server_is_ready = flag; }
00335 
00339   static TQString localDataPath();
00340 
00345   bool haveSystemTrayApplet();
00346 
00347   bool registerSystemTrayApplet( const KSystemTray* );
00348   bool unregisterSystemTrayApplet( const KSystemTray* );
00349 
00351   bool handleCommandLine( bool noArgsOpensReader );
00352   void emergencyExit( const TQString& reason );
00353 
00355   unsigned long getNextMsgSerNum();
00356   TQTextCodec *networkCodec() { return netCodec; }
00357 
00359   KMainWindow* mainWin();
00360 
00361   // ### The mContextMenuShown flag is necessary to work around bug# 56693
00362   // ### (kmail freeze with the complete desktop while pinentry-qt appears)
00363   // ### FIXME: Once the encryption support is asynchron this can be removed
00364   // ### again.
00365   void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00366   bool contextMenuShown() const { return mContextMenuShown; }
00367 
00372   ::KIMProxy* imProxy();
00373 
00378   bool mailCheckAborted() const;
00382   void enableMailCheck();
00388   void abortMailCheck();
00389 
00390   bool canQueryClose();
00391 
00395   void messageCountChanged();
00396 
00398   KWallet::Wallet *wallet();
00399 
00401   KMMainWidget *getKMMainWidget();
00402 
00404   TQValueList< TQGuardedPtr<KMFolder> > allFolders();
00405 
00406   void raise();
00407 
00408   void loadProfile( const TQString& path );
00409 
00410   void saveToProfile( const TQString& path ) const;
00411 
00412   bool isCodecAsciiCompatible( const TQTextCodec *codec );
00413 public slots:
00414 
00416   void dumpDeadLetters();
00417 
00423   void slotRequestConfigSync();
00424 
00426   void slotEmptyTrash();
00427 
00428   void slotShowConfigurationDialog();
00429   void slotRunBackgroundTasks();
00430 
00431   void slotConfigChanged();
00432 
00433 protected slots:
00434   void slotDataReq(KIO::Job*,TQByteArray&);
00435   void slotResult(KIO::Job*);
00436 
00437 signals:
00438   void configChanged();
00439   void folderRemoved( KMFolder* aFolder );
00440   void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00441 
00442 private:
00443   void openReader( bool onlyCheck );
00444   KMMsgStatus strToStatus(const TQString &flags);
00445   KMFolder *currentFolder();
00446 
00447   KMFolder *the_inboxFolder;
00448   KMFolder *the_outboxFolder;
00449   KMFolder *the_sentFolder;
00450   KMFolder *the_trashFolder;
00451   KMFolder *the_draftsFolder;
00452   KMFolder *the_templatesFolder;
00453 
00454   KMFolderMgr *the_folderMgr;
00455   KMFolderMgr *the_imapFolderMgr;
00456   KMFolderMgr *the_dimapFolderMgr;
00457   KMFolderMgr *the_searchFolderMgr;
00458   UndoStack *the_undoStack;
00459   AccountManager *the_acctMgr;
00460   KMFilterMgr *the_filterMgr;
00461   KMFilterMgr *the_popFilterMgr;
00462   KMFilterActionDict *the_filterActionDict;
00463   mutable KPIM::IdentityManager *mIdentityManager;
00464   KMSender *the_msgSender;
00465   KMMsgIndex *the_msgIndex;
00466   struct putData
00467   {
00468     KURL url;
00469     TQByteArray data;
00470     int offset;
00471   };
00472   TQMap<KIO::Job *, putData> mPutJobs;
00475   TQString the_previousVersion;
00477   bool the_firstStart;
00479   bool the_startingUp;
00481   bool the_shuttingDown;
00483   bool the_server_is_ready;
00485   bool closed_by_user;
00486   bool the_firstInstance;
00487   bool mMailCheckAborted;
00488   static KMKernel *mySelf;
00489   KSharedConfig::Ptr mConfig;
00490   TQTextCodec *netCodec;
00491   KInstance* mXmlGuiInstance;
00492   ConfigureDialog *mConfigureDialog;
00493 
00494   TQTimer *mBackgroundTasksTimer;
00495   KMailICalIfaceImpl* mICalIface;
00496   JobScheduler* mJobScheduler;
00497   // temporary mainwin
00498   KMMainWin *mWin;
00499   MailServiceImpl *mMailService;
00500 
00501   // the time of the last change of the unread or total count of a folder;
00502   // this can be queried via DCOP in order to determine whether the counts
00503   // need to be updated (e.g. in the Summary in Kontact)
00504   int mTimeOfLastMessageCountChange;
00505 
00506   // true if the context menu of KMFolderTree or KMHeaders is shown
00507   // this is necessary to know in order to prevent a dead lock between the
00508   // context menus and the pinentry program
00509   bool mContextMenuShown;
00510 
00511   TQValueList<const KSystemTray*> systemTrayApplets;
00512   TQValueList<const TQTextCodec*> mNonAsciiCompatibleCodecs;
00513 
00514   /* Weaver */
00515   KPIM::ThreadWeaver::Weaver *the_weaver;
00516   KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00517 
00518   KWallet::Wallet *mWallet;
00519 
00520   // variables used by dcopAddMessage()
00521   TQStringList mAddMessageMsgIds;
00522   TQString     mAddMessageLastFolder;
00523   KMFolder    *mAddMsgCurrentFolder;
00524 };
00525 
00526 #endif