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