22 #include <tdelocale.h>
24 #include <libkcal/kcalversion.h>
26 #include "calendardiffalgo.h"
28 using namespace KSync;
31 static bool compareString(
const TQString &left,
const TQString &right )
33 if ( left.isEmpty() && right.isEmpty() )
40 static TQString toString( KCal::Attendee *attendee )
42 return attendee->name() +
"<" + attendee->email() +
">";
45 static TQString toString( KCal::Alarm * )
50 static TQString toString( KCal::Incidence * )
55 static TQString toString( KCal::Attachment * )
60 static TQString toString(
const TQDate &date )
62 return date.toString();
65 static TQString toString(
const TQDateTime &dateTime )
67 return dateTime.toString();
70 static TQString toString(
const TQString str )
75 static TQString toString(
bool value )
83 CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence,
84 KCal::Incidence *rightIncidence )
85 : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence )
89 void CalendarDiffAlgo::run()
93 diffIncidenceBase( mLeftIncidence, mRightIncidence );
94 diffIncidence( mLeftIncidence, mRightIncidence );
96 KCal::Event *leftEvent =
dynamic_cast<KCal::Event*
>( mLeftIncidence );
97 KCal::Event *rightEvent =
dynamic_cast<KCal::Event*
>( mRightIncidence );
98 if ( leftEvent && rightEvent ) {
99 diffEvent( leftEvent, rightEvent );
101 KCal::Todo *leftTodo =
dynamic_cast<KCal::Todo*
>( mLeftIncidence );
102 KCal::Todo *rightTodo =
dynamic_cast<KCal::Todo*
>( mRightIncidence );
103 if ( leftTodo && rightTodo ) {
104 diffTodo( leftTodo, rightTodo );
111 void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right )
113 diffList( i18n(
"Attendees" ), left->attendees(), right->attendees() );
115 if ( left->dtStart() != right->dtStart() )
116 conflictField( i18n(
"Start time" ), left->dtStartStr(), right->dtStartStr() );
118 if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) )
119 conflictField( i18n(
"Organizer" ), left->organizer().fullName(), right->organizer().fullName() );
121 if ( !compareString( left->uid(), right->uid() ) )
122 conflictField( i18n(
"UID" ), left->uid(), right->uid() );
124 if ( left->doesFloat() != right->doesFloat() )
125 conflictField( i18n(
"Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) );
127 if ( left->hasDuration() != right->hasDuration() )
128 conflictField( i18n(
"Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) );
130 if ( left->duration() != right->duration() )
131 conflictField( i18n(
"Duration" ), TQString::number( left->duration() ), TQString::number( right->duration() ) );
134 void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right )
136 if ( !compareString( left->description(), right->description() ) )
137 conflictField( i18n(
"Description" ), left->description(), right->description() );
139 if ( !compareString( left->summary(), right->summary() ) )
140 conflictField( i18n(
"Summary" ), left->summary(), right->summary() );
142 if ( left->status() != right->status() )
143 conflictField( i18n(
"Status" ), left->statusStr(), right->statusStr() );
145 if ( left->secrecy() != right->secrecy() )
146 conflictField( i18n(
"Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) );
148 if ( left->priority() != right->priority() )
149 conflictField( i18n(
"Priority" ), toString( left->priority() ), toString( right->priority() ) );
151 if ( !compareString( left->location(), right->location() ) )
152 conflictField( i18n(
"Location" ), left->location(), right->location() );
154 diffList( i18n(
"Categories" ), left->categories(), right->categories() );
155 diffList( i18n(
"Alarms" ), left->alarms(), right->alarms() );
156 diffList( i18n(
"Resources" ), left->resources(), right->resources() );
157 diffList( i18n(
"Relations" ), left->relations(), right->relations() );
158 diffList( i18n(
"Attachments" ), left->attachments(), right->attachments() );
159 #if LIBKCAL_IS_VERSION( 1, 3, 1 )
160 diffList( i18n(
"Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() );
161 diffList( i18n(
"Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() );
165 if ( left->created() != right->created() )
166 conflictField( i18n(
"Created" ), left->created().toString(), right->created().toString() );
168 if ( !compareString( left->relatedToUid(), right->relatedToUid() ) )
169 conflictField( i18n(
"Related Uid" ), left->relatedToUid(), right->relatedToUid() );
172 void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right )
174 if ( left->hasEndDate() != right->hasEndDate() )
175 conflictField( i18n(
"Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) );
177 if ( left->dtEnd() != right->dtEnd() )
178 conflictField( i18n(
"End Date" ), left->dtEndStr(), right->dtEndStr() );
183 void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right )
185 if ( left->hasStartDate() != right->hasStartDate() )
186 conflictField( i18n(
"Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) );
188 if ( left->hasDueDate() != right->hasDueDate() )
189 conflictField( i18n(
"Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) );
191 if ( left->dtDue() != right->dtDue() )
192 conflictField( i18n(
"Due Date" ), left->dtDue().toString(), right->dtDue().toString() );
194 if ( left->hasCompletedDate() != right->hasCompletedDate() )
195 conflictField( i18n(
"Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) );
197 if ( left->percentComplete() != right->percentComplete() )
198 conflictField( i18n(
"Complete" ), TQString::number( left->percentComplete() ), TQString::number( right->percentComplete() ) );
200 if ( left->completed() != right->completed() )
201 conflictField( i18n(
"Completed" ), toString( left->completed() ), toString( right->completed() ) );
205 void CalendarDiffAlgo::diffList(
const TQString &
id,
206 const TQValueList<L> &left,
const TQValueList<L> &right )
208 for ( uint i = 0; i < left.count(); ++i ) {
209 if ( right.find( left[ i ] ) == right.end() )
210 additionalLeftField(
id, toString( left[ i ] ) );
213 for ( uint i = 0; i < right.count(); ++i ) {
214 if ( left.find( right[ i ] ) == left.end() )
215 additionalRightField(
id, toString( right[ i ] ) );