summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-30 15:49:34 (UTC)
committer zautrix <zautrix>2005-01-30 15:49:34 (UTC)
commita34c528fdd8d2cdec14bae9ccb0eee54c8e4e374 (patch) (unidiff)
tree21a900be618695f6dac42b5e9df6094201a981d0
parent11736af9b5348f251b0e8a3cf90fdb960c877936 (diff)
downloadkdepimpi-a34c528fdd8d2cdec14bae9ccb0eee54c8e4e374.zip
kdepimpi-a34c528fdd8d2cdec14bae9ccb0eee54c8e4e374.tar.gz
kdepimpi-a34c528fdd8d2cdec14bae9ccb0eee54c8e4e374.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 902f3f4..2f5259f 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1245 +1,1245 @@
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 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27 27
28#include <qvbox.h> 28#include <qvbox.h>
29#include <kdebug.h> 29#include <kdebug.h>
30#include "koprefs.h" 30#include "koprefs.h"
31#include <klocale.h> 31#include <klocale.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/vcaldrag.h> 37#include <libkcal/vcaldrag.h>
38#include <libkcal/calfilter.h> 38#include <libkcal/calfilter.h>
39#include <libkcal/dndfactory.h> 39#include <libkcal/dndfactory.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42#include <kresources/resourceselectdialog.h> 42#include <kresources/resourceselectdialog.h>
43#ifndef DESKTOP_VERSION 43#ifndef DESKTOP_VERSION
44#include <qpe/qpeapplication.h> 44#include <qpe/qpeapplication.h>
45#else 45#else
46#include <qapplication.h> 46#include <qapplication.h>
47#endif 47#endif
48#ifndef KORG_NOPRINTER 48#ifndef KORG_NOPRINTER
49#include "calprinter.h" 49#include "calprinter.h"
50#endif 50#endif
51#include "docprefs.h" 51#include "docprefs.h"
52 52
53#include "kotodoview.h" 53#include "kotodoview.h"
54using namespace KOrg; 54using namespace KOrg;
55 55
56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
57 const char *name) : 57 const char *name) :
58 KListView(parent,name) 58 KListView(parent,name)
59{ 59{
60 mName = QString ( name ); 60 mName = QString ( name );
61 mCalendar = calendar; 61 mCalendar = calendar;
62#ifndef DESKTOP_VERSION 62#ifndef DESKTOP_VERSION
63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
64#endif 64#endif
65 mOldCurrent = 0; 65 mOldCurrent = 0;
66 mMousePressed = false; 66 mMousePressed = false;
67 67
68 setAcceptDrops(true); 68 setAcceptDrops(true);
69 viewport()->setAcceptDrops(true); 69 viewport()->setAcceptDrops(true);
70 int size = 16; 70 int size = 16;
71 if (qApp->desktop()->width() < 300 ) 71 if (qApp->desktop()->width() < 300 )
72 size = 12; 72 size = 12;
73 setTreeStepSize( size + 6 ); 73 setTreeStepSize( size + 6 );
74 74
75} 75}
76 76
77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
78{ 78{
79#ifndef KORG_NODND 79#ifndef KORG_NODND
80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
82 !QTextDrag::canDecode( e ) ) { 82 !QTextDrag::canDecode( e ) ) {
83 e->ignore(); 83 e->ignore();
84 return; 84 return;
85 } 85 }
86 86
87 mOldCurrent = currentItem(); 87 mOldCurrent = currentItem();
88#endif 88#endif
89} 89}
90 90
91 91
92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
93{ 93{
94#ifndef KORG_NODND 94#ifndef KORG_NODND
95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
96 96
97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
98 !QTextDrag::canDecode( e ) ) { 98 !QTextDrag::canDecode( e ) ) {
99 e->ignore(); 99 e->ignore();
100 return; 100 return;
101 } 101 }
102 102
103 e->accept(); 103 e->accept();
104#endif 104#endif
105} 105}
106 106
107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
108{ 108{
109#ifndef KORG_NODND 109#ifndef KORG_NODND
110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
111 111
112 setCurrentItem(mOldCurrent); 112 setCurrentItem(mOldCurrent);
113 setSelected(mOldCurrent,true); 113 setSelected(mOldCurrent,true);
114#endif 114#endif
115} 115}
116 116
117void KOTodoListView::contentsDropEvent(QDropEvent *e) 117void KOTodoListView::contentsDropEvent(QDropEvent *e)
118{ 118{
119#ifndef KORG_NODND 119#ifndef KORG_NODND
120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
121 121
122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
123 !QTextDrag::canDecode( e ) ) { 123 !QTextDrag::canDecode( e ) ) {
124 e->ignore(); 124 e->ignore();
125 return; 125 return;
126 } 126 }
127 127
128 DndFactory factory( mCalendar ); 128 DndFactory factory( mCalendar );
129 Todo *todo = factory.createDropTodo(e); 129 Todo *todo = factory.createDropTodo(e);
130 130
131 if (todo) { 131 if (todo) {
132 e->acceptAction(); 132 e->acceptAction();
133 133
134 KOTodoViewItem *destination = 134 KOTodoViewItem *destination =
135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
136 Todo *destinationEvent = 0; 136 Todo *destinationEvent = 0;
137 if (destination) destinationEvent = destination->todo(); 137 if (destination) destinationEvent = destination->todo();
138 138
139 Todo *existingTodo = mCalendar->todo(todo->uid()); 139 Todo *existingTodo = mCalendar->todo(todo->uid());
140 140
141 if(existingTodo) { 141 if(existingTodo) {
142 Incidence *to = destinationEvent; 142 Incidence *to = destinationEvent;
143 while(to) { 143 while(to) {
144 if (to->uid() == todo->uid()) { 144 if (to->uid() == todo->uid()) {
145 KMessageBox::sorry(this, 145 KMessageBox::sorry(this,
146 i18n("Cannot move To-Do to itself\nor a child of itself"), 146 i18n("Cannot move To-Do to itself\nor a child of itself"),
147 i18n("Drop To-Do")); 147 i18n("Drop To-Do"));
148 delete todo; 148 delete todo;
149 return; 149 return;
150 } 150 }
151 to = to->relatedTo(); 151 to = to->relatedTo();
152 } 152 }
153 internalDrop = true; 153 internalDrop = true;
154 if ( destinationEvent ) 154 if ( destinationEvent )
155 reparentTodoSignal( destinationEvent, existingTodo ); 155 reparentTodoSignal( destinationEvent, existingTodo );
156 else 156 else
157 unparentTodoSignal(existingTodo); 157 unparentTodoSignal(existingTodo);
158 delete todo; 158 delete todo;
159 } else { 159 } else {
160 mCalendar->addTodo(todo); 160 mCalendar->addTodo(todo);
161 emit todoDropped(todo, KOGlobals::EVENTADDED); 161 emit todoDropped(todo, KOGlobals::EVENTADDED);
162 if ( destinationEvent ) 162 if ( destinationEvent )
163 reparentTodoSignal( destinationEvent, todo ); 163 reparentTodoSignal( destinationEvent, todo );
164 } 164 }
165 } 165 }
166 else { 166 else {
167 QString text; 167 QString text;
168 if (QTextDrag::decode(e,text)) { 168 if (QTextDrag::decode(e,text)) {
169 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 169 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
170 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 170 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
171 qDebug("Dropped : " + text); 171 qDebug("Dropped : " + text);
172 QStringList emails = QStringList::split(",",text); 172 QStringList emails = QStringList::split(",",text);
173 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 173 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
174 int pos = (*it).find("<"); 174 int pos = (*it).find("<");
175 QString name = (*it).left(pos); 175 QString name = (*it).left(pos);
176 QString email = (*it).mid(pos); 176 QString email = (*it).mid(pos);
177 if (!email.isEmpty() && todoi) { 177 if (!email.isEmpty() && todoi) {
178 todoi->todo()->addAttendee(new Attendee(name,email)); 178 todoi->todo()->addAttendee(new Attendee(name,email));
179 } 179 }
180 } 180 }
181 } 181 }
182 else { 182 else {
183 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 183 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
184 e->ignore(); 184 e->ignore();
185 } 185 }
186 } 186 }
187#endif 187#endif
188} 188}
189 189
190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
191{ 191{
192#ifndef KORG_NODND 192#ifndef KORG_NODND
193 QPoint p(contentsToViewport(e->pos())); 193 QPoint p(contentsToViewport(e->pos()));
194 QListViewItem *i = itemAt(p); 194 QListViewItem *i = itemAt(p);
195 mMousePressed = false; 195 mMousePressed = false;
196 if (i) { 196 if (i) {
197 // if the user clicked into the root decoration of the item, don't 197 // if the user clicked into the root decoration of the item, don't
198 // try to start a drag! 198 // try to start a drag!
199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
201 itemMargin() || 201 itemMargin() ||
202 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 202 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
203 if (e->button()==Qt::LeftButton) { 203 if (e->button()==Qt::LeftButton) {
204 mPressPos = e->pos(); 204 mPressPos = e->pos();
205 mMousePressed = true; 205 mMousePressed = true;
206 } 206 }
207 } 207 }
208 } 208 }
209#endif 209#endif
210 QListView::contentsMousePressEvent(e); 210 QListView::contentsMousePressEvent(e);
211} 211}
212 212
213void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 213void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
214{ 214{
215 215
216#ifndef KORG_NODND 216#ifndef KORG_NODND
217 QListView::contentsMouseMoveEvent(e); 217 QListView::contentsMouseMoveEvent(e);
218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
219 QApplication::startDragDistance()) { 219 QApplication::startDragDistance()) {
220 mMousePressed = false; 220 mMousePressed = false;
221 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 221 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
222 if (item) { 222 if (item) {
223 DndFactory factory( mCalendar ); 223 DndFactory factory( mCalendar );
224 ICalDrag *vd = factory.createDrag( 224 ICalDrag *vd = factory.createDrag(
225 ((KOTodoViewItem *)item)->todo(),viewport()); 225 ((KOTodoViewItem *)item)->todo(),viewport());
226 internalDrop = false; 226 internalDrop = false;
227 // we cannot do any senseful here, because the DnD is still broken in Qt 227 // we cannot do any senseful here, because the DnD is still broken in Qt
228 if (vd->drag()) { 228 if (vd->drag()) {
229 if ( !internalDrop ) { 229 if ( !internalDrop ) {
230 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 230 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
231 qDebug("Dnd: External move: Delete drag source "); 231 qDebug("Dnd: External move: Delete drag source ");
232 } else 232 } else
233 qDebug("Dnd: Internal move "); 233 qDebug("Dnd: Internal move ");
234 234
235 } else { 235 } else {
236 if ( !internalDrop ) { 236 if ( !internalDrop ) {
237 qDebug("Dnd: External Copy"); 237 qDebug("Dnd: External Copy");
238 } else 238 } else
239 qDebug("DnD: Internal copy: Copy pending"); 239 qDebug("DnD: Internal copy: Copy pending");
240 } 240 }
241 } 241 }
242 } 242 }
243#endif 243#endif
244} 244}
245void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 245void KOTodoListView::keyPressEvent ( QKeyEvent * e )
246{ 246{
247 247
248 QListViewItem* cn; 248 QListViewItem* cn;
249 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 249 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
250 cn = currentItem(); 250 cn = currentItem();
251 if ( cn ) { 251 if ( cn ) {
252 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 252 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
253 if ( ci ){ 253 if ( ci ){
254 if ( e->state() == ShiftButton ) 254 if ( e->state() == ShiftButton )
255 ci->setOn( false ); 255 ci->setOn( false );
256 else 256 else
257 ci->setOn( true ); 257 ci->setOn( true );
258 cn = cn->nextSibling(); 258 cn = cn->itemBelow();
259 if ( cn ) { 259 if ( cn ) {
260 setCurrentItem ( cn ); 260 setCurrentItem ( cn );
261 ensureItemVisible ( cn ); 261 ensureItemVisible ( cn );
262 } 262 }
263 263
264 } 264 }
265 } 265 }
266 266
267 return; 267 return;
268 } 268 }
269 269
270 // qDebug("KOTodoListView::keyPressEvent "); 270 // qDebug("KOTodoListView::keyPressEvent ");
271 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 271 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
272 switch ( e->key() ) { 272 switch ( e->key() ) {
273 case Qt::Key_Down: 273 case Qt::Key_Down:
274 case Qt::Key_Up: 274 case Qt::Key_Up:
275 QListView::keyPressEvent ( e ); 275 QListView::keyPressEvent ( e );
276 break; 276 break;
277 case Qt::Key_Left: 277 case Qt::Key_Left:
278 case Qt::Key_Right: 278 case Qt::Key_Right:
279 QListView::keyPressEvent ( e ); 279 QListView::keyPressEvent ( e );
280 e->accept(); 280 e->accept();
281 return; 281 return;
282 break; 282 break;
283 default: 283 default:
284 e->ignore(); 284 e->ignore();
285 break; 285 break;
286 } 286 }
287 return; 287 return;
288 } 288 }
289 e->ignore(); 289 e->ignore();
290} 290}
291void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 291void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
292{ 292{
293 QListView::contentsMouseReleaseEvent(e); 293 QListView::contentsMouseReleaseEvent(e);
294 mMousePressed = false; 294 mMousePressed = false;
295} 295}
296 296
297void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 297void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
298{ 298{
299 if (!e) return; 299 if (!e) return;
300 300
301 QPoint vp = contentsToViewport(e->pos()); 301 QPoint vp = contentsToViewport(e->pos());
302 302
303 QListViewItem *item = itemAt(vp); 303 QListViewItem *item = itemAt(vp);
304 304
305 emit double_Clicked(item); 305 emit double_Clicked(item);
306 if (!item) return; 306 if (!item) return;
307 307
308 emit doubleClicked(item,vp,0); 308 emit doubleClicked(item,vp,0);
309} 309}
310 310
311///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
312 312
313KOQuickTodo::KOQuickTodo(QWidget *parent) : 313KOQuickTodo::KOQuickTodo(QWidget *parent) :
314 QLineEdit(parent) 314 QLineEdit(parent)
315{ 315{
316 setText(i18n("Click to add a new Todo")); 316 setText(i18n("Click to add a new Todo"));
317} 317}
318 318
319void KOQuickTodo::focusInEvent(QFocusEvent *ev) 319void KOQuickTodo::focusInEvent(QFocusEvent *ev)
320{ 320{
321 if ( text()==i18n("Click to add a new Todo") ) 321 if ( text()==i18n("Click to add a new Todo") )
322 setText(""); 322 setText("");
323 QLineEdit::focusInEvent(ev); 323 QLineEdit::focusInEvent(ev);
324} 324}
325 325
326void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 326void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
327{ 327{
328 setText(i18n("Click to add a new Todo")); 328 setText(i18n("Click to add a new Todo"));
329 QLineEdit::focusOutEvent(ev); 329 QLineEdit::focusOutEvent(ev);
330} 330}
331 331
332///////////////////////////////////////////////////////////////////////////// 332/////////////////////////////////////////////////////////////////////////////
333 333
334KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 334KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
335 KOrg::BaseView(calendar,parent,name) 335 KOrg::BaseView(calendar,parent,name)
336{ 336{
337 isFlatDisplay = false; 337 isFlatDisplay = false;
338 mNavigator = 0; 338 mNavigator = 0;
339 QBoxLayout *topLayout = new QVBoxLayout(this); 339 QBoxLayout *topLayout = new QVBoxLayout(this);
340 mName = QString ( name ); 340 mName = QString ( name );
341 mBlockUpdate = false; 341 mBlockUpdate = false;
342 mQuickAdd = new KOQuickTodo(this); 342 mQuickAdd = new KOQuickTodo(this);
343 topLayout->addWidget(mQuickAdd); 343 topLayout->addWidget(mQuickAdd);
344 344
345 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 345 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
346 346
347 mTodoListView = new KOTodoListView(calendar,this, name ); 347 mTodoListView = new KOTodoListView(calendar,this, name );
348 topLayout->addWidget(mTodoListView); 348 topLayout->addWidget(mTodoListView);
349 //mTodoListView->header()->setMaximumHeight(30); 349 //mTodoListView->header()->setMaximumHeight(30);
350 mTodoListView->setRootIsDecorated(true); 350 mTodoListView->setRootIsDecorated(true);
351 mTodoListView->setAllColumnsShowFocus(true); 351 mTodoListView->setAllColumnsShowFocus(true);
352 352
353 mTodoListView->setShowSortIndicator(true); 353 mTodoListView->setShowSortIndicator(true);
354 354
355 mTodoListView->addColumn(i18n("Todo")); 355 mTodoListView->addColumn(i18n("Todo"));
356 mTodoListView->addColumn(i18n("Prio")); 356 mTodoListView->addColumn(i18n("Prio"));
357 mTodoListView->setColumnAlignment(1,AlignHCenter); 357 mTodoListView->setColumnAlignment(1,AlignHCenter);
358 mTodoListView->addColumn(i18n("Complete")); 358 mTodoListView->addColumn(i18n("Complete"));
359 mTodoListView->setColumnAlignment(2,AlignCenter); 359 mTodoListView->setColumnAlignment(2,AlignCenter);
360 360
361 mTodoListView->addColumn(i18n("Due Date")); 361 mTodoListView->addColumn(i18n("Due Date"));
362 mTodoListView->setColumnAlignment(3,AlignLeft); 362 mTodoListView->setColumnAlignment(3,AlignLeft);
363 mTodoListView->addColumn(i18n("Due Time")); 363 mTodoListView->addColumn(i18n("Due Time"));
364 mTodoListView->setColumnAlignment(4,AlignHCenter); 364 mTodoListView->setColumnAlignment(4,AlignHCenter);
365 365
366 mTodoListView->addColumn(i18n("Start Date")); 366 mTodoListView->addColumn(i18n("Start Date"));
367 mTodoListView->setColumnAlignment(5,AlignLeft); 367 mTodoListView->setColumnAlignment(5,AlignLeft);
368 mTodoListView->addColumn(i18n("Start Time")); 368 mTodoListView->addColumn(i18n("Start Time"));
369 mTodoListView->setColumnAlignment(6,AlignHCenter); 369 mTodoListView->setColumnAlignment(6,AlignHCenter);
370 370
371 mTodoListView->addColumn(i18n("Cancelled")); 371 mTodoListView->addColumn(i18n("Cancelled"));
372 mTodoListView->addColumn(i18n("Categories")); 372 mTodoListView->addColumn(i18n("Categories"));
373#if 0 373#if 0
374 mTodoListView->addColumn(i18n("Sort Id")); 374 mTodoListView->addColumn(i18n("Sort Id"));
375 mTodoListView->setColumnAlignment(4,AlignHCenter); 375 mTodoListView->setColumnAlignment(4,AlignHCenter);
376#endif 376#endif
377 377
378 mTodoListView->setMinimumHeight( 60 ); 378 mTodoListView->setMinimumHeight( 60 );
379 mTodoListView->setItemsRenameable( true ); 379 mTodoListView->setItemsRenameable( true );
380 mTodoListView->setRenameable( 0 ); 380 mTodoListView->setRenameable( 0 );
381 mTodoListView->setColumnWidth( 0, 120 ); 381 mTodoListView->setColumnWidth( 0, 120 );
382 mTodoListView->setColumnWidthMode(0, QListView::Manual); 382 mTodoListView->setColumnWidthMode(0, QListView::Manual);
383 mTodoListView->setColumnWidthMode(1, QListView::Manual); 383 mTodoListView->setColumnWidthMode(1, QListView::Manual);
384 mTodoListView->setColumnWidthMode(2, QListView::Manual); 384 mTodoListView->setColumnWidthMode(2, QListView::Manual);
385 mTodoListView->setColumnWidthMode(3, QListView::Manual); 385 mTodoListView->setColumnWidthMode(3, QListView::Manual);
386 mTodoListView->setColumnWidthMode(4, QListView::Manual); 386 mTodoListView->setColumnWidthMode(4, QListView::Manual);
387 mTodoListView->setColumnWidthMode(5, QListView::Manual); 387 mTodoListView->setColumnWidthMode(5, QListView::Manual);
388 mTodoListView->setColumnWidthMode(6, QListView::Manual); 388 mTodoListView->setColumnWidthMode(6, QListView::Manual);
389 mTodoListView->setColumnWidthMode(7, QListView::Manual); 389 mTodoListView->setColumnWidthMode(7, QListView::Manual);
390 mTodoListView->setColumnWidthMode(8, QListView::Manual); 390 mTodoListView->setColumnWidthMode(8, QListView::Manual);
391 391
392 392
393 mPriorityPopupMenu = new QPopupMenu(this); 393 mPriorityPopupMenu = new QPopupMenu(this);
394 for (int i = 1; i <= 5; i++) { 394 for (int i = 1; i <= 5; i++) {
395 QString label = QString ("%1").arg (i); 395 QString label = QString ("%1").arg (i);
396 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 396 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
397 } 397 }
398 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 398 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
399 399
400 mPercentageCompletedPopupMenu = new QPopupMenu(this); 400 mPercentageCompletedPopupMenu = new QPopupMenu(this);
401 for (int i = 0; i <= 100; i+=20) { 401 for (int i = 0; i <= 100; i+=20) {
402 QString label = QString ("%1 %").arg (i); 402 QString label = QString ("%1 %").arg (i);
403 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 403 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
404 } 404 }
405 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 405 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
406 406
407 407
408 408
409 mItemPopupMenu = new QPopupMenu(this); 409 mItemPopupMenu = new QPopupMenu(this);
410 mItemPopupMenu->insertItem(i18n("Show..."), this, 410 mItemPopupMenu->insertItem(i18n("Show..."), this,
411 SLOT (showTodo())); 411 SLOT (showTodo()));
412 mItemPopupMenu->insertItem(i18n("Edit..."), this, 412 mItemPopupMenu->insertItem(i18n("Edit..."), this,
413 SLOT (editTodo())); 413 SLOT (editTodo()));
414 mItemPopupMenu->insertItem( i18n("Delete"), this, 414 mItemPopupMenu->insertItem( i18n("Delete"), this,
415 SLOT (deleteTodo())); 415 SLOT (deleteTodo()));
416 mItemPopupMenu->insertItem( i18n("Clone..."), this, 416 mItemPopupMenu->insertItem( i18n("Clone..."), this,
417 SLOT (cloneTodo())); 417 SLOT (cloneTodo()));
418 mItemPopupMenu->insertItem( i18n("Move..."), this, 418 mItemPopupMenu->insertItem( i18n("Move..."), this,
419 SLOT (moveTodo())); 419 SLOT (moveTodo()));
420 mItemPopupMenu->insertItem( i18n("Beam..."), this, 420 mItemPopupMenu->insertItem( i18n("Beam..."), this,
421 SLOT (beamTodo())); 421 SLOT (beamTodo()));
422 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 422 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
423 SLOT (cancelTodo())); 423 SLOT (cancelTodo()));
424 mItemPopupMenu->insertSeparator(); 424 mItemPopupMenu->insertSeparator();
425 425
426 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 426 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
427 SLOT (newTodo())); 427 SLOT (newTodo()));
428 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 428 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
429 SLOT (newSubTodo())); 429 SLOT (newSubTodo()));
430 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 430 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
431 SLOT (unparentTodo()),0,21); 431 SLOT (unparentTodo()),0,21);
432 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 432 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
433 SLOT (reparentTodo()),0,22); 433 SLOT (reparentTodo()),0,22);
434 mItemPopupMenu->insertSeparator(); 434 mItemPopupMenu->insertSeparator();
435#if 0 435#if 0
436 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 436 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
437 this, SLOT( purgeCompleted() ) ); 437 this, SLOT( purgeCompleted() ) );
438 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 438 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
439 this, SLOT( toggleCompleted() ),0, 33 ); 439 this, SLOT( toggleCompleted() ),0, 33 );
440 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 440 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
441 this, SLOT( toggleQuickTodo() ),0, 34 ); 441 this, SLOT( toggleQuickTodo() ),0, 34 );
442 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 442 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
443 this, SLOT( toggleRunning() ),0, 35 ); 443 this, SLOT( toggleRunning() ),0, 35 );
444 444
445#endif 445#endif
446 mPopupMenu = new QPopupMenu(this); 446 mPopupMenu = new QPopupMenu(this);
447 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 447 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
448 SLOT (newTodo()),0,1); 448 SLOT (newTodo()),0,1);
449 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 449 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
450 this, SLOT(purgeCompleted()),0,2); 450 this, SLOT(purgeCompleted()),0,2);
451 mPopupMenu->insertItem(i18n("Show Completed"), 451 mPopupMenu->insertItem(i18n("Show Completed"),
452 this, SLOT( toggleCompleted() ),0,3 ); 452 this, SLOT( toggleCompleted() ),0,3 );
453 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 453 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
454 this, SLOT( toggleQuickTodo() ),0,4 ); 454 this, SLOT( toggleQuickTodo() ),0,4 );
455 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 455 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
456 this, SLOT( toggleRunning() ),0,5 ); 456 this, SLOT( toggleRunning() ),0,5 );
457 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 457 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
458 this, SLOT( setAllOpen() ),0,6 ); 458 this, SLOT( setAllOpen() ),0,6 );
459 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 459 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
460 this, SLOT( setAllClose() ),0,7 ); 460 this, SLOT( setAllClose() ),0,7 );
461 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 461 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
462 this, SLOT( setAllFlat() ),0,8 ); 462 this, SLOT( setAllFlat() ),0,8 );
463 mDocPrefs = new DocPrefs( name ); 463 mDocPrefs = new DocPrefs( name );
464 464
465 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 465 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
466 mPopupMenu->setCheckable( true ); 466 mPopupMenu->setCheckable( true );
467 mItemPopupMenu->setCheckable( true ); 467 mItemPopupMenu->setCheckable( true );
468 468
469 469
470 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 470 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
471 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 471 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
472 472
473 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 473 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
474 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 474 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
475 475
476 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 476 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
477 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 477 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
478 478
479 479
480 // Double clicking conflicts with opening/closing the subtree 480 // Double clicking conflicts with opening/closing the subtree
481 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 481 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
482 SLOT( editItem( QListViewItem *) ) ); 482 SLOT( editItem( QListViewItem *) ) );
483 /* 483 /*
484 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 484 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
485 const QPoint &,int ) ), 485 const QPoint &,int ) ),
486 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 486 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
487 */ 487 */
488 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 488 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
489 const QPoint &,int ) ), 489 const QPoint &,int ) ),
490 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 490 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
491 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 491 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
492 SLOT( itemClicked( QListViewItem * ) ) ); 492 SLOT( itemClicked( QListViewItem * ) ) );
493 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 493 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
494 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 494 SLOT( itemDoubleClicked( QListViewItem * ) ) );
495 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 495 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
496 SLOT( updateView() ) ); 496 SLOT( updateView() ) );
497 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 497 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
498 SLOT( todoModified(Todo *, int) ) ); 498 SLOT( todoModified(Todo *, int) ) );
499 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 499 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
500 SLOT( itemStateChanged( QListViewItem * ) ) ); 500 SLOT( itemStateChanged( QListViewItem * ) ) );
501 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 501 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
502 SLOT( itemStateChanged( QListViewItem * ) ) ); 502 SLOT( itemStateChanged( QListViewItem * ) ) );
503 503
504#if 0 504#if 0
505 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 505 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
506 SLOT(selectionChanged(QListViewItem *))); 506 SLOT(selectionChanged(QListViewItem *)));
507 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 507 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
508 SLOT(selectionChanged(QListViewItem *))); 508 SLOT(selectionChanged(QListViewItem *)));
509 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 509 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
510 SLOT(selectionChanged(QListViewItem *))); 510 SLOT(selectionChanged(QListViewItem *)));
511#endif 511#endif
512 512
513 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 513 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
514 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 514 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
515 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 515 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
516 516
517 connect( mTodoListView, SIGNAL(selectionChanged() ), 517 connect( mTodoListView, SIGNAL(selectionChanged() ),
518 SLOT( processSelectionChange() ) ); 518 SLOT( processSelectionChange() ) );
519 connect( mQuickAdd, SIGNAL( returnPressed () ), 519 connect( mQuickAdd, SIGNAL( returnPressed () ),
520 SLOT( addQuickTodo() ) ); 520 SLOT( addQuickTodo() ) );
521 521
522} 522}
523 523
524KOTodoView::~KOTodoView() 524KOTodoView::~KOTodoView()
525{ 525{
526 delete mDocPrefs; 526 delete mDocPrefs;
527} 527}
528 528
529void KOTodoView::jumpToDate () 529void KOTodoView::jumpToDate ()
530{ 530{
531 // if (mActiveItem) { 531 // if (mActiveItem) {
532// mActiveItem->todo()); 532// mActiveItem->todo());
533// if ( mActiveItem->todo()->hasDueDate() ) 533// if ( mActiveItem->todo()->hasDueDate() )
534// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 534// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
535} 535}
536 536
537void KOTodoView::updateView() 537void KOTodoView::updateView()
538{ 538{
539 pendingSubtodo = 0; 539 pendingSubtodo = 0;
540 if ( mBlockUpdate ) { 540 if ( mBlockUpdate ) {
541 //qDebug("blocked "); 541 //qDebug("blocked ");
542 return; 542 return;
543 } 543 }
544 if ( isFlatDisplay ) { 544 if ( isFlatDisplay ) {
545 setAllFlat(); 545 setAllFlat();
546 return; 546 return;
547 } 547 }
548 //qDebug("update "); 548 //qDebug("update ");
549// kdDebug() << "KOTodoView::updateView()" << endl; 549// kdDebug() << "KOTodoView::updateView()" << endl;
550 QFont fo = KOPrefs::instance()->mTodoViewFont; 550 QFont fo = KOPrefs::instance()->mTodoViewFont;
551 mTodoListView->clear(); 551 mTodoListView->clear();
552 if ( mName == "todolistsmall" ) { 552 if ( mName == "todolistsmall" ) {
553 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 553 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
554 int ps = fo.pointSize() -2; 554 int ps = fo.pointSize() -2;
555 if ( ps > 12 ) 555 if ( ps > 12 )
556 ps -= 2; 556 ps -= 2;
557 fo.setPointSize( ps ); 557 fo.setPointSize( ps );
558 } 558 }
559 } 559 }
560 560
561 mTodoListView->setFont( fo ); 561 mTodoListView->setFont( fo );
562 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 562 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
563 //mTodoListView->header()->setMaximumHeight(fm.height()); 563 //mTodoListView->header()->setMaximumHeight(fm.height());
564 QPtrList<Todo> todoList = calendar()->todos(); 564 QPtrList<Todo> todoList = calendar()->todos();
565 565
566/* 566/*
567 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 567 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
568 Event *t; 568 Event *t;
569 for(t = todoList.first(); t; t = todoList.next()) { 569 for(t = todoList.first(); t; t = todoList.next()) {
570 kdDebug() << " " << t->getSummary() << endl; 570 kdDebug() << " " << t->getSummary() << endl;
571 571
572 if (t->getRelatedTo()) { 572 if (t->getRelatedTo()) {
573 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 573 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
574 } 574 }
575 575
576 QPtrList<Event> l = t->getRelations(); 576 QPtrList<Event> l = t->getRelations();
577 Event *c; 577 Event *c;
578 for(c=l.first();c;c=l.next()) { 578 for(c=l.first();c;c=l.next()) {
579 kdDebug() << " - relation: " << c->getSummary() << endl; 579 kdDebug() << " - relation: " << c->getSummary() << endl;
580 } 580 }
581 } 581 }
582*/ 582*/
583 583
584 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 584 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
585 // specific order of events. That means that we have to generate parent items 585 // specific order of events. That means that we have to generate parent items
586 // recursively for proper hierarchical display of Todos. 586 // recursively for proper hierarchical display of Todos.
587 mTodoMap.clear(); 587 mTodoMap.clear();
588 Todo *todo; 588 Todo *todo;
589 todo = todoList.first();// todo; todo = todoList.next()) { 589 todo = todoList.first();// todo; todo = todoList.next()) {
590 while ( todo ) { 590 while ( todo ) {
591 bool next = true; 591 bool next = true;
592 // qDebug("todo %s ", todo->summary().latin1()); 592 // qDebug("todo %s ", todo->summary().latin1());
593 Incidence *incidence = todo->relatedTo(); 593 Incidence *incidence = todo->relatedTo();
594 while ( incidence ) { 594 while ( incidence ) {
595 if ( incidence->type() == "Todo") { 595 if ( incidence->type() == "Todo") {
596 //qDebug("related %s ",incidence->summary().latin1() ); 596 //qDebug("related %s ",incidence->summary().latin1() );
597 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 597 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
598 //qDebug("related not found "); 598 //qDebug("related not found ");
599 todoList.remove( ); 599 todoList.remove( );
600 todo = todoList.current(); 600 todo = todoList.current();
601 next = false; 601 next = false;
602 incidence = 0; 602 incidence = 0;
603 603
604 } else { 604 } else {
605 //qDebug("related found "); 605 //qDebug("related found ");
606 incidence = incidence->relatedTo(); 606 incidence = incidence->relatedTo();
607 } 607 }
608 } else 608 } else
609 incidence = 0; 609 incidence = 0;
610 } 610 }
611 if ( next ) 611 if ( next )
612 todo = todoList.next(); 612 todo = todoList.next();
613 } 613 }
614// qDebug("again .... "); 614// qDebug("again .... ");
615// for(todo = todoList.first(); todo; todo = todoList.next()) { 615// for(todo = todoList.first(); todo; todo = todoList.next()) {
616 616
617// qDebug("yytodo %s ", todo->summary().latin1()); 617// qDebug("yytodo %s ", todo->summary().latin1());
618// } 618// }
619 //qDebug("for "); 619 //qDebug("for ");
620 for(todo = todoList.first(); todo; todo = todoList.next()) { 620 for(todo = todoList.first(); todo; todo = todoList.next()) {
621 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 621 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
622 { 622 {
623 insertTodoItem(todo); 623 insertTodoItem(todo);
624 } 624 }
625 } 625 }
626 //qDebug("for end "); 626 //qDebug("for end ");
627 // Restore opened/closed state 627 // Restore opened/closed state
628 mTodoListView->blockSignals( true ); 628 mTodoListView->blockSignals( true );
629 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 629 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
630 mTodoListView->blockSignals( false ); 630 mTodoListView->blockSignals( false );
631 mTodoListView->setFocus(); 631 mTodoListView->setFocus();
632 processSelectionChange(); 632 processSelectionChange();
633} 633}
634 634
635bool KOTodoView::checkTodo( Todo * todo ) 635bool KOTodoView::checkTodo( Todo * todo )
636{ 636{
637 637
638 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 638 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
639 return false; 639 return false;
640 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 640 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
641 if ( todo->hasStartDate() ) 641 if ( todo->hasStartDate() )
642 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 642 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
643 return false; 643 return false;
644 if ( todo->hasDueDate() ) 644 if ( todo->hasDueDate() )
645 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 645 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
646 return false; 646 return false;
647 } 647 }
648 return true; 648 return true;
649} 649}
650 650
651void KOTodoView::restoreItemState( QListViewItem *item ) 651void KOTodoView::restoreItemState( QListViewItem *item )
652{ 652{
653 pendingSubtodo = 0; 653 pendingSubtodo = 0;
654 while( item ) { 654 while( item ) {
655 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 655 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
656 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 656 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
657 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 657 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
658 item = item->nextSibling(); 658 item = item->nextSibling();
659 } 659 }
660} 660}
661 661
662 662
663QMap<Todo *,KOTodoViewItem *>::ConstIterator 663QMap<Todo *,KOTodoViewItem *>::ConstIterator
664 KOTodoView::insertTodoItem(Todo *todo) 664 KOTodoView::insertTodoItem(Todo *todo)
665{ 665{
666 666
667// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 667// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
668 // TODO: Check, if dynmaic cast is necessary 668 // TODO: Check, if dynmaic cast is necessary
669 669
670 pendingSubtodo = 0; 670 pendingSubtodo = 0;
671 Incidence *incidence = todo->relatedTo(); 671 Incidence *incidence = todo->relatedTo();
672 if (incidence && incidence->type() == "Todo") { 672 if (incidence && incidence->type() == "Todo") {
673 Todo *relatedTodo = static_cast<Todo *>(incidence); 673 Todo *relatedTodo = static_cast<Todo *>(incidence);
674 674
675// kdDebug() << " has Related" << endl; 675// kdDebug() << " has Related" << endl;
676 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 676 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
677 itemIterator = mTodoMap.find(relatedTodo); 677 itemIterator = mTodoMap.find(relatedTodo);
678 if (itemIterator == mTodoMap.end()) { 678 if (itemIterator == mTodoMap.end()) {
679// kdDebug() << " related not yet in list" << endl; 679// kdDebug() << " related not yet in list" << endl;
680 itemIterator = insertTodoItem (relatedTodo); 680 itemIterator = insertTodoItem (relatedTodo);
681 } 681 }
682 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 682 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
683 // and one into the map. Sure finding is more easy but why? -zecke 683 // and one into the map. Sure finding is more easy but why? -zecke
684 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 684 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
685 return mTodoMap.insert(todo,todoItem); 685 return mTodoMap.insert(todo,todoItem);
686 } else { 686 } else {
687// kdDebug() << " no Related" << endl; 687// kdDebug() << " no Related" << endl;
688 // see above -zecke 688 // see above -zecke
689 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 689 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
690 return mTodoMap.insert(todo,todoItem); 690 return mTodoMap.insert(todo,todoItem);
691 } 691 }
692} 692}
693 693
694 694
695void KOTodoView::updateConfig() 695void KOTodoView::updateConfig()
696{ 696{
697 updateView(); 697 updateView();
698 mTodoListView->repaintContents(); 698 mTodoListView->repaintContents();
699} 699}
700 700
701QPtrList<Incidence> KOTodoView::selectedIncidences() 701QPtrList<Incidence> KOTodoView::selectedIncidences()
702{ 702{
703 QPtrList<Incidence> selected; 703 QPtrList<Incidence> selected;
704 704
705 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 705 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
706// if (!item) item = mActiveItem; 706// if (!item) item = mActiveItem;
707 if (item) selected.append(item->todo()); 707 if (item) selected.append(item->todo());
708 708
709 return selected; 709 return selected;
710} 710}
711 711
712QPtrList<Todo> KOTodoView::selectedTodos() 712QPtrList<Todo> KOTodoView::selectedTodos()
713{ 713{
714 QPtrList<Todo> selected; 714 QPtrList<Todo> selected;
715 715
716 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 716 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
717// if (!item) item = mActiveItem; 717// if (!item) item = mActiveItem;
718 if (item) selected.append(item->todo()); 718 if (item) selected.append(item->todo());
719 719
720 return selected; 720 return selected;
721} 721}
722 722
723void KOTodoView::changeEventDisplay(Event *, int) 723void KOTodoView::changeEventDisplay(Event *, int)
724{ 724{
725 updateView(); 725 updateView();
726} 726}
727 727
728void KOTodoView::showDates(const QDate &, const QDate &) 728void KOTodoView::showDates(const QDate &, const QDate &)
729{ 729{
730} 730}
731 731
732void KOTodoView::showEvents(QPtrList<Event>) 732void KOTodoView::showEvents(QPtrList<Event>)
733{ 733{
734 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 734 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
735} 735}
736 736
737void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 737void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
738 const QDate &td) 738 const QDate &td)
739{ 739{
740#ifndef KORG_NOPRINTER 740#ifndef KORG_NOPRINTER
741 calPrinter->preview(CalPrinter::Todolist, fd, td); 741 calPrinter->preview(CalPrinter::Todolist, fd, td);
742#endif 742#endif
743} 743}
744 744
745void KOTodoView::editItem(QListViewItem *item ) 745void KOTodoView::editItem(QListViewItem *item )
746{ 746{
747 // qDebug("editItem(QListViewItem *item ) "); 747 // qDebug("editItem(QListViewItem *item ) ");
748 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 748 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
749} 749}
750 750
751void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 751void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
752{ 752{
753 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 753 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
754} 754}
755 755
756void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column) 756void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column)
757{ 757{
758 pendingSubtodo = 0; 758 pendingSubtodo = 0;
759 mActiveItem = (KOTodoViewItem *)item; 759 mActiveItem = (KOTodoViewItem *)item;
760 if (item) { 760 if (item) {
761 switch (column){ 761 switch (column){
762 case 1: 762 case 1:
763 mPriorityPopupMenu->popup(QCursor::pos ()); break; 763 mPriorityPopupMenu->popup(QCursor::pos ()); break;
764 case 2: 764 case 2:
765 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 765 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
766 case 3: 766 case 3:
767 moveTodo(); 767 moveTodo();
768 break; 768 break;
769 case 8: 769 case 8:
770 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 770 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
771 default: 771 default:
772 mItemPopupMenu->popup(QCursor::pos()); 772 mItemPopupMenu->popup(QCursor::pos());
773 } 773 }
774 } else mPopupMenu->popup(QCursor::pos()); 774 } else mPopupMenu->popup(QCursor::pos());
775} 775}
776void KOTodoView::newTodo() 776void KOTodoView::newTodo()
777{ 777{
778 emit newTodoSignal(); 778 emit newTodoSignal();
779} 779}
780 780
781void KOTodoView::newSubTodo() 781void KOTodoView::newSubTodo()
782{ 782{
783 if (mActiveItem) { 783 if (mActiveItem) {
784 emit newSubTodoSignal(mActiveItem->todo()); 784 emit newSubTodoSignal(mActiveItem->todo());
785 } 785 }
786} 786}
787void KOTodoView::unparentTodo() 787void KOTodoView::unparentTodo()
788{ 788{
789 if (mActiveItem) { 789 if (mActiveItem) {
790 emit unparentTodoSignal(mActiveItem->todo()); 790 emit unparentTodoSignal(mActiveItem->todo());
791 } 791 }
792} 792}
793 793
794void KOTodoView::reparentTodo() 794void KOTodoView::reparentTodo()
795{ 795{
796 if (mActiveItem) { 796 if (mActiveItem) {
797 qDebug("KOTodoView::reparentTodo() "); 797 qDebug("KOTodoView::reparentTodo() ");
798 topLevelWidget()->setCaption(i18n("Click on new parent item")); 798 topLevelWidget()->setCaption(i18n("Click on new parent item"));
799 pendingSubtodo = mActiveItem; 799 pendingSubtodo = mActiveItem;
800 } 800 }
801} 801}
802void KOTodoView::editTodo() 802void KOTodoView::editTodo()
803{ 803{
804 if (mActiveItem) { 804 if (mActiveItem) {
805 emit editTodoSignal(mActiveItem->todo()); 805 emit editTodoSignal(mActiveItem->todo());
806 } 806 }
807} 807}
808void KOTodoView::cloneTodo() 808void KOTodoView::cloneTodo()
809{ 809{
810 if (mActiveItem) { 810 if (mActiveItem) {
811 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 811 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
812 } 812 }
813} 813}
814void KOTodoView::cancelTodo() 814void KOTodoView::cancelTodo()
815{ 815{
816 if (mActiveItem) { 816 if (mActiveItem) {
817 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 817 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
818 } 818 }
819} 819}
820void KOTodoView::moveTodo() 820void KOTodoView::moveTodo()
821{ 821{
822 if (mActiveItem) { 822 if (mActiveItem) {
823 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 823 emit moveTodoSignal((Incidence*)mActiveItem->todo());
824 } 824 }
825} 825}
826void KOTodoView::beamTodo() 826void KOTodoView::beamTodo()
827{ 827{
828 if (mActiveItem) { 828 if (mActiveItem) {
829 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 829 emit beamTodoSignal((Incidence*)mActiveItem->todo());
830 } 830 }
831} 831}
832 832
833 833
834void KOTodoView::showTodo() 834void KOTodoView::showTodo()
835{ 835{
836 if (mActiveItem) { 836 if (mActiveItem) {
837 emit showTodoSignal(mActiveItem->todo()); 837 emit showTodoSignal(mActiveItem->todo());
838 } 838 }
839} 839}
840 840
841void KOTodoView::deleteTodo() 841void KOTodoView::deleteTodo()
842{ 842{
843 if (mActiveItem) { 843 if (mActiveItem) {
844 emit deleteTodoSignal(mActiveItem->todo()); 844 emit deleteTodoSignal(mActiveItem->todo());
845 } 845 }
846} 846}
847 847
848void KOTodoView::setNewPriority(int index) 848void KOTodoView::setNewPriority(int index)
849{ 849{
850 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 850 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
851 mActiveItem->todo()->setPriority(mPriority[index]); 851 mActiveItem->todo()->setPriority(mPriority[index]);
852 mActiveItem->construct(); 852 mActiveItem->construct();
853 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 853 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
854 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 854 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
855 } 855 }
856} 856}
857 857
858void KOTodoView::setNewPercentage(int index) 858void KOTodoView::setNewPercentage(int index)
859{ 859{
860 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 860 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
861 861
862 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 862 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
863 mActiveItem->setOn( true ); 863 mActiveItem->setOn( true );
864 return; 864 return;
865 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 865 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
866 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 866 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
867 if ( par && par->isOn() ) 867 if ( par && par->isOn() )
868 par->setOn( false ); 868 par->setOn( false );
869 } 869 }
870 if (mPercentage[index] == 100) { 870 if (mPercentage[index] == 100) {
871 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 871 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
872 } else { 872 } else {
873 mActiveItem->todo()->setCompleted(false); 873 mActiveItem->todo()->setCompleted(false);
874 } 874 }
875 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 875 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
876 mActiveItem->construct(); 876 mActiveItem->construct();
877 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 877 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
878 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 878 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
879 } 879 }
880} 880}
881 881
882 882
883QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 883QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
884{ 884{
885 QPopupMenu* tempMenu = new QPopupMenu (this); 885 QPopupMenu* tempMenu = new QPopupMenu (this);
886 QStringList checkedCategories = todoItem->todo()->categories (); 886 QStringList checkedCategories = todoItem->todo()->categories ();
887 887
888 tempMenu->setCheckable (true); 888 tempMenu->setCheckable (true);
889 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 889 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
890 it != KOPrefs::instance()->mCustomCategories.end (); 890 it != KOPrefs::instance()->mCustomCategories.end ();
891 ++it) { 891 ++it) {
892 int index = tempMenu->insertItem (*it); 892 int index = tempMenu->insertItem (*it);
893 mCategory[index] = *it; 893 mCategory[index] = *it;
894 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 894 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
895 } 895 }
896 896
897 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 897 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
898 return tempMenu; 898 return tempMenu;
899 899
900 900
901} 901}
902void KOTodoView::changedCategories(int index) 902void KOTodoView::changedCategories(int index)
903{ 903{
904 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 904 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
905 QStringList categories = mActiveItem->todo()->categories (); 905 QStringList categories = mActiveItem->todo()->categories ();
906 if (categories.find (mCategory[index]) != categories.end ()) 906 if (categories.find (mCategory[index]) != categories.end ())
907 categories.remove (mCategory[index]); 907 categories.remove (mCategory[index]);
908 else 908 else
909 categories.insert (categories.end(), mCategory[index]); 909 categories.insert (categories.end(), mCategory[index]);
910 categories.sort (); 910 categories.sort ();
911 mActiveItem->todo()->setCategories (categories); 911 mActiveItem->todo()->setCategories (categories);
912 mActiveItem->construct(); 912 mActiveItem->construct();
913 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 913 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
914 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 914 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
915 } 915 }
916} 916}
917void KOTodoView::itemDoubleClicked(QListViewItem *item) 917void KOTodoView::itemDoubleClicked(QListViewItem *item)
918{ 918{
919 if ( pendingSubtodo != 0 ) { 919 if ( pendingSubtodo != 0 ) {
920 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 920 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
921 } 921 }
922 pendingSubtodo = 0; 922 pendingSubtodo = 0;
923 if (!item) { 923 if (!item) {
924 newTodo(); 924 newTodo();
925 return; 925 return;
926 } 926 }
927 if ( KOPrefs::instance()->mEditOnDoubleClick ) 927 if ( KOPrefs::instance()->mEditOnDoubleClick )
928 editItem( item ); 928 editItem( item );
929 else 929 else
930 showItem( item , QPoint(), 0 ); 930 showItem( item , QPoint(), 0 );
931} 931}
932void KOTodoView::itemClicked(QListViewItem *item) 932void KOTodoView::itemClicked(QListViewItem *item)
933{ 933{
934 934
935 if (!item) { 935 if (!item) {
936 if ( pendingSubtodo != 0 ) { 936 if ( pendingSubtodo != 0 ) {
937 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 937 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
938 } 938 }
939 pendingSubtodo = 0; 939 pendingSubtodo = 0;
940 return; 940 return;
941 } 941 }
942 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 942 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
943 if ( pendingSubtodo != 0 ) { 943 if ( pendingSubtodo != 0 ) {
944 bool allowReparent = true; 944 bool allowReparent = true;
945 QListViewItem *par = item; 945 QListViewItem *par = item;
946 while ( par ) { 946 while ( par ) {
947 if ( par == pendingSubtodo ) { 947 if ( par == pendingSubtodo ) {
948 allowReparent = false; 948 allowReparent = false;
949 break; 949 break;
950 } 950 }
951 par = par->parent(); 951 par = par->parent();
952 } 952 }
953 if ( !allowReparent ) { 953 if ( !allowReparent ) {
954 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 954 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
955 qDebug("Recursive reparenting not possible "); 955 qDebug("Recursive reparenting not possible ");
956 pendingSubtodo = 0; 956 pendingSubtodo = 0;
957 } else { 957 } else {
958 Todo* newParent = todoItem->todo(); 958 Todo* newParent = todoItem->todo();
959 Todo* newSub = pendingSubtodo->todo(); 959 Todo* newSub = pendingSubtodo->todo();
960 pendingSubtodo = 0; 960 pendingSubtodo = 0;
961 emit reparentTodoSignal( newParent,newSub ); 961 emit reparentTodoSignal( newParent,newSub );
962 return; 962 return;
963 } 963 }
964 } 964 }
965#if 0 965#if 0
966 // handled by the item itself 966 // handled by the item itself
967 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 967 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
968 qDebug("com %d ",completed ); 968 qDebug("com %d ",completed );
969 qDebug("itemclicked "); 969 qDebug("itemclicked ");
970 if (todoItem->isOn()) { 970 if (todoItem->isOn()) {
971 qDebug("on "); 971 qDebug("on ");
972 if (!completed) { 972 if (!completed) {
973 qDebug("set true "); 973 qDebug("set true ");
974 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 974 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
975 } 975 }
976 } else { 976 } else {
977 qDebug("not on "); 977 qDebug("not on ");
978 if (completed) { 978 if (completed) {
979 qDebug("set false "); 979 qDebug("set false ");
980 todoItem->todo()->setCompleted(false); 980 todoItem->todo()->setCompleted(false);
981 } 981 }
982 } 982 }
983#endif 983#endif
984} 984}
985 985
986void KOTodoView::setDocumentId( const QString &id ) 986void KOTodoView::setDocumentId( const QString &id )
987{ 987{
988 kdDebug() << "KOTodoView::setDocumentId()" << endl; 988 kdDebug() << "KOTodoView::setDocumentId()" << endl;
989 989
990 mDocPrefs->setDoc( id ); 990 mDocPrefs->setDoc( id );
991} 991}
992 992
993void KOTodoView::itemStateChanged( QListViewItem *item ) 993void KOTodoView::itemStateChanged( QListViewItem *item )
994{ 994{
995 if (!item) return; 995 if (!item) return;
996 996
997 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 997 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
998 998
999// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 999// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1000 1000
1001 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1001 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1002} 1002}
1003 1003
1004void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1004void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1005{ 1005{
1006 mTodoListView->saveLayout(config,group); 1006 mTodoListView->saveLayout(config,group);
1007} 1007}
1008 1008
1009void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1009void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1010{ 1010{
1011 mTodoListView->restoreLayout(config,group); 1011 mTodoListView->restoreLayout(config,group);
1012} 1012}
1013 1013
1014void KOTodoView::processSelectionChange() 1014void KOTodoView::processSelectionChange()
1015{ 1015{
1016// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1016// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1017 1017
1018 KOTodoViewItem *item = 1018 KOTodoViewItem *item =
1019 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1019 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1020 1020
1021 if ( !item ) { 1021 if ( !item ) {
1022 emit incidenceSelected( 0 ); 1022 emit incidenceSelected( 0 );
1023 } else { 1023 } else {
1024 emit incidenceSelected( item->todo() ); 1024 emit incidenceSelected( item->todo() );
1025 } 1025 }
1026} 1026}
1027 1027
1028void KOTodoView::modified(bool b) 1028void KOTodoView::modified(bool b)
1029{ 1029{
1030 emit isModified(b); 1030 emit isModified(b);
1031} 1031}
1032void KOTodoView::setTodoModified( Todo* todo ) 1032void KOTodoView::setTodoModified( Todo* todo )
1033{ 1033{
1034 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1034 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1035} 1035}
1036void KOTodoView::clearSelection() 1036void KOTodoView::clearSelection()
1037{ 1037{
1038 mTodoListView->selectAll( false ); 1038 mTodoListView->selectAll( false );
1039} 1039}
1040void KOTodoView::setAllOpen() 1040void KOTodoView::setAllOpen()
1041{ 1041{
1042 if ( isFlatDisplay ) { 1042 if ( isFlatDisplay ) {
1043 isFlatDisplay = false; 1043 isFlatDisplay = false;
1044 mPopupMenu->setItemChecked( 8,false ); 1044 mPopupMenu->setItemChecked( 8,false );
1045 updateView(); 1045 updateView();
1046 } 1046 }
1047 setOpen(mTodoListView->firstChild(), true); 1047 setOpen(mTodoListView->firstChild(), true);
1048} 1048}
1049void KOTodoView::setAllClose() 1049void KOTodoView::setAllClose()
1050{ 1050{
1051 if ( isFlatDisplay ) { 1051 if ( isFlatDisplay ) {
1052 isFlatDisplay = false; 1052 isFlatDisplay = false;
1053 mPopupMenu->setItemChecked( 8,false ); 1053 mPopupMenu->setItemChecked( 8,false );
1054 updateView(); 1054 updateView();
1055 } 1055 }
1056 setOpen(mTodoListView->firstChild(), false); 1056 setOpen(mTodoListView->firstChild(), false);
1057} 1057}
1058void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1058void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1059{ 1059{
1060 1060
1061 while ( item ) { 1061 while ( item ) {
1062 setOpen( item->firstChild(), setOpenI ); 1062 setOpen( item->firstChild(), setOpenI );
1063 item->setOpen( setOpenI ); 1063 item->setOpen( setOpenI );
1064 item = item->nextSibling(); 1064 item = item->nextSibling();
1065 } 1065 }
1066} 1066}
1067 1067
1068void KOTodoView::setAllFlat() 1068void KOTodoView::setAllFlat()
1069{ 1069{
1070 if ( isFlatDisplay ) { 1070 if ( isFlatDisplay ) {
1071 isFlatDisplay = false; 1071 isFlatDisplay = false;
1072 mPopupMenu->setItemChecked( 8,false ); 1072 mPopupMenu->setItemChecked( 8,false );
1073 updateView(); 1073 updateView();
1074 return; 1074 return;
1075 } 1075 }
1076 pendingSubtodo = 0; 1076 pendingSubtodo = 0;
1077 if ( mBlockUpdate ) { 1077 if ( mBlockUpdate ) {
1078 return; 1078 return;
1079 } 1079 }
1080 mPopupMenu->setItemChecked( 8,true ); 1080 mPopupMenu->setItemChecked( 8,true );
1081 isFlatDisplay = true; 1081 isFlatDisplay = true;
1082 QPtrList<Todo> todoList = calendar()->todos(); 1082 QPtrList<Todo> todoList = calendar()->todos();
1083 mTodoMap.clear(); 1083 mTodoMap.clear();
1084 mTodoListView->clear(); 1084 mTodoListView->clear();
1085 Todo *todo; 1085 Todo *todo;
1086 for(todo = todoList.first(); todo; todo = todoList.next()) { 1086 for(todo = todoList.first(); todo; todo = todoList.next()) {
1087 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1087 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1088 mTodoMap.insert(todo,todoItem); 1088 mTodoMap.insert(todo,todoItem);
1089 } 1089 }
1090 mTodoListView->setFocus(); 1090 mTodoListView->setFocus();
1091 processSelectionChange(); 1091 processSelectionChange();
1092} 1092}
1093 1093
1094void KOTodoView::purgeCompleted() 1094void KOTodoView::purgeCompleted()
1095{ 1095{
1096 emit purgeCompletedSignal(); 1096 emit purgeCompletedSignal();
1097} 1097}
1098void KOTodoView::toggleQuickTodo() 1098void KOTodoView::toggleQuickTodo()
1099{ 1099{
1100 if ( mQuickAdd->isVisible() ) { 1100 if ( mQuickAdd->isVisible() ) {
1101 mQuickAdd->hide(); 1101 mQuickAdd->hide();
1102 KOPrefs::instance()->mEnableQuickTodo = false; 1102 KOPrefs::instance()->mEnableQuickTodo = false;
1103 } 1103 }
1104 else { 1104 else {
1105 mQuickAdd->show(); 1105 mQuickAdd->show();
1106 KOPrefs::instance()->mEnableQuickTodo = true; 1106 KOPrefs::instance()->mEnableQuickTodo = true;
1107 } 1107 }
1108 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1108 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1109 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1109 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1110} 1110}
1111 1111
1112void KOTodoView::toggleRunning() 1112void KOTodoView::toggleRunning()
1113{ 1113{
1114 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1114 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1115 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1115 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1116 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1116 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1117 updateView(); 1117 updateView();
1118} 1118}
1119 1119
1120void KOTodoView::toggleCompleted() 1120void KOTodoView::toggleCompleted()
1121{ 1121{
1122 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1122 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1123 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1123 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1124 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1124 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1125 updateView(); 1125 updateView();
1126} 1126}
1127 1127
1128void KOTodoView::addQuickTodo() 1128void KOTodoView::addQuickTodo()
1129{ 1129{
1130 Todo *todo = new Todo(); 1130 Todo *todo = new Todo();
1131 todo->setSummary(mQuickAdd->text()); 1131 todo->setSummary(mQuickAdd->text());
1132 todo->setOrganizer(KOPrefs::instance()->email()); 1132 todo->setOrganizer(KOPrefs::instance()->email());
1133 CalFilter * cf = mCalendar->filter(); 1133 CalFilter * cf = mCalendar->filter();
1134 if ( cf ) { 1134 if ( cf ) {
1135 if ( cf->isEnabled()&& cf->showCategories()) { 1135 if ( cf->isEnabled()&& cf->showCategories()) {
1136 todo->setCategories(cf->categoryList()); 1136 todo->setCategories(cf->categoryList());
1137 } 1137 }
1138 if ( cf->isEnabled() ) 1138 if ( cf->isEnabled() )
1139 todo->setSecrecy( cf->getSecrecy()); 1139 todo->setSecrecy( cf->getSecrecy());
1140 } 1140 }
1141 mCalendar->addTodo(todo); 1141 mCalendar->addTodo(todo);
1142 mQuickAdd->setText(""); 1142 mQuickAdd->setText("");
1143 todoModified (todo, KOGlobals::EVENTADDED ); 1143 todoModified (todo, KOGlobals::EVENTADDED );
1144 updateView(); 1144 updateView();
1145} 1145}
1146void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1146void KOTodoView::keyPressEvent ( QKeyEvent * e )
1147{ 1147{
1148 // e->ignore(); 1148 // e->ignore();
1149 //return; 1149 //return;
1150 //qDebug("KOTodoView::keyPressEvent "); 1150 //qDebug("KOTodoView::keyPressEvent ");
1151 switch ( e->key() ) { 1151 switch ( e->key() ) {
1152 case Qt::Key_Down: 1152 case Qt::Key_Down:
1153 case Qt::Key_Up: 1153 case Qt::Key_Up:
1154 QWidget::keyPressEvent ( e ); 1154 QWidget::keyPressEvent ( e );
1155 break; 1155 break;
1156 1156
1157 case Qt::Key_Q: 1157 case Qt::Key_Q:
1158 toggleQuickTodo(); 1158 toggleQuickTodo();
1159 break; 1159 break;
1160 case Qt::Key_U: 1160 case Qt::Key_U:
1161 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1161 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1162 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1162 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1163 unparentTodo(); 1163 unparentTodo();
1164 e->accept(); 1164 e->accept();
1165 } else 1165 } else
1166 e->ignore(); 1166 e->ignore();
1167 break; 1167 break;
1168 case Qt::Key_S: 1168 case Qt::Key_S:
1169 if ( e->state() == Qt::ControlButton ) { 1169 if ( e->state() == Qt::ControlButton ) {
1170 e->ignore(); 1170 e->ignore();
1171 break; 1171 break;
1172 } 1172 }
1173 if ( e->state() == Qt::ShiftButton ) { 1173 if ( e->state() == Qt::ShiftButton ) {
1174 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1174 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1175 reparentTodo(); 1175 reparentTodo();
1176 e->accept(); 1176 e->accept();
1177 } else 1177 } else
1178 e->ignore(); 1178 e->ignore();
1179 break; 1179 break;
1180 case Qt::Key_P: 1180 case Qt::Key_P:
1181 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1181 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1182 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1182 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1183 if ( pendingSubtodo ) 1183 if ( pendingSubtodo )
1184 itemClicked(mActiveItem); 1184 itemClicked(mActiveItem);
1185 e->accept(); 1185 e->accept();
1186 } else 1186 } else
1187 e->ignore(); 1187 e->ignore();
1188 break; 1188 break;
1189 case Qt::Key_Escape: 1189 case Qt::Key_Escape:
1190 if ( pendingSubtodo ) { 1190 if ( pendingSubtodo ) {
1191 itemClicked(0); 1191 itemClicked(0);
1192 e->accept(); 1192 e->accept();
1193 } else 1193 } else
1194 e->ignore(); 1194 e->ignore();
1195 break; 1195 break;
1196 default: 1196 default:
1197 e->ignore(); 1197 e->ignore();
1198 } 1198 }
1199 1199
1200 if ( true ) { 1200 if ( true ) {
1201 if ( e->key() == Qt::Key_I ) { 1201 if ( e->key() == Qt::Key_I ) {
1202 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1202 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1203 if ( cn ) { 1203 if ( cn ) {
1204 mActiveItem = cn; 1204 mActiveItem = cn;
1205 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1205 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1206 if ( ci ){ 1206 if ( ci ){
1207 showTodo(); 1207 showTodo();
1208 cn = (KOTodoViewItem*)cn->itemBelow(); 1208 cn = (KOTodoViewItem*)cn->itemBelow();
1209 if ( cn ) { 1209 if ( cn ) {
1210 mTodoListView->setCurrentItem ( cn ); 1210 mTodoListView->setCurrentItem ( cn );
1211 mTodoListView->ensureItemVisible ( cn ); 1211 mTodoListView->ensureItemVisible ( cn );
1212 } 1212 }
1213 1213
1214 } 1214 }
1215 } 1215 }
1216 e->accept(); 1216 e->accept();
1217 1217
1218 } 1218 }
1219 1219
1220 } 1220 }
1221 1221
1222} 1222}
1223void KOTodoView::updateTodo( Todo * t, int type ) 1223void KOTodoView::updateTodo( Todo * t, int type )
1224{ 1224{
1225 if ( mBlockUpdate) 1225 if ( mBlockUpdate)
1226 return; 1226 return;
1227 1227
1228 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1228 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1229 itemIterator = mTodoMap.find(t); 1229 itemIterator = mTodoMap.find(t);
1230 if (itemIterator != mTodoMap.end()) { 1230 if (itemIterator != mTodoMap.end()) {
1231 (*itemIterator)->construct(); 1231 (*itemIterator)->construct();
1232 } else { 1232 } else {
1233 if ( type == KOGlobals::EVENTADDED ) { 1233 if ( type == KOGlobals::EVENTADDED ) {
1234 insertTodoItem( t ); 1234 insertTodoItem( t );
1235 } 1235 }
1236 } 1236 }
1237 1237
1238} 1238}
1239 1239
1240void KOTodoView::todoModified(Todo * t , int p ) 1240void KOTodoView::todoModified(Todo * t , int p )
1241{ 1241{
1242 mBlockUpdate = true; 1242 mBlockUpdate = true;
1243 emit todoModifiedSignal ( t, p ); 1243 emit todoModifiedSignal ( t, p );
1244 mBlockUpdate = false; 1244 mBlockUpdate = false;
1245} 1245}