summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp3
-rw-r--r--libkdepim/ksyncmanager.cpp2
2 files changed, 3 insertions, 2 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 2a57724..c33581c 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,722 +1,723 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
84{ 84{
85 Todo *todo;; 85 Todo *todo;;
86 Incidence *retVal = 0; 86 Incidence *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
89 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
90 if ( retVal ) { 90 if ( retVal ) {
91 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
92 retVal = todo; 92 retVal = todo;
93 } 93 }
94 } else { 94 } else {
95 retVal = todo; 95 retVal = todo;
96 } 96 }
97 } 97 }
98 } 98 }
99 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
100 Event *event; 100 Event *event;
101 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
102 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
103 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
104 if ( retVal ) { 104 if ( retVal ) {
105 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
106 retVal = event; 106 retVal = event;
107 } 107 }
108 } else { 108 } else {
109 retVal = event; 109 retVal = event;
110 } 110 }
111 } 111 }
112 } 112 }
113 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
115 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
116 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
117 if ( retVal ) { 117 if ( retVal ) {
118 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
119 retVal = it; 119 retVal = it;
120 } 120 }
121 } else { 121 } else {
122 retVal = it; 122 retVal = it;
123 } 123 }
124 } 124 }
125 return retVal; 125 return retVal;
126} 126}
127 127
128bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
129{ 129{
130 // 1 look for raw inc in local 130 // 1 look for raw inc in local
131 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
132 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
133 // if inc in local, replace it 133 // if inc in local, replace it
134 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
135 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
136 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
137 while ( inL ) { 137 while ( inL ) {
138 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
139 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
140 deleteIncidence( inL ); 140 deleteIncidence( inL );
141 inL = localInc.next(); 141 inL = localInc.next();
142 } 142 }
143 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
144 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
145 while ( inR ) { 145 while ( inR ) {
146 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
147 if ( inL ) { 147 if ( inL ) {
148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
149 int calID = inL->calID(); 149 int calID = inL->calID();
150 deleteIncidence( inL ); 150 deleteIncidence( inL );
151 inL = inR->clone(); 151 inL = inR->clone();
152 inL->setCalID( calID ); 152 inL->setCalID( calID );
153 addIncidence( inL ); 153 addIncidence( inL );
154 } 154 }
155 } else { 155 } else {
156 inL = inR->clone(); 156 inL = inR->clone();
157 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
158 addIncidence( inL ); 158 addIncidence( inL );
159 } 159 }
160 inR = er.next(); 160 inR = er.next();
161 } 161 }
162 return true; 162 return true;
163} 163}
164 164
165 165
166bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
167{ 167{
168 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
169 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
170 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
171 addCalendar( &calendar ); 171 addCalendar( &calendar );
172 return true; 172 return true;
173 } 173 }
174 return false; 174 return false;
175} 175}
176void CalendarLocal::setSyncEventsEnabled() 176void CalendarLocal::setSyncEventsEnabled()
177{ 177{
178 Event * ev; 178 Event * ev;
179 ev = mEventList.first(); 179 ev = mEventList.first();
180 while ( ev ) { 180 while ( ev ) {
181 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
182 ev->setCalEnabled( true ); 182 ev->setCalEnabled( true );
183 ev = mEventList.next(); 183 ev = mEventList.next();
184 } 184 }
185} 185}
186void CalendarLocal::setSyncEventsReadOnly() 186void CalendarLocal::setSyncEventsReadOnly()
187{ 187{
188 Event * ev; 188 Event * ev;
189 ev = mEventList.first(); 189 ev = mEventList.first();
190 while ( ev ) { 190 while ( ev ) {
191 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 191 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
192 ev->setReadOnly( true ); 192 ev->setReadOnly( true );
193 } 193 }
194 ev = mEventList.next(); 194 ev = mEventList.next();
195 } 195 }
196} 196}
197 197
198void CalendarLocal::addCalendar( Calendar* cal ) 198void CalendarLocal::addCalendar( Calendar* cal )
199{ 199{
200 cal->setDontDeleteIncidencesOnClose(); 200 cal->setDontDeleteIncidencesOnClose();
201 setSyncEventsEnabled(); 201 setSyncEventsEnabled();
202 { 202 {
203 QPtrList<Event> EventList = cal->rawEvents(); 203 QPtrList<Event> EventList = cal->rawEvents();
204 QPtrList<Event> el; 204 QPtrList<Event> el;
205 Event * ev = EventList.first(); 205 Event * ev = EventList.first();
206 while ( ev ) { 206 while ( ev ) {
207 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 207 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
208 Event * se = event( ev->uid() ); 208 Event * se = event( ev->uid() );
209 if ( se ) 209 if ( se )
210 el.append( se ); 210 el.append( se );
211 ev->setCalID( 1 );
211 } 212 }
212 ev->unRegisterObserver( cal ); 213 ev->unRegisterObserver( cal );
213 ev->registerObserver( this ); 214 ev->registerObserver( this );
214 mEventList.append( ev ); 215 mEventList.append( ev );
215 ev = EventList.next(); 216 ev = EventList.next();
216 } 217 }
217 for ( ev = el.first(); ev; ev = el.next() ) { 218 for ( ev = el.first(); ev; ev = el.next() ) {
218 deleteIncidence ( ev ); 219 deleteIncidence ( ev );
219 } 220 }
220 } 221 }
221 { 222 {
222 223
223 QPtrList<Todo> TodoList = cal->rawTodos(); 224 QPtrList<Todo> TodoList = cal->rawTodos();
224 Todo * ev = TodoList.first(); 225 Todo * ev = TodoList.first();
225 while ( ev ) { 226 while ( ev ) {
226 QString rel = ev->relatedToUid(); 227 QString rel = ev->relatedToUid();
227 if ( !rel.isEmpty() ){ 228 if ( !rel.isEmpty() ){
228 ev->setRelatedTo ( 0 ); 229 ev->setRelatedTo ( 0 );
229 ev->setRelatedToUid( rel ); 230 ev->setRelatedToUid( rel );
230 } 231 }
231 ev = TodoList.next(); 232 ev = TodoList.next();
232 } 233 }
233 //TodoList = cal->rawTodos(); 234 //TodoList = cal->rawTodos();
234 ev = TodoList.first(); 235 ev = TodoList.first();
235 while ( ev ) { 236 while ( ev ) {
236 ev->unRegisterObserver( cal ); 237 ev->unRegisterObserver( cal );
237 ev->registerObserver( this ); 238 ev->registerObserver( this );
238 mTodoList.append( ev ); 239 mTodoList.append( ev );
239 setupRelations( ev ); 240 setupRelations( ev );
240 ev = TodoList.next(); 241 ev = TodoList.next();
241 } 242 }
242 } 243 }
243 { 244 {
244 QPtrList<Journal> JournalList = cal->journals(); 245 QPtrList<Journal> JournalList = cal->journals();
245 Journal * ev = JournalList.first(); 246 Journal * ev = JournalList.first();
246 while ( ev ) { 247 while ( ev ) {
247 ev->unRegisterObserver( cal ); 248 ev->unRegisterObserver( cal );
248 ev->registerObserver( this ); 249 ev->registerObserver( this );
249 mJournalList.append( ev ); 250 mJournalList.append( ev );
250 ev = JournalList.next(); 251 ev = JournalList.next();
251 } 252 }
252 } 253 }
253 setModified( true ); 254 setModified( true );
254} 255}
255bool CalendarLocal::load( const QString &fileName ) 256bool CalendarLocal::load( const QString &fileName )
256{ 257{
257 FileStorage storage( this, fileName ); 258 FileStorage storage( this, fileName );
258 return storage.load(); 259 return storage.load();
259} 260}
260 261
261bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 262bool CalendarLocal::save( const QString &fileName, CalFormat *format )
262{ 263{
263 FileStorage storage( this, fileName, format ); 264 FileStorage storage( this, fileName, format );
264 return storage.save(); 265 return storage.save();
265} 266}
266 267
267void CalendarLocal::stopAllTodos() 268void CalendarLocal::stopAllTodos()
268{ 269{
269 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 270 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
270 it->setRunning( false ); 271 it->setRunning( false );
271 272
272} 273}
273void CalendarLocal::close() 274void CalendarLocal::close()
274{ 275{
275 276
276 Todo * i; 277 Todo * i;
277 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 278 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
278 279
279 mEventList.setAutoDelete( true ); 280 mEventList.setAutoDelete( true );
280 mTodoList.setAutoDelete( true ); 281 mTodoList.setAutoDelete( true );
281 mJournalList.setAutoDelete( true ); 282 mJournalList.setAutoDelete( true );
282 283
283 mEventList.clear(); 284 mEventList.clear();
284 mTodoList.clear(); 285 mTodoList.clear();
285 mJournalList.clear(); 286 mJournalList.clear();
286 287
287 mEventList.setAutoDelete( false ); 288 mEventList.setAutoDelete( false );
288 mTodoList.setAutoDelete( false ); 289 mTodoList.setAutoDelete( false );
289 mJournalList.setAutoDelete( false ); 290 mJournalList.setAutoDelete( false );
290 291
291 setModified( false ); 292 setModified( false );
292} 293}
293 294
294bool CalendarLocal::addAnniversaryNoDup( Event *event ) 295bool CalendarLocal::addAnniversaryNoDup( Event *event )
295{ 296{
296 QString cat; 297 QString cat;
297 bool isBirthday = true; 298 bool isBirthday = true;
298 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 299 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
299 isBirthday = false; 300 isBirthday = false;
300 cat = i18n( "Anniversary" ); 301 cat = i18n( "Anniversary" );
301 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 302 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
302 isBirthday = true; 303 isBirthday = true;
303 cat = i18n( "Birthday" ); 304 cat = i18n( "Birthday" );
304 } else { 305 } else {
305 qDebug("addAnniversaryNoDup called without fitting category! "); 306 qDebug("addAnniversaryNoDup called without fitting category! ");
306 return false; 307 return false;
307 } 308 }
308 Event * eve; 309 Event * eve;
309 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 310 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
310 if ( !(eve->categories().contains( cat ) )) 311 if ( !(eve->categories().contains( cat ) ))
311 continue; 312 continue;
312 // now we have an event with fitting category 313 // now we have an event with fitting category
313 if ( eve->dtStart().date() != event->dtStart().date() ) 314 if ( eve->dtStart().date() != event->dtStart().date() )
314 continue; 315 continue;
315 // now we have an event with fitting category+date 316 // now we have an event with fitting category+date
316 if ( eve->summary() != event->summary() ) 317 if ( eve->summary() != event->summary() )
317 continue; 318 continue;
318 // now we have an event with fitting category+date+summary 319 // now we have an event with fitting category+date+summary
319 return false; 320 return false;
320 } 321 }
321 return addEvent( event ); 322 return addEvent( event );
322 323
323} 324}
324bool CalendarLocal::addEventNoDup( Event *event ) 325bool CalendarLocal::addEventNoDup( Event *event )
325{ 326{
326 Event * eve; 327 Event * eve;
327 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 328 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
328 if ( *eve == *event ) { 329 if ( *eve == *event ) {
329 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 330 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
330 return false; 331 return false;
331 } 332 }
332 } 333 }
333 return addEvent( event ); 334 return addEvent( event );
334} 335}
335 336
336bool CalendarLocal::addEvent( Event *event ) 337bool CalendarLocal::addEvent( Event *event )
337{ 338{
338 insertEvent( event ); 339 insertEvent( event );
339 340
340 event->registerObserver( this ); 341 event->registerObserver( this );
341 342
342 setModified( true ); 343 setModified( true );
343 if ( event->calID() == 0 ) 344 if ( event->calID() == 0 )
344 event->setCalID( mDefaultCalendar ); 345 event->setCalID( mDefaultCalendar );
345 event->setCalEnabled( true ); 346 event->setCalEnabled( true );
346 347
347 return true; 348 return true;
348} 349}
349 350
350void CalendarLocal::deleteEvent( Event *event ) 351void CalendarLocal::deleteEvent( Event *event )
351{ 352{
352 clearUndo(event); 353 clearUndo(event);
353 if ( mEventList.removeRef( event ) ) { 354 if ( mEventList.removeRef( event ) ) {
354 setModified( true ); 355 setModified( true );
355 } 356 }
356} 357}
357 358
358 359
359Event *CalendarLocal::event( const QString &uid ) 360Event *CalendarLocal::event( const QString &uid )
360{ 361{
361 Event *event; 362 Event *event;
362 Event *retVal = 0; 363 Event *retVal = 0;
363 for ( event = mEventList.first(); event; event = mEventList.next() ) { 364 for ( event = mEventList.first(); event; event = mEventList.next() ) {
364 if ( event->calEnabled() && event->uid() == uid ) { 365 if ( event->calEnabled() && event->uid() == uid ) {
365 if ( retVal ) { 366 if ( retVal ) {
366 if ( retVal->calID() > event->calID() ) { 367 if ( retVal->calID() > event->calID() ) {
367 retVal = event; 368 retVal = event;
368 } 369 }
369 } else { 370 } else {
370 retVal = event; 371 retVal = event;
371 } 372 }
372 } 373 }
373 } 374 }
374 return retVal; 375 return retVal;
375} 376}
376bool CalendarLocal::addTodoNoDup( Todo *todo ) 377bool CalendarLocal::addTodoNoDup( Todo *todo )
377{ 378{
378 Todo * eve; 379 Todo * eve;
379 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 380 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
380 if ( *eve == *todo ) { 381 if ( *eve == *todo ) {
381 //qDebug("duplicate todo found! not inserted! "); 382 //qDebug("duplicate todo found! not inserted! ");
382 return false; 383 return false;
383 } 384 }
384 } 385 }
385 return addTodo( todo ); 386 return addTodo( todo );
386} 387}
387bool CalendarLocal::addTodo( Todo *todo ) 388bool CalendarLocal::addTodo( Todo *todo )
388{ 389{
389 mTodoList.append( todo ); 390 mTodoList.append( todo );
390 391
391 todo->registerObserver( this ); 392 todo->registerObserver( this );
392 393
393 // Set up subtask relations 394 // Set up subtask relations
394 setupRelations( todo ); 395 setupRelations( todo );
395 396
396 setModified( true ); 397 setModified( true );
397 if ( todo->calID() == 0 ) 398 if ( todo->calID() == 0 )
398 todo->setCalID( mDefaultCalendar ); 399 todo->setCalID( mDefaultCalendar );
399 todo->setCalEnabled( true ); 400 todo->setCalEnabled( true );
400 return true; 401 return true;
401} 402}
402 403
403void CalendarLocal::deleteTodo( Todo *todo ) 404void CalendarLocal::deleteTodo( Todo *todo )
404{ 405{
405 // Handle orphaned children 406 // Handle orphaned children
406 removeRelations( todo ); 407 removeRelations( todo );
407 clearUndo(todo); 408 clearUndo(todo);
408 409
409 if ( mTodoList.removeRef( todo ) ) { 410 if ( mTodoList.removeRef( todo ) ) {
410 setModified( true ); 411 setModified( true );
411 } 412 }
412} 413}
413 414
414QPtrList<Todo> CalendarLocal::rawTodos() 415QPtrList<Todo> CalendarLocal::rawTodos()
415{ 416{
416 QPtrList<Todo> el; 417 QPtrList<Todo> el;
417 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 418 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
418 if ( it->calEnabled() ) el.append( it ); 419 if ( it->calEnabled() ) el.append( it );
419 return el; 420 return el;
420} 421}
421Todo *CalendarLocal::todo( QString syncProf, QString id ) 422Todo *CalendarLocal::todo( QString syncProf, QString id )
422{ 423{
423 Todo *todo; 424 Todo *todo;
424 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 425 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
425 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 426 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
426 } 427 }
427 428
428 return 0; 429 return 0;
429} 430}
430void CalendarLocal::removeSyncInfo( QString syncProfile) 431void CalendarLocal::removeSyncInfo( QString syncProfile)
431{ 432{
432 QPtrList<Incidence> all = rawIncidences() ; 433 QPtrList<Incidence> all = rawIncidences() ;
433 Incidence *inc; 434 Incidence *inc;
434 for ( inc = all.first(); inc; inc = all.next() ) { 435 for ( inc = all.first(); inc; inc = all.next() ) {
435 inc->removeID( syncProfile ); 436 inc->removeID( syncProfile );
436 } 437 }
437 if ( syncProfile.isEmpty() ) { 438 if ( syncProfile.isEmpty() ) {
438 QPtrList<Event> el; 439 QPtrList<Event> el;
439 Event *todo; 440 Event *todo;
440 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 441 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
441 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 442 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
442 el.append( todo ); 443 el.append( todo );
443 } 444 }
444 for ( todo = el.first(); todo; todo = el.next() ) { 445 for ( todo = el.first(); todo; todo = el.next() ) {
445 deleteIncidence ( todo ); 446 deleteIncidence ( todo );
446 } 447 }
447 } else { 448 } else {
448 Event *lse = event( "last-syncEvent-"+ syncProfile); 449 Event *lse = event( "last-syncEvent-"+ syncProfile);
449 if ( lse ) 450 if ( lse )
450 deleteIncidence ( lse ); 451 deleteIncidence ( lse );
451 } 452 }
452} 453}
453QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 454QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
454{ 455{
455 QPtrList<Event> el; 456 QPtrList<Event> el;
456 Event *todo; 457 Event *todo;
457 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 458 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
458 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 459 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
459 if ( todo->summary().left(3) == "E: " ) 460 if ( todo->summary().left(3) == "E: " )
460 el.append( todo ); 461 el.append( todo );
461 } 462 }
462 463
463 return el; 464 return el;
464 465
465} 466}
466Event *CalendarLocal::event( QString syncProf, QString id ) 467Event *CalendarLocal::event( QString syncProf, QString id )
467{ 468{
468 Event *todo; 469 Event *todo;
469 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 470 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
470 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 471 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
471 } 472 }
472 473
473 return 0; 474 return 0;
474} 475}
475Todo *CalendarLocal::todo( const QString &uid ) 476Todo *CalendarLocal::todo( const QString &uid )
476{ 477{
477 Todo *todo; 478 Todo *todo;
478 Todo *retVal = 0; 479 Todo *retVal = 0;
479 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 480 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
480 if ( todo->calEnabled() && todo->uid() == uid ) { 481 if ( todo->calEnabled() && todo->uid() == uid ) {
481 if ( retVal ) { 482 if ( retVal ) {
482 if ( retVal->calID() > todo->calID() ) { 483 if ( retVal->calID() > todo->calID() ) {
483 retVal = todo; 484 retVal = todo;
484 } 485 }
485 } else { 486 } else {
486 retVal = todo; 487 retVal = todo;
487 } 488 }
488 } 489 }
489 } 490 }
490 return retVal; 491 return retVal;
491} 492}
492void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 493void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
493{ 494{
494 events = 0; 495 events = 0;
495 todos = 0; 496 todos = 0;
496 journals = 0; 497 journals = 0;
497 { 498 {
498 Todo *todo; 499 Todo *todo;
499 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 500 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
500 if ( todo->calID() == calId ) 501 if ( todo->calID() == calId )
501 ++todos; 502 ++todos;
502 } 503 }
503 } 504 }
504 { 505 {
505 Event *todo; 506 Event *todo;
506 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 507 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
507 if ( todo->calID() == calId ) 508 if ( todo->calID() == calId )
508 ++events; 509 ++events;
509 510
510 } 511 }
511 } 512 }
512 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 513 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
513 if ( it->calID() == calId ) ++journals; 514 if ( it->calID() == calId ) ++journals;
514 515
515} 516}
516QString CalendarLocal::nextSummary() const 517QString CalendarLocal::nextSummary() const
517{ 518{
518 return mNextSummary; 519 return mNextSummary;
519} 520}
520QDateTime CalendarLocal::nextAlarmEventDateTime() const 521QDateTime CalendarLocal::nextAlarmEventDateTime() const
521{ 522{
522 return mNextAlarmEventDateTime; 523 return mNextAlarmEventDateTime;
523} 524}
524void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 525void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
525{ 526{
526 //mNextAlarmIncidence 527 //mNextAlarmIncidence
527 //mNextAlarmDateTime 528 //mNextAlarmDateTime
528 //return mNextSummary; 529 //return mNextSummary;
529 //return mNextAlarmEventDateTime; 530 //return mNextAlarmEventDateTime;
530 bool newNextAlarm = false; 531 bool newNextAlarm = false;
531 bool computeNextAlarm = false; 532 bool computeNextAlarm = false;
532 bool ok; 533 bool ok;
533 int offset; 534 int offset;
534 QDateTime nextA; 535 QDateTime nextA;
535 // QString nextSum; 536 // QString nextSum;
536 //QDateTime nextEvent; 537 //QDateTime nextEvent;
537 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 538 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
538 computeNextAlarm = true; 539 computeNextAlarm = true;
539 } else { 540 } else {
540 if ( ! deleted ) { 541 if ( ! deleted ) {
541 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 542 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
542 if ( ok ) { 543 if ( ok ) {
543 if ( nextA < mNextAlarmDateTime ) { 544 if ( nextA < mNextAlarmDateTime ) {
544 deRegisterAlarm(); 545 deRegisterAlarm();
545 mNextAlarmDateTime = nextA; 546 mNextAlarmDateTime = nextA;
546 mNextSummary = incidence->summary(); 547 mNextSummary = incidence->summary();
547 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 548 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
548 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 549 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
549 newNextAlarm = true; 550 newNextAlarm = true;
550 mNextAlarmIncidence = incidence; 551 mNextAlarmIncidence = incidence;
551 } else { 552 } else {
552 if ( incidence == mNextAlarmIncidence ) { 553 if ( incidence == mNextAlarmIncidence ) {
553 computeNextAlarm = true; 554 computeNextAlarm = true;
554 } 555 }
555 } 556 }
556 } else { 557 } else {
557 if ( mNextAlarmIncidence == incidence ) { 558 if ( mNextAlarmIncidence == incidence ) {
558 computeNextAlarm = true; 559 computeNextAlarm = true;
559 } 560 }
560 } 561 }
561 } else { // deleted 562 } else { // deleted
562 if ( incidence == mNextAlarmIncidence ) { 563 if ( incidence == mNextAlarmIncidence ) {
563 computeNextAlarm = true; 564 computeNextAlarm = true;
564 } 565 }
565 } 566 }
566 } 567 }
567 if ( computeNextAlarm ) { 568 if ( computeNextAlarm ) {
568 deRegisterAlarm(); 569 deRegisterAlarm();
569 nextA = nextAlarm( 1000 ); 570 nextA = nextAlarm( 1000 );
570 if (! mNextAlarmIncidence ) { 571 if (! mNextAlarmIncidence ) {
571 return; 572 return;
572 } 573 }
573 newNextAlarm = true; 574 newNextAlarm = true;
574 } 575 }
575 if ( newNextAlarm ) 576 if ( newNextAlarm )
576 registerAlarm(); 577 registerAlarm();
577} 578}
578QString CalendarLocal:: getAlarmNotification() 579QString CalendarLocal:: getAlarmNotification()
579{ 580{
580 QString ret; 581 QString ret;
581 // this should not happen 582 // this should not happen
582 if (! mNextAlarmIncidence ) 583 if (! mNextAlarmIncidence )
583 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 584 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
584 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 585 Alarm* alarm = mNextAlarmIncidence->alarms().first();
585 if ( alarm->type() == Alarm::Procedure ) { 586 if ( alarm->type() == Alarm::Procedure ) {
586 ret = "proc_alarm" + alarm->programFile()+"+++"; 587 ret = "proc_alarm" + alarm->programFile()+"+++";
587 } else { 588 } else {
588 ret = "audio_alarm" +alarm->audioFile() +"+++"; 589 ret = "audio_alarm" +alarm->audioFile() +"+++";
589 } 590 }
590 ret += "cal_alarm"+ mNextSummary.left( 25 ); 591 ret += "cal_alarm"+ mNextSummary.left( 25 );
591 if ( mNextSummary.length() > 25 ) 592 if ( mNextSummary.length() > 25 )
592 ret += "\n" + mNextSummary.mid(25, 25 ); 593 ret += "\n" + mNextSummary.mid(25, 25 );
593 ret+= "\n"+mNextAlarmEventDateTimeString; 594 ret+= "\n"+mNextAlarmEventDateTimeString;
594 return ret; 595 return ret;
595} 596}
596void CalendarLocal::registerAlarm() 597void CalendarLocal::registerAlarm()
597{ 598{
598 mLastAlarmNotificationString = getAlarmNotification(); 599 mLastAlarmNotificationString = getAlarmNotification();
599 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 600 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
600 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 601 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
601// #ifndef DESKTOP_VERSION 602// #ifndef DESKTOP_VERSION
602// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 603// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
603// #endif 604// #endif
604} 605}
605void CalendarLocal::deRegisterAlarm() 606void CalendarLocal::deRegisterAlarm()
606{ 607{
607 if ( mLastAlarmNotificationString.isNull() ) 608 if ( mLastAlarmNotificationString.isNull() )
608 return; 609 return;
609 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 610 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
610 611
611 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 612 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
612 mNextAlarmEventDateTime = QDateTime(); 613 mNextAlarmEventDateTime = QDateTime();
613// #ifndef DESKTOP_VERSION 614// #ifndef DESKTOP_VERSION
614// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 615// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
615// #endif 616// #endif
616} 617}
617 618
618QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 619QPtrList<Todo> CalendarLocal::todos( const QDate &date )
619{ 620{
620 QPtrList<Todo> todos; 621 QPtrList<Todo> todos;
621 622
622 Todo *todo; 623 Todo *todo;
623 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 624 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
624 if ( !todo->calEnabled() ) continue; 625 if ( !todo->calEnabled() ) continue;
625 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 626 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
626 todos.append( todo ); 627 todos.append( todo );
627 } 628 }
628 } 629 }
629 630
630 filter()->apply( &todos ); 631 filter()->apply( &todos );
631 return todos; 632 return todos;
632} 633}
633void CalendarLocal::reInitAlarmSettings() 634void CalendarLocal::reInitAlarmSettings()
634{ 635{
635 if ( !mNextAlarmIncidence ) { 636 if ( !mNextAlarmIncidence ) {
636 nextAlarm( 1000 ); 637 nextAlarm( 1000 );
637 } 638 }
638 deRegisterAlarm(); 639 deRegisterAlarm();
639 mNextAlarmIncidence = 0; 640 mNextAlarmIncidence = 0;
640 checkAlarmForIncidence( 0, false ); 641 checkAlarmForIncidence( 0, false );
641 642
642} 643}
643 644
644 645
645 646
646QDateTime CalendarLocal::nextAlarm( int daysTo ) 647QDateTime CalendarLocal::nextAlarm( int daysTo )
647{ 648{
648 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 649 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
649 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 650 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
650 QDateTime next; 651 QDateTime next;
651 Event *e; 652 Event *e;
652 bool ok; 653 bool ok;
653 bool found = false; 654 bool found = false;
654 int offset; 655 int offset;
655 mNextAlarmIncidence = 0; 656 mNextAlarmIncidence = 0;
656 for( e = mEventList.first(); e; e = mEventList.next() ) { 657 for( e = mEventList.first(); e; e = mEventList.next() ) {
657 if ( !e->calEnabled() ) continue; 658 if ( !e->calEnabled() ) continue;
658 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 659 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
659 if ( ok ) { 660 if ( ok ) {
660 if ( next < nextA ) { 661 if ( next < nextA ) {
661 nextA = next; 662 nextA = next;
662 found = true; 663 found = true;
663 mNextSummary = e->summary(); 664 mNextSummary = e->summary();
664 mNextAlarmEventDateTime = next.addSecs(offset ) ; 665 mNextAlarmEventDateTime = next.addSecs(offset ) ;
665 mNextAlarmIncidence = (Incidence *) e; 666 mNextAlarmIncidence = (Incidence *) e;
666 } 667 }
667 } 668 }
668 } 669 }
669 Todo *t; 670 Todo *t;
670 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 671 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
671 if ( !t->calEnabled() ) continue; 672 if ( !t->calEnabled() ) continue;
672 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 673 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
673 if ( ok ) { 674 if ( ok ) {
674 if ( next < nextA ) { 675 if ( next < nextA ) {
675 nextA = next; 676 nextA = next;
676 found = true; 677 found = true;
677 mNextSummary = t->summary(); 678 mNextSummary = t->summary();
678 mNextAlarmEventDateTime = next.addSecs(offset ); 679 mNextAlarmEventDateTime = next.addSecs(offset );
679 mNextAlarmIncidence = (Incidence *) t; 680 mNextAlarmIncidence = (Incidence *) t;
680 } 681 }
681 } 682 }
682 } 683 }
683 if ( mNextAlarmIncidence ) { 684 if ( mNextAlarmIncidence ) {
684 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 685 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
685 mNextAlarmDateTime = nextA; 686 mNextAlarmDateTime = nextA;
686 } 687 }
687 return nextA; 688 return nextA;
688} 689}
689Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 690Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
690{ 691{
691 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 692 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
692} 693}
693 694
694Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 695Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
695{ 696{
696 697
697 Alarm::List alarms; 698 Alarm::List alarms;
698 699
699 Event *e; 700 Event *e;
700 701
701 for( e = mEventList.first(); e; e = mEventList.next() ) { 702 for( e = mEventList.first(); e; e = mEventList.next() ) {
702 if ( !e->calEnabled() ) continue; 703 if ( !e->calEnabled() ) continue;
703 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 704 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
704 else appendAlarms( alarms, e, from, to ); 705 else appendAlarms( alarms, e, from, to );
705 } 706 }
706 707
707 Todo *t; 708 Todo *t;
708 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 709 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
709 if ( !t->calEnabled() ) continue; 710 if ( !t->calEnabled() ) continue;
710 appendAlarms( alarms, t, from, to ); 711 appendAlarms( alarms, t, from, to );
711 } 712 }
712 713
713 return alarms; 714 return alarms;
714} 715}
715 716
716void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 717void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
717 const QDateTime &from, const QDateTime &to ) 718 const QDateTime &from, const QDateTime &to )
718{ 719{
719 QPtrList<Alarm> alarmList = incidence->alarms(); 720 QPtrList<Alarm> alarmList = incidence->alarms();
720 Alarm *alarm; 721 Alarm *alarm;
721 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 722 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
722// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 723// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index d2cb71b..e1b15d2 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1264,515 +1264,515 @@ KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject
1264void KServerSocket::newConnection ( int socket ) 1264void KServerSocket::newConnection ( int socket )
1265{ 1265{
1266 // qDebug("KServerSocket:New connection %d ", socket); 1266 // qDebug("KServerSocket:New connection %d ", socket);
1267 if ( mSocket ) { 1267 if ( mSocket ) {
1268 qDebug("KSS::newConnection Socket deleted! "); 1268 qDebug("KSS::newConnection Socket deleted! ");
1269 delete mSocket; 1269 delete mSocket;
1270 mSocket = 0; 1270 mSocket = 0;
1271 } 1271 }
1272 mSocket = new QSocket( this ); 1272 mSocket = new QSocket( this );
1273 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1273 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1274 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1274 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1275 mSocket->setSocket( socket ); 1275 mSocket->setSocket( socket );
1276} 1276}
1277 1277
1278void KServerSocket::discardClient() 1278void KServerSocket::discardClient()
1279{ 1279{
1280 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1280 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1281} 1281}
1282void KServerSocket::deleteSocket() 1282void KServerSocket::deleteSocket()
1283{ 1283{
1284 qDebug("KSS::deleteSocket"); 1284 qDebug("KSS::deleteSocket");
1285 if ( mSocket ) { 1285 if ( mSocket ) {
1286 delete mSocket; 1286 delete mSocket;
1287 mSocket = 0; 1287 mSocket = 0;
1288 } 1288 }
1289 if ( mErrorMessage ) 1289 if ( mErrorMessage )
1290 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1290 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1291} 1291}
1292void KServerSocket::readClient() 1292void KServerSocket::readClient()
1293{ 1293{
1294 if ( blockRC ) 1294 if ( blockRC )
1295 return; 1295 return;
1296 if ( mSocket == 0 ) { 1296 if ( mSocket == 0 ) {
1297 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1297 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1298 return; 1298 return;
1299 } 1299 }
1300 if ( mErrorMessage ) { 1300 if ( mErrorMessage ) {
1301 mErrorMessage = 999; 1301 mErrorMessage = 999;
1302 error_connect("ERROR_ED\r\n\r\n"); 1302 error_connect("ERROR_ED\r\n\r\n");
1303 return; 1303 return;
1304 } 1304 }
1305 mResource = ""; 1305 mResource = "";
1306 mErrorMessage = 0; 1306 mErrorMessage = 0;
1307 //qDebug("KServerSocket::readClient()"); 1307 //qDebug("KServerSocket::readClient()");
1308 if ( mSocket->canReadLine() ) { 1308 if ( mSocket->canReadLine() ) {
1309 QString line = mSocket->readLine(); 1309 QString line = mSocket->readLine();
1310 //qDebug("KServerSocket readline: %s ", line.latin1()); 1310 //qDebug("KServerSocket readline: %s ", line.latin1());
1311 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1311 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1312 if ( tokens[0] == "GET" ) { 1312 if ( tokens[0] == "GET" ) {
1313 if ( tokens[1] == mPassWord ) { 1313 if ( tokens[1] == mPassWord ) {
1314 //emit sendFile( mSocket ); 1314 //emit sendFile( mSocket );
1315 bool ok = false; 1315 bool ok = false;
1316 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1316 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1317 if ( ok ) { 1317 if ( ok ) {
1318 KSyncManager::mRequestedSyncEvent = dt; 1318 KSyncManager::mRequestedSyncEvent = dt;
1319 } 1319 }
1320 else 1320 else
1321 KSyncManager::mRequestedSyncEvent = QDateTime(); 1321 KSyncManager::mRequestedSyncEvent = QDateTime();
1322 mResource =tokens[3]; 1322 mResource =tokens[3];
1323 send_file(); 1323 send_file();
1324 } 1324 }
1325 else { 1325 else {
1326 mErrorMessage = 1; 1326 mErrorMessage = 1;
1327 error_connect("ERROR_PW\r\n\r\n"); 1327 error_connect("ERROR_PW\r\n\r\n");
1328 } 1328 }
1329 } 1329 }
1330 if ( tokens[0] == "PUT" ) { 1330 if ( tokens[0] == "PUT" ) {
1331 if ( tokens[1] == mPassWord ) { 1331 if ( tokens[1] == mPassWord ) {
1332 //emit getFile( mSocket ); 1332 //emit getFile( mSocket );
1333 blockRC = true; 1333 blockRC = true;
1334 mResource =tokens[2]; 1334 mResource =tokens[2];
1335 get_file(); 1335 get_file();
1336 } 1336 }
1337 else { 1337 else {
1338 mErrorMessage = 2; 1338 mErrorMessage = 2;
1339 error_connect("ERROR_PW\r\n\r\n"); 1339 error_connect("ERROR_PW\r\n\r\n");
1340 end_connect(); 1340 end_connect();
1341 } 1341 }
1342 } 1342 }
1343 if ( tokens[0] == "STOP" ) { 1343 if ( tokens[0] == "STOP" ) {
1344 //emit endConnect(); 1344 //emit endConnect();
1345 end_connect(); 1345 end_connect();
1346 } 1346 }
1347 } 1347 }
1348} 1348}
1349void KServerSocket::displayErrorMessage() 1349void KServerSocket::displayErrorMessage()
1350{ 1350{
1351 if ( mErrorMessage == 1 ) { 1351 if ( mErrorMessage == 1 ) {
1352 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1352 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1353 mErrorMessage = 0; 1353 mErrorMessage = 0;
1354 } 1354 }
1355 else if ( mErrorMessage == 2 ) { 1355 else if ( mErrorMessage == 2 ) {
1356 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1356 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1357 mErrorMessage = 0; 1357 mErrorMessage = 0;
1358 } 1358 }
1359} 1359}
1360void KServerSocket::error_connect( QString errmess ) 1360void KServerSocket::error_connect( QString errmess )
1361{ 1361{
1362 QTextStream os( mSocket ); 1362 QTextStream os( mSocket );
1363 os.setEncoding( QTextStream::Latin1 ); 1363 os.setEncoding( QTextStream::Latin1 );
1364 os << errmess ; 1364 os << errmess ;
1365 mSocket->close(); 1365 mSocket->close();
1366 if ( mSocket->state() == QSocket::Idle ) { 1366 if ( mSocket->state() == QSocket::Idle ) {
1367 QTimer::singleShot( 0, this , SLOT ( discardClient())); 1367 QTimer::singleShot( 0, this , SLOT ( discardClient()));
1368 } 1368 }
1369} 1369}
1370void KServerSocket::end_connect() 1370void KServerSocket::end_connect()
1371{ 1371{
1372 delete mSyncActionDialog; 1372 delete mSyncActionDialog;
1373 mSyncActionDialog = 0; 1373 mSyncActionDialog = 0;
1374} 1374}
1375void KServerSocket::send_file() 1375void KServerSocket::send_file()
1376{ 1376{
1377 //qDebug("MainWindow::sendFile(QSocket* s) "); 1377 //qDebug("MainWindow::sendFile(QSocket* s) ");
1378 if ( mSyncActionDialog ) 1378 if ( mSyncActionDialog )
1379 delete mSyncActionDialog; 1379 delete mSyncActionDialog;
1380 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1380 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1381 mSyncActionDialog->setCaption(i18n("Received sync request")); 1381 mSyncActionDialog->setCaption(i18n("Received sync request"));
1382 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1382 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1383 label->setAlignment ( Qt::AlignHCenter ); 1383 label->setAlignment ( Qt::AlignHCenter );
1384 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1384 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1385 lay->addWidget( label); 1385 lay->addWidget( label);
1386 lay->setMargin(7); 1386 lay->setMargin(7);
1387 lay->setSpacing(7); 1387 lay->setSpacing(7);
1388 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1388 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1389 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1389 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1390 //secs = 333; 1390 //secs = 333;
1391 if ( secs < 0 ) 1391 if ( secs < 0 )
1392 secs = secs * (-1); 1392 secs = secs * (-1);
1393 if ( secs > 30 ) 1393 if ( secs > 30 )
1394 //if ( true ) 1394 //if ( true )
1395 { 1395 {
1396 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1396 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1397 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1397 QLabel* label = new QLabel( warning, mSyncActionDialog );
1398 label->setAlignment ( Qt::AlignHCenter ); 1398 label->setAlignment ( Qt::AlignHCenter );
1399 lay->addWidget( label); 1399 lay->addWidget( label);
1400 if ( secs > 180 ) 1400 if ( secs > 180 )
1401 { 1401 {
1402 if ( secs > 300 ) { 1402 if ( secs > 300 ) {
1403 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1403 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1404 qDebug("KSS::Sync cancelled ,cs"); 1404 qDebug("KSS::Sync cancelled ,cs");
1405 mErrorMessage = 0; 1405 mErrorMessage = 0;
1406 end_connect(); 1406 end_connect();
1407 error_connect("ERROR_CA\r\n\r\n"); 1407 error_connect("ERROR_CA\r\n\r\n");
1408 return ; 1408 return ;
1409 } 1409 }
1410 } 1410 }
1411 QFont f = label->font(); 1411 QFont f = label->font();
1412 f.setPointSize ( f.pointSize() *2 ); 1412 f.setPointSize ( f.pointSize() *2 );
1413 f. setBold (true ); 1413 f. setBold (true );
1414 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1414 QLabel* label = new QLabel( warning, mSyncActionDialog );
1415 label->setFont( f ); 1415 label->setFont( f );
1416 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1416 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1417 label->setText( warning ); 1417 label->setText( warning );
1418 label->setAlignment ( Qt::AlignHCenter ); 1418 label->setAlignment ( Qt::AlignHCenter );
1419 lay->addWidget( label); 1419 lay->addWidget( label);
1420 mSyncActionDialog->setFixedSize( 230, 300); 1420 mSyncActionDialog->setFixedSize( 230, 300);
1421 } else { 1421 } else {
1422 mSyncActionDialog->setFixedSize( 230, 200); 1422 mSyncActionDialog->setFixedSize( 230, 200);
1423 } 1423 }
1424 } else { 1424 } else {
1425 mSyncActionDialog->setFixedSize( 230, 120); 1425 mSyncActionDialog->setFixedSize( 230, 120);
1426 } 1426 }
1427 } else 1427 } else
1428 mSyncActionDialog->setFixedSize( 230, 120); 1428 mSyncActionDialog->setFixedSize( 230, 120);
1429 mSyncActionDialog->show(); 1429 mSyncActionDialog->show();
1430 mSyncActionDialog->raise(); 1430 mSyncActionDialog->raise();
1431 emit request_file(mResource); 1431 emit request_file(mResource);
1432 emit request_file(); 1432 emit request_file();
1433 qApp->processEvents(); 1433 qApp->processEvents();
1434 QString fileName = mFileName; 1434 QString fileName = mFileName;
1435 QFile file( fileName ); 1435 QFile file( fileName );
1436 if (!file.open( IO_ReadOnly ) ) { 1436 if (!file.open( IO_ReadOnly ) ) {
1437 mErrorMessage = 0; 1437 mErrorMessage = 0;
1438 end_connect(); 1438 end_connect();
1439 error_connect("ERROR_FI\r\n\r\n"); 1439 error_connect("ERROR_FI\r\n\r\n");
1440 return ; 1440 return ;
1441 } 1441 }
1442 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1442 mSyncActionDialog->setCaption( i18n("Sending file...") );
1443 QTextStream ts( &file ); 1443 QTextStream ts( &file );
1444 ts.setEncoding( QTextStream::Latin1 ); 1444 ts.setEncoding( QTextStream::Latin1 );
1445 1445
1446 QTextStream os( mSocket ); 1446 QTextStream os( mSocket );
1447 os.setEncoding( QTextStream::Latin1 ); 1447 os.setEncoding( QTextStream::Latin1 );
1448 while ( ! ts.atEnd() ) { 1448 while ( ! ts.atEnd() ) {
1449 os << ts.readLine() << "\r\n"; 1449 os << ts.readLine() << "\r\n";
1450 } 1450 }
1451 os << "\r\n"; 1451 os << "\r\n";
1452 //os << ts.read(); 1452 //os << ts.read();
1453 file.close(); 1453 file.close();
1454 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1454 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1455 mSocket->close(); 1455 mSocket->close();
1456 if ( mSocket->state() == QSocket::Idle ) 1456 if ( mSocket->state() == QSocket::Idle )
1457 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1457 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1458} 1458}
1459void KServerSocket::get_file() 1459void KServerSocket::get_file()
1460{ 1460{
1461 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1461 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1462 1462
1463 piTime.start(); 1463 piTime.start();
1464 piFileString = ""; 1464 piFileString = "";
1465 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1465 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1466} 1466}
1467 1467
1468 1468
1469void KServerSocket::readBackFileFromSocket() 1469void KServerSocket::readBackFileFromSocket()
1470{ 1470{
1471 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1471 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1472 while ( mSocket->canReadLine () ) { 1472 while ( mSocket->canReadLine () ) {
1473 piTime.restart(); 1473 piTime.restart();
1474 QString line = mSocket->readLine (); 1474 QString line = mSocket->readLine ();
1475 piFileString += line; 1475 piFileString += line;
1476 //qDebug("readline: %s ", line.latin1()); 1476 //qDebug("readline: %s ", line.latin1());
1477 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1477 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1478 1478
1479 } 1479 }
1480 if ( piTime.elapsed () < 3000 ) { 1480 if ( piTime.elapsed () < 3000 ) {
1481 // wait for more 1481 // wait for more
1482 //qDebug("waitformore "); 1482 //qDebug("waitformore ");
1483 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1483 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1484 return; 1484 return;
1485 } 1485 }
1486 QString fileName = mFileName; 1486 QString fileName = mFileName;
1487 QFile file ( fileName ); 1487 QFile file ( fileName );
1488 if (!file.open( IO_WriteOnly ) ) { 1488 if (!file.open( IO_WriteOnly ) ) {
1489 delete mSyncActionDialog; 1489 delete mSyncActionDialog;
1490 mSyncActionDialog = 0; 1490 mSyncActionDialog = 0;
1491 qDebug("KSS:Error open read back file "); 1491 qDebug("KSS:Error open read back file ");
1492 piFileString = ""; 1492 piFileString = "";
1493 emit file_received( false, mResource); 1493 emit file_received( false, mResource);
1494 emit file_received( false); 1494 emit file_received( false);
1495 blockRC = false; 1495 blockRC = false;
1496 return ; 1496 return ;
1497 1497
1498 } 1498 }
1499 1499
1500 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1500 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1501 QTextStream ts ( &file ); 1501 QTextStream ts ( &file );
1502 ts.setEncoding( QTextStream::Latin1 ); 1502 ts.setEncoding( QTextStream::Latin1 );
1503 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1503 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1504 ts << piFileString; 1504 ts << piFileString;
1505 mSocket->close(); 1505 mSocket->close();
1506 if ( mSocket->state() == QSocket::Idle ) 1506 if ( mSocket->state() == QSocket::Idle )
1507 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1507 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1508 file.close(); 1508 file.close();
1509 piFileString = ""; 1509 piFileString = "";
1510 emit file_received( true, mResource ); 1510 emit file_received( true, mResource );
1511 emit file_received( true); 1511 emit file_received( true);
1512 delete mSyncActionDialog; 1512 delete mSyncActionDialog;
1513 mSyncActionDialog = 0; 1513 mSyncActionDialog = 0;
1514 blockRC = false; 1514 blockRC = false;
1515 1515
1516} 1516}
1517 1517
1518KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1518KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1519{ 1519{
1520 mRemoteResource = remres; 1520 mRemoteResource = remres;
1521 if ( mRemoteResource.isEmpty() ) 1521 if ( mRemoteResource.isEmpty() )
1522 mRemoteResource = "ALL"; 1522 mRemoteResource = "ALL";
1523 else 1523 else
1524 mRemoteResource.replace (QRegExp (" "),"_" ); 1524 mRemoteResource.replace (QRegExp (" "),"_" );
1525 mPassWord = password; 1525 mPassWord = password;
1526 mSocket = 0; 1526 mSocket = 0;
1527 mFirst = false; 1527 mFirst = false;
1528 mFirstLine = true; 1528 mFirstLine = true;
1529 mPort = port; 1529 mPort = port;
1530 mHost = host; 1530 mHost = host;
1531 tlw = cap; 1531 tlw = cap;
1532 mRetVal = quiet; 1532 mRetVal = quiet;
1533 mTimerSocket = new QTimer ( this ); 1533 mTimerSocket = new QTimer ( this );
1534 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1534 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1535 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1535 mConnectProgress.setCaption( i18n("Pi-Sync") );
1536 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1536 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1537 mConnectCount = -1; 1537 mConnectCount = -1;
1538} 1538}
1539void KCommandSocket::sendFileRequest() 1539void KCommandSocket::sendFileRequest()
1540{ 1540{
1541 if ( tlw ) 1541 if ( tlw )
1542 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1542 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1543 mConnectProgress.hide(); 1543 mConnectProgress.hide();
1544 mConnectCount = 300;mConnectMax = 300; 1544 mConnectCount = 300;mConnectMax = 300;
1545 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1545 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1546 mTimerSocket->start( 100, true ); 1546 mTimerSocket->start( 100, true );
1547 QTextStream os( mSocket ); 1547 QTextStream os( mSocket );
1548 os.setEncoding( QTextStream::Latin1 ); 1548 os.setEncoding( QTextStream::Latin1 );
1549 1549
1550 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1550 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1551 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; 1551 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n";
1552} 1552}
1553 1553
1554void KCommandSocket::readFile( QString fn ) 1554void KCommandSocket::readFile( QString fn )
1555{ 1555{
1556 if ( !mSocket ) { 1556 if ( !mSocket ) {
1557 mSocket = new QSocket( this ); 1557 mSocket = new QSocket( this );
1558 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1558 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1559 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1559 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1560 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1560 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1561 } 1561 }
1562 mFileString = ""; 1562 mFileString = "";
1563 mFileName = fn; 1563 mFileName = fn;
1564 mFirst = true; 1564 mFirst = true;
1565 if ( tlw ) 1565 if ( tlw )
1566 tlw->setCaption( i18n("Trying to connect to remote...") ); 1566 tlw->setCaption( i18n("Trying to connect to remote...") );
1567 mConnectCount = 30;mConnectMax = 30; 1567 mConnectCount = 30;mConnectMax = 30;
1568 mTimerSocket->start( 1000, true ); 1568 mTimerSocket->start( 1000, true );
1569 mSocket->connectToHost( mHost, mPort ); 1569 mSocket->connectToHost( mHost, mPort );
1570 qDebug("KSS: Waiting for connection"); 1570 qDebug("KSS: Waiting for connection");
1571} 1571}
1572void KCommandSocket::updateConnectDialog() 1572void KCommandSocket::updateConnectDialog()
1573{ 1573{
1574 1574
1575 if ( mConnectCount == mConnectMax ) { 1575 if ( mConnectCount == mConnectMax ) {
1576 //qDebug("MAXX %d", mConnectMax); 1576 //qDebug("MAXX %d", mConnectMax);
1577 mConnectProgress.setTotalSteps ( 30 ); 1577 mConnectProgress.setTotalSteps ( 30 );
1578 mConnectProgress.show(); 1578 mConnectProgress.show();
1579 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1579 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1580 } 1580 }
1581 //qDebug("updateConnectDialog() %d", mConnectCount); 1581 //qDebug("updateConnectDialog() %d", mConnectCount);
1582 mConnectProgress.raise(); 1582 mConnectProgress.raise();
1583 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1583 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1584 --mConnectCount; 1584 --mConnectCount;
1585 if ( mConnectCount > 0 ) 1585 if ( mConnectCount > 0 )
1586 mTimerSocket->start( 1000, true ); 1586 mTimerSocket->start( 1000, true );
1587 else 1587 else
1588 deleteSocket(); 1588 deleteSocket();
1589 1589
1590} 1590}
1591void KCommandSocket::writeFile( QString fileName ) 1591void KCommandSocket::writeFile( QString fileName )
1592{ 1592{
1593 if ( !mSocket ) { 1593 if ( !mSocket ) {
1594 mSocket = new QSocket( this ); 1594 mSocket = new QSocket( this );
1595 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1595 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1596 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1596 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1597 } 1597 }
1598 mFileName = fileName ; 1598 mFileName = fileName ;
1599 mConnectCount = 30;mConnectMax = 30; 1599 mConnectCount = 30;mConnectMax = 30;
1600 mTimerSocket->start( 1000, true ); 1600 mTimerSocket->start( 1000, true );
1601 mSocket->connectToHost( mHost, mPort ); 1601 mSocket->connectToHost( mHost, mPort );
1602} 1602}
1603void KCommandSocket::writeFileToSocket() 1603void KCommandSocket::writeFileToSocket()
1604{ 1604{
1605 mTimerSocket->stop(); 1605 mTimerSocket->stop();
1606 QFile file2( mFileName ); 1606 QFile file2( mFileName );
1607 if (!file2.open( IO_ReadOnly ) ) { 1607 if (!file2.open( IO_ReadOnly ) ) {
1608 mConnectProgress.hide(); 1608 mConnectProgress.hide();
1609 mConnectCount = -1; 1609 mConnectCount = -1;
1610 mRetVal= errorW; 1610 mRetVal= errorW;
1611 mSocket->close(); 1611 mSocket->close();
1612 if ( mSocket->state() == QSocket::Idle ) 1612 if ( mSocket->state() == QSocket::Idle )
1613 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1613 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1614 return ; 1614 return ;
1615 } 1615 }
1616 mConnectProgress.setTotalSteps ( file2.size() ); 1616 mConnectProgress.setTotalSteps ( file2.size() );
1617 mConnectProgress.show(); 1617 mConnectProgress.show();
1618 int count = 0; 1618 int count = 0;
1619 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1619 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1620 mConnectProgress.setProgress( count ); 1620 mConnectProgress.setProgress( count );
1621 mConnectProgress.blockSignals( true ); 1621 mConnectProgress.blockSignals( true );
1622 QTextStream ts2( &file2 ); 1622 QTextStream ts2( &file2 );
1623 ts2.setEncoding( QTextStream::Latin1 ); 1623 ts2.setEncoding( QTextStream::Latin1 );
1624 QTextStream os2( mSocket ); 1624 QTextStream os2( mSocket );
1625 os2.setEncoding( QTextStream::Latin1 ); 1625 os2.setEncoding( QTextStream::Latin1 );
1626 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; 1626 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
1627 int byteCount = 0; 1627 int byteCount = 0;
1628 int byteMax = file2.size()/53; 1628 int byteMax = file2.size()/53;
1629 while ( ! ts2.atEnd() ) { 1629 while ( ! ts2.atEnd() ) {
1630 qApp->processEvents(); 1630 qApp->processEvents();
1631 if ( byteCount > byteMax ) { 1631 if ( byteCount > byteMax ) {
1632 byteCount = 0; 1632 byteCount = 0;
1633 mConnectProgress.setProgress( count ); 1633 mConnectProgress.setProgress( count );
1634 } 1634 }
1635 QString temp = ts2.readLine(); 1635 QString temp = ts2.readLine();
1636 count += temp.length(); 1636 count += temp.length();
1637 byteCount += temp.length(); 1637 byteCount += temp.length();
1638 os2 << temp << "\r\n"; 1638 os2 << temp << "\r\n";
1639 } 1639 }
1640 file2.close(); 1640 file2.close();
1641 mConnectProgress.hide(); 1641 mConnectProgress.hide();
1642 mConnectCount = -1; 1642 mConnectCount = -1;
1643 os2 << "\r\n"; 1643 os2 << "\r\n";
1644 mRetVal= successW; 1644 mRetVal= successW;
1645 mSocket->close(); 1645 mSocket->close();
1646 if ( mSocket->state() == QSocket::Idle ) 1646 if ( mSocket->state() == QSocket::Idle )
1647 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1647 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1648 mConnectProgress.blockSignals( false ); 1648 mConnectProgress.blockSignals( false );
1649} 1649}
1650void KCommandSocket::sendStop() 1650void KCommandSocket::sendStop()
1651{ 1651{
1652 if ( !mSocket ) { 1652 if ( !mSocket ) {
1653 mSocket = new QSocket( this ); 1653 mSocket = new QSocket( this );
1654 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1654 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1655 } 1655 }
1656 mSocket->connectToHost( mHost, mPort ); 1656 mSocket->connectToHost( mHost, mPort );
1657 QTextStream os2( mSocket ); 1657 QTextStream os2( mSocket );
1658 os2.setEncoding( QTextStream::Latin1 ); 1658 os2.setEncoding( QTextStream::Latin1 );
1659 os2 << "STOP\r\n\r\n"; 1659 os2 << "STOP\r\n\r\n";
1660 mSocket->close(); 1660 mSocket->close();
1661 if ( mSocket->state() == QSocket::Idle ) 1661 if ( mSocket->state() == QSocket::Idle )
1662 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1662 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1663} 1663}
1664 1664
1665void KCommandSocket::startReadFileFromSocket() 1665void KCommandSocket::startReadFileFromSocket()
1666{ 1666{
1667 if ( ! mFirst ) 1667 if ( ! mFirst )
1668 return; 1668 return;
1669 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1669 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1670 mFirst = false; 1670 mFirst = false;
1671 mFileString = ""; 1671 mFileString = "";
1672 mTime.start(); 1672 mTime.start();
1673 mFirstLine = true; 1673 mFirstLine = true;
1674 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1674 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1675 1675
1676} 1676}
1677void KCommandSocket::readFileFromSocket() 1677void KCommandSocket::readFileFromSocket()
1678{ 1678{
1679 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1679 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1680 while ( mSocket->canReadLine () ) { 1680 while ( mSocket->canReadLine () ) {
1681 mTime.restart(); 1681 mTime.restart();
1682 QString line = mSocket->readLine (); 1682 QString line = mSocket->readLine ();
1683 if ( mFirstLine ) { 1683 if ( mFirstLine ) {
1684 mFirstLine = false; 1684 mFirstLine = false;
1685 if ( line.left( 6 ) == "ERROR_" ) { 1685 if ( line.left( 6 ) == "ERROR_" ) {
1686 mTimerSocket->stop(); 1686 mTimerSocket->stop();
1687 mConnectCount = -1; 1687 mConnectCount = -1;
1688 if ( line.left( 8 ) == "ERROR_PW" ) { 1688 if ( line.left( 8 ) == "ERROR_PW" ) {
1689 mRetVal = errorPW; 1689 mRetVal = errorPW;
1690 deleteSocket(); 1690 deleteSocket();
1691 return ; 1691 return ;
1692 } 1692 }
1693 if ( line.left( 8 ) == "ERROR_CA" ) { 1693 if ( line.left( 8 ) == "ERROR_CA" ) {
1694 mRetVal = errorCA; 1694 mRetVal = errorCA;
1695 deleteSocket(); 1695 deleteSocket();
1696 return ; 1696 return ;
1697 } 1697 }
1698 if ( line.left( 8 ) == "ERROR_FI" ) { 1698 if ( line.left( 8 ) == "ERROR_FI" ) {
1699 mRetVal = errorFI; 1699 mRetVal = errorFI;
1700 deleteSocket(); 1700 deleteSocket();
1701 return ; 1701 return ;
1702 } 1702 }
1703 if ( line.left( 8 ) == "ERROR_ED" ) { 1703 if ( line.left( 8 ) == "ERROR_ED" ) {
1704 mRetVal = errorED; 1704 mRetVal = errorED;
1705 deleteSocket(); 1705 deleteSocket();
1706 return ; 1706 return ;
1707 } 1707 }
1708 mRetVal = errorUN; 1708 mRetVal = errorUN;
1709 deleteSocket(); 1709 deleteSocket();
1710 return ; 1710 return ;
1711 } 1711 }
1712 } 1712 }
1713 mFileString += line; 1713 mFileString += line;
1714 //qDebug("readline: %s ", line.latin1()); 1714 //qDebug("readline: %s ", line.latin1());
1715 } 1715 }
1716 if ( mTime.elapsed () < 3000 ) { 1716 if ( mTime.elapsed () < 3000 ) {
1717 // wait for more 1717 // wait for more
1718 //qDebug("waitformore "); 1718 //qDebug("waitformore ");
1719 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1719 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1720 return; 1720 return;
1721 } 1721 }
1722 mTimerSocket->stop(); 1722 mTimerSocket->stop();
1723 mConnectCount = -1; 1723 mConnectCount = -1;
1724 mConnectProgress.hide(); 1724 mConnectProgress.hide();
1725 QString fileName = mFileName; 1725 QString fileName = mFileName;
1726 QFile file ( fileName ); 1726 QFile file ( fileName );
1727 if (!file.open( IO_WriteOnly ) ) { 1727 if (!file.open( IO_WriteOnly ) ) {
1728 mFileString = ""; 1728 mFileString = "";
1729 mRetVal = errorR; 1729 mRetVal = errorR;
1730 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1730 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1731 deleteSocket(); 1731 deleteSocket();
1732 return ; 1732 return ;
1733 1733
1734 } 1734 }
1735 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1735 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1736 QTextStream ts ( &file ); 1736 QTextStream ts ( &file );
1737 ts.setEncoding( QTextStream::Latin1 ); 1737 ts.setEncoding( QTextStream::Latin1 );
1738 ts << mFileString; 1738 ts << mFileString;
1739 file.close(); 1739 file.close();
1740 mFileString = ""; 1740 mFileString = "";
1741 mRetVal = successR; 1741 mRetVal = successR;
1742 mSocket->close(); 1742 mSocket->close();
1743 // if state is not idle, deleteSocket(); is called via 1743 // if state is not idle, deleteSocket(); is called via
1744 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1744 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1745 if ( mSocket->state() == QSocket::Idle ) 1745 if ( mSocket->state() == QSocket::Idle )
1746 deleteSocket(); 1746 deleteSocket();
1747} 1747}
1748 1748
1749void KCommandSocket::deleteSocket() 1749void KCommandSocket::deleteSocket()
1750{ 1750{
1751 //qDebug("KCommandSocket::deleteSocket() "); 1751 //qDebug("KCommandSocket::deleteSocket() ");
1752 mConnectProgress.hide(); 1752 mConnectProgress.hide();
1753 1753
1754 if ( mConnectCount >= 0 ) { 1754 if ( mConnectCount >= 0 ) {
1755 mTimerSocket->stop(); 1755 mTimerSocket->stop();
1756 mRetVal = errorTO; 1756 mRetVal = errorTO;
1757 qDebug("KCS::Connection to remote host timed out"); 1757 qDebug("KCS::Connection to remote host timed out");
1758 if ( mSocket ) { 1758 if ( mSocket ) {
1759 mSocket->close(); 1759 mSocket->close();
1760 //if ( mSocket->state() == QSocket::Idle ) 1760 //if ( mSocket->state() == QSocket::Idle )
1761 // deleteSocket(); 1761 // deleteSocket();
1762 delete mSocket; 1762 delete mSocket;
1763 mSocket = 0; 1763 mSocket = 0;
1764 } 1764 }
1765 if ( mConnectCount == 0 ) 1765 if ( mConnectCount == 0 )
1766 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1766 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1767 else if ( tlw ) 1767 else if ( tlw )
1768 tlw->setCaption( i18n("Connection to remote host cancelled!") ); 1768 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1769 emit commandFinished( this, mRetVal ); 1769 emit commandFinished( this, mRetVal );
1770 return; 1770 return;
1771 } 1771 }
1772 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1772 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1773 if ( mSocket) 1773 if ( mSocket)
1774 delete mSocket; 1774 delete mSocket;
1775 mSocket = 0; 1775 mSocket = 0;
1776 qDebug("commandFinished "); 1776 //qDebug("commandFinished ");
1777 emit commandFinished( this, mRetVal ); 1777 emit commandFinished( this, mRetVal );
1778} 1778}