summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 20:24:05 (UTC)
committer zautrix <zautrix>2004-09-12 20:24:05 (UTC)
commit7fcde3393eb2150fd96f7899056ec11d0fd2931e (patch) (unidiff)
treed46619e939b655b33df280f16c30b5e675be7450
parent5b434dd78f71bcea5e6067fc8ae0faaaea313f9d (diff)
downloadkdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.zip
kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.gz
kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.bz2
writing gammurc added
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp97
-rw-r--r--libkcal/phoneformat.h2
2 files changed, 94 insertions, 5 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 178a63e..99d6a06 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,473 +1,562 @@
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 <qxml.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 mDevice = device; 87
88 mConnection = connection; 88 QString fileName = QDir::homeDirPath() +"/.gammurc";
89 mModel = model; 89 //qDebug("save %d ", load );
90 QString content;
91 bool write = false;
92 bool addPort = true, addConnection = true, addModel = true;
93 QFile file( fileName );
94 if ( QFile::exists( fileName) ) {
95 if (!file.open( IO_ReadOnly ) ) {
96 qDebug("Error: cannot open %s ", fileName.latin1() );
97 return;
98 }
99 QString line;
100 while ( file.readLine( line, 1024 ) > 0 ) {
101 //qDebug("*%s* ", line.latin1() );
102 if ( line.left(7 ) == "[gammu]" ) {
103 ;
104 } else
105 if ( line.left(4 ) == "port" ) {
106 if ( line == "port = " + device+"\n" ) {
107 content += line ;
108 addPort = false;
109 //qDebug("port found" );
110 }
111
112 } else if ( line.left(5 ) == "model" ) {
113 if ( line == "model = " + model +"\n") {
114 content += line ;
115 addModel = false;
116 //qDebug("model found" );
117 }
118
119 } else if ( line.left( 10 ) == "connection" ) {
120 if ( line == "connection = " + connection +"\n") {
121 addConnection = false;
122 content += line ;
123 //qDebug("con found" );
124 }
125
126 } else {
127 content += line ;
128 }
129 }
130 file.close();
131 } else {
132 if ( ! connection.isEmpty() ) {
133 addConnection = true;
134 }
135 if ( ! device.isEmpty() ) {
136 addPort = true;
137
138 }
139 if ( ! model.isEmpty() ) {
140 addModel = true;
141 }
142 }
143
144 if ( addConnection ) {
145 if ( ! write )
146 content += "[gammu]\n";
147 write = true;
148 content += "connection = ";
149 content += connection;
150 content += "\n";
151 }
152 if ( addPort ) {
153 if ( ! write )
154 content += "[gammu]\n";
155 write = true;
156 content += "port = ";
157 content += device;
158 content += "\n";
159
160 }
161 if ( addModel ) {
162 if ( ! write )
163 content += "[gammu]\n";
164 write = true;
165 content += "model = ";
166 content += model;
167 content += "\n";
168 }
169 if ( write ) {
170 if (!file.open( IO_WriteOnly ) ) {
171 qDebug("Error: cannot write file %s ", fileName.latin1() );
172 return;
173 }
174 qDebug("Writing file %s ", fileName.latin1() );
175 QTextStream ts( &file );
176 ts << content ;
177 file.close();
178 }
90} 179}
91 180
92PhoneFormat::~PhoneFormat() 181PhoneFormat::~PhoneFormat()
93{ 182{
94} 183}
95#if 0 184#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 185int PhoneFormat::initDevice(GSM_StateMachine *s)
97{ 186{
98 GSM_ReadConfig(NULL, &s->Config[0], 0); 187 GSM_ReadConfig(NULL, &s->Config[0], 0);
99 s->ConfigNum = 1; 188 s->ConfigNum = 1;
100 GSM_Config *cfg = &s->Config[0]; 189 GSM_Config *cfg = &s->Config[0];
101 if ( ! mConnection.isEmpty() ) { 190 if ( ! mConnection.isEmpty() ) {
102 cfg->Connection = strdup(mConnection.latin1()); 191 cfg->Connection = strdup(mConnection.latin1());
103 cfg->DefaultConnection = false; 192 cfg->DefaultConnection = false;
104 qDebug("Connection set %s ", cfg->Connection ); 193 qDebug("Connection set %s ", cfg->Connection );
105 194
106 } 195 }
107 if ( ! mDevice.isEmpty() ) { 196 if ( ! mDevice.isEmpty() ) {
108 cfg->Device = strdup(mDevice.latin1()); 197 cfg->Device = strdup(mDevice.latin1());
109 cfg->DefaultDevice = false; 198 cfg->DefaultDevice = false;
110 qDebug("Device set %s ", cfg->Device); 199 qDebug("Device set %s ", cfg->Device);
111 200
112 } 201 }
113 if ( ! mModel.isEmpty() ) { 202 if ( ! mModel.isEmpty() ) {
114 strcpy(cfg->Model,mModel.latin1() ); 203 strcpy(cfg->Model,mModel.latin1() );
115 cfg->DefaultModel = false; 204 cfg->DefaultModel = false;
116 qDebug("Model set %s ",cfg->Model ); 205 qDebug("Model set %s ",cfg->Model );
117 } 206 }
118 int error=GSM_InitConnection(s,3); 207 int error=GSM_InitConnection(s,3);
119 return error; 208 return error;
120} 209}
121#endif 210#endif
122ulong PhoneFormat::getCsumTodo( Todo* todo ) 211ulong PhoneFormat::getCsumTodo( Todo* todo )
123{ 212{
124 QStringList attList; 213 QStringList attList;
125 if ( todo->hasDueDate() ) 214 if ( todo->hasDueDate() )
126 attList << PhoneParser::dtToString ( todo->dtDue() ); 215 attList << PhoneParser::dtToString ( todo->dtDue() );
127 attList << todo->summary(); 216 attList << todo->summary();
128 QString completedString = "no"; 217 QString completedString = "no";
129 if ( todo->isCompleted() ) 218 if ( todo->isCompleted() )
130 completedString = "yes"; 219 completedString = "yes";
131 attList << completedString; 220 attList << completedString;
132 int prio = todo->priority(); 221 int prio = todo->priority();
133 if( prio == 2 ) prio = 1; 222 if( prio == 2 ) prio = 1;
134 if (prio == 4 ) prio = 5 ; 223 if (prio == 4 ) prio = 5 ;
135 attList << QString::number( prio ); 224 attList << QString::number( prio );
136 QString alarmString = "na"; 225 QString alarmString = "na";
137 Alarm *alarm; 226 Alarm *alarm;
138 if ( todo->alarms().count() > 0 ) { 227 if ( todo->alarms().count() > 0 ) {
139 alarm = todo->alarms().first(); 228 alarm = todo->alarms().first();
140 if ( alarm->enabled() ) { 229 if ( alarm->enabled() ) {
141 alarmString = QString::number(alarm->offset() ); 230 alarmString = QString::number(alarm->offset() );
142 } 231 }
143 } 232 }
144 attList << alarmString; 233 attList << alarmString;
145 attList << todo->categoriesStr(); 234 attList << todo->categoriesStr();
146 attList << todo->secrecyStr(); 235 attList << todo->secrecyStr();
147 return PhoneFormat::getCsum(attList ); 236 return PhoneFormat::getCsum(attList );
148 237
149} 238}
150ulong PhoneFormat::getCsumEvent( Event* event ) 239ulong PhoneFormat::getCsumEvent( Event* event )
151{ 240{
152 QStringList attList; 241 QStringList attList;
153 attList << PhoneParser::dtToString ( event->dtStart() ); 242 attList << PhoneParser::dtToString ( event->dtStart() );
154 attList << PhoneParser::dtToString ( event->dtEnd() ); 243 attList << PhoneParser::dtToString ( event->dtEnd() );
155 attList << event->summary(); 244 attList << event->summary();
156 attList << event->location(); 245 attList << event->location();
157 QString alarmString = "na"; 246 QString alarmString = "na";
158 Alarm *alarm; 247 Alarm *alarm;
159 if ( event->alarms().count() > 0 ) { 248 if ( event->alarms().count() > 0 ) {
160 alarm = event->alarms().first(); 249 alarm = event->alarms().first();
161 if ( alarm->enabled() ) { 250 if ( alarm->enabled() ) {
162 alarmString = QString::number( alarm->offset() ); 251 alarmString = QString::number( alarm->offset() );
163 } 252 }
164 } 253 }
165 attList << alarmString; 254 attList << alarmString;
166 Recurrence* rec = event->recurrence(); 255 Recurrence* rec = event->recurrence();
167 QStringList list; 256 QStringList list;
168 bool writeEndDate = false; 257 bool writeEndDate = false;
169 switch ( rec->doesRecur() ) 258 switch ( rec->doesRecur() )
170 { 259 {
171 case Recurrence::rDaily: // 0 260 case Recurrence::rDaily: // 0
172 list.append( "0" ); 261 list.append( "0" );
173 list.append( QString::number( rec->frequency() ));//12 262 list.append( QString::number( rec->frequency() ));//12
174 list.append( "0" ); 263 list.append( "0" );
175 list.append( "0" ); 264 list.append( "0" );
176 writeEndDate = true; 265 writeEndDate = true;
177 break; 266 break;
178 case Recurrence::rWeekly:// 1 267 case Recurrence::rWeekly:// 1
179 list.append( "1" ); 268 list.append( "1" );
180 list.append( QString::number( rec->frequency()) );//12 269 list.append( QString::number( rec->frequency()) );//12
181 list.append( "0" ); 270 list.append( "0" );
182 { 271 {
183 int days = 0; 272 int days = 0;
184 QBitArray weekDays = rec->days(); 273 QBitArray weekDays = rec->days();
185 int i; 274 int i;
186 for( i = 1; i <= 7; ++i ) { 275 for( i = 1; i <= 7; ++i ) {
187 if ( weekDays[i-1] ) { 276 if ( weekDays[i-1] ) {
188 days += 1 << (i-1); 277 days += 1 << (i-1);
189 } 278 }
190 } 279 }
191 list.append( QString::number( days ) ); 280 list.append( QString::number( days ) );
192 } 281 }
193 //pending weekdays 282 //pending weekdays
194 writeEndDate = true; 283 writeEndDate = true;
195 284
196 break; 285 break;
197 case Recurrence::rMonthlyPos:// 2 286 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 287 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 288 list.append( QString::number( rec->frequency()) );//12
200 289
201 writeEndDate = true; 290 writeEndDate = true;
202 { 291 {
203 int count = 1; 292 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 293 QPtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 294 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 295 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 296 count = 5 - rmp.first()->rPos - 1;
208 else 297 else
209 count = rmp.first()->rPos - 1; 298 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 299 list.append( QString::number( count ) );
211 300
212 } 301 }
213 302
214 list.append( "0" ); 303 list.append( "0" );
215 break; 304 break;
216 case Recurrence::rMonthlyDay:// 3 305 case Recurrence::rMonthlyDay:// 3
217 list.append( "3" ); 306 list.append( "3" );
218 list.append( QString::number( rec->frequency()) );//12 307 list.append( QString::number( rec->frequency()) );//12
219 list.append( "0" ); 308 list.append( "0" );
220 list.append( "0" ); 309 list.append( "0" );
221 writeEndDate = true; 310 writeEndDate = true;
222 break; 311 break;
223 case Recurrence::rYearlyMonth://4 312 case Recurrence::rYearlyMonth://4
224 list.append( "4" ); 313 list.append( "4" );
225 list.append( QString::number( rec->frequency()) );//12 314 list.append( QString::number( rec->frequency()) );//12
226 list.append( "0" ); 315 list.append( "0" );
227 list.append( "0" ); 316 list.append( "0" );
228 writeEndDate = true; 317 writeEndDate = true;
229 break; 318 break;
230 319
231 default: 320 default:
232 list.append( "255" ); 321 list.append( "255" );
233 list.append( QString() ); 322 list.append( QString() );
234 list.append( "0" ); 323 list.append( "0" );
235 list.append( QString() ); 324 list.append( QString() );
236 list.append( "0" ); 325 list.append( "0" );
237 list.append( "20991231T000000" ); 326 list.append( "20991231T000000" );
238 break; 327 break;
239 } 328 }
240 if ( writeEndDate ) { 329 if ( writeEndDate ) {
241 330
242 if ( rec->endDate().isValid() ) { // 15 + 16 331 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 332 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 333 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 334 } else {
246 list.append( "0" ); 335 list.append( "0" );
247 list.append( "20991231T000000" ); 336 list.append( "20991231T000000" );
248 } 337 }
249 338
250 } 339 }
251 attList << list.join(""); 340 attList << list.join("");
252 attList << event->categoriesStr(); 341 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 342 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 343
255 attList << event->secrecyStr(); 344 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 345 return PhoneFormat::getCsum(attList );
257} 346}
258ulong PhoneFormat::getCsum( const QStringList & attList) 347ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 348{
260 int max = attList.count(); 349 int max = attList.count();
261 ulong cSum = 0; 350 ulong cSum = 0;
262 int j,k,i; 351 int j,k,i;
263 int add; 352 int add;
264 for ( i = 0; i < max ; ++i ) { 353 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 354 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
267 j = s.length(); 356 j = s.length();
268 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 358 int mul = k +1;
270 add = s[k].unicode (); 359 add = s[k].unicode ();
271 if ( k < 16 ) 360 if ( k < 16 )
272 mul = mul * mul; 361 mul = mul * mul;
273 int ii = i+1; 362 int ii = i+1;
274 add = add * mul *ii*ii*ii; 363 add = add * mul *ii*ii*ii;
275 cSum += add; 364 cSum += add;
276 } 365 }
277 } 366 }
278 367
279 } 368 }
280 //QString dump = attList.join(","); 369 //QString dump = attList.join(",");
281 //qDebug("csum: %d %s", cSum,dump.latin1()); 370 //qDebug("csum: %d %s", cSum,dump.latin1());
282 371
283 return cSum; 372 return cSum;
284 373
285} 374}
286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 375//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
287#include <stdlib.h> 376#include <stdlib.h>
288#define DEBUGMODE false 377#define DEBUGMODE false
289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 378bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
290{ 379{
291 380
292 QString fileName; 381 QString fileName;
293#ifdef _WIN32_ 382#ifdef _WIN32_
294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 383 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
295#else 384#else
296 fileName = "/tmp/kdepimtemp.vcs"; 385 fileName = "/tmp/kdepimtemp.vcs";
297#endif 386#endif
298 QString command ="./kammu --backup " + fileName + " -yes" ; 387 QString command ="./kammu --backup " + fileName + " -yes" ;
299 int ret = system ( command.latin1() ); 388 int ret = system ( command.latin1() );
300 if ( ret != 0 ) { 389 if ( ret != 0 ) {
301 qDebug("Error::command returned %d", ret); 390 qDebug("Error::command returned %d", ret);
302 return false; 391 return false;
303 } 392 }
304 VCalFormat vfload; 393 VCalFormat vfload;
305 vfload.setLocalTime ( true ); 394 vfload.setLocalTime ( true );
306 qDebug("loading file ..."); 395 qDebug("loading file ...");
307 396
308 if ( ! vfload.load( calendar, fileName ) ) 397 if ( ! vfload.load( calendar, fileName ) )
309 return false; 398 return false;
310 QPtrList<Event> er = calendar->rawEvents(); 399 QPtrList<Event> er = calendar->rawEvents();
311 Event* ev = er.first(); 400 Event* ev = er.first();
312 qDebug("reading events... "); 401 qDebug("reading events... ");
313 while ( ev ) { 402 while ( ev ) {
314 QStringList cat = ev->categories(); 403 QStringList cat = ev->categories();
315 if ( cat.contains( "MeetingDEF" )) { 404 if ( cat.contains( "MeetingDEF" )) {
316 ev->setCategories( QStringList() ); 405 ev->setCategories( QStringList() );
317 } 406 }
318 int id = ev->pilotId(); 407 int id = ev->pilotId();
319 Event *event; 408 Event *event;
320 event = existingCal->event( mProfileName ,QString::number( id ) ); 409 event = existingCal->event( mProfileName ,QString::number( id ) );
321 if ( event ) { 410 if ( event ) {
322 event = (Event*)event->clone(); 411 event = (Event*)event->clone();
323 copyEvent( event, ev ); 412 copyEvent( event, ev );
324 calendar->deleteEvent( ev ); 413 calendar->deleteEvent( ev );
325 calendar->addEvent( event); 414 calendar->addEvent( event);
326 } 415 }
327 else 416 else
328 event = ev; 417 event = ev;
329 uint cSum; 418 uint cSum;
330 cSum = PhoneFormat::getCsumEvent( event ); 419 cSum = PhoneFormat::getCsumEvent( event );
331 event->setCsum( mProfileName, QString::number( cSum )); 420 event->setCsum( mProfileName, QString::number( cSum ));
332 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 421 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
333 event->setID( mProfileName,QString::number( id ) ); 422 event->setID( mProfileName,QString::number( id ) );
334 ev = er.next(); 423 ev = er.next();
335 } 424 }
336 { 425 {
337 qDebug("reading todos... "); 426 qDebug("reading todos... ");
338 QPtrList<Todo> tr = calendar->rawTodos(); 427 QPtrList<Todo> tr = calendar->rawTodos();
339 Todo* ev = tr.first(); 428 Todo* ev = tr.first();
340 while ( ev ) { 429 while ( ev ) {
341 430
342 QStringList cat = ev->categories(); 431 QStringList cat = ev->categories();
343 if ( cat.contains( "MeetingDEF" )) { 432 if ( cat.contains( "MeetingDEF" )) {
344 ev->setCategories( QStringList() ); 433 ev->setCategories( QStringList() );
345 } 434 }
346 int id = ev->pilotId(); 435 int id = ev->pilotId();
347 Todo *event; 436 Todo *event;
348 event = existingCal->todo( mProfileName ,QString::number( id ) ); 437 event = existingCal->todo( mProfileName ,QString::number( id ) );
349 if ( event ) { 438 if ( event ) {
350 //qDebug("copy todo %s ", event->summary().latin1()); 439 //qDebug("copy todo %s ", event->summary().latin1());
351 440
352 event = (Todo*)event->clone(); 441 event = (Todo*)event->clone();
353 copyTodo( event, ev ); 442 copyTodo( event, ev );
354 calendar->deleteTodo( ev ); 443 calendar->deleteTodo( ev );
355 calendar->addTodo( event); 444 calendar->addTodo( event);
356 } 445 }
357 else 446 else
358 event = ev; 447 event = ev;
359 uint cSum; 448 uint cSum;
360 cSum = PhoneFormat::getCsumTodo( event ); 449 cSum = PhoneFormat::getCsumTodo( event );
361 event->setCsum( mProfileName, QString::number( cSum )); 450 event->setCsum( mProfileName, QString::number( cSum ));
362 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 451 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
363 event->setID( mProfileName,QString::number( id ) ); 452 event->setID( mProfileName,QString::number( id ) );
364 ev = tr.next(); 453 ev = tr.next();
365 } 454 }
366 } 455 }
367 return true; 456 return true;
368} 457}
369void PhoneFormat::copyEvent( Event* to, Event* from ) 458void PhoneFormat::copyEvent( Event* to, Event* from )
370{ 459{
371 if ( from->dtStart().isValid() ) 460 if ( from->dtStart().isValid() )
372 to->setDtStart( from->dtStart() ); 461 to->setDtStart( from->dtStart() );
373 if ( from->dtEnd().isValid() ) 462 if ( from->dtEnd().isValid() )
374 to->setDtEnd( from->dtEnd() ); 463 to->setDtEnd( from->dtEnd() );
375 if ( !from->location().isEmpty() ) 464 if ( !from->location().isEmpty() )
376 to->setLocation( from->location() ); 465 to->setLocation( from->location() );
377 if ( !from->description().isEmpty() ) 466 if ( !from->description().isEmpty() )
378 to->setDescription( from->description() ); 467 to->setDescription( from->description() );
379 if ( !from->summary().isEmpty() ) 468 if ( !from->summary().isEmpty() )
380 to->setSummary( from->summary() ); 469 to->setSummary( from->summary() );
381 470
382 if ( from->alarms().count() ) { 471 if ( from->alarms().count() ) {
383 to->clearAlarms(); 472 to->clearAlarms();
384 Alarm *a = from->alarms().first(); 473 Alarm *a = from->alarms().first();
385 Alarm *b = to->newAlarm( ); 474 Alarm *b = to->newAlarm( );
386 b->setEnabled( a->enabled() ); 475 b->setEnabled( a->enabled() );
387 if ( a->hasStartOffset() ) { 476 if ( a->hasStartOffset() ) {
388 b->setStartOffset( a->startOffset() ); 477 b->setStartOffset( a->startOffset() );
389 } 478 }
390 if ( a->hasTime() ) 479 if ( a->hasTime() )
391 b->setTime( a->time() ); 480 b->setTime( a->time() );
392 481
393 } 482 }
394 QStringList cat = to->categories(); 483 QStringList cat = to->categories();
395 QStringList catFrom = from->categories(); 484 QStringList catFrom = from->categories();
396 QString nCat; 485 QString nCat;
397 int iii; 486 int iii;
398 for ( iii = 0; iii < catFrom.count();++iii ) { 487 for ( iii = 0; iii < catFrom.count();++iii ) {
399 nCat = catFrom[iii]; 488 nCat = catFrom[iii];
400 if ( !nCat.isEmpty() ) 489 if ( !nCat.isEmpty() )
401 if ( !cat.contains( nCat )) { 490 if ( !cat.contains( nCat )) {
402 cat << nCat; 491 cat << nCat;
403 } 492 }
404 } 493 }
405 to->setCategories( cat ); 494 to->setCategories( cat );
406 Recurrence * r = new Recurrence( *from->recurrence(),to); 495 Recurrence * r = new Recurrence( *from->recurrence(),to);
407 to->setRecurrence( r ) ; 496 to->setRecurrence( r ) ;
408 497
409 498
410} 499}
411void PhoneFormat::copyTodo( Todo* to, Todo* from ) 500void PhoneFormat::copyTodo( Todo* to, Todo* from )
412{ 501{
413 if ( from->dtStart().isValid() ) 502 if ( from->dtStart().isValid() )
414 to->setDtStart( from->dtStart() ); 503 to->setDtStart( from->dtStart() );
415 if ( from->dtDue().isValid() ) 504 if ( from->dtDue().isValid() )
416 to->setDtDue( from->dtDue() ); 505 to->setDtDue( from->dtDue() );
417 if ( !from->location().isEmpty() ) 506 if ( !from->location().isEmpty() )
418 to->setLocation( from->location() ); 507 to->setLocation( from->location() );
419 if ( !from->description().isEmpty() ) 508 if ( !from->description().isEmpty() )
420 to->setDescription( from->description() ); 509 to->setDescription( from->description() );
421 if ( !from->summary().isEmpty() ) 510 if ( !from->summary().isEmpty() )
422 to->setSummary( from->summary() ); 511 to->setSummary( from->summary() );
423 512
424 if ( from->alarms().count() ) { 513 if ( from->alarms().count() ) {
425 to->clearAlarms(); 514 to->clearAlarms();
426 Alarm *a = from->alarms().first(); 515 Alarm *a = from->alarms().first();
427 Alarm *b = to->newAlarm( ); 516 Alarm *b = to->newAlarm( );
428 b->setEnabled( a->enabled() ); 517 b->setEnabled( a->enabled() );
429 if ( a->hasStartOffset() ) 518 if ( a->hasStartOffset() )
430 b->setStartOffset( a->startOffset() ); 519 b->setStartOffset( a->startOffset() );
431 if ( a->hasTime() ) 520 if ( a->hasTime() )
432 b->setTime( a->time() ); 521 b->setTime( a->time() );
433 } 522 }
434 523
435 QStringList cat = to->categories(); 524 QStringList cat = to->categories();
436 QStringList catFrom = from->categories(); 525 QStringList catFrom = from->categories();
437 QString nCat; 526 QString nCat;
438 int iii; 527 int iii;
439 for ( iii = 0; iii < catFrom.count();++iii ) { 528 for ( iii = 0; iii < catFrom.count();++iii ) {
440 nCat = catFrom[iii]; 529 nCat = catFrom[iii];
441 if ( !nCat.isEmpty() ) 530 if ( !nCat.isEmpty() )
442 if ( !cat.contains( nCat )) { 531 if ( !cat.contains( nCat )) {
443 cat << nCat; 532 cat << nCat;
444 } 533 }
445 } 534 }
446 to->setCategories( cat ); 535 to->setCategories( cat );
447 if ( from->isCompleted() ) { 536 if ( from->isCompleted() ) {
448 to->setCompleted( true ); 537 to->setCompleted( true );
449 if( from->completed().isValid() ) 538 if( from->completed().isValid() )
450 to->setCompleted( from->completed() ); 539 to->setCompleted( from->completed() );
451 } else { 540 } else {
452 // set percentcomplete only, if to->isCompleted() 541 // set percentcomplete only, if to->isCompleted()
453 if ( to->isCompleted() ) 542 if ( to->isCompleted() )
454 to->setPercentComplete(from->percentComplete()); 543 to->setPercentComplete(from->percentComplete());
455 } 544 }
456 if( to->priority() == 2 && from->priority() == 1 ) 545 if( to->priority() == 2 && from->priority() == 1 )
457 ; //skip 546 ; //skip
458 else if (to->priority() == 4 && from->priority() == 5 ) 547 else if (to->priority() == 4 && from->priority() == 5 )
459 ; 548 ;
460 else 549 else
461 to->setPriority(from->priority()); 550 to->setPriority(from->priority());
462 551
463} 552}
464#include <qcstring.h> 553#include <qcstring.h>
465 554
466void PhoneFormat::afterSave( Incidence* inc) 555void PhoneFormat::afterSave( Incidence* inc)
467{ 556{
468 uint csum; 557 uint csum;
469 inc->removeID( mProfileName ); 558 inc->removeID( mProfileName );
470 if ( inc->type() == "Event") 559 if ( inc->type() == "Event")
471 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 560 csum = PhoneFormat::getCsumEvent( (Event*) inc );
472 else 561 else
473 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 562 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 8286098..2d1ff79 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -1,61 +1,61 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21#ifndef PHONEFORMAT_H 21#ifndef PHONEFORMAT_H
22#define PHONEFORMAT_H 22#define PHONEFORMAT_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25 25
26#include "scheduler.h" 26#include "scheduler.h"
27 27
28#include "vcalformat.h" 28#include "vcalformat.h"
29#include "calformat.h" 29#include "calformat.h"
30 30
31namespace KCal { 31namespace KCal {
32 32
33/** 33/**
34 This class implements the calendar format used by Phone. 34 This class implements the calendar format used by Phone.
35*/ 35*/
36 class Event; 36 class Event;
37 class Todo; 37 class Todo;
38class PhoneFormat : public QObject { 38class PhoneFormat : public QObject {
39 public: 39 public:
40 /** Create new iCalendar format. */ 40 /** Create new iCalendar format. */
41 PhoneFormat(QString profileName, QString device,QString connection, QString model); 41 PhoneFormat(QString profileName, QString device,QString connection, QString model);
42 virtual ~PhoneFormat(); 42 virtual ~PhoneFormat();
43 43
44 bool load( Calendar * ,Calendar * ); 44 bool load( Calendar * ,Calendar * );
45 bool save( Calendar * ); 45 bool save( Calendar * );
46 bool fromString( Calendar *, const QString & ); 46 bool fromString( Calendar *, const QString & );
47 QString toString( Calendar * ); 47 QString toString( Calendar * );
48 static ulong getCsum( const QStringList & ); 48 static ulong getCsum( const QStringList & );
49 static ulong getCsumTodo( Todo* to ); 49 static ulong getCsumTodo( Todo* to );
50 static ulong getCsumEvent( Event* ev ); 50 static ulong getCsumEvent( Event* ev );
51 private: 51 private:
52 void copyEvent( Event* to, Event* from ); 52 void copyEvent( Event* to, Event* from );
53 void copyTodo( Todo* to, Todo* from ); 53 void copyTodo( Todo* to, Todo* from );
54 //int initDevice(GSM_StateMachine *s); 54 //int initDevice(GSM_StateMachine *s);
55 QString mProfileName, mDevice, mConnection, mModel; 55 QString mProfileName;
56 void afterSave( Incidence* ); 56 void afterSave( Incidence* );
57}; 57};
58 58
59} 59}
60 60
61#endif 61#endif