summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-09-14 01:03:08 (UTC)
committer zautrix <zautrix>2004-09-14 01:03:08 (UTC)
commit30762fe125216362e1a6c1d5ec5d22d9525aa336 (patch) (unidiff)
tree4ff0fbf43efa921c86d64ff3f50baa9e59d207d9 /libkcal
parent8ce7eae438dcd20f9c79fc0a36dfef0a6d3931eb (diff)
downloadkdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.zip
kdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.tar.gz
kdepimpi-30762fe125216362e1a6c1d5ec5d22d9525aa336.tar.bz2
Many bugfixes
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/alarm.cpp36
-rw-r--r--libkcal/recurrence.cpp56
-rw-r--r--libkcal/sharpformat.cpp7
3 files changed, 83 insertions, 16 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 29e6205..1fc7169 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,323 +1,357 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kdebug.h> 22#include <kdebug.h>
23 23
24#include "incidence.h" 24#include "incidence.h"
25#include "todo.h" 25#include "todo.h"
26 26
27#include "alarm.h" 27#include "alarm.h"
28 28
29using namespace KCal; 29using namespace KCal;
30#include <qwidget.h> 30#include <qwidget.h>
31Alarm::Alarm(Incidence *parent) 31Alarm::Alarm(Incidence *parent)
32 : mParent(parent), 32 : mParent(parent),
33 mType(Audio), 33 mType(Audio),
34 mDescription(""), // to make operator==() not fail 34 mDescription(""), // to make operator==() not fail
35 mFile(""), // to make operator==() not fail 35 mFile(""), // to make operator==() not fail
36 mMailSubject(""), // to make operator==() not fail 36 mMailSubject(""), // to make operator==() not fail
37 mAlarmSnoozeTime(5), 37 mAlarmSnoozeTime(5),
38 mAlarmRepeatCount(0), 38 mAlarmRepeatCount(0),
39 mEndOffset(false), 39 mEndOffset(false),
40 mHasTime(false), 40 mHasTime(false),
41 mAlarmEnabled(false) 41 mAlarmEnabled(false)
42{ 42{
43 43
44} 44}
45 45
46Alarm::~Alarm() 46Alarm::~Alarm()
47{ 47{
48} 48}
49 49
50bool Alarm::operator==( const Alarm& rhs ) const 50bool Alarm::operator==( const Alarm& rhs ) const
51{ 51{
52
52 if ( mType != rhs.mType || 53 if ( mType != rhs.mType ||
53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || 54 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
54 mAlarmRepeatCount != rhs.mAlarmRepeatCount || 55 mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
55 mAlarmEnabled != rhs.mAlarmEnabled || 56 mAlarmEnabled != rhs.mAlarmEnabled ||
56 mHasTime != rhs.mHasTime) 57 mHasTime != rhs.mHasTime)
57 return false; 58 return false;
58 59
60#if 0
61 if ( mType != rhs.mType ) {
62
63 qDebug("aaa1 ");
64 return false;
65 }
66
67 if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) {
68
69 qDebug("aaa2 ");
70 return false;
71 }
72
73
74 if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) {
75
76 qDebug("aaa3 ");
77 return false;
78 }
79
80 if ( mAlarmEnabled != rhs.mAlarmEnabled ) {
81
82 qDebug("aaa4 ");
83 return false;
84 }
85
86 if ( mHasTime != rhs.mHasTime ) {
87
88 qDebug("aaa5 ");
89 return false;
90 }
91#endif
92
93
59 if (mHasTime) { 94 if (mHasTime) {
60 if (mAlarmTime != rhs.mAlarmTime) 95 if (mAlarmTime != rhs.mAlarmTime)
61 return false; 96 return false;
62 } else { 97 } else {
63 if (mOffset != rhs.mOffset || 98 if (mOffset != rhs.mOffset ||
64 mEndOffset != rhs.mEndOffset) 99 mEndOffset != rhs.mEndOffset)
65 return false; 100 return false;
66 } 101 }
67
68 switch (mType) { 102 switch (mType) {
69 case Display: 103 case Display:
70 return mDescription == rhs.mDescription; 104 return mDescription == rhs.mDescription;
71 105
72 case Email: 106 case Email:
73 return mDescription == rhs.mDescription && 107 return mDescription == rhs.mDescription &&
74 mMailAttachFiles == rhs.mMailAttachFiles && 108 mMailAttachFiles == rhs.mMailAttachFiles &&
75 mMailAddresses == rhs.mMailAddresses && 109 mMailAddresses == rhs.mMailAddresses &&
76 mMailSubject == rhs.mMailSubject; 110 mMailSubject == rhs.mMailSubject;
77 111
78 case Procedure: 112 case Procedure:
79 return mFile == rhs.mFile && 113 return mFile == rhs.mFile &&
80 mDescription == rhs.mDescription; 114 mDescription == rhs.mDescription;
81 115
82 case Audio: 116 case Audio:
83 return mFile == rhs.mFile; 117 return mFile == rhs.mFile;
84 118
85 case Invalid: 119 case Invalid:
86 break; 120 break;
87 } 121 }
88 return false; 122 return false;
89} 123}
90 124
91void Alarm::setType(Alarm::Type type) 125void Alarm::setType(Alarm::Type type)
92{ 126{
93 if (type == mType) 127 if (type == mType)
94 return; 128 return;
95 129
96 switch (type) { 130 switch (type) {
97 case Display: 131 case Display:
98 mDescription = ""; 132 mDescription = "";
99 break; 133 break;
100 case Procedure: 134 case Procedure:
101 mFile = mDescription = ""; 135 mFile = mDescription = "";
102 break; 136 break;
103 case Audio: 137 case Audio:
104 mFile = ""; 138 mFile = "";
105 break; 139 break;
106 case Email: 140 case Email:
107 mMailSubject = mDescription = ""; 141 mMailSubject = mDescription = "";
108 mMailAddresses.clear(); 142 mMailAddresses.clear();
109 mMailAttachFiles.clear(); 143 mMailAttachFiles.clear();
110 break; 144 break;
111 case Invalid: 145 case Invalid:
112 break; 146 break;
113 default: 147 default:
114 return; 148 return;
115 } 149 }
116 mType = type; 150 mType = type;
117 mParent->updated(); 151 mParent->updated();
118} 152}
119 153
120Alarm::Type Alarm::type() const 154Alarm::Type Alarm::type() const
121{ 155{
122 return mType; 156 return mType;
123} 157}
124 158
125void Alarm::setAudioAlarm(const QString &audioFile) 159void Alarm::setAudioAlarm(const QString &audioFile)
126{ 160{
127 mType = Audio; 161 mType = Audio;
128 mFile = audioFile; 162 mFile = audioFile;
129 mParent->updated(); 163 mParent->updated();
130} 164}
131 165
132void Alarm::setAudioFile(const QString &audioFile) 166void Alarm::setAudioFile(const QString &audioFile)
133{ 167{
134 if (mType == Audio) { 168 if (mType == Audio) {
135 mFile = audioFile; 169 mFile = audioFile;
136 mParent->updated(); 170 mParent->updated();
137 } 171 }
138} 172}
139 173
140QString Alarm::audioFile() const 174QString Alarm::audioFile() const
141{ 175{
142 return (mType == Audio) ? mFile : QString::null; 176 return (mType == Audio) ? mFile : QString::null;
143} 177}
144 178
145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 179void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
146{ 180{
147 mType = Procedure; 181 mType = Procedure;
148 mFile = programFile; 182 mFile = programFile;
149 mDescription = arguments; 183 mDescription = arguments;
150 mParent->updated(); 184 mParent->updated();
151} 185}
152 186
153void Alarm::setProgramFile(const QString &programFile) 187void Alarm::setProgramFile(const QString &programFile)
154{ 188{
155 if (mType == Procedure) { 189 if (mType == Procedure) {
156 mFile = programFile; 190 mFile = programFile;
157 mParent->updated(); 191 mParent->updated();
158 } 192 }
159} 193}
160 194
161QString Alarm::programFile() const 195QString Alarm::programFile() const
162{ 196{
163 return (mType == Procedure) ? mFile : QString::null; 197 return (mType == Procedure) ? mFile : QString::null;
164} 198}
165 199
166void Alarm::setProgramArguments(const QString &arguments) 200void Alarm::setProgramArguments(const QString &arguments)
167{ 201{
168 if (mType == Procedure) { 202 if (mType == Procedure) {
169 mDescription = arguments; 203 mDescription = arguments;
170 mParent->updated(); 204 mParent->updated();
171 } 205 }
172} 206}
173 207
174QString Alarm::programArguments() const 208QString Alarm::programArguments() const
175{ 209{
176 return (mType == Procedure) ? mDescription : QString::null; 210 return (mType == Procedure) ? mDescription : QString::null;
177} 211}
178 212
179void Alarm::setEmailAlarm(const QString &subject, const QString &text, 213void Alarm::setEmailAlarm(const QString &subject, const QString &text,
180 const QValueList<Person> &addressees, const QStringList &attachments) 214 const QValueList<Person> &addressees, const QStringList &attachments)
181{ 215{
182 mType = Email; 216 mType = Email;
183 mMailSubject = subject; 217 mMailSubject = subject;
184 mDescription = text; 218 mDescription = text;
185 mMailAddresses = addressees; 219 mMailAddresses = addressees;
186 mMailAttachFiles = attachments; 220 mMailAttachFiles = attachments;
187 mParent->updated(); 221 mParent->updated();
188} 222}
189 223
190void Alarm::setMailAddress(const Person &mailAddress) 224void Alarm::setMailAddress(const Person &mailAddress)
191{ 225{
192 if (mType == Email) { 226 if (mType == Email) {
193 mMailAddresses.clear(); 227 mMailAddresses.clear();
194 mMailAddresses += mailAddress; 228 mMailAddresses += mailAddress;
195 mParent->updated(); 229 mParent->updated();
196 } 230 }
197} 231}
198 232
199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 233void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
200{ 234{
201 if (mType == Email) { 235 if (mType == Email) {
202 mMailAddresses = mailAddresses; 236 mMailAddresses = mailAddresses;
203 mParent->updated(); 237 mParent->updated();
204 } 238 }
205} 239}
206 240
207void Alarm::addMailAddress(const Person &mailAddress) 241void Alarm::addMailAddress(const Person &mailAddress)
208{ 242{
209 if (mType == Email) { 243 if (mType == Email) {
210 mMailAddresses += mailAddress; 244 mMailAddresses += mailAddress;
211 mParent->updated(); 245 mParent->updated();
212 } 246 }
213} 247}
214 248
215QValueList<Person> Alarm::mailAddresses() const 249QValueList<Person> Alarm::mailAddresses() const
216{ 250{
217 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 251 return (mType == Email) ? mMailAddresses : QValueList<Person>();
218} 252}
219 253
220void Alarm::setMailSubject(const QString &mailAlarmSubject) 254void Alarm::setMailSubject(const QString &mailAlarmSubject)
221{ 255{
222 if (mType == Email) { 256 if (mType == Email) {
223 mMailSubject = mailAlarmSubject; 257 mMailSubject = mailAlarmSubject;
224 mParent->updated(); 258 mParent->updated();
225 } 259 }
226} 260}
227 261
228QString Alarm::mailSubject() const 262QString Alarm::mailSubject() const
229{ 263{
230 return (mType == Email) ? mMailSubject : QString::null; 264 return (mType == Email) ? mMailSubject : QString::null;
231} 265}
232 266
233void Alarm::setMailAttachment(const QString &mailAttachFile) 267void Alarm::setMailAttachment(const QString &mailAttachFile)
234{ 268{
235 if (mType == Email) { 269 if (mType == Email) {
236 mMailAttachFiles.clear(); 270 mMailAttachFiles.clear();
237 mMailAttachFiles += mailAttachFile; 271 mMailAttachFiles += mailAttachFile;
238 mParent->updated(); 272 mParent->updated();
239 } 273 }
240} 274}
241 275
242void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 276void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
243{ 277{
244 if (mType == Email) { 278 if (mType == Email) {
245 mMailAttachFiles = mailAttachFiles; 279 mMailAttachFiles = mailAttachFiles;
246 mParent->updated(); 280 mParent->updated();
247 } 281 }
248} 282}
249 283
250void Alarm::addMailAttachment(const QString &mailAttachFile) 284void Alarm::addMailAttachment(const QString &mailAttachFile)
251{ 285{
252 if (mType == Email) { 286 if (mType == Email) {
253 mMailAttachFiles += mailAttachFile; 287 mMailAttachFiles += mailAttachFile;
254 mParent->updated(); 288 mParent->updated();
255 } 289 }
256} 290}
257 291
258QStringList Alarm::mailAttachments() const 292QStringList Alarm::mailAttachments() const
259{ 293{
260 return (mType == Email) ? mMailAttachFiles : QStringList(); 294 return (mType == Email) ? mMailAttachFiles : QStringList();
261} 295}
262 296
263void Alarm::setMailText(const QString &text) 297void Alarm::setMailText(const QString &text)
264{ 298{
265 if (mType == Email) { 299 if (mType == Email) {
266 mDescription = text; 300 mDescription = text;
267 mParent->updated(); 301 mParent->updated();
268 } 302 }
269} 303}
270 304
271QString Alarm::mailText() const 305QString Alarm::mailText() const
272{ 306{
273 return (mType == Email) ? mDescription : QString::null; 307 return (mType == Email) ? mDescription : QString::null;
274} 308}
275 309
276void Alarm::setDisplayAlarm(const QString &text) 310void Alarm::setDisplayAlarm(const QString &text)
277{ 311{
278 mType = Display; 312 mType = Display;
279 mDescription = text; 313 mDescription = text;
280 mParent->updated(); 314 mParent->updated();
281} 315}
282 316
283void Alarm::setText(const QString &text) 317void Alarm::setText(const QString &text)
284{ 318{
285 if (mType == Display) { 319 if (mType == Display) {
286 mDescription = text; 320 mDescription = text;
287 mParent->updated(); 321 mParent->updated();
288 } 322 }
289} 323}
290 324
291QString Alarm::text() const 325QString Alarm::text() const
292{ 326{
293 return (mType == Display) ? mDescription : QString::null; 327 return (mType == Display) ? mDescription : QString::null;
294} 328}
295 329
296void Alarm::setTime(const QDateTime &alarmTime) 330void Alarm::setTime(const QDateTime &alarmTime)
297{ 331{
298 mAlarmTime = alarmTime; 332 mAlarmTime = alarmTime;
299 mHasTime = true; 333 mHasTime = true;
300 334
301 mParent->updated(); 335 mParent->updated();
302} 336}
303int Alarm::offset() 337int Alarm::offset()
304{ 338{
305 if ( hasTime() ) { 339 if ( hasTime() ) {
306 if (mParent->type()=="Todo") { 340 if (mParent->type()=="Todo") {
307 Todo *t = static_cast<Todo*>(mParent); 341 Todo *t = static_cast<Todo*>(mParent);
308 return t->dtDue().secsTo( mAlarmTime ) ; 342 return t->dtDue().secsTo( mAlarmTime ) ;
309 } else 343 } else
310 return mParent->dtStart().secsTo( mAlarmTime ) ; 344 return mParent->dtStart().secsTo( mAlarmTime ) ;
311 } 345 }
312 else 346 else
313 { 347 {
314 return mOffset.asSeconds(); 348 return mOffset.asSeconds();
315 } 349 }
316 350
317} 351}
318 352
319 353
320QDateTime Alarm::time() const 354QDateTime Alarm::time() const
321{ 355{
322 if ( hasTime() ) 356 if ( hasTime() )
323 return mAlarmTime; 357 return mAlarmTime;
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index dd74e10..e84f672 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -1,392 +1,424 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> 5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <limits.h> 23#include <limits.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "incidence.h" 29#include "incidence.h"
30 30
31#include "recurrence.h" 31#include "recurrence.h"
32 32
33using namespace KCal; 33using namespace KCal;
34 34
35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; 35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1;
36 36
37 37
38Recurrence::Recurrence(Incidence *parent, int compatVersion) 38Recurrence::Recurrence(Incidence *parent, int compatVersion)
39: recurs(rNone), // by default, it's not a recurring event 39: recurs(rNone), // by default, it's not a recurring event
40 rWeekStart(1), // default is Monday 40 rWeekStart(1), // default is Monday
41 rDays(7), 41 rDays(7),
42 mFloats(parent ? parent->doesFloat() : false), 42 mFloats(parent ? parent->doesFloat() : false),
43 mRecurReadOnly(false), 43 mRecurReadOnly(false),
44 mRecurExDatesCount(0), 44 mRecurExDatesCount(0),
45 mFeb29YearlyType(mFeb29YearlyDefaultType), 45 mFeb29YearlyType(mFeb29YearlyDefaultType),
46 mCompatVersion(compatVersion ? compatVersion : INT_MAX), 46 mCompatVersion(compatVersion ? compatVersion : INT_MAX),
47 mCompatRecurs(rNone), 47 mCompatRecurs(rNone),
48 mCompatDuration(0), 48 mCompatDuration(0),
49 mParent(parent) 49 mParent(parent)
50{ 50{
51 rMonthDays.setAutoDelete( true ); 51 rMonthDays.setAutoDelete( true );
52 rMonthPositions.setAutoDelete( true ); 52 rMonthPositions.setAutoDelete( true );
53 rYearNums.setAutoDelete( true ); 53 rYearNums.setAutoDelete( true );
54} 54}
55 55
56Recurrence::Recurrence(const Recurrence &r, Incidence *parent) 56Recurrence::Recurrence(const Recurrence &r, Incidence *parent)
57: recurs(r.recurs), 57: recurs(r.recurs),
58 rWeekStart(r.rWeekStart), 58 rWeekStart(r.rWeekStart),
59 rDays(r.rDays.copy()), 59 rDays(r.rDays.copy()),
60 rFreq(r.rFreq), 60 rFreq(r.rFreq),
61 rDuration(r.rDuration), 61 rDuration(r.rDuration),
62 rEndDateTime(r.rEndDateTime), 62 rEndDateTime(r.rEndDateTime),
63 mRecurStart(r.mRecurStart), 63 mRecurStart(r.mRecurStart),
64 mFloats(r.mFloats), 64 mFloats(r.mFloats),
65 mRecurReadOnly(r.mRecurReadOnly), 65 mRecurReadOnly(r.mRecurReadOnly),
66 mRecurExDatesCount(r.mRecurExDatesCount), 66 mRecurExDatesCount(r.mRecurExDatesCount),
67 mFeb29YearlyType(r.mFeb29YearlyType), 67 mFeb29YearlyType(r.mFeb29YearlyType),
68 mCompatVersion(r.mCompatVersion), 68 mCompatVersion(r.mCompatVersion),
69 mCompatRecurs(r.mCompatRecurs), 69 mCompatRecurs(r.mCompatRecurs),
70 mCompatDuration(r.mCompatDuration), 70 mCompatDuration(r.mCompatDuration),
71 mParent(parent) 71 mParent(parent)
72{ 72{
73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { 73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) {
74 rMonthPos *tmp = new rMonthPos; 74 rMonthPos *tmp = new rMonthPos;
75 tmp->rPos = mp.current()->rPos; 75 tmp->rPos = mp.current()->rPos;
76 tmp->negative = mp.current()->negative; 76 tmp->negative = mp.current()->negative;
77 tmp->rDays = mp.current()->rDays.copy(); 77 tmp->rDays = mp.current()->rDays.copy();
78 rMonthPositions.append(tmp); 78 rMonthPositions.append(tmp);
79 } 79 }
80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { 80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) {
81 int *tmp = new int; 81 int *tmp = new int;
82 *tmp = *md.current(); 82 *tmp = *md.current();
83 rMonthDays.append(tmp); 83 rMonthDays.append(tmp);
84 } 84 }
85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { 85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) {
86 int *tmp = new int; 86 int *tmp = new int;
87 *tmp = *yn.current(); 87 *tmp = *yn.current();
88 rYearNums.append(tmp); 88 rYearNums.append(tmp);
89 } 89 }
90 rMonthDays.setAutoDelete( true ); 90 rMonthDays.setAutoDelete( true );
91 rMonthPositions.setAutoDelete( true ); 91 rMonthPositions.setAutoDelete( true );
92 rYearNums.setAutoDelete( true ); 92 rYearNums.setAutoDelete( true );
93} 93}
94 94
95Recurrence::~Recurrence() 95Recurrence::~Recurrence()
96{ 96{
97} 97}
98 98
99 99
100bool Recurrence::operator==( const Recurrence& r2 ) const 100bool Recurrence::operator==( const Recurrence& r2 ) const
101{ 101{
102 102
103 // the following line is obvious 103 // the following line is obvious
104 if ( recurs == rNone && r2.recurs == rNone ) 104 if ( recurs == rNone && r2.recurs == rNone )
105 return true; 105 return true;
106 // we need the above line, because two non recurring events may 106 // we need the above line, because two non recurring events may
107 // differ in the other settings, because one (or both) 107 // differ in the other settings, because one (or both)
108 // may be not initialized properly 108 // may be not initialized properly
109
109 if ( recurs != r2.recurs 110 if ( recurs != r2.recurs
110 || rFreq != r2.rFreq 111 || rFreq != r2.rFreq
111 || rDuration != r2.rDuration 112 || rDuration != r2.rDuration
112 || !rDuration && rEndDateTime != r2.rEndDateTime 113 || !rDuration && rEndDateTime != r2.rEndDateTime
113 || mRecurStart != r2.mRecurStart 114 || mRecurStart != r2.mRecurStart
114 || mFloats != r2.mFloats 115 || mFloats != r2.mFloats
115 || mRecurReadOnly != r2.mRecurReadOnly 116 || mRecurReadOnly != r2.mRecurReadOnly
116 || mRecurExDatesCount != r2.mRecurExDatesCount ) 117 || mRecurExDatesCount != r2.mRecurExDatesCount )
117 return false; 118 return false;
118 // no need to compare mCompat* and mParent 119 // no need to compare mCompat* and mParent
119 // OK to compare the pointers 120 // OK to compare the pointers
120 switch ( recurs ) 121 switch ( recurs )
121 { 122 {
122 case rWeekly: 123 case rWeekly:
123 return rDays == r2.rDays 124 return rDays == r2.rDays
124 && rWeekStart == r2.rWeekStart; 125 && rWeekStart == r2.rWeekStart;
125 case rMonthlyPos: 126 case rMonthlyPos: {
126 return rMonthPositions.count() == r2.rMonthPositions.count(); 127 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
127 case rMonthlyDay: 128 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
128 return rMonthDays.count() == r2.rMonthDays.count(); 129 if ( !MonthPositions.count() )
129 case rYearlyPos: 130 return false;
130 return rYearNums.count() == r2.rYearNums.count() 131 if ( !MonthPositions2.count() )
131 && rMonthPositions.count() == r2.rMonthPositions.count(); 132 return false;
132 case rYearlyMonth: 133 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
133 return rYearNums.count() == r2.rYearNums.count() 134 }
134 && mFeb29YearlyType == r2.mFeb29YearlyType; 135 case rMonthlyDay: {
135 case rYearlyDay: 136 QPtrList<int> MonthDays = rMonthDays ;
136 return rYearNums == r2.rYearNums; 137 QPtrList<int> MonthDays2 = r2.rMonthDays ;
138 if ( !MonthDays.count() )
139 return false;
140 if ( !MonthDays2.count() )
141 return false;
142 return *MonthDays.first() == *MonthDays2.first() ;
143 }
144 case rYearlyPos: {
145
146 QPtrList<int> YearNums = rYearNums;
147 QPtrList<int> YearNums2 = r2.rYearNums;
148 if ( *YearNums.first() != *YearNums2.first() )
149 return false;
150 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
151 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
152 if ( !MonthPositions.count() )
153 return false;
154 if ( !MonthPositions2.count() )
155 return false;
156 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
157
158 }
159 case rYearlyMonth: {
160 QPtrList<int> YearNums = rYearNums;
161 QPtrList<int> YearNums2 = r2.rYearNums;
162 return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType);
163 }
164 case rYearlyDay: {
165 QPtrList<int> YearNums = rYearNums;
166 QPtrList<int> YearNums2 = r2.rYearNums;
167 return ( *YearNums.first() == *YearNums2.first() );
168 }
137 case rNone: 169 case rNone:
138 case rMinutely: 170 case rMinutely:
139 case rHourly: 171 case rHourly:
140 case rDaily: 172 case rDaily:
141 default: 173 default:
142 return true; 174 return true;
143 } 175 }
144} 176}
145/* 177/*
146bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) 178bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2)
147{ 179{
148 if ( l1.count() != l2.count() ) 180 if ( l1.count() != l2.count() )
149 return false; 181 return false;
150 int count = l1.count(); 182 int count = l1.count();
151 int i; 183 int i;
152 for ( i = 0; i < count ; ++i ) { 184 for ( i = 0; i < count ; ++i ) {
153 // if ( l1.at(i) != l2.at(i) ) 185 // if ( l1.at(i) != l2.at(i) )
154 return false; 186 return false;
155 qDebug("compüare "); 187 qDebug("compüare ");
156 } 188 }
157 return true; 189 return true;
158} 190}
159*/ 191*/
160QString Recurrence::recurrenceText() const 192QString Recurrence::recurrenceText() const
161{ 193{
162 QString recurText = i18n("No"); 194 QString recurText = i18n("No");
163 if ( recurs == Recurrence::rMinutely ) 195 if ( recurs == Recurrence::rMinutely )
164 recurText = i18n("minutely"); 196 recurText = i18n("minutely");
165 else if ( recurs == Recurrence::rHourly ) 197 else if ( recurs == Recurrence::rHourly )
166 recurText = i18n("hourly"); 198 recurText = i18n("hourly");
167 else if ( recurs == Recurrence::rDaily ) 199 else if ( recurs == Recurrence::rDaily )
168 recurText = i18n("daily"); 200 recurText = i18n("daily");
169 else if ( recurs == Recurrence::rWeekly ) 201 else if ( recurs == Recurrence::rWeekly )
170 recurText = i18n("weekly"); 202 recurText = i18n("weekly");
171 else if ( recurs == Recurrence::rMonthlyPos ) 203 else if ( recurs == Recurrence::rMonthlyPos )
172 recurText = i18n("monthly"); 204 recurText = i18n("monthly");
173 else if ( recurs == Recurrence::rMonthlyDay ) 205 else if ( recurs == Recurrence::rMonthlyDay )
174 recurText = i18n("day-monthly"); 206 recurText = i18n("day-monthly");
175 else if ( recurs == Recurrence::rYearlyMonth ) 207 else if ( recurs == Recurrence::rYearlyMonth )
176 recurText = i18n("month-yearly"); 208 recurText = i18n("month-yearly");
177 else if ( recurs == Recurrence::rYearlyDay ) 209 else if ( recurs == Recurrence::rYearlyDay )
178 recurText = i18n("day-yearly"); 210 recurText = i18n("day-yearly");
179 else if ( recurs == Recurrence::rYearlyPos ) 211 else if ( recurs == Recurrence::rYearlyPos )
180 recurText = i18n("position-yearly"); 212 recurText = i18n("position-yearly");
181 return recurText; 213 return recurText;
182} 214}
183 215
184void Recurrence::setCompatVersion(int version) 216void Recurrence::setCompatVersion(int version)
185{ 217{
186 mCompatVersion = version ? version : INT_MAX; 218 mCompatVersion = version ? version : INT_MAX;
187} 219}
188 220
189ushort Recurrence::doesRecur() const 221ushort Recurrence::doesRecur() const
190{ 222{
191 return recurs; 223 return recurs;
192} 224}
193 225
194bool Recurrence::recursOnPure(const QDate &qd) const 226bool Recurrence::recursOnPure(const QDate &qd) const
195{ 227{
196 switch(recurs) { 228 switch(recurs) {
197 case rMinutely: 229 case rMinutely:
198 return recursSecondly(qd, rFreq*60); 230 return recursSecondly(qd, rFreq*60);
199 case rHourly: 231 case rHourly:
200 return recursSecondly(qd, rFreq*3600); 232 return recursSecondly(qd, rFreq*3600);
201 case rDaily: 233 case rDaily:
202 return recursDaily(qd); 234 return recursDaily(qd);
203 case rWeekly: 235 case rWeekly:
204 return recursWeekly(qd); 236 return recursWeekly(qd);
205 case rMonthlyPos: 237 case rMonthlyPos:
206 case rMonthlyDay: 238 case rMonthlyDay:
207 return recursMonthly(qd); 239 return recursMonthly(qd);
208 case rYearlyMonth: 240 case rYearlyMonth:
209 return recursYearlyByMonth(qd); 241 return recursYearlyByMonth(qd);
210 case rYearlyDay: 242 case rYearlyDay:
211 return recursYearlyByDay(qd); 243 return recursYearlyByDay(qd);
212 case rYearlyPos: 244 case rYearlyPos:
213 return recursYearlyByPos(qd); 245 return recursYearlyByPos(qd);
214 default: 246 default:
215 return false; 247 return false;
216 case rNone: 248 case rNone:
217 return false; 249 return false;
218 } // case 250 } // case
219 return false; 251 return false;
220} 252}
221 253
222bool Recurrence::recursAtPure(const QDateTime &dt) const 254bool Recurrence::recursAtPure(const QDateTime &dt) const
223{ 255{
224 switch(recurs) { 256 switch(recurs) {
225 case rMinutely: 257 case rMinutely:
226 return recursMinutelyAt(dt, rFreq); 258 return recursMinutelyAt(dt, rFreq);
227 case rHourly: 259 case rHourly:
228 return recursMinutelyAt(dt, rFreq*60); 260 return recursMinutelyAt(dt, rFreq*60);
229 default: 261 default:
230 if (dt.time() != mRecurStart.time()) 262 if (dt.time() != mRecurStart.time())
231 return false; 263 return false;
232 switch(recurs) { 264 switch(recurs) {
233 case rDaily: 265 case rDaily:
234 return recursDaily(dt.date()); 266 return recursDaily(dt.date());
235 case rWeekly: 267 case rWeekly:
236 return recursWeekly(dt.date()); 268 return recursWeekly(dt.date());
237 case rMonthlyPos: 269 case rMonthlyPos:
238 case rMonthlyDay: 270 case rMonthlyDay:
239 return recursMonthly(dt.date()); 271 return recursMonthly(dt.date());
240 case rYearlyMonth: 272 case rYearlyMonth:
241 return recursYearlyByMonth(dt.date()); 273 return recursYearlyByMonth(dt.date());
242 case rYearlyDay: 274 case rYearlyDay:
243 return recursYearlyByDay(dt.date()); 275 return recursYearlyByDay(dt.date());
244 case rYearlyPos: 276 case rYearlyPos:
245 return recursYearlyByPos(dt.date()); 277 return recursYearlyByPos(dt.date());
246 default: 278 default:
247 return false; 279 return false;
248 case rNone: 280 case rNone:
249 return false; 281 return false;
250 } 282 }
251 } // case 283 } // case
252 return false; 284 return false;
253} 285}
254 286
255QDate Recurrence::endDate() const 287QDate Recurrence::endDate() const
256{ 288{
257 int count = 0; 289 int count = 0;
258 QDate end; 290 QDate end;
259 if (recurs != rNone) { 291 if (recurs != rNone) {
260 if (rDuration < 0) 292 if (rDuration < 0)
261 return QDate(); // infinite recurrence 293 return QDate(); // infinite recurrence
262 if (rDuration == 0) 294 if (rDuration == 0)
263 return rEndDateTime.date(); 295 return rEndDateTime.date();
264 296
265 // The end date is determined by the recurrence count 297 // The end date is determined by the recurrence count
266 QDate dStart = mRecurStart.date(); 298 QDate dStart = mRecurStart.date();
267 switch (recurs) 299 switch (recurs)
268 { 300 {
269 case rMinutely: 301 case rMinutely:
270 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); 302 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date();
271 case rHourly: 303 case rHourly:
272 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); 304 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date();
273 case rDaily: 305 case rDaily:
274 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 306 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
275 307
276 case rWeekly: 308 case rWeekly:
277 count = weeklyCalc(END_DATE_AND_COUNT, end); 309 count = weeklyCalc(END_DATE_AND_COUNT, end);
278 break; 310 break;
279 case rMonthlyPos: 311 case rMonthlyPos:
280 case rMonthlyDay: 312 case rMonthlyDay:
281 count = monthlyCalc(END_DATE_AND_COUNT, end); 313 count = monthlyCalc(END_DATE_AND_COUNT, end);
282 break; 314 break;
283 case rYearlyMonth: 315 case rYearlyMonth:
284 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 316 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
285 break; 317 break;
286 case rYearlyDay: 318 case rYearlyDay:
287 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 319 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
288 break; 320 break;
289 case rYearlyPos: 321 case rYearlyPos:
290 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 322 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
291 break; 323 break;
292 default: 324 default:
293 // catch-all. Should never get here. 325 // catch-all. Should never get here.
294 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 326 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
295 break; 327 break;
296 } 328 }
297 } 329 }
298 if (!count) 330 if (!count)
299 return QDate(); // error - there is no recurrence 331 return QDate(); // error - there is no recurrence
300 return end; 332 return end;
301} 333}
302 334
303QDateTime Recurrence::endDateTime() const 335QDateTime Recurrence::endDateTime() const
304{ 336{
305 int count = 0; 337 int count = 0;
306 QDate end; 338 QDate end;
307 if (recurs != rNone) { 339 if (recurs != rNone) {
308 if (rDuration < 0) 340 if (rDuration < 0)
309 return QDateTime(); // infinite recurrence 341 return QDateTime(); // infinite recurrence
310 if (rDuration == 0) 342 if (rDuration == 0)
311 return rEndDateTime; 343 return rEndDateTime;
312 344
313 // The end date is determined by the recurrence count 345 // The end date is determined by the recurrence count
314 QDate dStart = mRecurStart.date(); 346 QDate dStart = mRecurStart.date();
315 switch (recurs) 347 switch (recurs)
316 { 348 {
317 case rMinutely: 349 case rMinutely:
318 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); 350 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60);
319 case rHourly: 351 case rHourly:
320 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); 352 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600);
321 case rDaily: 353 case rDaily:
322 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 354 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
323 355
324 case rWeekly: 356 case rWeekly:
325 count = weeklyCalc(END_DATE_AND_COUNT, end); 357 count = weeklyCalc(END_DATE_AND_COUNT, end);
326 break; 358 break;
327 case rMonthlyPos: 359 case rMonthlyPos:
328 case rMonthlyDay: 360 case rMonthlyDay:
329 count = monthlyCalc(END_DATE_AND_COUNT, end); 361 count = monthlyCalc(END_DATE_AND_COUNT, end);
330 break; 362 break;
331 case rYearlyMonth: 363 case rYearlyMonth:
332 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 364 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
333 break; 365 break;
334 case rYearlyDay: 366 case rYearlyDay:
335 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 367 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
336 break; 368 break;
337 case rYearlyPos: 369 case rYearlyPos:
338 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 370 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
339 break; 371 break;
340 default: 372 default:
341 // catch-all. Should never get here. 373 // catch-all. Should never get here.
342 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 374 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
343 break; 375 break;
344 } 376 }
345 } 377 }
346 if (!count) 378 if (!count)
347 return QDateTime(); // error - there is no recurrence 379 return QDateTime(); // error - there is no recurrence
348 return QDateTime(end, mRecurStart.time()); 380 return QDateTime(end, mRecurStart.time());
349} 381}
350 382
351int Recurrence::durationTo(const QDate &date) const 383int Recurrence::durationTo(const QDate &date) const
352{ 384{
353 QDate d = date; 385 QDate d = date;
354 return recurCalc(COUNT_TO_DATE, d); 386 return recurCalc(COUNT_TO_DATE, d);
355} 387}
356 388
357int Recurrence::durationTo(const QDateTime &datetime) const 389int Recurrence::durationTo(const QDateTime &datetime) const
358{ 390{
359 QDateTime dt = datetime; 391 QDateTime dt = datetime;
360 return recurCalc(COUNT_TO_DATE, dt); 392 return recurCalc(COUNT_TO_DATE, dt);
361} 393}
362 394
363void Recurrence::unsetRecurs() 395void Recurrence::unsetRecurs()
364{ 396{
365 if (mRecurReadOnly) return; 397 if (mRecurReadOnly) return;
366 recurs = rNone; 398 recurs = rNone;
367 rMonthPositions.clear(); 399 rMonthPositions.clear();
368 rMonthDays.clear(); 400 rMonthDays.clear();
369 rYearNums.clear(); 401 rYearNums.clear();
370} 402}
371 403
372void Recurrence::setRecurStart(const QDateTime &start) 404void Recurrence::setRecurStart(const QDateTime &start)
373{ 405{
374 mRecurStart = start; 406 mRecurStart = start;
375 mFloats = false; 407 mFloats = false;
376 switch (recurs) 408 switch (recurs)
377 { 409 {
378 case rMinutely: 410 case rMinutely:
379 case rHourly: 411 case rHourly:
380 break; 412 break;
381 case rDaily: 413 case rDaily:
382 case rWeekly: 414 case rWeekly:
383 case rMonthlyPos: 415 case rMonthlyPos:
384 case rMonthlyDay: 416 case rMonthlyDay:
385 case rYearlyMonth: 417 case rYearlyMonth:
386 case rYearlyDay: 418 case rYearlyDay:
387 case rYearlyPos: 419 case rYearlyPos:
388 default: 420 default:
389 rEndDateTime.setTime(start.time()); 421 rEndDateTime.setTime(start.time());
390 break; 422 break;
391 } 423 }
392} 424}
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index defdb09..89eb72f 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,633 +1,634 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "sharpformat.h" 44#include "sharpformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY 49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
51 51
52//ARSD silentalarm = 0 52//ARSD silentalarm = 0
53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly 53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
54// 12 RFRQ 54// 12 RFRQ
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 oldCategories = 0; 67 oldCategories = 0;
68 } 68 }
69 69
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 71 {
72 int i = 1; 72 int i = 1;
73 bool skip = true; 73 bool skip = true;
74 int max = attList.count() -2; 74 int max = attList.count() -2;
75 while ( i < max ) { 75 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 76 if ( !attList[i].isEmpty() ) {
77 skip = false; 77 skip = false;
78 break; 78 break;
79 } 79 }
80 ++i ; 80 ++i ;
81 } 81 }
82 if ( skip ) 82 if ( skip )
83 return false; 83 return false;
84 ulong cSum = SharpFormat::getCsum(attList ); 84 ulong cSum = SharpFormat::getCsum(attList );
85 85
86 if ( qName == "Event" ) { 86 if ( qName == "Event" ) {
87 Event *event; 87 Event *event;
88 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 88 event = existingCalendar->event( "Sharp_DTM",attList[0] );
89 if ( event ) 89 if ( event )
90 event = (Event*)event->clone(); 90 event = (Event*)event->clone();
91 else 91 else
92 event = new Event; 92 event = new Event;
93 event->setID("Sharp_DTM", attList[0] ); 93 event->setID("Sharp_DTM", attList[0] );
94 event->setCsum( "Sharp_DTM", QString::number( cSum )); 94 event->setCsum( "Sharp_DTM", QString::number( cSum ));
95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
96 96
97 event->setSummary( attList[2] ); 97 event->setSummary( attList[2] );
98 event->setLocation( attList[3] ); 98 event->setLocation( attList[3] );
99 event->setDescription( attList[4] ); 99 event->setDescription( attList[4] );
100 if ( attList[7] == "1" ) { 100 if ( attList[7] == "1" ) {
101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
103 event->setFloats( true ); 103 event->setFloats( true );
104 } else { 104 } else {
105 event->setFloats( false ); 105 event->setFloats( false );
106 event->setDtStart( fromString( attList[5] ) ); 106 event->setDtStart( fromString( attList[5] ) );
107 event->setDtEnd( fromString( attList[6] )); 107 event->setDtEnd( fromString( attList[6] ));
108 } 108 }
109 109
110 QString rtype = attList[11]; 110 QString rtype = attList[11];
111 if ( rtype != "255" ) { 111 if ( rtype != "255" ) {
112 // qDebug("recurs "); 112 // qDebug("recurs ");
113 QDate startDate = event->dtStart().date(); 113 QDate startDate = event->dtStart().date();
114 114
115 QString freqStr = attList[12]; 115 QString freqStr = attList[12];
116 int freq = freqStr.toInt(); 116 int freq = freqStr.toInt();
117 117
118 QString hasEndDateStr = attList[15] ; 118 QString hasEndDateStr = attList[15] ;
119 bool hasEndDate = hasEndDateStr == "1"; 119 bool hasEndDate = hasEndDateStr == "1";
120 120
121 QString endDateStr = attList[16]; 121 QString endDateStr = attList[16];
122 QDate endDate = fromString( endDateStr ).date(); 122 QDate endDate = fromString( endDateStr ).date();
123 123
124 QString weekDaysStr = attList[14]; 124 QString weekDaysStr = attList[14];
125 uint weekDaysNum = weekDaysStr.toInt(); 125 uint weekDaysNum = weekDaysStr.toInt();
126 126
127 QBitArray weekDays( 7 ); 127 QBitArray weekDays( 7 );
128 int i; 128 int i;
129 int bb = 1; 129 int bb = 1;
130 for( i = 1; i <= 7; ++i ) { 130 for( i = 1; i <= 7; ++i ) {
131 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 131 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
132 bb = 2 << (i-1); 132 bb = 2 << (i-1);
133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
134 } 134 }
135 // qDebug("next "); 135 // qDebug("next ");
136 QString posStr = attList[13]; 136 QString posStr = attList[13];
137 int pos = posStr.toInt(); 137 int pos = posStr.toInt();
138 Recurrence *r = event->recurrence(); 138 Recurrence *r = event->recurrence();
139 139
140 if ( rtype == "0" ) { 140 if ( rtype == "0" ) {
141 if ( hasEndDate ) r->setDaily( freq, endDate ); 141 if ( hasEndDate ) r->setDaily( freq, endDate );
142 else r->setDaily( freq, -1 ); 142 else r->setDaily( freq, -1 );
143 } else if ( rtype == "1" ) { 143 } else if ( rtype == "1" ) {
144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
145 else r->setWeekly( freq, weekDays, -1 ); 145 else r->setWeekly( freq, weekDays, -1 );
146 } else if ( rtype == "3" ) { 146 } else if ( rtype == "3" ) {
147 if ( hasEndDate ) 147 if ( hasEndDate )
148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
149 else 149 else
150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
151 r->addMonthlyDay( startDate.day() ); 151 r->addMonthlyDay( startDate.day() );
152 } else if ( rtype == "2" ) { 152 } else if ( rtype == "2" ) {
153 if ( hasEndDate ) 153 if ( hasEndDate )
154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
155 else 155 else
156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
157 QBitArray days( 7 ); 157 QBitArray days( 7 );
158 days.fill( false ); 158 days.fill( false );
159 days.setBit( startDate.dayOfWeek() - 1 ); 159 days.setBit( startDate.dayOfWeek() - 1 );
160 r->addMonthlyPos( pos, days ); 160 r->addMonthlyPos( pos, days );
161 } else if ( rtype == "4" ) { 161 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 162 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 164 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 166 r->addYearlyNum( startDate.month() );
167 } 167 }
168 } else { 168 } else {
169 event->recurrence()->unsetRecurs(); 169 event->recurrence()->unsetRecurs();
170 } 170 }
171 171
172 QString categoryList = attList[1] ; 172 QString categoryList = attList[1] ;
173 event->setCategories( lookupCategories( categoryList ) ); 173 event->setCategories( lookupCategories( categoryList ) );
174 174
175 // strange 0 semms to mean: alarm enabled 175 // strange 0 semms to mean: alarm enabled
176 if ( attList[8] == "0" ) { 176 if ( attList[8] == "0" ) {
177 Alarm *alarm; 177 Alarm *alarm;
178 if ( event->alarms().count() > 0 ) 178 if ( event->alarms().count() > 0 )
179 alarm = event->alarms().first(); 179 alarm = event->alarms().first();
180 else { 180 else {
181 alarm = new Alarm( event ); 181 alarm = new Alarm( event );
182 event->addAlarm( alarm ); 182 event->addAlarm( alarm );
183 alarm->setType( Alarm::Audio );
183 } 184 }
184 alarm->setType( Alarm::Audio ); 185 //alarm->setType( Alarm::Audio );
185 alarm->setEnabled( true ); 186 alarm->setEnabled( true );
186 int alarmOffset = attList[9].toInt(); 187 int alarmOffset = attList[9].toInt();
187 alarm->setStartOffset( alarmOffset * -60 ); 188 alarm->setStartOffset( alarmOffset * -60 );
188 } else { 189 } else {
189 Alarm *alarm; 190 Alarm *alarm;
190 if ( event->alarms().count() > 0 ) { 191 if ( event->alarms().count() > 0 ) {
191 alarm = event->alarms().first(); 192 alarm = event->alarms().first();
192 alarm->setType( Alarm::Audio ); 193 alarm->setType( Alarm::Audio );
193 alarm->setStartOffset( -60*15 ); 194 alarm->setStartOffset( -60*15 );
194 alarm->setEnabled( false ); 195 alarm->setEnabled( false );
195 } 196 }
196 } 197 }
197 198
198 mCalendar->addEvent( event); 199 mCalendar->addEvent( event);
199 } else if ( qName == "Todo" ) { 200 } else if ( qName == "Todo" ) {
200 Todo *todo; 201 Todo *todo;
201 202
202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 203 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
203 if (todo ) 204 if (todo )
204 todo = (Todo*)todo->clone(); 205 todo = (Todo*)todo->clone();
205 else 206 else
206 todo = new Todo; 207 todo = new Todo;
207 208
208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 209//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
209// 0 1 2 3 4 5 6 7 8 210// 0 1 2 3 4 5 6 7 8
210//1,,,,,1,4,Loch zumachen,"" 211//1,,,,,1,4,Loch zumachen,""
211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 212//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 213//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
213 214
214 todo->setID( "Sharp_DTM", attList[0]); 215 todo->setID( "Sharp_DTM", attList[0]);
215 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 216 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 217 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
217 218
218 todo->setSummary( attList[7] ); 219 todo->setSummary( attList[7] );
219 todo->setDescription( attList[8]); 220 todo->setDescription( attList[8]);
220 221
221 int priority = attList[6].toInt(); 222 int priority = attList[6].toInt();
222 if ( priority == 0 ) priority = 3; 223 if ( priority == 0 ) priority = 3;
223 todo->setPriority( priority ); 224 todo->setPriority( priority );
224 225
225 QString categoryList = attList[1]; 226 QString categoryList = attList[1];
226 todo->setCategories( lookupCategories( categoryList ) ); 227 todo->setCategories( lookupCategories( categoryList ) );
227 228
228 229
229 230
230 QString hasDateStr = attList[3]; // due 231 QString hasDateStr = attList[3]; // due
231 if ( !hasDateStr.isEmpty() ) { 232 if ( !hasDateStr.isEmpty() ) {
232 if ( hasDateStr.right(6) == "000000" ) { 233 if ( hasDateStr.right(6) == "000000" ) {
233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
234 todo->setFloats( true ); 235 todo->setFloats( true );
235 } 236 }
236 else { 237 else {
237 todo->setDtDue( fromString( hasDateStr ) ); 238 todo->setDtDue( fromString( hasDateStr ) );
238 todo->setFloats( false ); 239 todo->setFloats( false );
239 } 240 }
240 241
241 todo->setHasDueDate( true ); 242 todo->setHasDueDate( true );
242 } 243 }
243 hasDateStr = attList[2];//start 244 hasDateStr = attList[2];//start
244 if ( !hasDateStr.isEmpty() ) { 245 if ( !hasDateStr.isEmpty() ) {
245 246
246 todo->setDtStart( fromString( hasDateStr ) ); 247 todo->setDtStart( fromString( hasDateStr ) );
247 todo->setHasStartDate( true); 248 todo->setHasStartDate( true);
248 } else 249 } else
249 todo->setHasStartDate( false ); 250 todo->setHasStartDate( false );
250 hasDateStr = attList[4];//completed 251 hasDateStr = attList[4];//completed
251 if ( !hasDateStr.isEmpty() ) { 252 if ( !hasDateStr.isEmpty() ) {
252 todo->setCompleted(fromString( hasDateStr ) ); 253 todo->setCompleted(fromString( hasDateStr ) );
253 } 254 }
254 QString completedStr = attList[5]; 255 QString completedStr = attList[5];
255 if ( completedStr == "0" ) 256 if ( completedStr == "0" )
256 todo->setCompleted( true ); 257 todo->setCompleted( true );
257 else 258 else
258 todo->setCompleted( false ); 259 todo->setCompleted( false );
259 mCalendar->addTodo( todo ); 260 mCalendar->addTodo( todo );
260 261
261 } else if ( qName == "Category" ) { 262 } else if ( qName == "Category" ) {
262 /* 263 /*
263 QString id = attributes.value( "id" ); 264 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 265 QString name = attributes.value( "name" );
265 setCategory( id, name ); 266 setCategory( id, name );
266 */ 267 */
267 } 268 }
268 //qDebug("end "); 269 //qDebug("end ");
269 return true; 270 return true;
270 } 271 }
271 272
272 273
273 void setCategoriesList ( QStringList * c ) 274 void setCategoriesList ( QStringList * c )
274 { 275 {
275 oldCategories = c; 276 oldCategories = c;
276 } 277 }
277 278
278 QDateTime fromString ( QString s, bool useTz = true ) { 279 QDateTime fromString ( QString s, bool useTz = true ) {
279 QDateTime dt; 280 QDateTime dt;
280 int y,m,t,h,min,sec; 281 int y,m,t,h,min,sec;
281 y = s.mid(0,4).toInt(); 282 y = s.mid(0,4).toInt();
282 m = s.mid(4,2).toInt(); 283 m = s.mid(4,2).toInt();
283 t = s.mid(6,2).toInt(); 284 t = s.mid(6,2).toInt();
284 h = s.mid(9,2).toInt(); 285 h = s.mid(9,2).toInt();
285 min = s.mid(11,2).toInt(); 286 min = s.mid(11,2).toInt();
286 sec = s.mid(13,2).toInt(); 287 sec = s.mid(13,2).toInt();
287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
288 int offset = KGlobal::locale()->localTimeOffset( dt ); 289 int offset = KGlobal::locale()->localTimeOffset( dt );
289 if ( useTz ) 290 if ( useTz )
290 dt = dt.addSecs ( offset*60); 291 dt = dt.addSecs ( offset*60);
291 return dt; 292 return dt;
292 293
293 } 294 }
294 protected: 295 protected:
295 QDateTime toDateTime( const QString &value ) 296 QDateTime toDateTime( const QString &value )
296 { 297 {
297 QDateTime dt; 298 QDateTime dt;
298 dt.setTime_t( value.toUInt() ); 299 dt.setTime_t( value.toUInt() );
299 300
300 return dt; 301 return dt;
301 } 302 }
302 303
303 QStringList lookupCategories( const QString &categoryList ) 304 QStringList lookupCategories( const QString &categoryList )
304 { 305 {
305 QStringList categoryIds = QStringList::split( ";", categoryList ); 306 QStringList categoryIds = QStringList::split( ";", categoryList );
306 QStringList categories; 307 QStringList categories;
307 QStringList::ConstIterator it; 308 QStringList::ConstIterator it;
308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
309 QString cate = category( *it ); 310 QString cate = category( *it );
310 if ( oldCategories ) { 311 if ( oldCategories ) {
311 if ( ! oldCategories->contains( cate ) ) 312 if ( ! oldCategories->contains( cate ) )
312 oldCategories->append( cate ); 313 oldCategories->append( cate );
313 } 314 }
314 categories.append(cate ); 315 categories.append(cate );
315 } 316 }
316 return categories; 317 return categories;
317 } 318 }
318 319
319 private: 320 private:
320 Calendar *mCalendar; 321 Calendar *mCalendar;
321 QStringList * oldCategories; 322 QStringList * oldCategories;
322 static QString category( const QString &id ) 323 static QString category( const QString &id )
323 { 324 {
324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
325 if ( it == mCategoriesMap.end() ) return id; 326 if ( it == mCategoriesMap.end() ) return id;
326 else return *it; 327 else return *it;
327 } 328 }
328 329
329 static void setCategory( const QString &id, const QString &name ) 330 static void setCategory( const QString &id, const QString &name )
330 { 331 {
331 mCategoriesMap.insert( id, name ); 332 mCategoriesMap.insert( id, name );
332 } 333 }
333 334
334 static QMap<QString,QString> mCategoriesMap; 335 static QMap<QString,QString> mCategoriesMap;
335}; 336};
336 337
337QMap<QString,QString> SharpParser::mCategoriesMap; 338QMap<QString,QString> SharpParser::mCategoriesMap;
338 339
339SharpFormat::SharpFormat() 340SharpFormat::SharpFormat()
340{ 341{
341 mCategories = 0; 342 mCategories = 0;
342} 343}
343 344
344SharpFormat::~SharpFormat() 345SharpFormat::~SharpFormat()
345{ 346{
346} 347}
347ulong SharpFormat::getCsum( const QStringList & attList) 348ulong SharpFormat::getCsum( const QStringList & attList)
348{ 349{
349 int max = attList.count() -1; 350 int max = attList.count() -1;
350 ulong cSum = 0; 351 ulong cSum = 0;
351 int j,k,i; 352 int j,k,i;
352 int add; 353 int add;
353 for ( i = 1; i < max ; ++i ) { 354 for ( i = 1; i < max ; ++i ) {
354 QString s = attList[i]; 355 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 356 if ( ! s.isEmpty() ){
356 j = s.length(); 357 j = s.length();
357 for ( k = 0; k < j; ++k ) { 358 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 359 int mul = k +1;
359 add = s[k].unicode (); 360 add = s[k].unicode ();
360 if ( k < 16 ) 361 if ( k < 16 )
361 mul = mul * mul; 362 mul = mul * mul;
362 add = add * mul *i*i*i; 363 add = add * mul *i*i*i;
363 cSum += add; 364 cSum += add;
364 } 365 }
365 } 366 }
366 } 367 }
367 return cSum; 368 return cSum;
368 369
369} 370}
370#include <stdlib.h> 371#include <stdlib.h>
371#define DEBUGMODE false 372//#define DEBUGMODE false
373#define DEBUGMODE true
372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
373{ 375{
374 376
375 377
376 bool debug = DEBUGMODE; 378 bool debug = DEBUGMODE;
377 //debug = true;
378 QString text; 379 QString text;
379 QString codec = "utf8"; 380 QString codec = "utf8";
380 QLabel status ( i18n("Reading events ..."), 0 ); 381 QLabel status ( i18n("Reading events ..."), 0 );
381 382
382 int w = status.sizeHint().width()+20 ; 383 int w = status.sizeHint().width()+20 ;
383 if ( w < 200 ) w = 200; 384 if ( w < 200 ) w = 200;
384 int h = status.sizeHint().height()+20 ; 385 int h = status.sizeHint().height()+20 ;
385 int dw = QApplication::desktop()->width(); 386 int dw = QApplication::desktop()->width();
386 int dh = QApplication::desktop()->height(); 387 int dh = QApplication::desktop()->height();
387 status.setCaption(i18n("Reading DTM Data") ); 388 status.setCaption(i18n("Reading DTM Data") );
388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
389 status.show(); 390 status.show();
390 status.raise(); 391 status.raise();
391 qApp->processEvents(); 392 qApp->processEvents();
392 QString fileName; 393 QString fileName;
393 if ( ! debug ) { 394 if ( ! debug ) {
394 fileName = "/tmp/kopitempout"; 395 fileName = "/tmp/kopitempout";
395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
396 system ( command.latin1() ); 397 system ( command.latin1() );
397 } else { 398 } else {
398 fileName = "/tmp/events.txt"; 399 fileName = "/tmp/events.txt";
399 400
400 } 401 }
401 QFile file( fileName ); 402 QFile file( fileName );
402 if (!file.open( IO_ReadOnly ) ) { 403 if (!file.open( IO_ReadOnly ) ) {
403 return false; 404 return false;
404 405
405 } 406 }
406 QTextStream ts( &file ); 407 QTextStream ts( &file );
407 ts.setCodec( QTextCodec::codecForName("utf8") ); 408 ts.setCodec( QTextCodec::codecForName("utf8") );
408 text = ts.read(); 409 text = ts.read();
409 file.close(); 410 file.close();
410 status.setText( i18n("Processing events ...") ); 411 status.setText( i18n("Processing events ...") );
411 status.raise(); 412 status.raise();
412 qApp->processEvents(); 413 qApp->processEvents();
413 fromString2Cal( calendar, existngCal, text, "Event" ); 414 fromString2Cal( calendar, existngCal, text, "Event" );
414 status.setText( i18n("Reading todos ...") ); 415 status.setText( i18n("Reading todos ...") );
415 qApp->processEvents(); 416 qApp->processEvents();
416 if ( ! debug ) { 417 if ( ! debug ) {
417 fileName = "/tmp/kopitempout"; 418 fileName = "/tmp/kopitempout";
418 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 419 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
419 system ( command.latin1() ); 420 system ( command.latin1() );
420 } else { 421 } else {
421 fileName = "/tmp/todo.txt"; 422 fileName = "/tmp/todo.txt";
422 } 423 }
423 file.setName( fileName ); 424 file.setName( fileName );
424 if (!file.open( IO_ReadOnly ) ) { 425 if (!file.open( IO_ReadOnly ) ) {
425 return false; 426 return false;
426 427
427 } 428 }
428 ts.setDevice( &file ); 429 ts.setDevice( &file );
429 text = ts.read(); 430 text = ts.read();
430 file.close(); 431 file.close();
431 432
432 status.setText( i18n("Processing todos ...") ); 433 status.setText( i18n("Processing todos ...") );
433 status.raise(); 434 status.raise();
434 qApp->processEvents(); 435 qApp->processEvents();
435 fromString2Cal( calendar, existngCal, text, "Todo" ); 436 fromString2Cal( calendar, existngCal, text, "Todo" );
436 return true; 437 return true;
437} 438}
438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
439{ 440{
440 int retval = -1; 441 int retval = -1;
441 QStringList templist; 442 QStringList templist;
442 QString tempString; 443 QString tempString;
443 int start = 0; 444 int start = 0;
444 int len = answer.length(); 445 int len = answer.length();
445 int end = answer.find ("\n",start)+1; 446 int end = answer.find ("\n",start)+1;
446 bool ok = true; 447 bool ok = true;
447 start = end; 448 start = end;
448 int ccc = 0; 449 int ccc = 0;
449 while ( start > 0 ) { 450 while ( start > 0 ) {
450 templist.clear(); 451 templist.clear();
451 ok = true; 452 ok = true;
452 int loopCount = 0; 453 int loopCount = 0;
453 while ( ok ) { 454 while ( ok ) {
454 ++loopCount; 455 ++loopCount;
455 if ( loopCount > 25 ) { 456 if ( loopCount > 25 ) {
456 qDebug("KO: Error in while loop"); 457 qDebug("KO: Error in while loop");
457 ok = false; 458 ok = false;
458 start = 0; 459 start = 0;
459 break; 460 break;
460 } 461 }
461 if ( ok ) 462 if ( ok )
462 tempString = getPart( answer, ok, start ); 463 tempString = getPart( answer, ok, start );
463 if ( start >= len || start == 0 ) { 464 if ( start >= len || start == 0 ) {
464 start = 0; 465 start = 0;
465 ok = false; 466 ok = false;
466 } 467 }
467 if ( tempString.right(1) =="\n" ) 468 if ( tempString.right(1) =="\n" )
468 tempString = tempString.left( tempString.length()-1); 469 tempString = tempString.left( tempString.length()-1);
469 470
470 templist.append( tempString ); 471 templist.append( tempString );
471 } 472 }
472 ++ccc; 473 ++ccc;
473 if ( ccc == 2 && loopCount < 25 ) { 474 if ( ccc == 2 && loopCount < 25 ) {
474 start = 0; 475 start = 0;
475 bool ok; 476 bool ok;
476 int newnum = templist[0].toInt( &ok ); 477 int newnum = templist[0].toInt( &ok );
477 if ( ok && newnum > 0) { 478 if ( ok && newnum > 0) {
478 retval = newnum; 479 retval = newnum;
479 inc->setID( "Sharp_DTM",templist[0] ); 480 inc->setID( "Sharp_DTM",templist[0] );
480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
482 } 483 }
483 } 484 }
484 } 485 }
485 //qDebug("getNumFromRecord returning : %d ", retval); 486 //qDebug("getNumFromRecord returning : %d ", retval);
486 return retval; 487 return retval;
487} 488}
488bool SharpFormat::save( Calendar *calendar) 489bool SharpFormat::save( Calendar *calendar)
489{ 490{
490 491
491 QLabel status ( i18n("Processing/adding events ..."), 0 ); 492 QLabel status ( i18n("Processing/adding events ..."), 0 );
492 int w = status.sizeHint().width()+20 ; 493 int w = status.sizeHint().width()+20 ;
493 if ( w < 200 ) w = 200; 494 if ( w < 200 ) w = 200;
494 int h = status.sizeHint().height()+20 ; 495 int h = status.sizeHint().height()+20 ;
495 int dw = QApplication::desktop()->width(); 496 int dw = QApplication::desktop()->width();
496 int dh = QApplication::desktop()->height(); 497 int dh = QApplication::desktop()->height();
497 status.setCaption(i18n("Writing DTM Data") ); 498 status.setCaption(i18n("Writing DTM Data") );
498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 499 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
499 status.show(); 500 status.show();
500 status.raise(); 501 status.raise();
501 qApp->processEvents(); 502 qApp->processEvents();
502 bool debug = DEBUGMODE; 503 bool debug = DEBUGMODE;
503 QString codec = "utf8"; 504 QString codec = "utf8";
504 QString answer; 505 QString answer;
505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 506 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 507 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
507 QString command; 508 QString command;
508 QPtrList<Event> er = calendar->rawEvents(); 509 QPtrList<Event> er = calendar->rawEvents();
509 Event* ev = er.first(); 510 Event* ev = er.first();
510 QString fileName = "/tmp/kopitempout"; 511 QString fileName = "/tmp/kopitempout";
511 int i = 0; 512 int i = 0;
512 QString changeString = ePrefix; 513 QString changeString = ePrefix;
513 QString deleteString = ePrefix; 514 QString deleteString = ePrefix;
514 bool deleteEnt = false; 515 bool deleteEnt = false;
515 bool changeEnt = false; 516 bool changeEnt = false;
516 QString message = i18n("Processing event # "); 517 QString message = i18n("Processing event # ");
517 int procCount = 0; 518 int procCount = 0;
518 while ( ev ) { 519 while ( ev ) {
519 //qDebug("i %d ", ++i); 520 //qDebug("i %d ", ++i);
520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 521 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
521 status.setText ( message + QString::number ( ++procCount ) ); 522 status.setText ( message + QString::number ( ++procCount ) );
522 qApp->processEvents(); 523 qApp->processEvents();
523 QString eString = getEventString( ev ); 524 QString eString = getEventString( ev );
524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 525 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
525 // deleting empty strings does not work. 526 // deleting empty strings does not work.
526 // we write first and x and then delete the record with the x 527 // we write first and x and then delete the record with the x
527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 528 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
528 changeString += eString + "\n"; 529 changeString += eString + "\n";
529 deleteString += eString + "\n"; 530 deleteString += eString + "\n";
530 deleteEnt = true; 531 deleteEnt = true;
531 changeEnt = true; 532 changeEnt = true;
532 } 533 }
533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 534 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 535 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
535 system ( command.utf8() ); 536 system ( command.utf8() );
536 QFile file( fileName ); 537 QFile file( fileName );
537 if (!file.open( IO_ReadOnly ) ) { 538 if (!file.open( IO_ReadOnly ) ) {
538 return false; 539 return false;
539 540
540 } 541 }
541 QTextStream ts( &file ); 542 QTextStream ts( &file );
542 ts.setCodec( QTextCodec::codecForName("utf8") ); 543 ts.setCodec( QTextCodec::codecForName("utf8") );
543 answer = ts.read(); 544 answer = ts.read();
544 file.close(); 545 file.close();
545 //qDebug("answer \n%s ", answer.latin1()); 546 //qDebug("answer \n%s ", answer.latin1());
546 getNumFromRecord( answer, ev ) ; 547 getNumFromRecord( answer, ev ) ;
547 548
548 } 549 }
549 else { // change existing 550 else { // change existing
550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 551 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 552 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
552 changeString += eString + "\n"; 553 changeString += eString + "\n";
553 changeEnt = true; 554 changeEnt = true;
554 555
555 } 556 }
556 } 557 }
557 ev = er.next(); 558 ev = er.next();
558 } 559 }
559 status.setText ( i18n("Changing events ...") ); 560 status.setText ( i18n("Changing events ...") );
560 qApp->processEvents(); 561 qApp->processEvents();
561 //qDebug("changing... "); 562 //qDebug("changing... ");
562 if ( changeEnt ) { 563 if ( changeEnt ) {
563 QFile file( fileName ); 564 QFile file( fileName );
564 if (!file.open( IO_WriteOnly ) ) { 565 if (!file.open( IO_WriteOnly ) ) {
565 return false; 566 return false;
566 567
567 } 568 }
568 QTextStream ts( &file ); 569 QTextStream ts( &file );
569 ts.setCodec( QTextCodec::codecForName("utf8") ); 570 ts.setCodec( QTextCodec::codecForName("utf8") );
570 ts << changeString ; 571 ts << changeString ;
571 file.close(); 572 file.close();
572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 573 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
573 system ( command.latin1() ); 574 system ( command.latin1() );
574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 575 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
575 576
576 } 577 }
577 status.setText ( i18n("Deleting events ...") ); 578 status.setText ( i18n("Deleting events ...") );
578 qApp->processEvents(); 579 qApp->processEvents();
579 //qDebug("deleting... "); 580 //qDebug("deleting... ");
580 if ( deleteEnt ) { 581 if ( deleteEnt ) {
581 QFile file( fileName ); 582 QFile file( fileName );
582 if (!file.open( IO_WriteOnly ) ) { 583 if (!file.open( IO_WriteOnly ) ) {
583 return false; 584 return false;
584 585
585 } 586 }
586 QTextStream ts( &file ); 587 QTextStream ts( &file );
587 ts.setCodec( QTextCodec::codecForName("utf8") ); 588 ts.setCodec( QTextCodec::codecForName("utf8") );
588 ts << deleteString; 589 ts << deleteString;
589 file.close(); 590 file.close();
590 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 591 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
591 system ( command.latin1() ); 592 system ( command.latin1() );
592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 593 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
593 } 594 }
594 595
595 596
596 changeString = tPrefix; 597 changeString = tPrefix;
597 deleteString = tPrefix; 598 deleteString = tPrefix;
598 status.setText ( i18n("Processing todos ...") ); 599 status.setText ( i18n("Processing todos ...") );
599 qApp->processEvents(); 600 qApp->processEvents();
600 QPtrList<Todo> tl = calendar->rawTodos(); 601 QPtrList<Todo> tl = calendar->rawTodos();
601 Todo* to = tl.first(); 602 Todo* to = tl.first();
602 i = 0; 603 i = 0;
603 message = i18n("Processing todo # "); 604 message = i18n("Processing todo # ");
604 procCount = 0; 605 procCount = 0;
605 while ( to ) { 606 while ( to ) {
606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 607 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
607 status.setText ( message + QString::number ( ++procCount ) ); 608 status.setText ( message + QString::number ( ++procCount ) );
608 qApp->processEvents(); 609 qApp->processEvents();
609 QString eString = getTodoString( to ); 610 QString eString = getTodoString( to );
610 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 611 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
611 // deleting empty strings does not work. 612 // deleting empty strings does not work.
612 // we write first and x and then delete the record with the x 613 // we write first and x and then delete the record with the x
613 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 614 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
614 changeString += eString + "\n"; 615 changeString += eString + "\n";
615 deleteString += eString + "\n"; 616 deleteString += eString + "\n";
616 deleteEnt = true; 617 deleteEnt = true;
617 changeEnt = true; 618 changeEnt = true;
618 } 619 }
619 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 620 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
620 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 621 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
621 system ( command.utf8() ); 622 system ( command.utf8() );
622 QFile file( fileName ); 623 QFile file( fileName );
623 if (!file.open( IO_ReadOnly ) ) { 624 if (!file.open( IO_ReadOnly ) ) {
624 return false; 625 return false;
625 626
626 } 627 }
627 QTextStream ts( &file ); 628 QTextStream ts( &file );
628 ts.setCodec( QTextCodec::codecForName("utf8") ); 629 ts.setCodec( QTextCodec::codecForName("utf8") );
629 answer = ts.read(); 630 answer = ts.read();
630 file.close(); 631 file.close();
631 //qDebug("answer \n%s ", answer.latin1()); 632 //qDebug("answer \n%s ", answer.latin1());
632 getNumFromRecord( answer, to ) ; 633 getNumFromRecord( answer, to ) ;
633 634