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