summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 00285a5..29c530b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4010 +1,4046 @@
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#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 110#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 111#include "statusdialog.h"
112#include "kdatenavigator.h" 112#include "kdatenavigator.h"
113#include "kotodoview.h" 113#include "kotodoview.h"
114#include "datenavigator.h" 114#include "datenavigator.h"
115#include "resourceview.h" 115#include "resourceview.h"
116#include "navigatorbar.h" 116#include "navigatorbar.h"
117#include "searchdialog.h" 117#include "searchdialog.h"
118#include "mainwindow.h" 118#include "mainwindow.h"
119 119
120#include "calendarview.h" 120#include "calendarview.h"
121#ifndef DESKTOP_VERSION 121#ifndef DESKTOP_VERSION
122#include <qtopia/alarmserver.h> 122#include <qtopia/alarmserver.h>
123#endif 123#endif
124#ifndef _WIN32_ 124#ifndef _WIN32_
125#include <stdlib.h> 125#include <stdlib.h>
126#include <stdio.h> 126#include <stdio.h>
127#include <unistd.h> 127#include <unistd.h>
128#else 128#else
129#include <qprocess.h> 129#include <qprocess.h>
130#endif 130#endif
131 131
132#ifdef DESKTOP_VERSION 132#ifdef DESKTOP_VERSION
133#include <kabc/stdaddressbook.h> 133#include <kabc/stdaddressbook.h>
134#endif 134#endif
135using namespace KOrg; 135using namespace KOrg;
136using namespace KCal; 136using namespace KCal;
137extern int globalFlagBlockAgenda; 137extern int globalFlagBlockAgenda;
138extern int globalFlagBlockStartup; 138extern int globalFlagBlockStartup;
139 139
140 140
141 141
142class KOBeamPrefs : public QDialog 142class KOBeamPrefs : public QDialog
143{ 143{
144 public: 144 public:
145 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 145 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
146 QDialog( parent, name, true ) 146 QDialog( parent, name, true )
147 { 147 {
148 setCaption( i18n("Beam Options") ); 148 setCaption( i18n("Beam Options") );
149 QVBoxLayout* lay = new QVBoxLayout( this ); 149 QVBoxLayout* lay = new QVBoxLayout( this );
150 lay->setSpacing( 3 ); 150 lay->setSpacing( 3 );
151 lay->setMargin( 3 ); 151 lay->setMargin( 3 );
152 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 152 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
153 lay->addWidget( format ); 153 lay->addWidget( format );
154 format->setExclusive ( true ) ; 154 format->setExclusive ( true ) ;
155 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 155 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
156 lay->addWidget( time ); time->setExclusive ( true ) ; 156 lay->addWidget( time ); time->setExclusive ( true ) ;
157 vcal = new QRadioButton(" vCalendar ", format ); 157 vcal = new QRadioButton(" vCalendar ", format );
158 ical = new QRadioButton(" iCalendar ", format ); 158 ical = new QRadioButton(" iCalendar ", format );
159 vcal->setChecked( true ); 159 vcal->setChecked( true );
160 tz = new QRadioButton(i18n(" With timezone "), time ); 160 tz = new QRadioButton(i18n(" With timezone "), time );
161 local = new QRadioButton(i18n(" Local time "), time ); 161 local = new QRadioButton(i18n(" Local time "), time );
162 tz->setChecked( true ); 162 tz->setChecked( true );
163 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 163 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
164 lay->addWidget( ok ); 164 lay->addWidget( ok );
165 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 165 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
166 lay->addWidget( cancel ); 166 lay->addWidget( cancel );
167 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 167 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
168 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 168 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
169 resize( 200, 200 ); 169 resize( 200, 200 );
170 } 170 }
171 171
172 bool beamVcal() { return vcal->isChecked(); } 172 bool beamVcal() { return vcal->isChecked(); }
173 bool beamLocal() { return local->isChecked(); } 173 bool beamLocal() { return local->isChecked(); }
174private: 174private:
175 QRadioButton* vcal, *ical, *local, *tz; 175 QRadioButton* vcal, *ical, *local, *tz;
176}; 176};
177class KOCatPrefs : public QDialog 177class KOCatPrefs : public QDialog
178{ 178{
179 public: 179 public:
180 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 180 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
181 QDialog( parent, name, true ) 181 QDialog( parent, name, true )
182 { 182 {
183 setCaption( i18n("Manage new Categories") ); 183 setCaption( i18n("Manage new Categories") );
184 QVBoxLayout* lay = new QVBoxLayout( this ); 184 QVBoxLayout* lay = new QVBoxLayout( this );
185 lay->setSpacing( 3 ); 185 lay->setSpacing( 3 );
186 lay->setMargin( 3 ); 186 lay->setMargin( 3 );
187 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 ); 187 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 );
188 lay->addWidget( lab ); 188 lay->addWidget( lab );
189 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 189 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
190 lay->addWidget( format ); 190 lay->addWidget( format );
191 format->setExclusive ( true ) ; 191 format->setExclusive ( true ) ;
192 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 192 addCatBut = new QRadioButton(i18n("Add to category list"), format );
193 new QRadioButton(i18n("Remove from Events/Todos"), format ); 193 new QRadioButton(i18n("Remove from Events/Todos"), format );
194 addCatBut->setChecked( true ); 194 addCatBut->setChecked( true );
195 QPushButton * ok = new QPushButton( i18n("OK"), this ); 195 QPushButton * ok = new QPushButton( i18n("OK"), this );
196 lay->addWidget( ok ); 196 lay->addWidget( ok );
197 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 197 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
198 lay->addWidget( cancel ); 198 lay->addWidget( cancel );
199 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 199 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
200 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 200 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
201 resize( 200, 200 ); 201 resize( 200, 200 );
202 } 202 }
203 203
204 bool addCat() { return addCatBut->isChecked(); } 204 bool addCat() { return addCatBut->isChecked(); }
205private: 205private:
206 QRadioButton* addCatBut; 206 QRadioButton* addCatBut;
207}; 207};
208 208
209 209
210 210
211CalendarView::CalendarView( CalendarResources *calendar, 211CalendarView::CalendarView( CalendarResources *calendar,
212 QWidget *parent, const char *name ) 212 QWidget *parent, const char *name )
213 : CalendarViewBase( parent, name ), 213 : CalendarViewBase( parent, name ),
214 mCalendar( calendar ), 214 mCalendar( calendar ),
215 mResourceManager( calendar->resourceManager() ) 215 mResourceManager( calendar->resourceManager() )
216{ 216{
217 217
218 mEventEditor = 0; 218 mEventEditor = 0;
219 mTodoEditor = 0; 219 mTodoEditor = 0;
220 220
221 init(); 221 init();
222} 222}
223 223
224CalendarView::CalendarView( Calendar *calendar, 224CalendarView::CalendarView( Calendar *calendar,
225 QWidget *parent, const char *name ) 225 QWidget *parent, const char *name )
226 : CalendarViewBase( parent, name ), 226 : CalendarViewBase( parent, name ),
227 mCalendar( calendar ), 227 mCalendar( calendar ),
228 mResourceManager( 0 ) 228 mResourceManager( 0 )
229{ 229{
230 230
231 mEventEditor = 0; 231 mEventEditor = 0;
232 mTodoEditor = 0; 232 mTodoEditor = 0;
233 init(); 233 init();
234} 234}
235 235
236void CalendarView::init() 236void CalendarView::init()
237{ 237{
238 238
239 setFocusPolicy ( WheelFocus ); 239 setFocusPolicy ( WheelFocus );
240 mViewerCallerIsSearchDialog = false; 240 mViewerCallerIsSearchDialog = false;
241 mBlockShowDates = false; 241 mBlockShowDates = false;
242 beamDialog = new KOBeamPrefs(); 242 beamDialog = new KOBeamPrefs();
243 mDatePickerMode = 0; 243 mDatePickerMode = 0;
244 mCurrentSyncDevice = ""; 244 mCurrentSyncDevice = "";
245 writeLocale(); 245 writeLocale();
246 mViewManager = new KOViewManager( this ); 246 mViewManager = new KOViewManager( this );
247 mDialogManager = new KODialogManager( this ); 247 mDialogManager = new KODialogManager( this );
248 mEventViewerDialog = 0; 248 mEventViewerDialog = 0;
249 mModified = false; 249 mModified = false;
250 mReadOnly = false; 250 mReadOnly = false;
251 mSelectedIncidence = 0; 251 mSelectedIncidence = 0;
252 mCalPrinter = 0; 252 mCalPrinter = 0;
253 mFilters.setAutoDelete(true); 253 mFilters.setAutoDelete(true);
254 254
255 mCalendar->registerObserver( this ); 255 mCalendar->registerObserver( this );
256 // TODO: Make sure that view is updated, when calendar is changed. 256 // TODO: Make sure that view is updated, when calendar is changed.
257 257
258 mStorage = new FileStorage( mCalendar ); 258 mStorage = new FileStorage( mCalendar );
259 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 259 mNavigator = new DateNavigator( this, "datevav", mViewManager );
260 260
261 QBoxLayout *topLayout = (QBoxLayout*)layout(); 261 QBoxLayout *topLayout = (QBoxLayout*)layout();
262#ifndef KORG_NOSPLITTER 262#ifndef KORG_NOSPLITTER
263 // create the main layout frames. 263 // create the main layout frames.
264 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 264 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
265 topLayout->addWidget(mPanner); 265 topLayout->addWidget(mPanner);
266 266
267 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 267 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
268 "CalendarView::LeftFrame"); 268 "CalendarView::LeftFrame");
269 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 269 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
270 270
271 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 271 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
272 "CalendarView::DateNavigator" ); 272 "CalendarView::DateNavigator" );
273 273
274 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 274 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
275 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 275 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
276 mTodoList->setNavigator( mNavigator ); 276 mTodoList->setNavigator( mNavigator );
277 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 277 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
278 278
279#ifdef KORG_NORESOURCEVIEW 279#ifdef KORG_NORESOURCEVIEW
280 mResourceView = 0; 280 mResourceView = 0;
281#else 281#else
282 if ( mResourceManager ) { 282 if ( mResourceManager ) {
283 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 283 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
284 mResourceView->updateView(); 284 mResourceView->updateView();
285 connect( mResourceView, SIGNAL( resourcesChanged() ), 285 connect( mResourceView, SIGNAL( resourcesChanged() ),
286 SLOT( updateView() ) ); 286 SLOT( updateView() ) );
287 } else { 287 } else {
288 mResourceView = 0; 288 mResourceView = 0;
289 } 289 }
290#endif 290#endif
291 QWidget *rightBox = new QWidget( mPanner ); 291 QWidget *rightBox = new QWidget( mPanner );
292 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 292 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
293 293
294 mRightFrame = new QWidgetStack( rightBox ); 294 mRightFrame = new QWidgetStack( rightBox );
295 rightLayout->addWidget( mRightFrame, 1 ); 295 rightLayout->addWidget( mRightFrame, 1 );
296 296
297 mLeftFrame = mLeftSplitter; 297 mLeftFrame = mLeftSplitter;
298#else 298#else
299 QWidget *mainBox = new QWidget( this ); 299 QWidget *mainBox = new QWidget( this );
300 //QWidget *leftFrame = new QWidget( mainBox ); 300 //QWidget *leftFrame = new QWidget( mainBox );
301 QBoxLayout * mainBoxLayout; 301 QBoxLayout * mainBoxLayout;
302 if ( KOPrefs::instance()->mVerticalScreen ) { 302 if ( KOPrefs::instance()->mVerticalScreen ) {
303 mainBoxLayout = new QVBoxLayout(mainBox); 303 mainBoxLayout = new QVBoxLayout(mainBox);
304 //leftFrameLayout = new QHBoxLayout(leftFrame ); 304 //leftFrameLayout = new QHBoxLayout(leftFrame );
305 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mainBox);; 305 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mainBox);;
306 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left ); 306 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left );
307 } else { 307 } else {
308 mainBoxLayout = new QHBoxLayout(mainBox); 308 mainBoxLayout = new QHBoxLayout(mainBox);
309 //leftFrameLayout = new QVBoxLayout(leftFrame ); 309 //leftFrameLayout = new QVBoxLayout(leftFrame );
310 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mainBox);; 310 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mainBox);;
311 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 311 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
312 } 312 }
313 //QBoxLayout * leftFrameLayout; 313 //QBoxLayout * leftFrameLayout;
314 topLayout->addWidget( mainBox ); 314 topLayout->addWidget( mainBox );
315 mainBoxLayout->addWidget (mLeftFrame); 315 mainBoxLayout->addWidget (mLeftFrame);
316 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 316 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
317 "CalendarView::DateNavigator" ); 317 "CalendarView::DateNavigator" );
318#if 0 318#if 0
319 // FIXME 319 // FIXME
320 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 320 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
321 "CalendarView::DateNavigator", QDate::currentDate()); 321 "CalendarView::DateNavigator", QDate::currentDate());
322#endif 322#endif
323 // mDateNavigator->blockSignals( true ); 323 // mDateNavigator->blockSignals( true );
324 //leftFrameLayout->addWidget( mDateNavigator ); 324 //leftFrameLayout->addWidget( mDateNavigator );
325 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 325 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
326 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 326 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
327 mTodoList->setNavigator( mNavigator ); 327 mTodoList->setNavigator( mNavigator );
328#if 0 328#if 0
329 if ( QApplication::desktop()->width() < 480 ) { 329 if ( QApplication::desktop()->width() < 480 ) {
330 leftFrameLayout->addWidget(mFilterView); 330 leftFrameLayout->addWidget(mFilterView);
331 leftFrameLayout->addWidget(mTodoList, 2 ); 331 leftFrameLayout->addWidget(mTodoList, 2 );
332 332
333 } else { 333 } else {
334 leftFrameLayout->addWidget(mTodoList,2 ); 334 leftFrameLayout->addWidget(mTodoList,2 );
335 leftFrameLayout->addWidget(mFilterView ); 335 leftFrameLayout->addWidget(mFilterView );
336 } 336 }
337#endif 337#endif
338 mFilterView->hide(); 338 mFilterView->hide();
339 QWidget *rightBox = new QWidget( mainBox ); 339 QWidget *rightBox = new QWidget( mainBox );
340 mainBoxLayout->addWidget ( rightBox, 10 ); 340 mainBoxLayout->addWidget ( rightBox, 10 );
341 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 341 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
342 mRightFrame = new QWidgetStack( rightBox ); 342 mRightFrame = new QWidgetStack( rightBox );
343 rightLayout->addWidget( mRightFrame, 10 ); 343 rightLayout->addWidget( mRightFrame, 10 );
344 344
345 //mLeftFrame = (QWidget *)leftFrame; 345 //mLeftFrame = (QWidget *)leftFrame;
346 if ( KOPrefs::instance()->mVerticalScreen ) { 346 if ( KOPrefs::instance()->mVerticalScreen ) {
347 mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 347 mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
348 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 348 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
349 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 349 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
350 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 350 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
351 } else { 351 } else {
352 mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 352 mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
353 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 353 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
354 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 354 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
355 } 355 }
356 if ( !KOPrefs::instance()->mShowDateNavigator) 356 if ( !KOPrefs::instance()->mShowDateNavigator)
357 mLeftFrame->toggle(); 357 mDateNavigator->hide();
358 //qDebug("Calendarview Size %d %d ", width(), height()); 358 //qDebug("Calendarview Size %d %d ", width(), height());
359#endif 359#endif
360 360
361 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 361 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
362 SLOT( showDates( const KCal::DateList & ) ) ); 362 SLOT( showDates( const KCal::DateList & ) ) );
363 363
364 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 364 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
365 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 365 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
366 366
367 367
368 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 368 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
369 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 369 mNavigator, SLOT( selectWeek( const QDate & ) ) );
370 370
371 connect( mDateNavigator, SIGNAL( goPrevYear() ), 371 connect( mDateNavigator, SIGNAL( goPrevYear() ),
372 mNavigator, SLOT( selectPreviousYear() ) ); 372 mNavigator, SLOT( selectPreviousYear() ) );
373 connect( mDateNavigator, SIGNAL( goNextYear() ), 373 connect( mDateNavigator, SIGNAL( goNextYear() ),
374 mNavigator, SLOT( selectNextYear() ) ); 374 mNavigator, SLOT( selectNextYear() ) );
375 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 375 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
376 mNavigator, SLOT( selectPreviousMonth() ) ); 376 mNavigator, SLOT( selectPreviousMonth() ) );
377 connect( mDateNavigator, SIGNAL( goNextMonth() ), 377 connect( mDateNavigator, SIGNAL( goNextMonth() ),
378 mNavigator, SLOT( selectNextMonth() ) ); 378 mNavigator, SLOT( selectNextMonth() ) );
379 379
380 connect( mDateNavigator, SIGNAL( goPrevious() ), 380 connect( mDateNavigator, SIGNAL( goPrevious() ),
381 mNavigator, SLOT( selectPrevious() ) ); 381 mNavigator, SLOT( selectPrevious() ) );
382 connect( mDateNavigator, SIGNAL( goNext() ), 382 connect( mDateNavigator, SIGNAL( goNext() ),
383 mNavigator, SLOT( selectNext() ) ); 383 mNavigator, SLOT( selectNext() ) );
384 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 384 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
385 mNavigator, SLOT( slotMonthSelect( int ) ) ); 385 mNavigator, SLOT( slotMonthSelect( int ) ) );
386 386
387 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 387 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
388 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 388 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
389#if 0 389#if 0
390 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 390 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
391 SLOT( incidenceAdded( Incidence *) ) ); 391 SLOT( incidenceAdded( Incidence *) ) );
392#endif 392#endif
393 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 393 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
394 394
395 connect( this, SIGNAL( configChanged() ), 395 connect( this, SIGNAL( configChanged() ),
396 mDateNavigator, SLOT( updateConfig() ) ); 396 mDateNavigator, SLOT( updateConfig() ) );
397 397
398 connect( mTodoList, SIGNAL( newTodoSignal() ), 398 connect( mTodoList, SIGNAL( newTodoSignal() ),
399 SLOT( newTodo() ) ); 399 SLOT( newTodo() ) );
400 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 400 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
401 SLOT( newSubTodo( Todo * ) ) ); 401 SLOT( newSubTodo( Todo * ) ) );
402 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 402 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
403 SLOT( editTodo( Todo * ) ) ); 403 SLOT( editTodo( Todo * ) ) );
404 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 404 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
405 SLOT( showTodo( Todo *) ) ); 405 SLOT( showTodo( Todo *) ) );
406 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 406 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
407 SLOT( deleteTodo( Todo *) ) ); 407 SLOT( deleteTodo( Todo *) ) );
408 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 408 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
409 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 409 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
410 SLOT( purgeCompleted() ) ); 410 SLOT( purgeCompleted() ) );
411 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 411 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
412 SIGNAL( todoModified( Todo *, int ) ) ); 412 SIGNAL( todoModified( Todo *, int ) ) );
413 413
414 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
415 this, SLOT ( cloneIncidence( Incidence * ) ) ); 415 this, SLOT ( cloneIncidence( Incidence * ) ) );
416 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
417 this, SLOT (cancelIncidence( Incidence * ) ) ); 417 this, SLOT (cancelIncidence( Incidence * ) ) );
418 418
419 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 419 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
420 this, SLOT ( moveIncidence( Incidence * ) ) ); 420 this, SLOT ( moveIncidence( Incidence * ) ) );
421 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 421 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
422 this, SLOT ( beamIncidence( Incidence * ) ) ); 422 this, SLOT ( beamIncidence( Incidence * ) ) );
423 423
424 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 424 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
425 this, SLOT ( todo_unsub( Todo * ) ) ); 425 this, SLOT ( todo_unsub( Todo * ) ) );
426 426
427 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 427 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
428 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 428 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
429 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 429 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
430 SLOT( updateTodo( Todo *, int ) ) ); 430 SLOT( updateTodo( Todo *, int ) ) );
431 connect( this, SIGNAL( todoModified( Todo *, int )), this, 431 connect( this, SIGNAL( todoModified( Todo *, int )), this,
432 SLOT( changeTodoDisplay( Todo *, int ) ) ); 432 SLOT( changeTodoDisplay( Todo *, int ) ) );
433 433
434 434
435 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 435 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
436 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 436 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
437 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 437 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
438 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 438 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
439 439
440 440
441 441
442 442
443 443
444 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 444 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
445 SLOT(checkClipboard())); 445 SLOT(checkClipboard()));
446 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 446 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
447 SLOT( processTodoListSelection( Incidence * ) ) ); 447 SLOT( processTodoListSelection( Incidence * ) ) );
448 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 448 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
449 449
450 // kdDebug() << "CalendarView::CalendarView() done" << endl; 450 // kdDebug() << "CalendarView::CalendarView() done" << endl;
451 451
452 mDateFrame = new QVBox(0,0,WType_Popup); 452 mDateFrame = new QVBox(0,0,WType_Popup);
453 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 453 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
454 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 454 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
455 mDateFrame->setLineWidth(3); 455 mDateFrame->setLineWidth(3);
456 mDateFrame->hide(); 456 mDateFrame->hide();
457 mDateFrame->setCaption( i18n( "Pick a date to display")); 457 mDateFrame->setCaption( i18n( "Pick a date to display"));
458 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 458 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
459 459
460 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 460 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
461 461
462 mEventEditor = mDialogManager->getEventEditor(); 462 mEventEditor = mDialogManager->getEventEditor();
463 mTodoEditor = mDialogManager->getTodoEditor(); 463 mTodoEditor = mDialogManager->getTodoEditor();
464 464
465 mFlagEditDescription = false; 465 mFlagEditDescription = false;
466 466
467 mSuspendTimer = new QTimer( this ); 467 mSuspendTimer = new QTimer( this );
468 mAlarmTimer = new QTimer( this ); 468 mAlarmTimer = new QTimer( this );
469 mRecheckAlarmTimer = new QTimer( this ); 469 mRecheckAlarmTimer = new QTimer( this );
470 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 470 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
471 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 471 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
472 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 472 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
473 mAlarmDialog = new AlarmDialog( this ); 473 mAlarmDialog = new AlarmDialog( this );
474 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 474 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
475 mAlarmDialog->setServerNotification( false ); 475 mAlarmDialog->setServerNotification( false );
476 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 476 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
477 477
478 478
479#ifndef DESKTOP_VERSION 479#ifndef DESKTOP_VERSION
480//US listen for arriving address resultsets 480//US listen for arriving address resultsets
481 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 481 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
482 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 482 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
483#endif 483#endif
484 mDateNavigator->setCalendar( mCalendar ); 484 mDateNavigator->setCalendar( mCalendar );
485} 485}
486 486
487 487
488CalendarView::~CalendarView() 488CalendarView::~CalendarView()
489{ 489{
490 // kdDebug() << "~CalendarView()" << endl; 490 // kdDebug() << "~CalendarView()" << endl;
491 //qDebug("CalendarView::~CalendarView() "); 491 //qDebug("CalendarView::~CalendarView() ");
492 delete mDialogManager; 492 delete mDialogManager;
493 delete mViewManager; 493 delete mViewManager;
494 delete mStorage; 494 delete mStorage;
495 delete mDateFrame ; 495 delete mDateFrame ;
496 delete beamDialog; 496 delete beamDialog;
497 delete mEventViewerDialog; 497 delete mEventViewerDialog;
498 //kdDebug() << "~CalendarView() done" << endl; 498 //kdDebug() << "~CalendarView() done" << endl;
499} 499}
500 500
501void CalendarView::showDay( QDate d ) 501void CalendarView::showDay( QDate d )
502{ 502{
503 dateNavigator()->blockSignals( true ); 503 dateNavigator()->blockSignals( true );
504 dateNavigator()->selectDate( d ); 504 dateNavigator()->selectDate( d );
505 dateNavigator()->blockSignals( false ); 505 dateNavigator()->blockSignals( false );
506 mViewManager->showDayView(); 506 mViewManager->showDayView();
507 //dateNavigator()->selectDate( d ); 507 //dateNavigator()->selectDate( d );
508} 508}
509void CalendarView::timerAlarm() 509void CalendarView::timerAlarm()
510{ 510{
511 //qDebug("CalendarView::timerAlarm() "); 511 //qDebug("CalendarView::timerAlarm() ");
512 computeAlarm(mAlarmNotification ); 512 computeAlarm(mAlarmNotification );
513} 513}
514 514
515void CalendarView::suspendAlarm() 515void CalendarView::suspendAlarm()
516{ 516{
517 //qDebug(" CalendarView::suspendAlarm() "); 517 //qDebug(" CalendarView::suspendAlarm() ");
518 computeAlarm(mSuspendAlarmNotification ); 518 computeAlarm(mSuspendAlarmNotification );
519 519
520} 520}
521 521
522void CalendarView::startAlarm( QString mess , QString filename) 522void CalendarView::startAlarm( QString mess , QString filename)
523{ 523{
524 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 524 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
525 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 525 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
526 526
527} 527}
528 528
529void CalendarView::checkNextTimerAlarm() 529void CalendarView::checkNextTimerAlarm()
530{ 530{
531 mCalendar->checkAlarmForIncidence( 0, true ); 531 mCalendar->checkAlarmForIncidence( 0, true );
532} 532}
533 533
534void CalendarView::computeAlarm( QString msg ) 534void CalendarView::computeAlarm( QString msg )
535{ 535{
536 536
537 QString mess = msg; 537 QString mess = msg;
538 QString mAlarmMessage = mess.mid( 9 ); 538 QString mAlarmMessage = mess.mid( 9 );
539 QString filename = MainWindow::resourcePath(); 539 QString filename = MainWindow::resourcePath();
540 filename += "koalarm.wav"; 540 filename += "koalarm.wav";
541 QString tempfilename; 541 QString tempfilename;
542 if ( mess.left( 13 ) == "suspend_alarm") { 542 if ( mess.left( 13 ) == "suspend_alarm") {
543 bool error = false; 543 bool error = false;
544 int len = mess.mid( 13 ).find("+++"); 544 int len = mess.mid( 13 ).find("+++");
545 if ( len < 2 ) 545 if ( len < 2 )
546 error = true; 546 error = true;
547 else { 547 else {
548 tempfilename = mess.mid( 13, len ); 548 tempfilename = mess.mid( 13, len );
549 if ( !QFile::exists( tempfilename ) ) 549 if ( !QFile::exists( tempfilename ) )
550 error = true; 550 error = true;
551 } 551 }
552 if ( ! error ) { 552 if ( ! error ) {
553 filename = tempfilename; 553 filename = tempfilename;
554 } 554 }
555 mAlarmMessage = mess.mid( 13+len+3 ); 555 mAlarmMessage = mess.mid( 13+len+3 );
556 //qDebug("suspend file %s ",tempfilename.latin1() ); 556 //qDebug("suspend file %s ",tempfilename.latin1() );
557 startAlarm( mAlarmMessage, filename); 557 startAlarm( mAlarmMessage, filename);
558 return; 558 return;
559 } 559 }
560 if ( mess.left( 11 ) == "timer_alarm") { 560 if ( mess.left( 11 ) == "timer_alarm") {
561 //mTimerTime = 0; 561 //mTimerTime = 0;
562 startAlarm( mess.mid( 11 ), filename ); 562 startAlarm( mess.mid( 11 ), filename );
563 return; 563 return;
564 } 564 }
565 if ( mess.left( 10 ) == "proc_alarm") { 565 if ( mess.left( 10 ) == "proc_alarm") {
566 bool error = false; 566 bool error = false;
567 int len = mess.mid( 10 ).find("+++"); 567 int len = mess.mid( 10 ).find("+++");
568 if ( len < 2 ) 568 if ( len < 2 )
569 error = true; 569 error = true;
570 else { 570 else {
571 tempfilename = mess.mid( 10, len ); 571 tempfilename = mess.mid( 10, len );
572 if ( !QFile::exists( tempfilename ) ) 572 if ( !QFile::exists( tempfilename ) )
573 error = true; 573 error = true;
574 } 574 }
575 if ( error ) { 575 if ( error ) {
576 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 576 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
577 mAlarmMessage += mess.mid( 10+len+3+9 ); 577 mAlarmMessage += mess.mid( 10+len+3+9 );
578 } else { 578 } else {
579 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 579 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
580 //qDebug("-----system command %s ",tempfilename.latin1() ); 580 //qDebug("-----system command %s ",tempfilename.latin1() );
581#ifndef _WIN32_ 581#ifndef _WIN32_
582 if ( vfork () == 0 ) { 582 if ( vfork () == 0 ) {
583 execl ( tempfilename.latin1(), 0 ); 583 execl ( tempfilename.latin1(), 0 );
584 return; 584 return;
585 } 585 }
586#else 586#else
587 QProcess* p = new QProcess(); 587 QProcess* p = new QProcess();
588 p->addArgument( tempfilename.latin1() ); 588 p->addArgument( tempfilename.latin1() );
589 p->start(); 589 p->start();
590 return; 590 return;
591#endif 591#endif
592 592
593 return; 593 return;
594 } 594 }
595 595
596 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 596 //qDebug("+++++++system command %s ",tempfilename.latin1() );
597 } 597 }
598 if ( mess.left( 11 ) == "audio_alarm") { 598 if ( mess.left( 11 ) == "audio_alarm") {
599 bool error = false; 599 bool error = false;
600 int len = mess.mid( 11 ).find("+++"); 600 int len = mess.mid( 11 ).find("+++");
601 if ( len < 2 ) 601 if ( len < 2 )
602 error = true; 602 error = true;
603 else { 603 else {
604 tempfilename = mess.mid( 11, len ); 604 tempfilename = mess.mid( 11, len );
605 if ( !QFile::exists( tempfilename ) ) 605 if ( !QFile::exists( tempfilename ) )
606 error = true; 606 error = true;
607 } 607 }
608 if ( ! error ) { 608 if ( ! error ) {
609 filename = tempfilename; 609 filename = tempfilename;
610 } 610 }
611 mAlarmMessage = mess.mid( 11+len+3+9 ); 611 mAlarmMessage = mess.mid( 11+len+3+9 );
612 //qDebug("audio file command %s ",tempfilename.latin1() ); 612 //qDebug("audio file command %s ",tempfilename.latin1() );
613 } 613 }
614 if ( mess.left( 9 ) == "cal_alarm") { 614 if ( mess.left( 9 ) == "cal_alarm") {
615 mAlarmMessage = mess.mid( 9 ) ; 615 mAlarmMessage = mess.mid( 9 ) ;
616 } 616 }
617 617
618 startAlarm( mAlarmMessage, filename ); 618 startAlarm( mAlarmMessage, filename );
619 619
620 620
621} 621}
622 622
623void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 623void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
624{ 624{
625 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 625 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
626 626
627 mSuspendAlarmNotification = noti; 627 mSuspendAlarmNotification = noti;
628 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 628 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
629 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 629 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
630 mSuspendTimer->start( ms , true ); 630 mSuspendTimer->start( ms , true );
631 631
632} 632}
633 633
634void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 634void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
635{ 635{
636 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 636 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
637 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 637 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
638#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
639 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 639 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
640#endif 640#endif
641 return; 641 return;
642 } 642 }
643 int maxSec; 643 int maxSec;
644 //maxSec = 5; //testing only 644 //maxSec = 5; //testing only
645 maxSec = 86400+3600; // one day+1hour 645 maxSec = 86400+3600; // one day+1hour
646 mAlarmNotification = noti; 646 mAlarmNotification = noti;
647 int sec = QDateTime::currentDateTime().secsTo( qdt ); 647 int sec = QDateTime::currentDateTime().secsTo( qdt );
648 if ( sec > maxSec ) { 648 if ( sec > maxSec ) {
649 mRecheckAlarmTimer->start( maxSec * 1000 ); 649 mRecheckAlarmTimer->start( maxSec * 1000 );
650 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 650 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
651 return; 651 return;
652 } else { 652 } else {
653 mRecheckAlarmTimer->stop(); 653 mRecheckAlarmTimer->stop();
654 } 654 }
655 //qDebug("Alarm timer started with secs: %d ", sec); 655 //qDebug("Alarm timer started with secs: %d ", sec);
656 mAlarmTimer->start( sec *1000 , true ); 656 mAlarmTimer->start( sec *1000 , true );
657 657
658} 658}
659// called by mRecheckAlarmTimer to get next alarm 659// called by mRecheckAlarmTimer to get next alarm
660// we need this, because a QTimer has only a max range of 25 days 660// we need this, because a QTimer has only a max range of 25 days
661void CalendarView::recheckTimerAlarm() 661void CalendarView::recheckTimerAlarm()
662{ 662{
663 mAlarmTimer->stop(); 663 mAlarmTimer->stop();
664 mRecheckAlarmTimer->stop(); 664 mRecheckAlarmTimer->stop();
665 mCalendar->checkAlarmForIncidence( 0, true ); 665 mCalendar->checkAlarmForIncidence( 0, true );
666} 666}
667void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 667void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
668{ 668{
669 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 669 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
670 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 670 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
671#ifndef DESKTOP_VERSION 671#ifndef DESKTOP_VERSION
672 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 672 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
673#endif 673#endif
674 return; 674 return;
675 } 675 }
676 mAlarmTimer->stop(); 676 mAlarmTimer->stop();
677} 677}
678void CalendarView::selectWeekNum ( int num ) 678void CalendarView::selectWeekNum ( int num )
679{ 679{
680 dateNavigator()->blockSignals( true ); 680 dateNavigator()->blockSignals( true );
681 dateNavigator()->selectWeek( num ); 681 dateNavigator()->selectWeek( num );
682 dateNavigator()->blockSignals( false ); 682 dateNavigator()->blockSignals( false );
683 mViewManager->showWeekView(); 683 mViewManager->showWeekView();
684} 684}
685KOViewManager *CalendarView::viewManager() 685KOViewManager *CalendarView::viewManager()
686{ 686{
687 return mViewManager; 687 return mViewManager;
688} 688}
689 689
690KODialogManager *CalendarView::dialogManager() 690KODialogManager *CalendarView::dialogManager()
691{ 691{
692 return mDialogManager; 692 return mDialogManager;
693} 693}
694 694
695QDate CalendarView::startDate() 695QDate CalendarView::startDate()
696{ 696{
697 DateList dates = mNavigator->selectedDates(); 697 DateList dates = mNavigator->selectedDates();
698 698
699 return dates.first(); 699 return dates.first();
700} 700}
701 701
702QDate CalendarView::endDate() 702QDate CalendarView::endDate()
703{ 703{
704 DateList dates = mNavigator->selectedDates(); 704 DateList dates = mNavigator->selectedDates();
705 705
706 return dates.last(); 706 return dates.last();
707} 707}
708 708
709 709
710void CalendarView::createPrinter() 710void CalendarView::createPrinter()
711{ 711{
712#ifndef KORG_NOPRINTER 712#ifndef KORG_NOPRINTER
713 if (!mCalPrinter) { 713 if (!mCalPrinter) {
714 mCalPrinter = new CalPrinter(this, mCalendar); 714 mCalPrinter = new CalPrinter(this, mCalendar);
715 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 715 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
716 } 716 }
717#endif 717#endif
718} 718}
719 719
720 720
721//KOPrefs::instance()->mWriteBackFile 721//KOPrefs::instance()->mWriteBackFile
722//KOPrefs::instance()->mWriteBackExistingOnly 722//KOPrefs::instance()->mWriteBackExistingOnly
723 723
724// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 724// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
725// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 725// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
726// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 726// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
727// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 727// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
728// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 728// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
729// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 729// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
730 730
731int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 731int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
732{ 732{
733 733
734 // 0 equal 734 // 0 equal
735 // 1 take local 735 // 1 take local
736 // 2 take remote 736 // 2 take remote
737 // 3 cancel 737 // 3 cancel
738 QDateTime lastSync = mLastCalendarSync; 738 QDateTime lastSync = mLastCalendarSync;
739 QDateTime localMod = local->lastModified(); 739 QDateTime localMod = local->lastModified();
740 QDateTime remoteMod = remote->lastModified(); 740 QDateTime remoteMod = remote->lastModified();
741 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 741 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
742 bool remCh, locCh; 742 bool remCh, locCh;
743 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 743 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
744 //if ( remCh ) 744 //if ( remCh )
745 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 745 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
746 locCh = ( localMod > mLastCalendarSync ); 746 locCh = ( localMod > mLastCalendarSync );
747 if ( !remCh && ! locCh ) { 747 if ( !remCh && ! locCh ) {
748 //qDebug("both not changed "); 748 //qDebug("both not changed ");
749 lastSync = localMod.addDays(1); 749 lastSync = localMod.addDays(1);
750 if ( mode <= SYNC_PREF_ASK ) 750 if ( mode <= SYNC_PREF_ASK )
751 return 0; 751 return 0;
752 } else { 752 } else {
753 if ( locCh ) { 753 if ( locCh ) {
754 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 754 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
755 lastSync = localMod.addDays( -1 ); 755 lastSync = localMod.addDays( -1 );
756 if ( !remCh ) 756 if ( !remCh )
757 remoteMod = ( lastSync.addDays( -1 ) ); 757 remoteMod = ( lastSync.addDays( -1 ) );
758 } else { 758 } else {
759 //qDebug(" not loc changed "); 759 //qDebug(" not loc changed ");
760 lastSync = localMod.addDays( 1 ); 760 lastSync = localMod.addDays( 1 );
761 if ( remCh ) 761 if ( remCh )
762 remoteMod =( lastSync.addDays( 1 ) ); 762 remoteMod =( lastSync.addDays( 1 ) );
763 763
764 } 764 }
765 } 765 }
766 full = true; 766 full = true;
767 if ( mode < SYNC_PREF_ASK ) 767 if ( mode < SYNC_PREF_ASK )
768 mode = SYNC_PREF_ASK; 768 mode = SYNC_PREF_ASK;
769 } else { 769 } else {
770 if ( localMod == remoteMod ) 770 if ( localMod == remoteMod )
771 // if ( local->revision() == remote->revision() ) 771 // if ( local->revision() == remote->revision() )
772 return 0; 772 return 0;
773 773
774 } 774 }
775 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 775 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
776 776
777 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 777 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
778 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 778 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
779 //full = true; //debug only 779 //full = true; //debug only
780 if ( full ) { 780 if ( full ) {
781 bool equ = false; 781 bool equ = false;
782 if ( local->type() == "Event" ) { 782 if ( local->type() == "Event" ) {
783 equ = (*((Event*) local) == *((Event*) remote)); 783 equ = (*((Event*) local) == *((Event*) remote));
784 } 784 }
785 else if ( local->type() =="Todo" ) 785 else if ( local->type() =="Todo" )
786 equ = (*((Todo*) local) == (*(Todo*) remote)); 786 equ = (*((Todo*) local) == (*(Todo*) remote));
787 else if ( local->type() =="Journal" ) 787 else if ( local->type() =="Journal" )
788 equ = (*((Journal*) local) == *((Journal*) remote)); 788 equ = (*((Journal*) local) == *((Journal*) remote));
789 if ( equ ) { 789 if ( equ ) {
790 //qDebug("equal "); 790 //qDebug("equal ");
791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
792 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 792 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
793 } 793 }
794 if ( mode < SYNC_PREF_FORCE_LOCAL ) 794 if ( mode < SYNC_PREF_FORCE_LOCAL )
795 return 0; 795 return 0;
796 796
797 }//else //debug only 797 }//else //debug only
798 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 798 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
799 } 799 }
800 int result; 800 int result;
801 bool localIsNew; 801 bool localIsNew;
802 //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() ); 802 //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() );
803 803
804 if ( full && mode < SYNC_PREF_NEWEST ) 804 if ( full && mode < SYNC_PREF_NEWEST )
805 mode = SYNC_PREF_ASK; 805 mode = SYNC_PREF_ASK;
806 806
807 switch( mode ) { 807 switch( mode ) {
808 case SYNC_PREF_LOCAL: 808 case SYNC_PREF_LOCAL:
809 if ( lastSync > remoteMod ) 809 if ( lastSync > remoteMod )
810 return 1; 810 return 1;
811 if ( lastSync > localMod ) 811 if ( lastSync > localMod )
812 return 2; 812 return 2;
813 return 1; 813 return 1;
814 break; 814 break;
815 case SYNC_PREF_REMOTE: 815 case SYNC_PREF_REMOTE:
816 if ( lastSync > remoteMod ) 816 if ( lastSync > remoteMod )
817 return 1; 817 return 1;
818 if ( lastSync > localMod ) 818 if ( lastSync > localMod )
819 return 2; 819 return 2;
820 return 2; 820 return 2;
821 break; 821 break;
822 case SYNC_PREF_NEWEST: 822 case SYNC_PREF_NEWEST:
823 if ( localMod > remoteMod ) 823 if ( localMod > remoteMod )
824 return 1; 824 return 1;
825 else 825 else
826 return 2; 826 return 2;
827 break; 827 break;
828 case SYNC_PREF_ASK: 828 case SYNC_PREF_ASK:
829 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 829 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
830 if ( lastSync > remoteMod ) 830 if ( lastSync > remoteMod )
831 return 1; 831 return 1;
832 if ( lastSync > localMod ) 832 if ( lastSync > localMod )
833 return 2; 833 return 2;
834 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 834 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
835 localIsNew = localMod >= remoteMod; 835 localIsNew = localMod >= remoteMod;
836 if ( localIsNew ) 836 if ( localIsNew )
837 getEventViewerDialog()->setColorMode( 1 ); 837 getEventViewerDialog()->setColorMode( 1 );
838 else 838 else
839 getEventViewerDialog()->setColorMode( 2 ); 839 getEventViewerDialog()->setColorMode( 2 );
840 getEventViewerDialog()->setIncidence(local); 840 getEventViewerDialog()->setIncidence(local);
841 if ( localIsNew ) 841 if ( localIsNew )
842 getEventViewerDialog()->setColorMode( 2 ); 842 getEventViewerDialog()->setColorMode( 2 );
843 else 843 else
844 getEventViewerDialog()->setColorMode( 1 ); 844 getEventViewerDialog()->setColorMode( 1 );
845 getEventViewerDialog()->addIncidence(remote); 845 getEventViewerDialog()->addIncidence(remote);
846 getEventViewerDialog()->setColorMode( 0 ); 846 getEventViewerDialog()->setColorMode( 0 );
847 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 847 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
848 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 848 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
849 getEventViewerDialog()->showMe(); 849 getEventViewerDialog()->showMe();
850 result = getEventViewerDialog()->executeS( localIsNew ); 850 result = getEventViewerDialog()->executeS( localIsNew );
851 return result; 851 return result;
852 852
853 break; 853 break;
854 case SYNC_PREF_FORCE_LOCAL: 854 case SYNC_PREF_FORCE_LOCAL:
855 return 1; 855 return 1;
856 break; 856 break;
857 case SYNC_PREF_FORCE_REMOTE: 857 case SYNC_PREF_FORCE_REMOTE:
858 return 2; 858 return 2;
859 break; 859 break;
860 860
861 default: 861 default:
862 // SYNC_PREF_TAKE_BOTH not implemented 862 // SYNC_PREF_TAKE_BOTH not implemented
863 break; 863 break;
864 } 864 }
865 return 0; 865 return 0;
866} 866}
867Event* CalendarView::getLastSyncEvent() 867Event* CalendarView::getLastSyncEvent()
868{ 868{
869 Event* lse; 869 Event* lse;
870 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 870 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
871 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 871 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
872 if (!lse) { 872 if (!lse) {
873 lse = new Event(); 873 lse = new Event();
874 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 874 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
875 QString sum = ""; 875 QString sum = "";
876 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 876 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
877 sum = "E: "; 877 sum = "E: ";
878 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 878 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
879 lse->setDtStart( mLastCalendarSync ); 879 lse->setDtStart( mLastCalendarSync );
880 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 880 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
881 lse->setCategories( i18n("SyncEvent") ); 881 lse->setCategories( i18n("SyncEvent") );
882 lse->setReadOnly( true ); 882 lse->setReadOnly( true );
883 mCalendar->addEvent( lse ); 883 mCalendar->addEvent( lse );
884 } 884 }
885 885
886 return lse; 886 return lse;
887 887
888} 888}
889 889
890// we check, if the to delete event has a id for a profile 890// we check, if the to delete event has a id for a profile
891// if yes, we set this id in the profile to delete 891// if yes, we set this id in the profile to delete
892void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 892void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
893{ 893{
894 if ( lastSync.count() == 0 ) { 894 if ( lastSync.count() == 0 ) {
895 //qDebug(" lastSync.count() == 0"); 895 //qDebug(" lastSync.count() == 0");
896 return; 896 return;
897 } 897 }
898 if ( toDelete->type() == "Journal" ) 898 if ( toDelete->type() == "Journal" )
899 return; 899 return;
900 900
901 Event* eve = lastSync.first(); 901 Event* eve = lastSync.first();
902 902
903 while ( eve ) { 903 while ( eve ) {
904 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 904 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
905 if ( !id.isEmpty() ) { 905 if ( !id.isEmpty() ) {
906 QString des = eve->description(); 906 QString des = eve->description();
907 QString pref = "e"; 907 QString pref = "e";
908 if ( toDelete->type() == "Todo" ) 908 if ( toDelete->type() == "Todo" )
909 pref = "t"; 909 pref = "t";
910 des += pref+ id + ","; 910 des += pref+ id + ",";
911 eve->setReadOnly( false ); 911 eve->setReadOnly( false );
912 eve->setDescription( des ); 912 eve->setDescription( des );
913 //qDebug("setdes %s ", des.latin1()); 913 //qDebug("setdes %s ", des.latin1());
914 eve->setReadOnly( true ); 914 eve->setReadOnly( true );
915 } 915 }
916 eve = lastSync.next(); 916 eve = lastSync.next();
917 } 917 }
918 918
919} 919}
920void CalendarView::checkExternalId( Incidence * inc ) 920void CalendarView::checkExternalId( Incidence * inc )
921{ 921{
922 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 922 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
923 checkExternSyncEvent( lastSync, inc ); 923 checkExternSyncEvent( lastSync, inc );
924 924
925} 925}
926bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 926bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
927{ 927{
928 bool syncOK = true; 928 bool syncOK = true;
929 int addedEvent = 0; 929 int addedEvent = 0;
930 int addedEventR = 0; 930 int addedEventR = 0;
931 int deletedEventR = 0; 931 int deletedEventR = 0;
932 int deletedEventL = 0; 932 int deletedEventL = 0;
933 int changedLocal = 0; 933 int changedLocal = 0;
934 int changedRemote = 0; 934 int changedRemote = 0;
935 int filteredIN = 0; 935 int filteredIN = 0;
936 int filteredOUT = 0; 936 int filteredOUT = 0;
937 //QPtrList<Event> el = local->rawEvents(); 937 //QPtrList<Event> el = local->rawEvents();
938 Event* eventR; 938 Event* eventR;
939 QString uid; 939 QString uid;
940 int take; 940 int take;
941 Event* eventL; 941 Event* eventL;
942 Event* eventRSync; 942 Event* eventRSync;
943 Event* eventLSync; 943 Event* eventLSync;
944 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 944 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
945 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 945 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
946 bool fullDateRange = false; 946 bool fullDateRange = false;
947 local->resetTempSyncStat(); 947 local->resetTempSyncStat();
948 mLastCalendarSync = QDateTime::currentDateTime(); 948 mLastCalendarSync = QDateTime::currentDateTime();
949 if ( mSyncManager->syncWithDesktop() ) { 949 if ( mSyncManager->syncWithDesktop() ) {
950 remote->resetPilotStat(1); 950 remote->resetPilotStat(1);
951 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 951 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
952 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 952 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
953 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 953 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
954 } else { 954 } else {
955 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 955 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
956 } 956 }
957 } 957 }
958 QDateTime modifiedCalendar = mLastCalendarSync; 958 QDateTime modifiedCalendar = mLastCalendarSync;
959 eventLSync = getLastSyncEvent(); 959 eventLSync = getLastSyncEvent();
960 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 960 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
961 if ( eventR ) { 961 if ( eventR ) {
962 eventRSync = (Event*) eventR->clone(); 962 eventRSync = (Event*) eventR->clone();
963 remote->deleteEvent(eventR ); 963 remote->deleteEvent(eventR );
964 964
965 } else { 965 } else {
966 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 966 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
967 eventRSync = (Event*)eventLSync->clone(); 967 eventRSync = (Event*)eventLSync->clone();
968 } else { 968 } else {
969 fullDateRange = true; 969 fullDateRange = true;
970 eventRSync = new Event(); 970 eventRSync = new Event();
971 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 971 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
972 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 972 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
973 eventRSync->setDtStart( mLastCalendarSync ); 973 eventRSync->setDtStart( mLastCalendarSync );
974 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 974 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
975 eventRSync->setCategories( i18n("SyncEvent") ); 975 eventRSync->setCategories( i18n("SyncEvent") );
976 } 976 }
977 } 977 }
978 if ( eventLSync->dtStart() == mLastCalendarSync ) 978 if ( eventLSync->dtStart() == mLastCalendarSync )
979 fullDateRange = true; 979 fullDateRange = true;
980 980
981 if ( ! fullDateRange ) { 981 if ( ! fullDateRange ) {
982 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 982 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
983 983
984 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 984 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
985 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 985 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
986 fullDateRange = true; 986 fullDateRange = true;
987 } 987 }
988 } 988 }
989 if ( mSyncManager->syncWithDesktop() ) { 989 if ( mSyncManager->syncWithDesktop() ) {
990 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 990 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
991 } 991 }
992 if ( fullDateRange ) 992 if ( fullDateRange )
993 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 993 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
994 else 994 else
995 mLastCalendarSync = eventLSync->dtStart(); 995 mLastCalendarSync = eventLSync->dtStart();
996 // for resyncing if own file has changed 996 // for resyncing if own file has changed
997 if ( mCurrentSyncDevice == "deleteaftersync" ) { 997 if ( mCurrentSyncDevice == "deleteaftersync" ) {
998 mLastCalendarSync = loadedFileVersion; 998 mLastCalendarSync = loadedFileVersion;
999 //qDebug("setting mLastCalendarSync "); 999 //qDebug("setting mLastCalendarSync ");
1000 } 1000 }
1001 //qDebug("*************************** "); 1001 //qDebug("*************************** ");
1002 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1002 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1003 QPtrList<Incidence> er = remote->rawIncidences(); 1003 QPtrList<Incidence> er = remote->rawIncidences();
1004 Incidence* inR = er.first(); 1004 Incidence* inR = er.first();
1005 Incidence* inL; 1005 Incidence* inL;
1006 QProgressBar bar( er.count(),0 ); 1006 QProgressBar bar( er.count(),0 );
1007 bar.setCaption (i18n("Syncing - close to abort!") ); 1007 bar.setCaption (i18n("Syncing - close to abort!") );
1008 1008
1009 // ************** setting up filter ************* 1009 // ************** setting up filter *************
1010 CalFilter *filterIN = 0; 1010 CalFilter *filterIN = 0;
1011 CalFilter *filterOUT = 0; 1011 CalFilter *filterOUT = 0;
1012 CalFilter *filter = mFilters.first(); 1012 CalFilter *filter = mFilters.first();
1013 while(filter) { 1013 while(filter) {
1014 if ( filter->name() == mSyncManager->mFilterInCal ) 1014 if ( filter->name() == mSyncManager->mFilterInCal )
1015 filterIN = filter; 1015 filterIN = filter;
1016 if ( filter->name() == mSyncManager->mFilterOutCal ) 1016 if ( filter->name() == mSyncManager->mFilterOutCal )
1017 filterOUT = filter; 1017 filterOUT = filter;
1018 filter = mFilters.next(); 1018 filter = mFilters.next();
1019 } 1019 }
1020 int w = 300; 1020 int w = 300;
1021 if ( QApplication::desktop()->width() < 320 ) 1021 if ( QApplication::desktop()->width() < 320 )
1022 w = 220; 1022 w = 220;
1023 int h = bar.sizeHint().height() ; 1023 int h = bar.sizeHint().height() ;
1024 int dw = QApplication::desktop()->width(); 1024 int dw = QApplication::desktop()->width();
1025 int dh = QApplication::desktop()->height(); 1025 int dh = QApplication::desktop()->height();
1026 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1026 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1027 bar.show(); 1027 bar.show();
1028 int modulo = (er.count()/10)+1; 1028 int modulo = (er.count()/10)+1;
1029 int incCounter = 0; 1029 int incCounter = 0;
1030 while ( inR ) { 1030 while ( inR ) {
1031 if ( ! bar.isVisible() ) 1031 if ( ! bar.isVisible() )
1032 return false; 1032 return false;
1033 if ( incCounter % modulo == 0 ) 1033 if ( incCounter % modulo == 0 )
1034 bar.setProgress( incCounter ); 1034 bar.setProgress( incCounter );
1035 ++incCounter; 1035 ++incCounter;
1036 uid = inR->uid(); 1036 uid = inR->uid();
1037 bool skipIncidence = false; 1037 bool skipIncidence = false;
1038 if ( uid.left(15) == QString("last-syncEvent-") ) 1038 if ( uid.left(15) == QString("last-syncEvent-") )
1039 skipIncidence = true; 1039 skipIncidence = true;
1040 QString idS; 1040 QString idS;
1041 qApp->processEvents(); 1041 qApp->processEvents();
1042 if ( !skipIncidence ) { 1042 if ( !skipIncidence ) {
1043 inL = local->incidence( uid ); 1043 inL = local->incidence( uid );
1044 if ( inL ) { // maybe conflict - same uid in both calendars 1044 if ( inL ) { // maybe conflict - same uid in both calendars
1045 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1045 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1046 //qDebug("take %d %s ", take, inL->summary().latin1()); 1046 //qDebug("take %d %s ", take, inL->summary().latin1());
1047 if ( take == 3 ) 1047 if ( take == 3 )
1048 return false; 1048 return false;
1049 if ( take == 1 ) {// take local ********************** 1049 if ( take == 1 ) {// take local **********************
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1051 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1051 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1052 else 1052 else
1053 idS = inR->IDStr(); 1053 idS = inR->IDStr();
1054 remote->deleteIncidence( inR ); 1054 remote->deleteIncidence( inR );
1055 inR = inL->clone(); 1055 inR = inL->clone();
1056 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1057 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1057 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1058 inR->setIDStr( idS ); 1058 inR->setIDStr( idS );
1059 remote->addIncidence( inR ); 1059 remote->addIncidence( inR );
1060 if ( mSyncManager->syncWithDesktop() ) 1060 if ( mSyncManager->syncWithDesktop() )
1061 inR->setPilotId( 2 ); 1061 inR->setPilotId( 2 );
1062 ++changedRemote; 1062 ++changedRemote;
1063 } else {// take remote ********************** 1063 } else {// take remote **********************
1064 idS = inL->IDStr(); 1064 idS = inL->IDStr();
1065 int pid = inL->pilotId(); 1065 int pid = inL->pilotId();
1066 local->deleteIncidence( inL ); 1066 local->deleteIncidence( inL );
1067 inL = inR->clone(); 1067 inL = inR->clone();
1068 if ( mSyncManager->syncWithDesktop() ) 1068 if ( mSyncManager->syncWithDesktop() )
1069 inL->setPilotId( pid ); 1069 inL->setPilotId( pid );
1070 inL->setIDStr( idS ); 1070 inL->setIDStr( idS );
1071 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1071 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1074 } 1074 }
1075 local->addIncidence( inL ); 1075 local->addIncidence( inL );
1076 ++changedLocal; 1076 ++changedLocal;
1077 } 1077 }
1078 } 1078 }
1079 } else { // no conflict ********** add or delete remote 1079 } else { // no conflict ********** add or delete remote
1080 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1080 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1081 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1081 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1082 QString des = eventLSync->description(); 1082 QString des = eventLSync->description();
1083 QString pref = "e"; 1083 QString pref = "e";
1084 if ( inR->type() == "Todo" ) 1084 if ( inR->type() == "Todo" )
1085 pref = "t"; 1085 pref = "t";
1086 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1086 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1087 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1087 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1088 //remote->deleteIncidence( inR ); 1088 //remote->deleteIncidence( inR );
1089 ++deletedEventR; 1089 ++deletedEventR;
1090 } else { 1090 } else {
1091 inR->setLastModified( modifiedCalendar ); 1091 inR->setLastModified( modifiedCalendar );
1092 inL = inR->clone(); 1092 inL = inR->clone();
1093 inL->setIDStr( ":" ); 1093 inL->setIDStr( ":" );
1094 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1094 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1095 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1095 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1096 local->addIncidence( inL ); 1096 local->addIncidence( inL );
1097 ++addedEvent; 1097 ++addedEvent;
1098 1098
1099 } 1099 }
1100 } else { 1100 } else {
1101 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1101 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1102 inR->setLastModified( modifiedCalendar ); 1102 inR->setLastModified( modifiedCalendar );
1103 inL = inR->clone(); 1103 inL = inR->clone();
1104 inL->setIDStr( ":" ); 1104 inL->setIDStr( ":" );
1105 local->addIncidence( inL ); 1105 local->addIncidence( inL );
1106 ++addedEvent; 1106 ++addedEvent;
1107 1107
1108 } else { 1108 } else {
1109 checkExternSyncEvent(eventRSyncSharp, inR); 1109 checkExternSyncEvent(eventRSyncSharp, inR);
1110 remote->deleteIncidence( inR ); 1110 remote->deleteIncidence( inR );
1111 ++deletedEventR; 1111 ++deletedEventR;
1112 } 1112 }
1113 } 1113 }
1114 } else { 1114 } else {
1115 ++filteredIN; 1115 ++filteredIN;
1116 } 1116 }
1117 } 1117 }
1118 } 1118 }
1119 inR = er.next(); 1119 inR = er.next();
1120 } 1120 }
1121 QPtrList<Incidence> el = local->rawIncidences(); 1121 QPtrList<Incidence> el = local->rawIncidences();
1122 inL = el.first(); 1122 inL = el.first();
1123 modulo = (el.count()/10)+1; 1123 modulo = (el.count()/10)+1;
1124 bar.setCaption (i18n("Add / remove events") ); 1124 bar.setCaption (i18n("Add / remove events") );
1125 bar.setTotalSteps ( el.count() ) ; 1125 bar.setTotalSteps ( el.count() ) ;
1126 bar.show(); 1126 bar.show();
1127 incCounter = 0; 1127 incCounter = 0;
1128 1128
1129 while ( inL ) { 1129 while ( inL ) {
1130 1130
1131 qApp->processEvents(); 1131 qApp->processEvents();
1132 if ( ! bar.isVisible() ) 1132 if ( ! bar.isVisible() )
1133 return false; 1133 return false;
1134 if ( incCounter % modulo == 0 ) 1134 if ( incCounter % modulo == 0 )
1135 bar.setProgress( incCounter ); 1135 bar.setProgress( incCounter );
1136 ++incCounter; 1136 ++incCounter;
1137 uid = inL->uid(); 1137 uid = inL->uid();
1138 bool skipIncidence = false; 1138 bool skipIncidence = false;
1139 if ( uid.left(15) == QString("last-syncEvent-") ) 1139 if ( uid.left(15) == QString("last-syncEvent-") )
1140 skipIncidence = true; 1140 skipIncidence = true;
1141 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1141 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1142 skipIncidence = true; 1142 skipIncidence = true;
1143 if ( !skipIncidence ) { 1143 if ( !skipIncidence ) {
1144 inR = remote->incidence( uid ); 1144 inR = remote->incidence( uid );
1145 if ( ! inR ) { 1145 if ( ! inR ) {
1146 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1146 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1147 // no conflict ********** add or delete local 1147 // no conflict ********** add or delete local
1148 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1148 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1149 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1149 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1150 checkExternSyncEvent(eventLSyncSharp, inL); 1150 checkExternSyncEvent(eventLSyncSharp, inL);
1151 local->deleteIncidence( inL ); 1151 local->deleteIncidence( inL );
1152 ++deletedEventL; 1152 ++deletedEventL;
1153 } else { 1153 } else {
1154 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1154 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1155 inL->removeID(mCurrentSyncDevice ); 1155 inL->removeID(mCurrentSyncDevice );
1156 ++addedEventR; 1156 ++addedEventR;
1157 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1157 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1158 inL->setLastModified( modifiedCalendar ); 1158 inL->setLastModified( modifiedCalendar );
1159 inR = inL->clone(); 1159 inR = inL->clone();
1160 inR->setIDStr( ":" ); 1160 inR->setIDStr( ":" );
1161 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1161 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1162 remote->addIncidence( inR ); 1162 remote->addIncidence( inR );
1163 } 1163 }
1164 } 1164 }
1165 } else { 1165 } else {
1166 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1166 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1167 checkExternSyncEvent(eventLSyncSharp, inL); 1167 checkExternSyncEvent(eventLSyncSharp, inL);
1168 local->deleteIncidence( inL ); 1168 local->deleteIncidence( inL );
1169 ++deletedEventL; 1169 ++deletedEventL;
1170 } else { 1170 } else {
1171 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1171 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1172 ++addedEventR; 1172 ++addedEventR;
1173 inL->setLastModified( modifiedCalendar ); 1173 inL->setLastModified( modifiedCalendar );
1174 inR = inL->clone(); 1174 inR = inL->clone();
1175 inR->setIDStr( ":" ); 1175 inR->setIDStr( ":" );
1176 remote->addIncidence( inR ); 1176 remote->addIncidence( inR );
1177 } 1177 }
1178 } 1178 }
1179 } 1179 }
1180 } else { 1180 } else {
1181 ++filteredOUT; 1181 ++filteredOUT;
1182 } 1182 }
1183 } 1183 }
1184 } 1184 }
1185 inL = el.next(); 1185 inL = el.next();
1186 } 1186 }
1187 int delFut = 0; 1187 int delFut = 0;
1188 int remRem = 0; 1188 int remRem = 0;
1189 if ( mSyncManager->mWriteBackInFuture ) { 1189 if ( mSyncManager->mWriteBackInFuture ) {
1190 er = remote->rawIncidences(); 1190 er = remote->rawIncidences();
1191 remRem = er.count(); 1191 remRem = er.count();
1192 inR = er.first(); 1192 inR = er.first();
1193 QDateTime dt; 1193 QDateTime dt;
1194 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1194 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1195 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1195 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1196 while ( inR ) { 1196 while ( inR ) {
1197 if ( inR->type() == "Todo" ) { 1197 if ( inR->type() == "Todo" ) {
1198 Todo * t = (Todo*)inR; 1198 Todo * t = (Todo*)inR;
1199 if ( t->hasDueDate() ) 1199 if ( t->hasDueDate() )
1200 dt = t->dtDue(); 1200 dt = t->dtDue();
1201 else 1201 else
1202 dt = cur.addSecs( 62 ); 1202 dt = cur.addSecs( 62 );
1203 } 1203 }
1204 else if (inR->type() == "Event" ) { 1204 else if (inR->type() == "Event" ) {
1205 bool ok; 1205 bool ok;
1206 dt = inR->getNextOccurence( cur, &ok ); 1206 dt = inR->getNextOccurence( cur, &ok );
1207 if ( !ok ) 1207 if ( !ok )
1208 dt = cur.addSecs( -62 ); 1208 dt = cur.addSecs( -62 );
1209 } 1209 }
1210 else 1210 else
1211 dt = inR->dtStart(); 1211 dt = inR->dtStart();
1212 if ( dt < cur || dt > end ) { 1212 if ( dt < cur || dt > end ) {
1213 remote->deleteIncidence( inR ); 1213 remote->deleteIncidence( inR );
1214 ++delFut; 1214 ++delFut;
1215 } 1215 }
1216 inR = er.next(); 1216 inR = er.next();
1217 } 1217 }
1218 } 1218 }
1219 bar.hide(); 1219 bar.hide();
1220 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1220 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1221 eventLSync->setReadOnly( false ); 1221 eventLSync->setReadOnly( false );
1222 eventLSync->setDtStart( mLastCalendarSync ); 1222 eventLSync->setDtStart( mLastCalendarSync );
1223 eventRSync->setDtStart( mLastCalendarSync ); 1223 eventRSync->setDtStart( mLastCalendarSync );
1224 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1224 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1225 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1225 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1226 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1226 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1227 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1227 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1228 eventLSync->setReadOnly( true ); 1228 eventLSync->setReadOnly( true );
1229 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1229 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1230 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1230 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1231 remote->addEvent( eventRSync ); 1231 remote->addEvent( eventRSync );
1232 else 1232 else
1233 delete eventRSync; 1233 delete eventRSync;
1234 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1234 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1235 QString mes; 1235 QString mes;
1236 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1236 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1237 QString delmess; 1237 QString delmess;
1238 if ( delFut ) { 1238 if ( delFut ) {
1239 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1239 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1240 mes += delmess; 1240 mes += delmess;
1241 } 1241 }
1242 mes = i18n("Local calendar changed!\n") +mes; 1242 mes = i18n("Local calendar changed!\n") +mes;
1243 mCalendar->checkAlarmForIncidence( 0, true ); 1243 mCalendar->checkAlarmForIncidence( 0, true );
1244 qDebug( mes ); 1244 qDebug( mes );
1245 if ( mSyncManager->mShowSyncSummary ) { 1245 if ( mSyncManager->mShowSyncSummary ) {
1246 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1246 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1247 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1247 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1248 qDebug("KO: WB cancelled "); 1248 qDebug("KO: WB cancelled ");
1249 mSyncManager->mWriteBackFile = false; 1249 mSyncManager->mWriteBackFile = false;
1250 return syncOK; 1250 return syncOK;
1251 } 1251 }
1252 } 1252 }
1253 return syncOK; 1253 return syncOK;
1254} 1254}
1255 1255
1256void CalendarView::setSyncDevice( QString s ) 1256void CalendarView::setSyncDevice( QString s )
1257{ 1257{
1258 mCurrentSyncDevice= s; 1258 mCurrentSyncDevice= s;
1259} 1259}
1260void CalendarView::setSyncName( QString s ) 1260void CalendarView::setSyncName( QString s )
1261{ 1261{
1262 mCurrentSyncName= s; 1262 mCurrentSyncName= s;
1263} 1263}
1264bool CalendarView::syncCalendar(QString filename, int mode) 1264bool CalendarView::syncCalendar(QString filename, int mode)
1265{ 1265{
1266 //qDebug("syncCalendar %s ", filename.latin1()); 1266 //qDebug("syncCalendar %s ", filename.latin1());
1267 mGlobalSyncMode = SYNC_MODE_NORMAL; 1267 mGlobalSyncMode = SYNC_MODE_NORMAL;
1268 CalendarLocal* calendar = new CalendarLocal(); 1268 CalendarLocal* calendar = new CalendarLocal();
1269 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1269 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1270 FileStorage* storage = new FileStorage( calendar ); 1270 FileStorage* storage = new FileStorage( calendar );
1271 bool syncOK = false; 1271 bool syncOK = false;
1272 storage->setFileName( filename ); 1272 storage->setFileName( filename );
1273 // qDebug("loading ... "); 1273 // qDebug("loading ... ");
1274 if ( storage->load() ) { 1274 if ( storage->load() ) {
1275 getEventViewerDialog()->setSyncMode( true ); 1275 getEventViewerDialog()->setSyncMode( true );
1276 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1276 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1277 getEventViewerDialog()->setSyncMode( false ); 1277 getEventViewerDialog()->setSyncMode( false );
1278 if ( syncOK ) { 1278 if ( syncOK ) {
1279 if ( mSyncManager->mWriteBackFile ) 1279 if ( mSyncManager->mWriteBackFile )
1280 { 1280 {
1281 storage->setSaveFormat( new ICalFormat() ); 1281 storage->setSaveFormat( new ICalFormat() );
1282 storage->save(); 1282 storage->save();
1283 } 1283 }
1284 } 1284 }
1285 setModified( true ); 1285 setModified( true );
1286 } 1286 }
1287 delete storage; 1287 delete storage;
1288 delete calendar; 1288 delete calendar;
1289 if ( syncOK ) 1289 if ( syncOK )
1290 updateView(); 1290 updateView();
1291 return syncOK; 1291 return syncOK;
1292} 1292}
1293 1293
1294void CalendarView::syncExternal( int mode ) 1294void CalendarView::syncExternal( int mode )
1295{ 1295{
1296 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1296 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1297 1297
1298 qApp->processEvents(); 1298 qApp->processEvents();
1299 CalendarLocal* calendar = new CalendarLocal(); 1299 CalendarLocal* calendar = new CalendarLocal();
1300 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1300 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1301 bool syncOK = false; 1301 bool syncOK = false;
1302 bool loadSuccess = false; 1302 bool loadSuccess = false;
1303 PhoneFormat* phoneFormat = 0; 1303 PhoneFormat* phoneFormat = 0;
1304 emit tempDisableBR(true); 1304 emit tempDisableBR(true);
1305#ifndef DESKTOP_VERSION 1305#ifndef DESKTOP_VERSION
1306 SharpFormat* sharpFormat = 0; 1306 SharpFormat* sharpFormat = 0;
1307 if ( mode == 0 ) { // sharp 1307 if ( mode == 0 ) { // sharp
1308 sharpFormat = new SharpFormat () ; 1308 sharpFormat = new SharpFormat () ;
1309 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1309 loadSuccess = sharpFormat->load( calendar, mCalendar );
1310 1310
1311 } else 1311 } else
1312#endif 1312#endif
1313 if ( mode == 1 ) { // phone 1313 if ( mode == 1 ) { // phone
1314 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1314 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1315 mSyncManager->mPhoneDevice, 1315 mSyncManager->mPhoneDevice,
1316 mSyncManager->mPhoneConnection, 1316 mSyncManager->mPhoneConnection,
1317 mSyncManager->mPhoneModel); 1317 mSyncManager->mPhoneModel);
1318 loadSuccess = phoneFormat->load( calendar,mCalendar); 1318 loadSuccess = phoneFormat->load( calendar,mCalendar);
1319 1319
1320 } else { 1320 } else {
1321 emit tempDisableBR(false); 1321 emit tempDisableBR(false);
1322 return; 1322 return;
1323 } 1323 }
1324 if ( loadSuccess ) { 1324 if ( loadSuccess ) {
1325 getEventViewerDialog()->setSyncMode( true ); 1325 getEventViewerDialog()->setSyncMode( true );
1326 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1326 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1327 getEventViewerDialog()->setSyncMode( false ); 1327 getEventViewerDialog()->setSyncMode( false );
1328 qApp->processEvents(); 1328 qApp->processEvents();
1329 if ( syncOK ) { 1329 if ( syncOK ) {
1330 if ( mSyncManager->mWriteBackFile ) 1330 if ( mSyncManager->mWriteBackFile )
1331 { 1331 {
1332 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1332 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1333 Incidence* inc = iL.first(); 1333 Incidence* inc = iL.first();
1334 if ( phoneFormat ) { 1334 if ( phoneFormat ) {
1335 while ( inc ) { 1335 while ( inc ) {
1336 inc->removeID(mCurrentSyncDevice); 1336 inc->removeID(mCurrentSyncDevice);
1337 inc = iL.next(); 1337 inc = iL.next();
1338 } 1338 }
1339 } 1339 }
1340#ifndef DESKTOP_VERSION 1340#ifndef DESKTOP_VERSION
1341 if ( sharpFormat ) 1341 if ( sharpFormat )
1342 sharpFormat->save(calendar); 1342 sharpFormat->save(calendar);
1343#endif 1343#endif
1344 if ( phoneFormat ) 1344 if ( phoneFormat )
1345 phoneFormat->save(calendar); 1345 phoneFormat->save(calendar);
1346 iL = calendar->rawIncidences(); 1346 iL = calendar->rawIncidences();
1347 inc = iL.first(); 1347 inc = iL.first();
1348 Incidence* loc; 1348 Incidence* loc;
1349 while ( inc ) { 1349 while ( inc ) {
1350 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1350 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1351 loc = mCalendar->incidence(inc->uid() ); 1351 loc = mCalendar->incidence(inc->uid() );
1352 if ( loc ) { 1352 if ( loc ) {
1353 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1353 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1354 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1354 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1355 } 1355 }
1356 } 1356 }
1357 inc = iL.next(); 1357 inc = iL.next();
1358 } 1358 }
1359 Incidence* lse = getLastSyncEvent(); 1359 Incidence* lse = getLastSyncEvent();
1360 if ( lse ) { 1360 if ( lse ) {
1361 lse->setReadOnly( false ); 1361 lse->setReadOnly( false );
1362 lse->setDescription( "" ); 1362 lse->setDescription( "" );
1363 lse->setReadOnly( true ); 1363 lse->setReadOnly( true );
1364 } 1364 }
1365 } 1365 }
1366 } else { 1366 } else {
1367 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1367 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1368 } 1368 }
1369 setModified( true ); 1369 setModified( true );
1370 } else { 1370 } else {
1371 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1371 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1372 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1372 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1373 question, i18n("Ok")) ; 1373 question, i18n("Ok")) ;
1374 1374
1375 } 1375 }
1376 delete calendar; 1376 delete calendar;
1377 updateView(); 1377 updateView();
1378 emit tempDisableBR(false); 1378 emit tempDisableBR(false);
1379 return ;//syncOK; 1379 return ;//syncOK;
1380 1380
1381} 1381}
1382 1382
1383bool CalendarView::importBday() 1383bool CalendarView::importBday()
1384{ 1384{
1385#ifndef KORG_NOKABC 1385#ifndef KORG_NOKABC
1386 1386
1387#ifdef DESKTOP_VERSION 1387#ifdef DESKTOP_VERSION
1388 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1388 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1389 KABC::AddressBook::Iterator it; 1389 KABC::AddressBook::Iterator it;
1390 int count = 0; 1390 int count = 0;
1391 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1391 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1392 ++count; 1392 ++count;
1393 } 1393 }
1394 QProgressBar bar(count,0 ); 1394 QProgressBar bar(count,0 );
1395 int w = 300; 1395 int w = 300;
1396 if ( QApplication::desktop()->width() < 320 ) 1396 if ( QApplication::desktop()->width() < 320 )
1397 w = 220; 1397 w = 220;
1398 int h = bar.sizeHint().height() ; 1398 int h = bar.sizeHint().height() ;
1399 int dw = QApplication::desktop()->width(); 1399 int dw = QApplication::desktop()->width();
1400 int dh = QApplication::desktop()->height(); 1400 int dh = QApplication::desktop()->height();
1401 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1401 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1402 bar.show(); 1402 bar.show();
1403 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1403 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1404 qApp->processEvents(); 1404 qApp->processEvents();
1405 count = 0; 1405 count = 0;
1406 int addCount = 0; 1406 int addCount = 0;
1407 KCal::Attendee* a = 0; 1407 KCal::Attendee* a = 0;
1408 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1408 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1409 if ( ! bar.isVisible() ) 1409 if ( ! bar.isVisible() )
1410 return false; 1410 return false;
1411 bar.setProgress( count++ ); 1411 bar.setProgress( count++ );
1412 qApp->processEvents(); 1412 qApp->processEvents();
1413 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1413 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1414 if ( (*it).birthday().date().isValid() ){ 1414 if ( (*it).birthday().date().isValid() ){
1415 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1415 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1416 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1416 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1417 ++addCount; 1417 ++addCount;
1418 } 1418 }
1419 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1419 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1420 if ( anni.isValid() ){ 1420 if ( anni.isValid() ){
1421 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1421 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1422 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1422 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1423 ++addCount; 1423 ++addCount;
1424 } 1424 }
1425 } 1425 }
1426 updateView(); 1426 updateView();
1427 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1427 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1428#else //DESKTOP_VERSION 1428#else //DESKTOP_VERSION
1429 1429
1430 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1430 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1431 // the result should now arrive through method insertBirthdays 1431 // the result should now arrive through method insertBirthdays
1432 1432
1433#endif //DESKTOP_VERSION 1433#endif //DESKTOP_VERSION
1434 1434
1435#endif //KORG_NOKABC 1435#endif //KORG_NOKABC
1436 1436
1437 1437
1438 return true; 1438 return true;
1439} 1439}
1440 1440
1441// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1441// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1442void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1442void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1443 const QStringList& anniversaryList, const QStringList& realNameList, 1443 const QStringList& anniversaryList, const QStringList& realNameList,
1444 const QStringList& emailList, const QStringList& assembledNameList, 1444 const QStringList& emailList, const QStringList& assembledNameList,
1445 const QStringList& uidList) 1445 const QStringList& uidList)
1446{ 1446{
1447 //qDebug("KO::CalendarView::insertBirthdays"); 1447 //qDebug("KO::CalendarView::insertBirthdays");
1448 if (uid == this->name()) 1448 if (uid == this->name())
1449 { 1449 {
1450 int count = birthdayList.count(); 1450 int count = birthdayList.count();
1451 int addCount = 0; 1451 int addCount = 0;
1452 KCal::Attendee* a = 0; 1452 KCal::Attendee* a = 0;
1453 1453
1454 //qDebug("CalView 1 %i", count); 1454 //qDebug("CalView 1 %i", count);
1455 1455
1456 QProgressBar bar(count,0 ); 1456 QProgressBar bar(count,0 );
1457 int w = 300; 1457 int w = 300;
1458 if ( QApplication::desktop()->width() < 320 ) 1458 if ( QApplication::desktop()->width() < 320 )
1459 w = 220; 1459 w = 220;
1460 int h = bar.sizeHint().height() ; 1460 int h = bar.sizeHint().height() ;
1461 int dw = QApplication::desktop()->width(); 1461 int dw = QApplication::desktop()->width();
1462 int dh = QApplication::desktop()->height(); 1462 int dh = QApplication::desktop()->height();
1463 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1463 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1464 bar.show(); 1464 bar.show();
1465 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1465 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1466 qApp->processEvents(); 1466 qApp->processEvents();
1467 1467
1468 QDate birthday; 1468 QDate birthday;
1469 QDate anniversary; 1469 QDate anniversary;
1470 QString realName; 1470 QString realName;
1471 QString email; 1471 QString email;
1472 QString assembledName; 1472 QString assembledName;
1473 QString uid; 1473 QString uid;
1474 bool ok = true; 1474 bool ok = true;
1475 for ( int i = 0; i < count; i++) 1475 for ( int i = 0; i < count; i++)
1476 { 1476 {
1477 if ( ! bar.isVisible() ) 1477 if ( ! bar.isVisible() )
1478 return; 1478 return;
1479 bar.setProgress( i ); 1479 bar.setProgress( i );
1480 qApp->processEvents(); 1480 qApp->processEvents();
1481 1481
1482 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1482 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1483 if (!ok) { 1483 if (!ok) {
1484 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1484 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1485 } 1485 }
1486 1486
1487 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1487 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1488 if (!ok) { 1488 if (!ok) {
1489 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1489 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1490 } 1490 }
1491 realName = realNameList[i]; 1491 realName = realNameList[i];
1492 email = emailList[i]; 1492 email = emailList[i];
1493 assembledName = assembledNameList[i]; 1493 assembledName = assembledNameList[i];
1494 uid = uidList[i]; 1494 uid = uidList[i];
1495 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1495 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1496 1496
1497 if ( birthday.isValid() ){ 1497 if ( birthday.isValid() ){
1498 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1498 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1499 KCal::Attendee::ReqParticipant,uid) ; 1499 KCal::Attendee::ReqParticipant,uid) ;
1500 if ( addAnniversary( birthday, assembledName, a, true ) ) 1500 if ( addAnniversary( birthday, assembledName, a, true ) )
1501 ++addCount; 1501 ++addCount;
1502 } 1502 }
1503 1503
1504 if ( anniversary.isValid() ){ 1504 if ( anniversary.isValid() ){
1505 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1505 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1506 KCal::Attendee::ReqParticipant,uid) ; 1506 KCal::Attendee::ReqParticipant,uid) ;
1507 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1507 if ( addAnniversary( anniversary, assembledName, a, false ) )
1508 ++addCount; 1508 ++addCount;
1509 } 1509 }
1510 } 1510 }
1511 1511
1512 updateView(); 1512 updateView();
1513 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1513 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1514 1514
1515 } 1515 }
1516 1516
1517} 1517}
1518 1518
1519 1519
1520 1520
1521bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1521bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1522{ 1522{
1523 //qDebug("addAnni "); 1523 //qDebug("addAnni ");
1524 Event * ev = new Event(); 1524 Event * ev = new Event();
1525 ev->setOrganizer(KOPrefs::instance()->email()); 1525 ev->setOrganizer(KOPrefs::instance()->email());
1526 if ( a ) { 1526 if ( a ) {
1527 ev->addAttendee( a ); 1527 ev->addAttendee( a );
1528 } 1528 }
1529 QString kind; 1529 QString kind;
1530 if ( birthday ) { 1530 if ( birthday ) {
1531 kind = i18n( "Birthday" ); 1531 kind = i18n( "Birthday" );
1532 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1532 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1533 } 1533 }
1534 else { 1534 else {
1535 kind = i18n( "Anniversary" ); 1535 kind = i18n( "Anniversary" );
1536 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1536 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1537 } 1537 }
1538 ev->setCategories( kind ); 1538 ev->setCategories( kind );
1539 ev->setDtStart( QDateTime(date) ); 1539 ev->setDtStart( QDateTime(date) );
1540 ev->setDtEnd( QDateTime(date) ); 1540 ev->setDtEnd( QDateTime(date) );
1541 ev->setFloats( true ); 1541 ev->setFloats( true );
1542 Recurrence * rec = ev->recurrence(); 1542 Recurrence * rec = ev->recurrence();
1543 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1543 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1544 rec->addYearlyNum( date.month() ); 1544 rec->addYearlyNum( date.month() );
1545 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1545 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1546 delete ev; 1546 delete ev;
1547 return false; 1547 return false;
1548 } 1548 }
1549 return true; 1549 return true;
1550 1550
1551} 1551}
1552bool CalendarView::importQtopia( const QString &categories, 1552bool CalendarView::importQtopia( const QString &categories,
1553 const QString &datebook, 1553 const QString &datebook,
1554 const QString &todolist ) 1554 const QString &todolist )
1555{ 1555{
1556 1556
1557 QtopiaFormat qtopiaFormat; 1557 QtopiaFormat qtopiaFormat;
1558 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1558 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1559 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1559 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1560 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1560 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1561 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1561 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1562 1562
1563 updateView(); 1563 updateView();
1564 return true; 1564 return true;
1565 1565
1566#if 0 1566#if 0
1567 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1567 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1568 mCurrentSyncDevice = "qtopia-XML"; 1568 mCurrentSyncDevice = "qtopia-XML";
1569 if ( mSyncManager->mAskForPreferences ) 1569 if ( mSyncManager->mAskForPreferences )
1570 edit_sync_options(); 1570 edit_sync_options();
1571 qApp->processEvents(); 1571 qApp->processEvents();
1572 CalendarLocal* calendar = new CalendarLocal(); 1572 CalendarLocal* calendar = new CalendarLocal();
1573 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1573 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1574 bool syncOK = false; 1574 bool syncOK = false;
1575 QtopiaFormat qtopiaFormat; 1575 QtopiaFormat qtopiaFormat;
1576 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1576 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1577 bool loadOk = true; 1577 bool loadOk = true;
1578 if ( !categories.isEmpty() ) 1578 if ( !categories.isEmpty() )
1579 loadOk = qtopiaFormat.load( calendar, categories ); 1579 loadOk = qtopiaFormat.load( calendar, categories );
1580 if ( loadOk && !datebook.isEmpty() ) 1580 if ( loadOk && !datebook.isEmpty() )
1581 loadOk = qtopiaFormat.load( calendar, datebook ); 1581 loadOk = qtopiaFormat.load( calendar, datebook );
1582 if ( loadOk && !todolist.isEmpty() ) 1582 if ( loadOk && !todolist.isEmpty() )
1583 loadOk = qtopiaFormat.load( calendar, todolist ); 1583 loadOk = qtopiaFormat.load( calendar, todolist );
1584 1584
1585 if ( loadOk ) { 1585 if ( loadOk ) {
1586 getEventViewerDialog()->setSyncMode( true ); 1586 getEventViewerDialog()->setSyncMode( true );
1587 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1587 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1588 getEventViewerDialog()->setSyncMode( false ); 1588 getEventViewerDialog()->setSyncMode( false );
1589 qApp->processEvents(); 1589 qApp->processEvents();
1590 if ( syncOK ) { 1590 if ( syncOK ) {
1591 if ( mSyncManager->mWriteBackFile ) 1591 if ( mSyncManager->mWriteBackFile )
1592 { 1592 {
1593 // write back XML file 1593 // write back XML file
1594 1594
1595 } 1595 }
1596 setModified( true ); 1596 setModified( true );
1597 } 1597 }
1598 } else { 1598 } else {
1599 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1599 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1600 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1600 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1601 question, i18n("Ok")) ; 1601 question, i18n("Ok")) ;
1602 } 1602 }
1603 delete calendar; 1603 delete calendar;
1604 updateView(); 1604 updateView();
1605 return syncOK; 1605 return syncOK;
1606 1606
1607 1607
1608#endif 1608#endif
1609 1609
1610} 1610}
1611 1611
1612void CalendarView::setSyncEventsReadOnly() 1612void CalendarView::setSyncEventsReadOnly()
1613{ 1613{
1614 Event * ev; 1614 Event * ev;
1615 QPtrList<Event> eL = mCalendar->rawEvents(); 1615 QPtrList<Event> eL = mCalendar->rawEvents();
1616 ev = eL.first(); 1616 ev = eL.first();
1617 while ( ev ) { 1617 while ( ev ) {
1618 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1618 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1619 ev->setReadOnly( true ); 1619 ev->setReadOnly( true );
1620 ev = eL.next(); 1620 ev = eL.next();
1621 } 1621 }
1622} 1622}
1623bool CalendarView::openCalendar(QString filename, bool merge) 1623bool CalendarView::openCalendar(QString filename, bool merge)
1624{ 1624{
1625 1625
1626 if (filename.isEmpty()) { 1626 if (filename.isEmpty()) {
1627 return false; 1627 return false;
1628 } 1628 }
1629 1629
1630 if (!QFile::exists(filename)) { 1630 if (!QFile::exists(filename)) {
1631 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1631 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1632 return false; 1632 return false;
1633 } 1633 }
1634 1634
1635 globalFlagBlockAgenda = 1; 1635 globalFlagBlockAgenda = 1;
1636 if (!merge) mCalendar->close(); 1636 if (!merge) mCalendar->close();
1637 1637
1638 mStorage->setFileName( filename ); 1638 mStorage->setFileName( filename );
1639 1639
1640 if ( mStorage->load() ) { 1640 if ( mStorage->load() ) {
1641 if ( merge ) ;//setModified( true ); 1641 if ( merge ) ;//setModified( true );
1642 else { 1642 else {
1643 //setModified( true ); 1643 //setModified( true );
1644 mViewManager->setDocumentId( filename ); 1644 mViewManager->setDocumentId( filename );
1645 mDialogManager->setDocumentId( filename ); 1645 mDialogManager->setDocumentId( filename );
1646 mTodoList->setDocumentId( filename ); 1646 mTodoList->setDocumentId( filename );
1647 } 1647 }
1648 globalFlagBlockAgenda = 2; 1648 globalFlagBlockAgenda = 2;
1649 // if ( getLastSyncEvent() ) 1649 // if ( getLastSyncEvent() )
1650 // getLastSyncEvent()->setReadOnly( true ); 1650 // getLastSyncEvent()->setReadOnly( true );
1651 mCalendar->reInitAlarmSettings(); 1651 mCalendar->reInitAlarmSettings();
1652 setSyncEventsReadOnly(); 1652 setSyncEventsReadOnly();
1653 updateUnmanagedViews(); 1653 updateUnmanagedViews();
1654 updateView(); 1654 updateView();
1655 if ( filename != MainWindow::defaultFileName() ) { 1655 if ( filename != MainWindow::defaultFileName() ) {
1656 saveCalendar( MainWindow::defaultFileName() ); 1656 saveCalendar( MainWindow::defaultFileName() );
1657 } else { 1657 } else {
1658 QFileInfo finf ( MainWindow::defaultFileName()); 1658 QFileInfo finf ( MainWindow::defaultFileName());
1659 if ( finf.exists() ) { 1659 if ( finf.exists() ) {
1660 setLoadedFileVersion( finf.lastModified () ); 1660 setLoadedFileVersion( finf.lastModified () );
1661 } 1661 }
1662 } 1662 }
1663 return true; 1663 return true;
1664 } else { 1664 } else {
1665 // while failing to load, the calendar object could 1665 // while failing to load, the calendar object could
1666 // have become partially populated. Clear it out. 1666 // have become partially populated. Clear it out.
1667 if ( !merge ) { 1667 if ( !merge ) {
1668 mCalendar->close(); 1668 mCalendar->close();
1669 mViewManager->setDocumentId( filename ); 1669 mViewManager->setDocumentId( filename );
1670 mDialogManager->setDocumentId( filename ); 1670 mDialogManager->setDocumentId( filename );
1671 mTodoList->setDocumentId( filename ); 1671 mTodoList->setDocumentId( filename );
1672 } 1672 }
1673 1673
1674 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1674 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1675 1675
1676 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1676 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1677 globalFlagBlockAgenda = 2; 1677 globalFlagBlockAgenda = 2;
1678 mCalendar->reInitAlarmSettings(); 1678 mCalendar->reInitAlarmSettings();
1679 setSyncEventsReadOnly(); 1679 setSyncEventsReadOnly();
1680 updateUnmanagedViews(); 1680 updateUnmanagedViews();
1681 updateView(); 1681 updateView();
1682 } 1682 }
1683 return false; 1683 return false;
1684} 1684}
1685void CalendarView::showOpenError() 1685void CalendarView::showOpenError()
1686{ 1686{
1687 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1687 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1688} 1688}
1689void CalendarView::setLoadedFileVersion(QDateTime dt) 1689void CalendarView::setLoadedFileVersion(QDateTime dt)
1690{ 1690{
1691 loadedFileVersion = dt; 1691 loadedFileVersion = dt;
1692} 1692}
1693bool CalendarView::checkFileChanged(QString fn) 1693bool CalendarView::checkFileChanged(QString fn)
1694{ 1694{
1695 QFileInfo finf ( fn ); 1695 QFileInfo finf ( fn );
1696 if ( !finf.exists() ) 1696 if ( !finf.exists() )
1697 return true; 1697 return true;
1698 QDateTime dt = finf.lastModified (); 1698 QDateTime dt = finf.lastModified ();
1699 if ( dt <= loadedFileVersion ) 1699 if ( dt <= loadedFileVersion )
1700 return false; 1700 return false;
1701 return true; 1701 return true;
1702 1702
1703} 1703}
1704void CalendarView::watchSavedFile() 1704void CalendarView::watchSavedFile()
1705{ 1705{
1706 QFileInfo finf ( MainWindow::defaultFileName()); 1706 QFileInfo finf ( MainWindow::defaultFileName());
1707 if ( !finf.exists() ) 1707 if ( !finf.exists() )
1708 return; 1708 return;
1709 QDateTime dt = finf.lastModified (); 1709 QDateTime dt = finf.lastModified ();
1710 if ( dt < loadedFileVersion ) { 1710 if ( dt < loadedFileVersion ) {
1711 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1711 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1712 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1712 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1713 return; 1713 return;
1714 } 1714 }
1715 loadedFileVersion = dt; 1715 loadedFileVersion = dt;
1716} 1716}
1717 1717
1718bool CalendarView::checkFileVersion(QString fn) 1718bool CalendarView::checkFileVersion(QString fn)
1719{ 1719{
1720 QFileInfo finf ( fn ); 1720 QFileInfo finf ( fn );
1721 if ( !finf.exists() ) 1721 if ( !finf.exists() )
1722 return true; 1722 return true;
1723 QDateTime dt = finf.lastModified (); 1723 QDateTime dt = finf.lastModified ();
1724 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1724 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1725 //qDebug("file on disk version %s",dt.toString().latin1()); 1725 //qDebug("file on disk version %s",dt.toString().latin1());
1726 if ( dt <= loadedFileVersion ) 1726 if ( dt <= loadedFileVersion )
1727 return true; 1727 return true;
1728 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)) , 1728 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)) ,
1729 i18n("KO/Pi Warning"),i18n("Overwrite"), 1729 i18n("KO/Pi Warning"),i18n("Overwrite"),
1730 i18n("Sync+save")); 1730 i18n("Sync+save"));
1731 1731
1732 if ( km == KMessageBox::Cancel ) 1732 if ( km == KMessageBox::Cancel )
1733 return false; 1733 return false;
1734 if ( km == KMessageBox::Yes ) 1734 if ( km == KMessageBox::Yes )
1735 return true; 1735 return true;
1736 1736
1737 setSyncDevice("deleteaftersync" ); 1737 setSyncDevice("deleteaftersync" );
1738 mSyncManager->mAskForPreferences = true; 1738 mSyncManager->mAskForPreferences = true;
1739 mSyncManager->mSyncAlgoPrefs = 3; 1739 mSyncManager->mSyncAlgoPrefs = 3;
1740 mSyncManager->mWriteBackFile = false; 1740 mSyncManager->mWriteBackFile = false;
1741 mSyncManager->mWriteBackExistingOnly = false; 1741 mSyncManager->mWriteBackExistingOnly = false;
1742 mSyncManager->mShowSyncSummary = false; 1742 mSyncManager->mShowSyncSummary = false;
1743 syncCalendar( fn, 3 ); 1743 syncCalendar( fn, 3 );
1744 Event * e = getLastSyncEvent(); 1744 Event * e = getLastSyncEvent();
1745 mCalendar->deleteEvent ( e ); 1745 mCalendar->deleteEvent ( e );
1746 updateView(); 1746 updateView();
1747 return true; 1747 return true;
1748} 1748}
1749 1749
1750bool CalendarView::saveCalendar( QString filename ) 1750bool CalendarView::saveCalendar( QString filename )
1751{ 1751{
1752 1752
1753 // Store back all unsaved data into calendar object 1753 // Store back all unsaved data into calendar object
1754 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1754 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1755 if ( mViewManager->currentView() ) 1755 if ( mViewManager->currentView() )
1756 mViewManager->currentView()->flushView(); 1756 mViewManager->currentView()->flushView();
1757 1757
1758 1758
1759 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1759 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1760 mStorage->setSaveFormat( new ICalFormat() ); 1760 mStorage->setSaveFormat( new ICalFormat() );
1761 mStorage->setFileName( filename ); 1761 mStorage->setFileName( filename );
1762 bool success; 1762 bool success;
1763 success = mStorage->save(); 1763 success = mStorage->save();
1764 if ( !success ) { 1764 if ( !success ) {
1765 return false; 1765 return false;
1766 } 1766 }
1767 if ( filename == MainWindow::defaultFileName() ) { 1767 if ( filename == MainWindow::defaultFileName() ) {
1768 setLoadedFileVersion( lfv ); 1768 setLoadedFileVersion( lfv );
1769 watchSavedFile(); 1769 watchSavedFile();
1770 } 1770 }
1771 return true; 1771 return true;
1772} 1772}
1773 1773
1774void CalendarView::closeCalendar() 1774void CalendarView::closeCalendar()
1775{ 1775{
1776 1776
1777 // child windows no longer valid 1777 // child windows no longer valid
1778 emit closingDown(); 1778 emit closingDown();
1779 1779
1780 mCalendar->close(); 1780 mCalendar->close();
1781 setModified(false); 1781 setModified(false);
1782 updateView(); 1782 updateView();
1783} 1783}
1784 1784
1785void CalendarView::archiveCalendar() 1785void CalendarView::archiveCalendar()
1786{ 1786{
1787 mDialogManager->showArchiveDialog(); 1787 mDialogManager->showArchiveDialog();
1788} 1788}
1789 1789
1790 1790
1791void CalendarView::readSettings() 1791void CalendarView::readSettings()
1792{ 1792{
1793 1793
1794 1794
1795 // mViewManager->showAgendaView(); 1795 // mViewManager->showAgendaView();
1796 QString str; 1796 QString str;
1797 //qDebug("CalendarView::readSettings() "); 1797 //qDebug("CalendarView::readSettings() ");
1798 // read settings from the KConfig, supplying reasonable 1798 // read settings from the KConfig, supplying reasonable
1799 // defaults where none are to be found 1799 // defaults where none are to be found
1800 KConfig *config = KOGlobals::config(); 1800 KConfig *config = KOGlobals::config();
1801#ifndef KORG_NOSPLITTER 1801#ifndef KORG_NOSPLITTER
1802 config->setGroup("KOrganizer Geometry"); 1802 config->setGroup("KOrganizer Geometry");
1803 1803
1804 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1804 QValueList<int> sizes = config->readIntListEntry("Separator1");
1805 if (sizes.count() != 2) { 1805 if (sizes.count() != 2) {
1806 sizes << mDateNavigator->minimumSizeHint().width(); 1806 sizes << mDateNavigator->minimumSizeHint().width();
1807 sizes << 300; 1807 sizes << 300;
1808 } 1808 }
1809 mPanner->setSizes(sizes); 1809 mPanner->setSizes(sizes);
1810 1810
1811 sizes = config->readIntListEntry("Separator2"); 1811 sizes = config->readIntListEntry("Separator2");
1812 if ( ( mResourceView && sizes.count() == 4 ) || 1812 if ( ( mResourceView && sizes.count() == 4 ) ||
1813 ( !mResourceView && sizes.count() == 3 ) ) { 1813 ( !mResourceView && sizes.count() == 3 ) ) {
1814 mLeftSplitter->setSizes(sizes); 1814 mLeftSplitter->setSizes(sizes);
1815 } 1815 }
1816#endif 1816#endif
1817 globalFlagBlockAgenda = 1; 1817 globalFlagBlockAgenda = 1;
1818 mViewManager->showAgendaView(); 1818 mViewManager->showAgendaView();
1819 //mViewManager->readSettings( config ); 1819 //mViewManager->readSettings( config );
1820 mTodoList->restoreLayout(config,QString("Todo Layout")); 1820 mTodoList->restoreLayout(config,QString("Todo Layout"));
1821 readFilterSettings(config); 1821 readFilterSettings(config);
1822 config->setGroup( "Views" ); 1822 config->setGroup( "Views" );
1823 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1823 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1824
1825 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
1826
1827 int resetval = 0;
1828 int maxVal = 0;
1829 if (sizes.count() != 3) {
1830 if ( KOPrefs::instance()->mVerticalScreen ) {
1831 resetval = mDateNavigator->sizeHint().width()+2;
1832 } else {
1833 resetval = mDateNavigator->sizeHint().height()+2;
1834 }
1835 }
1836 if ( !resetval ){// i.e. sizes.count() == 3
1837 if ( KOPrefs::instance()->mVerticalScreen ) {
1838 if ( sizes[0] < mDateNavigator->sizeHint().width()+1 )
1839 resetval = mDateNavigator->sizeHint().width()+2;
1840 } else {
1841 if ( sizes[0] < mDateNavigator->sizeHint().height()+1 )
1842 resetval = mDateNavigator->sizeHint().height()+2;
1843 }
1844 }
1845 if ( resetval ) {
1846 sizes.clear();
1847 if ( KOPrefs::instance()->mVerticalScreen ) {
1848 maxVal = QApplication::desktop()->width() -10;
1849 } else {
1850 maxVal = QApplication::desktop()->height()-10;
1851 }
1852 sizes << resetval;
1853 if ( maxVal < resetval + resetval)
1854 resetval = maxVal - resetval;
1855 sizes << resetval;
1856 sizes << 100;
1857 }
1858 mLeftFrame->setSizes(sizes);
1859 qDebug("sizes count %d ", sizes.count());
1824 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1860 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1825 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1861 else if ( dateCount == 7 ) mNavigator->selectWeek();
1826 else mNavigator->selectDates( dateCount ); 1862 else mNavigator->selectDates( dateCount );
1827 // mViewManager->readSettings( config ); 1863 // mViewManager->readSettings( config );
1828 updateConfig(); 1864 updateConfig();
1829 globalFlagBlockAgenda = 2; 1865 globalFlagBlockAgenda = 2;
1830 mViewManager->readSettings( config ); 1866 mViewManager->readSettings( config );
1831#ifdef DESKTOP_VERSION 1867#ifdef DESKTOP_VERSION
1832 config->setGroup("WidgetLayout"); 1868 config->setGroup("WidgetLayout");
1833 QStringList list; 1869 QStringList list;
1834 list = config->readListEntry("MainLayout"); 1870 list = config->readListEntry("MainLayout");
1835 int x,y,w,h; 1871 int x,y,w,h;
1836 if ( ! list.isEmpty() ) { 1872 if ( ! list.isEmpty() ) {
1837 x = list[0].toInt(); 1873 x = list[0].toInt();
1838 y = list[1].toInt(); 1874 y = list[1].toInt();
1839 w = list[2].toInt(); 1875 w = list[2].toInt();
1840 h = list[3].toInt(); 1876 h = list[3].toInt();
1841 topLevelWidget()->setGeometry(x,y,w,h); 1877 topLevelWidget()->setGeometry(x,y,w,h);
1842 1878
1843 } else { 1879 } else {
1844 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1880 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1845 } 1881 }
1846 list = config->readListEntry("EditEventLayout"); 1882 list = config->readListEntry("EditEventLayout");
1847 if ( ! list.isEmpty() ) { 1883 if ( ! list.isEmpty() ) {
1848 x = list[0].toInt(); 1884 x = list[0].toInt();
1849 y = list[1].toInt(); 1885 y = list[1].toInt();
1850 w = list[2].toInt(); 1886 w = list[2].toInt();
1851 h = list[3].toInt(); 1887 h = list[3].toInt();
1852 mEventEditor->setGeometry(x,y,w,h); 1888 mEventEditor->setGeometry(x,y,w,h);
1853 1889
1854 } 1890 }
1855 list = config->readListEntry("EditTodoLayout"); 1891 list = config->readListEntry("EditTodoLayout");
1856 if ( ! list.isEmpty() ) { 1892 if ( ! list.isEmpty() ) {
1857 x = list[0].toInt(); 1893 x = list[0].toInt();
1858 y = list[1].toInt(); 1894 y = list[1].toInt();
1859 w = list[2].toInt(); 1895 w = list[2].toInt();
1860 h = list[3].toInt(); 1896 h = list[3].toInt();
1861 mTodoEditor->setGeometry(x,y,w,h); 1897 mTodoEditor->setGeometry(x,y,w,h);
1862 1898
1863 } 1899 }
1864 list = config->readListEntry("ViewerLayout"); 1900 list = config->readListEntry("ViewerLayout");
1865 if ( ! list.isEmpty() ) { 1901 if ( ! list.isEmpty() ) {
1866 x = list[0].toInt(); 1902 x = list[0].toInt();
1867 y = list[1].toInt(); 1903 y = list[1].toInt();
1868 w = list[2].toInt(); 1904 w = list[2].toInt();
1869 h = list[3].toInt(); 1905 h = list[3].toInt();
1870 getEventViewerDialog()->setGeometry(x,y,w,h); 1906 getEventViewerDialog()->setGeometry(x,y,w,h);
1871 } 1907 }
1872#endif 1908#endif
1873 1909
1874} 1910}
1875 1911
1876 1912
1877void CalendarView::writeSettings() 1913void CalendarView::writeSettings()
1878{ 1914{
1879 // kdDebug() << "CalendarView::writeSettings" << endl; 1915 // kdDebug() << "CalendarView::writeSettings" << endl;
1880 1916
1881 KConfig *config = KOGlobals::config(); 1917 KConfig *config = KOGlobals::config();
1882 1918
1883#ifndef KORG_NOSPLITTER 1919#ifndef KORG_NOSPLITTER
1884 config->setGroup("KOrganizer Geometry"); 1920 config->setGroup("KOrganizer Geometry");
1885 1921
1886 QValueList<int> list = mPanner->sizes(); 1922 QValueList<int> list = mPanner->sizes();
1887 config->writeEntry("Separator1",list); 1923 config->writeEntry("Separator1",list);
1888 1924
1889 list = mLeftSplitter->sizes(); 1925 list = mLeftSplitter->sizes();
1890 config->writeEntry("Separator2",list); 1926 config->writeEntry("Separator2",list);
1891#endif 1927#endif
1892 1928
1893 mViewManager->writeSettings( config ); 1929 mViewManager->writeSettings( config );
1894 mTodoList->saveLayout(config,QString("Todo Layout")); 1930 mTodoList->saveLayout(config,QString("Todo Layout"));
1895 mDialogManager->writeSettings( config ); 1931 mDialogManager->writeSettings( config );
1896 //KOPrefs::instance()->usrWriteConfig(); 1932 //KOPrefs::instance()->usrWriteConfig();
1897 KOPrefs::instance()->writeConfig(); 1933 KOPrefs::instance()->writeConfig();
1898 1934
1899 writeFilterSettings(config); 1935 writeFilterSettings(config);
1900 1936
1901 config->setGroup( "Views" ); 1937 config->setGroup( "Views" );
1902 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1938 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1903 1939
1940 QValueList<int> list = mLeftFrame->sizes();
1941 config->writeEntry("Left Splitter Frame",list);
1942
1904#ifdef DESKTOP_VERSION 1943#ifdef DESKTOP_VERSION
1905 config->setGroup("WidgetLayout"); 1944 config->setGroup("WidgetLayout");
1906 QStringList list ;//= config->readListEntry("MainLayout"); 1945 QStringList list ;//= config->readListEntry("MainLayout");
1907 int x,y,w,h; 1946 int x,y,w,h;
1908 QWidget* wid; 1947 QWidget* wid;
1909 wid = topLevelWidget(); 1948 wid = topLevelWidget();
1910 x = wid->geometry().x(); 1949 x = wid->geometry().x();
1911 y = wid->geometry().y(); 1950 y = wid->geometry().y();
1912 w = wid->width(); 1951 w = wid->width();
1913 h = wid->height(); 1952 h = wid->height();
1914 list.clear(); 1953 list.clear();
1915 list << QString::number( x ); 1954 list << QString::number( x );
1916 list << QString::number( y ); 1955 list << QString::number( y );
1917 list << QString::number( w ); 1956 list << QString::number( w );
1918 list << QString::number( h ); 1957 list << QString::number( h );
1919 config->writeEntry("MainLayout",list ); 1958 config->writeEntry("MainLayout",list );
1920 1959
1921 wid = mEventEditor; 1960 wid = mEventEditor;
1922 x = wid->geometry().x(); 1961 x = wid->geometry().x();
1923 y = wid->geometry().y(); 1962 y = wid->geometry().y();
1924 w = wid->width(); 1963 w = wid->width();
1925 h = wid->height(); 1964 h = wid->height();
1926 list.clear(); 1965 list.clear();
1927 list << QString::number( x ); 1966 list << QString::number( x );
1928 list << QString::number( y ); 1967 list << QString::number( y );
1929 list << QString::number( w ); 1968 list << QString::number( w );
1930 list << QString::number( h ); 1969 list << QString::number( h );
1931 config->writeEntry("EditEventLayout",list ); 1970 config->writeEntry("EditEventLayout",list );
1932 1971
1933 wid = mTodoEditor; 1972 wid = mTodoEditor;
1934 x = wid->geometry().x(); 1973 x = wid->geometry().x();
1935 y = wid->geometry().y(); 1974 y = wid->geometry().y();
1936 w = wid->width(); 1975 w = wid->width();
1937 h = wid->height(); 1976 h = wid->height();
1938 list.clear(); 1977 list.clear();
1939 list << QString::number( x ); 1978 list << QString::number( x );
1940 list << QString::number( y ); 1979 list << QString::number( y );
1941 list << QString::number( w ); 1980 list << QString::number( w );
1942 list << QString::number( h ); 1981 list << QString::number( h );
1943 config->writeEntry("EditTodoLayout",list ); 1982 config->writeEntry("EditTodoLayout",list );
1944 wid = getEventViewerDialog(); 1983 wid = getEventViewerDialog();
1945 x = wid->geometry().x(); 1984 x = wid->geometry().x();
1946 y = wid->geometry().y(); 1985 y = wid->geometry().y();
1947 w = wid->width(); 1986 w = wid->width();
1948 h = wid->height(); 1987 h = wid->height();
1949 list.clear(); 1988 list.clear();
1950 list << QString::number( x ); 1989 list << QString::number( x );
1951 list << QString::number( y ); 1990 list << QString::number( y );
1952 list << QString::number( w ); 1991 list << QString::number( w );
1953 list << QString::number( h ); 1992 list << QString::number( h );
1954 config->writeEntry("ViewerLayout",list ); 1993 config->writeEntry("ViewerLayout",list );
1955 wid = mDialogManager->getSearchDialog(); 1994 wid = mDialogManager->getSearchDialog();
1956 if ( wid ) { 1995 if ( wid ) {
1957 x = wid->geometry().x(); 1996 x = wid->geometry().x();
1958 y = wid->geometry().y(); 1997 y = wid->geometry().y();
1959 w = wid->width(); 1998 w = wid->width();
1960 h = wid->height(); 1999 h = wid->height();
1961 list.clear(); 2000 list.clear();
1962 list << QString::number( x ); 2001 list << QString::number( x );
1963 list << QString::number( y ); 2002 list << QString::number( y );
1964 list << QString::number( w ); 2003 list << QString::number( w );
1965 list << QString::number( h ); 2004 list << QString::number( h );
1966 config->writeEntry("SearchLayout",list ); 2005 config->writeEntry("SearchLayout",list );
1967 } 2006 }
1968#endif 2007#endif
1969 2008
1970 2009
1971 config->sync(); 2010 config->sync();
1972} 2011}
1973 2012
1974void CalendarView::readFilterSettings(KConfig *config) 2013void CalendarView::readFilterSettings(KConfig *config)
1975{ 2014{
1976 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2015 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1977 2016
1978 mFilters.clear(); 2017 mFilters.clear();
1979 2018
1980 config->setGroup("General"); 2019 config->setGroup("General");
1981 QStringList filterList = config->readListEntry("CalendarFilters"); 2020 QStringList filterList = config->readListEntry("CalendarFilters");
1982 2021
1983 QStringList::ConstIterator it = filterList.begin(); 2022 QStringList::ConstIterator it = filterList.begin();
1984 QStringList::ConstIterator end = filterList.end(); 2023 QStringList::ConstIterator end = filterList.end();
1985 while(it != end) { 2024 while(it != end) {
1986 // kdDebug() << " filter: " << (*it) << endl; 2025 // kdDebug() << " filter: " << (*it) << endl;
1987 2026
1988 CalFilter *filter; 2027 CalFilter *filter;
1989 filter = new CalFilter(*it); 2028 filter = new CalFilter(*it);
1990 config->setGroup("Filter_" + (*it)); 2029 config->setGroup("Filter_" + (*it));
1991 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2030 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1992 filter->setCriteria(config->readNumEntry("Criteria",0)); 2031 filter->setCriteria(config->readNumEntry("Criteria",0));
1993 filter->setCategoryList(config->readListEntry("CategoryList")); 2032 filter->setCategoryList(config->readListEntry("CategoryList"));
1994 mFilters.append(filter); 2033 mFilters.append(filter);
1995 2034
1996 ++it; 2035 ++it;
1997 } 2036 }
1998 2037
1999 if (mFilters.count() == 0) { 2038 if (mFilters.count() == 0) {
2000 CalFilter *filter = new CalFilter(i18n("Default")); 2039 CalFilter *filter = new CalFilter(i18n("Default"));
2001 mFilters.append(filter); 2040 mFilters.append(filter);
2002 } 2041 }
2003 mFilterView->updateFilters(); 2042 mFilterView->updateFilters();
2004 config->setGroup("FilterView"); 2043 config->setGroup("FilterView");
2005 2044
2006 mFilterView->blockSignals(true); 2045 mFilterView->blockSignals(true);
2007 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2046 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2008 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2047 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2009 mFilterView->blockSignals(false); 2048 mFilterView->blockSignals(false);
2010 // We do it manually to avoid it being done twice by the above calls 2049 // We do it manually to avoid it being done twice by the above calls
2011 updateFilter(); 2050 updateFilter();
2012} 2051}
2013 2052
2014void CalendarView::writeFilterSettings(KConfig *config) 2053void CalendarView::writeFilterSettings(KConfig *config)
2015{ 2054{
2016 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2055 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2017 2056
2018 QStringList filterList; 2057 QStringList filterList;
2019 2058
2020 CalFilter *filter = mFilters.first(); 2059 CalFilter *filter = mFilters.first();
2021 while(filter) { 2060 while(filter) {
2022 // kdDebug() << " fn: " << filter->name() << endl; 2061 // kdDebug() << " fn: " << filter->name() << endl;
2023 filterList << filter->name(); 2062 filterList << filter->name();
2024 config->setGroup("Filter_" + filter->name()); 2063 config->setGroup("Filter_" + filter->name());
2025 config->writeEntry("Criteria",filter->criteria()); 2064 config->writeEntry("Criteria",filter->criteria());
2026 config->writeEntry("CategoryList",filter->categoryList()); 2065 config->writeEntry("CategoryList",filter->categoryList());
2027 filter = mFilters.next(); 2066 filter = mFilters.next();
2028 } 2067 }
2029 config->setGroup("General"); 2068 config->setGroup("General");
2030 config->writeEntry("CalendarFilters",filterList); 2069 config->writeEntry("CalendarFilters",filterList);
2031 2070
2032 config->setGroup("FilterView"); 2071 config->setGroup("FilterView");
2033 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2072 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2034 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2073 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2035} 2074}
2036 2075
2037 2076
2038void CalendarView::goToday() 2077void CalendarView::goToday()
2039{ 2078{
2040 if ( mViewManager->currentView()->isMonthView() ) 2079 if ( mViewManager->currentView()->isMonthView() )
2041 mNavigator->selectTodayMonth(); 2080 mNavigator->selectTodayMonth();
2042 else 2081 else
2043 mNavigator->selectToday(); 2082 mNavigator->selectToday();
2044} 2083}
2045 2084
2046void CalendarView::goNext() 2085void CalendarView::goNext()
2047{ 2086{
2048 mNavigator->selectNext(); 2087 mNavigator->selectNext();
2049} 2088}
2050 2089
2051void CalendarView::goPrevious() 2090void CalendarView::goPrevious()
2052{ 2091{
2053 mNavigator->selectPrevious(); 2092 mNavigator->selectPrevious();
2054} 2093}
2055void CalendarView::goNextMonth() 2094void CalendarView::goNextMonth()
2056{ 2095{
2057 mNavigator->selectNextMonth(); 2096 mNavigator->selectNextMonth();
2058} 2097}
2059 2098
2060void CalendarView::goPreviousMonth() 2099void CalendarView::goPreviousMonth()
2061{ 2100{
2062 mNavigator->selectPreviousMonth(); 2101 mNavigator->selectPreviousMonth();
2063} 2102}
2064void CalendarView::writeLocale() 2103void CalendarView::writeLocale()
2065{ 2104{
2066 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2105 //KPimGlobalPrefs::instance()->setGlobalConfig();
2067#if 0 2106#if 0
2068 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2107 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2069 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2108 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2070 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2109 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2071 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2110 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2072 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2111 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2073 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2112 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2074 dummy = KOPrefs::instance()->mUserDateFormatShort; 2113 dummy = KOPrefs::instance()->mUserDateFormatShort;
2075 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2114 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2076 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2115 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2077 KOPrefs::instance()->mDaylightsavingStart, 2116 KOPrefs::instance()->mDaylightsavingStart,
2078 KOPrefs::instance()->mDaylightsavingEnd ); 2117 KOPrefs::instance()->mDaylightsavingEnd );
2079 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2118 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2080#endif 2119#endif
2081} 2120}
2082void CalendarView::updateConfig() 2121void CalendarView::updateConfig()
2083{ 2122{
2084 writeLocale(); 2123 writeLocale();
2085 if ( KOPrefs::instance()->mUseAppColors ) 2124 if ( KOPrefs::instance()->mUseAppColors )
2086 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2125 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2087 emit configChanged(); 2126 emit configChanged();
2088 mTodoList->updateConfig(); 2127 mTodoList->updateConfig();
2089 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2128 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2090 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2129 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2091 // To make the "fill window" configurations work 2130 // To make the "fill window" configurations work
2092 //mViewManager->raiseCurrentView(); 2131 //mViewManager->raiseCurrentView();
2093} 2132}
2094 2133
2095 2134
2096void CalendarView::eventChanged(Event *event) 2135void CalendarView::eventChanged(Event *event)
2097{ 2136{
2098 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2137 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2099 //updateUnmanagedViews(); 2138 //updateUnmanagedViews();
2100} 2139}
2101 2140
2102void CalendarView::eventAdded(Event *event) 2141void CalendarView::eventAdded(Event *event)
2103{ 2142{
2104 changeEventDisplay(event,KOGlobals::EVENTADDED); 2143 changeEventDisplay(event,KOGlobals::EVENTADDED);
2105} 2144}
2106 2145
2107void CalendarView::eventToBeDeleted(Event *) 2146void CalendarView::eventToBeDeleted(Event *)
2108{ 2147{
2109 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2148 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2110} 2149}
2111 2150
2112void CalendarView::eventDeleted() 2151void CalendarView::eventDeleted()
2113{ 2152{
2114 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2153 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2115} 2154}
2116void CalendarView::changeTodoDisplay(Todo *which, int action) 2155void CalendarView::changeTodoDisplay(Todo *which, int action)
2117{ 2156{
2118 changeIncidenceDisplay((Incidence *)which, action); 2157 changeIncidenceDisplay((Incidence *)which, action);
2119 mDateNavigator->updateView(); //LR 2158 mDateNavigator->updateView(); //LR
2120 //mDialogManager->updateSearchDialog(); 2159 //mDialogManager->updateSearchDialog();
2121 2160
2122 if (which) { 2161 if (which) {
2123 mViewManager->updateWNview(); 2162 mViewManager->updateWNview();
2124 //mTodoList->updateView(); 2163 //mTodoList->updateView();
2125 } 2164 }
2126 2165
2127} 2166}
2128 2167
2129void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2168void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2130{ 2169{
2131 updateUnmanagedViews(); 2170 updateUnmanagedViews();
2132 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2171 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2133 if ( action == KOGlobals::EVENTDELETED ) { //delete 2172 if ( action == KOGlobals::EVENTDELETED ) { //delete
2134 mCalendar->checkAlarmForIncidence( 0, true ); 2173 mCalendar->checkAlarmForIncidence( 0, true );
2135 if ( mEventViewerDialog ) 2174 if ( mEventViewerDialog )
2136 mEventViewerDialog->hide(); 2175 mEventViewerDialog->hide();
2137 } 2176 }
2138 else 2177 else
2139 mCalendar->checkAlarmForIncidence( which , false ); 2178 mCalendar->checkAlarmForIncidence( which , false );
2140} 2179}
2141 2180
2142// most of the changeEventDisplays() right now just call the view's 2181// most of the changeEventDisplays() right now just call the view's
2143// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2182// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2144void CalendarView::changeEventDisplay(Event *which, int action) 2183void CalendarView::changeEventDisplay(Event *which, int action)
2145{ 2184{
2146 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2185 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2147 changeIncidenceDisplay((Incidence *)which, action); 2186 changeIncidenceDisplay((Incidence *)which, action);
2148 mDateNavigator->updateView(); 2187 mDateNavigator->updateView();
2149 //mDialogManager->updateSearchDialog(); 2188 //mDialogManager->updateSearchDialog();
2150 2189
2151 if (which) { 2190 if (which) {
2152 // If there is an event view visible update the display 2191 // If there is an event view visible update the display
2153 mViewManager->currentView()->changeEventDisplay(which,action); 2192 mViewManager->currentView()->changeEventDisplay(which,action);
2154 // TODO: check, if update needed 2193 // TODO: check, if update needed
2155 // if (which->getTodoStatus()) { 2194 // if (which->getTodoStatus()) {
2156 mTodoList->updateView(); 2195 mTodoList->updateView();
2157 // } 2196 // }
2158 } else { 2197 } else {
2159 mViewManager->currentView()->updateView(); 2198 mViewManager->currentView()->updateView();
2160 } 2199 }
2161} 2200}
2162 2201
2163 2202
2164void CalendarView::updateTodoViews() 2203void CalendarView::updateTodoViews()
2165{ 2204{
2166 mTodoList->updateView(); 2205 mTodoList->updateView();
2167 mViewManager->currentView()->updateView(); 2206 mViewManager->currentView()->updateView();
2168 2207
2169} 2208}
2170 2209
2171 2210
2172void CalendarView::updateView(const QDate &start, const QDate &end) 2211void CalendarView::updateView(const QDate &start, const QDate &end)
2173{ 2212{
2174 mTodoList->updateView(); 2213 mTodoList->updateView();
2175 mViewManager->updateView(start, end); 2214 mViewManager->updateView(start, end);
2176 //mDateNavigator->updateView(); 2215 //mDateNavigator->updateView();
2177} 2216}
2178 2217
2179void CalendarView::updateView() 2218void CalendarView::updateView()
2180{ 2219{
2181 DateList tmpList = mNavigator->selectedDates(); 2220 DateList tmpList = mNavigator->selectedDates();
2182 2221
2183 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2222 if ( KOPrefs::instance()->mHideNonStartedTodos )
2184 mTodoList->updateView(); 2223 mTodoList->updateView();
2185 // We assume that the navigator only selects consecutive days. 2224 // We assume that the navigator only selects consecutive days.
2186 updateView( tmpList.first(), tmpList.last() ); 2225 updateView( tmpList.first(), tmpList.last() );
2187} 2226}
2188 2227
2189void CalendarView::updateUnmanagedViews() 2228void CalendarView::updateUnmanagedViews()
2190{ 2229{
2191 mDateNavigator->updateDayMatrix(); 2230 mDateNavigator->updateDayMatrix();
2192} 2231}
2193 2232
2194int CalendarView::msgItemDelete(const QString name) 2233int CalendarView::msgItemDelete(const QString name)
2195{ 2234{
2196 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2235 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2197 i18n("This item will be\npermanently deleted."), 2236 i18n("This item will be\npermanently deleted."),
2198 i18n("KO/Pi Confirmation"),i18n("Delete")); 2237 i18n("KO/Pi Confirmation"),i18n("Delete"));
2199} 2238}
2200 2239
2201 2240
2202void CalendarView::edit_cut() 2241void CalendarView::edit_cut()
2203{ 2242{
2204 Event *anEvent=0; 2243 Event *anEvent=0;
2205 2244
2206 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2245 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2207 2246
2208 if (mViewManager->currentView()->isEventView()) { 2247 if (mViewManager->currentView()->isEventView()) {
2209 if ( incidence && incidence->type() == "Event" ) { 2248 if ( incidence && incidence->type() == "Event" ) {
2210 anEvent = static_cast<Event *>(incidence); 2249 anEvent = static_cast<Event *>(incidence);
2211 } 2250 }
2212 } 2251 }
2213 2252
2214 if (!anEvent) { 2253 if (!anEvent) {
2215 KNotifyClient::beep(); 2254 KNotifyClient::beep();
2216 return; 2255 return;
2217 } 2256 }
2218 DndFactory factory( mCalendar ); 2257 DndFactory factory( mCalendar );
2219 factory.cutIncidence(anEvent); 2258 factory.cutIncidence(anEvent);
2220 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2259 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2221} 2260}
2222 2261
2223void CalendarView::edit_copy() 2262void CalendarView::edit_copy()
2224{ 2263{
2225 Event *anEvent=0; 2264 Event *anEvent=0;
2226 2265
2227 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2266 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2228 2267
2229 if (mViewManager->currentView()->isEventView()) { 2268 if (mViewManager->currentView()->isEventView()) {
2230 if ( incidence && incidence->type() == "Event" ) { 2269 if ( incidence && incidence->type() == "Event" ) {
2231 anEvent = static_cast<Event *>(incidence); 2270 anEvent = static_cast<Event *>(incidence);
2232 } 2271 }
2233 } 2272 }
2234 2273
2235 if (!anEvent) { 2274 if (!anEvent) {
2236 KNotifyClient::beep(); 2275 KNotifyClient::beep();
2237 return; 2276 return;
2238 } 2277 }
2239 DndFactory factory( mCalendar ); 2278 DndFactory factory( mCalendar );
2240 factory.copyIncidence(anEvent); 2279 factory.copyIncidence(anEvent);
2241} 2280}
2242 2281
2243void CalendarView::edit_paste() 2282void CalendarView::edit_paste()
2244{ 2283{
2245 QDate date = mNavigator->selectedDates().first(); 2284 QDate date = mNavigator->selectedDates().first();
2246 2285
2247 DndFactory factory( mCalendar ); 2286 DndFactory factory( mCalendar );
2248 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2287 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2249 2288
2250 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2289 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2251} 2290}
2252 2291
2253void CalendarView::edit_options() 2292void CalendarView::edit_options()
2254{ 2293{
2255 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2294 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2256 emit save(); 2295 emit save();
2257 emit saveStopTimer(); 2296 emit saveStopTimer();
2258 mDialogManager->showOptionsDialog(); 2297 mDialogManager->showOptionsDialog();
2259 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2298 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2260 emit saveStopTimer(); 2299 emit saveStopTimer();
2261 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2300 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2262 i18n("Timezone settings"),i18n("Reload"))) { 2301 i18n("Timezone settings"),i18n("Reload"))) {
2263 qDebug("KO: TZ reload cancelled "); 2302 qDebug("KO: TZ reload cancelled ");
2264 return; 2303 return;
2265 } 2304 }
2266 qDebug("KO: Timezone change "); 2305 qDebug("KO: Timezone change ");
2267 openCalendar( MainWindow::defaultFileName() ); 2306 openCalendar( MainWindow::defaultFileName() );
2268 setModified(true); 2307 setModified(true);
2269 } 2308 }
2270 else 2309 else
2271 qDebug("KO: No tz change "); 2310 qDebug("KO: No tz change ");
2272 2311
2273} 2312}
2274 2313
2275 2314
2276void CalendarView::slotSelectPickerDate( QDate d) 2315void CalendarView::slotSelectPickerDate( QDate d)
2277{ 2316{
2278 mDateFrame->hide(); 2317 mDateFrame->hide();
2279 if ( mDatePickerMode == 1 ) { 2318 if ( mDatePickerMode == 1 ) {
2280 mNavigator->slotDaySelect( d ); 2319 mNavigator->slotDaySelect( d );
2281 } else if ( mDatePickerMode == 2 ) { 2320 } else if ( mDatePickerMode == 2 ) {
2282 if ( mMoveIncidence->type() == "Todo" ) { 2321 if ( mMoveIncidence->type() == "Todo" ) {
2283 Todo * to = (Todo *) mMoveIncidence; 2322 Todo * to = (Todo *) mMoveIncidence;
2284 QTime tim; 2323 QTime tim;
2285 int len = 0; 2324 int len = 0;
2286 if ( to->hasStartDate() && to->hasDueDate() ) 2325 if ( to->hasStartDate() && to->hasDueDate() )
2287 len = to->dtStart().secsTo( to->dtDue()); 2326 len = to->dtStart().secsTo( to->dtDue());
2288 if ( to->hasDueDate() ) 2327 if ( to->hasDueDate() )
2289 tim = to->dtDue().time(); 2328 tim = to->dtDue().time();
2290 else { 2329 else {
2291 tim = QTime ( 0,0,0 ); 2330 tim = QTime ( 0,0,0 );
2292 to->setFloats( true ); 2331 to->setFloats( true );
2293 to->setHasDueDate( true ); 2332 to->setHasDueDate( true );
2294 } 2333 }
2295 QDateTime dt ( d,tim ); 2334 QDateTime dt ( d,tim );
2296 to->setDtDue( dt ); 2335 to->setDtDue( dt );
2297 2336
2298 if ( to->hasStartDate() ) { 2337 if ( to->hasStartDate() ) {
2299 if ( len>0 ) 2338 if ( len>0 )
2300 to->setDtStart(to->dtDue().addSecs( -len )); 2339 to->setDtStart(to->dtDue().addSecs( -len ));
2301 else 2340 else
2302 if (to->dtStart() > to->dtDue() ) 2341 if (to->dtStart() > to->dtDue() )
2303 to->setDtStart(to->dtDue().addDays( -3 )); 2342 to->setDtStart(to->dtDue().addDays( -3 ));
2304 } 2343 }
2305 2344
2306 todoChanged( to ); 2345 todoChanged( to );
2307 } else { 2346 } else {
2308 if ( mMoveIncidence->doesRecur() ) { 2347 if ( mMoveIncidence->doesRecur() ) {
2309#if 0 2348#if 0
2310 // PENDING implement this 2349 // PENDING implement this
2311 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2350 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2312 mCalendar()->addIncidence( newInc ); 2351 mCalendar()->addIncidence( newInc );
2313 if ( mMoveIncidence->type() == "Todo" ) 2352 if ( mMoveIncidence->type() == "Todo" )
2314 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2353 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2315 else 2354 else
2316 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2355 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2317 mMoveIncidence = newInc; 2356 mMoveIncidence = newInc;
2318 2357
2319#endif 2358#endif
2320 } 2359 }
2321 QTime tim = mMoveIncidence->dtStart().time(); 2360 QTime tim = mMoveIncidence->dtStart().time();
2322 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2361 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2323 QDateTime dt ( d,tim ); 2362 QDateTime dt ( d,tim );
2324 mMoveIncidence->setDtStart( dt ); 2363 mMoveIncidence->setDtStart( dt );
2325 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2364 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2326 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2365 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2327 } 2366 }
2328 2367
2329 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2368 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2330 } 2369 }
2331} 2370}
2332 2371
2333void CalendarView::removeCategories() 2372void CalendarView::removeCategories()
2334{ 2373{
2335 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2374 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2336 QStringList catList = KOPrefs::instance()->mCustomCategories; 2375 QStringList catList = KOPrefs::instance()->mCustomCategories;
2337 QStringList catIncList; 2376 QStringList catIncList;
2338 QStringList newCatList; 2377 QStringList newCatList;
2339 Incidence* inc = incList.first(); 2378 Incidence* inc = incList.first();
2340 int i; 2379 int i;
2341 int count = 0; 2380 int count = 0;
2342 while ( inc ) { 2381 while ( inc ) {
2343 newCatList.clear(); 2382 newCatList.clear();
2344 catIncList = inc->categories() ; 2383 catIncList = inc->categories() ;
2345 for( i = 0; i< catIncList.count(); ++i ) { 2384 for( i = 0; i< catIncList.count(); ++i ) {
2346 if ( catList.contains (catIncList[i])) 2385 if ( catList.contains (catIncList[i]))
2347 newCatList.append( catIncList[i] ); 2386 newCatList.append( catIncList[i] );
2348 } 2387 }
2349 newCatList.sort(); 2388 newCatList.sort();
2350 inc->setCategories( newCatList.join(",") ); 2389 inc->setCategories( newCatList.join(",") );
2351 inc = incList.next(); 2390 inc = incList.next();
2352 } 2391 }
2353} 2392}
2354 2393
2355int CalendarView::addCategories() 2394int CalendarView::addCategories()
2356{ 2395{
2357 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2396 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2358 QStringList catList = KOPrefs::instance()->mCustomCategories; 2397 QStringList catList = KOPrefs::instance()->mCustomCategories;
2359 QStringList catIncList; 2398 QStringList catIncList;
2360 Incidence* inc = incList.first(); 2399 Incidence* inc = incList.first();
2361 int i; 2400 int i;
2362 int count = 0; 2401 int count = 0;
2363 while ( inc ) { 2402 while ( inc ) {
2364 catIncList = inc->categories() ; 2403 catIncList = inc->categories() ;
2365 for( i = 0; i< catIncList.count(); ++i ) { 2404 for( i = 0; i< catIncList.count(); ++i ) {
2366 if ( !catList.contains (catIncList[i])) { 2405 if ( !catList.contains (catIncList[i])) {
2367 catList.append( catIncList[i] ); 2406 catList.append( catIncList[i] );
2368 //qDebug("add cat %s ", catIncList[i].latin1()); 2407 //qDebug("add cat %s ", catIncList[i].latin1());
2369 ++count; 2408 ++count;
2370 } 2409 }
2371 } 2410 }
2372 inc = incList.next(); 2411 inc = incList.next();
2373 } 2412 }
2374 catList.sort(); 2413 catList.sort();
2375 KOPrefs::instance()->mCustomCategories = catList; 2414 KOPrefs::instance()->mCustomCategories = catList;
2376 return count; 2415 return count;
2377} 2416}
2378 2417
2379void CalendarView::manageCategories() 2418void CalendarView::manageCategories()
2380{ 2419{
2381 KOCatPrefs* cp = new KOCatPrefs(); 2420 KOCatPrefs* cp = new KOCatPrefs();
2382 cp->show(); 2421 cp->show();
2383 int w =cp->sizeHint().width() ; 2422 int w =cp->sizeHint().width() ;
2384 int h = cp->sizeHint().height() ; 2423 int h = cp->sizeHint().height() ;
2385 int dw = QApplication::desktop()->width(); 2424 int dw = QApplication::desktop()->width();
2386 int dh = QApplication::desktop()->height(); 2425 int dh = QApplication::desktop()->height();
2387 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2426 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2388 if ( !cp->exec() ) { 2427 if ( !cp->exec() ) {
2389 delete cp; 2428 delete cp;
2390 return; 2429 return;
2391 } 2430 }
2392 int count = 0; 2431 int count = 0;
2393 if ( cp->addCat() ) { 2432 if ( cp->addCat() ) {
2394 count = addCategories(); 2433 count = addCategories();
2395 if ( count ) { 2434 if ( count ) {
2396 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2435 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2397 writeSettings(); 2436 writeSettings();
2398 } else 2437 } else
2399 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2438 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2400 } else { 2439 } else {
2401 removeCategories(); 2440 removeCategories();
2402 updateView(); 2441 updateView();
2403 } 2442 }
2404 delete cp; 2443 delete cp;
2405} 2444}
2406 2445
2407void CalendarView::beamIncidence(Incidence * Inc) 2446void CalendarView::beamIncidence(Incidence * Inc)
2408{ 2447{
2409 QPtrList<Incidence> delSel ; 2448 QPtrList<Incidence> delSel ;
2410 delSel.append(Inc); 2449 delSel.append(Inc);
2411 beamIncidenceList( delSel ); 2450 beamIncidenceList( delSel );
2412} 2451}
2413void CalendarView::beamCalendar() 2452void CalendarView::beamCalendar()
2414{ 2453{
2415 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2454 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2416 //qDebug("beamCalendar() "); 2455 //qDebug("beamCalendar() ");
2417 beamIncidenceList( delSel ); 2456 beamIncidenceList( delSel );
2418} 2457}
2419void CalendarView::beamFilteredCalendar() 2458void CalendarView::beamFilteredCalendar()
2420{ 2459{
2421 QPtrList<Incidence> delSel = mCalendar->incidences(); 2460 QPtrList<Incidence> delSel = mCalendar->incidences();
2422 //qDebug("beamFilteredCalendar() "); 2461 //qDebug("beamFilteredCalendar() ");
2423 beamIncidenceList( delSel ); 2462 beamIncidenceList( delSel );
2424} 2463}
2425void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2464void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2426{ 2465{
2427 if ( beamDialog->exec () == QDialog::Rejected ) 2466 if ( beamDialog->exec () == QDialog::Rejected )
2428 return; 2467 return;
2429#ifdef DESKTOP_VERSION 2468#ifdef DESKTOP_VERSION
2430 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2469 QString fn = locateLocal( "tmp", "kopibeamfile" );
2431#else 2470#else
2432 QString fn = "/tmp/kopibeamfile"; 2471 QString fn = "/tmp/kopibeamfile";
2433#endif 2472#endif
2434 QString mes; 2473 QString mes;
2435 bool createbup = true; 2474 bool createbup = true;
2436 if ( createbup ) { 2475 if ( createbup ) {
2437 QString description = "\n"; 2476 QString description = "\n";
2438 CalendarLocal* cal = new CalendarLocal(); 2477 CalendarLocal* cal = new CalendarLocal();
2439 if ( beamDialog->beamLocal() ) 2478 if ( beamDialog->beamLocal() )
2440 cal->setLocalTime(); 2479 cal->setLocalTime();
2441 else 2480 else
2442 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2481 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2443 Incidence *incidence = delSel.first(); 2482 Incidence *incidence = delSel.first();
2444 bool addText = false; 2483 bool addText = false;
2445 if ( delSel.count() < 10 ) 2484 if ( delSel.count() < 10 )
2446 addText = true; 2485 addText = true;
2447 else { 2486 else {
2448 description.sprintf(i18n(" %d items?"),delSel.count() ); 2487 description.sprintf(i18n(" %d items?"),delSel.count() );
2449 } 2488 }
2450 while ( incidence ) { 2489 while ( incidence ) {
2451 Incidence *in = incidence->clone(); 2490 Incidence *in = incidence->clone();
2452 if ( ! in->summary().isEmpty() ) { 2491 if ( ! in->summary().isEmpty() ) {
2453 in->setDescription(""); 2492 in->setDescription("");
2454 } else { 2493 } else {
2455 in->setSummary( in->description().left(20)); 2494 in->setSummary( in->description().left(20));
2456 in->setDescription(""); 2495 in->setDescription("");
2457 } 2496 }
2458 if ( addText ) 2497 if ( addText )
2459 description += in->summary() + "\n"; 2498 description += in->summary() + "\n";
2460 cal->addIncidence( in ); 2499 cal->addIncidence( in );
2461 incidence = delSel.next(); 2500 incidence = delSel.next();
2462 } 2501 }
2463 if ( beamDialog->beamVcal() ) { 2502 if ( beamDialog->beamVcal() ) {
2464 fn += ".vcs"; 2503 fn += ".vcs";
2465 FileStorage storage( cal, fn, new VCalFormat ); 2504 FileStorage storage( cal, fn, new VCalFormat );
2466 storage.save(); 2505 storage.save();
2467 } else { 2506 } else {
2468 fn += ".ics"; 2507 fn += ".ics";
2469 FileStorage storage( cal, fn, new ICalFormat( ) ); 2508 FileStorage storage( cal, fn, new ICalFormat( ) );
2470 storage.save(); 2509 storage.save();
2471 } 2510 }
2472 delete cal; 2511 delete cal;
2473 mes = i18n("KO/Pi: Ready for beaming"); 2512 mes = i18n("KO/Pi: Ready for beaming");
2474 topLevelWidget()->setCaption(mes); 2513 topLevelWidget()->setCaption(mes);
2475 KApplication::convert2latin1( fn ); 2514 KApplication::convert2latin1( fn );
2476#ifndef DESKTOP_VERSION 2515#ifndef DESKTOP_VERSION
2477 Ir *ir = new Ir( this ); 2516 Ir *ir = new Ir( this );
2478 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2517 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2479 ir->send( fn, description, "text/x-vCalendar" ); 2518 ir->send( fn, description, "text/x-vCalendar" );
2480#endif 2519#endif
2481 } 2520 }
2482} 2521}
2483void CalendarView::beamDone( Ir *ir ) 2522void CalendarView::beamDone( Ir *ir )
2484{ 2523{
2485#ifndef DESKTOP_VERSION 2524#ifndef DESKTOP_VERSION
2486 delete ir; 2525 delete ir;
2487#endif 2526#endif
2488 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2527 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2489 topLevelWidget()->raise(); 2528 topLevelWidget()->raise();
2490} 2529}
2491 2530
2492void CalendarView::moveIncidence(Incidence * inc ) 2531void CalendarView::moveIncidence(Incidence * inc )
2493{ 2532{
2494 if ( !inc ) return; 2533 if ( !inc ) return;
2495 showDatePickerPopup(); 2534 showDatePickerPopup();
2496 mDatePickerMode = 2; 2535 mDatePickerMode = 2;
2497 mMoveIncidence = inc ; 2536 mMoveIncidence = inc ;
2498 QDate da; 2537 QDate da;
2499 if ( mMoveIncidence->type() == "Todo" ) { 2538 if ( mMoveIncidence->type() == "Todo" ) {
2500 Todo * to = (Todo *) mMoveIncidence; 2539 Todo * to = (Todo *) mMoveIncidence;
2501 if ( to->hasDueDate() ) 2540 if ( to->hasDueDate() )
2502 da = to->dtDue().date(); 2541 da = to->dtDue().date();
2503 else 2542 else
2504 da = QDate::currentDate(); 2543 da = QDate::currentDate();
2505 } else { 2544 } else {
2506 da = mMoveIncidence->dtStart().date(); 2545 da = mMoveIncidence->dtStart().date();
2507 } 2546 }
2508 //PENDING set date for recurring incidence to date of recurrence 2547 //PENDING set date for recurring incidence to date of recurrence
2509 //mMoveIncidenceOldDate; 2548 //mMoveIncidenceOldDate;
2510 mDatePicker->setDate( da ); 2549 mDatePicker->setDate( da );
2511} 2550}
2512void CalendarView::showDatePickerPopup() 2551void CalendarView::showDatePickerPopup()
2513{ 2552{
2514 if ( mDateFrame->isVisible() ) 2553 if ( mDateFrame->isVisible() )
2515 mDateFrame->hide(); 2554 mDateFrame->hide();
2516 else { 2555 else {
2517 int offX = 0, offY = 0; 2556 int offX = 0, offY = 0;
2518#ifdef DESKTOP_VERSION 2557#ifdef DESKTOP_VERSION
2519 int w =mDatePicker->sizeHint().width() ; 2558 int w =mDatePicker->sizeHint().width() ;
2520 int h = mDatePicker->sizeHint().height() ; 2559 int h = mDatePicker->sizeHint().height() ;
2521 int dw = topLevelWidget()->width(); 2560 int dw = topLevelWidget()->width();
2522 int dh = topLevelWidget()->height(); 2561 int dh = topLevelWidget()->height();
2523 offX = topLevelWidget()->x(); 2562 offX = topLevelWidget()->x();
2524 offY = topLevelWidget()->y(); 2563 offY = topLevelWidget()->y();
2525#else 2564#else
2526 int w =mDatePicker->sizeHint().width() ; 2565 int w =mDatePicker->sizeHint().width() ;
2527 int h = mDatePicker->sizeHint().height() ; 2566 int h = mDatePicker->sizeHint().height() ;
2528 int dw = QApplication::desktop()->width(); 2567 int dw = QApplication::desktop()->width();
2529 int dh = QApplication::desktop()->height(); 2568 int dh = QApplication::desktop()->height();
2530#endif 2569#endif
2531 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2570 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2532 mDateFrame->show(); 2571 mDateFrame->show();
2533 } 2572 }
2534} 2573}
2535void CalendarView::showDatePicker( ) 2574void CalendarView::showDatePicker( )
2536{ 2575{
2537 showDatePickerPopup(); 2576 showDatePickerPopup();
2538 mDatePickerMode = 1; 2577 mDatePickerMode = 1;
2539 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2578 mDatePicker->setDate( mNavigator->selectedDates().first() );
2540} 2579}
2541 2580
2542void CalendarView::showEventEditor() 2581void CalendarView::showEventEditor()
2543{ 2582{
2544#ifdef DESKTOP_VERSION 2583#ifdef DESKTOP_VERSION
2545 int x,y,w,h; 2584 int x,y,w,h;
2546 x = mEventEditor->geometry().x(); 2585 x = mEventEditor->geometry().x();
2547 y = mEventEditor->geometry().y(); 2586 y = mEventEditor->geometry().y();
2548 w = mEventEditor->width(); 2587 w = mEventEditor->width();
2549 h = mEventEditor->height(); 2588 h = mEventEditor->height();
2550 mEventEditor->show(); 2589 mEventEditor->show();
2551 mEventEditor->setGeometry(x,y,w,h); 2590 mEventEditor->setGeometry(x,y,w,h);
2552#else 2591#else
2553 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2592 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2554 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2593 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2555 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2594 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2556 qApp->processEvents(); 2595 qApp->processEvents();
2557 delete mEventEditor; 2596 delete mEventEditor;
2558 mEventEditor = mDialogManager->getEventEditor(); 2597 mEventEditor = mDialogManager->getEventEditor();
2559 topLevelWidget()->setCaption( i18n("") ); 2598 topLevelWidget()->setCaption( i18n("") );
2560 } 2599 }
2561 mEventEditor->showMaximized(); 2600 mEventEditor->showMaximized();
2562#endif 2601#endif
2563} 2602}
2564void CalendarView::showTodoEditor() 2603void CalendarView::showTodoEditor()
2565{ 2604{
2566#ifdef DESKTOP_VERSION 2605#ifdef DESKTOP_VERSION
2567 int x,y,w,h; 2606 int x,y,w,h;
2568 x = mTodoEditor->geometry().x(); 2607 x = mTodoEditor->geometry().x();
2569 y = mTodoEditor->geometry().y(); 2608 y = mTodoEditor->geometry().y();
2570 w = mTodoEditor->width(); 2609 w = mTodoEditor->width();
2571 h = mTodoEditor->height(); 2610 h = mTodoEditor->height();
2572 mTodoEditor->show(); 2611 mTodoEditor->show();
2573 mTodoEditor->setGeometry(x,y,w,h); 2612 mTodoEditor->setGeometry(x,y,w,h);
2574#else 2613#else
2575 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2614 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2576 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2615 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2577 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2616 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2578 qApp->processEvents(); 2617 qApp->processEvents();
2579 delete mTodoEditor; 2618 delete mTodoEditor;
2580 mTodoEditor = mDialogManager->getTodoEditor(); 2619 mTodoEditor = mDialogManager->getTodoEditor();
2581 topLevelWidget()->setCaption( i18n("") ); 2620 topLevelWidget()->setCaption( i18n("") );
2582 } 2621 }
2583 mTodoEditor->showMaximized(); 2622 mTodoEditor->showMaximized();
2584#endif 2623#endif
2585} 2624}
2586 2625
2587void CalendarView::cloneIncidence() 2626void CalendarView::cloneIncidence()
2588{ 2627{
2589 Incidence *incidence = currentSelection(); 2628 Incidence *incidence = currentSelection();
2590 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2629 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2591 if ( incidence ) { 2630 if ( incidence ) {
2592 cloneIncidence(incidence); 2631 cloneIncidence(incidence);
2593 } 2632 }
2594} 2633}
2595void CalendarView::moveIncidence() 2634void CalendarView::moveIncidence()
2596{ 2635{
2597 Incidence *incidence = currentSelection(); 2636 Incidence *incidence = currentSelection();
2598 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2637 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2599 if ( incidence ) { 2638 if ( incidence ) {
2600 moveIncidence(incidence); 2639 moveIncidence(incidence);
2601 } 2640 }
2602} 2641}
2603void CalendarView::beamIncidence() 2642void CalendarView::beamIncidence()
2604{ 2643{
2605 Incidence *incidence = currentSelection(); 2644 Incidence *incidence = currentSelection();
2606 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2645 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2607 if ( incidence ) { 2646 if ( incidence ) {
2608 beamIncidence(incidence); 2647 beamIncidence(incidence);
2609 } 2648 }
2610} 2649}
2611void CalendarView::toggleCancelIncidence() 2650void CalendarView::toggleCancelIncidence()
2612{ 2651{
2613 Incidence *incidence = currentSelection(); 2652 Incidence *incidence = currentSelection();
2614 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2653 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2615 if ( incidence ) { 2654 if ( incidence ) {
2616 cancelIncidence(incidence); 2655 cancelIncidence(incidence);
2617 } 2656 }
2618} 2657}
2619 2658
2620 2659
2621void CalendarView::cancelIncidence(Incidence * inc ) 2660void CalendarView::cancelIncidence(Incidence * inc )
2622{ 2661{
2623 inc->setCancelled( ! inc->cancelled() ); 2662 inc->setCancelled( ! inc->cancelled() );
2624 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2663 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2625 updateView(); 2664 updateView();
2626} 2665}
2627void CalendarView::cloneIncidence(Incidence * orgInc ) 2666void CalendarView::cloneIncidence(Incidence * orgInc )
2628{ 2667{
2629 Incidence * newInc = orgInc->clone(); 2668 Incidence * newInc = orgInc->clone();
2630 newInc->recreate(); 2669 newInc->recreate();
2631 2670
2632 if ( newInc->type() == "Todo" ) { 2671 if ( newInc->type() == "Todo" ) {
2633 Todo* t = (Todo*) newInc; 2672 Todo* t = (Todo*) newInc;
2634 showTodoEditor(); 2673 showTodoEditor();
2635 mTodoEditor->editTodo( t ); 2674 mTodoEditor->editTodo( t );
2636 if ( mTodoEditor->exec() ) { 2675 if ( mTodoEditor->exec() ) {
2637 mCalendar->addTodo( t ); 2676 mCalendar->addTodo( t );
2638 updateView(); 2677 updateView();
2639 } else { 2678 } else {
2640 delete t; 2679 delete t;
2641 } 2680 }
2642 } 2681 }
2643 else { 2682 else {
2644 Event* e = (Event*) newInc; 2683 Event* e = (Event*) newInc;
2645 showEventEditor(); 2684 showEventEditor();
2646 mEventEditor->editEvent( e ); 2685 mEventEditor->editEvent( e );
2647 if ( mEventEditor->exec() ) { 2686 if ( mEventEditor->exec() ) {
2648 mCalendar->addEvent( e ); 2687 mCalendar->addEvent( e );
2649 updateView(); 2688 updateView();
2650 } else { 2689 } else {
2651 delete e; 2690 delete e;
2652 } 2691 }
2653 } 2692 }
2654 setActiveWindow(); 2693 setActiveWindow();
2655} 2694}
2656 2695
2657void CalendarView::newEvent() 2696void CalendarView::newEvent()
2658{ 2697{
2659 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2698 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2660 KOAgendaView *aView = mViewManager->agendaView(); 2699 KOAgendaView *aView = mViewManager->agendaView();
2661 if (aView) { 2700 if (aView) {
2662 if (aView->selectionStart().isValid()) { 2701 if (aView->selectionStart().isValid()) {
2663 if (aView->selectedIsAllDay()) { 2702 if (aView->selectedIsAllDay()) {
2664 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2703 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2665 } else { 2704 } else {
2666 newEvent(aView->selectionStart(),aView->selectionEnd()); 2705 newEvent(aView->selectionStart(),aView->selectionEnd());
2667 } 2706 }
2668 return; 2707 return;
2669 } 2708 }
2670 } 2709 }
2671 2710
2672 QDate date = mNavigator->selectedDates().first(); 2711 QDate date = mNavigator->selectedDates().first();
2673 QDateTime current = QDateTime::currentDateTime(); 2712 QDateTime current = QDateTime::currentDateTime();
2674 if ( date <= current.date() ) { 2713 if ( date <= current.date() ) {
2675 int hour = current.time().hour() +1; 2714 int hour = current.time().hour() +1;
2676 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2715 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2677 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2716 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2678 } else 2717 } else
2679 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2718 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2680 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2719 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2681 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2720 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2682} 2721}
2683 2722
2684void CalendarView::newEvent(QDateTime fh) 2723void CalendarView::newEvent(QDateTime fh)
2685{ 2724{
2686 newEvent(fh, 2725 newEvent(fh,
2687 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2726 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2688} 2727}
2689 2728
2690void CalendarView::newEvent(QDate dt) 2729void CalendarView::newEvent(QDate dt)
2691{ 2730{
2692 newEvent(QDateTime(dt, QTime(0,0,0)), 2731 newEvent(QDateTime(dt, QTime(0,0,0)),
2693 QDateTime(dt, QTime(0,0,0)), true); 2732 QDateTime(dt, QTime(0,0,0)), true);
2694} 2733}
2695void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 2734void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2696{ 2735{
2697 newEvent(fromHint, toHint, false); 2736 newEvent(fromHint, toHint, false);
2698} 2737}
2699void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2738void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2700{ 2739{
2701 2740
2702 showEventEditor(); 2741 showEventEditor();
2703 mEventEditor->newEvent(fromHint,toHint,allDay); 2742 mEventEditor->newEvent(fromHint,toHint,allDay);
2704 if ( mFilterView->filtersEnabled() ) { 2743 if ( mFilterView->filtersEnabled() ) {
2705 CalFilter *filter = mFilterView->selectedFilter(); 2744 CalFilter *filter = mFilterView->selectedFilter();
2706 if (filter && filter->showCategories()) { 2745 if (filter && filter->showCategories()) {
2707 mEventEditor->setCategories(filter->categoryList().join(",") ); 2746 mEventEditor->setCategories(filter->categoryList().join(",") );
2708 } 2747 }
2709 if ( filter ) 2748 if ( filter )
2710 mEventEditor->setSecrecy( filter->getSecrecy() ); 2749 mEventEditor->setSecrecy( filter->getSecrecy() );
2711 } 2750 }
2712 mEventEditor->exec(); 2751 mEventEditor->exec();
2713 setActiveWindow(); 2752 setActiveWindow();
2714} 2753}
2715void CalendarView::todoAdded(Todo * t) 2754void CalendarView::todoAdded(Todo * t)
2716{ 2755{
2717 2756
2718 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2757 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2719 updateTodoViews(); 2758 updateTodoViews();
2720} 2759}
2721void CalendarView::todoChanged(Todo * t) 2760void CalendarView::todoChanged(Todo * t)
2722{ 2761{
2723 emit todoModified( t, 4 ); 2762 emit todoModified( t, 4 );
2724 // updateTodoViews(); 2763 // updateTodoViews();
2725} 2764}
2726void CalendarView::todoToBeDeleted(Todo *) 2765void CalendarView::todoToBeDeleted(Todo *)
2727{ 2766{
2728 //qDebug("todoToBeDeleted(Todo *) "); 2767 //qDebug("todoToBeDeleted(Todo *) ");
2729 updateTodoViews(); 2768 updateTodoViews();
2730} 2769}
2731void CalendarView::todoDeleted() 2770void CalendarView::todoDeleted()
2732{ 2771{
2733 //qDebug(" todoDeleted()"); 2772 //qDebug(" todoDeleted()");
2734 updateTodoViews(); 2773 updateTodoViews();
2735} 2774}
2736 2775
2737 2776
2738void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 2777void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
2739{ 2778{
2740 showTodoEditor(); 2779 showTodoEditor();
2741 mTodoEditor->newTodo(dt,0,allday); 2780 mTodoEditor->newTodo(dt,0,allday);
2742 if ( mFilterView->filtersEnabled() ) { 2781 if ( mFilterView->filtersEnabled() ) {
2743 CalFilter *filter = mFilterView->selectedFilter(); 2782 CalFilter *filter = mFilterView->selectedFilter();
2744 if (filter && filter->showCategories()) { 2783 if (filter && filter->showCategories()) {
2745 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2784 mTodoEditor->setCategories(filter->categoryList().join(",") );
2746 } 2785 }
2747 if ( filter ) 2786 if ( filter )
2748 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2787 mTodoEditor->setSecrecy( filter->getSecrecy() );
2749 } 2788 }
2750 mTodoEditor->exec(); 2789 mTodoEditor->exec();
2751 setActiveWindow(); 2790 setActiveWindow();
2752} 2791}
2753 2792
2754void CalendarView::newTodo() 2793void CalendarView::newTodo()
2755{ 2794{
2756 newTodoDateTime( QDateTime(),true ); 2795 newTodoDateTime( QDateTime(),true );
2757} 2796}
2758 2797
2759void CalendarView::newSubTodo() 2798void CalendarView::newSubTodo()
2760{ 2799{
2761 Todo *todo = selectedTodo(); 2800 Todo *todo = selectedTodo();
2762 if ( todo ) newSubTodo( todo ); 2801 if ( todo ) newSubTodo( todo );
2763} 2802}
2764 2803
2765void CalendarView::newSubTodo(Todo *parentEvent) 2804void CalendarView::newSubTodo(Todo *parentEvent)
2766{ 2805{
2767 2806
2768 showTodoEditor(); 2807 showTodoEditor();
2769 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 2808 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
2770 mTodoEditor->exec(); 2809 mTodoEditor->exec();
2771 setActiveWindow(); 2810 setActiveWindow();
2772} 2811}
2773 2812
2774void CalendarView::newFloatingEvent() 2813void CalendarView::newFloatingEvent()
2775{ 2814{
2776 DateList tmpList = mNavigator->selectedDates(); 2815 DateList tmpList = mNavigator->selectedDates();
2777 QDate date = tmpList.first(); 2816 QDate date = tmpList.first();
2778 2817
2779 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2818 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2780 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2819 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2781} 2820}
2782 2821
2783 2822
2784void CalendarView::editEvent( Event *event ) 2823void CalendarView::editEvent( Event *event )
2785{ 2824{
2786 2825
2787 if ( !event ) return; 2826 if ( !event ) return;
2788 if ( event->isReadOnly() ) { 2827 if ( event->isReadOnly() ) {
2789 showEvent( event ); 2828 showEvent( event );
2790 return; 2829 return;
2791 } 2830 }
2792 showEventEditor(); 2831 showEventEditor();
2793 mEventEditor->editEvent( event , mFlagEditDescription); 2832 mEventEditor->editEvent( event , mFlagEditDescription);
2794 mEventEditor->exec(); 2833 mEventEditor->exec();
2795 setActiveWindow(); 2834 setActiveWindow();
2796 2835
2797} 2836}
2798void CalendarView::editJournal( Journal *jour ) 2837void CalendarView::editJournal( Journal *jour )
2799{ 2838{
2800 if ( !jour ) return; 2839 if ( !jour ) return;
2801 mDialogManager->hideSearchDialog(); 2840 mDialogManager->hideSearchDialog();
2802 mViewManager->showJournalView(); 2841 mViewManager->showJournalView();
2803 mNavigator->slotDaySelect( jour->dtStart().date() ); 2842 mNavigator->slotDaySelect( jour->dtStart().date() );
2804} 2843}
2805void CalendarView::editTodo( Todo *todo ) 2844void CalendarView::editTodo( Todo *todo )
2806{ 2845{
2807 if ( !todo ) return; 2846 if ( !todo ) return;
2808 2847
2809 if ( todo->isReadOnly() ) { 2848 if ( todo->isReadOnly() ) {
2810 showTodo( todo ); 2849 showTodo( todo );
2811 return; 2850 return;
2812 } 2851 }
2813 showTodoEditor(); 2852 showTodoEditor();
2814 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2853 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2815 mTodoEditor->exec(); 2854 mTodoEditor->exec();
2816 setActiveWindow(); 2855 setActiveWindow();
2817 2856
2818} 2857}
2819 2858
2820KOEventViewerDialog* CalendarView::getEventViewerDialog() 2859KOEventViewerDialog* CalendarView::getEventViewerDialog()
2821{ 2860{
2822 if ( !mEventViewerDialog ) { 2861 if ( !mEventViewerDialog ) {
2823 mEventViewerDialog = new KOEventViewerDialog(0); 2862 mEventViewerDialog = new KOEventViewerDialog(0);
2824 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2863 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2825 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2864 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2826 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2865 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2827 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2866 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2828 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2867 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2829 viewManager(), SLOT( showAgendaView( bool ) ) ); 2868 viewManager(), SLOT( showAgendaView( bool ) ) );
2830 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 2869 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
2831 this, SLOT( slotViewerClosed() ) ); 2870 this, SLOT( slotViewerClosed() ) );
2832 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 2871 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
2833 this, SLOT( todoChanged(Todo *) ) ); 2872 this, SLOT( todoChanged(Todo *) ) );
2834 mEventViewerDialog->resize( 640, 480 ); 2873 mEventViewerDialog->resize( 640, 480 );
2835 2874
2836 } 2875 }
2837 return mEventViewerDialog; 2876 return mEventViewerDialog;
2838} 2877}
2839void CalendarView::showEvent(Event *event) 2878void CalendarView::showEvent(Event *event)
2840{ 2879{
2841 getEventViewerDialog()->setEvent(event); 2880 getEventViewerDialog()->setEvent(event);
2842 getEventViewerDialog()->showMe(); 2881 getEventViewerDialog()->showMe();
2843} 2882}
2844 2883
2845void CalendarView::showTodo(Todo *event) 2884void CalendarView::showTodo(Todo *event)
2846{ 2885{
2847 getEventViewerDialog()->setTodo(event); 2886 getEventViewerDialog()->setTodo(event);
2848 getEventViewerDialog()->showMe(); 2887 getEventViewerDialog()->showMe();
2849} 2888}
2850void CalendarView::showJournal( Journal *jour ) 2889void CalendarView::showJournal( Journal *jour )
2851{ 2890{
2852 getEventViewerDialog()->setJournal(jour); 2891 getEventViewerDialog()->setJournal(jour);
2853 getEventViewerDialog()->showMe(); 2892 getEventViewerDialog()->showMe();
2854 2893
2855} 2894}
2856// void CalendarView::todoModified (Todo *event, int changed) 2895// void CalendarView::todoModified (Todo *event, int changed)
2857// { 2896// {
2858// // if (mDialogList.find (event) != mDialogList.end ()) { 2897// // if (mDialogList.find (event) != mDialogList.end ()) {
2859// // kdDebug() << "Todo modified and open" << endl; 2898// // kdDebug() << "Todo modified and open" << endl;
2860// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2899// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2861// // temp->modified (changed); 2900// // temp->modified (changed);
2862 2901
2863// // } 2902// // }
2864 2903
2865// mViewManager->updateView(); 2904// mViewManager->updateView();
2866// } 2905// }
2867 2906
2868void CalendarView::appointment_show() 2907void CalendarView::appointment_show()
2869{ 2908{
2870 Event *anEvent = 0; 2909 Event *anEvent = 0;
2871 2910
2872 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2911 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2873 2912
2874 if (mViewManager->currentView()->isEventView()) { 2913 if (mViewManager->currentView()->isEventView()) {
2875 if ( incidence && incidence->type() == "Event" ) { 2914 if ( incidence && incidence->type() == "Event" ) {
2876 anEvent = static_cast<Event *>(incidence); 2915 anEvent = static_cast<Event *>(incidence);
2877 } 2916 }
2878 } 2917 }
2879 2918
2880 if (!anEvent) { 2919 if (!anEvent) {
2881 KNotifyClient::beep(); 2920 KNotifyClient::beep();
2882 return; 2921 return;
2883 } 2922 }
2884 2923
2885 showEvent(anEvent); 2924 showEvent(anEvent);
2886} 2925}
2887 2926
2888void CalendarView::appointment_edit() 2927void CalendarView::appointment_edit()
2889{ 2928{
2890 Event *anEvent = 0; 2929 Event *anEvent = 0;
2891 2930
2892 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2931 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2893 2932
2894 if (mViewManager->currentView()->isEventView()) { 2933 if (mViewManager->currentView()->isEventView()) {
2895 if ( incidence && incidence->type() == "Event" ) { 2934 if ( incidence && incidence->type() == "Event" ) {
2896 anEvent = static_cast<Event *>(incidence); 2935 anEvent = static_cast<Event *>(incidence);
2897 } 2936 }
2898 } 2937 }
2899 2938
2900 if (!anEvent) { 2939 if (!anEvent) {
2901 KNotifyClient::beep(); 2940 KNotifyClient::beep();
2902 return; 2941 return;
2903 } 2942 }
2904 2943
2905 editEvent(anEvent); 2944 editEvent(anEvent);
2906} 2945}
2907 2946
2908void CalendarView::appointment_delete() 2947void CalendarView::appointment_delete()
2909{ 2948{
2910 Event *anEvent = 0; 2949 Event *anEvent = 0;
2911 2950
2912 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2951 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2913 2952
2914 if (mViewManager->currentView()->isEventView()) { 2953 if (mViewManager->currentView()->isEventView()) {
2915 if ( incidence && incidence->type() == "Event" ) { 2954 if ( incidence && incidence->type() == "Event" ) {
2916 anEvent = static_cast<Event *>(incidence); 2955 anEvent = static_cast<Event *>(incidence);
2917 } 2956 }
2918 } 2957 }
2919 2958
2920 if (!anEvent) { 2959 if (!anEvent) {
2921 KNotifyClient::beep(); 2960 KNotifyClient::beep();
2922 return; 2961 return;
2923 } 2962 }
2924 2963
2925 deleteEvent(anEvent); 2964 deleteEvent(anEvent);
2926} 2965}
2927 2966
2928void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2967void CalendarView::todo_resub( Todo * parent, Todo * sub )
2929{ 2968{
2930 if (!sub) return; 2969 if (!sub) return;
2931 if (!parent) return; 2970 if (!parent) return;
2932 if ( sub->relatedTo() ) 2971 if ( sub->relatedTo() )
2933 sub->relatedTo()->removeRelation(sub); 2972 sub->relatedTo()->removeRelation(sub);
2934 sub->setRelatedTo(parent); 2973 sub->setRelatedTo(parent);
2935 sub->setRelatedToUid(parent->uid()); 2974 sub->setRelatedToUid(parent->uid());
2936 parent->addRelation(sub); 2975 parent->addRelation(sub);
2937 sub->updated(); 2976 sub->updated();
2938 parent->updated(); 2977 parent->updated();
2939 setModified(true); 2978 setModified(true);
2940 updateView(); 2979 updateView();
2941} 2980}
2942void CalendarView::todo_unsub(Todo *anTodo ) 2981void CalendarView::todo_unsub(Todo *anTodo )
2943{ 2982{
2944 // Todo *anTodo = selectedTodo(); 2983 // Todo *anTodo = selectedTodo();
2945 if (!anTodo) return; 2984 if (!anTodo) return;
2946 if (!anTodo->relatedTo()) return; 2985 if (!anTodo->relatedTo()) return;
2947 anTodo->relatedTo()->removeRelation(anTodo); 2986 anTodo->relatedTo()->removeRelation(anTodo);
2948 anTodo->setRelatedTo(0); 2987 anTodo->setRelatedTo(0);
2949 anTodo->updated(); 2988 anTodo->updated();
2950 anTodo->setRelatedToUid(""); 2989 anTodo->setRelatedToUid("");
2951 setModified(true); 2990 setModified(true);
2952 updateView(); 2991 updateView();
2953} 2992}
2954 2993
2955void CalendarView::deleteTodo(Todo *todo) 2994void CalendarView::deleteTodo(Todo *todo)
2956{ 2995{
2957 if (!todo) { 2996 if (!todo) {
2958 KNotifyClient::beep(); 2997 KNotifyClient::beep();
2959 return; 2998 return;
2960 } 2999 }
2961 if (KOPrefs::instance()->mConfirm) { 3000 if (KOPrefs::instance()->mConfirm) {
2962 QString text = todo->summary().left(20); 3001 QString text = todo->summary().left(20);
2963 if (!todo->relations().isEmpty()) { 3002 if (!todo->relations().isEmpty()) {
2964 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3003 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
2965 3004
2966 } 3005 }
2967 switch (msgItemDelete(text)) { 3006 switch (msgItemDelete(text)) {
2968 case KMessageBox::Continue: // OK 3007 case KMessageBox::Continue: // OK
2969 bool deleteT = false; 3008 bool deleteT = false;
2970 if (!todo->relations().isEmpty()) { 3009 if (!todo->relations().isEmpty()) {
2971 deleteT = removeCompletedSubTodos( todo ); 3010 deleteT = removeCompletedSubTodos( todo );
2972 } 3011 }
2973 // deleteT == true: todo already deleted in removeCompletedSubTodos 3012 // deleteT == true: todo already deleted in removeCompletedSubTodos
2974 if ( !deleteT ) { 3013 if ( !deleteT ) {
2975 checkExternalId( todo ); 3014 checkExternalId( todo );
2976 calendar()->deleteTodo(todo); 3015 calendar()->deleteTodo(todo);
2977 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3016 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2978 updateView(); 3017 updateView();
2979 } 3018 }
2980 break; 3019 break;
2981 } // switch 3020 } // switch
2982 } else { 3021 } else {
2983 checkExternalId( todo ); 3022 checkExternalId( todo );
2984 mCalendar->deleteTodo(todo); 3023 mCalendar->deleteTodo(todo);
2985 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3024 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2986 updateView(); 3025 updateView();
2987 } 3026 }
2988 3027
2989 emit updateSearchDialog(); 3028 emit updateSearchDialog();
2990} 3029}
2991void CalendarView::deleteJournal(Journal *jour) 3030void CalendarView::deleteJournal(Journal *jour)
2992{ 3031{
2993 if (!jour) { 3032 if (!jour) {
2994 KNotifyClient::beep(); 3033 KNotifyClient::beep();
2995 return; 3034 return;
2996 } 3035 }
2997 if (KOPrefs::instance()->mConfirm) { 3036 if (KOPrefs::instance()->mConfirm) {
2998 switch (msgItemDelete( jour->description().left(20))) { 3037 switch (msgItemDelete( jour->description().left(20))) {
2999 case KMessageBox::Continue: // OK 3038 case KMessageBox::Continue: // OK
3000 calendar()->deleteJournal(jour); 3039 calendar()->deleteJournal(jour);
3001 updateView(); 3040 updateView();
3002 break; 3041 break;
3003 } // switch 3042 } // switch
3004 } else { 3043 } else {
3005 calendar()->deleteJournal(jour);; 3044 calendar()->deleteJournal(jour);;
3006 updateView(); 3045 updateView();
3007 } 3046 }
3008 emit updateSearchDialog(); 3047 emit updateSearchDialog();
3009} 3048}
3010 3049
3011void CalendarView::deleteEvent(Event *anEvent) 3050void CalendarView::deleteEvent(Event *anEvent)
3012{ 3051{
3013 if (!anEvent) { 3052 if (!anEvent) {
3014 KNotifyClient::beep(); 3053 KNotifyClient::beep();
3015 return; 3054 return;
3016 } 3055 }
3017 3056
3018 if (anEvent->recurrence()->doesRecur()) { 3057 if (anEvent->recurrence()->doesRecur()) {
3019 QDate itemDate = mViewManager->currentSelectionDate(); 3058 QDate itemDate = mViewManager->currentSelectionDate();
3020 int km; 3059 int km;
3021 if (!itemDate.isValid()) { 3060 if (!itemDate.isValid()) {
3022 //kdDebug() << "Date Not Valid" << endl; 3061 //kdDebug() << "Date Not Valid" << endl;
3023 if (KOPrefs::instance()->mConfirm) { 3062 if (KOPrefs::instance()->mConfirm) {
3024 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3063 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3025 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3064 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3026 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3065 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3027 if ( km == KMessageBox::Continue ) 3066 if ( km == KMessageBox::Continue )
3028 km = KMessageBox::No; // No = all below 3067 km = KMessageBox::No; // No = all below
3029 } else 3068 } else
3030 km = KMessageBox::No; 3069 km = KMessageBox::No;
3031 } else { 3070 } else {
3032 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3071 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3033 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3072 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3034 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3073 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3035 i18n("KO/Pi Confirmation"),i18n("Current"), 3074 i18n("KO/Pi Confirmation"),i18n("Current"),
3036 i18n("All")); 3075 i18n("All"));
3037 } 3076 }
3038 switch(km) { 3077 switch(km) {
3039 3078
3040 case KMessageBox::No: // Continue // all 3079 case KMessageBox::No: // Continue // all
3041 //qDebug("KMessageBox::No "); 3080 //qDebug("KMessageBox::No ");
3042 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3081 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3043 schedule(Scheduler::Cancel,anEvent); 3082 schedule(Scheduler::Cancel,anEvent);
3044 3083
3045 checkExternalId( anEvent); 3084 checkExternalId( anEvent);
3046 mCalendar->deleteEvent(anEvent); 3085 mCalendar->deleteEvent(anEvent);
3047 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3086 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3048 break; 3087 break;
3049 3088
3050 // Disabled because it does not work 3089 // Disabled because it does not work
3051 //#if 0 3090 //#if 0
3052 case KMessageBox::Yes: // just this one 3091 case KMessageBox::Yes: // just this one
3053 //QDate qd = mNavigator->selectedDates().first(); 3092 //QDate qd = mNavigator->selectedDates().first();
3054 //if (!qd.isValid()) { 3093 //if (!qd.isValid()) {
3055 // kdDebug() << "no date selected, or invalid date" << endl; 3094 // kdDebug() << "no date selected, or invalid date" << endl;
3056 // KNotifyClient::beep(); 3095 // KNotifyClient::beep();
3057 // return; 3096 // return;
3058 //} 3097 //}
3059 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3098 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3060 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3099 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3061 anEvent->addExDate(itemDate); 3100 anEvent->addExDate(itemDate);
3062 int duration = anEvent->recurrence()->duration(); 3101 int duration = anEvent->recurrence()->duration();
3063 if ( duration > 0 ) { 3102 if ( duration > 0 ) {
3064 anEvent->recurrence()->setDuration( duration - 1 ); 3103 anEvent->recurrence()->setDuration( duration - 1 );
3065 } 3104 }
3066 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3105 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3067 } 3106 }
3068 break; 3107 break;
3069 //#endif 3108 //#endif
3070 } // switch 3109 } // switch
3071 } else { 3110 } else {
3072 if (KOPrefs::instance()->mConfirm) { 3111 if (KOPrefs::instance()->mConfirm) {
3073 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3112 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3074 i18n("\nAre you sure you want\nto delete this event?"), 3113 i18n("\nAre you sure you want\nto delete this event?"),
3075 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3114 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3076 case KMessageBox::Continue: // OK 3115 case KMessageBox::Continue: // OK
3077 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3116 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3078 schedule(Scheduler::Cancel,anEvent); 3117 schedule(Scheduler::Cancel,anEvent);
3079 checkExternalId( anEvent); 3118 checkExternalId( anEvent);
3080 mCalendar->deleteEvent(anEvent); 3119 mCalendar->deleteEvent(anEvent);
3081 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3120 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3082 break; 3121 break;
3083 } // switch 3122 } // switch
3084 } else { 3123 } else {
3085 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3124 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3086 schedule(Scheduler::Cancel,anEvent); 3125 schedule(Scheduler::Cancel,anEvent);
3087 checkExternalId( anEvent); 3126 checkExternalId( anEvent);
3088 mCalendar->deleteEvent(anEvent); 3127 mCalendar->deleteEvent(anEvent);
3089 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3128 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3090 } 3129 }
3091 } // if-else 3130 } // if-else
3092 emit updateSearchDialog(); 3131 emit updateSearchDialog();
3093} 3132}
3094 3133
3095bool CalendarView::deleteEvent(const QString &uid) 3134bool CalendarView::deleteEvent(const QString &uid)
3096{ 3135{
3097 Event *ev = mCalendar->event(uid); 3136 Event *ev = mCalendar->event(uid);
3098 if (ev) { 3137 if (ev) {
3099 deleteEvent(ev); 3138 deleteEvent(ev);
3100 return true; 3139 return true;
3101 } else { 3140 } else {
3102 return false; 3141 return false;
3103 } 3142 }
3104} 3143}
3105 3144
3106/*****************************************************************************/ 3145/*****************************************************************************/
3107 3146
3108void CalendarView::action_mail() 3147void CalendarView::action_mail()
3109{ 3148{
3110#ifndef KORG_NOMAIL 3149#ifndef KORG_NOMAIL
3111 KOMailClient mailClient; 3150 KOMailClient mailClient;
3112 3151
3113 Incidence *incidence = currentSelection(); 3152 Incidence *incidence = currentSelection();
3114 3153
3115 if (!incidence) { 3154 if (!incidence) {
3116 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3155 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3117 return; 3156 return;
3118 } 3157 }
3119 if(incidence->attendeeCount() == 0 ) { 3158 if(incidence->attendeeCount() == 0 ) {
3120 KMessageBox::sorry(this, 3159 KMessageBox::sorry(this,
3121 i18n("Can't generate mail:\nNo attendees defined.\n")); 3160 i18n("Can't generate mail:\nNo attendees defined.\n"));
3122 return; 3161 return;
3123 } 3162 }
3124 3163
3125 CalendarLocal cal_tmp; 3164 CalendarLocal cal_tmp;
3126 Event *event = 0; 3165 Event *event = 0;
3127 Event *ev = 0; 3166 Event *ev = 0;
3128 if ( incidence && incidence->type() == "Event" ) { 3167 if ( incidence && incidence->type() == "Event" ) {
3129 event = static_cast<Event *>(incidence); 3168 event = static_cast<Event *>(incidence);
3130 ev = new Event(*event); 3169 ev = new Event(*event);
3131 cal_tmp.addEvent(ev); 3170 cal_tmp.addEvent(ev);
3132 } 3171 }
3133 ICalFormat mForm(); 3172 ICalFormat mForm();
3134 QString attachment = mForm.toString( &cal_tmp ); 3173 QString attachment = mForm.toString( &cal_tmp );
3135 if (ev) delete(ev); 3174 if (ev) delete(ev);
3136 3175
3137 mailClient.mailAttendees(currentSelection(), attachment); 3176 mailClient.mailAttendees(currentSelection(), attachment);
3138 3177
3139#endif 3178#endif
3140 3179
3141#if 0 3180#if 0
3142 Event *anEvent = 0; 3181 Event *anEvent = 0;
3143 if (mViewManager->currentView()->isEventView()) { 3182 if (mViewManager->currentView()->isEventView()) {
3144 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3183 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3145 } 3184 }
3146 3185
3147 if (!anEvent) { 3186 if (!anEvent) {
3148 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3187 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3149 return; 3188 return;
3150 } 3189 }
3151 if(anEvent->attendeeCount() == 0 ) { 3190 if(anEvent->attendeeCount() == 0 ) {
3152 KMessageBox::sorry(this, 3191 KMessageBox::sorry(this,
3153 i18n("Can't generate mail:\nNo attendees defined.\n")); 3192 i18n("Can't generate mail:\nNo attendees defined.\n"));
3154 return; 3193 return;
3155 } 3194 }
3156 3195
3157 mailobject.emailEvent(anEvent); 3196 mailobject.emailEvent(anEvent);
3158#endif 3197#endif
3159} 3198}
3160 3199
3161 3200
3162void CalendarView::schedule_publish(Incidence *incidence) 3201void CalendarView::schedule_publish(Incidence *incidence)
3163{ 3202{
3164 Event *event = 0; 3203 Event *event = 0;
3165 Todo *todo = 0; 3204 Todo *todo = 0;
3166 3205
3167 if (incidence == 0) { 3206 if (incidence == 0) {
3168 incidence = mViewManager->currentView()->selectedIncidences().first(); 3207 incidence = mViewManager->currentView()->selectedIncidences().first();
3169 if (incidence == 0) { 3208 if (incidence == 0) {
3170 incidence = mTodoList->selectedIncidences().first(); 3209 incidence = mTodoList->selectedIncidences().first();
3171 } 3210 }
3172 } 3211 }
3173 if ( incidence && incidence->type() == "Event" ) { 3212 if ( incidence && incidence->type() == "Event" ) {
3174 event = static_cast<Event *>(incidence); 3213 event = static_cast<Event *>(incidence);
3175 } else { 3214 } else {
3176 if ( incidence && incidence->type() == "Todo" ) { 3215 if ( incidence && incidence->type() == "Todo" ) {
3177 todo = static_cast<Todo *>(incidence); 3216 todo = static_cast<Todo *>(incidence);
3178 } 3217 }
3179 } 3218 }
3180 3219
3181 if (!event && !todo) { 3220 if (!event && !todo) {
3182 KMessageBox::sorry(this,i18n("No event selected.")); 3221 KMessageBox::sorry(this,i18n("No event selected."));
3183 return; 3222 return;
3184 } 3223 }
3185 3224
3186 PublishDialog *publishdlg = new PublishDialog(); 3225 PublishDialog *publishdlg = new PublishDialog();
3187 if (incidence->attendeeCount()>0) { 3226 if (incidence->attendeeCount()>0) {
3188 QPtrList<Attendee> attendees = incidence->attendees(); 3227 QPtrList<Attendee> attendees = incidence->attendees();
3189 attendees.first(); 3228 attendees.first();
3190 while ( attendees.current()!=0 ) { 3229 while ( attendees.current()!=0 ) {
3191 publishdlg->addAttendee(attendees.current()); 3230 publishdlg->addAttendee(attendees.current());
3192 attendees.next(); 3231 attendees.next();
3193 } 3232 }
3194 } 3233 }
3195 bool send = true; 3234 bool send = true;
3196 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3235 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3197 if ( publishdlg->exec() != QDialog::Accepted ) 3236 if ( publishdlg->exec() != QDialog::Accepted )
3198 send = false; 3237 send = false;
3199 } 3238 }
3200 if ( send ) { 3239 if ( send ) {
3201 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3240 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3202 if ( event ) { 3241 if ( event ) {
3203 Event *ev = new Event(*event); 3242 Event *ev = new Event(*event);
3204 ev->registerObserver(0); 3243 ev->registerObserver(0);
3205 ev->clearAttendees(); 3244 ev->clearAttendees();
3206 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3245 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3207 delete(ev); 3246 delete(ev);
3208 } 3247 }
3209 } else { 3248 } else {
3210 if ( todo ) { 3249 if ( todo ) {
3211 Todo *ev = new Todo(*todo); 3250 Todo *ev = new Todo(*todo);
3212 ev->registerObserver(0); 3251 ev->registerObserver(0);
3213 ev->clearAttendees(); 3252 ev->clearAttendees();
3214 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3253 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3215 delete(ev); 3254 delete(ev);
3216 } 3255 }
3217 } 3256 }
3218 } 3257 }
3219 } 3258 }
3220 delete publishdlg; 3259 delete publishdlg;
3221} 3260}
3222 3261
3223void CalendarView::schedule_request(Incidence *incidence) 3262void CalendarView::schedule_request(Incidence *incidence)
3224{ 3263{
3225 schedule(Scheduler::Request,incidence); 3264 schedule(Scheduler::Request,incidence);
3226} 3265}
3227 3266
3228void CalendarView::schedule_refresh(Incidence *incidence) 3267void CalendarView::schedule_refresh(Incidence *incidence)
3229{ 3268{
3230 schedule(Scheduler::Refresh,incidence); 3269 schedule(Scheduler::Refresh,incidence);
3231} 3270}
3232 3271
3233void CalendarView::schedule_cancel(Incidence *incidence) 3272void CalendarView::schedule_cancel(Incidence *incidence)
3234{ 3273{
3235 schedule(Scheduler::Cancel,incidence); 3274 schedule(Scheduler::Cancel,incidence);
3236} 3275}
3237 3276
3238void CalendarView::schedule_add(Incidence *incidence) 3277void CalendarView::schedule_add(Incidence *incidence)
3239{ 3278{
3240 schedule(Scheduler::Add,incidence); 3279 schedule(Scheduler::Add,incidence);
3241} 3280}
3242 3281
3243void CalendarView::schedule_reply(Incidence *incidence) 3282void CalendarView::schedule_reply(Incidence *incidence)
3244{ 3283{
3245 schedule(Scheduler::Reply,incidence); 3284 schedule(Scheduler::Reply,incidence);
3246} 3285}
3247 3286
3248void CalendarView::schedule_counter(Incidence *incidence) 3287void CalendarView::schedule_counter(Incidence *incidence)
3249{ 3288{
3250 schedule(Scheduler::Counter,incidence); 3289 schedule(Scheduler::Counter,incidence);
3251} 3290}
3252 3291
3253void CalendarView::schedule_declinecounter(Incidence *incidence) 3292void CalendarView::schedule_declinecounter(Incidence *incidence)
3254{ 3293{
3255 schedule(Scheduler::Declinecounter,incidence); 3294 schedule(Scheduler::Declinecounter,incidence);
3256} 3295}
3257 3296
3258void CalendarView::schedule_publish_freebusy(int daysToPublish) 3297void CalendarView::schedule_publish_freebusy(int daysToPublish)
3259{ 3298{
3260 QDateTime start = QDateTime::currentDateTime(); 3299 QDateTime start = QDateTime::currentDateTime();
3261 QDateTime end = start.addDays(daysToPublish); 3300 QDateTime end = start.addDays(daysToPublish);
3262 3301
3263 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3302 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3264 freebusy->setOrganizer(KOPrefs::instance()->email()); 3303 freebusy->setOrganizer(KOPrefs::instance()->email());
3265 3304
3266 3305
3267 PublishDialog *publishdlg = new PublishDialog(); 3306 PublishDialog *publishdlg = new PublishDialog();
3268 if ( publishdlg->exec() == QDialog::Accepted ) { 3307 if ( publishdlg->exec() == QDialog::Accepted ) {
3269 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3308 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3270 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3309 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3271 delete(freebusy); 3310 delete(freebusy);
3272 } 3311 }
3273 } 3312 }
3274 delete publishdlg; 3313 delete publishdlg;
3275} 3314}
3276 3315
3277void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3316void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3278{ 3317{
3279 Event *event = 0; 3318 Event *event = 0;
3280 Todo *todo = 0; 3319 Todo *todo = 0;
3281 3320
3282 if (incidence == 0) { 3321 if (incidence == 0) {
3283 incidence = mViewManager->currentView()->selectedIncidences().first(); 3322 incidence = mViewManager->currentView()->selectedIncidences().first();
3284 if (incidence == 0) { 3323 if (incidence == 0) {
3285 incidence = mTodoList->selectedIncidences().first(); 3324 incidence = mTodoList->selectedIncidences().first();
3286 } 3325 }
3287 } 3326 }
3288 if ( incidence && incidence->type() == "Event" ) { 3327 if ( incidence && incidence->type() == "Event" ) {
3289 event = static_cast<Event *>(incidence); 3328 event = static_cast<Event *>(incidence);
3290 } 3329 }
3291 if ( incidence && incidence->type() == "Todo" ) { 3330 if ( incidence && incidence->type() == "Todo" ) {
3292 todo = static_cast<Todo *>(incidence); 3331 todo = static_cast<Todo *>(incidence);
3293 } 3332 }
3294 3333
3295 if (!event && !todo) { 3334 if (!event && !todo) {
3296 KMessageBox::sorry(this,i18n("No event selected.")); 3335 KMessageBox::sorry(this,i18n("No event selected."));
3297 return; 3336 return;
3298 } 3337 }
3299 3338
3300 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3339 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3301 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3340 KMessageBox::sorry(this,i18n("The event has no attendees."));
3302 return; 3341 return;
3303 } 3342 }
3304 3343
3305 Event *ev = 0; 3344 Event *ev = 0;
3306 if (event) ev = new Event(*event); 3345 if (event) ev = new Event(*event);
3307 Todo *to = 0; 3346 Todo *to = 0;
3308 if (todo) to = new Todo(*todo); 3347 if (todo) to = new Todo(*todo);
3309 3348
3310 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3349 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3311 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3350 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3312 if (!me) { 3351 if (!me) {
3313 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3352 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3314 return; 3353 return;
3315 } 3354 }
3316 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3355 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3317 StatusDialog *statdlg = new StatusDialog(this); 3356 StatusDialog *statdlg = new StatusDialog(this);
3318 if (!statdlg->exec()==QDialog::Accepted) return; 3357 if (!statdlg->exec()==QDialog::Accepted) return;
3319 me->setStatus( statdlg->status() ); 3358 me->setStatus( statdlg->status() );
3320 delete(statdlg); 3359 delete(statdlg);
3321 } 3360 }
3322 Attendee *menew = new Attendee(*me); 3361 Attendee *menew = new Attendee(*me);
3323 if (ev) { 3362 if (ev) {
3324 ev->clearAttendees(); 3363 ev->clearAttendees();
3325 ev->addAttendee(menew,false); 3364 ev->addAttendee(menew,false);
3326 } else { 3365 } else {
3327 if (to) { 3366 if (to) {
3328 todo->clearAttendees(); 3367 todo->clearAttendees();
3329 todo->addAttendee(menew,false); 3368 todo->addAttendee(menew,false);
3330 } 3369 }
3331 } 3370 }
3332 } 3371 }
3333 3372
3334 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3373 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3335 if (ev) { 3374 if (ev) {
3336 if ( !dlg->addMessage(ev,method) ) delete(ev); 3375 if ( !dlg->addMessage(ev,method) ) delete(ev);
3337 } else { 3376 } else {
3338 if (to) { 3377 if (to) {
3339 if ( !dlg->addMessage(to,method) ) delete(to); 3378 if ( !dlg->addMessage(to,method) ) delete(to);
3340 } 3379 }
3341 } 3380 }
3342} 3381}
3343 3382
3344void CalendarView::openAddressbook() 3383void CalendarView::openAddressbook()
3345{ 3384{
3346 KRun::runCommand("kaddressbook"); 3385 KRun::runCommand("kaddressbook");
3347} 3386}
3348 3387
3349void CalendarView::setModified(bool modified) 3388void CalendarView::setModified(bool modified)
3350{ 3389{
3351 if ( modified ) 3390 if ( modified )
3352 emit signalmodified(); 3391 emit signalmodified();
3353 if (mModified != modified) { 3392 if (mModified != modified) {
3354 mModified = modified; 3393 mModified = modified;
3355 emit modifiedChanged(mModified); 3394 emit modifiedChanged(mModified);
3356 } 3395 }
3357} 3396}
3358 3397
3359bool CalendarView::isReadOnly() 3398bool CalendarView::isReadOnly()
3360{ 3399{
3361 return mReadOnly; 3400 return mReadOnly;
3362} 3401}
3363 3402
3364void CalendarView::setReadOnly(bool readOnly) 3403void CalendarView::setReadOnly(bool readOnly)
3365{ 3404{
3366 if (mReadOnly != readOnly) { 3405 if (mReadOnly != readOnly) {
3367 mReadOnly = readOnly; 3406 mReadOnly = readOnly;
3368 emit readOnlyChanged(mReadOnly); 3407 emit readOnlyChanged(mReadOnly);
3369 } 3408 }
3370} 3409}
3371 3410
3372bool CalendarView::isModified() 3411bool CalendarView::isModified()
3373{ 3412{
3374 return mModified; 3413 return mModified;
3375} 3414}
3376 3415
3377void CalendarView::printSetup() 3416void CalendarView::printSetup()
3378{ 3417{
3379#ifndef KORG_NOPRINTER 3418#ifndef KORG_NOPRINTER
3380 createPrinter(); 3419 createPrinter();
3381 3420
3382 mCalPrinter->setupPrinter(); 3421 mCalPrinter->setupPrinter();
3383#endif 3422#endif
3384} 3423}
3385 3424
3386void CalendarView::print() 3425void CalendarView::print()
3387{ 3426{
3388#ifndef KORG_NOPRINTER 3427#ifndef KORG_NOPRINTER
3389 createPrinter(); 3428 createPrinter();
3390 3429
3391 DateList tmpDateList = mNavigator->selectedDates(); 3430 DateList tmpDateList = mNavigator->selectedDates();
3392 mCalPrinter->print(CalPrinter::Month, 3431 mCalPrinter->print(CalPrinter::Month,
3393 tmpDateList.first(), tmpDateList.last()); 3432 tmpDateList.first(), tmpDateList.last());
3394#endif 3433#endif
3395} 3434}
3396 3435
3397void CalendarView::printPreview() 3436void CalendarView::printPreview()
3398{ 3437{
3399#ifndef KORG_NOPRINTER 3438#ifndef KORG_NOPRINTER
3400 kdDebug() << "CalendarView::printPreview()" << endl; 3439 kdDebug() << "CalendarView::printPreview()" << endl;
3401 3440
3402 createPrinter(); 3441 createPrinter();
3403 3442
3404 DateList tmpDateList = mNavigator->selectedDates(); 3443 DateList tmpDateList = mNavigator->selectedDates();
3405 3444
3406 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3445 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3407 tmpDateList.last()); 3446 tmpDateList.last());
3408#endif 3447#endif
3409} 3448}
3410 3449
3411void CalendarView::exportICalendar() 3450void CalendarView::exportICalendar()
3412{ 3451{
3413 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3452 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3414 3453
3415 // Force correct extension 3454 // Force correct extension
3416 if (filename.right(4) != ".ics") filename += ".ics"; 3455 if (filename.right(4) != ".ics") filename += ".ics";
3417 3456
3418 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3457 FileStorage storage( mCalendar, filename, new ICalFormat() );
3419 storage.save(); 3458 storage.save();
3420} 3459}
3421 3460
3422bool CalendarView::exportVCalendar( QString filename ) 3461bool CalendarView::exportVCalendar( QString filename )
3423{ 3462{
3424 if (mCalendar->journals().count() > 0) { 3463 if (mCalendar->journals().count() > 0) {
3425 int result = KMessageBox::warningContinueCancel(this, 3464 int result = KMessageBox::warningContinueCancel(this,
3426 i18n("The journal entries can not be\nexported to a vCalendar file."), 3465 i18n("The journal entries can not be\nexported to a vCalendar file."),
3427 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3466 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3428 true); 3467 true);
3429 if (result != KMessageBox::Continue) return false; 3468 if (result != KMessageBox::Continue) return false;
3430 } 3469 }
3431 3470
3432 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3471 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3433 3472
3434 // Force correct extension 3473 // Force correct extension
3435 if (filename.right(4) != ".vcs") filename += ".vcs"; 3474 if (filename.right(4) != ".vcs") filename += ".vcs";
3436 3475
3437 FileStorage storage( mCalendar, filename, new VCalFormat ); 3476 FileStorage storage( mCalendar, filename, new VCalFormat );
3438 return storage.save(); 3477 return storage.save();
3439 3478
3440} 3479}
3441 3480
3442void CalendarView::eventUpdated(Incidence *) 3481void CalendarView::eventUpdated(Incidence *)
3443{ 3482{
3444 setModified(); 3483 setModified();
3445 // Don't call updateView here. The code, which has caused the update of the 3484 // Don't call updateView here. The code, which has caused the update of the
3446 // event is responsible for updating the view. 3485 // event is responsible for updating the view.
3447 // updateView(); 3486 // updateView();
3448} 3487}
3449 3488
3450void CalendarView::adaptNavigationUnits() 3489void CalendarView::adaptNavigationUnits()
3451{ 3490{
3452 if (mViewManager->currentView()->isEventView()) { 3491 if (mViewManager->currentView()->isEventView()) {
3453 int days = mViewManager->currentView()->currentDateCount(); 3492 int days = mViewManager->currentView()->currentDateCount();
3454 if (days == 1) { 3493 if (days == 1) {
3455 emit changeNavStringPrev(i18n("&Previous Day")); 3494 emit changeNavStringPrev(i18n("&Previous Day"));
3456 emit changeNavStringNext(i18n("&Next Day")); 3495 emit changeNavStringNext(i18n("&Next Day"));
3457 } else { 3496 } else {
3458 emit changeNavStringPrev(i18n("&Previous Week")); 3497 emit changeNavStringPrev(i18n("&Previous Week"));
3459 emit changeNavStringNext(i18n("&Next Week")); 3498 emit changeNavStringNext(i18n("&Next Week"));
3460 } 3499 }
3461 } 3500 }
3462} 3501}
3463 3502
3464void CalendarView::processMainViewSelection( Incidence *incidence ) 3503void CalendarView::processMainViewSelection( Incidence *incidence )
3465{ 3504{
3466 if ( incidence ) mTodoList->clearSelection(); 3505 if ( incidence ) mTodoList->clearSelection();
3467 processIncidenceSelection( incidence ); 3506 processIncidenceSelection( incidence );
3468} 3507}
3469 3508
3470void CalendarView::processTodoListSelection( Incidence *incidence ) 3509void CalendarView::processTodoListSelection( Incidence *incidence )
3471{ 3510{
3472 if ( incidence && mViewManager->currentView() ) { 3511 if ( incidence && mViewManager->currentView() ) {
3473 mViewManager->currentView()->clearSelection(); 3512 mViewManager->currentView()->clearSelection();
3474 } 3513 }
3475 processIncidenceSelection( incidence ); 3514 processIncidenceSelection( incidence );
3476} 3515}
3477 3516
3478void CalendarView::processIncidenceSelection( Incidence *incidence ) 3517void CalendarView::processIncidenceSelection( Incidence *incidence )
3479{ 3518{
3480 if ( incidence == mSelectedIncidence ) return; 3519 if ( incidence == mSelectedIncidence ) return;
3481 3520
3482 mSelectedIncidence = incidence; 3521 mSelectedIncidence = incidence;
3483 3522
3484 emit incidenceSelected( mSelectedIncidence ); 3523 emit incidenceSelected( mSelectedIncidence );
3485 3524
3486 if ( incidence && incidence->type() == "Event" ) { 3525 if ( incidence && incidence->type() == "Event" ) {
3487 Event *event = static_cast<Event *>( incidence ); 3526 Event *event = static_cast<Event *>( incidence );
3488 if ( event->organizer() == KOPrefs::instance()->email() ) { 3527 if ( event->organizer() == KOPrefs::instance()->email() ) {
3489 emit organizerEventsSelected( true ); 3528 emit organizerEventsSelected( true );
3490 } else { 3529 } else {
3491 emit organizerEventsSelected(false); 3530 emit organizerEventsSelected(false);
3492 } 3531 }
3493 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3532 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3494 KOPrefs::instance()->email() ) ) { 3533 KOPrefs::instance()->email() ) ) {
3495 emit groupEventsSelected( true ); 3534 emit groupEventsSelected( true );
3496 } else { 3535 } else {
3497 emit groupEventsSelected(false); 3536 emit groupEventsSelected(false);
3498 } 3537 }
3499 return; 3538 return;
3500 } else { 3539 } else {
3501 if ( incidence && incidence->type() == "Todo" ) { 3540 if ( incidence && incidence->type() == "Todo" ) {
3502 emit todoSelected( true ); 3541 emit todoSelected( true );
3503 Todo *event = static_cast<Todo *>( incidence ); 3542 Todo *event = static_cast<Todo *>( incidence );
3504 if ( event->organizer() == KOPrefs::instance()->email() ) { 3543 if ( event->organizer() == KOPrefs::instance()->email() ) {
3505 emit organizerEventsSelected( true ); 3544 emit organizerEventsSelected( true );
3506 } else { 3545 } else {
3507 emit organizerEventsSelected(false); 3546 emit organizerEventsSelected(false);
3508 } 3547 }
3509 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3548 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3510 KOPrefs::instance()->email() ) ) { 3549 KOPrefs::instance()->email() ) ) {
3511 emit groupEventsSelected( true ); 3550 emit groupEventsSelected( true );
3512 } else { 3551 } else {
3513 emit groupEventsSelected(false); 3552 emit groupEventsSelected(false);
3514 } 3553 }
3515 return; 3554 return;
3516 } else { 3555 } else {
3517 emit todoSelected( false ); 3556 emit todoSelected( false );
3518 emit organizerEventsSelected(false); 3557 emit organizerEventsSelected(false);
3519 emit groupEventsSelected(false); 3558 emit groupEventsSelected(false);
3520 } 3559 }
3521 return; 3560 return;
3522 } 3561 }
3523 3562
3524 /* if ( incidence && incidence->type() == "Todo" ) { 3563 /* if ( incidence && incidence->type() == "Todo" ) {
3525 emit todoSelected( true ); 3564 emit todoSelected( true );
3526 } else { 3565 } else {
3527 emit todoSelected( false ); 3566 emit todoSelected( false );
3528 }*/ 3567 }*/
3529} 3568}
3530 3569
3531 3570
3532void CalendarView::checkClipboard() 3571void CalendarView::checkClipboard()
3533{ 3572{
3534#ifndef KORG_NODND 3573#ifndef KORG_NODND
3535 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3574 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3536 emit pasteEnabled(true); 3575 emit pasteEnabled(true);
3537 } else { 3576 } else {
3538 emit pasteEnabled(false); 3577 emit pasteEnabled(false);
3539 } 3578 }
3540#endif 3579#endif
3541} 3580}
3542 3581
3543void CalendarView::showDates(const DateList &selectedDates) 3582void CalendarView::showDates(const DateList &selectedDates)
3544{ 3583{
3545 // kdDebug() << "CalendarView::selectDates()" << endl; 3584 // kdDebug() << "CalendarView::selectDates()" << endl;
3546 3585
3547 3586
3548 if ( !mBlockShowDates ) { 3587 if ( !mBlockShowDates ) {
3549 if ( mViewManager->currentView() ) { 3588 if ( mViewManager->currentView() ) {
3550 updateView( selectedDates.first(), selectedDates.last() ); 3589 updateView( selectedDates.first(), selectedDates.last() );
3551 } else { 3590 } else {
3552 mViewManager->showAgendaView(); 3591 mViewManager->showAgendaView();
3553 } 3592 }
3554 } 3593 }
3555 3594
3556 QString selDates; 3595 QString selDates;
3557 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3596 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3558 if (selectedDates.first() < selectedDates.last() ) 3597 if (selectedDates.first() < selectedDates.last() )
3559 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3598 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3560 else { 3599 else {
3561 QString addString; 3600 QString addString;
3562 if ( selectedDates.first() == QDateTime::currentDateTime().date() ) 3601 if ( selectedDates.first() == QDateTime::currentDateTime().date() )
3563 addString = i18n("Today"); 3602 addString = i18n("Today");
3564 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 3603 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
3565 addString = i18n("Tomorrow"); 3604 addString = i18n("Tomorrow");
3566 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 3605 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
3567 addString = i18n("Yesterday"); 3606 addString = i18n("Yesterday");
3568 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 3607 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
3569 addString = i18n("Day before yesterday"); 3608 addString = i18n("Day before yesterday");
3570 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 3609 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
3571 addString = i18n("Day after tomorrow"); 3610 addString = i18n("Day after tomorrow");
3572 if ( !addString.isEmpty() ) { 3611 if ( !addString.isEmpty() ) {
3573 topLevelWidget()->setCaption( addString+", " + selDates ); 3612 topLevelWidget()->setCaption( addString+", " + selDates );
3574 return; 3613 return;
3575 } 3614 }
3576 } 3615 }
3577 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3616 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3578 3617
3579} 3618}
3580 3619
3581QPtrList<CalFilter> CalendarView::filters() 3620QPtrList<CalFilter> CalendarView::filters()
3582{ 3621{
3583 return mFilters; 3622 return mFilters;
3584 3623
3585} 3624}
3586void CalendarView::editFilters() 3625void CalendarView::editFilters()
3587{ 3626{
3588 // kdDebug() << "CalendarView::editFilters()" << endl; 3627 // kdDebug() << "CalendarView::editFilters()" << endl;
3589 3628
3590 CalFilter *filter = mFilters.first(); 3629 CalFilter *filter = mFilters.first();
3591 while(filter) { 3630 while(filter) {
3592 kdDebug() << " Filter: " << filter->name() << endl; 3631 kdDebug() << " Filter: " << filter->name() << endl;
3593 filter = mFilters.next(); 3632 filter = mFilters.next();
3594 } 3633 }
3595 3634
3596 mDialogManager->showFilterEditDialog(&mFilters); 3635 mDialogManager->showFilterEditDialog(&mFilters);
3597} 3636}
3598void CalendarView::toggleFilter() 3637void CalendarView::toggleFilter()
3599{ 3638{
3600 showFilter(! mFilterView->isVisible()); 3639 showFilter(! mFilterView->isVisible());
3601} 3640}
3602 3641
3603KOFilterView *CalendarView::filterView() 3642KOFilterView *CalendarView::filterView()
3604{ 3643{
3605 return mFilterView; 3644 return mFilterView;
3606} 3645}
3607void CalendarView::selectFilter( int fil ) 3646void CalendarView::selectFilter( int fil )
3608{ 3647{
3609 mFilterView->setSelectedFilter( fil ); 3648 mFilterView->setSelectedFilter( fil );
3610} 3649}
3611void CalendarView::showFilter(bool visible) 3650void CalendarView::showFilter(bool visible)
3612{ 3651{
3613 if (visible) mFilterView->show(); 3652 if (visible) mFilterView->show();
3614 else mFilterView->hide(); 3653 else mFilterView->hide();
3615} 3654}
3616void CalendarView::toggleFilerEnabled( ) 3655void CalendarView::toggleFilerEnabled( )
3617{ 3656{
3618 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3657 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3619 if ( !mFilterView->filtersEnabled() ) 3658 if ( !mFilterView->filtersEnabled() )
3620 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3659 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3621 3660
3622} 3661}
3623void CalendarView::updateFilter() 3662void CalendarView::updateFilter()
3624{ 3663{
3625 CalFilter *filter = mFilterView->selectedFilter(); 3664 CalFilter *filter = mFilterView->selectedFilter();
3626 if (filter) { 3665 if (filter) {
3627 QString mess; 3666 QString mess;
3628 if (mFilterView->filtersEnabled()) { 3667 if (mFilterView->filtersEnabled()) {
3629 mess = i18n("Filter selected: ")+filter->name(); 3668 mess = i18n("Filter selected: ")+filter->name();
3630 filter->setEnabled(true); 3669 filter->setEnabled(true);
3631 } 3670 }
3632 else filter->setEnabled(false); 3671 else filter->setEnabled(false);
3633 mCalendar->setFilter(filter); 3672 mCalendar->setFilter(filter);
3634 updateView(); 3673 updateView();
3635 if ( !mess.isEmpty() ) 3674 if ( !mess.isEmpty() )
3636 topLevelWidget()->setCaption( mess ); 3675 topLevelWidget()->setCaption( mess );
3637 3676
3638 } 3677 }
3639} 3678}
3640 3679
3641void CalendarView::filterEdited() 3680void CalendarView::filterEdited()
3642{ 3681{
3643 mFilterView->updateFilters(); 3682 mFilterView->updateFilters();
3644 updateFilter(); 3683 updateFilter();
3645 writeSettings(); 3684 writeSettings();
3646} 3685}
3647 3686
3648 3687
3649void CalendarView::takeOverEvent() 3688void CalendarView::takeOverEvent()
3650{ 3689{
3651 Incidence *incidence = currentSelection(); 3690 Incidence *incidence = currentSelection();
3652 3691
3653 if (!incidence) return; 3692 if (!incidence) return;
3654 3693
3655 incidence->setOrganizer(KOPrefs::instance()->email()); 3694 incidence->setOrganizer(KOPrefs::instance()->email());
3656 incidence->recreate(); 3695 incidence->recreate();
3657 incidence->setReadOnly(false); 3696 incidence->setReadOnly(false);
3658 3697
3659 updateView(); 3698 updateView();
3660} 3699}
3661 3700
3662void CalendarView::takeOverCalendar() 3701void CalendarView::takeOverCalendar()
3663{ 3702{
3664 // TODO: Create Calendar::allIncidences() function and use it here 3703 // TODO: Create Calendar::allIncidences() function and use it here
3665 3704
3666 QPtrList<Event> events = mCalendar->events(); 3705 QPtrList<Event> events = mCalendar->events();
3667 for(uint i=0; i<events.count(); ++i) { 3706 for(uint i=0; i<events.count(); ++i) {
3668 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3707 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3669 events.at(i)->recreate(); 3708 events.at(i)->recreate();
3670 events.at(i)->setReadOnly(false); 3709 events.at(i)->setReadOnly(false);
3671 } 3710 }
3672 3711
3673 QPtrList<Todo> todos = mCalendar->todos(); 3712 QPtrList<Todo> todos = mCalendar->todos();
3674 for(uint i=0; i<todos.count(); ++i) { 3713 for(uint i=0; i<todos.count(); ++i) {
3675 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3714 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3676 todos.at(i)->recreate(); 3715 todos.at(i)->recreate();
3677 todos.at(i)->setReadOnly(false); 3716 todos.at(i)->setReadOnly(false);
3678 } 3717 }
3679 3718
3680 QPtrList<Journal> journals = mCalendar->journals(); 3719 QPtrList<Journal> journals = mCalendar->journals();
3681 for(uint i=0; i<journals.count(); ++i) { 3720 for(uint i=0; i<journals.count(); ++i) {
3682 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3721 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3683 journals.at(i)->recreate(); 3722 journals.at(i)->recreate();
3684 journals.at(i)->setReadOnly(false); 3723 journals.at(i)->setReadOnly(false);
3685 } 3724 }
3686 3725
3687 updateView(); 3726 updateView();
3688} 3727}
3689 3728
3690void CalendarView::showIntro() 3729void CalendarView::showIntro()
3691{ 3730{
3692 kdDebug() << "To be implemented." << endl; 3731 kdDebug() << "To be implemented." << endl;
3693} 3732}
3694 3733
3695QWidgetStack *CalendarView::viewStack() 3734QWidgetStack *CalendarView::viewStack()
3696{ 3735{
3697 return mRightFrame; 3736 return mRightFrame;
3698} 3737}
3699 3738
3700QWidget *CalendarView::leftFrame() 3739QWidget *CalendarView::leftFrame()
3701{ 3740{
3702 return ( QWidget *)mLeftFrame; 3741 return ( QWidget *)mLeftFrame;
3703} 3742}
3704 3743
3705DateNavigator *CalendarView::dateNavigator() 3744DateNavigator *CalendarView::dateNavigator()
3706{ 3745{
3707 return mNavigator; 3746 return mNavigator;
3708} 3747}
3709 3748
3710KDateNavigator* CalendarView::dateNavigatorWidget() 3749KDateNavigator* CalendarView::dateNavigatorWidget()
3711{ 3750{
3712 return mDateNavigator->navigatorView(); 3751 return mDateNavigator->navigatorView();
3713} 3752}
3714void CalendarView::toggleDateNavigatorWidget() 3753void CalendarView::toggleDateNavigatorWidget()
3715{ 3754{
3716 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 3755 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
3717 mLeftFrame->toggle(); 3756
3718 // FIXME mShowDateNavigator is not the toggle state of mLeftFrame
3719#if 0
3720 if (!KOPrefs::instance()->mShowDateNavigator ) 3757 if (!KOPrefs::instance()->mShowDateNavigator )
3721 mDateNavigator->hide(); 3758 mDateNavigator->hide();
3722 else 3759 else
3723 mDateNavigator->show(); 3760 mDateNavigator->show();
3724#endif
3725} 3761}
3726void CalendarView::addView(KOrg::BaseView *view) 3762void CalendarView::addView(KOrg::BaseView *view)
3727{ 3763{
3728 mViewManager->addView(view); 3764 mViewManager->addView(view);
3729} 3765}
3730 3766
3731void CalendarView::showView(KOrg::BaseView *view) 3767void CalendarView::showView(KOrg::BaseView *view)
3732{ 3768{
3733 mViewManager->showView(view, mLeftFrame->isVisible()); 3769 mViewManager->showView(view, mLeftFrame->isVisible());
3734} 3770}
3735 3771
3736Incidence *CalendarView::currentSelection() 3772Incidence *CalendarView::currentSelection()
3737{ 3773{
3738 return mViewManager->currentSelection(); 3774 return mViewManager->currentSelection();
3739} 3775}
3740void CalendarView::toggleAllDaySize() 3776void CalendarView::toggleAllDaySize()
3741{ 3777{
3742 /* 3778 /*
3743 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3779 if ( KOPrefs::instance()->mAllDaySize > 47 )
3744 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3780 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3745 else 3781 else
3746 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3782 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3747 */ 3783 */
3748 viewManager()->agendaView()->toggleAllDay(); 3784 viewManager()->agendaView()->toggleAllDay();
3749} 3785}
3750void CalendarView::toggleExpand() 3786void CalendarView::toggleExpand()
3751{ 3787{
3752 // if ( mLeftFrame->isHidden() ) { 3788 // if ( mLeftFrame->isHidden() ) {
3753 // mLeftFrame->show(); 3789 // mLeftFrame->show();
3754 // emit calendarViewExpanded( false ); 3790 // emit calendarViewExpanded( false );
3755 // } else { 3791 // } else {
3756 // mLeftFrame->hide(); 3792 // mLeftFrame->hide();
3757 // emit calendarViewExpanded( true ); 3793 // emit calendarViewExpanded( true );
3758 // } 3794 // }
3759 //qDebug(" CalendarView::toggleExpand()"); 3795 //qDebug(" CalendarView::toggleExpand()");
3760 globalFlagBlockAgenda = 1; 3796 globalFlagBlockAgenda = 1;
3761 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3797 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3762 globalFlagBlockAgenda = 5; 3798 globalFlagBlockAgenda = 5;
3763 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3799 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3764 //mViewManager->showView( 0, true ); 3800 //mViewManager->showView( 0, true );
3765} 3801}
3766 3802
3767void CalendarView::calendarModified( bool modified, Calendar * ) 3803void CalendarView::calendarModified( bool modified, Calendar * )
3768{ 3804{
3769 setModified( modified ); 3805 setModified( modified );
3770} 3806}
3771 3807
3772Todo *CalendarView::selectedTodo() 3808Todo *CalendarView::selectedTodo()
3773{ 3809{
3774 Incidence *incidence = currentSelection(); 3810 Incidence *incidence = currentSelection();
3775 if ( incidence && incidence->type() == "Todo" ) { 3811 if ( incidence && incidence->type() == "Todo" ) {
3776 return static_cast<Todo *>( incidence ); 3812 return static_cast<Todo *>( incidence );
3777 } 3813 }
3778 3814
3779 incidence = mTodoList->selectedIncidences().first(); 3815 incidence = mTodoList->selectedIncidences().first();
3780 if ( incidence && incidence->type() == "Todo" ) { 3816 if ( incidence && incidence->type() == "Todo" ) {
3781 return static_cast<Todo *>( incidence ); 3817 return static_cast<Todo *>( incidence );
3782 } 3818 }
3783 3819
3784 return 0; 3820 return 0;
3785} 3821}
3786 3822
3787void CalendarView::dialogClosing(Incidence *in) 3823void CalendarView::dialogClosing(Incidence *in)
3788{ 3824{
3789 // mDialogList.remove(in); 3825 // mDialogList.remove(in);
3790} 3826}
3791 3827
3792void CalendarView::showIncidence() 3828void CalendarView::showIncidence()
3793{ 3829{
3794 mViewerCallerIsSearchDialog = false; 3830 mViewerCallerIsSearchDialog = false;
3795 Incidence *incidence = currentSelection(); 3831 Incidence *incidence = currentSelection();
3796 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3832 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3797 if ( incidence ) { 3833 if ( incidence ) {
3798 ShowIncidenceVisitor v; 3834 ShowIncidenceVisitor v;
3799 v.act( incidence, this ); 3835 v.act( incidence, this );
3800 } 3836 }
3801} 3837}
3802void CalendarView::editIncidenceDescription() 3838void CalendarView::editIncidenceDescription()
3803{ 3839{
3804 mFlagEditDescription = true; 3840 mFlagEditDescription = true;
3805 editIncidence(); 3841 editIncidence();
3806 mFlagEditDescription = false; 3842 mFlagEditDescription = false;
3807} 3843}
3808void CalendarView::editIncidence() 3844void CalendarView::editIncidence()
3809{ 3845{
3810 // qDebug("editIncidence() "); 3846 // qDebug("editIncidence() ");
3811 Incidence *incidence = currentSelection(); 3847 Incidence *incidence = currentSelection();
3812 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3848 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3813 if ( incidence ) { 3849 if ( incidence ) {
3814 EditIncidenceVisitor v; 3850 EditIncidenceVisitor v;
3815 v.act( incidence, this ); 3851 v.act( incidence, this );
3816 } 3852 }
3817} 3853}
3818 3854
3819void CalendarView::deleteIncidence() 3855void CalendarView::deleteIncidence()
3820{ 3856{
3821 Incidence *incidence = currentSelection(); 3857 Incidence *incidence = currentSelection();
3822 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3858 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3823 if ( incidence ) { 3859 if ( incidence ) {
3824 deleteIncidence(incidence); 3860 deleteIncidence(incidence);
3825 } 3861 }
3826} 3862}
3827 3863
3828void CalendarView::showIncidence(Incidence *incidence) 3864void CalendarView::showIncidence(Incidence *incidence)
3829{ 3865{
3830 mViewerCallerIsSearchDialog = false; 3866 mViewerCallerIsSearchDialog = false;
3831 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 3867 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
3832 if ( sender() && mDialogManager->getSearchDialog() ) { 3868 if ( sender() && mDialogManager->getSearchDialog() ) {
3833 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 3869 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
3834 mViewerCallerIsSearchDialog = true; 3870 mViewerCallerIsSearchDialog = true;
3835 } 3871 }
3836 } 3872 }
3837 if ( incidence ) { 3873 if ( incidence ) {
3838 ShowIncidenceVisitor v; 3874 ShowIncidenceVisitor v;
3839 v.act( incidence, this ); 3875 v.act( incidence, this );
3840 } 3876 }
3841} 3877}
3842 3878
3843void CalendarView::editIncidence(Incidence *incidence) 3879void CalendarView::editIncidence(Incidence *incidence)
3844{ 3880{
3845 if ( incidence ) { 3881 if ( incidence ) {
3846 3882
3847 EditIncidenceVisitor v; 3883 EditIncidenceVisitor v;
3848 v.act( incidence, this ); 3884 v.act( incidence, this );
3849 3885
3850 } 3886 }
3851} 3887}
3852 3888
3853void CalendarView::deleteIncidence(Incidence *incidence) 3889void CalendarView::deleteIncidence(Incidence *incidence)
3854{ 3890{
3855 //qDebug(" CalendarView::deleteIncidence "); 3891 //qDebug(" CalendarView::deleteIncidence ");
3856 if ( incidence ) { 3892 if ( incidence ) {
3857 DeleteIncidenceVisitor v; 3893 DeleteIncidenceVisitor v;
3858 v.act( incidence, this ); 3894 v.act( incidence, this );
3859 } 3895 }
3860} 3896}
3861 3897
3862 3898
3863void CalendarView::lookForOutgoingMessages() 3899void CalendarView::lookForOutgoingMessages()
3864{ 3900{
3865 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3901 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3866 ogd->loadMessages(); 3902 ogd->loadMessages();
3867} 3903}
3868 3904
3869void CalendarView::lookForIncomingMessages() 3905void CalendarView::lookForIncomingMessages()
3870{ 3906{
3871 IncomingDialog *icd = mDialogManager->incomingDialog(); 3907 IncomingDialog *icd = mDialogManager->incomingDialog();
3872 icd->retrieve(); 3908 icd->retrieve();
3873} 3909}
3874 3910
3875bool CalendarView::removeCompletedSubTodos( Todo* t ) 3911bool CalendarView::removeCompletedSubTodos( Todo* t )
3876{ 3912{
3877 bool deleteTodo = true; 3913 bool deleteTodo = true;
3878 QPtrList<Incidence> subTodos; 3914 QPtrList<Incidence> subTodos;
3879 Incidence *aTodo; 3915 Incidence *aTodo;
3880 subTodos = t->relations(); 3916 subTodos = t->relations();
3881 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3917 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3882 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3918 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3883 deleteTodo = false; 3919 deleteTodo = false;
3884 } 3920 }
3885 if ( deleteTodo ) { 3921 if ( deleteTodo ) {
3886 if ( t->isCompleted() && !t->doesRecur()) { 3922 if ( t->isCompleted() && !t->doesRecur()) {
3887 checkExternalId( t ); 3923 checkExternalId( t );
3888 mCalendar->deleteTodo( t ); 3924 mCalendar->deleteTodo( t );
3889 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3925 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3890 } 3926 }
3891 else 3927 else
3892 deleteTodo = false; 3928 deleteTodo = false;
3893 } 3929 }
3894 return deleteTodo; 3930 return deleteTodo;
3895 3931
3896} 3932}
3897void CalendarView::purgeCompleted() 3933void CalendarView::purgeCompleted()
3898{ 3934{
3899 int result = KMessageBox::warningContinueCancel(this, 3935 int result = KMessageBox::warningContinueCancel(this,
3900 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3936 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3901 3937
3902 if (result == KMessageBox::Continue) { 3938 if (result == KMessageBox::Continue) {
3903 3939
3904 QPtrList<Todo> todoCal; 3940 QPtrList<Todo> todoCal;
3905 QPtrList<Todo> rootTodos; 3941 QPtrList<Todo> rootTodos;
3906 //QPtrList<Incidence> rel; 3942 //QPtrList<Incidence> rel;
3907 Todo *aTodo;//, *rTodo; 3943 Todo *aTodo;//, *rTodo;
3908 Incidence *rIncidence; 3944 Incidence *rIncidence;
3909 bool childDelete = false; 3945 bool childDelete = false;
3910 bool deletedOne = true; 3946 bool deletedOne = true;
3911 todoCal = calendar()->todos(); 3947 todoCal = calendar()->todos();
3912 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3948 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3913 if ( !aTodo->relatedTo() ) 3949 if ( !aTodo->relatedTo() )
3914 rootTodos.append( aTodo ); 3950 rootTodos.append( aTodo );
3915 } 3951 }
3916 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3952 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3917 removeCompletedSubTodos( aTodo ); 3953 removeCompletedSubTodos( aTodo );
3918 } 3954 }
3919 3955
3920 updateView(); 3956 updateView();
3921 } 3957 }
3922} 3958}
3923 3959
3924void CalendarView::slotCalendarChanged() 3960void CalendarView::slotCalendarChanged()
3925{ 3961{
3926 ; 3962 ;
3927} 3963}
3928 3964
3929void CalendarView::keyPressEvent ( QKeyEvent *e) 3965void CalendarView::keyPressEvent ( QKeyEvent *e)
3930{ 3966{
3931 //qDebug(" alendarView::keyPressEvent "); 3967 //qDebug(" alendarView::keyPressEvent ");
3932 e->ignore(); 3968 e->ignore();
3933} 3969}
3934 3970
3935 3971
3936bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3972bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3937{ 3973{
3938 // mSyncManager = manager; 3974 // mSyncManager = manager;
3939 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3975 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3940 qDebug("KO: SyncKDE request detected!"); 3976 qDebug("KO: SyncKDE request detected!");
3941 } 3977 }
3942 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3978 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3943 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3979 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3944 return syncCalendar( filename, mode ); 3980 return syncCalendar( filename, mode );
3945} 3981}
3946bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3982bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3947{ 3983{
3948 //mSyncManager = manager; 3984 //mSyncManager = manager;
3949 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3985 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3950 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3986 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3951 if ( resource == "sharp" ) 3987 if ( resource == "sharp" )
3952 syncExternal( 0 ); 3988 syncExternal( 0 );
3953 if ( resource == "phone" ) 3989 if ( resource == "phone" )
3954 syncExternal( 1 ); 3990 syncExternal( 1 );
3955 // pending setmodified 3991 // pending setmodified
3956 return true; 3992 return true;
3957} 3993}
3958void CalendarView::setSyncManager(KSyncManager* manager) 3994void CalendarView::setSyncManager(KSyncManager* manager)
3959{ 3995{
3960 mSyncManager = manager; 3996 mSyncManager = manager;
3961} 3997}
3962 3998
3963void CalendarView::removeSyncInfo( QString syncProfile) 3999void CalendarView::removeSyncInfo( QString syncProfile)
3964{ 4000{
3965 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4001 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
3966 mCalendar->removeSyncInfo( syncProfile ); 4002 mCalendar->removeSyncInfo( syncProfile );
3967 4003
3968} 4004}
3969 4005
3970void CalendarView::undo_delete() 4006void CalendarView::undo_delete()
3971{ 4007{
3972 //qDebug("undo_delete() "); 4008 //qDebug("undo_delete() ");
3973 Incidence* undo = mCalendar->undoIncidence(); 4009 Incidence* undo = mCalendar->undoIncidence();
3974 if ( !undo ) { 4010 if ( !undo ) {
3975 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4011 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
3976 i18n("KO/Pi")); 4012 i18n("KO/Pi"));
3977 return; 4013 return;
3978 } 4014 }
3979 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) + 4015 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) +
3980 i18n("\nAre you sure you want\nto restore this?"), 4016 i18n("\nAre you sure you want\nto restore this?"),
3981 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4017 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
3982 mCalendar->undoDeleteIncidence(); 4018 mCalendar->undoDeleteIncidence();
3983 updateView(); 4019 updateView();
3984 } 4020 }
3985} 4021}
3986 4022
3987void CalendarView::slotViewerClosed() 4023void CalendarView::slotViewerClosed()
3988{ 4024{
3989 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4025 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
3990} 4026}
3991 4027
3992void CalendarView::resetFocus() 4028void CalendarView::resetFocus()
3993{ 4029{
3994 if ( mViewerCallerIsSearchDialog ) { 4030 if ( mViewerCallerIsSearchDialog ) {
3995 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4031 if ( mDialogManager->getSearchDialog()->isVisible() ){
3996 mDialogManager->getSearchDialog()->raise(); 4032 mDialogManager->getSearchDialog()->raise();
3997 mDialogManager->getSearchDialog()->setActiveWindow(); 4033 mDialogManager->getSearchDialog()->setActiveWindow();
3998 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4034 mDialogManager->getSearchDialog()->listview()->resetFocus();
3999 } else 4035 } else
4000 mViewerCallerIsSearchDialog = false; 4036 mViewerCallerIsSearchDialog = false;
4001 } 4037 }
4002 if ( !mViewerCallerIsSearchDialog ) { 4038 if ( !mViewerCallerIsSearchDialog ) {
4003 //mViewManager->currentView()->setFocus(); 4039 //mViewManager->currentView()->setFocus();
4004 //qDebug("sssssssssssssssset focus "); 4040 //qDebug("sssssssssssssssset focus ");
4005 topLevelWidget()->raise(); 4041 topLevelWidget()->raise();
4006 setActiveWindow(); 4042 setActiveWindow();
4007 //setFocus(); 4043 //setFocus();
4008 } 4044 }
4009 mViewerCallerIsSearchDialog = false; 4045 mViewerCallerIsSearchDialog = false;
4010} 4046}