22 #include <tdelocale.h>
24 #include "calendardiffalgo.h"
29 static bool compareString(
const TQString &left,
const TQString &right )
31 if ( left.isEmpty() && right.isEmpty() )
38 static TQString toString( KCal::Attendee *attendee )
40 return attendee->name() +
"<" + attendee->email() +
">";
43 static TQString toString( KCal::Alarm * )
48 static TQString toString( KCal::Incidence * )
53 static TQString toString( KCal::Attachment * )
58 static TQString toString(
const TQDate &date )
60 return date.toString();
63 static TQString toString(
const TQDateTime &dateTime )
65 return dateTime.toString();
68 static TQString toString(
const TQString str )
73 static TQString toString(
bool value )
81 CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence,
82 KCal::Incidence *rightIncidence )
83 : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence )
87 void CalendarDiffAlgo::run()
91 diffIncidenceBase( mLeftIncidence, mRightIncidence );
92 diffIncidence( mLeftIncidence, mRightIncidence );
94 KCal::Event *leftEvent =
dynamic_cast<KCal::Event*
>( mLeftIncidence );
95 KCal::Event *rightEvent =
dynamic_cast<KCal::Event*
>( mRightIncidence );
96 if ( leftEvent && rightEvent ) {
97 diffEvent( leftEvent, rightEvent );
99 KCal::Todo *leftTodo =
dynamic_cast<KCal::Todo*
>( mLeftIncidence );
100 KCal::Todo *rightTodo =
dynamic_cast<KCal::Todo*
>( mRightIncidence );
101 if ( leftTodo && rightTodo ) {
102 diffTodo( leftTodo, rightTodo );
109 void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right )
111 diffList( i18n(
"Attendees" ), left->attendees(), right->attendees() );
113 if ( left->dtStart() != right->dtStart() )
114 conflictField( i18n(
"Start time" ), left->dtStartStr(), right->dtStartStr() );
116 if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) )
117 conflictField( i18n(
"Organizer" ), left->organizer().fullName(), right->organizer().fullName() );
119 if ( !compareString( left->uid(), right->uid() ) )
120 conflictField( i18n(
"UID" ), left->uid(), right->uid() );
122 if ( left->doesFloat() != right->doesFloat() )
123 conflictField( i18n(
"Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) );
125 if ( left->hasDuration() != right->hasDuration() )
126 conflictField( i18n(
"Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) );
128 if ( left->duration() != right->duration() )
129 conflictField( i18n(
"Duration" ), TQString::number( left->duration() ), TQString::number( right->duration() ) );
132 void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right )
134 if ( !compareString( left->description(), right->description() ) )
135 conflictField( i18n(
"Description" ), left->description(), right->description() );
137 if ( !compareString( left->summary(), right->summary() ) )
138 conflictField( i18n(
"Summary" ), left->summary(), right->summary() );
140 if ( left->status() != right->status() )
141 conflictField( i18n(
"Status" ), left->statusStr(), right->statusStr() );
143 if ( left->secrecy() != right->secrecy() )
144 conflictField( i18n(
"Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) );
146 if ( left->priority() != right->priority() )
147 conflictField( i18n(
"Priority" ), toString( left->priority() ), toString( right->priority() ) );
149 if ( !compareString( left->location(), right->location() ) )
150 conflictField( i18n(
"Location" ), left->location(), right->location() );
152 diffList( i18n(
"Categories" ), left->categories(), right->categories() );
153 diffList( i18n(
"Alarms" ), left->alarms(), right->alarms() );
154 diffList( i18n(
"Resources" ), left->resources(), right->resources() );
155 diffList( i18n(
"Relations" ), left->relations(), right->relations() );
156 diffList( i18n(
"Attachments" ), left->attachments(), right->attachments() );
157 diffList( i18n(
"Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() );
158 diffList( i18n(
"Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() );
161 if ( left->created() != right->created() )
162 conflictField( i18n(
"Created" ), left->created().toString(), right->created().toString() );
164 if ( !compareString( left->relatedToUid(), right->relatedToUid() ) )
165 conflictField( i18n(
"Related Uid" ), left->relatedToUid(), right->relatedToUid() );
168 void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right )
170 if ( left->hasEndDate() != right->hasEndDate() )
171 conflictField( i18n(
"Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) );
173 if ( left->dtEnd() != right->dtEnd() )
174 conflictField( i18n(
"End Date" ), left->dtEndStr(), right->dtEndStr() );
179 void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right )
181 if ( left->hasStartDate() != right->hasStartDate() )
182 conflictField( i18n(
"Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) );
184 if ( left->hasDueDate() != right->hasDueDate() )
185 conflictField( i18n(
"Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) );
187 if ( left->dtDue() != right->dtDue() )
188 conflictField( i18n(
"Due Date" ), left->dtDue().toString(), right->dtDue().toString() );
190 if ( left->hasCompletedDate() != right->hasCompletedDate() )
191 conflictField( i18n(
"Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) );
193 if ( left->percentComplete() != right->percentComplete() )
194 conflictField( i18n(
"Complete" ), TQString::number( left->percentComplete() ), TQString::number( right->percentComplete() ) );
196 if ( left->completed() != right->completed() )
197 conflictField( i18n(
"Completed" ), toString( left->completed() ), toString( right->completed() ) );
201 void CalendarDiffAlgo::diffList(
const TQString &
id,
202 const TQValueList<L> &left,
const TQValueList<L> &right )
204 for ( uint i = 0; i < left.count(); ++i ) {
205 if ( right.find( left[ i ] ) == right.end() )
206 additionalLeftField(
id, toString( left[ i ] ) );
209 for ( uint i = 0; i < right.count(); ++i ) {
210 if ( left.find( right[ i ] ) == left.end() )
211 additionalRightField(
id, toString( right[ i ] ) );
TDEPIM classes for drag and drop of mails.