~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kresources/kolab/kcal/resourcekolab.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the kolab resource - the implementation of the
3
 
    Kolab storage format. See www.kolab.org for documentation on this.
4
 
 
5
 
    Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
6
 
                  2004 Till Adam <till@klaralvdalens-datakonsult.se>
7
 
 
8
 
    This library is free software; you can redistribute it and/or
9
 
    modify it under the terms of the GNU Library General Public
10
 
    License as published by the Free Software Foundation; either
11
 
    version 2 of the License, or (at your option) any later version.
12
 
 
13
 
    This library is distributed in the hope that it will be useful,
14
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
    Library General Public License for more details.
17
 
 
18
 
    You should have received a copy of the GNU Library General Public License
19
 
    along with this library; see the file COPYING.LIB.  If not, write to
20
 
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 
    Boston, MA 02110-1301, USA.
22
 
 
23
 
    In addition, as a special exception, the copyright holders give
24
 
    permission to link the code of this program with any edition of
25
 
    the Qt library by Trolltech AS, Norway (or with modified versions
26
 
    of Qt that use the same license as Qt), and distribute linked
27
 
    combinations including the two.  You must obey the GNU General
28
 
    Public License in all respects for all of the code used other than
29
 
    Qt.  If you modify this file, you may extend this exception to
30
 
    your version of the file, but you are not obligated to do so.  If
31
 
    you do not wish to do so, delete this exception statement from
32
 
    your version.
33
 
*/
34
 
 
35
 
#ifndef KCAL_RESOURCEKOLAB_H
36
 
#define KCAL_RESOURCEKOLAB_H
37
 
 
38
 
#include <QTimer>
39
 
#include <QHash>
40
 
 
41
 
#include <kcal/calendarlocal.h>
42
 
#include <kcal/icalformat.h>
43
 
#include <kcal/resourcecalendar.h>
44
 
#include "kcalkolab_export.h"
45
 
#include "../shared/resourcekolabbase.h"
46
 
 
47
 
namespace KCal {
48
 
 
49
 
struct TemporarySilencer;
50
 
 
51
 
class KCALKOLAB_EXPORT ResourceKolab : public KCal::ResourceCalendar,
52
 
                      public KCal::IncidenceBase::IncidenceObserver,
53
 
                      public Kolab::ResourceKolabBase
54
 
{
55
 
  Q_OBJECT
56
 
    friend struct TemporarySilencer;
57
 
 
58
 
public:
59
 
  ResourceKolab( const KConfigGroup& );
60
 
  ResourceKolab();
61
 
 
62
 
  virtual ~ResourceKolab();
63
 
 
64
 
  /// Load resource data.
65
 
  bool doLoad( bool syncCache );
66
 
 
67
 
  /// Save resource data.
68
 
  bool doSave( bool syncCache );
69
 
  bool doSave( bool syncCache, KCal::Incidence *incidence );
70
 
 
71
 
  /// Open the notes resource.
72
 
  bool doOpen();
73
 
  /// Close the notes resource.
74
 
  void doClose();
75
 
 
76
 
  // The libkcal functions. See the resource for descriptions
77
 
  bool addEvent( KCal::Event* anEvent );
78
 
  bool deleteEvent( KCal::Event* );
79
 
  KCal::Event* event( const QString &UniqueStr );
80
 
  KCal::Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
81
 
  KCal::Event::List rawEventsForDate(
82
 
    const QDate& date, const KDateTime::Spec& timespec = KDateTime::Spec(),
83
 
    EventSortField sortField=EventSortUnsorted,
84
 
    SortDirection sortDirection=SortDirectionAscending );
85
 
  KCal::Event::List rawEventsForDate( const KDateTime& dt );
86
 
  KCal::Event::List rawEvents( const QDate& start, const QDate& end,
87
 
                               const KDateTime::Spec& timespec = KDateTime::Spec(),
88
 
                               bool inclusive = false );
89
 
 
90
 
  bool addTodo( KCal::Todo* todo );
91
 
  bool deleteTodo( KCal::Todo* );
92
 
  KCal::Todo* todo( const QString& uid );
93
 
  KCal::Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
94
 
  KCal::Todo::List rawTodosForDate( const QDate& date );
95
 
 
96
 
  bool addJournal( KCal::Journal* );
97
 
  bool deleteJournal( KCal::Journal* );
98
 
  KCal::Journal* journal( const QString& uid );
99
 
  KCal::Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
100
 
  KCal::Journal::List rawJournalsForDate( const QDate &date );
101
 
 
102
 
  KCal::Alarm::List alarms( const KDateTime& from, const KDateTime& to );
103
 
  KCal::Alarm::List alarmsTo( const KDateTime& to );
104
 
 
105
 
  void setTimeZoneId( const QString& tzid );
106
 
 
107
 
  bool deleteIncidence( KCal::Incidence* i );
108
 
 
109
 
  /// The ResourceKolabBase methods called by KMail
110
 
  bool fromKMailAddIncidence( const QString& type, const QString& subResource,
111
 
                              quint32 sernum, int format, const QString& data );
112
 
  void fromKMailDelIncidence( const QString& type, const QString& subResource,
113
 
                              const QString& uid );
114
 
  void fromKMailRefresh( const QString& type, const QString& subResource );
115
 
 
116
 
  /// Listen to KMail changes in the amount of sub resources
117
 
  void fromKMailAddSubresource( const QString& type, const QString& subResource,
118
 
                                const QString& label, bool writable,
119
 
                                bool alarmRelevant );
120
 
  void fromKMailDelSubresource( const QString& type, const QString& subResource );
121
 
 
122
 
  void fromKMailAsyncLoadResult( const QMap<quint32, QString>& map,
123
 
                                 const QString& type,
124
 
                                 const QString& folder );
125
 
 
126
 
  /** Return the list of subresources. */
127
 
  QStringList subresources() const;
128
 
 
129
 
  bool canHaveSubresources() const { return true; }
130
 
 
131
 
  /** Is this subresource active? */
132
 
  bool subresourceActive( const QString& ) const;
133
 
  /** (De)activate the subresource */
134
 
  virtual void setSubresourceActive( const QString &, bool );
135
 
 
136
 
  /** What is the label for this subresource? */
137
 
  virtual QString labelForSubresource( const QString& resource ) const;
138
 
 
139
 
  virtual QString subresourceIdentifier( KCal::Incidence *incidence );
140
 
 
141
 
  //TODO need to implement them
142
 
  virtual void deleteAllEvents() {}
143
 
  virtual void deleteAllTodos(){}
144
 
  virtual void deleteAllJournals(){}
145
 
  virtual void setTimeSpec(const KDateTime::Spec&){}
146
 
  virtual KDateTime::Spec timeSpec() const{ return KDateTime::UTC; }
147
 
  virtual QString timeZoneId() const { return QString(); }
148
 
  virtual void shiftTimes(const KDateTime::Spec&, const KDateTime::Spec&){}
149
 
 
150
 
  virtual bool addSubresource( const QString& resource, const QString& parent );
151
 
  virtual bool removeSubresource( const QString& resource );
152
 
 
153
 
  QString subresourceType( const QString &resource );
154
 
 
155
 
  KABC::Lock* lock();
156
 
 
157
 
signals:
158
 
  void useGlobalMode();
159
 
protected slots:
160
 
  void slotEmitResourceChanged();
161
 
  void writeConfig();
162
 
protected:
163
 
  /**
164
 
   * Return list of alarms which are relevant for the current user. These
165
 
   * are the ones coming from folders which the user has "Administer" rights
166
 
   * for, as per ACL */
167
 
  KCal::Alarm::List relevantAlarms( const KCal::Alarm::List &alarms );
168
 
 
169
 
private:
170
 
  void removeIncidences( const QByteArray& incidenceType );
171
 
  void resolveConflict( KCal::Incidence*, const QString& subresource, quint32 sernum );
172
 
  void addIncidence( const char* mimetype, const QString& xml,
173
 
                     const QString& subResource, quint32 sernum );
174
 
 
175
 
  bool addIncidence( KCal::Incidence* i, const QString& subresource,
176
 
                     quint32 sernum );
177
 
 
178
 
  void addEvent( const QString& xml, const QString& subresource,
179
 
                 quint32 sernum );
180
 
  void addTodo( const QString& xml, const QString& subresource,
181
 
                quint32 sernum );
182
 
  void addJournal( const QString& xml, const QString& subresource,
183
 
                   quint32 sernum );
184
 
 
185
 
 
186
 
  bool loadAllEvents();
187
 
  bool loadAllTodos();
188
 
  bool loadAllJournals();
189
 
 
190
 
  bool doLoadAll( Kolab::ResourceMap& map, const char* mimetype );
191
 
 
192
 
  /// Reimplemented from IncidenceBase::Observer to know when an incidence was changed
193
 
  void incidenceUpdated( KCal::IncidenceBase* );
194
 
  void incidenceUpdatedSilent( KCal::IncidenceBase* incidencebase);
195
 
 
196
 
  bool openResource( KConfig& config, const char* contentType,
197
 
                     Kolab::ResourceMap& map );
198
 
  void loadSubResourceConfig( KConfig& config, const QString& name,
199
 
                              const QString& label, bool writable,
200
 
                              bool alarmRelevant, Kolab::ResourceMap& subResource );
201
 
  bool loadSubResource( const QString& subResource, const char* mimetype );
202
 
  bool unloadSubResource( const QString& subResource );
203
 
 
204
 
  QString configFile() const {
205
 
    return ResourceKolabBase::configFile( "kcal" );
206
 
  }
207
 
 
208
 
  Kolab::ResourceMap* subResourceMap( const QString& contentsType );
209
 
 
210
 
  bool sendKMailUpdate( KCal::IncidenceBase* incidence, const QString& _subresource,
211
 
                        quint32 sernum );
212
 
 
213
 
 
214
 
  KCal::CalendarLocal mCalendar;
215
 
 
216
 
  // The list of subresources
217
 
  Kolab::ResourceMap mEventSubResources, mTodoSubResources, mJournalSubResources;
218
 
 
219
 
  bool mOpen; // If the resource is open, this is true
220
 
  QHash<QString, KCal::IncidenceBase*> mPendingUpdates;
221
 
  QTimer mResourceChangedTimer;
222
 
  ICalFormat mFormat;
223
 
 
224
 
  /**
225
 
    This map contains the association between a new added incidence
226
 
    and the subresource it belongs to.
227
 
    That's needed to return the correct mapping in subresourceIdentifier().
228
 
 
229
 
    We can't trust on mUidMap here, because it contains only non-pending uids.
230
 
   */
231
 
  QMap<QString, QString> mNewIncidencesMap;
232
 
  int mProgressDialogIncidenceLimit;
233
 
 
234
 
  /**
235
 
   * If a user has a subresource for viewing another user's folder then it can happen
236
 
   * that addIncidence(...) adds an incidence with an already existing UID.
237
 
   *
238
 
   * When this happens, addIncidence(...) sets a new random UID and stores the
239
 
   * original UID using incidence->setSchedulingID(uid) because KCal doesn't
240
 
   * allow two incidences to have the same UID.
241
 
   *
242
 
   * This map keeps track of the generated UIDs (which are local) so we can delete the
243
 
   * right incidence inside fromKMailDelIncidence(...) whenever we sync.
244
 
   *
245
 
   * The key is originalUID,subResource and the value is the fake UID.
246
 
   */
247
 
  QMap< QPair<QString, QString>, QString > mOriginalUID2fakeUID;
248
 
 
249
 
};
250
 
 
251
 
struct TemporarySilencer {
252
 
 TemporarySilencer( ResourceKolab *_resource )
253
 
  {
254
 
    resource = _resource;
255
 
    oldValue = resource->mSilent;
256
 
    resource->mSilent = true;
257
 
  }
258
 
  ~TemporarySilencer()
259
 
  {
260
 
    resource->mSilent = oldValue;
261
 
  }
262
 
  ResourceKolab *resource;
263
 
  bool oldValue;
264
 
};
265
 
 
266
 
}
267
 
 
268
 
#endif // KCAL_RESOURCEKOLAB_H