00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qlayout.h>
00026 #include <qheader.h>
00027 #include <qcursor.h>
00028
00029 #include <kdebug.h>
00030 #include <klocale.h>
00031 #include <kglobal.h>
00032 #include <kiconloader.h>
00033 #include <kmessagebox.h>
00034
00035 #include <libkcal/icaldrag.h>
00036 #include <libkcal/vcaldrag.h>
00037 #include <libkcal/dndfactory.h>
00038 #include <libkcal/calendarresources.h>
00039 #include <libkcal/resourcecalendar.h>
00040
00041 #ifndef KORG_NOPRINTER
00042 #include "calprinter.h"
00043 #endif
00044 #include "docprefs.h"
00045
00046 #include "koincidencetooltip.h"
00047 #include "kodialogmanager.h"
00048 #include "kotodoview.h"
00049 #include "koglobals.h"
00050 using namespace KOrg;
00051 #include "kotodoview.moc"
00052
00053 const int KOTodoView::POPUP_UNSUBTODO=1234;
00054
00055 KOTodoListViewToolTip::KOTodoListViewToolTip (QWidget* parent,
00056 KOTodoListView* lv )
00057 :QToolTip(parent)
00058 {
00059 todolist=lv;
00060 }
00061
00062 void KOTodoListViewToolTip::maybeTip( const QPoint & pos)
00063 {
00064 QRect r;
00065 int headerPos;
00066 int col=todolist->header()->sectionAt(todolist->contentsX() + pos.x());
00067 KOTodoViewItem *i=(KOTodoViewItem *)todolist->itemAt(pos);
00068
00069
00070 if( i && KOPrefs::instance()->mEnableToolTips )
00071 {
00072
00073
00074 r=todolist->itemRect(i);
00075 headerPos = todolist->header()->sectionPos(col)-todolist->contentsX();
00076 r.setLeft( (headerPos < 0 ? 0 : headerPos) );
00077 r.setRight(headerPos + todolist->header()->sectionSize(col));
00078
00079
00080 QString tipText;
00081 ToolTipVisitor v;
00082 if (v.act(i->todo(), &tipText, true)) {
00083 tip(r, tipText);
00084 }
00085 }
00086
00087 }
00088
00089
00090
00091 KOTodoListView::KOTodoListView( QWidget *parent, const char *name )
00092 : KListView( parent, name ), mCalendar( 0 )
00093 {
00094 mOldCurrent = 0;
00095 mMousePressed = false;
00096
00097
00098 tooltip = new KOTodoListViewToolTip( viewport(), this );
00099 }
00100
00101 KOTodoListView::~KOTodoListView()
00102 {
00103 delete tooltip;
00104 }
00105
00106 void KOTodoListView::setCalendar( Calendar *cal )
00107 {
00108 mCalendar = cal;
00109 setAcceptDrops( mCalendar );
00110 viewport()->setAcceptDrops( mCalendar );
00111 }
00112
00113 bool KOTodoListView::event(QEvent *e)
00114 {
00115 int tmp=0;
00116 KOTodoViewItem *i;
00117
00118
00119
00120 if(e->type()==QEvent::ApplicationPaletteChange)
00121 {
00122
00123 KListView::event(e);
00124 i=(KOTodoViewItem *)itemAtIndex(tmp);
00125
00126 while(i!=0)
00127 {
00128 i->construct();
00129 tmp++;
00130 i=(KOTodoViewItem *)itemAtIndex(tmp);
00131 }
00132
00133 }
00134
00135 return (KListView::event(e) || e->type()==QEvent::ApplicationPaletteChange);
00136 }
00137
00138 void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
00139 {
00140 #ifndef KORG_NODND
00141
00142 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
00143 !QTextDrag::canDecode( e ) ) {
00144 e->ignore();
00145 return;
00146 }
00147
00148 mOldCurrent = currentItem();
00149 #endif
00150 }
00151
00152
00153 void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
00154 {
00155 #ifndef KORG_NODND
00156
00157
00158 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
00159 !QTextDrag::canDecode( e ) ) {
00160 e->ignore();
00161 return;
00162 }
00163
00164 e->accept();
00165 #endif
00166 }
00167
00168 void KOTodoListView::contentsDragLeaveEvent( QDragLeaveEvent * )
00169 {
00170 #ifndef KORG_NODND
00171
00172
00173 setCurrentItem(mOldCurrent);
00174 setSelected(mOldCurrent,true);
00175 #endif
00176 }
00177
00178 void KOTodoListView::contentsDropEvent( QDropEvent *e )
00179 {
00180 #ifndef KORG_NODND
00181
00182
00183 if ( !mCalendar ||
00184 ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
00185 !QTextDrag::canDecode( e ) ) ) {
00186 e->ignore();
00187 return;
00188 }
00189
00190 DndFactory factory( mCalendar );
00191 Todo *todo = factory.createDropTodo(e);
00192
00193 if (todo) {
00194 e->acceptAction();
00195
00196 KOTodoViewItem *destination =
00197 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
00198 Todo *destinationEvent = 0;
00199 if (destination) destinationEvent = destination->todo();
00200
00201 Todo *existingTodo = mCalendar->todo(todo->uid());
00202
00203 if(existingTodo) {
00204
00205 Incidence *to = destinationEvent;
00206 while(to) {
00207 if (to->uid() == todo->uid()) {
00208 KMessageBox::sorry(this,
00209 i18n("Cannot move To-Do to itself or a child of itself"),
00210 i18n("Drop To-Do"));
00211 delete todo;
00212 return;
00213 }
00214 to = to->relatedTo();
00215 }
00216 Todo*oldTodo = existingTodo->clone();
00217 existingTodo->setRelatedTo(destinationEvent);
00218
00219 emit todoDropped( todo );
00220 emit todoChanged( oldTodo, todo );
00221 delete oldTodo;
00222 delete todo;
00223 } else {
00224
00225 todo->setRelatedTo(destinationEvent);
00226 if ( !mCalendar->addTodo( todo ) ) {
00227 KODialogManager::errorSaveTodo( this );
00228 return;
00229 }
00230
00231 emit todoDropped(todo);
00232 emit todoAdded( todo );
00233 }
00234 }
00235 else {
00236 QString text;
00237 if (QTextDrag::decode(e,text)) {
00238
00239 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
00240 kdDebug(5850) << "Dropped : " << text << endl;
00241 QStringList emails = QStringList::split(",",text);
00242 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
00243 kdDebug(5850) << " Email: " << (*it) << endl;
00244 int pos = (*it).find("<");
00245 QString name = (*it).left(pos);
00246 QString email = (*it).mid(pos);
00247 if (!email.isEmpty() && todoi) {
00248 todoi->todo()->addAttendee(new Attendee(name,email));
00249 }
00250 }
00251 }
00252 else {
00253 kdDebug(5850) << "KOTodoListView::contentsDropEvent(): Todo from drop not decodable" << endl;
00254 e->ignore();
00255 }
00256 }
00257 #endif
00258 }
00259
00260 void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
00261 {
00262 QListView::contentsMousePressEvent(e);
00263 QPoint p(contentsToViewport(e->pos()));
00264 QListViewItem *i = itemAt(p);
00265 if (i) {
00266
00267
00268 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
00269 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
00270 itemMargin() ||
00271 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
00272 if (e->button()==Qt::LeftButton) {
00273 mPressPos = e->pos();
00274 mMousePressed = true;
00275 }
00276 }
00277 }
00278 }
00279
00280 void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
00281 {
00282 #ifndef KORG_NODND
00283
00284 QListView::contentsMouseMoveEvent(e);
00285 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
00286 QApplication::startDragDistance()) {
00287 mMousePressed = false;
00288 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
00289 if ( item && mCalendar ) {
00290
00291 DndFactory factory( mCalendar );
00292 ICalDrag *vd = factory.createDrag(
00293 ((KOTodoViewItem *)item)->todo(),viewport());
00294 if (vd->drag()) {
00295 kdDebug(5850) << "KOTodoListView::contentsMouseMoveEvent(): Delete drag source" << endl;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 }
00308 }
00309 #endif
00310 }
00311
00312 void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
00313 {
00314 QListView::contentsMouseReleaseEvent(e);
00315 mMousePressed = false;
00316 }
00317
00318 void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
00319 {
00320 if (!e) return;
00321
00322 QPoint vp = contentsToViewport(e->pos());
00323
00324 QListViewItem *item = itemAt(vp);
00325
00326 if (!item) return;
00327
00328 emit doubleClicked(item,vp,0);
00329 }
00330
00332
00333 KOQuickTodo::KOQuickTodo(QWidget *parent) :
00334 QLineEdit(parent)
00335 {
00336 setText(i18n("Click to add a new Todo"));
00337 setPaletteForegroundColor(gray);
00338 }
00339
00340 void KOQuickTodo::focusInEvent(QFocusEvent *ev)
00341 {
00342 if ( text()==i18n("Click to add a new Todo") )
00343 setText(QString::null);
00344 setPaletteForegroundColor(parentWidget()->paletteForegroundColor());
00345 QLineEdit::focusInEvent(ev);
00346 }
00347
00348 void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
00349 {
00350 if ( text().isEmpty() )
00351 setText(i18n("Click to add a new Todo"));
00352 setPaletteForegroundColor(gray);
00353 QLineEdit::focusOutEvent(ev);
00354 }
00355
00357
00358 KOTodoView::KOTodoView( Calendar *calendar, QWidget *parent, const char* name)
00359 : KOrg::BaseView( calendar, parent, name )
00360 {
00361 QBoxLayout *topLayout = new QVBoxLayout( this );
00362
00363 QLabel *title = new QLabel( i18n("To-do items:"), this );
00364 title->setFrameStyle( QFrame::Panel | QFrame::Raised );
00365 topLayout->addWidget( title );
00366
00367 mQuickAdd = new KOQuickTodo( this );
00368 topLayout->addWidget( mQuickAdd );
00369
00370 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
00371
00372 mTodoListView = new KOTodoListView( this );
00373 topLayout->addWidget( mTodoListView );
00374
00375 mTodoListView->setRootIsDecorated( true );
00376 mTodoListView->setAllColumnsShowFocus( true );
00377
00378 mTodoListView->setShowSortIndicator( true );
00379
00380 mTodoListView->addColumn( i18n("Summary") );
00381 mTodoListView->addColumn( i18n("Priority") );
00382 mTodoListView->setColumnAlignment( 1, AlignHCenter );
00383 mTodoListView->addColumn( i18n("Complete") );
00384 mTodoListView->setColumnAlignment( 2, AlignRight );
00385 mTodoListView->addColumn( i18n("Due Date") );
00386 mTodoListView->setColumnAlignment( 3, AlignHCenter );
00387 mTodoListView->addColumn( i18n("Due Time") );
00388 mTodoListView->setColumnAlignment( 4, AlignHCenter );
00389 mTodoListView->addColumn( i18n("Categories") );
00390 #if 0
00391 mTodoListView->addColumn( i18n("Sort Id") );
00392 mTodoListView->setColumnAlignment( 4, AlignHCenter );
00393 #endif
00394
00395 mTodoListView->setMinimumHeight( 60 );
00396 mTodoListView->setItemsRenameable( true );
00397 mTodoListView->setRenameable( 0 );
00398
00399 mTodoListView->setColumnWidthMode( 0, QListView::Manual );
00400 mTodoListView->setColumnWidthMode( 1, QListView::Manual );
00401 mTodoListView->setColumnWidthMode( 2, QListView::Manual );
00402 mTodoListView->setColumnWidthMode( 3, QListView::Manual );
00403 mTodoListView->setColumnWidthMode( 4, QListView::Manual );
00404 mTodoListView->setColumnWidthMode( 5, QListView::Manual );
00405 #if 0
00406 mTodoListView->setColumnWidthMode( 6, QListView::Manual );
00407 #endif
00408
00409 mPriorityPopupMenu = new QPopupMenu( this );
00410 for ( int i = 1; i <= 5; i++ ) {
00411 QString label = QString ("%1").arg( i );
00412 mPriority[ mPriorityPopupMenu->insertItem( label ) ] = i;
00413 }
00414 connect( mPriorityPopupMenu, SIGNAL( activated( int ) ),
00415 SLOT( setNewPriority( int ) ));
00416
00417 mPercentageCompletedPopupMenu = new QPopupMenu(this);
00418 for (int i = 0; i <= 100; i+=20) {
00419 QString label = QString ("%1 %").arg (i);
00420 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
00421 }
00422 connect( mPercentageCompletedPopupMenu, SIGNAL( activated( int ) ),
00423 SLOT( setNewPercentage( int ) ) );
00424
00425 mItemPopupMenu = new QPopupMenu(this);
00426 mItemPopupMenu->insertItem(i18n("Show"), this,
00427 SLOT (showTodo()));
00428 mItemPopupMenu->insertItem(i18n("Edit..."), this,
00429 SLOT (editTodo()));
00430 mItemPopupMenu->insertItem(KOGlobals::self()->smallIconSet("editdelete"), i18n("Delete"), this,
00431 SLOT (deleteTodo()));
00432 mItemPopupMenu->insertSeparator();
00433 mItemPopupMenu->insertItem(KOGlobals::self()->smallIconSet("todo"), i18n("New To-Do..."), this,
00434 SLOT (newTodo()));
00435 mItemPopupMenu->insertItem(i18n("New Sub-To-Do..."), this,
00436 SLOT (newSubTodo()));
00437 mItemPopupMenu->insertItem( i18n("Make Sub-To-Do Independent"), this,
00438 SIGNAL( unSubTodoSignal() ), 0, POPUP_UNSUBTODO );
00439 mItemPopupMenu->insertSeparator();
00440 mItemPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
00441 this, SLOT( purgeCompleted() ) );
00442
00443 mPopupMenu = new QPopupMenu(this);
00444 mPopupMenu->insertItem(KOGlobals::self()->smallIconSet("todo"), i18n("New To-Do..."), this,
00445 SLOT (newTodo()));
00446 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
00447 this, SLOT(purgeCompleted()));
00448
00449 mDocPrefs = new DocPrefs( name );
00450
00451
00452 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *,
00453 const QPoint &, int ) ),
00454 SLOT( editItem( QListViewItem *, const QPoint &, int ) ) );
00455 connect( mTodoListView, SIGNAL( returnPressed( QListViewItem * ) ),
00456 SLOT( editItem( QListViewItem * ) ) );
00457 connect( mTodoListView, SIGNAL( contextMenuRequested( QListViewItem *,
00458 const QPoint &, int ) ),
00459 SLOT( popupMenu( QListViewItem *, const QPoint &, int ) ) );
00460 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
00461 SLOT( itemClicked( QListViewItem * ) ) );
00462 connect( mTodoListView, SIGNAL( todoDropped( Todo * ) ),
00463 SLOT( updateView() ) );
00464 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
00465 SLOT( itemStateChanged( QListViewItem * ) ) );
00466 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
00467 SLOT( itemStateChanged( QListViewItem * ) ) );
00468
00469 #if 0
00470 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
00471 SLOT(selectionChanged(QListViewItem *)));
00472 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
00473 SLOT(selectionChanged(QListViewItem *)));
00474 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
00475 SLOT(selectionChanged(QListViewItem *)));
00476 #endif
00477 connect( mTodoListView, SIGNAL(selectionChanged() ),
00478 SLOT( processSelectionChange() ) );
00479 connect( mQuickAdd, SIGNAL( returnPressed () ),
00480 SLOT( addQuickTodo() ) );
00481 connect( mTodoListView, SIGNAL( todoChanged( Todo*, Todo* ) ),
00482 SIGNAL( todoChanged( Todo*, Todo* ) ) );
00483 connect( mTodoListView, SIGNAL( todoAdded( Todo* ) ),
00484 SIGNAL( todoAdded( Todo* ) ) );
00485 }
00486
00487 KOTodoView::~KOTodoView()
00488 {
00489 delete mDocPrefs;
00490 }
00491
00492 void KOTodoView::setCalendar( Calendar *cal )
00493 {
00494 BaseView::setCalendar( cal );
00495 mTodoListView->setCalendar( cal );
00496 }
00497
00498 void KOTodoView::updateView()
00499 {
00500
00501
00502 mTodoListView->clear();
00503
00504 Todo::List todoList = calendar()->todos();
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 mTodoMap.clear();
00528 Todo::List::ConstIterator it;
00529 for( it = todoList.begin(); it != todoList.end(); ++it ) {
00530 if ( !mTodoMap.contains( *it ) ) {
00531 insertTodoItem( *it );
00532 }
00533 }
00534
00535
00536 mTodoListView->blockSignals( true );
00537 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
00538 mTodoListView->blockSignals( false );
00539
00540 processSelectionChange();
00541 }
00542
00543 void KOTodoView::restoreItemState( QListViewItem *item )
00544 {
00545 while( item ) {
00546 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
00547 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
00548 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
00549 item = item->nextSibling();
00550 }
00551 }
00552
00553
00554 QMap<Todo *,KOTodoViewItem *>::ConstIterator
00555 KOTodoView::insertTodoItem(Todo *todo)
00556 {
00557
00558
00559 Incidence *incidence = todo->relatedTo();
00560 if (incidence && incidence->type() == "Todo") {
00561 Todo *relatedTodo = static_cast<Todo *>(incidence);
00562
00563
00564 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
00565 itemIterator = mTodoMap.find(relatedTodo);
00566 if (itemIterator == mTodoMap.end()) {
00567
00568 itemIterator = insertTodoItem (relatedTodo);
00569 }
00570
00571
00572 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
00573 return mTodoMap.insert(todo,todoItem);
00574 } else {
00575
00576
00577 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
00578 return mTodoMap.insert(todo,todoItem);
00579 }
00580 }
00581
00582
00583 void KOTodoView::updateConfig()
00584 {
00585 mTodoListView->repaintContents();
00586 }
00587
00588 Incidence::List KOTodoView::selectedIncidences()
00589 {
00590 Incidence::List selected;
00591
00592 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
00593
00594 if (item) selected.append(item->todo());
00595
00596 return selected;
00597 }
00598
00599 Todo::List KOTodoView::selectedTodos()
00600 {
00601 Todo::List selected;
00602
00603 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
00604
00605 if (item) selected.append(item->todo());
00606
00607 return selected;
00608 }
00609
00610 void KOTodoView::changeEventDisplay(Event *, int)
00611 {
00612 updateView();
00613 }
00614
00615 void KOTodoView::showDates(const QDate &, const QDate &)
00616 {
00617 }
00618
00619 void KOTodoView::showEvents( const Event::List & )
00620 {
00621 kdDebug(5850) << "KOTodoView::selectEvents(): not yet implemented" << endl;
00622 }
00623
00624 void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
00625 const QDate &td)
00626 {
00627 #ifndef KORG_NOPRINTER
00628 calPrinter->preview(CalPrinter::Todolist, fd, td);
00629 #endif
00630 }
00631
00632 CalPrinter::PrintType KOTodoView::printType()
00633 {
00634 return CalPrinter::Todolist;
00635 }
00636
00637 void KOTodoView::editItem( QListViewItem *item )
00638 {
00639 emit editTodoSignal( static_cast<KOTodoViewItem *>( item )->todo() );
00640 }
00641
00642 void KOTodoView::editItem( QListViewItem *item, const QPoint &, int )
00643 {
00644 editItem( item );
00645 }
00646
00647 void KOTodoView::showItem( QListViewItem *item, const QPoint &, int )
00648 {
00649 emit showTodoSignal( static_cast<KOTodoViewItem *>( item )->todo() );
00650 }
00651
00652 void KOTodoView::popupMenu( QListViewItem *item, const QPoint &, int column )
00653 {
00654 mActiveItem = static_cast<KOTodoViewItem *>( item );
00655 if ( item ) {
00656 switch ( column ) {
00657 case 1:
00658 mPriorityPopupMenu->popup( QCursor::pos () );
00659 break;
00660 case 2:
00661 mPercentageCompletedPopupMenu->popup( QCursor::pos () );
00662 break;
00663 case 5:
00664 getCategoryPopupMenu(
00665 static_cast<KOTodoViewItem *>( item ) )->popup( QCursor::pos () );
00666 break;
00667 default:
00668 mItemPopupMenu->setItemEnabled( POPUP_UNSUBTODO,
00669 mActiveItem->todo()->relatedTo() );
00670 mItemPopupMenu->popup( QCursor::pos() );
00671 }
00672 } else mPopupMenu->popup( QCursor::pos() );
00673 }
00674
00675 void KOTodoView::newTodo()
00676 {
00677 emit newTodoSignal();
00678 }
00679
00680 void KOTodoView::newSubTodo()
00681 {
00682 if (mActiveItem) {
00683 emit newSubTodoSignal(mActiveItem->todo());
00684 }
00685 }
00686
00687 void KOTodoView::editTodo()
00688 {
00689 if (mActiveItem) {
00690 emit editTodoSignal(mActiveItem->todo());
00691 }
00692 }
00693
00694 void KOTodoView::showTodo()
00695 {
00696 if (mActiveItem) {
00697 emit showTodoSignal(mActiveItem->todo());
00698 }
00699 }
00700
00701 void KOTodoView::deleteTodo()
00702 {
00703 if (mActiveItem) {
00704 if (mActiveItem->childCount()) {
00705 KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."),
00706 i18n("Delete To-Do"));
00707 } else {
00708 emit deleteTodoSignal(mActiveItem->todo());
00709 }
00710 }
00711 }
00712
00713 void KOTodoView::setNewPriority(int index)
00714 {
00715 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
00716 Todo*todo = mActiveItem->todo();
00717 Todo*oldTodo = todo->clone();
00718 todo->setPriority(mPriority[index]);
00719 mActiveItem->construct();
00720 emit todoModifiedSignal ( todo, oldTodo, KOGlobals::PRIORITY_MODIFIED );
00721 delete oldTodo;
00722 }
00723 }
00724
00725 void KOTodoView::setNewPercentage(int index)
00726 {
00727 if ( mActiveItem && !mActiveItem->todo()->isReadOnly () ) {
00728 Todo*todo = mActiveItem->todo();
00729 Todo*oldTodo = todo->clone();
00730
00731 if (mPercentage[index] == 100) {
00732 todo->setCompleted(QDateTime::currentDateTime());
00733 } else {
00734 todo->setCompleted(false);
00735 }
00736 todo->setPercentComplete(mPercentage[index]);
00737 mActiveItem->construct();
00738 emit todoModifiedSignal( todo, oldTodo, KOGlobals::COMPLETION_MODIFIED );
00739 delete oldTodo;
00740 }
00741 }
00742
00743
00744 QPopupMenu *KOTodoView::getCategoryPopupMenu( KOTodoViewItem *todoItem )
00745 {
00746 QPopupMenu *tempMenu = new QPopupMenu( this );
00747 QStringList checkedCategories = todoItem->todo()->categories();
00748
00749 tempMenu->setCheckable( true );
00750 QStringList::Iterator it;
00751 for ( it = KOPrefs::instance()->mCustomCategories.begin();
00752 it != KOPrefs::instance()->mCustomCategories.end();
00753 ++it ) {
00754 int index = tempMenu->insertItem( *it );
00755 mCategory[ index ] = *it;
00756 if ( checkedCategories.find( *it ) != checkedCategories.end() )
00757 tempMenu->setItemChecked( index, true );
00758 }
00759
00760 connect ( tempMenu, SIGNAL( activated( int ) ),
00761 SLOT( changedCategories( int ) ) );
00762 return tempMenu;
00763 }
00764
00765 void KOTodoView::changedCategories(int index)
00766 {
00767 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
00768 Todo*todo = mActiveItem->todo();
00769 Todo*oldTodo = todo->clone();
00770 QStringList categories = todo->categories ();
00771 if (categories.find (mCategory[index]) != categories.end ())
00772 categories.remove (mCategory[index]);
00773 else
00774 categories.insert (categories.end(), mCategory[index]);
00775 categories.sort ();
00776 todo->setCategories (categories);
00777 mActiveItem->construct();
00778 emit todoModifiedSignal( todo, oldTodo, KOGlobals::CATEGORY_MODIFIED);
00779 delete oldTodo;
00780 }
00781 }
00782
00783 void KOTodoView::itemClicked(QListViewItem *item)
00784 {
00785 if (!item) return;
00786
00787 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
00788 int completed = todoItem->todo()->isCompleted();
00789
00790 if (todoItem->isOn()) {
00791 if (!completed) {
00792 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
00793 }
00794 } else {
00795 if (completed) {
00796 todoItem->todo()->setCompleted(false);
00797 }
00798 }
00799 }
00800
00801 void KOTodoView::setDocumentId( const QString &id )
00802 {
00803 kdDebug(5850) << "KOTodoView::setDocumentId()" << endl;
00804
00805 mDocPrefs->setDoc( id );
00806 }
00807
00808 void KOTodoView::itemStateChanged( QListViewItem *item )
00809 {
00810 if (!item) return;
00811
00812 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
00813
00814
00815
00816 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
00817 }
00818
00819 void KOTodoView::saveLayout(KConfig *config, const QString &group) const
00820 {
00821 mTodoListView->saveLayout(config,group);
00822 }
00823
00824 void KOTodoView::restoreLayout(KConfig *config, const QString &group)
00825 {
00826 mTodoListView->restoreLayout(config,group);
00827 }
00828
00829 void KOTodoView::processSelectionChange()
00830 {
00831
00832
00833 KOTodoViewItem *item =
00834 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
00835
00836 if ( !item ) {
00837 emit incidenceSelected( 0 );
00838 } else {
00839 emit incidenceSelected( item->todo() );
00840 }
00841 }
00842
00843 void KOTodoView::modified(bool b)
00844 {
00845 emit isModified(b);
00846 }
00847
00848 void KOTodoView::clearSelection()
00849 {
00850 mTodoListView->selectAll( false );
00851 }
00852
00853 void KOTodoView::purgeCompleted()
00854 {
00855 emit purgeCompletedSignal();
00856 }
00857
00858 void KOTodoView::addQuickTodo()
00859 {
00860 Todo *todo = new Todo();
00861 todo->setSummary( mQuickAdd->text() );
00862 todo->setOrganizer( KOPrefs::instance()->email() );
00863 if ( !calendar()->addTodo( todo ) ) {
00864 KODialogManager::errorSaveTodo( this );
00865 return;
00866 }
00867 mQuickAdd->setText( QString::null );
00868 emit todoAdded( todo );
00869 updateView();
00870 }