summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-06-17 07:51:48 (UTC)
committer zautrix <zautrix>2005-06-17 07:51:48 (UTC)
commit825c34c11200f8ff0229cfb00b82b1880ef55b94 (patch) (unidiff)
tree243df776d77afe55ca36ca8a78586a9e2fca1888
parenta04fff3ce192e0bebf9243a1fbedb97cf7108d2b (diff)
downloadkdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.zip
kdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.tar.gz
kdepimpi-825c34c11200f8ff0229cfb00b82b1880ef55b94.tar.bz2
fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoview.cpp56
-rw-r--r--korganizer/kotodoview.h18
-rw-r--r--korganizer/kotodoviewitem.cpp2
-rw-r--r--libkcal/todo.cpp10
-rw-r--r--libkcal/todo.h1
5 files changed, 81 insertions, 6 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index b2ff33b..99e6a3a 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,188 +1,231 @@
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#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28#include <qdialog.h>
29#include <qlabel.h>
30#include <qpushbutton.h>
28 31
29#include <qinputdialog.h> 32#include <qinputdialog.h>
30 33
31#include <qvbox.h> 34#include <qvbox.h>
32#include <kdebug.h> 35#include <kdebug.h>
33#include "koprefs.h" 36#include "koprefs.h"
34#include <klocale.h> 37#include <klocale.h>
35#include <kglobal.h> 38#include <kglobal.h>
36#include <kiconloader.h> 39#include <kiconloader.h>
37#include <kmessagebox.h> 40#include <kmessagebox.h>
38 41
39#include <libkcal/icaldrag.h> 42#include <libkcal/icaldrag.h>
40#include <libkcal/vcaldrag.h> 43#include <libkcal/vcaldrag.h>
41#include <libkcal/calfilter.h> 44#include <libkcal/calfilter.h>
42#include <libkcal/dndfactory.h> 45#include <libkcal/dndfactory.h>
43#include <libkcal/calendarresources.h> 46#include <libkcal/calendarresources.h>
44#include <libkcal/resourcecalendar.h> 47#include <libkcal/resourcecalendar.h>
45#include <kresources/resourceselectdialog.h> 48#include <kresources/resourceselectdialog.h>
46#include <libkcal/kincidenceformatter.h> 49#include <libkcal/kincidenceformatter.h>
47#ifndef DESKTOP_VERSION 50#ifndef DESKTOP_VERSION
48#include <qpe/qpeapplication.h> 51#include <qpe/qpeapplication.h>
49#else 52#else
50#include <qapplication.h> 53#include <qapplication.h>
51#endif 54#endif
52#ifndef KORG_NOPRINTER 55#ifndef KORG_NOPRINTER
53#include "calprinter.h" 56#include "calprinter.h"
54#endif 57#endif
55#include "docprefs.h" 58#include "docprefs.h"
56 59
57#include "kotodoview.h" 60#include "kotodoview.h"
58using namespace KOrg; 61using namespace KOrg;
59 62
60 63
64KOStopTodoPrefs::KOStopTodoPrefs( Todo* todo, QWidget *parent, const char *name ) :
65 QDialog( parent, name, true )
66{
67 mTodo = todo;
68 setCaption( i18n("Stop todo") );
69 QVBoxLayout* lay = new QVBoxLayout( this );
70 lay->setSpacing( 3 );
71 lay->setMargin( 3 );
72 QLabel * lab = new QLabel( i18n("%1\nis running!").arg( todo->summary() ), this );
73 lay->addWidget( lab );
74 lab->setAlignment( AlignHCenter );
75
76 QPushButton * ok = new QPushButton( i18n("Stop and save"), this );
77 lay->addWidget( ok );
78 QPushButton * cancel = new QPushButton( i18n("Continue running"), this );
79 lay->addWidget( cancel );
80 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
81 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
82 ok = new QPushButton( i18n("Stop - do not save"), this );
83 connect ( ok,SIGNAL(clicked() ),this , SLOT ( doNotSave() ) );
84 lay->addWidget( ok );
85 resize( 200, 200 );
86}
87
88void KOStopTodoPrefs::accept()
89{
90 qDebug("KOStopTodoPrefs::accept() ");
91 QDialog::accept();
92}
93void KOStopTodoPrefs::doNotSave()
94{
95
96 int result = KMessageBox::warningContinueCancel(this,
97 i18n("Do you really want to set\nthe state to stopped\nwithout saving the data?"),mTodo->summary() );
98 if (result != KMessageBox::Continue) return;
99 mTodo->stopRunning();
100 QDialog::accept();
101}
102
103
61class KOTodoViewWhatsThis :public QWhatsThis 104class KOTodoViewWhatsThis :public QWhatsThis
62{ 105{
63public: 106public:
64 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 107 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
65 108
66protected: 109protected:
67 virtual QString text( const QPoint& p) 110 virtual QString text( const QPoint& p)
68 { 111 {
69 return _view->getWhatsThisText(p) ; 112 return _view->getWhatsThisText(p) ;
70 } 113 }
71private: 114private:
72 QWidget* _wid; 115 QWidget* _wid;
73 KOTodoView * _view; 116 KOTodoView * _view;
74}; 117};
75 118
76KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 119KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
77 const char *name) : 120 const char *name) :
78 KListView(parent,name) 121 KListView(parent,name)
79{ 122{
80 mName = QString ( name ); 123 mName = QString ( name );
81 mCalendar = calendar; 124 mCalendar = calendar;
82#ifndef DESKTOP_VERSION 125#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 126 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
84#endif 127#endif
85 mOldCurrent = 0; 128 mOldCurrent = 0;
86 mMousePressed = false; 129 mMousePressed = false;
87 130
88 setAcceptDrops(true); 131 setAcceptDrops(true);
89 viewport()->setAcceptDrops(true); 132 viewport()->setAcceptDrops(true);
90 int size = 16; 133 int size = 16;
91 if (qApp->desktop()->width() < 300 ) 134 if (qApp->desktop()->width() < 300 )
92 size = 12; 135 size = 12;
93 setTreeStepSize( size + 6 ); 136 setTreeStepSize( size + 6 );
94 137
95} 138}
96 139
97void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 140void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
98{ 141{
99#ifndef KORG_NODND 142#ifndef KORG_NODND
100// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 143// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
101 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 144 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
102 !QTextDrag::canDecode( e ) ) { 145 !QTextDrag::canDecode( e ) ) {
103 e->ignore(); 146 e->ignore();
104 return; 147 return;
105 } 148 }
106 149
107 mOldCurrent = currentItem(); 150 mOldCurrent = currentItem();
108#endif 151#endif
109} 152}
110 153
111 154
112void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 155void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
113{ 156{
114#ifndef KORG_NODND 157#ifndef KORG_NODND
115// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 158// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
116 159
117 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 160 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
118 !QTextDrag::canDecode( e ) ) { 161 !QTextDrag::canDecode( e ) ) {
119 e->ignore(); 162 e->ignore();
120 return; 163 return;
121 } 164 }
122 165
123 e->accept(); 166 e->accept();
124#endif 167#endif
125} 168}
126 169
127void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 170void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
128{ 171{
129#ifndef KORG_NODND 172#ifndef KORG_NODND
130// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 173// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
131 174
132 setCurrentItem(mOldCurrent); 175 setCurrentItem(mOldCurrent);
133 setSelected(mOldCurrent,true); 176 setSelected(mOldCurrent,true);
134#endif 177#endif
135} 178}
136 179
137void KOTodoListView::contentsDropEvent(QDropEvent *e) 180void KOTodoListView::contentsDropEvent(QDropEvent *e)
138{ 181{
139#ifndef KORG_NODND 182#ifndef KORG_NODND
140// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 183// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
141 184
142 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 185 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
143 !QTextDrag::canDecode( e ) ) { 186 !QTextDrag::canDecode( e ) ) {
144 e->ignore(); 187 e->ignore();
145 return; 188 return;
146 } 189 }
147 190
148 DndFactory factory( mCalendar ); 191 DndFactory factory( mCalendar );
149 Todo *todo = factory.createDropTodo(e); 192 Todo *todo = factory.createDropTodo(e);
150 193
151 if (todo) { 194 if (todo) {
152 e->acceptAction(); 195 e->acceptAction();
153 196
154 KOTodoViewItem *destination = 197 KOTodoViewItem *destination =
155 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 198 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
156 Todo *destinationEvent = 0; 199 Todo *destinationEvent = 0;
157 if (destination) destinationEvent = destination->todo(); 200 if (destination) destinationEvent = destination->todo();
158 201
159 Todo *existingTodo = mCalendar->todo(todo->uid()); 202 Todo *existingTodo = mCalendar->todo(todo->uid());
160 203
161 if(existingTodo) { 204 if(existingTodo) {
162 Incidence *to = destinationEvent; 205 Incidence *to = destinationEvent;
163 while(to) { 206 while(to) {
164 if (to->uid() == todo->uid()) { 207 if (to->uid() == todo->uid()) {
165 KMessageBox::sorry(this, 208 KMessageBox::sorry(this,
166 i18n("Cannot move Todo to itself\nor a child of itself"), 209 i18n("Cannot move Todo to itself\nor a child of itself"),
167 i18n("Drop Todo")); 210 i18n("Drop Todo"));
168 delete todo; 211 delete todo;
169 return; 212 return;
170 } 213 }
171 to = to->relatedTo(); 214 to = to->relatedTo();
172 } 215 }
173 internalDrop = true; 216 internalDrop = true;
174 if ( destinationEvent ) 217 if ( destinationEvent )
175 reparentTodoSignal( destinationEvent, existingTodo ); 218 reparentTodoSignal( destinationEvent, existingTodo );
176 else 219 else
177 unparentTodoSignal(existingTodo); 220 unparentTodoSignal(existingTodo);
178 delete todo; 221 delete todo;
179 } else { 222 } else {
180 mCalendar->addTodo(todo); 223 mCalendar->addTodo(todo);
181 emit todoDropped(todo, KOGlobals::EVENTADDED); 224 emit todoDropped(todo, KOGlobals::EVENTADDED);
182 if ( destinationEvent ) 225 if ( destinationEvent )
183 reparentTodoSignal( destinationEvent, todo ); 226 reparentTodoSignal( destinationEvent, todo );
184 } 227 }
185 } 228 }
186 else { 229 else {
187 QString text; 230 QString text;
188 if (QTextDrag::decode(e,text)) { 231 if (QTextDrag::decode(e,text)) {
@@ -1002,271 +1045,276 @@ void KOTodoView::beamTodo()
1002 1045
1003 1046
1004void KOTodoView::showTodo() 1047void KOTodoView::showTodo()
1005{ 1048{
1006 if (mActiveItem) { 1049 if (mActiveItem) {
1007 emit showTodoSignal(mActiveItem->todo()); 1050 emit showTodoSignal(mActiveItem->todo());
1008 } 1051 }
1009} 1052}
1010 1053
1011void KOTodoView::deleteTodo() 1054void KOTodoView::deleteTodo()
1012{ 1055{
1013 if (mActiveItem) { 1056 if (mActiveItem) {
1014 emit deleteTodoSignal(mActiveItem->todo()); 1057 emit deleteTodoSignal(mActiveItem->todo());
1015 } 1058 }
1016} 1059}
1017 1060
1018void KOTodoView::setNewPriority(int index) 1061void KOTodoView::setNewPriority(int index)
1019{ 1062{
1020 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1063 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1021 mActiveItem->todo()->setPriority(mPriority[index]); 1064 mActiveItem->todo()->setPriority(mPriority[index]);
1022 mActiveItem->construct(); 1065 mActiveItem->construct();
1023 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 1066 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
1024 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1067 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1025 } 1068 }
1026} 1069}
1027 1070
1028void KOTodoView::setNewPercentage(int index) 1071void KOTodoView::setNewPercentage(int index)
1029{ 1072{
1030 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1073 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1031 1074
1032 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 1075 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
1033 mActiveItem->setOn( true ); 1076 mActiveItem->setOn( true );
1034 return; 1077 return;
1035 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 1078 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
1036 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 1079 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
1037 if ( par && par->isOn() ) 1080 if ( par && par->isOn() )
1038 par->setOn( false ); 1081 par->setOn( false );
1039 } 1082 }
1040 if (mPercentage[index] == 100) { 1083 if (mPercentage[index] == 100) {
1041 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 1084 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
1042 } else { 1085 } else {
1043 mActiveItem->todo()->setCompleted(false); 1086 mActiveItem->todo()->setCompleted(false);
1044 } 1087 }
1045 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 1088 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
1046 mActiveItem->construct(); 1089 mActiveItem->construct();
1047 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 1090 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
1048 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1091 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1049 } 1092 }
1050} 1093}
1051 1094
1052 1095
1053QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 1096QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
1054{ 1097{
1055 QPopupMenu* tempMenu = new QPopupMenu (this); 1098 QPopupMenu* tempMenu = new QPopupMenu (this);
1056 QStringList checkedCategories = todoItem->todo()->categories (); 1099 QStringList checkedCategories = todoItem->todo()->categories ();
1057 1100
1058 tempMenu->setCheckable (true); 1101 tempMenu->setCheckable (true);
1059 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 1102 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
1060 it != KOPrefs::instance()->mCustomCategories.end (); 1103 it != KOPrefs::instance()->mCustomCategories.end ();
1061 ++it) { 1104 ++it) {
1062 int index = tempMenu->insertItem (*it); 1105 int index = tempMenu->insertItem (*it);
1063 mCategory[index] = *it; 1106 mCategory[index] = *it;
1064 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 1107 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
1065 } 1108 }
1066 1109
1067 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 1110 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
1068 return tempMenu; 1111 return tempMenu;
1069 1112
1070 1113
1071} 1114}
1072void KOTodoView::changedCategories(int index) 1115void KOTodoView::changedCategories(int index)
1073{ 1116{
1074 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 1117 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
1075 QStringList categories = mActiveItem->todo()->categories (); 1118 QStringList categories = mActiveItem->todo()->categories ();
1076 QString colcat = categories.first(); 1119 QString colcat = categories.first();
1077 if (categories.find (mCategory[index]) != categories.end ()) 1120 if (categories.find (mCategory[index]) != categories.end ())
1078 categories.remove (mCategory[index]); 1121 categories.remove (mCategory[index]);
1079 else 1122 else
1080 categories.insert (categories.end(), mCategory[index]); 1123 categories.insert (categories.end(), mCategory[index]);
1081 categories.sort (); 1124 categories.sort ();
1082 if ( !colcat.isEmpty() ) { 1125 if ( !colcat.isEmpty() ) {
1083 if ( categories.find ( colcat ) != categories.end () ) { 1126 if ( categories.find ( colcat ) != categories.end () ) {
1084 categories.remove( colcat ); 1127 categories.remove( colcat );
1085 categories.prepend( colcat ); 1128 categories.prepend( colcat );
1086 } 1129 }
1087 } 1130 }
1088 mActiveItem->todo()->setCategories (categories); 1131 mActiveItem->todo()->setCategories (categories);
1089 mActiveItem->construct(); 1132 mActiveItem->construct();
1090 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1133 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1091 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1134 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1092 } 1135 }
1093} 1136}
1094void KOTodoView::itemDoubleClicked(QListViewItem *item) 1137void KOTodoView::itemDoubleClicked(QListViewItem *item)
1095{ 1138{
1096 if ( pendingSubtodo != 0 ) { 1139 if ( pendingSubtodo != 0 ) {
1097 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1140 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1098 } 1141 }
1099 pendingSubtodo = 0; 1142 pendingSubtodo = 0;
1100 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() ); 1143 //int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() );
1101 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() ); 1144 int row = mTodoListView->header()->sectionAt ( mTodoListView->viewportToContents(mTodoListView->viewport()->mapFromGlobal( QCursor::pos())) .x() );
1102 //qDebug("ROW %d ", row); 1145 //qDebug("ROW %d ", row);
1103 if (!item) { 1146 if (!item) {
1104 newTodo(); 1147 newTodo();
1105 return; 1148 return;
1106 } else { 1149 } else {
1107 if ( row == 2 || row == 1 ) { 1150 if ( row == 2 || row == 1 ) {
1108 mActiveItem = (KOTodoViewItem *) item; 1151 mActiveItem = (KOTodoViewItem *) item;
1109 newSubTodo(); 1152 newSubTodo();
1110 return; 1153 return;
1111 } 1154 }
1112 if ( row == 5 || row == 6 ) { 1155 if ( row == 5 || row == 6 ) {
1113 mActiveItem = (KOTodoViewItem *) item; 1156 mActiveItem = (KOTodoViewItem *) item;
1114 toggleRunningItem(); 1157 toggleRunningItem();
1115 return; 1158 return;
1116 } 1159 }
1117 } 1160 }
1118 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1161 if ( KOPrefs::instance()->mEditOnDoubleClick )
1119 editItem( item ); 1162 editItem( item );
1120 else 1163 else
1121 showItem( item , QPoint(), 0 ); 1164 showItem( item , QPoint(), 0 );
1122} 1165}
1123void KOTodoView::toggleRunningItem() 1166void KOTodoView::toggleRunningItem()
1124{ 1167{
1125 // qDebug("KOTodoView::toggleRunning() "); 1168 // qDebug("KOTodoView::toggleRunning() ");
1126 if ( ! mActiveItem ) 1169 if ( ! mActiveItem )
1127 return; 1170 return;
1128 Todo * t = mActiveItem->todo(); 1171 Todo * t = mActiveItem->todo();
1129 if ( t->isRunning() ) { 1172 if ( t->isRunning() ) {
1130#if 0
1131 int result = KMessageBox::warningContinueCancel(this,
1132 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop todo"),i18n("Cancel"), true);
1133#endif
1134 1173
1174
1175 KOStopTodoPrefs tp ( t, this );
1176 tp.exec();
1177
1178
1179#if 0
1135 int result = KMessageBox::warningYesNoCancel(this, 1180 int result = KMessageBox::warningYesNoCancel(this,
1136 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop"),i18n("Stop+note")); 1181 i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is started"),i18n("Stop"),i18n("Stop+note"));
1137 if (result == KMessageBox::Cancel) return; 1182 if (result == KMessageBox::Cancel) return;
1138 if ( result == KMessageBox::No ) { 1183 if ( result == KMessageBox::No ) {
1139 QString comment = QInputDialog::getText(mActiveItem->text(0).left( 25 ),i18n("Comment for todo:") ); 1184 QString comment = QInputDialog::getText(mActiveItem->text(0).left( 25 ),i18n("Comment for todo:") );
1140 t->setRunningFalse( comment ); 1185 t->setRunningFalse( comment );
1141 } else { 1186 } else {
1142 t->setRunning( false ); 1187 t->setRunning( false );
1143 } 1188 }
1144 mActiveItem->construct(); 1189 mActiveItem->construct();
1190
1191
1192#endif
1145 } else { 1193 } else {
1146 int result = KMessageBox::warningContinueCancel(this, 1194 int result = KMessageBox::warningContinueCancel(this,
1147 i18n("The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is stopped"),i18n("Start todo"),i18n("Cancel"), true); 1195 i18n("The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?").arg(mActiveItem->text(0).left( 25 ) ),i18n("Todo is stopped"),i18n("Start todo"),i18n("Cancel"), true);
1148 if (result != KMessageBox::Continue) return; 1196 if (result != KMessageBox::Continue) return;
1149 t->setRunning( true ); 1197 t->setRunning( true );
1150 mActiveItem->construct(); 1198 mActiveItem->construct();
1151 } 1199 }
1152} 1200}
1153 1201
1154void KOTodoView::itemClicked(QListViewItem *item) 1202void KOTodoView::itemClicked(QListViewItem *item)
1155{ 1203{
1156 //qDebug("KOTodoView::itemClicked %d", item); 1204 //qDebug("KOTodoView::itemClicked %d", item);
1157 if (!item) { 1205 if (!item) {
1158 if ( pendingSubtodo != 0 ) { 1206 if ( pendingSubtodo != 0 ) {
1159 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1207 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1160 } 1208 }
1161 pendingSubtodo = 0; 1209 pendingSubtodo = 0;
1162 return; 1210 return;
1163 } 1211 }
1164 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1212 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1165 if ( pendingSubtodo != 0 ) { 1213 if ( pendingSubtodo != 0 ) {
1166 bool allowReparent = true; 1214 bool allowReparent = true;
1167 QListViewItem *par = item; 1215 QListViewItem *par = item;
1168 while ( par ) { 1216 while ( par ) {
1169 if ( par == pendingSubtodo ) { 1217 if ( par == pendingSubtodo ) {
1170 allowReparent = false; 1218 allowReparent = false;
1171 break; 1219 break;
1172 } 1220 }
1173 par = par->parent(); 1221 par = par->parent();
1174 } 1222 }
1175 if ( !allowReparent ) { 1223 if ( !allowReparent ) {
1176 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1224 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1177 pendingSubtodo = 0; 1225 pendingSubtodo = 0;
1178 } else { 1226 } else {
1179 Todo* newParent = todoItem->todo(); 1227 Todo* newParent = todoItem->todo();
1180 Todo* newSub = pendingSubtodo->todo(); 1228 Todo* newSub = pendingSubtodo->todo();
1181 pendingSubtodo = 0; 1229 pendingSubtodo = 0;
1182 emit reparentTodoSignal( newParent,newSub ); 1230 emit reparentTodoSignal( newParent,newSub );
1183 return; 1231 return;
1184 } 1232 }
1185 } 1233 }
1186 1234
1187} 1235}
1188 1236
1189void KOTodoView::setDocumentId( const QString &id ) 1237void KOTodoView::setDocumentId( const QString &id )
1190{ 1238{
1191 1239
1192 mDocPrefs->setDoc( id ); 1240 mDocPrefs->setDoc( id );
1193} 1241}
1194 1242
1195void KOTodoView::itemStateChanged( QListViewItem *item ) 1243void KOTodoView::itemStateChanged( QListViewItem *item )
1196{ 1244{
1197 if (!item) return; 1245 if (!item) return;
1198 1246
1199 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1247 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1200 1248
1201// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1249// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1202 1250
1203 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1251 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1204} 1252}
1205 1253
1206void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1254void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1207{ 1255{
1208 mTodoListView->saveLayout(config,group); 1256 mTodoListView->saveLayout(config,group);
1209} 1257}
1210 1258
1211void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1259void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1212{ 1260{
1213 mTodoListView->restoreLayout(config,group); 1261 mTodoListView->restoreLayout(config,group);
1214} 1262}
1215 1263
1216void KOTodoView::processSelectionChange() 1264void KOTodoView::processSelectionChange()
1217{ 1265{
1218// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1266// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1219 1267
1220 KOTodoViewItem *item = 1268 KOTodoViewItem *item =
1221 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1269 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1222 1270
1223 if ( !item ) { 1271 if ( !item ) {
1224 emit incidenceSelected( 0 ); 1272 emit incidenceSelected( 0 );
1225 } else { 1273 } else {
1226 emit incidenceSelected( item->todo() ); 1274 emit incidenceSelected( item->todo() );
1227 } 1275 }
1228} 1276}
1229 1277
1230void KOTodoView::modified(bool b) 1278void KOTodoView::modified(bool b)
1231{ 1279{
1232 emit isModified(b); 1280 emit isModified(b);
1233} 1281}
1234void KOTodoView::setTodoModified( Todo* todo ) 1282void KOTodoView::setTodoModified( Todo* todo )
1235{ 1283{
1236 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1284 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1237} 1285}
1238void KOTodoView::clearSelection() 1286void KOTodoView::clearSelection()
1239{ 1287{
1240 mTodoListView->selectAll( false ); 1288 mTodoListView->selectAll( false );
1241} 1289}
1242void KOTodoView::setAllOpen() 1290void KOTodoView::setAllOpen()
1243{ 1291{
1244 if ( isFlatDisplay ) { 1292 if ( isFlatDisplay ) {
1245 isFlatDisplay = false; 1293 isFlatDisplay = false;
1246 mPopupMenu->setItemChecked( 8,false ); 1294 mPopupMenu->setItemChecked( 8,false );
1247 updateView(); 1295 updateView();
1248 } else { 1296 } else {
1249 storeCurrentItem(); 1297 storeCurrentItem();
1250 } 1298 }
1251 setOpen(mTodoListView->firstChild(), true); 1299 setOpen(mTodoListView->firstChild(), true);
1252 resetCurrentItem(); 1300 resetCurrentItem();
1253} 1301}
1254void KOTodoView::setAllClose() 1302void KOTodoView::setAllClose()
1255{ 1303{
1256 if ( isFlatDisplay ) { 1304 if ( isFlatDisplay ) {
1257 isFlatDisplay = false; 1305 isFlatDisplay = false;
1258 mPopupMenu->setItemChecked( 8,false ); 1306 mPopupMenu->setItemChecked( 8,false );
1259 updateView(); 1307 updateView();
1260 } else { 1308 } else {
1261 storeCurrentItem(); 1309 storeCurrentItem();
1262 } 1310 }
1263 setOpen(mTodoListView->firstChild(), false); 1311 setOpen(mTodoListView->firstChild(), false);
1264 resetCurrentItem(); 1312 resetCurrentItem();
1265} 1313}
1266void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1314void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1267{ 1315{
1268 1316
1269 while ( item ) { 1317 while ( item ) {
1270 setOpen( item->firstChild(), setOpenI ); 1318 setOpen( item->firstChild(), setOpenI );
1271 item->setOpen( setOpenI ); 1319 item->setOpen( setOpenI );
1272 item = item->nextSibling(); 1320 item = item->nextSibling();
diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h
index 1ffc34a..ceabdba 100644
--- a/korganizer/kotodoview.h
+++ b/korganizer/kotodoview.h
@@ -1,183 +1,201 @@
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#ifndef KOTODOVIEW_H 23#ifndef KOTODOVIEW_H
24#define KOTODOVIEW_H 24#define KOTODOVIEW_H
25 25
26#include <qfont.h> 26#include <qfont.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qdialog.h>
36#include <qlabel.h>
35#include <qlistview.h> 37#include <qlistview.h>
36#include <klistview.h> 38#include <klistview.h>
37 39
38#include <libkcal/calendar.h> 40#include <libkcal/calendar.h>
39#include <libkcal/todo.h> 41#include <libkcal/todo.h>
40 42
41#include <korganizer/baseview.h> 43#include <korganizer/baseview.h>
42 44
43#include "kotodoviewitem.h" 45#include "kotodoviewitem.h"
44#include "koprefs.h" 46#include "koprefs.h"
45#include "koglobals.h" 47#include "koglobals.h"
46#include "datenavigator.h" 48#include "datenavigator.h"
47 49
48class QDragEnterEvent; 50class QDragEnterEvent;
49class QDragMoveEvent; 51class QDragMoveEvent;
50class QDragLeaveEvent; 52class QDragLeaveEvent;
51class QDropEvent; 53class QDropEvent;
52class KOTodoViewWhatsThis; 54class KOTodoViewWhatsThis;
53 55
54class DocPrefs; 56class DocPrefs;
55 57
58
59class KOStopTodoPrefs : public QDialog
60{
61 Q_OBJECT
62 public:
63 KOStopTodoPrefs( Todo* todo, QWidget *parent=0, const char *name=0 ) ;
64
65
66private slots:
67 void doNotSave();
68 void accept();
69private:
70 Todo* mTodo;
71
72};
73
56class KOTodoListView : public KListView 74class KOTodoListView : public KListView
57{ 75{
58 Q_OBJECT 76 Q_OBJECT
59 public: 77 public:
60 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0); 78 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0);
61 virtual ~KOTodoListView() {} 79 virtual ~KOTodoListView() {}
62 80
63 signals: 81 signals:
64 void paintNeeded(); 82 void paintNeeded();
65 void todoDropped(Todo *, int); 83 void todoDropped(Todo *, int);
66 void double_Clicked(QListViewItem *item); 84 void double_Clicked(QListViewItem *item);
67 void reparentTodoSignal( Todo *,Todo * ); 85 void reparentTodoSignal( Todo *,Todo * );
68 void unparentTodoSignal(Todo *); 86 void unparentTodoSignal(Todo *);
69 void deleteTodo( Todo * ); 87 void deleteTodo( Todo * );
70 protected: 88 protected:
71 void wheelEvent (QWheelEvent *e); 89 void wheelEvent (QWheelEvent *e);
72 void contentsDragEnterEvent(QDragEnterEvent *); 90 void contentsDragEnterEvent(QDragEnterEvent *);
73 void contentsDragMoveEvent(QDragMoveEvent *); 91 void contentsDragMoveEvent(QDragMoveEvent *);
74 void contentsDragLeaveEvent(QDragLeaveEvent *); 92 void contentsDragLeaveEvent(QDragLeaveEvent *);
75 void contentsDropEvent(QDropEvent *); 93 void contentsDropEvent(QDropEvent *);
76 94
77 void contentsMousePressEvent(QMouseEvent *); 95 void contentsMousePressEvent(QMouseEvent *);
78 void contentsMouseMoveEvent(QMouseEvent *); 96 void contentsMouseMoveEvent(QMouseEvent *);
79 void contentsMouseReleaseEvent(QMouseEvent *); 97 void contentsMouseReleaseEvent(QMouseEvent *);
80 void contentsMouseDoubleClickEvent(QMouseEvent *); 98 void contentsMouseDoubleClickEvent(QMouseEvent *);
81 99
82 private: 100 private:
83 void paintEvent(QPaintEvent * pevent); 101 void paintEvent(QPaintEvent * pevent);
84 bool internalDrop; 102 bool internalDrop;
85 QString mName; 103 QString mName;
86 Calendar *mCalendar; 104 Calendar *mCalendar;
87 QPoint mPressPos; 105 QPoint mPressPos;
88 bool mMousePressed; 106 bool mMousePressed;
89 QListViewItem *mOldCurrent; 107 QListViewItem *mOldCurrent;
90 bool mFlagKeyPressed; 108 bool mFlagKeyPressed;
91 void keyPressEvent ( QKeyEvent * ) ; 109 void keyPressEvent ( QKeyEvent * ) ;
92 void keyReleaseEvent ( QKeyEvent * ) ; 110 void keyReleaseEvent ( QKeyEvent * ) ;
93}; 111};
94 112
95 113
96/** 114/**
97 This is the line-edit on top of the todoview for fast addition of new todos 115 This is the line-edit on top of the todoview for fast addition of new todos
98*/ 116*/
99class KOQuickTodo : public QLineEdit 117class KOQuickTodo : public QLineEdit
100{ 118{
101 public: 119 public:
102 KOQuickTodo(QWidget *parent=0); 120 KOQuickTodo(QWidget *parent=0);
103 protected: 121 protected:
104 void focusInEvent(QFocusEvent *ev); 122 void focusInEvent(QFocusEvent *ev);
105 void focusOutEvent(QFocusEvent *ev); 123 void focusOutEvent(QFocusEvent *ev);
106}; 124};
107 125
108 126
109/** 127/**
110 This class provides a multi-column list view of todo events. 128 This class provides a multi-column list view of todo events.
111 129
112 @short multi-column list view of todo events. 130 @short multi-column list view of todo events.
113 @author Cornelius Schumacher <schumacher@kde.org> 131 @author Cornelius Schumacher <schumacher@kde.org>
114*/ 132*/
115class KOTodoView : public KOrg::BaseView 133class KOTodoView : public KOrg::BaseView
116{ 134{
117 Q_OBJECT 135 Q_OBJECT
118 public: 136 public:
119 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 ); 137 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 );
120 ~KOTodoView(); 138 ~KOTodoView();
121 139
122 QPtrList<Incidence> selectedIncidences(); 140 QPtrList<Incidence> selectedIncidences();
123 QPtrList<Todo> selectedTodos(); 141 QPtrList<Todo> selectedTodos();
124 142
125 DateList selectedDates() 143 DateList selectedDates()
126 {DateList q; 144 {DateList q;
127 return q;} 145 return q;}
128 146
129 /** Return number of shown dates. TodoView does not show dates, */ 147 /** Return number of shown dates. TodoView does not show dates, */
130 int currentDateCount() { return 0; } 148 int currentDateCount() { return 0; }
131 149
132 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td); 150 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td);
133 151
134 void setDocumentId( const QString & ); 152 void setDocumentId( const QString & );
135 153
136 void saveLayout(KConfig *config, const QString &group) const; 154 void saveLayout(KConfig *config, const QString &group) const;
137 void restoreLayout(KConfig *config, const QString &group); 155 void restoreLayout(KConfig *config, const QString &group);
138 /** Create a popup menu to set categories */ 156 /** Create a popup menu to set categories */
139 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem); 157 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem);
140 void setNavigator( DateNavigator* nav ) {mNavigator = nav;} 158 void setNavigator( DateNavigator* nav ) {mNavigator = nav;}
141 QString getWhatsThisText(QPoint p); 159 QString getWhatsThisText(QPoint p);
142 void clearList() {mTodoListView->clear(); } 160 void clearList() {mTodoListView->clear(); }
143 161
144 public slots: 162 public slots:
145 void updateView(); 163 void updateView();
146 void updateConfig(); 164 void updateConfig();
147 165
148 void changeEventDisplay(Event *, int); 166 void changeEventDisplay(Event *, int);
149 167
150 void showDates(const QDate &start, const QDate &end); 168 void showDates(const QDate &start, const QDate &end);
151 void showEvents(QPtrList<Event> eventList); 169 void showEvents(QPtrList<Event> eventList);
152 170
153 void clearSelection(); 171 void clearSelection();
154 void jumpToDate (); 172 void jumpToDate ();
155 173
156 void editItem(QListViewItem *item); 174 void editItem(QListViewItem *item);
157 void showItem(QListViewItem *item,const QPoint &,int); 175 void showItem(QListViewItem *item,const QPoint &,int);
158 void popupMenu(QListViewItem *item,const QPoint &,int); 176 void popupMenu(QListViewItem *item,const QPoint &,int);
159 void newTodo(); 177 void newTodo();
160 void newSubTodo(); 178 void newSubTodo();
161 void unparentTodo(); 179 void unparentTodo();
162 void reparentTodo(); 180 void reparentTodo();
163 void showTodo(); 181 void showTodo();
164 void editTodo(); 182 void editTodo();
165 void cloneTodo(); 183 void cloneTodo();
166 void cancelTodo(); 184 void cancelTodo();
167 void moveTodo(); 185 void moveTodo();
168 void beamTodo(); 186 void beamTodo();
169 void deleteTodo(); 187 void deleteTodo();
170 188
171 void setNewPriority(int); 189 void setNewPriority(int);
172 void setNewPercentage(int); 190 void setNewPercentage(int);
173 void changedCategories(int); 191 void changedCategories(int);
174 192
175 void setAllOpen(); 193 void setAllOpen();
176 void setAllClose(); 194 void setAllClose();
177 void setAllFlat(); 195 void setAllFlat();
178 void displayAllFlat(); 196 void displayAllFlat();
179 197
180 void purgeCompleted(); 198 void purgeCompleted();
181 void toggleCompleted(); 199 void toggleCompleted();
182 void toggleRunning(); 200 void toggleRunning();
183 void toggleQuickTodo(); 201 void toggleQuickTodo();
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index f62aab8..0cf6e4c 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -235,257 +235,257 @@ void KOTodoViewItem::stateChange(bool state)
235 } 235 }
236 QString keyd = "=="; 236 QString keyd = "==";
237 QString keyt = "=="; 237 QString keyt = "==";
238 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 238 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
239 if ( mTodo->doesRecur() ){ 239 if ( mTodo->doesRecur() ){
240 QDateTime start = mTodo->dtStart(); 240 QDateTime start = mTodo->dtStart();
241 mTodo->setCompleted(state); 241 mTodo->setCompleted(state);
242 if ( start != mTodo->dtStart() ) { 242 if ( start != mTodo->dtStart() ) {
243 if ( state && !mTodo->isCompleted() ) { 243 if ( state && !mTodo->isCompleted() ) {
244 setOn( false ); 244 setOn( false );
245 state = false; 245 state = false;
246 } 246 }
247 } 247 }
248 } else 248 } else
249 mTodo->setCompleted(state); 249 mTodo->setCompleted(state);
250 250
251 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 251 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
252 252
253 if (mTodo->hasDueDate()) { 253 if (mTodo->hasDueDate()) {
254 setText(3, mTodo->dtDueDateStr()); 254 setText(3, mTodo->dtDueDateStr());
255 QDate d = mTodo->dtDue().date(); 255 QDate d = mTodo->dtDue().date();
256 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 256 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
257 setSortKey(3,keyd); 257 setSortKey(3,keyd);
258 if (mTodo->doesFloat()) { 258 if (mTodo->doesFloat()) {
259 setText(4,""); 259 setText(4,"");
260 } 260 }
261 else { 261 else {
262 setText(4,mTodo->dtDueTimeStr()); 262 setText(4,mTodo->dtDueTimeStr());
263 QTime t = mTodo->dtDue().time(); 263 QTime t = mTodo->dtDue().time();
264 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 264 keyt.sprintf("%02d%02d",t.hour(),t.minute());
265 setSortKey(4,keyt); 265 setSortKey(4,keyt);
266 } 266 }
267 } 267 }
268 if (mTodo->hasStartDate()) { 268 if (mTodo->hasStartDate()) {
269 QString skeyt = "=="; 269 QString skeyt = "==";
270 QString skeyd = "=="; 270 QString skeyd = "==";
271 setText(5, mTodo->dtStartDateStr()); 271 setText(5, mTodo->dtStartDateStr());
272 QDate d = mTodo->dtStart().date(); 272 QDate d = mTodo->dtStart().date();
273 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 273 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
274 274
275 if (mTodo->doesFloat()) { 275 if (mTodo->doesFloat()) {
276 setText(6,""); 276 setText(6,"");
277 } 277 }
278 else { 278 else {
279 setText(6,mTodo->dtStartTimeStr()); 279 setText(6,mTodo->dtStartTimeStr());
280 QTime t = mTodo->dtStart().time(); 280 QTime t = mTodo->dtStart().time();
281 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 281 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
282 282
283 } 283 }
284 setSortKey(5,skeyd); 284 setSortKey(5,skeyd);
285 setSortKey(6,skeyt); 285 setSortKey(6,skeyt);
286 } 286 }
287 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 287 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
288 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 288 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
289 289
290 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 290 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
291 if (mTodo->percentComplete()<100) { 291 if (mTodo->percentComplete()<100) {
292 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 292 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
293 else setSortKey(2,QString::number(mTodo->percentComplete())); 293 else setSortKey(2,QString::number(mTodo->percentComplete()));
294 } 294 }
295 else { 295 else {
296 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 296 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
297 else setSortKey(2,QString::number(99)); 297 else setSortKey(2,QString::number(99));
298 } 298 }
299 if ( state ) { 299 if ( state ) {
300 QListViewItem * myChild = firstChild(); 300 QListViewItem * myChild = firstChild();
301 KOTodoViewItem *item; 301 KOTodoViewItem *item;
302 while( myChild ) { 302 while( myChild ) {
303 //qDebug("stateCH "); 303 //qDebug("stateCH ");
304 item = static_cast<KOTodoViewItem*>(myChild); 304 item = static_cast<KOTodoViewItem*>(myChild);
305 item->stateChange(state); 305 item->stateChange(state);
306 myChild = myChild->nextSibling(); 306 myChild = myChild->nextSibling();
307 } 307 }
308 } else { 308 } else {
309 QListViewItem * myChild = parent(); 309 QListViewItem * myChild = parent();
310 if ( myChild ) 310 if ( myChild )
311 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 311 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
312 } 312 }
313 mTodoView->modified(true); 313 mTodoView->modified(true);
314 setMyPixmap(); 314 setMyPixmap();
315 mTodoView->setTodoModified( mTodo ); 315 mTodoView->setTodoModified( mTodo );
316} 316}
317 317
318bool KOTodoViewItem::isAlternate() 318bool KOTodoViewItem::isAlternate()
319{ 319{
320 320
321 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 321 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
322 if (lv && lv->alternateBackground().isValid()) 322 if (lv && lv->alternateBackground().isValid())
323 { 323 {
324 KOTodoViewItem *above = 0; 324 KOTodoViewItem *above = 0;
325 above = static_cast<KOTodoViewItem *>(itemAbove()); 325 above = static_cast<KOTodoViewItem *>(itemAbove());
326 m_known = above ? above->m_known : true; 326 m_known = above ? above->m_known : true;
327 if (m_known) 327 if (m_known)
328 { 328 {
329 m_odd = above ? !above->m_odd : false; 329 m_odd = above ? !above->m_odd : false;
330 } 330 }
331 else 331 else
332 { 332 {
333 KOTodoViewItem *item; 333 KOTodoViewItem *item;
334 bool previous = true; 334 bool previous = true;
335 if (QListViewItem::parent()) 335 if (QListViewItem::parent())
336 { 336 {
337 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 337 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
338 if (item) 338 if (item)
339 previous = item->m_odd; 339 previous = item->m_odd;
340 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 340 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
341 } 341 }
342 else 342 else
343 { 343 {
344 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 344 item = static_cast<KOTodoViewItem *>(lv->firstChild());
345 } 345 }
346 346
347 while(item) 347 while(item)
348 { 348 {
349 item->m_odd = previous = !previous; 349 item->m_odd = previous = !previous;
350 item->m_known = true; 350 item->m_known = true;
351 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 351 item = static_cast<KOTodoViewItem *>(item->nextSibling());
352 } 352 }
353 } 353 }
354 return m_odd; 354 return m_odd;
355 } 355 }
356 return false; 356 return false;
357} 357}
358 358
359void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 359void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
360{ 360{
361 QColorGroup _cg = cg; 361 QColorGroup _cg = cg;
362 QColorGroup::ColorRole role; 362 QColorGroup::ColorRole role;
363 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 363 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor && !mTodo->isRunning())
364 role = QColorGroup::Text; 364 role = QColorGroup::Text;
365 else 365 else
366 role = QColorGroup::Base; 366 role = QColorGroup::Base;
367 //#ifndef KORG_NOLVALTERNATION 367 //#ifndef KORG_NOLVALTERNATION
368 if (isAlternate()) 368 if (isAlternate())
369 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 369 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
370 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 370 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
371 QColor colorToSet; 371 QColor colorToSet;
372 if ( column == 0 && mTodo->calID() > 1 ) { 372 if ( column == 0 && mTodo->calID() > 1 ) {
373 setColor = true; 373 setColor = true;
374 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() ); 374 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() );
375 } else if ( setColor ) { 375 } else if ( setColor ) {
376 QStringList categories = mTodo->categories(); 376 QStringList categories = mTodo->categories();
377 QString cat = categories.first(); 377 QString cat = categories.first();
378 if ( !cat.isEmpty()) { 378 if ( !cat.isEmpty()) {
379 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 379 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
380 } else 380 } else
381 setColor = false; 381 setColor = false;
382 } 382 }
383 bool openMode = !isOpen(); 383 bool openMode = !isOpen();
384 // maybe we are in flat-display-mode 384 // maybe we are in flat-display-mode
385 if ( !firstChild() ) 385 if ( !firstChild() )
386 openMode = false; 386 openMode = false;
387 bool colorRunning = mTodo->isRunning(); 387 bool colorRunning = mTodo->isRunning();
388 if ( ! colorRunning && openMode ) 388 if ( ! colorRunning && openMode )
389 colorRunning = mTodo->hasRunningSub(); 389 colorRunning = mTodo->hasRunningSub();
390 if ( colorRunning ) { 390 if ( colorRunning ) {
391 setColor = true; 391 setColor = true;
392 colorToSet = KOPrefs::instance()->mTodoRunColor; 392 colorToSet = KOPrefs::instance()->mTodoRunColor;
393 } else { 393 } else {
394 int odue = mTodo->hasDueSubTodo( openMode ); 394 int odue = mTodo->hasDueSubTodo( openMode );
395 if (odue == 2) { 395 if (odue == 2) {
396 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 396 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
397 setColor = true; 397 setColor = true;
398 } else if ( odue == 1 ) { 398 } else if ( odue == 1 ) {
399 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 399 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
400 setColor = true; 400 setColor = true;
401 } 401 }
402 } 402 }
403 403
404 404
405 if ( setColor ) { 405 if ( setColor ) {
406 _cg.setColor(role,colorToSet ); 406 _cg.setColor(role,colorToSet );
407 if ( role == QColorGroup::Base) { 407 if ( role == QColorGroup::Base) {
408 int rgb = colorToSet.red(); 408 int rgb = colorToSet.red();
409 rgb += colorToSet.blue()/2; 409 rgb += colorToSet.blue()/2;
410 rgb += colorToSet.green(); 410 rgb += colorToSet.green();
411 if ( rgb < 200 ) 411 if ( rgb < 200 )
412 _cg.setColor(QColorGroup::Text,Qt::white ); 412 _cg.setColor(QColorGroup::Text,Qt::white );
413 } 413 }
414 } 414 }
415 //#endif 415 //#endif
416 if ( column > 0 ){ 416 if ( column > 0 ){
417 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 417 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
418 p->save(); 418 p->save();
419 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 419 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
420 420
421 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 421 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
422 // p->setPen(Qt::black ); //border 422 // p->setPen(Qt::black ); //border
423 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 423 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
424 QColor fc = KOPrefs::instance()->mHighlightColor; 424 QColor fc = KOPrefs::instance()->mHighlightColor;
425 if ( mTodo->percentComplete() == 100 ) 425 if ( mTodo->percentComplete() == 100 )
426 fc = darkGreen; 426 fc = darkGreen;
427 p->drawRect( 2, 2, width-4, height()-4); 427 p->drawRect( 2, 2, width-4, height()-4);
428 p->fillRect( 3, 3, progress, height()-6, 428 p->fillRect( 3, 3, progress, height()-6,
429 fc ); 429 fc );
430 p->restore(); 430 p->restore();
431 } else { 431 } else {
432 QCheckListItem::paintCell(p, _cg, column, width, alignment); 432 QCheckListItem::paintCell(p, _cg, column, width, alignment);
433 } 433 }
434 return; 434 return;
435 } 435 }
436 436
437 int align = alignment; 437 int align = alignment;
438 438
439 if ( !p ) 439 if ( !p )
440 return; 440 return;
441 441
442 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 442 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
443 443
444 QListView *lv = listView(); 444 QListView *lv = listView();
445 if ( !lv ) 445 if ( !lv )
446 return; 446 return;
447 int marg = 2;//lv->itemMargin(); 447 int marg = 2;//lv->itemMargin();
448 int r = 0; 448 int r = 0;
449 QCheckListItem::Type myType = QCheckListItem::CheckBox; 449 QCheckListItem::Type myType = QCheckListItem::CheckBox;
450 int BoxSize = 20; 450 int BoxSize = 20;
451 int boxOffset = 2; 451 int boxOffset = 2;
452 int xOffset = 2; 452 int xOffset = 2;
453 if (qApp->desktop()->width() < 300 ) { 453 if (qApp->desktop()->width() < 300 ) {
454 BoxSize = 14; 454 BoxSize = 14;
455 boxOffset = -1; 455 boxOffset = -1;
456 xOffset = 1; 456 xOffset = 1;
457 // marg = 0; 457 // marg = 0;
458 } 458 }
459 if ( height() < BoxSize ) { 459 if ( height() < BoxSize ) {
460 boxOffset = boxOffset - ((BoxSize - height())/2) ; 460 boxOffset = boxOffset - ((BoxSize - height())/2) ;
461 // qDebug("boxOffset %d height %d", boxOffset, height() ); 461 // qDebug("boxOffset %d height %d", boxOffset, height() );
462 BoxSize = height(); 462 BoxSize = height();
463 463
464 } 464 }
465 //bool winStyle = lv->style() == WindowsStyle; 465 //bool winStyle = lv->style() == WindowsStyle;
466 466
467 int lineStart = 5; 467 int lineStart = 5;
468 if ( myType == Controller ) { 468 if ( myType == Controller ) {
469 if ( !pixmap( 0 ) ) 469 if ( !pixmap( 0 ) )
470 r += BoxSize + 4; 470 r += BoxSize + 4;
471 } else { 471 } else {
472 ASSERT( lv ); //### 472 ASSERT( lv ); //###
473 //QFontMetrics fm( lv->font() ); 473 //QFontMetrics fm( lv->font() );
474 //int d = fm.height(); 474 //int d = fm.height();
475 int x = 0; 475 int x = 0;
476 int y = (height() - BoxSize) / 2; 476 int y = (height() - BoxSize) / 2;
477 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 477 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
478 if ( myType == CheckBox ) { 478 if ( myType == CheckBox ) {
479 if ( isEnabled() ) 479 if ( isEnabled() )
480 p->setPen( QPen( _cg.text(), 1 ) ); 480 p->setPen( QPen( _cg.text(), 1 ) );
481 else 481 else
482 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 482 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
483 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 483 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
484 lineStart = x+marg; 484 lineStart = x+marg;
485 ///////////////////// 485 /////////////////////
486 x++; 486 x++;
487 y++; 487 y++;
488 if ( isOn() ) { 488 if ( isOn() ) {
489 QPointArray a( 7*2 ); 489 QPointArray a( 7*2 );
490 int i, xx, yy; 490 int i, xx, yy;
491 xx = x+xOffset+marg+(boxOffset/2); 491 xx = x+xOffset+marg+(boxOffset/2);
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index e98af3c..d062492 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,226 +1,234 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 70 saveRunningInfoToFile( s );
71} 71}
72void Todo::stopRunning()
73{
74 if ( !mRunning )
75 return;
76 if ( mRunSaveTimer )
77 mRunSaveTimer->stop();
78 mRunning = false;
79}
72void Todo::setRunning( bool run ) 80void Todo::setRunning( bool run )
73{ 81{
74 if ( run == mRunning ) 82 if ( run == mRunning )
75 return; 83 return;
76 //qDebug("Todo::setRunning %d ", run); 84 //qDebug("Todo::setRunning %d ", run);
77 if ( !mRunSaveTimer ) { 85 if ( !mRunSaveTimer ) {
78 mRunSaveTimer = new QTimer ( this ); 86 mRunSaveTimer = new QTimer ( this );
79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
80 } 88 }
81 mRunning = run; 89 mRunning = run;
82 if ( mRunning ) { 90 if ( mRunning ) {
83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
84 mRunStart = QDateTime::currentDateTime(); 92 mRunStart = QDateTime::currentDateTime();
85 } else { 93 } else {
86 mRunSaveTimer->stop(); 94 mRunSaveTimer->stop();
87 saveRunningInfoToFile(); 95 saveRunningInfoToFile();
88 } 96 }
89} 97}
90 98
91void Todo::saveRunningInfoToFile() 99void Todo::saveRunningInfoToFile()
92{ 100{
93 saveRunningInfoToFile( QString::null ); 101 saveRunningInfoToFile( QString::null );
94} 102}
95void Todo::saveRunningInfoToFile( QString comment ) 103void Todo::saveRunningInfoToFile( QString comment )
96{ 104{
97 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 105 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
98 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { 106 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 10 ) {
99 qDebug("Running time < 30 seconds. Skipped. "); 107 qDebug("Running time < 30 seconds. Skipped. ");
100 return; 108 return;
101 } 109 }
102 QString dir = KGlobalSettings::timeTrackerDir(); 110 QString dir = KGlobalSettings::timeTrackerDir();
103 //qDebug("%s ", dir.latin1()); 111 //qDebug("%s ", dir.latin1());
104 QString file = "%1%2%3-%4%5%6-"; 112 QString file = "%1%2%3-%4%5%6-";
105 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 113 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
106 file.replace ( QRegExp (" "), "0" ); 114 file.replace ( QRegExp (" "), "0" );
107 file += uid(); 115 file += uid();
108 //qDebug("File %s ",file.latin1() ); 116 //qDebug("File %s ",file.latin1() );
109 CalendarLocal cal; 117 CalendarLocal cal;
110 cal.setLocalTime(); 118 cal.setLocalTime();
111 Todo * to = (Todo*) clone(); 119 Todo * to = (Todo*) clone();
112 to->setFloats( false ); 120 to->setFloats( false );
113 to->setDtStart( mRunStart ); 121 to->setDtStart( mRunStart );
114 to->setHasStartDate( true ); 122 to->setHasStartDate( true );
115 to->setDtDue( QDateTime::currentDateTime() ); 123 to->setDtDue( QDateTime::currentDateTime() );
116 to->setHasDueDate( true ); 124 to->setHasDueDate( true );
117 to->setUid( file ); 125 to->setUid( file );
118 if ( !comment.isEmpty() ) { 126 if ( !comment.isEmpty() ) {
119 QString des = to->description(); 127 QString des = to->description();
120 if ( des.isEmpty () ) 128 if ( des.isEmpty () )
121 to->setDescription( "TT-Note: " + comment ); 129 to->setDescription( "TT-Note: " + comment );
122 else 130 else
123 to->setDescription( "TT-Note: " + comment +"\n" + des ); 131 to->setDescription( "TT-Note: " + comment +"\n" + des );
124 } 132 }
125 cal.addIncidence( to ); 133 cal.addIncidence( to );
126 ICalFormat format; 134 ICalFormat format;
127 file = dir +"/" +file +".ics"; 135 file = dir +"/" +file +".ics";
128 format.save( &cal, file ); 136 format.save( &cal, file );
129 saveParents(); 137 saveParents();
130 138
131} 139}
132void Todo::saveParents() 140void Todo::saveParents()
133{ 141{
134 if (!relatedTo() ) 142 if (!relatedTo() )
135 return; 143 return;
136 Incidence * inc = relatedTo(); 144 Incidence * inc = relatedTo();
137 if ( inc->typeID() != todoID ) 145 if ( inc->typeID() != todoID )
138 return; 146 return;
139 Todo* to = (Todo*)inc; 147 Todo* to = (Todo*)inc;
140 bool saveTodo = false; 148 bool saveTodo = false;
141 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 149 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
142 QFileInfo fi ( file ); 150 QFileInfo fi ( file );
143 if ( fi.exists() ) { 151 if ( fi.exists() ) {
144 if ( fi.lastModified () < to->lastModified ()) 152 if ( fi.lastModified () < to->lastModified ())
145 saveTodo = true; 153 saveTodo = true;
146 } else { 154 } else {
147 saveTodo = true; 155 saveTodo = true;
148 } 156 }
149 if ( saveTodo ) { 157 if ( saveTodo ) {
150 CalendarLocal cal; 158 CalendarLocal cal;
151 cal.setLocalTime(); 159 cal.setLocalTime();
152 Todo * par = (Todo *) to->clone(); 160 Todo * par = (Todo *) to->clone();
153 cal.addIncidence( par ); 161 cal.addIncidence( par );
154 ICalFormat format; 162 ICalFormat format;
155 format.save( &cal, file ); 163 format.save( &cal, file );
156 } 164 }
157 to->saveParents(); 165 to->saveParents();
158} 166}
159 167
160int Todo::runTime() 168int Todo::runTime()
161{ 169{
162 if ( !mRunning ) 170 if ( !mRunning )
163 return 0; 171 return 0;
164 return mRunStart.secsTo( QDateTime::currentDateTime() ); 172 return mRunStart.secsTo( QDateTime::currentDateTime() );
165} 173}
166bool Todo::hasRunningSub() 174bool Todo::hasRunningSub()
167{ 175{
168 if ( mRunning ) 176 if ( mRunning )
169 return true; 177 return true;
170 Incidence *aTodo; 178 Incidence *aTodo;
171 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 179 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
172 if ( ((Todo*)aTodo)->hasRunningSub() ) 180 if ( ((Todo*)aTodo)->hasRunningSub() )
173 return true; 181 return true;
174 } 182 }
175 return false; 183 return false;
176} 184}
177Incidence *Todo::clone() 185Incidence *Todo::clone()
178{ 186{
179 return new Todo(*this); 187 return new Todo(*this);
180} 188}
181 189
182bool Todo::contains ( Todo* from ) 190bool Todo::contains ( Todo* from )
183{ 191{
184 192
185 if ( !from->summary().isEmpty() ) 193 if ( !from->summary().isEmpty() )
186 if ( !summary().startsWith( from->summary() )) 194 if ( !summary().startsWith( from->summary() ))
187 return false; 195 return false;
188 if ( from->hasStartDate() ) { 196 if ( from->hasStartDate() ) {
189 if ( !hasStartDate() ) 197 if ( !hasStartDate() )
190 return false; 198 return false;
191 if ( from->dtStart() != dtStart()) 199 if ( from->dtStart() != dtStart())
192 return false; 200 return false;
193 } 201 }
194 if ( from->hasDueDate() ){ 202 if ( from->hasDueDate() ){
195 if ( !hasDueDate() ) 203 if ( !hasDueDate() )
196 return false; 204 return false;
197 if ( from->dtDue() != dtDue()) 205 if ( from->dtDue() != dtDue())
198 return false; 206 return false;
199 } 207 }
200 if ( !from->location().isEmpty() ) 208 if ( !from->location().isEmpty() )
201 if ( !location().startsWith( from->location() ) ) 209 if ( !location().startsWith( from->location() ) )
202 return false; 210 return false;
203 if ( !from->description().isEmpty() ) 211 if ( !from->description().isEmpty() )
204 if ( !description().startsWith( from->description() )) 212 if ( !description().startsWith( from->description() ))
205 return false; 213 return false;
206 if ( from->alarms().count() ) { 214 if ( from->alarms().count() ) {
207 Alarm *a = from->alarms().first(); 215 Alarm *a = from->alarms().first();
208 if ( a->enabled() ){ 216 if ( a->enabled() ){
209 if ( !alarms().count() ) 217 if ( !alarms().count() )
210 return false; 218 return false;
211 Alarm *b = alarms().first(); 219 Alarm *b = alarms().first();
212 if( ! b->enabled() ) 220 if( ! b->enabled() )
213 return false; 221 return false;
214 if ( ! (a->offset() == b->offset() )) 222 if ( ! (a->offset() == b->offset() ))
215 return false; 223 return false;
216 } 224 }
217 } 225 }
218 226
219 QStringList cat = categories(); 227 QStringList cat = categories();
220 QStringList catFrom = from->categories(); 228 QStringList catFrom = from->categories();
221 QString nCat; 229 QString nCat;
222 unsigned int iii; 230 unsigned int iii;
223 for ( iii = 0; iii < catFrom.count();++iii ) { 231 for ( iii = 0; iii < catFrom.count();++iii ) {
224 nCat = catFrom[iii]; 232 nCat = catFrom[iii];
225 if ( !nCat.isEmpty() ) 233 if ( !nCat.isEmpty() )
226 if ( !cat.contains( nCat )) { 234 if ( !cat.contains( nCat )) {
diff --git a/libkcal/todo.h b/libkcal/todo.h
index 6fc4d4b..42db025 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -1,152 +1,153 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef TODO_H 20#ifndef TODO_H
21#define TODO_H 21#define TODO_H
22// 22//
23// Todo component, representing a VTODO object 23// Todo component, representing a VTODO object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28#include <qtimer.h> 28#include <qtimer.h>
29 29
30namespace KCal { 30namespace KCal {
31 31
32/** 32/**
33 This class provides a Todo in the sense of RFC2445. 33 This class provides a Todo in the sense of RFC2445.
34*/ 34*/
35 class Todo : public QObject,public Incidence 35 class Todo : public QObject,public Incidence
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 public: 38 public:
39 Todo(); 39 Todo();
40 Todo(const Todo &); 40 Todo(const Todo &);
41 ~Todo(); 41 ~Todo();
42 typedef ListBase<Todo> List; 42 typedef ListBase<Todo> List;
43 QCString type() const { return "Todo"; } 43 QCString type() const { return "Todo"; }
44 IncTypeID typeID() const { return todoID; } 44 IncTypeID typeID() const { return todoID; }
45 45
46 /** Return an exact copy of this todo. */ 46 /** Return an exact copy of this todo. */
47 Incidence *clone(); 47 Incidence *clone();
48 QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; 48 QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const;
49 49
50 /** for setting the todo's due date/time with a QDateTime. */ 50 /** for setting the todo's due date/time with a QDateTime. */
51 void setDtDue(const QDateTime &dtDue); 51 void setDtDue(const QDateTime &dtDue);
52 /** returns an event's Due date/time as a QDateTime. */ 52 /** returns an event's Due date/time as a QDateTime. */
53 QDateTime dtDue() const; 53 QDateTime dtDue() const;
54 /** returns an event's due time as a string formatted according to the 54 /** returns an event's due time as a string formatted according to the
55 users locale settings */ 55 users locale settings */
56 QString dtDueTimeStr() const; 56 QString dtDueTimeStr() const;
57 /** returns an event's due date as a string formatted according to the 57 /** returns an event's due date as a string formatted according to the
58 users locale settings */ 58 users locale settings */
59 QString dtDueDateStr(bool shortfmt=true) const; 59 QString dtDueDateStr(bool shortfmt=true) const;
60 /** returns an event's due date and time as a string formatted according 60 /** returns an event's due date and time as a string formatted according
61 to the users locale settings */ 61 to the users locale settings */
62 QString dtDueStr(bool shortfmt=true) const; 62 QString dtDueStr(bool shortfmt=true) const;
63 63
64 /** returns TRUE or FALSE depending on whether the todo has a due date */ 64 /** returns TRUE or FALSE depending on whether the todo has a due date */
65 bool hasDueDate() const; 65 bool hasDueDate() const;
66 /** sets the event's hasDueDate value. */ 66 /** sets the event's hasDueDate value. */
67 void setHasDueDate(bool f); 67 void setHasDueDate(bool f);
68 68
69 /* 69 /*
70 Looks for a subtodo (including itself ) which is not complete and is 70 Looks for a subtodo (including itself ) which is not complete and is
71 - overdue, or 71 - overdue, or
72 - due today. 72 - due today.
73 It returns 0 for nothing found, 73 It returns 0 for nothing found,
74 1 for found a todo which is due today and no overdue found 74 1 for found a todo which is due today and no overdue found
75 2 for found a overdue todo 75 2 for found a overdue todo
76 */ 76 */
77 int hasDueSubTodo( bool checkSubtodos = true ); 77 int hasDueSubTodo( bool checkSubtodos = true );
78 /* same as above, but a specific date can be specified*/ 78 /* same as above, but a specific date can be specified*/
79 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); 79 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos );
80 80
81 81
82 /** sets the event's status to the string specified. The string 82 /** sets the event's status to the string specified. The string
83 * must be a recognized value for the status field, i.e. a string 83 * must be a recognized value for the status field, i.e. a string
84 * equivalent of the possible status enumerations previously described. */ 84 * equivalent of the possible status enumerations previously described. */
85// void setStatus(const QString &statStr); 85// void setStatus(const QString &statStr);
86 /** sets the event's status to the value specified. See the enumeration 86 /** sets the event's status to the value specified. See the enumeration
87 * above for possible values. */ 87 * above for possible values. */
88// void setStatus(int); 88// void setStatus(int);
89 /** return the event's status. */ 89 /** return the event's status. */
90// int status() const; 90// int status() const;
91 /** return the event's status in string format. */ 91 /** return the event's status in string format. */
92// QString statusStr() const; 92// QString statusStr() const;
93 93
94 /** return, if this todo is completed */ 94 /** return, if this todo is completed */
95 bool isCompleted() const; 95 bool isCompleted() const;
96 /** set completed state of this todo */ 96 /** set completed state of this todo */
97 void setCompleted(bool); 97 void setCompleted(bool);
98 98
99 /** 99 /**
100 Return how many percent of the task are completed. Returns a value 100 Return how many percent of the task are completed. Returns a value
101 between 0 and 100. 101 between 0 and 100.
102 */ 102 */
103 int percentComplete() const; 103 int percentComplete() const;
104 /** 104 /**
105 Set how many percent of the task are completed. Valid values are in the 105 Set how many percent of the task are completed. Valid values are in the
106 range from 0 to 100. 106 range from 0 to 100.
107 */ 107 */
108 void setPercentComplete(int); 108 void setPercentComplete(int);
109 109
110 /** return date and time when todo was completed */ 110 /** return date and time when todo was completed */
111 QDateTime completed() const; 111 QDateTime completed() const;
112 QString completedStr(bool shortF = true) const; 112 QString completedStr(bool shortF = true) const;
113 /** set date and time of completion */ 113 /** set date and time of completion */
114 void setCompleted(const QDateTime &completed); 114 void setCompleted(const QDateTime &completed);
115 115
116 /** Return true, if todo has a date associated with completion */ 116 /** Return true, if todo has a date associated with completion */
117 bool hasCompletedDate() const; 117 bool hasCompletedDate() const;
118 bool contains ( Todo*); 118 bool contains ( Todo*);
119 void checkSetCompletedFalse(); 119 void checkSetCompletedFalse();
120 bool setRecurDates(); 120 bool setRecurDates();
121 bool isRunning() {return mRunning;} 121 bool isRunning() {return mRunning;}
122 bool hasRunningSub(); 122 bool hasRunningSub();
123 void setRunning( bool ); 123 void setRunning( bool );
124 void setRunningFalse( QString ); 124 void setRunningFalse( QString );
125 void stopRunning();
125 int runTime(); 126 int runTime();
126 QDateTime runStart () const { return mRunStart;} 127 QDateTime runStart () const { return mRunStart;}
127 public slots: 128 public slots:
128 void saveRunningInfoToFile( QString st ); 129 void saveRunningInfoToFile( QString st );
129 void saveRunningInfoToFile( ); 130 void saveRunningInfoToFile( );
130 void saveParents(); 131 void saveParents();
131 private: 132 private:
132 bool mRunning; 133 bool mRunning;
133 QTimer * mRunSaveTimer; 134 QTimer * mRunSaveTimer;
134 QDateTime mRunStart; 135 QDateTime mRunStart;
135 bool accept(Visitor &v) { return v.visit(this); } 136 bool accept(Visitor &v) { return v.visit(this); }
136 137
137 QDateTime mDtDue; // due date of todo 138 QDateTime mDtDue; // due date of todo
138 139
139 bool mHasDueDate; // if todo has associated due date 140 bool mHasDueDate; // if todo has associated due date
140 141
141// int mStatus; // confirmed/delegated/tentative/etc 142// int mStatus; // confirmed/delegated/tentative/etc
142 143
143 QDateTime mCompleted; 144 QDateTime mCompleted;
144 bool mHasCompletedDate; 145 bool mHasCompletedDate;
145 146
146 int mPercentComplete; 147 int mPercentComplete;
147}; 148};
148 149
149 bool operator==( const Todo&, const Todo& ); 150 bool operator==( const Todo&, const Todo& );
150} 151}
151 152
152#endif 153#endif