summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp17
-rw-r--r--korganizer/calendarview.h4
-rw-r--r--korganizer/koagenda.cpp66
-rw-r--r--korganizer/koagenda.h6
-rw-r--r--korganizer/koagendaview.cpp19
-rw-r--r--korganizer/koagendaview.h3
-rw-r--r--korganizer/koeditorgeneraltodo.cpp17
-rw-r--r--korganizer/koviewmanager.cpp9
8 files changed, 119 insertions, 22 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 257a4dd..035d630 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3911 +1,3918 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130 130
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
133#endif 133#endif
134using namespace KOrg; 134using namespace KOrg;
135using namespace KCal; 135using namespace KCal;
136extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
137extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
138 138
139 139
140 140
141class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
142{ 142{
143 public: 143 public:
144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
145 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
146 { 146 {
147 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
148 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
149 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
150 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
152 lay->addWidget( format ); 152 lay->addWidget( format );
153 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
155 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
156 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
157 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
158 vcal->setChecked( true ); 158 vcal->setChecked( true );
159 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
160 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 mBlockShowDates = false; 236 mBlockShowDates = false;
237 beamDialog = new KOBeamPrefs(); 237 beamDialog = new KOBeamPrefs();
238 mDatePickerMode = 0; 238 mDatePickerMode = 0;
239 mCurrentSyncDevice = ""; 239 mCurrentSyncDevice = "";
240 writeLocale(); 240 writeLocale();
241 mViewManager = new KOViewManager( this ); 241 mViewManager = new KOViewManager( this );
242 mDialogManager = new KODialogManager( this ); 242 mDialogManager = new KODialogManager( this );
243 mEventViewerDialog = 0; 243 mEventViewerDialog = 0;
244 mModified = false; 244 mModified = false;
245 mReadOnly = false; 245 mReadOnly = false;
246 mSelectedIncidence = 0; 246 mSelectedIncidence = 0;
247 mCalPrinter = 0; 247 mCalPrinter = 0;
248 mFilters.setAutoDelete(true); 248 mFilters.setAutoDelete(true);
249 249
250 mCalendar->registerObserver( this ); 250 mCalendar->registerObserver( this );
251 // TODO: Make sure that view is updated, when calendar is changed. 251 // TODO: Make sure that view is updated, when calendar is changed.
252 252
253 mStorage = new FileStorage( mCalendar ); 253 mStorage = new FileStorage( mCalendar );
254 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 254 mNavigator = new DateNavigator( this, "datevav", mViewManager );
255 255
256 QBoxLayout *topLayout = (QBoxLayout*)layout(); 256 QBoxLayout *topLayout = (QBoxLayout*)layout();
257#ifndef KORG_NOSPLITTER 257#ifndef KORG_NOSPLITTER
258 // create the main layout frames. 258 // create the main layout frames.
259 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 259 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
260 topLayout->addWidget(mPanner); 260 topLayout->addWidget(mPanner);
261 261
262 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 262 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
263 "CalendarView::LeftFrame"); 263 "CalendarView::LeftFrame");
264 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 264 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
265 265
266 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 266 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
267 "CalendarView::DateNavigator", QDate::currentDate() ); 267 "CalendarView::DateNavigator", QDate::currentDate() );
268 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 268 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
269 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 269 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
270 mTodoList->setNavigator( mNavigator ); 270 mTodoList->setNavigator( mNavigator );
271 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 271 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
272 272
273#ifdef KORG_NORESOURCEVIEW 273#ifdef KORG_NORESOURCEVIEW
274 mResourceView = 0; 274 mResourceView = 0;
275#else 275#else
276 if ( mResourceManager ) { 276 if ( mResourceManager ) {
277 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 277 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
278 mResourceView->updateView(); 278 mResourceView->updateView();
279 connect( mResourceView, SIGNAL( resourcesChanged() ), 279 connect( mResourceView, SIGNAL( resourcesChanged() ),
280 SLOT( updateView() ) ); 280 SLOT( updateView() ) );
281 } else { 281 } else {
282 mResourceView = 0; 282 mResourceView = 0;
283 } 283 }
284#endif 284#endif
285 QWidget *rightBox = new QWidget( mPanner ); 285 QWidget *rightBox = new QWidget( mPanner );
286 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 286 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
287 287
288 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 288 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
289 rightLayout->addWidget( mNavigatorBar ); 289 rightLayout->addWidget( mNavigatorBar );
290 290
291 mRightFrame = new QWidgetStack( rightBox ); 291 mRightFrame = new QWidgetStack( rightBox );
292 rightLayout->addWidget( mRightFrame, 1 ); 292 rightLayout->addWidget( mRightFrame, 1 );
293 293
294 mLeftFrame = mLeftSplitter; 294 mLeftFrame = mLeftSplitter;
295#else 295#else
296 QWidget *mainBox = new QWidget( this ); 296 QWidget *mainBox = new QWidget( this );
297 QWidget *leftFrame = new QWidget( mainBox ); 297 QWidget *leftFrame = new QWidget( mainBox );
298 298
299 QBoxLayout * mainBoxLayout; 299 QBoxLayout * mainBoxLayout;
300 QBoxLayout * leftFrameLayout; 300 QBoxLayout * leftFrameLayout;
301 if ( KOPrefs::instance()->mVerticalScreen ) { 301 if ( KOPrefs::instance()->mVerticalScreen ) {
302 mainBoxLayout = new QVBoxLayout(mainBox); 302 mainBoxLayout = new QVBoxLayout(mainBox);
303 leftFrameLayout = new QHBoxLayout(leftFrame ); 303 leftFrameLayout = new QHBoxLayout(leftFrame );
304 } else { 304 } else {
305 mainBoxLayout = new QHBoxLayout(mainBox); 305 mainBoxLayout = new QHBoxLayout(mainBox);
306 leftFrameLayout = new QVBoxLayout(leftFrame ); 306 leftFrameLayout = new QVBoxLayout(leftFrame );
307 } 307 }
308 topLayout->addWidget( mainBox ); 308 topLayout->addWidget( mainBox );
309 mainBoxLayout->addWidget (leftFrame); 309 mainBoxLayout->addWidget (leftFrame);
310 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 310 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
311 "CalendarView::DateNavigator", QDate::currentDate()); 311 "CalendarView::DateNavigator", QDate::currentDate());
312 // mDateNavigator->blockSignals( true ); 312 // mDateNavigator->blockSignals( true );
313 leftFrameLayout->addWidget( mDateNavigator ); 313 leftFrameLayout->addWidget( mDateNavigator );
314 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 314 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
315 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 315 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
316 mTodoList->setNavigator( mNavigator ); 316 mTodoList->setNavigator( mNavigator );
317 317
318 if ( QApplication::desktop()->width() < 480 ) { 318 if ( QApplication::desktop()->width() < 480 ) {
319 leftFrameLayout->addWidget(mFilterView); 319 leftFrameLayout->addWidget(mFilterView);
320 leftFrameLayout->addWidget(mTodoList, 2 ); 320 leftFrameLayout->addWidget(mTodoList, 2 );
321 321
322 } else { 322 } else {
323 leftFrameLayout->addWidget(mTodoList,2 ); 323 leftFrameLayout->addWidget(mTodoList,2 );
324 leftFrameLayout->addWidget(mFilterView ); 324 leftFrameLayout->addWidget(mFilterView );
325 } 325 }
326 mFilterView->hide(); 326 mFilterView->hide();
327 QWidget *rightBox = new QWidget( mainBox ); 327 QWidget *rightBox = new QWidget( mainBox );
328 mainBoxLayout->addWidget ( rightBox, 10 ); 328 mainBoxLayout->addWidget ( rightBox, 10 );
329 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 329 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
330 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 330 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
331 mRightFrame = new QWidgetStack( rightBox ); 331 mRightFrame = new QWidgetStack( rightBox );
332 rightLayout->addWidget( mNavigatorBar ); 332 rightLayout->addWidget( mNavigatorBar );
333 rightLayout->addWidget( mRightFrame, 10 ); 333 rightLayout->addWidget( mRightFrame, 10 );
334 334
335 mLeftFrame = leftFrame; 335 mLeftFrame = leftFrame;
336 if ( KOPrefs::instance()->mVerticalScreen ) { 336 if ( KOPrefs::instance()->mVerticalScreen ) {
337 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 337 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
338 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 338 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
339 } else { 339 } else {
340 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 340 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
341 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 341 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
342 } 342 }
343 if ( !KOPrefs::instance()->mShowDateNavigator) 343 if ( !KOPrefs::instance()->mShowDateNavigator)
344 mDateNavigator->hide(); 344 mDateNavigator->hide();
345 //qDebug("Calendarview Size %d %d ", width(), height()); 345 //qDebug("Calendarview Size %d %d ", width(), height());
346#endif 346#endif
347 347
348 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 348 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
349 SLOT( showDates( const KCal::DateList & ) ) ); 349 SLOT( showDates( const KCal::DateList & ) ) );
350 350
351 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 351 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
352 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 352 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
353 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 353 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
354 mNavigator, SLOT( selectPreviousYear() ) ); 354 mNavigator, SLOT( selectPreviousYear() ) );
355 connect( mNavigatorBar, SIGNAL( goNextYear() ), 355 connect( mNavigatorBar, SIGNAL( goNextYear() ),
356 mNavigator, SLOT( selectNextYear() ) ); 356 mNavigator, SLOT( selectNextYear() ) );
357 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 357 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
358 mNavigator, SLOT( selectPreviousMonth() ) ); 358 mNavigator, SLOT( selectPreviousMonth() ) );
359 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 359 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
360 mNavigator, SLOT( selectNextMonth() ) ); 360 mNavigator, SLOT( selectNextMonth() ) );
361 361
362 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 362 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
363 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 363 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
364 364
365 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 365 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
366 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 366 mNavigator, SLOT( selectWeek( const QDate & ) ) );
367 367
368 connect( mDateNavigator, SIGNAL( goPrevYear() ), 368 connect( mDateNavigator, SIGNAL( goPrevYear() ),
369 mNavigator, SLOT( selectPreviousYear() ) ); 369 mNavigator, SLOT( selectPreviousYear() ) );
370 connect( mDateNavigator, SIGNAL( goNextYear() ), 370 connect( mDateNavigator, SIGNAL( goNextYear() ),
371 mNavigator, SLOT( selectNextYear() ) ); 371 mNavigator, SLOT( selectNextYear() ) );
372 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 372 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
373 mNavigator, SLOT( selectPreviousMonth() ) ); 373 mNavigator, SLOT( selectPreviousMonth() ) );
374 connect( mDateNavigator, SIGNAL( goNextMonth() ), 374 connect( mDateNavigator, SIGNAL( goNextMonth() ),
375 mNavigator, SLOT( selectNextMonth() ) ); 375 mNavigator, SLOT( selectNextMonth() ) );
376 376
377 connect( mDateNavigator, SIGNAL( goPrevious() ), 377 connect( mDateNavigator, SIGNAL( goPrevious() ),
378 mNavigator, SLOT( selectPrevious() ) ); 378 mNavigator, SLOT( selectPrevious() ) );
379 connect( mDateNavigator, SIGNAL( goNext() ), 379 connect( mDateNavigator, SIGNAL( goNext() ),
380 mNavigator, SLOT( selectNext() ) ); 380 mNavigator, SLOT( selectNext() ) );
381 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 381 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
382 mNavigator, SLOT( slotMonthSelect( int ) ) ); 382 mNavigator, SLOT( slotMonthSelect( int ) ) );
383 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 383 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
384 mNavigator, SLOT( slotMonthSelect( int ) ) ); 384 mNavigator, SLOT( slotMonthSelect( int ) ) );
385 385
386 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 386 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
387 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 387 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
388 388
389 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 389 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
390 SLOT( eventAdded( Event *) ) ); 390 SLOT( eventAdded( Event *) ) );
391 391
392 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 392 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
393 393
394 connect( this, SIGNAL( configChanged() ), 394 connect( this, SIGNAL( configChanged() ),
395 mDateNavigator, SLOT( updateConfig() ) ); 395 mDateNavigator, SLOT( updateConfig() ) );
396 396
397 connect( mTodoList, SIGNAL( newTodoSignal() ), 397 connect( mTodoList, SIGNAL( newTodoSignal() ),
398 SLOT( newTodo() ) ); 398 SLOT( newTodo() ) );
399 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 399 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
400 SLOT( newSubTodo( Todo * ) ) ); 400 SLOT( newSubTodo( Todo * ) ) );
401 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 401 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
402 SLOT( editTodo( Todo * ) ) ); 402 SLOT( editTodo( Todo * ) ) );
403 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 403 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
404 SLOT( showTodo( Todo *) ) ); 404 SLOT( showTodo( Todo *) ) );
405 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 405 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
406 SLOT( deleteTodo( Todo *) ) ); 406 SLOT( deleteTodo( Todo *) ) );
407 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 407 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
408 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 408 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
409 SLOT( purgeCompleted() ) ); 409 SLOT( purgeCompleted() ) );
410 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 410 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
411 SIGNAL( todoModified( Todo *, int ) ) ); 411 SIGNAL( todoModified( Todo *, int ) ) );
412 412
413 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 413 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
414 this, SLOT ( cloneIncidence( Incidence * ) ) ); 414 this, SLOT ( cloneIncidence( Incidence * ) ) );
415 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 415 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
416 this, SLOT (cancelIncidence( Incidence * ) ) ); 416 this, SLOT (cancelIncidence( Incidence * ) ) );
417 417
418 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 418 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
419 this, SLOT ( moveIncidence( Incidence * ) ) ); 419 this, SLOT ( moveIncidence( Incidence * ) ) );
420 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 420 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
421 this, SLOT ( beamIncidence( Incidence * ) ) ); 421 this, SLOT ( beamIncidence( Incidence * ) ) );
422 422
423 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 423 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
424 this, SLOT ( todo_unsub( Todo * ) ) ); 424 this, SLOT ( todo_unsub( Todo * ) ) );
425 425
426 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 426 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
427 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 427 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
428 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 428 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
429 SLOT( updateTodo( Todo *, int ) ) ); 429 SLOT( updateTodo( Todo *, int ) ) );
430 connect( this, SIGNAL( todoModified( Todo *, int )), this, 430 connect( this, SIGNAL( todoModified( Todo *, int )), this,
431 SLOT( changeTodoDisplay( Todo *, int ) ) ); 431 SLOT( changeTodoDisplay( Todo *, int ) ) );
432 432
433 433
434 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 434 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
435 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 435 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
436 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 436 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
437 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 437 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
438 438
439 439
440 440
441 441
442 442
443 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 443 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
444 SLOT(checkClipboard())); 444 SLOT(checkClipboard()));
445 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 445 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
446 SLOT( processTodoListSelection( Incidence * ) ) ); 446 SLOT( processTodoListSelection( Incidence * ) ) );
447 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 447 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
448 448
449 // kdDebug() << "CalendarView::CalendarView() done" << endl; 449 // kdDebug() << "CalendarView::CalendarView() done" << endl;
450 450
451 mDateFrame = new QVBox(0,0,WType_Popup); 451 mDateFrame = new QVBox(0,0,WType_Popup);
452 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 452 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
453 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 453 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
454 mDateFrame->setLineWidth(3); 454 mDateFrame->setLineWidth(3);
455 mDateFrame->hide(); 455 mDateFrame->hide();
456 mDateFrame->setCaption( i18n( "Pick a date to display")); 456 mDateFrame->setCaption( i18n( "Pick a date to display"));
457 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 457 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
458 458
459 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 459 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
460 460
461 mEventEditor = mDialogManager->getEventEditor(); 461 mEventEditor = mDialogManager->getEventEditor();
462 mTodoEditor = mDialogManager->getTodoEditor(); 462 mTodoEditor = mDialogManager->getTodoEditor();
463 463
464 mFlagEditDescription = false; 464 mFlagEditDescription = false;
465 465
466 mSuspendTimer = new QTimer( this ); 466 mSuspendTimer = new QTimer( this );
467 mAlarmTimer = new QTimer( this ); 467 mAlarmTimer = new QTimer( this );
468 mRecheckAlarmTimer = new QTimer( this ); 468 mRecheckAlarmTimer = new QTimer( this );
469 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 469 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
470 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 470 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
471 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 471 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
472 mAlarmDialog = new AlarmDialog( this ); 472 mAlarmDialog = new AlarmDialog( this );
473 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 473 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
474 mAlarmDialog->setServerNotification( false ); 474 mAlarmDialog->setServerNotification( false );
475 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 475 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
476 476
477 477
478#ifndef DESKTOP_VERSION 478#ifndef DESKTOP_VERSION
479//US listen for arriving address resultsets 479//US listen for arriving address resultsets
480 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 480 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
481 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 481 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
482#endif 482#endif
483 483
484} 484}
485 485
486 486
487CalendarView::~CalendarView() 487CalendarView::~CalendarView()
488{ 488{
489 // kdDebug() << "~CalendarView()" << endl; 489 // kdDebug() << "~CalendarView()" << endl;
490 //qDebug("CalendarView::~CalendarView() "); 490 //qDebug("CalendarView::~CalendarView() ");
491 delete mDialogManager; 491 delete mDialogManager;
492 delete mViewManager; 492 delete mViewManager;
493 delete mStorage; 493 delete mStorage;
494 delete mDateFrame ; 494 delete mDateFrame ;
495 delete beamDialog; 495 delete beamDialog;
496 //kdDebug() << "~CalendarView() done" << endl; 496 //kdDebug() << "~CalendarView() done" << endl;
497} 497}
498 498
499void CalendarView::showDay( QDate d ) 499void CalendarView::showDay( QDate d )
500{ 500{
501 dateNavigator()->blockSignals( true ); 501 dateNavigator()->blockSignals( true );
502 dateNavigator()->selectDate( d ); 502 dateNavigator()->selectDate( d );
503 dateNavigator()->blockSignals( false ); 503 dateNavigator()->blockSignals( false );
504 mViewManager->showDayView(); 504 mViewManager->showDayView();
505 //dateNavigator()->selectDate( d ); 505 //dateNavigator()->selectDate( d );
506} 506}
507void CalendarView::timerAlarm() 507void CalendarView::timerAlarm()
508{ 508{
509 //qDebug("CalendarView::timerAlarm() "); 509 //qDebug("CalendarView::timerAlarm() ");
510 computeAlarm(mAlarmNotification ); 510 computeAlarm(mAlarmNotification );
511} 511}
512 512
513void CalendarView::suspendAlarm() 513void CalendarView::suspendAlarm()
514{ 514{
515 //qDebug(" CalendarView::suspendAlarm() "); 515 //qDebug(" CalendarView::suspendAlarm() ");
516 computeAlarm(mSuspendAlarmNotification ); 516 computeAlarm(mSuspendAlarmNotification );
517 517
518} 518}
519 519
520void CalendarView::startAlarm( QString mess , QString filename) 520void CalendarView::startAlarm( QString mess , QString filename)
521{ 521{
522 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 522 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
523 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 523 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
524 524
525} 525}
526 526
527void CalendarView::checkNextTimerAlarm() 527void CalendarView::checkNextTimerAlarm()
528{ 528{
529 mCalendar->checkAlarmForIncidence( 0, true ); 529 mCalendar->checkAlarmForIncidence( 0, true );
530} 530}
531 531
532void CalendarView::computeAlarm( QString msg ) 532void CalendarView::computeAlarm( QString msg )
533{ 533{
534 534
535 QString mess = msg; 535 QString mess = msg;
536 QString mAlarmMessage = mess.mid( 9 ); 536 QString mAlarmMessage = mess.mid( 9 );
537 QString filename = MainWindow::resourcePath(); 537 QString filename = MainWindow::resourcePath();
538 filename += "koalarm.wav"; 538 filename += "koalarm.wav";
539 QString tempfilename; 539 QString tempfilename;
540 if ( mess.left( 13 ) == "suspend_alarm") { 540 if ( mess.left( 13 ) == "suspend_alarm") {
541 bool error = false; 541 bool error = false;
542 int len = mess.mid( 13 ).find("+++"); 542 int len = mess.mid( 13 ).find("+++");
543 if ( len < 2 ) 543 if ( len < 2 )
544 error = true; 544 error = true;
545 else { 545 else {
546 tempfilename = mess.mid( 13, len ); 546 tempfilename = mess.mid( 13, len );
547 if ( !QFile::exists( tempfilename ) ) 547 if ( !QFile::exists( tempfilename ) )
548 error = true; 548 error = true;
549 } 549 }
550 if ( ! error ) { 550 if ( ! error ) {
551 filename = tempfilename; 551 filename = tempfilename;
552 } 552 }
553 mAlarmMessage = mess.mid( 13+len+3 ); 553 mAlarmMessage = mess.mid( 13+len+3 );
554 //qDebug("suspend file %s ",tempfilename.latin1() ); 554 //qDebug("suspend file %s ",tempfilename.latin1() );
555 startAlarm( mAlarmMessage, filename); 555 startAlarm( mAlarmMessage, filename);
556 return; 556 return;
557 } 557 }
558 if ( mess.left( 11 ) == "timer_alarm") { 558 if ( mess.left( 11 ) == "timer_alarm") {
559 //mTimerTime = 0; 559 //mTimerTime = 0;
560 startAlarm( mess.mid( 11 ), filename ); 560 startAlarm( mess.mid( 11 ), filename );
561 return; 561 return;
562 } 562 }
563 if ( mess.left( 10 ) == "proc_alarm") { 563 if ( mess.left( 10 ) == "proc_alarm") {
564 bool error = false; 564 bool error = false;
565 int len = mess.mid( 10 ).find("+++"); 565 int len = mess.mid( 10 ).find("+++");
566 if ( len < 2 ) 566 if ( len < 2 )
567 error = true; 567 error = true;
568 else { 568 else {
569 tempfilename = mess.mid( 10, len ); 569 tempfilename = mess.mid( 10, len );
570 if ( !QFile::exists( tempfilename ) ) 570 if ( !QFile::exists( tempfilename ) )
571 error = true; 571 error = true;
572 } 572 }
573 if ( error ) { 573 if ( error ) {
574 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 574 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
575 mAlarmMessage += mess.mid( 10+len+3+9 ); 575 mAlarmMessage += mess.mid( 10+len+3+9 );
576 } else { 576 } else {
577 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 577 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
578 //qDebug("-----system command %s ",tempfilename.latin1() ); 578 //qDebug("-----system command %s ",tempfilename.latin1() );
579#ifndef _WIN32_ 579#ifndef _WIN32_
580 if ( vfork () == 0 ) { 580 if ( vfork () == 0 ) {
581 execl ( tempfilename.latin1(), 0 ); 581 execl ( tempfilename.latin1(), 0 );
582 return; 582 return;
583 } 583 }
584#else 584#else
585 QProcess* p = new QProcess(); 585 QProcess* p = new QProcess();
586 p->addArgument( tempfilename.latin1() ); 586 p->addArgument( tempfilename.latin1() );
587 p->start(); 587 p->start();
588 return; 588 return;
589#endif 589#endif
590 590
591 return; 591 return;
592 } 592 }
593 593
594 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 594 //qDebug("+++++++system command %s ",tempfilename.latin1() );
595 } 595 }
596 if ( mess.left( 11 ) == "audio_alarm") { 596 if ( mess.left( 11 ) == "audio_alarm") {
597 bool error = false; 597 bool error = false;
598 int len = mess.mid( 11 ).find("+++"); 598 int len = mess.mid( 11 ).find("+++");
599 if ( len < 2 ) 599 if ( len < 2 )
600 error = true; 600 error = true;
601 else { 601 else {
602 tempfilename = mess.mid( 11, len ); 602 tempfilename = mess.mid( 11, len );
603 if ( !QFile::exists( tempfilename ) ) 603 if ( !QFile::exists( tempfilename ) )
604 error = true; 604 error = true;
605 } 605 }
606 if ( ! error ) { 606 if ( ! error ) {
607 filename = tempfilename; 607 filename = tempfilename;
608 } 608 }
609 mAlarmMessage = mess.mid( 11+len+3+9 ); 609 mAlarmMessage = mess.mid( 11+len+3+9 );
610 //qDebug("audio file command %s ",tempfilename.latin1() ); 610 //qDebug("audio file command %s ",tempfilename.latin1() );
611 } 611 }
612 if ( mess.left( 9 ) == "cal_alarm") { 612 if ( mess.left( 9 ) == "cal_alarm") {
613 mAlarmMessage = mess.mid( 9 ) ; 613 mAlarmMessage = mess.mid( 9 ) ;
614 } 614 }
615 615
616 startAlarm( mAlarmMessage, filename ); 616 startAlarm( mAlarmMessage, filename );
617 617
618 618
619} 619}
620 620
621void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 621void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
622{ 622{
623 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 623 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
624 624
625 mSuspendAlarmNotification = noti; 625 mSuspendAlarmNotification = noti;
626 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 626 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
627 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 627 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
628 mSuspendTimer->start( ms , true ); 628 mSuspendTimer->start( ms , true );
629 629
630} 630}
631 631
632void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 632void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
633{ 633{
634 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 634 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
635 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 635 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
636#ifndef DESKTOP_VERSION 636#ifndef DESKTOP_VERSION
637 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 637 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
638#endif 638#endif
639 return; 639 return;
640 } 640 }
641 int maxSec; 641 int maxSec;
642 //maxSec = 5; //testing only 642 //maxSec = 5; //testing only
643 maxSec = 86400+3600; // one day+1hour 643 maxSec = 86400+3600; // one day+1hour
644 mAlarmNotification = noti; 644 mAlarmNotification = noti;
645 int sec = QDateTime::currentDateTime().secsTo( qdt ); 645 int sec = QDateTime::currentDateTime().secsTo( qdt );
646 if ( sec > maxSec ) { 646 if ( sec > maxSec ) {
647 mRecheckAlarmTimer->start( maxSec * 1000 ); 647 mRecheckAlarmTimer->start( maxSec * 1000 );
648 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 648 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
649 return; 649 return;
650 } else { 650 } else {
651 mRecheckAlarmTimer->stop(); 651 mRecheckAlarmTimer->stop();
652 } 652 }
653 //qDebug("Alarm timer started with secs: %d ", sec); 653 //qDebug("Alarm timer started with secs: %d ", sec);
654 mAlarmTimer->start( sec *1000 , true ); 654 mAlarmTimer->start( sec *1000 , true );
655 655
656} 656}
657// called by mRecheckAlarmTimer to get next alarm 657// called by mRecheckAlarmTimer to get next alarm
658// we need this, because a QTimer has only a max range of 25 days 658// we need this, because a QTimer has only a max range of 25 days
659void CalendarView::recheckTimerAlarm() 659void CalendarView::recheckTimerAlarm()
660{ 660{
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662 mRecheckAlarmTimer->stop(); 662 mRecheckAlarmTimer->stop();
663 mCalendar->checkAlarmForIncidence( 0, true ); 663 mCalendar->checkAlarmForIncidence( 0, true );
664} 664}
665void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 665void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
666{ 666{
667 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 667 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
668 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 668 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
669#ifndef DESKTOP_VERSION 669#ifndef DESKTOP_VERSION
670 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 670 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
671#endif 671#endif
672 return; 672 return;
673 } 673 }
674 mAlarmTimer->stop(); 674 mAlarmTimer->stop();
675} 675}
676void CalendarView::selectWeekNum ( int num ) 676void CalendarView::selectWeekNum ( int num )
677{ 677{
678 dateNavigator()->blockSignals( true ); 678 dateNavigator()->blockSignals( true );
679 dateNavigator()->selectWeek( num ); 679 dateNavigator()->selectWeek( num );
680 dateNavigator()->blockSignals( false ); 680 dateNavigator()->blockSignals( false );
681 mViewManager->showWeekView(); 681 mViewManager->showWeekView();
682} 682}
683KOViewManager *CalendarView::viewManager() 683KOViewManager *CalendarView::viewManager()
684{ 684{
685 return mViewManager; 685 return mViewManager;
686} 686}
687 687
688KODialogManager *CalendarView::dialogManager() 688KODialogManager *CalendarView::dialogManager()
689{ 689{
690 return mDialogManager; 690 return mDialogManager;
691} 691}
692 692
693QDate CalendarView::startDate() 693QDate CalendarView::startDate()
694{ 694{
695 DateList dates = mNavigator->selectedDates(); 695 DateList dates = mNavigator->selectedDates();
696 696
697 return dates.first(); 697 return dates.first();
698} 698}
699 699
700QDate CalendarView::endDate() 700QDate CalendarView::endDate()
701{ 701{
702 DateList dates = mNavigator->selectedDates(); 702 DateList dates = mNavigator->selectedDates();
703 703
704 return dates.last(); 704 return dates.last();
705} 705}
706 706
707 707
708void CalendarView::createPrinter() 708void CalendarView::createPrinter()
709{ 709{
710#ifndef KORG_NOPRINTER 710#ifndef KORG_NOPRINTER
711 if (!mCalPrinter) { 711 if (!mCalPrinter) {
712 mCalPrinter = new CalPrinter(this, mCalendar); 712 mCalPrinter = new CalPrinter(this, mCalendar);
713 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 713 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
714 } 714 }
715#endif 715#endif
716} 716}
717 717
718 718
719//KOPrefs::instance()->mWriteBackFile 719//KOPrefs::instance()->mWriteBackFile
720//KOPrefs::instance()->mWriteBackExistingOnly 720//KOPrefs::instance()->mWriteBackExistingOnly
721 721
722// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 722// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
723// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 723// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
724// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 724// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
725// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 725// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
726// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 726// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
727// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 727// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
728 728
729int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 729int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
730{ 730{
731 731
732 // 0 equal 732 // 0 equal
733 // 1 take local 733 // 1 take local
734 // 2 take remote 734 // 2 take remote
735 // 3 cancel 735 // 3 cancel
736 QDateTime lastSync = mLastCalendarSync; 736 QDateTime lastSync = mLastCalendarSync;
737 QDateTime localMod = local->lastModified(); 737 QDateTime localMod = local->lastModified();
738 QDateTime remoteMod = remote->lastModified(); 738 QDateTime remoteMod = remote->lastModified();
739 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 739 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
740 bool remCh, locCh; 740 bool remCh, locCh;
741 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 741 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
742 //if ( remCh ) 742 //if ( remCh )
743 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 743 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
744 locCh = ( localMod > mLastCalendarSync ); 744 locCh = ( localMod > mLastCalendarSync );
745 if ( !remCh && ! locCh ) { 745 if ( !remCh && ! locCh ) {
746 //qDebug("both not changed "); 746 //qDebug("both not changed ");
747 lastSync = localMod.addDays(1); 747 lastSync = localMod.addDays(1);
748 if ( mode <= SYNC_PREF_ASK ) 748 if ( mode <= SYNC_PREF_ASK )
749 return 0; 749 return 0;
750 } else { 750 } else {
751 if ( locCh ) { 751 if ( locCh ) {
752 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 752 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
753 lastSync = localMod.addDays( -1 ); 753 lastSync = localMod.addDays( -1 );
754 if ( !remCh ) 754 if ( !remCh )
755 remoteMod = ( lastSync.addDays( -1 ) ); 755 remoteMod = ( lastSync.addDays( -1 ) );
756 } else { 756 } else {
757 //qDebug(" not loc changed "); 757 //qDebug(" not loc changed ");
758 lastSync = localMod.addDays( 1 ); 758 lastSync = localMod.addDays( 1 );
759 if ( remCh ) 759 if ( remCh )
760 remoteMod =( lastSync.addDays( 1 ) ); 760 remoteMod =( lastSync.addDays( 1 ) );
761 761
762 } 762 }
763 } 763 }
764 full = true; 764 full = true;
765 if ( mode < SYNC_PREF_ASK ) 765 if ( mode < SYNC_PREF_ASK )
766 mode = SYNC_PREF_ASK; 766 mode = SYNC_PREF_ASK;
767 } else { 767 } else {
768 if ( localMod == remoteMod ) 768 if ( localMod == remoteMod )
769 // if ( local->revision() == remote->revision() ) 769 // if ( local->revision() == remote->revision() )
770 return 0; 770 return 0;
771 771
772 } 772 }
773 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 773 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
774 774
775 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 775 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
776 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 776 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
777 //full = true; //debug only 777 //full = true; //debug only
778 if ( full ) { 778 if ( full ) {
779 bool equ = false; 779 bool equ = false;
780 if ( local->type() == "Event" ) { 780 if ( local->type() == "Event" ) {
781 equ = (*((Event*) local) == *((Event*) remote)); 781 equ = (*((Event*) local) == *((Event*) remote));
782 } 782 }
783 else if ( local->type() =="Todo" ) 783 else if ( local->type() =="Todo" )
784 equ = (*((Todo*) local) == (*(Todo*) remote)); 784 equ = (*((Todo*) local) == (*(Todo*) remote));
785 else if ( local->type() =="Journal" ) 785 else if ( local->type() =="Journal" )
786 equ = (*((Journal*) local) == *((Journal*) remote)); 786 equ = (*((Journal*) local) == *((Journal*) remote));
787 if ( equ ) { 787 if ( equ ) {
788 //qDebug("equal "); 788 //qDebug("equal ");
789 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 789 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
790 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 790 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
791 } 791 }
792 if ( mode < SYNC_PREF_FORCE_LOCAL ) 792 if ( mode < SYNC_PREF_FORCE_LOCAL )
793 return 0; 793 return 0;
794 794
795 }//else //debug only 795 }//else //debug only
796 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 796 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
797 } 797 }
798 int result; 798 int result;
799 bool localIsNew; 799 bool localIsNew;
800 //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() ); 800 //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() );
801 801
802 if ( full && mode < SYNC_PREF_NEWEST ) 802 if ( full && mode < SYNC_PREF_NEWEST )
803 mode = SYNC_PREF_ASK; 803 mode = SYNC_PREF_ASK;
804 804
805 switch( mode ) { 805 switch( mode ) {
806 case SYNC_PREF_LOCAL: 806 case SYNC_PREF_LOCAL:
807 if ( lastSync > remoteMod ) 807 if ( lastSync > remoteMod )
808 return 1; 808 return 1;
809 if ( lastSync > localMod ) 809 if ( lastSync > localMod )
810 return 2; 810 return 2;
811 return 1; 811 return 1;
812 break; 812 break;
813 case SYNC_PREF_REMOTE: 813 case SYNC_PREF_REMOTE:
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 2; 818 return 2;
819 break; 819 break;
820 case SYNC_PREF_NEWEST: 820 case SYNC_PREF_NEWEST:
821 if ( localMod > remoteMod ) 821 if ( localMod > remoteMod )
822 return 1; 822 return 1;
823 else 823 else
824 return 2; 824 return 2;
825 break; 825 break;
826 case SYNC_PREF_ASK: 826 case SYNC_PREF_ASK:
827 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 827 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
828 if ( lastSync > remoteMod ) 828 if ( lastSync > remoteMod )
829 return 1; 829 return 1;
830 if ( lastSync > localMod ) 830 if ( lastSync > localMod )
831 return 2; 831 return 2;
832 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 832 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
833 localIsNew = localMod >= remoteMod; 833 localIsNew = localMod >= remoteMod;
834 if ( localIsNew ) 834 if ( localIsNew )
835 getEventViewerDialog()->setColorMode( 1 ); 835 getEventViewerDialog()->setColorMode( 1 );
836 else 836 else
837 getEventViewerDialog()->setColorMode( 2 ); 837 getEventViewerDialog()->setColorMode( 2 );
838 getEventViewerDialog()->setIncidence(local); 838 getEventViewerDialog()->setIncidence(local);
839 if ( localIsNew ) 839 if ( localIsNew )
840 getEventViewerDialog()->setColorMode( 2 ); 840 getEventViewerDialog()->setColorMode( 2 );
841 else 841 else
842 getEventViewerDialog()->setColorMode( 1 ); 842 getEventViewerDialog()->setColorMode( 1 );
843 getEventViewerDialog()->addIncidence(remote); 843 getEventViewerDialog()->addIncidence(remote);
844 getEventViewerDialog()->setColorMode( 0 ); 844 getEventViewerDialog()->setColorMode( 0 );
845 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 845 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
846 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 846 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
847 getEventViewerDialog()->showMe(); 847 getEventViewerDialog()->showMe();
848 result = getEventViewerDialog()->executeS( localIsNew ); 848 result = getEventViewerDialog()->executeS( localIsNew );
849 return result; 849 return result;
850 850
851 break; 851 break;
852 case SYNC_PREF_FORCE_LOCAL: 852 case SYNC_PREF_FORCE_LOCAL:
853 return 1; 853 return 1;
854 break; 854 break;
855 case SYNC_PREF_FORCE_REMOTE: 855 case SYNC_PREF_FORCE_REMOTE:
856 return 2; 856 return 2;
857 break; 857 break;
858 858
859 default: 859 default:
860 // SYNC_PREF_TAKE_BOTH not implemented 860 // SYNC_PREF_TAKE_BOTH not implemented
861 break; 861 break;
862 } 862 }
863 return 0; 863 return 0;
864} 864}
865Event* CalendarView::getLastSyncEvent() 865Event* CalendarView::getLastSyncEvent()
866{ 866{
867 Event* lse; 867 Event* lse;
868 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 868 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
869 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 869 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
870 if (!lse) { 870 if (!lse) {
871 lse = new Event(); 871 lse = new Event();
872 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 872 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
873 QString sum = ""; 873 QString sum = "";
874 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 874 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
875 sum = "E: "; 875 sum = "E: ";
876 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 876 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
877 lse->setDtStart( mLastCalendarSync ); 877 lse->setDtStart( mLastCalendarSync );
878 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 878 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
879 lse->setCategories( i18n("SyncEvent") ); 879 lse->setCategories( i18n("SyncEvent") );
880 lse->setReadOnly( true ); 880 lse->setReadOnly( true );
881 mCalendar->addEvent( lse ); 881 mCalendar->addEvent( lse );
882 } 882 }
883 883
884 return lse; 884 return lse;
885 885
886} 886}
887 887
888// we check, if the to delete event has a id for a profile 888// we check, if the to delete event has a id for a profile
889// if yes, we set this id in the profile to delete 889// if yes, we set this id in the profile to delete
890void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 890void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
891{ 891{
892 if ( lastSync.count() == 0 ) { 892 if ( lastSync.count() == 0 ) {
893 //qDebug(" lastSync.count() == 0"); 893 //qDebug(" lastSync.count() == 0");
894 return; 894 return;
895 } 895 }
896 if ( toDelete->type() == "Journal" ) 896 if ( toDelete->type() == "Journal" )
897 return; 897 return;
898 898
899 Event* eve = lastSync.first(); 899 Event* eve = lastSync.first();
900 900
901 while ( eve ) { 901 while ( eve ) {
902 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 902 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
903 if ( !id.isEmpty() ) { 903 if ( !id.isEmpty() ) {
904 QString des = eve->description(); 904 QString des = eve->description();
905 QString pref = "e"; 905 QString pref = "e";
906 if ( toDelete->type() == "Todo" ) 906 if ( toDelete->type() == "Todo" )
907 pref = "t"; 907 pref = "t";
908 des += pref+ id + ","; 908 des += pref+ id + ",";
909 eve->setReadOnly( false ); 909 eve->setReadOnly( false );
910 eve->setDescription( des ); 910 eve->setDescription( des );
911 //qDebug("setdes %s ", des.latin1()); 911 //qDebug("setdes %s ", des.latin1());
912 eve->setReadOnly( true ); 912 eve->setReadOnly( true );
913 } 913 }
914 eve = lastSync.next(); 914 eve = lastSync.next();
915 } 915 }
916 916
917} 917}
918void CalendarView::checkExternalId( Incidence * inc ) 918void CalendarView::checkExternalId( Incidence * inc )
919{ 919{
920 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 920 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
921 checkExternSyncEvent( lastSync, inc ); 921 checkExternSyncEvent( lastSync, inc );
922 922
923} 923}
924bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 924bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
925{ 925{
926 bool syncOK = true; 926 bool syncOK = true;
927 int addedEvent = 0; 927 int addedEvent = 0;
928 int addedEventR = 0; 928 int addedEventR = 0;
929 int deletedEventR = 0; 929 int deletedEventR = 0;
930 int deletedEventL = 0; 930 int deletedEventL = 0;
931 int changedLocal = 0; 931 int changedLocal = 0;
932 int changedRemote = 0; 932 int changedRemote = 0;
933 int filteredIN = 0; 933 int filteredIN = 0;
934 int filteredOUT = 0; 934 int filteredOUT = 0;
935 //QPtrList<Event> el = local->rawEvents(); 935 //QPtrList<Event> el = local->rawEvents();
936 Event* eventR; 936 Event* eventR;
937 QString uid; 937 QString uid;
938 int take; 938 int take;
939 Event* eventL; 939 Event* eventL;
940 Event* eventRSync; 940 Event* eventRSync;
941 Event* eventLSync; 941 Event* eventLSync;
942 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 942 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
943 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 943 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
944 bool fullDateRange = false; 944 bool fullDateRange = false;
945 local->resetTempSyncStat(); 945 local->resetTempSyncStat();
946 mLastCalendarSync = QDateTime::currentDateTime(); 946 mLastCalendarSync = QDateTime::currentDateTime();
947 if ( mSyncManager->syncWithDesktop() ) { 947 if ( mSyncManager->syncWithDesktop() ) {
948 remote->resetPilotStat(1); 948 remote->resetPilotStat(1);
949 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 949 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
950 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 950 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
951 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 951 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
952 } else { 952 } else {
953 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 953 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
954 } 954 }
955 } 955 }
956 QDateTime modifiedCalendar = mLastCalendarSync; 956 QDateTime modifiedCalendar = mLastCalendarSync;
957 eventLSync = getLastSyncEvent(); 957 eventLSync = getLastSyncEvent();
958 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 958 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
959 if ( eventR ) { 959 if ( eventR ) {
960 eventRSync = (Event*) eventR->clone(); 960 eventRSync = (Event*) eventR->clone();
961 remote->deleteEvent(eventR ); 961 remote->deleteEvent(eventR );
962 962
963 } else { 963 } else {
964 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 964 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
965 eventRSync = (Event*)eventLSync->clone(); 965 eventRSync = (Event*)eventLSync->clone();
966 } else { 966 } else {
967 fullDateRange = true; 967 fullDateRange = true;
968 eventRSync = new Event(); 968 eventRSync = new Event();
969 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 969 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
970 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 970 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
971 eventRSync->setDtStart( mLastCalendarSync ); 971 eventRSync->setDtStart( mLastCalendarSync );
972 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 972 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
973 eventRSync->setCategories( i18n("SyncEvent") ); 973 eventRSync->setCategories( i18n("SyncEvent") );
974 } 974 }
975 } 975 }
976 if ( eventLSync->dtStart() == mLastCalendarSync ) 976 if ( eventLSync->dtStart() == mLastCalendarSync )
977 fullDateRange = true; 977 fullDateRange = true;
978 978
979 if ( ! fullDateRange ) { 979 if ( ! fullDateRange ) {
980 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 980 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
981 981
982 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 982 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
983 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 983 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
984 fullDateRange = true; 984 fullDateRange = true;
985 } 985 }
986 } 986 }
987 if ( mSyncManager->syncWithDesktop() ) { 987 if ( mSyncManager->syncWithDesktop() ) {
988 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 988 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
989 } 989 }
990 if ( fullDateRange ) 990 if ( fullDateRange )
991 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 991 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
992 else 992 else
993 mLastCalendarSync = eventLSync->dtStart(); 993 mLastCalendarSync = eventLSync->dtStart();
994 // for resyncing if own file has changed 994 // for resyncing if own file has changed
995 if ( mCurrentSyncDevice == "deleteaftersync" ) { 995 if ( mCurrentSyncDevice == "deleteaftersync" ) {
996 mLastCalendarSync = loadedFileVersion; 996 mLastCalendarSync = loadedFileVersion;
997 //qDebug("setting mLastCalendarSync "); 997 //qDebug("setting mLastCalendarSync ");
998 } 998 }
999 //qDebug("*************************** "); 999 //qDebug("*************************** ");
1000 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1000 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1001 QPtrList<Incidence> er = remote->rawIncidences(); 1001 QPtrList<Incidence> er = remote->rawIncidences();
1002 Incidence* inR = er.first(); 1002 Incidence* inR = er.first();
1003 Incidence* inL; 1003 Incidence* inL;
1004 QProgressBar bar( er.count(),0 ); 1004 QProgressBar bar( er.count(),0 );
1005 bar.setCaption (i18n("Syncing - close to abort!") ); 1005 bar.setCaption (i18n("Syncing - close to abort!") );
1006 1006
1007 // ************** setting up filter ************* 1007 // ************** setting up filter *************
1008 CalFilter *filterIN = 0; 1008 CalFilter *filterIN = 0;
1009 CalFilter *filterOUT = 0; 1009 CalFilter *filterOUT = 0;
1010 CalFilter *filter = mFilters.first(); 1010 CalFilter *filter = mFilters.first();
1011 while(filter) { 1011 while(filter) {
1012 if ( filter->name() == mSyncManager->mFilterInCal ) 1012 if ( filter->name() == mSyncManager->mFilterInCal )
1013 filterIN = filter; 1013 filterIN = filter;
1014 if ( filter->name() == mSyncManager->mFilterOutCal ) 1014 if ( filter->name() == mSyncManager->mFilterOutCal )
1015 filterOUT = filter; 1015 filterOUT = filter;
1016 filter = mFilters.next(); 1016 filter = mFilters.next();
1017 } 1017 }
1018 int w = 300; 1018 int w = 300;
1019 if ( QApplication::desktop()->width() < 320 ) 1019 if ( QApplication::desktop()->width() < 320 )
1020 w = 220; 1020 w = 220;
1021 int h = bar.sizeHint().height() ; 1021 int h = bar.sizeHint().height() ;
1022 int dw = QApplication::desktop()->width(); 1022 int dw = QApplication::desktop()->width();
1023 int dh = QApplication::desktop()->height(); 1023 int dh = QApplication::desktop()->height();
1024 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1024 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1025 bar.show(); 1025 bar.show();
1026 int modulo = (er.count()/10)+1; 1026 int modulo = (er.count()/10)+1;
1027 int incCounter = 0; 1027 int incCounter = 0;
1028 while ( inR ) { 1028 while ( inR ) {
1029 if ( ! bar.isVisible() ) 1029 if ( ! bar.isVisible() )
1030 return false; 1030 return false;
1031 if ( incCounter % modulo == 0 ) 1031 if ( incCounter % modulo == 0 )
1032 bar.setProgress( incCounter ); 1032 bar.setProgress( incCounter );
1033 ++incCounter; 1033 ++incCounter;
1034 uid = inR->uid(); 1034 uid = inR->uid();
1035 bool skipIncidence = false; 1035 bool skipIncidence = false;
1036 if ( uid.left(15) == QString("last-syncEvent-") ) 1036 if ( uid.left(15) == QString("last-syncEvent-") )
1037 skipIncidence = true; 1037 skipIncidence = true;
1038 QString idS; 1038 QString idS;
1039 qApp->processEvents(); 1039 qApp->processEvents();
1040 if ( !skipIncidence ) { 1040 if ( !skipIncidence ) {
1041 inL = local->incidence( uid ); 1041 inL = local->incidence( uid );
1042 if ( inL ) { // maybe conflict - same uid in both calendars 1042 if ( inL ) { // maybe conflict - same uid in both calendars
1043 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1043 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1044 //qDebug("take %d %s ", take, inL->summary().latin1()); 1044 //qDebug("take %d %s ", take, inL->summary().latin1());
1045 if ( take == 3 ) 1045 if ( take == 3 )
1046 return false; 1046 return false;
1047 if ( take == 1 ) {// take local ********************** 1047 if ( take == 1 ) {// take local **********************
1048 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1048 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1049 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1049 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1050 else 1050 else
1051 idS = inR->IDStr(); 1051 idS = inR->IDStr();
1052 remote->deleteIncidence( inR ); 1052 remote->deleteIncidence( inR );
1053 inR = inL->clone(); 1053 inR = inL->clone();
1054 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1054 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1055 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1055 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1056 inR->setIDStr( idS ); 1056 inR->setIDStr( idS );
1057 remote->addIncidence( inR ); 1057 remote->addIncidence( inR );
1058 if ( mSyncManager->syncWithDesktop() ) 1058 if ( mSyncManager->syncWithDesktop() )
1059 inR->setPilotId( 2 ); 1059 inR->setPilotId( 2 );
1060 ++changedRemote; 1060 ++changedRemote;
1061 } else {// take remote ********************** 1061 } else {// take remote **********************
1062 idS = inL->IDStr(); 1062 idS = inL->IDStr();
1063 int pid = inL->pilotId(); 1063 int pid = inL->pilotId();
1064 local->deleteIncidence( inL ); 1064 local->deleteIncidence( inL );
1065 inL = inR->clone(); 1065 inL = inR->clone();
1066 if ( mSyncManager->syncWithDesktop() ) 1066 if ( mSyncManager->syncWithDesktop() )
1067 inL->setPilotId( pid ); 1067 inL->setPilotId( pid );
1068 inL->setIDStr( idS ); 1068 inL->setIDStr( idS );
1069 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1069 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1070 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1070 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1071 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1071 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1072 } 1072 }
1073 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1074 ++changedLocal; 1074 ++changedLocal;
1075 } 1075 }
1076 } 1076 }
1077 } else { // no conflict ********** add or delete remote 1077 } else { // no conflict ********** add or delete remote
1078 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1078 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1079 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1079 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1080 QString des = eventLSync->description(); 1080 QString des = eventLSync->description();
1081 QString pref = "e"; 1081 QString pref = "e";
1082 if ( inR->type() == "Todo" ) 1082 if ( inR->type() == "Todo" )
1083 pref = "t"; 1083 pref = "t";
1084 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1084 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1085 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1085 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1086 //remote->deleteIncidence( inR ); 1086 //remote->deleteIncidence( inR );
1087 ++deletedEventR; 1087 ++deletedEventR;
1088 } else { 1088 } else {
1089 inR->setLastModified( modifiedCalendar ); 1089 inR->setLastModified( modifiedCalendar );
1090 inL = inR->clone(); 1090 inL = inR->clone();
1091 inL->setIDStr( ":" ); 1091 inL->setIDStr( ":" );
1092 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1092 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1093 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1093 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1094 local->addIncidence( inL ); 1094 local->addIncidence( inL );
1095 ++addedEvent; 1095 ++addedEvent;
1096 1096
1097 } 1097 }
1098 } else { 1098 } else {
1099 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1099 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1100 inR->setLastModified( modifiedCalendar ); 1100 inR->setLastModified( modifiedCalendar );
1101 inL = inR->clone(); 1101 inL = inR->clone();
1102 inL->setIDStr( ":" ); 1102 inL->setIDStr( ":" );
1103 local->addIncidence( inL ); 1103 local->addIncidence( inL );
1104 ++addedEvent; 1104 ++addedEvent;
1105 1105
1106 } else { 1106 } else {
1107 checkExternSyncEvent(eventRSyncSharp, inR); 1107 checkExternSyncEvent(eventRSyncSharp, inR);
1108 remote->deleteIncidence( inR ); 1108 remote->deleteIncidence( inR );
1109 ++deletedEventR; 1109 ++deletedEventR;
1110 } 1110 }
1111 } 1111 }
1112 } else { 1112 } else {
1113 ++filteredIN; 1113 ++filteredIN;
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 inR = er.next(); 1117 inR = er.next();
1118 } 1118 }
1119 QPtrList<Incidence> el = local->rawIncidences(); 1119 QPtrList<Incidence> el = local->rawIncidences();
1120 inL = el.first(); 1120 inL = el.first();
1121 modulo = (el.count()/10)+1; 1121 modulo = (el.count()/10)+1;
1122 bar.setCaption (i18n("Add / remove events") ); 1122 bar.setCaption (i18n("Add / remove events") );
1123 bar.setTotalSteps ( el.count() ) ; 1123 bar.setTotalSteps ( el.count() ) ;
1124 bar.show(); 1124 bar.show();
1125 incCounter = 0; 1125 incCounter = 0;
1126 1126
1127 while ( inL ) { 1127 while ( inL ) {
1128 1128
1129 qApp->processEvents(); 1129 qApp->processEvents();
1130 if ( ! bar.isVisible() ) 1130 if ( ! bar.isVisible() )
1131 return false; 1131 return false;
1132 if ( incCounter % modulo == 0 ) 1132 if ( incCounter % modulo == 0 )
1133 bar.setProgress( incCounter ); 1133 bar.setProgress( incCounter );
1134 ++incCounter; 1134 ++incCounter;
1135 uid = inL->uid(); 1135 uid = inL->uid();
1136 bool skipIncidence = false; 1136 bool skipIncidence = false;
1137 if ( uid.left(15) == QString("last-syncEvent-") ) 1137 if ( uid.left(15) == QString("last-syncEvent-") )
1138 skipIncidence = true; 1138 skipIncidence = true;
1139 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1139 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1140 skipIncidence = true; 1140 skipIncidence = true;
1141 if ( !skipIncidence ) { 1141 if ( !skipIncidence ) {
1142 inR = remote->incidence( uid ); 1142 inR = remote->incidence( uid );
1143 if ( ! inR ) { 1143 if ( ! inR ) {
1144 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1144 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1145 // no conflict ********** add or delete local 1145 // no conflict ********** add or delete local
1146 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1146 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1147 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1147 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1148 checkExternSyncEvent(eventLSyncSharp, inL); 1148 checkExternSyncEvent(eventLSyncSharp, inL);
1149 local->deleteIncidence( inL ); 1149 local->deleteIncidence( inL );
1150 ++deletedEventL; 1150 ++deletedEventL;
1151 } else { 1151 } else {
1152 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1152 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1153 inL->removeID(mCurrentSyncDevice ); 1153 inL->removeID(mCurrentSyncDevice );
1154 ++addedEventR; 1154 ++addedEventR;
1155 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1155 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1156 inL->setLastModified( modifiedCalendar ); 1156 inL->setLastModified( modifiedCalendar );
1157 inR = inL->clone(); 1157 inR = inL->clone();
1158 inR->setIDStr( ":" ); 1158 inR->setIDStr( ":" );
1159 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1159 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1160 remote->addIncidence( inR ); 1160 remote->addIncidence( inR );
1161 } 1161 }
1162 } 1162 }
1163 } else { 1163 } else {
1164 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1164 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1165 checkExternSyncEvent(eventLSyncSharp, inL); 1165 checkExternSyncEvent(eventLSyncSharp, inL);
1166 local->deleteIncidence( inL ); 1166 local->deleteIncidence( inL );
1167 ++deletedEventL; 1167 ++deletedEventL;
1168 } else { 1168 } else {
1169 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1169 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1170 ++addedEventR; 1170 ++addedEventR;
1171 inL->setLastModified( modifiedCalendar ); 1171 inL->setLastModified( modifiedCalendar );
1172 inR = inL->clone(); 1172 inR = inL->clone();
1173 inR->setIDStr( ":" ); 1173 inR->setIDStr( ":" );
1174 remote->addIncidence( inR ); 1174 remote->addIncidence( inR );
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 } else { 1178 } else {
1179 ++filteredOUT; 1179 ++filteredOUT;
1180 } 1180 }
1181 } 1181 }
1182 } 1182 }
1183 inL = el.next(); 1183 inL = el.next();
1184 } 1184 }
1185 int delFut = 0; 1185 int delFut = 0;
1186 int remRem = 0; 1186 int remRem = 0;
1187 if ( mSyncManager->mWriteBackInFuture ) { 1187 if ( mSyncManager->mWriteBackInFuture ) {
1188 er = remote->rawIncidences(); 1188 er = remote->rawIncidences();
1189 remRem = er.count(); 1189 remRem = er.count();
1190 inR = er.first(); 1190 inR = er.first();
1191 QDateTime dt; 1191 QDateTime dt;
1192 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1192 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1193 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1193 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1194 while ( inR ) { 1194 while ( inR ) {
1195 if ( inR->type() == "Todo" ) { 1195 if ( inR->type() == "Todo" ) {
1196 Todo * t = (Todo*)inR; 1196 Todo * t = (Todo*)inR;
1197 if ( t->hasDueDate() ) 1197 if ( t->hasDueDate() )
1198 dt = t->dtDue(); 1198 dt = t->dtDue();
1199 else 1199 else
1200 dt = cur.addSecs( 62 ); 1200 dt = cur.addSecs( 62 );
1201 } 1201 }
1202 else if (inR->type() == "Event" ) { 1202 else if (inR->type() == "Event" ) {
1203 bool ok; 1203 bool ok;
1204 dt = inR->getNextOccurence( cur, &ok ); 1204 dt = inR->getNextOccurence( cur, &ok );
1205 if ( !ok ) 1205 if ( !ok )
1206 dt = cur.addSecs( -62 ); 1206 dt = cur.addSecs( -62 );
1207 } 1207 }
1208 else 1208 else
1209 dt = inR->dtStart(); 1209 dt = inR->dtStart();
1210 if ( dt < cur || dt > end ) { 1210 if ( dt < cur || dt > end ) {
1211 remote->deleteIncidence( inR ); 1211 remote->deleteIncidence( inR );
1212 ++delFut; 1212 ++delFut;
1213 } 1213 }
1214 inR = er.next(); 1214 inR = er.next();
1215 } 1215 }
1216 } 1216 }
1217 bar.hide(); 1217 bar.hide();
1218 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1218 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1219 eventLSync->setReadOnly( false ); 1219 eventLSync->setReadOnly( false );
1220 eventLSync->setDtStart( mLastCalendarSync ); 1220 eventLSync->setDtStart( mLastCalendarSync );
1221 eventRSync->setDtStart( mLastCalendarSync ); 1221 eventRSync->setDtStart( mLastCalendarSync );
1222 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1222 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1223 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1223 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1224 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1224 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1225 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1225 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1226 eventLSync->setReadOnly( true ); 1226 eventLSync->setReadOnly( true );
1227 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1227 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1228 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1228 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1229 remote->addEvent( eventRSync ); 1229 remote->addEvent( eventRSync );
1230 else 1230 else
1231 delete eventRSync; 1231 delete eventRSync;
1232 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1232 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1233 QString mes; 1233 QString mes;
1234 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 ); 1234 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 );
1235 QString delmess; 1235 QString delmess;
1236 if ( delFut ) { 1236 if ( delFut ) {
1237 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); 1237 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);
1238 mes += delmess; 1238 mes += delmess;
1239 } 1239 }
1240 mes = i18n("Local calendar changed!\n") +mes; 1240 mes = i18n("Local calendar changed!\n") +mes;
1241 mCalendar->checkAlarmForIncidence( 0, true ); 1241 mCalendar->checkAlarmForIncidence( 0, true );
1242 qDebug( mes ); 1242 qDebug( mes );
1243 if ( mSyncManager->mShowSyncSummary ) { 1243 if ( mSyncManager->mShowSyncSummary ) {
1244 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1244 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1245 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1245 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1246 qDebug("KO: WB cancelled "); 1246 qDebug("KO: WB cancelled ");
1247 return false; 1247 return false;
1248 } 1248 }
1249 } 1249 }
1250 return syncOK; 1250 return syncOK;
1251} 1251}
1252 1252
1253void CalendarView::setSyncDevice( QString s ) 1253void CalendarView::setSyncDevice( QString s )
1254{ 1254{
1255 mCurrentSyncDevice= s; 1255 mCurrentSyncDevice= s;
1256} 1256}
1257void CalendarView::setSyncName( QString s ) 1257void CalendarView::setSyncName( QString s )
1258{ 1258{
1259 mCurrentSyncName= s; 1259 mCurrentSyncName= s;
1260} 1260}
1261bool CalendarView::syncCalendar(QString filename, int mode) 1261bool CalendarView::syncCalendar(QString filename, int mode)
1262{ 1262{
1263 //qDebug("syncCalendar %s ", filename.latin1()); 1263 //qDebug("syncCalendar %s ", filename.latin1());
1264 mGlobalSyncMode = SYNC_MODE_NORMAL; 1264 mGlobalSyncMode = SYNC_MODE_NORMAL;
1265 CalendarLocal* calendar = new CalendarLocal(); 1265 CalendarLocal* calendar = new CalendarLocal();
1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1267 FileStorage* storage = new FileStorage( calendar ); 1267 FileStorage* storage = new FileStorage( calendar );
1268 bool syncOK = false; 1268 bool syncOK = false;
1269 storage->setFileName( filename ); 1269 storage->setFileName( filename );
1270 // qDebug("loading ... "); 1270 // qDebug("loading ... ");
1271 if ( storage->load() ) { 1271 if ( storage->load() ) {
1272 getEventViewerDialog()->setSyncMode( true ); 1272 getEventViewerDialog()->setSyncMode( true );
1273 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1273 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1274 getEventViewerDialog()->setSyncMode( false ); 1274 getEventViewerDialog()->setSyncMode( false );
1275 if ( syncOK ) { 1275 if ( syncOK ) {
1276 if ( mSyncManager->mWriteBackFile ) 1276 if ( mSyncManager->mWriteBackFile )
1277 { 1277 {
1278 storage->setSaveFormat( new ICalFormat() ); 1278 storage->setSaveFormat( new ICalFormat() );
1279 storage->save(); 1279 storage->save();
1280 } 1280 }
1281 } 1281 }
1282 setModified( true ); 1282 setModified( true );
1283 } 1283 }
1284 delete storage; 1284 delete storage;
1285 delete calendar; 1285 delete calendar;
1286 if ( syncOK ) 1286 if ( syncOK )
1287 updateView(); 1287 updateView();
1288 return syncOK; 1288 return syncOK;
1289} 1289}
1290 1290
1291void CalendarView::syncExternal( int mode ) 1291void CalendarView::syncExternal( int mode )
1292{ 1292{
1293 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1293 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1294 1294
1295 qApp->processEvents(); 1295 qApp->processEvents();
1296 CalendarLocal* calendar = new CalendarLocal(); 1296 CalendarLocal* calendar = new CalendarLocal();
1297 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1297 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1298 bool syncOK = false; 1298 bool syncOK = false;
1299 bool loadSuccess = false; 1299 bool loadSuccess = false;
1300 PhoneFormat* phoneFormat = 0; 1300 PhoneFormat* phoneFormat = 0;
1301 emit tempDisableBR(true); 1301 emit tempDisableBR(true);
1302#ifndef DESKTOP_VERSION 1302#ifndef DESKTOP_VERSION
1303 SharpFormat* sharpFormat = 0; 1303 SharpFormat* sharpFormat = 0;
1304 if ( mode == 0 ) { // sharp 1304 if ( mode == 0 ) { // sharp
1305 sharpFormat = new SharpFormat () ; 1305 sharpFormat = new SharpFormat () ;
1306 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1306 loadSuccess = sharpFormat->load( calendar, mCalendar );
1307 1307
1308 } else 1308 } else
1309#endif 1309#endif
1310 if ( mode == 1 ) { // phone 1310 if ( mode == 1 ) { // phone
1311 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1311 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1312 mSyncManager->mPhoneDevice, 1312 mSyncManager->mPhoneDevice,
1313 mSyncManager->mPhoneConnection, 1313 mSyncManager->mPhoneConnection,
1314 mSyncManager->mPhoneModel); 1314 mSyncManager->mPhoneModel);
1315 loadSuccess = phoneFormat->load( calendar,mCalendar); 1315 loadSuccess = phoneFormat->load( calendar,mCalendar);
1316 1316
1317 } else { 1317 } else {
1318 emit tempDisableBR(false); 1318 emit tempDisableBR(false);
1319 return; 1319 return;
1320 } 1320 }
1321 if ( loadSuccess ) { 1321 if ( loadSuccess ) {
1322 getEventViewerDialog()->setSyncMode( true ); 1322 getEventViewerDialog()->setSyncMode( true );
1323 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1323 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1324 getEventViewerDialog()->setSyncMode( false ); 1324 getEventViewerDialog()->setSyncMode( false );
1325 qApp->processEvents(); 1325 qApp->processEvents();
1326 if ( syncOK ) { 1326 if ( syncOK ) {
1327 if ( mSyncManager->mWriteBackFile ) 1327 if ( mSyncManager->mWriteBackFile )
1328 { 1328 {
1329 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1329 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1330 Incidence* inc = iL.first(); 1330 Incidence* inc = iL.first();
1331 if ( phoneFormat ) { 1331 if ( phoneFormat ) {
1332 while ( inc ) { 1332 while ( inc ) {
1333 inc->removeID(mCurrentSyncDevice); 1333 inc->removeID(mCurrentSyncDevice);
1334 inc = iL.next(); 1334 inc = iL.next();
1335 } 1335 }
1336 } 1336 }
1337#ifndef DESKTOP_VERSION 1337#ifndef DESKTOP_VERSION
1338 if ( sharpFormat ) 1338 if ( sharpFormat )
1339 sharpFormat->save(calendar); 1339 sharpFormat->save(calendar);
1340#endif 1340#endif
1341 if ( phoneFormat ) 1341 if ( phoneFormat )
1342 phoneFormat->save(calendar); 1342 phoneFormat->save(calendar);
1343 iL = calendar->rawIncidences(); 1343 iL = calendar->rawIncidences();
1344 inc = iL.first(); 1344 inc = iL.first();
1345 Incidence* loc; 1345 Incidence* loc;
1346 while ( inc ) { 1346 while ( inc ) {
1347 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1347 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1348 loc = mCalendar->incidence(inc->uid() ); 1348 loc = mCalendar->incidence(inc->uid() );
1349 if ( loc ) { 1349 if ( loc ) {
1350 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1350 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1351 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1351 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1352 } 1352 }
1353 } 1353 }
1354 inc = iL.next(); 1354 inc = iL.next();
1355 } 1355 }
1356 Incidence* lse = getLastSyncEvent(); 1356 Incidence* lse = getLastSyncEvent();
1357 if ( lse ) { 1357 if ( lse ) {
1358 lse->setReadOnly( false ); 1358 lse->setReadOnly( false );
1359 lse->setDescription( "" ); 1359 lse->setDescription( "" );
1360 lse->setReadOnly( true ); 1360 lse->setReadOnly( true );
1361 } 1361 }
1362 } 1362 }
1363 } else { 1363 } else {
1364 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1364 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1365 } 1365 }
1366 setModified( true ); 1366 setModified( true );
1367 } else { 1367 } else {
1368 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1368 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1369 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1369 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1370 question, i18n("Ok")) ; 1370 question, i18n("Ok")) ;
1371 1371
1372 } 1372 }
1373 delete calendar; 1373 delete calendar;
1374 updateView(); 1374 updateView();
1375 emit tempDisableBR(false); 1375 emit tempDisableBR(false);
1376 return ;//syncOK; 1376 return ;//syncOK;
1377 1377
1378} 1378}
1379 1379
1380bool CalendarView::importBday() 1380bool CalendarView::importBday()
1381{ 1381{
1382#ifndef KORG_NOKABC 1382#ifndef KORG_NOKABC
1383 1383
1384#ifdef DESKTOP_VERSION 1384#ifdef DESKTOP_VERSION
1385 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1385 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1386 KABC::AddressBook::Iterator it; 1386 KABC::AddressBook::Iterator it;
1387 int count = 0; 1387 int count = 0;
1388 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1388 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1389 ++count; 1389 ++count;
1390 } 1390 }
1391 QProgressBar bar(count,0 ); 1391 QProgressBar bar(count,0 );
1392 int w = 300; 1392 int w = 300;
1393 if ( QApplication::desktop()->width() < 320 ) 1393 if ( QApplication::desktop()->width() < 320 )
1394 w = 220; 1394 w = 220;
1395 int h = bar.sizeHint().height() ; 1395 int h = bar.sizeHint().height() ;
1396 int dw = QApplication::desktop()->width(); 1396 int dw = QApplication::desktop()->width();
1397 int dh = QApplication::desktop()->height(); 1397 int dh = QApplication::desktop()->height();
1398 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1398 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1399 bar.show(); 1399 bar.show();
1400 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1400 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1401 qApp->processEvents(); 1401 qApp->processEvents();
1402 count = 0; 1402 count = 0;
1403 int addCount = 0; 1403 int addCount = 0;
1404 KCal::Attendee* a = 0; 1404 KCal::Attendee* a = 0;
1405 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1405 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1406 if ( ! bar.isVisible() ) 1406 if ( ! bar.isVisible() )
1407 return false; 1407 return false;
1408 bar.setProgress( count++ ); 1408 bar.setProgress( count++ );
1409 qApp->processEvents(); 1409 qApp->processEvents();
1410 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1410 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1411 if ( (*it).birthday().date().isValid() ){ 1411 if ( (*it).birthday().date().isValid() ){
1412 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1412 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1413 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1413 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1414 ++addCount; 1414 ++addCount;
1415 } 1415 }
1416 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1416 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1417 if ( anni.isValid() ){ 1417 if ( anni.isValid() ){
1418 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1418 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1419 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1419 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1420 ++addCount; 1420 ++addCount;
1421 } 1421 }
1422 } 1422 }
1423 updateView(); 1423 updateView();
1424 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1424 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1425#else //DESKTOP_VERSION 1425#else //DESKTOP_VERSION
1426 1426
1427 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1427 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1428 // the result should now arrive through method insertBirthdays 1428 // the result should now arrive through method insertBirthdays
1429 1429
1430#endif //DESKTOP_VERSION 1430#endif //DESKTOP_VERSION
1431 1431
1432#endif //KORG_NOKABC 1432#endif //KORG_NOKABC
1433 1433
1434 1434
1435 return true; 1435 return true;
1436} 1436}
1437 1437
1438// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1438// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1439void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1439void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1440 const QStringList& anniversaryList, const QStringList& realNameList, 1440 const QStringList& anniversaryList, const QStringList& realNameList,
1441 const QStringList& emailList, const QStringList& assembledNameList, 1441 const QStringList& emailList, const QStringList& assembledNameList,
1442 const QStringList& uidList) 1442 const QStringList& uidList)
1443{ 1443{
1444 //qDebug("KO::CalendarView::insertBirthdays"); 1444 //qDebug("KO::CalendarView::insertBirthdays");
1445 if (uid == this->name()) 1445 if (uid == this->name())
1446 { 1446 {
1447 int count = birthdayList.count(); 1447 int count = birthdayList.count();
1448 int addCount = 0; 1448 int addCount = 0;
1449 KCal::Attendee* a = 0; 1449 KCal::Attendee* a = 0;
1450 1450
1451 //qDebug("CalView 1 %i", count); 1451 //qDebug("CalView 1 %i", count);
1452 1452
1453 QProgressBar bar(count,0 ); 1453 QProgressBar bar(count,0 );
1454 int w = 300; 1454 int w = 300;
1455 if ( QApplication::desktop()->width() < 320 ) 1455 if ( QApplication::desktop()->width() < 320 )
1456 w = 220; 1456 w = 220;
1457 int h = bar.sizeHint().height() ; 1457 int h = bar.sizeHint().height() ;
1458 int dw = QApplication::desktop()->width(); 1458 int dw = QApplication::desktop()->width();
1459 int dh = QApplication::desktop()->height(); 1459 int dh = QApplication::desktop()->height();
1460 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1460 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1461 bar.show(); 1461 bar.show();
1462 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1462 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1463 qApp->processEvents(); 1463 qApp->processEvents();
1464 1464
1465 QDate birthday; 1465 QDate birthday;
1466 QDate anniversary; 1466 QDate anniversary;
1467 QString realName; 1467 QString realName;
1468 QString email; 1468 QString email;
1469 QString assembledName; 1469 QString assembledName;
1470 QString uid; 1470 QString uid;
1471 bool ok = true; 1471 bool ok = true;
1472 for ( int i = 0; i < count; i++) 1472 for ( int i = 0; i < count; i++)
1473 { 1473 {
1474 if ( ! bar.isVisible() ) 1474 if ( ! bar.isVisible() )
1475 return; 1475 return;
1476 bar.setProgress( i ); 1476 bar.setProgress( i );
1477 qApp->processEvents(); 1477 qApp->processEvents();
1478 1478
1479 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1479 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1480 if (!ok) { 1480 if (!ok) {
1481 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1481 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1482 } 1482 }
1483 1483
1484 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1484 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1485 if (!ok) { 1485 if (!ok) {
1486 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1486 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1487 } 1487 }
1488 realName = realNameList[i]; 1488 realName = realNameList[i];
1489 email = emailList[i]; 1489 email = emailList[i];
1490 assembledName = assembledNameList[i]; 1490 assembledName = assembledNameList[i];
1491 uid = uidList[i]; 1491 uid = uidList[i];
1492 //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() ); 1492 //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() );
1493 1493
1494 if ( birthday.isValid() ){ 1494 if ( birthday.isValid() ){
1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1496 KCal::Attendee::ReqParticipant,uid) ; 1496 KCal::Attendee::ReqParticipant,uid) ;
1497 if ( addAnniversary( birthday, assembledName, a, true ) ) 1497 if ( addAnniversary( birthday, assembledName, a, true ) )
1498 ++addCount; 1498 ++addCount;
1499 } 1499 }
1500 1500
1501 if ( anniversary.isValid() ){ 1501 if ( anniversary.isValid() ){
1502 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1502 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1503 KCal::Attendee::ReqParticipant,uid) ; 1503 KCal::Attendee::ReqParticipant,uid) ;
1504 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1504 if ( addAnniversary( anniversary, assembledName, a, false ) )
1505 ++addCount; 1505 ++addCount;
1506 } 1506 }
1507 } 1507 }
1508 1508
1509 updateView(); 1509 updateView();
1510 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1510 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1511 1511
1512 } 1512 }
1513 1513
1514} 1514}
1515 1515
1516 1516
1517 1517
1518bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1518bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1519{ 1519{
1520 //qDebug("addAnni "); 1520 //qDebug("addAnni ");
1521 Event * ev = new Event(); 1521 Event * ev = new Event();
1522 if ( a ) { 1522 if ( a ) {
1523 ev->addAttendee( a ); 1523 ev->addAttendee( a );
1524 } 1524 }
1525 QString kind; 1525 QString kind;
1526 if ( birthday ) { 1526 if ( birthday ) {
1527 kind = i18n( "Birthday" ); 1527 kind = i18n( "Birthday" );
1528 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1528 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1529 } 1529 }
1530 else { 1530 else {
1531 kind = i18n( "Anniversary" ); 1531 kind = i18n( "Anniversary" );
1532 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1532 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1533 } 1533 }
1534 ev->setOrganizer(a->email()); 1534 ev->setOrganizer(a->email());
1535 ev->setCategories( kind ); 1535 ev->setCategories( kind );
1536 ev->setDtStart( QDateTime(date) ); 1536 ev->setDtStart( QDateTime(date) );
1537 ev->setDtEnd( QDateTime(date) ); 1537 ev->setDtEnd( QDateTime(date) );
1538 ev->setFloats( true ); 1538 ev->setFloats( true );
1539 Recurrence * rec = ev->recurrence(); 1539 Recurrence * rec = ev->recurrence();
1540 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1540 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1541 rec->addYearlyNum( date.month() ); 1541 rec->addYearlyNum( date.month() );
1542 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1542 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1543 delete ev; 1543 delete ev;
1544 return false; 1544 return false;
1545 } 1545 }
1546 return true; 1546 return true;
1547 1547
1548} 1548}
1549bool CalendarView::importQtopia( const QString &categories, 1549bool CalendarView::importQtopia( const QString &categories,
1550 const QString &datebook, 1550 const QString &datebook,
1551 const QString &todolist ) 1551 const QString &todolist )
1552{ 1552{
1553 1553
1554 QtopiaFormat qtopiaFormat; 1554 QtopiaFormat qtopiaFormat;
1555 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1555 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1556 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1556 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1557 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1557 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1558 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1558 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1559 1559
1560 updateView(); 1560 updateView();
1561 return true; 1561 return true;
1562 1562
1563#if 0 1563#if 0
1564 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1564 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1565 mCurrentSyncDevice = "qtopia-XML"; 1565 mCurrentSyncDevice = "qtopia-XML";
1566 if ( mSyncManager->mAskForPreferences ) 1566 if ( mSyncManager->mAskForPreferences )
1567 edit_sync_options(); 1567 edit_sync_options();
1568 qApp->processEvents(); 1568 qApp->processEvents();
1569 CalendarLocal* calendar = new CalendarLocal(); 1569 CalendarLocal* calendar = new CalendarLocal();
1570 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1570 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1571 bool syncOK = false; 1571 bool syncOK = false;
1572 QtopiaFormat qtopiaFormat; 1572 QtopiaFormat qtopiaFormat;
1573 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1573 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1574 bool loadOk = true; 1574 bool loadOk = true;
1575 if ( !categories.isEmpty() ) 1575 if ( !categories.isEmpty() )
1576 loadOk = qtopiaFormat.load( calendar, categories ); 1576 loadOk = qtopiaFormat.load( calendar, categories );
1577 if ( loadOk && !datebook.isEmpty() ) 1577 if ( loadOk && !datebook.isEmpty() )
1578 loadOk = qtopiaFormat.load( calendar, datebook ); 1578 loadOk = qtopiaFormat.load( calendar, datebook );
1579 if ( loadOk && !todolist.isEmpty() ) 1579 if ( loadOk && !todolist.isEmpty() )
1580 loadOk = qtopiaFormat.load( calendar, todolist ); 1580 loadOk = qtopiaFormat.load( calendar, todolist );
1581 1581
1582 if ( loadOk ) { 1582 if ( loadOk ) {
1583 getEventViewerDialog()->setSyncMode( true ); 1583 getEventViewerDialog()->setSyncMode( true );
1584 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1584 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1585 getEventViewerDialog()->setSyncMode( false ); 1585 getEventViewerDialog()->setSyncMode( false );
1586 qApp->processEvents(); 1586 qApp->processEvents();
1587 if ( syncOK ) { 1587 if ( syncOK ) {
1588 if ( mSyncManager->mWriteBackFile ) 1588 if ( mSyncManager->mWriteBackFile )
1589 { 1589 {
1590 // write back XML file 1590 // write back XML file
1591 1591
1592 } 1592 }
1593 setModified( true ); 1593 setModified( true );
1594 } 1594 }
1595 } else { 1595 } else {
1596 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1596 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1597 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1597 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1598 question, i18n("Ok")) ; 1598 question, i18n("Ok")) ;
1599 } 1599 }
1600 delete calendar; 1600 delete calendar;
1601 updateView(); 1601 updateView();
1602 return syncOK; 1602 return syncOK;
1603 1603
1604 1604
1605#endif 1605#endif
1606 1606
1607} 1607}
1608 1608
1609void CalendarView::setSyncEventsReadOnly() 1609void CalendarView::setSyncEventsReadOnly()
1610{ 1610{
1611 Event * ev; 1611 Event * ev;
1612 QPtrList<Event> eL = mCalendar->rawEvents(); 1612 QPtrList<Event> eL = mCalendar->rawEvents();
1613 ev = eL.first(); 1613 ev = eL.first();
1614 while ( ev ) { 1614 while ( ev ) {
1615 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1615 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1616 ev->setReadOnly( true ); 1616 ev->setReadOnly( true );
1617 ev = eL.next(); 1617 ev = eL.next();
1618 } 1618 }
1619} 1619}
1620bool CalendarView::openCalendar(QString filename, bool merge) 1620bool CalendarView::openCalendar(QString filename, bool merge)
1621{ 1621{
1622 1622
1623 if (filename.isEmpty()) { 1623 if (filename.isEmpty()) {
1624 return false; 1624 return false;
1625 } 1625 }
1626 1626
1627 if (!QFile::exists(filename)) { 1627 if (!QFile::exists(filename)) {
1628 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1628 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1629 return false; 1629 return false;
1630 } 1630 }
1631 1631
1632 globalFlagBlockAgenda = 1; 1632 globalFlagBlockAgenda = 1;
1633 if (!merge) mCalendar->close(); 1633 if (!merge) mCalendar->close();
1634 1634
1635 mStorage->setFileName( filename ); 1635 mStorage->setFileName( filename );
1636 1636
1637 if ( mStorage->load() ) { 1637 if ( mStorage->load() ) {
1638 if ( merge ) ;//setModified( true ); 1638 if ( merge ) ;//setModified( true );
1639 else { 1639 else {
1640 //setModified( true ); 1640 //setModified( true );
1641 mViewManager->setDocumentId( filename ); 1641 mViewManager->setDocumentId( filename );
1642 mDialogManager->setDocumentId( filename ); 1642 mDialogManager->setDocumentId( filename );
1643 mTodoList->setDocumentId( filename ); 1643 mTodoList->setDocumentId( filename );
1644 } 1644 }
1645 globalFlagBlockAgenda = 2; 1645 globalFlagBlockAgenda = 2;
1646 // if ( getLastSyncEvent() ) 1646 // if ( getLastSyncEvent() )
1647 // getLastSyncEvent()->setReadOnly( true ); 1647 // getLastSyncEvent()->setReadOnly( true );
1648 mCalendar->reInitAlarmSettings(); 1648 mCalendar->reInitAlarmSettings();
1649 setSyncEventsReadOnly(); 1649 setSyncEventsReadOnly();
1650 updateUnmanagedViews(); 1650 updateUnmanagedViews();
1651 updateView(); 1651 updateView();
1652 if ( filename != MainWindow::defaultFileName() ) { 1652 if ( filename != MainWindow::defaultFileName() ) {
1653 saveCalendar( MainWindow::defaultFileName() ); 1653 saveCalendar( MainWindow::defaultFileName() );
1654 } else { 1654 } else {
1655 QFileInfo finf ( MainWindow::defaultFileName()); 1655 QFileInfo finf ( MainWindow::defaultFileName());
1656 if ( finf.exists() ) { 1656 if ( finf.exists() ) {
1657 setLoadedFileVersion( finf.lastModified () ); 1657 setLoadedFileVersion( finf.lastModified () );
1658 } 1658 }
1659 } 1659 }
1660 return true; 1660 return true;
1661 } else { 1661 } else {
1662 // while failing to load, the calendar object could 1662 // while failing to load, the calendar object could
1663 // have become partially populated. Clear it out. 1663 // have become partially populated. Clear it out.
1664 if ( !merge ) { 1664 if ( !merge ) {
1665 mCalendar->close(); 1665 mCalendar->close();
1666 mViewManager->setDocumentId( filename ); 1666 mViewManager->setDocumentId( filename );
1667 mDialogManager->setDocumentId( filename ); 1667 mDialogManager->setDocumentId( filename );
1668 mTodoList->setDocumentId( filename ); 1668 mTodoList->setDocumentId( filename );
1669 } 1669 }
1670 1670
1671 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1671 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1672 1672
1673 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1673 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1674 globalFlagBlockAgenda = 2; 1674 globalFlagBlockAgenda = 2;
1675 mCalendar->reInitAlarmSettings(); 1675 mCalendar->reInitAlarmSettings();
1676 setSyncEventsReadOnly(); 1676 setSyncEventsReadOnly();
1677 updateUnmanagedViews(); 1677 updateUnmanagedViews();
1678 updateView(); 1678 updateView();
1679 } 1679 }
1680 return false; 1680 return false;
1681} 1681}
1682void CalendarView::showOpenError() 1682void CalendarView::showOpenError()
1683{ 1683{
1684 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1684 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1685} 1685}
1686void CalendarView::setLoadedFileVersion(QDateTime dt) 1686void CalendarView::setLoadedFileVersion(QDateTime dt)
1687{ 1687{
1688 loadedFileVersion = dt; 1688 loadedFileVersion = dt;
1689} 1689}
1690bool CalendarView::checkFileChanged(QString fn) 1690bool CalendarView::checkFileChanged(QString fn)
1691{ 1691{
1692 QFileInfo finf ( fn ); 1692 QFileInfo finf ( fn );
1693 if ( !finf.exists() ) 1693 if ( !finf.exists() )
1694 return true; 1694 return true;
1695 QDateTime dt = finf.lastModified (); 1695 QDateTime dt = finf.lastModified ();
1696 if ( dt <= loadedFileVersion ) 1696 if ( dt <= loadedFileVersion )
1697 return false; 1697 return false;
1698 return true; 1698 return true;
1699 1699
1700} 1700}
1701void CalendarView::watchSavedFile() 1701void CalendarView::watchSavedFile()
1702{ 1702{
1703 QFileInfo finf ( MainWindow::defaultFileName()); 1703 QFileInfo finf ( MainWindow::defaultFileName());
1704 if ( !finf.exists() ) 1704 if ( !finf.exists() )
1705 return; 1705 return;
1706 QDateTime dt = finf.lastModified (); 1706 QDateTime dt = finf.lastModified ();
1707 if ( dt < loadedFileVersion ) { 1707 if ( dt < loadedFileVersion ) {
1708 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1708 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1709 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1709 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1710 return; 1710 return;
1711 } 1711 }
1712 loadedFileVersion = dt; 1712 loadedFileVersion = dt;
1713} 1713}
1714 1714
1715bool CalendarView::checkFileVersion(QString fn) 1715bool CalendarView::checkFileVersion(QString fn)
1716{ 1716{
1717 QFileInfo finf ( fn ); 1717 QFileInfo finf ( fn );
1718 if ( !finf.exists() ) 1718 if ( !finf.exists() )
1719 return true; 1719 return true;
1720 QDateTime dt = finf.lastModified (); 1720 QDateTime dt = finf.lastModified ();
1721 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1721 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1722 //qDebug("file on disk version %s",dt.toString().latin1()); 1722 //qDebug("file on disk version %s",dt.toString().latin1());
1723 if ( dt <= loadedFileVersion ) 1723 if ( dt <= loadedFileVersion )
1724 return true; 1724 return true;
1725 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)) , 1725 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)) ,
1726 i18n("KO/Pi Warning"),i18n("Overwrite"), 1726 i18n("KO/Pi Warning"),i18n("Overwrite"),
1727 i18n("Sync+save")); 1727 i18n("Sync+save"));
1728 1728
1729 if ( km == KMessageBox::Cancel ) 1729 if ( km == KMessageBox::Cancel )
1730 return false; 1730 return false;
1731 if ( km == KMessageBox::Yes ) 1731 if ( km == KMessageBox::Yes )
1732 return true; 1732 return true;
1733 1733
1734 setSyncDevice("deleteaftersync" ); 1734 setSyncDevice("deleteaftersync" );
1735 mSyncManager->mAskForPreferences = true; 1735 mSyncManager->mAskForPreferences = true;
1736 mSyncManager->mSyncAlgoPrefs = 3; 1736 mSyncManager->mSyncAlgoPrefs = 3;
1737 mSyncManager->mWriteBackFile = false; 1737 mSyncManager->mWriteBackFile = false;
1738 mSyncManager->mWriteBackExistingOnly = false; 1738 mSyncManager->mWriteBackExistingOnly = false;
1739 mSyncManager->mShowSyncSummary = false; 1739 mSyncManager->mShowSyncSummary = false;
1740 syncCalendar( fn, 3 ); 1740 syncCalendar( fn, 3 );
1741 Event * e = getLastSyncEvent(); 1741 Event * e = getLastSyncEvent();
1742 mCalendar->deleteEvent ( e ); 1742 mCalendar->deleteEvent ( e );
1743 updateView(); 1743 updateView();
1744 return true; 1744 return true;
1745} 1745}
1746 1746
1747bool CalendarView::saveCalendar( QString filename ) 1747bool CalendarView::saveCalendar( QString filename )
1748{ 1748{
1749 1749
1750 // Store back all unsaved data into calendar object 1750 // Store back all unsaved data into calendar object
1751 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1751 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1752 if ( mViewManager->currentView() ) 1752 if ( mViewManager->currentView() )
1753 mViewManager->currentView()->flushView(); 1753 mViewManager->currentView()->flushView();
1754 1754
1755 1755
1756 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1756 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1757 mStorage->setSaveFormat( new ICalFormat() ); 1757 mStorage->setSaveFormat( new ICalFormat() );
1758 mStorage->setFileName( filename ); 1758 mStorage->setFileName( filename );
1759 bool success; 1759 bool success;
1760 success = mStorage->save(); 1760 success = mStorage->save();
1761 if ( !success ) { 1761 if ( !success ) {
1762 return false; 1762 return false;
1763 } 1763 }
1764 if ( filename == MainWindow::defaultFileName() ) { 1764 if ( filename == MainWindow::defaultFileName() ) {
1765 setLoadedFileVersion( lfv ); 1765 setLoadedFileVersion( lfv );
1766 watchSavedFile(); 1766 watchSavedFile();
1767 } 1767 }
1768 return true; 1768 return true;
1769} 1769}
1770 1770
1771void CalendarView::closeCalendar() 1771void CalendarView::closeCalendar()
1772{ 1772{
1773 1773
1774 // child windows no longer valid 1774 // child windows no longer valid
1775 emit closingDown(); 1775 emit closingDown();
1776 1776
1777 mCalendar->close(); 1777 mCalendar->close();
1778 setModified(false); 1778 setModified(false);
1779 updateView(); 1779 updateView();
1780} 1780}
1781 1781
1782void CalendarView::archiveCalendar() 1782void CalendarView::archiveCalendar()
1783{ 1783{
1784 mDialogManager->showArchiveDialog(); 1784 mDialogManager->showArchiveDialog();
1785} 1785}
1786 1786
1787 1787
1788void CalendarView::readSettings() 1788void CalendarView::readSettings()
1789{ 1789{
1790 1790
1791 1791
1792 // mViewManager->showAgendaView(); 1792 // mViewManager->showAgendaView();
1793 QString str; 1793 QString str;
1794 //qDebug("CalendarView::readSettings() "); 1794 //qDebug("CalendarView::readSettings() ");
1795 // read settings from the KConfig, supplying reasonable 1795 // read settings from the KConfig, supplying reasonable
1796 // defaults where none are to be found 1796 // defaults where none are to be found
1797 KConfig *config = KOGlobals::config(); 1797 KConfig *config = KOGlobals::config();
1798#ifndef KORG_NOSPLITTER 1798#ifndef KORG_NOSPLITTER
1799 config->setGroup("KOrganizer Geometry"); 1799 config->setGroup("KOrganizer Geometry");
1800 1800
1801 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1801 QValueList<int> sizes = config->readIntListEntry("Separator1");
1802 if (sizes.count() != 2) { 1802 if (sizes.count() != 2) {
1803 sizes << mDateNavigator->minimumSizeHint().width(); 1803 sizes << mDateNavigator->minimumSizeHint().width();
1804 sizes << 300; 1804 sizes << 300;
1805 } 1805 }
1806 mPanner->setSizes(sizes); 1806 mPanner->setSizes(sizes);
1807 1807
1808 sizes = config->readIntListEntry("Separator2"); 1808 sizes = config->readIntListEntry("Separator2");
1809 if ( ( mResourceView && sizes.count() == 4 ) || 1809 if ( ( mResourceView && sizes.count() == 4 ) ||
1810 ( !mResourceView && sizes.count() == 3 ) ) { 1810 ( !mResourceView && sizes.count() == 3 ) ) {
1811 mLeftSplitter->setSizes(sizes); 1811 mLeftSplitter->setSizes(sizes);
1812 } 1812 }
1813#endif 1813#endif
1814 globalFlagBlockAgenda = 1; 1814 globalFlagBlockAgenda = 1;
1815 mViewManager->showAgendaView(); 1815 mViewManager->showAgendaView();
1816 //mViewManager->readSettings( config ); 1816 //mViewManager->readSettings( config );
1817 mTodoList->restoreLayout(config,QString("Todo Layout")); 1817 mTodoList->restoreLayout(config,QString("Todo Layout"));
1818 readFilterSettings(config); 1818 readFilterSettings(config);
1819 config->setGroup( "Views" ); 1819 config->setGroup( "Views" );
1820 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1820 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1821 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1821 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1822 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1822 else if ( dateCount == 7 ) mNavigator->selectWeek();
1823 else mNavigator->selectDates( dateCount ); 1823 else mNavigator->selectDates( dateCount );
1824 // mViewManager->readSettings( config ); 1824 // mViewManager->readSettings( config );
1825 updateConfig(); 1825 updateConfig();
1826 globalFlagBlockAgenda = 2; 1826 globalFlagBlockAgenda = 2;
1827 mViewManager->readSettings( config ); 1827 mViewManager->readSettings( config );
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 1870
1871} 1871}
1872 1872
1873 1873
1874void CalendarView::writeSettings() 1874void CalendarView::writeSettings()
1875{ 1875{
1876 // kdDebug() << "CalendarView::writeSettings" << endl; 1876 // kdDebug() << "CalendarView::writeSettings" << endl;
1877 1877
1878 KConfig *config = KOGlobals::config(); 1878 KConfig *config = KOGlobals::config();
1879 1879
1880#ifndef KORG_NOSPLITTER 1880#ifndef KORG_NOSPLITTER
1881 config->setGroup("KOrganizer Geometry"); 1881 config->setGroup("KOrganizer Geometry");
1882 1882
1883 QValueList<int> list = mPanner->sizes(); 1883 QValueList<int> list = mPanner->sizes();
1884 config->writeEntry("Separator1",list); 1884 config->writeEntry("Separator1",list);
1885 1885
1886 list = mLeftSplitter->sizes(); 1886 list = mLeftSplitter->sizes();
1887 config->writeEntry("Separator2",list); 1887 config->writeEntry("Separator2",list);
1888#endif 1888#endif
1889 1889
1890 mViewManager->writeSettings( config ); 1890 mViewManager->writeSettings( config );
1891 mTodoList->saveLayout(config,QString("Todo Layout")); 1891 mTodoList->saveLayout(config,QString("Todo Layout"));
1892 mDialogManager->writeSettings( config ); 1892 mDialogManager->writeSettings( config );
1893 //KOPrefs::instance()->usrWriteConfig(); 1893 //KOPrefs::instance()->usrWriteConfig();
1894 KOPrefs::instance()->writeConfig(); 1894 KOPrefs::instance()->writeConfig();
1895 1895
1896 writeFilterSettings(config); 1896 writeFilterSettings(config);
1897 1897
1898 config->setGroup( "Views" ); 1898 config->setGroup( "Views" );
1899 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1899 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1900 1900
1901#ifdef DESKTOP_VERSION 1901#ifdef DESKTOP_VERSION
1902 config->setGroup("WidgetLayout"); 1902 config->setGroup("WidgetLayout");
1903 QStringList list ;//= config->readListEntry("MainLayout"); 1903 QStringList list ;//= config->readListEntry("MainLayout");
1904 int x,y,w,h; 1904 int x,y,w,h;
1905 QWidget* wid; 1905 QWidget* wid;
1906 wid = topLevelWidget(); 1906 wid = topLevelWidget();
1907 x = wid->geometry().x(); 1907 x = wid->geometry().x();
1908 y = wid->geometry().y(); 1908 y = wid->geometry().y();
1909 w = wid->width(); 1909 w = wid->width();
1910 h = wid->height(); 1910 h = wid->height();
1911 list.clear(); 1911 list.clear();
1912 list << QString::number( x ); 1912 list << QString::number( x );
1913 list << QString::number( y ); 1913 list << QString::number( y );
1914 list << QString::number( w ); 1914 list << QString::number( w );
1915 list << QString::number( h ); 1915 list << QString::number( h );
1916 config->writeEntry("MainLayout",list ); 1916 config->writeEntry("MainLayout",list );
1917 1917
1918 wid = mEventEditor; 1918 wid = mEventEditor;
1919 x = wid->geometry().x(); 1919 x = wid->geometry().x();
1920 y = wid->geometry().y(); 1920 y = wid->geometry().y();
1921 w = wid->width(); 1921 w = wid->width();
1922 h = wid->height(); 1922 h = wid->height();
1923 list.clear(); 1923 list.clear();
1924 list << QString::number( x ); 1924 list << QString::number( x );
1925 list << QString::number( y ); 1925 list << QString::number( y );
1926 list << QString::number( w ); 1926 list << QString::number( w );
1927 list << QString::number( h ); 1927 list << QString::number( h );
1928 config->writeEntry("EditEventLayout",list ); 1928 config->writeEntry("EditEventLayout",list );
1929 1929
1930 wid = mTodoEditor; 1930 wid = mTodoEditor;
1931 x = wid->geometry().x(); 1931 x = wid->geometry().x();
1932 y = wid->geometry().y(); 1932 y = wid->geometry().y();
1933 w = wid->width(); 1933 w = wid->width();
1934 h = wid->height(); 1934 h = wid->height();
1935 list.clear(); 1935 list.clear();
1936 list << QString::number( x ); 1936 list << QString::number( x );
1937 list << QString::number( y ); 1937 list << QString::number( y );
1938 list << QString::number( w ); 1938 list << QString::number( w );
1939 list << QString::number( h ); 1939 list << QString::number( h );
1940 config->writeEntry("EditTodoLayout",list ); 1940 config->writeEntry("EditTodoLayout",list );
1941 wid = getEventViewerDialog(); 1941 wid = getEventViewerDialog();
1942 x = wid->geometry().x(); 1942 x = wid->geometry().x();
1943 y = wid->geometry().y(); 1943 y = wid->geometry().y();
1944 w = wid->width(); 1944 w = wid->width();
1945 h = wid->height(); 1945 h = wid->height();
1946 list.clear(); 1946 list.clear();
1947 list << QString::number( x ); 1947 list << QString::number( x );
1948 list << QString::number( y ); 1948 list << QString::number( y );
1949 list << QString::number( w ); 1949 list << QString::number( w );
1950 list << QString::number( h ); 1950 list << QString::number( h );
1951 config->writeEntry("ViewerLayout",list ); 1951 config->writeEntry("ViewerLayout",list );
1952 wid = mDialogManager->getSearchDialog(); 1952 wid = mDialogManager->getSearchDialog();
1953 if ( wid ) { 1953 if ( wid ) {
1954 x = wid->geometry().x(); 1954 x = wid->geometry().x();
1955 y = wid->geometry().y(); 1955 y = wid->geometry().y();
1956 w = wid->width(); 1956 w = wid->width();
1957 h = wid->height(); 1957 h = wid->height();
1958 list.clear(); 1958 list.clear();
1959 list << QString::number( x ); 1959 list << QString::number( x );
1960 list << QString::number( y ); 1960 list << QString::number( y );
1961 list << QString::number( w ); 1961 list << QString::number( w );
1962 list << QString::number( h ); 1962 list << QString::number( h );
1963 config->writeEntry("SearchLayout",list ); 1963 config->writeEntry("SearchLayout",list );
1964 } 1964 }
1965#endif 1965#endif
1966 1966
1967 1967
1968 config->sync(); 1968 config->sync();
1969} 1969}
1970 1970
1971void CalendarView::readFilterSettings(KConfig *config) 1971void CalendarView::readFilterSettings(KConfig *config)
1972{ 1972{
1973 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1973 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1974 1974
1975 mFilters.clear(); 1975 mFilters.clear();
1976 1976
1977 config->setGroup("General"); 1977 config->setGroup("General");
1978 QStringList filterList = config->readListEntry("CalendarFilters"); 1978 QStringList filterList = config->readListEntry("CalendarFilters");
1979 1979
1980 QStringList::ConstIterator it = filterList.begin(); 1980 QStringList::ConstIterator it = filterList.begin();
1981 QStringList::ConstIterator end = filterList.end(); 1981 QStringList::ConstIterator end = filterList.end();
1982 while(it != end) { 1982 while(it != end) {
1983 // kdDebug() << " filter: " << (*it) << endl; 1983 // kdDebug() << " filter: " << (*it) << endl;
1984 1984
1985 CalFilter *filter; 1985 CalFilter *filter;
1986 filter = new CalFilter(*it); 1986 filter = new CalFilter(*it);
1987 config->setGroup("Filter_" + (*it)); 1987 config->setGroup("Filter_" + (*it));
1988 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1988 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1989 filter->setCriteria(config->readNumEntry("Criteria",0)); 1989 filter->setCriteria(config->readNumEntry("Criteria",0));
1990 filter->setCategoryList(config->readListEntry("CategoryList")); 1990 filter->setCategoryList(config->readListEntry("CategoryList"));
1991 mFilters.append(filter); 1991 mFilters.append(filter);
1992 1992
1993 ++it; 1993 ++it;
1994 } 1994 }
1995 1995
1996 if (mFilters.count() == 0) { 1996 if (mFilters.count() == 0) {
1997 CalFilter *filter = new CalFilter(i18n("Default")); 1997 CalFilter *filter = new CalFilter(i18n("Default"));
1998 mFilters.append(filter); 1998 mFilters.append(filter);
1999 } 1999 }
2000 mFilterView->updateFilters(); 2000 mFilterView->updateFilters();
2001 config->setGroup("FilterView"); 2001 config->setGroup("FilterView");
2002 2002
2003 mFilterView->blockSignals(true); 2003 mFilterView->blockSignals(true);
2004 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2004 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2005 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2005 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2006 mFilterView->blockSignals(false); 2006 mFilterView->blockSignals(false);
2007 // We do it manually to avoid it being done twice by the above calls 2007 // We do it manually to avoid it being done twice by the above calls
2008 updateFilter(); 2008 updateFilter();
2009} 2009}
2010 2010
2011void CalendarView::writeFilterSettings(KConfig *config) 2011void CalendarView::writeFilterSettings(KConfig *config)
2012{ 2012{
2013 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2013 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2014 2014
2015 QStringList filterList; 2015 QStringList filterList;
2016 2016
2017 CalFilter *filter = mFilters.first(); 2017 CalFilter *filter = mFilters.first();
2018 while(filter) { 2018 while(filter) {
2019 // kdDebug() << " fn: " << filter->name() << endl; 2019 // kdDebug() << " fn: " << filter->name() << endl;
2020 filterList << filter->name(); 2020 filterList << filter->name();
2021 config->setGroup("Filter_" + filter->name()); 2021 config->setGroup("Filter_" + filter->name());
2022 config->writeEntry("Criteria",filter->criteria()); 2022 config->writeEntry("Criteria",filter->criteria());
2023 config->writeEntry("CategoryList",filter->categoryList()); 2023 config->writeEntry("CategoryList",filter->categoryList());
2024 filter = mFilters.next(); 2024 filter = mFilters.next();
2025 } 2025 }
2026 config->setGroup("General"); 2026 config->setGroup("General");
2027 config->writeEntry("CalendarFilters",filterList); 2027 config->writeEntry("CalendarFilters",filterList);
2028 2028
2029 config->setGroup("FilterView"); 2029 config->setGroup("FilterView");
2030 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2030 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2031 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2031 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2032} 2032}
2033 2033
2034 2034
2035void CalendarView::goToday() 2035void CalendarView::goToday()
2036{ 2036{
2037 if ( mViewManager->currentView()->isMonthView() ) 2037 if ( mViewManager->currentView()->isMonthView() )
2038 mNavigator->selectTodayMonth(); 2038 mNavigator->selectTodayMonth();
2039 else 2039 else
2040 mNavigator->selectToday(); 2040 mNavigator->selectToday();
2041} 2041}
2042 2042
2043void CalendarView::goNext() 2043void CalendarView::goNext()
2044{ 2044{
2045 mNavigator->selectNext(); 2045 mNavigator->selectNext();
2046} 2046}
2047 2047
2048void CalendarView::goPrevious() 2048void CalendarView::goPrevious()
2049{ 2049{
2050 mNavigator->selectPrevious(); 2050 mNavigator->selectPrevious();
2051} 2051}
2052void CalendarView::goNextMonth() 2052void CalendarView::goNextMonth()
2053{ 2053{
2054 mNavigator->selectNextMonth(); 2054 mNavigator->selectNextMonth();
2055} 2055}
2056 2056
2057void CalendarView::goPreviousMonth() 2057void CalendarView::goPreviousMonth()
2058{ 2058{
2059 mNavigator->selectPreviousMonth(); 2059 mNavigator->selectPreviousMonth();
2060} 2060}
2061void CalendarView::writeLocale() 2061void CalendarView::writeLocale()
2062{ 2062{
2063 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2063 //KPimGlobalPrefs::instance()->setGlobalConfig();
2064#if 0 2064#if 0
2065 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2065 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2066 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2066 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2067 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2067 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2068 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2068 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2069 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2069 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2070 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2070 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2071 dummy = KOPrefs::instance()->mUserDateFormatShort; 2071 dummy = KOPrefs::instance()->mUserDateFormatShort;
2072 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2072 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2073 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2073 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2074 KOPrefs::instance()->mDaylightsavingStart, 2074 KOPrefs::instance()->mDaylightsavingStart,
2075 KOPrefs::instance()->mDaylightsavingEnd ); 2075 KOPrefs::instance()->mDaylightsavingEnd );
2076 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2076 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2077#endif 2077#endif
2078} 2078}
2079void CalendarView::updateConfig() 2079void CalendarView::updateConfig()
2080{ 2080{
2081 writeLocale(); 2081 writeLocale();
2082 if ( KOPrefs::instance()->mUseAppColors ) 2082 if ( KOPrefs::instance()->mUseAppColors )
2083 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2083 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2084 emit configChanged(); 2084 emit configChanged();
2085 mTodoList->updateConfig(); 2085 mTodoList->updateConfig();
2086 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2086 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2087 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2087 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2088 // To make the "fill window" configurations work 2088 // To make the "fill window" configurations work
2089 //mViewManager->raiseCurrentView(); 2089 //mViewManager->raiseCurrentView();
2090} 2090}
2091 2091
2092 2092
2093void CalendarView::eventChanged(Event *event) 2093void CalendarView::eventChanged(Event *event)
2094{ 2094{
2095 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2095 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2096 //updateUnmanagedViews(); 2096 //updateUnmanagedViews();
2097} 2097}
2098 2098
2099void CalendarView::eventAdded(Event *event) 2099void CalendarView::eventAdded(Event *event)
2100{ 2100{
2101 changeEventDisplay(event,KOGlobals::EVENTADDED); 2101 changeEventDisplay(event,KOGlobals::EVENTADDED);
2102} 2102}
2103 2103
2104void CalendarView::eventToBeDeleted(Event *) 2104void CalendarView::eventToBeDeleted(Event *)
2105{ 2105{
2106 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2106 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2107} 2107}
2108 2108
2109void CalendarView::eventDeleted() 2109void CalendarView::eventDeleted()
2110{ 2110{
2111 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2111 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2112} 2112}
2113void CalendarView::changeTodoDisplay(Todo *which, int action) 2113void CalendarView::changeTodoDisplay(Todo *which, int action)
2114{ 2114{
2115 changeIncidenceDisplay((Incidence *)which, action); 2115 changeIncidenceDisplay((Incidence *)which, action);
2116 mDateNavigator->updateView(); //LR 2116 mDateNavigator->updateView(); //LR
2117 //mDialogManager->updateSearchDialog(); 2117 //mDialogManager->updateSearchDialog();
2118 2118
2119 if (which) { 2119 if (which) {
2120 mViewManager->updateWNview(); 2120 mViewManager->updateWNview();
2121 //mTodoList->updateView(); 2121 //mTodoList->updateView();
2122 } 2122 }
2123 2123
2124} 2124}
2125 2125
2126void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2126void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2127{ 2127{
2128 updateUnmanagedViews(); 2128 updateUnmanagedViews();
2129 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2129 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2130 if ( action == KOGlobals::EVENTDELETED ) { //delete 2130 if ( action == KOGlobals::EVENTDELETED ) { //delete
2131 mCalendar->checkAlarmForIncidence( 0, true ); 2131 mCalendar->checkAlarmForIncidence( 0, true );
2132 if ( mEventViewerDialog ) 2132 if ( mEventViewerDialog )
2133 mEventViewerDialog->hide(); 2133 mEventViewerDialog->hide();
2134 } 2134 }
2135 else 2135 else
2136 mCalendar->checkAlarmForIncidence( which , false ); 2136 mCalendar->checkAlarmForIncidence( which , false );
2137} 2137}
2138 2138
2139// most of the changeEventDisplays() right now just call the view's 2139// most of the changeEventDisplays() right now just call the view's
2140// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2140// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2141void CalendarView::changeEventDisplay(Event *which, int action) 2141void CalendarView::changeEventDisplay(Event *which, int action)
2142{ 2142{
2143 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2143 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2144 changeIncidenceDisplay((Incidence *)which, action); 2144 changeIncidenceDisplay((Incidence *)which, action);
2145 mDateNavigator->updateView(); 2145 mDateNavigator->updateView();
2146 //mDialogManager->updateSearchDialog(); 2146 //mDialogManager->updateSearchDialog();
2147 2147
2148 if (which) { 2148 if (which) {
2149 // If there is an event view visible update the display 2149 // If there is an event view visible update the display
2150 mViewManager->currentView()->changeEventDisplay(which,action); 2150 mViewManager->currentView()->changeEventDisplay(which,action);
2151 // TODO: check, if update needed 2151 // TODO: check, if update needed
2152 // if (which->getTodoStatus()) { 2152 // if (which->getTodoStatus()) {
2153 mTodoList->updateView(); 2153 mTodoList->updateView();
2154 // } 2154 // }
2155 } else { 2155 } else {
2156 mViewManager->currentView()->updateView(); 2156 mViewManager->currentView()->updateView();
2157 } 2157 }
2158} 2158}
2159 2159
2160 2160
2161void CalendarView::updateTodoViews() 2161void CalendarView::updateTodoViews()
2162{ 2162{
2163 2163
2164 mTodoList->updateView(); 2164 mTodoList->updateView();
2165 mViewManager->currentView()->updateView(); 2165 mViewManager->currentView()->updateView();
2166 2166
2167} 2167}
2168 2168
2169 2169
2170void CalendarView::updateView(const QDate &start, const QDate &end) 2170void CalendarView::updateView(const QDate &start, const QDate &end)
2171{ 2171{
2172 mTodoList->updateView(); 2172 mTodoList->updateView();
2173 mViewManager->updateView(start, end); 2173 mViewManager->updateView(start, end);
2174 //mDateNavigator->updateView(); 2174 //mDateNavigator->updateView();
2175} 2175}
2176 2176
2177void CalendarView::updateView() 2177void CalendarView::updateView()
2178{ 2178{
2179 DateList tmpList = mNavigator->selectedDates(); 2179 DateList tmpList = mNavigator->selectedDates();
2180 2180
2181 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2181 if ( KOPrefs::instance()->mHideNonStartedTodos )
2182 mTodoList->updateView(); 2182 mTodoList->updateView();
2183 // We assume that the navigator only selects consecutive days. 2183 // We assume that the navigator only selects consecutive days.
2184 updateView( tmpList.first(), tmpList.last() ); 2184 updateView( tmpList.first(), tmpList.last() );
2185} 2185}
2186 2186
2187void CalendarView::updateUnmanagedViews() 2187void CalendarView::updateUnmanagedViews()
2188{ 2188{
2189 mDateNavigator->updateDayMatrix(); 2189 mDateNavigator->updateDayMatrix();
2190} 2190}
2191 2191
2192int CalendarView::msgItemDelete(const QString name) 2192int CalendarView::msgItemDelete(const QString name)
2193{ 2193{
2194 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2194 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2195 i18n("This item will be\npermanently deleted."), 2195 i18n("This item will be\npermanently deleted."),
2196 i18n("KO/Pi Confirmation"),i18n("Delete")); 2196 i18n("KO/Pi Confirmation"),i18n("Delete"));
2197} 2197}
2198 2198
2199 2199
2200void CalendarView::edit_cut() 2200void CalendarView::edit_cut()
2201{ 2201{
2202 Event *anEvent=0; 2202 Event *anEvent=0;
2203 2203
2204 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2204 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2205 2205
2206 if (mViewManager->currentView()->isEventView()) { 2206 if (mViewManager->currentView()->isEventView()) {
2207 if ( incidence && incidence->type() == "Event" ) { 2207 if ( incidence && incidence->type() == "Event" ) {
2208 anEvent = static_cast<Event *>(incidence); 2208 anEvent = static_cast<Event *>(incidence);
2209 } 2209 }
2210 } 2210 }
2211 2211
2212 if (!anEvent) { 2212 if (!anEvent) {
2213 KNotifyClient::beep(); 2213 KNotifyClient::beep();
2214 return; 2214 return;
2215 } 2215 }
2216 DndFactory factory( mCalendar ); 2216 DndFactory factory( mCalendar );
2217 factory.cutEvent(anEvent); 2217 factory.cutEvent(anEvent);
2218 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2218 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2219} 2219}
2220 2220
2221void CalendarView::edit_copy() 2221void CalendarView::edit_copy()
2222{ 2222{
2223 Event *anEvent=0; 2223 Event *anEvent=0;
2224 2224
2225 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2225 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2226 2226
2227 if (mViewManager->currentView()->isEventView()) { 2227 if (mViewManager->currentView()->isEventView()) {
2228 if ( incidence && incidence->type() == "Event" ) { 2228 if ( incidence && incidence->type() == "Event" ) {
2229 anEvent = static_cast<Event *>(incidence); 2229 anEvent = static_cast<Event *>(incidence);
2230 } 2230 }
2231 } 2231 }
2232 2232
2233 if (!anEvent) { 2233 if (!anEvent) {
2234 KNotifyClient::beep(); 2234 KNotifyClient::beep();
2235 return; 2235 return;
2236 } 2236 }
2237 DndFactory factory( mCalendar ); 2237 DndFactory factory( mCalendar );
2238 factory.copyEvent(anEvent); 2238 factory.copyEvent(anEvent);
2239} 2239}
2240 2240
2241void CalendarView::edit_paste() 2241void CalendarView::edit_paste()
2242{ 2242{
2243 QDate date = mNavigator->selectedDates().first(); 2243 QDate date = mNavigator->selectedDates().first();
2244 2244
2245 DndFactory factory( mCalendar ); 2245 DndFactory factory( mCalendar );
2246 Event *pastedEvent = factory.pasteEvent( date ); 2246 Event *pastedEvent = factory.pasteEvent( date );
2247 2247
2248 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2248 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2249} 2249}
2250 2250
2251void CalendarView::edit_options() 2251void CalendarView::edit_options()
2252{ 2252{
2253 mDialogManager->showOptionsDialog(); 2253 mDialogManager->showOptionsDialog();
2254 //writeSettings(); 2254 //writeSettings();
2255} 2255}
2256 2256
2257 2257
2258void CalendarView::slotSelectPickerDate( QDate d) 2258void CalendarView::slotSelectPickerDate( QDate d)
2259{ 2259{
2260 mDateFrame->hide(); 2260 mDateFrame->hide();
2261 if ( mDatePickerMode == 1 ) { 2261 if ( mDatePickerMode == 1 ) {
2262 mNavigator->slotDaySelect( d ); 2262 mNavigator->slotDaySelect( d );
2263 } else if ( mDatePickerMode == 2 ) { 2263 } else if ( mDatePickerMode == 2 ) {
2264 if ( mMoveIncidence->type() == "Todo" ) { 2264 if ( mMoveIncidence->type() == "Todo" ) {
2265 Todo * to = (Todo *) mMoveIncidence; 2265 Todo * to = (Todo *) mMoveIncidence;
2266 QTime tim; 2266 QTime tim;
2267 if ( to->hasDueDate() ) 2267 if ( to->hasDueDate() )
2268 tim = to->dtDue().time(); 2268 tim = to->dtDue().time();
2269 else { 2269 else {
2270 tim = QTime ( 0,0,0 ); 2270 tim = QTime ( 0,0,0 );
2271 to->setFloats( true ); 2271 to->setFloats( true );
2272 to->setHasDueDate( true ); 2272 to->setHasDueDate( true );
2273 } 2273 }
2274 QDateTime dt ( d,tim ); 2274 QDateTime dt ( d,tim );
2275 to->setDtDue( dt ); 2275 to->setDtDue( dt );
2276 todoChanged( to ); 2276 todoChanged( to );
2277 } else { 2277 } else {
2278 if ( mMoveIncidence->doesRecur() ) { 2278 if ( mMoveIncidence->doesRecur() ) {
2279#if 0 2279#if 0
2280 // PENDING implement this 2280 // PENDING implement this
2281 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2281 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2282 mCalendar()->addIncidence( newInc ); 2282 mCalendar()->addIncidence( newInc );
2283 if ( mMoveIncidence->type() == "Todo" ) 2283 if ( mMoveIncidence->type() == "Todo" )
2284 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2284 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2285 else 2285 else
2286 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2286 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2287 mMoveIncidence = newInc; 2287 mMoveIncidence = newInc;
2288 2288
2289#endif 2289#endif
2290 } 2290 }
2291 QTime tim = mMoveIncidence->dtStart().time(); 2291 QTime tim = mMoveIncidence->dtStart().time();
2292 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2292 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2293 QDateTime dt ( d,tim ); 2293 QDateTime dt ( d,tim );
2294 mMoveIncidence->setDtStart( dt ); 2294 mMoveIncidence->setDtStart( dt );
2295 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2295 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2296 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2296 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2297 } 2297 }
2298 2298
2299 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2299 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2300 } 2300 }
2301} 2301}
2302 2302
2303void CalendarView::removeCategories() 2303void CalendarView::removeCategories()
2304{ 2304{
2305 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2305 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2306 QStringList catList = KOPrefs::instance()->mCustomCategories; 2306 QStringList catList = KOPrefs::instance()->mCustomCategories;
2307 QStringList catIncList; 2307 QStringList catIncList;
2308 QStringList newCatList; 2308 QStringList newCatList;
2309 Incidence* inc = incList.first(); 2309 Incidence* inc = incList.first();
2310 int i; 2310 int i;
2311 int count = 0; 2311 int count = 0;
2312 while ( inc ) { 2312 while ( inc ) {
2313 newCatList.clear(); 2313 newCatList.clear();
2314 catIncList = inc->categories() ; 2314 catIncList = inc->categories() ;
2315 for( i = 0; i< catIncList.count(); ++i ) { 2315 for( i = 0; i< catIncList.count(); ++i ) {
2316 if ( catList.contains (catIncList[i])) 2316 if ( catList.contains (catIncList[i]))
2317 newCatList.append( catIncList[i] ); 2317 newCatList.append( catIncList[i] );
2318 } 2318 }
2319 newCatList.sort(); 2319 newCatList.sort();
2320 inc->setCategories( newCatList.join(",") ); 2320 inc->setCategories( newCatList.join(",") );
2321 inc = incList.next(); 2321 inc = incList.next();
2322 } 2322 }
2323} 2323}
2324 2324
2325int CalendarView::addCategories() 2325int CalendarView::addCategories()
2326{ 2326{
2327 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2327 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2328 QStringList catList = KOPrefs::instance()->mCustomCategories; 2328 QStringList catList = KOPrefs::instance()->mCustomCategories;
2329 QStringList catIncList; 2329 QStringList catIncList;
2330 Incidence* inc = incList.first(); 2330 Incidence* inc = incList.first();
2331 int i; 2331 int i;
2332 int count = 0; 2332 int count = 0;
2333 while ( inc ) { 2333 while ( inc ) {
2334 catIncList = inc->categories() ; 2334 catIncList = inc->categories() ;
2335 for( i = 0; i< catIncList.count(); ++i ) { 2335 for( i = 0; i< catIncList.count(); ++i ) {
2336 if ( !catList.contains (catIncList[i])) { 2336 if ( !catList.contains (catIncList[i])) {
2337 catList.append( catIncList[i] ); 2337 catList.append( catIncList[i] );
2338 //qDebug("add cat %s ", catIncList[i].latin1()); 2338 //qDebug("add cat %s ", catIncList[i].latin1());
2339 ++count; 2339 ++count;
2340 } 2340 }
2341 } 2341 }
2342 inc = incList.next(); 2342 inc = incList.next();
2343 } 2343 }
2344 catList.sort(); 2344 catList.sort();
2345 KOPrefs::instance()->mCustomCategories = catList; 2345 KOPrefs::instance()->mCustomCategories = catList;
2346 return count; 2346 return count;
2347} 2347}
2348 2348
2349void CalendarView::manageCategories() 2349void CalendarView::manageCategories()
2350{ 2350{
2351 KOCatPrefs* cp = new KOCatPrefs(); 2351 KOCatPrefs* cp = new KOCatPrefs();
2352 cp->show(); 2352 cp->show();
2353 int w =cp->sizeHint().width() ; 2353 int w =cp->sizeHint().width() ;
2354 int h = cp->sizeHint().height() ; 2354 int h = cp->sizeHint().height() ;
2355 int dw = QApplication::desktop()->width(); 2355 int dw = QApplication::desktop()->width();
2356 int dh = QApplication::desktop()->height(); 2356 int dh = QApplication::desktop()->height();
2357 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2357 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2358 if ( !cp->exec() ) { 2358 if ( !cp->exec() ) {
2359 delete cp; 2359 delete cp;
2360 return; 2360 return;
2361 } 2361 }
2362 int count = 0; 2362 int count = 0;
2363 if ( cp->addCat() ) { 2363 if ( cp->addCat() ) {
2364 count = addCategories(); 2364 count = addCategories();
2365 if ( count ) { 2365 if ( count ) {
2366 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2366 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2367 writeSettings(); 2367 writeSettings();
2368 } else 2368 } else
2369 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2369 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2370 } else { 2370 } else {
2371 removeCategories(); 2371 removeCategories();
2372 updateView(); 2372 updateView();
2373 } 2373 }
2374 delete cp; 2374 delete cp;
2375} 2375}
2376 2376
2377void CalendarView::beamIncidence(Incidence * Inc) 2377void CalendarView::beamIncidence(Incidence * Inc)
2378{ 2378{
2379 QPtrList<Incidence> delSel ; 2379 QPtrList<Incidence> delSel ;
2380 delSel.append(Inc); 2380 delSel.append(Inc);
2381 beamIncidenceList( delSel ); 2381 beamIncidenceList( delSel );
2382} 2382}
2383void CalendarView::beamCalendar() 2383void CalendarView::beamCalendar()
2384{ 2384{
2385 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2385 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2386 //qDebug("beamCalendar() "); 2386 //qDebug("beamCalendar() ");
2387 beamIncidenceList( delSel ); 2387 beamIncidenceList( delSel );
2388} 2388}
2389void CalendarView::beamFilteredCalendar() 2389void CalendarView::beamFilteredCalendar()
2390{ 2390{
2391 QPtrList<Incidence> delSel = mCalendar->incidences(); 2391 QPtrList<Incidence> delSel = mCalendar->incidences();
2392 //qDebug("beamFilteredCalendar() "); 2392 //qDebug("beamFilteredCalendar() ");
2393 beamIncidenceList( delSel ); 2393 beamIncidenceList( delSel );
2394} 2394}
2395void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2395void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2396{ 2396{
2397 if ( beamDialog->exec () == QDialog::Rejected ) 2397 if ( beamDialog->exec () == QDialog::Rejected )
2398 return; 2398 return;
2399#ifdef DESKTOP_VERSION 2399#ifdef DESKTOP_VERSION
2400 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2400 QString fn = locateLocal( "tmp", "kopibeamfile" );
2401#else 2401#else
2402 QString fn = "/tmp/kopibeamfile"; 2402 QString fn = "/tmp/kopibeamfile";
2403#endif 2403#endif
2404 QString mes; 2404 QString mes;
2405 bool createbup = true; 2405 bool createbup = true;
2406 if ( createbup ) { 2406 if ( createbup ) {
2407 QString description = "\n"; 2407 QString description = "\n";
2408 CalendarLocal* cal = new CalendarLocal(); 2408 CalendarLocal* cal = new CalendarLocal();
2409 if ( beamDialog->beamLocal() ) 2409 if ( beamDialog->beamLocal() )
2410 cal->setLocalTime(); 2410 cal->setLocalTime();
2411 else 2411 else
2412 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2412 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2413 Incidence *incidence = delSel.first(); 2413 Incidence *incidence = delSel.first();
2414 bool addText = false; 2414 bool addText = false;
2415 if ( delSel.count() < 10 ) 2415 if ( delSel.count() < 10 )
2416 addText = true; 2416 addText = true;
2417 else { 2417 else {
2418 description.sprintf(i18n(" %d items?"),delSel.count() ); 2418 description.sprintf(i18n(" %d items?"),delSel.count() );
2419 } 2419 }
2420 while ( incidence ) { 2420 while ( incidence ) {
2421 Incidence *in = incidence->clone(); 2421 Incidence *in = incidence->clone();
2422 if ( ! in->summary().isEmpty() ) { 2422 if ( ! in->summary().isEmpty() ) {
2423 in->setDescription(""); 2423 in->setDescription("");
2424 } else { 2424 } else {
2425 in->setSummary( in->description().left(20)); 2425 in->setSummary( in->description().left(20));
2426 in->setDescription(""); 2426 in->setDescription("");
2427 } 2427 }
2428 if ( addText ) 2428 if ( addText )
2429 description += in->summary() + "\n"; 2429 description += in->summary() + "\n";
2430 cal->addIncidence( in ); 2430 cal->addIncidence( in );
2431 incidence = delSel.next(); 2431 incidence = delSel.next();
2432 } 2432 }
2433 if ( beamDialog->beamVcal() ) { 2433 if ( beamDialog->beamVcal() ) {
2434 fn += ".vcs"; 2434 fn += ".vcs";
2435 FileStorage storage( cal, fn, new VCalFormat ); 2435 FileStorage storage( cal, fn, new VCalFormat );
2436 storage.save(); 2436 storage.save();
2437 } else { 2437 } else {
2438 fn += ".ics"; 2438 fn += ".ics";
2439 FileStorage storage( cal, fn, new ICalFormat( ) ); 2439 FileStorage storage( cal, fn, new ICalFormat( ) );
2440 storage.save(); 2440 storage.save();
2441 } 2441 }
2442 delete cal; 2442 delete cal;
2443 mes = i18n("KO/Pi: Ready for beaming"); 2443 mes = i18n("KO/Pi: Ready for beaming");
2444 topLevelWidget()->setCaption(mes); 2444 topLevelWidget()->setCaption(mes);
2445 KApplication::convert2latin1( fn ); 2445 KApplication::convert2latin1( fn );
2446#ifndef DESKTOP_VERSION 2446#ifndef DESKTOP_VERSION
2447 Ir *ir = new Ir( this ); 2447 Ir *ir = new Ir( this );
2448 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2448 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2449 ir->send( fn, description, "text/x-vCalendar" ); 2449 ir->send( fn, description, "text/x-vCalendar" );
2450#endif 2450#endif
2451 } 2451 }
2452} 2452}
2453void CalendarView::beamDone( Ir *ir ) 2453void CalendarView::beamDone( Ir *ir )
2454{ 2454{
2455#ifndef DESKTOP_VERSION 2455#ifndef DESKTOP_VERSION
2456 delete ir; 2456 delete ir;
2457#endif 2457#endif
2458 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2458 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2459 topLevelWidget()->raise(); 2459 topLevelWidget()->raise();
2460} 2460}
2461 2461
2462void CalendarView::moveIncidence(Incidence * inc ) 2462void CalendarView::moveIncidence(Incidence * inc )
2463{ 2463{
2464 if ( !inc ) return; 2464 if ( !inc ) return;
2465 // qDebug("showDatePickerForIncidence( ) "); 2465 // qDebug("showDatePickerForIncidence( ) ");
2466 if ( mDateFrame->isVisible() ) 2466 if ( mDateFrame->isVisible() )
2467 mDateFrame->hide(); 2467 mDateFrame->hide();
2468 else { 2468 else {
2469 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2469 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2470 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2470 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2471 int dw = QApplication::desktop()->width(); 2471 int dw = QApplication::desktop()->width();
2472 int dh = QApplication::desktop()->height(); 2472 int dh = QApplication::desktop()->height();
2473 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2473 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2474 mDateFrame->show(); 2474 mDateFrame->show();
2475 } 2475 }
2476 mDatePickerMode = 2; 2476 mDatePickerMode = 2;
2477 mMoveIncidence = inc ; 2477 mMoveIncidence = inc ;
2478 QDate da; 2478 QDate da;
2479 if ( mMoveIncidence->type() == "Todo" ) { 2479 if ( mMoveIncidence->type() == "Todo" ) {
2480 Todo * to = (Todo *) mMoveIncidence; 2480 Todo * to = (Todo *) mMoveIncidence;
2481 if ( to->hasDueDate() ) 2481 if ( to->hasDueDate() )
2482 da = to->dtDue().date(); 2482 da = to->dtDue().date();
2483 else 2483 else
2484 da = QDate::currentDate(); 2484 da = QDate::currentDate();
2485 } else { 2485 } else {
2486 da = mMoveIncidence->dtStart().date(); 2486 da = mMoveIncidence->dtStart().date();
2487 } 2487 }
2488 //PENDING set date for recurring incidence to date of recurrence 2488 //PENDING set date for recurring incidence to date of recurrence
2489 //mMoveIncidenceOldDate; 2489 //mMoveIncidenceOldDate;
2490 mDatePicker->setDate( da ); 2490 mDatePicker->setDate( da );
2491} 2491}
2492void CalendarView::showDatePicker( ) 2492void CalendarView::showDatePicker( )
2493{ 2493{
2494 //qDebug("CalendarView::showDatePicker( ) "); 2494 //qDebug("CalendarView::showDatePicker( ) ");
2495 if ( mDateFrame->isVisible() ) 2495 if ( mDateFrame->isVisible() )
2496 mDateFrame->hide(); 2496 mDateFrame->hide();
2497 else { 2497 else {
2498 int w =mDatePicker->sizeHint().width() ; 2498 int w =mDatePicker->sizeHint().width() ;
2499 int h = mDatePicker->sizeHint().height() ; 2499 int h = mDatePicker->sizeHint().height() ;
2500 int dw = QApplication::desktop()->width(); 2500 int dw = QApplication::desktop()->width();
2501 int dh = QApplication::desktop()->height(); 2501 int dh = QApplication::desktop()->height();
2502 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2502 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2503 mDateFrame->show(); 2503 mDateFrame->show();
2504 } 2504 }
2505 mDatePickerMode = 1; 2505 mDatePickerMode = 1;
2506 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2506 mDatePicker->setDate( mNavigator->selectedDates().first() );
2507} 2507}
2508 2508
2509void CalendarView::showEventEditor() 2509void CalendarView::showEventEditor()
2510{ 2510{
2511#ifdef DESKTOP_VERSION 2511#ifdef DESKTOP_VERSION
2512 mEventEditor->show(); 2512 mEventEditor->show();
2513#else 2513#else
2514 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2514 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2515 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2515 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2516 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2516 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2517 qApp->processEvents(); 2517 qApp->processEvents();
2518 delete mEventEditor; 2518 delete mEventEditor;
2519 mEventEditor = mDialogManager->getEventEditor(); 2519 mEventEditor = mDialogManager->getEventEditor();
2520 topLevelWidget()->setCaption( i18n("") ); 2520 topLevelWidget()->setCaption( i18n("") );
2521 } 2521 }
2522 mEventEditor->showMaximized(); 2522 mEventEditor->showMaximized();
2523#endif 2523#endif
2524} 2524}
2525void CalendarView::showTodoEditor() 2525void CalendarView::showTodoEditor()
2526{ 2526{
2527#ifdef DESKTOP_VERSION 2527#ifdef DESKTOP_VERSION
2528 mTodoEditor->show(); 2528 mTodoEditor->show();
2529#else 2529#else
2530 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2530 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2531 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2531 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2532 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2532 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2533 qApp->processEvents(); 2533 qApp->processEvents();
2534 delete mTodoEditor; 2534 delete mTodoEditor;
2535 mTodoEditor = mDialogManager->getTodoEditor(); 2535 mTodoEditor = mDialogManager->getTodoEditor();
2536 topLevelWidget()->setCaption( i18n("") ); 2536 topLevelWidget()->setCaption( i18n("") );
2537 } 2537 }
2538 mTodoEditor->showMaximized(); 2538 mTodoEditor->showMaximized();
2539#endif 2539#endif
2540} 2540}
2541 2541
2542void CalendarView::cloneIncidence() 2542void CalendarView::cloneIncidence()
2543{ 2543{
2544 Incidence *incidence = currentSelection(); 2544 Incidence *incidence = currentSelection();
2545 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2545 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2546 if ( incidence ) { 2546 if ( incidence ) {
2547 cloneIncidence(incidence); 2547 cloneIncidence(incidence);
2548 } 2548 }
2549} 2549}
2550void CalendarView::moveIncidence() 2550void CalendarView::moveIncidence()
2551{ 2551{
2552 Incidence *incidence = currentSelection(); 2552 Incidence *incidence = currentSelection();
2553 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2553 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2554 if ( incidence ) { 2554 if ( incidence ) {
2555 moveIncidence(incidence); 2555 moveIncidence(incidence);
2556 } 2556 }
2557} 2557}
2558void CalendarView::beamIncidence() 2558void CalendarView::beamIncidence()
2559{ 2559{
2560 Incidence *incidence = currentSelection(); 2560 Incidence *incidence = currentSelection();
2561 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2561 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2562 if ( incidence ) { 2562 if ( incidence ) {
2563 beamIncidence(incidence); 2563 beamIncidence(incidence);
2564 } 2564 }
2565} 2565}
2566void CalendarView::toggleCancelIncidence() 2566void CalendarView::toggleCancelIncidence()
2567{ 2567{
2568 Incidence *incidence = currentSelection(); 2568 Incidence *incidence = currentSelection();
2569 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2569 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2570 if ( incidence ) { 2570 if ( incidence ) {
2571 cancelIncidence(incidence); 2571 cancelIncidence(incidence);
2572 } 2572 }
2573} 2573}
2574 2574
2575 2575
2576void CalendarView::cancelIncidence(Incidence * inc ) 2576void CalendarView::cancelIncidence(Incidence * inc )
2577{ 2577{
2578 inc->setCancelled( ! inc->cancelled() ); 2578 inc->setCancelled( ! inc->cancelled() );
2579 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2579 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2580 updateView(); 2580 updateView();
2581} 2581}
2582void CalendarView::cloneIncidence(Incidence * orgInc ) 2582void CalendarView::cloneIncidence(Incidence * orgInc )
2583{ 2583{
2584 Incidence * newInc = orgInc->clone(); 2584 Incidence * newInc = orgInc->clone();
2585 newInc->recreate(); 2585 newInc->recreate();
2586 2586
2587 if ( newInc->type() == "Todo" ) { 2587 if ( newInc->type() == "Todo" ) {
2588 Todo* t = (Todo*) newInc; 2588 Todo* t = (Todo*) newInc;
2589 showTodoEditor(); 2589 showTodoEditor();
2590 mTodoEditor->editTodo( t ); 2590 mTodoEditor->editTodo( t );
2591 if ( mTodoEditor->exec() ) { 2591 if ( mTodoEditor->exec() ) {
2592 mCalendar->addTodo( t ); 2592 mCalendar->addTodo( t );
2593 updateView(); 2593 updateView();
2594 } else { 2594 } else {
2595 delete t; 2595 delete t;
2596 } 2596 }
2597 } 2597 }
2598 else { 2598 else {
2599 Event* e = (Event*) newInc; 2599 Event* e = (Event*) newInc;
2600 showEventEditor(); 2600 showEventEditor();
2601 mEventEditor->editEvent( e ); 2601 mEventEditor->editEvent( e );
2602 if ( mEventEditor->exec() ) { 2602 if ( mEventEditor->exec() ) {
2603 mCalendar->addEvent( e ); 2603 mCalendar->addEvent( e );
2604 updateView(); 2604 updateView();
2605 } else { 2605 } else {
2606 delete e; 2606 delete e;
2607 } 2607 }
2608 } 2608 }
2609} 2609}
2610 2610
2611void CalendarView::newEvent() 2611void CalendarView::newEvent()
2612{ 2612{
2613 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2613 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2614 KOAgendaView *aView = mViewManager->agendaView(); 2614 KOAgendaView *aView = mViewManager->agendaView();
2615 if (aView) { 2615 if (aView) {
2616 if (aView->selectionStart().isValid()) { 2616 if (aView->selectionStart().isValid()) {
2617 if (aView->selectedIsAllDay()) { 2617 if (aView->selectedIsAllDay()) {
2618 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2618 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2619 } else { 2619 } else {
2620 newEvent(aView->selectionStart(),aView->selectionEnd()); 2620 newEvent(aView->selectionStart(),aView->selectionEnd());
2621 } 2621 }
2622 return; 2622 return;
2623 } 2623 }
2624 } 2624 }
2625 2625
2626 QDate date = mNavigator->selectedDates().first(); 2626 QDate date = mNavigator->selectedDates().first();
2627 QDateTime current = QDateTime::currentDateTime(); 2627 QDateTime current = QDateTime::currentDateTime();
2628 if ( date <= current.date() ) { 2628 if ( date <= current.date() ) {
2629 int hour = current.time().hour() +1; 2629 int hour = current.time().hour() +1;
2630 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2630 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2631 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2631 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2632 } else 2632 } else
2633 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2633 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2634 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2634 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2635 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2635 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2636} 2636}
2637 2637
2638void CalendarView::newEvent(QDateTime fh) 2638void CalendarView::newEvent(QDateTime fh)
2639{ 2639{
2640 newEvent(fh, 2640 newEvent(fh,
2641 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2641 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2642} 2642}
2643 2643
2644void CalendarView::newEvent(QDate dt) 2644void CalendarView::newEvent(QDate dt)
2645{ 2645{
2646 newEvent(QDateTime(dt, QTime(0,0,0)), 2646 newEvent(QDateTime(dt, QTime(0,0,0)),
2647 QDateTime(dt, QTime(0,0,0)), true); 2647 QDateTime(dt, QTime(0,0,0)), true);
2648} 2648}
2649 2649void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2650{
2651 newEvent(fromHint, toHint, false);
2652}
2650void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2653void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2651{ 2654{
2652 2655
2653 showEventEditor(); 2656 showEventEditor();
2654 mEventEditor->newEvent(fromHint,toHint,allDay); 2657 mEventEditor->newEvent(fromHint,toHint,allDay);
2655 if ( mFilterView->filtersEnabled() ) { 2658 if ( mFilterView->filtersEnabled() ) {
2656 CalFilter *filter = mFilterView->selectedFilter(); 2659 CalFilter *filter = mFilterView->selectedFilter();
2657 if (filter && filter->showCategories()) { 2660 if (filter && filter->showCategories()) {
2658 mEventEditor->setCategories(filter->categoryList().join(",") ); 2661 mEventEditor->setCategories(filter->categoryList().join(",") );
2659 } 2662 }
2660 if ( filter ) 2663 if ( filter )
2661 mEventEditor->setSecrecy( filter->getSecrecy() ); 2664 mEventEditor->setSecrecy( filter->getSecrecy() );
2662 } 2665 }
2663} 2666}
2664void CalendarView::todoAdded(Todo * t) 2667void CalendarView::todoAdded(Todo * t)
2665{ 2668{
2666 2669
2667 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2670 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2668 updateTodoViews(); 2671 updateTodoViews();
2669} 2672}
2670void CalendarView::todoChanged(Todo * t) 2673void CalendarView::todoChanged(Todo * t)
2671{ 2674{
2672 emit todoModified( t, 4 ); 2675 emit todoModified( t, 4 );
2673 // updateTodoViews(); 2676 // updateTodoViews();
2674} 2677}
2675void CalendarView::todoToBeDeleted(Todo *) 2678void CalendarView::todoToBeDeleted(Todo *)
2676{ 2679{
2677 //qDebug("todoToBeDeleted(Todo *) "); 2680 //qDebug("todoToBeDeleted(Todo *) ");
2678 updateTodoViews(); 2681 updateTodoViews();
2679} 2682}
2680void CalendarView::todoDeleted() 2683void CalendarView::todoDeleted()
2681{ 2684{
2682 //qDebug(" todoDeleted()"); 2685 //qDebug(" todoDeleted()");
2683 updateTodoViews(); 2686 updateTodoViews();
2684} 2687}
2685 2688
2686 2689
2687 2690void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
2688void CalendarView::newTodo()
2689{ 2691{
2690 2692 qDebug("datetime ");
2691 showTodoEditor(); 2693 showTodoEditor();
2692 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2694 mTodoEditor->newTodo(dt,0,allday);
2693 if ( mFilterView->filtersEnabled() ) { 2695 if ( mFilterView->filtersEnabled() ) {
2694 CalFilter *filter = mFilterView->selectedFilter(); 2696 CalFilter *filter = mFilterView->selectedFilter();
2695 if (filter && filter->showCategories()) { 2697 if (filter && filter->showCategories()) {
2696 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2698 mTodoEditor->setCategories(filter->categoryList().join(",") );
2697 } 2699 }
2698 if ( filter ) 2700 if ( filter )
2699 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2701 mTodoEditor->setSecrecy( filter->getSecrecy() );
2700 } 2702 }
2701} 2703}
2702 2704
2705void CalendarView::newTodo()
2706{
2707 newTodoDateTime( QDateTime(),true );
2708}
2709
2703void CalendarView::newSubTodo() 2710void CalendarView::newSubTodo()
2704{ 2711{
2705 Todo *todo = selectedTodo(); 2712 Todo *todo = selectedTodo();
2706 if ( todo ) newSubTodo( todo ); 2713 if ( todo ) newSubTodo( todo );
2707} 2714}
2708 2715
2709void CalendarView::newSubTodo(Todo *parentEvent) 2716void CalendarView::newSubTodo(Todo *parentEvent)
2710{ 2717{
2711 2718
2712 showTodoEditor(); 2719 showTodoEditor();
2713 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2720 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2714} 2721}
2715 2722
2716void CalendarView::newFloatingEvent() 2723void CalendarView::newFloatingEvent()
2717{ 2724{
2718 DateList tmpList = mNavigator->selectedDates(); 2725 DateList tmpList = mNavigator->selectedDates();
2719 QDate date = tmpList.first(); 2726 QDate date = tmpList.first();
2720 2727
2721 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2728 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2722 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2729 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2723} 2730}
2724 2731
2725 2732
2726void CalendarView::editEvent( Event *event ) 2733void CalendarView::editEvent( Event *event )
2727{ 2734{
2728 2735
2729 if ( !event ) return; 2736 if ( !event ) return;
2730 if ( event->isReadOnly() ) { 2737 if ( event->isReadOnly() ) {
2731 showEvent( event ); 2738 showEvent( event );
2732 return; 2739 return;
2733 } 2740 }
2734 showEventEditor(); 2741 showEventEditor();
2735 mEventEditor->editEvent( event , mFlagEditDescription); 2742 mEventEditor->editEvent( event , mFlagEditDescription);
2736} 2743}
2737void CalendarView::editJournal( Journal *jour ) 2744void CalendarView::editJournal( Journal *jour )
2738{ 2745{
2739 if ( !jour ) return; 2746 if ( !jour ) return;
2740 mDialogManager->hideSearchDialog(); 2747 mDialogManager->hideSearchDialog();
2741 mViewManager->showJournalView(); 2748 mViewManager->showJournalView();
2742 mNavigator->slotDaySelect( jour->dtStart().date() ); 2749 mNavigator->slotDaySelect( jour->dtStart().date() );
2743} 2750}
2744void CalendarView::editTodo( Todo *todo ) 2751void CalendarView::editTodo( Todo *todo )
2745{ 2752{
2746 if ( !todo ) return; 2753 if ( !todo ) return;
2747 2754
2748 if ( todo->isReadOnly() ) { 2755 if ( todo->isReadOnly() ) {
2749 showTodo( todo ); 2756 showTodo( todo );
2750 return; 2757 return;
2751 } 2758 }
2752 showTodoEditor(); 2759 showTodoEditor();
2753 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2760 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2754 2761
2755} 2762}
2756 2763
2757KOEventViewerDialog* CalendarView::getEventViewerDialog() 2764KOEventViewerDialog* CalendarView::getEventViewerDialog()
2758{ 2765{
2759 if ( !mEventViewerDialog ) { 2766 if ( !mEventViewerDialog ) {
2760 mEventViewerDialog = new KOEventViewerDialog(this); 2767 mEventViewerDialog = new KOEventViewerDialog(this);
2761 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2768 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2762 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2769 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2763 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2770 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2764 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2771 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2765 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2772 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2766 viewManager(), SLOT( showAgendaView( bool ) ) ); 2773 viewManager(), SLOT( showAgendaView( bool ) ) );
2767 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 2774 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
2768 this, SLOT( todoChanged(Todo *) ) ); 2775 this, SLOT( todoChanged(Todo *) ) );
2769 mEventViewerDialog->resize( 640, 480 ); 2776 mEventViewerDialog->resize( 640, 480 );
2770 2777
2771 } 2778 }
2772 return mEventViewerDialog; 2779 return mEventViewerDialog;
2773} 2780}
2774void CalendarView::showEvent(Event *event) 2781void CalendarView::showEvent(Event *event)
2775{ 2782{
2776 getEventViewerDialog()->setEvent(event); 2783 getEventViewerDialog()->setEvent(event);
2777 getEventViewerDialog()->showMe(); 2784 getEventViewerDialog()->showMe();
2778} 2785}
2779 2786
2780void CalendarView::showTodo(Todo *event) 2787void CalendarView::showTodo(Todo *event)
2781{ 2788{
2782 getEventViewerDialog()->setTodo(event); 2789 getEventViewerDialog()->setTodo(event);
2783 getEventViewerDialog()->showMe(); 2790 getEventViewerDialog()->showMe();
2784} 2791}
2785void CalendarView::showJournal( Journal *jour ) 2792void CalendarView::showJournal( Journal *jour )
2786{ 2793{
2787 getEventViewerDialog()->setJournal(jour); 2794 getEventViewerDialog()->setJournal(jour);
2788 getEventViewerDialog()->showMe(); 2795 getEventViewerDialog()->showMe();
2789 2796
2790} 2797}
2791// void CalendarView::todoModified (Todo *event, int changed) 2798// void CalendarView::todoModified (Todo *event, int changed)
2792// { 2799// {
2793// // if (mDialogList.find (event) != mDialogList.end ()) { 2800// // if (mDialogList.find (event) != mDialogList.end ()) {
2794// // kdDebug() << "Todo modified and open" << endl; 2801// // kdDebug() << "Todo modified and open" << endl;
2795// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2802// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2796// // temp->modified (changed); 2803// // temp->modified (changed);
2797 2804
2798// // } 2805// // }
2799 2806
2800// mViewManager->updateView(); 2807// mViewManager->updateView();
2801// } 2808// }
2802 2809
2803void CalendarView::appointment_show() 2810void CalendarView::appointment_show()
2804{ 2811{
2805 Event *anEvent = 0; 2812 Event *anEvent = 0;
2806 2813
2807 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2814 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2808 2815
2809 if (mViewManager->currentView()->isEventView()) { 2816 if (mViewManager->currentView()->isEventView()) {
2810 if ( incidence && incidence->type() == "Event" ) { 2817 if ( incidence && incidence->type() == "Event" ) {
2811 anEvent = static_cast<Event *>(incidence); 2818 anEvent = static_cast<Event *>(incidence);
2812 } 2819 }
2813 } 2820 }
2814 2821
2815 if (!anEvent) { 2822 if (!anEvent) {
2816 KNotifyClient::beep(); 2823 KNotifyClient::beep();
2817 return; 2824 return;
2818 } 2825 }
2819 2826
2820 showEvent(anEvent); 2827 showEvent(anEvent);
2821} 2828}
2822 2829
2823void CalendarView::appointment_edit() 2830void CalendarView::appointment_edit()
2824{ 2831{
2825 Event *anEvent = 0; 2832 Event *anEvent = 0;
2826 2833
2827 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2834 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2828 2835
2829 if (mViewManager->currentView()->isEventView()) { 2836 if (mViewManager->currentView()->isEventView()) {
2830 if ( incidence && incidence->type() == "Event" ) { 2837 if ( incidence && incidence->type() == "Event" ) {
2831 anEvent = static_cast<Event *>(incidence); 2838 anEvent = static_cast<Event *>(incidence);
2832 } 2839 }
2833 } 2840 }
2834 2841
2835 if (!anEvent) { 2842 if (!anEvent) {
2836 KNotifyClient::beep(); 2843 KNotifyClient::beep();
2837 return; 2844 return;
2838 } 2845 }
2839 2846
2840 editEvent(anEvent); 2847 editEvent(anEvent);
2841} 2848}
2842 2849
2843void CalendarView::appointment_delete() 2850void CalendarView::appointment_delete()
2844{ 2851{
2845 Event *anEvent = 0; 2852 Event *anEvent = 0;
2846 2853
2847 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2854 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2848 2855
2849 if (mViewManager->currentView()->isEventView()) { 2856 if (mViewManager->currentView()->isEventView()) {
2850 if ( incidence && incidence->type() == "Event" ) { 2857 if ( incidence && incidence->type() == "Event" ) {
2851 anEvent = static_cast<Event *>(incidence); 2858 anEvent = static_cast<Event *>(incidence);
2852 } 2859 }
2853 } 2860 }
2854 2861
2855 if (!anEvent) { 2862 if (!anEvent) {
2856 KNotifyClient::beep(); 2863 KNotifyClient::beep();
2857 return; 2864 return;
2858 } 2865 }
2859 2866
2860 deleteEvent(anEvent); 2867 deleteEvent(anEvent);
2861} 2868}
2862 2869
2863void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2870void CalendarView::todo_resub( Todo * parent, Todo * sub )
2864{ 2871{
2865 if (!sub) return; 2872 if (!sub) return;
2866 if (!parent) return; 2873 if (!parent) return;
2867 if ( sub->relatedTo() ) 2874 if ( sub->relatedTo() )
2868 sub->relatedTo()->removeRelation(sub); 2875 sub->relatedTo()->removeRelation(sub);
2869 sub->setRelatedTo(parent); 2876 sub->setRelatedTo(parent);
2870 sub->setRelatedToUid(parent->uid()); 2877 sub->setRelatedToUid(parent->uid());
2871 parent->addRelation(sub); 2878 parent->addRelation(sub);
2872 sub->updated(); 2879 sub->updated();
2873 parent->updated(); 2880 parent->updated();
2874 setModified(true); 2881 setModified(true);
2875 updateView(); 2882 updateView();
2876} 2883}
2877void CalendarView::todo_unsub(Todo *anTodo ) 2884void CalendarView::todo_unsub(Todo *anTodo )
2878{ 2885{
2879 // Todo *anTodo = selectedTodo(); 2886 // Todo *anTodo = selectedTodo();
2880 if (!anTodo) return; 2887 if (!anTodo) return;
2881 if (!anTodo->relatedTo()) return; 2888 if (!anTodo->relatedTo()) return;
2882 anTodo->relatedTo()->removeRelation(anTodo); 2889 anTodo->relatedTo()->removeRelation(anTodo);
2883 anTodo->setRelatedTo(0); 2890 anTodo->setRelatedTo(0);
2884 anTodo->updated(); 2891 anTodo->updated();
2885 anTodo->setRelatedToUid(""); 2892 anTodo->setRelatedToUid("");
2886 setModified(true); 2893 setModified(true);
2887 updateView(); 2894 updateView();
2888} 2895}
2889 2896
2890void CalendarView::deleteTodo(Todo *todo) 2897void CalendarView::deleteTodo(Todo *todo)
2891{ 2898{
2892 if (!todo) { 2899 if (!todo) {
2893 KNotifyClient::beep(); 2900 KNotifyClient::beep();
2894 return; 2901 return;
2895 } 2902 }
2896 if (KOPrefs::instance()->mConfirm) { 2903 if (KOPrefs::instance()->mConfirm) {
2897 QString text = todo->summary().left(20); 2904 QString text = todo->summary().left(20);
2898 if (!todo->relations().isEmpty()) { 2905 if (!todo->relations().isEmpty()) {
2899 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 2906 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
2900 2907
2901 } 2908 }
2902 switch (msgItemDelete(text)) { 2909 switch (msgItemDelete(text)) {
2903 case KMessageBox::Continue: // OK 2910 case KMessageBox::Continue: // OK
2904 bool deleteT = false; 2911 bool deleteT = false;
2905 if (!todo->relations().isEmpty()) { 2912 if (!todo->relations().isEmpty()) {
2906 deleteT = removeCompletedSubTodos( todo ); 2913 deleteT = removeCompletedSubTodos( todo );
2907 } 2914 }
2908 // deleteT == true: todo already deleted in removeCompletedSubTodos 2915 // deleteT == true: todo already deleted in removeCompletedSubTodos
2909 if ( !deleteT ) { 2916 if ( !deleteT ) {
2910 checkExternalId( todo ); 2917 checkExternalId( todo );
2911 calendar()->deleteTodo(todo); 2918 calendar()->deleteTodo(todo);
2912 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2919 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2913 updateView(); 2920 updateView();
2914 } 2921 }
2915 break; 2922 break;
2916 } // switch 2923 } // switch
2917 } else { 2924 } else {
2918 checkExternalId( todo ); 2925 checkExternalId( todo );
2919 mCalendar->deleteTodo(todo); 2926 mCalendar->deleteTodo(todo);
2920 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2927 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2921 updateView(); 2928 updateView();
2922 } 2929 }
2923 2930
2924 emit updateSearchDialog(); 2931 emit updateSearchDialog();
2925} 2932}
2926void CalendarView::deleteJournal(Journal *jour) 2933void CalendarView::deleteJournal(Journal *jour)
2927{ 2934{
2928 if (!jour) { 2935 if (!jour) {
2929 KNotifyClient::beep(); 2936 KNotifyClient::beep();
2930 return; 2937 return;
2931 } 2938 }
2932 if (KOPrefs::instance()->mConfirm) { 2939 if (KOPrefs::instance()->mConfirm) {
2933 switch (msgItemDelete( jour->description().left(20))) { 2940 switch (msgItemDelete( jour->description().left(20))) {
2934 case KMessageBox::Continue: // OK 2941 case KMessageBox::Continue: // OK
2935 calendar()->deleteJournal(jour); 2942 calendar()->deleteJournal(jour);
2936 updateView(); 2943 updateView();
2937 break; 2944 break;
2938 } // switch 2945 } // switch
2939 } else { 2946 } else {
2940 calendar()->deleteJournal(jour);; 2947 calendar()->deleteJournal(jour);;
2941 updateView(); 2948 updateView();
2942 } 2949 }
2943 emit updateSearchDialog(); 2950 emit updateSearchDialog();
2944} 2951}
2945 2952
2946void CalendarView::deleteEvent(Event *anEvent) 2953void CalendarView::deleteEvent(Event *anEvent)
2947{ 2954{
2948 if (!anEvent) { 2955 if (!anEvent) {
2949 KNotifyClient::beep(); 2956 KNotifyClient::beep();
2950 return; 2957 return;
2951 } 2958 }
2952 2959
2953 if (anEvent->recurrence()->doesRecur()) { 2960 if (anEvent->recurrence()->doesRecur()) {
2954 QDate itemDate = mViewManager->currentSelectionDate(); 2961 QDate itemDate = mViewManager->currentSelectionDate();
2955 int km; 2962 int km;
2956 if (!itemDate.isValid()) { 2963 if (!itemDate.isValid()) {
2957 //kdDebug() << "Date Not Valid" << endl; 2964 //kdDebug() << "Date Not Valid" << endl;
2958 if (KOPrefs::instance()->mConfirm) { 2965 if (KOPrefs::instance()->mConfirm) {
2959 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 2966 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
2960 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2967 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2961 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2968 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2962 if ( km == KMessageBox::Continue ) 2969 if ( km == KMessageBox::Continue )
2963 km = KMessageBox::No; // No = all below 2970 km = KMessageBox::No; // No = all below
2964 } else 2971 } else
2965 km = KMessageBox::No; 2972 km = KMessageBox::No;
2966 } else { 2973 } else {
2967 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 2974 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
2968 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2975 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2969 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2976 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2970 i18n("KO/Pi Confirmation"),i18n("Current"), 2977 i18n("KO/Pi Confirmation"),i18n("Current"),
2971 i18n("All")); 2978 i18n("All"));
2972 } 2979 }
2973 switch(km) { 2980 switch(km) {
2974 2981
2975 case KMessageBox::No: // Continue // all 2982 case KMessageBox::No: // Continue // all
2976 //qDebug("KMessageBox::No "); 2983 //qDebug("KMessageBox::No ");
2977 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2984 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2978 schedule(Scheduler::Cancel,anEvent); 2985 schedule(Scheduler::Cancel,anEvent);
2979 2986
2980 checkExternalId( anEvent); 2987 checkExternalId( anEvent);
2981 mCalendar->deleteEvent(anEvent); 2988 mCalendar->deleteEvent(anEvent);
2982 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2989 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2983 break; 2990 break;
2984 2991
2985 // Disabled because it does not work 2992 // Disabled because it does not work
2986 //#if 0 2993 //#if 0
2987 case KMessageBox::Yes: // just this one 2994 case KMessageBox::Yes: // just this one
2988 //QDate qd = mNavigator->selectedDates().first(); 2995 //QDate qd = mNavigator->selectedDates().first();
2989 //if (!qd.isValid()) { 2996 //if (!qd.isValid()) {
2990 // kdDebug() << "no date selected, or invalid date" << endl; 2997 // kdDebug() << "no date selected, or invalid date" << endl;
2991 // KNotifyClient::beep(); 2998 // KNotifyClient::beep();
2992 // return; 2999 // return;
2993 //} 3000 //}
2994 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3001 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2995 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3002 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2996 anEvent->addExDate(itemDate); 3003 anEvent->addExDate(itemDate);
2997 int duration = anEvent->recurrence()->duration(); 3004 int duration = anEvent->recurrence()->duration();
2998 if ( duration > 0 ) { 3005 if ( duration > 0 ) {
2999 anEvent->recurrence()->setDuration( duration - 1 ); 3006 anEvent->recurrence()->setDuration( duration - 1 );
3000 } 3007 }
3001 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3008 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3002 } 3009 }
3003 break; 3010 break;
3004 //#endif 3011 //#endif
3005 } // switch 3012 } // switch
3006 } else { 3013 } else {
3007 if (KOPrefs::instance()->mConfirm) { 3014 if (KOPrefs::instance()->mConfirm) {
3008 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3015 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3009 i18n("\nAre you sure you want\nto delete this event?"), 3016 i18n("\nAre you sure you want\nto delete this event?"),
3010 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3017 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3011 case KMessageBox::Continue: // OK 3018 case KMessageBox::Continue: // OK
3012 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3019 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3013 schedule(Scheduler::Cancel,anEvent); 3020 schedule(Scheduler::Cancel,anEvent);
3014 checkExternalId( anEvent); 3021 checkExternalId( anEvent);
3015 mCalendar->deleteEvent(anEvent); 3022 mCalendar->deleteEvent(anEvent);
3016 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3023 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3017 break; 3024 break;
3018 } // switch 3025 } // switch
3019 } else { 3026 } else {
3020 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3027 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3021 schedule(Scheduler::Cancel,anEvent); 3028 schedule(Scheduler::Cancel,anEvent);
3022 checkExternalId( anEvent); 3029 checkExternalId( anEvent);
3023 mCalendar->deleteEvent(anEvent); 3030 mCalendar->deleteEvent(anEvent);
3024 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3031 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3025 } 3032 }
3026 } // if-else 3033 } // if-else
3027 emit updateSearchDialog(); 3034 emit updateSearchDialog();
3028} 3035}
3029 3036
3030bool CalendarView::deleteEvent(const QString &uid) 3037bool CalendarView::deleteEvent(const QString &uid)
3031{ 3038{
3032 Event *ev = mCalendar->event(uid); 3039 Event *ev = mCalendar->event(uid);
3033 if (ev) { 3040 if (ev) {
3034 deleteEvent(ev); 3041 deleteEvent(ev);
3035 return true; 3042 return true;
3036 } else { 3043 } else {
3037 return false; 3044 return false;
3038 } 3045 }
3039} 3046}
3040 3047
3041/*****************************************************************************/ 3048/*****************************************************************************/
3042 3049
3043void CalendarView::action_mail() 3050void CalendarView::action_mail()
3044{ 3051{
3045#ifndef KORG_NOMAIL 3052#ifndef KORG_NOMAIL
3046 KOMailClient mailClient; 3053 KOMailClient mailClient;
3047 3054
3048 Incidence *incidence = currentSelection(); 3055 Incidence *incidence = currentSelection();
3049 3056
3050 if (!incidence) { 3057 if (!incidence) {
3051 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3058 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3052 return; 3059 return;
3053 } 3060 }
3054 if(incidence->attendeeCount() == 0 ) { 3061 if(incidence->attendeeCount() == 0 ) {
3055 KMessageBox::sorry(this, 3062 KMessageBox::sorry(this,
3056 i18n("Can't generate mail:\nNo attendees defined.\n")); 3063 i18n("Can't generate mail:\nNo attendees defined.\n"));
3057 return; 3064 return;
3058 } 3065 }
3059 3066
3060 CalendarLocal cal_tmp; 3067 CalendarLocal cal_tmp;
3061 Event *event = 0; 3068 Event *event = 0;
3062 Event *ev = 0; 3069 Event *ev = 0;
3063 if ( incidence && incidence->type() == "Event" ) { 3070 if ( incidence && incidence->type() == "Event" ) {
3064 event = static_cast<Event *>(incidence); 3071 event = static_cast<Event *>(incidence);
3065 ev = new Event(*event); 3072 ev = new Event(*event);
3066 cal_tmp.addEvent(ev); 3073 cal_tmp.addEvent(ev);
3067 } 3074 }
3068 ICalFormat mForm(); 3075 ICalFormat mForm();
3069 QString attachment = mForm.toString( &cal_tmp ); 3076 QString attachment = mForm.toString( &cal_tmp );
3070 if (ev) delete(ev); 3077 if (ev) delete(ev);
3071 3078
3072 mailClient.mailAttendees(currentSelection(), attachment); 3079 mailClient.mailAttendees(currentSelection(), attachment);
3073 3080
3074#endif 3081#endif
3075 3082
3076#if 0 3083#if 0
3077 Event *anEvent = 0; 3084 Event *anEvent = 0;
3078 if (mViewManager->currentView()->isEventView()) { 3085 if (mViewManager->currentView()->isEventView()) {
3079 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3086 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3080 } 3087 }
3081 3088
3082 if (!anEvent) { 3089 if (!anEvent) {
3083 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3090 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3084 return; 3091 return;
3085 } 3092 }
3086 if(anEvent->attendeeCount() == 0 ) { 3093 if(anEvent->attendeeCount() == 0 ) {
3087 KMessageBox::sorry(this, 3094 KMessageBox::sorry(this,
3088 i18n("Can't generate mail:\nNo attendees defined.\n")); 3095 i18n("Can't generate mail:\nNo attendees defined.\n"));
3089 return; 3096 return;
3090 } 3097 }
3091 3098
3092 mailobject.emailEvent(anEvent); 3099 mailobject.emailEvent(anEvent);
3093#endif 3100#endif
3094} 3101}
3095 3102
3096 3103
3097void CalendarView::schedule_publish(Incidence *incidence) 3104void CalendarView::schedule_publish(Incidence *incidence)
3098{ 3105{
3099 Event *event = 0; 3106 Event *event = 0;
3100 Todo *todo = 0; 3107 Todo *todo = 0;
3101 3108
3102 if (incidence == 0) { 3109 if (incidence == 0) {
3103 incidence = mViewManager->currentView()->selectedIncidences().first(); 3110 incidence = mViewManager->currentView()->selectedIncidences().first();
3104 if (incidence == 0) { 3111 if (incidence == 0) {
3105 incidence = mTodoList->selectedIncidences().first(); 3112 incidence = mTodoList->selectedIncidences().first();
3106 } 3113 }
3107 } 3114 }
3108 if ( incidence && incidence->type() == "Event" ) { 3115 if ( incidence && incidence->type() == "Event" ) {
3109 event = static_cast<Event *>(incidence); 3116 event = static_cast<Event *>(incidence);
3110 } else { 3117 } else {
3111 if ( incidence && incidence->type() == "Todo" ) { 3118 if ( incidence && incidence->type() == "Todo" ) {
3112 todo = static_cast<Todo *>(incidence); 3119 todo = static_cast<Todo *>(incidence);
3113 } 3120 }
3114 } 3121 }
3115 3122
3116 if (!event && !todo) { 3123 if (!event && !todo) {
3117 KMessageBox::sorry(this,i18n("No event selected.")); 3124 KMessageBox::sorry(this,i18n("No event selected."));
3118 return; 3125 return;
3119 } 3126 }
3120 3127
3121 PublishDialog *publishdlg = new PublishDialog(); 3128 PublishDialog *publishdlg = new PublishDialog();
3122 if (incidence->attendeeCount()>0) { 3129 if (incidence->attendeeCount()>0) {
3123 QPtrList<Attendee> attendees = incidence->attendees(); 3130 QPtrList<Attendee> attendees = incidence->attendees();
3124 attendees.first(); 3131 attendees.first();
3125 while ( attendees.current()!=0 ) { 3132 while ( attendees.current()!=0 ) {
3126 publishdlg->addAttendee(attendees.current()); 3133 publishdlg->addAttendee(attendees.current());
3127 attendees.next(); 3134 attendees.next();
3128 } 3135 }
3129 } 3136 }
3130 bool send = true; 3137 bool send = true;
3131 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3138 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3132 if ( publishdlg->exec() != QDialog::Accepted ) 3139 if ( publishdlg->exec() != QDialog::Accepted )
3133 send = false; 3140 send = false;
3134 } 3141 }
3135 if ( send ) { 3142 if ( send ) {
3136 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3143 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3137 if ( event ) { 3144 if ( event ) {
3138 Event *ev = new Event(*event); 3145 Event *ev = new Event(*event);
3139 ev->registerObserver(0); 3146 ev->registerObserver(0);
3140 ev->clearAttendees(); 3147 ev->clearAttendees();
3141 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3148 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3142 delete(ev); 3149 delete(ev);
3143 } 3150 }
3144 } else { 3151 } else {
3145 if ( todo ) { 3152 if ( todo ) {
3146 Todo *ev = new Todo(*todo); 3153 Todo *ev = new Todo(*todo);
3147 ev->registerObserver(0); 3154 ev->registerObserver(0);
3148 ev->clearAttendees(); 3155 ev->clearAttendees();
3149 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3156 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3150 delete(ev); 3157 delete(ev);
3151 } 3158 }
3152 } 3159 }
3153 } 3160 }
3154 } 3161 }
3155 delete publishdlg; 3162 delete publishdlg;
3156} 3163}
3157 3164
3158void CalendarView::schedule_request(Incidence *incidence) 3165void CalendarView::schedule_request(Incidence *incidence)
3159{ 3166{
3160 schedule(Scheduler::Request,incidence); 3167 schedule(Scheduler::Request,incidence);
3161} 3168}
3162 3169
3163void CalendarView::schedule_refresh(Incidence *incidence) 3170void CalendarView::schedule_refresh(Incidence *incidence)
3164{ 3171{
3165 schedule(Scheduler::Refresh,incidence); 3172 schedule(Scheduler::Refresh,incidence);
3166} 3173}
3167 3174
3168void CalendarView::schedule_cancel(Incidence *incidence) 3175void CalendarView::schedule_cancel(Incidence *incidence)
3169{ 3176{
3170 schedule(Scheduler::Cancel,incidence); 3177 schedule(Scheduler::Cancel,incidence);
3171} 3178}
3172 3179
3173void CalendarView::schedule_add(Incidence *incidence) 3180void CalendarView::schedule_add(Incidence *incidence)
3174{ 3181{
3175 schedule(Scheduler::Add,incidence); 3182 schedule(Scheduler::Add,incidence);
3176} 3183}
3177 3184
3178void CalendarView::schedule_reply(Incidence *incidence) 3185void CalendarView::schedule_reply(Incidence *incidence)
3179{ 3186{
3180 schedule(Scheduler::Reply,incidence); 3187 schedule(Scheduler::Reply,incidence);
3181} 3188}
3182 3189
3183void CalendarView::schedule_counter(Incidence *incidence) 3190void CalendarView::schedule_counter(Incidence *incidence)
3184{ 3191{
3185 schedule(Scheduler::Counter,incidence); 3192 schedule(Scheduler::Counter,incidence);
3186} 3193}
3187 3194
3188void CalendarView::schedule_declinecounter(Incidence *incidence) 3195void CalendarView::schedule_declinecounter(Incidence *incidence)
3189{ 3196{
3190 schedule(Scheduler::Declinecounter,incidence); 3197 schedule(Scheduler::Declinecounter,incidence);
3191} 3198}
3192 3199
3193void CalendarView::schedule_publish_freebusy(int daysToPublish) 3200void CalendarView::schedule_publish_freebusy(int daysToPublish)
3194{ 3201{
3195 QDateTime start = QDateTime::currentDateTime(); 3202 QDateTime start = QDateTime::currentDateTime();
3196 QDateTime end = start.addDays(daysToPublish); 3203 QDateTime end = start.addDays(daysToPublish);
3197 3204
3198 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3205 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3199 freebusy->setOrganizer(KOPrefs::instance()->email()); 3206 freebusy->setOrganizer(KOPrefs::instance()->email());
3200 3207
3201 3208
3202 PublishDialog *publishdlg = new PublishDialog(); 3209 PublishDialog *publishdlg = new PublishDialog();
3203 if ( publishdlg->exec() == QDialog::Accepted ) { 3210 if ( publishdlg->exec() == QDialog::Accepted ) {
3204 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3211 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3205 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3212 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3206 delete(freebusy); 3213 delete(freebusy);
3207 } 3214 }
3208 } 3215 }
3209 delete publishdlg; 3216 delete publishdlg;
3210} 3217}
3211 3218
3212void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3219void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3213{ 3220{
3214 Event *event = 0; 3221 Event *event = 0;
3215 Todo *todo = 0; 3222 Todo *todo = 0;
3216 3223
3217 if (incidence == 0) { 3224 if (incidence == 0) {
3218 incidence = mViewManager->currentView()->selectedIncidences().first(); 3225 incidence = mViewManager->currentView()->selectedIncidences().first();
3219 if (incidence == 0) { 3226 if (incidence == 0) {
3220 incidence = mTodoList->selectedIncidences().first(); 3227 incidence = mTodoList->selectedIncidences().first();
3221 } 3228 }
3222 } 3229 }
3223 if ( incidence && incidence->type() == "Event" ) { 3230 if ( incidence && incidence->type() == "Event" ) {
3224 event = static_cast<Event *>(incidence); 3231 event = static_cast<Event *>(incidence);
3225 } 3232 }
3226 if ( incidence && incidence->type() == "Todo" ) { 3233 if ( incidence && incidence->type() == "Todo" ) {
3227 todo = static_cast<Todo *>(incidence); 3234 todo = static_cast<Todo *>(incidence);
3228 } 3235 }
3229 3236
3230 if (!event && !todo) { 3237 if (!event && !todo) {
3231 KMessageBox::sorry(this,i18n("No event selected.")); 3238 KMessageBox::sorry(this,i18n("No event selected."));
3232 return; 3239 return;
3233 } 3240 }
3234 3241
3235 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3242 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3236 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3243 KMessageBox::sorry(this,i18n("The event has no attendees."));
3237 return; 3244 return;
3238 } 3245 }
3239 3246
3240 Event *ev = 0; 3247 Event *ev = 0;
3241 if (event) ev = new Event(*event); 3248 if (event) ev = new Event(*event);
3242 Todo *to = 0; 3249 Todo *to = 0;
3243 if (todo) to = new Todo(*todo); 3250 if (todo) to = new Todo(*todo);
3244 3251
3245 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3252 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3246 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3253 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3247 if (!me) { 3254 if (!me) {
3248 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3255 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3249 return; 3256 return;
3250 } 3257 }
3251 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3258 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3252 StatusDialog *statdlg = new StatusDialog(this); 3259 StatusDialog *statdlg = new StatusDialog(this);
3253 if (!statdlg->exec()==QDialog::Accepted) return; 3260 if (!statdlg->exec()==QDialog::Accepted) return;
3254 me->setStatus( statdlg->status() ); 3261 me->setStatus( statdlg->status() );
3255 delete(statdlg); 3262 delete(statdlg);
3256 } 3263 }
3257 Attendee *menew = new Attendee(*me); 3264 Attendee *menew = new Attendee(*me);
3258 if (ev) { 3265 if (ev) {
3259 ev->clearAttendees(); 3266 ev->clearAttendees();
3260 ev->addAttendee(menew,false); 3267 ev->addAttendee(menew,false);
3261 } else { 3268 } else {
3262 if (to) { 3269 if (to) {
3263 todo->clearAttendees(); 3270 todo->clearAttendees();
3264 todo->addAttendee(menew,false); 3271 todo->addAttendee(menew,false);
3265 } 3272 }
3266 } 3273 }
3267 } 3274 }
3268 3275
3269 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3276 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3270 if (ev) { 3277 if (ev) {
3271 if ( !dlg->addMessage(ev,method) ) delete(ev); 3278 if ( !dlg->addMessage(ev,method) ) delete(ev);
3272 } else { 3279 } else {
3273 if (to) { 3280 if (to) {
3274 if ( !dlg->addMessage(to,method) ) delete(to); 3281 if ( !dlg->addMessage(to,method) ) delete(to);
3275 } 3282 }
3276 } 3283 }
3277} 3284}
3278 3285
3279void CalendarView::openAddressbook() 3286void CalendarView::openAddressbook()
3280{ 3287{
3281 KRun::runCommand("kaddressbook"); 3288 KRun::runCommand("kaddressbook");
3282} 3289}
3283 3290
3284void CalendarView::setModified(bool modified) 3291void CalendarView::setModified(bool modified)
3285{ 3292{
3286 if ( modified ) 3293 if ( modified )
3287 emit signalmodified(); 3294 emit signalmodified();
3288 if (mModified != modified) { 3295 if (mModified != modified) {
3289 mModified = modified; 3296 mModified = modified;
3290 emit modifiedChanged(mModified); 3297 emit modifiedChanged(mModified);
3291 } 3298 }
3292} 3299}
3293 3300
3294bool CalendarView::isReadOnly() 3301bool CalendarView::isReadOnly()
3295{ 3302{
3296 return mReadOnly; 3303 return mReadOnly;
3297} 3304}
3298 3305
3299void CalendarView::setReadOnly(bool readOnly) 3306void CalendarView::setReadOnly(bool readOnly)
3300{ 3307{
3301 if (mReadOnly != readOnly) { 3308 if (mReadOnly != readOnly) {
3302 mReadOnly = readOnly; 3309 mReadOnly = readOnly;
3303 emit readOnlyChanged(mReadOnly); 3310 emit readOnlyChanged(mReadOnly);
3304 } 3311 }
3305} 3312}
3306 3313
3307bool CalendarView::isModified() 3314bool CalendarView::isModified()
3308{ 3315{
3309 return mModified; 3316 return mModified;
3310} 3317}
3311 3318
3312void CalendarView::printSetup() 3319void CalendarView::printSetup()
3313{ 3320{
3314#ifndef KORG_NOPRINTER 3321#ifndef KORG_NOPRINTER
3315 createPrinter(); 3322 createPrinter();
3316 3323
3317 mCalPrinter->setupPrinter(); 3324 mCalPrinter->setupPrinter();
3318#endif 3325#endif
3319} 3326}
3320 3327
3321void CalendarView::print() 3328void CalendarView::print()
3322{ 3329{
3323#ifndef KORG_NOPRINTER 3330#ifndef KORG_NOPRINTER
3324 createPrinter(); 3331 createPrinter();
3325 3332
3326 DateList tmpDateList = mNavigator->selectedDates(); 3333 DateList tmpDateList = mNavigator->selectedDates();
3327 mCalPrinter->print(CalPrinter::Month, 3334 mCalPrinter->print(CalPrinter::Month,
3328 tmpDateList.first(), tmpDateList.last()); 3335 tmpDateList.first(), tmpDateList.last());
3329#endif 3336#endif
3330} 3337}
3331 3338
3332void CalendarView::printPreview() 3339void CalendarView::printPreview()
3333{ 3340{
3334#ifndef KORG_NOPRINTER 3341#ifndef KORG_NOPRINTER
3335 kdDebug() << "CalendarView::printPreview()" << endl; 3342 kdDebug() << "CalendarView::printPreview()" << endl;
3336 3343
3337 createPrinter(); 3344 createPrinter();
3338 3345
3339 DateList tmpDateList = mNavigator->selectedDates(); 3346 DateList tmpDateList = mNavigator->selectedDates();
3340 3347
3341 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3348 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3342 tmpDateList.last()); 3349 tmpDateList.last());
3343#endif 3350#endif
3344} 3351}
3345 3352
3346void CalendarView::exportICalendar() 3353void CalendarView::exportICalendar()
3347{ 3354{
3348 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3355 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3349 3356
3350 // Force correct extension 3357 // Force correct extension
3351 if (filename.right(4) != ".ics") filename += ".ics"; 3358 if (filename.right(4) != ".ics") filename += ".ics";
3352 3359
3353 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3360 FileStorage storage( mCalendar, filename, new ICalFormat() );
3354 storage.save(); 3361 storage.save();
3355} 3362}
3356 3363
3357bool CalendarView::exportVCalendar( QString filename ) 3364bool CalendarView::exportVCalendar( QString filename )
3358{ 3365{
3359 if (mCalendar->journals().count() > 0) { 3366 if (mCalendar->journals().count() > 0) {
3360 int result = KMessageBox::warningContinueCancel(this, 3367 int result = KMessageBox::warningContinueCancel(this,
3361 i18n("The journal entries can not be\nexported to a vCalendar file."), 3368 i18n("The journal entries can not be\nexported to a vCalendar file."),
3362 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3369 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3363 true); 3370 true);
3364 if (result != KMessageBox::Continue) return false; 3371 if (result != KMessageBox::Continue) return false;
3365 } 3372 }
3366 3373
3367 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3374 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3368 3375
3369 // Force correct extension 3376 // Force correct extension
3370 if (filename.right(4) != ".vcs") filename += ".vcs"; 3377 if (filename.right(4) != ".vcs") filename += ".vcs";
3371 3378
3372 FileStorage storage( mCalendar, filename, new VCalFormat ); 3379 FileStorage storage( mCalendar, filename, new VCalFormat );
3373 return storage.save(); 3380 return storage.save();
3374 3381
3375} 3382}
3376 3383
3377void CalendarView::eventUpdated(Incidence *) 3384void CalendarView::eventUpdated(Incidence *)
3378{ 3385{
3379 setModified(); 3386 setModified();
3380 // Don't call updateView here. The code, which has caused the update of the 3387 // Don't call updateView here. The code, which has caused the update of the
3381 // event is responsible for updating the view. 3388 // event is responsible for updating the view.
3382 // updateView(); 3389 // updateView();
3383} 3390}
3384 3391
3385void CalendarView::adaptNavigationUnits() 3392void CalendarView::adaptNavigationUnits()
3386{ 3393{
3387 if (mViewManager->currentView()->isEventView()) { 3394 if (mViewManager->currentView()->isEventView()) {
3388 int days = mViewManager->currentView()->currentDateCount(); 3395 int days = mViewManager->currentView()->currentDateCount();
3389 if (days == 1) { 3396 if (days == 1) {
3390 emit changeNavStringPrev(i18n("&Previous Day")); 3397 emit changeNavStringPrev(i18n("&Previous Day"));
3391 emit changeNavStringNext(i18n("&Next Day")); 3398 emit changeNavStringNext(i18n("&Next Day"));
3392 } else { 3399 } else {
3393 emit changeNavStringPrev(i18n("&Previous Week")); 3400 emit changeNavStringPrev(i18n("&Previous Week"));
3394 emit changeNavStringNext(i18n("&Next Week")); 3401 emit changeNavStringNext(i18n("&Next Week"));
3395 } 3402 }
3396 } 3403 }
3397} 3404}
3398 3405
3399void CalendarView::processMainViewSelection( Incidence *incidence ) 3406void CalendarView::processMainViewSelection( Incidence *incidence )
3400{ 3407{
3401 if ( incidence ) mTodoList->clearSelection(); 3408 if ( incidence ) mTodoList->clearSelection();
3402 processIncidenceSelection( incidence ); 3409 processIncidenceSelection( incidence );
3403} 3410}
3404 3411
3405void CalendarView::processTodoListSelection( Incidence *incidence ) 3412void CalendarView::processTodoListSelection( Incidence *incidence )
3406{ 3413{
3407 if ( incidence && mViewManager->currentView() ) { 3414 if ( incidence && mViewManager->currentView() ) {
3408 mViewManager->currentView()->clearSelection(); 3415 mViewManager->currentView()->clearSelection();
3409 } 3416 }
3410 processIncidenceSelection( incidence ); 3417 processIncidenceSelection( incidence );
3411} 3418}
3412 3419
3413void CalendarView::processIncidenceSelection( Incidence *incidence ) 3420void CalendarView::processIncidenceSelection( Incidence *incidence )
3414{ 3421{
3415 if ( incidence == mSelectedIncidence ) return; 3422 if ( incidence == mSelectedIncidence ) return;
3416 3423
3417 mSelectedIncidence = incidence; 3424 mSelectedIncidence = incidence;
3418 3425
3419 emit incidenceSelected( mSelectedIncidence ); 3426 emit incidenceSelected( mSelectedIncidence );
3420 3427
3421 if ( incidence && incidence->type() == "Event" ) { 3428 if ( incidence && incidence->type() == "Event" ) {
3422 Event *event = static_cast<Event *>( incidence ); 3429 Event *event = static_cast<Event *>( incidence );
3423 if ( event->organizer() == KOPrefs::instance()->email() ) { 3430 if ( event->organizer() == KOPrefs::instance()->email() ) {
3424 emit organizerEventsSelected( true ); 3431 emit organizerEventsSelected( true );
3425 } else { 3432 } else {
3426 emit organizerEventsSelected(false); 3433 emit organizerEventsSelected(false);
3427 } 3434 }
3428 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3435 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3429 KOPrefs::instance()->email() ) ) { 3436 KOPrefs::instance()->email() ) ) {
3430 emit groupEventsSelected( true ); 3437 emit groupEventsSelected( true );
3431 } else { 3438 } else {
3432 emit groupEventsSelected(false); 3439 emit groupEventsSelected(false);
3433 } 3440 }
3434 return; 3441 return;
3435 } else { 3442 } else {
3436 if ( incidence && incidence->type() == "Todo" ) { 3443 if ( incidence && incidence->type() == "Todo" ) {
3437 emit todoSelected( true ); 3444 emit todoSelected( true );
3438 Todo *event = static_cast<Todo *>( incidence ); 3445 Todo *event = static_cast<Todo *>( incidence );
3439 if ( event->organizer() == KOPrefs::instance()->email() ) { 3446 if ( event->organizer() == KOPrefs::instance()->email() ) {
3440 emit organizerEventsSelected( true ); 3447 emit organizerEventsSelected( true );
3441 } else { 3448 } else {
3442 emit organizerEventsSelected(false); 3449 emit organizerEventsSelected(false);
3443 } 3450 }
3444 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3451 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3445 KOPrefs::instance()->email() ) ) { 3452 KOPrefs::instance()->email() ) ) {
3446 emit groupEventsSelected( true ); 3453 emit groupEventsSelected( true );
3447 } else { 3454 } else {
3448 emit groupEventsSelected(false); 3455 emit groupEventsSelected(false);
3449 } 3456 }
3450 return; 3457 return;
3451 } else { 3458 } else {
3452 emit todoSelected( false ); 3459 emit todoSelected( false );
3453 emit organizerEventsSelected(false); 3460 emit organizerEventsSelected(false);
3454 emit groupEventsSelected(false); 3461 emit groupEventsSelected(false);
3455 } 3462 }
3456 return; 3463 return;
3457 } 3464 }
3458 3465
3459 /* if ( incidence && incidence->type() == "Todo" ) { 3466 /* if ( incidence && incidence->type() == "Todo" ) {
3460 emit todoSelected( true ); 3467 emit todoSelected( true );
3461 } else { 3468 } else {
3462 emit todoSelected( false ); 3469 emit todoSelected( false );
3463 }*/ 3470 }*/
3464} 3471}
3465 3472
3466 3473
3467void CalendarView::checkClipboard() 3474void CalendarView::checkClipboard()
3468{ 3475{
3469#ifndef KORG_NODND 3476#ifndef KORG_NODND
3470 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3477 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3471 emit pasteEnabled(true); 3478 emit pasteEnabled(true);
3472 } else { 3479 } else {
3473 emit pasteEnabled(false); 3480 emit pasteEnabled(false);
3474 } 3481 }
3475#endif 3482#endif
3476} 3483}
3477 3484
3478void CalendarView::showDates(const DateList &selectedDates) 3485void CalendarView::showDates(const DateList &selectedDates)
3479{ 3486{
3480 // kdDebug() << "CalendarView::selectDates()" << endl; 3487 // kdDebug() << "CalendarView::selectDates()" << endl;
3481 3488
3482 3489
3483 if ( !mBlockShowDates ) { 3490 if ( !mBlockShowDates ) {
3484 if ( mViewManager->currentView() ) { 3491 if ( mViewManager->currentView() ) {
3485 updateView( selectedDates.first(), selectedDates.last() ); 3492 updateView( selectedDates.first(), selectedDates.last() );
3486 } else { 3493 } else {
3487 mViewManager->showAgendaView(); 3494 mViewManager->showAgendaView();
3488 } 3495 }
3489 } 3496 }
3490 3497
3491 QString selDates; 3498 QString selDates;
3492 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3499 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3493 if (selectedDates.first() < selectedDates.last() ) 3500 if (selectedDates.first() < selectedDates.last() )
3494 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3501 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3495 else { 3502 else {
3496 QString addString; 3503 QString addString;
3497 if ( selectedDates.first() == QDateTime::currentDateTime().date() ) 3504 if ( selectedDates.first() == QDateTime::currentDateTime().date() )
3498 addString = i18n("Today"); 3505 addString = i18n("Today");
3499 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 3506 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
3500 addString = i18n("Tomorrow"); 3507 addString = i18n("Tomorrow");
3501 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 3508 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
3502 addString = i18n("Yesterday"); 3509 addString = i18n("Yesterday");
3503 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 3510 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
3504 addString = i18n("Day before yesterday"); 3511 addString = i18n("Day before yesterday");
3505 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 3512 else if ( selectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
3506 addString = i18n("Day after tomorrow"); 3513 addString = i18n("Day after tomorrow");
3507 if ( !addString.isEmpty() ) { 3514 if ( !addString.isEmpty() ) {
3508 topLevelWidget()->setCaption( addString+", " + selDates ); 3515 topLevelWidget()->setCaption( addString+", " + selDates );
3509 return; 3516 return;
3510 } 3517 }
3511 } 3518 }
3512 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3519 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3513 3520
3514} 3521}
3515 3522
3516QPtrList<CalFilter> CalendarView::filters() 3523QPtrList<CalFilter> CalendarView::filters()
3517{ 3524{
3518 return mFilters; 3525 return mFilters;
3519 3526
3520} 3527}
3521void CalendarView::editFilters() 3528void CalendarView::editFilters()
3522{ 3529{
3523 // kdDebug() << "CalendarView::editFilters()" << endl; 3530 // kdDebug() << "CalendarView::editFilters()" << endl;
3524 3531
3525 CalFilter *filter = mFilters.first(); 3532 CalFilter *filter = mFilters.first();
3526 while(filter) { 3533 while(filter) {
3527 kdDebug() << " Filter: " << filter->name() << endl; 3534 kdDebug() << " Filter: " << filter->name() << endl;
3528 filter = mFilters.next(); 3535 filter = mFilters.next();
3529 } 3536 }
3530 3537
3531 mDialogManager->showFilterEditDialog(&mFilters); 3538 mDialogManager->showFilterEditDialog(&mFilters);
3532} 3539}
3533void CalendarView::toggleFilter() 3540void CalendarView::toggleFilter()
3534{ 3541{
3535 showFilter(! mFilterView->isVisible()); 3542 showFilter(! mFilterView->isVisible());
3536} 3543}
3537 3544
3538KOFilterView *CalendarView::filterView() 3545KOFilterView *CalendarView::filterView()
3539{ 3546{
3540 return mFilterView; 3547 return mFilterView;
3541} 3548}
3542void CalendarView::selectFilter( int fil ) 3549void CalendarView::selectFilter( int fil )
3543{ 3550{
3544 mFilterView->setSelectedFilter( fil ); 3551 mFilterView->setSelectedFilter( fil );
3545} 3552}
3546void CalendarView::showFilter(bool visible) 3553void CalendarView::showFilter(bool visible)
3547{ 3554{
3548 if (visible) mFilterView->show(); 3555 if (visible) mFilterView->show();
3549 else mFilterView->hide(); 3556 else mFilterView->hide();
3550} 3557}
3551void CalendarView::toggleFilerEnabled( ) 3558void CalendarView::toggleFilerEnabled( )
3552{ 3559{
3553 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3560 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3554 if ( !mFilterView->filtersEnabled() ) 3561 if ( !mFilterView->filtersEnabled() )
3555 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3562 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3556 3563
3557} 3564}
3558void CalendarView::updateFilter() 3565void CalendarView::updateFilter()
3559{ 3566{
3560 CalFilter *filter = mFilterView->selectedFilter(); 3567 CalFilter *filter = mFilterView->selectedFilter();
3561 if (filter) { 3568 if (filter) {
3562 if (mFilterView->filtersEnabled()) { 3569 if (mFilterView->filtersEnabled()) {
3563 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3570 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3564 filter->setEnabled(true); 3571 filter->setEnabled(true);
3565 } 3572 }
3566 else filter->setEnabled(false); 3573 else filter->setEnabled(false);
3567 mCalendar->setFilter(filter); 3574 mCalendar->setFilter(filter);
3568 updateView(); 3575 updateView();
3569 } 3576 }
3570} 3577}
3571 3578
3572void CalendarView::filterEdited() 3579void CalendarView::filterEdited()
3573{ 3580{
3574 mFilterView->updateFilters(); 3581 mFilterView->updateFilters();
3575 updateFilter(); 3582 updateFilter();
3576 writeSettings(); 3583 writeSettings();
3577} 3584}
3578 3585
3579 3586
3580void CalendarView::takeOverEvent() 3587void CalendarView::takeOverEvent()
3581{ 3588{
3582 Incidence *incidence = currentSelection(); 3589 Incidence *incidence = currentSelection();
3583 3590
3584 if (!incidence) return; 3591 if (!incidence) return;
3585 3592
3586 incidence->setOrganizer(KOPrefs::instance()->email()); 3593 incidence->setOrganizer(KOPrefs::instance()->email());
3587 incidence->recreate(); 3594 incidence->recreate();
3588 incidence->setReadOnly(false); 3595 incidence->setReadOnly(false);
3589 3596
3590 updateView(); 3597 updateView();
3591} 3598}
3592 3599
3593void CalendarView::takeOverCalendar() 3600void CalendarView::takeOverCalendar()
3594{ 3601{
3595 // TODO: Create Calendar::allIncidences() function and use it here 3602 // TODO: Create Calendar::allIncidences() function and use it here
3596 3603
3597 QPtrList<Event> events = mCalendar->events(); 3604 QPtrList<Event> events = mCalendar->events();
3598 for(uint i=0; i<events.count(); ++i) { 3605 for(uint i=0; i<events.count(); ++i) {
3599 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3606 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3600 events.at(i)->recreate(); 3607 events.at(i)->recreate();
3601 events.at(i)->setReadOnly(false); 3608 events.at(i)->setReadOnly(false);
3602 } 3609 }
3603 3610
3604 QPtrList<Todo> todos = mCalendar->todos(); 3611 QPtrList<Todo> todos = mCalendar->todos();
3605 for(uint i=0; i<todos.count(); ++i) { 3612 for(uint i=0; i<todos.count(); ++i) {
3606 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3613 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3607 todos.at(i)->recreate(); 3614 todos.at(i)->recreate();
3608 todos.at(i)->setReadOnly(false); 3615 todos.at(i)->setReadOnly(false);
3609 } 3616 }
3610 3617
3611 QPtrList<Journal> journals = mCalendar->journals(); 3618 QPtrList<Journal> journals = mCalendar->journals();
3612 for(uint i=0; i<journals.count(); ++i) { 3619 for(uint i=0; i<journals.count(); ++i) {
3613 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3620 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3614 journals.at(i)->recreate(); 3621 journals.at(i)->recreate();
3615 journals.at(i)->setReadOnly(false); 3622 journals.at(i)->setReadOnly(false);
3616 } 3623 }
3617 3624
3618 updateView(); 3625 updateView();
3619} 3626}
3620 3627
3621void CalendarView::showIntro() 3628void CalendarView::showIntro()
3622{ 3629{
3623 kdDebug() << "To be implemented." << endl; 3630 kdDebug() << "To be implemented." << endl;
3624} 3631}
3625 3632
3626QWidgetStack *CalendarView::viewStack() 3633QWidgetStack *CalendarView::viewStack()
3627{ 3634{
3628 return mRightFrame; 3635 return mRightFrame;
3629} 3636}
3630 3637
3631QWidget *CalendarView::leftFrame() 3638QWidget *CalendarView::leftFrame()
3632{ 3639{
3633 return mLeftFrame; 3640 return mLeftFrame;
3634} 3641}
3635 3642
3636DateNavigator *CalendarView::dateNavigator() 3643DateNavigator *CalendarView::dateNavigator()
3637{ 3644{
3638 return mNavigator; 3645 return mNavigator;
3639} 3646}
3640 3647
3641KDateNavigator* CalendarView::dateNavigatorWidget() 3648KDateNavigator* CalendarView::dateNavigatorWidget()
3642{ 3649{
3643 return mDateNavigator; 3650 return mDateNavigator;
3644} 3651}
3645void CalendarView::toggleDateNavigatorWidget() 3652void CalendarView::toggleDateNavigatorWidget()
3646{ 3653{
3647 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 3654 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
3648 if (!KOPrefs::instance()->mShowDateNavigator ) 3655 if (!KOPrefs::instance()->mShowDateNavigator )
3649 mDateNavigator->hide(); 3656 mDateNavigator->hide();
3650 else 3657 else
3651 mDateNavigator->show(); 3658 mDateNavigator->show();
3652} 3659}
3653void CalendarView::addView(KOrg::BaseView *view) 3660void CalendarView::addView(KOrg::BaseView *view)
3654{ 3661{
3655 mViewManager->addView(view); 3662 mViewManager->addView(view);
3656} 3663}
3657 3664
3658void CalendarView::showView(KOrg::BaseView *view) 3665void CalendarView::showView(KOrg::BaseView *view)
3659{ 3666{
3660 mViewManager->showView(view, mLeftFrame->isVisible()); 3667 mViewManager->showView(view, mLeftFrame->isVisible());
3661} 3668}
3662 3669
3663Incidence *CalendarView::currentSelection() 3670Incidence *CalendarView::currentSelection()
3664{ 3671{
3665 return mViewManager->currentSelection(); 3672 return mViewManager->currentSelection();
3666} 3673}
3667void CalendarView::toggleAllDaySize() 3674void CalendarView::toggleAllDaySize()
3668{ 3675{
3669 /* 3676 /*
3670 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3677 if ( KOPrefs::instance()->mAllDaySize > 47 )
3671 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3678 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3672 else 3679 else
3673 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3680 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3674 */ 3681 */
3675 viewManager()->agendaView()->toggleAllDay(); 3682 viewManager()->agendaView()->toggleAllDay();
3676} 3683}
3677void CalendarView::toggleExpand() 3684void CalendarView::toggleExpand()
3678{ 3685{
3679 // if ( mLeftFrame->isHidden() ) { 3686 // if ( mLeftFrame->isHidden() ) {
3680 // mLeftFrame->show(); 3687 // mLeftFrame->show();
3681 // emit calendarViewExpanded( false ); 3688 // emit calendarViewExpanded( false );
3682 // } else { 3689 // } else {
3683 // mLeftFrame->hide(); 3690 // mLeftFrame->hide();
3684 // emit calendarViewExpanded( true ); 3691 // emit calendarViewExpanded( true );
3685 // } 3692 // }
3686 3693
3687 globalFlagBlockAgenda = 1; 3694 globalFlagBlockAgenda = 1;
3688 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3695 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3689 globalFlagBlockAgenda = 5; 3696 globalFlagBlockAgenda = 5;
3690 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3697 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3691 //mViewManager->showView( 0, true ); 3698 //mViewManager->showView( 0, true );
3692} 3699}
3693 3700
3694void CalendarView::calendarModified( bool modified, Calendar * ) 3701void CalendarView::calendarModified( bool modified, Calendar * )
3695{ 3702{
3696 setModified( modified ); 3703 setModified( modified );
3697} 3704}
3698 3705
3699Todo *CalendarView::selectedTodo() 3706Todo *CalendarView::selectedTodo()
3700{ 3707{
3701 Incidence *incidence = currentSelection(); 3708 Incidence *incidence = currentSelection();
3702 if ( incidence && incidence->type() == "Todo" ) { 3709 if ( incidence && incidence->type() == "Todo" ) {
3703 return static_cast<Todo *>( incidence ); 3710 return static_cast<Todo *>( incidence );
3704 } 3711 }
3705 3712
3706 incidence = mTodoList->selectedIncidences().first(); 3713 incidence = mTodoList->selectedIncidences().first();
3707 if ( incidence && incidence->type() == "Todo" ) { 3714 if ( incidence && incidence->type() == "Todo" ) {
3708 return static_cast<Todo *>( incidence ); 3715 return static_cast<Todo *>( incidence );
3709 } 3716 }
3710 3717
3711 return 0; 3718 return 0;
3712} 3719}
3713 3720
3714void CalendarView::dialogClosing(Incidence *in) 3721void CalendarView::dialogClosing(Incidence *in)
3715{ 3722{
3716 // mDialogList.remove(in); 3723 // mDialogList.remove(in);
3717} 3724}
3718 3725
3719void CalendarView::showIncidence() 3726void CalendarView::showIncidence()
3720{ 3727{
3721 Incidence *incidence = currentSelection(); 3728 Incidence *incidence = currentSelection();
3722 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3729 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3723 if ( incidence ) { 3730 if ( incidence ) {
3724 ShowIncidenceVisitor v; 3731 ShowIncidenceVisitor v;
3725 v.act( incidence, this ); 3732 v.act( incidence, this );
3726 } 3733 }
3727} 3734}
3728void CalendarView::editIncidenceDescription() 3735void CalendarView::editIncidenceDescription()
3729{ 3736{
3730 mFlagEditDescription = true; 3737 mFlagEditDescription = true;
3731 editIncidence(); 3738 editIncidence();
3732 mFlagEditDescription = false; 3739 mFlagEditDescription = false;
3733} 3740}
3734void CalendarView::editIncidence() 3741void CalendarView::editIncidence()
3735{ 3742{
3736 // qDebug("editIncidence() "); 3743 // qDebug("editIncidence() ");
3737 Incidence *incidence = currentSelection(); 3744 Incidence *incidence = currentSelection();
3738 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3745 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3739 if ( incidence ) { 3746 if ( incidence ) {
3740 EditIncidenceVisitor v; 3747 EditIncidenceVisitor v;
3741 v.act( incidence, this ); 3748 v.act( incidence, this );
3742 } 3749 }
3743} 3750}
3744 3751
3745void CalendarView::deleteIncidence() 3752void CalendarView::deleteIncidence()
3746{ 3753{
3747 Incidence *incidence = currentSelection(); 3754 Incidence *incidence = currentSelection();
3748 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3755 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3749 if ( incidence ) { 3756 if ( incidence ) {
3750 deleteIncidence(incidence); 3757 deleteIncidence(incidence);
3751 } 3758 }
3752} 3759}
3753 3760
3754void CalendarView::showIncidence(Incidence *incidence) 3761void CalendarView::showIncidence(Incidence *incidence)
3755{ 3762{
3756 if ( incidence ) { 3763 if ( incidence ) {
3757 ShowIncidenceVisitor v; 3764 ShowIncidenceVisitor v;
3758 v.act( incidence, this ); 3765 v.act( incidence, this );
3759 } 3766 }
3760} 3767}
3761 3768
3762void CalendarView::editIncidence(Incidence *incidence) 3769void CalendarView::editIncidence(Incidence *incidence)
3763{ 3770{
3764 if ( incidence ) { 3771 if ( incidence ) {
3765 3772
3766 EditIncidenceVisitor v; 3773 EditIncidenceVisitor v;
3767 v.act( incidence, this ); 3774 v.act( incidence, this );
3768 3775
3769 } 3776 }
3770} 3777}
3771 3778
3772void CalendarView::deleteIncidence(Incidence *incidence) 3779void CalendarView::deleteIncidence(Incidence *incidence)
3773{ 3780{
3774 //qDebug(" CalendarView::deleteIncidence "); 3781 //qDebug(" CalendarView::deleteIncidence ");
3775 if ( incidence ) { 3782 if ( incidence ) {
3776 DeleteIncidenceVisitor v; 3783 DeleteIncidenceVisitor v;
3777 v.act( incidence, this ); 3784 v.act( incidence, this );
3778 } 3785 }
3779} 3786}
3780 3787
3781 3788
3782void CalendarView::lookForOutgoingMessages() 3789void CalendarView::lookForOutgoingMessages()
3783{ 3790{
3784 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3791 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3785 ogd->loadMessages(); 3792 ogd->loadMessages();
3786} 3793}
3787 3794
3788void CalendarView::lookForIncomingMessages() 3795void CalendarView::lookForIncomingMessages()
3789{ 3796{
3790 IncomingDialog *icd = mDialogManager->incomingDialog(); 3797 IncomingDialog *icd = mDialogManager->incomingDialog();
3791 icd->retrieve(); 3798 icd->retrieve();
3792} 3799}
3793 3800
3794bool CalendarView::removeCompletedSubTodos( Todo* t ) 3801bool CalendarView::removeCompletedSubTodos( Todo* t )
3795{ 3802{
3796 bool deleteTodo = true; 3803 bool deleteTodo = true;
3797 QPtrList<Incidence> subTodos; 3804 QPtrList<Incidence> subTodos;
3798 Incidence *aTodo; 3805 Incidence *aTodo;
3799 subTodos = t->relations(); 3806 subTodos = t->relations();
3800 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3807 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3801 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3808 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3802 deleteTodo = false; 3809 deleteTodo = false;
3803 } 3810 }
3804 if ( deleteTodo ) { 3811 if ( deleteTodo ) {
3805 if ( t->isCompleted() ) { 3812 if ( t->isCompleted() ) {
3806 checkExternalId( t ); 3813 checkExternalId( t );
3807 mCalendar->deleteTodo( t ); 3814 mCalendar->deleteTodo( t );
3808 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3815 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3809 } 3816 }
3810 else 3817 else
3811 deleteTodo = false; 3818 deleteTodo = false;
3812 } 3819 }
3813 return deleteTodo; 3820 return deleteTodo;
3814 3821
3815} 3822}
3816void CalendarView::purgeCompleted() 3823void CalendarView::purgeCompleted()
3817{ 3824{
3818 int result = KMessageBox::warningContinueCancel(this, 3825 int result = KMessageBox::warningContinueCancel(this,
3819 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3826 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3820 3827
3821 if (result == KMessageBox::Continue) { 3828 if (result == KMessageBox::Continue) {
3822 3829
3823 QPtrList<Todo> todoCal; 3830 QPtrList<Todo> todoCal;
3824 QPtrList<Todo> rootTodos; 3831 QPtrList<Todo> rootTodos;
3825 //QPtrList<Incidence> rel; 3832 //QPtrList<Incidence> rel;
3826 Todo *aTodo;//, *rTodo; 3833 Todo *aTodo;//, *rTodo;
3827 Incidence *rIncidence; 3834 Incidence *rIncidence;
3828 bool childDelete = false; 3835 bool childDelete = false;
3829 bool deletedOne = true; 3836 bool deletedOne = true;
3830 todoCal = calendar()->todos(); 3837 todoCal = calendar()->todos();
3831 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3838 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3832 if ( !aTodo->relatedTo() ) 3839 if ( !aTodo->relatedTo() )
3833 rootTodos.append( aTodo ); 3840 rootTodos.append( aTodo );
3834 } 3841 }
3835 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3842 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3836 removeCompletedSubTodos( aTodo ); 3843 removeCompletedSubTodos( aTodo );
3837 } 3844 }
3838 3845
3839 updateView(); 3846 updateView();
3840 } 3847 }
3841} 3848}
3842 3849
3843void CalendarView::slotCalendarChanged() 3850void CalendarView::slotCalendarChanged()
3844{ 3851{
3845 ; 3852 ;
3846} 3853}
3847 3854
3848NavigatorBar *CalendarView::navigatorBar() 3855NavigatorBar *CalendarView::navigatorBar()
3849{ 3856{
3850 return mNavigatorBar; 3857 return mNavigatorBar;
3851} 3858}
3852 3859
3853 3860
3854 3861
3855void CalendarView::keyPressEvent ( QKeyEvent *e) 3862void CalendarView::keyPressEvent ( QKeyEvent *e)
3856{ 3863{
3857 //qDebug(" alendarView::keyPressEvent "); 3864 //qDebug(" alendarView::keyPressEvent ");
3858 e->ignore(); 3865 e->ignore();
3859} 3866}
3860 3867
3861 3868
3862bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3869bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3863{ 3870{
3864 // mSyncManager = manager; 3871 // mSyncManager = manager;
3865 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3872 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3866 qDebug("KO: SyncKDE request detected!"); 3873 qDebug("KO: SyncKDE request detected!");
3867 } 3874 }
3868 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3875 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3869 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3876 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3870 return syncCalendar( filename, mode ); 3877 return syncCalendar( filename, mode );
3871} 3878}
3872bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3879bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3873{ 3880{
3874 //mSyncManager = manager; 3881 //mSyncManager = manager;
3875 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3882 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3876 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3883 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3877 if ( resource == "sharp" ) 3884 if ( resource == "sharp" )
3878 syncExternal( 0 ); 3885 syncExternal( 0 );
3879 if ( resource == "phone" ) 3886 if ( resource == "phone" )
3880 syncExternal( 1 ); 3887 syncExternal( 1 );
3881 // pending setmodified 3888 // pending setmodified
3882 return true; 3889 return true;
3883} 3890}
3884void CalendarView::setSyncManager(KSyncManager* manager) 3891void CalendarView::setSyncManager(KSyncManager* manager)
3885{ 3892{
3886 mSyncManager = manager; 3893 mSyncManager = manager;
3887} 3894}
3888 3895
3889void CalendarView::removeSyncInfo( QString syncProfile) 3896void CalendarView::removeSyncInfo( QString syncProfile)
3890{ 3897{
3891 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 3898 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
3892 mCalendar->removeSyncInfo( syncProfile ); 3899 mCalendar->removeSyncInfo( syncProfile );
3893 3900
3894} 3901}
3895 3902
3896void CalendarView::undo_delete() 3903void CalendarView::undo_delete()
3897{ 3904{
3898 //qDebug("undo_delete() "); 3905 //qDebug("undo_delete() ");
3899 Incidence* undo = mCalendar->undoIncidence(); 3906 Incidence* undo = mCalendar->undoIncidence();
3900 if ( !undo ) { 3907 if ( !undo ) {
3901 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 3908 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
3902 i18n("KO/Pi")); 3909 i18n("KO/Pi"));
3903 return; 3910 return;
3904 } 3911 }
3905 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) + 3912 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) +
3906 i18n("\nAre you sure you want\nto restore this?"), 3913 i18n("\nAre you sure you want\nto restore this?"),
3907 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 3914 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
3908 mCalendar->undoDeleteIncidence(); 3915 mCalendar->undoDeleteIncidence();
3909 updateView(); 3916 updateView();
3910 } 3917 }
3911} 3918}
diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h
index c8d6bdd..7c59a8d 100644
--- a/korganizer/calendarview.h
+++ b/korganizer/calendarview.h
@@ -1,610 +1,612 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 3 Copyright (c) 2000, 2001
4 Cornelius Schumacher <schumacher@kde.org> 4 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24#ifndef CALENDARVIEW_H 24#ifndef CALENDARVIEW_H
25#define CALENDARVIEW_H 25#define CALENDARVIEW_H
26 26
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qptrlist.h> 30#include <qptrlist.h>
31#include <qvbox.h> 31#include <qvbox.h>
32#include <qmap.h> 32#include <qmap.h>
33#ifndef DESKTOP_VERSION 33#ifndef DESKTOP_VERSION
34#include <qtopia/ir.h> 34#include <qtopia/ir.h>
35#else 35#else
36#define Ir char 36#define Ir char
37#endif 37#endif
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/scheduler.h> 39#include <libkcal/scheduler.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42 42
43#include <korganizer/calendarviewbase.h> 43#include <korganizer/calendarviewbase.h>
44 44
45#include <ksyncmanager.h> 45#include <ksyncmanager.h>
46 46
47class QWidgetStack; 47class QWidgetStack;
48class QSplitter; 48class QSplitter;
49 49
50class CalPrinter; 50class CalPrinter;
51class KOFilterView; 51class KOFilterView;
52class KOViewManager; 52class KOViewManager;
53class KODialogManager; 53class KODialogManager;
54class KOTodoView; 54class KOTodoView;
55class KDateNavigator; 55class KDateNavigator;
56class DateNavigator; 56class DateNavigator;
57class KOIncidenceEditor; 57class KOIncidenceEditor;
58class KDatePicker; 58class KDatePicker;
59class ResourceView; 59class ResourceView;
60class NavigatorBar; 60class NavigatorBar;
61class KOEventEditor; 61class KOEventEditor;
62class KOTodoEditor ; 62class KOTodoEditor ;
63class KOEventViewerDialog; 63class KOEventViewerDialog;
64class KOBeamPrefs; 64class KOBeamPrefs;
65class KSyncProfile; 65class KSyncProfile;
66class AlarmDialog; 66class AlarmDialog;
67class KCal::Attendee; 67class KCal::Attendee;
68 68
69namespace KCal { class FileStorage; } 69namespace KCal { class FileStorage; }
70 70
71using namespace KCal; 71using namespace KCal;
72 72
73/** 73/**
74 This is the main calendar widget. It provides the different vies on t he 74 This is the main calendar widget. It provides the different vies on t he
75 calendar data as well as the date navigator. It also handles synchronisation 75 calendar data as well as the date navigator. It also handles synchronisation
76 of the different views and controls the different dialogs like preferences, 76 of the different views and controls the different dialogs like preferences,
77 event editor, search dialog etc. 77 event editor, search dialog etc.
78 78
79 @short main calendar view widget 79 @short main calendar view widget
80 @author Cornelius Schumacher 80 @author Cornelius Schumacher
81*/ 81*/
82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface 82class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface
83{ 83{
84 Q_OBJECT 84 Q_OBJECT
85 public: 85 public:
86 /** 86 /**
87 Constructs a new calendar view widget. 87 Constructs a new calendar view widget.
88 88
89 @param calendar calendar document 89 @param calendar calendar document
90 @param parent parent window 90 @param parent parent window
91 @param name Qt internal widget object name 91 @param name Qt internal widget object name
92 */ 92 */
93 CalendarView( CalendarResources *calendar, QWidget *parent = 0, 93 CalendarView( CalendarResources *calendar, QWidget *parent = 0,
94 const char *name = 0 ); 94 const char *name = 0 );
95 CalendarView( Calendar *calendar, QWidget *parent = 0, 95 CalendarView( Calendar *calendar, QWidget *parent = 0,
96 const char *name = 0 ); 96 const char *name = 0 );
97 virtual ~CalendarView(); 97 virtual ~CalendarView();
98 98
99 Calendar *calendar() { return mCalendar; } 99 Calendar *calendar() { return mCalendar; }
100 100
101 KOViewManager *viewManager(); 101 KOViewManager *viewManager();
102 KODialogManager *dialogManager(); 102 KODialogManager *dialogManager();
103 103
104 QDate startDate(); 104 QDate startDate();
105 QDate endDate(); 105 QDate endDate();
106 106
107 QWidgetStack *viewStack(); 107 QWidgetStack *viewStack();
108 QWidget *leftFrame(); 108 QWidget *leftFrame();
109 NavigatorBar *navigatorBar(); 109 NavigatorBar *navigatorBar();
110 110
111 DateNavigator *dateNavigator(); 111 DateNavigator *dateNavigator();
112 KDateNavigator *dateNavigatorWidget(); 112 KDateNavigator *dateNavigatorWidget();
113 113
114 void addView(KOrg::BaseView *); 114 void addView(KOrg::BaseView *);
115 void showView(KOrg::BaseView *); 115 void showView(KOrg::BaseView *);
116 KOEventViewerDialog* getEventViewerDialog(); 116 KOEventViewerDialog* getEventViewerDialog();
117 Incidence *currentSelection(); 117 Incidence *currentSelection();
118 118
119 signals: 119 signals:
120 void tempDisableBR(bool); 120 void tempDisableBR(bool);
121 /** This todo has been modified */ 121 /** This todo has been modified */
122 void todoModified(Todo *, int); 122 void todoModified(Todo *, int);
123 123
124 /** when change is made to options dialog, the topwidget will catch this 124 /** when change is made to options dialog, the topwidget will catch this
125 * and emit this signal which notifies all widgets which have registered 125 * and emit this signal which notifies all widgets which have registered
126 * for notification to update their settings. */ 126 * for notification to update their settings. */
127 void configChanged(); 127 void configChanged();
128 /** emitted when the topwidget is closing down, so that any attached 128 /** emitted when the topwidget is closing down, so that any attached
129 child windows can also close. */ 129 child windows can also close. */
130 void closingDown(); 130 void closingDown();
131 /** emitted right before we die */ 131 /** emitted right before we die */
132 void closed(QWidget *); 132 void closed(QWidget *);
133 133
134 /** Emitted when state of modified flag changes */ 134 /** Emitted when state of modified flag changes */
135 void modifiedChanged(bool); 135 void modifiedChanged(bool);
136 void signalmodified(); 136 void signalmodified();
137 137
138 /** Emitted when state of read-only flag changes */ 138 /** Emitted when state of read-only flag changes */
139 void readOnlyChanged(bool); 139 void readOnlyChanged(bool);
140 140
141 /** Emitted when the unit of navigation changes */ 141 /** Emitted when the unit of navigation changes */
142 void changeNavStringPrev(const QString &); 142 void changeNavStringPrev(const QString &);
143 void changeNavStringNext(const QString &); 143 void changeNavStringNext(const QString &);
144 144
145 /** Emitted when state of events selection has changed and user is organizer*/ 145 /** Emitted when state of events selection has changed and user is organizer*/
146 void organizerEventsSelected(bool); 146 void organizerEventsSelected(bool);
147 /** Emitted when state of events selection has changed and user is attendee*/ 147 /** Emitted when state of events selection has changed and user is attendee*/
148 void groupEventsSelected(bool); 148 void groupEventsSelected(bool);
149 /** 149 /**
150 Emitted when an incidence gets selected. If the selection is cleared the 150 Emitted when an incidence gets selected. If the selection is cleared the
151 signal is emitted with 0 as argument. 151 signal is emitted with 0 as argument.
152 */ 152 */
153 void incidenceSelected( Incidence * ); 153 void incidenceSelected( Incidence * );
154 /** Emitted, when a todoitem is selected or deselected. */ 154 /** Emitted, when a todoitem is selected or deselected. */
155 void todoSelected( bool ); 155 void todoSelected( bool );
156 156
157 /** 157 /**
158 Emitted, when clipboard content changes. Parameter indicates if paste 158 Emitted, when clipboard content changes. Parameter indicates if paste
159 is possible or not. 159 is possible or not.
160 */ 160 */
161 void pasteEnabled(bool); 161 void pasteEnabled(bool);
162 162
163 /** Emitted, when the number of incoming messages has changed. */ 163 /** Emitted, when the number of incoming messages has changed. */
164 void numIncomingChanged(int); 164 void numIncomingChanged(int);
165 165
166 /** Emitted, when the number of outgoing messages has changed. */ 166 /** Emitted, when the number of outgoing messages has changed. */
167 void numOutgoingChanged(int); 167 void numOutgoingChanged(int);
168 168
169 /** Send status message, which can e.g. be displayed in the status bar. */ 169 /** Send status message, which can e.g. be displayed in the status bar. */
170 void statusMessage(const QString &); 170 void statusMessage(const QString &);
171 171
172 void calendarViewExpanded( bool ); 172 void calendarViewExpanded( bool );
173 void updateSearchDialog(); 173 void updateSearchDialog();
174 174
175 175
176 public slots: 176 public slots:
177 void showOpenError(); 177 void showOpenError();
178 void watchSavedFile(); 178 void watchSavedFile();
179 void recheckTimerAlarm(); 179 void recheckTimerAlarm();
180 void checkNextTimerAlarm(); 180 void checkNextTimerAlarm();
181 void addAlarm(const QDateTime &qdt, const QString &noti ); 181 void addAlarm(const QDateTime &qdt, const QString &noti );
182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti ); 182 void addSuspendAlarm(const QDateTime &qdt, const QString &noti );
183 void removeAlarm(const QDateTime &qdt, const QString &noti ); 183 void removeAlarm(const QDateTime &qdt, const QString &noti );
184 184
185 /** options dialog made a changed to the configuration. we catch this 185 /** options dialog made a changed to the configuration. we catch this
186 * and notify all widgets which need to update their configuration. */ 186 * and notify all widgets which need to update their configuration. */
187 void updateConfig(); 187 void updateConfig();
188 188
189 void insertBirthdays(const QString& uid, const QStringList& birthdayList, 189 void insertBirthdays(const QString& uid, const QStringList& birthdayList,
190 const QStringList& anniversaryList, const QStringList& realNameList, 190 const QStringList& anniversaryList, const QStringList& realNameList,
191 const QStringList& emailList, const QStringList& assembledNameList, 191 const QStringList& emailList, const QStringList& assembledNameList,
192 const QStringList& uidList); 192 const QStringList& uidList);
193 193
194 /** 194 /**
195 Load calendar from file \a filename. If \a merge is true, load 195 Load calendar from file \a filename. If \a merge is true, load
196 calendar into existing one, if it is false, clear calendar, before 196 calendar into existing one, if it is false, clear calendar, before
197 loading. Return true, if calendar could be successfully loaded. 197 loading. Return true, if calendar could be successfully loaded.
198 */ 198 */
199 bool openCalendar(QString filename, bool merge=false); 199 bool openCalendar(QString filename, bool merge=false);
200 bool syncCalendar(QString filename,int mode = 0 ); 200 bool syncCalendar(QString filename,int mode = 0 );
201 201
202 /** 202 /**
203 Save calendar data to file. Return true if calendar could be 203 Save calendar data to file. Return true if calendar could be
204 successfully saved. 204 successfully saved.
205 */ 205 */
206 bool saveCalendar(QString filename); 206 bool saveCalendar(QString filename);
207 207
208 /** 208 /**
209 Close calendar. Clear calendar data and reset views to display an empty 209 Close calendar. Clear calendar data and reset views to display an empty
210 calendar. 210 calendar.
211 */ 211 */
212 void closeCalendar(); 212 void closeCalendar();
213 213
214 /** Archive old events of calendar */ 214 /** Archive old events of calendar */
215 void archiveCalendar(); 215 void archiveCalendar();
216 216
217 void showIncidence(); 217 void showIncidence();
218 void editIncidence(); 218 void editIncidence();
219 void editIncidenceDescription(); 219 void editIncidenceDescription();
220 void deleteIncidence(); 220 void deleteIncidence();
221 void cloneIncidence(); 221 void cloneIncidence();
222 void moveIncidence(); 222 void moveIncidence();
223 void beamIncidence(); 223 void beamIncidence();
224 void toggleCancelIncidence(); 224 void toggleCancelIncidence();
225 225
226 /** create an editeventwin with supplied date/time, and if bool is true, 226 /** create an editeventwin with supplied date/time, and if bool is true,
227 * make the event take all day. */ 227 * make the event take all day. */
228 void newEvent(QDateTime, QDateTime, bool allDay = false); 228 void newEvent(QDateTime, QDateTime, bool allDay );
229 void newEvent(QDateTime, QDateTime);
229 void newEvent(QDateTime fh); 230 void newEvent(QDateTime fh);
230 void newEvent(QDate dt); 231 void newEvent(QDate dt);
231 /** create new event without having a date hint. Takes current date as 232 /** create new event without having a date hint. Takes current date as
232 default hint. */ 233 default hint. */
233 void newEvent(); 234 void newEvent();
234 void newFloatingEvent(); 235 void newFloatingEvent();
235 236
236 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/ 237 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
237 void showIncidence(Incidence *); 238 void showIncidence(Incidence *);
238 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/ 239 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
239 void editIncidence(Incidence *); 240 void editIncidence(Incidence *);
240 /** Delete the supplied incidence. It calls the correct deleteXXX method*/ 241 /** Delete the supplied incidence. It calls the correct deleteXXX method*/
241 void deleteIncidence(Incidence *); 242 void deleteIncidence(Incidence *);
242 void cloneIncidence(Incidence *); 243 void cloneIncidence(Incidence *);
243 void cancelIncidence(Incidence *); 244 void cancelIncidence(Incidence *);
244 /** Create an editor for the supplied event. */ 245 /** Create an editor for the supplied event. */
245 void editEvent(Event *); 246 void editEvent(Event *);
246 /** Delete the supplied event. */ 247 /** Delete the supplied event. */
247 void deleteEvent(Event *); 248 void deleteEvent(Event *);
248 /** Delete the event with the given unique ID. Returns false, if event wasn't 249 /** Delete the event with the given unique ID. Returns false, if event wasn't
249 found. */ 250 found. */
250 bool deleteEvent(const QString &uid); 251 bool deleteEvent(const QString &uid);
251 /** Create a read-only viewer dialog for the supplied event. */ 252 /** Create a read-only viewer dialog for the supplied event. */
252 void showEvent(Event *); 253 void showEvent(Event *);
253 254
254 void editJournal(Journal *); 255 void editJournal(Journal *);
255 void showJournal(Journal *); 256 void showJournal(Journal *);
256 void deleteJournal(Journal *); 257 void deleteJournal(Journal *);
257 /** Create an editor dialog for a todo */ 258 /** Create an editor dialog for a todo */
258 void editTodo(Todo *); 259 void editTodo(Todo *);
259 /** Create a read-only viewer dialog for the supplied todo */ 260 /** Create a read-only viewer dialog for the supplied todo */
260 void showTodo(Todo *); 261 void showTodo(Todo *);
261 /** create new todo */ 262 /** create new todo */
262 void newTodo(); 263 void newTodo();
264 void newTodoDateTime(QDateTime, bool allday);
263 /** create new todo with a parent todo */ 265 /** create new todo with a parent todo */
264 void newSubTodo(); 266 void newSubTodo();
265 /** create new todo with a parent todo */ 267 /** create new todo with a parent todo */
266 void newSubTodo(Todo *); 268 void newSubTodo(Todo *);
267 /** Delete todo */ 269 /** Delete todo */
268 void deleteTodo(Todo *); 270 void deleteTodo(Todo *);
269 271
270 272
271 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is 273 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is
272 * emitted as result. */ 274 * emitted as result. */
273 void checkClipboard(); 275 void checkClipboard();
274 276
275 /** using the KConfig associated with the kapp variable, read in the 277 /** using the KConfig associated with the kapp variable, read in the
276 * settings from the config file. 278 * settings from the config file.
277 */ 279 */
278 void readSettings(); 280 void readSettings();
279 281
280 /** write current state to config file. */ 282 /** write current state to config file. */
281 void writeSettings(); 283 void writeSettings();
282 284
283 /** read settings for calendar filters */ 285 /** read settings for calendar filters */
284 void readFilterSettings(KConfig *config); 286 void readFilterSettings(KConfig *config);
285 287
286 /** write settings for calendar filters */ 288 /** write settings for calendar filters */
287 void writeFilterSettings(KConfig *config); 289 void writeFilterSettings(KConfig *config);
288 290
289 /** passes on the message that an event has changed to the currently 291 /** passes on the message that an event has changed to the currently
290 * activated view so that it can make appropriate display changes. */ 292 * activated view so that it can make appropriate display changes. */
291 void changeEventDisplay(Event *, int); 293 void changeEventDisplay(Event *, int);
292 void changeIncidenceDisplay(Incidence *, int); 294 void changeIncidenceDisplay(Incidence *, int);
293 void changeTodoDisplay(Todo *, int); 295 void changeTodoDisplay(Todo *, int);
294 296
295 void eventAdded(Event *); 297 void eventAdded(Event *);
296 void eventChanged(Event *); 298 void eventChanged(Event *);
297 void eventToBeDeleted(Event *); 299 void eventToBeDeleted(Event *);
298 void eventDeleted(); 300 void eventDeleted();
299 301
300 void todoAdded(Todo *); 302 void todoAdded(Todo *);
301 void todoChanged(Todo *); 303 void todoChanged(Todo *);
302 void todoToBeDeleted(Todo *); 304 void todoToBeDeleted(Todo *);
303 void todoDeleted(); 305 void todoDeleted();
304 306
305 void updateView(const QDate &start, const QDate &end); 307 void updateView(const QDate &start, const QDate &end);
306 void updateView(); 308 void updateView();
307 309
308 /** Full update of visible todo views */ 310 /** Full update of visible todo views */
309 void updateTodoViews(); 311 void updateTodoViews();
310 312
311 void updateUnmanagedViews(); 313 void updateUnmanagedViews();
312 314
313 /** cut the current appointment to the clipboard */ 315 /** cut the current appointment to the clipboard */
314 void edit_cut(); 316 void edit_cut();
315 317
316 /** copy the current appointment(s) to the clipboard */ 318 /** copy the current appointment(s) to the clipboard */
317 void edit_copy(); 319 void edit_copy();
318 320
319 /** paste the current vobject(s) in the clipboard buffer into calendar */ 321 /** paste the current vobject(s) in the clipboard buffer into calendar */
320 void edit_paste(); 322 void edit_paste();
321 323
322 /** edit viewing and configuration options. */ 324 /** edit viewing and configuration options. */
323 void edit_options(); 325 void edit_options();
324 /** 326 /**
325 Functions for printing, previewing a print, and setting up printing 327 Functions for printing, previewing a print, and setting up printing
326 parameters. 328 parameters.
327 */ 329 */
328 void print(); 330 void print();
329 void printSetup(); 331 void printSetup();
330 void printPreview(); 332 void printPreview();
331 333
332 /** Export as iCalendar file */ 334 /** Export as iCalendar file */
333 void exportICalendar(); 335 void exportICalendar();
334 336
335 /** Export as vCalendar file */ 337 /** Export as vCalendar file */
336 bool exportVCalendar( QString fn); 338 bool exportVCalendar( QString fn);
337 339
338 /** pop up a dialog to show an existing appointment. */ 340 /** pop up a dialog to show an existing appointment. */
339 void appointment_show(); 341 void appointment_show();
340 /** 342 /**
341 * pop up an Appointment Dialog to edit an existing appointment.Get 343 * pop up an Appointment Dialog to edit an existing appointment.Get
342 * information on the appointment from the list of unique IDs that is 344 * information on the appointment from the list of unique IDs that is
343 * currently in the View, called currIds. 345 * currently in the View, called currIds.
344 */ 346 */
345 void appointment_edit(); 347 void appointment_edit();
346 /** 348 /**
347 * pop up dialog confirming deletion of currently selected event in the 349 * pop up dialog confirming deletion of currently selected event in the
348 * View. 350 * View.
349 */ 351 */
350 void appointment_delete(); 352 void appointment_delete();
351 353
352 /** mails the currently selected event to a particular user as a vCalendar 354 /** mails the currently selected event to a particular user as a vCalendar
353 attachment. */ 355 attachment. */
354 void action_mail(); 356 void action_mail();
355 357
356 /* frees a subtodo from it's relation */ 358 /* frees a subtodo from it's relation */
357 void todo_unsub( Todo * ); 359 void todo_unsub( Todo * );
358 void todo_resub( Todo * parent, Todo * sub ); 360 void todo_resub( Todo * parent, Todo * sub );
359 361
360 /** Take ownership of selected event. */ 362 /** Take ownership of selected event. */
361 void takeOverEvent(); 363 void takeOverEvent();
362 364
363 /** Take ownership of all events in calendar. */ 365 /** Take ownership of all events in calendar. */
364 void takeOverCalendar(); 366 void takeOverCalendar();
365 367
366 /** query whether or not the calendar is "dirty". */ 368 /** query whether or not the calendar is "dirty". */
367 bool isModified(); 369 bool isModified();
368 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */ 370 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
369 void setModified(bool modified=true); 371 void setModified(bool modified=true);
370 372
371 /** query if the calendar is read-only. */ 373 /** query if the calendar is read-only. */
372 bool isReadOnly(); 374 bool isReadOnly();
373 /** set state of calendar to read-only */ 375 /** set state of calendar to read-only */
374 void setReadOnly(bool readOnly=true); 376 void setReadOnly(bool readOnly=true);
375 377
376 void eventUpdated(Incidence *); 378 void eventUpdated(Incidence *);
377 379
378 /* iTIP scheduling actions */ 380 /* iTIP scheduling actions */
379 void schedule_publish(Incidence *incidence = 0); 381 void schedule_publish(Incidence *incidence = 0);
380 void schedule_request(Incidence *incidence = 0); 382 void schedule_request(Incidence *incidence = 0);
381 void schedule_refresh(Incidence *incidence = 0); 383 void schedule_refresh(Incidence *incidence = 0);
382 void schedule_cancel(Incidence *incidence = 0); 384 void schedule_cancel(Incidence *incidence = 0);
383 void schedule_add(Incidence *incidence = 0); 385 void schedule_add(Incidence *incidence = 0);
384 void schedule_reply(Incidence *incidence = 0); 386 void schedule_reply(Incidence *incidence = 0);
385 void schedule_counter(Incidence *incidence = 0); 387 void schedule_counter(Incidence *incidence = 0);
386 void schedule_declinecounter(Incidence *incidence = 0); 388 void schedule_declinecounter(Incidence *incidence = 0);
387 void schedule_publish_freebusy(int daysToPublish = 30); 389 void schedule_publish_freebusy(int daysToPublish = 30);
388 390
389 void openAddressbook(); 391 void openAddressbook();
390 392
391 void editFilters(); 393 void editFilters();
392 void toggleFilerEnabled(); 394 void toggleFilerEnabled();
393 QPtrList<CalFilter> filters(); 395 QPtrList<CalFilter> filters();
394 void toggleFilter(); 396 void toggleFilter();
395 void showFilter(bool visible); 397 void showFilter(bool visible);
396 void updateFilter(); 398 void updateFilter();
397 void filterEdited(); 399 void filterEdited();
398 void selectFilter( int ); 400 void selectFilter( int );
399 KOFilterView *filterView(); 401 KOFilterView *filterView();
400 402
401 void showIntro(); 403 void showIntro();
402 404
403 /** Move the curdatepient view date to today */ 405 /** Move the curdatepient view date to today */
404 void goToday(); 406 void goToday();
405 407
406 /** Move to the next date(s) in the current view */ 408 /** Move to the next date(s) in the current view */
407 void goNext(); 409 void goNext();
408 410
409 /** Move to the previous date(s) in the current view */ 411 /** Move to the previous date(s) in the current view */
410 void goPrevious(); 412 void goPrevious();
411 /** Move to the next date(s) in the current view */ 413 /** Move to the next date(s) in the current view */
412 void goNextMonth(); 414 void goNextMonth();
413 415
414 /** Move to the previous date(s) in the current view */ 416 /** Move to the previous date(s) in the current view */
415 void goPreviousMonth(); 417 void goPreviousMonth();
416 418
417 void toggleExpand(); 419 void toggleExpand();
418 void toggleDateNavigatorWidget(); 420 void toggleDateNavigatorWidget();
419 void toggleAllDaySize(); 421 void toggleAllDaySize();
420 void dialogClosing(Incidence *); 422 void dialogClosing(Incidence *);
421 423
422 /** Look for new messages in the inbox */ 424 /** Look for new messages in the inbox */
423 void lookForIncomingMessages(); 425 void lookForIncomingMessages();
424 /** Look for new messages in the outbox */ 426 /** Look for new messages in the outbox */
425 void lookForOutgoingMessages(); 427 void lookForOutgoingMessages();
426 428
427 void processMainViewSelection( Incidence * ); 429 void processMainViewSelection( Incidence * );
428 void processTodoListSelection( Incidence * ); 430 void processTodoListSelection( Incidence * );
429 431
430 void processIncidenceSelection( Incidence * ); 432 void processIncidenceSelection( Incidence * );
431 433
432 void purgeCompleted(); 434 void purgeCompleted();
433 bool removeCompletedSubTodos( Todo* ); 435 bool removeCompletedSubTodos( Todo* );
434 void slotCalendarChanged(); 436 void slotCalendarChanged();
435 bool importBday(); 437 bool importBday();
436 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday ); 438 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday );
437 bool importQtopia( const QString &categoriesFile, 439 bool importQtopia( const QString &categoriesFile,
438 const QString &datebookFile, 440 const QString &datebookFile,
439 const QString &tasklistFile ); 441 const QString &tasklistFile );
440 void syncExternal( int mode ); 442 void syncExternal( int mode );
441 void slotSelectPickerDate( QDate ) ; 443 void slotSelectPickerDate( QDate ) ;
442 void showDatePicker( ) ; 444 void showDatePicker( ) ;
443 void moveIncidence(Incidence *) ; 445 void moveIncidence(Incidence *) ;
444 void beamIncidence(Incidence *) ; 446 void beamIncidence(Incidence *) ;
445 void beamCalendar() ; 447 void beamCalendar() ;
446 void beamFilteredCalendar() ; 448 void beamFilteredCalendar() ;
447 void beamIncidenceList(QPtrList<Incidence>) ; 449 void beamIncidenceList(QPtrList<Incidence>) ;
448 void manageCategories(); 450 void manageCategories();
449 int addCategories(); 451 int addCategories();
450 void removeCategories(); 452 void removeCategories();
451 void setSyncDevice( QString ); 453 void setSyncDevice( QString );
452 void setSyncName( QString ); 454 void setSyncName( QString );
453 void showDay( QDate ); 455 void showDay( QDate );
454 void undo_delete(); 456 void undo_delete();
455 protected slots: 457 protected slots:
456 void timerAlarm(); 458 void timerAlarm();
457 void suspendAlarm(); 459 void suspendAlarm();
458 void beamDone( Ir *ir ); 460 void beamDone( Ir *ir );
459 /** Select a view or adapt the current view to display the specified dates. */ 461 /** Select a view or adapt the current view to display the specified dates. */
460 void showDates( const KCal::DateList & ); 462 void showDates( const KCal::DateList & );
461 void selectWeekNum ( int ); 463 void selectWeekNum ( int );
462 464
463 public: 465 public:
464 // show a standard warning 466 // show a standard warning
465 // returns KMsgBox::yesNoCancel() 467 // returns KMsgBox::yesNoCancel()
466 int msgCalModified(); 468 int msgCalModified();
467 virtual bool sync(KSyncManager* manager, QString filename, int mode); 469 virtual bool sync(KSyncManager* manager, QString filename, int mode);
468 470
469 virtual bool syncExternal(KSyncManager* manager, QString resource); 471 virtual bool syncExternal(KSyncManager* manager, QString resource);
470 virtual void removeSyncInfo( QString syncProfile); 472 virtual void removeSyncInfo( QString syncProfile);
471 void setSyncManager(KSyncManager* manager); 473 void setSyncManager(KSyncManager* manager);
472 void setLoadedFileVersion(QDateTime); 474 void setLoadedFileVersion(QDateTime);
473 bool checkFileVersion(QString fn); 475 bool checkFileVersion(QString fn);
474 bool checkFileChanged(QString fn); 476 bool checkFileChanged(QString fn);
475 Event* getLastSyncEvent(); 477 Event* getLastSyncEvent();
476 /** Adapt navigation units correpsonding to step size of navigation of the 478 /** Adapt navigation units correpsonding to step size of navigation of the
477 * current view. 479 * current view.
478 */ 480 */
479 void adaptNavigationUnits(); 481 void adaptNavigationUnits();
480 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode ); 482 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode );
481 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false ); 483 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false );
482 //Attendee* getYourAttendee(Event *event); 484 //Attendee* getYourAttendee(Event *event);
483 void setBlockShowDates( bool b ) { mBlockShowDates = b ;} 485 void setBlockShowDates( bool b ) { mBlockShowDates = b ;}
484 protected: 486 protected:
485 void schedule(Scheduler::Method, Incidence *incidence = 0); 487 void schedule(Scheduler::Method, Incidence *incidence = 0);
486 488
487 // returns KMsgBox::OKCandel() 489 // returns KMsgBox::OKCandel()
488 int msgItemDelete(const QString name); 490 int msgItemDelete(const QString name);
489 void showEventEditor(); 491 void showEventEditor();
490 void showTodoEditor(); 492 void showTodoEditor();
491 void writeLocale(); 493 void writeLocale();
492 Todo *selectedTodo(); 494 Todo *selectedTodo();
493 495
494 private: 496 private:
495 bool mBlockShowDates; 497 bool mBlockShowDates;
496 KSyncManager* mSyncManager; 498 KSyncManager* mSyncManager;
497 AlarmDialog * mAlarmDialog; 499 AlarmDialog * mAlarmDialog;
498 QString mAlarmNotification; 500 QString mAlarmNotification;
499 QString mSuspendAlarmNotification; 501 QString mSuspendAlarmNotification;
500 QTimer* mSuspendTimer; 502 QTimer* mSuspendTimer;
501 QTimer* mAlarmTimer; 503 QTimer* mAlarmTimer;
502 QTimer* mRecheckAlarmTimer; 504 QTimer* mRecheckAlarmTimer;
503 void computeAlarm( QString ); 505 void computeAlarm( QString );
504 void startAlarm( QString, QString ); 506 void startAlarm( QString, QString );
505 void setSyncEventsReadOnly(); 507 void setSyncEventsReadOnly();
506 508
507 QDateTime loadedFileVersion; 509 QDateTime loadedFileVersion;
508 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ); 510 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete );
509 void checkExternalId( Incidence * inc ); 511 void checkExternalId( Incidence * inc );
510 int mGlobalSyncMode; 512 int mGlobalSyncMode;
511 QString mCurrentSyncDevice; 513 QString mCurrentSyncDevice;
512 QString mCurrentSyncName; 514 QString mCurrentSyncName;
513 KOBeamPrefs* beamDialog; 515 KOBeamPrefs* beamDialog;
514 void init(); 516 void init();
515 int mDatePickerMode; 517 int mDatePickerMode;
516 bool mFlagEditDescription; 518 bool mFlagEditDescription;
517 QDateTime mLastCalendarSync; 519 QDateTime mLastCalendarSync;
518 void createPrinter(); 520 void createPrinter();
519 521
520 void calendarModified( bool, Calendar * ); 522 void calendarModified( bool, Calendar * );
521 523
522 CalPrinter *mCalPrinter; 524 CalPrinter *mCalPrinter;
523 525
524 QSplitter *mPanner; 526 QSplitter *mPanner;
525 QSplitter *mLeftSplitter; 527 QSplitter *mLeftSplitter;
526 QWidget *mLeftFrame; 528 QWidget *mLeftFrame;
527 QWidgetStack *mRightFrame; 529 QWidgetStack *mRightFrame;
528 530
529 KDatePicker* mDatePicker; 531 KDatePicker* mDatePicker;
530 QVBox* mDateFrame; 532 QVBox* mDateFrame;
531 NavigatorBar *mNavigatorBar; 533 NavigatorBar *mNavigatorBar;
532 534
533 KDateNavigator *mDateNavigator; // widget showing small month view. 535 KDateNavigator *mDateNavigator; // widget showing small month view.
534 536
535 KOFilterView *mFilterView; 537 KOFilterView *mFilterView;
536 538
537 ResourceView *mResourceView; 539 ResourceView *mResourceView;
538 540
539 // calendar object for this viewing instance 541 // calendar object for this viewing instance
540 Calendar *mCalendar; 542 Calendar *mCalendar;
541 543
542 CalendarResourceManager *mResourceManager; 544 CalendarResourceManager *mResourceManager;
543 545
544 FileStorage *mStorage; 546 FileStorage *mStorage;
545 547
546 DateNavigator *mNavigator; 548 DateNavigator *mNavigator;
547 549
548 KOViewManager *mViewManager; 550 KOViewManager *mViewManager;
549 KODialogManager *mDialogManager; 551 KODialogManager *mDialogManager;
550 552
551 // Calendar filters 553 // Calendar filters
552 QPtrList<CalFilter> mFilters; 554 QPtrList<CalFilter> mFilters;
553 555
554 // various housekeeping variables. 556 // various housekeeping variables.
555 bool mModified; // flag indicating if calendar is modified 557 bool mModified; // flag indicating if calendar is modified
556 bool mReadOnly; // flag indicating if calendar is read-only 558 bool mReadOnly; // flag indicating if calendar is read-only
557 QDate mSaveSingleDate; 559 QDate mSaveSingleDate;
558 560
559 Incidence *mSelectedIncidence; 561 Incidence *mSelectedIncidence;
560 Incidence *mMoveIncidence; 562 Incidence *mMoveIncidence;
561 QDate mMoveIncidenceOldDate; 563 QDate mMoveIncidenceOldDate;
562 KOTodoView *mTodoList; 564 KOTodoView *mTodoList;
563 KOEventEditor * mEventEditor; 565 KOEventEditor * mEventEditor;
564 KOTodoEditor * mTodoEditor; 566 KOTodoEditor * mTodoEditor;
565 KOEventViewerDialog * mEventViewerDialog; 567 KOEventViewerDialog * mEventViewerDialog;
566 void keyPressEvent ( QKeyEvent *e) ; 568 void keyPressEvent ( QKeyEvent *e) ;
567 //QMap<Incidence*,KOIncidenceEditor*> mDialogList; 569 //QMap<Incidence*,KOIncidenceEditor*> mDialogList;
568}; 570};
569 571
570 572
571class CalendarViewVisitor : public Incidence::Visitor 573class CalendarViewVisitor : public Incidence::Visitor
572{ 574{
573 public: 575 public:
574 CalendarViewVisitor() : mView( 0 ) {} 576 CalendarViewVisitor() : mView( 0 ) {}
575 577
576 bool act( Incidence *incidence, CalendarView *view ) 578 bool act( Incidence *incidence, CalendarView *view )
577 { 579 {
578 mView = view; 580 mView = view;
579 return incidence->accept( *this ); 581 return incidence->accept( *this );
580 } 582 }
581 583
582 protected: 584 protected:
583 CalendarView *mView; 585 CalendarView *mView;
584}; 586};
585 587
586class ShowIncidenceVisitor : public CalendarViewVisitor 588class ShowIncidenceVisitor : public CalendarViewVisitor
587{ 589{
588 protected: 590 protected:
589 bool visit( Event *event ) { mView->showEvent( event ); return true; } 591 bool visit( Event *event ) { mView->showEvent( event ); return true; }
590 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } 592 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; }
591 bool visit( Journal * j ) { mView->showJournal( j );return true; } 593 bool visit( Journal * j ) { mView->showJournal( j );return true; }
592}; 594};
593 595
594class EditIncidenceVisitor : public CalendarViewVisitor 596class EditIncidenceVisitor : public CalendarViewVisitor
595{ 597{
596 protected: 598 protected:
597 bool visit( Event *event ) { mView->editEvent( event ); return true; } 599 bool visit( Event *event ) { mView->editEvent( event ); return true; }
598 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } 600 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; }
599 bool visit( Journal *j ) { mView->editJournal( j); return true; } 601 bool visit( Journal *j ) { mView->editJournal( j); return true; }
600}; 602};
601 603
602class DeleteIncidenceVisitor : public CalendarViewVisitor 604class DeleteIncidenceVisitor : public CalendarViewVisitor
603{ 605{
604 protected: 606 protected:
605 bool visit( Event *event ) { mView->deleteEvent( event ); return true; } 607 bool visit( Event *event ) { mView->deleteEvent( event ); return true; }
606 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } 608 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; }
607 bool visit( Journal * j) {mView->deleteJournal( j ); return true; } 609 bool visit( Journal * j) {mView->deleteJournal( j ); return true; }
608}; 610};
609 611
610#endif 612#endif
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index 7e0b216..73ee5cb 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,1936 +1,1988 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63//////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////
64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
65 : QFrame(_agenda->viewport(),name), agenda(_agenda) 65 : QFrame(_agenda->viewport(),name), agenda(_agenda)
66{ 66{
67 setLineWidth(0); 67 setLineWidth(0);
68 setMargin(0); 68 setMargin(0);
69 setBackgroundColor(Qt::red); 69 setBackgroundColor(Qt::red);
70 minutes = new QTimer(this); 70 minutes = new QTimer(this);
71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
72 minutes->start(0, true); 72 minutes->start(0, true);
73 73
74 mTimeBox = new QLabel(this); 74 mTimeBox = new QLabel(this);
75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
76 QPalette pal = mTimeBox->palette(); 76 QPalette pal = mTimeBox->palette();
77 pal.setColor(QColorGroup::Foreground, Qt::red); 77 pal.setColor(QColorGroup::Foreground, Qt::red);
78 mTimeBox->setPalette(pal); 78 mTimeBox->setPalette(pal);
79 //mTimeBox->setAutoMask(true); 79 //mTimeBox->setAutoMask(true);
80 80
81 agenda->addChild(mTimeBox); 81 agenda->addChild(mTimeBox);
82 82
83 oldToday = -1; 83 oldToday = -1;
84} 84}
85 85
86MarcusBains::~MarcusBains() 86MarcusBains::~MarcusBains()
87{ 87{
88 delete minutes; 88 delete minutes;
89} 89}
90 90
91int MarcusBains::todayColumn() 91int MarcusBains::todayColumn()
92{ 92{
93 QDate currentDate = QDate::currentDate(); 93 QDate currentDate = QDate::currentDate();
94 94
95 DateList dateList = agenda->dateList(); 95 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 96 DateList::ConstIterator it;
97 int col = 0; 97 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 98 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 99 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 100 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 101 agenda->columns() - 1 - col : col;
102 ++col; 102 ++col;
103 } 103 }
104 104
105 return -1; 105 return -1;
106} 106}
107void MarcusBains::updateLoc() 107void MarcusBains::updateLoc()
108{ 108{
109 updateLocation(); 109 updateLocation();
110} 110}
111void MarcusBains::updateLocation(bool recalculate) 111void MarcusBains::updateLocation(bool recalculate)
112{ 112{
113 113
114 QTime tim = QTime::currentTime(); 114 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 116 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 117 recalculate = true;
118 118
119 int mins = tim.hour()*60 + tim.minute(); 119 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 120 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 121 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 122 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 123 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 125
126 oldTime = tim; 126 oldTime = tim;
127 oldToday = today; 127 oldToday = today;
128 128
129 if(disabled || (today<0)) { 129 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 130 hide(); mTimeBox->hide();
131 return; 131 return;
132 } else { 132 } else {
133 show(); mTimeBox->show(); 133 show(); mTimeBox->show();
134 } 134 }
135 135
136 if(recalculate) 136 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 137 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 138 agenda->moveChild(this, x, y);
139 raise(); 139 raise();
140 140
141 if(recalculate) 141 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 142 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 144
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 146 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 147 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 148 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 149 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 150 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 151 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 153 y-mTimeBox->height());
154 154
155 mTimeBox->raise(); 155 mTimeBox->raise();
156 //mTimeBox->setAutoMask(true); 156 //mTimeBox->setAutoMask(true);
157 minutes->start(5000,true); 157 minutes->start(5000,true);
158} 158}
159 159
160 160
161//////////////////////////////////////////////////////////////////////////// 161////////////////////////////////////////////////////////////////////////////
162 162
163 163
164/* 164/*
165 Create an agenda widget with rows rows and columns columns. 165 Create an agenda widget with rows rows and columns columns.
166*/ 166*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 168 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 169 QScrollView(parent,name,f)
170{ 170{
171 171 mNewItemPopup = new QPopupMenu( this );
172 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
173 QString pathString = "";
174 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
175 if ( QApplication::desktop()->width() < 480 )
176 pathString += "icons16/";
177 } else
178 pathString += "iconsmini/";
179
180 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
181 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
182
172 mColumns = columns; 183 mColumns = columns;
173 mRows = rows; 184 mRows = rows;
174 mGridSpacingY = rowSize; 185 mGridSpacingY = rowSize;
175 mAllDayMode = false; 186 mAllDayMode = false;
176#ifndef DESKTOP_VERSION 187#ifndef DESKTOP_VERSION
177 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 188 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
178#endif 189#endif
179 mHolidayMask = 0; 190 mHolidayMask = 0;
180 init(); 191 init();
181} 192}
182 193
183/* 194/*
184 Create an agenda widget with columns columns and one row. This is used for 195 Create an agenda widget with columns columns and one row. This is used for
185 all-day events. 196 all-day events.
186*/ 197*/
187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 198KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
188 QScrollView(parent,name,f) 199 QScrollView(parent,name,f)
189{ 200{
190 201 mNewItemPopup = new QPopupMenu( this );
202 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
203 QString pathString = "";
204 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
205 if ( QApplication::desktop()->width() < 480 )
206 pathString += "icons16/";
207 } else
208 pathString += "iconsmini/";
209 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."),1 );
210 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
191 blockResize = false; 211 blockResize = false;
192 mColumns = columns; 212 mColumns = columns;
193 mRows = 1; 213 mRows = 1;
194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 214 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
195 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 215 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
196 mAllDayMode = true; 216 mAllDayMode = true;
197#ifndef DESKTOP_VERSION 217#ifndef DESKTOP_VERSION
198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 218 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
199#endif 219#endif
200 mHolidayMask = 0; 220 mHolidayMask = 0;
201 init(); 221 init();
202} 222}
203 223
204 224
205KOAgenda::~KOAgenda() 225KOAgenda::~KOAgenda()
206{ 226{
207 if(mMarcusBains) delete mMarcusBains; 227 if(mMarcusBains) delete mMarcusBains;
208 228
209} 229}
210 230
211Incidence *KOAgenda::selectedIncidence() const 231Incidence *KOAgenda::selectedIncidence() const
212{ 232{
213 return (mSelectedItem ? mSelectedItem->incidence() : 0); 233 return (mSelectedItem ? mSelectedItem->incidence() : 0);
214} 234}
215 235
216 236
217QDate KOAgenda::selectedIncidenceDate() const 237QDate KOAgenda::selectedIncidenceDate() const
218{ 238{
219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 239 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
220} 240}
221 241
222 242
223void KOAgenda::init() 243void KOAgenda::init()
224{ 244{
225#ifndef _WIN32_ 245#ifndef _WIN32_
226 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
227 viewport()->setWFlags ( wflags); 247 viewport()->setWFlags ( wflags);
228#endif 248#endif
229 mGridSpacingX = 80; 249 mGridSpacingX = 80;
230 mResizeBorderWidth = 8; 250 mResizeBorderWidth = 8;
231 mScrollBorderWidth = 8; 251 mScrollBorderWidth = 8;
232 mScrollDelay = 30; 252 mScrollDelay = 30;
233 mScrollOffset = 10; 253 mScrollOffset = 10;
234 mPaintPixmap.resize( 20,20); 254 mPaintPixmap.resize( 20,20);
235 //enableClipper(true); 255 //enableClipper(true);
236 256
237 // Grab key strokes for keyboard navigation of agenda. Seems to have no 257 // Grab key strokes for keyboard navigation of agenda. Seems to have no
238 // effect. Has to be fixed. 258 // effect. Has to be fixed.
239 setFocusPolicy(WheelFocus); 259 setFocusPolicy(WheelFocus);
240 260
241 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 261 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
242 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 262 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
243 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 263 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
244 264
245 mStartCellX = 0; 265 mStartCellX = 0;
246 mStartCellY = 0; 266 mStartCellY = 0;
247 mCurrentCellX = 0; 267 mCurrentCellX = 0;
248 mCurrentCellY = 0; 268 mCurrentCellY = 0;
249 269
250 mSelectionCellX = 0; 270 mSelectionCellX = 0;
251 mSelectionYTop = 0; 271 mSelectionYTop = 0;
252 mSelectionHeight = 0; 272 mSelectionHeight = 0;
253 273
254 mOldLowerScrollValue = -1; 274 mOldLowerScrollValue = -1;
255 mOldUpperScrollValue = -1; 275 mOldUpperScrollValue = -1;
256 276
257 mClickedItem = 0; 277 mClickedItem = 0;
258 278
259 mActionItem = 0; 279 mActionItem = 0;
260 mActionType = NOP; 280 mActionType = NOP;
261 mItemMoved = false; 281 mItemMoved = false;
262 282
263 mSelectedItem = 0; 283 mSelectedItem = 0;
264 284
265 // mItems.setAutoDelete(true); 285 // mItems.setAutoDelete(true);
266 286
267 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 287 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
268 288
269 viewport()->update(); 289 viewport()->update();
270 290
271 setMinimumSize(30, 1); 291 setMinimumSize(30, 1);
272// setMaximumHeight(mGridSpacingY * mRows + 5); 292// setMaximumHeight(mGridSpacingY * mRows + 5);
273 293
274 // Disable horizontal scrollbar. This is a hack. The geometry should be 294 // Disable horizontal scrollbar. This is a hack. The geometry should be
275 // controlled in a way that the contents horizontally always fits. Then it is 295 // controlled in a way that the contents horizontally always fits. Then it is
276 // not necessary to turn off the scrollbar. 296 // not necessary to turn off the scrollbar.
277 setHScrollBarMode(AlwaysOff); 297 setHScrollBarMode(AlwaysOff);
278 if ( ! mAllDayMode ) 298 if ( ! mAllDayMode )
279 setVScrollBarMode(AlwaysOn); 299 setVScrollBarMode(AlwaysOn);
280 else 300 else
281 setVScrollBarMode(AlwaysOff); 301 setVScrollBarMode(AlwaysOff);
282 302
283 setStartHour(KOPrefs::instance()->mDayBegins); 303 setStartHour(KOPrefs::instance()->mDayBegins);
284 304
285 calculateWorkingHours(); 305 calculateWorkingHours();
286 306
287 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 307 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
288 SLOT(checkScrollBoundaries(int))); 308 SLOT(checkScrollBoundaries(int)));
289 309
290 // Create the Marcus Bains line. 310 // Create the Marcus Bains line.
291 if(mAllDayMode) 311 if(mAllDayMode)
292 mMarcusBains = 0; 312 mMarcusBains = 0;
293 else { 313 else {
294 mMarcusBains = new MarcusBains(this); 314 mMarcusBains = new MarcusBains(this);
295 addChild(mMarcusBains); 315 addChild(mMarcusBains);
296 } 316 }
297} 317}
298 318
299void KOAgenda::clear() 319void KOAgenda::clear()
300{ 320{
301 KOAgendaItem *item; 321 KOAgendaItem *item;
302 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 322 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
303 mUnusedItems.append( item ); 323 mUnusedItems.append( item );
304 //item->hide(); 324 //item->hide();
305 } 325 }
306 mItems.clear(); 326 mItems.clear();
307 mSelectedItem = 0; 327 mSelectedItem = 0;
308 clearSelection(); 328 clearSelection();
309} 329}
310 330
311void KOAgenda::clearSelection() 331void KOAgenda::clearSelection()
312{ 332{
313 mSelectionCellX = 0; 333 mSelectionCellX = 0;
314 mSelectionYTop = 0; 334 mSelectionYTop = 0;
315 mSelectionHeight = 0; 335 mSelectionHeight = 0;
316} 336}
317 337
318void KOAgenda::marcus_bains() 338void KOAgenda::marcus_bains()
319{ 339{
320 if(mMarcusBains) mMarcusBains->updateLocation(true); 340 if(mMarcusBains) mMarcusBains->updateLocation(true);
321} 341}
322 342
323 343
324void KOAgenda::changeColumns(int columns) 344void KOAgenda::changeColumns(int columns)
325{ 345{
326 if (columns == 0) { 346 if (columns == 0) {
327 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; 347 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl;
328 return; 348 return;
329 } 349 }
330 350
331 clear(); 351 clear();
332 352
333 mColumns = columns; 353 mColumns = columns;
334// setMinimumSize(mColumns * 10, mGridSpacingY + 1); 354// setMinimumSize(mColumns * 10, mGridSpacingY + 1);
335// init(); 355// init();
336// update(); 356// update();
337 //qDebug("KOAgenda::changeColumns "); 357 //qDebug("KOAgenda::changeColumns ");
338 computeSizes(); 358 computeSizes();
339 // QResizeEvent event( size(), size() ); 359 // QResizeEvent event( size(), size() );
340 360
341 //QApplication::sendEvent( this, &event ); 361 //QApplication::sendEvent( this, &event );
342} 362}
343 363
344/* 364/*
345 This is the eventFilter function, which gets all events from the KOAgendaItems 365 This is the eventFilter function, which gets all events from the KOAgendaItems
346 contained in the agenda. It has to handle moving and resizing for all items. 366 contained in the agenda. It has to handle moving and resizing for all items.
347*/ 367*/
348bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 368bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
349{ 369{
350// kdDebug() << "KOAgenda::eventFilter" << endl; 370// kdDebug() << "KOAgenda::eventFilter" << endl;
351 switch(event->type()) { 371 switch(event->type()) {
352 case QEvent::MouseButtonPress: 372 case QEvent::MouseButtonPress:
353 case QEvent::MouseButtonDblClick: 373 case QEvent::MouseButtonDblClick:
354 case QEvent::MouseButtonRelease: 374 case QEvent::MouseButtonRelease:
355 case QEvent::MouseMove: 375 case QEvent::MouseMove:
356 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 376 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
357 377
358 case (QEvent::Leave): 378 case (QEvent::Leave):
359 if (!mActionItem) 379 if (!mActionItem)
360 setCursor(arrowCursor); 380 setCursor(arrowCursor);
361 return true; 381 return true;
362 382
363 default: 383 default:
364 return QScrollView::eventFilter(object,event); 384 return QScrollView::eventFilter(object,event);
365 } 385 }
366} 386}
367 387
368 388
369bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 389bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
370{ 390{
371 //qDebug("KOAgenda::eventFilter_mous "); 391 //qDebug("KOAgenda::eventFilter_mous ");
372 QPoint viewportPos; 392 QPoint viewportPos;
373 if (object != viewport()) { 393 if (object != viewport()) {
374 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 394 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
375 } else { 395 } else {
376 viewportPos = me->pos(); 396 viewportPos = me->pos();
377 } 397 }
378 static int startX = 0; 398 static int startX = 0;
379 static int startY = 0; 399 static int startY = 0;
380 static bool block = true; 400 static bool block = true;
381 switch (me->type()) { 401 switch (me->type()) {
382 case QEvent::MouseButtonPress: 402 case QEvent::MouseButtonPress:
383 //qDebug("QEvent::MouseButtonPress: "); 403 //qDebug("QEvent::MouseButtonPress: ");
384 // kdDebug() << "koagenda: filtered button press" << endl; 404 // kdDebug() << "koagenda: filtered button press" << endl;
385 if (object != viewport()) { 405 if (object != viewport()) {
386 if (me->button() == RightButton) { 406 if (me->button() == RightButton) {
387 407
388 mClickedItem = (KOAgendaItem *)object; 408 mClickedItem = (KOAgendaItem *)object;
389 if (mClickedItem) { 409 if (mClickedItem) {
390 selectItem(mClickedItem); 410 selectItem(mClickedItem);
391 // emit showIncidencePopupSignal(mClickedItem->incidence()); 411 // emit showIncidencePopupSignal(mClickedItem->incidence());
392 } 412 }
393 //mItemPopup->popup(QCursor::pos()); 413 //mItemPopup->popup(QCursor::pos());
394 } else { 414 } else {
395 mActionItem = (KOAgendaItem *)object; 415 mActionItem = (KOAgendaItem *)object;
396 if (mActionItem) { 416 if (mActionItem) {
397 if ( mSelectionHeight > 0 ) { 417 if ( mSelectionHeight > 0 ) {
398 int selectionCellX = mSelectionCellX * mGridSpacingX; 418 int selectionCellX = mSelectionCellX * mGridSpacingX;
399 int selectionYTop = mSelectionYTop; 419 int selectionYTop = mSelectionYTop;
400 int gridSpacingX = mGridSpacingX; 420 int gridSpacingX = mGridSpacingX;
401 int selectionHeight = mSelectionHeight; 421 int selectionHeight = mSelectionHeight;
402 clearSelection(); 422 clearSelection();
403 repaintContents( selectionCellX, selectionYTop, 423 repaintContents( selectionCellX, selectionYTop,
404 gridSpacingX, selectionHeight,false ); 424 gridSpacingX, selectionHeight,false );
405 } 425 }
406 selectItem(mActionItem); 426 selectItem(mActionItem);
407 Incidence *incidence = mActionItem->incidence(); 427 Incidence *incidence = mActionItem->incidence();
408 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 428 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
409 mActionItem = 0; 429 mActionItem = 0;
410 } else { 430 } else {
411 startItemAction(viewportPos); 431 startItemAction(viewportPos);
412 startX = viewportPos.x(); 432 startX = viewportPos.x();
413 startY = viewportPos.y(); 433 startY = viewportPos.y();
414 block = true; 434 block = true;
415 } 435 }
416 } 436 }
417 } 437 }
418 } else { 438 } else {
419 selectItem(0); 439 selectItem(0);
420 mActionItem = 0; 440 mActionItem = 0;
421 setCursor(arrowCursor); 441 if (me->button() == RightButton ) {
422 startSelectAction(viewportPos); 442 blockNewEvent = true;
443 qDebug("right ");
444 int x,y;
445 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
446 int gx,gy;
447 contentsToGrid(x,y,gx,gy);
448 mStartCellX = gx;
449 mStartCellY = gy;
450 mCurrentCellX = gx;
451 mCurrentCellY = gy;
452 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
453
454 } else {
455 blockNewEvent = false;
456 setCursor(arrowCursor);
457 startSelectAction(viewportPos);
458 }
423 } 459 }
424 break; 460 break;
425 461
426 case QEvent::MouseButtonRelease: 462 case QEvent::MouseButtonRelease:
427 //qDebug("QEvent::MouseButtonRelease: "); 463 //qDebug("QEvent::MouseButtonRelease: ");
428 if (me->button() == RightButton && block ) { 464 if (me->button() == RightButton && block ) {
429 if (object != viewport()) { 465 if (object != viewport()) {
430 mClickedItem = (KOAgendaItem *)object; 466 mClickedItem = (KOAgendaItem *)object;
431 if (mActionItem ) { 467 if (mActionItem ) {
432 endItemAction(); 468 endItemAction();
433 } 469 }
434 if (mClickedItem) { 470 if (mClickedItem) {
435 selectItem(mClickedItem); 471 selectItem(mClickedItem);
436 emit showIncidencePopupSignal(mClickedItem->incidence()); 472 emit showIncidencePopupSignal(mClickedItem->incidence());
437 } 473 }
438 } 474 }
439 break; 475 break;
440 } 476 }
441 block = true; 477 block = true;
442 if (mActionItem) { 478 if (mActionItem) {
443 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 479 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
444 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 480 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
445 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 481 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
446 mScrollUpTimer.stop(); 482 mScrollUpTimer.stop();
447 mScrollDownTimer.stop(); 483 mScrollDownTimer.stop();
448 mActionItem->resetMove(); 484 mActionItem->resetMove();
449 placeSubCells( mActionItem ); 485 placeSubCells( mActionItem );
450 // emit startDragSignal( mActionItem->incidence() ); 486 // emit startDragSignal( mActionItem->incidence() );
451 setCursor( arrowCursor ); 487 setCursor( arrowCursor );
452 mActionItem = 0; 488 mActionItem = 0;
453 mActionType = NOP; 489 mActionType = NOP;
454 mItemMoved = 0; 490 mItemMoved = 0;
455 return true; 491 return true;
456 } 492 }
457 endItemAction(); 493 endItemAction();
458 } else if ( mActionType == SELECT ) { 494 } else if ( mActionType == SELECT ) {
459 endSelectAction(); 495 if (me->button() == RightButton ) {
496
497 } else {
498 endSelectAction( !blockNewEvent );
499 }
460 } 500 }
461 break; 501 break;
462 502
463 case QEvent::MouseMove: 503 case QEvent::MouseMove:
464 if (object != viewport()) { 504 if (object != viewport()) {
465 KOAgendaItem *moveItem = (KOAgendaItem *)object; 505 KOAgendaItem *moveItem = (KOAgendaItem *)object;
466 //qDebug("moveItem %d ",moveItem ); 506 //qDebug("moveItem %d ",moveItem );
467 if (!moveItem->incidence()->isReadOnly() /*&& 507 if (!moveItem->incidence()->isReadOnly() /*&&
468 !moveItem->incidence()->recurrence()->doesRecur()*/ ) 508 !moveItem->incidence()->recurrence()->doesRecur()*/ )
469 if (!mActionItem) 509 if (!mActionItem)
470 setNoActionCursor(moveItem,viewportPos); 510 setNoActionCursor(moveItem,viewportPos);
471 else { 511 else {
472 if ( block ) { 512 if ( block ) {
473 int dX, dY; 513 int dX, dY;
474 dX = startX - viewportPos.x(); 514 dX = startX - viewportPos.x();
475 if ( dX < 0 ) 515 if ( dX < 0 )
476 dX = -dX; 516 dX = -dX;
477 dY = viewportPos.y() - startY; 517 dY = viewportPos.y() - startY;
478 if ( dY < 0 ) 518 if ( dY < 0 )
479 dY = -dY; 519 dY = -dY;
480 int diff = 30; 520 int diff = 30;
481 if ( QApplication::desktop()->width() < 480 ) 521 if ( QApplication::desktop()->width() < 480 )
482 diff = 15; 522 diff = 15;
483 // qDebug(" %d %d ",dX, dY ); 523 // qDebug(" %d %d ",dX, dY );
484 if ( dX > diff || dY > diff ) { 524 if ( dX > diff || dY > diff ) {
485 block = false; 525 block = false;
486 } 526 }
487 } 527 }
488 if ( !block ) 528 if ( !block )
489 performItemAction(viewportPos); 529 performItemAction(viewportPos);
490 } 530 }
491 } else { 531 } else {
492 if ( mActionType == SELECT ) { 532 if ( mActionType == SELECT ) {
493 performSelectAction( viewportPos ); 533 performSelectAction( viewportPos );
494 } 534 }
495 } 535 }
496 break; 536 break;
497 537
498 case QEvent::MouseButtonDblClick: 538 case QEvent::MouseButtonDblClick:
499 if (object == viewport()) { 539 if (object == viewport()) {
500 selectItem(0); 540 selectItem(0);
501 int x,y; 541 int x,y;
502 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 542 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
503 int gx,gy; 543 int gx,gy;
504 contentsToGrid(x,y,gx,gy); 544 contentsToGrid(x,y,gx,gy);
505 emit newEventSignal(gx,gy); 545 emit newEventSignal(gx,gy);
506 } else { 546 } else {
507 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 547 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
508 selectItem(doubleClickedItem); 548 selectItem(doubleClickedItem);
509 if ( KOPrefs::instance()->mEditOnDoubleClick ) 549 if ( KOPrefs::instance()->mEditOnDoubleClick )
510 emit editIncidenceSignal(doubleClickedItem->incidence()); 550 emit editIncidenceSignal(doubleClickedItem->incidence());
511 else 551 else
512 emit showIncidenceSignal(doubleClickedItem->incidence()); 552 emit showIncidenceSignal(doubleClickedItem->incidence());
513 } 553 }
514 break; 554 break;
515 555
516 default: 556 default:
517 break; 557 break;
518 } 558 }
519 559
520 return true; 560 return true;
521} 561}
522 562
563void KOAgenda::newItem( int item )
564{
565 qDebug("new %d ", item);
566 if ( item == 1 ) { //new event
567 newEventSignal(mStartCellX ,mStartCellY );
568 }
569 if ( item == 2 ) { //new event
570 newTodoSignal(mStartCellX ,mStartCellY );
571 }
572}
523void KOAgenda::startSelectAction(QPoint viewportPos) 573void KOAgenda::startSelectAction(QPoint viewportPos)
524{ 574{
525 //emit newStartSelectSignal(); 575 //emit newStartSelectSignal();
526 576
527 mActionType = SELECT; 577 mActionType = SELECT;
528 578
529 int x,y; 579 int x,y;
530 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 580 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
531 int gx,gy; 581 int gx,gy;
532 contentsToGrid(x,y,gx,gy); 582 contentsToGrid(x,y,gx,gy);
533 583
534 mStartCellX = gx; 584 mStartCellX = gx;
535 mStartCellY = gy; 585 mStartCellY = gy;
536 mCurrentCellX = gx; 586 mCurrentCellX = gx;
537 mCurrentCellY = gy; 587 mCurrentCellY = gy;
538 588
539 // Store coordinates of old selection 589 // Store coordinates of old selection
540 int selectionX = mSelectionCellX * mGridSpacingX; 590 int selectionX = mSelectionCellX * mGridSpacingX;
541 int selectionYTop = mSelectionYTop; 591 int selectionYTop = mSelectionYTop;
542 int selectionHeight = mSelectionHeight; 592 int selectionHeight = mSelectionHeight;
543 593
544 // Store new selection 594 // Store new selection
545 mSelectionCellX = gx; 595 mSelectionCellX = gx;
546 mSelectionYTop = gy * mGridSpacingY; 596 mSelectionYTop = gy * mGridSpacingY;
547 mSelectionHeight = mGridSpacingY; 597 mSelectionHeight = mGridSpacingY;
548 598
549 // Clear old selection 599 // Clear old selection
550 repaintContents( selectionX, selectionYTop, 600 repaintContents( selectionX, selectionYTop,
551 mGridSpacingX, selectionHeight,false ); 601 mGridSpacingX, selectionHeight,false );
552 602
553 // Paint new selection 603 // Paint new selection
554 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 604 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
555 // mGridSpacingX, mSelectionHeight ); 605 // mGridSpacingX, mSelectionHeight );
556} 606}
557 607
558void KOAgenda::performSelectAction(QPoint viewportPos) 608void KOAgenda::performSelectAction(QPoint viewportPos)
559{ 609{
560 int x,y; 610 int x,y;
561 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 611 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
562 int gx,gy; 612 int gx,gy;
563 contentsToGrid(x,y,gx,gy); 613 contentsToGrid(x,y,gx,gy);
564 614
565 QPoint clipperPos = clipper()-> 615 QPoint clipperPos = clipper()->
566 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 616 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
567 617
568 // Scroll if cursor was moved to upper or lower end of agenda. 618 // Scroll if cursor was moved to upper or lower end of agenda.
569 if (clipperPos.y() < mScrollBorderWidth) { 619 if (clipperPos.y() < mScrollBorderWidth) {
570 mScrollUpTimer.start(mScrollDelay); 620 mScrollUpTimer.start(mScrollDelay);
571 } else if (visibleHeight() - clipperPos.y() < 621 } else if (visibleHeight() - clipperPos.y() <
572 mScrollBorderWidth) { 622 mScrollBorderWidth) {
573 mScrollDownTimer.start(mScrollDelay); 623 mScrollDownTimer.start(mScrollDelay);
574 } else { 624 } else {
575 mScrollUpTimer.stop(); 625 mScrollUpTimer.stop();
576 mScrollDownTimer.stop(); 626 mScrollDownTimer.stop();
577 } 627 }
578 628
579 if ( gy > mCurrentCellY ) { 629 if ( gy > mCurrentCellY ) {
580 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 630 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
581 631
582#if 0 632#if 0
583 // FIXME: Repaint only the newly selected region 633 // FIXME: Repaint only the newly selected region
584 repaintContents( mSelectionCellX * mGridSpacingX, 634 repaintContents( mSelectionCellX * mGridSpacingX,
585 mCurrentCellY + mGridSpacingY, 635 mCurrentCellY + mGridSpacingY,
586 mGridSpacingX, 636 mGridSpacingX,
587 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 637 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
588#else 638#else
589 repaintContents( (KOGlobals::self()->reverseLayout() ? 639 repaintContents( (KOGlobals::self()->reverseLayout() ?
590 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 640 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
591 mGridSpacingX, mSelectionYTop, 641 mGridSpacingX, mSelectionYTop,
592 mGridSpacingX, mSelectionHeight , false); 642 mGridSpacingX, mSelectionHeight , false);
593#endif 643#endif
594 644
595 mCurrentCellY = gy; 645 mCurrentCellY = gy;
596 } else if ( gy < mCurrentCellY ) { 646 } else if ( gy < mCurrentCellY ) {
597 if ( gy >= mStartCellY ) { 647 if ( gy >= mStartCellY ) {
598 int selectionHeight = mSelectionHeight; 648 int selectionHeight = mSelectionHeight;
599 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 649 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
600 650
601 repaintContents( (KOGlobals::self()->reverseLayout() ? 651 repaintContents( (KOGlobals::self()->reverseLayout() ?
602 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 652 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
603 mGridSpacingX, mSelectionYTop, 653 mGridSpacingX, mSelectionYTop,
604 mGridSpacingX, selectionHeight,false ); 654 mGridSpacingX, selectionHeight,false );
605 655
606 mCurrentCellY = gy; 656 mCurrentCellY = gy;
607 } else { 657 } else {
608 } 658 }
609 } 659 }
610} 660}
611 661
612void KOAgenda::endSelectAction() 662void KOAgenda::endSelectAction( bool emitNewEvent )
613{ 663{
614 mActionType = NOP; 664 mActionType = NOP;
615 mScrollUpTimer.stop(); 665 mScrollUpTimer.stop();
616 mScrollDownTimer.stop(); 666 mScrollDownTimer.stop();
617 667
618 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 668 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
669 if ( emitNewEvent && mStartCellY < mCurrentCellY )
670 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
619} 671}
620 672
621void KOAgenda::startItemAction(QPoint viewportPos) 673void KOAgenda::startItemAction(QPoint viewportPos)
622{ 674{
623 int x,y; 675 int x,y;
624 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 676 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
625 int gx,gy; 677 int gx,gy;
626 contentsToGrid(x,y,gx,gy); 678 contentsToGrid(x,y,gx,gy);
627 679
628 mStartCellX = gx; 680 mStartCellX = gx;
629 mStartCellY = gy; 681 mStartCellY = gy;
630 mCurrentCellX = gx; 682 mCurrentCellX = gx;
631 mCurrentCellY = gy; 683 mCurrentCellY = gy;
632 684
633 if (mAllDayMode) { 685 if (mAllDayMode) {
634 int gridDistanceX = (x - gx * mGridSpacingX); 686 int gridDistanceX = (x - gx * mGridSpacingX);
635 if (gridDistanceX < mResizeBorderWidth && 687 if (gridDistanceX < mResizeBorderWidth &&
636 mActionItem->cellX() == mCurrentCellX) { 688 mActionItem->cellX() == mCurrentCellX) {
637 mActionType = RESIZELEFT; 689 mActionType = RESIZELEFT;
638 setCursor(sizeHorCursor); 690 setCursor(sizeHorCursor);
639 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 691 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
640 mActionItem->cellXWidth() == mCurrentCellX) { 692 mActionItem->cellXWidth() == mCurrentCellX) {
641 mActionType = RESIZERIGHT; 693 mActionType = RESIZERIGHT;
642 setCursor(sizeHorCursor); 694 setCursor(sizeHorCursor);
643 } else { 695 } else {
644 mActionType = MOVE; 696 mActionType = MOVE;
645 mActionItem->startMove(); 697 mActionItem->startMove();
646 setCursor(sizeAllCursor); 698 setCursor(sizeAllCursor);
647 } 699 }
648 } else { 700 } else {
649 int gridDistanceY = (y - gy * mGridSpacingY); 701 int gridDistanceY = (y - gy * mGridSpacingY);
650 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 702 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
651 if (allowResize && gridDistanceY < mResizeBorderWidth && 703 if (allowResize && gridDistanceY < mResizeBorderWidth &&
652 mActionItem->cellYTop() == mCurrentCellY && 704 mActionItem->cellYTop() == mCurrentCellY &&
653 !mActionItem->firstMultiItem()) { 705 !mActionItem->firstMultiItem()) {
654 mActionType = RESIZETOP; 706 mActionType = RESIZETOP;
655 setCursor(sizeVerCursor); 707 setCursor(sizeVerCursor);
656 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 708 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
657 mActionItem->cellYBottom() == mCurrentCellY && 709 mActionItem->cellYBottom() == mCurrentCellY &&
658 !mActionItem->lastMultiItem()) { 710 !mActionItem->lastMultiItem()) {
659 mActionType = RESIZEBOTTOM; 711 mActionType = RESIZEBOTTOM;
660 setCursor(sizeVerCursor); 712 setCursor(sizeVerCursor);
661 } else { 713 } else {
662 mActionType = MOVE; 714 mActionType = MOVE;
663 mActionItem->startMove(); 715 mActionItem->startMove();
664 setCursor(sizeAllCursor); 716 setCursor(sizeAllCursor);
665 } 717 }
666 } 718 }
667} 719}
668 720
669void KOAgenda::performItemAction(QPoint viewportPos) 721void KOAgenda::performItemAction(QPoint viewportPos)
670{ 722{
671// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 723// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
672// QPoint point = viewport()->mapToGlobal(viewportPos); 724// QPoint point = viewport()->mapToGlobal(viewportPos);
673// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 725// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
674// point = clipper()->mapFromGlobal(point); 726// point = clipper()->mapFromGlobal(point);
675// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 727// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
676// kdDebug() << "visible height: " << visibleHeight() << endl; 728// kdDebug() << "visible height: " << visibleHeight() << endl;
677 int x,y; 729 int x,y;
678 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 730 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
679// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 731// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
680 int gx,gy; 732 int gx,gy;
681 contentsToGrid(x,y,gx,gy); 733 contentsToGrid(x,y,gx,gy);
682 QPoint clipperPos = clipper()-> 734 QPoint clipperPos = clipper()->
683 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 735 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
684 736
685 // Cursor left active agenda area. 737 // Cursor left active agenda area.
686 // This starts a drag. 738 // This starts a drag.
687 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 739 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
688 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 740 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
689 if ( mActionType == MOVE ) { 741 if ( mActionType == MOVE ) {
690 mScrollUpTimer.stop(); 742 mScrollUpTimer.stop();
691 mScrollDownTimer.stop(); 743 mScrollDownTimer.stop();
692 mActionItem->resetMove(); 744 mActionItem->resetMove();
693 placeSubCells( mActionItem ); 745 placeSubCells( mActionItem );
694 // emit startDragSignal( mActionItem->incidence() ); 746 // emit startDragSignal( mActionItem->incidence() );
695 setCursor( arrowCursor ); 747 setCursor( arrowCursor );
696 mActionItem = 0; 748 mActionItem = 0;
697 mActionType = NOP; 749 mActionType = NOP;
698 mItemMoved = 0; 750 mItemMoved = 0;
699 return; 751 return;
700 } 752 }
701 } else { 753 } else {
702 switch ( mActionType ) { 754 switch ( mActionType ) {
703 case MOVE: 755 case MOVE:
704 setCursor( sizeAllCursor ); 756 setCursor( sizeAllCursor );
705 break; 757 break;
706 case RESIZETOP: 758 case RESIZETOP:
707 case RESIZEBOTTOM: 759 case RESIZEBOTTOM:
708 setCursor( sizeVerCursor ); 760 setCursor( sizeVerCursor );
709 break; 761 break;
710 case RESIZELEFT: 762 case RESIZELEFT:
711 case RESIZERIGHT: 763 case RESIZERIGHT:
712 setCursor( sizeHorCursor ); 764 setCursor( sizeHorCursor );
713 break; 765 break;
714 default: 766 default:
715 setCursor( arrowCursor ); 767 setCursor( arrowCursor );
716 } 768 }
717 } 769 }
718 770
719 // Scroll if item was moved to upper or lower end of agenda. 771 // Scroll if item was moved to upper or lower end of agenda.
720 if (clipperPos.y() < mScrollBorderWidth) { 772 if (clipperPos.y() < mScrollBorderWidth) {
721 mScrollUpTimer.start(mScrollDelay); 773 mScrollUpTimer.start(mScrollDelay);
722 } else if (visibleHeight() - clipperPos.y() < 774 } else if (visibleHeight() - clipperPos.y() <
723 mScrollBorderWidth) { 775 mScrollBorderWidth) {
724 mScrollDownTimer.start(mScrollDelay); 776 mScrollDownTimer.start(mScrollDelay);
725 } else { 777 } else {
726 mScrollUpTimer.stop(); 778 mScrollUpTimer.stop();
727 mScrollDownTimer.stop(); 779 mScrollDownTimer.stop();
728 } 780 }
729 781
730 // Move or resize item if necessary 782 // Move or resize item if necessary
731 if (mCurrentCellX != gx || mCurrentCellY != gy) { 783 if (mCurrentCellX != gx || mCurrentCellY != gy) {
732 mItemMoved = true; 784 mItemMoved = true;
733 mActionItem->raise(); 785 mActionItem->raise();
734 if (mActionType == MOVE) { 786 if (mActionType == MOVE) {
735 // Move all items belonging to a multi item 787 // Move all items belonging to a multi item
736 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 788 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
737 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 789 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
738 if (!moveItem) moveItem = mActionItem; 790 if (!moveItem) moveItem = mActionItem;
739 while (moveItem) { 791 while (moveItem) {
740 int dy; 792 int dy;
741 if (isMultiItem) dy = 0; 793 if (isMultiItem) dy = 0;
742 else dy = gy - mCurrentCellY; 794 else dy = gy - mCurrentCellY;
743 moveItem->moveRelative(gx - mCurrentCellX,dy); 795 moveItem->moveRelative(gx - mCurrentCellX,dy);
744 int x,y; 796 int x,y;
745 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 797 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
746 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 798 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
747 mGridSpacingY * moveItem->cellHeight()); 799 mGridSpacingY * moveItem->cellHeight());
748 moveChild(moveItem,x,y); 800 moveChild(moveItem,x,y);
749 moveItem = moveItem->nextMultiItem(); 801 moveItem = moveItem->nextMultiItem();
750 } 802 }
751 } else if (mActionType == RESIZETOP) { 803 } else if (mActionType == RESIZETOP) {
752 if (mCurrentCellY <= mActionItem->cellYBottom()) { 804 if (mCurrentCellY <= mActionItem->cellYBottom()) {
753 mActionItem->expandTop(gy - mCurrentCellY); 805 mActionItem->expandTop(gy - mCurrentCellY);
754 mActionItem->resize(mActionItem->width(), 806 mActionItem->resize(mActionItem->width(),
755 mGridSpacingY * mActionItem->cellHeight()); 807 mGridSpacingY * mActionItem->cellHeight());
756 int x,y; 808 int x,y;
757 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 809 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
758 //moveChild(mActionItem,childX(mActionItem),y); 810 //moveChild(mActionItem,childX(mActionItem),y);
759 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 811 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
760 } 812 }
761 } else if (mActionType == RESIZEBOTTOM) { 813 } else if (mActionType == RESIZEBOTTOM) {
762 if (mCurrentCellY >= mActionItem->cellYTop()) { 814 if (mCurrentCellY >= mActionItem->cellYTop()) {
763 mActionItem->expandBottom(gy - mCurrentCellY); 815 mActionItem->expandBottom(gy - mCurrentCellY);
764 mActionItem->resize(mActionItem->width(), 816 mActionItem->resize(mActionItem->width(),
765 mGridSpacingY * mActionItem->cellHeight()); 817 mGridSpacingY * mActionItem->cellHeight());
766 } 818 }
767 } else if (mActionType == RESIZELEFT) { 819 } else if (mActionType == RESIZELEFT) {
768 if (mCurrentCellX <= mActionItem->cellXWidth()) { 820 if (mCurrentCellX <= mActionItem->cellXWidth()) {
769 mActionItem->expandLeft(gx - mCurrentCellX); 821 mActionItem->expandLeft(gx - mCurrentCellX);
770 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 822 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
771 mActionItem->height()); 823 mActionItem->height());
772 int x,y; 824 int x,y;
773 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 825 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
774 moveChild(mActionItem,x,childY(mActionItem)); 826 moveChild(mActionItem,x,childY(mActionItem));
775 } 827 }
776 } else if (mActionType == RESIZERIGHT) { 828 } else if (mActionType == RESIZERIGHT) {
777 if (mCurrentCellX >= mActionItem->cellX()) { 829 if (mCurrentCellX >= mActionItem->cellX()) {
778 mActionItem->expandRight(gx - mCurrentCellX); 830 mActionItem->expandRight(gx - mCurrentCellX);
779 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 831 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
780 mActionItem->height()); 832 mActionItem->height());
781 } 833 }
782 } 834 }
783 mCurrentCellX = gx; 835 mCurrentCellX = gx;
784 mCurrentCellY = gy; 836 mCurrentCellY = gy;
785 } 837 }
786} 838}
787 839
788void KOAgenda::endItemAction() 840void KOAgenda::endItemAction()
789{ 841{
790 842
791 if ( mItemMoved ) { 843 if ( mItemMoved ) {
792 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 844 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
793 if ( !placeItem ) { 845 if ( !placeItem ) {
794 placeItem = mActionItem; 846 placeItem = mActionItem;
795 } 847 }
796 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 848 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
797 Incidence* oldInc = placeItem->incidence(); 849 Incidence* oldInc = placeItem->incidence();
798 placeItem->recreateIncidence(); 850 placeItem->recreateIncidence();
799 emit addToCalSignal(placeItem->incidence(), oldInc ); 851 emit addToCalSignal(placeItem->incidence(), oldInc );
800 } 852 }
801 int type = mActionType; 853 int type = mActionType;
802 if ( mAllDayMode ) 854 if ( mAllDayMode )
803 type = -1; 855 type = -1;
804 KOAgendaItem *modifiedItem = placeItem; 856 KOAgendaItem *modifiedItem = placeItem;
805 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 857 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
806 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 858 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
807 KOAgendaItem *item; 859 KOAgendaItem *item;
808 860
809 if ( placeItem->incidence()->type() == "Todo" ) { 861 if ( placeItem->incidence()->type() == "Todo" ) {
810 mSelectedItem = 0; 862 mSelectedItem = 0;
811 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 863 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
812 modifiedItem->mLastMoveXPos = mCurrentCellX; 864 modifiedItem->mLastMoveXPos = mCurrentCellX;
813 emit itemModified( modifiedItem, mActionType ); 865 emit itemModified( modifiedItem, mActionType );
814 } 866 }
815 else { 867 else {
816#if 0 868#if 0
817 for ( item=oldconflictItems.first(); item != 0; 869 for ( item=oldconflictItems.first(); item != 0;
818 item=oldconflictItems.next() ) { 870 item=oldconflictItems.next() ) {
819 placeSubCells(item); 871 placeSubCells(item);
820 } 872 }
821 while ( placeItem ) { 873 while ( placeItem ) {
822 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 874 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
823 placeSubCells( placeItem ); 875 placeSubCells( placeItem );
824 placeItem = placeItem->nextMultiItem(); 876 placeItem = placeItem->nextMultiItem();
825 } 877 }
826#endif 878#endif
827 879
828 globalFlagBlockAgendaItemPaint = 1; 880 globalFlagBlockAgendaItemPaint = 1;
829 for ( item=oldconflictItems.first(); item != 0; 881 for ( item=oldconflictItems.first(); item != 0;
830 item=oldconflictItems.next() ) { 882 item=oldconflictItems.next() ) {
831 placeSubCells(item); 883 placeSubCells(item);
832 } 884 }
833 while ( placeItem ) { 885 while ( placeItem ) {
834 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 886 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
835 oldconflictItems = placeItem->conflictItems(); 887 oldconflictItems = placeItem->conflictItems();
836 for ( item=oldconflictItems.first(); item != 0; 888 for ( item=oldconflictItems.first(); item != 0;
837 item=oldconflictItems.next() ) { 889 item=oldconflictItems.next() ) {
838 placeSubCells(item); 890 placeSubCells(item);
839 } 891 }
840 placeSubCells( placeItem ); 892 placeSubCells( placeItem );
841 placeItem = placeItem->nextMultiItem(); 893 placeItem = placeItem->nextMultiItem();
842 } 894 }
843 globalFlagBlockAgendaItemPaint = 0; 895 globalFlagBlockAgendaItemPaint = 0;
844 for ( item=oldconflictItems.first(); item != 0; 896 for ( item=oldconflictItems.first(); item != 0;
845 item=oldconflictItems.next() ) { 897 item=oldconflictItems.next() ) {
846 globalFlagBlockAgendaItemUpdate = 0; 898 globalFlagBlockAgendaItemUpdate = 0;
847 item->repaintMe(); 899 item->repaintMe();
848 globalFlagBlockAgendaItemUpdate = 1; 900 globalFlagBlockAgendaItemUpdate = 1;
849 item->repaint( false ); 901 item->repaint( false );
850 } 902 }
851 placeItem = modifiedItem; 903 placeItem = modifiedItem;
852 904
853 while ( placeItem ) { 905 while ( placeItem ) {
854 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 906 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
855 globalFlagBlockAgendaItemUpdate = 0; 907 globalFlagBlockAgendaItemUpdate = 0;
856 placeItem->repaintMe(); 908 placeItem->repaintMe();
857 globalFlagBlockAgendaItemUpdate = 1; 909 globalFlagBlockAgendaItemUpdate = 1;
858 placeItem->repaint(false); 910 placeItem->repaint(false);
859 placeItem = placeItem->nextMultiItem(); 911 placeItem = placeItem->nextMultiItem();
860 } 912 }
861 emit itemModified( modifiedItem, mActionType ); 913 emit itemModified( modifiedItem, mActionType );
862 914
863 915
864 placeItem = modifiedItem; 916 placeItem = modifiedItem;
865 while ( placeItem ) { 917 while ( placeItem ) {
866 oldconflictItems = placeItem->conflictItems(); 918 oldconflictItems = placeItem->conflictItems();
867 for ( item=oldconflictItems.first(); item != 0; 919 for ( item=oldconflictItems.first(); item != 0;
868 item=oldconflictItems.next() ) { 920 item=oldconflictItems.next() ) {
869 placeSubCells(item); 921 placeSubCells(item);
870 } 922 }
871 placeSubCells( placeItem ); 923 placeSubCells( placeItem );
872 placeItem = placeItem->nextMultiItem(); 924 placeItem = placeItem->nextMultiItem();
873 925
874 } 926 }
875 placeItem = modifiedItem; 927 placeItem = modifiedItem;
876 while ( placeItem ) { 928 while ( placeItem ) {
877 oldconflictItems = placeItem->conflictItems(); 929 oldconflictItems = placeItem->conflictItems();
878 for ( item=oldconflictItems.first(); item != 0; 930 for ( item=oldconflictItems.first(); item != 0;
879 item=oldconflictItems.next() ) { 931 item=oldconflictItems.next() ) {
880 globalFlagBlockAgendaItemUpdate = 0; 932 globalFlagBlockAgendaItemUpdate = 0;
881 item->repaintMe(); 933 item->repaintMe();
882 globalFlagBlockAgendaItemUpdate = 1; 934 globalFlagBlockAgendaItemUpdate = 1;
883 item->repaint(false); 935 item->repaint(false);
884 } 936 }
885 placeItem = placeItem->nextMultiItem(); 937 placeItem = placeItem->nextMultiItem();
886 } 938 }
887 /* 939 /*
888 940
889 oldconflictItems = modifiedItem->conflictItems(); 941 oldconflictItems = modifiedItem->conflictItems();
890 for ( item=oldconflictItems.first(); item != 0; 942 for ( item=oldconflictItems.first(); item != 0;
891 item=oldconflictItems.next() ) { 943 item=oldconflictItems.next() ) {
892 globalFlagBlockAgendaItemUpdate = 0; 944 globalFlagBlockAgendaItemUpdate = 0;
893 item->paintMe(false); 945 item->paintMe(false);
894 globalFlagBlockAgendaItemUpdate = 1; 946 globalFlagBlockAgendaItemUpdate = 1;
895 item->repaint(false); 947 item->repaint(false);
896 } 948 }
897 */ 949 */
898 950
899 951
900 } 952 }
901 953
902 } 954 }
903 955
904 mScrollUpTimer.stop(); 956 mScrollUpTimer.stop();
905 mScrollDownTimer.stop(); 957 mScrollDownTimer.stop();
906 setCursor( arrowCursor ); 958 setCursor( arrowCursor );
907 mActionItem = 0; 959 mActionItem = 0;
908 mActionType = NOP; 960 mActionType = NOP;
909 mItemMoved = 0; 961 mItemMoved = 0;
910 962
911} 963}
912 964
913void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 965void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
914{ 966{
915// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 967// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
916// QPoint point = viewport()->mapToGlobal(viewportPos); 968// QPoint point = viewport()->mapToGlobal(viewportPos);
917// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 969// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
918// point = clipper()->mapFromGlobal(point); 970// point = clipper()->mapFromGlobal(point);
919// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 971// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
920 972
921 int x,y; 973 int x,y;
922 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 974 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
923// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 975// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
924 int gx,gy; 976 int gx,gy;
925 contentsToGrid(x,y,gx,gy); 977 contentsToGrid(x,y,gx,gy);
926 978
927 // Change cursor to resize cursor if appropriate 979 // Change cursor to resize cursor if appropriate
928 if (mAllDayMode) { 980 if (mAllDayMode) {
929 int gridDistanceX = (x - gx * mGridSpacingX); 981 int gridDistanceX = (x - gx * mGridSpacingX);
930 if (gridDistanceX < mResizeBorderWidth && 982 if (gridDistanceX < mResizeBorderWidth &&
931 moveItem->cellX() == gx) { 983 moveItem->cellX() == gx) {
932 setCursor(sizeHorCursor); 984 setCursor(sizeHorCursor);
933 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 985 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
934 moveItem->cellXWidth() == gx) { 986 moveItem->cellXWidth() == gx) {
935 setCursor(sizeHorCursor); 987 setCursor(sizeHorCursor);
936 } else { 988 } else {
937 setCursor(arrowCursor); 989 setCursor(arrowCursor);
938 } 990 }
939 } else { 991 } else {
940 int gridDistanceY = (y - gy * mGridSpacingY); 992 int gridDistanceY = (y - gy * mGridSpacingY);
941 if (gridDistanceY < mResizeBorderWidth && 993 if (gridDistanceY < mResizeBorderWidth &&
942 moveItem->cellYTop() == gy && 994 moveItem->cellYTop() == gy &&
943 !moveItem->firstMultiItem()) { 995 !moveItem->firstMultiItem()) {
944 setCursor(sizeVerCursor); 996 setCursor(sizeVerCursor);
945 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 997 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
946 moveItem->cellYBottom() == gy && 998 moveItem->cellYBottom() == gy &&
947 !moveItem->lastMultiItem()) { 999 !moveItem->lastMultiItem()) {
948 setCursor(sizeVerCursor); 1000 setCursor(sizeVerCursor);
949 } else { 1001 } else {
950 setCursor(arrowCursor); 1002 setCursor(arrowCursor);
951 } 1003 }
952 } 1004 }
953} 1005}
954 1006
955 1007
956/* 1008/*
957 Place item in cell and take care that multiple items using the same cell do 1009 Place item in cell and take care that multiple items using the same cell do
958 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1010 not overlap. This method is not yet optimal. It doesn´t use the maximum space
959 it can get in all cases. 1011 it can get in all cases.
960 At the moment the method has a bug: When an item is placed only the sub cell 1012 At the moment the method has a bug: When an item is placed only the sub cell
961 widths of the items are changed, which are within the Y region the item to 1013 widths of the items are changed, which are within the Y region the item to
962 place spans. When the sub cell width change of one of this items affects a 1014 place spans. When the sub cell width change of one of this items affects a
963 cell, where other items are, which do not overlap in Y with the item to place, 1015 cell, where other items are, which do not overlap in Y with the item to place,
964 the display gets corrupted, although the corruption looks quite nice. 1016 the display gets corrupted, although the corruption looks quite nice.
965*/ 1017*/
966void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1018void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
967{ 1019{
968 1020
969 QPtrList<KOAgendaItem> conflictItems; 1021 QPtrList<KOAgendaItem> conflictItems;
970 int maxSubCells = 0; 1022 int maxSubCells = 0;
971 QIntDict<KOAgendaItem> subCellDict(5); 1023 QIntDict<KOAgendaItem> subCellDict(5);
972 1024
973 KOAgendaItem *item; 1025 KOAgendaItem *item;
974 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1026 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
975 if (item != placeItem) { 1027 if (item != placeItem) {
976 if (placeItem->cellX() <= item->cellXWidth() && 1028 if (placeItem->cellX() <= item->cellXWidth() &&
977 placeItem->cellXWidth() >= item->cellX()) { 1029 placeItem->cellXWidth() >= item->cellX()) {
978 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1030 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
979 (placeItem->cellYBottom() >= item->cellYTop())) { 1031 (placeItem->cellYBottom() >= item->cellYTop())) {
980 conflictItems.append(item); 1032 conflictItems.append(item);
981 if (item->subCells() > maxSubCells) 1033 if (item->subCells() > maxSubCells)
982 maxSubCells = item->subCells(); 1034 maxSubCells = item->subCells();
983 subCellDict.insert(item->subCell(),item); 1035 subCellDict.insert(item->subCell(),item);
984 } 1036 }
985 } 1037 }
986 } 1038 }
987 } 1039 }
988 1040
989 if (conflictItems.count() > 0) { 1041 if (conflictItems.count() > 0) {
990 // Look for unused sub cell and insert item 1042 // Look for unused sub cell and insert item
991 int i; 1043 int i;
992 for(i=0;i<maxSubCells;++i) { 1044 for(i=0;i<maxSubCells;++i) {
993 if (!subCellDict.find(i)) { 1045 if (!subCellDict.find(i)) {
994 placeItem->setSubCell(i); 1046 placeItem->setSubCell(i);
995 break; 1047 break;
996 } 1048 }
997 } 1049 }
998 if (i == maxSubCells) { 1050 if (i == maxSubCells) {
999 placeItem->setSubCell(maxSubCells); 1051 placeItem->setSubCell(maxSubCells);
1000 maxSubCells++; // add new item to number of sub cells 1052 maxSubCells++; // add new item to number of sub cells
1001 } 1053 }
1002 1054
1003 // Prepare for sub cell geometry adjustment 1055 // Prepare for sub cell geometry adjustment
1004 int newSubCellWidth; 1056 int newSubCellWidth;
1005 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1057 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1006 else newSubCellWidth = mGridSpacingX / maxSubCells; 1058 else newSubCellWidth = mGridSpacingX / maxSubCells;
1007 conflictItems.append(placeItem); 1059 conflictItems.append(placeItem);
1008 1060
1009 1061
1010 // Adjust sub cell geometry of all items 1062 // Adjust sub cell geometry of all items
1011 for ( item=conflictItems.first(); item != 0; 1063 for ( item=conflictItems.first(); item != 0;
1012 item=conflictItems.next() ) { 1064 item=conflictItems.next() ) {
1013 item->setSubCells(maxSubCells); 1065 item->setSubCells(maxSubCells);
1014 if (mAllDayMode) { 1066 if (mAllDayMode) {
1015 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1067 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1016 } else { 1068 } else {
1017 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1069 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1018 } 1070 }
1019 int x,y; 1071 int x,y;
1020 gridToContents(item->cellX(),item->cellYTop(),x,y); 1072 gridToContents(item->cellX(),item->cellYTop(),x,y);
1021 if (mAllDayMode) { 1073 if (mAllDayMode) {
1022 y += item->subCell() * newSubCellWidth; 1074 y += item->subCell() * newSubCellWidth;
1023 } else { 1075 } else {
1024 x += item->subCell() * newSubCellWidth; 1076 x += item->subCell() * newSubCellWidth;
1025 } 1077 }
1026 moveChild(item,x,y); 1078 moveChild(item,x,y);
1027 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1079 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1028 //item->updateItem(); 1080 //item->updateItem();
1029 } 1081 }
1030 1082
1031 } else { 1083 } else {
1032 placeItem->setSubCell(0); 1084 placeItem->setSubCell(0);
1033 placeItem->setSubCells(1); 1085 placeItem->setSubCells(1);
1034 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1086 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1035 else placeItem->resize(mGridSpacingX,placeItem->height()); 1087 else placeItem->resize(mGridSpacingX,placeItem->height());
1036 int x,y; 1088 int x,y;
1037 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1089 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1038 moveChild(placeItem,x,y); 1090 moveChild(placeItem,x,y);
1039 } 1091 }
1040 placeItem->setConflictItems(conflictItems); 1092 placeItem->setConflictItems(conflictItems);
1041 // for ( item=conflictItems.first(); item != 0; 1093 // for ( item=conflictItems.first(); item != 0;
1042// item=conflictItems.next() ) { 1094// item=conflictItems.next() ) {
1043// //item->updateItem(); 1095// //item->updateItem();
1044// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1096// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1045// } 1097// }
1046// placeItem->updateItem(); 1098// placeItem->updateItem();
1047} 1099}
1048 1100
1049void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1101void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1050{ 1102{
1051 if ( globalFlagBlockAgenda ) 1103 if ( globalFlagBlockAgenda )
1052 return; 1104 return;
1053 //qDebug("KOAgenda::drawContents "); 1105 //qDebug("KOAgenda::drawContents ");
1054 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1106 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1055 ;//drawContentsToPainter(); 1107 ;//drawContentsToPainter();
1056 1108
1057 QPaintDevice* pd = p->device(); 1109 QPaintDevice* pd = p->device();
1058 p->end(); 1110 p->end();
1059 int vx, vy; 1111 int vx, vy;
1060 int selectionX = KOGlobals::self()->reverseLayout() ? 1112 int selectionX = KOGlobals::self()->reverseLayout() ?
1061 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1113 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1062 mSelectionCellX * mGridSpacingX; 1114 mSelectionCellX * mGridSpacingX;
1063 contentsToViewport ( cx, cy, vx,vy); 1115 contentsToViewport ( cx, cy, vx,vy);
1064 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1116 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1065 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1117 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1066 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1118 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1067 1119
1068 if ( mSelectionHeight > 0 ) { 1120 if ( mSelectionHeight > 0 ) {
1069 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1121 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1070 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1122 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1071 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1123 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1072 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1124 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1073 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1125 bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1074 } 1126 }
1075 } 1127 }
1076 //qDebug("btbl "); 1128 //qDebug("btbl ");
1077 p->begin( pd ); 1129 p->begin( pd );
1078 //qDebug("end "); 1130 //qDebug("end ");
1079} 1131}
1080 1132
1081void KOAgenda::finishUpdate() 1133void KOAgenda::finishUpdate()
1082{ 1134{
1083 1135
1084 KOAgendaItem *item; 1136 KOAgendaItem *item;
1085 globalFlagBlockAgendaItemPaint = 1; 1137 globalFlagBlockAgendaItemPaint = 1;
1086 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1138 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1087 if ( !item->isVisible() ) 1139 if ( !item->isVisible() )
1088 item->show(); 1140 item->show();
1089 1141
1090 } 1142 }
1091 globalFlagBlockAgendaItemUpdate = 0; 1143 globalFlagBlockAgendaItemUpdate = 0;
1092 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1144 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1093 item->repaintMe( ); 1145 item->repaintMe( );
1094 } 1146 }
1095 globalFlagBlockAgendaItemUpdate = 1; 1147 globalFlagBlockAgendaItemUpdate = 1;
1096 qApp->processEvents(); 1148 qApp->processEvents();
1097 globalFlagBlockAgendaItemPaint = 0; 1149 globalFlagBlockAgendaItemPaint = 0;
1098 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1150 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1099 item->repaint( false ); 1151 item->repaint( false );
1100 } 1152 }
1101 1153
1102} 1154}
1103 1155
1104/* 1156/*
1105 Draw grid in the background of the agenda. 1157 Draw grid in the background of the agenda.
1106*/ 1158*/
1107void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1159void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1108{ 1160{
1109 1161
1110 1162
1111 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1163 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1112 return; 1164 return;
1113 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1165 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1114 return; 1166 return;
1115 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1167 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1116 if ( ch < 1 ) 1168 if ( ch < 1 )
1117 ch = 1; 1169 ch = 1;
1118 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1170 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1119 mPaintPixmap.resize( contentsWidth()+42, ch ); 1171 mPaintPixmap.resize( contentsWidth()+42, ch );
1120 } 1172 }
1121 mCurPixWid = contentsWidth(); 1173 mCurPixWid = contentsWidth();
1122 mCurPixHei = ch; 1174 mCurPixHei = ch;
1123 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { 1175 if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) {
1124 mHighlightPixmap.resize( mGridSpacingX-1, ch ); 1176 mHighlightPixmap.resize( mGridSpacingX-1, ch );
1125 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1177 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1126 } 1178 }
1127 mPixPainter.begin( &mPaintPixmap) ; 1179 mPixPainter.begin( &mPaintPixmap) ;
1128 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1180 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1129 QPainter * p ; 1181 QPainter * p ;
1130 if (paint == 0) { 1182 if (paint == 0) {
1131 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1183 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1132 p = &mPixPainter; 1184 p = &mPixPainter;
1133 } 1185 }
1134 else 1186 else
1135 p = paint ; 1187 p = paint ;
1136 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1188 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1137 1189
1138 //--cx;++cw; 1190 //--cx;++cw;
1139 int lGridSpacingY = mGridSpacingY*2; 1191 int lGridSpacingY = mGridSpacingY*2;
1140 int selDay; 1192 int selDay;
1141 if ( !backgroundOnly ) 1193 if ( !backgroundOnly )
1142 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1194 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1143 { 1195 {
1144 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { 1196 if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) {
1145 int x1 = cx; 1197 int x1 = cx;
1146 int y1 = 0; 1198 int y1 = 0;
1147 if (y1 < cy) y1 = cy; 1199 if (y1 < cy) y1 = cy;
1148 int x2 = cx+cw-1; 1200 int x2 = cx+cw-1;
1149 int y2 = contentsHeight(); 1201 int y2 = contentsHeight();
1150 if (y2 > cy+ch-1) y2=cy+ch-1; 1202 if (y2 > cy+ch-1) y2=cy+ch-1;
1151 if (x2 >= x1 && y2 >= y1) { 1203 if (x2 >= x1 && y2 >= y1) {
1152 int gxStart = selDay; 1204 int gxStart = selDay;
1153 int gxEnd = gxStart ; 1205 int gxEnd = gxStart ;
1154 int xStart = KOGlobals::self()->reverseLayout() ? 1206 int xStart = KOGlobals::self()->reverseLayout() ?
1155 (mColumns - 1 - gxStart)*mGridSpacingX : 1207 (mColumns - 1 - gxStart)*mGridSpacingX :
1156 gxStart*mGridSpacingX; 1208 gxStart*mGridSpacingX;
1157 if (xStart < x1) xStart = x1; 1209 if (xStart < x1) xStart = x1;
1158 int xEnd = KOGlobals::self()->reverseLayout() ? 1210 int xEnd = KOGlobals::self()->reverseLayout() ?
1159 (mColumns - gxStart)*mGridSpacingX-1 : 1211 (mColumns - gxStart)*mGridSpacingX-1 :
1160 (gxStart+1)*mGridSpacingX-1; 1212 (gxStart+1)*mGridSpacingX-1;
1161 if (xEnd > x2) xEnd = x2; 1213 if (xEnd > x2) xEnd = x2;
1162 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1214 if ( KOPrefs::instance()->mUseHighlightLightColor )
1163 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1215 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1164 KOPrefs::instance()->mAgendaBgColor.light()); 1216 KOPrefs::instance()->mAgendaBgColor.light());
1165 else 1217 else
1166 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1218 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1167 KOPrefs::instance()->mAgendaBgColor.dark()); 1219 KOPrefs::instance()->mAgendaBgColor.dark());
1168 1220
1169 } 1221 }
1170 } 1222 }
1171 } 1223 }
1172 // Highlight working hours 1224 // Highlight working hours
1173 1225
1174 if ( !backgroundOnly ) 1226 if ( !backgroundOnly )
1175 if (mWorkingHoursEnable) { 1227 if (mWorkingHoursEnable) {
1176 int x1 = cx; 1228 int x1 = cx;
1177 int y1 = mWorkingHoursYTop; 1229 int y1 = mWorkingHoursYTop;
1178 if (y1 < cy) y1 = cy; 1230 if (y1 < cy) y1 = cy;
1179 int x2 = cx+cw-1; 1231 int x2 = cx+cw-1;
1180 // int x2 = mGridSpacingX * 5 - 1; 1232 // int x2 = mGridSpacingX * 5 - 1;
1181 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1233 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1182 int y2 = mWorkingHoursYBottom; 1234 int y2 = mWorkingHoursYBottom;
1183 if (y2 > cy+ch-1) y2=cy+ch-1; 1235 if (y2 > cy+ch-1) y2=cy+ch-1;
1184 1236
1185 if (x2 >= x1 && y2 >= y1) { 1237 if (x2 >= x1 && y2 >= y1) {
1186 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1238 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1187 int gxStart = x1/mGridSpacingX; 1239 int gxStart = x1/mGridSpacingX;
1188 int gxEnd = x2/mGridSpacingX; 1240 int gxEnd = x2/mGridSpacingX;
1189 while(gxStart <= gxEnd) { 1241 while(gxStart <= gxEnd) {
1190 if (gxStart < int(mHolidayMask->count()) && 1242 if (gxStart < int(mHolidayMask->count()) &&
1191 !mHolidayMask->at(gxStart)) { 1243 !mHolidayMask->at(gxStart)) {
1192 int xStart = KOGlobals::self()->reverseLayout() ? 1244 int xStart = KOGlobals::self()->reverseLayout() ?
1193 (mColumns - 1 - gxStart)*mGridSpacingX : 1245 (mColumns - 1 - gxStart)*mGridSpacingX :
1194 gxStart*mGridSpacingX; 1246 gxStart*mGridSpacingX;
1195 if (xStart < x1) xStart = x1; 1247 if (xStart < x1) xStart = x1;
1196 int xEnd = KOGlobals::self()->reverseLayout() ? 1248 int xEnd = KOGlobals::self()->reverseLayout() ?
1197 (mColumns - gxStart)*mGridSpacingX-1 : 1249 (mColumns - gxStart)*mGridSpacingX-1 :
1198 (gxStart+1)*mGridSpacingX-1; 1250 (gxStart+1)*mGridSpacingX-1;
1199 if (xEnd > x2) xEnd = x2; 1251 if (xEnd > x2) xEnd = x2;
1200 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { 1252 if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) {
1201 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1253 if ( KOPrefs::instance()->mUseHighlightLightColor )
1202 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1254 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1203 KOPrefs::instance()->mWorkingHoursColor.light()); 1255 KOPrefs::instance()->mWorkingHoursColor.light());
1204 else 1256 else
1205 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1257 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1206 KOPrefs::instance()->mWorkingHoursColor.dark()); 1258 KOPrefs::instance()->mWorkingHoursColor.dark());
1207 } else { 1259 } else {
1208 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1260 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1209 KOPrefs::instance()->mWorkingHoursColor); 1261 KOPrefs::instance()->mWorkingHoursColor);
1210 } 1262 }
1211 } 1263 }
1212 ++gxStart; 1264 ++gxStart;
1213 } 1265 }
1214 } 1266 }
1215 } 1267 }
1216 /* 1268 /*
1217 int selectionX = KOGlobals::self()->reverseLayout() ? 1269 int selectionX = KOGlobals::self()->reverseLayout() ?
1218 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1270 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1219 mSelectionCellX * mGridSpacingX; 1271 mSelectionCellX * mGridSpacingX;
1220 1272
1221 // Draw selection 1273 // Draw selection
1222 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1274 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1223 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1275 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1224 // TODO: paint only part within cx,cy,cw,ch 1276 // TODO: paint only part within cx,cy,cw,ch
1225 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1277 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1226 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1278 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1227 } 1279 }
1228 */ 1280 */
1229 // Draw vertical lines of grid 1281 // Draw vertical lines of grid
1230 1282
1231 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1283 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1232 if ( mGridSpacingX > 0 ) { 1284 if ( mGridSpacingX > 0 ) {
1233 while (x < cx + cw) { 1285 while (x < cx + cw) {
1234 p->drawLine(x,cy,x,cy+ch); 1286 p->drawLine(x,cy,x,cy+ch);
1235 x+=mGridSpacingX; 1287 x+=mGridSpacingX;
1236 } 1288 }
1237 } 1289 }
1238 // Draw horizontal lines of grid 1290 // Draw horizontal lines of grid
1239 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1291 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1240 if ( lGridSpacingY > 0 ) { 1292 if ( lGridSpacingY > 0 ) {
1241 while (y < cy + ch) { 1293 while (y < cy + ch) {
1242 p->setPen( SolidLine ); 1294 p->setPen( SolidLine );
1243 p->drawLine(cx,y,cx+cw,y); 1295 p->drawLine(cx,y,cx+cw,y);
1244 y+=lGridSpacingY; 1296 y+=lGridSpacingY;
1245 p->setPen( DotLine ); 1297 p->setPen( DotLine );
1246 p->drawLine(cx,y,cx+cw,y); 1298 p->drawLine(cx,y,cx+cw,y);
1247 y+=lGridSpacingY; 1299 y+=lGridSpacingY;
1248 } 1300 }
1249 p->setPen( SolidLine ); 1301 p->setPen( SolidLine );
1250 } 1302 }
1251 mPixPainter.end() ; 1303 mPixPainter.end() ;
1252} 1304}
1253 1305
1254/* 1306/*
1255 Convert srcollview contents coordinates to agenda grid coordinates. 1307 Convert srcollview contents coordinates to agenda grid coordinates.
1256*/ 1308*/
1257void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1309void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1258{ 1310{
1259 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1311 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1260 x/mGridSpacingX; 1312 x/mGridSpacingX;
1261 gy = y/mGridSpacingY; 1313 gy = y/mGridSpacingY;
1262} 1314}
1263 1315
1264/* 1316/*
1265 Convert agenda grid coordinates to scrollview contents coordinates. 1317 Convert agenda grid coordinates to scrollview contents coordinates.
1266*/ 1318*/
1267void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1319void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1268{ 1320{
1269 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1321 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1270 gx*mGridSpacingX; 1322 gx*mGridSpacingX;
1271 y = gy*mGridSpacingY; 1323 y = gy*mGridSpacingY;
1272} 1324}
1273 1325
1274 1326
1275/* 1327/*
1276 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1328 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1277 the grid. 1329 the grid.
1278*/ 1330*/
1279int KOAgenda::timeToY(const QTime &time) 1331int KOAgenda::timeToY(const QTime &time)
1280{ 1332{
1281 int minutesPerCell = 24 * 60 / mRows; 1333 int minutesPerCell = 24 * 60 / mRows;
1282 int timeMinutes = time.hour() * 60 + time.minute(); 1334 int timeMinutes = time.hour() * 60 + time.minute();
1283 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1335 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1284 return Y; 1336 return Y;
1285} 1337}
1286 1338
1287 1339
1288/* 1340/*
1289 Return time corresponding to cell y coordinate. Coordinates are rounded to 1341 Return time corresponding to cell y coordinate. Coordinates are rounded to
1290 fit into the grid. 1342 fit into the grid.
1291*/ 1343*/
1292QTime KOAgenda::gyToTime(int gy) 1344QTime KOAgenda::gyToTime(int gy)
1293{ 1345{
1294 1346
1295 int secondsPerCell = 24 * 60 * 60/ mRows; 1347 int secondsPerCell = 24 * 60 * 60/ mRows;
1296 1348
1297 int timeSeconds = secondsPerCell * gy; 1349 int timeSeconds = secondsPerCell * gy;
1298 1350
1299 QTime time( 0, 0, 0 ); 1351 QTime time( 0, 0, 0 );
1300 if ( timeSeconds < 24 * 60 * 60 ) { 1352 if ( timeSeconds < 24 * 60 * 60 ) {
1301 time = time.addSecs(timeSeconds); 1353 time = time.addSecs(timeSeconds);
1302 } else { 1354 } else {
1303 time.setHMS( 23, 59, 59 ); 1355 time.setHMS( 23, 59, 59 );
1304 } 1356 }
1305 1357
1306 return time; 1358 return time;
1307} 1359}
1308 1360
1309void KOAgenda::setStartHour(int startHour) 1361void KOAgenda::setStartHour(int startHour)
1310{ 1362{
1311 int startCell = startHour * mRows / 24; 1363 int startCell = startHour * mRows / 24;
1312 setContentsPos(0,startCell * gridSpacingY()); 1364 setContentsPos(0,startCell * gridSpacingY());
1313} 1365}
1314void KOAgenda::hideUnused() 1366void KOAgenda::hideUnused()
1315{ 1367{
1316 // experimental only 1368 // experimental only
1317 // return; 1369 // return;
1318 KOAgendaItem *item; 1370 KOAgendaItem *item;
1319 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1371 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1320 item->hide(); 1372 item->hide();
1321 } 1373 }
1322} 1374}
1323 1375
1324 1376
1325KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1377KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1326{ 1378{
1327 1379
1328 KOAgendaItem *fi; 1380 KOAgendaItem *fi;
1329 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1381 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1330 if ( fi->incidence() == event ) { 1382 if ( fi->incidence() == event ) {
1331 mUnusedItems.remove(); 1383 mUnusedItems.remove();
1332 fi->init( event, qd ); 1384 fi->init( event, qd );
1333 return fi; 1385 return fi;
1334 } 1386 }
1335 } 1387 }
1336 fi=mUnusedItems.first(); 1388 fi=mUnusedItems.first();
1337 if ( fi ) { 1389 if ( fi ) {
1338 mUnusedItems.remove(); 1390 mUnusedItems.remove();
1339 fi->init( event, qd ); 1391 fi->init( event, qd );
1340 return fi; 1392 return fi;
1341 } 1393 }
1342 // qDebug("new KOAgendaItem "); 1394 // qDebug("new KOAgendaItem ");
1343 1395
1344 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1396 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1345 agendaItem->installEventFilter(this); 1397 agendaItem->installEventFilter(this);
1346 addChild(agendaItem,0,0); 1398 addChild(agendaItem,0,0);
1347 return agendaItem; 1399 return agendaItem;
1348} 1400}
1349KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1401KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1350{ 1402{
1351 KOAgendaItem *item; 1403 KOAgendaItem *item;
1352 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1404 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1353 if ( item->incidence() == todo ) { 1405 if ( item->incidence() == todo ) {
1354 mItems.remove(); 1406 mItems.remove();
1355 return item; 1407 return item;
1356 } 1408 }
1357 } 1409 }
1358 return 0; 1410 return 0;
1359} 1411}
1360 1412
1361 1413
1362void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1414void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1363{ 1415{
1364 1416
1365 KOAgendaItem *item; 1417 KOAgendaItem *item;
1366 item = getItemForTodo ( todo ); 1418 item = getItemForTodo ( todo );
1367 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1419 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1368 if ( item ) { 1420 if ( item ) {
1369 blockSignals( true ); 1421 blockSignals( true );
1370 //qDebug("item found "); 1422 //qDebug("item found ");
1371 item->hide(); 1423 item->hide();
1372 item->setCellX(-2, -1 ); 1424 item->setCellX(-2, -1 );
1373 item->select(false); 1425 item->select(false);
1374 mUnusedItems.append( item ); 1426 mUnusedItems.append( item );
1375 mItems.remove( item ); 1427 mItems.remove( item );
1376 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1428 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1377 KOAgendaItem *itemit; 1429 KOAgendaItem *itemit;
1378 //globalFlagBlockAgendaItemPaint = 1; 1430 //globalFlagBlockAgendaItemPaint = 1;
1379 for ( itemit=oldconflictItems.first(); itemit != 0; 1431 for ( itemit=oldconflictItems.first(); itemit != 0;
1380 itemit=oldconflictItems.next() ) { 1432 itemit=oldconflictItems.next() ) {
1381 if ( itemit != item ) 1433 if ( itemit != item )
1382 placeSubCells(itemit); 1434 placeSubCells(itemit);
1383 } 1435 }
1384 qApp->processEvents(); 1436 qApp->processEvents();
1385 //globalFlagBlockAgendaItemPaint = 0; 1437 //globalFlagBlockAgendaItemPaint = 0;
1386 for ( itemit=oldconflictItems.first(); itemit != 0; 1438 for ( itemit=oldconflictItems.first(); itemit != 0;
1387 itemit=oldconflictItems.next() ) { 1439 itemit=oldconflictItems.next() ) {
1388 globalFlagBlockAgendaItemUpdate = 0; 1440 globalFlagBlockAgendaItemUpdate = 0;
1389 if ( itemit != item ) 1441 if ( itemit != item )
1390 itemit->repaintMe(); 1442 itemit->repaintMe();
1391 globalFlagBlockAgendaItemUpdate = 1; 1443 globalFlagBlockAgendaItemUpdate = 1;
1392 itemit->repaint(); 1444 itemit->repaint();
1393 } 1445 }
1394 blockSignals( false ); 1446 blockSignals( false );
1395 } 1447 }
1396 if ( remove ) { 1448 if ( remove ) {
1397 //qDebug("remove****************************************** "); 1449 //qDebug("remove****************************************** ");
1398 return; 1450 return;
1399 } 1451 }
1400 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1452 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1401 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1453 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda );
1402 QDate currentDate; 1454 QDate currentDate;
1403 if ( overdue ) { 1455 if ( overdue ) {
1404 currentDate = QDate::currentDate(); 1456 currentDate = QDate::currentDate();
1405 days += todo->dtDue().date().daysTo( currentDate ); 1457 days += todo->dtDue().date().daysTo( currentDate );
1406 } 1458 }
1407 else 1459 else
1408 currentDate = todo->dtDue().date(); 1460 currentDate = todo->dtDue().date();
1409 1461
1410 if ( todo->doesFloat() || overdue ) { 1462 if ( todo->doesFloat() || overdue ) {
1411 if ( ! mAllDayMode ) return; 1463 if ( ! mAllDayMode ) return;
1412 // aldayagenda 1464 // aldayagenda
1413 globalFlagBlockAgendaItemPaint = 1; 1465 globalFlagBlockAgendaItemPaint = 1;
1414 item = insertAllDayItem(todo, currentDate,days, days); 1466 item = insertAllDayItem(todo, currentDate,days, days);
1415 item->show(); 1467 item->show();
1416 1468
1417 } 1469 }
1418 else { 1470 else {
1419 if ( mAllDayMode ) return; 1471 if ( mAllDayMode ) return;
1420 // mAgenda 1472 // mAgenda
1421 globalFlagBlockAgendaItemPaint = 1; 1473 globalFlagBlockAgendaItemPaint = 1;
1422 int endY = timeToY(todo->dtDue().time()) - 1; 1474 int endY = timeToY(todo->dtDue().time()) - 1;
1423 int hi = 12/KOPrefs::instance()->mHourSize; 1475 int hi = 12/KOPrefs::instance()->mHourSize;
1424 int startY = endY - 1-hi; 1476 int startY = endY - 1-hi;
1425 item = insertItem(todo,currentDate,days,startY,endY); 1477 item = insertItem(todo,currentDate,days,startY,endY);
1426 item->show(); 1478 item->show();
1427 } 1479 }
1428 qApp->processEvents(); 1480 qApp->processEvents();
1429 globalFlagBlockAgendaItemPaint = 0; 1481 globalFlagBlockAgendaItemPaint = 0;
1430 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1482 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1431 KOAgendaItem *itemit; 1483 KOAgendaItem *itemit;
1432 for ( itemit=oldconflictItems.first(); itemit != 0; 1484 for ( itemit=oldconflictItems.first(); itemit != 0;
1433 itemit=oldconflictItems.next() ) { 1485 itemit=oldconflictItems.next() ) {
1434 globalFlagBlockAgendaItemUpdate = 0; 1486 globalFlagBlockAgendaItemUpdate = 0;
1435 itemit->repaintMe(); 1487 itemit->repaintMe();
1436 globalFlagBlockAgendaItemUpdate = 1; 1488 globalFlagBlockAgendaItemUpdate = 1;
1437 itemit->repaint(); 1489 itemit->repaint();
1438 } 1490 }
1439 globalFlagBlockAgendaItemUpdate = 0; 1491 globalFlagBlockAgendaItemUpdate = 0;
1440 item->repaintMe(); 1492 item->repaintMe();
1441 globalFlagBlockAgendaItemUpdate = 1; 1493 globalFlagBlockAgendaItemUpdate = 1;
1442 item->repaint(); 1494 item->repaint();
1443} 1495}
1444/* 1496/*
1445 Insert KOAgendaItem into agenda. 1497 Insert KOAgendaItem into agenda.
1446*/ 1498*/
1447KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1499KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1448{ 1500{
1449 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; 1501 //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl;
1450 1502
1451 if (mAllDayMode) { 1503 if (mAllDayMode) {
1452 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; 1504 kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl;
1453 return 0; 1505 return 0;
1454 } 1506 }
1455 1507
1456 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1508 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1457 //agendaItem->setFrameStyle(WinPanel|Raised); 1509 //agendaItem->setFrameStyle(WinPanel|Raised);
1458 1510
1459 int YSize = YBottom - YTop + 1; 1511 int YSize = YBottom - YTop + 1;
1460 if (YSize < 0) { 1512 if (YSize < 0) {
1461 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; 1513 kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl;
1462 YSize = 1; 1514 YSize = 1;
1463 } 1515 }
1464 int iheight = mGridSpacingY * YSize; 1516 int iheight = mGridSpacingY * YSize;
1465 1517
1466 agendaItem->resize(mGridSpacingX,iheight ); 1518 agendaItem->resize(mGridSpacingX,iheight );
1467 agendaItem->setCellXY(X,YTop,YBottom); 1519 agendaItem->setCellXY(X,YTop,YBottom);
1468 agendaItem->setCellXWidth(X); 1520 agendaItem->setCellXWidth(X);
1469 1521
1470 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1522 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1471 mItems.append(agendaItem); 1523 mItems.append(agendaItem);
1472 1524
1473 placeSubCells(agendaItem); 1525 placeSubCells(agendaItem);
1474 1526
1475 //agendaItem->show(); 1527 //agendaItem->show();
1476 1528
1477 marcus_bains(); 1529 marcus_bains();
1478 1530
1479 return agendaItem; 1531 return agendaItem;
1480} 1532}
1481 1533
1482 1534
1483/* 1535/*
1484 Insert all-day KOAgendaItem into agenda. 1536 Insert all-day KOAgendaItem into agenda.
1485*/ 1537*/
1486KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1538KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1487{ 1539{
1488 if (!mAllDayMode) { 1540 if (!mAllDayMode) {
1489 return 0; 1541 return 0;
1490 } 1542 }
1491 1543
1492 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1544 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1493 1545
1494 agendaItem->setCellXY(XBegin,0,0); 1546 agendaItem->setCellXY(XBegin,0,0);
1495 agendaItem->setCellXWidth(XEnd); 1547 agendaItem->setCellXWidth(XEnd);
1496 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1548 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1497 1549
1498 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1550 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1499 mItems.append(agendaItem); 1551 mItems.append(agendaItem);
1500 1552
1501 placeSubCells(agendaItem); 1553 placeSubCells(agendaItem);
1502 1554
1503 //agendaItem->show(); 1555 //agendaItem->show();
1504 1556
1505 return agendaItem; 1557 return agendaItem;
1506} 1558}
1507 1559
1508 1560
1509void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1561void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1510 int YTop,int YBottom) 1562 int YTop,int YBottom)
1511{ 1563{
1512 if (mAllDayMode) { 1564 if (mAllDayMode) {
1513 ; 1565 ;
1514 return; 1566 return;
1515 } 1567 }
1516 1568
1517 int cellX,cellYTop,cellYBottom; 1569 int cellX,cellYTop,cellYBottom;
1518 QString newtext; 1570 QString newtext;
1519 int width = XEnd - XBegin + 1; 1571 int width = XEnd - XBegin + 1;
1520 int count = 0; 1572 int count = 0;
1521 KOAgendaItem *current = 0; 1573 KOAgendaItem *current = 0;
1522 QPtrList<KOAgendaItem> multiItems; 1574 QPtrList<KOAgendaItem> multiItems;
1523 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1575 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1524 if (cellX == XBegin) cellYTop = YTop; 1576 if (cellX == XBegin) cellYTop = YTop;
1525 else cellYTop = 0; 1577 else cellYTop = 0;
1526 if (cellX == XEnd) cellYBottom = YBottom; 1578 if (cellX == XEnd) cellYBottom = YBottom;
1527 else cellYBottom = rows() - 1; 1579 else cellYBottom = rows() - 1;
1528 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1580 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1529 newtext.append(event->summary()); 1581 newtext.append(event->summary());
1530 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1582 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1531 current->setText(newtext); 1583 current->setText(newtext);
1532 multiItems.append(current); 1584 multiItems.append(current);
1533 } 1585 }
1534 1586
1535 KOAgendaItem *next = 0; 1587 KOAgendaItem *next = 0;
1536 KOAgendaItem *last = multiItems.last(); 1588 KOAgendaItem *last = multiItems.last();
1537 KOAgendaItem *first = multiItems.first(); 1589 KOAgendaItem *first = multiItems.first();
1538 KOAgendaItem *setFirst,*setLast; 1590 KOAgendaItem *setFirst,*setLast;
1539 current = first; 1591 current = first;
1540 while (current) { 1592 while (current) {
1541 next = multiItems.next(); 1593 next = multiItems.next();
1542 if (current == first) setFirst = 0; 1594 if (current == first) setFirst = 0;
1543 else setFirst = first; 1595 else setFirst = first;
1544 if (current == last) setLast = 0; 1596 if (current == last) setLast = 0;
1545 else setLast = last; 1597 else setLast = last;
1546 1598
1547 current->setMultiItem(setFirst,next,setLast); 1599 current->setMultiItem(setFirst,next,setLast);
1548 current = next; 1600 current = next;
1549 } 1601 }
1550 1602
1551 marcus_bains(); 1603 marcus_bains();
1552} 1604}
1553 1605
1554 1606
1555//QSizePolicy KOAgenda::sizePolicy() const 1607//QSizePolicy KOAgenda::sizePolicy() const
1556//{ 1608//{
1557 // Thought this would make the all-day event agenda minimum size and the 1609 // Thought this would make the all-day event agenda minimum size and the
1558 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1610 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1559 // don´t seem to think that an Expanding widget needs more space than a 1611 // don´t seem to think that an Expanding widget needs more space than a
1560 // Preferred one. 1612 // Preferred one.
1561 // But it doesn´t hurt, so it stays. 1613 // But it doesn´t hurt, so it stays.
1562// if (mAllDayMode) { 1614// if (mAllDayMode) {
1563// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1615// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1564// } else { 1616// } else {
1565// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1617// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1566// } 1618// }
1567//} 1619//}
1568void KOAgenda::finishResize ( ) 1620void KOAgenda::finishResize ( )
1569{ 1621{
1570 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1622 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1571 if ( globalFlagBlockAgenda == 0 ) { 1623 if ( globalFlagBlockAgenda == 0 ) {
1572 finishUpdate(); 1624 finishUpdate();
1573 //qDebug("finishUpdate() called "); 1625 //qDebug("finishUpdate() called ");
1574 } 1626 }
1575} 1627}
1576/* 1628/*
1577 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1629 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1578*/ 1630*/
1579void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1631void KOAgenda::resizeEvent ( QResizeEvent *ev )
1580{ 1632{
1581 1633
1582 mResizeTimer.start( 150 , true ); 1634 mResizeTimer.start( 150 , true );
1583 computeSizes(); 1635 computeSizes();
1584 return; 1636 return;
1585 1637
1586} 1638}
1587void KOAgenda::computeSizes() 1639void KOAgenda::computeSizes()
1588{ 1640{
1589 if ( globalFlagBlockStartup ) 1641 if ( globalFlagBlockStartup )
1590 return; 1642 return;
1591 1643
1592 if (mAllDayMode) { 1644 if (mAllDayMode) {
1593 mGridSpacingX = (width()-3) / mColumns; 1645 mGridSpacingX = (width()-3) / mColumns;
1594 mGridSpacingY = height() - 2 * frameWidth() - 1; 1646 mGridSpacingY = height() - 2 * frameWidth() - 1;
1595 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1647 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1596// mGridSpacingY = height(); 1648// mGridSpacingY = height();
1597// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1649// resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1598 1650
1599 KOAgendaItem *item; 1651 KOAgendaItem *item;
1600 int subCellWidth; 1652 int subCellWidth;
1601 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1653 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1602 subCellWidth = mGridSpacingY / item->subCells(); 1654 subCellWidth = mGridSpacingY / item->subCells();
1603 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1655 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1604 moveChild(item,KOGlobals::self()->reverseLayout() ? 1656 moveChild(item,KOGlobals::self()->reverseLayout() ?
1605 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1657 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1606 item->cellX() * mGridSpacingX, 1658 item->cellX() * mGridSpacingX,
1607 item->subCell() * subCellWidth); 1659 item->subCell() * subCellWidth);
1608 } 1660 }
1609 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1661 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1610 } else { 1662 } else {
1611 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; 1663 mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns;
1612 if (height() > mGridSpacingY * mRows + 1 ) { 1664 if (height() > mGridSpacingY * mRows + 1 ) {
1613 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1665 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1614 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1666 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1615 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1667 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1616 emit resizedSignal(); 1668 emit resizedSignal();
1617 } else 1669 } else
1618 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1670 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1619 KOAgendaItem *item; 1671 KOAgendaItem *item;
1620 int subCellWidth; 1672 int subCellWidth;
1621 1673
1622 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1674 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1623 subCellWidth = mGridSpacingX / item->subCells(); 1675 subCellWidth = mGridSpacingX / item->subCells();
1624 item->resize(subCellWidth,item->height()); 1676 item->resize(subCellWidth,item->height());
1625 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1677 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1626 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1678 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1627 item->cellX() * mGridSpacingX) + 1679 item->cellX() * mGridSpacingX) +
1628 item->subCell() * subCellWidth,childY(item)); 1680 item->subCell() * subCellWidth,childY(item));
1629 } 1681 }
1630 } 1682 }
1631 int cw = contentsWidth(); 1683 int cw = contentsWidth();
1632 int ch = contentsHeight(); 1684 int ch = contentsHeight();
1633 if ( mAllDayMode ) { 1685 if ( mAllDayMode ) {
1634 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1686 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1635 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) 1687 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
1636 paintPixAll->resize( cw, ch ); 1688 paintPixAll->resize( cw, ch );
1637 } else { 1689 } else {
1638 QPixmap* paintPix = KOAgendaItem::paintPix(); 1690 QPixmap* paintPix = KOAgendaItem::paintPix();
1639 if ( paintPix->width() < cw || paintPix->height() < ch ) 1691 if ( paintPix->width() < cw || paintPix->height() < ch )
1640 KOAgendaItem::resizePixmap( cw , ch ); 1692 KOAgendaItem::resizePixmap( cw , ch );
1641 } 1693 }
1642 1694
1643 checkScrollBoundaries(); 1695 checkScrollBoundaries();
1644 marcus_bains(); 1696 marcus_bains();
1645 drawContentsToPainter(); 1697 drawContentsToPainter();
1646 viewport()->repaint(false); 1698 viewport()->repaint(false);
1647} 1699}
1648 1700
1649void KOAgenda::scrollUp() 1701void KOAgenda::scrollUp()
1650{ 1702{
1651 scrollBy(0,-mScrollOffset); 1703 scrollBy(0,-mScrollOffset);
1652} 1704}
1653 1705
1654 1706
1655void KOAgenda::scrollDown() 1707void KOAgenda::scrollDown()
1656{ 1708{
1657 scrollBy(0,mScrollOffset); 1709 scrollBy(0,mScrollOffset);
1658} 1710}
1659 1711
1660void KOAgenda::popupAlarm() 1712void KOAgenda::popupAlarm()
1661{ 1713{
1662 if (!mClickedItem) { 1714 if (!mClickedItem) {
1663 kdDebug() << "KOAgenda::popupAlarm() called without having a clicked item" << endl; 1715 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1664 return; 1716 return;
1665 } 1717 }
1666// TODO: deal correctly with multiple alarms 1718// TODO: deal correctly with multiple alarms
1667 Alarm* alarm; 1719 Alarm* alarm;
1668 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1720 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1669 for(alarm=list.first();alarm;alarm=list.next()) { 1721 for(alarm=list.first();alarm;alarm=list.next()) {
1670 alarm->toggleAlarm(); 1722 alarm->toggleAlarm();
1671 } 1723 }
1672 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 1724 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
1673 mClickedItem->paintMe( true ); 1725 mClickedItem->paintMe( true );
1674 mClickedItem->repaint( false ); 1726 mClickedItem->repaint( false );
1675} 1727}
1676 1728
1677/* 1729/*
1678 Calculates the minimum width 1730 Calculates the minimum width
1679*/ 1731*/
1680int KOAgenda::minimumWidth() const 1732int KOAgenda::minimumWidth() const
1681{ 1733{
1682 // TODO:: develop a way to dynamically determine the minimum width 1734 // TODO:: develop a way to dynamically determine the minimum width
1683 int min = 100; 1735 int min = 100;
1684 1736
1685 return min; 1737 return min;
1686} 1738}
1687 1739
1688void KOAgenda::updateConfig() 1740void KOAgenda::updateConfig()
1689{ 1741{
1690 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 1742 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
1691 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 1743 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
1692 if ( mAllDayMode ) { 1744 if ( mAllDayMode ) {
1693 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 1745 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
1694 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 1746 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
1695 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 1747 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
1696 // setMaximumHeight( mGridSpacingY+1 ); 1748 // setMaximumHeight( mGridSpacingY+1 );
1697 viewport()->repaint( false ); 1749 viewport()->repaint( false );
1698 //setFixedHeight( mGridSpacingY+1 ); 1750 //setFixedHeight( mGridSpacingY+1 );
1699 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 1751 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
1700 } 1752 }
1701 else { 1753 else {
1702 mGridSpacingY = KOPrefs::instance()->mHourSize; 1754 mGridSpacingY = KOPrefs::instance()->mHourSize;
1703 calculateWorkingHours(); 1755 calculateWorkingHours();
1704 marcus_bains(); 1756 marcus_bains();
1705 } 1757 }
1706} 1758}
1707 1759
1708void KOAgenda::checkScrollBoundaries() 1760void KOAgenda::checkScrollBoundaries()
1709{ 1761{
1710 // Invalidate old values to force update 1762 // Invalidate old values to force update
1711 mOldLowerScrollValue = -1; 1763 mOldLowerScrollValue = -1;
1712 mOldUpperScrollValue = -1; 1764 mOldUpperScrollValue = -1;
1713 1765
1714 checkScrollBoundaries(verticalScrollBar()->value()); 1766 checkScrollBoundaries(verticalScrollBar()->value());
1715} 1767}
1716 1768
1717void KOAgenda::checkScrollBoundaries(int v) 1769void KOAgenda::checkScrollBoundaries(int v)
1718{ 1770{
1719 if ( mGridSpacingY == 0 ) 1771 if ( mGridSpacingY == 0 )
1720 return; 1772 return;
1721 int yMin = v/mGridSpacingY; 1773 int yMin = v/mGridSpacingY;
1722 int yMax = (v+visibleHeight())/mGridSpacingY; 1774 int yMax = (v+visibleHeight())/mGridSpacingY;
1723 1775
1724// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 1776// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
1725 1777
1726 if (yMin != mOldLowerScrollValue) { 1778 if (yMin != mOldLowerScrollValue) {
1727 mOldLowerScrollValue = yMin; 1779 mOldLowerScrollValue = yMin;
1728 emit lowerYChanged(yMin); 1780 emit lowerYChanged(yMin);
1729 } 1781 }
1730 if (yMax != mOldUpperScrollValue) { 1782 if (yMax != mOldUpperScrollValue) {
1731 mOldUpperScrollValue = yMax; 1783 mOldUpperScrollValue = yMax;
1732 emit upperYChanged(yMax); 1784 emit upperYChanged(yMax);
1733 } 1785 }
1734} 1786}
1735 1787
1736void KOAgenda::deselectItem() 1788void KOAgenda::deselectItem()
1737{ 1789{
1738 if (mSelectedItem.isNull()) return; 1790 if (mSelectedItem.isNull()) return;
1739 mSelectedItem->select(false); 1791 mSelectedItem->select(false);
1740 mSelectedItem = 0; 1792 mSelectedItem = 0;
1741} 1793}
1742 1794
1743void KOAgenda::selectItem(KOAgendaItem *item) 1795void KOAgenda::selectItem(KOAgendaItem *item)
1744{ 1796{
1745 if ((KOAgendaItem *)mSelectedItem == item) return; 1797 if ((KOAgendaItem *)mSelectedItem == item) return;
1746 deselectItem(); 1798 deselectItem();
1747 if (item == 0) { 1799 if (item == 0) {
1748 emit incidenceSelected( 0 ); 1800 emit incidenceSelected( 0 );
1749 return; 1801 return;
1750 } 1802 }
1751 mSelectedItem = item; 1803 mSelectedItem = item;
1752 mSelectedItem->select(); 1804 mSelectedItem->select();
1753 emit incidenceSelected( mSelectedItem->incidence() ); 1805 emit incidenceSelected( mSelectedItem->incidence() );
1754} 1806}
1755 1807
1756// This function seems never be called. 1808// This function seems never be called.
1757void KOAgenda::keyPressEvent( QKeyEvent *kev ) 1809void KOAgenda::keyPressEvent( QKeyEvent *kev )
1758{ 1810{
1759 switch(kev->key()) { 1811 switch(kev->key()) {
1760 case Key_PageDown: 1812 case Key_PageDown:
1761 verticalScrollBar()->addPage(); 1813 verticalScrollBar()->addPage();
1762 break; 1814 break;
1763 case Key_PageUp: 1815 case Key_PageUp:
1764 verticalScrollBar()->subtractPage(); 1816 verticalScrollBar()->subtractPage();
1765 break; 1817 break;
1766 case Key_Down: 1818 case Key_Down:
1767 verticalScrollBar()->addLine(); 1819 verticalScrollBar()->addLine();
1768 break; 1820 break;
1769 case Key_Up: 1821 case Key_Up:
1770 verticalScrollBar()->subtractLine(); 1822 verticalScrollBar()->subtractLine();
1771 break; 1823 break;
1772 default: 1824 default:
1773 ; 1825 ;
1774 } 1826 }
1775} 1827}
1776 1828
1777void KOAgenda::calculateWorkingHours() 1829void KOAgenda::calculateWorkingHours()
1778{ 1830{
1779// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 1831// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
1780 mWorkingHoursEnable = !mAllDayMode; 1832 mWorkingHoursEnable = !mAllDayMode;
1781 1833
1782 mWorkingHoursYTop = mGridSpacingY * 1834 mWorkingHoursYTop = mGridSpacingY *
1783 KOPrefs::instance()->mWorkingHoursStart * 4; 1835 KOPrefs::instance()->mWorkingHoursStart * 4;
1784 mWorkingHoursYBottom = mGridSpacingY * 1836 mWorkingHoursYBottom = mGridSpacingY *
1785 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 1837 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
1786} 1838}
1787 1839
1788 1840
1789DateList KOAgenda::dateList() const 1841DateList KOAgenda::dateList() const
1790{ 1842{
1791 return mSelectedDates; 1843 return mSelectedDates;
1792} 1844}
1793 1845
1794void KOAgenda::setDateList(const DateList &selectedDates) 1846void KOAgenda::setDateList(const DateList &selectedDates)
1795{ 1847{
1796 mSelectedDates = selectedDates; 1848 mSelectedDates = selectedDates;
1797 marcus_bains(); 1849 marcus_bains();
1798} 1850}
1799 1851
1800void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 1852void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
1801{ 1853{
1802 mHolidayMask = mask; 1854 mHolidayMask = mask;
1803 1855
1804/* 1856/*
1805 kdDebug() << "HolidayMask: "; 1857 kdDebug() << "HolidayMask: ";
1806 for(uint i=0;i<mask->count();++i) { 1858 for(uint i=0;i<mask->count();++i) {
1807 kdDebug() << (mask->at(i) ? "*" : "o"); 1859 kdDebug() << (mask->at(i) ? "*" : "o");
1808 } 1860 }
1809 kdDebug() << endl; 1861 kdDebug() << endl;
1810*/ 1862*/
1811} 1863}
1812 1864
1813void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 1865void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
1814{ 1866{
1815 1867
1816 QScrollView::contentsMousePressEvent(event); 1868 QScrollView::contentsMousePressEvent(event);
1817} 1869}
1818 1870
1819void KOAgenda::storePosition() 1871void KOAgenda::storePosition()
1820{ 1872{
1821 //mContentPosition 1873 //mContentPosition
1822 int max = mGridSpacingY*4*24; 1874 int max = mGridSpacingY*4*24;
1823 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 1875 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
1824 mContentPosition = 0; 1876 mContentPosition = 0;
1825 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 1877 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
1826 mContentPosition = -1.0; 1878 mContentPosition = -1.0;
1827 else 1879 else
1828 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 1880 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
1829 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 1881 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
1830 1882
1831} 1883}
1832void KOAgenda::restorePosition() 1884void KOAgenda::restorePosition()
1833{ 1885{
1834 int posY; 1886 int posY;
1835 int max = mGridSpacingY*4*24; 1887 int max = mGridSpacingY*4*24;
1836 if ( mContentPosition < 0 ) 1888 if ( mContentPosition < 0 )
1837 posY = max-viewport()->height(); 1889 posY = max-viewport()->height();
1838 else 1890 else
1839 if ( mContentPosition == 0 ) 1891 if ( mContentPosition == 0 )
1840 posY = 0; 1892 posY = 0;
1841 else 1893 else
1842 posY = (max/mContentPosition)-(viewport()->height()/2); 1894 posY = (max/mContentPosition)-(viewport()->height()/2);
1843 setContentsPos (0, posY ); 1895 setContentsPos (0, posY );
1844 //qDebug("posY %d hei %d", posY, max); 1896 //qDebug("posY %d hei %d", posY, max);
1845 1897
1846} 1898}
1847void KOAgenda::moveChild( QWidget *w, int x , int y ) 1899void KOAgenda::moveChild( QWidget *w, int x , int y )
1848{ 1900{
1849 ++x; 1901 ++x;
1850 QScrollView::moveChild( w, x , y ); 1902 QScrollView::moveChild( w, x , y );
1851} 1903}
1852#include <qmessagebox.h> 1904#include <qmessagebox.h>
1853#ifdef DESKTOP_VERSION 1905#ifdef DESKTOP_VERSION
1854#include <qprinter.h> 1906#include <qprinter.h>
1855#include <qpainter.h> 1907#include <qpainter.h>
1856#include <qpaintdevicemetrics.h> 1908#include <qpaintdevicemetrics.h>
1857 1909
1858#endif 1910#endif
1859void KOAgenda::printSelection() 1911void KOAgenda::printSelection()
1860{ 1912{
1861#ifdef DESKTOP_VERSION 1913#ifdef DESKTOP_VERSION
1862 if ( mStartCellY == mCurrentCellY ) { 1914 if ( mStartCellY == mCurrentCellY ) {
1863 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1915 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1864 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), 1916 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "),
1865 i18n("OK"), 0, 0, 1917 i18n("OK"), 0, 0,
1866 0, 1 ); 1918 0, 1 );
1867 return; 1919 return;
1868 } 1920 }
1869 1921
1870 float dx, dy; 1922 float dx, dy;
1871 int x,y,w,h; 1923 int x,y,w,h;
1872 x= 0; 1924 x= 0;
1873 w= contentsWidth()+2; 1925 w= contentsWidth()+2;
1874 // h= contentsHeight(); 1926 // h= contentsHeight();
1875 y = mGridSpacingY*mStartCellY; 1927 y = mGridSpacingY*mStartCellY;
1876 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 1928 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
1877 1929
1878 //return; 1930 //return;
1879 QPrinter* printer = new QPrinter(); 1931 QPrinter* printer = new QPrinter();
1880 if ( !printer->setup()) { 1932 if ( !printer->setup()) {
1881 delete printer; 1933 delete printer;
1882 return; 1934 return;
1883 } 1935 }
1884 QPainter p( printer ); 1936 QPainter p( printer );
1885 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 1937 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
1886 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 1938 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
1887 date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 1939 date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
1888 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 1940 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
1889 // p.drawText( 0, 0, date ); 1941 // p.drawText( 0, 0, date );
1890 int offset = m.width()/8; 1942 int offset = m.width()/8;
1891 // compute the scale 1943 // compute the scale
1892 dx = ((float) m.width()-offset) / (float)w; 1944 dx = ((float) m.width()-offset) / (float)w;
1893 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 1945 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
1894 float scale; 1946 float scale;
1895 // scale to fit the width or height of the paper 1947 // scale to fit the width or height of the paper
1896 if ( dx < dy ) 1948 if ( dx < dy )
1897 scale = dx; 1949 scale = dx;
1898 else 1950 else
1899 scale = dy; 1951 scale = dy;
1900 // set the scale 1952 // set the scale
1901 p.drawText( offset* scale, offset* scale*3/4, date ); 1953 p.drawText( offset* scale, offset* scale*3/4, date );
1902 1954
1903 int selDay; 1955 int selDay;
1904 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 1956 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
1905 float startX = 1; 1957 float startX = 1;
1906 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1958 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1907 { 1959 {
1908 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 1960 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
1909 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 1961 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
1910 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 1962 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
1911 startX += widOffset; 1963 startX += widOffset;
1912 1964
1913 } 1965 }
1914 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 1966 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
1915 p.scale( scale, scale ); 1967 p.scale( scale, scale );
1916 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 1968 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
1917 // now printing with y offset: 2 hei 1969 // now printing with y offset: 2 hei
1918 // p.translate( 0, -y*scale); 1970 // p.translate( 0, -y*scale);
1919 1971
1920 drawContentsToPainter(&p, true ); 1972 drawContentsToPainter(&p, true );
1921 globalFlagBlockAgendaItemUpdate = false; 1973 globalFlagBlockAgendaItemUpdate = false;
1922 KOAgendaItem *item; 1974 KOAgendaItem *item;
1923 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1975 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1924 item->select(false); 1976 item->select(false);
1925 item->paintMe( false, &p ); 1977 item->paintMe( false, &p );
1926 } 1978 }
1927 globalFlagBlockAgendaItemUpdate = true; 1979 globalFlagBlockAgendaItemUpdate = true;
1928 p.end(); 1980 p.end();
1929 delete printer; 1981 delete printer;
1930#else 1982#else
1931 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1983 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1932 i18n("Not supported \non PDA!\n"), 1984 i18n("Not supported \non PDA!\n"),
1933 i18n("OK"), 0, 0, 1985 i18n("OK"), 0, 0,
1934 0, 1 ); 1986 0, 1 );
1935#endif 1987#endif
1936} 1988}
diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h
index 111242f..12943d7 100644
--- a/korganizer/koagenda.h
+++ b/korganizer/koagenda.h
@@ -1,286 +1,290 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 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#ifndef KOAGENDA_H 23#ifndef KOAGENDA_H
24#define KOAGENDA_H 24#define KOAGENDA_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qmemarray.h> 28#include <qmemarray.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qpixmap.h> 30#include <qpixmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33#include "koagendaitem.h" 33#include "koagendaitem.h"
34 34
35class QPopupMenu; 35class QPopupMenu;
36class QTime; 36class QTime;
37class KConfig; 37class KConfig;
38class QFrame; 38class QFrame;
39class KOAgenda; 39class KOAgenda;
40class KCal::Event; 40class KCal::Event;
41class KCal::Todo; 41class KCal::Todo;
42 42
43using namespace KCal; 43using namespace KCal;
44 44
45class MarcusBains : public QFrame { 45class MarcusBains : public QFrame {
46 Q_OBJECT 46 Q_OBJECT
47 public: 47 public:
48 MarcusBains(KOAgenda *agenda=0,const char *name=0); 48 MarcusBains(KOAgenda *agenda=0,const char *name=0);
49 virtual ~MarcusBains(); 49 virtual ~MarcusBains();
50 50
51 public slots: 51 public slots:
52 void updateLocation(bool recalculate=false); 52 void updateLocation(bool recalculate=false);
53 void updateLoc(); 53 void updateLoc();
54 54
55 private: 55 private:
56 int todayColumn(); 56 int todayColumn();
57 QTimer *minutes; 57 QTimer *minutes;
58 QLabel *mTimeBox; 58 QLabel *mTimeBox;
59 KOAgenda *agenda; 59 KOAgenda *agenda;
60 QTime oldTime; 60 QTime oldTime;
61 int oldToday; 61 int oldToday;
62}; 62};
63 63
64 64
65class KOAgenda : public QScrollView 65class KOAgenda : public QScrollView
66{ 66{
67 Q_OBJECT 67 Q_OBJECT
68 public: 68 public:
69 enum MouseActionType { NOP, MOVE, SELECT, 69 enum MouseActionType { NOP, MOVE, SELECT,
70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; 70 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
71 71
72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, 72 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0,
73 const char * name=0, WFlags f=0 ); 73 const char * name=0, WFlags f=0 );
74 KOAgenda ( int columns, QWidget * parent=0, 74 KOAgenda ( int columns, QWidget * parent=0,
75 const char * name=0, WFlags f=0 ); 75 const char * name=0, WFlags f=0 );
76 virtual ~KOAgenda(); 76 virtual ~KOAgenda();
77 77
78 Incidence *selectedIncidence() const; 78 Incidence *selectedIncidence() const;
79 QDate selectedIncidenceDate() const; 79 QDate selectedIncidenceDate() const;
80 80
81 virtual bool eventFilter ( QObject *, QEvent * ); 81 virtual bool eventFilter ( QObject *, QEvent * );
82 82
83 void contentsToGrid (int x, int y, int& gx, int& gy); 83 void contentsToGrid (int x, int y, int& gx, int& gy);
84 void gridToContents (int gx, int gy, int& x, int& y); 84 void gridToContents (int gx, int gy, int& x, int& y);
85 85
86 int timeToY (const QTime &time); 86 int timeToY (const QTime &time);
87 QTime gyToTime (int y); 87 QTime gyToTime (int y);
88 88
89 void setStartHour(int startHour); 89 void setStartHour(int startHour);
90 90
91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); 91 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom);
92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); 92 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd);
93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 93 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
94 int YTop,int YBottom); 94 int YTop,int YBottom);
95 95
96 void changeColumns(int columns); 96 void changeColumns(int columns);
97 97
98 int columns() { return mColumns; } 98 int columns() { return mColumns; }
99 int rows() { return mRows; } 99 int rows() { return mRows; }
100 100
101 int gridSpacingX() const { return mGridSpacingX; } 101 int gridSpacingX() const { return mGridSpacingX; }
102 int gridSpacingY() const { return mGridSpacingY; } 102 int gridSpacingY() const { return mGridSpacingY; }
103 103
104// virtual QSizePolicy sizePolicy() const; 104// virtual QSizePolicy sizePolicy() const;
105 105
106 void clear(); 106 void clear();
107 107
108 void clearSelection(); 108 void clearSelection();
109 void hideUnused(); 109 void hideUnused();
110 110
111 /** Calculates the minimum width */ 111 /** Calculates the minimum width */
112 virtual int minimumWidth() const; 112 virtual int minimumWidth() const;
113 /** Update configuration from preference settings */ 113 /** Update configuration from preference settings */
114 void updateConfig(); 114 void updateConfig();
115 115
116 void checkScrollBoundaries(); 116 void checkScrollBoundaries();
117 117
118 void setHolidayMask(QMemArray<bool> *); 118 void setHolidayMask(QMemArray<bool> *);
119 void setDateList(const DateList &selectedDates); 119 void setDateList(const DateList &selectedDates);
120 DateList dateList() const; 120 DateList dateList() const;
121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); 121 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false);
122 void finishUpdate(); 122 void finishUpdate();
123 void printSelection(); 123 void printSelection();
124 void storePosition(); 124 void storePosition();
125 void restorePosition(); 125 void restorePosition();
126 126
127 127
128 public slots: 128 public slots:
129 void newItem( int );
129 void moveChild( QWidget *, int, int ); 130 void moveChild( QWidget *, int, int );
130 void scrollUp(); 131 void scrollUp();
131 void scrollDown(); 132 void scrollDown();
132 void updateTodo( Todo * t, int , bool ); 133 void updateTodo( Todo * t, int , bool );
133 void popupAlarm(); 134 void popupAlarm();
134 135
135 void checkScrollBoundaries(int); 136 void checkScrollBoundaries(int);
136 137
137 /** Deselect selected items. This function does not emit any signals. */ 138 /** Deselect selected items. This function does not emit any signals. */
138 void deselectItem(); 139 void deselectItem();
139 /** Select item. If the argument is 0, the currently selected item gets 140 /** Select item. If the argument is 0, the currently selected item gets
140 deselected. This function emits the itemSelected(bool) signal to inform 141 deselected. This function emits the itemSelected(bool) signal to inform
141 about selection/deseelction of events. */ 142 about selection/deseelction of events. */
142 void selectItem(KOAgendaItem *); 143 void selectItem(KOAgendaItem *);
143 void finishResize(); 144 void finishResize();
144 145
145 signals: 146 signals:
146 void newEventSignal(); 147 void newEventSignal();
147 void newEventSignal(int gx,int gy); 148 void newEventSignal(int gx,int gy);
149 void newTodoSignal(int gx,int gy);
148 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 150 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
149 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 151 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
150 void newStartSelectSignal(); 152 void newStartSelectSignal();
151 void showIncidenceSignal(Incidence *); 153 void showIncidenceSignal(Incidence *);
152 void editIncidenceSignal(Incidence *); 154 void editIncidenceSignal(Incidence *);
153 void deleteIncidenceSignal(Incidence *); 155 void deleteIncidenceSignal(Incidence *);
154 void showIncidencePopupSignal(Incidence *); 156 void showIncidencePopupSignal(Incidence *);
155 157
156 void itemModified(KOAgendaItem *item, int ); 158 void itemModified(KOAgendaItem *item, int );
157 void incidenceSelected(Incidence *); 159 void incidenceSelected(Incidence *);
158 160
159 void lowerYChanged(int); 161 void lowerYChanged(int);
160 void upperYChanged(int); 162 void upperYChanged(int);
161 163
162 void startDragSignal(Incidence *); 164 void startDragSignal(Incidence *);
163 void addToCalSignal(Incidence *, Incidence *); 165 void addToCalSignal(Incidence *, Incidence *);
164 void resizedSignal(); 166 void resizedSignal();
165 167
166 protected: 168 protected:
167 QPainter mPixPainter; 169 QPainter mPixPainter;
168 QPixmap mPaintPixmap; 170 QPixmap mPaintPixmap;
169 QPixmap mHighlightPixmap; 171 QPixmap mHighlightPixmap;
170 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 172 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
171 virtual void resizeEvent ( QResizeEvent * ); 173 virtual void resizeEvent ( QResizeEvent * );
172 174
173 /** Handles mouse events. Called from eventFilter */ 175 /** Handles mouse events. Called from eventFilter */
174 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); 176 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
175 177
176 /** Start selecting time span. */ 178 /** Start selecting time span. */
177 void startSelectAction(QPoint viewportPos); 179 void startSelectAction(QPoint viewportPos);
178 180
179 /** Select time span. */ 181 /** Select time span. */
180 void performSelectAction(QPoint viewportPos); 182 void performSelectAction(QPoint viewportPos);
181 183
182 /** Emd selecting time span. */ 184 /** Emd selecting time span. */
183 void endSelectAction(); 185 void endSelectAction( bool emitNewEvent = false );
184 186
185 /** Start moving/resizing agenda item */ 187 /** Start moving/resizing agenda item */
186 void startItemAction(QPoint viewportPos); 188 void startItemAction(QPoint viewportPos);
187 189
188 /** Move/resize agenda item */ 190 /** Move/resize agenda item */
189 void performItemAction(QPoint viewportPos); 191 void performItemAction(QPoint viewportPos);
190 192
191 /** End moving/resizing agenda item */ 193 /** End moving/resizing agenda item */
192 void endItemAction(); 194 void endItemAction();
193 195
194 /** Set cursor, when no item action is in progress */ 196 /** Set cursor, when no item action is in progress */
195 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); 197 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos);
196 198
197 /** Place agenda item in agenda and adjust other cells if necessary */ 199 /** Place agenda item in agenda and adjust other cells if necessary */
198 void placeSubCells(KOAgendaItem *placeItem); 200 void placeSubCells(KOAgendaItem *placeItem);
199 201
200 /** Process the keyevent, including the ignored keyevents of eventwidgets. 202 /** Process the keyevent, including the ignored keyevents of eventwidgets.
201 * Implements pgup/pgdn and cursor key navigation in the view. 203 * Implements pgup/pgdn and cursor key navigation in the view.
202 */ 204 */
203 void keyPressEvent( QKeyEvent * ); 205 void keyPressEvent( QKeyEvent * );
204 206
205 void calculateWorkingHours(); 207 void calculateWorkingHours();
206 208
207 virtual void contentsMousePressEvent ( QMouseEvent * ); 209 virtual void contentsMousePressEvent ( QMouseEvent * );
208 210
209 private: 211 private:
212 bool blockNewEvent;
210 void init(); 213 void init();
211 void marcus_bains(); 214 void marcus_bains();
212 bool mAllDayMode; 215 bool mAllDayMode;
213 bool blockResize; 216 bool blockResize;
214 QTimer mResizeTimer; 217 QTimer mResizeTimer;
215 double mContentPosition; 218 double mContentPosition;
216 219
217 // Width and height of agenda cells 220 // Width and height of agenda cells
218 int mGridSpacingX; 221 int mGridSpacingX;
219 int mGridSpacingY; 222 int mGridSpacingY;
220 223
221 // size of border, where mouse action will resize the KOAgendaItem 224 // size of border, where mouse action will resize the KOAgendaItem
222 int mResizeBorderWidth; 225 int mResizeBorderWidth;
223 226
224 // size of border, where mouse mve will cause a scroll of the agenda 227 // size of border, where mouse mve will cause a scroll of the agenda
225 int mScrollBorderWidth; 228 int mScrollBorderWidth;
226 int mScrollDelay; 229 int mScrollDelay;
227 int mScrollOffset; 230 int mScrollOffset;
228 231
229 QTimer mScrollUpTimer; 232 QTimer mScrollUpTimer;
230 QTimer mScrollDownTimer; 233 QTimer mScrollDownTimer;
231 234
232 // Number of Columns/Rows of agenda grid 235 // Number of Columns/Rows of agenda grid
233 int mColumns; 236 int mColumns;
234 int mRows; 237 int mRows;
235 238
236 // Cells to store Move and Resize coordiantes 239 // Cells to store Move and Resize coordiantes
237 int mStartCellX; 240 int mStartCellX;
238 int mStartCellY; 241 int mStartCellY;
239 int mCurrentCellX; 242 int mCurrentCellX;
240 int mCurrentCellY; 243 int mCurrentCellY;
241 244
242 // Working Hour coordiantes 245 // Working Hour coordiantes
243 bool mWorkingHoursEnable; 246 bool mWorkingHoursEnable;
244 int mWorkingHoursYTop; 247 int mWorkingHoursYTop;
245 int mWorkingHoursYBottom; 248 int mWorkingHoursYBottom;
246 249
247 // Selection 250 // Selection
248 int mSelectionCellX; 251 int mSelectionCellX;
249 int mSelectionYTop; 252 int mSelectionYTop;
250 int mSelectionHeight; 253 int mSelectionHeight;
251 254
252 // List of dates to be displayed 255 // List of dates to be displayed
253 DateList mSelectedDates; 256 DateList mSelectedDates;
254 257
255 // The KOAgendaItem, which has been right-clicked last 258 // The KOAgendaItem, which has been right-clicked last
256 KOAgendaItem *mClickedItem; 259 KOAgendaItem *mClickedItem;
257 260
258 // The KOAgendaItem, which is being moved/resized 261 // The KOAgendaItem, which is being moved/resized
259 QGuardedPtr<KOAgendaItem> mActionItem; 262 QGuardedPtr<KOAgendaItem> mActionItem;
260 263
261 // Currently selected item 264 // Currently selected item
262 QGuardedPtr<KOAgendaItem> mSelectedItem; 265 QGuardedPtr<KOAgendaItem> mSelectedItem;
263 266
264 // The Marcus Bains Line widget. 267 // The Marcus Bains Line widget.
265 MarcusBains *mMarcusBains; 268 MarcusBains *mMarcusBains;
266 void computeSizes(); 269 void computeSizes();
267 270
268 MouseActionType mActionType; 271 MouseActionType mActionType;
269 272
270 bool mItemMoved; 273 bool mItemMoved;
271 274
272 // List of all Items contained in agenda 275 // List of all Items contained in agenda
273 QPtrList<KOAgendaItem> mItems; 276 QPtrList<KOAgendaItem> mItems;
274 QPtrList<KOAgendaItem> mUnusedItems; 277 QPtrList<KOAgendaItem> mUnusedItems;
275 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); 278 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport);
276 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems 279 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
280 QPopupMenu *mNewItemPopup;
277 281
278 int mOldLowerScrollValue; 282 int mOldLowerScrollValue;
279 int mOldUpperScrollValue; 283 int mOldUpperScrollValue;
280 KOAgendaItem * getItemForTodo ( Todo * todo ); 284 KOAgendaItem * getItemForTodo ( Todo * todo );
281 QMemArray<bool> *mHolidayMask; 285 QMemArray<bool> *mHolidayMask;
282 int mCurPixWid; 286 int mCurPixWid;
283 int mCurPixHei; 287 int mCurPixHei;
284}; 288};
285 289
286#endif // KOAGENDA_H 290#endif // KOAGENDA_H
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index f54f7bc..60ae41f 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,1511 +1,1530 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 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 <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
59#include "kocore.h" 59#include "kocore.h"
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 79TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
80 QScrollView(parent,name,f) 80 QScrollView(parent,name,f)
81{ 81{
82 mRows = rows; 82 mRows = rows;
83 83
84 setMinimumHeight( 20 ); 84 setMinimumHeight( 20 );
85 mCellHeight = KOPrefs::instance()->mHourSize*4; 85 mCellHeight = KOPrefs::instance()->mHourSize*4;
86 86
87 enableClipper(true); 87 enableClipper(true);
88 88
89 setHScrollBarMode(AlwaysOff); 89 setHScrollBarMode(AlwaysOff);
90 setVScrollBarMode(AlwaysOff); 90 setVScrollBarMode(AlwaysOff);
91 91
92 resizeContents(50,mRows * mCellHeight); 92 resizeContents(50,mRows * mCellHeight);
93 93
94 viewport()->setBackgroundMode( PaletteBackground ); 94 viewport()->setBackgroundMode( PaletteBackground );
95} 95}
96 96
97void TimeLabels::setCellHeight(int height) 97void TimeLabels::setCellHeight(int height)
98{ 98{
99 mCellHeight = height; 99 mCellHeight = height;
100} 100}
101 101
102/* 102/*
103 Optimization so that only the "dirty" portion of the scroll view 103 Optimization so that only the "dirty" portion of the scroll view
104 is redrawn. Unfortunately, this is not called by default paintEvent() method. 104 is redrawn. Unfortunately, this is not called by default paintEvent() method.
105*/ 105*/
106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 106void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
107{ 107{
108 108
109 // if ( globalFlagBlockAgenda ) 109 // if ( globalFlagBlockAgenda )
110 // return; 110 // return;
111 // bug: the parameters cx, cy, cw, ch are the areas that need to be 111 // bug: the parameters cx, cy, cw, ch are the areas that need to be
112 // redrawn, not the area of the widget. unfortunately, this 112 // redrawn, not the area of the widget. unfortunately, this
113 // code assumes the latter... 113 // code assumes the latter...
114 114
115 // now, for a workaround... 115 // now, for a workaround...
116 // these two assignments fix the weird redraw bug 116 // these two assignments fix the weird redraw bug
117 cx = contentsX() + 2; 117 cx = contentsX() + 2;
118 cw = contentsWidth() - 2; 118 cw = contentsWidth() - 2;
119 // end of workaround 119 // end of workaround
120 120
121 int cell = ((int)(cy/mCellHeight)); 121 int cell = ((int)(cy/mCellHeight));
122 int y = cell * mCellHeight; 122 int y = cell * mCellHeight;
123 QFontMetrics fm = fontMetrics(); 123 QFontMetrics fm = fontMetrics();
124 QString hour; 124 QString hour;
125 QString suffix; 125 QString suffix;
126 QString fullTime; 126 QString fullTime;
127 int tW = fm.width("24:00i"); 127 int tW = fm.width("24:00i");
128 128
129 while (y < cy + ch) { 129 while (y < cy + ch) {
130 p->drawLine(cx,y,cx+tW,y); 130 p->drawLine(cx,y,cx+tW,y);
131 hour.setNum(cell); 131 hour.setNum(cell);
132 suffix = "am"; 132 suffix = "am";
133 133
134 // handle 24h and am/pm time formats 134 // handle 24h and am/pm time formats
135 if (KGlobal::locale()->use12Clock()) { 135 if (KGlobal::locale()->use12Clock()) {
136 if (cell > 11) suffix = "pm"; 136 if (cell > 11) suffix = "pm";
137 if (cell == 0) hour.setNum(12); 137 if (cell == 0) hour.setNum(12);
138 if (cell > 12) hour.setNum(cell - 12); 138 if (cell > 12) hour.setNum(cell - 12);
139 } else { 139 } else {
140 suffix = ":00"; 140 suffix = ":00";
141 } 141 }
142 142
143 // create string in format of "XX:XX" or "XXpm/am" 143 // create string in format of "XX:XX" or "XXpm/am"
144 fullTime = hour + suffix; 144 fullTime = hour + suffix;
145 145
146 // center and draw the time label 146 // center and draw the time label
147 int timeWidth = fm.width(fullTime+"i"); 147 int timeWidth = fm.width(fullTime+"i");
148 int offset = this->width() - timeWidth; 148 int offset = this->width() - timeWidth;
149 int borderWidth = 5; 149 int borderWidth = 5;
150 int timeHeight = fm.height(); 150 int timeHeight = fm.height();
151 timeHeight = timeHeight + 2 - ( timeHeight / 4 ); 151 timeHeight = timeHeight + 2 - ( timeHeight / 4 );
152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime); 152 p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime);
153 153
154 // increment indices 154 // increment indices
155 y += mCellHeight; 155 y += mCellHeight;
156 cell++; 156 cell++;
157 } 157 }
158} 158}
159 159
160/** 160/**
161 Calculates the minimum width. 161 Calculates the minimum width.
162*/ 162*/
163int TimeLabels::minimumWidth() const 163int TimeLabels::minimumWidth() const
164{ 164{
165 QFontMetrics fm = fontMetrics(); 165 QFontMetrics fm = fontMetrics();
166 166
167 //TODO: calculate this value 167 //TODO: calculate this value
168 int borderWidth = 4; 168 int borderWidth = 4;
169 169
170 // the maximum width possible 170 // the maximum width possible
171 int width = fm.width("88:88x") + borderWidth; 171 int width = fm.width("88:88x") + borderWidth;
172 172
173 return width; 173 return width;
174} 174}
175 175
176/** updates widget's internal state */ 176/** updates widget's internal state */
177void TimeLabels::updateConfig() 177void TimeLabels::updateConfig()
178{ 178{
179 // set the font 179 // set the font
180 // config->setGroup("Fonts"); 180 // config->setGroup("Fonts");
181 // QFont font = config->readFontEntry("TimeBar Font"); 181 // QFont font = config->readFontEntry("TimeBar Font");
182 setFont(KOPrefs::instance()->mTimeBarFont); 182 setFont(KOPrefs::instance()->mTimeBarFont);
183 183
184 // update geometry restrictions based on new settings 184 // update geometry restrictions based on new settings
185 setFixedWidth(minimumWidth()); 185 setFixedWidth(minimumWidth());
186 186
187 // update HourSize 187 // update HourSize
188 mCellHeight = KOPrefs::instance()->mHourSize*4; 188 mCellHeight = KOPrefs::instance()->mHourSize*4;
189 resizeContents(50,mRows * mCellHeight); 189 resizeContents(50,mRows * mCellHeight);
190} 190}
191 191
192/** update time label positions */ 192/** update time label positions */
193void TimeLabels::positionChanged() 193void TimeLabels::positionChanged()
194{ 194{
195 int adjustment = mAgenda->contentsY(); 195 int adjustment = mAgenda->contentsY();
196 setContentsPos(0, adjustment); 196 setContentsPos(0, adjustment);
197} 197}
198 198
199/** */ 199/** */
200void TimeLabels::setAgenda(KOAgenda* agenda) 200void TimeLabels::setAgenda(KOAgenda* agenda)
201{ 201{
202 mAgenda = agenda; 202 mAgenda = agenda;
203} 203}
204 204
205void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 205void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
206{ 206{
207 mMouseDownY = e->pos().y(); 207 mMouseDownY = e->pos().y();
208 mOrgCap = topLevelWidget()->caption(); 208 mOrgCap = topLevelWidget()->caption();
209} 209}
210 210
211void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 211void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
212{ 212{
213 int diff = mMouseDownY - e->pos().y(); 213 int diff = mMouseDownY - e->pos().y();
214 if ( diff < 10 && diff > -10 ) 214 if ( diff < 10 && diff > -10 )
215 return; 215 return;
216 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 216 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
217 if ( tSize < 4 ) 217 if ( tSize < 4 )
218 tSize = 4; 218 tSize = 4;
219 if ( tSize > 22 ) 219 if ( tSize > 22 )
220 tSize = 22; 220 tSize = 22;
221 tSize = (tSize-2)/2; 221 tSize = (tSize-2)/2;
222 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 222 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
223 223
224} 224}
225void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 225void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
226{ 226{
227 topLevelWidget()->setCaption( mOrgCap ); 227 topLevelWidget()->setCaption( mOrgCap );
228 int diff = mMouseDownY - e->pos().y(); 228 int diff = mMouseDownY - e->pos().y();
229 if ( diff < 10 && diff > -10 ) 229 if ( diff < 10 && diff > -10 )
230 return; 230 return;
231 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 231 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
232 if ( tSize < 4 ) 232 if ( tSize < 4 )
233 tSize = 4; 233 tSize = 4;
234 if ( tSize > 22 ) 234 if ( tSize > 22 )
235 tSize = 22; 235 tSize = 22;
236 tSize = (tSize/2)*2; 236 tSize = (tSize/2)*2;
237 if ( tSize == KOPrefs::instance()->mHourSize ) 237 if ( tSize == KOPrefs::instance()->mHourSize )
238 return; 238 return;
239 KOPrefs::instance()->mHourSize = tSize; 239 KOPrefs::instance()->mHourSize = tSize;
240 emit scaleChanged(); 240 emit scaleChanged();
241} 241}
242 242
243/** This is called in response to repaint() */ 243/** This is called in response to repaint() */
244void TimeLabels::paintEvent(QPaintEvent*) 244void TimeLabels::paintEvent(QPaintEvent*)
245{ 245{
246 246
247 // kdDebug() << "paintevent..." << endl; 247 // kdDebug() << "paintevent..." << endl;
248 // this is another hack! 248 // this is another hack!
249 // QPainter painter(this); 249 // QPainter painter(this);
250 //QString c 250 //QString c
251 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 251 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
252} 252}
253 253
254//////////////////////////////////////////////////////////////////////////// 254////////////////////////////////////////////////////////////////////////////
255 255
256EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 256EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
257 : QFrame(parent,name) 257 : QFrame(parent,name)
258{ 258{
259 mColumns = 1; 259 mColumns = 1;
260 mTopBox = 0; 260 mTopBox = 0;
261 mLocation = loc; 261 mLocation = loc;
262 mTopLayout = 0; 262 mTopLayout = 0;
263 mPaintWidget = 0; 263 mPaintWidget = 0;
264 mXOffset = 0; 264 mXOffset = 0;
265 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 265 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
266 else mPixmap = SmallIcon("1downarrow"); 266 else mPixmap = SmallIcon("1downarrow");
267 mEnabled.resize(mColumns); 267 mEnabled.resize(mColumns);
268 if (mLocation == Top) 268 if (mLocation == Top)
269 setMaximumHeight(0); 269 setMaximumHeight(0);
270 else 270 else
271 setMinimumHeight(mPixmap.height()); 271 setMinimumHeight(mPixmap.height());
272} 272}
273 273
274EventIndicator::~EventIndicator() 274EventIndicator::~EventIndicator()
275{ 275{
276} 276}
277 277
278void EventIndicator::drawContents(QPainter *p) 278void EventIndicator::drawContents(QPainter *p)
279{ 279{
280 280
281 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; 281 // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
282 KDGanttSplitterHandle* han = 0; 282 KDGanttSplitterHandle* han = 0;
283 if ( mPaintWidget ) 283 if ( mPaintWidget )
284 han = mPaintWidget->firstHandle(); 284 han = mPaintWidget->firstHandle();
285 if ( ! han ) { 285 if ( ! han ) {
286 int i; 286 int i;
287 for(i=0;i<mColumns;++i) { 287 for(i=0;i<mColumns;++i) {
288 if (mEnabled[i]) { 288 if (mEnabled[i]) {
289 int cellWidth = contentsRect().right()/mColumns; 289 int cellWidth = contentsRect().right()/mColumns;
290 int xOffset = KOGlobals::self()->reverseLayout() ? 290 int xOffset = KOGlobals::self()->reverseLayout() ?
291 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 291 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
292 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 292 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
293 p->drawPixmap(QPoint(xOffset,0),mPixmap); 293 p->drawPixmap(QPoint(xOffset,0),mPixmap);
294 } 294 }
295 } 295 }
296 } else { 296 } else {
297 han->repaint(); 297 han->repaint();
298 //mPaintWidget->setBackgroundColor( red ); 298 //mPaintWidget->setBackgroundColor( red );
299 299
300 QPainter pa( han ); 300 QPainter pa( han );
301 int i; 301 int i;
302 bool setColor = false; 302 bool setColor = false;
303 for(i=0;i<mColumns;++i) { 303 for(i=0;i<mColumns;++i) {
304 if (mEnabled[i]) { 304 if (mEnabled[i]) {
305 setColor = true; 305 setColor = true;
306 306
307 int cellWidth = contentsRect().right()/mColumns; 307 int cellWidth = contentsRect().right()/mColumns;
308 int xOffset = KOGlobals::self()->reverseLayout() ? 308 int xOffset = KOGlobals::self()->reverseLayout() ?
309 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : 309 (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
310 i*cellWidth + cellWidth/2 -mPixmap.width()/2; 310 i*cellWidth + cellWidth/2 -mPixmap.width()/2;
311 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); 311 pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
312 //qDebug("222draw pix %d ",xOffset ); 312 //qDebug("222draw pix %d ",xOffset );
313 313
314 } 314 }
315 315
316 } 316 }
317 pa.end(); 317 pa.end();
318 318
319 } 319 }
320} 320}
321 321
322void EventIndicator::setXOffset( int x ) 322void EventIndicator::setXOffset( int x )
323{ 323{
324 mXOffset = x; 324 mXOffset = x;
325} 325}
326void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) 326void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
327{ 327{
328 mPaintWidget = w; 328 mPaintWidget = w;
329} 329}
330void EventIndicator::changeColumns(int columns) 330void EventIndicator::changeColumns(int columns)
331{ 331{
332 mColumns = columns; 332 mColumns = columns;
333 mEnabled.resize(mColumns); 333 mEnabled.resize(mColumns);
334 334
335 update(); 335 update();
336} 336}
337 337
338void EventIndicator::enableColumn(int column, bool enable) 338void EventIndicator::enableColumn(int column, bool enable)
339{ 339{
340 mEnabled[column] = enable; 340 mEnabled[column] = enable;
341} 341}
342 342
343 343
344//////////////////////////////////////////////////////////////////////////// 344////////////////////////////////////////////////////////////////////////////
345//////////////////////////////////////////////////////////////////////////// 345////////////////////////////////////////////////////////////////////////////
346//////////////////////////////////////////////////////////////////////////// 346////////////////////////////////////////////////////////////////////////////
347 347
348KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : 348KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
349 KOEventView (cal,parent,name) 349 KOEventView (cal,parent,name)
350{ 350{
351 mBlockUpdating = true; 351 mBlockUpdating = true;
352 mStartHour = 8; 352 mStartHour = 8;
353 mSelectedDates.append(QDate::currentDate()); 353 mSelectedDates.append(QDate::currentDate());
354 354
355 mLayoutDayLabels = 0; 355 mLayoutDayLabels = 0;
356 mDayLabelsFrame = 0; 356 mDayLabelsFrame = 0;
357 mDayLabels = 0; 357 mDayLabels = 0;
358 bool isRTL = KOGlobals::self()->reverseLayout(); 358 bool isRTL = KOGlobals::self()->reverseLayout();
359 359
360 if ( KOPrefs::instance()->mVerticalScreen ) { 360 if ( KOPrefs::instance()->mVerticalScreen ) {
361 mExpandedPixmap = SmallIcon( "1downarrow" ); 361 mExpandedPixmap = SmallIcon( "1downarrow" );
362 mNotExpandedPixmap = SmallIcon( "1uparrow" ); 362 mNotExpandedPixmap = SmallIcon( "1uparrow" );
363 } else { 363 } else {
364 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" ); 364 mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
365 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" ); 365 mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
366 } 366 }
367 367
368 QBoxLayout *topLayout = new QVBoxLayout(this); 368 QBoxLayout *topLayout = new QVBoxLayout(this);
369 369
370 // Create day name labels for agenda columns 370 // Create day name labels for agenda columns
371 mDayLabelsFrame = new QHBox(this); 371 mDayLabelsFrame = new QHBox(this);
372 topLayout->addWidget(mDayLabelsFrame); 372 topLayout->addWidget(mDayLabelsFrame);
373 mDayLabels = new QFrame (mDayLabelsFrame); 373 mDayLabels = new QFrame (mDayLabelsFrame);
374 mLayoutDayLabels = new QHBoxLayout(mDayLabels); 374 mLayoutDayLabels = new QHBoxLayout(mDayLabels);
375 // Create agenda splitter 375 // Create agenda splitter
376#ifndef KORG_NOSPLITTER 376#ifndef KORG_NOSPLITTER
377 mSplitterAgenda = new QSplitter(Vertical,this); 377 mSplitterAgenda = new QSplitter(Vertical,this);
378 topLayout->addWidget(mSplitterAgenda); 378 topLayout->addWidget(mSplitterAgenda);
379 mSplitterAgenda->setOpaqueResize(); 379 mSplitterAgenda->setOpaqueResize();
380 380
381 mAllDayFrame = new QHBox(mSplitterAgenda); 381 mAllDayFrame = new QHBox(mSplitterAgenda);
382 382
383 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 383 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
384#else 384#else
385#if 0 385#if 0
386 QWidget *mainBox = new QWidget( this ); 386 QWidget *mainBox = new QWidget( this );
387 topLayout->addWidget( mainBox ); 387 topLayout->addWidget( mainBox );
388 QBoxLayout *mainLayout = new QVBoxLayout(mainBox); 388 QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
389 mAllDayFrame = new QHBox(mainBox); 389 mAllDayFrame = new QHBox(mainBox);
390 mainLayout->addWidget(mAllDayFrame); 390 mainLayout->addWidget(mAllDayFrame);
391 mainLayout->setStretchFactor( mAllDayFrame, 0 ); 391 mainLayout->setStretchFactor( mAllDayFrame, 0 );
392 mAllDayFrame->setFocusPolicy(NoFocus); 392 mAllDayFrame->setFocusPolicy(NoFocus);
393 QWidget *agendaFrame = new QWidget(mainBox); 393 QWidget *agendaFrame = new QWidget(mainBox);
394 mainLayout->addWidget(agendaFrame); 394 mainLayout->addWidget(agendaFrame);
395 mainLayout->setStretchFactor( agendaFrame, 10 ); 395 mainLayout->setStretchFactor( agendaFrame, 10 );
396 396
397 agendaFrame->setFocusPolicy(NoFocus); 397 agendaFrame->setFocusPolicy(NoFocus);
398#endif 398#endif
399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); 399 mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 400 mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
401 topLayout->addWidget( mSplitterAgenda ); 401 topLayout->addWidget( mSplitterAgenda );
402 mAllDayFrame = new QHBox(mSplitterAgenda); 402 mAllDayFrame = new QHBox(mSplitterAgenda);
403 mAllDayFrame->setFocusPolicy(NoFocus); 403 mAllDayFrame->setFocusPolicy(NoFocus);
404 QWidget *agendaFrame = new QWidget(mSplitterAgenda); 404 QWidget *agendaFrame = new QWidget(mSplitterAgenda);
405 agendaFrame->setFocusPolicy(NoFocus); 405 agendaFrame->setFocusPolicy(NoFocus);
406 406
407#endif 407#endif
408 408
409 // Create all-day agenda widget 409 // Create all-day agenda widget
410 mDummyAllDayLeft = new QVBox( mAllDayFrame ); 410 mDummyAllDayLeft = new QVBox( mAllDayFrame );
411 411
412 mExpandButton = new QPushButton(mDummyAllDayLeft); 412 mExpandButton = new QPushButton(mDummyAllDayLeft);
413 mExpandButton->setPixmap( mNotExpandedPixmap ); 413 mExpandButton->setPixmap( mNotExpandedPixmap );
414 int widebut = mExpandButton->sizeHint().width(); 414 int widebut = mExpandButton->sizeHint().width();
415 if ( QApplication::desktop()->width() < 480 ) 415 if ( QApplication::desktop()->width() < 480 )
416 widebut = widebut*2; 416 widebut = widebut*2;
417 else 417 else
418 widebut = (widebut*3) / 2; 418 widebut = (widebut*3) / 2;
419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, 419 //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
420 // QSizePolicy::Fixed ) ); 420 // QSizePolicy::Fixed ) );
421 mExpandButton->setFixedSize( widebut, widebut); 421 mExpandButton->setFixedSize( widebut, widebut);
422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); 422 connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
423 mExpandButton->setFocusPolicy(NoFocus); 423 mExpandButton->setFocusPolicy(NoFocus);
424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame); 424 mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
425 mAllDayAgenda->setFocusPolicy(NoFocus); 425 mAllDayAgenda->setFocusPolicy(NoFocus);
426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame); 426 QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
427 427
428 // Create event context menu for all day agenda 428 // Create event context menu for all day agenda
429 mAllDayAgendaPopup = eventPopup(); 429 mAllDayAgendaPopup = eventPopup();
430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 430 connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 431 mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
432 432
433 // Create agenda frame 433 // Create agenda frame
434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3); 434 QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
435 // QHBox *agendaFrame = new QHBox(splitterAgenda); 435 // QHBox *agendaFrame = new QHBox(splitterAgenda);
436 436
437 // create event indicator bars 437 // create event indicator bars
438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); 438 mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
439 agendaLayout->addWidget(mEventIndicatorTop,0,1); 439 agendaLayout->addWidget(mEventIndicatorTop,0,1);
440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); 440 mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, 441 mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
442 agendaFrame); 442 agendaFrame);
443 agendaLayout->addWidget(mEventIndicatorBottom,2,1); 443 agendaLayout->addWidget(mEventIndicatorBottom,2,1);
444 QWidget *dummyAgendaRight = new QWidget(agendaFrame); 444 QWidget *dummyAgendaRight = new QWidget(agendaFrame);
445 agendaLayout->addWidget(dummyAgendaRight,0,2); 445 agendaLayout->addWidget(dummyAgendaRight,0,2);
446 446
447 // Create time labels 447 // Create time labels
448 mTimeLabels = new TimeLabels(24,agendaFrame); 448 mTimeLabels = new TimeLabels(24,agendaFrame);
449 agendaLayout->addWidget(mTimeLabels,1,0); 449 agendaLayout->addWidget(mTimeLabels,1,0);
450 connect(mTimeLabels,SIGNAL( scaleChanged()), 450 connect(mTimeLabels,SIGNAL( scaleChanged()),
451 this,SLOT(updateConfig())); 451 this,SLOT(updateConfig()));
452 452
453 // Create agenda 453 // Create agenda
454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); 454 mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2); 455 agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
456 agendaLayout->setColStretch(1,1); 456 agendaLayout->setColStretch(1,1);
457 mAgenda->setFocusPolicy(NoFocus); 457 mAgenda->setFocusPolicy(NoFocus);
458 // Create event context menu for agenda 458 // Create event context menu for agenda
459 mAgendaPopup = eventPopup(); 459 mAgendaPopup = eventPopup();
460 460
461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), 461 mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
462 i18n("Toggle Alarm"),mAgenda, 462 i18n("Toggle Alarm"),mAgenda,
463 SLOT(popupAlarm()),true); 463 SLOT(popupAlarm()),true);
464 464
465 465
466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), 466 connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); 467 mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
468 468
469 // make connections between dependent widgets 469 // make connections between dependent widgets
470 mTimeLabels->setAgenda(mAgenda); 470 mTimeLabels->setAgenda(mAgenda);
471 471
472 // Update widgets to reflect user preferences 472 // Update widgets to reflect user preferences
473 // updateConfig(); 473 // updateConfig();
474 474
475 // createDayLabels(); 475 // createDayLabels();
476 476
477 // these blank widgets make the All Day Event box line up with the agenda 477 // these blank widgets make the All Day Event box line up with the agenda
478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 478 dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); 479 dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 480 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
481 481
482 // Scrolling 482 // Scrolling
483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), 483 connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
484 mTimeLabels, SLOT(positionChanged())); 484 mTimeLabels, SLOT(positionChanged()));
485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), 485 connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
486 SLOT(setContentsPos(int))); 486 SLOT(setContentsPos(int)));
487 487
488 // Create/Show/Edit/Delete Event 488 // Create/Show/Edit/Delete Event
489 connect(mAgenda,SIGNAL(newEventSignal(int,int)), 489 connect(mAgenda,SIGNAL(newEventSignal(int,int)),
490 SLOT(newEvent(int,int))); 490 SLOT(newEvent(int,int)));
491 connect(mAgenda,SIGNAL(newTodoSignal(int,int)),
492 SLOT(newTodo(int,int)));
491 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), 493 connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
492 SLOT(newEvent(int,int,int,int))); 494 SLOT(newEvent(int,int,int,int)));
493 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), 495 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
494 SLOT(newEventAllDay(int,int))); 496 SLOT(newEventAllDay(int,int)));
497 connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)),
498 SLOT(newTodoAllDay(int,int)));
495 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), 499 connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
496 SLOT(newEventAllDay(int,int))); 500 SLOT(newEventAllDay(int,int)));
497 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 501 connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
498 SLOT(newTimeSpanSelected(int,int,int,int))); 502 SLOT(newTimeSpanSelected(int,int,int,int)));
499 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), 503 connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
500 SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); 504 SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
501 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 505 connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
502 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); 506 connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
503 507
504 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 508 connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
505 SIGNAL(editIncidenceSignal(Incidence *))); 509 SIGNAL(editIncidenceSignal(Incidence *)));
506 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), 510 connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
507 SIGNAL(editIncidenceSignal(Incidence *))); 511 SIGNAL(editIncidenceSignal(Incidence *)));
508 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 512 connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
509 SIGNAL(showIncidenceSignal(Incidence *))); 513 SIGNAL(showIncidenceSignal(Incidence *)));
510 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), 514 connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
511 SIGNAL(showIncidenceSignal(Incidence *))); 515 SIGNAL(showIncidenceSignal(Incidence *)));
512 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 516 connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
513 SIGNAL(deleteIncidenceSignal(Incidence *))); 517 SIGNAL(deleteIncidenceSignal(Incidence *)));
514 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), 518 connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
515 SIGNAL(deleteIncidenceSignal(Incidence *))); 519 SIGNAL(deleteIncidenceSignal(Incidence *)));
516 520
517 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 521 connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
518 SLOT(updateEventDates(KOAgendaItem *, int ))); 522 SLOT(updateEventDates(KOAgendaItem *, int )));
519 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), 523 connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
520 SLOT(updateEventDates(KOAgendaItem *, int))); 524 SLOT(updateEventDates(KOAgendaItem *, int)));
521 525
522 // event indicator update 526 // event indicator update
523 connect(mAgenda,SIGNAL(lowerYChanged(int)), 527 connect(mAgenda,SIGNAL(lowerYChanged(int)),
524 SLOT(updateEventIndicatorTop(int))); 528 SLOT(updateEventIndicatorTop(int)));
525 connect(mAgenda,SIGNAL(upperYChanged(int)), 529 connect(mAgenda,SIGNAL(upperYChanged(int)),
526 SLOT(updateEventIndicatorBottom(int))); 530 SLOT(updateEventIndicatorBottom(int)));
527 // drag signals 531 // drag signals
528 /* 532 /*
529 connect(mAgenda,SIGNAL(startDragSignal(Event *)), 533 connect(mAgenda,SIGNAL(startDragSignal(Event *)),
530 SLOT(startDrag(Event *))); 534 SLOT(startDrag(Event *)));
531 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), 535 connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
532 SLOT(startDrag(Event *))); 536 SLOT(startDrag(Event *)));
533 */ 537 */
534 // synchronize selections 538 // synchronize selections
535 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 539 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
536 mAllDayAgenda, SLOT( deselectItem() ) ); 540 mAllDayAgenda, SLOT( deselectItem() ) );
537 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 541 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
538 mAgenda, SLOT( deselectItem() ) ); 542 mAgenda, SLOT( deselectItem() ) );
539 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 543 connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
540 SIGNAL( incidenceSelected( Incidence * ) ) ); 544 SIGNAL( incidenceSelected( Incidence * ) ) );
541 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), 545 connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
542 SIGNAL( incidenceSelected( Incidence * ) ) ); 546 SIGNAL( incidenceSelected( Incidence * ) ) );
543 connect( mAgenda, SIGNAL( resizedSignal() ), 547 connect( mAgenda, SIGNAL( resizedSignal() ),
544 SLOT( updateConfig( ) ) ); 548 SLOT( updateConfig( ) ) );
545 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), 549 connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
546 SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); 550 SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
547 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), 551 connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),
548 SLOT( addToCalSlot(Incidence * , Incidence *) ) ); 552 SLOT( addToCalSlot(Incidence * , Incidence *) ) );
549 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 553 // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
550 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); 554 //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) );
551 555
552 556
553} 557}
554 558
555void KOAgendaView::toggleAllDay() 559void KOAgendaView::toggleAllDay()
556{ 560{
557 if ( mSplitterAgenda->firstHandle() ) 561 if ( mSplitterAgenda->firstHandle() )
558 mSplitterAgenda->firstHandle()->toggle(); 562 mSplitterAgenda->firstHandle()->toggle();
559} 563}
560void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) 564void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld )
561{ 565{
562 calendar()->addIncidence( inc ); 566 calendar()->addIncidence( inc );
563 567
564 if ( incOld ) { 568 if ( incOld ) {
565 if ( incOld->type() == "Todo" ) 569 if ( incOld->type() == "Todo" )
566 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); 570 emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED );
567 else 571 else
568 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); 572 emit incidenceChanged(incOld, KOGlobals::EVENTEDITED);
569 } 573 }
570 574
571} 575}
572 576
573KOAgendaView::~KOAgendaView() 577KOAgendaView::~KOAgendaView()
574{ 578{
575 delete mAgendaPopup; 579 delete mAgendaPopup;
576 delete mAllDayAgendaPopup; 580 delete mAllDayAgendaPopup;
577 delete KOAgendaItem::paintPix(); 581 delete KOAgendaItem::paintPix();
578 delete KOAgendaItem::paintPixSel(); 582 delete KOAgendaItem::paintPixSel();
579} 583}
580void KOAgendaView::resizeEvent( QResizeEvent* e ) 584void KOAgendaView::resizeEvent( QResizeEvent* e )
581{ 585{
582 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); 586 //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width());
583 bool uc = false; 587 bool uc = false;
584 int ow = e->oldSize().width(); 588 int ow = e->oldSize().width();
585 int oh = e->oldSize().height(); 589 int oh = e->oldSize().height();
586 int w = e->size().width(); 590 int w = e->size().width();
587 int h = e->size().height(); 591 int h = e->size().height();
588 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { 592 if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) {
589 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) 593 if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda )
590 uc = true; 594 uc = true;
591 //qDebug("view changed %d %d %d %d ", ow, oh , w , h); 595 //qDebug("view changed %d %d %d %d ", ow, oh , w , h);
592 } 596 }
593 mUpcomingWidth = e->size().width() ; 597 mUpcomingWidth = e->size().width() ;
594 if ( mBlockUpdating || uc ) { 598 if ( mBlockUpdating || uc ) {
595 mBlockUpdating = false; 599 mBlockUpdating = false;
596 //mAgenda->setMinimumSize(800 , 600 ); 600 //mAgenda->setMinimumSize(800 , 600 );
597 //qDebug("mAgenda->resize+++++++++++++++ "); 601 //qDebug("mAgenda->resize+++++++++++++++ ");
598 updateConfig(); 602 updateConfig();
599 //qDebug("KOAgendaView::Updating now possible "); 603 //qDebug("KOAgendaView::Updating now possible ");
600 } else 604 } else
601 createDayLabels(); 605 createDayLabels();
602 //qDebug("resizeEvent end "); 606 //qDebug("resizeEvent end ");
603 607
604} 608}
605void KOAgendaView::createDayLabels() 609void KOAgendaView::createDayLabels()
606{ 610{
607 611
608 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 612 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
609 // qDebug(" KOAgendaView::createDayLabels() blocked "); 613 // qDebug(" KOAgendaView::createDayLabels() blocked ");
610 return; 614 return;
611 615
612 } 616 }
613 int newHight; 617 int newHight;
614 618
615 // ### Before deleting and recreating we could check if mSelectedDates changed... 619 // ### Before deleting and recreating we could check if mSelectedDates changed...
616 // It would remove some flickering and gain speed (since this is called by 620 // It would remove some flickering and gain speed (since this is called by
617 // each updateView() call) 621 // each updateView() call)
618 622
619 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; 623 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2;
620 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 624 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
621 if ( maxWid < 0 ) 625 if ( maxWid < 0 )
622 maxWid = 20; 626 maxWid = 20;
623 627
624 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 628 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
625 QFontMetrics fm ( dlf ); 629 QFontMetrics fm ( dlf );
626 int selCount = mSelectedDates.count(); 630 int selCount = mSelectedDates.count();
627 QString dayTest = "Mon 20"; 631 QString dayTest = "Mon 20";
628 int wid = fm.width( dayTest ); 632 int wid = fm.width( dayTest );
629 maxWid -= ( selCount * 3 ); 633 maxWid -= ( selCount * 3 );
630 if ( maxWid < 0 ) 634 if ( maxWid < 0 )
631 maxWid = 20; 635 maxWid = 20;
632 int needWid = wid * selCount; 636 int needWid = wid * selCount;
633 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 637 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
634 //if ( needWid > maxWid ) 638 //if ( needWid > maxWid )
635 // qDebug("DAYLABELS TOOOOOOO BIG "); 639 // qDebug("DAYLABELS TOOOOOOO BIG ");
636 while ( needWid > maxWid ) { 640 while ( needWid > maxWid ) {
637 dayTest = dayTest.left( dayTest.length() - 1 ); 641 dayTest = dayTest.left( dayTest.length() - 1 );
638 wid = fm.width( dayTest ); 642 wid = fm.width( dayTest );
639 needWid = wid * selCount; 643 needWid = wid * selCount;
640 } 644 }
641 int maxLen = dayTest.length(); 645 int maxLen = dayTest.length();
642 int fontPoint = dlf.pointSize(); 646 int fontPoint = dlf.pointSize();
643 if ( maxLen < 2 ) { 647 if ( maxLen < 2 ) {
644 int fontPoint = dlf.pointSize(); 648 int fontPoint = dlf.pointSize();
645 while ( fontPoint > 4 ) { 649 while ( fontPoint > 4 ) {
646 --fontPoint; 650 --fontPoint;
647 dlf.setPointSize( fontPoint ); 651 dlf.setPointSize( fontPoint );
648 QFontMetrics f( dlf ); 652 QFontMetrics f( dlf );
649 wid = f.width( "20" ); 653 wid = f.width( "20" );
650 needWid = wid * selCount; 654 needWid = wid * selCount;
651 if ( needWid < maxWid ) 655 if ( needWid < maxWid )
652 break; 656 break;
653 } 657 }
654 maxLen = 2; 658 maxLen = 2;
655 } 659 }
656 //qDebug("Max len %d ", dayTest.length() ); 660 //qDebug("Max len %d ", dayTest.length() );
657 661
658 QFontMetrics tempF( dlf ); 662 QFontMetrics tempF( dlf );
659 newHight = tempF.height(); 663 newHight = tempF.height();
660 mDayLabels->setFont( dlf ); 664 mDayLabels->setFont( dlf );
661 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; 665 // mLayoutDayLabels = new QHBoxLayout(mDayLabels);;
662 // mLayoutDayLabels->addSpacing(mTimeLabels->width()); 666 // mLayoutDayLabels->addSpacing(mTimeLabels->width());
663 //mLayoutDayLabels->addSpacing( 2 ); 667 //mLayoutDayLabels->addSpacing( 2 );
664 // QFont lFont = dlf; 668 // QFont lFont = dlf;
665 bool appendLabels = false; 669 bool appendLabels = false;
666 QLabel *dayLabel; 670 QLabel *dayLabel;
667 dayLabel = mDayLabelsList.first(); 671 dayLabel = mDayLabelsList.first();
668 if ( !dayLabel ) { 672 if ( !dayLabel ) {
669 appendLabels = true; 673 appendLabels = true;
670 dayLabel = new QLabel(mDayLabels); 674 dayLabel = new QLabel(mDayLabels);
671 mDayLabelsList.append( dayLabel ); 675 mDayLabelsList.append( dayLabel );
672 mLayoutDayLabels->addWidget(dayLabel); 676 mLayoutDayLabels->addWidget(dayLabel);
673 } 677 }
674 dayLabel->setFixedWidth( mTimeLabels->width()+2 ); 678 dayLabel->setFixedWidth( mTimeLabels->width()+2 );
675 dayLabel->setFont( dlf ); 679 dayLabel->setFont( dlf );
676 dayLabel->setAlignment(QLabel::AlignHCenter); 680 dayLabel->setAlignment(QLabel::AlignHCenter);
677 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); 681 dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) );
678 dayLabel->show(); 682 dayLabel->show();
679 DateList::ConstIterator dit; 683 DateList::ConstIterator dit;
680 bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); 684 bool oneday = (mSelectedDates.first() == mSelectedDates.last() );
681 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 685 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
682 QDate date = *dit; 686 QDate date = *dit;
683 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); 687 // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
684 if ( ! appendLabels ) { 688 if ( ! appendLabels ) {
685 dayLabel = mDayLabelsList.next(); 689 dayLabel = mDayLabelsList.next();
686 if ( !dayLabel ) 690 if ( !dayLabel )
687 appendLabels = true; 691 appendLabels = true;
688 } 692 }
689 if ( appendLabels ) { 693 if ( appendLabels ) {
690 dayLabel = new QLabel(mDayLabels); 694 dayLabel = new QLabel(mDayLabels);
691 mDayLabelsList.append( dayLabel ); 695 mDayLabelsList.append( dayLabel );
692 mLayoutDayLabels->addWidget(dayLabel); 696 mLayoutDayLabels->addWidget(dayLabel);
693 } 697 }
694 dayLabel->setMinimumWidth( 1 ); 698 dayLabel->setMinimumWidth( 1 );
695 dayLabel->setMaximumWidth( 2048 ); 699 dayLabel->setMaximumWidth( 2048 );
696 dayLabel->setFont( dlf ); 700 dayLabel->setFont( dlf );
697 dayLabel->show(); 701 dayLabel->show();
698 QString str; 702 QString str;
699 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); 703 int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date);
700 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); 704 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true );
701 switch ( maxLen ) { 705 switch ( maxLen ) {
702 case 2: 706 case 2:
703 str = QString::number( date.day() ); 707 str = QString::number( date.day() );
704 break; 708 break;
705 709
706 case 3: 710 case 3:
707 str = dayName.left( 1 ) +QString::number( date.day()); 711 str = dayName.left( 1 ) +QString::number( date.day());
708 712
709 break; 713 break;
710 case 4: 714 case 4:
711 str = dayName.left( 1 ) + " " +QString::number( date.day()); 715 str = dayName.left( 1 ) + " " +QString::number( date.day());
712 716
713 break; 717 break;
714 case 5: 718 case 5:
715 str = dayName.left( 2 ) + " " +QString::number( date.day()); 719 str = dayName.left( 2 ) + " " +QString::number( date.day());
716 720
717 break; 721 break;
718 case 6: 722 case 6:
719 str = dayName.left( 3 ) + " " +QString::number( date.day()); 723 str = dayName.left( 3 ) + " " +QString::number( date.day());
720 break; 724 break;
721 725
722 default: 726 default:
723 break; 727 break;
724 } 728 }
725 if ( oneday ) { 729 if ( oneday ) {
726 QString addString; 730 QString addString;
727 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) 731 if ( mSelectedDates.first() == QDateTime::currentDateTime().date() )
728 addString = i18n("Today"); 732 addString = i18n("Today");
729 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) 733 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) )
730 addString = i18n("Tomorrow"); 734 addString = i18n("Tomorrow");
731 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) 735 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) )
732 addString = i18n("Yesterday"); 736 addString = i18n("Yesterday");
733 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 737 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) )
734 addString = i18n("Day before yesterday"); 738 addString = i18n("Day before yesterday");
735 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) 739 else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) )
736 addString = i18n("Day after tomorrow"); 740 addString = i18n("Day after tomorrow");
737 if ( !addString.isEmpty() ) { 741 if ( !addString.isEmpty() ) {
738 str = addString+", " + str; 742 str = addString+", " + str;
739 } 743 }
740 } 744 }
741 dayLabel->setText(str); 745 dayLabel->setText(str);
742 dayLabel->setAlignment(QLabel::AlignHCenter); 746 dayLabel->setAlignment(QLabel::AlignHCenter);
743 if (date == QDate::currentDate()) { 747 if (date == QDate::currentDate()) {
744 QFont bFont = dlf; 748 QFont bFont = dlf;
745 bFont.setBold( true ); 749 bFont.setBold( true );
746 dayLabel->setFont(bFont); 750 dayLabel->setFont(bFont);
747 } 751 }
748 //dayLayout->addWidget(dayLabel); 752 //dayLayout->addWidget(dayLabel);
749 753
750#ifndef KORG_NOPLUGINS 754#ifndef KORG_NOPLUGINS
751 CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); 755 CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
752 CalendarDecoration *it; 756 CalendarDecoration *it;
753 for(it = cds.first(); it; it = cds.next()) { 757 for(it = cds.first(); it; it = cds.next()) {
754 QString text = it->shortText( date ); 758 QString text = it->shortText( date );
755 if ( !text.isEmpty() ) { 759 if ( !text.isEmpty() ) {
756 QLabel *label = new QLabel(text,mDayLabels); 760 QLabel *label = new QLabel(text,mDayLabels);
757 label->setAlignment(AlignCenter); 761 label->setAlignment(AlignCenter);
758 dayLayout->addWidget(label); 762 dayLayout->addWidget(label);
759 } 763 }
760 } 764 }
761 765
762 for(it = cds.first(); it; it = cds.next()) { 766 for(it = cds.first(); it; it = cds.next()) {
763 QWidget *wid = it->smallWidget(mDayLabels,date); 767 QWidget *wid = it->smallWidget(mDayLabels,date);
764 if ( wid ) { 768 if ( wid ) {
765 // wid->setHeight(20); 769 // wid->setHeight(20);
766 dayLayout->addWidget(wid); 770 dayLayout->addWidget(wid);
767 } 771 }
768 } 772 }
769#endif 773#endif
770 } 774 }
771 if ( ! appendLabels ) { 775 if ( ! appendLabels ) {
772 dayLabel = mDayLabelsList.next(); 776 dayLabel = mDayLabelsList.next();
773 if ( !dayLabel ) 777 if ( !dayLabel )
774 appendLabels = true; 778 appendLabels = true;
775 } 779 }
776 if ( appendLabels ) { 780 if ( appendLabels ) {
777 dayLabel = new QLabel(mDayLabels); 781 dayLabel = new QLabel(mDayLabels);
778 mDayLabelsList.append( dayLabel ); 782 mDayLabelsList.append( dayLabel );
779 mLayoutDayLabels->addWidget(dayLabel); 783 mLayoutDayLabels->addWidget(dayLabel);
780 } 784 }
781 //dayLabel->hide();//test only 785 //dayLabel->hide();//test only
782 786
783 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; 787 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ;
784 if ( offset < 0 ) offset = 0; 788 if ( offset < 0 ) offset = 0;
785 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); 789 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
786 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) ); 790 dayLabel->setText("");//QString::number ( mSelectedDates.first().month() ) );
787 dayLabel->show(); 791 dayLabel->show();
788 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 792 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset );
789 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); 793 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
790 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 794 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
791 if ( !appendLabels ) { 795 if ( !appendLabels ) {
792 dayLabel = mDayLabelsList.next(); 796 dayLabel = mDayLabelsList.next();
793 while ( dayLabel ) { 797 while ( dayLabel ) {
794 //qDebug("!dayLabel %d",dayLabel ); 798 //qDebug("!dayLabel %d",dayLabel );
795 dayLabel->hide(); 799 dayLabel->hide();
796 dayLabel = mDayLabelsList.next(); 800 dayLabel = mDayLabelsList.next();
797 } 801 }
798 } 802 }
799 //mDayLabelsFrame->show(); 803 //mDayLabelsFrame->show();
800 //mDayLabels->show(); 804 //mDayLabels->show();
801 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); 805 //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight);
802 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); 806 //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight );
803 mDayLabelsFrame->setFixedHeight( newHight ); 807 mDayLabelsFrame->setFixedHeight( newHight );
804} 808}
805 809
806int KOAgendaView::maxDatesHint() 810int KOAgendaView::maxDatesHint()
807{ 811{
808 // Not sure about the max number of events, so return 0 for now. 812 // Not sure about the max number of events, so return 0 for now.
809 return 0; 813 return 0;
810} 814}
811 815
812int KOAgendaView::currentDateCount() 816int KOAgendaView::currentDateCount()
813{ 817{
814 return mSelectedDates.count(); 818 return mSelectedDates.count();
815} 819}
816 820
817QPtrList<Incidence> KOAgendaView::selectedIncidences() 821QPtrList<Incidence> KOAgendaView::selectedIncidences()
818{ 822{
819 QPtrList<Incidence> selected; 823 QPtrList<Incidence> selected;
820 Incidence *incidence; 824 Incidence *incidence;
821 825
822 incidence = mAgenda->selectedIncidence(); 826 incidence = mAgenda->selectedIncidence();
823 if (incidence) selected.append(incidence); 827 if (incidence) selected.append(incidence);
824 828
825 incidence = mAllDayAgenda->selectedIncidence(); 829 incidence = mAllDayAgenda->selectedIncidence();
826 if (incidence) selected.append(incidence); 830 if (incidence) selected.append(incidence);
827 831
828 return selected; 832 return selected;
829} 833}
830 834
831DateList KOAgendaView::selectedDates() 835DateList KOAgendaView::selectedDates()
832{ 836{
833 DateList selected; 837 DateList selected;
834 QDate qd; 838 QDate qd;
835 839
836 qd = mAgenda->selectedIncidenceDate(); 840 qd = mAgenda->selectedIncidenceDate();
837 if (qd.isValid()) selected.append(qd); 841 if (qd.isValid()) selected.append(qd);
838 842
839 qd = mAllDayAgenda->selectedIncidenceDate(); 843 qd = mAllDayAgenda->selectedIncidenceDate();
840 if (qd.isValid()) selected.append(qd); 844 if (qd.isValid()) selected.append(qd);
841 845
842 return selected; 846 return selected;
843} 847}
844 848
845 849
846void KOAgendaView::updateView() 850void KOAgendaView::updateView()
847{ 851{
848 if ( mBlockUpdating ) 852 if ( mBlockUpdating )
849 return; 853 return;
850 // kdDebug() << "KOAgendaView::updateView()" << endl; 854 // kdDebug() << "KOAgendaView::updateView()" << endl;
851 fillAgenda(); 855 fillAgenda();
852 856
853} 857}
854 858
855 859
856/* 860/*
857 Update configuration settings for the agenda view. This method is not 861 Update configuration settings for the agenda view. This method is not
858 complete. 862 complete.
859*/ 863*/
860void KOAgendaView::updateConfig() 864void KOAgendaView::updateConfig()
861{ 865{
862 if ( mBlockUpdating ) 866 if ( mBlockUpdating )
863 return; 867 return;
864 // kdDebug() << "KOAgendaView::updateConfig()" << endl; 868 // kdDebug() << "KOAgendaView::updateConfig()" << endl;
865 869
866 // update config for children 870 // update config for children
867 mTimeLabels->updateConfig(); 871 mTimeLabels->updateConfig();
868 mAgenda->storePosition(); 872 mAgenda->storePosition();
869 mAgenda->updateConfig(); 873 mAgenda->updateConfig();
870 mAllDayAgenda->updateConfig(); 874 mAllDayAgenda->updateConfig();
871 // widget synchronization 875 // widget synchronization
872 //TODO: find a better way, maybe signal/slot 876 //TODO: find a better way, maybe signal/slot
873 mTimeLabels->positionChanged(); 877 mTimeLabels->positionChanged();
874 878
875 // for some reason, this needs to be called explicitly 879 // for some reason, this needs to be called explicitly
876 mTimeLabels->repaint(); 880 mTimeLabels->repaint();
877 881
878 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 882 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
879 883
880 // ToolTips displaying summary of events 884 // ToolTips displaying summary of events
881 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 885 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
882 ->mEnableToolTips); 886 ->mEnableToolTips);
883 887
884 //setHolidayMasks(); 888 //setHolidayMasks();
885 889
886 //createDayLabels(); called by via updateView(); 890 //createDayLabels(); called by via updateView();
887 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 891 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
888 updateView(); 892 updateView();
889 mAgenda->restorePosition(); 893 mAgenda->restorePosition();
890} 894}
891 895
892 896
893void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 897void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
894{ 898{
895 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 899 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
896 //qDebug("KOAgendaView::updateEventDates "); 900 //qDebug("KOAgendaView::updateEventDates ");
897 QDateTime startDt,endDt; 901 QDateTime startDt,endDt;
898 QDate startDate; 902 QDate startDate;
899 int lenInSecs; 903 int lenInSecs;
900 // if ( type == KOAgenda::RESIZETOP ) 904 // if ( type == KOAgenda::RESIZETOP )
901 // qDebug("RESIZETOP "); 905 // qDebug("RESIZETOP ");
902 // if ( type == KOAgenda::RESIZEBOTTOM ) 906 // if ( type == KOAgenda::RESIZEBOTTOM )
903 // qDebug("RESIZEBOTTOM "); 907 // qDebug("RESIZEBOTTOM ");
904 // if ( type == KOAgenda::MOVE ) 908 // if ( type == KOAgenda::MOVE )
905 // qDebug("MOVE "); 909 // qDebug("MOVE ");
906 if ( item->incidence()->type() == "Event" ) { 910 if ( item->incidence()->type() == "Event" ) {
907 startDt =item->incidence()->dtStart(); 911 startDt =item->incidence()->dtStart();
908 endDt = item->incidence()->dtEnd(); 912 endDt = item->incidence()->dtEnd();
909 lenInSecs = startDt.secsTo( endDt ); 913 lenInSecs = startDt.secsTo( endDt );
910 } 914 }
911 915
912 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 916 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );
913 917
914 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { 918 if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) {
915 startDate = mSelectedDates[item->mLastMoveXPos]; 919 startDate = mSelectedDates[item->mLastMoveXPos];
916 } else { 920 } else {
917 if (item->cellX() < 0) { 921 if (item->cellX() < 0) {
918 startDate = (mSelectedDates.first()).addDays(item->cellX()); 922 startDate = (mSelectedDates.first()).addDays(item->cellX());
919 } else { 923 } else {
920 startDate = mSelectedDates[item->cellX()]; 924 startDate = mSelectedDates[item->cellX()];
921 } 925 }
922 } 926 }
923 startDt.setDate(startDate); 927 startDt.setDate(startDate);
924 928
925 if (item->incidence()->doesFloat()) { 929 if (item->incidence()->doesFloat()) {
926 endDt.setDate(startDate.addDays(item->cellWidth() - 1)); 930 endDt.setDate(startDate.addDays(item->cellWidth() - 1));
927 } else { 931 } else {
928 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) 932 if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE )
929 startDt.setTime(mAgenda->gyToTime(item->cellYTop())); 933 startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
930 if ( item->incidence()->type() == "Event" ) { 934 if ( item->incidence()->type() == "Event" ) {
931 if ( type == KOAgenda::MOVE ) { 935 if ( type == KOAgenda::MOVE ) {
932 endDt = startDt.addSecs(lenInSecs); 936 endDt = startDt.addSecs(lenInSecs);
933 937
934 } else if ( type == KOAgenda::RESIZEBOTTOM ) { 938 } else if ( type == KOAgenda::RESIZEBOTTOM ) {
935 if (item->lastMultiItem()) { 939 if (item->lastMultiItem()) {
936 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 940 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
937 endDt.setDate(startDate. 941 endDt.setDate(startDate.
938 addDays(item->lastMultiItem()->cellX() - item->cellX())); 942 addDays(item->lastMultiItem()->cellX() - item->cellX()));
939 } else { 943 } else {
940 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 944 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
941 endDt.setDate(startDate); 945 endDt.setDate(startDate);
942 } 946 }
943 } 947 }
944 } else { 948 } else {
945 // todo 949 // todo
946 if (item->lastMultiItem()) { 950 if (item->lastMultiItem()) {
947 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); 951 endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
948 endDt.setDate(startDate. 952 endDt.setDate(startDate.
949 addDays(item->lastMultiItem()->cellX() - item->cellX())); 953 addDays(item->lastMultiItem()->cellX() - item->cellX()));
950 } else { 954 } else {
951 //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); 955 //qDebug("tem->cellYBottom() %d",item->cellYBottom() );
952 if ( item->cellYBottom() > 0 ) 956 if ( item->cellYBottom() > 0 )
953 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); 957 endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
954 else 958 else
955 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); 959 endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time());
956 endDt.setDate(startDate); 960 endDt.setDate(startDate);
957 } 961 }
958 } 962 }
959 } 963 }
960 964
961 965
962 if ( item->incidence()->type() == "Event" ) { 966 if ( item->incidence()->type() == "Event" ) {
963 item->incidence()->setDtStart(startDt); 967 item->incidence()->setDtStart(startDt);
964 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); 968 (static_cast<Event*>(item->incidence()))->setDtEnd(endDt);
965 } else if ( item->incidence()->type() == "Todo" ) { 969 } else if ( item->incidence()->type() == "Todo" ) {
966 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt); 970 (static_cast<Todo*>(item->incidence()))->setDtDue(endDt);
967 } 971 }
968 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); 972 //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() );
969 item->incidence()->setRevision(item->incidence()->revision()+1); 973 item->incidence()->setRevision(item->incidence()->revision()+1);
970 item->setItemDate(startDt.date()); 974 item->setItemDate(startDt.date());
971 //item->updateItem(); 975 //item->updateItem();
972 if ( item->incidence()->type() == "Todo" ) { 976 if ( item->incidence()->type() == "Todo" ) {
973 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); 977 emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED );
974 978
975 } 979 }
976 else 980 else
977 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); 981 emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED);
978 item->updateItem(); 982 item->updateItem();
979} 983}
980 984
981void KOAgendaView::showDates( const QDate &start, const QDate &end ) 985void KOAgendaView::showDates( const QDate &start, const QDate &end )
982{ 986{
983 // kdDebug() << "KOAgendaView::selectDates" << endl; 987 // kdDebug() << "KOAgendaView::selectDates" << endl;
984 988
985 mSelectedDates.clear(); 989 mSelectedDates.clear();
986 // qDebug("KOAgendaView::showDates "); 990 // qDebug("KOAgendaView::showDates ");
987 QDate d = start; 991 QDate d = start;
988 while (d <= end) { 992 while (d <= end) {
989 mSelectedDates.append(d); 993 mSelectedDates.append(d);
990 d = d.addDays( 1 ); 994 d = d.addDays( 1 );
991 } 995 }
992 996
993 // and update the view 997 // and update the view
994 fillAgenda(); 998 fillAgenda();
995} 999}
996 1000
997 1001
998void KOAgendaView::showEvents(QPtrList<Event>) 1002void KOAgendaView::showEvents(QPtrList<Event>)
999{ 1003{
1000 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; 1004 kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
1001} 1005}
1002 1006
1003void KOAgendaView::changeEventDisplay(Event *, int) 1007void KOAgendaView::changeEventDisplay(Event *, int)
1004{ 1008{
1005 // qDebug("KOAgendaView::changeEventDisplay "); 1009 // qDebug("KOAgendaView::changeEventDisplay ");
1006 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; 1010 // kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
1007 // this should be re-written to be MUCH smarter. Right now we 1011 // this should be re-written to be MUCH smarter. Right now we
1008 // are just playing dumb. 1012 // are just playing dumb.
1009 fillAgenda(); 1013 fillAgenda();
1010} 1014}
1011 1015
1012void KOAgendaView::fillAgenda(const QDate &) 1016void KOAgendaView::fillAgenda(const QDate &)
1013{ 1017{
1014 // qDebug("KOAgendaView::fillAgenda "); 1018 // qDebug("KOAgendaView::fillAgenda ");
1015 fillAgenda(); 1019 fillAgenda();
1016} 1020}
1017 1021
1018void KOAgendaView::fillAgenda() 1022void KOAgendaView::fillAgenda()
1019{ 1023{
1020 if ( globalFlagBlockStartup ) 1024 if ( globalFlagBlockStartup )
1021 return; 1025 return;
1022 if ( globalFlagBlockAgenda == 1 ) 1026 if ( globalFlagBlockAgenda == 1 )
1023 return; 1027 return;
1024 //if ( globalFlagBlockAgenda == 2 ) 1028 //if ( globalFlagBlockAgenda == 2 )
1025 //globalFlagBlockAgenda = 0; 1029 //globalFlagBlockAgenda = 0;
1026 // globalFlagBlockPainting = false; 1030 // globalFlagBlockPainting = false;
1027 if ( globalFlagBlockAgenda == 0 ) 1031 if ( globalFlagBlockAgenda == 0 )
1028 globalFlagBlockAgenda = 1; 1032 globalFlagBlockAgenda = 1;
1029 // clearView(); 1033 // clearView();
1030 //qDebug("fillAgenda()++++ "); 1034 //qDebug("fillAgenda()++++ ");
1031 globalFlagBlockAgendaItemPaint = 1; 1035 globalFlagBlockAgendaItemPaint = 1;
1032 mAllDayAgenda->changeColumns(mSelectedDates.count()); 1036 mAllDayAgenda->changeColumns(mSelectedDates.count());
1033 mAgenda->changeColumns(mSelectedDates.count()); 1037 mAgenda->changeColumns(mSelectedDates.count());
1034 qApp->processEvents(); 1038 qApp->processEvents();
1035 mEventIndicatorTop->changeColumns(mSelectedDates.count()); 1039 mEventIndicatorTop->changeColumns(mSelectedDates.count());
1036 mEventIndicatorBottom->changeColumns(mSelectedDates.count()); 1040 mEventIndicatorBottom->changeColumns(mSelectedDates.count());
1037 setHolidayMasks(); 1041 setHolidayMasks();
1038 1042
1039 //mAgenda->hideUnused(); 1043 //mAgenda->hideUnused();
1040 //mAllDayAgenda->hideUnused(); 1044 //mAllDayAgenda->hideUnused();
1041 1045
1042 // mAgenda->blockNextRepaint( false ); 1046 // mAgenda->blockNextRepaint( false );
1043 // mAgenda->viewport()->repaint(); 1047 // mAgenda->viewport()->repaint();
1044 // mAgenda->blockNextRepaint( true ); 1048 // mAgenda->blockNextRepaint( true );
1045 mMinY.resize(mSelectedDates.count()); 1049 mMinY.resize(mSelectedDates.count());
1046 mMaxY.resize(mSelectedDates.count()); 1050 mMaxY.resize(mSelectedDates.count());
1047 1051
1048 QPtrList<Event> dayEvents; 1052 QPtrList<Event> dayEvents;
1049 1053
1050 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1054 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1051 // Therefore, get all of them. 1055 // Therefore, get all of them.
1052 QPtrList<Todo> todos = calendar()->todos(); 1056 QPtrList<Todo> todos = calendar()->todos();
1053 1057
1054 mAgenda->setDateList(mSelectedDates); 1058 mAgenda->setDateList(mSelectedDates);
1055 1059
1056 QDate today = QDate::currentDate(); 1060 QDate today = QDate::currentDate();
1057 1061
1058 DateList::ConstIterator dit; 1062 DateList::ConstIterator dit;
1059 int curCol = 0; 1063 int curCol = 0;
1060 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { 1064 for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
1061 QDate currentDate = *dit; 1065 QDate currentDate = *dit;
1062 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() 1066 // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
1063 // << endl; 1067 // << endl;
1064 1068
1065 dayEvents = calendar()->events(currentDate,true); 1069 dayEvents = calendar()->events(currentDate,true);
1066 1070
1067 // Default values, which can never be reached 1071 // Default values, which can never be reached
1068 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; 1072 mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
1069 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; 1073 mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
1070 1074
1071 unsigned int numEvent; 1075 unsigned int numEvent;
1072 for(numEvent=0;numEvent<dayEvents.count();++numEvent) { 1076 for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
1073 Event *event = dayEvents.at(numEvent); 1077 Event *event = dayEvents.at(numEvent);
1074 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1078 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1075 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1079 if ( event->uid().left(15) == QString("last-syncEvent-") )
1076 continue; 1080 continue;
1077 // kdDebug() << " Event: " << event->summary() << endl; 1081 // kdDebug() << " Event: " << event->summary() << endl;
1078 1082
1079 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; 1083 int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
1080 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; 1084 int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
1081 1085
1082 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; 1086 // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl;
1083 1087
1084 if (event->doesFloat()) { 1088 if (event->doesFloat()) {
1085 if (event->recurrence()->doesRecur()) { 1089 if (event->recurrence()->doesRecur()) {
1086 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); 1090 mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
1087 } else { 1091 } else {
1088 if (beginX <= 0 && curCol == 0) { 1092 if (beginX <= 0 && curCol == 0) {
1089 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1093 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1090 } else if (beginX == curCol) { 1094 } else if (beginX == curCol) {
1091 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); 1095 mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
1092 } 1096 }
1093 } 1097 }
1094 } else if (event->isMultiDay()) { 1098 } else if (event->isMultiDay()) {
1095 if ( event->doesRecur () ) { 1099 if ( event->doesRecur () ) {
1096 QDate dateit = currentDate; 1100 QDate dateit = currentDate;
1097 int count = 0; 1101 int count = 0;
1098 int max = event->dtStart().daysTo( event->dtEnd() ) +2; 1102 int max = event->dtStart().daysTo( event->dtEnd() ) +2;
1099 while (! event->recursOn( dateit ) && count <= max ) { 1103 while (! event->recursOn( dateit ) && count <= max ) {
1100 ++count; 1104 ++count;
1101 dateit = dateit.addDays( -1 ); 1105 dateit = dateit.addDays( -1 );
1102 } 1106 }
1103 bool ok; 1107 bool ok;
1104 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); 1108 QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok );
1105 if ( ok ) 1109 if ( ok )
1106 { 1110 {
1107 int secs = event->dtStart().secsTo( event->dtEnd() ); 1111 int secs = event->dtStart().secsTo( event->dtEnd() );
1108 QDateTime nextOcend =nextOcstart.addSecs( secs ); ; 1112 QDateTime nextOcend =nextOcstart.addSecs( secs ); ;
1109 beginX = currentDate.daysTo(nextOcstart.date()) + curCol; 1113 beginX = currentDate.daysTo(nextOcstart.date()) + curCol;
1110 endX = currentDate.daysTo(nextOcend.date()) + curCol; 1114 endX = currentDate.daysTo(nextOcend.date()) + curCol;
1111 1115
1112 } 1116 }
1113 } 1117 }
1114 int startY = mAgenda->timeToY(event->dtStart().time()); 1118 int startY = mAgenda->timeToY(event->dtStart().time());
1115 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1119 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1116 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); 1120 //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol );
1117 if ((beginX <= 0 && curCol == 0) || beginX == curCol) { 1121 if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
1118 //qDebug("insert!!! "); 1122 //qDebug("insert!!! ");
1119 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); 1123 mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
1120 } 1124 }
1121 if (beginX == curCol) { 1125 if (beginX == curCol) {
1122 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1126 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1123 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1127 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1124 } else if (endX == curCol) { 1128 } else if (endX == curCol) {
1125 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1129 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1126 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1130 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1127 } else { 1131 } else {
1128 mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); 1132 mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
1129 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); 1133 mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
1130 } 1134 }
1131 } else { 1135 } else {
1132 int startY = mAgenda->timeToY(event->dtStart().time()); 1136 int startY = mAgenda->timeToY(event->dtStart().time());
1133 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; 1137 int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
1134 if (endY < startY) endY = startY; 1138 if (endY < startY) endY = startY;
1135 mAgenda->insertItem(event,currentDate,curCol,startY,endY); 1139 mAgenda->insertItem(event,currentDate,curCol,startY,endY);
1136 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1140 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1137 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1141 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1138 } 1142 }
1139 } 1143 }
1140 // ---------- [display Todos -------------- 1144 // ---------- [display Todos --------------
1141 unsigned int numTodo; 1145 unsigned int numTodo;
1142 for (numTodo = 0; numTodo < todos.count(); ++numTodo) { 1146 for (numTodo = 0; numTodo < todos.count(); ++numTodo) {
1143 Todo *todo = todos.at(numTodo); 1147 Todo *todo = todos.at(numTodo);
1144 1148
1145 if ( ! todo->hasDueDate() ) continue; // todo shall not be displayed if it has no date 1149 if ( ! todo->hasDueDate() ) continue; // todo shall not be displayed if it has no date
1146 1150
1147 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. 1151 // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue.
1148 // Already completed items can be displayed on their original due date 1152 // Already completed items can be displayed on their original due date
1149 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda 1153 //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda
1150 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; 1154 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda;
1151 1155
1152 if ( ((todo->dtDue().date() == currentDate) && !overdue) || 1156 if ( ((todo->dtDue().date() == currentDate) && !overdue) ||
1153 ((currentDate == today) && overdue) ) { 1157 ((currentDate == today) && overdue) ) {
1154 if ( todo->doesFloat() || overdue ) { // Todo has no due-time set or is already overdue 1158 if ( todo->doesFloat() || overdue ) { // Todo has no due-time set or is already overdue
1155 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1159 if ( KOPrefs::instance()->mShowTodoInAgenda )
1156 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); 1160 mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol);
1157 } 1161 }
1158 else { 1162 else {
1159 1163
1160 int endY = mAgenda->timeToY(todo->dtDue().time()) - 1; 1164 int endY = mAgenda->timeToY(todo->dtDue().time()) - 1;
1161 int hi = (18/KOPrefs::instance()->mHourSize); 1165 int hi = (18/KOPrefs::instance()->mHourSize);
1162 //qDebug("hei %d ",KOPrefs::instance()->mHourSize); 1166 //qDebug("hei %d ",KOPrefs::instance()->mHourSize);
1163 int startY = endY -hi; 1167 int startY = endY -hi;
1164 1168
1165 mAgenda->insertItem(todo,currentDate,curCol,startY,endY); 1169 mAgenda->insertItem(todo,currentDate,curCol,startY,endY);
1166 1170
1167 if (startY < mMinY[curCol]) mMinY[curCol] = startY; 1171 if (startY < mMinY[curCol]) mMinY[curCol] = startY;
1168 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; 1172 if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
1169 } 1173 }
1170 } 1174 }
1171 } 1175 }
1172 // ---------- display Todos] -------------- 1176 // ---------- display Todos] --------------
1173 1177
1174 ++curCol; 1178 ++curCol;
1175 } 1179 }
1176 mAgenda->hideUnused(); 1180 mAgenda->hideUnused();
1177 mAllDayAgenda->hideUnused(); 1181 mAllDayAgenda->hideUnused();
1178 mAgenda->checkScrollBoundaries(); 1182 mAgenda->checkScrollBoundaries();
1179 1183
1180 deleteSelectedDateTime(); 1184 deleteSelectedDateTime();
1181 1185
1182 createDayLabels(); 1186 createDayLabels();
1183 emit incidenceSelected( 0 ); 1187 emit incidenceSelected( 0 );
1184 1188
1185 if ( globalFlagBlockAgenda == 2 ) { 1189 if ( globalFlagBlockAgenda == 2 ) {
1186 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 1190 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
1187 setStartHour( KOPrefs::instance()->mDayBegins ); 1191 setStartHour( KOPrefs::instance()->mDayBegins );
1188 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 1192 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
1189 setStartHour( QTime::currentTime ().hour() ); 1193 setStartHour( QTime::currentTime ().hour() );
1190 // qApp->processEvents(); 1194 // qApp->processEvents();
1191 } 1195 }
1192 qApp->processEvents(); 1196 qApp->processEvents();
1193 //qDebug("qApp->processEvents(); END "); 1197 //qDebug("qApp->processEvents(); END ");
1194 globalFlagBlockAgenda = 0; 1198 globalFlagBlockAgenda = 0;
1195 1199
1196 // mAgenda->hideUnused(); 1200 // mAgenda->hideUnused();
1197 //mAllDayAgenda->hideUnused(); 1201 //mAllDayAgenda->hideUnused();
1198 mAllDayAgenda->drawContentsToPainter(); 1202 mAllDayAgenda->drawContentsToPainter();
1199 mAgenda->drawContentsToPainter(); 1203 mAgenda->drawContentsToPainter();
1200 repaintAgenda(); 1204 repaintAgenda();
1201 // mAgenda->finishUpdate(); 1205 // mAgenda->finishUpdate();
1202 //mAllDayAgenda->finishUpdate(); 1206 //mAllDayAgenda->finishUpdate();
1203 1207
1204 // repaintAgenda(); 1208 // repaintAgenda();
1205 //qApp->processEvents(); 1209 //qApp->processEvents();
1206 // globalFlagBlockAgenda = 0; 1210 // globalFlagBlockAgenda = 0;
1207} 1211}
1208void KOAgendaView::repaintAgenda() 1212void KOAgendaView::repaintAgenda()
1209{ 1213{
1210 // mAllDayAgenda->drawContentsToPainter(); 1214 // mAllDayAgenda->drawContentsToPainter();
1211// mAllDayAgenda->viewport()->repaint( false ); 1215// mAllDayAgenda->viewport()->repaint( false );
1212// mAgenda->drawContentsToPainter(); 1216// mAgenda->drawContentsToPainter();
1213// mAgenda->viewport()->repaint( false ); 1217// mAgenda->viewport()->repaint( false );
1214// qApp->processEvents(); 1218// qApp->processEvents();
1215 1219
1216 //qDebug("KOAgendaView::repaintAgenda() "); 1220 //qDebug("KOAgendaView::repaintAgenda() ");
1217 //qApp->processEvents(); 1221 //qApp->processEvents();
1218 mAgenda->viewport()->repaint( false ); 1222 mAgenda->viewport()->repaint( false );
1219 mAllDayAgenda->viewport()->repaint( false ); 1223 mAllDayAgenda->viewport()->repaint( false );
1220 mAgenda->finishUpdate(); 1224 mAgenda->finishUpdate();
1221 mAllDayAgenda->finishUpdate(); 1225 mAllDayAgenda->finishUpdate();
1222} 1226}
1223 1227
1224 1228
1225void KOAgendaView::clearView() 1229void KOAgendaView::clearView()
1226{ 1230{
1227 // kdDebug() << "ClearView" << endl; 1231 // kdDebug() << "ClearView" << endl;
1228 mAllDayAgenda->clear(); 1232 mAllDayAgenda->clear();
1229 mAgenda->clear(); 1233 mAgenda->clear();
1230} 1234}
1231 1235
1232void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1236void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1233 const QDate &td) 1237 const QDate &td)
1234{ 1238{
1235#ifndef KORG_NOPRINTER 1239#ifndef KORG_NOPRINTER
1236 if (fd == td) 1240 if (fd == td)
1237 calPrinter->preview(CalPrinter::Day, fd, td); 1241 calPrinter->preview(CalPrinter::Day, fd, td);
1238 else 1242 else
1239 calPrinter->preview(CalPrinter::Week, fd, td); 1243 calPrinter->preview(CalPrinter::Week, fd, td);
1240#endif 1244#endif
1241} 1245}
1242 1246
1243// void KOAgendaView::updateMovedTodo() 1247// void KOAgendaView::updateMovedTodo()
1244// { 1248// {
1245// // updateConfig(); 1249// // updateConfig();
1246// // emit updateTodoViews(); 1250// // emit updateTodoViews();
1247// } 1251// }
1248 1252
1249void KOAgendaView::newEvent(int gx, int gy) 1253void KOAgendaView::newEvent(int gx, int gy)
1250{ 1254{
1251 if (!mSelectedDates.count()) return; 1255 if (!mSelectedDates.count()) return;
1252 1256
1253 QDate day = mSelectedDates[gx]; 1257 QDate day = mSelectedDates[gx];
1254 1258
1255 QTime time = mAgenda->gyToTime(gy); 1259 QTime time = mAgenda->gyToTime(gy);
1256 QDateTime dt(day,time); 1260 QDateTime dt(day,time);
1257 // if ( dt < QDateTime::currentDateTime () ) 1261 // if ( dt < QDateTime::currentDateTime () )
1258 // dt = QDateTime::currentDateTime ().addSecs( 3600 ); 1262 // dt = QDateTime::currentDateTime ().addSecs( 3600 );
1259 emit newEventSignal(dt); 1263 emit newEventSignal(dt);
1260} 1264}
1261 1265
1262void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) 1266void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
1263{ 1267{
1264 if (!mSelectedDates.count()) return; 1268 if (!mSelectedDates.count()) return;
1265 1269
1266 QDate dayStart = mSelectedDates[gxStart]; 1270 QDate dayStart = mSelectedDates[gxStart];
1267 QDate dayEnd = mSelectedDates[gxEnd]; 1271 QDate dayEnd = mSelectedDates[gxEnd];
1268 1272
1269 QTime timeStart = mAgenda->gyToTime(gyStart); 1273 QTime timeStart = mAgenda->gyToTime(gyStart);
1270 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1274 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1271 1275
1272 QDateTime dtStart(dayStart,timeStart); 1276 QDateTime dtStart(dayStart,timeStart);
1273 QDateTime dtEnd(dayEnd,timeEnd); 1277 QDateTime dtEnd(dayEnd,timeEnd);
1274 1278
1275 emit newEventSignal(dtStart,dtEnd); 1279 emit newEventSignal(dtStart,dtEnd);
1276} 1280}
1277 1281
1278void KOAgendaView::newEventAllDay(int gx, int ) 1282void KOAgendaView::newEventAllDay(int gx, int )
1279{ 1283{
1280 if (!mSelectedDates.count()) return; 1284 if (!mSelectedDates.count()) return;
1281 1285
1282 QDate day = mSelectedDates[gx]; 1286 QDate day = mSelectedDates[gx];
1283 1287
1284 emit newEventSignal(day); 1288 emit newEventSignal(day);
1285} 1289}
1290void KOAgendaView::newTodoAllDay(int gx, int )
1291{
1292 if (!mSelectedDates.count()) return;
1293
1294 QDateTime day (mSelectedDates[gx] );
1295 emit newTodoSignal(day, true);
1296}
1297void KOAgendaView::newTodo(int gx, int gy )
1298{
1299 if (!mSelectedDates.count()) return;
1300 QDate dayStart = mSelectedDates[gx];
1301 QTime timeStart = mAgenda->gyToTime(gy);
1302 QDateTime dt (dayStart,timeStart);
1303 emit newTodoSignal( dt, false );
1304}
1286 1305
1287void KOAgendaView::updateEventIndicatorTop(int newY) 1306void KOAgendaView::updateEventIndicatorTop(int newY)
1288{ 1307{
1289 uint i; 1308 uint i;
1290 for(i=0;i<mMinY.size();++i) { 1309 for(i=0;i<mMinY.size();++i) {
1291 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); 1310 if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true);
1292 else mEventIndicatorTop->enableColumn(i,false); 1311 else mEventIndicatorTop->enableColumn(i,false);
1293 } 1312 }
1294 1313
1295 mEventIndicatorTop->update(); 1314 mEventIndicatorTop->update();
1296} 1315}
1297 1316
1298void KOAgendaView::updateEventIndicatorBottom(int newY) 1317void KOAgendaView::updateEventIndicatorBottom(int newY)
1299{ 1318{
1300 uint i; 1319 uint i;
1301 for(i=0;i<mMaxY.size();++i) { 1320 for(i=0;i<mMaxY.size();++i) {
1302 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); 1321 if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true);
1303 else mEventIndicatorBottom->enableColumn(i,false); 1322 else mEventIndicatorBottom->enableColumn(i,false);
1304 } 1323 }
1305 1324
1306 mEventIndicatorBottom->update(); 1325 mEventIndicatorBottom->update();
1307} 1326}
1308 1327
1309void KOAgendaView::startDrag(Event *event) 1328void KOAgendaView::startDrag(Event *event)
1310{ 1329{
1311#ifndef KORG_NODND 1330#ifndef KORG_NODND
1312 DndFactory factory( calendar() ); 1331 DndFactory factory( calendar() );
1313 ICalDrag *vd = factory.createDrag(event,this); 1332 ICalDrag *vd = factory.createDrag(event,this);
1314 if (vd->drag()) { 1333 if (vd->drag()) {
1315 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; 1334 kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
1316 } 1335 }
1317#endif 1336#endif
1318} 1337}
1319 1338
1320void KOAgendaView::readSettings() 1339void KOAgendaView::readSettings()
1321{ 1340{
1322 readSettings(KOGlobals::config()); 1341 readSettings(KOGlobals::config());
1323} 1342}
1324 1343
1325void KOAgendaView::readSettings(KConfig *config) 1344void KOAgendaView::readSettings(KConfig *config)
1326{ 1345{
1327 // kdDebug() << "KOAgendaView::readSettings()" << endl; 1346 // kdDebug() << "KOAgendaView::readSettings()" << endl;
1328 1347
1329 config->setGroup("Views"); 1348 config->setGroup("Views");
1330 1349
1331 //#ifndef KORG_NOSPLITTER 1350 //#ifndef KORG_NOSPLITTER
1332 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); 1351 QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
1333 if (sizes.count() == 2) { 1352 if (sizes.count() == 2) {
1334 if ( sizes[0] < 20 ) { 1353 if ( sizes[0] < 20 ) {
1335 sizes[1] = sizes[1] +20 - sizes[0]; 1354 sizes[1] = sizes[1] +20 - sizes[0];
1336 sizes[0] = 20; 1355 sizes[0] = 20;
1337 } 1356 }
1338 mSplitterAgenda->setSizes(sizes); 1357 mSplitterAgenda->setSizes(sizes);
1339 // qDebug("read %d %d ",sizes[0],sizes[1] ); 1358 // qDebug("read %d %d ",sizes[0],sizes[1] );
1340 } 1359 }
1341 //#endif 1360 //#endif
1342 1361
1343 // updateConfig(); 1362 // updateConfig();
1344} 1363}
1345 1364
1346void KOAgendaView::writeSettings(KConfig *config) 1365void KOAgendaView::writeSettings(KConfig *config)
1347{ 1366{
1348 // kdDebug() << "KOAgendaView::writeSettings()" << endl; 1367 // kdDebug() << "KOAgendaView::writeSettings()" << endl;
1349 1368
1350 config->setGroup("Views"); 1369 config->setGroup("Views");
1351 1370
1352 //#ifndef KORG_NOSPLITTER 1371 //#ifndef KORG_NOSPLITTER
1353 QValueList<int> list = mSplitterAgenda->sizes(); 1372 QValueList<int> list = mSplitterAgenda->sizes();
1354 config->writeEntry("Separator AgendaView",list); 1373 config->writeEntry("Separator AgendaView",list);
1355 //qDebug("write %d %d ", list[0],list[1] ); 1374 //qDebug("write %d %d ", list[0],list[1] );
1356 //#endif 1375 //#endif
1357} 1376}
1358 1377
1359void KOAgendaView::setHolidayMasks() 1378void KOAgendaView::setHolidayMasks()
1360{ 1379{
1361 mHolidayMask.resize(mSelectedDates.count()); 1380 mHolidayMask.resize(mSelectedDates.count());
1362 1381
1363 uint i; 1382 uint i;
1364 for(i=0;i<mSelectedDates.count();++i) { 1383 for(i=0;i<mSelectedDates.count();++i) {
1365 QDate date = mSelectedDates[i]; 1384 QDate date = mSelectedDates[i];
1366 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); 1385 bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
1367 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); 1386 bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
1368 bool showHoliday = false; 1387 bool showHoliday = false;
1369 if ( KOPrefs::instance()->mExcludeHolidays ) { 1388 if ( KOPrefs::instance()->mExcludeHolidays ) {
1370 QPtrList<Event> events = calendar()->events( date, true ); 1389 QPtrList<Event> events = calendar()->events( date, true );
1371 Event *event; 1390 Event *event;
1372 for( event = events.first(); event; event = events.next() ) { 1391 for( event = events.first(); event; event = events.next() ) {
1373 if ( event->categories().contains("Holiday") || 1392 if ( event->categories().contains("Holiday") ||
1374 event->categories().contains(i18n("Holiday"))) { 1393 event->categories().contains(i18n("Holiday"))) {
1375 showHoliday = true; 1394 showHoliday = true;
1376 break; 1395 break;
1377 } 1396 }
1378 } 1397 }
1379 1398
1380 } 1399 }
1381 1400
1382#ifndef KORG_NOPLUGINS 1401#ifndef KORG_NOPLUGINS
1383 bool showHoliday = KOPrefs::instance()->mExcludeHolidays && 1402 bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
1384 !KOCore::self()->holiday(date).isEmpty(); 1403 !KOCore::self()->holiday(date).isEmpty();
1385#endif 1404#endif
1386 bool showDay = showSaturday || showSunday || showHoliday; 1405 bool showDay = showSaturday || showSunday || showHoliday;
1387 1406
1388 if (showDay) { 1407 if (showDay) {
1389 mHolidayMask.at(i) = true; 1408 mHolidayMask.at(i) = true;
1390 } else { 1409 } else {
1391 mHolidayMask.at(i) = false; 1410 mHolidayMask.at(i) = false;
1392 } 1411 }
1393 } 1412 }
1394 1413
1395 mAgenda->setHolidayMask(&mHolidayMask); 1414 mAgenda->setHolidayMask(&mHolidayMask);
1396 mAllDayAgenda->setHolidayMask(&mHolidayMask); 1415 mAllDayAgenda->setHolidayMask(&mHolidayMask);
1397} 1416}
1398 1417
1399void KOAgendaView::setContentsPos(int y) 1418void KOAgendaView::setContentsPos(int y)
1400{ 1419{
1401 mAgenda->setContentsPos(0,y); 1420 mAgenda->setContentsPos(0,y);
1402} 1421}
1403 1422
1404void KOAgendaView::setExpandedButton( bool expanded ) 1423void KOAgendaView::setExpandedButton( bool expanded )
1405{ 1424{
1406 if ( expanded ) { 1425 if ( expanded ) {
1407 mExpandButton->setPixmap( mExpandedPixmap ); 1426 mExpandButton->setPixmap( mExpandedPixmap );
1408 } else { 1427 } else {
1409 mExpandButton->setPixmap( mNotExpandedPixmap ); 1428 mExpandButton->setPixmap( mNotExpandedPixmap );
1410 } 1429 }
1411} 1430}
1412 1431
1413void KOAgendaView::clearSelection() 1432void KOAgendaView::clearSelection()
1414{ 1433{
1415 mAgenda->deselectItem(); 1434 mAgenda->deselectItem();
1416 mAllDayAgenda->deselectItem(); 1435 mAllDayAgenda->deselectItem();
1417} 1436}
1418 1437
1419void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, 1438void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
1420 int gxEnd, int gyEnd) 1439 int gxEnd, int gyEnd)
1421{ 1440{
1422 mTimeSpanInAllDay = true; 1441 mTimeSpanInAllDay = true;
1423 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); 1442 newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
1424} 1443}
1425 1444
1426 1445
1427 1446
1428 1447
1429void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, 1448void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
1430 int gxEnd, int gyEnd) 1449 int gxEnd, int gyEnd)
1431{ 1450{
1432 if (!mSelectedDates.count()) return; 1451 if (!mSelectedDates.count()) return;
1433 1452
1434 QDate dayStart = mSelectedDates[gxStart]; 1453 QDate dayStart = mSelectedDates[gxStart];
1435 QDate dayEnd = mSelectedDates[gxEnd]; 1454 QDate dayEnd = mSelectedDates[gxEnd];
1436 1455
1437 QTime timeStart = mAgenda->gyToTime(gyStart); 1456 QTime timeStart = mAgenda->gyToTime(gyStart);
1438 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); 1457 QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
1439 1458
1440 QDateTime dtStart(dayStart,timeStart); 1459 QDateTime dtStart(dayStart,timeStart);
1441 QDateTime dtEnd(dayEnd,timeEnd); 1460 QDateTime dtEnd(dayEnd,timeEnd);
1442 1461
1443 mTimeSpanBegin = dtStart; 1462 mTimeSpanBegin = dtStart;
1444 mTimeSpanEnd = dtEnd; 1463 mTimeSpanEnd = dtEnd;
1445 1464
1446} 1465}
1447 1466
1448void KOAgendaView::deleteSelectedDateTime() 1467void KOAgendaView::deleteSelectedDateTime()
1449{ 1468{
1450 mTimeSpanBegin.setDate(QDate()); 1469 mTimeSpanBegin.setDate(QDate());
1451 mTimeSpanEnd.setDate(QDate()); 1470 mTimeSpanEnd.setDate(QDate());
1452 mTimeSpanInAllDay = false; 1471 mTimeSpanInAllDay = false;
1453} 1472}
1454 1473
1455void KOAgendaView::keyPressEvent ( QKeyEvent * e ) 1474void KOAgendaView::keyPressEvent ( QKeyEvent * e )
1456{ 1475{
1457 e->ignore(); 1476 e->ignore();
1458} 1477}
1459 1478
1460void KOAgendaView::scrollOneHourUp() 1479void KOAgendaView::scrollOneHourUp()
1461{ 1480{
1462 1481
1463 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); 1482 mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 );
1464} 1483}
1465void KOAgendaView::scrollOneHourDown() 1484void KOAgendaView::scrollOneHourDown()
1466{ 1485{
1467 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); 1486 mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 );
1468} 1487}
1469 1488
1470void KOAgendaView::setStartHour( int h ) 1489void KOAgendaView::setStartHour( int h )
1471{ 1490{
1472 mAgenda->setStartHour( h ); 1491 mAgenda->setStartHour( h );
1473 1492
1474} 1493}
1475 1494
1476void KOAgendaView::updateTodo( Todo * t, int ) 1495void KOAgendaView::updateTodo( Todo * t, int )
1477{ 1496{
1478 1497
1479 bool remove = false; 1498 bool remove = false;
1480 bool removeAD = false; 1499 bool removeAD = false;
1481 if ( ! t->hasDueDate() ) { 1500 if ( ! t->hasDueDate() ) {
1482 remove = true; 1501 remove = true;
1483 removeAD = true; 1502 removeAD = true;
1484 } 1503 }
1485 else { 1504 else {
1486 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; 1505 bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ;
1487 if ( overdue && 1506 if ( overdue &&
1488 QDate::currentDate() >= mSelectedDates.first() && 1507 QDate::currentDate() >= mSelectedDates.first() &&
1489 QDate::currentDate() <= mSelectedDates.last()) { 1508 QDate::currentDate() <= mSelectedDates.last()) {
1490 removeAD = false; 1509 removeAD = false;
1491 remove = true; 1510 remove = true;
1492 } 1511 }
1493 else { 1512 else {
1494 if ( t->dtDue().date() < mSelectedDates.first() || 1513 if ( t->dtDue().date() < mSelectedDates.first() ||
1495 t->dtDue().date() > mSelectedDates.last() ) { 1514 t->dtDue().date() > mSelectedDates.last() ) {
1496 remove = true; 1515 remove = true;
1497 removeAD = true; 1516 removeAD = true;
1498 } else { 1517 } else {
1499 remove = t->doesFloat(); 1518 remove = t->doesFloat();
1500 removeAD = !remove; 1519 removeAD = !remove;
1501 } 1520 }
1502 } 1521 }
1503 } 1522 }
1504 int days = mSelectedDates.first().daysTo( t->dtDue().date() ); 1523 int days = mSelectedDates.first().daysTo( t->dtDue().date() );
1505 // qDebug("daysto %d ", days ); 1524 // qDebug("daysto %d ", days );
1506 mAgenda->updateTodo( t , days, remove); 1525 mAgenda->updateTodo( t , days, remove);
1507 if ( KOPrefs::instance()->mShowTodoInAgenda ) 1526 if ( KOPrefs::instance()->mShowTodoInAgenda )
1508 mAllDayAgenda->updateTodo( t , days, removeAD); 1527 mAllDayAgenda->updateTodo( t , days, removeAD);
1509 //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); 1528 //qDebug("KOAgendaView::updateTodo( Todo *, int ) ");
1510 1529
1511} 1530}
diff --git a/korganizer/koagendaview.h b/korganizer/koagendaview.h
index 3cf938f..01d74a1 100644
--- a/korganizer/koagendaview.h
+++ b/korganizer/koagendaview.h
@@ -1,258 +1,261 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 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#ifndef KOAGENDAVIEW_H 23#ifndef KOAGENDAVIEW_H
24#define KOAGENDAVIEW_H 24#define KOAGENDAVIEW_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef DESKTOP_VERSION 29#ifndef DESKTOP_VERSION
30#include <qksplitter.h> 30#include <qksplitter.h>
31#else 31#else
32#include <qsplitter.h> 32#include <qsplitter.h>
33#endif 33#endif
34#include <qmemarray.h> 34#include <qmemarray.h>
35 35
36#include "koeventview.h" 36#include "koeventview.h"
37 37
38 38
39class QHBox; 39class QHBox;
40class QFrame; 40class QFrame;
41class QLabel; 41class QLabel;
42class QPushButton; 42class QPushButton;
43class CalendarView; 43class CalendarView;
44class KOAgenda; 44class KOAgenda;
45class KOAgendaItem; 45class KOAgendaItem;
46class KConfig; 46class KConfig;
47class KDGanttMinimizeSplitter; 47class KDGanttMinimizeSplitter;
48class TimeLabels : public QScrollView { 48class TimeLabels : public QScrollView {
49 Q_OBJECT 49 Q_OBJECT
50 public: 50 public:
51 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0); 51 TimeLabels(int rows,QWidget *parent=0,const char *name=0,WFlags f=0);
52 52
53 void setCellHeight(int height); 53 void setCellHeight(int height);
54 54
55 /** Calculates the minimum width */ 55 /** Calculates the minimum width */
56 virtual int minimumWidth() const; 56 virtual int minimumWidth() const;
57 57
58 /** updates widget's internal state */ 58 /** updates widget's internal state */
59 void updateConfig(); 59 void updateConfig();
60 60
61 /** */ 61 /** */
62 void setAgenda(KOAgenda* agenda); 62 void setAgenda(KOAgenda* agenda);
63 63
64 /** */ 64 /** */
65 virtual void paintEvent(QPaintEvent* e); 65 virtual void paintEvent(QPaintEvent* e);
66 void contentsMousePressEvent ( QMouseEvent * ) ; 66 void contentsMousePressEvent ( QMouseEvent * ) ;
67 void contentsMouseReleaseEvent ( QMouseEvent * ); 67 void contentsMouseReleaseEvent ( QMouseEvent * );
68 void contentsMouseMoveEvent ( QMouseEvent * ); 68 void contentsMouseMoveEvent ( QMouseEvent * );
69 69
70 public slots: 70 public slots:
71 /** update time label positions */ 71 /** update time label positions */
72 void positionChanged(); 72 void positionChanged();
73 signals: 73 signals:
74 void scaleChanged(); 74 void scaleChanged();
75 protected: 75 protected:
76 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 76 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
77 77
78 private: 78 private:
79 int mMouseDownY; 79 int mMouseDownY;
80 QString mOrgCap; 80 QString mOrgCap;
81 int mRows; 81 int mRows;
82 int mCellHeight; 82 int mCellHeight;
83 83
84 /** */ 84 /** */
85 KOAgenda* mAgenda; 85 KOAgenda* mAgenda;
86}; 86};
87 87
88class EventIndicator : public QFrame { 88class EventIndicator : public QFrame {
89 Q_OBJECT 89 Q_OBJECT
90 public: 90 public:
91 enum Location { Top, Bottom }; 91 enum Location { Top, Bottom };
92 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0); 92 EventIndicator(Location loc=Top,QWidget *parent=0,const char *name=0);
93 virtual ~EventIndicator(); 93 virtual ~EventIndicator();
94 94
95 void changeColumns(int columns); 95 void changeColumns(int columns);
96 void setPaintWidget( KDGanttMinimizeSplitter* ); 96 void setPaintWidget( KDGanttMinimizeSplitter* );
97 void setXOffset( int ); 97 void setXOffset( int );
98 void enableColumn(int column, bool enable); 98 void enableColumn(int column, bool enable);
99 99
100 protected: 100 protected:
101 void drawContents(QPainter *); 101 void drawContents(QPainter *);
102 102
103 private: 103 private:
104 int mXOffset; 104 int mXOffset;
105 KDGanttMinimizeSplitter* mPaintWidget; 105 KDGanttMinimizeSplitter* mPaintWidget;
106 int mColumns; 106 int mColumns;
107 QHBox *mTopBox; 107 QHBox *mTopBox;
108 QBoxLayout *mTopLayout; 108 QBoxLayout *mTopLayout;
109 Location mLocation; 109 Location mLocation;
110 QPixmap mPixmap; 110 QPixmap mPixmap;
111 QMemArray<bool> mEnabled; 111 QMemArray<bool> mEnabled;
112}; 112};
113 113
114/** 114/**
115 KOAgendaView is the agenda-like view used to display events in an one or 115 KOAgendaView is the agenda-like view used to display events in an one or
116 multi-day view. 116 multi-day view.
117*/ 117*/
118class KOAgendaView : public KOEventView { 118class KOAgendaView : public KOEventView {
119 Q_OBJECT 119 Q_OBJECT
120 public: 120 public:
121 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 ); 121 KOAgendaView(Calendar *cal,QWidget *parent = 0,const char *name = 0 );
122 virtual ~KOAgendaView(); 122 virtual ~KOAgendaView();
123 void setStartHour( int ); 123 void setStartHour( int );
124 void toggleAllDay(); 124 void toggleAllDay();
125 125
126 126
127 /** Returns maximum number of days supported by the koagendaview */ 127 /** Returns maximum number of days supported by the koagendaview */
128 virtual int maxDatesHint(); 128 virtual int maxDatesHint();
129 129
130 /** Returns number of currently shown dates. */ 130 /** Returns number of currently shown dates. */
131 virtual int currentDateCount(); 131 virtual int currentDateCount();
132 132
133 /** returns the currently selected events */ 133 /** returns the currently selected events */
134 virtual QPtrList<Incidence> selectedIncidences(); 134 virtual QPtrList<Incidence> selectedIncidences();
135 135
136 /** returns the currently selected events */ 136 /** returns the currently selected events */
137 virtual DateList selectedDates(); 137 virtual DateList selectedDates();
138 138
139 /** Remove all events from view */ 139 /** Remove all events from view */
140 void clearView(); 140 void clearView();
141 KOAgenda *agenda() { return mAgenda;} 141 KOAgenda *agenda() { return mAgenda;}
142 virtual void printPreview(CalPrinter *calPrinter, 142 virtual void printPreview(CalPrinter *calPrinter,
143 const QDate &, const QDate &); 143 const QDate &, const QDate &);
144 144
145 /** start-datetime of selection */ 145 /** start-datetime of selection */
146 QDateTime selectionStart() {return mTimeSpanBegin;} 146 QDateTime selectionStart() {return mTimeSpanBegin;}
147 /** end-datetime of selection */ 147 /** end-datetime of selection */
148 QDateTime selectionEnd() {return mTimeSpanEnd;} 148 QDateTime selectionEnd() {return mTimeSpanEnd;}
149 /** returns true if selection is for whole day */ 149 /** returns true if selection is for whole day */
150 bool selectedIsAllDay() {return mTimeSpanInAllDay;} 150 bool selectedIsAllDay() {return mTimeSpanInAllDay;}
151 /** make selected start/end invalid */ 151 /** make selected start/end invalid */
152 void deleteSelectedDateTime(); 152 void deleteSelectedDateTime();
153 void repaintAgenda(); 153 void repaintAgenda();
154 public slots: 154 public slots:
155 virtual void updateView(); 155 virtual void updateView();
156 virtual void updateConfig(); 156 virtual void updateConfig();
157 virtual void showDates(const QDate &start, const QDate &end); 157 virtual void showDates(const QDate &start, const QDate &end);
158 virtual void showEvents(QPtrList<Event> eventList); 158 virtual void showEvents(QPtrList<Event> eventList);
159 159
160 void updateTodo( Todo *, int ); 160 void updateTodo( Todo *, int );
161 void changeEventDisplay(Event *, int); 161 void changeEventDisplay(Event *, int);
162 162
163 void clearSelection(); 163 void clearSelection();
164 164
165 void newTodo(int gx,int gy);
165 void newEvent(int gx,int gy); 166 void newEvent(int gx,int gy);
166 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd); 167 void newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd);
167 void newEventAllDay(int gx, int gy); 168 void newEventAllDay(int gx, int gy);
169 void newTodoAllDay(int gx, int gy);
168 170
169 void startDrag(Event *); 171 void startDrag(Event *);
170 172
171 void readSettings(); 173 void readSettings();
172 void readSettings(KConfig *); 174 void readSettings(KConfig *);
173 void writeSettings(KConfig *); 175 void writeSettings(KConfig *);
174 176
175 void setContentsPos(int y); 177 void setContentsPos(int y);
176 178
177 void setExpandedButton( bool expanded ); 179 void setExpandedButton( bool expanded );
178 void scrollOneHourUp(); 180 void scrollOneHourUp();
179 void scrollOneHourDown(); 181 void scrollOneHourDown();
180 void addToCalSlot(Incidence *, Incidence *); 182 void addToCalSlot(Incidence *, Incidence *);
181 183
182 signals: 184 signals:
185 void newTodoSignal( QDateTime ,bool );
183 void toggleExpand(); 186 void toggleExpand();
184 void todoMoved( Todo *, int ); 187 void todoMoved( Todo *, int );
185 void incidenceChanged(Incidence * , int ); 188 void incidenceChanged(Incidence * , int );
186 // void cloneIncidenceSignal(Incidence *); 189 // void cloneIncidenceSignal(Incidence *);
187 190
188 protected: 191 protected:
189 bool mBlockUpdating; 192 bool mBlockUpdating;
190 int mUpcomingWidth; 193 int mUpcomingWidth;
191 /** Fill agenda beginning with date startDate */ 194 /** Fill agenda beginning with date startDate */
192 void fillAgenda(const QDate &startDate); 195 void fillAgenda(const QDate &startDate);
193 void resizeEvent( QResizeEvent* e ); 196 void resizeEvent( QResizeEvent* e );
194 /** Fill agenda using the current set value for the start date */ 197 /** Fill agenda using the current set value for the start date */
195 void fillAgenda(); 198 void fillAgenda();
196 199
197 /** Create labels for the selected dates. */ 200 /** Create labels for the selected dates. */
198 void createDayLabels(); 201 void createDayLabels();
199 202
200 /** 203 /**
201 Set the masks on the agenda widgets indicating, which days are holidays. 204 Set the masks on the agenda widgets indicating, which days are holidays.
202 */ 205 */
203 void setHolidayMasks(); 206 void setHolidayMasks();
204 207
205 protected slots: 208 protected slots:
206 /** Update event belonging to agenda item */ 209 /** Update event belonging to agenda item */
207 void updateEventDates(KOAgendaItem *item, int mode = -1); 210 void updateEventDates(KOAgendaItem *item, int mode = -1);
208 //void updateMovedTodo(); 211 //void updateMovedTodo();
209 212
210 void updateEventIndicatorTop(int newY); 213 void updateEventIndicatorTop(int newY);
211 void updateEventIndicatorBottom(int newY); 214 void updateEventIndicatorBottom(int newY);
212 215
213 /** Updates data for selected timespan */ 216 /** Updates data for selected timespan */
214 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd); 217 void newTimeSpanSelected(int gxStart, int gyStart, int gxEnd, int gyEnd);
215 /** Updates data for selected timespan for all day event*/ 218 /** Updates data for selected timespan for all day event*/
216 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd); 219 void newTimeSpanSelectedAllDay(int gxStart, int gyStart, int gxEnd, int gyEnd);
217 220
218 private: 221 private:
219 // view widgets 222 // view widgets
220 QFrame *mDayLabels; 223 QFrame *mDayLabels;
221 QHBox *mDayLabelsFrame; 224 QHBox *mDayLabelsFrame;
222 QBoxLayout *mLayoutDayLabels; 225 QBoxLayout *mLayoutDayLabels;
223 QFrame *mAllDayFrame; 226 QFrame *mAllDayFrame;
224 KOAgenda *mAllDayAgenda; 227 KOAgenda *mAllDayAgenda;
225 KOAgenda *mAgenda; 228 KOAgenda *mAgenda;
226 TimeLabels *mTimeLabels; 229 TimeLabels *mTimeLabels;
227 QWidget *mDummyAllDayLeft; 230 QWidget *mDummyAllDayLeft;
228 231
229 KDGanttMinimizeSplitter* mSplitterAgenda; 232 KDGanttMinimizeSplitter* mSplitterAgenda;
230 QPushButton *mExpandButton; 233 QPushButton *mExpandButton;
231 234
232 DateList mSelectedDates; // List of dates to be displayed 235 DateList mSelectedDates; // List of dates to be displayed
233 int mViewType; 236 int mViewType;
234 237
235 bool mWeekStartsMonday; 238 bool mWeekStartsMonday;
236 int mStartHour; 239 int mStartHour;
237 240
238 KOEventPopupMenu *mAgendaPopup; 241 KOEventPopupMenu *mAgendaPopup;
239 KOEventPopupMenu *mAllDayAgendaPopup; 242 KOEventPopupMenu *mAllDayAgendaPopup;
240 243
241 EventIndicator *mEventIndicatorTop; 244 EventIndicator *mEventIndicatorTop;
242 EventIndicator *mEventIndicatorBottom; 245 EventIndicator *mEventIndicatorBottom;
243 246
244 QMemArray<int> mMinY; 247 QMemArray<int> mMinY;
245 QMemArray<int> mMaxY; 248 QMemArray<int> mMaxY;
246 249
247 QMemArray<bool> mHolidayMask; 250 QMemArray<bool> mHolidayMask;
248 251
249 QPixmap mExpandedPixmap; 252 QPixmap mExpandedPixmap;
250 QPixmap mNotExpandedPixmap; 253 QPixmap mNotExpandedPixmap;
251 QPtrList<QLabel> mDayLabelsList; 254 QPtrList<QLabel> mDayLabelsList;
252 QDateTime mTimeSpanBegin; 255 QDateTime mTimeSpanBegin;
253 QDateTime mTimeSpanEnd; 256 QDateTime mTimeSpanEnd;
254 bool mTimeSpanInAllDay; 257 bool mTimeSpanInAllDay;
255 void keyPressEvent ( QKeyEvent * e ); 258 void keyPressEvent ( QKeyEvent * e );
256}; 259};
257 260
258#endif // KOAGENDAVIEW_H 261#endif // KOAGENDAVIEW_H
diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp
index 158a7d3..b9a028b 100644
--- a/korganizer/koeditorgeneraltodo.cpp
+++ b/korganizer/koeditorgeneraltodo.cpp
@@ -1,454 +1,459 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 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 <qtooltip.h> 24#include <qtooltip.h>
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32 32
33#include <kglobal.h> 33#include <kglobal.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <kmessagebox.h> 36#include <kmessagebox.h>
37#include <kdebug.h> 37#include <kdebug.h>
38#include <krestrictedline.h> 38#include <krestrictedline.h>
39#include <kstandarddirs.h> 39#include <kstandarddirs.h>
40#include <kfiledialog.h> 40#include <kfiledialog.h>
41 41
42#include <libkcal/todo.h> 42#include <libkcal/todo.h>
43 43
44#include <libkdepim/kdateedit.h> 44#include <libkdepim/kdateedit.h>
45 45
46#include "koprefs.h" 46#include "koprefs.h"
47#include "ktimeedit.h" 47#include "ktimeedit.h"
48 48
49#include "koeditorgeneraltodo.h" 49#include "koeditorgeneraltodo.h"
50#include "kolocationbox.h" 50#include "kolocationbox.h"
51 51
52KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent, 52KOEditorGeneralTodo::KOEditorGeneralTodo(QObject* parent,
53 const char* name) 53 const char* name)
54 : KOEditorGeneral( parent, name) 54 : KOEditorGeneral( parent, name)
55{ 55{
56} 56}
57 57
58KOEditorGeneralTodo::~KOEditorGeneralTodo() 58KOEditorGeneralTodo::~KOEditorGeneralTodo()
59{ 59{
60} 60}
61 61
62void KOEditorGeneralTodo::finishSetup() 62void KOEditorGeneralTodo::finishSetup()
63{ 63{
64 64
65// QWidget::setTabOrder(mSummaryEdit, mLocationEdit); 65// QWidget::setTabOrder(mSummaryEdit, mLocationEdit);
66// QWidget::setTabOrder(mLocationEdit, mDueCheck); 66// QWidget::setTabOrder(mLocationEdit, mDueCheck);
67// QWidget::setTabOrder(mDueCheck, mDueDateEdit); 67// QWidget::setTabOrder(mDueCheck, mDueDateEdit);
68// QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit); 68// QWidget::setTabOrder(mDueDateEdit, mDueTimeEdit);
69// QWidget::setTabOrder(mDueTimeEdit, mStartCheck); 69// QWidget::setTabOrder(mDueTimeEdit, mStartCheck);
70// QWidget::setTabOrder(mStartCheck, mStartDateEdit); 70// QWidget::setTabOrder(mStartCheck, mStartDateEdit);
71// QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit); 71// QWidget::setTabOrder(mStartDateEdit, mStartTimeEdit);
72// QWidget::setTabOrder(mStartTimeEdit, mTimeButton); 72// QWidget::setTabOrder(mStartTimeEdit, mTimeButton);
73// QWidget::setTabOrder(mTimeButton, mCompletedCombo); 73// QWidget::setTabOrder(mTimeButton, mCompletedCombo);
74// QWidget::setTabOrder(mCompletedCombo, mPriorityCombo); 74// QWidget::setTabOrder(mCompletedCombo, mPriorityCombo);
75// QWidget::setTabOrder(mPriorityCombo, mAlarmButton); 75// QWidget::setTabOrder(mPriorityCombo, mAlarmButton);
76// QWidget::setTabOrder(mAlarmButton, mCategoriesButton); 76// QWidget::setTabOrder(mAlarmButton, mCategoriesButton);
77// QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo); 77// QWidget::setTabOrder(mCategoriesButton, mSecrecyCombo);
78// QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit); 78// QWidget::setTabOrder(mSecrecyCombo, mDescriptionEdit);
79 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 79 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
80 mSummaryEdit->setFocus(); 80 mSummaryEdit->setFocus();
81} 81}
82 82
83void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout) 83void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout)
84{ 84{
85 QBoxLayout *timeLayout = new QVBoxLayout(topLayout); 85 QBoxLayout *timeLayout = new QVBoxLayout(topLayout);
86 86
87 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal, 87 QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal,
88 i18n("Date && Time"),parent); 88 i18n("Date && Time"),parent);
89 timeLayout->addWidget(timeGroupBox); 89 timeLayout->addWidget(timeGroupBox);
90 timeGroupBox->layout()->setSpacing( 0 ); 90 timeGroupBox->layout()->setSpacing( 0 );
91 timeGroupBox->layout()->setMargin( 5 ); 91 timeGroupBox->layout()->setMargin( 5 );
92 QFrame *timeBoxFrame = new QFrame(timeGroupBox); 92 QFrame *timeBoxFrame = new QFrame(timeGroupBox);
93 93
94 QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3); 94 QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3);
95 layoutTimeBox->setSpacing(topLayout->spacing()); 95 layoutTimeBox->setSpacing(topLayout->spacing());
96 layoutTimeBox->setColStretch( 1, 1 ); 96 layoutTimeBox->setColStretch( 1, 1 );
97 97
98 mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame); 98 mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame);
99 layoutTimeBox->addWidget(mDueCheck,0,0); 99 layoutTimeBox->addWidget(mDueCheck,0,0);
100 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool))); 100 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool)));
101 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm())); 101 connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm()));
102 102
103 103
104 mDueDateEdit = new KDateEdit(timeBoxFrame); 104 mDueDateEdit = new KDateEdit(timeBoxFrame);
105 layoutTimeBox->addWidget(mDueDateEdit,0,1); 105 layoutTimeBox->addWidget(mDueDateEdit,0,1);
106 106
107 mDueTimeEdit = new KOTimeEdit(timeBoxFrame); 107 mDueTimeEdit = new KOTimeEdit(timeBoxFrame);
108 layoutTimeBox->addWidget(mDueTimeEdit,0,2); 108 layoutTimeBox->addWidget(mDueTimeEdit,0,2);
109 109
110 110
111 mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame); 111 mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame);
112 layoutTimeBox->addWidget(mStartCheck,1,0); 112 layoutTimeBox->addWidget(mStartCheck,1,0);
113 connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool))); 113 connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool)));
114 114
115 mStartDateEdit = new KDateEdit(timeBoxFrame); 115 mStartDateEdit = new KDateEdit(timeBoxFrame);
116 layoutTimeBox->addWidget(mStartDateEdit,1,1); 116 layoutTimeBox->addWidget(mStartDateEdit,1,1);
117 117
118 mStartTimeEdit = new KOTimeEdit(timeBoxFrame); 118 mStartTimeEdit = new KOTimeEdit(timeBoxFrame);
119 layoutTimeBox->addWidget(mStartTimeEdit,1,2); 119 layoutTimeBox->addWidget(mStartTimeEdit,1,2);
120 120
121 121
122 mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame); 122 mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame);
123 layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1); 123 layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1);
124 124
125 connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool))); 125 connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool)));
126 126
127 // some more layouting 127 // some more layouting
128 //layoutTimeBox->setColStretch(3,1); 128 //layoutTimeBox->setColStretch(3,1);
129} 129}
130 130
131 131
132void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout) 132void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout)
133{ 133{
134 mCompletedCombo = new QComboBox(parent); 134 mCompletedCombo = new QComboBox(parent);
135 // xgettext:no-c-format 135 // xgettext:no-c-format
136 mCompletedCombo->insertItem(i18n(" 0 %")); 136 mCompletedCombo->insertItem(i18n(" 0 %"));
137 // xgettext:no-c-format 137 // xgettext:no-c-format
138 mCompletedCombo->insertItem(i18n(" 20 %")); 138 mCompletedCombo->insertItem(i18n(" 20 %"));
139 // xgettext:no-c-format 139 // xgettext:no-c-format
140 mCompletedCombo->insertItem(i18n(" 40 %")); 140 mCompletedCombo->insertItem(i18n(" 40 %"));
141 // xgettext:no-c-format 141 // xgettext:no-c-format
142 mCompletedCombo->insertItem(i18n(" 60 %")); 142 mCompletedCombo->insertItem(i18n(" 60 %"));
143 // xgettext:no-c-format 143 // xgettext:no-c-format
144 mCompletedCombo->insertItem(i18n(" 80 %")); 144 mCompletedCombo->insertItem(i18n(" 80 %"));
145 // xgettext:no-c-format 145 // xgettext:no-c-format
146 mCompletedCombo->insertItem(i18n("100 %")); 146 mCompletedCombo->insertItem(i18n("100 %"));
147 connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int))); 147 connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int)));
148 topLayout->addWidget(mCompletedCombo); 148 topLayout->addWidget(mCompletedCombo);
149 149
150 mCompletedLabel = new QLabel(i18n("completed"),parent); 150 mCompletedLabel = new QLabel(i18n("completed"),parent);
151 topLayout->addWidget(mCompletedLabel); 151 topLayout->addWidget(mCompletedLabel);
152} 152}
153 153
154void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout) 154void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout)
155{ 155{
156 156
157 QHBox* h = new QHBox ( parent ); 157 QHBox* h = new QHBox ( parent );
158 topLayout->addWidget( h ); 158 topLayout->addWidget( h );
159 QLabel *priorityLabel = new QLabel(i18n("Priority:"), h); 159 QLabel *priorityLabel = new QLabel(i18n("Priority:"), h);
160 // topLayout->addWidget(priorityLabel); 160 // topLayout->addWidget(priorityLabel);
161 161
162 mPriorityCombo = new QComboBox( h ); 162 mPriorityCombo = new QComboBox( h );
163 mPriorityCombo->insertItem(i18n("1 (high)")); 163 mPriorityCombo->insertItem(i18n("1 (high)"));
164 mPriorityCombo->insertItem(i18n("2")); 164 mPriorityCombo->insertItem(i18n("2"));
165 mPriorityCombo->insertItem(i18n("3")); 165 mPriorityCombo->insertItem(i18n("3"));
166 mPriorityCombo->insertItem(i18n("4")); 166 mPriorityCombo->insertItem(i18n("4"));
167 mPriorityCombo->insertItem(i18n("5 (low)")); 167 mPriorityCombo->insertItem(i18n("5 (low)"));
168 //topLayout->addWidget(mPriorityCombo); 168 //topLayout->addWidget(mPriorityCombo);
169} 169}
170 170
171void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout) 171void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout)
172{ 172{
173 QBoxLayout *statusLayout = new QHBoxLayout(topLayout); 173 QBoxLayout *statusLayout = new QHBoxLayout(topLayout);
174 174
175 initCompletion( parent, statusLayout ); 175 initCompletion( parent, statusLayout );
176 176
177 statusLayout->addStretch( 1 ); 177 statusLayout->addStretch( 1 );
178 178
179 initPriority( parent, statusLayout ); 179 initPriority( parent, statusLayout );
180} 180}
181 181
182void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay) 182void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay)
183{ 183{
184 184
185 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 185 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
186 mLocationEdit->load(KOLocationBox::LOCATION); 186 mLocationEdit->load(KOLocationBox::LOCATION);
187 KOEditorGeneral::setDefaults(allDay); 187 KOEditorGeneral::setDefaults(allDay);
188 188
189 mTimeButton->setChecked( !allDay ); 189 mTimeButton->setChecked( !allDay );
190 if(mTimeButton->isChecked()) { 190 if(mTimeButton->isChecked()) {
191 mTimeButton->setEnabled(true); 191 mTimeButton->setEnabled(true);
192 } 192 }
193 else { 193 else {
194 mTimeButton->setEnabled(false); 194 mTimeButton->setEnabled(false);
195 } 195 }
196 196
197 enableTimeEdits( !allDay ); 197 enableTimeEdits( !allDay );
198 198 if ( due.isValid() ) {
199 mDueCheck->setChecked(false); 199 mDueCheck->setChecked(true);
200 enableDueEdit(false); 200 enableDueEdit(true);
201 } else {
202 mDueCheck->setChecked(false);
203 enableDueEdit(false);
204 due = QDateTime::currentDateTime().addDays(7);
205 }
201 206
202 alarmDisable(true); 207 alarmDisable(true);
203 208
204 mStartCheck->setChecked(false); 209 mStartCheck->setChecked(false);
205 enableStartEdit(false); 210 enableStartEdit(false);
206 211
207 mDueDateEdit->setDate(due.date()); 212 mDueDateEdit->setDate(due.date());
208 mDueTimeEdit->setTime(due.time()); 213 mDueTimeEdit->setTime(due.time());
209 214 due = due.addDays(-7);
210 mStartDateEdit->setDate(QDate::currentDate()); 215 mStartDateEdit->setDate(due.date());
211 mStartTimeEdit->setTime(QTime::currentTime()); 216 mStartTimeEdit->setTime(due.time());
212 217
213 mPriorityCombo->setCurrentItem(2); 218 mPriorityCombo->setCurrentItem(2);
214 mCompletedLabel->setText(i18n("completed"));; 219 mCompletedLabel->setText(i18n("completed"));;
215 mCompletedCombo->setCurrentItem(0); 220 mCompletedCombo->setCurrentItem(0);
216} 221}
217 222
218void KOEditorGeneralTodo::readTodo(Todo *todo) 223void KOEditorGeneralTodo::readTodo(Todo *todo)
219{ 224{
220 225
221 mSummaryEdit->load(KOLocationBox::SUMMARYTODO); 226 mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
222 mLocationEdit->load(KOLocationBox::LOCATION); 227 mLocationEdit->load(KOLocationBox::LOCATION);
223 KOEditorGeneral::readIncidence(todo); 228 KOEditorGeneral::readIncidence(todo);
224 229
225 QDateTime dueDT; 230 QDateTime dueDT;
226 231
227 if (todo->hasDueDate()) { 232 if (todo->hasDueDate()) {
228 enableAlarmEdit(true); 233 enableAlarmEdit(true);
229 dueDT = todo->dtDue(); 234 dueDT = todo->dtDue();
230 mDueDateEdit->setDate(todo->dtDue().date()); 235 mDueDateEdit->setDate(todo->dtDue().date());
231 mDueTimeEdit->setTime(todo->dtDue().time()); 236 mDueTimeEdit->setTime(todo->dtDue().time());
232 mDueCheck->setChecked(true); 237 mDueCheck->setChecked(true);
233 } else { 238 } else {
234 alarmDisable(true); 239 alarmDisable(true);
235 mDueDateEdit->setEnabled(false); 240 mDueDateEdit->setEnabled(false);
236 mDueTimeEdit->setEnabled(false); 241 mDueTimeEdit->setEnabled(false);
237 mDueDateEdit->setDate(QDate::currentDate()); 242 mDueDateEdit->setDate(QDate::currentDate());
238 mDueTimeEdit->setTime(QTime::currentTime()); 243 mDueTimeEdit->setTime(QTime::currentTime());
239 mDueCheck->setChecked(false); 244 mDueCheck->setChecked(false);
240 } 245 }
241 246
242 if (todo->hasStartDate()) { 247 if (todo->hasStartDate()) {
243 mStartDateEdit->setDate(todo->dtStart().date()); 248 mStartDateEdit->setDate(todo->dtStart().date());
244 mStartTimeEdit->setTime(todo->dtStart().time()); 249 mStartTimeEdit->setTime(todo->dtStart().time());
245 mStartCheck->setChecked(true); 250 mStartCheck->setChecked(true);
246 } else { 251 } else {
247 mStartDateEdit->setEnabled(false); 252 mStartDateEdit->setEnabled(false);
248 mStartTimeEdit->setEnabled(false); 253 mStartTimeEdit->setEnabled(false);
249 mStartDateEdit->setDate(QDate::currentDate()); 254 mStartDateEdit->setDate(QDate::currentDate());
250 mStartTimeEdit->setTime(QTime::currentTime()); 255 mStartTimeEdit->setTime(QTime::currentTime());
251 mStartCheck->setChecked(false); 256 mStartCheck->setChecked(false);
252 } 257 }
253 258
254 mTimeButton->setChecked( !todo->doesFloat() ); 259 mTimeButton->setChecked( !todo->doesFloat() );
255 260
256 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); 261 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
257 if (todo->isCompleted() && todo->hasCompletedDate()) { 262 if (todo->isCompleted() && todo->hasCompletedDate()) {
258 mCompleted = todo->completed(); 263 mCompleted = todo->completed();
259 } 264 }
260 setCompletedDate(); 265 setCompletedDate();
261 266
262 mPriorityCombo->setCurrentItem(todo->priority()-1); 267 mPriorityCombo->setCurrentItem(todo->priority()-1);
263} 268}
264 269
265void KOEditorGeneralTodo::writeTodo(Todo *todo) 270void KOEditorGeneralTodo::writeTodo(Todo *todo)
266{ 271{
267 KOEditorGeneral::writeIncidence(todo); 272 KOEditorGeneral::writeIncidence(todo);
268 273
269 // temp. until something better happens. 274 // temp. until something better happens.
270 QString tmpStr; 275 QString tmpStr;
271 276
272 todo->setHasDueDate(mDueCheck->isChecked()); 277 todo->setHasDueDate(mDueCheck->isChecked());
273 todo->setHasStartDate(mStartCheck->isChecked()); 278 todo->setHasStartDate(mStartCheck->isChecked());
274 279
275 QDate tmpDate; 280 QDate tmpDate;
276 QTime tmpTime; 281 QTime tmpTime;
277 QDateTime tmpDT; 282 QDateTime tmpDT;
278 if ( mTimeButton->isChecked() ) { 283 if ( mTimeButton->isChecked() ) {
279 todo->setFloats(false); 284 todo->setFloats(false);
280 285
281 // set due date/time 286 // set due date/time
282 tmpDate = mDueDateEdit->date(); 287 tmpDate = mDueDateEdit->date();
283 tmpTime = mDueTimeEdit->getTime(); 288 tmpTime = mDueTimeEdit->getTime();
284 tmpDT.setDate(tmpDate); 289 tmpDT.setDate(tmpDate);
285 tmpDT.setTime(tmpTime); 290 tmpDT.setTime(tmpTime);
286 todo->setDtDue(tmpDT); 291 todo->setDtDue(tmpDT);
287 292
288 // set start date/time 293 // set start date/time
289 tmpDate = mStartDateEdit->date(); 294 tmpDate = mStartDateEdit->date();
290 tmpTime = mStartTimeEdit->getTime(); 295 tmpTime = mStartTimeEdit->getTime();
291 tmpDT.setDate(tmpDate); 296 tmpDT.setDate(tmpDate);
292 tmpDT.setTime(tmpTime); 297 tmpDT.setTime(tmpTime);
293 todo->setDtStart(tmpDT); 298 todo->setDtStart(tmpDT);
294 } else { 299 } else {
295 todo->setFloats(true); 300 todo->setFloats(true);
296 301
297 // need to change this. 302 // need to change this.
298 tmpDate = mDueDateEdit->date(); 303 tmpDate = mDueDateEdit->date();
299 tmpTime.setHMS(0,0,0); 304 tmpTime.setHMS(0,0,0);
300 tmpDT.setDate(tmpDate); 305 tmpDT.setDate(tmpDate);
301 tmpDT.setTime(tmpTime); 306 tmpDT.setTime(tmpTime);
302 todo->setDtDue(tmpDT); 307 todo->setDtDue(tmpDT);
303 308
304 tmpDate = mStartDateEdit->date(); 309 tmpDate = mStartDateEdit->date();
305 tmpTime.setHMS(0,0,0); 310 tmpTime.setHMS(0,0,0);
306 tmpDT.setDate(tmpDate); 311 tmpDT.setDate(tmpDate);
307 tmpDT.setTime(tmpTime); 312 tmpDT.setTime(tmpTime);
308 todo->setDtStart(tmpDT); 313 todo->setDtStart(tmpDT);
309 } 314 }
310 315
311 todo->setPriority(mPriorityCombo->currentItem()+1); 316 todo->setPriority(mPriorityCombo->currentItem()+1);
312 317
313 // set completion state 318 // set completion state
314 todo->setPercentComplete(mCompletedCombo->currentItem() * 20); 319 todo->setPercentComplete(mCompletedCombo->currentItem() * 20);
315 320
316 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { 321 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
317 todo->setCompleted(mCompleted); 322 todo->setCompleted(mCompleted);
318 } 323 }
319 mSummaryEdit->save(KOLocationBox::SUMMARYTODO); 324 mSummaryEdit->save(KOLocationBox::SUMMARYTODO);
320} 325}
321 326
322void KOEditorGeneralTodo::enableDueEdit(bool enable) 327void KOEditorGeneralTodo::enableDueEdit(bool enable)
323{ 328{
324 mDueDateEdit->setEnabled( enable ); 329 mDueDateEdit->setEnabled( enable );
325 330
326 if(mDueCheck->isChecked() || mStartCheck->isChecked()) { 331 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
327 mTimeButton->setEnabled(true); 332 mTimeButton->setEnabled(true);
328 } 333 }
329 else { 334 else {
330 mTimeButton->setEnabled(false); 335 mTimeButton->setEnabled(false);
331 mTimeButton->setChecked(false); 336 mTimeButton->setChecked(false);
332 } 337 }
333 338
334 if (enable) { 339 if (enable) {
335 mDueTimeEdit->setEnabled( mTimeButton->isChecked() ); 340 mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
336 } else { 341 } else {
337 mDueTimeEdit->setEnabled( false ); 342 mDueTimeEdit->setEnabled( false );
338 } 343 }
339} 344}
340 345
341void KOEditorGeneralTodo::enableStartEdit( bool enable ) 346void KOEditorGeneralTodo::enableStartEdit( bool enable )
342{ 347{
343 mStartDateEdit->setEnabled( enable ); 348 mStartDateEdit->setEnabled( enable );
344 349
345 if(mDueCheck->isChecked() || mStartCheck->isChecked()) { 350 if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
346 mTimeButton->setEnabled(true); 351 mTimeButton->setEnabled(true);
347 } 352 }
348 else { 353 else {
349 mTimeButton->setEnabled(false); 354 mTimeButton->setEnabled(false);
350 mTimeButton->setChecked(false); 355 mTimeButton->setChecked(false);
351 } 356 }
352 357
353 if (enable) { 358 if (enable) {
354 mStartTimeEdit->setEnabled( mTimeButton->isChecked() ); 359 mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
355 } else { 360 } else {
356 mStartTimeEdit->setEnabled( false ); 361 mStartTimeEdit->setEnabled( false );
357 } 362 }
358} 363}
359 364
360void KOEditorGeneralTodo::enableTimeEdits(bool enable) 365void KOEditorGeneralTodo::enableTimeEdits(bool enable)
361{ 366{
362 if(mStartCheck->isChecked()) { 367 if(mStartCheck->isChecked()) {
363 mStartTimeEdit->setEnabled( enable ); 368 mStartTimeEdit->setEnabled( enable );
364 } 369 }
365 if(mDueCheck->isChecked()) { 370 if(mDueCheck->isChecked()) {
366 mDueTimeEdit->setEnabled( enable ); 371 mDueTimeEdit->setEnabled( enable );
367 } 372 }
368} 373}
369 374
370void KOEditorGeneralTodo::showAlarm() 375void KOEditorGeneralTodo::showAlarm()
371{ 376{
372 if ( mDueCheck->isChecked() ) { 377 if ( mDueCheck->isChecked() ) {
373 alarmDisable(false); 378 alarmDisable(false);
374 } 379 }
375 else { 380 else {
376 alarmDisable(true); 381 alarmDisable(true);
377 } 382 }
378} 383}
379 384
380bool KOEditorGeneralTodo::validateInput() 385bool KOEditorGeneralTodo::validateInput()
381{ 386{
382 if (mDueCheck->isChecked()) { 387 if (mDueCheck->isChecked()) {
383 if (!mDueDateEdit->inputIsValid()) { 388 if (!mDueDateEdit->inputIsValid()) {
384 KMessageBox::sorry(0,i18n("Please specify a valid due date.")); 389 KMessageBox::sorry(0,i18n("Please specify a valid due date."));
385 return false; 390 return false;
386 } 391 }
387 } 392 }
388 393
389 if (mStartCheck->isChecked()) { 394 if (mStartCheck->isChecked()) {
390 if (!mStartDateEdit->inputIsValid()) { 395 if (!mStartDateEdit->inputIsValid()) {
391 KMessageBox::sorry(0,i18n("Please specify a valid start date.")); 396 KMessageBox::sorry(0,i18n("Please specify a valid start date."));
392 return false; 397 return false;
393 } 398 }
394 } 399 }
395 400
396 if (mStartCheck->isChecked() && mDueCheck->isChecked()) { 401 if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
397 QDateTime startDate; 402 QDateTime startDate;
398 QDateTime dueDate; 403 QDateTime dueDate;
399 startDate.setDate(mStartDateEdit->date()); 404 startDate.setDate(mStartDateEdit->date());
400 dueDate.setDate(mDueDateEdit->date()); 405 dueDate.setDate(mDueDateEdit->date());
401 if (mTimeButton->isChecked()) { 406 if (mTimeButton->isChecked()) {
402 startDate.setTime(mStartTimeEdit->getTime()); 407 startDate.setTime(mStartTimeEdit->getTime());
403 dueDate.setTime(mDueTimeEdit->getTime()); 408 dueDate.setTime(mDueTimeEdit->getTime());
404 } 409 }
405 if (startDate > dueDate) { 410 if (startDate > dueDate) {
406 KMessageBox::sorry(0, 411 KMessageBox::sorry(0,
407 i18n("The start date cannot be after the due date.")); 412 i18n("The start date cannot be after the due date."));
408 return false; 413 return false;
409 } 414 }
410 } 415 }
411 416
412 return KOEditorGeneral::validateInput(); 417 return KOEditorGeneral::validateInput();
413} 418}
414 419
415void KOEditorGeneralTodo::completedChanged(int index) 420void KOEditorGeneralTodo::completedChanged(int index)
416{ 421{
417 if (index == 5) { 422 if (index == 5) {
418 mCompleted = QDateTime::currentDateTime(); 423 mCompleted = QDateTime::currentDateTime();
419 } 424 }
420 setCompletedDate(); 425 setCompletedDate();
421} 426}
422 427
423void KOEditorGeneralTodo::setCompletedDate() 428void KOEditorGeneralTodo::setCompletedDate()
424{ 429{
425 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) { 430 if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
426 mCompletedLabel->setText(i18n("completed on %1") 431 mCompletedLabel->setText(i18n("completed on %1")
427 .arg(KGlobal::locale()->formatDateTime(mCompleted))); 432 .arg(KGlobal::locale()->formatDateTime(mCompleted)));
428 } else { 433 } else {
429 mCompletedLabel->setText(i18n("completed")); 434 mCompletedLabel->setText(i18n("completed"));
430 } 435 }
431} 436}
432 437
433void KOEditorGeneralTodo::modified (Todo* todo, int modification) 438void KOEditorGeneralTodo::modified (Todo* todo, int modification)
434{ 439{
435 switch (modification) { 440 switch (modification) {
436 case KOGlobals::PRIORITY_MODIFIED: 441 case KOGlobals::PRIORITY_MODIFIED:
437 mPriorityCombo->setCurrentItem(todo->priority()-1); 442 mPriorityCombo->setCurrentItem(todo->priority()-1);
438 break; 443 break;
439 case KOGlobals::COMPLETION_MODIFIED: 444 case KOGlobals::COMPLETION_MODIFIED:
440 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20); 445 mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
441 if (todo->isCompleted() && todo->hasCompletedDate()) { 446 if (todo->isCompleted() && todo->hasCompletedDate()) {
442 mCompleted = todo->completed(); 447 mCompleted = todo->completed();
443 } 448 }
444 setCompletedDate(); 449 setCompletedDate();
445 break; 450 break;
446 case KOGlobals::CATEGORY_MODIFIED: 451 case KOGlobals::CATEGORY_MODIFIED:
447 setCategories (todo->categoriesStr ()); 452 setCategories (todo->categoriesStr ());
448 break; 453 break;
449 case KOGlobals::UNKNOWN_MODIFIED: // fall through 454 case KOGlobals::UNKNOWN_MODIFIED: // fall through
450 default: 455 default:
451 readTodo( todo ); 456 readTodo( todo );
452 break; 457 break;
453 } 458 }
454} 459}
diff --git a/korganizer/koviewmanager.cpp b/korganizer/koviewmanager.cpp
index e8d5ab1..a88276e 100644
--- a/korganizer/koviewmanager.cpp
+++ b/korganizer/koviewmanager.cpp
@@ -1,594 +1,599 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001 4 Copyright (c) 2001
5 Cornelius Schumacher <schumacher@kde.org> 5 Cornelius Schumacher <schumacher@kde.org>
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 <qwidgetstack.h> 26#include <qwidgetstack.h>
27 27
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#ifndef DESKTOP_VERSION 30#ifndef DESKTOP_VERSION
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#else 32#else
33#include <qapplication.h> 33#include <qapplication.h>
34#endif 34#endif
35#include <qdatetime.h> 35#include <qdatetime.h>
36#include "calendarview.h" 36#include "calendarview.h"
37#include "datenavigator.h" 37#include "datenavigator.h"
38#include "kotodoview.h" 38#include "kotodoview.h"
39#include "koagendaview.h" 39#include "koagendaview.h"
40#include "kodialogmanager.h" 40#include "kodialogmanager.h"
41#include "komonthview.h" 41#include "komonthview.h"
42#include "kolistview.h" 42#include "kolistview.h"
43#include "kowhatsnextview.h" 43#include "kowhatsnextview.h"
44#include "kojournalview.h" 44#include "kojournalview.h"
45#include "kotimespanview.h" 45#include "kotimespanview.h"
46#include "koprefs.h" 46#include "koprefs.h"
47#include "navigatorbar.h" 47#include "navigatorbar.h"
48#include "kdatenavigator.h" 48#include "kdatenavigator.h"
49 49
50#include "koviewmanager.h" 50#include "koviewmanager.h"
51//extern bool externFlagMonthviewBlockPainting; 51//extern bool externFlagMonthviewBlockPainting;
52 52
53//bool globalFlagBlockPainting = false; 53//bool globalFlagBlockPainting = false;
54int globalFlagBlockAgenda = 0; 54int globalFlagBlockAgenda = 0;
55int globalFlagBlockLabel = 0; 55int globalFlagBlockLabel = 0;
56int globalFlagBlockAgendaItemPaint = 1; 56int globalFlagBlockAgendaItemPaint = 1;
57int globalFlagBlockAgendaItemUpdate = 1; 57int globalFlagBlockAgendaItemUpdate = 1;
58 58
59 59
60KOViewManager::KOViewManager( CalendarView *mainView ) : 60KOViewManager::KOViewManager( CalendarView *mainView ) :
61 QObject(), mMainView( mainView ) 61 QObject(), mMainView( mainView )
62{ 62{
63 mCurrentView = 0; 63 mCurrentView = 0;
64 64
65 mWhatsNextView = 0; 65 mWhatsNextView = 0;
66 mTodoView = 0; 66 mTodoView = 0;
67 mAgendaView = 0; 67 mAgendaView = 0;
68 mMonthView = 0; 68 mMonthView = 0;
69 mListView = 0; 69 mListView = 0;
70 mJournalView = 0; 70 mJournalView = 0;
71 mTimeSpanView = 0; 71 mTimeSpanView = 0;
72 mCurrentAgendaView = 0 ; 72 mCurrentAgendaView = 0 ;
73 mFlagShowNextxDays = false; 73 mFlagShowNextxDays = false;
74} 74}
75 75
76KOViewManager::~KOViewManager() 76KOViewManager::~KOViewManager()
77{ 77{
78} 78}
79 79
80 80
81KOrg::BaseView *KOViewManager::currentView() 81KOrg::BaseView *KOViewManager::currentView()
82{ 82{
83 return mCurrentView; 83 return mCurrentView;
84} 84}
85 85
86void KOViewManager::readSettings(KConfig *config) 86void KOViewManager::readSettings(KConfig *config)
87{ 87{
88 config->setGroup("General"); 88 config->setGroup("General");
89 QString view = config->readEntry("Current View"); 89 QString view = config->readEntry("Current View");
90 if (view == "WhatsNext") showWhatsNextView(); 90 if (view == "WhatsNext") showWhatsNextView();
91 else if (view == "Month") showMonthView(); 91 else if (view == "Month") showMonthView();
92 else if (view == "List") showListView(); 92 else if (view == "List") showListView();
93 else if (view == "Journal") showJournalView(); 93 else if (view == "Journal") showJournalView();
94 else if (view == "TimeSpan") showTimeSpanView(); 94 else if (view == "TimeSpan") showTimeSpanView();
95 else if (view == "Todo") showTodoView(); 95 else if (view == "Todo") showTodoView();
96 else { 96 else {
97 showAgendaView(); 97 showAgendaView();
98 } 98 }
99} 99}
100 100
101void KOViewManager::writeSettings(KConfig *config) 101void KOViewManager::writeSettings(KConfig *config)
102{ 102{
103 config->setGroup("General"); 103 config->setGroup("General");
104 104
105 QString view; 105 QString view;
106 if (mCurrentView == mWhatsNextView) view = "WhatsNext"; 106 if (mCurrentView == mWhatsNextView) view = "WhatsNext";
107 else if (mCurrentView == mMonthView) view = "Month"; 107 else if (mCurrentView == mMonthView) view = "Month";
108 else if (mCurrentView == mListView) view = "List"; 108 else if (mCurrentView == mListView) view = "List";
109 else if (mCurrentView == mJournalView) view = "Journal"; 109 else if (mCurrentView == mJournalView) view = "Journal";
110 else if (mCurrentView == mTimeSpanView) view = "TimeSpan"; 110 else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
111 else if (mCurrentView == mTodoView) view = "Todo"; 111 else if (mCurrentView == mTodoView) view = "Todo";
112 else view = "Agenda"; 112 else view = "Agenda";
113 113
114 config->writeEntry("Current View",view); 114 config->writeEntry("Current View",view);
115 115
116 if (mAgendaView) { 116 if (mAgendaView) {
117 mAgendaView->writeSettings(config); 117 mAgendaView->writeSettings(config);
118 } 118 }
119 if (mTimeSpanView) { 119 if (mTimeSpanView) {
120 mTimeSpanView->writeSettings(config); 120 mTimeSpanView->writeSettings(config);
121 } 121 }
122 if (mListView) { 122 if (mListView) {
123 mListView->writeSettings(config); 123 mListView->writeSettings(config);
124 } 124 }
125 if (mTodoView) { 125 if (mTodoView) {
126 mTodoView->saveLayout(config,"Todo View"); 126 mTodoView->saveLayout(config,"Todo View");
127 } 127 }
128} 128}
129 129
130void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen ) 130void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen )
131{ 131{
132 132
133 //mFlagShowNextxDays = false; 133 //mFlagShowNextxDays = false;
134 //if(view == mCurrentView) return; 134 //if(view == mCurrentView) return;
135 if ( view == 0 ) { 135 if ( view == 0 ) {
136 view = mCurrentView; 136 view = mCurrentView;
137 if ( view == 0 ) 137 if ( view == 0 )
138 return; 138 return;
139 } 139 }
140 bool full = fullScreen; 140 bool full = fullScreen;
141 if(view == mCurrentView && view != mWhatsNextView ) { 141 if(view == mCurrentView && view != mWhatsNextView ) {
142 if ( mCurrentAgendaView < 0 ) 142 if ( mCurrentAgendaView < 0 )
143 return; 143 return;
144 full = mMainView->leftFrame()->isVisible(); 144 full = mMainView->leftFrame()->isVisible();
145 } else { 145 } else {
146 mCurrentView = view; 146 mCurrentView = view;
147 147
148 // bool full = fullScreen; 148 // bool full = fullScreen;
149 bool isFull = !mMainView->leftFrame()->isVisible(); 149 bool isFull = !mMainView->leftFrame()->isVisible();
150 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen ) 150 if ( isFull && KOPrefs::instance()->mViewChangeHoldFullscreen )
151 full = true; 151 full = true;
152 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen ) 152 if ( !isFull && KOPrefs::instance()->mViewChangeHoldNonFullscreen )
153 full = false; 153 full = false;
154 } 154 }
155 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime(); 155 if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
156 //raiseCurrentView( full ); 156 //raiseCurrentView( full );
157 mMainView->processIncidenceSelection( 0 ); 157 mMainView->processIncidenceSelection( 0 );
158 mMainView->updateView(); 158 mMainView->updateView();
159 raiseCurrentView( full ); 159 raiseCurrentView( full );
160 mMainView->adaptNavigationUnits(); 160 mMainView->adaptNavigationUnits();
161} 161}
162 162
163void KOViewManager::raiseCurrentView( bool fullScreen ) 163void KOViewManager::raiseCurrentView( bool fullScreen )
164{ 164{
165 //qDebug("raiseCurrentView "); 165 //qDebug("raiseCurrentView ");
166 mCurrentAgendaView = 0; 166 mCurrentAgendaView = 0;
167 int wid = mMainView->width() ; 167 int wid = mMainView->width() ;
168 int hei = mMainView->height(); 168 int hei = mMainView->height();
169 if ( mCurrentView == mMonthView ) { 169 if ( mCurrentView == mMonthView ) {
170 mMainView->navigatorBar()->show(); 170 mMainView->navigatorBar()->show();
171 hei -= mMainView->navigatorBar()->sizeHint().height(); 171 hei -= mMainView->navigatorBar()->sizeHint().height();
172 //mMainView->navigatorBar()->hide(); 172 //mMainView->navigatorBar()->hide();
173 } else { 173 } else {
174 mMainView->navigatorBar()->hide(); 174 mMainView->navigatorBar()->hide();
175 } 175 }
176 if ( fullScreen ) { 176 if ( fullScreen ) {
177 mMainView->leftFrame()->hide(); 177 mMainView->leftFrame()->hide();
178 } else { 178 } else {
179 mMainView->leftFrame()->show(); 179 mMainView->leftFrame()->show();
180 if ( KOPrefs::instance()->mVerticalScreen ) 180 if ( KOPrefs::instance()->mVerticalScreen )
181 hei -= mMainView->leftFrame()->height(); 181 hei -= mMainView->leftFrame()->height();
182 else 182 else
183 wid -= mMainView->leftFrame()->width(); 183 wid -= mMainView->leftFrame()->width();
184 } 184 }
185 emit signalFullScreen( !fullScreen ); 185 emit signalFullScreen( !fullScreen );
186 if ( globalFlagBlockAgenda == 5 ) { 186 if ( globalFlagBlockAgenda == 5 ) {
187 globalFlagBlockAgenda = 4; 187 globalFlagBlockAgenda = 4;
188 globalFlagBlockAgendaItemPaint = 1; 188 globalFlagBlockAgendaItemPaint = 1;
189 } 189 }
190 mMainView->viewStack()->raiseWidget(mCurrentView); 190 mMainView->viewStack()->raiseWidget(mCurrentView);
191 if ( globalFlagBlockAgenda == 4 ) { 191 if ( globalFlagBlockAgenda == 4 ) {
192 if ( mCurrentView == mAgendaView ) { 192 if ( mCurrentView == mAgendaView ) {
193 //globalFlagBlockAgenda =1 ; 193 //globalFlagBlockAgenda =1 ;
194 if ( KOPrefs::instance()->mSetTimeToDayStartAt ) 194 if ( KOPrefs::instance()->mSetTimeToDayStartAt )
195 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins ); 195 mAgendaView->setStartHour( KOPrefs::instance()->mDayBegins );
196 else if ( KOPrefs::instance()->mCenterOnCurrentTime ) 196 else if ( KOPrefs::instance()->mCenterOnCurrentTime )
197 mAgendaView->setStartHour( QTime::currentTime ().hour() ); 197 mAgendaView->setStartHour( QTime::currentTime ().hour() );
198 qApp->processEvents(); 198 qApp->processEvents();
199 //qDebug("qApp->processEvents() "); 199 //qDebug("qApp->processEvents() ");
200 globalFlagBlockAgenda = 0; 200 globalFlagBlockAgenda = 0;
201 mAgendaView->repaintAgenda(); 201 mAgendaView->repaintAgenda();
202 202
203 } 203 }
204 globalFlagBlockAgenda = 0; 204 globalFlagBlockAgenda = 0;
205 } 205 }
206 emit signalAgendaView( mCurrentView == mAgendaView ); 206 emit signalAgendaView( mCurrentView == mAgendaView );
207 //qDebug("raiseCurrentView ende "); 207 //qDebug("raiseCurrentView ende ");
208 208
209} 209}
210 210
211void KOViewManager::updateView() 211void KOViewManager::updateView()
212{ 212{
213 // qDebug("KOViewManager::updateView() "); 213 // qDebug("KOViewManager::updateView() ");
214 // if we are updating mTodoView, we get endless recursion 214 // if we are updating mTodoView, we get endless recursion
215 if ( mTodoView == mCurrentView ) 215 if ( mTodoView == mCurrentView )
216 return; 216 return;
217 if ( mCurrentView ) mCurrentView->updateView(); 217 if ( mCurrentView ) mCurrentView->updateView();
218 218
219} 219}
220 220
221void KOViewManager::updateView(const QDate &start, const QDate &end) 221void KOViewManager::updateView(const QDate &start, const QDate &end)
222{ 222{
223 // kdDebug() << "KOViewManager::updateView()" << endl; 223 // kdDebug() << "KOViewManager::updateView()" << endl;
224 224
225 if (mCurrentView) mCurrentView->showDates(start, end); 225 if (mCurrentView) mCurrentView->showDates(start, end);
226 226
227 if (mTodoView) mTodoView->updateView(); 227 if (mTodoView) mTodoView->updateView();
228} 228}
229 229
230 230
231void KOViewManager::updateWNview() 231void KOViewManager::updateWNview()
232{ 232{
233 if ( mCurrentView == mWhatsNextView && mWhatsNextView ) 233 if ( mCurrentView == mWhatsNextView && mWhatsNextView )
234 mWhatsNextView->updateView(); 234 mWhatsNextView->updateView();
235 235
236} 236}
237void KOViewManager::showWhatsNextView() 237void KOViewManager::showWhatsNextView()
238{ 238{
239 if (!mWhatsNextView) { 239 if (!mWhatsNextView) {
240 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(), 240 mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
241 "KOViewManager::WhatsNextView"); 241 "KOViewManager::WhatsNextView");
242 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog()); 242 mWhatsNextView->setEventViewer( mMainView->getEventViewerDialog());
243 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig())); 243 connect(mMainView, SIGNAL(configChanged()), mWhatsNextView, SLOT(updateConfig()));
244 addView(mWhatsNextView); 244 addView(mWhatsNextView);
245 connect(this, SIGNAL( printWNV() ), 245 connect(this, SIGNAL( printWNV() ),
246 mWhatsNextView, SLOT( printMe() ) ); 246 mWhatsNextView, SLOT( printMe() ) );
247 } 247 }
248 globalFlagBlockAgenda = 1; 248 globalFlagBlockAgenda = 1;
249 showView(mWhatsNextView, true ); 249 showView(mWhatsNextView, true );
250 //mWhatsNextView->updateView(); 250 //mWhatsNextView->updateView();
251 251
252} 252}
253 253
254void KOViewManager::showListView() 254void KOViewManager::showListView()
255{ 255{
256 if (!mListView) { 256 if (!mListView) {
257 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView"); 257 mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
258 addView(mListView); 258 addView(mListView);
259 259
260 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)), 260 connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)),
261 mMainView, SLOT(showIncidence(Incidence *))); 261 mMainView, SLOT(showIncidence(Incidence *)));
262 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)), 262 connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)),
263 mMainView, SLOT(editIncidence(Incidence *))); 263 mMainView, SLOT(editIncidence(Incidence *)));
264 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)), 264 connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)),
265 mMainView, SLOT(deleteIncidence(Incidence *))); 265 mMainView, SLOT(deleteIncidence(Incidence *)));
266 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ), 266 connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ),
267 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 267 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
268 connect( mListView, SIGNAL( signalNewEvent() ), 268 connect( mListView, SIGNAL( signalNewEvent() ),
269 mMainView, SLOT( newEvent() ) ); 269 mMainView, SLOT( newEvent() ) );
270 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig())); 270 connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig()));
271 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 271 connect( mListView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
272 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 272 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
273 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 273 connect( mListView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
274 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 274 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
275 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 275 connect( mListView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
276 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 276 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
277 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 277 connect( mListView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
278 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 278 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
279 } 279 }
280 // bool temp = mFlagShowNextxDays; 280 // bool temp = mFlagShowNextxDays;
281 //globalFlagBlockPainting = true; 281 //globalFlagBlockPainting = true;
282 globalFlagBlockAgenda = 1; 282 globalFlagBlockAgenda = 1;
283 if ( KOPrefs::instance()->mListViewMonthTimespan ) { 283 if ( KOPrefs::instance()->mListViewMonthTimespan ) {
284 mMainView->setBlockShowDates( true ); 284 mMainView->setBlockShowDates( true );
285 mMainView->dateNavigator()->selectMonth(); 285 mMainView->dateNavigator()->selectMonth();
286 mMainView->setBlockShowDates( false ); 286 mMainView->setBlockShowDates( false );
287 } 287 }
288 showView(mListView, KOPrefs::instance()->mFullViewTodo); 288 showView(mListView, KOPrefs::instance()->mFullViewTodo);
289 //mFlagShowNextxDays = temp; 289 //mFlagShowNextxDays = temp;
290} 290}
291 291
292void KOViewManager::showAgendaView( bool fullScreen ) 292void KOViewManager::showAgendaView( bool fullScreen )
293{ 293{
294 294
295 mMainView->dialogManager()->hideSearchDialog(); 295 mMainView->dialogManager()->hideSearchDialog();
296 // qDebug("KOViewManager::showAgendaView "); 296 // qDebug("KOViewManager::showAgendaView ");
297 bool full; 297 bool full;
298 full = fullScreen; 298 full = fullScreen;
299 if (!mAgendaView) { 299 if (!mAgendaView) {
300 full = false; 300 full = false;
301 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView"); 301 mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
302 addView(mAgendaView); 302 addView(mAgendaView);
303#ifndef DESKTOP_VERSION 303#ifndef DESKTOP_VERSION
304 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold ); 304 QPEApplication::setStylusOperation( mAgendaView, QPEApplication::RightOnHold );
305#endif 305#endif
306 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )), 306 connect( mAgendaView, SIGNAL( incidenceChanged(Incidence *, int )),
307 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) )); 307 mMainView, SLOT( changeIncidenceDisplay( Incidence *, int ) ));
308 308
309 // SIGNALS/SLOTS FOR DAY/WEEK VIEW 309 // SIGNALS/SLOTS FOR DAY/WEEK VIEW
310
311
312
313 connect(mAgendaView,SIGNAL(newTodoSignal(QDateTime,bool)),
314 mMainView, SLOT(newTodoDateTime(QDateTime,bool)));
310 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)), 315 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)),
311 mMainView, SLOT(newEvent(QDateTime))); 316 mMainView, SLOT(newEvent(QDateTime)));
312 // connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)), 317 connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)),
313 // mMainView, SLOT(newEvent(QDateTime,QDateTime))); 318 mMainView, SLOT(newEvent(QDateTime,QDateTime)));
314 connect(mAgendaView,SIGNAL(newEventSignal(QDate)), 319 connect(mAgendaView,SIGNAL(newEventSignal(QDate)),
315 mMainView, SLOT(newEvent(QDate))); 320 mMainView, SLOT(newEvent(QDate)));
316 321
317 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)), 322 connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)),
318 mMainView, SLOT(editIncidence(Incidence *))); 323 mMainView, SLOT(editIncidence(Incidence *)));
319 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)), 324 connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)),
320 mMainView, SLOT(showIncidence(Incidence *))); 325 mMainView, SLOT(showIncidence(Incidence *)));
321 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)), 326 connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)),
322 mMainView, SLOT(deleteIncidence(Incidence *))); 327 mMainView, SLOT(deleteIncidence(Incidence *)));
323 328
324 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ), 329 connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ),
325 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 330 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
326 331
327 connect(mAgendaView, SIGNAL( toggleExpand() ), 332 connect(mAgendaView, SIGNAL( toggleExpand() ),
328 mMainView, SLOT( toggleExpand() ) ); 333 mMainView, SLOT( toggleExpand() ) );
329 334
330 connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ), 335 connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
331 mAgendaView, SLOT( setExpandedButton( bool ) ) ); 336 mAgendaView, SLOT( setExpandedButton( bool ) ) );
332 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ), 337 connect( mAgendaView, SIGNAL( cloneIncidenceSignal(Incidence *) ),
333 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ; 338 mMainView, SLOT(cloneIncidence(Incidence *) ) ) ;
334 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ), 339 connect( mAgendaView, SIGNAL( cancelIncidenceSignal(Incidence *) ),
335 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ; 340 mMainView, SLOT(cancelIncidence(Incidence *) ) ) ;
336 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig())); 341 connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig()));
337 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView, 342 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mAgendaView,
338 SLOT( updateTodo( Todo *, int ) ) ); 343 SLOT( updateTodo( Todo *, int ) ) );
339 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )), 344 connect( mAgendaView,SIGNAL( todoMoved( Todo *, int )),
340 mMainView, SIGNAL( todoModified( Todo *, int ))); 345 mMainView, SIGNAL( todoModified( Todo *, int )));
341 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 346 connect( mAgendaView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
342 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 347 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
343 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 348 connect( mAgendaView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
344 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 349 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
345 mAgendaView->readSettings(); 350 mAgendaView->readSettings();
346 mAgendaView->updateConfig(); 351 mAgendaView->updateConfig();
347 } 352 }
348 353
349 showView( mAgendaView, full); 354 showView( mAgendaView, full);
350 355
351} 356}
352 357
353void KOViewManager::showDayView() 358void KOViewManager::showDayView()
354{ 359{
355 mFlagShowNextxDays = false; 360 mFlagShowNextxDays = false;
356 globalFlagBlockLabel = 1; 361 globalFlagBlockLabel = 1;
357 globalFlagBlockAgenda = 1; 362 globalFlagBlockAgenda = 1;
358 if ( mCurrentAgendaView != 1 ) 363 if ( mCurrentAgendaView != 1 )
359 mCurrentAgendaView = -1; 364 mCurrentAgendaView = -1;
360 showAgendaView(); 365 showAgendaView();
361 qApp->processEvents(); 366 qApp->processEvents();
362 globalFlagBlockAgenda = 2; 367 globalFlagBlockAgenda = 2;
363 globalFlagBlockLabel = 0; 368 globalFlagBlockLabel = 0;
364 mMainView->dateNavigator()->selectDates( 1 ); 369 mMainView->dateNavigator()->selectDates( 1 );
365 mCurrentAgendaView = 1 ; 370 mCurrentAgendaView = 1 ;
366 371
367} 372}
368 373
369void KOViewManager::showWorkWeekView() 374void KOViewManager::showWorkWeekView()
370{ 375{
371 mFlagShowNextxDays = false; 376 mFlagShowNextxDays = false;
372 globalFlagBlockAgenda = 1; 377 globalFlagBlockAgenda = 1;
373 globalFlagBlockLabel = 1; 378 globalFlagBlockLabel = 1;
374 if ( mCurrentAgendaView != 5 ) 379 if ( mCurrentAgendaView != 5 )
375 mCurrentAgendaView = -1; 380 mCurrentAgendaView = -1;
376 showAgendaView(); 381 showAgendaView();
377 qApp->processEvents(); 382 qApp->processEvents();
378 globalFlagBlockAgenda = 2; 383 globalFlagBlockAgenda = 2;
379 globalFlagBlockLabel = 0; 384 globalFlagBlockLabel = 0;
380 mMainView->dateNavigator()->selectWorkWeek(); 385 mMainView->dateNavigator()->selectWorkWeek();
381 mCurrentAgendaView = 5 ; 386 mCurrentAgendaView = 5 ;
382 387
383} 388}
384 389
385void KOViewManager::showWeekView() 390void KOViewManager::showWeekView()
386{ 391{
387 /* 392 /*
388 globalFlagBlockAgenda = 2; 393 globalFlagBlockAgenda = 2;
389 qDebug("4globalFlagBlockAgenda = 2; "); 394 qDebug("4globalFlagBlockAgenda = 2; ");
390 //globalFlagBlockPainting = true; 395 //globalFlagBlockPainting = true;
391 mMainView->dateNavigator()->selectWeek(); 396 mMainView->dateNavigator()->selectWeek();
392 showAgendaView(); 397 showAgendaView();
393 */ 398 */
394 399
395 400
396 mFlagShowNextxDays = false; 401 mFlagShowNextxDays = false;
397 globalFlagBlockAgenda = 1; 402 globalFlagBlockAgenda = 1;
398 globalFlagBlockLabel = 1; 403 globalFlagBlockLabel = 1;
399 if ( mCurrentAgendaView != 7 ) 404 if ( mCurrentAgendaView != 7 )
400 mCurrentAgendaView = -1; 405 mCurrentAgendaView = -1;
401 showAgendaView(); 406 showAgendaView();
402 qApp->processEvents(); 407 qApp->processEvents();
403 globalFlagBlockAgenda = 2; 408 globalFlagBlockAgenda = 2;
404 globalFlagBlockLabel = 0; 409 globalFlagBlockLabel = 0;
405 mMainView->dateNavigator()->selectWeek(); 410 mMainView->dateNavigator()->selectWeek();
406 mCurrentAgendaView = 7 ; 411 mCurrentAgendaView = 7 ;
407} 412}
408 413
409void KOViewManager::showNextXView() 414void KOViewManager::showNextXView()
410{ 415{
411 416
412 globalFlagBlockAgenda = 1; 417 globalFlagBlockAgenda = 1;
413 if ( mCurrentAgendaView != 3 ) 418 if ( mCurrentAgendaView != 3 )
414 mCurrentAgendaView = -1; 419 mCurrentAgendaView = -1;
415 showAgendaView(KOPrefs::instance()->mFullViewMonth); 420 showAgendaView(KOPrefs::instance()->mFullViewMonth);
416 globalFlagBlockAgenda = 2; 421 globalFlagBlockAgenda = 2;
417 mMainView->dateNavigator()->selectDates( QDate::currentDate(), 422 mMainView->dateNavigator()->selectDates( QDate::currentDate(),
418 KOPrefs::instance()->mNextXDays ); 423 KOPrefs::instance()->mNextXDays );
419 mFlagShowNextxDays = true; 424 mFlagShowNextxDays = true;
420 mCurrentAgendaView = 3 ; 425 mCurrentAgendaView = 3 ;
421} 426}
422bool KOViewManager::showsNextDays() 427bool KOViewManager::showsNextDays()
423{ 428{
424 return mFlagShowNextxDays; 429 return mFlagShowNextxDays;
425} 430}
426void KOViewManager::showMonthView() 431void KOViewManager::showMonthView()
427{ 432{
428 if (!mMonthView) { 433 if (!mMonthView) {
429 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView"); 434 mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
430 435
431 addView(mMonthView); 436 addView(mMonthView);
432 // mMonthView->show(); 437 // mMonthView->show();
433 // SIGNALS/SLOTS FOR MONTH VIEW 438 // SIGNALS/SLOTS FOR MONTH VIEW
434 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)), 439 connect(mMonthView, SIGNAL(newEventSignal(QDateTime)),
435 mMainView, SLOT(newEvent(QDateTime))); 440 mMainView, SLOT(newEvent(QDateTime)));
436 441
437 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)), 442 connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)),
438 mMainView, SLOT(showIncidence(Incidence *))); 443 mMainView, SLOT(showIncidence(Incidence *)));
439 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)), 444 connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)),
440 mMainView, SLOT(editIncidence(Incidence *))); 445 mMainView, SLOT(editIncidence(Incidence *)));
441 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)), 446 connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)),
442 mMainView, SLOT(deleteIncidence(Incidence *))); 447 mMainView, SLOT(deleteIncidence(Incidence *)));
443 448
444 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ), 449 connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ),
445 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 450 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
446 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ), 451 connect( mMonthView, SIGNAL( cloneIncidenceSignal( Incidence * ) ),
447 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 452 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
448 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ), 453 connect( mMonthView, SIGNAL( cancelIncidenceSignal( Incidence * ) ),
449 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 454 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
450 455
451 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ), 456 connect( mMonthView, SIGNAL( moveIncidenceSignal( Incidence * ) ),
452 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 457 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
453 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ), 458 connect( mMonthView, SIGNAL( beamIncidenceSignal( Incidence * ) ),
454 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 459 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
455 connect( mMonthView, SIGNAL( selectWeekNum( int ) ), 460 connect( mMonthView, SIGNAL( selectWeekNum( int ) ),
456 mMainView, SLOT ( selectWeekNum( int ) ) ); 461 mMainView, SLOT ( selectWeekNum( int ) ) );
457 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ), 462 connect( mMonthView, SIGNAL( showDaySignal( QDate ) ),
458 mMainView, SLOT ( showDay( QDate ) ) ); 463 mMainView, SLOT ( showDay( QDate ) ) );
459 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig())); 464 connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig()));
460 connect( mMonthView, SIGNAL(nextMonth() ), 465 connect( mMonthView, SIGNAL(nextMonth() ),
461 mMainView->navigatorBar(), SIGNAL(goNextMonth() ) ); 466 mMainView->navigatorBar(), SIGNAL(goNextMonth() ) );
462 connect( mMonthView, SIGNAL(prevMonth() ), 467 connect( mMonthView, SIGNAL(prevMonth() ),
463 mMainView->navigatorBar(), SIGNAL(goPrevMonth() ) ); 468 mMainView->navigatorBar(), SIGNAL(goPrevMonth() ) );
464 mMonthView->updateConfig(); 469 mMonthView->updateConfig();
465 } 470 }
466 471
467 globalFlagBlockAgenda = 1; 472 globalFlagBlockAgenda = 1;
468 //mFlagShowNextxDays = false; 473 //mFlagShowNextxDays = false;
469 // if(mMonthView == mCurrentView) return; 474 // if(mMonthView == mCurrentView) return;
470 mMainView->dateNavigator()->selectMonth(); 475 mMainView->dateNavigator()->selectMonth();
471 // DateList tmpList = mMainView->dateNavigator()->selectedDates( ); 476 // DateList tmpList = mMainView->dateNavigator()->selectedDates( );
472 //mMonthView->showDates(tmpList.first(), tmpList.last()); 477 //mMonthView->showDates(tmpList.first(), tmpList.last());
473 478
474 showView(mMonthView, true ); 479 showView(mMonthView, true );
475 480
476} 481}
477 482
478void KOViewManager::showTodoView() 483void KOViewManager::showTodoView()
479{ 484{
480 //mFlagShowNextxDays = false; 485 //mFlagShowNextxDays = false;
481 if ( !mTodoView ) { 486 if ( !mTodoView ) {
482 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(), 487 mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
483 "KOViewManager::TodoView" ); 488 "KOViewManager::TodoView" );
484 489
485 addView( mTodoView ); 490 addView( mTodoView );
486 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold ); 491 // QPEApplication::setStylusOperation( mTodoView, QPEApplication::RightOnHold );
487 492
488 // SIGNALS/SLOTS FOR TODO VIEW 493 // SIGNALS/SLOTS FOR TODO VIEW
489 connect( mTodoView, SIGNAL( newTodoSignal() ), 494 connect( mTodoView, SIGNAL( newTodoSignal() ),
490 mMainView, SLOT( newTodo() ) ); 495 mMainView, SLOT( newTodo() ) );
491 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ), 496 connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ),
492 mMainView, SLOT( newSubTodo( Todo *) ) ); 497 mMainView, SLOT( newSubTodo( Todo *) ) );
493 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ), 498 connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ),
494 mMainView, SLOT( showTodo( Todo * ) ) ); 499 mMainView, SLOT( showTodo( Todo * ) ) );
495 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ), 500 connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ),
496 mMainView, SLOT( editTodo( Todo * ) ) ); 501 mMainView, SLOT( editTodo( Todo * ) ) );
497 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ), 502 connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ),
498 mMainView, SLOT( deleteTodo( Todo * ) ) ); 503 mMainView, SLOT( deleteTodo( Todo * ) ) );
499 connect( mTodoView, SIGNAL( purgeCompletedSignal() ), 504 connect( mTodoView, SIGNAL( purgeCompletedSignal() ),
500 mMainView, SLOT( purgeCompleted() ) ); 505 mMainView, SLOT( purgeCompleted() ) );
501 506
502 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ), 507 connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ),
503 mMainView, SLOT( processMainViewSelection( Incidence * ) ) ); 508 mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
504 509
505 connect( mMainView, SIGNAL( configChanged() ), mTodoView, 510 connect( mMainView, SIGNAL( configChanged() ), mTodoView,
506 SLOT( updateConfig() ) ); 511 SLOT( updateConfig() ) );
507 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView, 512 connect( mMainView, SIGNAL( todoModified( Todo *, int )), mTodoView,
508 SLOT( updateTodo( Todo *, int ) ) ); 513 SLOT( updateTodo( Todo *, int ) ) );
509 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ), 514 connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ),
510 mMainView, SIGNAL ( todoModified( Todo *, int ) ) ); 515 mMainView, SIGNAL ( todoModified( Todo *, int ) ) );
511 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ), 516 connect( mTodoView, SIGNAL( cloneTodoSignal( Incidence * ) ),
512 mMainView, SLOT ( cloneIncidence( Incidence * ) ) ); 517 mMainView, SLOT ( cloneIncidence( Incidence * ) ) );
513 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ), 518 connect( mTodoView, SIGNAL( cancelTodoSignal( Incidence * ) ),
514 mMainView, SLOT ( cancelIncidence( Incidence * ) ) ); 519 mMainView, SLOT ( cancelIncidence( Incidence * ) ) );
515 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ), 520 connect( mTodoView, SIGNAL( unparentTodoSignal( Todo * ) ),
516 mMainView, SLOT ( todo_unsub( Todo * ) ) ); 521 mMainView, SLOT ( todo_unsub( Todo * ) ) );
517 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 522 connect( mTodoView, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
518 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) ); 523 mMainView, SLOT ( todo_resub( Todo *, Todo *) ) );
519 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ), 524 connect( mTodoView, SIGNAL( moveTodoSignal( Incidence * ) ),
520 mMainView, SLOT ( moveIncidence( Incidence * ) ) ); 525 mMainView, SLOT ( moveIncidence( Incidence * ) ) );
521 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ), 526 connect( mTodoView, SIGNAL( beamTodoSignal( Incidence * ) ),
522 mMainView, SLOT ( beamIncidence( Incidence * ) ) ); 527 mMainView, SLOT ( beamIncidence( Incidence * ) ) );
523 KConfig *config = KOGlobals::config(); 528 KConfig *config = KOGlobals::config();
524 mTodoView->restoreLayout(config,"Todo View"); 529 mTodoView->restoreLayout(config,"Todo View");
525 mTodoView->setNavigator( mMainView->dateNavigator() ); 530 mTodoView->setNavigator( mMainView->dateNavigator() );
526 } 531 }
527 532
528 globalFlagBlockAgenda = 1; 533 globalFlagBlockAgenda = 1;
529 showView( mTodoView, true ); 534 showView( mTodoView, true );
530 535
531} 536}
532 537
533void KOViewManager::showJournalView() 538void KOViewManager::showJournalView()
534{ 539{
535 //mFlagShowNextxDays = false; 540 //mFlagShowNextxDays = false;
536 if (!mJournalView) { 541 if (!mJournalView) {
537 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(), 542 mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
538 "KOViewManager::JournalView"); 543 "KOViewManager::JournalView");
539 connect( mMainView, SIGNAL( configChanged() ), mJournalView, 544 connect( mMainView, SIGNAL( configChanged() ), mJournalView,
540 SLOT( updateConfig() ) ); 545 SLOT( updateConfig() ) );
541 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) ); 546 connect(mJournalView, SIGNAL(deleteJournal(Journal *) ), mMainView,SLOT(deleteJournal(Journal *)) );
542 addView(mJournalView); 547 addView(mJournalView);
543 } 548 }
544 549
545 showView(mJournalView); 550 showView(mJournalView);
546} 551}
547 552
548void KOViewManager::showTimeSpanView() 553void KOViewManager::showTimeSpanView()
549{ 554{
550 //mFlagShowNextxDays = false; 555 //mFlagShowNextxDays = false;
551 if (!mTimeSpanView) { 556 if (!mTimeSpanView) {
552 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(), 557 mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
553 "KOViewManager::TimeSpanView"); 558 "KOViewManager::TimeSpanView");
554 addView(mTimeSpanView); 559 addView(mTimeSpanView);
555 560
556 mTimeSpanView->readSettings(); 561 mTimeSpanView->readSettings();
557 } 562 }
558 563
559 showView(mTimeSpanView); 564 showView(mTimeSpanView);
560} 565}
561 566
562Incidence *KOViewManager::currentSelection() 567Incidence *KOViewManager::currentSelection()
563{ 568{
564 if (!mCurrentView) return 0; 569 if (!mCurrentView) return 0;
565 if ( mCurrentView == mListView ) { 570 if ( mCurrentView == mListView ) {
566 if ( mListView->currentItem() ) 571 if ( mListView->currentItem() )
567 return mListView->currentItem(); 572 return mListView->currentItem();
568 } 573 }
569 return mCurrentView->selectedIncidences().first(); 574 return mCurrentView->selectedIncidences().first();
570} 575}
571 576
572QDate KOViewManager::currentSelectionDate() 577QDate KOViewManager::currentSelectionDate()
573{ 578{
574 QDate qd; 579 QDate qd;
575 if (mCurrentView) { 580 if (mCurrentView) {
576 DateList qvl = mCurrentView->selectedDates(); 581 DateList qvl = mCurrentView->selectedDates();
577 if (!qvl.isEmpty()) qd = qvl.first(); 582 if (!qvl.isEmpty()) qd = qvl.first();
578 } 583 }
579 return qd; 584 return qd;
580} 585}
581 586
582void KOViewManager::addView(KOrg::BaseView *view) 587void KOViewManager::addView(KOrg::BaseView *view)
583{ 588{
584#if QT_VERSION >= 0x030000 589#if QT_VERSION >= 0x030000
585 mMainView->viewStack()->addWidget( view ); 590 mMainView->viewStack()->addWidget( view );
586#else 591#else
587 mMainView->viewStack()->addWidget( view, 1 ); 592 mMainView->viewStack()->addWidget( view, 1 );
588#endif 593#endif
589} 594}
590 595
591void KOViewManager::setDocumentId( const QString &id ) 596void KOViewManager::setDocumentId( const QString &id )
592{ 597{
593 if (mTodoView) mTodoView->setDocumentId( id ); 598 if (mTodoView) mTodoView->setDocumentId( id );
594} 599}