kmail

kmaccount.h

Go to the documentation of this file.
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 <qstring.h>
00027 #include <qguardedptr.h>
00028 #include <qvaluelist.h>
00029 #include <qmap.h>
00030 
00031 #include "kmmessage.h"
00032 class QTimer;
00033 
00034 class KMFolder;
00035 class KMAcctFolder;
00036 class KConfig;
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 QValueList< ::KMAccount* > AccountList;
00051 
00052 class KMPrecommand : public QObject
00053 {
00054   Q_OBJECT
00055 
00056 public:
00057   KMPrecommand(const QString &precommand, QObject *parent = 0);
00058   virtual ~KMPrecommand();
00059   bool start();
00060 
00061 protected slots:
00062   void precommandExited(KProcess *);
00063 
00064 signals:
00065   void finished(bool);
00066 
00067 protected:
00068   KProcess mPrecommandProcess;
00069   QString mPrecommand;
00070 };
00071 
00072 
00073 class KMAccount: public QObject, public KAccount
00074 {
00075   Q_OBJECT
00076   friend class KMail::AccountManager;
00077   friend class ::KMail::FolderJob;
00078   friend class ::AccountsPageReceivingTab; // part of the config dialog
00079   friend class ::KMFolderCachedImap; /* HACK for processNewMSg() */
00080 
00081 public:
00082   virtual ~KMAccount();
00083 
00084   enum CheckStatus { CheckOK, CheckIgnored, CheckCanceled, CheckAborted,
00085                      CheckError };
00086 
00088   static const int DefaultCheckInterval = 5;
00089 
00093   virtual QString type() const { return QString::null; }
00094 
00098   virtual void setName(const QString&);
00099 
00103   virtual QString name() const { return KAccount::name(); }
00104 
00108   virtual void clearPasswd();
00109 
00113   virtual void init();
00114 
00118   virtual void pseudoAssign(const KMAccount * a );
00119 
00123   KMFolder* folder(void) const { return ((KMFolder*)((KMAcctFolder*)mFolder)); }
00124   virtual void setFolder(KMFolder*, bool addAccount = false);
00125 
00129   QString trash() const { return mTrash; }
00130   virtual void setTrash(const QString& aTrash) { mTrash = aTrash; }
00131 
00137   virtual void processNewMail(bool interactive) = 0;
00138 
00144   virtual void readConfig(KConfig& config);
00145   void readTimerConfig();
00146 
00151   virtual void writeConfig(KConfig& config);
00152 
00157   virtual void setCheckInterval(int aInterval);
00158   int checkInterval() const;
00159 
00163   inline int defaultCheckInterval(void) const { return DefaultCheckInterval; }
00164 
00168   void deleteFolderJobs();
00169 
00173   virtual void ignoreJobsForMessage( KMMessage* );
00178   virtual void setCheckExclude(bool aExclude);
00179   bool checkExclude(void) const { return mExclude; }
00180 
00184   const QString& precommand(void) const { return mPrecommand; }
00185   virtual void setPrecommand(const QString &cmd) { mPrecommand = cmd; }
00186 
00193   bool runPrecommand(const QString &precommand);
00194 
00199   static QString encryptStr(const QString& inStr);
00200   static QString decryptStr(const QString& inStr) { return  encryptStr(inStr); }
00201 
00202   static QString importPassword(const QString &);
00203 
00205   bool hasInbox() const { return mHasInbox; }
00206   virtual void setHasInbox( bool has ) { mHasInbox = has; }
00207 
00211   virtual void invalidateIMAPFolders();
00212 
00219   virtual bool mailCheckCanProceed() const { return true; }
00220 
00224   bool checkingMail() { return mCheckingMail; }
00225   virtual void setCheckingMail( bool checking ) { mCheckingMail = checking; }
00226 
00232   void checkDone( bool newMail, CheckStatus status );
00233 
00239   virtual void cancelMailCheck() {}
00240 
00245   ProgressItem *mailCheckProgressItem() const {
00246     return mMailCheckProgressItem;
00247   }
00248 
00252   void setIdentityId(uint identityId ) { mIdentityId = identityId; }
00253   uint identityId() const{ return mIdentityId; }
00254 
00255 signals:
00261   virtual void finishedCheck( bool newMail, CheckStatus status );
00262 
00267   virtual void newMailsProcessed( const QMap<QString, int> & newInFolder );
00268 
00269 protected slots:
00270   virtual void mailCheck();
00271   virtual void sendReceipts();
00272   virtual void precommandExited(bool);
00273 
00274 protected:
00275   KMAccount( AccountManager* owner, const QString& accountName, uint id);
00276 
00282   virtual bool processNewMsg(KMMessage* msg);
00283 
00290   virtual void sendReceipt(KMMessage* msg);
00291 
00295   virtual void installTimer();
00296   virtual void deinstallTimer();
00297 
00304   void addToNewInFolder( QString folderId, int num );
00305 
00306 protected:
00307   QString       mPrecommand;
00308   QString       mTrash;
00309   AccountManager*    mOwner;
00310   QGuardedPtr<KMAcctFolder> mFolder;
00311   QTimer *mTimer;
00312   int mInterval; // this is a switch and a scalar at the same time. If it is 0,
00313   // interval mail checking is turned off and the interval spinbox proposes a
00314   // default value. If it is non-null, it is the count of minutes between two
00315   // automated mail checks. This means that as soon as you disable interval
00316   // mail checking, the value in the spin box returns to a default value.
00317   bool mExclude;
00318   bool mCheckingMail : 1;
00319   bool mPrecommandSuccess;
00320   QValueList<KMMessage*> mReceipts;
00321   QPtrList<FolderJob>  mJobList;
00322   bool mHasInbox : 1;
00323   QGuardedPtr<ProgressItem> mMailCheckProgressItem;
00324   uint mIdentityId;
00325 private:
00329     virtual void setName( const char *name ) { QObject::setName( name ); }
00330 
00331 private:
00332   // for detailed (per folder) new mail notification
00333   QMap<QString, int> mNewInFolder;
00334 };
00335 
00336 #endif /*kmaccount_h*/