kmail

kmaccount.h
00001 /* -*- mode: C++ -*-
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #ifndef kmaccount_h
00021 #define kmaccount_h
00022 
00023 #include <kprocess.h>
00024 #include <kaccount.h>
00025 
00026 #include <tqstring.h>
00027 #include <tqguardedptr.h>
00028 #include <tqvaluelist.h>
00029 #include <tqmap.h>
00030 
00031 #include "kmmessage.h"
00032 class TQTimer;
00033 
00034 class KMFolder;
00035 class KMAcctFolder;
00036 class TDEConfig;
00037 class KMFolderJob;
00038 class KMFolderCachedImap;
00039 class AccountsPageReceivingTab;
00040 namespace  KMail {
00041   class FolderJob;
00042   class AccountManager;
00043 }
00044 using KMail::AccountManager;
00045 namespace KPIM { class ProgressItem; }
00046 using KMail::FolderJob;
00047 using KPIM::ProgressItem;
00048 
00049 class KMAccount;
00050 typedef TQValueList< ::KMAccount* > AccountList;
00051 
00052 class KMPrecommand : public TQObject
00053 {
00054   Q_OBJECT
00055   
00056 
00057 public:
00058   KMPrecommand(const TQString &precommand, TQObject *parent = 0);
00059   virtual ~KMPrecommand();
00060   bool start();
00061 
00062 protected slots:
00063   void precommandExited(TDEProcess *);
00064 
00065 signals:
00066   void finished(bool);
00067 
00068 protected:
00069   TDEProcess mPrecommandProcess;
00070   TQString mPrecommand;
00071 };
00072 
00073 
00074 class KMAccount: public TQObject, public KAccount
00075 {
00076   Q_OBJECT
00077   
00078   friend class KMail::AccountManager;
00079   friend class ::KMail::FolderJob;
00080   friend class ::AccountsPageReceivingTab; // part of the config dialog
00081   friend class ::KMFolderCachedImap; /* HACK for processNewMSg() */
00082 
00083 public:
00084   virtual ~KMAccount();
00085 
00086   enum CheckStatus { CheckOK, CheckIgnored, CheckCanceled, CheckAborted,
00087                      CheckError };
00088 
00090   static const int DefaultCheckInterval = 5;
00091 
00095   virtual TQString type() const { return TQString(); }
00096 
00100   virtual void setName(const TQString&);
00101 
00105   virtual TQString name() const { return KAccount::name(); }
00106 
00110   virtual void clearPasswd();
00111 
00115   virtual void init();
00116 
00120   virtual void pseudoAssign(const KMAccount * a );
00121 
00125   KMFolder* folder(void) const { return ((KMFolder*)((KMAcctFolder*)mFolder)); }
00126   virtual void setFolder(KMFolder*, bool addAccount = false);
00127 
00131   TQString trash() const { return mTrash; }
00132   virtual void setTrash(const TQString& aTrash) { mTrash = aTrash; }
00133 
00139   virtual void processNewMail(bool interactive) = 0;
00140 
00146   virtual void readConfig(TDEConfig& config);
00147   void readTimerConfig();
00148 
00153   virtual void writeConfig(TDEConfig& config);
00154 
00159   virtual void setCheckInterval(int aInterval);
00160   int checkInterval() const;
00161 
00165   inline int defaultCheckInterval(void) const { return DefaultCheckInterval; }
00166 
00170   void deleteFolderJobs();
00171 
00175   virtual void ignoreJobsForMessage( KMMessage* );
00180   virtual void setCheckExclude(bool aExclude);
00181   bool checkExclude(void) const { return mExclude; }
00182 
00186   const TQString& precommand(void) const { return mPrecommand; }
00187   virtual void setPrecommand(const TQString &cmd) { mPrecommand = cmd; }
00188 
00195   bool runPrecommand(const TQString &precommand);
00196 
00201   static TQString encryptStr(const TQString& inStr);
00202   static TQString decryptStr(const TQString& inStr) { return  encryptStr(inStr); }
00203 
00204   static TQString importPassword(const TQString &);
00205 
00207   bool hasInbox() const { return mHasInbox; }
00208   virtual void setHasInbox( bool has ) { mHasInbox = has; }
00209 
00213   virtual void invalidateIMAPFolders();
00214 
00221   virtual bool mailCheckCanProceed() const { return true; }
00222 
00226   bool checkingMail() { return mCheckingMail; }
00227   virtual void setCheckingMail( bool checking ) { mCheckingMail = checking; }
00228 
00234   void checkDone( bool newMail, CheckStatus status );
00235 
00241   virtual void cancelMailCheck() {}
00242 
00247   ProgressItem *mailCheckProgressItem() const {
00248     return mMailCheckProgressItem;
00249   }
00250 
00254   void setIdentityId(uint identityId ) { mIdentityId = identityId; }
00255   uint identityId() const{ return mIdentityId; }
00256 
00257 signals:
00263   virtual void finishedCheck( bool newMail, CheckStatus status );
00264 
00269   virtual void newMailsProcessed( const TQMap<TQString, int> & newInFolder );
00270 
00271 protected slots:
00272   virtual void mailCheck();
00273   virtual void sendReceipts();
00274   virtual void precommandExited(bool);
00275 
00276 protected:
00277   KMAccount( AccountManager* owner, const TQString& accountName, uint id);
00278 
00284   virtual bool processNewMsg(KMMessage* msg);
00285 
00292   virtual void sendReceipt(KMMessage* msg);
00293 
00297   virtual void installTimer();
00298   virtual void deinstallTimer();
00299 
00306   void addToNewInFolder( TQString folderId, int num );
00307 
00308 protected:
00309   TQString       mPrecommand;
00310   TQString       mTrash;
00311   AccountManager*    mOwner;
00312   TQGuardedPtr<KMAcctFolder> mFolder;
00313   TQTimer *mTimer;
00314   int mInterval; // this is a switch and a scalar at the same time. If it is 0,
00315   // interval mail checking is turned off and the interval spinbox proposes a
00316   // default value. If it is non-null, it is the count of minutes between two
00317   // automated mail checks. This means that as soon as you disable interval
00318   // mail checking, the value in the spin box returns to a default value.
00319   bool mExclude;
00320   bool mCheckingMail : 1;
00321   bool mPrecommandSuccess;
00322   TQValueList<KMMessage*> mReceipts;
00323   TQPtrList<FolderJob>  mJobList;
00324   bool mHasInbox : 1;
00325   TQGuardedPtr<ProgressItem> mMailCheckProgressItem;
00326   uint mIdentityId;
00327 private:
00331     virtual void setName( const char *name ) { TQObject::setName( name ); }
00332 
00333 private:
00334   // for detailed (per folder) new mail notification
00335   TQMap<TQString, int> mNewInFolder;
00336 };
00337 
00338 #endif /*kmaccount_h*/