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 );
00205   static KMMessage* findMessageBySerNum( Q_UINT32 serNum, KMFolder* folder );
00206 
00208   void deleteMsg( KMMessage* msg );
00209 
00210   bool isEnabled() const { return mUseResourceIMAP; }
00211 
00213   void folderContentsTypeChanged( KMFolder*, KMail::FolderContentsType );
00214 
00216   StorageFormat storageFormat( KMFolder* folder ) const;
00218   void setStorageFormat( KMFolder* folder, StorageFormat format );
00219 
00220 
00221   static const char* annotationForContentsType( KMail::FolderContentsType type );
00222 
00223   // Called after a folder was synced with the server
00224   void folderSynced( KMFolder* folder, const KURL& folderURL );
00225   // Called when deletion of a folder from the server suceeded,
00226   // triggers fb re-generation
00227   void folderDeletedOnServer( const KURL& folderURL );
00228   void addFolderChange( KMFolder* folder, FolderChanges changes );
00229 
00230   // See CachedImapJob::slotPutMessageResult
00231   bool isResourceQuiet() const;
00232   void setResourceQuiet(bool q);
00233 
00234   static QMap<QString, QString>* getResourceMap() { return mSubResourceUINamesMap; }
00235 
00236 public slots:
00237   /* (Re-)Read configuration file */
00238   void readConfig();
00239   void slotFolderRemoved( KMFolder* folder );
00240 
00241   void slotIncidenceAdded( KMFolder* folder, Q_UINT32 sernum );
00242   void slotIncidenceDeleted( KMFolder* folder, Q_UINT32 sernum );
00243   void slotRefresh( const QString& type);
00244 
00245   // Called when a folder is made readonly or readwrite, or renamed,
00246   // or any other similar change that affects the resources
00247   void slotFolderPropertiesChanged( KMFolder* folder );
00248   void changeResourceUIName( const QString &folderPath, const QString &newName );
00249 
00250 private slots:
00251   void slotRefreshFolder( KMFolder* );
00252   void slotCheckDone();
00253   void slotFolderLocationChanged( const QString&, const QString& );
00254   void slotFolderRenamed();
00255   void slotMessageRetrieved( KMMessage* );
00256   void slotFreeBusyTriggerResult( KIO::Job* );
00257 
00258 private:
00260   KMFolder* initFolder( KMail::FolderContentsType contentsType );
00261   KMFolder* initScalixFolder( KMail::FolderContentsType contentsType );
00262 
00263   void connectFolder( KMFolder* folder );
00264 
00265   KMFolder* extraFolder( const QString& type, const QString& folder );
00266 
00267   void syncFolder( KMFolder* folder ) const;
00268 
00269   struct StandardFolderSearchResult
00270   {
00271     enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName };
00272     StandardFolderSearchResult() : folder( 0 ) {}
00273     StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {}
00274     StandardFolderSearchResult( const QValueList<KMFolder*> &f, FoundEnum e ) :
00275         folder( f.first() ), folders( f ), found( e ) {}
00276     KMFolder* folder; // NotFound implies folder==0 of course.
00277     QValueList<KMFolder*> folders; // in case we found multiple default folders (which should not happen)
00278     FoundEnum found;
00279   };
00280 
00281   StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType );
00282   KMFolder* findResourceFolder( const QString& resource );
00283 
00284 
00285   bool updateAttachment( KMMessage& msg,
00286                          const QString& attachmentURL,
00287                          const QString& attachmentName,
00288                          const QString& attachmentMimetype,
00289                          bool lookupByName );
00290   bool deleteAttachment( KMMessage& msg,
00291                          const QString& attachmentURL );
00292   Q_UINT32 addIncidenceKolab( KMFolder& folder,
00293                               const QString& subject,
00294                               const QString& plainTextBody,
00295                               const QMap<QCString, QString>& customHeaders,
00296                               const QStringList& attachmentURLs,
00297                               const QStringList& attachmentNames,
00298                               const QStringList& attachmentMimetypes );
00299   static bool kolabXMLFoundAndDecoded( const KMMessage& msg, const QString& mimetype, QString& s );
00300 
00301   void handleFolderSynced( KMFolder* folder,
00302                            const KURL& folderURL,
00303                            int _changes );
00304   void triggerKolabFreeBusy( const KURL& folderURL, bool report );
00305 
00306   StorageFormat globalStorageFormat() const;
00307 
00308   static bool folderIsAlarmRelevant( const KMFolder * );
00309 
00310 private:
00311   QGuardedPtr<KMFolder> mContacts;
00312   QGuardedPtr<KMFolder> mCalendar;
00313   QGuardedPtr<KMFolder> mNotes;
00314   QGuardedPtr<KMFolder> mTasks;
00315   QGuardedPtr<KMFolder> mJournals;
00316 
00317   // The extra IMAP resource folders
00318   // Key: folder location. Data: folder.
00319   QDict<KMail::ExtraFolder> mExtraFolders;
00320   // used for collecting incidences during async loading
00321   QDict<KMail::Accumulator> mAccumulators;
00322   // More info for each folder we care about (mContacts etc. as well as the extra folders)
00323   // The reason for storing it here is that it can be shared between
00324   // kmfoldercachedimap and kmfolderimap, and that it's groupware data anyway.
00325   struct FolderInfo {
00326     FolderInfo() {} // for QMap
00327     FolderInfo( StorageFormat f, FolderChanges c ) :
00328       mStorageFormat( f ), mChanges( c ) {}
00329     StorageFormat mStorageFormat;
00330     FolderChanges mChanges;
00331   };
00332   // The storage format used for each folder that we care about
00333   typedef QMap<KMFolder*, FolderInfo> FolderInfoMap;
00334   // helper for reading the FolderInfo from the config file
00335   FolderInfo readFolderInfo( const KMFolder * const folder ) const;
00336 
00337   FolderInfoMap mFolderInfoMap;
00338 
00339   unsigned int mFolderLanguage;
00340 
00341   KMFolderDir* mFolderParentDir;
00342   KMFolder*    mFolderParent;
00343   KMFolderType mFolderType;
00344 
00345   bool mUseResourceIMAP;
00346   bool mResourceQuiet;
00347   bool mHideFolders;
00348 
00349   /*
00350    * Bunch of maps to keep track of incidents currently in transfer, ones
00351    * which need to be ungotten, once we are done, once with updates pending.
00352    * Since these are transient attributes of only a small but changing number
00353    * of incidences they are not encapsulated in a struct or somesuch.
00354    */
00355   QMap<QString, Q_UINT32> mUIDToSerNum;
00356   QMap<Q_UINT32, bool> mTheUnGetMes;
00357   QMap<QString, QString> mPendingUpdates;
00358   QMap<QString, bool> mInTransit;
00359   static QMap<QString, QString> *mSubResourceUINamesMap;
00360 };
00361 
00362 #endif // KMAILICALIFACEIMPL_H
KDE Home | KDE Accessibility Home | Description of Access Keys