summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index b02f706..ad8ace3 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,211 +1,220 @@
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, bool enabledOnly )
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 ( enabledOnly )
90 if ( !todo->calEnabled() )
91 continue;
89 if ( doNotCheckDuplicates ) return todo; 92 if ( doNotCheckDuplicates ) return todo;
90 if ( retVal ) { 93 if ( retVal ) {
91 if ( retVal->calID() > todo->calID() ) { 94 if ( retVal->calID() > todo->calID() ) {
92 retVal = todo; 95 retVal = todo;
93 } 96 }
94 } else { 97 } else {
95 retVal = todo; 98 retVal = todo;
96 } 99 }
97 } 100 }
98 } 101 }
99 if ( retVal ) return retVal; 102 if ( retVal ) return retVal;
100 Event *event; 103 Event *event;
101 for ( event = mEventList.first(); event; event = mEventList.next() ) { 104 for ( event = mEventList.first(); event; event = mEventList.next() ) {
102 if ( event->uid() == uid ) { 105 if ( event->uid() == uid ) {
106 if ( enabledOnly )
107 if ( !event->calEnabled() )
108 continue;
103 if ( doNotCheckDuplicates ) return event; 109 if ( doNotCheckDuplicates ) return event;
104 if ( retVal ) { 110 if ( retVal ) {
105 if ( retVal->calID() > event->calID() ) { 111 if ( retVal->calID() > event->calID() ) {
106 retVal = event; 112 retVal = event;
107 } 113 }
108 } else { 114 } else {
109 retVal = event; 115 retVal = event;
110 } 116 }
111 } 117 }
112 } 118 }
113 if ( retVal ) return retVal; 119 if ( retVal ) return retVal;
114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 120 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
115 if ( it->uid() == uid ) { 121 if ( it->uid() == uid ) {
122 if ( enabledOnly )
123 if ( !it->calEnabled() )
124 continue;
116 if ( doNotCheckDuplicates ) return it; 125 if ( doNotCheckDuplicates ) return it;
117 if ( retVal ) { 126 if ( retVal ) {
118 if ( retVal->calID() > it->calID() ) { 127 if ( retVal->calID() > it->calID() ) {
119 retVal = it; 128 retVal = it;
120 } 129 }
121 } else { 130 } else {
122 retVal = it; 131 retVal = it;
123 } 132 }
124 } 133 }
125 return retVal; 134 return retVal;
126} 135}
127 136
128bool CalendarLocal::mergeCalendar( Calendar* remote ) 137bool CalendarLocal::mergeCalendar( Calendar* remote )
129{ 138{
130 // 1 look for raw inc in local 139 // 1 look for raw inc in local
131 // if inc not in remote, delete in local 140 // if inc not in remote, delete in local
132 // 2 look for raw inc in remote 141 // 2 look for raw inc in remote
133 // if inc in local, replace it 142 // if inc in local, replace it
134 // if not in local, add it to default calendar 143 // if not in local, add it to default calendar
135 QPtrList<Incidence> localInc = rawIncidences(); 144 QPtrList<Incidence> localInc = rawIncidences();
136 Incidence* inL = localInc.first(); 145 Incidence* inL = localInc.first();
137 while ( inL ) { 146 while ( inL ) {
138 if ( ! inL->isReadOnly () ) 147 if ( ! inL->isReadOnly () )
139 if ( !remote->incidenceForUid( inL->uid(), true )) 148 if ( !remote->incidenceForUid( inL->uid(), true ))
140 deleteIncidence( inL ); 149 deleteIncidence( inL );
141 inL = localInc.next(); 150 inL = localInc.next();
142 } 151 }
143 QPtrList<Incidence> er = remote->rawIncidences(); 152 QPtrList<Incidence> er = remote->rawIncidences();
144 Incidence* inR = er.first(); 153 Incidence* inR = er.first();
145 while ( inR ) { 154 while ( inR ) {
146 inL = incidenceForUid( inR->uid(),false ); 155 inL = incidenceForUid( inR->uid(),false );
147 if ( inL ) { 156 if ( inL ) {
148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 157 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
149 int calID = inL->calID(); 158 int calID = inL->calID();
150 deleteIncidence( inL ); 159 deleteIncidence( inL );
151 inL = inR->clone(); 160 inL = inR->clone();
152 inL->setCalID_block( calID ); 161 inL->setCalID_block( calID );
153 addIncidence( inL ); 162 addIncidence( inL );
154 } 163 }
155 } else { 164 } else {
156 inL = inR->clone(); 165 inL = inR->clone();
157 inL->setCalID_block( 0 );// add to default cal 166 inL->setCalID_block( 0 );// add to default cal
158 addIncidence( inL ); 167 addIncidence( inL );
159 } 168 }
160 inR = er.next(); 169 inR = er.next();
161 } 170 }
162 return true; 171 return true;
163} 172}
164 173
165 174
166bool CalendarLocal::addCalendarFile( QString name, int id ) 175bool CalendarLocal::addCalendarFile( QString name, int id )
167{ 176{
168 CalendarLocal calendar( timeZoneId() ); 177 CalendarLocal calendar( timeZoneId() );
169 calendar.setDefaultCalendar( id ); 178 calendar.setDefaultCalendar( id );
170 if ( calendar.load( name ) ) { 179 if ( calendar.load( name ) ) {
171 addCalendar( &calendar ); 180 addCalendar( &calendar );
172 return true; 181 return true;
173 } 182 }
174 return false; 183 return false;
175} 184}
176void CalendarLocal::setSyncEventsEnabled() 185void CalendarLocal::setSyncEventsEnabled()
177{ 186{
178 Event * ev; 187 Event * ev;
179 ev = mEventList.first(); 188 ev = mEventList.first();
180 while ( ev ) { 189 while ( ev ) {
181 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 190 if ( ev->uid().left(15) == QString("last-syncEvent-") )
182 ev->setCalEnabled( true ); 191 ev->setCalEnabled( true );
183 ev = mEventList.next(); 192 ev = mEventList.next();
184 } 193 }
185} 194}
186void CalendarLocal::setSyncEventsReadOnly() 195void CalendarLocal::setSyncEventsReadOnly()
187{ 196{
188 Event * ev; 197 Event * ev;
189 ev = mEventList.first(); 198 ev = mEventList.first();
190 while ( ev ) { 199 while ( ev ) {
191 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 200 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
192 ev->setReadOnly( true ); 201 ev->setReadOnly( true );
193 } 202 }
194 ev = mEventList.next(); 203 ev = mEventList.next();
195 } 204 }
196} 205}
197 206
198void CalendarLocal::addCalendar( Calendar* cal ) 207void CalendarLocal::addCalendar( Calendar* cal )
199{ 208{
200 cal->setDontDeleteIncidencesOnClose(); 209 cal->setDontDeleteIncidencesOnClose();
201 setSyncEventsEnabled(); 210 setSyncEventsEnabled();
202 { 211 {
203 QPtrList<Event> EventList = cal->rawEvents(); 212 QPtrList<Event> EventList = cal->rawEvents();
204 QPtrList<Event> el; 213 QPtrList<Event> el;
205 Event * ev = EventList.first(); 214 Event * ev = EventList.first();
206 while ( ev ) { 215 while ( ev ) {
207 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 216 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
208 Event * se = event( ev->uid() ); 217 Event * se = event( ev->uid() );
209 if ( se ) 218 if ( se )
210 el.append( se ); 219 el.append( se );
211 ev->setCalID_block( 1 ); 220 ev->setCalID_block( 1 );