summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
authorzautrix <zautrix>2005-04-15 07:31:29 (UTC)
committer zautrix <zautrix>2005-04-15 07:31:29 (UTC)
commit6a16de9a18235d2ddd771c97a4bb4512b43d181a (patch) (unidiff)
tree3fec37074addd6afc6eebb191d57a1d5ef5127ab /libkcal/todo.cpp
parent7e87a287a0860882af27e26288bc9cc553dd3a0b (diff)
downloadkdepimpi-6a16de9a18235d2ddd771c97a4bb4512b43d181a.zip
kdepimpi-6a16de9a18235d2ddd771c97a4bb4512b43d181a.tar.gz
kdepimpi-6a16de9a18235d2ddd771c97a4bb4512b43d181a.tar.bz2
fix
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 90e7eb9..b89abce 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,203 +1,233 @@
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 27
27#include "calendarlocal.h" 28#include "calendarlocal.h"
28#include "icalformat.h" 29#include "icalformat.h"
29#include "todo.h" 30#include "todo.h"
30 31
31using namespace KCal; 32using namespace KCal;
32 33
33Todo::Todo(): Incidence() 34Todo::Todo(): QObject(), Incidence()
34{ 35{
35// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
36 37
37 mHasDueDate = false; 38 mHasDueDate = false;
38 setHasStartDate( false ); 39 setHasStartDate( false );
39 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
40 mHasCompletedDate = false; 41 mHasCompletedDate = false;
41 mPercentComplete = 0; 42 mPercentComplete = 0;
42 mRunning = false; 43 mRunning = false;
43 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
44} 45}
45 46
46Todo::Todo(const Todo &t) : Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
47{ 48{
48 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
49 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
50 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
51 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
52 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
53 mRunning = false; 54 mRunning = false;
54 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
55} 56}
56 57
57Todo::~Todo() 58Todo::~Todo()
58{ 59{
59 setRunning( false ); 60 setRunning( false );
60 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
61} 62}
62 63
63void Todo::setRunning( bool run ) 64void Todo::setRunning( bool run )
64{ 65{
65 if ( run == mRunning ) 66 if ( run == mRunning )
66 return; 67 return;
67 if ( !mRunSaveTimer ) { 68 if ( !mRunSaveTimer ) {
68 mRunSaveTimer = new QTimer ( this ); 69 mRunSaveTimer = new QTimer ( this );
69 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 70 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
70 } 71 }
71 mRunning = run; 72 mRunning = run;
72 if ( mRunning ) { 73 if ( mRunning ) {
73 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 74 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
74 mRunStart = QDateTime::currentDateTime(); 75 mRunStart = QDateTime::currentDateTime();
75 } else { 76 } else {
76 mRunSaveTimer->stop(); 77 mRunSaveTimer->stop();
77 saveRunningInfoToFile(); 78 saveRunningInfoToFile();
78 } 79 }
79} 80}
80 81
81void Todo::saveRunningInfoToFile() 82void Todo::saveRunningInfoToFile()
82{ 83{
83 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 84 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
84 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) 85 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
86 qDebug("Running time < 30 seconds. Skipped. ");
85 return; 87 return;
88 }
86 QString dir = KGlobalSettings::timeTrackerDir(); 89 QString dir = KGlobalSettings::timeTrackerDir();
87 //qDebug("%s ", dir.latin1()); 90 //qDebug("%s ", dir.latin1());
88 QString file = "%1%2%3-%4%5%6-"; 91 QString file = "%1%2%3-%4%5%6-";
89 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 ); 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 );
90 file.replace ( QRegExp (" "), "0" ); 93 file.replace ( QRegExp (" "), "0" );
91 file += uid(); 94 file += uid();
92 //qDebug("File %s ",file.latin1() ); 95 //qDebug("File %s ",file.latin1() );
93 CalendarLocal cal; 96 CalendarLocal cal;
94 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); 97 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
95 Todo * to = (Todo*) clone(); 98 Todo * to = (Todo*) clone();
96 to->setFloats( false ); 99 to->setFloats( false );
97 to->setDtStart( mRunStart ); 100 to->setDtStart( mRunStart );
98 to->setHasStartDate( true ); 101 to->setHasStartDate( true );
99 to->setDtDue( QDateTime::currentDateTime() ); 102 to->setDtDue( QDateTime::currentDateTime() );
100 to->setHasDueDate( true ); 103 to->setHasDueDate( true );
101 to->setUid( file ); 104 to->setUid( file );
102 cal.addIncidence( to ); 105 cal.addIncidence( to );
103 ICalFormat format; 106 ICalFormat format;
104 file = dir +"/" +file +".ics"; 107 file = dir +"/" +file +".ics";
105 format.save( &cal, file ); 108 format.save( &cal, file );
109 saveParents();
106 110
107} 111}
112void Todo::saveParents()
113{
114 if (!relatedTo() )
115 return;
116 Incidence * inc = relatedTo();
117 if ( inc->type() != "Todo" )
118 return;
119 Todo* to = (Todo*)inc;
120 bool saveTodo = false;
121 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
122 QFileInfo fi ( file );
123 if ( fi.exists() ) {
124 if ( fi.lastModified () < to->lastModified ())
125 saveTodo = true;
126 } else {
127 saveTodo = true;
128 }
129 if ( saveTodo ) {
130 CalendarLocal cal;
131 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
132 Todo * par = (Todo *) to->clone();
133 cal.addIncidence( par );
134 ICalFormat format;
135 format.save( &cal, file );
136 }
137}
108 138
109int Todo::runTime() 139int Todo::runTime()
110{ 140{
111 if ( !mRunning ) 141 if ( !mRunning )
112 return 0; 142 return 0;
113 return mRunStart.secsTo( QDateTime::currentDateTime() ); 143 return mRunStart.secsTo( QDateTime::currentDateTime() );
114} 144}
115bool Todo::hasRunningSub() 145bool Todo::hasRunningSub()
116{ 146{
117 if ( mRunning ) 147 if ( mRunning )
118 return true; 148 return true;
119 Incidence *aTodo; 149 Incidence *aTodo;
120 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 150 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
121 if ( ((Todo*)aTodo)->hasRunningSub() ) 151 if ( ((Todo*)aTodo)->hasRunningSub() )
122 return true; 152 return true;
123 } 153 }
124 return false; 154 return false;
125} 155}
126Incidence *Todo::clone() 156Incidence *Todo::clone()
127{ 157{
128 return new Todo(*this); 158 return new Todo(*this);
129} 159}
130 160
131bool Todo::contains ( Todo* from ) 161bool Todo::contains ( Todo* from )
132{ 162{
133 163
134 if ( !from->summary().isEmpty() ) 164 if ( !from->summary().isEmpty() )
135 if ( !summary().startsWith( from->summary() )) 165 if ( !summary().startsWith( from->summary() ))
136 return false; 166 return false;
137 if ( from->hasStartDate() ) { 167 if ( from->hasStartDate() ) {
138 if ( !hasStartDate() ) 168 if ( !hasStartDate() )
139 return false; 169 return false;
140 if ( from->dtStart() != dtStart()) 170 if ( from->dtStart() != dtStart())
141 return false; 171 return false;
142 } 172 }
143 if ( from->hasDueDate() ){ 173 if ( from->hasDueDate() ){
144 if ( !hasDueDate() ) 174 if ( !hasDueDate() )
145 return false; 175 return false;
146 if ( from->dtDue() != dtDue()) 176 if ( from->dtDue() != dtDue())
147 return false; 177 return false;
148 } 178 }
149 if ( !from->location().isEmpty() ) 179 if ( !from->location().isEmpty() )
150 if ( !location().startsWith( from->location() ) ) 180 if ( !location().startsWith( from->location() ) )
151 return false; 181 return false;
152 if ( !from->description().isEmpty() ) 182 if ( !from->description().isEmpty() )
153 if ( !description().startsWith( from->description() )) 183 if ( !description().startsWith( from->description() ))
154 return false; 184 return false;
155 if ( from->alarms().count() ) { 185 if ( from->alarms().count() ) {
156 Alarm *a = from->alarms().first(); 186 Alarm *a = from->alarms().first();
157 if ( a->enabled() ){ 187 if ( a->enabled() ){
158 if ( !alarms().count() ) 188 if ( !alarms().count() )
159 return false; 189 return false;
160 Alarm *b = alarms().first(); 190 Alarm *b = alarms().first();
161 if( ! b->enabled() ) 191 if( ! b->enabled() )
162 return false; 192 return false;
163 if ( ! (a->offset() == b->offset() )) 193 if ( ! (a->offset() == b->offset() ))
164 return false; 194 return false;
165 } 195 }
166 } 196 }
167 197
168 QStringList cat = categories(); 198 QStringList cat = categories();
169 QStringList catFrom = from->categories(); 199 QStringList catFrom = from->categories();
170 QString nCat; 200 QString nCat;
171 unsigned int iii; 201 unsigned int iii;
172 for ( iii = 0; iii < catFrom.count();++iii ) { 202 for ( iii = 0; iii < catFrom.count();++iii ) {
173 nCat = catFrom[iii]; 203 nCat = catFrom[iii];
174 if ( !nCat.isEmpty() ) 204 if ( !nCat.isEmpty() )
175 if ( !cat.contains( nCat )) { 205 if ( !cat.contains( nCat )) {
176 return false; 206 return false;
177 } 207 }
178 } 208 }
179 if ( from->isCompleted() ) { 209 if ( from->isCompleted() ) {
180 if ( !isCompleted() ) 210 if ( !isCompleted() )
181 return false; 211 return false;
182 } 212 }
183 if( priority() != from->priority() ) 213 if( priority() != from->priority() )
184 return false; 214 return false;
185 215
186 216
187 return true; 217 return true;
188 218
189} 219}
190bool KCal::operator==( const Todo& t1, const Todo& t2 ) 220bool KCal::operator==( const Todo& t1, const Todo& t2 )
191{ 221{
192 222
193 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 223 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
194 if ( ! ret ) 224 if ( ! ret )
195 return false; 225 return false;
196 if ( t1.hasDueDate() == t2.hasDueDate() ) { 226 if ( t1.hasDueDate() == t2.hasDueDate() ) {
197 if ( t1.hasDueDate() ) { 227 if ( t1.hasDueDate() ) {
198 if ( t1.doesFloat() == t2.doesFloat() ) { 228 if ( t1.doesFloat() == t2.doesFloat() ) {
199 if ( t1.doesFloat() ) { 229 if ( t1.doesFloat() ) {
200 if ( t1.dtDue().date() != t2.dtDue().date() ) 230 if ( t1.dtDue().date() != t2.dtDue().date() )
201 return false; 231 return false;
202 } else 232 } else
203 if ( t1.dtDue() != t2.dtDue() ) 233 if ( t1.dtDue() != t2.dtDue() )