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