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 "kmacctcachedimap.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 KMCommand;
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 reallyDoClose(const char* owner);
00106 
00108   void initializeFrom( KMFolderCachedImap* parent );
00109 
00110   virtual void readConfig();
00111   virtual void writeConfig();
00112 
00113   void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
00114 
00116   virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00117 
00119   virtual int create();
00120 
00122   virtual void remove();
00123 
00125   virtual void serverSync( bool recurse );
00126 
00128   void resetSyncState( );
00129 
00133   void setAlarmsBlocked( bool blocked );
00135   bool alarmsBlocked() const;
00136 
00137   void checkUidValidity();
00138 
00139   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00140 
00141   virtual imapState getContentState() { return mContentState; }
00142   virtual void setContentState(imapState state) { mContentState = state; }
00143 
00144   virtual imapState getSubfolderState() { return mSubfolderState; }
00145   virtual void setSubfolderState(imapState state);
00146 
00148   void setImapPath(const QString &path);
00149   QString imapPath() const { return mImapPath; }
00150 
00152   void setLastUid( ulong uid );
00153   ulong lastUid();
00154 
00156   KMMsgBase* findByUID( ulong uid );
00157 
00159   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00160   QString uidValidity() const { return mUidValidity; }
00161 
00164   void clearUidMap() { uidMap.clear(); }
00165 
00167   void setAccount(KMAcctCachedImap *acct);
00168   KMAcctCachedImap* account() const;
00169 
00171   QString uidCacheLocation() const;
00172 
00174   int readUidCache();
00175 
00177   int writeUidCache();
00178 
00180   int progress() const { return mProgress; }
00181 
00182   /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
00183   virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00184 
00185   /* Reimplemented from KMFolderMaildir */
00186   virtual KMMessage* take(int idx);
00187   /* Reimplemented from KMFolderMaildir */
00188   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00189   /* internal version that doesn't remove the X-UID header */
00190   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00191   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00192     return addMsgInternal(msg, false, index_return);
00193   }
00194 
00195   /* Reimplemented from KMFolderMaildir */
00196   virtual void removeMsg(int i, bool imapQuiet = false);
00197   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = false)
00198     { FolderStorage::removeMsg(msgList, imapQuiet); }
00199 
00201   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00202   bool canDeleteMessages() const;
00203 
00204 
00208   void sendFolderComplete(bool success)
00209   { emit folderComplete(this, success); }
00210 
00214   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00215   bool silentUpload() { return mSilentUpload; }
00216 
00217   virtual int createIndexFromContents()
00218     { return KMFolderMaildir::createIndexFromContents(); }
00219 
00220   int createIndexFromContentsRecursive();
00221 
00222   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00223 
00229   virtual bool listDirectory();
00230 
00231   virtual void listNamespaces();
00232 
00234   KMFolder* trashFolder() const;
00235 
00240   int userRights() const { return mUserRights; }
00241 
00243   void setUserRights( unsigned int userRights );
00244 
00254   const QuotaInfo quotaInfo() const { return mQuotaInfo; }
00255   void setQuotaInfo( const QuotaInfo & );
00256 
00258   typedef QValueVector<KMail::ACLListEntry> ACLList;
00259   const ACLList& aclList() const { return mACLList; }
00260 
00262   void setACLList( const ACLList& arr );
00263 
00264   // Reimplemented so the mStatusChangedLocally bool can be set
00265   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00266   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00267 
00268   QString annotationFolderType() const { return mAnnotationFolderType; }
00269 
00270   // For kmailicalifaceimpl only
00271   void updateAnnotationFolderType();
00272 
00281   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00282 
00283   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00285   void setIncidencesFor( IncidencesFor incfor );
00286 
00288   virtual bool isMoveable() const;
00289 
00294   QStringList namespacesToList() { return mNamespacesToList; }
00295   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00296 
00301   const QString& imapPathForCreation() { return mImapPathCreation; }
00302   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00303 
00305   bool isCloseToQuota() const;
00306 
00308   int permanentFlags() const { return mPermanentFlags; }
00309 
00310 
00311   QString folderAttributes() const { return mFolderAttributes; }
00312 
00313 protected slots:
00314   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00315   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00316   void slotGetLastMessagesResult(KMail::FolderJob *);
00317   void slotProgress(unsigned long done, unsigned long total);
00318   void slotPutProgress( unsigned long, unsigned long );
00319 
00320   //virtual void slotCheckValidityResult(KIO::Job * job);
00321   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00322 
00323   // Connected to the imap account
00324   void slotConnectionResult( int errorCode, const QString& errorMsg );
00325 
00326   void slotCheckUidValidityResult( KMail::FolderJob* job );
00327   void slotPermanentFlags( int flags );
00328   void slotTestAnnotationResult(KIO::Job *job);
00329   void slotGetAnnotationResult( KIO::Job* );
00330   void slotMultiUrlGetAnnotationResult( KIO::Job* );
00331   void slotSetAnnotationResult(KIO::Job *job);
00332   void slotReceivedUserRights( KMFolder* );
00333   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00334 
00335   void slotMultiSetACLResult(KIO::Job *);
00336   void slotACLChanged( const QString&, int );
00337   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00338   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00339   void slotDeleteMessagesResult(KMail::FolderJob *);
00340   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00341   void slotStorageQuotaResult( const QuotaInfo& );
00342   void slotQuotaResult( KIO::Job* job );
00343 
00344 protected:
00345   /* returns true if there were messages to delete
00346      on the server */
00347   bool deleteMessages();
00348   void listMessages();
00349   void uploadNewMessages();
00350   void uploadFlags();
00351   void uploadSeenFlags();
00352   void createNewFolders();
00353 
00354   void listDirectory2();
00355   void createFoldersNewOnServerAndFinishListing( const QValueVector<int> foldersNewOnServer );
00356 
00357 
00360   virtual QValueList<unsigned long> findNewMessages();
00363   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00364 
00366   virtual bool canRemoveFolder() const;
00367 
00369   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00370                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00371   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00372                                   FolderJob::JobType jt, KMFolder *folder ) const;
00373 
00374   virtual void timerEvent( QTimerEvent* );
00375 
00376   /* update progress status */
00377   void newState( int progress, const QString& syncStatus );
00378 
00380   KMFolderCachedImap* findParent( const QString& path, const QString& name );
00381 
00382 
00383 
00384 public slots:
00388   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00389 
00393   void slotTroubleshoot();
00394 
00399   void slotListResult( const QStringList&, const QStringList&,
00400       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00401 
00406   void slotCheckNamespace( const QStringList&, const QStringList&,
00407       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00408 
00409 private slots:
00410   void serverSyncInternal();
00411   void slotIncreaseProgress();
00412   void slotUpdateLastUid();
00413   void slotFolderDeletionOnServerFinished();
00414   void slotRescueDone( KMCommand* command );
00415 
00416 signals:
00417   void folderComplete(KMFolderCachedImap *folder, bool success);
00418   void listComplete( KMFolderCachedImap* );
00419 
00423   void syncState( int state, int number );
00424 
00425 private:
00426   void setReadOnly( bool readOnly );
00427   QString state2String( int state ) const;
00428   void rememberDeletion( int );
00433   KMCommand* rescueUnsyncedMessages();
00435   void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
00436 
00438   enum {
00439     SYNC_STATE_INITIAL,
00440     SYNC_STATE_TEST_ANNOTATIONS,
00441     SYNC_STATE_PUT_MESSAGES,
00442     SYNC_STATE_UPLOAD_FLAGS,
00443     SYNC_STATE_CREATE_SUBFOLDERS,
00444     SYNC_STATE_LIST_NAMESPACES,
00445     SYNC_STATE_LIST_SUBFOLDERS,
00446     SYNC_STATE_LIST_SUBFOLDERS2,
00447     SYNC_STATE_DELETE_SUBFOLDERS,
00448     SYNC_STATE_LIST_MESSAGES,
00449     SYNC_STATE_DELETE_MESSAGES,
00450     SYNC_STATE_EXPUNGE_MESSAGES,
00451     SYNC_STATE_GET_MESSAGES,
00452     SYNC_STATE_HANDLE_INBOX,
00453     SYNC_STATE_GET_USERRIGHTS,
00454     SYNC_STATE_GET_ANNOTATIONS,
00455     SYNC_STATE_SET_ANNOTATIONS,
00456     SYNC_STATE_GET_ACLS,
00457     SYNC_STATE_SET_ACLS,
00458     SYNC_STATE_GET_QUOTA,
00459     SYNC_STATE_FIND_SUBFOLDERS,
00460     SYNC_STATE_SYNC_SUBFOLDERS,
00461     SYNC_STATE_CHECK_UIDVALIDITY,
00462     SYNC_STATE_RENAME_FOLDER
00463   } mSyncState;
00464 
00465   int mProgress;
00466   int mStatusFlagsJobs;
00467 
00468   QString mUidValidity;
00469   QString     mImapPath;
00470   imapState   mContentState, mSubfolderState;
00471   QStringList mSubfolderNames, mSubfolderPaths,
00472               mSubfolderMimeTypes, mSubfolderAttributes;
00473   QString     mFolderAttributes;
00474   QString     mAnnotationFolderType;
00475   IncidencesFor mIncidencesFor;
00476 
00477   bool        mHasInbox;
00478   bool        mIsSelected;
00479   bool        mCheckFlags;
00480   bool        mReadOnly;
00481   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00482 
00483   QIntDict<int> uidsOnServer;
00484   QValueList<ulong> uidsForDeletionOnServer;
00485   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00486   QValueList<ulong> mUidsForDownload;
00487   QStringList       foldersForDeletionOnServer;
00488 
00489   QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00490   KMFolderCachedImap* mCurrentSubfolder;
00491 
00495   QMap<ulong,int> uidMap;
00496   bool uidMapDirty;
00497   void reloadUidMap();
00498   int uidWriteTimer;
00499 
00509   ulong mLastUid;
00514   ulong mTentativeHighestUid;
00515 
00519   bool mFoundAnIMAPDigest;
00520 
00521   int mUserRights, mOldUserRights;
00522   ACLList mACLList;
00523 
00524   bool mSilentUpload;
00525   bool mFolderRemoved;
00526   //bool mHoldSyncs;
00527   bool mRecurse;
00532   bool mStatusChangedLocally;
00534   bool mAnnotationFolderTypeChanged;
00536   bool mIncidencesForChanged;
00537 
00538   QStringList mNamespacesToList;
00539   int mNamespacesToCheck;
00540   bool mPersonalNamespacesCheckDone;
00541   QString mImapPathCreation;
00542 
00543   QuotaInfo mQuotaInfo;
00544   QMap<ulong,void*> mDeletedUIDsSinceLastSync;
00545   bool mAlarmsBlocked;
00546 
00547   QValueList<KMFolder*> mToBeDeletedAfterRescue;
00548   int mRescueCommandCount;
00549 
00550   int mPermanentFlags;
00551 };
00552 
00553 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys