kmail

kmfoldercachedimap.h

00001 /*
00002  *  kmfoldercachedimap.cpp
00003  *
00004  *  Copyright (c) 2002-2004 Bo Thorsen <bo@sonofthor.dk>
00005  *  Copyright (c) 2002-2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  *  In addition, as a special exception, the copyright holders give
00021  *  permission to link the code of this program with any edition of
00022  *  the Qt library by Trolltech AS, Norway (or with modified versions
00023  *  of Qt that use the same license as Qt), and distribute linked
00024  *  combinations including the two.  You must obey the GNU General
00025  *  Public License in all respects for all of the code used other than
00026  *  Qt.  If you modify this file, you may extend this exception to
00027  *  your version of the file, but you are not obligated to do so.  If
00028  *  you do not wish to do so, delete this exception statement from
00029  *  your version.
00030  */
00031 
00032 #ifndef kmfoldercachedimap_h
00033 #define kmfoldercachedimap_h
00034 
00035 #include <kdialogbase.h>
00036 #include <kstandarddirs.h>
00037 #include <qvaluelist.h>
00038 #include <qvaluevector.h>
00039 #include <qptrlist.h>
00040 #include <qdialog.h>
00041 
00042 #include "kmfoldermaildir.h"
00043 #include "kmfolderimap.h"
00044 #include "kmacctimap.h"
00045 #include "kmfoldertype.h"
00046 #include "folderjob.h"
00047 #include "cachedimapjob.h"
00048 #include "quotajobs.h"
00049 
00050 using KMail::FolderJob;
00051 using KMail::QuotaInfo;
00052 class KMAcctCachedImap;
00053 
00054 class QComboBox;
00055 class QRadioButton;
00056 
00057 namespace KMail {
00058   class AttachmentStrategy;
00059   class ImapAccountBase;
00060   struct ACLListEntry;
00061 }
00062 using KMail::AttachmentStrategy;
00063 
00064 class DImapTroubleShootDialog : public KDialogBase
00065 {
00066   Q_OBJECT
00067 public:
00068   enum SelectedOperation {
00069     None = -1,
00070     ReindexCurrent = 0,
00071     ReindexRecursive = 1,
00072     ReindexAll = 2,
00073     RefreshCache
00074   };
00075 
00076   DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00077 
00078   static int run();
00079 
00080 private slots:
00081   void slotDone();
00082 
00083 private:
00084   QRadioButton *mIndexButton, *mCacheButton;
00085   QComboBox *mIndexScope;
00086   int rc;
00087 };
00088 
00089 class KMFolderCachedImap : public KMFolderMaildir
00090 {
00091   Q_OBJECT
00092 
00093 public:
00094   static QString cacheLocation() {
00095      return locateLocal("data", "kmail/dimap" );
00096   }
00097 
00101   KMFolderCachedImap(KMFolder* folder, const char* name=0);
00102   virtual ~KMFolderCachedImap();
00103 
00105   void initializeFrom( KMFolderCachedImap* parent );
00106 
00107   virtual void readConfig();
00108   virtual void writeConfig();
00109 
00110   void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00111 
00113   virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00114 
00116   virtual int create();
00117   
00119   virtual void remove();
00120 
00122   virtual void serverSync( bool recurse );
00123 
00125   void resetSyncState();
00126 
00127   void checkUidValidity();
00128 
00129   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00130 
00131   virtual imapState getContentState() { return mContentState; }
00132   virtual void setContentState(imapState state) { mContentState = state; }
00133 
00134   virtual imapState getSubfolderState() { return mSubfolderState; }
00135   virtual void setSubfolderState(imapState state);
00136 
00138   void setImapPath(const QString &path);
00139   QString imapPath() const { return mImapPath; }
00140 
00142   void setLastUid( ulong uid );
00143   ulong lastUid();
00144 
00146   KMMsgBase* findByUID( ulong uid );
00147 
00149   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00150   QString uidValidity() const { return mUidValidity; }
00151 
00154   void clearUidMap() { uidMap.clear(); }
00155 
00157   void setAccount(KMAcctCachedImap *acct);
00158   KMAcctCachedImap* account() const;
00159 
00161   QString uidCacheLocation() const;
00162 
00164   int readUidCache();
00165 
00167   int writeUidCache();
00168 
00170   int progress() const { return mProgress; }
00171 
00172   /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
00173   virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00174 
00175   /* Reimplemented from KMFolderMaildir */
00176   virtual KMMessage* take(int idx);
00177   /* Reimplemented from KMFolderMaildir */
00178   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00179   /* internal version that doesn't remove the X-UID header */
00180   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00181   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00182     return addMsgInternal(msg, false, index_return);
00183   }
00184 
00185   /* Reimplemented from KMFolderMaildir */
00186   virtual void removeMsg(int i, bool imapQuiet = FALSE);
00187   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00188     { FolderStorage::removeMsg(msgList, imapQuiet); }
00189 
00191   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00192 
00196   void sendFolderComplete(bool success)
00197   { emit folderComplete(this, success); }
00198 
00202   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00203   bool silentUpload() { return mSilentUpload; }
00204 
00205   virtual int createIndexFromContents()
00206     { return KMFolderMaildir::createIndexFromContents(); }
00207 
00208   int createIndexFromContentsRecursive();
00209 
00210   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00211 
00217   virtual bool listDirectory();
00218 
00219   virtual void listNamespaces();
00220 
00222   KMFolder* trashFolder() const;
00223 
00228   int userRights() const { return mUserRights; }
00229 
00231   void setUserRights( unsigned int userRights );
00232 
00242   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00243 
00245   typedef QValueVector<KMail::ACLListEntry> ACLList;
00246   const ACLList& aclList() const { return mACLList; }
00247 
00249   void setACLList( const ACLList& arr );
00250 
00251   // Reimplemented so the mStatusChangedLocally bool can be set
00252   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00253   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00254 
00255   QString annotationFolderType() const { return mAnnotationFolderType; }
00256 
00257   // For kmailicalifaceimpl only
00258   void updateAnnotationFolderType();
00259 
00268   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00269 
00270   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00272   void setIncidencesFor( IncidencesFor incfor );
00273 
00275   virtual bool isMoveable() const;
00276 
00281   QStringList namespacesToList() { return mNamespacesToList; }
00282   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00283 
00288   const QString& imapPathForCreation() { return mImapPathCreation; }
00289   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00290 
00291 protected slots:
00292   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00293   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00294   void slotGetLastMessagesResult(KMail::FolderJob *);
00295   void slotProgress(unsigned long done, unsigned long total);
00296   void slotPutProgress( unsigned long, unsigned long );
00297 
00298   //virtual void slotCheckValidityResult(KIO::Job * job);
00299   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00300 
00301   // Connected to the imap account
00302   void slotConnectionResult( int errorCode, const QString& errorMsg );
00303 
00304   void slotCheckUidValidityResult( KMail::FolderJob* job );
00305   void slotTestAnnotationResult(KIO::Job *job);
00306   void slotGetAnnotationResult( KIO::Job* );
00307   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00308   void slotSetAnnotationResult(KIO::Job *job);
00309   void slotReceivedUserRights( KMFolder* );
00310   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00311 
00312   void slotMultiSetACLResult(KIO::Job *);
00313   void slotACLChanged( const QString&, int );
00314   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00315   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00316   void slotDeleteMessagesResult(KMail::FolderJob *);
00317   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00318   void slotStorageQuotaResult( const QuotaInfo& );
00319   void slotQuotaResult( KIO::Job* job );
00320 
00321 protected:
00322   /* returns true if there were messages to delete
00323      on the server */
00324   bool deleteMessages();
00325   void listMessages();
00326   void uploadNewMessages();
00327   void uploadFlags();
00328   void createNewFolders();
00329 
00330   void listDirectory2();
00331   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00332 
00333 
00336   virtual QValueList<unsigned long> findNewMessages();
00339   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00340 
00342   virtual bool canRemoveFolder() const;
00343 
00345   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00346                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00347   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00348                                   FolderJob::JobType jt, KMFolder *folder ) const;
00349 
00350   virtual void timerEvent( QTimerEvent* );
00351 
00352   /* update progress status */
00353   void newState( int progress, const QString& syncStatus );
00354 
00356   KMFolderCachedImap* findParent( const QString& path, const QString& name );  
00357 
00358 public slots:
00362   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00363 
00367   void slotTroubleshoot();
00368 
00373   void slotListResult( const QStringList&, const QStringList&,
00374       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00375 
00380   void slotCheckNamespace( const QStringList&, const QStringList&,
00381       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00382 
00383 private slots:
00384   void serverSyncInternal();
00385   void slotIncreaseProgress();
00386   void slotUpdateLastUid();
00387   void slotFolderDeletionOnServerFinished();
00388 
00389 signals:
00390   void folderComplete(KMFolderCachedImap *folder, bool success);
00391   void listComplete( KMFolderCachedImap* );
00392 
00396   void syncState( int state, int number );
00397 
00398 private:
00399   void setReadOnly( bool readOnly );
00400   QString state2String( int state ) const;
00401 
00403   enum {
00404     SYNC_STATE_INITIAL,
00405     SYNC_STATE_TEST_ANNOTATIONS,
00406     SYNC_STATE_PUT_MESSAGES,
00407     SYNC_STATE_UPLOAD_FLAGS,
00408     SYNC_STATE_CREATE_SUBFOLDERS,
00409     SYNC_STATE_LIST_NAMESPACES,
00410     SYNC_STATE_LIST_SUBFOLDERS,
00411     SYNC_STATE_LIST_SUBFOLDERS2,
00412     SYNC_STATE_DELETE_SUBFOLDERS,
00413     SYNC_STATE_LIST_MESSAGES,
00414     SYNC_STATE_DELETE_MESSAGES,
00415     SYNC_STATE_EXPUNGE_MESSAGES,
00416     SYNC_STATE_GET_MESSAGES,
00417     SYNC_STATE_HANDLE_INBOX,
00418     SYNC_STATE_GET_USERRIGHTS,
00419     SYNC_STATE_GET_ANNOTATIONS,
00420     SYNC_STATE_SET_ANNOTATIONS,
00421     SYNC_STATE_GET_ACLS,
00422     SYNC_STATE_SET_ACLS,
00423     SYNC_STATE_GET_QUOTA,
00424     SYNC_STATE_FIND_SUBFOLDERS,
00425     SYNC_STATE_SYNC_SUBFOLDERS,
00426     SYNC_STATE_CHECK_UIDVALIDITY,
00427     SYNC_STATE_RENAME_FOLDER
00428   } mSyncState;
00429 
00430   int mProgress;
00431   int mStatusFlagsJobs;
00432 
00433   QString mUidValidity;
00434   QString     mImapPath;
00435   imapState   mContentState, mSubfolderState;
00436   QStringList mSubfolderNames, mSubfolderPaths,
00437               mSubfolderMimeTypes, mSubfolderAttributes;
00438   QString     mAnnotationFolderType;
00439   IncidencesFor mIncidencesFor;
00440 
00441   bool        mHasInbox;
00442   bool        mIsSelected;
00443   bool        mCheckFlags;
00444   bool        mReadOnly;
00445   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00446 
00447   QIntDict<int> uidsOnServer;
00448   QValueList<ulong> uidsForDeletionOnServer;
00449   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00450   QValueList<ulong> mUidsForDownload;
00451   QStringList       foldersForDeletionOnServer;
00452 
00453   QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00454   KMFolderCachedImap* mCurrentSubfolder;
00455 
00459   QMap<ulong,int> uidMap;
00460   bool uidMapDirty;
00461   void reloadUidMap();
00462   int uidWriteTimer;
00463 
00473   ulong mLastUid;
00478   ulong mTentativeHighestUid;
00479 
00483   bool mFoundAnIMAPDigest;
00484 
00485   int mUserRights, mOldUserRights;
00486   ACLList mACLList;
00487 
00488   bool mSilentUpload;
00489   bool mFolderRemoved;
00490   //bool mHoldSyncs;
00491   bool mRecurse;
00496   bool mStatusChangedLocally;
00498   bool mAnnotationFolderTypeChanged;
00500   bool mIncidencesForChanged;
00501 
00502   QStringList mNamespacesToList;
00503   int mNamespacesToCheck;
00504   bool mPersonalNamespacesCheckDone;
00505   QString mImapPathCreation;
00506 
00507   QuotaInfo mQuotaInfo;
00508 };
00509 
00510 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys