TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
7.5KB

  1. /*
  2. This file is part of libtdepim.
  3. Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <klocale.h>
  18. #include <libkcal/kcalversion.h>
  19. #include "calendardiffalgo.h"
  20. using namespace KSync;
  21. #ifndef KDE_USE_FINAL
  22. static bool compareString( const TQString &left, const TQString &right )
  23. {
  24. if ( left.isEmpty() && right.isEmpty() )
  25. return true;
  26. else
  27. return left == right;
  28. }
  29. #endif
  30. static TQString toString( KCal::Attendee *attendee )
  31. {
  32. return attendee->name() + "<" + attendee->email() + ">";
  33. }
  34. static TQString toString( KCal::Alarm * )
  35. {
  36. return TQString();
  37. }
  38. static TQString toString( KCal::Incidence * )
  39. {
  40. return TQString();
  41. }
  42. static TQString toString( KCal::Attachment * )
  43. {
  44. return TQString();
  45. }
  46. static TQString toString( const TQDate &date )
  47. {
  48. return date.toString();
  49. }
  50. static TQString toString( const TQDateTime &dateTime )
  51. {
  52. return dateTime.toString();
  53. }
  54. static TQString toString( const TQString str )
  55. {
  56. return str;
  57. }
  58. static TQString toString( bool value )
  59. {
  60. if ( value )
  61. return i18n( "Yes" );
  62. else
  63. return i18n( "No" );
  64. }
  65. CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence,
  66. KCal::Incidence *rightIncidence )
  67. : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence )
  68. {
  69. }
  70. void CalendarDiffAlgo::run()
  71. {
  72. begin();
  73. diffIncidenceBase( mLeftIncidence, mRightIncidence );
  74. diffIncidence( mLeftIncidence, mRightIncidence );
  75. KCal::Event *leftEvent = dynamic_cast<KCal::Event*>( mLeftIncidence );
  76. KCal::Event *rightEvent = dynamic_cast<KCal::Event*>( mRightIncidence );
  77. if ( leftEvent && rightEvent ) {
  78. diffEvent( leftEvent, rightEvent );
  79. } else {
  80. KCal::Todo *leftTodo = dynamic_cast<KCal::Todo*>( mLeftIncidence );
  81. KCal::Todo *rightTodo = dynamic_cast<KCal::Todo*>( mRightIncidence );
  82. if ( leftTodo && rightTodo ) {
  83. diffTodo( leftTodo, rightTodo );
  84. }
  85. }
  86. end();
  87. }
  88. void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right )
  89. {
  90. diffList( i18n( "Attendees" ), left->attendees(), right->attendees() );
  91. if ( left->dtStart() != right->dtStart() )
  92. conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() );
  93. if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) )
  94. conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() );
  95. if ( !compareString( left->uid(), right->uid() ) )
  96. conflictField( i18n( "UID" ), left->uid(), right->uid() );
  97. if ( left->doesFloat() != right->doesFloat() )
  98. conflictField( i18n( "Is floating" ), toString( left->doesFloat() ), toString( right->doesFloat() ) );
  99. if ( left->hasDuration() != right->hasDuration() )
  100. conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) );
  101. if ( left->duration() != right->duration() )
  102. conflictField( i18n( "Duration" ), TQString::number( left->duration() ), TQString::number( right->duration() ) );
  103. }
  104. void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right )
  105. {
  106. if ( !compareString( left->description(), right->description() ) )
  107. conflictField( i18n( "Description" ), left->description(), right->description() );
  108. if ( !compareString( left->summary(), right->summary() ) )
  109. conflictField( i18n( "Summary" ), left->summary(), right->summary() );
  110. if ( left->status() != right->status() )
  111. conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() );
  112. if ( left->secrecy() != right->secrecy() )
  113. conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) );
  114. if ( left->priority() != right->priority() )
  115. conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) );
  116. if ( !compareString( left->location(), right->location() ) )
  117. conflictField( i18n( "Location" ), left->location(), right->location() );
  118. diffList( i18n( "Categories" ), left->categories(), right->categories() );
  119. diffList( i18n( "Alarms" ), left->alarms(), right->alarms() );
  120. diffList( i18n( "Resources" ), left->resources(), right->resources() );
  121. diffList( i18n( "Relations" ), left->relations(), right->relations() );
  122. diffList( i18n( "Attachments" ), left->attachments(), right->attachments() );
  123. #if LIBKCAL_IS_VERSION( 1, 3, 1 )
  124. diffList( i18n( "Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() );
  125. diffList( i18n( "Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() );
  126. #endif
  127. // TODO: recurrence dates and date/times, exrules, rrules
  128. if ( left->created() != right->created() )
  129. conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() );
  130. if ( !compareString( left->relatedToUid(), right->relatedToUid() ) )
  131. conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() );
  132. }
  133. void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right )
  134. {
  135. if ( left->hasEndDate() != right->hasEndDate() )
  136. conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) );
  137. if ( left->dtEnd() != right->dtEnd() )
  138. conflictField( i18n( "End Date" ), left->dtEndStr(), right->dtEndStr() );
  139. // TODO: check transparency
  140. }
  141. void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right )
  142. {
  143. if ( left->hasStartDate() != right->hasStartDate() )
  144. conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) );
  145. if ( left->hasDueDate() != right->hasDueDate() )
  146. conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) );
  147. if ( left->dtDue() != right->dtDue() )
  148. conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() );
  149. if ( left->hasCompletedDate() != right->hasCompletedDate() )
  150. conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) );
  151. if ( left->percentComplete() != right->percentComplete() )
  152. conflictField( i18n( "Complete" ), TQString::number( left->percentComplete() ), TQString::number( right->percentComplete() ) );
  153. if ( left->completed() != right->completed() )
  154. conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) );
  155. }
  156. template <class L>
  157. void CalendarDiffAlgo::diffList( const TQString &id,
  158. const TQValueList<L> &left, const TQValueList<L> &right )
  159. {
  160. for ( uint i = 0; i < left.count(); ++i ) {
  161. if ( right.find( left[ i ] ) == right.end() )
  162. additionalLeftField( id, toString( left[ i ] ) );
  163. }
  164. for ( uint i = 0; i < right.count(); ++i ) {
  165. if ( left.find( right[ i ] ) == left.end() )
  166. additionalRightField( id, toString( right[ i ] ) );
  167. }
  168. }