KCalCore Library
compat.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00105
00106
00107
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
00133
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
00152 RecurrenceRule *r = recurrence->defaultRRule();
00153 if ( r && !r->dateMatchesRules( start ) ) {
00154 recurrence->addExDateTime( start );
00155 }
00156 }
00157
00158
00159 Compat::fixRecurrence( incidence );
00160 }
00161
00162 int CompatPre34::fixPriority( int priority )
00163 {
00164 if ( 0 < priority && priority < 6 ) {
00165
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
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
00200
00201
00202
00203 r->setDuration( -1 );
00204 QDate end( r->startDt().date() );
00205 bool doNothing = false;
00206
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
00237
00238
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 }