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