• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • kcalcore
compat.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
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 */
34 #include "compat.h"
35 #include "incidence.h"
36 
37 #include <KDebug>
38 
39 #include <QtCore/QRegExp>
40 #include <QtCore/QString>
41 
42 using namespace KCalCore;
43 
44 Compat *CompatFactory::createCompat( const QString &productId, const QString &implementationVersion )
45 {
46  Compat *compat = 0;
47 
48  int korg = productId.indexOf( "KOrganizer" );
49  int outl9 = productId.indexOf( "Outlook 9.0" );
50 
51  if ( korg >= 0 ) {
52  int versionStart = productId.indexOf( " ", korg );
53  if ( versionStart >= 0 ) {
54  int versionStop = productId.indexOf( QRegExp( "[ /]" ), versionStart + 1 );
55  if ( versionStop >= 0 ) {
56  QString version = productId.mid( versionStart + 1,
57  versionStop - versionStart - 1 );
58 
59  int versionNum = version.section( '.', 0, 0 ).toInt() * 10000 +
60  version.section( '.', 1, 1 ).toInt() * 100 +
61  version.section( '.', 2, 2 ).toInt();
62  int releaseStop = productId.indexOf( "/", versionStop );
63  QString release;
64  if ( releaseStop > versionStop ) {
65  release = productId.mid( versionStop+1, releaseStop-versionStop-1 );
66  }
67  if ( versionNum < 30100 ) {
68  compat = new CompatPre31;
69  } else if ( versionNum < 30200 ) {
70  compat = new CompatPre32;
71  } else if ( versionNum == 30200 && release == "pre" ) {
72  kDebug() << "Generating compat for KOrganizer 3.2 pre";
73  compat = new Compat32PrereleaseVersions;
74  } else if ( versionNum < 30400 ) {
75  compat = new CompatPre34;
76  } else if ( versionNum < 30500 ) {
77  compat = new CompatPre35;
78  }
79  }
80  }
81  } else if ( outl9 >= 0 ) {
82  kDebug() << "Generating compat for Outlook < 2000 (Outlook 9.0)";
83  compat = new CompatOutlook9;
84  }
85  if ( !compat ) {
86  compat = new Compat;
87  }
88  //Older implementations lacked the implementation version, so apply this fix if it is a file from kontact and the version is missing.
89  if ( implementationVersion.isEmpty() && ( productId.contains("libkcal") || productId.contains("KOrganizer") || productId.contains("KAlarm") ) ) {
90  compat = new CompatPre410( compat );
91  }
92 
93 
94  return compat;
95 }
96 
97 Compat::Compat()
98 {
99 }
100 
101 Compat::~Compat()
102 {
103 }
104 
105 void Compat::fixEmptySummary( const Incidence::Ptr &incidence )
106 {
107  // some stupid vCal exporters ignore the standard and use Description
108  // instead of Summary for the default field. Correct for this: Copy the
109  // first line of the description to the summary (if summary is just one
110  // line, move it)
111  if ( incidence->summary().isEmpty() && !( incidence->description().isEmpty() ) ) {
112  QString oldDescription = incidence->description().trimmed();
113  QString newSummary( oldDescription );
114  newSummary.remove( QRegExp( "\n.*" ) );
115  incidence->setSummary( newSummary );
116  if ( oldDescription == newSummary ) {
117  incidence->setDescription( "" );
118  }
119  }
120 }
121 
122 void Compat::fixAlarms( const Incidence::Ptr &incidence )
123 {
124  Q_UNUSED( incidence );
125 }
126 
127 void Compat::fixFloatingEnd( QDate &date )
128 {
129  Q_UNUSED( date );
130 }
131 
132 void Compat::fixRecurrence( const Incidence::Ptr &incidence )
133 {
134  Q_UNUSED( incidence );
135  // Prevent use of compatibility mode during subsequent changes by the application
136  // incidence->recurrence()->setCompatVersion();
137 }
138 
139 int Compat::fixPriority( int priority )
140 {
141  return priority;
142 }
143 
144 bool Compat::useTimeZoneShift()
145 {
146  return true;
147 }
148 
149 void Compat::setCreatedToDtStamp(const Incidence::Ptr& incidence, const KDateTime& dtstamp)
150 {
151  Q_UNUSED( incidence );
152  Q_UNUSED( dtstamp );
153 }
154 
155 
156 struct CompatDecorator::Private {
157  Compat *compat;
158 };
159 
160 CompatDecorator::CompatDecorator(Compat *compat)
161 : d(new CompatDecorator::Private)
162 {
163  d->compat = compat;
164 }
165 
166 CompatDecorator::~CompatDecorator()
167 {
168  delete d->compat;
169  delete d;
170 }
171 
172 void CompatDecorator::fixEmptySummary( const Incidence::Ptr &incidence )
173 {
174  d->compat->fixEmptySummary( incidence );
175 }
176 
177 void CompatDecorator::fixAlarms( const Incidence::Ptr &incidence )
178 {
179  d->compat->fixAlarms( incidence );
180 }
181 
182 void CompatDecorator::fixFloatingEnd( QDate &date )
183 {
184  d->compat->fixFloatingEnd( date );
185 }
186 
187 void CompatDecorator::fixRecurrence( const Incidence::Ptr &incidence )
188 {
189  d->compat->fixRecurrence( incidence );
190 }
191 
192 int CompatDecorator::fixPriority( int priority )
193 {
194  return d->compat->fixPriority( priority );
195 }
196 
197 bool CompatDecorator::useTimeZoneShift()
198 {
199  return d->compat->useTimeZoneShift();
200 }
201 
202 void CompatDecorator::setCreatedToDtStamp(const Incidence::Ptr& incidence, const KDateTime& dtstamp)
203 {
204  d->compat->setCreatedToDtStamp( incidence, dtstamp );
205 }
206 
207 void CompatPre35::fixRecurrence( const Incidence::Ptr &incidence )
208 {
209  Recurrence *recurrence = incidence->recurrence();
210  if ( recurrence ) {
211  KDateTime start( incidence->dtStart() );
212  // kde < 3.5 only had one rrule, so no need to loop over all RRULEs.
213  RecurrenceRule *r = recurrence->defaultRRule();
214  if ( r && !r->dateMatchesRules( start ) ) {
215  recurrence->addExDateTime( start );
216  }
217  }
218 
219  // Call base class method now that everything else is done
220  Compat::fixRecurrence( incidence );
221 }
222 
223 int CompatPre34::fixPriority( int priority )
224 {
225  if ( 0 < priority && priority < 6 ) {
226  // adjust 1->1, 2->3, 3->5, 4->7, 5->9
227  return 2 * priority - 1;
228  } else {
229  return priority;
230  }
231 }
232 
233 void CompatPre32::fixRecurrence( const Incidence::Ptr &incidence )
234 {
235  Recurrence *recurrence = incidence->recurrence();
236  if ( recurrence->recurs() && recurrence->duration() > 0 ) {
237  recurrence->setDuration( recurrence->duration() + incidence->recurrence()->exDates().count() );
238  }
239  // Call base class method now that everything else is done
240  CompatPre35::fixRecurrence( incidence );
241 }
242 
243 void CompatPre31::fixFloatingEnd( QDate &endDate )
244 {
245  endDate = endDate.addDays( 1 );
246 }
247 
248 void CompatPre31::fixRecurrence( const Incidence::Ptr &incidence )
249 {
250  CompatPre32::fixRecurrence( incidence );
251 
252  Recurrence *recur = incidence->recurrence();
253  RecurrenceRule *r = 0;
254  if ( recur ) {
255  r = recur->defaultRRule();
256  }
257  if ( recur && r ) {
258  int duration = r->duration();
259  if ( duration > 0 ) {
260  // Backwards compatibility for KDE < 3.1.
261  // rDuration was set to the number of time periods to recur,
262  // with week start always on a Monday.
263  // Convert this to the number of occurrences.
264  r->setDuration( -1 );
265  QDate end( r->startDt().date() );
266  bool doNothing = false;
267  // # of periods:
268  int tmp = ( duration - 1 ) * r->frequency();
269  switch ( r->recurrenceType() ) {
270  case RecurrenceRule::rWeekly:
271  {
272  end = end.addDays( tmp * 7 + 7 - end.dayOfWeek() );
273  break;
274  }
275  case RecurrenceRule::rMonthly:
276  {
277  int month = end.month() - 1 + tmp;
278  end.setYMD( end.year() + month / 12, month % 12 + 1, 31 );
279  break;
280  }
281  case RecurrenceRule::rYearly:
282  {
283  end.setYMD( end.year() + tmp, 12, 31 );
284  break;
285  }
286  default:
287  doNothing = true;
288  break;
289  }
290  if ( !doNothing ) {
291  duration = r->durationTo(
292  KDateTime( end, QTime( 0, 0, 0 ), incidence->dtStart().timeSpec() ) );
293  r->setDuration( duration );
294  }
295  }
296 
297  /* addYearlyNum */
298  // Dates were stored as day numbers, with a fiddle to take account of
299  // leap years. Convert the day number to a month.
300  QList<int> days = r->byYearDays();
301  if ( !days.isEmpty() ) {
302  QList<int> months = r->byMonths();
303  for ( int i = 0; i < months.size(); ++i ) {
304  int newmonth =
305  QDate( r->startDt().date().year(), 1, 1 ).addDays( months.at( i ) - 1 ).month();
306  if ( !months.contains( newmonth ) ) {
307  months.append( newmonth );
308  }
309  }
310 
311  r->setByMonths( months );
312  days.clear();
313  r->setByYearDays( days );
314  }
315  }
316 }
317 
318 void CompatOutlook9::fixAlarms( const Incidence::Ptr &incidence )
319 {
320  if ( !incidence ) {
321  return;
322  }
323  Alarm::List alarms = incidence->alarms();
324  Alarm::List::Iterator it;
325  for ( it = alarms.begin(); it != alarms.end(); ++it ) {
326  Alarm::Ptr al = *it;
327  if ( al && al->hasStartOffset() ) {
328  Duration offsetDuration = al->startOffset();
329  int offs = offsetDuration.asSeconds();
330  if ( offs > 0 ) {
331  offsetDuration = Duration( -offs );
332  }
333  al->setStartOffset( offsetDuration );
334  }
335  }
336 }
337 
338 bool Compat32PrereleaseVersions::useTimeZoneShift()
339 {
340  return false;
341 }
342 
343 CompatPre410::CompatPre410( Compat* decoratedCompat )
344 : CompatDecorator( decoratedCompat )
345 {
346 
347 }
348 
349 void CompatPre410::setCreatedToDtStamp( const Incidence::Ptr& incidence, const KDateTime &dtstamp )
350 {
351  if ( dtstamp.isValid() ) {
352  incidence->setCreated( dtstamp );
353  }
354 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:24:51 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal