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