summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp70
1 files changed, 38 insertions, 32 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 685bb60..da1edea 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,2245 +1,2251 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130 130
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
133#endif 133#endif
134using namespace KOrg; 134using namespace KOrg;
135using namespace KCal; 135using namespace KCal;
136extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
137extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
138 138
139 139
140 140
141class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
142{ 142{
143 public: 143 public:
144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
145 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
146 { 146 {
147 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
148 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
149 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
150 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
152 lay->addWidget( format ); 152 lay->addWidget( format );
153 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
155 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
156 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
157 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
158 vcal->setChecked( true ); 158 vcal->setChecked( true );
159 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
160 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
237 mDatePickerMode = 0; 237 mDatePickerMode = 0;
238 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
239 writeLocale(); 239 writeLocale();
240 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
241 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
242 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
243 mModified = false; 243 mModified = false;
244 mReadOnly = false; 244 mReadOnly = false;
245 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
246 mCalPrinter = 0; 246 mCalPrinter = 0;
247 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
248 248
249 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
250 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
251 251
252 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
253 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
254 254
255 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
256#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
257 // create the main layout frames. 257 // create the main layout frames.
258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
259 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
260 260
261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
262 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
264 264
265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
266 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
269 mTodoList->setNavigator( mNavigator ); 269 mTodoList->setNavigator( mNavigator );
270 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 270 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
271 271
272#ifdef KORG_NORESOURCEVIEW 272#ifdef KORG_NORESOURCEVIEW
273 mResourceView = 0; 273 mResourceView = 0;
274#else 274#else
275 if ( mResourceManager ) { 275 if ( mResourceManager ) {
276 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 276 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
277 mResourceView->updateView(); 277 mResourceView->updateView();
278 connect( mResourceView, SIGNAL( resourcesChanged() ), 278 connect( mResourceView, SIGNAL( resourcesChanged() ),
279 SLOT( updateView() ) ); 279 SLOT( updateView() ) );
280 } else { 280 } else {
281 mResourceView = 0; 281 mResourceView = 0;
282 } 282 }
283#endif 283#endif
284 QWidget *rightBox = new QWidget( mPanner ); 284 QWidget *rightBox = new QWidget( mPanner );
285 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 285 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
286 286
287 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 287 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
288 rightLayout->addWidget( mNavigatorBar ); 288 rightLayout->addWidget( mNavigatorBar );
289 289
290 mRightFrame = new QWidgetStack( rightBox ); 290 mRightFrame = new QWidgetStack( rightBox );
291 rightLayout->addWidget( mRightFrame, 1 ); 291 rightLayout->addWidget( mRightFrame, 1 );
292 292
293 mLeftFrame = mLeftSplitter; 293 mLeftFrame = mLeftSplitter;
294#else 294#else
295 QWidget *mainBox = new QWidget( this ); 295 QWidget *mainBox = new QWidget( this );
296 QWidget *leftFrame = new QWidget( mainBox ); 296 QWidget *leftFrame = new QWidget( mainBox );
297 297
298 QBoxLayout * mainBoxLayout; 298 QBoxLayout * mainBoxLayout;
299 QBoxLayout * leftFrameLayout; 299 QBoxLayout * leftFrameLayout;
300 if ( KOPrefs::instance()->mVerticalScreen ) { 300 if ( KOPrefs::instance()->mVerticalScreen ) {
301 mainBoxLayout = new QVBoxLayout(mainBox); 301 mainBoxLayout = new QVBoxLayout(mainBox);
302 leftFrameLayout = new QHBoxLayout(leftFrame ); 302 leftFrameLayout = new QHBoxLayout(leftFrame );
303 } else { 303 } else {
304 mainBoxLayout = new QHBoxLayout(mainBox); 304 mainBoxLayout = new QHBoxLayout(mainBox);
305 leftFrameLayout = new QVBoxLayout(leftFrame ); 305 leftFrameLayout = new QVBoxLayout(leftFrame );
306 } 306 }
307 topLayout->addWidget( mainBox ); 307 topLayout->addWidget( mainBox );
308 mainBoxLayout->addWidget (leftFrame); 308 mainBoxLayout->addWidget (leftFrame);
309 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 309 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
310 "CalendarView::DateNavigator", QDate::currentDate()); 310 "CalendarView::DateNavigator", QDate::currentDate());
311 // mDateNavigator->blockSignals( true ); 311 // mDateNavigator->blockSignals( true );
312 leftFrameLayout->addWidget( mDateNavigator ); 312 leftFrameLayout->addWidget( mDateNavigator );
313 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 313 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
314 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 314 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
315 mTodoList->setNavigator( mNavigator ); 315 mTodoList->setNavigator( mNavigator );
316 316
317 if ( QApplication::desktop()->width() < 480 ) { 317 if ( QApplication::desktop()->width() < 480 ) {
318 leftFrameLayout->addWidget(mFilterView); 318 leftFrameLayout->addWidget(mFilterView);
319 leftFrameLayout->addWidget(mTodoList, 2 ); 319 leftFrameLayout->addWidget(mTodoList, 2 );
320 320
321 } else { 321 } else {
322 leftFrameLayout->addWidget(mTodoList,2 ); 322 leftFrameLayout->addWidget(mTodoList,2 );
323 leftFrameLayout->addWidget(mFilterView ); 323 leftFrameLayout->addWidget(mFilterView );
324 } 324 }
325 mFilterView->hide(); 325 mFilterView->hide();
326 QWidget *rightBox = new QWidget( mainBox ); 326 QWidget *rightBox = new QWidget( mainBox );
327 mainBoxLayout->addWidget ( rightBox, 10 ); 327 mainBoxLayout->addWidget ( rightBox, 10 );
328 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 328 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
329 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 329 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
330 mRightFrame = new QWidgetStack( rightBox ); 330 mRightFrame = new QWidgetStack( rightBox );
331 rightLayout->addWidget( mNavigatorBar ); 331 rightLayout->addWidget( mNavigatorBar );
332 rightLayout->addWidget( mRightFrame, 10 ); 332 rightLayout->addWidget( mRightFrame, 10 );
333 333
334 mLeftFrame = leftFrame; 334 mLeftFrame = leftFrame;
335 if ( KOPrefs::instance()->mVerticalScreen ) { 335 if ( KOPrefs::instance()->mVerticalScreen ) {
336 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 336 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
337 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 337 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
338 } else { 338 } else {
339 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 339 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
340 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 340 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
341 } 341 }
342 342
343 //qDebug("Calendarview Size %d %d ", width(), height()); 343 //qDebug("Calendarview Size %d %d ", width(), height());
344#endif 344#endif
345 345
346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
347 SLOT( showDates( const KCal::DateList & ) ) ); 347 SLOT( showDates( const KCal::DateList & ) ) );
348 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 348 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
349 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 349 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
350 350
351 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 351 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
352 mNavigator, SLOT( selectPreviousYear() ) ); 352 mNavigator, SLOT( selectPreviousYear() ) );
353 connect( mNavigatorBar, SIGNAL( goNextYear() ), 353 connect( mNavigatorBar, SIGNAL( goNextYear() ),
354 mNavigator, SLOT( selectNextYear() ) ); 354 mNavigator, SLOT( selectNextYear() ) );
355 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 355 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
356 mNavigator, SLOT( selectPreviousMonth() ) ); 356 mNavigator, SLOT( selectPreviousMonth() ) );
357 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 357 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
358 mNavigator, SLOT( selectNextMonth() ) ); 358 mNavigator, SLOT( selectNextMonth() ) );
359 359
360 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 360 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
361 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 361 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
362 362
363 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 363 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
364 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 364 mNavigator, SLOT( selectWeek( const QDate & ) ) );
365 365
366 connect( mDateNavigator, SIGNAL( goPrevYear() ), 366 connect( mDateNavigator, SIGNAL( goPrevYear() ),
367 mNavigator, SLOT( selectPreviousYear() ) ); 367 mNavigator, SLOT( selectPreviousYear() ) );
368 connect( mDateNavigator, SIGNAL( goNextYear() ), 368 connect( mDateNavigator, SIGNAL( goNextYear() ),
369 mNavigator, SLOT( selectNextYear() ) ); 369 mNavigator, SLOT( selectNextYear() ) );
370 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 370 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
371 mNavigator, SLOT( selectPreviousMonth() ) ); 371 mNavigator, SLOT( selectPreviousMonth() ) );
372 connect( mDateNavigator, SIGNAL( goNextMonth() ), 372 connect( mDateNavigator, SIGNAL( goNextMonth() ),
373 mNavigator, SLOT( selectNextMonth() ) ); 373 mNavigator, SLOT( selectNextMonth() ) );
374 374
375 connect( mDateNavigator, SIGNAL( goPrevious() ), 375 connect( mDateNavigator, SIGNAL( goPrevious() ),
376 mNavigator, SLOT( selectPrevious() ) ); 376 mNavigator, SLOT( selectPrevious() ) );
377 connect( mDateNavigator, SIGNAL( goNext() ), 377 connect( mDateNavigator, SIGNAL( goNext() ),
378 mNavigator, SLOT( selectNext() ) ); 378 mNavigator, SLOT( selectNext() ) );
379 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 379 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
380 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
381 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 381 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
382 mNavigator, SLOT( slotMonthSelect( int ) ) ); 382 mNavigator, SLOT( slotMonthSelect( int ) ) );
383 383
384 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 384 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
385 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 385 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
386 386
387 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 387 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
388 SLOT( eventAdded( Event *) ) ); 388 SLOT( eventAdded( Event *) ) );
389 389
390 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 390 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
391 391
392 connect( this, SIGNAL( configChanged() ), 392 connect( this, SIGNAL( configChanged() ),
393 mDateNavigator, SLOT( updateConfig() ) ); 393 mDateNavigator, SLOT( updateConfig() ) );
394 394
395 connect( mTodoList, SIGNAL( newTodoSignal() ), 395 connect( mTodoList, SIGNAL( newTodoSignal() ),
396 SLOT( newTodo() ) ); 396 SLOT( newTodo() ) );
397 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 397 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
398 SLOT( newSubTodo( Todo * ) ) ); 398 SLOT( newSubTodo( Todo * ) ) );
399 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
400 SLOT( editTodo( Todo * ) ) ); 400 SLOT( editTodo( Todo * ) ) );
401 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 401 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
402 SLOT( showTodo( Todo *) ) ); 402 SLOT( showTodo( Todo *) ) );
403 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 403 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
404 SLOT( deleteTodo( Todo *) ) ); 404 SLOT( deleteTodo( Todo *) ) );
405 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 405 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
406 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 406 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
407 SLOT( purgeCompleted() ) ); 407 SLOT( purgeCompleted() ) );
408 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 408 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
409 SIGNAL( todoModified( Todo *, int ) ) ); 409 SIGNAL( todoModified( Todo *, int ) ) );
410 410
411 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
412 this, SLOT ( cloneIncidence( Incidence * ) ) ); 412 this, SLOT ( cloneIncidence( Incidence * ) ) );
413 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 413 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
414 this, SLOT (cancelIncidence( Incidence * ) ) ); 414 this, SLOT (cancelIncidence( Incidence * ) ) );
415 415
416 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
417 this, SLOT ( moveIncidence( Incidence * ) ) ); 417 this, SLOT ( moveIncidence( Incidence * ) ) );
418 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 418 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
419 this, SLOT ( beamIncidence( Incidence * ) ) ); 419 this, SLOT ( beamIncidence( Incidence * ) ) );
420 420
421 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 421 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
422 this, SLOT ( todo_unsub( Todo * ) ) ); 422 this, SLOT ( todo_unsub( Todo * ) ) );
423 423
424 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 424 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
425 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 425 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
426 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 426 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
427 SLOT( updateTodo( Todo *, int ) ) ); 427 SLOT( updateTodo( Todo *, int ) ) );
428 connect( this, SIGNAL( todoModified( Todo *, int )), this, 428 connect( this, SIGNAL( todoModified( Todo *, int )), this,
429 SLOT( changeTodoDisplay( Todo *, int ) ) ); 429 SLOT( changeTodoDisplay( Todo *, int ) ) );
430 430
431 431
432 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 432 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
433 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 433 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
434 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 434 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
435 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 435 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
436 436
437 437
438 438
439 439
440 440
441 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 441 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
442 SLOT(checkClipboard())); 442 SLOT(checkClipboard()));
443 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 443 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
444 SLOT( processTodoListSelection( Incidence * ) ) ); 444 SLOT( processTodoListSelection( Incidence * ) ) );
445 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 445 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
446 446
447 // kdDebug() << "CalendarView::CalendarView() done" << endl; 447 // kdDebug() << "CalendarView::CalendarView() done" << endl;
448 448
449 mDateFrame = new QVBox(0,0,WType_Popup); 449 mDateFrame = new QVBox(0,0,WType_Popup);
450 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 450 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
451 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 451 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
452 mDateFrame->setLineWidth(3); 452 mDateFrame->setLineWidth(3);
453 mDateFrame->hide(); 453 mDateFrame->hide();
454 mDateFrame->setCaption( i18n( "Pick a date to display")); 454 mDateFrame->setCaption( i18n( "Pick a date to display"));
455 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 455 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
456 456
457 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 457 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
458 458
459 mEventEditor = mDialogManager->getEventEditor(); 459 mEventEditor = mDialogManager->getEventEditor();
460 mTodoEditor = mDialogManager->getTodoEditor(); 460 mTodoEditor = mDialogManager->getTodoEditor();
461 461
462 mFlagEditDescription = false; 462 mFlagEditDescription = false;
463 463
464 mSuspendTimer = new QTimer( this ); 464 mSuspendTimer = new QTimer( this );
465 mAlarmTimer = new QTimer( this ); 465 mAlarmTimer = new QTimer( this );
466 mRecheckAlarmTimer = new QTimer( this ); 466 mRecheckAlarmTimer = new QTimer( this );
467 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 467 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
468 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 468 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
469 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 469 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
470 mAlarmDialog = new AlarmDialog( this ); 470 mAlarmDialog = new AlarmDialog( this );
471 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 471 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
472 mAlarmDialog->setServerNotification( false ); 472 mAlarmDialog->setServerNotification( false );
473 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 473 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
474 474
475 475
476#ifndef DESKTOP_VERSION 476#ifndef DESKTOP_VERSION
477//US listen for arriving address resultsets 477//US listen for arriving address resultsets
478 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 478 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
479 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 479 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
480#endif 480#endif
481 481
482} 482}
483 483
484 484
485CalendarView::~CalendarView() 485CalendarView::~CalendarView()
486{ 486{
487 // kdDebug() << "~CalendarView()" << endl; 487 // kdDebug() << "~CalendarView()" << endl;
488 //qDebug("CalendarView::~CalendarView() "); 488 //qDebug("CalendarView::~CalendarView() ");
489 delete mDialogManager; 489 delete mDialogManager;
490 delete mViewManager; 490 delete mViewManager;
491 delete mStorage; 491 delete mStorage;
492 delete mDateFrame ; 492 delete mDateFrame ;
493 delete beamDialog; 493 delete beamDialog;
494 //kdDebug() << "~CalendarView() done" << endl; 494 //kdDebug() << "~CalendarView() done" << endl;
495} 495}
496 496
497void CalendarView::showDay( QDate d ) 497void CalendarView::showDay( QDate d )
498{ 498{
499 dateNavigator()->selectDate( d ); 499 dateNavigator()->selectDate( d );
500 mViewManager->showWeekView(); 500 mViewManager->showWeekView();
501 dateNavigator()->selectDate( d ); 501 dateNavigator()->selectDate( d );
502} 502}
503void CalendarView::timerAlarm() 503void CalendarView::timerAlarm()
504{ 504{
505 //qDebug("CalendarView::timerAlarm() "); 505 //qDebug("CalendarView::timerAlarm() ");
506 computeAlarm(mAlarmNotification ); 506 computeAlarm(mAlarmNotification );
507} 507}
508 508
509void CalendarView::suspendAlarm() 509void CalendarView::suspendAlarm()
510{ 510{
511 //qDebug(" CalendarView::suspendAlarm() "); 511 //qDebug(" CalendarView::suspendAlarm() ");
512 computeAlarm(mSuspendAlarmNotification ); 512 computeAlarm(mSuspendAlarmNotification );
513 513
514} 514}
515 515
516void CalendarView::startAlarm( QString mess , QString filename) 516void CalendarView::startAlarm( QString mess , QString filename)
517{ 517{
518 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 518 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
519 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 519 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
520 520
521} 521}
522 522
523void CalendarView::checkNextTimerAlarm() 523void CalendarView::checkNextTimerAlarm()
524{ 524{
525 mCalendar->checkAlarmForIncidence( 0, true ); 525 mCalendar->checkAlarmForIncidence( 0, true );
526} 526}
527 527
528void CalendarView::computeAlarm( QString msg ) 528void CalendarView::computeAlarm( QString msg )
529{ 529{
530 530
531 QString mess = msg; 531 QString mess = msg;
532 QString mAlarmMessage = mess.mid( 9 ); 532 QString mAlarmMessage = mess.mid( 9 );
533 QString filename = MainWindow::resourcePath(); 533 QString filename = MainWindow::resourcePath();
534 filename += "koalarm.wav"; 534 filename += "koalarm.wav";
535 QString tempfilename; 535 QString tempfilename;
536 if ( mess.left( 13 ) == "suspend_alarm") { 536 if ( mess.left( 13 ) == "suspend_alarm") {
537 bool error = false; 537 bool error = false;
538 int len = mess.mid( 13 ).find("+++"); 538 int len = mess.mid( 13 ).find("+++");
539 if ( len < 2 ) 539 if ( len < 2 )
540 error = true; 540 error = true;
541 else { 541 else {
542 tempfilename = mess.mid( 13, len ); 542 tempfilename = mess.mid( 13, len );
543 if ( !QFile::exists( tempfilename ) ) 543 if ( !QFile::exists( tempfilename ) )
544 error = true; 544 error = true;
545 } 545 }
546 if ( ! error ) { 546 if ( ! error ) {
547 filename = tempfilename; 547 filename = tempfilename;
548 } 548 }
549 mAlarmMessage = mess.mid( 13+len+3 ); 549 mAlarmMessage = mess.mid( 13+len+3 );
550 //qDebug("suspend file %s ",tempfilename.latin1() ); 550 //qDebug("suspend file %s ",tempfilename.latin1() );
551 startAlarm( mAlarmMessage, filename); 551 startAlarm( mAlarmMessage, filename);
552 return; 552 return;
553 } 553 }
554 if ( mess.left( 11 ) == "timer_alarm") { 554 if ( mess.left( 11 ) == "timer_alarm") {
555 //mTimerTime = 0; 555 //mTimerTime = 0;
556 startAlarm( mess.mid( 11 ), filename ); 556 startAlarm( mess.mid( 11 ), filename );
557 return; 557 return;
558 } 558 }
559 if ( mess.left( 10 ) == "proc_alarm") { 559 if ( mess.left( 10 ) == "proc_alarm") {
560 bool error = false; 560 bool error = false;
561 int len = mess.mid( 10 ).find("+++"); 561 int len = mess.mid( 10 ).find("+++");
562 if ( len < 2 ) 562 if ( len < 2 )
563 error = true; 563 error = true;
564 else { 564 else {
565 tempfilename = mess.mid( 10, len ); 565 tempfilename = mess.mid( 10, len );
566 if ( !QFile::exists( tempfilename ) ) 566 if ( !QFile::exists( tempfilename ) )
567 error = true; 567 error = true;
568 } 568 }
569 if ( error ) { 569 if ( error ) {
570 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 570 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
571 mAlarmMessage += mess.mid( 10+len+3+9 ); 571 mAlarmMessage += mess.mid( 10+len+3+9 );
572 } else { 572 } else {
573 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 573 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
574 //qDebug("-----system command %s ",tempfilename.latin1() ); 574 //qDebug("-----system command %s ",tempfilename.latin1() );
575#ifndef _WIN32_ 575#ifndef _WIN32_
576 if ( vfork () == 0 ) { 576 if ( vfork () == 0 ) {
577 execl ( tempfilename.latin1(), 0 ); 577 execl ( tempfilename.latin1(), 0 );
578 return; 578 return;
579 } 579 }
580#else 580#else
581 QProcess* p = new QProcess(); 581 QProcess* p = new QProcess();
582 p->addArgument( tempfilename.latin1() ); 582 p->addArgument( tempfilename.latin1() );
583 p->start(); 583 p->start();
584 return; 584 return;
585#endif 585#endif
586 586
587 return; 587 return;
588 } 588 }
589 589
590 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 590 //qDebug("+++++++system command %s ",tempfilename.latin1() );
591 } 591 }
592 if ( mess.left( 11 ) == "audio_alarm") { 592 if ( mess.left( 11 ) == "audio_alarm") {
593 bool error = false; 593 bool error = false;
594 int len = mess.mid( 11 ).find("+++"); 594 int len = mess.mid( 11 ).find("+++");
595 if ( len < 2 ) 595 if ( len < 2 )
596 error = true; 596 error = true;
597 else { 597 else {
598 tempfilename = mess.mid( 11, len ); 598 tempfilename = mess.mid( 11, len );
599 if ( !QFile::exists( tempfilename ) ) 599 if ( !QFile::exists( tempfilename ) )
600 error = true; 600 error = true;
601 } 601 }
602 if ( ! error ) { 602 if ( ! error ) {
603 filename = tempfilename; 603 filename = tempfilename;
604 } 604 }
605 mAlarmMessage = mess.mid( 11+len+3+9 ); 605 mAlarmMessage = mess.mid( 11+len+3+9 );
606 //qDebug("audio file command %s ",tempfilename.latin1() ); 606 //qDebug("audio file command %s ",tempfilename.latin1() );
607 } 607 }
608 if ( mess.left( 9 ) == "cal_alarm") { 608 if ( mess.left( 9 ) == "cal_alarm") {
609 mAlarmMessage = mess.mid( 9 ) ; 609 mAlarmMessage = mess.mid( 9 ) ;
610 } 610 }
611 611
612 startAlarm( mAlarmMessage, filename ); 612 startAlarm( mAlarmMessage, filename );
613 613
614 614
615} 615}
616 616
617void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 617void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
618{ 618{
619 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 619 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
620 620
621 mSuspendAlarmNotification = noti; 621 mSuspendAlarmNotification = noti;
622 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 622 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
623 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 623 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
624 mSuspendTimer->start( ms , true ); 624 mSuspendTimer->start( ms , true );
625 625
626} 626}
627 627
628void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 628void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
629{ 629{
630 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 630 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
631 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 631 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
632#ifndef DESKTOP_VERSION 632#ifndef DESKTOP_VERSION
633 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 633 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
634#endif 634#endif
635 return; 635 return;
636 } 636 }
637 int maxSec; 637 int maxSec;
638 //maxSec = 5; //testing only 638 //maxSec = 5; //testing only
639 maxSec = 86400+3600; // one day+1hour 639 maxSec = 86400+3600; // one day+1hour
640 mAlarmNotification = noti; 640 mAlarmNotification = noti;
641 int sec = QDateTime::currentDateTime().secsTo( qdt ); 641 int sec = QDateTime::currentDateTime().secsTo( qdt );
642 if ( sec > maxSec ) { 642 if ( sec > maxSec ) {
643 mRecheckAlarmTimer->start( maxSec * 1000 ); 643 mRecheckAlarmTimer->start( maxSec * 1000 );
644 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 644 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
645 return; 645 return;
646 } else { 646 } else {
647 mRecheckAlarmTimer->stop(); 647 mRecheckAlarmTimer->stop();
648 } 648 }
649 //qDebug("Alarm timer started with secs: %d ", sec); 649 //qDebug("Alarm timer started with secs: %d ", sec);
650 mAlarmTimer->start( sec *1000 , true ); 650 mAlarmTimer->start( sec *1000 , true );
651 651
652} 652}
653// called by mRecheckAlarmTimer to get next alarm 653// called by mRecheckAlarmTimer to get next alarm
654// we need this, because a QTimer has only a max range of 25 days 654// we need this, because a QTimer has only a max range of 25 days
655void CalendarView::recheckTimerAlarm() 655void CalendarView::recheckTimerAlarm()
656{ 656{
657 mAlarmTimer->stop(); 657 mAlarmTimer->stop();
658 mRecheckAlarmTimer->stop(); 658 mRecheckAlarmTimer->stop();
659 mCalendar->checkAlarmForIncidence( 0, true ); 659 mCalendar->checkAlarmForIncidence( 0, true );
660} 660}
661void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 661void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
662{ 662{
663 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 663 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
664 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 664 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
665#ifndef DESKTOP_VERSION 665#ifndef DESKTOP_VERSION
666 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 666 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
667#endif 667#endif
668 return; 668 return;
669 } 669 }
670 mAlarmTimer->stop(); 670 mAlarmTimer->stop();
671} 671}
672void CalendarView::selectWeekNum ( int num ) 672void CalendarView::selectWeekNum ( int num )
673{ 673{
674 dateNavigator()->selectWeek( num ); 674 dateNavigator()->selectWeek( num );
675 mViewManager->showWeekView(); 675 mViewManager->showWeekView();
676} 676}
677KOViewManager *CalendarView::viewManager() 677KOViewManager *CalendarView::viewManager()
678{ 678{
679 return mViewManager; 679 return mViewManager;
680} 680}
681 681
682KODialogManager *CalendarView::dialogManager() 682KODialogManager *CalendarView::dialogManager()
683{ 683{
684 return mDialogManager; 684 return mDialogManager;
685} 685}
686 686
687QDate CalendarView::startDate() 687QDate CalendarView::startDate()
688{ 688{
689 DateList dates = mNavigator->selectedDates(); 689 DateList dates = mNavigator->selectedDates();
690 690
691 return dates.first(); 691 return dates.first();
692} 692}
693 693
694QDate CalendarView::endDate() 694QDate CalendarView::endDate()
695{ 695{
696 DateList dates = mNavigator->selectedDates(); 696 DateList dates = mNavigator->selectedDates();
697 697
698 return dates.last(); 698 return dates.last();
699} 699}
700 700
701 701
702void CalendarView::createPrinter() 702void CalendarView::createPrinter()
703{ 703{
704#ifndef KORG_NOPRINTER 704#ifndef KORG_NOPRINTER
705 if (!mCalPrinter) { 705 if (!mCalPrinter) {
706 mCalPrinter = new CalPrinter(this, mCalendar); 706 mCalPrinter = new CalPrinter(this, mCalendar);
707 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 707 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
708 } 708 }
709#endif 709#endif
710} 710}
711 711
712 712
713//KOPrefs::instance()->mWriteBackFile 713//KOPrefs::instance()->mWriteBackFile
714//KOPrefs::instance()->mWriteBackExistingOnly 714//KOPrefs::instance()->mWriteBackExistingOnly
715 715
716// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 716// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
717// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 717// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
718// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 718// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
719// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 719// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
720// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 720// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
721// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 721// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
722 722
723int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 723int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
724{ 724{
725 725
726 // 0 equal 726 // 0 equal
727 // 1 take local 727 // 1 take local
728 // 2 take remote 728 // 2 take remote
729 // 3 cancel 729 // 3 cancel
730 QDateTime lastSync = mLastCalendarSync; 730 QDateTime lastSync = mLastCalendarSync;
731 QDateTime localMod = local->lastModified(); 731 QDateTime localMod = local->lastModified();
732 QDateTime remoteMod = remote->lastModified(); 732 QDateTime remoteMod = remote->lastModified();
733 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 733 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
734 bool remCh, locCh; 734 bool remCh, locCh;
735 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 735 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
736 //if ( remCh ) 736 //if ( remCh )
737 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 737 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
738 locCh = ( localMod > mLastCalendarSync ); 738 locCh = ( localMod > mLastCalendarSync );
739 if ( !remCh && ! locCh ) { 739 if ( !remCh && ! locCh ) {
740 //qDebug("both not changed "); 740 //qDebug("both not changed ");
741 lastSync = localMod.addDays(1); 741 lastSync = localMod.addDays(1);
742 if ( mode <= SYNC_PREF_ASK ) 742 if ( mode <= SYNC_PREF_ASK )
743 return 0; 743 return 0;
744 } else { 744 } else {
745 if ( locCh ) { 745 if ( locCh ) {
746 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 746 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
747 lastSync = localMod.addDays( -1 ); 747 lastSync = localMod.addDays( -1 );
748 if ( !remCh ) 748 if ( !remCh )
749 remoteMod = ( lastSync.addDays( -1 ) ); 749 remoteMod = ( lastSync.addDays( -1 ) );
750 } else { 750 } else {
751 //qDebug(" not loc changed "); 751 //qDebug(" not loc changed ");
752 lastSync = localMod.addDays( 1 ); 752 lastSync = localMod.addDays( 1 );
753 if ( remCh ) 753 if ( remCh )
754 remoteMod =( lastSync.addDays( 1 ) ); 754 remoteMod =( lastSync.addDays( 1 ) );
755 755
756 } 756 }
757 } 757 }
758 full = true; 758 full = true;
759 if ( mode < SYNC_PREF_ASK ) 759 if ( mode < SYNC_PREF_ASK )
760 mode = SYNC_PREF_ASK; 760 mode = SYNC_PREF_ASK;
761 } else { 761 } else {
762 if ( localMod == remoteMod ) 762 if ( localMod == remoteMod )
763 // if ( local->revision() == remote->revision() ) 763 // if ( local->revision() == remote->revision() )
764 return 0; 764 return 0;
765 765
766 } 766 }
767 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 767 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
768 768
769 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 769 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
770 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 770 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
771 //full = true; //debug only 771 //full = true; //debug only
772 if ( full ) { 772 if ( full ) {
773 bool equ = false; 773 bool equ = false;
774 if ( local->type() == "Event" ) { 774 if ( local->type() == "Event" ) {
775 equ = (*((Event*) local) == *((Event*) remote)); 775 equ = (*((Event*) local) == *((Event*) remote));
776 } 776 }
777 else if ( local->type() =="Todo" ) 777 else if ( local->type() =="Todo" )
778 equ = (*((Todo*) local) == (*(Todo*) remote)); 778 equ = (*((Todo*) local) == (*(Todo*) remote));
779 else if ( local->type() =="Journal" ) 779 else if ( local->type() =="Journal" )
780 equ = (*((Journal*) local) == *((Journal*) remote)); 780 equ = (*((Journal*) local) == *((Journal*) remote));
781 if ( equ ) { 781 if ( equ ) {
782 //qDebug("equal "); 782 //qDebug("equal ");
783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 783 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 784 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
785 } 785 }
786 if ( mode < SYNC_PREF_FORCE_LOCAL ) 786 if ( mode < SYNC_PREF_FORCE_LOCAL )
787 return 0; 787 return 0;
788 788
789 }//else //debug only 789 }//else //debug only
790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 790 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
791 } 791 }
792 int result; 792 int result;
793 bool localIsNew; 793 bool localIsNew;
794 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 794 //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() );
795 795
796 if ( full && mode < SYNC_PREF_NEWEST ) 796 if ( full && mode < SYNC_PREF_NEWEST )
797 mode = SYNC_PREF_ASK; 797 mode = SYNC_PREF_ASK;
798 798
799 switch( mode ) { 799 switch( mode ) {
800 case SYNC_PREF_LOCAL: 800 case SYNC_PREF_LOCAL:
801 if ( lastSync > remoteMod ) 801 if ( lastSync > remoteMod )
802 return 1; 802 return 1;
803 if ( lastSync > localMod ) 803 if ( lastSync > localMod )
804 return 2; 804 return 2;
805 return 1; 805 return 1;
806 break; 806 break;
807 case SYNC_PREF_REMOTE: 807 case SYNC_PREF_REMOTE:
808 if ( lastSync > remoteMod ) 808 if ( lastSync > remoteMod )
809 return 1; 809 return 1;
810 if ( lastSync > localMod ) 810 if ( lastSync > localMod )
811 return 2; 811 return 2;
812 return 2; 812 return 2;
813 break; 813 break;
814 case SYNC_PREF_NEWEST: 814 case SYNC_PREF_NEWEST:
815 if ( localMod > remoteMod ) 815 if ( localMod > remoteMod )
816 return 1; 816 return 1;
817 else 817 else
818 return 2; 818 return 2;
819 break; 819 break;
820 case SYNC_PREF_ASK: 820 case SYNC_PREF_ASK:
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
822 if ( lastSync > remoteMod ) 822 if ( lastSync > remoteMod )
823 return 1; 823 return 1;
824 if ( lastSync > localMod ) 824 if ( lastSync > localMod )
825 return 2; 825 return 2;
826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 826 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
827 localIsNew = localMod >= remoteMod; 827 localIsNew = localMod >= remoteMod;
828 if ( localIsNew ) 828 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 1 ); 829 getEventViewerDialog()->setColorMode( 1 );
830 else 830 else
831 getEventViewerDialog()->setColorMode( 2 ); 831 getEventViewerDialog()->setColorMode( 2 );
832 getEventViewerDialog()->setIncidence(local); 832 getEventViewerDialog()->setIncidence(local);
833 if ( localIsNew ) 833 if ( localIsNew )
834 getEventViewerDialog()->setColorMode( 2 ); 834 getEventViewerDialog()->setColorMode( 2 );
835 else 835 else
836 getEventViewerDialog()->setColorMode( 1 ); 836 getEventViewerDialog()->setColorMode( 1 );
837 getEventViewerDialog()->addIncidence(remote); 837 getEventViewerDialog()->addIncidence(remote);
838 getEventViewerDialog()->setColorMode( 0 ); 838 getEventViewerDialog()->setColorMode( 0 );
839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 839 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 840 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
841 getEventViewerDialog()->showMe(); 841 getEventViewerDialog()->showMe();
842 result = getEventViewerDialog()->executeS( localIsNew ); 842 result = getEventViewerDialog()->executeS( localIsNew );
843 return result; 843 return result;
844 844
845 break; 845 break;
846 case SYNC_PREF_FORCE_LOCAL: 846 case SYNC_PREF_FORCE_LOCAL:
847 return 1; 847 return 1;
848 break; 848 break;
849 case SYNC_PREF_FORCE_REMOTE: 849 case SYNC_PREF_FORCE_REMOTE:
850 return 2; 850 return 2;
851 break; 851 break;
852 852
853 default: 853 default:
854 // SYNC_PREF_TAKE_BOTH not implemented 854 // SYNC_PREF_TAKE_BOTH not implemented
855 break; 855 break;
856 } 856 }
857 return 0; 857 return 0;
858} 858}
859Event* CalendarView::getLastSyncEvent() 859Event* CalendarView::getLastSyncEvent()
860{ 860{
861 Event* lse; 861 Event* lse;
862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
864 if (!lse) { 864 if (!lse) {
865 lse = new Event(); 865 lse = new Event();
866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
867 QString sum = ""; 867 QString sum = "";
868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
869 sum = "E: "; 869 sum = "E: ";
870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
871 lse->setDtStart( mLastCalendarSync ); 871 lse->setDtStart( mLastCalendarSync );
872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
873 lse->setCategories( i18n("SyncEvent") ); 873 lse->setCategories( i18n("SyncEvent") );
874 lse->setReadOnly( true ); 874 lse->setReadOnly( true );
875 mCalendar->addEvent( lse ); 875 mCalendar->addEvent( lse );
876 } 876 }
877 877
878 return lse; 878 return lse;
879 879
880} 880}
881 881
882// we check, if the to delete event has a id for a profile 882// we check, if the to delete event has a id for a profile
883// if yes, we set this id in the profile to delete 883// if yes, we set this id in the profile to delete
884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 884void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
885{ 885{
886 if ( lastSync.count() == 0 ) { 886 if ( lastSync.count() == 0 ) {
887 //qDebug(" lastSync.count() == 0"); 887 //qDebug(" lastSync.count() == 0");
888 return; 888 return;
889 } 889 }
890 if ( toDelete->type() == "Journal" ) 890 if ( toDelete->type() == "Journal" )
891 return; 891 return;
892 892
893 Event* eve = lastSync.first(); 893 Event* eve = lastSync.first();
894 894
895 while ( eve ) { 895 while ( eve ) {
896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 896 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
897 if ( !id.isEmpty() ) { 897 if ( !id.isEmpty() ) {
898 QString des = eve->description(); 898 QString des = eve->description();
899 QString pref = "e"; 899 QString pref = "e";
900 if ( toDelete->type() == "Todo" ) 900 if ( toDelete->type() == "Todo" )
901 pref = "t"; 901 pref = "t";
902 des += pref+ id + ","; 902 des += pref+ id + ",";
903 eve->setReadOnly( false ); 903 eve->setReadOnly( false );
904 eve->setDescription( des ); 904 eve->setDescription( des );
905 //qDebug("setdes %s ", des.latin1()); 905 //qDebug("setdes %s ", des.latin1());
906 eve->setReadOnly( true ); 906 eve->setReadOnly( true );
907 } 907 }
908 eve = lastSync.next(); 908 eve = lastSync.next();
909 } 909 }
910 910
911} 911}
912void CalendarView::checkExternalId( Incidence * inc ) 912void CalendarView::checkExternalId( Incidence * inc )
913{ 913{
914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 914 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
915 checkExternSyncEvent( lastSync, inc ); 915 checkExternSyncEvent( lastSync, inc );
916 916
917} 917}
918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 918bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
919{ 919{
920 bool syncOK = true; 920 bool syncOK = true;
921 int addedEvent = 0; 921 int addedEvent = 0;
922 int addedEventR = 0; 922 int addedEventR = 0;
923 int deletedEventR = 0; 923 int deletedEventR = 0;
924 int deletedEventL = 0; 924 int deletedEventL = 0;
925 int changedLocal = 0; 925 int changedLocal = 0;
926 int changedRemote = 0; 926 int changedRemote = 0;
927 int filteredIN = 0;
928 int filteredOUT = 0;
927 //QPtrList<Event> el = local->rawEvents(); 929 //QPtrList<Event> el = local->rawEvents();
928 Event* eventR; 930 Event* eventR;
929 QString uid; 931 QString uid;
930 int take; 932 int take;
931 Event* eventL; 933 Event* eventL;
932 Event* eventRSync; 934 Event* eventRSync;
933 Event* eventLSync; 935 Event* eventLSync;
934 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 936 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
935 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 937 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
936 bool fullDateRange = false; 938 bool fullDateRange = false;
937 local->resetTempSyncStat(); 939 local->resetTempSyncStat();
938 mLastCalendarSync = QDateTime::currentDateTime(); 940 mLastCalendarSync = QDateTime::currentDateTime();
939 if ( mSyncManager->syncWithDesktop() ) { 941 if ( mSyncManager->syncWithDesktop() ) {
940 remote->resetPilotStat(1); 942 remote->resetPilotStat(1);
941 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 943 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
942 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 944 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
943 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 945 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
944 } else { 946 } else {
945 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 947 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
946 } 948 }
947 } 949 }
948 QDateTime modifiedCalendar = mLastCalendarSync; 950 QDateTime modifiedCalendar = mLastCalendarSync;
949 eventLSync = getLastSyncEvent(); 951 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 952 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 953 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 954 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 955 remote->deleteEvent(eventR );
954 956
955 } else { 957 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 958 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
957 eventRSync = (Event*)eventLSync->clone(); 959 eventRSync = (Event*)eventLSync->clone();
958 } else { 960 } else {
959 fullDateRange = true; 961 fullDateRange = true;
960 eventRSync = new Event(); 962 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 963 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 964 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 965 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 966 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 967 eventRSync->setCategories( i18n("SyncEvent") );
966 } 968 }
967 } 969 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 970 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 971 fullDateRange = true;
970 972
971 if ( ! fullDateRange ) { 973 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 974 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 975
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 976 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 977 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 978 fullDateRange = true;
977 } 979 }
978 } 980 }
979 if ( mSyncManager->syncWithDesktop() ) { 981 if ( mSyncManager->syncWithDesktop() ) {
980 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 982 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
981 } 983 }
982 if ( fullDateRange ) 984 if ( fullDateRange )
983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 985 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
984 else 986 else
985 mLastCalendarSync = eventLSync->dtStart(); 987 mLastCalendarSync = eventLSync->dtStart();
986 // for resyncing if own file has changed 988 // for resyncing if own file has changed
987 if ( mCurrentSyncDevice == "deleteaftersync" ) { 989 if ( mCurrentSyncDevice == "deleteaftersync" ) {
988 mLastCalendarSync = loadedFileVersion; 990 mLastCalendarSync = loadedFileVersion;
989 //qDebug("setting mLastCalendarSync "); 991 //qDebug("setting mLastCalendarSync ");
990 } 992 }
991 //qDebug("*************************** "); 993 //qDebug("*************************** ");
992 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 994 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
993 QPtrList<Incidence> er = remote->rawIncidences(); 995 QPtrList<Incidence> er = remote->rawIncidences();
994 Incidence* inR = er.first(); 996 Incidence* inR = er.first();
995 Incidence* inL; 997 Incidence* inL;
996 QProgressBar bar( er.count(),0 ); 998 QProgressBar bar( er.count(),0 );
997 bar.setCaption (i18n("Syncing - close to abort!") ); 999 bar.setCaption (i18n("Syncing - close to abort!") );
998 1000
999 // ************** setting up filter ************* 1001 // ************** setting up filter *************
1000 CalFilter *filterIN = 0; 1002 CalFilter *filterIN = 0;
1001 CalFilter *filterOUT = 0; 1003 CalFilter *filterOUT = 0;
1002 CalFilter *filter = mFilters.first(); 1004 CalFilter *filter = mFilters.first();
1003 while(filter) { 1005 while(filter) {
1004 if ( filter->name() == mSyncManager->mFilterInCal ) 1006 if ( filter->name() == mSyncManager->mFilterInCal )
1005 filterIN = filter; 1007 filterIN = filter;
1006 if ( filter->name() == mSyncManager->mFilterOutCal ) 1008 if ( filter->name() == mSyncManager->mFilterOutCal )
1007 filterOUT = filter; 1009 filterOUT = filter;
1008 filter = mFilters.next(); 1010 filter = mFilters.next();
1009 } 1011 }
1010 int w = 300; 1012 int w = 300;
1011 if ( QApplication::desktop()->width() < 320 ) 1013 if ( QApplication::desktop()->width() < 320 )
1012 w = 220; 1014 w = 220;
1013 int h = bar.sizeHint().height() ; 1015 int h = bar.sizeHint().height() ;
1014 int dw = QApplication::desktop()->width(); 1016 int dw = QApplication::desktop()->width();
1015 int dh = QApplication::desktop()->height(); 1017 int dh = QApplication::desktop()->height();
1016 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1018 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1017 bar.show(); 1019 bar.show();
1018 int modulo = (er.count()/10)+1; 1020 int modulo = (er.count()/10)+1;
1019 int incCounter = 0; 1021 int incCounter = 0;
1020 while ( inR ) { 1022 while ( inR ) {
1021 if ( ! bar.isVisible() ) 1023 if ( ! bar.isVisible() )
1022 return false; 1024 return false;
1023 if ( incCounter % modulo == 0 ) 1025 if ( incCounter % modulo == 0 )
1024 bar.setProgress( incCounter ); 1026 bar.setProgress( incCounter );
1025 ++incCounter; 1027 ++incCounter;
1026 uid = inR->uid(); 1028 uid = inR->uid();
1027 bool skipIncidence = false; 1029 bool skipIncidence = false;
1028 if ( uid.left(15) == QString("last-syncEvent-") ) 1030 if ( uid.left(15) == QString("last-syncEvent-") )
1029 skipIncidence = true; 1031 skipIncidence = true;
1030 QString idS; 1032 QString idS;
1031 qApp->processEvents(); 1033 qApp->processEvents();
1032 if ( !skipIncidence ) { 1034 if ( !skipIncidence ) {
1033 inL = local->incidence( uid ); 1035 inL = local->incidence( uid );
1034 if ( inL ) { // maybe conflict - same uid in both calendars 1036 if ( inL ) { // maybe conflict - same uid in both calendars
1035 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1037 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1036 //qDebug("take %d %s ", take, inL->summary().latin1()); 1038 //qDebug("take %d %s ", take, inL->summary().latin1());
1037 if ( take == 3 ) 1039 if ( take == 3 )
1038 return false; 1040 return false;
1039 if ( take == 1 ) {// take local ********************** 1041 if ( take == 1 ) {// take local **********************
1040 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1042 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1041 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1043 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1042 else 1044 else
1043 idS = inR->IDStr(); 1045 idS = inR->IDStr();
1044 remote->deleteIncidence( inR ); 1046 remote->deleteIncidence( inR );
1045 inR = inL->clone(); 1047 inR = inL->clone();
1046 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1048 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1047 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1049 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1048 inR->setIDStr( idS ); 1050 inR->setIDStr( idS );
1049 remote->addIncidence( inR ); 1051 remote->addIncidence( inR );
1050 if ( mSyncManager->syncWithDesktop() ) 1052 if ( mSyncManager->syncWithDesktop() )
1051 inR->setPilotId( 2 ); 1053 inR->setPilotId( 2 );
1052 ++changedRemote; 1054 ++changedRemote;
1053 } else {// take remote ********************** 1055 } else {// take remote **********************
1054 idS = inL->IDStr(); 1056 idS = inL->IDStr();
1055 int pid = inL->pilotId(); 1057 int pid = inL->pilotId();
1056 local->deleteIncidence( inL ); 1058 local->deleteIncidence( inL );
1057 inL = inR->clone(); 1059 inL = inR->clone();
1058 if ( mSyncManager->syncWithDesktop() ) 1060 if ( mSyncManager->syncWithDesktop() )
1059 inL->setPilotId( pid ); 1061 inL->setPilotId( pid );
1060 inL->setIDStr( idS ); 1062 inL->setIDStr( idS );
1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1063 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1062 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1064 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1063 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1065 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1064 } 1066 }
1065 local->addIncidence( inL ); 1067 local->addIncidence( inL );
1066 ++changedLocal; 1068 ++changedLocal;
1067 } 1069 }
1068 } 1070 }
1069 } else { // no conflict ********** add or delete remote 1071 } else { // no conflict ********** add or delete remote
1070 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1072 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1071 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1073 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1072 QString des = eventLSync->description(); 1074 QString des = eventLSync->description();
1073 QString pref = "e"; 1075 QString pref = "e";
1074 if ( inR->type() == "Todo" ) 1076 if ( inR->type() == "Todo" )
1075 pref = "t"; 1077 pref = "t";
1076 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1078 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1077 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1079 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1078 //remote->deleteIncidence( inR ); 1080 //remote->deleteIncidence( inR );
1079 ++deletedEventR; 1081 ++deletedEventR;
1080 } else { 1082 } else {
1081 inR->setLastModified( modifiedCalendar ); 1083 inR->setLastModified( modifiedCalendar );
1082 inL = inR->clone(); 1084 inL = inR->clone();
1083 inL->setIDStr( ":" ); 1085 inL->setIDStr( ":" );
1084 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1086 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1085 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1087 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1086 local->addIncidence( inL ); 1088 local->addIncidence( inL );
1087 ++addedEvent; 1089 ++addedEvent;
1088 1090
1089 } 1091 }
1090 } else { 1092 } else {
1091 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1093 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1092 inR->setLastModified( modifiedCalendar ); 1094 inR->setLastModified( modifiedCalendar );
1093 inL = inR->clone(); 1095 inL = inR->clone();
1094 inL->setIDStr( ":" ); 1096 inL->setIDStr( ":" );
1095 local->addIncidence( inL ); 1097 local->addIncidence( inL );
1096 ++addedEvent; 1098 ++addedEvent;
1097 1099
1098 } else { 1100 } else {
1099 checkExternSyncEvent(eventRSyncSharp, inR); 1101 checkExternSyncEvent(eventRSyncSharp, inR);
1100 remote->deleteIncidence( inR ); 1102 remote->deleteIncidence( inR );
1101 ++deletedEventR; 1103 ++deletedEventR;
1102 } 1104 }
1103 } 1105 }
1106 } else {
1107 ++filteredIN;
1104 } 1108 }
1105 } 1109 }
1106 } 1110 }
1107 inR = er.next(); 1111 inR = er.next();
1108 } 1112 }
1109 QPtrList<Incidence> el = local->rawIncidences(); 1113 QPtrList<Incidence> el = local->rawIncidences();
1110 inL = el.first(); 1114 inL = el.first();
1111 modulo = (el.count()/10)+1; 1115 modulo = (el.count()/10)+1;
1112 bar.setCaption (i18n("Add / remove events") ); 1116 bar.setCaption (i18n("Add / remove events") );
1113 bar.setTotalSteps ( el.count() ) ; 1117 bar.setTotalSteps ( el.count() ) ;
1114 bar.show(); 1118 bar.show();
1115 incCounter = 0; 1119 incCounter = 0;
1116 1120
1117 while ( inL ) { 1121 while ( inL ) {
1118 1122
1119 qApp->processEvents(); 1123 qApp->processEvents();
1120 if ( ! bar.isVisible() ) 1124 if ( ! bar.isVisible() )
1121 return false; 1125 return false;
1122 if ( incCounter % modulo == 0 ) 1126 if ( incCounter % modulo == 0 )
1123 bar.setProgress( incCounter ); 1127 bar.setProgress( incCounter );
1124 ++incCounter; 1128 ++incCounter;
1125 uid = inL->uid(); 1129 uid = inL->uid();
1126 bool skipIncidence = false; 1130 bool skipIncidence = false;
1127 if ( uid.left(15) == QString("last-syncEvent-") ) 1131 if ( uid.left(15) == QString("last-syncEvent-") )
1128 skipIncidence = true; 1132 skipIncidence = true;
1129 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1133 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1130 skipIncidence = true; 1134 skipIncidence = true;
1131 if ( filterOUT && ! filterOUT->filterCalendarItem( inL ) ){
1132 skipIncidence = true;
1133 }
1134 if ( !skipIncidence ) { 1135 if ( !skipIncidence ) {
1135 inR = remote->incidence( uid ); 1136 inR = remote->incidence( uid );
1136 if ( ! inR ) { // no conflict ********** add or delete local 1137 if ( ! inR ) {
1137 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1138 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1138 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1139 // no conflict ********** add or delete local
1139 checkExternSyncEvent(eventLSyncSharp, inL); 1140 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1140 local->deleteIncidence( inL ); 1141 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1141 ++deletedEventL; 1142 checkExternSyncEvent(eventLSyncSharp, inL);
1142 } else { 1143 local->deleteIncidence( inL );
1143 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1144 ++deletedEventL;
1144 inL->removeID(mCurrentSyncDevice ); 1145 } else {
1145 ++addedEventR; 1146 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1146 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1147 inL->removeID(mCurrentSyncDevice );
1147 inL->setLastModified( modifiedCalendar ); 1148 ++addedEventR;
1148 inR = inL->clone(); 1149 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1149 inR->setIDStr( ":" ); 1150 inL->setLastModified( modifiedCalendar );
1150 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1151 inR = inL->clone();
1151 remote->addIncidence( inR ); 1152 inR->setIDStr( ":" );
1153 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1154 remote->addIncidence( inR );
1155 }
1152 } 1156 }
1153 }
1154 } else {
1155 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1156 checkExternSyncEvent(eventLSyncSharp, inL);
1157 local->deleteIncidence( inL );
1158 ++deletedEventL;
1159 } else { 1157 } else {
1160 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1158 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1161 ++addedEventR; 1159 checkExternSyncEvent(eventLSyncSharp, inL);
1162 inL->setLastModified( modifiedCalendar ); 1160 local->deleteIncidence( inL );
1163 inR = inL->clone(); 1161 ++deletedEventL;
1164 inR->setIDStr( ":" ); 1162 } else {
1165 remote->addIncidence( inR ); 1163 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1164 ++addedEventR;
1165 inL->setLastModified( modifiedCalendar );
1166 inR = inL->clone();
1167 inR->setIDStr( ":" );
1168 remote->addIncidence( inR );
1169 }
1166 } 1170 }
1167 } 1171 }
1172 } else {
1173 ++filteredOUT;
1168 } 1174 }
1169 } 1175 }
1170 } 1176 }
1171 inL = el.next(); 1177 inL = el.next();
1172 } 1178 }
1173 int delFut = 0; 1179 int delFut = 0;
1174 int remRem = 0; 1180 int remRem = 0;
1175 if ( mSyncManager->mWriteBackInFuture ) { 1181 if ( mSyncManager->mWriteBackInFuture ) {
1176 er = remote->rawIncidences(); 1182 er = remote->rawIncidences();
1177 remRem = er.count(); 1183 remRem = er.count();
1178 inR = er.first(); 1184 inR = er.first();
1179 QDateTime dt; 1185 QDateTime dt;
1180 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1186 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1181 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1187 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1182 while ( inR ) { 1188 while ( inR ) {
1183 if ( inR->type() == "Todo" ) { 1189 if ( inR->type() == "Todo" ) {
1184 Todo * t = (Todo*)inR; 1190 Todo * t = (Todo*)inR;
1185 if ( t->hasDueDate() ) 1191 if ( t->hasDueDate() )
1186 dt = t->dtDue(); 1192 dt = t->dtDue();
1187 else 1193 else
1188 dt = cur.addSecs( 62 ); 1194 dt = cur.addSecs( 62 );
1189 } 1195 }
1190 else if (inR->type() == "Event" ) { 1196 else if (inR->type() == "Event" ) {
1191 bool ok; 1197 bool ok;
1192 dt = inR->getNextOccurence( cur, &ok ); 1198 dt = inR->getNextOccurence( cur, &ok );
1193 if ( !ok ) 1199 if ( !ok )
1194 dt = cur.addSecs( -62 ); 1200 dt = cur.addSecs( -62 );
1195 } 1201 }
1196 else 1202 else
1197 dt = inR->dtStart(); 1203 dt = inR->dtStart();
1198 if ( dt < cur || dt > end ) { 1204 if ( dt < cur || dt > end ) {
1199 remote->deleteIncidence( inR ); 1205 remote->deleteIncidence( inR );
1200 ++delFut; 1206 ++delFut;
1201 } 1207 }
1202 inR = er.next(); 1208 inR = er.next();
1203 } 1209 }
1204 } 1210 }
1205 bar.hide(); 1211 bar.hide();
1206 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1212 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1207 eventLSync->setReadOnly( false ); 1213 eventLSync->setReadOnly( false );
1208 eventLSync->setDtStart( mLastCalendarSync ); 1214 eventLSync->setDtStart( mLastCalendarSync );
1209 eventRSync->setDtStart( mLastCalendarSync ); 1215 eventRSync->setDtStart( mLastCalendarSync );
1210 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1216 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1211 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1217 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1212 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1218 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1213 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1219 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1214 eventLSync->setReadOnly( true ); 1220 eventLSync->setReadOnly( true );
1215 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1221 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1216 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1222 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1217 remote->addEvent( eventRSync ); 1223 remote->addEvent( eventRSync );
1218 else 1224 else
1219 delete eventRSync; 1225 delete eventRSync;
1220 QString mes; 1226 QString mes;
1221 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 ); 1227 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1222 QString delmess; 1228 QString delmess;
1223 if ( delFut ) { 1229 if ( delFut ) {
1224 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1230 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1225 mes += delmess; 1231 mes += delmess;
1226 } 1232 }
1227 mes = i18n("Local calendar changed!\n") +mes; 1233 mes = i18n("Local calendar changed!\n") +mes;
1228 mCalendar->checkAlarmForIncidence( 0, true ); 1234 mCalendar->checkAlarmForIncidence( 0, true );
1229 qDebug( mes ); 1235 qDebug( mes );
1230 if ( mSyncManager->mShowSyncSummary ) { 1236 if ( mSyncManager->mShowSyncSummary ) {
1231 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1237 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1232 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1238 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1233 qDebug("cancelled "); 1239 qDebug("cancelled ");
1234 return false; 1240 return false;
1235 } 1241 }
1236 } 1242 }
1237 return syncOK; 1243 return syncOK;
1238} 1244}
1239 1245
1240void CalendarView::setSyncDevice( QString s ) 1246void CalendarView::setSyncDevice( QString s )
1241{ 1247{
1242 mCurrentSyncDevice= s; 1248 mCurrentSyncDevice= s;
1243} 1249}
1244void CalendarView::setSyncName( QString s ) 1250void CalendarView::setSyncName( QString s )
1245{ 1251{
1246 mCurrentSyncName= s; 1252 mCurrentSyncName= s;
1247} 1253}
1248bool CalendarView::syncCalendar(QString filename, int mode) 1254bool CalendarView::syncCalendar(QString filename, int mode)
1249{ 1255{
1250 //qDebug("syncCalendar %s ", filename.latin1()); 1256 //qDebug("syncCalendar %s ", filename.latin1());
1251 mGlobalSyncMode = SYNC_MODE_NORMAL; 1257 mGlobalSyncMode = SYNC_MODE_NORMAL;
1252 CalendarLocal* calendar = new CalendarLocal(); 1258 CalendarLocal* calendar = new CalendarLocal();
1253 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1259 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1254 FileStorage* storage = new FileStorage( calendar ); 1260 FileStorage* storage = new FileStorage( calendar );
1255 bool syncOK = false; 1261 bool syncOK = false;
1256 storage->setFileName( filename ); 1262 storage->setFileName( filename );
1257 // qDebug("loading ... "); 1263 // qDebug("loading ... ");
1258 if ( storage->load() ) { 1264 if ( storage->load() ) {
1259 getEventViewerDialog()->setSyncMode( true ); 1265 getEventViewerDialog()->setSyncMode( true );
1260 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1266 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1261 getEventViewerDialog()->setSyncMode( false ); 1267 getEventViewerDialog()->setSyncMode( false );
1262 if ( syncOK ) { 1268 if ( syncOK ) {
1263 if ( mSyncManager->mWriteBackFile ) 1269 if ( mSyncManager->mWriteBackFile )
1264 { 1270 {
1265 storage->setSaveFormat( new ICalFormat() ); 1271 storage->setSaveFormat( new ICalFormat() );
1266 storage->save(); 1272 storage->save();
1267 } 1273 }
1268 } 1274 }
1269 setModified( true ); 1275 setModified( true );
1270 } 1276 }
1271 delete storage; 1277 delete storage;
1272 delete calendar; 1278 delete calendar;
1273 if ( syncOK ) 1279 if ( syncOK )
1274 updateView(); 1280 updateView();
1275 return syncOK; 1281 return syncOK;
1276} 1282}
1277 1283
1278void CalendarView::syncExternal( int mode ) 1284void CalendarView::syncExternal( int mode )
1279{ 1285{
1280 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1286 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1281 1287
1282 qApp->processEvents(); 1288 qApp->processEvents();
1283 CalendarLocal* calendar = new CalendarLocal(); 1289 CalendarLocal* calendar = new CalendarLocal();
1284 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1290 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1285 bool syncOK = false; 1291 bool syncOK = false;
1286 bool loadSuccess = false; 1292 bool loadSuccess = false;
1287 PhoneFormat* phoneFormat = 0; 1293 PhoneFormat* phoneFormat = 0;
1288 emit tempDisableBR(true); 1294 emit tempDisableBR(true);
1289#ifndef DESKTOP_VERSION 1295#ifndef DESKTOP_VERSION
1290 SharpFormat* sharpFormat = 0; 1296 SharpFormat* sharpFormat = 0;
1291 if ( mode == 0 ) { // sharp 1297 if ( mode == 0 ) { // sharp
1292 sharpFormat = new SharpFormat () ; 1298 sharpFormat = new SharpFormat () ;
1293 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1299 loadSuccess = sharpFormat->load( calendar, mCalendar );
1294 1300
1295 } else 1301 } else
1296#endif 1302#endif
1297 if ( mode == 1 ) { // phone 1303 if ( mode == 1 ) { // phone
1298 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1304 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1299 mSyncManager->mPhoneDevice, 1305 mSyncManager->mPhoneDevice,
1300 mSyncManager->mPhoneConnection, 1306 mSyncManager->mPhoneConnection,
1301 mSyncManager->mPhoneModel); 1307 mSyncManager->mPhoneModel);
1302 loadSuccess = phoneFormat->load( calendar,mCalendar); 1308 loadSuccess = phoneFormat->load( calendar,mCalendar);
1303 1309
1304 } else { 1310 } else {
1305 emit tempDisableBR(false); 1311 emit tempDisableBR(false);
1306 return; 1312 return;
1307 } 1313 }
1308 if ( loadSuccess ) { 1314 if ( loadSuccess ) {
1309 getEventViewerDialog()->setSyncMode( true ); 1315 getEventViewerDialog()->setSyncMode( true );
1310 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1316 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1311 getEventViewerDialog()->setSyncMode( false ); 1317 getEventViewerDialog()->setSyncMode( false );
1312 qApp->processEvents(); 1318 qApp->processEvents();
1313 if ( syncOK ) { 1319 if ( syncOK ) {
1314 if ( mSyncManager->mWriteBackFile ) 1320 if ( mSyncManager->mWriteBackFile )
1315 { 1321 {
1316 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1322 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1317 Incidence* inc = iL.first(); 1323 Incidence* inc = iL.first();
1318 if ( phoneFormat ) { 1324 if ( phoneFormat ) {
1319 while ( inc ) { 1325 while ( inc ) {
1320 inc->removeID(mCurrentSyncDevice); 1326 inc->removeID(mCurrentSyncDevice);
1321 inc = iL.next(); 1327 inc = iL.next();
1322 } 1328 }
1323 } 1329 }
1324#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1325 if ( sharpFormat ) 1331 if ( sharpFormat )
1326 sharpFormat->save(calendar); 1332 sharpFormat->save(calendar);
1327#endif 1333#endif
1328 if ( phoneFormat ) 1334 if ( phoneFormat )
1329 phoneFormat->save(calendar); 1335 phoneFormat->save(calendar);
1330 iL = calendar->rawIncidences(); 1336 iL = calendar->rawIncidences();
1331 inc = iL.first(); 1337 inc = iL.first();
1332 Incidence* loc; 1338 Incidence* loc;
1333 while ( inc ) { 1339 while ( inc ) {
1334 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1340 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1335 loc = mCalendar->incidence(inc->uid() ); 1341 loc = mCalendar->incidence(inc->uid() );
1336 if ( loc ) { 1342 if ( loc ) {
1337 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1343 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1338 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1344 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1339 } 1345 }
1340 } 1346 }
1341 inc = iL.next(); 1347 inc = iL.next();
1342 } 1348 }
1343 Incidence* lse = getLastSyncEvent(); 1349 Incidence* lse = getLastSyncEvent();
1344 if ( lse ) { 1350 if ( lse ) {
1345 lse->setReadOnly( false ); 1351 lse->setReadOnly( false );
1346 lse->setDescription( "" ); 1352 lse->setDescription( "" );
1347 lse->setReadOnly( true ); 1353 lse->setReadOnly( true );
1348 } 1354 }
1349 } 1355 }
1350 } else { 1356 } else {
1351 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1357 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1352 } 1358 }
1353 setModified( true ); 1359 setModified( true );
1354 } else { 1360 } else {
1355 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1361 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1356 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1362 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1357 question, i18n("Ok")) ; 1363 question, i18n("Ok")) ;
1358 1364
1359 } 1365 }
1360 delete calendar; 1366 delete calendar;
1361 updateView(); 1367 updateView();
1362 emit tempDisableBR(false); 1368 emit tempDisableBR(false);
1363 return ;//syncOK; 1369 return ;//syncOK;
1364 1370
1365} 1371}
1366 1372
1367bool CalendarView::importBday() 1373bool CalendarView::importBday()
1368{ 1374{
1369#ifndef KORG_NOKABC 1375#ifndef KORG_NOKABC
1370 1376
1371#ifdef DESKTOP_VERSION 1377#ifdef DESKTOP_VERSION
1372 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1378 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1373 KABC::AddressBook::Iterator it; 1379 KABC::AddressBook::Iterator it;
1374 int count = 0; 1380 int count = 0;
1375 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1381 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1376 ++count; 1382 ++count;
1377 } 1383 }
1378 QProgressBar bar(count,0 ); 1384 QProgressBar bar(count,0 );
1379 int w = 300; 1385 int w = 300;
1380 if ( QApplication::desktop()->width() < 320 ) 1386 if ( QApplication::desktop()->width() < 320 )
1381 w = 220; 1387 w = 220;
1382 int h = bar.sizeHint().height() ; 1388 int h = bar.sizeHint().height() ;
1383 int dw = QApplication::desktop()->width(); 1389 int dw = QApplication::desktop()->width();
1384 int dh = QApplication::desktop()->height(); 1390 int dh = QApplication::desktop()->height();
1385 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1391 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1386 bar.show(); 1392 bar.show();
1387 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1393 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1388 qApp->processEvents(); 1394 qApp->processEvents();
1389 count = 0; 1395 count = 0;
1390 int addCount = 0; 1396 int addCount = 0;
1391 KCal::Attendee* a = 0; 1397 KCal::Attendee* a = 0;
1392 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1398 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1393 if ( ! bar.isVisible() ) 1399 if ( ! bar.isVisible() )
1394 return false; 1400 return false;
1395 bar.setProgress( count++ ); 1401 bar.setProgress( count++ );
1396 qApp->processEvents(); 1402 qApp->processEvents();
1397 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1403 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1398 if ( (*it).birthday().date().isValid() ){ 1404 if ( (*it).birthday().date().isValid() ){
1399 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1405 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1400 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1406 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1401 ++addCount; 1407 ++addCount;
1402 } 1408 }
1403 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1409 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1404 if ( anni.isValid() ){ 1410 if ( anni.isValid() ){
1405 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1411 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1406 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1412 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1407 ++addCount; 1413 ++addCount;
1408 } 1414 }
1409 } 1415 }
1410 updateView(); 1416 updateView();
1411 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1417 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1412#else //DESKTOP_VERSION 1418#else //DESKTOP_VERSION
1413 1419
1414 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1420 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1415 // the result should now arrive through method insertBirthdays 1421 // the result should now arrive through method insertBirthdays
1416 1422
1417#endif //DESKTOP_VERSION 1423#endif //DESKTOP_VERSION
1418 1424
1419#endif //KORG_NOKABC 1425#endif //KORG_NOKABC
1420 1426
1421 1427
1422 return true; 1428 return true;
1423} 1429}
1424 1430
1425// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1431// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1426void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1432void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1427 const QStringList& anniversaryList, const QStringList& realNameList, 1433 const QStringList& anniversaryList, const QStringList& realNameList,
1428 const QStringList& emailList, const QStringList& assembledNameList, 1434 const QStringList& emailList, const QStringList& assembledNameList,
1429 const QStringList& uidList) 1435 const QStringList& uidList)
1430{ 1436{
1431 qDebug("CalendarView::insertBirthdays"); 1437 qDebug("CalendarView::insertBirthdays");
1432 if (uid == this->name()) 1438 if (uid == this->name())
1433 { 1439 {
1434 int count = birthdayList.count(); 1440 int count = birthdayList.count();
1435 int addCount = 0; 1441 int addCount = 0;
1436 KCal::Attendee* a = 0; 1442 KCal::Attendee* a = 0;
1437 1443
1438 qDebug("CalView 1 %i", count); 1444 qDebug("CalView 1 %i", count);
1439 1445
1440 QProgressBar bar(count,0 ); 1446 QProgressBar bar(count,0 );
1441 int w = 300; 1447 int w = 300;
1442 if ( QApplication::desktop()->width() < 320 ) 1448 if ( QApplication::desktop()->width() < 320 )
1443 w = 220; 1449 w = 220;
1444 int h = bar.sizeHint().height() ; 1450 int h = bar.sizeHint().height() ;
1445 int dw = QApplication::desktop()->width(); 1451 int dw = QApplication::desktop()->width();
1446 int dh = QApplication::desktop()->height(); 1452 int dh = QApplication::desktop()->height();
1447 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1453 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1448 bar.show(); 1454 bar.show();
1449 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1455 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1450 qApp->processEvents(); 1456 qApp->processEvents();
1451 1457
1452 QDate birthday; 1458 QDate birthday;
1453 QDate anniversary; 1459 QDate anniversary;
1454 QString realName; 1460 QString realName;
1455 QString email; 1461 QString email;
1456 QString assembledName; 1462 QString assembledName;
1457 QString uid; 1463 QString uid;
1458 bool ok = true; 1464 bool ok = true;
1459 for ( int i = 0; i < count; i++) 1465 for ( int i = 0; i < count; i++)
1460 { 1466 {
1461 if ( ! bar.isVisible() ) 1467 if ( ! bar.isVisible() )
1462 return; 1468 return;
1463 bar.setProgress( i ); 1469 bar.setProgress( i );
1464 qApp->processEvents(); 1470 qApp->processEvents();
1465 1471
1466 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1472 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1467 if (!ok) { 1473 if (!ok) {
1468 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1474 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1469 } 1475 }
1470 1476
1471 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1477 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1472 if (!ok) { 1478 if (!ok) {
1473 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1479 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1474 } 1480 }
1475 realName = realNameList[i]; 1481 realName = realNameList[i];
1476 email = emailList[i]; 1482 email = emailList[i];
1477 assembledName = assembledNameList[i]; 1483 assembledName = assembledNameList[i];
1478 uid = uidList[i]; 1484 uid = uidList[i];
1479 //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() ); 1485 //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() );
1480 1486
1481 if ( birthday.isValid() ){ 1487 if ( birthday.isValid() ){
1482 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1488 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1483 KCal::Attendee::ReqParticipant,uid) ; 1489 KCal::Attendee::ReqParticipant,uid) ;
1484 if ( addAnniversary( birthday, assembledName, a, true ) ) 1490 if ( addAnniversary( birthday, assembledName, a, true ) )
1485 ++addCount; 1491 ++addCount;
1486 } 1492 }
1487 1493
1488 if ( anniversary.isValid() ){ 1494 if ( anniversary.isValid() ){
1489 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1490 KCal::Attendee::ReqParticipant,uid) ; 1496 KCal::Attendee::ReqParticipant,uid) ;
1491 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1497 if ( addAnniversary( anniversary, assembledName, a, false ) )
1492 ++addCount; 1498 ++addCount;
1493 } 1499 }
1494 } 1500 }
1495 1501
1496 updateView(); 1502 updateView();
1497 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1503 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1498 1504
1499 } 1505 }
1500 1506
1501} 1507}
1502 1508
1503 1509
1504 1510
1505bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1511bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1506{ 1512{
1507 //qDebug("addAnni "); 1513 //qDebug("addAnni ");
1508 Event * ev = new Event(); 1514 Event * ev = new Event();
1509 if ( a ) { 1515 if ( a ) {
1510 ev->addAttendee( a ); 1516 ev->addAttendee( a );
1511 } 1517 }
1512 QString kind; 1518 QString kind;
1513 if ( birthday ) 1519 if ( birthday )
1514 kind = i18n( "Birthday" ); 1520 kind = i18n( "Birthday" );
1515 else 1521 else
1516 kind = i18n( "Anniversary" ); 1522 kind = i18n( "Anniversary" );
1517 ev->setSummary( name + " - " + kind ); 1523 ev->setSummary( name + " - " + kind );
1518 ev->setOrganizer(a->email()); 1524 ev->setOrganizer(a->email());
1519 ev->setCategories( kind ); 1525 ev->setCategories( kind );
1520 ev->setDtStart( QDateTime(date) ); 1526 ev->setDtStart( QDateTime(date) );
1521 ev->setDtEnd( QDateTime(date) ); 1527 ev->setDtEnd( QDateTime(date) );
1522 ev->setFloats( true ); 1528 ev->setFloats( true );
1523 Recurrence * rec = ev->recurrence(); 1529 Recurrence * rec = ev->recurrence();
1524 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1530 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1525 rec->addYearlyNum( date.month() ); 1531 rec->addYearlyNum( date.month() );
1526 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1532 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1527 delete ev; 1533 delete ev;
1528 return false; 1534 return false;
1529 } 1535 }
1530 return true; 1536 return true;
1531 1537
1532} 1538}
1533bool CalendarView::importQtopia( const QString &categories, 1539bool CalendarView::importQtopia( const QString &categories,
1534 const QString &datebook, 1540 const QString &datebook,
1535 const QString &todolist ) 1541 const QString &todolist )
1536{ 1542{
1537 1543
1538 QtopiaFormat qtopiaFormat; 1544 QtopiaFormat qtopiaFormat;
1539 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1545 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1540 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1546 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1541 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1547 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1542 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1548 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1543 1549
1544 updateView(); 1550 updateView();
1545 return true; 1551 return true;
1546 1552
1547#if 0 1553#if 0
1548 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1554 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1549 mCurrentSyncDevice = "qtopia-XML"; 1555 mCurrentSyncDevice = "qtopia-XML";
1550 if ( mSyncManager->mAskForPreferences ) 1556 if ( mSyncManager->mAskForPreferences )
1551 edit_sync_options(); 1557 edit_sync_options();
1552 qApp->processEvents(); 1558 qApp->processEvents();
1553 CalendarLocal* calendar = new CalendarLocal(); 1559 CalendarLocal* calendar = new CalendarLocal();
1554 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1560 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1555 bool syncOK = false; 1561 bool syncOK = false;
1556 QtopiaFormat qtopiaFormat; 1562 QtopiaFormat qtopiaFormat;
1557 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1563 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1558 bool loadOk = true; 1564 bool loadOk = true;
1559 if ( !categories.isEmpty() ) 1565 if ( !categories.isEmpty() )
1560 loadOk = qtopiaFormat.load( calendar, categories ); 1566 loadOk = qtopiaFormat.load( calendar, categories );
1561 if ( loadOk && !datebook.isEmpty() ) 1567 if ( loadOk && !datebook.isEmpty() )
1562 loadOk = qtopiaFormat.load( calendar, datebook ); 1568 loadOk = qtopiaFormat.load( calendar, datebook );
1563 if ( loadOk && !todolist.isEmpty() ) 1569 if ( loadOk && !todolist.isEmpty() )
1564 loadOk = qtopiaFormat.load( calendar, todolist ); 1570 loadOk = qtopiaFormat.load( calendar, todolist );
1565 1571
1566 if ( loadOk ) { 1572 if ( loadOk ) {
1567 getEventViewerDialog()->setSyncMode( true ); 1573 getEventViewerDialog()->setSyncMode( true );
1568 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1574 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1569 getEventViewerDialog()->setSyncMode( false ); 1575 getEventViewerDialog()->setSyncMode( false );
1570 qApp->processEvents(); 1576 qApp->processEvents();
1571 if ( syncOK ) { 1577 if ( syncOK ) {
1572 if ( mSyncManager->mWriteBackFile ) 1578 if ( mSyncManager->mWriteBackFile )
1573 { 1579 {
1574 // write back XML file 1580 // write back XML file
1575 1581
1576 } 1582 }
1577 setModified( true ); 1583 setModified( true );
1578 } 1584 }
1579 } else { 1585 } else {
1580 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1586 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1581 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1587 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1582 question, i18n("Ok")) ; 1588 question, i18n("Ok")) ;
1583 } 1589 }
1584 delete calendar; 1590 delete calendar;
1585 updateView(); 1591 updateView();
1586 return syncOK; 1592 return syncOK;
1587 1593
1588 1594
1589#endif 1595#endif
1590 1596
1591} 1597}
1592 1598
1593void CalendarView::setSyncEventsReadOnly() 1599void CalendarView::setSyncEventsReadOnly()
1594{ 1600{
1595 Event * ev; 1601 Event * ev;
1596 QPtrList<Event> eL = mCalendar->rawEvents(); 1602 QPtrList<Event> eL = mCalendar->rawEvents();
1597 ev = eL.first(); 1603 ev = eL.first();
1598 while ( ev ) { 1604 while ( ev ) {
1599 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1605 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1600 ev->setReadOnly( true ); 1606 ev->setReadOnly( true );
1601 ev = eL.next(); 1607 ev = eL.next();
1602 } 1608 }
1603} 1609}
1604bool CalendarView::openCalendar(QString filename, bool merge) 1610bool CalendarView::openCalendar(QString filename, bool merge)
1605{ 1611{
1606 1612
1607 if (filename.isEmpty()) { 1613 if (filename.isEmpty()) {
1608 return false; 1614 return false;
1609 } 1615 }
1610 1616
1611 if (!QFile::exists(filename)) { 1617 if (!QFile::exists(filename)) {
1612 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1618 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1613 return false; 1619 return false;
1614 } 1620 }
1615 1621
1616 globalFlagBlockAgenda = 1; 1622 globalFlagBlockAgenda = 1;
1617 if (!merge) mCalendar->close(); 1623 if (!merge) mCalendar->close();
1618 1624
1619 mStorage->setFileName( filename ); 1625 mStorage->setFileName( filename );
1620 1626
1621 if ( mStorage->load() ) { 1627 if ( mStorage->load() ) {
1622 if ( merge ) ;//setModified( true ); 1628 if ( merge ) ;//setModified( true );
1623 else { 1629 else {
1624 //setModified( true ); 1630 //setModified( true );
1625 mViewManager->setDocumentId( filename ); 1631 mViewManager->setDocumentId( filename );
1626 mDialogManager->setDocumentId( filename ); 1632 mDialogManager->setDocumentId( filename );
1627 mTodoList->setDocumentId( filename ); 1633 mTodoList->setDocumentId( filename );
1628 } 1634 }
1629 globalFlagBlockAgenda = 2; 1635 globalFlagBlockAgenda = 2;
1630 // if ( getLastSyncEvent() ) 1636 // if ( getLastSyncEvent() )
1631 // getLastSyncEvent()->setReadOnly( true ); 1637 // getLastSyncEvent()->setReadOnly( true );
1632 mCalendar->reInitAlarmSettings(); 1638 mCalendar->reInitAlarmSettings();
1633 setSyncEventsReadOnly(); 1639 setSyncEventsReadOnly();
1634 updateUnmanagedViews(); 1640 updateUnmanagedViews();
1635 updateView(); 1641 updateView();
1636 if ( filename != MainWindow::defaultFileName() ) { 1642 if ( filename != MainWindow::defaultFileName() ) {
1637 saveCalendar( MainWindow::defaultFileName() ); 1643 saveCalendar( MainWindow::defaultFileName() );
1638 } else { 1644 } else {
1639 QFileInfo finf ( MainWindow::defaultFileName()); 1645 QFileInfo finf ( MainWindow::defaultFileName());
1640 if ( finf.exists() ) { 1646 if ( finf.exists() ) {
1641 setLoadedFileVersion( finf.lastModified () ); 1647 setLoadedFileVersion( finf.lastModified () );
1642 } 1648 }
1643 } 1649 }
1644 return true; 1650 return true;
1645 } else { 1651 } else {
1646 // while failing to load, the calendar object could 1652 // while failing to load, the calendar object could
1647 // have become partially populated. Clear it out. 1653 // have become partially populated. Clear it out.
1648 if ( !merge ) { 1654 if ( !merge ) {
1649 mCalendar->close(); 1655 mCalendar->close();
1650 mViewManager->setDocumentId( filename ); 1656 mViewManager->setDocumentId( filename );
1651 mDialogManager->setDocumentId( filename ); 1657 mDialogManager->setDocumentId( filename );
1652 mTodoList->setDocumentId( filename ); 1658 mTodoList->setDocumentId( filename );
1653 } 1659 }
1654 1660
1655 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1661 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1656 1662
1657 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1663 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1658 globalFlagBlockAgenda = 2; 1664 globalFlagBlockAgenda = 2;
1659 mCalendar->reInitAlarmSettings(); 1665 mCalendar->reInitAlarmSettings();
1660 setSyncEventsReadOnly(); 1666 setSyncEventsReadOnly();
1661 updateUnmanagedViews(); 1667 updateUnmanagedViews();
1662 updateView(); 1668 updateView();
1663 } 1669 }
1664 return false; 1670 return false;
1665} 1671}
1666void CalendarView::showOpenError() 1672void CalendarView::showOpenError()
1667{ 1673{
1668 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1674 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1669} 1675}
1670void CalendarView::setLoadedFileVersion(QDateTime dt) 1676void CalendarView::setLoadedFileVersion(QDateTime dt)
1671{ 1677{
1672 loadedFileVersion = dt; 1678 loadedFileVersion = dt;
1673} 1679}
1674bool CalendarView::checkFileChanged(QString fn) 1680bool CalendarView::checkFileChanged(QString fn)
1675{ 1681{
1676 QFileInfo finf ( fn ); 1682 QFileInfo finf ( fn );
1677 if ( !finf.exists() ) 1683 if ( !finf.exists() )
1678 return true; 1684 return true;
1679 QDateTime dt = finf.lastModified (); 1685 QDateTime dt = finf.lastModified ();
1680 if ( dt <= loadedFileVersion ) 1686 if ( dt <= loadedFileVersion )
1681 return false; 1687 return false;
1682 return true; 1688 return true;
1683 1689
1684} 1690}
1685void CalendarView::watchSavedFile() 1691void CalendarView::watchSavedFile()
1686{ 1692{
1687 QFileInfo finf ( MainWindow::defaultFileName()); 1693 QFileInfo finf ( MainWindow::defaultFileName());
1688 if ( !finf.exists() ) 1694 if ( !finf.exists() )
1689 return; 1695 return;
1690 QDateTime dt = finf.lastModified (); 1696 QDateTime dt = finf.lastModified ();
1691 if ( dt < loadedFileVersion ) { 1697 if ( dt < loadedFileVersion ) {
1692 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1698 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1693 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1699 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1694 return; 1700 return;
1695 } 1701 }
1696 loadedFileVersion = dt; 1702 loadedFileVersion = dt;
1697} 1703}
1698 1704
1699bool CalendarView::checkFileVersion(QString fn) 1705bool CalendarView::checkFileVersion(QString fn)
1700{ 1706{
1701 QFileInfo finf ( fn ); 1707 QFileInfo finf ( fn );
1702 if ( !finf.exists() ) 1708 if ( !finf.exists() )
1703 return true; 1709 return true;
1704 QDateTime dt = finf.lastModified (); 1710 QDateTime dt = finf.lastModified ();
1705 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1711 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1706 //qDebug("file on disk version %s",dt.toString().latin1()); 1712 //qDebug("file on disk version %s",dt.toString().latin1());
1707 if ( dt <= loadedFileVersion ) 1713 if ( dt <= loadedFileVersion )
1708 return true; 1714 return true;
1709 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)) , 1715 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)) ,
1710 i18n("KO/Pi Warning"),i18n("Overwrite"), 1716 i18n("KO/Pi Warning"),i18n("Overwrite"),
1711 i18n("Sync+save")); 1717 i18n("Sync+save"));
1712 1718
1713 if ( km == KMessageBox::Cancel ) 1719 if ( km == KMessageBox::Cancel )
1714 return false; 1720 return false;
1715 if ( km == KMessageBox::Yes ) 1721 if ( km == KMessageBox::Yes )
1716 return true; 1722 return true;
1717 1723
1718 setSyncDevice("deleteaftersync" ); 1724 setSyncDevice("deleteaftersync" );
1719 mSyncManager->mAskForPreferences = true; 1725 mSyncManager->mAskForPreferences = true;
1720 mSyncManager->mSyncAlgoPrefs = 3; 1726 mSyncManager->mSyncAlgoPrefs = 3;
1721 mSyncManager->mWriteBackFile = false; 1727 mSyncManager->mWriteBackFile = false;
1722 mSyncManager->mWriteBackExistingOnly = false; 1728 mSyncManager->mWriteBackExistingOnly = false;
1723 mSyncManager->mShowSyncSummary = false; 1729 mSyncManager->mShowSyncSummary = false;
1724 syncCalendar( fn, 3 ); 1730 syncCalendar( fn, 3 );
1725 Event * e = getLastSyncEvent(); 1731 Event * e = getLastSyncEvent();
1726 mCalendar->deleteEvent ( e ); 1732 mCalendar->deleteEvent ( e );
1727 updateView(); 1733 updateView();
1728 return true; 1734 return true;
1729} 1735}
1730 1736
1731bool CalendarView::saveCalendar( QString filename ) 1737bool CalendarView::saveCalendar( QString filename )
1732{ 1738{
1733 1739
1734 // Store back all unsaved data into calendar object 1740 // Store back all unsaved data into calendar object
1735 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1741 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1736 if ( mViewManager->currentView() ) 1742 if ( mViewManager->currentView() )
1737 mViewManager->currentView()->flushView(); 1743 mViewManager->currentView()->flushView();
1738 1744
1739 1745
1740 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1746 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1741 mStorage->setSaveFormat( new ICalFormat() ); 1747 mStorage->setSaveFormat( new ICalFormat() );
1742 mStorage->setFileName( filename ); 1748 mStorage->setFileName( filename );
1743 bool success; 1749 bool success;
1744 success = mStorage->save(); 1750 success = mStorage->save();
1745 if ( !success ) { 1751 if ( !success ) {
1746 return false; 1752 return false;
1747 } 1753 }
1748 if ( filename == MainWindow::defaultFileName() ) { 1754 if ( filename == MainWindow::defaultFileName() ) {
1749 setLoadedFileVersion( lfv ); 1755 setLoadedFileVersion( lfv );
1750 watchSavedFile(); 1756 watchSavedFile();
1751 } 1757 }
1752 return true; 1758 return true;
1753} 1759}
1754 1760
1755void CalendarView::closeCalendar() 1761void CalendarView::closeCalendar()
1756{ 1762{
1757 1763
1758 // child windows no longer valid 1764 // child windows no longer valid
1759 emit closingDown(); 1765 emit closingDown();
1760 1766
1761 mCalendar->close(); 1767 mCalendar->close();
1762 setModified(false); 1768 setModified(false);
1763 updateView(); 1769 updateView();
1764} 1770}
1765 1771
1766void CalendarView::archiveCalendar() 1772void CalendarView::archiveCalendar()
1767{ 1773{
1768 mDialogManager->showArchiveDialog(); 1774 mDialogManager->showArchiveDialog();
1769} 1775}
1770 1776
1771 1777
1772void CalendarView::readSettings() 1778void CalendarView::readSettings()
1773{ 1779{
1774 1780
1775 1781
1776 // mViewManager->showAgendaView(); 1782 // mViewManager->showAgendaView();
1777 QString str; 1783 QString str;
1778 //qDebug("CalendarView::readSettings() "); 1784 //qDebug("CalendarView::readSettings() ");
1779 // read settings from the KConfig, supplying reasonable 1785 // read settings from the KConfig, supplying reasonable
1780 // defaults where none are to be found 1786 // defaults where none are to be found
1781 KConfig *config = KOGlobals::config(); 1787 KConfig *config = KOGlobals::config();
1782#ifndef KORG_NOSPLITTER 1788#ifndef KORG_NOSPLITTER
1783 config->setGroup("KOrganizer Geometry"); 1789 config->setGroup("KOrganizer Geometry");
1784 1790
1785 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1791 QValueList<int> sizes = config->readIntListEntry("Separator1");
1786 if (sizes.count() != 2) { 1792 if (sizes.count() != 2) {
1787 sizes << mDateNavigator->minimumSizeHint().width(); 1793 sizes << mDateNavigator->minimumSizeHint().width();
1788 sizes << 300; 1794 sizes << 300;
1789 } 1795 }
1790 mPanner->setSizes(sizes); 1796 mPanner->setSizes(sizes);
1791 1797
1792 sizes = config->readIntListEntry("Separator2"); 1798 sizes = config->readIntListEntry("Separator2");
1793 if ( ( mResourceView && sizes.count() == 4 ) || 1799 if ( ( mResourceView && sizes.count() == 4 ) ||
1794 ( !mResourceView && sizes.count() == 3 ) ) { 1800 ( !mResourceView && sizes.count() == 3 ) ) {
1795 mLeftSplitter->setSizes(sizes); 1801 mLeftSplitter->setSizes(sizes);
1796 } 1802 }
1797#endif 1803#endif
1798 globalFlagBlockAgenda = 1; 1804 globalFlagBlockAgenda = 1;
1799 mViewManager->showAgendaView(); 1805 mViewManager->showAgendaView();
1800 //mViewManager->readSettings( config ); 1806 //mViewManager->readSettings( config );
1801 mTodoList->restoreLayout(config,QString("Todo Layout")); 1807 mTodoList->restoreLayout(config,QString("Todo Layout"));
1802 readFilterSettings(config); 1808 readFilterSettings(config);
1803 config->setGroup( "Views" ); 1809 config->setGroup( "Views" );
1804 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1810 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1805 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1811 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1806 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1812 else if ( dateCount == 7 ) mNavigator->selectWeek();
1807 else mNavigator->selectDates( dateCount ); 1813 else mNavigator->selectDates( dateCount );
1808 // mViewManager->readSettings( config ); 1814 // mViewManager->readSettings( config );
1809 updateConfig(); 1815 updateConfig();
1810 globalFlagBlockAgenda = 2; 1816 globalFlagBlockAgenda = 2;
1811 mViewManager->readSettings( config ); 1817 mViewManager->readSettings( config );
1812#ifdef DESKTOP_VERSION 1818#ifdef DESKTOP_VERSION
1813 config->setGroup("WidgetLayout"); 1819 config->setGroup("WidgetLayout");
1814 QStringList list; 1820 QStringList list;
1815 list = config->readListEntry("MainLayout"); 1821 list = config->readListEntry("MainLayout");
1816 int x,y,w,h; 1822 int x,y,w,h;
1817 if ( ! list.isEmpty() ) { 1823 if ( ! list.isEmpty() ) {
1818 x = list[0].toInt(); 1824 x = list[0].toInt();
1819 y = list[1].toInt(); 1825 y = list[1].toInt();
1820 w = list[2].toInt(); 1826 w = list[2].toInt();
1821 h = list[3].toInt(); 1827 h = list[3].toInt();
1822 topLevelWidget()->setGeometry(x,y,w,h); 1828 topLevelWidget()->setGeometry(x,y,w,h);
1823 1829
1824 } else { 1830 } else {
1825 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1831 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1826 } 1832 }
1827 list = config->readListEntry("EditEventLayout"); 1833 list = config->readListEntry("EditEventLayout");
1828 if ( ! list.isEmpty() ) { 1834 if ( ! list.isEmpty() ) {
1829 x = list[0].toInt(); 1835 x = list[0].toInt();
1830 y = list[1].toInt(); 1836 y = list[1].toInt();
1831 w = list[2].toInt(); 1837 w = list[2].toInt();
1832 h = list[3].toInt(); 1838 h = list[3].toInt();
1833 mEventEditor->setGeometry(x,y,w,h); 1839 mEventEditor->setGeometry(x,y,w,h);
1834 1840
1835 } 1841 }
1836 list = config->readListEntry("EditTodoLayout"); 1842 list = config->readListEntry("EditTodoLayout");
1837 if ( ! list.isEmpty() ) { 1843 if ( ! list.isEmpty() ) {
1838 x = list[0].toInt(); 1844 x = list[0].toInt();
1839 y = list[1].toInt(); 1845 y = list[1].toInt();
1840 w = list[2].toInt(); 1846 w = list[2].toInt();
1841 h = list[3].toInt(); 1847 h = list[3].toInt();
1842 mTodoEditor->setGeometry(x,y,w,h); 1848 mTodoEditor->setGeometry(x,y,w,h);
1843 1849
1844 } 1850 }
1845 list = config->readListEntry("ViewerLayout"); 1851 list = config->readListEntry("ViewerLayout");
1846 if ( ! list.isEmpty() ) { 1852 if ( ! list.isEmpty() ) {
1847 x = list[0].toInt(); 1853 x = list[0].toInt();
1848 y = list[1].toInt(); 1854 y = list[1].toInt();
1849 w = list[2].toInt(); 1855 w = list[2].toInt();
1850 h = list[3].toInt(); 1856 h = list[3].toInt();
1851 getEventViewerDialog()->setGeometry(x,y,w,h); 1857 getEventViewerDialog()->setGeometry(x,y,w,h);
1852 } 1858 }
1853#endif 1859#endif
1854 1860
1855} 1861}
1856 1862
1857 1863
1858void CalendarView::writeSettings() 1864void CalendarView::writeSettings()
1859{ 1865{
1860 // kdDebug() << "CalendarView::writeSettings" << endl; 1866 // kdDebug() << "CalendarView::writeSettings" << endl;
1861 1867
1862 KConfig *config = KOGlobals::config(); 1868 KConfig *config = KOGlobals::config();
1863 1869
1864#ifndef KORG_NOSPLITTER 1870#ifndef KORG_NOSPLITTER
1865 config->setGroup("KOrganizer Geometry"); 1871 config->setGroup("KOrganizer Geometry");
1866 1872
1867 QValueList<int> list = mPanner->sizes(); 1873 QValueList<int> list = mPanner->sizes();
1868 config->writeEntry("Separator1",list); 1874 config->writeEntry("Separator1",list);
1869 1875
1870 list = mLeftSplitter->sizes(); 1876 list = mLeftSplitter->sizes();
1871 config->writeEntry("Separator2",list); 1877 config->writeEntry("Separator2",list);
1872#endif 1878#endif
1873 1879
1874 mViewManager->writeSettings( config ); 1880 mViewManager->writeSettings( config );
1875 mTodoList->saveLayout(config,QString("Todo Layout")); 1881 mTodoList->saveLayout(config,QString("Todo Layout"));
1876 mDialogManager->writeSettings( config ); 1882 mDialogManager->writeSettings( config );
1877 //KOPrefs::instance()->usrWriteConfig(); 1883 //KOPrefs::instance()->usrWriteConfig();
1878 KOPrefs::instance()->writeConfig(); 1884 KOPrefs::instance()->writeConfig();
1879 1885
1880 writeFilterSettings(config); 1886 writeFilterSettings(config);
1881 1887
1882 config->setGroup( "Views" ); 1888 config->setGroup( "Views" );
1883 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1889 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1884 1890
1885#ifdef DESKTOP_VERSION 1891#ifdef DESKTOP_VERSION
1886 config->setGroup("WidgetLayout"); 1892 config->setGroup("WidgetLayout");
1887 QStringList list ;//= config->readListEntry("MainLayout"); 1893 QStringList list ;//= config->readListEntry("MainLayout");
1888 int x,y,w,h; 1894 int x,y,w,h;
1889 QWidget* wid; 1895 QWidget* wid;
1890 wid = topLevelWidget(); 1896 wid = topLevelWidget();
1891 x = wid->geometry().x(); 1897 x = wid->geometry().x();
1892 y = wid->geometry().y(); 1898 y = wid->geometry().y();
1893 w = wid->width(); 1899 w = wid->width();
1894 h = wid->height(); 1900 h = wid->height();
1895 list.clear(); 1901 list.clear();
1896 list << QString::number( x ); 1902 list << QString::number( x );
1897 list << QString::number( y ); 1903 list << QString::number( y );
1898 list << QString::number( w ); 1904 list << QString::number( w );
1899 list << QString::number( h ); 1905 list << QString::number( h );
1900 config->writeEntry("MainLayout",list ); 1906 config->writeEntry("MainLayout",list );
1901 1907
1902 wid = mEventEditor; 1908 wid = mEventEditor;
1903 x = wid->geometry().x(); 1909 x = wid->geometry().x();
1904 y = wid->geometry().y(); 1910 y = wid->geometry().y();
1905 w = wid->width(); 1911 w = wid->width();
1906 h = wid->height(); 1912 h = wid->height();
1907 list.clear(); 1913 list.clear();
1908 list << QString::number( x ); 1914 list << QString::number( x );
1909 list << QString::number( y ); 1915 list << QString::number( y );
1910 list << QString::number( w ); 1916 list << QString::number( w );
1911 list << QString::number( h ); 1917 list << QString::number( h );
1912 config->writeEntry("EditEventLayout",list ); 1918 config->writeEntry("EditEventLayout",list );
1913 1919
1914 wid = mTodoEditor; 1920 wid = mTodoEditor;
1915 x = wid->geometry().x(); 1921 x = wid->geometry().x();
1916 y = wid->geometry().y(); 1922 y = wid->geometry().y();
1917 w = wid->width(); 1923 w = wid->width();
1918 h = wid->height(); 1924 h = wid->height();
1919 list.clear(); 1925 list.clear();
1920 list << QString::number( x ); 1926 list << QString::number( x );
1921 list << QString::number( y ); 1927 list << QString::number( y );
1922 list << QString::number( w ); 1928 list << QString::number( w );
1923 list << QString::number( h ); 1929 list << QString::number( h );
1924 config->writeEntry("EditTodoLayout",list ); 1930 config->writeEntry("EditTodoLayout",list );
1925 wid = getEventViewerDialog(); 1931 wid = getEventViewerDialog();
1926 x = wid->geometry().x(); 1932 x = wid->geometry().x();
1927 y = wid->geometry().y(); 1933 y = wid->geometry().y();
1928 w = wid->width(); 1934 w = wid->width();
1929 h = wid->height(); 1935 h = wid->height();
1930 list.clear(); 1936 list.clear();
1931 list << QString::number( x ); 1937 list << QString::number( x );
1932 list << QString::number( y ); 1938 list << QString::number( y );
1933 list << QString::number( w ); 1939 list << QString::number( w );
1934 list << QString::number( h ); 1940 list << QString::number( h );
1935 config->writeEntry("ViewerLayout",list ); 1941 config->writeEntry("ViewerLayout",list );
1936 wid = mDialogManager->getSearchDialog(); 1942 wid = mDialogManager->getSearchDialog();
1937 if ( wid ) { 1943 if ( wid ) {
1938 x = wid->geometry().x(); 1944 x = wid->geometry().x();
1939 y = wid->geometry().y(); 1945 y = wid->geometry().y();
1940 w = wid->width(); 1946 w = wid->width();
1941 h = wid->height(); 1947 h = wid->height();
1942 list.clear(); 1948 list.clear();
1943 list << QString::number( x ); 1949 list << QString::number( x );
1944 list << QString::number( y ); 1950 list << QString::number( y );
1945 list << QString::number( w ); 1951 list << QString::number( w );
1946 list << QString::number( h ); 1952 list << QString::number( h );
1947 config->writeEntry("SearchLayout",list ); 1953 config->writeEntry("SearchLayout",list );
1948 } 1954 }
1949#endif 1955#endif
1950 1956
1951 1957
1952 config->sync(); 1958 config->sync();
1953} 1959}
1954 1960
1955void CalendarView::readFilterSettings(KConfig *config) 1961void CalendarView::readFilterSettings(KConfig *config)
1956{ 1962{
1957 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1963 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1958 1964
1959 mFilters.clear(); 1965 mFilters.clear();
1960 1966
1961 config->setGroup("General"); 1967 config->setGroup("General");
1962 QStringList filterList = config->readListEntry("CalendarFilters"); 1968 QStringList filterList = config->readListEntry("CalendarFilters");
1963 1969
1964 QStringList::ConstIterator it = filterList.begin(); 1970 QStringList::ConstIterator it = filterList.begin();
1965 QStringList::ConstIterator end = filterList.end(); 1971 QStringList::ConstIterator end = filterList.end();
1966 while(it != end) { 1972 while(it != end) {
1967 // kdDebug() << " filter: " << (*it) << endl; 1973 // kdDebug() << " filter: " << (*it) << endl;
1968 1974
1969 CalFilter *filter; 1975 CalFilter *filter;
1970 filter = new CalFilter(*it); 1976 filter = new CalFilter(*it);
1971 config->setGroup("Filter_" + (*it)); 1977 config->setGroup("Filter_" + (*it));
1972 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1978 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1973 filter->setCriteria(config->readNumEntry("Criteria",0)); 1979 filter->setCriteria(config->readNumEntry("Criteria",0));
1974 filter->setCategoryList(config->readListEntry("CategoryList")); 1980 filter->setCategoryList(config->readListEntry("CategoryList"));
1975 mFilters.append(filter); 1981 mFilters.append(filter);
1976 1982
1977 ++it; 1983 ++it;
1978 } 1984 }
1979 1985
1980 if (mFilters.count() == 0) { 1986 if (mFilters.count() == 0) {
1981 CalFilter *filter = new CalFilter(i18n("Default")); 1987 CalFilter *filter = new CalFilter(i18n("Default"));
1982 mFilters.append(filter); 1988 mFilters.append(filter);
1983 } 1989 }
1984 mFilterView->updateFilters(); 1990 mFilterView->updateFilters();
1985 config->setGroup("FilterView"); 1991 config->setGroup("FilterView");
1986 1992
1987 mFilterView->blockSignals(true); 1993 mFilterView->blockSignals(true);
1988 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1994 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1989 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1995 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1990 mFilterView->blockSignals(false); 1996 mFilterView->blockSignals(false);
1991 // We do it manually to avoid it being done twice by the above calls 1997 // We do it manually to avoid it being done twice by the above calls
1992 updateFilter(); 1998 updateFilter();
1993} 1999}
1994 2000
1995void CalendarView::writeFilterSettings(KConfig *config) 2001void CalendarView::writeFilterSettings(KConfig *config)
1996{ 2002{
1997 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2003 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1998 2004
1999 QStringList filterList; 2005 QStringList filterList;
2000 2006
2001 CalFilter *filter = mFilters.first(); 2007 CalFilter *filter = mFilters.first();
2002 while(filter) { 2008 while(filter) {
2003 // kdDebug() << " fn: " << filter->name() << endl; 2009 // kdDebug() << " fn: " << filter->name() << endl;
2004 filterList << filter->name(); 2010 filterList << filter->name();
2005 config->setGroup("Filter_" + filter->name()); 2011 config->setGroup("Filter_" + filter->name());
2006 config->writeEntry("Criteria",filter->criteria()); 2012 config->writeEntry("Criteria",filter->criteria());
2007 config->writeEntry("CategoryList",filter->categoryList()); 2013 config->writeEntry("CategoryList",filter->categoryList());
2008 filter = mFilters.next(); 2014 filter = mFilters.next();
2009 } 2015 }
2010 config->setGroup("General"); 2016 config->setGroup("General");
2011 config->writeEntry("CalendarFilters",filterList); 2017 config->writeEntry("CalendarFilters",filterList);
2012 2018
2013 config->setGroup("FilterView"); 2019 config->setGroup("FilterView");
2014 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2020 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2015 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2021 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2016} 2022}
2017 2023
2018 2024
2019void CalendarView::goToday() 2025void CalendarView::goToday()
2020{ 2026{
2021 if ( mViewManager->currentView()->isMonthView() ) 2027 if ( mViewManager->currentView()->isMonthView() )
2022 mNavigator->selectTodayMonth(); 2028 mNavigator->selectTodayMonth();
2023 else 2029 else
2024 mNavigator->selectToday(); 2030 mNavigator->selectToday();
2025} 2031}
2026 2032
2027void CalendarView::goNext() 2033void CalendarView::goNext()
2028{ 2034{
2029 mNavigator->selectNext(); 2035 mNavigator->selectNext();
2030} 2036}
2031 2037
2032void CalendarView::goPrevious() 2038void CalendarView::goPrevious()
2033{ 2039{
2034 mNavigator->selectPrevious(); 2040 mNavigator->selectPrevious();
2035} 2041}
2036void CalendarView::goNextMonth() 2042void CalendarView::goNextMonth()
2037{ 2043{
2038 mNavigator->selectNextMonth(); 2044 mNavigator->selectNextMonth();
2039} 2045}
2040 2046
2041void CalendarView::goPreviousMonth() 2047void CalendarView::goPreviousMonth()
2042{ 2048{
2043 mNavigator->selectPreviousMonth(); 2049 mNavigator->selectPreviousMonth();
2044} 2050}
2045void CalendarView::writeLocale() 2051void CalendarView::writeLocale()
2046{ 2052{
2047 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2053 //KPimGlobalPrefs::instance()->setGlobalConfig();
2048#if 0 2054#if 0
2049 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2055 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2050 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2056 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2051 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2057 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2052 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2058 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2053 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2059 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2054 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2060 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2055 dummy = KOPrefs::instance()->mUserDateFormatShort; 2061 dummy = KOPrefs::instance()->mUserDateFormatShort;
2056 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2062 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2057 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2063 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2058 KOPrefs::instance()->mDaylightsavingStart, 2064 KOPrefs::instance()->mDaylightsavingStart,
2059 KOPrefs::instance()->mDaylightsavingEnd ); 2065 KOPrefs::instance()->mDaylightsavingEnd );
2060 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2066 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2061#endif 2067#endif
2062} 2068}
2063void CalendarView::updateConfig() 2069void CalendarView::updateConfig()
2064{ 2070{
2065 writeLocale(); 2071 writeLocale();
2066 if ( KOPrefs::instance()->mUseAppColors ) 2072 if ( KOPrefs::instance()->mUseAppColors )
2067 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2073 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2068 emit configChanged(); 2074 emit configChanged();
2069 mTodoList->updateConfig(); 2075 mTodoList->updateConfig();
2070 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2076 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2071 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2077 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2072 // To make the "fill window" configurations work 2078 // To make the "fill window" configurations work
2073 //mViewManager->raiseCurrentView(); 2079 //mViewManager->raiseCurrentView();
2074} 2080}
2075 2081
2076 2082
2077void CalendarView::eventChanged(Event *event) 2083void CalendarView::eventChanged(Event *event)
2078{ 2084{
2079 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2085 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2080 //updateUnmanagedViews(); 2086 //updateUnmanagedViews();
2081} 2087}
2082 2088
2083void CalendarView::eventAdded(Event *event) 2089void CalendarView::eventAdded(Event *event)
2084{ 2090{
2085 changeEventDisplay(event,KOGlobals::EVENTADDED); 2091 changeEventDisplay(event,KOGlobals::EVENTADDED);
2086} 2092}
2087 2093
2088void CalendarView::eventToBeDeleted(Event *) 2094void CalendarView::eventToBeDeleted(Event *)
2089{ 2095{
2090 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2096 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2091} 2097}
2092 2098
2093void CalendarView::eventDeleted() 2099void CalendarView::eventDeleted()
2094{ 2100{
2095 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2101 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2096} 2102}
2097void CalendarView::changeTodoDisplay(Todo *which, int action) 2103void CalendarView::changeTodoDisplay(Todo *which, int action)
2098{ 2104{
2099 changeIncidenceDisplay((Incidence *)which, action); 2105 changeIncidenceDisplay((Incidence *)which, action);
2100 mDateNavigator->updateView(); //LR 2106 mDateNavigator->updateView(); //LR
2101 //mDialogManager->updateSearchDialog(); 2107 //mDialogManager->updateSearchDialog();
2102 2108
2103 if (which) { 2109 if (which) {
2104 mViewManager->updateWNview(); 2110 mViewManager->updateWNview();
2105 //mTodoList->updateView(); 2111 //mTodoList->updateView();
2106 } 2112 }
2107 2113
2108} 2114}
2109 2115
2110void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2116void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2111{ 2117{
2112 updateUnmanagedViews(); 2118 updateUnmanagedViews();
2113 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2119 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2114 if ( action == KOGlobals::EVENTDELETED ) { //delete 2120 if ( action == KOGlobals::EVENTDELETED ) { //delete
2115 mCalendar->checkAlarmForIncidence( 0, true ); 2121 mCalendar->checkAlarmForIncidence( 0, true );
2116 if ( mEventViewerDialog ) 2122 if ( mEventViewerDialog )
2117 mEventViewerDialog->hide(); 2123 mEventViewerDialog->hide();
2118 } 2124 }
2119 else 2125 else
2120 mCalendar->checkAlarmForIncidence( which , false ); 2126 mCalendar->checkAlarmForIncidence( which , false );
2121} 2127}
2122 2128
2123// most of the changeEventDisplays() right now just call the view's 2129// most of the changeEventDisplays() right now just call the view's
2124// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2130// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2125void CalendarView::changeEventDisplay(Event *which, int action) 2131void CalendarView::changeEventDisplay(Event *which, int action)
2126{ 2132{
2127 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2133 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2128 changeIncidenceDisplay((Incidence *)which, action); 2134 changeIncidenceDisplay((Incidence *)which, action);
2129 mDateNavigator->updateView(); 2135 mDateNavigator->updateView();
2130 //mDialogManager->updateSearchDialog(); 2136 //mDialogManager->updateSearchDialog();
2131 2137
2132 if (which) { 2138 if (which) {
2133 // If there is an event view visible update the display 2139 // If there is an event view visible update the display
2134 mViewManager->currentView()->changeEventDisplay(which,action); 2140 mViewManager->currentView()->changeEventDisplay(which,action);
2135 // TODO: check, if update needed 2141 // TODO: check, if update needed
2136 // if (which->getTodoStatus()) { 2142 // if (which->getTodoStatus()) {
2137 mTodoList->updateView(); 2143 mTodoList->updateView();
2138 // } 2144 // }
2139 } else { 2145 } else {
2140 mViewManager->currentView()->updateView(); 2146 mViewManager->currentView()->updateView();
2141 } 2147 }
2142} 2148}
2143 2149
2144 2150
2145void CalendarView::updateTodoViews() 2151void CalendarView::updateTodoViews()
2146{ 2152{
2147 2153
2148 mTodoList->updateView(); 2154 mTodoList->updateView();
2149 mViewManager->currentView()->updateView(); 2155 mViewManager->currentView()->updateView();
2150 2156
2151} 2157}
2152 2158
2153 2159
2154void CalendarView::updateView(const QDate &start, const QDate &end) 2160void CalendarView::updateView(const QDate &start, const QDate &end)
2155{ 2161{
2156 mTodoList->updateView(); 2162 mTodoList->updateView();
2157 mViewManager->updateView(start, end); 2163 mViewManager->updateView(start, end);
2158 //mDateNavigator->updateView(); 2164 //mDateNavigator->updateView();
2159} 2165}
2160 2166
2161void CalendarView::updateView() 2167void CalendarView::updateView()
2162{ 2168{
2163 DateList tmpList = mNavigator->selectedDates(); 2169 DateList tmpList = mNavigator->selectedDates();
2164 2170
2165 // We assume that the navigator only selects consecutive days. 2171 // We assume that the navigator only selects consecutive days.
2166 updateView( tmpList.first(), tmpList.last() ); 2172 updateView( tmpList.first(), tmpList.last() );
2167 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2173 if ( KOPrefs::instance()->mHideNonStartedTodos )
2168 mTodoList->updateView(); 2174 mTodoList->updateView();
2169} 2175}
2170 2176
2171void CalendarView::updateUnmanagedViews() 2177void CalendarView::updateUnmanagedViews()
2172{ 2178{
2173 mDateNavigator->updateDayMatrix(); 2179 mDateNavigator->updateDayMatrix();
2174} 2180}
2175 2181
2176int CalendarView::msgItemDelete() 2182int CalendarView::msgItemDelete()
2177{ 2183{
2178 return KMessageBox::warningContinueCancel(this, 2184 return KMessageBox::warningContinueCancel(this,
2179 i18n("This item will be\npermanently deleted."), 2185 i18n("This item will be\npermanently deleted."),
2180 i18n("KO/Pi Confirmation"),i18n("Delete")); 2186 i18n("KO/Pi Confirmation"),i18n("Delete"));
2181} 2187}
2182 2188
2183 2189
2184void CalendarView::edit_cut() 2190void CalendarView::edit_cut()
2185{ 2191{
2186 Event *anEvent=0; 2192 Event *anEvent=0;
2187 2193
2188 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2194 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2189 2195
2190 if (mViewManager->currentView()->isEventView()) { 2196 if (mViewManager->currentView()->isEventView()) {
2191 if ( incidence && incidence->type() == "Event" ) { 2197 if ( incidence && incidence->type() == "Event" ) {
2192 anEvent = static_cast<Event *>(incidence); 2198 anEvent = static_cast<Event *>(incidence);
2193 } 2199 }
2194 } 2200 }
2195 2201
2196 if (!anEvent) { 2202 if (!anEvent) {
2197 KNotifyClient::beep(); 2203 KNotifyClient::beep();
2198 return; 2204 return;
2199 } 2205 }
2200 DndFactory factory( mCalendar ); 2206 DndFactory factory( mCalendar );
2201 factory.cutEvent(anEvent); 2207 factory.cutEvent(anEvent);
2202 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2208 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2203} 2209}
2204 2210
2205void CalendarView::edit_copy() 2211void CalendarView::edit_copy()
2206{ 2212{
2207 Event *anEvent=0; 2213 Event *anEvent=0;
2208 2214
2209 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2215 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2210 2216
2211 if (mViewManager->currentView()->isEventView()) { 2217 if (mViewManager->currentView()->isEventView()) {
2212 if ( incidence && incidence->type() == "Event" ) { 2218 if ( incidence && incidence->type() == "Event" ) {
2213 anEvent = static_cast<Event *>(incidence); 2219 anEvent = static_cast<Event *>(incidence);
2214 } 2220 }
2215 } 2221 }
2216 2222
2217 if (!anEvent) { 2223 if (!anEvent) {
2218 KNotifyClient::beep(); 2224 KNotifyClient::beep();
2219 return; 2225 return;
2220 } 2226 }
2221 DndFactory factory( mCalendar ); 2227 DndFactory factory( mCalendar );
2222 factory.copyEvent(anEvent); 2228 factory.copyEvent(anEvent);
2223} 2229}
2224 2230
2225void CalendarView::edit_paste() 2231void CalendarView::edit_paste()
2226{ 2232{
2227 QDate date = mNavigator->selectedDates().first(); 2233 QDate date = mNavigator->selectedDates().first();
2228 2234
2229 DndFactory factory( mCalendar ); 2235 DndFactory factory( mCalendar );
2230 Event *pastedEvent = factory.pasteEvent( date ); 2236 Event *pastedEvent = factory.pasteEvent( date );
2231 2237
2232 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2238 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2233} 2239}
2234 2240
2235void CalendarView::edit_options() 2241void CalendarView::edit_options()
2236{ 2242{
2237 mDialogManager->showOptionsDialog(); 2243 mDialogManager->showOptionsDialog();
2238 //writeSettings(); 2244 //writeSettings();
2239} 2245}
2240 2246
2241 2247
2242void CalendarView::slotSelectPickerDate( QDate d) 2248void CalendarView::slotSelectPickerDate( QDate d)
2243{ 2249{
2244 mDateFrame->hide(); 2250 mDateFrame->hide();
2245 if ( mDatePickerMode == 1 ) { 2251 if ( mDatePickerMode == 1 ) {