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 
00049 using KMail::FolderJob;
00050 class KMAcctCachedImap;
00051 
00052 namespace KMail {
00053   class AttachmentStrategy;
00054   class ImapAccountBase;
00055   struct ACLListEntry;
00056 }
00057 using KMail::AttachmentStrategy;
00058 
00059 class DImapTroubleShootDialog : public KDialogBase
00060 {
00061   Q_OBJECT
00062 public:
00063   DImapTroubleShootDialog( QWidget* parent=0, const char* name=0 );
00064 
00065   static int run();
00066 
00067 private slots:
00068   void slotRebuildIndex();
00069   void slotRebuildCache();
00070 
00071 private:
00072   int rc;
00073 };
00074 
00075 class KMFolderCachedImap : public KMFolderMaildir
00076 {
00077   Q_OBJECT
00078 
00079 public:
00080   static QString cacheLocation() {
00081      return locateLocal("data", "kmail/dimap" );
00082   }
00083 
00087   KMFolderCachedImap(KMFolder* folder, const char* name=0);
00088   virtual ~KMFolderCachedImap();
00089 
00091   void initializeFrom( KMFolderCachedImap* parent );
00092 
00093   virtual void readConfig();
00094   virtual void writeConfig();
00095 
00096   void writeAnnotationConfig();
00097 
00099   virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
00100 
00102   virtual int create();
00103   
00105   virtual void remove();
00106 
00108   virtual void serverSync( bool recurse );
00109 
00111   void resetSyncState();
00112 
00113   void checkUidValidity();
00114 
00115   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
00116 
00117   virtual imapState getContentState() { return mContentState; }
00118   virtual void setContentState(imapState state) { mContentState = state; }
00119 
00120   virtual imapState getSubfolderState() { return mSubfolderState; }
00121   virtual void setSubfolderState(imapState state);
00122 
00124   void setImapPath(const QString &path);
00125   QString imapPath() const { return mImapPath; }
00126 
00128   void setLastUid( ulong uid );
00129   ulong lastUid();
00130 
00132   KMMsgBase* findByUID( ulong uid );
00133 
00135   void setUidValidity(const QString &validity) { mUidValidity = validity; }
00136   QString uidValidity() const { return mUidValidity; }
00137 
00140   void clearUidMap() { uidMap.clear(); }
00141 
00143   void setAccount(KMAcctCachedImap *acct);
00144   KMAcctCachedImap* account() const;
00145 
00147   QString uidCacheLocation() const;
00148 
00150   int readUidCache();
00151 
00153   int writeUidCache();
00154 
00156   int progress() const { return mProgress; }
00157 
00158   /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
00159   virtual int rename(const QString& aName, KMFolderDir *aParent=0);
00160 
00161   /* Reimplemented from KMFolderMaildir */
00162   virtual KMMessage* take(int idx);
00163   /* Reimplemented from KMFolderMaildir */
00164   virtual int addMsg(KMMessage* msg, int* index_return = 0);
00165   /* internal version that doesn't remove the X-UID header */
00166   virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
00167   virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
00168     return addMsgInternal(msg, false, index_return);
00169   }
00170 
00171   /* Reimplemented from KMFolderMaildir */
00172   virtual void removeMsg(int i, bool imapQuiet = FALSE);
00173   virtual void removeMsg(QPtrList<KMMessage> msgList, bool imapQuiet = FALSE)
00174     { FolderStorage::removeMsg(msgList, imapQuiet); }
00175 
00177   bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
00178 
00182   void sendFolderComplete(bool success)
00183   { emit folderComplete(this, success); }
00184 
00188   void setSilentUpload( bool silent ) { mSilentUpload = silent; }
00189   bool silentUpload() { return mSilentUpload; }
00190 
00191   virtual int createIndexFromContents()
00192     { return KMFolderMaildir::createIndexFromContents(); }
00193 
00194   //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
00195 
00201   virtual bool listDirectory();
00202 
00203   virtual void listNamespaces();
00204 
00206   KMFolder* trashFolder() const;
00207 
00212   int userRights() const { return mUserRights; }
00213 
00215   void setUserRights( unsigned int userRights );
00216 
00218   typedef QValueVector<KMail::ACLListEntry> ACLList;
00219   const ACLList& aclList() const { return mACLList; }
00220 
00222   void setACLList( const ACLList& arr );
00223 
00224   // Reimplemented so the mStatusChangedLocally bool can be set
00225   virtual void setStatus( int id, KMMsgStatus status, bool toggle );
00226   virtual void setStatus( QValueList<int>& ids, KMMsgStatus status, bool toggle );
00227 
00228   QString annotationFolderType() const { return mAnnotationFolderType; }
00229 
00230   // For kmailicalifaceimpl only
00231   void updateAnnotationFolderType();
00232 
00241   enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
00242 
00243   IncidencesFor incidencesFor() const { return mIncidencesFor; }
00245   void setIncidencesFor( IncidencesFor incfor );
00246 
00248   virtual bool isMoveable() const;
00249 
00254   QStringList namespacesToList() { return mNamespacesToList; }
00255   void setNamespacesToList( QStringList list ) { mNamespacesToList = list; }
00256 
00261   const QString& imapPathForCreation() { return mImapPathCreation; }
00262   void setImapPathForCreation( const QString& path ) { mImapPathCreation = path; }
00263 
00264 protected slots:
00265   void slotGetMessagesData(KIO::Job * job, const QByteArray & data);
00266   void getMessagesResult(KMail::FolderJob *, bool lastSet);
00267   void slotGetLastMessagesResult(KMail::FolderJob *);
00268   void slotProgress(unsigned long done, unsigned long total);
00269   void slotPutProgress( unsigned long, unsigned long );
00270 
00271   //virtual void slotCheckValidityResult(KIO::Job * job);
00272   void slotSubFolderComplete(KMFolderCachedImap*, bool);
00273 
00274   // Connected to the imap account
00275   void slotConnectionResult( int errorCode, const QString& errorMsg );
00276 
00277   void slotCheckUidValidityResult( KMail::FolderJob* job );
00278   void slotTestAnnotationResult(KIO::Job *job);
00279   void slotGetAnnotationResult( KIO::Job* );
00280   void slotSetAnnotationResult(KIO::Job *job);
00281   void slotReceivedUserRights( KMFolder* );
00282   void slotReceivedACL( KMFolder*, KIO::Job*, const KMail::ACLList& );
00283 
00284   void slotMultiSetACLResult(KIO::Job *);
00285   void slotACLChanged( const QString&, int );
00286   void slotAnnotationResult(const QString& entry, const QString& value, bool found);
00287   void slotAnnotationChanged( const QString& entry, const QString& attribute, const QString& value );
00288   void slotDeleteMessagesResult(KMail::FolderJob *);
00289   void slotImapStatusChanged(KMFolder* folder, const QString&, bool);
00290 
00291 protected:
00292   /* returns true if there were messages to delete
00293      on the server */
00294   bool deleteMessages();
00295   void listMessages();
00296   void uploadNewMessages();
00297   void uploadFlags();
00298   void createNewFolders();
00299 
00300   void listDirectory2();
00301 
00302 
00305   virtual QValueList<unsigned long> findNewMessages();
00308   virtual QValueList<KMFolderCachedImap*> findNewFolders();
00309 
00311   virtual bool canRemoveFolder() const;
00312 
00314   virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
00315                                   QString partSpecifier, const AttachmentStrategy *as ) const;
00316   virtual FolderJob* doCreateJob( QPtrList<KMMessage>& msgList, const QString& sets,
00317                                   FolderJob::JobType jt, KMFolder *folder ) const;
00318 
00319   virtual void timerEvent( QTimerEvent* );
00320 
00321   /* update progress status */
00322   void newState( int progress, const QString& syncStatus );
00323 
00325   KMFolderCachedImap* findParent( const QString& path, const QString& name );  
00326 
00327 public slots:
00331   void slotSimpleData(KIO::Job * job, const QByteArray & data);
00332 
00336   void slotTroubleshoot();
00337 
00342   void slotListResult( const QStringList&, const QStringList&,
00343       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00344 
00349   void slotCheckNamespace( const QStringList&, const QStringList&,
00350       const QStringList&, const QStringList&, const ImapAccountBase::jobData& );
00351 
00352 private slots:
00353   void serverSyncInternal();
00354   void slotIncreaseProgress();
00355   void slotUpdateLastUid();
00356   void slotFolderDeletionOnServerFinished();
00357 
00358 signals:
00359   void folderComplete(KMFolderCachedImap *folder, bool success);
00360   void listComplete( KMFolderCachedImap* );
00361 
00365   void syncState( int state, int number );
00366 
00367 private:
00368   void setReadOnly( bool readOnly );
00369   QString state2String( int state ) const;
00370 
00372   enum {
00373     SYNC_STATE_INITIAL,
00374     SYNC_STATE_TEST_ANNOTATIONS,
00375     SYNC_STATE_PUT_MESSAGES,
00376     SYNC_STATE_UPLOAD_FLAGS,
00377     SYNC_STATE_CREATE_SUBFOLDERS,
00378     SYNC_STATE_LIST_NAMESPACES,
00379     SYNC_STATE_LIST_SUBFOLDERS,
00380     SYNC_STATE_LIST_SUBFOLDERS2,
00381     SYNC_STATE_DELETE_SUBFOLDERS,
00382     SYNC_STATE_LIST_MESSAGES,
00383     SYNC_STATE_DELETE_MESSAGES,
00384     SYNC_STATE_EXPUNGE_MESSAGES,
00385     SYNC_STATE_GET_MESSAGES,
00386     SYNC_STATE_HANDLE_INBOX,
00387     SYNC_STATE_GET_USERRIGHTS,
00388     SYNC_STATE_GET_ANNOTATIONS,
00389     SYNC_STATE_SET_ANNOTATIONS,
00390     SYNC_STATE_GET_ACLS,
00391     SYNC_STATE_SET_ACLS,
00392     SYNC_STATE_FIND_SUBFOLDERS,
00393     SYNC_STATE_SYNC_SUBFOLDERS,
00394     SYNC_STATE_CHECK_UIDVALIDITY,
00395     SYNC_STATE_RENAME_FOLDER
00396   } mSyncState;
00397 
00398   int mProgress;
00399   int mStatusFlagsJobs;
00400 
00401   QString mUidValidity;
00402   QString     mImapPath;
00403   imapState   mContentState, mSubfolderState;
00404   QStringList mSubfolderNames, mSubfolderPaths,
00405               mSubfolderMimeTypes, mSubfolderAttributes;
00406   QString     mAnnotationFolderType;
00407   IncidencesFor mIncidencesFor;
00408 
00409   bool        mHasInbox;
00410   bool        mIsSelected;
00411   bool        mCheckFlags;
00412   bool        mReadOnly;
00413   mutable QGuardedPtr<KMAcctCachedImap> mAccount;
00414 
00415   QIntDict<int> uidsOnServer;
00416   QValueList<ulong> uidsForDeletionOnServer;
00417   QValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
00418   QValueList<ulong> mUidsForDownload;
00419   QStringList       foldersForDeletionOnServer;
00420 
00421   QValueList<KMFolderCachedImap*> mSubfoldersForSync;
00422   KMFolderCachedImap* mCurrentSubfolder;
00423 
00427   QMap<ulong,int> uidMap;
00428   bool uidMapDirty;
00429   void reloadUidMap();
00430   int uidWriteTimer;
00431 
00441   ulong mLastUid;
00446   ulong mTentativeHighestUid;
00447 
00448   int mUserRights;
00449   ACLList mACLList;
00450 
00451   bool mSilentUpload;
00452   bool mFolderRemoved;
00453   //bool mHoldSyncs;
00454   bool mRecurse;
00459   bool mStatusChangedLocally;
00461   bool mAnnotationFolderTypeChanged;
00463   bool mIncidencesForChanged;
00464 
00465   QStringList mNamespacesToList;
00466   int mNamespacesToCheck;
00467   bool mPersonalNamespacesCheckDone;
00468   QString mImapPathCreation;
00469 };
00470 
00471 #endif /*kmfoldercachedimap_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys