Build, if that was not necessary blame cartman who told me "sure" :-D
[kdepim.git] / libkcal / compat.cpp
blob0378dbf336b8a1c7a5c0383d81bf7653f04d3ca4
1 /*
2 This file is part of libkcal.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
22 #include "compat.h"
24 #include <kdebug.h>
26 #include <qregexp.h>
28 #include "incidence.h"
30 using namespace KCal;
32 Compat *CompatFactory::createCompat( const QString &productId )
34 // kdDebug(5800) << "CompatFactory::createCompat(): '" << productId << "'"
35 // << endl;
37 Compat *compat = 0;
39 int korg = productId.find( "KOrganizer" );
40 int outl9 = productId.find( "Outlook 9.0" );
41 if ( korg >= 0 ) {
42 int versionStart = productId.find( " ", korg );
43 if ( versionStart >= 0 ) {
44 int versionStop = productId.find( QRegExp( "[ /]" ), versionStart + 1 );
45 if ( versionStop >= 0 ) {
46 QString version = productId.mid( versionStart + 1,
47 versionStop - versionStart - 1 );
48 // kdDebug(5800) << "Found KOrganizer version: " << version << endl;
50 int versionNum = version.section( ".", 0, 0 ).toInt() * 10000 +
51 version.section( ".", 1, 1 ).toInt() * 100 +
52 version.section( ".", 2, 2 ).toInt();
53 int releaseStop = productId.find( "/", versionStop );
54 QString release;
55 if ( releaseStop > versionStop ) {
56 release = productId.mid( versionStop+1, releaseStop-versionStop-1 );
58 // kdDebug(5800) << "KOrganizer release: \"" << release << "\"" << endl;
60 // kdDebug(5800) << "Numerical version: " << versionNum << endl;
62 if ( versionNum < 30100 ) {
63 compat = new CompatPre31;
64 } else if ( versionNum < 30200 ) {
65 compat = new CompatPre32;
66 } else if ( versionNum == 30200 && release == "pre" ) {
67 kdDebug(5800) << "Generating compat for KOrganizer 3.2 pre " << endl;
68 compat = new Compat32PrereleaseVersions;
69 } else if ( versionNum < 30400 ) {
70 compat = new CompatPre34;
74 } else if ( outl9 >= 0 ) {
75 kdDebug(5800) << "Generating compat for Outlook < 2000 (Outlook 9.0)" << endl;
76 compat = new CompatOutlook9;
79 if ( !compat ) compat = new Compat;
81 return compat;
84 void Compat::fixEmptySummary( Incidence *incidence )
86 // some stupid vCal exporters ignore the standard and use Description
87 // instead of Summary for the default field. Correct for this: Copy the
88 // first line of the description to the summary (if summary is just one
89 // line, move it)
90 if (incidence->summary().isEmpty() &&
91 !(incidence->description().isEmpty())) {
92 QString oldDescription = incidence->description().stripWhiteSpace();
93 QString newSummary( oldDescription );
94 newSummary.remove( QRegExp("\n.*") );
95 incidence->setSummary( newSummary );
96 if ( oldDescription == newSummary )
97 incidence->setDescription("");
101 void Compat::fixRecurrence( Incidence *incidence )
103 // Prevent use of compatibility mode during subsequent changes by the application
104 incidence->recurrence()->setCompatVersion();
107 int CompatPre34::fixPriority( int prio )
109 if ( 0<prio && prio<6 ) {
110 // adjust 1->1, 2->3, 3->5, 4->7, 5->9
111 return 2*prio - 1;
112 } else return prio;
115 void CompatPre32::fixRecurrence( Incidence *incidence )
117 Recurrence* recurrence = incidence->recurrence();
118 if ( recurrence->doesRecur() != Recurrence::rNone && recurrence->duration() > 0 ) {
119 // The recurrence has a specified number of repetitions.
120 // Pre-3.2, this was extended by the number of exception dates.
121 recurrence->setDuration( recurrence->duration() + incidence->exDates().count() );
123 // Call base class method now that everything else is done
124 Compat::fixRecurrence( incidence );
127 void CompatPre31::fixFloatingEnd( QDate &endDate )
129 endDate = endDate.addDays( 1 );
132 void CompatOutlook9::fixAlarms( Incidence *incidence )
134 if ( !incidence ) return;
135 Alarm::List alarms = incidence->alarms();
136 Alarm::List::Iterator it;
137 for ( it = alarms.begin(); it != alarms.end(); ++it ) {
138 Alarm *al = *it;
139 if ( al && al->hasStartOffset() ) {
140 Duration offsetDuration = al->startOffset();
141 int offs = offsetDuration.asSeconds();
142 if ( offs>0 )
143 offsetDuration = Duration( -offs );
144 al->setStartOffset( offsetDuration );