-rw-r--r-- | libkcal/todo.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 4ada2d8..7bf756a 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -37,65 +37,66 @@ Todo::Todo(): QObject(), Incidence() | |||
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 ) | 64 | void Todo::setRunningFalse( QString s ) |
65 | { | 65 | { |
66 | if ( ! mRunning ) | 66 | if ( ! mRunning ) |
67 | return; | 67 | return; |
68 | mRunning = false; | 68 | mRunning = false; |
69 | mRunSaveTimer->stop(); | 69 | if ( mRunSaveTimer ) |
70 | mRunSaveTimer->stop(); | ||
70 | saveRunningInfoToFile( s ); | 71 | saveRunningInfoToFile( s ); |
71 | } | 72 | } |
72 | void Todo::stopRunning() | 73 | void Todo::stopRunning() |
73 | { | 74 | { |
74 | if ( !mRunning ) | 75 | if ( !mRunning ) |
75 | return; | 76 | return; |
76 | if ( mRunSaveTimer ) | 77 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 78 | mRunSaveTimer->stop(); |
78 | mRunning = false; | 79 | mRunning = false; |
79 | } | 80 | } |
80 | void Todo::setRunning( bool run ) | 81 | void Todo::setRunning( bool run ) |
81 | { | 82 | { |
82 | if ( run == mRunning ) | 83 | if ( run == mRunning ) |
83 | return; | 84 | return; |
84 | //qDebug("Todo::setRunning %d ", run); | 85 | //qDebug("Todo::setRunning %d ", run); |
85 | if ( !mRunSaveTimer ) { | 86 | if ( !mRunSaveTimer ) { |
86 | mRunSaveTimer = new QTimer ( this ); | 87 | mRunSaveTimer = new QTimer ( this ); |
87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 88 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
88 | } | 89 | } |
89 | mRunning = run; | 90 | mRunning = run; |
90 | if ( mRunning ) { | 91 | if ( mRunning ) { |
91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 92 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
92 | mRunStart = QDateTime::currentDateTime(); | 93 | mRunStart = QDateTime::currentDateTime(); |
93 | } else { | 94 | } else { |
94 | mRunSaveTimer->stop(); | 95 | mRunSaveTimer->stop(); |
95 | saveRunningInfoToFile(); | 96 | saveRunningInfoToFile(); |
96 | } | 97 | } |
97 | } | 98 | } |
98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 99 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
99 | { | 100 | { |
100 | if ( !mRunning) return; | 101 | if ( !mRunning) return; |
101 | mRunning = false; | 102 | mRunning = false; |
@@ -110,93 +111,93 @@ void Todo::saveRunningInfoToFile() | |||
110 | } | 111 | } |
111 | void Todo::saveRunningInfoToFile( QString comment ) | 112 | void Todo::saveRunningInfoToFile( QString comment ) |
112 | { | 113 | { |
113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 114 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
114 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 115 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
115 | qDebug("Running time < 15 seconds. Skipped. "); | 116 | qDebug("Running time < 15 seconds. Skipped. "); |
116 | return; | 117 | return; |
117 | } | 118 | } |
118 | QString dir = KGlobalSettings::timeTrackerDir(); | 119 | QString dir = KGlobalSettings::timeTrackerDir(); |
119 | //qDebug("%s ", dir.latin1()); | 120 | //qDebug("%s ", dir.latin1()); |
120 | QString file = "%1%2%3-%4%5%6-"; | 121 | QString file = "%1%2%3-%4%5%6-"; |
121 | 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 ); | 122 | 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 ); |
122 | file.replace ( QRegExp (" "), "0" ); | 123 | file.replace ( QRegExp (" "), "0" ); |
123 | file += uid(); | 124 | file += uid(); |
124 | //qDebug("File %s ",file.latin1() ); | 125 | //qDebug("File %s ",file.latin1() ); |
125 | CalendarLocal cal; | 126 | CalendarLocal cal; |
126 | cal.setLocalTime(); | 127 | cal.setLocalTime(); |
127 | Todo * to = (Todo*) clone(); | 128 | Todo * to = (Todo*) clone(); |
128 | to->setFloats( false ); | 129 | to->setFloats( false ); |
129 | to->setDtStart( mRunStart ); | 130 | to->setDtStart( mRunStart ); |
130 | to->setHasStartDate( true ); | 131 | to->setHasStartDate( true ); |
131 | to->setDtDue( mRunEnd ); | 132 | to->setDtDue( mRunEnd ); |
132 | to->setHasDueDate( true ); | 133 | to->setHasDueDate( true ); |
133 | to->setUid( file ); | 134 | to->setUid( file ); |
134 | if ( !comment.isEmpty() ) { | 135 | if ( !comment.isEmpty() ) { |
135 | QString des = to->description(); | 136 | QString des = to->description(); |
136 | if ( des.isEmpty () ) | 137 | if ( des.isEmpty () ) |
137 | to->setDescription( "TT-Note: " + comment ); | 138 | to->setDescription( "TT-Note: " + comment ); |
138 | else | 139 | else |
139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 140 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
140 | } | 141 | } |
141 | cal.addIncidence( to ); | 142 | cal.addIncidence( to ); |
142 | ICalFormat format; | 143 | ICalFormat format( false ); |
143 | file = dir +"/" +file +".ics"; | 144 | file = dir +"/" +file +".ics"; |
144 | format.save( &cal, file ); | 145 | format.save( &cal, file ); |
145 | saveParents(); | 146 | saveParents(); |
146 | 147 | ||
147 | } | 148 | } |
148 | void Todo::saveParents() | 149 | void Todo::saveParents() |
149 | { | 150 | { |
150 | if (!relatedTo() ) | 151 | if (!relatedTo() ) |
151 | return; | 152 | return; |
152 | Incidence * inc = relatedTo(); | 153 | Incidence * inc = relatedTo(); |
153 | if ( inc->typeID() != todoID ) | 154 | if ( inc->typeID() != todoID ) |
154 | return; | 155 | return; |
155 | Todo* to = (Todo*)inc; | 156 | Todo* to = (Todo*)inc; |
156 | bool saveTodo = false; | 157 | bool saveTodo = false; |
157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 158 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
158 | QFileInfo fi ( file ); | 159 | QFileInfo fi ( file ); |
159 | if ( fi.exists() ) { | 160 | if ( fi.exists() ) { |
160 | if ( fi.lastModified () < to->lastModified ()) | 161 | if ( fi.lastModified () < to->lastModified ()) |
161 | saveTodo = true; | 162 | saveTodo = true; |
162 | } else { | 163 | } else { |
163 | saveTodo = true; | 164 | saveTodo = true; |
164 | } | 165 | } |
165 | if ( saveTodo ) { | 166 | if ( saveTodo ) { |
166 | CalendarLocal cal; | 167 | CalendarLocal cal; |
167 | cal.setLocalTime(); | 168 | cal.setLocalTime(); |
168 | Todo * par = (Todo *) to->clone(); | 169 | Todo * par = (Todo *) to->clone(); |
169 | cal.addIncidence( par ); | 170 | cal.addIncidence( par ); |
170 | ICalFormat format; | 171 | ICalFormat format( false ); |
171 | format.save( &cal, file ); | 172 | format.save( &cal, file ); |
172 | } | 173 | } |
173 | to->saveParents(); | 174 | to->saveParents(); |
174 | } | 175 | } |
175 | 176 | ||
176 | int Todo::runTime() | 177 | int Todo::runTime() |
177 | { | 178 | { |
178 | if ( !mRunning ) | 179 | if ( !mRunning ) |
179 | return 0; | 180 | return 0; |
180 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 181 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
181 | } | 182 | } |
182 | bool Todo::hasRunningSub() | 183 | bool Todo::hasRunningSub() |
183 | { | 184 | { |
184 | if ( mRunning ) | 185 | if ( mRunning ) |
185 | return true; | 186 | return true; |
186 | Incidence *aTodo; | 187 | Incidence *aTodo; |
187 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 188 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
188 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 189 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
189 | return true; | 190 | return true; |
190 | } | 191 | } |
191 | return false; | 192 | return false; |
192 | } | 193 | } |
193 | Incidence *Todo::clone() | 194 | Incidence *Todo::clone() |
194 | { | 195 | { |
195 | return new Todo(*this); | 196 | return new Todo(*this); |
196 | } | 197 | } |
197 | 198 | ||
198 | bool Todo::contains ( Todo* from ) | 199 | bool Todo::contains ( Todo* from ) |
199 | { | 200 | { |
200 | 201 | ||
201 | if ( !from->summary().isEmpty() ) | 202 | if ( !from->summary().isEmpty() ) |
202 | if ( !summary().startsWith( from->summary() )) | 203 | if ( !summary().startsWith( from->summary() )) |