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 <kdemacros.h>
00013 #include <tdeconfig.h>
00014 #include <tdeversion.h>
00015 #include <tdeimproxy.h>
00016 #include <tdepimmacros.h>
00017 
00018 #ifdef __TDE_HAVE_TDEHWLIB
00019 # include <tdenetworkconnections.h>
00020 #else
00021 namespace TDENetworkConnectionStatus {
00022     enum TDENetworkConnectionStatus {
00023     };
00024 }
00025 #endif
00026 
00027 #include "kmailIface.h"
00028 #include "kmmsgbase.h"
00029 #include "globalsettings.h"
00030 
00031 #define kmkernel KMKernel::self()
00032 #define kmconfig KMKernel::config()
00033 
00034 namespace TDEIO {
00035   class Job;
00036 }
00037 namespace TDEWallet {
00038   class Wallet;
00039 }
00040 
00045 namespace KMail {
00046   class MailServiceImpl;
00047   class UndoStack;
00048   class JobScheduler;
00049   class MessageSender;
00050   class AccountManager;
00051 }
00052 namespace KPIM { class ProgressDialog; }
00053 using KMail::MailServiceImpl;
00054 using KMail::AccountManager;
00055 using KMail::UndoStack;
00056 using KMail::JobScheduler;
00057 using KPIM::ProgressDialog;
00058 class KMMsgIndex;
00059 class TQLabel;
00060 class KMFolder;
00061 class KMFolderMgr;
00062 class KMFilterMgr;
00063 class KMFilterActionDict;
00064 class KMSender;
00065 namespace KPIM {
00066   class Identity;
00067   class IdentityManager;
00068 }
00069 class KMKernel;
00070 class TDEProcess;
00071 class KProgressDialog;
00072 class TDEInstance;
00073 class TQTimer;
00074 class KProgress;
00075 class KPassivePopup;
00076 class KMMainWin;
00077 class TDEMainWindow;
00078 class KMailICalIfaceImpl;
00079 class KMReaderWin;
00080 class KSystemTray;
00081 class KMMainWidget;
00082 class ConfigureDialog;
00083 
00093 class KDE_EXPORT KMKernel : public TQObject, virtual public KMailIface
00094 {
00095   Q_OBJECT
00096   
00097 
00098 public:
00099   KMKernel (TQObject *parent=0, const char *name=0);
00100   ~KMKernel ();
00101 
00104   void checkMail ();
00105   TQStringList accounts();
00106   void checkAccount (const TQString &account);
00108   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00109                     const TQString &subject, const TQString &body, int hidden,
00110                     const KURL &messageFile, const KURL::List &attachURLs,
00111                     const QCStringList &customHeaders);
00113   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00114                     const TQString &subject, const TQString &body, int hidden,
00115                     const KURL &messageFile, const KURL::List &attachURLs)
00116   {
00117     QCStringList noCustomHeaders;
00118     return openComposer(to, cc, bcc, subject, body, hidden, messageFile, attachURLs, noCustomHeaders);
00119   }
00121   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00122                     const TQString &subject, const TQString &body, int hidden,
00123                     const KURL &messageFile, const KURL& attachURL)
00124   {
00125     return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List(attachURL));
00126   }
00128   int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
00129                     const TQString &subject, const TQString &body, int hidden,
00130                     const KURL &messageFile)
00131   {
00132     return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List());
00133   }
00137   int openComposer (const TQString &to, const TQString &cc,
00138                     const TQString &bcc, const TQString &subject,
00139                     const TQString &body, int hidden,
00140                     const TQString &attachName,
00141                     const TQCString &attachCte,
00142                     const TQCString &attachData,
00143                     const TQCString &attachType,
00144                     const TQCString &attachSubType,
00145                     const TQCString &attachParamAttr,
00146                     const TQString &attachParamValue,
00147                     const TQCString &attachContDisp);
00148 
00152   int openComposer (const TQString &to, const TQString &cc,
00153                     const TQString &bcc, const TQString &subject,
00154                     const TQString &body, int hidden,
00155                     const TQString &attachName,
00156                     const TQCString &attachCte,
00157                     const TQCString &attachData,
00158                     const TQCString &attachType,
00159                     const TQCString &attachSubType,
00160                     const TQCString &attachParamAttr,
00161                     const TQString &attachParamValue,
00162                     const TQCString &attachContDisp,
00163                     const TQCString &attachCharset);
00164 
00165   int openComposer (const TQString &to, const TQString &cc,
00166                     const TQString &bcc, const TQString &subject,
00167                     const TQString &body, int hidden,
00168                     const TQString &attachName,
00169                     const TQCString &attachCte,
00170                     const TQCString &attachData,
00171                     const TQCString &attachType,
00172                     const TQCString &attachSubType,
00173                     const TQCString &attachParamAttr,
00174                     const TQString &attachParamValue,
00175                     const TQCString &attachContDisp,
00176                     const TQCString &attachCharset,
00177                     unsigned int identity);
00178 
00179   DCOPRef openComposer(const TQString &to, const TQString &cc,
00180                        const TQString &bcc, const TQString &subject,
00181                        const TQString &body,bool hidden);
00182 
00185   void setDefaultTransport( const TQString & transport );
00186 
00188   DCOPRef newMessage(const TQString &to,
00189                      const TQString &cc,
00190                      const TQString &bcc,
00191                      bool hidden,
00192                      bool useFolderId,
00193                      const KURL &messageFile,
00194                      const KURL &attachURL);
00195 
00196   int sendCertificate( const TQString& to, const TQByteArray& certData );
00197 
00198   void openReader() { openReader( false ); }
00199 
00200   int dcopAddMessage(const TQString & foldername, const TQString & messagefile,
00201                      const TQString & MsgStatusFlags = TQString());
00202   int dcopAddMessage(const TQString & foldername, const KURL & messagefile,
00203                      const TQString & MsgStatusFlags = TQString());
00204   void dcopResetAddMessage();
00206   int dcopAddMessage_fastImport(const TQString & foldername, const TQString & messagefile,
00207                                 const TQString & MsgStatusFlags = TQString());
00208   int dcopAddMessage_fastImport(const TQString & foldername, const KURL & messagefile,
00209                                 const TQString & MsgStatusFlags = TQString());
00210   void showImportArchiveDialog();
00211 
00212   TQStringList folderList() const;
00213   DCOPRef getFolder( const TQString& vpath );
00214   void selectFolder( TQString folder );
00215   int timeOfLastMessageCountChange() const;
00216   virtual bool showMail( TQ_UINT32 serialNumber, TQString messageId );
00217   virtual TQString getFrom( TQ_UINT32 serialNumber );
00218   virtual TQString debugScheduler();
00219   virtual TQString debugSernum( TQ_UINT32 serialNumber );
00220   int viewMessage( const KURL & messageFile );
00221 
00226   virtual void pauseBackgroundJobs();
00227 
00232   virtual void resumeBackgroundJobs();
00233 
00238   void stopNetworkJobs();
00239 
00244   void resumeNetworkJobs();
00245 
00251   static bool askToGoOnline();
00252 
00257   static bool isOffline();
00258 
00261   static KMKernel *self() { return mySelf; }
00262   static TDEConfig *config();
00263 
00264   void init();
00265   void readConfig();
00266   void cleanupImapFolders();
00267   void recreateCorruptIndexFiles();
00268   void testDir(const char *_name);
00269   void recoverDeadLetters();
00270   void initFolders(TDEConfig* cfg);
00271   void closeAllKMailWindows();
00272   void cleanup(void);
00273   void quit();
00279   bool transferMail( TQString & destinationDir );
00280   void ungrabPtrKb(void);
00281   void kmailMsgHandler(TQtMsgType aType, const char* aMsg);
00282   bool doSessionManagement();
00283   bool firstInstance() { return the_firstInstance; }
00284   void setFirstInstance(bool value) { the_firstInstance = value; }
00285   void action (bool mailto, bool check, const TQString &to, const TQString &cc,
00286                const TQString &bcc, const TQString &subj, const TQString &body,
00287                const KURL &messageFile, const KURL::List &attach,
00288                const QCStringList &customHeaders);
00289   void byteArrayToRemoteFile(const TQByteArray&, const KURL&,
00290                  bool overwrite = FALSE);
00291   bool folderIsDraftOrOutbox( const KMFolder * );
00292   bool folderIsDrafts( const KMFolder * );
00293   bool folderIsTemplates( const KMFolder * );
00294   bool folderIsTrash( KMFolder * );
00298   bool folderIsSentMailFolder( const KMFolder * );
00302   KMFolder* findFolderById( const TQString& idString );
00303 
00304   TDEInstance *xmlGuiInstance() { return mXmlGuiInstance; }
00305   void setXmlGuiInstance( TDEInstance *instance ) { mXmlGuiInstance = instance; }
00306 
00307   KMFolder *inboxFolder() { return the_inboxFolder; }
00308   KMFolder *outboxFolder() { return the_outboxFolder; }
00309   KMFolder *sentFolder() { return the_sentFolder; }
00310   KMFolder *trashFolder() { return the_trashFolder; }
00311   KMFolder *draftsFolder() { return the_draftsFolder; }
00312   KMFolder *templatesFolder() { return the_templatesFolder; }
00313 
00314   KMFolderMgr *folderMgr() { return the_folderMgr; }
00315   KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
00316   KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
00317   KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
00318   UndoStack *undoStack() { return the_undoStack; }
00319   AccountManager *acctMgr() { return the_acctMgr; }
00320   KMFilterMgr *filterMgr() { return the_filterMgr; }
00321   KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
00322   KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
00323   KMail::MessageSender *msgSender();
00324   KMMsgIndex *msgIndex();
00325 
00326   KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
00328   KPIM::IdentityManager *identityManager();
00329 
00330   JobScheduler* jobScheduler() { return mJobScheduler; }
00331 
00333   void compactAllFolders();
00335   void expireAllFoldersNow();
00336 
00337   KMailICalIfaceImpl& iCalIface();
00338 
00339   bool firstStart() { return the_firstStart; }
00340   TQString previousVersion() { return the_previousVersion; }
00341   bool startingUp() { return the_startingUp; }
00342   void setStartingUp (bool flag) { the_startingUp = flag; }
00343   bool shuttingDown() { return the_shuttingDown; }
00344   void setShuttingDown(bool flag) { the_shuttingDown = flag; }
00345   void serverReady (bool flag) { the_server_is_ready = flag; }
00346 
00350   static TQString localDataPath();
00351 
00356   bool haveSystemTrayApplet();
00357 
00358   bool registerSystemTrayApplet( const KSystemTray* );
00359   bool unregisterSystemTrayApplet( const KSystemTray* );
00360 
00362   bool handleCommandLine( bool noArgsOpensReader );
00363   void emergencyExit( const TQString& reason );
00364 
00366   unsigned long getNextMsgSerNum();
00367   TQTextCodec *networkCodec() { return netCodec; }
00368 
00370   TDEMainWindow* mainWin();
00371 
00372   // ### The mContextMenuShown flag is necessary to work around bug# 56693
00373   // ### (kmail freeze with the complete desktop while pinentry-qt appears)
00374   // ### FIXME: Once the encryption support is asynchron this can be removed
00375   // ### again.
00376   void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
00377   bool contextMenuShown() const { return mContextMenuShown; }
00378 
00383   ::KIMProxy* imProxy();
00384 
00389   bool mailCheckAborted() const;
00393   void enableMailCheck();
00399   void abortMailCheck();
00400 
00401   bool canQueryClose();
00402 
00406   void messageCountChanged();
00407 
00409   TDEWallet::Wallet *wallet();
00410 
00412   KMMainWidget *getKMMainWidget();
00413 
00415   TQValueList< TQGuardedPtr<KMFolder> > allFolders();
00416 
00417   void raise();
00418 
00419   void loadProfile( const TQString& path );
00420 
00421   void saveToProfile( const TQString& path ) const;
00422 
00423   bool isCodecAsciiCompatible( const TQTextCodec *codec );
00424 public slots:
00425 
00427   void dumpDeadLetters();
00428 
00434   void slotRequestConfigSync();
00435 
00437   void slotEmptyTrash();
00438 
00439   void slotShowConfigurationDialog();
00440   void slotRunBackgroundTasks();
00441 
00442   void slotConfigChanged();
00443 
00444 protected slots:
00445   void slotDataReq(TDEIO::Job*,TQByteArray&);
00446   void slotResult(TDEIO::Job*);
00447   void slotNetworkStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString);
00448 
00449 signals:
00450   void configChanged();
00451   void folderRemoved( KMFolder* aFolder );
00452   void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );
00453 
00454 private:
00455   void openReader( bool onlyCheck );
00456   KMMsgStatus strToStatus(const TQString &flags);
00457   bool networkStateConnected();
00458   KMFolder *currentFolder();
00459 
00460   KMFolder *the_inboxFolder;
00461   KMFolder *the_outboxFolder;
00462   KMFolder *the_sentFolder;
00463   KMFolder *the_trashFolder;
00464   KMFolder *the_draftsFolder;
00465   KMFolder *the_templatesFolder;
00466 
00467   KMFolderMgr *the_folderMgr;
00468   KMFolderMgr *the_imapFolderMgr;
00469   KMFolderMgr *the_dimapFolderMgr;
00470   KMFolderMgr *the_searchFolderMgr;
00471   UndoStack *the_undoStack;
00472   AccountManager *the_acctMgr;
00473   KMFilterMgr *the_filterMgr;
00474   KMFilterMgr *the_popFilterMgr;
00475   KMFilterActionDict *the_filterActionDict;
00476   mutable KPIM::IdentityManager *mIdentityManager;
00477   KMSender *the_msgSender;
00478   KMMsgIndex *the_msgIndex;
00479   struct putData
00480   {
00481     KURL url;
00482     TQByteArray data;
00483     int offset;
00484   };
00485   TQMap<TDEIO::Job *, putData> mPutJobs;
00488   TQString the_previousVersion;
00490   bool the_firstStart;
00492   bool the_startingUp;
00494   bool the_shuttingDown;
00496   bool the_server_is_ready;
00498   bool closed_by_user;
00499   bool the_firstInstance;
00500   bool mMailCheckAborted;
00501   static KMKernel *mySelf;
00502   TDESharedConfig::Ptr mConfig;
00503   TQTextCodec *netCodec;
00504   TDEInstance* mXmlGuiInstance;
00505   ConfigureDialog *mConfigureDialog;
00506 
00507   TQTimer *mBackgroundTasksTimer;
00508   KMailICalIfaceImpl* mICalIface;
00509   JobScheduler* mJobScheduler;
00510   // temporary mainwin
00511   KMMainWin *mWin;
00512   MailServiceImpl *mMailService;
00513 
00514   // the time of the last change of the unread or total count of a folder;
00515   // this can be queried via DCOP in order to determine whether the counts
00516   // need to be updated (e.g. in the Summary in Kontact)
00517   int mTimeOfLastMessageCountChange;
00518 
00519   // true if the context menu of KMFolderTree or KMHeaders is shown
00520   // this is necessary to know in order to prevent a dead lock between the
00521   // context menus and the pinentry program
00522   bool mContextMenuShown;
00523 
00524   TQValueList<const KSystemTray*> systemTrayApplets;
00525   TQValueList<const TQTextCodec*> mNonAsciiCompatibleCodecs;
00526 
00527   /* Weaver */
00528   KPIM::ThreadWeaver::Weaver *the_weaver;
00529   KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
00530 
00531   TDEWallet::Wallet *mWallet;
00532 
00533   // variables used by dcopAddMessage()
00534   TQStringList mAddMessageMsgIds;
00535   TQString     mAddMessageLastFolder;
00536   KMFolder    *mAddMsgCurrentFolder;
00537 
00538 #ifdef __TDE_HAVE_TDEHWLIB
00539   TDEGlobalNetworkManager *mNetworkManager;
00540 #endif
00541 };
00542 
00543 #endif