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