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