1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
|
/*
This file is part of KOrganizer.
Copyright (c) 2000,2001,2003 Cornelius Schumacher <[email protected]>
Copyright (C) 2003-2004 Reinhold Kainhofer <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of TQt, and distribute the resulting executable,
without including the source code for TQt in the source distribution.
*/
#include <tqlayout.h>
#include <tqheader.h>
#include <tqcursor.h>
#include <tqlabel.h>
#include <tqtimer.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kiconloader.h>
#include <tdemessagebox.h>
#include <libkcal/calhelper.h>
#include <libkcal/icaldrag.h>
#include <libkcal/vcaldrag.h>
#include <libkcal/dndfactory.h>
#include <libkcal/calendarresources.h>
#include <libkcal/resourcecalendar.h>
#include <libkcal/calfilter.h>
#include <libkcal/incidenceformatter.h>
#include <libtdepim/clicklineedit.h>
#include <libtdepim/kdatepickerpopup.h>
#include <libemailfunctions/email.h>
#include "docprefs.h"
#include "koincidencetooltip.h"
#include "kodialogmanager.h"
#include "kotodoview.h"
#include "koprefs.h"
#include "koglobals.h"
using namespace KOrg;
#include "kotodoviewitem.h"
#include "kotodoview.moc"
#ifndef KORG_NOPRINTER
#include "kocorehelper.h"
#include "calprinter.h"
#endif
KOTodoListViewToolTip::KOTodoListViewToolTip (TQWidget *parent,
Calendar *calendar,
KOTodoListView *lv )
:TQToolTip(parent), mCalendar( calendar )
{
todolist=lv;
}
void KOTodoListViewToolTip::maybeTip( const TQPoint & pos)
{
TQRect r;
int headerPos;
int col=todolist->header()->sectionAt(todolist->contentsX() + pos.x());
KOTodoViewItem *i=(KOTodoViewItem *)todolist->itemAt(pos);
/* Check wether a tooltip is necessary. */
if( i && KOPrefs::instance()->mEnableToolTips )
{
/* Calculate the rectangle. */
r=todolist->itemRect(i);
headerPos = todolist->header()->sectionPos(col)-todolist->contentsX();
r.setLeft( (headerPos < 0 ? 0 : headerPos) );
r.setRight(headerPos + todolist->header()->sectionSize(col));
/* Show the tip */
TQString tipText( IncidenceFormatter::toolTipStr( mCalendar, i->todo(), TQDate(), true ) );;
if ( !tipText.isEmpty() ) {
tip(r, tipText);
}
}
}
KOTodoListView::KOTodoListView( TQWidget *parent, const char *name )
: TDEListView( parent, name ), mCalendar( 0 ), mChanger( 0 )
{
mOldCurrent = 0;
mMousePressed = false;
}
KOTodoListView::~KOTodoListView()
{
}
void KOTodoListView::setCalendar( Calendar *cal )
{
mCalendar = cal;
setAcceptDrops( mCalendar );
viewport()->setAcceptDrops( mCalendar );
}
bool KOTodoListView::event(TQEvent *e)
{
int tmp=0;
KOTodoViewItem *i;
/* Checks for an ApplicationPaletteChange event and updates
* the small Progress bars to make therm have the right colors. */
if(e->type()==TQEvent::ApplicationPaletteChange)
{
TDEListView::event(e);
i=(KOTodoViewItem *)itemAtIndex(tmp);
while(i!=0)
{
i->construct();
tmp++;
i=(KOTodoViewItem *)itemAtIndex(tmp);
}
}
return (TDEListView::event(e) || e->type()==TQEvent::ApplicationPaletteChange);
}
void KOTodoListView::contentsDragEnterEvent(TQDragEnterEvent *e)
{
#ifndef KORG_NODND
// kdDebug(5850) << "KOTodoListView::contentsDragEnterEvent" << endl;
if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
!TQTextDrag::canDecode( e ) ) {
e->ignore();
return;
}
mOldCurrent = currentItem();
#endif
}
void KOTodoListView::contentsDragMoveEvent(TQDragMoveEvent *e)
{
#ifndef KORG_NODND
// kdDebug(5850) << "KOTodoListView::contentsDragMoveEvent" << endl;
if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
!TQTextDrag::canDecode( e ) ) {
e->ignore();
return;
}
e->accept();
#endif
}
void KOTodoListView::contentsDragLeaveEvent( TQDragLeaveEvent * )
{
#ifndef KORG_NODND
// kdDebug(5850) << "KOTodoListView::contentsDragLeaveEvent" << endl;
setCurrentItem(mOldCurrent);
setSelected(mOldCurrent,true);
#endif
}
void KOTodoListView::contentsDropEvent( TQDropEvent *e )
{
#ifndef KORG_NODND
kdDebug(5850) << "KOTodoListView::contentsDropEvent" << endl;
if ( !mCalendar || !mChanger ||
( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
!TQTextDrag::canDecode( e ) ) ) {
e->ignore();
return;
}
DndFactory factory( mCalendar );
Todo *todo = factory.createDropTodo(e);
if ( todo ) {
e->acceptAction();
KOTodoViewItem *destination =
(KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
Todo *destinationEvent = 0;
if (destination) destinationEvent = destination->todo();
Todo *existingTodo = mCalendar->todo(todo->uid());
if( existingTodo ) {
kdDebug(5850) << "Drop existing Todo " << existingTodo << " onto " << destinationEvent << endl;
Incidence *to = destinationEvent;
while(to) {
if (to->uid() == todo->uid()) {
KMessageBox::information(this,
i18n("Cannot move to-do to itself or a child of itself."),
i18n("Drop To-do"), "NoDropTodoOntoItself" );
delete todo;
return;
}
to = to->relatedTo();
}
Todo*oldTodo = existingTodo->clone();
if ( mChanger->beginChange( existingTodo, 0, TQString() ) ) {
existingTodo->setRelatedTo( destinationEvent );
mChanger->changeIncidence( oldTodo, existingTodo, KOGlobals::RELATION_MODIFIED, this );
mChanger->endChange( existingTodo, 0, TQString() );
} else {
KMessageBox::sorry( this, i18n("Unable to change to-do's parent, "
"because the to-do cannot be locked.") );
}
delete oldTodo;
delete todo;
} else {
// kdDebug(5850) << "Drop new Todo" << endl;
todo->setRelatedTo(destinationEvent);
if ( !mChanger->addIncidence( todo, 0, TQString(), this ) ) {
KODialogManager::errorSaveIncidence( this, todo );
delete todo;
return;
}
}
} else {
TQString text;
KOTodoViewItem *todoi = dynamic_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
if ( ! todoi ) {
// Not dropped on a todo item:
e->ignore();
kdDebug( 5850 ) << "KOTodoListView::contentsDropEvent(): Not dropped on a todo item" << endl;
kdDebug( 5850 ) << "TODO: Create a new todo with the given data" << endl;
// FIXME: Create a new todo with the given text/contact/whatever
} else if ( TQTextDrag::decode(e, text) ) {
//TQListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
kdDebug(5850) << "Dropped : " << text << endl;
Todo*todo = todoi->todo();
if( mChanger->beginChange( todo, 0, TQString() ) ) {
Todo*oldtodo = todo->clone();
if( text.startsWith( "file:" ) ) {
todo->addAttachment( new Attachment( text ) );
} else {
TQStringList emails = KPIM::splitEmailAddrList( text );
for(TQStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
kdDebug(5850) << " Email: " << (*it) << endl;
int pos = (*it).find("<");
TQString name = (*it).left(pos);
TQString email = (*it).mid(pos);
if (!email.isEmpty() && todoi) {
todo->addAttendee( new Attendee( name, email ) );
}
}
}
//FIXME: attendees or attachment added, so there is something modified
mChanger->changeIncidence( oldtodo, todo, KOGlobals::NOTHING_MODIFIED, this );
mChanger->endChange( todo, 0, TQString() );
} else {
KMessageBox::sorry( this, i18n("Unable to add attendees to the to-do, "
"because the to-do cannot be locked.") );
}
}
else {
kdDebug(5850) << "KOTodoListView::contentsDropEvent(): Todo from drop not decodable" << endl;
e->ignore();
}
}
#endif
}
void KOTodoListView::contentsMousePressEvent(TQMouseEvent* e)
{
TQListView::contentsMousePressEvent(e);
TQPoint p(contentsToViewport(e->pos()));
TQListViewItem *i = itemAt(p);
if (i) {
// if the user clicked into the root decoration of the item, don't
// try to start a drag!
if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
itemMargin() ||
p.x() < header()->sectionPos(header()->mapToIndex(0))) {
if (e->button()==Qt::LeftButton) {
mPressPos = e->pos();
mMousePressed = true;
}
}
}
}
void KOTodoListView::contentsMouseMoveEvent(TQMouseEvent* e)
{
#ifndef KORG_NODND
// kdDebug(5850) << "KOTodoListView::contentsMouseMoveEvent()" << endl;
TQListView::contentsMouseMoveEvent(e);
if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
TQApplication::startDragDistance()) {
mMousePressed = false;
TQListViewItem *item = itemAt(contentsToViewport(mPressPos));
if ( item && mCalendar ) {
// kdDebug(5850) << "Start Drag for item " << item->text(0) << endl;
DndFactory factory( mCalendar );
ICalDrag *vd = factory.createDrag(
((KOTodoViewItem *)item)->todo(),viewport());
if (vd->drag()) {
kdDebug(5850) << "KOTodoListView::contentsMouseMoveEvent(): Delete drag source" << endl;
}
/*
TQString source = fullPath(item);
if ( TQFile::exists(source) ) {
KURL url;
url.setPath(source);
KURLDrag* ud = KURLDrag::newDrag(KURL::List(url), viewport());
if ( ud->drag() )
TQMessageBox::information( this, "Drag source",
TQString("Delete ")+source, "Not implemented" );
*/
}
}
#endif
}
void KOTodoListView::contentsMouseReleaseEvent(TQMouseEvent *e)
{
TQListView::contentsMouseReleaseEvent(e);
mMousePressed = false;
}
void KOTodoListView::contentsMouseDoubleClickEvent(TQMouseEvent *e)
{
if (!e) return;
TQPoint vp = contentsToViewport(e->pos());
TQListViewItem *item = itemAt(vp);
if (!item) return;
emit doubleClicked(item,vp,0);
}
/////////////////////////////////////////////////////////////////////////////
KOTodoView::KOTodoView( Calendar *calendar, TQWidget *parent, const char* name)
: KOrg::BaseView( calendar, parent, name )
{
TQBoxLayout *topLayout = new TQVBoxLayout( this );
TQLabel *title = new TQLabel( i18n("To-dos:"), this );
title->setFrameStyle( TQFrame::Panel | TQFrame::Raised );
topLayout->addWidget( title );
mQuickAdd = new KPIM::ClickLineEdit( this, i18n( "Click to add a new to-do" ) );
mQuickAdd->setAcceptDrops( false );
topLayout->addWidget( mQuickAdd );
if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
mTodoListView = new KOTodoListView( this );
topLayout->addWidget( mTodoListView );
mTodoListView->setRootIsDecorated( true );
mTodoListView->setAllColumnsShowFocus( true );
mTodoListView->setShowSortIndicator( true );
mTodoListView->addColumn( i18n("Summary") );
mTodoListView->addColumn( i18n("Recurs") );
mTodoListView->addColumn( i18n("Priority") );
mTodoListView->setColumnAlignment( ePriorityColumn, AlignHCenter );
mTodoListView->addColumn( i18n("Complete") );
mTodoListView->setColumnAlignment( ePercentColumn, AlignRight );
mTodoListView->addColumn( i18n("Due Date/Time") );
mTodoListView->setColumnAlignment( eDueDateColumn, AlignLeft );
mTodoListView->addColumn( i18n("Categories") );
mTodoListView->addColumn( i18n( "Calendar" ) );
#if 0
mTodoListView->addColumn( i18n("Sort Id") );
mTodoListView->setColumnAlignment( 4, AlignHCenter );
#endif
mTodoListView->setMinimumHeight( 60 );
mTodoListView->setItemsRenameable( true );
mTodoListView->setRenameable( 0 );
mTodoListView->setColumnWidthMode( eSummaryColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( eRecurColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( ePriorityColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( ePercentColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( eDueDateColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( eCategoriesColumn, TQListView::Manual );
mTodoListView->setColumnWidthMode( eFolderColumn, TQListView::Manual );
#if 0
mTodoListView->setColumnWidthMode( eDescriptionColumn, TQListView::Manual );
#endif
mPriorityPopupMenu = new TQPopupMenu( this );
mPriority[ mPriorityPopupMenu->insertItem( i18n("Unspecified priority", "unspecified") ) ] = 0;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "1 (highest)") ) ] = 1;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "2" ) ) ] = 2;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "3" ) ) ] = 3;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "4" ) ) ] = 4;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "5 (medium)" ) ) ] = 5;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "6" ) ) ] = 6;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "7" ) ) ] = 7;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "8" ) ) ] = 8;
mPriority[ mPriorityPopupMenu->insertItem( i18n( "9 (lowest)" ) ) ] = 9;
connect( mPriorityPopupMenu, TQT_SIGNAL( activated( int ) ),
TQT_SLOT( setNewPriority( int ) ));
mPercentageCompletedPopupMenu = new TQPopupMenu(this);
for (int i = 0; i <= 100; i+=10) {
TQString label = TQString ("%1 %").arg (i);
mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
}
connect( mPercentageCompletedPopupMenu, TQT_SIGNAL( activated( int ) ),
TQT_SLOT( setNewPercentage( int ) ) );
mMovePopupMenu = new KDatePickerPopup(
KDatePickerPopup::NoDate |
KDatePickerPopup::DatePicker |
KDatePickerPopup::Words );
mCopyPopupMenu = new KDatePickerPopup(
KDatePickerPopup::NoDate |
KDatePickerPopup::DatePicker |
KDatePickerPopup::Words );
connect( mMovePopupMenu, TQT_SIGNAL( dateChanged( TQDate )),
TQT_SLOT( setNewDate( TQDate ) ) );
connect( mCopyPopupMenu, TQT_SIGNAL( dateChanged( TQDate )),
TQT_SLOT( copyTodoToDate( TQDate ) ) );
mItemPopupMenu = new TQPopupMenu(this);
mItemPopupMenu->insertItem(i18n("&Show"), this,
TQT_SLOT (showTodo()));
mItemPopupMenu->insertItem(i18n("&Edit..."), this,
TQT_SLOT (editTodo()), 0, ePopupEdit );
#ifndef KORG_NOPRINTER
mItemPopupMenu->insertItem(KOGlobals::self()->smallIcon("printer"), i18n("&Print..."), this, TQT_SLOT( printTodo() ) );
#endif
mItemPopupMenu->insertItem(KOGlobals::self()->smallIconSet("edit-delete"), i18n("&Delete"), this,
TQT_SLOT (deleteTodo()), 0, ePopupDelete );
mItemPopupMenu->insertSeparator();
mItemPopupMenu->insertItem(KOGlobals::self()->smallIconSet("todo"), i18n("New &To-do..."), this,
TQT_SLOT (newTodo()) );
mItemPopupMenu->insertItem(i18n("New Su&b-to-do..."), this,
TQT_SLOT (newSubTodo()));
mItemPopupMenu->insertItem( i18n("&Make this To-do Independent"), this,
TQT_SIGNAL( unSubTodoSignal() ), 0, ePopupUnSubTodo );
mItemPopupMenu->insertItem( i18n("Make all Sub-to-dos &Independent"), this,
TQT_SIGNAL( unAllSubTodoSignal() ), 0, ePopupUnAllSubTodo );
mItemPopupMenu->insertSeparator();
mItemPopupMenu->insertItem( i18n("&Copy To"), mCopyPopupMenu, ePopupCopyTo );
mItemPopupMenu->insertItem(i18n("&Move To"), mMovePopupMenu, ePopupMoveTo );
mItemPopupMenu->insertSeparator();
mItemPopupMenu->insertItem(i18n("delete completed to-dos","Pur&ge Completed"),
this, TQT_SLOT( purgeCompleted() ) );
connect( mMovePopupMenu, TQT_SIGNAL( dateChanged( TQDate ) ),
mItemPopupMenu, TQT_SLOT( hide() ) );
connect( mCopyPopupMenu, TQT_SIGNAL( dateChanged( TQDate ) ),
mItemPopupMenu, TQT_SLOT( hide() ) );
mPopupMenu = new TQPopupMenu(this);
mPopupMenu->insertItem(KOGlobals::self()->smallIconSet("todo"), i18n("&New To-do..."), this,
TQT_SLOT(newTodo()) );
mPopupMenu->insertItem(i18n("delete completed to-dos","&Purge Completed"),
this, TQT_SLOT(purgeCompleted()));
mDocPrefs = new DocPrefs( name );
// Double clicking conflicts with opening/closing the subtree
connect( mTodoListView, TQT_SIGNAL( doubleClicked( TQListViewItem *,
const TQPoint &, int ) ),
TQT_SLOT( editItem( TQListViewItem *, const TQPoint &, int ) ) );
connect( mTodoListView, TQT_SIGNAL( returnPressed( TQListViewItem * ) ),
TQT_SLOT( editItem( TQListViewItem * ) ) );
connect( mTodoListView, TQT_SIGNAL( contextMenuRequested( TQListViewItem *,
const TQPoint &, int ) ),
TQT_SLOT( popupMenu( TQListViewItem *, const TQPoint &, int ) ) );
connect( mTodoListView, TQT_SIGNAL( expanded( TQListViewItem * ) ),
TQT_SLOT( itemStateChanged( TQListViewItem * ) ) );
connect( mTodoListView, TQT_SIGNAL( collapsed( TQListViewItem * ) ),
TQT_SLOT( itemStateChanged( TQListViewItem * ) ) );
#if 0
connect(mTodoListView,TQT_SIGNAL(selectionChanged(TQListViewItem *)),
TQT_SLOT(selectionChanged(TQListViewItem *)));
connect(mTodoListView,TQT_SIGNAL(clicked(TQListViewItem *)),
TQT_SLOT(selectionChanged(TQListViewItem *)));
connect(mTodoListView,TQT_SIGNAL(pressed(TQListViewItem *)),
TQT_SLOT(selectionChanged(TQListViewItem *)));
#endif
connect( mTodoListView, TQT_SIGNAL(selectionChanged() ),
TQT_SLOT( processSelectionChange() ) );
connect( mQuickAdd, TQT_SIGNAL( returnPressed () ),
TQT_SLOT( addQuickTodo() ) );
new KOTodoListViewToolTip( mTodoListView->viewport(), calendar, mTodoListView );
}
KOTodoView::~KOTodoView()
{
delete mDocPrefs;
}
void KOTodoView::setCalendar( Calendar *cal )
{
BaseView::setCalendar( cal );
mTodoListView->setCalendar( cal );
}
void KOTodoView::updateView()
{
// kdDebug(5850) << "KOTodoView::updateView()" << endl;
int oldPos = mTodoListView->contentsY();
mItemsToDelete.clear();
mTodoListView->clear();
Todo::List todoList = calendar()->todos();
/*
kdDebug(5850) << "KOTodoView::updateView(): Todo List:" << endl;
Event *t;
for(t = todoList.first(); t; t = todoList.next()) {
kdDebug(5850) << " " << t->getSummary() << endl;
if (t->getRelatedTo()) {
kdDebug(5850) << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
}
TQPtrList<Event> l = t->getRelations();
Event *c;
for(c=l.first();c;c=l.next()) {
kdDebug(5850) << " - relation: " << c->getSummary() << endl;
}
}
*/
// Put for each Event a KOTodoViewItem in the list view. Don't rely on a
// specific order of events. That means that we have to generate parent items
// recursively for proper hierarchical display of Todos.
mTodoMap.clear();
Todo::List::ConstIterator it;
for( it = todoList.begin(); it != todoList.end(); ++it ) {
if ( !mTodoMap.contains( *it ) ) {
insertTodoItem( *it );
}
}
// Restore opened/closed state
mTodoListView->blockSignals( true );
if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
mTodoListView->blockSignals( false );
mTodoListView->setContentsPos( 0, oldPos );
processSelectionChange();
}
void KOTodoView::restoreItemState( TQListViewItem *item )
{
while( item ) {
KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
item = item->nextSibling();
}
}
TQMap<Todo *,KOTodoViewItem *>::ConstIterator
KOTodoView::insertTodoItem(Todo *todo)
{
// kdDebug(5850) << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
Incidence *incidence = todo->relatedTo();
if (incidence && incidence->type() == "Todo") {
// Use dynamic_cast, because in the future the related item might also be an event
Todo *relatedTodo = dynamic_cast<Todo *>(incidence);
// just make sure we know we have this item already to avoid endless recursion (Bug 101696)
mTodoMap.insert(todo,0);
// kdDebug(5850) << " has Related" << endl;
TQMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
itemIterator = mTodoMap.find(relatedTodo);
if (itemIterator == mTodoMap.end()) {
// kdDebug(5850) << " related not yet in list" << endl;
itemIterator = insertTodoItem (relatedTodo);
}
// isn't this pretty stupid? We give one Todo to the KOTodoViewItem
// and one into the map. Sure finding is more easy but why? -zecke
KOTodoViewItem *todoItem;
// in case we found a related parent, which has no KOTodoViewItem yet, this must
// be the case where 2 items refer to each other, therefore simply create item as root item
if ( *itemIterator == 0 ) {
todo->setRelatedTo(0); // break the recursion, else we will have troubles later
todoItem = new KOTodoViewItem(mTodoListView,todo,this);
}
else
todoItem = new KOTodoViewItem(*itemIterator,todo,this);
return mTodoMap.insert(todo,todoItem);
} else {
// kdDebug(5850) << " no Related" << endl;
// see above -zecke
KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
return mTodoMap.insert(todo,todoItem);
}
}
void KOTodoView::removeTodoItems()
{
KOTodoViewItem *item;
for ( item = mItemsToDelete.first(); item; item = mItemsToDelete.next() ) {
Todo *todo = item->todo();
if ( todo && mTodoMap.contains( todo ) ) {
mTodoMap.remove( todo );
}
delete item;
}
mItemsToDelete.clear();
}
bool KOTodoView::scheduleRemoveTodoItem( KOTodoViewItem *todoItem )
{
if ( todoItem ) {
mItemsToDelete.append( todoItem );
TQTimer::singleShot( 0, this, TQT_SLOT( removeTodoItems() ) );
return true;
} else
return false;
}
void KOTodoView::updateConfig()
{
mTodoListView->repaintContents();
}
Incidence::List KOTodoView::selectedIncidences()
{
Incidence::List selected;
KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
// if (!item) item = mActiveItem;
if (item) selected.append(item->todo());
return selected;
}
Todo::List KOTodoView::selectedTodos()
{
Todo::List selected;
KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
// if (!item) item = mActiveItem;
if (item) selected.append(item->todo());
return selected;
}
void KOTodoView::changeIncidenceDisplay(Incidence *incidence, int action)
{
// The todo view only displays todos, so exit on all other incidences
if ( incidence->type() != "Todo" )
return;
CalFilter *filter = calendar()->filter();
bool isFiltered = filter && !filter->filterIncidence( incidence );
Todo *todo = static_cast<Todo *>(incidence);
if ( todo ) {
KOTodoViewItem *todoItem = 0;
if ( mTodoMap.contains( todo ) ) {
todoItem = mTodoMap[todo];
}
switch ( action ) {
case KOGlobals::INCIDENCEADDED:
case KOGlobals::INCIDENCEEDITED:
// If it's already there, edit it, otherwise just add
if ( todoItem ) {
if ( isFiltered ) {
scheduleRemoveTodoItem( todoItem );
} else {
// correctly update changes in relations
Todo*parent = dynamic_cast<Todo*>( todo->relatedTo() );
KOTodoViewItem*parentItem = 0;
if ( parent && mTodoMap.contains(parent) ) {
parentItem = mTodoMap[ parent ];
}
if ( todoItem->parent() != parentItem ) {
// The relations changed
if ( parentItem ) {
parentItem->insertItem( todoItem );
} else {
mTodoListView->insertItem( todoItem );
}
}
todoItem->construct();
}
} else {
if ( !isFiltered ) {
insertTodoItem( todo );
}
}
mTodoListView->sort();
break;
case KOGlobals::INCIDENCEDELETED:
if ( todoItem ) {
scheduleRemoveTodoItem( todoItem );
}
break;
default:
TQTimer::singleShot( 0, this, TQT_SLOT( updateView() ) );
}
} else {
// use a TQTimer here, because when marking todos finished using
// the checkbox, this slot gets called, but we cannot update the views
// because we're still inside KOTodoViewItem::stateChange
TQTimer::singleShot(0,this,TQT_SLOT(updateView()));
}
}
void KOTodoView::showDates(const TQDate &, const TQDate &)
{
}
void KOTodoView::showIncidences( const Incidence::List &, const TQDate & )
{
kdDebug(5850) << "KOTodoView::showIncidences( const Incidence::List & ): not yet implemented" << endl;
}
CalPrinterBase::PrintType KOTodoView::printType()
{
return CalPrinterBase::Todolist;
}
void KOTodoView::editItem( TQListViewItem *item )
{
if ( item ) {
emit editIncidenceSignal( static_cast<KOTodoViewItem *>( item )->todo(), TQDate () );
}
}
void KOTodoView::editItem( TQListViewItem *item, const TQPoint &, int )
{
editItem( item );
}
void KOTodoView::showItem( TQListViewItem *item )
{
if ( item ) {
emit showIncidenceSignal( static_cast<KOTodoViewItem *>( item )->todo(), TQDate() );
}
}
void KOTodoView::showItem( TQListViewItem *item, const TQPoint &, int )
{
showItem( item );
}
void KOTodoView::popupMenu( TQListViewItem *item, const TQPoint &, int column )
{
mActiveItem = static_cast<KOTodoViewItem *>( item );
if ( mActiveItem && mActiveItem->todo() &&
!mActiveItem->todo()->isReadOnly() ) {
bool editable = !mActiveItem->todo()->isReadOnly();
mItemPopupMenu->setItemEnabled( ePopupEdit, editable );
mItemPopupMenu->setItemEnabled( ePopupDelete, editable );
mItemPopupMenu->setItemEnabled( ePopupMoveTo, editable );
mItemPopupMenu->setItemEnabled( ePopupCopyTo, editable );
mItemPopupMenu->setItemEnabled( ePopupUnSubTodo, editable );
mItemPopupMenu->setItemEnabled( ePopupUnAllSubTodo, editable );
if ( editable ) {
TQDate date = mActiveItem->todo()->dtDue().date();
if ( mActiveItem->todo()->hasDueDate () ) {
mMovePopupMenu->datePicker()->setDate( date );
} else {
mMovePopupMenu->datePicker()->setDate( TQDate::currentDate() );
}
switch ( column ) {
case ePriorityColumn:
mPriorityPopupMenu->popup( TQCursor::pos() );
break;
case ePercentColumn: {
mPercentageCompletedPopupMenu->popup( TQCursor::pos() );
break;
}
case eDueDateColumn:
mMovePopupMenu->popup( TQCursor::pos() );
break;
case eCategoriesColumn:
getCategoryPopupMenu( mActiveItem )->popup( TQCursor::pos() );
break;
default:
mCopyPopupMenu->datePicker()->setDate( date );
mCopyPopupMenu->datePicker()->setDate( TQDate::currentDate() );
mItemPopupMenu->setItemEnabled( ePopupUnSubTodo,
mActiveItem->todo()->relatedTo() );
mItemPopupMenu->setItemEnabled( ePopupUnAllSubTodo,
!mActiveItem->todo()->relations().isEmpty() );
mItemPopupMenu->popup( TQCursor::pos() );
}
} else {
mItemPopupMenu->popup( TQCursor::pos() );
}
} else mPopupMenu->popup( TQCursor::pos() );
}
void KOTodoView::newTodo()
{
kdDebug() << k_funcinfo << endl;
emit newTodoSignal( 0/*ResourceCalendar*/, TQString()/*subResource*/,
TQDate::currentDate().addDays(7) );
}
void KOTodoView::newSubTodo()
{
if (mActiveItem) {
emit newSubTodoSignal(mActiveItem->todo());
}
}
void KOTodoView::editTodo()
{
editItem( mActiveItem );
}
void KOTodoView::showTodo()
{
showItem( mActiveItem );
}
void KOTodoView::printTodo()
{
#ifndef KORG_NOPRINTER
KOCoreHelper helper;
CalPrinter printer( this, BaseView::calendar(), &helper );
connect( this, TQT_SIGNAL(configChanged()), &printer, TQT_SLOT(updateConfig()) );
Incidence::List selectedIncidences;
selectedIncidences.append( mActiveItem->todo() );
TQDateTime todoDate;
if ( mActiveItem->todo() && mActiveItem->todo()->hasStartDate() ) {
todoDate = mActiveItem->todo()->dtStart();
} else {
todoDate = mActiveItem->todo()->dtDue();
}
printer.print( KOrg::CalPrinterBase::Incidence,
todoDate.date(), todoDate.date(), selectedIncidences );
#endif
}
void KOTodoView::deleteTodo()
{
if (mActiveItem) {
emit deleteIncidenceSignal( mActiveItem->todo() );
}
}
void KOTodoView::setNewPriority(int index)
{
if ( !mActiveItem || !mChanger ) return;
Todo *todo = mActiveItem->todo();
if ( !todo->isReadOnly () &&
mChanger->beginChange( todo, 0, TQString() ) ) {
Todo *oldTodo = todo->clone();
todo->setPriority(mPriority[index]);
mActiveItem->construct();
mChanger->changeIncidence( oldTodo, todo, KOGlobals::PRIORITY_MODIFIED, this );
mChanger->endChange( todo, 0, TQString() );
delete oldTodo;
}
}
void KOTodoView::setNewPercentage( KOTodoViewItem *item, int percentage )
{
kdDebug(5850) << "KOTodoView::setNewPercentage( " << percentage << "), item = " << item << endl;
if ( !item || !mChanger ) return;
Todo *todo = item->todo();
if ( !todo ) return;
if ( !todo->isReadOnly () &&
mChanger->beginChange( todo, 0, TQString() ) ) {
Todo *oldTodo = todo->clone();
/* Old code to make sub-items's percentage related to this one's:
TQListViewItem *myChild = firstChild();
KOTodoViewItem *item;
while( myChild ) {
item = static_cast<KOTodoViewItem*>(myChild);
item->stateChange(state);
myChild = myChild->nextSibling();
}*/
if ( percentage == 100 ) {
todo->setCompleted( TQDateTime::currentDateTime() );
// If the todo does recur, it doesn't get set as completed. However, the
// item is still checked. Uncheck it again.
if ( !todo->isCompleted() ) {
item->setState( TQCheckListItem::Off );
}
} else {
todo->setPercentComplete( percentage );
}
item->construct();
if ( todo->doesRecur() && percentage == 100 )
mChanger->changeIncidence( oldTodo, todo,
KOGlobals::COMPLETION_MODIFIED_WITH_RECURRENCE, this );
else
mChanger->changeIncidence( oldTodo, todo,
KOGlobals::COMPLETION_MODIFIED, this );
mChanger->endChange( todo, 0, TQString() );
delete oldTodo;
} else {
item->construct();
kdDebug(5850) << "No active item, active item is read-only, or locking failed" << endl;
}
}
void KOTodoView::setNewPercentage( int index )
{
setNewPercentage( mActiveItem, mPercentage[index] );
}
void KOTodoView::setNewDate( TQDate date )
{
if ( !mActiveItem || !mChanger ) return;
Todo *todo = mActiveItem->todo();
if ( !todo ) return;
if ( !todo->isReadOnly() && mChanger->beginChange( todo, 0, TQString() ) ) {
Todo *oldTodo = todo->clone();
TQDateTime dt;
dt.setDate( date );
if ( !todo->doesFloat() ) {
dt.setTime( todo->dtDue().time() );
}
todo->setHasDueDate( !date.isNull() );
todo->setDtDue( dt );
mActiveItem->construct();
mChanger->changeIncidence( oldTodo, todo, KOGlobals::COMPLETION_MODIFIED, this );
mChanger->endChange( todo, 0, TQString() );
delete oldTodo;
} else {
kdDebug(5850) << "No active item, active item is read-only, or locking failed" << endl;
}
}
void KOTodoView::copyTodoToDate( TQDate date )
{
TQDateTime dt( date );
if ( mActiveItem && mChanger ) {
Todo *oldTodo = mActiveItem->todo();
Todo *newTodo = oldTodo->clone();
newTodo->recreate();
newTodo->setHasDueDate( !date.isNull() );
if ( oldTodo->hasDueDate() && !oldTodo->doesFloat() ) {
dt.setTime( oldTodo->dtDue().time() );
}
newTodo->setDtDue( dt );
newTodo->setPercentComplete( 0 );
TQPair<ResourceCalendar *, TQString>p =
CalHelper::incSubResourceCalendar( calendar(), mActiveItem->todo() );
mChanger->addIncidence( newTodo, p.first, p.second, this );
}
}
TQPopupMenu *KOTodoView::getCategoryPopupMenu( KOTodoViewItem *todoItem )
{
TQPopupMenu *tempMenu = new TQPopupMenu( this );
TQStringList checkedCategories = todoItem->todo()->categories();
tempMenu->setCheckable( true );
TQStringList::Iterator it;
for ( it = KOPrefs::instance()->mCustomCategories.begin();
it != KOPrefs::instance()->mCustomCategories.end();
++it ) {
int index = tempMenu->insertItem( *it );
mCategory[ index ] = *it;
if ( checkedCategories.find( *it ) != checkedCategories.end() )
tempMenu->setItemChecked( index, true );
}
connect ( tempMenu, TQT_SIGNAL( activated( int ) ),
TQT_SLOT( changedCategories( int ) ) );
return tempMenu;
}
void KOTodoView::changedCategories(int index)
{
if ( !mActiveItem || !mChanger ) return;
Todo *todo = mActiveItem->todo();
if ( !todo ) return;
if ( !todo->isReadOnly() && mChanger->beginChange( todo, 0, TQString() ) ) {
Todo *oldTodo = todo->clone();
TQStringList categories = todo->categories ();
if ( categories.find( mCategory[index] ) != categories.end() )
categories.remove( mCategory[index] );
else
categories.insert( categories.end(), mCategory[index] );
categories.sort();
todo->setCategories( categories );
mActiveItem->construct();
mChanger->changeIncidence( oldTodo, todo, KOGlobals::CATEGORY_MODIFIED, this );
mChanger->endChange( todo, 0, TQString() );
delete oldTodo;
} else {
kdDebug(5850) << "No active item, active item is read-only, or locking failed" << endl;
}
}
void KOTodoView::setDocumentId( const TQString &id )
{
kdDebug(5850) << "KOTodoView::setDocumentId()" << endl;
mDocPrefs->setDoc( id );
}
void KOTodoView::itemStateChanged( TQListViewItem *item )
{
if (!item) return;
KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
// kdDebug(5850) << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
}
void KOTodoView::setNewPercentageDelayed( KOTodoViewItem *item, int percentage )
{
mPercentChangedMap.append( tqMakePair( item, percentage ) );
TQTimer::singleShot( 0, this, TQT_SLOT( processDelayedNewPercentage() ) );
}
void KOTodoView::processDelayedNewPercentage()
{
TQValueList< TQPair< KOTodoViewItem *, int> >::Iterator it;
for ( it = mPercentChangedMap.begin(); it != mPercentChangedMap.end(); ++it )
setNewPercentage( (*it).first, (*it).second );
mPercentChangedMap.clear();
}
void KOTodoView::saveLayout(TDEConfig *config, const TQString &group) const
{
mTodoListView->saveLayout(config,group);
}
void KOTodoView::restoreLayout(TDEConfig *config, const TQString &group)
{
mTodoListView->restoreLayout(config,group);
}
void KOTodoView::processSelectionChange()
{
// kdDebug(5850) << "KOTodoView::processSelectionChange()" << endl;
KOTodoViewItem *item =
static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
if ( !item ) {
emit incidenceSelected( 0, TQDate() );
} else {
if ( selectedIncidenceDates().isEmpty() ) {
emit incidenceSelected( item->todo(), TQDate() );
} else {
emit incidenceSelected( item->todo(), selectedIncidenceDates().first() );
}
}
}
void KOTodoView::clearSelection()
{
mTodoListView->selectAll( false );
}
void KOTodoView::purgeCompleted()
{
emit purgeCompletedSignal();
}
void KOTodoView::addQuickTodo()
{
if ( ! mQuickAdd->text().stripWhiteSpace().isEmpty() ) {
Todo *todo = new Todo();
todo->setSummary( mQuickAdd->text() );
todo->setOrganizer( Person( KOPrefs::instance()->fullName(),
KOPrefs::instance()->email() ) );
if ( !mChanger->addIncidence( todo, 0, TQString(), this ) ) {
delete todo;
return;
}
mQuickAdd->setText( TQString() );
}
}
void KOTodoView::setIncidenceChanger( IncidenceChangerBase *changer )
{
mChanger = changer;
mTodoListView->setIncidenceChanger( changer );
}
|