summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index d062492..62b74f1 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,315 +1,321 @@
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
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::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
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::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
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 70 saveRunningInfoToFile( s );
71} 71}
72void Todo::stopRunning() 72void Todo::stopRunning()
73{ 73{
74 if ( !mRunning ) 74 if ( !mRunning )
75 return; 75 return;
76 if ( mRunSaveTimer ) 76 if ( mRunSaveTimer )
77 mRunSaveTimer->stop(); 77 mRunSaveTimer->stop();
78 mRunning = false; 78 mRunning = false;
79} 79}
80void Todo::setRunning( bool run ) 80void Todo::setRunning( bool run )
81{ 81{
82 if ( run == mRunning ) 82 if ( run == mRunning )
83 return; 83 return;
84 //qDebug("Todo::setRunning %d ", run); 84 //qDebug("Todo::setRunning %d ", run);
85 if ( !mRunSaveTimer ) { 85 if ( !mRunSaveTimer ) {
86 mRunSaveTimer = new QTimer ( this ); 86 mRunSaveTimer = new QTimer ( this );
87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
88 } 88 }
89 mRunning = run; 89 mRunning = run;
90 if ( mRunning ) { 90 if ( mRunning ) {
91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
92 mRunStart = QDateTime::currentDateTime(); 92 mRunStart = QDateTime::currentDateTime();
93 } else { 93 } else {
94 mRunSaveTimer->stop(); 94 mRunSaveTimer->stop();
95 saveRunningInfoToFile(); 95 saveRunningInfoToFile();
96 } 96 }
97} 97}
98 98void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
99{
100 mRunStart = start;
101 mRunEnd = end;
102 saveRunningInfoToFile( comment );
103}
99void Todo::saveRunningInfoToFile() 104void Todo::saveRunningInfoToFile()
100{ 105{
106 mRunEnd = QDateTime::currentDateTime();
101 saveRunningInfoToFile( QString::null ); 107 saveRunningInfoToFile( QString::null );
102} 108}
103void Todo::saveRunningInfoToFile( QString comment ) 109void Todo::saveRunningInfoToFile( QString comment )
104{ 110{
105 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 111 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
106 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 10 ) { 112 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 10 ) {
107 qDebug("Running time < 30 seconds. Skipped. "); 113 qDebug("Running time < 30 seconds. Skipped. ");
108 return; 114 return;
109 } 115 }
110 QString dir = KGlobalSettings::timeTrackerDir(); 116 QString dir = KGlobalSettings::timeTrackerDir();
111 //qDebug("%s ", dir.latin1()); 117 //qDebug("%s ", dir.latin1());
112 QString file = "%1%2%3-%4%5%6-"; 118 QString file = "%1%2%3-%4%5%6-";
113 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 ); 119 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 );
114 file.replace ( QRegExp (" "), "0" ); 120 file.replace ( QRegExp (" "), "0" );
115 file += uid(); 121 file += uid();
116 //qDebug("File %s ",file.latin1() ); 122 //qDebug("File %s ",file.latin1() );
117 CalendarLocal cal; 123 CalendarLocal cal;
118 cal.setLocalTime(); 124 cal.setLocalTime();
119 Todo * to = (Todo*) clone(); 125 Todo * to = (Todo*) clone();
120 to->setFloats( false ); 126 to->setFloats( false );
121 to->setDtStart( mRunStart ); 127 to->setDtStart( mRunStart );
122 to->setHasStartDate( true ); 128 to->setHasStartDate( true );
123 to->setDtDue( QDateTime::currentDateTime() ); 129 to->setDtDue( mRunEnd );
124 to->setHasDueDate( true ); 130 to->setHasDueDate( true );
125 to->setUid( file ); 131 to->setUid( file );
126 if ( !comment.isEmpty() ) { 132 if ( !comment.isEmpty() ) {
127 QString des = to->description(); 133 QString des = to->description();
128 if ( des.isEmpty () ) 134 if ( des.isEmpty () )
129 to->setDescription( "TT-Note: " + comment ); 135 to->setDescription( "TT-Note: " + comment );
130 else 136 else
131 to->setDescription( "TT-Note: " + comment +"\n" + des ); 137 to->setDescription( "TT-Note: " + comment +"\n" + des );
132 } 138 }
133 cal.addIncidence( to ); 139 cal.addIncidence( to );
134 ICalFormat format; 140 ICalFormat format;
135 file = dir +"/" +file +".ics"; 141 file = dir +"/" +file +".ics";
136 format.save( &cal, file ); 142 format.save( &cal, file );
137 saveParents(); 143 saveParents();
138 144
139} 145}
140void Todo::saveParents() 146void Todo::saveParents()
141{ 147{
142 if (!relatedTo() ) 148 if (!relatedTo() )
143 return; 149 return;
144 Incidence * inc = relatedTo(); 150 Incidence * inc = relatedTo();
145 if ( inc->typeID() != todoID ) 151 if ( inc->typeID() != todoID )
146 return; 152 return;
147 Todo* to = (Todo*)inc; 153 Todo* to = (Todo*)inc;
148 bool saveTodo = false; 154 bool saveTodo = false;
149 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 155 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
150 QFileInfo fi ( file ); 156 QFileInfo fi ( file );
151 if ( fi.exists() ) { 157 if ( fi.exists() ) {
152 if ( fi.lastModified () < to->lastModified ()) 158 if ( fi.lastModified () < to->lastModified ())
153 saveTodo = true; 159 saveTodo = true;
154 } else { 160 } else {
155 saveTodo = true; 161 saveTodo = true;
156 } 162 }
157 if ( saveTodo ) { 163 if ( saveTodo ) {
158 CalendarLocal cal; 164 CalendarLocal cal;
159 cal.setLocalTime(); 165 cal.setLocalTime();
160 Todo * par = (Todo *) to->clone(); 166 Todo * par = (Todo *) to->clone();
161 cal.addIncidence( par ); 167 cal.addIncidence( par );
162 ICalFormat format; 168 ICalFormat format;
163 format.save( &cal, file ); 169 format.save( &cal, file );
164 } 170 }
165 to->saveParents(); 171 to->saveParents();
166} 172}
167 173
168int Todo::runTime() 174int Todo::runTime()
169{ 175{
170 if ( !mRunning ) 176 if ( !mRunning )
171 return 0; 177 return 0;
172 return mRunStart.secsTo( QDateTime::currentDateTime() ); 178 return mRunStart.secsTo( QDateTime::currentDateTime() );
173} 179}
174bool Todo::hasRunningSub() 180bool Todo::hasRunningSub()
175{ 181{
176 if ( mRunning ) 182 if ( mRunning )
177 return true; 183 return true;
178 Incidence *aTodo; 184 Incidence *aTodo;
179 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 185 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
180 if ( ((Todo*)aTodo)->hasRunningSub() ) 186 if ( ((Todo*)aTodo)->hasRunningSub() )
181 return true; 187 return true;
182 } 188 }
183 return false; 189 return false;
184} 190}
185Incidence *Todo::clone() 191Incidence *Todo::clone()
186{ 192{
187 return new Todo(*this); 193 return new Todo(*this);
188} 194}
189 195
190bool Todo::contains ( Todo* from ) 196bool Todo::contains ( Todo* from )
191{ 197{
192 198
193 if ( !from->summary().isEmpty() ) 199 if ( !from->summary().isEmpty() )
194 if ( !summary().startsWith( from->summary() )) 200 if ( !summary().startsWith( from->summary() ))
195 return false; 201 return false;
196 if ( from->hasStartDate() ) { 202 if ( from->hasStartDate() ) {
197 if ( !hasStartDate() ) 203 if ( !hasStartDate() )
198 return false; 204 return false;
199 if ( from->dtStart() != dtStart()) 205 if ( from->dtStart() != dtStart())
200 return false; 206 return false;
201 } 207 }
202 if ( from->hasDueDate() ){ 208 if ( from->hasDueDate() ){
203 if ( !hasDueDate() ) 209 if ( !hasDueDate() )
204 return false; 210 return false;
205 if ( from->dtDue() != dtDue()) 211 if ( from->dtDue() != dtDue())
206 return false; 212 return false;
207 } 213 }
208 if ( !from->location().isEmpty() ) 214 if ( !from->location().isEmpty() )
209 if ( !location().startsWith( from->location() ) ) 215 if ( !location().startsWith( from->location() ) )
210 return false; 216 return false;
211 if ( !from->description().isEmpty() ) 217 if ( !from->description().isEmpty() )
212 if ( !description().startsWith( from->description() )) 218 if ( !description().startsWith( from->description() ))
213 return false; 219 return false;
214 if ( from->alarms().count() ) { 220 if ( from->alarms().count() ) {
215 Alarm *a = from->alarms().first(); 221 Alarm *a = from->alarms().first();
216 if ( a->enabled() ){ 222 if ( a->enabled() ){
217 if ( !alarms().count() ) 223 if ( !alarms().count() )
218 return false; 224 return false;
219 Alarm *b = alarms().first(); 225 Alarm *b = alarms().first();
220 if( ! b->enabled() ) 226 if( ! b->enabled() )
221 return false; 227 return false;
222 if ( ! (a->offset() == b->offset() )) 228 if ( ! (a->offset() == b->offset() ))
223 return false; 229 return false;
224 } 230 }
225 } 231 }
226 232
227 QStringList cat = categories(); 233 QStringList cat = categories();
228 QStringList catFrom = from->categories(); 234 QStringList catFrom = from->categories();
229 QString nCat; 235 QString nCat;
230 unsigned int iii; 236 unsigned int iii;
231 for ( iii = 0; iii < catFrom.count();++iii ) { 237 for ( iii = 0; iii < catFrom.count();++iii ) {
232 nCat = catFrom[iii]; 238 nCat = catFrom[iii];
233 if ( !nCat.isEmpty() ) 239 if ( !nCat.isEmpty() )
234 if ( !cat.contains( nCat )) { 240 if ( !cat.contains( nCat )) {
235 return false; 241 return false;
236 } 242 }
237 } 243 }
238 if ( from->isCompleted() ) { 244 if ( from->isCompleted() ) {
239 if ( !isCompleted() ) 245 if ( !isCompleted() )
240 return false; 246 return false;
241 } 247 }
242 if( priority() != from->priority() ) 248 if( priority() != from->priority() )
243 return false; 249 return false;
244 250
245 251
246 return true; 252 return true;
247 253
248} 254}
249bool KCal::operator==( const Todo& t1, const Todo& t2 ) 255bool KCal::operator==( const Todo& t1, const Todo& t2 )
250{ 256{
251 257
252 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 258 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
253 if ( ! ret ) 259 if ( ! ret )
254 return false; 260 return false;
255 if ( t1.hasDueDate() == t2.hasDueDate() ) { 261 if ( t1.hasDueDate() == t2.hasDueDate() ) {
256 if ( t1.hasDueDate() ) { 262 if ( t1.hasDueDate() ) {
257 if ( t1.doesFloat() == t2.doesFloat() ) { 263 if ( t1.doesFloat() == t2.doesFloat() ) {
258 if ( t1.doesFloat() ) { 264 if ( t1.doesFloat() ) {
259 if ( t1.dtDue().date() != t2.dtDue().date() ) 265 if ( t1.dtDue().date() != t2.dtDue().date() )
260 return false; 266 return false;
261 } else 267 } else
262 if ( t1.dtDue() != t2.dtDue() ) 268 if ( t1.dtDue() != t2.dtDue() )
263 return false; 269 return false;
264 } else 270 } else
265 return false;// float != 271 return false;// float !=
266 } 272 }
267 273
268 } else 274 } else
269 return false; 275 return false;
270 if ( t1.percentComplete() != t2.percentComplete() ) 276 if ( t1.percentComplete() != t2.percentComplete() )
271 return false; 277 return false;
272 if ( t1.isCompleted() ) { 278 if ( t1.isCompleted() ) {
273 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 279 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
274 if ( t1.hasCompletedDate() ) { 280 if ( t1.hasCompletedDate() ) {
275 if ( t1.completed() != t2.completed() ) 281 if ( t1.completed() != t2.completed() )
276 return false; 282 return false;
277 } 283 }
278 284
279 } else 285 } else
280 return false; 286 return false;
281 } 287 }
282 return true; 288 return true;
283 289
284} 290}
285 291
286void Todo::setDtDue(const QDateTime &dtDue) 292void Todo::setDtDue(const QDateTime &dtDue)
287{ 293{
288 //int diffsecs = mDtDue.secsTo(dtDue); 294 //int diffsecs = mDtDue.secsTo(dtDue);
289 295
290 /*if (mReadOnly) return; 296 /*if (mReadOnly) return;
291 const QPtrList<Alarm>& alarms = alarms(); 297 const QPtrList<Alarm>& alarms = alarms();
292 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 298 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
293 if (alarm->enabled()) { 299 if (alarm->enabled()) {
294 alarm->setTime(alarm->time().addSecs(diffsecs)); 300 alarm->setTime(alarm->time().addSecs(diffsecs));
295 } 301 }
296 }*/ 302 }*/
297 mDtDue = getEvenTime(dtDue); 303 mDtDue = getEvenTime(dtDue);
298 304
299 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 305 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
300 306
301 /*const QPtrList<Alarm>& alarms = alarms(); 307 /*const QPtrList<Alarm>& alarms = alarms();
302 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 308 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
303 alarm->setAlarmStart(mDtDue);*/ 309 alarm->setAlarmStart(mDtDue);*/
304 updated(); 310 updated();
305} 311}
306 312
307QDateTime Todo::dtDue() const 313QDateTime Todo::dtDue() const
308{ 314{
309 return mDtDue; 315 return mDtDue;
310} 316}
311 317
312QString Todo::dtDueTimeStr() const 318QString Todo::dtDueTimeStr() const
313{ 319{
314 return KGlobal::locale()->formatTime(mDtDue.time()); 320 return KGlobal::locale()->formatTime(mDtDue.time());
315} 321}