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