summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kolistview.cpp21
-rw-r--r--korganizer/kotodoviewitem.cpp14
-rw-r--r--libkcal/incidence.cpp13
-rw-r--r--libkcal/incidence.h2
-rw-r--r--libkcal/incidencebase.cpp13
-rw-r--r--libkcal/incidencebase.h2
6 files changed, 40 insertions, 25 deletions
diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp
index b236c2d..4fc1194 100644
--- a/korganizer/kolistview.cpp
+++ b/korganizer/kolistview.cpp
@@ -1,1444 +1,1437 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1999 Preston Brown 3 Copyright (c) 1999 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qprogressbar.h> 29#include <qprogressbar.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qdialog.h> 32#include <qdialog.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qdir.h> 34#include <qdir.h>
35#include <qwhatsthis.h> 35#include <qwhatsthis.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qpainter.h> 37#include <qpainter.h>
38#include <qpaintdevicemetrics.h> 38#include <qpaintdevicemetrics.h>
39 39
40#include <klocale.h> 40#include <klocale.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43#include <kglobal.h> 43#include <kglobal.h>
44 44
45#include <libkdepim/kpimglobalprefs.h> 45#include <libkdepim/kpimglobalprefs.h>
46#include <libkcal/calendar.h> 46#include <libkcal/calendar.h>
47#include <libkcal/calendarlocal.h> 47#include <libkcal/calendarlocal.h>
48#include <libkcal/icalformat.h> 48#include <libkcal/icalformat.h>
49#include <libkcal/vcalformat.h> 49#include <libkcal/vcalformat.h>
50#include <libkcal/recurrence.h> 50#include <libkcal/recurrence.h>
51#include <libkcal/filestorage.h> 51#include <libkcal/filestorage.h>
52#include <libkdepim/categoryselectdialog.h> 52#include <libkdepim/categoryselectdialog.h>
53#include <libkcal/kincidenceformatter.h> 53#include <libkcal/kincidenceformatter.h>
54#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
56#else 56#else
57#include <qapplication.h> 57#include <qapplication.h>
58#endif 58#endif
59 59
60#ifndef KORG_NOPRINTER 60#ifndef KORG_NOPRINTER
61#include "calprinter.h" 61#include "calprinter.h"
62#endif 62#endif
63#include "koglobals.h" 63#include "koglobals.h"
64#include "koprefs.h" 64#include "koprefs.h"
65#include "kfiledialog.h" 65#include "kfiledialog.h"
66 66
67#include "kolistview.h" 67#include "kolistview.h"
68#include "koeventviewer.h" 68#include "koeventviewer.h"
69 69
70extern QPixmap* sgListViewCompletedPix[6]; 70extern QPixmap* sgListViewCompletedPix[6];
71extern QPixmap* sgListViewJournalPix; 71extern QPixmap* sgListViewJournalPix;
72 72
73class KOListViewWhatsThis :public QWhatsThis 73class KOListViewWhatsThis :public QWhatsThis
74{ 74{
75public: 75public:
76 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 76 KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
77 77
78protected: 78protected:
79 virtual QString text( const QPoint& p) 79 virtual QString text( const QPoint& p)
80 { 80 {
81 return _view->getWhatsThisText(p) ; 81 return _view->getWhatsThisText(p) ;
82 } 82 }
83private: 83private:
84 QWidget* _wid; 84 QWidget* _wid;
85 KOListView * _view; 85 KOListView * _view;
86}; 86};
87 87
88 88
89ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date ) 89ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date )
90{ 90{
91 mItem = item; 91 mItem = item;
92 mDate = date; 92 mDate = date;
93} 93}
94 94
95ListItemVisitor::~ListItemVisitor() 95ListItemVisitor::~ListItemVisitor()
96{ 96{
97} 97}
98 98
99bool ListItemVisitor::visit(Event *e) 99bool ListItemVisitor::visit(Event *e)
100{ 100{
101 bool ok = false; 101 bool ok = false;
102 QString start, end; 102 QString start, end;
103 QDate ds, de; 103 QDate ds, de;
104 if ( e->doesRecur() ) { 104 if ( e->doesRecur() ) {
105 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date(); 105 ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date();
106 if ( ok ) { 106 if ( ok ) {
107 int days = e->dtStart().date().daysTo(e->dtEnd().date() ); 107 int days = e->dtStart().date().daysTo(e->dtEnd().date() );
108 start = KGlobal::locale()->formatDate(ds,true); 108 start = KGlobal::locale()->formatDate(ds,true);
109 de = ds.addDays( days); 109 de = ds.addDays( days);
110 end = KGlobal::locale()->formatDate(de,true); 110 end = KGlobal::locale()->formatDate(de,true);
111 } 111 }
112 112
113 } 113 }
114 if ( ! ok ) { 114 if ( ! ok ) {
115 start =e->dtStartDateStr(); 115 start =e->dtStartDateStr();
116 end = e->dtEndDateStr(); 116 end = e->dtEndDateStr();
117 ds = e->dtStart().date(); 117 ds = e->dtStart().date();
118 de = e->dtEnd().date(); 118 de = e->dtEnd().date();
119 } 119 }
120 mItem->setText(0,e->summary()); 120 mItem->setText(0,e->summary());
121 mItem->setText(1,start); 121 mItem->setText(1,start);
122 if ( e->doesFloat() ) 122 if ( e->doesFloat() )
123 mItem->setText(2,"---"); 123 mItem->setText(2,"---");
124 else 124 else
125 mItem->setText(2,e->dtStartTimeStr()); 125 mItem->setText(2,e->dtStartTimeStr());
126 mItem->setText(3,end); 126 mItem->setText(3,end);
127 if ( e->doesFloat() ) 127 if ( e->doesFloat() )
128 mItem->setText(4,"---"); 128 mItem->setText(4,"---");
129 else 129 else
130 mItem->setText(4,e->dtEndTimeStr()); 130 mItem->setText(4,e->dtEndTimeStr());
131 mItem->setText(5, e->durationText()); 131 mItem->setText(5, e->durationText());
132 if ( e->isAlarmEnabled() ) { 132 if ( e->isAlarmEnabled() ) {
133 mItem->setText(6,e->alarms().first()->offsetText() ); 133 mItem->setText(6,e->alarms().first()->offsetText() );
134 } else { 134 } else {
135 mItem->setText(6, i18n("No")); 135 mItem->setText(6, i18n("No"));
136 } 136 }
137 mItem->setText(7, e->recurrenceText()); 137 mItem->setText(7, e->recurrenceText());
138 if( ! e->doesRecur() ) 138 if( ! e->doesRecur() )
139 mItem->setSortKey( 7, "-" ); 139 mItem->setSortKey( 7, "-" );
140 mItem->setText(8, e->cancelled() ? i18n("Yes") : i18n("No")); 140 mItem->setText(8, e->cancelled() ? i18n("Yes") : i18n("No"));
141 mItem->setText(9,e->categoriesStr()); 141 mItem->setText(9,e->categoriesStr());
142 mItem->setText(10, KOPrefs::instance()->calName( e->calID() )); 142 mItem->setText(10, KOPrefs::instance()->calName( e->calID() ));
143 mItem->setText(11, KGlobal::locale()->formatDateTime( e->lastModified(), true, true )); 143 mItem->setText(11, KGlobal::locale()->formatDateTime( e->lastModified(), true, true ));
144 mItem->setSortKey(11,e->lastModifiedSortKey());
144 145
145 QString key; 146 QString key;
146 QDate d = e->lastModified().date(); 147 QTime t;
147 QTime t = e->lastModified().time();
148 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() );
149 mItem->setSortKey(12,key);
150 t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); 148 t = e->doesFloat() ? QTime(0,0) : e->dtStart().time();
151 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute()); 149 key.sprintf("%04d%02d%02d%02d%02d",ds.year(),ds.month(),ds.day(),t.hour(),t.minute());
152 mItem->setSortKey(1,key); 150 mItem->setSortKey(1,key);
153 151
154 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); 152 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time();
155 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute()); 153 key.sprintf("%04d%02d%02d%02d%02d",de.year(),de.month(),de.day(),t.hour(),t.minute());
156 mItem->setSortKey(3,key); 154 mItem->setSortKey(3,key);
157 return true; 155 return true;
158} 156}
159 157
160bool ListItemVisitor::visit(Todo *t) 158bool ListItemVisitor::visit(Todo *t)
161{ 159{
162 mItem->setText(0,t->summary()); 160 mItem->setText(0,t->summary());
163 if ( t->isCompleted() ) { 161 if ( t->isCompleted() ) {
164 mItem->setSortKey(0,"99"+ t->summary().left(10)); 162 mItem->setSortKey(0,"99"+ t->summary().left(10));
165 } else 163 } else
166 mItem->setSortKey(0,QString::number( t->percentComplete()+1 )+ t->summary().left(10)); 164 mItem->setSortKey(0,QString::number( t->percentComplete()+1 )+ t->summary().left(10));
167 mItem->setPixmap( 0, *(sgListViewCompletedPix[t->percentComplete()/20])); 165 mItem->setPixmap( 0, *(sgListViewCompletedPix[t->percentComplete()/20]));
168 if (t->hasStartDate()) { 166 if (t->hasStartDate()) {
169 mItem->setText(1,t->dtStartDateStr()); 167 mItem->setText(1,t->dtStartDateStr());
170 if (t->doesFloat()) { 168 if (t->doesFloat()) {
171 mItem->setText(2,"---"); 169 mItem->setText(2,"---");
172 } else { 170 } else {
173 mItem->setText(2,t->dtStartTimeStr()); 171 mItem->setText(2,t->dtStartTimeStr());
174 } 172 }
175 } else { 173 } else {
176 mItem->setText(1,"---"); 174 mItem->setText(1,"---");
177 mItem->setText(2,"---"); 175 mItem->setText(2,"---");
178 } 176 }
179 if ( t->isAlarmEnabled() ) { 177 if ( t->isAlarmEnabled() ) {
180 mItem->setText(6,t->alarms().first()->offsetText() ); 178 mItem->setText(6,t->alarms().first()->offsetText() );
181 } else { 179 } else {
182 mItem->setText(6, i18n("No")); 180 mItem->setText(6, i18n("No"));
183 } 181 }
184 mItem->setText(7, t->recurrenceText()); 182 mItem->setText(7, t->recurrenceText());
185 if( ! t->doesRecur() ) 183 if( ! t->doesRecur() )
186 mItem->setSortKey( 7, "-" ); 184 mItem->setSortKey( 7, "-" );
187 if (t->hasDueDate()) { 185 if (t->hasDueDate()) {
188 mItem->setText(3,t->dtDueDateStr()); 186 mItem->setText(3,t->dtDueDateStr());
189 if (t->doesFloat()) { 187 if (t->doesFloat()) {
190 mItem->setText(4,"---"); 188 mItem->setText(4,"---");
191 } else { 189 } else {
192 mItem->setText(4,t->dtDueTimeStr()); 190 mItem->setText(4,t->dtDueTimeStr());
193 } 191 }
194 } else { 192 } else {
195 mItem->setText(3,"---"); 193 mItem->setText(3,"---");
196 mItem->setText(4,"---"); 194 mItem->setText(4,"---");
197 } 195 }
198 mItem->setText(5, t->durationText()); 196 mItem->setText(5, t->durationText());
199 mItem->setText(8, t->cancelled() ? i18n("Yes") : i18n("No")); 197 mItem->setText(8, t->cancelled() ? i18n("Yes") : i18n("No"));
200 mItem->setText(9,t->categoriesStr()); 198 mItem->setText(9,t->categoriesStr());
201 mItem->setText(10, KOPrefs::instance()->calName( t->calID() )); 199 mItem->setText(10, KOPrefs::instance()->calName( t->calID() ));
202 mItem->setText(11, KGlobal::locale()->formatDateTime( t->lastModified(), true, true )); 200 mItem->setText(11, KGlobal::locale()->formatDateTime( t->lastModified(), true, true ));
201 mItem->setSortKey(11,t->lastModifiedSortKey());
203 QString key; 202 QString key;
204 QDate d = t->lastModified().date(); 203 QDate d;
205 QTime tm = t->lastModified().time(); 204 QTime tm;
206 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() );
207 mItem->setSortKey(11,key);
208 if (t->hasDueDate()) { 205 if (t->hasDueDate()) {
209 d = t->dtDue().date(); 206 d = t->dtDue().date();
210 tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); 207 tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time();
211 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 208 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
212 mItem->setSortKey(3,key); 209 mItem->setSortKey(3,key);
213 } 210 }
214 if ( t->hasStartDate() ) { 211 if ( t->hasStartDate() ) {
215 d = t->dtStart().date(); 212 d = t->dtStart().date();
216 tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time(); 213 tm = t->doesFloat() ? QTime(0,0) : t->dtStart().time();
217 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 214 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute());
218 mItem->setSortKey(1,key); 215 mItem->setSortKey(1,key);
219 } 216 }
220 return true; 217 return true;
221} 218}
222 219
223bool ListItemVisitor::visit(Journal * j) 220bool ListItemVisitor::visit(Journal * j)
224{ 221{
225 222
226 QString des; 223 QString des;
227 mItem->setPixmap( 0, *sgListViewJournalPix); 224 mItem->setPixmap( 0, *sgListViewJournalPix);
228 if ( !j->summary().isEmpty() ) { 225 if ( !j->summary().isEmpty() ) {
229 des = j->summary(); 226 des = j->summary();
230 } else { 227 } else {
231 des = j->description().left(30); 228 des = j->description().left(30);
232 des = des.simplifyWhiteSpace (); 229 des = des.simplifyWhiteSpace ();
233 des.replace (QRegExp ("\\n"),"" ); 230 des.replace (QRegExp ("\\n"),"" );
234 des.replace (QRegExp ("\\r"),"" ); 231 des.replace (QRegExp ("\\r"),"" );
235 } 232 }
236 mItem->setText(0,des.left(25)); 233 mItem->setText(0,des.left(25));
237 mItem->setSortKey(0,"0"+ des.left(25)); 234 mItem->setSortKey(0,"0"+ des.left(25));
238 mItem->setText(1,j->dtStartDateStr()); 235 mItem->setText(1,j->dtStartDateStr());
239 mItem->setText(2,"---"); 236 mItem->setText(2,"---");
240 mItem->setText(3,"---"); 237 mItem->setText(3,"---");
241 mItem->setText(4,"---"); 238 mItem->setText(4,"---");
242 mItem->setText(5,"---"); 239 mItem->setText(5,"---");
243 mItem->setText(6,"---"); 240 mItem->setText(6,"---");
244 mItem->setText(7,"---"); 241 mItem->setText(7,"---");
245 mItem->setText(8,"---"); 242 mItem->setText(8,"---");
246 mItem->setText(9,j->categoriesStr()); 243 mItem->setText(9,j->categoriesStr());
247 mItem->setText(10, KOPrefs::instance()->calName( j->calID() )); 244 mItem->setText(10, KOPrefs::instance()->calName( j->calID() ));
248 mItem->setText(11, KGlobal::locale()->formatDateTime( j->lastModified(), true, true )); 245 mItem->setText(11, KGlobal::locale()->formatDateTime( j->lastModified(), true, true ));
246 mItem->setSortKey(11,j->lastModifiedSortKey());
249 247
250 QString key; 248 QString key;
251 QDate d = j->lastModified().date(); 249 QDate d;
252 QTime tm = j->lastModified().time();
253 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute(),tm.second() );
254 mItem->setSortKey(12,key);
255 d = j->dtStart().date(); 250 d = j->dtStart().date();
256 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 251 key.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
257 mItem->setSortKey(1,key); 252 mItem->setSortKey(1,key);
258 mItem->setSortKey(7,key);
259
260 return true; 253 return true;
261} 254}
262 255
263KOListView::KOListView(Calendar *calendar, QWidget *parent, 256KOListView::KOListView(Calendar *calendar, QWidget *parent,
264 const char *name) 257 const char *name)
265 : KOEventView(calendar, parent, name) 258 : KOEventView(calendar, parent, name)
266{ 259{
267 260
268 mActiveItem = 0; 261 mActiveItem = 0;
269 mForceShowCompletedTodos = false; 262 mForceShowCompletedTodos = false;
270 mListView = new KOListViewListView(this); 263 mListView = new KOListViewListView(this);
271 mListView->addColumn(i18n("Summary")); 264 mListView->addColumn(i18n("Summary"));
272 mListView->addColumn(i18n("Start Date")); 265 mListView->addColumn(i18n("Start Date"));
273 mListView->addColumn(i18n("Start Time")); 266 mListView->addColumn(i18n("Start Time"));
274 mListView->addColumn(i18n("End/Due Date")); 267 mListView->addColumn(i18n("End/Due Date"));
275 mListView->addColumn(i18n("End/Due Time")); 268 mListView->addColumn(i18n("End/Due Time"));
276 mListView->addColumn(i18n("Duration")); 269 mListView->addColumn(i18n("Duration"));
277 mListView->addColumn(i18n("Alarm")); // alarm set? 270 mListView->addColumn(i18n("Alarm")); // alarm set?
278 mListView->addColumn(i18n("Recurs")); // recurs? 271 mListView->addColumn(i18n("Recurs")); // recurs?
279 mListView->addColumn(i18n("Cancelled")); 272 mListView->addColumn(i18n("Cancelled"));
280 mListView->addColumn(i18n("Categories")); 273 mListView->addColumn(i18n("Categories"));
281 mListView->addColumn(i18n("Calendar")); 274 mListView->addColumn(i18n("Calendar"));
282 mListView->addColumn(i18n("Last Modified")); 275 mListView->addColumn(i18n("Last Modified"));
283 276
284 mListView->setColumnAlignment(0,AlignLeft); 277 mListView->setColumnAlignment(0,AlignLeft);
285 mListView->setColumnAlignment(1,AlignLeft); 278 mListView->setColumnAlignment(1,AlignLeft);
286 mListView->setColumnAlignment(2,AlignHCenter); 279 mListView->setColumnAlignment(2,AlignHCenter);
287 mListView->setColumnAlignment(3,AlignLeft); 280 mListView->setColumnAlignment(3,AlignLeft);
288 mListView->setColumnAlignment(4,AlignHCenter); 281 mListView->setColumnAlignment(4,AlignHCenter);
289 mListView->setColumnAlignment(5,AlignLeft); 282 mListView->setColumnAlignment(5,AlignLeft);
290 mListView->setColumnAlignment(6,AlignLeft); 283 mListView->setColumnAlignment(6,AlignLeft);
291 mListView->setColumnAlignment(7,AlignLeft); 284 mListView->setColumnAlignment(7,AlignLeft);
292 mListView->setColumnAlignment(8,AlignLeft); 285 mListView->setColumnAlignment(8,AlignLeft);
293 mListView->setColumnAlignment(9,AlignLeft); 286 mListView->setColumnAlignment(9,AlignLeft);
294 mListView->setColumnAlignment(10,AlignLeft); 287 mListView->setColumnAlignment(10,AlignLeft);
295 mListView->setColumnAlignment(11,AlignLeft); 288 mListView->setColumnAlignment(11,AlignLeft);
296 mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this); 289 mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this);
297 290
298 int iii = 0; 291 int iii = 0;
299 for ( iii = 0; iii< 12 ; ++iii ) 292 for ( iii = 0; iii< 12 ; ++iii )
300 mListView->setColumnWidthMode( iii, QListView::Manual ); 293 mListView->setColumnWidthMode( iii, QListView::Manual );
301 294
302 QBoxLayout *layoutTop = new QVBoxLayout(this); 295 QBoxLayout *layoutTop = new QVBoxLayout(this);
303 layoutTop->addWidget(mListView); 296 layoutTop->addWidget(mListView);
304 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 297 mListView->setFont ( KOPrefs::instance()->mListViewFont );
305 mPopupMenu = eventPopup(); 298 mPopupMenu = eventPopup();
306 QPopupMenu* selPopup = new QPopupMenu ( this ); 299 QPopupMenu* selPopup = new QPopupMenu ( this );
307 mPopupMenu->insertSeparator(); 300 mPopupMenu->insertSeparator();
308 301
309 selPopup->insertItem(i18n("All"),this, 302 selPopup->insertItem(i18n("All"),this,
310 SLOT(allSelection())); 303 SLOT(allSelection()));
311 selPopup->insertItem(i18n("None"),this, 304 selPopup->insertItem(i18n("None"),this,
312 SLOT(clearSelection())); 305 SLOT(clearSelection()));
313 selPopup->insertItem(i18n("Delete selected..."),this, 306 selPopup->insertItem(i18n("Delete selected..."),this,
314 SLOT(deleteAll())); 307 SLOT(deleteAll()));
315 mPopupMenu->insertItem(i18n("Selection"), selPopup ); 308 mPopupMenu->insertItem(i18n("Selection"), selPopup );
316 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 309 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
317 i18n("Hide all selected"),this, 310 i18n("Hide all selected"),this,
318 SLOT(hideAll()),true); 311 SLOT(hideAll()),true);
319 312
320 selPopup->insertSeparator(); 313 selPopup->insertSeparator();
321 QPopupMenu * exportPO = new QPopupMenu ( this ); 314 QPopupMenu * exportPO = new QPopupMenu ( this );
322 selPopup->insertItem( i18n("Export"), exportPO ); 315 selPopup->insertItem( i18n("Export"), exportPO );
323#ifdef DESKTOP_VERSION 316#ifdef DESKTOP_VERSION
324 mPopupMenu->insertSeparator(); 317 mPopupMenu->insertSeparator();
325 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 318 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
326 i18n("Print complete list..."),this, 319 i18n("Print complete list..."),this,
327 SLOT(printList()),true); 320 SLOT(printList()),true);
328#endif 321#endif
329 mCalPopup = new QPopupMenu ( this ); 322 mCalPopup = new QPopupMenu ( this );
330 selPopup->insertItem( i18n("Set Calendar"), mCalPopup ); 323 selPopup->insertItem( i18n("Set Calendar"), mCalPopup );
331 324
332 selPopup->insertItem(i18n("Set categories")+"...",this, 325 selPopup->insertItem(i18n("Set categories")+"...",this,
333 SLOT(setCat()) ); 326 SLOT(setCat()) );
334 selPopup->insertItem( i18n("Set alarm..."),this, 327 selPopup->insertItem( i18n("Set alarm..."),this,
335 SLOT(setAlarm())); 328 SLOT(setAlarm()));
336#if 0 329#if 0
337 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 330 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
338 i18n("Set categories")+"...",this, 331 i18n("Set categories")+"...",this,
339 SLOT(setCat()),true); 332 SLOT(setCat()),true);
340 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 333 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
341 i18n("Set alarm..."),this, 334 i18n("Set alarm..."),this,
342 SLOT(setAlarm()),true); 335 SLOT(setAlarm()),true);
343#endif 336#endif
344 QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this, 337 QObject::connect(mCalPopup,SIGNAL(aboutToShow()),this,
345 SLOT( populateCalPopup() )); 338 SLOT( populateCalPopup() ));
346 QObject::connect(mCalPopup,SIGNAL(activated( int )),this, 339 QObject::connect(mCalPopup,SIGNAL(activated( int )),this,
347 SLOT( setCalendar( int ) )); 340 SLOT( setCalendar( int ) ));
348 QObject::connect(mPopupMenu,SIGNAL(categoryChanged( Incidence * )),this, 341 QObject::connect(mPopupMenu,SIGNAL(categoryChanged( Incidence * )),this,
349 SLOT( catChanged( Incidence * ) )); 342 SLOT( catChanged( Incidence * ) ));
350 exportPO->insertItem( i18n("As iCal (ics) file..."),this, 343 exportPO->insertItem( i18n("As iCal (ics) file..."),this,
351 SLOT(saveToFile())); 344 SLOT(saveToFile()));
352 exportPO->insertItem( i18n("As vCal (vcs) file..."),this, 345 exportPO->insertItem( i18n("As vCal (vcs) file..."),this,
353 SLOT(saveToFileVCS())); 346 SLOT(saveToFileVCS()));
354 exportPO->insertItem( i18n("Journal/Details..."),this, 347 exportPO->insertItem( i18n("Journal/Details..."),this,
355 SLOT(saveDescriptionToFile())); 348 SLOT(saveDescriptionToFile()));
356 // mPopupMenu->insertSeparator(); 349 // mPopupMenu->insertSeparator();
357 // mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 350 // mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
358 // i18n("Add Categ. to selected..."),this, 351 // i18n("Add Categ. to selected..."),this,
359 // SLOT(addCat()),true); 352 // SLOT(addCat()),true);
360 //mPopupMenu->insertSeparator(); 353 //mPopupMenu->insertSeparator();
361#ifndef DESKTOP_VERSION 354#ifndef DESKTOP_VERSION
362 selPopup->insertSeparator(); 355 selPopup->insertSeparator();
363 selPopup->insertItem( i18n("Beam via IR..."),this, 356 selPopup->insertItem( i18n("Beam via IR..."),this,
364 SLOT(beamSelected())); 357 SLOT(beamSelected()));
365#if 0 358#if 0
366 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()), 359 mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
367 i18n("Beam via IR"),this, 360 i18n("Beam via IR"),this,
368 SLOT(beamSelected()),true); 361 SLOT(beamSelected()),true);
369#endif 362#endif
370#endif 363#endif
371 /* 364 /*
372 mPopupMenu = new QPopupMenu; 365 mPopupMenu = new QPopupMenu;
373 mPopupMenu->insertItem(i18n("Edit Event"), this, 366 mPopupMenu->insertItem(i18n("Edit Event"), this,
374 SLOT (editEvent())); 367 SLOT (editEvent()));
375 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this, 368 mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this,
376 SLOT (deleteEvent())); 369 SLOT (deleteEvent()));
377 mPopupMenu->insertSeparator(); 370 mPopupMenu->insertSeparator();
378 mPopupMenu->insertItem(i18n("Show Dates"), this, 371 mPopupMenu->insertItem(i18n("Show Dates"), this,
379 SLOT(showDates())); 372 SLOT(showDates()));
380 mPopupMenu->insertItem(i18n("Hide Dates"), this, 373 mPopupMenu->insertItem(i18n("Hide Dates"), this,
381 SLOT(hideDates())); 374 SLOT(hideDates()));
382 */ 375 */
383 QObject::connect(mListView,SIGNAL( newEvent()), 376 QObject::connect(mListView,SIGNAL( newEvent()),
384 this,SIGNAL(signalNewEvent())); 377 this,SIGNAL(signalNewEvent()));
385 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)), 378 QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)),
386 this,SLOT(defaultItemAction(QListViewItem *))); 379 this,SLOT(defaultItemAction(QListViewItem *)));
387 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *, 380 QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *,
388 const QPoint &, int )), 381 const QPoint &, int )),
389 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int))); 382 this,SLOT(popupMenu(QListViewItem *,const QPoint &,int)));
390 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)), 383 QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)),
391 SLOT(processSelectionChange(QListViewItem *))); 384 SLOT(processSelectionChange(QListViewItem *)));
392 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)), 385 QObject::connect(mListView,SIGNAL(showIncidence(Incidence *)),
393 SIGNAL(showIncidenceSignal(Incidence *)) ); 386 SIGNAL(showIncidenceSignal(Incidence *)) );
394 387
395 readSettings(KOGlobals::config(),"KOListView Layout"); 388 readSettings(KOGlobals::config(),"KOListView Layout");
396} 389}
397 390
398KOListView::~KOListView() 391KOListView::~KOListView()
399{ 392{
400 delete mPopupMenu; 393 delete mPopupMenu;
401#if QT_VERSION >= 0x030000 394#if QT_VERSION >= 0x030000
402 395
403#else 396#else
404 delete mKOListViewWhatsThis; 397 delete mKOListViewWhatsThis;
405#endif 398#endif
406} 399}
407 400
408void KOListView::catChanged( Incidence* inc) 401void KOListView::catChanged( Incidence* inc)
409{ 402{
410 KOListViewItem* item = getItemForEvent(inc); 403 KOListViewItem* item = getItemForEvent(inc);
411 if (item) { 404 if (item) {
412 ListItemVisitor v(item, mStartDate ); 405 ListItemVisitor v(item, mStartDate );
413 inc->accept(v); 406 inc->accept(v);
414 } 407 }
415} 408}
416QString KOListView::getWhatsThisText(QPoint p) 409QString KOListView::getWhatsThisText(QPoint p)
417{ 410{
418 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p ); 411 KOListViewItem* item = ( KOListViewItem* ) mListView->itemAt( p );
419 if ( item ) 412 if ( item )
420 return KIncidenceFormatter::instance()->getFormattedText( item->data(), 413 return KIncidenceFormatter::instance()->getFormattedText( item->data(),
421 KOPrefs::instance()->mWTshowDetails, 414 KOPrefs::instance()->mWTshowDetails,
422 KOPrefs::instance()->mWTshowCreated, 415 KOPrefs::instance()->mWTshowCreated,
423 KOPrefs::instance()->mWTshowChanged); 416 KOPrefs::instance()->mWTshowChanged);
424 return i18n("That is the list view" ); 417 return i18n("That is the list view" );
425 418
426} 419}
427 420
428void KOListView::setCalendar( int c ) 421void KOListView::setCalendar( int c )
429{ 422{
430 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), 423 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"),
431 i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ), 424 i18n("This adds the selected\nitems to the calendar\n%1\nand removes them from\ntheir current calendar!").arg( KOPrefs::instance()->calName( c ) ),
432 i18n("Continue"), i18n("Cancel"), 0, 425 i18n("Continue"), i18n("Cancel"), 0,
433 0, 1 ); 426 0, 1 );
434 if ( result != 0 ) { 427 if ( result != 0 ) {
435 return; 428 return;
436 } 429 }
437 430
438 QPtrList<Incidence> delSel = getSelectedIncidences() ; 431 QPtrList<Incidence> delSel = getSelectedIncidences() ;
439 int icount = delSel.count(); 432 int icount = delSel.count();
440 if ( icount ) { 433 if ( icount ) {
441 Incidence *incidence = delSel.first(); 434 Incidence *incidence = delSel.first();
442 while ( incidence ) { 435 while ( incidence ) {
443 incidence->setCalID( c ); 436 incidence->setCalID( c );
444 KOListViewItem * item = getItemForEvent( incidence ); 437 KOListViewItem * item = getItemForEvent( incidence );
445 if ( item ) { 438 if ( item ) {
446 ListItemVisitor v(item, mStartDate ); 439 ListItemVisitor v(item, mStartDate );
447 incidence->accept(v); 440 incidence->accept(v);
448 } 441 }
449 incidence = delSel.next(); 442 incidence = delSel.next();
450 } 443 }
451 } 444 }
452 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 445 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
453 KopiCalendarFile * cal = calendars.first(); 446 KopiCalendarFile * cal = calendars.first();
454 while ( cal ) { 447 while ( cal ) {
455 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 448 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
456 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 449 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
457 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 450 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
458 if ( cal->isStandard ) 451 if ( cal->isStandard )
459 mCalendar->setDefaultCalendar( cal->mCalNumber ); 452 mCalendar->setDefaultCalendar( cal->mCalNumber );
460 cal = calendars.next(); 453 cal = calendars.next();
461 } 454 }
462 mCalendar->setSyncEventsReadOnly(); 455 mCalendar->setSyncEventsReadOnly();
463 mCalendar->reInitAlarmSettings(); 456 mCalendar->reInitAlarmSettings();
464 457
465} 458}
466void KOListView::populateCalPopup() 459void KOListView::populateCalPopup()
467{ 460{
468 mCalPopup->clear(); 461 mCalPopup->clear();
469 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 462 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
470 while ( kkf ) { 463 while ( kkf ) {
471 int index = mCalPopup->insertItem( kkf->mName+"...", kkf->mCalNumber); 464 int index = mCalPopup->insertItem( kkf->mName+"...", kkf->mCalNumber);
472 if ( kkf->mErrorOnLoad || kkf->isReadOnly ) 465 if ( kkf->mErrorOnLoad || kkf->isReadOnly )
473 mCalPopup->setItemEnabled( index, false ); 466 mCalPopup->setItemEnabled( index, false );
474 kkf = KOPrefs::instance()->mCalendars.next(); 467 kkf = KOPrefs::instance()->mCalendars.next();
475 } 468 }
476} 469}
477void KOListView::updateList() 470void KOListView::updateList()
478{ 471{
479 // qDebug(" KOListView::updateList() "); 472 // qDebug(" KOListView::updateList() ");
480 473
481} 474}
482 475
483void KOListView::clearList() 476void KOListView::clearList()
484{ 477{
485 clear (); 478 clear ();
486} 479}
487 480
488void KOListView::setCat() 481void KOListView::setCat()
489{ 482{
490 483
491 bool set = true; 484 bool set = true;
492 int result = KMessageBox::warningYesNoCancel(this, 485 int result = KMessageBox::warningYesNoCancel(this,
493 i18n("Do you want to <b>add</b> categories to the selected items or <b>reset</b> the list (i.e. remove current categories)?"), 486 i18n("Do you want to <b>add</b> categories to the selected items or <b>reset</b> the list (i.e. remove current categories)?"),
494 i18n("Set categories"), 487 i18n("Set categories"),
495 i18n("Add"), 488 i18n("Add"),
496 i18n("Reset")); 489 i18n("Reset"));
497 if (result == KMessageBox::Cancel) return; 490 if (result == KMessageBox::Cancel) return;
498 if (result == KMessageBox::Yes) set = false; 491 if (result == KMessageBox::Yes) set = false;
499 setCategories( set ); 492 setCategories( set );
500} 493}
501 494
502void KOListView::setAlarm() 495void KOListView::setAlarm()
503{ 496{
504 KOAlarmPrefs kap( this); 497 KOAlarmPrefs kap( this);
505 if ( !kap.exec() ) 498 if ( !kap.exec() )
506 return; 499 return;
507 QPtrList<Incidence> delSel = getSelectedIncidences( true, true, false, true ); // no journals, only due todos 500 QPtrList<Incidence> delSel = getSelectedIncidences( true, true, false, true ); // no journals, only due todos
508 Incidence* inc = delSel.first(); 501 Incidence* inc = delSel.first();
509 int count = 0; 502 int count = 0;
510 while ( inc ) { 503 while ( inc ) {
511 ++count; 504 ++count;
512 if (kap.mAlarmButton->isChecked()) { 505 if (kap.mAlarmButton->isChecked()) {
513 if (inc->alarms().count() == 0) 506 if (inc->alarms().count() == 0)
514 inc->newAlarm(); 507 inc->newAlarm();
515 Alarm *alarm = inc->alarms().first(); 508 Alarm *alarm = inc->alarms().first();
516 alarm->setEnabled(true); 509 alarm->setEnabled(true);
517 int j = kap.mAlarmTimeEdit->value()* -60; 510 int j = kap.mAlarmTimeEdit->value()* -60;
518 if (kap.mAlarmIncrCombo->currentItem() == 1) 511 if (kap.mAlarmIncrCombo->currentItem() == 1)
519 j = j * 60; 512 j = j * 60;
520 else if (kap.mAlarmIncrCombo->currentItem() == 2) 513 else if (kap.mAlarmIncrCombo->currentItem() == 2)
521 j = j * (60 * 24); 514 j = j * (60 * 24);
522 alarm->setStartOffset( j ); 515 alarm->setStartOffset( j );
523 516
524 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) { 517 if (!kap.mAlarmProgram.isEmpty() && kap.mAlarmProgramButton->isOn()) {
525 alarm->setProcedureAlarm(kap.mAlarmProgram); 518 alarm->setProcedureAlarm(kap.mAlarmProgram);
526 } 519 }
527 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn()) 520 else if (!kap.mAlarmSound.isEmpty() && kap.mAlarmSoundButton->isOn())
528 alarm->setAudioAlarm(kap.mAlarmSound); 521 alarm->setAudioAlarm(kap.mAlarmSound);
529 else 522 else
530 alarm->setType(Alarm::Invalid); 523 alarm->setType(Alarm::Invalid);
531 } else { 524 } else {
532 QPtrList<Alarm> alarms = inc->alarms(); 525 QPtrList<Alarm> alarms = inc->alarms();
533 Alarm *alarm; 526 Alarm *alarm;
534 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { 527 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
535 alarm->setEnabled(false); 528 alarm->setEnabled(false);
536 alarm->setType(Alarm::Invalid); 529 alarm->setType(Alarm::Invalid);
537 } 530 }
538 } 531 }
539 KOListViewItem* item = getItemForEvent(inc); 532 KOListViewItem* item = getItemForEvent(inc);
540 if (item) { 533 if (item) {
541 ListItemVisitor v(item, mStartDate ); 534 ListItemVisitor v(item, mStartDate );
542 inc->accept(v); 535 inc->accept(v);
543 } 536 }
544 inc = delSel.next(); 537 inc = delSel.next();
545 } 538 }
546 topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) ); 539 topLevelWidget()->setCaption( i18n("Changed alarm for %1 items").arg( count ) );
547 qDebug("KO: Set alarm for %d items", count); 540 qDebug("KO: Set alarm for %d items", count);
548 calendar()->reInitAlarmSettings(); 541 calendar()->reInitAlarmSettings();
549 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 542 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
550} 543}
551void KOListView::setCategories( bool removeOld ) 544void KOListView::setCategories( bool removeOld )
552{ 545{
553 546
554 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); 547 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 );
555 csd->setColorEnabled(); 548 csd->setColorEnabled();
556 if (! csd->exec()) { 549 if (! csd->exec()) {
557 delete csd; 550 delete csd;
558 return; 551 return;
559 } 552 }
560 QStringList catList = csd->selectedCategories(); 553 QStringList catList = csd->selectedCategories();
561 delete csd; 554 delete csd;
562 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed; 555 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;
563 Incidence* inc = delSel.first(); 556 Incidence* inc = delSel.first();
564 while ( inc ) { 557 while ( inc ) {
565 if ( removeOld ) { 558 if ( removeOld ) {
566 inc->setCategories( catList, false ); 559 inc->setCategories( catList, false );
567 } else { 560 } else {
568 inc->addCategories( catList, false ); 561 inc->addCategories( catList, false );
569 } 562 }
570 KOListViewItem* item = getItemForEvent(inc); 563 KOListViewItem* item = getItemForEvent(inc);
571 if (item) { 564 if (item) {
572 ListItemVisitor v(item, mStartDate ); 565 ListItemVisitor v(item, mStartDate );
573 inc->accept(v); 566 inc->accept(v);
574 } 567 }
575 inc = delSel.next(); 568 inc = delSel.next();
576 } 569 }
577 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 570 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
578} 571}
579 572
580void KOListView::beamSelected() 573void KOListView::beamSelected()
581{ 574{
582 QPtrList<Incidence> delSel = getSelectedIncidences() ; 575 QPtrList<Incidence> delSel = getSelectedIncidences() ;
583 if ( delSel.count() ) 576 if ( delSel.count() )
584 emit beamIncidenceList( delSel ); 577 emit beamIncidenceList( delSel );
585} 578}
586 579
587void KOListView::saveDescriptionToFile() 580void KOListView::saveDescriptionToFile()
588{ 581{
589 582
590 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"), 583 int result = QMessageBox::warning( this, i18n("KO/Pi: Information!"),
591 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."), 584 i18n("This saves the text/details of selected\nJournals and Events/Todos\nto a text file."),
592 i18n("Continue"), i18n("Cancel"), 0, 585 i18n("Continue"), i18n("Cancel"), 0,
593 0, 1 ); 586 0, 1 );
594 if ( result != 0 ) { 587 if ( result != 0 ) {
595 return; 588 return;
596 } 589 }
597 QPtrList<Incidence> delSel = getSelectedIncidences() ; 590 QPtrList<Incidence> delSel = getSelectedIncidences() ;
598 int icount = delSel.count(); 591 int icount = delSel.count();
599 if ( icount ) { 592 if ( icount ) {
600 QString fn = KOPrefs::instance()->mLastSaveFile; 593 QString fn = KOPrefs::instance()->mLastSaveFile;
601 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 594 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
602 595
603 if ( fn == "" ) 596 if ( fn == "" )
604 return; 597 return;
605 QFileInfo info; 598 QFileInfo info;
606 info.setFile( fn ); 599 info.setFile( fn );
607 QString mes; 600 QString mes;
608 bool createbup = true; 601 bool createbup = true;
609 if ( info. exists() ) { 602 if ( info. exists() ) {
610 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 603 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
611 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 604 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
612 i18n("Overwrite!"), i18n("Cancel"), 0, 605 i18n("Overwrite!"), i18n("Cancel"), 0,
613 0, 1 ); 606 0, 1 );
614 if ( result != 0 ) { 607 if ( result != 0 ) {
615 createbup = false; 608 createbup = false;
616 } 609 }
617 } 610 }
618 if ( createbup ) { 611 if ( createbup ) {
619 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") + 612 QString text = i18n("KO/Pi Description/Journal save file.\nSave date: ") +
620 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false); 613 KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), false);
621 Incidence *incidence = delSel.first(); 614 Incidence *incidence = delSel.first();
622 icount = 0; 615 icount = 0;
623 while ( incidence ) { 616 while ( incidence ) {
624 if ( incidence->typeID() == journalID ) { 617 if ( incidence->typeID() == journalID ) {
625 text += "\n************************************\n"; 618 text += "\n************************************\n";
626 if ( !incidence->summary().isEmpty() ) 619 if ( !incidence->summary().isEmpty() )
627 text += i18n("Journal: %1 from ").arg( incidence->summary() ) +incidence->dtStartDateStr( false ); 620 text += i18n("Journal: %1 from ").arg( incidence->summary() ) +incidence->dtStartDateStr( false );
628 else 621 else
629 text += i18n("Journal from: ") +incidence->dtStartDateStr( false ); 622 text += i18n("Journal from: ") +incidence->dtStartDateStr( false );
630 if ( !incidence->location().isEmpty() ) 623 if ( !incidence->location().isEmpty() )
631 text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; 624 text +="\n(" + i18n("Location: ") + incidence->location()+ ")";
632 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 625 text +="\n" + i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
633 text +="\n" + i18n("Description: ") + "\n"+ incidence->description(); 626 text +="\n" + i18n("Description: ") + "\n"+ incidence->description();
634 ++icount; 627 ++icount;
635 628
636 } else { 629 } else {
637 if ( !incidence->description().isEmpty() ) { 630 if ( !incidence->description().isEmpty() ) {
638 text += "\n************************************\n"; 631 text += "\n************************************\n";
639 if ( incidence->typeID() == todoID ) 632 if ( incidence->typeID() == todoID )
640 text += i18n("To-Do: "); 633 text += i18n("To-Do: ");
641 text += incidence->summary(); 634 text += incidence->summary();
642 if ( !incidence->location().isEmpty() ) 635 if ( !incidence->location().isEmpty() )
643 text +="\n(" + i18n("Location: ") + incidence->location()+ ")"; 636 text +="\n(" + i18n("Location: ") + incidence->location()+ ")";
644 if ( incidence->hasStartDate() ) 637 if ( incidence->hasStartDate() )
645 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false ); 638 text +="\n"+ i18n("Start Date: ") + incidence->dtStartStr( false );
646 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false); 639 text +="\n"+ i18n("Last modified: ") +KGlobal::locale()->formatDateTime(incidence->lastModified(), false);
647 text += "\n" + i18n("Description: ") + "\n" + incidence->description(); 640 text += "\n" + i18n("Description: ") + "\n" + incidence->description();
648 ++icount; 641 ++icount;
649 642
650 } 643 }
651 } 644 }
652 incidence = delSel.next(); 645 incidence = delSel.next();
653 } 646 }
654 QFile file( fn ); 647 QFile file( fn );
655 if (!file.open( IO_WriteOnly ) ) { 648 if (!file.open( IO_WriteOnly ) ) {
656 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") ); 649 topLevelWidget()->setCaption(i18n("File open error - nothing saved!") );
657 return; 650 return;
658 } 651 }
659 QTextStream ts( &file ); 652 QTextStream ts( &file );
660 ts << text; 653 ts << text;
661 file.close(); 654 file.close();
662 //qDebug("%s ", text.latin1()); 655 //qDebug("%s ", text.latin1());
663 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount ); 656 mes = i18n("KO/Pi:Saved %1 descriptions/journals").arg(icount );
664 KOPrefs::instance()->mLastSaveFile = fn; 657 KOPrefs::instance()->mLastSaveFile = fn;
665 topLevelWidget()->setCaption(mes); 658 topLevelWidget()->setCaption(mes);
666 } 659 }
667 } 660 }
668} 661}
669void KOListView::saveToFileVCS() 662void KOListView::saveToFileVCS()
670{ 663{
671 writeToFile( false ); 664 writeToFile( false );
672} 665}
673void KOListView::saveToFile() 666void KOListView::saveToFile()
674{ 667{
675 writeToFile( true ); 668 writeToFile( true );
676} 669}
677QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents, bool includeTodos, bool includeJournals, bool onlyDueTodos ) 670QPtrList<Incidence> KOListView::getSelectedIncidences( bool includeEvents, bool includeTodos, bool includeJournals, bool onlyDueTodos )
678{ 671{
679 QPtrList<Incidence> delSel ; 672 QPtrList<Incidence> delSel ;
680 bool addSubTodos = false; 673 bool addSubTodos = false;
681 bool askSubTodos = true; 674 bool askSubTodos = true;
682 QListViewItem *item = mListView->firstChild (); 675 QListViewItem *item = mListView->firstChild ();
683 while ( item ) { 676 while ( item ) {
684 if ( item->isSelected() ) { 677 if ( item->isSelected() ) {
685 Incidence* inc = ((KOListViewItem *)item)->data(); 678 Incidence* inc = ((KOListViewItem *)item)->data();
686 if ( ( addSubTodos && delSel.findRef( inc ) == -1) || !addSubTodos ) { 679 if ( ( addSubTodos && delSel.findRef( inc ) == -1) || !addSubTodos ) {
687 if ( (inc->typeID() == todoID && includeTodos) || 680 if ( (inc->typeID() == todoID && includeTodos) ||
688 (inc->typeID() == eventID && includeEvents) || 681 (inc->typeID() == eventID && includeEvents) ||
689 (inc->typeID() == journalID && includeJournals) ) { 682 (inc->typeID() == journalID && includeJournals) ) {
690 if ( inc->typeID() == todoID && onlyDueTodos ) { 683 if ( inc->typeID() == todoID && onlyDueTodos ) {
691 if ( ((Todo*)inc)->hasDueDate() ) 684 if ( ((Todo*)inc)->hasDueDate() )
692 delSel.append( inc ); 685 delSel.append( inc );
693 } else 686 } else
694 delSel.append( inc ); 687 delSel.append( inc );
695 688
696 } 689 }
697 } 690 }
698 if ( inc->typeID() == todoID ) { 691 if ( inc->typeID() == todoID ) {
699 Todo * todo = (Todo*) inc; 692 Todo * todo = (Todo*) inc;
700 if ( todo->relations().count() ) { 693 if ( todo->relations().count() ) {
701 if ( askSubTodos ) { 694 if ( askSubTodos ) {
702 int result = KMessageBox::warningYesNoCancel(this, 695 int result = KMessageBox::warningYesNoCancel(this,
703 i18n("One (or more) selected\ntodo has subtodos!\nDo you want to select\nall subtodos of all\nselected todos as well?"), 696 i18n("One (or more) selected\ntodo has subtodos!\nDo you want to select\nall subtodos of all\nselected todos as well?"),
704 i18n("Todo has subtodos"), 697 i18n("Todo has subtodos"),
705 i18n("Yes"), 698 i18n("Yes"),
706 i18n("No")); 699 i18n("No"));
707 if ( result == KMessageBox::Cancel ) { 700 if ( result == KMessageBox::Cancel ) {
708 delSel.clear(); 701 delSel.clear();
709 return delSel; 702 return delSel;
710 } 703 }
711 if (result == KMessageBox::Yes) 704 if (result == KMessageBox::Yes)
712 addSubTodos = true; 705 addSubTodos = true;
713 askSubTodos = false; 706 askSubTodos = false;
714 } 707 }
715 if ( addSubTodos ) { 708 if ( addSubTodos ) {
716 QPtrList<Incidence> tempSel ; 709 QPtrList<Incidence> tempSel ;
717 inc->addRelationsToList( &tempSel ); 710 inc->addRelationsToList( &tempSel );
718 Incidence* tempinc = tempSel.first(); 711 Incidence* tempinc = tempSel.first();
719 while ( tempinc ) { 712 while ( tempinc ) {
720 if ( delSel.findRef( tempinc ) == -1 ) { 713 if ( delSel.findRef( tempinc ) == -1 ) {
721 if ( tempinc->typeID() == todoID && onlyDueTodos ) { 714 if ( tempinc->typeID() == todoID && onlyDueTodos ) {
722 if ( ((Todo*)tempinc)->hasDueDate() ) 715 if ( ((Todo*)tempinc)->hasDueDate() )
723 delSel.append( tempinc ); 716 delSel.append( tempinc );
724 } else 717 } else
725 delSel.append( tempinc ); 718 delSel.append( tempinc );
726 } 719 }
727 tempinc = tempSel.next(); 720 tempinc = tempSel.next();
728 } 721 }
729 } 722 }
730 } 723 }
731 } 724 }
732 } 725 }
733 item = item->nextSibling(); 726 item = item->nextSibling();
734 } 727 }
735 return delSel; 728 return delSel;
736} 729}
737 730
738void KOListView::writeToFile( bool iCal ) 731void KOListView::writeToFile( bool iCal )
739{ 732{
740 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed; 733 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;
741 if ( !iCal ) { 734 if ( !iCal ) {
742 bool journal = false; 735 bool journal = false;
743 Incidence *incidence = delSel.first(); 736 Incidence *incidence = delSel.first();
744 while ( incidence ) { 737 while ( incidence ) {
745 if ( incidence->typeID() == journalID ) { 738 if ( incidence->typeID() == journalID ) {
746 journal = true; 739 journal = true;
747 break; 740 break;
748 } 741 }
749 incidence = delSel.next(); 742 incidence = delSel.next();
750 } 743 }
751 if ( journal ) { 744 if ( journal ) {
752 int result = KMessageBox::warningContinueCancel(this, 745 int result = KMessageBox::warningContinueCancel(this,
753 i18n("The journal entries can not be\nexported to a vCalendar file."), 746 i18n("The journal entries can not be\nexported to a vCalendar file."),
754 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 747 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
755 true); 748 true);
756 if (result != KMessageBox::Continue) return; 749 if (result != KMessageBox::Continue) return;
757 } 750 }
758 } 751 }
759 if ( delSel.count() ) { 752 if ( delSel.count() ) {
760 QString fn = KOPrefs::instance()->mLastSaveFile; 753 QString fn = KOPrefs::instance()->mLastSaveFile;
761 QString extension; 754 QString extension;
762 if ( iCal ) { 755 if ( iCal ) {
763 if ( fn.right( 4 ).lower() == ".vcs" ) { 756 if ( fn.right( 4 ).lower() == ".vcs" ) {
764 fn = fn.left( fn.length() -3) + "ics"; 757 fn = fn.left( fn.length() -3) + "ics";
765 } 758 }
766 } else { 759 } else {
767 if ( fn.right( 4 ).lower() == ".ics" ) { 760 if ( fn.right( 4 ).lower() == ".ics" ) {
768 fn = fn.left( fn.length() -3) + "vcs"; 761 fn = fn.left( fn.length() -3) + "vcs";
769 } 762 }
770 } 763 }
771 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this ); 764 fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
772 765
773 if ( fn == "" ) 766 if ( fn == "" )
774 return; 767 return;
775 QFileInfo info; 768 QFileInfo info;
776 info.setFile( fn ); 769 info.setFile( fn );
777 QString mes; 770 QString mes;
778 bool createbup = true; 771 bool createbup = true;
779 if ( info. exists() ) { 772 if ( info. exists() ) {
780 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 773 mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
781 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 774 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
782 i18n("Overwrite!"), i18n("Cancel"), 0, 775 i18n("Overwrite!"), i18n("Cancel"), 0,
783 0, 1 ); 776 0, 1 );
784 if ( result != 0 ) { 777 if ( result != 0 ) {
785 createbup = false; 778 createbup = false;
786 } 779 }
787 } 780 }
788 if ( createbup ) { 781 if ( createbup ) {
789 CalendarLocal cal; 782 CalendarLocal cal;
790 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 783 cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
791 Incidence *incidence = delSel.first(); 784 Incidence *incidence = delSel.first();
792 while ( incidence ) { 785 while ( incidence ) {
793 cal.addIncidence( incidence->clone() ); 786 cal.addIncidence( incidence->clone() );
794 incidence = delSel.next(); 787 incidence = delSel.next();
795 } 788 }
796 if ( iCal ) { 789 if ( iCal ) {
797 ICalFormat format; 790 ICalFormat format;
798 format.save( &cal, fn ); 791 format.save( &cal, fn );
799 } else { 792 } else {
800 793
801 VCalFormat format; 794 VCalFormat format;
802 format.save( &cal, fn ); 795 format.save( &cal, fn );
803 } 796 }
804 mes = i18n("KO/Pi:Saved %1").arg(fn ); 797 mes = i18n("KO/Pi:Saved %1").arg(fn );
805 KOPrefs::instance()->mLastSaveFile = fn; 798 KOPrefs::instance()->mLastSaveFile = fn;
806 topLevelWidget()->setCaption(mes); 799 topLevelWidget()->setCaption(mes);
807 } 800 }
808 } 801 }
809 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) ); 802 QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
810} 803}
811void KOListView::hideAll() 804void KOListView::hideAll()
812{ 805{
813 QPtrList<QListViewItem> delSel ; 806 QPtrList<QListViewItem> delSel ;
814 QListViewItem *item = mListView->firstChild (); 807 QListViewItem *item = mListView->firstChild ();
815 while ( item ) { 808 while ( item ) {
816 if ( item->isSelected() ) { 809 if ( item->isSelected() ) {
817 delSel.append(item); 810 delSel.append(item);
818 } 811 }
819 item = item->nextSibling(); 812 item = item->nextSibling();
820 } 813 }
821 item = delSel.first() ; 814 item = delSel.first() ;
822 while ( item ) { 815 while ( item ) {
823 QListViewItem * del = item; 816 QListViewItem * del = item;
824 item = delSel.next(); 817 item = delSel.next();
825 delete del; 818 delete del;
826 } 819 }
827} 820}
828void KOListView::printList() 821void KOListView::printList()
829{ 822{
830 mListView->printList(); 823 mListView->printList();
831} 824}
832void KOListView::deleteAll() 825void KOListView::deleteAll()
833{ 826{
834 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;; 827 QPtrList<Incidence> delSel = getSelectedIncidences(); // all inc allowed;;
835 if ( delSel.count() ) { 828 if ( delSel.count() ) {
836 int icount = delSel.count(); 829 int icount = delSel.count();
837 Incidence *incidence = delSel.first(); 830 Incidence *incidence = delSel.first();
838 Incidence *toDelete; 831 Incidence *toDelete;
839 KOPrefs *p = KOPrefs::instance(); 832 KOPrefs *p = KOPrefs::instance();
840 bool confirm = p->mConfirm; 833 bool confirm = p->mConfirm;
841 QString mess; 834 QString mess;
842 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount ); 835 mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount );
843 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) { 836 if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) {
844 p->mConfirm = false; 837 p->mConfirm = false;
845 int delCounter = 0; 838 int delCounter = 0;
846 QDialog dia ( this, "p-dialog", true ); 839 QDialog dia ( this, "p-dialog", true );
847 QLabel lab (i18n("Close dialog to abort deletion!"), &dia ); 840 QLabel lab (i18n("Close dialog to abort deletion!"), &dia );
848 QVBoxLayout lay( &dia ); 841 QVBoxLayout lay( &dia );
849 lay.setMargin(7); 842 lay.setMargin(7);
850 lay.setSpacing(7); 843 lay.setSpacing(7);
851 lay.addWidget( &lab); 844 lay.addWidget( &lab);
852 QProgressBar bar( icount, &dia ); 845 QProgressBar bar( icount, &dia );
853 lay.addWidget( &bar); 846 lay.addWidget( &bar);
854 int w = 220; 847 int w = 220;
855 int h = 50; 848 int h = 50;
856 int dw = QApplication::desktop()->width(); 849 int dw = QApplication::desktop()->width();
857 int dh = QApplication::desktop()->height(); 850 int dh = QApplication::desktop()->height();
858 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 851 dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
859 //dia.resize( 240,50 ); 852 //dia.resize( 240,50 );
860 dia.show(); 853 dia.show();
861 KOPrefs::instance()->mGlobalUpdateDisabled = true; 854 KOPrefs::instance()->mGlobalUpdateDisabled = true;
862 while ( incidence ) { 855 while ( incidence ) {
863 bar.setProgress( delCounter ); 856 bar.setProgress( delCounter );
864 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter ); 857 mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter );
865 dia.setCaption( mess ); 858 dia.setCaption( mess );
866 qApp->processEvents(); 859 qApp->processEvents();
867 toDelete = (incidence); 860 toDelete = (incidence);
868 incidence = delSel.next(); 861 incidence = delSel.next();
869 emit deleteIncidenceSignal(toDelete ); 862 emit deleteIncidenceSignal(toDelete );
870 if ( dia.result() != 0 ) 863 if ( dia.result() != 0 )
871 break; 864 break;
872 865
873 } 866 }
874 KOPrefs::instance()->mGlobalUpdateDisabled = false; 867 KOPrefs::instance()->mGlobalUpdateDisabled = false;
875 emit deleteIncidenceSignal( 0 ); 868 emit deleteIncidenceSignal( 0 );
876 mess = mess.sprintf( i18n("%d items remaining in list."), count() ); 869 mess = mess.sprintf( i18n("%d items remaining in list."), count() );
877 topLevelWidget ()->setCaption( mess ); 870 topLevelWidget ()->setCaption( mess );
878 p->mConfirm = confirm; 871 p->mConfirm = confirm;
879 } 872 }
880 } 873 }
881 874
882 875
883} 876}
884int KOListView::maxDatesHint() 877int KOListView::maxDatesHint()
885{ 878{
886 return 0; 879 return 0;
887} 880}
888 881
889int KOListView::currentDateCount() 882int KOListView::currentDateCount()
890{ 883{
891 return 0; 884 return 0;
892} 885}
893 886
894QPtrList<Incidence> KOListView::selectedIncidences() 887QPtrList<Incidence> KOListView::selectedIncidences()
895{ 888{
896 QPtrList<Incidence> eventList; 889 QPtrList<Incidence> eventList;
897 QListViewItem *item = mListView->firstChild (); 890 QListViewItem *item = mListView->firstChild ();
898 while ( item ) { 891 while ( item ) {
899 if ( item->isSelected() ) { 892 if ( item->isSelected() ) {
900 eventList.append(((KOListViewItem *)item)->data()); 893 eventList.append(((KOListViewItem *)item)->data());
901 } 894 }
902 895
903 item = item->nextSibling(); 896 item = item->nextSibling();
904 } 897 }
905 898
906 // // QListViewItem *item = mListView->selectedItem(); 899 // // QListViewItem *item = mListView->selectedItem();
907 //if (item) eventList.append(((KOListViewItem *)item)->data()); 900 //if (item) eventList.append(((KOListViewItem *)item)->data());
908 901
909 return eventList; 902 return eventList;
910} 903}
911 904
912DateList KOListView::selectedDates() 905DateList KOListView::selectedDates()
913{ 906{
914 DateList eventList; 907 DateList eventList;
915 return eventList; 908 return eventList;
916} 909}
917 910
918void KOListView::showDates(bool show) 911void KOListView::showDates(bool show)
919{ 912{
920 // Shouldn't we set it to a value greater 0? When showDates is called with 913 // Shouldn't we set it to a value greater 0? When showDates is called with
921 // show == true at first, then the columnwidths are set to zero. 914 // show == true at first, then the columnwidths are set to zero.
922 static int oldColWidth1 = 0; 915 static int oldColWidth1 = 0;
923 static int oldColWidth3 = 0; 916 static int oldColWidth3 = 0;
924 917
925 if (!show) { 918 if (!show) {
926 oldColWidth1 = mListView->columnWidth(1); 919 oldColWidth1 = mListView->columnWidth(1);
927 oldColWidth3 = mListView->columnWidth(3); 920 oldColWidth3 = mListView->columnWidth(3);
928 mListView->setColumnWidth(1, 0); 921 mListView->setColumnWidth(1, 0);
929 mListView->setColumnWidth(3, 0); 922 mListView->setColumnWidth(3, 0);
930 } else { 923 } else {
931 mListView->setColumnWidth(1, oldColWidth1); 924 mListView->setColumnWidth(1, oldColWidth1);
932 mListView->setColumnWidth(3, oldColWidth3); 925 mListView->setColumnWidth(3, oldColWidth3);
933 } 926 }
934 mListView->repaint(); 927 mListView->repaint();
935} 928}
936 929
937void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, 930void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd,
938 const QDate &td) 931 const QDate &td)
939{ 932{
940#ifndef KORG_NOPRINTER 933#ifndef KORG_NOPRINTER
941 calPrinter->preview(CalPrinter::Day, fd, td); 934 calPrinter->preview(CalPrinter::Day, fd, td);
942#endif 935#endif
943} 936}
944 937
945void KOListView::showDates() 938void KOListView::showDates()
946{ 939{
947 showDates(true); 940 showDates(true);
948} 941}
949 942
950void KOListView::hideDates() 943void KOListView::hideDates()
951{ 944{
952 showDates(false); 945 showDates(false);
953} 946}
954 947
955void KOListView::resetFocus() 948void KOListView::resetFocus()
956{ 949{
957 topLevelWidget()->setActiveWindow(); 950 topLevelWidget()->setActiveWindow();
958 topLevelWidget()->raise(); 951 topLevelWidget()->raise();
959 mListView->setFocus(); 952 mListView->setFocus();
960} 953}
961void KOListView::updateView() 954void KOListView::updateView()
962{ 955{
963 mListView->setFocus(); 956 mListView->setFocus();
964 if ( mListView->firstChild () ) { 957 if ( mListView->firstChild () ) {
965 mListView->setCurrentItem( mListView->firstChild () ); 958 mListView->setCurrentItem( mListView->firstChild () );
966 } 959 }
967 processSelectionChange( mListView->firstChild () ); 960 processSelectionChange( mListView->firstChild () );
968} 961}
969void KOListView::updateConfig() 962void KOListView::updateConfig()
970{ 963{
971 964
972 mListView->setFont ( KOPrefs::instance()->mListViewFont ); 965 mListView->setFont ( KOPrefs::instance()->mListViewFont );
973 updateView(); 966 updateView();
974 967
975} 968}
976void KOListView::setStartDate(const QDate &start) 969void KOListView::setStartDate(const QDate &start)
977{ 970{
978 mStartDate = start; 971 mStartDate = start;
979} 972}
980 973
981void KOListView::showDates(const QDate &start, const QDate &end) 974void KOListView::showDates(const QDate &start, const QDate &end)
982{ 975{
983 clear(); 976 clear();
984 mStartDate = start; 977 mStartDate = start;
985 QDate date = start; 978 QDate date = start;
986 while( date <= end ) { 979 while( date <= end ) {
987 addEvents(calendar()->events(date)); 980 addEvents(calendar()->events(date));
988 addTodos(calendar()->todos(date)); 981 addTodos(calendar()->todos(date));
989 addJournals( calendar()->journals4Date(date) ); 982 addJournals( calendar()->journals4Date(date) );
990 date = date.addDays( 1 ); 983 date = date.addDays( 1 );
991 } 984 }
992 //emit incidenceSelected( 0 ); 985 //emit incidenceSelected( 0 );
993 updateView(); 986 updateView();
994 987
995} 988}
996 989
997void KOListView::addEvents(QPtrList<Event> eventList) 990void KOListView::addEvents(QPtrList<Event> eventList)
998{ 991{
999 992
1000 Event *ev; 993 Event *ev;
1001 for(ev = eventList.first(); ev; ev = eventList.next()) { 994 for(ev = eventList.first(); ev; ev = eventList.next()) {
1002 addIncidence(ev); 995 addIncidence(ev);
1003 } 996 }
1004 if ( !mListView->currentItem() ){ 997 if ( !mListView->currentItem() ){
1005 updateView(); 998 updateView();
1006 } 999 }
1007} 1000}
1008 1001
1009void KOListView::addTodos(QPtrList<Todo> eventList) 1002void KOListView::addTodos(QPtrList<Todo> eventList)
1010{ 1003{
1011 Todo *ev; 1004 Todo *ev;
1012 for(ev = eventList.first(); ev; ev = eventList.next()) { 1005 for(ev = eventList.first(); ev; ev = eventList.next()) {
1013 addIncidence(ev); 1006 addIncidence(ev);
1014 } 1007 }
1015 if ( !mListView->currentItem() ){ 1008 if ( !mListView->currentItem() ){
1016 updateView(); 1009 updateView();
1017 } 1010 }
1018} 1011}
1019void KOListView::addJournals(QPtrList<Journal> eventList) 1012void KOListView::addJournals(QPtrList<Journal> eventList)
1020{ 1013{
1021 Journal *ev; 1014 Journal *ev;
1022 for(ev = eventList.first(); ev; ev = eventList.next()) { 1015 for(ev = eventList.first(); ev; ev = eventList.next()) {
1023 addIncidence(ev); 1016 addIncidence(ev);
1024 } 1017 }
1025 if ( !mListView->currentItem() ){ 1018 if ( !mListView->currentItem() ){
1026 updateView(); 1019 updateView();
1027 } 1020 }
1028} 1021}
1029 1022
1030void KOListView::showCompletedTodos() 1023void KOListView::showCompletedTodos()
1031{ 1024{
1032 mForceShowCompletedTodos = true; 1025 mForceShowCompletedTodos = true;
1033} 1026}
1034void KOListView::addIncidence(Incidence *incidence) 1027void KOListView::addIncidence(Incidence *incidence)
1035{ 1028{
1036 if ( mUidDict.find( incidence->uid() ) ) return; 1029 if ( mUidDict.find( incidence->uid() ) ) return;
1037 1030
1038 // mListView->setFont ( KOPrefs::instance()->mListViewFont ); 1031 // mListView->setFont ( KOPrefs::instance()->mListViewFont );
1039 if ( incidence->typeID() == todoID ) { 1032 if ( incidence->typeID() == todoID ) {
1040 if ( ! mForceShowCompletedTodos ) { 1033 if ( ! mForceShowCompletedTodos ) {
1041 if ( !KOPrefs::instance()->mShowCompletedTodo && ((Todo*)incidence)->isCompleted() ) 1034 if ( !KOPrefs::instance()->mShowCompletedTodo && ((Todo*)incidence)->isCompleted() )
1042 return; 1035 return;
1043 } 1036 }
1044 } 1037 }
1045 mUidDict.insert( incidence->uid(), incidence ); 1038 mUidDict.insert( incidence->uid(), incidence );
1046 KOListViewItem *item = new KOListViewItem( incidence, mListView ); 1039 KOListViewItem *item = new KOListViewItem( incidence, mListView );
1047 ListItemVisitor v(item, mStartDate ); 1040 ListItemVisitor v(item, mStartDate );
1048 if (incidence->accept(v)) { 1041 if (incidence->accept(v)) {
1049 return; 1042 return;
1050 } 1043 }
1051 else delete item; 1044 else delete item;
1052} 1045}
1053 1046
1054void KOListView::showEvents(QPtrList<Event> eventList) 1047void KOListView::showEvents(QPtrList<Event> eventList)
1055{ 1048{
1056 clear(); 1049 clear();
1057 1050
1058 addEvents(eventList); 1051 addEvents(eventList);
1059 1052
1060 // After new creation of list view no events are selected. 1053 // After new creation of list view no events are selected.
1061 emit incidenceSelected( 0 ); 1054 emit incidenceSelected( 0 );
1062} 1055}
1063int KOListView::count() 1056int KOListView::count()
1064{ 1057{
1065 return mListView->childCount(); 1058 return mListView->childCount();
1066} 1059}
1067 1060
1068void KOListView::changeEventDisplay(Event *event, int action) 1061void KOListView::changeEventDisplay(Event *event, int action)
1069{ 1062{
1070 KOListViewItem *item; 1063 KOListViewItem *item;
1071 1064
1072 switch(action) { 1065 switch(action) {
1073 case KOGlobals::EVENTADDED: 1066 case KOGlobals::EVENTADDED:
1074 addIncidence( event ); 1067 addIncidence( event );
1075 break; 1068 break;
1076 case KOGlobals::EVENTEDITED: 1069 case KOGlobals::EVENTEDITED:
1077 item = getItemForEvent(event); 1070 item = getItemForEvent(event);
1078 if (item) { 1071 if (item) {
1079 ListItemVisitor v(item, mStartDate ); 1072 ListItemVisitor v(item, mStartDate );
1080 ((Incidence*)event)->accept(v); 1073 ((Incidence*)event)->accept(v);
1081 } 1074 }
1082 break; 1075 break;
1083 case KOGlobals::EVENTDELETED: 1076 case KOGlobals::EVENTDELETED:
1084 item = getItemForEvent(event); 1077 item = getItemForEvent(event);
1085 if (item) { 1078 if (item) {
1086 mUidDict.remove( event->uid() ); 1079 mUidDict.remove( event->uid() );
1087 delete item; 1080 delete item;
1088 } 1081 }
1089 break; 1082 break;
1090 default: 1083 default:
1091 ; 1084 ;
1092 } 1085 }
1093} 1086}
1094 1087
1095KOListViewItem *KOListView::getItemForEvent(Incidence *event) 1088KOListViewItem *KOListView::getItemForEvent(Incidence *event)
1096{ 1089{
1097 KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); 1090 KOListViewItem *item = (KOListViewItem *)mListView->firstChild();
1098 while (item) { 1091 while (item) {
1099 if (item->data() == event) return item; 1092 if (item->data() == event) return item;
1100 item = (KOListViewItem *)item->nextSibling(); 1093 item = (KOListViewItem *)item->nextSibling();
1101 } 1094 }
1102 return 0; 1095 return 0;
1103} 1096}
1104 1097
1105void KOListView::defaultItemAction(QListViewItem *i) 1098void KOListView::defaultItemAction(QListViewItem *i)
1106{ 1099{
1107 KOListViewItem *item = static_cast<KOListViewItem *>( i ); 1100 KOListViewItem *item = static_cast<KOListViewItem *>( i );
1108 if ( item ) defaultAction( item->data() ); 1101 if ( item ) defaultAction( item->data() );
1109 1102
1110} 1103}
1111 1104
1112void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) 1105void KOListView::popupMenu(QListViewItem *item,const QPoint &,int)
1113{ 1106{
1114 mActiveItem = (KOListViewItem *)item; 1107 mActiveItem = (KOListViewItem *)item;
1115 if (mActiveItem) { 1108 if (mActiveItem) {
1116 Incidence *incidence = mActiveItem->data(); 1109 Incidence *incidence = mActiveItem->data();
1117 mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) ); 1110 mPopupMenu->enableDefault( !mListView->hasMultiSelection( item ) );
1118 mPopupMenu->showIncidencePopup(incidence); 1111 mPopupMenu->showIncidencePopup(incidence);
1119 1112
1120 /* 1113 /*
1121 if ( incidence && incidence->type() == "Event" ) { 1114 if ( incidence && incidence->type() == "Event" ) {
1122 Event *event = static_cast<Event *>( incidence ); 1115 Event *event = static_cast<Event *>( incidence );
1123 mPopupMenu->showEventPopup(event); 1116 mPopupMenu->showEventPopup(event);
1124 } 1117 }
1125 */ 1118 */
1126 } 1119 }
1127} 1120}
1128 1121
1129void KOListView::readSettings(KConfig *config, QString setting) 1122void KOListView::readSettings(KConfig *config, QString setting)
1130{ 1123{
1131 // qDebug("KOListView::readSettings "); 1124 // qDebug("KOListView::readSettings ");
1132 mListView->restoreLayout(config,setting); 1125 mListView->restoreLayout(config,setting);
1133} 1126}
1134 1127
1135void KOListView::writeSettings(KConfig *config, QString setting) 1128void KOListView::writeSettings(KConfig *config, QString setting)
1136{ 1129{
1137 // qDebug("KOListView::writeSettings "); 1130 // qDebug("KOListView::writeSettings ");
1138 mListView->saveLayout(config, setting); 1131 mListView->saveLayout(config, setting);
1139} 1132}
1140 1133
1141void KOListView::processSelectionChange(QListViewItem *) 1134void KOListView::processSelectionChange(QListViewItem *)
1142{ 1135{
1143 1136
1144 KOListViewItem *item = 1137 KOListViewItem *item =
1145 static_cast<KOListViewItem *>( mListView->currentItem() ); 1138 static_cast<KOListViewItem *>( mListView->currentItem() );
1146 1139
1147 if ( !item ) { 1140 if ( !item ) {
1148 emit incidenceSelected( 0 ); 1141 emit incidenceSelected( 0 );
1149 } else { 1142 } else {
1150 emit incidenceSelected( item->data() ); 1143 emit incidenceSelected( item->data() );
1151 } 1144 }
1152} 1145}
1153 1146
1154void KOListView::clearSelection() 1147void KOListView::clearSelection()
1155{ 1148{
1156 mListView->selectAll( false ); 1149 mListView->selectAll( false );
1157} 1150}
1158void KOListView::allSelection() 1151void KOListView::allSelection()
1159{ 1152{
1160 mListView->selectAll( true ); 1153 mListView->selectAll( true );
1161} 1154}
1162 1155
1163void KOListView::clear() 1156void KOListView::clear()
1164{ 1157{
1165 mListView->clear(); 1158 mListView->clear();
1166 mUidDict.clear(); 1159 mUidDict.clear();
1167} 1160}
1168 1161
1169Incidence* KOListView::currentItem() 1162Incidence* KOListView::currentItem()
1170{ 1163{
1171 if ( mListView->currentItem() ) 1164 if ( mListView->currentItem() )
1172 return ((KOListViewItem*) mListView->currentItem())->data(); 1165 return ((KOListViewItem*) mListView->currentItem())->data();
1173 return 0; 1166 return 0;
1174} 1167}
1175void KOListView::keyPressEvent ( QKeyEvent *e) 1168void KOListView::keyPressEvent ( QKeyEvent *e)
1176{ 1169{
1177 1170
1178 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) { 1171 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace ) {
1179 deleteAll(); 1172 deleteAll();
1180 return; 1173 return;
1181 } 1174 }
1182 1175
1183 e->ignore(); 1176 e->ignore();
1184} 1177}
1185void KOListViewListView::keyPressEvent ( QKeyEvent *e) 1178void KOListViewListView::keyPressEvent ( QKeyEvent *e)
1186{ 1179{
1187 1180
1188 switch ( e->key() ) { 1181 switch ( e->key() ) {
1189 case Qt::Key_Down: 1182 case Qt::Key_Down:
1190 if ( e->state() == ShiftButton ) { 1183 if ( e->state() == ShiftButton ) {
1191 QListViewItem* cn = currentItem(); 1184 QListViewItem* cn = currentItem();
1192 if ( !cn ) 1185 if ( !cn )
1193 cn = firstChild(); 1186 cn = firstChild();
1194 if ( !cn ) 1187 if ( !cn )
1195 return; 1188 return;
1196 while ( cn->nextSibling() ) 1189 while ( cn->nextSibling() )
1197 cn = cn->nextSibling(); 1190 cn = cn->nextSibling();
1198 setCurrentItem ( cn ); 1191 setCurrentItem ( cn );
1199 ensureItemVisible ( cn ); 1192 ensureItemVisible ( cn );
1200 1193
1201 e->accept(); 1194 e->accept();
1202 return; 1195 return;
1203 } 1196 }
1204 if ( e->state() == ControlButton ) { 1197 if ( e->state() == ControlButton ) {
1205 int count = childCount (); 1198 int count = childCount ();
1206 int jump = count / 5; 1199 int jump = count / 5;
1207 QListViewItem* cn; 1200 QListViewItem* cn;
1208 cn = currentItem(); 1201 cn = currentItem();
1209 if ( ! cn ) 1202 if ( ! cn )
1210 return; 1203 return;
1211 if ( jump == 0 ) 1204 if ( jump == 0 )
1212 jump = 1; 1205 jump = 1;
1213 while ( jump && cn->nextSibling() ) { 1206 while ( jump && cn->nextSibling() ) {
1214 cn = cn->nextSibling(); 1207 cn = cn->nextSibling();
1215 --jump; 1208 --jump;
1216 } 1209 }
1217 setCurrentItem ( cn ); 1210 setCurrentItem ( cn );
1218 ensureItemVisible ( cn ); 1211 ensureItemVisible ( cn );
1219 1212
1220 } else 1213 } else
1221 QListView::keyPressEvent ( e ) ; 1214 QListView::keyPressEvent ( e ) ;
1222 e->accept(); 1215 e->accept();
1223 break; 1216 break;
1224 1217
1225 case Qt::Key_Up: 1218 case Qt::Key_Up:
1226 if ( e->state() == ShiftButton ) { 1219 if ( e->state() == ShiftButton ) {
1227 QListViewItem* cn = firstChild(); 1220 QListViewItem* cn = firstChild();
1228 if ( cn ) { 1221 if ( cn ) {
1229 setCurrentItem ( cn ); 1222 setCurrentItem ( cn );
1230 ensureItemVisible ( cn ); 1223 ensureItemVisible ( cn );
1231 } 1224 }
1232 e->accept(); 1225 e->accept();
1233 return; 1226 return;
1234 } 1227 }
1235 if ( e->state() == ControlButton ) { 1228 if ( e->state() == ControlButton ) {
1236 int count = childCount (); 1229 int count = childCount ();
1237 int jump = count / 5; 1230 int jump = count / 5;
1238 QListViewItem* cn; 1231 QListViewItem* cn;
1239 cn = currentItem(); 1232 cn = currentItem();
1240 if ( ! cn ) 1233 if ( ! cn )
1241 return; 1234 return;
1242 if ( jump == 0 ) 1235 if ( jump == 0 )
1243 jump = 1; 1236 jump = 1;
1244 while ( jump && cn->itemAbove ()) { 1237 while ( jump && cn->itemAbove ()) {
1245 cn = cn->itemAbove (); 1238 cn = cn->itemAbove ();
1246 --jump; 1239 --jump;
1247 } 1240 }
1248 setCurrentItem ( cn ); 1241 setCurrentItem ( cn );
1249 ensureItemVisible ( cn ); 1242 ensureItemVisible ( cn );
1250 } else 1243 } else
1251 QListView::keyPressEvent ( e ) ; 1244 QListView::keyPressEvent ( e ) ;
1252 e->accept(); 1245 e->accept();
1253 break; 1246 break;
1254 case Qt::Key_I: { 1247 case Qt::Key_I: {
1255 QListViewItem* cn; 1248 QListViewItem* cn;
1256 cn = currentItem(); 1249 cn = currentItem();
1257 if ( cn ) { 1250 if ( cn ) {
1258 KOListViewItem* ci = (KOListViewItem*)( cn ); 1251 KOListViewItem* ci = (KOListViewItem*)( cn );
1259 if ( ci ){ 1252 if ( ci ){
1260 //emit showIncidence( ci->data()); 1253 //emit showIncidence( ci->data());
1261 cn = cn->nextSibling(); 1254 cn = cn->nextSibling();
1262 if ( cn ) { 1255 if ( cn ) {
1263 setCurrentItem ( cn ); 1256 setCurrentItem ( cn );
1264 ensureItemVisible ( cn ); 1257 ensureItemVisible ( cn );
1265 } 1258 }
1266 emit showIncidence( ci->data()); 1259 emit showIncidence( ci->data());
1267 } 1260 }
1268 } 1261 }
1269 e->accept(); 1262 e->accept();
1270 } 1263 }
1271 break; 1264 break;
1272 case Qt::Key_Return: 1265 case Qt::Key_Return:
1273 case Qt::Key_Enter: 1266 case Qt::Key_Enter:
1274 { 1267 {
1275 QListViewItem* cn; 1268 QListViewItem* cn;
1276 cn = currentItem(); 1269 cn = currentItem();
1277 if ( cn ) { 1270 if ( cn ) {
1278 KOListViewItem* ci = (KOListViewItem*)( cn ); 1271 KOListViewItem* ci = (KOListViewItem*)( cn );
1279 if ( ci ){ 1272 if ( ci ){
1280 if ( e->state() == ShiftButton ) 1273 if ( e->state() == ShiftButton )
1281 ci->setSelected( false ); 1274 ci->setSelected( false );
1282 else 1275 else
1283 ci->setSelected( true ); 1276 ci->setSelected( true );
1284 cn = cn->nextSibling(); 1277 cn = cn->nextSibling();
1285 if ( cn ) { 1278 if ( cn ) {
1286 setCurrentItem ( cn ); 1279 setCurrentItem ( cn );
1287 ensureItemVisible ( cn ); 1280 ensureItemVisible ( cn );
1288 } else { 1281 } else {
1289 emit currentChanged( ci ); 1282 emit currentChanged( ci );
1290 } 1283 }
1291 } 1284 }
1292 } 1285 }
1293 e->accept(); 1286 e->accept();
1294 } 1287 }
1295 break; 1288 break;
1296 default: 1289 default:
1297 e->ignore(); 1290 e->ignore();
1298 } 1291 }
1299} 1292}
1300KOListViewListView::KOListViewListView(KOListView * lv ) 1293KOListViewListView::KOListViewListView(KOListView * lv )
1301 : KListView( lv, "kolistlistview", false ) 1294 : KListView( lv, "kolistlistview", false )
1302{ 1295{
1303 mYMousePos = 0; 1296 mYMousePos = 0;
1304 mPopupTimer = new QTimer(this); 1297 mPopupTimer = new QTimer(this);
1305 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 1298 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
1306#ifndef DESKTOP_VERSION 1299#ifndef DESKTOP_VERSION
1307 //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 1300 //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
1308#endif 1301#endif
1309 setSelectionMode( QListView::Multi ); 1302 setSelectionMode( QListView::Multi );
1310 setMultiSelection( true); 1303 setMultiSelection( true);
1311} 1304}
1312bool KOListViewListView::hasMultiSelection(QListViewItem* item) 1305bool KOListViewListView::hasMultiSelection(QListViewItem* item)
1313{ 1306{
1314 QListViewItem *qitem = firstChild (); 1307 QListViewItem *qitem = firstChild ();
1315 while ( qitem ) { 1308 while ( qitem ) {
1316 if ( qitem->isSelected() && item != qitem ) 1309 if ( qitem->isSelected() && item != qitem )
1317 return true; 1310 return true;
1318 qitem = qitem->nextSibling(); 1311 qitem = qitem->nextSibling();
1319 } 1312 }
1320 return false; 1313 return false;
1321} 1314}
1322void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 1315void KOListViewListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1323{ 1316{
1324 if (!e) return; 1317 if (!e) return;
1325 QPoint vp = contentsToViewport(e->pos()); 1318 QPoint vp = contentsToViewport(e->pos());
1326 QListViewItem *item = itemAt(vp); 1319 QListViewItem *item = itemAt(vp);
1327 if (!item) { 1320 if (!item) {
1328 emit newEvent(); 1321 emit newEvent();
1329 return; 1322 return;
1330 } 1323 }
1331 KListView::contentsMouseDoubleClickEvent(e); 1324 KListView::contentsMouseDoubleClickEvent(e);
1332} 1325}
1333#if 0 1326#if 0
1334void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1327void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1335{ 1328{
1336 //qDebug("contentsMousePressEvent++++ "); 1329 //qDebug("contentsMousePressEvent++++ ");
1337 KListView::contentsMousePressEvent( e ); 1330 KListView::contentsMousePressEvent( e );
1338 if ( e->button() == RightButton ) { 1331 if ( e->button() == RightButton ) {
1339 QListViewItem* ci = currentItem(); 1332 QListViewItem* ci = currentItem();
1340 clearSelection () ; 1333 clearSelection () ;
1341 if ( ci ) 1334 if ( ci )
1342 ci->setSelected( true ); 1335 ci->setSelected( true );
1343 } 1336 }
1344} 1337}
1345void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1338void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1346{ 1339{
1347 KListView::contentsMouseReleaseEvent(e); 1340 KListView::contentsMouseReleaseEvent(e);
1348} 1341}
1349void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1342void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1350{ 1343{
1351 KListView::contentsMouseMoveEvent(e); 1344 KListView::contentsMouseMoveEvent(e);
1352} 1345}
1353#endif 1346#endif
1354void KOListViewListView::popupMenu() 1347void KOListViewListView::popupMenu()
1355{ 1348{
1356 mPopupTimer->stop(); 1349 mPopupTimer->stop();
1357 QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton ); 1350 QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton );
1358 QApplication::postEvent( this->viewport(), e ); 1351 QApplication::postEvent( this->viewport(), e );
1359 1352
1360} 1353}
1361void KOListViewListView::contentsMousePressEvent(QMouseEvent *e) 1354void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
1362{ 1355{
1363 //qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y()); 1356 //qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y());
1364 mYMousePos = mapToGlobal( (e->pos())).y(); 1357 mYMousePos = mapToGlobal( (e->pos())).y();
1365 if ( e->button() == LeftButton ) { 1358 if ( e->button() == LeftButton ) {
1366 mPopupTimer->start( 600 ); 1359 mPopupTimer->start( 600 );
1367 mEventPos = contentsToViewport(e->pos()); 1360 mEventPos = contentsToViewport(e->pos());
1368 mEventGlobalPos = e->globalPos(); 1361 mEventGlobalPos = e->globalPos();
1369 } 1362 }
1370 KListView::contentsMousePressEvent( e ); 1363 KListView::contentsMousePressEvent( e );
1371 if ( e->button() == RightButton ) { 1364 if ( e->button() == RightButton ) {
1372 QListViewItem* ci = currentItem(); 1365 QListViewItem* ci = currentItem();
1373 //clearSelection(); 1366 //clearSelection();
1374 if ( ci ) 1367 if ( ci )
1375 ci->setSelected( true ); 1368 ci->setSelected( true );
1376 } 1369 }
1377} 1370}
1378void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e) 1371void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
1379{ 1372{
1380 mPopupTimer->stop(); 1373 mPopupTimer->stop();
1381 KListView::contentsMouseReleaseEvent(e); 1374 KListView::contentsMouseReleaseEvent(e);
1382} 1375}
1383void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e) 1376void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
1384{ 1377{
1385 // qDebug("contentsMouseMoveEv....... "); 1378 // qDebug("contentsMouseMoveEv....... ");
1386 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() ); 1379 // qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() );
1387 int diff = mYMousePos - mapToGlobal( (e->pos())).y(); 1380 int diff = mYMousePos - mapToGlobal( (e->pos())).y();
1388 if ( diff < 0 ) diff = -diff; 1381 if ( diff < 0 ) diff = -diff;
1389 if ( diff > 15 ) 1382 if ( diff > 15 )
1390 mPopupTimer->stop(); 1383 mPopupTimer->stop();
1391 else { 1384 else {
1392 mEventPos = contentsToViewport(e->pos()); 1385 mEventPos = contentsToViewport(e->pos());
1393 mEventGlobalPos = e->globalPos(); 1386 mEventGlobalPos = e->globalPos();
1394 } 1387 }
1395 KListView::contentsMouseMoveEvent(e); 1388 KListView::contentsMouseMoveEvent(e);
1396} 1389}
1397 1390
1398#define protected public 1391#define protected public
1399#include <qheader.h> 1392#include <qheader.h>
1400#undef protected 1393#undef protected
1401void KOListViewListView::printList() 1394void KOListViewListView::printList()
1402{ 1395{
1403#ifdef DESKTOP_VERSION 1396#ifdef DESKTOP_VERSION
1404 KOPrintPrefs pp ( this ); 1397 KOPrintPrefs pp ( this );
1405 if (!pp.exec() ) 1398 if (!pp.exec() )
1406 return; 1399 return;
1407 int scaleval = pp.printMode() ; 1400 int scaleval = pp.printMode() ;
1408 1401
1409 QPrinter printer; 1402 QPrinter printer;
1410 if (!printer.setup() ) 1403 if (!printer.setup() )
1411 return; 1404 return;
1412 clearSelection (); 1405 clearSelection ();
1413 QPainter p; 1406 QPainter p;
1414 p.begin ( &printer ); 1407 p.begin ( &printer );
1415 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 1408 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
1416 float dx, dy; 1409 float dx, dy;
1417 int wid = (m.width() * 9)/10; 1410 int wid = (m.width() * 9)/10;
1418 dx = (float) wid/(float)contentsWidth (); 1411 dx = (float) wid/(float)contentsWidth ();
1419 dy = (float)(m.height()) / (float)contentsHeight (); 1412 dy = (float)(m.height()) / (float)contentsHeight ();
1420 float scale; 1413 float scale;
1421 // scale to fit the width or height of the paper 1414 // scale to fit the width or height of the paper
1422 if ( dx < dy ) 1415 if ( dx < dy )
1423 scale = dx; 1416 scale = dx;
1424 else 1417 else
1425 scale = dy; 1418 scale = dy;
1426 1419
1427 p.translate( m.width()/10,m.width()/10 ); 1420 p.translate( m.width()/10,m.width()/10 );
1428 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) { 1421 if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) {
1429 p.scale( scale, scale ); 1422 p.scale( scale, scale );
1430 } 1423 }
1431 1424
1432 int cou = header()->count(); 1425 int cou = header()->count();
1433 int iii; 1426 int iii;
1434 QRect rect ( 0,0,0, header()->height()); 1427 QRect rect ( 0,0,0, header()->height());
1435 for ( iii = 0; iii < cou; ++iii ) { 1428 for ( iii = 0; iii < cou; ++iii ) {
1436 rect.setLeft ( header()->sectionPos( iii ) ); 1429 rect.setLeft ( header()->sectionPos( iii ) );
1437 rect.setRight ( header()->sectionPos( iii ) + header()->sectionSize (iii)); 1430 rect.setRight ( header()->sectionPos( iii ) + header()->sectionSize (iii));
1438 header()->paintSection ( & p, header()->mapToIndex (iii), rect ); 1431 header()->paintSection ( & p, header()->mapToIndex (iii), rect );
1439 } 1432 }
1440 p.translate( 0, header()->height()); 1433 p.translate( 0, header()->height());
1441 drawContentsOffset ( &p, 0,0, 0,0, contentsWidth (), contentsHeight () ); 1434 drawContentsOffset ( &p, 0,0, 0,0, contentsWidth (), contentsHeight () );
1442 p.end(); 1435 p.end();
1443#endif 1436#endif
1444} 1437}
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index bdef94c..848e9e7 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,576 +1,570 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23#include <kglobal.h> 23#include <kglobal.h>
24 24
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include "kotodoviewitem.h" 26#include "kotodoviewitem.h"
27#include "kotodoview.h" 27#include "kotodoview.h"
28#include "koprefs.h" 28#include "koprefs.h"
29 29
30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 30KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 31 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
32{ 32{
33 construct(); 33 construct();
34} 34}
35 35
36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 36KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 37 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
38{ 38{
39 construct(); 39 construct();
40} 40}
41 41
42QString KOTodoViewItem::key(int column,bool) const 42QString KOTodoViewItem::key(int column,bool) const
43{ 43{
44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 44 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
45 if (it == mKeyMap.end()) { 45 if (it == mKeyMap.end()) {
46 return text(column).lower(); 46 return text(column).lower();
47 } else { 47 } else {
48 return *it; 48 return *it;
49 } 49 }
50} 50}
51 51
52void KOTodoViewItem:: setup() 52void KOTodoViewItem:: setup()
53{ 53{
54 54
55 int h = 20; 55 int h = 20;
56 if ( listView () ) { 56 if ( listView () ) {
57 QFontMetrics fm ( listView ()->font () ); 57 QFontMetrics fm ( listView ()->font () );
58 h = fm.height(); 58 h = fm.height();
59 } 59 }
60 setHeight( h ); 60 setHeight( h );
61 61
62} 62}
63void KOTodoViewItem::setSortKey(int column,const QString &key) 63void KOTodoViewItem::setSortKey(int column,const QString &key)
64{ 64{
65 mKeyMap.insert(column,key); 65 mKeyMap.insert(column,key);
66} 66}
67 67
68#if QT_VERSION >= 0x030000 68#if QT_VERSION >= 0x030000
69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 69void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
70 int y,int h) 70 int y,int h)
71{ 71{
72 QListViewItem::paintBranches(p,cg,w,y,h); 72 QListViewItem::paintBranches(p,cg,w,y,h);
73} 73}
74#else 74#else
75#endif 75#endif
76 76
77void KOTodoViewItem::construct() 77void KOTodoViewItem::construct()
78{ 78{
79 // qDebug("KOTodoViewItem::construct() "); 79 // qDebug("KOTodoViewItem::construct() ");
80 m_init = true; 80 m_init = true;
81 QString keyd = "=="; 81 QString keyd = "==";
82 QString keyt = "=="; 82 QString keyt = "==";
83 QString skeyd = "=="; 83 QString skeyd = "==";
84 QString skeyt = "=="; 84 QString skeyt = "==";
85 85
86 setOn(mTodo->isCompleted()); 86 setOn(mTodo->isCompleted());
87 setText(0,mTodo->summary()); 87 setText(0,mTodo->summary());
88 setText(1,QString::number(mTodo->priority())); 88 setText(1,QString::number(mTodo->priority()));
89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 89 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
90 if (mTodo->percentComplete()<100) { 90 if (mTodo->percentComplete()<100) {
91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 91 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
92 else setSortKey(2,QString::number(mTodo->percentComplete())); 92 else setSortKey(2,QString::number(mTodo->percentComplete()));
93 } 93 }
94 else { 94 else {
95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 95 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
96 else setSortKey(2,QString::number(99)); 96 else setSortKey(2,QString::number(99));
97 } 97 }
98 if (mTodo->hasDueDate()) { 98 if (mTodo->hasDueDate()) {
99 setText(3, mTodo->dtDueDateStr()); 99 setText(3, mTodo->dtDueDateStr());
100 QDate d = mTodo->dtDue().date(); 100 QDate d = mTodo->dtDue().date();
101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 101 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
102 // setSortKey(3,keyd); 102 // setSortKey(3,keyd);
103 if (mTodo->doesFloat()) { 103 if (mTodo->doesFloat()) {
104 setText(4,""); 104 setText(4,"");
105 } 105 }
106 else { 106 else {
107 setText(4,mTodo->dtDueTimeStr()); 107 setText(4,mTodo->dtDueTimeStr());
108 QTime t = mTodo->dtDue().time(); 108 QTime t = mTodo->dtDue().time();
109 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 109 keyt.sprintf("%02d%02d",t.hour(),t.minute());
110 //setSortKey(4,keyt); 110 //setSortKey(4,keyt);
111 } 111 }
112 } else { 112 } else {
113 setText(3,""); 113 setText(3,"");
114 setText(4,""); 114 setText(4,"");
115 } 115 }
116 setSortKey(3,keyd); 116 setSortKey(3,keyd);
117 setSortKey(4,keyt); 117 setSortKey(4,keyt);
118 118
119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 119 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 120 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
121 121
122
123
124 keyd = ""; 122 keyd = "";
125 keyt = ""; 123 keyt = "";
126 124
127 if (mTodo->isRunning() ) { 125 if (mTodo->isRunning() ) {
128 QDate d = mTodo->runStart().date(); 126 QDate d = mTodo->runStart().date();
129 QTime t = mTodo->runStart().time(); 127 QTime t = mTodo->runStart().time();
130 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 128 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
131 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 129 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
132 keyd = KGlobal::locale()->formatDate( d , true); 130 keyd = KGlobal::locale()->formatDate( d , true);
133 keyt = KGlobal::locale()->formatTime( t ); 131 keyt = KGlobal::locale()->formatTime( t );
134 132
135 } else { 133 } else {
136 134
137 if (mTodo->hasStartDate()) { 135 if (mTodo->hasStartDate()) {
138 keyd = mTodo->dtStartDateStr(); 136 keyd = mTodo->dtStartDateStr();
139 QDate d = mTodo->dtStart().date(); 137 QDate d = mTodo->dtStart().date();
140 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 138 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
141 139
142 if ( !mTodo->doesFloat()) { 140 if ( !mTodo->doesFloat()) {
143 keyt = mTodo->dtStartTimeStr(); 141 keyt = mTodo->dtStartTimeStr();
144 QTime t = mTodo->dtStart().time(); 142 QTime t = mTodo->dtStart().time();
145 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 143 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
146 144
147 } 145 }
148 146
149 } 147 }
150 } 148 }
151 setText(5,keyd); 149 setText(5,keyd);
152 setText(6,keyt); 150 setText(6,keyt);
153 setSortKey(5,skeyd); 151 setSortKey(5,skeyd);
154 setSortKey(6,skeyt); 152 setSortKey(6,skeyt);
155 153
156 //setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 154 //setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
157 setText(7,mTodo->categoriesStr()); 155 setText(7,mTodo->categoriesStr());
158 setText(8,KOPrefs::instance()->calName( mTodo->calID())); 156 setText(8,KOPrefs::instance()->calName( mTodo->calID()));
159 setText(9, KGlobal::locale()->formatDateTime( mTodo->lastModified(), true, true )); 157 setText(9, KGlobal::locale()->formatDateTime( mTodo->lastModified(), true, true ));
160 setText(10, KGlobal::locale()->formatDateTime( mTodo->created(), true, true )); 158 setText(10, KGlobal::locale()->formatDateTime( mTodo->created(), true, true ));
161 setText(11, KGlobal::locale()->formatDateTime( mTodo->lastModifiedSub(), true, true )); 159 setText(11, KGlobal::locale()->formatDateTime( mTodo->lastModifiedSub(), true, true ));
162 QString key; 160 QString key;
163 QDate d = mTodo->lastModified().date(); 161 QDate d;
164 QTime t = mTodo->lastModified().time(); 162 QTime t;
165 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() ); 163 setSortKey(9,mTodo->lastModifiedSortKey());
166 setSortKey(9,key);
167 d = mTodo->created().date(); 164 d = mTodo->created().date();
168 t = mTodo->created().time(); 165 t = mTodo->created().time();
169 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() ); 166 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() );
170 setSortKey(10,key); 167 setSortKey(10,key);
171 d = mTodo->lastModifiedSub().date(); 168 setSortKey(11,mTodo->lastModifiedSubSortKey());
172 t = mTodo->lastModifiedSub().time();
173 key.sprintf("%04d%02d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute(),t.second() );
174 setSortKey(11,key);
175 169
176#if 0 170#if 0
177 // Find sort id in description. It's the text behind the last '#' character 171 // Find sort id in description. It's the text behind the last '#' character
178 // found in the description. White spaces are removed from beginning and end 172 // found in the description. White spaces are removed from beginning and end
179 // of sort id. 173 // of sort id.
180 int pos = mTodo->description().findRev('#'); 174 int pos = mTodo->description().findRev('#');
181 if (pos < 0) { 175 if (pos < 0) {
182 setText(6,""); 176 setText(6,"");
183 } else { 177 } else {
184 QString str = mTodo->description().mid(pos+1); 178 QString str = mTodo->description().mid(pos+1);
185 str.stripWhiteSpace(); 179 str.stripWhiteSpace();
186 setText(6,str); 180 setText(6,str);
187 } 181 }
188#endif 182#endif
189 183
190 m_known = false; 184 m_known = false;
191 m_init = false; 185 m_init = false;
192 186
193 setMyPixmap(); 187 setMyPixmap();
194 188
195} 189}
196void KOTodoViewItem::setMyPixmap() 190void KOTodoViewItem::setMyPixmap()
197{ 191{
198 int size = 5; 192 int size = 5;
199 QPixmap pixi = QPixmap( 1, 1 ); 193 QPixmap pixi = QPixmap( 1, 1 );
200 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 194 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
201// pixi = SmallIcon("redcross16"); 195// pixi = SmallIcon("redcross16");
202// } else { 196// } else {
203 QPainter p; 197 QPainter p;
204 198
205 int pixSize = 0; 199 int pixSize = 0;
206 QPixmap pPix = QPixmap( size, size ); 200 QPixmap pPix = QPixmap( size, size );
207 if ( mTodo->description().length() > 0 ) { 201 if ( mTodo->description().length() > 0 ) {
208 pixi.resize(size, pixSize+size); 202 pixi.resize(size, pixSize+size);
209 pPix.fill( Qt::darkGreen ); 203 pPix.fill( Qt::darkGreen );
210 p.begin( &pixi ); 204 p.begin( &pixi );
211 p. drawPixmap ( 0, pixSize, pPix); 205 p. drawPixmap ( 0, pixSize, pPix);
212 p.end(); 206 p.end();
213 pixSize += size; 207 pixSize += size;
214 } 208 }
215 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) { 209 if ( mTodo->isAlarmEnabled() && mTodo->alarmEnabled()) {
216 pixi.resize(size, pixSize+size); 210 pixi.resize(size, pixSize+size);
217 pPix.fill( Qt::red ); 211 pPix.fill( Qt::red );
218 p.begin( &pixi ); 212 p.begin( &pixi );
219 p. drawPixmap ( 0, pixSize, pPix); 213 p. drawPixmap ( 0, pixSize, pPix);
220 p.end(); 214 p.end();
221 pixSize += size; 215 pixSize += size;
222 } 216 }
223 if ( mTodo->doesRecur() ) { 217 if ( mTodo->doesRecur() ) {
224 pixi.resize(size, pixSize+size); 218 pixi.resize(size, pixSize+size);
225 pPix.fill( Qt::blue ); 219 pPix.fill( Qt::blue );
226 p.begin( &pixi ); 220 p.begin( &pixi );
227 p. drawPixmap ( 0, pixSize, pPix); 221 p. drawPixmap ( 0, pixSize, pPix);
228 p.end(); 222 p.end();
229 pixSize += size; 223 pixSize += size;
230 } 224 }
231 // } 225 // }
232 if ( pixi.width() > 1 ) { 226 if ( pixi.width() > 1 ) {
233 setPixmap ( 0,pixi ) ; 227 setPixmap ( 0,pixi ) ;
234 } else { 228 } else {
235 setPixmap ( 0,QPixmap() ) ; 229 setPixmap ( 0,QPixmap() ) ;
236 } 230 }
237} 231}
238void KOTodoViewItem::stateChange(bool state) 232void KOTodoViewItem::stateChange(bool state)
239{ 233{
240 // qDebug("KOTodoViewItem::stateChange %d ", state); 234 // qDebug("KOTodoViewItem::stateChange %d ", state);
241 // do not change setting on startup 235 // do not change setting on startup
242 if ( m_init ) return; 236 if ( m_init ) return;
243 if (isOn()!=state) { 237 if (isOn()!=state) {
244 setOn(state); 238 setOn(state);
245 //qDebug("SETON "); 239 //qDebug("SETON ");
246 return; 240 return;
247 } 241 }
248 if ( mTodo->isCompleted() == state ) { 242 if ( mTodo->isCompleted() == state ) {
249 //qDebug("STATECHANGE:nothing to do "); 243 //qDebug("STATECHANGE:nothing to do ");
250 return; 244 return;
251 } 245 }
252 QString keyd = "=="; 246 QString keyd = "==";
253 QString keyt = "=="; 247 QString keyt = "==";
254 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); 248 //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1());
255 if ( mTodo->doesRecur() ){ 249 if ( mTodo->doesRecur() ){
256 QDateTime start = mTodo->dtStart(); 250 QDateTime start = mTodo->dtStart();
257 mTodo->setCompleted(state); 251 mTodo->setCompleted(state);
258 if ( start != mTodo->dtStart() ) { 252 if ( start != mTodo->dtStart() ) {
259 if ( state && !mTodo->isCompleted() ) { 253 if ( state && !mTodo->isCompleted() ) {
260 setOn( false ); 254 setOn( false );
261 state = false; 255 state = false;
262 } 256 }
263 } 257 }
264 } else 258 } else
265 mTodo->setCompleted(state); 259 mTodo->setCompleted(state);
266 260
267 if (state) mTodo->setCompleted(QDateTime::currentDateTime()); 261 if (state) mTodo->setCompleted(QDateTime::currentDateTime());
268 262
269 if (mTodo->hasDueDate()) { 263 if (mTodo->hasDueDate()) {
270 setText(3, mTodo->dtDueDateStr()); 264 setText(3, mTodo->dtDueDateStr());
271 QDate d = mTodo->dtDue().date(); 265 QDate d = mTodo->dtDue().date();
272 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 266 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
273 setSortKey(3,keyd); 267 setSortKey(3,keyd);
274 if (mTodo->doesFloat()) { 268 if (mTodo->doesFloat()) {
275 setText(4,""); 269 setText(4,"");
276 } 270 }
277 else { 271 else {
278 setText(4,mTodo->dtDueTimeStr()); 272 setText(4,mTodo->dtDueTimeStr());
279 QTime t = mTodo->dtDue().time(); 273 QTime t = mTodo->dtDue().time();
280 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 274 keyt.sprintf("%02d%02d",t.hour(),t.minute());
281 setSortKey(4,keyt); 275 setSortKey(4,keyt);
282 } 276 }
283 } 277 }
284 if (mTodo->hasStartDate()) { 278 if (mTodo->hasStartDate()) {
285 QString skeyt = "=="; 279 QString skeyt = "==";
286 QString skeyd = "=="; 280 QString skeyd = "==";
287 setText(5, mTodo->dtStartDateStr()); 281 setText(5, mTodo->dtStartDateStr());
288 QDate d = mTodo->dtStart().date(); 282 QDate d = mTodo->dtStart().date();
289 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 283 skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
290 284
291 if (mTodo->doesFloat()) { 285 if (mTodo->doesFloat()) {
292 setText(6,""); 286 setText(6,"");
293 } 287 }
294 else { 288 else {
295 setText(6,mTodo->dtStartTimeStr()); 289 setText(6,mTodo->dtStartTimeStr());
296 QTime t = mTodo->dtStart().time(); 290 QTime t = mTodo->dtStart().time();
297 skeyt.sprintf("%02d%02d",t.hour(),t.minute()); 291 skeyt.sprintf("%02d%02d",t.hour(),t.minute());
298 292
299 } 293 }
300 setSortKey(5,skeyd); 294 setSortKey(5,skeyd);
301 setSortKey(6,skeyt); 295 setSortKey(6,skeyt);
302 } 296 }
303 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 297 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
304 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 298 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
305 299
306 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 300 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
307 if (mTodo->percentComplete()<100) { 301 if (mTodo->percentComplete()<100) {
308 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 302 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
309 else setSortKey(2,QString::number(mTodo->percentComplete())); 303 else setSortKey(2,QString::number(mTodo->percentComplete()));
310 } 304 }
311 else { 305 else {
312 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 306 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
313 else setSortKey(2,QString::number(99)); 307 else setSortKey(2,QString::number(99));
314 } 308 }
315 if ( state ) { 309 if ( state ) {
316 QListViewItem * myChild = firstChild(); 310 QListViewItem * myChild = firstChild();
317 KOTodoViewItem *item; 311 KOTodoViewItem *item;
318 while( myChild ) { 312 while( myChild ) {
319 //qDebug("stateCH "); 313 //qDebug("stateCH ");
320 item = static_cast<KOTodoViewItem*>(myChild); 314 item = static_cast<KOTodoViewItem*>(myChild);
321 item->stateChange(state); 315 item->stateChange(state);
322 myChild = myChild->nextSibling(); 316 myChild = myChild->nextSibling();
323 } 317 }
324 } else { 318 } else {
325 QListViewItem * myChild = parent(); 319 QListViewItem * myChild = parent();
326 if ( myChild ) 320 if ( myChild )
327 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); 321 (static_cast<KOTodoViewItem*>(myChild))->stateChange(state);
328 } 322 }
329 mTodoView->modified(true); 323 mTodoView->modified(true);
330 setMyPixmap(); 324 setMyPixmap();
331 mTodoView->setTodoModified( mTodo ); 325 mTodoView->setTodoModified( mTodo );
332} 326}
333 327
334bool KOTodoViewItem::isAlternate() 328bool KOTodoViewItem::isAlternate()
335{ 329{
336#if 0 330#if 0
337 //if ( m_known ) return m_odd; 331 //if ( m_known ) return m_odd;
338 //qDebug("test "); 332 //qDebug("test ");
339 KOTodoViewItem *item = static_cast<KOTodoViewItem *>(itemAbove()); 333 KOTodoViewItem *item = static_cast<KOTodoViewItem *>(itemAbove());
340 if ( item ) { 334 if ( item ) {
341 m_known = item->m_known; 335 m_known = item->m_known;
342 if ( m_known ) { 336 if ( m_known ) {
343 m_odd = !item->m_odd ; 337 m_odd = !item->m_odd ;
344 return m_odd; 338 return m_odd;
345 } 339 }
346 } else { 340 } else {
347 item = static_cast<KOTodoViewItem *>(itemBelow()); 341 item = static_cast<KOTodoViewItem *>(itemBelow());
348 if ( item ) { 342 if ( item ) {
349 m_known = item->m_known; 343 m_known = item->m_known;
350 if ( m_known ) { 344 if ( m_known ) {
351 m_odd = !item->m_odd ; 345 m_odd = !item->m_odd ;
352 return m_odd; 346 return m_odd;
353 } 347 }
354 } 348 }
355 } 349 }
356 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 350 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
357 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 351 item = static_cast<KOTodoViewItem *>(lv->firstChild());
358 bool previous = true; 352 bool previous = true;
359 qDebug("WHILE "); 353 qDebug("WHILE ");
360 while ( item ) { 354 while ( item ) {
361 item->m_odd = !previous; 355 item->m_odd = !previous;
362 item->m_known = true; 356 item->m_known = true;
363 previous = !previous; 357 previous = !previous;
364 item = static_cast<KOTodoViewItem *>(item->itemBelow()); 358 item = static_cast<KOTodoViewItem *>(item->itemBelow());
365 } 359 }
366 return m_odd; 360 return m_odd;
367 361
368#else 362#else
369 363
370 //KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 364 //KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
371 //if (lv && lv->alternateBackground().isValid()) 365 //if (lv && lv->alternateBackground().isValid())
372 { 366 {
373 KOTodoViewItem *above = static_cast<KOTodoViewItem *>(itemAbove()); 367 KOTodoViewItem *above = static_cast<KOTodoViewItem *>(itemAbove());
374 m_known = above ? above->m_known : true; 368 m_known = above ? above->m_known : true;
375 if (m_known) 369 if (m_known)
376 { 370 {
377 m_odd = above ? !above->m_odd : false; 371 m_odd = above ? !above->m_odd : false;
378 } 372 }
379 else 373 else
380 { 374 {
381 KOTodoViewItem *item; 375 KOTodoViewItem *item;
382 bool previous = true; 376 bool previous = true;
383 if (QListViewItem::parent()) 377 if (QListViewItem::parent())
384 { 378 {
385 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); 379 item = static_cast<KOTodoViewItem *>(QListViewItem::parent());
386 if (item) 380 if (item)
387 previous = item->m_odd; 381 previous = item->m_odd;
388 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 382 item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
389 } 383 }
390 else 384 else
391 { 385 {
392 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 386 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
393 item = static_cast<KOTodoViewItem *>(lv->firstChild()); 387 item = static_cast<KOTodoViewItem *>(lv->firstChild());
394 } 388 }
395 389
396 while(item) 390 while(item)
397 { 391 {
398 item->m_odd = previous = !previous; 392 item->m_odd = previous = !previous;
399 item->m_known = true; 393 item->m_known = true;
400 item = static_cast<KOTodoViewItem *>(item->nextSibling()); 394 item = static_cast<KOTodoViewItem *>(item->nextSibling());
401 } 395 }
402 } 396 }
403 return m_odd; 397 return m_odd;
404 } 398 }
405 return false; 399 return false;
406#endif 400#endif
407} 401}
408 402
409void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 403void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
410{ 404{
411 QColorGroup _cg = cg; 405 QColorGroup _cg = cg;
412 QColorGroup::ColorRole role; 406 QColorGroup::ColorRole role;
413 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor && !mTodo->isRunning()) 407 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor && !mTodo->isRunning())
414 role = QColorGroup::Text; 408 role = QColorGroup::Text;
415 else 409 else
416 role = QColorGroup::Base; 410 role = QColorGroup::Base;
417 //#ifndef KORG_NOLVALTERNATION 411 //#ifndef KORG_NOLVALTERNATION
418 if (isAlternate()) 412 if (isAlternate())
419 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 413 _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
420 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 414 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
421 QColor colorToSet; 415 QColor colorToSet;
422 if ( column == 0 && mTodo->calID() > 1 ) { 416 if ( column == 0 && mTodo->calID() > 1 ) {
423 setColor = true; 417 setColor = true;
424 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() ); 418 colorToSet = KOPrefs::instance()->defaultColor( mTodo->calID() );
425 } else if ( setColor ) { 419 } else if ( setColor ) {
426 QStringList categories = mTodo->categories(); 420 QStringList categories = mTodo->categories();
427 QString cat = categories.first(); 421 QString cat = categories.first();
428 if ( !cat.isEmpty()) { 422 if ( !cat.isEmpty()) {
429 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 423 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
430 } else 424 } else
431 setColor = false; 425 setColor = false;
432 } 426 }
433 bool openMode = !isOpen(); 427 bool openMode = !isOpen();
434 // maybe we are in flat-display-mode 428 // maybe we are in flat-display-mode
435 if ( !firstChild() ) 429 if ( !firstChild() )
436 openMode = false; 430 openMode = false;
437 bool colorRunning = mTodo->isRunning(); 431 bool colorRunning = mTodo->isRunning();
438 if ( ! colorRunning && openMode ) 432 if ( ! colorRunning && openMode )
439 colorRunning = mTodo->hasRunningSub(); 433 colorRunning = mTodo->hasRunningSub();
440 if ( colorRunning ) { 434 if ( colorRunning ) {
441 setColor = true; 435 setColor = true;
442 colorToSet = KOPrefs::instance()->mTodoRunColor; 436 colorToSet = KOPrefs::instance()->mTodoRunColor;
443 } else { 437 } else {
444 int odue = mTodo->hasDueSubTodo( openMode ); 438 int odue = mTodo->hasDueSubTodo( openMode );
445 if (odue == 2) { 439 if (odue == 2) {
446 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 440 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
447 setColor = true; 441 setColor = true;
448 } else if ( odue == 1 ) { 442 } else if ( odue == 1 ) {
449 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 443 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
450 setColor = true; 444 setColor = true;
451 } 445 }
452 } 446 }
453 447
454 448
455 if ( setColor ) { 449 if ( setColor ) {
456 _cg.setColor(role,colorToSet ); 450 _cg.setColor(role,colorToSet );
457 if ( role == QColorGroup::Base) { 451 if ( role == QColorGroup::Base) {
458 int rgb = colorToSet.red(); 452 int rgb = colorToSet.red();
459 rgb += colorToSet.blue()/2; 453 rgb += colorToSet.blue()/2;
460 rgb += colorToSet.green(); 454 rgb += colorToSet.green();
461 if ( rgb < 200 ) 455 if ( rgb < 200 )
462 _cg.setColor(QColorGroup::Text,Qt::white ); 456 _cg.setColor(QColorGroup::Text,Qt::white );
463 } 457 }
464 } 458 }
465 //#endif 459 //#endif
466 if ( column > 0 ){ 460 if ( column > 0 ){
467 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 461 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
468 p->save(); 462 p->save();
469 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 463 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
470 464
471 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 465 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
472 // p->setPen(Qt::black ); //border 466 // p->setPen(Qt::black ); //border
473 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 467 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
474 QColor fc = KOPrefs::instance()->mHighlightColor; 468 QColor fc = KOPrefs::instance()->mHighlightColor;
475 if ( mTodo->percentComplete() == 100 ) 469 if ( mTodo->percentComplete() == 100 )
476 fc = darkGreen; 470 fc = darkGreen;
477 p->drawRect( 2, 2, width-4, height()-4); 471 p->drawRect( 2, 2, width-4, height()-4);
478 p->fillRect( 3, 3, progress, height()-6, 472 p->fillRect( 3, 3, progress, height()-6,
479 fc ); 473 fc );
480 p->restore(); 474 p->restore();
481 } else { 475 } else {
482 QCheckListItem::paintCell(p, _cg, column, width, alignment); 476 QCheckListItem::paintCell(p, _cg, column, width, alignment);
483 } 477 }
484 return; 478 return;
485 } 479 }
486 480
487 int align = alignment; 481 int align = alignment;
488 482
489 if ( !p ) 483 if ( !p )
490 return; 484 return;
491 485
492 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 486 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
493 487
494 QListView *lv = listView(); 488 QListView *lv = listView();
495 if ( !lv ) 489 if ( !lv )
496 return; 490 return;
497 int marg = 2;//lv->itemMargin(); 491 int marg = 2;//lv->itemMargin();
498 int r = 0; 492 int r = 0;
499 QCheckListItem::Type myType = QCheckListItem::CheckBox; 493 QCheckListItem::Type myType = QCheckListItem::CheckBox;
500 int BoxSize = 20; 494 int BoxSize = 20;
501 int boxOffset = 2; 495 int boxOffset = 2;
502 int xOffset = 2; 496 int xOffset = 2;
503 if (qApp->desktop()->width() < 300 ) { 497 if (qApp->desktop()->width() < 300 ) {
504 BoxSize = 14; 498 BoxSize = 14;
505 boxOffset = -1; 499 boxOffset = -1;
506 xOffset = 1; 500 xOffset = 1;
507 // marg = 0; 501 // marg = 0;
508 } 502 }
509 if ( height() < BoxSize ) { 503 if ( height() < BoxSize ) {
510 boxOffset = boxOffset - ((BoxSize - height())/2) ; 504 boxOffset = boxOffset - ((BoxSize - height())/2) ;
511 // qDebug("boxOffset %d height %d", boxOffset, height() ); 505 // qDebug("boxOffset %d height %d", boxOffset, height() );
512 BoxSize = height(); 506 BoxSize = height();
513 507
514 } 508 }
515 //bool winStyle = lv->style() == WindowsStyle; 509 //bool winStyle = lv->style() == WindowsStyle;
516 510
517 int lineStart = 5; 511 int lineStart = 5;
518 if ( myType == Controller ) { 512 if ( myType == Controller ) {
519 if ( !pixmap( 0 ) ) 513 if ( !pixmap( 0 ) )
520 r += BoxSize + 4; 514 r += BoxSize + 4;
521 } else { 515 } else {
522 ASSERT( lv ); //### 516 ASSERT( lv ); //###
523 //QFontMetrics fm( lv->font() ); 517 //QFontMetrics fm( lv->font() );
524 //int d = fm.height(); 518 //int d = fm.height();
525 int x = 0; 519 int x = 0;
526 int y = (height() - BoxSize) / 2; 520 int y = (height() - BoxSize) / 2;
527 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 521 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
528 if ( myType == CheckBox ) { 522 if ( myType == CheckBox ) {
529 if ( isEnabled() ) 523 if ( isEnabled() )
530 p->setPen( QPen( _cg.text(), 1 ) ); 524 p->setPen( QPen( _cg.text(), 1 ) );
531 else 525 else
532 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 526 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
533 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 527 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
534 lineStart = x+marg; 528 lineStart = x+marg;
535 ///////////////////// 529 /////////////////////
536 x++; 530 x++;
537 y++; 531 y++;
538 if ( isOn() ) { 532 if ( isOn() ) {
539 QPointArray a( 7*2 ); 533 QPointArray a( 7*2 );
540 int i, xx, yy; 534 int i, xx, yy;
541 xx = x+xOffset+marg+(boxOffset/2); 535 xx = x+xOffset+marg+(boxOffset/2);
542 yy = y+5+boxOffset; 536 yy = y+5+boxOffset;
543 for ( i=0; i<3; i++ ) { 537 for ( i=0; i<3; i++ ) {
544 a.setPoint( 2*i, xx, yy ); 538 a.setPoint( 2*i, xx, yy );
545 a.setPoint( 2*i+1, xx, yy+2 ); 539 a.setPoint( 2*i+1, xx, yy+2 );
546 // qDebug(" "); 540 // qDebug(" ");
547 xx++; yy++; 541 xx++; yy++;
548 } 542 }
549 yy -= 2; 543 yy -= 2;
550 for ( i=3; i<7; i++ ) { 544 for ( i=3; i<7; i++ ) {
551 a.setPoint( 2*i, xx, yy ); 545 a.setPoint( 2*i, xx, yy );
552 a.setPoint( 2*i+1, xx, yy+2 ); 546 a.setPoint( 2*i+1, xx, yy+2 );
553 xx++; yy--; 547 xx++; yy--;
554 } 548 }
555 p->setPen( darkGreen ); 549 p->setPen( darkGreen );
556 p->drawLineSegments( a ); 550 p->drawLineSegments( a );
557 } 551 }
558 //////////////////////// 552 ////////////////////////
559 } 553 }
560 r += BoxSize + 4; 554 r += BoxSize + 4;
561 } 555 }
562 556
563 p->translate( r, 0 ); 557 p->translate( r, 0 );
564 p->setPen( QPen( _cg.text() ) ); 558 p->setPen( QPen( _cg.text() ) );
565 QListViewItem::paintCell( p, _cg, column, width - r, align ); 559 QListViewItem::paintCell( p, _cg, column, width - r, align );
566 if ( mTodo->cancelled () ) { 560 if ( mTodo->cancelled () ) {
567 p->setPen( black ); 561 p->setPen( black );
568 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 562 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
569 int wid = br.width() +lineStart; 563 int wid = br.width() +lineStart;
570 if ( wid > width-3 ) 564 if ( wid > width-3 )
571 wid = width-3; 565 wid = width-3;
572 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); 566 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
573 567
574 } 568 }
575 569
576} 570}
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 39c14f5..fe9f854 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,853 +1,866 @@
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 <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = 0;//new Recurrence(this); 36 mRecurrence = 0;//new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false; 42 mHasRecurrenceID = false;
43 mHoliday = false; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 QPtrListIterator<Attachment> itat( i.mAttachments ); 62 QPtrListIterator<Attachment> itat( i.mAttachments );
63 Attachment *at; 63 Attachment *at;
64 while( (at = itat.current()) ) { 64 while( (at = itat.current()) ) {
65 Attachment *a = new Attachment( *at ); 65 Attachment *a = new Attachment( *at );
66 mAttachments.append( a ); 66 mAttachments.append( a );
67 ++itat; 67 ++itat;
68 } 68 }
69 mAttachments.setAutoDelete( true ); 69 mAttachments.setAutoDelete( true );
70 mResources = i.mResources; 70 mResources = i.mResources;
71 mSecrecy = i.mSecrecy; 71 mSecrecy = i.mSecrecy;
72 mPriority = i.mPriority; 72 mPriority = i.mPriority;
73 mLocation = i.mLocation; 73 mLocation = i.mLocation;
74 mCancelled = i.mCancelled; 74 mCancelled = i.mCancelled;
75 mHasStartDate = i.mHasStartDate; 75 mHasStartDate = i.mHasStartDate;
76 QPtrListIterator<Alarm> it( i.mAlarms ); 76 QPtrListIterator<Alarm> it( i.mAlarms );
77 const Alarm *a; 77 const Alarm *a;
78 while( (a = it.current()) ) { 78 while( (a = it.current()) ) {
79 Alarm *b = new Alarm( *a ); 79 Alarm *b = new Alarm( *a );
80 b->setParent( this ); 80 b->setParent( this );
81 mAlarms.append( b ); 81 mAlarms.append( b );
82 82
83 ++it; 83 ++it;
84 } 84 }
85 mAlarms.setAutoDelete(true); 85 mAlarms.setAutoDelete(true);
86 mHasRecurrenceID = i.mHasRecurrenceID; 86 mHasRecurrenceID = i.mHasRecurrenceID;
87 mRecurrenceID = i.mRecurrenceID; 87 mRecurrenceID = i.mRecurrenceID;
88 if ( i.mRecurrence ) 88 if ( i.mRecurrence )
89 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 89 mRecurrence = new Recurrence( *(i.mRecurrence), this );
90 else 90 else
91 mRecurrence = 0; 91 mRecurrence = 0;
92 mHoliday = i.mHoliday ; 92 mHoliday = i.mHoliday ;
93 mBirthday = i.mBirthday; 93 mBirthday = i.mBirthday;
94 mAnniversary = i.mAnniversary; 94 mAnniversary = i.mAnniversary;
95} 95}
96 96
97Incidence::~Incidence() 97Incidence::~Incidence()
98{ 98{
99 99
100 Incidence *ev; 100 Incidence *ev;
101 QPtrList<Incidence> Relations = relations(); 101 QPtrList<Incidence> Relations = relations();
102 for (ev=Relations.first();ev;ev=Relations.next()) { 102 for (ev=Relations.first();ev;ev=Relations.next()) {
103 if (ev->relatedTo() == this) ev->setRelatedTo(0); 103 if (ev->relatedTo() == this) ev->setRelatedTo(0);
104 } 104 }
105 if (relatedTo()) relatedTo()->removeRelation(this); 105 if (relatedTo()) relatedTo()->removeRelation(this);
106 if ( mRecurrence ) 106 if ( mRecurrence )
107 delete mRecurrence; 107 delete mRecurrence;
108 108
109} 109}
110QString Incidence::durationText() 110QString Incidence::durationText()
111{ 111{
112 return "---"; 112 return "---";
113} 113}
114QString Incidence::durationText4Time( int offset ) 114QString Incidence::durationText4Time( int offset )
115{ 115{
116 int min = offset/60; 116 int min = offset/60;
117 int hours = min /60; 117 int hours = min /60;
118 min = min % 60; 118 min = min % 60;
119 int days = hours /24; 119 int days = hours /24;
120 hours = hours % 24; 120 hours = hours % 24;
121 121
122 if ( doesFloat() || ( min == 0 && hours == 0 ) ) { 122 if ( doesFloat() || ( min == 0 && hours == 0 ) ) {
123 if ( days == 1 ) 123 if ( days == 1 )
124 return "1" + i18n(" day"); 124 return "1" + i18n(" day");
125 else 125 else
126 return QString::number( days )+ i18n(" days"); 126 return QString::number( days )+ i18n(" days");
127 127
128 } 128 }
129 QString message = QString::number ( hours ) +":"; 129 QString message = QString::number ( hours ) +":";
130 if ( min < 10 ) message += "0"; 130 if ( min < 10 ) message += "0";
131 message += QString::number ( min ); 131 message += QString::number ( min );
132 if ( days > 0 ) { 132 if ( days > 0 ) {
133 if ( days == 1 ) 133 if ( days == 1 )
134 message = "1" + i18n(" day") + " "+message; 134 message = "1" + i18n(" day") + " "+message;
135 else 135 else
136 message = QString::number( days )+ i18n(" days") + " "+message; 136 message = QString::number( days )+ i18n(" days") + " "+message;
137 } 137 }
138 return message; 138 return message;
139} 139}
140bool Incidence::isHoliday() const 140bool Incidence::isHoliday() const
141{ 141{
142 return mHoliday; 142 return mHoliday;
143} 143}
144bool Incidence::isBirthday() const 144bool Incidence::isBirthday() const
145{ 145{
146 146
147 return mBirthday ; 147 return mBirthday ;
148} 148}
149bool Incidence::isAnniversary() const 149bool Incidence::isAnniversary() const
150{ 150{
151 return mAnniversary ; 151 return mAnniversary ;
152 152
153} 153}
154 154
155bool Incidence::hasRecurrenceID() const 155bool Incidence::hasRecurrenceID() const
156{ 156{
157 return mHasRecurrenceID; 157 return mHasRecurrenceID;
158} 158}
159 159
160void Incidence::setHasRecurrenceID( bool b ) 160void Incidence::setHasRecurrenceID( bool b )
161{ 161{
162 mHasRecurrenceID = b; 162 mHasRecurrenceID = b;
163} 163}
164 164
165void Incidence::setRecurrenceID(QDateTime d) 165void Incidence::setRecurrenceID(QDateTime d)
166{ 166{
167 mRecurrenceID = d; 167 mRecurrenceID = d;
168 mHasRecurrenceID = true; 168 mHasRecurrenceID = true;
169 updated(); 169 updated();
170} 170}
171QDateTime Incidence::recurrenceID () const 171QDateTime Incidence::recurrenceID () const
172{ 172{
173 return mRecurrenceID; 173 return mRecurrenceID;
174} 174}
175 175
176bool Incidence::cancelled() const 176bool Incidence::cancelled() const
177{ 177{
178 return mCancelled; 178 return mCancelled;
179} 179}
180void Incidence::setCancelled( bool b ) 180void Incidence::setCancelled( bool b )
181{ 181{
182 mCancelled = b; 182 mCancelled = b;
183 updated(); 183 updated();
184} 184}
185bool Incidence::hasStartDate() const 185bool Incidence::hasStartDate() const
186{ 186{
187 return mHasStartDate; 187 return mHasStartDate;
188} 188}
189 189
190void Incidence::setHasStartDate(bool f) 190void Incidence::setHasStartDate(bool f)
191{ 191{
192 if (mReadOnly) return; 192 if (mReadOnly) return;
193 mHasStartDate = f; 193 mHasStartDate = f;
194 updated(); 194 updated();
195} 195}
196 196
197// A string comparison that considers that null and empty are the same 197// A string comparison that considers that null and empty are the same
198static bool stringCompare( const QString& s1, const QString& s2 ) 198static bool stringCompare( const QString& s1, const QString& s2 )
199{ 199{
200 if ( s1.isEmpty() && s2.isEmpty() ) 200 if ( s1.isEmpty() && s2.isEmpty() )
201 return true; 201 return true;
202 return s1 == s2; 202 return s1 == s2;
203} 203}
204 204
205bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 205bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
206{ 206{
207 207
208 if( i1.alarms().count() != i2.alarms().count() ) { 208 if( i1.alarms().count() != i2.alarms().count() ) {
209 return false; // no need to check further 209 return false; // no need to check further
210 } 210 }
211 if ( i1.alarms().count() > 0 ) { 211 if ( i1.alarms().count() > 0 ) {
212 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 212 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
213 { 213 {
214 qDebug("alarm not equal "); 214 qDebug("alarm not equal ");
215 return false; 215 return false;
216 } 216 }
217 } 217 }
218#if 0 218#if 0
219 QPtrListIterator<Alarm> a1( i1.alarms() ); 219 QPtrListIterator<Alarm> a1( i1.alarms() );
220 QPtrListIterator<Alarm> a2( i2.alarms() ); 220 QPtrListIterator<Alarm> a2( i2.alarms() );
221 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 221 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
222 if( *a1.current() == *a2.current() ) { 222 if( *a1.current() == *a2.current() ) {
223 continue; 223 continue;
224 } 224 }
225 else { 225 else {
226 return false; 226 return false;
227 } 227 }
228 } 228 }
229#endif 229#endif
230 230
231 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 231 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
232 if ( i1.hasRecurrenceID() ) { 232 if ( i1.hasRecurrenceID() ) {
233 if ( i1.recurrenceID() != i2.recurrenceID() ) 233 if ( i1.recurrenceID() != i2.recurrenceID() )
234 return false; 234 return false;
235 } 235 }
236 236
237 } else { 237 } else {
238 return false; 238 return false;
239 } 239 }
240 240
241 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 241 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
242 return false; 242 return false;
243 if ( i1.hasStartDate() == i2.hasStartDate() ) { 243 if ( i1.hasStartDate() == i2.hasStartDate() ) {
244 if ( i1.hasStartDate() ) { 244 if ( i1.hasStartDate() ) {
245 if ( i1.dtStart() != i2.dtStart() ) 245 if ( i1.dtStart() != i2.dtStart() )
246 return false; 246 return false;
247 } 247 }
248 } else { 248 } else {
249 return false; 249 return false;
250 } 250 }
251 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { 251 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
252 if (!( *i1.mRecurrence == *i2.mRecurrence) ) { 252 if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
253 //qDebug("recurrence is NOT equal "); 253 //qDebug("recurrence is NOT equal ");
254 return false; 254 return false;
255 } 255 }
256 } else { 256 } else {
257 // one ( or both ) recurrence is 0 257 // one ( or both ) recurrence is 0
258 if ( i1.mRecurrence == 0 ) { 258 if ( i1.mRecurrence == 0 ) {
259 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) 259 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
260 return false; 260 return false;
261 } else { 261 } else {
262 // i1.mRecurrence != 0 262 // i1.mRecurrence != 0
263 // i2.mRecurrence == 0 263 // i2.mRecurrence == 0
264 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) 264 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
265 return false; 265 return false;
266 } 266 }
267 } 267 }
268 268
269 return 269 return
270 // i1.created() == i2.created() && 270 // i1.created() == i2.created() &&
271 stringCompare( i1.description(), i2.description() ) && 271 stringCompare( i1.description(), i2.description() ) &&
272 stringCompare( i1.summary(), i2.summary() ) && 272 stringCompare( i1.summary(), i2.summary() ) &&
273 i1.categories() == i2.categories() && 273 i1.categories() == i2.categories() &&
274 // no need to compare mRelatedTo 274 // no need to compare mRelatedTo
275 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 275 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
276 // i1.relations() == i2.relations() && 276 // i1.relations() == i2.relations() &&
277 i1.exDates() == i2.exDates() && 277 i1.exDates() == i2.exDates() &&
278 i1.attachments() == i2.attachments() && 278 i1.attachments() == i2.attachments() &&
279 i1.resources() == i2.resources() && 279 i1.resources() == i2.resources() &&
280 i1.secrecy() == i2.secrecy() && 280 i1.secrecy() == i2.secrecy() &&
281 i1.priority() == i2.priority() && 281 i1.priority() == i2.priority() &&
282 i1.cancelled() == i2.cancelled() && 282 i1.cancelled() == i2.cancelled() &&
283 stringCompare( i1.location(), i2.location() ); 283 stringCompare( i1.location(), i2.location() );
284} 284}
285 285
286Incidence* Incidence::recreateCloneException( QDate d ) 286Incidence* Incidence::recreateCloneException( QDate d )
287{ 287{
288 Incidence* newInc = clone(); 288 Incidence* newInc = clone();
289 newInc->recreate(); 289 newInc->recreate();
290 if ( doesRecur() ) { 290 if ( doesRecur() ) {
291 addExDate( d ); 291 addExDate( d );
292 newInc->recurrence()->unsetRecurs(); 292 newInc->recurrence()->unsetRecurs();
293 if ( typeID() == eventID ) { 293 if ( typeID() == eventID ) {
294 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 294 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
295 QTime tim = dtStart().time(); 295 QTime tim = dtStart().time();
296 newInc->setDtStart( QDateTime(d, tim) ); 296 newInc->setDtStart( QDateTime(d, tim) );
297 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 297 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
298 } else { 298 } else {
299 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 299 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
300 QTime tim = ((Todo*)this)->dtDue().time(); 300 QTime tim = ((Todo*)this)->dtDue().time();
301 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 301 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
302 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 302 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
303 ((Todo*)this)->setRecurDates(); 303 ((Todo*)this)->setRecurDates();
304 } 304 }
305 newInc->setExDates( DateList () ); 305 newInc->setExDates( DateList () );
306 } 306 }
307 return newInc; 307 return newInc;
308} 308}
309 309
310void Incidence::recreate() 310void Incidence::recreate()
311{ 311{
312 setCreated(QDateTime::currentDateTime()); 312 setCreated(QDateTime::currentDateTime());
313 313
314 setUid(CalFormat::createUniqueId()); 314 setUid(CalFormat::createUniqueId());
315 315
316 setRevision(0); 316 setRevision(0);
317 setIDStr( ":" ); 317 setIDStr( ":" );
318 setLastModified(QDateTime::currentDateTime()); 318 setLastModified(QDateTime::currentDateTime());
319} 319}
320void Incidence::cloneRelations( Incidence * newInc ) 320void Incidence::cloneRelations( Incidence * newInc )
321{ 321{
322 // newInc is already a clone of this incidence 322 // newInc is already a clone of this incidence
323 Incidence * inc; 323 Incidence * inc;
324 Incidence * cloneInc; 324 Incidence * cloneInc;
325 QPtrList<Incidence> Relations = relations(); 325 QPtrList<Incidence> Relations = relations();
326 for (inc=Relations.first();inc;inc=Relations.next()) { 326 for (inc=Relations.first();inc;inc=Relations.next()) {
327 cloneInc = inc->clone(); 327 cloneInc = inc->clone();
328 cloneInc->recreate(); 328 cloneInc->recreate();
329 cloneInc->setRelatedTo( newInc ); 329 cloneInc->setRelatedTo( newInc );
330 inc->cloneRelations( cloneInc ); 330 inc->cloneRelations( cloneInc );
331 } 331 }
332} 332}
333void Incidence::setReadOnly( bool readOnly ) 333void Incidence::setReadOnly( bool readOnly )
334{ 334{
335 IncidenceBase::setReadOnly( readOnly ); 335 IncidenceBase::setReadOnly( readOnly );
336 if ( mRecurrence ) 336 if ( mRecurrence )
337 mRecurrence->setRecurReadOnly( readOnly); 337 mRecurrence->setRecurReadOnly( readOnly);
338} 338}
339void Incidence::setLastModifiedSubInvalid() 339void Incidence::setLastModifiedSubInvalid()
340{ 340{
341 mLastModifiedSub = QDateTime(); 341 mLastModifiedSub = QDateTime();
342 if ( mRelatedTo ) 342 if ( mRelatedTo )
343 mRelatedTo->setLastModifiedSubInvalid(); 343 mRelatedTo->setLastModifiedSubInvalid();
344} 344}
345QString Incidence::lastModifiedSubSortKey() const
346{
347 if ( mLastModifiedSubSortKey.isEmpty() )
348 return lastModifiedSortKey();
349 return mLastModifiedSubSortKey;
350}
345QDateTime Incidence::lastModifiedSub() 351QDateTime Incidence::lastModifiedSub()
346{ 352{
347 if ( !mRelations.count() ) 353 if ( !mRelations.count() )
348 return lastModified(); 354 return lastModified();
349 if ( mLastModifiedSub.isValid() ) 355 if ( mLastModifiedSub.isValid() )
350 return mLastModifiedSub; 356 return mLastModifiedSub;
351 mLastModifiedSub = lastModified(); 357 mLastModifiedSub = lastModified();
352 Incidence * inc; 358 Incidence * inc;
353 QPtrList<Incidence> Relations = relations(); 359 QPtrList<Incidence> Relations = relations();
354 for (inc=Relations.first();inc;inc=Relations.next()) { 360 for (inc=Relations.first();inc;inc=Relations.next()) {
355 if ( inc->lastModifiedSub() > mLastModifiedSub ) 361 if ( inc->lastModifiedSub() > mLastModifiedSub )
356 mLastModifiedSub = inc->lastModifiedSub(); 362 mLastModifiedSub = inc->lastModifiedSub();
357 } 363 }
364 mLastModifiedSubSortKey.sprintf("%04d%02d%02d%02d%02d%02d",
365 mLastModifiedSub.date().year(),
366 mLastModifiedSub.date().month(),
367 mLastModifiedSub.date().day(),
368 mLastModifiedSub.time().hour(),
369 mLastModifiedSub.time().minute(),
370 mLastModifiedSub.time().second() );
358 return mLastModifiedSub; 371 return mLastModifiedSub;
359} 372}
360void Incidence::setCreated(QDateTime created) 373void Incidence::setCreated(QDateTime created)
361{ 374{
362 if (mReadOnly) return; 375 if (mReadOnly) return;
363 mCreated = getEvenTime(created); 376 mCreated = getEvenTime(created);
364} 377}
365 378
366QDateTime Incidence::created() const 379QDateTime Incidence::created() const
367{ 380{
368 return mCreated; 381 return mCreated;
369} 382}
370 383
371void Incidence::setRevision(int rev) 384void Incidence::setRevision(int rev)
372{ 385{
373 if (mReadOnly) return; 386 if (mReadOnly) return;
374 mRevision = rev; 387 mRevision = rev;
375 388
376 updated(); 389 updated();
377} 390}
378 391
379int Incidence::revision() const 392int Incidence::revision() const
380{ 393{
381 return mRevision; 394 return mRevision;
382} 395}
383 396
384void Incidence::setDtStart(const QDateTime &dtStart) 397void Incidence::setDtStart(const QDateTime &dtStart)
385{ 398{
386 399
387 QDateTime dt = getEvenTime(dtStart); 400 QDateTime dt = getEvenTime(dtStart);
388 401
389 if ( mRecurrence ) 402 if ( mRecurrence )
390 mRecurrence->setRecurStart( dt); 403 mRecurrence->setRecurStart( dt);
391 IncidenceBase::setDtStart( dt ); 404 IncidenceBase::setDtStart( dt );
392} 405}
393 406
394void Incidence::setDescription(const QString &description) 407void Incidence::setDescription(const QString &description)
395{ 408{
396 if (mReadOnly) return; 409 if (mReadOnly) return;
397 mDescription = description; 410 mDescription = description;
398 updated(); 411 updated();
399} 412}
400 413
401QString Incidence::description() const 414QString Incidence::description() const
402{ 415{
403 return mDescription; 416 return mDescription;
404} 417}
405 418
406 419
407void Incidence::setSummary(const QString &summary) 420void Incidence::setSummary(const QString &summary)
408{ 421{
409 if (mReadOnly) return; 422 if (mReadOnly) return;
410 mSummary = summary; 423 mSummary = summary;
411 updated(); 424 updated();
412} 425}
413 426
414QString Incidence::summary() const 427QString Incidence::summary() const
415{ 428{
416 return mSummary; 429 return mSummary;
417} 430}
418void Incidence::checkCategories() 431void Incidence::checkCategories()
419{ 432{
420 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 433 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
421 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 434 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
422 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 435 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
423} 436}
424 437
425void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 438void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
426{ 439{
427 if (mReadOnly) return; 440 if (mReadOnly) return;
428 int i; 441 int i;
429 for( i = 0; i < categories.count(); ++i ) { 442 for( i = 0; i < categories.count(); ++i ) {
430 if ( !mCategories.contains (categories[i])) 443 if ( !mCategories.contains (categories[i]))
431 mCategories.append( categories[i] ); 444 mCategories.append( categories[i] );
432 } 445 }
433 checkCategories(); 446 checkCategories();
434 updated(); 447 updated();
435 if ( addToRelations ) { 448 if ( addToRelations ) {
436 Incidence * inc; 449 Incidence * inc;
437 QPtrList<Incidence> Relations = relations(); 450 QPtrList<Incidence> Relations = relations();
438 for (inc=Relations.first();inc;inc=Relations.next()) { 451 for (inc=Relations.first();inc;inc=Relations.next()) {
439 inc->addCategories( categories, true ); 452 inc->addCategories( categories, true );
440 } 453 }
441 } 454 }
442} 455}
443 456
444void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 457void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
445{ 458{
446 if (mReadOnly) return; 459 if (mReadOnly) return;
447 mCategories = categories; 460 mCategories = categories;
448 checkCategories(); 461 checkCategories();
449 updated(); 462 updated();
450 if ( setForRelations ) { 463 if ( setForRelations ) {
451 Incidence * inc; 464 Incidence * inc;
452 QPtrList<Incidence> Relations = relations(); 465 QPtrList<Incidence> Relations = relations();
453 for (inc=Relations.first();inc;inc=Relations.next()) { 466 for (inc=Relations.first();inc;inc=Relations.next()) {
454 inc->setCategories( categories, true ); 467 inc->setCategories( categories, true );
455 } 468 }
456 } 469 }
457} 470}
458 471
459// TODO: remove setCategories(QString) function 472// TODO: remove setCategories(QString) function
460void Incidence::setCategories(const QString &catStr) 473void Incidence::setCategories(const QString &catStr)
461{ 474{
462 if (mReadOnly) return; 475 if (mReadOnly) return;
463 mCategories.clear(); 476 mCategories.clear();
464 477
465 if (catStr.isEmpty()) return; 478 if (catStr.isEmpty()) return;
466 479
467 mCategories = QStringList::split(",",catStr); 480 mCategories = QStringList::split(",",catStr);
468 481
469 QStringList::Iterator it; 482 QStringList::Iterator it;
470 for(it = mCategories.begin();it != mCategories.end(); ++it) { 483 for(it = mCategories.begin();it != mCategories.end(); ++it) {
471 *it = (*it).stripWhiteSpace(); 484 *it = (*it).stripWhiteSpace();
472 } 485 }
473 checkCategories(); 486 checkCategories();
474 updated(); 487 updated();
475} 488}
476// using this makes filtering 3 times faster 489// using this makes filtering 3 times faster
477QStringList* Incidence::categoriesP() 490QStringList* Incidence::categoriesP()
478{ 491{
479 return &mCategories; 492 return &mCategories;
480} 493}
481 494
482QStringList Incidence::categories() const 495QStringList Incidence::categories() const
483{ 496{
484 return mCategories; 497 return mCategories;
485} 498}
486 499
487QString Incidence::categoriesStr() 500QString Incidence::categoriesStr()
488{ 501{
489 return mCategories.join(","); 502 return mCategories.join(",");
490} 503}
491QString Incidence::categoriesStrWithSpace() 504QString Incidence::categoriesStrWithSpace()
492{ 505{
493 return mCategories.join(", "); 506 return mCategories.join(", ");
494} 507}
495 508
496void Incidence::setRelatedToUid(const QString &relatedToUid) 509void Incidence::setRelatedToUid(const QString &relatedToUid)
497{ 510{
498 if (mReadOnly) return; 511 if (mReadOnly) return;
499 mRelatedToUid = relatedToUid; 512 mRelatedToUid = relatedToUid;
500} 513}
501void Incidence::clearRelations() 514void Incidence::clearRelations()
502{ 515{
503 mRelatedTo = 0; 516 mRelatedTo = 0;
504 mRelations.clear(); 517 mRelations.clear();
505} 518}
506QString Incidence::relatedToUid() const 519QString Incidence::relatedToUid() const
507{ 520{
508 return mRelatedToUid; 521 return mRelatedToUid;
509} 522}
510 523
511void Incidence::setRelatedTo(Incidence *relatedTo) 524void Incidence::setRelatedTo(Incidence *relatedTo)
512{ 525{
513 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 526 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
514 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 527 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
515 if (mReadOnly || mRelatedTo == relatedTo) return; 528 if (mReadOnly || mRelatedTo == relatedTo) return;
516 if(mRelatedTo) { 529 if(mRelatedTo) {
517 // updated(); 530 // updated();
518 mRelatedTo->removeRelation(this); 531 mRelatedTo->removeRelation(this);
519 } 532 }
520 mRelatedTo = relatedTo; 533 mRelatedTo = relatedTo;
521 if (mRelatedTo) { 534 if (mRelatedTo) {
522 mRelatedTo->addRelation(this); 535 mRelatedTo->addRelation(this);
523 mRelatedToUid = mRelatedTo->uid(); 536 mRelatedToUid = mRelatedTo->uid();
524 } else { 537 } else {
525 mRelatedToUid = ""; 538 mRelatedToUid = "";
526 } 539 }
527} 540}
528 541
529Incidence *Incidence::relatedTo() const 542Incidence *Incidence::relatedTo() const
530{ 543{
531 return mRelatedTo; 544 return mRelatedTo;
532} 545}
533 546
534QPtrList<Incidence> Incidence::relations() const 547QPtrList<Incidence> Incidence::relations() const
535{ 548{
536 return mRelations; 549 return mRelations;
537} 550}
538 551
539void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 552void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
540{ 553{
541 Incidence* inc; 554 Incidence* inc;
542 QPtrList<Incidence> Relations = relations(); 555 QPtrList<Incidence> Relations = relations();
543 for (inc=Relations.first();inc;inc=Relations.next()) { 556 for (inc=Relations.first();inc;inc=Relations.next()) {
544 inc->addRelationsToList( rel ); 557 inc->addRelationsToList( rel );
545 } 558 }
546 if ( rel->findRef( this ) == -1 ) 559 if ( rel->findRef( this ) == -1 )
547 rel->append( this ); 560 rel->append( this );
548} 561}
549 562
550void Incidence::addRelation(Incidence *event) 563void Incidence::addRelation(Incidence *event)
551{ 564{
552 setLastModifiedSubInvalid(); 565 setLastModifiedSubInvalid();
553 if( mRelations.findRef( event ) == -1 ) { 566 if( mRelations.findRef( event ) == -1 ) {
554 mRelations.append(event); 567 mRelations.append(event);
555 //updated(); 568 //updated();
556 } 569 }
557} 570}
558 571
559void Incidence::removeRelation(Incidence *event) 572void Incidence::removeRelation(Incidence *event)
560{ 573{
561 setLastModifiedSubInvalid(); 574 setLastModifiedSubInvalid();
562 mRelations.removeRef(event); 575 mRelations.removeRef(event);
563// if (event->getRelatedTo() == this) event->setRelatedTo(0); 576// if (event->getRelatedTo() == this) event->setRelatedTo(0);
564} 577}
565 578
566bool Incidence::recursOn(const QDate &qd) const 579bool Incidence::recursOn(const QDate &qd) const
567{ 580{
568 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; 581 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
569 else return false; 582 else return false;
570} 583}
571 584
572void Incidence::setExDates(const DateList &exDates) 585void Incidence::setExDates(const DateList &exDates)
573{ 586{
574 if (mReadOnly) return; 587 if (mReadOnly) return;
575 mExDates = exDates; 588 mExDates = exDates;
576 recurrence()->setRecurExDatesCount(mExDates.count()); 589 recurrence()->setRecurExDatesCount(mExDates.count());
577 590
578 updated(); 591 updated();
579} 592}
580 593
581void Incidence::addExDate(const QDate &date) 594void Incidence::addExDate(const QDate &date)
582{ 595{
583 if (mReadOnly) return; 596 if (mReadOnly) return;
584 mExDates.append(date); 597 mExDates.append(date);
585 598
586 recurrence()->setRecurExDatesCount(mExDates.count()); 599 recurrence()->setRecurExDatesCount(mExDates.count());
587 600
588 updated(); 601 updated();
589} 602}
590 603
591DateList Incidence::exDates() const 604DateList Incidence::exDates() const
592{ 605{
593 return mExDates; 606 return mExDates;
594} 607}
595 608
596bool Incidence::isException(const QDate &date) const 609bool Incidence::isException(const QDate &date) const
597{ 610{
598 DateList::ConstIterator it; 611 DateList::ConstIterator it;
599 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 612 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
600 if ( (*it) == date ) { 613 if ( (*it) == date ) {
601 return true; 614 return true;
602 } 615 }
603 } 616 }
604 617
605 return false; 618 return false;
606} 619}
607 620
608void Incidence::addAttachment(Attachment *attachment) 621void Incidence::addAttachment(Attachment *attachment)
609{ 622{
610 if (mReadOnly || !attachment) return; 623 if (mReadOnly || !attachment) return;
611 mAttachments.append(attachment); 624 mAttachments.append(attachment);
612 updated(); 625 updated();
613} 626}
614 627
615void Incidence::deleteAttachment(Attachment *attachment) 628void Incidence::deleteAttachment(Attachment *attachment)
616{ 629{
617 mAttachments.removeRef(attachment); 630 mAttachments.removeRef(attachment);
618} 631}
619 632
620void Incidence::deleteAttachments(const QString& mime) 633void Incidence::deleteAttachments(const QString& mime)
621{ 634{
622 Attachment *at = mAttachments.first(); 635 Attachment *at = mAttachments.first();
623 while (at) { 636 while (at) {
624 if (at->mimeType() == mime) 637 if (at->mimeType() == mime)
625 mAttachments.remove(); 638 mAttachments.remove();
626 else 639 else
627 at = mAttachments.next(); 640 at = mAttachments.next();
628 } 641 }
629} 642}
630 643
631QPtrList<Attachment> Incidence::attachments() const 644QPtrList<Attachment> Incidence::attachments() const
632{ 645{
633 return mAttachments; 646 return mAttachments;
634} 647}
635 648
636QPtrList<Attachment> Incidence::attachments(const QString& mime) const 649QPtrList<Attachment> Incidence::attachments(const QString& mime) const
637{ 650{
638 QPtrList<Attachment> attachments; 651 QPtrList<Attachment> attachments;
639 QPtrListIterator<Attachment> it( mAttachments ); 652 QPtrListIterator<Attachment> it( mAttachments );
640 Attachment *at; 653 Attachment *at;
641 while ( (at = it.current()) ) { 654 while ( (at = it.current()) ) {
642 if (at->mimeType() == mime) 655 if (at->mimeType() == mime)
643 attachments.append(at); 656 attachments.append(at);
644 ++it; 657 ++it;
645 } 658 }
646 659
647 return attachments; 660 return attachments;
648} 661}
649 662
650void Incidence::setResources(const QStringList &resources) 663void Incidence::setResources(const QStringList &resources)
651{ 664{
652 if (mReadOnly) return; 665 if (mReadOnly) return;
653 mResources = resources; 666 mResources = resources;
654 updated(); 667 updated();
655} 668}
656 669
657QStringList Incidence::resources() const 670QStringList Incidence::resources() const
658{ 671{
659 return mResources; 672 return mResources;
660} 673}
661 674
662 675
663void Incidence::setPriority(int priority) 676void Incidence::setPriority(int priority)
664{ 677{
665 if (mReadOnly) return; 678 if (mReadOnly) return;
666 mPriority = priority; 679 mPriority = priority;
667 updated(); 680 updated();
668} 681}
669 682
670int Incidence::priority() const 683int Incidence::priority() const
671{ 684{
672 return mPriority; 685 return mPriority;
673} 686}
674 687
675void Incidence::setSecrecy(int sec) 688void Incidence::setSecrecy(int sec)
676{ 689{
677 if (mReadOnly) return; 690 if (mReadOnly) return;
678 mSecrecy = sec; 691 mSecrecy = sec;
679 updated(); 692 updated();
680} 693}
681 694
682int Incidence::secrecy() const 695int Incidence::secrecy() const
683{ 696{
684 return mSecrecy; 697 return mSecrecy;
685} 698}
686 699
687QString Incidence::secrecyStr() const 700QString Incidence::secrecyStr() const
688{ 701{
689 return secrecyName(mSecrecy); 702 return secrecyName(mSecrecy);
690} 703}
691 704
692QString Incidence::secrecyName(int secrecy) 705QString Incidence::secrecyName(int secrecy)
693{ 706{
694 switch (secrecy) { 707 switch (secrecy) {
695 case SecrecyPublic: 708 case SecrecyPublic:
696 return i18n("Public"); 709 return i18n("Public");
697 break; 710 break;
698 case SecrecyPrivate: 711 case SecrecyPrivate:
699 return i18n("Private"); 712 return i18n("Private");
700 break; 713 break;
701 case SecrecyConfidential: 714 case SecrecyConfidential:
702 return i18n("Confidential"); 715 return i18n("Confidential");
703 break; 716 break;
704 default: 717 default:
705 return i18n("Undefined"); 718 return i18n("Undefined");
706 break; 719 break;
707 } 720 }
708} 721}
709 722
710QStringList Incidence::secrecyList() 723QStringList Incidence::secrecyList()
711{ 724{
712 QStringList list; 725 QStringList list;
713 list << secrecyName(SecrecyPublic); 726 list << secrecyName(SecrecyPublic);
714 list << secrecyName(SecrecyPrivate); 727 list << secrecyName(SecrecyPrivate);
715 list << secrecyName(SecrecyConfidential); 728 list << secrecyName(SecrecyConfidential);
716 729
717 return list; 730 return list;
718} 731}
719 732
720 733
721QPtrList<Alarm> Incidence::alarms() const 734QPtrList<Alarm> Incidence::alarms() const
722{ 735{
723 return mAlarms; 736 return mAlarms;
724} 737}
725 738
726Alarm* Incidence::newAlarm() 739Alarm* Incidence::newAlarm()
727{ 740{
728 Alarm* alarm = new Alarm(this); 741 Alarm* alarm = new Alarm(this);
729 mAlarms.append(alarm); 742 mAlarms.append(alarm);
730// updated(); 743// updated();
731 return alarm; 744 return alarm;
732} 745}
733 746
734void Incidence::addAlarm(Alarm *alarm) 747void Incidence::addAlarm(Alarm *alarm)
735{ 748{
736 mAlarms.append(alarm); 749 mAlarms.append(alarm);
737 updated(); 750 updated();
738} 751}
739 752
740void Incidence::removeAlarm(Alarm *alarm) 753void Incidence::removeAlarm(Alarm *alarm)
741{ 754{
742 mAlarms.removeRef(alarm); 755 mAlarms.removeRef(alarm);
743 updated(); 756 updated();
744} 757}
745 758
746void Incidence::clearAlarms() 759void Incidence::clearAlarms()
747{ 760{
748 mAlarms.clear(); 761 mAlarms.clear();
749 updated(); 762 updated();
750} 763}
751 764
752bool Incidence::isAlarmEnabled() const 765bool Incidence::isAlarmEnabled() const
753{ 766{
754 Alarm* alarm; 767 Alarm* alarm;
755 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 768 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
756 if (alarm->enabled()) 769 if (alarm->enabled())
757 return true; 770 return true;
758 } 771 }
759 return false; 772 return false;
760} 773}
761#include <stdlib.h> 774#include <stdlib.h>
762Recurrence *Incidence::recurrence() 775Recurrence *Incidence::recurrence()
763{ 776{
764 if ( ! mRecurrence ) { 777 if ( ! mRecurrence ) {
765 mRecurrence = new Recurrence(this); 778 mRecurrence = new Recurrence(this);
766 mRecurrence->setRecurStart( dtStart() ); 779 mRecurrence->setRecurStart( dtStart() );
767 mRecurrence->setRecurReadOnly( isReadOnly()); 780 mRecurrence->setRecurReadOnly( isReadOnly());
768 //qDebug("creating new recurence "); 781 //qDebug("creating new recurence ");
769 //abort(); 782 //abort();
770 } 783 }
771 return mRecurrence; 784 return mRecurrence;
772} 785}
773void Incidence::setRecurrence( Recurrence * r) 786void Incidence::setRecurrence( Recurrence * r)
774{ 787{
775 if ( mRecurrence ) 788 if ( mRecurrence )
776 delete mRecurrence; 789 delete mRecurrence;
777 mRecurrence = r; 790 mRecurrence = r;
778} 791}
779 792
780void Incidence::setLocation(const QString &location) 793void Incidence::setLocation(const QString &location)
781{ 794{
782 if (mReadOnly) return; 795 if (mReadOnly) return;
783 mLocation = location; 796 mLocation = location;
784 updated(); 797 updated();
785} 798}
786 799
787QString Incidence::location() const 800QString Incidence::location() const
788{ 801{
789 return mLocation; 802 return mLocation;
790} 803}
791QString Incidence::recurrenceText() const 804QString Incidence::recurrenceText() const
792{ 805{
793 if ( mRecurrence ) return mRecurrence->recurrenceText(); 806 if ( mRecurrence ) return mRecurrence->recurrenceText();
794 return i18n("No"); 807 return i18n("No");
795} 808}
796 809
797ushort Incidence::doesRecur() const 810ushort Incidence::doesRecur() const
798{ 811{
799 if ( mRecurrence ) return mRecurrence->doesRecur(); 812 if ( mRecurrence ) return mRecurrence->doesRecur();
800 else return Recurrence::rNone; 813 else return Recurrence::rNone;
801} 814}
802 815
803QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 816QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
804{ 817{
805 QDateTime incidenceStart = dt; 818 QDateTime incidenceStart = dt;
806 *ok = false; 819 *ok = false;
807 if ( doesRecur() ) { 820 if ( doesRecur() ) {
808 bool last; 821 bool last;
809 mRecurrence->getPreviousDateTime( incidenceStart , &last ); 822 mRecurrence->getPreviousDateTime( incidenceStart , &last );
810 int count = 0; 823 int count = 0;
811 if ( !last ) { 824 if ( !last ) {
812 while ( !last ) { 825 while ( !last ) {
813 ++count; 826 ++count;
814 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); 827 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
815 if ( recursOn( incidenceStart.date() ) ) { 828 if ( recursOn( incidenceStart.date() ) ) {
816 last = true; // exit while llop 829 last = true; // exit while llop
817 } else { 830 } else {
818 if ( last ) { // no alarm on last recurrence 831 if ( last ) { // no alarm on last recurrence
819 return QDateTime (); 832 return QDateTime ();
820 } 833 }
821 int year = incidenceStart.date().year(); 834 int year = incidenceStart.date().year();
822 // workaround for bug in recurrence 835 // workaround for bug in recurrence
823 if ( count == 100 || year < 1000 || year > 5000 ) { 836 if ( count == 100 || year < 1000 || year > 5000 ) {
824 return QDateTime (); 837 return QDateTime ();
825 } 838 }
826 incidenceStart = incidenceStart.addSecs( 1 ); 839 incidenceStart = incidenceStart.addSecs( 1 );
827 } 840 }
828 } 841 }
829 } else { 842 } else {
830 return QDateTime (); 843 return QDateTime ();
831 } 844 }
832 } else { 845 } else {
833 if ( hasStartDate () ) { 846 if ( hasStartDate () ) {
834 incidenceStart = dtStart(); 847 incidenceStart = dtStart();
835 } 848 }
836 if ( typeID() == todoID ) { 849 if ( typeID() == todoID ) {
837 if ( ((Todo*)this)->hasDueDate() ) 850 if ( ((Todo*)this)->hasDueDate() )
838 incidenceStart = ((Todo*)this)->dtDue(); 851 incidenceStart = ((Todo*)this)->dtDue();
839 } 852 }
840 } 853 }
841 if ( incidenceStart > dt ) 854 if ( incidenceStart > dt )
842 *ok = true; 855 *ok = true;
843 return incidenceStart; 856 return incidenceStart;
844} 857}
845QDateTime Incidence::dtStart() const 858QDateTime Incidence::dtStart() const
846{ 859{
847 if ( doesRecur() ) { 860 if ( doesRecur() ) {
848 if ( typeID() == todoID ) { 861 if ( typeID() == todoID ) {
849 ((Todo*)this)->checkSetCompletedFalse(); 862 ((Todo*)this)->checkSetCompletedFalse();
850 } 863 }
851 } 864 }
852 return mDtStart; 865 return mDtStart;
853} 866}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index eef9e64..dc49640 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -1,324 +1,326 @@
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 INCIDENCE_H 20#ifndef INCIDENCE_H
21#define INCIDENCE_H 21#define INCIDENCE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29 29
30#include "recurrence.h" 30#include "recurrence.h"
31#include "alarm.h" 31#include "alarm.h"
32#include "attachment.h" 32#include "attachment.h"
33#include "listbase.h" 33#include "listbase.h"
34#include "incidencebase.h" 34#include "incidencebase.h"
35 35
36namespace KCal { 36namespace KCal {
37 37
38class Event; 38class Event;
39class Todo; 39class Todo;
40class Journal; 40class Journal;
41 41
42/** 42/**
43 This class provides the base class common to all calendar components. 43 This class provides the base class common to all calendar components.
44*/ 44*/
45class Incidence : public IncidenceBase 45class Incidence : public IncidenceBase
46{ 46{
47 public: 47 public:
48 /** 48 /**
49 This class provides the interface for a visitor of calendar components. It 49 This class provides the interface for a visitor of calendar components. It
50 serves as base class for concrete visitors, which implement certain actions on 50 serves as base class for concrete visitors, which implement certain actions on
51 calendar components. It allows to add functions, which operate on the concrete 51 calendar components. It allows to add functions, which operate on the concrete
52 types of calendar components, without changing the calendar component classes. 52 types of calendar components, without changing the calendar component classes.
53 */ 53 */
54 class Visitor 54 class Visitor
55 { 55 {
56 public: 56 public:
57 /** Destruct Incidence::Visitor */ 57 /** Destruct Incidence::Visitor */
58 virtual ~Visitor() {} 58 virtual ~Visitor() {}
59 59
60 /** 60 /**
61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
62 on an Event object. 62 on an Event object.
63 */ 63 */
64 virtual bool visit(Event *) { return false; } 64 virtual bool visit(Event *) { return false; }
65 /** 65 /**
66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
67 on an Todo object. 67 on an Todo object.
68 */ 68 */
69 virtual bool visit(Todo *) { return false; } 69 virtual bool visit(Todo *) { return false; }
70 /** 70 /**
71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
72 on an Journal object. 72 on an Journal object.
73 */ 73 */
74 virtual bool visit(Journal *) { return false; } 74 virtual bool visit(Journal *) { return false; }
75 75
76 protected: 76 protected:
77 /** Constructor is protected to prevent direct creation of visitor base class. */ 77 /** Constructor is protected to prevent direct creation of visitor base class. */
78 Visitor() {} 78 Visitor() {}
79 }; 79 };
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 void addRelationsToList(QPtrList<Incidence> *rel); 116 void addRelationsToList(QPtrList<Incidence> *rel);
117 void clearRelations(); 117 void clearRelations();
118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; 118 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
119 void setReadOnly( bool ); 119 void setReadOnly( bool );
120 120
121 /** 121 /**
122 Recreate event. The event is made a new unique event, but already stored 122 Recreate event. The event is made a new unique event, but already stored
123 event information is preserved. Sets uniquie id, creation date, last 123 event information is preserved. Sets uniquie id, creation date, last
124 modification date and revision number. 124 modification date and revision number.
125 */ 125 */
126 void recreate(); 126 void recreate();
127 Incidence* recreateCloneException(QDate); 127 Incidence* recreateCloneException(QDate);
128 128
129 /** set creation date */ 129 /** set creation date */
130 void setCreated(QDateTime); 130 void setCreated(QDateTime);
131 /** return time and date of creation. */ 131 /** return time and date of creation. */
132 QDateTime created() const; 132 QDateTime created() const;
133 133
134 /** set the number of revisions this event has seen */ 134 /** set the number of revisions this event has seen */
135 void setRevision(int rev); 135 void setRevision(int rev);
136 /** return the number of revisions this event has seen */ 136 /** return the number of revisions this event has seen */
137 int revision() const; 137 int revision() const;
138 138
139 /** Set starting date/time. */ 139 /** Set starting date/time. */
140 virtual void setDtStart(const QDateTime &dtStart); 140 virtual void setDtStart(const QDateTime &dtStart);
141 /** Return the incidence's ending date/time as a QDateTime. */ 141 /** Return the incidence's ending date/time as a QDateTime. */
142 virtual QDateTime dtEnd() const { return QDateTime(); } 142 virtual QDateTime dtEnd() const { return QDateTime(); }
143 143
144 /** sets the event's lengthy description. */ 144 /** sets the event's lengthy description. */
145 void setDescription(const QString &description); 145 void setDescription(const QString &description);
146 /** returns a reference to the event's description. */ 146 /** returns a reference to the event's description. */
147 QString description() const; 147 QString description() const;
148 148
149 /** sets the event's short summary. */ 149 /** sets the event's short summary. */
150 void setSummary(const QString &summary); 150 void setSummary(const QString &summary);
151 /** returns a reference to the event's summary. */ 151 /** returns a reference to the event's summary. */
152 QString summary() const; 152 QString summary() const;
153 153
154 /** set event's applicable categories */ 154 /** set event's applicable categories */
155 void setCategories(const QStringList &categories, bool setForRelations = false); 155 void setCategories(const QStringList &categories, bool setForRelations = false);
156 void addCategories(const QStringList &categories, bool addToRelations = false); 156 void addCategories(const QStringList &categories, bool addToRelations = false);
157 /** set event's categories based on a comma delimited string */ 157 /** set event's categories based on a comma delimited string */
158 void setCategories(const QString &catStr); 158 void setCategories(const QString &catStr);
159 /** return categories in a list */ 159 /** return categories in a list */
160 QStringList categories() const; 160 QStringList categories() const;
161 QStringList* categoriesP(); 161 QStringList* categoriesP();
162 /** return categories as a comma separated string */ 162 /** return categories as a comma separated string */
163 QString categoriesStr(); 163 QString categoriesStr();
164 QString categoriesStrWithSpace(); 164 QString categoriesStrWithSpace();
165 165
166 /** point at some other event to which the event relates. This function should 166 /** point at some other event to which the event relates. This function should
167 * only be used when constructing a calendar before the related Event 167 * only be used when constructing a calendar before the related Event
168 * exists. */ 168 * exists. */
169 void setRelatedToUid(const QString &); 169 void setRelatedToUid(const QString &);
170 /** what event does this one relate to? This function should 170 /** what event does this one relate to? This function should
171 * only be used when constructing a calendar before the related Event 171 * only be used when constructing a calendar before the related Event
172 * exists. */ 172 * exists. */
173 QString relatedToUid() const; 173 QString relatedToUid() const;
174 /** point at some other event to which the event relates */ 174 /** point at some other event to which the event relates */
175 void setRelatedTo(Incidence *relatedTo); 175 void setRelatedTo(Incidence *relatedTo);
176 /** what event does this one relate to? */ 176 /** what event does this one relate to? */
177 Incidence *relatedTo() const; 177 Incidence *relatedTo() const;
178 /** All events that are related to this event */ 178 /** All events that are related to this event */
179 QPtrList<Incidence> relations() const; 179 QPtrList<Incidence> relations() const;
180 /** Add an event which is related to this event */ 180 /** Add an event which is related to this event */
181 void addRelation(Incidence *); 181 void addRelation(Incidence *);
182 /** Remove event that is related to this event */ 182 /** Remove event that is related to this event */
183 void removeRelation(Incidence *); 183 void removeRelation(Incidence *);
184 184
185 /** returns the list of dates which are exceptions to the recurrence rule */ 185 /** returns the list of dates which are exceptions to the recurrence rule */
186 DateList exDates() const; 186 DateList exDates() const;
187 /** sets the list of dates which are exceptions to the recurrence rule */ 187 /** sets the list of dates which are exceptions to the recurrence rule */
188 void setExDates(const DateList &_exDates); 188 void setExDates(const DateList &_exDates);
189 void setExDates(const char *dates); 189 void setExDates(const char *dates);
190 /** Add a date to the list of exceptions of the recurrence rule. */ 190 /** Add a date to the list of exceptions of the recurrence rule. */
191 void addExDate(const QDate &date); 191 void addExDate(const QDate &date);
192 192
193 /** returns true if there is an exception for this date in the recurrence 193 /** returns true if there is an exception for this date in the recurrence
194 rule set, or false otherwise. */ 194 rule set, or false otherwise. */
195 bool isException(const QDate &qd) const; 195 bool isException(const QDate &qd) const;
196 196
197 /** add attachment to this event */ 197 /** add attachment to this event */
198 void addAttachment(Attachment *attachment); 198 void addAttachment(Attachment *attachment);
199 /** remove and delete a specific attachment */ 199 /** remove and delete a specific attachment */
200 void deleteAttachment(Attachment *attachment); 200 void deleteAttachment(Attachment *attachment);
201 /** remove and delete all attachments with this mime type */ 201 /** remove and delete all attachments with this mime type */
202 void deleteAttachments(const QString& mime); 202 void deleteAttachments(const QString& mime);
203 /** return list of all associated attachments */ 203 /** return list of all associated attachments */
204 QPtrList<Attachment> attachments() const; 204 QPtrList<Attachment> attachments() const;
205 /** find a list of attachments with this mime type */ 205 /** find a list of attachments with this mime type */
206 QPtrList<Attachment> attachments(const QString& mime) const; 206 QPtrList<Attachment> attachments(const QString& mime) const;
207 207
208 /** sets the event's status the value specified. See the enumeration 208 /** sets the event's status the value specified. See the enumeration
209 * above for possible values. */ 209 * above for possible values. */
210 void setSecrecy(int); 210 void setSecrecy(int);
211 /** return the event's secrecy. */ 211 /** return the event's secrecy. */
212 int secrecy() const; 212 int secrecy() const;
213 /** return the event's secrecy in string format. */ 213 /** return the event's secrecy in string format. */
214 QString secrecyStr() const; 214 QString secrecyStr() const;
215 /** return list of all availbale secrecy classes */ 215 /** return list of all availbale secrecy classes */
216 static QStringList secrecyList(); 216 static QStringList secrecyList();
217 /** return human-readable name of secrecy class */ 217 /** return human-readable name of secrecy class */
218 static QString secrecyName(int); 218 static QString secrecyName(int);
219 219
220 /** returns TRUE if the date specified is one on which the event will 220 /** returns TRUE if the date specified is one on which the event will
221 * recur. */ 221 * recur. */
222 bool recursOn(const QDate &qd) const; 222 bool recursOn(const QDate &qd) const;
223 223
224 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 224 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
225 225
226 /** set resources used, such as Office, Car, etc. */ 226 /** set resources used, such as Office, Car, etc. */
227 void setResources(const QStringList &resources); 227 void setResources(const QStringList &resources);
228 /** return list of current resources */ 228 /** return list of current resources */
229 QStringList resources() const; 229 QStringList resources() const;
230 230
231 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 231 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
232 void setPriority(int priority); 232 void setPriority(int priority);
233 /** get the event's priority */ 233 /** get the event's priority */
234 int priority() const; 234 int priority() const;
235 235
236 /** All alarms that are associated with this incidence */ 236 /** All alarms that are associated with this incidence */
237 QPtrList<Alarm> alarms() const; 237 QPtrList<Alarm> alarms() const;
238 /** Create a new alarm which is associated with this incidence */ 238 /** Create a new alarm which is associated with this incidence */
239 Alarm* newAlarm(); 239 Alarm* newAlarm();
240 /** Add an alarm which is associated with this incidence */ 240 /** Add an alarm which is associated with this incidence */
241 void addAlarm(Alarm*); 241 void addAlarm(Alarm*);
242 /** Remove an alarm that is associated with this incidence */ 242 /** Remove an alarm that is associated with this incidence */
243 void removeAlarm(Alarm*); 243 void removeAlarm(Alarm*);
244 /** Remove all alarms that are associated with this incidence */ 244 /** Remove all alarms that are associated with this incidence */
245 void clearAlarms(); 245 void clearAlarms();
246 /** return whether any alarm associated with this incidence is enabled */ 246 /** return whether any alarm associated with this incidence is enabled */
247 bool isAlarmEnabled() const; 247 bool isAlarmEnabled() const;
248 248
249 /** 249 /**
250 Return the recurrence rule associated with this incidence. If there is 250 Return the recurrence rule associated with this incidence. If there is
251 none, returns an appropriate (non-0) object. 251 none, returns an appropriate (non-0) object.
252 */ 252 */
253 Recurrence *recurrence(); 253 Recurrence *recurrence();
254 void setRecurrence(Recurrence * r); 254 void setRecurrence(Recurrence * r);
255 /** 255 /**
256 Forward to Recurrence::doesRecur(). 256 Forward to Recurrence::doesRecur().
257 */ 257 */
258 ushort doesRecur() const; 258 ushort doesRecur() const;
259 259
260 /** set the event's/todo's location. Do _not_ use it with journal */ 260 /** set the event's/todo's location. Do _not_ use it with journal */
261 void setLocation(const QString &location); 261 void setLocation(const QString &location);
262 /** return the event's/todo's location. Do _not_ use it with journal */ 262 /** return the event's/todo's location. Do _not_ use it with journal */
263 QString location() const; 263 QString location() const;
264 /** returns TRUE or FALSE depending on whether the todo has a start date */ 264 /** returns TRUE or FALSE depending on whether the todo has a start date */
265 bool hasStartDate() const; 265 bool hasStartDate() const;
266 /** sets the event's hasStartDate value. */ 266 /** sets the event's hasStartDate value. */
267 void setHasStartDate(bool f); 267 void setHasStartDate(bool f);
268 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 268 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
269 bool cancelled() const; 269 bool cancelled() const;
270 void setCancelled( bool b ); 270 void setCancelled( bool b );
271 271
272 bool hasRecurrenceID() const; 272 bool hasRecurrenceID() const;
273 void setHasRecurrenceID( bool b ); 273 void setHasRecurrenceID( bool b );
274 274
275 void setRecurrenceID(QDateTime); 275 void setRecurrenceID(QDateTime);
276 QDateTime recurrenceID () const; 276 QDateTime recurrenceID () const;
277 QDateTime dtStart() const; 277 QDateTime dtStart() const;
278 bool isHoliday() const; 278 bool isHoliday() const;
279 bool isBirthday() const; 279 bool isBirthday() const;
280 bool isAnniversary() const; 280 bool isAnniversary() const;
281 QDateTime lastModifiedSub(); 281 QDateTime lastModifiedSub();
282 QString lastModifiedSubSortKey() const;
282 QString recurrenceText() const; 283 QString recurrenceText() const;
283 void setLastModifiedSubInvalid(); 284 void setLastModifiedSubInvalid();
284 285
285 virtual QString durationText(); 286 virtual QString durationText();
286 QString durationText4Time( int secs ); 287 QString durationText4Time( int secs );
287 Recurrence *mRecurrence; 288 Recurrence *mRecurrence;
288protected: 289protected:
289 QPtrList<Alarm> mAlarms; 290 QPtrList<Alarm> mAlarms;
290 QPtrList<Incidence> mRelations; 291 QPtrList<Incidence> mRelations;
291 QDateTime mRecurrenceID; 292 QDateTime mRecurrenceID;
292 bool mHasRecurrenceID; 293 bool mHasRecurrenceID;
293 private: 294 private:
294 void checkCategories(); 295 void checkCategories();
296 QString mLastModifiedSubSortKey;
295 bool mHoliday, mBirthday, mAnniversary; 297 bool mHoliday, mBirthday, mAnniversary;
296 int mRevision; 298 int mRevision;
297 bool mCancelled; 299 bool mCancelled;
298 300
299 // base components of jounal, event and todo 301 // base components of jounal, event and todo
300 QDateTime mCreated; 302 QDateTime mCreated;
301 QDateTime mLastModifiedSub; 303 QDateTime mLastModifiedSub;
302 QString mDescription; 304 QString mDescription;
303 QString mSummary; 305 QString mSummary;
304 QStringList mCategories; 306 QStringList mCategories;
305 Incidence *mRelatedTo; 307 Incidence *mRelatedTo;
306 QString mRelatedToUid; 308 QString mRelatedToUid;
307 DateList mExDates; 309 DateList mExDates;
308 QPtrList<Attachment> mAttachments; 310 QPtrList<Attachment> mAttachments;
309 QStringList mResources; 311 QStringList mResources;
310 bool mHasStartDate; // if todo has associated start date 312 bool mHasStartDate; // if todo has associated start date
311 313
312 int mSecrecy; 314 int mSecrecy;
313 int mPriority; // 1 = highest, 2 = less, etc. 315 int mPriority; // 1 = highest, 2 = less, etc.
314 316
315 //QPtrList<Alarm> mAlarms; 317 //QPtrList<Alarm> mAlarms;
316 318
317 QString mLocation; 319 QString mLocation;
318}; 320};
319 321
320bool operator==( const Incidence&, const Incidence& ); 322bool operator==( const Incidence&, const Incidence& );
321 323
322} 324}
323 325
324#endif 326#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 022dead..cfef973 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,482 +1,493 @@
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 <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 blockLastModified = false; 37 blockLastModified = false;
38 setUid(CalFormat::createUniqueId()); 38 setUid(CalFormat::createUniqueId());
39 mOrganizer = ""; 39 mOrganizer = "";
40 mFloats = false; 40 mFloats = false;
41 mDuration = 0; 41 mDuration = 0;
42 mHasDuration = false; 42 mHasDuration = false;
43 mPilotId = 0; 43 mPilotId = 0;
44 mExternalId = ":"; 44 mExternalId = ":";
45 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 45 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
46 mSyncStatus = 0; 46 mSyncStatus = 0;
47 mAttendees.setAutoDelete( true ); 47 mAttendees.setAutoDelete( true );
48 mCalEnabled = true; 48 mCalEnabled = true;
49 mAlarmEnabled = true; 49 mAlarmEnabled = true;
50 mCalID = 0; 50 mCalID = 0;
51} 51}
52 52
53IncidenceBase::IncidenceBase(const IncidenceBase &i) : 53IncidenceBase::IncidenceBase(const IncidenceBase &i) :
54 CustomProperties( i ) 54 CustomProperties( i )
55{ 55{
56 56
57 blockLastModified = false; 57 blockLastModified = false;
58 mReadOnly = i.mReadOnly; 58 mReadOnly = i.mReadOnly;
59 mDtStart = i.mDtStart; 59 mDtStart = i.mDtStart;
60 mDuration = i.mDuration; 60 mDuration = i.mDuration;
61 mHasDuration = i.mHasDuration; 61 mHasDuration = i.mHasDuration;
62 mOrganizer = i.mOrganizer; 62 mOrganizer = i.mOrganizer;
63 mUid = i.mUid; 63 mUid = i.mUid;
64 mCalEnabled = i.mCalEnabled; 64 mCalEnabled = i.mCalEnabled;
65 mAlarmEnabled = i.mAlarmEnabled; 65 mAlarmEnabled = i.mAlarmEnabled;
66 mCalID = i.mCalID; 66 mCalID = i.mCalID;
67 QPtrList<Attendee> attendees = i.attendees(); 67 QPtrList<Attendee> attendees = i.attendees();
68 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 68 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
69 mAttendees.append( new Attendee( *a ) ); 69 mAttendees.append( new Attendee( *a ) );
70 } 70 }
71 mFloats = i.mFloats; 71 mFloats = i.mFloats;
72 mLastModified = i.mLastModified; 72 mLastModified = i.mLastModified;
73 mPilotId = i.mPilotId; 73 mPilotId = i.mPilotId;
74 mTempSyncStat = i.mTempSyncStat; 74 mTempSyncStat = i.mTempSyncStat;
75 mSyncStatus = i.mSyncStatus; 75 mSyncStatus = i.mSyncStatus;
76 mExternalId = i.mExternalId; 76 mExternalId = i.mExternalId;
77 // The copied object is a new one, so it isn't observed by the observer 77 // The copied object is a new one, so it isn't observed by the observer
78 // of the original object. 78 // of the original object.
79 mObservers.clear(); 79 mObservers.clear();
80 80
81 mAttendees.setAutoDelete( true ); 81 mAttendees.setAutoDelete( true );
82} 82}
83 83
84IncidenceBase::~IncidenceBase() 84IncidenceBase::~IncidenceBase()
85{ 85{
86} 86}
87 87
88 88
89bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 89bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
90{ 90{
91 // do not compare mSyncStatus and mExternalId 91 // do not compare mSyncStatus and mExternalId
92 if( i1.attendees().count() != i2.attendees().count() ) { 92 if( i1.attendees().count() != i2.attendees().count() ) {
93 return false; // no need to check further 93 return false; // no need to check further
94 } 94 }
95 if ( i1.attendees().count() > 0 ) { 95 if ( i1.attendees().count() > 0 ) {
96 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 96 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
97 while ( a1 ) { 97 while ( a1 ) {
98 if ( !( (*a1) == (*a2)) ) 98 if ( !( (*a1) == (*a2)) )
99 { 99 {
100 //qDebug("Attendee not equal "); 100 //qDebug("Attendee not equal ");
101 return false; 101 return false;
102 } 102 }
103 a1 = i1.attendees().next(); 103 a1 = i1.attendees().next();
104 a2 = i2.attendees().next(); 104 a2 = i2.attendees().next();
105 } 105 }
106 } 106 }
107 //if ( i1.dtStart() != i2.dtStart() ) 107 //if ( i1.dtStart() != i2.dtStart() )
108 // return false; 108 // return false;
109#if 0 109#if 0
110 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 110 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
111 qDebug("1 %d ",i1.duration() == i2.duration() ); 111 qDebug("1 %d ",i1.duration() == i2.duration() );
112 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 112 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
113 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 113 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
114 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 114 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
115 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 115 qDebug("6 %d ",i1.organizer() == i2.organizer() );
116 116
117#endif 117#endif
118 if ( i1.hasDuration() == i2.hasDuration() ) { 118 if ( i1.hasDuration() == i2.hasDuration() ) {
119 if ( i1.hasDuration() ) { 119 if ( i1.hasDuration() ) {
120 if ( i1.duration() != i2.duration() ) 120 if ( i1.duration() != i2.duration() )
121 return false; 121 return false;
122 } 122 }
123 } else { 123 } else {
124 return false; 124 return false;
125 } 125 }
126 126
127 return ( i1.organizer() == i2.organizer() && 127 return ( i1.organizer() == i2.organizer() &&
128 // i1.uid() == i2.uid() && 128 // i1.uid() == i2.uid() &&
129 // Don't compare lastModified, otherwise the operator is not 129 // Don't compare lastModified, otherwise the operator is not
130 // of much use. We are not comparing for identity, after all. 130 // of much use. We are not comparing for identity, after all.
131 i1.doesFloat() == i2.doesFloat() && 131 i1.doesFloat() == i2.doesFloat() &&
132 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 132 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
133 // no need to compare mObserver 133 // no need to compare mObserver
134} 134}
135 135
136 136
137QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 137QDateTime IncidenceBase::getEvenTime( QDateTime dt )
138{ 138{
139 QTime t = dt.time(); 139 QTime t = dt.time();
140 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 140 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
141 return dt; 141 return dt;
142} 142}
143 143
144bool IncidenceBase::isTagged() const 144bool IncidenceBase::isTagged() const
145{ 145{
146 return mIsTagged; 146 return mIsTagged;
147} 147}
148void IncidenceBase::setTagged( bool b) 148void IncidenceBase::setTagged( bool b)
149{ 149{
150 mIsTagged = b; 150 mIsTagged = b;
151} 151}
152void IncidenceBase::setCalID( int id ) 152void IncidenceBase::setCalID( int id )
153{ 153{
154 if ( mCalID > 0 ) { 154 if ( mCalID > 0 ) {
155 blockLastModified = true; 155 blockLastModified = true;
156 updated(); 156 updated();
157 blockLastModified = false; 157 blockLastModified = false;
158 } 158 }
159 mCalID = id; 159 mCalID = id;
160} 160}
161int IncidenceBase::calID() const 161int IncidenceBase::calID() const
162{ 162{
163 return mCalID; 163 return mCalID;
164} 164}
165void IncidenceBase::setCalEnabled( bool b ) 165void IncidenceBase::setCalEnabled( bool b )
166{ 166{
167 mCalEnabled = b; 167 mCalEnabled = b;
168} 168}
169bool IncidenceBase::calEnabled() const 169bool IncidenceBase::calEnabled() const
170{ 170{
171 return mCalEnabled; 171 return mCalEnabled;
172} 172}
173 173
174void IncidenceBase::setAlarmEnabled( bool b ) 174void IncidenceBase::setAlarmEnabled( bool b )
175{ 175{
176 mAlarmEnabled = b; 176 mAlarmEnabled = b;
177} 177}
178bool IncidenceBase::alarmEnabled() const 178bool IncidenceBase::alarmEnabled() const
179{ 179{
180 return mAlarmEnabled; 180 return mAlarmEnabled;
181} 181}
182 182
183 183
184void IncidenceBase::setUid(const QString &uid) 184void IncidenceBase::setUid(const QString &uid)
185{ 185{
186 mUid = uid; 186 mUid = uid;
187 updated(); 187 updated();
188} 188}
189 189
190QString IncidenceBase::uid() const 190QString IncidenceBase::uid() const
191{ 191{
192 return mUid; 192 return mUid;
193} 193}
194void IncidenceBase::setLastModifiedSubInvalid() 194void IncidenceBase::setLastModifiedSubInvalid()
195{ 195{
196 196 // virtual method
197} 197}
198void IncidenceBase::setLastModified(const QDateTime &lm) 198void IncidenceBase::setLastModified(const QDateTime &lm)
199{ 199{
200 if ( blockLastModified ) return; 200 if ( blockLastModified ) return;
201 // DON'T! updated() because we call this from 201 // DON'T! updated() because we call this from
202 // Calendar::updateEvent(). 202 // Calendar::updateEvent().
203 mLastModified = getEvenTime(lm); 203 mLastModified = getEvenTime(lm);
204 mLastModifiedKey.sprintf("%04d%02d%02d%02d%02d%02d",
205 mLastModified.date().year(),
206 mLastModified.date().month(),
207 mLastModified.date().day(),
208 mLastModified.time().hour(),
209 mLastModified.time().minute(),
210 mLastModified.time().second() );
204 setLastModifiedSubInvalid(); 211 setLastModifiedSubInvalid();
205 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 212 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
206} 213}
214QString IncidenceBase::lastModifiedSortKey() const
215{
216 return mLastModifiedKey;
217}
207 218
208QDateTime IncidenceBase::lastModified() const 219QDateTime IncidenceBase::lastModified() const
209{ 220{
210 return mLastModified; 221 return mLastModified;
211} 222}
212 223
213void IncidenceBase::setOrganizer(const QString &o) 224void IncidenceBase::setOrganizer(const QString &o)
214{ 225{
215 // we don't check for readonly here, because it is 226 // we don't check for readonly here, because it is
216 // possible that by setting the organizer we are changing 227 // possible that by setting the organizer we are changing
217 // the event's readonly status... 228 // the event's readonly status...
218 mOrganizer = o; 229 mOrganizer = o;
219 if (mOrganizer.left(7).upper() == "MAILTO:") 230 if (mOrganizer.left(7).upper() == "MAILTO:")
220 mOrganizer = mOrganizer.remove(0,7); 231 mOrganizer = mOrganizer.remove(0,7);
221 232
222 updated(); 233 updated();
223} 234}
224 235
225QString IncidenceBase::organizer() const 236QString IncidenceBase::organizer() const
226{ 237{
227 return mOrganizer; 238 return mOrganizer;
228} 239}
229 240
230void IncidenceBase::setReadOnly( bool readOnly ) 241void IncidenceBase::setReadOnly( bool readOnly )
231{ 242{
232 mReadOnly = readOnly; 243 mReadOnly = readOnly;
233} 244}
234 245
235void IncidenceBase::setDtStart(const QDateTime &dtStart) 246void IncidenceBase::setDtStart(const QDateTime &dtStart)
236{ 247{
237// if (mReadOnly) return; 248// if (mReadOnly) return;
238 mDtStart = getEvenTime(dtStart); 249 mDtStart = getEvenTime(dtStart);
239 updated(); 250 updated();
240} 251}
241 252
242 253
243QDateTime IncidenceBase::dtStart() const 254QDateTime IncidenceBase::dtStart() const
244{ 255{
245 return mDtStart; 256 return mDtStart;
246} 257}
247 258
248QString IncidenceBase::dtStartTimeStr() const 259QString IncidenceBase::dtStartTimeStr() const
249{ 260{
250 return KGlobal::locale()->formatTime(dtStart().time()); 261 return KGlobal::locale()->formatTime(dtStart().time());
251} 262}
252 263
253QString IncidenceBase::dtStartDateStr(bool shortfmt) const 264QString IncidenceBase::dtStartDateStr(bool shortfmt) const
254{ 265{
255 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 266 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
256} 267}
257 268
258QString IncidenceBase::dtStartStr(bool shortfmt) const 269QString IncidenceBase::dtStartStr(bool shortfmt) const
259{ 270{
260 if ( doesFloat() ) 271 if ( doesFloat() )
261 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 272 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
262 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 273 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
263} 274}
264 275
265 276
266bool IncidenceBase::doesFloat() const 277bool IncidenceBase::doesFloat() const
267{ 278{
268 return mFloats; 279 return mFloats;
269} 280}
270 281
271void IncidenceBase::setFloats(bool f) 282void IncidenceBase::setFloats(bool f)
272{ 283{
273 if (mReadOnly) return; 284 if (mReadOnly) return;
274 mFloats = f; 285 mFloats = f;
275 updated(); 286 updated();
276} 287}
277 288
278 289
279bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 290bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
280{ 291{
281 if (mReadOnly) return false; 292 if (mReadOnly) return false;
282 if (a->name().left(7).upper() == "MAILTO:") 293 if (a->name().left(7).upper() == "MAILTO:")
283 a->setName(a->name().remove(0,7)); 294 a->setName(a->name().remove(0,7));
284 295
285 QPtrListIterator<Attendee> qli(mAttendees); 296 QPtrListIterator<Attendee> qli(mAttendees);
286 297
287 qli.toFirst(); 298 qli.toFirst();
288 while (qli) { 299 while (qli) {
289 if (*qli.current() == *a) 300 if (*qli.current() == *a)
290 return false; 301 return false;
291 ++qli; 302 ++qli;
292 } 303 }
293 mAttendees.append(a); 304 mAttendees.append(a);
294 if (doupdate) updated(); 305 if (doupdate) updated();
295 return true; 306 return true;
296} 307}
297 308
298#if 0 309#if 0
299void IncidenceBase::removeAttendee(Attendee *a) 310void IncidenceBase::removeAttendee(Attendee *a)
300{ 311{
301 if (mReadOnly) return; 312 if (mReadOnly) return;
302 mAttendees.removeRef(a); 313 mAttendees.removeRef(a);
303 updated(); 314 updated();
304} 315}
305 316
306void IncidenceBase::removeAttendee(const char *n) 317void IncidenceBase::removeAttendee(const char *n)
307{ 318{
308 Attendee *a; 319 Attendee *a;
309 320
310 if (mReadOnly) return; 321 if (mReadOnly) return;
311 for (a = mAttendees.first(); a; a = mAttendees.next()) 322 for (a = mAttendees.first(); a; a = mAttendees.next())
312 if (a->getName() == n) { 323 if (a->getName() == n) {
313 mAttendees.remove(); 324 mAttendees.remove();
314 break; 325 break;
315 } 326 }
316} 327}
317#endif 328#endif
318 329
319void IncidenceBase::clearAttendees() 330void IncidenceBase::clearAttendees()
320{ 331{
321 if (mReadOnly) return; 332 if (mReadOnly) return;
322 mAttendees.clear(); 333 mAttendees.clear();
323} 334}
324 335
325#if 0 336#if 0
326Attendee *IncidenceBase::getAttendee(const char *n) const 337Attendee *IncidenceBase::getAttendee(const char *n) const
327{ 338{
328 QPtrListIterator<Attendee> qli(mAttendees); 339 QPtrListIterator<Attendee> qli(mAttendees);
329 340
330 qli.toFirst(); 341 qli.toFirst();
331 while (qli) { 342 while (qli) {
332 if (qli.current()->getName() == n) 343 if (qli.current()->getName() == n)
333 return qli.current(); 344 return qli.current();
334 ++qli; 345 ++qli;
335 } 346 }
336 return 0L; 347 return 0L;
337} 348}
338#endif 349#endif
339 350
340Attendee *IncidenceBase::attendeeByMail(const QString &email) 351Attendee *IncidenceBase::attendeeByMail(const QString &email)
341{ 352{
342 QPtrListIterator<Attendee> qli(mAttendees); 353 QPtrListIterator<Attendee> qli(mAttendees);
343 354
344 qli.toFirst(); 355 qli.toFirst();
345 while (qli) { 356 while (qli) {
346 if (qli.current()->email().lower() == email.lower()) 357 if (qli.current()->email().lower() == email.lower())
347 return qli.current(); 358 return qli.current();
348 ++qli; 359 ++qli;
349 } 360 }
350 return 0L; 361 return 0L;
351} 362}
352 363
353Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 364Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
354{ 365{
355 QPtrListIterator<Attendee> qli(mAttendees); 366 QPtrListIterator<Attendee> qli(mAttendees);
356 367
357 QStringList mails = emails; 368 QStringList mails = emails;
358 if (!email.isEmpty()) { 369 if (!email.isEmpty()) {
359 mails.append(email); 370 mails.append(email);
360 } 371 }
361 qli.toFirst(); 372 qli.toFirst();
362 while (qli) { 373 while (qli) {
363 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 374 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
364 if (qli.current()->email().lower() == (*it).lower()) 375 if (qli.current()->email().lower() == (*it).lower())
365 return qli.current(); 376 return qli.current();
366 } 377 }
367 378
368 ++qli; 379 ++qli;
369 } 380 }
370 return 0L; 381 return 0L;
371} 382}
372 383
373void IncidenceBase::setDuration(int seconds) 384void IncidenceBase::setDuration(int seconds)
374{ 385{
375 mDuration = seconds; 386 mDuration = seconds;
376 setHasDuration(true); 387 setHasDuration(true);
377} 388}
378 389
379int IncidenceBase::duration() const 390int IncidenceBase::duration() const
380{ 391{
381 return mDuration; 392 return mDuration;
382} 393}
383 394
384void IncidenceBase::setHasDuration(bool b) 395void IncidenceBase::setHasDuration(bool b)
385{ 396{
386 mHasDuration = b; 397 mHasDuration = b;
387} 398}
388 399
389bool IncidenceBase::hasDuration() const 400bool IncidenceBase::hasDuration() const
390{ 401{
391 return mHasDuration; 402 return mHasDuration;
392} 403}
393 404
394void IncidenceBase::setSyncStatus(int stat) 405void IncidenceBase::setSyncStatus(int stat)
395{ 406{
396 if (mReadOnly) return; 407 if (mReadOnly) return;
397 mSyncStatus = stat; 408 mSyncStatus = stat;
398} 409}
399 410
400int IncidenceBase::syncStatus() const 411int IncidenceBase::syncStatus() const
401{ 412{
402 return mSyncStatus; 413 return mSyncStatus;
403} 414}
404 415
405void IncidenceBase::setPilotId( int id ) 416void IncidenceBase::setPilotId( int id )
406{ 417{
407 if (mReadOnly) return; 418 if (mReadOnly) return;
408 mPilotId = id; 419 mPilotId = id;
409} 420}
410 421
411int IncidenceBase::pilotId() const 422int IncidenceBase::pilotId() const
412{ 423{
413 return mPilotId; 424 return mPilotId;
414} 425}
415 426
416int IncidenceBase::tempSyncStat() const 427int IncidenceBase::tempSyncStat() const
417{ 428{
418 return mTempSyncStat; 429 return mTempSyncStat;
419} 430}
420void IncidenceBase::setTempSyncStat( int id ) 431void IncidenceBase::setTempSyncStat( int id )
421{ 432{
422 if (mReadOnly) return; 433 if (mReadOnly) return;
423 mTempSyncStat = id; 434 mTempSyncStat = id;
424} 435}
425 436
426void IncidenceBase::removeID(const QString &prof) 437void IncidenceBase::removeID(const QString &prof)
427{ 438{
428 if ( prof.isEmpty() ) 439 if ( prof.isEmpty() )
429 mExternalId = ":"; 440 mExternalId = ":";
430 else 441 else
431 mExternalId = KIdManager::removeId ( mExternalId, prof); 442 mExternalId = KIdManager::removeId ( mExternalId, prof);
432 443
433} 444}
434void IncidenceBase::setID( const QString & prof , const QString & id ) 445void IncidenceBase::setID( const QString & prof , const QString & id )
435{ 446{
436 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 447 mExternalId = KIdManager::setId ( mExternalId, prof, id );
437} 448}
438QString IncidenceBase::getID( const QString & prof) 449QString IncidenceBase::getID( const QString & prof)
439{ 450{
440 return KIdManager::getId ( mExternalId, prof ); 451 return KIdManager::getId ( mExternalId, prof );
441} 452}
442 453
443// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 454// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
444// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 455// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
445void IncidenceBase::setCsum( const QString & prof , const QString & id ) 456void IncidenceBase::setCsum( const QString & prof , const QString & id )
446{ 457{
447 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 458 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
448} 459}
449QString IncidenceBase::getCsum( const QString & prof) 460QString IncidenceBase::getCsum( const QString & prof)
450{ 461{
451 return KIdManager::getCsum ( mExternalId, prof ); 462 return KIdManager::getCsum ( mExternalId, prof );
452} 463}
453 464
454void IncidenceBase::setIDStr( const QString & s ) 465void IncidenceBase::setIDStr( const QString & s )
455{ 466{
456 if (mReadOnly) return; 467 if (mReadOnly) return;
457 mExternalId = s; 468 mExternalId = s;
458} 469}
459 470
460QString IncidenceBase::IDStr() const 471QString IncidenceBase::IDStr() const
461{ 472{
462 return mExternalId ; 473 return mExternalId ;
463} 474}
464void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 475void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
465{ 476{
466 if( !mObservers.contains(observer) ) mObservers.append( observer ); 477 if( !mObservers.contains(observer) ) mObservers.append( observer );
467} 478}
468 479
469void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 480void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
470{ 481{
471 mObservers.remove( observer ); 482 mObservers.remove( observer );
472} 483}
473 484
474void IncidenceBase::updated() 485void IncidenceBase::updated()
475{ 486{
476 QPtrListIterator<Observer> it(mObservers); 487 QPtrListIterator<Observer> it(mObservers);
477 while( it.current() ) { 488 while( it.current() ) {
478 Observer *o = it.current(); 489 Observer *o = it.current();
479 ++it; 490 ++it;
480 o->incidenceUpdated( this ); 491 o->incidenceUpdated( this );
481 } 492 }
482} 493}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index 665c1f6..444d4c4 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,187 +1,189 @@
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 KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 enum IncTypeID { eventID,todoID,journalID,freebusyID }; 37 enum IncTypeID { eventID,todoID,journalID,freebusyID };
38 38
39/** 39/**
40 This class provides the base class common to all calendar components. 40 This class provides the base class common to all calendar components.
41*/ 41*/
42class IncidenceBase : public CustomProperties 42class IncidenceBase : public CustomProperties
43{ 43{
44 public: 44 public:
45 class Observer { 45 class Observer {
46 public: 46 public:
47 virtual void incidenceUpdated( IncidenceBase * ) = 0; 47 virtual void incidenceUpdated( IncidenceBase * ) = 0;
48 }; 48 };
49 49
50 IncidenceBase(); 50 IncidenceBase();
51 IncidenceBase(const IncidenceBase &); 51 IncidenceBase(const IncidenceBase &);
52 virtual ~IncidenceBase(); 52 virtual ~IncidenceBase();
53 53
54 virtual QCString type() const = 0; 54 virtual QCString type() const = 0;
55 virtual IncTypeID typeID() const = 0; 55 virtual IncTypeID typeID() const = 0;
56 56
57 /** Set the unique id for the event */ 57 /** Set the unique id for the event */
58 void setUid(const QString &); 58 void setUid(const QString &);
59 /** Return the unique id for the event */ 59 /** Return the unique id for the event */
60 QString uid() const; 60 QString uid() const;
61 61
62 /** Sets the time the incidence was last modified. */ 62 /** Sets the time the incidence was last modified. */
63 void setLastModified(const QDateTime &lm); 63 void setLastModified(const QDateTime &lm);
64 /** Return the time the incidence was last modified. */ 64 /** Return the time the incidence was last modified. */
65 QDateTime lastModified() const; 65 QDateTime lastModified() const;
66 QString lastModifiedSortKey() const;
66 67
67 /** sets the organizer for the event */ 68 /** sets the organizer for the event */
68 void setOrganizer(const QString &o); 69 void setOrganizer(const QString &o);
69 QString organizer() const; 70 QString organizer() const;
70 71
71 /** Set readonly status. */ 72 /** Set readonly status. */
72 virtual void setReadOnly( bool ); 73 virtual void setReadOnly( bool );
73 /** Return if the object is read-only. */ 74 /** Return if the object is read-only. */
74 bool isReadOnly() const { return mReadOnly; } 75 bool isReadOnly() const { return mReadOnly; }
75 76
76 /** for setting the event's starting date/time with a QDateTime. */ 77 /** for setting the event's starting date/time with a QDateTime. */
77 virtual void setDtStart(const QDateTime &dtStart); 78 virtual void setDtStart(const QDateTime &dtStart);
78 /** returns an event's starting date/time as a QDateTime. */ 79 /** returns an event's starting date/time as a QDateTime. */
79 virtual QDateTime dtStart() const; 80 virtual QDateTime dtStart() const;
80 /** returns an event's starting time as a string formatted according to the 81 /** returns an event's starting time as a string formatted according to the
81 users locale settings */ 82 users locale settings */
82 QString dtStartTimeStr() const; 83 QString dtStartTimeStr() const;
83 /** returns an event's starting date as a string formatted according to the 84 /** returns an event's starting date as a string formatted according to the
84 users locale settings */ 85 users locale settings */
85 QString dtStartDateStr(bool shortfmt=true) const; 86 QString dtStartDateStr(bool shortfmt=true) const;
86 /** returns an event's starting date and time as a string formatted according 87 /** returns an event's starting date and time as a string formatted according
87 to the users locale settings */ 88 to the users locale settings */
88 QString dtStartStr(bool shortfmt=true) const; 89 QString dtStartStr(bool shortfmt=true) const;
89 90
90 virtual void setDuration(int seconds); 91 virtual void setDuration(int seconds);
91 int duration() const; 92 int duration() const;
92 void setHasDuration(bool); 93 void setHasDuration(bool);
93 bool hasDuration() const; 94 bool hasDuration() const;
94 95
95 /** Return true or false depending on whether the incidence "floats," 96 /** Return true or false depending on whether the incidence "floats,"
96 * i.e. has a date but no time attached to it. */ 97 * i.e. has a date but no time attached to it. */
97 bool doesFloat() const; 98 bool doesFloat() const;
98 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 99 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
99 void setFloats(bool f); 100 void setFloats(bool f);
100 101
101 /** 102 /**
102 Add Attendee to this incidence. IncidenceBase takes ownership of the 103 Add Attendee to this incidence. IncidenceBase takes ownership of the
103 Attendee object. 104 Attendee object.
104 */ 105 */
105 bool addAttendee(Attendee *a, bool doupdate=true ); 106 bool addAttendee(Attendee *a, bool doupdate=true );
106// void removeAttendee(Attendee *a); 107// void removeAttendee(Attendee *a);
107// void removeAttendee(const char *n); 108// void removeAttendee(const char *n);
108 /** Remove all Attendees. */ 109 /** Remove all Attendees. */
109 void clearAttendees(); 110 void clearAttendees();
110 /** Return list of attendees. */ 111 /** Return list of attendees. */
111 QPtrList<Attendee> attendees() const { return mAttendees; }; 112 QPtrList<Attendee> attendees() const { return mAttendees; };
112 /** Return number of attendees. */ 113 /** Return number of attendees. */
113 int attendeeCount() const { return mAttendees.count(); }; 114 int attendeeCount() const { return mAttendees.count(); };
114 /** Return the Attendee with this email */ 115 /** Return the Attendee with this email */
115 Attendee* attendeeByMail(const QString &); 116 Attendee* attendeeByMail(const QString &);
116 /** Return first Attendee with one of this emails */ 117 /** Return first Attendee with one of this emails */
117 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 118 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
118 119
119 /** pilot syncronization states */ 120 /** pilot syncronization states */
120 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 121 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
121 /** Set synchronisation satus. */ 122 /** Set synchronisation satus. */
122 void setSyncStatus(int stat); 123 void setSyncStatus(int stat);
123 /** Return synchronisation status. */ 124 /** Return synchronisation status. */
124 int syncStatus() const; 125 int syncStatus() const;
125 126
126 /** Set Pilot Id. */ 127 /** Set Pilot Id. */
127 void setPilotId(int id); 128 void setPilotId(int id);
128 /** Return Pilot Id. */ 129 /** Return Pilot Id. */
129 int pilotId() const; 130 int pilotId() const;
130 131
131 void setTempSyncStat(int id); 132 void setTempSyncStat(int id);
132 int tempSyncStat() const; 133 int tempSyncStat() const;
133 void setIDStr( const QString & ); 134 void setIDStr( const QString & );
134 QString IDStr() const; 135 QString IDStr() const;
135 void setID( const QString &, const QString & ); 136 void setID( const QString &, const QString & );
136 QString getID( const QString & ); 137 QString getID( const QString & );
137 void setCsum( const QString &, const QString & ); 138 void setCsum( const QString &, const QString & );
138 QString getCsum( const QString & ); 139 QString getCsum( const QString & );
139 void removeID(const QString &); 140 void removeID(const QString &);
140 141
141 void registerObserver( Observer * ); 142 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 143 void unRegisterObserver( Observer * );
143 void updated(); 144 void updated();
144 void setCalID( int id ); 145 void setCalID( int id );
145 int calID() const; 146 int calID() const;
146 void setCalEnabled( bool ); 147 void setCalEnabled( bool );
147 bool calEnabled() const; 148 bool calEnabled() const;
148 void setAlarmEnabled( bool ); 149 void setAlarmEnabled( bool );
149 bool alarmEnabled() const; 150 bool alarmEnabled() const;
150 bool isTagged() const; 151 bool isTagged() const;
151 void setTagged( bool ); 152 void setTagged( bool );
152 virtual void setLastModifiedSubInvalid(); 153 virtual void setLastModifiedSubInvalid();
153 protected: 154 protected:
154 bool blockLastModified; 155 bool blockLastModified;
155 bool mIsTagged; 156 bool mIsTagged;
156 QDateTime mDtStart; 157 QDateTime mDtStart;
157 bool mReadOnly; 158 bool mReadOnly;
158 QDateTime getEvenTime( QDateTime ); 159 QDateTime getEvenTime( QDateTime );
159 160
160 private: 161 private:
161 // base components 162 // base components
162 QString mOrganizer; 163 QString mOrganizer;
164 QString mLastModifiedKey;
163 QString mUid; 165 QString mUid;
164 int mCalID; 166 int mCalID;
165 bool mCalEnabled; 167 bool mCalEnabled;
166 bool mAlarmEnabled; 168 bool mAlarmEnabled;
167 QDateTime mLastModified; 169 QDateTime mLastModified;
168 QPtrList<Attendee> mAttendees; 170 QPtrList<Attendee> mAttendees;
169 171
170 bool mFloats; 172 bool mFloats;
171 173
172 int mDuration; 174 int mDuration;
173 bool mHasDuration; 175 bool mHasDuration;
174 QString mExternalId; 176 QString mExternalId;
175 int mTempSyncStat; 177 int mTempSyncStat;
176 178
177 // PILOT SYNCHRONIZATION STUFF 179 // PILOT SYNCHRONIZATION STUFF
178 int mPilotId; // unique id for pilot sync 180 int mPilotId; // unique id for pilot sync
179 int mSyncStatus; // status (for sync) 181 int mSyncStatus; // status (for sync)
180 182
181 QPtrList<Observer> mObservers; 183 QPtrList<Observer> mObservers;
182}; 184};
183 185
184bool operator==( const IncidenceBase&, const IncidenceBase& ); 186bool operator==( const IncidenceBase&, const IncidenceBase& );
185} 187}
186 188
187#endif 189#endif