libkdepim Library API Documentation

calendardiffalgo.cpp

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <klocale.h>
00023 
00024 #include "calendardiffalgo.h"
00025 
00026 using namespace KPIM;
00027 
00028 #ifndef KDE_USE_FINAL
00029 static bool compareString( const QString &left, const QString &right )
00030 {
00031   if ( left.isEmpty() && right.isEmpty() )
00032     return true;
00033   else
00034     return left == right;
00035 }
00036 #endif
00037 
00038 static QString toString( KCal::Attendee *attendee )
00039 {
00040   return attendee->name() + "<" + attendee->email() + ">";
00041 }
00042 
00043 static QString toString( KCal::Alarm * )
00044 {
00045   return QString::null;
00046 }
00047 
00048 static QString toString( KCal::Incidence * )
00049 {
00050   return QString::null;
00051 }
00052 
00053 static QString toString( KCal::Attachment * )
00054 {
00055   return QString::null;
00056 }
00057 
00058 static QString toString( const QDate &date )
00059 {
00060   return date.toString();
00061 }
00062 
00063 static QString toString( const QDateTime &dateTime )
00064 {
00065   return dateTime.toString();
00066 }
00067 
00068 static QString toString( const QString str )
00069 {
00070   return str;
00071 }
00072 
00073 static QString toString( bool value )
00074 {
00075   if ( value )
00076     return i18n( "Yes" );
00077   else
00078     return i18n( "No" );
00079 }
00080 
00081 CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence,
00082                                     KCal::Incidence *rightIncidence )
00083   : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence )
00084 {
00085 }
00086 
00087 void CalendarDiffAlgo::run()
00088 {
00089   begin();
00090 
00091   diffIncidenceBase( mLeftIncidence, mRightIncidence );
00092   diffIncidence( mLeftIncidence, mRightIncidence );
00093 
00094   KCal::Event *leftEvent = dynamic_cast<KCal::Event*>( mLeftIncidence );
00095   KCal::Event *rightEvent = dynamic_cast<KCal::Event*>( mRightIncidence );
00096   if ( leftEvent && rightEvent ) {
00097     diffEvent( leftEvent, rightEvent );
00098   } else {
00099     KCal::Todo *leftTodo = dynamic_cast<KCal::Todo*>( mLeftIncidence );
00100     KCal::Todo *rightTodo = dynamic_cast<KCal::Todo*>( mRightIncidence );
00101     if ( leftTodo && rightTodo ) {
00102       diffTodo( leftTodo, rightTodo );
00103     }
00104   }
00105 
00106   end();
00107 }
00108 
00109 void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right )
00110 {
00111   diffList( i18n( "Attendees" ), left->attendees(), right->attendees() );
00112 
00113   if ( left->dtStart() != right->dtStart() )
00114     conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() );
00115 
00116   if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) )
00117     conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() );
00118 
00119   if ( !compareString( left->uid(), right->uid() ) )
00120     conflictField( i18n( "UID" ), left->uid(), right->uid() );
00121 
00122   if ( left->doesFloat() != right->doesFloat() )
00123     conflictField( i18n( "Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) );
00124 
00125   if ( left->hasDuration() != right->hasDuration() )
00126     conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) );
00127 
00128   if ( left->duration() != right->duration() )
00129     conflictField( i18n( "Duration" ), QString::number( left->duration() ), QString::number( right->duration() ) );
00130 }
00131 
00132 void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right )
00133 {
00134   if ( !compareString( left->description(), right->description() ) )
00135     conflictField( i18n( "Description" ), left->description(), right->description() );
00136 
00137   if ( !compareString( left->summary(), right->summary() ) )
00138     conflictField( i18n( "Summary" ), left->summary(), right->summary() );
00139 
00140   if ( left->status() != right->status() )
00141     conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() );
00142 
00143   if ( left->secrecy() != right->secrecy() )
00144     conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) );
00145 
00146   if ( left->priority() != right->priority() )
00147     conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) );
00148 
00149   if ( !compareString( left->location(), right->location() ) )
00150     conflictField( i18n( "Location" ), left->location(), right->location() );
00151   
00152   diffList( i18n( "Categories" ), left->categories(), right->categories() );
00153   diffList( i18n( "Alarms" ), left->alarms(), right->alarms() );
00154   diffList( i18n( "Resources" ), left->resources(), right->resources() );
00155   diffList( i18n( "Relations" ), left->relations(), right->relations() );
00156   diffList( i18n( "Attachments" ), left->attachments(), right->attachments() );
00157   diffList( i18n( "Exception Dates" ), left->exDates(), right->exDates() );
00158   diffList( i18n( "Exception Times" ), left->exDateTimes(), right->exDateTimes() );
00159 
00160   if ( left->created() != right->created() )
00161     conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() );
00162 
00163   if ( !compareString( left->relatedToUid(), right->relatedToUid() ) )
00164     conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() );
00165 }
00166 
00167 void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right )
00168 {
00169   if ( left->hasEndDate() != right->hasEndDate() )
00170     conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) );
00171 
00172   if ( left->dtEnd() != right->dtEnd() )
00173     conflictField( i18n( "End Date" ), left->dtEnd().toString(), right->dtEnd().toString() );
00174 
00175   // TODO: check transparency
00176 }
00177 
00178 void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right )
00179 {
00180   if ( left->hasStartDate() != right->hasStartDate() )
00181     conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) );
00182 
00183   if ( left->hasDueDate() != right->hasDueDate() )
00184     conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) );
00185 
00186   if ( left->dtDue() != right->dtDue() )
00187     conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() );
00188 
00189   if ( left->hasCompletedDate() != right->hasCompletedDate() )
00190     conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) );
00191 
00192   if ( left->percentComplete() != right->percentComplete() )
00193     conflictField( i18n( "Complete" ), QString::number( left->percentComplete() ), QString::number( right->percentComplete() ) );
00194 
00195   if ( left->completed() != right->completed() )
00196     conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) );
00197 }
00198 
00199 template <class L>
00200 void CalendarDiffAlgo::diffList( const QString &id,
00201                                  const QValueList<L> &left, const QValueList<L> &right )
00202 {
00203   for ( uint i = 0; i < left.count(); ++i ) {
00204     if ( right.find( left[ i ] ) == right.end() )
00205       additionalLeftField( id, toString( left[ i ] ) );
00206   }
00207 
00208   for ( uint i = 0; i < right.count(); ++i ) {
00209     if ( left.find( right[ i ] ) == left.end() )
00210       additionalRightField( id, toString( right[ i ] ) );
00211   }
00212 }
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:23:16 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003