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