-rw-r--r-- | libkcal/todo.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index b89abce..5e6ac22 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,163 +1,164 @@ | |||
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::setRunning( bool run ) | 64 | void Todo::setRunning( bool run ) |
65 | { | 65 | { |
66 | if ( run == mRunning ) | 66 | if ( run == mRunning ) |
67 | return; | 67 | return; |
68 | //qDebug("Todo::setRunning %d ", run); | ||
68 | if ( !mRunSaveTimer ) { | 69 | if ( !mRunSaveTimer ) { |
69 | mRunSaveTimer = new QTimer ( this ); | 70 | mRunSaveTimer = new QTimer ( this ); |
70 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 71 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
71 | } | 72 | } |
72 | mRunning = run; | 73 | mRunning = run; |
73 | if ( mRunning ) { | 74 | if ( mRunning ) { |
74 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 75 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
75 | mRunStart = QDateTime::currentDateTime(); | 76 | mRunStart = QDateTime::currentDateTime(); |
76 | } else { | 77 | } else { |
77 | mRunSaveTimer->stop(); | 78 | mRunSaveTimer->stop(); |
78 | saveRunningInfoToFile(); | 79 | saveRunningInfoToFile(); |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | void Todo::saveRunningInfoToFile() | 83 | void Todo::saveRunningInfoToFile() |
83 | { | 84 | { |
84 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 85 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
85 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { | 86 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
86 | qDebug("Running time < 30 seconds. Skipped. "); | 87 | qDebug("Running time < 30 seconds. Skipped. "); |
87 | return; | 88 | return; |
88 | } | 89 | } |
89 | QString dir = KGlobalSettings::timeTrackerDir(); | 90 | QString dir = KGlobalSettings::timeTrackerDir(); |
90 | //qDebug("%s ", dir.latin1()); | 91 | //qDebug("%s ", dir.latin1()); |
91 | QString file = "%1%2%3-%4%5%6-"; | 92 | QString file = "%1%2%3-%4%5%6-"; |
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 ); | 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 ); |
93 | file.replace ( QRegExp (" "), "0" ); | 94 | file.replace ( QRegExp (" "), "0" ); |
94 | file += uid(); | 95 | file += uid(); |
95 | //qDebug("File %s ",file.latin1() ); | 96 | //qDebug("File %s ",file.latin1() ); |
96 | CalendarLocal cal; | 97 | CalendarLocal cal; |
97 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 98 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
98 | Todo * to = (Todo*) clone(); | 99 | Todo * to = (Todo*) clone(); |
99 | to->setFloats( false ); | 100 | to->setFloats( false ); |
100 | to->setDtStart( mRunStart ); | 101 | to->setDtStart( mRunStart ); |
101 | to->setHasStartDate( true ); | 102 | to->setHasStartDate( true ); |
102 | to->setDtDue( QDateTime::currentDateTime() ); | 103 | to->setDtDue( QDateTime::currentDateTime() ); |
103 | to->setHasDueDate( true ); | 104 | to->setHasDueDate( true ); |
104 | to->setUid( file ); | 105 | to->setUid( file ); |
105 | cal.addIncidence( to ); | 106 | cal.addIncidence( to ); |
106 | ICalFormat format; | 107 | ICalFormat format; |
107 | file = dir +"/" +file +".ics"; | 108 | file = dir +"/" +file +".ics"; |
108 | format.save( &cal, file ); | 109 | format.save( &cal, file ); |
109 | saveParents(); | 110 | saveParents(); |
110 | 111 | ||
111 | } | 112 | } |
112 | void Todo::saveParents() | 113 | void Todo::saveParents() |
113 | { | 114 | { |
114 | if (!relatedTo() ) | 115 | if (!relatedTo() ) |
115 | return; | 116 | return; |
116 | Incidence * inc = relatedTo(); | 117 | Incidence * inc = relatedTo(); |
117 | if ( inc->type() != "Todo" ) | 118 | if ( inc->type() != "Todo" ) |
118 | return; | 119 | return; |
119 | Todo* to = (Todo*)inc; | 120 | Todo* to = (Todo*)inc; |
120 | bool saveTodo = false; | 121 | bool saveTodo = false; |
121 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 122 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
122 | QFileInfo fi ( file ); | 123 | QFileInfo fi ( file ); |
123 | if ( fi.exists() ) { | 124 | if ( fi.exists() ) { |
124 | if ( fi.lastModified () < to->lastModified ()) | 125 | if ( fi.lastModified () < to->lastModified ()) |
125 | saveTodo = true; | 126 | saveTodo = true; |
126 | } else { | 127 | } else { |
127 | saveTodo = true; | 128 | saveTodo = true; |
128 | } | 129 | } |
129 | if ( saveTodo ) { | 130 | if ( saveTodo ) { |
130 | CalendarLocal cal; | 131 | CalendarLocal cal; |
131 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 132 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
132 | Todo * par = (Todo *) to->clone(); | 133 | Todo * par = (Todo *) to->clone(); |
133 | cal.addIncidence( par ); | 134 | cal.addIncidence( par ); |
134 | ICalFormat format; | 135 | ICalFormat format; |
135 | format.save( &cal, file ); | 136 | format.save( &cal, file ); |
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
139 | int Todo::runTime() | 140 | int Todo::runTime() |
140 | { | 141 | { |
141 | if ( !mRunning ) | 142 | if ( !mRunning ) |
142 | return 0; | 143 | return 0; |
143 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 144 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
144 | } | 145 | } |
145 | bool Todo::hasRunningSub() | 146 | bool Todo::hasRunningSub() |
146 | { | 147 | { |
147 | if ( mRunning ) | 148 | if ( mRunning ) |
148 | return true; | 149 | return true; |
149 | Incidence *aTodo; | 150 | Incidence *aTodo; |
150 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 151 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
151 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 152 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
152 | return true; | 153 | return true; |
153 | } | 154 | } |
154 | return false; | 155 | return false; |
155 | } | 156 | } |
156 | Incidence *Todo::clone() | 157 | Incidence *Todo::clone() |
157 | { | 158 | { |
158 | return new Todo(*this); | 159 | return new Todo(*this); |
159 | } | 160 | } |
160 | 161 | ||
161 | bool Todo::contains ( Todo* from ) | 162 | bool Todo::contains ( Todo* from ) |
162 | { | 163 | { |
163 | 164 | ||