-rw-r--r-- | libkcal/calendarlocal.cpp | 31 |
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 | |||
@@ -3,192 +3,223 @@ | |||
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 |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool 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 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool 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 | ||
83 | void CalendarLocal::close() | 83 | void 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 | |||
100 | bool 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 | } | ||
99 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool 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 | ||
111 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool 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 | ||
122 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void 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 | ||
132 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *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 | } |
145 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool 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 | } |
156 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool 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 | ||
170 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void 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 | ||
180 | QPtrList<Todo> CalendarLocal::rawTodos() | 211 | QPtrList<Todo> CalendarLocal::rawTodos() |
181 | { | 212 | { |
182 | return mTodoList; | 213 | return mTodoList; |
183 | } | 214 | } |
184 | Todo *CalendarLocal::todo( int id ) | 215 | Todo *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 | ||
194 | Event *CalendarLocal::event( int id ) | 225 | Event *CalendarLocal::event( int id ) |