summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp16
-rw-r--r--libkcal/sharpformat.cpp8
2 files changed, 22 insertions, 2 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 7e1c9cd..94744fb 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,1154 +1,1166 @@
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 "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
53 ; 53 ;
54 } 54 }
55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
56 { 56 {
57 57
58 int id = ToDo->Location; 58 int id = ToDo->Location;
59 Todo *todo; 59 Todo *todo;
60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
61 if (todo ) 61 if (todo )
62 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
63 else 63 else
64 todo = new Todo; 64 todo = new Todo;
65 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
67 int priority; 67 int priority;
68 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
69 case GSM_Priority_Low : priority = 1; break; 69 case GSM_Priority_Low : priority = 1; break;
70 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
71 case GSM_Priority_High : priority = 5; break; 71 case GSM_Priority_High : priority = 5; break;
72 default :priority = 3 ;break; 72 default :priority = 3 ;break;
73 } 73 }
74 todo->setPriority( priority ); 74 todo->setPriority( priority );
75 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
76 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
77 int j; 77 int j;
78 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
79 bool alarm = false; 79 bool alarm = false;
80 QDateTime alarmDt; 80 QDateTime alarmDt;
81 GSM_Category Category; 81 GSM_Category Category;
82 int error; 82 int error;
83 QString completedString = "no"; 83 QString completedString = "no";
84 for (j=0;j<ToDo->EntriesNum;j++) { 84 for (j=0;j<ToDo->EntriesNum;j++) {
85 85
86 //qDebug(" for todo %d",ToDo->Location ); 86 //qDebug(" for todo %d",ToDo->Location );
87 switch (ToDo->Entries[j].EntryType) { 87 switch (ToDo->Entries[j].EntryType) {
88 case TODO_END_DATETIME: 88 case TODO_END_DATETIME:
89 dtp = &ToDo->Entries[j].Date ; 89 dtp = &ToDo->Entries[j].Date ;
90 todo->setDtDue (fromGSM ( dtp )); 90 todo->setDtDue (fromGSM ( dtp ));
91 break; 91 break;
92 case TODO_COMPLETED: 92 case TODO_COMPLETED:
93 if ( ToDo->Entries[j].Number == 1 ) { 93 if ( ToDo->Entries[j].Number == 1 ) {
94 todo->setCompleted( true ); 94 todo->setCompleted( true );
95 completedString = "yes"; 95 completedString = "yes";
96 } 96 }
97 else { 97 else {
98 todo->setCompleted( false ); 98 todo->setCompleted( false );
99 } 99 }
100 break; 100 break;
101 case TODO_ALARM_DATETIME: 101 case TODO_ALARM_DATETIME:
102 dtp = &ToDo->Entries[j].Date ; 102 dtp = &ToDo->Entries[j].Date ;
103 alarm = true; 103 alarm = true;
104 alarmDt = fromGSM ( dtp ); 104 alarmDt = fromGSM ( dtp );
105 break; 105 break;
106 case TODO_SILENT_ALARM_DATETIME: 106 case TODO_SILENT_ALARM_DATETIME:
107 dtp = &ToDo->Entries[j].Date ; 107 dtp = &ToDo->Entries[j].Date ;
108 alarm = true; 108 alarm = true;
109 alarmDt = fromGSM ( dtp ); 109 alarmDt = fromGSM ( dtp );
110 break; 110 break;
111 case TODO_TEXT: 111 case TODO_TEXT:
112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
114 break; 114 break;
115 case TODO_PRIVATE: 115 case TODO_PRIVATE:
116 if ( ToDo->Entries[j].Number == 1 ) 116 if ( ToDo->Entries[j].Number == 1 )
117 todo->setSecrecy( Incidence::SecrecyPrivate ); 117 todo->setSecrecy( Incidence::SecrecyPrivate );
118 else 118 else
119 todo->setSecrecy( Incidence::SecrecyPublic ); 119 todo->setSecrecy( Incidence::SecrecyPublic );
120 break; 120 break;
121 case TODO_CATEGORY: 121 case TODO_CATEGORY:
122 Category.Location = ToDo->Entries[j].Number; 122 Category.Location = ToDo->Entries[j].Number;
123 Category.Type = Category_ToDo; 123 Category.Type = Category_ToDo;
124 error=Phone->GetCategory(s, &Category); 124 error=Phone->GetCategory(s, &Category);
125 if (error == ERR_NONE) { 125 if (error == ERR_NONE) {
126 QStringList cat = todo->categories(); 126 QStringList cat = todo->categories();
127 QString nCat = QString ( (const char*)Category.Name ); 127 QString nCat = QString ( (const char*)Category.Name );
128 if ( !nCat.isEmpty() ) 128 if ( !nCat.isEmpty() )
129 if ( !cat.contains( nCat )) { 129 if ( !cat.contains( nCat )) {
130 cat << nCat; 130 cat << nCat;
131 todo->setCategories( cat ); 131 todo->setCategories( cat );
132 } 132 }
133 } 133 }
134 break; 134 break;
135 case TODO_CONTACTID: 135 case TODO_CONTACTID:
136#if 0 136#if 0
137 // not supported 137 // not supported
138 entry.Location = ToDo->Entries[j].Number; 138 entry.Location = ToDo->Entries[j].Number;
139 entry.MemoryType = MEM_ME; 139 entry.MemoryType = MEM_ME;
140 error=Phone->GetMemory(s, &entry); 140 error=Phone->GetMemory(s, &entry);
141 if (error == ERR_NONE) { 141 if (error == ERR_NONE) {
142 name = GSM_PhonebookGetEntryName(&entry); 142 name = GSM_PhonebookGetEntryName(&entry);
143 if (name != NULL) { 143 if (name != NULL) {
144 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); 144 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
145 } else { 145 } else {
146 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 146 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
147 } 147 }
148 } else { 148 } else {
149 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 149 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
150 } 150 }
151#endif 151#endif
152 break; 152 break;
153 case TODO_PHONE: 153 case TODO_PHONE:
154#if 0 154#if 0
155 // not supported 155 // not supported
156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
157#endif 157#endif
158 break; 158 break;
159 } 159 }
160 } 160 }
161 QString alarmString = ""; 161 QString alarmString = "";
162 if ( alarm ) { 162 if ( alarm ) {
163 Alarm *alarm; 163 Alarm *alarm;
164 if ( todo->alarms().count() > 0 ) 164 if ( todo->alarms().count() > 0 )
165 alarm = todo->alarms().first(); 165 alarm = todo->alarms().first();
166 else { 166 else {
167 alarm = new Alarm( todo ); 167 alarm = new Alarm( todo );
168 todo->addAlarm( alarm ); 168 todo->addAlarm( alarm );
169 } 169 }
170 alarm->setType( Alarm::Audio ); 170 alarm->setType( Alarm::Audio );
171 alarm->setEnabled( true ); 171 alarm->setEnabled( true );
172 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 172 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
173 alarm->setStartOffset( alarmOffset ); 173 alarm->setStartOffset( -alarmOffset );
174 alarmString = QString::number( alarmOffset ); 174 alarmString = QString::number( alarmOffset );
175 } else {
176 Alarm *alarm;
177 if ( todo->alarms().count() > 0 ) {
178 alarm = todo->alarms().first();
179 alarm->setEnabled( false );
180 }
175 } 181 }
176 // csum ***************************************** 182 // csum *****************************************
177 QStringList attList; 183 QStringList attList;
178 uint cSum; 184 uint cSum;
179 if ( todo->hasDueDate() ) 185 if ( todo->hasDueDate() )
180 attList << dtToString ( todo->dtDue() ); 186 attList << dtToString ( todo->dtDue() );
181 attList << QString::number( id ); 187 attList << QString::number( id );
182 attList << todo->summary(); 188 attList << todo->summary();
183 attList << completedString; 189 attList << completedString;
184 attList << QString::number( todo->priority() ); 190 attList << QString::number( todo->priority() );
185 attList << alarmString; 191 attList << alarmString;
186 attList << todo->categoriesStr(); 192 attList << todo->categoriesStr();
187 attList << todo->secrecyStr(); 193 attList << todo->secrecyStr();
188 cSum = PhoneFormat::getCsum(attList ); 194 cSum = PhoneFormat::getCsum(attList );
189 todo->setCsum( mProfileName, QString::number( cSum )); 195 todo->setCsum( mProfileName, QString::number( cSum ));
190 mCalendar->addTodo( todo); 196 mCalendar->addTodo( todo);
191 197
192 return true; 198 return true;
193 } 199 }
194 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 200 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
195 { 201 {
196 202
197 int id = Note->Location; 203 int id = Note->Location;
198 Event *event; 204 Event *event;
199 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 205 event = existingCalendar->event( mProfileName ,QString::number( id ) );
200 if ( event ) 206 if ( event )
201 event = (Event*)event->clone(); 207 event = (Event*)event->clone();
202 else 208 else
203 event = new Event; 209 event = new Event;
204 event->setID( mProfileName,QString::number( id ) ); 210 event->setID( mProfileName,QString::number( id ) );
205 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 211 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
206 212
207 213
208 int i = 0; 214 int i = 0;
209 bool repeating = false; 215 bool repeating = false;
210 int repeat_dayofweek = -1; 216 int repeat_dayofweek = -1;
211 int repeat_day = -1; 217 int repeat_day = -1;
212 int repeat_weekofmonth = -1; 218 int repeat_weekofmonth = -1;
213 int repeat_month = -1; 219 int repeat_month = -1;
214 int repeat_frequency = -1; 220 int repeat_frequency = -1;
215 int rec_type = -1; 221 int rec_type = -1;
216 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 222 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
217 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 223 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
218 GSM_DateTime* dtp; 224 GSM_DateTime* dtp;
219 bool alarm = false; 225 bool alarm = false;
220 QDateTime alarmDt; 226 QDateTime alarmDt;
221 repeat_startdate.Day= 0; 227 repeat_startdate.Day= 0;
222 repeat_stopdate.Day = 0; 228 repeat_stopdate.Day = 0;
223 for (i=0;i<Note->EntriesNum;i++) { 229 for (i=0;i<Note->EntriesNum;i++) {
224 230
225 //qDebug(" for ev"); 231 //qDebug(" for ev");
226 switch (Note->Entries[i].EntryType) { 232 switch (Note->Entries[i].EntryType) {
227 case CAL_START_DATETIME: 233 case CAL_START_DATETIME:
228 dtp = &Note->Entries[i].Date ; 234 dtp = &Note->Entries[i].Date ;
229 if ( dtp->Hour > 24 ) { 235 if ( dtp->Hour > 24 ) {
230 event->setFloats( true ); 236 event->setFloats( true );
231 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 237 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
232 } else { 238 } else {
233 event->setDtStart (fromGSM ( dtp )); 239 event->setDtStart (fromGSM ( dtp ));
234 240
235 } 241 }
236 break; 242 break;
237 case CAL_END_DATETIME: 243 case CAL_END_DATETIME:
238 dtp = &Note->Entries[i].Date ; 244 dtp = &Note->Entries[i].Date ;
239 if ( dtp->Hour > 24 ) { 245 if ( dtp->Hour > 24 ) {
240 event->setFloats( true ); 246 event->setFloats( true );
241 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 247 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
242 } else { 248 } else {
243 event->setDtEnd (fromGSM ( dtp )); 249 event->setDtEnd (fromGSM ( dtp ));
244 } 250 }
245 break; 251 break;
246 case CAL_ALARM_DATETIME: 252 case CAL_ALARM_DATETIME:
247 dtp = &Note->Entries[i].Date ; 253 dtp = &Note->Entries[i].Date ;
248 alarm = true; 254 alarm = true;
249 alarmDt = fromGSM ( dtp ); 255 alarmDt = fromGSM ( dtp );
250 break; 256 break;
251 case CAL_SILENT_ALARM_DATETIME: 257 case CAL_SILENT_ALARM_DATETIME:
252 dtp = &Note->Entries[i].Date ; 258 dtp = &Note->Entries[i].Date ;
253 alarm = true; 259 alarm = true;
254 alarmDt = fromGSM ( dtp ); 260 alarmDt = fromGSM ( dtp );
255 break; 261 break;
256 case CAL_RECURRANCE: 262 case CAL_RECURRANCE:
257 rec_type = Note->Entries[i].Number; 263 rec_type = Note->Entries[i].Number;
258 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 264 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
259 break; 265 break;
260 case CAL_TEXT: 266 case CAL_TEXT:
261 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); 267 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
262 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); 268 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
263 break; 269 break;
264 case CAL_LOCATION: 270 case CAL_LOCATION:
265 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); 271 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
266 break; 272 break;
267 case CAL_PHONE: 273 case CAL_PHONE:
268 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 274 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
269 break; 275 break;
270 case CAL_PRIVATE: 276 case CAL_PRIVATE:
271 if ( Note->Entries[i].Number == 1 ) 277 if ( Note->Entries[i].Number == 1 )
272 event->setSecrecy( Incidence::SecrecyPrivate ); 278 event->setSecrecy( Incidence::SecrecyPrivate );
273 else 279 else
274 event->setSecrecy( Incidence::SecrecyPublic ); 280 event->setSecrecy( Incidence::SecrecyPublic );
275 281
276 break; 282 break;
277 case CAL_CONTACTID: 283 case CAL_CONTACTID:
278#if 0 284#if 0
279 entry.Location = Note->Entries[i].Number; 285 entry.Location = Note->Entries[i].Number;
280 entry.MemoryType = MEM_ME; 286 entry.MemoryType = MEM_ME;
281 error=Phone->GetMemory(&s, &entry); 287 error=Phone->GetMemory(&s, &entry);
282 if (error == ERR_NONE) { 288 if (error == ERR_NONE) {
283 name = GSM_PhonebookGetEntryName(&entry); 289 name = GSM_PhonebookGetEntryName(&entry);
284 if (name != NULL) { 290 if (name != NULL) {
285 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 291 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
286 } else { 292 } else {
287 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 293 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
288 } 294 }
289 } else { 295 } else {
290 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 296 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
291 } 297 }
292#endif 298#endif
293 break; 299 break;
294 case CAL_REPEAT_DAYOFWEEK: 300 case CAL_REPEAT_DAYOFWEEK:
295 repeat_dayofweek = Note->Entries[i].Number; 301 repeat_dayofweek = Note->Entries[i].Number;
296 repeating = true; 302 repeating = true;
297 break; 303 break;
298 case CAL_REPEAT_DAY: 304 case CAL_REPEAT_DAY:
299 repeat_day = Note->Entries[i].Number; 305 repeat_day = Note->Entries[i].Number;
300 repeating = true; 306 repeating = true;
301 break; 307 break;
302 case CAL_REPEAT_WEEKOFMONTH: 308 case CAL_REPEAT_WEEKOFMONTH:
303 repeat_weekofmonth = Note->Entries[i].Number; 309 repeat_weekofmonth = Note->Entries[i].Number;
304 repeating = true; 310 repeating = true;
305 break; 311 break;
306 case CAL_REPEAT_MONTH: 312 case CAL_REPEAT_MONTH:
307 repeat_month = Note->Entries[i].Number; 313 repeat_month = Note->Entries[i].Number;
308 repeating = true; 314 repeating = true;
309 break; 315 break;
310 case CAL_REPEAT_FREQUENCY: 316 case CAL_REPEAT_FREQUENCY:
311 repeat_frequency = Note->Entries[i].Number; 317 repeat_frequency = Note->Entries[i].Number;
312 repeating = true; 318 repeating = true;
313 break; 319 break;
314 case CAL_REPEAT_STARTDATE: 320 case CAL_REPEAT_STARTDATE:
315 repeat_startdate = Note->Entries[i].Date; 321 repeat_startdate = Note->Entries[i].Date;
316 repeating = true; 322 repeating = true;
317 break; 323 break;
318 case CAL_REPEAT_STOPDATE: 324 case CAL_REPEAT_STOPDATE:
319 repeat_stopdate = Note->Entries[i].Date; 325 repeat_stopdate = Note->Entries[i].Date;
320 repeating = true; 326 repeating = true;
321 break; 327 break;
322 } 328 }
323 } 329 }
324#if 0 330#if 0
325 event->setDescription( attList[4] ); 331 event->setDescription( attList[4] );
326 bool repeating = false; 332 bool repeating = false;
327 int repeat_dayofweek = -1; 333 int repeat_dayofweek = -1;
328 int repeat_day = -1; 334 int repeat_day = -1;
329 int repeat_weekofmonth = -1; 335 int repeat_weekofmonth = -1;
330 int repeat_month = -1; 336 int repeat_month = -1;
331 int repeat_frequency = -1; 337 int repeat_frequency = -1;
332 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 338 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
333 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 339 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
334 340
335#endif 341#endif
336 342
337 QString recurString = "no"; 343 QString recurString = "no";
338 if ( repeating ) { 344 if ( repeating ) {
339 recurString = "y"; 345 recurString = "y";
340 if ( repeat_dayofweek >= 0 ) 346 if ( repeat_dayofweek >= 0 )
341 recurString += "dow" + QString::number (repeat_dayofweek); 347 recurString += "dow" + QString::number (repeat_dayofweek);
342 if ( repeat_day >= 0 ) 348 if ( repeat_day >= 0 )
343 recurString += "d" + QString::number (repeat_day); 349 recurString += "d" + QString::number (repeat_day);
344 if ( repeat_weekofmonth >= 0 ) 350 if ( repeat_weekofmonth >= 0 )
345 recurString += "w" + QString::number (repeat_weekofmonth); 351 recurString += "w" + QString::number (repeat_weekofmonth);
346 if ( repeat_month >= 0 ) 352 if ( repeat_month >= 0 )
347 recurString += "m" + QString::number ( repeat_month ); 353 recurString += "m" + QString::number ( repeat_month );
348 if ( repeat_frequency >= 0 ) 354 if ( repeat_frequency >= 0 )
349 recurString += "f" + QString::number (repeat_frequency ); 355 recurString += "f" + QString::number (repeat_frequency );
350 356
351 int rtype = 0; 357 int rtype = 0;
352 // qDebug("recurs "); 358 // qDebug("recurs ");
353 QDate startDate, endDate; 359 QDate startDate, endDate;
354 if ( repeat_startdate.Day > 0 ) 360 if ( repeat_startdate.Day > 0 )
355 startDate = datefromGSM ( &repeat_startdate ); 361 startDate = datefromGSM ( &repeat_startdate );
356 else 362 else
357 startDate = event->dtStart().date(); 363 startDate = event->dtStart().date();
358 int freq = repeat_frequency; 364 int freq = repeat_frequency;
359 bool hasEndDate = false; 365 bool hasEndDate = false;
360 if ( repeat_stopdate.Day > 0 ) { 366 if ( repeat_stopdate.Day > 0 ) {
361 endDate = datefromGSM ( &repeat_stopdate ); 367 endDate = datefromGSM ( &repeat_stopdate );
362 hasEndDate = true; 368 hasEndDate = true;
363 } 369 }
364 370
365 uint weekDaysNum = repeat_dayofweek ; 371 uint weekDaysNum = repeat_dayofweek ;
366 372
367 QBitArray weekDays( 7 ); 373 QBitArray weekDays( 7 );
368 int i; 374 int i;
369 int bb = 1; 375 int bb = 1;
370 for( i = 1; i <= 7; ++i ) { 376 for( i = 1; i <= 7; ++i ) {
371 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 377 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
372 bb = 2 << (i-1); 378 bb = 2 << (i-1);
373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 379 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
374 } 380 }
375 // qDebug("next "); 381 // qDebug("next ");
376 int pos = 0; 382 int pos = 0;
377 Recurrence *r = event->recurrence(); 383 Recurrence *r = event->recurrence();
378 /* 384 /*
379 0 daily; 385 0 daily;
380 1 weekly;x 386 1 weekly;x
381 2 monthpos;x 387 2 monthpos;x
382 3 monthlyday; 388 3 monthlyday;
383 4 rYearlyMont 389 4 rYearlyMont
384 bool repeating = false; 390 bool repeating = false;
385 int repeat_dayofweek = -1; 391 int repeat_dayofweek = -1;
386 int repeat_day = -1; 392 int repeat_day = -1;
387 int repeat_weekofmonth = -1; 393 int repeat_weekofmonth = -1;
388 int repeat_month = -1; 394 int repeat_month = -1;
389 int repeat_frequency = -1; 395 int repeat_frequency = -1;
390 */ 396 */
391 int dayOfWeek = startDate.dayOfWeek(); 397 int dayOfWeek = startDate.dayOfWeek();
392 if ( repeat_weekofmonth >= 0 ) { 398 if ( repeat_weekofmonth >= 0 ) {
393 rtype = 2; 399 rtype = 2;
394 pos = repeat_weekofmonth; 400 pos = repeat_weekofmonth;
395 if ( repeat_dayofweek >= 0 ) 401 if ( repeat_dayofweek >= 0 )
396 dayOfWeek = repeat_dayofweek; 402 dayOfWeek = repeat_dayofweek;
397 } else if ( repeat_dayofweek >= 0 ) { 403 } else if ( repeat_dayofweek >= 0 ) {
398 rtype = 1; 404 rtype = 1;
399 } if ( repeat_dayofweek >= 0 ) { 405 } if ( repeat_dayofweek >= 0 ) {
400 rtype = 1; 406 rtype = 1;
401 } 407 }
402 408
403 if ( rtype == 0 ) { 409 if ( rtype == 0 ) {
404 if ( hasEndDate ) r->setDaily( freq, endDate ); 410 if ( hasEndDate ) r->setDaily( freq, endDate );
405 else r->setDaily( freq, -1 ); 411 else r->setDaily( freq, -1 );
406 } else if ( rtype == 1 ) { 412 } else if ( rtype == 1 ) {
407 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 413 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
408 else r->setWeekly( freq, weekDays, -1 ); 414 else r->setWeekly( freq, weekDays, -1 );
409 } else if ( rtype == 3 ) { 415 } else if ( rtype == 3 ) {
410 if ( hasEndDate ) 416 if ( hasEndDate )
411 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 417 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
412 else 418 else
413 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 419 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
414 r->addMonthlyDay( startDate.day() ); 420 r->addMonthlyDay( startDate.day() );
415 } else if ( rtype == 2 ) { 421 } else if ( rtype == 2 ) {
416 if ( hasEndDate ) 422 if ( hasEndDate )
417 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 423 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
418 else 424 else
419 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 425 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
420 QBitArray days( 7 ); 426 QBitArray days( 7 );
421 days.fill( false ); 427 days.fill( false );
422 days.setBit( dayOfWeek - 1 ); 428 days.setBit( dayOfWeek - 1 );
423 r->addMonthlyPos( pos, days ); 429 r->addMonthlyPos( pos, days );
424 } else if ( rtype == 4 ) { 430 } else if ( rtype == 4 ) {
425 if ( hasEndDate ) 431 if ( hasEndDate )
426 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 432 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
427 else 433 else
428 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 434 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
429 r->addYearlyNum( startDate.month() ); 435 r->addYearlyNum( startDate.month() );
430 } 436 }
431 } else { 437 } else {
432 event->recurrence()->unsetRecurs(); 438 event->recurrence()->unsetRecurs();
433 } 439 }
434 440
435 QStringList categoryList; 441 QStringList categoryList;
436 categoryList << getCategory( Note ); 442 categoryList << getCategory( Note );
437 event->setCategories( categoryList ); 443 event->setCategories( categoryList );
438 QString alarmString = ""; 444 QString alarmString = "";
439 // strange 0 semms to mean: alarm enabled 445 // strange 0 semms to mean: alarm enabled
440 if ( alarm ) { 446 if ( alarm ) {
441 Alarm *alarm; 447 Alarm *alarm;
442 if ( event->alarms().count() > 0 ) 448 if ( event->alarms().count() > 0 )
443 alarm = event->alarms().first(); 449 alarm = event->alarms().first();
444 else { 450 else {
445 alarm = new Alarm( event ); 451 alarm = new Alarm( event );
446 event->addAlarm( alarm ); 452 event->addAlarm( alarm );
447 } 453 }
448 alarm->setType( Alarm::Audio ); 454 alarm->setType( Alarm::Audio );
449 alarm->setEnabled( true ); 455 alarm->setEnabled( true );
450 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 456 int alarmOffset = alarmDt.secsTo( event->dtStart() );
451 alarm->setStartOffset( alarmOffset ); 457 alarm->setStartOffset( -alarmOffset );
452 alarmString = QString::number( alarmOffset ); 458 alarmString = QString::number( alarmOffset );
459 } else {
460 Alarm *alarm;
461 if ( event->alarms().count() > 0 ) {
462 alarm = event->alarms().first();
463 alarm->setEnabled( false );
464 }
453 } 465 }
454 // csum ***************************************** 466 // csum *****************************************
455 QStringList attList; 467 QStringList attList;
456 uint cSum; 468 uint cSum;
457 attList << dtToString ( event->dtStart() ); 469 attList << dtToString ( event->dtStart() );
458 attList << dtToString ( event->dtEnd() ); 470 attList << dtToString ( event->dtEnd() );
459 attList << QString::number( id ); 471 attList << QString::number( id );
460 attList << event->summary(); 472 attList << event->summary();
461 attList << event->location(); 473 attList << event->location();
462 attList << alarmString; 474 attList << alarmString;
463 attList << recurString; 475 attList << recurString;
464 attList << event->categoriesStr(); 476 attList << event->categoriesStr();
465 attList << event->secrecyStr(); 477 attList << event->secrecyStr();
466 cSum = PhoneFormat::getCsum(attList ); 478 cSum = PhoneFormat::getCsum(attList );
467 event->setCsum( mProfileName, QString::number( cSum )); 479 event->setCsum( mProfileName, QString::number( cSum ));
468 mCalendar->addEvent( event); 480 mCalendar->addEvent( event);
469 481
470 return true; 482 return true;
471 } 483 }
472 484
473 485
474 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) {
475 QDateTime dt; 487 QDateTime dt;
476 int y,m,t,h,min,sec; 488 int y,m,t,h,min,sec;
477 y = dtp->Year; 489 y = dtp->Year;
478 m = dtp->Month; 490 m = dtp->Month;
479 t = dtp->Day; 491 t = dtp->Day;
480 h = dtp->Hour; 492 h = dtp->Hour;
481 min = dtp->Minute; 493 min = dtp->Minute;
482 sec = dtp->Second; 494 sec = dtp->Second;
483 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
484 // dtp->Timezone: offset in hours 496 // dtp->Timezone: offset in hours
485 int offset = KGlobal::locale()->localTimeOffset( dt ); 497 int offset = KGlobal::locale()->localTimeOffset( dt );
486 if ( useTz ) 498 if ( useTz )
487 dt = dt.addSecs ( offset*60); 499 dt = dt.addSecs ( offset*60);
488 return dt; 500 return dt;
489 501
490 } 502 }
491 503
492 QString dtToString( const QDateTime& dti, bool useTZ = false ) 504 QString dtToString( const QDateTime& dti, bool useTZ = false )
493 { 505 {
494 QString datestr; 506 QString datestr;
495 QString timestr; 507 QString timestr;
496 int offset = KGlobal::locale()->localTimeOffset( dti ); 508 int offset = KGlobal::locale()->localTimeOffset( dti );
497 QDateTime dt; 509 QDateTime dt;
498 if (useTZ) 510 if (useTZ)
499 dt = dti.addSecs ( -(offset*60)); 511 dt = dti.addSecs ( -(offset*60));
500 else 512 else
501 dt = dti; 513 dt = dti;
502 if(dt.date().isValid()){ 514 if(dt.date().isValid()){
503 const QDate& date = dt.date(); 515 const QDate& date = dt.date();
504 datestr.sprintf("%04d%02d%02d", 516 datestr.sprintf("%04d%02d%02d",
505 date.year(), date.month(), date.day()); 517 date.year(), date.month(), date.day());
506 } 518 }
507 if(dt.time().isValid()){ 519 if(dt.time().isValid()){
508 const QTime& time = dt.time(); 520 const QTime& time = dt.time();
509 timestr.sprintf("T%02d%02d%02d", 521 timestr.sprintf("T%02d%02d%02d",
510 time.hour(), time.minute(), time.second()); 522 time.hour(), time.minute(), time.second());
511 } 523 }
512 return datestr + timestr; 524 return datestr + timestr;
513 } 525 }
514 QDate datefromGSM ( GSM_DateTime*dtp ) { 526 QDate datefromGSM ( GSM_DateTime*dtp ) {
515 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 527 return QDate ( dtp->Year, dtp->Month, dtp->Day );
516 } 528 }
517 QString getCategory( GSM_CalendarEntry*Note) 529 QString getCategory( GSM_CalendarEntry*Note)
518 { 530 {
519 QString CATEGORY; 531 QString CATEGORY;
520 switch (Note->Type) { 532 switch (Note->Type) {
521 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
522 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
523 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
524 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
525 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
526 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
527 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
528 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
529 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
530 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
531 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
532 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
533 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
534 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
535 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
536 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
537 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
538 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
539 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
540 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
541 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
542 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
543 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
544 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
545 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
546 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
547 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
548 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
549 default : CATEGORY = QString(""); 561 default : CATEGORY = QString("");
550 } 562 }
551 563
552 return CATEGORY; 564 return CATEGORY;
553 } 565 }
554 566
555protected: 567protected:
556private: 568private:
557 Calendar *mCalendar; 569 Calendar *mCalendar;
558 QString mProfileName ; 570 QString mProfileName ;
559}; 571};
560 572
561 573
562PhoneFormat::PhoneFormat() 574PhoneFormat::PhoneFormat()
563{ 575{
564 ; 576 ;
565} 577}
566 578
567PhoneFormat::~PhoneFormat() 579PhoneFormat::~PhoneFormat()
568{ 580{
569} 581}
570ulong PhoneFormat::getCsum( const QStringList & attList) 582ulong PhoneFormat::getCsum( const QStringList & attList)
571{ 583{
572 int max = attList.count() -1; 584 int max = attList.count() -1;
573 ulong cSum = 0; 585 ulong cSum = 0;
574 int j,k,i; 586 int j,k,i;
575 int add; 587 int add;
576 for ( i = 1; i < max ; ++i ) { 588 for ( i = 1; i < max ; ++i ) {
577 QString s = attList[i]; 589 QString s = attList[i];
578 if ( ! s.isEmpty() ){ 590 if ( ! s.isEmpty() ){
579 j = s.length(); 591 j = s.length();
580 for ( k = 0; k < j; ++k ) { 592 for ( k = 0; k < j; ++k ) {
581 int mul = k +1; 593 int mul = k +1;
582 add = s[k].unicode (); 594 add = s[k].unicode ();
583 if ( k < 16 ) 595 if ( k < 16 )
584 mul = mul * mul; 596 mul = mul * mul;
585 add = add * mul *i*i*i; 597 add = add * mul *i*i*i;
586 cSum += add; 598 cSum += add;
587 } 599 }
588 } 600 }
589 } 601 }
590 return cSum; 602 return cSum;
591 603
592} 604}
593//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 605//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
594#include <stdlib.h> 606#include <stdlib.h>
595#define DEBUGMODE false 607#define DEBUGMODE false
596bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) 608bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model )
597{ 609{
598 mProfileName = profileName; 610 mProfileName = profileName;
599 GSM_StateMachines; 611 GSM_StateMachines;
600 qDebug(" load "); 612 qDebug(" load ");
601 s.opened = false; 613 s.opened = false;
602 s.msg = NULL; 614 s.msg = NULL;
603 s.ConfigNum = 0; 615 s.ConfigNum = 0;
604#if 0 616#if 0
605 static char*cp; 617 static char*cp;
606 static INI_Section *cfg = NULL; 618 static INI_Section *cfg = NULL;
607 cfg=GSM_FindGammuRC(); 619 cfg=GSM_FindGammuRC();
608 int i; 620 int i;
609 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 621 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
610 if (cfg!=NULL) { 622 if (cfg!=NULL) {
611 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); 623 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
612 if (cp) di.coding = cp; 624 if (cp) di.coding = cp;
613 625
614 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); 626 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
615 if (s.Config[i].Localize) { 627 if (s.Config[i].Localize) {
616 s.msg=INI_ReadFile(s.Config[i].Localize, true); 628 s.msg=INI_ReadFile(s.Config[i].Localize, true);
617 } else { 629 } else {
618#if !defined(WIN32) && defined(LOCALE_PATH) 630#if !defined(WIN32) && defined(LOCALE_PATH)
619 locale = setlocale(LC_MESSAGES, NULL); 631 locale = setlocale(LC_MESSAGES, NULL);
620 if (locale != NULL) { 632 if (locale != NULL) {
621 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 633 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
622 LOCALE_PATH, 634 LOCALE_PATH,
623 tolower(locale[0]), 635 tolower(locale[0]),
624 tolower(locale[1])); 636 tolower(locale[1]));
625 s.msg = INI_ReadFile(locale_file, true); 637 s.msg = INI_ReadFile(locale_file, true);
626 } 638 }
627#endif 639#endif
628 } 640 }
629 } 641 }
630 642
631 /* Wanted user specific configuration? */ 643 /* Wanted user specific configuration? */
632 644
633 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 645 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
634 646
635 s.ConfigNum++; 647 s.ConfigNum++;
636 648
637 /* We want to use only one file descriptor for global and state machine debug output */ 649 /* We want to use only one file descriptor for global and state machine debug output */
638 s.Config[i].UseGlobalDebugFile = true; 650 s.Config[i].UseGlobalDebugFile = true;
639 651
640 652
641 653
642 /* We wanted to read just user specified configuration. */ 654 /* We wanted to read just user specified configuration. */
643 {break;} 655 {break;}
644 } 656 }
645 657
646#endif 658#endif
647 setlocale(LC_ALL, ""); 659 setlocale(LC_ALL, "");
648 GSM_ReadConfig(NULL, &s.Config[0], 0); 660 GSM_ReadConfig(NULL, &s.Config[0], 0);
649 s.ConfigNum = 1; 661 s.ConfigNum = 1;
650 GSM_Config *cfg = &s.Config[0]; 662 GSM_Config *cfg = &s.Config[0];
651 if ( ! connection.isEmpty() ) { 663 if ( ! connection.isEmpty() ) {
652 cfg->Connection = strdup(connection.latin1()); 664 cfg->Connection = strdup(connection.latin1());
653 cfg->DefaultConnection = false; 665 cfg->DefaultConnection = false;
654 qDebug("Connection set %s ", cfg->Connection ); 666 qDebug("Connection set %s ", cfg->Connection );
655 667
656 } 668 }
657 if ( ! device.isEmpty() ) { 669 if ( ! device.isEmpty() ) {
658 cfg->Device = strdup(device.latin1()); 670 cfg->Device = strdup(device.latin1());
659 cfg->DefaultDevice = false; 671 cfg->DefaultDevice = false;
660 qDebug("Device set %s ", cfg->Device); 672 qDebug("Device set %s ", cfg->Device);
661 673
662 } 674 }
663 if ( ! model.isEmpty() ) { 675 if ( ! model.isEmpty() ) {
664 strcpy(cfg->Model,model.latin1() ); 676 strcpy(cfg->Model,model.latin1() );
665 cfg->DefaultModel = false; 677 cfg->DefaultModel = false;
666 qDebug("Model set %s ",cfg->Model ); 678 qDebug("Model set %s ",cfg->Model );
667 679
668 680
669 } 681 }
670 int error=GSM_InitConnection(&s,3); 682 int error=GSM_InitConnection(&s,3);
671 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 683 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
672 if ( error != ERR_NONE ) 684 if ( error != ERR_NONE )
673 return false; 685 return false;
674 GSM_Phone_Functions*Phone; 686 GSM_Phone_Functions*Phone;
675 GSM_CalendarEntrynote; 687 GSM_CalendarEntrynote;
676 bool start = true; 688 bool start = true;
677 Phone=s.Phone.Functions; 689 Phone=s.Phone.Functions;
678 bool gshutdown = false; 690 bool gshutdown = false;
679 PhoneParser handler( calendar, profileName ); 691 PhoneParser handler( calendar, profileName );
680 int ccc = 0; 692 int ccc = 0;
681 qDebug("Debug: only 10 calender items are downloaded "); 693 qDebug("Debug: only 10 calender items are downloaded ");
682 while (!gshutdown && ccc++ < 10) { 694 while (!gshutdown && ccc++ < 10) {
683 695
684 qDebug("readEvent %d ", ccc); 696 qDebug("readEvent %d ", ccc);
685 error=Phone->GetNextCalendar(&s,&note,start); 697 error=Phone->GetNextCalendar(&s,&note,start);
686 if (error == ERR_EMPTY) break; 698 if (error == ERR_EMPTY) break;
687 start = false; 699 start = false;
688 handler.readEvent( existingCal, &note ); 700 handler.readEvent( existingCal, &note );
689 } 701 }
690 702
691 start = true; 703 start = true;
692 GSM_ToDoEntry ToDo; 704 GSM_ToDoEntry ToDo;
693 ccc = 0; 705 ccc = 0;
694 while (!gshutdown) { 706 while (!gshutdown) {
695 error = Phone->GetNextToDo(&s, &ToDo, start); 707 error = Phone->GetNextToDo(&s, &ToDo, start);
696 if (error == ERR_EMPTY) break; 708 if (error == ERR_EMPTY) break;
697 start = false; 709 start = false;
698 qDebug("ReadTodo %d ", ++ccc); 710 qDebug("ReadTodo %d ", ++ccc);
699 handler.readTodo( existingCal, &ToDo, &s); 711 handler.readTodo( existingCal, &ToDo, &s);
700 712
701 } 713 }
702 714
703 error=GSM_TerminateConnection(&s); 715 error=GSM_TerminateConnection(&s);
704 716
705 return true; 717 return true;
706} 718}
707 719
708bool PhoneFormat::save( Calendar *calendar) 720bool PhoneFormat::save( Calendar *calendar)
709{ 721{
710#if 0 722#if 0
711 QLabel status ( i18n("Processing/adding events ..."), 0 ); 723 QLabel status ( i18n("Processing/adding events ..."), 0 );
712 int w = status.sizeHint().width()+20 ; 724 int w = status.sizeHint().width()+20 ;
713 if ( w < 200 ) w = 200; 725 if ( w < 200 ) w = 200;
714 int h = status.sizeHint().height()+20 ; 726 int h = status.sizeHint().height()+20 ;
715 int dw = QApplication::desktop()->width(); 727 int dw = QApplication::desktop()->width();
716 int dh = QApplication::desktop()->height(); 728 int dh = QApplication::desktop()->height();
717 status.setCaption(i18n("Writing DTM Data") ); 729 status.setCaption(i18n("Writing DTM Data") );
718 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 730 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
719 status.show(); 731 status.show();
720 status.raise(); 732 status.raise();
721 qApp->processEvents(); 733 qApp->processEvents();
722 bool debug = DEBUGMODE; 734 bool debug = DEBUGMODE;
723 QString codec = "utf8"; 735 QString codec = "utf8";
724 QString answer; 736 QString answer;
725 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 737 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
726 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 738 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
727 QString command; 739 QString command;
728 QPtrList<Event> er = calendar->rawEvents(); 740 QPtrList<Event> er = calendar->rawEvents();
729 Event* ev = er.first(); 741 Event* ev = er.first();
730 QString fileName = "/tmp/kopitempout"; 742 QString fileName = "/tmp/kopitempout";
731 int i = 0; 743 int i = 0;
732 QString changeString = ePrefix; 744 QString changeString = ePrefix;
733 QString deleteString = ePrefix; 745 QString deleteString = ePrefix;
734 bool deleteEnt = false; 746 bool deleteEnt = false;
735 bool changeEnt = false; 747 bool changeEnt = false;
736 QString message = i18n("Processing event # "); 748 QString message = i18n("Processing event # ");
737 int procCount = 0; 749 int procCount = 0;
738 while ( ev ) { 750 while ( ev ) {
739 //qDebug("i %d ", ++i); 751 //qDebug("i %d ", ++i);
740 if ( true /*ev->zaurusStat() != -2*/ ) { 752 if ( true /*ev->zaurusStat() != -2*/ ) {
741 status.setText ( message + QString::number ( ++procCount ) ); 753 status.setText ( message + QString::number ( ++procCount ) );
742 qApp->processEvents(); 754 qApp->processEvents();
743 QString eString = getEventString( ev ); 755 QString eString = getEventString( ev );
744 if (/* ev->zaurusStat() == -3 */ true) { // delete 756 if (/* ev->zaurusStat() == -3 */ true) { // delete
745 // deleting empty strings does not work. 757 // deleting empty strings does not work.
746 // we write first and x and then delete the record with the x 758 // we write first and x and then delete the record with the x
747 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 759 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
748 changeString += eString + "\n"; 760 changeString += eString + "\n";
749 deleteString += eString + "\n"; 761 deleteString += eString + "\n";
750 deleteEnt = true; 762 deleteEnt = true;
751 changeEnt = true; 763 changeEnt = true;
752 } 764 }
753 else if ( /*ev->zaurusId() == -1*/true ) { // add new 765 else if ( /*ev->zaurusId() == -1*/true ) { // add new
754 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 766 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
755 system ( command.utf8() ); 767 system ( command.utf8() );
756 QFile file( fileName ); 768 QFile file( fileName );
757 if (!file.open( IO_ReadOnly ) ) { 769 if (!file.open( IO_ReadOnly ) ) {
758 return false; 770 return false;
759 771
760 } 772 }
761 QTextStream ts( &file ); 773 QTextStream ts( &file );
762 ts.setCodec( QTextCodec::codecForName("utf8") ); 774 ts.setCodec( QTextCodec::codecForName("utf8") );
763 answer = ts.read(); 775 answer = ts.read();
764 file.close(); 776 file.close();
765 //qDebug("answer \n%s ", answer.latin1()); 777 //qDebug("answer \n%s ", answer.latin1());
766 getNumFromRecord( answer, ev ) ; 778 getNumFromRecord( answer, ev ) ;
767 779
768 } 780 }
769 else { // change existing 781 else { // change existing
770 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 782 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
771 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 783 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
772 changeString += eString + "\n"; 784 changeString += eString + "\n";
773 changeEnt = true; 785 changeEnt = true;
774 786
775 } 787 }
776 } 788 }
777 ev = er.next(); 789 ev = er.next();
778 } 790 }
779 status.setText ( i18n("Changing events ...") ); 791 status.setText ( i18n("Changing events ...") );
780 qApp->processEvents(); 792 qApp->processEvents();
781 //qDebug("changing... "); 793 //qDebug("changing... ");
782 if ( changeEnt ) { 794 if ( changeEnt ) {
783 QFile file( fileName ); 795 QFile file( fileName );
784 if (!file.open( IO_WriteOnly ) ) { 796 if (!file.open( IO_WriteOnly ) ) {
785 return false; 797 return false;
786 798
787 } 799 }
788 QTextStream ts( &file ); 800 QTextStream ts( &file );
789 ts.setCodec( QTextCodec::codecForName("utf8") ); 801 ts.setCodec( QTextCodec::codecForName("utf8") );
790 ts << changeString ; 802 ts << changeString ;
791 file.close(); 803 file.close();
792 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 804 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
793 system ( command.latin1() ); 805 system ( command.latin1() );
794 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 806 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
795 807
796 } 808 }
797 status.setText ( i18n("Deleting events ...") ); 809 status.setText ( i18n("Deleting events ...") );
798 qApp->processEvents(); 810 qApp->processEvents();
799 //qDebug("deleting... "); 811 //qDebug("deleting... ");
800 if ( deleteEnt ) { 812 if ( deleteEnt ) {
801 QFile file( fileName ); 813 QFile file( fileName );
802 if (!file.open( IO_WriteOnly ) ) { 814 if (!file.open( IO_WriteOnly ) ) {
803 return false; 815 return false;
804 816
805 } 817 }
806 QTextStream ts( &file ); 818 QTextStream ts( &file );
807 ts.setCodec( QTextCodec::codecForName("utf8") ); 819 ts.setCodec( QTextCodec::codecForName("utf8") );
808 ts << deleteString; 820 ts << deleteString;
809 file.close(); 821 file.close();
810 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 822 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
811 system ( command.latin1() ); 823 system ( command.latin1() );
812 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 824 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
813 } 825 }
814 826
815 827
816 changeString = tPrefix; 828 changeString = tPrefix;
817 deleteString = tPrefix; 829 deleteString = tPrefix;
818 status.setText ( i18n("Processing todos ...") ); 830 status.setText ( i18n("Processing todos ...") );
819 qApp->processEvents(); 831 qApp->processEvents();
820 QPtrList<Todo> tl = calendar->rawTodos(); 832 QPtrList<Todo> tl = calendar->rawTodos();
821 Todo* to = tl.first(); 833 Todo* to = tl.first();
822 i = 0; 834 i = 0;
823 message = i18n("Processing todo # "); 835 message = i18n("Processing todo # ");
824 procCount = 0; 836 procCount = 0;
825 while ( to ) { 837 while ( to ) {
826 if ( true /*to->zaurusStat() != -2 */) { 838 if ( true /*to->zaurusStat() != -2 */) {
827 status.setText ( message + QString::number ( ++procCount ) ); 839 status.setText ( message + QString::number ( ++procCount ) );
828 qApp->processEvents(); 840 qApp->processEvents();
829 QString eString = getTodoString( to ); 841 QString eString = getTodoString( to );
830 if ( /*to->zaurusStat() == -3*/true ) { // delete 842 if ( /*to->zaurusStat() == -3*/true ) { // delete
831 // deleting empty strings does not work. 843 // deleting empty strings does not work.
832 // we write first and x and then delete the record with the x 844 // we write first and x and then delete the record with the x
833 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 845 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
834 changeString += eString + "\n"; 846 changeString += eString + "\n";
835 deleteString += eString + "\n"; 847 deleteString += eString + "\n";
836 deleteEnt = true; 848 deleteEnt = true;
837 changeEnt = true; 849 changeEnt = true;
838 } 850 }
839 else if ( true /*to->zaurusId() == -1*/ ) { // add new 851 else if ( true /*to->zaurusId() == -1*/ ) { // add new
840 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 852 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
841 system ( command.utf8() ); 853 system ( command.utf8() );
842 QFile file( fileName ); 854 QFile file( fileName );
843 if (!file.open( IO_ReadOnly ) ) { 855 if (!file.open( IO_ReadOnly ) ) {
844 return false; 856 return false;
845 857
846 } 858 }
847 QTextStream ts( &file ); 859 QTextStream ts( &file );
848 ts.setCodec( QTextCodec::codecForName("utf8") ); 860 ts.setCodec( QTextCodec::codecForName("utf8") );
849 answer = ts.read(); 861 answer = ts.read();
850 file.close(); 862 file.close();
851 //qDebug("answer \n%s ", answer.latin1()); 863 //qDebug("answer \n%s ", answer.latin1());
852 getNumFromRecord( answer, to ) ; 864 getNumFromRecord( answer, to ) ;
853 865
854 } 866 }
855 else { // change existing 867 else { // change existing
856 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 868 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
857 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 869 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
858 changeString += eString + "\n"; 870 changeString += eString + "\n";
859 changeEnt = true; 871 changeEnt = true;
860 872
861 } 873 }
862 } 874 }
863 875
864 to = tl.next(); 876 to = tl.next();
865 } 877 }
866 status.setText ( i18n("Changing todos ...") ); 878 status.setText ( i18n("Changing todos ...") );
867 qApp->processEvents(); 879 qApp->processEvents();
868 //qDebug("changing... "); 880 //qDebug("changing... ");
869 if ( changeEnt ) { 881 if ( changeEnt ) {
870 QFile file( fileName ); 882 QFile file( fileName );
871 if (!file.open( IO_WriteOnly ) ) { 883 if (!file.open( IO_WriteOnly ) ) {
872 return false; 884 return false;
873 885
874 } 886 }
875 QTextStream ts( &file ); 887 QTextStream ts( &file );
876 ts.setCodec( QTextCodec::codecForName("utf8") ); 888 ts.setCodec( QTextCodec::codecForName("utf8") );
877 ts << changeString ; 889 ts << changeString ;
878 file.close(); 890 file.close();
879 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 891 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
880 system ( command.latin1() ); 892 system ( command.latin1() );
881 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 893 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
882 894
883 } 895 }
884 status.setText ( i18n("Deleting todos ...") ); 896 status.setText ( i18n("Deleting todos ...") );
885 qApp->processEvents(); 897 qApp->processEvents();
886 //qDebug("deleting... "); 898 //qDebug("deleting... ");
887 if ( deleteEnt ) { 899 if ( deleteEnt ) {
888 QFile file( fileName ); 900 QFile file( fileName );
889 if (!file.open( IO_WriteOnly ) ) { 901 if (!file.open( IO_WriteOnly ) ) {
890 return false; 902 return false;
891 903
892 } 904 }
893 QTextStream ts( &file ); 905 QTextStream ts( &file );
894 ts.setCodec( QTextCodec::codecForName("utf8") ); 906 ts.setCodec( QTextCodec::codecForName("utf8") );
895 ts << deleteString; 907 ts << deleteString;
896 file.close(); 908 file.close();
897 command = "db2file todo -d -c " + codec+ " < "+ fileName; 909 command = "db2file todo -d -c " + codec+ " < "+ fileName;
898 system ( command.latin1() ); 910 system ( command.latin1() );
899 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 911 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
900 } 912 }
901#endif 913#endif
902 return true; 914 return true;
903} 915}
904QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 916QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
905{ 917{
906 QString datestr; 918 QString datestr;
907 QString timestr; 919 QString timestr;
908 int offset = KGlobal::locale()->localTimeOffset( dti ); 920 int offset = KGlobal::locale()->localTimeOffset( dti );
909 QDateTime dt; 921 QDateTime dt;
910 if (useTZ) 922 if (useTZ)
911 dt = dti.addSecs ( -(offset*60)); 923 dt = dti.addSecs ( -(offset*60));
912 else 924 else
913 dt = dti; 925 dt = dti;
914 if(dt.date().isValid()){ 926 if(dt.date().isValid()){
915 const QDate& date = dt.date(); 927 const QDate& date = dt.date();
916 datestr.sprintf("%04d%02d%02d", 928 datestr.sprintf("%04d%02d%02d",
917 date.year(), date.month(), date.day()); 929 date.year(), date.month(), date.day());
918 } 930 }
919 if(dt.time().isValid()){ 931 if(dt.time().isValid()){
920 const QTime& time = dt.time(); 932 const QTime& time = dt.time();
921 timestr.sprintf("T%02d%02d%02d", 933 timestr.sprintf("T%02d%02d%02d",
922 time.hour(), time.minute(), time.second()); 934 time.hour(), time.minute(), time.second());
923 } 935 }
924 return datestr + timestr; 936 return datestr + timestr;
925} 937}
926QString PhoneFormat::getEventString( Event* event ) 938QString PhoneFormat::getEventString( Event* event )
927{ 939{
928#if 0 940#if 0
929 QStringList list; 941 QStringList list;
930 list.append( QString::number(event->zaurusId() ) ); 942 list.append( QString::number(event->zaurusId() ) );
931 list.append( event->categories().join(",") ); 943 list.append( event->categories().join(",") );
932 if ( !event->summary().isEmpty() ) 944 if ( !event->summary().isEmpty() )
933 list.append( event->summary() ); 945 list.append( event->summary() );
934 else 946 else
935 list.append("" ); 947 list.append("" );
936 if ( !event->location().isEmpty() ) 948 if ( !event->location().isEmpty() )
937 list.append( event->location() ); 949 list.append( event->location() );
938 else 950 else
939 list.append("" ); 951 list.append("" );
940 if ( !event->description().isEmpty() ) 952 if ( !event->description().isEmpty() )
941 list.append( event->description() ); 953 list.append( event->description() );
942 else 954 else
943 list.append( "" ); 955 list.append( "" );
944 if ( event->doesFloat () ) { 956 if ( event->doesFloat () ) {
945 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 957 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
946 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 958 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
947 list.append( "1" ); 959 list.append( "1" );
948 960
949 } 961 }
950 else { 962 else {
951 list.append( dtToString( event->dtStart()) ); 963 list.append( dtToString( event->dtStart()) );
952 list.append( dtToString( event->dtEnd()) ); //6 964 list.append( dtToString( event->dtEnd()) ); //6
953 list.append( "0" ); 965 list.append( "0" );
954 } 966 }
955 bool noAlarm = true; 967 bool noAlarm = true;
956 if ( event->alarms().count() > 0 ) { 968 if ( event->alarms().count() > 0 ) {
957 Alarm * al = event->alarms().first(); 969 Alarm * al = event->alarms().first();
958 if ( al->enabled() ) { 970 if ( al->enabled() ) {
959 noAlarm = false; 971 noAlarm = false;
960 list.append( "0" ); // yes, 0 == alarm 972 list.append( "0" ); // yes, 0 == alarm
961 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 973 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
962 if ( al->type() == Alarm::Audio ) 974 if ( al->type() == Alarm::Audio )
963 list.append( "1" ); // type audio 975 list.append( "1" ); // type audio
964 else 976 else
965 list.append( "0" ); // type silent 977 list.append( "0" ); // type silent
966 } 978 }
967 } 979 }
968 if ( noAlarm ) { 980 if ( noAlarm ) {
969 list.append( "1" ); // yes, 1 == no alarm 981 list.append( "1" ); // yes, 1 == no alarm
970 list.append( "0" ); // no alarm offset 982 list.append( "0" ); // no alarm offset
971 list.append( "1" ); // type 983 list.append( "1" ); // type
972 } 984 }
973 // next is: 11 985 // next is: 11
974 // next is: 11-16 are recurrence 986 // next is: 11-16 are recurrence
975 Recurrence* rec = event->recurrence(); 987 Recurrence* rec = event->recurrence();
976 988
977 bool writeEndDate = false; 989 bool writeEndDate = false;
978 switch ( rec->doesRecur() ) 990 switch ( rec->doesRecur() )
979 { 991 {
980 case Recurrence::rDaily: // 0 992 case Recurrence::rDaily: // 0
981 list.append( "0" ); 993 list.append( "0" );
982 list.append( QString::number( rec->frequency() ));//12 994 list.append( QString::number( rec->frequency() ));//12
983 list.append( "0" ); 995 list.append( "0" );
984 list.append( "0" ); 996 list.append( "0" );
985 writeEndDate = true; 997 writeEndDate = true;
986 break; 998 break;
987 case Recurrence::rWeekly:// 1 999 case Recurrence::rWeekly:// 1
988 list.append( "1" ); 1000 list.append( "1" );
989 list.append( QString::number( rec->frequency()) );//12 1001 list.append( QString::number( rec->frequency()) );//12
990 list.append( "0" ); 1002 list.append( "0" );
991 { 1003 {
992 int days = 0; 1004 int days = 0;
993 QBitArray weekDays = rec->days(); 1005 QBitArray weekDays = rec->days();
994 int i; 1006 int i;
995 for( i = 1; i <= 7; ++i ) { 1007 for( i = 1; i <= 7; ++i ) {
996 if ( weekDays[i-1] ) { 1008 if ( weekDays[i-1] ) {
997 days += 1 << (i-1); 1009 days += 1 << (i-1);
998 } 1010 }
999 } 1011 }
1000 list.append( QString::number( days ) ); 1012 list.append( QString::number( days ) );
1001 } 1013 }
1002 //pending weekdays 1014 //pending weekdays
1003 writeEndDate = true; 1015 writeEndDate = true;
1004 1016
1005 break; 1017 break;
1006 case Recurrence::rMonthlyPos:// 2 1018 case Recurrence::rMonthlyPos:// 2
1007 list.append( "2" ); 1019 list.append( "2" );
1008 list.append( QString::number( rec->frequency()) );//12 1020 list.append( QString::number( rec->frequency()) );//12
1009 1021
1010 writeEndDate = true; 1022 writeEndDate = true;
1011 { 1023 {
1012 int count = 1; 1024 int count = 1;
1013 QPtrList<Recurrence::rMonthPos> rmp; 1025 QPtrList<Recurrence::rMonthPos> rmp;
1014 rmp = rec->monthPositions(); 1026 rmp = rec->monthPositions();
1015 if ( rmp.first()->negative ) 1027 if ( rmp.first()->negative )
1016 count = 5 - rmp.first()->rPos - 1; 1028 count = 5 - rmp.first()->rPos - 1;
1017 else 1029 else
1018 count = rmp.first()->rPos - 1; 1030 count = rmp.first()->rPos - 1;
1019 list.append( QString::number( count ) ); 1031 list.append( QString::number( count ) );
1020 1032
1021 } 1033 }
1022 1034
1023 list.append( "0" ); 1035 list.append( "0" );
1024 break; 1036 break;
1025 case Recurrence::rMonthlyDay:// 3 1037 case Recurrence::rMonthlyDay:// 3
1026 list.append( "3" ); 1038 list.append( "3" );
1027 list.append( QString::number( rec->frequency()) );//12 1039 list.append( QString::number( rec->frequency()) );//12
1028 list.append( "0" ); 1040 list.append( "0" );
1029 list.append( "0" ); 1041 list.append( "0" );
1030 writeEndDate = true; 1042 writeEndDate = true;
1031 break; 1043 break;
1032 case Recurrence::rYearlyMonth://4 1044 case Recurrence::rYearlyMonth://4
1033 list.append( "4" ); 1045 list.append( "4" );
1034 list.append( QString::number( rec->frequency()) );//12 1046 list.append( QString::number( rec->frequency()) );//12
1035 list.append( "0" ); 1047 list.append( "0" );
1036 list.append( "0" ); 1048 list.append( "0" );
1037 writeEndDate = true; 1049 writeEndDate = true;
1038 break; 1050 break;
1039 1051
1040 default: 1052 default:
1041 list.append( "255" ); 1053 list.append( "255" );
1042 list.append( QString() ); 1054 list.append( QString() );
1043 list.append( "0" ); 1055 list.append( "0" );
1044 list.append( QString() ); 1056 list.append( QString() );
1045 list.append( "0" ); 1057 list.append( "0" );
1046 list.append( "20991231T000000" ); 1058 list.append( "20991231T000000" );
1047 break; 1059 break;
1048 } 1060 }
1049 if ( writeEndDate ) { 1061 if ( writeEndDate ) {
1050 1062
1051 if ( rec->endDate().isValid() ) { // 15 + 16 1063 if ( rec->endDate().isValid() ) { // 15 + 16
1052 list.append( "1" ); 1064 list.append( "1" );
1053 list.append( dtToString( rec->endDate()) ); 1065 list.append( dtToString( rec->endDate()) );
1054 } else { 1066 } else {
1055 list.append( "0" ); 1067 list.append( "0" );
1056 list.append( "20991231T000000" ); 1068 list.append( "20991231T000000" );
1057 } 1069 }
1058 1070
1059 } 1071 }
1060 if ( event->doesFloat () ) { 1072 if ( event->doesFloat () ) {
1061 list.append( dtToString( event->dtStart(), false ).left( 8 )); 1073 list.append( dtToString( event->dtStart(), false ).left( 8 ));
1062 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 1074 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
1063 1075
1064 } 1076 }
1065 else { 1077 else {
1066 list.append( QString() ); 1078 list.append( QString() );
1067 list.append( QString() ); 1079 list.append( QString() );
1068 1080
1069 } 1081 }
1070 if (event->dtStart().date() == event->dtEnd().date() ) 1082 if (event->dtStart().date() == event->dtEnd().date() )
1071 list.append( "0" ); 1083 list.append( "0" );
1072 else 1084 else
1073 list.append( "1" ); 1085 list.append( "1" );
1074 1086
1075 1087
1076 for(QStringList::Iterator it=list.begin(); 1088 for(QStringList::Iterator it=list.begin();
1077 it!=list.end(); ++it){ 1089 it!=list.end(); ++it){
1078 QString& s = (*it); 1090 QString& s = (*it);
1079 s.replace(QRegExp("\""), "\"\""); 1091 s.replace(QRegExp("\""), "\"\"");
1080 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1092 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1081 s.prepend('\"'); 1093 s.prepend('\"');
1082 s.append('\"'); 1094 s.append('\"');
1083 } else if(s.isEmpty() && !s.isNull()){ 1095 } else if(s.isEmpty() && !s.isNull()){
1084 s = "\"\""; 1096 s = "\"\"";
1085 } 1097 }
1086 } 1098 }
1087 return list.join(","); 1099 return list.join(",");
1088#endif 1100#endif
1089 return QString(); 1101 return QString();
1090 1102
1091} 1103}
1092QString PhoneFormat::getTodoString( Todo* todo ) 1104QString PhoneFormat::getTodoString( Todo* todo )
1093{ 1105{
1094#if 0 1106#if 0
1095 QStringList list; 1107 QStringList list;
1096 list.append( QString::number( todo->zaurusId() ) ); 1108 list.append( QString::number( todo->zaurusId() ) );
1097 list.append( todo->categories().join(",") ); 1109 list.append( todo->categories().join(",") );
1098 1110
1099 if ( todo->hasStartDate() ) { 1111 if ( todo->hasStartDate() ) {
1100 list.append( dtToString( todo->dtStart()) ); 1112 list.append( dtToString( todo->dtStart()) );
1101 } else 1113 } else
1102 list.append( QString() ); 1114 list.append( QString() );
1103 1115
1104 if ( todo->hasDueDate() ) { 1116 if ( todo->hasDueDate() ) {
1105 QTime tim; 1117 QTime tim;
1106 if ( todo->doesFloat()) { 1118 if ( todo->doesFloat()) {
1107 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 1119 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
1108 } else { 1120 } else {
1109 list.append( dtToString(todo->dtDue() ) ); 1121 list.append( dtToString(todo->dtDue() ) );
1110 } 1122 }
1111 } else 1123 } else
1112 list.append( QString() ); 1124 list.append( QString() );
1113 1125
1114 if ( todo->isCompleted() ) { 1126 if ( todo->isCompleted() ) {
1115 list.append( dtToString( todo->completed()) ); 1127 list.append( dtToString( todo->completed()) );
1116 list.append( "0" ); // yes 0 == completed 1128 list.append( "0" ); // yes 0 == completed
1117 } else { 1129 } else {
1118 list.append( dtToString( todo->completed()) ); 1130 list.append( dtToString( todo->completed()) );
1119 list.append( "1" ); 1131 list.append( "1" );
1120 } 1132 }
1121 list.append( QString::number( todo->priority() )); 1133 list.append( QString::number( todo->priority() ));
1122 if( ! todo->summary().isEmpty() ) 1134 if( ! todo->summary().isEmpty() )
1123 list.append( todo->summary() ); 1135 list.append( todo->summary() );
1124 else 1136 else
1125 list.append( "" ); 1137 list.append( "" );
1126 if (! todo->description().isEmpty() ) 1138 if (! todo->description().isEmpty() )
1127 list.append( todo->description() ); 1139 list.append( todo->description() );
1128 else 1140 else
1129 list.append( "" ); 1141 list.append( "" );
1130 for(QStringList::Iterator it=list.begin(); 1142 for(QStringList::Iterator it=list.begin();
1131 it!=list.end(); ++it){ 1143 it!=list.end(); ++it){
1132 QString& s = (*it); 1144 QString& s = (*it);
1133 s.replace(QRegExp("\""), "\"\""); 1145 s.replace(QRegExp("\""), "\"\"");
1134 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1146 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1135 s.prepend('\"'); 1147 s.prepend('\"');
1136 s.append('\"'); 1148 s.append('\"');
1137 } else if(s.isEmpty() && !s.isNull()){ 1149 } else if(s.isEmpty() && !s.isNull()){
1138 s = "\"\""; 1150 s = "\"\"";
1139 } 1151 }
1140 } 1152 }
1141 return list.join(","); 1153 return list.join(",");
1142#endif 1154#endif
1143 return QString(); 1155 return QString();
1144} 1156}
1145 1157
1146 1158
1147QString PhoneFormat::toString( Calendar * ) 1159QString PhoneFormat::toString( Calendar * )
1148{ 1160{
1149 return QString::null; 1161 return QString::null;
1150} 1162}
1151bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 1163bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
1152{ 1164{
1153 return false; 1165 return false;
1154} 1166}
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 4e54fdf..f8b066d 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,1008 +1,1016 @@
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 {
169 event->recurrence()->unsetRecurs();
168 } 170 }
169 171
170 QString categoryList = attList[1] ; 172 QString categoryList = attList[1] ;
171 event->setCategories( lookupCategories( categoryList ) ); 173 event->setCategories( lookupCategories( categoryList ) );
172 174
173 // strange 0 semms to mean: alarm enabled 175 // strange 0 semms to mean: alarm enabled
174 if ( attList[8] == "0" ) { 176 if ( attList[8] == "0" ) {
175 Alarm *alarm; 177 Alarm *alarm;
176 if ( event->alarms().count() > 0 ) 178 if ( event->alarms().count() > 0 )
177 alarm = event->alarms().first(); 179 alarm = event->alarms().first();
178 else { 180 else {
179 alarm = new Alarm( event ); 181 alarm = new Alarm( event );
180 event->addAlarm( alarm ); 182 event->addAlarm( alarm );
181 } 183 }
182 alarm->setType( Alarm::Audio ); 184 alarm->setType( Alarm::Audio );
183 alarm->setEnabled( true ); 185 alarm->setEnabled( true );
184 int alarmOffset = attList[9].toInt(); 186 int alarmOffset = attList[9].toInt();
185 alarm->setStartOffset( alarmOffset * -60 ); 187 alarm->setStartOffset( alarmOffset * -60 );
188 } else {
189 Alarm *alarm;
190 if ( event->alarms().count() > 0 ) {
191 alarm = event->alarms().first();
192 alarm->setEnabled( false );
193 }
186 } 194 }
187 195
188 mCalendar->addEvent( event); 196 mCalendar->addEvent( event);
189 } else if ( qName == "Todo" ) { 197 } else if ( qName == "Todo" ) {
190 Todo *todo; 198 Todo *todo;
191 199
192 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 200 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
193 if (todo ) 201 if (todo )
194 todo = (Todo*)todo->clone(); 202 todo = (Todo*)todo->clone();
195 else 203 else
196 todo = new Todo; 204 todo = new Todo;
197 205
198//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 206//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
199// 0 1 2 3 4 5 6 7 8 207// 0 1 2 3 4 5 6 7 8
200//1,,,,,1,4,Loch zumachen,"" 208//1,,,,,1,4,Loch zumachen,""
201//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 209//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
202//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 210//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
203 211
204 todo->setID( "Sharp_DTM", attList[0]); 212 todo->setID( "Sharp_DTM", attList[0]);
205 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 213 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
206 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 214 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
207 215
208 todo->setSummary( attList[7] ); 216 todo->setSummary( attList[7] );
209 todo->setDescription( attList[8]); 217 todo->setDescription( attList[8]);
210 218
211 int priority = attList[6].toInt(); 219 int priority = attList[6].toInt();
212 if ( priority == 0 ) priority = 3; 220 if ( priority == 0 ) priority = 3;
213 todo->setPriority( priority ); 221 todo->setPriority( priority );
214 222
215 QString categoryList = attList[1]; 223 QString categoryList = attList[1];
216 todo->setCategories( lookupCategories( categoryList ) ); 224 todo->setCategories( lookupCategories( categoryList ) );
217 225
218 226
219 227
220 QString hasDateStr = attList[3]; // due 228 QString hasDateStr = attList[3]; // due
221 if ( !hasDateStr.isEmpty() ) { 229 if ( !hasDateStr.isEmpty() ) {
222 if ( hasDateStr.right(6) == "000000" ) { 230 if ( hasDateStr.right(6) == "000000" ) {
223 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 231 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
224 todo->setFloats( true ); 232 todo->setFloats( true );
225 } 233 }
226 else { 234 else {
227 todo->setDtDue( fromString( hasDateStr ) ); 235 todo->setDtDue( fromString( hasDateStr ) );
228 todo->setFloats( false ); 236 todo->setFloats( false );
229 } 237 }
230 238
231 todo->setHasDueDate( true ); 239 todo->setHasDueDate( true );
232 } 240 }
233 hasDateStr = attList[2];//start 241 hasDateStr = attList[2];//start
234 if ( !hasDateStr.isEmpty() ) { 242 if ( !hasDateStr.isEmpty() ) {
235 243
236 todo->setDtStart( fromString( hasDateStr ) ); 244 todo->setDtStart( fromString( hasDateStr ) );
237 todo->setHasStartDate( true); 245 todo->setHasStartDate( true);
238 } else 246 } else
239 todo->setHasStartDate( false ); 247 todo->setHasStartDate( false );
240 hasDateStr = attList[4];//completed 248 hasDateStr = attList[4];//completed
241 if ( !hasDateStr.isEmpty() ) { 249 if ( !hasDateStr.isEmpty() ) {
242 todo->setCompleted(fromString( hasDateStr ) ); 250 todo->setCompleted(fromString( hasDateStr ) );
243 } 251 }
244 QString completedStr = attList[5]; 252 QString completedStr = attList[5];
245 if ( completedStr == "0" ) 253 if ( completedStr == "0" )
246 todo->setCompleted( true ); 254 todo->setCompleted( true );
247 else 255 else
248 todo->setCompleted( false ); 256 todo->setCompleted( false );
249 mCalendar->addTodo( todo ); 257 mCalendar->addTodo( todo );
250 258
251 } else if ( qName == "Category" ) { 259 } else if ( qName == "Category" ) {
252 /* 260 /*
253 QString id = attributes.value( "id" ); 261 QString id = attributes.value( "id" );
254 QString name = attributes.value( "name" ); 262 QString name = attributes.value( "name" );
255 setCategory( id, name ); 263 setCategory( id, name );
256 */ 264 */
257 } 265 }
258 //qDebug("end "); 266 //qDebug("end ");
259 return true; 267 return true;
260 } 268 }
261 269
262 270
263 void setCategoriesList ( QStringList * c ) 271 void setCategoriesList ( QStringList * c )
264 { 272 {
265 oldCategories = c; 273 oldCategories = c;
266 } 274 }
267 275
268 QDateTime fromString ( QString s, bool useTz = true ) { 276 QDateTime fromString ( QString s, bool useTz = true ) {
269 QDateTime dt; 277 QDateTime dt;
270 int y,m,t,h,min,sec; 278 int y,m,t,h,min,sec;
271 y = s.mid(0,4).toInt(); 279 y = s.mid(0,4).toInt();
272 m = s.mid(4,2).toInt(); 280 m = s.mid(4,2).toInt();
273 t = s.mid(6,2).toInt(); 281 t = s.mid(6,2).toInt();
274 h = s.mid(9,2).toInt(); 282 h = s.mid(9,2).toInt();
275 min = s.mid(11,2).toInt(); 283 min = s.mid(11,2).toInt();
276 sec = s.mid(13,2).toInt(); 284 sec = s.mid(13,2).toInt();
277 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 285 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
278 int offset = KGlobal::locale()->localTimeOffset( dt ); 286 int offset = KGlobal::locale()->localTimeOffset( dt );
279 if ( useTz ) 287 if ( useTz )
280 dt = dt.addSecs ( offset*60); 288 dt = dt.addSecs ( offset*60);
281 return dt; 289 return dt;
282 290
283 } 291 }
284 protected: 292 protected:
285 QDateTime toDateTime( const QString &value ) 293 QDateTime toDateTime( const QString &value )
286 { 294 {
287 QDateTime dt; 295 QDateTime dt;
288 dt.setTime_t( value.toUInt() ); 296 dt.setTime_t( value.toUInt() );
289 297
290 return dt; 298 return dt;
291 } 299 }
292 300
293 QStringList lookupCategories( const QString &categoryList ) 301 QStringList lookupCategories( const QString &categoryList )
294 { 302 {
295 QStringList categoryIds = QStringList::split( ";", categoryList ); 303 QStringList categoryIds = QStringList::split( ";", categoryList );
296 QStringList categories; 304 QStringList categories;
297 QStringList::ConstIterator it; 305 QStringList::ConstIterator it;
298 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 306 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
299 QString cate = category( *it ); 307 QString cate = category( *it );
300 if ( oldCategories ) { 308 if ( oldCategories ) {
301 if ( ! oldCategories->contains( cate ) ) 309 if ( ! oldCategories->contains( cate ) )
302 oldCategories->append( cate ); 310 oldCategories->append( cate );
303 } 311 }
304 categories.append(cate ); 312 categories.append(cate );
305 } 313 }
306 return categories; 314 return categories;
307 } 315 }
308 316
309 private: 317 private:
310 Calendar *mCalendar; 318 Calendar *mCalendar;
311 QStringList * oldCategories; 319 QStringList * oldCategories;
312 static QString category( const QString &id ) 320 static QString category( const QString &id )
313 { 321 {
314 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 322 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
315 if ( it == mCategoriesMap.end() ) return id; 323 if ( it == mCategoriesMap.end() ) return id;
316 else return *it; 324 else return *it;
317 } 325 }
318 326
319 static void setCategory( const QString &id, const QString &name ) 327 static void setCategory( const QString &id, const QString &name )
320 { 328 {
321 mCategoriesMap.insert( id, name ); 329 mCategoriesMap.insert( id, name );
322 } 330 }
323 331
324 static QMap<QString,QString> mCategoriesMap; 332 static QMap<QString,QString> mCategoriesMap;
325}; 333};
326 334
327QMap<QString,QString> SharpParser::mCategoriesMap; 335QMap<QString,QString> SharpParser::mCategoriesMap;
328 336
329SharpFormat::SharpFormat() 337SharpFormat::SharpFormat()
330{ 338{
331 mCategories = 0; 339 mCategories = 0;
332} 340}
333 341
334SharpFormat::~SharpFormat() 342SharpFormat::~SharpFormat()
335{ 343{
336} 344}
337ulong SharpFormat::getCsum( const QStringList & attList) 345ulong SharpFormat::getCsum( const QStringList & attList)
338{ 346{
339 int max = attList.count() -1; 347 int max = attList.count() -1;
340 ulong cSum = 0; 348 ulong cSum = 0;
341 int j,k,i; 349 int j,k,i;
342 int add; 350 int add;
343 for ( i = 1; i < max ; ++i ) { 351 for ( i = 1; i < max ; ++i ) {
344 QString s = attList[i]; 352 QString s = attList[i];
345 if ( ! s.isEmpty() ){ 353 if ( ! s.isEmpty() ){
346 j = s.length(); 354 j = s.length();
347 for ( k = 0; k < j; ++k ) { 355 for ( k = 0; k < j; ++k ) {
348 int mul = k +1; 356 int mul = k +1;
349 add = s[k].unicode (); 357 add = s[k].unicode ();
350 if ( k < 16 ) 358 if ( k < 16 )
351 mul = mul * mul; 359 mul = mul * mul;
352 add = add * mul *i*i*i; 360 add = add * mul *i*i*i;
353 cSum += add; 361 cSum += add;
354 } 362 }
355 } 363 }
356 } 364 }
357 return cSum; 365 return cSum;
358 366
359} 367}
360#include <stdlib.h> 368#include <stdlib.h>
361#define DEBUGMODE false 369#define DEBUGMODE false
362bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 370bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
363{ 371{
364 372
365 373
366 bool debug = DEBUGMODE; 374 bool debug = DEBUGMODE;
367 //debug = true; 375 //debug = true;
368 QString text; 376 QString text;
369 QString codec = "utf8"; 377 QString codec = "utf8";
370 QLabel status ( i18n("Reading events ..."), 0 ); 378 QLabel status ( i18n("Reading events ..."), 0 );
371 379
372 int w = status.sizeHint().width()+20 ; 380 int w = status.sizeHint().width()+20 ;
373 if ( w < 200 ) w = 200; 381 if ( w < 200 ) w = 200;
374 int h = status.sizeHint().height()+20 ; 382 int h = status.sizeHint().height()+20 ;
375 int dw = QApplication::desktop()->width(); 383 int dw = QApplication::desktop()->width();
376 int dh = QApplication::desktop()->height(); 384 int dh = QApplication::desktop()->height();
377 status.setCaption(i18n("Reading DTM Data") ); 385 status.setCaption(i18n("Reading DTM Data") );
378 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 386 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
379 status.show(); 387 status.show();
380 status.raise(); 388 status.raise();
381 qApp->processEvents(); 389 qApp->processEvents();
382 QString fileName; 390 QString fileName;
383 if ( ! debug ) { 391 if ( ! debug ) {
384 fileName = "/tmp/kopitempout"; 392 fileName = "/tmp/kopitempout";
385 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 393 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
386 system ( command.latin1() ); 394 system ( command.latin1() );
387 } else { 395 } else {
388 fileName = "/tmp/events.txt"; 396 fileName = "/tmp/events.txt";
389 397
390 } 398 }
391 QFile file( fileName ); 399 QFile file( fileName );
392 if (!file.open( IO_ReadOnly ) ) { 400 if (!file.open( IO_ReadOnly ) ) {
393 return false; 401 return false;
394 402
395 } 403 }
396 QTextStream ts( &file ); 404 QTextStream ts( &file );
397 ts.setCodec( QTextCodec::codecForName("utf8") ); 405 ts.setCodec( QTextCodec::codecForName("utf8") );
398 text = ts.read(); 406 text = ts.read();
399 file.close(); 407 file.close();
400 status.setText( i18n("Processing events ...") ); 408 status.setText( i18n("Processing events ...") );
401 status.raise(); 409 status.raise();
402 qApp->processEvents(); 410 qApp->processEvents();
403 fromString2Cal( calendar, existngCal, text, "Event" ); 411 fromString2Cal( calendar, existngCal, text, "Event" );
404 status.setText( i18n("Reading todos ...") ); 412 status.setText( i18n("Reading todos ...") );
405 qApp->processEvents(); 413 qApp->processEvents();
406 if ( ! debug ) { 414 if ( ! debug ) {
407 fileName = "/tmp/kopitempout"; 415 fileName = "/tmp/kopitempout";
408 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 416 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
409 system ( command.latin1() ); 417 system ( command.latin1() );
410 } else { 418 } else {
411 fileName = "/tmp/todo.txt"; 419 fileName = "/tmp/todo.txt";
412 } 420 }
413 file.setName( fileName ); 421 file.setName( fileName );
414 if (!file.open( IO_ReadOnly ) ) { 422 if (!file.open( IO_ReadOnly ) ) {
415 return false; 423 return false;
416 424
417 } 425 }
418 ts.setDevice( &file ); 426 ts.setDevice( &file );
419 text = ts.read(); 427 text = ts.read();
420 file.close(); 428 file.close();
421 429
422 status.setText( i18n("Processing todos ...") ); 430 status.setText( i18n("Processing todos ...") );
423 status.raise(); 431 status.raise();
424 qApp->processEvents(); 432 qApp->processEvents();
425 fromString2Cal( calendar, existngCal, text, "Todo" ); 433 fromString2Cal( calendar, existngCal, text, "Todo" );
426 return true; 434 return true;
427} 435}
428int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 436int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
429{ 437{
430 int retval = -1; 438 int retval = -1;
431 QStringList templist; 439 QStringList templist;
432 QString tempString; 440 QString tempString;
433 int start = 0; 441 int start = 0;
434 int len = answer.length(); 442 int len = answer.length();
435 int end = answer.find ("\n",start)+1; 443 int end = answer.find ("\n",start)+1;
436 bool ok = true; 444 bool ok = true;
437 start = end; 445 start = end;
438 int ccc = 0; 446 int ccc = 0;
439 while ( start > 0 ) { 447 while ( start > 0 ) {
440 templist.clear(); 448 templist.clear();
441 ok = true; 449 ok = true;
442 int loopCount = 0; 450 int loopCount = 0;
443 while ( ok ) { 451 while ( ok ) {
444 ++loopCount; 452 ++loopCount;
445 if ( loopCount > 25 ) { 453 if ( loopCount > 25 ) {
446 qDebug("KO: Error in while loop"); 454 qDebug("KO: Error in while loop");
447 ok = false; 455 ok = false;
448 start = 0; 456 start = 0;
449 break; 457 break;
450 } 458 }
451 if ( ok ) 459 if ( ok )
452 tempString = getPart( answer, ok, start ); 460 tempString = getPart( answer, ok, start );
453 if ( start >= len || start == 0 ) { 461 if ( start >= len || start == 0 ) {
454 start = 0; 462 start = 0;
455 ok = false; 463 ok = false;
456 } 464 }
457 if ( tempString.right(1) =="\n" ) 465 if ( tempString.right(1) =="\n" )
458 tempString = tempString.left( tempString.length()-1); 466 tempString = tempString.left( tempString.length()-1);
459 467
460 templist.append( tempString ); 468 templist.append( tempString );
461 } 469 }
462 ++ccc; 470 ++ccc;
463 if ( ccc == 2 && loopCount < 25 ) { 471 if ( ccc == 2 && loopCount < 25 ) {
464 start = 0; 472 start = 0;
465 bool ok; 473 bool ok;
466 int newnum = templist[0].toInt( &ok ); 474 int newnum = templist[0].toInt( &ok );
467 if ( ok && newnum > 0) { 475 if ( ok && newnum > 0) {
468 retval = newnum; 476 retval = newnum;
469 inc->setID( "Sharp_DTM",templist[0] ); 477 inc->setID( "Sharp_DTM",templist[0] );
470 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 478 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
471 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 479 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
472 } 480 }
473 } 481 }
474 } 482 }
475 //qDebug("getNumFromRecord returning : %d ", retval); 483 //qDebug("getNumFromRecord returning : %d ", retval);
476 return retval; 484 return retval;
477} 485}
478bool SharpFormat::save( Calendar *calendar) 486bool SharpFormat::save( Calendar *calendar)
479{ 487{
480 488
481 QLabel status ( i18n("Processing/adding events ..."), 0 ); 489 QLabel status ( i18n("Processing/adding events ..."), 0 );
482 int w = status.sizeHint().width()+20 ; 490 int w = status.sizeHint().width()+20 ;
483 if ( w < 200 ) w = 200; 491 if ( w < 200 ) w = 200;
484 int h = status.sizeHint().height()+20 ; 492 int h = status.sizeHint().height()+20 ;
485 int dw = QApplication::desktop()->width(); 493 int dw = QApplication::desktop()->width();
486 int dh = QApplication::desktop()->height(); 494 int dh = QApplication::desktop()->height();
487 status.setCaption(i18n("Writing DTM Data") ); 495 status.setCaption(i18n("Writing DTM Data") );
488 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 496 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
489 status.show(); 497 status.show();
490 status.raise(); 498 status.raise();
491 qApp->processEvents(); 499 qApp->processEvents();
492 bool debug = DEBUGMODE; 500 bool debug = DEBUGMODE;
493 QString codec = "utf8"; 501 QString codec = "utf8";
494 QString answer; 502 QString answer;
495 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 503 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
496 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 504 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
497 QString command; 505 QString command;
498 QPtrList<Event> er = calendar->rawEvents(); 506 QPtrList<Event> er = calendar->rawEvents();
499 Event* ev = er.first(); 507 Event* ev = er.first();
500 QString fileName = "/tmp/kopitempout"; 508 QString fileName = "/tmp/kopitempout";
501 int i = 0; 509 int i = 0;
502 QString changeString = ePrefix; 510 QString changeString = ePrefix;
503 QString deleteString = ePrefix; 511 QString deleteString = ePrefix;
504 bool deleteEnt = false; 512 bool deleteEnt = false;
505 bool changeEnt = false; 513 bool changeEnt = false;
506 QString message = i18n("Processing event # "); 514 QString message = i18n("Processing event # ");
507 int procCount = 0; 515 int procCount = 0;
508 while ( ev ) { 516 while ( ev ) {
509 //qDebug("i %d ", ++i); 517 //qDebug("i %d ", ++i);
510 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 518 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
511 status.setText ( message + QString::number ( ++procCount ) ); 519 status.setText ( message + QString::number ( ++procCount ) );
512 qApp->processEvents(); 520 qApp->processEvents();
513 QString eString = getEventString( ev ); 521 QString eString = getEventString( ev );
514 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 522 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
515 // deleting empty strings does not work. 523 // deleting empty strings does not work.
516 // we write first and x and then delete the record with the x 524 // we write first and x and then delete the record with the x
517 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 525 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
518 changeString += eString + "\n"; 526 changeString += eString + "\n";
519 deleteString += eString + "\n"; 527 deleteString += eString + "\n";
520 deleteEnt = true; 528 deleteEnt = true;
521 changeEnt = true; 529 changeEnt = true;
522 } 530 }
523 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 531 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
524 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 532 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
525 system ( command.utf8() ); 533 system ( command.utf8() );
526 QFile file( fileName ); 534 QFile file( fileName );
527 if (!file.open( IO_ReadOnly ) ) { 535 if (!file.open( IO_ReadOnly ) ) {
528 return false; 536 return false;
529 537
530 } 538 }
531 QTextStream ts( &file ); 539 QTextStream ts( &file );
532 ts.setCodec( QTextCodec::codecForName("utf8") ); 540 ts.setCodec( QTextCodec::codecForName("utf8") );
533 answer = ts.read(); 541 answer = ts.read();
534 file.close(); 542 file.close();
535 //qDebug("answer \n%s ", answer.latin1()); 543 //qDebug("answer \n%s ", answer.latin1());
536 getNumFromRecord( answer, ev ) ; 544 getNumFromRecord( answer, ev ) ;
537 545
538 } 546 }
539 else { // change existing 547 else { // change existing
540 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 548 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
541 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 549 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
542 changeString += eString + "\n"; 550 changeString += eString + "\n";
543 changeEnt = true; 551 changeEnt = true;
544 552
545 } 553 }
546 } 554 }
547 ev = er.next(); 555 ev = er.next();
548 } 556 }
549 status.setText ( i18n("Changing events ...") ); 557 status.setText ( i18n("Changing events ...") );
550 qApp->processEvents(); 558 qApp->processEvents();
551 //qDebug("changing... "); 559 //qDebug("changing... ");
552 if ( changeEnt ) { 560 if ( changeEnt ) {
553 QFile file( fileName ); 561 QFile file( fileName );
554 if (!file.open( IO_WriteOnly ) ) { 562 if (!file.open( IO_WriteOnly ) ) {
555 return false; 563 return false;
556 564
557 } 565 }
558 QTextStream ts( &file ); 566 QTextStream ts( &file );
559 ts.setCodec( QTextCodec::codecForName("utf8") ); 567 ts.setCodec( QTextCodec::codecForName("utf8") );
560 ts << changeString ; 568 ts << changeString ;
561 file.close(); 569 file.close();
562 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 570 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
563 system ( command.latin1() ); 571 system ( command.latin1() );
564 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 572 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
565 573
566 } 574 }
567 status.setText ( i18n("Deleting events ...") ); 575 status.setText ( i18n("Deleting events ...") );
568 qApp->processEvents(); 576 qApp->processEvents();
569 //qDebug("deleting... "); 577 //qDebug("deleting... ");
570 if ( deleteEnt ) { 578 if ( deleteEnt ) {
571 QFile file( fileName ); 579 QFile file( fileName );
572 if (!file.open( IO_WriteOnly ) ) { 580 if (!file.open( IO_WriteOnly ) ) {
573 return false; 581 return false;
574 582
575 } 583 }
576 QTextStream ts( &file ); 584 QTextStream ts( &file );
577 ts.setCodec( QTextCodec::codecForName("utf8") ); 585 ts.setCodec( QTextCodec::codecForName("utf8") );
578 ts << deleteString; 586 ts << deleteString;
579 file.close(); 587 file.close();
580 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 588 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
581 system ( command.latin1() ); 589 system ( command.latin1() );
582 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 590 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
583 } 591 }
584 592
585 593
586 changeString = tPrefix; 594 changeString = tPrefix;
587 deleteString = tPrefix; 595 deleteString = tPrefix;
588 status.setText ( i18n("Processing todos ...") ); 596 status.setText ( i18n("Processing todos ...") );
589 qApp->processEvents(); 597 qApp->processEvents();
590 QPtrList<Todo> tl = calendar->rawTodos(); 598 QPtrList<Todo> tl = calendar->rawTodos();
591 Todo* to = tl.first(); 599 Todo* to = tl.first();
592 i = 0; 600 i = 0;
593 message = i18n("Processing todo # "); 601 message = i18n("Processing todo # ");
594 procCount = 0; 602 procCount = 0;
595 while ( to ) { 603 while ( to ) {
596 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 604 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
597 status.setText ( message + QString::number ( ++procCount ) ); 605 status.setText ( message + QString::number ( ++procCount ) );
598 qApp->processEvents(); 606 qApp->processEvents();
599 QString eString = getTodoString( to ); 607 QString eString = getTodoString( to );
600 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 608 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
601 // deleting empty strings does not work. 609 // deleting empty strings does not work.
602 // we write first and x and then delete the record with the x 610 // we write first and x and then delete the record with the x
603 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 611 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
604 changeString += eString + "\n"; 612 changeString += eString + "\n";
605 deleteString += eString + "\n"; 613 deleteString += eString + "\n";
606 deleteEnt = true; 614 deleteEnt = true;
607 changeEnt = true; 615 changeEnt = true;
608 } 616 }
609 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 617 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
610 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 618 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
611 system ( command.utf8() ); 619 system ( command.utf8() );
612 QFile file( fileName ); 620 QFile file( fileName );
613 if (!file.open( IO_ReadOnly ) ) { 621 if (!file.open( IO_ReadOnly ) ) {
614 return false; 622 return false;
615 623
616 } 624 }
617 QTextStream ts( &file ); 625 QTextStream ts( &file );
618 ts.setCodec( QTextCodec::codecForName("utf8") ); 626 ts.setCodec( QTextCodec::codecForName("utf8") );
619 answer = ts.read(); 627 answer = ts.read();
620 file.close(); 628 file.close();
621 //qDebug("answer \n%s ", answer.latin1()); 629 //qDebug("answer \n%s ", answer.latin1());
622 getNumFromRecord( answer, to ) ; 630 getNumFromRecord( answer, to ) ;
623 631
624 } 632 }
625 else { // change existing 633 else { // change existing
626 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 634 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
627 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 635 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
628 changeString += eString + "\n"; 636 changeString += eString + "\n";
629 changeEnt = true; 637 changeEnt = true;
630 638
631 } 639 }
632 } 640 }
633 641
634 to = tl.next(); 642 to = tl.next();
635 } 643 }
636 status.setText ( i18n("Changing todos ...") ); 644 status.setText ( i18n("Changing todos ...") );
637 qApp->processEvents(); 645 qApp->processEvents();
638 //qDebug("changing... "); 646 //qDebug("changing... ");
639 if ( changeEnt ) { 647 if ( changeEnt ) {
640 QFile file( fileName ); 648 QFile file( fileName );
641 if (!file.open( IO_WriteOnly ) ) { 649 if (!file.open( IO_WriteOnly ) ) {
642 return false; 650 return false;
643 651
644 } 652 }
645 QTextStream ts( &file ); 653 QTextStream ts( &file );
646 ts.setCodec( QTextCodec::codecForName("utf8") ); 654 ts.setCodec( QTextCodec::codecForName("utf8") );
647 ts << changeString ; 655 ts << changeString ;
648 file.close(); 656 file.close();
649 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 657 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
650 system ( command.latin1() ); 658 system ( command.latin1() );
651 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 659 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
652 660
653 } 661 }
654 status.setText ( i18n("Deleting todos ...") ); 662 status.setText ( i18n("Deleting todos ...") );
655 qApp->processEvents(); 663 qApp->processEvents();
656 //qDebug("deleting... "); 664 //qDebug("deleting... ");
657 if ( deleteEnt ) { 665 if ( deleteEnt ) {
658 QFile file( fileName ); 666 QFile file( fileName );
659 if (!file.open( IO_WriteOnly ) ) { 667 if (!file.open( IO_WriteOnly ) ) {
660 return false; 668 return false;
661 669
662 } 670 }
663 QTextStream ts( &file ); 671 QTextStream ts( &file );
664 ts.setCodec( QTextCodec::codecForName("utf8") ); 672 ts.setCodec( QTextCodec::codecForName("utf8") );
665 ts << deleteString; 673 ts << deleteString;
666 file.close(); 674 file.close();
667 command = "db2file todo -d -c " + codec+ " < "+ fileName; 675 command = "db2file todo -d -c " + codec+ " < "+ fileName;
668 system ( command.latin1() ); 676 system ( command.latin1() );
669 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 677 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
670 } 678 }
671 679
672 return true; 680 return true;
673} 681}
674QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 682QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
675{ 683{
676 QString datestr; 684 QString datestr;
677 QString timestr; 685 QString timestr;
678 int offset = KGlobal::locale()->localTimeOffset( dti ); 686 int offset = KGlobal::locale()->localTimeOffset( dti );
679 QDateTime dt; 687 QDateTime dt;
680 if (useTZ) 688 if (useTZ)
681 dt = dti.addSecs ( -(offset*60)); 689 dt = dti.addSecs ( -(offset*60));
682 else 690 else
683 dt = dti; 691 dt = dti;
684 if(dt.date().isValid()){ 692 if(dt.date().isValid()){
685 const QDate& date = dt.date(); 693 const QDate& date = dt.date();
686 datestr.sprintf("%04d%02d%02d", 694 datestr.sprintf("%04d%02d%02d",
687 date.year(), date.month(), date.day()); 695 date.year(), date.month(), date.day());
688 } 696 }
689 if(dt.time().isValid()){ 697 if(dt.time().isValid()){
690 const QTime& time = dt.time(); 698 const QTime& time = dt.time();
691 timestr.sprintf("T%02d%02d%02d", 699 timestr.sprintf("T%02d%02d%02d",
692 time.hour(), time.minute(), time.second()); 700 time.hour(), time.minute(), time.second());
693 } 701 }
694 return datestr + timestr; 702 return datestr + timestr;
695} 703}
696QString SharpFormat::getEventString( Event* event ) 704QString SharpFormat::getEventString( Event* event )
697{ 705{
698 QStringList list; 706 QStringList list;
699 list.append( event->getID("Sharp_DTM") ); 707 list.append( event->getID("Sharp_DTM") );
700 list.append( event->categories().join(",") ); 708 list.append( event->categories().join(",") );
701 if ( !event->summary().isEmpty() ) 709 if ( !event->summary().isEmpty() )
702 list.append( event->summary() ); 710 list.append( event->summary() );
703 else 711 else
704 list.append("" ); 712 list.append("" );
705 if ( !event->location().isEmpty() ) 713 if ( !event->location().isEmpty() )
706 list.append( event->location() ); 714 list.append( event->location() );
707 else 715 else
708 list.append("" ); 716 list.append("" );
709 if ( !event->description().isEmpty() ) 717 if ( !event->description().isEmpty() )
710 list.append( event->description() ); 718 list.append( event->description() );
711 else 719 else
712 list.append( "" ); 720 list.append( "" );
713 if ( event->doesFloat () ) { 721 if ( event->doesFloat () ) {
714 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 722 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
715 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 723 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
716 list.append( "1" ); 724 list.append( "1" );
717 725
718 } 726 }
719 else { 727 else {
720 list.append( dtToString( event->dtStart()) ); 728 list.append( dtToString( event->dtStart()) );
721 list.append( dtToString( event->dtEnd()) ); //6 729 list.append( dtToString( event->dtEnd()) ); //6
722 list.append( "0" ); 730 list.append( "0" );
723 } 731 }
724 bool noAlarm = true; 732 bool noAlarm = true;
725 if ( event->alarms().count() > 0 ) { 733 if ( event->alarms().count() > 0 ) {
726 Alarm * al = event->alarms().first(); 734 Alarm * al = event->alarms().first();
727 if ( al->enabled() ) { 735 if ( al->enabled() ) {
728 noAlarm = false; 736 noAlarm = false;
729 list.append( "0" ); // yes, 0 == alarm 737 list.append( "0" ); // yes, 0 == alarm
730 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 738 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
731 if ( al->type() == Alarm::Audio ) 739 if ( al->type() == Alarm::Audio )
732 list.append( "1" ); // type audio 740 list.append( "1" ); // type audio
733 else 741 else
734 list.append( "0" ); // type silent 742 list.append( "0" ); // type silent
735 } 743 }
736 } 744 }
737 if ( noAlarm ) { 745 if ( noAlarm ) {
738 list.append( "1" ); // yes, 1 == no alarm 746 list.append( "1" ); // yes, 1 == no alarm
739 list.append( "0" ); // no alarm offset 747 list.append( "0" ); // no alarm offset
740 list.append( "1" ); // type 748 list.append( "1" ); // type
741 } 749 }
742 // next is: 11 750 // next is: 11
743 // next is: 11-16 are recurrence 751 // next is: 11-16 are recurrence
744 Recurrence* rec = event->recurrence(); 752 Recurrence* rec = event->recurrence();
745 753
746 bool writeEndDate = false; 754 bool writeEndDate = false;
747 switch ( rec->doesRecur() ) 755 switch ( rec->doesRecur() )
748 { 756 {
749 case Recurrence::rDaily: // 0 757 case Recurrence::rDaily: // 0
750 list.append( "0" ); 758 list.append( "0" );
751 list.append( QString::number( rec->frequency() ));//12 759 list.append( QString::number( rec->frequency() ));//12
752 list.append( "0" ); 760 list.append( "0" );
753 list.append( "0" ); 761 list.append( "0" );
754 writeEndDate = true; 762 writeEndDate = true;
755 break; 763 break;
756 case Recurrence::rWeekly:// 1 764 case Recurrence::rWeekly:// 1
757 list.append( "1" ); 765 list.append( "1" );
758 list.append( QString::number( rec->frequency()) );//12 766 list.append( QString::number( rec->frequency()) );//12
759 list.append( "0" ); 767 list.append( "0" );
760 { 768 {
761 int days = 0; 769 int days = 0;
762 QBitArray weekDays = rec->days(); 770 QBitArray weekDays = rec->days();
763 int i; 771 int i;
764 for( i = 1; i <= 7; ++i ) { 772 for( i = 1; i <= 7; ++i ) {
765 if ( weekDays[i-1] ) { 773 if ( weekDays[i-1] ) {
766 days += 1 << (i-1); 774 days += 1 << (i-1);
767 } 775 }
768 } 776 }
769 list.append( QString::number( days ) ); 777 list.append( QString::number( days ) );
770 } 778 }
771 //pending weekdays 779 //pending weekdays
772 writeEndDate = true; 780 writeEndDate = true;
773 781
774 break; 782 break;
775 case Recurrence::rMonthlyPos:// 2 783 case Recurrence::rMonthlyPos:// 2
776 list.append( "2" ); 784 list.append( "2" );
777 list.append( QString::number( rec->frequency()) );//12 785 list.append( QString::number( rec->frequency()) );//12
778 786
779 writeEndDate = true; 787 writeEndDate = true;
780 { 788 {
781 int count = 1; 789 int count = 1;
782 QPtrList<Recurrence::rMonthPos> rmp; 790 QPtrList<Recurrence::rMonthPos> rmp;
783 rmp = rec->monthPositions(); 791 rmp = rec->monthPositions();
784 if ( rmp.first()->negative ) 792 if ( rmp.first()->negative )
785 count = 5 - rmp.first()->rPos - 1; 793 count = 5 - rmp.first()->rPos - 1;
786 else 794 else
787 count = rmp.first()->rPos - 1; 795 count = rmp.first()->rPos - 1;
788 list.append( QString::number( count ) ); 796 list.append( QString::number( count ) );
789 797
790 } 798 }
791 799
792 list.append( "0" ); 800 list.append( "0" );
793 break; 801 break;
794 case Recurrence::rMonthlyDay:// 3 802 case Recurrence::rMonthlyDay:// 3
795 list.append( "3" ); 803 list.append( "3" );
796 list.append( QString::number( rec->frequency()) );//12 804 list.append( QString::number( rec->frequency()) );//12
797 list.append( "0" ); 805 list.append( "0" );
798 list.append( "0" ); 806 list.append( "0" );
799 writeEndDate = true; 807 writeEndDate = true;
800 break; 808 break;
801 case Recurrence::rYearlyMonth://4 809 case Recurrence::rYearlyMonth://4
802 list.append( "4" ); 810 list.append( "4" );
803 list.append( QString::number( rec->frequency()) );//12 811 list.append( QString::number( rec->frequency()) );//12
804 list.append( "0" ); 812 list.append( "0" );
805 list.append( "0" ); 813 list.append( "0" );
806 writeEndDate = true; 814 writeEndDate = true;
807 break; 815 break;
808 816
809 default: 817 default:
810 list.append( "255" ); 818 list.append( "255" );
811 list.append( QString() ); 819 list.append( QString() );
812 list.append( "0" ); 820 list.append( "0" );
813 list.append( QString() ); 821 list.append( QString() );
814 list.append( "0" ); 822 list.append( "0" );
815 list.append( "20991231T000000" ); 823 list.append( "20991231T000000" );
816 break; 824 break;
817 } 825 }
818 if ( writeEndDate ) { 826 if ( writeEndDate ) {
819 827
820 if ( rec->endDate().isValid() ) { // 15 + 16 828 if ( rec->endDate().isValid() ) { // 15 + 16
821 list.append( "1" ); 829 list.append( "1" );
822 list.append( dtToString( rec->endDate()) ); 830 list.append( dtToString( rec->endDate()) );
823 } else { 831 } else {
824 list.append( "0" ); 832 list.append( "0" );
825 list.append( "20991231T000000" ); 833 list.append( "20991231T000000" );
826 } 834 }
827 835
828 } 836 }
829 if ( event->doesFloat () ) { 837 if ( event->doesFloat () ) {
830 list.append( dtToString( event->dtStart(), false ).left( 8 )); 838 list.append( dtToString( event->dtStart(), false ).left( 8 ));
831 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 839 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
832 840
833 } 841 }
834 else { 842 else {
835 list.append( QString() ); 843 list.append( QString() );
836 list.append( QString() ); 844 list.append( QString() );
837 845
838 } 846 }
839 if (event->dtStart().date() == event->dtEnd().date() ) 847 if (event->dtStart().date() == event->dtEnd().date() )
840 list.append( "0" ); 848 list.append( "0" );
841 else 849 else
842 list.append( "1" ); 850 list.append( "1" );
843 851
844 852
845 for(QStringList::Iterator it=list.begin(); 853 for(QStringList::Iterator it=list.begin();
846 it!=list.end(); ++it){ 854 it!=list.end(); ++it){
847 QString& s = (*it); 855 QString& s = (*it);
848 s.replace(QRegExp("\""), "\"\""); 856 s.replace(QRegExp("\""), "\"\"");
849 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 857 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
850 s.prepend('\"'); 858 s.prepend('\"');
851 s.append('\"'); 859 s.append('\"');
852 } else if(s.isEmpty() && !s.isNull()){ 860 } else if(s.isEmpty() && !s.isNull()){
853 s = "\"\""; 861 s = "\"\"";
854 } 862 }
855 } 863 }
856 return list.join(","); 864 return list.join(",");
857 865
858 866
859} 867}
860QString SharpFormat::getTodoString( Todo* todo ) 868QString SharpFormat::getTodoString( Todo* todo )
861{ 869{
862 QStringList list; 870 QStringList list;
863 list.append( todo->getID("Sharp_DTM") ); 871 list.append( todo->getID("Sharp_DTM") );
864 list.append( todo->categories().join(",") ); 872 list.append( todo->categories().join(",") );
865 873
866 if ( todo->hasStartDate() ) { 874 if ( todo->hasStartDate() ) {
867 list.append( dtToString( todo->dtStart()) ); 875 list.append( dtToString( todo->dtStart()) );
868 } else 876 } else
869 list.append( QString() ); 877 list.append( QString() );
870 878
871 if ( todo->hasDueDate() ) { 879 if ( todo->hasDueDate() ) {
872 QTime tim; 880 QTime tim;
873 if ( todo->doesFloat()) { 881 if ( todo->doesFloat()) {
874 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 882 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
875 } else { 883 } else {
876 list.append( dtToString(todo->dtDue() ) ); 884 list.append( dtToString(todo->dtDue() ) );
877 } 885 }
878 } else 886 } else
879 list.append( QString() ); 887 list.append( QString() );
880 888
881 if ( todo->isCompleted() ) { 889 if ( todo->isCompleted() ) {
882 list.append( dtToString( todo->completed()) ); 890 list.append( dtToString( todo->completed()) );
883 list.append( "0" ); // yes 0 == completed 891 list.append( "0" ); // yes 0 == completed
884 } else { 892 } else {
885 list.append( dtToString( todo->completed()) ); 893 list.append( dtToString( todo->completed()) );
886 list.append( "1" ); 894 list.append( "1" );
887 } 895 }
888 list.append( QString::number( todo->priority() )); 896 list.append( QString::number( todo->priority() ));
889 if( ! todo->summary().isEmpty() ) 897 if( ! todo->summary().isEmpty() )
890 list.append( todo->summary() ); 898 list.append( todo->summary() );
891 else 899 else
892 list.append( "" ); 900 list.append( "" );
893 if (! todo->description().isEmpty() ) 901 if (! todo->description().isEmpty() )
894 list.append( todo->description() ); 902 list.append( todo->description() );
895 else 903 else
896 list.append( "" ); 904 list.append( "" );
897 for(QStringList::Iterator it=list.begin(); 905 for(QStringList::Iterator it=list.begin();
898 it!=list.end(); ++it){ 906 it!=list.end(); ++it){
899 QString& s = (*it); 907 QString& s = (*it);
900 s.replace(QRegExp("\""), "\"\""); 908 s.replace(QRegExp("\""), "\"\"");
901 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 909 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
902 s.prepend('\"'); 910 s.prepend('\"');
903 s.append('\"'); 911 s.append('\"');
904 } else if(s.isEmpty() && !s.isNull()){ 912 } else if(s.isEmpty() && !s.isNull()){
905 s = "\"\""; 913 s = "\"\"";
906 } 914 }
907 } 915 }
908 return list.join(","); 916 return list.join(",");
909} 917}
910QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) 918QString SharpFormat::getPart( const QString & text, bool &ok, int &start )
911{ 919{
912 //qDebug("start %d ", start); 920 //qDebug("start %d ", start);
913 921
914 QString retval =""; 922 QString retval ="";
915 if ( text.at(start) == '"' ) { 923 if ( text.at(start) == '"' ) {
916 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { 924 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
917 start = start +2; 925 start = start +2;
918 if ( text.mid( start,1) == "," ) { 926 if ( text.mid( start,1) == "," ) {
919 start += 1; 927 start += 1;
920 } 928 }
921 retval = ""; 929 retval = "";
922 if ( text.mid( start,1) == "\n" ) { 930 if ( text.mid( start,1) == "\n" ) {
923 start += 1; 931 start += 1;
924 ok = false; 932 ok = false;
925 } 933 }
926 return retval; 934 return retval;
927 } 935 }
928 int hk = start+1; 936 int hk = start+1;
929 hk = text.find ('"',hk); 937 hk = text.find ('"',hk);
930 while ( text.at(hk+1) == '"' ) 938 while ( text.at(hk+1) == '"' )
931 hk = text.find ('"',hk+2); 939 hk = text.find ('"',hk+2);
932 retval = text.mid( start+1, hk-start-1); 940 retval = text.mid( start+1, hk-start-1);
933 start = hk+1; 941 start = hk+1;
934 retval.replace( QRegExp("\"\""), "\""); 942 retval.replace( QRegExp("\"\""), "\"");
935 if ( text.mid( start,1) == "," ) { 943 if ( text.mid( start,1) == "," ) {
936 start += 1; 944 start += 1;
937 } 945 }
938 if ( text.mid( start,1) == "\n" ) { 946 if ( text.mid( start,1) == "\n" ) {
939 start += 1; 947 start += 1;
940 ok = false; 948 ok = false;
941 } 949 }
942 //qDebug("retval***%s*** ",retval.latin1() ); 950 //qDebug("retval***%s*** ",retval.latin1() );
943 return retval; 951 return retval;
944 952
945 } else { 953 } else {
946 int nl = text.find ("\n",start); 954 int nl = text.find ("\n",start);
947 int kom = text.find (',',start); 955 int kom = text.find (',',start);
948 if ( kom < nl ) { 956 if ( kom < nl ) {
949 // qDebug("kom < nl %d ", kom); 957 // qDebug("kom < nl %d ", kom);
950 retval = text.mid(start, kom-start); 958 retval = text.mid(start, kom-start);
951 start = kom+1; 959 start = kom+1;
952 return retval; 960 return retval;
953 } else { 961 } else {
954 if ( nl == kom ) { 962 if ( nl == kom ) {
955 // qDebug(" nl == kom "); 963 // qDebug(" nl == kom ");
956 start = 0; 964 start = 0;
957 ok = false; 965 ok = false;
958 return "0"; 966 return "0";
959 } 967 }
960 // qDebug(" nl < kom ", nl); 968 // qDebug(" nl < kom ", nl);
961 retval = text.mid( start, nl-start); 969 retval = text.mid( start, nl-start);
962 ok = false; 970 ok = false;
963 start = nl+1; 971 start = nl+1;
964 return retval; 972 return retval;
965 } 973 }
966 } 974 }
967} 975}
968bool SharpFormat::fromString( Calendar *calendar, const QString & text) 976bool SharpFormat::fromString( Calendar *calendar, const QString & text)
969{ 977{
970 return false; 978 return false;
971} 979}
972bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 980bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
973{ 981{
974 // qDebug("test %s ", text.latin1()); 982 // qDebug("test %s ", text.latin1());
975 QStringList templist; 983 QStringList templist;
976 QString tempString; 984 QString tempString;
977 int start = 0; 985 int start = 0;
978 int len = text.length(); 986 int len = text.length();
979 int end = text.find ("\n",start)+1; 987 int end = text.find ("\n",start)+1;
980 bool ok = true; 988 bool ok = true;
981 start = end; 989 start = end;
982 SharpParser handler( calendar ); 990 SharpParser handler( calendar );
983 handler.setCategoriesList( mCategories ); 991 handler.setCategoriesList( mCategories );
984 while ( start > 0 ) { 992 while ( start > 0 ) {
985 templist.clear(); 993 templist.clear();
986 ok = true; 994 ok = true;
987 while ( ok ) { 995 while ( ok ) {
988 tempString = getPart( text, ok, start ); 996 tempString = getPart( text, ok, start );
989 if ( start >= len || start == 0 ) { 997 if ( start >= len || start == 0 ) {
990 start = 0; 998 start = 0;
991 ok = false; 999 ok = false;
992 } 1000 }
993 if ( tempString.right(1) =="\n" ) 1001 if ( tempString.right(1) =="\n" )
994 tempString = tempString.left( tempString.length()-1); 1002 tempString = tempString.left( tempString.length()-1);
995 //if ( ok ) 1003 //if ( ok )
996 templist.append( tempString ); 1004 templist.append( tempString );
997 //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); 1005 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
998 } 1006 }
999 handler.startElement( existingCalendar, templist, type ); 1007 handler.startElement( existingCalendar, templist, type );
1000 } 1008 }
1001 1009
1002 return false; 1010 return false;
1003} 1011}
1004 1012
1005QString SharpFormat::toString( Calendar * ) 1013QString SharpFormat::toString( Calendar * )
1006{ 1014{
1007 return QString::null; 1015 return QString::null;
1008} 1016}