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