summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-05 11:37:46 (UTC)
committer zautrix <zautrix>2004-10-05 11:37:46 (UTC)
commit4c877944b4e7bb7f74b4c8db07a99fd8133e8b86 (patch) (unidiff)
treebd3ecaaa9618eb6774ccc05fa79d546296fe54ba
parentf002814959b88dc7786bbb4299ab6252a6fa8e0d (diff)
downloadkdepimpi-4c877944b4e7bb7f74b4c8db07a99fd8133e8b86.zip
kdepimpi-4c877944b4e7bb7f74b4c8db07a99fd8133e8b86.tar.gz
kdepimpi-4c877944b4e7bb7f74b4c8db07a99fd8133e8b86.tar.bz2
added missing ;
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 16c5880..29c1ae6 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,732 +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("tmp", "tempfile.vcs") 383 fileName = locateLocal("tmp", "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#ifdef DESKTOP_VERSION
388 QString command ="./kammu --backup " + fileName + " -yes" ; 388 QString command ="./kammu --backup " + fileName + " -yes" ;
389#else 389#else
390 QString command ="kammu --backup " + fileName + " -yes" ; 390 QString command ="kammu --backup " + fileName + " -yes" ;
391#endif 391#endif
392 int ret = system ( command.latin1() ); 392 int ret = system ( command.latin1() );
393 if ( ret != 0 ) { 393 if ( ret != 0 ) {
394 qDebug("Error::command returned %d", ret); 394 qDebug("Error::command returned %d", ret);
395 return false; 395 return false;
396 } 396 }
397 VCalFormat vfload; 397 VCalFormat vfload;
398 vfload.setLocalTime ( true ); 398 vfload.setLocalTime ( true );
399 qDebug("loading file ..."); 399 qDebug("loading file ...");
400 400
401 if ( ! vfload.load( calendar, fileName ) ) 401 if ( ! vfload.load( calendar, fileName ) )
402 return false; 402 return false;
403 QPtrList<Event> er = calendar->rawEvents(); 403 QPtrList<Event> er = calendar->rawEvents();
404 Event* ev = er.first(); 404 Event* ev = er.first();
405 qDebug("reading events... "); 405 qDebug("reading events... ");
406 while ( ev ) { 406 while ( ev ) {
407 QStringList cat = ev->categories(); 407 QStringList cat = ev->categories();
408 if ( cat.contains( "MeetingDEF" )) { 408 if ( cat.contains( "MeetingDEF" )) {
409 ev->setCategories( QStringList() ); 409 ev->setCategories( QStringList() );
410 } 410 }
411 int id = ev->pilotId(); 411 int id = ev->pilotId();
412 Event *event; 412 Event *event;
413 event = existingCal->event( mProfileName ,QString::number( id ) ); 413 event = existingCal->event( mProfileName ,QString::number( id ) );
414 if ( event ) { 414 if ( event ) {
415 event = (Event*)event->clone(); 415 event = (Event*)event->clone();
416 copyEvent( event, ev ); 416 copyEvent( event, ev );
417 calendar->deleteEvent( ev ); 417 calendar->deleteEvent( ev );
418 calendar->addEvent( event); 418 calendar->addEvent( event);
419 } 419 }
420 else 420 else
421 event = ev; 421 event = ev;
422 uint cSum; 422 uint cSum;
423 cSum = PhoneFormat::getCsumEvent( event ); 423 cSum = PhoneFormat::getCsumEvent( event );
424 event->setCsum( mProfileName, QString::number( cSum )); 424 event->setCsum( mProfileName, QString::number( cSum ));
425 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 425 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
426 event->setID( mProfileName,QString::number( id ) ); 426 event->setID( mProfileName,QString::number( id ) );
427 ev = er.next(); 427 ev = er.next();
428 } 428 }
429 { 429 {
430 qDebug("reading todos... "); 430 qDebug("reading todos... ");
431 QPtrList<Todo> tr = calendar->rawTodos(); 431 QPtrList<Todo> tr = calendar->rawTodos();
432 Todo* ev = tr.first(); 432 Todo* ev = tr.first();
433 while ( ev ) { 433 while ( ev ) {
434 434
435 QStringList cat = ev->categories(); 435 QStringList cat = ev->categories();
436 if ( cat.contains( "MeetingDEF" )) { 436 if ( cat.contains( "MeetingDEF" )) {
437 ev->setCategories( QStringList() ); 437 ev->setCategories( QStringList() );
438 } 438 }
439 int id = ev->pilotId(); 439 int id = ev->pilotId();
440 Todo *event; 440 Todo *event;
441 event = existingCal->todo( mProfileName ,QString::number( id ) ); 441 event = existingCal->todo( mProfileName ,QString::number( id ) );
442 if ( event ) { 442 if ( event ) {
443 //qDebug("copy todo %s ", event->summary().latin1()); 443 //qDebug("copy todo %s ", event->summary().latin1());
444 444
445 event = (Todo*)event->clone(); 445 event = (Todo*)event->clone();
446 copyTodo( event, ev ); 446 copyTodo( event, ev );
447 calendar->deleteTodo( ev ); 447 calendar->deleteTodo( ev );
448 calendar->addTodo( event); 448 calendar->addTodo( event);
449 } 449 }
450 else 450 else
451 event = ev; 451 event = ev;
452 uint cSum; 452 uint cSum;
453 cSum = PhoneFormat::getCsumTodo( event ); 453 cSum = PhoneFormat::getCsumTodo( event );
454 event->setCsum( mProfileName, QString::number( cSum )); 454 event->setCsum( mProfileName, QString::number( cSum ));
455 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 455 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
456 event->setID( mProfileName,QString::number( id ) ); 456 event->setID( mProfileName,QString::number( id ) );
457 ev = tr.next(); 457 ev = tr.next();
458 } 458 }
459 } 459 }
460 return true; 460 return true;
461} 461}
462void PhoneFormat::copyEvent( Event* to, Event* from ) 462void PhoneFormat::copyEvent( Event* to, Event* from )
463{ 463{
464 if ( from->dtStart().isValid() ) 464 if ( from->dtStart().isValid() )
465 to->setDtStart( from->dtStart() ); 465 to->setDtStart( from->dtStart() );
466 if ( from->dtEnd().isValid() ) 466 if ( from->dtEnd().isValid() )
467 to->setDtEnd( from->dtEnd() ); 467 to->setDtEnd( from->dtEnd() );
468 if ( !from->location().isEmpty() ) 468 if ( !from->location().isEmpty() )
469 to->setLocation( from->location() ); 469 to->setLocation( from->location() );
470 if ( !from->description().isEmpty() ) 470 if ( !from->description().isEmpty() )
471 to->setDescription( from->description() ); 471 to->setDescription( from->description() );
472 if ( !from->summary().isEmpty() ) 472 if ( !from->summary().isEmpty() )
473 to->setSummary( from->summary() ); 473 to->setSummary( from->summary() );
474 474
475 if ( from->alarms().count() ) { 475 if ( from->alarms().count() ) {
476 to->clearAlarms(); 476 to->clearAlarms();
477 Alarm *a = from->alarms().first(); 477 Alarm *a = from->alarms().first();
478 Alarm *b = to->newAlarm( ); 478 Alarm *b = to->newAlarm( );
479 b->setEnabled( a->enabled() ); 479 b->setEnabled( a->enabled() );
480 if ( a->hasStartOffset() ) { 480 if ( a->hasStartOffset() ) {
481 b->setStartOffset( a->startOffset() ); 481 b->setStartOffset( a->startOffset() );
482 } 482 }
483 if ( a->hasTime() ) 483 if ( a->hasTime() )
484 b->setTime( a->time() ); 484 b->setTime( a->time() );
485 485
486 } 486 }
487 QStringList cat = to->categories(); 487 QStringList cat = to->categories();
488 QStringList catFrom = from->categories(); 488 QStringList catFrom = from->categories();
489 QString nCat; 489 QString nCat;
490 int iii; 490 int iii;
491 for ( iii = 0; iii < catFrom.count();++iii ) { 491 for ( iii = 0; iii < catFrom.count();++iii ) {
492 nCat = catFrom[iii]; 492 nCat = catFrom[iii];
493 if ( !nCat.isEmpty() ) 493 if ( !nCat.isEmpty() )
494 if ( !cat.contains( nCat )) { 494 if ( !cat.contains( nCat )) {
495 cat << nCat; 495 cat << nCat;
496 } 496 }
497 } 497 }
498 to->setCategories( cat ); 498 to->setCategories( cat );
499 Recurrence * r = new Recurrence( *from->recurrence(),to); 499 Recurrence * r = new Recurrence( *from->recurrence(),to);
500 to->setRecurrence( r ) ; 500 to->setRecurrence( r ) ;
501 501
502 502
503} 503}
504void PhoneFormat::copyTodo( Todo* to, Todo* from ) 504void PhoneFormat::copyTodo( Todo* to, Todo* from )
505{ 505{
506 if ( from->dtStart().isValid() ) 506 if ( from->dtStart().isValid() )
507 to->setDtStart( from->dtStart() ); 507 to->setDtStart( from->dtStart() );
508 if ( from->dtDue().isValid() ) 508 if ( from->dtDue().isValid() )
509 to->setDtDue( from->dtDue() ); 509 to->setDtDue( from->dtDue() );
510 if ( !from->location().isEmpty() ) 510 if ( !from->location().isEmpty() )
511 to->setLocation( from->location() ); 511 to->setLocation( from->location() );
512 if ( !from->description().isEmpty() ) 512 if ( !from->description().isEmpty() )
513 to->setDescription( from->description() ); 513 to->setDescription( from->description() );
514 if ( !from->summary().isEmpty() ) 514 if ( !from->summary().isEmpty() )
515 to->setSummary( from->summary() ); 515 to->setSummary( from->summary() );
516 516
517 if ( from->alarms().count() ) { 517 if ( from->alarms().count() ) {
518 to->clearAlarms(); 518 to->clearAlarms();
519 Alarm *a = from->alarms().first(); 519 Alarm *a = from->alarms().first();
520 Alarm *b = to->newAlarm( ); 520 Alarm *b = to->newAlarm( );
521 b->setEnabled( a->enabled() ); 521 b->setEnabled( a->enabled() );
522 if ( a->hasStartOffset() ) 522 if ( a->hasStartOffset() )
523 b->setStartOffset( a->startOffset() ); 523 b->setStartOffset( a->startOffset() );
524 if ( a->hasTime() ) 524 if ( a->hasTime() )
525 b->setTime( a->time() ); 525 b->setTime( a->time() );
526 } 526 }
527 527
528 QStringList cat = to->categories(); 528 QStringList cat = to->categories();
529 QStringList catFrom = from->categories(); 529 QStringList catFrom = from->categories();
530 QString nCat; 530 QString nCat;
531 int iii; 531 int iii;
532 for ( iii = 0; iii < catFrom.count();++iii ) { 532 for ( iii = 0; iii < catFrom.count();++iii ) {
533 nCat = catFrom[iii]; 533 nCat = catFrom[iii];
534 if ( !nCat.isEmpty() ) 534 if ( !nCat.isEmpty() )
535 if ( !cat.contains( nCat )) { 535 if ( !cat.contains( nCat )) {
536 cat << nCat; 536 cat << nCat;
537 } 537 }
538 } 538 }
539 to->setCategories( cat ); 539 to->setCategories( cat );
540 if ( from->isCompleted() ) { 540 if ( from->isCompleted() ) {
541 to->setCompleted( true ); 541 to->setCompleted( true );
542 if( from->completed().isValid() ) 542 if( from->completed().isValid() )
543 to->setCompleted( from->completed() ); 543 to->setCompleted( from->completed() );
544 } else { 544 } else {
545 // set percentcomplete only, if to->isCompleted() 545 // set percentcomplete only, if to->isCompleted()
546 if ( to->isCompleted() ) 546 if ( to->isCompleted() )
547 to->setPercentComplete(from->percentComplete()); 547 to->setPercentComplete(from->percentComplete());
548 } 548 }
549 if( to->priority() == 2 && from->priority() == 1 ) 549 if( to->priority() == 2 && from->priority() == 1 )
550 ; //skip 550 ; //skip
551 else if (to->priority() == 4 && from->priority() == 5 ) 551 else if (to->priority() == 4 && from->priority() == 5 )
552 ; 552 ;
553 else 553 else
554 to->setPriority(from->priority()); 554 to->setPriority(from->priority());
555 555
556} 556}
557#include <qcstring.h> 557#include <qcstring.h>
558 558
559void PhoneFormat::afterSave( Incidence* inc) 559void PhoneFormat::afterSave( Incidence* inc)
560{ 560{
561 uint csum; 561 uint csum;
562 inc->removeID( mProfileName ); 562 inc->removeID( mProfileName );
563 if ( inc->type() == "Event") 563 if ( inc->type() == "Event")
564 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 564 csum = PhoneFormat::getCsumEvent( (Event*) inc );
565 else 565 else
566 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 566 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
567 inc->setCsum( mProfileName, QString::number( csum )); 567 inc->setCsum( mProfileName, QString::number( csum ));
568 568
569 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 569 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
570 570
571} 571}
572bool PhoneFormat::save( Calendar *calendar) 572bool PhoneFormat::save( Calendar *calendar)
573{ 573{
574 QLabel status ( i18n(" Opening device ..."), 0 ); 574 QLabel status ( i18n(" Opening device ..."), 0 );
575 int w = status.sizeHint().width()+20 ; 575 int w = status.sizeHint().width()+20 ;
576 if ( w < 200 ) w = 230; 576 if ( w < 200 ) w = 230;
577 int h = status.sizeHint().height()+20 ; 577 int h = status.sizeHint().height()+20 ;
578 int dw = QApplication::desktop()->width(); 578 int dw = QApplication::desktop()->width();
579 int dh = QApplication::desktop()->height(); 579 int dh = QApplication::desktop()->height();
580 status.setCaption(i18n("Writing to phone...") ); 580 status.setCaption(i18n("Writing to phone...") );
581 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 581 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
582 status.show(); 582 status.show();
583 status.raise(); 583 status.raise();
584 qApp->processEvents(); 584 qApp->processEvents();
585 QString message; 585 QString message;
586#ifdef _WIN32_ 586#ifdef _WIN32_
587 QString fileName = locateLocal("tmp", "tempfile.vcs") 587 QString fileName = locateLocal("tmp", "tempfile.vcs");
588#else 588#else
589 QString fileName = "/tmp/kdepimtemp.vcs"; 589 QString fileName = "/tmp/kdepimtemp.vcs";
590#endif 590#endif
591 591
592 // 1 remove events which should be deleted 592 // 1 remove events which should be deleted
593 QPtrList<Event> er = calendar->rawEvents(); 593 QPtrList<Event> er = calendar->rawEvents();
594 Event* ev = er.first(); 594 Event* ev = er.first();
595 while ( ev ) { 595 while ( ev ) {
596 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 596 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
597 calendar->deleteEvent( ev ); 597 calendar->deleteEvent( ev );
598 } else { 598 } else {
599 599
600 } 600 }
601 ev = er.next(); 601 ev = er.next();
602 } 602 }
603 // 2 remove todos which should be deleted 603 // 2 remove todos which should be deleted
604 QPtrList<Todo> tl = calendar->rawTodos(); 604 QPtrList<Todo> tl = calendar->rawTodos();
605 Todo* to = tl.first(); 605 Todo* to = tl.first();
606 while ( to ) { 606 while ( to ) {
607 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 607 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
608 calendar->deleteTodo( to ); 608 calendar->deleteTodo( to );
609 } else { 609 } else {
610 if ( to->isCompleted()) { 610 if ( to->isCompleted()) {
611 calendar->deleteTodo( to ); 611 calendar->deleteTodo( to );
612 } 612 }
613 } 613 }
614 to = tl.next(); 614 to = tl.next();
615 } 615 }
616 // 3 save file 616 // 3 save file
617 VCalFormat vfsave; 617 VCalFormat vfsave;
618 vfsave.setLocalTime ( true ); 618 vfsave.setLocalTime ( true );
619 if ( ! vfsave.save( calendar, fileName ) ) 619 if ( ! vfsave.save( calendar, fileName ) )
620 return false; 620 return false;
621 // 4 call kammu 621 // 4 call kammu
622#ifdef DESKTOP_VERSION 622#ifdef DESKTOP_VERSION
623 QString command ="./kammu --restore " + fileName ; 623 QString command ="./kammu --restore " + fileName ;
624#else 624#else
625 QString command ="kammu --restore " + fileName ; 625 QString command ="kammu --restore " + fileName ;
626#endif 626#endif
627 int ret; 627 int ret;
628 while ( (ret = system ( command.latin1())) != 0 ) { 628 while ( (ret = system ( command.latin1())) != 0 ) {
629 qDebug("Error S::command returned %d. asking users", ret); 629 qDebug("Error S::command returned %d. asking users", ret);
630 int retval = KMessageBox::warningContinueCancel(0, 630 int retval = KMessageBox::warningContinueCancel(0,
631 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"));
632 if ( retval != KMessageBox::Continue ) 632 if ( retval != KMessageBox::Continue )
633 return false; 633 return false;
634 } 634 }
635 635
636 // 5 reread data 636 // 5 reread data
637 message = i18n(" Rereading all data ... "); 637 message = i18n(" Rereading all data ... ");
638 status.setText ( message ); 638 status.setText ( message );
639 qApp->processEvents(); 639 qApp->processEvents();
640 CalendarLocal* calendarTemp = new CalendarLocal(); 640 CalendarLocal* calendarTemp = new CalendarLocal();
641 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 641 calendarTemp->setTimeZoneId( calendar->timeZoneId());
642 if ( ! load( calendarTemp,calendar) ){ 642 if ( ! load( calendarTemp,calendar) ){
643 qDebug("error reloading calendar "); 643 qDebug("error reloading calendar ");
644 delete calendarTemp; 644 delete calendarTemp;
645 return false; 645 return false;
646 } 646 }
647 // 6 compare data 647 // 6 compare data
648 648
649//algo 6 compare event 649//algo 6 compare event
650 er = calendar->rawEvents(); 650 er = calendar->rawEvents();
651 ev = er.first(); 651 ev = er.first();
652 message = i18n(" Comparing event # "); 652 message = i18n(" Comparing event # ");
653 QPtrList<Event> er1 = calendarTemp->rawEvents(); 653 QPtrList<Event> er1 = calendarTemp->rawEvents();
654 Event* ev1; 654 Event* ev1;
655 int procCount = 0; 655 int procCount = 0;
656 while ( ev ) { 656 while ( ev ) {
657 //qDebug("event new ID %s",ev->summary().latin1()); 657 //qDebug("event new ID %s",ev->summary().latin1());
658 status.setText ( message + QString::number ( ++procCount ) ); 658 status.setText ( message + QString::number ( ++procCount ) );
659 qApp->processEvents(); 659 qApp->processEvents();
660 uint csum; 660 uint csum;
661 csum = PhoneFormat::getCsumEvent( ev ); 661 csum = PhoneFormat::getCsumEvent( ev );
662 QString cSum = QString::number( csum ); 662 QString cSum = QString::number( csum );
663 //ev->setCsum( mProfileName, cSum ); 663 //ev->setCsum( mProfileName, cSum );
664 //qDebug("Event cSum %s ", cSum.latin1()); 664 //qDebug("Event cSum %s ", cSum.latin1());
665 ev1 = er1.first(); 665 ev1 = er1.first();
666 while ( ev1 ) { 666 while ( ev1 ) {
667 if ( ev1->getCsum( mProfileName ) == cSum ) { 667 if ( ev1->getCsum( mProfileName ) == cSum ) {
668 er1.remove( ev1 ); 668 er1.remove( ev1 );
669 afterSave( ev ); 669 afterSave( ev );
670 ev->setID(mProfileName, ev1->getID(mProfileName) ); 670 ev->setID(mProfileName, ev1->getID(mProfileName) );
671 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 671 //qDebug("Event found on phone for %s ", ev->summary().latin1());
672 672
673 break; 673 break;
674 } 674 }
675 ev1 = er1.next(); 675 ev1 = er1.next();
676 } 676 }
677 if ( ! ev1 ) { 677 if ( ! ev1 ) {
678 // ev->removeID(mProfileName); 678 // ev->removeID(mProfileName);
679 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());
680 } 680 }
681 681
682 682
683 ev = er.next(); 683 ev = er.next();
684 } 684 }
685 //algo 6 compare todo 685 //algo 6 compare todo
686 tl = calendar->rawTodos(); 686 tl = calendar->rawTodos();
687 to = tl.first(); 687 to = tl.first();
688 procCount = 0; 688 procCount = 0;
689 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 689 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
690 Todo* to1 ; 690 Todo* to1 ;
691 message = i18n(" Comparing todo # "); 691 message = i18n(" Comparing todo # ");
692 while ( to ) { 692 while ( to ) {
693 status.setText ( message + QString::number ( ++procCount ) ); 693 status.setText ( message + QString::number ( ++procCount ) );
694 qApp->processEvents(); 694 qApp->processEvents();
695 uint csum; 695 uint csum;
696 csum = PhoneFormat::getCsumTodo( to ); 696 csum = PhoneFormat::getCsumTodo( to );
697 QString cSum = QString::number( csum ); 697 QString cSum = QString::number( csum );
698 //to->setCsum( mProfileName, cSum ); 698 //to->setCsum( mProfileName, cSum );
699 //qDebug("Todo cSum %s ", cSum.latin1()); 699 //qDebug("Todo cSum %s ", cSum.latin1());
700 Todo* to1 = tl1.first(); 700 Todo* to1 = tl1.first();
701 while ( to1 ) { 701 while ( to1 ) {
702 if ( to1->getCsum( mProfileName ) == cSum ) { 702 if ( to1->getCsum( mProfileName ) == cSum ) {
703 tl1.remove( to1 ); 703 tl1.remove( to1 );
704 afterSave( to ); 704 afterSave( to );
705 to->setID(mProfileName, to1->getID(mProfileName) ); 705 to->setID(mProfileName, to1->getID(mProfileName) );
706 break; 706 break;
707 } 707 }
708 to1 = tl1.next(); 708 to1 = tl1.next();
709 } 709 }
710 if ( ! to1 ) { 710 if ( ! to1 ) {
711 //to->removeID(mProfileName); 711 //to->removeID(mProfileName);
712 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());
713 } 713 }
714 714
715 to = tl.next(); 715 to = tl.next();
716 } 716 }
717 delete calendarTemp; 717 delete calendarTemp;
718 return true; 718 return true;
719 719
720 720
721 721
722} 722}
723 723
724 724
725QString PhoneFormat::toString( Calendar * ) 725QString PhoneFormat::toString( Calendar * )
726{ 726{
727 return QString::null; 727 return QString::null;
728} 728}
729bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 729bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
730{ 730{
731 return false; 731 return false;
732} 732}