-rw-r--r-- | libkcal/todo.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 002d3f2..f7e38a7 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,233 +1,244 @@ | |||
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::setRunningFalse( QString s ) | ||
65 | { | ||
66 | if ( ! mRunning ) | ||
67 | return; | ||
68 | mRunning = false; | ||
69 | mRunSaveTimer->stop(); | ||
70 | saveRunningInfoToFile( s ); | ||
71 | } | ||
64 | void Todo::setRunning( bool run ) | 72 | void Todo::setRunning( bool run ) |
65 | { | 73 | { |
66 | if ( run == mRunning ) | 74 | if ( run == mRunning ) |
67 | return; | 75 | return; |
68 | //qDebug("Todo::setRunning %d ", run); | 76 | //qDebug("Todo::setRunning %d ", run); |
69 | if ( !mRunSaveTimer ) { | 77 | if ( !mRunSaveTimer ) { |
70 | mRunSaveTimer = new QTimer ( this ); | 78 | mRunSaveTimer = new QTimer ( this ); |
71 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 79 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
72 | } | 80 | } |
73 | mRunning = run; | 81 | mRunning = run; |
74 | if ( mRunning ) { | 82 | if ( mRunning ) { |
75 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 83 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
76 | mRunStart = QDateTime::currentDateTime(); | 84 | mRunStart = QDateTime::currentDateTime(); |
77 | } else { | 85 | } else { |
78 | mRunSaveTimer->stop(); | 86 | mRunSaveTimer->stop(); |
79 | saveRunningInfoToFile(); | 87 | saveRunningInfoToFile(); |
80 | } | 88 | } |
81 | } | 89 | } |
82 | 90 | ||
83 | void Todo::saveRunningInfoToFile() | 91 | void Todo::saveRunningInfoToFile( QString comment ) |
84 | { | 92 | { |
85 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 93 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
86 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { | 94 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
87 | qDebug("Running time < 30 seconds. Skipped. "); | 95 | qDebug("Running time < 30 seconds. Skipped. "); |
88 | return; | 96 | return; |
89 | } | 97 | } |
90 | QString dir = KGlobalSettings::timeTrackerDir(); | 98 | QString dir = KGlobalSettings::timeTrackerDir(); |
91 | //qDebug("%s ", dir.latin1()); | 99 | //qDebug("%s ", dir.latin1()); |
92 | QString file = "%1%2%3-%4%5%6-"; | 100 | QString file = "%1%2%3-%4%5%6-"; |
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 ); | 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 ); |
94 | file.replace ( QRegExp (" "), "0" ); | 102 | file.replace ( QRegExp (" "), "0" ); |
95 | file += uid(); | 103 | file += uid(); |
96 | //qDebug("File %s ",file.latin1() ); | 104 | //qDebug("File %s ",file.latin1() ); |
97 | CalendarLocal cal; | 105 | CalendarLocal cal; |
98 | cal.setLocalTime(); | 106 | cal.setLocalTime(); |
99 | Todo * to = (Todo*) clone(); | 107 | Todo * to = (Todo*) clone(); |
100 | to->setFloats( false ); | 108 | to->setFloats( false ); |
101 | to->setDtStart( mRunStart ); | 109 | to->setDtStart( mRunStart ); |
102 | to->setHasStartDate( true ); | 110 | to->setHasStartDate( true ); |
103 | to->setDtDue( QDateTime::currentDateTime() ); | 111 | to->setDtDue( QDateTime::currentDateTime() ); |
104 | to->setHasDueDate( true ); | 112 | to->setHasDueDate( true ); |
105 | to->setUid( file ); | 113 | to->setUid( file ); |
114 | if ( !comment.isEmpty() ) { | ||
115 | to->setDescription( comment ); | ||
116 | } | ||
106 | cal.addIncidence( to ); | 117 | cal.addIncidence( to ); |
107 | ICalFormat format; | 118 | ICalFormat format; |
108 | file = dir +"/" +file +".ics"; | 119 | file = dir +"/" +file +".ics"; |
109 | format.save( &cal, file ); | 120 | format.save( &cal, file ); |
110 | saveParents(); | 121 | saveParents(); |
111 | 122 | ||
112 | } | 123 | } |
113 | void Todo::saveParents() | 124 | void Todo::saveParents() |
114 | { | 125 | { |
115 | if (!relatedTo() ) | 126 | if (!relatedTo() ) |
116 | return; | 127 | return; |
117 | Incidence * inc = relatedTo(); | 128 | Incidence * inc = relatedTo(); |
118 | if ( inc->type() != "Todo" ) | 129 | if ( inc->type() != "Todo" ) |
119 | return; | 130 | return; |
120 | Todo* to = (Todo*)inc; | 131 | Todo* to = (Todo*)inc; |
121 | bool saveTodo = false; | 132 | bool saveTodo = false; |
122 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 133 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
123 | QFileInfo fi ( file ); | 134 | QFileInfo fi ( file ); |
124 | if ( fi.exists() ) { | 135 | if ( fi.exists() ) { |
125 | if ( fi.lastModified () < to->lastModified ()) | 136 | if ( fi.lastModified () < to->lastModified ()) |
126 | saveTodo = true; | 137 | saveTodo = true; |
127 | } else { | 138 | } else { |
128 | saveTodo = true; | 139 | saveTodo = true; |
129 | } | 140 | } |
130 | if ( saveTodo ) { | 141 | if ( saveTodo ) { |
131 | CalendarLocal cal; | 142 | CalendarLocal cal; |
132 | cal.setLocalTime(); | 143 | cal.setLocalTime(); |
133 | Todo * par = (Todo *) to->clone(); | 144 | Todo * par = (Todo *) to->clone(); |
134 | cal.addIncidence( par ); | 145 | cal.addIncidence( par ); |
135 | ICalFormat format; | 146 | ICalFormat format; |
136 | format.save( &cal, file ); | 147 | format.save( &cal, file ); |
137 | } | 148 | } |
138 | to->saveParents(); | 149 | to->saveParents(); |
139 | } | 150 | } |
140 | 151 | ||
141 | int Todo::runTime() | 152 | int Todo::runTime() |
142 | { | 153 | { |
143 | if ( !mRunning ) | 154 | if ( !mRunning ) |
144 | return 0; | 155 | return 0; |
145 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 156 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
146 | } | 157 | } |
147 | bool Todo::hasRunningSub() | 158 | bool Todo::hasRunningSub() |
148 | { | 159 | { |
149 | if ( mRunning ) | 160 | if ( mRunning ) |
150 | return true; | 161 | return true; |
151 | Incidence *aTodo; | 162 | Incidence *aTodo; |
152 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 163 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
153 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 164 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
154 | return true; | 165 | return true; |
155 | } | 166 | } |
156 | return false; | 167 | return false; |
157 | } | 168 | } |
158 | Incidence *Todo::clone() | 169 | Incidence *Todo::clone() |
159 | { | 170 | { |
160 | return new Todo(*this); | 171 | return new Todo(*this); |
161 | } | 172 | } |
162 | 173 | ||
163 | bool Todo::contains ( Todo* from ) | 174 | bool Todo::contains ( Todo* from ) |
164 | { | 175 | { |
165 | 176 | ||
166 | if ( !from->summary().isEmpty() ) | 177 | if ( !from->summary().isEmpty() ) |
167 | if ( !summary().startsWith( from->summary() )) | 178 | if ( !summary().startsWith( from->summary() )) |
168 | return false; | 179 | return false; |
169 | if ( from->hasStartDate() ) { | 180 | if ( from->hasStartDate() ) { |
170 | if ( !hasStartDate() ) | 181 | if ( !hasStartDate() ) |
171 | return false; | 182 | return false; |
172 | if ( from->dtStart() != dtStart()) | 183 | if ( from->dtStart() != dtStart()) |
173 | return false; | 184 | return false; |
174 | } | 185 | } |
175 | if ( from->hasDueDate() ){ | 186 | if ( from->hasDueDate() ){ |
176 | if ( !hasDueDate() ) | 187 | if ( !hasDueDate() ) |
177 | return false; | 188 | return false; |
178 | if ( from->dtDue() != dtDue()) | 189 | if ( from->dtDue() != dtDue()) |
179 | return false; | 190 | return false; |
180 | } | 191 | } |
181 | if ( !from->location().isEmpty() ) | 192 | if ( !from->location().isEmpty() ) |
182 | if ( !location().startsWith( from->location() ) ) | 193 | if ( !location().startsWith( from->location() ) ) |
183 | return false; | 194 | return false; |
184 | if ( !from->description().isEmpty() ) | 195 | if ( !from->description().isEmpty() ) |
185 | if ( !description().startsWith( from->description() )) | 196 | if ( !description().startsWith( from->description() )) |
186 | return false; | 197 | return false; |
187 | if ( from->alarms().count() ) { | 198 | if ( from->alarms().count() ) { |
188 | Alarm *a = from->alarms().first(); | 199 | Alarm *a = from->alarms().first(); |
189 | if ( a->enabled() ){ | 200 | if ( a->enabled() ){ |
190 | if ( !alarms().count() ) | 201 | if ( !alarms().count() ) |
191 | return false; | 202 | return false; |
192 | Alarm *b = alarms().first(); | 203 | Alarm *b = alarms().first(); |
193 | if( ! b->enabled() ) | 204 | if( ! b->enabled() ) |
194 | return false; | 205 | return false; |
195 | if ( ! (a->offset() == b->offset() )) | 206 | if ( ! (a->offset() == b->offset() )) |
196 | return false; | 207 | return false; |
197 | } | 208 | } |
198 | } | 209 | } |
199 | 210 | ||
200 | QStringList cat = categories(); | 211 | QStringList cat = categories(); |
201 | QStringList catFrom = from->categories(); | 212 | QStringList catFrom = from->categories(); |
202 | QString nCat; | 213 | QString nCat; |
203 | unsigned int iii; | 214 | unsigned int iii; |
204 | for ( iii = 0; iii < catFrom.count();++iii ) { | 215 | for ( iii = 0; iii < catFrom.count();++iii ) { |
205 | nCat = catFrom[iii]; | 216 | nCat = catFrom[iii]; |
206 | if ( !nCat.isEmpty() ) | 217 | if ( !nCat.isEmpty() ) |
207 | if ( !cat.contains( nCat )) { | 218 | if ( !cat.contains( nCat )) { |
208 | return false; | 219 | return false; |
209 | } | 220 | } |
210 | } | 221 | } |
211 | if ( from->isCompleted() ) { | 222 | if ( from->isCompleted() ) { |
212 | if ( !isCompleted() ) | 223 | if ( !isCompleted() ) |
213 | return false; | 224 | return false; |
214 | } | 225 | } |
215 | if( priority() != from->priority() ) | 226 | if( priority() != from->priority() ) |
216 | return false; | 227 | return false; |
217 | 228 | ||
218 | 229 | ||
219 | return true; | 230 | return true; |
220 | 231 | ||
221 | } | 232 | } |
222 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 233 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
223 | { | 234 | { |
224 | 235 | ||
225 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 236 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
226 | if ( ! ret ) | 237 | if ( ! ret ) |
227 | return false; | 238 | return false; |
228 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 239 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
229 | if ( t1.hasDueDate() ) { | 240 | if ( t1.hasDueDate() ) { |
230 | if ( t1.doesFloat() == t2.doesFloat() ) { | 241 | if ( t1.doesFloat() == t2.doesFloat() ) { |
231 | if ( t1.doesFloat() ) { | 242 | if ( t1.doesFloat() ) { |
232 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 243 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
233 | return false; | 244 | return false; |