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