KCalCore Library
compat.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcalcore library. 00003 00004 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00034 #include "compat.h" 00035 #include "incidence.h" 00036 00037 #include <KDebug> 00038 00039 #include <QtCore/QRegExp> 00040 #include <QtCore/QString> 00041 00042 using namespace KCalCore; 00043 00044 Compat *CompatFactory::createCompat( const QString &productId ) 00045 { 00046 Compat *compat = 0; 00047 00048 int korg = productId.indexOf( "KOrganizer" ); 00049 int outl9 = productId.indexOf( "Outlook 9.0" ); 00050 00051 // TODO: Use the version of LibKCal to determine the compat class... 00052 if ( korg >= 0 ) { 00053 int versionStart = productId.indexOf( " ", korg ); 00054 if ( versionStart >= 0 ) { 00055 int versionStop = productId.indexOf( QRegExp( "[ /]" ), versionStart + 1 ); 00056 if ( versionStop >= 0 ) { 00057 QString version = productId.mid( versionStart + 1, 00058 versionStop - versionStart - 1 ); 00059 00060 int versionNum = version.section( '.', 0, 0 ).toInt() * 10000 + 00061 version.section( '.', 1, 1 ).toInt() * 100 + 00062 version.section( '.', 2, 2 ).toInt(); 00063 int releaseStop = productId.indexOf( "/", versionStop ); 00064 QString release; 00065 if ( releaseStop > versionStop ) { 00066 release = productId.mid( versionStop+1, releaseStop-versionStop-1 ); 00067 } 00068 if ( versionNum < 30100 ) { 00069 compat = new CompatPre31; 00070 } else if ( versionNum < 30200 ) { 00071 compat = new CompatPre32; 00072 } else if ( versionNum == 30200 && release == "pre" ) { 00073 kDebug() << "Generating compat for KOrganizer 3.2 pre"; 00074 compat = new Compat32PrereleaseVersions; 00075 } else if ( versionNum < 30400 ) { 00076 compat = new CompatPre34; 00077 } else if ( versionNum < 30500 ) { 00078 compat = new CompatPre35; 00079 } 00080 } 00081 } 00082 } else if ( outl9 >= 0 ) { 00083 kDebug() << "Generating compat for Outlook < 2000 (Outlook 9.0)"; 00084 compat = new CompatOutlook9; 00085 } 00086 00087 if ( !compat ) { 00088 compat = new Compat; 00089 } 00090 00091 return compat; 00092 } 00093 00094 Compat::Compat() 00095 { 00096 } 00097 00098 Compat::~Compat() 00099 { 00100 } 00101 00102 void Compat::fixEmptySummary( const Incidence::Ptr &incidence ) 00103 { 00104 // some stupid vCal exporters ignore the standard and use Description 00105 // instead of Summary for the default field. Correct for this: Copy the 00106 // first line of the description to the summary (if summary is just one 00107 // line, move it) 00108 if ( incidence->summary().isEmpty() && !( incidence->description().isEmpty() ) ) { 00109 QString oldDescription = incidence->description().trimmed(); 00110 QString newSummary( oldDescription ); 00111 newSummary.remove( QRegExp( "\n.*" ) ); 00112 incidence->setSummary( newSummary ); 00113 if ( oldDescription == newSummary ) { 00114 incidence->setDescription( "" ); 00115 } 00116 } 00117 } 00118 00119 void Compat::fixAlarms( const Incidence::Ptr &incidence ) 00120 { 00121 Q_UNUSED( incidence ); 00122 } 00123 00124 void Compat::fixFloatingEnd( QDate &date ) 00125 { 00126 Q_UNUSED( date ); 00127 } 00128 00129 void Compat::fixRecurrence( const Incidence::Ptr &incidence ) 00130 { 00131 Q_UNUSED( incidence ); 00132 // Prevent use of compatibility mode during subsequent changes by the application 00133 // incidence->recurrence()->setCompatVersion(); 00134 } 00135 00136 int Compat::fixPriority( int priority ) 00137 { 00138 return priority; 00139 } 00140 00141 bool Compat::useTimeZoneShift() 00142 { 00143 return true; 00144 } 00145 00146 void CompatPre35::fixRecurrence( const Incidence::Ptr &incidence ) 00147 { 00148 Recurrence *recurrence = incidence->recurrence(); 00149 if ( recurrence ) { 00150 KDateTime start( incidence->dtStart() ); 00151 // kde < 3.5 only had one rrule, so no need to loop over all RRULEs. 00152 RecurrenceRule *r = recurrence->defaultRRule(); 00153 if ( r && !r->dateMatchesRules( start ) ) { 00154 recurrence->addExDateTime( start ); 00155 } 00156 } 00157 00158 // Call base class method now that everything else is done 00159 Compat::fixRecurrence( incidence ); 00160 } 00161 00162 int CompatPre34::fixPriority( int priority ) 00163 { 00164 if ( 0 < priority && priority < 6 ) { 00165 // adjust 1->1, 2->3, 3->5, 4->7, 5->9 00166 return 2 * priority - 1; 00167 } else { 00168 return priority; 00169 } 00170 } 00171 00172 void CompatPre32::fixRecurrence( const Incidence::Ptr &incidence ) 00173 { 00174 Recurrence *recurrence = incidence->recurrence(); 00175 if ( recurrence->recurs() && recurrence->duration() > 0 ) { 00176 recurrence->setDuration( recurrence->duration() + incidence->recurrence()->exDates().count() ); 00177 } 00178 // Call base class method now that everything else is done 00179 CompatPre35::fixRecurrence( incidence ); 00180 } 00181 00182 void CompatPre31::fixFloatingEnd( QDate &endDate ) 00183 { 00184 endDate = endDate.addDays( 1 ); 00185 } 00186 00187 void CompatPre31::fixRecurrence( const Incidence::Ptr &incidence ) 00188 { 00189 CompatPre32::fixRecurrence( incidence ); 00190 00191 Recurrence *recur = incidence->recurrence(); 00192 RecurrenceRule *r = 0; 00193 if ( recur ) { 00194 r = recur->defaultRRule(); 00195 } 00196 if ( recur && r ) { 00197 int duration = r->duration(); 00198 if ( duration > 0 ) { 00199 // Backwards compatibility for KDE < 3.1. 00200 // rDuration was set to the number of time periods to recur, 00201 // with week start always on a Monday. 00202 // Convert this to the number of occurrences. 00203 r->setDuration( -1 ); 00204 QDate end( r->startDt().date() ); 00205 bool doNothing = false; 00206 // # of periods: 00207 int tmp = ( duration - 1 ) * r->frequency(); 00208 switch ( r->recurrenceType() ) { 00209 case RecurrenceRule::rWeekly: 00210 { 00211 end = end.addDays( tmp * 7 + 7 - end.dayOfWeek() ); 00212 break; 00213 } 00214 case RecurrenceRule::rMonthly: 00215 { 00216 int month = end.month() - 1 + tmp; 00217 end.setYMD( end.year() + month / 12, month % 12 + 1, 31 ); 00218 break; 00219 } 00220 case RecurrenceRule::rYearly: 00221 { 00222 end.setYMD( end.year() + tmp, 12, 31 ); 00223 break; 00224 } 00225 default: 00226 doNothing = true; 00227 break; 00228 } 00229 if ( !doNothing ) { 00230 duration = r->durationTo( 00231 KDateTime( end, QTime( 0, 0, 0 ), incidence->dtStart().timeSpec() ) ); 00232 r->setDuration( duration ); 00233 } 00234 } 00235 00236 /* addYearlyNum */ 00237 // Dates were stored as day numbers, with a fiddle to take account of 00238 // leap years. Convert the day number to a month. 00239 QList<int> days = r->byYearDays(); 00240 if ( !days.isEmpty() ) { 00241 QList<int> months = r->byMonths(); 00242 for ( int i = 0; i < months.size(); ++i ) { 00243 int newmonth = 00244 QDate( r->startDt().date().year(), 1, 1 ).addDays( months.at( i ) - 1 ).month(); 00245 if ( !months.contains( newmonth ) ) { 00246 months.append( newmonth ); 00247 } 00248 } 00249 00250 r->setByMonths( months ); 00251 days.clear(); 00252 r->setByYearDays( days ); 00253 } 00254 } 00255 } 00256 00257 void CompatOutlook9::fixAlarms( const Incidence::Ptr &incidence ) 00258 { 00259 if ( !incidence ) { 00260 return; 00261 } 00262 Alarm::List alarms = incidence->alarms(); 00263 Alarm::List::Iterator it; 00264 for ( it = alarms.begin(); it != alarms.end(); ++it ) { 00265 Alarm::Ptr al = *it; 00266 if ( al && al->hasStartOffset() ) { 00267 Duration offsetDuration = al->startOffset(); 00268 int offs = offsetDuration.asSeconds(); 00269 if ( offs > 0 ) { 00270 offsetDuration = Duration( -offs ); 00271 } 00272 al->setStartOffset( offsetDuration ); 00273 } 00274 } 00275 } 00276 00277 bool Compat32PrereleaseVersions::useTimeZoneShift() 00278 { 00279 return false; 00280 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:21 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:21 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.