summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7906046..19a7ffd 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -44,74 +44,76 @@ Todo::Todo(): Incidence()
44} 44}
45 45
46Todo::Todo(const Todo &t) : Incidence(t) 46Todo::Todo(const Todo &t) : Incidence(t)
47{ 47{
48 mDtDue = t.mDtDue; 48 mDtDue = t.mDtDue;
49 mHasDueDate = t.mHasDueDate; 49 mHasDueDate = t.mHasDueDate;
50 mCompleted = t.mCompleted; 50 mCompleted = t.mCompleted;
51 mHasCompletedDate = t.mHasCompletedDate; 51 mHasCompletedDate = t.mHasCompletedDate;
52 mPercentComplete = t.mPercentComplete; 52 mPercentComplete = t.mPercentComplete;
53 mRunning = false; 53 mRunning = false;
54 mRunSaveTimer = 0; 54 mRunSaveTimer = 0;
55} 55}
56 56
57Todo::~Todo() 57Todo::~Todo()
58{ 58{
59 setRunning( false ); 59 setRunning( false );
60 qDebug("Todo::~Todo() "); 60 //qDebug("Todo::~Todo() ");
61} 61}
62 62
63void Todo::setRunning( bool run ) 63void Todo::setRunning( bool run )
64{ 64{
65 if ( run == mRunning ) 65 if ( run == mRunning )
66 return; 66 return;
67 if ( !mRunSaveTimer ) { 67 if ( !mRunSaveTimer ) {
68 mRunSaveTimer = new QTimer ( this ); 68 mRunSaveTimer = new QTimer ( this );
69 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 69 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
70 } 70 }
71 mRunning = run; 71 mRunning = run;
72 if ( mRunning ) { 72 if ( mRunning ) {
73 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 73 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
74 mRunStart = QDateTime::currentDateTime(); 74 mRunStart = QDateTime::currentDateTime();
75 } else { 75 } else {
76 mRunSaveTimer->stop(); 76 mRunSaveTimer->stop();
77 saveRunningInfoToFile(); 77 saveRunningInfoToFile();
78 } 78 }
79} 79}
80 80
81void Todo::saveRunningInfoToFile() 81void Todo::saveRunningInfoToFile()
82{ 82{
83 qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 83 qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
84 84
85 QString dir = KGlobalSettings::timeTrackerDir(); 85 QString dir = KGlobalSettings::timeTrackerDir();
86 qDebug("%s ", dir.latin1()); 86 qDebug("%s ", dir.latin1());
87 QString file = "%1%2%3-%4%5%6-%7%8%9-"; 87 QString file = "%1%2%3-%4%5%6-";
88 int runtime = mRunStart.secsTo( QDateTime::currentDateTime() ); 88 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 );
89 runtime = (runtime / 60) +1;
90 int h = runtime / 60;
91 int m = runtime % 60;
92 int d = h / 24;
93 h = h % 24;
94 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( d,3 ).arg( h,2 ).arg( m,2 );
95 file.replace ( QRegExp (" "), "0" ); 89 file.replace ( QRegExp (" "), "0" );
96 file = dir +"/" +file + uid()+".ics"; 90 file += uid();
97 qDebug("File %s ",file.latin1() ); 91 qDebug("File %s ",file.latin1() );
98 CalendarLocal cal; 92 CalendarLocal cal;
99 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); 93 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
100 cal.addIncidence( clone() ); 94 Todo * to = (Todo*) clone();
95 to->setFloats( false );
96 to->setDtStart( mRunStart );
97 to->setHasStartDate( true );
98 to->setDtDue( QDateTime::currentDateTime() );
99 to->setHasDueDate( true );
100 to->setUid( file );
101 cal.addIncidence( to );
101 ICalFormat format; 102 ICalFormat format;
103 file = dir +"/" +file +".ics";
102 format.save( &cal, file ); 104 format.save( &cal, file );
103 105
104} 106}
105 107
106int Todo::runTime() 108int Todo::runTime()
107{ 109{
108 if ( !mRunning ) 110 if ( !mRunning )
109 return 0; 111 return 0;
110 return mRunStart.secsTo( QDateTime::currentDateTime() ); 112 return mRunStart.secsTo( QDateTime::currentDateTime() );
111} 113}
112bool Todo::hasRunningSub() 114bool Todo::hasRunningSub()
113{ 115{
114 if ( mRunning ) 116 if ( mRunning )
115 return true; 117 return true;
116 Incidence *aTodo; 118 Incidence *aTodo;
117 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 119 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
@@ -226,33 +228,32 @@ void Todo::setDtDue(const QDateTime &dtDue)
226 //int diffsecs = mDtDue.secsTo(dtDue); 228 //int diffsecs = mDtDue.secsTo(dtDue);
227 229
228 /*if (mReadOnly) return; 230 /*if (mReadOnly) return;
229 const QPtrList<Alarm>& alarms = alarms(); 231 const QPtrList<Alarm>& alarms = alarms();
230 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 232 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
231 if (alarm->enabled()) { 233 if (alarm->enabled()) {
232 alarm->setTime(alarm->time().addSecs(diffsecs)); 234 alarm->setTime(alarm->time().addSecs(diffsecs));
233 } 235 }
234 }*/ 236 }*/
235 mDtDue = getEvenTime(dtDue); 237 mDtDue = getEvenTime(dtDue);
236 238
237 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 239 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
238 240
239 /*const QPtrList<Alarm>& alarms = alarms(); 241 /*const QPtrList<Alarm>& alarms = alarms();
240 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 242 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
241 alarm->setAlarmStart(mDtDue);*/ 243 alarm->setAlarmStart(mDtDue);*/
242
243 updated(); 244 updated();
244} 245}
245 246
246QDateTime Todo::dtDue() const 247QDateTime Todo::dtDue() const
247{ 248{
248 return mDtDue; 249 return mDtDue;
249} 250}
250 251
251QString Todo::dtDueTimeStr() const 252QString Todo::dtDueTimeStr() const
252{ 253{
253 return KGlobal::locale()->formatTime(mDtDue.time()); 254 return KGlobal::locale()->formatTime(mDtDue.time());
254} 255}
255 256
256QString Todo::dtDueDateStr(bool shortfmt) const 257QString Todo::dtDueDateStr(bool shortfmt) const
257{ 258{
258 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 259 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);