summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-02-13 17:05:02 (UTC)
committer zautrix <zautrix>2005-02-13 17:05:02 (UTC)
commit293271fe9e6a9061da329183f8f488d79580f7da (patch) (unidiff)
tree3a0234eabdf58440a484e960b5eef912a63d0056 /korganizer
parent0a33f91e166747406ca2ccb5819881feeecfdb40 (diff)
downloadkdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.zip
kdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.tar.gz
kdepimpi-293271fe9e6a9061da329183f8f488d79580f7da.tar.bz2
todo rec fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoeditor.cpp29
-rw-r--r--korganizer/kotodoviewitem.cpp42
2 files changed, 69 insertions, 2 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 069dda8..9232e09 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -1,426 +1,455 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown 3 Copyright (c) 1997, 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qtooltip.h> 25#include <qtooltip.h>
26#include <qframe.h> 26#include <qframe.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qhbox.h> 29#include <qhbox.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qtabwidget.h> 33#include <qtabwidget.h>
34 34
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kfiledialog.h> 37#include <kfiledialog.h>
38#include <kstandarddirs.h> 38#include <kstandarddirs.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40 40
41#include <libkdepim/categoryselectdialog.h> 41#include <libkdepim/categoryselectdialog.h>
42#include <libkcal/calendarlocal.h> 42#include <libkcal/calendarlocal.h>
43#include <libkcal/calendarresources.h> 43#include <libkcal/calendarresources.h>
44#include <libkcal/resourcecalendar.h> 44#include <libkcal/resourcecalendar.h>
45#include <libkcal/icalformat.h> 45#include <libkcal/icalformat.h>
46#include <kresources/resourceselectdialog.h> 46#include <kresources/resourceselectdialog.h>
47#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
48 48
49#include "koprefs.h" 49#include "koprefs.h"
50#include "kolocationbox.h" 50#include "kolocationbox.h"
51 51
52#include "kotodoeditor.h" 52#include "kotodoeditor.h"
53extern int globalFlagBlockAgenda; 53extern int globalFlagBlockAgenda;
54 54
55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
57{ 57{
58 mTodo = 0; 58 mTodo = 0;
59 mRelatedTodo = 0; 59 mRelatedTodo = 0;
60 findButton(User1)->hide(); 60 findButton(User1)->hide();
61 init(); 61 init();
62} 62}
63 63
64KOTodoEditor::~KOTodoEditor() 64KOTodoEditor::~KOTodoEditor()
65{ 65{
66 emit dialogClose( mTodo ); 66 emit dialogClose( mTodo );
67} 67}
68 68
69void KOTodoEditor::init() 69void KOTodoEditor::init()
70{ 70{
71 setupGeneral(); 71 setupGeneral();
72 setupAttendeesTab(); 72 setupAttendeesTab();
73 setupRecurrence(); 73 setupRecurrence();
74 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence())); 74 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence()));
75} 75}
76void KOTodoEditor::setupRecurrence() 76void KOTodoEditor::setupRecurrence()
77{ 77{
78 QFrame *topFrame = addPage( i18n("Recurrence") ); 78 QFrame *topFrame = addPage( i18n("Recurrence") );
79 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 79 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
80 80
81 mRecurrence = new KOEditorRecurrence( topFrame ); 81 mRecurrence = new KOEditorRecurrence( topFrame );
82 topLayout->addWidget( mRecurrence ); 82 topLayout->addWidget( mRecurrence );
83} 83}
84 84
85void KOTodoEditor::setCategories( QString s ) 85void KOTodoEditor::setCategories( QString s )
86{ 86{
87 mGeneral->setCategories(s); 87 mGeneral->setCategories(s);
88} 88}
89void KOTodoEditor::setSecrecy( int sec ) 89void KOTodoEditor::setSecrecy( int sec )
90{ 90{
91 mGeneral->setSecrecy( sec ); 91 mGeneral->setSecrecy( sec );
92} 92}
93void KOTodoEditor::reload() 93void KOTodoEditor::reload()
94{ 94{
95 if ( mTodo ) readTodo( mTodo ); 95 if ( mTodo ) readTodo( mTodo );
96} 96}
97 97
98void KOTodoEditor::setupGeneral() 98void KOTodoEditor::setupGeneral()
99{ 99{
100 mGeneral = new KOEditorGeneralTodo(this); 100 mGeneral = new KOEditorGeneralTodo(this);
101 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); 101 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
102 102
103 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 103 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
104 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 104 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
105 // mGeneral,SLOT(setCategories(const QString &))); 105 // mGeneral,SLOT(setCategories(const QString &)));
106 106
107 if (KOPrefs::instance()->mCompactDialogs) { 107 if (KOPrefs::instance()->mCompactDialogs) {
108 QFrame *topFrame = addPage(i18n("General")); 108 QFrame *topFrame = addPage(i18n("General"));
109 109
110 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 110 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
111 if ( QApplication::desktop()->width() < 480 ) { 111 if ( QApplication::desktop()->width() < 480 ) {
112 topLayout->setMargin(1); 112 topLayout->setMargin(1);
113 topLayout->setSpacing(1); 113 topLayout->setSpacing(1);
114 } else { 114 } else {
115 topLayout->setMargin(marginHint()-1); 115 topLayout->setMargin(marginHint()-1);
116 topLayout->setSpacing(spacingHint()-1); 116 topLayout->setSpacing(spacingHint()-1);
117 } 117 }
118 mGeneral->initHeader(topFrame,topLayout); 118 mGeneral->initHeader(topFrame,topLayout);
119 mGeneral->initTime(topFrame,topLayout); 119 mGeneral->initTime(topFrame,topLayout);
120 mGeneral->initAlarm(topFrame,topLayout); 120 mGeneral->initAlarm(topFrame,topLayout);
121 mGeneral->enableAlarm( false ); 121 mGeneral->enableAlarm( false );
122 122
123 123
124 QBoxLayout *priorityLayout; 124 QBoxLayout *priorityLayout;
125 if ( QApplication::desktop()->width() < 500 ) 125 if ( QApplication::desktop()->width() < 500 )
126 priorityLayout = new QVBoxLayout( topLayout ); 126 priorityLayout = new QVBoxLayout( topLayout );
127 else 127 else
128 priorityLayout = new QHBoxLayout( topLayout ); 128 priorityLayout = new QHBoxLayout( topLayout );
129 QWidget* prioWidget = new QWidget (topFrame); 129 QWidget* prioWidget = new QWidget (topFrame);
130 priorityLayout->addWidget( prioWidget ); 130 priorityLayout->addWidget( prioWidget );
131 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget); 131 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget);
132 132
133 133
134 QIconSet icon; 134 QIconSet icon;
135 if ( QApplication::desktop()->width() < 321 ) 135 if ( QApplication::desktop()->width() < 321 )
136 icon = SmallIcon("fileexport16"); 136 icon = SmallIcon("fileexport16");
137 else 137 else
138 icon = SmallIcon("fileexport"); 138 icon = SmallIcon("fileexport");
139 QPushButton * saveTemplate = new QPushButton( prioWidget); 139 QPushButton * saveTemplate = new QPushButton( prioWidget);
140 saveTemplate->setIconSet (icon ) ; 140 saveTemplate->setIconSet (icon ) ;
141 int size = saveTemplate->sizeHint().height(); 141 int size = saveTemplate->sizeHint().height();
142 saveTemplate->setFixedSize( size, size ); 142 saveTemplate->setFixedSize( size, size );
143 if ( QApplication::desktop()->width() < 321 ) 143 if ( QApplication::desktop()->width() < 321 )
144 icon = SmallIcon("fileimport16"); 144 icon = SmallIcon("fileimport16");
145 else 145 else
146 icon = SmallIcon("fileimport"); 146 icon = SmallIcon("fileimport");
147 QPushButton * loadTemplate = new QPushButton( prioWidget); 147 QPushButton * loadTemplate = new QPushButton( prioWidget);
148 loadTemplate->setIconSet (icon ) ; 148 loadTemplate->setIconSet (icon ) ;
149 loadTemplate->setFixedSize( size, size ); 149 loadTemplate->setFixedSize( size, size );
150 150
151 priorityLayout2->addWidget(loadTemplate); 151 priorityLayout2->addWidget(loadTemplate);
152 priorityLayout2->addWidget(saveTemplate); 152 priorityLayout2->addWidget(saveTemplate);
153 mGeneral->initPriority(prioWidget,priorityLayout2); 153 mGeneral->initPriority(prioWidget,priorityLayout2);
154 mGeneral->initCategories( topFrame, priorityLayout ); 154 mGeneral->initCategories( topFrame, priorityLayout );
155 topLayout->addStretch(1); 155 topLayout->addStretch(1);
156 156
157 QFrame *topFrame2 = addPage(i18n("Details")); 157 QFrame *topFrame2 = addPage(i18n("Details"));
158 158
159 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 159 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
160 topLayout2->setMargin(marginHint()); 160 topLayout2->setMargin(marginHint());
161 topLayout2->setSpacing(spacingHint()); 161 topLayout2->setSpacing(spacingHint());
162 162
163 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 163 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
164 mGeneral->initCompletion(topFrame2,completionLayout); 164 mGeneral->initCompletion(topFrame2,completionLayout);
165 165
166 166
167 mGeneral->initSecrecy( topFrame2, topLayout2 ); 167 mGeneral->initSecrecy( topFrame2, topLayout2 );
168 mGeneral->initDescription(topFrame2,topLayout2); 168 mGeneral->initDescription(topFrame2,topLayout2);
169 169
170 // QHBox * hb = new QHBox ( topFrame2 ); 170 // QHBox * hb = new QHBox ( topFrame2 );
171 // topLayout2->addWidget(hb); 171 // topLayout2->addWidget(hb);
172 // hb->setSpacing( 3 ); 172 // hb->setSpacing( 3 );
173 173
174 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 174 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
175 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 175 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
176 176
177 } else { 177 } else {
178 QFrame *topFrame = addPage(i18n("General")); 178 QFrame *topFrame = addPage(i18n("General"));
179 179
180 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 180 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
181 topLayout->setSpacing(spacingHint()); 181 topLayout->setSpacing(spacingHint());
182 182
183 mGeneral->initHeader(topFrame,topLayout); 183 mGeneral->initHeader(topFrame,topLayout);
184 mGeneral->initTime(topFrame,topLayout); 184 mGeneral->initTime(topFrame,topLayout);
185 mGeneral->initStatus(topFrame,topLayout); 185 mGeneral->initStatus(topFrame,topLayout);
186 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 186 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
187 mGeneral->initAlarm(topFrame,alarmLineLayout); 187 mGeneral->initAlarm(topFrame,alarmLineLayout);
188 mGeneral->initDescription(topFrame,topLayout); 188 mGeneral->initDescription(topFrame,topLayout);
189 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 189 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
190 mGeneral->initCategories( topFrame, detailsLayout ); 190 mGeneral->initCategories( topFrame, detailsLayout );
191 mGeneral->initSecrecy( topFrame, detailsLayout ); 191 mGeneral->initSecrecy( topFrame, detailsLayout );
192 } 192 }
193 mGeneral->finishSetup(); 193 mGeneral->finishSetup();
194 194
195} 195}
196 196
197void KOTodoEditor::editTodo(Todo *todo, bool editDescription) 197void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
198{ 198{
199 //init(); 199 //init();
200 200
201 mTodo = todo; 201 mTodo = todo;
202 readTodo(mTodo); 202 readTodo(mTodo);
203 if ( editDescription ) { 203 if ( editDescription ) {
204 showPage( 1 ); 204 showPage( 1 );
205 mGeneral->setFocusOn( 1 ); 205 mGeneral->setFocusOn( 1 );
206 } else { 206 } else {
207 showPage( 0 ); 207 showPage( 0 );
208 mGeneral->setFocusOn( 2 ); 208 mGeneral->setFocusOn( 2 );
209 } 209 }
210 checkRecurrence(); 210 checkRecurrence();
211} 211}
212 212
213void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 213void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
214{ 214{
215 //init(); 215 //init();
216 216
217 mTodo = 0; 217 mTodo = 0;
218 setDefaults(due,relatedTodo,allDay); 218 setDefaults(due,relatedTodo,allDay);
219} 219}
220 220
221void KOTodoEditor::loadDefaults() 221void KOTodoEditor::loadDefaults()
222{ 222{
223 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 223 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
224} 224}
225 225
226bool KOTodoEditor::processInput( bool emitTime ) 226bool KOTodoEditor::processInput( bool emitTime )
227{ 227{
228 if (!validateInput()) return false; 228 if (!validateInput()) return false;
229 229
230 Todo *todo = 0; 230 Todo *todo = 0;
231 231
232 if (mTodo) todo = mTodo; 232 if (mTodo) todo = mTodo;
233 else { 233 else {
234 todo = new Todo; 234 todo = new Todo;
235 todo->setOrganizer(KOPrefs::instance()->email()); 235 todo->setOrganizer(KOPrefs::instance()->email());
236 } 236 }
237 237
238 writeTodo(todo); 238 writeTodo(todo);
239 if ( emitTime ) { 239 if ( emitTime ) {
240 globalFlagBlockAgenda = 1; 240 globalFlagBlockAgenda = 1;
241 emit showAgendaView( false ); 241 emit showAgendaView( false );
242 if ( todo->hasDueDate() ) 242 if ( todo->hasDueDate() )
243 emit jumpToTime( todo->dtDue().date() ); 243 emit jumpToTime( todo->dtDue().date() );
244 globalFlagBlockAgenda = 2; 244 globalFlagBlockAgenda = 2;
245 } 245 }
246 if (mTodo) { 246 if (mTodo) {
247 todo->setRevision(todo->revision()+1); 247 todo->setRevision(todo->revision()+1);
248 emit todoChanged(todo); 248 emit todoChanged(todo);
249 } else { 249 } else {
250 mCalendar->addTodo(todo); 250 mCalendar->addTodo(todo);
251 mTodo = todo; 251 mTodo = todo;
252 emit todoAdded(todo); 252 emit todoAdded(todo);
253 } 253 }
254 254
255 return true; 255 return true;
256} 256}
257 257
258void KOTodoEditor::deleteTodo() 258void KOTodoEditor::deleteTodo()
259{ 259{
260 if (mTodo) { 260 if (mTodo) {
261 if (KOPrefs::instance()->mConfirm) { 261 if (KOPrefs::instance()->mConfirm) {
262 switch (msgItemDelete()) { 262 switch (msgItemDelete()) {
263 case KMessageBox::Continue: // OK 263 case KMessageBox::Continue: // OK
264 emit todoToBeDeleted(mTodo); 264 emit todoToBeDeleted(mTodo);
265 emit dialogClose(mTodo); 265 emit dialogClose(mTodo);
266 mCalendar->deleteTodo(mTodo); 266 mCalendar->deleteTodo(mTodo);
267 emit todoDeleted(); 267 emit todoDeleted();
268 reject(); 268 reject();
269 break; 269 break;
270 } 270 }
271 } 271 }
272 else { 272 else {
273 emit todoToBeDeleted(mTodo); 273 emit todoToBeDeleted(mTodo);
274 emit dialogClose(mTodo); 274 emit dialogClose(mTodo);
275 mCalendar->deleteTodo(mTodo); 275 mCalendar->deleteTodo(mTodo);
276 emit todoDeleted(); 276 emit todoDeleted();
277 reject(); 277 reject();
278 } 278 }
279 } else { 279 } else {
280 reject(); 280 reject();
281 } 281 }
282} 282}
283 283
284void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 284void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
285{ 285{
286 mRelatedTodo = relatedEvent; 286 mRelatedTodo = relatedEvent;
287 287
288 mGeneral->setDefaults(due,allDay); 288 mGeneral->setDefaults(due,allDay);
289 mDetails->setDefaults(); 289 mDetails->setDefaults();
290 showPage( 0 ); 290 showPage( 0 );
291 if ( mRelatedTodo ) { 291 if ( mRelatedTodo ) {
292 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 292 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
293 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 293 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
294 if ( mRelatedTodo->priority() < 3 ) 294 if ( mRelatedTodo->priority() < 3 )
295 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); 295 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
296 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); 296 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
297 int len = mRelatedTodo->summary().length(); 297 int len = mRelatedTodo->summary().length();
298 mGeneral->mSummaryEdit->lineEdit()->setFocus(); 298 mGeneral->mSummaryEdit->lineEdit()->setFocus();
299 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); 299 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
300 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); 300 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
301 301
302 } else 302 } else
303 mGeneral->setFocusOn( 2 ); 303 mGeneral->setFocusOn( 2 );
304 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 304 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
305 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 305 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
306} 306}
307void KOTodoEditor::checkRecurrence() 307void KOTodoEditor::checkRecurrence()
308{ 308{
309 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 309 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
310 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); 310 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true );
311 311
312 if ( mTodo ) 312 if ( mTodo )
313 mRecurrence->readEvent( mTodo ); 313 mRecurrence->readEvent( mTodo );
314 else { 314 else {
315 bool time = mGeneral->mTimeButton->isChecked(); 315 bool time = mGeneral->mTimeButton->isChecked();
316 QDateTime from,to; 316 QDateTime from,to;
317 if ( time ) { 317 if ( time ) {
318 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; 318 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
319 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; 319 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
320 } else { 320 } else {
321 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; 321 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
322 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; 322 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
323 } 323 }
324 if ( to < from )
325 to = from;
324 mRecurrence->setDefaults(from,to,!time); 326 mRecurrence->setDefaults(from,to,!time);
325 } 327 }
326 } else { 328 } else {
327 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); 329 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
328 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); 330 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
329 } 331 }
330} 332}
331void KOTodoEditor::readTodo(Todo *todo) 333void KOTodoEditor::readTodo(Todo *todo)
332{ 334{
333 mGeneral->readTodo(todo); 335 mGeneral->readTodo(todo);
334 mDetails->readEvent(todo); 336 mDetails->readEvent(todo);
335 mRelatedTodo = 0;//todo->relatedTo(); 337 mRelatedTodo = 0;//todo->relatedTo();
336 // categories 338 // categories
337 // mCategoryDialog->setSelected(todo->categories()); 339 // mCategoryDialog->setSelected(todo->categories());
338 340
339 // We should handle read-only events here. 341 // We should handle read-only events here.
340} 342}
341 343
342void KOTodoEditor::writeTodo(Todo *event) 344void KOTodoEditor::writeTodo(Todo *event)
343{ 345{
344 mGeneral->writeTodo(event); 346 mGeneral->writeTodo(event);
345 mDetails->writeEvent(event); 347 mDetails->writeEvent(event);
346 348
347 // set related event, i.e. parent to-do in this case. 349 // set related event, i.e. parent to-do in this case.
348 if (mRelatedTodo) { 350 if (mRelatedTodo) {
349 event->setRelatedTo(mRelatedTodo); 351 event->setRelatedTo(mRelatedTodo);
350 } 352 }
351 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { 353 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
352 mRecurrence->writeEvent(event); 354 mRecurrence->writeEvent(event);
355 event->setRecurrenceID( event->dtStart().addSecs(-1) );
356 event->setRecurDates();
357#if 0
358 bool ok;
359 QDateTime next = event->getNextOccurence( event->dtStart().addSecs(-1), &ok );
360 if ( ok ) {
361 QDateTime from,to;
362 bool time = mGeneral->mTimeButton->isChecked();
363 if ( time ) {
364 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
365 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
366 } else {
367 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
368 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
369 }
370 if ( to < from )
371 to = from;
372 int secs = from.secsTo( to );
373 event->setRecurrenceID( next );
374 event->setDtStart( next );
375 event->setDtDue( next.addSecs( secs ) );
376 }
377 else {
378 event->setHasRecurrenceID( false );
379 event->recurrence()->unsetRecurs();
380 }
381#endif
353 } else 382 } else
354 event->recurrence()->unsetRecurs(); 383 event->recurrence()->unsetRecurs();
355} 384}
356 385
357bool KOTodoEditor::validateInput() 386bool KOTodoEditor::validateInput()
358{ 387{
359 if (!mGeneral->validateInput()) return false; 388 if (!mGeneral->validateInput()) return false;
360 if (!mDetails->validateInput()) return false; 389 if (!mDetails->validateInput()) return false;
361 return true; 390 return true;
362} 391}
363 392
364int KOTodoEditor::msgItemDelete() 393int KOTodoEditor::msgItemDelete()
365{ 394{
366 return KMessageBox::warningContinueCancel(this, 395 return KMessageBox::warningContinueCancel(this,
367 i18n("This item will be permanently deleted."), 396 i18n("This item will be permanently deleted."),
368 i18n("KOrganizer Confirmation"),i18n("Delete")); 397 i18n("KOrganizer Confirmation"),i18n("Delete"));
369} 398}
370 399
371void KOTodoEditor::modified (int modification) 400void KOTodoEditor::modified (int modification)
372{ 401{
373 if (modification == KOGlobals::CATEGORY_MODIFIED || 402 if (modification == KOGlobals::CATEGORY_MODIFIED ||
374 KOGlobals::UNKNOWN_MODIFIED == modification ) 403 KOGlobals::UNKNOWN_MODIFIED == modification )
375 // mCategoryDialog->setSelected (mTodo->categories ()); 404 // mCategoryDialog->setSelected (mTodo->categories ());
376 mGeneral->modified (mTodo, modification); 405 mGeneral->modified (mTodo, modification);
377 406
378} 407}
379 408
380void KOTodoEditor::slotLoadTemplate() 409void KOTodoEditor::slotLoadTemplate()
381{ 410{
382 411
383 QString fileName =locateLocal( "templates", "todos" ); 412 QString fileName =locateLocal( "templates", "todos" );
384 QDir t_dir; 413 QDir t_dir;
385 if ( !t_dir.exists(fileName) ) 414 if ( !t_dir.exists(fileName) )
386 t_dir.mkdir ( fileName ); 415 t_dir.mkdir ( fileName );
387 fileName += "/todo"; 416 fileName += "/todo";
388 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); 417 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
389 if ( fileName.length() == 0 ) 418 if ( fileName.length() == 0 )
390 return; 419 return;
391 CalendarLocal cal; 420 CalendarLocal cal;
392 ICalFormat format; 421 ICalFormat format;
393 if ( !format.load( &cal, fileName ) ) { 422 if ( !format.load( &cal, fileName ) ) {
394 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 423 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
395 .arg( fileName ) ); 424 .arg( fileName ) );
396 return ; 425 return ;
397 } 426 }
398 QPtrList<Todo> todos = cal.todos(); 427 QPtrList<Todo> todos = cal.todos();
399 Todo * todo = todos.first(); 428 Todo * todo = todos.first();
400 if ( !todo ) { 429 if ( !todo ) {
401 KMessageBox::error( this, 430 KMessageBox::error( this,
402 i18n("Template does not\ncontain a valid Todo.")); 431 i18n("Template does not\ncontain a valid Todo."));
403 } else { 432 } else {
404 readTodo( todo ); 433 readTodo( todo );
405 } 434 }
406 435
407} 436}
408 437
409void KOTodoEditor::slotSaveTemplate() 438void KOTodoEditor::slotSaveTemplate()
410{ 439{
411 QString fileName =locateLocal( "templates", "todos" ); 440 QString fileName =locateLocal( "templates", "todos" );
412 QDir t_dir; 441 QDir t_dir;
413 if ( !t_dir.exists(fileName) ) 442 if ( !t_dir.exists(fileName) )
414 t_dir.mkdir ( fileName ); 443 t_dir.mkdir ( fileName );
415 fileName += "/todo"; 444 fileName += "/todo";
416 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); 445 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
417 if ( fileName.length() > 0 ) 446 if ( fileName.length() > 0 )
418 saveTemplate( fileName ); 447 saveTemplate( fileName );
419} 448}
420 449
421void KOTodoEditor::saveTemplate( const QString &templateName ) 450void KOTodoEditor::saveTemplate( const QString &templateName )
422{ 451{
423 Todo *todo = new Todo; 452 Todo *todo = new Todo;
424 writeTodo( todo ); 453 writeTodo( todo );
425 saveAsTemplate( todo, templateName ); 454 saveAsTemplate( todo, templateName );
426} 455}
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 0e847c2..70f00c6 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,461 +1,499 @@
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 23
24#include <kiconloader.h> 24#include <kiconloader.h>
25#include "kotodoviewitem.h" 25#include "kotodoviewitem.h"
26#include "kotodoview.h" 26#include "kotodoview.h"
27#include "koprefs.h" 27#include "koprefs.h"
28 28
29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
31{ 31{
32 construct(); 32 construct();
33} 33}
34 34
35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
37{ 37{
38 construct(); 38 construct();
39} 39}
40 40
41QString KOTodoViewItem::key(int column,bool) const 41QString KOTodoViewItem::key(int column,bool) const
42{ 42{
43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
44 if (it == mKeyMap.end()) { 44 if (it == mKeyMap.end()) {
45 return text(column).lower(); 45 return text(column).lower();
46 } else { 46 } else {
47 return *it; 47 return *it;
48 } 48 }
49} 49}
50 50
51void KOTodoViewItem:: setup() 51void KOTodoViewItem:: setup()
52{ 52{
53 53
54 int h = 20; 54 int h = 20;
55 if ( listView () ) { 55 if ( listView () ) {
56 QFontMetrics fm ( listView ()->font () ); 56 QFontMetrics fm ( listView ()->font () );
57 h = fm.height(); 57 h = fm.height();
58 } 58 }
59 setHeight( h ); 59 setHeight( h );
60 60
61} 61}
62void KOTodoViewItem::setSortKey(int column,const QString &key) 62void KOTodoViewItem::setSortKey(int column,const QString &key)
63{ 63{
64 mKeyMap.insert(column,key); 64 mKeyMap.insert(column,key);
65} 65}
66 66
67#if QT_VERSION >= 0x030000 67#if QT_VERSION >= 0x030000
68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
69 int y,int h) 69 int y,int h)
70{ 70{
71 QListViewItem::paintBranches(p,cg,w,y,h); 71 QListViewItem::paintBranches(p,cg,w,y,h);
72} 72}
73#else 73#else
74#endif 74#endif
75 75
76void KOTodoViewItem::construct() 76void KOTodoViewItem::construct()
77{ 77{
78 // qDebug("KOTodoViewItem::construct() "); 78 // qDebug("KOTodoViewItem::construct() ");
79 m_init = true; 79 m_init = true;
80 QString keyd = "=="; 80 QString keyd = "==";
81 QString keyt = "=="; 81 QString keyt = "==";
82 QString skeyd = "=="; 82 QString skeyd = "==";
83 QString skeyt = "=="; 83 QString skeyt = "==";
84 84
85 setOn(mTodo->isCompleted()); 85 setOn(mTodo->isCompleted());
86 setText(0,mTodo->summary()); 86 setText(0,mTodo->summary());
87 setText(1,QString::number(mTodo->priority())); 87 setText(1,QString::number(mTodo->priority()));
88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 88 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
89 if (mTodo->percentComplete()<100) { 89 if (mTodo->percentComplete()<100) {
90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 90 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
91 else setSortKey(2,QString::number(mTodo->percentComplete())); 91 else setSortKey(2,QString::number(mTodo->percentComplete()));
92 } 92 }
93 else { 93 else {
94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 94 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
95 else setSortKey(2,QString::number(99)); 95 else setSortKey(2,QString::number(99));
96 } 96 }
97 if (mTodo->hasDueDate()) { 97 if (mTodo->hasDueDate()) {
98 setText(3, mTodo->dtDueDateStr()); 98 setText(3, mTodo->dtDueDateStr());
99 QDate d = mTodo->dtDue().date(); 99 QDate d = mTodo->dtDue().date();
100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 100 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
101 // setSortKey(3,keyd); 101 // setSortKey(3,keyd);
102 if (mTodo->doesFloat()) { 102 if (mTodo->doesFloat()) {
103 setText(4,""); 103 setText(4,"");
104 } 104 }
105 else { 105 else {
106 setText(4,mTodo->dtDueTimeStr()); 106 setText(4,mTodo->dtDueTimeStr());
107 QTime t = mTodo->dtDue().time(); 107 QTime t = mTodo->dtDue().time();
108 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 108 keyt.sprintf("%02d%02d",t.hour(),t.minute());
109 //setSortKey(4,keyt); 109 //setSortKey(4,keyt);
110 } 110 }
111 } else { 111 } else {
112 setText(3,""); 112 setText(3,"");
113 setText(4,""); 113 setText(4,"");
114 } 114 }
115 setSortKey(3,keyd); 115 setSortKey(3,keyd);
116 setSortKey(4,keyt); 116 setSortKey(4,keyt);
117 117
118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 118 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 119 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
120 120
121 121
122 122
123 if (mTodo->hasStartDate()) { 123 if (mTodo->hasStartDate()) {
124 setText(5, mTodo->dtStartDateStr()); 124 setText(5, mTodo->dtStartDateStr());
125 QDate d = mTodo->dtStart().date(); 125 QDate d = mTodo->dtStart().date();
126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 126 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
127 127
128 if (mTodo->doesFloat()) { 128 if (mTodo->doesFloat()) {
129 setText(6,""); 129 setText(6,"");
130 } 130 }
131 else { 131 else {
132 setText(6,mTodo->dtStartTimeStr()); 132 setText(6,mTodo->dtStartTimeStr());
133 QTime t = mTodo->dtStart().time(); 133 QTime t = mTodo->dtStart().time();
134 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 134 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
135 135
136 } 136 }
137 } else { 137 } else {
138 setText(5,""); 138 setText(5,"");
139 setText(6,""); 139 setText(6,"");
140 } 140 }
141 setSortKey(5,skeyd); 141 setSortKey(5,skeyd);
142 setSortKey(6,skeyt); 142 setSortKey(6,skeyt);
143 143
144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 144 setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
145 setText(8,mTodo->categoriesStr()); 145 setText(8,mTodo->categoriesStr());
146 146
147#if 0 147#if 0
148 // Find sort id in description. It's the text behind the last '#' character 148 // Find sort id in description. It's the text behind the last '#' character
149 // found in the description. White spaces are removed from beginning and end 149 // found in the description. White spaces are removed from beginning and end
150 // of sort id. 150 // of sort id.
151 int pos = mTodo->description().findRev('#'); 151 int pos = mTodo->description().findRev('#');
152 if (pos < 0) { 152 if (pos < 0) {
153 setText(6,""); 153 setText(6,"");
154 } else { 154 } else {
155 QString str = mTodo->description().mid(pos+1); 155 QString str = mTodo->description().mid(pos+1);
156 str.stripWhiteSpace(); 156 str.stripWhiteSpace();
157 setText(6,str); 157 setText(6,str);
158 } 158 }
159#endif 159#endif
160 160
161 m_known = false; 161 m_known = false;
162 m_init = false; 162 m_init = false;
163 163
164 setMyPixmap(); 164 setMyPixmap();
165 165
166} 166}
167void KOTodoViewItem::setMyPixmap() 167void KOTodoViewItem::setMyPixmap()
168{ 168{
169 int size = 5; 169 int size = 5;
170 QPixmap pixi = QPixmap( 1, 1 ); 170 QPixmap pixi = QPixmap( 1, 1 );
171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 171 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
172// pixi = SmallIcon("redcross16"); 172// pixi = SmallIcon("redcross16");
173// } else { 173// } else {
174 QPainter p; 174 QPainter p;
175 175
176 int pixSize = 0; 176 int pixSize = 0;
177 QPixmap pPix = QPixmap( size, size ); 177 QPixmap pPix = QPixmap( size, size );
178 if ( mTodo->description().length() > 0 ) { 178 if ( mTodo->description().length() > 0 ) {
179 pixi.resize(size, pixSize+size); 179 pixi.resize(size, pixSize+size);
180 pPix.fill( Qt::darkGreen ); 180 pPix.fill( Qt::darkGreen );
181 p.begin( &pixi ); 181 p.begin( &pixi );
182 p. drawPixmap ( 0, pixSize, pPix); 182 p. drawPixmap ( 0, pixSize, pPix);
183 p.end(); 183 p.end();
184 pixSize += size; 184 pixSize += size;
185 } 185 }
186 if ( mTodo->isAlarmEnabled() ) { 186 if ( mTodo->isAlarmEnabled() ) {
187 pixi.resize(size, pixSize+size); 187 pixi.resize(size, pixSize+size);
188 pPix.fill( Qt::red ); 188 pPix.fill( Qt::red );
189 p.begin( &pixi ); 189 p.begin( &pixi );
190 p. drawPixmap ( 0, pixSize, pPix); 190 p. drawPixmap ( 0, pixSize, pPix);
191 p.end(); 191 p.end();
192 pixSize += size; 192 pixSize += size;
193 }
194 if ( mTodo->doesRecur() ) {
195 pixi.resize(size, pixSize+size);
196 pPix.fill( Qt::blue );
197 p.begin( &pixi );
198 p. drawPixmap ( 0, pixSize, pPix);
199 p.end();
200 pixSize += size;
193 } 201 }
194 // } 202 // }
195 if ( pixi.width() > 1 ) { 203 if ( pixi.width() > 1 ) {
196 setPixmap ( 0,pixi ) ; 204 setPixmap ( 0,pixi ) ;
197 } else { 205 } else {
198 setPixmap ( 0,QPixmap() ) ; 206 setPixmap ( 0,QPixmap() ) ;
199 } 207 }
200} 208}
201void KOTodoViewItem::stateChange(bool state) 209void KOTodoViewItem::stateChange(bool state)
202{ 210{
203 // qDebug("KOTodoViewItem::stateChange "); 211 // qDebug("KOTodoViewItem::stateChange %d ", state);
204 // do not change setting on startup 212 // do not change setting on startup
205 if ( m_init ) return; 213 if ( m_init ) return;
206 if (isOn()!=state) { 214 if (isOn()!=state) {
207 setOn(state); 215 setOn(state);
208 //qDebug("SETON "); 216 //qDebug("SETON ");
209 return; 217 return;
210 } 218 }
211 if ( mTodo->isCompleted() == state ) { 219 if ( mTodo->isCompleted() == state ) {
212 //qDebug("STATECHANGE:nothing to do "); 220 //qDebug("STATECHANGE:nothing to do ");
213 return; 221 return;
214 } 222 }
215 QString keyd = "=="; 223 QString keyd = "==";
216 QString keyt = "=="; 224 QString keyt = "==";
217 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 225 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
218 mTodo->setCompleted(state); 226 if ( mTodo->doesRecur() ){
227 QDateTime start = mTodo->dtStart();
228 mTodo->setCompleted(state);
229 if ( start != mTodo->dtStart() ) {
230 if ( state && !mTodo->isCompleted() ) {
231 setOn( false );
232 state = false;
233 }
234 }
235 } else
236 mTodo->setCompleted(state);
237
219 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 238 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
220 239
221 if (mTodo->hasDueDate()) { 240 if (mTodo->hasDueDate()) {
222 setText(3, mTodo->dtDueDateStr()); 241 setText(3, mTodo->dtDueDateStr());
223 QDate d = mTodo->dtDue().date(); 242 QDate d = mTodo->dtDue().date();
224 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 243 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
225 setSortKey(3,keyd); 244 setSortKey(3,keyd);
226 if (mTodo->doesFloat()) { 245 if (mTodo->doesFloat()) {
227 setText(4,""); 246 setText(4,"");
228 } 247 }
229 else { 248 else {
230 setText(4,mTodo->dtDueTimeStr()); 249 setText(4,mTodo->dtDueTimeStr());
231 QTime t = mTodo->dtDue().time(); 250 QTime t = mTodo->dtDue().time();
232 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 251 keyt.sprintf("%02d%02d",t.hour(),t.minute());
233 setSortKey(4,keyt); 252 setSortKey(4,keyt);
234 } 253 }
235 } 254 }
255 if (mTodo->hasStartDate()) {
256 QString skeyt = "==";
257 QString skeyd = "==";
258 setText(5, mTodo->dtStartDateStr());
259 QDate d = mTodo->dtStart().date();
260 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
261
262 if (mTodo->doesFloat()) {
263 setText(6,"");
264 }
265 else {
266 setText(6,mTodo->dtStartTimeStr());
267 QTime t = mTodo->dtStart().time();
268 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
269
270 }
271 setSortKey(5,skeyd);
272 setSortKey(6,skeyt);
273 }
236 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 274 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
237 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 275 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
238 276
239 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 277 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
240 if (mTodo->percentComplete()<100) { 278 if (mTodo->percentComplete()<100) {
241 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 279 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
242 else setSortKey(2,QString::number(mTodo->percentComplete())); 280 else setSortKey(2,QString::number(mTodo->percentComplete()));
243 } 281 }
244 else { 282 else {
245 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 283 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
246 else setSortKey(2,QString::number(99)); 284 else setSortKey(2,QString::number(99));
247 } 285 }
248 if ( state ) { 286 if ( state ) {
249 QListViewItem * myChild = firstChild(); 287 QListViewItem * myChild = firstChild();
250 KOTodoViewItem *item; 288 KOTodoViewItem *item;
251 while( myChild ) { 289 while( myChild ) {
252 //qDebug("stateCH "); 290 //qDebug("stateCH ");
253 item = static_cast<KOTodoViewItem*>(myChild); 291 item = static_cast<KOTodoViewItem*>(myChild);
254 item->stateChange(state); 292 item->stateChange(state);
255 myChild = myChild->nextSibling(); 293 myChild = myChild->nextSibling();
256 } 294 }
257 } else { 295 } else {
258 QListViewItem * myChild = parent(); 296 QListViewItem * myChild = parent();
259 if ( myChild ) 297 if ( myChild )
260 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 298 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
261 } 299 }
262 mTodoView->modified(true); 300 mTodoView->modified(true);
263 setMyPixmap(); 301 setMyPixmap();
264 mTodoView->setTodoModified( mTodo ); 302 mTodoView->setTodoModified( mTodo );
265} 303}
266 304
267bool KOTodoViewItem::isAlternate() 305bool KOTodoViewItem::isAlternate()
268{ 306{
269 307
270 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 308 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
271 if (lv && lv->alternateBackground().isValid()) 309 if (lv && lv->alternateBackground().isValid())
272 { 310 {
273 KOTodoViewItem *above = 0; 311 KOTodoViewItem *above = 0;
274 above = static_cast<KOTodoViewItem *>(itemAbove()); 312 above = static_cast<KOTodoViewItem *>(itemAbove());
275 m_known = above ? above->m_known : true; 313 m_known = above ? above->m_known : true;
276 if (m_known) 314 if (m_known)
277 { 315 {
278 m_odd = above ? !above->m_odd : false; 316 m_odd = above ? !above->m_odd : false;
279 } 317 }
280 else 318 else
281 { 319 {
282 KOTodoViewItem *item; 320 KOTodoViewItem *item;
283 bool previous = true; 321 bool previous = true;
284 if (QListViewItem::parent()) 322 if (QListViewItem::parent())
285 { 323 {
286 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 324 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
287 if (item) 325 if (item)
288 previous = item->m_odd; 326 previous = item->m_odd;
289 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 327 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
290 } 328 }
291 else 329 else
292 { 330 {
293 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 331 item = static_cast<KOTodoViewItem *>(lv->firstChild());
294 } 332 }
295 333
296 while(item) 334 while(item)
297 { 335 {
298 item->m_odd = previous = !previous; 336 item->m_odd = previous = !previous;
299 item->m_known = true; 337 item->m_known = true;
300 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 338 item = static_cast<KOTodoViewItem *>(item->nextSibling());
301 } 339 }
302 } 340 }
303 return m_odd; 341 return m_odd;
304 } 342 }
305 return false; 343 return false;
306} 344}
307 345
308void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 346void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
309{ 347{
310 QColorGroup _cg = cg; 348 QColorGroup _cg = cg;
311 QColorGroup::ColorRole role; 349 QColorGroup::ColorRole role;
312 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 350 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
313 role = QColorGroup::Text; 351 role = QColorGroup::Text;
314 else 352 else
315 role = QColorGroup::Base; 353 role = QColorGroup::Base;
316 //#ifndef KORG_NOLVALTERNATION 354 //#ifndef KORG_NOLVALTERNATION
317 if (isAlternate()) 355 if (isAlternate())
318 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 356 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
319 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 357 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
320 QColor colorToSet; 358 QColor colorToSet;
321 if ( setColor ) { 359 if ( setColor ) {
322 QStringList categories = mTodo->categories(); 360 QStringList categories = mTodo->categories();
323 QString cat = categories.first(); 361 QString cat = categories.first();
324 if ( !cat.isEmpty()) { 362 if ( !cat.isEmpty()) {
325 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 363 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
326 } else 364 } else
327 setColor = false; 365 setColor = false;
328 } 366 }
329 367
330 int odue = mTodo->hasDueSubTodo( !isOpen()); 368 int odue = mTodo->hasDueSubTodo( !isOpen());
331 if (odue == 2) { 369 if (odue == 2) {
332 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 370 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
333 setColor = true; 371 setColor = true;
334 } else if ( odue == 1 ) { 372 } else if ( odue == 1 ) {
335 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 373 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
336 setColor = true; 374 setColor = true;
337 } 375 }
338 376
339 377
340 if ( setColor ) { 378 if ( setColor ) {
341 _cg.setColor(role,colorToSet ); 379 _cg.setColor(role,colorToSet );
342 if ( role == QColorGroup::Base) { 380 if ( role == QColorGroup::Base) {
343 int rgb = colorToSet.red(); 381 int rgb = colorToSet.red();
344 rgb += colorToSet.blue()/2; 382 rgb += colorToSet.blue()/2;
345 rgb += colorToSet.green(); 383 rgb += colorToSet.green();
346 if ( rgb < 200 ) 384 if ( rgb < 200 )
347 _cg.setColor(QColorGroup::Text,Qt::white ); 385 _cg.setColor(QColorGroup::Text,Qt::white );
348 } 386 }
349 } 387 }
350 //#endif 388 //#endif
351 if ( column > 0 ){ 389 if ( column > 0 ){
352 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 390 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
353 p->save(); 391 p->save();
354 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 392 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
355 393
356 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 394 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
357 // p->setPen(Qt::black ); //border 395 // p->setPen(Qt::black ); //border
358 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 396 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
359 QColor fc = KOPrefs::instance()->mHighlightColor; 397 QColor fc = KOPrefs::instance()->mHighlightColor;
360 if ( mTodo->percentComplete() == 100 ) 398 if ( mTodo->percentComplete() == 100 )
361 fc = darkGreen; 399 fc = darkGreen;
362 p->drawRect( 2, 2, width-4, height()-4); 400 p->drawRect( 2, 2, width-4, height()-4);
363 p->fillRect( 3, 3, progress, height()-6, 401 p->fillRect( 3, 3, progress, height()-6,
364 fc ); 402 fc );
365 p->restore(); 403 p->restore();
366 } else { 404 } else {
367 QCheckListItem::paintCell(p, _cg, column, width, alignment); 405 QCheckListItem::paintCell(p, _cg, column, width, alignment);
368 } 406 }
369 return; 407 return;
370 } 408 }
371 409
372 int align = alignment; 410 int align = alignment;
373 411
374 if ( !p ) 412 if ( !p )
375 return; 413 return;
376 414
377 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 415 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
378 416
379 QListView *lv = listView(); 417 QListView *lv = listView();
380 if ( !lv ) 418 if ( !lv )
381 return; 419 return;
382 int marg = 2;//lv->itemMargin(); 420 int marg = 2;//lv->itemMargin();
383 int r = 0; 421 int r = 0;
384 QCheckListItem::Type myType = QCheckListItem::CheckBox; 422 QCheckListItem::Type myType = QCheckListItem::CheckBox;
385 int BoxSize = 20; 423 int BoxSize = 20;
386 int boxOffset = 2; 424 int boxOffset = 2;
387 int xOffset = 2; 425 int xOffset = 2;
388 if (qApp->desktop()->width() < 300 ) { 426 if (qApp->desktop()->width() < 300 ) {
389 BoxSize = 14; 427 BoxSize = 14;
390 boxOffset = -1; 428 boxOffset = -1;
391 xOffset = 1; 429 xOffset = 1;
392 // marg = 0; 430 // marg = 0;
393 } 431 }
394 if ( height() < BoxSize ) { 432 if ( height() < BoxSize ) {
395 boxOffset = boxOffset - ((BoxSize - height())/2) ; 433 boxOffset = boxOffset - ((BoxSize - height())/2) ;
396 // qDebug("boxOffset %d height %d", boxOffset, height() ); 434 // qDebug("boxOffset %d height %d", boxOffset, height() );
397 BoxSize = height(); 435 BoxSize = height();
398 436
399 } 437 }
400 //bool winStyle = lv->style() == WindowsStyle; 438 //bool winStyle = lv->style() == WindowsStyle;
401 439
402 int lineStart = 5; 440 int lineStart = 5;
403 if ( myType == Controller ) { 441 if ( myType == Controller ) {
404 if ( !pixmap( 0 ) ) 442 if ( !pixmap( 0 ) )
405 r += BoxSize + 4; 443 r += BoxSize + 4;
406 } else { 444 } else {
407 ASSERT( lv ); //### 445 ASSERT( lv ); //###
408 //QFontMetrics fm( lv->font() ); 446 //QFontMetrics fm( lv->font() );
409 //int d = fm.height(); 447 //int d = fm.height();
410 int x = 0; 448 int x = 0;
411 int y = (height() - BoxSize) / 2; 449 int y = (height() - BoxSize) / 2;
412 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 450 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
413 if ( myType == CheckBox ) { 451 if ( myType == CheckBox ) {
414 if ( isEnabled() ) 452 if ( isEnabled() )
415 p->setPen( QPen( _cg.text(), 1 ) ); 453 p->setPen( QPen( _cg.text(), 1 ) );
416 else 454 else
417 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 455 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
418 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 456 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
419 lineStart = x+marg; 457 lineStart = x+marg;
420 ///////////////////// 458 /////////////////////
421 x++; 459 x++;
422 y++; 460 y++;
423 if ( isOn() ) { 461 if ( isOn() ) {
424 QPointArray a( 7*2 ); 462 QPointArray a( 7*2 );
425 int i, xx, yy; 463 int i, xx, yy;
426 xx = x+xOffset+marg+(boxOffset/2); 464 xx = x+xOffset+marg+(boxOffset/2);
427 yy = y+5+boxOffset; 465 yy = y+5+boxOffset;
428 for ( i=0; i<3; i++ ) { 466 for ( i=0; i<3; i++ ) {
429 a.setPoint( 2*i, xx, yy ); 467 a.setPoint( 2*i, xx, yy );
430 a.setPoint( 2*i+1, xx, yy+2 ); 468 a.setPoint( 2*i+1, xx, yy+2 );
431 // qDebug(" "); 469 // qDebug(" ");
432 xx++; yy++; 470 xx++; yy++;
433 } 471 }
434 yy -= 2; 472 yy -= 2;
435 for ( i=3; i<7; i++ ) { 473 for ( i=3; i<7; i++ ) {
436 a.setPoint( 2*i, xx, yy ); 474 a.setPoint( 2*i, xx, yy );
437 a.setPoint( 2*i+1, xx, yy+2 ); 475 a.setPoint( 2*i+1, xx, yy+2 );
438 xx++; yy--; 476 xx++; yy--;
439 } 477 }
440 p->setPen( darkGreen ); 478 p->setPen( darkGreen );
441 p->drawLineSegments( a ); 479 p->drawLineSegments( a );
442 } 480 }
443 //////////////////////// 481 ////////////////////////
444 } 482 }
445 r += BoxSize + 4; 483 r += BoxSize + 4;
446 } 484 }
447 485
448 p->translate( r, 0 ); 486 p->translate( r, 0 );
449 p->setPen( QPen( _cg.text() ) ); 487 p->setPen( QPen( _cg.text() ) );
450 QListViewItem::paintCell( p, _cg, column, width - r, align ); 488 QListViewItem::paintCell( p, _cg, column, width - r, align );
451 if ( mTodo->cancelled () ) { 489 if ( mTodo->cancelled () ) {
452 p->setPen( black ); 490 p->setPen( black );
453 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 491 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
454 int wid = br.width() +lineStart; 492 int wid = br.width() +lineStart;
455 if ( wid > width-3 ) 493 if ( wid > width-3 )
456 wid = width-3; 494 wid = width-3;
457 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); 495 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
458 496
459 } 497 }
460 498
461} 499}