kmailicalifaceimpl.h
00001 /* 00002 This file is part of KMail. 00003 00004 Copyright (c) 2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se> 00005 Copyright (c) 2003 - 2004 Bo Thorsen <bo@sonofthor.dk> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 00022 In addition, as a special exception, the copyright holders give 00023 permission to link the code of this program with any edition of 00024 the TQt library by Trolltech AS, Norway (or with modified versions 00025 of TQt that use the same license as TQt), and distribute linked 00026 combinations including the two. You must obey the GNU General 00027 Public License in all respects for all of the code used other than 00028 TQt. If you modify this file, you may extend this exception to 00029 your version of the file, but you are not obligated to do so. If 00030 you do not wish to do so, delete this exception statement from 00031 your version. 00032 */ 00033 00038 #ifndef KMAILICALIFACEIMPL_H 00039 #define KMAILICALIFACEIMPL_H 00040 00041 #include "kmailicalIface.h" 00042 #include "kmfoldertype.h" 00043 #include <kfoldertree.h> 00044 00045 #include <tqdict.h> 00046 #include <tqguardedptr.h> 00047 #include <tqmap.h> 00048 00049 class KMFolder; 00050 class KMMessage; 00051 class KMFolderDir; 00052 class KMFolderTreeItem; 00053 00054 namespace KMail { 00055 00056 // Local helper class 00057 class ExtraFolder { 00058 public: 00059 ExtraFolder( KMFolder* f ); 00060 ~ExtraFolder(); 00061 TQGuardedPtr<KMFolder> folder; 00062 }; 00063 00064 class Accumulator { 00065 public: 00066 Accumulator( const TQString& t, const TQString& f, int c ) 00067 :type( t ), folder( f ), count( c ) {} 00068 00069 void add( const TQString& incidence ) { 00070 incidences << incidence; 00071 count--; 00072 } 00073 bool isFull() { return count == 0; } 00074 00075 const TQString type; 00076 const TQString folder; 00077 TQStringList incidences; 00078 int count; 00079 }; 00080 00081 } 00082 00084 class KMailICalIfaceImpl : public TQObject, virtual public KMailICalIface { 00085 Q_OBJECT 00086 TQ_OBJECT 00087 public: 00088 KMailICalIfaceImpl(); 00089 00090 bool isWritableFolder( const TQString& type, const TQString& resource ); 00091 00092 StorageFormat storageFormat( const TQString &resource ); 00093 00099 TQ_UINT32 update( const TQString& resource, 00100 TQ_UINT32 sernum, 00101 const TQString& subject, 00102 const TQString& plainTextBody, 00103 const TQMap<TQCString, TQString>& customHeaders, 00104 const TQStringList& attachmentURLs, 00105 const TQStringList& attachmentMimetypes, 00106 const TQStringList& attachmentNames, 00107 const TQStringList& deletedAttachments ); 00108 00109 bool deleteIncidenceKolab( const TQString& resource, 00110 TQ_UINT32 sernum ); 00111 int incidencesKolabCount( const TQString& mimetype, 00112 const TQString& resource ); 00113 TQMap<TQ_UINT32, TQString> incidencesKolab( const TQString& mimetype, 00114 const TQString& resource, 00115 int startIndex, 00116 int nbMessages ); 00117 int dimapAccounts(); 00118 00119 TQValueList<SubResource> subresourcesKolab( const TQString& contentsType ); 00120 00121 bool triggerSync( const TQString& contentsType ); 00122 00123 // "Get" an attachment. This actually saves the attachment in a file 00124 // and returns a URL to it 00125 KURL getAttachment( const TQString& resource, 00126 TQ_UINT32 sernum, 00127 const TQString& filename ); 00128 00129 TQString attachmentMimetype( const TQString &resource, 00130 TQ_UINT32 sernum, 00131 const TQString &filename ); 00132 00133 TQStringList listAttachments( const TQString &resource, TQ_UINT32 sernum ); 00134 00135 00136 bool removeSubresource( const TQString& ); 00137 00138 bool addSubresource( const TQString& resource, 00139 const TQString& parent, 00140 const TQString& contentsType ); 00141 00142 // tell KOrganizer about messages to be deleted 00143 void msgRemoved( KMFolder*, KMMessage* ); 00144 00146 void initFolders(); 00147 00149 void cleanup(); 00150 00155 bool isResourceFolder( KMFolder* folder ) const; 00156 00157 /* Returns true if the folder is one of the standard resource folders, as 00158 * opposed to an extra folder. */ 00159 bool isStandardResourceFolder( KMFolder* folder ) const; 00160 00165 bool hideResourceFolder( KMFolder* folder ) const; 00166 00172 bool hideResourceAccountRoot( KMFolder* folder ) const; 00173 00178 KFolderTreeItem::Type folderType( KMFolder* folder ) const; 00179 00184 TQString folderPixmap( KFolderTreeItem::Type type ) const; 00185 00188 TQString folderName( KFolderTreeItem::Type type, int language = -1 ) const; 00189 00191 KMFolder* folderFromType( const TQString& type, const TQString& folder ); 00192 00194 TQString icalFolderType( KMFolder* folder ) const; 00195 00197 KMMessage* findMessageByUID( const TQString& uid, KMFolder* folder ); 00199 static KMMessage* findMessageBySerNum( TQ_UINT32 serNum, KMFolder* folder ); 00200 00202 void deleteMsg( KMMessage* msg ); 00203 00204 bool isEnabled() const { return mUseResourceIMAP; } 00205 00207 void folderContentsTypeChanged( KMFolder*, KMail::FolderContentsType ); 00208 00210 StorageFormat storageFormat( KMFolder* folder ) const; 00212 void setStorageFormat( KMFolder* folder, StorageFormat format ); 00213 00214 00215 static const char* annotationForContentsType( KMail::FolderContentsType type ); 00216 00217 // Called after a folder was synced with the server 00218 void folderSynced( KMFolder* folder, const KURL& folderURL ); 00219 // Called when deletion of a folder from the server suceeded, 00220 // triggers fb re-generation 00221 void folderDeletedOnServer( const KURL& folderURL ); 00222 void addFolderChange( KMFolder* folder, FolderChanges changes ); 00223 00224 // See CachedImapJob::slotPutMessageResult 00225 bool isResourceQuiet() const; 00226 void setResourceQuiet(bool q); 00227 00228 static TQMap<TQString, TQString>* getResourceMap() { return mSubResourceUINamesMap; } 00229 00230 public slots: 00231 /* (Re-)Read configuration file */ 00232 void readConfig(); 00233 void slotFolderRemoved( KMFolder* folder ); 00234 00235 void slotIncidenceAdded( KMFolder* folder, TQ_UINT32 sernum ); 00236 void slotIncidenceDeleted( KMFolder* folder, TQ_UINT32 sernum ); 00237 void slotRefresh( const TQString& type); 00238 00239 // Called when a folder is made readonly or readwrite, or renamed, 00240 // or any other similar change that affects the resources 00241 void slotFolderPropertiesChanged( KMFolder* folder ); 00242 void changeResourceUIName( const TQString &folderPath, const TQString &newName ); 00243 00244 private slots: 00245 void slotRefreshFolder( KMFolder* ); 00246 void slotCheckDone(); 00247 void slotFolderLocationChanged( const TQString&, const TQString& ); 00248 void slotFolderRenamed(); 00249 void slotMessageRetrieved( KMMessage* ); 00250 00251 private: 00253 KMFolder* initFolder( KMail::FolderContentsType contentsType ); 00254 KMFolder* initScalixFolder( KMail::FolderContentsType contentsType ); 00255 00256 void connectFolder( KMFolder* folder ); 00257 00258 KMFolder* extraFolder( const TQString& type, const TQString& folder ); 00259 00260 void syncFolder( KMFolder* folder ) const; 00261 00262 struct StandardFolderSearchResult 00263 { 00264 enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName }; 00265 StandardFolderSearchResult() : folder( 0 ) {} 00266 StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {} 00267 StandardFolderSearchResult( const TQValueList<KMFolder*> &f, FoundEnum e ) : 00268 folder( f.first() ), folders( f ), found( e ) {} 00269 KMFolder* folder; // NotFound implies folder==0 of course. 00270 TQValueList<KMFolder*> folders; // in case we found multiple default folders (which should not happen) 00271 FoundEnum found; 00272 }; 00273 00274 StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ); 00275 KMFolder* findResourceFolder( const TQString& resource ); 00276 00277 00278 bool updateAttachment( KMMessage& msg, 00279 const TQString& attachmentURL, 00280 const TQString& attachmentName, 00281 const TQString& attachmentMimetype, 00282 bool lookupByName ); 00283 bool deleteAttachment( KMMessage& msg, 00284 const TQString& attachmentURL ); 00285 TQ_UINT32 addIncidenceKolab( KMFolder& folder, 00286 const TQString& subject, 00287 const TQString& plainTextBody, 00288 const TQMap<TQCString, TQString>& customHeaders, 00289 const TQStringList& attachmentURLs, 00290 const TQStringList& attachmentNames, 00291 const TQStringList& attachmentMimetypes ); 00292 static bool kolabXMLFoundAndDecoded( const KMMessage& msg, const TQString& mimetype, TQString& s ); 00293 00294 void handleFolderSynced( KMFolder* folder, 00295 const KURL& folderURL, 00296 int _changes ); 00297 void triggerKolabFreeBusy( const KURL& folderURL ); 00298 00299 StorageFormat globalStorageFormat() const; 00300 00301 static bool folderIsAlarmRelevant( const KMFolder * ); 00302 00303 private: 00304 TQGuardedPtr<KMFolder> mContacts; 00305 TQGuardedPtr<KMFolder> mCalendar; 00306 TQGuardedPtr<KMFolder> mNotes; 00307 TQGuardedPtr<KMFolder> mTasks; 00308 TQGuardedPtr<KMFolder> mJournals; 00309 00310 // The extra IMAP resource folders 00311 // Key: folder location. Data: folder. 00312 TQDict<KMail::ExtraFolder> mExtraFolders; 00313 // used for collecting incidences during async loading 00314 TQDict<KMail::Accumulator> mAccumulators; 00315 // More info for each folder we care about (mContacts etc. as well as the extra folders) 00316 // The reason for storing it here is that it can be shared between 00317 // kmfoldercachedimap and kmfolderimap, and that it's groupware data anyway. 00318 struct FolderInfo { 00319 FolderInfo() {} // for TQMap 00320 FolderInfo( StorageFormat f, FolderChanges c ) : 00321 mStorageFormat( f ), mChanges( c ) {} 00322 StorageFormat mStorageFormat; 00323 FolderChanges mChanges; 00324 }; 00325 // The storage format used for each folder that we care about 00326 typedef TQMap<KMFolder*, FolderInfo> FolderInfoMap; 00327 // helper for reading the FolderInfo from the config file 00328 FolderInfo readFolderInfo( const KMFolder * const folder ) const; 00329 00330 FolderInfoMap mFolderInfoMap; 00331 00332 unsigned int mFolderLanguage; 00333 00334 KMFolderDir* mFolderParentDir; 00335 KMFolder* mFolderParent; 00336 KMFolderType mFolderType; 00337 00338 bool mUseResourceIMAP; 00339 bool mResourceQuiet; 00340 bool mHideFolders; 00341 00342 /* 00343 * Bunch of maps to keep track of incidents currently in transfer, ones 00344 * which need to be ungotten, once we are done, once with updates pending. 00345 * Since these are transient attributes of only a small but changing number 00346 * of incidences they are not encapsulated in a struct or somesuch. 00347 */ 00348 TQMap<TQString, TQ_UINT32> mUIDToSerNum; 00349 TQMap<TQ_UINT32, bool> mTheUnGetMes; 00350 TQMap<TQString, TQString> mPendingUpdates; 00351 TQMap<TQString, bool> mInTransit; 00352 static TQMap<TQString, TQString> *mSubResourceUINamesMap; 00353 00354 }; 00355 00356 #endif // KMAILICALIFACEIMPL_H