libkcal Library API Documentation

compat.cpp

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "compat.h"
00022 
00023 #include <kdebug.h>
00024 
00025 #include <qregexp.h>
00026 
00027 #include "incidence.h"
00028 
00029 using namespace KCal;
00030 
00031 Compat *CompatFactory::createCompat( const QString &productId )
00032 {
00033 //  kdDebug(5800) << "CompatFactory::createCompat(): '" << productId << "'"
00034 //                << endl;
00035 
00036   Compat *compat = 0;
00037 
00038   int korg = productId.find( "KOrganizer" );
00039   if ( korg >= 0 ) {
00040     int versionStart = productId.find( " ", korg );
00041     if ( versionStart >= 0 ) {
00042       int versionStop = productId.find( QRegExp( "[ /]" ), versionStart + 1 );
00043       if ( versionStop >= 0 ) {
00044         QString version = productId.mid( versionStart + 1,
00045                                          versionStop - versionStart - 1 );
00046 //        kdDebug(5800) << "Found KOrganizer version: " << version << endl;
00047         
00048         int versionNum = version.section( ".", 0, 0 ).toInt() * 10000 +
00049                          version.section( ".", 1, 1 ).toInt() * 100 +
00050                          version.section( ".", 2, 2 ).toInt();
00051         int releaseStop = productId.find( "/", versionStop );
00052         QString release;
00053         if ( releaseStop > versionStop ) {
00054           release = productId.mid( versionStop+1, releaseStop-versionStop-1 );
00055         }
00056 //        kdDebug(5800) << "KOrganizer release: \"" << release << "\"" << endl;
00057                          
00058 //        kdDebug(5800) << "Numerical version: " << versionNum << endl;
00059         
00060         if ( versionNum < 30100 ) {
00061           compat = new CompatPre31;
00062         }
00063         else if ( versionNum < 30200 ) {
00064           compat = new CompatPre32;
00065         } else if ( versionNum == 30200 && release == "pre" ) {
00066           kdDebug(5800) << "Generating compat for KOrganizer 3.2 pre " << endl;
00067           compat = new Compat32PrereleaseVersions;
00068         }
00069       }
00070     }
00071   }
00072   
00073   if ( !compat ) compat = new Compat;
00074 
00075   return compat;
00076 }
00077 
00078 void Compat::fixEmptySummary( Incidence *incidence )
00079 {
00080   // some stupid vCal exporters ignore the standard and use Description
00081   // instead of Summary for the default field. Correct for this: Copy the 
00082   // first line of the description to the summary (if summary is just one
00083   // line, move it)
00084   if (incidence->summary().isEmpty() &&
00085       !(incidence->description().isEmpty())) {
00086     QString oldDescription = incidence->description().stripWhiteSpace();
00087     QString newSummary( oldDescription );
00088     newSummary.remove( QRegExp("\n.*") );
00089     incidence->setSummary( newSummary );
00090     if ( oldDescription == newSummary )
00091       incidence->setDescription("");
00092   }
00093 }
00094 
00095 void Compat::fixRecurrence( Incidence *incidence )
00096 {
00097   // Prevent use of compatibility mode during subsequent changes by the application
00098   incidence->recurrence()->setCompatVersion();
00099 }
00100 
00101 void CompatPre32::fixRecurrence( Incidence *incidence )
00102 {
00103   Recurrence* recurrence = incidence->recurrence();
00104   if ( recurrence->doesRecur() != Recurrence::rNone  &&  recurrence->duration() > 0 ) {
00105     // The recurrence has a specified number of repetitions.
00106     // Pre-3.2, this was extended by the number of exception dates.
00107     recurrence->setDuration( recurrence->duration() + incidence->exDates().count() );
00108   }
00109   // Call base class method now that everything else is done
00110   Compat::fixRecurrence( incidence );
00111 }
00112 
00113 void CompatPre31::fixFloatingEnd( QDate &endDate )
00114 {
00115   endDate = endDate.addDays( 1 );
00116 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:21 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003