-rw-r--r-- | libkcal/calendarlocal.cpp | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 00a43e5..e75df70 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,276 +1,280 @@ | |||
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 |
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 | |||
86 | Todo * i; | ||
87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | ||
88 | |||
85 | mEventList.setAutoDelete( true ); | 89 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 90 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 91 | mJournalList.setAutoDelete( false ); |
88 | 92 | ||
89 | mEventList.clear(); | 93 | mEventList.clear(); |
90 | mTodoList.clear(); | 94 | mTodoList.clear(); |
91 | mJournalList.clear(); | 95 | mJournalList.clear(); |
92 | 96 | ||
93 | mEventList.setAutoDelete( false ); | 97 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 98 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 99 | mJournalList.setAutoDelete( false ); |
96 | 100 | ||
97 | setModified( false ); | 101 | setModified( false ); |
98 | } | 102 | } |
99 | 103 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 105 | { |
102 | QString cat; | 106 | QString cat; |
103 | bool isBirthday = true; | 107 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 109 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 110 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 112 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 113 | cat = i18n( "Birthday" ); |
110 | } else { | 114 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 115 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 116 | return false; |
113 | } | 117 | } |
114 | Event * eve; | 118 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 120 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 121 | continue; |
118 | // now we have an event with fitting category | 122 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 123 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 124 | continue; |
121 | // now we have an event with fitting category+date | 125 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 126 | if ( eve->summary() != event->summary() ) |
123 | continue; | 127 | continue; |
124 | // now we have an event with fitting category+date+summary | 128 | // now we have an event with fitting category+date+summary |
125 | return false; | 129 | return false; |
126 | } | 130 | } |
127 | return addEvent( event ); | 131 | return addEvent( event ); |
128 | 132 | ||
129 | } | 133 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 134 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 135 | { |
132 | Event * eve; | 136 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 138 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 140 | return false; |
137 | } | 141 | } |
138 | } | 142 | } |
139 | return addEvent( event ); | 143 | return addEvent( event ); |
140 | } | 144 | } |
141 | 145 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 146 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 147 | { |
144 | insertEvent( event ); | 148 | insertEvent( event ); |
145 | 149 | ||
146 | event->registerObserver( this ); | 150 | event->registerObserver( this ); |
147 | 151 | ||
148 | setModified( true ); | 152 | setModified( true ); |
149 | 153 | ||
150 | return true; | 154 | return true; |
151 | } | 155 | } |
152 | 156 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 157 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 158 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 159 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 160 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 161 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 162 | setModified( true ); |
159 | } | 163 | } |
160 | } | 164 | } |
161 | 165 | ||
162 | 166 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 167 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 168 | { |
165 | 169 | ||
166 | Event *event; | 170 | Event *event; |
167 | 171 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 172 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 173 | if ( event->uid() == uid ) { |
170 | return event; | 174 | return event; |
171 | } | 175 | } |
172 | } | 176 | } |
173 | 177 | ||
174 | return 0; | 178 | return 0; |
175 | } | 179 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 180 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 181 | { |
178 | Todo * eve; | 182 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 183 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 184 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 185 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 186 | return false; |
183 | } | 187 | } |
184 | } | 188 | } |
185 | return addTodo( todo ); | 189 | return addTodo( todo ); |
186 | } | 190 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 191 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 192 | { |
189 | mTodoList.append( todo ); | 193 | mTodoList.append( todo ); |
190 | 194 | ||
191 | todo->registerObserver( this ); | 195 | todo->registerObserver( this ); |
192 | 196 | ||
193 | // Set up subtask relations | 197 | // Set up subtask relations |
194 | setupRelations( todo ); | 198 | setupRelations( todo ); |
195 | 199 | ||
196 | setModified( true ); | 200 | setModified( true ); |
197 | 201 | ||
198 | return true; | 202 | return true; |
199 | } | 203 | } |
200 | 204 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 205 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 206 | { |
203 | // Handle orphaned children | 207 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 208 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 209 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 210 | mUndoIncidence = todo->clone(); |
207 | 211 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 212 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 213 | setModified( true ); |
210 | } | 214 | } |
211 | } | 215 | } |
212 | 216 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 217 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 218 | { |
215 | return mTodoList; | 219 | return mTodoList; |
216 | } | 220 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 221 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 222 | { |
219 | Todo *todo; | 223 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 224 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 225 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 226 | } |
223 | 227 | ||
224 | return 0; | 228 | return 0; |
225 | } | 229 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 230 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 231 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 232 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 233 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 234 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 235 | inc->removeID( syncProfile ); |
232 | } | 236 | } |
233 | if ( syncProfile.isEmpty() ) { | 237 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 238 | QPtrList<Event> el; |
235 | Event *todo; | 239 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 240 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 241 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 242 | el.append( todo ); |
239 | } | 243 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 244 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 245 | deleteIncidence ( todo ); |
242 | } | 246 | } |
243 | } else { | 247 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 248 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | if ( lse ) | 249 | if ( lse ) |
246 | deleteIncidence ( lse ); | 250 | deleteIncidence ( lse ); |
247 | } | 251 | } |
248 | } | 252 | } |
249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 253 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
250 | { | 254 | { |
251 | QPtrList<Event> el; | 255 | QPtrList<Event> el; |
252 | Event *todo; | 256 | Event *todo; |
253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 257 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 258 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
255 | if ( todo->summary().left(3) == "E: " ) | 259 | if ( todo->summary().left(3) == "E: " ) |
256 | el.append( todo ); | 260 | el.append( todo ); |
257 | } | 261 | } |
258 | 262 | ||
259 | return el; | 263 | return el; |
260 | 264 | ||
261 | } | 265 | } |
262 | Event *CalendarLocal::event( QString syncProf, QString id ) | 266 | Event *CalendarLocal::event( QString syncProf, QString id ) |
263 | { | 267 | { |
264 | Event *todo; | 268 | Event *todo; |
265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 269 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
266 | if ( todo->getID( syncProf ) == id ) return todo; | 270 | if ( todo->getID( syncProf ) == id ) return todo; |
267 | } | 271 | } |
268 | 272 | ||
269 | return 0; | 273 | return 0; |
270 | } | 274 | } |
271 | Todo *CalendarLocal::todo( const QString &uid ) | 275 | Todo *CalendarLocal::todo( const QString &uid ) |
272 | { | 276 | { |
273 | Todo *todo; | 277 | Todo *todo; |
274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 278 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
275 | if ( todo->uid() == uid ) return todo; | 279 | if ( todo->uid() == uid ) return todo; |
276 | } | 280 | } |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index b89abce..5e6ac22 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,259 +1,260 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <kglobalsettings.h> | 22 | #include <kglobalsettings.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | 27 | ||
28 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
29 | #include "icalformat.h" | 29 | #include "icalformat.h" |
30 | #include "todo.h" | 30 | #include "todo.h" |
31 | 31 | ||
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | Todo::Todo(): QObject(), Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
35 | { | 35 | { |
36 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
37 | 37 | ||
38 | mHasDueDate = false; | 38 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
43 | mRunning = false; | 43 | mRunning = false; |
44 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
48 | { | 48 | { |
49 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
50 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
51 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
52 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
53 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
54 | mRunning = false; | 54 | mRunning = false; |
55 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | Todo::~Todo() | 58 | Todo::~Todo() |
59 | { | 59 | { |
60 | setRunning( false ); | 60 | setRunning( false ); |
61 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Todo::setRunning( bool run ) | 64 | void Todo::setRunning( bool run ) |
65 | { | 65 | { |
66 | if ( run == mRunning ) | 66 | if ( run == mRunning ) |
67 | return; | 67 | return; |
68 | //qDebug("Todo::setRunning %d ", run); | ||
68 | if ( !mRunSaveTimer ) { | 69 | if ( !mRunSaveTimer ) { |
69 | mRunSaveTimer = new QTimer ( this ); | 70 | mRunSaveTimer = new QTimer ( this ); |
70 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 71 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
71 | } | 72 | } |
72 | mRunning = run; | 73 | mRunning = run; |
73 | if ( mRunning ) { | 74 | if ( mRunning ) { |
74 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 75 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
75 | mRunStart = QDateTime::currentDateTime(); | 76 | mRunStart = QDateTime::currentDateTime(); |
76 | } else { | 77 | } else { |
77 | mRunSaveTimer->stop(); | 78 | mRunSaveTimer->stop(); |
78 | saveRunningInfoToFile(); | 79 | saveRunningInfoToFile(); |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | void Todo::saveRunningInfoToFile() | 83 | void Todo::saveRunningInfoToFile() |
83 | { | 84 | { |
84 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 85 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
85 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { | 86 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
86 | qDebug("Running time < 30 seconds. Skipped. "); | 87 | qDebug("Running time < 30 seconds. Skipped. "); |
87 | return; | 88 | return; |
88 | } | 89 | } |
89 | QString dir = KGlobalSettings::timeTrackerDir(); | 90 | QString dir = KGlobalSettings::timeTrackerDir(); |
90 | //qDebug("%s ", dir.latin1()); | 91 | //qDebug("%s ", dir.latin1()); |
91 | QString file = "%1%2%3-%4%5%6-"; | 92 | QString file = "%1%2%3-%4%5%6-"; |
92 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 93 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
93 | file.replace ( QRegExp (" "), "0" ); | 94 | file.replace ( QRegExp (" "), "0" ); |
94 | file += uid(); | 95 | file += uid(); |
95 | //qDebug("File %s ",file.latin1() ); | 96 | //qDebug("File %s ",file.latin1() ); |
96 | CalendarLocal cal; | 97 | CalendarLocal cal; |
97 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 98 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
98 | Todo * to = (Todo*) clone(); | 99 | Todo * to = (Todo*) clone(); |
99 | to->setFloats( false ); | 100 | to->setFloats( false ); |
100 | to->setDtStart( mRunStart ); | 101 | to->setDtStart( mRunStart ); |
101 | to->setHasStartDate( true ); | 102 | to->setHasStartDate( true ); |
102 | to->setDtDue( QDateTime::currentDateTime() ); | 103 | to->setDtDue( QDateTime::currentDateTime() ); |
103 | to->setHasDueDate( true ); | 104 | to->setHasDueDate( true ); |
104 | to->setUid( file ); | 105 | to->setUid( file ); |
105 | cal.addIncidence( to ); | 106 | cal.addIncidence( to ); |
106 | ICalFormat format; | 107 | ICalFormat format; |
107 | file = dir +"/" +file +".ics"; | 108 | file = dir +"/" +file +".ics"; |
108 | format.save( &cal, file ); | 109 | format.save( &cal, file ); |
109 | saveParents(); | 110 | saveParents(); |
110 | 111 | ||
111 | } | 112 | } |
112 | void Todo::saveParents() | 113 | void Todo::saveParents() |
113 | { | 114 | { |
114 | if (!relatedTo() ) | 115 | if (!relatedTo() ) |
115 | return; | 116 | return; |
116 | Incidence * inc = relatedTo(); | 117 | Incidence * inc = relatedTo(); |
117 | if ( inc->type() != "Todo" ) | 118 | if ( inc->type() != "Todo" ) |
118 | return; | 119 | return; |
119 | Todo* to = (Todo*)inc; | 120 | Todo* to = (Todo*)inc; |
120 | bool saveTodo = false; | 121 | bool saveTodo = false; |
121 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 122 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
122 | QFileInfo fi ( file ); | 123 | QFileInfo fi ( file ); |
123 | if ( fi.exists() ) { | 124 | if ( fi.exists() ) { |
124 | if ( fi.lastModified () < to->lastModified ()) | 125 | if ( fi.lastModified () < to->lastModified ()) |
125 | saveTodo = true; | 126 | saveTodo = true; |
126 | } else { | 127 | } else { |
127 | saveTodo = true; | 128 | saveTodo = true; |
128 | } | 129 | } |
129 | if ( saveTodo ) { | 130 | if ( saveTodo ) { |
130 | CalendarLocal cal; | 131 | CalendarLocal cal; |
131 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 132 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
132 | Todo * par = (Todo *) to->clone(); | 133 | Todo * par = (Todo *) to->clone(); |
133 | cal.addIncidence( par ); | 134 | cal.addIncidence( par ); |
134 | ICalFormat format; | 135 | ICalFormat format; |
135 | format.save( &cal, file ); | 136 | format.save( &cal, file ); |
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
139 | int Todo::runTime() | 140 | int Todo::runTime() |
140 | { | 141 | { |
141 | if ( !mRunning ) | 142 | if ( !mRunning ) |
142 | return 0; | 143 | return 0; |
143 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 144 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
144 | } | 145 | } |
145 | bool Todo::hasRunningSub() | 146 | bool Todo::hasRunningSub() |
146 | { | 147 | { |
147 | if ( mRunning ) | 148 | if ( mRunning ) |
148 | return true; | 149 | return true; |
149 | Incidence *aTodo; | 150 | Incidence *aTodo; |
150 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 151 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
151 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 152 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
152 | return true; | 153 | return true; |
153 | } | 154 | } |
154 | return false; | 155 | return false; |
155 | } | 156 | } |
156 | Incidence *Todo::clone() | 157 | Incidence *Todo::clone() |
157 | { | 158 | { |
158 | return new Todo(*this); | 159 | return new Todo(*this); |
159 | } | 160 | } |
160 | 161 | ||
161 | bool Todo::contains ( Todo* from ) | 162 | bool Todo::contains ( Todo* from ) |
162 | { | 163 | { |
163 | 164 | ||
164 | if ( !from->summary().isEmpty() ) | 165 | if ( !from->summary().isEmpty() ) |
165 | if ( !summary().startsWith( from->summary() )) | 166 | if ( !summary().startsWith( from->summary() )) |
166 | return false; | 167 | return false; |
167 | if ( from->hasStartDate() ) { | 168 | if ( from->hasStartDate() ) { |
168 | if ( !hasStartDate() ) | 169 | if ( !hasStartDate() ) |
169 | return false; | 170 | return false; |
170 | if ( from->dtStart() != dtStart()) | 171 | if ( from->dtStart() != dtStart()) |
171 | return false; | 172 | return false; |
172 | } | 173 | } |
173 | if ( from->hasDueDate() ){ | 174 | if ( from->hasDueDate() ){ |
174 | if ( !hasDueDate() ) | 175 | if ( !hasDueDate() ) |
175 | return false; | 176 | return false; |
176 | if ( from->dtDue() != dtDue()) | 177 | if ( from->dtDue() != dtDue()) |
177 | return false; | 178 | return false; |
178 | } | 179 | } |
179 | if ( !from->location().isEmpty() ) | 180 | if ( !from->location().isEmpty() ) |
180 | if ( !location().startsWith( from->location() ) ) | 181 | if ( !location().startsWith( from->location() ) ) |
181 | return false; | 182 | return false; |
182 | if ( !from->description().isEmpty() ) | 183 | if ( !from->description().isEmpty() ) |
183 | if ( !description().startsWith( from->description() )) | 184 | if ( !description().startsWith( from->description() )) |
184 | return false; | 185 | return false; |
185 | if ( from->alarms().count() ) { | 186 | if ( from->alarms().count() ) { |
186 | Alarm *a = from->alarms().first(); | 187 | Alarm *a = from->alarms().first(); |
187 | if ( a->enabled() ){ | 188 | if ( a->enabled() ){ |
188 | if ( !alarms().count() ) | 189 | if ( !alarms().count() ) |
189 | return false; | 190 | return false; |
190 | Alarm *b = alarms().first(); | 191 | Alarm *b = alarms().first(); |
191 | if( ! b->enabled() ) | 192 | if( ! b->enabled() ) |
192 | return false; | 193 | return false; |
193 | if ( ! (a->offset() == b->offset() )) | 194 | if ( ! (a->offset() == b->offset() )) |
194 | return false; | 195 | return false; |
195 | } | 196 | } |
196 | } | 197 | } |
197 | 198 | ||
198 | QStringList cat = categories(); | 199 | QStringList cat = categories(); |
199 | QStringList catFrom = from->categories(); | 200 | QStringList catFrom = from->categories(); |
200 | QString nCat; | 201 | QString nCat; |
201 | unsigned int iii; | 202 | unsigned int iii; |
202 | for ( iii = 0; iii < catFrom.count();++iii ) { | 203 | for ( iii = 0; iii < catFrom.count();++iii ) { |
203 | nCat = catFrom[iii]; | 204 | nCat = catFrom[iii]; |
204 | if ( !nCat.isEmpty() ) | 205 | if ( !nCat.isEmpty() ) |
205 | if ( !cat.contains( nCat )) { | 206 | if ( !cat.contains( nCat )) { |
206 | return false; | 207 | return false; |
207 | } | 208 | } |
208 | } | 209 | } |
209 | if ( from->isCompleted() ) { | 210 | if ( from->isCompleted() ) { |
210 | if ( !isCompleted() ) | 211 | if ( !isCompleted() ) |
211 | return false; | 212 | return false; |
212 | } | 213 | } |
213 | if( priority() != from->priority() ) | 214 | if( priority() != from->priority() ) |
214 | return false; | 215 | return false; |
215 | 216 | ||
216 | 217 | ||
217 | return true; | 218 | return true; |
218 | 219 | ||
219 | } | 220 | } |
220 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 221 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
221 | { | 222 | { |
222 | 223 | ||
223 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 224 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
224 | if ( ! ret ) | 225 | if ( ! ret ) |
225 | return false; | 226 | return false; |
226 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 227 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
227 | if ( t1.hasDueDate() ) { | 228 | if ( t1.hasDueDate() ) { |
228 | if ( t1.doesFloat() == t2.doesFloat() ) { | 229 | if ( t1.doesFloat() == t2.doesFloat() ) { |
229 | if ( t1.doesFloat() ) { | 230 | if ( t1.doesFloat() ) { |
230 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 231 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
231 | return false; | 232 | return false; |
232 | } else | 233 | } else |
233 | if ( t1.dtDue() != t2.dtDue() ) | 234 | if ( t1.dtDue() != t2.dtDue() ) |
234 | return false; | 235 | return false; |
235 | } else | 236 | } else |
236 | return false;// float != | 237 | return false;// float != |
237 | } | 238 | } |
238 | 239 | ||
239 | } else | 240 | } else |
240 | return false; | 241 | return false; |
241 | if ( t1.percentComplete() != t2.percentComplete() ) | 242 | if ( t1.percentComplete() != t2.percentComplete() ) |
242 | return false; | 243 | return false; |
243 | if ( t1.isCompleted() ) { | 244 | if ( t1.isCompleted() ) { |
244 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 245 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
245 | if ( t1.hasCompletedDate() ) { | 246 | if ( t1.hasCompletedDate() ) { |
246 | if ( t1.completed() != t2.completed() ) | 247 | if ( t1.completed() != t2.completed() ) |
247 | return false; | 248 | return false; |
248 | } | 249 | } |
249 | 250 | ||
250 | } else | 251 | } else |
251 | return false; | 252 | return false; |
252 | } | 253 | } |
253 | return true; | 254 | return true; |
254 | 255 | ||
255 | } | 256 | } |
256 | 257 | ||
257 | void Todo::setDtDue(const QDateTime &dtDue) | 258 | void Todo::setDtDue(const QDateTime &dtDue) |
258 | { | 259 | { |
259 | //int diffsecs = mDtDue.secsTo(dtDue); | 260 | //int diffsecs = mDtDue.secsTo(dtDue); |