kmail

kmailicalifaceimpl.h
1 /*
2  This file is part of KMail.
3 
4  Copyright (c) 2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
5  Copyright (c) 2003 - 2004 Bo Thorsen <bo@sonofthor.dk>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the TQt library by Trolltech AS, Norway (or with modified versions
25  of TQt that use the same license as TQt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  TQt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 */
33 
38 #ifndef KMAILICALIFACEIMPL_H
39 #define KMAILICALIFACEIMPL_H
40 
41 #include "kmailicalIface.h"
42 #include "kmfoldertype.h"
43 #include <kfoldertree.h>
44 
45 #include <tqdict.h>
46 #include <tqguardedptr.h>
47 #include <tqmap.h>
48 
49 class KMFolder;
50 class KMMessage;
51 class KMFolderDir;
52 class KMFolderTreeItem;
53 
54 namespace KMail {
55 
56  // Local helper class
57 class ExtraFolder {
58 public:
59  ExtraFolder( KMFolder* f );
60  ~ExtraFolder();
61  TQGuardedPtr<KMFolder> folder;
62 };
63 
64 class Accumulator {
65 public:
66  Accumulator( const TQString& t, const TQString& f, int c )
67  :type( t ), folder( f ), count( c ) {}
68 
69  void add( const TQString& incidence ) {
70  incidences << incidence;
71  count--;
72  }
73  bool isFull() { return count == 0; }
74 
75  const TQString type;
76  const TQString folder;
77  TQStringList incidences;
78  int count;
79 };
80 
81 }
82 
84 class KMailICalIfaceImpl : public TQObject, virtual public KMailICalIface {
85  TQ_OBJECT
86 
87 public:
89 
90  bool isWritableFolder( const TQString& type, const TQString& resource );
91 
92  StorageFormat storageFormat( const TQString &resource );
93 
99  TQ_UINT32 update( const TQString& resource,
100  TQ_UINT32 sernum,
101  const TQString& subject,
102  const TQString& plainTextBody,
103  const TQMap<TQCString, TQString>& customHeaders,
104  const TQStringList& attachmentURLs,
105  const TQStringList& attachmentMimetypes,
106  const TQStringList& attachmentNames,
107  const TQStringList& deletedAttachments );
108 
109  bool deleteIncidenceKolab( const TQString& resource,
110  TQ_UINT32 sernum );
111  int incidencesKolabCount( const TQString& mimetype,
112  const TQString& resource );
113  TQMap<TQ_UINT32, TQString> incidencesKolab( const TQString& mimetype,
114  const TQString& resource,
115  int startIndex,
116  int nbMessages );
117  int dimapAccounts();
118 
119  TQValueList<SubResource> subresourcesKolab( const TQString& contentsType );
120 
121  bool triggerSync( const TQString& contentsType );
122 
123  // "Get" an attachment. This actually saves the attachment in a file
124  // and returns a URL to it
125  KURL getAttachment( const TQString& resource,
126  TQ_UINT32 sernum,
127  const TQString& filename );
128 
129  TQString attachmentMimetype( const TQString &resource,
130  TQ_UINT32 sernum,
131  const TQString &filename );
132 
133  TQStringList listAttachments( const TQString &resource, TQ_UINT32 sernum );
134 
135 
136  bool removeSubresource( const TQString& );
137 
138  bool addSubresource( const TQString& resource,
139  const TQString& parent,
140  const TQString& contentsType );
141 
142  // tell KOrganizer about messages to be deleted
143  void msgRemoved( KMFolder*, KMMessage* );
144 
146  void initFolders();
147 
149  void cleanup();
150 
155  bool isResourceFolder( KMFolder* folder ) const;
156 
157  /* Returns true if the folder is one of the standard resource folders, as
158  * opposed to an extra folder. */
159  bool isStandardResourceFolder( KMFolder* folder ) const;
160 
165  bool hideResourceFolder( KMFolder* folder ) const;
166 
172  bool hideResourceAccountRoot( KMFolder* folder ) const;
173 
178  KFolderTreeItem::Type folderType( KMFolder* folder ) const;
179 
184  TQString folderPixmap( KFolderTreeItem::Type type ) const;
185 
188  TQString folderName( KFolderTreeItem::Type type, int language = -1 ) const;
189 
191  KMFolder* folderFromType( const TQString& type, const TQString& folder );
192 
194  TQString icalFolderType( KMFolder* folder ) const;
195 
197  KMMessage* findMessageByUID( const TQString& uid, KMFolder* folder );
199  static KMMessage* findMessageBySerNum( TQ_UINT32 serNum, KMFolder* folder );
200 
202  void deleteMsg( KMMessage* msg );
203 
204  bool isEnabled() const { return mUseResourceIMAP; }
205 
207  void folderContentsTypeChanged( KMFolder*, KMail::FolderContentsType );
208 
210  StorageFormat storageFormat( KMFolder* folder ) const;
212  void setStorageFormat( KMFolder* folder, StorageFormat format );
213 
214 
215  static const char* annotationForContentsType( KMail::FolderContentsType type );
216 
217  // Called after a folder was synced with the server
218  void folderSynced( KMFolder* folder, const KURL& folderURL );
219  // Called when deletion of a folder from the server suceeded,
220  // triggers fb re-generation
221  void folderDeletedOnServer( const KURL& folderURL );
222  void addFolderChange( KMFolder* folder, FolderChanges changes );
223 
224  // See CachedImapJob::slotPutMessageResult
225  bool isResourceQuiet() const;
226  void setResourceQuiet(bool q);
227 
228  static TQMap<TQString, TQString>* getResourceMap() { return mSubResourceUINamesMap; }
229 
230 public slots:
231  /* (Re-)Read configuration file */
232  void readConfig();
233  void slotFolderRemoved( KMFolder* folder );
234 
235  void slotIncidenceAdded( KMFolder* folder, TQ_UINT32 sernum );
236  void slotIncidenceDeleted( KMFolder* folder, TQ_UINT32 sernum );
237  void slotRefresh( const TQString& type);
238 
239  // Called when a folder is made readonly or readwrite, or renamed,
240  // or any other similar change that affects the resources
241  void slotFolderPropertiesChanged( KMFolder* folder );
242  void changeResourceUIName( const TQString &folderPath, const TQString &newName );
243 
244 private slots:
245  void slotRefreshFolder( KMFolder* );
246  void slotCheckDone();
247  void slotFolderLocationChanged( const TQString&, const TQString& );
248  void slotFolderRenamed();
249  void slotMessageRetrieved( KMMessage* );
250 
251 private:
253  KMFolder* initFolder( KMail::FolderContentsType contentsType );
254  KMFolder* initScalixFolder( KMail::FolderContentsType contentsType );
255 
256  void connectFolder( KMFolder* folder );
257 
258  KMFolder* extraFolder( const TQString& type, const TQString& folder );
259 
260  void syncFolder( KMFolder* folder ) const;
261 
262  struct StandardFolderSearchResult
263  {
264  enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName };
265  StandardFolderSearchResult() : folder( 0 ) {}
266  StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {}
267  StandardFolderSearchResult( const TQValueList<KMFolder*> &f, FoundEnum e ) :
268  folder( f.first() ), folders( f ), found( e ) {}
269  KMFolder* folder; // NotFound implies folder==0 of course.
270  TQValueList<KMFolder*> folders; // in case we found multiple default folders (which should not happen)
271  FoundEnum found;
272  };
273 
274  StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType );
275  KMFolder* findResourceFolder( const TQString& resource );
276 
277 
278  bool updateAttachment( KMMessage& msg,
279  const TQString& attachmentURL,
280  const TQString& attachmentName,
281  const TQString& attachmentMimetype,
282  bool lookupByName );
283  bool deleteAttachment( KMMessage& msg,
284  const TQString& attachmentURL );
285  TQ_UINT32 addIncidenceKolab( KMFolder& folder,
286  const TQString& subject,
287  const TQString& plainTextBody,
288  const TQMap<TQCString, TQString>& customHeaders,
289  const TQStringList& attachmentURLs,
290  const TQStringList& attachmentNames,
291  const TQStringList& attachmentMimetypes );
292  static bool kolabXMLFoundAndDecoded( const KMMessage& msg, const TQString& mimetype, TQString& s );
293 
294  void handleFolderSynced( KMFolder* folder,
295  const KURL& folderURL,
296  int _changes );
297  void triggerKolabFreeBusy( const KURL& folderURL );
298 
299  StorageFormat globalStorageFormat() const;
300 
301  static bool folderIsAlarmRelevant( const KMFolder * );
302 
303 private:
304  TQGuardedPtr<KMFolder> mContacts;
305  TQGuardedPtr<KMFolder> mCalendar;
306  TQGuardedPtr<KMFolder> mNotes;
307  TQGuardedPtr<KMFolder> mTasks;
308  TQGuardedPtr<KMFolder> mJournals;
309 
310  // The extra IMAP resource folders
311  // Key: folder location. Data: folder.
312  TQDict<KMail::ExtraFolder> mExtraFolders;
313  // used for collecting incidences during async loading
314  TQDict<KMail::Accumulator> mAccumulators;
315  // More info for each folder we care about (mContacts etc. as well as the extra folders)
316  // The reason for storing it here is that it can be shared between
317  // kmfoldercachedimap and kmfolderimap, and that it's groupware data anyway.
318  struct FolderInfo {
319  FolderInfo() {} // for TQMap
320  FolderInfo( StorageFormat f, FolderChanges c ) :
321  mStorageFormat( f ), mChanges( c ) {}
322  StorageFormat mStorageFormat;
323  FolderChanges mChanges;
324  };
325  // The storage format used for each folder that we care about
326  typedef TQMap<KMFolder*, FolderInfo> FolderInfoMap;
327  // helper for reading the FolderInfo from the config file
328  FolderInfo readFolderInfo( const KMFolder * const folder ) const;
329 
330  FolderInfoMap mFolderInfoMap;
331 
332  unsigned int mFolderLanguage;
333 
334  KMFolderDir* mFolderParentDir;
335  KMFolder* mFolderParent;
336  KMFolderType mFolderType;
337 
338  bool mUseResourceIMAP;
339  bool mResourceQuiet;
340  bool mHideFolders;
341 
342  /*
343  * Bunch of maps to keep track of incidents currently in transfer, ones
344  * which need to be ungotten, once we are done, once with updates pending.
345  * Since these are transient attributes of only a small but changing number
346  * of incidences they are not encapsulated in a struct or somesuch.
347  */
348  TQMap<TQString, TQ_UINT32> mUIDToSerNum;
349  TQMap<TQ_UINT32, bool> mTheUnGetMes;
350  TQMap<TQString, TQString> mPendingUpdates;
351  TQMap<TQString, bool> mInTransit;
352  static TQMap<TQString, TQString> *mSubResourceUINamesMap;
353 
354 };
355 
356 #endif // KMAILICALIFACEIMPL_H
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
The implementation of the interface.
static KMMessage * findMessageBySerNum(TQ_UINT32 serNum, KMFolder *folder)
Find message matching a given serial number.
bool isResourceFolder(KMFolder *folder) const
Returns true if resource mode is enabled and folder is one of the resource folders.
void initFolders()
Initialize all folders.
KMFolder * folderFromType(const TQString &type, const TQString &folder)
Get the folder that holds type entries.
TQString icalFolderType(KMFolder *folder) const
Return the ical type of a folder.
TQ_UINT32 update(const TQString &resource, TQ_UINT32 sernum, const TQString &subject, const TQString &plainTextBody, const TQMap< TQCString, TQString > &customHeaders, const TQStringList &attachmentURLs, const TQStringList &attachmentMimetypes, const TQStringList &attachmentNames, const TQStringList &deletedAttachments)
Update a kolab storage entry.
bool hideResourceAccountRoot(KMFolder *folder) const
Returns true if the given folder is the root of the groupware account, groupware folders are hidden,...
TQString folderPixmap(KFolderTreeItem::Type type) const
Returns the name of the standard icon for a folder of given type or TQString() if the type is no grou...
KMMessage * findMessageByUID(const TQString &uid, KMFolder *folder)
Find message matching a given UID.
KFolderTreeItem::Type folderType(KMFolder *folder) const
Returns the resource folder type.
void deleteMsg(KMMessage *msg)
Convenience function to delete a message.
void cleanup()
Disconnect all slots and close the dirs.
TQMap< TQ_UINT32, TQString > incidencesKolab(const TQString &mimetype, const TQString &resource, int startIndex, int nbMessages)
bool hideResourceFolder(KMFolder *folder) const
Returns true if isResourceFolder( folder ) returns true, and imap folders should be hidden.
TQString folderName(KFolderTreeItem::Type type, int language=-1) const
Returns the localized name of a folder of given type.
void folderContentsTypeChanged(KMFolder *, KMail::FolderContentsType)
Called when a folders contents have changed.
void setStorageFormat(KMFolder *folder, StorageFormat format)
Set the storage format of a given folder. Called when seeing the kolab annotation.
folderdiaquotatab.h
Definition: aboutdata.cpp:40