summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-13 11:55:52 (UTC)
committer zautrix <zautrix>2005-02-13 11:55:52 (UTC)
commit0a33f91e166747406ca2ccb5819881feeecfdb40 (patch) (unidiff)
treee9130a16aaa6365e106d6733c3e1adeca01f72ac
parent00ec9899a4727a4c9100d320935dde7da4803801 (diff)
downloadkdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.zip
kdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.tar.gz
kdepimpi-0a33f91e166747406ca2ccb5819881feeecfdb40.tar.bz2
todo recurchanges
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorgeneraltodo.cpp2
-rw-r--r--korganizer/koeditorgeneraltodo.h1
-rw-r--r--korganizer/koeditorrecurrence.cpp20
-rw-r--r--korganizer/koeditorrecurrence.h4
-rw-r--r--korganizer/kotodoeditor.cpp47
-rw-r--r--korganizer/kotodoeditor.h4
-rw-r--r--libkcal/icalformatimpl.cpp10
-rw-r--r--libkcal/incidence.cpp35
-rw-r--r--libkcal/incidence.h9
-rw-r--r--microkde/kdialogbase.h2
10 files changed, 121 insertions, 13 deletions
diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp
index 6370b54..a9d1ed3 100644
--- a/korganizer/koeditorgeneraltodo.cpp
+++ b/korganizer/koeditorgeneraltodo.cpp
@@ -1,497 +1,499 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33 33
34#include <kglobal.h> 34#include <kglobal.h>
35#include <klocale.h> 35#include <klocale.h>
36#include <kiconloader.h> 36#include <kiconloader.h>
37#include <kmessagebox.h> 37#include <kmessagebox.h>
38#include <kdebug.h> 38#include <kdebug.h>
39#include <krestrictedline.h> 39#include <krestrictedline.h>
40#include <kstandarddirs.h> 40#include <kstandarddirs.h>
41#include <kfiledialog.h> 41#include <kfiledialog.h>
42 42
43#include <libkcal/todo.h> 43#include <libkcal/todo.h>
44 44
45#include <libkdepim/kdateedit.h> 45#include <libkdepim/kdateedit.h>
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48#include "ktimeedit.h" 48#include "ktimeedit.h"
49 49
50#include "koeditorgeneraltodo.h" 50#include "koeditorgeneraltodo.h"
51#include "kolocationbox.h" 51#include "kolocationbox.h"
52 52
53KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent, 53KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent,
54 const char* name) 54 const char* name)
55 : KOEditorGeneral( parent, name) 55 : KOEditorGeneral( parent, name)
56{ 56{
57} 57}
58 58
59KOEditorGeneralTodo::~KOEditorGeneralTodo() 59KOEditorGeneralTodo::~KOEditorGeneralTodo()
60{ 60{
61} 61}
62 62
63void KOEditorGeneralTodo::finishSetup() 63void KOEditorGeneralTodo::finishSetup()
64{ 64{
65 65
66// QWidget::setTabOrder(mSummaryEdit, mLocationEdit); 66// QWidget::setTabOrder(mSummaryEdit, mLocationEdit);
67// QWidget::setTabOrder(mLocationEdit, mDueCheck); 67// QWidget::setTabOrder(mLocationEdit, mDueCheck);
68// QWidget::setTabOrder(mDueCheck, mDueDateEdit); 68// QWidget::setTabOrder(mDueCheck, mDueDateEdit);
69// QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit); 69// QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit);
70// QWidget::setTabOrder(mDueTimeEdit, mStartCheck); 70// QWidget::setTabOrder(mDueTimeEdit, mStartCheck);
71// QWidget::setTabOrder(mStartCheck, mStartDateEdit); 71// QWidget::setTabOrder(mStartCheck, mStartDateEdit);
72// QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit); 72// QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit);
73// QWidget::setTabOrder(mStartTimeEdit, mTimeButton); 73// QWidget::setTabOrder(mStartTimeEdit, mTimeButton);
74// QWidget::setTabOrder(mTimeButton, mCompletedCombo); 74// QWidget::setTabOrder(mTimeButton, mCompletedCombo);
75// QWidget::setTabOrder(mCompletedCombo, mPriorityCombo); 75// QWidget::setTabOrder(mCompletedCombo, mPriorityCombo);
76// QWidget::setTabOrder(mPriorityCombo, mAlarmButton); 76// QWidget::setTabOrder(mPriorityCombo, mAlarmButton);
77// QWidget::setTabOrder(mAlarmButton, mCategoriesButton); 77// QWidget::setTabOrder(mAlarmButton, mCategoriesButton);
78// QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo); 78// QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo);
79// QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit); 79// QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit);
80 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 80 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
81 mSummaryEdit->setFocus(); 81 mSummaryEdit->setFocus();
82} 82}
83 83
84void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout) 84void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout)
85{ 85{
86 QBoxLayout *timeLayout = new QVBoxLayout(topLayout); 86 QBoxLayout *timeLayout = new QVBoxLayout(topLayout);
87 87
88 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal, 88 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal,
89 i18n("Date && Time"),parent); 89 i18n("Date && Time"),parent);
90 timeLayout->addWidget(timeGroupBox); 90 timeLayout->addWidget(timeGroupBox);
91 timeGroupBox->layout()->setSpacing( 0 ); 91 timeGroupBox->layout()->setSpacing( 0 );
92 timeGroupBox->layout()->setMargin( 5 ); 92 timeGroupBox->layout()->setMargin( 5 );
93 QFrame *timeBoxFrame = new QFrame(timeGroupBox); 93 QFrame *timeBoxFrame = new QFrame(timeGroupBox);
94 94
95 QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3); 95 QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3);
96 layoutTimeBox->setSpacing(topLayout->spacing()); 96 layoutTimeBox->setSpacing(topLayout->spacing());
97 layoutTimeBox->setColStretch( 1, 1 ); 97 layoutTimeBox->setColStretch( 1, 1 );
98 98
99 mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame); 99 mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame);
100 layoutTimeBox->addWidget(mDueCheck,0,0); 100 layoutTimeBox->addWidget(mDueCheck,0,0);
101 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool))); 101 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool)));
102 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm())); 102 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm()));
103 103
104 104
105 mDueDateEdit = new KDateEdit(timeBoxFrame); 105 mDueDateEdit = new KDateEdit(timeBoxFrame);
106 layoutTimeBox->addWidget(mDueDateEdit,0,1); 106 layoutTimeBox->addWidget(mDueDateEdit,0,1);
107 107
108 mDueTimeEdit = new KOTimeEdit(timeBoxFrame); 108 mDueTimeEdit = new KOTimeEdit(timeBoxFrame);
109 layoutTimeBox->addWidget(mDueTimeEdit,0,2); 109 layoutTimeBox->addWidget(mDueTimeEdit,0,2);
110 110
111 111
112 mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame); 112 mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame);
113 layoutTimeBox->addWidget(mStartCheck,1,0); 113 layoutTimeBox->addWidget(mStartCheck,1,0);
114 connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool))); 114 connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool)));
115 115
116 mStartDateEdit = new KDateEdit(timeBoxFrame); 116 mStartDateEdit = new KDateEdit(timeBoxFrame);
117 layoutTimeBox->addWidget(mStartDateEdit,1,1); 117 layoutTimeBox->addWidget(mStartDateEdit,1,1);
118 118
119 mStartTimeEdit = new KOTimeEdit(timeBoxFrame); 119 mStartTimeEdit = new KOTimeEdit(timeBoxFrame);
120 layoutTimeBox->addWidget(mStartTimeEdit,1,2); 120 layoutTimeBox->addWidget(mStartTimeEdit,1,2);
121 121
122 122
123 mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame); 123 mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame);
124 layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1); 124 layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1);
125 125
126 connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool))); 126 connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool)));
127 127
128 // some more layouting 128 // some more layouting
129 //layoutTimeBox->setColStretch(3,1); 129 //layoutTimeBox->setColStretch(3,1);
130} 130}
131 131
132 132
133void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout) 133void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout)
134{ 134{
135 mCompletedCombo = new QComboBox(parent); 135 mCompletedCombo = new QComboBox(parent);
136 // xgettext:no-c-format 136 // xgettext:no-c-format
137 mCompletedCombo->insertItem(i18n(" 0 %")); 137 mCompletedCombo->insertItem(i18n(" 0 %"));
138 // xgettext:no-c-format 138 // xgettext:no-c-format
139 mCompletedCombo->insertItem(i18n(" 20 %")); 139 mCompletedCombo->insertItem(i18n(" 20 %"));
140 // xgettext:no-c-format 140 // xgettext:no-c-format
141 mCompletedCombo->insertItem(i18n(" 40 %")); 141 mCompletedCombo->insertItem(i18n(" 40 %"));
142 // xgettext:no-c-format 142 // xgettext:no-c-format
143 mCompletedCombo->insertItem(i18n(" 60 %")); 143 mCompletedCombo->insertItem(i18n(" 60 %"));
144 // xgettext:no-c-format 144 // xgettext:no-c-format
145 mCompletedCombo->insertItem(i18n(" 80 %")); 145 mCompletedCombo->insertItem(i18n(" 80 %"));
146 // xgettext:no-c-format 146 // xgettext:no-c-format
147 mCompletedCombo->insertItem(i18n("100 %")); 147 mCompletedCombo->insertItem(i18n("100 %"));
148 connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int))); 148 connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int)));
149 topLayout->addWidget(mCompletedCombo); 149 topLayout->addWidget(mCompletedCombo);
150 150
151 mCompletedLabel = new QLabel(i18n("completed"),parent); 151 mCompletedLabel = new QLabel(i18n("completed"),parent);
152 topLayout->addWidget(mCompletedLabel); 152 topLayout->addWidget(mCompletedLabel);
153 153
154 mCompleteDateEdit = new KDateEdit(parent); 154 mCompleteDateEdit = new KDateEdit(parent);
155 topLayout->addWidget(mCompleteDateEdit ); 155 topLayout->addWidget(mCompleteDateEdit );
156 156
157 mCompleteTimeEdit = new KOTimeEdit(parent); 157 mCompleteTimeEdit = new KOTimeEdit(parent);
158 topLayout->addWidget( mCompleteTimeEdit); 158 topLayout->addWidget( mCompleteTimeEdit);
159 159
160 mCompletedCombo->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,QSizePolicy::Preferred) ); 160 mCompletedCombo->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,QSizePolicy::Preferred) );
161 mCompletedLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Preferred) ); 161 mCompletedLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Preferred) );
162 162
163 if ( QApplication::desktop()->width() <= 480 ) { 163 if ( QApplication::desktop()->width() <= 480 ) {
164 if ( QApplication::desktop()->width() < 320 ) 164 if ( QApplication::desktop()->width() < 320 )
165 mCompleteDateEdit->setMaximumWidth( 85 ); 165 mCompleteDateEdit->setMaximumWidth( 85 );
166 else 166 else
167 mCompleteDateEdit->setMaximumWidth( 140 ); 167 mCompleteDateEdit->setMaximumWidth( 140 );
168 topLayout->setSpacing( 0 ); 168 topLayout->setSpacing( 0 );
169 } 169 }
170} 170}
171 171
172void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout) 172void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout)
173{ 173{
174 174
175 QHBox* h = new QHBox ( parent ); 175 QHBox* h = new QHBox ( parent );
176 topLayout->addWidget( h ); 176 topLayout->addWidget( h );
177 QLabel *priorityLabel = new QLabel(i18n("Priority:"), h); 177 QLabel *priorityLabel = new QLabel(i18n("Priority:"), h);
178 // topLayout->addWidget(priorityLabel); 178 // topLayout->addWidget(priorityLabel);
179 mPriorityCombo = new QComboBox( h ); 179 mPriorityCombo = new QComboBox( h );
180 mPriorityCombo->insertItem(i18n("1 (high)")); 180 mPriorityCombo->insertItem(i18n("1 (high)"));
181 mPriorityCombo->insertItem(i18n("2")); 181 mPriorityCombo->insertItem(i18n("2"));
182 mPriorityCombo->insertItem(i18n("3")); 182 mPriorityCombo->insertItem(i18n("3"));
183 mPriorityCombo->insertItem(i18n("4")); 183 mPriorityCombo->insertItem(i18n("4"));
184 mPriorityCombo->insertItem(i18n("5 (low)")); 184 mPriorityCombo->insertItem(i18n("5 (low)"));
185 //topLayout->addWidget(mPriorityCombo); 185 //topLayout->addWidget(mPriorityCombo);
186} 186}
187 187
188void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout) 188void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout)
189{ 189{
190 QBoxLayout *statusLayout = new QHBoxLayout(topLayout); 190 QBoxLayout *statusLayout = new QHBoxLayout(topLayout);
191 191
192 initCompletion( parent, statusLayout ); 192 initCompletion( parent, statusLayout );
193 193
194 statusLayout->addStretch( 1 ); 194 statusLayout->addStretch( 1 );
195 195
196 initPriority( parent, statusLayout ); 196 initPriority( parent, statusLayout );
197} 197}
198 198
199void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay) 199void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay)
200{ 200{
201 201
202 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 202 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
203 mLocationEdit->load(KOLocationBox::LOCATION); 203 mLocationEdit->load(KOLocationBox::LOCATION);
204 KOEditorGeneral::setDefaults(allDay); 204 KOEditorGeneral::setDefaults(allDay);
205 205
206 mTimeButton->setChecked( !allDay ); 206 mTimeButton->setChecked( !allDay );
207 if(mTimeButton->isChecked()) { 207 if(mTimeButton->isChecked()) {
208 mTimeButton->setEnabled(true); 208 mTimeButton->setEnabled(true);
209 } 209 }
210 else { 210 else {
211 mTimeButton->setEnabled(false); 211 mTimeButton->setEnabled(false);
212 } 212 }
213 213
214 enableTimeEdits( !allDay ); 214 enableTimeEdits( !allDay );
215 if ( due.isValid() ) { 215 if ( due.isValid() ) {
216 mDueCheck->setChecked(true); 216 mDueCheck->setChecked(true);
217 enableDueEdit(true); 217 enableDueEdit(true);
218 } else { 218 } else {
219 mDueCheck->setChecked(false); 219 mDueCheck->setChecked(false);
220 enableDueEdit(false); 220 enableDueEdit(false);
221 due = QDateTime::currentDateTime().addDays(7); 221 due = QDateTime::currentDateTime().addDays(7);
222 } 222 }
223 223
224 alarmDisable(true); 224 alarmDisable(true);
225 225
226 mStartCheck->setChecked(false); 226 mStartCheck->setChecked(false);
227 enableStartEdit(false); 227 enableStartEdit(false);
228 228
229 mDueDateEdit->setDate(due.date()); 229 mDueDateEdit->setDate(due.date());
230 mDueTimeEdit->setTime(due.time()); 230 mDueTimeEdit->setTime(due.time());
231 due = due.addDays(-7); 231 due = due.addDays(-7);
232 mStartDateEdit->setDate(due.date()); 232 mStartDateEdit->setDate(due.date());
233 mStartTimeEdit->setTime(due.time()); 233 mStartTimeEdit->setTime(due.time());
234 234
235 mPriorityCombo->setCurrentItem(2); 235 mPriorityCombo->setCurrentItem(2);
236 mCompletedLabel->setText(i18n(" completed"));; 236 mCompletedLabel->setText(i18n(" completed"));;
237 mCompletedCombo->setCurrentItem(0); 237 mCompletedCombo->setCurrentItem(0);
238 mCompleteDateEdit->hide(); 238 mCompleteDateEdit->hide();
239 mCompleteTimeEdit->hide(); 239 mCompleteTimeEdit->hide();
240} 240}
241 241
242void KOEditorGeneralTodo::readTodo(Todo *todo) 242void KOEditorGeneralTodo::readTodo(Todo *todo)
243{ 243{
244 244
245 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 245 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
246 mLocationEdit->load(KOLocationBox::LOCATION); 246 mLocationEdit->load(KOLocationBox::LOCATION);
247 KOEditorGeneral::readIncidence(todo); 247 KOEditorGeneral::readIncidence(todo);
248 248
249 QDateTime dueDT; 249 QDateTime dueDT;
250 250
251 if (todo->hasDueDate()) { 251 if (todo->hasDueDate()) {
252 enableAlarmEdit(true); 252 enableAlarmEdit(true);
253 dueDT = todo->dtDue(); 253 dueDT = todo->dtDue();
254 mDueDateEdit->setDate(todo->dtDue().date()); 254 mDueDateEdit->setDate(todo->dtDue().date());
255 mDueTimeEdit->setTime(todo->dtDue().time()); 255 mDueTimeEdit->setTime(todo->dtDue().time());
256 mDueCheck->setChecked(true); 256 mDueCheck->setChecked(true);
257 } else { 257 } else {
258 alarmDisable(true); 258 alarmDisable(true);
259 mDueDateEdit->setEnabled(false); 259 mDueDateEdit->setEnabled(false);
260 mDueTimeEdit->setEnabled(false); 260 mDueTimeEdit->setEnabled(false);
261 mDueDateEdit->setDate(QDate::currentDate()); 261 mDueDateEdit->setDate(QDate::currentDate());
262 mDueTimeEdit->setTime(QTime::currentTime()); 262 mDueTimeEdit->setTime(QTime::currentTime());
263 mDueCheck->setChecked(false); 263 mDueCheck->setChecked(false);
264 } 264 }
265 265
266 if (todo->hasStartDate()) { 266 if (todo->hasStartDate()) {
267 mStartDateEdit->setDate(todo->dtStart().date()); 267 mStartDateEdit->setDate(todo->dtStart().date());
268 mStartTimeEdit->setTime(todo->dtStart().time()); 268 mStartTimeEdit->setTime(todo->dtStart().time());
269 mStartCheck->setChecked(true); 269 mStartCheck->setChecked(true);
270 } else { 270 } else {
271 mStartDateEdit->setEnabled(false); 271 mStartDateEdit->setEnabled(false);
272 mStartTimeEdit->setEnabled(false); 272 mStartTimeEdit->setEnabled(false);
273 mStartDateEdit->setDate(QDate::currentDate()); 273 mStartDateEdit->setDate(QDate::currentDate());
274 mStartTimeEdit->setTime(QTime::currentTime()); 274 mStartTimeEdit->setTime(QTime::currentTime());
275 mStartCheck->setChecked(false); 275 mStartCheck->setChecked(false);
276 } 276 }
277 277
278 mTimeButton->setChecked( !todo->doesFloat() ); 278 mTimeButton->setChecked( !todo->doesFloat() );
279 279
280 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); 280 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
281 if (todo->isCompleted() && todo->hasCompletedDate()) { 281 if (todo->isCompleted() && todo->hasCompletedDate()) {
282 mCompleted = todo->completed(); 282 mCompleted = todo->completed();
283 } 283 }
284 setCompletedDate(); 284 setCompletedDate();
285 285
286 mPriorityCombo->setCurrentItem(todo->priority()-1); 286 mPriorityCombo->setCurrentItem(todo->priority()-1);
287} 287}
288 288
289void KOEditorGeneralTodo::writeTodo(Todo *todo) 289void KOEditorGeneralTodo::writeTodo(Todo *todo)
290{ 290{
291 KOEditorGeneral::writeIncidence(todo); 291 KOEditorGeneral::writeIncidence(todo);
292 292
293 // temp. until something better happens. 293 // temp. until something better happens.
294 QString tmpStr; 294 QString tmpStr;
295 295
296 todo->setHasDueDate(mDueCheck->isChecked()); 296 todo->setHasDueDate(mDueCheck->isChecked());
297 todo->setHasStartDate(mStartCheck->isChecked()); 297 todo->setHasStartDate(mStartCheck->isChecked());
298 298
299 QDate tmpDate; 299 QDate tmpDate;
300 QTime tmpTime; 300 QTime tmpTime;
301 QDateTime tmpDT; 301 QDateTime tmpDT;
302 if ( mTimeButton->isChecked() ) { 302 if ( mTimeButton->isChecked() ) {
303 todo->setFloats(false); 303 todo->setFloats(false);
304 304
305 // set due date/time 305 // set due date/time
306 tmpDate = mDueDateEdit->date(); 306 tmpDate = mDueDateEdit->date();
307 tmpTime = mDueTimeEdit->getTime(); 307 tmpTime = mDueTimeEdit->getTime();
308 tmpDT.setDate(tmpDate); 308 tmpDT.setDate(tmpDate);
309 tmpDT.setTime(tmpTime); 309 tmpDT.setTime(tmpTime);
310 todo->setDtDue(tmpDT); 310 todo->setDtDue(tmpDT);
311 311
312 // set start date/time 312 // set start date/time
313 tmpDate = mStartDateEdit->date(); 313 tmpDate = mStartDateEdit->date();
314 tmpTime = mStartTimeEdit->getTime(); 314 tmpTime = mStartTimeEdit->getTime();
315 tmpDT.setDate(tmpDate); 315 tmpDT.setDate(tmpDate);
316 tmpDT.setTime(tmpTime); 316 tmpDT.setTime(tmpTime);
317 todo->setDtStart(tmpDT); 317 todo->setDtStart(tmpDT);
318 } else { 318 } else {
319 todo->setFloats(true); 319 todo->setFloats(true);
320 320
321 // need to change this. 321 // need to change this.
322 tmpDate = mDueDateEdit->date(); 322 tmpDate = mDueDateEdit->date();
323 tmpTime.setHMS(0,0,0); 323 tmpTime.setHMS(0,0,0);
324 tmpDT.setDate(tmpDate); 324 tmpDT.setDate(tmpDate);
325 tmpDT.setTime(tmpTime); 325 tmpDT.setTime(tmpTime);
326 todo->setDtDue(tmpDT); 326 todo->setDtDue(tmpDT);
327 327
328 tmpDate = mStartDateEdit->date(); 328 tmpDate = mStartDateEdit->date();
329 tmpTime.setHMS(0,0,0); 329 tmpTime.setHMS(0,0,0);
330 tmpDT.setDate(tmpDate); 330 tmpDT.setDate(tmpDate);
331 tmpDT.setTime(tmpTime); 331 tmpDT.setTime(tmpTime);
332 todo->setDtStart(tmpDT); 332 todo->setDtStart(tmpDT);
333 } 333 }
334 todo->setPriority(mPriorityCombo->currentItem()+1); 334 todo->setPriority(mPriorityCombo->currentItem()+1);
335 335
336 // set completion state 336 // set completion state
337 if ( mCompletedCombo->currentItem() == 5 ) { 337 if ( mCompletedCombo->currentItem() == 5 ) {
338 QDateTime comp ( mCompleteDateEdit->date(), mCompleteTimeEdit->getTime() ); 338 QDateTime comp ( mCompleteDateEdit->date(), mCompleteTimeEdit->getTime() );
339 if ( comp.isValid () ) { 339 if ( comp.isValid () ) {
340 todo->setPercentComplete(0); 340 todo->setPercentComplete(0);
341 todo->setPercentComplete(100); 341 todo->setPercentComplete(100);
342 todo->setCompleted(comp); 342 todo->setCompleted(comp);
343 } else { 343 } else {
344 todo->setPercentComplete( 100 ); 344 todo->setPercentComplete( 100 );
345 if ( mCompleted.isValid() ) 345 if ( mCompleted.isValid() )
346 todo->setCompleted(mCompleted); 346 todo->setCompleted(mCompleted);
347 } 347 }
348 } else { 348 } else {
349 todo->setPercentComplete(mCompletedCombo->currentItem() * 20); 349 todo->setPercentComplete(mCompletedCombo->currentItem() * 20);
350 } 350 }
351 351
352 mSummaryEdit->save(KOLocationBox::SUMMARYTODO); 352 mSummaryEdit->save(KOLocationBox::SUMMARYTODO);
353} 353}
354 354
355void KOEditorGeneralTodo::enableDueEdit(bool enable) 355void KOEditorGeneralTodo::enableDueEdit(bool enable)
356{ 356{
357 mDueDateEdit->setEnabled( enable ); 357 mDueDateEdit->setEnabled( enable );
358 358
359 if(mDueCheck->isChecked() || mStartCheck->isChecked()) { 359 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
360 mTimeButton->setEnabled(true); 360 mTimeButton->setEnabled(true);
361 } 361 }
362 else { 362 else {
363 mTimeButton->setEnabled(false); 363 mTimeButton->setEnabled(false);
364 mTimeButton->setChecked(false); 364 mTimeButton->setChecked(false);
365 } 365 }
366 366
367 if (enable) { 367 if (enable) {
368 mDueTimeEdit->setEnabled( mTimeButton->isChecked() ); 368 mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
369 } else { 369 } else {
370 mDueTimeEdit->setEnabled( false ); 370 mDueTimeEdit->setEnabled( false );
371 } 371 }
372 emit datesChecked();
372} 373}
373 374
374void KOEditorGeneralTodo::enableStartEdit( bool enable ) 375void KOEditorGeneralTodo::enableStartEdit( bool enable )
375{ 376{
376 mStartDateEdit->setEnabled( enable ); 377 mStartDateEdit->setEnabled( enable );
377 378
378 if(mDueCheck->isChecked() || mStartCheck->isChecked()) { 379 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
379 mTimeButton->setEnabled(true); 380 mTimeButton->setEnabled(true);
380 } 381 }
381 else { 382 else {
382 mTimeButton->setEnabled(false); 383 mTimeButton->setEnabled(false);
383 mTimeButton->setChecked(false); 384 mTimeButton->setChecked(false);
384 } 385 }
385 386
386 if (enable) { 387 if (enable) {
387 mStartTimeEdit->setEnabled( mTimeButton->isChecked() ); 388 mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
388 } else { 389 } else {
389 mStartTimeEdit->setEnabled( false ); 390 mStartTimeEdit->setEnabled( false );
390 } 391 }
392 emit datesChecked();
391} 393}
392 394
393void KOEditorGeneralTodo::enableTimeEdits(bool enable) 395void KOEditorGeneralTodo::enableTimeEdits(bool enable)
394{ 396{
395 if(mStartCheck->isChecked()) { 397 if(mStartCheck->isChecked()) {
396 mStartTimeEdit->setEnabled( enable ); 398 mStartTimeEdit->setEnabled( enable );
397 } 399 }
398 if(mDueCheck->isChecked()) { 400 if(mDueCheck->isChecked()) {
399 mDueTimeEdit->setEnabled( enable ); 401 mDueTimeEdit->setEnabled( enable );
400 } 402 }
401} 403}
402 404
403void KOEditorGeneralTodo::showAlarm() 405void KOEditorGeneralTodo::showAlarm()
404{ 406{
405 if ( mDueCheck->isChecked() ) { 407 if ( mDueCheck->isChecked() ) {
406 alarmDisable(false); 408 alarmDisable(false);
407 } 409 }
408 else { 410 else {
409 alarmDisable(true); 411 alarmDisable(true);
410 } 412 }
411} 413}
412 414
413bool KOEditorGeneralTodo::validateInput() 415bool KOEditorGeneralTodo::validateInput()
414{ 416{
415 if (mDueCheck->isChecked()) { 417 if (mDueCheck->isChecked()) {
416 if (!mDueDateEdit->inputIsValid()) { 418 if (!mDueDateEdit->inputIsValid()) {
417 KMessageBox::sorry(0,i18n("Please specify a valid due date.")); 419 KMessageBox::sorry(0,i18n("Please specify a valid due date."));
418 return false; 420 return false;
419 } 421 }
420 } 422 }
421 423
422 if (mStartCheck->isChecked()) { 424 if (mStartCheck->isChecked()) {
423 if (!mStartDateEdit->inputIsValid()) { 425 if (!mStartDateEdit->inputIsValid()) {
424 KMessageBox::sorry(0,i18n("Please specify a valid start date.")); 426 KMessageBox::sorry(0,i18n("Please specify a valid start date."));
425 return false; 427 return false;
426 } 428 }
427 } 429 }
428 430
429 if (mStartCheck->isChecked() && mDueCheck->isChecked()) { 431 if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
430 QDateTime startDate; 432 QDateTime startDate;
431 QDateTime dueDate; 433 QDateTime dueDate;
432 startDate.setDate(mStartDateEdit->date()); 434 startDate.setDate(mStartDateEdit->date());
433 dueDate.setDate(mDueDateEdit->date()); 435 dueDate.setDate(mDueDateEdit->date());
434 if (mTimeButton->isChecked()) { 436 if (mTimeButton->isChecked()) {
435 startDate.setTime(mStartTimeEdit->getTime()); 437 startDate.setTime(mStartTimeEdit->getTime());
436 dueDate.setTime(mDueTimeEdit->getTime()); 438 dueDate.setTime(mDueTimeEdit->getTime());
437 } 439 }
438 if (startDate > dueDate) { 440 if (startDate > dueDate) {
439 KMessageBox::sorry(0, 441 KMessageBox::sorry(0,
440 i18n("The start date cannot be after the due date.")); 442 i18n("The start date cannot be after the due date."));
441 return false; 443 return false;
442 } 444 }
443 } 445 }
444 446
445 return KOEditorGeneral::validateInput(); 447 return KOEditorGeneral::validateInput();
446} 448}
447 449
448void KOEditorGeneralTodo::completedChanged(int index) 450void KOEditorGeneralTodo::completedChanged(int index)
449{ 451{
450 if (index == 5) { 452 if (index == 5) {
451 //get rid of milli sec 453 //get rid of milli sec
452 mCompleted = QDateTime::currentDateTime(); 454 mCompleted = QDateTime::currentDateTime();
453 } 455 }
454 setCompletedDate(); 456 setCompletedDate();
455} 457}
456 458
457void KOEditorGeneralTodo::setCompletedDate() 459void KOEditorGeneralTodo::setCompletedDate()
458{ 460{
459 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { 461 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
460 if ( QApplication::desktop()->width() < 480 ) { 462 if ( QApplication::desktop()->width() < 480 ) {
461 mCompletedLabel->setText(i18n(" on")); 463 mCompletedLabel->setText(i18n(" on"));
462 } 464 }
463 else 465 else
464 mCompletedLabel->setText(i18n(" completed on ")); 466 mCompletedLabel->setText(i18n(" completed on "));
465 mCompleteDateEdit->show(); 467 mCompleteDateEdit->show();
466 mCompleteTimeEdit->show(); 468 mCompleteTimeEdit->show();
467 mCompleteTimeEdit->setTime( mCompleted.time() ); 469 mCompleteTimeEdit->setTime( mCompleted.time() );
468 mCompleteDateEdit->setDate( mCompleted.date() ); 470 mCompleteDateEdit->setDate( mCompleted.date() );
469 } else { 471 } else {
470 mCompletedLabel->setText(i18n(" completed")); 472 mCompletedLabel->setText(i18n(" completed"));
471 mCompleteDateEdit->hide(); 473 mCompleteDateEdit->hide();
472 mCompleteTimeEdit->hide(); 474 mCompleteTimeEdit->hide();
473 } 475 }
474} 476}
475 477
476void KOEditorGeneralTodo::modified (Todo* todo, int modification) 478void KOEditorGeneralTodo::modified (Todo* todo, int modification)
477{ 479{
478 switch (modification) { 480 switch (modification) {
479 case KOGlobals::PRIORITY_MODIFIED: 481 case KOGlobals::PRIORITY_MODIFIED:
480 mPriorityCombo->setCurrentItem(todo->priority()-1); 482 mPriorityCombo->setCurrentItem(todo->priority()-1);
481 break; 483 break;
482 case KOGlobals::COMPLETION_MODIFIED: 484 case KOGlobals::COMPLETION_MODIFIED:
483 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); 485 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
484 if (todo->isCompleted() && todo->hasCompletedDate()) { 486 if (todo->isCompleted() && todo->hasCompletedDate()) {
485 mCompleted = todo->completed(); 487 mCompleted = todo->completed();
486 } 488 }
487 setCompletedDate(); 489 setCompletedDate();
488 break; 490 break;
489 case KOGlobals::CATEGORY_MODIFIED: 491 case KOGlobals::CATEGORY_MODIFIED:
490 setCategories (todo->categoriesStr ()); 492 setCategories (todo->categoriesStr ());
491 break; 493 break;
492 case KOGlobals::UNKNOWN_MODIFIED: // fall through 494 case KOGlobals::UNKNOWN_MODIFIED: // fall through
493 default: 495 default:
494 readTodo( todo ); 496 readTodo( todo );
495 break; 497 break;
496 } 498 }
497} 499}
diff --git a/korganizer/koeditorgeneraltodo.h b/korganizer/koeditorgeneraltodo.h
index 98f43dd..b198539 100644
--- a/korganizer/koeditorgeneraltodo.h
+++ b/korganizer/koeditorgeneraltodo.h
@@ -1,108 +1,109 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef _KOEDITORGENERALTODO_H 23#ifndef _KOEDITORGENERALTODO_H
24#define _KOEDITORGENERALTODO_H 24#define _KOEDITORGENERALTODO_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qgroupbox.h> 30#include <qgroupbox.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qmultilineedit.h> 33#include <qmultilineedit.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36 36
37#include "koeditorgeneral.h" 37#include "koeditorgeneral.h"
38#include "koglobals.h" 38#include "koglobals.h"
39 39
40class KRestrictedLine; 40class KRestrictedLine;
41 41
42class KDateEdit; 42class KDateEdit;
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46class KOEditorGeneralTodo : public KOEditorGeneral 46class KOEditorGeneralTodo : public KOEditorGeneral
47{ 47{
48 Q_OBJECT 48 Q_OBJECT
49 public: 49 public:
50 KOEditorGeneralTodo (QObject* parent=0,const char* name=0); 50 KOEditorGeneralTodo (QObject* parent=0,const char* name=0);
51 virtual ~KOEditorGeneralTodo(); 51 virtual ~KOEditorGeneralTodo();
52 52
53 void initTime(QWidget *, QBoxLayout *); 53 void initTime(QWidget *, QBoxLayout *);
54 void initStatus(QWidget *, QBoxLayout *); 54 void initStatus(QWidget *, QBoxLayout *);
55 void initCompletion(QWidget *, QBoxLayout *); 55 void initCompletion(QWidget *, QBoxLayout *);
56 void initPriority(QWidget *, QBoxLayout *); 56 void initPriority(QWidget *, QBoxLayout *);
57 57
58 void finishSetup(); 58 void finishSetup();
59 59
60 /** Set widgets to default values */ 60 /** Set widgets to default values */
61 void setDefaults(QDateTime due,bool allDay); 61 void setDefaults(QDateTime due,bool allDay);
62 /** Read todo object and setup widgets accordingly */ 62 /** Read todo object and setup widgets accordingly */
63 void readTodo(Todo *); 63 void readTodo(Todo *);
64 /** Write todo settings to event object */ 64 /** Write todo settings to event object */
65 void writeTodo(Todo *); 65 void writeTodo(Todo *);
66 66
67 /** Check if the input is valid. */ 67 /** Check if the input is valid. */
68 bool validateInput(); 68 bool validateInput();
69 69
70 /** The todo has been modified externally */ 70 /** The todo has been modified externally */
71 void modified (Todo*, int); 71 void modified (Todo*, int);
72 72
73 signals: 73 signals:
74 void openCategoryDialog(); 74 void openCategoryDialog();
75 void datesChecked();
75 76
76 protected slots: 77 protected slots:
77 void completedChanged(int); 78 void completedChanged(int);
78 79
79 void enableDueEdit( bool enable ); 80 void enableDueEdit( bool enable );
80 void enableStartEdit( bool enable ); 81 void enableStartEdit( bool enable );
81 void enableTimeEdits( bool enable ); 82 void enableTimeEdits( bool enable );
82 void showAlarm(); 83 void showAlarm();
83 84
84 protected: 85 protected:
85 void setCompletedDate(); 86 void setCompletedDate();
86 87
87 private: 88 private:
88 friend class KOTodoEditor; 89 friend class KOTodoEditor;
89 KDateEdit *mStartDateEdit; 90 KDateEdit *mStartDateEdit;
90 KOTimeEdit *mStartTimeEdit; 91 KOTimeEdit *mStartTimeEdit;
91 KDateEdit *mCompleteDateEdit; 92 KDateEdit *mCompleteDateEdit;
92 KOTimeEdit *mCompleteTimeEdit; 93 KOTimeEdit *mCompleteTimeEdit;
93 QCheckBox *mTimeButton; 94 QCheckBox *mTimeButton;
94 QCheckBox *mDueCheck; 95 QCheckBox *mDueCheck;
95 KDateEdit *mDueDateEdit; 96 KDateEdit *mDueDateEdit;
96 KOTimeEdit *mDueTimeEdit; 97 KOTimeEdit *mDueTimeEdit;
97 QComboBox *mCompletedCombo; 98 QComboBox *mCompletedCombo;
98 QLabel *mCompletedLabel; 99 QLabel *mCompletedLabel;
99 QLabel *mPriorityLabel; 100 QLabel *mPriorityLabel;
100 QComboBox *mPriorityCombo; 101 QComboBox *mPriorityCombo;
101 102
102 QCheckBox *mStartCheck; 103 QCheckBox *mStartCheck;
103 104
104 QDateTime mCompleted; 105 QDateTime mCompleted;
105}; 106};
106 107
107 108
108#endif 109#endif
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp
index 4209e10..bedc75a 100644
--- a/korganizer/koeditorrecurrence.cpp
+++ b/korganizer/koeditorrecurrence.cpp
@@ -1,1139 +1,1147 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qlistbox.h> 32#include <qlistbox.h>
33#include <qspinbox.h> 33#include <qspinbox.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qapplication.h> 35#include <qapplication.h>
36 36
37#include <kdialog.h> 37#include <kdialog.h>
38#include <kglobal.h> 38#include <kglobal.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <knumvalidator.h> 42#include <knumvalidator.h>
43 43
44#include <libkcal/event.h> 44#include <libkcal/event.h>
45#include <libkcal/todo.h>
45 46
46#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
47 48
48#include "koprefs.h" 49#include "koprefs.h"
49 50
50#include "koeditorrecurrence.h" 51#include "koeditorrecurrence.h"
51 52
52/////////////////////////// RecurBase /////////////////////////////// 53/////////////////////////// RecurBase ///////////////////////////////
53 54
54RecurBase::RecurBase( QWidget *parent, const char *name ) : 55RecurBase::RecurBase( QWidget *parent, const char *name ) :
55 QWidget( parent, name ) 56 QWidget( parent, name )
56{ 57{
57 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this ); 58 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this );
58 mFrequencyEdit->setValue( 1 ); 59 mFrequencyEdit->setValue( 1 );
59} 60}
60 61
61QWidget *RecurBase::frequencyEdit() 62QWidget *RecurBase::frequencyEdit()
62{ 63{
63 return mFrequencyEdit; 64 return mFrequencyEdit;
64} 65}
65 66
66void RecurBase::setFrequency( int f ) 67void RecurBase::setFrequency( int f )
67{ 68{
68 if ( f < 1 ) f = 1; 69 if ( f < 1 ) f = 1;
69 70
70 mFrequencyEdit->setValue( f ); 71 mFrequencyEdit->setValue( f );
71} 72}
72 73
73int RecurBase::frequency() 74int RecurBase::frequency()
74{ 75{
75 return mFrequencyEdit->value(); 76 return mFrequencyEdit->value();
76} 77}
77 78
78/////////////////////////// RecurDaily /////////////////////////////// 79/////////////////////////// RecurDaily ///////////////////////////////
79 80
80RecurDaily::RecurDaily( QWidget *parent, const char *name ) : 81RecurDaily::RecurDaily( QWidget *parent, const char *name ) :
81 RecurBase( parent, name ) 82 RecurBase( parent, name )
82{ 83{
83 QBoxLayout *topLayout = new QHBoxLayout( this ); 84 QBoxLayout *topLayout = new QHBoxLayout( this );
84 topLayout->setSpacing( KDialog::spacingHint() ); 85 topLayout->setSpacing( KDialog::spacingHint() );
85 86
86 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 87 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
87 topLayout->addWidget( preLabel ); 88 topLayout->addWidget( preLabel );
88 89
89 topLayout->addWidget( frequencyEdit() ); 90 topLayout->addWidget( frequencyEdit() );
90 91
91 QLabel *postLabel = new QLabel( i18n("day(s)"), this ); 92 QLabel *postLabel = new QLabel( i18n("day(s)"), this );
92 topLayout->addWidget( postLabel ); 93 topLayout->addWidget( postLabel );
93} 94}
94 95
95 96
96/////////////////////////// RecurWeekly /////////////////////////////// 97/////////////////////////// RecurWeekly ///////////////////////////////
97 98
98RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) : 99RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) :
99 RecurBase( parent, name ) 100 RecurBase( parent, name )
100{ 101{
101 QBoxLayout *topLayout = new QVBoxLayout( this ); 102 QBoxLayout *topLayout = new QVBoxLayout( this );
102 topLayout->setSpacing( KDialog::spacingHint() ); 103 topLayout->setSpacing( KDialog::spacingHint() );
103 104
104 topLayout->addStretch( 1 ); 105 topLayout->addStretch( 1 );
105 106
106 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout ); 107 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout );
107 108
108 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 109 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
109 weeksLayout->addWidget( preLabel ); 110 weeksLayout->addWidget( preLabel );
110 111
111 weeksLayout->addWidget( frequencyEdit() ); 112 weeksLayout->addWidget( frequencyEdit() );
112 113
113 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this ); 114 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this );
114 weeksLayout->addWidget( postLabel ); 115 weeksLayout->addWidget( postLabel );
115 116
116 QHBox *dayBox = new QHBox( this ); 117 QHBox *dayBox = new QHBox( this );
117 topLayout->addWidget( dayBox, 1, AlignVCenter ); 118 topLayout->addWidget( dayBox, 1, AlignVCenter );
118 // TODO: Respect start of week setting 119 // TODO: Respect start of week setting
119 for ( int i = 0; i < 7; ++i ) { 120 for ( int i = 0; i < 7; ++i ) {
120 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true ); 121 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true );
121 if ( KOPrefs::instance()->mCompactDialogs ) { 122 if ( KOPrefs::instance()->mCompactDialogs ) {
122 weekDayName = weekDayName.left( 1 ); 123 weekDayName = weekDayName.left( 1 );
123 } 124 }
124 mDayBoxes[ i ] = new QCheckBox( weekDayName, dayBox ); 125 mDayBoxes[ i ] = new QCheckBox( weekDayName, dayBox );
125 } 126 }
126 127
127 topLayout->addStretch( 1 ); 128 topLayout->addStretch( 1 );
128} 129}
129 130
130void RecurWeekly::setDays( const QBitArray &days ) 131void RecurWeekly::setDays( const QBitArray &days )
131{ 132{
132 for ( int i = 0; i < 7; ++i ) { 133 for ( int i = 0; i < 7; ++i ) {
133 mDayBoxes[ i ]->setChecked( days.testBit( i ) ); 134 mDayBoxes[ i ]->setChecked( days.testBit( i ) );
134 } 135 }
135} 136}
136 137
137QBitArray RecurWeekly::days() 138QBitArray RecurWeekly::days()
138{ 139{
139 QBitArray days( 7 ); 140 QBitArray days( 7 );
140 141
141 for ( int i = 0; i < 7; ++i ) { 142 for ( int i = 0; i < 7; ++i ) {
142 days.setBit( i, mDayBoxes[ i ]->isChecked() ); 143 days.setBit( i, mDayBoxes[ i ]->isChecked() );
143 } 144 }
144 145
145 return days; 146 return days;
146} 147}
147 148
148/////////////////////////// RecurMonthly /////////////////////////////// 149/////////////////////////// RecurMonthly ///////////////////////////////
149 150
150RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) : 151RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) :
151 RecurBase( parent, name ) 152 RecurBase( parent, name )
152{ 153{
153 QBoxLayout *topLayout = new QVBoxLayout( this ); 154 QBoxLayout *topLayout = new QVBoxLayout( this );
154 topLayout->setSpacing( KDialog::spacingHint() ); 155 topLayout->setSpacing( KDialog::spacingHint() );
155 156
156 157
157 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 158 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
158 159
159 QLabel *preLabel = new QLabel( i18n("every"), this ); 160 QLabel *preLabel = new QLabel( i18n("every"), this );
160 freqLayout->addWidget( preLabel ); 161 freqLayout->addWidget( preLabel );
161 162
162 freqLayout->addWidget( frequencyEdit() ); 163 freqLayout->addWidget( frequencyEdit() );
163 164
164 QLabel *postLabel = new QLabel( i18n("month(s)"), this ); 165 QLabel *postLabel = new QLabel( i18n("month(s)"), this );
165 freqLayout->addWidget( postLabel ); 166 freqLayout->addWidget( postLabel );
166 167
167 168
168 QButtonGroup *buttonGroup = new QButtonGroup( this ); 169 QButtonGroup *buttonGroup = new QButtonGroup( this );
169 buttonGroup->setFrameStyle( QFrame::NoFrame ); 170 buttonGroup->setFrameStyle( QFrame::NoFrame );
170 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 171 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
171 172
172 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); 173 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 );
173 buttonLayout->setSpacing( KDialog::spacingHint() ); 174 buttonLayout->setSpacing( KDialog::spacingHint() );
174 175
175 176
176 QString recurOnText; 177 QString recurOnText;
177 if ( !KOPrefs::instance()->mCompactDialogs ) { 178 if ( !KOPrefs::instance()->mCompactDialogs ) {
178 recurOnText = i18n("Recur on the"); 179 recurOnText = i18n("Recur on the");
179 } 180 }
180 181
181 mByDayRadio = new QRadioButton( recurOnText, buttonGroup ); 182 mByDayRadio = new QRadioButton( recurOnText, buttonGroup );
182 buttonLayout->addWidget( mByDayRadio, 0, 0 ); 183 buttonLayout->addWidget( mByDayRadio, 0, 0 );
183 184
184 mByDayCombo = new QComboBox( buttonGroup ); 185 mByDayCombo = new QComboBox( buttonGroup );
185 mByDayCombo->setSizeLimit( 7 ); 186 mByDayCombo->setSizeLimit( 7 );
186 mByDayCombo->insertItem( i18n("1st") ); 187 mByDayCombo->insertItem( i18n("1st") );
187 mByDayCombo->insertItem( i18n("2nd") ); 188 mByDayCombo->insertItem( i18n("2nd") );
188 mByDayCombo->insertItem( i18n("3rd") ); 189 mByDayCombo->insertItem( i18n("3rd") );
189 mByDayCombo->insertItem( i18n("4th") ); 190 mByDayCombo->insertItem( i18n("4th") );
190 mByDayCombo->insertItem( i18n("5th") ); 191 mByDayCombo->insertItem( i18n("5th") );
191 mByDayCombo->insertItem( i18n("6th") ); 192 mByDayCombo->insertItem( i18n("6th") );
192 mByDayCombo->insertItem( i18n("7th") ); 193 mByDayCombo->insertItem( i18n("7th") );
193 mByDayCombo->insertItem( i18n("8th") ); 194 mByDayCombo->insertItem( i18n("8th") );
194 mByDayCombo->insertItem( i18n("9th") ); 195 mByDayCombo->insertItem( i18n("9th") );
195 mByDayCombo->insertItem( i18n("10th") ); 196 mByDayCombo->insertItem( i18n("10th") );
196 mByDayCombo->insertItem( i18n("11th") ); 197 mByDayCombo->insertItem( i18n("11th") );
197 mByDayCombo->insertItem( i18n("12th") ); 198 mByDayCombo->insertItem( i18n("12th") );
198 mByDayCombo->insertItem( i18n("13th") ); 199 mByDayCombo->insertItem( i18n("13th") );
199 mByDayCombo->insertItem( i18n("14th") ); 200 mByDayCombo->insertItem( i18n("14th") );
200 mByDayCombo->insertItem( i18n("15th") ); 201 mByDayCombo->insertItem( i18n("15th") );
201 mByDayCombo->insertItem( i18n("16th") ); 202 mByDayCombo->insertItem( i18n("16th") );
202 mByDayCombo->insertItem( i18n("17th") ); 203 mByDayCombo->insertItem( i18n("17th") );
203 mByDayCombo->insertItem( i18n("18th") ); 204 mByDayCombo->insertItem( i18n("18th") );
204 mByDayCombo->insertItem( i18n("19th") ); 205 mByDayCombo->insertItem( i18n("19th") );
205 mByDayCombo->insertItem( i18n("20th") ); 206 mByDayCombo->insertItem( i18n("20th") );
206 mByDayCombo->insertItem( i18n("21st") ); 207 mByDayCombo->insertItem( i18n("21st") );
207 mByDayCombo->insertItem( i18n("22nd") ); 208 mByDayCombo->insertItem( i18n("22nd") );
208 mByDayCombo->insertItem( i18n("23rd") ); 209 mByDayCombo->insertItem( i18n("23rd") );
209 mByDayCombo->insertItem( i18n("24th") ); 210 mByDayCombo->insertItem( i18n("24th") );
210 mByDayCombo->insertItem( i18n("25th") ); 211 mByDayCombo->insertItem( i18n("25th") );
211 mByDayCombo->insertItem( i18n("26th") ); 212 mByDayCombo->insertItem( i18n("26th") );
212 mByDayCombo->insertItem( i18n("27th") ); 213 mByDayCombo->insertItem( i18n("27th") );
213 mByDayCombo->insertItem( i18n("28th") ); 214 mByDayCombo->insertItem( i18n("28th") );
214 mByDayCombo->insertItem( i18n("29th") ); 215 mByDayCombo->insertItem( i18n("29th") );
215 mByDayCombo->insertItem( i18n("30th") ); 216 mByDayCombo->insertItem( i18n("30th") );
216 mByDayCombo->insertItem( i18n("31st") ); 217 mByDayCombo->insertItem( i18n("31st") );
217 buttonLayout->addWidget( mByDayCombo, 0, 1 ); 218 buttonLayout->addWidget( mByDayCombo, 0, 1 );
218 219
219 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup ); 220 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup );
220 buttonLayout->addWidget( byDayLabel, 0, 2 ); 221 buttonLayout->addWidget( byDayLabel, 0, 2 );
221 222
222 223
223 mByPosRadio = new QRadioButton( recurOnText, buttonGroup); 224 mByPosRadio = new QRadioButton( recurOnText, buttonGroup);
224 buttonLayout->addWidget( mByPosRadio, 1, 0 ); 225 buttonLayout->addWidget( mByPosRadio, 1, 0 );
225 226
226 mByPosCountCombo = new QComboBox( buttonGroup ); 227 mByPosCountCombo = new QComboBox( buttonGroup );
227 mByPosCountCombo->insertItem( i18n("1st") ); 228 mByPosCountCombo->insertItem( i18n("1st") );
228 mByPosCountCombo->insertItem( i18n("2nd") ); 229 mByPosCountCombo->insertItem( i18n("2nd") );
229 mByPosCountCombo->insertItem( i18n("3rd") ); 230 mByPosCountCombo->insertItem( i18n("3rd") );
230 mByPosCountCombo->insertItem( i18n("4th") ); 231 mByPosCountCombo->insertItem( i18n("4th") );
231 mByPosCountCombo->insertItem( i18n("5th") ); 232 mByPosCountCombo->insertItem( i18n("5th") );
232 buttonLayout->addWidget( mByPosCountCombo, 1, 1 ); 233 buttonLayout->addWidget( mByPosCountCombo, 1, 1 );
233 234
234 mByPosWeekdayCombo = new QComboBox( buttonGroup ); 235 mByPosWeekdayCombo = new QComboBox( buttonGroup );
235 mByPosWeekdayCombo->insertItem( i18n("Monday") ); 236 mByPosWeekdayCombo->insertItem( i18n("Monday") );
236 mByPosWeekdayCombo->insertItem( i18n("Tuesday") ); 237 mByPosWeekdayCombo->insertItem( i18n("Tuesday") );
237 mByPosWeekdayCombo->insertItem( i18n("Wednesday") ); 238 mByPosWeekdayCombo->insertItem( i18n("Wednesday") );
238 mByPosWeekdayCombo->insertItem( i18n("Thursday") ); 239 mByPosWeekdayCombo->insertItem( i18n("Thursday") );
239 mByPosWeekdayCombo->insertItem( i18n("Friday") ); 240 mByPosWeekdayCombo->insertItem( i18n("Friday") );
240 mByPosWeekdayCombo->insertItem( i18n("Saturday") ); 241 mByPosWeekdayCombo->insertItem( i18n("Saturday") );
241 mByPosWeekdayCombo->insertItem( i18n("Sunday") ); 242 mByPosWeekdayCombo->insertItem( i18n("Sunday") );
242 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 ); 243 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 );
243} 244}
244 245
245void RecurMonthly::setByDay( int day ) 246void RecurMonthly::setByDay( int day )
246{ 247{
247 mByDayRadio->setChecked( true ); 248 mByDayRadio->setChecked( true );
248 mByDayCombo->setCurrentItem( day ); 249 mByDayCombo->setCurrentItem( day );
249} 250}
250 251
251void RecurMonthly::setByPos( int count, int weekday ) 252void RecurMonthly::setByPos( int count, int weekday )
252{ 253{
253 mByPosRadio->setChecked( true ); 254 mByPosRadio->setChecked( true );
254 mByPosCountCombo->setCurrentItem( count ); 255 mByPosCountCombo->setCurrentItem( count );
255 mByPosWeekdayCombo->setCurrentItem( weekday ); 256 mByPosWeekdayCombo->setCurrentItem( weekday );
256} 257}
257 258
258bool RecurMonthly::byDay() 259bool RecurMonthly::byDay()
259{ 260{
260 return mByDayRadio->isChecked(); 261 return mByDayRadio->isChecked();
261} 262}
262 263
263bool RecurMonthly::byPos() 264bool RecurMonthly::byPos()
264{ 265{
265 return mByPosRadio->isChecked(); 266 return mByPosRadio->isChecked();
266} 267}
267 268
268int RecurMonthly::day() 269int RecurMonthly::day()
269{ 270{
270 return mByDayCombo->currentItem() + 1; 271 return mByDayCombo->currentItem() + 1;
271} 272}
272 273
273int RecurMonthly::count() 274int RecurMonthly::count()
274{ 275{
275 return mByPosCountCombo->currentItem() + 1; 276 return mByPosCountCombo->currentItem() + 1;
276} 277}
277 278
278int RecurMonthly::weekday() 279int RecurMonthly::weekday()
279{ 280{
280 return mByPosWeekdayCombo->currentItem(); 281 return mByPosWeekdayCombo->currentItem();
281} 282}
282 283
283/////////////////////////// RecurYearly /////////////////////////////// 284/////////////////////////// RecurYearly ///////////////////////////////
284 285
285RecurYearly::RecurYearly( QWidget *parent, const char *name ) : 286RecurYearly::RecurYearly( QWidget *parent, const char *name ) :
286 RecurBase( parent, name ) 287 RecurBase( parent, name )
287{ 288{
288 QBoxLayout *topLayout = new QVBoxLayout( this ); 289 QBoxLayout *topLayout = new QVBoxLayout( this );
289 topLayout->setSpacing( KDialog::spacingHint() ); 290 topLayout->setSpacing( KDialog::spacingHint() );
290 291
291 292
292 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 293 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
293 294
294 QLabel *preLabel = new QLabel( i18n("every"), this ); 295 QLabel *preLabel = new QLabel( i18n("every"), this );
295 freqLayout->addWidget( preLabel ); 296 freqLayout->addWidget( preLabel );
296 297
297 freqLayout->addWidget( frequencyEdit() ); 298 freqLayout->addWidget( frequencyEdit() );
298 299
299 QLabel *postLabel = new QLabel( i18n("year(s)"), this ); 300 QLabel *postLabel = new QLabel( i18n("year(s)"), this );
300 freqLayout->addWidget( postLabel ); 301 freqLayout->addWidget( postLabel );
301 302
302 303
303 QButtonGroup *buttonGroup = new QButtonGroup( this ); 304 QButtonGroup *buttonGroup = new QButtonGroup( this );
304 buttonGroup->setFrameStyle( QFrame::NoFrame ); 305 buttonGroup->setFrameStyle( QFrame::NoFrame );
305 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 306 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
306 307
307 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 ); 308 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 );
308 309
309 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup); 310 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup);
310 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight); 311 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight);
311 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup ); 312 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup );
312 313
313 buttonLayout->addWidget( mByDayLabel, 0, 1 ); 314 buttonLayout->addWidget( mByDayLabel, 0, 1 );
314 mByMonthCombo = new QComboBox( buttonGroup ); 315 mByMonthCombo = new QComboBox( buttonGroup );
315 mByMonthCombo->insertItem( i18n("January") ); 316 mByMonthCombo->insertItem( i18n("January") );
316 mByMonthCombo->insertItem( i18n("February") ); 317 mByMonthCombo->insertItem( i18n("February") );
317 mByMonthCombo->insertItem( i18n("March") ); 318 mByMonthCombo->insertItem( i18n("March") );
318 mByMonthCombo->insertItem( i18n("April") ); 319 mByMonthCombo->insertItem( i18n("April") );
319 mByMonthCombo->insertItem( i18n("May") ); 320 mByMonthCombo->insertItem( i18n("May") );
320 mByMonthCombo->insertItem( i18n("June") ); 321 mByMonthCombo->insertItem( i18n("June") );
321 mByMonthCombo->insertItem( i18n("July") ); 322 mByMonthCombo->insertItem( i18n("July") );
322 mByMonthCombo->insertItem( i18n("August") ); 323 mByMonthCombo->insertItem( i18n("August") );
323 mByMonthCombo->insertItem( i18n("September") ); 324 mByMonthCombo->insertItem( i18n("September") );
324 mByMonthCombo->insertItem( i18n("October") ); 325 mByMonthCombo->insertItem( i18n("October") );
325 mByMonthCombo->insertItem( i18n("November") ); 326 mByMonthCombo->insertItem( i18n("November") );
326 mByMonthCombo->insertItem( i18n("December") ); 327 mByMonthCombo->insertItem( i18n("December") );
327 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft ); 328 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft );
328 if ( QApplication::desktop()->width() <= 640 ) { 329 if ( QApplication::desktop()->width() <= 640 ) {
329 mByMonthCombo->setSizeLimit( 6 ); 330 mByMonthCombo->setSizeLimit( 6 );
330 } 331 }
331 332
332 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup); 333 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup);
333 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight); 334 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight);
334 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup ); 335 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup );
335 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 ); 336 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 );
336 337
337} 338}
338 339
339void RecurYearly::setByDay( int doy ) 340void RecurYearly::setByDay( int doy )
340{ 341{
341 mByDayRadio->setChecked( true ); 342 mByDayRadio->setChecked( true );
342 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) ); 343 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) );
343} 344}
344 345
345void RecurYearly::setByMonth( int month, int day ) 346void RecurYearly::setByMonth( int month, int day )
346{ 347{
347 mByMonthRadio->setChecked( true ); 348 mByMonthRadio->setChecked( true );
348 mByMonthCombo->setCurrentItem( month - 1 ); 349 mByMonthCombo->setCurrentItem( month - 1 );
349 mByDayLabel->setText(i18n("%1 of ").arg( day ) ); 350 mByDayLabel->setText(i18n("%1 of ").arg( day ) );
350 mDay = day; 351 mDay = day;
351} 352}
352 353
353bool RecurYearly::byMonth() 354bool RecurYearly::byMonth()
354{ 355{
355 return mByMonthRadio->isChecked(); 356 return mByMonthRadio->isChecked();
356} 357}
357 358
358bool RecurYearly::byDay() 359bool RecurYearly::byDay()
359{ 360{
360 return mByDayRadio->isChecked(); 361 return mByDayRadio->isChecked();
361} 362}
362 363
363int RecurYearly::month() 364int RecurYearly::month()
364{ 365{
365 return mByMonthCombo->currentItem() + 1; 366 return mByMonthCombo->currentItem() + 1;
366} 367}
367int RecurYearly::day() 368int RecurYearly::day()
368{ 369{
369 return mDay;//mByDayCombo->currentItem() + 1; 370 return mDay;//mByDayCombo->currentItem() + 1;
370} 371}
371 372
372//////////////////////////// ExceptionsWidget ////////////////////////// 373//////////////////////////// ExceptionsWidget //////////////////////////
373 374
374ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) : 375ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) :
375 QWidget( parent, name ) 376 QWidget( parent, name )
376{ 377{
377 QBoxLayout *topLayout = new QVBoxLayout( this ); 378 QBoxLayout *topLayout = new QVBoxLayout( this );
378 379
379 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"), 380 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"),
380 this ); 381 this );
381 topLayout->addWidget( groupBox ); 382 topLayout->addWidget( groupBox );
382 383
383 QWidget *box = new QWidget( groupBox ); 384 QWidget *box = new QWidget( groupBox );
384 385
385 QGridLayout *boxLayout = new QGridLayout( box ); 386 QGridLayout *boxLayout = new QGridLayout( box );
386 387
387 mExceptionDateEdit = new KDateEdit( box ); 388 mExceptionDateEdit = new KDateEdit( box );
388 boxLayout->addWidget( mExceptionDateEdit, 0, 0 ); 389 boxLayout->addWidget( mExceptionDateEdit, 0, 0 );
389 390
390 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box ); 391 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box );
391 boxLayout->addWidget( addExceptionButton, 1, 0 ); 392 boxLayout->addWidget( addExceptionButton, 1, 0 );
392 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box ); 393 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box );
393 boxLayout->addWidget( changeExceptionButton, 2, 0 ); 394 boxLayout->addWidget( changeExceptionButton, 2, 0 );
394 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box ); 395 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box );
395 boxLayout->addWidget( deleteExceptionButton, 3, 0 ); 396 boxLayout->addWidget( deleteExceptionButton, 3, 0 );
396 397
397 mExceptionList = new QListBox( box ); 398 mExceptionList = new QListBox( box );
398 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 ); 399 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 );
399 400
400 boxLayout->setRowStretch( 4, 1 ); 401 boxLayout->setRowStretch( 4, 1 );
401 boxLayout->setColStretch( 1, 3 ); 402 boxLayout->setColStretch( 1, 3 );
402 403
403 connect( addExceptionButton, SIGNAL( clicked() ), 404 connect( addExceptionButton, SIGNAL( clicked() ),
404 SLOT( addException() ) ); 405 SLOT( addException() ) );
405 connect( changeExceptionButton, SIGNAL( clicked() ), 406 connect( changeExceptionButton, SIGNAL( clicked() ),
406 SLOT( changeException() ) ); 407 SLOT( changeException() ) );
407 connect( deleteExceptionButton, SIGNAL( clicked() ), 408 connect( deleteExceptionButton, SIGNAL( clicked() ),
408 SLOT( deleteException() ) ); 409 SLOT( deleteException() ) );
409 if ( QApplication::desktop()->width() < 480 ) { 410 if ( QApplication::desktop()->width() < 480 ) {
410 setMinimumWidth( 220 ); 411 setMinimumWidth( 220 );
411 } else { 412 } else {
412 setMinimumWidth( 440 ); 413 setMinimumWidth( 440 );
413 mExceptionDateEdit->setMinimumWidth( 200 ); 414 mExceptionDateEdit->setMinimumWidth( 200 );
414 } 415 }
415} 416}
416 417
417void ExceptionsWidget::setDefaults( const QDateTime &from ) 418void ExceptionsWidget::setDefaults( const QDateTime &from )
418{ 419{
419 mExceptionDateEdit->setDate( from.date() ); 420 mExceptionDateEdit->setDate( from.date() );
420} 421}
421 422
422void ExceptionsWidget::addException() 423void ExceptionsWidget::addException()
423{ 424{
424 QDate date = mExceptionDateEdit->date(); 425 QDate date = mExceptionDateEdit->date();
425 QString dateStr = KGlobal::locale()->formatDate( date ); 426 QString dateStr = KGlobal::locale()->formatDate( date );
426 if( !mExceptionList->findItem( dateStr ) ) { 427 if( !mExceptionList->findItem( dateStr ) ) {
427 mExceptionDates.append( date ); 428 mExceptionDates.append( date );
428 mExceptionList->insertItem( dateStr ); 429 mExceptionList->insertItem( dateStr );
429 } 430 }
430} 431}
431 432
432void ExceptionsWidget::changeException() 433void ExceptionsWidget::changeException()
433{ 434{
434 int pos = mExceptionList->currentItem(); 435 int pos = mExceptionList->currentItem();
435 if ( pos < 0 ) return; 436 if ( pos < 0 ) return;
436 437
437 QDate date = mExceptionDateEdit->date(); 438 QDate date = mExceptionDateEdit->date();
438 mExceptionDates[ pos ] = date; 439 mExceptionDates[ pos ] = date;
439 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos ); 440 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos );
440} 441}
441 442
442void ExceptionsWidget::deleteException() 443void ExceptionsWidget::deleteException()
443{ 444{
444 int pos = mExceptionList->currentItem(); 445 int pos = mExceptionList->currentItem();
445 if ( pos < 0 ) return; 446 if ( pos < 0 ) return;
446 447
447 mExceptionDates.remove( mExceptionDates.at( pos ) ); 448 mExceptionDates.remove( mExceptionDates.at( pos ) );
448 mExceptionList->removeItem( pos ); 449 mExceptionList->removeItem( pos );
449} 450}
450 451
451void ExceptionsWidget::setDates( const DateList &dates ) 452void ExceptionsWidget::setDates( const DateList &dates )
452{ 453{
453 mExceptionList->clear(); 454 mExceptionList->clear();
454 mExceptionDates.clear(); 455 mExceptionDates.clear();
455 DateList::ConstIterator dit; 456 DateList::ConstIterator dit;
456 for ( dit = dates.begin(); dit != dates.end(); ++dit ) { 457 for ( dit = dates.begin(); dit != dates.end(); ++dit ) {
457 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) ); 458 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) );
458 mExceptionDates.append( *dit ); 459 mExceptionDates.append( *dit );
459 } 460 }
460} 461}
461 462
462DateList ExceptionsWidget::dates() 463DateList ExceptionsWidget::dates()
463{ 464{
464 return mExceptionDates; 465 return mExceptionDates;
465} 466}
466 467
467///////////////////////// ExceptionsDialog /////////////////////////// 468///////////////////////// ExceptionsDialog ///////////////////////////
468 469
469ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) : 470ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) :
470 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel ) 471 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel )
471{ 472{
472 mExceptions = new ExceptionsWidget( this ); 473 mExceptions = new ExceptionsWidget( this );
473 setMainWidget( mExceptions ); 474 setMainWidget( mExceptions );
474 resize(220,10); 475 resize(220,10);
475} 476}
476 477
477void ExceptionsDialog::setDefaults( const QDateTime &from ) 478void ExceptionsDialog::setDefaults( const QDateTime &from )
478{ 479{
479 mExceptions->setDefaults( from ); 480 mExceptions->setDefaults( from );
480} 481}
481 482
482void ExceptionsDialog::setDates( const DateList &dates ) 483void ExceptionsDialog::setDates( const DateList &dates )
483{ 484{
484 mExceptions->setDates( dates ); 485 mExceptions->setDates( dates );
485} 486}
486 487
487DateList ExceptionsDialog::dates() 488DateList ExceptionsDialog::dates()
488{ 489{
489 return mExceptions->dates(); 490 return mExceptions->dates();
490} 491}
491 492
492///////////////////////// RecurrenceRangeWidget /////////////////////////// 493///////////////////////// RecurrenceRangeWidget ///////////////////////////
493 494
494RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent, 495RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent,
495 const char *name ) 496 const char *name )
496 : QWidget( parent, name ) 497 : QWidget( parent, name )
497{ 498{
498 QBoxLayout *topLayout = new QVBoxLayout( this ); 499 QBoxLayout *topLayout = new QVBoxLayout( this );
499 500
500 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"), 501 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"),
501 this ); 502 this );
502 topLayout->addWidget( mRangeGroupBox ); 503 topLayout->addWidget( mRangeGroupBox );
503 504
504 QWidget *rangeBox = new QWidget( mRangeGroupBox ); 505 QWidget *rangeBox = new QWidget( mRangeGroupBox );
505 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox ); 506 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox );
506 rangeLayout->setSpacing( KDialog::spacingHint() ); 507 rangeLayout->setSpacing( KDialog::spacingHint() );
507 508
508 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox ); 509 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox );
509 rangeLayout->addWidget( mStartDateLabel ); 510 rangeLayout->addWidget( mStartDateLabel );
510 511
511 QButtonGroup *rangeButtonGroup = new QButtonGroup; 512 QButtonGroup *rangeButtonGroup = new QButtonGroup;
512 513
513 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox ); 514 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox );
514 rangeButtonGroup->insert( mNoEndDateButton ); 515 rangeButtonGroup->insert( mNoEndDateButton );
515 rangeLayout->addWidget( mNoEndDateButton ); 516 rangeLayout->addWidget( mNoEndDateButton );
516 517
517 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout ); 518 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout );
518 durationLayout->setSpacing( KDialog::spacingHint() ); 519 durationLayout->setSpacing( KDialog::spacingHint() );
519 520
520 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox ); 521 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox );
521 rangeButtonGroup->insert( mEndDurationButton ); 522 rangeButtonGroup->insert( mEndDurationButton );
522 durationLayout->addWidget( mEndDurationButton ); 523 durationLayout->addWidget( mEndDurationButton );
523 524
524 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox ); 525 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox );
525 durationLayout->addWidget( mEndDurationEdit ); 526 durationLayout->addWidget( mEndDurationEdit );
526 527
527 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox ); 528 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox );
528 durationLayout ->addWidget( endDurationLabel ); 529 durationLayout ->addWidget( endDurationLabel );
529 530
530 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout ); 531 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout );
531 endDateLayout->setSpacing( KDialog::spacingHint() ); 532 endDateLayout->setSpacing( KDialog::spacingHint() );
532 533
533 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox ); 534 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox );
534 rangeButtonGroup->insert( mEndDateButton ); 535 rangeButtonGroup->insert( mEndDateButton );
535 endDateLayout->addWidget( mEndDateButton ); 536 endDateLayout->addWidget( mEndDateButton );
536 537
537 mEndDateEdit = new KDateEdit( rangeBox ); 538 mEndDateEdit = new KDateEdit( rangeBox );
538 endDateLayout->addWidget( mEndDateEdit ); 539 endDateLayout->addWidget( mEndDateEdit );
539 540
540 endDateLayout->addStretch( 1 ); 541 endDateLayout->addStretch( 1 );
541 542
542 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ), 543 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ),
543 SLOT( showCurrentRange() ) ); 544 SLOT( showCurrentRange() ) );
544 connect( mEndDurationButton, SIGNAL( toggled( bool ) ), 545 connect( mEndDurationButton, SIGNAL( toggled( bool ) ),
545 SLOT( showCurrentRange() ) ); 546 SLOT( showCurrentRange() ) );
546 connect( mEndDateButton, SIGNAL( toggled( bool ) ), 547 connect( mEndDateButton, SIGNAL( toggled( bool ) ),
547 SLOT( showCurrentRange() ) ); 548 SLOT( showCurrentRange() ) );
548} 549}
549 550
550void RecurrenceRangeWidget::setDefaults( const QDateTime &from ) 551void RecurrenceRangeWidget::setDefaults( const QDateTime &from )
551{ 552{
552 mNoEndDateButton->setChecked( true ); 553 mNoEndDateButton->setChecked( true );
553 554
554 setDateTimes( from ); 555 setDateTimes( from );
555 mEndDateEdit->setDate( from.date() ); 556 mEndDateEdit->setDate( from.date() );
556} 557}
557 558
558void RecurrenceRangeWidget::setDuration( int duration ) 559void RecurrenceRangeWidget::setDuration( int duration )
559{ 560{
560 if ( duration == -1 ) { 561 if ( duration == -1 ) {
561 mNoEndDateButton->setChecked( true ); 562 mNoEndDateButton->setChecked( true );
562 } else if ( duration == 0 ) { 563 } else if ( duration == 0 ) {
563 mEndDateButton->setChecked( true ); 564 mEndDateButton->setChecked( true );
564 } else { 565 } else {
565 mEndDurationButton->setChecked( true ); 566 mEndDurationButton->setChecked( true );
566 mEndDurationEdit->setValue( duration ); 567 mEndDurationEdit->setValue( duration );
567 } 568 }
568} 569}
569 570
570int RecurrenceRangeWidget::duration() 571int RecurrenceRangeWidget::duration()
571{ 572{
572 if ( mNoEndDateButton->isChecked() ) { 573 if ( mNoEndDateButton->isChecked() ) {
573 return -1; 574 return -1;
574 } else if ( mEndDurationButton->isChecked() ) { 575 } else if ( mEndDurationButton->isChecked() ) {
575 return mEndDurationEdit->value(); 576 return mEndDurationEdit->value();
576 } else { 577 } else {
577 return 0; 578 return 0;
578 } 579 }
579} 580}
580 581
581void RecurrenceRangeWidget::setEndDate( const QDate &date ) 582void RecurrenceRangeWidget::setEndDate( const QDate &date )
582{ 583{
583 mEndDateEdit->setDate( date ); 584 mEndDateEdit->setDate( date );
584} 585}
585 586
586QDate RecurrenceRangeWidget::endDate() 587QDate RecurrenceRangeWidget::endDate()
587{ 588{
588 return mEndDateEdit->date(); 589 return mEndDateEdit->date();
589} 590}
590 591
591void RecurrenceRangeWidget::showCurrentRange() 592void RecurrenceRangeWidget::showCurrentRange()
592{ 593{
593 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() ); 594 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() );
594 mEndDateEdit->setEnabled( mEndDateButton->isChecked() ); 595 mEndDateEdit->setEnabled( mEndDateButton->isChecked() );
595} 596}
596 597
597void RecurrenceRangeWidget::setDateTimes( const QDateTime &start, 598void RecurrenceRangeWidget::setDateTimes( const QDateTime &start,
598 const QDateTime & ) 599 const QDateTime & )
599{ 600{
600 mStartDateLabel->setText( i18n("Start date: %1") 601 mStartDateLabel->setText( i18n("Start date: %1")
601 .arg( KGlobal::locale()->formatDate( start.date() ) ) ); 602 .arg( KGlobal::locale()->formatDate( start.date() ) ) );
602 603
603 if(!mEndDateButton->isChecked()) 604 if(!mEndDateButton->isChecked())
604 mEndDateEdit->setDate( start.date() ); 605 mEndDateEdit->setDate( start.date() );
605} 606}
606 607
607///////////////////////// RecurrenceRangeDialog /////////////////////////// 608///////////////////////// RecurrenceRangeDialog ///////////////////////////
608 609
609RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent, 610RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent,
610 const char *name ) : 611 const char *name ) :
611 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel ) 612 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel )
612{ 613{
613 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this ); 614 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this );
614 setMainWidget( mRecurrenceRangeWidget ); 615 setMainWidget( mRecurrenceRangeWidget );
615} 616}
616 617
617void RecurrenceRangeDialog::setDefaults( const QDateTime &from ) 618void RecurrenceRangeDialog::setDefaults( const QDateTime &from )
618{ 619{
619 mRecurrenceRangeWidget->setDefaults( from ); 620 mRecurrenceRangeWidget->setDefaults( from );
620} 621}
621 622
622void RecurrenceRangeDialog::setDuration( int duration ) 623void RecurrenceRangeDialog::setDuration( int duration )
623{ 624{
624 mRecurrenceRangeWidget->setDuration( duration ); 625 mRecurrenceRangeWidget->setDuration( duration );
625} 626}
626 627
627int RecurrenceRangeDialog::duration() 628int RecurrenceRangeDialog::duration()
628{ 629{
629 return mRecurrenceRangeWidget->duration(); 630 return mRecurrenceRangeWidget->duration();
630} 631}
631 632
632void RecurrenceRangeDialog::setEndDate( const QDate &date ) 633void RecurrenceRangeDialog::setEndDate( const QDate &date )
633{ 634{
634 mRecurrenceRangeWidget->setEndDate( date ); 635 mRecurrenceRangeWidget->setEndDate( date );
635} 636}
636 637
637QDate RecurrenceRangeDialog::endDate() 638QDate RecurrenceRangeDialog::endDate()
638{ 639{
639 return mRecurrenceRangeWidget->endDate(); 640 return mRecurrenceRangeWidget->endDate();
640} 641}
641 642
642void RecurrenceRangeDialog::setDateTimes( const QDateTime &start, 643void RecurrenceRangeDialog::setDateTimes( const QDateTime &start,
643 const QDateTime &end ) 644 const QDateTime &end )
644{ 645{
645 mRecurrenceRangeWidget->setDateTimes( start, end ); 646 mRecurrenceRangeWidget->setDateTimes( start, end );
646} 647}
647 648
648//////////////////////////// RecurrenceChooser //////////////////////// 649//////////////////////////// RecurrenceChooser ////////////////////////
649 650
650RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) : 651RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) :
651 QWidget( parent, name ) 652 QWidget( parent, name )
652{ 653{
653 QBoxLayout *topLayout = new QVBoxLayout( this ); 654 QBoxLayout *topLayout = new QVBoxLayout( this );
654 655
655 if ( KOPrefs::instance()->mCompactDialogs ) { 656 if ( KOPrefs::instance()->mCompactDialogs ) {
656 mTypeCombo = new QComboBox( this ); 657 mTypeCombo = new QComboBox( this );
657 mTypeCombo->insertItem( i18n("Daily") ); 658 mTypeCombo->insertItem( i18n("Daily") );
658 mTypeCombo->insertItem( i18n("Weekly") ); 659 mTypeCombo->insertItem( i18n("Weekly") );
659 mTypeCombo->insertItem( i18n("Monthly") ); 660 mTypeCombo->insertItem( i18n("Monthly") );
660 mTypeCombo->insertItem( i18n("Yearly") ); 661 mTypeCombo->insertItem( i18n("Yearly") );
661 662
662 topLayout->addWidget( mTypeCombo ); 663 topLayout->addWidget( mTypeCombo );
663 664
664 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) ); 665 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) );
665 } else { 666 } else {
666 mTypeCombo = 0; 667 mTypeCombo = 0;
667 668
668 QButtonGroup *ruleButtonGroup = new QButtonGroup( 1, Horizontal, this ); 669 QButtonGroup *ruleButtonGroup = new QButtonGroup( 1, Horizontal, this );
669 ruleButtonGroup->setFrameStyle( QFrame::NoFrame ); 670 ruleButtonGroup->setFrameStyle( QFrame::NoFrame );
670 topLayout->addWidget( ruleButtonGroup ); 671 topLayout->addWidget( ruleButtonGroup );
671 672
672 mDailyButton = new QRadioButton( i18n("Daily"), ruleButtonGroup ); 673 mDailyButton = new QRadioButton( i18n("Daily"), ruleButtonGroup );
673 mWeeklyButton = new QRadioButton( i18n("Weekly"), ruleButtonGroup ); 674 mWeeklyButton = new QRadioButton( i18n("Weekly"), ruleButtonGroup );
674 mMonthlyButton = new QRadioButton( i18n("Monthly"), ruleButtonGroup ); 675 mMonthlyButton = new QRadioButton( i18n("Monthly"), ruleButtonGroup );
675 mYearlyButton = new QRadioButton( i18n("Yearly"), ruleButtonGroup ); 676 mYearlyButton = new QRadioButton( i18n("Yearly"), ruleButtonGroup );
676 677
677 connect( mDailyButton, SIGNAL( toggled( bool ) ), 678 connect( mDailyButton, SIGNAL( toggled( bool ) ),
678 SLOT( emitChoice() ) ); 679 SLOT( emitChoice() ) );
679 connect( mWeeklyButton, SIGNAL( toggled( bool ) ), 680 connect( mWeeklyButton, SIGNAL( toggled( bool ) ),
680 SLOT( emitChoice() ) ); 681 SLOT( emitChoice() ) );
681 connect( mMonthlyButton, SIGNAL( toggled( bool ) ), 682 connect( mMonthlyButton, SIGNAL( toggled( bool ) ),
682 SLOT( emitChoice() ) ); 683 SLOT( emitChoice() ) );
683 connect( mYearlyButton, SIGNAL( toggled( bool ) ), 684 connect( mYearlyButton, SIGNAL( toggled( bool ) ),
684 SLOT( emitChoice() ) ); 685 SLOT( emitChoice() ) );
685 } 686 }
686} 687}
687 688
688int RecurrenceChooser::type() 689int RecurrenceChooser::type()
689{ 690{
690 if ( mTypeCombo ) { 691 if ( mTypeCombo ) {
691 return mTypeCombo->currentItem(); 692 return mTypeCombo->currentItem();
692 } else { 693 } else {
693 if ( mDailyButton->isChecked() ) return Daily; 694 if ( mDailyButton->isChecked() ) return Daily;
694 else if ( mWeeklyButton->isChecked() ) return Weekly; 695 else if ( mWeeklyButton->isChecked() ) return Weekly;
695 else if ( mMonthlyButton->isChecked() ) return Monthly; 696 else if ( mMonthlyButton->isChecked() ) return Monthly;
696 else return Yearly; 697 else return Yearly;
697 } 698 }
698} 699}
699 700
700void RecurrenceChooser::setType( int type ) 701void RecurrenceChooser::setType( int type )
701{ 702{
702 if ( mTypeCombo ) { 703 if ( mTypeCombo ) {
703 mTypeCombo->setCurrentItem( type ); 704 mTypeCombo->setCurrentItem( type );
704 } else { 705 } else {
705 switch ( type ) { 706 switch ( type ) {
706 case Daily: 707 case Daily:
707 mDailyButton->setChecked( true ); 708 mDailyButton->setChecked( true );
708 break; 709 break;
709 case Weekly: 710 case Weekly:
710 mWeeklyButton->setChecked( true ); 711 mWeeklyButton->setChecked( true );
711 break; 712 break;
712 case Monthly: 713 case Monthly:
713 mMonthlyButton->setChecked( true ); 714 mMonthlyButton->setChecked( true );
714 break; 715 break;
715 case Yearly: 716 case Yearly:
716 default: 717 default:
717 mYearlyButton->setChecked( true ); 718 mYearlyButton->setChecked( true );
718 break; 719 break;
719 } 720 }
720 } 721 }
721} 722}
722 723
723void RecurrenceChooser::emitChoice() 724void RecurrenceChooser::emitChoice()
724{ 725{
725 emit chosen ( type() ); 726 emit chosen ( type() );
726} 727}
727 728
728/////////////////////////////// Main Widget ///////////////////////////// 729/////////////////////////////// Main Widget /////////////////////////////
729 730
730KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : 731KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
731 QWidget( parent, name ) 732 QWidget( parent, name )
732{ 733{
733 QGridLayout *topLayout = new QGridLayout( this, 2,2 ); 734 QGridLayout *topLayout = new QGridLayout( this, 2,2 );
734 topLayout->setSpacing( KDialog::spacingHint() ); 735 topLayout->setSpacing( KDialog::spacingHint() );
735 736
736 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this ); 737 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this );
737 connect( mEnabledCheck, SIGNAL( toggled( bool ) ), 738 connect( mEnabledCheck, SIGNAL( toggled( bool ) ),
738 SLOT( setEnabled( bool ) ) ); 739 SLOT( setEnabled( bool ) ) );
739 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 ); 740 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 );
740 741
741 742
742 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Appointment Time "), 743 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Appointment Time "),
743 this ); 744 this );
744 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 ); 745 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 );
745 746
746 if ( KOPrefs::instance()->mCompactDialogs ) { 747 if ( KOPrefs::instance()->mCompactDialogs ) {
747 mTimeGroupBox->hide(); 748 mTimeGroupBox->hide();
748 } 749 }
749 750
750// QFrame *timeFrame = new QFrame( mTimeGroupBox ); 751// QFrame *timeFrame = new QFrame( mTimeGroupBox );
751// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame ); 752// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame );
752// layoutTimeFrame->setSpacing( KDialog::spacingHint() ); 753// layoutTimeFrame->setSpacing( KDialog::spacingHint() );
753 754
754 mDateTimeLabel = new QLabel( mTimeGroupBox ); 755 mDateTimeLabel = new QLabel( mTimeGroupBox );
755// mDateTimeLabel = new QLabel( timeFrame ); 756// mDateTimeLabel = new QLabel( timeFrame );
756// layoutTimeFrame->addWidget( mDateTimeLabel ); 757// layoutTimeFrame->addWidget( mDateTimeLabel );
757 758
758 Qt::Orientation orientation; 759 Qt::Orientation orientation;
759 if ( KOPrefs::instance()->mCompactDialogs ) orientation = Horizontal; 760 if ( KOPrefs::instance()->mCompactDialogs ) orientation = Horizontal;
760 else orientation = Vertical; 761 else orientation = Vertical;
761 762
762 mRuleBox = new QGroupBox( 1, orientation, i18n("Recurrence Rule"), this ); 763 mRuleBox = new QGroupBox( 1, orientation, i18n("Recurrence Rule"), this );
763 if ( KOPrefs::instance()->mCompactDialogs ) { 764 if ( KOPrefs::instance()->mCompactDialogs ) {
764 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); 765 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 );
765 } else { 766 } else {
766 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); 767 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 );
767 } 768 }
768 769
769 mRecurrenceChooser = new RecurrenceChooser( mRuleBox ); 770 mRecurrenceChooser = new RecurrenceChooser( mRuleBox );
770 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ), 771 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ),
771 SLOT( showCurrentRule( int ) ) ); 772 SLOT( showCurrentRule( int ) ) );
772 773
773 if ( !KOPrefs::instance()->mCompactDialogs ) { 774 if ( !KOPrefs::instance()->mCompactDialogs ) {
774 QFrame *ruleSepFrame = new QFrame( mRuleBox ); 775 QFrame *ruleSepFrame = new QFrame( mRuleBox );
775 ruleSepFrame->setFrameStyle( QFrame::VLine | QFrame::Sunken ); 776 ruleSepFrame->setFrameStyle( QFrame::VLine | QFrame::Sunken );
776 } 777 }
777 778
778 mRuleStack = new QWidgetStack( mRuleBox ); 779 mRuleStack = new QWidgetStack( mRuleBox );
779 780
780 mDaily = new RecurDaily( mRuleStack ); 781 mDaily = new RecurDaily( mRuleStack );
781 mRuleStack->addWidget( mDaily, 0 ); 782 mRuleStack->addWidget( mDaily, 0 );
782 783
783 mWeekly = new RecurWeekly( mRuleStack ); 784 mWeekly = new RecurWeekly( mRuleStack );
784 mRuleStack->addWidget( mWeekly, 0 ); 785 mRuleStack->addWidget( mWeekly, 0 );
785 786
786 mMonthly = new RecurMonthly( mRuleStack ); 787 mMonthly = new RecurMonthly( mRuleStack );
787 mRuleStack->addWidget( mMonthly, 0 ); 788 mRuleStack->addWidget( mMonthly, 0 );
788 789
789 mYearly = new RecurYearly( mRuleStack ); 790 mYearly = new RecurYearly( mRuleStack );
790 mRuleStack->addWidget( mYearly, 0 ); 791 mRuleStack->addWidget( mYearly, 0 );
791 792
792 showCurrentRule( mRecurrenceChooser->type() ); 793 showCurrentRule( mRecurrenceChooser->type() );
793 794
794 if ( KOPrefs::instance()->mCompactDialogs ) { 795 if ( KOPrefs::instance()->mCompactDialogs ) {
795 mRecurrenceRangeWidget = 0; 796 mRecurrenceRangeWidget = 0;
796 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); 797 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this );
797 mRecurrenceRange = mRecurrenceRangeDialog; 798 mRecurrenceRange = mRecurrenceRangeDialog;
798 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), 799 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."),
799 this ); 800 this );
800 801
801 connect( mRecurrenceRangeButton, SIGNAL( clicked() ), 802 connect( mRecurrenceRangeButton, SIGNAL( clicked() ),
802 SLOT( showRecurrenceRangeDialog() ) ); 803 SLOT( showRecurrenceRangeDialog() ) );
803 804
804 mExceptionsWidget = 0; 805 mExceptionsWidget = 0;
805 mExceptionsDialog = new ExceptionsDialog( this ); 806 mExceptionsDialog = new ExceptionsDialog( this );
806 mExceptions = mExceptionsDialog; 807 mExceptions = mExceptionsDialog;
807 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); 808 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this );
808 if ( QApplication::desktop()->width() < 320 ) { 809 if ( QApplication::desktop()->width() < 320 ) {
809 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); 810 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 );
810 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); 811 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 );
811 } else { 812 } else {
812 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); 813 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 );
813 topLayout->addWidget( mExceptionsButton, 3, 1 ); 814 topLayout->addWidget( mExceptionsButton, 3, 1 );
814 } 815 }
815 connect( mExceptionsButton, SIGNAL( clicked() ), 816 connect( mExceptionsButton, SIGNAL( clicked() ),
816 SLOT( showExceptionsDialog() ) ); 817 SLOT( showExceptionsDialog() ) );
817 818
818 } else { 819 } else {
819 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this ); 820 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this );
820 mRecurrenceRangeDialog = 0; 821 mRecurrenceRangeDialog = 0;
821 mRecurrenceRange = mRecurrenceRangeWidget; 822 mRecurrenceRange = mRecurrenceRangeWidget;
822 mRecurrenceRangeButton = 0; 823 mRecurrenceRangeButton = 0;
823 topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 ); 824 topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 );
824 825
825 mExceptionsWidget = new ExceptionsWidget( this ); 826 mExceptionsWidget = new ExceptionsWidget( this );
826 mExceptionsDialog = 0; 827 mExceptionsDialog = 0;
827 mExceptions = mExceptionsWidget; 828 mExceptions = mExceptionsWidget;
828 mExceptionsButton = 0; 829 mExceptionsButton = 0;
829 topLayout->addWidget( mExceptionsWidget, 3, 1 ); 830 topLayout->addWidget( mExceptionsWidget, 3, 1 );
830 } 831 }
831} 832}
832 833
833KOEditorRecurrence::~KOEditorRecurrence() 834KOEditorRecurrence::~KOEditorRecurrence()
834{ 835{
835} 836}
836 837
837void KOEditorRecurrence::setEnabled( bool enabled ) 838void KOEditorRecurrence::setEnabled( bool enabled )
838{ 839{
839// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; 840// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
840 841
841 mTimeGroupBox->setEnabled( enabled ); 842 mTimeGroupBox->setEnabled( enabled );
842 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); 843 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
843 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); 844 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
844 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); 845 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
845 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); 846 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
846 mRuleBox->setEnabled( enabled ); 847 mRuleBox->setEnabled( enabled );
847} 848}
848 849
849void KOEditorRecurrence::showCurrentRule( int current ) 850void KOEditorRecurrence::showCurrentRule( int current )
850{ 851{
851 switch ( current ) { 852 switch ( current ) {
852 case Daily: 853 case Daily:
853 mRuleStack->raiseWidget( mDaily ); 854 mRuleStack->raiseWidget( mDaily );
854 break; 855 break;
855 case Weekly: 856 case Weekly:
856 mRuleStack->raiseWidget( mWeekly ); 857 mRuleStack->raiseWidget( mWeekly );
857 break; 858 break;
858 case Monthly: 859 case Monthly:
859 mRuleStack->raiseWidget( mMonthly ); 860 mRuleStack->raiseWidget( mMonthly );
860 break; 861 break;
861 default: 862 default:
862 case Yearly: 863 case Yearly:
863 mRuleStack->raiseWidget( mYearly ); 864 mRuleStack->raiseWidget( mYearly );
864 break; 865 break;
865 } 866 }
866} 867}
867 868
868void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) 869void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
869{ 870{
870// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; 871// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl;
871 872
872 mRecurrenceRange->setDateTimes( start, end ); 873 mRecurrenceRange->setDateTimes( start, end );
873 mExceptions->setDefaults( end ); 874 mExceptions->setDefaults( end );
874 875
875} 876}
876 877
877void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) 878void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool )
878{ 879{
879 880
880 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); 881 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
881 setDateTimes( from, to ); 882 setDateTimes( from, to );
882 883
883 bool enabled = false; 884 bool enabled = false;
884 mEnabledCheck->setChecked( enabled ); 885 mEnabledCheck->setChecked( enabled );
885 setEnabled( enabled ); 886 setEnabled( enabled );
886 887
887 mExceptions->setDefaults( to ); 888 mExceptions->setDefaults( to );
888 mRecurrenceRange->setDefaults( to ); 889 mRecurrenceRange->setDefaults( to );
889 890
890 mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); 891 mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
891 showCurrentRule( mRecurrenceChooser->type() ); 892 showCurrentRule( mRecurrenceChooser->type() );
892 893
893 mDaily->setFrequency( 1 ); 894 mDaily->setFrequency( 1 );
894 895
895 mWeekly->setFrequency( 1 ); 896 mWeekly->setFrequency( 1 );
896 QBitArray days( 7 ); 897 QBitArray days( 7 );
897 days.fill( 0 ); 898 days.fill( 0 );
898 days.setBit( from.date().dayOfWeek()- 1); 899 days.setBit( from.date().dayOfWeek()- 1);
899 mWeekly->setDays( days ); 900 mWeekly->setDays( days );
900 mMonthly->setFrequency( 1 ); 901 mMonthly->setFrequency( 1 );
901 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); 902 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
902 mMonthly->setByDay( from.date().day()-1 ); 903 mMonthly->setByDay( from.date().day()-1 );
903 mYearly->setFrequency( 1 ); 904 mYearly->setFrequency( 1 );
904 mYearly->setByDay( from.date().dayOfYear() ); 905 mYearly->setByDay( from.date().dayOfYear() );
905 mYearly->setByMonth( from.date().month(), from.date().day() ); 906 mYearly->setByMonth( from.date().month(), from.date().day() );
906} 907}
907 908
908void KOEditorRecurrence::readEvent(Event *event) 909void KOEditorRecurrence::readEvent(Incidence *event)
909{ 910{
910 setDefaults( event->dtStart(), event->dtEnd(), true ); 911
912 QDateTime dtEnd;
913 if ( event->type() == "Event" )
914 dtEnd = ((Event*)event)->dtEnd();
915 else
916 dtEnd = ((Todo*)event)->dtDue();
917
918 setDefaults( event->dtStart(), dtEnd, true );
911 QBitArray rDays( 7 ); 919 QBitArray rDays( 7 );
912 QPtrList<Recurrence::rMonthPos> rmp; 920 QPtrList<Recurrence::rMonthPos> rmp;
913 QPtrList<int> rmd; 921 QPtrList<int> rmd;
914 int day = 0; 922 int day = 0;
915 int count = 0; 923 int count = 0;
916 int month = 0; 924 int month = 0;
917 setDateTimes( event->dtStart(), event->dtEnd() ); 925 setDateTimes( event->dtStart(), dtEnd );
918 926
919 Recurrence *r = event->recurrence(); 927 Recurrence *r = event->recurrence();
920 int f = r->frequency(); 928 int f = r->frequency();
921 929
922 int recurs = r->doesRecur(); 930 int recurs = r->doesRecur();
923 931
924 mEnabledCheck->setChecked( recurs ); 932 mEnabledCheck->setChecked( recurs );
925 setEnabled( recurs ); 933 setEnabled( recurs );
926 934
927 int recurrenceType = RecurrenceChooser::Weekly; 935 int recurrenceType = RecurrenceChooser::Weekly;
928 936
929 switch ( recurs ) { 937 switch ( recurs ) {
930 case Recurrence::rNone: 938 case Recurrence::rNone:
931 setDefaults( event->dtStart(), event->dtEnd(), true ); 939 setDefaults( event->dtStart(), dtEnd, true );
932 break; 940 break;
933 case Recurrence::rDaily: 941 case Recurrence::rDaily:
934 recurrenceType = RecurrenceChooser::Daily; 942 recurrenceType = RecurrenceChooser::Daily;
935 mDaily->setFrequency( f ); 943 mDaily->setFrequency( f );
936 break; 944 break;
937 case Recurrence::rWeekly: 945 case Recurrence::rWeekly:
938 recurrenceType = RecurrenceChooser::Weekly; 946 recurrenceType = RecurrenceChooser::Weekly;
939 mWeekly->setFrequency( f ); 947 mWeekly->setFrequency( f );
940 mWeekly->setDays( r->days() ); 948 mWeekly->setDays( r->days() );
941 break; 949 break;
942 case Recurrence::rMonthlyPos: 950 case Recurrence::rMonthlyPos:
943 // we only handle one possibility in the list right now, 951 // we only handle one possibility in the list right now,
944 // so I have hardcoded calls with first(). If we make the GUI 952 // so I have hardcoded calls with first(). If we make the GUI
945 // more extended, this can be changed. 953 // more extended, this can be changed.
946 recurrenceType = RecurrenceChooser::Monthly; 954 recurrenceType = RecurrenceChooser::Monthly;
947 955
948 rmp = r->monthPositions(); 956 rmp = r->monthPositions();
949 if ( rmp.first()->negative ) 957 if ( rmp.first()->negative )
950 count = 5 - rmp.first()->rPos - 1; 958 count = 5 - rmp.first()->rPos - 1;
951 else 959 else
952 count = rmp.first()->rPos - 1; 960 count = rmp.first()->rPos - 1;
953 day = 0; 961 day = 0;
954 while ( !rmp.first()->rDays.testBit( day ) ) ++day; 962 while ( !rmp.first()->rDays.testBit( day ) ) ++day;
955 mMonthly->setByPos( count, day ); 963 mMonthly->setByPos( count, day );
956 964
957 mMonthly->setFrequency( f ); 965 mMonthly->setFrequency( f );
958 966
959 break; 967 break;
960 case Recurrence::rMonthlyDay: 968 case Recurrence::rMonthlyDay:
961 recurrenceType = RecurrenceChooser::Monthly; 969 recurrenceType = RecurrenceChooser::Monthly;
962 970
963 rmd = r->monthDays(); 971 rmd = r->monthDays();
964 day = *rmd.first() - 1; 972 day = *rmd.first() - 1;
965 mMonthly->setByDay( day ); 973 mMonthly->setByDay( day );
966 974
967 mMonthly->setFrequency( f ); 975 mMonthly->setFrequency( f );
968 976
969 break; 977 break;
970 case Recurrence::rYearlyMonth: 978 case Recurrence::rYearlyMonth:
971 { 979 {
972 recurrenceType = RecurrenceChooser::Yearly; 980 recurrenceType = RecurrenceChooser::Yearly;
973 qDebug("Recurrence::rYearlyMonth: "); 981 qDebug("Recurrence::rYearlyMonth: ");
974 day = event->dtStart().date().day(); 982 day = event->dtStart().date().day();
975 rmd = r->yearNums(); 983 rmd = r->yearNums();
976 if ( rmd.count() > 0 ) 984 if ( rmd.count() > 0 )
977 month = *rmd.first(); 985 month = *rmd.first();
978 else 986 else
979 month = event->dtStart().date().month() ; 987 month = event->dtStart().date().month() ;
980 mYearly->setByMonth( month, day ); 988 mYearly->setByMonth( month, day );
981#if 0 989#if 0
982 qDebug("2day = %d ",day ); 990 qDebug("2day = %d ",day );
983 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); 991 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions();
984 int month; 992 int month;
985 if ( !monthlist.isEmpty() ) { 993 if ( !monthlist.isEmpty() ) {
986 month = monthlist.first()->rPos ; 994 month = monthlist.first()->rPos ;
987 } else { 995 } else {
988 month = event->dtStart().date().month() ; 996 month = event->dtStart().date().month() ;
989 } 997 }
990 mYearly->setByMonth( day, month ); 998 mYearly->setByMonth( day, month );
991#endif 999#endif
992 mYearly->setFrequency( f ); 1000 mYearly->setFrequency( f );
993 } 1001 }
994 1002
995 break; 1003 break;
996 case Recurrence::rYearlyDay: 1004 case Recurrence::rYearlyDay:
997 qDebug("Recurrence::rYearlyDay: "); 1005 qDebug("Recurrence::rYearlyDay: ");
998 recurrenceType = RecurrenceChooser::Yearly; 1006 recurrenceType = RecurrenceChooser::Yearly;
999 mYearly->setByDay( event->dtStart().date().dayOfYear() ); 1007 mYearly->setByDay( event->dtStart().date().dayOfYear() );
1000 mYearly->setFrequency( f ); 1008 mYearly->setFrequency( f );
1001 break; 1009 break;
1002 default: 1010 default:
1003 setDefaults( event->dtStart(), event->dtEnd(), true ); 1011 setDefaults( event->dtStart(), dtEnd, true );
1004 break; 1012 break;
1005 } 1013 }
1006 1014
1007 mRecurrenceChooser->setType( recurrenceType ); 1015 mRecurrenceChooser->setType( recurrenceType );
1008 showCurrentRule( recurrenceType ); 1016 showCurrentRule( recurrenceType );
1009 1017
1010 mRecurrenceRange->setDateTimes( event->dtStart() ); 1018 mRecurrenceRange->setDateTimes( event->dtStart() );
1011 1019
1012 if ( r->doesRecur() ) { 1020 if ( r->doesRecur() ) {
1013 mRecurrenceRange->setDuration( r->duration() ); 1021 mRecurrenceRange->setDuration( r->duration() );
1014 if ( r->duration() == 0 ) 1022 if ( r->duration() == 0 )
1015 { 1023 {
1016 if ( r->endDate() < event->dtStart().date() ) 1024 if ( r->endDate() < event->dtStart().date() )
1017 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1025 mRecurrenceRange->setEndDate( event->dtStart().date() );
1018 else 1026 else
1019 mRecurrenceRange->setEndDate( r->endDate() ); 1027 mRecurrenceRange->setEndDate( r->endDate() );
1020 } else 1028 } else
1021 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1029 mRecurrenceRange->setEndDate( event->dtStart().date() );
1022 } 1030 }
1023 1031
1024 mExceptions->setDates( event->exDates() ); 1032 mExceptions->setDates( event->exDates() );
1025} 1033}
1026 1034
1027void KOEditorRecurrence::writeEvent( Event *event ) 1035void KOEditorRecurrence::writeEvent( Incidence *event )
1028{ 1036{
1029 Recurrence *r = event->recurrence(); 1037 Recurrence *r = event->recurrence();
1030 1038
1031 // clear out any old settings; 1039 // clear out any old settings;
1032 r->unsetRecurs(); 1040 r->unsetRecurs();
1033 1041
1034 if ( mEnabledCheck->isChecked() ) { 1042 if ( mEnabledCheck->isChecked() ) {
1035 int duration = mRecurrenceRange->duration(); 1043 int duration = mRecurrenceRange->duration();
1036 QDate endDate; 1044 QDate endDate;
1037 if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); 1045 if ( duration == 0 ) endDate = mRecurrenceRange->endDate();
1038 1046
1039 int recurrenceType = mRecurrenceChooser->type(); 1047 int recurrenceType = mRecurrenceChooser->type();
1040 1048
1041 if ( recurrenceType == RecurrenceChooser::Daily ) { 1049 if ( recurrenceType == RecurrenceChooser::Daily ) {
1042 int freq = mDaily->frequency(); 1050 int freq = mDaily->frequency();
1043 if ( duration != 0 ) r->setDaily( freq, duration ); 1051 if ( duration != 0 ) r->setDaily( freq, duration );
1044 else r->setDaily( freq, endDate ); 1052 else r->setDaily( freq, endDate );
1045 } else if ( recurrenceType == RecurrenceChooser::Weekly ) { 1053 } else if ( recurrenceType == RecurrenceChooser::Weekly ) {
1046 int freq = mWeekly->frequency(); 1054 int freq = mWeekly->frequency();
1047 QBitArray days = mWeekly->days(); 1055 QBitArray days = mWeekly->days();
1048 int j; 1056 int j;
1049 bool found = false; 1057 bool found = false;
1050 for (j = 0; j < 7 ; ++j ) { 1058 for (j = 0; j < 7 ; ++j ) {
1051 found |=days.at(j); 1059 found |=days.at(j);
1052 } 1060 }
1053 if ( !found ) { 1061 if ( !found ) {
1054 days.setBit( event->dtStart().date().dayOfWeek()-1); 1062 days.setBit( event->dtStart().date().dayOfWeek()-1);
1055 qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); 1063 qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1);
1056 } 1064 }
1057 if ( duration != 0 ) r->setWeekly( freq, days, duration ); 1065 if ( duration != 0 ) r->setWeekly( freq, days, duration );
1058 else r->setWeekly( freq, days, endDate ); 1066 else r->setWeekly( freq, days, endDate );
1059 } else if ( recurrenceType == RecurrenceChooser::Monthly ) { 1067 } else if ( recurrenceType == RecurrenceChooser::Monthly ) {
1060 int freq = mMonthly->frequency(); 1068 int freq = mMonthly->frequency();
1061 if ( mMonthly->byPos() ) { 1069 if ( mMonthly->byPos() ) {
1062 int pos = mMonthly->count(); 1070 int pos = mMonthly->count();
1063 1071
1064 QBitArray days( 7 ); 1072 QBitArray days( 7 );
1065 days.fill( false ); 1073 days.fill( false );
1066 1074
1067 days.setBit( mMonthly->weekday() ); 1075 days.setBit( mMonthly->weekday() );
1068 if ( duration != 0 ) 1076 if ( duration != 0 )
1069 r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); 1077 r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
1070 else 1078 else
1071 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 1079 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
1072 r->addMonthlyPos( pos, days ); 1080 r->addMonthlyPos( pos, days );
1073 } else { 1081 } else {
1074 // it's by day 1082 // it's by day
1075 int day = mMonthly->day(); 1083 int day = mMonthly->day();
1076 1084
1077 if ( duration != 0 ) { 1085 if ( duration != 0 ) {
1078 r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); 1086 r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
1079 } else { 1087 } else {
1080 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 1088 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
1081 } 1089 }
1082 r->addMonthlyDay( day ); 1090 r->addMonthlyDay( day );
1083 } 1091 }
1084 } else if ( recurrenceType == RecurrenceChooser::Yearly ) { 1092 } else if ( recurrenceType == RecurrenceChooser::Yearly ) {
1085 qDebug("RecurrenceChooser::Yearly "); 1093 qDebug("RecurrenceChooser::Yearly ");
1086 int freq = mYearly->frequency(); 1094 int freq = mYearly->frequency();
1087 if ( mYearly->byDay() ) { 1095 if ( mYearly->byDay() ) {
1088 if ( duration != 0 ) { 1096 if ( duration != 0 ) {
1089 r->setYearly( Recurrence::rYearlyDay, freq, duration ); 1097 r->setYearly( Recurrence::rYearlyDay, freq, duration );
1090 } else { 1098 } else {
1091 r->setYearly( Recurrence::rYearlyDay, freq, endDate ); 1099 r->setYearly( Recurrence::rYearlyDay, freq, endDate );
1092 } 1100 }
1093 r->addYearlyNum( event->dtStart().date().dayOfYear() ); 1101 r->addYearlyNum( event->dtStart().date().dayOfYear() );
1094 } else { 1102 } else {
1095 if ( duration != 0 ) { 1103 if ( duration != 0 ) {
1096 r->setYearly( Recurrence::rYearlyMonth, freq, duration ); 1104 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1097 } else { 1105 } else {
1098 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 1106 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
1099 } 1107 }
1100 r->addYearlyNum( mYearly->month() ); 1108 r->addYearlyNum( mYearly->month() );
1101 } 1109 }
1102 1110
1103 } 1111 }
1104 1112
1105 event->setExDates( mExceptions->dates() ); 1113 event->setExDates( mExceptions->dates() );
1106 } 1114 }
1107} 1115}
1108 1116
1109void KOEditorRecurrence::setDateTimeStr( const QString &str ) 1117void KOEditorRecurrence::setDateTimeStr( const QString &str )
1110{ 1118{
1111 mDateTimeLabel->setText( str ); 1119 mDateTimeLabel->setText( str );
1112} 1120}
1113 1121
1114bool KOEditorRecurrence::validateInput() 1122bool KOEditorRecurrence::validateInput()
1115{ 1123{
1116 // Check input here 1124 // Check input here
1117 1125
1118 return true; 1126 return true;
1119} 1127}
1120 1128
1121void KOEditorRecurrence::showExceptionsDialog() 1129void KOEditorRecurrence::showExceptionsDialog()
1122{ 1130{
1123 DateList dates = mExceptions->dates(); 1131 DateList dates = mExceptions->dates();
1124 int result = mExceptionsDialog->exec(); 1132 int result = mExceptionsDialog->exec();
1125 if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); 1133 if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
1126} 1134}
1127 1135
1128void KOEditorRecurrence::showRecurrenceRangeDialog() 1136void KOEditorRecurrence::showRecurrenceRangeDialog()
1129{ 1137{
1130 int duration = mRecurrenceRange->duration(); 1138 int duration = mRecurrenceRange->duration();
1131 QDate endDate = mRecurrenceRange->endDate(); 1139 QDate endDate = mRecurrenceRange->endDate();
1132 1140
1133 int result = mRecurrenceRangeDialog->exec(); 1141 int result = mRecurrenceRangeDialog->exec();
1134 if ( result == QDialog::Rejected ) { 1142 if ( result == QDialog::Rejected ) {
1135 mRecurrenceRange->setDuration( duration ); 1143 mRecurrenceRange->setDuration( duration );
1136 mRecurrenceRange->setEndDate( endDate ); 1144 mRecurrenceRange->setEndDate( endDate );
1137 } 1145 }
1138 1146
1139} 1147}
diff --git a/korganizer/koeditorrecurrence.h b/korganizer/koeditorrecurrence.h
index 2b59085..a15afcb 100644
--- a/korganizer/koeditorrecurrence.h
+++ b/korganizer/koeditorrecurrence.h
@@ -1,324 +1,324 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef _KOEDITORRECURRENCE_H 23#ifndef _KOEDITORRECURRENCE_H
24#define _KOEDITORRECURRENCE_H 24#define _KOEDITORRECURRENCE_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qgroupbox.h> 30#include <qgroupbox.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qmultilineedit.h> 33#include <qmultilineedit.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36 36
37#include <kdialogbase.h> 37#include <kdialogbase.h>
38 38
39#include <libkcal/event.h> 39#include <libkcal/event.h>
40 40
41#include "ktimeedit.h" 41#include "ktimeedit.h"
42 42
43class QWidgetStack; 43class QWidgetStack;
44class QSpinBox; 44class QSpinBox;
45 45
46class KDateEdit; 46class KDateEdit;
47 47
48using namespace KCal; 48using namespace KCal;
49 49
50class RecurBase : public QWidget 50class RecurBase : public QWidget
51{ 51{
52 public: 52 public:
53 RecurBase( QWidget *parent = 0, const char *name = 0 ); 53 RecurBase( QWidget *parent = 0, const char *name = 0 );
54 54
55 void setFrequency( int ); 55 void setFrequency( int );
56 int frequency(); 56 int frequency();
57 57
58 QWidget *frequencyEdit(); 58 QWidget *frequencyEdit();
59 59
60 private: 60 private:
61 QSpinBox *mFrequencyEdit; 61 QSpinBox *mFrequencyEdit;
62}; 62};
63 63
64class RecurDaily : public RecurBase 64class RecurDaily : public RecurBase
65{ 65{
66 public: 66 public:
67 RecurDaily( QWidget *parent = 0, const char *name = 0 ); 67 RecurDaily( QWidget *parent = 0, const char *name = 0 );
68}; 68};
69 69
70class RecurWeekly : public RecurBase 70class RecurWeekly : public RecurBase
71{ 71{
72 public: 72 public:
73 RecurWeekly( QWidget *parent = 0, const char *name = 0 ); 73 RecurWeekly( QWidget *parent = 0, const char *name = 0 );
74 74
75 void setDays( const QBitArray & ); 75 void setDays( const QBitArray & );
76 QBitArray days(); 76 QBitArray days();
77 77
78 private: 78 private:
79 QCheckBox *mDayBoxes[7]; 79 QCheckBox *mDayBoxes[7];
80}; 80};
81 81
82class RecurMonthly : public RecurBase 82class RecurMonthly : public RecurBase
83{ 83{
84 public: 84 public:
85 RecurMonthly( QWidget *parent = 0, const char *name = 0 ); 85 RecurMonthly( QWidget *parent = 0, const char *name = 0 );
86 86
87 void setByDay( int day ); 87 void setByDay( int day );
88 void setByPos( int count, int weekday ); 88 void setByPos( int count, int weekday );
89 89
90 bool byDay(); 90 bool byDay();
91 bool byPos(); 91 bool byPos();
92 92
93 int day(); 93 int day();
94 94
95 int count(); 95 int count();
96 int weekday(); 96 int weekday();
97 97
98 private: 98 private:
99 QRadioButton *mByDayRadio; 99 QRadioButton *mByDayRadio;
100 QComboBox *mByDayCombo; 100 QComboBox *mByDayCombo;
101 101
102 QRadioButton *mByPosRadio; 102 QRadioButton *mByPosRadio;
103 QComboBox *mByPosCountCombo; 103 QComboBox *mByPosCountCombo;
104 QComboBox *mByPosWeekdayCombo; 104 QComboBox *mByPosWeekdayCombo;
105}; 105};
106 106
107class RecurYearly : public RecurBase 107class RecurYearly : public RecurBase
108{ 108{
109 public: 109 public:
110 RecurYearly( QWidget *parent = 0, const char *name = 0 ); 110 RecurYearly( QWidget *parent = 0, const char *name = 0 );
111 111
112 void setByDay( int doy ); 112 void setByDay( int doy );
113 void setByMonth( int month, int day ); 113 void setByMonth( int month, int day );
114 114
115 bool byMonth(); 115 bool byMonth();
116 bool byDay(); 116 bool byDay();
117 117
118 int month(); 118 int month();
119 int day(); 119 int day();
120 120
121 private: 121 private:
122 int mDay; 122 int mDay;
123 QRadioButton *mByMonthRadio; 123 QRadioButton *mByMonthRadio;
124 QComboBox *mByMonthCombo; 124 QComboBox *mByMonthCombo;
125 QLabel* mByDayLabel; 125 QLabel* mByDayLabel;
126 QLabel* mDayOfLabel; 126 QLabel* mDayOfLabel;
127 QRadioButton *mByDayRadio; 127 QRadioButton *mByDayRadio;
128}; 128};
129 129
130class RecurrenceChooser : public QWidget 130class RecurrenceChooser : public QWidget
131{ 131{
132 Q_OBJECT 132 Q_OBJECT
133 public: 133 public:
134 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 ); 134 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 );
135 135
136 enum { Daily, Weekly, Monthly, Yearly }; 136 enum { Daily, Weekly, Monthly, Yearly };
137 137
138 void setType( int ); 138 void setType( int );
139 int type(); 139 int type();
140 140
141 signals: 141 signals:
142 void chosen( int ); 142 void chosen( int );
143 143
144 protected slots: 144 protected slots:
145 void emitChoice(); 145 void emitChoice();
146 146
147 private: 147 private:
148 QComboBox *mTypeCombo; 148 QComboBox *mTypeCombo;
149 149
150 QRadioButton *mDailyButton; 150 QRadioButton *mDailyButton;
151 QRadioButton *mWeeklyButton; 151 QRadioButton *mWeeklyButton;
152 QRadioButton *mMonthlyButton; 152 QRadioButton *mMonthlyButton;
153 QRadioButton *mYearlyButton; 153 QRadioButton *mYearlyButton;
154}; 154};
155 155
156class ExceptionsBase 156class ExceptionsBase
157{ 157{
158 public: 158 public:
159 virtual void setDefaults( const QDateTime &from ) = 0; 159 virtual void setDefaults( const QDateTime &from ) = 0;
160 virtual void setDates( const DateList & ) = 0; 160 virtual void setDates( const DateList & ) = 0;
161 virtual DateList dates() = 0; 161 virtual DateList dates() = 0;
162}; 162};
163 163
164class ExceptionsWidget : public QWidget, public ExceptionsBase 164class ExceptionsWidget : public QWidget, public ExceptionsBase
165{ 165{
166 Q_OBJECT 166 Q_OBJECT
167 public: 167 public:
168 ExceptionsWidget( QWidget *parent = 0, const char *name = 0 ); 168 ExceptionsWidget( QWidget *parent = 0, const char *name = 0 );
169 169
170 void setDefaults( const QDateTime &from ); 170 void setDefaults( const QDateTime &from );
171 171
172 void setDates( const DateList & ); 172 void setDates( const DateList & );
173 DateList dates(); 173 DateList dates();
174 174
175 protected slots: 175 protected slots:
176 void addException(); 176 void addException();
177 void changeException(); 177 void changeException();
178 void deleteException(); 178 void deleteException();
179 179
180 private: 180 private:
181 KDateEdit *mExceptionDateEdit; 181 KDateEdit *mExceptionDateEdit;
182 QListBox *mExceptionList; 182 QListBox *mExceptionList;
183 DateList mExceptionDates; 183 DateList mExceptionDates;
184}; 184};
185 185
186class ExceptionsDialog : public KDialogBase, public ExceptionsBase 186class ExceptionsDialog : public KDialogBase, public ExceptionsBase
187{ 187{
188 public: 188 public:
189 ExceptionsDialog( QWidget *parent, const char *name = 0 ); 189 ExceptionsDialog( QWidget *parent, const char *name = 0 );
190 190
191 void setDefaults( const QDateTime &from ); 191 void setDefaults( const QDateTime &from );
192 192
193 void setDates( const DateList & ); 193 void setDates( const DateList & );
194 DateList dates(); 194 DateList dates();
195 195
196 private: 196 private:
197 ExceptionsWidget *mExceptions; 197 ExceptionsWidget *mExceptions;
198}; 198};
199 199
200class RecurrenceRangeBase 200class RecurrenceRangeBase
201{ 201{
202 public: 202 public:
203 virtual void setDefaults( const QDateTime &from ) = 0; 203 virtual void setDefaults( const QDateTime &from ) = 0;
204 204
205 virtual void setDuration( int ) = 0; 205 virtual void setDuration( int ) = 0;
206 virtual int duration() = 0; 206 virtual int duration() = 0;
207 207
208 virtual void setEndDate( const QDate & ) = 0; 208 virtual void setEndDate( const QDate & ) = 0;
209 virtual QDate endDate() = 0; 209 virtual QDate endDate() = 0;
210 210
211 virtual void setDateTimes( const QDateTime &start, 211 virtual void setDateTimes( const QDateTime &start,
212 const QDateTime &end = QDateTime() ) = 0; 212 const QDateTime &end = QDateTime() ) = 0;
213}; 213};
214 214
215class RecurrenceRangeWidget : public QWidget, public RecurrenceRangeBase 215class RecurrenceRangeWidget : public QWidget, public RecurrenceRangeBase
216{ 216{
217 Q_OBJECT 217 Q_OBJECT
218 public: 218 public:
219 RecurrenceRangeWidget( QWidget *parent = 0, const char *name = 0 ); 219 RecurrenceRangeWidget( QWidget *parent = 0, const char *name = 0 );
220 220
221 void setDefaults( const QDateTime &from ); 221 void setDefaults( const QDateTime &from );
222 222
223 void setDuration( int ); 223 void setDuration( int );
224 int duration(); 224 int duration();
225 225
226 void setEndDate( const QDate & ); 226 void setEndDate( const QDate & );
227 QDate endDate(); 227 QDate endDate();
228 228
229 void setDateTimes( const QDateTime &start, 229 void setDateTimes( const QDateTime &start,
230 const QDateTime &end = QDateTime() ); 230 const QDateTime &end = QDateTime() );
231 231
232 protected slots: 232 protected slots:
233 void showCurrentRange(); 233 void showCurrentRange();
234 234
235 private: 235 private:
236 QGroupBox *mRangeGroupBox; 236 QGroupBox *mRangeGroupBox;
237 QLabel *mStartDateLabel; 237 QLabel *mStartDateLabel;
238 QRadioButton *mNoEndDateButton; 238 QRadioButton *mNoEndDateButton;
239 QRadioButton *mEndDurationButton; 239 QRadioButton *mEndDurationButton;
240 QSpinBox *mEndDurationEdit; 240 QSpinBox *mEndDurationEdit;
241 QRadioButton *mEndDateButton; 241 QRadioButton *mEndDateButton;
242 KDateEdit *mEndDateEdit; 242 KDateEdit *mEndDateEdit;
243}; 243};
244 244
245class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase 245class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase
246{ 246{
247 public: 247 public:
248 RecurrenceRangeDialog( QWidget *parent = 0, const char *name = 0 ); 248 RecurrenceRangeDialog( QWidget *parent = 0, const char *name = 0 );
249 249
250 void setDefaults( const QDateTime &from ); 250 void setDefaults( const QDateTime &from );
251 251
252 void setDuration( int ); 252 void setDuration( int );
253 int duration(); 253 int duration();
254 254
255 void setEndDate( const QDate & ); 255 void setEndDate( const QDate & );
256 QDate endDate(); 256 QDate endDate();
257 257
258 void setDateTimes( const QDateTime &start, 258 void setDateTimes( const QDateTime &start,
259 const QDateTime &end = QDateTime() ); 259 const QDateTime &end = QDateTime() );
260 260
261 private: 261 private:
262 RecurrenceRangeWidget *mRecurrenceRangeWidget; 262 RecurrenceRangeWidget *mRecurrenceRangeWidget;
263}; 263};
264 264
265class KOEditorRecurrence : public QWidget 265class KOEditorRecurrence : public QWidget
266{ 266{
267 Q_OBJECT 267 Q_OBJECT
268 public: 268 public:
269 KOEditorRecurrence ( QWidget *parent = 0, const char *name = 0 ); 269 KOEditorRecurrence ( QWidget *parent = 0, const char *name = 0 );
270 virtual ~KOEditorRecurrence(); 270 virtual ~KOEditorRecurrence();
271 271
272 enum { Daily, Weekly, Monthly, Yearly }; 272 enum { Daily, Weekly, Monthly, Yearly };
273 273
274 /** Set widgets to default values */ 274 /** Set widgets to default values */
275 void setDefaults( QDateTime from, QDateTime to, bool allday ); 275 void setDefaults( QDateTime from, QDateTime to, bool allday );
276 /** Read event object and setup widgets accordingly */ 276 /** Read event object and setup widgets accordingly */
277 void readEvent( Event * ); 277 void readEvent( Incidence * );
278 /** Write event settings to event object */ 278 /** Write event settings to event object */
279 void writeEvent( Event * ); 279 void writeEvent( Incidence * );
280 280
281 /** Check if the input is valid. */ 281 /** Check if the input is valid. */
282 bool validateInput(); 282 bool validateInput();
283 283
284 public slots: 284 public slots:
285 void setEnabled( bool ); 285 void setEnabled( bool );
286 void setDateTimes( QDateTime start, QDateTime end ); 286 void setDateTimes( QDateTime start, QDateTime end );
287 void setDateTimeStr( const QString & ); 287 void setDateTimeStr( const QString & );
288 288
289 signals: 289 signals:
290 void dateTimesChanged( QDateTime start, QDateTime end ); 290 void dateTimesChanged( QDateTime start, QDateTime end );
291 291
292 protected slots: 292 protected slots:
293 void showCurrentRule( int ); 293 void showCurrentRule( int );
294 void showExceptionsDialog(); 294 void showExceptionsDialog();
295 void showRecurrenceRangeDialog(); 295 void showRecurrenceRangeDialog();
296 296
297 private: 297 private:
298 QCheckBox *mEnabledCheck; 298 QCheckBox *mEnabledCheck;
299 299
300 QGroupBox *mTimeGroupBox; 300 QGroupBox *mTimeGroupBox;
301 QLabel *mDateTimeLabel; 301 QLabel *mDateTimeLabel;
302 302
303 QGroupBox *mRuleBox; 303 QGroupBox *mRuleBox;
304 QWidgetStack *mRuleStack; 304 QWidgetStack *mRuleStack;
305 RecurrenceChooser *mRecurrenceChooser; 305 RecurrenceChooser *mRecurrenceChooser;
306 306
307 RecurDaily *mDaily; 307 RecurDaily *mDaily;
308 RecurWeekly *mWeekly; 308 RecurWeekly *mWeekly;
309 RecurMonthly *mMonthly; 309 RecurMonthly *mMonthly;
310 RecurYearly *mYearly; 310 RecurYearly *mYearly;
311 311
312 RecurrenceRangeBase *mRecurrenceRange; 312 RecurrenceRangeBase *mRecurrenceRange;
313 RecurrenceRangeWidget *mRecurrenceRangeWidget; 313 RecurrenceRangeWidget *mRecurrenceRangeWidget;
314 RecurrenceRangeDialog *mRecurrenceRangeDialog; 314 RecurrenceRangeDialog *mRecurrenceRangeDialog;
315 QPushButton *mRecurrenceRangeButton; 315 QPushButton *mRecurrenceRangeButton;
316 316
317 ExceptionsBase *mExceptions; 317 ExceptionsBase *mExceptions;
318 ExceptionsDialog *mExceptionsDialog; 318 ExceptionsDialog *mExceptionsDialog;
319 ExceptionsWidget *mExceptionsWidget; 319 ExceptionsWidget *mExceptionsWidget;
320 QPushButton *mExceptionsButton; 320 QPushButton *mExceptionsButton;
321 321
322}; 322};
323 323
324#endif 324#endif
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp
index 70dfbd1..069dda8 100644
--- a/korganizer/kotodoeditor.cpp
+++ b/korganizer/kotodoeditor.cpp
@@ -1,383 +1,426 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown 3 Copyright (c) 1997, 1998 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 <qtooltip.h> 25#include <qtooltip.h>
26#include <qframe.h> 26#include <qframe.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qhbox.h> 29#include <qhbox.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qtabwidget.h>
33 34
34#include <kiconloader.h> 35#include <kiconloader.h>
35#include <klocale.h> 36#include <klocale.h>
36#include <kfiledialog.h> 37#include <kfiledialog.h>
37#include <kstandarddirs.h> 38#include <kstandarddirs.h>
38#include <kmessagebox.h> 39#include <kmessagebox.h>
39 40
40#include <libkdepim/categoryselectdialog.h> 41#include <libkdepim/categoryselectdialog.h>
41#include <libkcal/calendarlocal.h> 42#include <libkcal/calendarlocal.h>
42#include <libkcal/calendarresources.h> 43#include <libkcal/calendarresources.h>
43#include <libkcal/resourcecalendar.h> 44#include <libkcal/resourcecalendar.h>
44#include <libkcal/icalformat.h> 45#include <libkcal/icalformat.h>
45#include <kresources/resourceselectdialog.h> 46#include <kresources/resourceselectdialog.h>
47#include <libkdepim/kdateedit.h>
46 48
47#include "koprefs.h" 49#include "koprefs.h"
48#include "kolocationbox.h" 50#include "kolocationbox.h"
49 51
50#include "kotodoeditor.h" 52#include "kotodoeditor.h"
51extern int globalFlagBlockAgenda; 53extern int globalFlagBlockAgenda;
52 54
53KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) : 55KOTodoEditor::KOTodoEditor( Calendar *calendar, QWidget *parent ) :
54 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent ) 56 KOIncidenceEditor( i18n("Edit To-Do"), calendar, parent )
55{ 57{
56 mTodo = 0; 58 mTodo = 0;
57 mRelatedTodo = 0; 59 mRelatedTodo = 0;
58 findButton(User1)->hide(); 60 findButton(User1)->hide();
59 init(); 61 init();
60} 62}
61 63
62KOTodoEditor::~KOTodoEditor() 64KOTodoEditor::~KOTodoEditor()
63{ 65{
64 emit dialogClose( mTodo ); 66 emit dialogClose( mTodo );
65} 67}
66 68
67void KOTodoEditor::init() 69void KOTodoEditor::init()
68{ 70{
69 setupGeneral(); 71 setupGeneral();
70 setupAttendeesTab(); 72 setupAttendeesTab();
73 setupRecurrence();
74 connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence()));
71} 75}
76void KOTodoEditor::setupRecurrence()
77{
78 QFrame *topFrame = addPage( i18n("Recurrence") );
79 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
80
81 mRecurrence = new KOEditorRecurrence( topFrame );
82 topLayout->addWidget( mRecurrence );
83}
84
72void KOTodoEditor::setCategories( QString s ) 85void KOTodoEditor::setCategories( QString s )
73{ 86{
74 mGeneral->setCategories(s); 87 mGeneral->setCategories(s);
75} 88}
76void KOTodoEditor::setSecrecy( int sec ) 89void KOTodoEditor::setSecrecy( int sec )
77{ 90{
78 mGeneral->setSecrecy( sec ); 91 mGeneral->setSecrecy( sec );
79} 92}
80void KOTodoEditor::reload() 93void KOTodoEditor::reload()
81{ 94{
82 if ( mTodo ) readTodo( mTodo ); 95 if ( mTodo ) readTodo( mTodo );
83} 96}
84 97
85void KOTodoEditor::setupGeneral() 98void KOTodoEditor::setupGeneral()
86{ 99{
87 mGeneral = new KOEditorGeneralTodo(this); 100 mGeneral = new KOEditorGeneralTodo(this);
88 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); 101 connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) );
89 102
90 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); 103 // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
91 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), 104 //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)),
92 // mGeneral,SLOT(setCategories(const QString &))); 105 // mGeneral,SLOT(setCategories(const QString &)));
93 106
94 if (KOPrefs::instance()->mCompactDialogs) { 107 if (KOPrefs::instance()->mCompactDialogs) {
95 QFrame *topFrame = addPage(i18n("General")); 108 QFrame *topFrame = addPage(i18n("General"));
96 109
97 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 110 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
98 if ( QApplication::desktop()->width() < 480 ) { 111 if ( QApplication::desktop()->width() < 480 ) {
99 topLayout->setMargin(1); 112 topLayout->setMargin(1);
100 topLayout->setSpacing(1); 113 topLayout->setSpacing(1);
101 } else { 114 } else {
102 topLayout->setMargin(marginHint()-1); 115 topLayout->setMargin(marginHint()-1);
103 topLayout->setSpacing(spacingHint()-1); 116 topLayout->setSpacing(spacingHint()-1);
104 } 117 }
105 mGeneral->initHeader(topFrame,topLayout); 118 mGeneral->initHeader(topFrame,topLayout);
106 mGeneral->initTime(topFrame,topLayout); 119 mGeneral->initTime(topFrame,topLayout);
107 mGeneral->initAlarm(topFrame,topLayout); 120 mGeneral->initAlarm(topFrame,topLayout);
108 mGeneral->enableAlarm( false ); 121 mGeneral->enableAlarm( false );
109 122
110 123
111 QBoxLayout *priorityLayout; 124 QBoxLayout *priorityLayout;
112 if ( QApplication::desktop()->width() < 500 ) 125 if ( QApplication::desktop()->width() < 500 )
113 priorityLayout = new QVBoxLayout( topLayout ); 126 priorityLayout = new QVBoxLayout( topLayout );
114 else 127 else
115 priorityLayout = new QHBoxLayout( topLayout ); 128 priorityLayout = new QHBoxLayout( topLayout );
116 QWidget* prioWidget = new QWidget (topFrame); 129 QWidget* prioWidget = new QWidget (topFrame);
117 priorityLayout->addWidget( prioWidget ); 130 priorityLayout->addWidget( prioWidget );
118 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget); 131 QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget);
119 132
120 133
121 QIconSet icon; 134 QIconSet icon;
122 if ( QApplication::desktop()->width() < 321 ) 135 if ( QApplication::desktop()->width() < 321 )
123 icon = SmallIcon("fileexport16"); 136 icon = SmallIcon("fileexport16");
124 else 137 else
125 icon = SmallIcon("fileexport"); 138 icon = SmallIcon("fileexport");
126 QPushButton * saveTemplate = new QPushButton( prioWidget); 139 QPushButton * saveTemplate = new QPushButton( prioWidget);
127 saveTemplate->setIconSet (icon ) ; 140 saveTemplate->setIconSet (icon ) ;
128 int size = saveTemplate->sizeHint().height(); 141 int size = saveTemplate->sizeHint().height();
129 saveTemplate->setFixedSize( size, size ); 142 saveTemplate->setFixedSize( size, size );
130 if ( QApplication::desktop()->width() < 321 ) 143 if ( QApplication::desktop()->width() < 321 )
131 icon = SmallIcon("fileimport16"); 144 icon = SmallIcon("fileimport16");
132 else 145 else
133 icon = SmallIcon("fileimport"); 146 icon = SmallIcon("fileimport");
134 QPushButton * loadTemplate = new QPushButton( prioWidget); 147 QPushButton * loadTemplate = new QPushButton( prioWidget);
135 loadTemplate->setIconSet (icon ) ; 148 loadTemplate->setIconSet (icon ) ;
136 loadTemplate->setFixedSize( size, size ); 149 loadTemplate->setFixedSize( size, size );
137 150
138 priorityLayout2->addWidget(loadTemplate); 151 priorityLayout2->addWidget(loadTemplate);
139 priorityLayout2->addWidget(saveTemplate); 152 priorityLayout2->addWidget(saveTemplate);
140 mGeneral->initPriority(prioWidget,priorityLayout2); 153 mGeneral->initPriority(prioWidget,priorityLayout2);
141 mGeneral->initCategories( topFrame, priorityLayout ); 154 mGeneral->initCategories( topFrame, priorityLayout );
142 topLayout->addStretch(1); 155 topLayout->addStretch(1);
143 156
144 QFrame *topFrame2 = addPage(i18n("Details")); 157 QFrame *topFrame2 = addPage(i18n("Details"));
145 158
146 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); 159 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
147 topLayout2->setMargin(marginHint()); 160 topLayout2->setMargin(marginHint());
148 topLayout2->setSpacing(spacingHint()); 161 topLayout2->setSpacing(spacingHint());
149 162
150 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); 163 QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 );
151 mGeneral->initCompletion(topFrame2,completionLayout); 164 mGeneral->initCompletion(topFrame2,completionLayout);
152 165
153 166
154 mGeneral->initSecrecy( topFrame2, topLayout2 ); 167 mGeneral->initSecrecy( topFrame2, topLayout2 );
155 mGeneral->initDescription(topFrame2,topLayout2); 168 mGeneral->initDescription(topFrame2,topLayout2);
156 169
157 // QHBox * hb = new QHBox ( topFrame2 ); 170 // QHBox * hb = new QHBox ( topFrame2 );
158 // topLayout2->addWidget(hb); 171 // topLayout2->addWidget(hb);
159 // hb->setSpacing( 3 ); 172 // hb->setSpacing( 3 );
160 173
161 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 174 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
162 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 175 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
163 176
164 } else { 177 } else {
165 QFrame *topFrame = addPage(i18n("General")); 178 QFrame *topFrame = addPage(i18n("General"));
166 179
167 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 180 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
168 topLayout->setSpacing(spacingHint()); 181 topLayout->setSpacing(spacingHint());
169 182
170 mGeneral->initHeader(topFrame,topLayout); 183 mGeneral->initHeader(topFrame,topLayout);
171 mGeneral->initTime(topFrame,topLayout); 184 mGeneral->initTime(topFrame,topLayout);
172 mGeneral->initStatus(topFrame,topLayout); 185 mGeneral->initStatus(topFrame,topLayout);
173 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); 186 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
174 mGeneral->initAlarm(topFrame,alarmLineLayout); 187 mGeneral->initAlarm(topFrame,alarmLineLayout);
175 mGeneral->initDescription(topFrame,topLayout); 188 mGeneral->initDescription(topFrame,topLayout);
176 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); 189 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
177 mGeneral->initCategories( topFrame, detailsLayout ); 190 mGeneral->initCategories( topFrame, detailsLayout );
178 mGeneral->initSecrecy( topFrame, detailsLayout ); 191 mGeneral->initSecrecy( topFrame, detailsLayout );
179 } 192 }
180 mGeneral->finishSetup(); 193 mGeneral->finishSetup();
181 194
182} 195}
183 196
184void KOTodoEditor::editTodo(Todo *todo, bool editDescription) 197void KOTodoEditor::editTodo(Todo *todo, bool editDescription)
185{ 198{
186 //init(); 199 //init();
187 200
188 mTodo = todo; 201 mTodo = todo;
189 readTodo(mTodo); 202 readTodo(mTodo);
190 if ( editDescription ) { 203 if ( editDescription ) {
191 showPage( 1 ); 204 showPage( 1 );
192 mGeneral->setFocusOn( 1 ); 205 mGeneral->setFocusOn( 1 );
193 } else { 206 } else {
194 showPage( 0 ); 207 showPage( 0 );
195 mGeneral->setFocusOn( 2 ); 208 mGeneral->setFocusOn( 2 );
196 } 209 }
210 checkRecurrence();
197} 211}
198 212
199void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) 213void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay)
200{ 214{
201 //init(); 215 //init();
202 216
203 mTodo = 0; 217 mTodo = 0;
204 setDefaults(due,relatedTodo,allDay); 218 setDefaults(due,relatedTodo,allDay);
205} 219}
206 220
207void KOTodoEditor::loadDefaults() 221void KOTodoEditor::loadDefaults()
208{ 222{
209 setDefaults(QDateTime::currentDateTime().addDays(7),0,false); 223 setDefaults(QDateTime::currentDateTime().addDays(7),0,false);
210} 224}
211 225
212bool KOTodoEditor::processInput( bool emitTime ) 226bool KOTodoEditor::processInput( bool emitTime )
213{ 227{
214 if (!validateInput()) return false; 228 if (!validateInput()) return false;
215 229
216 Todo *todo = 0; 230 Todo *todo = 0;
217 231
218 if (mTodo) todo = mTodo; 232 if (mTodo) todo = mTodo;
219 else { 233 else {
220 todo = new Todo; 234 todo = new Todo;
221 todo->setOrganizer(KOPrefs::instance()->email()); 235 todo->setOrganizer(KOPrefs::instance()->email());
222 } 236 }
223 237
224 writeTodo(todo); 238 writeTodo(todo);
225 if ( emitTime ) { 239 if ( emitTime ) {
226 globalFlagBlockAgenda = 1; 240 globalFlagBlockAgenda = 1;
227 emit showAgendaView( false ); 241 emit showAgendaView( false );
228 if ( todo->hasDueDate() ) 242 if ( todo->hasDueDate() )
229 emit jumpToTime( todo->dtDue().date() ); 243 emit jumpToTime( todo->dtDue().date() );
230 globalFlagBlockAgenda = 2; 244 globalFlagBlockAgenda = 2;
231 } 245 }
232 if (mTodo) { 246 if (mTodo) {
233 todo->setRevision(todo->revision()+1); 247 todo->setRevision(todo->revision()+1);
234 emit todoChanged(todo); 248 emit todoChanged(todo);
235 } else { 249 } else {
236 mCalendar->addTodo(todo); 250 mCalendar->addTodo(todo);
237 mTodo = todo; 251 mTodo = todo;
238 emit todoAdded(todo); 252 emit todoAdded(todo);
239 } 253 }
240 254
241 return true; 255 return true;
242} 256}
243 257
244void KOTodoEditor::deleteTodo() 258void KOTodoEditor::deleteTodo()
245{ 259{
246 if (mTodo) { 260 if (mTodo) {
247 if (KOPrefs::instance()->mConfirm) { 261 if (KOPrefs::instance()->mConfirm) {
248 switch (msgItemDelete()) { 262 switch (msgItemDelete()) {
249 case KMessageBox::Continue: // OK 263 case KMessageBox::Continue: // OK
250 emit todoToBeDeleted(mTodo); 264 emit todoToBeDeleted(mTodo);
251 emit dialogClose(mTodo); 265 emit dialogClose(mTodo);
252 mCalendar->deleteTodo(mTodo); 266 mCalendar->deleteTodo(mTodo);
253 emit todoDeleted(); 267 emit todoDeleted();
254 reject(); 268 reject();
255 break; 269 break;
256 } 270 }
257 } 271 }
258 else { 272 else {
259 emit todoToBeDeleted(mTodo); 273 emit todoToBeDeleted(mTodo);
260 emit dialogClose(mTodo); 274 emit dialogClose(mTodo);
261 mCalendar->deleteTodo(mTodo); 275 mCalendar->deleteTodo(mTodo);
262 emit todoDeleted(); 276 emit todoDeleted();
263 reject(); 277 reject();
264 } 278 }
265 } else { 279 } else {
266 reject(); 280 reject();
267 } 281 }
268} 282}
269 283
270void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) 284void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay)
271{ 285{
272 mRelatedTodo = relatedEvent; 286 mRelatedTodo = relatedEvent;
273 287
274 mGeneral->setDefaults(due,allDay); 288 mGeneral->setDefaults(due,allDay);
275 mDetails->setDefaults(); 289 mDetails->setDefaults();
276 showPage( 0 ); 290 showPage( 0 );
277 if ( mRelatedTodo ) { 291 if ( mRelatedTodo ) {
278 mGeneral->setCategories (mRelatedTodo->categoriesStr ()); 292 mGeneral->setCategories (mRelatedTodo->categoriesStr ());
279 mGeneral->setSecrecy (mRelatedTodo->secrecy ()); 293 mGeneral->setSecrecy (mRelatedTodo->secrecy ());
280 if ( mRelatedTodo->priority() < 3 ) 294 if ( mRelatedTodo->priority() < 3 )
281 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); 295 mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1);
282 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); 296 mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": ");
283 int len = mRelatedTodo->summary().length(); 297 int len = mRelatedTodo->summary().length();
284 mGeneral->mSummaryEdit->lineEdit()->setFocus(); 298 mGeneral->mSummaryEdit->lineEdit()->setFocus();
285 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); 299 mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 );
286 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); 300 mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 );
287 301
288 } else 302 } else
289 mGeneral->setFocusOn( 2 ); 303 mGeneral->setFocusOn( 2 );
304 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
305 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
306}
307void KOTodoEditor::checkRecurrence()
308{
309 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
310 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true );
311
312 if ( mTodo )
313 mRecurrence->readEvent( mTodo );
314 else {
315 bool time = mGeneral->mTimeButton->isChecked();
316 QDateTime from,to;
317 if ( time ) {
318 to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ;
319 from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ;
320 } else {
321 to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ;
322 from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ;
323 }
324 mRecurrence->setDefaults(from,to,!time);
325 }
326 } else {
327 tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false );
328 mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true);
329 }
290} 330}
291
292void KOTodoEditor::readTodo(Todo *todo) 331void KOTodoEditor::readTodo(Todo *todo)
293{ 332{
294 mGeneral->readTodo(todo); 333 mGeneral->readTodo(todo);
295 mDetails->readEvent(todo); 334 mDetails->readEvent(todo);
296 mRelatedTodo = 0;//todo->relatedTo(); 335 mRelatedTodo = 0;//todo->relatedTo();
297 // categories 336 // categories
298 // mCategoryDialog->setSelected(todo->categories()); 337 // mCategoryDialog->setSelected(todo->categories());
299 338
300 // We should handle read-only events here. 339 // We should handle read-only events here.
301} 340}
302 341
303void KOTodoEditor::writeTodo(Todo *event) 342void KOTodoEditor::writeTodo(Todo *event)
304{ 343{
305 mGeneral->writeTodo(event); 344 mGeneral->writeTodo(event);
306 mDetails->writeEvent(event); 345 mDetails->writeEvent(event);
307 346
308 // set related event, i.e. parent to-do in this case. 347 // set related event, i.e. parent to-do in this case.
309 if (mRelatedTodo) { 348 if (mRelatedTodo) {
310 event->setRelatedTo(mRelatedTodo); 349 event->setRelatedTo(mRelatedTodo);
311 } 350 }
351 if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) {
352 mRecurrence->writeEvent(event);
353 } else
354 event->recurrence()->unsetRecurs();
312} 355}
313 356
314bool KOTodoEditor::validateInput() 357bool KOTodoEditor::validateInput()
315{ 358{
316 if (!mGeneral->validateInput()) return false; 359 if (!mGeneral->validateInput()) return false;
317 if (!mDetails->validateInput()) return false; 360 if (!mDetails->validateInput()) return false;
318 return true; 361 return true;
319} 362}
320 363
321int KOTodoEditor::msgItemDelete() 364int KOTodoEditor::msgItemDelete()
322{ 365{
323 return KMessageBox::warningContinueCancel(this, 366 return KMessageBox::warningContinueCancel(this,
324 i18n("This item will be permanently deleted."), 367 i18n("This item will be permanently deleted."),
325 i18n("KOrganizer Confirmation"),i18n("Delete")); 368 i18n("KOrganizer Confirmation"),i18n("Delete"));
326} 369}
327 370
328void KOTodoEditor::modified (int modification) 371void KOTodoEditor::modified (int modification)
329{ 372{
330 if (modification == KOGlobals::CATEGORY_MODIFIED || 373 if (modification == KOGlobals::CATEGORY_MODIFIED ||
331 KOGlobals::UNKNOWN_MODIFIED == modification ) 374 KOGlobals::UNKNOWN_MODIFIED == modification )
332 // mCategoryDialog->setSelected (mTodo->categories ()); 375 // mCategoryDialog->setSelected (mTodo->categories ());
333 mGeneral->modified (mTodo, modification); 376 mGeneral->modified (mTodo, modification);
334 377
335} 378}
336 379
337void KOTodoEditor::slotLoadTemplate() 380void KOTodoEditor::slotLoadTemplate()
338{ 381{
339 382
340 QString fileName =locateLocal( "templates", "todos" ); 383 QString fileName =locateLocal( "templates", "todos" );
341 QDir t_dir; 384 QDir t_dir;
342 if ( !t_dir.exists(fileName) ) 385 if ( !t_dir.exists(fileName) )
343 t_dir.mkdir ( fileName ); 386 t_dir.mkdir ( fileName );
344 fileName += "/todo"; 387 fileName += "/todo";
345 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); 388 fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this );
346 if ( fileName.length() == 0 ) 389 if ( fileName.length() == 0 )
347 return; 390 return;
348 CalendarLocal cal; 391 CalendarLocal cal;
349 ICalFormat format; 392 ICalFormat format;
350 if ( !format.load( &cal, fileName ) ) { 393 if ( !format.load( &cal, fileName ) ) {
351 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 394 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
352 .arg( fileName ) ); 395 .arg( fileName ) );
353 return ; 396 return ;
354 } 397 }
355 QPtrList<Todo> todos = cal.todos(); 398 QPtrList<Todo> todos = cal.todos();
356 Todo * todo = todos.first(); 399 Todo * todo = todos.first();
357 if ( !todo ) { 400 if ( !todo ) {
358 KMessageBox::error( this, 401 KMessageBox::error( this,
359 i18n("Template does not\ncontain a valid Todo.")); 402 i18n("Template does not\ncontain a valid Todo."));
360 } else { 403 } else {
361 readTodo( todo ); 404 readTodo( todo );
362 } 405 }
363 406
364} 407}
365 408
366void KOTodoEditor::slotSaveTemplate() 409void KOTodoEditor::slotSaveTemplate()
367{ 410{
368 QString fileName =locateLocal( "templates", "todos" ); 411 QString fileName =locateLocal( "templates", "todos" );
369 QDir t_dir; 412 QDir t_dir;
370 if ( !t_dir.exists(fileName) ) 413 if ( !t_dir.exists(fileName) )
371 t_dir.mkdir ( fileName ); 414 t_dir.mkdir ( fileName );
372 fileName += "/todo"; 415 fileName += "/todo";
373 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); 416 fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this );
374 if ( fileName.length() > 0 ) 417 if ( fileName.length() > 0 )
375 saveTemplate( fileName ); 418 saveTemplate( fileName );
376} 419}
377 420
378void KOTodoEditor::saveTemplate( const QString &templateName ) 421void KOTodoEditor::saveTemplate( const QString &templateName )
379{ 422{
380 Todo *todo = new Todo; 423 Todo *todo = new Todo;
381 writeTodo( todo ); 424 writeTodo( todo );
382 saveAsTemplate( todo, templateName ); 425 saveAsTemplate( todo, templateName );
383} 426}
diff --git a/korganizer/kotodoeditor.h b/korganizer/kotodoeditor.h
index 2657bd8..1b5e3b4 100644
--- a/korganizer/kotodoeditor.h
+++ b/korganizer/kotodoeditor.h
@@ -1,102 +1,106 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1997, 1998 Preston Brown 3 Copyright (c) 1997, 1998 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#ifndef _KOTODOEDITOR_H 24#ifndef _KOTODOEDITOR_H
25#define _KOTODOEDITOR_H 25#define _KOTODOEDITOR_H
26 26
27#include <libkcal/calendar.h> 27#include <libkcal/calendar.h>
28 28
29#include "koeditorgeneraltodo.h" 29#include "koeditorgeneraltodo.h"
30#include "koeditordetails.h" 30#include "koeditordetails.h"
31#include "koincidenceeditor.h" 31#include "koincidenceeditor.h"
32#include "koeditorrecurrence.h"
32 33
33class QDateTime; 34class QDateTime;
34 35
35/** 36/**
36 This class provides a dialog for editing a Todo. 37 This class provides a dialog for editing a Todo.
37*/ 38*/
38class KOTodoEditor : public KOIncidenceEditor 39class KOTodoEditor : public KOIncidenceEditor
39{ 40{
40 Q_OBJECT 41 Q_OBJECT
41 public: 42 public:
42 /** 43 /**
43 Constructs a new todo editor. 44 Constructs a new todo editor.
44 */ 45 */
45 KOTodoEditor( Calendar *calendar, QWidget *parent ); 46 KOTodoEditor( Calendar *calendar, QWidget *parent );
46 virtual ~KOTodoEditor(); 47 virtual ~KOTodoEditor();
47 48
48 void init(); 49 void init();
49 50
50 void reload(); 51 void reload();
51 void setSecrecy( int sec ); 52 void setSecrecy( int sec );
52 /** 53 /**
53 Clear editor for new todo, and preset the dates and times with hint. 54 Clear editor for new todo, and preset the dates and times with hint.
54 */ 55 */
55 void newTodo(QDateTime due,Todo *relatedTodo=0,bool allDay=false); 56 void newTodo(QDateTime due,Todo *relatedTodo=0,bool allDay=false);
56 57
57 /** Edit an existing todo. */ 58 /** Edit an existing todo. */
58 void editTodo(Todo * ,bool editDescription = false ); 59 void editTodo(Todo * ,bool editDescription = false );
59 60
60 /** Set widgets to default values */ 61 /** Set widgets to default values */
61 void setDefaults(QDateTime due,Todo *relatedTodo,bool allDay); 62 void setDefaults(QDateTime due,Todo *relatedTodo,bool allDay);
62 /** Read event object and setup widgets accordingly */ 63 /** Read event object and setup widgets accordingly */
63 void readTodo(Todo *); 64 void readTodo(Todo *);
64 /** Write event settings to event object */ 65 /** Write event settings to event object */
65 void writeTodo(Todo *); 66 void writeTodo(Todo *);
66 67
67 /** Check if the input is valid. */ 68 /** Check if the input is valid. */
68 bool validateInput(); 69 bool validateInput();
69 /** Process user input and create or update event. Returns false if input 70 /** Process user input and create or update event. Returns false if input
70 * is not valid */ 71 * is not valid */
71 bool processInput( bool ); 72 bool processInput( bool );
72 73
73 /** This todo has been modified externally */ 74 /** This todo has been modified externally */
74 void modified (int); 75 void modified (int);
75 void setCategories( QString s ); 76 void setCategories( QString s );
76 signals: 77 signals:
77 void todoChanged(Todo *); 78 void todoChanged(Todo *);
78 void todoAdded(Todo *); 79 void todoAdded(Todo *);
79 void todoToBeDeleted(Todo *); 80 void todoToBeDeleted(Todo *);
80 void todoDeleted(); 81 void todoDeleted();
81 82
82 protected slots: 83 protected slots:
83 void loadDefaults(); 84 void loadDefaults();
84 void deleteTodo(); 85 void deleteTodo();
86 void checkRecurrence();
85 87
86 void slotLoadTemplate(); 88 void slotLoadTemplate();
87 void slotSaveTemplate(); 89 void slotSaveTemplate();
88 void saveTemplate( const QString & ); 90 void saveTemplate( const QString & );
89 91
90 protected: 92 protected:
91 void setupGeneral(); 93 void setupGeneral();
92 int msgItemDelete(); 94 int msgItemDelete();
95 void setupRecurrence();
93 96
94 private: 97 private:
95 Todo *mTodo; 98 Todo *mTodo;
96 99
97 Incidence *mRelatedTodo; 100 Incidence *mRelatedTodo;
98 101
99 KOEditorGeneralTodo *mGeneral; 102 KOEditorGeneralTodo *mGeneral;
103 KOEditorRecurrence *mRecurrence;
100}; 104};
101 105
102#endif 106#endif
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index bd13132..bb9cb29 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1,2156 +1,2164 @@
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 <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qfile.h> 24#include <qfile.h>
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28#include <kglobal.h> 28#include <kglobal.h>
29 29
30extern "C" { 30extern "C" {
31 #include <ical.h> 31 #include <ical.h>
32 #include <icalss.h> 32 #include <icalss.h>
33 #include <icalparser.h> 33 #include <icalparser.h>
34 #include <icalrestriction.h> 34 #include <icalrestriction.h>
35} 35}
36 36
37#include "calendar.h" 37#include "calendar.h"
38#include "journal.h" 38#include "journal.h"
39#include "icalformat.h" 39#include "icalformat.h"
40#include "icalformatimpl.h" 40#include "icalformatimpl.h"
41#include "compat.h" 41#include "compat.h"
42 42
43#define _ICAL_VERSION "2.0" 43#define _ICAL_VERSION "2.0"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47const int gSecondsPerMinute = 60; 47const int gSecondsPerMinute = 60;
48const int gSecondsPerHour = gSecondsPerMinute * 60; 48const int gSecondsPerHour = gSecondsPerMinute * 60;
49const int gSecondsPerDay = gSecondsPerHour * 24; 49const int gSecondsPerDay = gSecondsPerHour * 24;
50const int gSecondsPerWeek = gSecondsPerDay * 7; 50const int gSecondsPerWeek = gSecondsPerDay * 7;
51 51
52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : 52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) :
53 mParent( parent ), mCalendarVersion( 0 ) 53 mParent( parent ), mCalendarVersion( 0 )
54{ 54{
55 mCompat = new Compat; 55 mCompat = new Compat;
56} 56}
57 57
58ICalFormatImpl::~ICalFormatImpl() 58ICalFormatImpl::~ICalFormatImpl()
59{ 59{
60 delete mCompat; 60 delete mCompat;
61} 61}
62 62
63class ToStringVisitor : public Incidence::Visitor 63class ToStringVisitor : public Incidence::Visitor
64{ 64{
65 public: 65 public:
66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} 66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {}
67 67
68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } 68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; }
69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } 69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; }
70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } 70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; }
71 71
72 icalcomponent *component() { return mComponent; } 72 icalcomponent *component() { return mComponent; }
73 73
74 private: 74 private:
75 ICalFormatImpl *mImpl; 75 ICalFormatImpl *mImpl;
76 icalcomponent *mComponent; 76 icalcomponent *mComponent;
77}; 77};
78 78
79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) 79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence)
80{ 80{
81 ToStringVisitor v( this ); 81 ToStringVisitor v( this );
82 incidence->accept(v); 82 incidence->accept(v);
83 return v.component(); 83 return v.component();
84} 84}
85 85
86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) 86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo)
87{ 87{
88 QString tmpStr; 88 QString tmpStr;
89 QStringList tmpStrList; 89 QStringList tmpStrList;
90 90
91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); 91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
92 92
93 writeIncidence(vtodo,todo); 93 writeIncidence(vtodo,todo);
94 94
95 // due date 95 // due date
96 if (todo->hasDueDate()) { 96 if (todo->hasDueDate()) {
97 icaltimetype due; 97 icaltimetype due;
98 if (todo->doesFloat()) { 98 if (todo->doesFloat()) {
99 due = writeICalDate(todo->dtDue().date()); 99 due = writeICalDate(todo->dtDue().date());
100 } else { 100 } else {
101 due = writeICalDateTime(todo->dtDue()); 101 due = writeICalDateTime(todo->dtDue());
102 } 102 }
103 icalcomponent_add_property(vtodo,icalproperty_new_due(due)); 103 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
104 } 104 }
105 105
106 // start time 106 // start time
107 if (todo->hasStartDate()) { 107 if (todo->hasStartDate()) {
108 icaltimetype start; 108 icaltimetype start;
109 if (todo->doesFloat()) { 109 if (todo->doesFloat()) {
110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; 110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl;
111 start = writeICalDate(todo->dtStart().date()); 111 start = writeICalDate(todo->dtStart().date());
112 } else { 112 } else {
113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; 113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl;
114 start = writeICalDateTime(todo->dtStart()); 114 start = writeICalDateTime(todo->dtStart());
115 } 115 }
116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); 116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
117 } 117 }
118 118
119 // completion date 119 // completion date
120 if (todo->isCompleted()) { 120 if (todo->isCompleted()) {
121 if (!todo->hasCompletedDate()) { 121 if (!todo->hasCompletedDate()) {
122 // If todo was created by KOrganizer <2.2 it has no correct completion 122 // If todo was created by KOrganizer <2.2 it has no correct completion
123 // date. Set it to now. 123 // date. Set it to now.
124 todo->setCompleted(QDateTime::currentDateTime()); 124 todo->setCompleted(QDateTime::currentDateTime());
125 } 125 }
126 icaltimetype completed = writeICalDateTime(todo->completed()); 126 icaltimetype completed = writeICalDateTime(todo->completed());
127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); 127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
128 } 128 }
129 129
130 icalcomponent_add_property(vtodo, 130 icalcomponent_add_property(vtodo,
131 icalproperty_new_percentcomplete(todo->percentComplete())); 131 icalproperty_new_percentcomplete(todo->percentComplete()));
132 132
133 return vtodo; 133 return vtodo;
134} 134}
135 135
136icalcomponent *ICalFormatImpl::writeEvent(Event *event) 136icalcomponent *ICalFormatImpl::writeEvent(Event *event)
137{ 137{
138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() 138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid()
139 << ")" << endl; 139 << ")" << endl;
140 140
141 QString tmpStr; 141 QString tmpStr;
142 QStringList tmpStrList; 142 QStringList tmpStrList;
143 143
144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); 144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
145 145
146 writeIncidence(vevent,event); 146 writeIncidence(vevent,event);
147 147
148 // start time 148 // start time
149 icaltimetype start; 149 icaltimetype start;
150 if (event->doesFloat()) { 150 if (event->doesFloat()) {
151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
152 start = writeICalDate(event->dtStart().date()); 152 start = writeICalDate(event->dtStart().date());
153 } else { 153 } else {
154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
155 start = writeICalDateTime(event->dtStart()); 155 start = writeICalDateTime(event->dtStart());
156 } 156 }
157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); 157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
158 158
159 if (event->hasEndDate()) { 159 if (event->hasEndDate()) {
160 // end time 160 // end time
161 icaltimetype end; 161 icaltimetype end;
162 if (event->doesFloat()) { 162 if (event->doesFloat()) {
163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; 163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl;
164 // +1 day because end date is non-inclusive. 164 // +1 day because end date is non-inclusive.
165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); 165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) );
166 } else { 166 } else {
167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; 167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl;
168 end = writeICalDateTime(event->dtEnd()); 168 end = writeICalDateTime(event->dtEnd());
169 } 169 }
170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); 170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
171 } 171 }
172 172
173// TODO: attachments, resources 173// TODO: attachments, resources
174#if 0 174#if 0
175 // attachments 175 // attachments
176 tmpStrList = anEvent->attachments(); 176 tmpStrList = anEvent->attachments();
177 for ( QStringList::Iterator it = tmpStrList.begin(); 177 for ( QStringList::Iterator it = tmpStrList.begin();
178 it != tmpStrList.end(); 178 it != tmpStrList.end();
179 ++it ) 179 ++it )
180 addPropValue(vevent, VCAttachProp, (*it).utf8()); 180 addPropValue(vevent, VCAttachProp, (*it).utf8());
181 181
182 // resources 182 // resources
183 tmpStrList = anEvent->resources(); 183 tmpStrList = anEvent->resources();
184 tmpStr = tmpStrList.join(";"); 184 tmpStr = tmpStrList.join(";");
185 if (!tmpStr.isEmpty()) 185 if (!tmpStr.isEmpty())
186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); 186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
187 187
188#endif 188#endif
189 189
190 // Transparency 190 // Transparency
191 switch( event->transparency() ) { 191 switch( event->transparency() ) {
192 case Event::Transparent: 192 case Event::Transparent:
193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); 193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
194 break; 194 break;
195 case Event::Opaque: 195 case Event::Opaque:
196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); 196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
197 break; 197 break;
198 } 198 }
199 199
200 return vevent; 200 return vevent;
201} 201}
202 202
203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, 203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
204 Scheduler::Method method) 204 Scheduler::Method method)
205{ 205{
206 206
207 207
208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
209 209
210 writeIncidenceBase(vfreebusy,freebusy); 210 writeIncidenceBase(vfreebusy,freebusy);
211 211
212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
213 writeICalDateTime(freebusy->dtStart()))); 213 writeICalDateTime(freebusy->dtStart())));
214 214
215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
216 writeICalDateTime(freebusy->dtEnd()))); 216 writeICalDateTime(freebusy->dtEnd())));
217 217
218 if (method == Scheduler::Request) { 218 if (method == Scheduler::Request) {
219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
220 freebusy->uid().utf8())); 220 freebusy->uid().utf8()));
221 } 221 }
222 222
223 //Loops through all the periods in the freebusy object 223 //Loops through all the periods in the freebusy object
224 QValueList<Period> list = freebusy->busyPeriods(); 224 QValueList<Period> list = freebusy->busyPeriods();
225 QValueList<Period>::Iterator it; 225 QValueList<Period>::Iterator it;
226 icalperiodtype period; 226 icalperiodtype period;
227 for (it = list.begin(); it!= list.end(); ++it) { 227 for (it = list.begin(); it!= list.end(); ++it) {
228 period.start = writeICalDateTime((*it).start()); 228 period.start = writeICalDateTime((*it).start());
229 period.end = writeICalDateTime((*it).end()); 229 period.end = writeICalDateTime((*it).end());
230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
231 } 231 }
232 232
233 return vfreebusy; 233 return vfreebusy;
234} 234}
235 235
236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
237{ 237{
238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
239 239
240 writeIncidence(vjournal,journal); 240 writeIncidence(vjournal,journal);
241 241
242 // start time 242 // start time
243 if (journal->dtStart().isValid()) { 243 if (journal->dtStart().isValid()) {
244 icaltimetype start; 244 icaltimetype start;
245 if (journal->doesFloat()) { 245 if (journal->doesFloat()) {
246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
247 start = writeICalDate(journal->dtStart().date()); 247 start = writeICalDate(journal->dtStart().date());
248 } else { 248 } else {
249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
250 start = writeICalDateTime(journal->dtStart()); 250 start = writeICalDateTime(journal->dtStart());
251 } 251 }
252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
253 } 253 }
254 254
255 return vjournal; 255 return vjournal;
256} 256}
257 257
258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
259{ 259{
260 // pilot sync stuff 260 // pilot sync stuff
261// TODO: move this application-specific code to kpilot 261// TODO: move this application-specific code to kpilot
262 if (incidence->pilotId()) { 262 if (incidence->pilotId()) {
263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
265 } 265 }
266 if ( !incidence->IDStr().isEmpty()) { 266 if ( !incidence->IDStr().isEmpty()) {
267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); 267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
268 } 268 }
269 269
270 270
271 writeIncidenceBase(parent,incidence); 271 writeIncidenceBase(parent,incidence);
272 if (incidence->cancelled()) { 272 if (incidence->cancelled()) {
273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
274 } 274 }
275 275
276 // creation date 276 // creation date
277 icalcomponent_add_property(parent,icalproperty_new_created( 277 icalcomponent_add_property(parent,icalproperty_new_created(
278 writeICalDateTime(incidence->created()))); 278 writeICalDateTime(incidence->created())));
279 279
280 // unique id 280 // unique id
281 icalcomponent_add_property(parent,icalproperty_new_uid( 281 icalcomponent_add_property(parent,icalproperty_new_uid(
282 incidence->uid().utf8())); 282 incidence->uid().utf8()));
283 283
284 // revision 284 // revision
285 icalcomponent_add_property(parent,icalproperty_new_sequence( 285 icalcomponent_add_property(parent,icalproperty_new_sequence(
286 incidence->revision())); 286 incidence->revision()));
287 287
288 // last modification date 288 // last modification date
289 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 289 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
290 writeICalDateTime(incidence->lastModified()))); 290 writeICalDateTime(incidence->lastModified())));
291 291
292 // description 292 // description
293 if (!incidence->description().isEmpty()) { 293 if (!incidence->description().isEmpty()) {
294 icalcomponent_add_property(parent,icalproperty_new_description( 294 icalcomponent_add_property(parent,icalproperty_new_description(
295 incidence->description().utf8())); 295 incidence->description().utf8()));
296 } 296 }
297 297
298 // summary 298 // summary
299 if (!incidence->summary().isEmpty()) { 299 if (!incidence->summary().isEmpty()) {
300 icalcomponent_add_property(parent,icalproperty_new_summary( 300 icalcomponent_add_property(parent,icalproperty_new_summary(
301 incidence->summary().utf8())); 301 incidence->summary().utf8()));
302 } 302 }
303 303
304 // location 304 // location
305 if (!incidence->location().isEmpty()) { 305 if (!incidence->location().isEmpty()) {
306 icalcomponent_add_property(parent,icalproperty_new_location( 306 icalcomponent_add_property(parent,icalproperty_new_location(
307 incidence->location().utf8())); 307 incidence->location().utf8()));
308 } 308 }
309 309
310// TODO: 310// TODO:
311 // status 311 // status
312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
313 313
314 // secrecy 314 // secrecy
315 enum icalproperty_class classInt; 315 enum icalproperty_class classInt;
316 switch (incidence->secrecy()) { 316 switch (incidence->secrecy()) {
317 case Incidence::SecrecyPublic: 317 case Incidence::SecrecyPublic:
318 classInt = ICAL_CLASS_PUBLIC; 318 classInt = ICAL_CLASS_PUBLIC;
319 break; 319 break;
320 case Incidence::SecrecyConfidential: 320 case Incidence::SecrecyConfidential:
321 classInt = ICAL_CLASS_CONFIDENTIAL; 321 classInt = ICAL_CLASS_CONFIDENTIAL;
322 break; 322 break;
323 case Incidence::SecrecyPrivate: 323 case Incidence::SecrecyPrivate:
324 classInt =ICAL_CLASS_PRIVATE ; 324 classInt =ICAL_CLASS_PRIVATE ;
325 default: 325 default:
326 classInt =ICAL_CLASS_PRIVATE ; 326 classInt =ICAL_CLASS_PRIVATE ;
327 break; 327 break;
328 } 328 }
329 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 329 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
330 330
331 // priority 331 // priority
332 icalcomponent_add_property(parent,icalproperty_new_priority( 332 icalcomponent_add_property(parent,icalproperty_new_priority(
333 incidence->priority())); 333 incidence->priority()));
334 334
335 // categories 335 // categories
336 QStringList categories = incidence->categories(); 336 QStringList categories = incidence->categories();
337 QStringList::Iterator it; 337 QStringList::Iterator it;
338 for(it = categories.begin(); it != categories.end(); ++it ) { 338 for(it = categories.begin(); it != categories.end(); ++it ) {
339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
340 } 340 }
341// TODO: Ensure correct concatenation of categories properties. 341// TODO: Ensure correct concatenation of categories properties.
342 342
343/* 343/*
344 // categories 344 // categories
345 tmpStrList = incidence->getCategories(); 345 tmpStrList = incidence->getCategories();
346 tmpStr = ""; 346 tmpStr = "";
347 QString catStr; 347 QString catStr;
348 for ( QStringList::Iterator it = tmpStrList.begin(); 348 for ( QStringList::Iterator it = tmpStrList.begin();
349 it != tmpStrList.end(); 349 it != tmpStrList.end();
350 ++it ) { 350 ++it ) {
351 catStr = *it; 351 catStr = *it;
352 if (catStr[0] == ' ') 352 if (catStr[0] == ' ')
353 tmpStr += catStr.mid(1); 353 tmpStr += catStr.mid(1);
354 else 354 else
355 tmpStr += catStr; 355 tmpStr += catStr;
356 // this must be a ';' character as the vCalendar specification requires! 356 // this must be a ';' character as the vCalendar specification requires!
357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
358 // read in. 358 // read in.
359 tmpStr += ";"; 359 tmpStr += ";";
360 } 360 }
361 if (!tmpStr.isEmpty()) { 361 if (!tmpStr.isEmpty()) {
362 tmpStr.truncate(tmpStr.length()-1); 362 tmpStr.truncate(tmpStr.length()-1);
363 icalcomponent_add_property(parent,icalproperty_new_categories( 363 icalcomponent_add_property(parent,icalproperty_new_categories(
364 writeText(incidence->getCategories().join(";")))); 364 writeText(incidence->getCategories().join(";"))));
365 } 365 }
366*/ 366*/
367 367
368 // related event 368 // related event
369 if (incidence->relatedTo()) { 369 if (incidence->relatedTo()) {
370 icalcomponent_add_property(parent,icalproperty_new_relatedto( 370 icalcomponent_add_property(parent,icalproperty_new_relatedto(
371 incidence->relatedTo()->uid().utf8())); 371 incidence->relatedTo()->uid().utf8()));
372 } 372 }
373 373
374 // recurrence rule stuff 374 // recurrence rule stuff
375 Recurrence *recur = incidence->recurrence(); 375 Recurrence *recur = incidence->recurrence();
376 if (recur->doesRecur()) { 376 if (recur->doesRecur()) {
377 377
378 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 378 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
379 } 379 }
380 380
381 // recurrence excpetion dates 381 // recurrence excpetion dates
382 DateList dateList = incidence->exDates(); 382 DateList dateList = incidence->exDates();
383 DateList::ConstIterator exIt; 383 DateList::ConstIterator exIt;
384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 384 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
385 icalcomponent_add_property(parent,icalproperty_new_exdate( 385 icalcomponent_add_property(parent,icalproperty_new_exdate(
386 writeICalDate(*exIt))); 386 writeICalDate(*exIt)));
387 } 387 }
388 388
389 // attachments 389 // attachments
390 QPtrList<Attachment> attachments = incidence->attachments(); 390 QPtrList<Attachment> attachments = incidence->attachments();
391 for (Attachment *at = attachments.first(); at; at = attachments.next()) 391 for (Attachment *at = attachments.first(); at; at = attachments.next())
392 icalcomponent_add_property(parent,writeAttachment(at)); 392 icalcomponent_add_property(parent,writeAttachment(at));
393 393
394 // alarms 394 // alarms
395 QPtrList<Alarm> alarms = incidence->alarms(); 395 QPtrList<Alarm> alarms = incidence->alarms();
396 Alarm* alarm; 396 Alarm* alarm;
397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 397 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
398 if (alarm->enabled()) { 398 if (alarm->enabled()) {
399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 399 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
400 icalcomponent_add_component(parent,writeAlarm(alarm)); 400 icalcomponent_add_component(parent,writeAlarm(alarm));
401 } 401 }
402 } 402 }
403 403 if( incidence->hasRecurrenceID() ) {
404 icalcomponent_add_property(parent,
405 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
406 }
404 // duration 407 // duration
405 408
406// turned off as it always is set to PTS0 (and must not occur together with DTEND 409// turned off as it always is set to PTS0 (and must not occur together with DTEND
407 410
408// if (incidence->hasDuration()) { 411// if (incidence->hasDuration()) {
409// icaldurationtype duration; 412// icaldurationtype duration;
410// duration = writeICalDuration(incidence->duration()); 413// duration = writeICalDuration(incidence->duration());
411// icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 414// icalcomponent_add_property(parent,icalproperty_new_duration(duration));
412// } 415// }
413} 416}
414 417
415void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 418void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
416{ 419{
417 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 420 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
418 writeICalDateTime(QDateTime::currentDateTime()))); 421 writeICalDateTime(QDateTime::currentDateTime())));
419 422
420 // organizer stuff 423 // organizer stuff
421 icalcomponent_add_property(parent,icalproperty_new_organizer( 424 icalcomponent_add_property(parent,icalproperty_new_organizer(
422 ("MAILTO:" + incidenceBase->organizer()).utf8())); 425 ("MAILTO:" + incidenceBase->organizer()).utf8()));
423 426
424 // attendees 427 // attendees
425 if (incidenceBase->attendeeCount() != 0) { 428 if (incidenceBase->attendeeCount() != 0) {
426 QPtrList<Attendee> al = incidenceBase->attendees(); 429 QPtrList<Attendee> al = incidenceBase->attendees();
427 QPtrListIterator<Attendee> ai(al); 430 QPtrListIterator<Attendee> ai(al);
428 for (; ai.current(); ++ai) { 431 for (; ai.current(); ++ai) {
429 icalcomponent_add_property(parent,writeAttendee(ai.current())); 432 icalcomponent_add_property(parent,writeAttendee(ai.current()));
430 } 433 }
431 } 434 }
432 435
433 // custom properties 436 // custom properties
434 writeCustomProperties(parent, incidenceBase); 437 writeCustomProperties(parent, incidenceBase);
435} 438}
436 439
437void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 440void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
438{ 441{
439 QMap<QCString, QString> custom = properties->customProperties(); 442 QMap<QCString, QString> custom = properties->customProperties();
440 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 443 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
441 icalproperty *p = icalproperty_new_x(c.data().utf8()); 444 icalproperty *p = icalproperty_new_x(c.data().utf8());
442 icalproperty_set_x_name(p,c.key()); 445 icalproperty_set_x_name(p,c.key());
443 icalcomponent_add_property(parent,p); 446 icalcomponent_add_property(parent,p);
444 } 447 }
445} 448}
446 449
447icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 450icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
448{ 451{
449 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 452 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
450 453
451 if (!attendee->name().isEmpty()) { 454 if (!attendee->name().isEmpty()) {
452 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 455 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
453 } 456 }
454 457
455 458
456 icalproperty_add_parameter(p,icalparameter_new_rsvp( 459 icalproperty_add_parameter(p,icalparameter_new_rsvp(
457 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 460 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
458 461
459 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 462 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
460 switch (attendee->status()) { 463 switch (attendee->status()) {
461 default: 464 default:
462 case Attendee::NeedsAction: 465 case Attendee::NeedsAction:
463 status = ICAL_PARTSTAT_NEEDSACTION; 466 status = ICAL_PARTSTAT_NEEDSACTION;
464 break; 467 break;
465 case Attendee::Accepted: 468 case Attendee::Accepted:
466 status = ICAL_PARTSTAT_ACCEPTED; 469 status = ICAL_PARTSTAT_ACCEPTED;
467 break; 470 break;
468 case Attendee::Declined: 471 case Attendee::Declined:
469 status = ICAL_PARTSTAT_DECLINED; 472 status = ICAL_PARTSTAT_DECLINED;
470 break; 473 break;
471 case Attendee::Tentative: 474 case Attendee::Tentative:
472 status = ICAL_PARTSTAT_TENTATIVE; 475 status = ICAL_PARTSTAT_TENTATIVE;
473 break; 476 break;
474 case Attendee::Delegated: 477 case Attendee::Delegated:
475 status = ICAL_PARTSTAT_DELEGATED; 478 status = ICAL_PARTSTAT_DELEGATED;
476 break; 479 break;
477 case Attendee::Completed: 480 case Attendee::Completed:
478 status = ICAL_PARTSTAT_COMPLETED; 481 status = ICAL_PARTSTAT_COMPLETED;
479 break; 482 break;
480 case Attendee::InProcess: 483 case Attendee::InProcess:
481 status = ICAL_PARTSTAT_INPROCESS; 484 status = ICAL_PARTSTAT_INPROCESS;
482 break; 485 break;
483 } 486 }
484 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 487 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
485 488
486 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 489 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
487 switch (attendee->role()) { 490 switch (attendee->role()) {
488 case Attendee::Chair: 491 case Attendee::Chair:
489 role = ICAL_ROLE_CHAIR; 492 role = ICAL_ROLE_CHAIR;
490 break; 493 break;
491 default: 494 default:
492 case Attendee::ReqParticipant: 495 case Attendee::ReqParticipant:
493 role = ICAL_ROLE_REQPARTICIPANT; 496 role = ICAL_ROLE_REQPARTICIPANT;
494 break; 497 break;
495 case Attendee::OptParticipant: 498 case Attendee::OptParticipant:
496 role = ICAL_ROLE_OPTPARTICIPANT; 499 role = ICAL_ROLE_OPTPARTICIPANT;
497 break; 500 break;
498 case Attendee::NonParticipant: 501 case Attendee::NonParticipant:
499 role = ICAL_ROLE_NONPARTICIPANT; 502 role = ICAL_ROLE_NONPARTICIPANT;
500 break; 503 break;
501 } 504 }
502 icalproperty_add_parameter(p,icalparameter_new_role(role)); 505 icalproperty_add_parameter(p,icalparameter_new_role(role));
503 506
504 if (!attendee->uid().isEmpty()) { 507 if (!attendee->uid().isEmpty()) {
505 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 508 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
506 icalparameter_set_xname(icalparameter_uid,"X-UID"); 509 icalparameter_set_xname(icalparameter_uid,"X-UID");
507 icalproperty_add_parameter(p,icalparameter_uid); 510 icalproperty_add_parameter(p,icalparameter_uid);
508 } 511 }
509 512
510 return p; 513 return p;
511} 514}
512 515
513icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 516icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
514{ 517{
515#if 0 518#if 0
516 icalattachtype* attach = icalattachtype_new(); 519 icalattachtype* attach = icalattachtype_new();
517 if (att->isURI()) 520 if (att->isURI())
518 icalattachtype_set_url(attach, att->uri().utf8().data()); 521 icalattachtype_set_url(attach, att->uri().utf8().data());
519 else 522 else
520 icalattachtype_set_base64(attach, att->data(), 0); 523 icalattachtype_set_base64(attach, att->data(), 0);
521#endif 524#endif
522 icalattach *attach; 525 icalattach *attach;
523 if (att->isURI()) 526 if (att->isURI())
524 attach = icalattach_new_from_url( att->uri().utf8().data()); 527 attach = icalattach_new_from_url( att->uri().utf8().data());
525 else 528 else
526 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); 529 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
527 icalproperty *p = icalproperty_new_attach(attach); 530 icalproperty *p = icalproperty_new_attach(attach);
528 if (!att->mimeType().isEmpty()) 531 if (!att->mimeType().isEmpty())
529 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 532 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
530 533
531 if (att->isBinary()) { 534 if (att->isBinary()) {
532 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 535 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
533 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 536 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
534 } 537 }
535 return p; 538 return p;
536} 539}
537 540
538icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 541icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
539{ 542{
540// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 543// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
541 544
542 icalrecurrencetype r; 545 icalrecurrencetype r;
543 546
544 icalrecurrencetype_clear(&r); 547 icalrecurrencetype_clear(&r);
545 548
546 int index = 0; 549 int index = 0;
547 int index2 = 0; 550 int index2 = 0;
548 551
549 QPtrList<Recurrence::rMonthPos> tmpPositions; 552 QPtrList<Recurrence::rMonthPos> tmpPositions;
550 QPtrList<int> tmpDays; 553 QPtrList<int> tmpDays;
551 int *tmpDay; 554 int *tmpDay;
552 Recurrence::rMonthPos *tmpPos; 555 Recurrence::rMonthPos *tmpPos;
553 bool datetime = false; 556 bool datetime = false;
554 int day; 557 int day;
555 int i; 558 int i;
556 559
557 switch(recur->doesRecur()) { 560 switch(recur->doesRecur()) {
558 case Recurrence::rMinutely: 561 case Recurrence::rMinutely:
559 r.freq = ICAL_MINUTELY_RECURRENCE; 562 r.freq = ICAL_MINUTELY_RECURRENCE;
560 datetime = true; 563 datetime = true;
561 break; 564 break;
562 case Recurrence::rHourly: 565 case Recurrence::rHourly:
563 r.freq = ICAL_HOURLY_RECURRENCE; 566 r.freq = ICAL_HOURLY_RECURRENCE;
564 datetime = true; 567 datetime = true;
565 break; 568 break;
566 case Recurrence::rDaily: 569 case Recurrence::rDaily:
567 r.freq = ICAL_DAILY_RECURRENCE; 570 r.freq = ICAL_DAILY_RECURRENCE;
568 break; 571 break;
569 case Recurrence::rWeekly: 572 case Recurrence::rWeekly:
570 r.freq = ICAL_WEEKLY_RECURRENCE; 573 r.freq = ICAL_WEEKLY_RECURRENCE;
571 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 574 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
572 for (i = 0; i < 7; i++) { 575 for (i = 0; i < 7; i++) {
573 if (recur->days().testBit(i)) { 576 if (recur->days().testBit(i)) {
574 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 577 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
575 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 578 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
576 } 579 }
577 } 580 }
578// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 581// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
579 break; 582 break;
580 case Recurrence::rMonthlyPos: 583 case Recurrence::rMonthlyPos:
581 r.freq = ICAL_MONTHLY_RECURRENCE; 584 r.freq = ICAL_MONTHLY_RECURRENCE;
582 585
583 tmpPositions = recur->monthPositions(); 586 tmpPositions = recur->monthPositions();
584 for (tmpPos = tmpPositions.first(); 587 for (tmpPos = tmpPositions.first();
585 tmpPos; 588 tmpPos;
586 tmpPos = tmpPositions.next()) { 589 tmpPos = tmpPositions.next()) {
587 for (i = 0; i < 7; i++) { 590 for (i = 0; i < 7; i++) {
588 if (tmpPos->rDays.testBit(i)) { 591 if (tmpPos->rDays.testBit(i)) {
589 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 592 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
590 day += tmpPos->rPos*8; 593 day += tmpPos->rPos*8;
591 if (tmpPos->negative) day = -day; 594 if (tmpPos->negative) day = -day;
592 r.by_day[index++] = day; 595 r.by_day[index++] = day;
593 } 596 }
594 } 597 }
595 } 598 }
596// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 599// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
597 break; 600 break;
598 case Recurrence::rMonthlyDay: 601 case Recurrence::rMonthlyDay:
599 r.freq = ICAL_MONTHLY_RECURRENCE; 602 r.freq = ICAL_MONTHLY_RECURRENCE;
600 603
601 tmpDays = recur->monthDays(); 604 tmpDays = recur->monthDays();
602 for (tmpDay = tmpDays.first(); 605 for (tmpDay = tmpDays.first();
603 tmpDay; 606 tmpDay;
604 tmpDay = tmpDays.next()) { 607 tmpDay = tmpDays.next()) {
605 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); 608 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay);
606 } 609 }
607// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 610// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
608 break; 611 break;
609 case Recurrence::rYearlyMonth: 612 case Recurrence::rYearlyMonth:
610 case Recurrence::rYearlyPos: 613 case Recurrence::rYearlyPos:
611 r.freq = ICAL_YEARLY_RECURRENCE; 614 r.freq = ICAL_YEARLY_RECURRENCE;
612 615
613 tmpDays = recur->yearNums(); 616 tmpDays = recur->yearNums();
614 for (tmpDay = tmpDays.first(); 617 for (tmpDay = tmpDays.first();
615 tmpDay; 618 tmpDay;
616 tmpDay = tmpDays.next()) { 619 tmpDay = tmpDays.next()) {
617 r.by_month[index++] = *tmpDay; 620 r.by_month[index++] = *tmpDay;
618 } 621 }
619// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; 622// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX;
620 if (recur->doesRecur() == Recurrence::rYearlyPos) { 623 if (recur->doesRecur() == Recurrence::rYearlyPos) {
621 tmpPositions = recur->monthPositions(); 624 tmpPositions = recur->monthPositions();
622 for (tmpPos = tmpPositions.first(); 625 for (tmpPos = tmpPositions.first();
623 tmpPos; 626 tmpPos;
624 tmpPos = tmpPositions.next()) { 627 tmpPos = tmpPositions.next()) {
625 for (i = 0; i < 7; i++) { 628 for (i = 0; i < 7; i++) {
626 if (tmpPos->rDays.testBit(i)) { 629 if (tmpPos->rDays.testBit(i)) {
627 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 630 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
628 day += tmpPos->rPos*8; 631 day += tmpPos->rPos*8;
629 if (tmpPos->negative) day = -day; 632 if (tmpPos->negative) day = -day;
630 r.by_day[index2++] = day; 633 r.by_day[index2++] = day;
631 } 634 }
632 } 635 }
633 } 636 }
634// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; 637// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX;
635 } 638 }
636 break; 639 break;
637 case Recurrence::rYearlyDay: 640 case Recurrence::rYearlyDay:
638 r.freq = ICAL_YEARLY_RECURRENCE; 641 r.freq = ICAL_YEARLY_RECURRENCE;
639 642
640 tmpDays = recur->yearNums(); 643 tmpDays = recur->yearNums();
641 for (tmpDay = tmpDays.first(); 644 for (tmpDay = tmpDays.first();
642 tmpDay; 645 tmpDay;
643 tmpDay = tmpDays.next()) { 646 tmpDay = tmpDays.next()) {
644 r.by_year_day[index++] = *tmpDay; 647 r.by_year_day[index++] = *tmpDay;
645 } 648 }
646// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 649// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
647 break; 650 break;
648 default: 651 default:
649 r.freq = ICAL_NO_RECURRENCE; 652 r.freq = ICAL_NO_RECURRENCE;
650 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; 653 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
651 break; 654 break;
652 } 655 }
653 656
654 r.interval = recur->frequency(); 657 r.interval = recur->frequency();
655 658
656 if (recur->duration() > 0) { 659 if (recur->duration() > 0) {
657 r.count = recur->duration(); 660 r.count = recur->duration();
658 } else if (recur->duration() == -1) { 661 } else if (recur->duration() == -1) {
659 r.count = 0; 662 r.count = 0;
660 } else { 663 } else {
661 if (datetime) 664 if (datetime)
662 r.until = writeICalDateTime(recur->endDateTime()); 665 r.until = writeICalDateTime(recur->endDateTime());
663 else 666 else
664 r.until = writeICalDate(recur->endDate()); 667 r.until = writeICalDate(recur->endDate());
665 } 668 }
666 669
667// Debug output 670// Debug output
668#if 0 671#if 0
669 const char *str = icalrecurrencetype_as_string(&r); 672 const char *str = icalrecurrencetype_as_string(&r);
670 if (str) { 673 if (str) {
671 kdDebug(5800) << " String: " << str << endl; 674 kdDebug(5800) << " String: " << str << endl;
672 } else { 675 } else {
673 kdDebug(5800) << " No String" << endl; 676 kdDebug(5800) << " No String" << endl;
674 } 677 }
675#endif 678#endif
676 679
677 return icalproperty_new_rrule(r); 680 return icalproperty_new_rrule(r);
678} 681}
679 682
680icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) 683icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
681{ 684{
682 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); 685 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
683 686
684 icalproperty_action action; 687 icalproperty_action action;
685 icalattach *attach = 0; 688 icalattach *attach = 0;
686 689
687 switch (alarm->type()) { 690 switch (alarm->type()) {
688 case Alarm::Procedure: 691 case Alarm::Procedure:
689 action = ICAL_ACTION_PROCEDURE; 692 action = ICAL_ACTION_PROCEDURE;
690 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); 693 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() );
691 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 694 icalcomponent_add_property(a,icalproperty_new_attach(attach));
692 if (!alarm->programArguments().isEmpty()) { 695 if (!alarm->programArguments().isEmpty()) {
693 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 696 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
694 } 697 }
695 break; 698 break;
696 case Alarm::Audio: 699 case Alarm::Audio:
697 action = ICAL_ACTION_AUDIO; 700 action = ICAL_ACTION_AUDIO;
698 if (!alarm->audioFile().isEmpty()) { 701 if (!alarm->audioFile().isEmpty()) {
699 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); 702 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
700 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 703 icalcomponent_add_property(a,icalproperty_new_attach(attach));
701 } 704 }
702 break; 705 break;
703 case Alarm::Email: { 706 case Alarm::Email: {
704 action = ICAL_ACTION_EMAIL; 707 action = ICAL_ACTION_EMAIL;
705 QValueList<Person> addresses = alarm->mailAddresses(); 708 QValueList<Person> addresses = alarm->mailAddresses();
706 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 709 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
707 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 710 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
708 if (!(*ad).name().isEmpty()) { 711 if (!(*ad).name().isEmpty()) {
709 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 712 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
710 } 713 }
711 icalcomponent_add_property(a,p); 714 icalcomponent_add_property(a,p);
712 } 715 }
713 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 716 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
714 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 717 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
715 QStringList attachments = alarm->mailAttachments(); 718 QStringList attachments = alarm->mailAttachments();
716 if (attachments.count() > 0) { 719 if (attachments.count() > 0) {
717 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 720 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
718 attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); 721 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
719 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 722 icalcomponent_add_property(a,icalproperty_new_attach(attach));
720 } 723 }
721 } 724 }
722 break; 725 break;
723 } 726 }
724 case Alarm::Display: 727 case Alarm::Display:
725 action = ICAL_ACTION_DISPLAY; 728 action = ICAL_ACTION_DISPLAY;
726 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 729 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
727 break; 730 break;
728 case Alarm::Invalid: 731 case Alarm::Invalid:
729 default: 732 default:
730 kdDebug(5800) << "Unknown type of alarm" << endl; 733 kdDebug(5800) << "Unknown type of alarm" << endl;
731 action = ICAL_ACTION_NONE; 734 action = ICAL_ACTION_NONE;
732 break; 735 break;
733 } 736 }
734 icalcomponent_add_property(a,icalproperty_new_action(action)); 737 icalcomponent_add_property(a,icalproperty_new_action(action));
735 738
736 // Trigger time 739 // Trigger time
737 icaltriggertype trigger; 740 icaltriggertype trigger;
738 if ( alarm->hasTime() ) { 741 if ( alarm->hasTime() ) {
739 trigger.time = writeICalDateTime(alarm->time()); 742 trigger.time = writeICalDateTime(alarm->time());
740 trigger.duration = icaldurationtype_null_duration(); 743 trigger.duration = icaldurationtype_null_duration();
741 } else { 744 } else {
742 trigger.time = icaltime_null_time(); 745 trigger.time = icaltime_null_time();
743 Duration offset; 746 Duration offset;
744 if ( alarm->hasStartOffset() ) 747 if ( alarm->hasStartOffset() )
745 offset = alarm->startOffset(); 748 offset = alarm->startOffset();
746 else 749 else
747 offset = alarm->endOffset(); 750 offset = alarm->endOffset();
748 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 751 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
749 } 752 }
750 icalproperty *p = icalproperty_new_trigger(trigger); 753 icalproperty *p = icalproperty_new_trigger(trigger);
751 if ( alarm->hasEndOffset() ) 754 if ( alarm->hasEndOffset() )
752 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 755 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
753 icalcomponent_add_property(a,p); 756 icalcomponent_add_property(a,p);
754 757
755 // Repeat count and duration 758 // Repeat count and duration
756 if (alarm->repeatCount()) { 759 if (alarm->repeatCount()) {
757 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 760 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
758 icalcomponent_add_property(a,icalproperty_new_duration( 761 icalcomponent_add_property(a,icalproperty_new_duration(
759 icaldurationtype_from_int(alarm->snoozeTime()*60))); 762 icaldurationtype_from_int(alarm->snoozeTime()*60)));
760 } 763 }
761 764
762 // Custom properties 765 // Custom properties
763 QMap<QCString, QString> custom = alarm->customProperties(); 766 QMap<QCString, QString> custom = alarm->customProperties();
764 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 767 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
765 icalproperty *p = icalproperty_new_x(c.data().utf8()); 768 icalproperty *p = icalproperty_new_x(c.data().utf8());
766 icalproperty_set_x_name(p,c.key()); 769 icalproperty_set_x_name(p,c.key());
767 icalcomponent_add_property(a,p); 770 icalcomponent_add_property(a,p);
768 } 771 }
769 772
770 return a; 773 return a;
771} 774}
772 775
773Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 776Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
774{ 777{
775 Todo *todo = new Todo; 778 Todo *todo = new Todo;
776 779
777 readIncidence(vtodo,todo); 780 readIncidence(vtodo,todo);
778 781
779 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 782 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
780 783
781// int intvalue; 784// int intvalue;
782 icaltimetype icaltime; 785 icaltimetype icaltime;
783 786
784 QStringList categories; 787 QStringList categories;
785 788
786 while (p) { 789 while (p) {
787 icalproperty_kind kind = icalproperty_isa(p); 790 icalproperty_kind kind = icalproperty_isa(p);
788 switch (kind) { 791 switch (kind) {
789 792
790 case ICAL_DUE_PROPERTY: // due date 793 case ICAL_DUE_PROPERTY: // due date
791 icaltime = icalproperty_get_due(p); 794 icaltime = icalproperty_get_due(p);
792 if (icaltime.is_date) { 795 if (icaltime.is_date) {
793 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 796 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
794 todo->setFloats(true); 797 todo->setFloats(true);
795 798
796 } else { 799 } else {
797 todo->setDtDue(readICalDateTime(icaltime)); 800 todo->setDtDue(readICalDateTime(icaltime));
798 todo->setFloats(false); 801 todo->setFloats(false);
799 } 802 }
800 todo->setHasDueDate(true); 803 todo->setHasDueDate(true);
801 break; 804 break;
802 805
803 case ICAL_COMPLETED_PROPERTY: // completion date 806 case ICAL_COMPLETED_PROPERTY: // completion date
804 icaltime = icalproperty_get_completed(p); 807 icaltime = icalproperty_get_completed(p);
805 todo->setCompleted(readICalDateTime(icaltime)); 808 todo->setCompleted(readICalDateTime(icaltime));
806 break; 809 break;
807 810
808 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed 811 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
809 todo->setPercentComplete(icalproperty_get_percentcomplete(p)); 812 todo->setPercentComplete(icalproperty_get_percentcomplete(p));
810 break; 813 break;
811 814
812 case ICAL_RELATEDTO_PROPERTY: // related todo (parent) 815 case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
813 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 816 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
814 mTodosRelate.append(todo); 817 mTodosRelate.append(todo);
815 break; 818 break;
816 819
817 case ICAL_DTSTART_PROPERTY: 820 case ICAL_DTSTART_PROPERTY:
818 // Flag that todo has start date. Value is read in by readIncidence(). 821 // Flag that todo has start date. Value is read in by readIncidence().
819 todo->setHasStartDate(true); 822 todo->setHasStartDate(true);
820 break; 823 break;
821 824
822 default: 825 default:
823// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind 826// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind
824// << endl; 827// << endl;
825 break; 828 break;
826 } 829 }
827 830
828 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); 831 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
829 } 832 }
830 833
831 return todo; 834 return todo;
832} 835}
833 836
834Event *ICalFormatImpl::readEvent(icalcomponent *vevent) 837Event *ICalFormatImpl::readEvent(icalcomponent *vevent)
835{ 838{
836 Event *event = new Event; 839 Event *event = new Event;
837 event->setFloats(false); 840 event->setFloats(false);
838 841
839 readIncidence(vevent,event); 842 readIncidence(vevent,event);
840 843
841 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); 844 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY);
842 845
843// int intvalue; 846// int intvalue;
844 icaltimetype icaltime; 847 icaltimetype icaltime;
845 848
846 QStringList categories; 849 QStringList categories;
847 QString transparency; 850 QString transparency;
848 851
849 while (p) { 852 while (p) {
850 icalproperty_kind kind = icalproperty_isa(p); 853 icalproperty_kind kind = icalproperty_isa(p);
851 switch (kind) { 854 switch (kind) {
852 855
853 case ICAL_DTEND_PROPERTY: // start date and time 856 case ICAL_DTEND_PROPERTY: // start date and time
854 icaltime = icalproperty_get_dtend(p); 857 icaltime = icalproperty_get_dtend(p);
855 if (icaltime.is_date) { 858 if (icaltime.is_date) {
856 event->setFloats( true ); 859 event->setFloats( true );
857 // End date is non-inclusive 860 // End date is non-inclusive
858 QDate endDate = readICalDate( icaltime ).addDays( -1 ); 861 QDate endDate = readICalDate( icaltime ).addDays( -1 );
859 mCompat->fixFloatingEnd( endDate ); 862 mCompat->fixFloatingEnd( endDate );
860 if ( endDate < event->dtStart().date() ) { 863 if ( endDate < event->dtStart().date() ) {
861 endDate = event->dtStart().date(); 864 endDate = event->dtStart().date();
862 } 865 }
863 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); 866 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) );
864 } else { 867 } else {
865 event->setDtEnd(readICalDateTime(icaltime)); 868 event->setDtEnd(readICalDateTime(icaltime));
866 } 869 }
867 break; 870 break;
868 871
869// TODO: 872// TODO:
870 // at this point, there should be at least a start or end time. 873 // at this point, there should be at least a start or end time.
871 // fix up for events that take up no time but have a time associated 874 // fix up for events that take up no time but have a time associated
872#if 0 875#if 0
873 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 876 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
874 anEvent->setDtStart(anEvent->dtEnd()); 877 anEvent->setDtStart(anEvent->dtEnd());
875 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 878 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
876 anEvent->setDtEnd(anEvent->dtStart()); 879 anEvent->setDtEnd(anEvent->dtStart());
877#endif 880#endif
878 881
879// TODO: exdates 882// TODO: exdates
880#if 0 883#if 0
881 // recurrence exceptions 884 // recurrence exceptions
882 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { 885 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
883 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); 886 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo)));
884 deleteStr(s); 887 deleteStr(s);
885 } 888 }
886#endif 889#endif
887 890
888#if 0 891#if 0
889 // secrecy 892 // secrecy
890 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 893 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
891 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); 894 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo)));
892 deleteStr(s); 895 deleteStr(s);
893 } 896 }
894 else 897 else
895 anEvent->setSecrecy("PUBLIC"); 898 anEvent->setSecrecy("PUBLIC");
896 899
897 // attachments 900 // attachments
898 tmpStrList.clear(); 901 tmpStrList.clear();
899 initPropIterator(&voi, vevent); 902 initPropIterator(&voi, vevent);
900 while (moreIteration(&voi)) { 903 while (moreIteration(&voi)) {
901 vo = nextVObject(&voi); 904 vo = nextVObject(&voi);
902 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 905 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
903 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); 906 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo)));
904 deleteStr(s); 907 deleteStr(s);
905 } 908 }
906 } 909 }
907 anEvent->setAttachments(tmpStrList); 910 anEvent->setAttachments(tmpStrList);
908 911
909 // resources 912 // resources
910 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 913 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
911 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 914 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
912 deleteStr(s); 915 deleteStr(s);
913 tmpStrList.clear(); 916 tmpStrList.clear();
914 index1 = 0; 917 index1 = 0;
915 index2 = 0; 918 index2 = 0;
916 QString resource; 919 QString resource;
917 while ((index2 = resources.find(';', index1)) != -1) { 920 while ((index2 = resources.find(';', index1)) != -1) {
918 resource = resources.mid(index1, (index2 - index1)); 921 resource = resources.mid(index1, (index2 - index1));
919 tmpStrList.append(resource); 922 tmpStrList.append(resource);
920 index1 = index2; 923 index1 = index2;
921 } 924 }
922 anEvent->setResources(tmpStrList); 925 anEvent->setResources(tmpStrList);
923 } 926 }
924#endif 927#endif
925 928
926 case ICAL_RELATEDTO_PROPERTY: // releated event (parent) 929 case ICAL_RELATEDTO_PROPERTY: // releated event (parent)
927 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 930 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
928 mEventsRelate.append(event); 931 mEventsRelate.append(event);
929 break; 932 break;
930 933
931 case ICAL_TRANSP_PROPERTY: // Transparency 934 case ICAL_TRANSP_PROPERTY: // Transparency
932 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) 935 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT )
933 event->setTransparency( Event::Transparent ); 936 event->setTransparency( Event::Transparent );
934 else 937 else
935 event->setTransparency( Event::Opaque ); 938 event->setTransparency( Event::Opaque );
936 break; 939 break;
937 940
938 default: 941 default:
939// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind 942// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind
940// << endl; 943// << endl;
941 break; 944 break;
942 } 945 }
943 946
944 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); 947 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY);
945 } 948 }
946 949
947 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); 950 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
948 if (!msade.isNull()) { 951 if (!msade.isNull()) {
949 bool floats = (msade == QString::fromLatin1("TRUE")); 952 bool floats = (msade == QString::fromLatin1("TRUE"));
950 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; 953 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl;
951 event->setFloats(floats); 954 event->setFloats(floats);
952 if (floats) { 955 if (floats) {
953 QDateTime endDate = event->dtEnd(); 956 QDateTime endDate = event->dtEnd();
954 event->setDtEnd(endDate.addDays(-1)); 957 event->setDtEnd(endDate.addDays(-1));
955 } 958 }
956 } 959 }
957 960
958 // some stupid vCal exporters ignore the standard and use Description 961 // some stupid vCal exporters ignore the standard and use Description
959 // instead of Summary for the default field. Correct for this. 962 // instead of Summary for the default field. Correct for this.
960 if (event->summary().isEmpty() && 963 if (event->summary().isEmpty() &&
961 !(event->description().isEmpty())) { 964 !(event->description().isEmpty())) {
962 QString tmpStr = event->description().simplifyWhiteSpace(); 965 QString tmpStr = event->description().simplifyWhiteSpace();
963 event->setDescription(""); 966 event->setDescription("");
964 event->setSummary(tmpStr); 967 event->setSummary(tmpStr);
965 } 968 }
966 969
967 return event; 970 return event;
968} 971}
969 972
970FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) 973FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
971{ 974{
972 FreeBusy *freebusy = new FreeBusy; 975 FreeBusy *freebusy = new FreeBusy;
973 976
974 readIncidenceBase(vfreebusy,freebusy); 977 readIncidenceBase(vfreebusy,freebusy);
975 978
976 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); 979 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
977 980
978 icaltimetype icaltime; 981 icaltimetype icaltime;
979 icalperiodtype icalperiod; 982 icalperiodtype icalperiod;
980 QDateTime period_start, period_end; 983 QDateTime period_start, period_end;
981 984
982 while (p) { 985 while (p) {
983 icalproperty_kind kind = icalproperty_isa(p); 986 icalproperty_kind kind = icalproperty_isa(p);
984 switch (kind) { 987 switch (kind) {
985 988
986 case ICAL_DTSTART_PROPERTY: // start date and time 989 case ICAL_DTSTART_PROPERTY: // start date and time
987 icaltime = icalproperty_get_dtstart(p); 990 icaltime = icalproperty_get_dtstart(p);
988 freebusy->setDtStart(readICalDateTime(icaltime)); 991 freebusy->setDtStart(readICalDateTime(icaltime));
989 break; 992 break;
990 993
991 case ICAL_DTEND_PROPERTY: // start End Date and Time 994 case ICAL_DTEND_PROPERTY: // start End Date and Time
992 icaltime = icalproperty_get_dtend(p); 995 icaltime = icalproperty_get_dtend(p);
993 freebusy->setDtEnd(readICalDateTime(icaltime)); 996 freebusy->setDtEnd(readICalDateTime(icaltime));
994 break; 997 break;
995 998
996 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times 999 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times
997 icalperiod = icalproperty_get_freebusy(p); 1000 icalperiod = icalproperty_get_freebusy(p);
998 period_start = readICalDateTime(icalperiod.start); 1001 period_start = readICalDateTime(icalperiod.start);
999 period_end = readICalDateTime(icalperiod.end); 1002 period_end = readICalDateTime(icalperiod.end);
1000 freebusy->addPeriod(period_start, period_end); 1003 freebusy->addPeriod(period_start, period_end);
1001 break; 1004 break;
1002 1005
1003 default: 1006 default:
1004 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1007 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1005 << endl; 1008 << endl;
1006 break; 1009 break;
1007 } 1010 }
1008 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1011 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1009 } 1012 }
1010 1013
1011 return freebusy; 1014 return freebusy;
1012} 1015}
1013 1016
1014Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1017Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1015{ 1018{
1016 Journal *journal = new Journal; 1019 Journal *journal = new Journal;
1017 1020
1018 readIncidence(vjournal,journal); 1021 readIncidence(vjournal,journal);
1019 1022
1020 return journal; 1023 return journal;
1021} 1024}
1022 1025
1023Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1026Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1024{ 1027{
1025 icalparameter *p = 0; 1028 icalparameter *p = 0;
1026 1029
1027 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1030 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1028 1031
1029 QString name; 1032 QString name;
1030 QString uid = QString::null; 1033 QString uid = QString::null;
1031 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1034 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1032 if (p) { 1035 if (p) {
1033 name = QString::fromUtf8(icalparameter_get_cn(p)); 1036 name = QString::fromUtf8(icalparameter_get_cn(p));
1034 } else { 1037 } else {
1035 } 1038 }
1036 1039
1037 bool rsvp=false; 1040 bool rsvp=false;
1038 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1041 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1039 if (p) { 1042 if (p) {
1040 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1043 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1041 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1044 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1042 } 1045 }
1043 1046
1044 Attendee::PartStat status = Attendee::NeedsAction; 1047 Attendee::PartStat status = Attendee::NeedsAction;
1045 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1048 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1046 if (p) { 1049 if (p) {
1047 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1050 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1048 switch(partStatParameter) { 1051 switch(partStatParameter) {
1049 default: 1052 default:
1050 case ICAL_PARTSTAT_NEEDSACTION: 1053 case ICAL_PARTSTAT_NEEDSACTION:
1051 status = Attendee::NeedsAction; 1054 status = Attendee::NeedsAction;
1052 break; 1055 break;
1053 case ICAL_PARTSTAT_ACCEPTED: 1056 case ICAL_PARTSTAT_ACCEPTED:
1054 status = Attendee::Accepted; 1057 status = Attendee::Accepted;
1055 break; 1058 break;
1056 case ICAL_PARTSTAT_DECLINED: 1059 case ICAL_PARTSTAT_DECLINED:
1057 status = Attendee::Declined; 1060 status = Attendee::Declined;
1058 break; 1061 break;
1059 case ICAL_PARTSTAT_TENTATIVE: 1062 case ICAL_PARTSTAT_TENTATIVE:
1060 status = Attendee::Tentative; 1063 status = Attendee::Tentative;
1061 break; 1064 break;
1062 case ICAL_PARTSTAT_DELEGATED: 1065 case ICAL_PARTSTAT_DELEGATED:
1063 status = Attendee::Delegated; 1066 status = Attendee::Delegated;
1064 break; 1067 break;
1065 case ICAL_PARTSTAT_COMPLETED: 1068 case ICAL_PARTSTAT_COMPLETED:
1066 status = Attendee::Completed; 1069 status = Attendee::Completed;
1067 break; 1070 break;
1068 case ICAL_PARTSTAT_INPROCESS: 1071 case ICAL_PARTSTAT_INPROCESS:
1069 status = Attendee::InProcess; 1072 status = Attendee::InProcess;
1070 break; 1073 break;
1071 } 1074 }
1072 } 1075 }
1073 1076
1074 Attendee::Role role = Attendee::ReqParticipant; 1077 Attendee::Role role = Attendee::ReqParticipant;
1075 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1078 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1076 if (p) { 1079 if (p) {
1077 icalparameter_role roleParameter = icalparameter_get_role(p); 1080 icalparameter_role roleParameter = icalparameter_get_role(p);
1078 switch(roleParameter) { 1081 switch(roleParameter) {
1079 case ICAL_ROLE_CHAIR: 1082 case ICAL_ROLE_CHAIR:
1080 role = Attendee::Chair; 1083 role = Attendee::Chair;
1081 break; 1084 break;
1082 default: 1085 default:
1083 case ICAL_ROLE_REQPARTICIPANT: 1086 case ICAL_ROLE_REQPARTICIPANT:
1084 role = Attendee::ReqParticipant; 1087 role = Attendee::ReqParticipant;
1085 break; 1088 break;
1086 case ICAL_ROLE_OPTPARTICIPANT: 1089 case ICAL_ROLE_OPTPARTICIPANT:
1087 role = Attendee::OptParticipant; 1090 role = Attendee::OptParticipant;
1088 break; 1091 break;
1089 case ICAL_ROLE_NONPARTICIPANT: 1092 case ICAL_ROLE_NONPARTICIPANT:
1090 role = Attendee::NonParticipant; 1093 role = Attendee::NonParticipant;
1091 break; 1094 break;
1092 } 1095 }
1093 } 1096 }
1094 1097
1095 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1098 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1096 uid = icalparameter_get_xvalue(p); 1099 uid = icalparameter_get_xvalue(p);
1097 // This should be added, but there seems to be a libical bug here. 1100 // This should be added, but there seems to be a libical bug here.
1098 /*while (p) { 1101 /*while (p) {
1099 // if (icalparameter_get_xname(p) == "X-UID") { 1102 // if (icalparameter_get_xname(p) == "X-UID") {
1100 uid = icalparameter_get_xvalue(p); 1103 uid = icalparameter_get_xvalue(p);
1101 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1104 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1102 } */ 1105 } */
1103 1106
1104 return new Attendee( name, email, rsvp, status, role, uid ); 1107 return new Attendee( name, email, rsvp, status, role, uid );
1105} 1108}
1106 1109
1107Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1110Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1108{ 1111{
1109 icalattach *a = icalproperty_get_attach(attach); 1112 icalattach *a = icalproperty_get_attach(attach);
1110 icalparameter_value v = ICAL_VALUE_NONE; 1113 icalparameter_value v = ICAL_VALUE_NONE;
1111 icalparameter_encoding e = ICAL_ENCODING_NONE; 1114 icalparameter_encoding e = ICAL_ENCODING_NONE;
1112 1115
1113 Attachment *attachment = 0; 1116 Attachment *attachment = 0;
1114 /* 1117 /*
1115 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1118 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1116 if (vp) 1119 if (vp)
1117 v = icalparameter_get_value(vp); 1120 v = icalparameter_get_value(vp);
1118 1121
1119 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1122 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1120 if (ep) 1123 if (ep)
1121 e = icalparameter_get_encoding(ep); 1124 e = icalparameter_get_encoding(ep);
1122 */ 1125 */
1123 int isurl = icalattach_get_is_url (a); 1126 int isurl = icalattach_get_is_url (a);
1124 if (isurl == 0) 1127 if (isurl == 0)
1125 attachment = new Attachment((const char*)icalattach_get_data(a)); 1128 attachment = new Attachment((const char*)icalattach_get_data(a));
1126 else { 1129 else {
1127 attachment = new Attachment(QString(icalattach_get_url(a))); 1130 attachment = new Attachment(QString(icalattach_get_url(a)));
1128 } 1131 }
1129 1132
1130 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1133 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1131 if (p) 1134 if (p)
1132 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1135 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1133 1136
1134 return attachment; 1137 return attachment;
1135} 1138}
1136#include <qtextcodec.h> 1139#include <qtextcodec.h>
1137void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1140void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1138{ 1141{
1139 readIncidenceBase(parent,incidence); 1142 readIncidenceBase(parent,incidence);
1140 1143
1141 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1144 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1142 bool readrec = false; 1145 bool readrec = false;
1143 const char *text; 1146 const char *text;
1144 int intvalue; 1147 int intvalue;
1145 icaltimetype icaltime; 1148 icaltimetype icaltime;
1146 icaldurationtype icalduration; 1149 icaldurationtype icalduration;
1147 struct icalrecurrencetype rectype; 1150 struct icalrecurrencetype rectype;
1148 QStringList categories; 1151 QStringList categories;
1149 1152
1150 while (p) { 1153 while (p) {
1151 icalproperty_kind kind = icalproperty_isa(p); 1154 icalproperty_kind kind = icalproperty_isa(p);
1152 switch (kind) { 1155 switch (kind) {
1153 1156
1154 case ICAL_CREATED_PROPERTY: 1157 case ICAL_CREATED_PROPERTY:
1155 icaltime = icalproperty_get_created(p); 1158 icaltime = icalproperty_get_created(p);
1156 incidence->setCreated(readICalDateTime(icaltime)); 1159 incidence->setCreated(readICalDateTime(icaltime));
1157 break; 1160 break;
1158 1161
1159 case ICAL_SEQUENCE_PROPERTY: // sequence 1162 case ICAL_SEQUENCE_PROPERTY: // sequence
1160 intvalue = icalproperty_get_sequence(p); 1163 intvalue = icalproperty_get_sequence(p);
1161 incidence->setRevision(intvalue); 1164 incidence->setRevision(intvalue);
1162 break; 1165 break;
1163 1166
1164 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1167 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1165 icaltime = icalproperty_get_lastmodified(p); 1168 icaltime = icalproperty_get_lastmodified(p);
1166 incidence->setLastModified(readICalDateTime(icaltime)); 1169 incidence->setLastModified(readICalDateTime(icaltime));
1167 break; 1170 break;
1168 1171
1169 case ICAL_DTSTART_PROPERTY: // start date and time 1172 case ICAL_DTSTART_PROPERTY: // start date and time
1170 icaltime = icalproperty_get_dtstart(p); 1173 icaltime = icalproperty_get_dtstart(p);
1171 if (icaltime.is_date) { 1174 if (icaltime.is_date) {
1172 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1175 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1173 incidence->setFloats(true); 1176 incidence->setFloats(true);
1174 } else { 1177 } else {
1175 incidence->setDtStart(readICalDateTime(icaltime)); 1178 incidence->setDtStart(readICalDateTime(icaltime));
1176 } 1179 }
1177 break; 1180 break;
1178 1181
1179 case ICAL_DURATION_PROPERTY: // start date and time 1182 case ICAL_DURATION_PROPERTY: // start date and time
1180 icalduration = icalproperty_get_duration(p); 1183 icalduration = icalproperty_get_duration(p);
1181 incidence->setDuration(readICalDuration(icalduration)); 1184 incidence->setDuration(readICalDuration(icalduration));
1182 break; 1185 break;
1183 1186
1184 case ICAL_DESCRIPTION_PROPERTY: // description 1187 case ICAL_DESCRIPTION_PROPERTY: // description
1185 text = icalproperty_get_description(p); 1188 text = icalproperty_get_description(p);
1186 incidence->setDescription(QString::fromUtf8(text)); 1189 incidence->setDescription(QString::fromUtf8(text));
1187 break; 1190 break;
1188 1191
1189 case ICAL_SUMMARY_PROPERTY: // summary 1192 case ICAL_SUMMARY_PROPERTY: // summary
1190 { 1193 {
1191 text = icalproperty_get_summary(p); 1194 text = icalproperty_get_summary(p);
1192 incidence->setSummary(QString::fromUtf8(text)); 1195 incidence->setSummary(QString::fromUtf8(text));
1193 } 1196 }
1194 break; 1197 break;
1195 case ICAL_STATUS_PROPERTY: // summary 1198 case ICAL_STATUS_PROPERTY: // summary
1196 { 1199 {
1197 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1200 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1198 incidence->setCancelled( true ); 1201 incidence->setCancelled( true );
1199 } 1202 }
1200 break; 1203 break;
1201 1204
1202 case ICAL_LOCATION_PROPERTY: // location 1205 case ICAL_LOCATION_PROPERTY: // location
1203 text = icalproperty_get_location(p); 1206 text = icalproperty_get_location(p);
1204 incidence->setLocation(QString::fromUtf8(text)); 1207 incidence->setLocation(QString::fromUtf8(text));
1205 break; 1208 break;
1206 1209
1210 case ICAL_RECURRENCEID_PROPERTY:
1211 icaltime = icalproperty_get_recurrenceid(p);
1212 incidence->setRecurrenceID( readICalDateTime(icaltime) );
1213 qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() );
1214 break;
1207#if 0 1215#if 0
1208 // status 1216 // status
1209 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1217 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1210 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1218 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1211 deleteStr(s); 1219 deleteStr(s);
1212 } 1220 }
1213 else 1221 else
1214 incidence->setStatus("NEEDS ACTION"); 1222 incidence->setStatus("NEEDS ACTION");
1215#endif 1223#endif
1216 1224
1217 case ICAL_PRIORITY_PROPERTY: // priority 1225 case ICAL_PRIORITY_PROPERTY: // priority
1218 intvalue = icalproperty_get_priority(p); 1226 intvalue = icalproperty_get_priority(p);
1219 incidence->setPriority(intvalue); 1227 incidence->setPriority(intvalue);
1220 break; 1228 break;
1221 1229
1222 case ICAL_CATEGORIES_PROPERTY: // categories 1230 case ICAL_CATEGORIES_PROPERTY: // categories
1223 text = icalproperty_get_categories(p); 1231 text = icalproperty_get_categories(p);
1224 categories.append(QString::fromUtf8(text)); 1232 categories.append(QString::fromUtf8(text));
1225 break; 1233 break;
1226 //******************************************* 1234 //*******************************************
1227 case ICAL_RRULE_PROPERTY: 1235 case ICAL_RRULE_PROPERTY:
1228 // we do need (maybe )start datetime of incidence for recurrence 1236 // we do need (maybe )start datetime of incidence for recurrence
1229 // such that we can read recurrence only after we read incidence completely 1237 // such that we can read recurrence only after we read incidence completely
1230 readrec = true; 1238 readrec = true;
1231 rectype = icalproperty_get_rrule(p); 1239 rectype = icalproperty_get_rrule(p);
1232 break; 1240 break;
1233 1241
1234 case ICAL_EXDATE_PROPERTY: 1242 case ICAL_EXDATE_PROPERTY:
1235 icaltime = icalproperty_get_exdate(p); 1243 icaltime = icalproperty_get_exdate(p);
1236 incidence->addExDate(readICalDate(icaltime)); 1244 incidence->addExDate(readICalDate(icaltime));
1237 break; 1245 break;
1238 1246
1239 case ICAL_CLASS_PROPERTY: { 1247 case ICAL_CLASS_PROPERTY: {
1240 int inttext = icalproperty_get_class(p); 1248 int inttext = icalproperty_get_class(p);
1241 if (inttext == ICAL_CLASS_PUBLIC ) { 1249 if (inttext == ICAL_CLASS_PUBLIC ) {
1242 incidence->setSecrecy(Incidence::SecrecyPublic); 1250 incidence->setSecrecy(Incidence::SecrecyPublic);
1243 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1251 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1244 incidence->setSecrecy(Incidence::SecrecyConfidential); 1252 incidence->setSecrecy(Incidence::SecrecyConfidential);
1245 } else { 1253 } else {
1246 incidence->setSecrecy(Incidence::SecrecyPrivate); 1254 incidence->setSecrecy(Incidence::SecrecyPrivate);
1247 } 1255 }
1248 } 1256 }
1249 break; 1257 break;
1250 1258
1251 case ICAL_ATTACH_PROPERTY: // attachments 1259 case ICAL_ATTACH_PROPERTY: // attachments
1252 incidence->addAttachment(readAttachment(p)); 1260 incidence->addAttachment(readAttachment(p));
1253 break; 1261 break;
1254 1262
1255 default: 1263 default:
1256// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1264// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1257// << endl; 1265// << endl;
1258 break; 1266 break;
1259 } 1267 }
1260 1268
1261 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1269 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1262 } 1270 }
1263 if ( readrec ) { 1271 if ( readrec ) {
1264 readRecurrenceRule(rectype,incidence); 1272 readRecurrenceRule(rectype,incidence);
1265 } 1273 }
1266 // kpilot stuff 1274 // kpilot stuff
1267// TODO: move this application-specific code to kpilot 1275// TODO: move this application-specific code to kpilot
1268 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1276 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1269 if (!kp.isNull()) { 1277 if (!kp.isNull()) {
1270 incidence->setPilotId(kp.toInt()); 1278 incidence->setPilotId(kp.toInt());
1271 } 1279 }
1272 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1280 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1273 if (!kp.isNull()) { 1281 if (!kp.isNull()) {
1274 incidence->setSyncStatus(kp.toInt()); 1282 incidence->setSyncStatus(kp.toInt());
1275 } 1283 }
1276 1284
1277 1285
1278 kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); 1286 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1279 if (!kp.isNull()) { 1287 if (!kp.isNull()) {
1280 incidence->setIDStr(kp); 1288 incidence->setIDStr(kp);
1281 } 1289 }
1282 1290
1283 // Cancel backwards compatibility mode for subsequent changes by the application 1291 // Cancel backwards compatibility mode for subsequent changes by the application
1284 incidence->recurrence()->setCompatVersion(); 1292 incidence->recurrence()->setCompatVersion();
1285 1293
1286 // add categories 1294 // add categories
1287 incidence->setCategories(categories); 1295 incidence->setCategories(categories);
1288 1296
1289 // iterate through all alarms 1297 // iterate through all alarms
1290 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1298 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1291 alarm; 1299 alarm;
1292 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1300 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1293 readAlarm(alarm,incidence); 1301 readAlarm(alarm,incidence);
1294 } 1302 }
1295} 1303}
1296 1304
1297void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1305void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1298{ 1306{
1299 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1307 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1300 1308
1301 while (p) { 1309 while (p) {
1302 icalproperty_kind kind = icalproperty_isa(p); 1310 icalproperty_kind kind = icalproperty_isa(p);
1303 switch (kind) { 1311 switch (kind) {
1304 1312
1305 case ICAL_UID_PROPERTY: // unique id 1313 case ICAL_UID_PROPERTY: // unique id
1306 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1314 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1307 break; 1315 break;
1308 1316
1309 case ICAL_ORGANIZER_PROPERTY: // organizer 1317 case ICAL_ORGANIZER_PROPERTY: // organizer
1310 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1318 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1311 break; 1319 break;
1312 1320
1313 case ICAL_ATTENDEE_PROPERTY: // attendee 1321 case ICAL_ATTENDEE_PROPERTY: // attendee
1314 incidenceBase->addAttendee(readAttendee(p)); 1322 incidenceBase->addAttendee(readAttendee(p));
1315 break; 1323 break;
1316 1324
1317 default: 1325 default:
1318 break; 1326 break;
1319 } 1327 }
1320 1328
1321 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1329 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1322 } 1330 }
1323 1331
1324 // custom properties 1332 // custom properties
1325 readCustomProperties(parent, incidenceBase); 1333 readCustomProperties(parent, incidenceBase);
1326} 1334}
1327 1335
1328void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1336void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1329{ 1337{
1330 QMap<QCString, QString> customProperties; 1338 QMap<QCString, QString> customProperties;
1331 1339
1332 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1340 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1333 1341
1334 while (p) { 1342 while (p) {
1335 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1343 QString value = QString::fromUtf8(icalproperty_get_x(p));
1336 customProperties[icalproperty_get_x_name(p)] = value; 1344 customProperties[icalproperty_get_x_name(p)] = value;
1337 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1345 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1338 1346
1339 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1347 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1340 } 1348 }
1341 1349
1342 properties->setCustomProperties(customProperties); 1350 properties->setCustomProperties(customProperties);
1343} 1351}
1344 1352
1345void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1353void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1346{ 1354{
1347// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1355// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1348 1356
1349 Recurrence *recur = incidence->recurrence(); 1357 Recurrence *recur = incidence->recurrence();
1350 recur->setCompatVersion(mCalendarVersion); 1358 recur->setCompatVersion(mCalendarVersion);
1351 recur->unsetRecurs(); 1359 recur->unsetRecurs();
1352 1360
1353 struct icalrecurrencetype r = rrule; 1361 struct icalrecurrencetype r = rrule;
1354 1362
1355 dumpIcalRecurrence(r); 1363 dumpIcalRecurrence(r);
1356 readRecurrence( r, recur, incidence); 1364 readRecurrence( r, recur, incidence);
1357} 1365}
1358 1366
1359void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1367void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1360{ 1368{
1361 int wkst; 1369 int wkst;
1362 int index = 0; 1370 int index = 0;
1363 short day = 0; 1371 short day = 0;
1364 QBitArray qba(7); 1372 QBitArray qba(7);
1365 int frequ = r.freq; 1373 int frequ = r.freq;
1366 int interv = r.interval; 1374 int interv = r.interval;
1367 // preprocessing for odd recurrence definitions 1375 // preprocessing for odd recurrence definitions
1368 1376
1369 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1377 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1370 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1378 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1371 interv = 12; 1379 interv = 12;
1372 } 1380 }
1373 } 1381 }
1374 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1382 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1375 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1383 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1376 frequ = ICAL_MONTHLY_RECURRENCE; 1384 frequ = ICAL_MONTHLY_RECURRENCE;
1377 interv = 12* r.interval; 1385 interv = 12* r.interval;
1378 } 1386 }
1379 } 1387 }
1380 1388
1381 switch (frequ) { 1389 switch (frequ) {
1382 case ICAL_MINUTELY_RECURRENCE: 1390 case ICAL_MINUTELY_RECURRENCE:
1383 if (!icaltime_is_null_time(r.until)) { 1391 if (!icaltime_is_null_time(r.until)) {
1384 recur->setMinutely(interv,readICalDateTime(r.until)); 1392 recur->setMinutely(interv,readICalDateTime(r.until));
1385 } else { 1393 } else {
1386 if (r.count == 0) 1394 if (r.count == 0)
1387 recur->setMinutely(interv,-1); 1395 recur->setMinutely(interv,-1);
1388 else 1396 else
1389 recur->setMinutely(interv,r.count); 1397 recur->setMinutely(interv,r.count);
1390 } 1398 }
1391 break; 1399 break;
1392 case ICAL_HOURLY_RECURRENCE: 1400 case ICAL_HOURLY_RECURRENCE:
1393 if (!icaltime_is_null_time(r.until)) { 1401 if (!icaltime_is_null_time(r.until)) {
1394 recur->setHourly(interv,readICalDateTime(r.until)); 1402 recur->setHourly(interv,readICalDateTime(r.until));
1395 } else { 1403 } else {
1396 if (r.count == 0) 1404 if (r.count == 0)
1397 recur->setHourly(interv,-1); 1405 recur->setHourly(interv,-1);
1398 else 1406 else
1399 recur->setHourly(interv,r.count); 1407 recur->setHourly(interv,r.count);
1400 } 1408 }
1401 break; 1409 break;
1402 case ICAL_DAILY_RECURRENCE: 1410 case ICAL_DAILY_RECURRENCE:
1403 if (!icaltime_is_null_time(r.until)) { 1411 if (!icaltime_is_null_time(r.until)) {
1404 recur->setDaily(interv,readICalDate(r.until)); 1412 recur->setDaily(interv,readICalDate(r.until));
1405 } else { 1413 } else {
1406 if (r.count == 0) 1414 if (r.count == 0)
1407 recur->setDaily(interv,-1); 1415 recur->setDaily(interv,-1);
1408 else 1416 else
1409 recur->setDaily(interv,r.count); 1417 recur->setDaily(interv,r.count);
1410 } 1418 }
1411 break; 1419 break;
1412 case ICAL_WEEKLY_RECURRENCE: 1420 case ICAL_WEEKLY_RECURRENCE:
1413 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1421 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1414 wkst = (r.week_start + 5)%7 + 1; 1422 wkst = (r.week_start + 5)%7 + 1;
1415 if (!icaltime_is_null_time(r.until)) { 1423 if (!icaltime_is_null_time(r.until)) {
1416 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1424 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1417 } else { 1425 } else {
1418 if (r.count == 0) 1426 if (r.count == 0)
1419 recur->setWeekly(interv,qba,-1,wkst); 1427 recur->setWeekly(interv,qba,-1,wkst);
1420 else 1428 else
1421 recur->setWeekly(interv,qba,r.count,wkst); 1429 recur->setWeekly(interv,qba,r.count,wkst);
1422 } 1430 }
1423 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1431 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1424 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1432 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1425 //qDebug("weekly error found "); 1433 //qDebug("weekly error found ");
1426 qba.setBit(wday); 1434 qba.setBit(wday);
1427 } else { 1435 } else {
1428 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1436 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1429 // kdDebug(5800) << " " << day << endl; 1437 // kdDebug(5800) << " " << day << endl;
1430 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1438 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1431 } 1439 }
1432 } 1440 }
1433 break; 1441 break;
1434 case ICAL_MONTHLY_RECURRENCE: 1442 case ICAL_MONTHLY_RECURRENCE:
1435 1443
1436 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1444 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1437 if (!icaltime_is_null_time(r.until)) { 1445 if (!icaltime_is_null_time(r.until)) {
1438 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1446 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1439 readICalDate(r.until)); 1447 readICalDate(r.until));
1440 } else { 1448 } else {
1441 if (r.count == 0) 1449 if (r.count == 0)
1442 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1450 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1443 else 1451 else
1444 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1452 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1445 } 1453 }
1446 bool useSetPos = false; 1454 bool useSetPos = false;
1447 short pos = 0; 1455 short pos = 0;
1448 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1456 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1449 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1457 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1450 pos = icalrecurrencetype_day_position(day); 1458 pos = icalrecurrencetype_day_position(day);
1451 if (pos) { 1459 if (pos) {
1452 day = icalrecurrencetype_day_day_of_week(day); 1460 day = icalrecurrencetype_day_day_of_week(day);
1453 QBitArray ba(7); // don't wipe qba 1461 QBitArray ba(7); // don't wipe qba
1454 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1462 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1455 recur->addMonthlyPos(pos,ba); 1463 recur->addMonthlyPos(pos,ba);
1456 } else { 1464 } else {
1457 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1465 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1458 useSetPos = true; 1466 useSetPos = true;
1459 } 1467 }
1460 } 1468 }
1461 if (useSetPos) { 1469 if (useSetPos) {
1462 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1470 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1463 recur->addMonthlyPos(r.by_set_pos[0],qba); 1471 recur->addMonthlyPos(r.by_set_pos[0],qba);
1464 } 1472 }
1465 } 1473 }
1466 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1474 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1467 if (!icaltime_is_null_time(r.until)) { 1475 if (!icaltime_is_null_time(r.until)) {
1468 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1476 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1469 readICalDate(r.until)); 1477 readICalDate(r.until));
1470 } else { 1478 } else {
1471 if (r.count == 0) 1479 if (r.count == 0)
1472 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1480 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1473 else 1481 else
1474 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1482 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1475 } 1483 }
1476 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1484 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1477 // kdDebug(5800) << "----b " << day << endl; 1485 // kdDebug(5800) << "----b " << day << endl;
1478 recur->addMonthlyDay(day); 1486 recur->addMonthlyDay(day);
1479 } 1487 }
1480 } 1488 }
1481 break; 1489 break;
1482 case ICAL_YEARLY_RECURRENCE: 1490 case ICAL_YEARLY_RECURRENCE:
1483 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1491 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1484 //qDebug(" YEARLY DAY OF YEAR"); 1492 //qDebug(" YEARLY DAY OF YEAR");
1485 if (!icaltime_is_null_time(r.until)) { 1493 if (!icaltime_is_null_time(r.until)) {
1486 recur->setYearly(Recurrence::rYearlyDay,interv, 1494 recur->setYearly(Recurrence::rYearlyDay,interv,
1487 readICalDate(r.until)); 1495 readICalDate(r.until));
1488 } else { 1496 } else {
1489 if (r.count == 0) 1497 if (r.count == 0)
1490 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1498 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1491 else 1499 else
1492 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1500 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1493 } 1501 }
1494 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1502 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1495 recur->addYearlyNum(day); 1503 recur->addYearlyNum(day);
1496 } 1504 }
1497 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1505 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1498 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1506 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1499 qDebug("YEARLY POS NOT SUPPORTED BY GUI"); 1507 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1500 if (!icaltime_is_null_time(r.until)) { 1508 if (!icaltime_is_null_time(r.until)) {
1501 recur->setYearly(Recurrence::rYearlyPos,interv, 1509 recur->setYearly(Recurrence::rYearlyPos,interv,
1502 readICalDate(r.until)); 1510 readICalDate(r.until));
1503 } else { 1511 } else {
1504 if (r.count == 0) 1512 if (r.count == 0)
1505 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1513 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1506 else 1514 else
1507 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1515 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1508 } 1516 }
1509 bool useSetPos = false; 1517 bool useSetPos = false;
1510 short pos = 0; 1518 short pos = 0;
1511 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1519 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1512 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1520 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1513 pos = icalrecurrencetype_day_position(day); 1521 pos = icalrecurrencetype_day_position(day);
1514 if (pos) { 1522 if (pos) {
1515 day = icalrecurrencetype_day_day_of_week(day); 1523 day = icalrecurrencetype_day_day_of_week(day);
1516 QBitArray ba(7); // don't wipe qba 1524 QBitArray ba(7); // don't wipe qba
1517 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1525 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1518 recur->addYearlyMonthPos(pos,ba); 1526 recur->addYearlyMonthPos(pos,ba);
1519 } else { 1527 } else {
1520 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1528 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1521 useSetPos = true; 1529 useSetPos = true;
1522 } 1530 }
1523 } 1531 }
1524 if (useSetPos) { 1532 if (useSetPos) {
1525 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1533 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1526 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1534 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1527 } 1535 }
1528 } 1536 }
1529 } else { 1537 } else {
1530 //qDebug("YEARLY MONTH "); 1538 //qDebug("YEARLY MONTH ");
1531 if (!icaltime_is_null_time(r.until)) { 1539 if (!icaltime_is_null_time(r.until)) {
1532 recur->setYearly(Recurrence::rYearlyMonth,interv, 1540 recur->setYearly(Recurrence::rYearlyMonth,interv,
1533 readICalDate(r.until)); 1541 readICalDate(r.until));
1534 } else { 1542 } else {
1535 if (r.count == 0) 1543 if (r.count == 0)
1536 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1544 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1537 else 1545 else
1538 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1546 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1539 } 1547 }
1540 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1548 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1541 index = 0; 1549 index = 0;
1542 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1550 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1543 recur->addYearlyNum(day); 1551 recur->addYearlyNum(day);
1544 } 1552 }
1545 } else { 1553 } else {
1546 recur->addYearlyNum(incidence->dtStart().date().month()); 1554 recur->addYearlyNum(incidence->dtStart().date().month());
1547 } 1555 }
1548 } 1556 }
1549 1557
1550 } 1558 }
1551 break; 1559 break;
1552 default: 1560 default:
1553 ; 1561 ;
1554 break; 1562 break;
1555 } 1563 }
1556} 1564}
1557 1565
1558void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1566void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1559{ 1567{
1560 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1568 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1561 1569
1562 Alarm* ialarm = incidence->newAlarm(); 1570 Alarm* ialarm = incidence->newAlarm();
1563 ialarm->setRepeatCount(0); 1571 ialarm->setRepeatCount(0);
1564 ialarm->setEnabled(true); 1572 ialarm->setEnabled(true);
1565 1573
1566 // Determine the alarm's action type 1574 // Determine the alarm's action type
1567 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1575 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1568 if ( !p ) { 1576 if ( !p ) {
1569 return; 1577 return;
1570 } 1578 }
1571 1579
1572 icalproperty_action action = icalproperty_get_action(p); 1580 icalproperty_action action = icalproperty_get_action(p);
1573 Alarm::Type type = Alarm::Display; 1581 Alarm::Type type = Alarm::Display;
1574 switch ( action ) { 1582 switch ( action ) {
1575 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1583 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1576 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1584 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1577 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1585 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1578 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1586 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1579 default: 1587 default:
1580 ; 1588 ;
1581 return; 1589 return;
1582 } 1590 }
1583 ialarm->setType(type); 1591 ialarm->setType(type);
1584 1592
1585 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1593 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1586 while (p) { 1594 while (p) {
1587 icalproperty_kind kind = icalproperty_isa(p); 1595 icalproperty_kind kind = icalproperty_isa(p);
1588 1596
1589 switch (kind) { 1597 switch (kind) {
1590 case ICAL_TRIGGER_PROPERTY: { 1598 case ICAL_TRIGGER_PROPERTY: {
1591 icaltriggertype trigger = icalproperty_get_trigger(p); 1599 icaltriggertype trigger = icalproperty_get_trigger(p);
1592 if (icaltime_is_null_time(trigger.time)) { 1600 if (icaltime_is_null_time(trigger.time)) {
1593 if (icaldurationtype_is_null_duration(trigger.duration)) { 1601 if (icaldurationtype_is_null_duration(trigger.duration)) {
1594 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; 1602 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1595 } else { 1603 } else {
1596 Duration duration = icaldurationtype_as_int( trigger.duration ); 1604 Duration duration = icaldurationtype_as_int( trigger.duration );
1597 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1605 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1598 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1606 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1599 ialarm->setEndOffset(duration); 1607 ialarm->setEndOffset(duration);
1600 else 1608 else
1601 ialarm->setStartOffset(duration); 1609 ialarm->setStartOffset(duration);
1602 } 1610 }
1603 } else { 1611 } else {
1604 ialarm->setTime(readICalDateTime(trigger.time)); 1612 ialarm->setTime(readICalDateTime(trigger.time));
1605 } 1613 }
1606 break; 1614 break;
1607 } 1615 }
1608 case ICAL_DURATION_PROPERTY: { 1616 case ICAL_DURATION_PROPERTY: {
1609 icaldurationtype duration = icalproperty_get_duration(p); 1617 icaldurationtype duration = icalproperty_get_duration(p);
1610 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1618 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1611 break; 1619 break;
1612 } 1620 }
1613 case ICAL_REPEAT_PROPERTY: 1621 case ICAL_REPEAT_PROPERTY:
1614 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1622 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1615 break; 1623 break;
1616 1624
1617 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1625 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1618 case ICAL_DESCRIPTION_PROPERTY: { 1626 case ICAL_DESCRIPTION_PROPERTY: {
1619 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1627 QString description = QString::fromUtf8(icalproperty_get_description(p));
1620 switch ( action ) { 1628 switch ( action ) {
1621 case ICAL_ACTION_DISPLAY: 1629 case ICAL_ACTION_DISPLAY:
1622 ialarm->setText( description ); 1630 ialarm->setText( description );
1623 break; 1631 break;
1624 case ICAL_ACTION_PROCEDURE: 1632 case ICAL_ACTION_PROCEDURE:
1625 ialarm->setProgramArguments( description ); 1633 ialarm->setProgramArguments( description );
1626 break; 1634 break;
1627 case ICAL_ACTION_EMAIL: 1635 case ICAL_ACTION_EMAIL:
1628 ialarm->setMailText( description ); 1636 ialarm->setMailText( description );
1629 break; 1637 break;
1630 default: 1638 default:
1631 break; 1639 break;
1632 } 1640 }
1633 break; 1641 break;
1634 } 1642 }
1635 // Only in EMAIL alarm 1643 // Only in EMAIL alarm
1636 case ICAL_SUMMARY_PROPERTY: 1644 case ICAL_SUMMARY_PROPERTY:
1637 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1645 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1638 break; 1646 break;
1639 1647
1640 // Only in EMAIL alarm 1648 // Only in EMAIL alarm
1641 case ICAL_ATTENDEE_PROPERTY: { 1649 case ICAL_ATTENDEE_PROPERTY: {
1642 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1650 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1643 QString name; 1651 QString name;
1644 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1652 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1645 if (param) { 1653 if (param) {
1646 name = QString::fromUtf8(icalparameter_get_cn(param)); 1654 name = QString::fromUtf8(icalparameter_get_cn(param));
1647 } 1655 }
1648 ialarm->addMailAddress(Person(name, email)); 1656 ialarm->addMailAddress(Person(name, email));
1649 break; 1657 break;
1650 } 1658 }
1651 // Only in AUDIO and EMAIL and PROCEDURE alarms 1659 // Only in AUDIO and EMAIL and PROCEDURE alarms
1652 case ICAL_ATTACH_PROPERTY: { 1660 case ICAL_ATTACH_PROPERTY: {
1653 icalattach *attach = icalproperty_get_attach(p); 1661 icalattach *attach = icalproperty_get_attach(p);
1654 QString url = QFile::decodeName(icalattach_get_url(attach)); 1662 QString url = QFile::decodeName(icalattach_get_url(attach));
1655 switch ( action ) { 1663 switch ( action ) {
1656 case ICAL_ACTION_AUDIO: 1664 case ICAL_ACTION_AUDIO:
1657 ialarm->setAudioFile( url ); 1665 ialarm->setAudioFile( url );
1658 break; 1666 break;
1659 case ICAL_ACTION_PROCEDURE: 1667 case ICAL_ACTION_PROCEDURE:
1660 ialarm->setProgramFile( url ); 1668 ialarm->setProgramFile( url );
1661 break; 1669 break;
1662 case ICAL_ACTION_EMAIL: 1670 case ICAL_ACTION_EMAIL:
1663 ialarm->addMailAttachment( url ); 1671 ialarm->addMailAttachment( url );
1664 break; 1672 break;
1665 default: 1673 default:
1666 break; 1674 break;
1667 } 1675 }
1668 break; 1676 break;
1669 } 1677 }
1670 default: 1678 default:
1671 break; 1679 break;
1672 } 1680 }
1673 1681
1674 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1682 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1675 } 1683 }
1676 1684
1677 // custom properties 1685 // custom properties
1678 readCustomProperties(alarm, ialarm); 1686 readCustomProperties(alarm, ialarm);
1679 1687
1680 // TODO: check for consistency of alarm properties 1688 // TODO: check for consistency of alarm properties
1681} 1689}
1682 1690
1683icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1691icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1684{ 1692{
1685 icaltimetype t; 1693 icaltimetype t;
1686 1694
1687 t.year = date.year(); 1695 t.year = date.year();
1688 t.month = date.month(); 1696 t.month = date.month();
1689 t.day = date.day(); 1697 t.day = date.day();
1690 1698
1691 t.hour = 0; 1699 t.hour = 0;
1692 t.minute = 0; 1700 t.minute = 0;
1693 t.second = 0; 1701 t.second = 0;
1694 1702
1695 t.is_date = 1; 1703 t.is_date = 1;
1696 1704
1697 t.is_utc = 0; 1705 t.is_utc = 0;
1698 1706
1699 t.zone = 0; 1707 t.zone = 0;
1700 1708
1701 return t; 1709 return t;
1702} 1710}
1703 1711
1704icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1712icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1705{ 1713{
1706 icaltimetype t; 1714 icaltimetype t;
1707 t.is_date = 0; 1715 t.is_date = 0;
1708 t.zone = 0; 1716 t.zone = 0;
1709 QDateTime datetime; 1717 QDateTime datetime;
1710 if ( mParent->utc() ) { 1718 if ( mParent->utc() ) {
1711 int offset = KGlobal::locale()->localTimeOffset( dt ); 1719 int offset = KGlobal::locale()->localTimeOffset( dt );
1712 datetime = dt.addSecs ( -offset*60); 1720 datetime = dt.addSecs ( -offset*60);
1713 t.is_utc = 1; 1721 t.is_utc = 1;
1714 } 1722 }
1715 else { 1723 else {
1716 datetime = dt; 1724 datetime = dt;
1717 t.is_utc = 0; 1725 t.is_utc = 0;
1718 1726
1719 } 1727 }
1720 t.year = datetime.date().year(); 1728 t.year = datetime.date().year();
1721 t.month = datetime.date().month(); 1729 t.month = datetime.date().month();
1722 t.day = datetime.date().day(); 1730 t.day = datetime.date().day();
1723 1731
1724 t.hour = datetime.time().hour(); 1732 t.hour = datetime.time().hour();
1725 t.minute = datetime.time().minute(); 1733 t.minute = datetime.time().minute();
1726 t.second = datetime.time().second(); 1734 t.second = datetime.time().second();
1727 1735
1728 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1736 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1729 1737
1730// if ( mParent->utc() ) { 1738// if ( mParent->utc() ) {
1731// datetime = KGlobal::locale()->localTime( dt ); 1739// datetime = KGlobal::locale()->localTime( dt );
1732// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1740// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1733// if (mParent->timeZoneId().isEmpty()) 1741// if (mParent->timeZoneId().isEmpty())
1734// t = icaltime_as_utc(t, 0); 1742// t = icaltime_as_utc(t, 0);
1735// else 1743// else
1736// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1744// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1737// } 1745// }
1738 1746
1739 return t; 1747 return t;
1740} 1748}
1741 1749
1742QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1750QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1743{ 1751{
1744 QDateTime dt (QDate(t.year,t.month,t.day), 1752 QDateTime dt (QDate(t.year,t.month,t.day),
1745 QTime(t.hour,t.minute,t.second) ); 1753 QTime(t.hour,t.minute,t.second) );
1746 1754
1747 if (t.is_utc) { 1755 if (t.is_utc) {
1748 int offset = KGlobal::locale()->localTimeOffset( dt ); 1756 int offset = KGlobal::locale()->localTimeOffset( dt );
1749 dt = dt.addSecs ( offset*60); 1757 dt = dt.addSecs ( offset*60);
1750 } 1758 }
1751 1759
1752 return dt; 1760 return dt;
1753} 1761}
1754 1762
1755QDate ICalFormatImpl::readICalDate(icaltimetype t) 1763QDate ICalFormatImpl::readICalDate(icaltimetype t)
1756{ 1764{
1757 return QDate(t.year,t.month,t.day); 1765 return QDate(t.year,t.month,t.day);
1758} 1766}
1759 1767
1760icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1768icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1761{ 1769{
1762 icaldurationtype d; 1770 icaldurationtype d;
1763 1771
1764 d.weeks = seconds % gSecondsPerWeek; 1772 d.weeks = seconds % gSecondsPerWeek;
1765 seconds -= d.weeks * gSecondsPerWeek; 1773 seconds -= d.weeks * gSecondsPerWeek;
1766 d.days = seconds % gSecondsPerDay; 1774 d.days = seconds % gSecondsPerDay;
1767 seconds -= d.days * gSecondsPerDay; 1775 seconds -= d.days * gSecondsPerDay;
1768 d.hours = seconds % gSecondsPerHour; 1776 d.hours = seconds % gSecondsPerHour;
1769 seconds -= d.hours * gSecondsPerHour; 1777 seconds -= d.hours * gSecondsPerHour;
1770 d.minutes = seconds % gSecondsPerMinute; 1778 d.minutes = seconds % gSecondsPerMinute;
1771 seconds -= d.minutes * gSecondsPerMinute; 1779 seconds -= d.minutes * gSecondsPerMinute;
1772 d.seconds = seconds; 1780 d.seconds = seconds;
1773 d.is_neg = 0; 1781 d.is_neg = 0;
1774 1782
1775 return d; 1783 return d;
1776} 1784}
1777 1785
1778int ICalFormatImpl::readICalDuration(icaldurationtype d) 1786int ICalFormatImpl::readICalDuration(icaldurationtype d)
1779{ 1787{
1780 int result = 0; 1788 int result = 0;
1781 1789
1782 result += d.weeks * gSecondsPerWeek; 1790 result += d.weeks * gSecondsPerWeek;
1783 result += d.days * gSecondsPerDay; 1791 result += d.days * gSecondsPerDay;
1784 result += d.hours * gSecondsPerHour; 1792 result += d.hours * gSecondsPerHour;
1785 result += d.minutes * gSecondsPerMinute; 1793 result += d.minutes * gSecondsPerMinute;
1786 result += d.seconds; 1794 result += d.seconds;
1787 1795
1788 if (d.is_neg) result *= -1; 1796 if (d.is_neg) result *= -1;
1789 1797
1790 return result; 1798 return result;
1791} 1799}
1792 1800
1793icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1801icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1794{ 1802{
1795 icalcomponent *calendar; 1803 icalcomponent *calendar;
1796 1804
1797 // Root component 1805 // Root component
1798 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1806 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1799 1807
1800 icalproperty *p; 1808 icalproperty *p;
1801 1809
1802 // Product Identifier 1810 // Product Identifier
1803 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1811 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1804 icalcomponent_add_property(calendar,p); 1812 icalcomponent_add_property(calendar,p);
1805 1813
1806 // TODO: Add time zone 1814 // TODO: Add time zone
1807 1815
1808 // iCalendar version (2.0) 1816 // iCalendar version (2.0)
1809 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1817 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1810 icalcomponent_add_property(calendar,p); 1818 icalcomponent_add_property(calendar,p);
1811 1819
1812 // Custom properties 1820 // Custom properties
1813 if( cal != 0 ) 1821 if( cal != 0 )
1814 writeCustomProperties(calendar, cal); 1822 writeCustomProperties(calendar, cal);
1815 1823
1816 return calendar; 1824 return calendar;
1817} 1825}
1818 1826
1819 1827
1820 1828
1821// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1829// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1822// and break it down from its tree-like format into the dictionary format 1830// and break it down from its tree-like format into the dictionary format
1823// that is used internally in the ICalFormatImpl. 1831// that is used internally in the ICalFormatImpl.
1824bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1832bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1825{ 1833{
1826 // this function will populate the caldict dictionary and other event 1834 // this function will populate the caldict dictionary and other event
1827 // lists. It turns vevents into Events and then inserts them. 1835 // lists. It turns vevents into Events and then inserts them.
1828 1836
1829 if (!calendar) return false; 1837 if (!calendar) return false;
1830 1838
1831// TODO: check for METHOD 1839// TODO: check for METHOD
1832#if 0 1840#if 0
1833 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1841 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1834 char *methodType = 0; 1842 char *methodType = 0;
1835 methodType = fakeCString(vObjectUStringZValue(curVO)); 1843 methodType = fakeCString(vObjectUStringZValue(curVO));
1836 if (mEnableDialogs) 1844 if (mEnableDialogs)
1837 KMessageBox::information(mTopWidget, 1845 KMessageBox::information(mTopWidget,
1838 i18n("This calendar is an iTIP transaction of type \"%1\".") 1846 i18n("This calendar is an iTIP transaction of type \"%1\".")
1839 .arg(methodType), 1847 .arg(methodType),
1840 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1848 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1841 delete methodType; 1849 delete methodType;
1842 } 1850 }
1843#endif 1851#endif
1844 1852
1845 icalproperty *p; 1853 icalproperty *p;
1846 1854
1847 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1855 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1848 if (!p) { 1856 if (!p) {
1849// TODO: does no PRODID really matter? 1857// TODO: does no PRODID really matter?
1850// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1858// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1851// return false; 1859// return false;
1852 mLoadedProductId = ""; 1860 mLoadedProductId = "";
1853 mCalendarVersion = 0; 1861 mCalendarVersion = 0;
1854 } else { 1862 } else {
1855 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1863 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1856 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1864 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1857 1865
1858 delete mCompat; 1866 delete mCompat;
1859 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1867 mCompat = CompatFactory::createCompat( mLoadedProductId );
1860 } 1868 }
1861 1869
1862// TODO: check for unknown PRODID 1870// TODO: check for unknown PRODID
1863#if 0 1871#if 0
1864 if (!mCalendarVersion 1872 if (!mCalendarVersion
1865 && CalFormat::productId() != mLoadedProductId) { 1873 && CalFormat::productId() != mLoadedProductId) {
1866 // warn the user that we might have trouble reading non-known calendar. 1874 // warn the user that we might have trouble reading non-known calendar.
1867 if (mEnableDialogs) 1875 if (mEnableDialogs)
1868 KMessageBox::information(mTopWidget, 1876 KMessageBox::information(mTopWidget,
1869 i18n("This vCalendar file was not created by KOrganizer " 1877 i18n("This vCalendar file was not created by KOrganizer "
1870 "or any other product we support. Loading anyway..."), 1878 "or any other product we support. Loading anyway..."),
1871 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); 1879 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application()));
1872 } 1880 }
1873#endif 1881#endif
1874 1882
1875 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); 1883 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
1876 if (!p) { 1884 if (!p) {
1877 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1885 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1878 return false; 1886 return false;
1879 } else { 1887 } else {
1880 const char *version = icalproperty_get_version(p); 1888 const char *version = icalproperty_get_version(p);
1881 1889
1882 if (strcmp(version,"1.0") == 0) { 1890 if (strcmp(version,"1.0") == 0) {
1883 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, 1891 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1,
1884 i18n("Expected iCalendar format"))); 1892 i18n("Expected iCalendar format")));
1885 return false; 1893 return false;
1886 } else if (strcmp(version,"2.0") != 0) { 1894 } else if (strcmp(version,"2.0") != 0) {
1887 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1895 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1888 return false; 1896 return false;
1889 } 1897 }
1890 } 1898 }
1891 1899
1892 1900
1893// TODO: check for calendar format version 1901// TODO: check for calendar format version
1894#if 0 1902#if 0
1895 // warn the user we might have trouble reading this unknown version. 1903 // warn the user we might have trouble reading this unknown version.
1896 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1904 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1897 char *s = fakeCString(vObjectUStringZValue(curVO)); 1905 char *s = fakeCString(vObjectUStringZValue(curVO));
1898 if (strcmp(_VCAL_VERSION, s) != 0) 1906 if (strcmp(_VCAL_VERSION, s) != 0)
1899 if (mEnableDialogs) 1907 if (mEnableDialogs)
1900 KMessageBox::sorry(mTopWidget, 1908 KMessageBox::sorry(mTopWidget,
1901 i18n("This vCalendar file has version %1.\n" 1909 i18n("This vCalendar file has version %1.\n"
1902 "We only support %2.") 1910 "We only support %2.")
1903 .arg(s).arg(_VCAL_VERSION), 1911 .arg(s).arg(_VCAL_VERSION),
1904 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); 1912 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application()));
1905 deleteStr(s); 1913 deleteStr(s);
1906 } 1914 }
1907#endif 1915#endif
1908 1916
1909 // custom properties 1917 // custom properties
1910 readCustomProperties(calendar, cal); 1918 readCustomProperties(calendar, cal);
1911 1919
1912// TODO: set time zone 1920// TODO: set time zone
1913#if 0 1921#if 0
1914 // set the time zone 1922 // set the time zone
1915 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1923 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1916 char *s = fakeCString(vObjectUStringZValue(curVO)); 1924 char *s = fakeCString(vObjectUStringZValue(curVO));
1917 cal->setTimeZone(s); 1925 cal->setTimeZone(s);
1918 deleteStr(s); 1926 deleteStr(s);
1919 } 1927 }
1920#endif 1928#endif
1921 1929
1922 // Store all events with a relatedTo property in a list for post-processing 1930 // Store all events with a relatedTo property in a list for post-processing
1923 mEventsRelate.clear(); 1931 mEventsRelate.clear();
1924 mTodosRelate.clear(); 1932 mTodosRelate.clear();
1925 // TODO: make sure that only actually added ecvens go to this lists. 1933 // TODO: make sure that only actually added ecvens go to this lists.
1926 1934
1927 icalcomponent *c; 1935 icalcomponent *c;
1928 1936
1929 // Iterate through all todos 1937 // Iterate through all todos
1930 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); 1938 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
1931 while (c) { 1939 while (c) {
1932// kdDebug(5800) << "----Todo found" << endl; 1940// kdDebug(5800) << "----Todo found" << endl;
1933 Todo *todo = readTodo(c); 1941 Todo *todo = readTodo(c);
1934 if (!cal->todo(todo->uid())) cal->addTodo(todo); 1942 if (!cal->todo(todo->uid())) cal->addTodo(todo);
1935 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); 1943 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
1936 } 1944 }
1937 1945
1938 // Iterate through all events 1946 // Iterate through all events
1939 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); 1947 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
1940 while (c) { 1948 while (c) {
1941// kdDebug(5800) << "----Event found" << endl; 1949// kdDebug(5800) << "----Event found" << endl;
1942 Event *event = readEvent(c); 1950 Event *event = readEvent(c);
1943 if (!cal->event(event->uid())) cal->addEvent(event); 1951 if (!cal->event(event->uid())) cal->addEvent(event);
1944 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); 1952 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
1945 } 1953 }
1946 1954
1947 // Iterate through all journals 1955 // Iterate through all journals
1948 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); 1956 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
1949 while (c) { 1957 while (c) {
1950// kdDebug(5800) << "----Journal found" << endl; 1958// kdDebug(5800) << "----Journal found" << endl;
1951 Journal *journal = readJournal(c); 1959 Journal *journal = readJournal(c);
1952 if (!cal->journal(journal->uid())) cal->addJournal(journal); 1960 if (!cal->journal(journal->uid())) cal->addJournal(journal);
1953 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); 1961 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
1954 } 1962 }
1955 1963
1956#if 0 1964#if 0
1957 initPropIterator(&i, vcal); 1965 initPropIterator(&i, vcal);
1958 1966
1959 // go through all the vobjects in the vcal 1967 // go through all the vobjects in the vcal
1960 while (moreIteration(&i)) { 1968 while (moreIteration(&i)) {
1961 curVO = nextVObject(&i); 1969 curVO = nextVObject(&i);
1962 1970
1963 /************************************************************************/ 1971 /************************************************************************/
1964 1972
1965 // now, check to see that the object is an event or todo. 1973 // now, check to see that the object is an event or todo.
1966 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1974 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1967 1975
1968 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { 1976 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) {
1969 char *s; 1977 char *s;
1970 s = fakeCString(vObjectUStringZValue(curVOProp)); 1978 s = fakeCString(vObjectUStringZValue(curVOProp));
1971 // check to see if event was deleted by the kpilot conduit 1979 // check to see if event was deleted by the kpilot conduit
1972 if (atoi(s) == Event::SYNCDEL) { 1980 if (atoi(s) == Event::SYNCDEL) {
1973 deleteStr(s); 1981 deleteStr(s);
1974 goto SKIP; 1982 goto SKIP;
1975 } 1983 }
1976 deleteStr(s); 1984 deleteStr(s);
1977 } 1985 }
1978 1986
1979 // this code checks to see if we are trying to read in an event 1987 // this code checks to see if we are trying to read in an event
1980 // that we already find to be in the calendar. If we find this 1988 // that we already find to be in the calendar. If we find this
1981 // to be the case, we skip the event. 1989 // to be the case, we skip the event.
1982 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1990 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1983 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1991 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1984 QString tmpStr(s); 1992 QString tmpStr(s);
1985 deleteStr(s); 1993 deleteStr(s);
1986 1994
1987 if (cal->event(tmpStr)) { 1995 if (cal->event(tmpStr)) {
1988 goto SKIP; 1996 goto SKIP;
1989 } 1997 }
1990 if (cal->todo(tmpStr)) { 1998 if (cal->todo(tmpStr)) {
1991 goto SKIP; 1999 goto SKIP;
1992 } 2000 }
1993 } 2001 }
1994 2002
1995 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 2003 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1996 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 2004 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1997 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 2005 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1998 goto SKIP; 2006 goto SKIP;
1999 } 2007 }
2000 2008
2001 anEvent = VEventToEvent(curVO); 2009 anEvent = VEventToEvent(curVO);
2002 // we now use addEvent instead of insertEvent so that the 2010 // we now use addEvent instead of insertEvent so that the
2003 // signal/slot get connected. 2011 // signal/slot get connected.
2004 if (anEvent) 2012 if (anEvent)
2005 cal->addEvent(anEvent); 2013 cal->addEvent(anEvent);
2006 else { 2014 else {
2007 // some sort of error must have occurred while in translation. 2015 // some sort of error must have occurred while in translation.
2008 goto SKIP; 2016 goto SKIP;
2009 } 2017 }
2010 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 2018 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
2011 anEvent = VTodoToEvent(curVO); 2019 anEvent = VTodoToEvent(curVO);
2012 cal->addTodo(anEvent); 2020 cal->addTodo(anEvent);
2013 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 2021 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
2014 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 2022 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
2015 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 2023 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
2016 // do nothing, we know these properties and we want to skip them. 2024 // do nothing, we know these properties and we want to skip them.
2017 // we have either already processed them or are ignoring them. 2025 // we have either already processed them or are ignoring them.
2018 ; 2026 ;
2019 } else { 2027 } else {
2020 ; 2028 ;
2021 } 2029 }
2022 SKIP: 2030 SKIP:
2023 ; 2031 ;
2024 } // while 2032 } // while
2025#endif 2033#endif
2026 2034
2027 // Post-Process list of events with relations, put Event objects in relation 2035 // Post-Process list of events with relations, put Event objects in relation
2028 Event *ev; 2036 Event *ev;
2029 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 2037 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
2030 ev->setRelatedTo(cal->event(ev->relatedToUid())); 2038 ev->setRelatedTo(cal->event(ev->relatedToUid()));
2031 } 2039 }
2032 Todo *todo; 2040 Todo *todo;
2033 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 2041 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
2034 todo->setRelatedTo(cal->todo(todo->relatedToUid())); 2042 todo->setRelatedTo(cal->todo(todo->relatedToUid()));
2035 } 2043 }
2036 2044
2037 return true; 2045 return true;
2038} 2046}
2039 2047
2040QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) 2048QString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2041{ 2049{
2042// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " 2050// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: "
2043// << icalcomponent_as_ical_string(c) << endl; 2051// << icalcomponent_as_ical_string(c) << endl;
2044 2052
2045 QString errorMessage; 2053 QString errorMessage;
2046 2054
2047 icalproperty *error; 2055 icalproperty *error;
2048 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); 2056 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
2049 while(error) { 2057 while(error) {
2050 errorMessage += icalproperty_get_xlicerror(error); 2058 errorMessage += icalproperty_get_xlicerror(error);
2051 errorMessage += "\n"; 2059 errorMessage += "\n";
2052 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); 2060 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY);
2053 } 2061 }
2054 2062
2055// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; 2063// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl;
2056 2064
2057 return errorMessage; 2065 return errorMessage;
2058} 2066}
2059 2067
2060void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) 2068void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r)
2061{ 2069{
2062 int i; 2070 int i;
2063 2071
2064 2072
2065 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2073 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2066 int index = 0; 2074 int index = 0;
2067 QString out = " By Day: "; 2075 QString out = " By Day: ";
2068 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2076 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2069 out.append(QString::number(i) + " "); 2077 out.append(QString::number(i) + " ");
2070 } 2078 }
2071 } 2079 }
2072 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2080 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2073 int index = 0; 2081 int index = 0;
2074 QString out = " By Month Day: "; 2082 QString out = " By Month Day: ";
2075 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2083 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2076 out.append(QString::number(i) + " "); 2084 out.append(QString::number(i) + " ");
2077 } 2085 }
2078 } 2086 }
2079 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2087 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2080 int index = 0; 2088 int index = 0;
2081 QString out = " By Year Day: "; 2089 QString out = " By Year Day: ";
2082 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2090 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2083 out.append(QString::number(i) + " "); 2091 out.append(QString::number(i) + " ");
2084 } 2092 }
2085 } 2093 }
2086 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2094 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2087 int index = 0; 2095 int index = 0;
2088 QString out = " By Month: "; 2096 QString out = " By Month: ";
2089 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2097 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2090 out.append(QString::number(i) + " "); 2098 out.append(QString::number(i) + " ");
2091 } 2099 }
2092 } 2100 }
2093 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2101 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2094 int index = 0; 2102 int index = 0;
2095 QString out = " By Set Pos: "; 2103 QString out = " By Set Pos: ";
2096 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2104 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2097 out.append(QString::number(i) + " "); 2105 out.append(QString::number(i) + " ");
2098 } 2106 }
2099 } 2107 }
2100} 2108}
2101 2109
2102icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, 2110icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence,
2103 Scheduler::Method method) 2111 Scheduler::Method method)
2104{ 2112{
2105 icalcomponent *message = createCalendarComponent(); 2113 icalcomponent *message = createCalendarComponent();
2106 2114
2107 icalproperty_method icalmethod = ICAL_METHOD_NONE; 2115 icalproperty_method icalmethod = ICAL_METHOD_NONE;
2108 2116
2109 switch (method) { 2117 switch (method) {
2110 case Scheduler::Publish: 2118 case Scheduler::Publish:
2111 icalmethod = ICAL_METHOD_PUBLISH; 2119 icalmethod = ICAL_METHOD_PUBLISH;
2112 break; 2120 break;
2113 case Scheduler::Request: 2121 case Scheduler::Request:
2114 icalmethod = ICAL_METHOD_REQUEST; 2122 icalmethod = ICAL_METHOD_REQUEST;
2115 break; 2123 break;
2116 case Scheduler::Refresh: 2124 case Scheduler::Refresh:
2117 icalmethod = ICAL_METHOD_REFRESH; 2125 icalmethod = ICAL_METHOD_REFRESH;
2118 break; 2126 break;
2119 case Scheduler::Cancel: 2127 case Scheduler::Cancel:
2120 icalmethod = ICAL_METHOD_CANCEL; 2128 icalmethod = ICAL_METHOD_CANCEL;
2121 break; 2129 break;
2122 case Scheduler::Add: 2130 case Scheduler::Add:
2123 icalmethod = ICAL_METHOD_ADD; 2131 icalmethod = ICAL_METHOD_ADD;
2124 break; 2132 break;
2125 case Scheduler::Reply: 2133 case Scheduler::Reply:
2126 icalmethod = ICAL_METHOD_REPLY; 2134 icalmethod = ICAL_METHOD_REPLY;
2127 break; 2135 break;
2128 case Scheduler::Counter: 2136 case Scheduler::Counter:
2129 icalmethod = ICAL_METHOD_COUNTER; 2137 icalmethod = ICAL_METHOD_COUNTER;
2130 break; 2138 break;
2131 case Scheduler::Declinecounter: 2139 case Scheduler::Declinecounter:
2132 icalmethod = ICAL_METHOD_DECLINECOUNTER; 2140 icalmethod = ICAL_METHOD_DECLINECOUNTER;
2133 break; 2141 break;
2134 default: 2142 default:
2135 2143
2136 return message; 2144 return message;
2137 } 2145 }
2138 2146
2139 icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); 2147 icalcomponent_add_property(message,icalproperty_new_method(icalmethod));
2140 2148
2141 // TODO: check, if dynamic cast is required 2149 // TODO: check, if dynamic cast is required
2142 if(incidence->type() == "Todo") { 2150 if(incidence->type() == "Todo") {
2143 Todo *todo = static_cast<Todo *>(incidence); 2151 Todo *todo = static_cast<Todo *>(incidence);
2144 icalcomponent_add_component(message,writeTodo(todo)); 2152 icalcomponent_add_component(message,writeTodo(todo));
2145 } 2153 }
2146 if(incidence->type() == "Event") { 2154 if(incidence->type() == "Event") {
2147 Event *event = static_cast<Event *>(incidence); 2155 Event *event = static_cast<Event *>(incidence);
2148 icalcomponent_add_component(message,writeEvent(event)); 2156 icalcomponent_add_component(message,writeEvent(event));
2149 } 2157 }
2150 if(incidence->type() == "FreeBusy") { 2158 if(incidence->type() == "FreeBusy") {
2151 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); 2159 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence);
2152 icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); 2160 icalcomponent_add_component(message,writeFreeBusy(freebusy, method));
2153 } 2161 }
2154 2162
2155 return message; 2163 return message;
2156} 2164}
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index f9e1e9e..dbc159c 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,616 +1,649 @@
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 = new Recurrence(this); 36 mRecurrence = 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} 43}
43 44
44Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 45Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
45{ 46{
46// TODO: reenable attributes currently commented out. 47// TODO: reenable attributes currently commented out.
47 mRevision = i.mRevision; 48 mRevision = i.mRevision;
48 mCreated = i.mCreated; 49 mCreated = i.mCreated;
49 mDescription = i.mDescription; 50 mDescription = i.mDescription;
50 mSummary = i.mSummary; 51 mSummary = i.mSummary;
51 mCategories = i.mCategories; 52 mCategories = i.mCategories;
52// Incidence *mRelatedTo; Incidence *mRelatedTo; 53// Incidence *mRelatedTo; Incidence *mRelatedTo;
53 mRelatedTo = 0; 54 mRelatedTo = 0;
54 mRelatedToUid = i.mRelatedToUid; 55 mRelatedToUid = i.mRelatedToUid;
55// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 56// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
56 mExDates = i.mExDates; 57 mExDates = i.mExDates;
57 mAttachments = i.mAttachments; 58 mAttachments = i.mAttachments;
58 mResources = i.mResources; 59 mResources = i.mResources;
59 mSecrecy = i.mSecrecy; 60 mSecrecy = i.mSecrecy;
60 mPriority = i.mPriority; 61 mPriority = i.mPriority;
61 mLocation = i.mLocation; 62 mLocation = i.mLocation;
62 mCancelled = i.mCancelled; 63 mCancelled = i.mCancelled;
63 mHasStartDate = i.mHasStartDate; 64 mHasStartDate = i.mHasStartDate;
64 QPtrListIterator<Alarm> it( i.mAlarms ); 65 QPtrListIterator<Alarm> it( i.mAlarms );
65 const Alarm *a; 66 const Alarm *a;
66 while( (a = it.current()) ) { 67 while( (a = it.current()) ) {
67 Alarm *b = new Alarm( *a ); 68 Alarm *b = new Alarm( *a );
68 b->setParent( this ); 69 b->setParent( this );
69 mAlarms.append( b ); 70 mAlarms.append( b );
70 71
71 ++it; 72 ++it;
72 } 73 }
73 mAlarms.setAutoDelete(true); 74 mAlarms.setAutoDelete(true);
74 75 mHasRecurrenceID = i.mHasRecurrenceID;
76 mRecurrenceID = i.mRecurrenceID;
75 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 77 mRecurrence = new Recurrence( *(i.mRecurrence), this );
76} 78}
77 79
78Incidence::~Incidence() 80Incidence::~Incidence()
79{ 81{
80 82
81 Incidence *ev; 83 Incidence *ev;
82 QPtrList<Incidence> Relations = relations(); 84 QPtrList<Incidence> Relations = relations();
83 for (ev=Relations.first();ev;ev=Relations.next()) { 85 for (ev=Relations.first();ev;ev=Relations.next()) {
84 if (ev->relatedTo() == this) ev->setRelatedTo(0); 86 if (ev->relatedTo() == this) ev->setRelatedTo(0);
85 } 87 }
86 if (relatedTo()) relatedTo()->removeRelation(this); 88 if (relatedTo()) relatedTo()->removeRelation(this);
87 delete mRecurrence; 89 delete mRecurrence;
88 90
89} 91}
92bool Incidence::hasRecurrenceID() const
93{
94 return mHasRecurrenceID;
95}
96
97void Incidence::setHasRecurrenceID( bool b )
98{
99 mHasRecurrenceID = b;
100}
101
102void Incidence::setRecurrenceID(QDateTime d)
103{
104 mRecurrenceID = d;
105 mHasRecurrenceID = true;
106 updated();
107}
108QDateTime Incidence::recurrenceID () const
109{
110 return mRecurrenceID;
111}
90 112
91bool Incidence::cancelled() const 113bool Incidence::cancelled() const
92{ 114{
93 return mCancelled; 115 return mCancelled;
94} 116}
95void Incidence::setCancelled( bool b ) 117void Incidence::setCancelled( bool b )
96{ 118{
97 mCancelled = b; 119 mCancelled = b;
98 updated(); 120 updated();
99} 121}
100bool Incidence::hasStartDate() const 122bool Incidence::hasStartDate() const
101{ 123{
102 return mHasStartDate; 124 return mHasStartDate;
103} 125}
104 126
105void Incidence::setHasStartDate(bool f) 127void Incidence::setHasStartDate(bool f)
106{ 128{
107 if (mReadOnly) return; 129 if (mReadOnly) return;
108 mHasStartDate = f; 130 mHasStartDate = f;
109 updated(); 131 updated();
110} 132}
111 133
112// A string comparison that considers that null and empty are the same 134// A string comparison that considers that null and empty are the same
113static bool stringCompare( const QString& s1, const QString& s2 ) 135static bool stringCompare( const QString& s1, const QString& s2 )
114{ 136{
115 if ( s1.isEmpty() && s2.isEmpty() ) 137 if ( s1.isEmpty() && s2.isEmpty() )
116 return true; 138 return true;
117 return s1 == s2; 139 return s1 == s2;
118} 140}
119 141
120bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 142bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
121{ 143{
122 144
123 if( i1.alarms().count() != i2.alarms().count() ) { 145 if( i1.alarms().count() != i2.alarms().count() ) {
124 return false; // no need to check further 146 return false; // no need to check further
125 } 147 }
126 if ( i1.alarms().count() > 0 ) { 148 if ( i1.alarms().count() > 0 ) {
127 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 149 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
128 { 150 {
129 qDebug("alarm not equal "); 151 qDebug("alarm not equal ");
130 return false; 152 return false;
131 } 153 }
132 } 154 }
133#if 0 155#if 0
134 QPtrListIterator<Alarm> a1( i1.alarms() ); 156 QPtrListIterator<Alarm> a1( i1.alarms() );
135 QPtrListIterator<Alarm> a2( i2.alarms() ); 157 QPtrListIterator<Alarm> a2( i2.alarms() );
136 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 158 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
137 if( *a1.current() == *a2.current() ) { 159 if( *a1.current() == *a2.current() ) {
138 continue; 160 continue;
139 } 161 }
140 else { 162 else {
141 return false; 163 return false;
142 } 164 }
143 } 165 }
144#endif 166#endif
145 167
168 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
169 if ( i1.hasRecurrenceID() ) {
170 if ( i1.recurrenceID() != i2.recurrenceID() )
171 return false;
172 }
173
174 } else {
175 return false;
176 }
177
146 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 178 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
147 return false; 179 return false;
148 if ( i1.hasStartDate() == i2.hasStartDate() ) { 180 if ( i1.hasStartDate() == i2.hasStartDate() ) {
149 if ( i1.hasStartDate() ) { 181 if ( i1.hasStartDate() ) {
150 if ( i1.dtStart() != i2.dtStart() ) 182 if ( i1.dtStart() != i2.dtStart() )
151 return false; 183 return false;
152 } 184 }
153 } else { 185 } else {
154 return false; 186 return false;
155 } 187 }
156 if (!( *i1.recurrence() == *i2.recurrence()) ) { 188 if (!( *i1.recurrence() == *i2.recurrence()) ) {
157 qDebug("recurrence is NOT equal "); 189 qDebug("recurrence is NOT equal ");
158 return false; 190 return false;
159 } 191 }
160 return 192 return
161 // i1.created() == i2.created() && 193 // i1.created() == i2.created() &&
162 stringCompare( i1.description(), i2.description() ) && 194 stringCompare( i1.description(), i2.description() ) &&
163 stringCompare( i1.summary(), i2.summary() ) && 195 stringCompare( i1.summary(), i2.summary() ) &&
164 i1.categories() == i2.categories() && 196 i1.categories() == i2.categories() &&
165 // no need to compare mRelatedTo 197 // no need to compare mRelatedTo
166 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 198 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
167 // i1.relations() == i2.relations() && 199 // i1.relations() == i2.relations() &&
168 i1.exDates() == i2.exDates() && 200 i1.exDates() == i2.exDates() &&
169 i1.attachments() == i2.attachments() && 201 i1.attachments() == i2.attachments() &&
170 i1.resources() == i2.resources() && 202 i1.resources() == i2.resources() &&
171 i1.secrecy() == i2.secrecy() && 203 i1.secrecy() == i2.secrecy() &&
172 i1.priority() == i2.priority() && 204 i1.priority() == i2.priority() &&
205 i1.cancelled() == i2.cancelled() &&
173 stringCompare( i1.location(), i2.location() ); 206 stringCompare( i1.location(), i2.location() );
174} 207}
175 208
176Incidence* Incidence::recreateCloneException( QDate d ) 209Incidence* Incidence::recreateCloneException( QDate d )
177{ 210{
178 Incidence* newInc = clone(); 211 Incidence* newInc = clone();
179 newInc->recreate(); 212 newInc->recreate();
180 if ( doesRecur() ) { 213 if ( doesRecur() ) {
181 addExDate( d ); 214 addExDate( d );
182 newInc->recurrence()->unsetRecurs(); 215 newInc->recurrence()->unsetRecurs();
183 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 216 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
184 QTime tim = dtStart().time(); 217 QTime tim = dtStart().time();
185 newInc->setDtStart( QDateTime(d, tim) ); 218 newInc->setDtStart( QDateTime(d, tim) );
186 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 219 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
187 } 220 }
188 return newInc; 221 return newInc;
189} 222}
190 223
191void Incidence::recreate() 224void Incidence::recreate()
192{ 225{
193 setCreated(QDateTime::currentDateTime()); 226 setCreated(QDateTime::currentDateTime());
194 227
195 setUid(CalFormat::createUniqueId()); 228 setUid(CalFormat::createUniqueId());
196 229
197 setRevision(0); 230 setRevision(0);
198 setIDStr( ":" ); 231 setIDStr( ":" );
199 setLastModified(QDateTime::currentDateTime()); 232 setLastModified(QDateTime::currentDateTime());
200} 233}
201 234
202void Incidence::setReadOnly( bool readOnly ) 235void Incidence::setReadOnly( bool readOnly )
203{ 236{
204 IncidenceBase::setReadOnly( readOnly ); 237 IncidenceBase::setReadOnly( readOnly );
205 recurrence()->setRecurReadOnly( readOnly); 238 recurrence()->setRecurReadOnly( readOnly);
206} 239}
207 240
208void Incidence::setCreated(QDateTime created) 241void Incidence::setCreated(QDateTime created)
209{ 242{
210 if (mReadOnly) return; 243 if (mReadOnly) return;
211 mCreated = getEvenTime(created); 244 mCreated = getEvenTime(created);
212} 245}
213 246
214QDateTime Incidence::created() const 247QDateTime Incidence::created() const
215{ 248{
216 return mCreated; 249 return mCreated;
217} 250}
218 251
219void Incidence::setRevision(int rev) 252void Incidence::setRevision(int rev)
220{ 253{
221 if (mReadOnly) return; 254 if (mReadOnly) return;
222 mRevision = rev; 255 mRevision = rev;
223 256
224 updated(); 257 updated();
225} 258}
226 259
227int Incidence::revision() const 260int Incidence::revision() const
228{ 261{
229 return mRevision; 262 return mRevision;
230} 263}
231 264
232void Incidence::setDtStart(const QDateTime &dtStart) 265void Incidence::setDtStart(const QDateTime &dtStart)
233{ 266{
234 267
235 QDateTime dt = getEvenTime(dtStart); 268 QDateTime dt = getEvenTime(dtStart);
236 recurrence()->setRecurStart( dt); 269 recurrence()->setRecurStart( dt);
237 IncidenceBase::setDtStart( dt ); 270 IncidenceBase::setDtStart( dt );
238} 271}
239 272
240void Incidence::setDescription(const QString &description) 273void Incidence::setDescription(const QString &description)
241{ 274{
242 if (mReadOnly) return; 275 if (mReadOnly) return;
243 mDescription = description; 276 mDescription = description;
244 updated(); 277 updated();
245} 278}
246 279
247QString Incidence::description() const 280QString Incidence::description() const
248{ 281{
249 return mDescription; 282 return mDescription;
250} 283}
251 284
252 285
253void Incidence::setSummary(const QString &summary) 286void Incidence::setSummary(const QString &summary)
254{ 287{
255 if (mReadOnly) return; 288 if (mReadOnly) return;
256 mSummary = summary; 289 mSummary = summary;
257 updated(); 290 updated();
258} 291}
259 292
260QString Incidence::summary() const 293QString Incidence::summary() const
261{ 294{
262 return mSummary; 295 return mSummary;
263} 296}
264 297
265void Incidence::setCategories(const QStringList &categories) 298void Incidence::setCategories(const QStringList &categories)
266{ 299{
267 if (mReadOnly) return; 300 if (mReadOnly) return;
268 mCategories = categories; 301 mCategories = categories;
269 updated(); 302 updated();
270} 303}
271 304
272// TODO: remove setCategories(QString) function 305// TODO: remove setCategories(QString) function
273void Incidence::setCategories(const QString &catStr) 306void Incidence::setCategories(const QString &catStr)
274{ 307{
275 if (mReadOnly) return; 308 if (mReadOnly) return;
276 mCategories.clear(); 309 mCategories.clear();
277 310
278 if (catStr.isEmpty()) return; 311 if (catStr.isEmpty()) return;
279 312
280 mCategories = QStringList::split(",",catStr); 313 mCategories = QStringList::split(",",catStr);
281 314
282 QStringList::Iterator it; 315 QStringList::Iterator it;
283 for(it = mCategories.begin();it != mCategories.end(); ++it) { 316 for(it = mCategories.begin();it != mCategories.end(); ++it) {
284 *it = (*it).stripWhiteSpace(); 317 *it = (*it).stripWhiteSpace();
285 } 318 }
286 319
287 updated(); 320 updated();
288} 321}
289 322
290QStringList Incidence::categories() const 323QStringList Incidence::categories() const
291{ 324{
292 return mCategories; 325 return mCategories;
293} 326}
294 327
295QString Incidence::categoriesStr() 328QString Incidence::categoriesStr()
296{ 329{
297 return mCategories.join(","); 330 return mCategories.join(",");
298} 331}
299 332
300void Incidence::setRelatedToUid(const QString &relatedToUid) 333void Incidence::setRelatedToUid(const QString &relatedToUid)
301{ 334{
302 if (mReadOnly) return; 335 if (mReadOnly) return;
303 mRelatedToUid = relatedToUid; 336 mRelatedToUid = relatedToUid;
304} 337}
305 338
306QString Incidence::relatedToUid() const 339QString Incidence::relatedToUid() const
307{ 340{
308 return mRelatedToUid; 341 return mRelatedToUid;
309} 342}
310 343
311void Incidence::setRelatedTo(Incidence *relatedTo) 344void Incidence::setRelatedTo(Incidence *relatedTo)
312{ 345{
313 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 346 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
314 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 347 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
315 if (mReadOnly || mRelatedTo == relatedTo) return; 348 if (mReadOnly || mRelatedTo == relatedTo) return;
316 if(mRelatedTo) { 349 if(mRelatedTo) {
317 // updated(); 350 // updated();
318 mRelatedTo->removeRelation(this); 351 mRelatedTo->removeRelation(this);
319 } 352 }
320 mRelatedTo = relatedTo; 353 mRelatedTo = relatedTo;
321 if (mRelatedTo) mRelatedTo->addRelation(this); 354 if (mRelatedTo) mRelatedTo->addRelation(this);
322} 355}
323 356
324Incidence *Incidence::relatedTo() const 357Incidence *Incidence::relatedTo() const
325{ 358{
326 return mRelatedTo; 359 return mRelatedTo;
327} 360}
328 361
329QPtrList<Incidence> Incidence::relations() const 362QPtrList<Incidence> Incidence::relations() const
330{ 363{
331 return mRelations; 364 return mRelations;
332} 365}
333 366
334void Incidence::addRelation(Incidence *event) 367void Incidence::addRelation(Incidence *event)
335{ 368{
336 if( mRelations.findRef( event ) == -1 ) { 369 if( mRelations.findRef( event ) == -1 ) {
337 mRelations.append(event); 370 mRelations.append(event);
338 //updated(); 371 //updated();
339 } 372 }
340} 373}
341 374
342void Incidence::removeRelation(Incidence *event) 375void Incidence::removeRelation(Incidence *event)
343{ 376{
344 377
345 mRelations.removeRef(event); 378 mRelations.removeRef(event);
346 379
347// if (event->getRelatedTo() == this) event->setRelatedTo(0); 380// if (event->getRelatedTo() == this) event->setRelatedTo(0);
348} 381}
349 382
350bool Incidence::recursOn(const QDate &qd) const 383bool Incidence::recursOn(const QDate &qd) const
351{ 384{
352 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 385 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
353 else return false; 386 else return false;
354} 387}
355 388
356void Incidence::setExDates(const DateList &exDates) 389void Incidence::setExDates(const DateList &exDates)
357{ 390{
358 if (mReadOnly) return; 391 if (mReadOnly) return;
359 mExDates = exDates; 392 mExDates = exDates;
360 393
361 recurrence()->setRecurExDatesCount(mExDates.count()); 394 recurrence()->setRecurExDatesCount(mExDates.count());
362 395
363 updated(); 396 updated();
364} 397}
365 398
366void Incidence::addExDate(const QDate &date) 399void Incidence::addExDate(const QDate &date)
367{ 400{
368 if (mReadOnly) return; 401 if (mReadOnly) return;
369 mExDates.append(date); 402 mExDates.append(date);
370 403
371 recurrence()->setRecurExDatesCount(mExDates.count()); 404 recurrence()->setRecurExDatesCount(mExDates.count());
372 405
373 updated(); 406 updated();
374} 407}
375 408
376DateList Incidence::exDates() const 409DateList Incidence::exDates() const
377{ 410{
378 return mExDates; 411 return mExDates;
379} 412}
380 413
381bool Incidence::isException(const QDate &date) const 414bool Incidence::isException(const QDate &date) const
382{ 415{
383 DateList::ConstIterator it; 416 DateList::ConstIterator it;
384 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 417 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
385 if ( (*it) == date ) { 418 if ( (*it) == date ) {
386 return true; 419 return true;
387 } 420 }
388 } 421 }
389 422
390 return false; 423 return false;
391} 424}
392 425
393void Incidence::addAttachment(Attachment *attachment) 426void Incidence::addAttachment(Attachment *attachment)
394{ 427{
395 if (mReadOnly || !attachment) return; 428 if (mReadOnly || !attachment) return;
396 mAttachments.append(attachment); 429 mAttachments.append(attachment);
397 updated(); 430 updated();
398} 431}
399 432
400void Incidence::deleteAttachment(Attachment *attachment) 433void Incidence::deleteAttachment(Attachment *attachment)
401{ 434{
402 mAttachments.removeRef(attachment); 435 mAttachments.removeRef(attachment);
403} 436}
404 437
405void Incidence::deleteAttachments(const QString& mime) 438void Incidence::deleteAttachments(const QString& mime)
406{ 439{
407 Attachment *at = mAttachments.first(); 440 Attachment *at = mAttachments.first();
408 while (at) { 441 while (at) {
409 if (at->mimeType() == mime) 442 if (at->mimeType() == mime)
410 mAttachments.remove(); 443 mAttachments.remove();
411 else 444 else
412 at = mAttachments.next(); 445 at = mAttachments.next();
413 } 446 }
414} 447}
415 448
416QPtrList<Attachment> Incidence::attachments() const 449QPtrList<Attachment> Incidence::attachments() const
417{ 450{
418 return mAttachments; 451 return mAttachments;
419} 452}
420 453
421QPtrList<Attachment> Incidence::attachments(const QString& mime) const 454QPtrList<Attachment> Incidence::attachments(const QString& mime) const
422{ 455{
423 QPtrList<Attachment> attachments; 456 QPtrList<Attachment> attachments;
424 QPtrListIterator<Attachment> it( mAttachments ); 457 QPtrListIterator<Attachment> it( mAttachments );
425 Attachment *at; 458 Attachment *at;
426 while ( (at = it.current()) ) { 459 while ( (at = it.current()) ) {
427 if (at->mimeType() == mime) 460 if (at->mimeType() == mime)
428 attachments.append(at); 461 attachments.append(at);
429 ++it; 462 ++it;
430 } 463 }
431 464
432 return attachments; 465 return attachments;
433} 466}
434 467
435void Incidence::setResources(const QStringList &resources) 468void Incidence::setResources(const QStringList &resources)
436{ 469{
437 if (mReadOnly) return; 470 if (mReadOnly) return;
438 mResources = resources; 471 mResources = resources;
439 updated(); 472 updated();
440} 473}
441 474
442QStringList Incidence::resources() const 475QStringList Incidence::resources() const
443{ 476{
444 return mResources; 477 return mResources;
445} 478}
446 479
447 480
448void Incidence::setPriority(int priority) 481void Incidence::setPriority(int priority)
449{ 482{
450 if (mReadOnly) return; 483 if (mReadOnly) return;
451 mPriority = priority; 484 mPriority = priority;
452 updated(); 485 updated();
453} 486}
454 487
455int Incidence::priority() const 488int Incidence::priority() const
456{ 489{
457 return mPriority; 490 return mPriority;
458} 491}
459 492
460void Incidence::setSecrecy(int sec) 493void Incidence::setSecrecy(int sec)
461{ 494{
462 if (mReadOnly) return; 495 if (mReadOnly) return;
463 mSecrecy = sec; 496 mSecrecy = sec;
464 updated(); 497 updated();
465} 498}
466 499
467int Incidence::secrecy() const 500int Incidence::secrecy() const
468{ 501{
469 return mSecrecy; 502 return mSecrecy;
470} 503}
471 504
472QString Incidence::secrecyStr() const 505QString Incidence::secrecyStr() const
473{ 506{
474 return secrecyName(mSecrecy); 507 return secrecyName(mSecrecy);
475} 508}
476 509
477QString Incidence::secrecyName(int secrecy) 510QString Incidence::secrecyName(int secrecy)
478{ 511{
479 switch (secrecy) { 512 switch (secrecy) {
480 case SecrecyPublic: 513 case SecrecyPublic:
481 return i18n("Public"); 514 return i18n("Public");
482 break; 515 break;
483 case SecrecyPrivate: 516 case SecrecyPrivate:
484 return i18n("Private"); 517 return i18n("Private");
485 break; 518 break;
486 case SecrecyConfidential: 519 case SecrecyConfidential:
487 return i18n("Confidential"); 520 return i18n("Confidential");
488 break; 521 break;
489 default: 522 default:
490 return i18n("Undefined"); 523 return i18n("Undefined");
491 break; 524 break;
492 } 525 }
493} 526}
494 527
495QStringList Incidence::secrecyList() 528QStringList Incidence::secrecyList()
496{ 529{
497 QStringList list; 530 QStringList list;
498 list << secrecyName(SecrecyPublic); 531 list << secrecyName(SecrecyPublic);
499 list << secrecyName(SecrecyPrivate); 532 list << secrecyName(SecrecyPrivate);
500 list << secrecyName(SecrecyConfidential); 533 list << secrecyName(SecrecyConfidential);
501 534
502 return list; 535 return list;
503} 536}
504 537
505 538
506QPtrList<Alarm> Incidence::alarms() const 539QPtrList<Alarm> Incidence::alarms() const
507{ 540{
508 return mAlarms; 541 return mAlarms;
509} 542}
510 543
511Alarm* Incidence::newAlarm() 544Alarm* Incidence::newAlarm()
512{ 545{
513 Alarm* alarm = new Alarm(this); 546 Alarm* alarm = new Alarm(this);
514 mAlarms.append(alarm); 547 mAlarms.append(alarm);
515// updated(); 548// updated();
516 return alarm; 549 return alarm;
517} 550}
518 551
519void Incidence::addAlarm(Alarm *alarm) 552void Incidence::addAlarm(Alarm *alarm)
520{ 553{
521 mAlarms.append(alarm); 554 mAlarms.append(alarm);
522 updated(); 555 updated();
523} 556}
524 557
525void Incidence::removeAlarm(Alarm *alarm) 558void Incidence::removeAlarm(Alarm *alarm)
526{ 559{
527 mAlarms.removeRef(alarm); 560 mAlarms.removeRef(alarm);
528 updated(); 561 updated();
529} 562}
530 563
531void Incidence::clearAlarms() 564void Incidence::clearAlarms()
532{ 565{
533 mAlarms.clear(); 566 mAlarms.clear();
534 updated(); 567 updated();
535} 568}
536 569
537bool Incidence::isAlarmEnabled() const 570bool Incidence::isAlarmEnabled() const
538{ 571{
539 Alarm* alarm; 572 Alarm* alarm;
540 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 573 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
541 if (alarm->enabled()) 574 if (alarm->enabled())
542 return true; 575 return true;
543 } 576 }
544 return false; 577 return false;
545} 578}
546 579
547Recurrence *Incidence::recurrence() const 580Recurrence *Incidence::recurrence() const
548{ 581{
549 return mRecurrence; 582 return mRecurrence;
550} 583}
551void Incidence::setRecurrence( Recurrence * r) 584void Incidence::setRecurrence( Recurrence * r)
552{ 585{
553 delete mRecurrence; 586 delete mRecurrence;
554 mRecurrence = r; 587 mRecurrence = r;
555} 588}
556 589
557void Incidence::setLocation(const QString &location) 590void Incidence::setLocation(const QString &location)
558{ 591{
559 if (mReadOnly) return; 592 if (mReadOnly) return;
560 mLocation = location; 593 mLocation = location;
561 updated(); 594 updated();
562} 595}
563 596
564QString Incidence::location() const 597QString Incidence::location() const
565{ 598{
566 return mLocation; 599 return mLocation;
567} 600}
568 601
569ushort Incidence::doesRecur() const 602ushort Incidence::doesRecur() const
570{ 603{
571 if ( mRecurrence ) return mRecurrence->doesRecur(); 604 if ( mRecurrence ) return mRecurrence->doesRecur();
572 else return Recurrence::rNone; 605 else return Recurrence::rNone;
573} 606}
574 607
575QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 608QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
576{ 609{
577 QDateTime incidenceStart = dt; 610 QDateTime incidenceStart = dt;
578 *ok = false; 611 *ok = false;
579 if ( doesRecur() ) { 612 if ( doesRecur() ) {
580 bool last; 613 bool last;
581 recurrence()->getPreviousDateTime( incidenceStart , &last ); 614 recurrence()->getPreviousDateTime( incidenceStart , &last );
582 int count = 0; 615 int count = 0;
583 if ( !last ) { 616 if ( !last ) {
584 while ( !last ) { 617 while ( !last ) {
585 ++count; 618 ++count;
586 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); 619 incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last );
587 if ( recursOn( incidenceStart.date() ) ) { 620 if ( recursOn( incidenceStart.date() ) ) {
588 last = true; // exit while llop 621 last = true; // exit while llop
589 } else { 622 } else {
590 if ( last ) { // no alarm on last recurrence 623 if ( last ) { // no alarm on last recurrence
591 return QDateTime (); 624 return QDateTime ();
592 } 625 }
593 int year = incidenceStart.date().year(); 626 int year = incidenceStart.date().year();
594 // workaround for bug in recurrence 627 // workaround for bug in recurrence
595 if ( count == 100 || year < 1000 || year > 5000 ) { 628 if ( count == 100 || year < 1000 || year > 5000 ) {
596 return QDateTime (); 629 return QDateTime ();
597 } 630 }
598 incidenceStart = incidenceStart.addSecs( 1 ); 631 incidenceStart = incidenceStart.addSecs( 1 );
599 } 632 }
600 } 633 }
601 } else { 634 } else {
602 return QDateTime (); 635 return QDateTime ();
603 } 636 }
604 } else { 637 } else {
605 if ( hasStartDate () ) { 638 if ( hasStartDate () ) {
606 incidenceStart = dtStart(); 639 incidenceStart = dtStart();
607 } 640 }
608 if ( type() =="Todo" ) { 641 if ( type() =="Todo" ) {
609 if ( ((Todo*)this)->hasDueDate() ) 642 if ( ((Todo*)this)->hasDueDate() )
610 incidenceStart = ((Todo*)this)->dtDue(); 643 incidenceStart = ((Todo*)this)->dtDue();
611 } 644 }
612 } 645 }
613 if ( incidenceStart > dt ) 646 if ( incidenceStart > dt )
614 *ok = true; 647 *ok = true;
615 return incidenceStart; 648 return incidenceStart;
616} 649}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index de2a381..38d2aaa 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -1,299 +1,308 @@
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 115
116 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; 116 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0;
117 void setReadOnly( bool ); 117 void setReadOnly( bool );
118 118
119 /** 119 /**
120 Recreate event. The event is made a new unique event, but already stored 120 Recreate event. The event is made a new unique event, but already stored
121 event information is preserved. Sets uniquie id, creation date, last 121 event information is preserved. Sets uniquie id, creation date, last
122 modification date and revision number. 122 modification date and revision number.
123 */ 123 */
124 void recreate(); 124 void recreate();
125 Incidence* recreateCloneException(QDate); 125 Incidence* recreateCloneException(QDate);
126 126
127 /** set creation date */ 127 /** set creation date */
128 void setCreated(QDateTime); 128 void setCreated(QDateTime);
129 /** return time and date of creation. */ 129 /** return time and date of creation. */
130 QDateTime created() const; 130 QDateTime created() const;
131 131
132 /** set the number of revisions this event has seen */ 132 /** set the number of revisions this event has seen */
133 void setRevision(int rev); 133 void setRevision(int rev);
134 /** return the number of revisions this event has seen */ 134 /** return the number of revisions this event has seen */
135 int revision() const; 135 int revision() const;
136 136
137 /** Set starting date/time. */ 137 /** Set starting date/time. */
138 virtual void setDtStart(const QDateTime &dtStart); 138 virtual void setDtStart(const QDateTime &dtStart);
139 /** Return the incidence's ending date/time as a QDateTime. */ 139 /** Return the incidence's ending date/time as a QDateTime. */
140 virtual QDateTime dtEnd() const { return QDateTime(); } 140 virtual QDateTime dtEnd() const { return QDateTime(); }
141 141
142 /** sets the event's lengthy description. */ 142 /** sets the event's lengthy description. */
143 void setDescription(const QString &description); 143 void setDescription(const QString &description);
144 /** returns a reference to the event's description. */ 144 /** returns a reference to the event's description. */
145 QString description() const; 145 QString description() const;
146 146
147 /** sets the event's short summary. */ 147 /** sets the event's short summary. */
148 void setSummary(const QString &summary); 148 void setSummary(const QString &summary);
149 /** returns a reference to the event's summary. */ 149 /** returns a reference to the event's summary. */
150 QString summary() const; 150 QString summary() const;
151 151
152 /** set event's applicable categories */ 152 /** set event's applicable categories */
153 void setCategories(const QStringList &categories); 153 void setCategories(const QStringList &categories);
154 /** set event's categories based on a comma delimited string */ 154 /** set event's categories based on a comma delimited string */
155 void setCategories(const QString &catStr); 155 void setCategories(const QString &catStr);
156 /** return categories in a list */ 156 /** return categories in a list */
157 QStringList categories() const; 157 QStringList categories() const;
158 /** return categories as a comma separated string */ 158 /** return categories as a comma separated string */
159 QString categoriesStr(); 159 QString categoriesStr();
160 160
161 /** point at some other event to which the event relates. This function should 161 /** point at some other event to which the event relates. This function should
162 * only be used when constructing a calendar before the related Event 162 * only be used when constructing a calendar before the related Event
163 * exists. */ 163 * exists. */
164 void setRelatedToUid(const QString &); 164 void setRelatedToUid(const QString &);
165 /** what event does this one relate to? This function should 165 /** what event does this one relate to? This function should
166 * only be used when constructing a calendar before the related Event 166 * only be used when constructing a calendar before the related Event
167 * exists. */ 167 * exists. */
168 QString relatedToUid() const; 168 QString relatedToUid() const;
169 /** point at some other event to which the event relates */ 169 /** point at some other event to which the event relates */
170 void setRelatedTo(Incidence *relatedTo); 170 void setRelatedTo(Incidence *relatedTo);
171 /** what event does this one relate to? */ 171 /** what event does this one relate to? */
172 Incidence *relatedTo() const; 172 Incidence *relatedTo() const;
173 /** All events that are related to this event */ 173 /** All events that are related to this event */
174 QPtrList<Incidence> relations() const; 174 QPtrList<Incidence> relations() const;
175 /** Add an event which is related to this event */ 175 /** Add an event which is related to this event */
176 void addRelation(Incidence *); 176 void addRelation(Incidence *);
177 /** Remove event that is related to this event */ 177 /** Remove event that is related to this event */
178 void removeRelation(Incidence *); 178 void removeRelation(Incidence *);
179 179
180 /** returns the list of dates which are exceptions to the recurrence rule */ 180 /** returns the list of dates which are exceptions to the recurrence rule */
181 DateList exDates() const; 181 DateList exDates() const;
182 /** sets the list of dates which are exceptions to the recurrence rule */ 182 /** sets the list of dates which are exceptions to the recurrence rule */
183 void setExDates(const DateList &_exDates); 183 void setExDates(const DateList &_exDates);
184 void setExDates(const char *dates); 184 void setExDates(const char *dates);
185 /** Add a date to the list of exceptions of the recurrence rule. */ 185 /** Add a date to the list of exceptions of the recurrence rule. */
186 void addExDate(const QDate &date); 186 void addExDate(const QDate &date);
187 187
188 /** returns true if there is an exception for this date in the recurrence 188 /** returns true if there is an exception for this date in the recurrence
189 rule set, or false otherwise. */ 189 rule set, or false otherwise. */
190 bool isException(const QDate &qd) const; 190 bool isException(const QDate &qd) const;
191 191
192 /** add attachment to this event */ 192 /** add attachment to this event */
193 void addAttachment(Attachment *attachment); 193 void addAttachment(Attachment *attachment);
194 /** remove and delete a specific attachment */ 194 /** remove and delete a specific attachment */
195 void deleteAttachment(Attachment *attachment); 195 void deleteAttachment(Attachment *attachment);
196 /** remove and delete all attachments with this mime type */ 196 /** remove and delete all attachments with this mime type */
197 void deleteAttachments(const QString& mime); 197 void deleteAttachments(const QString& mime);
198 /** return list of all associated attachments */ 198 /** return list of all associated attachments */
199 QPtrList<Attachment> attachments() const; 199 QPtrList<Attachment> attachments() const;
200 /** find a list of attachments with this mime type */ 200 /** find a list of attachments with this mime type */
201 QPtrList<Attachment> attachments(const QString& mime) const; 201 QPtrList<Attachment> attachments(const QString& mime) const;
202 202
203 /** sets the event's status the value specified. See the enumeration 203 /** sets the event's status the value specified. See the enumeration
204 * above for possible values. */ 204 * above for possible values. */
205 void setSecrecy(int); 205 void setSecrecy(int);
206 /** return the event's secrecy. */ 206 /** return the event's secrecy. */
207 int secrecy() const; 207 int secrecy() const;
208 /** return the event's secrecy in string format. */ 208 /** return the event's secrecy in string format. */
209 QString secrecyStr() const; 209 QString secrecyStr() const;
210 /** return list of all availbale secrecy classes */ 210 /** return list of all availbale secrecy classes */
211 static QStringList secrecyList(); 211 static QStringList secrecyList();
212 /** return human-readable name of secrecy class */ 212 /** return human-readable name of secrecy class */
213 static QString secrecyName(int); 213 static QString secrecyName(int);
214 214
215 /** returns TRUE if the date specified is one on which the event will 215 /** returns TRUE if the date specified is one on which the event will
216 * recur. */ 216 * recur. */
217 bool recursOn(const QDate &qd) const; 217 bool recursOn(const QDate &qd) const;
218 218
219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 219 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
220 220
221 /** set resources used, such as Office, Car, etc. */ 221 /** set resources used, such as Office, Car, etc. */
222 void setResources(const QStringList &resources); 222 void setResources(const QStringList &resources);
223 /** return list of current resources */ 223 /** return list of current resources */
224 QStringList resources() const; 224 QStringList resources() const;
225 225
226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 226 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
227 void setPriority(int priority); 227 void setPriority(int priority);
228 /** get the event's priority */ 228 /** get the event's priority */
229 int priority() const; 229 int priority() const;
230 230
231 /** All alarms that are associated with this incidence */ 231 /** All alarms that are associated with this incidence */
232 QPtrList<Alarm> alarms() const; 232 QPtrList<Alarm> alarms() const;
233 /** Create a new alarm which is associated with this incidence */ 233 /** Create a new alarm which is associated with this incidence */
234 Alarm* newAlarm(); 234 Alarm* newAlarm();
235 /** Add an alarm which is associated with this incidence */ 235 /** Add an alarm which is associated with this incidence */
236 void addAlarm(Alarm*); 236 void addAlarm(Alarm*);
237 /** Remove an alarm that is associated with this incidence */ 237 /** Remove an alarm that is associated with this incidence */
238 void removeAlarm(Alarm*); 238 void removeAlarm(Alarm*);
239 /** Remove all alarms that are associated with this incidence */ 239 /** Remove all alarms that are associated with this incidence */
240 void clearAlarms(); 240 void clearAlarms();
241 /** return whether any alarm associated with this incidence is enabled */ 241 /** return whether any alarm associated with this incidence is enabled */
242 bool isAlarmEnabled() const; 242 bool isAlarmEnabled() const;
243 243
244 /** 244 /**
245 Return the recurrence rule associated with this incidence. If there is 245 Return the recurrence rule associated with this incidence. If there is
246 none, returns an appropriate (non-0) object. 246 none, returns an appropriate (non-0) object.
247 */ 247 */
248 Recurrence *recurrence() const; 248 Recurrence *recurrence() const;
249 void setRecurrence(Recurrence * r); 249 void setRecurrence(Recurrence * r);
250 /** 250 /**
251 Forward to Recurrence::doesRecur(). 251 Forward to Recurrence::doesRecur().
252 */ 252 */
253 ushort doesRecur() const; 253 ushort doesRecur() const;
254 254
255 /** set the event's/todo's location. Do _not_ use it with journal */ 255 /** set the event's/todo's location. Do _not_ use it with journal */
256 void setLocation(const QString &location); 256 void setLocation(const QString &location);
257 /** return the event's/todo's location. Do _not_ use it with journal */ 257 /** return the event's/todo's location. Do _not_ use it with journal */
258 QString location() const; 258 QString location() const;
259 /** returns TRUE or FALSE depending on whether the todo has a start date */ 259 /** returns TRUE or FALSE depending on whether the todo has a start date */
260 bool hasStartDate() const; 260 bool hasStartDate() const;
261 /** sets the event's hasStartDate value. */ 261 /** sets the event's hasStartDate value. */
262 void setHasStartDate(bool f); 262 void setHasStartDate(bool f);
263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 263 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
264 bool cancelled() const; 264 bool cancelled() const;
265 void setCancelled( bool b ); 265 void setCancelled( bool b );
266
267 bool hasRecurrenceID() const;
268 void setHasRecurrenceID( bool b );
269
270 void setRecurrenceID(QDateTime);
271 QDateTime recurrenceID () const;
272
266 273
267protected: 274protected:
268 QPtrList<Alarm> mAlarms; 275 QPtrList<Alarm> mAlarms;
269 QPtrList<Incidence> mRelations; 276 QPtrList<Incidence> mRelations;
270 private: 277 private:
271 int mRevision; 278 int mRevision;
272 bool mCancelled; 279 bool mCancelled;
273 280
274 // base components of jounal, event and todo 281 // base components of jounal, event and todo
282 QDateTime mRecurrenceID;
283 bool mHasRecurrenceID;
275 QDateTime mCreated; 284 QDateTime mCreated;
276 QString mDescription; 285 QString mDescription;
277 QString mSummary; 286 QString mSummary;
278 QStringList mCategories; 287 QStringList mCategories;
279 Incidence *mRelatedTo; 288 Incidence *mRelatedTo;
280 QString mRelatedToUid; 289 QString mRelatedToUid;
281 DateList mExDates; 290 DateList mExDates;
282 QPtrList<Attachment> mAttachments; 291 QPtrList<Attachment> mAttachments;
283 QStringList mResources; 292 QStringList mResources;
284 bool mHasStartDate; // if todo has associated start date 293 bool mHasStartDate; // if todo has associated start date
285 294
286 int mSecrecy; 295 int mSecrecy;
287 int mPriority; // 1 = highest, 2 = less, etc. 296 int mPriority; // 1 = highest, 2 = less, etc.
288 297
289 //QPtrList<Alarm> mAlarms; 298 //QPtrList<Alarm> mAlarms;
290 Recurrence *mRecurrence; 299 Recurrence *mRecurrence;
291 300
292 QString mLocation; 301 QString mLocation;
293}; 302};
294 303
295bool operator==( const Incidence&, const Incidence& ); 304bool operator==( const Incidence&, const Incidence& );
296 305
297} 306}
298 307
299#endif 308#endif
diff --git a/microkde/kdialogbase.h b/microkde/kdialogbase.h
index 7b44bfb..a2fc2dc 100644
--- a/microkde/kdialogbase.h
+++ b/microkde/kdialogbase.h
@@ -1,141 +1,141 @@
1#ifndef MINIKDE_KDIALOGBASE_H 1#ifndef MINIKDE_KDIALOGBASE_H
2#define MINIKDE_KDIALOGBASE_H 2#define MINIKDE_KDIALOGBASE_H
3 3
4#include <qframe.h> 4#include <qframe.h>
5 5
6#include "kdialog.h" 6#include "kdialog.h"
7 7
8class QPushButton; 8class QPushButton;
9class QLayout; 9class QLayout;
10class QTabWidget; 10class QTabWidget;
11class QBoxLayout; 11class QBoxLayout;
12 12
13class KDialogBase : public KDialog 13class KDialogBase : public KDialog
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 public: 16 public:
17 enum ButtonCode 17 enum ButtonCode
18 { 18 {
19 Help = 0x00000001, 19 Help = 0x00000001,
20 Default = 0x00000002, 20 Default = 0x00000002,
21 Ok = 0x00000004, 21 Ok = 0x00000004,
22 Apply = 0x00000008, 22 Apply = 0x00000008,
23 Try = 0x00000010, 23 Try = 0x00000010,
24 Cancel = 0x00000020, 24 Cancel = 0x00000020,
25 Close = 0x00000040, 25 Close = 0x00000040,
26 User1 = 0x00000080, 26 User1 = 0x00000080,
27 User2 = 0x00000100, 27 User2 = 0x00000100,
28 User3 = 0x00000200, 28 User3 = 0x00000200,
29 No = 0x00000080, 29 No = 0x00000080,
30 Yes = 0x00000100, 30 Yes = 0x00000100,
31 Details = 0x00000400, 31 Details = 0x00000400,
32 Filler = 0x40000000, 32 Filler = 0x40000000,
33 Stretch = 0x80000000 33 Stretch = 0x80000000
34 }; 34 };
35 35
36 enum DialogType 36 enum DialogType
37 { 37 {
38 TreeList, 38 TreeList,
39 Tabbed, 39 Tabbed,
40 Plain, 40 Plain,
41 Swallow, 41 Swallow,
42 IconList 42 IconList
43 }; 43 };
44 44
45 KDialogBase(); 45 KDialogBase();
46 KDialogBase( QWidget *parent=0, const char *name=0, bool modal=true, 46 KDialogBase( QWidget *parent=0, const char *name=0, bool modal=true,
47 const QString &caption=QString::null, 47 const QString &caption=QString::null,
48 int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, 48 int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok,
49 bool separator=false, 49 bool separator=false,
50 const QString &user1=QString::null, 50 const QString &user1=QString::null,
51 const QString &user2=QString::null, 51 const QString &user2=QString::null,
52 const QString &user3=QString::null); 52 const QString &user3=QString::null);
53 KDialogBase( int dialogFace, const QString &caption, 53 KDialogBase( int dialogFace, const QString &caption,
54 int buttonMask, ButtonCode defaultButton, 54 int buttonMask, ButtonCode defaultButton,
55 QWidget *parent=0, const char *name=0, bool modal=true, 55 QWidget *parent=0, const char *name=0, bool modal=true,
56 bool separator=false, 56 bool separator=false,
57 const QString &user1=QString::null, 57 const QString &user1=QString::null,
58 const QString &user2=QString::null, 58 const QString &user2=QString::null,
59 const QString &user3=QString::null); 59 const QString &user3=QString::null);
60 virtual ~KDialogBase(); 60 virtual ~KDialogBase();
61 61
62 QFrame *addPage( const QString & ); 62 QFrame *addPage( const QString & );
63 QFrame *addPage( const QString &, int, const QPixmap & ); 63 QFrame *addPage( const QString &, int, const QPixmap & );
64 64
65 void setMainWidget( QWidget *widget ); 65 void setMainWidget( QWidget *widget );
66 66
67 void setButtonText( ButtonCode id, const QString &text ); 67 void setButtonText( ButtonCode id, const QString &text );
68 68
69 void enableButton( ButtonCode id, bool state ); 69 void enableButton( ButtonCode id, bool state );
70 void enableButtonOK( bool state ); 70 void enableButtonOK( bool state );
71 void enableButtonApply( bool state ); 71 void enableButtonApply( bool state );
72 72
73 void showButton( ButtonCode, bool show ); 73 void showButton( ButtonCode, bool show );
74 74
75 int pageIndex( QWidget *widget ) const; 75 int pageIndex( QWidget *widget ) const;
76 76
77 bool showPage( int index ); 77 bool showPage( int index );
78 void hideButtons(); 78 void hideButtons();
79 79
80 QFrame *plainPage(); 80 QFrame *plainPage();
81 81
82 signals: 82 signals:
83 void user1Clicked(); 83 void user1Clicked();
84 void user2Clicked(); 84 void user2Clicked();
85 /** 85 /**
86 * The Apply button was pressed. This signal is only emitted if 86 * The Apply button was pressed. This signal is only emitted if
87 * @ref slotApply() is not replaced. 87 * @ref slotApply() is not replaced.
88 */ 88 */
89 void applyClicked(); 89 void applyClicked();
90 90
91 /** 91 /**
92 * The OK button was pressed. This signal is only emitted if 92 * The OK button was pressed. This signal is only emitted if
93 * @ref slotOk() is not replaced. 93 * @ref slotOk() is not replaced.
94 */ 94 */
95 void okClicked(); 95 void okClicked();
96 96
97 /** 97 /**
98 * The Cancel button was pressed. This signal is only emitted if 98 * The Cancel button was pressed. This signal is only emitted if
99 * @ref slotCancel() is not replaced. 99 * @ref slotCancel() is not replaced.
100 */ 100 */
101 void cancelClicked(); 101 void cancelClicked();
102 102
103 /** 103 /**
104 * The Close button was pressed. This signal is only emitted if 104 * The Close button was pressed. This signal is only emitted if
105 * @ref slotClose() is not replaced. 105 * @ref slotClose() is not replaced.
106 */ 106 */
107 void closeClicked(); 107 void closeClicked();
108 void defaultClicked(); 108 void defaultClicked();
109 109
110 protected slots: 110 protected slots:
111 virtual void slotOk(); 111 virtual void slotOk();
112 virtual void slotApply(); 112 virtual void slotApply();
113 virtual void slotCancel(); 113 virtual void slotCancel();
114 virtual void slotClose(); 114 virtual void slotClose();
115 virtual void slotUser1(); 115 virtual void slotUser1();
116 virtual void slotUser2(); 116 virtual void slotUser2();
117 117
118 protected: 118 protected:
119 QPushButton *findButton( ButtonCode ); 119 QPushButton *findButton( ButtonCode );
120 QTabWidget *tabWidget();
120 121
121 private: 122 private:
122 QTabWidget *tabWidget();
123 void init( const QString &caption, int buttonMask, 123 void init( const QString &caption, int buttonMask,
124 const QString &user1=QString::null, const QString &user2=QString::null ); 124 const QString &user1=QString::null, const QString &user2=QString::null );
125 void initLayout(); 125 void initLayout();
126 126
127 QWidget *mMainWidget; 127 QWidget *mMainWidget;
128 QTabWidget *mTabWidget; 128 QTabWidget *mTabWidget;
129 QFrame *mPlainPage; 129 QFrame *mPlainPage;
130 QBoxLayout *mTopLayout; 130 QBoxLayout *mTopLayout;
131 131
132 QPushButton *mUser1Button; 132 QPushButton *mUser1Button;
133 QPushButton *mUser2Button; 133 QPushButton *mUser2Button;
134 QPushButton *mCloseButton; 134 QPushButton *mCloseButton;
135 QPushButton *mOkButton; 135 QPushButton *mOkButton;
136 QPushButton *mApplyButton; 136 QPushButton *mApplyButton;
137 QPushButton *mCancelButton; 137 QPushButton *mCancelButton;
138 QPushButton *mDefaultButton; 138 QPushButton *mDefaultButton;
139}; 139};
140 140
141#endif 141#endif