kmail

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 Qt library by Trolltech AS, Norway (or with modified versions
00025     of Qt that use the same license as Qt), 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     Qt.  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 <qdict.h>
00046 #include <qguardedptr.h>
00047 #include <qmap.h>
00048 
00049 class KMFolder;
00050 class KMMessage;
00051 class KMFolderDir;
00052 class KMFolderTreeItem;
00053 
00054 namespace {
00055 
00056   // Local helper class
00057 class ExtraFolder {
00058 public:
00059   ExtraFolder( KMFolder* f ) : folder( f ) {}
00060   QGuardedPtr<KMFolder> folder;
00061 };
00062 
00063 class Accumulator {
00064 public:
00065   Accumulator( const QString& t, const QString& f, int c )
00066   :type( t ), folder( f ), count( c ) {}
00067 
00068   void add( const QString& incidence ) {
00069     incidences << incidence;
00070     count--;
00071   }
00072   bool isFull() { return count == 0; }
00073 
00074   const QString type;
00075   const QString folder;
00076   QStringList incidences;
00077   int count;
00078 };
00079 
00080 }
00081 
00083 class KMailICalIfaceImpl : public QObject, virtual public KMailICalIface {
00084   Q_OBJECT
00085 public:
00086   KMailICalIfaceImpl();
00087 
00088   bool isWritableFolder( const QString& type, const QString& resource );
00089 
00090   StorageFormat storageFormat( const QString &resource );
00091 
00097   Q_UINT32 update( const QString& resource,
00098                    Q_UINT32 sernum,
00099                    const QString& subject,
00100                    const QString& plainTextBody,
00101                    const QMap<QCString, QString>& customHeaders,
00102                    const QStringList& attachmentURLs,
00103                    const QStringList& attachmentMimetypes,
00104                    const QStringList& attachmentNames,
00105                    const QStringList& deletedAttachments );
00106 
00107   bool deleteIncidenceKolab( const QString& resource,
00108                              Q_UINT32 sernum );
00109   int incidencesKolabCount( const QString& mimetype,
00110                             const QString& resource );
00111   QMap<Q_UINT32, QString> incidencesKolab( const QString& mimetype,
00112                                            const QString& resource,
00113                                            int startIndex,
00114                                            int nbMessages );
00115 
00116   QValueList<SubResource> subresourcesKolab( const QString& contentsType );
00117 
00118   bool triggerSync( const QString& contentsType );
00119 
00120   // "Get" an attachment. This actually saves the attachment in a file
00121   // and returns a URL to it
00122   KURL getAttachment( const QString& resource,
00123                       Q_UINT32 sernum,
00124                       const QString& filename );
00125 
00126 
00127   // tell KOrganizer about messages to be deleted
00128   void msgRemoved( KMFolder*, KMMessage* );
00129 
00131   void initFolders();
00132 
00134   void cleanup();
00135 
00140   bool isResourceFolder( KMFolder* folder ) const;
00141 
00142   /* Returns true if the folder is one of the standard resource folders, as
00143    * opposed to an extra folder. */
00144   bool isStandardResourceFolder( KMFolder* folder ) const;
00145 
00150   bool hideResourceFolder( KMFolder* folder ) const;
00151 
00156   KFolderTreeItem::Type folderType( KMFolder* folder ) const;
00157 
00162   QString folderPixmap( KFolderTreeItem::Type type ) const;
00163 
00166   QString folderName( KFolderTreeItem::Type type, int language = -1 ) const;
00167 
00169   KMFolder* folderFromType( const QString& type, const QString& folder );
00170 
00172   QString icalFolderType( KMFolder* folder ) const;
00173 
00175   KMMessage* findMessageByUID( const QString& uid, KMFolder* folder );
00177   static KMMessage* findMessageBySerNum( Q_UINT32 serNum, KMFolder* folder );
00178 
00180   void deleteMsg( KMMessage* msg );
00181 
00182   bool isEnabled() const { return mUseResourceIMAP; }
00183 
00185   void folderContentsTypeChanged( KMFolder*, KMail::FolderContentsType );
00186 
00188   StorageFormat storageFormat( KMFolder* folder ) const;
00190   void setStorageFormat( KMFolder* folder, StorageFormat format );
00191 
00192 
00193   static const char* annotationForContentsType( KMail::FolderContentsType type );
00194 
00195   // Called after a folder was synced with the server
00196   void folderSynced( KMFolder* folder, const KURL& folderURL );
00197   // Called when deletion of a folder from the server suceeded,
00198   // triggers fb re-generation
00199   void folderDeletedOnServer( const KURL& folderURL );
00200   void addFolderChange( KMFolder* folder, FolderChanges changes );
00201 
00202   // See CachedImapJob::slotPutMessageResult
00203   bool isResourceQuiet() const;
00204   void setResourceQuiet(bool q);
00205 
00206 public slots:
00207   /* (Re-)Read configuration file */
00208   void readConfig();
00209   void slotFolderRemoved( KMFolder* folder );
00210 
00211   void slotIncidenceAdded( KMFolder* folder, Q_UINT32 sernum );
00212   void slotIncidenceDeleted( KMFolder* folder, Q_UINT32 sernum );
00213   void slotRefresh( const QString& type);
00214 
00215   // Called when a folder is made readonly or readwrite, or renamed,
00216   // or any other similar change that affects the resources
00217   void slotFolderPropertiesChanged( KMFolder* folder );
00218 
00219 private slots:
00220   void slotRefreshFolder( KMFolder* );
00221   void slotCheckDone();
00222   void slotFolderLocationChanged( const QString&, const QString& );
00223   void slotFolderRenamed();
00224   void slotMessageRetrieved( KMMessage* );
00225 
00226 private:
00228   KMFolder* initFolder( KMail::FolderContentsType contentsType );
00229 
00230   void connectFolder( KMFolder* folder );
00231 
00232   KMFolder* extraFolder( const QString& type, const QString& folder );
00233 
00234   struct StandardFolderSearchResult
00235   {
00236     enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName };
00237     StandardFolderSearchResult() : folder( 0 ) {}
00238     StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {}
00239     KMFolder* folder; // NotFound implies folder==0 of course.
00240     FoundEnum found;
00241   };
00242 
00243   StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType );
00244   KMFolder* findResourceFolder( const QString& resource );
00245 
00246 
00247   bool updateAttachment( KMMessage& msg,
00248                          const QString& attachmentURL,
00249                          const QString& attachmentName,
00250                          const QString& attachmentMimetype,
00251                          bool lookupByName );
00252   bool deleteAttachment( KMMessage& msg,
00253                          const QString& attachmentURL );
00254   Q_UINT32 addIncidenceKolab( KMFolder& folder,
00255                               const QString& subject,
00256                               const QString& plainTextBody,
00257                               const QMap<QCString, QString>& customHeaders,
00258                               const QStringList& attachmentURLs,
00259                               const QStringList& attachmentNames,
00260                               const QStringList& attachmentMimetypes );
00261   static bool kolabXMLFoundAndDecoded( const KMMessage& msg, const QString& mimetype, QString& s );
00262 
00263   void handleFolderSynced( KMFolder* folder,
00264                            const KURL& folderURL,
00265                            int _changes );
00266   void triggerKolabFreeBusy( const KURL& folderURL );
00267 
00268   StorageFormat globalStorageFormat() const;
00269 
00270 private:
00271   QGuardedPtr<KMFolder> mContacts;
00272   QGuardedPtr<KMFolder> mCalendar;
00273   QGuardedPtr<KMFolder> mNotes;
00274   QGuardedPtr<KMFolder> mTasks;
00275   QGuardedPtr<KMFolder> mJournals;
00276 
00277   // The extra IMAP resource folders
00278   // Key: folder location. Data: folder.
00279   QDict<ExtraFolder> mExtraFolders;
00280   // used for collecting incidences during async loading
00281   QDict<Accumulator> mAccumulators;
00282   // More info for each folder we care about (mContacts etc. as well as the extra folders)
00283   // The reason for storing it here is that it can be shared between
00284   // kmfoldercachedimap and kmfolderimap, and that it's groupware data anyway.
00285   struct FolderInfo {
00286     FolderInfo() {} // for QMap
00287     FolderInfo( StorageFormat f, FolderChanges c ) :
00288       mStorageFormat( f ), mChanges( c ) {}
00289     StorageFormat mStorageFormat;
00290     FolderChanges mChanges;
00291   };
00292   // The storage format used for each folder that we care about
00293   typedef QMap<KMFolder*, FolderInfo> FolderInfoMap;
00294   // helper for reading the FolderInfo from the config file
00295   FolderInfo readFolderInfo( const KMFolder * const folder ) const;
00296 
00297   FolderInfoMap mFolderInfoMap;
00298 
00299   unsigned int mFolderLanguage;
00300 
00301   KMFolderDir* mFolderParentDir;
00302   KMFolder*    mFolderParent;
00303   KMFolderType mFolderType;
00304 
00305   bool mUseResourceIMAP;
00306   bool mResourceQuiet;
00307   bool mHideFolders;
00308 
00309   /*
00310    * Bunch of maps to keep track of incidents currently in transfer, ones
00311    * which need to be ungotten, once we are done, once with updates pending.
00312    * Since these are transient attributes of only a small but changing number
00313    * of incidences they are not encapsulated in a struct or somesuch.
00314    */
00315   QMap<QString, Q_UINT32> mUIDToSerNum;
00316   QMap<Q_UINT32, bool> mTheUnGetMes;
00317   QMap<QString, QString> mPendingUpdates;
00318   QMap<QString, bool> mInTransit;
00319 
00320 };
00321 
00322 #endif // KMAILICALIFACEIMPL_H
KDE Home | KDE Accessibility Home | Description of Access Keys