-rw-r--r-- | libkcal/todo.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 7dee4cd..c008fe1 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,206 +1,220 @@ | |||
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 <klocale.h> | 23 | #include <klocale.h> |
23 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | ||
24 | 26 | ||
25 | #include "todo.h" | 27 | #include "todo.h" |
26 | 28 | ||
27 | using namespace KCal; | 29 | using namespace KCal; |
28 | 30 | ||
29 | Todo::Todo(): Incidence() | 31 | Todo::Todo(): Incidence() |
30 | { | 32 | { |
31 | // mStatus = TENTATIVE; | 33 | // mStatus = TENTATIVE; |
32 | 34 | ||
33 | mHasDueDate = false; | 35 | mHasDueDate = false; |
34 | setHasStartDate( false ); | 36 | setHasStartDate( false ); |
35 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 37 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
36 | mHasCompletedDate = false; | 38 | mHasCompletedDate = false; |
37 | mPercentComplete = 0; | 39 | mPercentComplete = 0; |
38 | mRunning = false; | 40 | mRunning = false; |
39 | mRunSaveTimer = 0; | 41 | mRunSaveTimer = 0; |
40 | } | 42 | } |
41 | 43 | ||
42 | Todo::Todo(const Todo &t) : Incidence(t) | 44 | Todo::Todo(const Todo &t) : Incidence(t) |
43 | { | 45 | { |
44 | mDtDue = t.mDtDue; | 46 | mDtDue = t.mDtDue; |
45 | mHasDueDate = t.mHasDueDate; | 47 | mHasDueDate = t.mHasDueDate; |
46 | mCompleted = t.mCompleted; | 48 | mCompleted = t.mCompleted; |
47 | mHasCompletedDate = t.mHasCompletedDate; | 49 | mHasCompletedDate = t.mHasCompletedDate; |
48 | mPercentComplete = t.mPercentComplete; | 50 | mPercentComplete = t.mPercentComplete; |
49 | mRunning = false; | 51 | mRunning = false; |
50 | mRunSaveTimer = 0; | 52 | mRunSaveTimer = 0; |
51 | } | 53 | } |
52 | 54 | ||
53 | Todo::~Todo() | 55 | Todo::~Todo() |
54 | { | 56 | { |
55 | setRunning( false ); | 57 | setRunning( false ); |
56 | } | 58 | } |
57 | 59 | ||
58 | void Todo::setRunning( bool run ) | 60 | void Todo::setRunning( bool run ) |
59 | { | 61 | { |
60 | if ( run == mRunning ) | 62 | if ( run == mRunning ) |
61 | return; | 63 | return; |
62 | if ( !mRunSaveTimer ) { | 64 | if ( !mRunSaveTimer ) { |
63 | mRunSaveTimer = new QTimer ( this ); | 65 | mRunSaveTimer = new QTimer ( this ); |
64 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 66 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
65 | } | 67 | } |
66 | mRunning = run; | 68 | mRunning = run; |
67 | if ( mRunning ) { | 69 | if ( mRunning ) { |
68 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 70 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
69 | mRunStart = QDateTime::currentDateTime(); | 71 | mRunStart = QDateTime::currentDateTime(); |
70 | } else { | 72 | } else { |
71 | mRunSaveTimer->stop(); | 73 | mRunSaveTimer->stop(); |
72 | saveRunningInfoToFile(); | 74 | saveRunningInfoToFile(); |
73 | } | 75 | } |
74 | } | 76 | } |
75 | 77 | ||
76 | void Todo::saveRunningInfoToFile() | 78 | void Todo::saveRunningInfoToFile() |
77 | { | 79 | { |
78 | qDebug("Todo::saveRunningInfoToFile() "); | 80 | qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
81 | |||
82 | QString dir = KGlobalSettings::timeTrackerDir(); | ||
83 | qDebug("%s ", dir.latin1()); | ||
84 | QString file = "%1-%2-%3-%4-%5-%6-%7.tt"; | ||
85 | |||
86 | 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 ).arg( mRunStart.time().msec(), 3 ); | ||
87 | file.replace ( QRegExp (" "), "0" ); | ||
88 | file = dir +"/" +file; | ||
89 | qDebug("%s ", file.latin1()); | ||
90 | |||
91 | |||
92 | |||
79 | } | 93 | } |
80 | 94 | ||
81 | int Todo::runTime() | 95 | int Todo::runTime() |
82 | { | 96 | { |
83 | if ( !mRunning ) | 97 | if ( !mRunning ) |
84 | return 0; | 98 | return 0; |
85 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 99 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
86 | } | 100 | } |
87 | bool Todo::hasRunningSub() | 101 | bool Todo::hasRunningSub() |
88 | { | 102 | { |
89 | if ( mRunning ) | 103 | if ( mRunning ) |
90 | return true; | 104 | return true; |
91 | Incidence *aTodo; | 105 | Incidence *aTodo; |
92 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 106 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
93 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 107 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
94 | return true; | 108 | return true; |
95 | } | 109 | } |
96 | return false; | 110 | return false; |
97 | } | 111 | } |
98 | Incidence *Todo::clone() | 112 | Incidence *Todo::clone() |
99 | { | 113 | { |
100 | return new Todo(*this); | 114 | return new Todo(*this); |
101 | } | 115 | } |
102 | 116 | ||
103 | bool Todo::contains ( Todo* from ) | 117 | bool Todo::contains ( Todo* from ) |
104 | { | 118 | { |
105 | 119 | ||
106 | if ( !from->summary().isEmpty() ) | 120 | if ( !from->summary().isEmpty() ) |
107 | if ( !summary().startsWith( from->summary() )) | 121 | if ( !summary().startsWith( from->summary() )) |
108 | return false; | 122 | return false; |
109 | if ( from->hasStartDate() ) { | 123 | if ( from->hasStartDate() ) { |
110 | if ( !hasStartDate() ) | 124 | if ( !hasStartDate() ) |
111 | return false; | 125 | return false; |
112 | if ( from->dtStart() != dtStart()) | 126 | if ( from->dtStart() != dtStart()) |
113 | return false; | 127 | return false; |
114 | } | 128 | } |
115 | if ( from->hasDueDate() ){ | 129 | if ( from->hasDueDate() ){ |
116 | if ( !hasDueDate() ) | 130 | if ( !hasDueDate() ) |
117 | return false; | 131 | return false; |
118 | if ( from->dtDue() != dtDue()) | 132 | if ( from->dtDue() != dtDue()) |
119 | return false; | 133 | return false; |
120 | } | 134 | } |
121 | if ( !from->location().isEmpty() ) | 135 | if ( !from->location().isEmpty() ) |
122 | if ( !location().startsWith( from->location() ) ) | 136 | if ( !location().startsWith( from->location() ) ) |
123 | return false; | 137 | return false; |
124 | if ( !from->description().isEmpty() ) | 138 | if ( !from->description().isEmpty() ) |
125 | if ( !description().startsWith( from->description() )) | 139 | if ( !description().startsWith( from->description() )) |
126 | return false; | 140 | return false; |
127 | if ( from->alarms().count() ) { | 141 | if ( from->alarms().count() ) { |
128 | Alarm *a = from->alarms().first(); | 142 | Alarm *a = from->alarms().first(); |
129 | if ( a->enabled() ){ | 143 | if ( a->enabled() ){ |
130 | if ( !alarms().count() ) | 144 | if ( !alarms().count() ) |
131 | return false; | 145 | return false; |
132 | Alarm *b = alarms().first(); | 146 | Alarm *b = alarms().first(); |
133 | if( ! b->enabled() ) | 147 | if( ! b->enabled() ) |
134 | return false; | 148 | return false; |
135 | if ( ! (a->offset() == b->offset() )) | 149 | if ( ! (a->offset() == b->offset() )) |
136 | return false; | 150 | return false; |
137 | } | 151 | } |
138 | } | 152 | } |
139 | 153 | ||
140 | QStringList cat = categories(); | 154 | QStringList cat = categories(); |
141 | QStringList catFrom = from->categories(); | 155 | QStringList catFrom = from->categories(); |
142 | QString nCat; | 156 | QString nCat; |
143 | unsigned int iii; | 157 | unsigned int iii; |
144 | for ( iii = 0; iii < catFrom.count();++iii ) { | 158 | for ( iii = 0; iii < catFrom.count();++iii ) { |
145 | nCat = catFrom[iii]; | 159 | nCat = catFrom[iii]; |
146 | if ( !nCat.isEmpty() ) | 160 | if ( !nCat.isEmpty() ) |
147 | if ( !cat.contains( nCat )) { | 161 | if ( !cat.contains( nCat )) { |
148 | return false; | 162 | return false; |
149 | } | 163 | } |
150 | } | 164 | } |
151 | if ( from->isCompleted() ) { | 165 | if ( from->isCompleted() ) { |
152 | if ( !isCompleted() ) | 166 | if ( !isCompleted() ) |
153 | return false; | 167 | return false; |
154 | } | 168 | } |
155 | if( priority() != from->priority() ) | 169 | if( priority() != from->priority() ) |
156 | return false; | 170 | return false; |
157 | 171 | ||
158 | 172 | ||
159 | return true; | 173 | return true; |
160 | 174 | ||
161 | } | 175 | } |
162 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 176 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
163 | { | 177 | { |
164 | 178 | ||
165 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 179 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
166 | if ( ! ret ) | 180 | if ( ! ret ) |
167 | return false; | 181 | return false; |
168 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 182 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
169 | if ( t1.hasDueDate() ) { | 183 | if ( t1.hasDueDate() ) { |
170 | if ( t1.doesFloat() == t2.doesFloat() ) { | 184 | if ( t1.doesFloat() == t2.doesFloat() ) { |
171 | if ( t1.doesFloat() ) { | 185 | if ( t1.doesFloat() ) { |
172 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 186 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
173 | return false; | 187 | return false; |
174 | } else | 188 | } else |
175 | if ( t1.dtDue() != t2.dtDue() ) | 189 | if ( t1.dtDue() != t2.dtDue() ) |
176 | return false; | 190 | return false; |
177 | } else | 191 | } else |
178 | return false;// float != | 192 | return false;// float != |
179 | } | 193 | } |
180 | 194 | ||
181 | } else | 195 | } else |
182 | return false; | 196 | return false; |
183 | if ( t1.percentComplete() != t2.percentComplete() ) | 197 | if ( t1.percentComplete() != t2.percentComplete() ) |
184 | return false; | 198 | return false; |
185 | if ( t1.isCompleted() ) { | 199 | if ( t1.isCompleted() ) { |
186 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 200 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
187 | if ( t1.hasCompletedDate() ) { | 201 | if ( t1.hasCompletedDate() ) { |
188 | if ( t1.completed() != t2.completed() ) | 202 | if ( t1.completed() != t2.completed() ) |
189 | return false; | 203 | return false; |
190 | } | 204 | } |
191 | 205 | ||
192 | } else | 206 | } else |
193 | return false; | 207 | return false; |
194 | } | 208 | } |
195 | return true; | 209 | return true; |
196 | 210 | ||
197 | } | 211 | } |
198 | 212 | ||
199 | void Todo::setDtDue(const QDateTime &dtDue) | 213 | void Todo::setDtDue(const QDateTime &dtDue) |
200 | { | 214 | { |
201 | //int diffsecs = mDtDue.secsTo(dtDue); | 215 | //int diffsecs = mDtDue.secsTo(dtDue); |
202 | 216 | ||
203 | /*if (mReadOnly) return; | 217 | /*if (mReadOnly) return; |
204 | const QPtrList<Alarm>& alarms = alarms(); | 218 | const QPtrList<Alarm>& alarms = alarms(); |
205 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 219 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
206 | if (alarm->enabled()) { | 220 | if (alarm->enabled()) { |