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