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 KIO {
00055 class Job;
00056 }
00057 
00058 namespace KMail {
00059 
00060   // Local helper class
00061 class ExtraFolder {
00062 public:
00063   ExtraFolder( KMFolder* f );
00064   ~ExtraFolder();
00065   QGuardedPtr<KMFolder> folder;
00066 };
00067 
00068 class Accumulator {
00069 public:
00070   Accumulator( const QString& t, const QString& f, int c )
00071   :type( t ), folder( f ), count( c ) {}
00072 
00073   void add( const QString& incidence ) {
00074     incidences << incidence;
00075     count--;
00076   }
00077   bool isFull() { return count == 0; }
00078 
00079   const QString type;
00080   const QString folder;
00081   QStringList incidences;
00082   int count;
00083 };
00084 
00085 }
00086 
00088 class KMailICalIfaceImpl : public QObject, virtual public KMailICalIface {
00089   Q_OBJECT
00090 public:
00091   KMailICalIfaceImpl();
00092 
00093   bool isWritableFolder( const QString& type, const QString& resource );
00094 
00095   StorageFormat storageFormat( const QString &resource );
00096 
00102   Q_UINT32 update( const QString& resource,
00103                    Q_UINT32 sernum,
00104                    const QString& subject,
00105                    const QString& plainTextBody,
00106                    const QMap<QCString, QString>& customHeaders,
00107                    const QStringList& attachmentURLs,
00108                    const QStringList& attachmentMimetypes,
00109                    const QStringList& attachmentNames,
00110                    const QStringList& deletedAttachments );
00111 
00112   bool deleteIncidenceKolab( const QString& resource,
00113                              Q_UINT32 sernum );
00114   int incidencesKolabCount( const QString& mimetype,
00115                             const QString& resource );
00116   QMap<Q_UINT32, QString> incidencesKolab( const QString& mimetype,
00117                                            const QString& resource,
00118                                            int startIndex,
00119                                            int nbMessages );
00120   int dimapAccounts();
00121   QString dimapFolderAccountName( const QString &folderPath );
00122 
00123   QValueList<SubResource> subresourcesKolab( const QString& contentsType );
00124 
00125   bool triggerSync( const QString& contentsType );
00126 
00127   // "Get" an attachment. This actually saves the attachment in a file
00128   // and returns a URL to it
00129   KURL getAttachment( const QString& resource,
00130                       Q_UINT32 sernum,
00131                       const QString& filename );
00132 
00133   QString attachmentMimetype( const QString &resource,
00134                               Q_UINT32 sernum,
00135                               const QString &filename );
00136 
00137   QStringList listAttachments( const QString &resource, Q_UINT32 sernum );
00138 
00139 
00140   bool removeSubresource( const QString& );
00141 
00142   bool addSubresource( const QString& resource,
00143                        const QString& parent,
00144                        const QString& contentsType );
00145 
00146   // tell KOrganizer about messages to be deleted
00147   void msgRemoved( KMFolder*, KMMessage* );
00148 
00150   void initFolders();
00151 
00153   void cleanup();
00154 
00159   bool isResourceFolder( KMFolder* folder ) const;
00160 
00161   /* Returns true if the folder is one of the standard resource folders, as
00162    * opposed to an extra folder. */
00163   bool isStandardResourceFolder( KMFolder* folder ) const;
00164 
00169   bool hideResourceFolder( KMFolder* folder ) const;
00170 
00176   bool hideResourceAccountRoot( KMFolder* folder ) const;
00177 
00182   KFolderTreeItem::Type folderType( KMFolder* folder ) const;
00183 
00188   QString folderPixmap( KFolderTreeItem::Type type ) const;
00189 
00192   QString folderName( KFolderTreeItem::Type type, int language = -1 ) const;
00193 
00195   KMFolder* folderFromType( const QString& type, const QString& folder );
00196 
00198   QString icalFolderType( KMFolder* folder ) const;
00199 
00201   KMMessage* findMessageByUID( const QString& uid, KMFolder* folder );
00203   static KMMessage* findMessageBySerNum( Q_UINT32 serNum, KMFolder* folder );
00204 
00206   void deleteMsg( KMMessage* msg );
00207 
00208   bool isEnabled() const { return mUseResourceIMAP; }
00209 
00211   void folderContentsTypeChanged( KMFolder*, KMail::FolderContentsType );
00212 
00214   StorageFormat storageFormat( KMFolder* folder ) const;
00216   void setStorageFormat( KMFolder* folder, StorageFormat format );
00217 
00218 
00219   static const char* annotationForContentsType( KMail::FolderContentsType type );
00220 
00221   // Called after a folder was synced with the server
00222   void folderSynced( KMFolder* folder, const KURL& folderURL );
00223   // Called when deletion of a folder from the server suceeded,
00224   // triggers fb re-generation
00225   void folderDeletedOnServer( const KURL& folderURL );
00226   void addFolderChange( KMFolder* folder, FolderChanges changes );
00227 
00228   // See CachedImapJob::slotPutMessageResult
00229   bool isResourceQuiet() const;
00230   void setResourceQuiet(bool q);
00231 
00232   static QMap<QString, QString>* getResourceMap() { return mSubResourceUINamesMap; }
00233 
00234 public slots:
00235   /* (Re-)Read configuration file */
00236   void readConfig();
00237   void slotFolderRemoved( KMFolder* folder );
00238 
00239   void slotIncidenceAdded( KMFolder* folder, Q_UINT32 sernum );
00240   void slotIncidenceDeleted( KMFolder* folder, Q_UINT32 sernum );
00241   void slotRefresh( const QString& type);
00242 
00243   // Called when a folder is made readonly or readwrite, or renamed,
00244   // or any other similar change that affects the resources
00245   void slotFolderPropertiesChanged( KMFolder* folder );
00246   void changeResourceUIName( const QString &folderPath, const QString &newName );
00247 
00248 private slots:
00249   void slotRefreshFolder( KMFolder* );
00250   void slotCheckDone();
00251   void slotFolderLocationChanged( const QString&, const QString& );
00252   void slotFolderRenamed();
00253   void slotMessageRetrieved( KMMessage* );
00254   void slotFreeBusyTriggerResult( KIO::Job* );
00255 
00256 private:
00258   KMFolder* initFolder( KMail::FolderContentsType contentsType );
00259   KMFolder* initScalixFolder( KMail::FolderContentsType contentsType );
00260 
00261   void connectFolder( KMFolder* folder );
00262 
00263   KMFolder* extraFolder( const QString& type, const QString& folder );
00264 
00265   void syncFolder( KMFolder* folder ) const;
00266 
00267   struct StandardFolderSearchResult
00268   {
00269     enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName };
00270     StandardFolderSearchResult() : folder( 0 ) {}
00271     StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {}
00272     StandardFolderSearchResult( const QValueList<KMFolder*> &f, FoundEnum e ) :
00273         folder( f.first() ), folders( f ), found( e ) {}
00274     KMFolder* folder; // NotFound implies folder==0 of course.
00275     QValueList<KMFolder*> folders; // in case we found multiple default folders (which should not happen)
00276     FoundEnum found;
00277   };
00278 
00279   StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType );
00280   KMFolder* findResourceFolder( const QString& resource );
00281 
00282 
00283   bool updateAttachment( KMMessage& msg,
00284                          const QString& attachmentURL,
00285                          const QString& attachmentName,
00286                          const QString& attachmentMimetype,
00287                          bool lookupByName );
00288   bool deleteAttachment( KMMessage& msg,
00289                          const QString& attachmentURL );
00290   Q_UINT32 addIncidenceKolab( KMFolder& folder,
00291                               const QString& subject,
00292                               const QString& plainTextBody,
00293                               const QMap<QCString, QString>& customHeaders,
00294                               const QStringList& attachmentURLs,
00295                               const QStringList& attachmentNames,
00296                               const QStringList& attachmentMimetypes );
00297   static bool kolabXMLFoundAndDecoded( const KMMessage& msg, const QString& mimetype, QString& s );
00298 
00299   void handleFolderSynced( KMFolder* folder,
00300                            const KURL& folderURL,
00301                            int _changes );
00302   void triggerKolabFreeBusy( const KURL& folderURL, bool report );
00303 
00304   StorageFormat globalStorageFormat() const;
00305 
00306   static bool folderIsAlarmRelevant( const KMFolder * );
00307 
00308 private:
00309   QGuardedPtr<KMFolder> mContacts;
00310   QGuardedPtr<KMFolder> mCalendar;
00311   QGuardedPtr<KMFolder> mNotes;
00312   QGuardedPtr<KMFolder> mTasks;
00313   QGuardedPtr<KMFolder> mJournals;
00314 
00315   // The extra IMAP resource folders
00316   // Key: folder location. Data: folder.
00317   QDict<KMail::ExtraFolder> mExtraFolders;
00318   // used for collecting incidences during async loading
00319   QDict<KMail::Accumulator> mAccumulators;
00320   // More info for each folder we care about (mContacts etc. as well as the extra folders)
00321   // The reason for storing it here is that it can be shared between
00322   // kmfoldercachedimap and kmfolderimap, and that it's groupware data anyway.
00323   struct FolderInfo {
00324     FolderInfo() {} // for QMap
00325     FolderInfo( StorageFormat f, FolderChanges c ) :
00326       mStorageFormat( f ), mChanges( c ) {}
00327     StorageFormat mStorageFormat;
00328     FolderChanges mChanges;
00329   };
00330   // The storage format used for each folder that we care about
00331   typedef QMap<KMFolder*, FolderInfo> FolderInfoMap;
00332   // helper for reading the FolderInfo from the config file
00333   FolderInfo readFolderInfo( const KMFolder * const folder ) const;
00334 
00335   FolderInfoMap mFolderInfoMap;
00336 
00337   unsigned int mFolderLanguage;
00338 
00339   KMFolderDir* mFolderParentDir;
00340   KMFolder*    mFolderParent;
00341   KMFolderType mFolderType;
00342 
00343   bool mUseResourceIMAP;
00344   bool mResourceQuiet;
00345   bool mHideFolders;
00346 
00347   /*
00348    * Bunch of maps to keep track of incidents currently in transfer, ones
00349    * which need to be ungotten, once we are done, once with updates pending.
00350    * Since these are transient attributes of only a small but changing number
00351    * of incidences they are not encapsulated in a struct or somesuch.
00352    */
00353   QMap<QString, Q_UINT32> mUIDToSerNum;
00354   QMap<Q_UINT32, bool> mTheUnGetMes;
00355   QMap<QString, QString> mPendingUpdates;
00356   QMap<QString, bool> mInTransit;
00357   static QMap<QString, QString> *mSubResourceUINamesMap;
00358 
00359 };
00360 
00361 #endif // KMAILICALIFACEIMPL_H
KDE Home | KDE Accessibility Home | Description of Access Keys