summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-05 13:34:33 (UTC)
committer zautrix <zautrix>2004-10-05 13:34:33 (UTC)
commit191ced43b27c047b0a39f0acdc8ba1f8a58817df (patch) (unidiff)
treed164ae32c16259d9a8d5c9fdfa74f975d1f10075
parenta946c09db6f71f595d8bdcb6b34ba3160c5497dc (diff)
downloadkdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.zip
kdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.tar.gz
kdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.tar.bz2
fix for filewatch and vcal timezone
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp3
-rw-r--r--libkcal/vcalformat.cpp2
2 files changed, 3 insertions, 2 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 687943e..b1da144 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3617 +1,3618 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#endif 86#endif
87#include <libkcal/phoneformat.h> 87#include <libkcal/phoneformat.h>
88#ifndef KORG_NOMAIL 88#ifndef KORG_NOMAIL
89#include "komailclient.h" 89#include "komailclient.h"
90#endif 90#endif
91#ifndef KORG_NOPRINTER 91#ifndef KORG_NOPRINTER
92#include "calprinter.h" 92#include "calprinter.h"
93#endif 93#endif
94#ifndef KORG_NOPLUGINS 94#ifndef KORG_NOPLUGINS
95#include "kocore.h" 95#include "kocore.h"
96#endif 96#endif
97#include "koeventeditor.h" 97#include "koeventeditor.h"
98#include "kotodoeditor.h" 98#include "kotodoeditor.h"
99#include "koprefs.h" 99#include "koprefs.h"
100#include "koeventviewerdialog.h" 100#include "koeventviewerdialog.h"
101#include "publishdialog.h" 101#include "publishdialog.h"
102#include "kofilterview.h" 102#include "kofilterview.h"
103#include "koglobals.h" 103#include "koglobals.h"
104#include "koviewmanager.h" 104#include "koviewmanager.h"
105#include "koagendaview.h" 105#include "koagendaview.h"
106#include "kodialogmanager.h" 106#include "kodialogmanager.h"
107#include "outgoingdialog.h" 107#include "outgoingdialog.h"
108#include "incomingdialog.h" 108#include "incomingdialog.h"
109#include "statusdialog.h" 109#include "statusdialog.h"
110#include "kdatenavigator.h" 110#include "kdatenavigator.h"
111#include "kotodoview.h" 111#include "kotodoview.h"
112#include "datenavigator.h" 112#include "datenavigator.h"
113#include "resourceview.h" 113#include "resourceview.h"
114#include "navigatorbar.h" 114#include "navigatorbar.h"
115#include "searchdialog.h" 115#include "searchdialog.h"
116#include "mainwindow.h" 116#include "mainwindow.h"
117 117
118#include "calendarview.h" 118#include "calendarview.h"
119#ifndef DESKTOP_VERSION 119#ifndef DESKTOP_VERSION
120#include <qtopia/alarmserver.h> 120#include <qtopia/alarmserver.h>
121#endif 121#endif
122#ifndef _WIN32_ 122#ifndef _WIN32_
123#include <stdlib.h> 123#include <stdlib.h>
124#include <stdio.h> 124#include <stdio.h>
125#include <unistd.h> 125#include <unistd.h>
126#else 126#else
127#include <qprocess.h> 127#include <qprocess.h>
128#endif 128#endif
129using namespace KOrg; 129using namespace KOrg;
130using namespace KCal; 130using namespace KCal;
131extern int globalFlagBlockAgenda; 131extern int globalFlagBlockAgenda;
132extern int globalFlagBlockStartup; 132extern int globalFlagBlockStartup;
133 133
134 134
135 135
136class KOBeamPrefs : public QDialog 136class KOBeamPrefs : public QDialog
137{ 137{
138 public: 138 public:
139 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 139 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
140 QDialog( parent, name, true ) 140 QDialog( parent, name, true )
141 { 141 {
142 setCaption( i18n("Beam Options") ); 142 setCaption( i18n("Beam Options") );
143 QVBoxLayout* lay = new QVBoxLayout( this ); 143 QVBoxLayout* lay = new QVBoxLayout( this );
144 lay->setSpacing( 3 ); 144 lay->setSpacing( 3 );
145 lay->setMargin( 3 ); 145 lay->setMargin( 3 );
146 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 146 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
147 lay->addWidget( format ); 147 lay->addWidget( format );
148 format->setExclusive ( true ) ; 148 format->setExclusive ( true ) ;
149 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 149 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
150 lay->addWidget( time ); time->setExclusive ( true ) ; 150 lay->addWidget( time ); time->setExclusive ( true ) ;
151 vcal = new QRadioButton(" vCalendar ", format ); 151 vcal = new QRadioButton(" vCalendar ", format );
152 ical = new QRadioButton(" iCalendar ", format ); 152 ical = new QRadioButton(" iCalendar ", format );
153 vcal->setChecked( true ); 153 vcal->setChecked( true );
154 tz = new QRadioButton(i18n(" With timezone "), time ); 154 tz = new QRadioButton(i18n(" With timezone "), time );
155 local = new QRadioButton(i18n(" Local time "), time ); 155 local = new QRadioButton(i18n(" Local time "), time );
156 tz->setChecked( true ); 156 tz->setChecked( true );
157 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 157 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
158 lay->addWidget( ok ); 158 lay->addWidget( ok );
159 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 159 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
160 lay->addWidget( cancel ); 160 lay->addWidget( cancel );
161 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 161 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
162 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 162 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
163 resize( 200, 200 ); 163 resize( 200, 200 );
164 } 164 }
165 165
166 bool beamVcal() { return vcal->isChecked(); } 166 bool beamVcal() { return vcal->isChecked(); }
167 bool beamLocal() { return local->isChecked(); } 167 bool beamLocal() { return local->isChecked(); }
168private: 168private:
169 QRadioButton* vcal, *ical, *local, *tz; 169 QRadioButton* vcal, *ical, *local, *tz;
170}; 170};
171class KOCatPrefs : public QDialog 171class KOCatPrefs : public QDialog
172{ 172{
173 public: 173 public:
174 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 174 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
175 QDialog( parent, name, true ) 175 QDialog( parent, name, true )
176 { 176 {
177 setCaption( i18n("Manage new Categories") ); 177 setCaption( i18n("Manage new Categories") );
178 QVBoxLayout* lay = new QVBoxLayout( this ); 178 QVBoxLayout* lay = new QVBoxLayout( this );
179 lay->setSpacing( 3 ); 179 lay->setSpacing( 3 );
180 lay->setMargin( 3 ); 180 lay->setMargin( 3 );
181 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 181 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
182 lay->addWidget( lab ); 182 lay->addWidget( lab );
183 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 183 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
184 lay->addWidget( format ); 184 lay->addWidget( format );
185 format->setExclusive ( true ) ; 185 format->setExclusive ( true ) ;
186 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 186 addCatBut = new QRadioButton(i18n("Add to category list"), format );
187 new QRadioButton(i18n("Remove from Events/Todos"), format ); 187 new QRadioButton(i18n("Remove from Events/Todos"), format );
188 addCatBut->setChecked( true ); 188 addCatBut->setChecked( true );
189 QPushButton * ok = new QPushButton( i18n("OK"), this ); 189 QPushButton * ok = new QPushButton( i18n("OK"), this );
190 lay->addWidget( ok ); 190 lay->addWidget( ok );
191 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 191 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
192 lay->addWidget( cancel ); 192 lay->addWidget( cancel );
193 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 193 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
194 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 194 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
195 resize( 200, 200 ); 195 resize( 200, 200 );
196 } 196 }
197 197
198 bool addCat() { return addCatBut->isChecked(); } 198 bool addCat() { return addCatBut->isChecked(); }
199private: 199private:
200 QRadioButton* addCatBut; 200 QRadioButton* addCatBut;
201}; 201};
202 202
203 203
204 204
205CalendarView::CalendarView( CalendarResources *calendar, 205CalendarView::CalendarView( CalendarResources *calendar,
206 QWidget *parent, const char *name ) 206 QWidget *parent, const char *name )
207 : CalendarViewBase( parent, name ), 207 : CalendarViewBase( parent, name ),
208 mCalendar( calendar ), 208 mCalendar( calendar ),
209 mResourceManager( calendar->resourceManager() ) 209 mResourceManager( calendar->resourceManager() )
210{ 210{
211 211
212 mEventEditor = 0; 212 mEventEditor = 0;
213 mTodoEditor = 0; 213 mTodoEditor = 0;
214 214
215 init(); 215 init();
216} 216}
217 217
218CalendarView::CalendarView( Calendar *calendar, 218CalendarView::CalendarView( Calendar *calendar,
219 QWidget *parent, const char *name ) 219 QWidget *parent, const char *name )
220 : CalendarViewBase( parent, name ), 220 : CalendarViewBase( parent, name ),
221 mCalendar( calendar ), 221 mCalendar( calendar ),
222 mResourceManager( 0 ) 222 mResourceManager( 0 )
223{ 223{
224 224
225 mEventEditor = 0; 225 mEventEditor = 0;
226 mTodoEditor = 0; 226 mTodoEditor = 0;
227 init();} 227 init();}
228 228
229void CalendarView::init() 229void CalendarView::init()
230{ 230{
231 beamDialog = new KOBeamPrefs(); 231 beamDialog = new KOBeamPrefs();
232 mDatePickerMode = 0; 232 mDatePickerMode = 0;
233 mCurrentSyncDevice = ""; 233 mCurrentSyncDevice = "";
234 writeLocale(); 234 writeLocale();
235 mViewManager = new KOViewManager( this ); 235 mViewManager = new KOViewManager( this );
236 mDialogManager = new KODialogManager( this ); 236 mDialogManager = new KODialogManager( this );
237 mEventViewerDialog = 0; 237 mEventViewerDialog = 0;
238 mModified = false; 238 mModified = false;
239 mReadOnly = false; 239 mReadOnly = false;
240 mSelectedIncidence = 0; 240 mSelectedIncidence = 0;
241 mCalPrinter = 0; 241 mCalPrinter = 0;
242 mFilters.setAutoDelete(true); 242 mFilters.setAutoDelete(true);
243 243
244 mCalendar->registerObserver( this ); 244 mCalendar->registerObserver( this );
245 // TODO: Make sure that view is updated, when calendar is changed. 245 // TODO: Make sure that view is updated, when calendar is changed.
246 246
247 mStorage = new FileStorage( mCalendar ); 247 mStorage = new FileStorage( mCalendar );
248 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 248 mNavigator = new DateNavigator( this, "datevav", mViewManager );
249 249
250 QBoxLayout *topLayout = (QBoxLayout*)layout(); 250 QBoxLayout *topLayout = (QBoxLayout*)layout();
251#ifndef KORG_NOSPLITTER 251#ifndef KORG_NOSPLITTER
252 // create the main layout frames. 252 // create the main layout frames.
253 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 253 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
254 topLayout->addWidget(mPanner); 254 topLayout->addWidget(mPanner);
255 255
256 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 256 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
257 "CalendarView::LeftFrame"); 257 "CalendarView::LeftFrame");
258 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 258 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
259 259
260 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 260 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
261 "CalendarView::DateNavigator", QDate::currentDate() ); 261 "CalendarView::DateNavigator", QDate::currentDate() );
262 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 262 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
263 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 263 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
264 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 264 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
265 265
266#ifdef KORG_NORESOURCEVIEW 266#ifdef KORG_NORESOURCEVIEW
267 mResourceView = 0; 267 mResourceView = 0;
268#else 268#else
269 if ( mResourceManager ) { 269 if ( mResourceManager ) {
270 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 270 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
271 mResourceView->updateView(); 271 mResourceView->updateView();
272 connect( mResourceView, SIGNAL( resourcesChanged() ), 272 connect( mResourceView, SIGNAL( resourcesChanged() ),
273 SLOT( updateView() ) ); 273 SLOT( updateView() ) );
274 } else { 274 } else {
275 mResourceView = 0; 275 mResourceView = 0;
276 } 276 }
277#endif 277#endif
278 QWidget *rightBox = new QWidget( mPanner ); 278 QWidget *rightBox = new QWidget( mPanner );
279 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 279 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
280 280
281 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 281 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
282 rightLayout->addWidget( mNavigatorBar ); 282 rightLayout->addWidget( mNavigatorBar );
283 283
284 mRightFrame = new QWidgetStack( rightBox ); 284 mRightFrame = new QWidgetStack( rightBox );
285 rightLayout->addWidget( mRightFrame, 1 ); 285 rightLayout->addWidget( mRightFrame, 1 );
286 286
287 mLeftFrame = mLeftSplitter; 287 mLeftFrame = mLeftSplitter;
288#else 288#else
289 QWidget *mainBox = new QWidget( this ); 289 QWidget *mainBox = new QWidget( this );
290 QWidget *leftFrame = new QWidget( mainBox ); 290 QWidget *leftFrame = new QWidget( mainBox );
291 291
292 QBoxLayout * mainBoxLayout; 292 QBoxLayout * mainBoxLayout;
293 QBoxLayout * leftFrameLayout; 293 QBoxLayout * leftFrameLayout;
294 if ( KOPrefs::instance()->mVerticalScreen ) { 294 if ( KOPrefs::instance()->mVerticalScreen ) {
295 mainBoxLayout = new QVBoxLayout(mainBox); 295 mainBoxLayout = new QVBoxLayout(mainBox);
296 leftFrameLayout = new QHBoxLayout(leftFrame ); 296 leftFrameLayout = new QHBoxLayout(leftFrame );
297 } else { 297 } else {
298 mainBoxLayout = new QHBoxLayout(mainBox); 298 mainBoxLayout = new QHBoxLayout(mainBox);
299 leftFrameLayout = new QVBoxLayout(leftFrame ); 299 leftFrameLayout = new QVBoxLayout(leftFrame );
300 } 300 }
301 topLayout->addWidget( mainBox ); 301 topLayout->addWidget( mainBox );
302 mainBoxLayout->addWidget (leftFrame); 302 mainBoxLayout->addWidget (leftFrame);
303 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 303 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
304 "CalendarView::DateNavigator", QDate::currentDate()); 304 "CalendarView::DateNavigator", QDate::currentDate());
305 // mDateNavigator->blockSignals( true ); 305 // mDateNavigator->blockSignals( true );
306 leftFrameLayout->addWidget( mDateNavigator ); 306 leftFrameLayout->addWidget( mDateNavigator );
307 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 307 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
308 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); 308 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist");
309 309
310 if ( QApplication::desktop()->width() < 480 ) { 310 if ( QApplication::desktop()->width() < 480 ) {
311 leftFrameLayout->addWidget(mFilterView); 311 leftFrameLayout->addWidget(mFilterView);
312 leftFrameLayout->addWidget(mTodoList, 2 ); 312 leftFrameLayout->addWidget(mTodoList, 2 );
313 313
314 } else { 314 } else {
315 leftFrameLayout->addWidget(mTodoList,2 ); 315 leftFrameLayout->addWidget(mTodoList,2 );
316 leftFrameLayout->addWidget(mFilterView ); 316 leftFrameLayout->addWidget(mFilterView );
317 } 317 }
318 mFilterView->hide(); 318 mFilterView->hide();
319 QWidget *rightBox = new QWidget( mainBox ); 319 QWidget *rightBox = new QWidget( mainBox );
320 mainBoxLayout->addWidget ( rightBox, 10 ); 320 mainBoxLayout->addWidget ( rightBox, 10 );
321 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 321 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
322 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 322 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
323 mRightFrame = new QWidgetStack( rightBox ); 323 mRightFrame = new QWidgetStack( rightBox );
324 rightLayout->addWidget( mNavigatorBar ); 324 rightLayout->addWidget( mNavigatorBar );
325 rightLayout->addWidget( mRightFrame, 10 ); 325 rightLayout->addWidget( mRightFrame, 10 );
326 326
327 mLeftFrame = leftFrame; 327 mLeftFrame = leftFrame;
328 if ( KOPrefs::instance()->mVerticalScreen ) { 328 if ( KOPrefs::instance()->mVerticalScreen ) {
329 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 329 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
330 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 330 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
331 } else { 331 } else {
332 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 332 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
333 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 333 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
334 } 334 }
335 335
336 //qDebug("Calendarview Size %d %d ", width(), height()); 336 //qDebug("Calendarview Size %d %d ", width(), height());
337#endif 337#endif
338 338
339 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 339 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
340 SLOT( showDates( const KCal::DateList & ) ) ); 340 SLOT( showDates( const KCal::DateList & ) ) );
341 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 341 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
342 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 342 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
343 343
344 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 344 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
345 mNavigator, SLOT( selectPreviousYear() ) ); 345 mNavigator, SLOT( selectPreviousYear() ) );
346 connect( mNavigatorBar, SIGNAL( goNextYear() ), 346 connect( mNavigatorBar, SIGNAL( goNextYear() ),
347 mNavigator, SLOT( selectNextYear() ) ); 347 mNavigator, SLOT( selectNextYear() ) );
348 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 348 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
349 mNavigator, SLOT( selectPreviousMonth() ) ); 349 mNavigator, SLOT( selectPreviousMonth() ) );
350 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 350 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
351 mNavigator, SLOT( selectNextMonth() ) ); 351 mNavigator, SLOT( selectNextMonth() ) );
352 352
353 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 353 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
354 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 354 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
355 355
356 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 356 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
357 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 357 mNavigator, SLOT( selectWeek( const QDate & ) ) );
358 358
359 connect( mDateNavigator, SIGNAL( goPrevYear() ), 359 connect( mDateNavigator, SIGNAL( goPrevYear() ),
360 mNavigator, SLOT( selectPreviousYear() ) ); 360 mNavigator, SLOT( selectPreviousYear() ) );
361 connect( mDateNavigator, SIGNAL( goNextYear() ), 361 connect( mDateNavigator, SIGNAL( goNextYear() ),
362 mNavigator, SLOT( selectNextYear() ) ); 362 mNavigator, SLOT( selectNextYear() ) );
363 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 363 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
364 mNavigator, SLOT( selectPreviousMonth() ) ); 364 mNavigator, SLOT( selectPreviousMonth() ) );
365 connect( mDateNavigator, SIGNAL( goNextMonth() ), 365 connect( mDateNavigator, SIGNAL( goNextMonth() ),
366 mNavigator, SLOT( selectNextMonth() ) ); 366 mNavigator, SLOT( selectNextMonth() ) );
367 367
368 connect( mDateNavigator, SIGNAL( goPrevious() ), 368 connect( mDateNavigator, SIGNAL( goPrevious() ),
369 mNavigator, SLOT( selectPrevious() ) ); 369 mNavigator, SLOT( selectPrevious() ) );
370 connect( mDateNavigator, SIGNAL( goNext() ), 370 connect( mDateNavigator, SIGNAL( goNext() ),
371 mNavigator, SLOT( selectNext() ) ); 371 mNavigator, SLOT( selectNext() ) );
372 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 372 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
373 mNavigator, SLOT( slotMonthSelect( int ) ) ); 373 mNavigator, SLOT( slotMonthSelect( int ) ) );
374 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 374 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
375 mNavigator, SLOT( slotMonthSelect( int ) ) ); 375 mNavigator, SLOT( slotMonthSelect( int ) ) );
376 376
377 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 377 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
378 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 378 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
379 379
380 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 380 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
381 SLOT( eventAdded( Event *) ) ); 381 SLOT( eventAdded( Event *) ) );
382 382
383 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 383 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
384 384
385 connect( this, SIGNAL( configChanged() ), 385 connect( this, SIGNAL( configChanged() ),
386 mDateNavigator, SLOT( updateConfig() ) ); 386 mDateNavigator, SLOT( updateConfig() ) );
387 387
388 connect( mTodoList, SIGNAL( newTodoSignal() ), 388 connect( mTodoList, SIGNAL( newTodoSignal() ),
389 SLOT( newTodo() ) ); 389 SLOT( newTodo() ) );
390 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 390 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
391 SLOT( newSubTodo( Todo * ) ) ); 391 SLOT( newSubTodo( Todo * ) ) );
392 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 392 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
393 SLOT( editTodo( Todo * ) ) ); 393 SLOT( editTodo( Todo * ) ) );
394 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 394 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
395 SLOT( showTodo( Todo *) ) ); 395 SLOT( showTodo( Todo *) ) );
396 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 396 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
397 SLOT( deleteTodo( Todo *) ) ); 397 SLOT( deleteTodo( Todo *) ) );
398 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 398 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
399 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 399 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
400 SLOT( purgeCompleted() ) ); 400 SLOT( purgeCompleted() ) );
401 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 401 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
402 SIGNAL( todoModified( Todo *, int ) ) ); 402 SIGNAL( todoModified( Todo *, int ) ) );
403 403
404 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 404 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
405 this, SLOT ( cloneIncidence( Incidence * ) ) ); 405 this, SLOT ( cloneIncidence( Incidence * ) ) );
406 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 406 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
407 this, SLOT (cancelIncidence( Incidence * ) ) ); 407 this, SLOT (cancelIncidence( Incidence * ) ) );
408 408
409 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
410 this, SLOT ( moveIncidence( Incidence * ) ) ); 410 this, SLOT ( moveIncidence( Incidence * ) ) );
411 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
412 this, SLOT ( beamIncidence( Incidence * ) ) ); 412 this, SLOT ( beamIncidence( Incidence * ) ) );
413 413
414 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 414 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
415 this, SLOT ( todo_unsub( Todo * ) ) ); 415 this, SLOT ( todo_unsub( Todo * ) ) );
416 416
417 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 417 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
418 SLOT( updateTodo( Todo *, int ) ) ); 418 SLOT( updateTodo( Todo *, int ) ) );
419 connect( this, SIGNAL( todoModified( Todo *, int )), this, 419 connect( this, SIGNAL( todoModified( Todo *, int )), this,
420 SLOT( changeTodoDisplay( Todo *, int ) ) ); 420 SLOT( changeTodoDisplay( Todo *, int ) ) );
421 421
422 422
423 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 423 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
424 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 424 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
425 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 425 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
426 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 426 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
427 427
428 428
429 429
430 430
431 431
432 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 432 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
433 SLOT(checkClipboard())); 433 SLOT(checkClipboard()));
434 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 434 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
435 SLOT( processTodoListSelection( Incidence * ) ) ); 435 SLOT( processTodoListSelection( Incidence * ) ) );
436 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 436 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
437 437
438 // kdDebug() << "CalendarView::CalendarView() done" << endl; 438 // kdDebug() << "CalendarView::CalendarView() done" << endl;
439 439
440 mDateFrame = new QVBox(0,0,WType_Popup); 440 mDateFrame = new QVBox(0,0,WType_Popup);
441 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 441 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
442 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 442 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
443 mDateFrame->setLineWidth(3); 443 mDateFrame->setLineWidth(3);
444 mDateFrame->hide(); 444 mDateFrame->hide();
445 mDateFrame->setCaption( i18n( "Pick a date to display")); 445 mDateFrame->setCaption( i18n( "Pick a date to display"));
446 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 446 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
447 447
448 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 448 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
449 449
450 mEventEditor = mDialogManager->getEventEditor(); 450 mEventEditor = mDialogManager->getEventEditor();
451 mTodoEditor = mDialogManager->getTodoEditor(); 451 mTodoEditor = mDialogManager->getTodoEditor();
452 452
453 mFlagEditDescription = false; 453 mFlagEditDescription = false;
454 454
455 mSuspendTimer = new QTimer( this ); 455 mSuspendTimer = new QTimer( this );
456 mAlarmTimer = new QTimer( this ); 456 mAlarmTimer = new QTimer( this );
457 mRecheckAlarmTimer = new QTimer( this ); 457 mRecheckAlarmTimer = new QTimer( this );
458 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 458 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
459 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 459 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
460 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 460 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
461 mAlarmDialog = new AlarmDialog( this ); 461 mAlarmDialog = new AlarmDialog( this );
462 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 462 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
463 mAlarmDialog->setServerNotification( false ); 463 mAlarmDialog->setServerNotification( false );
464 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 464 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
465} 465}
466 466
467 467
468CalendarView::~CalendarView() 468CalendarView::~CalendarView()
469{ 469{
470 // kdDebug() << "~CalendarView()" << endl; 470 // kdDebug() << "~CalendarView()" << endl;
471 //qDebug("CalendarView::~CalendarView() "); 471 //qDebug("CalendarView::~CalendarView() ");
472 delete mDialogManager; 472 delete mDialogManager;
473 delete mViewManager; 473 delete mViewManager;
474 delete mStorage; 474 delete mStorage;
475 delete mDateFrame ; 475 delete mDateFrame ;
476 delete beamDialog; 476 delete beamDialog;
477 //kdDebug() << "~CalendarView() done" << endl; 477 //kdDebug() << "~CalendarView() done" << endl;
478} 478}
479void CalendarView::timerAlarm() 479void CalendarView::timerAlarm()
480{ 480{
481 //qDebug("CalendarView::timerAlarm() "); 481 //qDebug("CalendarView::timerAlarm() ");
482 computeAlarm(mAlarmNotification ); 482 computeAlarm(mAlarmNotification );
483} 483}
484 484
485void CalendarView::suspendAlarm() 485void CalendarView::suspendAlarm()
486{ 486{
487 //qDebug(" CalendarView::suspendAlarm() "); 487 //qDebug(" CalendarView::suspendAlarm() ");
488 computeAlarm(mSuspendAlarmNotification ); 488 computeAlarm(mSuspendAlarmNotification );
489 489
490} 490}
491 491
492void CalendarView::startAlarm( QString mess , QString filename) 492void CalendarView::startAlarm( QString mess , QString filename)
493{ 493{
494 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 494 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
495 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 495 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
496 496
497} 497}
498 498
499void CalendarView::checkNextTimerAlarm() 499void CalendarView::checkNextTimerAlarm()
500{ 500{
501 mCalendar->checkAlarmForIncidence( 0, true ); 501 mCalendar->checkAlarmForIncidence( 0, true );
502} 502}
503 503
504void CalendarView::computeAlarm( QString msg ) 504void CalendarView::computeAlarm( QString msg )
505{ 505{
506 506
507 QString mess = msg; 507 QString mess = msg;
508 QString mAlarmMessage = mess.mid( 9 ); 508 QString mAlarmMessage = mess.mid( 9 );
509 QString filename = MainWindow::resourcePath(); 509 QString filename = MainWindow::resourcePath();
510 filename += "koalarm.wav"; 510 filename += "koalarm.wav";
511 QString tempfilename; 511 QString tempfilename;
512 if ( mess.left( 13 ) == "suspend_alarm") { 512 if ( mess.left( 13 ) == "suspend_alarm") {
513 bool error = false; 513 bool error = false;
514 int len = mess.mid( 13 ).find("+++"); 514 int len = mess.mid( 13 ).find("+++");
515 if ( len < 2 ) 515 if ( len < 2 )
516 error = true; 516 error = true;
517 else { 517 else {
518 tempfilename = mess.mid( 13, len ); 518 tempfilename = mess.mid( 13, len );
519 if ( !QFile::exists( tempfilename ) ) 519 if ( !QFile::exists( tempfilename ) )
520 error = true; 520 error = true;
521 } 521 }
522 if ( ! error ) { 522 if ( ! error ) {
523 filename = tempfilename; 523 filename = tempfilename;
524 } 524 }
525 mAlarmMessage = mess.mid( 13+len+3 ); 525 mAlarmMessage = mess.mid( 13+len+3 );
526 //qDebug("suspend file %s ",tempfilename.latin1() ); 526 //qDebug("suspend file %s ",tempfilename.latin1() );
527 startAlarm( mAlarmMessage, filename); 527 startAlarm( mAlarmMessage, filename);
528 return; 528 return;
529 } 529 }
530 if ( mess.left( 11 ) == "timer_alarm") { 530 if ( mess.left( 11 ) == "timer_alarm") {
531 //mTimerTime = 0; 531 //mTimerTime = 0;
532 startAlarm( mess.mid( 11 ), filename ); 532 startAlarm( mess.mid( 11 ), filename );
533 return; 533 return;
534 } 534 }
535 if ( mess.left( 10 ) == "proc_alarm") { 535 if ( mess.left( 10 ) == "proc_alarm") {
536 bool error = false; 536 bool error = false;
537 int len = mess.mid( 10 ).find("+++"); 537 int len = mess.mid( 10 ).find("+++");
538 if ( len < 2 ) 538 if ( len < 2 )
539 error = true; 539 error = true;
540 else { 540 else {
541 tempfilename = mess.mid( 10, len ); 541 tempfilename = mess.mid( 10, len );
542 if ( !QFile::exists( tempfilename ) ) 542 if ( !QFile::exists( tempfilename ) )
543 error = true; 543 error = true;
544 } 544 }
545 if ( error ) { 545 if ( error ) {
546 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 546 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
547 mAlarmMessage += mess.mid( 10+len+3+9 ); 547 mAlarmMessage += mess.mid( 10+len+3+9 );
548 } else { 548 } else {
549 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 549 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
550 //qDebug("-----system command %s ",tempfilename.latin1() ); 550 //qDebug("-----system command %s ",tempfilename.latin1() );
551#ifndef _WIN32_ 551#ifndef _WIN32_
552 if ( vfork () == 0 ) { 552 if ( vfork () == 0 ) {
553 execl ( tempfilename.latin1(), 0 ); 553 execl ( tempfilename.latin1(), 0 );
554 return; 554 return;
555 } 555 }
556#else 556#else
557 QProcess* p = new QProcess(); 557 QProcess* p = new QProcess();
558 p->addArgument( tempfilename.latin1() ); 558 p->addArgument( tempfilename.latin1() );
559 p->start(); 559 p->start();
560 return; 560 return;
561#endif 561#endif
562 562
563 return; 563 return;
564 } 564 }
565 565
566 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 566 //qDebug("+++++++system command %s ",tempfilename.latin1() );
567 } 567 }
568 if ( mess.left( 11 ) == "audio_alarm") { 568 if ( mess.left( 11 ) == "audio_alarm") {
569 bool error = false; 569 bool error = false;
570 int len = mess.mid( 11 ).find("+++"); 570 int len = mess.mid( 11 ).find("+++");
571 if ( len < 2 ) 571 if ( len < 2 )
572 error = true; 572 error = true;
573 else { 573 else {
574 tempfilename = mess.mid( 11, len ); 574 tempfilename = mess.mid( 11, len );
575 if ( !QFile::exists( tempfilename ) ) 575 if ( !QFile::exists( tempfilename ) )
576 error = true; 576 error = true;
577 } 577 }
578 if ( ! error ) { 578 if ( ! error ) {
579 filename = tempfilename; 579 filename = tempfilename;
580 } 580 }
581 mAlarmMessage = mess.mid( 11+len+3+9 ); 581 mAlarmMessage = mess.mid( 11+len+3+9 );
582 //qDebug("audio file command %s ",tempfilename.latin1() ); 582 //qDebug("audio file command %s ",tempfilename.latin1() );
583 } 583 }
584 if ( mess.left( 9 ) == "cal_alarm") { 584 if ( mess.left( 9 ) == "cal_alarm") {
585 mAlarmMessage = mess.mid( 9 ) ; 585 mAlarmMessage = mess.mid( 9 ) ;
586 } 586 }
587 587
588 startAlarm( mAlarmMessage, filename ); 588 startAlarm( mAlarmMessage, filename );
589 589
590 590
591} 591}
592 592
593void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 593void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
594{ 594{
595 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 595 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
596 596
597 mSuspendAlarmNotification = noti; 597 mSuspendAlarmNotification = noti;
598 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 598 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
599 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 599 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
600 mSuspendTimer->start( ms , true ); 600 mSuspendTimer->start( ms , true );
601 601
602} 602}
603 603
604void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 604void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
605{ 605{
606 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 606 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
607 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 607 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
608#ifndef DESKTOP_VERSION 608#ifndef DESKTOP_VERSION
609 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 609 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
610#endif 610#endif
611 return; 611 return;
612 } 612 }
613 int maxSec; 613 int maxSec;
614 //maxSec = 5; //testing only 614 //maxSec = 5; //testing only
615 maxSec = 86400+3600; // one day+1hour 615 maxSec = 86400+3600; // one day+1hour
616 mAlarmNotification = noti; 616 mAlarmNotification = noti;
617 int sec = QDateTime::currentDateTime().secsTo( qdt ); 617 int sec = QDateTime::currentDateTime().secsTo( qdt );
618 if ( sec > maxSec ) { 618 if ( sec > maxSec ) {
619 mRecheckAlarmTimer->start( maxSec * 1000 ); 619 mRecheckAlarmTimer->start( maxSec * 1000 );
620 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 620 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
621 return; 621 return;
622 } else { 622 } else {
623 mRecheckAlarmTimer->stop(); 623 mRecheckAlarmTimer->stop();
624 } 624 }
625 //qDebug("Alarm timer started with secs: %d ", sec); 625 //qDebug("Alarm timer started with secs: %d ", sec);
626 mAlarmTimer->start( sec *1000 , true ); 626 mAlarmTimer->start( sec *1000 , true );
627 627
628} 628}
629// called by mRecheckAlarmTimer to get next alarm 629// called by mRecheckAlarmTimer to get next alarm
630// we need this, because a QTimer has only a max range of 25 days 630// we need this, because a QTimer has only a max range of 25 days
631void CalendarView::recheckTimerAlarm() 631void CalendarView::recheckTimerAlarm()
632{ 632{
633 mAlarmTimer->stop(); 633 mAlarmTimer->stop();
634 mRecheckAlarmTimer->stop(); 634 mRecheckAlarmTimer->stop();
635 mCalendar->checkAlarmForIncidence( 0, true ); 635 mCalendar->checkAlarmForIncidence( 0, true );
636} 636}
637void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 637void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
638{ 638{
639 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 639 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
640 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 640 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
641#ifndef DESKTOP_VERSION 641#ifndef DESKTOP_VERSION
642 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 642 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
643#endif 643#endif
644 return; 644 return;
645 } 645 }
646 mAlarmTimer->stop(); 646 mAlarmTimer->stop();
647} 647}
648void CalendarView::selectWeekNum ( int num ) 648void CalendarView::selectWeekNum ( int num )
649{ 649{
650 dateNavigator()->selectWeek( num ); 650 dateNavigator()->selectWeek( num );
651 mViewManager->showWeekView(); 651 mViewManager->showWeekView();
652} 652}
653KOViewManager *CalendarView::viewManager() 653KOViewManager *CalendarView::viewManager()
654{ 654{
655 return mViewManager; 655 return mViewManager;
656} 656}
657 657
658KODialogManager *CalendarView::dialogManager() 658KODialogManager *CalendarView::dialogManager()
659{ 659{
660 return mDialogManager; 660 return mDialogManager;
661} 661}
662 662
663QDate CalendarView::startDate() 663QDate CalendarView::startDate()
664{ 664{
665 DateList dates = mNavigator->selectedDates(); 665 DateList dates = mNavigator->selectedDates();
666 666
667 return dates.first(); 667 return dates.first();
668} 668}
669 669
670QDate CalendarView::endDate() 670QDate CalendarView::endDate()
671{ 671{
672 DateList dates = mNavigator->selectedDates(); 672 DateList dates = mNavigator->selectedDates();
673 673
674 return dates.last(); 674 return dates.last();
675} 675}
676 676
677 677
678void CalendarView::createPrinter() 678void CalendarView::createPrinter()
679{ 679{
680#ifndef KORG_NOPRINTER 680#ifndef KORG_NOPRINTER
681 if (!mCalPrinter) { 681 if (!mCalPrinter) {
682 mCalPrinter = new CalPrinter(this, mCalendar); 682 mCalPrinter = new CalPrinter(this, mCalendar);
683 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 683 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
684 } 684 }
685#endif 685#endif
686} 686}
687 687
688void CalendarView::confSync() 688void CalendarView::confSync()
689{ 689{
690 static KSyncPrefsDialog* sp = 0; 690 static KSyncPrefsDialog* sp = 0;
691 if ( ! sp ) { 691 if ( ! sp ) {
692 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 692 sp = new KSyncPrefsDialog( this, "syncprefs", true );
693 } 693 }
694 sp->usrReadConfig(); 694 sp->usrReadConfig();
695#ifndef DESKTOP_VERSION 695#ifndef DESKTOP_VERSION
696 sp->showMaximized(); 696 sp->showMaximized();
697#else 697#else
698 sp->show(); 698 sp->show();
699#endif 699#endif
700 sp->exec(); 700 sp->exec();
701 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 701 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
702 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 702 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
703} 703}
704 704
705 705
706//KOPrefs::instance()->mWriteBackFile 706//KOPrefs::instance()->mWriteBackFile
707//KOPrefs::instance()->mWriteBackExistingOnly 707//KOPrefs::instance()->mWriteBackExistingOnly
708 708
709// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 709// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
710// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 710// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
711// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 711// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
712// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 712// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
713// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 713// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
714// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 714// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
715 715
716int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 716int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
717{ 717{
718 718
719 //void setZaurusId(int id); 719 //void setZaurusId(int id);
720 // int zaurusId() const; 720 // int zaurusId() const;
721 // void setZaurusUid(int id); 721 // void setZaurusUid(int id);
722 // int zaurusUid() const; 722 // int zaurusUid() const;
723 // void setZaurusStat(int id); 723 // void setZaurusStat(int id);
724 // int zaurusStat() const; 724 // int zaurusStat() const;
725 // 0 equal 725 // 0 equal
726 // 1 take local 726 // 1 take local
727 // 2 take remote 727 // 2 take remote
728 // 3 cancel 728 // 3 cancel
729 QDateTime lastSync = mLastCalendarSync; 729 QDateTime lastSync = mLastCalendarSync;
730 QDateTime localMod = local->lastModified(); 730 QDateTime localMod = local->lastModified();
731 QDateTime remoteMod = remote->lastModified(); 731 QDateTime remoteMod = remote->lastModified();
732 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 732 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
733 bool remCh, locCh; 733 bool remCh, locCh;
734 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 734 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
735 //if ( remCh ) 735 //if ( remCh )
736 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 736 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
737 locCh = ( localMod > mLastCalendarSync ); 737 locCh = ( localMod > mLastCalendarSync );
738 if ( !remCh && ! locCh ) { 738 if ( !remCh && ! locCh ) {
739 //qDebug("both not changed "); 739 //qDebug("both not changed ");
740 lastSync = localMod.addDays(1); 740 lastSync = localMod.addDays(1);
741 if ( mode <= SYNC_PREF_ASK ) 741 if ( mode <= SYNC_PREF_ASK )
742 return 0; 742 return 0;
743 } else { 743 } else {
744 if ( locCh ) { 744 if ( locCh ) {
745 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 745 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
746 lastSync = localMod.addDays( -1 ); 746 lastSync = localMod.addDays( -1 );
747 if ( !remCh ) 747 if ( !remCh )
748 remoteMod = ( lastSync.addDays( -1 ) ); 748 remoteMod = ( lastSync.addDays( -1 ) );
749 } else { 749 } else {
750 //qDebug(" not loc changed "); 750 //qDebug(" not loc changed ");
751 lastSync = localMod.addDays( 1 ); 751 lastSync = localMod.addDays( 1 );
752 if ( remCh ) 752 if ( remCh )
753 remoteMod =( lastSync.addDays( 1 ) ); 753 remoteMod =( lastSync.addDays( 1 ) );
754 754
755 } 755 }
756 } 756 }
757 full = true; 757 full = true;
758 if ( mode < SYNC_PREF_ASK ) 758 if ( mode < SYNC_PREF_ASK )
759 mode = SYNC_PREF_ASK; 759 mode = SYNC_PREF_ASK;
760 } else { 760 } else {
761 if ( localMod == remoteMod ) 761 if ( localMod == remoteMod )
762 if ( local->revision() == remote->revision() ) 762 if ( local->revision() == remote->revision() )
763 return 0; 763 return 0;
764 764
765 } 765 }
766 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 766 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
767 767
768 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 768 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
769 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 769 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
770 //full = true; //debug only 770 //full = true; //debug only
771 if ( full ) { 771 if ( full ) {
772 bool equ = false; 772 bool equ = false;
773 if ( local->type() == "Event" ) { 773 if ( local->type() == "Event" ) {
774 equ = (*((Event*) local) == *((Event*) remote)); 774 equ = (*((Event*) local) == *((Event*) remote));
775 } 775 }
776 else if ( local->type() =="Todo" ) 776 else if ( local->type() =="Todo" )
777 equ = (*((Todo*) local) == (*(Todo*) remote)); 777 equ = (*((Todo*) local) == (*(Todo*) remote));
778 else if ( local->type() =="Journal" ) 778 else if ( local->type() =="Journal" )
779 equ = (*((Journal*) local) == *((Journal*) remote)); 779 equ = (*((Journal*) local) == *((Journal*) remote));
780 if ( equ ) { 780 if ( equ ) {
781 //qDebug("equal "); 781 //qDebug("equal ");
782 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 782 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
783 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 783 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
784 } 784 }
785 if ( mode < SYNC_PREF_FORCE_LOCAL ) 785 if ( mode < SYNC_PREF_FORCE_LOCAL )
786 return 0; 786 return 0;
787 787
788 }//else //debug only 788 }//else //debug only
789 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 789 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
790 } 790 }
791 int result; 791 int result;
792 bool localIsNew; 792 bool localIsNew;
793 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 793 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
794 794
795 if ( full && mode < SYNC_PREF_NEWEST ) 795 if ( full && mode < SYNC_PREF_NEWEST )
796 mode = SYNC_PREF_ASK; 796 mode = SYNC_PREF_ASK;
797 797
798 switch( mode ) { 798 switch( mode ) {
799 case SYNC_PREF_LOCAL: 799 case SYNC_PREF_LOCAL:
800 if ( lastSync > remoteMod ) 800 if ( lastSync > remoteMod )
801 return 1; 801 return 1;
802 if ( lastSync > localMod ) 802 if ( lastSync > localMod )
803 return 2; 803 return 2;
804 return 1; 804 return 1;
805 break; 805 break;
806 case SYNC_PREF_REMOTE: 806 case SYNC_PREF_REMOTE:
807 if ( lastSync > remoteMod ) 807 if ( lastSync > remoteMod )
808 return 1; 808 return 1;
809 if ( lastSync > localMod ) 809 if ( lastSync > localMod )
810 return 2; 810 return 2;
811 return 2; 811 return 2;
812 break; 812 break;
813 case SYNC_PREF_NEWEST: 813 case SYNC_PREF_NEWEST:
814 if ( localMod > remoteMod ) 814 if ( localMod > remoteMod )
815 return 1; 815 return 1;
816 else 816 else
817 return 2; 817 return 2;
818 break; 818 break;
819 case SYNC_PREF_ASK: 819 case SYNC_PREF_ASK:
820 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 820 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
821 if ( lastSync > remoteMod ) 821 if ( lastSync > remoteMod )
822 return 1; 822 return 1;
823 if ( lastSync > localMod ) 823 if ( lastSync > localMod )
824 return 2; 824 return 2;
825 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 825 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
826 localIsNew = localMod >= remoteMod; 826 localIsNew = localMod >= remoteMod;
827 if ( localIsNew ) 827 if ( localIsNew )
828 getEventViewerDialog()->setColorMode( 1 ); 828 getEventViewerDialog()->setColorMode( 1 );
829 else 829 else
830 getEventViewerDialog()->setColorMode( 2 ); 830 getEventViewerDialog()->setColorMode( 2 );
831 getEventViewerDialog()->setIncidence(local); 831 getEventViewerDialog()->setIncidence(local);
832 if ( localIsNew ) 832 if ( localIsNew )
833 getEventViewerDialog()->setColorMode( 2 ); 833 getEventViewerDialog()->setColorMode( 2 );
834 else 834 else
835 getEventViewerDialog()->setColorMode( 1 ); 835 getEventViewerDialog()->setColorMode( 1 );
836 getEventViewerDialog()->addIncidence(remote); 836 getEventViewerDialog()->addIncidence(remote);
837 getEventViewerDialog()->setColorMode( 0 ); 837 getEventViewerDialog()->setColorMode( 0 );
838 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 838 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
839 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 839 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
840 getEventViewerDialog()->showMe(); 840 getEventViewerDialog()->showMe();
841 result = getEventViewerDialog()->executeS( localIsNew ); 841 result = getEventViewerDialog()->executeS( localIsNew );
842 return result; 842 return result;
843 843
844 break; 844 break;
845 case SYNC_PREF_FORCE_LOCAL: 845 case SYNC_PREF_FORCE_LOCAL:
846 return 1; 846 return 1;
847 break; 847 break;
848 case SYNC_PREF_FORCE_REMOTE: 848 case SYNC_PREF_FORCE_REMOTE:
849 return 2; 849 return 2;
850 break; 850 break;
851 851
852 default: 852 default:
853 // SYNC_PREF_TAKE_BOTH not implemented 853 // SYNC_PREF_TAKE_BOTH not implemented
854 break; 854 break;
855 } 855 }
856 return 0; 856 return 0;
857} 857}
858Event* CalendarView::getLastSyncEvent() 858Event* CalendarView::getLastSyncEvent()
859{ 859{
860 Event* lse; 860 Event* lse;
861 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 861 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
862 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 862 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
863 if (!lse) { 863 if (!lse) {
864 lse = new Event(); 864 lse = new Event();
865 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 865 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
866 QString sum = ""; 866 QString sum = "";
867 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 867 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
868 sum = "E: "; 868 sum = "E: ";
869 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 869 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
870 lse->setDtStart( mLastCalendarSync ); 870 lse->setDtStart( mLastCalendarSync );
871 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 871 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
872 lse->setCategories( i18n("SyncEvent") ); 872 lse->setCategories( i18n("SyncEvent") );
873 lse->setReadOnly( true ); 873 lse->setReadOnly( true );
874 mCalendar->addEvent( lse ); 874 mCalendar->addEvent( lse );
875 } 875 }
876 876
877 return lse; 877 return lse;
878 878
879} 879}
880// probaly useless 880// probaly useless
881void CalendarView::setupExternSyncProfiles() 881void CalendarView::setupExternSyncProfiles()
882{ 882{
883 Event* lse; 883 Event* lse;
884 mExternLastSyncEvent.clear(); 884 mExternLastSyncEvent.clear();
885 int i; 885 int i;
886 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 886 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
887 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 887 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
888 if ( lse ) 888 if ( lse )
889 mExternLastSyncEvent.append( lse ); 889 mExternLastSyncEvent.append( lse );
890 else 890 else
891 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 891 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
892 } 892 }
893 893
894} 894}
895// we check, if the to delete event has a id for a profile 895// we check, if the to delete event has a id for a profile
896// if yes, we set this id in the profile to delete 896// if yes, we set this id in the profile to delete
897void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 897void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
898{ 898{
899 if ( lastSync.count() == 0 ) { 899 if ( lastSync.count() == 0 ) {
900 //qDebug(" lastSync.count() == 0"); 900 //qDebug(" lastSync.count() == 0");
901 return; 901 return;
902 } 902 }
903 if ( toDelete->type() == "Journal" ) 903 if ( toDelete->type() == "Journal" )
904 return; 904 return;
905 905
906 Event* eve = lastSync.first(); 906 Event* eve = lastSync.first();
907 907
908 while ( eve ) { 908 while ( eve ) {
909 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 909 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
910 if ( !id.isEmpty() ) { 910 if ( !id.isEmpty() ) {
911 QString des = eve->description(); 911 QString des = eve->description();
912 QString pref = "e"; 912 QString pref = "e";
913 if ( toDelete->type() == "Todo" ) 913 if ( toDelete->type() == "Todo" )
914 pref = "t"; 914 pref = "t";
915 des += pref+ id + ","; 915 des += pref+ id + ",";
916 eve->setReadOnly( false ); 916 eve->setReadOnly( false );
917 eve->setDescription( des ); 917 eve->setDescription( des );
918 //qDebug("setdes %s ", des.latin1()); 918 //qDebug("setdes %s ", des.latin1());
919 eve->setReadOnly( true ); 919 eve->setReadOnly( true );
920 } 920 }
921 eve = lastSync.next(); 921 eve = lastSync.next();
922 } 922 }
923 923
924} 924}
925void CalendarView::checkExternalId( Incidence * inc ) 925void CalendarView::checkExternalId( Incidence * inc )
926{ 926{
927 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 927 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
928 checkExternSyncEvent( lastSync, inc ); 928 checkExternSyncEvent( lastSync, inc );
929 929
930} 930}
931bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 931bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
932{ 932{
933 bool syncOK = true; 933 bool syncOK = true;
934 int addedEvent = 0; 934 int addedEvent = 0;
935 int addedEventR = 0; 935 int addedEventR = 0;
936 int deletedEventR = 0; 936 int deletedEventR = 0;
937 int deletedEventL = 0; 937 int deletedEventL = 0;
938 int changedLocal = 0; 938 int changedLocal = 0;
939 int changedRemote = 0; 939 int changedRemote = 0;
940 //QPtrList<Event> el = local->rawEvents(); 940 //QPtrList<Event> el = local->rawEvents();
941 Event* eventR; 941 Event* eventR;
942 QString uid; 942 QString uid;
943 int take; 943 int take;
944 Event* eventL; 944 Event* eventL;
945 Event* eventRSync; 945 Event* eventRSync;
946 Event* eventLSync; 946 Event* eventLSync;
947 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 947 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
948 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 948 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
949 bool fullDateRange = false; 949 bool fullDateRange = false;
950 local->resetTempSyncStat(); 950 local->resetTempSyncStat();
951 mLastCalendarSync = QDateTime::currentDateTime(); 951 mLastCalendarSync = QDateTime::currentDateTime();
952 QDateTime modifiedCalendar = mLastCalendarSync;; 952 QDateTime modifiedCalendar = mLastCalendarSync;;
953 eventLSync = getLastSyncEvent(); 953 eventLSync = getLastSyncEvent();
954 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 954 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
955 if ( eventR ) { 955 if ( eventR ) {
956 eventRSync = (Event*) eventR->clone(); 956 eventRSync = (Event*) eventR->clone();
957 remote->deleteEvent(eventR ); 957 remote->deleteEvent(eventR );
958 958
959 } else { 959 } else {
960 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 960 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
961 eventRSync = (Event*)eventLSync->clone(); 961 eventRSync = (Event*)eventLSync->clone();
962 } else { 962 } else {
963 fullDateRange = true; 963 fullDateRange = true;
964 eventRSync = new Event(); 964 eventRSync = new Event();
965 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 965 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
966 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 966 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
967 eventRSync->setDtStart( mLastCalendarSync ); 967 eventRSync->setDtStart( mLastCalendarSync );
968 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 968 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
969 eventRSync->setCategories( i18n("SyncEvent") ); 969 eventRSync->setCategories( i18n("SyncEvent") );
970 } 970 }
971 } 971 }
972 if ( eventLSync->dtStart() == mLastCalendarSync ) 972 if ( eventLSync->dtStart() == mLastCalendarSync )
973 fullDateRange = true; 973 fullDateRange = true;
974 974
975 if ( ! fullDateRange ) { 975 if ( ! fullDateRange ) {
976 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 976 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
977 977
978 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 978 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
979 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 979 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
980 fullDateRange = true; 980 fullDateRange = true;
981 } 981 }
982 } 982 }
983 if ( fullDateRange ) 983 if ( fullDateRange )
984 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 984 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
985 else 985 else
986 mLastCalendarSync = eventLSync->dtStart(); 986 mLastCalendarSync = eventLSync->dtStart();
987 // for resyncing if own file has changed 987 // for resyncing if own file has changed
988 if ( mCurrentSyncDevice == "deleteaftersync" ) { 988 if ( mCurrentSyncDevice == "deleteaftersync" ) {
989 mLastCalendarSync = loadedFileVersion; 989 mLastCalendarSync = loadedFileVersion;
990 qDebug("setting mLastCalendarSync "); 990 qDebug("setting mLastCalendarSync ");
991 } 991 }
992 //qDebug("*************************** "); 992 //qDebug("*************************** ");
993 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 993 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
994 QPtrList<Incidence> er = remote->rawIncidences(); 994 QPtrList<Incidence> er = remote->rawIncidences();
995 Incidence* inR = er.first(); 995 Incidence* inR = er.first();
996 Incidence* inL; 996 Incidence* inL;
997 QProgressBar bar( er.count(),0 ); 997 QProgressBar bar( er.count(),0 );
998 bar.setCaption (i18n("Syncing - close to abort!") ); 998 bar.setCaption (i18n("Syncing - close to abort!") );
999 999
1000 int w = 300; 1000 int w = 300;
1001 if ( QApplication::desktop()->width() < 320 ) 1001 if ( QApplication::desktop()->width() < 320 )
1002 w = 220; 1002 w = 220;
1003 int h = bar.sizeHint().height() ; 1003 int h = bar.sizeHint().height() ;
1004 int dw = QApplication::desktop()->width(); 1004 int dw = QApplication::desktop()->width();
1005 int dh = QApplication::desktop()->height(); 1005 int dh = QApplication::desktop()->height();
1006 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1006 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1007 bar.show(); 1007 bar.show();
1008 int modulo = (er.count()/10)+1; 1008 int modulo = (er.count()/10)+1;
1009 int incCounter = 0; 1009 int incCounter = 0;
1010 while ( inR ) { 1010 while ( inR ) {
1011 if ( ! bar.isVisible() ) 1011 if ( ! bar.isVisible() )
1012 return false; 1012 return false;
1013 if ( incCounter % modulo == 0 ) 1013 if ( incCounter % modulo == 0 )
1014 bar.setProgress( incCounter ); 1014 bar.setProgress( incCounter );
1015 ++incCounter; 1015 ++incCounter;
1016 uid = inR->uid(); 1016 uid = inR->uid();
1017 bool skipIncidence = false; 1017 bool skipIncidence = false;
1018 if ( uid.left(15) == QString("last-syncEvent-") ) 1018 if ( uid.left(15) == QString("last-syncEvent-") )
1019 skipIncidence = true; 1019 skipIncidence = true;
1020 QString idS; 1020 QString idS;
1021 qApp->processEvents(); 1021 qApp->processEvents();
1022 if ( !skipIncidence ) { 1022 if ( !skipIncidence ) {
1023 inL = local->incidence( uid ); 1023 inL = local->incidence( uid );
1024 if ( inL ) { // maybe conflict - same uid in both calendars 1024 if ( inL ) { // maybe conflict - same uid in both calendars
1025 int maxrev = inL->revision(); 1025 int maxrev = inL->revision();
1026 if ( maxrev < inR->revision() ) 1026 if ( maxrev < inR->revision() )
1027 maxrev = inR->revision(); 1027 maxrev = inR->revision();
1028 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1028 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1029 //qDebug("take %d %s ", take, inL->summary().latin1()); 1029 //qDebug("take %d %s ", take, inL->summary().latin1());
1030 if ( take == 3 ) 1030 if ( take == 3 )
1031 return false; 1031 return false;
1032 if ( take == 1 ) {// take local 1032 if ( take == 1 ) {// take local
1033 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1033 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1034 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1034 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1035 else 1035 else
1036 idS = inR->IDStr(); 1036 idS = inR->IDStr();
1037 remote->deleteIncidence( inR ); 1037 remote->deleteIncidence( inR );
1038 if ( inL->revision() < maxrev ) 1038 if ( inL->revision() < maxrev )
1039 inL->setRevision( maxrev ); 1039 inL->setRevision( maxrev );
1040 inR = inL->clone(); 1040 inR = inL->clone();
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1041 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1042 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1042 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1043 inR->setIDStr( idS ); 1043 inR->setIDStr( idS );
1044 remote->addIncidence( inR ); 1044 remote->addIncidence( inR );
1045 ++changedRemote; 1045 ++changedRemote;
1046 } else { 1046 } else {
1047 if ( inR->revision() < maxrev ) 1047 if ( inR->revision() < maxrev )
1048 inR->setRevision( maxrev ); 1048 inR->setRevision( maxrev );
1049 idS = inL->IDStr(); 1049 idS = inL->IDStr();
1050 local->deleteIncidence( inL ); 1050 local->deleteIncidence( inL );
1051 inL = inR->clone(); 1051 inL = inR->clone();
1052 inL->setIDStr( idS ); 1052 inL->setIDStr( idS );
1053 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1053 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1054 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1054 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1055 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1055 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1056 } 1056 }
1057 local->addIncidence( inL ); 1057 local->addIncidence( inL );
1058 ++changedLocal; 1058 ++changedLocal;
1059 } 1059 }
1060 } 1060 }
1061 } else { // no conflict 1061 } else { // no conflict
1062 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1062 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1063 QString des = eventLSync->description(); 1063 QString des = eventLSync->description();
1064 QString pref = "e"; 1064 QString pref = "e";
1065 if ( inR->type() == "Todo" ) 1065 if ( inR->type() == "Todo" )
1066 pref = "t"; 1066 pref = "t";
1067 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1067 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1068 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1068 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1069 //remote->deleteIncidence( inR ); 1069 //remote->deleteIncidence( inR );
1070 ++deletedEventR; 1070 ++deletedEventR;
1071 } else { 1071 } else {
1072 inR->setLastModified( modifiedCalendar ); 1072 inR->setLastModified( modifiedCalendar );
1073 inL = inR->clone(); 1073 inL = inR->clone();
1074 local->addIncidence( inL ); 1074 local->addIncidence( inL );
1075 ++addedEvent; 1075 ++addedEvent;
1076 } 1076 }
1077 } else { 1077 } else {
1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1079 inR->setLastModified( modifiedCalendar ); 1079 inR->setLastModified( modifiedCalendar );
1080 local->addIncidence( inR->clone() ); 1080 local->addIncidence( inR->clone() );
1081 ++addedEvent; 1081 ++addedEvent;
1082 } else { 1082 } else {
1083 checkExternSyncEvent(eventRSyncSharp, inR); 1083 checkExternSyncEvent(eventRSyncSharp, inR);
1084 remote->deleteIncidence( inR ); 1084 remote->deleteIncidence( inR );
1085 ++deletedEventR; 1085 ++deletedEventR;
1086 } 1086 }
1087 } 1087 }
1088 } 1088 }
1089 } 1089 }
1090 inR = er.next(); 1090 inR = er.next();
1091 } 1091 }
1092 QPtrList<Incidence> el = local->rawIncidences(); 1092 QPtrList<Incidence> el = local->rawIncidences();
1093 inL = el.first(); 1093 inL = el.first();
1094 modulo = (el.count()/10)+1; 1094 modulo = (el.count()/10)+1;
1095 bar.setCaption (i18n("Add / remove events") ); 1095 bar.setCaption (i18n("Add / remove events") );
1096 bar.setTotalSteps ( el.count() ) ; 1096 bar.setTotalSteps ( el.count() ) ;
1097 bar.show(); 1097 bar.show();
1098 incCounter = 0; 1098 incCounter = 0;
1099 1099
1100 while ( inL ) { 1100 while ( inL ) {
1101 1101
1102 qApp->processEvents(); 1102 qApp->processEvents();
1103 if ( ! bar.isVisible() ) 1103 if ( ! bar.isVisible() )
1104 return false; 1104 return false;
1105 if ( incCounter % modulo == 0 ) 1105 if ( incCounter % modulo == 0 )
1106 bar.setProgress( incCounter ); 1106 bar.setProgress( incCounter );
1107 ++incCounter; 1107 ++incCounter;
1108 uid = inL->uid(); 1108 uid = inL->uid();
1109 bool skipIncidence = false; 1109 bool skipIncidence = false;
1110 if ( uid.left(15) == QString("last-syncEvent-") ) 1110 if ( uid.left(15) == QString("last-syncEvent-") )
1111 skipIncidence = true; 1111 skipIncidence = true;
1112 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1112 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1113 skipIncidence = true; 1113 skipIncidence = true;
1114 if ( !skipIncidence ) { 1114 if ( !skipIncidence ) {
1115 inR = remote->incidence( uid ); 1115 inR = remote->incidence( uid );
1116 if ( ! inR ) { 1116 if ( ! inR ) {
1117 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1117 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1118 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1118 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1119 checkExternSyncEvent(eventLSyncSharp, inL); 1119 checkExternSyncEvent(eventLSyncSharp, inL);
1120 local->deleteIncidence( inL ); 1120 local->deleteIncidence( inL );
1121 ++deletedEventL; 1121 ++deletedEventL;
1122 } else { 1122 } else {
1123 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1123 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1124 inL->removeID(mCurrentSyncDevice ); 1124 inL->removeID(mCurrentSyncDevice );
1125 ++addedEventR; 1125 ++addedEventR;
1126 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1126 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1127 inL->setLastModified( modifiedCalendar ); 1127 inL->setLastModified( modifiedCalendar );
1128 inR = inL->clone(); 1128 inR = inL->clone();
1129 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1129 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1130 remote->addIncidence( inR ); 1130 remote->addIncidence( inR );
1131 } 1131 }
1132 } 1132 }
1133 } else { 1133 } else {
1134 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1134 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1135 checkExternSyncEvent(eventLSyncSharp, inL); 1135 checkExternSyncEvent(eventLSyncSharp, inL);
1136 local->deleteIncidence( inL ); 1136 local->deleteIncidence( inL );
1137 ++deletedEventL; 1137 ++deletedEventL;
1138 } else { 1138 } else {
1139 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1139 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1140 ++addedEventR; 1140 ++addedEventR;
1141 inL->setLastModified( modifiedCalendar ); 1141 inL->setLastModified( modifiedCalendar );
1142 remote->addIncidence( inL->clone() ); 1142 remote->addIncidence( inL->clone() );
1143 } 1143 }
1144 } 1144 }
1145 } 1145 }
1146 } 1146 }
1147 } 1147 }
1148 inL = el.next(); 1148 inL = el.next();
1149 } 1149 }
1150 int delFut = 0; 1150 int delFut = 0;
1151 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1151 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1152 er = remote->rawIncidences(); 1152 er = remote->rawIncidences();
1153 inR = er.first(); 1153 inR = er.first();
1154 QDateTime dt; 1154 QDateTime dt;
1155 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1155 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1156 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); 1156 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 );
1157 while ( inR ) { 1157 while ( inR ) {
1158 if ( inR->type() == "Todo" ) { 1158 if ( inR->type() == "Todo" ) {
1159 Todo * t = (Todo*)inR; 1159 Todo * t = (Todo*)inR;
1160 if ( t->hasDueDate() ) 1160 if ( t->hasDueDate() )
1161 dt = t->dtDue(); 1161 dt = t->dtDue();
1162 else 1162 else
1163 dt = cur.addSecs( 62 ); 1163 dt = cur.addSecs( 62 );
1164 } 1164 }
1165 else if (inR->type() == "Event" ) { 1165 else if (inR->type() == "Event" ) {
1166 bool ok; 1166 bool ok;
1167 dt = inR->getNextOccurence( cur, &ok ); 1167 dt = inR->getNextOccurence( cur, &ok );
1168 if ( !ok ) 1168 if ( !ok )
1169 dt = cur.addSecs( -62 ); 1169 dt = cur.addSecs( -62 );
1170 } 1170 }
1171 else 1171 else
1172 dt = inR->dtStart(); 1172 dt = inR->dtStart();
1173 if ( dt < cur || dt > end ) { 1173 if ( dt < cur || dt > end ) {
1174 remote->deleteIncidence( inR ); 1174 remote->deleteIncidence( inR );
1175 ++delFut; 1175 ++delFut;
1176 } 1176 }
1177 inR = er.next(); 1177 inR = er.next();
1178 } 1178 }
1179 } 1179 }
1180 bar.hide(); 1180 bar.hide();
1181 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1181 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1182 eventLSync->setReadOnly( false ); 1182 eventLSync->setReadOnly( false );
1183 eventLSync->setDtStart( mLastCalendarSync ); 1183 eventLSync->setDtStart( mLastCalendarSync );
1184 eventRSync->setDtStart( mLastCalendarSync ); 1184 eventRSync->setDtStart( mLastCalendarSync );
1185 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1185 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1186 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1186 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1187 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1187 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1188 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1188 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1189 eventLSync->setReadOnly( true ); 1189 eventLSync->setReadOnly( true );
1190 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1190 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1191 remote->addEvent( eventRSync ); 1191 remote->addEvent( eventRSync );
1192 QString mes; 1192 QString mes;
1193 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1193 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1194 QString delmess; 1194 QString delmess;
1195 if ( delFut ) { 1195 if ( delFut ) {
1196 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1196 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1197 mes += delmess; 1197 mes += delmess;
1198 } 1198 }
1199 if ( KOPrefs::instance()->mShowSyncSummary ) { 1199 if ( KOPrefs::instance()->mShowSyncSummary ) {
1200 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1200 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1201 } 1201 }
1202 qDebug( mes ); 1202 qDebug( mes );
1203 mCalendar->checkAlarmForIncidence( 0, true ); 1203 mCalendar->checkAlarmForIncidence( 0, true );
1204 return syncOK; 1204 return syncOK;
1205} 1205}
1206 1206
1207void CalendarView::setSyncDevice( QString s ) 1207void CalendarView::setSyncDevice( QString s )
1208{ 1208{
1209 mCurrentSyncDevice= s; 1209 mCurrentSyncDevice= s;
1210} 1210}
1211void CalendarView::setSyncName( QString s ) 1211void CalendarView::setSyncName( QString s )
1212{ 1212{
1213 mCurrentSyncName= s; 1213 mCurrentSyncName= s;
1214} 1214}
1215bool CalendarView::syncCalendar(QString filename, int mode) 1215bool CalendarView::syncCalendar(QString filename, int mode)
1216{ 1216{
1217 mGlobalSyncMode = SYNC_MODE_NORMAL; 1217 mGlobalSyncMode = SYNC_MODE_NORMAL;
1218 CalendarLocal* calendar = new CalendarLocal(); 1218 CalendarLocal* calendar = new CalendarLocal();
1219 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1219 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1220 FileStorage* storage = new FileStorage( calendar ); 1220 FileStorage* storage = new FileStorage( calendar );
1221 bool syncOK = false; 1221 bool syncOK = false;
1222 storage->setFileName( filename ); 1222 storage->setFileName( filename );
1223 // qDebug("loading ... "); 1223 // qDebug("loading ... ");
1224 if ( storage->load() ) { 1224 if ( storage->load() ) {
1225 getEventViewerDialog()->setSyncMode( true ); 1225 getEventViewerDialog()->setSyncMode( true );
1226 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1226 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1227 getEventViewerDialog()->setSyncMode( false ); 1227 getEventViewerDialog()->setSyncMode( false );
1228 if ( syncOK ) { 1228 if ( syncOK ) {
1229 if ( KOPrefs::instance()->mWriteBackFile ) 1229 if ( KOPrefs::instance()->mWriteBackFile )
1230 { 1230 {
1231 storage->setSaveFormat( new ICalFormat() ); 1231 storage->setSaveFormat( new ICalFormat() );
1232 storage->save(); 1232 storage->save();
1233 } 1233 }
1234 } 1234 }
1235 setModified( true ); 1235 setModified( true );
1236 } 1236 }
1237 delete storage; 1237 delete storage;
1238 delete calendar; 1238 delete calendar;
1239 if ( syncOK ) 1239 if ( syncOK )
1240 updateView(); 1240 updateView();
1241 return syncOK; 1241 return syncOK;
1242} 1242}
1243void CalendarView::syncPhone() 1243void CalendarView::syncPhone()
1244{ 1244{
1245 syncExternal( 1 ); 1245 syncExternal( 1 );
1246} 1246}
1247void CalendarView::syncExternal( int mode ) 1247void CalendarView::syncExternal( int mode )
1248{ 1248{
1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1250 //mCurrentSyncDevice = "sharp-DTM"; 1250 //mCurrentSyncDevice = "sharp-DTM";
1251 if ( KOPrefs::instance()->mAskForPreferences ) 1251 if ( KOPrefs::instance()->mAskForPreferences )
1252 edit_sync_options(); 1252 edit_sync_options();
1253 qApp->processEvents(); 1253 qApp->processEvents();
1254 CalendarLocal* calendar = new CalendarLocal(); 1254 CalendarLocal* calendar = new CalendarLocal();
1255 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1255 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1256 bool syncOK = false; 1256 bool syncOK = false;
1257 bool loadSuccess = false; 1257 bool loadSuccess = false;
1258 PhoneFormat* phoneFormat = 0; 1258 PhoneFormat* phoneFormat = 0;
1259#ifndef DESKTOP_VERSION 1259#ifndef DESKTOP_VERSION
1260 SharpFormat* sharpFormat = 0; 1260 SharpFormat* sharpFormat = 0;
1261 if ( mode == 0 ) { // sharp 1261 if ( mode == 0 ) { // sharp
1262 sharpFormat = new SharpFormat () ; 1262 sharpFormat = new SharpFormat () ;
1263 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1263 loadSuccess = sharpFormat->load( calendar, mCalendar );
1264 1264
1265 } else 1265 } else
1266#endif 1266#endif
1267 if ( mode == 1 ) { // phone 1267 if ( mode == 1 ) { // phone
1268 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1268 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1269 KOPrefs::instance()->mPhoneDevice, 1269 KOPrefs::instance()->mPhoneDevice,
1270 KOPrefs::instance()->mPhoneConnection, 1270 KOPrefs::instance()->mPhoneConnection,
1271 KOPrefs::instance()->mPhoneModel); 1271 KOPrefs::instance()->mPhoneModel);
1272 loadSuccess = phoneFormat->load( calendar,mCalendar); 1272 loadSuccess = phoneFormat->load( calendar,mCalendar);
1273 1273
1274 } else 1274 } else
1275 return; 1275 return;
1276 if ( loadSuccess ) { 1276 if ( loadSuccess ) {
1277 getEventViewerDialog()->setSyncMode( true ); 1277 getEventViewerDialog()->setSyncMode( true );
1278 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1278 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1279 getEventViewerDialog()->setSyncMode( false ); 1279 getEventViewerDialog()->setSyncMode( false );
1280 qApp->processEvents(); 1280 qApp->processEvents();
1281 if ( syncOK ) { 1281 if ( syncOK ) {
1282 if ( KOPrefs::instance()->mWriteBackFile ) 1282 if ( KOPrefs::instance()->mWriteBackFile )
1283 { 1283 {
1284 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1284 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1285 Incidence* inc = iL.first(); 1285 Incidence* inc = iL.first();
1286 if ( phoneFormat ) { 1286 if ( phoneFormat ) {
1287 while ( inc ) { 1287 while ( inc ) {
1288 inc->removeID(mCurrentSyncDevice); 1288 inc->removeID(mCurrentSyncDevice);
1289 inc = iL.next(); 1289 inc = iL.next();
1290 } 1290 }
1291 } 1291 }
1292#ifndef DESKTOP_VERSION 1292#ifndef DESKTOP_VERSION
1293 if ( sharpFormat ) 1293 if ( sharpFormat )
1294 sharpFormat->save(calendar); 1294 sharpFormat->save(calendar);
1295#endif 1295#endif
1296 if ( phoneFormat ) 1296 if ( phoneFormat )
1297 phoneFormat->save(calendar); 1297 phoneFormat->save(calendar);
1298 iL = calendar->rawIncidences(); 1298 iL = calendar->rawIncidences();
1299 inc = iL.first(); 1299 inc = iL.first();
1300 Incidence* loc; 1300 Incidence* loc;
1301 while ( inc ) { 1301 while ( inc ) {
1302 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1302 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1303 loc = mCalendar->incidence(inc->uid() ); 1303 loc = mCalendar->incidence(inc->uid() );
1304 if ( loc ) { 1304 if ( loc ) {
1305 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1305 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1306 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1306 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1307 } 1307 }
1308 } 1308 }
1309 inc = iL.next(); 1309 inc = iL.next();
1310 } 1310 }
1311 Incidence* lse = getLastSyncEvent(); 1311 Incidence* lse = getLastSyncEvent();
1312 if ( lse ) { 1312 if ( lse ) {
1313 lse->setReadOnly( false ); 1313 lse->setReadOnly( false );
1314 lse->setDescription( "" ); 1314 lse->setDescription( "" );
1315 lse->setReadOnly( true ); 1315 lse->setReadOnly( true );
1316 } 1316 }
1317 } 1317 }
1318 } 1318 }
1319 setModified( true ); 1319 setModified( true );
1320 } else { 1320 } else {
1321 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1321 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1322 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1322 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1323 question, i18n("Ok")) ; 1323 question, i18n("Ok")) ;
1324 1324
1325 } 1325 }
1326 delete calendar; 1326 delete calendar;
1327 updateView(); 1327 updateView();
1328 return ;//syncOK; 1328 return ;//syncOK;
1329 1329
1330} 1330}
1331void CalendarView::syncSharp() 1331void CalendarView::syncSharp()
1332{ 1332{
1333 syncExternal( 0 ); 1333 syncExternal( 0 );
1334 1334
1335} 1335}
1336 1336
1337 1337
1338//#include <kabc/stdaddressbook.h> 1338//#include <kabc/stdaddressbook.h>
1339bool CalendarView::importBday() 1339bool CalendarView::importBday()
1340{ 1340{
1341#if 0 1341#if 0
1342 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1342 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1343 KABC::AddressBook::Iterator it; 1343 KABC::AddressBook::Iterator it;
1344 int count = 0; 1344 int count = 0;
1345 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1345 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1346 ++count; 1346 ++count;
1347 } 1347 }
1348 QProgressBar bar(count,0 ); 1348 QProgressBar bar(count,0 );
1349 int w = 300; 1349 int w = 300;
1350 if ( QApplication::desktop()->width() < 320 ) 1350 if ( QApplication::desktop()->width() < 320 )
1351 w = 220; 1351 w = 220;
1352 int h = bar.sizeHint().height() ; 1352 int h = bar.sizeHint().height() ;
1353 int dw = QApplication::desktop()->width(); 1353 int dw = QApplication::desktop()->width();
1354 int dh = QApplication::desktop()->height(); 1354 int dh = QApplication::desktop()->height();
1355 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1355 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1356 bar.show(); 1356 bar.show();
1357 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1357 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1358 qApp->processEvents(); 1358 qApp->processEvents();
1359 count = 0; 1359 count = 0;
1360 int addCount = 0; 1360 int addCount = 0;
1361 KCal::Attendee* a = 0; 1361 KCal::Attendee* a = 0;
1362 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1362 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1363 if ( ! bar.isVisible() ) 1363 if ( ! bar.isVisible() )
1364 return false; 1364 return false;
1365 bar.setProgress( count++ ); 1365 bar.setProgress( count++ );
1366 qApp->processEvents(); 1366 qApp->processEvents();
1367 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1367 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1368 if ( (*it).birthday().date().isValid() ){ 1368 if ( (*it).birthday().date().isValid() ){
1369 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1369 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1370 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1370 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1371 ++addCount; 1371 ++addCount;
1372 } 1372 }
1373 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1373 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1374 if ( anni.isValid() ){ 1374 if ( anni.isValid() ){
1375 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1375 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1376 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1376 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1377 ++addCount; 1377 ++addCount;
1378 } 1378 }
1379 } 1379 }
1380 updateView(); 1380 updateView();
1381 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1381 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1382#endif 1382#endif
1383 return true; 1383 return true;
1384} 1384}
1385 1385
1386bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1386bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1387{ 1387{
1388 //qDebug("addAnni "); 1388 //qDebug("addAnni ");
1389 Event * ev = new Event(); 1389 Event * ev = new Event();
1390 if ( a ) { 1390 if ( a ) {
1391 ev->addAttendee( a ); 1391 ev->addAttendee( a );
1392 } 1392 }
1393 QString kind; 1393 QString kind;
1394 if ( birthday ) 1394 if ( birthday )
1395 kind = i18n( "Birthday" ); 1395 kind = i18n( "Birthday" );
1396 else 1396 else
1397 kind = i18n( "Anniversary" ); 1397 kind = i18n( "Anniversary" );
1398 ev->setSummary( name + " - " + kind ); 1398 ev->setSummary( name + " - " + kind );
1399 ev->setOrganizer( "nobody@nowhere" ); 1399 ev->setOrganizer( "nobody@nowhere" );
1400 ev->setCategories( kind ); 1400 ev->setCategories( kind );
1401 ev->setDtStart( QDateTime(date) ); 1401 ev->setDtStart( QDateTime(date) );
1402 ev->setDtEnd( QDateTime(date) ); 1402 ev->setDtEnd( QDateTime(date) );
1403 ev->setFloats( true ); 1403 ev->setFloats( true );
1404 Recurrence * rec = ev->recurrence(); 1404 Recurrence * rec = ev->recurrence();
1405 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1405 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1406 rec->addYearlyNum( date.month() ); 1406 rec->addYearlyNum( date.month() );
1407 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1407 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1408 delete ev; 1408 delete ev;
1409 return false; 1409 return false;
1410 } 1410 }
1411 return true; 1411 return true;
1412 1412
1413} 1413}
1414bool CalendarView::importQtopia( const QString &categories, 1414bool CalendarView::importQtopia( const QString &categories,
1415 const QString &datebook, 1415 const QString &datebook,
1416 const QString &todolist ) 1416 const QString &todolist )
1417{ 1417{
1418 1418
1419 QtopiaFormat qtopiaFormat; 1419 QtopiaFormat qtopiaFormat;
1420 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1420 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1421 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1421 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1422 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1422 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1423 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1423 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1424 1424
1425 updateView(); 1425 updateView();
1426 return true; 1426 return true;
1427 1427
1428#if 0 1428#if 0
1429 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1429 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1430 mCurrentSyncDevice = "qtopia-XML"; 1430 mCurrentSyncDevice = "qtopia-XML";
1431 if ( KOPrefs::instance()->mAskForPreferences ) 1431 if ( KOPrefs::instance()->mAskForPreferences )
1432 edit_sync_options(); 1432 edit_sync_options();
1433 qApp->processEvents(); 1433 qApp->processEvents();
1434 CalendarLocal* calendar = new CalendarLocal(); 1434 CalendarLocal* calendar = new CalendarLocal();
1435 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1435 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1436 bool syncOK = false; 1436 bool syncOK = false;
1437 QtopiaFormat qtopiaFormat; 1437 QtopiaFormat qtopiaFormat;
1438 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1438 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1439 bool loadOk = true; 1439 bool loadOk = true;
1440 if ( !categories.isEmpty() ) 1440 if ( !categories.isEmpty() )
1441 loadOk = qtopiaFormat.load( calendar, categories ); 1441 loadOk = qtopiaFormat.load( calendar, categories );
1442 if ( loadOk && !datebook.isEmpty() ) 1442 if ( loadOk && !datebook.isEmpty() )
1443 loadOk = qtopiaFormat.load( calendar, datebook ); 1443 loadOk = qtopiaFormat.load( calendar, datebook );
1444 if ( loadOk && !todolist.isEmpty() ) 1444 if ( loadOk && !todolist.isEmpty() )
1445 loadOk = qtopiaFormat.load( calendar, todolist ); 1445 loadOk = qtopiaFormat.load( calendar, todolist );
1446 1446
1447 if ( loadOk ) { 1447 if ( loadOk ) {
1448 getEventViewerDialog()->setSyncMode( true ); 1448 getEventViewerDialog()->setSyncMode( true );
1449 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1449 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1450 getEventViewerDialog()->setSyncMode( false ); 1450 getEventViewerDialog()->setSyncMode( false );
1451 qApp->processEvents(); 1451 qApp->processEvents();
1452 if ( syncOK ) { 1452 if ( syncOK ) {
1453 if ( KOPrefs::instance()->mWriteBackFile ) 1453 if ( KOPrefs::instance()->mWriteBackFile )
1454 { 1454 {
1455 // write back XML file 1455 // write back XML file
1456 1456
1457 } 1457 }
1458 setModified( true ); 1458 setModified( true );
1459 } 1459 }
1460 } else { 1460 } else {
1461 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1461 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1462 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1462 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1463 question, i18n("Ok")) ; 1463 question, i18n("Ok")) ;
1464 } 1464 }
1465 delete calendar; 1465 delete calendar;
1466 updateView(); 1466 updateView();
1467 return syncOK; 1467 return syncOK;
1468 1468
1469 1469
1470#endif 1470#endif
1471 1471
1472} 1472}
1473 1473
1474void CalendarView::setSyncEventsReadOnly() 1474void CalendarView::setSyncEventsReadOnly()
1475{ 1475{
1476 Event * ev; 1476 Event * ev;
1477 QPtrList<Event> eL = mCalendar->rawEvents(); 1477 QPtrList<Event> eL = mCalendar->rawEvents();
1478 ev = eL.first(); 1478 ev = eL.first();
1479 while ( ev ) { 1479 while ( ev ) {
1480 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1480 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1481 ev->setReadOnly( true ); 1481 ev->setReadOnly( true );
1482 ev = eL.next(); 1482 ev = eL.next();
1483 } 1483 }
1484} 1484}
1485bool CalendarView::openCalendar(QString filename, bool merge) 1485bool CalendarView::openCalendar(QString filename, bool merge)
1486{ 1486{
1487 1487
1488 if (filename.isEmpty()) { 1488 if (filename.isEmpty()) {
1489 return false; 1489 return false;
1490 } 1490 }
1491 1491
1492 if (!QFile::exists(filename)) { 1492 if (!QFile::exists(filename)) {
1493 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1493 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1494 return false; 1494 return false;
1495 } 1495 }
1496 1496
1497 globalFlagBlockAgenda = 1; 1497 globalFlagBlockAgenda = 1;
1498 if (!merge) mCalendar->close(); 1498 if (!merge) mCalendar->close();
1499 1499
1500 mStorage->setFileName( filename ); 1500 mStorage->setFileName( filename );
1501 1501
1502 if ( mStorage->load() ) { 1502 if ( mStorage->load() ) {
1503 if ( merge ) ;//setModified( true ); 1503 if ( merge ) ;//setModified( true );
1504 else { 1504 else {
1505 //setModified( true ); 1505 //setModified( true );
1506 mViewManager->setDocumentId( filename ); 1506 mViewManager->setDocumentId( filename );
1507 mDialogManager->setDocumentId( filename ); 1507 mDialogManager->setDocumentId( filename );
1508 mTodoList->setDocumentId( filename ); 1508 mTodoList->setDocumentId( filename );
1509 } 1509 }
1510 globalFlagBlockAgenda = 2; 1510 globalFlagBlockAgenda = 2;
1511 // if ( getLastSyncEvent() ) 1511 // if ( getLastSyncEvent() )
1512 // getLastSyncEvent()->setReadOnly( true ); 1512 // getLastSyncEvent()->setReadOnly( true );
1513 mCalendar->reInitAlarmSettings(); 1513 mCalendar->reInitAlarmSettings();
1514 setSyncEventsReadOnly(); 1514 setSyncEventsReadOnly();
1515 updateUnmanagedViews(); 1515 updateUnmanagedViews();
1516 updateView(); 1516 updateView();
1517 loadedFileVersion = QDateTime::currentDateTime(); 1517 setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 ));
1518 if ( filename != MainWindow::defaultFileName() ) { 1518 if ( filename != MainWindow::defaultFileName() ) {
1519 saveCalendar( MainWindow::defaultFileName() ); 1519 saveCalendar( MainWindow::defaultFileName() );
1520 watchSavedFile(); 1520 watchSavedFile();
1521 } 1521 }
1522 return true; 1522 return true;
1523 } else { 1523 } else {
1524 // while failing to load, the calendar object could 1524 // while failing to load, the calendar object could
1525 // have become partially populated. Clear it out. 1525 // have become partially populated. Clear it out.
1526 if ( !merge ) { 1526 if ( !merge ) {
1527 mCalendar->close(); 1527 mCalendar->close();
1528 mViewManager->setDocumentId( filename ); 1528 mViewManager->setDocumentId( filename );
1529 mDialogManager->setDocumentId( filename ); 1529 mDialogManager->setDocumentId( filename );
1530 mTodoList->setDocumentId( filename ); 1530 mTodoList->setDocumentId( filename );
1531 } 1531 }
1532 1532
1533 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1533 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1534 1534
1535 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1535 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1536 globalFlagBlockAgenda = 2; 1536 globalFlagBlockAgenda = 2;
1537 mCalendar->reInitAlarmSettings(); 1537 mCalendar->reInitAlarmSettings();
1538 setSyncEventsReadOnly(); 1538 setSyncEventsReadOnly();
1539 updateUnmanagedViews(); 1539 updateUnmanagedViews();
1540 updateView(); 1540 updateView();
1541 } 1541 }
1542 return false; 1542 return false;
1543} 1543}
1544void CalendarView::showOpenError() 1544void CalendarView::showOpenError()
1545{ 1545{
1546 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1546 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1547} 1547}
1548void CalendarView::setLoadedFileVersion(QDateTime dt) 1548void CalendarView::setLoadedFileVersion(QDateTime dt)
1549{ 1549{
1550 loadedFileVersion = dt; 1550 loadedFileVersion = dt;
1551} 1551}
1552bool CalendarView::checkFileChanged(QString fn) 1552bool CalendarView::checkFileChanged(QString fn)
1553{ 1553{
1554 QFileInfo finf ( fn ); 1554 QFileInfo finf ( fn );
1555 if ( !finf.exists() ) 1555 if ( !finf.exists() )
1556 return true; 1556 return true;
1557 QDateTime dt = finf.lastModified (); 1557 QDateTime dt = finf.lastModified ();
1558 if ( dt <= loadedFileVersion ) 1558 if ( dt <= loadedFileVersion )
1559 return false; 1559 return false;
1560 return true; 1560 return true;
1561 1561
1562} 1562}
1563void CalendarView::watchSavedFile() 1563void CalendarView::watchSavedFile()
1564{ 1564{
1565 QFileInfo finf ( MainWindow::defaultFileName()); 1565 QFileInfo finf ( MainWindow::defaultFileName());
1566 if ( !finf.exists() ) 1566 if ( !finf.exists() )
1567 return; 1567 return;
1568 QDateTime dt = finf.lastModified (); 1568 QDateTime dt = finf.lastModified ();
1569 if ( dt < loadedFileVersion ) { 1569 if ( dt < loadedFileVersion ) {
1570 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1570 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1571 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1571 return; 1572 return;
1572 } 1573 }
1573 loadedFileVersion = dt; 1574 loadedFileVersion = dt;
1574} 1575}
1575 1576
1576bool CalendarView::checkFileVersion(QString fn) 1577bool CalendarView::checkFileVersion(QString fn)
1577{ 1578{
1578 QFileInfo finf ( fn ); 1579 QFileInfo finf ( fn );
1579 if ( !finf.exists() ) 1580 if ( !finf.exists() )
1580 return true; 1581 return true;
1581 QDateTime dt = finf.lastModified (); 1582 QDateTime dt = finf.lastModified ();
1582 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1583 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1583 //qDebug("file on disk version %s",dt.toString().latin1()); 1584 //qDebug("file on disk version %s",dt.toString().latin1());
1584 if ( dt <= loadedFileVersion ) 1585 if ( dt <= loadedFileVersion )
1585 return true; 1586 return true;
1586 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1587 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1587 i18n("KO/Pi Warning"),i18n("Overwrite"), 1588 i18n("KO/Pi Warning"),i18n("Overwrite"),
1588 i18n("Sync+save")); 1589 i18n("Sync+save"));
1589 1590
1590 if ( km == KMessageBox::Cancel ) 1591 if ( km == KMessageBox::Cancel )
1591 return false; 1592 return false;
1592 if ( km == KMessageBox::Yes ) 1593 if ( km == KMessageBox::Yes )
1593 return true; 1594 return true;
1594 1595
1595 setSyncDevice("deleteaftersync" ); 1596 setSyncDevice("deleteaftersync" );
1596 KOPrefs::instance()->mAskForPreferences = true; 1597 KOPrefs::instance()->mAskForPreferences = true;
1597 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1598 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1598 KOPrefs::instance()->mWriteBackFile = false; 1599 KOPrefs::instance()->mWriteBackFile = false;
1599 KOPrefs::instance()->mWriteBackExistingOnly = false; 1600 KOPrefs::instance()->mWriteBackExistingOnly = false;
1600 KOPrefs::instance()->mShowSyncSummary = false; 1601 KOPrefs::instance()->mShowSyncSummary = false;
1601 syncCalendar( fn, 3 ); 1602 syncCalendar( fn, 3 );
1602 Event * e = getLastSyncEvent(); 1603 Event * e = getLastSyncEvent();
1603 mCalendar->deleteEvent ( e ); 1604 mCalendar->deleteEvent ( e );
1604 updateView(); 1605 updateView();
1605 return true; 1606 return true;
1606} 1607}
1607 1608
1608bool CalendarView::saveCalendar( QString filename ) 1609bool CalendarView::saveCalendar( QString filename )
1609{ 1610{
1610 1611
1611 // Store back all unsaved data into calendar object 1612 // Store back all unsaved data into calendar object
1612 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1613 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1613 if ( mViewManager->currentView() ) 1614 if ( mViewManager->currentView() )
1614 mViewManager->currentView()->flushView(); 1615 mViewManager->currentView()->flushView();
1615 1616
1616 //mStorage->setFileName( filename ); 1617 //mStorage->setFileName( filename );
1617 1618
1618 mStorage->setSaveFormat( new ICalFormat() ); 1619 mStorage->setSaveFormat( new ICalFormat() );
1619 mStorage->setFileName( filename ); 1620 mStorage->setFileName( filename );
1620 bool success; 1621 bool success;
1621 success = mStorage->save(); 1622 success = mStorage->save();
1622 if ( !success ) { 1623 if ( !success ) {
1623 return false; 1624 return false;
1624 } 1625 }
1625 1626
1626 return true; 1627 return true;
1627} 1628}
1628 1629
1629void CalendarView::closeCalendar() 1630void CalendarView::closeCalendar()
1630{ 1631{
1631 1632
1632 // child windows no longer valid 1633 // child windows no longer valid
1633 emit closingDown(); 1634 emit closingDown();
1634 1635
1635 mCalendar->close(); 1636 mCalendar->close();
1636 setModified(false); 1637 setModified(false);
1637 updateView(); 1638 updateView();
1638} 1639}
1639 1640
1640void CalendarView::archiveCalendar() 1641void CalendarView::archiveCalendar()
1641{ 1642{
1642 mDialogManager->showArchiveDialog(); 1643 mDialogManager->showArchiveDialog();
1643} 1644}
1644 1645
1645 1646
1646void CalendarView::readSettings() 1647void CalendarView::readSettings()
1647{ 1648{
1648 1649
1649 1650
1650 // mViewManager->showAgendaView(); 1651 // mViewManager->showAgendaView();
1651 QString str; 1652 QString str;
1652 //qDebug("CalendarView::readSettings() "); 1653 //qDebug("CalendarView::readSettings() ");
1653 // read settings from the KConfig, supplying reasonable 1654 // read settings from the KConfig, supplying reasonable
1654 // defaults where none are to be found 1655 // defaults where none are to be found
1655 KConfig *config = KOGlobals::config(); 1656 KConfig *config = KOGlobals::config();
1656#ifndef KORG_NOSPLITTER 1657#ifndef KORG_NOSPLITTER
1657 config->setGroup("KOrganizer Geometry"); 1658 config->setGroup("KOrganizer Geometry");
1658 1659
1659 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1660 QValueList<int> sizes = config->readIntListEntry("Separator1");
1660 if (sizes.count() != 2) { 1661 if (sizes.count() != 2) {
1661 sizes << mDateNavigator->minimumSizeHint().width(); 1662 sizes << mDateNavigator->minimumSizeHint().width();
1662 sizes << 300; 1663 sizes << 300;
1663 } 1664 }
1664 mPanner->setSizes(sizes); 1665 mPanner->setSizes(sizes);
1665 1666
1666 sizes = config->readIntListEntry("Separator2"); 1667 sizes = config->readIntListEntry("Separator2");
1667 if ( ( mResourceView && sizes.count() == 4 ) || 1668 if ( ( mResourceView && sizes.count() == 4 ) ||
1668 ( !mResourceView && sizes.count() == 3 ) ) { 1669 ( !mResourceView && sizes.count() == 3 ) ) {
1669 mLeftSplitter->setSizes(sizes); 1670 mLeftSplitter->setSizes(sizes);
1670 } 1671 }
1671#endif 1672#endif
1672 globalFlagBlockAgenda = 1; 1673 globalFlagBlockAgenda = 1;
1673 mViewManager->showAgendaView(); 1674 mViewManager->showAgendaView();
1674 //mViewManager->readSettings( config ); 1675 //mViewManager->readSettings( config );
1675 mTodoList->restoreLayout(config,QString("Todo Layout")); 1676 mTodoList->restoreLayout(config,QString("Todo Layout"));
1676 readFilterSettings(config); 1677 readFilterSettings(config);
1677 config->setGroup( "Views" ); 1678 config->setGroup( "Views" );
1678 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1679 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1679 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1680 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1680 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1681 else if ( dateCount == 7 ) mNavigator->selectWeek();
1681 else mNavigator->selectDates( dateCount ); 1682 else mNavigator->selectDates( dateCount );
1682 // mViewManager->readSettings( config ); 1683 // mViewManager->readSettings( config );
1683 updateConfig(); 1684 updateConfig();
1684 globalFlagBlockAgenda = 2; 1685 globalFlagBlockAgenda = 2;
1685 mViewManager->readSettings( config ); 1686 mViewManager->readSettings( config );
1686#ifdef DESKTOP_VERSION 1687#ifdef DESKTOP_VERSION
1687 config->setGroup("WidgetLayout"); 1688 config->setGroup("WidgetLayout");
1688 QStringList list; 1689 QStringList list;
1689 list = config->readListEntry("MainLayout"); 1690 list = config->readListEntry("MainLayout");
1690 int x,y,w,h; 1691 int x,y,w,h;
1691 if ( ! list.isEmpty() ) { 1692 if ( ! list.isEmpty() ) {
1692 x = list[0].toInt(); 1693 x = list[0].toInt();
1693 y = list[1].toInt(); 1694 y = list[1].toInt();
1694 w = list[2].toInt(); 1695 w = list[2].toInt();
1695 h = list[3].toInt(); 1696 h = list[3].toInt();
1696 topLevelWidget()->setGeometry(x,y,w,h); 1697 topLevelWidget()->setGeometry(x,y,w,h);
1697 1698
1698 } else { 1699 } else {
1699 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1700 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1700 } 1701 }
1701 list = config->readListEntry("EditEventLayout"); 1702 list = config->readListEntry("EditEventLayout");
1702 if ( ! list.isEmpty() ) { 1703 if ( ! list.isEmpty() ) {
1703 x = list[0].toInt(); 1704 x = list[0].toInt();
1704 y = list[1].toInt(); 1705 y = list[1].toInt();
1705 w = list[2].toInt(); 1706 w = list[2].toInt();
1706 h = list[3].toInt(); 1707 h = list[3].toInt();
1707 mEventEditor->setGeometry(x,y,w,h); 1708 mEventEditor->setGeometry(x,y,w,h);
1708 1709
1709 } 1710 }
1710 list = config->readListEntry("EditTodoLayout"); 1711 list = config->readListEntry("EditTodoLayout");
1711 if ( ! list.isEmpty() ) { 1712 if ( ! list.isEmpty() ) {
1712 x = list[0].toInt(); 1713 x = list[0].toInt();
1713 y = list[1].toInt(); 1714 y = list[1].toInt();
1714 w = list[2].toInt(); 1715 w = list[2].toInt();
1715 h = list[3].toInt(); 1716 h = list[3].toInt();
1716 mTodoEditor->setGeometry(x,y,w,h); 1717 mTodoEditor->setGeometry(x,y,w,h);
1717 1718
1718 } 1719 }
1719 list = config->readListEntry("ViewerLayout"); 1720 list = config->readListEntry("ViewerLayout");
1720 if ( ! list.isEmpty() ) { 1721 if ( ! list.isEmpty() ) {
1721 x = list[0].toInt(); 1722 x = list[0].toInt();
1722 y = list[1].toInt(); 1723 y = list[1].toInt();
1723 w = list[2].toInt(); 1724 w = list[2].toInt();
1724 h = list[3].toInt(); 1725 h = list[3].toInt();
1725 getEventViewerDialog()->setGeometry(x,y,w,h); 1726 getEventViewerDialog()->setGeometry(x,y,w,h);
1726 } 1727 }
1727#endif 1728#endif
1728 1729
1729} 1730}
1730 1731
1731 1732
1732void CalendarView::writeSettings() 1733void CalendarView::writeSettings()
1733{ 1734{
1734 // kdDebug() << "CalendarView::writeSettings" << endl; 1735 // kdDebug() << "CalendarView::writeSettings" << endl;
1735 1736
1736 KConfig *config = KOGlobals::config(); 1737 KConfig *config = KOGlobals::config();
1737 1738
1738#ifndef KORG_NOSPLITTER 1739#ifndef KORG_NOSPLITTER
1739 config->setGroup("KOrganizer Geometry"); 1740 config->setGroup("KOrganizer Geometry");
1740 1741
1741 QValueList<int> list = mPanner->sizes(); 1742 QValueList<int> list = mPanner->sizes();
1742 config->writeEntry("Separator1",list); 1743 config->writeEntry("Separator1",list);
1743 1744
1744 list = mLeftSplitter->sizes(); 1745 list = mLeftSplitter->sizes();
1745 config->writeEntry("Separator2",list); 1746 config->writeEntry("Separator2",list);
1746#endif 1747#endif
1747 1748
1748 mViewManager->writeSettings( config ); 1749 mViewManager->writeSettings( config );
1749 mTodoList->saveLayout(config,QString("Todo Layout")); 1750 mTodoList->saveLayout(config,QString("Todo Layout"));
1750 mDialogManager->writeSettings( config ); 1751 mDialogManager->writeSettings( config );
1751 //KOPrefs::instance()->usrWriteConfig(); 1752 //KOPrefs::instance()->usrWriteConfig();
1752 KOPrefs::instance()->writeConfig(); 1753 KOPrefs::instance()->writeConfig();
1753 1754
1754 writeFilterSettings(config); 1755 writeFilterSettings(config);
1755 1756
1756 config->setGroup( "Views" ); 1757 config->setGroup( "Views" );
1757 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1758 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1758 1759
1759#ifdef DESKTOP_VERSION 1760#ifdef DESKTOP_VERSION
1760 config->setGroup("WidgetLayout"); 1761 config->setGroup("WidgetLayout");
1761 QStringList list ;//= config->readListEntry("MainLayout"); 1762 QStringList list ;//= config->readListEntry("MainLayout");
1762 int x,y,w,h; 1763 int x,y,w,h;
1763 QWidget* wid; 1764 QWidget* wid;
1764 wid = topLevelWidget(); 1765 wid = topLevelWidget();
1765 x = wid->geometry().x(); 1766 x = wid->geometry().x();
1766 y = wid->geometry().y(); 1767 y = wid->geometry().y();
1767 w = wid->width(); 1768 w = wid->width();
1768 h = wid->height(); 1769 h = wid->height();
1769 list.clear(); 1770 list.clear();
1770 list << QString::number( x ); 1771 list << QString::number( x );
1771 list << QString::number( y ); 1772 list << QString::number( y );
1772 list << QString::number( w ); 1773 list << QString::number( w );
1773 list << QString::number( h ); 1774 list << QString::number( h );
1774 config->writeEntry("MainLayout",list ); 1775 config->writeEntry("MainLayout",list );
1775 1776
1776 wid = mEventEditor; 1777 wid = mEventEditor;
1777 x = wid->geometry().x(); 1778 x = wid->geometry().x();
1778 y = wid->geometry().y(); 1779 y = wid->geometry().y();
1779 w = wid->width(); 1780 w = wid->width();
1780 h = wid->height(); 1781 h = wid->height();
1781 list.clear(); 1782 list.clear();
1782 list << QString::number( x ); 1783 list << QString::number( x );
1783 list << QString::number( y ); 1784 list << QString::number( y );
1784 list << QString::number( w ); 1785 list << QString::number( w );
1785 list << QString::number( h ); 1786 list << QString::number( h );
1786 config->writeEntry("EditEventLayout",list ); 1787 config->writeEntry("EditEventLayout",list );
1787 1788
1788 wid = mTodoEditor; 1789 wid = mTodoEditor;
1789 x = wid->geometry().x(); 1790 x = wid->geometry().x();
1790 y = wid->geometry().y(); 1791 y = wid->geometry().y();
1791 w = wid->width(); 1792 w = wid->width();
1792 h = wid->height(); 1793 h = wid->height();
1793 list.clear(); 1794 list.clear();
1794 list << QString::number( x ); 1795 list << QString::number( x );
1795 list << QString::number( y ); 1796 list << QString::number( y );
1796 list << QString::number( w ); 1797 list << QString::number( w );
1797 list << QString::number( h ); 1798 list << QString::number( h );
1798 config->writeEntry("EditTodoLayout",list ); 1799 config->writeEntry("EditTodoLayout",list );
1799 wid = getEventViewerDialog(); 1800 wid = getEventViewerDialog();
1800 x = wid->geometry().x(); 1801 x = wid->geometry().x();
1801 y = wid->geometry().y(); 1802 y = wid->geometry().y();
1802 w = wid->width(); 1803 w = wid->width();
1803 h = wid->height(); 1804 h = wid->height();
1804 list.clear(); 1805 list.clear();
1805 list << QString::number( x ); 1806 list << QString::number( x );
1806 list << QString::number( y ); 1807 list << QString::number( y );
1807 list << QString::number( w ); 1808 list << QString::number( w );
1808 list << QString::number( h ); 1809 list << QString::number( h );
1809 config->writeEntry("ViewerLayout",list ); 1810 config->writeEntry("ViewerLayout",list );
1810 wid = mDialogManager->getSearchDialog(); 1811 wid = mDialogManager->getSearchDialog();
1811 if ( wid ) { 1812 if ( wid ) {
1812 x = wid->geometry().x(); 1813 x = wid->geometry().x();
1813 y = wid->geometry().y(); 1814 y = wid->geometry().y();
1814 w = wid->width(); 1815 w = wid->width();
1815 h = wid->height(); 1816 h = wid->height();
1816 list.clear(); 1817 list.clear();
1817 list << QString::number( x ); 1818 list << QString::number( x );
1818 list << QString::number( y ); 1819 list << QString::number( y );
1819 list << QString::number( w ); 1820 list << QString::number( w );
1820 list << QString::number( h ); 1821 list << QString::number( h );
1821 config->writeEntry("SearchLayout",list ); 1822 config->writeEntry("SearchLayout",list );
1822 } 1823 }
1823#endif 1824#endif
1824 1825
1825 1826
1826 config->sync(); 1827 config->sync();
1827} 1828}
1828 1829
1829void CalendarView::readFilterSettings(KConfig *config) 1830void CalendarView::readFilterSettings(KConfig *config)
1830{ 1831{
1831 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1832 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1832 1833
1833 mFilters.clear(); 1834 mFilters.clear();
1834 1835
1835 config->setGroup("General"); 1836 config->setGroup("General");
1836 QStringList filterList = config->readListEntry("CalendarFilters"); 1837 QStringList filterList = config->readListEntry("CalendarFilters");
1837 1838
1838 QStringList::ConstIterator it = filterList.begin(); 1839 QStringList::ConstIterator it = filterList.begin();
1839 QStringList::ConstIterator end = filterList.end(); 1840 QStringList::ConstIterator end = filterList.end();
1840 while(it != end) { 1841 while(it != end) {
1841 // kdDebug() << " filter: " << (*it) << endl; 1842 // kdDebug() << " filter: " << (*it) << endl;
1842 1843
1843 CalFilter *filter; 1844 CalFilter *filter;
1844 filter = new CalFilter(*it); 1845 filter = new CalFilter(*it);
1845 config->setGroup("Filter_" + (*it)); 1846 config->setGroup("Filter_" + (*it));
1846 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1847 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1847 filter->setCriteria(config->readNumEntry("Criteria",0)); 1848 filter->setCriteria(config->readNumEntry("Criteria",0));
1848 filter->setCategoryList(config->readListEntry("CategoryList")); 1849 filter->setCategoryList(config->readListEntry("CategoryList"));
1849 mFilters.append(filter); 1850 mFilters.append(filter);
1850 1851
1851 ++it; 1852 ++it;
1852 } 1853 }
1853 1854
1854 if (mFilters.count() == 0) { 1855 if (mFilters.count() == 0) {
1855 CalFilter *filter = new CalFilter(i18n("Default")); 1856 CalFilter *filter = new CalFilter(i18n("Default"));
1856 mFilters.append(filter); 1857 mFilters.append(filter);
1857 } 1858 }
1858 mFilterView->updateFilters(); 1859 mFilterView->updateFilters();
1859 config->setGroup("FilterView"); 1860 config->setGroup("FilterView");
1860 1861
1861 mFilterView->blockSignals(true); 1862 mFilterView->blockSignals(true);
1862 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1863 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1863 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1864 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1864 mFilterView->blockSignals(false); 1865 mFilterView->blockSignals(false);
1865 // We do it manually to avoid it being done twice by the above calls 1866 // We do it manually to avoid it being done twice by the above calls
1866 updateFilter(); 1867 updateFilter();
1867} 1868}
1868 1869
1869void CalendarView::writeFilterSettings(KConfig *config) 1870void CalendarView::writeFilterSettings(KConfig *config)
1870{ 1871{
1871 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1872 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1872 1873
1873 QStringList filterList; 1874 QStringList filterList;
1874 1875
1875 CalFilter *filter = mFilters.first(); 1876 CalFilter *filter = mFilters.first();
1876 while(filter) { 1877 while(filter) {
1877 // kdDebug() << " fn: " << filter->name() << endl; 1878 // kdDebug() << " fn: " << filter->name() << endl;
1878 filterList << filter->name(); 1879 filterList << filter->name();
1879 config->setGroup("Filter_" + filter->name()); 1880 config->setGroup("Filter_" + filter->name());
1880 config->writeEntry("Criteria",filter->criteria()); 1881 config->writeEntry("Criteria",filter->criteria());
1881 config->writeEntry("CategoryList",filter->categoryList()); 1882 config->writeEntry("CategoryList",filter->categoryList());
1882 filter = mFilters.next(); 1883 filter = mFilters.next();
1883 } 1884 }
1884 config->setGroup("General"); 1885 config->setGroup("General");
1885 config->writeEntry("CalendarFilters",filterList); 1886 config->writeEntry("CalendarFilters",filterList);
1886 1887
1887 config->setGroup("FilterView"); 1888 config->setGroup("FilterView");
1888 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1889 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1889 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1890 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1890} 1891}
1891 1892
1892 1893
1893void CalendarView::goToday() 1894void CalendarView::goToday()
1894{ 1895{
1895 mNavigator->selectToday(); 1896 mNavigator->selectToday();
1896} 1897}
1897 1898
1898void CalendarView::goNext() 1899void CalendarView::goNext()
1899{ 1900{
1900 mNavigator->selectNext(); 1901 mNavigator->selectNext();
1901} 1902}
1902 1903
1903void CalendarView::goPrevious() 1904void CalendarView::goPrevious()
1904{ 1905{
1905 mNavigator->selectPrevious(); 1906 mNavigator->selectPrevious();
1906} 1907}
1907void CalendarView::goNextMonth() 1908void CalendarView::goNextMonth()
1908{ 1909{
1909 mNavigator->selectNextMonth(); 1910 mNavigator->selectNextMonth();
1910} 1911}
1911 1912
1912void CalendarView::goPreviousMonth() 1913void CalendarView::goPreviousMonth()
1913{ 1914{
1914 mNavigator->selectPreviousMonth(); 1915 mNavigator->selectPreviousMonth();
1915} 1916}
1916void CalendarView::writeLocale() 1917void CalendarView::writeLocale()
1917{ 1918{
1918 //KPimGlobalPrefs::instance()->setGlobalConfig(); 1919 //KPimGlobalPrefs::instance()->setGlobalConfig();
1919#if 0 1920#if 0
1920 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1921 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1921 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1922 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1922 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1923 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1923 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1924 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1924 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1925 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1925 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1926 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1926 dummy = KOPrefs::instance()->mUserDateFormatShort; 1927 dummy = KOPrefs::instance()->mUserDateFormatShort;
1927 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1928 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1928 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1929 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1929 KOPrefs::instance()->mDaylightsavingStart, 1930 KOPrefs::instance()->mDaylightsavingStart,
1930 KOPrefs::instance()->mDaylightsavingEnd ); 1931 KOPrefs::instance()->mDaylightsavingEnd );
1931 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1932 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1932#endif 1933#endif
1933} 1934}
1934void CalendarView::updateConfig() 1935void CalendarView::updateConfig()
1935{ 1936{
1936 writeLocale(); 1937 writeLocale();
1937 if ( KOPrefs::instance()->mUseAppColors ) 1938 if ( KOPrefs::instance()->mUseAppColors )
1938 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1939 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1939 emit configChanged(); 1940 emit configChanged();
1940 mTodoList->updateConfig(); 1941 mTodoList->updateConfig();
1941 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1942 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1942 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1943 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1943 // To make the "fill window" configurations work 1944 // To make the "fill window" configurations work
1944 //mViewManager->raiseCurrentView(); 1945 //mViewManager->raiseCurrentView();
1945} 1946}
1946 1947
1947 1948
1948void CalendarView::eventChanged(Event *event) 1949void CalendarView::eventChanged(Event *event)
1949{ 1950{
1950 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1951 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1951 //updateUnmanagedViews(); 1952 //updateUnmanagedViews();
1952} 1953}
1953 1954
1954void CalendarView::eventAdded(Event *event) 1955void CalendarView::eventAdded(Event *event)
1955{ 1956{
1956 changeEventDisplay(event,KOGlobals::EVENTADDED); 1957 changeEventDisplay(event,KOGlobals::EVENTADDED);
1957} 1958}
1958 1959
1959void CalendarView::eventToBeDeleted(Event *) 1960void CalendarView::eventToBeDeleted(Event *)
1960{ 1961{
1961 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 1962 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
1962} 1963}
1963 1964
1964void CalendarView::eventDeleted() 1965void CalendarView::eventDeleted()
1965{ 1966{
1966 changeEventDisplay(0,KOGlobals::EVENTDELETED); 1967 changeEventDisplay(0,KOGlobals::EVENTDELETED);
1967} 1968}
1968void CalendarView::changeTodoDisplay(Todo *which, int action) 1969void CalendarView::changeTodoDisplay(Todo *which, int action)
1969{ 1970{
1970 changeIncidenceDisplay((Incidence *)which, action); 1971 changeIncidenceDisplay((Incidence *)which, action);
1971 mDateNavigator->updateView(); //LR 1972 mDateNavigator->updateView(); //LR
1972 //mDialogManager->updateSearchDialog(); 1973 //mDialogManager->updateSearchDialog();
1973 1974
1974 if (which) { 1975 if (which) {
1975 mViewManager->updateWNview(); 1976 mViewManager->updateWNview();
1976 //mTodoList->updateView(); 1977 //mTodoList->updateView();
1977 } 1978 }
1978 1979
1979} 1980}
1980 1981
1981void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 1982void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
1982{ 1983{
1983 updateUnmanagedViews(); 1984 updateUnmanagedViews();
1984 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 1985 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
1985 if ( action == KOGlobals::EVENTDELETED ) { //delete 1986 if ( action == KOGlobals::EVENTDELETED ) { //delete
1986 mCalendar->checkAlarmForIncidence( 0, true ); 1987 mCalendar->checkAlarmForIncidence( 0, true );
1987 if ( mEventViewerDialog ) 1988 if ( mEventViewerDialog )
1988 mEventViewerDialog->hide(); 1989 mEventViewerDialog->hide();
1989 } 1990 }
1990 else 1991 else
1991 mCalendar->checkAlarmForIncidence( which , false ); 1992 mCalendar->checkAlarmForIncidence( which , false );
1992} 1993}
1993 1994
1994// most of the changeEventDisplays() right now just call the view's 1995// most of the changeEventDisplays() right now just call the view's
1995// total update mode, but they SHOULD be recoded to be more refresh-efficient. 1996// total update mode, but they SHOULD be recoded to be more refresh-efficient.
1996void CalendarView::changeEventDisplay(Event *which, int action) 1997void CalendarView::changeEventDisplay(Event *which, int action)
1997{ 1998{
1998 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 1999 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
1999 changeIncidenceDisplay((Incidence *)which, action); 2000 changeIncidenceDisplay((Incidence *)which, action);
2000 mDateNavigator->updateView(); 2001 mDateNavigator->updateView();
2001 //mDialogManager->updateSearchDialog(); 2002 //mDialogManager->updateSearchDialog();
2002 2003
2003 if (which) { 2004 if (which) {
2004 // If there is an event view visible update the display 2005 // If there is an event view visible update the display
2005 mViewManager->currentView()->changeEventDisplay(which,action); 2006 mViewManager->currentView()->changeEventDisplay(which,action);
2006 // TODO: check, if update needed 2007 // TODO: check, if update needed
2007 // if (which->getTodoStatus()) { 2008 // if (which->getTodoStatus()) {
2008 mTodoList->updateView(); 2009 mTodoList->updateView();
2009 // } 2010 // }
2010 } else { 2011 } else {
2011 mViewManager->currentView()->updateView(); 2012 mViewManager->currentView()->updateView();
2012 } 2013 }
2013} 2014}
2014 2015
2015 2016
2016void CalendarView::updateTodoViews() 2017void CalendarView::updateTodoViews()
2017{ 2018{
2018 2019
2019 mTodoList->updateView(); 2020 mTodoList->updateView();
2020 mViewManager->currentView()->updateView(); 2021 mViewManager->currentView()->updateView();
2021 2022
2022} 2023}
2023 2024
2024 2025
2025void CalendarView::updateView(const QDate &start, const QDate &end) 2026void CalendarView::updateView(const QDate &start, const QDate &end)
2026{ 2027{
2027 mTodoList->updateView(); 2028 mTodoList->updateView();
2028 mViewManager->updateView(start, end); 2029 mViewManager->updateView(start, end);
2029 //mDateNavigator->updateView(); 2030 //mDateNavigator->updateView();
2030} 2031}
2031 2032
2032void CalendarView::updateView() 2033void CalendarView::updateView()
2033{ 2034{
2034 DateList tmpList = mNavigator->selectedDates(); 2035 DateList tmpList = mNavigator->selectedDates();
2035 2036
2036 // We assume that the navigator only selects consecutive days. 2037 // We assume that the navigator only selects consecutive days.
2037 updateView( tmpList.first(), tmpList.last() ); 2038 updateView( tmpList.first(), tmpList.last() );
2038} 2039}
2039 2040
2040void CalendarView::updateUnmanagedViews() 2041void CalendarView::updateUnmanagedViews()
2041{ 2042{
2042 mDateNavigator->updateDayMatrix(); 2043 mDateNavigator->updateDayMatrix();
2043} 2044}
2044 2045
2045int CalendarView::msgItemDelete() 2046int CalendarView::msgItemDelete()
2046{ 2047{
2047 return KMessageBox::warningContinueCancel(this, 2048 return KMessageBox::warningContinueCancel(this,
2048 i18n("This item will be\npermanently deleted."), 2049 i18n("This item will be\npermanently deleted."),
2049 i18n("KO/Pi Confirmation"),i18n("Delete")); 2050 i18n("KO/Pi Confirmation"),i18n("Delete"));
2050} 2051}
2051 2052
2052 2053
2053void CalendarView::edit_cut() 2054void CalendarView::edit_cut()
2054{ 2055{
2055 Event *anEvent=0; 2056 Event *anEvent=0;
2056 2057
2057 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2058 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2058 2059
2059 if (mViewManager->currentView()->isEventView()) { 2060 if (mViewManager->currentView()->isEventView()) {
2060 if ( incidence && incidence->type() == "Event" ) { 2061 if ( incidence && incidence->type() == "Event" ) {
2061 anEvent = static_cast<Event *>(incidence); 2062 anEvent = static_cast<Event *>(incidence);
2062 } 2063 }
2063 } 2064 }
2064 2065
2065 if (!anEvent) { 2066 if (!anEvent) {
2066 KNotifyClient::beep(); 2067 KNotifyClient::beep();
2067 return; 2068 return;
2068 } 2069 }
2069 DndFactory factory( mCalendar ); 2070 DndFactory factory( mCalendar );
2070 factory.cutEvent(anEvent); 2071 factory.cutEvent(anEvent);
2071 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2072 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2072} 2073}
2073 2074
2074void CalendarView::edit_copy() 2075void CalendarView::edit_copy()
2075{ 2076{
2076 Event *anEvent=0; 2077 Event *anEvent=0;
2077 2078
2078 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2079 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2079 2080
2080 if (mViewManager->currentView()->isEventView()) { 2081 if (mViewManager->currentView()->isEventView()) {
2081 if ( incidence && incidence->type() == "Event" ) { 2082 if ( incidence && incidence->type() == "Event" ) {
2082 anEvent = static_cast<Event *>(incidence); 2083 anEvent = static_cast<Event *>(incidence);
2083 } 2084 }
2084 } 2085 }
2085 2086
2086 if (!anEvent) { 2087 if (!anEvent) {
2087 KNotifyClient::beep(); 2088 KNotifyClient::beep();
2088 return; 2089 return;
2089 } 2090 }
2090 DndFactory factory( mCalendar ); 2091 DndFactory factory( mCalendar );
2091 factory.copyEvent(anEvent); 2092 factory.copyEvent(anEvent);
2092} 2093}
2093 2094
2094void CalendarView::edit_paste() 2095void CalendarView::edit_paste()
2095{ 2096{
2096 QDate date = mNavigator->selectedDates().first(); 2097 QDate date = mNavigator->selectedDates().first();
2097 2098
2098 DndFactory factory( mCalendar ); 2099 DndFactory factory( mCalendar );
2099 Event *pastedEvent = factory.pasteEvent( date ); 2100 Event *pastedEvent = factory.pasteEvent( date );
2100 2101
2101 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2102 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2102} 2103}
2103 2104
2104void CalendarView::edit_options() 2105void CalendarView::edit_options()
2105{ 2106{
2106 mDialogManager->showOptionsDialog(); 2107 mDialogManager->showOptionsDialog();
2107 //writeSettings(); 2108 //writeSettings();
2108} 2109}
2109void CalendarView::edit_sync_options() 2110void CalendarView::edit_sync_options()
2110{ 2111{
2111 //mDialogManager->showSyncOptions(); 2112 //mDialogManager->showSyncOptions();
2112 //KOPrefs::instance()->mSyncAlgoPrefs 2113 //KOPrefs::instance()->mSyncAlgoPrefs
2113 QDialog dia( this, "dia", true ); 2114 QDialog dia( this, "dia", true );
2114 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2115 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2115 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2116 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2116 QVBoxLayout lay ( &dia ); 2117 QVBoxLayout lay ( &dia );
2117 lay.setSpacing( 2 ); 2118 lay.setSpacing( 2 );
2118 lay.setMargin( 3 ); 2119 lay.setMargin( 3 );
2119 lay.addWidget(&gr); 2120 lay.addWidget(&gr);
2120 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2121 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2121 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2122 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2122 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2123 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2123 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2124 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2124 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2125 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2125 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2126 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2126 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2127 //QRadioButton both( i18n("Take both on conflict"), &gr );
2127 QPushButton pb ( "OK", &dia); 2128 QPushButton pb ( "OK", &dia);
2128 lay.addWidget( &pb ); 2129 lay.addWidget( &pb );
2129 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2130 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2130 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { 2131 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2131 case 0: 2132 case 0:
2132 loc.setChecked( true); 2133 loc.setChecked( true);
2133 break; 2134 break;
2134 case 1: 2135 case 1:
2135 rem.setChecked( true ); 2136 rem.setChecked( true );
2136 break; 2137 break;
2137 case 2: 2138 case 2:
2138 newest.setChecked( true); 2139 newest.setChecked( true);
2139 break; 2140 break;
2140 case 3: 2141 case 3:
2141 ask.setChecked( true); 2142 ask.setChecked( true);
2142 break; 2143 break;
2143 case 4: 2144 case 4:
2144 f_loc.setChecked( true); 2145 f_loc.setChecked( true);
2145 break; 2146 break;
2146 case 5: 2147 case 5:
2147 f_rem.setChecked( true); 2148 f_rem.setChecked( true);
2148 break; 2149 break;
2149 case 6: 2150 case 6:
2150 // both.setChecked( true); 2151 // both.setChecked( true);
2151 break; 2152 break;
2152 default: 2153 default:
2153 break; 2154 break;
2154 } 2155 }
2155 if ( dia.exec() ) { 2156 if ( dia.exec() ) {
2156 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2157 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2157 } 2158 }
2158 2159
2159} 2160}
2160 2161
2161void CalendarView::slotSelectPickerDate( QDate d) 2162void CalendarView::slotSelectPickerDate( QDate d)
2162{ 2163{
2163 mDateFrame->hide(); 2164 mDateFrame->hide();
2164 if ( mDatePickerMode == 1 ) { 2165 if ( mDatePickerMode == 1 ) {
2165 mNavigator->slotDaySelect( d ); 2166 mNavigator->slotDaySelect( d );
2166 } else if ( mDatePickerMode == 2 ) { 2167 } else if ( mDatePickerMode == 2 ) {
2167 if ( mMoveIncidence->type() == "Todo" ) { 2168 if ( mMoveIncidence->type() == "Todo" ) {
2168 Todo * to = (Todo *) mMoveIncidence; 2169 Todo * to = (Todo *) mMoveIncidence;
2169 QTime tim; 2170 QTime tim;
2170 if ( to->hasDueDate() ) 2171 if ( to->hasDueDate() )
2171 tim = to->dtDue().time(); 2172 tim = to->dtDue().time();
2172 else { 2173 else {
2173 tim = QTime ( 0,0,0 ); 2174 tim = QTime ( 0,0,0 );
2174 to->setFloats( true ); 2175 to->setFloats( true );
2175 to->setHasDueDate( true ); 2176 to->setHasDueDate( true );
2176 } 2177 }
2177 QDateTime dt ( d,tim ); 2178 QDateTime dt ( d,tim );
2178 to->setDtDue( dt ); 2179 to->setDtDue( dt );
2179 todoChanged( to ); 2180 todoChanged( to );
2180 } else { 2181 } else {
2181 QTime tim = mMoveIncidence->dtStart().time(); 2182 QTime tim = mMoveIncidence->dtStart().time();
2182 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2183 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2183 QDateTime dt ( d,tim ); 2184 QDateTime dt ( d,tim );
2184 mMoveIncidence->setDtStart( dt ); 2185 mMoveIncidence->setDtStart( dt );
2185 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2186 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2186 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2187 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2187 } 2188 }
2188 2189
2189 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2190 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2190 } 2191 }
2191} 2192}
2192 2193
2193void CalendarView::removeCategories() 2194void CalendarView::removeCategories()
2194{ 2195{
2195 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2196 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2196 QStringList catList = KOPrefs::instance()->mCustomCategories; 2197 QStringList catList = KOPrefs::instance()->mCustomCategories;
2197 QStringList catIncList; 2198 QStringList catIncList;
2198 QStringList newCatList; 2199 QStringList newCatList;
2199 Incidence* inc = incList.first(); 2200 Incidence* inc = incList.first();
2200 int i; 2201 int i;
2201 int count = 0; 2202 int count = 0;
2202 while ( inc ) { 2203 while ( inc ) {
2203 newCatList.clear(); 2204 newCatList.clear();
2204 catIncList = inc->categories() ; 2205 catIncList = inc->categories() ;
2205 for( i = 0; i< catIncList.count(); ++i ) { 2206 for( i = 0; i< catIncList.count(); ++i ) {
2206 if ( catList.contains (catIncList[i])) 2207 if ( catList.contains (catIncList[i]))
2207 newCatList.append( catIncList[i] ); 2208 newCatList.append( catIncList[i] );
2208 } 2209 }
2209 newCatList.sort(); 2210 newCatList.sort();
2210 inc->setCategories( newCatList.join(",") ); 2211 inc->setCategories( newCatList.join(",") );
2211 inc = incList.next(); 2212 inc = incList.next();
2212 } 2213 }
2213} 2214}
2214 2215
2215int CalendarView::addCategories() 2216int CalendarView::addCategories()
2216{ 2217{
2217 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2218 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2218 QStringList catList = KOPrefs::instance()->mCustomCategories; 2219 QStringList catList = KOPrefs::instance()->mCustomCategories;
2219 QStringList catIncList; 2220 QStringList catIncList;
2220 Incidence* inc = incList.first(); 2221 Incidence* inc = incList.first();
2221 int i; 2222 int i;
2222 int count = 0; 2223 int count = 0;
2223 while ( inc ) { 2224 while ( inc ) {
2224 catIncList = inc->categories() ; 2225 catIncList = inc->categories() ;
2225 for( i = 0; i< catIncList.count(); ++i ) { 2226 for( i = 0; i< catIncList.count(); ++i ) {
2226 if ( !catList.contains (catIncList[i])) { 2227 if ( !catList.contains (catIncList[i])) {
2227 catList.append( catIncList[i] ); 2228 catList.append( catIncList[i] );
2228 //qDebug("add cat %s ", catIncList[i].latin1()); 2229 //qDebug("add cat %s ", catIncList[i].latin1());
2229 ++count; 2230 ++count;
2230 } 2231 }
2231 } 2232 }
2232 inc = incList.next(); 2233 inc = incList.next();
2233 } 2234 }
2234 catList.sort(); 2235 catList.sort();
2235 KOPrefs::instance()->mCustomCategories = catList; 2236 KOPrefs::instance()->mCustomCategories = catList;
2236 return count; 2237 return count;
2237} 2238}
2238 2239
2239void CalendarView::manageCategories() 2240void CalendarView::manageCategories()
2240{ 2241{
2241 KOCatPrefs* cp = new KOCatPrefs(); 2242 KOCatPrefs* cp = new KOCatPrefs();
2242 cp->show(); 2243 cp->show();
2243 int w =cp->sizeHint().width() ; 2244 int w =cp->sizeHint().width() ;
2244 int h = cp->sizeHint().height() ; 2245 int h = cp->sizeHint().height() ;
2245 int dw = QApplication::desktop()->width(); 2246 int dw = QApplication::desktop()->width();
2246 int dh = QApplication::desktop()->height(); 2247 int dh = QApplication::desktop()->height();
2247 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2248 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2248 if ( !cp->exec() ) { 2249 if ( !cp->exec() ) {
2249 delete cp; 2250 delete cp;
2250 return; 2251 return;
2251 } 2252 }
2252 int count = 0; 2253 int count = 0;
2253 if ( cp->addCat() ) { 2254 if ( cp->addCat() ) {
2254 count = addCategories(); 2255 count = addCategories();
2255 if ( count ) { 2256 if ( count ) {
2256 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2257 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2257 writeSettings(); 2258 writeSettings();
2258 } 2259 }
2259 } else { 2260 } else {
2260 removeCategories(); 2261 removeCategories();
2261 updateView(); 2262 updateView();
2262 } 2263 }
2263 delete cp; 2264 delete cp;
2264} 2265}
2265 2266
2266void CalendarView::beamIncidence(Incidence * Inc) 2267void CalendarView::beamIncidence(Incidence * Inc)
2267{ 2268{
2268 QPtrList<Incidence> delSel ; 2269 QPtrList<Incidence> delSel ;
2269 delSel.append(Inc); 2270 delSel.append(Inc);
2270 beamIncidenceList( delSel ); 2271 beamIncidenceList( delSel );
2271} 2272}
2272void CalendarView::beamCalendar() 2273void CalendarView::beamCalendar()
2273{ 2274{
2274 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2275 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2275 //qDebug("beamCalendar() "); 2276 //qDebug("beamCalendar() ");
2276 beamIncidenceList( delSel ); 2277 beamIncidenceList( delSel );
2277} 2278}
2278void CalendarView::beamFilteredCalendar() 2279void CalendarView::beamFilteredCalendar()
2279{ 2280{
2280 QPtrList<Incidence> delSel = mCalendar->incidences(); 2281 QPtrList<Incidence> delSel = mCalendar->incidences();
2281 //qDebug("beamFilteredCalendar() "); 2282 //qDebug("beamFilteredCalendar() ");
2282 beamIncidenceList( delSel ); 2283 beamIncidenceList( delSel );
2283} 2284}
2284void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2285void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2285{ 2286{
2286 if ( beamDialog->exec () == QDialog::Rejected ) 2287 if ( beamDialog->exec () == QDialog::Rejected )
2287 return; 2288 return;
2288 2289
2289 QString fn = "/tmp/kopibeamfile"; 2290 QString fn = "/tmp/kopibeamfile";
2290 QString mes; 2291 QString mes;
2291 bool createbup = true; 2292 bool createbup = true;
2292 if ( createbup ) { 2293 if ( createbup ) {
2293 QString description = "\n"; 2294 QString description = "\n";
2294 CalendarLocal* cal = new CalendarLocal(); 2295 CalendarLocal* cal = new CalendarLocal();
2295 if ( beamDialog->beamLocal() ) 2296 if ( beamDialog->beamLocal() )
2296 cal->setLocalTime(); 2297 cal->setLocalTime();
2297 else 2298 else
2298 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2299 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2299 Incidence *incidence = delSel.first(); 2300 Incidence *incidence = delSel.first();
2300 bool addText = false; 2301 bool addText = false;
2301 if ( delSel.count() < 10 ) 2302 if ( delSel.count() < 10 )
2302 addText = true; 2303 addText = true;
2303 else { 2304 else {
2304 description.sprintf(i18n(" %d items?"),delSel.count() ); 2305 description.sprintf(i18n(" %d items?"),delSel.count() );
2305 } 2306 }
2306 while ( incidence ) { 2307 while ( incidence ) {
2307 Incidence *in = incidence->clone(); 2308 Incidence *in = incidence->clone();
2308 if ( addText ) 2309 if ( addText )
2309 description += in->summary() + "\n"; 2310 description += in->summary() + "\n";
2310 cal->addIncidence( in ); 2311 cal->addIncidence( in );
2311 incidence = delSel.next(); 2312 incidence = delSel.next();
2312 } 2313 }
2313 if ( beamDialog->beamVcal() ) { 2314 if ( beamDialog->beamVcal() ) {
2314 fn += ".vcs"; 2315 fn += ".vcs";
2315 FileStorage storage( cal, fn, new VCalFormat ); 2316 FileStorage storage( cal, fn, new VCalFormat );
2316 storage.save(); 2317 storage.save();
2317 } else { 2318 } else {
2318 fn += ".ics"; 2319 fn += ".ics";
2319 FileStorage storage( cal, fn, new ICalFormat( ) ); 2320 FileStorage storage( cal, fn, new ICalFormat( ) );
2320 storage.save(); 2321 storage.save();
2321 } 2322 }
2322 delete cal; 2323 delete cal;
2323 mes = i18n("KO/Pi: Ready for beaming"); 2324 mes = i18n("KO/Pi: Ready for beaming");
2324 setCaption(mes); 2325 setCaption(mes);
2325 2326
2326#ifndef DESKTOP_VERSION 2327#ifndef DESKTOP_VERSION
2327 Ir *ir = new Ir( this ); 2328 Ir *ir = new Ir( this );
2328 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2329 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2329 ir->send( fn, description, "text/x-vCalendar" ); 2330 ir->send( fn, description, "text/x-vCalendar" );
2330#endif 2331#endif
2331 } 2332 }
2332} 2333}
2333void CalendarView::beamDone( Ir *ir ) 2334void CalendarView::beamDone( Ir *ir )
2334{ 2335{
2335#ifndef DESKTOP_VERSION 2336#ifndef DESKTOP_VERSION
2336 delete ir; 2337 delete ir;
2337#endif 2338#endif
2338} 2339}
2339 2340
2340void CalendarView::moveIncidence(Incidence * inc ) 2341void CalendarView::moveIncidence(Incidence * inc )
2341{ 2342{
2342 if ( !inc ) return; 2343 if ( !inc ) return;
2343 // qDebug("showDatePickerForIncidence( ) "); 2344 // qDebug("showDatePickerForIncidence( ) ");
2344 if ( mDateFrame->isVisible() ) 2345 if ( mDateFrame->isVisible() )
2345 mDateFrame->hide(); 2346 mDateFrame->hide();
2346 else { 2347 else {
2347 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2348 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2348 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2349 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2349 int dw = QApplication::desktop()->width(); 2350 int dw = QApplication::desktop()->width();
2350 int dh = QApplication::desktop()->height(); 2351 int dh = QApplication::desktop()->height();
2351 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2352 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2352 mDateFrame->show(); 2353 mDateFrame->show();
2353 } 2354 }
2354 mDatePickerMode = 2; 2355 mDatePickerMode = 2;
2355 mMoveIncidence = inc ; 2356 mMoveIncidence = inc ;
2356 QDate da; 2357 QDate da;
2357 if ( mMoveIncidence->type() == "Todo" ) { 2358 if ( mMoveIncidence->type() == "Todo" ) {
2358 Todo * to = (Todo *) mMoveIncidence; 2359 Todo * to = (Todo *) mMoveIncidence;
2359 if ( to->hasDueDate() ) 2360 if ( to->hasDueDate() )
2360 da = to->dtDue().date(); 2361 da = to->dtDue().date();
2361 else 2362 else
2362 da = QDate::currentDate(); 2363 da = QDate::currentDate();
2363 } else { 2364 } else {
2364 da = mMoveIncidence->dtStart().date(); 2365 da = mMoveIncidence->dtStart().date();
2365 } 2366 }
2366 mDatePicker->setDate( da ); 2367 mDatePicker->setDate( da );
2367} 2368}
2368void CalendarView::showDatePicker( ) 2369void CalendarView::showDatePicker( )
2369{ 2370{
2370 //qDebug("CalendarView::showDatePicker( ) "); 2371 //qDebug("CalendarView::showDatePicker( ) ");
2371 if ( mDateFrame->isVisible() ) 2372 if ( mDateFrame->isVisible() )
2372 mDateFrame->hide(); 2373 mDateFrame->hide();
2373 else { 2374 else {
2374 int w =mDatePicker->sizeHint().width() ; 2375 int w =mDatePicker->sizeHint().width() ;
2375 int h = mDatePicker->sizeHint().height() ; 2376 int h = mDatePicker->sizeHint().height() ;
2376 int dw = QApplication::desktop()->width(); 2377 int dw = QApplication::desktop()->width();
2377 int dh = QApplication::desktop()->height(); 2378 int dh = QApplication::desktop()->height();
2378 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2379 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2379 mDateFrame->show(); 2380 mDateFrame->show();
2380 } 2381 }
2381 mDatePickerMode = 1; 2382 mDatePickerMode = 1;
2382 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2383 mDatePicker->setDate( mNavigator->selectedDates().first() );
2383} 2384}
2384 2385
2385void CalendarView::showEventEditor() 2386void CalendarView::showEventEditor()
2386{ 2387{
2387#ifdef DESKTOP_VERSION 2388#ifdef DESKTOP_VERSION
2388 mEventEditor->show(); 2389 mEventEditor->show();
2389#else 2390#else
2390 mEventEditor->showMaximized(); 2391 mEventEditor->showMaximized();
2391#endif 2392#endif
2392} 2393}
2393void CalendarView::showTodoEditor() 2394void CalendarView::showTodoEditor()
2394{ 2395{
2395#ifdef DESKTOP_VERSION 2396#ifdef DESKTOP_VERSION
2396 mTodoEditor->show(); 2397 mTodoEditor->show();
2397#else 2398#else
2398 mTodoEditor->showMaximized(); 2399 mTodoEditor->showMaximized();
2399#endif 2400#endif
2400} 2401}
2401void CalendarView::cancelIncidence(Incidence * inc ) 2402void CalendarView::cancelIncidence(Incidence * inc )
2402{ 2403{
2403 inc->setCancelled( ! inc->cancelled() ); 2404 inc->setCancelled( ! inc->cancelled() );
2404 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2405 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2405 updateView(); 2406 updateView();
2406} 2407}
2407void CalendarView::cloneIncidence(Incidence * orgInc ) 2408void CalendarView::cloneIncidence(Incidence * orgInc )
2408{ 2409{
2409 Incidence * newInc = orgInc->clone(); 2410 Incidence * newInc = orgInc->clone();
2410 newInc->recreate(); 2411 newInc->recreate();
2411 2412
2412 if ( newInc->type() == "Todo" ) { 2413 if ( newInc->type() == "Todo" ) {
2413 Todo* t = (Todo*) newInc; 2414 Todo* t = (Todo*) newInc;
2414 mTodoEditor->editTodo( t ); 2415 mTodoEditor->editTodo( t );
2415 showTodoEditor(); 2416 showTodoEditor();
2416 if ( mTodoEditor->exec() ) { 2417 if ( mTodoEditor->exec() ) {
2417 mCalendar->addTodo( t ); 2418 mCalendar->addTodo( t );
2418 updateView(); 2419 updateView();
2419 } else { 2420 } else {
2420 delete t; 2421 delete t;
2421 } 2422 }
2422 } 2423 }
2423 else { 2424 else {
2424 Event* e = (Event*) newInc; 2425 Event* e = (Event*) newInc;
2425 mEventEditor->editEvent( e ); 2426 mEventEditor->editEvent( e );
2426 showEventEditor(); 2427 showEventEditor();
2427 if ( mEventEditor->exec() ) { 2428 if ( mEventEditor->exec() ) {
2428 mCalendar->addEvent( e ); 2429 mCalendar->addEvent( e );
2429 updateView(); 2430 updateView();
2430 } else { 2431 } else {
2431 delete e; 2432 delete e;
2432 } 2433 }
2433 } 2434 }
2434} 2435}
2435 2436
2436void CalendarView::newEvent() 2437void CalendarView::newEvent()
2437{ 2438{
2438 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2439 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2439 KOAgendaView *aView = mViewManager->agendaView(); 2440 KOAgendaView *aView = mViewManager->agendaView();
2440 if (aView) { 2441 if (aView) {
2441 if (aView->selectionStart().isValid()) { 2442 if (aView->selectionStart().isValid()) {
2442 if (aView->selectedIsAllDay()) { 2443 if (aView->selectedIsAllDay()) {
2443 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2444 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2444 } else { 2445 } else {
2445 newEvent(aView->selectionStart(),aView->selectionEnd()); 2446 newEvent(aView->selectionStart(),aView->selectionEnd());
2446 } 2447 }
2447 return; 2448 return;
2448 } 2449 }
2449 } 2450 }
2450 2451
2451 QDate date = mNavigator->selectedDates().first(); 2452 QDate date = mNavigator->selectedDates().first();
2452 QDateTime current = QDateTime::currentDateTime(); 2453 QDateTime current = QDateTime::currentDateTime();
2453 if ( date <= current.date() ) { 2454 if ( date <= current.date() ) {
2454 int hour = current.time().hour() +1; 2455 int hour = current.time().hour() +1;
2455 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2456 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2456 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2457 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2457 } else 2458 } else
2458 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2459 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2459 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2460 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2460 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2461 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2461} 2462}
2462 2463
2463void CalendarView::newEvent(QDateTime fh) 2464void CalendarView::newEvent(QDateTime fh)
2464{ 2465{
2465 newEvent(fh, 2466 newEvent(fh,
2466 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2467 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2467} 2468}
2468 2469
2469void CalendarView::newEvent(QDate dt) 2470void CalendarView::newEvent(QDate dt)
2470{ 2471{
2471 newEvent(QDateTime(dt, QTime(0,0,0)), 2472 newEvent(QDateTime(dt, QTime(0,0,0)),
2472 QDateTime(dt, QTime(0,0,0)), true); 2473 QDateTime(dt, QTime(0,0,0)), true);
2473} 2474}
2474 2475
2475void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2476void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2476{ 2477{
2477 2478
2478 mEventEditor->newEvent(fromHint,toHint,allDay); 2479 mEventEditor->newEvent(fromHint,toHint,allDay);
2479 if ( mFilterView->filtersEnabled() ) { 2480 if ( mFilterView->filtersEnabled() ) {
2480 CalFilter *filter = mFilterView->selectedFilter(); 2481 CalFilter *filter = mFilterView->selectedFilter();
2481 if (filter && filter->showCategories()) { 2482 if (filter && filter->showCategories()) {
2482 mEventEditor->setCategories(filter->categoryList().join(",") ); 2483 mEventEditor->setCategories(filter->categoryList().join(",") );
2483 } 2484 }
2484 if ( filter ) 2485 if ( filter )
2485 mEventEditor->setSecrecy( filter->getSecrecy() ); 2486 mEventEditor->setSecrecy( filter->getSecrecy() );
2486 } 2487 }
2487 showEventEditor(); 2488 showEventEditor();
2488} 2489}
2489void CalendarView::todoAdded(Todo * t) 2490void CalendarView::todoAdded(Todo * t)
2490{ 2491{
2491 2492
2492 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2493 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2493 updateTodoViews(); 2494 updateTodoViews();
2494} 2495}
2495void CalendarView::todoChanged(Todo * t) 2496void CalendarView::todoChanged(Todo * t)
2496{ 2497{
2497 emit todoModified( t, 4 ); 2498 emit todoModified( t, 4 );
2498 // updateTodoViews(); 2499 // updateTodoViews();
2499} 2500}
2500void CalendarView::todoToBeDeleted(Todo *) 2501void CalendarView::todoToBeDeleted(Todo *)
2501{ 2502{
2502 //qDebug("todoToBeDeleted(Todo *) "); 2503 //qDebug("todoToBeDeleted(Todo *) ");
2503 updateTodoViews(); 2504 updateTodoViews();
2504} 2505}
2505void CalendarView::todoDeleted() 2506void CalendarView::todoDeleted()
2506{ 2507{
2507 //qDebug(" todoDeleted()"); 2508 //qDebug(" todoDeleted()");
2508 updateTodoViews(); 2509 updateTodoViews();
2509} 2510}
2510 2511
2511 2512
2512 2513
2513void CalendarView::newTodo() 2514void CalendarView::newTodo()
2514{ 2515{
2515 2516
2516 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2517 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2517 if ( mFilterView->filtersEnabled() ) { 2518 if ( mFilterView->filtersEnabled() ) {
2518 CalFilter *filter = mFilterView->selectedFilter(); 2519 CalFilter *filter = mFilterView->selectedFilter();
2519 if (filter && filter->showCategories()) { 2520 if (filter && filter->showCategories()) {
2520 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2521 mTodoEditor->setCategories(filter->categoryList().join(",") );
2521 } 2522 }
2522 if ( filter ) 2523 if ( filter )
2523 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2524 mTodoEditor->setSecrecy( filter->getSecrecy() );
2524 } 2525 }
2525 showTodoEditor(); 2526 showTodoEditor();
2526} 2527}
2527 2528
2528void CalendarView::newSubTodo() 2529void CalendarView::newSubTodo()
2529{ 2530{
2530 Todo *todo = selectedTodo(); 2531 Todo *todo = selectedTodo();
2531 if ( todo ) newSubTodo( todo ); 2532 if ( todo ) newSubTodo( todo );
2532} 2533}
2533 2534
2534void CalendarView::newSubTodo(Todo *parentEvent) 2535void CalendarView::newSubTodo(Todo *parentEvent)
2535{ 2536{
2536 2537
2537 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2538 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2538 showTodoEditor(); 2539 showTodoEditor();
2539} 2540}
2540 2541
2541void CalendarView::newFloatingEvent() 2542void CalendarView::newFloatingEvent()
2542{ 2543{
2543 DateList tmpList = mNavigator->selectedDates(); 2544 DateList tmpList = mNavigator->selectedDates();
2544 QDate date = tmpList.first(); 2545 QDate date = tmpList.first();
2545 2546
2546 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2547 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2547 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2548 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2548} 2549}
2549 2550
2550 2551
2551void CalendarView::editEvent( Event *event ) 2552void CalendarView::editEvent( Event *event )
2552{ 2553{
2553 2554
2554 if ( !event ) return; 2555 if ( !event ) return;
2555 if ( event->isReadOnly() ) { 2556 if ( event->isReadOnly() ) {
2556 showEvent( event ); 2557 showEvent( event );
2557 return; 2558 return;
2558 } 2559 }
2559 mEventEditor->editEvent( event , mFlagEditDescription); 2560 mEventEditor->editEvent( event , mFlagEditDescription);
2560 showEventEditor(); 2561 showEventEditor();
2561} 2562}
2562void CalendarView::editJournal( Journal *jour ) 2563void CalendarView::editJournal( Journal *jour )
2563{ 2564{
2564 if ( !jour ) return; 2565 if ( !jour ) return;
2565 mDialogManager->hideSearchDialog(); 2566 mDialogManager->hideSearchDialog();
2566 mViewManager->showJournalView(); 2567 mViewManager->showJournalView();
2567 mNavigator->slotDaySelect( jour->dtStart().date() ); 2568 mNavigator->slotDaySelect( jour->dtStart().date() );
2568} 2569}
2569void CalendarView::editTodo( Todo *todo ) 2570void CalendarView::editTodo( Todo *todo )
2570{ 2571{
2571 if ( !todo ) return; 2572 if ( !todo ) return;
2572 2573
2573 if ( todo->isReadOnly() ) { 2574 if ( todo->isReadOnly() ) {
2574 showTodo( todo ); 2575 showTodo( todo );
2575 return; 2576 return;
2576 } 2577 }
2577 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2578 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2578 showTodoEditor(); 2579 showTodoEditor();
2579 2580
2580} 2581}
2581 2582
2582KOEventViewerDialog* CalendarView::getEventViewerDialog() 2583KOEventViewerDialog* CalendarView::getEventViewerDialog()
2583{ 2584{
2584 if ( !mEventViewerDialog ) { 2585 if ( !mEventViewerDialog ) {
2585 mEventViewerDialog = new KOEventViewerDialog(this); 2586 mEventViewerDialog = new KOEventViewerDialog(this);
2586 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2587 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2587 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2588 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2588 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2589 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2589 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2590 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2590 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2591 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2591 viewManager(), SLOT( showAgendaView( bool ) ) ); 2592 viewManager(), SLOT( showAgendaView( bool ) ) );
2592 mEventViewerDialog->resize( 640, 480 ); 2593 mEventViewerDialog->resize( 640, 480 );
2593 2594
2594 } 2595 }
2595 return mEventViewerDialog; 2596 return mEventViewerDialog;
2596} 2597}
2597void CalendarView::showEvent(Event *event) 2598void CalendarView::showEvent(Event *event)
2598{ 2599{
2599 getEventViewerDialog()->setEvent(event); 2600 getEventViewerDialog()->setEvent(event);
2600 getEventViewerDialog()->showMe(); 2601 getEventViewerDialog()->showMe();
2601} 2602}
2602 2603
2603void CalendarView::showTodo(Todo *event) 2604void CalendarView::showTodo(Todo *event)
2604{ 2605{
2605 getEventViewerDialog()->setTodo(event); 2606 getEventViewerDialog()->setTodo(event);
2606 getEventViewerDialog()->showMe(); 2607 getEventViewerDialog()->showMe();
2607} 2608}
2608void CalendarView::showJournal( Journal *jour ) 2609void CalendarView::showJournal( Journal *jour )
2609{ 2610{
2610 getEventViewerDialog()->setJournal(jour); 2611 getEventViewerDialog()->setJournal(jour);
2611 getEventViewerDialog()->showMe(); 2612 getEventViewerDialog()->showMe();
2612 2613
2613} 2614}
2614// void CalendarView::todoModified (Todo *event, int changed) 2615// void CalendarView::todoModified (Todo *event, int changed)
2615// { 2616// {
2616// // if (mDialogList.find (event) != mDialogList.end ()) { 2617// // if (mDialogList.find (event) != mDialogList.end ()) {
2617// // kdDebug() << "Todo modified and open" << endl; 2618// // kdDebug() << "Todo modified and open" << endl;
2618// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2619// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2619// // temp->modified (changed); 2620// // temp->modified (changed);
2620 2621
2621// // } 2622// // }
2622 2623
2623// mViewManager->updateView(); 2624// mViewManager->updateView();
2624// } 2625// }
2625 2626
2626void CalendarView::appointment_show() 2627void CalendarView::appointment_show()
2627{ 2628{
2628 Event *anEvent = 0; 2629 Event *anEvent = 0;
2629 2630
2630 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2631 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2631 2632
2632 if (mViewManager->currentView()->isEventView()) { 2633 if (mViewManager->currentView()->isEventView()) {
2633 if ( incidence && incidence->type() == "Event" ) { 2634 if ( incidence && incidence->type() == "Event" ) {
2634 anEvent = static_cast<Event *>(incidence); 2635 anEvent = static_cast<Event *>(incidence);
2635 } 2636 }
2636 } 2637 }
2637 2638
2638 if (!anEvent) { 2639 if (!anEvent) {
2639 KNotifyClient::beep(); 2640 KNotifyClient::beep();
2640 return; 2641 return;
2641 } 2642 }
2642 2643
2643 showEvent(anEvent); 2644 showEvent(anEvent);
2644} 2645}
2645 2646
2646void CalendarView::appointment_edit() 2647void CalendarView::appointment_edit()
2647{ 2648{
2648 Event *anEvent = 0; 2649 Event *anEvent = 0;
2649 2650
2650 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2651 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2651 2652
2652 if (mViewManager->currentView()->isEventView()) { 2653 if (mViewManager->currentView()->isEventView()) {
2653 if ( incidence && incidence->type() == "Event" ) { 2654 if ( incidence && incidence->type() == "Event" ) {
2654 anEvent = static_cast<Event *>(incidence); 2655 anEvent = static_cast<Event *>(incidence);
2655 } 2656 }
2656 } 2657 }
2657 2658
2658 if (!anEvent) { 2659 if (!anEvent) {
2659 KNotifyClient::beep(); 2660 KNotifyClient::beep();
2660 return; 2661 return;
2661 } 2662 }
2662 2663
2663 editEvent(anEvent); 2664 editEvent(anEvent);
2664} 2665}
2665 2666
2666void CalendarView::appointment_delete() 2667void CalendarView::appointment_delete()
2667{ 2668{
2668 Event *anEvent = 0; 2669 Event *anEvent = 0;
2669 2670
2670 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2671 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2671 2672
2672 if (mViewManager->currentView()->isEventView()) { 2673 if (mViewManager->currentView()->isEventView()) {
2673 if ( incidence && incidence->type() == "Event" ) { 2674 if ( incidence && incidence->type() == "Event" ) {
2674 anEvent = static_cast<Event *>(incidence); 2675 anEvent = static_cast<Event *>(incidence);
2675 } 2676 }
2676 } 2677 }
2677 2678
2678 if (!anEvent) { 2679 if (!anEvent) {
2679 KNotifyClient::beep(); 2680 KNotifyClient::beep();
2680 return; 2681 return;
2681 } 2682 }
2682 2683
2683 deleteEvent(anEvent); 2684 deleteEvent(anEvent);
2684} 2685}
2685 2686
2686void CalendarView::todo_unsub(Todo *anTodo ) 2687void CalendarView::todo_unsub(Todo *anTodo )
2687{ 2688{
2688 // Todo *anTodo = selectedTodo(); 2689 // Todo *anTodo = selectedTodo();
2689 if (!anTodo) return; 2690 if (!anTodo) return;
2690 if (!anTodo->relatedTo()) return; 2691 if (!anTodo->relatedTo()) return;
2691 anTodo->relatedTo()->removeRelation(anTodo); 2692 anTodo->relatedTo()->removeRelation(anTodo);
2692 anTodo->setRelatedTo(0); 2693 anTodo->setRelatedTo(0);
2693 anTodo->updated(); 2694 anTodo->updated();
2694 anTodo->setRelatedToUid(""); 2695 anTodo->setRelatedToUid("");
2695 setModified(true); 2696 setModified(true);
2696 updateView(); 2697 updateView();
2697} 2698}
2698 2699
2699void CalendarView::deleteTodo(Todo *todo) 2700void CalendarView::deleteTodo(Todo *todo)
2700{ 2701{
2701 if (!todo) { 2702 if (!todo) {
2702 KNotifyClient::beep(); 2703 KNotifyClient::beep();
2703 return; 2704 return;
2704 } 2705 }
2705 if (KOPrefs::instance()->mConfirm) { 2706 if (KOPrefs::instance()->mConfirm) {
2706 switch (msgItemDelete()) { 2707 switch (msgItemDelete()) {
2707 case KMessageBox::Continue: // OK 2708 case KMessageBox::Continue: // OK
2708 if (!todo->relations().isEmpty()) { 2709 if (!todo->relations().isEmpty()) {
2709 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2710 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2710 i18n("Delete To-Do")); 2711 i18n("Delete To-Do"));
2711 } else { 2712 } else {
2712 checkExternalId( todo ); 2713 checkExternalId( todo );
2713 calendar()->deleteTodo(todo); 2714 calendar()->deleteTodo(todo);
2714 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2715 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2715 updateView(); 2716 updateView();
2716 } 2717 }
2717 break; 2718 break;
2718 } // switch 2719 } // switch
2719 } else { 2720 } else {
2720 if (!todo->relations().isEmpty()) { 2721 if (!todo->relations().isEmpty()) {
2721 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2722 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2722 i18n("Delete To-Do")); 2723 i18n("Delete To-Do"));
2723 } else { 2724 } else {
2724 checkExternalId( todo ); 2725 checkExternalId( todo );
2725 mCalendar->deleteTodo(todo); 2726 mCalendar->deleteTodo(todo);
2726 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2727 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2727 updateView(); 2728 updateView();
2728 } 2729 }
2729 } 2730 }
2730 emit updateSearchDialog(); 2731 emit updateSearchDialog();
2731} 2732}
2732void CalendarView::deleteJournal(Journal *jour) 2733void CalendarView::deleteJournal(Journal *jour)
2733{ 2734{
2734 if (!jour) { 2735 if (!jour) {
2735 KNotifyClient::beep(); 2736 KNotifyClient::beep();
2736 return; 2737 return;
2737 } 2738 }
2738 if (KOPrefs::instance()->mConfirm) { 2739 if (KOPrefs::instance()->mConfirm) {
2739 switch (msgItemDelete()) { 2740 switch (msgItemDelete()) {
2740 case KMessageBox::Continue: // OK 2741 case KMessageBox::Continue: // OK
2741 calendar()->deleteJournal(jour); 2742 calendar()->deleteJournal(jour);
2742 updateView(); 2743 updateView();
2743 break; 2744 break;
2744 } // switch 2745 } // switch
2745 } else { 2746 } else {
2746 calendar()->deleteJournal(jour);; 2747 calendar()->deleteJournal(jour);;
2747 updateView(); 2748 updateView();
2748 } 2749 }
2749 emit updateSearchDialog(); 2750 emit updateSearchDialog();
2750} 2751}
2751 2752
2752void CalendarView::deleteEvent(Event *anEvent) 2753void CalendarView::deleteEvent(Event *anEvent)
2753{ 2754{
2754 if (!anEvent) { 2755 if (!anEvent) {
2755 KNotifyClient::beep(); 2756 KNotifyClient::beep();
2756 return; 2757 return;
2757 } 2758 }
2758 2759
2759 if (anEvent->recurrence()->doesRecur()) { 2760 if (anEvent->recurrence()->doesRecur()) {
2760 QDate itemDate = mViewManager->currentSelectionDate(); 2761 QDate itemDate = mViewManager->currentSelectionDate();
2761 int km; 2762 int km;
2762 if (!itemDate.isValid()) { 2763 if (!itemDate.isValid()) {
2763 //kdDebug() << "Date Not Valid" << endl; 2764 //kdDebug() << "Date Not Valid" << endl;
2764 if (KOPrefs::instance()->mConfirm) { 2765 if (KOPrefs::instance()->mConfirm) {
2765 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2766 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2766 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2767 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2767 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2768 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2768 if ( km == KMessageBox::Continue ) 2769 if ( km == KMessageBox::Continue )
2769 km = KMessageBox::No; // No = all below 2770 km = KMessageBox::No; // No = all below
2770 } else 2771 } else
2771 km = KMessageBox::No; 2772 km = KMessageBox::No;
2772 } else { 2773 } else {
2773 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2774 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2774 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2775 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2775 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2776 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2776 i18n("KO/Pi Confirmation"),i18n("Current"), 2777 i18n("KO/Pi Confirmation"),i18n("Current"),
2777 i18n("All")); 2778 i18n("All"));
2778 } 2779 }
2779 switch(km) { 2780 switch(km) {
2780 2781
2781 case KMessageBox::No: // Continue // all 2782 case KMessageBox::No: // Continue // all
2782 //qDebug("KMessageBox::No "); 2783 //qDebug("KMessageBox::No ");
2783 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2784 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2784 schedule(Scheduler::Cancel,anEvent); 2785 schedule(Scheduler::Cancel,anEvent);
2785 2786
2786 checkExternalId( anEvent); 2787 checkExternalId( anEvent);
2787 mCalendar->deleteEvent(anEvent); 2788 mCalendar->deleteEvent(anEvent);
2788 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2789 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2789 break; 2790 break;
2790 2791
2791 // Disabled because it does not work 2792 // Disabled because it does not work
2792 //#if 0 2793 //#if 0
2793 case KMessageBox::Yes: // just this one 2794 case KMessageBox::Yes: // just this one
2794 //QDate qd = mNavigator->selectedDates().first(); 2795 //QDate qd = mNavigator->selectedDates().first();
2795 //if (!qd.isValid()) { 2796 //if (!qd.isValid()) {
2796 // kdDebug() << "no date selected, or invalid date" << endl; 2797 // kdDebug() << "no date selected, or invalid date" << endl;
2797 // KNotifyClient::beep(); 2798 // KNotifyClient::beep();
2798 // return; 2799 // return;
2799 //} 2800 //}
2800 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2801 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2801 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2802 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2802 anEvent->addExDate(itemDate); 2803 anEvent->addExDate(itemDate);
2803 int duration = anEvent->recurrence()->duration(); 2804 int duration = anEvent->recurrence()->duration();
2804 if ( duration > 0 ) { 2805 if ( duration > 0 ) {
2805 anEvent->recurrence()->setDuration( duration - 1 ); 2806 anEvent->recurrence()->setDuration( duration - 1 );
2806 } 2807 }
2807 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2808 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2808 } 2809 }
2809 break; 2810 break;
2810 //#endif 2811 //#endif
2811 } // switch 2812 } // switch
2812 } else { 2813 } else {
2813 if (KOPrefs::instance()->mConfirm) { 2814 if (KOPrefs::instance()->mConfirm) {
2814 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2815 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2815 i18n("\nAre you sure you want\nto delete this event?"), 2816 i18n("\nAre you sure you want\nto delete this event?"),
2816 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2817 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2817 case KMessageBox::Continue: // OK 2818 case KMessageBox::Continue: // OK
2818 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2819 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2819 schedule(Scheduler::Cancel,anEvent); 2820 schedule(Scheduler::Cancel,anEvent);
2820 checkExternalId( anEvent); 2821 checkExternalId( anEvent);
2821 mCalendar->deleteEvent(anEvent); 2822 mCalendar->deleteEvent(anEvent);
2822 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2823 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2823 break; 2824 break;
2824 } // switch 2825 } // switch
2825 } else { 2826 } else {
2826 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2827 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2827 schedule(Scheduler::Cancel,anEvent); 2828 schedule(Scheduler::Cancel,anEvent);
2828 checkExternalId( anEvent); 2829 checkExternalId( anEvent);
2829 mCalendar->deleteEvent(anEvent); 2830 mCalendar->deleteEvent(anEvent);
2830 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2831 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2831 } 2832 }
2832 } // if-else 2833 } // if-else
2833 emit updateSearchDialog(); 2834 emit updateSearchDialog();
2834} 2835}
2835 2836
2836bool CalendarView::deleteEvent(const QString &uid) 2837bool CalendarView::deleteEvent(const QString &uid)
2837{ 2838{
2838 Event *ev = mCalendar->event(uid); 2839 Event *ev = mCalendar->event(uid);
2839 if (ev) { 2840 if (ev) {
2840 deleteEvent(ev); 2841 deleteEvent(ev);
2841 return true; 2842 return true;
2842 } else { 2843 } else {
2843 return false; 2844 return false;
2844 } 2845 }
2845} 2846}
2846 2847
2847/*****************************************************************************/ 2848/*****************************************************************************/
2848 2849
2849void CalendarView::action_mail() 2850void CalendarView::action_mail()
2850{ 2851{
2851#ifndef KORG_NOMAIL 2852#ifndef KORG_NOMAIL
2852 KOMailClient mailClient; 2853 KOMailClient mailClient;
2853 2854
2854 Incidence *incidence = currentSelection(); 2855 Incidence *incidence = currentSelection();
2855 2856
2856 if (!incidence) { 2857 if (!incidence) {
2857 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2858 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2858 return; 2859 return;
2859 } 2860 }
2860 if(incidence->attendeeCount() == 0 ) { 2861 if(incidence->attendeeCount() == 0 ) {
2861 KMessageBox::sorry(this, 2862 KMessageBox::sorry(this,
2862 i18n("Can't generate mail:\nNo attendees defined.\n")); 2863 i18n("Can't generate mail:\nNo attendees defined.\n"));
2863 return; 2864 return;
2864 } 2865 }
2865 2866
2866 CalendarLocal cal_tmp; 2867 CalendarLocal cal_tmp;
2867 Event *event = 0; 2868 Event *event = 0;
2868 Event *ev = 0; 2869 Event *ev = 0;
2869 if ( incidence && incidence->type() == "Event" ) { 2870 if ( incidence && incidence->type() == "Event" ) {
2870 event = static_cast<Event *>(incidence); 2871 event = static_cast<Event *>(incidence);
2871 ev = new Event(*event); 2872 ev = new Event(*event);
2872 cal_tmp.addEvent(ev); 2873 cal_tmp.addEvent(ev);
2873 } 2874 }
2874 ICalFormat mForm(); 2875 ICalFormat mForm();
2875 QString attachment = mForm.toString( &cal_tmp ); 2876 QString attachment = mForm.toString( &cal_tmp );
2876 if (ev) delete(ev); 2877 if (ev) delete(ev);
2877 2878
2878 mailClient.mailAttendees(currentSelection(), attachment); 2879 mailClient.mailAttendees(currentSelection(), attachment);
2879 2880
2880#endif 2881#endif
2881 2882
2882#if 0 2883#if 0
2883 Event *anEvent = 0; 2884 Event *anEvent = 0;
2884 if (mViewManager->currentView()->isEventView()) { 2885 if (mViewManager->currentView()->isEventView()) {
2885 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2886 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2886 } 2887 }
2887 2888
2888 if (!anEvent) { 2889 if (!anEvent) {
2889 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2890 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2890 return; 2891 return;
2891 } 2892 }
2892 if(anEvent->attendeeCount() == 0 ) { 2893 if(anEvent->attendeeCount() == 0 ) {
2893 KMessageBox::sorry(this, 2894 KMessageBox::sorry(this,
2894 i18n("Can't generate mail:\nNo attendees defined.\n")); 2895 i18n("Can't generate mail:\nNo attendees defined.\n"));
2895 return; 2896 return;
2896 } 2897 }
2897 2898
2898 mailobject.emailEvent(anEvent); 2899 mailobject.emailEvent(anEvent);
2899#endif 2900#endif
2900} 2901}
2901 2902
2902 2903
2903void CalendarView::schedule_publish(Incidence *incidence) 2904void CalendarView::schedule_publish(Incidence *incidence)
2904{ 2905{
2905 Event *event = 0; 2906 Event *event = 0;
2906 Todo *todo = 0; 2907 Todo *todo = 0;
2907 2908
2908 if (incidence == 0) { 2909 if (incidence == 0) {
2909 incidence = mViewManager->currentView()->selectedIncidences().first(); 2910 incidence = mViewManager->currentView()->selectedIncidences().first();
2910 if (incidence == 0) { 2911 if (incidence == 0) {
2911 incidence = mTodoList->selectedIncidences().first(); 2912 incidence = mTodoList->selectedIncidences().first();
2912 } 2913 }
2913 } 2914 }
2914 if ( incidence && incidence->type() == "Event" ) { 2915 if ( incidence && incidence->type() == "Event" ) {
2915 event = static_cast<Event *>(incidence); 2916 event = static_cast<Event *>(incidence);
2916 } else { 2917 } else {
2917 if ( incidence && incidence->type() == "Todo" ) { 2918 if ( incidence && incidence->type() == "Todo" ) {
2918 todo = static_cast<Todo *>(incidence); 2919 todo = static_cast<Todo *>(incidence);
2919 } 2920 }
2920 } 2921 }
2921 2922
2922 if (!event && !todo) { 2923 if (!event && !todo) {
2923 KMessageBox::sorry(this,i18n("No event selected.")); 2924 KMessageBox::sorry(this,i18n("No event selected."));
2924 return; 2925 return;
2925 } 2926 }
2926 2927
2927 PublishDialog *publishdlg = new PublishDialog(); 2928 PublishDialog *publishdlg = new PublishDialog();
2928 if (incidence->attendeeCount()>0) { 2929 if (incidence->attendeeCount()>0) {
2929 QPtrList<Attendee> attendees = incidence->attendees(); 2930 QPtrList<Attendee> attendees = incidence->attendees();
2930 attendees.first(); 2931 attendees.first();
2931 while ( attendees.current()!=0 ) { 2932 while ( attendees.current()!=0 ) {
2932 publishdlg->addAttendee(attendees.current()); 2933 publishdlg->addAttendee(attendees.current());
2933 attendees.next(); 2934 attendees.next();
2934 } 2935 }
2935 } 2936 }
2936 bool send = true; 2937 bool send = true;
2937 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 2938 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
2938 if ( publishdlg->exec() != QDialog::Accepted ) 2939 if ( publishdlg->exec() != QDialog::Accepted )
2939 send = false; 2940 send = false;
2940 } 2941 }
2941 if ( send ) { 2942 if ( send ) {
2942 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2943 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2943 if ( event ) { 2944 if ( event ) {
2944 Event *ev = new Event(*event); 2945 Event *ev = new Event(*event);
2945 ev->registerObserver(0); 2946 ev->registerObserver(0);
2946 ev->clearAttendees(); 2947 ev->clearAttendees();
2947 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2948 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2948 delete(ev); 2949 delete(ev);
2949 } 2950 }
2950 } else { 2951 } else {
2951 if ( todo ) { 2952 if ( todo ) {
2952 Todo *ev = new Todo(*todo); 2953 Todo *ev = new Todo(*todo);
2953 ev->registerObserver(0); 2954 ev->registerObserver(0);
2954 ev->clearAttendees(); 2955 ev->clearAttendees();
2955 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2956 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2956 delete(ev); 2957 delete(ev);
2957 } 2958 }
2958 } 2959 }
2959 } 2960 }
2960 } 2961 }
2961 delete publishdlg; 2962 delete publishdlg;
2962} 2963}
2963 2964
2964void CalendarView::schedule_request(Incidence *incidence) 2965void CalendarView::schedule_request(Incidence *incidence)
2965{ 2966{
2966 schedule(Scheduler::Request,incidence); 2967 schedule(Scheduler::Request,incidence);
2967} 2968}
2968 2969
2969void CalendarView::schedule_refresh(Incidence *incidence) 2970void CalendarView::schedule_refresh(Incidence *incidence)
2970{ 2971{
2971 schedule(Scheduler::Refresh,incidence); 2972 schedule(Scheduler::Refresh,incidence);
2972} 2973}
2973 2974
2974void CalendarView::schedule_cancel(Incidence *incidence) 2975void CalendarView::schedule_cancel(Incidence *incidence)
2975{ 2976{
2976 schedule(Scheduler::Cancel,incidence); 2977 schedule(Scheduler::Cancel,incidence);
2977} 2978}
2978 2979
2979void CalendarView::schedule_add(Incidence *incidence) 2980void CalendarView::schedule_add(Incidence *incidence)
2980{ 2981{
2981 schedule(Scheduler::Add,incidence); 2982 schedule(Scheduler::Add,incidence);
2982} 2983}
2983 2984
2984void CalendarView::schedule_reply(Incidence *incidence) 2985void CalendarView::schedule_reply(Incidence *incidence)
2985{ 2986{
2986 schedule(Scheduler::Reply,incidence); 2987 schedule(Scheduler::Reply,incidence);
2987} 2988}
2988 2989
2989void CalendarView::schedule_counter(Incidence *incidence) 2990void CalendarView::schedule_counter(Incidence *incidence)
2990{ 2991{
2991 schedule(Scheduler::Counter,incidence); 2992 schedule(Scheduler::Counter,incidence);
2992} 2993}
2993 2994
2994void CalendarView::schedule_declinecounter(Incidence *incidence) 2995void CalendarView::schedule_declinecounter(Incidence *incidence)
2995{ 2996{
2996 schedule(Scheduler::Declinecounter,incidence); 2997 schedule(Scheduler::Declinecounter,incidence);
2997} 2998}
2998 2999
2999void CalendarView::schedule_publish_freebusy(int daysToPublish) 3000void CalendarView::schedule_publish_freebusy(int daysToPublish)
3000{ 3001{
3001 QDateTime start = QDateTime::currentDateTime(); 3002 QDateTime start = QDateTime::currentDateTime();
3002 QDateTime end = start.addDays(daysToPublish); 3003 QDateTime end = start.addDays(daysToPublish);
3003 3004
3004 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3005 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3005 freebusy->setOrganizer(KOPrefs::instance()->email()); 3006 freebusy->setOrganizer(KOPrefs::instance()->email());
3006 3007
3007 3008
3008 PublishDialog *publishdlg = new PublishDialog(); 3009 PublishDialog *publishdlg = new PublishDialog();
3009 if ( publishdlg->exec() == QDialog::Accepted ) { 3010 if ( publishdlg->exec() == QDialog::Accepted ) {
3010 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3011 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3011 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3012 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3012 delete(freebusy); 3013 delete(freebusy);
3013 } 3014 }
3014 } 3015 }
3015 delete publishdlg; 3016 delete publishdlg;
3016} 3017}
3017 3018
3018void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3019void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3019{ 3020{
3020 Event *event = 0; 3021 Event *event = 0;
3021 Todo *todo = 0; 3022 Todo *todo = 0;
3022 3023
3023 if (incidence == 0) { 3024 if (incidence == 0) {
3024 incidence = mViewManager->currentView()->selectedIncidences().first(); 3025 incidence = mViewManager->currentView()->selectedIncidences().first();
3025 if (incidence == 0) { 3026 if (incidence == 0) {
3026 incidence = mTodoList->selectedIncidences().first(); 3027 incidence = mTodoList->selectedIncidences().first();
3027 } 3028 }
3028 } 3029 }
3029 if ( incidence && incidence->type() == "Event" ) { 3030 if ( incidence && incidence->type() == "Event" ) {
3030 event = static_cast<Event *>(incidence); 3031 event = static_cast<Event *>(incidence);
3031 } 3032 }
3032 if ( incidence && incidence->type() == "Todo" ) { 3033 if ( incidence && incidence->type() == "Todo" ) {
3033 todo = static_cast<Todo *>(incidence); 3034 todo = static_cast<Todo *>(incidence);
3034 } 3035 }
3035 3036
3036 if (!event && !todo) { 3037 if (!event && !todo) {
3037 KMessageBox::sorry(this,i18n("No event selected.")); 3038 KMessageBox::sorry(this,i18n("No event selected."));
3038 return; 3039 return;
3039 } 3040 }
3040 3041
3041 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3042 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3042 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3043 KMessageBox::sorry(this,i18n("The event has no attendees."));
3043 return; 3044 return;
3044 } 3045 }
3045 3046
3046 Event *ev = 0; 3047 Event *ev = 0;
3047 if (event) ev = new Event(*event); 3048 if (event) ev = new Event(*event);
3048 Todo *to = 0; 3049 Todo *to = 0;
3049 if (todo) to = new Todo(*todo); 3050 if (todo) to = new Todo(*todo);
3050 3051
3051 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3052 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3052 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3053 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3053 if (!me) { 3054 if (!me) {
3054 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3055 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3055 return; 3056 return;
3056 } 3057 }
3057 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3058 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3058 StatusDialog *statdlg = new StatusDialog(this); 3059 StatusDialog *statdlg = new StatusDialog(this);
3059 if (!statdlg->exec()==QDialog::Accepted) return; 3060 if (!statdlg->exec()==QDialog::Accepted) return;
3060 me->setStatus( statdlg->status() ); 3061 me->setStatus( statdlg->status() );
3061 delete(statdlg); 3062 delete(statdlg);
3062 } 3063 }
3063 Attendee *menew = new Attendee(*me); 3064 Attendee *menew = new Attendee(*me);
3064 if (ev) { 3065 if (ev) {
3065 ev->clearAttendees(); 3066 ev->clearAttendees();
3066 ev->addAttendee(menew,false); 3067 ev->addAttendee(menew,false);
3067 } else { 3068 } else {
3068 if (to) { 3069 if (to) {
3069 todo->clearAttendees(); 3070 todo->clearAttendees();
3070 todo->addAttendee(menew,false); 3071 todo->addAttendee(menew,false);
3071 } 3072 }
3072 } 3073 }
3073 } 3074 }
3074 3075
3075 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3076 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3076 if (ev) { 3077 if (ev) {
3077 if ( !dlg->addMessage(ev,method) ) delete(ev); 3078 if ( !dlg->addMessage(ev,method) ) delete(ev);
3078 } else { 3079 } else {
3079 if (to) { 3080 if (to) {
3080 if ( !dlg->addMessage(to,method) ) delete(to); 3081 if ( !dlg->addMessage(to,method) ) delete(to);
3081 } 3082 }
3082 } 3083 }
3083} 3084}
3084 3085
3085void CalendarView::openAddressbook() 3086void CalendarView::openAddressbook()
3086{ 3087{
3087 KRun::runCommand("kaddressbook"); 3088 KRun::runCommand("kaddressbook");
3088} 3089}
3089 3090
3090void CalendarView::setModified(bool modified) 3091void CalendarView::setModified(bool modified)
3091{ 3092{
3092 if ( modified ) 3093 if ( modified )
3093 emit signalmodified(); 3094 emit signalmodified();
3094 if (mModified != modified) { 3095 if (mModified != modified) {
3095 mModified = modified; 3096 mModified = modified;
3096 emit modifiedChanged(mModified); 3097 emit modifiedChanged(mModified);
3097 } 3098 }
3098} 3099}
3099 3100
3100bool CalendarView::isReadOnly() 3101bool CalendarView::isReadOnly()
3101{ 3102{
3102 return mReadOnly; 3103 return mReadOnly;
3103} 3104}
3104 3105
3105void CalendarView::setReadOnly(bool readOnly) 3106void CalendarView::setReadOnly(bool readOnly)
3106{ 3107{
3107 if (mReadOnly != readOnly) { 3108 if (mReadOnly != readOnly) {
3108 mReadOnly = readOnly; 3109 mReadOnly = readOnly;
3109 emit readOnlyChanged(mReadOnly); 3110 emit readOnlyChanged(mReadOnly);
3110 } 3111 }
3111} 3112}
3112 3113
3113bool CalendarView::isModified() 3114bool CalendarView::isModified()
3114{ 3115{
3115 return mModified; 3116 return mModified;
3116} 3117}
3117 3118
3118void CalendarView::printSetup() 3119void CalendarView::printSetup()
3119{ 3120{
3120#ifndef KORG_NOPRINTER 3121#ifndef KORG_NOPRINTER
3121 createPrinter(); 3122 createPrinter();
3122 3123
3123 mCalPrinter->setupPrinter(); 3124 mCalPrinter->setupPrinter();
3124#endif 3125#endif
3125} 3126}
3126 3127
3127void CalendarView::print() 3128void CalendarView::print()
3128{ 3129{
3129#ifndef KORG_NOPRINTER 3130#ifndef KORG_NOPRINTER
3130 createPrinter(); 3131 createPrinter();
3131 3132
3132 DateList tmpDateList = mNavigator->selectedDates(); 3133 DateList tmpDateList = mNavigator->selectedDates();
3133 mCalPrinter->print(CalPrinter::Month, 3134 mCalPrinter->print(CalPrinter::Month,
3134 tmpDateList.first(), tmpDateList.last()); 3135 tmpDateList.first(), tmpDateList.last());
3135#endif 3136#endif
3136} 3137}
3137 3138
3138void CalendarView::printPreview() 3139void CalendarView::printPreview()
3139{ 3140{
3140#ifndef KORG_NOPRINTER 3141#ifndef KORG_NOPRINTER
3141 kdDebug() << "CalendarView::printPreview()" << endl; 3142 kdDebug() << "CalendarView::printPreview()" << endl;
3142 3143
3143 createPrinter(); 3144 createPrinter();
3144 3145
3145 DateList tmpDateList = mNavigator->selectedDates(); 3146 DateList tmpDateList = mNavigator->selectedDates();
3146 3147
3147 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3148 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3148 tmpDateList.last()); 3149 tmpDateList.last());
3149#endif 3150#endif
3150} 3151}
3151 3152
3152void CalendarView::exportICalendar() 3153void CalendarView::exportICalendar()
3153{ 3154{
3154 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3155 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3155 3156
3156 // Force correct extension 3157 // Force correct extension
3157 if (filename.right(4) != ".ics") filename += ".ics"; 3158 if (filename.right(4) != ".ics") filename += ".ics";
3158 3159
3159 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3160 FileStorage storage( mCalendar, filename, new ICalFormat() );
3160 storage.save(); 3161 storage.save();
3161} 3162}
3162 3163
3163bool CalendarView::exportVCalendar( QString filename ) 3164bool CalendarView::exportVCalendar( QString filename )
3164{ 3165{
3165 if (mCalendar->journals().count() > 0) { 3166 if (mCalendar->journals().count() > 0) {
3166 int result = KMessageBox::warningContinueCancel(this, 3167 int result = KMessageBox::warningContinueCancel(this,
3167 i18n("The journal entries can not be\nexported to a vCalendar file."), 3168 i18n("The journal entries can not be\nexported to a vCalendar file."),
3168 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3169 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3169 true); 3170 true);
3170 if (result != KMessageBox::Continue) return false; 3171 if (result != KMessageBox::Continue) return false;
3171 } 3172 }
3172 3173
3173 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3174 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3174 3175
3175 // Force correct extension 3176 // Force correct extension
3176 if (filename.right(4) != ".vcs") filename += ".vcs"; 3177 if (filename.right(4) != ".vcs") filename += ".vcs";
3177 3178
3178 FileStorage storage( mCalendar, filename, new VCalFormat ); 3179 FileStorage storage( mCalendar, filename, new VCalFormat );
3179 return storage.save(); 3180 return storage.save();
3180 3181
3181} 3182}
3182 3183
3183void CalendarView::eventUpdated(Incidence *) 3184void CalendarView::eventUpdated(Incidence *)
3184{ 3185{
3185 setModified(); 3186 setModified();
3186 // Don't call updateView here. The code, which has caused the update of the 3187 // Don't call updateView here. The code, which has caused the update of the
3187 // event is responsible for updating the view. 3188 // event is responsible for updating the view.
3188 // updateView(); 3189 // updateView();
3189} 3190}
3190 3191
3191void CalendarView::adaptNavigationUnits() 3192void CalendarView::adaptNavigationUnits()
3192{ 3193{
3193 if (mViewManager->currentView()->isEventView()) { 3194 if (mViewManager->currentView()->isEventView()) {
3194 int days = mViewManager->currentView()->currentDateCount(); 3195 int days = mViewManager->currentView()->currentDateCount();
3195 if (days == 1) { 3196 if (days == 1) {
3196 emit changeNavStringPrev(i18n("&Previous Day")); 3197 emit changeNavStringPrev(i18n("&Previous Day"));
3197 emit changeNavStringNext(i18n("&Next Day")); 3198 emit changeNavStringNext(i18n("&Next Day"));
3198 } else { 3199 } else {
3199 emit changeNavStringPrev(i18n("&Previous Week")); 3200 emit changeNavStringPrev(i18n("&Previous Week"));
3200 emit changeNavStringNext(i18n("&Next Week")); 3201 emit changeNavStringNext(i18n("&Next Week"));
3201 } 3202 }
3202 } 3203 }
3203} 3204}
3204 3205
3205void CalendarView::processMainViewSelection( Incidence *incidence ) 3206void CalendarView::processMainViewSelection( Incidence *incidence )
3206{ 3207{
3207 if ( incidence ) mTodoList->clearSelection(); 3208 if ( incidence ) mTodoList->clearSelection();
3208 processIncidenceSelection( incidence ); 3209 processIncidenceSelection( incidence );
3209} 3210}
3210 3211
3211void CalendarView::processTodoListSelection( Incidence *incidence ) 3212void CalendarView::processTodoListSelection( Incidence *incidence )
3212{ 3213{
3213 if ( incidence && mViewManager->currentView() ) { 3214 if ( incidence && mViewManager->currentView() ) {
3214 mViewManager->currentView()->clearSelection(); 3215 mViewManager->currentView()->clearSelection();
3215 } 3216 }
3216 processIncidenceSelection( incidence ); 3217 processIncidenceSelection( incidence );
3217} 3218}
3218 3219
3219void CalendarView::processIncidenceSelection( Incidence *incidence ) 3220void CalendarView::processIncidenceSelection( Incidence *incidence )
3220{ 3221{
3221 if ( incidence == mSelectedIncidence ) return; 3222 if ( incidence == mSelectedIncidence ) return;
3222 3223
3223 mSelectedIncidence = incidence; 3224 mSelectedIncidence = incidence;
3224 3225
3225 emit incidenceSelected( mSelectedIncidence ); 3226 emit incidenceSelected( mSelectedIncidence );
3226 3227
3227 if ( incidence && incidence->type() == "Event" ) { 3228 if ( incidence && incidence->type() == "Event" ) {
3228 Event *event = static_cast<Event *>( incidence ); 3229 Event *event = static_cast<Event *>( incidence );
3229 if ( event->organizer() == KOPrefs::instance()->email() ) { 3230 if ( event->organizer() == KOPrefs::instance()->email() ) {
3230 emit organizerEventsSelected( true ); 3231 emit organizerEventsSelected( true );
3231 } else { 3232 } else {
3232 emit organizerEventsSelected(false); 3233 emit organizerEventsSelected(false);
3233 } 3234 }
3234 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3235 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3235 KOPrefs::instance()->email() ) ) { 3236 KOPrefs::instance()->email() ) ) {
3236 emit groupEventsSelected( true ); 3237 emit groupEventsSelected( true );
3237 } else { 3238 } else {
3238 emit groupEventsSelected(false); 3239 emit groupEventsSelected(false);
3239 } 3240 }
3240 return; 3241 return;
3241 } else { 3242 } else {
3242 if ( incidence && incidence->type() == "Todo" ) { 3243 if ( incidence && incidence->type() == "Todo" ) {
3243 emit todoSelected( true ); 3244 emit todoSelected( true );
3244 Todo *event = static_cast<Todo *>( incidence ); 3245 Todo *event = static_cast<Todo *>( incidence );
3245 if ( event->organizer() == KOPrefs::instance()->email() ) { 3246 if ( event->organizer() == KOPrefs::instance()->email() ) {
3246 emit organizerEventsSelected( true ); 3247 emit organizerEventsSelected( true );
3247 } else { 3248 } else {
3248 emit organizerEventsSelected(false); 3249 emit organizerEventsSelected(false);
3249 } 3250 }
3250 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3251 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3251 KOPrefs::instance()->email() ) ) { 3252 KOPrefs::instance()->email() ) ) {
3252 emit groupEventsSelected( true ); 3253 emit groupEventsSelected( true );
3253 } else { 3254 } else {
3254 emit groupEventsSelected(false); 3255 emit groupEventsSelected(false);
3255 } 3256 }
3256 return; 3257 return;
3257 } else { 3258 } else {
3258 emit todoSelected( false ); 3259 emit todoSelected( false );
3259 emit organizerEventsSelected(false); 3260 emit organizerEventsSelected(false);
3260 emit groupEventsSelected(false); 3261 emit groupEventsSelected(false);
3261 } 3262 }
3262 return; 3263 return;
3263 } 3264 }
3264 3265
3265 /* if ( incidence && incidence->type() == "Todo" ) { 3266 /* if ( incidence && incidence->type() == "Todo" ) {
3266 emit todoSelected( true ); 3267 emit todoSelected( true );
3267 } else { 3268 } else {
3268 emit todoSelected( false ); 3269 emit todoSelected( false );
3269 }*/ 3270 }*/
3270} 3271}
3271 3272
3272 3273
3273void CalendarView::checkClipboard() 3274void CalendarView::checkClipboard()
3274{ 3275{
3275#ifndef KORG_NODND 3276#ifndef KORG_NODND
3276 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3277 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3277 emit pasteEnabled(true); 3278 emit pasteEnabled(true);
3278 } else { 3279 } else {
3279 emit pasteEnabled(false); 3280 emit pasteEnabled(false);
3280 } 3281 }
3281#endif 3282#endif
3282} 3283}
3283 3284
3284void CalendarView::showDates(const DateList &selectedDates) 3285void CalendarView::showDates(const DateList &selectedDates)
3285{ 3286{
3286 // kdDebug() << "CalendarView::selectDates()" << endl; 3287 // kdDebug() << "CalendarView::selectDates()" << endl;
3287 3288
3288 if ( mViewManager->currentView() ) { 3289 if ( mViewManager->currentView() ) {
3289 updateView( selectedDates.first(), selectedDates.last() ); 3290 updateView( selectedDates.first(), selectedDates.last() );
3290 } else { 3291 } else {
3291 mViewManager->showAgendaView(); 3292 mViewManager->showAgendaView();
3292 } 3293 }
3293 3294
3294 QString selDates; 3295 QString selDates;
3295 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3296 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3296 if (selectedDates.first() < selectedDates.last() ) 3297 if (selectedDates.first() < selectedDates.last() )
3297 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3298 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3298 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3299 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3299 3300
3300} 3301}
3301 3302
3302QPtrList<CalFilter> CalendarView::filters() 3303QPtrList<CalFilter> CalendarView::filters()
3303{ 3304{
3304 return mFilters; 3305 return mFilters;
3305 3306
3306} 3307}
3307void CalendarView::editFilters() 3308void CalendarView::editFilters()
3308{ 3309{
3309 // kdDebug() << "CalendarView::editFilters()" << endl; 3310 // kdDebug() << "CalendarView::editFilters()" << endl;
3310 3311
3311 CalFilter *filter = mFilters.first(); 3312 CalFilter *filter = mFilters.first();
3312 while(filter) { 3313 while(filter) {
3313 kdDebug() << " Filter: " << filter->name() << endl; 3314 kdDebug() << " Filter: " << filter->name() << endl;
3314 filter = mFilters.next(); 3315 filter = mFilters.next();
3315 } 3316 }
3316 3317
3317 mDialogManager->showFilterEditDialog(&mFilters); 3318 mDialogManager->showFilterEditDialog(&mFilters);
3318} 3319}
3319void CalendarView::toggleFilter() 3320void CalendarView::toggleFilter()
3320{ 3321{
3321 showFilter(! mFilterView->isVisible()); 3322 showFilter(! mFilterView->isVisible());
3322} 3323}
3323 3324
3324KOFilterView *CalendarView::filterView() 3325KOFilterView *CalendarView::filterView()
3325{ 3326{
3326 return mFilterView; 3327 return mFilterView;
3327} 3328}
3328void CalendarView::selectFilter( int fil ) 3329void CalendarView::selectFilter( int fil )
3329{ 3330{
3330 mFilterView->setSelectedFilter( fil ); 3331 mFilterView->setSelectedFilter( fil );
3331} 3332}
3332void CalendarView::showFilter(bool visible) 3333void CalendarView::showFilter(bool visible)
3333{ 3334{
3334 if (visible) mFilterView->show(); 3335 if (visible) mFilterView->show();
3335 else mFilterView->hide(); 3336 else mFilterView->hide();
3336} 3337}
3337void CalendarView::toggleFilerEnabled( ) 3338void CalendarView::toggleFilerEnabled( )
3338{ 3339{
3339 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3340 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3340 if ( !mFilterView->filtersEnabled() ) 3341 if ( !mFilterView->filtersEnabled() )
3341 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3342 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3342 3343
3343} 3344}
3344void CalendarView::updateFilter() 3345void CalendarView::updateFilter()
3345{ 3346{
3346 CalFilter *filter = mFilterView->selectedFilter(); 3347 CalFilter *filter = mFilterView->selectedFilter();
3347 if (filter) { 3348 if (filter) {
3348 if (mFilterView->filtersEnabled()) { 3349 if (mFilterView->filtersEnabled()) {
3349 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3350 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3350 filter->setEnabled(true); 3351 filter->setEnabled(true);
3351 } 3352 }
3352 else filter->setEnabled(false); 3353 else filter->setEnabled(false);
3353 mCalendar->setFilter(filter); 3354 mCalendar->setFilter(filter);
3354 updateView(); 3355 updateView();
3355 } 3356 }
3356} 3357}
3357 3358
3358void CalendarView::filterEdited() 3359void CalendarView::filterEdited()
3359{ 3360{
3360 mFilterView->updateFilters(); 3361 mFilterView->updateFilters();
3361 updateFilter(); 3362 updateFilter();
3362 writeSettings(); 3363 writeSettings();
3363} 3364}
3364 3365
3365 3366
3366void CalendarView::takeOverEvent() 3367void CalendarView::takeOverEvent()
3367{ 3368{
3368 Incidence *incidence = currentSelection(); 3369 Incidence *incidence = currentSelection();
3369 3370
3370 if (!incidence) return; 3371 if (!incidence) return;
3371 3372
3372 incidence->setOrganizer(KOPrefs::instance()->email()); 3373 incidence->setOrganizer(KOPrefs::instance()->email());
3373 incidence->recreate(); 3374 incidence->recreate();
3374 incidence->setReadOnly(false); 3375 incidence->setReadOnly(false);
3375 3376
3376 updateView(); 3377 updateView();
3377} 3378}
3378 3379
3379void CalendarView::takeOverCalendar() 3380void CalendarView::takeOverCalendar()
3380{ 3381{
3381 // TODO: Create Calendar::allIncidences() function and use it here 3382 // TODO: Create Calendar::allIncidences() function and use it here
3382 3383
3383 QPtrList<Event> events = mCalendar->events(); 3384 QPtrList<Event> events = mCalendar->events();
3384 for(uint i=0; i<events.count(); ++i) { 3385 for(uint i=0; i<events.count(); ++i) {
3385 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3386 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3386 events.at(i)->recreate(); 3387 events.at(i)->recreate();
3387 events.at(i)->setReadOnly(false); 3388 events.at(i)->setReadOnly(false);
3388 } 3389 }
3389 3390
3390 QPtrList<Todo> todos = mCalendar->todos(); 3391 QPtrList<Todo> todos = mCalendar->todos();
3391 for(uint i=0; i<todos.count(); ++i) { 3392 for(uint i=0; i<todos.count(); ++i) {
3392 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3393 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3393 todos.at(i)->recreate(); 3394 todos.at(i)->recreate();
3394 todos.at(i)->setReadOnly(false); 3395 todos.at(i)->setReadOnly(false);
3395 } 3396 }
3396 3397
3397 QPtrList<Journal> journals = mCalendar->journals(); 3398 QPtrList<Journal> journals = mCalendar->journals();
3398 for(uint i=0; i<journals.count(); ++i) { 3399 for(uint i=0; i<journals.count(); ++i) {
3399 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3400 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3400 journals.at(i)->recreate(); 3401 journals.at(i)->recreate();
3401 journals.at(i)->setReadOnly(false); 3402 journals.at(i)->setReadOnly(false);
3402 } 3403 }
3403 3404
3404 updateView(); 3405 updateView();
3405} 3406}
3406 3407
3407void CalendarView::showIntro() 3408void CalendarView::showIntro()
3408{ 3409{
3409 kdDebug() << "To be implemented." << endl; 3410 kdDebug() << "To be implemented." << endl;
3410} 3411}
3411 3412
3412QWidgetStack *CalendarView::viewStack() 3413QWidgetStack *CalendarView::viewStack()
3413{ 3414{
3414 return mRightFrame; 3415 return mRightFrame;
3415} 3416}
3416 3417
3417QWidget *CalendarView::leftFrame() 3418QWidget *CalendarView::leftFrame()
3418{ 3419{
3419 return mLeftFrame; 3420 return mLeftFrame;
3420} 3421}
3421 3422
3422DateNavigator *CalendarView::dateNavigator() 3423DateNavigator *CalendarView::dateNavigator()
3423{ 3424{
3424 return mNavigator; 3425 return mNavigator;
3425} 3426}
3426 3427
3427KDateNavigator* CalendarView::dateNavigatorWidget() 3428KDateNavigator* CalendarView::dateNavigatorWidget()
3428{ 3429{
3429 return mDateNavigator; 3430 return mDateNavigator;
3430} 3431}
3431void CalendarView::toggleDateNavigatorWidget() 3432void CalendarView::toggleDateNavigatorWidget()
3432{ 3433{
3433 if (mDateNavigator->isVisible()) 3434 if (mDateNavigator->isVisible())
3434 mDateNavigator->hide(); 3435 mDateNavigator->hide();
3435 else 3436 else
3436 mDateNavigator->show(); 3437 mDateNavigator->show();
3437} 3438}
3438void CalendarView::addView(KOrg::BaseView *view) 3439void CalendarView::addView(KOrg::BaseView *view)
3439{ 3440{
3440 mViewManager->addView(view); 3441 mViewManager->addView(view);
3441} 3442}
3442 3443
3443void CalendarView::showView(KOrg::BaseView *view) 3444void CalendarView::showView(KOrg::BaseView *view)
3444{ 3445{
3445 mViewManager->showView(view, mLeftFrame->isVisible()); 3446 mViewManager->showView(view, mLeftFrame->isVisible());
3446} 3447}
3447 3448
3448Incidence *CalendarView::currentSelection() 3449Incidence *CalendarView::currentSelection()
3449{ 3450{
3450 return mViewManager->currentSelection(); 3451 return mViewManager->currentSelection();
3451} 3452}
3452void CalendarView::toggleAllDaySize() 3453void CalendarView::toggleAllDaySize()
3453{ 3454{
3454 /* 3455 /*
3455 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3456 if ( KOPrefs::instance()->mAllDaySize > 47 )
3456 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3457 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3457 else 3458 else
3458 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3459 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3459 */ 3460 */
3460 viewManager()->agendaView()->toggleAllDay(); 3461 viewManager()->agendaView()->toggleAllDay();
3461} 3462}
3462void CalendarView::toggleExpand() 3463void CalendarView::toggleExpand()
3463{ 3464{
3464 // if ( mLeftFrame->isHidden() ) { 3465 // if ( mLeftFrame->isHidden() ) {
3465 // mLeftFrame->show(); 3466 // mLeftFrame->show();
3466 // emit calendarViewExpanded( false ); 3467 // emit calendarViewExpanded( false );
3467 // } else { 3468 // } else {
3468 // mLeftFrame->hide(); 3469 // mLeftFrame->hide();
3469 // emit calendarViewExpanded( true ); 3470 // emit calendarViewExpanded( true );
3470 // } 3471 // }
3471 3472
3472 globalFlagBlockAgenda = 1; 3473 globalFlagBlockAgenda = 1;
3473 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3474 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3474 globalFlagBlockAgenda = 5; 3475 globalFlagBlockAgenda = 5;
3475 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3476 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3476 //mViewManager->showView( 0, true ); 3477 //mViewManager->showView( 0, true );
3477} 3478}
3478 3479
3479void CalendarView::calendarModified( bool modified, Calendar * ) 3480void CalendarView::calendarModified( bool modified, Calendar * )
3480{ 3481{
3481 setModified( modified ); 3482 setModified( modified );
3482} 3483}
3483 3484
3484Todo *CalendarView::selectedTodo() 3485Todo *CalendarView::selectedTodo()
3485{ 3486{
3486 Incidence *incidence = currentSelection(); 3487 Incidence *incidence = currentSelection();
3487 if ( incidence && incidence->type() == "Todo" ) { 3488 if ( incidence && incidence->type() == "Todo" ) {
3488 return static_cast<Todo *>( incidence ); 3489 return static_cast<Todo *>( incidence );
3489 } 3490 }
3490 3491
3491 incidence = mTodoList->selectedIncidences().first(); 3492 incidence = mTodoList->selectedIncidences().first();
3492 if ( incidence && incidence->type() == "Todo" ) { 3493 if ( incidence && incidence->type() == "Todo" ) {
3493 return static_cast<Todo *>( incidence ); 3494 return static_cast<Todo *>( incidence );
3494 } 3495 }
3495 3496
3496 return 0; 3497 return 0;
3497} 3498}
3498 3499
3499void CalendarView::dialogClosing(Incidence *in) 3500void CalendarView::dialogClosing(Incidence *in)
3500{ 3501{
3501 // mDialogList.remove(in); 3502 // mDialogList.remove(in);
3502} 3503}
3503 3504
3504void CalendarView::showIncidence() 3505void CalendarView::showIncidence()
3505{ 3506{
3506 Incidence *incidence = currentSelection(); 3507 Incidence *incidence = currentSelection();
3507 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3508 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3508 if ( incidence ) { 3509 if ( incidence ) {
3509 ShowIncidenceVisitor v; 3510 ShowIncidenceVisitor v;
3510 v.act( incidence, this ); 3511 v.act( incidence, this );
3511 } 3512 }
3512} 3513}
3513void CalendarView::editIncidenceDescription() 3514void CalendarView::editIncidenceDescription()
3514{ 3515{
3515 mFlagEditDescription = true; 3516 mFlagEditDescription = true;
3516 editIncidence(); 3517 editIncidence();
3517 mFlagEditDescription = false; 3518 mFlagEditDescription = false;
3518} 3519}
3519void CalendarView::editIncidence() 3520void CalendarView::editIncidence()
3520{ 3521{
3521 // qDebug("editIncidence() "); 3522 // qDebug("editIncidence() ");
3522 Incidence *incidence = currentSelection(); 3523 Incidence *incidence = currentSelection();
3523 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3524 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3524 if ( incidence ) { 3525 if ( incidence ) {
3525 EditIncidenceVisitor v; 3526 EditIncidenceVisitor v;
3526 v.act( incidence, this ); 3527 v.act( incidence, this );
3527 } 3528 }
3528} 3529}
3529 3530
3530void CalendarView::deleteIncidence() 3531void CalendarView::deleteIncidence()
3531{ 3532{
3532 Incidence *incidence = currentSelection(); 3533 Incidence *incidence = currentSelection();
3533 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3534 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3534 if ( incidence ) { 3535 if ( incidence ) {
3535 deleteIncidence(incidence); 3536 deleteIncidence(incidence);
3536 } 3537 }
3537} 3538}
3538 3539
3539void CalendarView::showIncidence(Incidence *incidence) 3540void CalendarView::showIncidence(Incidence *incidence)
3540{ 3541{
3541 if ( incidence ) { 3542 if ( incidence ) {
3542 ShowIncidenceVisitor v; 3543 ShowIncidenceVisitor v;
3543 v.act( incidence, this ); 3544 v.act( incidence, this );
3544 } 3545 }
3545} 3546}
3546 3547
3547void CalendarView::editIncidence(Incidence *incidence) 3548void CalendarView::editIncidence(Incidence *incidence)
3548{ 3549{
3549 if ( incidence ) { 3550 if ( incidence ) {
3550 3551
3551 EditIncidenceVisitor v; 3552 EditIncidenceVisitor v;
3552 v.act( incidence, this ); 3553 v.act( incidence, this );
3553 3554
3554 } 3555 }
3555} 3556}
3556 3557
3557void CalendarView::deleteIncidence(Incidence *incidence) 3558void CalendarView::deleteIncidence(Incidence *incidence)
3558{ 3559{
3559 //qDebug(" CalendarView::deleteIncidence "); 3560 //qDebug(" CalendarView::deleteIncidence ");
3560 if ( incidence ) { 3561 if ( incidence ) {
3561 DeleteIncidenceVisitor v; 3562 DeleteIncidenceVisitor v;
3562 v.act( incidence, this ); 3563 v.act( incidence, this );
3563 } 3564 }
3564} 3565}
3565 3566
3566 3567
3567void CalendarView::lookForOutgoingMessages() 3568void CalendarView::lookForOutgoingMessages()
3568{ 3569{
3569 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3570 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3570 ogd->loadMessages(); 3571 ogd->loadMessages();
3571} 3572}
3572 3573
3573void CalendarView::lookForIncomingMessages() 3574void CalendarView::lookForIncomingMessages()
3574{ 3575{
3575 IncomingDialog *icd = mDialogManager->incomingDialog(); 3576 IncomingDialog *icd = mDialogManager->incomingDialog();
3576 icd->retrieve(); 3577 icd->retrieve();
3577} 3578}
3578 3579
3579bool CalendarView::removeCompletedSubTodos( Todo* t ) 3580bool CalendarView::removeCompletedSubTodos( Todo* t )
3580{ 3581{
3581 bool deleteTodo = true; 3582 bool deleteTodo = true;
3582 QPtrList<Incidence> subTodos; 3583 QPtrList<Incidence> subTodos;
3583 Incidence *aTodo; 3584 Incidence *aTodo;
3584 subTodos = t->relations(); 3585 subTodos = t->relations();
3585 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3586 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3586 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3587 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3587 deleteTodo = false; 3588 deleteTodo = false;
3588 } 3589 }
3589 if ( deleteTodo ) { 3590 if ( deleteTodo ) {
3590 if ( t->isCompleted() ) { 3591 if ( t->isCompleted() ) {
3591 checkExternalId( t ); 3592 checkExternalId( t );
3592 mCalendar->deleteTodo( t ); 3593 mCalendar->deleteTodo( t );
3593 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3594 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3594 } 3595 }
3595 else 3596 else
3596 deleteTodo = false; 3597 deleteTodo = false;
3597 } 3598 }
3598 return deleteTodo; 3599 return deleteTodo;
3599 3600
3600} 3601}
3601void CalendarView::purgeCompleted() 3602void CalendarView::purgeCompleted()
3602{ 3603{
3603 int result = KMessageBox::warningContinueCancel(this, 3604 int result = KMessageBox::warningContinueCancel(this,
3604 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3605 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3605 3606
3606 if (result == KMessageBox::Continue) { 3607 if (result == KMessageBox::Continue) {
3607 3608
3608 QPtrList<Todo> todoCal; 3609 QPtrList<Todo> todoCal;
3609 QPtrList<Todo> rootTodos; 3610 QPtrList<Todo> rootTodos;
3610 //QPtrList<Incidence> rel; 3611 //QPtrList<Incidence> rel;
3611 Todo *aTodo;//, *rTodo; 3612 Todo *aTodo;//, *rTodo;
3612 Incidence *rIncidence; 3613 Incidence *rIncidence;
3613 bool childDelete = false; 3614 bool childDelete = false;
3614 bool deletedOne = true; 3615 bool deletedOne = true;
3615 todoCal = calendar()->todos(); 3616 todoCal = calendar()->todos();
3616 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3617 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3617 if ( !aTodo->relatedTo() ) 3618 if ( !aTodo->relatedTo() )
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 4727a7a..309c699 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,1717 +1,1717 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brwon 3 Copyright (c) 1998 Preston Brwon
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library 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 GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kmessagebox.h> 33#include <kmessagebox.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <klocale.h> 35#include <klocale.h>
36 36
37#include "vcc.h" 37#include "vcc.h"
38#include "vobject.h" 38#include "vobject.h"
39 39
40#include "vcaldrag.h" 40#include "vcaldrag.h"
41#include "calendar.h" 41#include "calendar.h"
42 42
43#include "vcalformat.h" 43#include "vcalformat.h"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47VCalFormat::VCalFormat() 47VCalFormat::VCalFormat()
48{ 48{
49 mCalendar = 0; 49 mCalendar = 0;
50 useLocalTime = false; 50 useLocalTime = false;
51} 51}
52 52
53VCalFormat::~VCalFormat() 53VCalFormat::~VCalFormat()
54{ 54{
55} 55}
56 56
57void VCalFormat::setLocalTime ( bool b ) 57void VCalFormat::setLocalTime ( bool b )
58{ 58{
59 useLocalTime = b; 59 useLocalTime = b;
60} 60}
61bool VCalFormat::load(Calendar *calendar, const QString &fileName) 61bool VCalFormat::load(Calendar *calendar, const QString &fileName)
62{ 62{
63 mCalendar = calendar; 63 mCalendar = calendar;
64 clearException(); 64 clearException();
65 65
66 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 66 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
67 67
68 VObject *vcal = 0; 68 VObject *vcal = 0;
69 69
70 // this is not necessarily only 1 vcal. Could be many vcals, or include 70 // this is not necessarily only 1 vcal. Could be many vcals, or include
71 // a vcard... 71 // a vcard...
72 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 72 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
73 73
74 if (!vcal) { 74 if (!vcal) {
75 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 75 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
76 return FALSE; 76 return FALSE;
77 } 77 }
78 78
79 // any other top-level calendar stuff should be added/initialized here 79 // any other top-level calendar stuff should be added/initialized here
80 80
81 // put all vobjects into their proper places 81 // put all vobjects into their proper places
82 populate(vcal); 82 populate(vcal);
83 83
84 // clean up from vcal API stuff 84 // clean up from vcal API stuff
85 cleanVObjects(vcal); 85 cleanVObjects(vcal);
86 cleanStrTbl(); 86 cleanStrTbl();
87 87
88 return true; 88 return true;
89} 89}
90 90
91 91
92bool VCalFormat::save(Calendar *calendar, const QString &fileName) 92bool VCalFormat::save(Calendar *calendar, const QString &fileName)
93{ 93{
94 mCalendar = calendar; 94 mCalendar = calendar;
95 95
96 QString tmpStr; 96 QString tmpStr;
97 VObject *vcal, *vo; 97 VObject *vcal, *vo;
98 98
99 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; 99 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
100 100
101 vcal = newVObject(VCCalProp); 101 vcal = newVObject(VCCalProp);
102 102
103 // addPropValue(vcal,VCLocationProp, "0.0"); 103 // addPropValue(vcal,VCLocationProp, "0.0");
104 addPropValue(vcal,VCProdIdProp, productId()); 104 addPropValue(vcal,VCProdIdProp, productId());
105 tmpStr = mCalendar->getTimeZoneStr(); 105 tmpStr = mCalendar->getTimeZoneStr();
106 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 106 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
107 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 107 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
108 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 108 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
109 109
110 // TODO STUFF 110 // TODO STUFF
111 QPtrList<Todo> todoList = mCalendar->rawTodos(); 111 QPtrList<Todo> todoList = mCalendar->rawTodos();
112 QPtrListIterator<Todo> qlt(todoList); 112 QPtrListIterator<Todo> qlt(todoList);
113 for (; qlt.current(); ++qlt) { 113 for (; qlt.current(); ++qlt) {
114 vo = eventToVTodo(qlt.current()); 114 vo = eventToVTodo(qlt.current());
115 addVObjectProp(vcal, vo); 115 addVObjectProp(vcal, vo);
116 } 116 }
117 117
118 // EVENT STUFF 118 // EVENT STUFF
119 QPtrList<Event> events = mCalendar->rawEvents(); 119 QPtrList<Event> events = mCalendar->rawEvents();
120 Event *ev; 120 Event *ev;
121 for(ev=events.first();ev;ev=events.next()) { 121 for(ev=events.first();ev;ev=events.next()) {
122 vo = eventToVEvent(ev); 122 vo = eventToVEvent(ev);
123 addVObjectProp(vcal, vo); 123 addVObjectProp(vcal, vo);
124 } 124 }
125 125
126 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 126 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
127 cleanVObjects(vcal); 127 cleanVObjects(vcal);
128 cleanStrTbl(); 128 cleanStrTbl();
129 129
130 if (QFile::exists(fileName)) { 130 if (QFile::exists(fileName)) {
131 kdDebug(5800) << "No error" << endl; 131 kdDebug(5800) << "No error" << endl;
132 return true; 132 return true;
133 } else { 133 } else {
134 kdDebug(5800) << "Error" << endl; 134 kdDebug(5800) << "Error" << endl;
135 return false; // error 135 return false; // error
136 } 136 }
137} 137}
138 138
139bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 139bool VCalFormat::fromString( Calendar *calendar, const QString &text )
140{ 140{
141 // TODO: Factor out VCalFormat::fromString() 141 // TODO: Factor out VCalFormat::fromString()
142 142
143 QCString data = text.utf8(); 143 QCString data = text.utf8();
144 144
145 if ( !data.size() ) return false; 145 if ( !data.size() ) return false;
146 146
147 VObject *vcal = Parse_MIME( data.data(), data.size()); 147 VObject *vcal = Parse_MIME( data.data(), data.size());
148 if ( !vcal ) return false; 148 if ( !vcal ) return false;
149 149
150 VObjectIterator i; 150 VObjectIterator i;
151 VObject *curvo; 151 VObject *curvo;
152 initPropIterator( &i, vcal ); 152 initPropIterator( &i, vcal );
153 153
154 // we only take the first object. TODO: parse all incidences. 154 // we only take the first object. TODO: parse all incidences.
155 do { 155 do {
156 curvo = nextVObject( &i ); 156 curvo = nextVObject( &i );
157 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 157 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
158 strcmp( vObjectName( curvo ), VCTodoProp ) ); 158 strcmp( vObjectName( curvo ), VCTodoProp ) );
159 159
160 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 160 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
161 Event *event = VEventToEvent( curvo ); 161 Event *event = VEventToEvent( curvo );
162 calendar->addEvent( event ); 162 calendar->addEvent( event );
163 } else { 163 } else {
164 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 164 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
165 deleteVObject( vcal ); 165 deleteVObject( vcal );
166 return false; 166 return false;
167 } 167 }
168 168
169 deleteVObject( vcal ); 169 deleteVObject( vcal );
170 170
171 return true; 171 return true;
172} 172}
173 173
174QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) 174QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
175{ 175{
176 176
177 if ( !event ) return QString::null; 177 if ( !event ) return QString::null;
178 bool useL = useLocalTime; 178 bool useL = useLocalTime;
179 useLocalTime = useLocal; 179 useLocalTime = useLocal;
180 mCalendar = calendar; 180 mCalendar = calendar;
181 VObject *vevent = eventToVEvent( event ); 181 VObject *vevent = eventToVEvent( event );
182 char *buf = writeMemVObject( 0, 0, vevent ); 182 char *buf = writeMemVObject( 0, 0, vevent );
183 QString result( buf ); 183 QString result( buf );
184 cleanVObject( vevent ); 184 cleanVObject( vevent );
185 useLocalTime = useL; 185 useLocalTime = useL;
186 return result; 186 return result;
187} 187}
188QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) 188QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
189{ 189{
190 190
191 if ( !todo ) return QString::null; 191 if ( !todo ) return QString::null;
192 bool useL = useLocalTime; 192 bool useL = useLocalTime;
193 useLocalTime = useLocal; 193 useLocalTime = useLocal;
194 mCalendar = calendar; 194 mCalendar = calendar;
195 VObject *vevent = eventToVTodo( todo ); 195 VObject *vevent = eventToVTodo( todo );
196 char *buf = writeMemVObject( 0, 0, vevent ); 196 char *buf = writeMemVObject( 0, 0, vevent );
197 QString result( buf ); 197 QString result( buf );
198 cleanVObject( vevent ); 198 cleanVObject( vevent );
199 useLocalTime = useL; 199 useLocalTime = useL;
200 return result; 200 return result;
201} 201}
202 202
203QString VCalFormat::toString( Calendar *calendar ) 203QString VCalFormat::toString( Calendar *calendar )
204{ 204{
205 // TODO: Factor out VCalFormat::asString() 205 // TODO: Factor out VCalFormat::asString()
206 206
207 VObject *vcal = newVObject(VCCalProp); 207 VObject *vcal = newVObject(VCCalProp);
208 208
209 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 209 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
210 QString tmpStr = mCalendar->getTimeZoneStr(); 210 QString tmpStr = mCalendar->getTimeZoneStr();
211 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 211 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
212 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 212 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
213 213
214 // TODO: Use all data. 214 // TODO: Use all data.
215 QPtrList<Event> events = calendar->events(); 215 QPtrList<Event> events = calendar->events();
216 Event *event = events.first(); 216 Event *event = events.first();
217 if ( !event ) return QString::null; 217 if ( !event ) return QString::null;
218 218
219 VObject *vevent = eventToVEvent( event ); 219 VObject *vevent = eventToVEvent( event );
220 220
221 addVObjectProp( vcal, vevent ); 221 addVObjectProp( vcal, vevent );
222 222
223 char *buf = writeMemVObject( 0, 0, vcal ); 223 char *buf = writeMemVObject( 0, 0, vcal );
224 224
225 QString result( buf ); 225 QString result( buf );
226 226
227 cleanVObject( vcal ); 227 cleanVObject( vcal );
228 228
229 return result; 229 return result;
230} 230}
231 231
232VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 232VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
233{ 233{
234 VObject *vtodo; 234 VObject *vtodo;
235 QString tmpStr; 235 QString tmpStr;
236 QStringList tmpStrList; 236 QStringList tmpStrList;
237 237
238 vtodo = newVObject(VCTodoProp); 238 vtodo = newVObject(VCTodoProp);
239 239
240 // due date 240 // due date
241 if (anEvent->hasDueDate()) { 241 if (anEvent->hasDueDate()) {
242 tmpStr = qDateTimeToISO(anEvent->dtDue(), 242 tmpStr = qDateTimeToISO(anEvent->dtDue(),
243 !anEvent->doesFloat()); 243 !anEvent->doesFloat());
244 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 244 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
245 } 245 }
246 246
247 // start date 247 // start date
248 if (anEvent->hasStartDate()) { 248 if (anEvent->hasStartDate()) {
249 tmpStr = qDateTimeToISO(anEvent->dtStart(), 249 tmpStr = qDateTimeToISO(anEvent->dtStart(),
250 !anEvent->doesFloat()); 250 !anEvent->doesFloat());
251 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 251 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
252 } 252 }
253 253
254 // creation date 254 // creation date
255 tmpStr = qDateTimeToISO(anEvent->created()); 255 tmpStr = qDateTimeToISO(anEvent->created());
256 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 256 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
257 257
258 // unique id 258 // unique id
259 addPropValue(vtodo, VCUniqueStringProp, 259 addPropValue(vtodo, VCUniqueStringProp,
260 anEvent->uid().local8Bit()); 260 anEvent->uid().local8Bit());
261 261
262 // revision 262 // revision
263 tmpStr.sprintf("%i", anEvent->revision()); 263 tmpStr.sprintf("%i", anEvent->revision());
264 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 264 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
265 265
266 // last modification date 266 // last modification date
267 tmpStr = qDateTimeToISO(anEvent->lastModified()); 267 tmpStr = qDateTimeToISO(anEvent->lastModified());
268 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 268 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
269 269
270 // organizer stuff 270 // organizer stuff
271 tmpStr = "MAILTO:" + anEvent->organizer(); 271 tmpStr = "MAILTO:" + anEvent->organizer();
272 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 272 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
273 273
274 // attendees 274 // attendees
275 if (anEvent->attendeeCount() != 0) { 275 if (anEvent->attendeeCount() != 0) {
276 QPtrList<Attendee> al = anEvent->attendees(); 276 QPtrList<Attendee> al = anEvent->attendees();
277 QPtrListIterator<Attendee> ai(al); 277 QPtrListIterator<Attendee> ai(al);
278 Attendee *curAttendee; 278 Attendee *curAttendee;
279 279
280 for (; ai.current(); ++ai) { 280 for (; ai.current(); ++ai) {
281 curAttendee = ai.current(); 281 curAttendee = ai.current();
282 if (!curAttendee->email().isEmpty() && 282 if (!curAttendee->email().isEmpty() &&
283 !curAttendee->name().isEmpty()) 283 !curAttendee->name().isEmpty())
284 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 284 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
285 curAttendee->email() + ">"; 285 curAttendee->email() + ">";
286 else if (curAttendee->name().isEmpty()) 286 else if (curAttendee->name().isEmpty())
287 tmpStr = "MAILTO: " + curAttendee->email(); 287 tmpStr = "MAILTO: " + curAttendee->email();
288 else if (curAttendee->email().isEmpty()) 288 else if (curAttendee->email().isEmpty())
289 tmpStr = "MAILTO: " + curAttendee->name(); 289 tmpStr = "MAILTO: " + curAttendee->name();
290 else if (curAttendee->name().isEmpty() && 290 else if (curAttendee->name().isEmpty() &&
291 curAttendee->email().isEmpty()) 291 curAttendee->email().isEmpty())
292 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 292 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
293 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 293 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
294 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 294 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
295 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 295 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
296 } 296 }
297 } 297 }
298 298
299 // description BL: 299 // description BL:
300 if (!anEvent->description().isEmpty()) { 300 if (!anEvent->description().isEmpty()) {
301 VObject *d = addPropValue(vtodo, VCDescriptionProp, 301 VObject *d = addPropValue(vtodo, VCDescriptionProp,
302 anEvent->description().local8Bit()); 302 anEvent->description().local8Bit());
303 if (anEvent->description().find('\n') != -1) 303 if (anEvent->description().find('\n') != -1)
304 addProp(d, VCQuotedPrintableProp); 304 addProp(d, VCQuotedPrintableProp);
305 } 305 }
306 306
307 // summary 307 // summary
308 if (!anEvent->summary().isEmpty()) 308 if (!anEvent->summary().isEmpty())
309 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 309 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
310 310
311 if (!anEvent->location().isEmpty()) 311 if (!anEvent->location().isEmpty())
312 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 312 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
313 313
314 // completed 314 // completed
315 // status 315 // status
316 // backward compatibility, KOrganizer used to interpret only these two values 316 // backward compatibility, KOrganizer used to interpret only these two values
317 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 317 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
318 "NEEDS_ACTION"); 318 "NEEDS_ACTION");
319 // completion date 319 // completion date
320 if (anEvent->hasCompletedDate()) { 320 if (anEvent->hasCompletedDate()) {
321 tmpStr = qDateTimeToISO(anEvent->completed()); 321 tmpStr = qDateTimeToISO(anEvent->completed());
322 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 322 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
323 } 323 }
324 324
325 // priority 325 // priority
326 tmpStr.sprintf("%i",anEvent->priority()); 326 tmpStr.sprintf("%i",anEvent->priority());
327 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 327 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
328 328
329 // related event 329 // related event
330 if (anEvent->relatedTo()) { 330 if (anEvent->relatedTo()) {
331 addPropValue(vtodo, VCRelatedToProp, 331 addPropValue(vtodo, VCRelatedToProp,
332 anEvent->relatedTo()->uid().local8Bit()); 332 anEvent->relatedTo()->uid().local8Bit());
333 } 333 }
334 334
335 // categories 335 // categories
336 tmpStrList = anEvent->categories(); 336 tmpStrList = anEvent->categories();
337 tmpStr = ""; 337 tmpStr = "";
338 QString catStr; 338 QString catStr;
339 for ( QStringList::Iterator it = tmpStrList.begin(); 339 for ( QStringList::Iterator it = tmpStrList.begin();
340 it != tmpStrList.end(); 340 it != tmpStrList.end();
341 ++it ) { 341 ++it ) {
342 catStr = *it; 342 catStr = *it;
343 if (catStr[0] == ' ') 343 if (catStr[0] == ' ')
344 tmpStr += catStr.mid(1); 344 tmpStr += catStr.mid(1);
345 else 345 else
346 tmpStr += catStr; 346 tmpStr += catStr;
347 // this must be a ';' character as the vCalendar specification requires! 347 // this must be a ';' character as the vCalendar specification requires!
348 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 348 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
349 // read in. 349 // read in.
350 tmpStr += ";"; 350 tmpStr += ";";
351 } 351 }
352 if (!tmpStr.isEmpty()) { 352 if (!tmpStr.isEmpty()) {
353 tmpStr.truncate(tmpStr.length()-1); 353 tmpStr.truncate(tmpStr.length()-1);
354 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 354 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
355 } 355 }
356 356
357 // alarm stuff 357 // alarm stuff
358 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 358 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
359 QPtrList<Alarm> alarms = anEvent->alarms(); 359 QPtrList<Alarm> alarms = anEvent->alarms();
360 Alarm* alarm; 360 Alarm* alarm;
361 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 361 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
362 if (alarm->enabled()) { 362 if (alarm->enabled()) {
363 VObject *a; 363 VObject *a;
364 tmpStr = qDateTimeToISO(alarm->time()); 364 tmpStr = qDateTimeToISO(alarm->time());
365 if (alarm->type() == Alarm::Audio) { 365 if (alarm->type() == Alarm::Audio) {
366 a = addProp(vtodo, VCAAlarmProp); 366 a = addProp(vtodo, VCAAlarmProp);
367 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 367 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
368 addPropValue(a, VCRepeatCountProp, "1"); 368 addPropValue(a, VCRepeatCountProp, "1");
369 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 369 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
370 } 370 }
371 else if (alarm->type() == Alarm::Procedure) { 371 else if (alarm->type() == Alarm::Procedure) {
372 a = addProp(vtodo, VCPAlarmProp); 372 a = addProp(vtodo, VCPAlarmProp);
373 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 373 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
374 addPropValue(a, VCRepeatCountProp, "1"); 374 addPropValue(a, VCRepeatCountProp, "1");
375 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 375 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
376 } else { 376 } else {
377 a = addProp(vtodo, VCDAlarmProp); 377 a = addProp(vtodo, VCDAlarmProp);
378 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 378 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
379 addPropValue(a, VCRepeatCountProp, "1"); 379 addPropValue(a, VCRepeatCountProp, "1");
380 addPropValue(a, VCDisplayStringProp, "beep!"); 380 addPropValue(a, VCDisplayStringProp, "beep!");
381 } 381 }
382 } 382 }
383 } 383 }
384 384
385 if (anEvent->pilotId()) { 385 if (anEvent->pilotId()) {
386 // pilot sync stuff 386 // pilot sync stuff
387 tmpStr.sprintf("%i",anEvent->pilotId()); 387 tmpStr.sprintf("%i",anEvent->pilotId());
388 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 388 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
389 tmpStr.sprintf("%i",anEvent->syncStatus()); 389 tmpStr.sprintf("%i",anEvent->syncStatus());
390 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 390 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
391 } 391 }
392 392
393 return vtodo; 393 return vtodo;
394} 394}
395 395
396VObject* VCalFormat::eventToVEvent(const Event *anEvent) 396VObject* VCalFormat::eventToVEvent(const Event *anEvent)
397{ 397{
398 VObject *vevent; 398 VObject *vevent;
399 QString tmpStr; 399 QString tmpStr;
400 QStringList tmpStrList; 400 QStringList tmpStrList;
401 401
402 vevent = newVObject(VCEventProp); 402 vevent = newVObject(VCEventProp);
403 403
404 // start and end time 404 // start and end time
405 tmpStr = qDateTimeToISO(anEvent->dtStart(), 405 tmpStr = qDateTimeToISO(anEvent->dtStart(),
406 !anEvent->doesFloat()); 406 !anEvent->doesFloat());
407 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 407 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
408 408
409 // events that have time associated but take up no time should 409 // events that have time associated but take up no time should
410 // not have both DTSTART and DTEND. 410 // not have both DTSTART and DTEND.
411 if (anEvent->dtStart() != anEvent->dtEnd()) { 411 if (anEvent->dtStart() != anEvent->dtEnd()) {
412 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 412 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
413 !anEvent->doesFloat()); 413 !anEvent->doesFloat());
414 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 414 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
415 } 415 }
416 416
417 // creation date 417 // creation date
418 tmpStr = qDateTimeToISO(anEvent->created()); 418 tmpStr = qDateTimeToISO(anEvent->created());
419 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 419 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
420 420
421 // unique id 421 // unique id
422 addPropValue(vevent, VCUniqueStringProp, 422 addPropValue(vevent, VCUniqueStringProp,
423 anEvent->uid().local8Bit()); 423 anEvent->uid().local8Bit());
424 424
425 // revision 425 // revision
426 tmpStr.sprintf("%i", anEvent->revision()); 426 tmpStr.sprintf("%i", anEvent->revision());
427 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 427 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
428 428
429 // last modification date 429 // last modification date
430 tmpStr = qDateTimeToISO(anEvent->lastModified()); 430 tmpStr = qDateTimeToISO(anEvent->lastModified());
431 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 431 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
432 432
433 // attendee and organizer stuff 433 // attendee and organizer stuff
434 tmpStr = "MAILTO:" + anEvent->organizer(); 434 tmpStr = "MAILTO:" + anEvent->organizer();
435 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 435 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
436 436
437 if (anEvent->attendeeCount() != 0) { 437 if (anEvent->attendeeCount() != 0) {
438 QPtrList<Attendee> al = anEvent->attendees(); 438 QPtrList<Attendee> al = anEvent->attendees();
439 QPtrListIterator<Attendee> ai(al); 439 QPtrListIterator<Attendee> ai(al);
440 Attendee *curAttendee; 440 Attendee *curAttendee;
441 441
442 // TODO: Put this functionality into Attendee class 442 // TODO: Put this functionality into Attendee class
443 for (; ai.current(); ++ai) { 443 for (; ai.current(); ++ai) {
444 curAttendee = ai.current(); 444 curAttendee = ai.current();
445 if (!curAttendee->email().isEmpty() && 445 if (!curAttendee->email().isEmpty() &&
446 !curAttendee->name().isEmpty()) 446 !curAttendee->name().isEmpty())
447 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 447 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
448 curAttendee->email() + ">"; 448 curAttendee->email() + ">";
449 else if (curAttendee->name().isEmpty()) 449 else if (curAttendee->name().isEmpty())
450 tmpStr = "MAILTO: " + curAttendee->email(); 450 tmpStr = "MAILTO: " + curAttendee->email();
451 else if (curAttendee->email().isEmpty()) 451 else if (curAttendee->email().isEmpty())
452 tmpStr = "MAILTO: " + curAttendee->name(); 452 tmpStr = "MAILTO: " + curAttendee->name();
453 else if (curAttendee->name().isEmpty() && 453 else if (curAttendee->name().isEmpty() &&
454 curAttendee->email().isEmpty()) 454 curAttendee->email().isEmpty())
455 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 455 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
456 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 456 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
457 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; 457 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
458 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 458 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
459 } 459 }
460 } 460 }
461 461
462 // recurrence rule stuff 462 // recurrence rule stuff
463 if (anEvent->recurrence()->doesRecur()) { 463 if (anEvent->recurrence()->doesRecur()) {
464 // some more variables 464 // some more variables
465 QPtrList<Recurrence::rMonthPos> tmpPositions; 465 QPtrList<Recurrence::rMonthPos> tmpPositions;
466 QPtrList<int> tmpDays; 466 QPtrList<int> tmpDays;
467 int *tmpDay; 467 int *tmpDay;
468 Recurrence::rMonthPos *tmpPos; 468 Recurrence::rMonthPos *tmpPos;
469 QString tmpStr2; 469 QString tmpStr2;
470 int i; 470 int i;
471 471
472 switch(anEvent->recurrence()->doesRecur()) { 472 switch(anEvent->recurrence()->doesRecur()) {
473 case Recurrence::rDaily: 473 case Recurrence::rDaily:
474 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 474 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
475// if (anEvent->rDuration > 0) 475// if (anEvent->rDuration > 0)
476 //tmpStr += "#"; 476 //tmpStr += "#";
477 break; 477 break;
478 case Recurrence::rWeekly: 478 case Recurrence::rWeekly:
479 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); 479 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency());
480 for (i = 0; i < 7; i++) { 480 for (i = 0; i < 7; i++) {
481 if (anEvent->recurrence()->days().testBit(i)) 481 if (anEvent->recurrence()->days().testBit(i))
482 tmpStr += dayFromNum(i); 482 tmpStr += dayFromNum(i);
483 } 483 }
484 break; 484 break;
485 case Recurrence::rMonthlyPos: 485 case Recurrence::rMonthlyPos:
486 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); 486 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency());
487 // write out all rMonthPos's 487 // write out all rMonthPos's
488 tmpPositions = anEvent->recurrence()->monthPositions(); 488 tmpPositions = anEvent->recurrence()->monthPositions();
489 for (tmpPos = tmpPositions.first(); 489 for (tmpPos = tmpPositions.first();
490 tmpPos; 490 tmpPos;
491 tmpPos = tmpPositions.next()) { 491 tmpPos = tmpPositions.next()) {
492 492
493 tmpStr2.sprintf("%i", tmpPos->rPos); 493 tmpStr2.sprintf("%i", tmpPos->rPos);
494 if (tmpPos->negative) 494 if (tmpPos->negative)
495 tmpStr2 += "- "; 495 tmpStr2 += "- ";
496 else 496 else
497 tmpStr2 += "+ "; 497 tmpStr2 += "+ ";
498 tmpStr += tmpStr2; 498 tmpStr += tmpStr2;
499 for (i = 0; i < 7; i++) { 499 for (i = 0; i < 7; i++) {
500 if (tmpPos->rDays.testBit(i)) 500 if (tmpPos->rDays.testBit(i))
501 tmpStr += dayFromNum(i); 501 tmpStr += dayFromNum(i);
502 } 502 }
503 } // loop for all rMonthPos's 503 } // loop for all rMonthPos's
504 break; 504 break;
505 case Recurrence::rMonthlyDay: 505 case Recurrence::rMonthlyDay:
506 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); 506 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency());
507 // write out all rMonthDays; 507 // write out all rMonthDays;
508 tmpDays = anEvent->recurrence()->monthDays(); 508 tmpDays = anEvent->recurrence()->monthDays();
509 for (tmpDay = tmpDays.first(); 509 for (tmpDay = tmpDays.first();
510 tmpDay; 510 tmpDay;
511 tmpDay = tmpDays.next()) { 511 tmpDay = tmpDays.next()) {
512 tmpStr2.sprintf("%i ", *tmpDay); 512 tmpStr2.sprintf("%i ", *tmpDay);
513 tmpStr += tmpStr2; 513 tmpStr += tmpStr2;
514 } 514 }
515 break; 515 break;
516 case Recurrence::rYearlyMonth: 516 case Recurrence::rYearlyMonth:
517 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); 517 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency());
518 // write out all the rYearNums; 518 // write out all the rYearNums;
519 tmpDays = anEvent->recurrence()->yearNums(); 519 tmpDays = anEvent->recurrence()->yearNums();
520 for (tmpDay = tmpDays.first(); 520 for (tmpDay = tmpDays.first();
521 tmpDay; 521 tmpDay;
522 tmpDay = tmpDays.next()) { 522 tmpDay = tmpDays.next()) {
523 tmpStr2.sprintf("%i ", *tmpDay); 523 tmpStr2.sprintf("%i ", *tmpDay);
524 tmpStr += tmpStr2; 524 tmpStr += tmpStr2;
525 } 525 }
526 break; 526 break;
527 case Recurrence::rYearlyDay: 527 case Recurrence::rYearlyDay:
528 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); 528 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency());
529 // write out all the rYearNums; 529 // write out all the rYearNums;
530 tmpDays = anEvent->recurrence()->yearNums(); 530 tmpDays = anEvent->recurrence()->yearNums();
531 for (tmpDay = tmpDays.first(); 531 for (tmpDay = tmpDays.first();
532 tmpDay; 532 tmpDay;
533 tmpDay = tmpDays.next()) { 533 tmpDay = tmpDays.next()) {
534 tmpStr2.sprintf("%i ", *tmpDay); 534 tmpStr2.sprintf("%i ", *tmpDay);
535 tmpStr += tmpStr2; 535 tmpStr += tmpStr2;
536 } 536 }
537 break; 537 break;
538 default: 538 default:
539 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; 539 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl;
540 break; 540 break;
541 } // switch 541 } // switch
542 542
543 if (anEvent->recurrence()->duration() > 0) { 543 if (anEvent->recurrence()->duration() > 0) {
544 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); 544 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration());
545 tmpStr += tmpStr2; 545 tmpStr += tmpStr2;
546 } else if (anEvent->recurrence()->duration() == -1) { 546 } else if (anEvent->recurrence()->duration() == -1) {
547 tmpStr += "#0"; // defined as repeat forever 547 tmpStr += "#0"; // defined as repeat forever
548 } else { 548 } else {
549 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); 549 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE);
550 } 550 }
551 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); 551 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
552 552
553 } // event repeats 553 } // event repeats
554 554
555 // exceptions to recurrence 555 // exceptions to recurrence
556 DateList dateList = anEvent->exDates(); 556 DateList dateList = anEvent->exDates();
557 DateList::ConstIterator it; 557 DateList::ConstIterator it;
558 QString tmpStr2; 558 QString tmpStr2;
559 559
560 for (it = dateList.begin(); it != dateList.end(); ++it) { 560 for (it = dateList.begin(); it != dateList.end(); ++it) {
561 tmpStr = qDateToISO(*it) + ";"; 561 tmpStr = qDateToISO(*it) + ";";
562 tmpStr2 += tmpStr; 562 tmpStr2 += tmpStr;
563 } 563 }
564 if (!tmpStr2.isEmpty()) { 564 if (!tmpStr2.isEmpty()) {
565 tmpStr2.truncate(tmpStr2.length()-1); 565 tmpStr2.truncate(tmpStr2.length()-1);
566 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); 566 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
567 } 567 }
568 568
569 // description 569 // description
570 if (!anEvent->description().isEmpty()) { 570 if (!anEvent->description().isEmpty()) {
571 VObject *d = addPropValue(vevent, VCDescriptionProp, 571 VObject *d = addPropValue(vevent, VCDescriptionProp,
572 anEvent->description().local8Bit()); 572 anEvent->description().local8Bit());
573 if (anEvent->description().find('\n') != -1) 573 if (anEvent->description().find('\n') != -1)
574 addProp(d, VCQuotedPrintableProp); 574 addProp(d, VCQuotedPrintableProp);
575 } 575 }
576 576
577 // summary 577 // summary
578 if (!anEvent->summary().isEmpty()) 578 if (!anEvent->summary().isEmpty())
579 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); 579 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
580 580
581 if (!anEvent->location().isEmpty()) 581 if (!anEvent->location().isEmpty())
582 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); 582 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
583 583
584 // status 584 // status
585// TODO: define Event status 585// TODO: define Event status
586// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); 586// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
587 587
588 // secrecy 588 // secrecy
589 const char *text = 0; 589 const char *text = 0;
590 switch (anEvent->secrecy()) { 590 switch (anEvent->secrecy()) {
591 case Incidence::SecrecyPublic: 591 case Incidence::SecrecyPublic:
592 text = "PUBLIC"; 592 text = "PUBLIC";
593 break; 593 break;
594 case Incidence::SecrecyPrivate: 594 case Incidence::SecrecyPrivate:
595 text = "PRIVATE"; 595 text = "PRIVATE";
596 break; 596 break;
597 case Incidence::SecrecyConfidential: 597 case Incidence::SecrecyConfidential:
598 text = "CONFIDENTIAL"; 598 text = "CONFIDENTIAL";
599 break; 599 break;
600 } 600 }
601 if (text) { 601 if (text) {
602 addPropValue(vevent, VCClassProp, text); 602 addPropValue(vevent, VCClassProp, text);
603 } 603 }
604 604
605 // categories 605 // categories
606 tmpStrList = anEvent->categories(); 606 tmpStrList = anEvent->categories();
607 tmpStr = ""; 607 tmpStr = "";
608 QString catStr; 608 QString catStr;
609 for ( QStringList::Iterator it = tmpStrList.begin(); 609 for ( QStringList::Iterator it = tmpStrList.begin();
610 it != tmpStrList.end(); 610 it != tmpStrList.end();
611 ++it ) { 611 ++it ) {
612 catStr = *it; 612 catStr = *it;
613 if (catStr[0] == ' ') 613 if (catStr[0] == ' ')
614 tmpStr += catStr.mid(1); 614 tmpStr += catStr.mid(1);
615 else 615 else
616 tmpStr += catStr; 616 tmpStr += catStr;
617 // this must be a ';' character as the vCalendar specification requires! 617 // this must be a ';' character as the vCalendar specification requires!
618 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 618 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
619 // read in. 619 // read in.
620 tmpStr += ";"; 620 tmpStr += ";";
621 } 621 }
622 if (!tmpStr.isEmpty()) { 622 if (!tmpStr.isEmpty()) {
623 tmpStr.truncate(tmpStr.length()-1); 623 tmpStr.truncate(tmpStr.length()-1);
624 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); 624 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
625 } 625 }
626 626
627 // attachments 627 // attachments
628 // TODO: handle binary attachments! 628 // TODO: handle binary attachments!
629 QPtrList<Attachment> attachments = anEvent->attachments(); 629 QPtrList<Attachment> attachments = anEvent->attachments();
630 for ( Attachment *at = attachments.first(); at; at = attachments.next() ) 630 for ( Attachment *at = attachments.first(); at; at = attachments.next() )
631 addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); 631 addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
632 632
633 // resources 633 // resources
634 tmpStrList = anEvent->resources(); 634 tmpStrList = anEvent->resources();
635 tmpStr = tmpStrList.join(";"); 635 tmpStr = tmpStrList.join(";");
636 if (!tmpStr.isEmpty()) 636 if (!tmpStr.isEmpty())
637 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); 637 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
638 638
639 // alarm stuff 639 // alarm stuff
640 QPtrList<Alarm> alarms = anEvent->alarms(); 640 QPtrList<Alarm> alarms = anEvent->alarms();
641 Alarm* alarm; 641 Alarm* alarm;
642 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 642 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
643 if (alarm->enabled()) { 643 if (alarm->enabled()) {
644 VObject *a ; 644 VObject *a ;
645 tmpStr = qDateTimeToISO(alarm->time()); 645 tmpStr = qDateTimeToISO(alarm->time());
646 if (alarm->type() == Alarm::Audio) { 646 if (alarm->type() == Alarm::Audio) {
647 a = addProp(vevent, VCAAlarmProp); 647 a = addProp(vevent, VCAAlarmProp);
648 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 648 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
649 addPropValue(a, VCRepeatCountProp, "1"); 649 addPropValue(a, VCRepeatCountProp, "1");
650 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 650 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
651 } 651 }
652 if (alarm->type() == Alarm::Procedure) { 652 if (alarm->type() == Alarm::Procedure) {
653 a = addProp(vevent, VCPAlarmProp); 653 a = addProp(vevent, VCPAlarmProp);
654 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 654 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
655 addPropValue(a, VCRepeatCountProp, "1"); 655 addPropValue(a, VCRepeatCountProp, "1");
656 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 656 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
657 } else { 657 } else {
658 a = addProp(vevent, VCDAlarmProp); 658 a = addProp(vevent, VCDAlarmProp);
659 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 659 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
660 addPropValue(a, VCRepeatCountProp, "1"); 660 addPropValue(a, VCRepeatCountProp, "1");
661 addPropValue(a, VCDisplayStringProp, "beep!"); 661 addPropValue(a, VCDisplayStringProp, "beep!");
662 662
663 } 663 }
664 } 664 }
665 } 665 }
666 666
667 // priority 667 // priority
668 tmpStr.sprintf("%i",anEvent->priority()); 668 tmpStr.sprintf("%i",anEvent->priority());
669 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); 669 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
670 670
671 // transparency 671 // transparency
672 tmpStr.sprintf("%i",anEvent->transparency()); 672 tmpStr.sprintf("%i",anEvent->transparency());
673 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); 673 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
674 674
675 // related event 675 // related event
676 if (anEvent->relatedTo()) { 676 if (anEvent->relatedTo()) {
677 addPropValue(vevent, VCRelatedToProp, 677 addPropValue(vevent, VCRelatedToProp,
678 anEvent->relatedTo()->uid().local8Bit()); 678 anEvent->relatedTo()->uid().local8Bit());
679 } 679 }
680 680
681 if (anEvent->pilotId()) { 681 if (anEvent->pilotId()) {
682 // pilot sync stuff 682 // pilot sync stuff
683 tmpStr.sprintf("%i",anEvent->pilotId()); 683 tmpStr.sprintf("%i",anEvent->pilotId());
684 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); 684 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
685 tmpStr.sprintf("%i",anEvent->syncStatus()); 685 tmpStr.sprintf("%i",anEvent->syncStatus());
686 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); 686 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
687 } 687 }
688 688
689 return vevent; 689 return vevent;
690} 690}
691 691
692Todo *VCalFormat::VTodoToEvent(VObject *vtodo) 692Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
693{ 693{
694 VObject *vo; 694 VObject *vo;
695 VObjectIterator voi; 695 VObjectIterator voi;
696 char *s; 696 char *s;
697 697
698 Todo *anEvent = new Todo; 698 Todo *anEvent = new Todo;
699 699
700 // creation date 700 // creation date
701 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { 701 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
702 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 702 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
703 deleteStr(s); 703 deleteStr(s);
704 } 704 }
705 705
706 // unique id 706 // unique id
707 vo = isAPropertyOf(vtodo, VCUniqueStringProp); 707 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
708 // while the UID property is preferred, it is not required. We'll use the 708 // while the UID property is preferred, it is not required. We'll use the
709 // default Event UID if none is given. 709 // default Event UID if none is given.
710 if (vo) { 710 if (vo) {
711 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 711 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
712 deleteStr(s); 712 deleteStr(s);
713 } 713 }
714 714
715 // last modification date 715 // last modification date
716 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { 716 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
717 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 717 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
718 deleteStr(s); 718 deleteStr(s);
719 } 719 }
720 else 720 else
721 anEvent->setLastModified(QDateTime(QDate::currentDate(), 721 anEvent->setLastModified(QDateTime(QDate::currentDate(),
722 QTime::currentTime())); 722 QTime::currentTime()));
723 723
724 // organizer 724 // organizer
725 // if our extension property for the event's ORGANIZER exists, add it. 725 // if our extension property for the event's ORGANIZER exists, add it.
726 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { 726 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
727 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 727 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
728 deleteStr(s); 728 deleteStr(s);
729 } else { 729 } else {
730 anEvent->setOrganizer(mCalendar->getEmail()); 730 anEvent->setOrganizer(mCalendar->getEmail());
731 } 731 }
732 732
733 // attendees. 733 // attendees.
734 initPropIterator(&voi, vtodo); 734 initPropIterator(&voi, vtodo);
735 while (moreIteration(&voi)) { 735 while (moreIteration(&voi)) {
736 vo = nextVObject(&voi); 736 vo = nextVObject(&voi);
737 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 737 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
738 Attendee *a; 738 Attendee *a;
739 VObject *vp; 739 VObject *vp;
740 s = fakeCString(vObjectUStringZValue(vo)); 740 s = fakeCString(vObjectUStringZValue(vo));
741 QString tmpStr = QString::fromLocal8Bit(s); 741 QString tmpStr = QString::fromLocal8Bit(s);
742 deleteStr(s); 742 deleteStr(s);
743 tmpStr = tmpStr.simplifyWhiteSpace(); 743 tmpStr = tmpStr.simplifyWhiteSpace();
744 int emailPos1, emailPos2; 744 int emailPos1, emailPos2;
745 if ((emailPos1 = tmpStr.find('<')) > 0) { 745 if ((emailPos1 = tmpStr.find('<')) > 0) {
746 // both email address and name 746 // both email address and name
747 emailPos2 = tmpStr.findRev('>'); 747 emailPos2 = tmpStr.findRev('>');
748 a = new Attendee(tmpStr.left(emailPos1 - 1), 748 a = new Attendee(tmpStr.left(emailPos1 - 1),
749 tmpStr.mid(emailPos1 + 1, 749 tmpStr.mid(emailPos1 + 1,
750 emailPos2 - (emailPos1 + 1))); 750 emailPos2 - (emailPos1 + 1)));
751 } else if (tmpStr.find('@') > 0) { 751 } else if (tmpStr.find('@') > 0) {
752 // just an email address 752 // just an email address
753 a = new Attendee(0, tmpStr); 753 a = new Attendee(0, tmpStr);
754 } else { 754 } else {
755 // just a name 755 // just a name
756 QString email = tmpStr.replace( QRegExp(" "), "." ); 756 QString email = tmpStr.replace( QRegExp(" "), "." );
757 a = new Attendee(tmpStr,email); 757 a = new Attendee(tmpStr,email);
758 } 758 }
759 759
760 // is there an RSVP property? 760 // is there an RSVP property?
761 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 761 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
762 a->setRSVP(vObjectStringZValue(vp)); 762 a->setRSVP(vObjectStringZValue(vp));
763 // is there a status property? 763 // is there a status property?
764 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 764 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
765 a->setStatus(readStatus(vObjectStringZValue(vp))); 765 a->setStatus(readStatus(vObjectStringZValue(vp)));
766 // add the attendee 766 // add the attendee
767 anEvent->addAttendee(a); 767 anEvent->addAttendee(a);
768 } 768 }
769 } 769 }
770 770
771 // description for todo 771 // description for todo
772 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { 772 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) {
773 s = fakeCString(vObjectUStringZValue(vo)); 773 s = fakeCString(vObjectUStringZValue(vo));
774 anEvent->setDescription(QString::fromLocal8Bit(s)); 774 anEvent->setDescription(QString::fromLocal8Bit(s));
775 deleteStr(s); 775 deleteStr(s);
776 } 776 }
777 777
778 // summary 778 // summary
779 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { 779 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) {
780 s = fakeCString(vObjectUStringZValue(vo)); 780 s = fakeCString(vObjectUStringZValue(vo));
781 anEvent->setSummary(QString::fromLocal8Bit(s)); 781 anEvent->setSummary(QString::fromLocal8Bit(s));
782 deleteStr(s); 782 deleteStr(s);
783 } 783 }
784 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { 784 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) {
785 s = fakeCString(vObjectUStringZValue(vo)); 785 s = fakeCString(vObjectUStringZValue(vo));
786 anEvent->setLocation(QString::fromLocal8Bit(s)); 786 anEvent->setLocation(QString::fromLocal8Bit(s));
787 deleteStr(s); 787 deleteStr(s);
788 } 788 }
789 789
790 790
791 // completed 791 // completed
792 // was: status 792 // was: status
793 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { 793 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) {
794 s = fakeCString(vObjectUStringZValue(vo)); 794 s = fakeCString(vObjectUStringZValue(vo));
795 if (strcmp(s,"COMPLETED") == 0) { 795 if (strcmp(s,"COMPLETED") == 0) {
796 anEvent->setCompleted(true); 796 anEvent->setCompleted(true);
797 } else { 797 } else {
798 anEvent->setCompleted(false); 798 anEvent->setCompleted(false);
799 } 799 }
800 deleteStr(s); 800 deleteStr(s);
801 } 801 }
802 else 802 else
803 anEvent->setCompleted(false); 803 anEvent->setCompleted(false);
804 804
805 // completion date 805 // completion date
806 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { 806 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) {
807 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 807 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
808 deleteStr(s); 808 deleteStr(s);
809 } 809 }
810 810
811 // priority 811 // priority
812 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { 812 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) {
813 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 813 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
814 deleteStr(s); 814 deleteStr(s);
815 } 815 }
816 816
817 // due date 817 // due date
818 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { 818 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) {
819 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 819 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
820 deleteStr(s); 820 deleteStr(s);
821 anEvent->setHasDueDate(true); 821 anEvent->setHasDueDate(true);
822 } else { 822 } else {
823 anEvent->setHasDueDate(false); 823 anEvent->setHasDueDate(false);
824 } 824 }
825 825
826 // start time 826 // start time
827 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { 827 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) {
828 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 828 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
829 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 829 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
830 deleteStr(s); 830 deleteStr(s);
831 anEvent->setHasStartDate(true); 831 anEvent->setHasStartDate(true);
832 } else { 832 } else {
833 anEvent->setHasStartDate(false); 833 anEvent->setHasStartDate(false);
834 } 834 }
835 835
836 /* alarm stuff */ 836 /* alarm stuff */
837 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; 837 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl;
838 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { 838 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) {
839 Alarm* alarm = anEvent->newAlarm(); 839 Alarm* alarm = anEvent->newAlarm();
840 VObject *a; 840 VObject *a;
841 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 841 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
842 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 842 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
843 deleteStr(s); 843 deleteStr(s);
844 } 844 }
845 alarm->setEnabled(true); 845 alarm->setEnabled(true);
846 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { 846 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) {
847 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 847 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
848 s = fakeCString(vObjectUStringZValue(a)); 848 s = fakeCString(vObjectUStringZValue(a));
849 alarm->setProcedureAlarm(QFile::decodeName(s)); 849 alarm->setProcedureAlarm(QFile::decodeName(s));
850 deleteStr(s); 850 deleteStr(s);
851 } 851 }
852 } 852 }
853 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { 853 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) {
854 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 854 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
855 s = fakeCString(vObjectUStringZValue(a)); 855 s = fakeCString(vObjectUStringZValue(a));
856 alarm->setAudioAlarm(QFile::decodeName(s)); 856 alarm->setAudioAlarm(QFile::decodeName(s));
857 deleteStr(s); 857 deleteStr(s);
858 } 858 }
859 } 859 }
860 } 860 }
861 861
862 // related todo 862 // related todo
863 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { 863 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) {
864 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 864 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
865 deleteStr(s); 865 deleteStr(s);
866 mTodosRelate.append(anEvent); 866 mTodosRelate.append(anEvent);
867 } 867 }
868 868
869 // categories 869 // categories
870 QStringList tmpStrList; 870 QStringList tmpStrList;
871 int index1 = 0; 871 int index1 = 0;
872 int index2 = 0; 872 int index2 = 0;
873 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { 873 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) {
874 s = fakeCString(vObjectUStringZValue(vo)); 874 s = fakeCString(vObjectUStringZValue(vo));
875 QString categories = QString::fromLocal8Bit(s); 875 QString categories = QString::fromLocal8Bit(s);
876 deleteStr(s); 876 deleteStr(s);
877 //const char* category; 877 //const char* category;
878 QString category; 878 QString category;
879 while ((index2 = categories.find(',', index1)) != -1) { 879 while ((index2 = categories.find(',', index1)) != -1) {
880 //category = (const char *) categories.mid(index1, (index2 - index1)); 880 //category = (const char *) categories.mid(index1, (index2 - index1));
881 category = categories.mid(index1, (index2 - index1)); 881 category = categories.mid(index1, (index2 - index1));
882 tmpStrList.append(category); 882 tmpStrList.append(category);
883 index1 = index2+1; 883 index1 = index2+1;
884 } 884 }
885 // get last category 885 // get last category
886 category = categories.mid(index1, (categories.length()-index1)); 886 category = categories.mid(index1, (categories.length()-index1));
887 tmpStrList.append(category); 887 tmpStrList.append(category);
888 anEvent->setCategories(tmpStrList); 888 anEvent->setCategories(tmpStrList);
889 } 889 }
890 890
891 /* PILOT SYNC STUFF */ 891 /* PILOT SYNC STUFF */
892 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { 892 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) {
893 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 893 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
894 deleteStr(s); 894 deleteStr(s);
895 } 895 }
896 else 896 else
897 anEvent->setPilotId(0); 897 anEvent->setPilotId(0);
898 898
899 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { 899 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) {
900 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 900 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
901 deleteStr(s); 901 deleteStr(s);
902 } 902 }
903 else 903 else
904 anEvent->setSyncStatus(Event::SYNCMOD); 904 anEvent->setSyncStatus(Event::SYNCMOD);
905 905
906 return anEvent; 906 return anEvent;
907} 907}
908 908
909Event* VCalFormat::VEventToEvent(VObject *vevent) 909Event* VCalFormat::VEventToEvent(VObject *vevent)
910{ 910{
911 VObject *vo; 911 VObject *vo;
912 VObjectIterator voi; 912 VObjectIterator voi;
913 char *s; 913 char *s;
914 914
915 Event *anEvent = new Event; 915 Event *anEvent = new Event;
916 916
917 // creation date 917 // creation date
918 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { 918 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) {
919 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 919 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
920 deleteStr(s); 920 deleteStr(s);
921 } 921 }
922 922
923 // unique id 923 // unique id
924 vo = isAPropertyOf(vevent, VCUniqueStringProp); 924 vo = isAPropertyOf(vevent, VCUniqueStringProp);
925 // while the UID property is preferred, it is not required. We'll use the 925 // while the UID property is preferred, it is not required. We'll use the
926 // default Event UID if none is given. 926 // default Event UID if none is given.
927 if (vo) { 927 if (vo) {
928 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 928 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
929 deleteStr(s); 929 deleteStr(s);
930 } 930 }
931 931
932 // revision 932 // revision
933 // again NSCAL doesn't give us much to work with, so we improvise... 933 // again NSCAL doesn't give us much to work with, so we improvise...
934 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { 934 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) {
935 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 935 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo))));
936 deleteStr(s); 936 deleteStr(s);
937 } 937 }
938 else 938 else
939 anEvent->setRevision(0); 939 anEvent->setRevision(0);
940 940
941 // last modification date 941 // last modification date
942 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { 942 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) {
943 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 943 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
944 deleteStr(s); 944 deleteStr(s);
945 } 945 }
946 else 946 else
947 anEvent->setLastModified(QDateTime(QDate::currentDate(), 947 anEvent->setLastModified(QDateTime(QDate::currentDate(),
948 QTime::currentTime())); 948 QTime::currentTime()));
949 949
950 // organizer 950 // organizer
951 // if our extension property for the event's ORGANIZER exists, add it. 951 // if our extension property for the event's ORGANIZER exists, add it.
952 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { 952 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) {
953 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 953 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
954 deleteStr(s); 954 deleteStr(s);
955 } else { 955 } else {
956 anEvent->setOrganizer(mCalendar->getEmail()); 956 anEvent->setOrganizer(mCalendar->getEmail());
957 } 957 }
958 958
959 // deal with attendees. 959 // deal with attendees.
960 initPropIterator(&voi, vevent); 960 initPropIterator(&voi, vevent);
961 while (moreIteration(&voi)) { 961 while (moreIteration(&voi)) {
962 vo = nextVObject(&voi); 962 vo = nextVObject(&voi);
963 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 963 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
964 Attendee *a; 964 Attendee *a;
965 VObject *vp; 965 VObject *vp;
966 s = fakeCString(vObjectUStringZValue(vo)); 966 s = fakeCString(vObjectUStringZValue(vo));
967 QString tmpStr = QString::fromLocal8Bit(s); 967 QString tmpStr = QString::fromLocal8Bit(s);
968 deleteStr(s); 968 deleteStr(s);
969 tmpStr = tmpStr.simplifyWhiteSpace(); 969 tmpStr = tmpStr.simplifyWhiteSpace();
970 int emailPos1, emailPos2; 970 int emailPos1, emailPos2;
971 if ((emailPos1 = tmpStr.find('<')) > 0) { 971 if ((emailPos1 = tmpStr.find('<')) > 0) {
972 // both email address and name 972 // both email address and name
973 emailPos2 = tmpStr.findRev('>'); 973 emailPos2 = tmpStr.findRev('>');
974 a = new Attendee(tmpStr.left(emailPos1 - 1), 974 a = new Attendee(tmpStr.left(emailPos1 - 1),
975 tmpStr.mid(emailPos1 + 1, 975 tmpStr.mid(emailPos1 + 1,
976 emailPos2 - (emailPos1 + 1))); 976 emailPos2 - (emailPos1 + 1)));
977 } else if (tmpStr.find('@') > 0) { 977 } else if (tmpStr.find('@') > 0) {
978 // just an email address 978 // just an email address
979 a = new Attendee(0, tmpStr); 979 a = new Attendee(0, tmpStr);
980 } else { 980 } else {
981 // just a name 981 // just a name
982 QString email = tmpStr.replace( QRegExp(" "), "." ); 982 QString email = tmpStr.replace( QRegExp(" "), "." );
983 a = new Attendee(tmpStr,email); 983 a = new Attendee(tmpStr,email);
984 } 984 }
985 985
986 // is there an RSVP property? 986 // is there an RSVP property?
987 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 987 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
988 a->setRSVP(vObjectStringZValue(vp)); 988 a->setRSVP(vObjectStringZValue(vp));
989 // is there a status property? 989 // is there a status property?
990 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 990 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
991 a->setStatus(readStatus(vObjectStringZValue(vp))); 991 a->setStatus(readStatus(vObjectStringZValue(vp)));
992 // add the attendee 992 // add the attendee
993 anEvent->addAttendee(a); 993 anEvent->addAttendee(a);
994 } 994 }
995 } 995 }
996 996
997 // This isn't strictly true. An event that doesn't have a start time 997 // This isn't strictly true. An event that doesn't have a start time
998 // or an end time doesn't "float", it has an anchor in time but it doesn't 998 // or an end time doesn't "float", it has an anchor in time but it doesn't
999 // "take up" any time. 999 // "take up" any time.
1000 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || 1000 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) ||
1001 (isAPropertyOf(vevent, VCDTendProp) == 0)) { 1001 (isAPropertyOf(vevent, VCDTendProp) == 0)) {
1002 anEvent->setFloats(TRUE); 1002 anEvent->setFloats(TRUE);
1003 } else { 1003 } else {
1004 }*/ 1004 }*/
1005 1005
1006 anEvent->setFloats(FALSE); 1006 anEvent->setFloats(FALSE);
1007 1007
1008 // start time 1008 // start time
1009 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { 1009 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) {
1010 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 1010 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
1011 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 1011 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
1012 deleteStr(s); 1012 deleteStr(s);
1013 if (anEvent->dtStart().time().isNull()) 1013 if (anEvent->dtStart().time().isNull())
1014 anEvent->setFloats(TRUE); 1014 anEvent->setFloats(TRUE);
1015 } 1015 }
1016 1016
1017 // stop time 1017 // stop time
1018 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { 1018 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) {
1019 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 1019 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
1020 deleteStr(s); 1020 deleteStr(s);
1021 if (anEvent->dtEnd().time().isNull()) 1021 if (anEvent->dtEnd().time().isNull())
1022 anEvent->setFloats(TRUE); 1022 anEvent->setFloats(TRUE);
1023 } 1023 }
1024 1024
1025 // at this point, there should be at least a start or end time. 1025 // at this point, there should be at least a start or end time.
1026 // fix up for events that take up no time but have a time associated 1026 // fix up for events that take up no time but have a time associated
1027 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 1027 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
1028 anEvent->setDtStart(anEvent->dtEnd()); 1028 anEvent->setDtStart(anEvent->dtEnd());
1029 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 1029 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
1030 anEvent->setDtEnd(anEvent->dtStart()); 1030 anEvent->setDtEnd(anEvent->dtStart());
1031 1031
1032 /////////////////////////////////////////////////////////////////////////// 1032 ///////////////////////////////////////////////////////////////////////////
1033 1033
1034 // repeat stuff 1034 // repeat stuff
1035 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { 1035 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) {
1036 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); 1036 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo)));
1037 deleteStr(s); 1037 deleteStr(s);
1038 tmpStr.simplifyWhiteSpace(); 1038 tmpStr.simplifyWhiteSpace();
1039 tmpStr = tmpStr.upper(); 1039 tmpStr = tmpStr.upper();
1040 1040
1041 /********************************* DAILY ******************************/ 1041 /********************************* DAILY ******************************/
1042 if (tmpStr.left(1) == "D") { 1042 if (tmpStr.left(1) == "D") {
1043 int index = tmpStr.find(' '); 1043 int index = tmpStr.find(' ');
1044 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1044 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1045 index = tmpStr.findRev(' ') + 1; // advance to last field 1045 index = tmpStr.findRev(' ') + 1; // advance to last field
1046 if (tmpStr.mid(index,1) == "#") index++; 1046 if (tmpStr.mid(index,1) == "#") index++;
1047 if (tmpStr.find('T', index) != -1) { 1047 if (tmpStr.find('T', index) != -1) {
1048 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1048 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1049 anEvent->recurrence()->setDaily(rFreq, rEndDate); 1049 anEvent->recurrence()->setDaily(rFreq, rEndDate);
1050 } else { 1050 } else {
1051 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1051 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1052 if (rDuration == 0) // VEvents set this to 0 forever, we use -1 1052 if (rDuration == 0) // VEvents set this to 0 forever, we use -1
1053 anEvent->recurrence()->setDaily(rFreq, -1); 1053 anEvent->recurrence()->setDaily(rFreq, -1);
1054 else 1054 else
1055 anEvent->recurrence()->setDaily(rFreq, rDuration); 1055 anEvent->recurrence()->setDaily(rFreq, rDuration);
1056 } 1056 }
1057 } 1057 }
1058 /********************************* WEEKLY ******************************/ 1058 /********************************* WEEKLY ******************************/
1059 else if (tmpStr.left(1) == "W") { 1059 else if (tmpStr.left(1) == "W") {
1060 int index = tmpStr.find(' '); 1060 int index = tmpStr.find(' ');
1061 int last = tmpStr.findRev(' ') + 1; 1061 int last = tmpStr.findRev(' ') + 1;
1062 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1062 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1063 index += 1; // advance to beginning of stuff after freq 1063 index += 1; // advance to beginning of stuff after freq
1064 QBitArray qba(7); 1064 QBitArray qba(7);
1065 QString dayStr; 1065 QString dayStr;
1066 if( index == last ) { 1066 if( index == last ) {
1067 // e.g. W1 #0 1067 // e.g. W1 #0
1068 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1068 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1069 } 1069 }
1070 else { 1070 else {
1071 // e.g. W1 SU #0 1071 // e.g. W1 SU #0
1072 while (index < last) { 1072 while (index < last) {
1073 dayStr = tmpStr.mid(index, 3); 1073 dayStr = tmpStr.mid(index, 3);
1074 int dayNum = numFromDay(dayStr); 1074 int dayNum = numFromDay(dayStr);
1075 qba.setBit(dayNum); 1075 qba.setBit(dayNum);
1076 index += 3; // advance to next day, or possibly "#" 1076 index += 3; // advance to next day, or possibly "#"
1077 } 1077 }
1078 } 1078 }
1079 index = last; if (tmpStr.mid(index,1) == "#") index++; 1079 index = last; if (tmpStr.mid(index,1) == "#") index++;
1080 if (tmpStr.find('T', index) != -1) { 1080 if (tmpStr.find('T', index) != -1) {
1081 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1081 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1082 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); 1082 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate);
1083 } else { 1083 } else {
1084 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1084 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1085 if (rDuration == 0) 1085 if (rDuration == 0)
1086 anEvent->recurrence()->setWeekly(rFreq, qba, -1); 1086 anEvent->recurrence()->setWeekly(rFreq, qba, -1);
1087 else 1087 else
1088 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); 1088 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration);
1089 } 1089 }
1090 } 1090 }
1091 /**************************** MONTHLY-BY-POS ***************************/ 1091 /**************************** MONTHLY-BY-POS ***************************/
1092 else if (tmpStr.left(2) == "MP") { 1092 else if (tmpStr.left(2) == "MP") {
1093 int index = tmpStr.find(' '); 1093 int index = tmpStr.find(' ');
1094 int last = tmpStr.findRev(' ') + 1; 1094 int last = tmpStr.findRev(' ') + 1;
1095 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1095 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1096 index += 1; // advance to beginning of stuff after freq 1096 index += 1; // advance to beginning of stuff after freq
1097 QBitArray qba(7); 1097 QBitArray qba(7);
1098 short tmpPos; 1098 short tmpPos;
1099 if( index == last ) { 1099 if( index == last ) {
1100 // e.g. MP1 #0 1100 // e.g. MP1 #0
1101 tmpPos = anEvent->dtStart().date().day()/7 + 1; 1101 tmpPos = anEvent->dtStart().date().day()/7 + 1;
1102 if( tmpPos == 5 ) 1102 if( tmpPos == 5 )
1103 tmpPos = -1; 1103 tmpPos = -1;
1104 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1104 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1105 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1105 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1106 } 1106 }
1107 else { 1107 else {
1108 // e.g. MP1 1+ SU #0 1108 // e.g. MP1 1+ SU #0
1109 while (index < last) { 1109 while (index < last) {
1110 tmpPos = tmpStr.mid(index,1).toShort(); 1110 tmpPos = tmpStr.mid(index,1).toShort();
1111 index += 1; 1111 index += 1;
1112 if (tmpStr.mid(index,1) == "-") 1112 if (tmpStr.mid(index,1) == "-")
1113 // convert tmpPos to negative 1113 // convert tmpPos to negative
1114 tmpPos = 0 - tmpPos; 1114 tmpPos = 0 - tmpPos;
1115 index += 2; // advance to day(s) 1115 index += 2; // advance to day(s)
1116 while (numFromDay(tmpStr.mid(index,3)) >= 0) { 1116 while (numFromDay(tmpStr.mid(index,3)) >= 0) {
1117 int dayNum = numFromDay(tmpStr.mid(index,3)); 1117 int dayNum = numFromDay(tmpStr.mid(index,3));
1118 qba.setBit(dayNum); 1118 qba.setBit(dayNum);
1119 index += 3; // advance to next day, or possibly pos or "#" 1119 index += 3; // advance to next day, or possibly pos or "#"
1120 } 1120 }
1121 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1121 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1122 qba.detach(); 1122 qba.detach();
1123 qba.fill(FALSE); // clear out 1123 qba.fill(FALSE); // clear out
1124 } // while != "#" 1124 } // while != "#"
1125 } 1125 }
1126 index = last; if (tmpStr.mid(index,1) == "#") index++; 1126 index = last; if (tmpStr.mid(index,1) == "#") index++;
1127 if (tmpStr.find('T', index) != -1) { 1127 if (tmpStr.find('T', index) != -1) {
1128 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - 1128 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() -
1129 index))).date(); 1129 index))).date();
1130 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); 1130 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate);
1131 } else { 1131 } else {
1132 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1132 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1133 if (rDuration == 0) 1133 if (rDuration == 0)
1134 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); 1134 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1);
1135 else 1135 else
1136 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); 1136 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration);
1137 } 1137 }
1138 } 1138 }
1139 1139
1140 /**************************** MONTHLY-BY-DAY ***************************/ 1140 /**************************** MONTHLY-BY-DAY ***************************/
1141 else if (tmpStr.left(2) == "MD") { 1141 else if (tmpStr.left(2) == "MD") {
1142 int index = tmpStr.find(' '); 1142 int index = tmpStr.find(' ');
1143 int last = tmpStr.findRev(' ') + 1; 1143 int last = tmpStr.findRev(' ') + 1;
1144 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1144 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1145 index += 1; 1145 index += 1;
1146 short tmpDay; 1146 short tmpDay;
1147 if( index == last ) { 1147 if( index == last ) {
1148 // e.g. MD1 #0 1148 // e.g. MD1 #0
1149 tmpDay = anEvent->dtStart().date().day(); 1149 tmpDay = anEvent->dtStart().date().day();
1150 anEvent->recurrence()->addMonthlyDay(tmpDay); 1150 anEvent->recurrence()->addMonthlyDay(tmpDay);
1151 } 1151 }
1152 else { 1152 else {
1153 // e.g. MD1 3 #0 1153 // e.g. MD1 3 #0
1154 while (index < last) { 1154 while (index < last) {
1155 int index2 = tmpStr.find(' ', index); 1155 int index2 = tmpStr.find(' ', index);
1156 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1156 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1157 index = index2-1; 1157 index = index2-1;
1158 if (tmpStr.mid(index, 1) == "-") 1158 if (tmpStr.mid(index, 1) == "-")
1159 tmpDay = 0 - tmpDay; 1159 tmpDay = 0 - tmpDay;
1160 index += 2; // advance the index; 1160 index += 2; // advance the index;
1161 anEvent->recurrence()->addMonthlyDay(tmpDay); 1161 anEvent->recurrence()->addMonthlyDay(tmpDay);
1162 } // while != # 1162 } // while != #
1163 } 1163 }
1164 index = last; if (tmpStr.mid(index,1) == "#") index++; 1164 index = last; if (tmpStr.mid(index,1) == "#") index++;
1165 if (tmpStr.find('T', index) != -1) { 1165 if (tmpStr.find('T', index) != -1) {
1166 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1166 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1167 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); 1167 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate);
1168 } else { 1168 } else {
1169 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1169 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1170 if (rDuration == 0) 1170 if (rDuration == 0)
1171 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); 1171 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1);
1172 else 1172 else
1173 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); 1173 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration);
1174 } 1174 }
1175 } 1175 }
1176 1176
1177 /*********************** YEARLY-BY-MONTH *******************************/ 1177 /*********************** YEARLY-BY-MONTH *******************************/
1178 else if (tmpStr.left(2) == "YM") { 1178 else if (tmpStr.left(2) == "YM") {
1179 int index = tmpStr.find(' '); 1179 int index = tmpStr.find(' ');
1180 int last = tmpStr.findRev(' ') + 1; 1180 int last = tmpStr.findRev(' ') + 1;
1181 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1181 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1182 index += 1; 1182 index += 1;
1183 short tmpMonth; 1183 short tmpMonth;
1184 if( index == last ) { 1184 if( index == last ) {
1185 // e.g. YM1 #0 1185 // e.g. YM1 #0
1186 tmpMonth = anEvent->dtStart().date().month(); 1186 tmpMonth = anEvent->dtStart().date().month();
1187 anEvent->recurrence()->addYearlyNum(tmpMonth); 1187 anEvent->recurrence()->addYearlyNum(tmpMonth);
1188 } 1188 }
1189 else { 1189 else {
1190 // e.g. YM1 3 #0 1190 // e.g. YM1 3 #0
1191 while (index < last) { 1191 while (index < last) {
1192 int index2 = tmpStr.find(' ', index); 1192 int index2 = tmpStr.find(' ', index);
1193 tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); 1193 tmpMonth = tmpStr.mid(index, (index2-index)).toShort();
1194 index = index2+1; 1194 index = index2+1;
1195 anEvent->recurrence()->addYearlyNum(tmpMonth); 1195 anEvent->recurrence()->addYearlyNum(tmpMonth);
1196 } // while != # 1196 } // while != #
1197 } 1197 }
1198 index = last; if (tmpStr.mid(index,1) == "#") index++; 1198 index = last; if (tmpStr.mid(index,1) == "#") index++;
1199 if (tmpStr.find('T', index) != -1) { 1199 if (tmpStr.find('T', index) != -1) {
1200 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1200 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1201 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); 1201 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate);
1202 } else { 1202 } else {
1203 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1203 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1204 if (rDuration == 0) 1204 if (rDuration == 0)
1205 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); 1205 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1);
1206 else 1206 else
1207 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); 1207 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration);
1208 } 1208 }
1209 } 1209 }
1210 1210
1211 /*********************** YEARLY-BY-DAY *********************************/ 1211 /*********************** YEARLY-BY-DAY *********************************/
1212 else if (tmpStr.left(2) == "YD") { 1212 else if (tmpStr.left(2) == "YD") {
1213 int index = tmpStr.find(' '); 1213 int index = tmpStr.find(' ');
1214 int last = tmpStr.findRev(' ') + 1; 1214 int last = tmpStr.findRev(' ') + 1;
1215 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1215 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1216 index += 1; 1216 index += 1;
1217 short tmpDay; 1217 short tmpDay;
1218 if( index == last ) { 1218 if( index == last ) {
1219 // e.g. YD1 #0 1219 // e.g. YD1 #0
1220 tmpDay = anEvent->dtStart().date().dayOfYear(); 1220 tmpDay = anEvent->dtStart().date().dayOfYear();
1221 anEvent->recurrence()->addYearlyNum(tmpDay); 1221 anEvent->recurrence()->addYearlyNum(tmpDay);
1222 } 1222 }
1223 else { 1223 else {
1224 // e.g. YD1 123 #0 1224 // e.g. YD1 123 #0
1225 while (index < last) { 1225 while (index < last) {
1226 int index2 = tmpStr.find(' ', index); 1226 int index2 = tmpStr.find(' ', index);
1227 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1227 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1228 index = index2+1; 1228 index = index2+1;
1229 anEvent->recurrence()->addYearlyNum(tmpDay); 1229 anEvent->recurrence()->addYearlyNum(tmpDay);
1230 } // while != # 1230 } // while != #
1231 } 1231 }
1232 index = last; if (tmpStr.mid(index,1) == "#") index++; 1232 index = last; if (tmpStr.mid(index,1) == "#") index++;
1233 if (tmpStr.find('T', index) != -1) { 1233 if (tmpStr.find('T', index) != -1) {
1234 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1234 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1235 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); 1235 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate);
1236 } else { 1236 } else {
1237 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1237 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1238 if (rDuration == 0) 1238 if (rDuration == 0)
1239 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); 1239 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1);
1240 else 1240 else
1241 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); 1241 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration);
1242 } 1242 }
1243 } else { 1243 } else {
1244 kdDebug(5800) << "we don't understand this type of recurrence!" << endl; 1244 kdDebug(5800) << "we don't understand this type of recurrence!" << endl;
1245 } // if 1245 } // if
1246 } // repeats 1246 } // repeats
1247 1247
1248 1248
1249 // recurrence exceptions 1249 // recurrence exceptions
1250 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { 1250 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) {
1251 s = fakeCString(vObjectUStringZValue(vo)); 1251 s = fakeCString(vObjectUStringZValue(vo));
1252 QStringList exDates = QStringList::split(",",s); 1252 QStringList exDates = QStringList::split(",",s);
1253 QStringList::ConstIterator it; 1253 QStringList::ConstIterator it;
1254 for(it = exDates.begin(); it != exDates.end(); ++it ) { 1254 for(it = exDates.begin(); it != exDates.end(); ++it ) {
1255 anEvent->addExDate(ISOToQDate(*it)); 1255 anEvent->addExDate(ISOToQDate(*it));
1256 } 1256 }
1257 deleteStr(s); 1257 deleteStr(s);
1258 } 1258 }
1259 1259
1260 // summary 1260 // summary
1261 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { 1261 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) {
1262 s = fakeCString(vObjectUStringZValue(vo)); 1262 s = fakeCString(vObjectUStringZValue(vo));
1263 anEvent->setSummary(QString::fromLocal8Bit(s)); 1263 anEvent->setSummary(QString::fromLocal8Bit(s));
1264 deleteStr(s); 1264 deleteStr(s);
1265 } 1265 }
1266 if ((vo = isAPropertyOf(vevent, VCLocationProp))) { 1266 if ((vo = isAPropertyOf(vevent, VCLocationProp))) {
1267 s = fakeCString(vObjectUStringZValue(vo)); 1267 s = fakeCString(vObjectUStringZValue(vo));
1268 anEvent->setLocation(QString::fromLocal8Bit(s)); 1268 anEvent->setLocation(QString::fromLocal8Bit(s));
1269 deleteStr(s); 1269 deleteStr(s);
1270 } 1270 }
1271 1271
1272 // description 1272 // description
1273 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { 1273 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) {
1274 s = fakeCString(vObjectUStringZValue(vo)); 1274 s = fakeCString(vObjectUStringZValue(vo));
1275 if (!anEvent->description().isEmpty()) { 1275 if (!anEvent->description().isEmpty()) {
1276 anEvent->setDescription(anEvent->description() + "\n" + 1276 anEvent->setDescription(anEvent->description() + "\n" +
1277 QString::fromLocal8Bit(s)); 1277 QString::fromLocal8Bit(s));
1278 } else { 1278 } else {
1279 anEvent->setDescription(QString::fromLocal8Bit(s)); 1279 anEvent->setDescription(QString::fromLocal8Bit(s));
1280 } 1280 }
1281 deleteStr(s); 1281 deleteStr(s);
1282 } 1282 }
1283 1283
1284 // some stupid vCal exporters ignore the standard and use Description 1284 // some stupid vCal exporters ignore the standard and use Description
1285 // instead of Summary for the default field. Correct for this. 1285 // instead of Summary for the default field. Correct for this.
1286 if (anEvent->summary().isEmpty() && 1286 if (anEvent->summary().isEmpty() &&
1287 !(anEvent->description().isEmpty())) { 1287 !(anEvent->description().isEmpty())) {
1288 QString tmpStr = anEvent->description().simplifyWhiteSpace(); 1288 QString tmpStr = anEvent->description().simplifyWhiteSpace();
1289 anEvent->setDescription(""); 1289 anEvent->setDescription("");
1290 anEvent->setSummary(tmpStr); 1290 anEvent->setSummary(tmpStr);
1291 } 1291 }
1292 1292
1293#if 0 1293#if 0
1294 // status 1294 // status
1295 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { 1295 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) {
1296 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); 1296 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo)));
1297 deleteStr(s); 1297 deleteStr(s);
1298// TODO: Define Event status 1298// TODO: Define Event status
1299// anEvent->setStatus(tmpStr); 1299// anEvent->setStatus(tmpStr);
1300 } 1300 }
1301 else 1301 else
1302// anEvent->setStatus("NEEDS ACTION"); 1302// anEvent->setStatus("NEEDS ACTION");
1303#endif 1303#endif
1304 1304
1305 // secrecy 1305 // secrecy
1306 int secrecy = Incidence::SecrecyPublic; 1306 int secrecy = Incidence::SecrecyPublic;
1307 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 1307 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
1308 s = fakeCString(vObjectUStringZValue(vo)); 1308 s = fakeCString(vObjectUStringZValue(vo));
1309 if (strcmp(s,"PRIVATE") == 0) { 1309 if (strcmp(s,"PRIVATE") == 0) {
1310 secrecy = Incidence::SecrecyPrivate; 1310 secrecy = Incidence::SecrecyPrivate;
1311 } else if (strcmp(s,"CONFIDENTIAL") == 0) { 1311 } else if (strcmp(s,"CONFIDENTIAL") == 0) {
1312 secrecy = Incidence::SecrecyConfidential; 1312 secrecy = Incidence::SecrecyConfidential;
1313 } 1313 }
1314 deleteStr(s); 1314 deleteStr(s);
1315 } 1315 }
1316 anEvent->setSecrecy(secrecy); 1316 anEvent->setSecrecy(secrecy);
1317 1317
1318 // categories 1318 // categories
1319 QStringList tmpStrList; 1319 QStringList tmpStrList;
1320 int index1 = 0; 1320 int index1 = 0;
1321 int index2 = 0; 1321 int index2 = 0;
1322 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { 1322 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1323 s = fakeCString(vObjectUStringZValue(vo)); 1323 s = fakeCString(vObjectUStringZValue(vo));
1324 QString categories = QString::fromLocal8Bit(s); 1324 QString categories = QString::fromLocal8Bit(s);
1325 deleteStr(s); 1325 deleteStr(s);
1326 //const char* category; 1326 //const char* category;
1327 QString category; 1327 QString category;
1328 while ((index2 = categories.find(',', index1)) != -1) { 1328 while ((index2 = categories.find(',', index1)) != -1) {
1329 //category = (const char *) categories.mid(index1, (index2 - index1)); 1329 //category = (const char *) categories.mid(index1, (index2 - index1));
1330 category = categories.mid(index1, (index2 - index1)); 1330 category = categories.mid(index1, (index2 - index1));
1331 tmpStrList.append(category); 1331 tmpStrList.append(category);
1332 index1 = index2+1; 1332 index1 = index2+1;
1333 } 1333 }
1334 // get last category 1334 // get last category
1335 category = categories.mid(index1, (categories.length()-index1)); 1335 category = categories.mid(index1, (categories.length()-index1));
1336 tmpStrList.append(category); 1336 tmpStrList.append(category);
1337 anEvent->setCategories(tmpStrList); 1337 anEvent->setCategories(tmpStrList);
1338 } 1338 }
1339 1339
1340 // attachments 1340 // attachments
1341 tmpStrList.clear(); 1341 tmpStrList.clear();
1342 initPropIterator(&voi, vevent); 1342 initPropIterator(&voi, vevent);
1343 while (moreIteration(&voi)) { 1343 while (moreIteration(&voi)) {
1344 vo = nextVObject(&voi); 1344 vo = nextVObject(&voi);
1345 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 1345 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1346 s = fakeCString(vObjectUStringZValue(vo)); 1346 s = fakeCString(vObjectUStringZValue(vo));
1347 anEvent->addAttachment(new Attachment(QString(s))); 1347 anEvent->addAttachment(new Attachment(QString(s)));
1348 deleteStr(s); 1348 deleteStr(s);
1349 } 1349 }
1350 } 1350 }
1351 1351
1352 // resources 1352 // resources
1353 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 1353 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1354 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1354 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1355 deleteStr(s); 1355 deleteStr(s);
1356 tmpStrList.clear(); 1356 tmpStrList.clear();
1357 index1 = 0; 1357 index1 = 0;
1358 index2 = 0; 1358 index2 = 0;
1359 QString resource; 1359 QString resource;
1360 while ((index2 = resources.find(';', index1)) != -1) { 1360 while ((index2 = resources.find(';', index1)) != -1) {
1361 resource = resources.mid(index1, (index2 - index1)); 1361 resource = resources.mid(index1, (index2 - index1));
1362 tmpStrList.append(resource); 1362 tmpStrList.append(resource);
1363 index1 = index2; 1363 index1 = index2;
1364 } 1364 }
1365 anEvent->setResources(tmpStrList); 1365 anEvent->setResources(tmpStrList);
1366 } 1366 }
1367 1367
1368 /* alarm stuff */ 1368 /* alarm stuff */
1369 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1369 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1370 Alarm* alarm = anEvent->newAlarm(); 1370 Alarm* alarm = anEvent->newAlarm();
1371 VObject *a; 1371 VObject *a;
1372 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1372 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1373 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1373 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1374 deleteStr(s); 1374 deleteStr(s);
1375 } 1375 }
1376 alarm->setEnabled(true); 1376 alarm->setEnabled(true);
1377 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1377 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1378 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1378 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1379 s = fakeCString(vObjectUStringZValue(a)); 1379 s = fakeCString(vObjectUStringZValue(a));
1380 alarm->setProcedureAlarm(QFile::decodeName(s)); 1380 alarm->setProcedureAlarm(QFile::decodeName(s));
1381 deleteStr(s); 1381 deleteStr(s);
1382 } 1382 }
1383 } 1383 }
1384 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1384 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1385 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1385 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1386 s = fakeCString(vObjectUStringZValue(a)); 1386 s = fakeCString(vObjectUStringZValue(a));
1387 alarm->setAudioAlarm(QFile::decodeName(s)); 1387 alarm->setAudioAlarm(QFile::decodeName(s));
1388 deleteStr(s); 1388 deleteStr(s);
1389 } 1389 }
1390 } 1390 }
1391 } 1391 }
1392 1392
1393 // priority 1393 // priority
1394 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1394 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1395 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1395 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1396 deleteStr(s); 1396 deleteStr(s);
1397 } 1397 }
1398 1398
1399 // transparency 1399 // transparency
1400 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1400 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1401 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1401 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1402 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1402 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1403 deleteStr(s); 1403 deleteStr(s);
1404 } 1404 }
1405 1405
1406 // related event 1406 // related event
1407 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1407 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1408 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1408 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1409 deleteStr(s); 1409 deleteStr(s);
1410 mEventsRelate.append(anEvent); 1410 mEventsRelate.append(anEvent);
1411 } 1411 }
1412 1412
1413 /* PILOT SYNC STUFF */ 1413 /* PILOT SYNC STUFF */
1414 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1414 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1415 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1415 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1416 deleteStr(s); 1416 deleteStr(s);
1417 } 1417 }
1418 else 1418 else
1419 anEvent->setPilotId(0); 1419 anEvent->setPilotId(0);
1420 1420
1421 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1421 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1422 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1422 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1423 deleteStr(s); 1423 deleteStr(s);
1424 } 1424 }
1425 else 1425 else
1426 anEvent->setSyncStatus(Event::SYNCMOD); 1426 anEvent->setSyncStatus(Event::SYNCMOD);
1427 1427
1428 return anEvent; 1428 return anEvent;
1429} 1429}
1430 1430
1431 1431
1432QString VCalFormat::qDateToISO(const QDate &qd) 1432QString VCalFormat::qDateToISO(const QDate &qd)
1433{ 1433{
1434 QString tmpStr; 1434 QString tmpStr;
1435 1435
1436 ASSERT(qd.isValid()); 1436 ASSERT(qd.isValid());
1437 1437
1438 tmpStr.sprintf("%.2d%.2d%.2d", 1438 tmpStr.sprintf("%.2d%.2d%.2d",
1439 qd.year(), qd.month(), qd.day()); 1439 qd.year(), qd.month(), qd.day());
1440 return tmpStr; 1440 return tmpStr;
1441 1441
1442} 1442}
1443 1443
1444QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1444QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1445{ 1445{
1446 QString tmpStr; 1446 QString tmpStr;
1447 1447
1448 ASSERT(qdt.date().isValid()); 1448 ASSERT(qdt.date().isValid());
1449 ASSERT(qdt.time().isValid()); 1449 ASSERT(qdt.time().isValid());
1450 if (zulu && !useLocalTime ) { 1450 if (zulu && !useLocalTime ) {
1451 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); 1451 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60);
1452 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1452 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1453 tmpDT.date().year(), tmpDT.date().month(), 1453 tmpDT.date().year(), tmpDT.date().month(),
1454 tmpDT.date().day(), tmpDT.time().hour(), 1454 tmpDT.date().day(), tmpDT.time().hour(),
1455 tmpDT.time().minute(), tmpDT.time().second()); 1455 tmpDT.time().minute(), tmpDT.time().second());
1456 } else { 1456 } else {
1457 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1457 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1458 qdt.date().year(), qdt.date().month(), 1458 qdt.date().year(), qdt.date().month(),
1459 qdt.date().day(), qdt.time().hour(), 1459 qdt.date().day(), qdt.time().hour(),
1460 qdt.time().minute(), qdt.time().second()); 1460 qdt.time().minute(), qdt.time().second());
1461 } 1461 }
1462 return tmpStr; 1462 return tmpStr;
1463} 1463}
1464 1464
1465QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1465QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1466{ 1466{
1467 QDate tmpDate; 1467 QDate tmpDate;
1468 QTime tmpTime; 1468 QTime tmpTime;
1469 QString tmpStr; 1469 QString tmpStr;
1470 int year, month, day, hour, minute, second; 1470 int year, month, day, hour, minute, second;
1471 1471
1472 tmpStr = dtStr; 1472 tmpStr = dtStr;
1473 year = tmpStr.left(4).toInt(); 1473 year = tmpStr.left(4).toInt();
1474 month = tmpStr.mid(4,2).toInt(); 1474 month = tmpStr.mid(4,2).toInt();
1475 day = tmpStr.mid(6,2).toInt(); 1475 day = tmpStr.mid(6,2).toInt();
1476 hour = tmpStr.mid(9,2).toInt(); 1476 hour = tmpStr.mid(9,2).toInt();
1477 minute = tmpStr.mid(11,2).toInt(); 1477 minute = tmpStr.mid(11,2).toInt();
1478 second = tmpStr.mid(13,2).toInt(); 1478 second = tmpStr.mid(13,2).toInt();
1479 tmpDate.setYMD(year, month, day); 1479 tmpDate.setYMD(year, month, day);
1480 tmpTime.setHMS(hour, minute, second); 1480 tmpTime.setHMS(hour, minute, second);
1481 1481
1482 ASSERT(tmpDate.isValid()); 1482 ASSERT(tmpDate.isValid());
1483 ASSERT(tmpTime.isValid()); 1483 ASSERT(tmpTime.isValid());
1484 QDateTime tmpDT(tmpDate, tmpTime); 1484 QDateTime tmpDT(tmpDate, tmpTime);
1485 // correct for GMT if string is in Zulu format 1485 // correct for GMT if string is in Zulu format
1486 if (dtStr.at(dtStr.length()-1) == 'Z') 1486 if (dtStr.at(dtStr.length()-1) == 'Z')
1487 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); 1487 tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60);
1488 return tmpDT; 1488 return tmpDT;
1489} 1489}
1490 1490
1491QDate VCalFormat::ISOToQDate(const QString &dateStr) 1491QDate VCalFormat::ISOToQDate(const QString &dateStr)
1492{ 1492{
1493 int year, month, day; 1493 int year, month, day;
1494 1494
1495 year = dateStr.left(4).toInt(); 1495 year = dateStr.left(4).toInt();
1496 month = dateStr.mid(4,2).toInt(); 1496 month = dateStr.mid(4,2).toInt();
1497 day = dateStr.mid(6,2).toInt(); 1497 day = dateStr.mid(6,2).toInt();
1498 1498
1499 return(QDate(year, month, day)); 1499 return(QDate(year, month, day));
1500} 1500}
1501 1501
1502// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1502// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1503// and break it down from it's tree-like format into the dictionary format 1503// and break it down from it's tree-like format into the dictionary format
1504// that is used internally in the VCalFormat. 1504// that is used internally in the VCalFormat.
1505void VCalFormat::populate(VObject *vcal) 1505void VCalFormat::populate(VObject *vcal)
1506{ 1506{
1507 // this function will populate the caldict dictionary and other event 1507 // this function will populate the caldict dictionary and other event
1508 // lists. It turns vevents into Events and then inserts them. 1508 // lists. It turns vevents into Events and then inserts them.
1509 1509
1510 VObjectIterator i; 1510 VObjectIterator i;
1511 VObject *curVO, *curVOProp; 1511 VObject *curVO, *curVOProp;
1512 Event *anEvent; 1512 Event *anEvent;
1513 1513
1514 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1514 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1515 char *methodType = 0; 1515 char *methodType = 0;
1516 methodType = fakeCString(vObjectUStringZValue(curVO)); 1516 methodType = fakeCString(vObjectUStringZValue(curVO));
1517 kdDebug() << "This calendar is an iTIP transaction of type '" 1517 kdDebug() << "This calendar is an iTIP transaction of type '"
1518 << methodType << "'" << endl; 1518 << methodType << "'" << endl;
1519 delete methodType; 1519 delete methodType;
1520 } 1520 }
1521 1521
1522 // warn the user that we might have trouble reading non-known calendar. 1522 // warn the user that we might have trouble reading non-known calendar.
1523 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1523 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1524 char *s = fakeCString(vObjectUStringZValue(curVO)); 1524 char *s = fakeCString(vObjectUStringZValue(curVO));
1525 if (strcmp(productId().local8Bit(), s) != 0) 1525 if (strcmp(productId().local8Bit(), s) != 0)
1526 kdDebug() << "This vCalendar file was not created by KOrganizer " 1526 kdDebug() << "This vCalendar file was not created by KOrganizer "
1527 "or any other product we support. Loading anyway..." << endl; 1527 "or any other product we support. Loading anyway..." << endl;
1528 mLoadedProductId = s; 1528 mLoadedProductId = s;
1529 deleteStr(s); 1529 deleteStr(s);
1530 } 1530 }
1531 1531
1532 // warn the user we might have trouble reading this unknown version. 1532 // warn the user we might have trouble reading this unknown version.
1533 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1533 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1534 char *s = fakeCString(vObjectUStringZValue(curVO)); 1534 char *s = fakeCString(vObjectUStringZValue(curVO));
1535 if (strcmp(_VCAL_VERSION, s) != 0) 1535 if (strcmp(_VCAL_VERSION, s) != 0)
1536 kdDebug() << "This vCalendar file has version " << s 1536 kdDebug() << "This vCalendar file has version " << s
1537 << "We only support " << _VCAL_VERSION << endl; 1537 << "We only support " << _VCAL_VERSION << endl;
1538 deleteStr(s); 1538 deleteStr(s);
1539 } 1539 }
1540 1540
1541 // set the time zone 1541 // set the time zone
1542 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1542 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1543 char *s = fakeCString(vObjectUStringZValue(curVO)); 1543 char *s = fakeCString(vObjectUStringZValue(curVO));
1544 mCalendar->setTimeZone(s); 1544 mCalendar->setTimeZone(s);
1545 deleteStr(s); 1545 deleteStr(s);
1546 } 1546 }
1547 1547
1548 1548
1549 // Store all events with a relatedTo property in a list for post-processing 1549 // Store all events with a relatedTo property in a list for post-processing
1550 mEventsRelate.clear(); 1550 mEventsRelate.clear();
1551 mTodosRelate.clear(); 1551 mTodosRelate.clear();
1552 1552
1553 initPropIterator(&i, vcal); 1553 initPropIterator(&i, vcal);
1554 1554
1555 // go through all the vobjects in the vcal 1555 // go through all the vobjects in the vcal
1556 while (moreIteration(&i)) { 1556 while (moreIteration(&i)) {
1557 curVO = nextVObject(&i); 1557 curVO = nextVObject(&i);
1558 1558
1559 /************************************************************************/ 1559 /************************************************************************/
1560 1560
1561 // now, check to see that the object is an event or todo. 1561 // now, check to see that the object is an event or todo.
1562 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1562 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1563 1563
1564 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { 1564 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) {
1565 char *s; 1565 char *s;
1566 s = fakeCString(vObjectUStringZValue(curVOProp)); 1566 s = fakeCString(vObjectUStringZValue(curVOProp));
1567 // check to see if event was deleted by the kpilot conduit 1567 // check to see if event was deleted by the kpilot conduit
1568 if (atoi(s) == Event::SYNCDEL) { 1568 if (atoi(s) == Event::SYNCDEL) {
1569 deleteStr(s); 1569 deleteStr(s);
1570 kdDebug(5800) << "skipping pilot-deleted event" << endl; 1570 kdDebug(5800) << "skipping pilot-deleted event" << endl;
1571 goto SKIP; 1571 goto SKIP;
1572 } 1572 }
1573 deleteStr(s); 1573 deleteStr(s);
1574 } 1574 }
1575 1575
1576 // this code checks to see if we are trying to read in an event 1576 // this code checks to see if we are trying to read in an event
1577 // that we already find to be in the calendar. If we find this 1577 // that we already find to be in the calendar. If we find this
1578 // to be the case, we skip the event. 1578 // to be the case, we skip the event.
1579 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1579 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1580 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1580 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1581 QString tmpStr(s); 1581 QString tmpStr(s);
1582 deleteStr(s); 1582 deleteStr(s);
1583 1583
1584 if (mCalendar->event(tmpStr)) { 1584 if (mCalendar->event(tmpStr)) {
1585 goto SKIP; 1585 goto SKIP;
1586 } 1586 }
1587 if (mCalendar->todo(tmpStr)) { 1587 if (mCalendar->todo(tmpStr)) {
1588 goto SKIP; 1588 goto SKIP;
1589 } 1589 }
1590 } 1590 }
1591 1591
1592 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1592 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1593 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 1593 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1594 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 1594 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1595 goto SKIP; 1595 goto SKIP;
1596 } 1596 }
1597 1597
1598 anEvent = VEventToEvent(curVO); 1598 anEvent = VEventToEvent(curVO);
1599 // we now use addEvent instead of insertEvent so that the 1599 // we now use addEvent instead of insertEvent so that the
1600 // signal/slot get connected. 1600 // signal/slot get connected.
1601 if (anEvent) { 1601 if (anEvent) {
1602 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { 1602 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) {
1603 kdDebug() << "VCalFormat::populate(): Event has invalid dates." 1603 kdDebug() << "VCalFormat::populate(): Event has invalid dates."
1604 << endl; 1604 << endl;
1605 } else { 1605 } else {
1606 mCalendar->addEvent(anEvent); 1606 mCalendar->addEvent(anEvent);
1607 } 1607 }
1608 } else { 1608 } else {
1609 // some sort of error must have occurred while in translation. 1609 // some sort of error must have occurred while in translation.
1610 goto SKIP; 1610 goto SKIP;
1611 } 1611 }
1612 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 1612 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1613 Todo *aTodo = VTodoToEvent(curVO); 1613 Todo *aTodo = VTodoToEvent(curVO);
1614 mCalendar->addTodo(aTodo); 1614 mCalendar->addTodo(aTodo);
1615 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 1615 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1616 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 1616 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1617 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 1617 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1618 // do nothing, we know these properties and we want to skip them. 1618 // do nothing, we know these properties and we want to skip them.
1619 // we have either already processed them or are ignoring them. 1619 // we have either already processed them or are ignoring them.
1620 ; 1620 ;
1621 } else { 1621 } else {
1622 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; 1622 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl;
1623 } 1623 }
1624 SKIP: 1624 SKIP:
1625 ; 1625 ;
1626 } // while 1626 } // while
1627 1627
1628 // Post-Process list of events with relations, put Event objects in relation 1628 // Post-Process list of events with relations, put Event objects in relation
1629 Event *ev; 1629 Event *ev;
1630 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 1630 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
1631 ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); 1631 ev->setRelatedTo(mCalendar->event(ev->relatedToUid()));
1632 } 1632 }
1633 Todo *todo; 1633 Todo *todo;
1634 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 1634 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
1635 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); 1635 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid()));
1636 } 1636 }
1637} 1637}
1638 1638
1639const char *VCalFormat::dayFromNum(int day) 1639const char *VCalFormat::dayFromNum(int day)
1640{ 1640{
1641 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; 1641 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " };
1642 1642
1643 return days[day]; 1643 return days[day];
1644} 1644}
1645 1645
1646int VCalFormat::numFromDay(const QString &day) 1646int VCalFormat::numFromDay(const QString &day)
1647{ 1647{
1648 if (day == "MO ") return 0; 1648 if (day == "MO ") return 0;
1649 if (day == "TU ") return 1; 1649 if (day == "TU ") return 1;
1650 if (day == "WE ") return 2; 1650 if (day == "WE ") return 2;
1651 if (day == "TH ") return 3; 1651 if (day == "TH ") return 3;
1652 if (day == "FR ") return 4; 1652 if (day == "FR ") return 4;
1653 if (day == "SA ") return 5; 1653 if (day == "SA ") return 5;
1654 if (day == "SU ") return 6; 1654 if (day == "SU ") return 6;
1655 1655
1656 return -1; // something bad happened. :) 1656 return -1; // something bad happened. :)
1657} 1657}
1658 1658
1659Attendee::PartStat VCalFormat::readStatus(const char *s) const 1659Attendee::PartStat VCalFormat::readStatus(const char *s) const
1660{ 1660{
1661 QString statStr = s; 1661 QString statStr = s;
1662 statStr = statStr.upper(); 1662 statStr = statStr.upper();
1663 Attendee::PartStat status; 1663 Attendee::PartStat status;
1664 1664
1665 if (statStr == "X-ACTION") 1665 if (statStr == "X-ACTION")
1666 status = Attendee::NeedsAction; 1666 status = Attendee::NeedsAction;
1667 else if (statStr == "NEEDS ACTION") 1667 else if (statStr == "NEEDS ACTION")
1668 status = Attendee::NeedsAction; 1668 status = Attendee::NeedsAction;
1669 else if (statStr== "ACCEPTED") 1669 else if (statStr== "ACCEPTED")
1670 status = Attendee::Accepted; 1670 status = Attendee::Accepted;
1671 else if (statStr== "SENT") 1671 else if (statStr== "SENT")
1672 status = Attendee::NeedsAction; 1672 status = Attendee::NeedsAction;
1673 else if (statStr== "TENTATIVE") 1673 else if (statStr== "TENTATIVE")
1674 status = Attendee::Tentative; 1674 status = Attendee::Tentative;
1675 else if (statStr== "CONFIRMED") 1675 else if (statStr== "CONFIRMED")
1676 status = Attendee::Accepted; 1676 status = Attendee::Accepted;
1677 else if (statStr== "DECLINED") 1677 else if (statStr== "DECLINED")
1678 status = Attendee::Declined; 1678 status = Attendee::Declined;
1679 else if (statStr== "COMPLETED") 1679 else if (statStr== "COMPLETED")
1680 status = Attendee::Completed; 1680 status = Attendee::Completed;
1681 else if (statStr== "DELEGATED") 1681 else if (statStr== "DELEGATED")
1682 status = Attendee::Delegated; 1682 status = Attendee::Delegated;
1683 else { 1683 else {
1684 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; 1684 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl;
1685 status = Attendee::NeedsAction; 1685 status = Attendee::NeedsAction;
1686 } 1686 }
1687 1687
1688 return status; 1688 return status;
1689} 1689}
1690 1690
1691QCString VCalFormat::writeStatus(Attendee::PartStat status) const 1691QCString VCalFormat::writeStatus(Attendee::PartStat status) const
1692{ 1692{
1693 switch(status) { 1693 switch(status) {
1694 default: 1694 default:
1695 case Attendee::NeedsAction: 1695 case Attendee::NeedsAction:
1696 return "NEEDS ACTION"; 1696 return "NEEDS ACTION";
1697 break; 1697 break;
1698 case Attendee::Accepted: 1698 case Attendee::Accepted:
1699 return "ACCEPTED"; 1699 return "ACCEPTED";
1700 break; 1700 break;
1701 case Attendee::Declined: 1701 case Attendee::Declined:
1702 return "DECLINED"; 1702 return "DECLINED";
1703 break; 1703 break;
1704 case Attendee::Tentative: 1704 case Attendee::Tentative:
1705 return "TENTATIVE"; 1705 return "TENTATIVE";
1706 break; 1706 break;
1707 case Attendee::Delegated: 1707 case Attendee::Delegated:
1708 return "DELEGATED"; 1708 return "DELEGATED";
1709 break; 1709 break;
1710 case Attendee::Completed: 1710 case Attendee::Completed:
1711 return "COMPLETED"; 1711 return "COMPLETED";
1712 break; 1712 break;
1713 case Attendee::InProcess: 1713 case Attendee::InProcess:
1714 return "NEEDS ACTION"; 1714 return "NEEDS ACTION";
1715 break; 1715 break;
1716 } 1716 }
1717} 1717}