1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
/*
This file is part of libkcal.
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
@file calendarresources.cpp
Provides a calendar composed of several calendar resources.
@author Cornelius Schumacher
@author Reinhold Kainhofer
*/
#include <stdlib.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qptrlist.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <klocale.h>
#include "vcaldrag.h"
#include "vcalformat.h"
#include "icalformat.h"
#include "exceptions.h"
#include "incidence.h"
#include "journal.h"
#include "filestorage.h"
#include <kresources/manager.h>
#include <kresources/selectdialog.h>
#include <kabc/lock.h>
#include "resourcecalendar.h"
#include "resourcelocal.h"
#include "calendarresources.h"
using namespace KCal;
ResourceCalendar
*CalendarResources::StandardDestinationPolicy::destination( Incidence * )
{
return resourceManager()->standardResource();
}
ResourceCalendar
*CalendarResources::AskDestinationPolicy::destination( Incidence * )
{
QPtrList<KRES::Resource> list;
CalendarResourceManager::ActiveIterator it;
for ( it = resourceManager()->activeBegin();
it != resourceManager()->activeEnd(); ++it ) {
if ( !(*it)->readOnly() ) {
//Insert the first the Standard resource to get be the default selected.
if ( resourceManager()->standardResource() == *it )
list.insert( 0, *it );
else
list.append( *it );
}
}
KRES::Resource *r;
r = KRES::SelectDialog::getResource( list, parent() );
return static_cast<ResourceCalendar *>( r );
}
CalendarResources::CalendarResources( const QString &timeZoneId,
const QString &family )
: Calendar( timeZoneId )
{
init( family );
}
void CalendarResources::init( const QString &family )
{
kdDebug(5800) << "CalendarResources::init( " << family << " )" << endl;
mManager = new CalendarResourceManager( family );
mManager->addObserver( this );
mStandardPolicy = new StandardDestinationPolicy( mManager );
mAskPolicy = new AskDestinationPolicy( mManager );
mDestinationPolicy = mStandardPolicy;
}
CalendarResources::~CalendarResources()
{
close();
delete mManager;
delete mStandardPolicy;
delete mAskPolicy;
}
void CalendarResources::readConfig( KConfig *config )
{
mManager->readConfig( config );
CalendarResourceManager::Iterator it;
for ( it = mManager->begin(); it != mManager->end(); ++it ) {
connectResource( *it );
}
}
void CalendarResources::load()
{
kdDebug(5800) << "CalendarResources::load()" << endl;
if ( !mManager->standardResource() ) {
kdDebug(5800) << "Warning! No standard resource yet." << endl;
}
// set the timezone for all resources. Otherwise we'll have those terrible tz
// troubles ;-((
CalendarResourceManager::Iterator i1;
for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
(*i1)->setTimeZoneId( timeZoneId() );
}
QValueList<ResourceCalendar *> failed;
// Open all active resources
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
if ( !(*it)->load() ) {
failed.append( *it );
}
Incidence::List incidences = (*it)->rawIncidences();
Incidence::List::Iterator incit;
for ( incit = incidences.begin(); incit != incidences.end(); ++incit ) {
(*incit)->registerObserver( this );
notifyIncidenceAdded( *incit );
}
}
QValueList<ResourceCalendar *>::ConstIterator it2;
for ( it2 = failed.begin(); it2 != failed.end(); ++it2 ) {
(*it2)->setActive( false );
emit signalResourceModified( *it2 );
}
mOpen = true;
}
bool CalendarResources::reload( const QString &tz )
{
save();
close();
setTimeZoneId( tz );
load();
return true;
}
void CalendarResources::setStandardDestinationPolicy()
{
mDestinationPolicy = mStandardPolicy;
}
void CalendarResources::setAskDestinationPolicy()
{
mDestinationPolicy = mAskPolicy;
}
QWidget *CalendarResources::dialogParentWidget()
{
return mDestinationPolicy->parent();
}
void CalendarResources::setDialogParentWidget( QWidget *parent )
{
mDestinationPolicy->setParent( parent );
}
void CalendarResources::close()
{
kdDebug(5800) << "CalendarResources::close" << endl;
if ( mOpen ) {
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
(*it)->close();
}
setModified( false );
mOpen = false;
}
}
void CalendarResources::save()
{
kdDebug(5800) << "CalendarResources::save()" << endl;
if ( mOpen && isModified() ) {
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
(*it)->save();
}
setModified( false );
}
}
bool CalendarResources::isSaving()
{
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
if ( (*it)->isSaving() ) {
return true;
}
}
return false;
}
bool CalendarResources::addIncidence( Incidence *incidence,
ResourceCalendar *resource )
{
// FIXME: Use proper locking via begin/endChange!
bool validRes = false;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
if ( (*it) == resource )
validRes = true;
}
ResourceCalendar *oldResource = 0;
if ( mResourceMap.contains( incidence ) ) {
oldResource = mResourceMap[incidence];
}
mResourceMap[incidence] = resource;
if ( validRes && beginChange( incidence ) &&
resource->addIncidence( incidence ) ) {
// mResourceMap[incidence] = resource;
incidence->registerObserver( this );
notifyIncidenceAdded( incidence );
setModified( true );
endChange( incidence );
return true;
} else {
if ( oldResource )
mResourceMap[incidence] = oldResource;
else
mResourceMap.remove( incidence );
}
return false;
}
bool CalendarResources::addIncidence( Incidence *incidence )
{
kdDebug(5800) << "CalendarResources::addIncidence" << this << endl;
ResourceCalendar *resource = mDestinationPolicy->destination( incidence );
if ( resource ) {
mResourceMap[ incidence ] = resource;
if ( beginChange( incidence ) && resource->addIncidence( incidence ) ) {
incidence->registerObserver( this );
notifyIncidenceAdded( incidence );
mResourceMap[ incidence ] = resource;
setModified( true );
endChange( incidence );
return true;
} else {
mResourceMap.remove( incidence );
}
} else
kdDebug(5800) << "CalendarResources::addIncidence(): no resource" << endl;
return false;
}
bool CalendarResources::addEvent( Event *event )
{
kdDebug(5800) << "CalendarResources::addEvent" << endl;
return addIncidence( event );
}
bool CalendarResources::addEvent( Event *Event, ResourceCalendar *resource )
{
return addIncidence( Event, resource );
}
bool CalendarResources::deleteEvent( Event *event )
{
kdDebug(5800) << "CalendarResources::deleteEvent" << endl;
bool status;
if ( mResourceMap.find( event ) != mResourceMap.end() ) {
status = mResourceMap[event]->deleteEvent( event );
if ( status )
mResourceMap.remove( event );
} else {
status = false;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
status = (*it)->deleteEvent( event ) || status;
}
}
setModified( status );
return status;
}
Event *CalendarResources::event( const QString &uid )
{
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Event* event = (*it)->event( uid );
if ( event ) {
mResourceMap[event] = *it;
return event;
}
}
// Not found
return 0;
}
bool CalendarResources::addTodo( Todo *todo )
{
kdDebug(5800) << "CalendarResources::addTodo" << endl;
return addIncidence( todo );
}
bool CalendarResources::addTodo( Todo *todo, ResourceCalendar *resource )
{
return addIncidence( todo, resource );
}
bool CalendarResources::deleteTodo( Todo *todo )
{
kdDebug(5800) << "CalendarResources::deleteTodo" << endl;
bool status;
if ( mResourceMap.find( todo ) != mResourceMap.end() ) {
status = mResourceMap[todo]->deleteTodo( todo );
if ( status )
mResourceMap.remove( todo );
} else {
CalendarResourceManager::ActiveIterator it;
status = false;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
status = (*it)->deleteTodo( todo ) || status;
}
}
setModified( status );
return status;
}
Todo::List CalendarResources::rawTodos( TodoSortField sortField,
SortDirection sortDirection )
{
Todo::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Todo::List todos = (*it)->rawTodos( TodoSortUnsorted );
Todo::List::ConstIterator it2;
for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return sortTodos( &result, sortField, sortDirection );
}
Todo *CalendarResources::todo( const QString &uid )
{
kdDebug(5800) << "CalendarResources::todo(uid)" << endl;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Todo *todo = (*it)->todo( uid );
if ( todo ) {
mResourceMap[todo] = *it;
return todo;
}
}
// Not found
return 0;
}
Todo::List CalendarResources::rawTodosForDate( const QDate &date )
{
Todo::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Todo::List todos = (*it)->rawTodosForDate( date );
Todo::List::ConstIterator it2;
for ( it2 = todos.begin(); it2 != todos.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return result;
}
Alarm::List CalendarResources::alarmsTo( const QDateTime &to )
{
kdDebug(5800) << "CalendarResources::alarmsTo" << endl;
Alarm::List result;
CalendarResourceManager::ActiveIterator resit;
for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
Alarm::List list = (*resit)->alarmsTo( to );
Alarm::List::Iterator alarmit;
for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
result.append( *alarmit );
}
return result;
}
Alarm::List CalendarResources::alarms( const QDateTime &from,
const QDateTime &to )
{
Alarm::List result;
CalendarResourceManager::ActiveIterator resit;
for ( resit = mManager->activeBegin(); resit != mManager->activeEnd(); ++resit ) {
Alarm::List list = (*resit)->alarms( from, to );
Alarm::List::Iterator alarmit;
for ( alarmit = list.begin(); alarmit != list.end(); ++alarmit )
result.append( *alarmit );
}
return result;
}
/****************************** PROTECTED METHODS ****************************/
Event::List CalendarResources::rawEventsForDate( const QDate &date,
EventSortField sortField,
SortDirection sortDirection )
{
Event::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Event::List list = (*it)->rawEventsForDate( date );
Event::List::ConstIterator it2;
for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return sortEvents( &result, sortField, sortDirection );
}
Event::List CalendarResources::rawEvents( const QDate &start, const QDate &end,
bool inclusive )
{
kdDebug(5800) << "CalendarResources::rawEvents(start,end,inclusive)" << endl;
Event::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Event::List list = (*it)->rawEvents( start, end, inclusive );
Event::List::ConstIterator it2;
for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return result;
}
Event::List CalendarResources::rawEventsForDate( const QDateTime &qdt )
{
kdDebug(5800) << "CalendarResources::rawEventsForDate(qdt)" << endl;
// @TODO: Remove the code duplication by the resourcemap iteration block.
Event::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Event::List list = (*it)->rawEventsForDate( qdt );
Event::List::ConstIterator it2;
for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return result;
}
Event::List CalendarResources::rawEvents( EventSortField sortField,
SortDirection sortDirection )
{
kdDebug(5800) << "CalendarResources::rawEvents()" << endl;
Event::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Event::List list = (*it)->rawEvents( EventSortUnsorted );
Event::List::ConstIterator it2;
for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return sortEvents( &result, sortField, sortDirection );
}
bool CalendarResources::addJournal( Journal *journal )
{
kdDebug(5800) << "CalendarResources::addJournal" << endl;
return addIncidence( journal );
}
bool CalendarResources::deleteJournal( Journal *journal )
{
kdDebug(5800) << "CalendarResources::deleteJournal" << endl;
bool status;
if ( mResourceMap.find( journal ) != mResourceMap.end() ) {
status = mResourceMap[journal]->deleteJournal( journal );
if ( status )
mResourceMap.remove( journal );
} else {
CalendarResourceManager::ActiveIterator it;
status = false;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
status = (*it)->deleteJournal( journal ) || status;
}
}
setModified( status );
return status;
}
bool CalendarResources::addJournal( Journal *journal,
ResourceCalendar *resource
)
{
return addIncidence( journal, resource );
}
Journal *CalendarResources::journal( const QString &uid )
{
kdDebug(5800) << "CalendarResources::journal(uid)" << endl;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Journal* journal = (*it)->journal( uid );
if ( journal ) {
mResourceMap[journal] = *it;
return journal;
}
}
// Not found
return 0;
}
Journal::List CalendarResources::rawJournals( JournalSortField sortField,
SortDirection sortDirection )
{
kdDebug(5800) << "CalendarResources::rawJournals()" << endl;
Journal::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Journal::List journals = (*it)->rawJournals( JournalSortUnsorted );
Journal::List::ConstIterator it2;
for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return sortJournals( &result, sortField, sortDirection );
}
Journal::List CalendarResources::rawJournalsForDate( const QDate &date )
{
Journal::List result;
CalendarResourceManager::ActiveIterator it;
for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
Journal::List journals = (*it)->rawJournalsForDate( date );
Journal::List::ConstIterator it2;
for ( it2 = journals.begin(); it2 != journals.end(); ++it2 ) {
result.append( *it2 );
mResourceMap[ *it2 ] = *it;
}
}
return result;
}
void CalendarResources::connectResource( ResourceCalendar *resource )
{
connect( resource, SIGNAL( resourceChanged( ResourceCalendar * ) ),
SIGNAL( calendarChanged() ) );
connect( resource, SIGNAL( resourceSaved( ResourceCalendar * ) ),
SIGNAL( calendarSaved() ) );
connect( resource, SIGNAL( resourceLoadError( ResourceCalendar *,
const QString & ) ),
SLOT( slotLoadError( ResourceCalendar *, const QString & ) ) );
connect( resource, SIGNAL( resourceSaveError( ResourceCalendar *,
const QString & ) ),
SLOT( slotSaveError( ResourceCalendar *, const QString & ) ) );
}
ResourceCalendar *CalendarResources::resource( Incidence *incidence )
{
if ( mResourceMap.find( incidence ) != mResourceMap.end() ) {
return mResourceMap[ incidence ];
}
return 0;
}
void CalendarResources::resourceAdded( ResourceCalendar *resource )
{
kdDebug(5800) << "Resource added: " << resource->resourceName() << endl;
if ( !resource->isActive() )
return;
if ( resource->open() ) {
resource->load();
}
connectResource( resource );
emit signalResourceAdded( resource );
}
void CalendarResources::resourceModified( ResourceCalendar *resource )
{
kdDebug(5800) << "Resource modified: " << resource->resourceName() << endl;
emit signalResourceModified( resource );
}
void CalendarResources::resourceDeleted( ResourceCalendar *resource )
{
kdDebug(5800) << "Resource deleted: " << resource->resourceName() << endl;
emit signalResourceDeleted( resource );
}
void CalendarResources::doSetTimeZoneId( const QString &timeZoneId )
{
// set the timezone for all resources. Otherwise we'll have those terrible
// tz troubles ;-((
CalendarResourceManager::Iterator i1;
for ( i1 = mManager->begin(); i1 != mManager->end(); ++i1 ) {
(*i1)->setTimeZoneId( timeZoneId );
}
}
void CalendarResources::setTimeZoneIdViewOnly( const QString &timeZoneId )
{
reload( timeZoneId );
}
CalendarResources::Ticket
*CalendarResources::requestSaveTicket( ResourceCalendar *resource )
{
kdDebug(5800) << "CalendarResources::requestSaveTicket()" << endl;
KABC::Lock *lock = resource->lock();
if ( !lock )
return 0;
if ( lock->lock() )
return new Ticket( resource );
else
return 0;
}
bool CalendarResources::save( Ticket *ticket, Incidence *incidence )
{
kdDebug(5800) << "CalendarResources::save( Ticket *)" << endl;
if ( !ticket || !ticket->resource() )
return false;
kdDebug(5800) << "tick " << ticket->resource()->resourceName() << endl;
// @TODO: Check if the resource was changed at all. If not, don't save.
if ( ticket->resource()->save( incidence ) ) {
releaseSaveTicket( ticket );
return true;
}
return false;
}
void CalendarResources::releaseSaveTicket( Ticket *ticket )
{
ticket->resource()->lock()->unlock();
delete ticket;
}
bool CalendarResources::beginChange( Incidence *incidence )
{
kdDebug(5800) << "CalendarResources::beginChange()" << endl;
ResourceCalendar *r = resource( incidence );
if ( !r ) {
r = mDestinationPolicy->destination( incidence );
if ( !r ) {
kdError() << "Unable to get destination resource." << endl;
return false;
}
mResourceMap[ incidence ] = r;
}
int count = incrementChangeCount( r );
if ( count == 1 ) {
Ticket *ticket = requestSaveTicket( r );
if ( !ticket ) {
kdDebug(5800) << "CalendarResources::beginChange(): unable to get ticket."
<< endl;
decrementChangeCount( r );
return false;
} else {
mTickets[ r ] = ticket;
}
}
return true;
}
bool CalendarResources::endChange( Incidence *incidence )
{
kdDebug(5800) << "CalendarResource::endChange()" << endl;
ResourceCalendar *r = resource( incidence );
if ( !r )
return false;
int count = decrementChangeCount( r );
if ( count == 0 ) {
bool ok = save( mTickets[ r ], incidence );
if ( ok ) {
mTickets.remove( r );
} else {
return false;
}
}
return true;
}
int CalendarResources::incrementChangeCount( ResourceCalendar *r )
{
if ( !mChangeCounts.contains( r ) ) {
mChangeCounts.insert( r, 0 );
}
int count = mChangeCounts[ r ];
++count;
mChangeCounts[ r ] = count;
return count;
}
int CalendarResources::decrementChangeCount( ResourceCalendar *r )
{
if ( !mChangeCounts.contains( r ) ) {
kdError() << "No change count for resource." << endl;
return 0;
}
int count = mChangeCounts[ r ];
--count;
if ( count < 0 ) {
kdError() << "Can't decrement change count. It already is 0." << endl;
count = 0;
}
mChangeCounts[ r ] = count;
return count;
}
void CalendarResources::slotLoadError( ResourceCalendar *, const QString &err )
{
emit signalErrorMessage( err );
}
void CalendarResources::slotSaveError( ResourceCalendar *, const QString &err )
{
emit signalErrorMessage( err );
}
#include "calendarresources.moc"
|