summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 8ff8b14..3c572f0 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,290 +1,321 @@
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 close(); 68 close();
69} 69}
70 70
71bool CalendarLocal::load( const QString &fileName ) 71bool CalendarLocal::load( const QString &fileName )
72{ 72{
73 FileStorage storage( this, fileName ); 73 FileStorage storage( this, fileName );
74 return storage.load(); 74 return storage.load();
75} 75}
76 76
77bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 77bool CalendarLocal::save( const QString &fileName, CalFormat *format )
78{ 78{
79 FileStorage storage( this, fileName, format ); 79 FileStorage storage( this, fileName, format );
80 return storage.save(); 80 return storage.save();
81} 81}
82 82
83void CalendarLocal::close() 83void CalendarLocal::close()
84{ 84{
85 mEventList.setAutoDelete( true ); 85 mEventList.setAutoDelete( true );
86 mTodoList.setAutoDelete( true ); 86 mTodoList.setAutoDelete( true );
87 mJournalList.setAutoDelete( false ); 87 mJournalList.setAutoDelete( false );
88 88
89 mEventList.clear(); 89 mEventList.clear();
90 mTodoList.clear(); 90 mTodoList.clear();
91 mJournalList.clear(); 91 mJournalList.clear();
92 92
93 mEventList.setAutoDelete( false ); 93 mEventList.setAutoDelete( false );
94 mTodoList.setAutoDelete( false ); 94 mTodoList.setAutoDelete( false );
95 mJournalList.setAutoDelete( false ); 95 mJournalList.setAutoDelete( false );
96 96
97 setModified( false ); 97 setModified( false );
98} 98}
99
100bool CalendarLocal::addAnniversaryNoDup( Event *event )
101{
102 QString cat;
103 bool isBirthday = true;
104 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
105 isBirthday = false;
106 cat = i18n( "Anniversary" );
107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
108 isBirthday = true;
109 cat = i18n( "Birthday" );
110 } else {
111 qDebug("addAnniversaryNoDup called without fitting category! ");
112 return false;
113 }
114 Event * eve;
115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
116 if ( !(eve->categories().contains( cat ) ))
117 continue;
118 // now we have an event with fitting category
119 if ( eve->dtStart().date() != event->dtStart().date() )
120 continue;
121 // now we have an event with fitting category+date
122 if ( eve->summary() != event->summary() )
123 continue;
124 // now we have an event with fitting category+date+summary
125 return false;
126 }
127 return addEvent( event );
128
129}
99bool CalendarLocal::addEventNoDup( Event *event ) 130bool CalendarLocal::addEventNoDup( Event *event )
100{ 131{
101 Event * eve; 132 Event * eve;
102 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 133 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
103 if ( *eve == *event ) { 134 if ( *eve == *event ) {
104 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 135 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
105 return false; 136 return false;
106 } 137 }
107 } 138 }
108 return addEvent( event ); 139 return addEvent( event );
109} 140}
110 141
111bool CalendarLocal::addEvent( Event *event ) 142bool CalendarLocal::addEvent( Event *event )
112{ 143{
113 insertEvent( event ); 144 insertEvent( event );
114 145
115 event->registerObserver( this ); 146 event->registerObserver( this );
116 147
117 setModified( true ); 148 setModified( true );
118 149
119 return true; 150 return true;
120} 151}
121 152
122void CalendarLocal::deleteEvent( Event *event ) 153void CalendarLocal::deleteEvent( Event *event )
123{ 154{
124 155
125 156
126 if ( mEventList.removeRef( event ) ) { 157 if ( mEventList.removeRef( event ) ) {
127 setModified( true ); 158 setModified( true );
128 } 159 }
129} 160}
130 161
131 162
132Event *CalendarLocal::event( const QString &uid ) 163Event *CalendarLocal::event( const QString &uid )
133{ 164{
134 165
135 Event *event; 166 Event *event;
136 167
137 for ( event = mEventList.first(); event; event = mEventList.next() ) { 168 for ( event = mEventList.first(); event; event = mEventList.next() ) {
138 if ( event->uid() == uid ) { 169 if ( event->uid() == uid ) {
139 return event; 170 return event;
140 } 171 }
141 } 172 }
142 173
143 return 0; 174 return 0;
144} 175}
145bool CalendarLocal::addTodoNoDup( Todo *todo ) 176bool CalendarLocal::addTodoNoDup( Todo *todo )
146{ 177{
147 Todo * eve; 178 Todo * eve;
148 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 179 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
149 if ( *eve == *todo ) { 180 if ( *eve == *todo ) {
150 //qDebug("duplicate todo found! not inserted! "); 181 //qDebug("duplicate todo found! not inserted! ");
151 return false; 182 return false;
152 } 183 }
153 } 184 }
154 return addTodo( todo ); 185 return addTodo( todo );
155} 186}
156bool CalendarLocal::addTodo( Todo *todo ) 187bool CalendarLocal::addTodo( Todo *todo )
157{ 188{
158 mTodoList.append( todo ); 189 mTodoList.append( todo );
159 190
160 todo->registerObserver( this ); 191 todo->registerObserver( this );
161 192
162 // Set up subtask relations 193 // Set up subtask relations
163 setupRelations( todo ); 194 setupRelations( todo );
164 195
165 setModified( true ); 196 setModified( true );
166 197
167 return true; 198 return true;
168} 199}
169 200
170void CalendarLocal::deleteTodo( Todo *todo ) 201void CalendarLocal::deleteTodo( Todo *todo )
171{ 202{
172 // Handle orphaned children 203 // Handle orphaned children
173 removeRelations( todo ); 204 removeRelations( todo );
174 205
175 if ( mTodoList.removeRef( todo ) ) { 206 if ( mTodoList.removeRef( todo ) ) {
176 setModified( true ); 207 setModified( true );
177 } 208 }
178} 209}
179 210
180QPtrList<Todo> CalendarLocal::rawTodos() 211QPtrList<Todo> CalendarLocal::rawTodos()
181{ 212{
182 return mTodoList; 213 return mTodoList;
183} 214}
184Todo *CalendarLocal::todo( int id ) 215Todo *CalendarLocal::todo( int id )
185{ 216{
186 Todo *todo; 217 Todo *todo;
187 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 218 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
188 if ( todo->zaurusId() == id ) return todo; 219 if ( todo->zaurusId() == id ) return todo;
189 } 220 }
190 221
191 return 0; 222 return 0;
192} 223}
193 224
194Event *CalendarLocal::event( int id ) 225Event *CalendarLocal::event( int id )
195{ 226{
196 Event *todo; 227 Event *todo;
197 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 228 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
198 if ( todo->zaurusId() == id ) return todo; 229 if ( todo->zaurusId() == id ) return todo;
199 } 230 }
200 231
201 return 0; 232 return 0;
202} 233}
203Todo *CalendarLocal::todo( const QString &uid ) 234Todo *CalendarLocal::todo( const QString &uid )
204{ 235{
205 Todo *todo; 236 Todo *todo;
206 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 237 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
207 if ( todo->uid() == uid ) return todo; 238 if ( todo->uid() == uid ) return todo;
208 } 239 }
209 240
210 return 0; 241 return 0;
211} 242}
212QString CalendarLocal::nextSummary() const 243QString CalendarLocal::nextSummary() const
213{ 244{
214 return mNextSummary; 245 return mNextSummary;
215} 246}
216QDateTime CalendarLocal::nextAlarmEventDateTime() const 247QDateTime CalendarLocal::nextAlarmEventDateTime() const
217{ 248{
218 return mNextAlarmEventDateTime; 249 return mNextAlarmEventDateTime;
219} 250}
220void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 251void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
221{ 252{
222 //mNextAlarmIncidence 253 //mNextAlarmIncidence
223 //mNextAlarmDateTime 254 //mNextAlarmDateTime
224 //return mNextSummary; 255 //return mNextSummary;
225 //return mNextAlarmEventDateTime; 256 //return mNextAlarmEventDateTime;
226 bool newNextAlarm = false; 257 bool newNextAlarm = false;
227 bool computeNextAlarm = false; 258 bool computeNextAlarm = false;
228 bool ok; 259 bool ok;
229 int offset; 260 int offset;
230 QDateTime nextA; 261 QDateTime nextA;
231 // QString nextSum; 262 // QString nextSum;
232 //QDateTime nextEvent; 263 //QDateTime nextEvent;
233 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 264 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
234 computeNextAlarm = true; 265 computeNextAlarm = true;
235 } else { 266 } else {
236 if ( ! deleted ) { 267 if ( ! deleted ) {
237 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 268 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ;
238 if ( ok ) { 269 if ( ok ) {
239 if ( nextA < mNextAlarmDateTime ) { 270 if ( nextA < mNextAlarmDateTime ) {
240 deRegisterAlarm(); 271 deRegisterAlarm();
241 mNextAlarmDateTime = nextA; 272 mNextAlarmDateTime = nextA;
242 mNextSummary = incidence->summary(); 273 mNextSummary = incidence->summary();
243 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 274 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
244 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 275 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
245 newNextAlarm = true; 276 newNextAlarm = true;
246 mNextAlarmIncidence = incidence; 277 mNextAlarmIncidence = incidence;
247 } else { 278 } else {
248 if ( incidence == mNextAlarmIncidence ) { 279 if ( incidence == mNextAlarmIncidence ) {
249 computeNextAlarm = true; 280 computeNextAlarm = true;
250 } 281 }
251 } 282 }
252 } else { 283 } else {
253 if ( mNextAlarmIncidence == incidence ) { 284 if ( mNextAlarmIncidence == incidence ) {
254 computeNextAlarm = true; 285 computeNextAlarm = true;
255 } 286 }
256 } 287 }
257 } else { // deleted 288 } else { // deleted
258 if ( incidence == mNextAlarmIncidence ) { 289 if ( incidence == mNextAlarmIncidence ) {
259 computeNextAlarm = true; 290 computeNextAlarm = true;
260 } 291 }
261 } 292 }
262 } 293 }
263 if ( computeNextAlarm ) { 294 if ( computeNextAlarm ) {
264 deRegisterAlarm(); 295 deRegisterAlarm();
265 nextA = nextAlarm( 1000 ); 296 nextA = nextAlarm( 1000 );
266 if (! mNextAlarmIncidence ) { 297 if (! mNextAlarmIncidence ) {
267 return; 298 return;
268 } 299 }
269 newNextAlarm = true; 300 newNextAlarm = true;
270 } 301 }
271 if ( newNextAlarm ) 302 if ( newNextAlarm )
272 registerAlarm(); 303 registerAlarm();
273} 304}
274QString CalendarLocal:: getAlarmNotification() 305QString CalendarLocal:: getAlarmNotification()
275{ 306{
276 QString ret; 307 QString ret;
277 // this should not happen 308 // this should not happen
278 if (! mNextAlarmIncidence ) 309 if (! mNextAlarmIncidence )
279 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 310 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
280 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 311 Alarm* alarm = mNextAlarmIncidence->alarms().first();
281 if ( alarm->type() == Alarm::Procedure ) { 312 if ( alarm->type() == Alarm::Procedure ) {
282 ret = "proc_alarm" + alarm->programFile()+"+++"; 313 ret = "proc_alarm" + alarm->programFile()+"+++";
283 } else { 314 } else {
284 ret = "audio_alarm" +alarm->audioFile() +"+++"; 315 ret = "audio_alarm" +alarm->audioFile() +"+++";
285 } 316 }
286 ret += "cal_alarm"+ mNextSummary.left( 25 ); 317 ret += "cal_alarm"+ mNextSummary.left( 25 );
287 if ( mNextSummary.length() > 25 ) 318 if ( mNextSummary.length() > 25 )
288 ret += "\n" + mNextSummary.mid(25, 25 ); 319 ret += "\n" + mNextSummary.mid(25, 25 );
289 ret+= "\n"+mNextAlarmEventDateTimeString; 320 ret+= "\n"+mNextAlarmEventDateTimeString;
290 return ret; 321 return ret;