~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/libkdepim-copy/calendardiffalgo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of libkdepim.
 
3
 
 
4
    Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
20
*/
 
21
 
 
22
#include "calendardiffalgo.h"
 
23
 
 
24
#include <KDateTime>
 
25
#include <KLocale>
 
26
 
 
27
using namespace KPIM;
 
28
 
 
29
#ifndef KDE_USE_FINAL
 
30
static bool compareString( const QString &left, const QString &right )
 
31
{
 
32
  if ( left.isEmpty() && right.isEmpty() )
 
33
    return true;
 
34
  else
 
35
    return left == right;
 
36
}
 
37
#endif
 
38
 
 
39
static QString toString( KCal::Attendee *attendee )
 
40
{
 
41
  return attendee->name() + '<' + attendee->email() + '>';
 
42
}
 
43
 
 
44
static QString toString( KCal::Alarm * )
 
45
{
 
46
  return QString();
 
47
}
 
48
 
 
49
static QString toString( KCal::Incidence * )
 
50
{
 
51
  return QString();
 
52
}
 
53
 
 
54
static QString toString( KCal::Attachment * )
 
55
{
 
56
  return QString();
 
57
}
 
58
 
 
59
static QString toString( const QDate &date )
 
60
{
 
61
  return date.toString();
 
62
}
 
63
 
 
64
static QString toString( const KDateTime &dateTime )
 
65
{
 
66
  return dateTime.dateTime().toString();
 
67
}
 
68
 
 
69
static QString toString( const QString str )
 
70
{
 
71
  return str;
 
72
}
 
73
 
 
74
static QString toString( bool value )
 
75
{
 
76
  if ( value )
 
77
    return i18n( "Yes" );
 
78
  else
 
79
    return i18n( "No" );
 
80
}
 
81
 
 
82
CalendarDiffAlgo::CalendarDiffAlgo( KCal::Incidence *leftIncidence,
 
83
                                    KCal::Incidence *rightIncidence )
 
84
  : mLeftIncidence( leftIncidence ), mRightIncidence( rightIncidence )
 
85
{
 
86
}
 
87
 
 
88
void CalendarDiffAlgo::run()
 
89
{
 
90
  begin();
 
91
 
 
92
  diffIncidenceBase( mLeftIncidence, mRightIncidence );
 
93
  diffIncidence( mLeftIncidence, mRightIncidence );
 
94
 
 
95
  KCal::Event *leftEvent = dynamic_cast<KCal::Event*>( mLeftIncidence );
 
96
  KCal::Event *rightEvent = dynamic_cast<KCal::Event*>( mRightIncidence );
 
97
  if ( leftEvent && rightEvent ) {
 
98
    diffEvent( leftEvent, rightEvent );
 
99
  } else {
 
100
    KCal::Todo *leftTodo = dynamic_cast<KCal::Todo*>( mLeftIncidence );
 
101
    KCal::Todo *rightTodo = dynamic_cast<KCal::Todo*>( mRightIncidence );
 
102
    if ( leftTodo && rightTodo ) {
 
103
      diffTodo( leftTodo, rightTodo );
 
104
    }
 
105
  }
 
106
 
 
107
  end();
 
108
}
 
109
 
 
110
void CalendarDiffAlgo::diffIncidenceBase( KCal::IncidenceBase *left, KCal::IncidenceBase *right )
 
111
{
 
112
  diffList( i18n( "Attendees" ), left->attendees(), right->attendees() );
 
113
 
 
114
  if ( left->dtStart() != right->dtStart() )
 
115
    conflictField( i18n( "Start time" ), left->dtStartStr(), right->dtStartStr() );
 
116
 
 
117
  if ( !compareString( left->organizer().fullName(), right->organizer().fullName() ) )
 
118
    conflictField( i18n( "Organizer" ), left->organizer().fullName(), right->organizer().fullName() );
 
119
 
 
120
  if ( !compareString( left->uid(), right->uid() ) )
 
121
    conflictField( i18n( "UID" ), left->uid(), right->uid() );
 
122
 
 
123
  if ( left->allDay() != right->allDay() )
 
124
    conflictField( i18n( "Is all-day" ), toString( left->allDay() ), toString( right->allDay() ) );
 
125
 
 
126
  if ( left->hasDuration() != right->hasDuration() )
 
127
    conflictField( i18n( "Has duration" ), toString( left->hasDuration() ), toString( right->hasDuration() ) );
 
128
 
 
129
  if ( left->duration() != right->duration() )
 
130
    conflictField( i18n( "Duration" ), QString::number( left->duration().asSeconds() ), QString::number( right->duration().asSeconds() ) );
 
131
}
 
132
 
 
133
void CalendarDiffAlgo::diffIncidence( KCal::Incidence *left, KCal::Incidence *right )
 
134
{
 
135
  if ( !compareString( left->description(), right->description() ) )
 
136
    conflictField( i18n( "Description" ), left->description(), right->description() );
 
137
 
 
138
  if ( !compareString( left->summary(), right->summary() ) )
 
139
    conflictField( i18n( "Summary" ), left->summary(), right->summary() );
 
140
 
 
141
  if ( left->status() != right->status() )
 
142
    conflictField( i18n( "Status" ), left->statusStr(), right->statusStr() );
 
143
 
 
144
  if ( left->secrecy() != right->secrecy() )
 
145
    conflictField( i18n( "Secrecy" ), toString( left->secrecy() ), toString( right->secrecy() ) );
 
146
 
 
147
  if ( left->priority() != right->priority() )
 
148
    conflictField( i18n( "Priority" ), toString( left->priority() ), toString( right->priority() ) );
 
149
 
 
150
  if ( !compareString( left->location(), right->location() ) )
 
151
    conflictField( i18n( "Location" ), left->location(), right->location() );
 
152
 
 
153
  diffList( i18n( "Categories" ), left->categories(), right->categories() );
 
154
  diffList( i18n( "Alarms" ), left->alarms(), right->alarms() );
 
155
  diffList( i18n( "Resources" ), left->resources(), right->resources() );
 
156
  diffList( i18n( "Relations" ), left->relations(), right->relations() );
 
157
  diffList( i18n( "Attachments" ), left->attachments(), right->attachments() );
 
158
  diffList( i18n( "Exception Dates" ), left->recurrence()->exDates(), right->recurrence()->exDates() );
 
159
  diffList( i18n( "Exception Times" ), left->recurrence()->exDateTimes(), right->recurrence()->exDateTimes() );
 
160
        // TODO: recurrence dates and date/times, exrules, rrules
 
161
 
 
162
  if ( left->created() != right->created() )
 
163
    conflictField( i18n( "Created" ), left->created().toString(), right->created().toString() );
 
164
 
 
165
  if ( !compareString( left->relatedToUid(), right->relatedToUid() ) )
 
166
    conflictField( i18n( "Related Uid" ), left->relatedToUid(), right->relatedToUid() );
 
167
}
 
168
 
 
169
void CalendarDiffAlgo::diffEvent( KCal::Event *left, KCal::Event *right )
 
170
{
 
171
  if ( left->hasEndDate() != right->hasEndDate() )
 
172
    conflictField( i18n( "Has End Date" ), toString( left->hasEndDate() ), toString( right->hasEndDate() ) );
 
173
 
 
174
  if ( left->dtEnd() != right->dtEnd() )
 
175
    conflictField( i18n( "End Date" ), left->dtEndStr(), right->dtEndStr() );
 
176
 
 
177
  // TODO: check transparency
 
178
}
 
179
 
 
180
void CalendarDiffAlgo::diffTodo( KCal::Todo *left, KCal::Todo *right )
 
181
{
 
182
  if ( left->hasStartDate() != right->hasStartDate() )
 
183
    conflictField( i18n( "Has Start Date" ), toString( left->hasStartDate() ), toString( right->hasStartDate() ) );
 
184
 
 
185
  if ( left->hasDueDate() != right->hasDueDate() )
 
186
    conflictField( i18n( "Has Due Date" ), toString( left->hasDueDate() ), toString( right->hasDueDate() ) );
 
187
 
 
188
  if ( left->dtDue() != right->dtDue() )
 
189
    conflictField( i18n( "Due Date" ), left->dtDue().toString(), right->dtDue().toString() );
 
190
 
 
191
  if ( left->hasCompletedDate() != right->hasCompletedDate() )
 
192
    conflictField( i18n( "Has Complete Date" ), toString( left->hasCompletedDate() ), toString( right->hasCompletedDate() ) );
 
193
 
 
194
  if ( left->percentComplete() != right->percentComplete() )
 
195
    conflictField( i18n( "Complete" ), QString::number( left->percentComplete() ), QString::number( right->percentComplete() ) );
 
196
 
 
197
  if ( left->completed() != right->completed() )
 
198
    conflictField( i18n( "Completed" ), toString( left->completed() ), toString( right->completed() ) );
 
199
}
 
200
 
 
201
template <class L>
 
202
void CalendarDiffAlgo::diffList( const QString &id,
 
203
                                 const QList<L> &left, const QList<L> &right )
 
204
{
 
205
  for ( int i = 0; i < left.count(); ++i ) {
 
206
    if ( !right.contains( left[ i ] )  )
 
207
      additionalLeftField( id, toString( left[ i ] ) );
 
208
  }
 
209
 
 
210
  for ( int i = 0; i < right.count(); ++i ) {
 
211
    if ( !left.contains( right[ i ] )  )
 
212
      additionalRightField( id, toString( right[ i ] ) );
 
213
  }
 
214
}