• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 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 )
45 {
46  Compat *compat = 0;
47 
48  int korg = productId.indexOf( "KOrganizer" );
49  int outl9 = productId.indexOf( "Outlook 9.0" );
50 
51  // TODO: Use the version of LibKCal to determine the compat class...
52  if ( korg >= 0 ) {
53  int versionStart = productId.indexOf( " ", korg );
54  if ( versionStart >= 0 ) {
55  int versionStop = productId.indexOf( QRegExp( "[ /]" ), versionStart + 1 );
56  if ( versionStop >= 0 ) {
57  QString version = productId.mid( versionStart + 1,
58  versionStop - versionStart - 1 );
59 
60  int versionNum = version.section( '.', 0, 0 ).toInt() * 10000 +
61  version.section( '.', 1, 1 ).toInt() * 100 +
62  version.section( '.', 2, 2 ).toInt();
63  int releaseStop = productId.indexOf( "/", versionStop );
64  QString release;
65  if ( releaseStop > versionStop ) {
66  release = productId.mid( versionStop+1, releaseStop-versionStop-1 );
67  }
68  if ( versionNum < 30100 ) {
69  compat = new CompatPre31;
70  } else if ( versionNum < 30200 ) {
71  compat = new CompatPre32;
72  } else if ( versionNum == 30200 && release == "pre" ) {
73  kDebug() << "Generating compat for KOrganizer 3.2 pre";
74  compat = new Compat32PrereleaseVersions;
75  } else if ( versionNum < 30400 ) {
76  compat = new CompatPre34;
77  } else if ( versionNum < 30500 ) {
78  compat = new CompatPre35;
79  }
80  }
81  }
82  } else if ( outl9 >= 0 ) {
83  kDebug() << "Generating compat for Outlook < 2000 (Outlook 9.0)";
84  compat = new CompatOutlook9;
85  }
86 
87  if ( !compat ) {
88  compat = new Compat;
89  }
90 
91  return compat;
92 }
93 
94 Compat::Compat()
95 {
96 }
97 
98 Compat::~Compat()
99 {
100 }
101 
102 void Compat::fixEmptySummary( const Incidence::Ptr &incidence )
103 {
104  // some stupid vCal exporters ignore the standard and use Description
105  // instead of Summary for the default field. Correct for this: Copy the
106  // first line of the description to the summary (if summary is just one
107  // line, move it)
108  if ( incidence->summary().isEmpty() && !( incidence->description().isEmpty() ) ) {
109  QString oldDescription = incidence->description().trimmed();
110  QString newSummary( oldDescription );
111  newSummary.remove( QRegExp( "\n.*" ) );
112  incidence->setSummary( newSummary );
113  if ( oldDescription == newSummary ) {
114  incidence->setDescription( "" );
115  }
116  }
117 }
118 
119 void Compat::fixAlarms( const Incidence::Ptr &incidence )
120 {
121  Q_UNUSED( incidence );
122 }
123 
124 void Compat::fixFloatingEnd( QDate &date )
125 {
126  Q_UNUSED( date );
127 }
128 
129 void Compat::fixRecurrence( const Incidence::Ptr &incidence )
130 {
131  Q_UNUSED( incidence );
132  // Prevent use of compatibility mode during subsequent changes by the application
133  // incidence->recurrence()->setCompatVersion();
134 }
135 
136 int Compat::fixPriority( int priority )
137 {
138  return priority;
139 }
140 
141 bool Compat::useTimeZoneShift()
142 {
143  return true;
144 }
145 
146 void CompatPre35::fixRecurrence( const Incidence::Ptr &incidence )
147 {
148  Recurrence *recurrence = incidence->recurrence();
149  if ( recurrence ) {
150  KDateTime start( incidence->dtStart() );
151  // kde < 3.5 only had one rrule, so no need to loop over all RRULEs.
152  RecurrenceRule *r = recurrence->defaultRRule();
153  if ( r && !r->dateMatchesRules( start ) ) {
154  recurrence->addExDateTime( start );
155  }
156  }
157 
158  // Call base class method now that everything else is done
159  Compat::fixRecurrence( incidence );
160 }
161 
162 int CompatPre34::fixPriority( int priority )
163 {
164  if ( 0 < priority && priority < 6 ) {
165  // adjust 1->1, 2->3, 3->5, 4->7, 5->9
166  return 2 * priority - 1;
167  } else {
168  return priority;
169  }
170 }
171 
172 void CompatPre32::fixRecurrence( const Incidence::Ptr &incidence )
173 {
174  Recurrence *recurrence = incidence->recurrence();
175  if ( recurrence->recurs() && recurrence->duration() > 0 ) {
176  recurrence->setDuration( recurrence->duration() + incidence->recurrence()->exDates().count() );
177  }
178  // Call base class method now that everything else is done
179  CompatPre35::fixRecurrence( incidence );
180 }
181 
182 void CompatPre31::fixFloatingEnd( QDate &endDate )
183 {
184  endDate = endDate.addDays( 1 );
185 }
186 
187 void CompatPre31::fixRecurrence( const Incidence::Ptr &incidence )
188 {
189  CompatPre32::fixRecurrence( incidence );
190 
191  Recurrence *recur = incidence->recurrence();
192  RecurrenceRule *r = 0;
193  if ( recur ) {
194  r = recur->defaultRRule();
195  }
196  if ( recur && r ) {
197  int duration = r->duration();
198  if ( duration > 0 ) {
199  // Backwards compatibility for KDE < 3.1.
200  // rDuration was set to the number of time periods to recur,
201  // with week start always on a Monday.
202  // Convert this to the number of occurrences.
203  r->setDuration( -1 );
204  QDate end( r->startDt().date() );
205  bool doNothing = false;
206  // # of periods:
207  int tmp = ( duration - 1 ) * r->frequency();
208  switch ( r->recurrenceType() ) {
209  case RecurrenceRule::rWeekly:
210  {
211  end = end.addDays( tmp * 7 + 7 - end.dayOfWeek() );
212  break;
213  }
214  case RecurrenceRule::rMonthly:
215  {
216  int month = end.month() - 1 + tmp;
217  end.setYMD( end.year() + month / 12, month % 12 + 1, 31 );
218  break;
219  }
220  case RecurrenceRule::rYearly:
221  {
222  end.setYMD( end.year() + tmp, 12, 31 );
223  break;
224  }
225  default:
226  doNothing = true;
227  break;
228  }
229  if ( !doNothing ) {
230  duration = r->durationTo(
231  KDateTime( end, QTime( 0, 0, 0 ), incidence->dtStart().timeSpec() ) );
232  r->setDuration( duration );
233  }
234  }
235 
236  /* addYearlyNum */
237  // Dates were stored as day numbers, with a fiddle to take account of
238  // leap years. Convert the day number to a month.
239  QList<int> days = r->byYearDays();
240  if ( !days.isEmpty() ) {
241  QList<int> months = r->byMonths();
242  for ( int i = 0; i < months.size(); ++i ) {
243  int newmonth =
244  QDate( r->startDt().date().year(), 1, 1 ).addDays( months.at( i ) - 1 ).month();
245  if ( !months.contains( newmonth ) ) {
246  months.append( newmonth );
247  }
248  }
249 
250  r->setByMonths( months );
251  days.clear();
252  r->setByYearDays( days );
253  }
254  }
255 }
256 
257 void CompatOutlook9::fixAlarms( const Incidence::Ptr &incidence )
258 {
259  if ( !incidence ) {
260  return;
261  }
262  Alarm::List alarms = incidence->alarms();
263  Alarm::List::Iterator it;
264  for ( it = alarms.begin(); it != alarms.end(); ++it ) {
265  Alarm::Ptr al = *it;
266  if ( al && al->hasStartOffset() ) {
267  Duration offsetDuration = al->startOffset();
268  int offs = offsetDuration.asSeconds();
269  if ( offs > 0 ) {
270  offsetDuration = Duration( -offs );
271  }
272  al->setStartOffset( offsetDuration );
273  }
274  }
275 }
276 
277 bool Compat32PrereleaseVersions::useTimeZoneShift()
278 {
279  return false;
280 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:46:19 by doxygen 1.8.1.2 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.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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