summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-08 20:55:19 (UTC)
committer zautrix <zautrix>2004-08-08 20:55:19 (UTC)
commitb51c65d86224ee7d77e672fcfba5ea92d55eed0e (patch) (unidiff)
tree1137e001be49f130477b3b53acfab4f2150ccf86 /libkcal
parent3a769cd15cfdb8e19e5fec2088c59aadeed4800a (diff)
downloadkdepimpi-b51c65d86224ee7d77e672fcfba5ea92d55eed0e.zip
kdepimpi-b51c65d86224ee7d77e672fcfba5ea92d55eed0e.tar.gz
kdepimpi-b51c65d86224ee7d77e672fcfba5ea92d55eed0e.tar.bz2
cleanup
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp24
1 files changed, 4 insertions, 20 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 1a9ccbc..7e1c9cd 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,304 +1,289 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
51
52//ARSD silentalarm = 0
53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
54// 12 RFRQ
55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt
59//ALSD
60//ALED
61//MDAY
62
63class PhoneParser : public QObject 49class PhoneParser : public QObject
64{ 50{
65public: 51public:
66 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
67 ; 53 ;
68 } 54 }
69 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
70 { 56 {
71 57
72 int id = ToDo->Location; 58 int id = ToDo->Location;
73 Todo *todo; 59 Todo *todo;
74 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
75 if (todo ) 61 if (todo )
76 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
77 else 63 else
78 todo = new Todo; 64 todo = new Todo;
79 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
80 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
81 int priority; 67 int priority;
82 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
83 case GSM_Priority_Low : priority = 1; break; 69 case GSM_Priority_Low : priority = 1; break;
84 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
85 case GSM_Priority_High : priority = 5; break; 71 case GSM_Priority_High : priority = 5; break;
86 default :priority = 3 ;break; 72 default :priority = 3 ;break;
87 } 73 }
88 todo->setPriority( priority ); 74 todo->setPriority( priority );
89 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
90 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
91 int j; 77 int j;
92 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
93 bool alarm = false; 79 bool alarm = false;
94 QDateTime alarmDt; 80 QDateTime alarmDt;
95 GSM_Category Category; 81 GSM_Category Category;
96 int error; 82 int error;
97 QString completedString = "no"; 83 QString completedString = "no";
98 for (j=0;j<ToDo->EntriesNum;j++) { 84 for (j=0;j<ToDo->EntriesNum;j++) {
99 85
100 //qDebug(" for todo %d",ToDo->Location ); 86 //qDebug(" for todo %d",ToDo->Location );
101 switch (ToDo->Entries[j].EntryType) { 87 switch (ToDo->Entries[j].EntryType) {
102 case TODO_END_DATETIME: 88 case TODO_END_DATETIME:
103 dtp = &ToDo->Entries[j].Date ; 89 dtp = &ToDo->Entries[j].Date ;
104 todo->setDtDue (fromGSM ( dtp )); 90 todo->setDtDue (fromGSM ( dtp ));
105 break; 91 break;
106 case TODO_COMPLETED: 92 case TODO_COMPLETED:
107 if ( ToDo->Entries[j].Number == 1 ) { 93 if ( ToDo->Entries[j].Number == 1 ) {
108 todo->setCompleted( true ); 94 todo->setCompleted( true );
109 completedString = "yes"; 95 completedString = "yes";
110 } 96 }
111 else { 97 else {
112 todo->setCompleted( false ); 98 todo->setCompleted( false );
113 } 99 }
114 break; 100 break;
115 case TODO_ALARM_DATETIME: 101 case TODO_ALARM_DATETIME:
116 dtp = &ToDo->Entries[j].Date ; 102 dtp = &ToDo->Entries[j].Date ;
117 alarm = true; 103 alarm = true;
118 alarmDt = fromGSM ( dtp ); 104 alarmDt = fromGSM ( dtp );
119 break; 105 break;
120 case TODO_SILENT_ALARM_DATETIME: 106 case TODO_SILENT_ALARM_DATETIME:
121 dtp = &ToDo->Entries[j].Date ; 107 dtp = &ToDo->Entries[j].Date ;
122 alarm = true; 108 alarm = true;
123 alarmDt = fromGSM ( dtp ); 109 alarmDt = fromGSM ( dtp );
124 break; 110 break;
125 case TODO_TEXT: 111 case TODO_TEXT:
126 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
127 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
128 break; 114 break;
129 case TODO_PRIVATE: 115 case TODO_PRIVATE:
130 if ( ToDo->Entries[j].Number == 1 ) 116 if ( ToDo->Entries[j].Number == 1 )
131 todo->setSecrecy( Incidence::SecrecyPrivate ); 117 todo->setSecrecy( Incidence::SecrecyPrivate );
132 else 118 else
133 todo->setSecrecy( Incidence::SecrecyPublic ); 119 todo->setSecrecy( Incidence::SecrecyPublic );
134 break; 120 break;
135 case TODO_CATEGORY: 121 case TODO_CATEGORY:
136 Category.Location = ToDo->Entries[j].Number; 122 Category.Location = ToDo->Entries[j].Number;
137 Category.Type = Category_ToDo; 123 Category.Type = Category_ToDo;
138 error=Phone->GetCategory(s, &Category); 124 error=Phone->GetCategory(s, &Category);
139 if (error == ERR_NONE) { 125 if (error == ERR_NONE) {
140 QStringList cat = todo->categories(); 126 QStringList cat = todo->categories();
141 QString nCat = QString ( (const char*)Category.Name ); 127 QString nCat = QString ( (const char*)Category.Name );
142 if ( !nCat.isEmpty() ) 128 if ( !nCat.isEmpty() )
143 if ( !cat.contains( nCat )) { 129 if ( !cat.contains( nCat )) {
144 cat << nCat; 130 cat << nCat;
145 todo->setCategories( cat ); 131 todo->setCategories( cat );
146 } 132 }
147 } 133 }
148 break; 134 break;
149 case TODO_CONTACTID: 135 case TODO_CONTACTID:
150#if 0 136#if 0
151 // not supported 137 // not supported
152 entry.Location = ToDo->Entries[j].Number; 138 entry.Location = ToDo->Entries[j].Number;
153 entry.MemoryType = MEM_ME; 139 entry.MemoryType = MEM_ME;
154 error=Phone->GetMemory(s, &entry); 140 error=Phone->GetMemory(s, &entry);
155 if (error == ERR_NONE) { 141 if (error == ERR_NONE) {
156 name = GSM_PhonebookGetEntryName(&entry); 142 name = GSM_PhonebookGetEntryName(&entry);
157 if (name != NULL) { 143 if (name != NULL) {
158 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);
159 } else { 145 } else {
160 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 146 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
161 } 147 }
162 } else { 148 } else {
163 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 149 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
164 } 150 }
165#endif 151#endif
166 break; 152 break;
167 case TODO_PHONE: 153 case TODO_PHONE:
168#if 0 154#if 0
169 // not supported 155 // not supported
170 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
171#endif 157#endif
172 break; 158 break;
173 } 159 }
174 } 160 }
175 QString alarmString = ""; 161 QString alarmString = "";
176 // strange 0 semms to mean: alarm enabled
177 if ( alarm ) { 162 if ( alarm ) {
178 Alarm *alarm; 163 Alarm *alarm;
179 if ( todo->alarms().count() > 0 ) 164 if ( todo->alarms().count() > 0 )
180 alarm = todo->alarms().first(); 165 alarm = todo->alarms().first();
181 else { 166 else {
182 alarm = new Alarm( todo ); 167 alarm = new Alarm( todo );
183 todo->addAlarm( alarm ); 168 todo->addAlarm( alarm );
184 } 169 }
185 alarm->setType( Alarm::Audio ); 170 alarm->setType( Alarm::Audio );
186 alarm->setEnabled( true ); 171 alarm->setEnabled( true );
187 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 172 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
188 alarm->setStartOffset( alarmOffset ); 173 alarm->setStartOffset( alarmOffset );
189 alarmString = QString::number( alarmOffset ); 174 alarmString = QString::number( alarmOffset );
190 } 175 }
191 // csum ***************************************** 176 // csum *****************************************
192 QStringList attList; 177 QStringList attList;
193 uint cSum; 178 uint cSum;
194 if ( todo->hasDueDate() ) 179 if ( todo->hasDueDate() )
195 attList << dtToString ( todo->dtDue() ); 180 attList << dtToString ( todo->dtDue() );
196 attList << QString::number( id ); 181 attList << QString::number( id );
197 attList << todo->summary(); 182 attList << todo->summary();
198 attList << completedString; 183 attList << completedString;
199 attList << QString::number( todo->priority() ); 184 attList << QString::number( todo->priority() );
200 attList << alarmString; 185 attList << alarmString;
201 attList << todo->categoriesStr(); 186 attList << todo->categoriesStr();
202 attList << todo->secrecyStr(); 187 attList << todo->secrecyStr();
203 cSum = PhoneFormat::getCsum(attList ); 188 cSum = PhoneFormat::getCsum(attList );
204 todo->setCsum( mProfileName, QString::number( cSum )); 189 todo->setCsum( mProfileName, QString::number( cSum ));
205 mCalendar->addTodo( todo); 190 mCalendar->addTodo( todo);
206 191
207 return true; 192 return true;
208 } 193 }
209 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 194 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
210 { 195 {
211 196
212 int id = Note->Location; 197 int id = Note->Location;
213 Event *event; 198 Event *event;
214 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 199 event = existingCalendar->event( mProfileName ,QString::number( id ) );
215 if ( event ) 200 if ( event )
216 event = (Event*)event->clone(); 201 event = (Event*)event->clone();
217 else 202 else
218 event = new Event; 203 event = new Event;
219 event->setID( mProfileName,QString::number( id ) ); 204 event->setID( mProfileName,QString::number( id ) );
220 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 205 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
221 206
222 207
223 int i = 0; 208 int i = 0;
224 bool repeating = false; 209 bool repeating = false;
225 int repeat_dayofweek = -1; 210 int repeat_dayofweek = -1;
226 int repeat_day = -1; 211 int repeat_day = -1;
227 int repeat_weekofmonth = -1; 212 int repeat_weekofmonth = -1;
228 int repeat_month = -1; 213 int repeat_month = -1;
229 int repeat_frequency = -1; 214 int repeat_frequency = -1;
230 int rec_type = -1; 215 int rec_type = -1;
231 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 216 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
232 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 217 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
233 GSM_DateTime* dtp; 218 GSM_DateTime* dtp;
234 bool alarm = false; 219 bool alarm = false;
235 QDateTime alarmDt; 220 QDateTime alarmDt;
236 repeat_startdate.Day= 0; 221 repeat_startdate.Day= 0;
237 repeat_stopdate.Day = 0; 222 repeat_stopdate.Day = 0;
238 for (i=0;i<Note->EntriesNum;i++) { 223 for (i=0;i<Note->EntriesNum;i++) {
239 224
240 //qDebug(" for ev"); 225 //qDebug(" for ev");
241 switch (Note->Entries[i].EntryType) { 226 switch (Note->Entries[i].EntryType) {
242 case CAL_START_DATETIME: 227 case CAL_START_DATETIME:
243 dtp = &Note->Entries[i].Date ; 228 dtp = &Note->Entries[i].Date ;
244 if ( dtp->Hour > 24 ) { 229 if ( dtp->Hour > 24 ) {
245 event->setFloats( true ); 230 event->setFloats( true );
246 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 231 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
247 } else { 232 } else {
248 event->setDtStart (fromGSM ( dtp )); 233 event->setDtStart (fromGSM ( dtp ));
249 234
250 } 235 }
251 break; 236 break;
252 case CAL_END_DATETIME: 237 case CAL_END_DATETIME:
253 dtp = &Note->Entries[i].Date ; 238 dtp = &Note->Entries[i].Date ;
254 if ( dtp->Hour > 24 ) { 239 if ( dtp->Hour > 24 ) {
255 event->setFloats( true ); 240 event->setFloats( true );
256 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 241 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
257 } else { 242 } else {
258 event->setDtEnd (fromGSM ( dtp )); 243 event->setDtEnd (fromGSM ( dtp ));
259 } 244 }
260 break; 245 break;
261 case CAL_ALARM_DATETIME: 246 case CAL_ALARM_DATETIME:
262 dtp = &Note->Entries[i].Date ; 247 dtp = &Note->Entries[i].Date ;
263 alarm = true; 248 alarm = true;
264 alarmDt = fromGSM ( dtp ); 249 alarmDt = fromGSM ( dtp );
265 break; 250 break;
266 case CAL_SILENT_ALARM_DATETIME: 251 case CAL_SILENT_ALARM_DATETIME:
267 dtp = &Note->Entries[i].Date ; 252 dtp = &Note->Entries[i].Date ;
268 alarm = true; 253 alarm = true;
269 alarmDt = fromGSM ( dtp ); 254 alarmDt = fromGSM ( dtp );
270 break; 255 break;
271 case CAL_RECURRANCE: 256 case CAL_RECURRANCE:
272 rec_type = Note->Entries[i].Number; 257 rec_type = Note->Entries[i].Number;
273 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 258 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
274 break; 259 break;
275 case CAL_TEXT: 260 case CAL_TEXT:
276 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); 261 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
277 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); 262 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
278 break; 263 break;
279 case CAL_LOCATION: 264 case CAL_LOCATION:
280 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); 265 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
281 break; 266 break;
282 case CAL_PHONE: 267 case CAL_PHONE:
283 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 268 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
284 break; 269 break;
285 case CAL_PRIVATE: 270 case CAL_PRIVATE:
286 if ( Note->Entries[i].Number == 1 ) 271 if ( Note->Entries[i].Number == 1 )
287 event->setSecrecy( Incidence::SecrecyPrivate ); 272 event->setSecrecy( Incidence::SecrecyPrivate );
288 else 273 else
289 event->setSecrecy( Incidence::SecrecyPublic ); 274 event->setSecrecy( Incidence::SecrecyPublic );
290 275
291 break; 276 break;
292 case CAL_CONTACTID: 277 case CAL_CONTACTID:
293#if 0 278#if 0
294 entry.Location = Note->Entries[i].Number; 279 entry.Location = Note->Entries[i].Number;
295 entry.MemoryType = MEM_ME; 280 entry.MemoryType = MEM_ME;
296 error=Phone->GetMemory(&s, &entry); 281 error=Phone->GetMemory(&s, &entry);
297 if (error == ERR_NONE) { 282 if (error == ERR_NONE) {
298 name = GSM_PhonebookGetEntryName(&entry); 283 name = GSM_PhonebookGetEntryName(&entry);
299 if (name != NULL) { 284 if (name != NULL) {
300 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 285 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
301 } else { 286 } else {
302 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 287 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
303 } 288 }
304 } else { 289 } else {
@@ -538,305 +523,304 @@ public:
538 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 523 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
539 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 524 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
540 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 525 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
541 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 526 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
542 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 527 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
543 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 528 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
544 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 529 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
545 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 530 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
546 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 531 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
547 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 532 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
548 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 533 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
549 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 534 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
550 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 535 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
551 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 536 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
552 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 537 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
553 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 538 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
554 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 539 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
555 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 540 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
556 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 541 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
557 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 542 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
558 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 543 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
559 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 544 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
560 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 545 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
561 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 546 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
562 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 547 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
563 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 548 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
564 default : CATEGORY = QString(""); 549 default : CATEGORY = QString("");
565 } 550 }
566 551
567 return CATEGORY; 552 return CATEGORY;
568 } 553 }
569 554
570protected: 555protected:
571private: 556private:
572 Calendar *mCalendar; 557 Calendar *mCalendar;
573 QString mProfileName ; 558 QString mProfileName ;
574}; 559};
575 560
576 561
577PhoneFormat::PhoneFormat() 562PhoneFormat::PhoneFormat()
578{ 563{
579 ; 564 ;
580} 565}
581 566
582PhoneFormat::~PhoneFormat() 567PhoneFormat::~PhoneFormat()
583{ 568{
584} 569}
585ulong PhoneFormat::getCsum( const QStringList & attList) 570ulong PhoneFormat::getCsum( const QStringList & attList)
586{ 571{
587 int max = attList.count() -1; 572 int max = attList.count() -1;
588 ulong cSum = 0; 573 ulong cSum = 0;
589 int j,k,i; 574 int j,k,i;
590 int add; 575 int add;
591 for ( i = 1; i < max ; ++i ) { 576 for ( i = 1; i < max ; ++i ) {
592 QString s = attList[i]; 577 QString s = attList[i];
593 if ( ! s.isEmpty() ){ 578 if ( ! s.isEmpty() ){
594 j = s.length(); 579 j = s.length();
595 for ( k = 0; k < j; ++k ) { 580 for ( k = 0; k < j; ++k ) {
596 int mul = k +1; 581 int mul = k +1;
597 add = s[k].unicode (); 582 add = s[k].unicode ();
598 if ( k < 16 ) 583 if ( k < 16 )
599 mul = mul * mul; 584 mul = mul * mul;
600 add = add * mul *i*i*i; 585 add = add * mul *i*i*i;
601 cSum += add; 586 cSum += add;
602 } 587 }
603 } 588 }
604 } 589 }
605 return cSum; 590 return cSum;
606 591
607} 592}
608//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 593//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
609#include <stdlib.h> 594#include <stdlib.h>
610#define DEBUGMODE false 595#define DEBUGMODE false
611bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) 596bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model )
612{ 597{
613 mProfileName = profileName; 598 mProfileName = profileName;
614 GSM_StateMachines; 599 GSM_StateMachines;
615 qDebug(" load "); 600 qDebug(" load ");
616 s.opened = false; 601 s.opened = false;
617 s.msg = NULL; 602 s.msg = NULL;
618 s.ConfigNum = 0; 603 s.ConfigNum = 0;
619#if 0 604#if 0
620 static char*cp; 605 static char*cp;
621 static INI_Section *cfg = NULL; 606 static INI_Section *cfg = NULL;
622 cfg=GSM_FindGammuRC(); 607 cfg=GSM_FindGammuRC();
623 int i; 608 int i;
624 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 609 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
625 if (cfg!=NULL) { 610 if (cfg!=NULL) {
626 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); 611 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
627 if (cp) di.coding = cp; 612 if (cp) di.coding = cp;
628 613
629 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); 614 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
630 if (s.Config[i].Localize) { 615 if (s.Config[i].Localize) {
631 s.msg=INI_ReadFile(s.Config[i].Localize, true); 616 s.msg=INI_ReadFile(s.Config[i].Localize, true);
632 } else { 617 } else {
633#if !defined(WIN32) && defined(LOCALE_PATH) 618#if !defined(WIN32) && defined(LOCALE_PATH)
634 locale = setlocale(LC_MESSAGES, NULL); 619 locale = setlocale(LC_MESSAGES, NULL);
635 if (locale != NULL) { 620 if (locale != NULL) {
636 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 621 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
637 LOCALE_PATH, 622 LOCALE_PATH,
638 tolower(locale[0]), 623 tolower(locale[0]),
639 tolower(locale[1])); 624 tolower(locale[1]));
640 s.msg = INI_ReadFile(locale_file, true); 625 s.msg = INI_ReadFile(locale_file, true);
641 } 626 }
642#endif 627#endif
643 } 628 }
644 } 629 }
645 630
646 /* Wanted user specific configuration? */ 631 /* Wanted user specific configuration? */
647 632
648 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 633 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
649 634
650 s.ConfigNum++; 635 s.ConfigNum++;
651 636
652 /* We want to use only one file descriptor for global and state machine debug output */ 637 /* We want to use only one file descriptor for global and state machine debug output */
653 s.Config[i].UseGlobalDebugFile = true; 638 s.Config[i].UseGlobalDebugFile = true;
654 639
655 640
656 641
657 /* We wanted to read just user specified configuration. */ 642 /* We wanted to read just user specified configuration. */
658 {break;} 643 {break;}
659 } 644 }
660 645
661#endif 646#endif
662 setlocale(LC_ALL, ""); 647 setlocale(LC_ALL, "");
663 GSM_ReadConfig(NULL, &s.Config[0], 0); 648 GSM_ReadConfig(NULL, &s.Config[0], 0);
664 s.ConfigNum = 1; 649 s.ConfigNum = 1;
665 GSM_Config *cfg = &s.Config[0]; 650 GSM_Config *cfg = &s.Config[0];
666 di.coding = "utf8";
667 if ( ! connection.isEmpty() ) { 651 if ( ! connection.isEmpty() ) {
668 cfg->Connection = strdup(connection.latin1()); 652 cfg->Connection = strdup(connection.latin1());
669 cfg->DefaultConnection = false; 653 cfg->DefaultConnection = false;
670 qDebug("Connection set %s ", cfg->Connection ); 654 qDebug("Connection set %s ", cfg->Connection );
671 655
672 } 656 }
673 if ( ! device.isEmpty() ) { 657 if ( ! device.isEmpty() ) {
674 cfg->Device = strdup(device.latin1()); 658 cfg->Device = strdup(device.latin1());
675 cfg->DefaultDevice = false; 659 cfg->DefaultDevice = false;
676 qDebug("Device set %s ", cfg->Device); 660 qDebug("Device set %s ", cfg->Device);
677 661
678 } 662 }
679 if ( ! model.isEmpty() ) { 663 if ( ! model.isEmpty() ) {
680 strcpy(cfg->Model,model.latin1() ); 664 strcpy(cfg->Model,model.latin1() );
681 cfg->DefaultModel = false; 665 cfg->DefaultModel = false;
682 qDebug("Model set %s ",cfg->Model ); 666 qDebug("Model set %s ",cfg->Model );
683 667
684 668
685 } 669 }
686 int error=GSM_InitConnection(&s,3); 670 int error=GSM_InitConnection(&s,3);
687 qDebug(" init %d %d", error, ERR_NONE); 671 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
688 if ( error != ERR_NONE ) 672 if ( error != ERR_NONE )
689 return false; 673 return false;
690 // fromString2Cal( calendar, existngCal, &s, "Event" );
691 GSM_Phone_Functions*Phone; 674 GSM_Phone_Functions*Phone;
692 GSM_CalendarEntrynote; 675 GSM_CalendarEntrynote;
693 bool start = true; 676 bool start = true;
694 Phone=s.Phone.Functions; 677 Phone=s.Phone.Functions;
695 bool gshutdown = false; 678 bool gshutdown = false;
696 PhoneParser handler( calendar, profileName ); 679 PhoneParser handler( calendar, profileName );
697 int ccc = 0; 680 int ccc = 0;
698 while (!gshutdown && ccc++ < 3) { 681 qDebug("Debug: only 10 calender items are downloaded ");
682 while (!gshutdown && ccc++ < 10) {
699 683
700 qDebug("readEvent %d ", ccc); 684 qDebug("readEvent %d ", ccc);
701 error=Phone->GetNextCalendar(&s,&note,start); 685 error=Phone->GetNextCalendar(&s,&note,start);
702 if (error == ERR_EMPTY) break; 686 if (error == ERR_EMPTY) break;
703 start = false; 687 start = false;
704 handler.readEvent( existingCal, &note ); 688 handler.readEvent( existingCal, &note );
705 } 689 }
706 690
707 start = true; 691 start = true;
708 GSM_ToDoEntry ToDo; 692 GSM_ToDoEntry ToDo;
709 ccc = 0; 693 ccc = 0;
710 while (!gshutdown) { 694 while (!gshutdown) {
711 error = Phone->GetNextToDo(&s, &ToDo, start); 695 error = Phone->GetNextToDo(&s, &ToDo, start);
712 if (error == ERR_EMPTY) break; 696 if (error == ERR_EMPTY) break;
713 start = false; 697 start = false;
714 qDebug("readTodo %d ", ++ccc); 698 qDebug("ReadTodo %d ", ++ccc);
715 handler.readTodo( existingCal, &ToDo, &s); 699 handler.readTodo( existingCal, &ToDo, &s);
716 700
717 } 701 }
718 702
719 error=GSM_TerminateConnection(&s); 703 error=GSM_TerminateConnection(&s);
720 704
721 return true; 705 return true;
722} 706}
723 707
724bool PhoneFormat::save( Calendar *calendar) 708bool PhoneFormat::save( Calendar *calendar)
725{ 709{
726#if 0 710#if 0
727 QLabel status ( i18n("Processing/adding events ..."), 0 ); 711 QLabel status ( i18n("Processing/adding events ..."), 0 );
728 int w = status.sizeHint().width()+20 ; 712 int w = status.sizeHint().width()+20 ;
729 if ( w < 200 ) w = 200; 713 if ( w < 200 ) w = 200;
730 int h = status.sizeHint().height()+20 ; 714 int h = status.sizeHint().height()+20 ;
731 int dw = QApplication::desktop()->width(); 715 int dw = QApplication::desktop()->width();
732 int dh = QApplication::desktop()->height(); 716 int dh = QApplication::desktop()->height();
733 status.setCaption(i18n("Writing DTM Data") ); 717 status.setCaption(i18n("Writing DTM Data") );
734 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 718 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
735 status.show(); 719 status.show();
736 status.raise(); 720 status.raise();
737 qApp->processEvents(); 721 qApp->processEvents();
738 bool debug = DEBUGMODE; 722 bool debug = DEBUGMODE;
739 QString codec = "utf8"; 723 QString codec = "utf8";
740 QString answer; 724 QString answer;
741 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 725 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
742 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 726 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
743 QString command; 727 QString command;
744 QPtrList<Event> er = calendar->rawEvents(); 728 QPtrList<Event> er = calendar->rawEvents();
745 Event* ev = er.first(); 729 Event* ev = er.first();
746 QString fileName = "/tmp/kopitempout"; 730 QString fileName = "/tmp/kopitempout";
747 int i = 0; 731 int i = 0;
748 QString changeString = ePrefix; 732 QString changeString = ePrefix;
749 QString deleteString = ePrefix; 733 QString deleteString = ePrefix;
750 bool deleteEnt = false; 734 bool deleteEnt = false;
751 bool changeEnt = false; 735 bool changeEnt = false;
752 QString message = i18n("Processing event # "); 736 QString message = i18n("Processing event # ");
753 int procCount = 0; 737 int procCount = 0;
754 while ( ev ) { 738 while ( ev ) {
755 //qDebug("i %d ", ++i); 739 //qDebug("i %d ", ++i);
756 if ( true /*ev->zaurusStat() != -2*/ ) { 740 if ( true /*ev->zaurusStat() != -2*/ ) {
757 status.setText ( message + QString::number ( ++procCount ) ); 741 status.setText ( message + QString::number ( ++procCount ) );
758 qApp->processEvents(); 742 qApp->processEvents();
759 QString eString = getEventString( ev ); 743 QString eString = getEventString( ev );
760 if (/* ev->zaurusStat() == -3 */ true) { // delete 744 if (/* ev->zaurusStat() == -3 */ true) { // delete
761 // deleting empty strings does not work. 745 // deleting empty strings does not work.
762 // we write first and x and then delete the record with the x 746 // we write first and x and then delete the record with the x
763 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 747 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
764 changeString += eString + "\n"; 748 changeString += eString + "\n";
765 deleteString += eString + "\n"; 749 deleteString += eString + "\n";
766 deleteEnt = true; 750 deleteEnt = true;
767 changeEnt = true; 751 changeEnt = true;
768 } 752 }
769 else if ( /*ev->zaurusId() == -1*/true ) { // add new 753 else if ( /*ev->zaurusId() == -1*/true ) { // add new
770 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 754 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
771 system ( command.utf8() ); 755 system ( command.utf8() );
772 QFile file( fileName ); 756 QFile file( fileName );
773 if (!file.open( IO_ReadOnly ) ) { 757 if (!file.open( IO_ReadOnly ) ) {
774 return false; 758 return false;
775 759
776 } 760 }
777 QTextStream ts( &file ); 761 QTextStream ts( &file );
778 ts.setCodec( QTextCodec::codecForName("utf8") ); 762 ts.setCodec( QTextCodec::codecForName("utf8") );
779 answer = ts.read(); 763 answer = ts.read();
780 file.close(); 764 file.close();
781 //qDebug("answer \n%s ", answer.latin1()); 765 //qDebug("answer \n%s ", answer.latin1());
782 getNumFromRecord( answer, ev ) ; 766 getNumFromRecord( answer, ev ) ;
783 767
784 } 768 }
785 else { // change existing 769 else { // change existing
786 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 770 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
787 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 771 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
788 changeString += eString + "\n"; 772 changeString += eString + "\n";
789 changeEnt = true; 773 changeEnt = true;
790 774
791 } 775 }
792 } 776 }
793 ev = er.next(); 777 ev = er.next();
794 } 778 }
795 status.setText ( i18n("Changing events ...") ); 779 status.setText ( i18n("Changing events ...") );
796 qApp->processEvents(); 780 qApp->processEvents();
797 //qDebug("changing... "); 781 //qDebug("changing... ");
798 if ( changeEnt ) { 782 if ( changeEnt ) {
799 QFile file( fileName ); 783 QFile file( fileName );
800 if (!file.open( IO_WriteOnly ) ) { 784 if (!file.open( IO_WriteOnly ) ) {
801 return false; 785 return false;
802 786
803 } 787 }
804 QTextStream ts( &file ); 788 QTextStream ts( &file );
805 ts.setCodec( QTextCodec::codecForName("utf8") ); 789 ts.setCodec( QTextCodec::codecForName("utf8") );
806 ts << changeString ; 790 ts << changeString ;
807 file.close(); 791 file.close();
808 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 792 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
809 system ( command.latin1() ); 793 system ( command.latin1() );
810 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 794 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
811 795
812 } 796 }
813 status.setText ( i18n("Deleting events ...") ); 797 status.setText ( i18n("Deleting events ...") );
814 qApp->processEvents(); 798 qApp->processEvents();
815 //qDebug("deleting... "); 799 //qDebug("deleting... ");
816 if ( deleteEnt ) { 800 if ( deleteEnt ) {
817 QFile file( fileName ); 801 QFile file( fileName );
818 if (!file.open( IO_WriteOnly ) ) { 802 if (!file.open( IO_WriteOnly ) ) {
819 return false; 803 return false;
820 804
821 } 805 }
822 QTextStream ts( &file ); 806 QTextStream ts( &file );
823 ts.setCodec( QTextCodec::codecForName("utf8") ); 807 ts.setCodec( QTextCodec::codecForName("utf8") );
824 ts << deleteString; 808 ts << deleteString;
825 file.close(); 809 file.close();
826 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 810 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
827 system ( command.latin1() ); 811 system ( command.latin1() );
828 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 812 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
829 } 813 }
830 814
831 815
832 changeString = tPrefix; 816 changeString = tPrefix;
833 deleteString = tPrefix; 817 deleteString = tPrefix;
834 status.setText ( i18n("Processing todos ...") ); 818 status.setText ( i18n("Processing todos ...") );
835 qApp->processEvents(); 819 qApp->processEvents();
836 QPtrList<Todo> tl = calendar->rawTodos(); 820 QPtrList<Todo> tl = calendar->rawTodos();
837 Todo* to = tl.first(); 821 Todo* to = tl.first();
838 i = 0; 822 i = 0;
839 message = i18n("Processing todo # "); 823 message = i18n("Processing todo # ");
840 procCount = 0; 824 procCount = 0;
841 while ( to ) { 825 while ( to ) {
842 if ( true /*to->zaurusStat() != -2 */) { 826 if ( true /*to->zaurusStat() != -2 */) {