2 This file is part of libkdepim.
4 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "calendardiffalgo.h"
25 #include <kcal/alarm.h>
26 #include <kcal/attachment.h>
27 #include <kcal/attendee.h>
28 #include <kcal/event.h>
29 #include <kcal/incidence.h>
30 #include <kcal/incidenceformatter.h>
31 #include <kcal/todo.h>
37 static bool compareString( const QString
&left
, const QString
&right
)
43 static QString
toString( Attendee
*attendee
)
45 return attendee
->name() + '<' + attendee
->email() + '>';
48 static QString
toString( Alarm
* )
53 static QString
toString( Incidence
* )
58 static QString
toString( Attachment
* )
63 static QString
toString( const QDate
&date
)
65 return date
.toString();
68 static QString
toString( const KDateTime
&dateTime
)
70 return dateTime
.dateTime().toString();
73 static QString
toString( const QString str
)
78 static QString
toString( bool value
)
81 return i18nc( "boolean yes", "Yes" );
83 return i18nc( "boolean no", "No" );
87 CalendarDiffAlgo::CalendarDiffAlgo( Incidence
*leftIncidence
,
88 Incidence
*rightIncidence
)
89 : mLeftIncidence( leftIncidence
), mRightIncidence( rightIncidence
)
93 void CalendarDiffAlgo::run()
97 diffIncidenceBase( mLeftIncidence
, mRightIncidence
);
98 diffIncidence( mLeftIncidence
, mRightIncidence
);
100 Event
*leftEvent
= dynamic_cast<Event
*>( mLeftIncidence
);
101 Event
*rightEvent
= dynamic_cast<Event
*>( mRightIncidence
);
102 if ( leftEvent
&& rightEvent
) {
103 diffEvent( leftEvent
, rightEvent
);
105 Todo
*leftTodo
= dynamic_cast<Todo
*>( mLeftIncidence
);
106 Todo
*rightTodo
= dynamic_cast<Todo
*>( mRightIncidence
);
107 if ( leftTodo
&& rightTodo
) {
108 diffTodo( leftTodo
, rightTodo
);
115 void CalendarDiffAlgo::diffIncidenceBase( IncidenceBase
*left
, IncidenceBase
*right
)
117 diffList( i18n( "Attendees" ), left
->attendees(), right
->attendees() );
119 if ( left
->dtStart() != right
->dtStart() ) {
120 conflictField( i18n( "Start time" ),
121 IncidenceFormatter::dateToString( left
->dtStart() ),
122 IncidenceFormatter::dateToString( right
->dtStart() ) );
125 if ( !compareString( left
->organizer().fullName(), right
->organizer().fullName() ) ) {
126 conflictField( i18n( "Organizer" ),
127 left
->organizer().fullName(), right
->organizer().fullName() );
130 if ( !compareString( left
->uid(), right
->uid() ) ) {
131 conflictField( i18n( "UID" ), left
->uid(), right
->uid() );
134 if ( left
->allDay() != right
->allDay() ) {
135 conflictField( i18n( "Is all-day" ),
136 toString( left
->allDay() ), toString( right
->allDay() ) );
139 if ( left
->hasDuration() != right
->hasDuration() ) {
140 conflictField( i18n( "Has duration" ),
141 toString( left
->hasDuration() ),
142 toString( right
->hasDuration() ) );
145 if ( left
->duration() != right
->duration() ) {
146 conflictField( i18n( "Duration" ),
147 QString::number( left
->duration().asSeconds() ),
148 QString::number( right
->duration().asSeconds() ) );
152 void CalendarDiffAlgo::diffIncidence( Incidence
*left
, Incidence
*right
)
154 if ( !compareString( left
->description(), right
->description() ) ) {
155 conflictField( i18n( "Description" ),
156 left
->description(), right
->description() );
159 if ( !compareString( left
->summary(), right
->summary() ) ) {
160 conflictField( i18n( "Summary" ), left
->summary(), right
->summary() );
163 if ( left
->status() != right
->status() ) {
164 conflictField( i18n( "Status" ), left
->statusStr(), right
->statusStr() );
167 if ( left
->secrecy() != right
->secrecy() ) {
168 conflictField( i18n( "Secrecy" ),
169 toString( left
->secrecy() ), toString( right
->secrecy() ) );
172 if ( left
->priority() != right
->priority() ) {
173 conflictField( i18n( "Priority" ),
174 toString( left
->priority() ), toString( right
->priority() ) );
177 if ( !compareString( left
->location(), right
->location() ) ) {
178 conflictField( i18n( "Location" ), left
->location(), right
->location() );
181 diffList( i18n( "Categories" ),
182 left
->categories(), right
->categories() );
183 diffList( i18n( "Alarms" ),
184 left
->alarms(), right
->alarms() );
185 diffList( i18n( "Resources" ),
186 left
->resources(), right
->resources() );
187 diffList( i18n( "Relations" ),
188 left
->relations(), right
->relations() );
189 diffList( i18n( "Attachments" ),
190 left
->attachments(), right
->attachments() );
191 diffList( i18n( "Exception Dates" ),
192 left
->recurrence()->exDates(), right
->recurrence()->exDates() );
193 diffList( i18n( "Exception Times" ),
194 left
->recurrence()->exDateTimes(), right
->recurrence()->exDateTimes() );
195 // TODO: recurrence dates and date/times, exrules, rrules
197 if ( left
->created() != right
->created() ) {
198 conflictField( i18nc( "todo creation time", "Created" ),
199 left
->created().toString(), right
->created().toString() );
202 if ( !compareString( left
->relatedToUid(), right
->relatedToUid() ) ) {
203 conflictField( i18n( "Related Uid" ),
204 left
->relatedToUid(), right
->relatedToUid() );
208 void CalendarDiffAlgo::diffEvent( Event
*left
, Event
*right
)
210 if ( left
->hasEndDate() != right
->hasEndDate() ) {
211 conflictField( i18n( "Has End Date" ),
212 toString( left
->hasEndDate() ),
213 toString( right
->hasEndDate() ) );
216 if ( left
->dtEnd() != right
->dtEnd() ) {
217 conflictField( i18n( "End Date" ),
218 IncidenceFormatter::dateToString( left
->dtEnd() ),
219 IncidenceFormatter::dateToString( right
->dtEnd() ) );
222 // TODO: check transparency
225 void CalendarDiffAlgo::diffTodo( Todo
*left
, Todo
*right
)
227 if ( left
->hasStartDate() != right
->hasStartDate() ) {
228 conflictField( i18n( "Has Start Date" ),
229 toString( left
->hasStartDate() ),
230 toString( right
->hasStartDate() ) );
233 if ( left
->hasDueDate() != right
->hasDueDate() ) {
234 conflictField( i18n( "Has Due Date" ),
235 toString( left
->hasDueDate() ),
236 toString( right
->hasDueDate() ) );
239 if ( left
->dtDue() != right
->dtDue() ) {
240 conflictField( i18n( "Due Date" ),
241 left
->dtDue().toString(),
242 right
->dtDue().toString() );
245 if ( left
->hasCompletedDate() != right
->hasCompletedDate() ) {
246 conflictField( i18n( "Has Complete Date" ),
247 toString( left
->hasCompletedDate() ),
248 toString( right
->hasCompletedDate() ) );
251 if ( left
->percentComplete() != right
->percentComplete() ) {
252 conflictField( i18nc( "to-do completion percentage", "Complete" ),
253 QString::number( left
->percentComplete() ),
254 QString::number( right
->percentComplete() ) );
257 if ( left
->completed() != right
->completed() ) {
258 conflictField( i18nc( "if to-do is completed", "Completed" ),
259 toString( left
->completed() ),
260 toString( right
->completed() ) );
265 void CalendarDiffAlgo::diffList( const QString
&id
,
266 const QList
<L
> &left
, const QList
<L
> &right
)
268 for ( int i
= 0; i
< left
.count(); ++i
) {
269 if ( !right
.contains( left
[ i
] ) ) {
270 additionalLeftField( id
, toString( left
[ i
] ) );
274 for ( int i
= 0; i
< right
.count(); ++i
) {
275 if ( !left
.contains( right
[ i
] ) ) {
276 additionalRightField( id
, toString( right
[ i
] ) );