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