summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 22:05:14 (UTC)
committer zautrix <zautrix>2004-09-12 22:05:14 (UTC)
commit483c6ac49ea1764bdd154e33e220b7945a6ab754 (patch) (unidiff)
tree29d5cb00ff3a36595c2fb0e1125d3e2b8ec246a6
parent185e2f4a2b10c65d8186dad63fe6cc3acd6b84f1 (diff)
downloadkdepimpi-483c6ac49ea1764bdd154e33e220b7945a6ab754.zip
kdepimpi-483c6ac49ea1764bdd154e33e220b7945a6ab754.tar.gz
kdepimpi-483c6ac49ea1764bdd154e33e220b7945a6ab754.tar.bz2
fix for Z
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 99d6a06..c67dc6a 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,724 +1,732 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 4 Copyright (c) 2004 Lutz Rogowski <rogowski@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 <qdir.h> 32#include <qdir.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#include <kmessagebox.h> 38#include <kmessagebox.h>
39 39
40#include "calendar.h" 40#include "calendar.h"
41#include "alarm.h" 41#include "alarm.h"
42#include "recurrence.h" 42#include "recurrence.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44 44
45#include "phoneformat.h" 45#include "phoneformat.h"
46#include "syncdefines.h" 46#include "syncdefines.h"
47 47
48using namespace KCal; 48using namespace KCal;
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( ) { 52 PhoneParser( ) {
53 ; 53 ;
54 } 54 }
55 55
56 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 56 static QString dtToString( const QDateTime& dti, bool useTZ = false )
57 { 57 {
58 QString datestr; 58 QString datestr;
59 QString timestr; 59 QString timestr;
60 int offset = KGlobal::locale()->localTimeOffset( dti ); 60 int offset = KGlobal::locale()->localTimeOffset( dti );
61 QDateTime dt; 61 QDateTime dt;
62 if (useTZ) 62 if (useTZ)
63 dt = dti.addSecs ( -(offset*60)); 63 dt = dti.addSecs ( -(offset*60));
64 else 64 else
65 dt = dti; 65 dt = dti;
66 if(dt.date().isValid()){ 66 if(dt.date().isValid()){
67 const QDate& date = dt.date(); 67 const QDate& date = dt.date();
68 datestr.sprintf("%04d%02d%02d", 68 datestr.sprintf("%04d%02d%02d",
69 date.year(), date.month(), date.day()); 69 date.year(), date.month(), date.day());
70 } 70 }
71 if(dt.time().isValid()){ 71 if(dt.time().isValid()){
72 const QTime& time = dt.time(); 72 const QTime& time = dt.time();
73 timestr.sprintf("T%02d%02d%02d", 73 timestr.sprintf("T%02d%02d%02d",
74 time.hour(), time.minute(), time.second()); 74 time.hour(), time.minute(), time.second());
75 } 75 }
76 return datestr + timestr; 76 return datestr + timestr;
77 } 77 }
78 78
79 79
80}; 80};
81 81
82 82
83 83
84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
85{ 85{
86 mProfileName = profileName; 86 mProfileName = profileName;
87 87
88 QString fileName = QDir::homeDirPath() +"/.gammurc"; 88 QString fileName = QDir::homeDirPath() +"/.gammurc";
89 //qDebug("save %d ", load ); 89 //qDebug("save %d ", load );
90 QString content; 90 QString content;
91 bool write = false; 91 bool write = false;
92 bool addPort = true, addConnection = true, addModel = true; 92 bool addPort = true, addConnection = true, addModel = true;
93 QFile file( fileName ); 93 QFile file( fileName );
94 if ( QFile::exists( fileName) ) { 94 if ( QFile::exists( fileName) ) {
95 if (!file.open( IO_ReadOnly ) ) { 95 if (!file.open( IO_ReadOnly ) ) {
96 qDebug("Error: cannot open %s ", fileName.latin1() ); 96 qDebug("Error: cannot open %s ", fileName.latin1() );
97 return; 97 return;
98 } 98 }
99 QString line; 99 QString line;
100 while ( file.readLine( line, 1024 ) > 0 ) { 100 while ( file.readLine( line, 1024 ) > 0 ) {
101 //qDebug("*%s* ", line.latin1() ); 101 //qDebug("*%s* ", line.latin1() );
102 if ( line.left(7 ) == "[gammu]" ) { 102 if ( line.left(7 ) == "[gammu]" ) {
103 ; 103 ;
104 } else 104 } else
105 if ( line.left(4 ) == "port" ) { 105 if ( line.left(4 ) == "port" ) {
106 if ( line == "port = " + device+"\n" ) { 106 if ( line == "port = " + device+"\n" ) {
107 content += line ; 107 content += line ;
108 addPort = false; 108 addPort = false;
109 //qDebug("port found" ); 109 //qDebug("port found" );
110 } 110 }
111 111
112 } else if ( line.left(5 ) == "model" ) { 112 } else if ( line.left(5 ) == "model" ) {
113 if ( line == "model = " + model +"\n") { 113 if ( line == "model = " + model +"\n") {
114 content += line ; 114 content += line ;
115 addModel = false; 115 addModel = false;
116 //qDebug("model found" ); 116 //qDebug("model found" );
117 } 117 }
118 118
119 } else if ( line.left( 10 ) == "connection" ) { 119 } else if ( line.left( 10 ) == "connection" ) {
120 if ( line == "connection = " + connection +"\n") { 120 if ( line == "connection = " + connection +"\n") {
121 addConnection = false; 121 addConnection = false;
122 content += line ; 122 content += line ;
123 //qDebug("con found" ); 123 //qDebug("con found" );
124 } 124 }
125 125
126 } else { 126 } else {
127 content += line ; 127 content += line ;
128 } 128 }
129 } 129 }
130 file.close(); 130 file.close();
131 } else { 131 } else {
132 if ( ! connection.isEmpty() ) { 132 if ( ! connection.isEmpty() ) {
133 addConnection = true; 133 addConnection = true;
134 } 134 }
135 if ( ! device.isEmpty() ) { 135 if ( ! device.isEmpty() ) {
136 addPort = true; 136 addPort = true;
137 137
138 } 138 }
139 if ( ! model.isEmpty() ) { 139 if ( ! model.isEmpty() ) {
140 addModel = true; 140 addModel = true;
141 } 141 }
142 } 142 }
143 143
144 if ( addConnection ) { 144 if ( addConnection ) {
145 if ( ! write ) 145 if ( ! write )
146 content += "[gammu]\n"; 146 content += "[gammu]\n";
147 write = true; 147 write = true;
148 content += "connection = "; 148 content += "connection = ";
149 content += connection; 149 content += connection;
150 content += "\n"; 150 content += "\n";
151 } 151 }
152 if ( addPort ) { 152 if ( addPort ) {
153 if ( ! write ) 153 if ( ! write )
154 content += "[gammu]\n"; 154 content += "[gammu]\n";
155 write = true; 155 write = true;
156 content += "port = "; 156 content += "port = ";
157 content += device; 157 content += device;
158 content += "\n"; 158 content += "\n";
159 159
160 } 160 }
161 if ( addModel ) { 161 if ( addModel ) {
162 if ( ! write ) 162 if ( ! write )
163 content += "[gammu]\n"; 163 content += "[gammu]\n";
164 write = true; 164 write = true;
165 content += "model = "; 165 content += "model = ";
166 content += model; 166 content += model;
167 content += "\n"; 167 content += "\n";
168 } 168 }
169 if ( write ) { 169 if ( write ) {
170 if (!file.open( IO_WriteOnly ) ) { 170 if (!file.open( IO_WriteOnly ) ) {
171 qDebug("Error: cannot write file %s ", fileName.latin1() ); 171 qDebug("Error: cannot write file %s ", fileName.latin1() );
172 return; 172 return;
173 } 173 }
174 qDebug("Writing file %s ", fileName.latin1() ); 174 qDebug("Writing file %s ", fileName.latin1() );
175 QTextStream ts( &file ); 175 QTextStream ts( &file );
176 ts << content ; 176 ts << content ;
177 file.close(); 177 file.close();
178 } 178 }
179} 179}
180 180
181PhoneFormat::~PhoneFormat() 181PhoneFormat::~PhoneFormat()
182{ 182{
183} 183}
184#if 0 184#if 0
185int PhoneFormat::initDevice(GSM_StateMachine *s) 185int PhoneFormat::initDevice(GSM_StateMachine *s)
186{ 186{
187 GSM_ReadConfig(NULL, &s->Config[0], 0); 187 GSM_ReadConfig(NULL, &s->Config[0], 0);
188 s->ConfigNum = 1; 188 s->ConfigNum = 1;
189 GSM_Config *cfg = &s->Config[0]; 189 GSM_Config *cfg = &s->Config[0];
190 if ( ! mConnection.isEmpty() ) { 190 if ( ! mConnection.isEmpty() ) {
191 cfg->Connection = strdup(mConnection.latin1()); 191 cfg->Connection = strdup(mConnection.latin1());
192 cfg->DefaultConnection = false; 192 cfg->DefaultConnection = false;
193 qDebug("Connection set %s ", cfg->Connection ); 193 qDebug("Connection set %s ", cfg->Connection );
194 194
195 } 195 }
196 if ( ! mDevice.isEmpty() ) { 196 if ( ! mDevice.isEmpty() ) {
197 cfg->Device = strdup(mDevice.latin1()); 197 cfg->Device = strdup(mDevice.latin1());
198 cfg->DefaultDevice = false; 198 cfg->DefaultDevice = false;
199 qDebug("Device set %s ", cfg->Device); 199 qDebug("Device set %s ", cfg->Device);
200 200
201 } 201 }
202 if ( ! mModel.isEmpty() ) { 202 if ( ! mModel.isEmpty() ) {
203 strcpy(cfg->Model,mModel.latin1() ); 203 strcpy(cfg->Model,mModel.latin1() );
204 cfg->DefaultModel = false; 204 cfg->DefaultModel = false;
205 qDebug("Model set %s ",cfg->Model ); 205 qDebug("Model set %s ",cfg->Model );
206 } 206 }
207 int error=GSM_InitConnection(s,3); 207 int error=GSM_InitConnection(s,3);
208 return error; 208 return error;
209} 209}
210#endif 210#endif
211ulong PhoneFormat::getCsumTodo( Todo* todo ) 211ulong PhoneFormat::getCsumTodo( Todo* todo )
212{ 212{
213 QStringList attList; 213 QStringList attList;
214 if ( todo->hasDueDate() ) 214 if ( todo->hasDueDate() )
215 attList << PhoneParser::dtToString ( todo->dtDue() ); 215 attList << PhoneParser::dtToString ( todo->dtDue() );
216 attList << todo->summary(); 216 attList << todo->summary();
217 QString completedString = "no"; 217 QString completedString = "no";
218 if ( todo->isCompleted() ) 218 if ( todo->isCompleted() )
219 completedString = "yes"; 219 completedString = "yes";
220 attList << completedString; 220 attList << completedString;
221 int prio = todo->priority(); 221 int prio = todo->priority();
222 if( prio == 2 ) prio = 1; 222 if( prio == 2 ) prio = 1;
223 if (prio == 4 ) prio = 5 ; 223 if (prio == 4 ) prio = 5 ;
224 attList << QString::number( prio ); 224 attList << QString::number( prio );
225 QString alarmString = "na"; 225 QString alarmString = "na";
226 Alarm *alarm; 226 Alarm *alarm;
227 if ( todo->alarms().count() > 0 ) { 227 if ( todo->alarms().count() > 0 ) {
228 alarm = todo->alarms().first(); 228 alarm = todo->alarms().first();
229 if ( alarm->enabled() ) { 229 if ( alarm->enabled() ) {
230 alarmString = QString::number(alarm->offset() ); 230 alarmString = QString::number(alarm->offset() );
231 } 231 }
232 } 232 }
233 attList << alarmString; 233 attList << alarmString;
234 attList << todo->categoriesStr(); 234 attList << todo->categoriesStr();
235 attList << todo->secrecyStr(); 235 attList << todo->secrecyStr();
236 return PhoneFormat::getCsum(attList ); 236 return PhoneFormat::getCsum(attList );
237 237
238} 238}
239ulong PhoneFormat::getCsumEvent( Event* event ) 239ulong PhoneFormat::getCsumEvent( Event* event )
240{ 240{
241 QStringList attList; 241 QStringList attList;
242 attList << PhoneParser::dtToString ( event->dtStart() ); 242 attList << PhoneParser::dtToString ( event->dtStart() );
243 attList << PhoneParser::dtToString ( event->dtEnd() ); 243 attList << PhoneParser::dtToString ( event->dtEnd() );
244 attList << event->summary(); 244 attList << event->summary();
245 attList << event->location(); 245 attList << event->location();
246 QString alarmString = "na"; 246 QString alarmString = "na";
247 Alarm *alarm; 247 Alarm *alarm;
248 if ( event->alarms().count() > 0 ) { 248 if ( event->alarms().count() > 0 ) {
249 alarm = event->alarms().first(); 249 alarm = event->alarms().first();
250 if ( alarm->enabled() ) { 250 if ( alarm->enabled() ) {
251 alarmString = QString::number( alarm->offset() ); 251 alarmString = QString::number( alarm->offset() );
252 } 252 }
253 } 253 }
254 attList << alarmString; 254 attList << alarmString;
255 Recurrence* rec = event->recurrence(); 255 Recurrence* rec = event->recurrence();
256 QStringList list; 256 QStringList list;
257 bool writeEndDate = false; 257 bool writeEndDate = false;
258 switch ( rec->doesRecur() ) 258 switch ( rec->doesRecur() )
259 { 259 {
260 case Recurrence::rDaily: // 0 260 case Recurrence::rDaily: // 0
261 list.append( "0" ); 261 list.append( "0" );
262 list.append( QString::number( rec->frequency() ));//12 262 list.append( QString::number( rec->frequency() ));//12
263 list.append( "0" ); 263 list.append( "0" );
264 list.append( "0" ); 264 list.append( "0" );
265 writeEndDate = true; 265 writeEndDate = true;
266 break; 266 break;
267 case Recurrence::rWeekly:// 1 267 case Recurrence::rWeekly:// 1
268 list.append( "1" ); 268 list.append( "1" );
269 list.append( QString::number( rec->frequency()) );//12 269 list.append( QString::number( rec->frequency()) );//12
270 list.append( "0" ); 270 list.append( "0" );
271 { 271 {
272 int days = 0; 272 int days = 0;
273 QBitArray weekDays = rec->days(); 273 QBitArray weekDays = rec->days();
274 int i; 274 int i;
275 for( i = 1; i <= 7; ++i ) { 275 for( i = 1; i <= 7; ++i ) {
276 if ( weekDays[i-1] ) { 276 if ( weekDays[i-1] ) {
277 days += 1 << (i-1); 277 days += 1 << (i-1);
278 } 278 }
279 } 279 }
280 list.append( QString::number( days ) ); 280 list.append( QString::number( days ) );
281 } 281 }
282 //pending weekdays 282 //pending weekdays
283 writeEndDate = true; 283 writeEndDate = true;
284 284
285 break; 285 break;
286 case Recurrence::rMonthlyPos:// 2 286 case Recurrence::rMonthlyPos:// 2
287 list.append( "2" ); 287 list.append( "2" );
288 list.append( QString::number( rec->frequency()) );//12 288 list.append( QString::number( rec->frequency()) );//12
289 289
290 writeEndDate = true; 290 writeEndDate = true;
291 { 291 {
292 int count = 1; 292 int count = 1;
293 QPtrList<Recurrence::rMonthPos> rmp; 293 QPtrList<Recurrence::rMonthPos> rmp;
294 rmp = rec->monthPositions(); 294 rmp = rec->monthPositions();
295 if ( rmp.first()->negative ) 295 if ( rmp.first()->negative )
296 count = 5 - rmp.first()->rPos - 1; 296 count = 5 - rmp.first()->rPos - 1;
297 else 297 else
298 count = rmp.first()->rPos - 1; 298 count = rmp.first()->rPos - 1;
299 list.append( QString::number( count ) ); 299 list.append( QString::number( count ) );
300 300
301 } 301 }
302 302
303 list.append( "0" ); 303 list.append( "0" );
304 break; 304 break;
305 case Recurrence::rMonthlyDay:// 3 305 case Recurrence::rMonthlyDay:// 3
306 list.append( "3" ); 306 list.append( "3" );
307 list.append( QString::number( rec->frequency()) );//12 307 list.append( QString::number( rec->frequency()) );//12
308 list.append( "0" ); 308 list.append( "0" );
309 list.append( "0" ); 309 list.append( "0" );
310 writeEndDate = true; 310 writeEndDate = true;
311 break; 311 break;
312 case Recurrence::rYearlyMonth://4 312 case Recurrence::rYearlyMonth://4
313 list.append( "4" ); 313 list.append( "4" );
314 list.append( QString::number( rec->frequency()) );//12 314 list.append( QString::number( rec->frequency()) );//12
315 list.append( "0" ); 315 list.append( "0" );
316 list.append( "0" ); 316 list.append( "0" );
317 writeEndDate = true; 317 writeEndDate = true;
318 break; 318 break;
319 319
320 default: 320 default:
321 list.append( "255" ); 321 list.append( "255" );
322 list.append( QString() ); 322 list.append( QString() );
323 list.append( "0" ); 323 list.append( "0" );
324 list.append( QString() ); 324 list.append( QString() );
325 list.append( "0" ); 325 list.append( "0" );
326 list.append( "20991231T000000" ); 326 list.append( "20991231T000000" );
327 break; 327 break;
328 } 328 }
329 if ( writeEndDate ) { 329 if ( writeEndDate ) {
330 330
331 if ( rec->endDate().isValid() ) { // 15 + 16 331 if ( rec->endDate().isValid() ) { // 15 + 16
332 list.append( "1" ); 332 list.append( "1" );
333 list.append( PhoneParser::dtToString( rec->endDate()) ); 333 list.append( PhoneParser::dtToString( rec->endDate()) );
334 } else { 334 } else {
335 list.append( "0" ); 335 list.append( "0" );
336 list.append( "20991231T000000" ); 336 list.append( "20991231T000000" );
337 } 337 }
338 338
339 } 339 }
340 attList << list.join(""); 340 attList << list.join("");
341 attList << event->categoriesStr(); 341 attList << event->categoriesStr();
342 //qDebug("csum cat %s", event->categoriesStr().latin1()); 342 //qDebug("csum cat %s", event->categoriesStr().latin1());
343 343
344 attList << event->secrecyStr(); 344 attList << event->secrecyStr();
345 return PhoneFormat::getCsum(attList ); 345 return PhoneFormat::getCsum(attList );
346} 346}
347ulong PhoneFormat::getCsum( const QStringList & attList) 347ulong PhoneFormat::getCsum( const QStringList & attList)
348{ 348{
349 int max = attList.count(); 349 int max = attList.count();
350 ulong cSum = 0; 350 ulong cSum = 0;
351 int j,k,i; 351 int j,k,i;
352 int add; 352 int add;
353 for ( i = 0; i < max ; ++i ) { 353 for ( i = 0; i < max ; ++i ) {
354 QString s = attList[i]; 354 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
356 j = s.length(); 356 j = s.length();
357 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 358 int mul = k +1;
359 add = s[k].unicode (); 359 add = s[k].unicode ();
360 if ( k < 16 ) 360 if ( k < 16 )
361 mul = mul * mul; 361 mul = mul * mul;
362 int ii = i+1; 362 int ii = i+1;
363 add = add * mul *ii*ii*ii; 363 add = add * mul *ii*ii*ii;
364 cSum += add; 364 cSum += add;
365 } 365 }
366 } 366 }
367 367
368 } 368 }
369 //QString dump = attList.join(","); 369 //QString dump = attList.join(",");
370 //qDebug("csum: %d %s", cSum,dump.latin1()); 370 //qDebug("csum: %d %s", cSum,dump.latin1());
371 371
372 return cSum; 372 return cSum;
373 373
374} 374}
375//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 375//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
376#include <stdlib.h> 376#include <stdlib.h>
377#define DEBUGMODE false 377#define DEBUGMODE false
378bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 378bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
379{ 379{
380 380
381 QString fileName; 381 QString fileName;
382#ifdef _WIN32_ 382#ifdef _WIN32_
383 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 383 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
384#else 384#else
385 fileName = "/tmp/kdepimtemp.vcs"; 385 fileName = "/tmp/kdepimtemp.vcs";
386#endif 386#endif
387#ifdef DESKTOP_VERSION
387 QString command ="./kammu --backup " + fileName + " -yes" ; 388 QString command ="./kammu --backup " + fileName + " -yes" ;
389#else
390 QString command ="kammu --backup " + fileName + " -yes" ;
391#endif
388 int ret = system ( command.latin1() ); 392 int ret = system ( command.latin1() );
389 if ( ret != 0 ) { 393 if ( ret != 0 ) {
390 qDebug("Error::command returned %d", ret); 394 qDebug("Error::command returned %d", ret);
391 return false; 395 return false;
392 } 396 }
393 VCalFormat vfload; 397 VCalFormat vfload;
394 vfload.setLocalTime ( true ); 398 vfload.setLocalTime ( true );
395 qDebug("loading file ..."); 399 qDebug("loading file ...");
396 400
397 if ( ! vfload.load( calendar, fileName ) ) 401 if ( ! vfload.load( calendar, fileName ) )
398 return false; 402 return false;
399 QPtrList<Event> er = calendar->rawEvents(); 403 QPtrList<Event> er = calendar->rawEvents();
400 Event* ev = er.first(); 404 Event* ev = er.first();
401 qDebug("reading events... "); 405 qDebug("reading events... ");
402 while ( ev ) { 406 while ( ev ) {
403 QStringList cat = ev->categories(); 407 QStringList cat = ev->categories();
404 if ( cat.contains( "MeetingDEF" )) { 408 if ( cat.contains( "MeetingDEF" )) {
405 ev->setCategories( QStringList() ); 409 ev->setCategories( QStringList() );
406 } 410 }
407 int id = ev->pilotId(); 411 int id = ev->pilotId();
408 Event *event; 412 Event *event;
409 event = existingCal->event( mProfileName ,QString::number( id ) ); 413 event = existingCal->event( mProfileName ,QString::number( id ) );
410 if ( event ) { 414 if ( event ) {
411 event = (Event*)event->clone(); 415 event = (Event*)event->clone();
412 copyEvent( event, ev ); 416 copyEvent( event, ev );
413 calendar->deleteEvent( ev ); 417 calendar->deleteEvent( ev );
414 calendar->addEvent( event); 418 calendar->addEvent( event);
415 } 419 }
416 else 420 else
417 event = ev; 421 event = ev;
418 uint cSum; 422 uint cSum;
419 cSum = PhoneFormat::getCsumEvent( event ); 423 cSum = PhoneFormat::getCsumEvent( event );
420 event->setCsum( mProfileName, QString::number( cSum )); 424 event->setCsum( mProfileName, QString::number( cSum ));
421 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 425 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
422 event->setID( mProfileName,QString::number( id ) ); 426 event->setID( mProfileName,QString::number( id ) );
423 ev = er.next(); 427 ev = er.next();
424 } 428 }
425 { 429 {
426 qDebug("reading todos... "); 430 qDebug("reading todos... ");
427 QPtrList<Todo> tr = calendar->rawTodos(); 431 QPtrList<Todo> tr = calendar->rawTodos();
428 Todo* ev = tr.first(); 432 Todo* ev = tr.first();
429 while ( ev ) { 433 while ( ev ) {
430 434
431 QStringList cat = ev->categories(); 435 QStringList cat = ev->categories();
432 if ( cat.contains( "MeetingDEF" )) { 436 if ( cat.contains( "MeetingDEF" )) {
433 ev->setCategories( QStringList() ); 437 ev->setCategories( QStringList() );
434 } 438 }
435 int id = ev->pilotId(); 439 int id = ev->pilotId();
436 Todo *event; 440 Todo *event;
437 event = existingCal->todo( mProfileName ,QString::number( id ) ); 441 event = existingCal->todo( mProfileName ,QString::number( id ) );
438 if ( event ) { 442 if ( event ) {
439 //qDebug("copy todo %s ", event->summary().latin1()); 443 //qDebug("copy todo %s ", event->summary().latin1());
440 444
441 event = (Todo*)event->clone(); 445 event = (Todo*)event->clone();
442 copyTodo( event, ev ); 446 copyTodo( event, ev );
443 calendar->deleteTodo( ev ); 447 calendar->deleteTodo( ev );
444 calendar->addTodo( event); 448 calendar->addTodo( event);
445 } 449 }
446 else 450 else
447 event = ev; 451 event = ev;
448 uint cSum; 452 uint cSum;
449 cSum = PhoneFormat::getCsumTodo( event ); 453 cSum = PhoneFormat::getCsumTodo( event );
450 event->setCsum( mProfileName, QString::number( cSum )); 454 event->setCsum( mProfileName, QString::number( cSum ));
451 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 455 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
452 event->setID( mProfileName,QString::number( id ) ); 456 event->setID( mProfileName,QString::number( id ) );
453 ev = tr.next(); 457 ev = tr.next();
454 } 458 }
455 } 459 }
456 return true; 460 return true;
457} 461}
458void PhoneFormat::copyEvent( Event* to, Event* from ) 462void PhoneFormat::copyEvent( Event* to, Event* from )
459{ 463{
460 if ( from->dtStart().isValid() ) 464 if ( from->dtStart().isValid() )
461 to->setDtStart( from->dtStart() ); 465 to->setDtStart( from->dtStart() );
462 if ( from->dtEnd().isValid() ) 466 if ( from->dtEnd().isValid() )
463 to->setDtEnd( from->dtEnd() ); 467 to->setDtEnd( from->dtEnd() );
464 if ( !from->location().isEmpty() ) 468 if ( !from->location().isEmpty() )
465 to->setLocation( from->location() ); 469 to->setLocation( from->location() );
466 if ( !from->description().isEmpty() ) 470 if ( !from->description().isEmpty() )
467 to->setDescription( from->description() ); 471 to->setDescription( from->description() );
468 if ( !from->summary().isEmpty() ) 472 if ( !from->summary().isEmpty() )
469 to->setSummary( from->summary() ); 473 to->setSummary( from->summary() );
470 474
471 if ( from->alarms().count() ) { 475 if ( from->alarms().count() ) {
472 to->clearAlarms(); 476 to->clearAlarms();
473 Alarm *a = from->alarms().first(); 477 Alarm *a = from->alarms().first();
474 Alarm *b = to->newAlarm( ); 478 Alarm *b = to->newAlarm( );
475 b->setEnabled( a->enabled() ); 479 b->setEnabled( a->enabled() );
476 if ( a->hasStartOffset() ) { 480 if ( a->hasStartOffset() ) {
477 b->setStartOffset( a->startOffset() ); 481 b->setStartOffset( a->startOffset() );
478 } 482 }
479 if ( a->hasTime() ) 483 if ( a->hasTime() )
480 b->setTime( a->time() ); 484 b->setTime( a->time() );
481 485
482 } 486 }
483 QStringList cat = to->categories(); 487 QStringList cat = to->categories();
484 QStringList catFrom = from->categories(); 488 QStringList catFrom = from->categories();
485 QString nCat; 489 QString nCat;
486 int iii; 490 int iii;
487 for ( iii = 0; iii < catFrom.count();++iii ) { 491 for ( iii = 0; iii < catFrom.count();++iii ) {
488 nCat = catFrom[iii]; 492 nCat = catFrom[iii];
489 if ( !nCat.isEmpty() ) 493 if ( !nCat.isEmpty() )
490 if ( !cat.contains( nCat )) { 494 if ( !cat.contains( nCat )) {
491 cat << nCat; 495 cat << nCat;
492 } 496 }
493 } 497 }
494 to->setCategories( cat ); 498 to->setCategories( cat );
495 Recurrence * r = new Recurrence( *from->recurrence(),to); 499 Recurrence * r = new Recurrence( *from->recurrence(),to);
496 to->setRecurrence( r ) ; 500 to->setRecurrence( r ) ;
497 501
498 502
499} 503}
500void PhoneFormat::copyTodo( Todo* to, Todo* from ) 504void PhoneFormat::copyTodo( Todo* to, Todo* from )
501{ 505{
502 if ( from->dtStart().isValid() ) 506 if ( from->dtStart().isValid() )
503 to->setDtStart( from->dtStart() ); 507 to->setDtStart( from->dtStart() );
504 if ( from->dtDue().isValid() ) 508 if ( from->dtDue().isValid() )
505 to->setDtDue( from->dtDue() ); 509 to->setDtDue( from->dtDue() );
506 if ( !from->location().isEmpty() ) 510 if ( !from->location().isEmpty() )
507 to->setLocation( from->location() ); 511 to->setLocation( from->location() );
508 if ( !from->description().isEmpty() ) 512 if ( !from->description().isEmpty() )
509 to->setDescription( from->description() ); 513 to->setDescription( from->description() );
510 if ( !from->summary().isEmpty() ) 514 if ( !from->summary().isEmpty() )
511 to->setSummary( from->summary() ); 515 to->setSummary( from->summary() );
512 516
513 if ( from->alarms().count() ) { 517 if ( from->alarms().count() ) {
514 to->clearAlarms(); 518 to->clearAlarms();
515 Alarm *a = from->alarms().first(); 519 Alarm *a = from->alarms().first();
516 Alarm *b = to->newAlarm( ); 520 Alarm *b = to->newAlarm( );
517 b->setEnabled( a->enabled() ); 521 b->setEnabled( a->enabled() );
518 if ( a->hasStartOffset() ) 522 if ( a->hasStartOffset() )
519 b->setStartOffset( a->startOffset() ); 523 b->setStartOffset( a->startOffset() );
520 if ( a->hasTime() ) 524 if ( a->hasTime() )
521 b->setTime( a->time() ); 525 b->setTime( a->time() );
522 } 526 }
523 527
524 QStringList cat = to->categories(); 528 QStringList cat = to->categories();
525 QStringList catFrom = from->categories(); 529 QStringList catFrom = from->categories();
526 QString nCat; 530 QString nCat;
527 int iii; 531 int iii;
528 for ( iii = 0; iii < catFrom.count();++iii ) { 532 for ( iii = 0; iii < catFrom.count();++iii ) {
529 nCat = catFrom[iii]; 533 nCat = catFrom[iii];
530 if ( !nCat.isEmpty() ) 534 if ( !nCat.isEmpty() )
531 if ( !cat.contains( nCat )) { 535 if ( !cat.contains( nCat )) {
532 cat << nCat; 536 cat << nCat;
533 } 537 }
534 } 538 }
535 to->setCategories( cat ); 539 to->setCategories( cat );
536 if ( from->isCompleted() ) { 540 if ( from->isCompleted() ) {
537 to->setCompleted( true ); 541 to->setCompleted( true );
538 if( from->completed().isValid() ) 542 if( from->completed().isValid() )
539 to->setCompleted( from->completed() ); 543 to->setCompleted( from->completed() );
540 } else { 544 } else {
541 // set percentcomplete only, if to->isCompleted() 545 // set percentcomplete only, if to->isCompleted()
542 if ( to->isCompleted() ) 546 if ( to->isCompleted() )
543 to->setPercentComplete(from->percentComplete()); 547 to->setPercentComplete(from->percentComplete());
544 } 548 }
545 if( to->priority() == 2 && from->priority() == 1 ) 549 if( to->priority() == 2 && from->priority() == 1 )
546 ; //skip 550 ; //skip
547 else if (to->priority() == 4 && from->priority() == 5 ) 551 else if (to->priority() == 4 && from->priority() == 5 )
548 ; 552 ;
549 else 553 else
550 to->setPriority(from->priority()); 554 to->setPriority(from->priority());
551 555
552} 556}
553#include <qcstring.h> 557#include <qcstring.h>
554 558
555void PhoneFormat::afterSave( Incidence* inc) 559void PhoneFormat::afterSave( Incidence* inc)
556{ 560{
557 uint csum; 561 uint csum;
558 inc->removeID( mProfileName ); 562 inc->removeID( mProfileName );
559 if ( inc->type() == "Event") 563 if ( inc->type() == "Event")
560 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 564 csum = PhoneFormat::getCsumEvent( (Event*) inc );
561 else 565 else
562 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 566 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
563 inc->setCsum( mProfileName, QString::number( csum )); 567 inc->setCsum( mProfileName, QString::number( csum ));
564 568
565 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 569 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
566 570
567} 571}
568bool PhoneFormat::save( Calendar *calendar) 572bool PhoneFormat::save( Calendar *calendar)
569{ 573{
570 QLabel status ( i18n(" Opening device ..."), 0 ); 574 QLabel status ( i18n(" Opening device ..."), 0 );
571 int w = status.sizeHint().width()+20 ; 575 int w = status.sizeHint().width()+20 ;
572 if ( w < 200 ) w = 230; 576 if ( w < 200 ) w = 230;
573 int h = status.sizeHint().height()+20 ; 577 int h = status.sizeHint().height()+20 ;
574 int dw = QApplication::desktop()->width(); 578 int dw = QApplication::desktop()->width();
575 int dh = QApplication::desktop()->height(); 579 int dh = QApplication::desktop()->height();
576 status.setCaption(i18n("Writing to phone...") ); 580 status.setCaption(i18n("Writing to phone...") );
577 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 581 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
578 status.show(); 582 status.show();
579 status.raise(); 583 status.raise();
580 qApp->processEvents(); 584 qApp->processEvents();
581 QString message; 585 QString message;
582#ifdef _WIN32_ 586#ifdef _WIN32_
583 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 587 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
584#else 588#else
585 QString fileName = "/tmp/kdepimtemp.vcs"; 589 QString fileName = "/tmp/kdepimtemp.vcs";
586#endif 590#endif
587 591
588 // 1 remove events which should be deleted 592 // 1 remove events which should be deleted
589 QPtrList<Event> er = calendar->rawEvents(); 593 QPtrList<Event> er = calendar->rawEvents();
590 Event* ev = er.first(); 594 Event* ev = er.first();
591 while ( ev ) { 595 while ( ev ) {
592 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 596 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
593 calendar->deleteEvent( ev ); 597 calendar->deleteEvent( ev );
594 } else { 598 } else {
595 599
596 } 600 }
597 ev = er.next(); 601 ev = er.next();
598 } 602 }
599 // 2 remove todos which should be deleted 603 // 2 remove todos which should be deleted
600 QPtrList<Todo> tl = calendar->rawTodos(); 604 QPtrList<Todo> tl = calendar->rawTodos();
601 Todo* to = tl.first(); 605 Todo* to = tl.first();
602 while ( to ) { 606 while ( to ) {
603 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 607 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
604 calendar->deleteTodo( to ); 608 calendar->deleteTodo( to );
605 } else { 609 } else {
606 if ( to->isCompleted()) { 610 if ( to->isCompleted()) {
607 calendar->deleteTodo( to ); 611 calendar->deleteTodo( to );
608 } 612 }
609 } 613 }
610 to = tl.next(); 614 to = tl.next();
611 } 615 }
612 // 3 save file 616 // 3 save file
613 VCalFormat vfsave; 617 VCalFormat vfsave;
614 vfsave.setLocalTime ( true ); 618 vfsave.setLocalTime ( true );
615 if ( ! vfsave.save( calendar, fileName ) ) 619 if ( ! vfsave.save( calendar, fileName ) )
616 return false; 620 return false;
617 // 4 call kammu 621 // 4 call kammu
622#ifdef DESKTOP_VERSION
618 QString command ="./kammu --restore " + fileName ; 623 QString command ="./kammu --restore " + fileName ;
624#else
625 QString command ="kammu --restore " + fileName ;
626#endif
619 int ret; 627 int ret;
620 while ( (ret = system ( command.latin1())) != 0 ) { 628 while ( (ret = system ( command.latin1())) != 0 ) {
621 qDebug("Error S::command returned %d. asking users", ret); 629 qDebug("Error S::command returned %d. asking users", ret);
622 int retval = KMessageBox::warningContinueCancel(0, 630 int retval = KMessageBox::warningContinueCancel(0,
623 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); 631 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
624 if ( retval != KMessageBox::Continue ) 632 if ( retval != KMessageBox::Continue )
625 return false; 633 return false;
626 } 634 }
627 635
628 // 5 reread data 636 // 5 reread data
629 message = i18n(" Rereading all data ... "); 637 message = i18n(" Rereading all data ... ");
630 status.setText ( message ); 638 status.setText ( message );
631 qApp->processEvents(); 639 qApp->processEvents();
632 CalendarLocal* calendarTemp = new CalendarLocal(); 640 CalendarLocal* calendarTemp = new CalendarLocal();
633 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 641 calendarTemp->setTimeZoneId( calendar->timeZoneId());
634 if ( ! load( calendarTemp,calendar) ){ 642 if ( ! load( calendarTemp,calendar) ){
635 qDebug("error reloading calendar "); 643 qDebug("error reloading calendar ");
636 delete calendarTemp; 644 delete calendarTemp;
637 return false; 645 return false;
638 } 646 }
639 // 6 compare data 647 // 6 compare data
640 648
641//algo 6 compare event 649//algo 6 compare event
642 er = calendar->rawEvents(); 650 er = calendar->rawEvents();
643 ev = er.first(); 651 ev = er.first();
644 message = i18n(" Comparing event # "); 652 message = i18n(" Comparing event # ");
645 QPtrList<Event> er1 = calendarTemp->rawEvents(); 653 QPtrList<Event> er1 = calendarTemp->rawEvents();
646 Event* ev1; 654 Event* ev1;
647 int procCount = 0; 655 int procCount = 0;
648 while ( ev ) { 656 while ( ev ) {
649 //qDebug("event new ID %s",ev->summary().latin1()); 657 //qDebug("event new ID %s",ev->summary().latin1());
650 status.setText ( message + QString::number ( ++procCount ) ); 658 status.setText ( message + QString::number ( ++procCount ) );
651 qApp->processEvents(); 659 qApp->processEvents();
652 uint csum; 660 uint csum;
653 csum = PhoneFormat::getCsumEvent( ev ); 661 csum = PhoneFormat::getCsumEvent( ev );
654 QString cSum = QString::number( csum ); 662 QString cSum = QString::number( csum );
655 //ev->setCsum( mProfileName, cSum ); 663 //ev->setCsum( mProfileName, cSum );
656 //qDebug("Event cSum %s ", cSum.latin1()); 664 //qDebug("Event cSum %s ", cSum.latin1());
657 ev1 = er1.first(); 665 ev1 = er1.first();
658 while ( ev1 ) { 666 while ( ev1 ) {
659 if ( ev1->getCsum( mProfileName ) == cSum ) { 667 if ( ev1->getCsum( mProfileName ) == cSum ) {
660 er1.remove( ev1 ); 668 er1.remove( ev1 );
661 afterSave( ev ); 669 afterSave( ev );
662 ev->setID(mProfileName, ev1->getID(mProfileName) ); 670 ev->setID(mProfileName, ev1->getID(mProfileName) );
663 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 671 //qDebug("Event found on phone for %s ", ev->summary().latin1());
664 672
665 break; 673 break;
666 } 674 }
667 ev1 = er1.next(); 675 ev1 = er1.next();
668 } 676 }
669 if ( ! ev1 ) { 677 if ( ! ev1 ) {
670 // ev->removeID(mProfileName); 678 // ev->removeID(mProfileName);
671 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 679 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
672 } 680 }
673 681
674 682
675 ev = er.next(); 683 ev = er.next();
676 } 684 }
677 //algo 6 compare todo 685 //algo 6 compare todo
678 tl = calendar->rawTodos(); 686 tl = calendar->rawTodos();
679 to = tl.first(); 687 to = tl.first();
680 procCount = 0; 688 procCount = 0;
681 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 689 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
682 Todo* to1 ; 690 Todo* to1 ;
683 message = i18n(" Comparing todo # "); 691 message = i18n(" Comparing todo # ");
684 while ( to ) { 692 while ( to ) {
685 status.setText ( message + QString::number ( ++procCount ) ); 693 status.setText ( message + QString::number ( ++procCount ) );
686 qApp->processEvents(); 694 qApp->processEvents();
687 uint csum; 695 uint csum;
688 csum = PhoneFormat::getCsumTodo( to ); 696 csum = PhoneFormat::getCsumTodo( to );
689 QString cSum = QString::number( csum ); 697 QString cSum = QString::number( csum );
690 //to->setCsum( mProfileName, cSum ); 698 //to->setCsum( mProfileName, cSum );
691 //qDebug("Todo cSum %s ", cSum.latin1()); 699 //qDebug("Todo cSum %s ", cSum.latin1());
692 Todo* to1 = tl1.first(); 700 Todo* to1 = tl1.first();
693 while ( to1 ) { 701 while ( to1 ) {
694 if ( to1->getCsum( mProfileName ) == cSum ) { 702 if ( to1->getCsum( mProfileName ) == cSum ) {
695 tl1.remove( to1 ); 703 tl1.remove( to1 );
696 afterSave( to ); 704 afterSave( to );
697 to->setID(mProfileName, to1->getID(mProfileName) ); 705 to->setID(mProfileName, to1->getID(mProfileName) );
698 break; 706 break;
699 } 707 }
700 to1 = tl1.next(); 708 to1 = tl1.next();
701 } 709 }
702 if ( ! to1 ) { 710 if ( ! to1 ) {
703 //to->removeID(mProfileName); 711 //to->removeID(mProfileName);
704 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 712 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
705 } 713 }
706 714
707 to = tl.next(); 715 to = tl.next();
708 } 716 }
709 delete calendarTemp; 717 delete calendarTemp;
710 return true; 718 return true;
711 719
712 720
713 721
714} 722}
715 723
716 724
717QString PhoneFormat::toString( Calendar * ) 725QString PhoneFormat::toString( Calendar * )
718{ 726{
719 return QString::null; 727 return QString::null;
720} 728}
721bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 729bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
722{ 730{
723 return false; 731 return false;
724} 732}