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