summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 2201814..cc1c5ae 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,242 +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#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#endif 34#endif
35 35
36#define SAVETIMER_TIMEOUT_SECONDS 300 36#define SAVETIMER_TIMEOUT_SECONDS 300
37//#define SAVETIMER_TIMEOUT_SECONDS 8 37//#define SAVETIMER_TIMEOUT_SECONDS 8
38#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 38#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5
39 39
40using namespace KCal; 40using namespace KCal;
41 41
42Todo::Todo(): QObject(), Incidence() 42Todo::Todo(): QObject(), Incidence()
43{ 43{
44// mStatus = TENTATIVE; 44// mStatus = TENTATIVE;
45 45
46 mHasDueDate = false; 46 mHasDueDate = false;
47 setHasStartDate( false ); 47 setHasStartDate( false );
48 mCompleted = getEvenTime(QDateTime::currentDateTime()); 48 mCompleted = getEvenTime(QDateTime::currentDateTime());
49 mHasCompletedDate = false; 49 mHasCompletedDate = false;
50 mPercentComplete = 0; 50 mPercentComplete = 0;
51 mRunning = false; 51 mRunning = false;
52 mRunSaveTimer = 0; 52 mRunSaveTimer = 0;
53 setFloats( true ); 53 setFloats( true );
54 mCurrentTimerDelay = 0; 54 mCurrentTimerDelay = 0;
55} 55}
56 56
57Todo::Todo(const Todo &t) : QObject(),Incidence(t) 57Todo::Todo(const Todo &t) : QObject(),Incidence(t)
58{ 58{
59 mDtDue = t.mDtDue; 59 mDtDue = t.mDtDue;
60 mHasDueDate = t.mHasDueDate; 60 mHasDueDate = t.mHasDueDate;
61 mCompleted = t.mCompleted; 61 mCompleted = t.mCompleted;
62 mHasCompletedDate = t.mHasCompletedDate; 62 mHasCompletedDate = t.mHasCompletedDate;
63 mPercentComplete = t.mPercentComplete; 63 mPercentComplete = t.mPercentComplete;
64 mRunning = false; 64 mRunning = false;
65 mRunSaveTimer = 0; 65 mRunSaveTimer = 0;
66 mCurrentTimerDelay = 0; 66 mCurrentTimerDelay = 0;
67} 67}
68 68
69Todo::~Todo() 69Todo::~Todo()
70{ 70{
71 setRunning( false ); 71 setRunning( false );
72 //qDebug("Todo::~Todo() "); 72 //qDebug("Todo::~Todo() ");
73} 73}
74 74
75void Todo::setRunningFalse( QString s ) 75void Todo::setRunningFalse( QString s )
76{ 76{
77 if ( ! mRunning ) 77 if ( ! mRunning )
78 return; 78 return;
79 mRunning = false; 79 mRunning = false;
80 if ( mRunSaveTimer ) 80 if ( mRunSaveTimer )
81 mRunSaveTimer->stop(); 81 mRunSaveTimer->stop();
82 saveRunningInfoToFile( s ); 82 saveRunningInfoToFile( s );
83} 83}
84void Todo::stopRunning() 84void Todo::stopRunning()
85{ 85{
86 if ( !mRunning ) 86 if ( !mRunning )
87 return; 87 return;
88 if ( mRunSaveTimer ) 88 if ( mRunSaveTimer )
89 mRunSaveTimer->stop(); 89 mRunSaveTimer->stop();
90 mRunning = false; 90 mRunning = false;
91} 91}
92void Todo::setRunning( bool run ) 92void Todo::setRunning( bool run )
93{ 93{
94 if ( run == mRunning ) 94 if ( run == mRunning )
95 return; 95 return;
96 //qDebug("Todo::setRunning %d ", run); 96 //qDebug("Todo::setRunning %d ", run);
97 if ( !mRunSaveTimer ) { 97 if ( !mRunSaveTimer ) {
98 mRunSaveTimer = new QTimer ( this ); 98 mRunSaveTimer = new QTimer ( this );
99 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); 99 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) );
100 } 100 }
101 mRunning = run; 101 mRunning = run;
102 mRunLastSave = QDateTime::currentDateTime(); 102 mRunLastSave = QDateTime::currentDateTime();
103 if ( mRunning ) { 103 if ( mRunning ) {
104 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); 104 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
105 mRunStart = QDateTime::currentDateTime(); 105 mRunStart = QDateTime::currentDateTime();
106 } else { 106 } else {
107 mRunSaveTimer->stop(); 107 mRunSaveTimer->stop();
108 saveRunningInfoToFile(); 108 saveRunningInfoToFile();
109 } 109 }
110 mLastSavedFileName = ""; 110 mLastSavedFileName = "";
111} 111}
112void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 112void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
113{ 113{
114 if ( !mRunning) return; 114 if ( !mRunning) return;
115 if ( mRunSaveTimer )
116 mRunSaveTimer->stop();
115 mRunning = false; 117 mRunning = false;
116 mRunStart = start; 118 mRunStart = start;
117 mRunEnd = end; 119 mRunEnd = end;
118 saveRunningInfoToFile( comment ); 120 saveRunningInfoToFile( comment );
119} 121}
120void Todo::restartSaveTimer( int secs ) 122void Todo::restartSaveTimer( int secs )
121{ 123{
122 mRunSaveTimer->start( secs * 1000 ); 124 mRunSaveTimer->start( secs * 1000 );
123 mRunLastSave = QDateTime::currentDateTime(); 125 mRunLastSave = QDateTime::currentDateTime();
124 mCurrentTimerDelay = secs; 126 mCurrentTimerDelay = secs;
125} 127}
126void Todo::timerSlotSaveRunningInfoToFile() 128void Todo::timerSlotSaveRunningInfoToFile()
127{ 129{
128 mRunEnd = QDateTime::currentDateTime(); 130 mRunEnd = QDateTime::currentDateTime();
129 int secsTo = mRunLastSave.secsTo( mRunEnd ); 131 int secsTo = mRunLastSave.secsTo( mRunEnd );
130 //if( secsTo == 8 ) ++secsTo; 132 //if( secsTo == 8 ) ++secsTo;
131 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); 133 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
132 if ( secsTo > mCurrentTimerDelay ) { 134 if ( secsTo > mCurrentTimerDelay ) {
133 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); 135 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
134 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 136 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
135 return; 137 return;
136 } 138 }
137 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); 139 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time());
138 if ( msecs < 0 ) { 140 if ( msecs < 0 ) {
139 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 141 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
140 return; 142 return;
141 } 143 }
142 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 144 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
143 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { 145 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) {
144 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 146 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
145 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 147 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
146 return; 148 return;
147 } 149 }
148 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); 150 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
149 saveRunningInfoToFile( QString::null ); 151 saveRunningInfoToFile( QString::null );
150} 152}
151void Todo::saveRunningInfoToFile() 153void Todo::saveRunningInfoToFile()
152{ 154{
153 mRunEnd = QDateTime::currentDateTime(); 155 mRunEnd = QDateTime::currentDateTime();
154 saveRunningInfoToFile( QString::null ); 156 saveRunningInfoToFile( QString::null );
155} 157}
156void Todo::saveRunningInfoToFile( QString comment ) 158void Todo::saveRunningInfoToFile( QString comment )
157{ 159{
158#ifndef DESKTOP_VERSION 160#ifndef DESKTOP_VERSION
159 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); 161 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
160#endif 162#endif
161 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 163 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
162 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 164 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
163 qDebug("Running time < 15 seconds. Skipped. "); 165 qDebug("Running time < 15 seconds. Skipped. ");
164 return; 166 return;
165 } 167 }
166 QString dir = KGlobalSettings::timeTrackerDir(); 168 QString dir = KGlobalSettings::timeTrackerDir();
167 //qDebug("%s ", dir.latin1()); 169 //qDebug("%s ", dir.latin1());
168 QString file = "%1%2%3-%4%5%6-"; 170 QString file = "%1%2%3-%4%5%6-";
169 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 ); 171 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 );
170 file.replace ( QRegExp (" "), "0" ); 172 file.replace ( QRegExp (" "), "0" );
171 file += uid(); 173 file += uid();
172 //qDebug("File %s ",file.latin1() ); 174 //qDebug("File %s ",file.latin1() );
173 CalendarLocal cal; 175 CalendarLocal cal;
174 cal.setLocalTime(); 176 cal.setLocalTime();
175 Todo * to = (Todo*) clone(); 177 Todo * to = (Todo*) clone();
176 to->setFloats( false ); 178 to->setFloats( false );
177 to->setDtStart( mRunStart ); 179 to->setDtStart( mRunStart );
178 to->setHasStartDate( true ); 180 to->setHasStartDate( true );
179 to->setDtDue( mRunEnd ); 181 to->setDtDue( mRunEnd );
180 to->setHasDueDate( true ); 182 to->setHasDueDate( true );
181 to->setUid( file ); 183 to->setUid( file );
182 if ( !comment.isEmpty() ) { 184 if ( !comment.isEmpty() ) {
183 QString des = to->description(); 185 QString des = to->description();
184 if ( des.isEmpty () ) 186 if ( des.isEmpty () )
185 to->setDescription( "TT-Note: " + comment ); 187 to->setDescription( "TT-Note: " + comment );
186 else 188 else
187 to->setDescription( "TT-Note: " + comment +"\n" + des ); 189 to->setDescription( "TT-Note: " + comment +"\n" + des );
188 } 190 }
189 cal.addIncidence( to ); 191 cal.addIncidence( to );
190 ICalFormat format( false ); 192 ICalFormat format( false );
191 file = dir +"/" +file +".ics"; 193 file = dir +"/" +file +".ics";
192 format.save( &cal, file ); 194 format.save( &cal, file );
193 saveParents(); 195 saveParents();
194 if ( !mLastSavedFileName.isEmpty() ) { 196 if ( !mLastSavedFileName.isEmpty() ) {
195 if ( mLastSavedFileName != file ) { 197 if ( mLastSavedFileName != file ) {
196 QFile::remove( mLastSavedFileName ); 198 QFile::remove( mLastSavedFileName );
197 } 199 }
198 } 200 }
199 mLastSavedFileName = file; 201 mLastSavedFileName = file;
200#ifndef DESKTOP_VERSION 202#ifndef DESKTOP_VERSION
201 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); 203 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
202#endif 204#endif
203} 205}
204void Todo::saveParents() 206void Todo::saveParents()
205{ 207{
206 if (!relatedTo() ) 208 if (!relatedTo() )
207 return; 209 return;
208 Incidence * inc = relatedTo(); 210 Incidence * inc = relatedTo();
209 if ( inc->typeID() != todoID ) 211 if ( inc->typeID() != todoID )
210 return; 212 return;
211 Todo* to = (Todo*)inc; 213 Todo* to = (Todo*)inc;
212 bool saveTodo = false; 214 bool saveTodo = false;
213 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 215 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
214 QFileInfo fi ( file ); 216 QFileInfo fi ( file );
215 if ( fi.exists() ) { 217 if ( fi.exists() ) {
216 if ( fi.lastModified () < to->lastModified ()) 218 if ( fi.lastModified () < to->lastModified ())
217 saveTodo = true; 219 saveTodo = true;
218 } else { 220 } else {
219 saveTodo = true; 221 saveTodo = true;
220 } 222 }
221 if ( saveTodo ) { 223 if ( saveTodo ) {
222 CalendarLocal cal; 224 CalendarLocal cal;
223 cal.setLocalTime(); 225 cal.setLocalTime();
224 Todo * par = (Todo *) to->clone(); 226 Todo * par = (Todo *) to->clone();
225 cal.addIncidence( par ); 227 cal.addIncidence( par );
226 ICalFormat format( false ); 228 ICalFormat format( false );
227 format.save( &cal, file ); 229 format.save( &cal, file );
228 } 230 }
229 to->saveParents(); 231 to->saveParents();
230} 232}
231 233
232int Todo::runTime() 234int Todo::runTime()
233{ 235{
234 if ( !mRunning ) 236 if ( !mRunning )
235 return 0; 237 return 0;
236 return mRunStart.secsTo( QDateTime::currentDateTime() ); 238 return mRunStart.secsTo( QDateTime::currentDateTime() );
237} 239}
238bool Todo::hasRunningSub() 240bool Todo::hasRunningSub()
239{ 241{
240 if ( mRunning ) 242 if ( mRunning )
241 return true; 243 return true;
242 Incidence *aTodo; 244 Incidence *aTodo;