summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoviewitem.cpp2
-rw-r--r--libkcal/todo.cpp16
-rw-r--r--microkde/kglobalsettings.cpp10
-rw-r--r--microkde/kglobalsettings.h1
4 files changed, 27 insertions, 2 deletions
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 66f8d06..8cb6b83 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,516 +1,516 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23#include <kglobal.h> 23#include <kglobal.h>
24 24
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include "kotodoviewitem.h" 26#include "kotodoviewitem.h"
27#include "kotodoview.h" 27#include "kotodoview.h"
28#include "koprefs.h" 28#include "koprefs.h"
29 29
30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
32{ 32{
33 construct(); 33 construct();
34} 34}
35 35
36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
38{ 38{
39 construct(); 39 construct();
40} 40}
41 41
42QString KOTodoViewItem::key(int column,bool) const 42QString KOTodoViewItem::key(int column,bool) const
43{ 43{
44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
45 if (it == mKeyMap.end()) { 45 if (it == mKeyMap.end()) {
46 return text(column).lower(); 46 return text(column).lower();
47 } else { 47 } else {
48 return *it; 48 return *it;
49 } 49 }
50} 50}
51 51
52void KOTodoViewItem:: setup() 52void KOTodoViewItem:: setup()
53{ 53{
54 54
55 int h = 20; 55 int h = 20;
56 if ( listView () ) { 56 if ( listView () ) {
57 QFontMetrics fm ( listView ()->font () ); 57 QFontMetrics fm ( listView ()->font () );
58 h = fm.height(); 58 h = fm.height();
59 } 59 }
60 setHeight( h ); 60 setHeight( h );
61 61
62} 62}
63void KOTodoViewItem::setSortKey(int column,const QString &key) 63void KOTodoViewItem::setSortKey(int column,const QString &key)
64{ 64{
65 mKeyMap.insert(column,key); 65 mKeyMap.insert(column,key);
66} 66}
67 67
68#if QT_VERSION >= 0x030000 68#if QT_VERSION >= 0x030000
69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
70 int y,int h) 70 int y,int h)
71{ 71{
72 QListViewItem::paintBranches(p,cg,w,y,h); 72 QListViewItem::paintBranches(p,cg,w,y,h);
73} 73}
74#else 74#else
75#endif 75#endif
76 76
77void KOTodoViewItem::construct() 77void KOTodoViewItem::construct()
78{ 78{
79 // qDebug("KOTodoViewItem::construct() "); 79 // qDebug("KOTodoViewItem::construct() ");
80 m_init = true; 80 m_init = true;
81 QString keyd = "=="; 81 QString keyd = "==";
82 QString keyt = "=="; 82 QString keyt = "==";
83 QString skeyd = "=="; 83 QString skeyd = "==";
84 QString skeyt = "=="; 84 QString skeyt = "==";
85 85
86 setOn(mTodo->isCompleted()); 86 setOn(mTodo->isCompleted());
87 setText(0,mTodo->summary()); 87 setText(0,mTodo->summary());
88 setText(1,QString::number(mTodo->priority())); 88 setText(1,QString::number(mTodo->priority()));
89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
90 if (mTodo->percentComplete()<100) { 90 if (mTodo->percentComplete()<100) {
91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
92 else setSortKey(2,QString::number(mTodo->percentComplete())); 92 else setSortKey(2,QString::number(mTodo->percentComplete()));
93 } 93 }
94 else { 94 else {
95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
96 else setSortKey(2,QString::number(99)); 96 else setSortKey(2,QString::number(99));
97 } 97 }
98 if (mTodo->hasDueDate()) { 98 if (mTodo->hasDueDate()) {
99 setText(3, mTodo->dtDueDateStr()); 99 setText(3, mTodo->dtDueDateStr());
100 QDate d = mTodo->dtDue().date(); 100 QDate d = mTodo->dtDue().date();
101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
102 // setSortKey(3,keyd); 102 // setSortKey(3,keyd);
103 if (mTodo->doesFloat()) { 103 if (mTodo->doesFloat()) {
104 setText(4,""); 104 setText(4,"");
105 } 105 }
106 else { 106 else {
107 setText(4,mTodo->dtDueTimeStr()); 107 setText(4,mTodo->dtDueTimeStr());
108 QTime t = mTodo->dtDue().time(); 108 QTime t = mTodo->dtDue().time();
109 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 109 keyt.sprintf("%02d%02d",t.hour(),t.minute());
110 //setSortKey(4,keyt); 110 //setSortKey(4,keyt);
111 } 111 }
112 } else { 112 } else {
113 setText(3,""); 113 setText(3,"");
114 setText(4,""); 114 setText(4,"");
115 } 115 }
116 setSortKey(3,keyd); 116 setSortKey(3,keyd);
117 setSortKey(4,keyt); 117 setSortKey(4,keyt);
118 118
119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
121 121
122 122
123 123
124 keyd = ""; 124 keyd = "";
125 keyt = ""; 125 keyt = "";
126 126
127 if (mTodo->isRunning() ) { 127 if (mTodo->isRunning() ) {
128 QDate d = mTodo->runStart().date(); 128 QDate d = mTodo->runStart().date();
129 QTime t = mTodo->runStart().time(); 129 QTime t = mTodo->runStart().time();
130 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 130 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
132 keyd = KGlobal::locale()->formatDate( d ); 132 keyd = KGlobal::locale()->formatDate( d , true);
133 keyt = KGlobal::locale()->formatTime( t ); 133 keyt = KGlobal::locale()->formatTime( t );
134 134
135 } else { 135 } else {
136 136
137 if (mTodo->hasStartDate()) { 137 if (mTodo->hasStartDate()) {
138 keyd = mTodo->dtStartDateStr(); 138 keyd = mTodo->dtStartDateStr();
139 QDate d = mTodo->dtStart().date(); 139 QDate d = mTodo->dtStart().date();
140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
141 141
142 if ( !mTodo->doesFloat()) { 142 if ( !mTodo->doesFloat()) {
143 keyt = mTodo->dtStartTimeStr(); 143 keyt = mTodo->dtStartTimeStr();
144 QTime t = mTodo->dtStart().time(); 144 QTime t = mTodo->dtStart().time();
145 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 145 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
146 146
147 } 147 }
148 148
149 } 149 }
150 } 150 }
151 setText(5,keyd); 151 setText(5,keyd);
152 setText(6,keyt); 152 setText(6,keyt);
153 setSortKey(5,skeyd); 153 setSortKey(5,skeyd);
154 setSortKey(6,skeyt); 154 setSortKey(6,skeyt);
155 155
156 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 156 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
157 setText(8,mTodo->categoriesStr()); 157 setText(8,mTodo->categoriesStr());
158 158
159#if 0 159#if 0
160 // Find sort id in description. It's the text behind the last '#' character 160 // Find sort id in description. It's the text behind the last '#' character
161 // found in the description. White spaces are removed from beginning and end 161 // found in the description. White spaces are removed from beginning and end
162 // of sort id. 162 // of sort id.
163 int pos = mTodo->description().findRev('#'); 163 int pos = mTodo->description().findRev('#');
164 if (pos < 0) { 164 if (pos < 0) {
165 setText(6,""); 165 setText(6,"");
166 } else { 166 } else {
167 QString str = mTodo->description().mid(pos+1); 167 QString str = mTodo->description().mid(pos+1);
168 str.stripWhiteSpace(); 168 str.stripWhiteSpace();
169 setText(6,str); 169 setText(6,str);
170 } 170 }
171#endif 171#endif
172 172
173 m_known = false; 173 m_known = false;
174 m_init = false; 174 m_init = false;
175 175
176 setMyPixmap(); 176 setMyPixmap();
177 177
178} 178}
179void KOTodoViewItem::setMyPixmap() 179void KOTodoViewItem::setMyPixmap()
180{ 180{
181 int size = 5; 181 int size = 5;
182 QPixmap pixi = QPixmap( 1, 1 ); 182 QPixmap pixi = QPixmap( 1, 1 );
183 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 183 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
184// pixi = SmallIcon("redcross16"); 184// pixi = SmallIcon("redcross16");
185// } else { 185// } else {
186 QPainter p; 186 QPainter p;
187 187
188 int pixSize = 0; 188 int pixSize = 0;
189 QPixmap pPix = QPixmap( size, size ); 189 QPixmap pPix = QPixmap( size, size );
190 if ( mTodo->description().length() > 0 ) { 190 if ( mTodo->description().length() > 0 ) {
191 pixi.resize(size, pixSize+size); 191 pixi.resize(size, pixSize+size);
192 pPix.fill( Qt::darkGreen ); 192 pPix.fill( Qt::darkGreen );
193 p.begin( &pixi ); 193 p.begin( &pixi );
194 p. drawPixmap ( 0, pixSize, pPix); 194 p. drawPixmap ( 0, pixSize, pPix);
195 p.end(); 195 p.end();
196 pixSize += size; 196 pixSize += size;
197 } 197 }
198 if ( mTodo->isAlarmEnabled() ) { 198 if ( mTodo->isAlarmEnabled() ) {
199 pixi.resize(size, pixSize+size); 199 pixi.resize(size, pixSize+size);
200 pPix.fill( Qt::red ); 200 pPix.fill( Qt::red );
201 p.begin( &pixi ); 201 p.begin( &pixi );
202 p. drawPixmap ( 0, pixSize, pPix); 202 p. drawPixmap ( 0, pixSize, pPix);
203 p.end(); 203 p.end();
204 pixSize += size; 204 pixSize += size;
205 } 205 }
206 if ( mTodo->doesRecur() ) { 206 if ( mTodo->doesRecur() ) {
207 pixi.resize(size, pixSize+size); 207 pixi.resize(size, pixSize+size);
208 pPix.fill( Qt::blue ); 208 pPix.fill( Qt::blue );
209 p.begin( &pixi ); 209 p.begin( &pixi );
210 p. drawPixmap ( 0, pixSize, pPix); 210 p. drawPixmap ( 0, pixSize, pPix);
211 p.end(); 211 p.end();
212 pixSize += size; 212 pixSize += size;
213 } 213 }
214 // } 214 // }
215 if ( pixi.width() > 1 ) { 215 if ( pixi.width() > 1 ) {
216 setPixmap ( 0,pixi ) ; 216 setPixmap ( 0,pixi ) ;
217 } else { 217 } else {
218 setPixmap ( 0,QPixmap() ) ; 218 setPixmap ( 0,QPixmap() ) ;
219 } 219 }
220} 220}
221void KOTodoViewItem::stateChange(bool state) 221void KOTodoViewItem::stateChange(bool state)
222{ 222{
223 // qDebug("KOTodoViewItem::stateChange %d ", state); 223 // qDebug("KOTodoViewItem::stateChange %d ", state);
224 // do not change setting on startup 224 // do not change setting on startup
225 if ( m_init ) return; 225 if ( m_init ) return;
226 if (isOn()!=state) { 226 if (isOn()!=state) {
227 setOn(state); 227 setOn(state);
228 //qDebug("SETON "); 228 //qDebug("SETON ");
229 return; 229 return;
230 } 230 }
231 if ( mTodo->isCompleted() == state ) { 231 if ( mTodo->isCompleted() == state ) {
232 //qDebug("STATECHANGE:nothing to do "); 232 //qDebug("STATECHANGE:nothing to do ");
233 return; 233 return;
234 } 234 }
235 QString keyd = "=="; 235 QString keyd = "==";
236 QString keyt = "=="; 236 QString keyt = "==";
237 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 237 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
238 if ( mTodo->doesRecur() ){ 238 if ( mTodo->doesRecur() ){
239 QDateTime start = mTodo->dtStart(); 239 QDateTime start = mTodo->dtStart();
240 mTodo->setCompleted(state); 240 mTodo->setCompleted(state);
241 if ( start != mTodo->dtStart() ) { 241 if ( start != mTodo->dtStart() ) {
242 if ( state && !mTodo->isCompleted() ) { 242 if ( state && !mTodo->isCompleted() ) {
243 setOn( false ); 243 setOn( false );
244 state = false; 244 state = false;
245 } 245 }
246 } 246 }
247 } else 247 } else
248 mTodo->setCompleted(state); 248 mTodo->setCompleted(state);
249 249
250 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 250 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
251 251
252 if (mTodo->hasDueDate()) { 252 if (mTodo->hasDueDate()) {
253 setText(3, mTodo->dtDueDateStr()); 253 setText(3, mTodo->dtDueDateStr());
254 QDate d = mTodo->dtDue().date(); 254 QDate d = mTodo->dtDue().date();
255 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 255 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
256 setSortKey(3,keyd); 256 setSortKey(3,keyd);
257 if (mTodo->doesFloat()) { 257 if (mTodo->doesFloat()) {
258 setText(4,""); 258 setText(4,"");
259 } 259 }
260 else { 260 else {
261 setText(4,mTodo->dtDueTimeStr()); 261 setText(4,mTodo->dtDueTimeStr());
262 QTime t = mTodo->dtDue().time(); 262 QTime t = mTodo->dtDue().time();
263 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 263 keyt.sprintf("%02d%02d",t.hour(),t.minute());
264 setSortKey(4,keyt); 264 setSortKey(4,keyt);
265 } 265 }
266 } 266 }
267 if (mTodo->hasStartDate()) { 267 if (mTodo->hasStartDate()) {
268 QString skeyt = "=="; 268 QString skeyt = "==";
269 QString skeyd = "=="; 269 QString skeyd = "==";
270 setText(5, mTodo->dtStartDateStr()); 270 setText(5, mTodo->dtStartDateStr());
271 QDate d = mTodo->dtStart().date(); 271 QDate d = mTodo->dtStart().date();
272 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 272 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
273 273
274 if (mTodo->doesFloat()) { 274 if (mTodo->doesFloat()) {
275 setText(6,""); 275 setText(6,"");
276 } 276 }
277 else { 277 else {
278 setText(6,mTodo->dtStartTimeStr()); 278 setText(6,mTodo->dtStartTimeStr());
279 QTime t = mTodo->dtStart().time(); 279 QTime t = mTodo->dtStart().time();
280 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 280 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
281 281
282 } 282 }
283 setSortKey(5,skeyd); 283 setSortKey(5,skeyd);
284 setSortKey(6,skeyt); 284 setSortKey(6,skeyt);
285 } 285 }
286 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 286 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
287 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 287 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
288 288
289 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 289 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
290 if (mTodo->percentComplete()<100) { 290 if (mTodo->percentComplete()<100) {
291 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 291 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
292 else setSortKey(2,QString::number(mTodo->percentComplete())); 292 else setSortKey(2,QString::number(mTodo->percentComplete()));
293 } 293 }
294 else { 294 else {
295 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 295 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
296 else setSortKey(2,QString::number(99)); 296 else setSortKey(2,QString::number(99));
297 } 297 }
298 if ( state ) { 298 if ( state ) {
299 QListViewItem * myChild = firstChild(); 299 QListViewItem * myChild = firstChild();
300 KOTodoViewItem *item; 300 KOTodoViewItem *item;
301 while( myChild ) { 301 while( myChild ) {
302 //qDebug("stateCH "); 302 //qDebug("stateCH ");
303 item = static_cast<KOTodoViewItem*>(myChild); 303 item = static_cast<KOTodoViewItem*>(myChild);
304 item->stateChange(state); 304 item->stateChange(state);
305 myChild = myChild->nextSibling(); 305 myChild = myChild->nextSibling();
306 } 306 }
307 } else { 307 } else {
308 QListViewItem * myChild = parent(); 308 QListViewItem * myChild = parent();
309 if ( myChild ) 309 if ( myChild )
310 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 310 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
311 } 311 }
312 mTodoView->modified(true); 312 mTodoView->modified(true);
313 setMyPixmap(); 313 setMyPixmap();
314 mTodoView->setTodoModified( mTodo ); 314 mTodoView->setTodoModified( mTodo );
315} 315}
316 316
317bool KOTodoViewItem::isAlternate() 317bool KOTodoViewItem::isAlternate()
318{ 318{
319 319
320 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 320 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
321 if (lv && lv->alternateBackground().isValid()) 321 if (lv && lv->alternateBackground().isValid())
322 { 322 {
323 KOTodoViewItem *above = 0; 323 KOTodoViewItem *above = 0;
324 above = static_cast<KOTodoViewItem *>(itemAbove()); 324 above = static_cast<KOTodoViewItem *>(itemAbove());
325 m_known = above ? above->m_known : true; 325 m_known = above ? above->m_known : true;
326 if (m_known) 326 if (m_known)
327 { 327 {
328 m_odd = above ? !above->m_odd : false; 328 m_odd = above ? !above->m_odd : false;
329 } 329 }
330 else 330 else
331 { 331 {
332 KOTodoViewItem *item; 332 KOTodoViewItem *item;
333 bool previous = true; 333 bool previous = true;
334 if (QListViewItem::parent()) 334 if (QListViewItem::parent())
335 { 335 {
336 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 336 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
337 if (item) 337 if (item)
338 previous = item->m_odd; 338 previous = item->m_odd;
339 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 339 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
340 } 340 }
341 else 341 else
342 { 342 {
343 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 343 item = static_cast<KOTodoViewItem *>(lv->firstChild());
344 } 344 }
345 345
346 while(item) 346 while(item)
347 { 347 {
348 item->m_odd = previous = !previous; 348 item->m_odd = previous = !previous;
349 item->m_known = true; 349 item->m_known = true;
350 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 350 item = static_cast<KOTodoViewItem *>(item->nextSibling());
351 } 351 }
352 } 352 }
353 return m_odd; 353 return m_odd;
354 } 354 }
355 return false; 355 return false;
356} 356}
357 357
358void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 358void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
359{ 359{
360 QColorGroup _cg = cg; 360 QColorGroup _cg = cg;
361 QColorGroup::ColorRole role; 361 QColorGroup::ColorRole role;
362 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 362 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
363 role = QColorGroup::Text; 363 role = QColorGroup::Text;
364 else 364 else
365 role = QColorGroup::Base; 365 role = QColorGroup::Base;
366 //#ifndef KORG_NOLVALTERNATION 366 //#ifndef KORG_NOLVALTERNATION
367 if (isAlternate()) 367 if (isAlternate())
368 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 368 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
369 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 369 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
370 QColor colorToSet; 370 QColor colorToSet;
371 if ( setColor ) { 371 if ( setColor ) {
372 QStringList categories = mTodo->categories(); 372 QStringList categories = mTodo->categories();
373 QString cat = categories.first(); 373 QString cat = categories.first();
374 if ( !cat.isEmpty()) { 374 if ( !cat.isEmpty()) {
375 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 375 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
376 } else 376 } else
377 setColor = false; 377 setColor = false;
378 } 378 }
379 bool openMode = !isOpen(); 379 bool openMode = !isOpen();
380 // maybe we are in flat-display-mode 380 // maybe we are in flat-display-mode
381 if ( !firstChild() ) 381 if ( !firstChild() )
382 openMode = false; 382 openMode = false;
383 bool colorRunning = mTodo->isRunning(); 383 bool colorRunning = mTodo->isRunning();
384 if ( ! colorRunning && openMode ) 384 if ( ! colorRunning && openMode )
385 colorRunning = mTodo->hasRunningSub(); 385 colorRunning = mTodo->hasRunningSub();
386 if ( colorRunning ) { 386 if ( colorRunning ) {
387 setColor = true; 387 setColor = true;
388 colorToSet = KOPrefs::instance()->mTodoRunColor; 388 colorToSet = KOPrefs::instance()->mTodoRunColor;
389 } else { 389 } else {
390 int odue = mTodo->hasDueSubTodo( openMode ); 390 int odue = mTodo->hasDueSubTodo( openMode );
391 if (odue == 2) { 391 if (odue == 2) {
392 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 392 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
393 setColor = true; 393 setColor = true;
394 } else if ( odue == 1 ) { 394 } else if ( odue == 1 ) {
395 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 395 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
396 setColor = true; 396 setColor = true;
397 } 397 }
398 } 398 }
399 399
400 400
401 if ( setColor ) { 401 if ( setColor ) {
402 _cg.setColor(role,colorToSet ); 402 _cg.setColor(role,colorToSet );
403 if ( role == QColorGroup::Base) { 403 if ( role == QColorGroup::Base) {
404 int rgb = colorToSet.red(); 404 int rgb = colorToSet.red();
405 rgb += colorToSet.blue()/2; 405 rgb += colorToSet.blue()/2;
406 rgb += colorToSet.green(); 406 rgb += colorToSet.green();
407 if ( rgb < 200 ) 407 if ( rgb < 200 )
408 _cg.setColor(QColorGroup::Text,Qt::white ); 408 _cg.setColor(QColorGroup::Text,Qt::white );
409 } 409 }
410 } 410 }
411 //#endif 411 //#endif
412 if ( column > 0 ){ 412 if ( column > 0 ){
413 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 413 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
414 p->save(); 414 p->save();
415 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 415 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
416 416
417 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 417 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
418 // p->setPen(Qt::black ); //border 418 // p->setPen(Qt::black ); //border
419 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 419 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
420 QColor fc = KOPrefs::instance()->mHighlightColor; 420 QColor fc = KOPrefs::instance()->mHighlightColor;
421 if ( mTodo->percentComplete() == 100 ) 421 if ( mTodo->percentComplete() == 100 )
422 fc = darkGreen; 422 fc = darkGreen;
423 p->drawRect( 2, 2, width-4, height()-4); 423 p->drawRect( 2, 2, width-4, height()-4);
424 p->fillRect( 3, 3, progress, height()-6, 424 p->fillRect( 3, 3, progress, height()-6,
425 fc ); 425 fc );
426 p->restore(); 426 p->restore();
427 } else { 427 } else {
428 QCheckListItem::paintCell(p, _cg, column, width, alignment); 428 QCheckListItem::paintCell(p, _cg, column, width, alignment);
429 } 429 }
430 return; 430 return;
431 } 431 }
432 432
433 int align = alignment; 433 int align = alignment;
434 434
435 if ( !p ) 435 if ( !p )
436 return; 436 return;
437 437
438 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 438 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
439 439
440 QListView *lv = listView(); 440 QListView *lv = listView();
441 if ( !lv ) 441 if ( !lv )
442 return; 442 return;
443 int marg = 2;//lv->itemMargin(); 443 int marg = 2;//lv->itemMargin();
444 int r = 0; 444 int r = 0;
445 QCheckListItem::Type myType = QCheckListItem::CheckBox; 445 QCheckListItem::Type myType = QCheckListItem::CheckBox;
446 int BoxSize = 20; 446 int BoxSize = 20;
447 int boxOffset = 2; 447 int boxOffset = 2;
448 int xOffset = 2; 448 int xOffset = 2;
449 if (qApp->desktop()->width() < 300 ) { 449 if (qApp->desktop()->width() < 300 ) {
450 BoxSize = 14; 450 BoxSize = 14;
451 boxOffset = -1; 451 boxOffset = -1;
452 xOffset = 1; 452 xOffset = 1;
453 // marg = 0; 453 // marg = 0;
454 } 454 }
455 if ( height() < BoxSize ) { 455 if ( height() < BoxSize ) {
456 boxOffset = boxOffset - ((BoxSize - height())/2) ; 456 boxOffset = boxOffset - ((BoxSize - height())/2) ;
457 // qDebug("boxOffset %d height %d", boxOffset, height() ); 457 // qDebug("boxOffset %d height %d", boxOffset, height() );
458 BoxSize = height(); 458 BoxSize = height();
459 459
460 } 460 }
461 //bool winStyle = lv->style() == WindowsStyle; 461 //bool winStyle = lv->style() == WindowsStyle;
462 462
463 int lineStart = 5; 463 int lineStart = 5;
464 if ( myType == Controller ) { 464 if ( myType == Controller ) {
465 if ( !pixmap( 0 ) ) 465 if ( !pixmap( 0 ) )
466 r += BoxSize + 4; 466 r += BoxSize + 4;
467 } else { 467 } else {
468 ASSERT( lv ); //### 468 ASSERT( lv ); //###
469 //QFontMetrics fm( lv->font() ); 469 //QFontMetrics fm( lv->font() );
470 //int d = fm.height(); 470 //int d = fm.height();
471 int x = 0; 471 int x = 0;
472 int y = (height() - BoxSize) / 2; 472 int y = (height() - BoxSize) / 2;
473 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 473 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
474 if ( myType == CheckBox ) { 474 if ( myType == CheckBox ) {
475 if ( isEnabled() ) 475 if ( isEnabled() )
476 p->setPen( QPen( _cg.text(), 1 ) ); 476 p->setPen( QPen( _cg.text(), 1 ) );
477 else 477 else
478 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 478 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
479 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 479 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
480 lineStart = x+marg; 480 lineStart = x+marg;
481 ///////////////////// 481 /////////////////////
482 x++; 482 x++;
483 y++; 483 y++;
484 if ( isOn() ) { 484 if ( isOn() ) {
485 QPointArray a( 7*2 ); 485 QPointArray a( 7*2 );
486 int i, xx, yy; 486 int i, xx, yy;
487 xx = x+xOffset+marg+(boxOffset/2); 487 xx = x+xOffset+marg+(boxOffset/2);
488 yy = y+5+boxOffset; 488 yy = y+5+boxOffset;
489 for ( i=0; i<3; i++ ) { 489 for ( i=0; i<3; i++ ) {
490 a.setPoint( 2*i, xx, yy ); 490 a.setPoint( 2*i, xx, yy );
491 a.setPoint( 2*i+1, xx, yy+2 ); 491 a.setPoint( 2*i+1, xx, yy+2 );
492 // qDebug(" "); 492 // qDebug(" ");
493 xx++; yy++; 493 xx++; yy++;
494 } 494 }
495 yy -= 2; 495 yy -= 2;
496 for ( i=3; i<7; i++ ) { 496 for ( i=3; i<7; i++ ) {
497 a.setPoint( 2*i, xx, yy ); 497 a.setPoint( 2*i, xx, yy );
498 a.setPoint( 2*i+1, xx, yy+2 ); 498 a.setPoint( 2*i+1, xx, yy+2 );
499 xx++; yy--; 499 xx++; yy--;
500 } 500 }
501 p->setPen( darkGreen ); 501 p->setPen( darkGreen );
502 p->drawLineSegments( a ); 502 p->drawLineSegments( a );
503 } 503 }
504 //////////////////////// 504 ////////////////////////
505 } 505 }
506 r += BoxSize + 4; 506 r += BoxSize + 4;
507 } 507 }
508 508
509 p->translate( r, 0 ); 509 p->translate( r, 0 );
510 p->setPen( QPen( _cg.text() ) ); 510 p->setPen( QPen( _cg.text() ) );
511 QListViewItem::paintCell( p, _cg, column, width - r, align ); 511 QListViewItem::paintCell( p, _cg, column, width - r, align );
512 if ( mTodo->cancelled () ) { 512 if ( mTodo->cancelled () ) {
513 p->setPen( black ); 513 p->setPen( black );
514 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 514 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
515 int wid = br.width() +lineStart; 515 int wid = br.width() +lineStart;
516 if ( wid > width-3 ) 516 if ( wid > width-3 )
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7dee4cd..c008fe1 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,462 +1,476 @@
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
27using namespace KCal; 29using namespace KCal;
28 30
29Todo::Todo(): Incidence() 31Todo::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
42Todo::Todo(const Todo &t) : Incidence(t) 44Todo::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
53Todo::~Todo() 55Todo::~Todo()
54{ 56{
55 setRunning( false ); 57 setRunning( false );
56} 58}
57 59
58void Todo::setRunning( bool run ) 60void 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
76void Todo::saveRunningInfoToFile() 78void 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
81int Todo::runTime() 95int 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}
87bool Todo::hasRunningSub() 101bool 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}
98Incidence *Todo::clone() 112Incidence *Todo::clone()
99{ 113{
100 return new Todo(*this); 114 return new Todo(*this);
101} 115}
102 116
103bool Todo::contains ( Todo* from ) 117bool 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}
162bool KCal::operator==( const Todo& t1, const Todo& t2 ) 176bool 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
199void Todo::setDtDue(const QDateTime &dtDue) 213void 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()) {
207 alarm->setTime(alarm->time().addSecs(diffsecs)); 221 alarm->setTime(alarm->time().addSecs(diffsecs));
208 } 222 }
209 }*/ 223 }*/
210 mDtDue = getEvenTime(dtDue); 224 mDtDue = getEvenTime(dtDue);
211 225
212 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 226 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
213 227
214 /*const QPtrList<Alarm>& alarms = alarms(); 228 /*const QPtrList<Alarm>& alarms = alarms();
215 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 229 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
216 alarm->setAlarmStart(mDtDue);*/ 230 alarm->setAlarmStart(mDtDue);*/
217 231
218 updated(); 232 updated();
219} 233}
220 234
221QDateTime Todo::dtDue() const 235QDateTime Todo::dtDue() const
222{ 236{
223 return mDtDue; 237 return mDtDue;
224} 238}
225 239
226QString Todo::dtDueTimeStr() const 240QString Todo::dtDueTimeStr() const
227{ 241{
228 return KGlobal::locale()->formatTime(mDtDue.time()); 242 return KGlobal::locale()->formatTime(mDtDue.time());
229} 243}
230 244
231QString Todo::dtDueDateStr(bool shortfmt) const 245QString Todo::dtDueDateStr(bool shortfmt) const
232{ 246{
233 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 247 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
234} 248}
235 249
236QString Todo::dtDueStr(bool shortfmt) const 250QString Todo::dtDueStr(bool shortfmt) const
237{ 251{
238 if ( doesFloat() ) 252 if ( doesFloat() )
239 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 253 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
240 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 254 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
241} 255}
242// retval 0 : no found 256// retval 0 : no found
243// 1 : due for date found 257// 1 : due for date found
244// 2 : overdue for date found 258// 2 : overdue for date found
245int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 259int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
246{ 260{
247 int retval = 0; 261 int retval = 0;
248 if ( isCompleted() ) 262 if ( isCompleted() )
249 return 0; 263 return 0;
250 if ( hasDueDate() ) { 264 if ( hasDueDate() ) {
251 if ( dtDue().date() < date ) 265 if ( dtDue().date() < date )
252 return 2; 266 return 2;
253 // we do not return, because we may find an overdue sub todo 267 // we do not return, because we may find an overdue sub todo
254 if ( dtDue().date() == date ) 268 if ( dtDue().date() == date )
255 retval = 1; 269 retval = 1;
256 } 270 }
257 if ( checkSubtodos ) { 271 if ( checkSubtodos ) {
258 Incidence *aTodo; 272 Incidence *aTodo;
259 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 273 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
260 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 274 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
261 if ( ret == 2 ) 275 if ( ret == 2 )
262 return 2; 276 return 2;
263 if ( ret == 1) 277 if ( ret == 1)
264 retval = 1; 278 retval = 1;
265 } 279 }
266 } 280 }
267 return retval; 281 return retval;
268} 282}
269int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 283int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
270{ 284{
271 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 285 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
272} 286}
273bool Todo::hasDueDate() const 287bool Todo::hasDueDate() const
274{ 288{
275 return mHasDueDate; 289 return mHasDueDate;
276} 290}
277 291
278void Todo::setHasDueDate(bool f) 292void Todo::setHasDueDate(bool f)
279{ 293{
280 if (mReadOnly) return; 294 if (mReadOnly) return;
281 mHasDueDate = f; 295 mHasDueDate = f;
282 updated(); 296 updated();
283} 297}
284 298
285 299
286#if 0 300#if 0
287void Todo::setStatus(const QString &statStr) 301void Todo::setStatus(const QString &statStr)
288{ 302{
289 if (mReadOnly) return; 303 if (mReadOnly) return;
290 QString ss(statStr.upper()); 304 QString ss(statStr.upper());
291 305
292 if (ss == "X-ACTION") 306 if (ss == "X-ACTION")
293 mStatus = NEEDS_ACTION; 307 mStatus = NEEDS_ACTION;
294 else if (ss == "NEEDS ACTION") 308 else if (ss == "NEEDS ACTION")
295 mStatus = NEEDS_ACTION; 309 mStatus = NEEDS_ACTION;
296 else if (ss == "ACCEPTED") 310 else if (ss == "ACCEPTED")
297 mStatus = ACCEPTED; 311 mStatus = ACCEPTED;
298 else if (ss == "SENT") 312 else if (ss == "SENT")
299 mStatus = SENT; 313 mStatus = SENT;
300 else if (ss == "TENTATIVE") 314 else if (ss == "TENTATIVE")
301 mStatus = TENTATIVE; 315 mStatus = TENTATIVE;
302 else if (ss == "CONFIRMED") 316 else if (ss == "CONFIRMED")
303 mStatus = CONFIRMED; 317 mStatus = CONFIRMED;
304 else if (ss == "DECLINED") 318 else if (ss == "DECLINED")
305 mStatus = DECLINED; 319 mStatus = DECLINED;
306 else if (ss == "COMPLETED") 320 else if (ss == "COMPLETED")
307 mStatus = COMPLETED; 321 mStatus = COMPLETED;
308 else if (ss == "DELEGATED") 322 else if (ss == "DELEGATED")
309 mStatus = DELEGATED; 323 mStatus = DELEGATED;
310 324
311 updated(); 325 updated();
312} 326}
313 327
314void Todo::setStatus(int status) 328void Todo::setStatus(int status)
315{ 329{
316 if (mReadOnly) return; 330 if (mReadOnly) return;
317 mStatus = status; 331 mStatus = status;
318 updated(); 332 updated();
319} 333}
320 334
321int Todo::status() const 335int Todo::status() const
322{ 336{
323 return mStatus; 337 return mStatus;
324} 338}
325 339
326QString Todo::statusStr() const 340QString Todo::statusStr() const
327{ 341{
328 switch(mStatus) { 342 switch(mStatus) {
329 case NEEDS_ACTION: 343 case NEEDS_ACTION:
330 return QString("NEEDS ACTION"); 344 return QString("NEEDS ACTION");
331 break; 345 break;
332 case ACCEPTED: 346 case ACCEPTED:
333 return QString("ACCEPTED"); 347 return QString("ACCEPTED");
334 break; 348 break;
335 case SENT: 349 case SENT:
336 return QString("SENT"); 350 return QString("SENT");
337 break; 351 break;
338 case TENTATIVE: 352 case TENTATIVE:
339 return QString("TENTATIVE"); 353 return QString("TENTATIVE");
340 break; 354 break;
341 case CONFIRMED: 355 case CONFIRMED:
342 return QString("CONFIRMED"); 356 return QString("CONFIRMED");
343 break; 357 break;
344 case DECLINED: 358 case DECLINED:
345 return QString("DECLINED"); 359 return QString("DECLINED");
346 break; 360 break;
347 case COMPLETED: 361 case COMPLETED:
348 return QString("COMPLETED"); 362 return QString("COMPLETED");
349 break; 363 break;
350 case DELEGATED: 364 case DELEGATED:
351 return QString("DELEGATED"); 365 return QString("DELEGATED");
352 break; 366 break;
353 } 367 }
354 return QString(""); 368 return QString("");
355} 369}
356#endif 370#endif
357 371
358bool Todo::isCompleted() const 372bool Todo::isCompleted() const
359{ 373{
360 if (mPercentComplete == 100) { 374 if (mPercentComplete == 100) {
361 return true; 375 return true;
362 } 376 }
363 else return false; 377 else return false;
364} 378}
365 379
366void Todo::setCompleted(bool completed) 380void Todo::setCompleted(bool completed)
367{ 381{
368 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 382 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
369 if ( !setRecurDates() ) 383 if ( !setRecurDates() )
370 completed = false; 384 completed = false;
371 } 385 }
372 if (completed) mPercentComplete = 100; 386 if (completed) mPercentComplete = 100;
373 else { 387 else {
374 mPercentComplete = 0; 388 mPercentComplete = 0;
375 mHasCompletedDate = false; 389 mHasCompletedDate = false;
376 } 390 }
377 updated(); 391 updated();
378} 392}
379 393
380QDateTime Todo::completed() const 394QDateTime Todo::completed() const
381{ 395{
382 return mCompleted; 396 return mCompleted;
383} 397}
384 398
385QString Todo::completedStr( bool shortF ) const 399QString Todo::completedStr( bool shortF ) const
386{ 400{
387 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 401 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
388} 402}
389 403
390void Todo::setCompleted(const QDateTime &completed) 404void Todo::setCompleted(const QDateTime &completed)
391{ 405{
392 //qDebug("Todo::setCompleted "); 406 //qDebug("Todo::setCompleted ");
393 if ( mHasCompletedDate ) { 407 if ( mHasCompletedDate ) {
394 // qDebug("has completed data - return "); 408 // qDebug("has completed data - return ");
395 return; 409 return;
396 } 410 }
397 mHasCompletedDate = true; 411 mHasCompletedDate = true;
398 mPercentComplete = 100; 412 mPercentComplete = 100;
399 mCompleted = getEvenTime(completed); 413 mCompleted = getEvenTime(completed);
400 updated(); 414 updated();
401} 415}
402 416
403bool Todo::hasCompletedDate() const 417bool Todo::hasCompletedDate() const
404{ 418{
405 return mHasCompletedDate; 419 return mHasCompletedDate;
406} 420}
407 421
408int Todo::percentComplete() const 422int Todo::percentComplete() const
409{ 423{
410 return mPercentComplete; 424 return mPercentComplete;
411} 425}
412bool Todo::setRecurDates() 426bool Todo::setRecurDates()
413{ 427{
414 if ( !mHasRecurrenceID ) 428 if ( !mHasRecurrenceID )
415 return true; 429 return true;
416 int secs = mDtStart.secsTo( dtDue() ); 430 int secs = mDtStart.secsTo( dtDue() );
417 bool ok; 431 bool ok;
418 qDebug("T:setRecurDates() "); 432 qDebug("T:setRecurDates() ");
419 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 433 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
420 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 434 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
421 if ( ok ) { 435 if ( ok ) {
422 mRecurrenceID = next; 436 mRecurrenceID = next;
423 mDtStart = next; 437 mDtStart = next;
424 setDtDue( next.addSecs( secs ) ); 438 setDtDue( next.addSecs( secs ) );
425 if ( QDateTime::currentDateTime() > next) 439 if ( QDateTime::currentDateTime() > next)
426 return false; 440 return false;
427 } else { 441 } else {
428 setHasRecurrenceID( false ); 442 setHasRecurrenceID( false );
429 recurrence()->unsetRecurs(); 443 recurrence()->unsetRecurs();
430 } 444 }
431 return true; 445 return true;
432} 446}
433void Todo::setPercentComplete(int v) 447void Todo::setPercentComplete(int v)
434{ 448{
435 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 449 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
436 if ( !setRecurDates() ) 450 if ( !setRecurDates() )
437 v = 0; 451 v = 0;
438 } 452 }
439 mPercentComplete = v; 453 mPercentComplete = v;
440 if ( v != 100 ) 454 if ( v != 100 )
441 mHasCompletedDate = false; 455 mHasCompletedDate = false;
442 updated(); 456 updated();
443} 457}
444QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 458QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
445{ 459{
446 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 460 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
447 *ok = false; 461 *ok = false;
448 return QDateTime (); 462 return QDateTime ();
449 } 463 }
450 QDateTime incidenceStart; 464 QDateTime incidenceStart;
451 incidenceStart = dtDue(); 465 incidenceStart = dtDue();
452 bool enabled = false; 466 bool enabled = false;
453 Alarm* alarm; 467 Alarm* alarm;
454 int off = 0; 468 int off = 0;
455 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 469 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
456 // if ( QDateTime::currentDateTime() > incidenceStart ){ 470 // if ( QDateTime::currentDateTime() > incidenceStart ){
457// *ok = false; 471// *ok = false;
458// return incidenceStart; 472// return incidenceStart;
459// } 473// }
460 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 474 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
461 if (alarm->enabled()) { 475 if (alarm->enabled()) {
462 if ( alarm->hasTime () ) { 476 if ( alarm->hasTime () ) {
diff --git a/microkde/kglobalsettings.cpp b/microkde/kglobalsettings.cpp
index b837b23..e54b0d9 100644
--- a/microkde/kglobalsettings.cpp
+++ b/microkde/kglobalsettings.cpp
@@ -1,66 +1,76 @@
1#include "kglobalsettings.h" 1#include "kglobalsettings.h"
2#include "kconfig.h" 2#include "kconfig.h"
3#include "kglobal.h" 3#include "kglobal.h"
4#include "kconfigbase.h" 4#include "kconfigbase.h"
5 5
6#include <qapplication.h> 6#include <qapplication.h>
7 7
8QFont KGlobalSettings::generalFont() 8QFont KGlobalSettings::generalFont()
9{ 9{
10 int size = 12; 10 int size = 12;
11 if (QApplication::desktop()->width() < 480 ) { 11 if (QApplication::desktop()->width() < 480 ) {
12 size = 10; 12 size = 10;
13 } 13 }
14#ifndef DESKTOP_VERSION 14#ifndef DESKTOP_VERSION
15 else 15 else
16 if (QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) 16 if (QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
17 size = 18; 17 size = 18;
18#endif 18#endif
19 QFont f = QApplication::font(); 19 QFont f = QApplication::font();
20 //qDebug("pointsize %d %s", f.pointSize(),f.family().latin1()); 20 //qDebug("pointsize %d %s", f.pointSize(),f.family().latin1());
21 f.setPointSize( size ); 21 f.setPointSize( size );
22 return f; 22 return f;
23} 23}
24QFont KGlobalSettings::generalMaxFont() 24QFont KGlobalSettings::generalMaxFont()
25{ 25{
26 int size = 12; 26 int size = 12;
27 if (QApplication::desktop()->width() < 480 ) { 27 if (QApplication::desktop()->width() < 480 ) {
28 size = 10; 28 size = 10;
29 } 29 }
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31 else 31 else
32 if (QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) 32 if (QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
33 size = 18; 33 size = 18;
34#endif 34#endif
35 QFont f = QApplication::font(); 35 QFont f = QApplication::font();
36 if ( f.pointSize() > size ) 36 if ( f.pointSize() > size )
37 f.setPointSize( size ); 37 f.setPointSize( size );
38 return f; 38 return f;
39} 39}
40
41QString KGlobalSettings::timeTrackerDir()
42{
43 static QString dir;
44 if ( dir.isEmpty() ) {
45 dir = locateLocal( "data", "timetracker" );
46 }
47 return dir;
48}
49
40QFont KGlobalSettings::toolBarFont() 50QFont KGlobalSettings::toolBarFont()
41{ 51{
42 return QApplication::font(); 52 return QApplication::font();
43} 53}
44 54
45QColor KGlobalSettings::toolBarHighlightColor() 55QColor KGlobalSettings::toolBarHighlightColor()
46{ 56{
47 return QColor( "black" ); 57 return QColor( "black" );
48} 58}
49 59
50QRect KGlobalSettings::desktopGeometry( QWidget * ) 60QRect KGlobalSettings::desktopGeometry( QWidget * )
51{ 61{
52 return QApplication::desktop()->rect(); 62 return QApplication::desktop()->rect();
53} 63}
54 64
55 /** 65 /**
56 * Returns whether KDE runs in single (default) or double click 66 * Returns whether KDE runs in single (default) or double click
57 * mode. 67 * mode.
58 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html 68 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html
59 * @return true if single click mode, or false if double click mode. 69 * @return true if single click mode, or false if double click mode.
60 **/ 70 **/
61bool KGlobalSettings::singleClick() 71bool KGlobalSettings::singleClick()
62{ 72{
63 KConfig *c = KGlobal::config(); 73 KConfig *c = KGlobal::config();
64 KConfigGroupSaver cgs( c, "KDE" ); 74 KConfigGroupSaver cgs( c, "KDE" );
65 return c->readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK); 75 return c->readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK);
66} 76}
diff --git a/microkde/kglobalsettings.h b/microkde/kglobalsettings.h
index 075bb1c..3eeda35 100644
--- a/microkde/kglobalsettings.h
+++ b/microkde/kglobalsettings.h
@@ -1,31 +1,32 @@
1#ifndef MICROKDE_KGLOBALSETTINGS_H 1#ifndef MICROKDE_KGLOBALSETTINGS_H
2#define MICROKDE_KGLOBALSETTINGS_H 2#define MICROKDE_KGLOBALSETTINGS_H
3 3
4#include <qfont.h> 4#include <qfont.h>
5#include <qrect.h> 5#include <qrect.h>
6 6
7 7
8#define KDE_DEFAULT_SINGLECLICK true 8#define KDE_DEFAULT_SINGLECLICK true
9 9
10 10
11class KGlobalSettings 11class KGlobalSettings
12{ 12{
13 public: 13 public:
14 static QFont generalFont(); 14 static QFont generalFont();
15 static QFont generalMaxFont(); 15 static QFont generalMaxFont();
16 static QFont toolBarFont(); 16 static QFont toolBarFont();
17 17
18 static QColor toolBarHighlightColor(); 18 static QColor toolBarHighlightColor();
19 static QRect desktopGeometry( QWidget * ); 19 static QRect desktopGeometry( QWidget * );
20 static QString timeTrackerDir();
20 21
21 /** 22 /**
22 * Returns whether KDE runs in single (default) or double click 23 * Returns whether KDE runs in single (default) or double click
23 * mode. 24 * mode.
24 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html 25 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html
25 * @return true if single click mode, or false if double click mode. 26 * @return true if single click mode, or false if double click mode.
26 **/ 27 **/
27 static bool singleClick(); 28 static bool singleClick();
28 29
29}; 30};
30 31
31#endif 32#endif