summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp1
-rw-r--r--korganizer/datenavigatorcontainer.cpp13
-rw-r--r--korganizer/kdatenavigator.cpp11
-rw-r--r--korganizer/kdatenavigator.h6
-rw-r--r--korganizer/kodaymatrix.cpp7
-rw-r--r--korganizer/komonthview.cpp2
-rw-r--r--korganizer/navigatorbar.cpp4
-rw-r--r--korganizer/navigatorbar.h2
8 files changed, 32 insertions, 14 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 90b36ac..8100e25 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,1852 +1,1853 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 110#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 111#include "statusdialog.h"
112#include "kdatenavigator.h" 112#include "kdatenavigator.h"
113#include "kotodoview.h" 113#include "kotodoview.h"
114#include "datenavigator.h" 114#include "datenavigator.h"
115#include "resourceview.h" 115#include "resourceview.h"
116#include "navigatorbar.h" 116#include "navigatorbar.h"
117#include "searchdialog.h" 117#include "searchdialog.h"
118#include "mainwindow.h" 118#include "mainwindow.h"
119 119
120#include "calendarview.h" 120#include "calendarview.h"
121#ifndef DESKTOP_VERSION 121#ifndef DESKTOP_VERSION
122#include <qtopia/alarmserver.h> 122#include <qtopia/alarmserver.h>
123#endif 123#endif
124#ifndef _WIN32_ 124#ifndef _WIN32_
125#include <stdlib.h> 125#include <stdlib.h>
126#include <stdio.h> 126#include <stdio.h>
127#include <unistd.h> 127#include <unistd.h>
128#else 128#else
129#include <qprocess.h> 129#include <qprocess.h>
130#endif 130#endif
131 131
132#ifdef DESKTOP_VERSION 132#ifdef DESKTOP_VERSION
133#include <kabc/stdaddressbook.h> 133#include <kabc/stdaddressbook.h>
134#endif 134#endif
135using namespace KOrg; 135using namespace KOrg;
136using namespace KCal; 136using namespace KCal;
137extern int globalFlagBlockAgenda; 137extern int globalFlagBlockAgenda;
138extern int globalFlagBlockStartup; 138extern int globalFlagBlockStartup;
139 139
140 140
141 141
142class KOBeamPrefs : public QDialog 142class KOBeamPrefs : public QDialog
143{ 143{
144 public: 144 public:
145 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 145 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
146 QDialog( parent, name, true ) 146 QDialog( parent, name, true )
147 { 147 {
148 setCaption( i18n("Beam Options") ); 148 setCaption( i18n("Beam Options") );
149 QVBoxLayout* lay = new QVBoxLayout( this ); 149 QVBoxLayout* lay = new QVBoxLayout( this );
150 lay->setSpacing( 3 ); 150 lay->setSpacing( 3 );
151 lay->setMargin( 3 ); 151 lay->setMargin( 3 );
152 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 152 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
153 lay->addWidget( format ); 153 lay->addWidget( format );
154 format->setExclusive ( true ) ; 154 format->setExclusive ( true ) ;
155 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 155 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
156 lay->addWidget( time ); time->setExclusive ( true ) ; 156 lay->addWidget( time ); time->setExclusive ( true ) ;
157 vcal = new QRadioButton(" vCalendar ", format ); 157 vcal = new QRadioButton(" vCalendar ", format );
158 ical = new QRadioButton(" iCalendar ", format ); 158 ical = new QRadioButton(" iCalendar ", format );
159 vcal->setChecked( true ); 159 vcal->setChecked( true );
160 tz = new QRadioButton(i18n(" With timezone "), time ); 160 tz = new QRadioButton(i18n(" With timezone "), time );
161 local = new QRadioButton(i18n(" Local time "), time ); 161 local = new QRadioButton(i18n(" Local time "), time );
162 tz->setChecked( true ); 162 tz->setChecked( true );
163 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 163 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
164 lay->addWidget( ok ); 164 lay->addWidget( ok );
165 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 165 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
166 lay->addWidget( cancel ); 166 lay->addWidget( cancel );
167 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 167 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
168 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 168 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
169 resize( 200, 200 ); 169 resize( 200, 200 );
170 } 170 }
171 171
172 bool beamVcal() { return vcal->isChecked(); } 172 bool beamVcal() { return vcal->isChecked(); }
173 bool beamLocal() { return local->isChecked(); } 173 bool beamLocal() { return local->isChecked(); }
174private: 174private:
175 QRadioButton* vcal, *ical, *local, *tz; 175 QRadioButton* vcal, *ical, *local, *tz;
176}; 176};
177class KOCatPrefs : public QDialog 177class KOCatPrefs : public QDialog
178{ 178{
179 public: 179 public:
180 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 180 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
181 QDialog( parent, name, true ) 181 QDialog( parent, name, true )
182 { 182 {
183 setCaption( i18n("Manage new Categories") ); 183 setCaption( i18n("Manage new Categories") );
184 QVBoxLayout* lay = new QVBoxLayout( this ); 184 QVBoxLayout* lay = new QVBoxLayout( this );
185 lay->setSpacing( 3 ); 185 lay->setSpacing( 3 );
186 lay->setMargin( 3 ); 186 lay->setMargin( 3 );
187 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 187 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
188 lay->addWidget( lab ); 188 lay->addWidget( lab );
189 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 189 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
190 lay->addWidget( format ); 190 lay->addWidget( format );
191 format->setExclusive ( true ) ; 191 format->setExclusive ( true ) ;
192 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 192 addCatBut = new QRadioButton(i18n("Add to category list"), format );
193 new QRadioButton(i18n("Remove from Events/Todos"), format ); 193 new QRadioButton(i18n("Remove from Events/Todos"), format );
194 addCatBut->setChecked( true ); 194 addCatBut->setChecked( true );
195 QPushButton * ok = new QPushButton( i18n("OK"), this ); 195 QPushButton * ok = new QPushButton( i18n("OK"), this );
196 lay->addWidget( ok ); 196 lay->addWidget( ok );
197 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 197 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
198 lay->addWidget( cancel ); 198 lay->addWidget( cancel );
199 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 199 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
200 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 200 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
201 resize( 200, 200 ); 201 resize( 200, 200 );
202 } 202 }
203 203
204 bool addCat() { return addCatBut->isChecked(); } 204 bool addCat() { return addCatBut->isChecked(); }
205private: 205private:
206 QRadioButton* addCatBut; 206 QRadioButton* addCatBut;
207}; 207};
208 208
209 209
210 210
211CalendarView::CalendarView( CalendarResources *calendar, 211CalendarView::CalendarView( CalendarResources *calendar,
212 QWidget *parent, const char *name ) 212 QWidget *parent, const char *name )
213 : CalendarViewBase( parent, name ), 213 : CalendarViewBase( parent, name ),
214 mCalendar( calendar ), 214 mCalendar( calendar ),
215 mResourceManager( calendar->resourceManager() ) 215 mResourceManager( calendar->resourceManager() )
216{ 216{
217 217
218 mEventEditor = 0; 218 mEventEditor = 0;
219 mTodoEditor = 0; 219 mTodoEditor = 0;
220 220
221 init(); 221 init();
222} 222}
223 223
224CalendarView::CalendarView( Calendar *calendar, 224CalendarView::CalendarView( Calendar *calendar,
225 QWidget *parent, const char *name ) 225 QWidget *parent, const char *name )
226 : CalendarViewBase( parent, name ), 226 : CalendarViewBase( parent, name ),
227 mCalendar( calendar ), 227 mCalendar( calendar ),
228 mResourceManager( 0 ) 228 mResourceManager( 0 )
229{ 229{
230 230
231 mEventEditor = 0; 231 mEventEditor = 0;
232 mTodoEditor = 0; 232 mTodoEditor = 0;
233 init(); 233 init();
234} 234}
235 235
236void CalendarView::init() 236void CalendarView::init()
237{ 237{
238 238
239 setFocusPolicy ( WheelFocus ); 239 setFocusPolicy ( WheelFocus );
240 mViewerCallerIsSearchDialog = false; 240 mViewerCallerIsSearchDialog = false;
241 mBlockShowDates = false; 241 mBlockShowDates = false;
242 beamDialog = new KOBeamPrefs(); 242 beamDialog = new KOBeamPrefs();
243 mDatePickerMode = 0; 243 mDatePickerMode = 0;
244 mCurrentSyncDevice = ""; 244 mCurrentSyncDevice = "";
245 writeLocale(); 245 writeLocale();
246 mViewManager = new KOViewManager( this ); 246 mViewManager = new KOViewManager( this );
247 mDialogManager = new KODialogManager( this ); 247 mDialogManager = new KODialogManager( this );
248 mEventViewerDialog = 0; 248 mEventViewerDialog = 0;
249 mModified = false; 249 mModified = false;
250 mReadOnly = false; 250 mReadOnly = false;
251 mSelectedIncidence = 0; 251 mSelectedIncidence = 0;
252 mCalPrinter = 0; 252 mCalPrinter = 0;
253 mFilters.setAutoDelete(true); 253 mFilters.setAutoDelete(true);
254 254
255 mCalendar->registerObserver( this ); 255 mCalendar->registerObserver( this );
256 // TODO: Make sure that view is updated, when calendar is changed. 256 // TODO: Make sure that view is updated, when calendar is changed.
257 257
258 mStorage = new FileStorage( mCalendar ); 258 mStorage = new FileStorage( mCalendar );
259 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 259 mNavigator = new DateNavigator( this, "datevav", mViewManager );
260 260
261 QBoxLayout *topLayout = (QBoxLayout*)layout(); 261 QBoxLayout *topLayout = (QBoxLayout*)layout();
262#ifndef KORG_NOSPLITTER 262#ifndef KORG_NOSPLITTER
263 // create the main layout frames. 263 // create the main layout frames.
264 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 264 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
265 topLayout->addWidget(mPanner); 265 topLayout->addWidget(mPanner);
266 266
267 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 267 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
268 "CalendarView::LeftFrame"); 268 "CalendarView::LeftFrame");
269 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 269 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
270 270
271 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 271 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
272 "CalendarView::DateNavigator" ); 272 "CalendarView::DateNavigator" );
273 273
274 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 274 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
275 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 275 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
276 mTodoList->setNavigator( mNavigator ); 276 mTodoList->setNavigator( mNavigator );
277 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 277 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
278 278
279#ifdef KORG_NORESOURCEVIEW 279#ifdef KORG_NORESOURCEVIEW
280 mResourceView = 0; 280 mResourceView = 0;
281#else 281#else
282 if ( mResourceManager ) { 282 if ( mResourceManager ) {
283 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 283 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
284 mResourceView->updateView(); 284 mResourceView->updateView();
285 connect( mResourceView, SIGNAL( resourcesChanged() ), 285 connect( mResourceView, SIGNAL( resourcesChanged() ),
286 SLOT( updateView() ) ); 286 SLOT( updateView() ) );
287 } else { 287 } else {
288 mResourceView = 0; 288 mResourceView = 0;
289 } 289 }
290#endif 290#endif
291 QWidget *rightBox = new QWidget( mPanner ); 291 QWidget *rightBox = new QWidget( mPanner );
292 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 292 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
293 293
294 mRightFrame = new QWidgetStack( rightBox ); 294 mRightFrame = new QWidgetStack( rightBox );
295 rightLayout->addWidget( mRightFrame, 1 ); 295 rightLayout->addWidget( mRightFrame, 1 );
296 296
297 mLeftFrame = mLeftSplitter; 297 mLeftFrame = mLeftSplitter;
298#else 298#else
299 //QWidget *mainBox = new QWidget( this ); 299 //QWidget *mainBox = new QWidget( this );
300 //QWidget *leftFrame = new QWidget( mainBox ); 300 //QWidget *leftFrame = new QWidget( mainBox );
301 //QBoxLayout * mainBoxLayout; 301 //QBoxLayout * mainBoxLayout;
302 if ( KOPrefs::instance()->mVerticalScreen ) { 302 if ( KOPrefs::instance()->mVerticalScreen ) {
303 //mainBoxLayout = new QVBoxLayout(mainBox); 303 //mainBoxLayout = new QVBoxLayout(mainBox);
304 //leftFrameLayout = new QHBoxLayout(leftFrame ); 304 //leftFrameLayout = new QHBoxLayout(leftFrame );
305 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 305 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
306 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 306 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
307 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 307 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
308 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 308 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
309 } else { 309 } else {
310 //mainBoxLayout = new QHBoxLayout(mainBox); 310 //mainBoxLayout = new QHBoxLayout(mainBox);
311 //leftFrameLayout = new QVBoxLayout(leftFrame ); 311 //leftFrameLayout = new QVBoxLayout(leftFrame );
312 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 312 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
313 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 313 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
314 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 314 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
315 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 315 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
316 } 316 }
317 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
317 //QBoxLayout * leftFrameLayout; 318 //QBoxLayout * leftFrameLayout;
318 topLayout->addWidget( mMainFrame ); 319 topLayout->addWidget( mMainFrame );
319 //mainBoxLayout->addWidget (mLeftFrame); 320 //mainBoxLayout->addWidget (mLeftFrame);
320 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 321 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
321 "CalendarView::DateNavigator" ); 322 "CalendarView::DateNavigator" );
322#if 0 323#if 0
323 // FIXME 324 // FIXME
324 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 325 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
325 "CalendarView::DateNavigator", QDate::currentDate()); 326 "CalendarView::DateNavigator", QDate::currentDate());
326#endif 327#endif
327 // mDateNavigator->blockSignals( true ); 328 // mDateNavigator->blockSignals( true );
328 //leftFrameLayout->addWidget( mDateNavigator ); 329 //leftFrameLayout->addWidget( mDateNavigator );
329 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 330 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
330 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 331 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
331 mTodoList->setNavigator( mNavigator ); 332 mTodoList->setNavigator( mNavigator );
332#if 0 333#if 0
333 if ( QApplication::desktop()->width() < 480 ) { 334 if ( QApplication::desktop()->width() < 480 ) {
334 leftFrameLayout->addWidget(mFilterView); 335 leftFrameLayout->addWidget(mFilterView);
335 leftFrameLayout->addWidget(mTodoList, 2 ); 336 leftFrameLayout->addWidget(mTodoList, 2 );
336 337
337 } else { 338 } else {
338 leftFrameLayout->addWidget(mTodoList,2 ); 339 leftFrameLayout->addWidget(mTodoList,2 );
339 leftFrameLayout->addWidget(mFilterView ); 340 leftFrameLayout->addWidget(mFilterView );
340 } 341 }
341#endif 342#endif
342 mFilterView->hide(); 343 mFilterView->hide();
343 QWidget *rightBox = new QWidget( mMainFrame ); 344 QWidget *rightBox = new QWidget( mMainFrame );
344 //mainBoxLayout->addWidget ( rightBox, 10 ); 345 //mainBoxLayout->addWidget ( rightBox, 10 );
345 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 346 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
346 mRightFrame = new QWidgetStack( rightBox ); 347 mRightFrame = new QWidgetStack( rightBox );
347 rightLayout->addWidget( mRightFrame, 10 ); 348 rightLayout->addWidget( mRightFrame, 10 );
348 349
349 //mLeftFrame = (QWidget *)leftFrame; 350 //mLeftFrame = (QWidget *)leftFrame;
350 if ( KOPrefs::instance()->mVerticalScreen ) { 351 if ( KOPrefs::instance()->mVerticalScreen ) {
351 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 352 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
352 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 353 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
353 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 354 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
354 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 355 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
355 } else { 356 } else {
356 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 357 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
357 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 358 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
358 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 359 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
359 } 360 }
360 if ( !KOPrefs::instance()->mShowDateNavigator) 361 if ( !KOPrefs::instance()->mShowDateNavigator)
361 mDateNavigator->hide(); 362 mDateNavigator->hide();
362 //qDebug("Calendarview Size %d %d ", width(), height()); 363 //qDebug("Calendarview Size %d %d ", width(), height());
363#endif 364#endif
364 365
365 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 366 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
366 SLOT( showDates( const KCal::DateList & ) ) ); 367 SLOT( showDates( const KCal::DateList & ) ) );
367 368
368 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 369 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
369 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 370 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
370 371
371 372
372 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 373 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
373 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 374 mNavigator, SLOT( selectWeek( const QDate & ) ) );
374 375
375 connect( mDateNavigator, SIGNAL( goPrevYear() ), 376 connect( mDateNavigator, SIGNAL( goPrevYear() ),
376 mNavigator, SLOT( selectPreviousYear() ) ); 377 mNavigator, SLOT( selectPreviousYear() ) );
377 connect( mDateNavigator, SIGNAL( goNextYear() ), 378 connect( mDateNavigator, SIGNAL( goNextYear() ),
378 mNavigator, SLOT( selectNextYear() ) ); 379 mNavigator, SLOT( selectNextYear() ) );
379 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 380 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
380 mNavigator, SLOT( selectPreviousMonth() ) ); 381 mNavigator, SLOT( selectPreviousMonth() ) );
381 connect( mDateNavigator, SIGNAL( goNextMonth() ), 382 connect( mDateNavigator, SIGNAL( goNextMonth() ),
382 mNavigator, SLOT( selectNextMonth() ) ); 383 mNavigator, SLOT( selectNextMonth() ) );
383 384
384 connect( mDateNavigator, SIGNAL( goPrevious() ), 385 connect( mDateNavigator, SIGNAL( goPrevious() ),
385 mNavigator, SLOT( selectPrevious() ) ); 386 mNavigator, SLOT( selectPrevious() ) );
386 connect( mDateNavigator, SIGNAL( goNext() ), 387 connect( mDateNavigator, SIGNAL( goNext() ),
387 mNavigator, SLOT( selectNext() ) ); 388 mNavigator, SLOT( selectNext() ) );
388 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 389 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
389 mNavigator, SLOT( slotMonthSelect( int ) ) ); 390 mNavigator, SLOT( slotMonthSelect( int ) ) );
390 391
391 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 392 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
392 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 393 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
393#if 0 394#if 0
394 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 395 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
395 SLOT( incidenceAdded( Incidence *) ) ); 396 SLOT( incidenceAdded( Incidence *) ) );
396#endif 397#endif
397 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 398 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
398 399
399 connect( this, SIGNAL( configChanged() ), 400 connect( this, SIGNAL( configChanged() ),
400 mDateNavigator, SLOT( updateConfig() ) ); 401 mDateNavigator, SLOT( updateConfig() ) );
401 402
402 connect( mTodoList, SIGNAL( newTodoSignal() ), 403 connect( mTodoList, SIGNAL( newTodoSignal() ),
403 SLOT( newTodo() ) ); 404 SLOT( newTodo() ) );
404 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 405 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
405 SLOT( newSubTodo( Todo * ) ) ); 406 SLOT( newSubTodo( Todo * ) ) );
406 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 407 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
407 SLOT( editTodo( Todo * ) ) ); 408 SLOT( editTodo( Todo * ) ) );
408 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 409 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
409 SLOT( showTodo( Todo *) ) ); 410 SLOT( showTodo( Todo *) ) );
410 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 411 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
411 SLOT( deleteTodo( Todo *) ) ); 412 SLOT( deleteTodo( Todo *) ) );
412 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 413 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
413 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 414 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
414 SLOT( purgeCompleted() ) ); 415 SLOT( purgeCompleted() ) );
415 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 416 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
416 SIGNAL( todoModified( Todo *, int ) ) ); 417 SIGNAL( todoModified( Todo *, int ) ) );
417 418
418 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 419 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
419 this, SLOT ( cloneIncidence( Incidence * ) ) ); 420 this, SLOT ( cloneIncidence( Incidence * ) ) );
420 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 421 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
421 this, SLOT (cancelIncidence( Incidence * ) ) ); 422 this, SLOT (cancelIncidence( Incidence * ) ) );
422 423
423 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 424 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
424 this, SLOT ( moveIncidence( Incidence * ) ) ); 425 this, SLOT ( moveIncidence( Incidence * ) ) );
425 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 426 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
426 this, SLOT ( beamIncidence( Incidence * ) ) ); 427 this, SLOT ( beamIncidence( Incidence * ) ) );
427 428
428 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 429 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
429 this, SLOT ( todo_unsub( Todo * ) ) ); 430 this, SLOT ( todo_unsub( Todo * ) ) );
430 431
431 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 432 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
432 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 433 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
433 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 434 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
434 SLOT( updateTodo( Todo *, int ) ) ); 435 SLOT( updateTodo( Todo *, int ) ) );
435 connect( this, SIGNAL( todoModified( Todo *, int )), this, 436 connect( this, SIGNAL( todoModified( Todo *, int )), this,
436 SLOT( changeTodoDisplay( Todo *, int ) ) ); 437 SLOT( changeTodoDisplay( Todo *, int ) ) );
437 438
438 439
439 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 440 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
440 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 441 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
441 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 442 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
442 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 443 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
443 444
444 445
445 446
446 447
447 448
448 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 449 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
449 SLOT(checkClipboard())); 450 SLOT(checkClipboard()));
450 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 451 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
451 SLOT( processTodoListSelection( Incidence * ) ) ); 452 SLOT( processTodoListSelection( Incidence * ) ) );
452 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 453 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
453 454
454 // kdDebug() << "CalendarView::CalendarView() done" << endl; 455 // kdDebug() << "CalendarView::CalendarView() done" << endl;
455 456
456 mDateFrame = new QVBox(0,0,WType_Popup); 457 mDateFrame = new QVBox(0,0,WType_Popup);
457 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 458 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
458 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 459 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
459 mDateFrame->setLineWidth(3); 460 mDateFrame->setLineWidth(3);
460 mDateFrame->hide(); 461 mDateFrame->hide();
461 mDateFrame->setCaption( i18n( "Pick a date to display")); 462 mDateFrame->setCaption( i18n( "Pick a date to display"));
462 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 463 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
463 464
464 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 465 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
465 466
466 mEventEditor = mDialogManager->getEventEditor(); 467 mEventEditor = mDialogManager->getEventEditor();
467 mTodoEditor = mDialogManager->getTodoEditor(); 468 mTodoEditor = mDialogManager->getTodoEditor();
468 469
469 mFlagEditDescription = false; 470 mFlagEditDescription = false;
470 471
471 mSuspendTimer = new QTimer( this ); 472 mSuspendTimer = new QTimer( this );
472 mAlarmTimer = new QTimer( this ); 473 mAlarmTimer = new QTimer( this );
473 mRecheckAlarmTimer = new QTimer( this ); 474 mRecheckAlarmTimer = new QTimer( this );
474 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 475 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
475 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 476 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
476 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 477 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
477 mAlarmDialog = new AlarmDialog( this ); 478 mAlarmDialog = new AlarmDialog( this );
478 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 479 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
479 mAlarmDialog->setServerNotification( false ); 480 mAlarmDialog->setServerNotification( false );
480 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 481 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
481 482
482 483
483#ifndef DESKTOP_VERSION 484#ifndef DESKTOP_VERSION
484//US listen for arriving address resultsets 485//US listen for arriving address resultsets
485 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 486 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
486 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 487 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
487#endif 488#endif
488 mDateNavigator->setCalendar( mCalendar ); 489 mDateNavigator->setCalendar( mCalendar );
489} 490}
490 491
491 492
492CalendarView::~CalendarView() 493CalendarView::~CalendarView()
493{ 494{
494 // kdDebug() << "~CalendarView()" << endl; 495 // kdDebug() << "~CalendarView()" << endl;
495 //qDebug("CalendarView::~CalendarView() "); 496 //qDebug("CalendarView::~CalendarView() ");
496 delete mDialogManager; 497 delete mDialogManager;
497 delete mViewManager; 498 delete mViewManager;
498 delete mStorage; 499 delete mStorage;
499 delete mDateFrame ; 500 delete mDateFrame ;
500 delete beamDialog; 501 delete beamDialog;
501 delete mEventViewerDialog; 502 delete mEventViewerDialog;
502 //kdDebug() << "~CalendarView() done" << endl; 503 //kdDebug() << "~CalendarView() done" << endl;
503} 504}
504 505
505void CalendarView::showDay( QDate d ) 506void CalendarView::showDay( QDate d )
506{ 507{
507 dateNavigator()->blockSignals( true ); 508 dateNavigator()->blockSignals( true );
508 dateNavigator()->selectDate( d ); 509 dateNavigator()->selectDate( d );
509 dateNavigator()->blockSignals( false ); 510 dateNavigator()->blockSignals( false );
510 mViewManager->showDayView(); 511 mViewManager->showDayView();
511 //dateNavigator()->selectDate( d ); 512 //dateNavigator()->selectDate( d );
512} 513}
513void CalendarView::timerAlarm() 514void CalendarView::timerAlarm()
514{ 515{
515 //qDebug("CalendarView::timerAlarm() "); 516 //qDebug("CalendarView::timerAlarm() ");
516 computeAlarm(mAlarmNotification ); 517 computeAlarm(mAlarmNotification );
517} 518}
518 519
519void CalendarView::suspendAlarm() 520void CalendarView::suspendAlarm()
520{ 521{
521 //qDebug(" CalendarView::suspendAlarm() "); 522 //qDebug(" CalendarView::suspendAlarm() ");
522 computeAlarm(mSuspendAlarmNotification ); 523 computeAlarm(mSuspendAlarmNotification );
523 524
524} 525}
525 526
526void CalendarView::startAlarm( QString mess , QString filename) 527void CalendarView::startAlarm( QString mess , QString filename)
527{ 528{
528 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 529 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
529 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 530 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
530 531
531} 532}
532 533
533void CalendarView::checkNextTimerAlarm() 534void CalendarView::checkNextTimerAlarm()
534{ 535{
535 mCalendar->checkAlarmForIncidence( 0, true ); 536 mCalendar->checkAlarmForIncidence( 0, true );
536} 537}
537 538
538void CalendarView::computeAlarm( QString msg ) 539void CalendarView::computeAlarm( QString msg )
539{ 540{
540 541
541 QString mess = msg; 542 QString mess = msg;
542 QString mAlarmMessage = mess.mid( 9 ); 543 QString mAlarmMessage = mess.mid( 9 );
543 QString filename = MainWindow::resourcePath(); 544 QString filename = MainWindow::resourcePath();
544 filename += "koalarm.wav"; 545 filename += "koalarm.wav";
545 QString tempfilename; 546 QString tempfilename;
546 if ( mess.left( 13 ) == "suspend_alarm") { 547 if ( mess.left( 13 ) == "suspend_alarm") {
547 bool error = false; 548 bool error = false;
548 int len = mess.mid( 13 ).find("+++"); 549 int len = mess.mid( 13 ).find("+++");
549 if ( len < 2 ) 550 if ( len < 2 )
550 error = true; 551 error = true;
551 else { 552 else {
552 tempfilename = mess.mid( 13, len ); 553 tempfilename = mess.mid( 13, len );
553 if ( !QFile::exists( tempfilename ) ) 554 if ( !QFile::exists( tempfilename ) )
554 error = true; 555 error = true;
555 } 556 }
556 if ( ! error ) { 557 if ( ! error ) {
557 filename = tempfilename; 558 filename = tempfilename;
558 } 559 }
559 mAlarmMessage = mess.mid( 13+len+3 ); 560 mAlarmMessage = mess.mid( 13+len+3 );
560 //qDebug("suspend file %s ",tempfilename.latin1() ); 561 //qDebug("suspend file %s ",tempfilename.latin1() );
561 startAlarm( mAlarmMessage, filename); 562 startAlarm( mAlarmMessage, filename);
562 return; 563 return;
563 } 564 }
564 if ( mess.left( 11 ) == "timer_alarm") { 565 if ( mess.left( 11 ) == "timer_alarm") {
565 //mTimerTime = 0; 566 //mTimerTime = 0;
566 startAlarm( mess.mid( 11 ), filename ); 567 startAlarm( mess.mid( 11 ), filename );
567 return; 568 return;
568 } 569 }
569 if ( mess.left( 10 ) == "proc_alarm") { 570 if ( mess.left( 10 ) == "proc_alarm") {
570 bool error = false; 571 bool error = false;
571 int len = mess.mid( 10 ).find("+++"); 572 int len = mess.mid( 10 ).find("+++");
572 if ( len < 2 ) 573 if ( len < 2 )
573 error = true; 574 error = true;
574 else { 575 else {
575 tempfilename = mess.mid( 10, len ); 576 tempfilename = mess.mid( 10, len );
576 if ( !QFile::exists( tempfilename ) ) 577 if ( !QFile::exists( tempfilename ) )
577 error = true; 578 error = true;
578 } 579 }
579 if ( error ) { 580 if ( error ) {
580 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 581 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
581 mAlarmMessage += mess.mid( 10+len+3+9 ); 582 mAlarmMessage += mess.mid( 10+len+3+9 );
582 } else { 583 } else {
583 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 584 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
584 //qDebug("-----system command %s ",tempfilename.latin1() ); 585 //qDebug("-----system command %s ",tempfilename.latin1() );
585#ifndef _WIN32_ 586#ifndef _WIN32_
586 if ( vfork () == 0 ) { 587 if ( vfork () == 0 ) {
587 execl ( tempfilename.latin1(), 0 ); 588 execl ( tempfilename.latin1(), 0 );
588 return; 589 return;
589 } 590 }
590#else 591#else
591 QProcess* p = new QProcess(); 592 QProcess* p = new QProcess();
592 p->addArgument( tempfilename.latin1() ); 593 p->addArgument( tempfilename.latin1() );
593 p->start(); 594 p->start();
594 return; 595 return;
595#endif 596#endif
596 597
597 return; 598 return;
598 } 599 }
599 600
600 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 601 //qDebug("+++++++system command %s ",tempfilename.latin1() );
601 } 602 }
602 if ( mess.left( 11 ) == "audio_alarm") { 603 if ( mess.left( 11 ) == "audio_alarm") {
603 bool error = false; 604 bool error = false;
604 int len = mess.mid( 11 ).find("+++"); 605 int len = mess.mid( 11 ).find("+++");
605 if ( len < 2 ) 606 if ( len < 2 )
606 error = true; 607 error = true;
607 else { 608 else {
608 tempfilename = mess.mid( 11, len ); 609 tempfilename = mess.mid( 11, len );
609 if ( !QFile::exists( tempfilename ) ) 610 if ( !QFile::exists( tempfilename ) )
610 error = true; 611 error = true;
611 } 612 }
612 if ( ! error ) { 613 if ( ! error ) {
613 filename = tempfilename; 614 filename = tempfilename;
614 } 615 }
615 mAlarmMessage = mess.mid( 11+len+3+9 ); 616 mAlarmMessage = mess.mid( 11+len+3+9 );
616 //qDebug("audio file command %s ",tempfilename.latin1() ); 617 //qDebug("audio file command %s ",tempfilename.latin1() );
617 } 618 }
618 if ( mess.left( 9 ) == "cal_alarm") { 619 if ( mess.left( 9 ) == "cal_alarm") {
619 mAlarmMessage = mess.mid( 9 ) ; 620 mAlarmMessage = mess.mid( 9 ) ;
620 } 621 }
621 622
622 startAlarm( mAlarmMessage, filename ); 623 startAlarm( mAlarmMessage, filename );
623 624
624 625
625} 626}
626 627
627void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 628void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
628{ 629{
629 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 630 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
630 631
631 mSuspendAlarmNotification = noti; 632 mSuspendAlarmNotification = noti;
632 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 633 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
633 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 634 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
634 mSuspendTimer->start( ms , true ); 635 mSuspendTimer->start( ms , true );
635 636
636} 637}
637 638
638void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 639void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
639{ 640{
640 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 641 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
641 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 642 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
642#ifndef DESKTOP_VERSION 643#ifndef DESKTOP_VERSION
643 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 644 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
644#endif 645#endif
645 return; 646 return;
646 } 647 }
647 int maxSec; 648 int maxSec;
648 //maxSec = 5; //testing only 649 //maxSec = 5; //testing only
649 maxSec = 86400+3600; // one day+1hour 650 maxSec = 86400+3600; // one day+1hour
650 mAlarmNotification = noti; 651 mAlarmNotification = noti;
651 int sec = QDateTime::currentDateTime().secsTo( qdt ); 652 int sec = QDateTime::currentDateTime().secsTo( qdt );
652 if ( sec > maxSec ) { 653 if ( sec > maxSec ) {
653 mRecheckAlarmTimer->start( maxSec * 1000 ); 654 mRecheckAlarmTimer->start( maxSec * 1000 );
654 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 655 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
655 return; 656 return;
656 } else { 657 } else {
657 mRecheckAlarmTimer->stop(); 658 mRecheckAlarmTimer->stop();
658 } 659 }
659 //qDebug("Alarm timer started with secs: %d ", sec); 660 //qDebug("Alarm timer started with secs: %d ", sec);
660 mAlarmTimer->start( sec *1000 , true ); 661 mAlarmTimer->start( sec *1000 , true );
661 662
662} 663}
663// called by mRecheckAlarmTimer to get next alarm 664// called by mRecheckAlarmTimer to get next alarm
664// we need this, because a QTimer has only a max range of 25 days 665// we need this, because a QTimer has only a max range of 25 days
665void CalendarView::recheckTimerAlarm() 666void CalendarView::recheckTimerAlarm()
666{ 667{
667 mAlarmTimer->stop(); 668 mAlarmTimer->stop();
668 mRecheckAlarmTimer->stop(); 669 mRecheckAlarmTimer->stop();
669 mCalendar->checkAlarmForIncidence( 0, true ); 670 mCalendar->checkAlarmForIncidence( 0, true );
670} 671}
671void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 672void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
672{ 673{
673 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 674 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
674 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 675 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
675#ifndef DESKTOP_VERSION 676#ifndef DESKTOP_VERSION
676 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 677 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
677#endif 678#endif
678 return; 679 return;
679 } 680 }
680 mAlarmTimer->stop(); 681 mAlarmTimer->stop();
681} 682}
682void CalendarView::selectWeekNum ( int num ) 683void CalendarView::selectWeekNum ( int num )
683{ 684{
684 dateNavigator()->blockSignals( true ); 685 dateNavigator()->blockSignals( true );
685 dateNavigator()->selectWeek( num ); 686 dateNavigator()->selectWeek( num );
686 dateNavigator()->blockSignals( false ); 687 dateNavigator()->blockSignals( false );
687 mViewManager->showWeekView(); 688 mViewManager->showWeekView();
688} 689}
689KOViewManager *CalendarView::viewManager() 690KOViewManager *CalendarView::viewManager()
690{ 691{
691 return mViewManager; 692 return mViewManager;
692} 693}
693 694
694KODialogManager *CalendarView::dialogManager() 695KODialogManager *CalendarView::dialogManager()
695{ 696{
696 return mDialogManager; 697 return mDialogManager;
697} 698}
698 699
699QDate CalendarView::startDate() 700QDate CalendarView::startDate()
700{ 701{
701 DateList dates = mNavigator->selectedDates(); 702 DateList dates = mNavigator->selectedDates();
702 703
703 return dates.first(); 704 return dates.first();
704} 705}
705 706
706QDate CalendarView::endDate() 707QDate CalendarView::endDate()
707{ 708{
708 DateList dates = mNavigator->selectedDates(); 709 DateList dates = mNavigator->selectedDates();
709 710
710 return dates.last(); 711 return dates.last();
711} 712}
712 713
713 714
714void CalendarView::createPrinter() 715void CalendarView::createPrinter()
715{ 716{
716#ifndef KORG_NOPRINTER 717#ifndef KORG_NOPRINTER
717 if (!mCalPrinter) { 718 if (!mCalPrinter) {
718 mCalPrinter = new CalPrinter(this, mCalendar); 719 mCalPrinter = new CalPrinter(this, mCalendar);
719 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 720 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
720 } 721 }
721#endif 722#endif
722} 723}
723 724
724 725
725//KOPrefs::instance()->mWriteBackFile 726//KOPrefs::instance()->mWriteBackFile
726//KOPrefs::instance()->mWriteBackExistingOnly 727//KOPrefs::instance()->mWriteBackExistingOnly
727 728
728// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 729// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
729// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 730// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
730// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 731// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
731// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 732// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
732// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 733// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
733// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 734// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
734 735
735int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 736int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
736{ 737{
737 738
738 // 0 equal 739 // 0 equal
739 // 1 take local 740 // 1 take local
740 // 2 take remote 741 // 2 take remote
741 // 3 cancel 742 // 3 cancel
742 QDateTime lastSync = mLastCalendarSync; 743 QDateTime lastSync = mLastCalendarSync;
743 QDateTime localMod = local->lastModified(); 744 QDateTime localMod = local->lastModified();
744 QDateTime remoteMod = remote->lastModified(); 745 QDateTime remoteMod = remote->lastModified();
745 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 746 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
746 bool remCh, locCh; 747 bool remCh, locCh;
747 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 748 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
748 //if ( remCh ) 749 //if ( remCh )
749 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 750 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
750 locCh = ( localMod > mLastCalendarSync ); 751 locCh = ( localMod > mLastCalendarSync );
751 if ( !remCh && ! locCh ) { 752 if ( !remCh && ! locCh ) {
752 //qDebug("both not changed "); 753 //qDebug("both not changed ");
753 lastSync = localMod.addDays(1); 754 lastSync = localMod.addDays(1);
754 if ( mode <= SYNC_PREF_ASK ) 755 if ( mode <= SYNC_PREF_ASK )
755 return 0; 756 return 0;
756 } else { 757 } else {
757 if ( locCh ) { 758 if ( locCh ) {
758 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 759 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
759 lastSync = localMod.addDays( -1 ); 760 lastSync = localMod.addDays( -1 );
760 if ( !remCh ) 761 if ( !remCh )
761 remoteMod = ( lastSync.addDays( -1 ) ); 762 remoteMod = ( lastSync.addDays( -1 ) );
762 } else { 763 } else {
763 //qDebug(" not loc changed "); 764 //qDebug(" not loc changed ");
764 lastSync = localMod.addDays( 1 ); 765 lastSync = localMod.addDays( 1 );
765 if ( remCh ) 766 if ( remCh )
766 remoteMod =( lastSync.addDays( 1 ) ); 767 remoteMod =( lastSync.addDays( 1 ) );
767 768
768 } 769 }
769 } 770 }
770 full = true; 771 full = true;
771 if ( mode < SYNC_PREF_ASK ) 772 if ( mode < SYNC_PREF_ASK )
772 mode = SYNC_PREF_ASK; 773 mode = SYNC_PREF_ASK;
773 } else { 774 } else {
774 if ( localMod == remoteMod ) 775 if ( localMod == remoteMod )
775 // if ( local->revision() == remote->revision() ) 776 // if ( local->revision() == remote->revision() )
776 return 0; 777 return 0;
777 778
778 } 779 }
779 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 780 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
780 781
781 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 782 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
782 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 783 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
783 //full = true; //debug only 784 //full = true; //debug only
784 if ( full ) { 785 if ( full ) {
785 bool equ = false; 786 bool equ = false;
786 if ( local->type() == "Event" ) { 787 if ( local->type() == "Event" ) {
787 equ = (*((Event*) local) == *((Event*) remote)); 788 equ = (*((Event*) local) == *((Event*) remote));
788 } 789 }
789 else if ( local->type() =="Todo" ) 790 else if ( local->type() =="Todo" )
790 equ = (*((Todo*) local) == (*(Todo*) remote)); 791 equ = (*((Todo*) local) == (*(Todo*) remote));
791 else if ( local->type() =="Journal" ) 792 else if ( local->type() =="Journal" )
792 equ = (*((Journal*) local) == *((Journal*) remote)); 793 equ = (*((Journal*) local) == *((Journal*) remote));
793 if ( equ ) { 794 if ( equ ) {
794 //qDebug("equal "); 795 //qDebug("equal ");
795 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 796 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
796 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 797 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
797 } 798 }
798 if ( mode < SYNC_PREF_FORCE_LOCAL ) 799 if ( mode < SYNC_PREF_FORCE_LOCAL )
799 return 0; 800 return 0;
800 801
801 }//else //debug only 802 }//else //debug only
802 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 803 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
803 } 804 }
804 int result; 805 int result;
805 bool localIsNew; 806 bool localIsNew;
806 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 807 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
807 808
808 if ( full && mode < SYNC_PREF_NEWEST ) 809 if ( full && mode < SYNC_PREF_NEWEST )
809 mode = SYNC_PREF_ASK; 810 mode = SYNC_PREF_ASK;
810 811
811 switch( mode ) { 812 switch( mode ) {
812 case SYNC_PREF_LOCAL: 813 case SYNC_PREF_LOCAL:
813 if ( lastSync > remoteMod ) 814 if ( lastSync > remoteMod )
814 return 1; 815 return 1;
815 if ( lastSync > localMod ) 816 if ( lastSync > localMod )
816 return 2; 817 return 2;
817 return 1; 818 return 1;
818 break; 819 break;
819 case SYNC_PREF_REMOTE: 820 case SYNC_PREF_REMOTE:
820 if ( lastSync > remoteMod ) 821 if ( lastSync > remoteMod )
821 return 1; 822 return 1;
822 if ( lastSync > localMod ) 823 if ( lastSync > localMod )
823 return 2; 824 return 2;
824 return 2; 825 return 2;
825 break; 826 break;
826 case SYNC_PREF_NEWEST: 827 case SYNC_PREF_NEWEST:
827 if ( localMod > remoteMod ) 828 if ( localMod > remoteMod )
828 return 1; 829 return 1;
829 else 830 else
830 return 2; 831 return 2;
831 break; 832 break;
832 case SYNC_PREF_ASK: 833 case SYNC_PREF_ASK:
833 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 834 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
834 if ( lastSync > remoteMod ) 835 if ( lastSync > remoteMod )
835 return 1; 836 return 1;
836 if ( lastSync > localMod ) 837 if ( lastSync > localMod )
837 return 2; 838 return 2;
838 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 839 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
839 localIsNew = localMod >= remoteMod; 840 localIsNew = localMod >= remoteMod;
840 if ( localIsNew ) 841 if ( localIsNew )
841 getEventViewerDialog()->setColorMode( 1 ); 842 getEventViewerDialog()->setColorMode( 1 );
842 else 843 else
843 getEventViewerDialog()->setColorMode( 2 ); 844 getEventViewerDialog()->setColorMode( 2 );
844 getEventViewerDialog()->setIncidence(local); 845 getEventViewerDialog()->setIncidence(local);
845 if ( localIsNew ) 846 if ( localIsNew )
846 getEventViewerDialog()->setColorMode( 2 ); 847 getEventViewerDialog()->setColorMode( 2 );
847 else 848 else
848 getEventViewerDialog()->setColorMode( 1 ); 849 getEventViewerDialog()->setColorMode( 1 );
849 getEventViewerDialog()->addIncidence(remote); 850 getEventViewerDialog()->addIncidence(remote);
850 getEventViewerDialog()->setColorMode( 0 ); 851 getEventViewerDialog()->setColorMode( 0 );
851 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 852 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
852 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 853 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
853 getEventViewerDialog()->showMe(); 854 getEventViewerDialog()->showMe();
854 result = getEventViewerDialog()->executeS( localIsNew ); 855 result = getEventViewerDialog()->executeS( localIsNew );
855 return result; 856 return result;
856 857
857 break; 858 break;
858 case SYNC_PREF_FORCE_LOCAL: 859 case SYNC_PREF_FORCE_LOCAL:
859 return 1; 860 return 1;
860 break; 861 break;
861 case SYNC_PREF_FORCE_REMOTE: 862 case SYNC_PREF_FORCE_REMOTE:
862 return 2; 863 return 2;
863 break; 864 break;
864 865
865 default: 866 default:
866 // SYNC_PREF_TAKE_BOTH not implemented 867 // SYNC_PREF_TAKE_BOTH not implemented
867 break; 868 break;
868 } 869 }
869 return 0; 870 return 0;
870} 871}
871Event* CalendarView::getLastSyncEvent() 872Event* CalendarView::getLastSyncEvent()
872{ 873{
873 Event* lse; 874 Event* lse;
874 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 875 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
875 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 876 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
876 if (!lse) { 877 if (!lse) {
877 lse = new Event(); 878 lse = new Event();
878 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 879 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
879 QString sum = ""; 880 QString sum = "";
880 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 881 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
881 sum = "E: "; 882 sum = "E: ";
882 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 883 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
883 lse->setDtStart( mLastCalendarSync ); 884 lse->setDtStart( mLastCalendarSync );
884 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 885 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
885 lse->setCategories( i18n("SyncEvent") ); 886 lse->setCategories( i18n("SyncEvent") );
886 lse->setReadOnly( true ); 887 lse->setReadOnly( true );
887 mCalendar->addEvent( lse ); 888 mCalendar->addEvent( lse );
888 } 889 }
889 890
890 return lse; 891 return lse;
891 892
892} 893}
893 894
894// we check, if the to delete event has a id for a profile 895// we check, if the to delete event has a id for a profile
895// if yes, we set this id in the profile to delete 896// if yes, we set this id in the profile to delete
896void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 897void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
897{ 898{
898 if ( lastSync.count() == 0 ) { 899 if ( lastSync.count() == 0 ) {
899 //qDebug(" lastSync.count() == 0"); 900 //qDebug(" lastSync.count() == 0");
900 return; 901 return;
901 } 902 }
902 if ( toDelete->type() == "Journal" ) 903 if ( toDelete->type() == "Journal" )
903 return; 904 return;
904 905
905 Event* eve = lastSync.first(); 906 Event* eve = lastSync.first();
906 907
907 while ( eve ) { 908 while ( eve ) {
908 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 909 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
909 if ( !id.isEmpty() ) { 910 if ( !id.isEmpty() ) {
910 QString des = eve->description(); 911 QString des = eve->description();
911 QString pref = "e"; 912 QString pref = "e";
912 if ( toDelete->type() == "Todo" ) 913 if ( toDelete->type() == "Todo" )
913 pref = "t"; 914 pref = "t";
914 des += pref+ id + ","; 915 des += pref+ id + ",";
915 eve->setReadOnly( false ); 916 eve->setReadOnly( false );
916 eve->setDescription( des ); 917 eve->setDescription( des );
917 //qDebug("setdes %s ", des.latin1()); 918 //qDebug("setdes %s ", des.latin1());
918 eve->setReadOnly( true ); 919 eve->setReadOnly( true );
919 } 920 }
920 eve = lastSync.next(); 921 eve = lastSync.next();
921 } 922 }
922 923
923} 924}
924void CalendarView::checkExternalId( Incidence * inc ) 925void CalendarView::checkExternalId( Incidence * inc )
925{ 926{
926 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 927 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
927 checkExternSyncEvent( lastSync, inc ); 928 checkExternSyncEvent( lastSync, inc );
928 929
929} 930}
930bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 931bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
931{ 932{
932 bool syncOK = true; 933 bool syncOK = true;
933 int addedEvent = 0; 934 int addedEvent = 0;
934 int addedEventR = 0; 935 int addedEventR = 0;
935 int deletedEventR = 0; 936 int deletedEventR = 0;
936 int deletedEventL = 0; 937 int deletedEventL = 0;
937 int changedLocal = 0; 938 int changedLocal = 0;
938 int changedRemote = 0; 939 int changedRemote = 0;
939 int filteredIN = 0; 940 int filteredIN = 0;
940 int filteredOUT = 0; 941 int filteredOUT = 0;
941 //QPtrList<Event> el = local->rawEvents(); 942 //QPtrList<Event> el = local->rawEvents();
942 Event* eventR; 943 Event* eventR;
943 QString uid; 944 QString uid;
944 int take; 945 int take;
945 Event* eventL; 946 Event* eventL;
946 Event* eventRSync; 947 Event* eventRSync;
947 Event* eventLSync; 948 Event* eventLSync;
948 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 949 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
949 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 950 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
950 bool fullDateRange = false; 951 bool fullDateRange = false;
951 local->resetTempSyncStat(); 952 local->resetTempSyncStat();
952 mLastCalendarSync = QDateTime::currentDateTime(); 953 mLastCalendarSync = QDateTime::currentDateTime();
953 if ( mSyncManager->syncWithDesktop() ) { 954 if ( mSyncManager->syncWithDesktop() ) {
954 remote->resetPilotStat(1); 955 remote->resetPilotStat(1);
955 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 956 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
956 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 957 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
957 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 958 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
958 } else { 959 } else {
959 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 960 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
960 } 961 }
961 } 962 }
962 QDateTime modifiedCalendar = mLastCalendarSync; 963 QDateTime modifiedCalendar = mLastCalendarSync;
963 eventLSync = getLastSyncEvent(); 964 eventLSync = getLastSyncEvent();
964 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 965 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
965 if ( eventR ) { 966 if ( eventR ) {
966 eventRSync = (Event*) eventR->clone(); 967 eventRSync = (Event*) eventR->clone();
967 remote->deleteEvent(eventR ); 968 remote->deleteEvent(eventR );
968 969
969 } else { 970 } else {
970 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 971 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
971 eventRSync = (Event*)eventLSync->clone(); 972 eventRSync = (Event*)eventLSync->clone();
972 } else { 973 } else {
973 fullDateRange = true; 974 fullDateRange = true;
974 eventRSync = new Event(); 975 eventRSync = new Event();
975 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 976 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
976 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 977 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
977 eventRSync->setDtStart( mLastCalendarSync ); 978 eventRSync->setDtStart( mLastCalendarSync );
978 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 979 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
979 eventRSync->setCategories( i18n("SyncEvent") ); 980 eventRSync->setCategories( i18n("SyncEvent") );
980 } 981 }
981 } 982 }
982 if ( eventLSync->dtStart() == mLastCalendarSync ) 983 if ( eventLSync->dtStart() == mLastCalendarSync )
983 fullDateRange = true; 984 fullDateRange = true;
984 985
985 if ( ! fullDateRange ) { 986 if ( ! fullDateRange ) {
986 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 987 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
987 988
988 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 989 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
989 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 990 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
990 fullDateRange = true; 991 fullDateRange = true;
991 } 992 }
992 } 993 }
993 if ( mSyncManager->syncWithDesktop() ) { 994 if ( mSyncManager->syncWithDesktop() ) {
994 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 995 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
995 } 996 }
996 if ( fullDateRange ) 997 if ( fullDateRange )
997 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 998 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
998 else 999 else
999 mLastCalendarSync = eventLSync->dtStart(); 1000 mLastCalendarSync = eventLSync->dtStart();
1000 // for resyncing if own file has changed 1001 // for resyncing if own file has changed
1001 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1002 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1002 mLastCalendarSync = loadedFileVersion; 1003 mLastCalendarSync = loadedFileVersion;
1003 //qDebug("setting mLastCalendarSync "); 1004 //qDebug("setting mLastCalendarSync ");
1004 } 1005 }
1005 //qDebug("*************************** "); 1006 //qDebug("*************************** ");
1006 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1007 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1007 QPtrList<Incidence> er = remote->rawIncidences(); 1008 QPtrList<Incidence> er = remote->rawIncidences();
1008 Incidence* inR = er.first(); 1009 Incidence* inR = er.first();
1009 Incidence* inL; 1010 Incidence* inL;
1010 QProgressBar bar( er.count(),0 ); 1011 QProgressBar bar( er.count(),0 );
1011 bar.setCaption (i18n("Syncing - close to abort!") ); 1012 bar.setCaption (i18n("Syncing - close to abort!") );
1012 1013
1013 // ************** setting up filter ************* 1014 // ************** setting up filter *************
1014 CalFilter *filterIN = 0; 1015 CalFilter *filterIN = 0;
1015 CalFilter *filterOUT = 0; 1016 CalFilter *filterOUT = 0;
1016 CalFilter *filter = mFilters.first(); 1017 CalFilter *filter = mFilters.first();
1017 while(filter) { 1018 while(filter) {
1018 if ( filter->name() == mSyncManager->mFilterInCal ) 1019 if ( filter->name() == mSyncManager->mFilterInCal )
1019 filterIN = filter; 1020 filterIN = filter;
1020 if ( filter->name() == mSyncManager->mFilterOutCal ) 1021 if ( filter->name() == mSyncManager->mFilterOutCal )
1021 filterOUT = filter; 1022 filterOUT = filter;
1022 filter = mFilters.next(); 1023 filter = mFilters.next();
1023 } 1024 }
1024 int w = 300; 1025 int w = 300;
1025 if ( QApplication::desktop()->width() < 320 ) 1026 if ( QApplication::desktop()->width() < 320 )
1026 w = 220; 1027 w = 220;
1027 int h = bar.sizeHint().height() ; 1028 int h = bar.sizeHint().height() ;
1028 int dw = QApplication::desktop()->width(); 1029 int dw = QApplication::desktop()->width();
1029 int dh = QApplication::desktop()->height(); 1030 int dh = QApplication::desktop()->height();
1030 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1031 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1031 bar.show(); 1032 bar.show();
1032 int modulo = (er.count()/10)+1; 1033 int modulo = (er.count()/10)+1;
1033 int incCounter = 0; 1034 int incCounter = 0;
1034 while ( inR ) { 1035 while ( inR ) {
1035 if ( ! bar.isVisible() ) 1036 if ( ! bar.isVisible() )
1036 return false; 1037 return false;
1037 if ( incCounter % modulo == 0 ) 1038 if ( incCounter % modulo == 0 )
1038 bar.setProgress( incCounter ); 1039 bar.setProgress( incCounter );
1039 ++incCounter; 1040 ++incCounter;
1040 uid = inR->uid(); 1041 uid = inR->uid();
1041 bool skipIncidence = false; 1042 bool skipIncidence = false;
1042 if ( uid.left(15) == QString("last-syncEvent-") ) 1043 if ( uid.left(15) == QString("last-syncEvent-") )
1043 skipIncidence = true; 1044 skipIncidence = true;
1044 QString idS; 1045 QString idS;
1045 qApp->processEvents(); 1046 qApp->processEvents();
1046 if ( !skipIncidence ) { 1047 if ( !skipIncidence ) {
1047 inL = local->incidence( uid ); 1048 inL = local->incidence( uid );
1048 if ( inL ) { // maybe conflict - same uid in both calendars 1049 if ( inL ) { // maybe conflict - same uid in both calendars
1049 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1050 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1050 //qDebug("take %d %s ", take, inL->summary().latin1()); 1051 //qDebug("take %d %s ", take, inL->summary().latin1());
1051 if ( take == 3 ) 1052 if ( take == 3 )
1052 return false; 1053 return false;
1053 if ( take == 1 ) {// take local ********************** 1054 if ( take == 1 ) {// take local **********************
1054 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1055 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1055 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1056 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1056 else 1057 else
1057 idS = inR->IDStr(); 1058 idS = inR->IDStr();
1058 remote->deleteIncidence( inR ); 1059 remote->deleteIncidence( inR );
1059 inR = inL->clone(); 1060 inR = inL->clone();
1060 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1061 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1061 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1062 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1062 inR->setIDStr( idS ); 1063 inR->setIDStr( idS );
1063 remote->addIncidence( inR ); 1064 remote->addIncidence( inR );
1064 if ( mSyncManager->syncWithDesktop() ) 1065 if ( mSyncManager->syncWithDesktop() )
1065 inR->setPilotId( 2 ); 1066 inR->setPilotId( 2 );
1066 ++changedRemote; 1067 ++changedRemote;
1067 } else {// take remote ********************** 1068 } else {// take remote **********************
1068 idS = inL->IDStr(); 1069 idS = inL->IDStr();
1069 int pid = inL->pilotId(); 1070 int pid = inL->pilotId();
1070 local->deleteIncidence( inL ); 1071 local->deleteIncidence( inL );
1071 inL = inR->clone(); 1072 inL = inR->clone();
1072 if ( mSyncManager->syncWithDesktop() ) 1073 if ( mSyncManager->syncWithDesktop() )
1073 inL->setPilotId( pid ); 1074 inL->setPilotId( pid );
1074 inL->setIDStr( idS ); 1075 inL->setIDStr( idS );
1075 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1076 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1076 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1077 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1077 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1078 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1078 } 1079 }
1079 local->addIncidence( inL ); 1080 local->addIncidence( inL );
1080 ++changedLocal; 1081 ++changedLocal;
1081 } 1082 }
1082 } 1083 }
1083 } else { // no conflict ********** add or delete remote 1084 } else { // no conflict ********** add or delete remote
1084 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1085 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1085 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1086 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1086 QString des = eventLSync->description(); 1087 QString des = eventLSync->description();
1087 QString pref = "e"; 1088 QString pref = "e";
1088 if ( inR->type() == "Todo" ) 1089 if ( inR->type() == "Todo" )
1089 pref = "t"; 1090 pref = "t";
1090 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1091 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1091 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1092 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1092 //remote->deleteIncidence( inR ); 1093 //remote->deleteIncidence( inR );
1093 ++deletedEventR; 1094 ++deletedEventR;
1094 } else { 1095 } else {
1095 inR->setLastModified( modifiedCalendar ); 1096 inR->setLastModified( modifiedCalendar );
1096 inL = inR->clone(); 1097 inL = inR->clone();
1097 inL->setIDStr( ":" ); 1098 inL->setIDStr( ":" );
1098 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1099 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1099 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1100 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1100 local->addIncidence( inL ); 1101 local->addIncidence( inL );
1101 ++addedEvent; 1102 ++addedEvent;
1102 1103
1103 } 1104 }
1104 } else { 1105 } else {
1105 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1106 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1106 inR->setLastModified( modifiedCalendar ); 1107 inR->setLastModified( modifiedCalendar );
1107 inL = inR->clone(); 1108 inL = inR->clone();
1108 inL->setIDStr( ":" ); 1109 inL->setIDStr( ":" );
1109 local->addIncidence( inL ); 1110 local->addIncidence( inL );
1110 ++addedEvent; 1111 ++addedEvent;
1111 1112
1112 } else { 1113 } else {
1113 checkExternSyncEvent(eventRSyncSharp, inR); 1114 checkExternSyncEvent(eventRSyncSharp, inR);
1114 remote->deleteIncidence( inR ); 1115 remote->deleteIncidence( inR );
1115 ++deletedEventR; 1116 ++deletedEventR;
1116 } 1117 }
1117 } 1118 }
1118 } else { 1119 } else {
1119 ++filteredIN; 1120 ++filteredIN;
1120 } 1121 }
1121 } 1122 }
1122 } 1123 }
1123 inR = er.next(); 1124 inR = er.next();
1124 } 1125 }
1125 QPtrList<Incidence> el = local->rawIncidences(); 1126 QPtrList<Incidence> el = local->rawIncidences();
1126 inL = el.first(); 1127 inL = el.first();
1127 modulo = (el.count()/10)+1; 1128 modulo = (el.count()/10)+1;
1128 bar.setCaption (i18n("Add / remove events") ); 1129 bar.setCaption (i18n("Add / remove events") );
1129 bar.setTotalSteps ( el.count() ) ; 1130 bar.setTotalSteps ( el.count() ) ;
1130 bar.show(); 1131 bar.show();
1131 incCounter = 0; 1132 incCounter = 0;
1132 1133
1133 while ( inL ) { 1134 while ( inL ) {
1134 1135
1135 qApp->processEvents(); 1136 qApp->processEvents();
1136 if ( ! bar.isVisible() ) 1137 if ( ! bar.isVisible() )
1137 return false; 1138 return false;
1138 if ( incCounter % modulo == 0 ) 1139 if ( incCounter % modulo == 0 )
1139 bar.setProgress( incCounter ); 1140 bar.setProgress( incCounter );
1140 ++incCounter; 1141 ++incCounter;
1141 uid = inL->uid(); 1142 uid = inL->uid();
1142 bool skipIncidence = false; 1143 bool skipIncidence = false;
1143 if ( uid.left(15) == QString("last-syncEvent-") ) 1144 if ( uid.left(15) == QString("last-syncEvent-") )
1144 skipIncidence = true; 1145 skipIncidence = true;
1145 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1146 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1146 skipIncidence = true; 1147 skipIncidence = true;
1147 if ( !skipIncidence ) { 1148 if ( !skipIncidence ) {
1148 inR = remote->incidence( uid ); 1149 inR = remote->incidence( uid );
1149 if ( ! inR ) { 1150 if ( ! inR ) {
1150 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1151 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1151 // no conflict ********** add or delete local 1152 // no conflict ********** add or delete local
1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1153 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1153 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1154 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1154 checkExternSyncEvent(eventLSyncSharp, inL); 1155 checkExternSyncEvent(eventLSyncSharp, inL);
1155 local->deleteIncidence( inL ); 1156 local->deleteIncidence( inL );
1156 ++deletedEventL; 1157 ++deletedEventL;
1157 } else { 1158 } else {
1158 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1159 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1159 inL->removeID(mCurrentSyncDevice ); 1160 inL->removeID(mCurrentSyncDevice );
1160 ++addedEventR; 1161 ++addedEventR;
1161 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1162 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1162 inL->setLastModified( modifiedCalendar ); 1163 inL->setLastModified( modifiedCalendar );
1163 inR = inL->clone(); 1164 inR = inL->clone();
1164 inR->setIDStr( ":" ); 1165 inR->setIDStr( ":" );
1165 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1166 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1166 remote->addIncidence( inR ); 1167 remote->addIncidence( inR );
1167 } 1168 }
1168 } 1169 }
1169 } else { 1170 } else {
1170 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1171 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1171 checkExternSyncEvent(eventLSyncSharp, inL); 1172 checkExternSyncEvent(eventLSyncSharp, inL);
1172 local->deleteIncidence( inL ); 1173 local->deleteIncidence( inL );
1173 ++deletedEventL; 1174 ++deletedEventL;
1174 } else { 1175 } else {
1175 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1176 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1176 ++addedEventR; 1177 ++addedEventR;
1177 inL->setLastModified( modifiedCalendar ); 1178 inL->setLastModified( modifiedCalendar );
1178 inR = inL->clone(); 1179 inR = inL->clone();
1179 inR->setIDStr( ":" ); 1180 inR->setIDStr( ":" );
1180 remote->addIncidence( inR ); 1181 remote->addIncidence( inR );
1181 } 1182 }
1182 } 1183 }
1183 } 1184 }
1184 } else { 1185 } else {
1185 ++filteredOUT; 1186 ++filteredOUT;
1186 } 1187 }
1187 } 1188 }
1188 } 1189 }
1189 inL = el.next(); 1190 inL = el.next();
1190 } 1191 }
1191 int delFut = 0; 1192 int delFut = 0;
1192 int remRem = 0; 1193 int remRem = 0;
1193 if ( mSyncManager->mWriteBackInFuture ) { 1194 if ( mSyncManager->mWriteBackInFuture ) {
1194 er = remote->rawIncidences(); 1195 er = remote->rawIncidences();
1195 remRem = er.count(); 1196 remRem = er.count();
1196 inR = er.first(); 1197 inR = er.first();
1197 QDateTime dt; 1198 QDateTime dt;
1198 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1199 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1199 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1200 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1200 while ( inR ) { 1201 while ( inR ) {
1201 if ( inR->type() == "Todo" ) { 1202 if ( inR->type() == "Todo" ) {
1202 Todo * t = (Todo*)inR; 1203 Todo * t = (Todo*)inR;
1203 if ( t->hasDueDate() ) 1204 if ( t->hasDueDate() )
1204 dt = t->dtDue(); 1205 dt = t->dtDue();
1205 else 1206 else
1206 dt = cur.addSecs( 62 ); 1207 dt = cur.addSecs( 62 );
1207 } 1208 }
1208 else if (inR->type() == "Event" ) { 1209 else if (inR->type() == "Event" ) {
1209 bool ok; 1210 bool ok;
1210 dt = inR->getNextOccurence( cur, &ok ); 1211 dt = inR->getNextOccurence( cur, &ok );
1211 if ( !ok ) 1212 if ( !ok )
1212 dt = cur.addSecs( -62 ); 1213 dt = cur.addSecs( -62 );
1213 } 1214 }
1214 else 1215 else
1215 dt = inR->dtStart(); 1216 dt = inR->dtStart();
1216 if ( dt < cur || dt > end ) { 1217 if ( dt < cur || dt > end ) {
1217 remote->deleteIncidence( inR ); 1218 remote->deleteIncidence( inR );
1218 ++delFut; 1219 ++delFut;
1219 } 1220 }
1220 inR = er.next(); 1221 inR = er.next();
1221 } 1222 }
1222 } 1223 }
1223 bar.hide(); 1224 bar.hide();
1224 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1225 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1225 eventLSync->setReadOnly( false ); 1226 eventLSync->setReadOnly( false );
1226 eventLSync->setDtStart( mLastCalendarSync ); 1227 eventLSync->setDtStart( mLastCalendarSync );
1227 eventRSync->setDtStart( mLastCalendarSync ); 1228 eventRSync->setDtStart( mLastCalendarSync );
1228 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1229 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1229 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1230 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1230 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1231 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1231 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1232 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1232 eventLSync->setReadOnly( true ); 1233 eventLSync->setReadOnly( true );
1233 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1234 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1234 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1235 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1235 remote->addEvent( eventRSync ); 1236 remote->addEvent( eventRSync );
1236 else 1237 else
1237 delete eventRSync; 1238 delete eventRSync;
1238 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1239 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1239 QString mes; 1240 QString mes;
1240 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1241 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1241 QString delmess; 1242 QString delmess;
1242 if ( delFut ) { 1243 if ( delFut ) {
1243 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1244 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1244 mes += delmess; 1245 mes += delmess;
1245 } 1246 }
1246 mes = i18n("Local calendar changed!\n") +mes; 1247 mes = i18n("Local calendar changed!\n") +mes;
1247 mCalendar->checkAlarmForIncidence( 0, true ); 1248 mCalendar->checkAlarmForIncidence( 0, true );
1248 qDebug( mes ); 1249 qDebug( mes );
1249 if ( mSyncManager->mShowSyncSummary ) { 1250 if ( mSyncManager->mShowSyncSummary ) {
1250 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1251 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1251 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1252 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1252 qDebug("KO: WB cancelled "); 1253 qDebug("KO: WB cancelled ");
1253 mSyncManager->mWriteBackFile = false; 1254 mSyncManager->mWriteBackFile = false;
1254 return syncOK; 1255 return syncOK;
1255 } 1256 }
1256 } 1257 }
1257 return syncOK; 1258 return syncOK;
1258} 1259}
1259 1260
1260void CalendarView::setSyncDevice( QString s ) 1261void CalendarView::setSyncDevice( QString s )
1261{ 1262{
1262 mCurrentSyncDevice= s; 1263 mCurrentSyncDevice= s;
1263} 1264}
1264void CalendarView::setSyncName( QString s ) 1265void CalendarView::setSyncName( QString s )
1265{ 1266{
1266 mCurrentSyncName= s; 1267 mCurrentSyncName= s;
1267} 1268}
1268bool CalendarView::syncCalendar(QString filename, int mode) 1269bool CalendarView::syncCalendar(QString filename, int mode)
1269{ 1270{
1270 //qDebug("syncCalendar %s ", filename.latin1()); 1271 //qDebug("syncCalendar %s ", filename.latin1());
1271 mGlobalSyncMode = SYNC_MODE_NORMAL; 1272 mGlobalSyncMode = SYNC_MODE_NORMAL;
1272 CalendarLocal* calendar = new CalendarLocal(); 1273 CalendarLocal* calendar = new CalendarLocal();
1273 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1274 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1274 FileStorage* storage = new FileStorage( calendar ); 1275 FileStorage* storage = new FileStorage( calendar );
1275 bool syncOK = false; 1276 bool syncOK = false;
1276 storage->setFileName( filename ); 1277 storage->setFileName( filename );
1277 // qDebug("loading ... "); 1278 // qDebug("loading ... ");
1278 if ( storage->load() ) { 1279 if ( storage->load() ) {
1279 getEventViewerDialog()->setSyncMode( true ); 1280 getEventViewerDialog()->setSyncMode( true );
1280 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1281 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1281 getEventViewerDialog()->setSyncMode( false ); 1282 getEventViewerDialog()->setSyncMode( false );
1282 if ( syncOK ) { 1283 if ( syncOK ) {
1283 if ( mSyncManager->mWriteBackFile ) 1284 if ( mSyncManager->mWriteBackFile )
1284 { 1285 {
1285 storage->setSaveFormat( new ICalFormat() ); 1286 storage->setSaveFormat( new ICalFormat() );
1286 storage->save(); 1287 storage->save();
1287 } 1288 }
1288 } 1289 }
1289 setModified( true ); 1290 setModified( true );
1290 } 1291 }
1291 delete storage; 1292 delete storage;
1292 delete calendar; 1293 delete calendar;
1293 if ( syncOK ) 1294 if ( syncOK )
1294 updateView(); 1295 updateView();
1295 return syncOK; 1296 return syncOK;
1296} 1297}
1297 1298
1298void CalendarView::syncExternal( int mode ) 1299void CalendarView::syncExternal( int mode )
1299{ 1300{
1300 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1301 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1301 1302
1302 qApp->processEvents(); 1303 qApp->processEvents();
1303 CalendarLocal* calendar = new CalendarLocal(); 1304 CalendarLocal* calendar = new CalendarLocal();
1304 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1305 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1305 bool syncOK = false; 1306 bool syncOK = false;
1306 bool loadSuccess = false; 1307 bool loadSuccess = false;
1307 PhoneFormat* phoneFormat = 0; 1308 PhoneFormat* phoneFormat = 0;
1308 emit tempDisableBR(true); 1309 emit tempDisableBR(true);
1309#ifndef DESKTOP_VERSION 1310#ifndef DESKTOP_VERSION
1310 SharpFormat* sharpFormat = 0; 1311 SharpFormat* sharpFormat = 0;
1311 if ( mode == 0 ) { // sharp 1312 if ( mode == 0 ) { // sharp
1312 sharpFormat = new SharpFormat () ; 1313 sharpFormat = new SharpFormat () ;
1313 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1314 loadSuccess = sharpFormat->load( calendar, mCalendar );
1314 1315
1315 } else 1316 } else
1316#endif 1317#endif
1317 if ( mode == 1 ) { // phone 1318 if ( mode == 1 ) { // phone
1318 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1319 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1319 mSyncManager->mPhoneDevice, 1320 mSyncManager->mPhoneDevice,
1320 mSyncManager->mPhoneConnection, 1321 mSyncManager->mPhoneConnection,
1321 mSyncManager->mPhoneModel); 1322 mSyncManager->mPhoneModel);
1322 loadSuccess = phoneFormat->load( calendar,mCalendar); 1323 loadSuccess = phoneFormat->load( calendar,mCalendar);
1323 1324
1324 } else { 1325 } else {
1325 emit tempDisableBR(false); 1326 emit tempDisableBR(false);
1326 return; 1327 return;
1327 } 1328 }
1328 if ( loadSuccess ) { 1329 if ( loadSuccess ) {
1329 getEventViewerDialog()->setSyncMode( true ); 1330 getEventViewerDialog()->setSyncMode( true );
1330 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1331 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1331 getEventViewerDialog()->setSyncMode( false ); 1332 getEventViewerDialog()->setSyncMode( false );
1332 qApp->processEvents(); 1333 qApp->processEvents();
1333 if ( syncOK ) { 1334 if ( syncOK ) {
1334 if ( mSyncManager->mWriteBackFile ) 1335 if ( mSyncManager->mWriteBackFile )
1335 { 1336 {
1336 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1337 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1337 Incidence* inc = iL.first(); 1338 Incidence* inc = iL.first();
1338 if ( phoneFormat ) { 1339 if ( phoneFormat ) {
1339 while ( inc ) { 1340 while ( inc ) {
1340 inc->removeID(mCurrentSyncDevice); 1341 inc->removeID(mCurrentSyncDevice);
1341 inc = iL.next(); 1342 inc = iL.next();
1342 } 1343 }
1343 } 1344 }
1344#ifndef DESKTOP_VERSION 1345#ifndef DESKTOP_VERSION
1345 if ( sharpFormat ) 1346 if ( sharpFormat )
1346 sharpFormat->save(calendar); 1347 sharpFormat->save(calendar);
1347#endif 1348#endif
1348 if ( phoneFormat ) 1349 if ( phoneFormat )
1349 phoneFormat->save(calendar); 1350 phoneFormat->save(calendar);
1350 iL = calendar->rawIncidences(); 1351 iL = calendar->rawIncidences();
1351 inc = iL.first(); 1352 inc = iL.first();
1352 Incidence* loc; 1353 Incidence* loc;
1353 while ( inc ) { 1354 while ( inc ) {
1354 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1355 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1355 loc = mCalendar->incidence(inc->uid() ); 1356 loc = mCalendar->incidence(inc->uid() );
1356 if ( loc ) { 1357 if ( loc ) {
1357 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1358 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1358 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1359 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1359 } 1360 }
1360 } 1361 }
1361 inc = iL.next(); 1362 inc = iL.next();
1362 } 1363 }
1363 Incidence* lse = getLastSyncEvent(); 1364 Incidence* lse = getLastSyncEvent();
1364 if ( lse ) { 1365 if ( lse ) {
1365 lse->setReadOnly( false ); 1366 lse->setReadOnly( false );
1366 lse->setDescription( "" ); 1367 lse->setDescription( "" );
1367 lse->setReadOnly( true ); 1368 lse->setReadOnly( true );
1368 } 1369 }
1369 } 1370 }
1370 } else { 1371 } else {
1371 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1372 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1372 } 1373 }
1373 setModified( true ); 1374 setModified( true );
1374 } else { 1375 } else {
1375 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1376 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1376 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1377 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1377 question, i18n("Ok")) ; 1378 question, i18n("Ok")) ;
1378 1379
1379 } 1380 }
1380 delete calendar; 1381 delete calendar;
1381 updateView(); 1382 updateView();
1382 emit tempDisableBR(false); 1383 emit tempDisableBR(false);
1383 return ;//syncOK; 1384 return ;//syncOK;
1384 1385
1385} 1386}
1386 1387
1387bool CalendarView::importBday() 1388bool CalendarView::importBday()
1388{ 1389{
1389#ifndef KORG_NOKABC 1390#ifndef KORG_NOKABC
1390 1391
1391#ifdef DESKTOP_VERSION 1392#ifdef DESKTOP_VERSION
1392 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1393 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1393 KABC::AddressBook::Iterator it; 1394 KABC::AddressBook::Iterator it;
1394 int count = 0; 1395 int count = 0;
1395 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1396 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1396 ++count; 1397 ++count;
1397 } 1398 }
1398 QProgressBar bar(count,0 ); 1399 QProgressBar bar(count,0 );
1399 int w = 300; 1400 int w = 300;
1400 if ( QApplication::desktop()->width() < 320 ) 1401 if ( QApplication::desktop()->width() < 320 )
1401 w = 220; 1402 w = 220;
1402 int h = bar.sizeHint().height() ; 1403 int h = bar.sizeHint().height() ;
1403 int dw = QApplication::desktop()->width(); 1404 int dw = QApplication::desktop()->width();
1404 int dh = QApplication::desktop()->height(); 1405 int dh = QApplication::desktop()->height();
1405 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1406 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1406 bar.show(); 1407 bar.show();
1407 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1408 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1408 qApp->processEvents(); 1409 qApp->processEvents();
1409 count = 0; 1410 count = 0;
1410 int addCount = 0; 1411 int addCount = 0;
1411 KCal::Attendee* a = 0; 1412 KCal::Attendee* a = 0;
1412 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1413 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1413 if ( ! bar.isVisible() ) 1414 if ( ! bar.isVisible() )
1414 return false; 1415 return false;
1415 bar.setProgress( count++ ); 1416 bar.setProgress( count++ );
1416 qApp->processEvents(); 1417 qApp->processEvents();
1417 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1418 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1418 if ( (*it).birthday().date().isValid() ){ 1419 if ( (*it).birthday().date().isValid() ){
1419 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1420 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1420 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1421 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1421 ++addCount; 1422 ++addCount;
1422 } 1423 }
1423 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1424 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1424 if ( anni.isValid() ){ 1425 if ( anni.isValid() ){
1425 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1426 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1426 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1427 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1427 ++addCount; 1428 ++addCount;
1428 } 1429 }
1429 } 1430 }
1430 updateView(); 1431 updateView();
1431 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1432 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1432#else //DESKTOP_VERSION 1433#else //DESKTOP_VERSION
1433 1434
1434 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1435 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1435 // the result should now arrive through method insertBirthdays 1436 // the result should now arrive through method insertBirthdays
1436 1437
1437#endif //DESKTOP_VERSION 1438#endif //DESKTOP_VERSION
1438 1439
1439#endif //KORG_NOKABC 1440#endif //KORG_NOKABC
1440 1441
1441 1442
1442 return true; 1443 return true;
1443} 1444}
1444 1445
1445// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1446// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1446void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1447void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1447 const QStringList& anniversaryList, const QStringList& realNameList, 1448 const QStringList& anniversaryList, const QStringList& realNameList,
1448 const QStringList& emailList, const QStringList& assembledNameList, 1449 const QStringList& emailList, const QStringList& assembledNameList,
1449 const QStringList& uidList) 1450 const QStringList& uidList)
1450{ 1451{
1451 //qDebug("KO::CalendarView::insertBirthdays"); 1452 //qDebug("KO::CalendarView::insertBirthdays");
1452 if (uid == this->name()) 1453 if (uid == this->name())
1453 { 1454 {
1454 int count = birthdayList.count(); 1455 int count = birthdayList.count();
1455 int addCount = 0; 1456 int addCount = 0;
1456 KCal::Attendee* a = 0; 1457 KCal::Attendee* a = 0;
1457 1458
1458 //qDebug("CalView 1 %i", count); 1459 //qDebug("CalView 1 %i", count);
1459 1460
1460 QProgressBar bar(count,0 ); 1461 QProgressBar bar(count,0 );
1461 int w = 300; 1462 int w = 300;
1462 if ( QApplication::desktop()->width() < 320 ) 1463 if ( QApplication::desktop()->width() < 320 )
1463 w = 220; 1464 w = 220;
1464 int h = bar.sizeHint().height() ; 1465 int h = bar.sizeHint().height() ;
1465 int dw = QApplication::desktop()->width(); 1466 int dw = QApplication::desktop()->width();
1466 int dh = QApplication::desktop()->height(); 1467 int dh = QApplication::desktop()->height();
1467 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1468 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1468 bar.show(); 1469 bar.show();
1469 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1470 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1470 qApp->processEvents(); 1471 qApp->processEvents();
1471 1472
1472 QDate birthday; 1473 QDate birthday;
1473 QDate anniversary; 1474 QDate anniversary;
1474 QString realName; 1475 QString realName;
1475 QString email; 1476 QString email;
1476 QString assembledName; 1477 QString assembledName;
1477 QString uid; 1478 QString uid;
1478 bool ok = true; 1479 bool ok = true;
1479 for ( int i = 0; i < count; i++) 1480 for ( int i = 0; i < count; i++)
1480 { 1481 {
1481 if ( ! bar.isVisible() ) 1482 if ( ! bar.isVisible() )
1482 return; 1483 return;
1483 bar.setProgress( i ); 1484 bar.setProgress( i );
1484 qApp->processEvents(); 1485 qApp->processEvents();
1485 1486
1486 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1487 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1487 if (!ok) { 1488 if (!ok) {
1488 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1489 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1489 } 1490 }
1490 1491
1491 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1492 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1492 if (!ok) { 1493 if (!ok) {
1493 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1494 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1494 } 1495 }
1495 realName = realNameList[i]; 1496 realName = realNameList[i];
1496 email = emailList[i]; 1497 email = emailList[i];
1497 assembledName = assembledNameList[i]; 1498 assembledName = assembledNameList[i];
1498 uid = uidList[i]; 1499 uid = uidList[i];
1499 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1500 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1500 1501
1501 if ( birthday.isValid() ){ 1502 if ( birthday.isValid() ){
1502 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1503 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1503 KCal::Attendee::ReqParticipant,uid) ; 1504 KCal::Attendee::ReqParticipant,uid) ;
1504 if ( addAnniversary( birthday, assembledName, a, true ) ) 1505 if ( addAnniversary( birthday, assembledName, a, true ) )
1505 ++addCount; 1506 ++addCount;
1506 } 1507 }
1507 1508
1508 if ( anniversary.isValid() ){ 1509 if ( anniversary.isValid() ){
1509 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1510 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1510 KCal::Attendee::ReqParticipant,uid) ; 1511 KCal::Attendee::ReqParticipant,uid) ;
1511 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1512 if ( addAnniversary( anniversary, assembledName, a, false ) )
1512 ++addCount; 1513 ++addCount;
1513 } 1514 }
1514 } 1515 }
1515 1516
1516 updateView(); 1517 updateView();
1517 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1518 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1518 1519
1519 } 1520 }
1520 1521
1521} 1522}
1522 1523
1523 1524
1524 1525
1525bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1526bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1526{ 1527{
1527 //qDebug("addAnni "); 1528 //qDebug("addAnni ");
1528 Event * ev = new Event(); 1529 Event * ev = new Event();
1529 ev->setOrganizer(KOPrefs::instance()->email()); 1530 ev->setOrganizer(KOPrefs::instance()->email());
1530 if ( a ) { 1531 if ( a ) {
1531 ev->addAttendee( a ); 1532 ev->addAttendee( a );
1532 } 1533 }
1533 QString kind; 1534 QString kind;
1534 if ( birthday ) { 1535 if ( birthday ) {
1535 kind = i18n( "Birthday" ); 1536 kind = i18n( "Birthday" );
1536 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1537 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1537 } 1538 }
1538 else { 1539 else {
1539 kind = i18n( "Anniversary" ); 1540 kind = i18n( "Anniversary" );
1540 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1541 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1541 } 1542 }
1542 ev->setCategories( kind ); 1543 ev->setCategories( kind );
1543 ev->setDtStart( QDateTime(date) ); 1544 ev->setDtStart( QDateTime(date) );
1544 ev->setDtEnd( QDateTime(date) ); 1545 ev->setDtEnd( QDateTime(date) );
1545 ev->setFloats( true ); 1546 ev->setFloats( true );
1546 Recurrence * rec = ev->recurrence(); 1547 Recurrence * rec = ev->recurrence();
1547 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1548 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1548 rec->addYearlyNum( date.month() ); 1549 rec->addYearlyNum( date.month() );
1549 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1550 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1550 delete ev; 1551 delete ev;
1551 return false; 1552 return false;
1552 } 1553 }
1553 return true; 1554 return true;
1554 1555
1555} 1556}
1556bool CalendarView::importQtopia( const QString &categories, 1557bool CalendarView::importQtopia( const QString &categories,
1557 const QString &datebook, 1558 const QString &datebook,
1558 const QString &todolist ) 1559 const QString &todolist )
1559{ 1560{
1560 1561
1561 QtopiaFormat qtopiaFormat; 1562 QtopiaFormat qtopiaFormat;
1562 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1563 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1563 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1564 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1564 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1565 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1565 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1566 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1566 1567
1567 updateView(); 1568 updateView();
1568 return true; 1569 return true;
1569 1570
1570#if 0 1571#if 0
1571 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1572 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1572 mCurrentSyncDevice = "qtopia-XML"; 1573 mCurrentSyncDevice = "qtopia-XML";
1573 if ( mSyncManager->mAskForPreferences ) 1574 if ( mSyncManager->mAskForPreferences )
1574 edit_sync_options(); 1575 edit_sync_options();
1575 qApp->processEvents(); 1576 qApp->processEvents();
1576 CalendarLocal* calendar = new CalendarLocal(); 1577 CalendarLocal* calendar = new CalendarLocal();
1577 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1578 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1578 bool syncOK = false; 1579 bool syncOK = false;
1579 QtopiaFormat qtopiaFormat; 1580 QtopiaFormat qtopiaFormat;
1580 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1581 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1581 bool loadOk = true; 1582 bool loadOk = true;
1582 if ( !categories.isEmpty() ) 1583 if ( !categories.isEmpty() )
1583 loadOk = qtopiaFormat.load( calendar, categories ); 1584 loadOk = qtopiaFormat.load( calendar, categories );
1584 if ( loadOk && !datebook.isEmpty() ) 1585 if ( loadOk && !datebook.isEmpty() )
1585 loadOk = qtopiaFormat.load( calendar, datebook ); 1586 loadOk = qtopiaFormat.load( calendar, datebook );
1586 if ( loadOk && !todolist.isEmpty() ) 1587 if ( loadOk && !todolist.isEmpty() )
1587 loadOk = qtopiaFormat.load( calendar, todolist ); 1588 loadOk = qtopiaFormat.load( calendar, todolist );
1588 1589
1589 if ( loadOk ) { 1590 if ( loadOk ) {
1590 getEventViewerDialog()->setSyncMode( true ); 1591 getEventViewerDialog()->setSyncMode( true );
1591 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1592 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1592 getEventViewerDialog()->setSyncMode( false ); 1593 getEventViewerDialog()->setSyncMode( false );
1593 qApp->processEvents(); 1594 qApp->processEvents();
1594 if ( syncOK ) { 1595 if ( syncOK ) {
1595 if ( mSyncManager->mWriteBackFile ) 1596 if ( mSyncManager->mWriteBackFile )
1596 { 1597 {
1597 // write back XML file 1598 // write back XML file
1598 1599
1599 } 1600 }
1600 setModified( true ); 1601 setModified( true );
1601 } 1602 }
1602 } else { 1603 } else {
1603 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1604 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1604 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1605 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1605 question, i18n("Ok")) ; 1606 question, i18n("Ok")) ;
1606 } 1607 }
1607 delete calendar; 1608 delete calendar;
1608 updateView(); 1609 updateView();
1609 return syncOK; 1610 return syncOK;
1610 1611
1611 1612
1612#endif 1613#endif
1613 1614
1614} 1615}
1615 1616
1616void CalendarView::setSyncEventsReadOnly() 1617void CalendarView::setSyncEventsReadOnly()
1617{ 1618{
1618 Event * ev; 1619 Event * ev;
1619 QPtrList<Event> eL = mCalendar->rawEvents(); 1620 QPtrList<Event> eL = mCalendar->rawEvents();
1620 ev = eL.first(); 1621 ev = eL.first();
1621 while ( ev ) { 1622 while ( ev ) {
1622 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1623 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1623 ev->setReadOnly( true ); 1624 ev->setReadOnly( true );
1624 ev = eL.next(); 1625 ev = eL.next();
1625 } 1626 }
1626} 1627}
1627bool CalendarView::openCalendar(QString filename, bool merge) 1628bool CalendarView::openCalendar(QString filename, bool merge)
1628{ 1629{
1629 1630
1630 if (filename.isEmpty()) { 1631 if (filename.isEmpty()) {
1631 return false; 1632 return false;
1632 } 1633 }
1633 1634
1634 if (!QFile::exists(filename)) { 1635 if (!QFile::exists(filename)) {
1635 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1636 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1636 return false; 1637 return false;
1637 } 1638 }
1638 1639
1639 globalFlagBlockAgenda = 1; 1640 globalFlagBlockAgenda = 1;
1640 if (!merge) mCalendar->close(); 1641 if (!merge) mCalendar->close();
1641 1642
1642 mStorage->setFileName( filename ); 1643 mStorage->setFileName( filename );
1643 1644
1644 if ( mStorage->load() ) { 1645 if ( mStorage->load() ) {
1645 if ( merge ) ;//setModified( true ); 1646 if ( merge ) ;//setModified( true );
1646 else { 1647 else {
1647 //setModified( true ); 1648 //setModified( true );
1648 mViewManager->setDocumentId( filename ); 1649 mViewManager->setDocumentId( filename );
1649 mDialogManager->setDocumentId( filename ); 1650 mDialogManager->setDocumentId( filename );
1650 mTodoList->setDocumentId( filename ); 1651 mTodoList->setDocumentId( filename );
1651 } 1652 }
1652 globalFlagBlockAgenda = 2; 1653 globalFlagBlockAgenda = 2;
1653 // if ( getLastSyncEvent() ) 1654 // if ( getLastSyncEvent() )
1654 // getLastSyncEvent()->setReadOnly( true ); 1655 // getLastSyncEvent()->setReadOnly( true );
1655 mCalendar->reInitAlarmSettings(); 1656 mCalendar->reInitAlarmSettings();
1656 setSyncEventsReadOnly(); 1657 setSyncEventsReadOnly();
1657 updateUnmanagedViews(); 1658 updateUnmanagedViews();
1658 updateView(); 1659 updateView();
1659 if ( filename != MainWindow::defaultFileName() ) { 1660 if ( filename != MainWindow::defaultFileName() ) {
1660 saveCalendar( MainWindow::defaultFileName() ); 1661 saveCalendar( MainWindow::defaultFileName() );
1661 } else { 1662 } else {
1662 QFileInfo finf ( MainWindow::defaultFileName()); 1663 QFileInfo finf ( MainWindow::defaultFileName());
1663 if ( finf.exists() ) { 1664 if ( finf.exists() ) {
1664 setLoadedFileVersion( finf.lastModified () ); 1665 setLoadedFileVersion( finf.lastModified () );
1665 } 1666 }
1666 } 1667 }
1667 return true; 1668 return true;
1668 } else { 1669 } else {
1669 // while failing to load, the calendar object could 1670 // while failing to load, the calendar object could
1670 // have become partially populated. Clear it out. 1671 // have become partially populated. Clear it out.
1671 if ( !merge ) { 1672 if ( !merge ) {
1672 mCalendar->close(); 1673 mCalendar->close();
1673 mViewManager->setDocumentId( filename ); 1674 mViewManager->setDocumentId( filename );
1674 mDialogManager->setDocumentId( filename ); 1675 mDialogManager->setDocumentId( filename );
1675 mTodoList->setDocumentId( filename ); 1676 mTodoList->setDocumentId( filename );
1676 } 1677 }
1677 1678
1678 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1679 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1679 1680
1680 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1681 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1681 globalFlagBlockAgenda = 2; 1682 globalFlagBlockAgenda = 2;
1682 mCalendar->reInitAlarmSettings(); 1683 mCalendar->reInitAlarmSettings();
1683 setSyncEventsReadOnly(); 1684 setSyncEventsReadOnly();
1684 updateUnmanagedViews(); 1685 updateUnmanagedViews();
1685 updateView(); 1686 updateView();
1686 } 1687 }
1687 return false; 1688 return false;
1688} 1689}
1689void CalendarView::showOpenError() 1690void CalendarView::showOpenError()
1690{ 1691{
1691 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1692 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1692} 1693}
1693void CalendarView::setLoadedFileVersion(QDateTime dt) 1694void CalendarView::setLoadedFileVersion(QDateTime dt)
1694{ 1695{
1695 loadedFileVersion = dt; 1696 loadedFileVersion = dt;
1696} 1697}
1697bool CalendarView::checkFileChanged(QString fn) 1698bool CalendarView::checkFileChanged(QString fn)
1698{ 1699{
1699 QFileInfo finf ( fn ); 1700 QFileInfo finf ( fn );
1700 if ( !finf.exists() ) 1701 if ( !finf.exists() )
1701 return true; 1702 return true;
1702 QDateTime dt = finf.lastModified (); 1703 QDateTime dt = finf.lastModified ();
1703 if ( dt <= loadedFileVersion ) 1704 if ( dt <= loadedFileVersion )
1704 return false; 1705 return false;
1705 return true; 1706 return true;
1706 1707
1707} 1708}
1708void CalendarView::watchSavedFile() 1709void CalendarView::watchSavedFile()
1709{ 1710{
1710 QFileInfo finf ( MainWindow::defaultFileName()); 1711 QFileInfo finf ( MainWindow::defaultFileName());
1711 if ( !finf.exists() ) 1712 if ( !finf.exists() )
1712 return; 1713 return;
1713 QDateTime dt = finf.lastModified (); 1714 QDateTime dt = finf.lastModified ();
1714 if ( dt < loadedFileVersion ) { 1715 if ( dt < loadedFileVersion ) {
1715 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1716 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1716 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1717 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1717 return; 1718 return;
1718 } 1719 }
1719 loadedFileVersion = dt; 1720 loadedFileVersion = dt;
1720} 1721}
1721 1722
1722bool CalendarView::checkFileVersion(QString fn) 1723bool CalendarView::checkFileVersion(QString fn)
1723{ 1724{
1724 QFileInfo finf ( fn ); 1725 QFileInfo finf ( fn );
1725 if ( !finf.exists() ) 1726 if ( !finf.exists() )
1726 return true; 1727 return true;
1727 QDateTime dt = finf.lastModified (); 1728 QDateTime dt = finf.lastModified ();
1728 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1729 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1729 //qDebug("file on disk version %s",dt.toString().latin1()); 1730 //qDebug("file on disk version %s",dt.toString().latin1());
1730 if ( dt <= loadedFileVersion ) 1731 if ( dt <= loadedFileVersion )
1731 return true; 1732 return true;
1732 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1733 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1733 i18n("KO/Pi Warning"),i18n("Overwrite"), 1734 i18n("KO/Pi Warning"),i18n("Overwrite"),
1734 i18n("Sync+save")); 1735 i18n("Sync+save"));
1735 1736
1736 if ( km == KMessageBox::Cancel ) 1737 if ( km == KMessageBox::Cancel )
1737 return false; 1738 return false;
1738 if ( km == KMessageBox::Yes ) 1739 if ( km == KMessageBox::Yes )
1739 return true; 1740 return true;
1740 1741
1741 setSyncDevice("deleteaftersync" ); 1742 setSyncDevice("deleteaftersync" );
1742 mSyncManager->mAskForPreferences = true; 1743 mSyncManager->mAskForPreferences = true;
1743 mSyncManager->mSyncAlgoPrefs = 3; 1744 mSyncManager->mSyncAlgoPrefs = 3;
1744 mSyncManager->mWriteBackFile = false; 1745 mSyncManager->mWriteBackFile = false;
1745 mSyncManager->mWriteBackExistingOnly = false; 1746 mSyncManager->mWriteBackExistingOnly = false;
1746 mSyncManager->mShowSyncSummary = false; 1747 mSyncManager->mShowSyncSummary = false;
1747 syncCalendar( fn, 3 ); 1748 syncCalendar( fn, 3 );
1748 Event * e = getLastSyncEvent(); 1749 Event * e = getLastSyncEvent();
1749 mCalendar->deleteEvent ( e ); 1750 mCalendar->deleteEvent ( e );
1750 updateView(); 1751 updateView();
1751 return true; 1752 return true;
1752} 1753}
1753 1754
1754bool CalendarView::saveCalendar( QString filename ) 1755bool CalendarView::saveCalendar( QString filename )
1755{ 1756{
1756 1757
1757 // Store back all unsaved data into calendar object 1758 // Store back all unsaved data into calendar object
1758 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1759 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1759 if ( mViewManager->currentView() ) 1760 if ( mViewManager->currentView() )
1760 mViewManager->currentView()->flushView(); 1761 mViewManager->currentView()->flushView();
1761 1762
1762 1763
1763 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1764 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1764 mStorage->setSaveFormat( new ICalFormat() ); 1765 mStorage->setSaveFormat( new ICalFormat() );
1765 mStorage->setFileName( filename ); 1766 mStorage->setFileName( filename );
1766 bool success; 1767 bool success;
1767 success = mStorage->save(); 1768 success = mStorage->save();
1768 if ( !success ) { 1769 if ( !success ) {
1769 return false; 1770 return false;
1770 } 1771 }
1771 if ( filename == MainWindow::defaultFileName() ) { 1772 if ( filename == MainWindow::defaultFileName() ) {
1772 setLoadedFileVersion( lfv ); 1773 setLoadedFileVersion( lfv );
1773 watchSavedFile(); 1774 watchSavedFile();
1774 } 1775 }
1775 return true; 1776 return true;
1776} 1777}
1777 1778
1778void CalendarView::closeCalendar() 1779void CalendarView::closeCalendar()
1779{ 1780{
1780 1781
1781 // child windows no longer valid 1782 // child windows no longer valid
1782 emit closingDown(); 1783 emit closingDown();
1783 1784
1784 mCalendar->close(); 1785 mCalendar->close();
1785 setModified(false); 1786 setModified(false);
1786 updateView(); 1787 updateView();
1787} 1788}
1788 1789
1789void CalendarView::archiveCalendar() 1790void CalendarView::archiveCalendar()
1790{ 1791{
1791 mDialogManager->showArchiveDialog(); 1792 mDialogManager->showArchiveDialog();
1792} 1793}
1793 1794
1794 1795
1795void CalendarView::readSettings() 1796void CalendarView::readSettings()
1796{ 1797{
1797 1798
1798 1799
1799 // mViewManager->showAgendaView(); 1800 // mViewManager->showAgendaView();
1800 QString str; 1801 QString str;
1801 //qDebug("CalendarView::readSettings() "); 1802 //qDebug("CalendarView::readSettings() ");
1802 // read settings from the KConfig, supplying reasonable 1803 // read settings from the KConfig, supplying reasonable
1803 // defaults where none are to be found 1804 // defaults where none are to be found
1804 KConfig *config = KOGlobals::config(); 1805 KConfig *config = KOGlobals::config();
1805#ifndef KORG_NOSPLITTER 1806#ifndef KORG_NOSPLITTER
1806 config->setGroup("KOrganizer Geometry"); 1807 config->setGroup("KOrganizer Geometry");
1807 1808
1808 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1809 QValueList<int> sizes = config->readIntListEntry("Separator1");
1809 if (sizes.count() != 2) { 1810 if (sizes.count() != 2) {
1810 sizes << mDateNavigator->minimumSizeHint().width(); 1811 sizes << mDateNavigator->minimumSizeHint().width();
1811 sizes << 300; 1812 sizes << 300;
1812 } 1813 }
1813 mPanner->setSizes(sizes); 1814 mPanner->setSizes(sizes);
1814 1815
1815 sizes = config->readIntListEntry("Separator2"); 1816 sizes = config->readIntListEntry("Separator2");
1816 if ( ( mResourceView && sizes.count() == 4 ) || 1817 if ( ( mResourceView && sizes.count() == 4 ) ||
1817 ( !mResourceView && sizes.count() == 3 ) ) { 1818 ( !mResourceView && sizes.count() == 3 ) ) {
1818 mLeftSplitter->setSizes(sizes); 1819 mLeftSplitter->setSizes(sizes);
1819 } 1820 }
1820#endif 1821#endif
1821 globalFlagBlockAgenda = 1; 1822 globalFlagBlockAgenda = 1;
1822 mViewManager->showAgendaView(); 1823 mViewManager->showAgendaView();
1823 //mViewManager->readSettings( config ); 1824 //mViewManager->readSettings( config );
1824 mTodoList->restoreLayout(config,QString("Todo Layout")); 1825 mTodoList->restoreLayout(config,QString("Todo Layout"));
1825 readFilterSettings(config); 1826 readFilterSettings(config);
1826 1827
1827#ifdef DESKTOP_VERSION 1828#ifdef DESKTOP_VERSION
1828 config->setGroup("WidgetLayout"); 1829 config->setGroup("WidgetLayout");
1829 QStringList list; 1830 QStringList list;
1830 list = config->readListEntry("MainLayout"); 1831 list = config->readListEntry("MainLayout");
1831 int x,y,w,h; 1832 int x,y,w,h;
1832 if ( ! list.isEmpty() ) { 1833 if ( ! list.isEmpty() ) {
1833 x = list[0].toInt(); 1834 x = list[0].toInt();
1834 y = list[1].toInt(); 1835 y = list[1].toInt();
1835 w = list[2].toInt(); 1836 w = list[2].toInt();
1836 h = list[3].toInt(); 1837 h = list[3].toInt();
1837 topLevelWidget()->setGeometry(x,y,w,h); 1838 topLevelWidget()->setGeometry(x,y,w,h);
1838 1839
1839 } else { 1840 } else {
1840 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1841 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1841 } 1842 }
1842 list = config->readListEntry("EditEventLayout"); 1843 list = config->readListEntry("EditEventLayout");
1843 if ( ! list.isEmpty() ) { 1844 if ( ! list.isEmpty() ) {
1844 x = list[0].toInt(); 1845 x = list[0].toInt();
1845 y = list[1].toInt(); 1846 y = list[1].toInt();
1846 w = list[2].toInt(); 1847 w = list[2].toInt();
1847 h = list[3].toInt(); 1848 h = list[3].toInt();
1848 mEventEditor->setGeometry(x,y,w,h); 1849 mEventEditor->setGeometry(x,y,w,h);
1849 1850
1850 } 1851 }
1851 list = config->readListEntry("EditTodoLayout"); 1852 list = config->readListEntry("EditTodoLayout");
1852 if ( ! list.isEmpty() ) { 1853 if ( ! list.isEmpty() ) {
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index b147427..ab0dd50 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,267 +1,276 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29//#include "koglobals.h" 29//#include "koglobals.h"
30#include "navigatorbar.h" 30#include "navigatorbar.h"
31#include "kdatenavigator.h" 31#include "kdatenavigator.h"
32 32
33#include <kcalendarsystem.h> 33#include <kcalendarsystem.h>
34 34
35#include "datenavigatorcontainer.h" 35#include "datenavigatorcontainer.h"
36#include "koprefs.h" 36#include "koprefs.h"
37 37
38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
39 const char *name ) 39 const char *name )
40 : QWidget( parent, name ), mCalendar( 0 ), 40 : QWidget( parent, name ), mCalendar( 0 ),
41 mHorizontalCount( 1 ), mVerticalCount( 1 ) 41 mHorizontalCount( 1 ), mVerticalCount( 1 )
42{ 42{
43 mExtraViews.setAutoDelete( true ); 43 mExtraViews.setAutoDelete( true );
44 44
45 mNavigatorView = new KDateNavigator( this, name ); 45 mNavigatorView = new KDateNavigator( this, name );
46 46
47 connectNavigatorView( mNavigatorView ); 47 connectNavigatorView( mNavigatorView );
48 //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
48} 49}
49 50
50DateNavigatorContainer::~DateNavigatorContainer() 51DateNavigatorContainer::~DateNavigatorContainer()
51{ 52{
52} 53}
53 54
54void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 55void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
55{ 56{
56 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 57 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
57 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 58 SIGNAL( datesSelected( const KCal::DateList & ) ) );
58#if 0 59#if 0
59 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 60 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
60 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 61 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
61 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 62 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
62 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 63 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
63#endif 64#endif
64 connect( v, SIGNAL( weekClicked( const QDate & ) ), 65 connect( v, SIGNAL( weekClicked( const QDate & ) ),
65 SIGNAL( weekClicked( const QDate & ) ) ); 66 SIGNAL( weekClicked( const QDate & ) ) );
66 67
67 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); 68 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
68 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); 69 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
69 70
70 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 71 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
71 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 72 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
72 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 73 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
73 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 74 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
74 75
75 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); 76 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) );
76} 77}
77 78
78void DateNavigatorContainer::setCalendar( Calendar *cal ) 79void DateNavigatorContainer::setCalendar( Calendar *cal )
79{ 80{
80 mCalendar = cal; 81 mCalendar = cal;
81 mNavigatorView->setCalendar( cal ); 82 mNavigatorView->setCalendar( cal );
82 KDateNavigator *n; 83 KDateNavigator *n;
83 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 84 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
84 n->setCalendar( cal ); 85 n->setCalendar( cal );
85 } 86 }
86} 87}
87 88
88void DateNavigatorContainer::updateDayMatrix() 89void DateNavigatorContainer::updateDayMatrix()
89{ 90{
90 mNavigatorView->updateDayMatrix(); 91 mNavigatorView->updateDayMatrix();
91 KDateNavigator *n; 92 KDateNavigator *n;
92 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 93 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
93 n->updateDayMatrix(); 94 n->updateDayMatrix();
94 } 95 }
95} 96}
96 97
97void DateNavigatorContainer::updateToday() 98void DateNavigatorContainer::updateToday()
98{ 99{
99 qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); 100 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
100#if 0 101#if 0
101 mNavigatorView->updateToday(); 102 mNavigatorView->updateToday();
102 KDateNavigator *n; 103 KDateNavigator *n;
103 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 104 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
104 n->updateToday(); 105 n->updateToday();
105 } 106 }
106#endif 107#endif
107} 108}
108 109
109void DateNavigatorContainer::updateView() 110void DateNavigatorContainer::updateView()
110{ 111{
111 mNavigatorView->updateView(); 112 mNavigatorView->updateView();
112 KDateNavigator *n; 113 KDateNavigator *n;
113 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 114 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
114 n->updateView(); 115 n->updateView();
115 } 116 }
116} 117}
117 118
118void DateNavigatorContainer::updateConfig() 119void DateNavigatorContainer::updateConfig()
119{ 120{
120 mNavigatorView->updateConfig(); 121 mNavigatorView->updateConfig();
121 KDateNavigator *n; 122 KDateNavigator *n;
122 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 123 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
123 n->updateConfig(); 124 n->updateConfig();
124 } 125 }
125} 126}
126 127
127void DateNavigatorContainer::selectDates( const DateList &dateList ) 128void DateNavigatorContainer::selectDates( const DateList &dateList )
128{ 129{
129 mNavigatorView->selectDates( dateList ); 130 mNavigatorView->selectDates( dateList );
130 setBaseDates(); 131 setBaseDates();
131 if ( mExtraViews.count() ) { 132 if ( mExtraViews.count() ) {
132 KDateNavigator *view = mExtraViews.at( 0 ); 133 KDateNavigator *view = mExtraViews.at( 0 );
133 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 134 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
134 view->dayMatrix()->repaint( false ); 135 view->dayMatrix()->repaint( false );
135 if ( mExtraViews.count() > 1 ) { 136 if ( mExtraViews.count() > 1 ) {
136 KDateNavigator *view = mExtraViews.at( 1 ); 137 KDateNavigator *view = mExtraViews.at( 1 );
137 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 138 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
138 view->dayMatrix()->repaint( false ); 139 view->dayMatrix()->repaint( false );
139 } 140 }
140 } 141 }
141} 142}
142 143
143void DateNavigatorContainer::setBaseDates() 144void DateNavigatorContainer::setBaseDates()
144{ 145{
145 KCal::DateList dateList = mNavigatorView->selectedDates(); 146 KCal::DateList dateList = mNavigatorView->selectedDates();
146 if ( dateList.isEmpty() ) { 147 if ( dateList.isEmpty() ) {
147 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; 148 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl;
148 } 149 }
149 QDate baseDate = dateList.first(); 150 QDate baseDate = dateList.first();
150 KDateNavigator *n; 151 KDateNavigator *n;
151 bool doRepaint = false; // skip first repaint 152 bool doRepaint = false; // skip first repaint
152 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 153 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
153 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); 154 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
154 n->setBaseDate( baseDate, doRepaint ); 155 n->setBaseDate( baseDate, doRepaint );
155 doRepaint = true; 156 doRepaint = true;
156 } 157 }
157} 158}
158 159
159void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 160void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
160{ 161{
161#if 0 162#if 0
162 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; 163 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
163 kdDebug(5850) << " CURRENT SIZE: " << size() << endl; 164 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
164 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; 165 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
165 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; 166 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
166 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; 167 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
167#endif 168#endif
168 //QSize minSize = mNavigatorView->sizeHintTwoButtons(); 169 //QSize minSize = mNavigatorView->sizeHintTwoButtons();
169 QSize minSize = mNavigatorView->yourSizeHint(); 170 QSize minSize = mNavigatorView->yourSizeHint();
170 171
171// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; 172// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
172 173
173 int verticalCount = size().height() / minSize.height(); 174 int verticalCount = size().height() / minSize.height();
174 int horizontalCount = size().width() / minSize.width(); 175 int horizontalCount = size().width() / minSize.width();
175 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); 176 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() );
176 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); 177 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
177 bool fontchange = false; 178 bool fontchange = false;
179 if ( horizontalCount == 1)
180 horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width();
178 QFont fo; 181 QFont fo;
179 if ( horizontalCount != mHorizontalCount || 182 if ( horizontalCount != mHorizontalCount ||
180 verticalCount != mVerticalCount ) { 183 verticalCount != mVerticalCount ) {
181 uint count = horizontalCount * verticalCount; 184 uint count = horizontalCount * verticalCount;
182 if ( count == 0 ) { 185 if ( count == 0 ) {
183 bool ok; 186 bool ok;
184 fo = mNavigatorView->yourFontHint( size() , &ok); 187 fo = mNavigatorView->yourFontHint( size() , &ok );
185 //mNavigatorView->resize( size() ); 188 //mNavigatorView->resize( size() );
186 //if ( ! ok ) 189 //if ( ! ok )
187 // return; 190 // return;
188 minSize = mNavigatorView->sizeHintTwoButtons(); 191 int butt = 2;
192 horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width();
193 if ( horizontalCount <= 1 )
194 minSize = mNavigatorView->sizeHintTwoButtons( 4 );
195 else
196 minSize = mNavigatorView->sizeHintTwoButtons();
189 verticalCount = size().height() / minSize.height(); 197 verticalCount = size().height() / minSize.height();
190 horizontalCount = size().width() / minSize.width(); 198 horizontalCount = size().width() / minSize.width();
191 if ( horizontalCount == 0 ) 199 if ( horizontalCount == 0 )
192 horizontalCount = 1; 200 horizontalCount = 1;
193 if ( verticalCount == 0 ) 201 if ( verticalCount == 0 )
194 verticalCount = 1; 202 verticalCount = 1;
195 fontchange = true; 203 fontchange = true;
196 count = horizontalCount * verticalCount; 204 count = horizontalCount * verticalCount;
197 } else { 205 } else {
198 if ( mNavigatorView->fontChanged() ) { 206 if ( mNavigatorView->fontChanged() ) {
199 fontchange = true; 207 fontchange = true;
200 fo = KOPrefs::instance()->mDateNavigatorFont; 208 fo = KOPrefs::instance()->mDateNavigatorFont;
201 mNavigatorView->changeFont( fo ); 209 mNavigatorView->changeFont( fo );
202 mNavigatorView->unsetFontChanged(); 210 mNavigatorView->unsetFontChanged();
203 } 211 }
204 } 212 }
205 213
206 while ( count > ( mExtraViews.count() + 1 ) ) { 214 while ( count > ( mExtraViews.count() + 1 ) ) {
207 KDateNavigator *n = new KDateNavigator( this ); 215 KDateNavigator *n = new KDateNavigator( this );
208 n->setMonthSignalOffset ( mExtraViews.count()+1 ); 216 n->setMonthSignalOffset ( mExtraViews.count()+1 );
209 mExtraViews.append( n ); 217 mExtraViews.append( n );
210 n->setCalendar( mCalendar ); 218 n->setCalendar( mCalendar );
211 setBaseDates(); 219 setBaseDates();
212 connectNavigatorView( n ); 220 connectNavigatorView( n );
213 n->show(); 221 n->show();
214 } 222 }
215 int iii = 0; 223 int iii = 0;
216 while ( iii < ( mExtraViews.count() ) ) { 224 while ( iii < ( mExtraViews.count() ) ) {
217 if ( iii < count-1 ) 225 if ( iii < count-1 )
218 mExtraViews.at( iii )->show(); 226 mExtraViews.at( iii )->show();
219 else 227 else
220 mExtraViews.at( iii )->hide(); 228 mExtraViews.at( iii )->hide();
221 ++iii; 229 ++iii;
222 } 230 }
223 if ( fontchange ) { 231 if ( fontchange ) {
224 //mNavigatorView->changeFont( fo ); 232 //mNavigatorView->changeFont( fo );
225 uint i; 233 uint i;
226 for( i = 0; i < mExtraViews.count(); ++i ) { 234 for( i = 0; i < mExtraViews.count(); ++i ) {
227 KDateNavigator *view = mExtraViews.at( i ); 235 KDateNavigator *view = mExtraViews.at( i );
228 view->changeFont( fo ); 236 view->changeFont( fo );
229 } 237 }
230 } 238 }
231 mHorizontalCount = horizontalCount; 239 mHorizontalCount = horizontalCount;
232 mVerticalCount = verticalCount; 240 mVerticalCount = verticalCount;
233 } 241 }
242 //qDebug("COUNT %d ", mExtraViews.count());
234 int height = size().height() / verticalCount; 243 int height = size().height() / verticalCount;
235 int width = size().width() / horizontalCount; 244 int width = size().width() / horizontalCount;
236 245
237 NavigatorBar *bar = mNavigatorView->navigatorBar(); 246 NavigatorBar *bar = mNavigatorView->navigatorBar();
238 if ( horizontalCount > 1 ) bar->showButtons( true, false ); 247 if ( horizontalCount > 1 ) bar->showButtons( true, false );
239 else bar->showButtons( true, true ); 248 else bar->showButtons( true, true );
240 249
241 mNavigatorView->setGeometry(0, 250 mNavigatorView->setGeometry(0,
242 0, width, height ); 251 0, width, height );
243 for( uint i = 0; i < mExtraViews.count(); ++i ) { 252 for( uint i = 0; i < mExtraViews.count(); ++i ) {
244 int x = ( i + 1 ) % horizontalCount; 253 int x = ( i + 1 ) % horizontalCount;
245 int y = ( i + 1 ) / horizontalCount; 254 int y = ( i + 1 ) / horizontalCount;
246 255
247 KDateNavigator *view = mExtraViews.at( i ); 256 KDateNavigator *view = mExtraViews.at( i );
248 bar = view->navigatorBar(); 257 bar = view->navigatorBar();
249 if ( y > 0 ) bar->showButtons( false, false ); 258 if ( y > 0 ) bar->showButtons( false, false );
250 else { 259 else {
251 if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); 260 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
252 else bar->showButtons( false, false ); 261 else bar->showButtons( false, false );
253 } 262 }
254 view->setGeometry( x * width, 263 view->setGeometry( x * width,
255 y * height, width, height ); 264 y * height, width, height );
256 } 265 }
257} 266}
258 267
259QSize DateNavigatorContainer::minimumSizeHint() const 268QSize DateNavigatorContainer::minimumSizeHint() const
260{ 269{
261 return mNavigatorView->minimumSizeHint(); 270 return mNavigatorView->minimumSizeHint();
262} 271}
263 272
264QSize DateNavigatorContainer::sizeHint() const 273QSize DateNavigatorContainer::sizeHint() const
265{ 274{
266 return mNavigatorView->sizeHint(); 275 return mNavigatorView->sizeHint();
267} 276}
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index fe83e09..231095f 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -1,442 +1,447 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qkeycode.h> 25#include <qkeycode.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qframe.h> 28#include <qframe.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <kglobal.h> 34#include <kglobal.h>
35 35
36#include "koglobals.h" 36#include "koglobals.h"
37#include "koprefs.h" 37#include "koprefs.h"
38#ifndef KORG_NOPLUGINS 38#ifndef KORG_NOPLUGINS
39#include "kocore.h" 39#include "kocore.h"
40#endif 40#endif
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#include "navigatorbar.h" 44#include "navigatorbar.h"
45 45
46#include "kdatenavigator.h" 46#include "kdatenavigator.h"
47 47
48KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) 48KDateNavigator::KDateNavigator( QWidget *parent, const char *name )
49 : QFrame(parent, name), 49 : QFrame(parent, name),
50 updateTimer(0L) 50 updateTimer(0L)
51{ 51{
52 setFrameStyle(QFrame::NoFrame); 52 setFrameStyle(QFrame::NoFrame);
53 QDate startDate = QDate::currentDate(); 53 QDate startDate = QDate::currentDate();
54 QGridLayout *topLayout = new QGridLayout(this,8,8); 54 QGridLayout *topLayout = new QGridLayout(this,8,8);
55 55
56 if (! startDate.isValid()) { 56 if (! startDate.isValid()) {
57 qDebug("KDateNavigator::invalid startdate "); 57 qDebug("KDateNavigator::invalid startdate ");
58 startDate = QDate::currentDate(); 58 startDate = QDate::currentDate();
59 } 59 }
60 mMonthSignalOffset = 0; 60 mMonthSignalOffset = 0;
61 mSelectedDates.append(startDate); 61 mSelectedDates.append(startDate);
62 m_MthYr = startDate; 62 m_MthYr = startDate;
63 m_bShowWeekNums = true; 63 m_bShowWeekNums = true;
64 64
65 setFont( KOPrefs::instance()->mDateNavigatorFont ); 65 setFont( KOPrefs::instance()->mDateNavigatorFont );
66 mNavigatorBar = new NavigatorBar( startDate, this ); 66 mNavigatorBar = new NavigatorBar( startDate, this );
67 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); 67 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 );
68 //mNavigatorBar->resize( 1,1); 68 //mNavigatorBar->resize( 1,1);
69 connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 69 connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
70 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 70 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
71 connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 71 connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
72 connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 72 connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
73 connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); 73 connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
74 74
75 // get the day of the week on the first day 75 // get the day of the week on the first day
76 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 76 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
77 m_fstDayOfWk = dayone.dayOfWeek(); 77 m_fstDayOfWk = dayone.dayOfWeek();
78 78
79 int i; 79 int i;
80 80
81 // Set up the heading fields. 81 // Set up the heading fields.
82 for( i = 0; i < 7; i++ ) { 82 for( i = 0; i < 7; i++ ) {
83 headings[i] = new QLabel("",this); 83 headings[i] = new QLabel("",this);
84 //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); 84 //headings[i]->setFont(QFont("Arial", 10, QFont::Bold));
85 headings[i]->setAlignment(AlignCenter); 85 headings[i]->setAlignment(AlignCenter);
86 86
87 topLayout->addWidget(headings[i],1,i+1); 87 topLayout->addWidget(headings[i],1,i+1);
88 } 88 }
89 89
90 // Create the weeknumber labels 90 // Create the weeknumber labels
91 for( i = 0; i < 6; i++ ) { 91 for( i = 0; i < 6; i++ ) {
92 weeknos[i] = new QLabel(this); 92 weeknos[i] = new QLabel(this);
93 weeknos[i]->setAlignment(AlignCenter); 93 weeknos[i]->setAlignment(AlignCenter);
94 //weeknos[i]->setFont(QFont("Arial", 10)); 94 //weeknos[i]->setFont(QFont("Arial", 10));
95 if(!m_bShowWeekNums) { 95 if(!m_bShowWeekNums) {
96 weeknos[i]->hide(); 96 weeknos[i]->hide();
97 } 97 }
98 weeknos[i]->installEventFilter(this); 98 weeknos[i]->installEventFilter(this);
99 99
100 topLayout->addWidget(weeknos[i],i+2,0); 100 topLayout->addWidget(weeknos[i],i+2,0);
101 } 101 }
102 102
103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); 103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix");
104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); 104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken);
105 daymatrix->setLineWidth(1); 105 daymatrix->setLineWidth(1);
106 106
107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), 107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ),
108 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 108 SIGNAL( datesSelected( const KCal::DateList & ) ) );
109 109
110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ), 110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ),
111 SIGNAL( eventDropped( Event * ) ) ); 111 SIGNAL( eventDropped( Event * ) ) );
112 112
113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7); 113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7);
114 114
115 // read settings from configuration file. 115 // read settings from configuration file.
116 updateConfig(); 116 updateConfig();
117 enableRollover(FollowMonth); 117 enableRollover(FollowMonth);
118 mySizeHint = sizeHintTwoButtons(); 118 mySizeHint = sizeHintTwoButtons();
119 myFullSizeHint = sizeHintTwoButtons( 4 );
119 mFontChanged = false; 120 mFontChanged = false;
120} 121}
121void KDateNavigator::changeFont ( QFont fo ) 122void KDateNavigator::changeFont ( QFont fo )
122{ 123{
123 setFont( fo ); 124 setFont( fo );
124 mNavigatorBar->resetFont( fo ); 125 mNavigatorBar->resetFont( fo );
125} 126}
126QFont KDateNavigator::yourFontHint( QSize si , bool *b) 127QFont KDateNavigator::yourFontHint( QSize si , bool *b)
127{ 128{
128 QFont fo = KOPrefs::instance()->mDateNavigatorFont; 129 QFont fo = KOPrefs::instance()->mDateNavigatorFont;
129 *b = false; 130 *b = false;
130 int fontPoint = fo.pointSize(); 131 int fontPoint = fo.pointSize();
131 while ( fontPoint > 5 ) { 132 while ( fontPoint > 5 ) {
132 --fontPoint; 133 --fontPoint;
133 fo.setPointSize( fontPoint ); 134 fo.setPointSize( fontPoint );
134 setFont( fo ); 135 setFont( fo );
135 mFontChanged = true; 136 mFontChanged = true;
136 mNavigatorBar->resetFont( fo ); 137 mNavigatorBar->resetFont( fo );
137 QSize sh = sizeHintTwoButtons(); 138 QSize sh = sizeHintTwoButtons( 2 );
138 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); 139 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() );
139 if ( si.width() > sh.width() && si.height() > sh.height()) { 140 if ( si.width() > sh.width() && si.height() > sh.height()) {
141 if ( si.width() / sh.width() == 1 ) {
142 if ( si.width() < sizeHintTwoButtons( 4 ).width())
143 continue;
144 }
140 *b = true; 145 *b = true;
141 //qDebug("fooooooooooooooooooooooouuuuund "); 146 //qDebug("fooooooooooooooooooooooouuuuund ");
142 break; 147 break;
143 } 148 }
144 } 149 }
145 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); 150 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() );
146 return fo; 151 return fo;
147} 152}
148QSize KDateNavigator::sizeHint() const 153QSize KDateNavigator::sizeHint() const
149{ 154{
150 QFontMetrics fm ( font() ); 155 QFontMetrics fm ( font() );
151 QSize day = daymatrix->sizeHint(); 156 QSize day = daymatrix->sizeHint();
152 QSize nav = mNavigatorBar->sizeHint(); 157 QSize nav = mNavigatorBar->sizeHint();
153 int wid = fm.width( "30") + day.width()+3; 158 int wid = fm.width( "30") + day.width()+3;
154 int hei = fm.height() +day.height()+nav.height()+2; 159 int hei = fm.height() +day.height()+nav.height()+2;
155 if ( wid < nav.width() ) 160 if ( wid < nav.width() )
156 wid = nav.width() ; 161 wid = nav.width() ;
157 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 162 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
158 return QSize ( wid, hei ); 163 return QSize ( wid, hei );
159} 164}
160QSize KDateNavigator::sizeHintTwoButtons() const 165QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const
161{ 166{
162 QFontMetrics fm ( font() ); 167 QFontMetrics fm ( font() );
163 QSize day = daymatrix->sizeHint(); 168 QSize day = daymatrix->sizeHint();
164 QSize nav = mNavigatorBar->sizeHintTwoButtons(); 169 QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum );
165 int wid = fm.width( "30") + day.width()+3; 170 int wid = fm.width( "30") + day.width()+3;
166 int hei = fm.height() +day.height()+nav.height()+2; 171 int hei = fm.height() +day.height()+nav.height()+2;
167 if ( wid < nav.width() ) 172 if ( wid < nav.width() )
168 wid = nav.width() ; 173 wid = nav.width() ;
169 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 174 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
170 return QSize ( wid, hei ); 175 return QSize ( wid, hei );
171} 176}
172void KDateNavigator::slotMonthSelected( int m ) 177void KDateNavigator::slotMonthSelected( int m )
173{ 178{
174 if ( m_MthYr.month() <= mMonthSignalOffset) 179 if ( m_MthYr.month() <= mMonthSignalOffset)
175 m += 12; 180 m += 12;
176 //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset); 181 //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset);
177 emit monthSelected( m - mMonthSignalOffset ); 182 emit monthSelected( m - mMonthSignalOffset );
178 183
179} 184}
180void KDateNavigator::setCalendar( Calendar *cal ) 185void KDateNavigator::setCalendar( Calendar *cal )
181{ 186{
182 daymatrix->setCalendar( cal ); 187 daymatrix->setCalendar( cal );
183} 188}
184 189
185void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true 190void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true
186{ 191{
187 m_MthYr = date; 192 m_MthYr = date;
188 193
189 updateDates(); 194 updateDates();
190 updateView(); 195 updateView();
191 196
192 KCal::DateList dates; 197 KCal::DateList dates;
193 dates.append( date ); 198 dates.append( date );
194 mNavigatorBar->selectDates( dates ); 199 mNavigatorBar->selectDates( dates );
195 200
196 daymatrix->clearSelection(); 201 daymatrix->clearSelection();
197 if ( doRepaint ) 202 if ( doRepaint )
198 daymatrix->repaint( false ); 203 daymatrix->repaint( false );
199} 204}
200 205
201void KDateNavigator::enableRollover(RolloverType r) 206void KDateNavigator::enableRollover(RolloverType r)
202{ 207{
203 switch(r) 208 switch(r)
204 { 209 {
205 case None : 210 case None :
206 if (updateTimer) 211 if (updateTimer)
207 { 212 {
208 updateTimer->stop(); 213 updateTimer->stop();
209 delete updateTimer; 214 delete updateTimer;
210 updateTimer=0L; 215 updateTimer=0L;
211 } 216 }
212 break; 217 break;
213 case FollowDay : 218 case FollowDay :
214 case FollowMonth : 219 case FollowMonth :
215 if (!updateTimer) 220 if (!updateTimer)
216 { 221 {
217 updateTimer = new QTimer(this); 222 updateTimer = new QTimer(this);
218 QObject::connect(updateTimer,SIGNAL(timeout()), 223 QObject::connect(updateTimer,SIGNAL(timeout()),
219 this,SLOT(possiblyPastMidnight())); 224 this,SLOT(possiblyPastMidnight()));
220 } 225 }
221 updateTimer->start(0,true); 226 updateTimer->start(0,true);
222 lastDayChecked = QDate::currentDate(); 227 lastDayChecked = QDate::currentDate();
223 } 228 }
224 updateRollover=r; 229 updateRollover=r;
225} 230}
226 231
227 232
228KDateNavigator::~KDateNavigator() 233KDateNavigator::~KDateNavigator()
229{ 234{
230} 235}
231 236
232 237
233void KDateNavigator::passedMidnight() 238void KDateNavigator::passedMidnight()
234{ 239{
235 QDate today = QDate::currentDate(); 240 QDate today = QDate::currentDate();
236 bool emitMonth = false; 241 bool emitMonth = false;
237 242
238 if (today.month() != lastDayChecked.month()) 243 if (today.month() != lastDayChecked.month())
239 { 244 {
240 if (updateRollover==FollowMonth && 245 if (updateRollover==FollowMonth &&
241 daymatrix->isEndOfMonth()) { 246 daymatrix->isEndOfMonth()) {
242 goNextMonth(); 247 goNextMonth();
243 emitMonth=true; 248 emitMonth=true;
244 } 249 }
245 } 250 }
246 daymatrix->recalculateToday(); 251 daymatrix->recalculateToday();
247 daymatrix->repaint( false ); 252 daymatrix->repaint( false );
248 emit dayPassed(today); 253 emit dayPassed(today);
249 if (emitMonth) { emit monthPassed(today); } 254 if (emitMonth) { emit monthPassed(today); }
250} 255}
251 256
252/* slot */ void KDateNavigator::possiblyPastMidnight() 257/* slot */ void KDateNavigator::possiblyPastMidnight()
253{ 258{
254 if (lastDayChecked!=QDate::currentDate()) 259 if (lastDayChecked!=QDate::currentDate())
255 { 260 {
256 passedMidnight(); 261 passedMidnight();
257 lastDayChecked=QDate::currentDate(); 262 lastDayChecked=QDate::currentDate();
258 } 263 }
259 // Set the timer to go off 1 second after midnight 264 // Set the timer to go off 1 second after midnight
260 // or after 8 minutes, whichever comes first. 265 // or after 8 minutes, whichever comes first.
261 if (updateTimer) 266 if (updateTimer)
262 { 267 {
263 QTime now = QTime::currentTime(); 268 QTime now = QTime::currentTime();
264 QTime midnight = QTime(23,59,59); 269 QTime midnight = QTime(23,59,59);
265 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 270 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
266 271
267 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 272 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
268 //.arg(now.toString()).arg(midnight.toString())); 273 //.arg(now.toString()).arg(midnight.toString()));
269 274
270 updateTimer->stop(); 275 updateTimer->stop();
271 updateTimer->start(msecsWait,true); 276 updateTimer->start(msecsWait,true);
272 } 277 }
273} 278}
274 279
275void KDateNavigator::updateDates() 280void KDateNavigator::updateDates()
276{ 281{
277 // Find the first day of the week of the current month. 282 // Find the first day of the week of the current month.
278 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 283 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
279 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 284 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
280 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 285 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
281 //int di = d1 - d2 + 1; 286 //int di = d1 - d2 + 1;
282 dayone = dayone.addDays( -d2 + 1 ); 287 dayone = dayone.addDays( -d2 + 1 );
283 288
284 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 289 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
285 290
286 // If month begins on Monday and Monday is first day of week, 291 // If month begins on Monday and Monday is first day of week,
287 // month should begin on second line. Sunday doesn't have this problem. 292 // month should begin on second line. Sunday doesn't have this problem.
288 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 293 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
289 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 294 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
290 295
291 // update the matrix dates 296 // update the matrix dates
292 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 297 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
293 298
294 299
295 daymatrix->updateView(dayone.addDays(index)); 300 daymatrix->updateView(dayone.addDays(index));
296//each updateDates is followed by an updateView -> repaint is issued there ! 301//each updateDates is followed by an updateView -> repaint is issued there !
297// daymatrix->repaint(); 302// daymatrix->repaint();
298} 303}
299 304
300void KDateNavigator::updateDayMatrix() 305void KDateNavigator::updateDayMatrix()
301{ 306{
302 daymatrix->updateView(); 307 daymatrix->updateView();
303 //daymatrix->repaint(); 308 //daymatrix->repaint();
304} 309}
305 310
306 311
307void KDateNavigator::updateView() 312void KDateNavigator::updateView()
308{ 313{
309 314
310 setUpdatesEnabled( false ); 315 setUpdatesEnabled( false );
311 316
312 int i; 317 int i;
313 318
314// kdDebug() << "updateView() -> daymatrix->updateView()" << endl; 319// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
315 daymatrix->updateView(); 320 daymatrix->updateView();
316 321
317 // set the week numbers. 322 // set the week numbers.
318 for(i = 0; i < 6; i++) { 323 for(i = 0; i < 6; i++) {
319 QString weeknum; 324 QString weeknum;
320 // remember, according to ISO 8601, the first week of the year is the 325 // remember, according to ISO 8601, the first week of the year is the
321 // first week that contains a thursday. Thus we must subtract off 4, 326 // first week that contains a thursday. Thus we must subtract off 4,
322 // not just 1. 327 // not just 1.
323 328
324 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 329 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
325 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); 330 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
326 331
327 int add = 0; 332 int add = 0;
328 if ( ! KGlobal::locale()->weekStartsMonday() ) 333 if ( ! KGlobal::locale()->weekStartsMonday() )
329 ++add; 334 ++add;
330 if (dayOfYear % 7 != 0) 335 if (dayOfYear % 7 != 0)
331 weeknum.setNum(dayOfYear / 7 + 1+add); 336 weeknum.setNum(dayOfYear / 7 + 1+add);
332 else 337 else
333 weeknum.setNum(dayOfYear / 7 +add); 338 weeknum.setNum(dayOfYear / 7 +add);
334 weeknos[i]->setText(weeknum); 339 weeknos[i]->setText(weeknum);
335 } 340 }
336 341
337 setUpdatesEnabled( true ); 342 setUpdatesEnabled( true );
338// kdDebug() << "updateView() -> repaint()" << endl; 343// kdDebug() << "updateView() -> repaint()" << endl;
339 repaint(); 344 repaint();
340 // daymatrix->repaint(); 345 // daymatrix->repaint();
341} 346}
342 347
343void KDateNavigator::updateConfig() 348void KDateNavigator::updateConfig()
344{ 349{
345 int day; 350 int day;
346 for(int i=0; i<7; i++) { 351 for(int i=0; i<7; i++) {
347 // take the first letter of the day name to be the abbreviation 352 // take the first letter of the day name to be the abbreviation
348 if (KGlobal::locale()->weekStartsMonday()) { 353 if (KGlobal::locale()->weekStartsMonday()) {
349 day = i+1; 354 day = i+1;
350 } else { 355 } else {
351 if (i==0) day = 7; 356 if (i==0) day = 7;
352 else day = i; 357 else day = i;
353 } 358 }
354 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 359 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
355 true ); 360 true );
356 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 361 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
357 headings[i]->setText( dayName ); 362 headings[i]->setText( dayName );
358 } 363 }
359 updateDates(); 364 updateDates();
360 updateView(); 365 updateView();
361} 366}
362 367
363void KDateNavigator::setShowWeekNums(bool enabled) 368void KDateNavigator::setShowWeekNums(bool enabled)
364{ 369{
365 m_bShowWeekNums = enabled; 370 m_bShowWeekNums = enabled;
366 for(int i=0; i<6; i++) { 371 for(int i=0; i<6; i++) {
367 if(enabled) 372 if(enabled)
368 weeknos[i]->show(); 373 weeknos[i]->show();
369 else 374 else
370 weeknos[i]->hide(); 375 weeknos[i]->hide();
371 } 376 }
372 resize(size()); 377 resize(size());
373} 378}
374 379
375void KDateNavigator::selectDates(const DateList& dateList) 380void KDateNavigator::selectDates(const DateList& dateList)
376{ 381{
377 382
378 if (dateList.count() > 0) { 383 if (dateList.count() > 0) {
379 mNavigatorBar->selectDates( dateList ); 384 mNavigatorBar->selectDates( dateList );
380 mSelectedDates = dateList; 385 mSelectedDates = dateList;
381 386
382 // set our record of the month and year that this datetbl is 387 // set our record of the month and year that this datetbl is
383 // displaying. 388 // displaying.
384 m_MthYr = mSelectedDates.first(); 389 m_MthYr = mSelectedDates.first();
385 390
386 391
387 // set our record of the first day of the week of the current 392 // set our record of the first day of the week of the current
388 // month. This needs to be done before calling dayToIndex, since it 393 // month. This needs to be done before calling dayToIndex, since it
389 // relies on this information being up to date. 394 // relies on this information being up to date.
390 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 395 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
391 m_fstDayOfWk = dayone.dayOfWeek(); 396 m_fstDayOfWk = dayone.dayOfWeek();
392 397
393 updateDates(); 398 updateDates();
394 399
395 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 400 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
396 401
397 updateView(); 402 updateView();
398 } 403 }
399} 404}
400 405
401int KDateNavigator::dayNum(int row, int col) 406int KDateNavigator::dayNum(int row, int col)
402{ 407{
403 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; 408 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
404} 409}
405 410
406int KDateNavigator::dayToIndex(int dayNum) 411int KDateNavigator::dayToIndex(int dayNum)
407{ 412{
408 int row, col; 413 int row, col;
409 414
410 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; 415 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7;
411 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) 416 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1))
412 row++; 417 row++;
413 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; 418 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7;
414 return row * 7 + col; 419 return row * 7 + col;
415} 420}
416 421
417void KDateNavigator::wheelEvent (QWheelEvent *e) 422void KDateNavigator::wheelEvent (QWheelEvent *e)
418{ 423{
419 if(e->delta()>0) emit goPrevious(); 424 if(e->delta()>0) emit goPrevious();
420 else emit goNext(); 425 else emit goNext();
421 426
422 e->accept(); 427 e->accept();
423} 428}
424 429
425bool KDateNavigator::eventFilter (QObject *o,QEvent *e) 430bool KDateNavigator::eventFilter (QObject *o,QEvent *e)
426{ 431{
427 if (e->type() == QEvent::MouseButtonPress) { 432 if (e->type() == QEvent::MouseButtonPress) {
428 int i; 433 int i;
429 for(i=0;i<6;++i) { 434 for(i=0;i<6;++i) {
430 if (o == weeknos[i]) { 435 if (o == weeknos[i]) {
431 QDate weekstart = daymatrix->getDate(i*7); 436 QDate weekstart = daymatrix->getDate(i*7);
432 emit weekClicked(weekstart); 437 emit weekClicked(weekstart);
433 break; 438 break;
434 } 439 }
435 } 440 }
436 return true; 441 return true;
437 } else { 442 } else {
438 return false; 443 return false;
439 } 444 }
440} 445}
441 446
442//#include "kdatenavigator.moc" 447//#include "kdatenavigator.moc"
diff --git a/korganizer/kdatenavigator.h b/korganizer/kdatenavigator.h
index 77b9b7c..10bc1be 100644
--- a/korganizer/kdatenavigator.h
+++ b/korganizer/kdatenavigator.h
@@ -1,161 +1,163 @@
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 KDATENAVIGATOR_H 23#ifndef KDATENAVIGATOR_H
24#define KDATENAVIGATOR_H 24#define KDATENAVIGATOR_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qlabel.h> 28#include <qlabel.h>
29 29
30#include <libkcal/calendar.h> 30#include <libkcal/calendar.h>
31 31
32#include "kodaymatrix.h" 32#include "kodaymatrix.h"
33 33
34class QPushButton; 34class QPushButton;
35class QTimer; 35class QTimer;
36 36
37class KCalendarSystem; 37class KCalendarSystem;
38 38
39class NavigatorBar; 39class NavigatorBar;
40 40
41class KDateNavigator: public QFrame 41class KDateNavigator: public QFrame
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44 public: 44 public:
45 KDateNavigator( QWidget *parent = 0,const char *name = 0 ); 45 KDateNavigator( QWidget *parent = 0,const char *name = 0 );
46 ~KDateNavigator(); 46 ~KDateNavigator();
47 47
48 /** The DateNavigator automatically checks for 48 /** The DateNavigator automatically checks for
49 * the passage of midnight. If rollover type is 49 * the passage of midnight. If rollover type is
50 * set to None, no signals are emitted and no 50 * set to None, no signals are emitted and no
51 * processing is done. With rollover set to 51 * processing is done. With rollover set to
52 * FollowDay, the day highlighter changes at 52 * FollowDay, the day highlighter changes at
53 * midnight and dayPassed() is emitted. 53 * midnight and dayPassed() is emitted.
54 * With FollowMonth, it has the same effect 54 * With FollowMonth, it has the same effect
55 * as FollowDay but also adjusts the month that is 55 * as FollowDay but also adjusts the month that is
56 * visible and emits monthPassed() when the month changes. 56 * visible and emits monthPassed() when the month changes.
57 */ 57 */
58 enum RolloverType { None, FollowDay, FollowMonth } ; 58 enum RolloverType { None, FollowDay, FollowMonth } ;
59 void enableRollover( RolloverType ); 59 void enableRollover( RolloverType );
60 60
61 void setShowWeekNums( bool enabled ); 61 void setShowWeekNums( bool enabled );
62 void setCalendar( Calendar * ); 62 void setCalendar( Calendar * );
63 void setBaseDate( const QDate & , bool doRepaint = true ); 63 void setBaseDate( const QDate & , bool doRepaint = true );
64 KCal::DateList selectedDates() const { return mSelectedDates; } 64 KCal::DateList selectedDates() const { return mSelectedDates; }
65 NavigatorBar *navigatorBar() const { return mNavigatorBar; } 65 NavigatorBar *navigatorBar() const { return mNavigatorBar; }
66 void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off%12;} 66 void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off%12;}
67 QSize yourSizeHint() { return mySizeHint; } 67 QSize yourSizeHint()const { return mySizeHint; };
68 QSize yourFullSizeHint() const { return myFullSizeHint;};
68 QFont yourFontHint( QSize , bool * b); 69 QFont yourFontHint( QSize , bool * b);
69 bool fontChanged() {return mFontChanged; } 70 bool fontChanged() {return mFontChanged; }
70 void unsetFontChanged() { mFontChanged = false; } 71 void unsetFontChanged() { mFontChanged = false; }
71 KODayMatrix *dayMatrix() { return daymatrix ;} 72 KODayMatrix *dayMatrix() { return daymatrix ;}
72 QSize sizeHint() const; 73 QSize sizeHint() const;
73 QSize sizeHintTwoButtons() const; 74 QSize sizeHintTwoButtons( int butnum = 2 ) const;
74 void changeFont ( QFont fo ); 75 void changeFont ( QFont fo );
75 public slots: 76 public slots:
76 void selectDates( const KCal::DateList & ); 77 void selectDates( const KCal::DateList & );
77 void updateView(); 78 void updateView();
78 void updateConfig(); 79 void updateConfig();
79 void updateDayMatrix(); 80 void updateDayMatrix();
80 81
81 signals: 82 signals:
82 void datesSelected( const KCal::DateList & ); 83 void datesSelected( const KCal::DateList & );
83 void eventDropped( Event * ); 84 void eventDropped( Event * );
84 void weekClicked( const QDate &); 85 void weekClicked( const QDate &);
85 86
86 void goPrevious(); 87 void goPrevious();
87 void goNext(); 88 void goNext();
88 89
89 void goNextMonth(); 90 void goNextMonth();
90 void goPrevMonth(); 91 void goPrevMonth();
91 void goNextYear(); 92 void goNextYear();
92 void goPrevYear(); 93 void goPrevYear();
93 void monthSelected( int ); 94 void monthSelected( int );
94 95
95 // Signals emitted at midnight carrying the new date. 96 // Signals emitted at midnight carrying the new date.
96 void dayPassed( QDate ); 97 void dayPassed( QDate );
97 void monthPassed( QDate ); 98 void monthPassed( QDate );
98 99
99 protected slots: 100 protected slots:
100 101
101 /** 102 /**
102 * Called regularly to see if we need to update the view 103 * Called regularly to see if we need to update the view
103 * wrt. the today box and the month box. Only important 104 * wrt. the today box and the month box. Only important
104 * if you leave KOrganizer idle for long periods of time. 105 * if you leave KOrganizer idle for long periods of time.
105 * 106 *
106 * Until we have a reliable way of setting QTimers to go 107 * Until we have a reliable way of setting QTimers to go
107 * off at a particular wall-clock time, we need this, 108 * off at a particular wall-clock time, we need this,
108 * which calls passedMidnight() at the right moments. 109 * which calls passedMidnight() at the right moments.
109 */ 110 */
110 void possiblyPastMidnight(); 111 void possiblyPastMidnight();
111 112
112 /** handles updating the view when midnight has come by due to idle time. 113 /** handles updating the view when midnight has come by due to idle time.
113 * 114 *
114 */ 115 */
115 void passedMidnight(); 116 void passedMidnight();
116 void slotMonthSelected( int m ); 117 void slotMonthSelected( int m );
117 protected: 118 protected:
118 void updateDates(); 119 void updateDates();
119 120
120 void wheelEvent (QWheelEvent *); 121 void wheelEvent (QWheelEvent *);
121 122
122 bool eventFilter (QObject *,QEvent *); 123 bool eventFilter (QObject *,QEvent *);
123 124
124 private: 125 private:
125 QSize mySizeHint; 126 QSize mySizeHint;
127 QSize myFullSizeHint;
126 bool mFontChanged; 128 bool mFontChanged;
127 int mMonthSignalOffset; 129 int mMonthSignalOffset;
128 NavigatorBar *mNavigatorBar; 130 NavigatorBar *mNavigatorBar;
129 131
130 QFrame *headingSep; 132 QFrame *headingSep;
131 QFrame *weeknumSep; 133 QFrame *weeknumSep;
132 QLabel *headings[7]; 134 QLabel *headings[7];
133 QLabel *weeknos[7]; 135 QLabel *weeknos[7];
134 KODayMatrix *daymatrix; 136 KODayMatrix *daymatrix;
135 137
136 KCal::DateList mSelectedDates; 138 KCal::DateList mSelectedDates;
137 QDate m_MthYr; 139 QDate m_MthYr;
138 int m_fstDayOfWk; 140 int m_fstDayOfWk;
139 bool m_bShowWeekNums; 141 bool m_bShowWeekNums;
140 142
141 int dayNum(int row, int col); 143 int dayNum(int row, int col);
142 int dayToIndex(int dayNum); 144 int dayToIndex(int dayNum);
143 145
144 Calendar *mCalendar; 146 Calendar *mCalendar;
145 KCalendarSystem *mCalendarSystem; 147 KCalendarSystem *mCalendarSystem;
146 148
147 const QString *curHeaders; 149 const QString *curHeaders;
148 150
149 /** used to update the day view periodically, in particular every 151 /** used to update the day view periodically, in particular every
150 * midnight to move the "today" rectangle. 152 * midnight to move the "today" rectangle.
151 */ 153 */
152 QTimer *updateTimer; 154 QTimer *updateTimer;
153 QDate lastDayChecked; 155 QDate lastDayChecked;
154 RolloverType updateRollover; 156 RolloverType updateRollover;
155 157
156 // Disabling copy constructor and assignment operator 158 // Disabling copy constructor and assignment operator
157 KDateNavigator(const KDateNavigator & ); 159 KDateNavigator(const KDateNavigator & );
158 KDateNavigator &operator=(const KDateNavigator &); 160 KDateNavigator &operator=(const KDateNavigator &);
159}; 161};
160 162
161#endif 163#endif
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 120bc89..a2e0ae0 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,931 +1,932 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
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 ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name ), mCalendar( 0 ) 106 : QFrame( parent, name ), mCalendar( 0 )
107 107
108#if 0 108#if 0
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name) 110 QFrame(parent, name)
111#endif 111#endif
112{ 112{
113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
114 mPendingUpdateBeforeRepaint = false; 114 mPendingUpdateBeforeRepaint = false;
115 mouseDown = false; 115 mouseDown = false;
116 // initialize dynamic arrays 116 // initialize dynamic arrays
117 bDays.resize ( NUMDAYS ); 117 bDays.resize ( NUMDAYS );
118 days = new QDate[NUMDAYS]; 118 days = new QDate[NUMDAYS];
119 daylbls = new QString[NUMDAYS]; 119 daylbls = new QString[NUMDAYS];
120 events = new int[NUMDAYS]; 120 events = new int[NUMDAYS];
121 mToolTip = new DynamicTip(this); 121 mToolTip = new DynamicTip(this);
122 122
123 // set default values used for drawing the matrix 123 // set default values used for drawing the matrix
124 mDefaultBackColor = palette().active().base(); 124 mDefaultBackColor = palette().active().base();
125 mDefaultTextColor = palette().active().foreground(); 125 mDefaultTextColor = palette().active().foreground();
126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
128 mSelectedDaysColor = QColor("white"); 128 mSelectedDaysColor = QColor("white");
129 mTodayMarginWidth = 2; 129 mTodayMarginWidth = 2;
130 mSelEnd = mSelStart = NOSELECTION; 130 mSelEnd = mSelStart = NOSELECTION;
131 131
132 setAcceptDrops(true); 132 setAcceptDrops(true);
133 //setFont( QFont("Arial", 10) ); 133 //setFont( QFont("Arial", 10) );
134 134
135 mUpdateTimer = new QTimer( this ); 135 mUpdateTimer = new QTimer( this );
136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
137 mRepaintTimer = new QTimer( this ); 137 mRepaintTimer = new QTimer( this );
138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
139 mDayChanged = false; 139 mDayChanged = false;
140 updateView(); 140 updateView();
141} 141}
142QString KODayMatrix::getWhatsThisText( QPoint p ) 142QString KODayMatrix::getWhatsThisText( QPoint p )
143{ 143{
144 144
145 int tmp = getDayIndexFrom(p.x(), p.y()); 145 int tmp = getDayIndexFrom(p.x(), p.y());
146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
147 return QString(); 147 return QString();
148 QDate mDate = days[tmp]; 148 QDate mDate = days[tmp];
149 QPtrList<Event> eventlist = mCalendar->events(mDate); 149 QPtrList<Event> eventlist = mCalendar->events(mDate);
150 Event *event; 150 Event *event;
151 QStringList mToolTip; 151 QStringList mToolTip;
152 for(event=eventlist.first();event != 0;event=eventlist.next()) { 152 for(event=eventlist.first();event != 0;event=eventlist.next()) {
153 QString mToolTipText; 153 QString mToolTipText;
154 QString text; 154 QString text;
155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
156 if (event->isMultiDay()) { 156 if (event->isMultiDay()) {
157 QString prefix = "<->";multiday = 2; 157 QString prefix = "<->";multiday = 2;
158 QString time; 158 QString time;
159 if ( event->doesRecur() ) { 159 if ( event->doesRecur() ) {
160 if ( event->recursOn( mDate) ) { 160 if ( event->recursOn( mDate) ) {
161 prefix ="->" ;multiday = 1; 161 prefix ="->" ;multiday = 1;
162 } 162 }
163 else { 163 else {
164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
165 if ( event->recursOn( mDate.addDays( -days)) ) { 165 if ( event->recursOn( mDate.addDays( -days)) ) {
166 prefix ="<-" ;multiday = 3; 166 prefix ="<-" ;multiday = 3;
167 } 167 }
168 } 168 }
169 } else { 169 } else {
170 if (mDate == event->dtStart().date()) { 170 if (mDate == event->dtStart().date()) {
171 prefix ="->" ;multiday = 1; 171 prefix ="->" ;multiday = 1;
172 } else if (mDate == event->dtEnd().date()) { 172 } else if (mDate == event->dtEnd().date()) {
173 prefix ="<-" ;multiday = 3; 173 prefix ="<-" ;multiday = 3;
174 } 174 }
175 } 175 }
176 if ( !event->doesFloat() ) { 176 if ( !event->doesFloat() ) {
177 if ( mDate == event->dtStart().date () ) 177 if ( mDate == event->dtStart().date () )
178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
179 else if ( mDate == event->dtEnd().date () ) 179 else if ( mDate == event->dtEnd().date () )
180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
181 181
182 } 182 }
183 text = time + event->summary(); 183 text = time + event->summary();
184 mToolTipText += prefix + text; 184 mToolTipText += prefix + text;
185 } else { 185 } else {
186 if (event->doesFloat()) { 186 if (event->doesFloat()) {
187 text = event->summary(); 187 text = event->summary();
188 mToolTipText += text; 188 mToolTipText += text;
189 } 189 }
190 else { 190 else {
191 text = KGlobal::locale()->formatTime(event->dtStart().time()); 191 text = KGlobal::locale()->formatTime(event->dtStart().time());
192 text += " " + event->summary(); 192 text += " " + event->summary();
193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
194 } 194 }
195 } 195 }
196 if ( !event->location().isEmpty() ) 196 if ( !event->location().isEmpty() )
197 mToolTipText += " (" + event->location() + ")"; 197 mToolTipText += " (" + event->location() + ")";
198#if QT_VERSION >= 0x030000 198#if QT_VERSION >= 0x030000
199 mToolTipText.replace( '<' , "&lt;" ); 199 mToolTipText.replace( '<' , "&lt;" );
200 mToolTipText.replace( '>' , "&gt;" ); 200 mToolTipText.replace( '>' , "&gt;" );
201#else 201#else
202 if ( mToolTipText.find ('<') >= 0 ) { 202 if ( mToolTipText.find ('<') >= 0 ) {
203 mToolTipText.replace( QRegExp("<") , "&lt;" ); 203 mToolTipText.replace( QRegExp("<") , "&lt;" );
204 } 204 }
205 if ( mToolTipText.find ('>') >= 0 ) { 205 if ( mToolTipText.find ('>') >= 0 ) {
206 mToolTipText.replace( QRegExp(">") , "&gt;" ); 206 mToolTipText.replace( QRegExp(">") , "&gt;" );
207 } 207 }
208#endif 208#endif
209 //qDebug("TTT: %s ", mToolTipText.latin1()); 209 //qDebug("TTT: %s ", mToolTipText.latin1());
210 mToolTip.append( mToolTipText ); 210 mToolTip.append( mToolTipText );
211 } 211 }
212 mToolTip.sort(); 212 mToolTip.sort();
213 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 213 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
214} 214}
215void KODayMatrix::setCalendar( Calendar *cal ) 215void KODayMatrix::setCalendar( Calendar *cal )
216{ 216{
217 mCalendar = cal; 217 mCalendar = cal;
218 218
219 setAcceptDrops( mCalendar ); 219 setAcceptDrops( mCalendar );
220 220
221 updateEvents(); 221 updateEvents();
222} 222}
223 223
224QColor KODayMatrix::getShadedColor(QColor color) 224QColor KODayMatrix::getShadedColor(QColor color)
225{ 225{
226 QColor shaded; 226 QColor shaded;
227 int h=0; 227 int h=0;
228 int s=0; 228 int s=0;
229 int v=0; 229 int v=0;
230 color.hsv(&h,&s,&v); 230 color.hsv(&h,&s,&v);
231 s = s/4; 231 s = s/4;
232 v = 192+v/4; 232 v = 192+v/4;
233 shaded.setHsv(h,s,v); 233 shaded.setHsv(h,s,v);
234 234
235 return shaded; 235 return shaded;
236} 236}
237 237
238KODayMatrix::~KODayMatrix() 238KODayMatrix::~KODayMatrix()
239{ 239{
240 // delete mKODaymatrixWhatsThis; 240 // delete mKODaymatrixWhatsThis;
241 delete [] days; 241 delete [] days;
242 delete [] daylbls; 242 delete [] daylbls;
243 delete [] events; 243 delete [] events;
244 delete mToolTip; 244 delete mToolTip;
245} 245}
246 246
247/* 247/*
248void KODayMatrix::setStartDate(QDate start) 248void KODayMatrix::setStartDate(QDate start)
249{ 249{
250 updateView(start); 250 updateView(start);
251} 251}
252*/ 252*/
253 253
254void KODayMatrix::addSelectedDaysTo(DateList& selDays) 254void KODayMatrix::addSelectedDaysTo(DateList& selDays)
255{ 255{
256 256
257 if (mSelStart == NOSELECTION) { 257 if (mSelStart == NOSELECTION) {
258 return; 258 return;
259 } 259 }
260 260
261 //cope with selection being out of matrix limits at top (< 0) 261 //cope with selection being out of matrix limits at top (< 0)
262 int i0 = mSelStart; 262 int i0 = mSelStart;
263 if (i0 < 0) { 263 if (i0 < 0) {
264 for (int i = i0; i < 0; i++) { 264 for (int i = i0; i < 0; i++) {
265 selDays.append(days[0].addDays(i)); 265 selDays.append(days[0].addDays(i));
266 } 266 }
267 i0 = 0; 267 i0 = 0;
268 } 268 }
269 269
270 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 270 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
271 if (mSelEnd > NUMDAYS-1) { 271 if (mSelEnd > NUMDAYS-1) {
272 for (int i = i0; i <= NUMDAYS-1; i++) { 272 for (int i = i0; i <= NUMDAYS-1; i++) {
273 selDays.append(days[i]); 273 selDays.append(days[i]);
274 } 274 }
275 for (int i = NUMDAYS; i < mSelEnd; i++) { 275 for (int i = NUMDAYS; i < mSelEnd; i++) {
276 selDays.append(days[0].addDays(i)); 276 selDays.append(days[0].addDays(i));
277 } 277 }
278 278
279 // apply normal routine to selection being entirely within matrix limits 279 // apply normal routine to selection being entirely within matrix limits
280 } else { 280 } else {
281 for (int i = i0; i <= mSelEnd; i++) { 281 for (int i = i0; i <= mSelEnd; i++) {
282 selDays.append(days[i]); 282 selDays.append(days[i]);
283 } 283 }
284 } 284 }
285} 285}
286 286
287void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 287void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
288{ 288{
289 mSelStart = startdate.daysTo(start); 289 mSelStart = startdate.daysTo(start);
290 if ( mSelStart < 0 ) 290 if ( mSelStart < 0 )
291 mSelStart = 0; 291 mSelStart = 0;
292 mSelEnd = startdate.daysTo(end); 292 mSelEnd = startdate.daysTo(end);
293 //qDebug("SELECTION %d %d ", mSelStart ,mSelEnd ); 293 //qDebug("SELECTION %d %d ", mSelStart ,mSelEnd );
294 if ( mSelEnd < 0 ) 294 if ( mSelEnd < 0 )
295 clearSelection(); 295 clearSelection();
296} 296}
297void KODayMatrix::clearSelection() 297void KODayMatrix::clearSelection()
298{ 298{
299 mSelEnd = mSelStart = NOSELECTION; 299 mSelEnd = mSelStart = NOSELECTION;
300} 300}
301 301
302 302
303void KODayMatrix::recalculateToday() 303void KODayMatrix::recalculateToday()
304{ 304{
305 today = -1; 305 today = -1;
306 for (int i=0; i<NUMDAYS; i++) { 306 for (int i=0; i<NUMDAYS; i++) {
307 events[i] = 0; 307 events[i] = 0;
308 days[i] = startdate.addDays(i); 308 days[i] = startdate.addDays(i);
309 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 309 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
310 310
311 // if today is in the currently displayed month, hilight today 311 // if today is in the currently displayed month, hilight today
312 if (days[i].year() == QDate::currentDate().year() && 312 if (days[i].year() == QDate::currentDate().year() &&
313 days[i].month() == QDate::currentDate().month() && 313 days[i].month() == QDate::currentDate().month() &&
314 days[i].day() == QDate::currentDate().day()) { 314 days[i].day() == QDate::currentDate().day()) {
315 today = i; 315 today = i;
316 } 316 }
317 } 317 }
318 // qDebug(QString("Today is visible at %1.").arg(today)); 318 // qDebug(QString("Today is visible at %1.").arg(today));
319} 319}
320 320
321void KODayMatrix::updateView() 321void KODayMatrix::updateView()
322{ 322{
323 updateView(startdate); 323 updateView(startdate);
324} 324}
325void KODayMatrix::repaintViewTimed() 325void KODayMatrix::repaintViewTimed()
326{ 326{
327 mRepaintTimer->stop(); 327 mRepaintTimer->stop();
328 repaint(false); 328 repaint(false);
329} 329}
330void KODayMatrix::updateViewTimed() 330void KODayMatrix::updateViewTimed()
331{ 331{
332 mUpdateTimer->stop(); 332 mUpdateTimer->stop();
333 if ( !mCalendar ) { 333 if ( !mCalendar ) {
334 qDebug("NOT CAL "); 334 qDebug("NOT CAL ");
335 return; 335 return;
336 } 336 }
337 //qDebug("KODayMatrix::updateViewTimed "); 337 //qDebug("KODayMatrix::updateViewTimed ");
338 for(int i = 0; i < NUMDAYS; i++) { 338 for(int i = 0; i < NUMDAYS; i++) {
339 // if events are set for the day then remember to draw it bold 339 // if events are set for the day then remember to draw it bold
340 QPtrList<Event> eventlist = mCalendar->events(days[i]); 340 QPtrList<Event> eventlist = mCalendar->events(days[i]);
341 Event *event; 341 Event *event;
342 int numEvents = eventlist.count(); 342 int numEvents = eventlist.count();
343 QString holiStr = ""; 343 QString holiStr = "";
344 bDays.clearBit(i); 344 bDays.clearBit(i);
345 for(event=eventlist.first();event != 0;event=eventlist.next()) { 345 for(event=eventlist.first();event != 0;event=eventlist.next()) {
346 ushort recurType = event->recurrence()->doesRecur(); 346 ushort recurType = event->recurrence()->doesRecur();
347 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 347 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
348 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 348 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
349 numEvents--; 349 numEvents--;
350 } 350 }
351 if ( event->isHoliday()) { 351 if ( event->isHoliday()) {
352 if ( !holiStr.isEmpty() ) 352 if ( !holiStr.isEmpty() )
353 holiStr += "\n"; 353 holiStr += "\n";
354 holiStr += event->summary(); 354 holiStr += event->summary();
355 if ( !event->location().isEmpty() ) 355 if ( !event->location().isEmpty() )
356 holiStr += " (" + event->location() + ")"; 356 holiStr += " (" + event->location() + ")";
357 } 357 }
358 if ( event->isBirthday()) { 358 if ( event->isBirthday()) {
359 if ( !holiStr.isEmpty() ) 359 if ( !holiStr.isEmpty() )
360 holiStr += "\n"; 360 holiStr += "\n";
361 holiStr += i18n("Birthday") + ": "+event->summary(); 361 holiStr += i18n("Birthday") + ": "+event->summary();
362 if ( !event->location().isEmpty() ) 362 if ( !event->location().isEmpty() )
363 holiStr += " (" + event->location() + ")"; 363 holiStr += " (" + event->location() + ")";
364 bDays.setBit(i); 364 bDays.setBit(i);
365 } 365 }
366 } 366 }
367 events[i] = numEvents; 367 events[i] = numEvents;
368 //if it is a holy day then draw it red. Sundays are consider holidays, too 368 //if it is a holy day then draw it red. Sundays are consider holidays, too
369 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 369 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
370 !holiStr.isEmpty()) { 370 !holiStr.isEmpty()) {
371 mHolidays[i] = holiStr; 371 mHolidays[i] = holiStr;
372 } else { 372 } else {
373 mHolidays[i] = QString::null; 373 mHolidays[i] = QString::null;
374 } 374 }
375 } 375 }
376 if ( ! mPendingUpdateBeforeRepaint ) 376 if ( ! mPendingUpdateBeforeRepaint )
377 repaint(false); 377 repaint(false);
378} 378}
379void KODayMatrix::updateView(QDate actdate) 379void KODayMatrix::updateView(QDate actdate)
380{ 380{
381 381
382 if ( ! actdate.isValid() ) { 382 if ( ! actdate.isValid() ) {
383 //qDebug("date not valid "); 383 //qDebug("date not valid ");
384 return; 384 return;
385 } 385 }
386 mDayChanged = false; 386 mDayChanged = false;
387 //flag to indicate if the starting day of the matrix has changed by this call 387 //flag to indicate if the starting day of the matrix has changed by this call
388 //mDayChanged = false; 388 //mDayChanged = false;
389 // if a new startdate is to be set then apply Cornelius's calculation 389 // if a new startdate is to be set then apply Cornelius's calculation
390 // of the first day to be shown 390 // of the first day to be shown
391 if (actdate != startdate) { 391 if (actdate != startdate) {
392 // reset index of selection according to shift of starting date from startdate to actdate 392 // reset index of selection according to shift of starting date from startdate to actdate
393 if (mSelStart != NOSELECTION) { 393 if (mSelStart != NOSELECTION) {
394 int tmp = actdate.daysTo(startdate); 394 int tmp = actdate.daysTo(startdate);
395 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 395 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
396 // shift selection if new one would be visible at least partly ! 396 // shift selection if new one would be visible at least partly !
397 397
398 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 398 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
399 // nested if is required for next X display pushed from a different month - correction required 399 // nested if is required for next X display pushed from a different month - correction required
400 // otherwise, for month forward and backward, it must be avoided 400 // otherwise, for month forward and backward, it must be avoided
401 if( mSelStart > NUMDAYS || mSelStart < 0 ) 401 if( mSelStart > NUMDAYS || mSelStart < 0 )
402 mSelStart = mSelStart + tmp; 402 mSelStart = mSelStart + tmp;
403 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 403 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
404 mSelEnd = mSelEnd + tmp; 404 mSelEnd = mSelEnd + tmp;
405 } 405 }
406 } 406 }
407 startdate = actdate; 407 startdate = actdate;
408 mDayChanged = true; 408 mDayChanged = true;
409 recalculateToday(); 409 recalculateToday();
410 } 410 }
411 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 411 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
412 if ( !isVisible() ) { 412 if ( !isVisible() ) {
413 mPendingUpdateBeforeRepaint = true; 413 mPendingUpdateBeforeRepaint = true;
414 } else { 414 } else {
415#ifdef DESKTOP_VERSION 415#ifdef DESKTOP_VERSION
416 //mRepaintTimer->start( 100 ); 416 //mRepaintTimer->start( 100 );
417 mUpdateTimer->start( 100 ); 417 //updateViewTimed();
418 mUpdateTimer->start( 20 );
418#else 419#else
419 mRepaintTimer->start( 350 ); 420 mRepaintTimer->start( 350 );
420 mUpdateTimer->start( 1200 ); 421 mUpdateTimer->start( 1200 );
421#endif 422#endif
422 } 423 }
423} 424}
424void KODayMatrix::updateEvents() 425void KODayMatrix::updateEvents()
425{ 426{
426 if ( !mCalendar ) return; 427 if ( !mCalendar ) return;
427 428
428 for( int i = 0; i < NUMDAYS; i++ ) { 429 for( int i = 0; i < NUMDAYS; i++ ) {
429 // if events are set for the day then remember to draw it bold 430 // if events are set for the day then remember to draw it bold
430 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 431 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
431 int numEvents = eventlist.count(); 432 int numEvents = eventlist.count();
432 Event *event; 433 Event *event;
433 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 434 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
434 ushort recurType = event->doesRecur(); 435 ushort recurType = event->doesRecur();
435 436
436 if ( ( recurType == Recurrence::rDaily && 437 if ( ( recurType == Recurrence::rDaily &&
437 !KOPrefs::instance()->mDailyRecur ) || 438 !KOPrefs::instance()->mDailyRecur ) ||
438 ( recurType == Recurrence::rWeekly && 439 ( recurType == Recurrence::rWeekly &&
439 !KOPrefs::instance()->mWeeklyRecur ) ) { 440 !KOPrefs::instance()->mWeeklyRecur ) ) {
440 numEvents--; 441 numEvents--;
441 } 442 }
442 } 443 }
443 events[ i ] = numEvents; 444 events[ i ] = numEvents;
444 } 445 }
445} 446}
446 447
447const QDate& KODayMatrix::getDate(int offset) 448const QDate& KODayMatrix::getDate(int offset)
448{ 449{
449 if (offset < 0 || offset > NUMDAYS-1) { 450 if (offset < 0 || offset > NUMDAYS-1) {
450 qDebug("Wrong offset2 %d", offset); 451 qDebug("Wrong offset2 %d", offset);
451 return days[0]; 452 return days[0];
452 } 453 }
453 return days[offset]; 454 return days[offset];
454} 455}
455 456
456QString KODayMatrix::getHolidayLabel(int offset) 457QString KODayMatrix::getHolidayLabel(int offset)
457{ 458{
458 if (offset < 0 || offset > NUMDAYS-1) { 459 if (offset < 0 || offset > NUMDAYS-1) {
459 qDebug("Wrong offset1 %d", offset); 460 qDebug("Wrong offset1 %d", offset);
460 return QString(); 461 return QString();
461 } 462 }
462 return mHolidays[offset]; 463 return mHolidays[offset];
463} 464}
464 465
465int KODayMatrix::getDayIndexFrom(int x, int y) 466int KODayMatrix::getDayIndexFrom(int x, int y)
466{ 467{
467 int colModulo = (width()-2) % 7; 468 int colModulo = (width()-2) % 7;
468 int rowModulo = (height()-2) % 6; 469 int rowModulo = (height()-2) % 6;
469#if 0 470#if 0
470 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 471 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
471 6 - x/daysize.width() : x/daysize.width()); 472 6 - x/daysize.width() : x/daysize.width());
472#endif 473#endif
473 int xVal = (x-colModulo/2-2)/daysize.width(); 474 int xVal = (x-colModulo/2-2)/daysize.width();
474 int yVal = (y-rowModulo/2-2)/daysize.height(); 475 int yVal = (y-rowModulo/2-2)/daysize.height();
475 476
476 477
477 return 7*(yVal) + xVal; 478 return 7*(yVal) + xVal;
478 479
479} 480}
480 481
481// ---------------------------------------------------------------------------- 482// ----------------------------------------------------------------------------
482// M O U S E E V E N T H A N D L I N G 483// M O U S E E V E N T H A N D L I N G
483// ---------------------------------------------------------------------------- 484// ----------------------------------------------------------------------------
484 485
485void KODayMatrix::mousePressEvent (QMouseEvent* e) 486void KODayMatrix::mousePressEvent (QMouseEvent* e)
486{ 487{
487 488
488 if ( e->button() == LeftButton ) 489 if ( e->button() == LeftButton )
489 mouseDown = true; 490 mouseDown = true;
490 mSelStart = getDayIndexFrom(e->x(), e->y()); 491 mSelStart = getDayIndexFrom(e->x(), e->y());
491 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 492 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
492 mSelInit = mSelStart; 493 mSelInit = mSelStart;
493 mSelEnd = mSelStart; 494 mSelEnd = mSelStart;
494 repaint(false); 495 repaint(false);
495} 496}
496 497
497void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 498void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
498{ 499{
499 if ( e->button() == LeftButton ) 500 if ( e->button() == LeftButton )
500 if ( ! mouseDown ) { 501 if ( ! mouseDown ) {
501 return; 502 return;
502 } 503 }
503 else 504 else
504 mouseDown = false; 505 mouseDown = false;
505 int tmp = getDayIndexFrom(e->x(), e->y()); 506 int tmp = getDayIndexFrom(e->x(), e->y());
506 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 507 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
507 508
508 if (mSelInit > tmp) { 509 if (mSelInit > tmp) {
509 mSelEnd = mSelInit; 510 mSelEnd = mSelInit;
510 if (tmp != mSelStart) { 511 if (tmp != mSelStart) {
511 mSelStart = tmp; 512 mSelStart = tmp;
512 repaint(false); 513 repaint(false);
513 } 514 }
514 } else { 515 } else {
515 mSelStart = mSelInit; 516 mSelStart = mSelInit;
516 517
517 //repaint only if selection has changed 518 //repaint only if selection has changed
518 if (tmp != mSelEnd) { 519 if (tmp != mSelEnd) {
519 mSelEnd = tmp; 520 mSelEnd = tmp;
520 repaint(false); 521 repaint(false);
521 } 522 }
522 } 523 }
523 524
524 DateList daylist; 525 DateList daylist;
525 if ( mSelStart < 0 ) 526 if ( mSelStart < 0 )
526 mSelStart = 0; 527 mSelStart = 0;
527 for (int i = mSelStart; i <= mSelEnd; i++) { 528 for (int i = mSelStart; i <= mSelEnd; i++) {
528 daylist.append(days[i]); 529 daylist.append(days[i]);
529 } 530 }
530 emit selected((const DateList)daylist); 531 emit selected((const DateList)daylist);
531 532
532} 533}
533 534
534void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 535void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
535{ 536{
536 if ( ! mouseDown ) { 537 if ( ! mouseDown ) {
537 return; 538 return;
538 } 539 }
539 int tmp = getDayIndexFrom(e->x(), e->y()); 540 int tmp = getDayIndexFrom(e->x(), e->y());
540 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 541 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
541 542
542 if (mSelInit > tmp) { 543 if (mSelInit > tmp) {
543 mSelEnd = mSelInit; 544 mSelEnd = mSelInit;
544 if (tmp != mSelStart) { 545 if (tmp != mSelStart) {
545 mSelStart = tmp; 546 mSelStart = tmp;
546 repaint(false); 547 repaint(false);
547 } 548 }
548 } else { 549 } else {
549 mSelStart = mSelInit; 550 mSelStart = mSelInit;
550 551
551 //repaint only if selection has changed 552 //repaint only if selection has changed
552 if (tmp != mSelEnd) { 553 if (tmp != mSelEnd) {
553 mSelEnd = tmp; 554 mSelEnd = tmp;
554 repaint(false); 555 repaint(false);
555 } 556 }
556 } 557 }
557} 558}
558 559
559// ---------------------------------------------------------------------------- 560// ----------------------------------------------------------------------------
560// D R A G ' N D R O P H A N D L I N G 561// D R A G ' N D R O P H A N D L I N G
561// ---------------------------------------------------------------------------- 562// ----------------------------------------------------------------------------
562 563
563void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 564void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
564{ 565{
565#ifndef KORG_NODND 566#ifndef KORG_NODND
566 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 567 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
567 e->ignore(); 568 e->ignore();
568 return; 569 return;
569 } 570 }
570 571
571 // some visual feedback 572 // some visual feedback
572// oldPalette = palette(); 573// oldPalette = palette();
573// setPalette(my_HilitePalette); 574// setPalette(my_HilitePalette);
574// update(); 575// update();
575#endif 576#endif
576} 577}
577 578
578void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 579void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
579{ 580{
580#ifndef KORG_NODND 581#ifndef KORG_NODND
581 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 582 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
582 e->ignore(); 583 e->ignore();
583 return; 584 return;
584 } 585 }
585 586
586 e->accept(); 587 e->accept();
587#endif 588#endif
588} 589}
589 590
590void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 591void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
591{ 592{
592#ifndef KORG_NODND 593#ifndef KORG_NODND
593// setPalette(oldPalette); 594// setPalette(oldPalette);
594// update(); 595// update();
595#endif 596#endif
596} 597}
597 598
598void KODayMatrix::dropEvent(QDropEvent *e) 599void KODayMatrix::dropEvent(QDropEvent *e)
599{ 600{
600#ifndef KORG_NODND 601#ifndef KORG_NODND
601// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 602// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
602 603
603 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 604 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
604 e->ignore(); 605 e->ignore();
605 return; 606 return;
606 } 607 }
607 608
608 DndFactory factory( mCalendar ); 609 DndFactory factory( mCalendar );
609 Event *event = factory.createDrop(e); 610 Event *event = factory.createDrop(e);
610 611
611 if (event) { 612 if (event) {
612 e->acceptAction(); 613 e->acceptAction();
613 614
614 Event *existingEvent = mCalendar->event(event->uid()); 615 Event *existingEvent = mCalendar->event(event->uid());
615 616
616 if(existingEvent) { 617 if(existingEvent) {
617 // uniquify event 618 // uniquify event
618 event->recreate(); 619 event->recreate();
619/* 620/*
620 KMessageBox::sorry(this, 621 KMessageBox::sorry(this,
621 i18n("Event already exists in this calendar."), 622 i18n("Event already exists in this calendar."),
622 i18n("Drop Event")); 623 i18n("Drop Event"));
623 delete event; 624 delete event;
624 return; 625 return;
625*/ 626*/
626 } 627 }
627// kdDebug() << "Drop new Event" << endl; 628// kdDebug() << "Drop new Event" << endl;
628 // Adjust date 629 // Adjust date
629 QDateTime start = event->dtStart(); 630 QDateTime start = event->dtStart();
630 QDateTime end = event->dtEnd(); 631 QDateTime end = event->dtEnd();
631 int duration = start.daysTo(end); 632 int duration = start.daysTo(end);
632 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 633 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
633 634
634 start.setDate(days[idx]); 635 start.setDate(days[idx]);
635 end.setDate(days[idx].addDays(duration)); 636 end.setDate(days[idx].addDays(duration));
636 637
637 event->setDtStart(start); 638 event->setDtStart(start);
638 event->setDtEnd(end); 639 event->setDtEnd(end);
639 mCalendar->addEvent(event); 640 mCalendar->addEvent(event);
640 641
641 emit eventDropped(event); 642 emit eventDropped(event);
642 } else { 643 } else {
643// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 644// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
644 e->ignore(); 645 e->ignore();
645 } 646 }
646#endif 647#endif
647} 648}
648 649
649// ---------------------------------------------------------------------------- 650// ----------------------------------------------------------------------------
650// P A I N T E V E N T H A N D L I N G 651// P A I N T E V E N T H A N D L I N G
651// ---------------------------------------------------------------------------- 652// ----------------------------------------------------------------------------
652 653
653void KODayMatrix::paintEvent(QPaintEvent * pevent) 654void KODayMatrix::paintEvent(QPaintEvent * pevent)
654{ 655{
655 QRect sz = frameRect(); 656 QRect sz = frameRect();
656 if ( sz.width() <= 0 || sz.height() <= 0 ) 657 if ( sz.width() <= 0 || sz.height() <= 0 )
657 return; 658 return;
658 if ( mPendingUpdateBeforeRepaint ) { 659 if ( mPendingUpdateBeforeRepaint ) {
659 updateViewTimed(); 660 updateViewTimed();
660 mPendingUpdateBeforeRepaint = false; 661 mPendingUpdateBeforeRepaint = false;
661 } 662 }
662 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 663 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
663 myPix.resize(sz.size() ); 664 myPix.resize(sz.size() );
664 } 665 }
665 QPainter p(&myPix); 666 QPainter p(&myPix);
666 p.setFont(font()); 667 p.setFont(font());
667 668
668 669
669 int dheight = daysize.height(); 670 int dheight = daysize.height();
670 int dwidth = daysize.width(); 671 int dwidth = daysize.width();
671 int row,col; 672 int row,col;
672 int selw, selh; 673 int selw, selh;
673 int xyOff = frameWidth(); 674 int xyOff = frameWidth();
674 int colModulo = sz.width() % 7; 675 int colModulo = sz.width() % 7;
675 int rowModulo = sz.height() % 6; 676 int rowModulo = sz.height() % 6;
676 //qDebug("col %d row %d ",colModulo,rowModulo ); 677 //qDebug("col %d row %d ",colModulo,rowModulo );
677 678
678 bool isRTL = KOGlobals::self()->reverseLayout(); 679 bool isRTL = KOGlobals::self()->reverseLayout();
679 680
680 // draw background and topleft frame 681 // draw background and topleft frame
681 p.fillRect(pevent->rect(), mDefaultBackColor); 682 p.fillRect(pevent->rect(), mDefaultBackColor);
682 p.setPen(mDefaultTextColor); 683 p.setPen(mDefaultTextColor);
683 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 684 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
684 int mSelStartT = mSelStart; 685 int mSelStartT = mSelStart;
685 int mSelEndT = mSelEnd; 686 int mSelEndT = mSelEnd;
686 if ( mSelEndT >= NUMDAYS ) 687 if ( mSelEndT >= NUMDAYS )
687 mSelEndT = NUMDAYS-1; 688 mSelEndT = NUMDAYS-1;
688 // draw selected days with highlighted background color 689 // draw selected days with highlighted background color
689 if (mSelStart != NOSELECTION) { 690 if (mSelStart != NOSELECTION) {
690 bool skip = false; 691 bool skip = false;
691 if ( ! mouseDown ) { 692 if ( ! mouseDown ) {
692 int mo = days[20].month(); 693 int mo = days[20].month();
693 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 694 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
694 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 695 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
695 int startMo = days[mSelStartT].month(); 696 int startMo = days[mSelStartT].month();
696 int endMo = days[mSelEndT].month(); 697 int endMo = days[mSelEndT].month();
697 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 698 if ( startMo == 12 && mo == 1 && endMo <= 2 )
698 startMo = 1; 699 startMo = 1;
699 if ( endMo == 1 && mo == 12 ) 700 if ( endMo == 1 && mo == 12 )
700 endMo = 12; 701 endMo = 12;
701 if ( (startMo > mo || endMo < mo) ) { 702 if ( (startMo > mo || endMo < mo) ) {
702 skip = true; 703 skip = true;
703 } else { 704 } else {
704 if ( days[mSelStartT].month() != mo ) { 705 if ( days[mSelStartT].month() != mo ) {
705 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 706 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
706 mSelStartT += add +1; 707 mSelStartT += add +1;
707 } 708 }
708 if ( days[mSelEndT].month() != mo ) { 709 if ( days[mSelEndT].month() != mo ) {
709 int sub = days[mSelEndT].day(); 710 int sub = days[mSelEndT].day();
710 mSelEndT -= sub ; 711 mSelEndT -= sub ;
711 } 712 }
712 } 713 }
713 } 714 }
714 if ( ! skip ) { 715 if ( ! skip ) {
715 row = mSelStartT/7; 716 row = mSelStartT/7;
716 col = mSelStartT -row*7; 717 col = mSelStartT -row*7;
717 QColor selcol = KOPrefs::instance()->mHighlightColor; 718 QColor selcol = KOPrefs::instance()->mHighlightColor;
718 int addCol = 0; 719 int addCol = 0;
719 int addRow = 0; 720 int addRow = 0;
720 int addRow2 = 0; 721 int addRow2 = 0;
721 int addCol2 = 0; 722 int addCol2 = 0;
722 if (row == mSelEndT/7) { 723 if (row == mSelEndT/7) {
723 if ( rowModulo ) { 724 if ( rowModulo ) {
724 if ( row >= 6 - rowModulo ) 725 if ( row >= 6 - rowModulo )
725 addRow = row - 5 + rowModulo; 726 addRow = row - 5 + rowModulo;
726 } 727 }
727 if ( colModulo ) { 728 if ( colModulo ) {
728 int colt1 = mSelEndT%7; 729 int colt1 = mSelEndT%7;
729 //qDebug("colt1 %d ", colt1 ); 730 //qDebug("colt1 %d ", colt1 );
730 if ( colt1 >= 7 - colModulo ) 731 if ( colt1 >= 7 - colModulo )
731 addCol = colt1 - 7 + colModulo+1; 732 addCol = colt1 - 7 + colModulo+1;
732 int colt = mSelStartT%7; 733 int colt = mSelStartT%7;
733 if ( colt >= 7 - colModulo ) 734 if ( colt >= 7 - colModulo )
734 addCol2 = colt - 7 + colModulo; 735 addCol2 = colt - 7 + colModulo;
735 addCol -= addCol2; 736 addCol -= addCol2;
736 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 737 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
737 } 738 }
738 // Single row selection 739 // Single row selection
739 if ( row == 0) 740 if ( row == 0)
740 addRow = 1; 741 addRow = 1;
741 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 742 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
742 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 743 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
743 } else { 744 } else {
744 // draw first row to the right 745 // draw first row to the right
745 if ( colModulo ) { 746 if ( colModulo ) {
746 if ( col >= 7 - colModulo ) 747 if ( col >= 7 - colModulo )
747 addCol2 = col - 7 + colModulo; 748 addCol2 = col - 7 + colModulo;
748 } 749 }
749 if ( rowModulo ) { 750 if ( rowModulo ) {
750 if ( row >= 6 - rowModulo ) 751 if ( row >= 6 - rowModulo )
751 addRow = row - 5 + rowModulo; 752 addRow = row - 5 + rowModulo;
752 } 753 }
753 if ( row == 0) 754 if ( row == 0)
754 addRow = 1; 755 addRow = 1;
755 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 756 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
756 dheight+1, selcol); 757 dheight+1, selcol);
757 // draw full block till last line 758 // draw full block till last line
758 selh = mSelEndT/7-row; 759 selh = mSelEndT/7-row;
759 addRow = 0; 760 addRow = 0;
760 if ( rowModulo ) { 761 if ( rowModulo ) {
761 if ( mSelEndT/7 >= 6 - rowModulo ) 762 if ( mSelEndT/7 >= 6 - rowModulo )
762 addRow = mSelEndT/7 - 5 + rowModulo; 763 addRow = mSelEndT/7 - 5 + rowModulo;
763 } 764 }
764 if (selh > 1) { 765 if (selh > 1) {
765 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 766 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
766 } 767 }
767 // draw last block from left to mSelEndT 768 // draw last block from left to mSelEndT
768 selw = mSelEndT-7*(mSelEndT/7)+1; 769 selw = mSelEndT-7*(mSelEndT/7)+1;
769 //qDebug("esl %d ",selw ); 770 //qDebug("esl %d ",selw );
770 int add = 0; 771 int add = 0;
771 if ( colModulo ) { 772 if ( colModulo ) {
772 add = 7 - colModulo; 773 add = 7 - colModulo;
773 if ( selw > add ) 774 if ( selw > add )
774 add = selw - add; 775 add = selw - add;
775 else 776 else
776 add = 0; 777 add = 0;
777 } 778 }
778 //qDebug("add %d ", add); 779 //qDebug("add %d ", add);
779 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 780 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
780 selw*dwidth+add, dheight+1, selcol); 781 selw*dwidth+add, dheight+1, selcol);
781 } 782 }
782 } 783 }
783 } 784 }
784 785
785 // iterate over all days in the matrix and draw the day label in appropriate colors 786 // iterate over all days in the matrix and draw the day label in appropriate colors
786 QColor actcol = mDefaultTextColorShaded; 787 QColor actcol = mDefaultTextColorShaded;
787 p.setPen(actcol); 788 p.setPen(actcol);
788 QPen tmppen; 789 QPen tmppen;
789 for(int i = 0; i < NUMDAYS; i++) { 790 for(int i = 0; i < NUMDAYS; i++) {
790 row = i/7; 791 row = i/7;
791 col = isRTL ? 6-(i-row*7) : i-row*7; 792 col = isRTL ? 6-(i-row*7) : i-row*7;
792 793
793 // if it is the first day of a month switch color from normal to shaded and vice versa 794 // if it is the first day of a month switch color from normal to shaded and vice versa
794 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 795 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
795 if (actcol == mDefaultTextColorShaded) { 796 if (actcol == mDefaultTextColorShaded) {
796 actcol = mDefaultTextColor; 797 actcol = mDefaultTextColor;
797 } else { 798 } else {
798 actcol = mDefaultTextColorShaded; 799 actcol = mDefaultTextColorShaded;
799 } 800 }
800 p.setPen(actcol); 801 p.setPen(actcol);
801 } 802 }
802 if (actcol == mDefaultTextColorShaded) { 803 if (actcol == mDefaultTextColorShaded) {
803 if ( ! mouseDown ) { 804 if ( ! mouseDown ) {
804 continue; 805 continue;
805 } 806 }
806 } 807 }
807 //Reset pen color after selected days block 808 //Reset pen color after selected days block
808 if (i == mSelEndT+1) { 809 if (i == mSelEndT+1) {
809 p.setPen(actcol); 810 p.setPen(actcol);
810 } 811 }
811 812
812 // if today then draw rectangle around day 813 // if today then draw rectangle around day
813 if (today == i) { 814 if (today == i) {
814 tmppen = p.pen(); 815 tmppen = p.pen();
815 QPen mTodayPen(p.pen()); 816 QPen mTodayPen(p.pen());
816 if ( daysize.width() < 20 ) 817 if ( daysize.width() < 20 )
817 mTodayPen.setWidth(1); 818 mTodayPen.setWidth(1);
818 else 819 else
819 mTodayPen.setWidth(mTodayMarginWidth); 820 mTodayPen.setWidth(mTodayMarginWidth);
820 //draw red rectangle for holidays 821 //draw red rectangle for holidays
821 if (!mHolidays[i].isNull()) { 822 if (!mHolidays[i].isNull()) {
822 if (actcol == mDefaultTextColor) { 823 if (actcol == mDefaultTextColor) {
823 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 824 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
824 } else { 825 } else {
825 mTodayPen.setColor(mHolidayColorShaded); 826 mTodayPen.setColor(mHolidayColorShaded);
826 } 827 }
827 } 828 }
828 //draw gray rectangle for today if in selection 829 //draw gray rectangle for today if in selection
829 if (i >= mSelStartT && i <= mSelEndT) { 830 if (i >= mSelStartT && i <= mSelEndT) {
830 QColor grey("grey"); 831 QColor grey("grey");
831 mTodayPen.setColor(grey); 832 mTodayPen.setColor(grey);
832 } 833 }
833 p.setPen(mTodayPen); 834 p.setPen(mTodayPen);
834 835
835 836
836 int addCol = 0; 837 int addCol = 0;
837 int addRow = 0; 838 int addRow = 0;
838 if (rowModulo) { 839 if (rowModulo) {
839 if ( row >= 6 - rowModulo ) 840 if ( row >= 6 - rowModulo )
840 addRow = row - 5 + rowModulo; 841 addRow = row - 5 + rowModulo;
841 } 842 }
842 if ( colModulo ) { 843 if ( colModulo ) {
843 if ( col >= 7 - colModulo ) 844 if ( col >= 7 - colModulo )
844 addCol = col - 6 + colModulo-1; 845 addCol = col - 6 + colModulo-1;
845 } 846 }
846 if ( col == 0 ) 847
847 addCol = 1; 848 addCol += 1;
848 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 849 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
849 p.setPen(tmppen); 850 p.setPen(tmppen);
850 } 851 }
851 852
852 // if any events are on that day then draw it using a bold font 853 // if any events are on that day then draw it using a bold font
853 if (events[i] > 0) { 854 if (events[i] > 0) {
854 QFont myFont = font(); 855 QFont myFont = font();
855 myFont.setBold(true); 856 myFont.setBold(true);
856 p.setFont(myFont); 857 p.setFont(myFont);
857 } 858 }
858 859
859 // if it is a holiday then use the default holiday color 860 // if it is a holiday then use the default holiday color
860 if (!mHolidays[i].isNull()) { 861 if (!mHolidays[i].isNull()) {
861 if ( bDays.testBit(i) ) { 862 if ( bDays.testBit(i) ) {
862 p.setPen(Qt::green); 863 p.setPen(Qt::green);
863 } else { 864 } else {
864 if (actcol == mDefaultTextColor) { 865 if (actcol == mDefaultTextColor) {
865 p.setPen(KOPrefs::instance()->mHolidayColor); 866 p.setPen(KOPrefs::instance()->mHolidayColor);
866 } else { 867 } else {
867 p.setPen(mHolidayColorShaded); 868 p.setPen(mHolidayColorShaded);
868 } 869 }
869 } 870 }
870 } 871 }
871 872
872 // draw selected days with special color 873 // draw selected days with special color
873 // DO NOT specially highlight holidays in selection ! 874 // DO NOT specially highlight holidays in selection !
874 if (i >= mSelStartT && i <= mSelEndT) { 875 if (i >= mSelStartT && i <= mSelEndT) {
875 ;//p.setPen(mSelectedDaysColor); 876 ;//p.setPen(mSelectedDaysColor);
876 } 877 }
877 878
878 int addCol = 0; 879 int addCol = 0;
879 int addRow = 0; 880 int addRow = 0;
880 if ( colModulo ) { 881 if ( colModulo ) {
881 if ( col >= 7 - colModulo ) 882 if ( col >= 7 - colModulo )
882 addCol = col - 7 + colModulo; 883 addCol = col - 7 + colModulo;
883 } 884 }
884 if ( rowModulo ) { 885 if ( rowModulo ) {
885 if ( row >= 6 - rowModulo ) 886 if ( row >= 6 - rowModulo )
886 addRow = row - 5 + rowModulo; 887 addRow = row - 5 + rowModulo;
887 } 888 }
888 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 889 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
889 ++addCol;//++addCol; 890 ++addCol;//++addCol;
890 if ( row == 0) 891 if ( row == 0)
891 addRow = 1; 892 addRow = 1;
892 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 893 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
893 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 894 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
894 895
895 // reset color to actual color 896 // reset color to actual color
896 if (!mHolidays[i].isNull()) { 897 if (!mHolidays[i].isNull()) {
897 p.setPen(actcol); 898 p.setPen(actcol);
898 } 899 }
899 // reset bold font to plain font 900 // reset bold font to plain font
900 if (events[i] > 0) { 901 if (events[i] > 0) {
901 QFont myFont = font(); 902 QFont myFont = font();
902 myFont.setBold(false); 903 myFont.setBold(false);
903 p.setFont(myFont); 904 p.setFont(myFont);
904 } 905 }
905 } 906 }
906 int off = xyOff; 907 int off = xyOff;
907 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 908 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
908 //qDebug("ffffffffff %d ", off); 909 //qDebug("ffffffffff %d ", off);
909} 910}
910 911
911// ---------------------------------------------------------------------------- 912// ----------------------------------------------------------------------------
912// R E SI Z E E V E N T H A N D L I N G 913// R E SI Z E E V E N T H A N D L I N G
913// ---------------------------------------------------------------------------- 914// ----------------------------------------------------------------------------
914 915
915void KODayMatrix::resizeEvent(QResizeEvent *) 916void KODayMatrix::resizeEvent(QResizeEvent *)
916{ 917{
917 QRect sz = frameRect(); 918 QRect sz = frameRect();
918 daysize.setHeight(sz.height()*7 / NUMDAYS); 919 daysize.setHeight(sz.height()*7 / NUMDAYS);
919 daysize.setWidth(sz.width() / 7); 920 daysize.setWidth(sz.width() / 7);
920} 921}
921 922
922QSize KODayMatrix::sizeHint() const 923QSize KODayMatrix::sizeHint() const
923{ 924{
924 925
925 QFontMetrics fm ( font() ); 926 QFontMetrics fm ( font() );
926 int wid = fm.width( "30") *7+3; 927 int wid = fm.width( "30") *7+3;
927 int hei = fm.height() * 6+3; 928 int hei = fm.height() * 6+3;
928 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 929 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
929 return QSize ( wid, hei ); 930 return QSize ( wid, hei );
930 931
931} 932}
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 76982b4..9fd1f68 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1,1697 +1,1697 @@
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 19
20#include <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qfont.h> 21#include <qfont.h>
22#include <qfontmetrics.h> 22#include <qfontmetrics.h>
23#include <qkeycode.h> 23#include <qkeycode.h>
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qwidgetstack.h> 26#include <qwidgetstack.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qtooltip.h> 28#include <qtooltip.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qwhatsthis.h> 31#include <qwhatsthis.h>
32#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#else 34#else
35#include <qapplication.h> 35#include <qapplication.h>
36#endif 36#endif
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kglobal.h> 40#include <kglobal.h>
41#include <kconfig.h> 41#include <kconfig.h>
42#include <kiconloader.h> 42#include <kiconloader.h>
43 43
44#include <kcalendarsystem.h> 44#include <kcalendarsystem.h>
45 45
46#ifndef KORG_NOPRINTER 46#ifndef KORG_NOPRINTER
47#include "calprinter.h" 47#include "calprinter.h"
48#endif 48#endif
49#include "koprefs.h" 49#include "koprefs.h"
50#ifndef KORG_NOPLUGINS 50#ifndef KORG_NOPLUGINS
51#include "kocore.h" 51#include "kocore.h"
52#endif 52#endif
53#include "koglobals.h" 53#include "koglobals.h"
54#include <libkcal/kincidenceformatter.h> 54#include <libkcal/kincidenceformatter.h>
55 55
56#include "komonthview.h" 56#include "komonthview.h"
57 57
58#define PIXMAP_SIZE 5 58#define PIXMAP_SIZE 5
59#ifdef DESKTOP_VERSION 59#ifdef DESKTOP_VERSION
60QToolTipGroup *MonthViewCell::mToolTipGroup = 0; 60QToolTipGroup *MonthViewCell::mToolTipGroup = 0;
61#endif 61#endif
62class KNOWhatsThis :public QWhatsThis 62class KNOWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; 65 KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { };
66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; 66 //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p) 69 virtual QString text( const QPoint& p)
70 { 70 {
71 return _wid->getWhatsThisText(p) ; 71 return _wid->getWhatsThisText(p) ;
72 }; 72 };
73private: 73private:
74 KNoScrollListBox* _wid; 74 KNoScrollListBox* _wid;
75 75
76}; 76};
77 77
78 78
79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 79KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name)
80 : QListBox(parent, name, WRepaintNoErase) 80 : QListBox(parent, name, WRepaintNoErase)
81{ 81{
82#ifndef DESKTOP_VERSION 82#ifndef DESKTOP_VERSION
83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 83 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
84#endif 84#endif
85 mWT = new KNOWhatsThis(this); 85 mWT = new KNOWhatsThis(this);
86} 86}
87KNoScrollListBox::~KNoScrollListBox() 87KNoScrollListBox::~KNoScrollListBox()
88{ 88{
89 89
90} 90}
91QString KNoScrollListBox::getWhatsThisText(QPoint p) 91QString KNoScrollListBox::getWhatsThisText(QPoint p)
92{ 92{
93 QListBoxItem* item = itemAt ( p ); 93 QListBoxItem* item = itemAt ( p );
94 if ( ! item ) { 94 if ( ! item ) {
95 return i18n("Click in the cell\nto add an event!"); 95 return i18n("Click in the cell\nto add an event!");
96 } 96 }
97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), 97 return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(),
98 KOPrefs::instance()->mWTshowDetails, 98 KOPrefs::instance()->mWTshowDetails,
99 KOPrefs::instance()->mWTshowCreated, 99 KOPrefs::instance()->mWTshowCreated,
100 KOPrefs::instance()->mWTshowChanged); 100 KOPrefs::instance()->mWTshowChanged);
101} 101}
102void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 102void KNoScrollListBox::keyPressEvent(QKeyEvent *e)
103{ 103{
104 104
105 switch(e->key()) { 105 switch(e->key()) {
106 case Key_Right: 106 case Key_Right:
107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 107 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
108 { 108 {
109 e->ignore(); 109 e->ignore();
110 return; 110 return;
111 } 111 }
112 scrollBy(10,0); 112 scrollBy(10,0);
113 break; 113 break;
114 case Key_Left: 114 case Key_Left:
115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 115 if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
116 { 116 {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 scrollBy(-10,0); 120 scrollBy(-10,0);
121 break; 121 break;
122 case Key_Up: 122 case Key_Up:
123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 123 if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
124 e->ignore(); 124 e->ignore();
125 break; 125 break;
126 } 126 }
127 setCurrentItem((currentItem()+count()-1)%count()); 127 setCurrentItem((currentItem()+count()-1)%count());
128 if(!itemVisible(currentItem())) { 128 if(!itemVisible(currentItem())) {
129 if((unsigned int) currentItem() == (count()-1)) { 129 if((unsigned int) currentItem() == (count()-1)) {
130 setTopItem(currentItem()-numItemsVisible()+1); 130 setTopItem(currentItem()-numItemsVisible()+1);
131 } else { 131 } else {
132 setTopItem(topItem()-1); 132 setTopItem(topItem()-1);
133 } 133 }
134 } 134 }
135 break; 135 break;
136 case Key_Down: 136 case Key_Down:
137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { 137 if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) {
138 e->ignore(); 138 e->ignore();
139 break; 139 break;
140 } 140 }
141 setCurrentItem((currentItem()+1)%count()); 141 setCurrentItem((currentItem()+1)%count());
142 if(!itemVisible(currentItem())) { 142 if(!itemVisible(currentItem())) {
143 if(currentItem() == 0) { 143 if(currentItem() == 0) {
144 setTopItem(0); 144 setTopItem(0);
145 } else { 145 } else {
146 setTopItem(topItem()+1); 146 setTopItem(topItem()+1);
147 } 147 }
148 } 148 }
149 break; 149 break;
150 case Key_I: 150 case Key_I:
151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); 151 QTimer::singleShot( 11, this, SLOT ( oneDown() ) );
152 e->ignore(); 152 e->ignore();
153 break; 153 break;
154 case Key_Shift: 154 case Key_Shift:
155 emit shiftDown(); 155 emit shiftDown();
156 break; 156 break;
157 default: 157 default:
158 e->ignore(); 158 e->ignore();
159 break; 159 break;
160 } 160 }
161} 161}
162 162
163void KNoScrollListBox::oneDown() 163void KNoScrollListBox::oneDown()
164{ 164{
165 setCurrentItem((currentItem()+1)%count()); 165 setCurrentItem((currentItem()+1)%count());
166 if(!itemVisible(currentItem())) { 166 if(!itemVisible(currentItem())) {
167 if(currentItem() == 0) { 167 if(currentItem() == 0) {
168 setTopItem(0); 168 setTopItem(0);
169 } else { 169 } else {
170 setTopItem(topItem()+1); 170 setTopItem(topItem()+1);
171 } 171 }
172 } 172 }
173} 173}
174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 174void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e)
175{ 175{
176 switch(e->key()) { 176 switch(e->key()) {
177 case Key_Shift: 177 case Key_Shift:
178 emit shiftUp(); 178 emit shiftUp();
179 break; 179 break;
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183} 183}
184 184
185void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 185void KNoScrollListBox::mousePressEvent(QMouseEvent *e)
186{ 186{
187 QListBox::mousePressEvent(e); 187 QListBox::mousePressEvent(e);
188 188
189 if(e->button() == RightButton) { 189 if(e->button() == RightButton) {
190 emit rightClick(); 190 emit rightClick();
191 } 191 }
192} 192}
193 193
194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 194MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s)
195 : QListBoxItem() 195 : QListBoxItem()
196{ 196{
197 setText( s ); 197 setText( s );
198 mMultiday = 0; 198 mMultiday = 0;
199 mIncidence = incidence; 199 mIncidence = incidence;
200 mDate = qd; 200 mDate = qd;
201 mRecur = false; 201 mRecur = false;
202 mAlarm = false; 202 mAlarm = false;
203 mReply = false; 203 mReply = false;
204 mInfo = false; 204 mInfo = false;
205} 205}
206 206
207void MonthViewItem::paint(QPainter *p) 207void MonthViewItem::paint(QPainter *p)
208{ 208{
209#if QT_VERSION >= 0x030000 209#if QT_VERSION >= 0x030000
210 bool sel = isSelected(); 210 bool sel = isSelected();
211#else 211#else
212 bool sel = selected(); 212 bool sel = selected();
213#endif 213#endif
214 214
215 215
216 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) 216 if (KOPrefs::instance()->mMonthViewUsesCategoryColor)
217 { 217 {
218 p->setBackgroundColor( palette().color( QPalette::Normal, \ 218 p->setBackgroundColor( palette().color( QPalette::Normal, \
219 sel ? QColorGroup::Highlight : QColorGroup::Background ) ); 219 sel ? QColorGroup::Highlight : QColorGroup::Background ) );
220 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 220 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
221 } 221 }
222 int x = 1; 222 int x = 1;
223 //int y = 3;//(height() - mRecurPixmap.height()) /2; 223 //int y = 3;//(height() - mRecurPixmap.height()) /2;
224 int size = PIXMAP_SIZE; 224 int size = PIXMAP_SIZE;
225 if ( QApplication::desktop()->width() < 300 ) 225 if ( QApplication::desktop()->width() < 300 )
226 size = 3; 226 size = 3;
227 int heihei = height( listBox () ); 227 int heihei = height( listBox () );
228 int y = (heihei - size -1 ) /2; 228 int y = (heihei - size -1 ) /2;
229 229
230 if ( KOPrefs::instance()->mMonthShowIcons ) { 230 if ( KOPrefs::instance()->mMonthShowIcons ) {
231 if ( mInfo ) { 231 if ( mInfo ) {
232 p->fillRect ( x, y,size,size, Qt::darkGreen ); 232 p->fillRect ( x, y,size,size, Qt::darkGreen );
233 x += size + 1; 233 x += size + 1;
234 } 234 }
235 if ( mRecur ) { 235 if ( mRecur ) {
236 p->fillRect ( x, y,size,size, Qt::blue ); 236 p->fillRect ( x, y,size,size, Qt::blue );
237 x += size + 1; 237 x += size + 1;
238 } 238 }
239 if ( mAlarm ) { 239 if ( mAlarm ) {
240 p->fillRect ( x, y,size,size, Qt::red ); 240 p->fillRect ( x, y,size,size, Qt::red );
241 x += size + 1; 241 x += size + 1;
242 } 242 }
243 if ( mReply ) { 243 if ( mReply ) {
244 p->fillRect ( x, y,size,size, Qt::yellow ); 244 p->fillRect ( x, y,size,size, Qt::yellow );
245 x += size + 1; 245 x += size + 1;
246 } 246 }
247 } 247 }
248 if ( mMultiday ) { 248 if ( mMultiday ) {
249 int yyy = y+(size/2); 249 int yyy = y+(size/2);
250 int sizeM = size+2; 250 int sizeM = size+2;
251 p->setBrush( QBrush::SolidPattern ); 251 p->setBrush( QBrush::SolidPattern );
252 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; 252 p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ;
253 if ( mMultiday == 2 || mMultiday == 3 ) { 253 if ( mMultiday == 2 || mMultiday == 3 ) {
254 QPointArray pa ( 3 ); 254 QPointArray pa ( 3 );
255 pa.setPoint (0, x, yyy ); 255 pa.setPoint (0, x, yyy );
256 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); 256 pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 );
257 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); 257 pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 );
258 p->drawPolygon( pa ); 258 p->drawPolygon( pa );
259 } 259 }
260 if ( mMultiday == 2 || mMultiday == 1 ) { 260 if ( mMultiday == 2 || mMultiday == 1 ) {
261 QPointArray pa ( 3 ); 261 QPointArray pa ( 3 );
262 pa.setPoint (0, x+sizeM +sizeM/2, yyy ); 262 pa.setPoint (0, x+sizeM +sizeM/2, yyy );
263 pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); 263 pa.setPoint (1, x+sizeM, yyy+sizeM/2 );
264 pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); 264 pa.setPoint (2, x+sizeM, yyy-sizeM/2 );
265 p->drawPolygon( pa ); 265 p->drawPolygon( pa );
266 } 266 }
267 if ( mMultiday == 1 ) { 267 if ( mMultiday == 1 ) {
268 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 268 // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
269 269
270 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); 270 p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 );
271 } 271 }
272 if ( mMultiday == 3 ) { 272 if ( mMultiday == 3 ) {
273 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); 273 // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) );
274 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); 274 p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 );
275 275
276 } 276 }
277 x += sizeM/2 + 1; 277 x += sizeM/2 + 1;
278 x += sizeM + 1; 278 x += sizeM + 1;
279 } 279 }
280 280
281 if ( mIncidence->type() == "Todo" ){ 281 if ( mIncidence->type() == "Todo" ){
282 Todo* td = ( Todo* ) mIncidence; 282 Todo* td = ( Todo* ) mIncidence;
283 if ( td->isCompleted() ) { 283 if ( td->isCompleted() ) {
284 int half = size/2; 284 int half = size/2;
285 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; 285 p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
286 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; 286 p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
287 x += half+half + 4; 287 x += half+half + 4;
288 288
289 } else { 289 } else {
290 int val = td->percentComplete()/20; 290 int val = td->percentComplete()/20;
291 p->fillRect ( x+1, y-1, val ,size+2,Qt::black ); 291 p->fillRect ( x+1, y-1, val ,size+2,Qt::black );
292 p->drawRect ( x, y-1,7,size+2); 292 p->drawRect ( x, y-1,7,size+2);
293 x += size + 3; 293 x += size + 3;
294 } 294 }
295 } 295 }
296 QFontMetrics fm = p->fontMetrics(); 296 QFontMetrics fm = p->fontMetrics();
297 int yPos; 297 int yPos;
298 int pmheight = size; 298 int pmheight = size;
299 if( pmheight < fm.height() ) 299 if( pmheight < fm.height() )
300 yPos = fm.ascent() + fm.leading()/2; 300 yPos = fm.ascent() + fm.leading()/2;
301 else 301 else
302 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 302 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
303 p->setPen( palette().color( QPalette::Normal, sel ? \ 303 p->setPen( palette().color( QPalette::Normal, sel ? \
304 QColorGroup::HighlightedText : QColorGroup::Foreground ) ); 304 QColorGroup::HighlightedText : QColorGroup::Foreground ) );
305 p->drawText( x, yPos, text() ); 305 p->drawText( x, yPos, text() );
306 if ( mIncidence->cancelled() ) { 306 if ( mIncidence->cancelled() ) {
307 int wid = fm.width( text() ); 307 int wid = fm.width( text() );
308 p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); 308 p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 );
309 } 309 }
310 310
311} 311}
312 312
313int MonthViewItem::height(const QListBox *lb) const 313int MonthViewItem::height(const QListBox *lb) const
314{ 314{
315 if ( lb ) 315 if ( lb )
316 return lb->fontMetrics().lineSpacing()+1; 316 return lb->fontMetrics().lineSpacing()+1;
317 return 10; 317 return 10;
318} 318}
319 319
320int MonthViewItem::width(const QListBox *lb) const 320int MonthViewItem::width(const QListBox *lb) const
321{ 321{
322 int size = PIXMAP_SIZE; 322 int size = PIXMAP_SIZE;
323 if ( QApplication::desktop()->width() < 300 ) 323 if ( QApplication::desktop()->width() < 300 )
324 size = 3; 324 size = 3;
325 int x = 1; 325 int x = 1;
326 if ( KOPrefs::instance()->mMonthShowIcons ) { 326 if ( KOPrefs::instance()->mMonthShowIcons ) {
327 if ( mInfo ) { 327 if ( mInfo ) {
328 x += size + 1; 328 x += size + 1;
329 } 329 }
330 if( mRecur ) { 330 if( mRecur ) {
331 x += size+1; 331 x += size+1;
332 } 332 }
333 if( mAlarm ) { 333 if( mAlarm ) {
334 x += size+1; 334 x += size+1;
335 } 335 }
336 if( mReply ) { 336 if( mReply ) {
337 x += size+1; 337 x += size+1;
338 } 338 }
339 } 339 }
340 if( mMultiday ) { 340 if( mMultiday ) {
341 x += size+1+2+size/2; 341 x += size+1+2+size/2;
342 } 342 }
343 343
344 return( x + lb->fontMetrics().width( text() ) + 1 ); 344 return( x + lb->fontMetrics().width( text() ) + 1 );
345} 345}
346 346
347 347
348MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) 348MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
349 : QWidget( par ), 349 : QWidget( par ),
350 mMonthView( parent ) 350 mMonthView( parent )
351{ 351{
352 352
353 QVBoxLayout *topLayout = new QVBoxLayout( this ); 353 QVBoxLayout *topLayout = new QVBoxLayout( this );
354 354
355 // mLabel = new QLabel( this );QPushButton 355 // mLabel = new QLabel( this );QPushButton
356 mLabel = new QPushButton( this ); 356 mLabel = new QPushButton( this );
357 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 357 //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
358 //mLabel->setLineWidth( 1 ); 358 //mLabel->setLineWidth( 1 );
359 //mLabel->setAlignment( AlignCenter ); 359 //mLabel->setAlignment( AlignCenter );
360 mLabel->setFlat( true ); 360 mLabel->setFlat( true );
361 mLabel->setFocusPolicy(NoFocus); 361 mLabel->setFocusPolicy(NoFocus);
362 mItemList = new KNoScrollListBox( this ); 362 mItemList = new KNoScrollListBox( this );
363 mItemList->setMinimumSize( 10, 10 ); 363 mItemList->setMinimumSize( 10, 10 );
364 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); 364 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain );
365 mItemList->setLineWidth( 1 ); 365 mItemList->setLineWidth( 1 );
366 topLayout->addWidget( mItemList ); 366 topLayout->addWidget( mItemList );
367 mLabel->raise(); 367 mLabel->raise();
368 // QColor( 0,0,255 ) QColor( 160,1600,255 ) 368 // QColor( 0,0,255 ) QColor( 160,1600,255 )
369 mStandardPalette = palette(); 369 mStandardPalette = palette();
370 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); 370 mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
371 371
372 enableScrollBars( false ); 372 enableScrollBars( false );
373 updateConfig(); 373 updateConfig();
374 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); 374 //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
375 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); 375 connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
376 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), 376 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ),
377 SLOT( defaultAction( QListBoxItem * ) ) ); 377 SLOT( defaultAction( QListBoxItem * ) ) );
378 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, 378 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *,
379 const QPoint &) ), 379 const QPoint &) ),
380 SLOT( contextMenu( QListBoxItem * ) ) ); 380 SLOT( contextMenu( QListBoxItem * ) ) );
381 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), 381 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ),
382 SLOT( selection( QListBoxItem * ) ) ); 382 SLOT( selection( QListBoxItem * ) ) );
383 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 383 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
384 SLOT( cellClicked( QListBoxItem * ) ) ); 384 SLOT( cellClicked( QListBoxItem * ) ) );
385 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 385 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ),
386 SLOT( selection( QListBoxItem * ) ) ); 386 SLOT( selection( QListBoxItem * ) ) );
387} 387}
388#ifdef DESKTOP_VERSION 388#ifdef DESKTOP_VERSION
389QToolTipGroup *MonthViewCell::toolTipGroup() 389QToolTipGroup *MonthViewCell::toolTipGroup()
390{ 390{
391 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 391 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
392 return mToolTipGroup; 392 return mToolTipGroup;
393} 393}
394#endif 394#endif
395 395
396void MonthViewCell::setDate( const QDate &date ) 396void MonthViewCell::setDate( const QDate &date )
397{ 397{
398 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; 398 // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
399 mDate = date; 399 mDate = date;
400 400
401 401
402 402
403 //resizeEvent( 0 ); 403 //resizeEvent( 0 );
404} 404}
405 405
406QDate MonthViewCell::date() const 406QDate MonthViewCell::date() const
407{ 407{
408 return mDate; 408 return mDate;
409} 409}
410 410
411void MonthViewCell::setPrimary( bool primary ) 411void MonthViewCell::setPrimary( bool primary )
412{ 412{
413 mPrimary = primary; 413 mPrimary = primary;
414 //setMyPalette(); 414 //setMyPalette();
415} 415}
416void MonthViewCell::setMyPalette() 416void MonthViewCell::setMyPalette()
417{ 417{
418 418
419 if ( mHoliday) { 419 if ( mHoliday) {
420 setPalette( mHolidayPalette ); 420 setPalette( mHolidayPalette );
421 } else { 421 } else {
422 if ( mPrimary ) { 422 if ( mPrimary ) {
423 setPalette( mPrimaryPalette ); 423 setPalette( mPrimaryPalette );
424 } else { 424 } else {
425 setPalette( mNonPrimaryPalette ); 425 setPalette( mNonPrimaryPalette );
426 } 426 }
427 } 427 }
428 QPalette pal = palette(); 428 QPalette pal = palette();
429 429
430 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); 430 mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
431} 431}
432QPalette MonthViewCell::getPalette () 432QPalette MonthViewCell::getPalette ()
433{ 433{
434 if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) 434 if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
435 return mStandardPalette; 435 return mStandardPalette;
436 if ( mHoliday) { 436 if ( mHoliday) {
437 return mHolidayPalette ; 437 return mHolidayPalette ;
438 } else { 438 } else {
439 if ( mPrimary ) { 439 if ( mPrimary ) {
440 return mPrimaryPalette ; 440 return mPrimaryPalette ;
441 } 441 }
442 } 442 }
443 return mNonPrimaryPalette; 443 return mNonPrimaryPalette;
444} 444}
445bool MonthViewCell::isPrimary() const 445bool MonthViewCell::isPrimary() const
446{ 446{
447 return mPrimary; 447 return mPrimary;
448} 448}
449 449
450void MonthViewCell::setHoliday( bool holiday ) 450void MonthViewCell::setHoliday( bool holiday )
451{ 451{
452 mHoliday = holiday; 452 mHoliday = holiday;
453 //setMyPalette(); 453 //setMyPalette();
454} 454}
455 455
456void MonthViewCell::setHoliday( const QString &holiday ) 456void MonthViewCell::setHoliday( const QString &holiday )
457{ 457{
458 mHolidayString = holiday; 458 mHolidayString = holiday;
459 459
460 if ( !holiday.isEmpty() ) { 460 if ( !holiday.isEmpty() ) {
461 setHoliday( true ); 461 setHoliday( true );
462 } 462 }
463} 463}
464void MonthViewCell::keyPressEvent ( QKeyEvent * e ) 464void MonthViewCell::keyPressEvent ( QKeyEvent * e )
465{ 465{
466 466
467 e->ignore(); 467 e->ignore();
468 468
469} 469}
470 470
471void MonthViewCell::startUpdateCell() 471void MonthViewCell::startUpdateCell()
472{ 472{
473 473
474 mItemList->setFocusPolicy(NoFocus); 474 mItemList->setFocusPolicy(NoFocus);
475 if ( !mMonthView->isUpdatePossible() ) 475 if ( !mMonthView->isUpdatePossible() )
476 return; 476 return;
477 477
478 /* 478 /*
479 if ( !isVisible() ){ 479 if ( !isVisible() ){
480 return; 480 return;
481 } 481 }
482 */ 482 */
483 // qDebug("MonthViewCell::updateCell() "); 483 // qDebug("MonthViewCell::updateCell() ");
484 setPrimary( mDate.month()%2 ); 484 setPrimary( mDate.month()%2 );
485 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); 485 setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
486 if ( mDate == QDate::currentDate() ) { 486 if ( mDate == QDate::currentDate() ) {
487 mItemList->setLineWidth( 3 ); 487 mItemList->setLineWidth( 3 );
488 } else { 488 } else {
489 mItemList->setLineWidth( 1 ); 489 mItemList->setLineWidth( 1 );
490 } 490 }
491 mItemList->clear(); 491 mItemList->clear();
492 492
493#ifdef DESKTOP_VERSION 493#ifdef DESKTOP_VERSION
494 QToolTip::remove(this); 494 QToolTip::remove(this);
495#endif 495#endif
496 mToolTip.clear(); 496 mToolTip.clear();
497 //qApp->processEvents(); 497 //qApp->processEvents();
498 if ( !mHolidayString.isEmpty() ) { 498 if ( !mHolidayString.isEmpty() ) {
499 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 499 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
500 item->setPalette( mHolidayPalette ); 500 item->setPalette( mHolidayPalette );
501 mItemList->insertItem( item ); 501 mItemList->insertItem( item );
502 mToolTip.append ( mHolidayString ); 502 mToolTip.append ( mHolidayString );
503 } 503 }
504} 504}
505 505
506void MonthViewCell::insertEvent(Event *event) 506void MonthViewCell::insertEvent(Event *event)
507{ 507{
508 QString mToolTipText; 508 QString mToolTipText;
509 mItemList->setFocusPolicy(WheelFocus); 509 mItemList->setFocusPolicy(WheelFocus);
510 if ( !(event->doesRecur() == Recurrence::rNone) ) { 510 if ( !(event->doesRecur() == Recurrence::rNone) ) {
511 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) 511 if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
512 return; 512 return;
513 else 513 else
514 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) 514 if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
515 return; 515 return;
516 } 516 }
517 517
518 if ( event->isHoliday()) { 518 if ( event->isHoliday()) {
519 setHoliday( true ); 519 setHoliday( true );
520 if ( mDate.dayOfWeek() == 7 ) 520 if ( mDate.dayOfWeek() == 7 )
521 mItemList->setLineWidth( 3 ); 521 mItemList->setLineWidth( 3 );
522 } 522 }
523 QString text; 523 QString text;
524 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 524 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
525 if (event->isMultiDay()) { 525 if (event->isMultiDay()) {
526 QString prefix = "<->";multiday = 2; 526 QString prefix = "<->";multiday = 2;
527 QString time; 527 QString time;
528 if ( event->doesRecur() ) { 528 if ( event->doesRecur() ) {
529 if ( event->recursOn( mDate) ) { 529 if ( event->recursOn( mDate) ) {
530 prefix ="->" ;multiday = 1; 530 prefix ="->" ;multiday = 1;
531 } 531 }
532 else { 532 else {
533 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 533 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
534 if ( event->recursOn( mDate.addDays( -days)) ) { 534 if ( event->recursOn( mDate.addDays( -days)) ) {
535 prefix ="<-" ;multiday = 3; 535 prefix ="<-" ;multiday = 3;
536 } 536 }
537 } 537 }
538 538
539 } else { 539 } else {
540 if (mDate == event->dtStart().date()) { 540 if (mDate == event->dtStart().date()) {
541 prefix ="->" ;multiday = 1; 541 prefix ="->" ;multiday = 1;
542 } else if (mDate == event->dtEnd().date()) { 542 } else if (mDate == event->dtEnd().date()) {
543 prefix ="<-" ;multiday = 3; 543 prefix ="<-" ;multiday = 3;
544 } 544 }
545 } 545 }
546 if ( !event->doesFloat() ) { 546 if ( !event->doesFloat() ) {
547 if ( mDate == event->dtStart().date () ) 547 if ( mDate == event->dtStart().date () )
548 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 548 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
549 else if ( mDate == event->dtEnd().date () ) 549 else if ( mDate == event->dtEnd().date () )
550 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 550 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
551 551
552 } 552 }
553 text = time + event->summary(); 553 text = time + event->summary();
554 mToolTipText += prefix + text; 554 mToolTipText += prefix + text;
555 } else { 555 } else {
556 if (event->doesFloat()) { 556 if (event->doesFloat()) {
557 text = event->summary(); 557 text = event->summary();
558 mToolTipText += text; 558 mToolTipText += text;
559 } 559 }
560 else { 560 else {
561 text = KGlobal::locale()->formatTime(event->dtStart().time()); 561 text = KGlobal::locale()->formatTime(event->dtStart().time());
562 text += " " + event->summary(); 562 text += " " + event->summary();
563 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 563 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
564 } 564 }
565 } 565 }
566 566
567 MonthViewItem *item = new MonthViewItem( event, mDate, text ); 567 MonthViewItem *item = new MonthViewItem( event, mDate, text );
568 QPalette pal; 568 QPalette pal;
569 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 569 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
570 QStringList categories = event->categories(); 570 QStringList categories = event->categories();
571 QString cat = categories.first(); 571 QString cat = categories.first();
572 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 572 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
573 pal = getPalette(); 573 pal = getPalette();
574 if (cat.isEmpty()) { 574 if (cat.isEmpty()) {
575 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 575 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
576 } else { 576 } else {
577 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 577 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
578 } 578 }
579 579
580 } else { 580 } else {
581 if (cat.isEmpty()) { 581 if (cat.isEmpty()) {
582 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 582 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
583 } else { 583 } else {
584 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 584 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
585 } 585 }
586 } 586 }
587 587
588 } else { 588 } else {
589 pal = mStandardPalette ; 589 pal = mStandardPalette ;
590 } 590 }
591 item->setPalette( pal ); 591 item->setPalette( pal );
592 item->setRecur( event->recurrence()->doesRecur() ); 592 item->setRecur( event->recurrence()->doesRecur() );
593 item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); 593 item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
594 item->setMoreInfo( event->description().length() > 0 ); 594 item->setMoreInfo( event->description().length() > 0 );
595#ifdef DESKTOP_VERSION 595#ifdef DESKTOP_VERSION
596 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, 596 Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
597 KOPrefs::instance()->email()); 597 KOPrefs::instance()->email());
598 if ( me != 0 ) { 598 if ( me != 0 ) {
599 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 599 if ( me->status() == Attendee::NeedsAction && me->RSVP())
600 item->setReply(true && multiday < 2); 600 item->setReply(true && multiday < 2);
601 else 601 else
602 item->setReply(false); 602 item->setReply(false);
603 } else 603 } else
604 item->setReply(false); 604 item->setReply(false);
605#endif 605#endif
606 item->setMultiDay( multiday ); 606 item->setMultiDay( multiday );
607 mItemList->insertItem( item ); 607 mItemList->insertItem( item );
608 mToolTip.append( mToolTipText ); 608 mToolTip.append( mToolTipText );
609} 609}
610void MonthViewCell::insertTodo(Todo *todo) 610void MonthViewCell::insertTodo(Todo *todo)
611{ 611{
612 mItemList->setFocusPolicy(WheelFocus); 612 mItemList->setFocusPolicy(WheelFocus);
613 QString text; 613 QString text;
614 if (todo->hasDueDate()) { 614 if (todo->hasDueDate()) {
615 if (!todo->doesFloat()) { 615 if (!todo->doesFloat()) {
616 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 616 text += KGlobal::locale()->formatTime(todo->dtDue().time());
617 text += " "; 617 text += " ";
618 } 618 }
619 } 619 }
620 text += todo->summary(); 620 text += todo->summary();
621 621
622 MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 622 MonthViewItem *item = new MonthViewItem( todo, mDate, text );
623 //item->setPalette( mStandardPalette ); 623 //item->setPalette( mStandardPalette );
624 QPalette pal; 624 QPalette pal;
625 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { 625 if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
626 QStringList categories = todo->categories(); 626 QStringList categories = todo->categories();
627 QString cat = categories.first(); 627 QString cat = categories.first();
628 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { 628 if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
629 pal = getPalette(); 629 pal = getPalette();
630 if (cat.isEmpty()) { 630 if (cat.isEmpty()) {
631 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); 631 pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
632 } else { 632 } else {
633 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); 633 pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
634 } 634 }
635 635
636 } else { 636 } else {
637 if (cat.isEmpty()) { 637 if (cat.isEmpty()) {
638 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); 638 pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
639 } else { 639 } else {
640 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); 640 pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
641 } 641 }
642 } 642 }
643 643
644 } else { 644 } else {
645 pal = mStandardPalette ; 645 pal = mStandardPalette ;
646 } 646 }
647 item->setPalette( pal ); 647 item->setPalette( pal );
648 item->setRecur( todo->recurrence()->doesRecur() ); 648 item->setRecur( todo->recurrence()->doesRecur() );
649 item->setAlarm( todo->isAlarmEnabled() ); 649 item->setAlarm( todo->isAlarmEnabled() );
650 item->setMoreInfo( todo->description().length() > 0 ); 650 item->setMoreInfo( todo->description().length() > 0 );
651 mItemList->insertItem( item ); 651 mItemList->insertItem( item );
652 mToolTip.append( text ); 652 mToolTip.append( text );
653} 653}
654void MonthViewCell::finishUpdateCell() 654void MonthViewCell::finishUpdateCell()
655{ 655{
656#ifdef DESKTOP_VERSION 656#ifdef DESKTOP_VERSION
657 if (mToolTip.count() > 0 ) { 657 if (mToolTip.count() > 0 ) {
658 mToolTip.sort(); 658 mToolTip.sort();
659 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); 659 QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
660 } 660 }
661#endif 661#endif
662 mItemList->sort(); 662 mItemList->sort();
663 //setMyPalette(); 663 //setMyPalette();
664 setMyPalette(); 664 setMyPalette();
665 QString text; 665 QString text;
666 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 666 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
667 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 667 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
668 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 668 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
669 mLabel->resize( mLabelBigSize ); 669 mLabel->resize( mLabelBigSize );
670 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 670 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
671 } else { 671 } else {
672 mLabel->resize( mLabelSize ); 672 mLabel->resize( mLabelSize );
673 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 673 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
674 } 674 }
675 675
676 mLabel->setText( text ); 676 mLabel->setText( text );
677 resizeEvent( 0 ); 677 resizeEvent( 0 );
678} 678}
679void MonthViewCell::updateCell() 679void MonthViewCell::updateCell()
680{ 680{
681 //qDebug("MonthViewCell::updateCell() "); 681 //qDebug("MonthViewCell::updateCell() ");
682 if ( !mMonthView->isUpdatePossible() ) 682 if ( !mMonthView->isUpdatePossible() )
683 return; 683 return;
684 startUpdateCell(); 684 startUpdateCell();
685 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 685 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
686 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); 686 QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
687 Event *event; 687 Event *event;
688 for( event = events.first(); event; event = events.next() ) { // for event 688 for( event = events.first(); event; event = events.next() ) { // for event
689 insertEvent(event); 689 insertEvent(event);
690 } 690 }
691 // insert due todos 691 // insert due todos
692 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); 692 QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
693 Todo *todo; 693 Todo *todo;
694 for(todo = todos.first(); todo; todo = todos.next()) { 694 for(todo = todos.first(); todo; todo = todos.next()) {
695 insertTodo( todo ); 695 insertTodo( todo );
696 } 696 }
697 finishUpdateCell(); 697 finishUpdateCell();
698 // if ( isVisible()) 698 // if ( isVisible())
699 //qApp->processEvents(); 699 //qApp->processEvents();
700} 700}
701 701
702void MonthViewCell::updateConfig( bool bigFont ) // = false 702void MonthViewCell::updateConfig( bool bigFont ) // = false
703{ 703{
704 704
705 if ( bigFont ) { 705 if ( bigFont ) {
706 QFont fo = KOPrefs::instance()->mMonthViewFont; 706 QFont fo = KOPrefs::instance()->mMonthViewFont;
707 int ps = fo.pointSize() + 2; 707 int ps = fo.pointSize() + 2;
708 if ( ps < 18 ) 708 if ( ps < 18 )
709 ps += 2; 709 ps += 2;
710 fo.setPointSize( ps ); 710 fo.setPointSize( ps );
711 setFont( fo ); 711 setFont( fo );
712 } else 712 } else
713 setFont( KOPrefs::instance()->mMonthViewFont ); 713 setFont( KOPrefs::instance()->mMonthViewFont );
714 714
715 QFontMetrics fm( font() ); 715 QFontMetrics fm( font() );
716 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); 716 mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
717 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); 717 mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
718 mHolidayPalette = mStandardPalette; 718 mHolidayPalette = mStandardPalette;
719 mPrimaryPalette = mStandardPalette; 719 mPrimaryPalette = mStandardPalette;
720 mNonPrimaryPalette = mStandardPalette; 720 mNonPrimaryPalette = mStandardPalette;
721 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { 721 if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
722 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); 722 mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
723 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); 723 mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
724 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); 724 mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
725 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); 725 mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
726 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); 726 mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
727 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); 727 mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
728 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); 728 mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
729 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); 729 mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
730 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); 730 mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
731 } 731 }
732 //updateCell(); 732 //updateCell();
733} 733}
734 734
735void MonthViewCell::enableScrollBars( bool enabled ) 735void MonthViewCell::enableScrollBars( bool enabled )
736{ 736{
737 if ( enabled ) { 737 if ( enabled ) {
738 mItemList->setVScrollBarMode(QScrollView::Auto); 738 mItemList->setVScrollBarMode(QScrollView::Auto);
739 mItemList->setHScrollBarMode(QScrollView::Auto); 739 mItemList->setHScrollBarMode(QScrollView::Auto);
740 } else { 740 } else {
741 mItemList->setVScrollBarMode(QScrollView::AlwaysOff); 741 mItemList->setVScrollBarMode(QScrollView::AlwaysOff);
742 mItemList->setHScrollBarMode(QScrollView::AlwaysOff); 742 mItemList->setHScrollBarMode(QScrollView::AlwaysOff);
743 } 743 }
744} 744}
745 745
746Incidence *MonthViewCell::selectedIncidence() 746Incidence *MonthViewCell::selectedIncidence()
747{ 747{
748 int index = mItemList->currentItem(); 748 int index = mItemList->currentItem();
749 if ( index < 0 ) return 0; 749 if ( index < 0 ) return 0;
750 750
751 MonthViewItem *item = 751 MonthViewItem *item =
752 static_cast<MonthViewItem *>( mItemList->item( index ) ); 752 static_cast<MonthViewItem *>( mItemList->item( index ) );
753 753
754 if ( !item ) return 0; 754 if ( !item ) return 0;
755 755
756 return item->incidence(); 756 return item->incidence();
757} 757}
758 758
759QDate MonthViewCell::selectedIncidenceDate() 759QDate MonthViewCell::selectedIncidenceDate()
760{ 760{
761 QDate qd; 761 QDate qd;
762 int index = mItemList->currentItem(); 762 int index = mItemList->currentItem();
763 if ( index < 0 ) return qd; 763 if ( index < 0 ) return qd;
764 764
765 MonthViewItem *item = 765 MonthViewItem *item =
766 static_cast<MonthViewItem *>( mItemList->item( index ) ); 766 static_cast<MonthViewItem *>( mItemList->item( index ) );
767 767
768 if ( !item ) return qd; 768 if ( !item ) return qd;
769 769
770 return item->incidenceDate(); 770 return item->incidenceDate();
771} 771}
772 772
773void MonthViewCell::deselect() 773void MonthViewCell::deselect()
774{ 774{
775 mItemList->clearSelection(); 775 mItemList->clearSelection();
776 enableScrollBars( false ); 776 enableScrollBars( false );
777 // updateCell(); 777 // updateCell();
778} 778}
779void MonthViewCell::select() 779void MonthViewCell::select()
780{ 780{
781 ;// updateCell(); 781 ;// updateCell();
782} 782}
783 783
784void MonthViewCell::resizeEvent ( QResizeEvent * ) 784void MonthViewCell::resizeEvent ( QResizeEvent * )
785{ 785{
786 if ( !mMonthView->isUpdatePossible() ) 786 if ( !mMonthView->isUpdatePossible() )
787 return; 787 return;
788 788
789 int size = height() - mLabel->height() - 2; 789 int size = height() - mLabel->height() - 2;
790 if ( size > 0 ) 790 if ( size > 0 )
791 mItemList->verticalScrollBar()->setMaximumHeight( size ); 791 mItemList->verticalScrollBar()->setMaximumHeight( size );
792 size = width() - mLabel->width() -2; 792 size = width() - mLabel->width() -2;
793 if ( size > 0 ) 793 if ( size > 0 )
794 mItemList->horizontalScrollBar()->setMaximumWidth( size ); 794 mItemList->horizontalScrollBar()->setMaximumWidth( size );
795 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); 795 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() );
796 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 796 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
797} 797}
798 798
799void MonthViewCell::defaultAction( QListBoxItem *item ) 799void MonthViewCell::defaultAction( QListBoxItem *item )
800{ 800{
801 if ( !item ) return; 801 if ( !item ) return;
802 802
803 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 803 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
804 Incidence *incidence = eventItem->incidence(); 804 Incidence *incidence = eventItem->incidence();
805 if ( incidence ) mMonthView->defaultAction( incidence ); 805 if ( incidence ) mMonthView->defaultAction( incidence );
806} 806}
807void MonthViewCell::showDay() 807void MonthViewCell::showDay()
808{ 808{
809 emit showDaySignal( date() ); 809 emit showDaySignal( date() );
810} 810}
811void MonthViewCell::newEvent() 811void MonthViewCell::newEvent()
812{ 812{
813 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 813 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
814 emit newEventSignal( dt ); 814 emit newEventSignal( dt );
815} 815}
816void MonthViewCell::cellClicked( QListBoxItem *item ) 816void MonthViewCell::cellClicked( QListBoxItem *item )
817{ 817{
818 static QListBoxItem * lastClicked = 0; 818 static QListBoxItem * lastClicked = 0;
819 if ( item == 0 ) { 819 if ( item == 0 ) {
820 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 820 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
821 emit newEventSignal( dt ); 821 emit newEventSignal( dt );
822 return; 822 return;
823 } 823 }
824 /* 824 /*
825 if ( lastClicked ) 825 if ( lastClicked )
826 if ( ! item ) { 826 if ( ! item ) {
827 if ( lastClicked->listBox() != item->listBox() ) 827 if ( lastClicked->listBox() != item->listBox() )
828 lastClicked->listBox()->clearSelection(); 828 lastClicked->listBox()->clearSelection();
829 } 829 }
830 */ 830 */
831 831
832 mMonthView->setSelectedCell( this ); 832 mMonthView->setSelectedCell( this );
833 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); 833 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
834 select(); 834 select();
835} 835}
836 836
837void MonthViewCell::contextMenu( QListBoxItem *item ) 837void MonthViewCell::contextMenu( QListBoxItem *item )
838{ 838{
839 if ( !item ) return; 839 if ( !item ) return;
840 840
841 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 841 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
842 Incidence *incidence = eventItem->incidence(); 842 Incidence *incidence = eventItem->incidence();
843 if ( incidence ) mMonthView->showContextMenu( incidence ); 843 if ( incidence ) mMonthView->showContextMenu( incidence );
844} 844}
845 845
846void MonthViewCell::selection( QListBoxItem *item ) 846void MonthViewCell::selection( QListBoxItem *item )
847{ 847{
848 if ( !item ) return; 848 if ( !item ) return;
849 849
850 mMonthView->setSelectedCell( this ); 850 mMonthView->setSelectedCell( this );
851} 851}
852 852
853 853
854// ******************************************************************************* 854// *******************************************************************************
855// ******************************************************************************* 855// *******************************************************************************
856// ******************************************************************************* 856// *******************************************************************************
857 857
858 858
859KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 859KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
860 : KOEventView( calendar, parent, name ), 860 : KOEventView( calendar, parent, name ),
861 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 861 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
862 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 862 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
863{ 863{
864 mShortDayLabelsM = false; 864 mShortDayLabelsM = false;
865 mShortDayLabelsW = false; 865 mShortDayLabelsW = false;
866 skipResize = false; 866 skipResize = false;
867 clPending = true; 867 clPending = true;
868 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 868 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
869 mWidStack = new QWidgetStack( this ); 869 mWidStack = new QWidgetStack( this );
870 QVBoxLayout* hb = new QVBoxLayout( this ); 870 QVBoxLayout* hb = new QVBoxLayout( this );
871 mMonthView = new QWidget( mWidStack ); 871 mMonthView = new QWidget( mWidStack );
872 mWeekView = new QWidget( mWidStack ); 872 mWeekView = new QWidget( mWidStack );
873#if QT_VERSION >= 0x030000 873#if QT_VERSION >= 0x030000
874 mWidStack->addWidget(mMonthView ); 874 mWidStack->addWidget(mMonthView );
875 mWidStack->addWidget(mWeekView ); 875 mWidStack->addWidget(mWeekView );
876#else 876#else
877 mWidStack->addWidget( mMonthView, 1 ); 877 mWidStack->addWidget( mMonthView, 1 );
878 mWidStack->addWidget( mWeekView , 1 ); 878 mWidStack->addWidget( mWeekView , 1 );
879#endif 879#endif
880 hb->addWidget( mNavigatorBar ); 880 hb->addWidget( mNavigatorBar );
881 hb->addWidget( mWidStack ); 881 hb->addWidget( mWidStack );
882 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 882 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
883 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 883 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
884 if ( mShowWeekView ) 884 if ( mShowWeekView )
885 mWeekStartsMonday = true; 885 mWeekStartsMonday = true;
886 updatePossible = false; 886 updatePossible = false;
887 //updatePossible = true; 887 //updatePossible = true;
888 mCells.setAutoDelete( true ); 888 mCells.setAutoDelete( true );
889 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 889 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
890 mDayLabels.resize( mDaysPerWeek ); 890 mDayLabels.resize( mDaysPerWeek );
891 mDayLabelsW.resize( mDaysPerWeek ); 891 mDayLabelsW.resize( mDaysPerWeek );
892 QFont bfont = font(); 892 QFont bfont = font();
893 if ( QApplication::desktop()->width() < 650 ) { 893 if ( QApplication::desktop()->width() < 650 ) {
894 bfont.setPointSize( bfont.pointSize() - 2 ); 894 bfont.setPointSize( bfont.pointSize() - 2 );
895 } 895 }
896 bfont.setBold( true ); 896 bfont.setBold( true );
897 int i; 897 int i;
898 898
899 for( i = 0; i < mDaysPerWeek; i++ ) { 899 for( i = 0; i < mDaysPerWeek; i++ ) {
900 QLabel *label = new QLabel( mMonthView ); 900 QLabel *label = new QLabel( mMonthView );
901 label->setFont(bfont); 901 label->setFont(bfont);
902 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 902 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
903 label->setLineWidth(1); 903 label->setLineWidth(1);
904 label->setAlignment(AlignCenter); 904 label->setAlignment(AlignCenter);
905 mDayLabels.insert( i, label ); 905 mDayLabels.insert( i, label );
906 label = new QLabel( mWeekView ); 906 label = new QLabel( mWeekView );
907 label->setFont(bfont); 907 label->setFont(bfont);
908 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 908 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
909 label->setLineWidth(1); 909 label->setLineWidth(1);
910 label->setAlignment(AlignCenter); 910 label->setAlignment(AlignCenter);
911 mDayLabelsW.insert( i, label ); 911 mDayLabelsW.insert( i, label );
912 } 912 }
913 913
914 bfont.setBold( false ); 914 bfont.setBold( false );
915 mWeekLabels.resize( mNumWeeks+1 ); 915 mWeekLabels.resize( mNumWeeks+1 );
916 mWeekLabelsW.resize( 2 ); 916 mWeekLabelsW.resize( 2 );
917 for( i = 0; i < mNumWeeks+1; i++ ) { 917 for( i = 0; i < mNumWeeks+1; i++ ) {
918 KOWeekButton *label = new KOWeekButton( mMonthView ); 918 KOWeekButton *label = new KOWeekButton( mMonthView );
919 label->setFocusPolicy(NoFocus); 919 label->setFocusPolicy(NoFocus);
920 label->setFont(bfont); 920 label->setFont(bfont);
921 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 921 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
922 label->setFlat(true); 922 label->setFlat(true);
923 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 923 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
924 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 924 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
925 //label->setLineWidth(1); 925 //label->setLineWidth(1);
926 //label->setAlignment(AlignCenter); 926 //label->setAlignment(AlignCenter);
927 mWeekLabels.insert( i, label ); 927 mWeekLabels.insert( i, label );
928 } 928 }
929 mWeekLabels[mNumWeeks]->setText( i18n("W")); 929 mWeekLabels[mNumWeeks]->setText( i18n("W"));
930 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 930 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
931 931
932 for( i = 0; i < 1+1; i++ ) { 932 for( i = 0; i < 1+1; i++ ) {
933 KOWeekButton *label = new KOWeekButton( mWeekView ); 933 KOWeekButton *label = new KOWeekButton( mWeekView );
934 label->setFocusPolicy(NoFocus); 934 label->setFocusPolicy(NoFocus);
935 label->setFont(bfont); 935 label->setFont(bfont);
936 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 936 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
937 label->setFlat(true); 937 label->setFlat(true);
938 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 938 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
939 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 939 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
940 //label->setLineWidth(1); 940 //label->setLineWidth(1);
941 //label->setAlignment(AlignCenter); 941 //label->setAlignment(AlignCenter);
942 mWeekLabelsW.insert( i, label ); 942 mWeekLabelsW.insert( i, label );
943 } 943 }
944 mWeekLabelsW[1]->setText( i18n("W")); 944 mWeekLabelsW[1]->setText( i18n("W"));
945 945
946 946
947 int row, col; 947 int row, col;
948 mCells.resize( mNumCells ); 948 mCells.resize( mNumCells );
949 for( row = 0; row < mNumWeeks; ++row ) { 949 for( row = 0; row < mNumWeeks; ++row ) {
950 for( col = 0; col < mDaysPerWeek; ++col ) { 950 for( col = 0; col < mDaysPerWeek; ++col ) {
951 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 951 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
952 mCells.insert( row * mDaysPerWeek + col, cell ); 952 mCells.insert( row * mDaysPerWeek + col, cell );
953 953
954 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 954 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
955 SLOT( defaultAction( Incidence * ) ) ); 955 SLOT( defaultAction( Incidence * ) ) );
956 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 956 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
957 SIGNAL( newEventSignal( QDateTime ) ) ); 957 SIGNAL( newEventSignal( QDateTime ) ) );
958 connect( cell, SIGNAL( showDaySignal( QDate ) ), 958 connect( cell, SIGNAL( showDaySignal( QDate ) ),
959 SIGNAL( showDaySignal( QDate ) ) ); 959 SIGNAL( showDaySignal( QDate ) ) );
960 } 960 }
961 } 961 }
962 mCellsW.resize( mDaysPerWeek ); 962 mCellsW.resize( mDaysPerWeek );
963 for( col = 0; col < mDaysPerWeek; ++col ) { 963 for( col = 0; col < mDaysPerWeek; ++col ) {
964 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 964 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
965 mCellsW.insert( col, cell ); 965 mCellsW.insert( col, cell );
966 966
967 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 967 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
968 SLOT( defaultAction( Incidence * ) ) ); 968 SLOT( defaultAction( Incidence * ) ) );
969 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 969 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
970 SIGNAL( newEventSignal( QDateTime ) ) ); 970 SIGNAL( newEventSignal( QDateTime ) ) );
971 connect( cell, SIGNAL( showDaySignal( QDate ) ), 971 connect( cell, SIGNAL( showDaySignal( QDate ) ),
972 SIGNAL( showDaySignal( QDate ) ) ); 972 SIGNAL( showDaySignal( QDate ) ) );
973 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 973 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
974 } 974 }
975 975
976 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 976 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
977 mContextMenu = eventPopup(); 977 mContextMenu = eventPopup();
978 // updateConfig(); //useless here... 978 // updateConfig(); //useless here...
979 // ... but we need mWidthLongDayLabel computed 979 // ... but we need mWidthLongDayLabel computed
980 QFontMetrics fontmetric(mDayLabels[0]->font()); 980 QFontMetrics fontmetric(mDayLabels[0]->font());
981 mWidthLongDayLabel = 0; 981 mWidthLongDayLabel = 0;
982 for (int i = 0; i < 7; i++) { 982 for (int i = 0; i < 7; i++) {
983 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 983 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
984 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 984 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
985 } 985 }
986 986
987 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 987 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
988 988
989#if 0 989#if 0
990 if ( mShowWeekView ) 990 if ( mShowWeekView )
991 mWidStack->raiseWidget( mWeekView ); 991 mWidStack->raiseWidget( mWeekView );
992 else 992 else
993 mWidStack->raiseWidget( mMonthView ); 993 mWidStack->raiseWidget( mMonthView );
994#endif 994#endif
995 995
996 emit incidenceSelected( 0 ); 996 emit incidenceSelected( 0 );
997#ifndef DESKTOP_VERSION 997#ifndef DESKTOP_VERSION
998 resize( QApplication::desktop()->size() ); 998 resize( QApplication::desktop()->size() );
999#else 999#else
1000 resize(640, 480 ); 1000 resize(640, 480 );
1001 updatePossible = true; 1001 updatePossible = true;
1002#endif 1002#endif
1003 computeLayout(); 1003 computeLayout();
1004 1004
1005 if ( mShowWeekView ) 1005 if ( mShowWeekView )
1006 mWidStack->raiseWidget( mWeekView ); 1006 mWidStack->raiseWidget( mWeekView );
1007 else 1007 else
1008 mWidStack->raiseWidget( mMonthView ); 1008 mWidStack->raiseWidget( mMonthView );
1009} 1009}
1010 1010
1011KOMonthView::~KOMonthView() 1011KOMonthView::~KOMonthView()
1012{ 1012{
1013 delete mContextMenu; 1013 delete mContextMenu;
1014} 1014}
1015 1015
1016void KOMonthView::selectInternalWeekNum ( int n ) 1016void KOMonthView::selectInternalWeekNum ( int n )
1017{ 1017{
1018 switchView(); 1018 switchView();
1019 if ( !KOPrefs::instance()->mMonthViewWeek ) 1019 if ( !KOPrefs::instance()->mMonthViewWeek )
1020 emit selectMonth (); 1020 emit selectMonth ();
1021 else 1021 else
1022 emit selectWeekNum ( n ); 1022 emit selectWeekNum ( n );
1023} 1023}
1024 1024
1025int KOMonthView::currentWeek() 1025int KOMonthView::currentWeek()
1026{ 1026{
1027 if ( mShowWeekView ) 1027 if ( mShowWeekView )
1028 return mWeekLabelsW[0]->getWeekNum(); 1028 return mWeekLabelsW[0]->getWeekNum();
1029 return mWeekLabels[0]->getWeekNum(); 1029 return mWeekLabels[0]->getWeekNum();
1030} 1030}
1031void KOMonthView::switchView() 1031void KOMonthView::switchView()
1032{ 1032{
1033 if ( selectedCell( ) ) 1033 if ( selectedCell( ) )
1034 selectedCell()->deselect(); 1034 selectedCell()->deselect();
1035 mShowWeekView = !mShowWeekView; 1035 mShowWeekView = !mShowWeekView;
1036 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1036 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1037 if ( clPending ) { 1037 if ( clPending ) {
1038 computeLayout(); 1038 computeLayout();
1039 updateConfig(); 1039 updateConfig();
1040 } 1040 }
1041 if ( mShowWeekView ) 1041 if ( mShowWeekView )
1042 mWidStack->raiseWidget( mWeekView ); 1042 mWidStack->raiseWidget( mWeekView );
1043 else 1043 else
1044 mWidStack->raiseWidget( mMonthView ); 1044 mWidStack->raiseWidget( mMonthView );
1045 clPending = false; 1045 clPending = false;
1046} 1046}
1047 1047
1048int KOMonthView::maxDatesHint() 1048int KOMonthView::maxDatesHint()
1049{ 1049{
1050 return mNumCells; 1050 return mNumCells;
1051} 1051}
1052 1052
1053int KOMonthView::currentDateCount() 1053int KOMonthView::currentDateCount()
1054{ 1054{
1055 return mNumCells; 1055 return mNumCells;
1056} 1056}
1057 1057
1058QPtrList<Incidence> KOMonthView::selectedIncidences() 1058QPtrList<Incidence> KOMonthView::selectedIncidences()
1059{ 1059{
1060 QPtrList<Incidence> selected; 1060 QPtrList<Incidence> selected;
1061 1061
1062 if ( mSelectedCell ) { 1062 if ( mSelectedCell ) {
1063 Incidence *incidence = mSelectedCell->selectedIncidence(); 1063 Incidence *incidence = mSelectedCell->selectedIncidence();
1064 if ( incidence ) selected.append( incidence ); 1064 if ( incidence ) selected.append( incidence );
1065 } 1065 }
1066 1066
1067 return selected; 1067 return selected;
1068} 1068}
1069 1069
1070DateList KOMonthView::selectedDates() 1070DateList KOMonthView::selectedDates()
1071{ 1071{
1072 DateList selected; 1072 DateList selected;
1073 1073
1074 if ( mSelectedCell ) { 1074 if ( mSelectedCell ) {
1075 QDate qd = mSelectedCell->selectedIncidenceDate(); 1075 QDate qd = mSelectedCell->selectedIncidenceDate();
1076 if ( qd.isValid() ) selected.append( qd ); 1076 if ( qd.isValid() ) selected.append( qd );
1077 } 1077 }
1078 1078
1079 return selected; 1079 return selected;
1080} 1080}
1081 1081
1082void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1082void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1083 const QDate &td) 1083 const QDate &td)
1084{ 1084{
1085#ifndef KORG_NOPRINTER 1085#ifndef KORG_NOPRINTER
1086 calPrinter->preview(CalPrinter::Month, fd, td); 1086 calPrinter->preview(CalPrinter::Month, fd, td);
1087#endif 1087#endif
1088} 1088}
1089 1089
1090void KOMonthView::updateConfig() 1090void KOMonthView::updateConfig()
1091{ 1091{
1092 1092
1093 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1093 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1094 1094
1095 if ( mShowWeekView ) { 1095 if ( mShowWeekView ) {
1096 mWeekStartsMonday = true; 1096 mWeekStartsMonday = true;
1097 } 1097 }
1098 QFontMetrics fontmetric(mDayLabels[0]->font()); 1098 QFontMetrics fontmetric(mDayLabels[0]->font());
1099 mWidthLongDayLabel = 0; 1099 mWidthLongDayLabel = 0;
1100 1100
1101 for (int i = 0; i < 7; i++) { 1101 for (int i = 0; i < 7; i++) {
1102 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1102 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1103 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1103 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1104 } 1104 }
1105 bool temp = mShowSatSunComp ; 1105 bool temp = mShowSatSunComp ;
1106 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1106 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1107 if ( ! mShowWeekView ) { 1107 if ( ! mShowWeekView ) {
1108 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1108 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1109 computeLayout(); 1109 computeLayout();
1110 } 1110 }
1111 updateDayLabels(); 1111 updateDayLabels();
1112 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1112 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1113 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1113 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1114 //resizeEvent( 0 ); 1114 //resizeEvent( 0 );
1115 for (uint i = 0; i < mCells.count(); ++i) { 1115 for (uint i = 0; i < mCells.count(); ++i) {
1116 mCells[i]->updateConfig(); 1116 mCells[i]->updateConfig();
1117 } 1117 }
1118 1118
1119 for (uint i = 0; i < mCellsW.count(); ++i) { 1119 for (uint i = 0; i < mCellsW.count(); ++i) {
1120 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1120 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1121 } 1121 }
1122#ifdef DESKTOP_VERSION 1122#ifdef DESKTOP_VERSION
1123 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1123 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1124#endif 1124#endif
1125 updateView(); 1125 updateView();
1126} 1126}
1127 1127
1128void KOMonthView::updateDayLabels() 1128void KOMonthView::updateDayLabels()
1129{ 1129{
1130 1130
1131 QPtrVector<QLabel> *mDayLabelsT; 1131 QPtrVector<QLabel> *mDayLabelsT;
1132 1132
1133 mDayLabelsT = &mDayLabelsW; 1133 mDayLabelsT = &mDayLabelsW;
1134 for (int i = 0; i < 7; i++) { 1134 for (int i = 0; i < 7; i++) {
1135 if (mWeekStartsMonday) { 1135 if (mWeekStartsMonday) {
1136 bool show = mShortDayLabelsW; 1136 bool show = mShortDayLabelsW;
1137 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1137 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1138 show = true; 1138 show = true;
1139 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1139 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1140 } else { 1140 } else {
1141 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW)); 1141 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW));
1142 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW)); 1142 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW));
1143 1143
1144 } 1144 }
1145 } 1145 }
1146 mDayLabelsT = &mDayLabels; 1146 mDayLabelsT = &mDayLabels;
1147 for (int i = 0; i < 7; i++) { 1147 for (int i = 0; i < 7; i++) {
1148 if (mWeekStartsMonday) { 1148 if (mWeekStartsMonday) {
1149 bool show = mShortDayLabelsM; 1149 bool show = mShortDayLabelsM;
1150 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1150 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1151 show = true; 1151 show = true;
1152 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1152 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1153 } else { 1153 } else {
1154 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1154 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1155 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1155 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1156 1156
1157 } 1157 }
1158 } 1158 }
1159 1159
1160} 1160}
1161 1161
1162void KOMonthView::showDates(const QDate &start, const QDate &) 1162void KOMonthView::showDates(const QDate &start, const QDate &)
1163{ 1163{
1164 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1164 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1165 1165
1166 QPtrVector<MonthViewCell> *cells; 1166 QPtrVector<MonthViewCell> *cells;
1167 QPtrVector<QLabel> *dayLabels; 1167 QPtrVector<QLabel> *dayLabels;
1168 QPtrVector<KOWeekButton> *weekLabels; 1168 QPtrVector<KOWeekButton> *weekLabels;
1169 int weekNum = 6; 1169 int weekNum = 6;
1170 if ( mShowWeekView ) { 1170 if ( mShowWeekView ) {
1171 weekNum = 1; 1171 weekNum = 1;
1172 cells = &mCellsW; 1172 cells = &mCellsW;
1173 dayLabels = &mDayLabelsW; 1173 dayLabels = &mDayLabelsW;
1174 weekLabels = &mWeekLabelsW; 1174 weekLabels = &mWeekLabelsW;
1175 } else { 1175 } else {
1176 cells = &mCells; 1176 cells = &mCells;
1177 dayLabels = &mDayLabels; 1177 dayLabels = &mDayLabels;
1178 weekLabels = &mWeekLabels; 1178 weekLabels = &mWeekLabels;
1179 } 1179 }
1180 1180
1181 mStartDate = start; 1181 mStartDate = start;
1182 1182
1183 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1183 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1184 1184
1185 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1185 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1186 mStartDate = mStartDate.addDays( -1 ); 1186 mStartDate = mStartDate.addDays( -1 );
1187 } 1187 }
1188 1188
1189 bool primary = false; 1189 bool primary = false;
1190 uint i; 1190 uint i;
1191 for( i = 0; i < (*cells).size(); ++i ) { 1191 for( i = 0; i < (*cells).size(); ++i ) {
1192 QDate date = mStartDate.addDays( i ); 1192 QDate date = mStartDate.addDays( i );
1193 (*cells)[i]->setDate( date ); 1193 (*cells)[i]->setDate( date );
1194 1194
1195#ifndef KORG_NOPLUGINS 1195#ifndef KORG_NOPLUGINS
1196 // add holiday, if present 1196 // add holiday, if present
1197 QString hstring(KOCore::self()->holiday(date)); 1197 QString hstring(KOCore::self()->holiday(date));
1198 (*cells)[i]->setHoliday( hstring ); 1198 (*cells)[i]->setHoliday( hstring );
1199#endif 1199#endif
1200 1200
1201 } 1201 }
1202 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1202 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1203 for( i = 0; i < weekNum; ++i ) { 1203 for( i = 0; i < weekNum; ++i ) {
1204 int wno; 1204 int wno;
1205 // remember, according to ISO 8601, the first week of the year is the 1205 // remember, according to ISO 8601, the first week of the year is the
1206 // first week that contains a thursday. Thus we must subtract off 4, 1206 // first week that contains a thursday. Thus we must subtract off 4,
1207 // not just 1. 1207 // not just 1.
1208 int dayOfYear = date.dayOfYear(); 1208 int dayOfYear = date.dayOfYear();
1209 if (dayOfYear % 7 != 0) 1209 if (dayOfYear % 7 != 0)
1210 wno = dayOfYear / 7 + 1; 1210 wno = dayOfYear / 7 + 1;
1211 else 1211 else
1212 wno =dayOfYear / 7; 1212 wno =dayOfYear / 7;
1213 (*weekLabels)[i]->setWeekNum( wno ); 1213 (*weekLabels)[i]->setWeekNum( wno );
1214 date = date.addDays( 7 ); 1214 date = date.addDays( 7 );
1215 } 1215 }
1216 updateView(); 1216 updateView();
1217} 1217}
1218 1218
1219void KOMonthView::showEvents(QPtrList<Event>) 1219void KOMonthView::showEvents(QPtrList<Event>)
1220{ 1220{
1221 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1221 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1222} 1222}
1223 1223
1224void KOMonthView::changeEventDisplay(Event *, int) 1224void KOMonthView::changeEventDisplay(Event *, int)
1225{ 1225{
1226 // this should be re-written to be much more efficient, but this 1226 // this should be re-written to be much more efficient, but this
1227 // quick-and-dirty-hack gets the job done for right now. 1227 // quick-and-dirty-hack gets the job done for right now.
1228 updateView(); 1228 updateView();
1229} 1229}
1230 1230
1231void KOMonthView::updateView() 1231void KOMonthView::updateView()
1232{ 1232{
1233 1233
1234 if ( !updatePossible ) 1234 if ( !updatePossible )
1235 return; 1235 return;
1236 //QTime ti; 1236 //QTime ti;
1237 //ti.start(); 1237 //ti.start();
1238 clearSelection(); 1238 clearSelection();
1239 QPtrVector<MonthViewCell> *cells; 1239 QPtrVector<MonthViewCell> *cells;
1240 if ( mShowWeekView ) { 1240 if ( mShowWeekView ) {
1241 cells = &mCellsW; 1241 cells = &mCellsW;
1242 } else { 1242 } else {
1243 cells = &mCells; 1243 cells = &mCells;
1244 } 1244 }
1245#if 1 1245#if 1
1246 int i; 1246 int i;
1247 int timeSpan = (*cells).size()-1; 1247 int timeSpan = (*cells).size()-1;
1248 if ( KOPrefs::instance()->mMonthViewWeek ) 1248 if ( KOPrefs::instance()->mMonthViewWeek )
1249 timeSpan = 6; 1249 timeSpan = 6;
1250 for( i = 0; i < timeSpan + 1; ++i ) { 1250 for( i = 0; i < timeSpan + 1; ++i ) {
1251 (*cells)[i]->startUpdateCell(); 1251 (*cells)[i]->startUpdateCell();
1252 } 1252 }
1253 1253
1254 QPtrList<Event> events = calendar()->events(); 1254 QPtrList<Event> events = calendar()->events();
1255 Event *event; 1255 Event *event;
1256 QDateTime dt; 1256 QDateTime dt;
1257 bool ok; 1257 bool ok;
1258 QDate endDate = mStartDate.addDays( timeSpan ); 1258 QDate endDate = mStartDate.addDays( timeSpan );
1259 for( event = events.first(); event; event = events.next() ) { // for event 1259 for( event = events.first(); event; event = events.next() ) { // for event
1260 if ( event->doesRecur() ) { 1260 if ( event->doesRecur() ) {
1261 bool last; 1261 bool last;
1262 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1262 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1263 QDateTime incidenceEnd; 1263 QDateTime incidenceEnd;
1264 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1264 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1265 bool invalid = false; 1265 bool invalid = false;
1266 while( true ) { 1266 while( true ) {
1267 if ( incidenceStart.isValid() ) { 1267 if ( incidenceStart.isValid() ) {
1268 incidenceEnd = incidenceStart.addDays( eventlen ); 1268 incidenceEnd = incidenceStart.addDays( eventlen );
1269 int st = incidenceStart.date().daysTo( endDate ); 1269 int st = incidenceStart.date().daysTo( endDate );
1270 if ( st >= 0 ) { // start before timeend 1270 if ( st >= 0 ) { // start before timeend
1271 int end = mStartDate.daysTo( incidenceEnd.date() ); 1271 int end = mStartDate.daysTo( incidenceEnd.date() );
1272 if ( end >= 0 ) { // end after timestart --- got one! 1272 if ( end >= 0 ) { // end after timestart --- got one!
1273 //normalize 1273 //normalize
1274 st = timeSpan - st; 1274 st = timeSpan - st;
1275 if ( st < 0 ) st = 0; 1275 if ( st < 0 ) st = 0;
1276 if ( end > timeSpan ) end = timeSpan; 1276 if ( end > timeSpan ) end = timeSpan;
1277 int iii; 1277 int iii;
1278 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1278 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1279 for ( iii = st;iii<= end;++iii) 1279 for ( iii = st;iii<= end;++iii)
1280 (*cells)[iii]->insertEvent( event ); 1280 (*cells)[iii]->insertEvent( event );
1281 } 1281 }
1282 } 1282 }
1283 } else { 1283 } else {
1284 if ( invalid ) 1284 if ( invalid )
1285 break; 1285 break;
1286 invalid = true; 1286 invalid = true;
1287 //qDebug("invalid %s", event->summary().latin1()); 1287 //qDebug("invalid %s", event->summary().latin1());
1288 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1288 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1289 } 1289 }
1290 if ( last ) 1290 if ( last )
1291 break; 1291 break;
1292 bool ok; 1292 bool ok;
1293 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1293 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1294 if ( ! ok ) 1294 if ( ! ok )
1295 break; 1295 break;
1296 if ( incidenceStart.date() > endDate ) 1296 if ( incidenceStart.date() > endDate )
1297 break; 1297 break;
1298 } 1298 }
1299 } else { // no recur 1299 } else { // no recur
1300 int st = event->dtStart().date().daysTo( endDate ); 1300 int st = event->dtStart().date().daysTo( endDate );
1301 if ( st >= 0 ) { // start before timeend 1301 if ( st >= 0 ) { // start before timeend
1302 int end = mStartDate.daysTo( event->dtEnd().date() ); 1302 int end = mStartDate.daysTo( event->dtEnd().date() );
1303 if ( end >= 0 ) { // end after timestart --- got one! 1303 if ( end >= 0 ) { // end after timestart --- got one!
1304 //normalize 1304 //normalize
1305 st = timeSpan - st; 1305 st = timeSpan - st;
1306 if ( st < 0 ) st = 0; 1306 if ( st < 0 ) st = 0;
1307 if ( end > timeSpan ) end = timeSpan; 1307 if ( end > timeSpan ) end = timeSpan;
1308 int iii; 1308 int iii;
1309 for ( iii = st;iii<= end;++iii) 1309 for ( iii = st;iii<= end;++iii)
1310 (*cells)[iii]->insertEvent( event ); 1310 (*cells)[iii]->insertEvent( event );
1311 } 1311 }
1312 } 1312 }
1313 } 1313 }
1314 } 1314 }
1315 // insert due todos 1315 // insert due todos
1316 QPtrList<Todo> todos = calendar()->todos( ); 1316 QPtrList<Todo> todos = calendar()->todos( );
1317 Todo *todo; 1317 Todo *todo;
1318 for(todo = todos.first(); todo; todo = todos.next()) { 1318 for(todo = todos.first(); todo; todo = todos.next()) {
1319 //insertTodo( todo ); 1319 //insertTodo( todo );
1320 if ( todo->hasDueDate() ) { 1320 if ( todo->hasDueDate() ) {
1321 int day = mStartDate.daysTo( todo->dtDue().date() ); 1321 int day = mStartDate.daysTo( todo->dtDue().date() );
1322 if ( day >= 0 && day < timeSpan + 1) { 1322 if ( day >= 0 && day < timeSpan + 1) {
1323 (*cells)[day]->insertTodo( todo ); 1323 (*cells)[day]->insertTodo( todo );
1324 } 1324 }
1325 } 1325 }
1326 } 1326 }
1327 1327
1328 for( i = 0; i < timeSpan+1; ++i ) { 1328 for( i = 0; i < timeSpan+1; ++i ) {
1329 (*cells)[i]->finishUpdateCell(); 1329 (*cells)[i]->finishUpdateCell();
1330 } 1330 }
1331 processSelectionChange(); 1331 processSelectionChange();
1332 (*cells)[0]->setFocus(); 1332 (*cells)[0]->setFocus();
1333 1333
1334 1334
1335#else 1335#else
1336 // old code 1336 // old code
1337 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1337 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1338 int i; 1338 int i;
1339 for( i = 0; i < (*cells).count(); ++i ) { 1339 for( i = 0; i < (*cells).count(); ++i ) {
1340 (*cells)[i]->updateCell(); 1340 (*cells)[i]->updateCell();
1341 } 1341 }
1342 1342
1343 //qDebug("KOMonthView::updateView() "); 1343 //qDebug("KOMonthView::updateView() ");
1344 processSelectionChange(); 1344 processSelectionChange();
1345 // qDebug("---------------------------------------------------------------------+ "); 1345 // qDebug("---------------------------------------------------------------------+ ");
1346 (*cells)[0]->setFocus(); 1346 (*cells)[0]->setFocus();
1347#endif 1347#endif
1348 1348
1349 //qDebug("update time %d ", ti.elapsed()); 1349 //qDebug("update time %d ", ti.elapsed());
1350} 1350}
1351 1351
1352void KOMonthView::resizeEvent(QResizeEvent * e) 1352void KOMonthView::resizeEvent(QResizeEvent * e)
1353{ 1353{
1354 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1354 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1355 computeLayout(); 1355 computeLayout();
1356 clPending = true; 1356 clPending = true;
1357 if ( mShowWeekView ) 1357 if ( mShowWeekView )
1358 mCellsW[0]->setFocus(); 1358 mCellsW[0]->setFocus();
1359 else 1359 else
1360 mCells[0]->setFocus(); 1360 mCells[0]->setFocus();
1361} 1361}
1362void KOMonthView::computeLayoutWeek() 1362void KOMonthView::computeLayoutWeek()
1363{ 1363{
1364 static int lastWid = 0; 1364 static int lastWid = 0;
1365 static int lastHei = 0; 1365 static int lastHei = 0;
1366 int daysToShow; 1366 int daysToShow;
1367 bool combinedSatSun = false; 1367 bool combinedSatSun = false;
1368 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1368 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1369 daysToShow = 6; 1369 daysToShow = 6;
1370 combinedSatSun = true; 1370 combinedSatSun = true;
1371 } 1371 }
1372 int tWid = topLevelWidget()->size().width(); 1372 int tWid = topLevelWidget()->size().width();
1373 int tHei = topLevelWidget()->size().height(); 1373 int tHei = topLevelWidget()->size().height();
1374 1374
1375 int wid = width();//e 1375 int wid = width();//e
1376 int hei = height()-1-mNavigatorBar->height(); 1376 int hei = height()-1-mNavigatorBar->height();
1377 1377
1378 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1378 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1379 return; 1379 return;
1380 1380
1381 if ( lastWid == width() && lastHei == height() ) 1381 if ( lastWid == width() && lastHei == height() )
1382 return; 1382 return;
1383 lastWid = width(); 1383 lastWid = width();
1384 lastHei = height(); 1384 lastHei = height();
1385 1385
1386 1386
1387 if ( wid < hei ) 1387 if ( wid < hei )
1388 daysToShow = 2; 1388 daysToShow = 2;
1389 else 1389 else
1390 daysToShow = 3; 1390 daysToShow = 3;
1391 mShowSatSunComp = true; 1391 mShowSatSunComp = true;
1392 combinedSatSun = true; 1392 combinedSatSun = true;
1393 1393
1394 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1394 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1395 QFontMetrics fm ( mWeekLabels[0]->font() ); 1395 QFontMetrics fm ( mWeekLabels[0]->font() );
1396 int weeklabelwid = fm.width( "888" ); 1396 int weeklabelwid = fm.width( "888" );
1397 wid -= weeklabelwid; 1397 wid -= weeklabelwid;
1398 1398
1399 int colWid = wid / daysToShow; 1399 int colWid = wid / daysToShow;
1400 int lastCol = wid - ( colWid*6 ); 1400 int lastCol = wid - ( colWid*6 );
1401 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1401 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1402 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1402 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1403 int colModulo = wid % daysToShow; 1403 int colModulo = wid % daysToShow;
1404 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1404 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1405 //qDebug("rowmod %d ", rowModulo); 1405 //qDebug("rowmod %d ", rowModulo);
1406 int i; 1406 int i;
1407 int x,y,w,h; 1407 int x,y,w,h;
1408 x= 0; 1408 x= 0;
1409 y= 0; 1409 y= 0;
1410 w = colWid; 1410 w = colWid;
1411 h = dayLabelHei ; 1411 h = dayLabelHei ;
1412 for ( i = 0; i < 7; i++) { 1412 for ( i = 0; i < 7; i++) {
1413 if ( i && !( i % daysToShow) && i < 6) { 1413 if ( i && !( i % daysToShow) && i < 6) {
1414 y += hei/(5-daysToShow); 1414 y += hei/(5-daysToShow);
1415 x = 0; 1415 x = 0;
1416 w = colWid; 1416 w = colWid;
1417 } 1417 }
1418 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1418 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1419 ++w; 1419 ++w;
1420 } 1420 }
1421 if ( i >= 5 ) { 1421 if ( i >= 5 ) {
1422 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h); 1422 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w/2+w%2,h);
1423 x -= (w/2 ); 1423 x -= (w/2 );
1424 } 1424 }
1425 else 1425 else
1426 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h); 1426 mDayLabelsW[i]->setGeometry( x+weeklabelwid,y,w,h);
1427 x += w; 1427 x += w;
1428 } 1428 }
1429 x= 0; 1429 x= 0;
1430 y= dayLabelHei; 1430 y= dayLabelHei;
1431 w = colWid; 1431 w = colWid;
1432 h = cellHei; 1432 h = cellHei;
1433 for ( i = 0; i < mCellsW.count(); ++i) { 1433 for ( i = 0; i < mCellsW.count(); ++i) {
1434 if ( i > 6 ) { 1434 if ( i > 6 ) {
1435 mCellsW[i]->hide(); 1435 mCellsW[i]->hide();
1436 continue; 1436 continue;
1437 } 1437 }
1438 1438
1439 w = colWid; 1439 w = colWid;
1440 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1440 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1441 ++w; 1441 ++w;
1442 } 1442 }
1443 if ( i == (daysToShow-1-rowModulo)*7) 1443 if ( i == (daysToShow-1-rowModulo)*7)
1444 ++h; 1444 ++h;
1445 1445
1446 if ( i >= 5 ) { 1446 if ( i >= 5 ) {
1447 if ( i ==5 ) { 1447 if ( i ==5 ) {
1448 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); 1448 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h/2 );
1449 x -= w ;y += h/2; 1449 x -= w ;y += h/2;
1450 } else { 1450 } else {
1451 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1451 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1452 ++w; 1452 ++w;
1453 } 1453 }
1454 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); 1454 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 );
1455 y -= h/2; 1455 y -= h/2;
1456 } 1456 }
1457 } else 1457 } else
1458 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1458 mCellsW[i]->setGeometry ( x+weeklabelwid,y,w,h );
1459 1459
1460 1460
1461 x += w; 1461 x += w;
1462 if ( x + w/2 > wid ) { 1462 if ( x + w/2 > wid ) {
1463 x = 0; 1463 x = 0;
1464 y += h+dayLabelHei ; 1464 y += h+dayLabelHei ;
1465 } 1465 }
1466 } 1466 }
1467 y= dayLabelHei; 1467 y= dayLabelHei;
1468 h = cellHei ; 1468 h = cellHei ;
1469 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1469 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1470 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1470 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1471 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1471 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1472 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1472 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1473 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1473 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1474 updateDayLabels(); 1474 updateDayLabels();
1475 //bool forceUpdate = !updatePossible; 1475 //bool forceUpdate = !updatePossible;
1476 updatePossible = true; 1476 updatePossible = true;
1477 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1477 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1478 //if ( forceUpdate ) 1478 //if ( forceUpdate )
1479 // updateView(); 1479 // updateView();
1480} 1480}
1481void KOMonthView::computeLayout() 1481void KOMonthView::computeLayout()
1482{ 1482{
1483 1483
1484 1484
1485 static int lastWid = 0; 1485 static int lastWid = 0;
1486 static int lastHei = 0; 1486 static int lastHei = 0;
1487 1487
1488 if ( mShowWeekView ){ 1488 if ( mShowWeekView ){
1489 computeLayoutWeek(); 1489 computeLayoutWeek();
1490 return; 1490 return;
1491 } 1491 }
1492 int daysToShow = 7; 1492 int daysToShow = 7;
1493 bool combinedSatSun = false; 1493 bool combinedSatSun = false;
1494 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1494 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1495 daysToShow = 6; 1495 daysToShow = 6;
1496 combinedSatSun = true; 1496 combinedSatSun = true;
1497 } 1497 }
1498 int tWid = topLevelWidget()->size().width(); 1498 int tWid = topLevelWidget()->size().width();
1499 int tHei = topLevelWidget()->size().height(); 1499 int tHei = topLevelWidget()->size().height();
1500 1500
1501 int wid = width();//e 1501 int wid = width();//e
1502 int hei = height()-1-mNavigatorBar->height(); 1502 int hei = height()-1-mNavigatorBar->height();
1503 1503
1504 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 1504 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
1505 return; 1505 return;
1506 } 1506 }
1507 if ( lastWid == width() && lastHei == height() ){ 1507 if ( lastWid == width() && lastHei == height() ){
1508 return; 1508 return;
1509 } 1509 }
1510 1510
1511 lastWid = width(); 1511 lastWid = width();
1512 lastHei = height(); 1512 lastHei = height();
1513 //qDebug("KOMonthView::computeLayout() MMM ------------------------------------ "); 1513 //qDebug("KOMonthView::computeLayout() MMM ------------------------------------ ");
1514 QFontMetrics fm ( mWeekLabels[0]->font() ); 1514 QFontMetrics fm ( mWeekLabels[0]->font() );
1515 int weeklabelwid = fm.width( "888" ); 1515 int weeklabelwid = fm.width( "888" );
1516 wid -= weeklabelwid; 1516 wid -= weeklabelwid;
1517 1517
1518 int colWid = wid / daysToShow; 1518 int colWid = wid / daysToShow;
1519 int lastCol = wid - ( colWid*6 ); 1519 int lastCol = wid - ( colWid*6 );
1520 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 1520 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1521 int cellHei = (hei - dayLabelHei) /6; 1521 int cellHei = (hei - dayLabelHei) /6;
1522 int colModulo = wid % daysToShow; 1522 int colModulo = wid % daysToShow;
1523 int rowModulo = (hei- dayLabelHei) % 6; 1523 int rowModulo = (hei- dayLabelHei) % 6;
1524 //qDebug("rowmod %d ", rowModulo); 1524 //qDebug("rowmod %d ", rowModulo);
1525 int i; 1525 int i;
1526 int x,y,w,h; 1526 int x,y,w,h;
1527 x= 0; 1527 x= 0;
1528 y= 0; 1528 y= 0;
1529 w = colWid; 1529 w = colWid;
1530 h = dayLabelHei ; 1530 h = dayLabelHei ;
1531 for ( i = 0; i < 7; i++) { 1531 for ( i = 0; i < 7; i++) {
1532 if ( i == daysToShow-colModulo ) 1532 if ( i == daysToShow-colModulo )
1533 ++w; 1533 ++w;
1534 if ( combinedSatSun ) { 1534 if ( combinedSatSun ) {
1535 if ( i >= daysToShow-1 ) { 1535 if ( i >= daysToShow-1 ) {
1536 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 1536 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1537 x -= w/2 ; 1537 x -= w/2 ;
1538 } 1538 }
1539 else 1539 else
1540 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1540 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1541 } else 1541 } else
1542 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 1542 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1543 x += w; 1543 x += w;
1544 } 1544 }
1545 x= 0; 1545 x= 0;
1546 y= dayLabelHei; 1546 y= dayLabelHei;
1547 w = colWid; 1547 w = colWid;
1548 h = cellHei ; 1548 h = cellHei ;
1549 for ( i = 0; i < mCells.count(); ++i) { 1549 for ( i = 0; i < mCells.count(); ++i) {
1550 //qDebug("iii %d ", i); 1550 //qDebug("iii %d ", i);
1551 w = colWid; 1551 w = colWid;
1552 if ( ((i) % 7) >= 7-colModulo ) { 1552 if ( ((i) % 7) >= 7-colModulo ) {
1553 ++w; 1553 ++w;
1554 } 1554 }
1555 if ( i == (6-rowModulo)*7) 1555 if ( i == (6-rowModulo)*7)
1556 ++h; 1556 ++h;
1557 if ( combinedSatSun ) { 1557 if ( combinedSatSun ) {
1558 if ( (i)%7 >= daysToShow-1 ) { 1558 if ( (i)%7 >= daysToShow-1 ) {
1559 if ( (i)%7 == daysToShow-1 ) { 1559 if ( (i)%7 == daysToShow-1 ) {
1560 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 ); 1560 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 );
1561 x -= w ;y += h/2; 1561 x -= w ;y += h/2;
1562 } else { 1562 } else {
1563 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 ); 1563 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 );
1564 y -= h/2; 1564 y -= h/2;
1565 } 1565 }
1566 } else 1566 } else
1567 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1567 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1568 1568
1569 } 1569 }
1570 else 1570 else
1571 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 1571 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1572 x += w; 1572 x += w;
1573 if ( x + w/2 > wid ) { 1573 if ( x + w/2 > wid ) {
1574 x = 0; 1574 x = 0;
1575 y += h; 1575 y += h;
1576 } 1576 }
1577 } 1577 }
1578 y= dayLabelHei; 1578 y= dayLabelHei;
1579 h = cellHei ; 1579 h = cellHei ;
1580 for ( i = 0; i < 6; i++) { 1580 for ( i = 0; i < 6; i++) {
1581 if ( i == (6-rowModulo)) 1581 if ( i == (6-rowModulo))
1582 ++h; 1582 ++h;
1583 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1583 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1584 y += h; 1584 y += h;
1585 } 1585 }
1586 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1586 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1587 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1587 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1588 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1588 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1589 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 1589 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
1590 updateDayLabels(); 1590 updateDayLabels();
1591 //bool forceUpdate = !updatePossible; 1591 //bool forceUpdate = !updatePossible;
1592 updatePossible = true; 1592 updatePossible = true;
1593 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1593 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1594} 1594}
1595 1595
1596void KOMonthView::showContextMenu( Incidence *incidence ) 1596void KOMonthView::showContextMenu( Incidence *incidence )
1597{ 1597{
1598 mContextMenu->showIncidencePopup(incidence); 1598 mContextMenu->showIncidencePopup(incidence);
1599 /* 1599 /*
1600 if( incidence && incidence->type() == "Event" ) { 1600 if( incidence && incidence->type() == "Event" ) {
1601 Event *event = static_cast<Event *>(incidence); 1601 Event *event = static_cast<Event *>(incidence);
1602 mContextMenu->showEventPopup(event); 1602 mContextMenu->showEventPopup(event);
1603 } else { 1603 } else {
1604 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 1604 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
1605 } 1605 }
1606 */ 1606 */
1607} 1607}
1608MonthViewCell * KOMonthView::selectedCell( ) 1608MonthViewCell * KOMonthView::selectedCell( )
1609{ 1609{
1610 return mSelectedCell; 1610 return mSelectedCell;
1611} 1611}
1612void KOMonthView::setSelectedCell( MonthViewCell *cell ) 1612void KOMonthView::setSelectedCell( MonthViewCell *cell )
1613{ 1613{
1614 //qDebug("KOMonthView::setSelectedCell "); 1614 //qDebug("KOMonthView::setSelectedCell ");
1615 if ( mSelectedCell && mSelectedCell != cell ) { 1615 if ( mSelectedCell && mSelectedCell != cell ) {
1616 MonthViewCell * mvc = mSelectedCell; 1616 MonthViewCell * mvc = mSelectedCell;
1617 mSelectedCell = cell; 1617 mSelectedCell = cell;
1618 mvc->deselect(); 1618 mvc->deselect();
1619 } else 1619 } else
1620 mSelectedCell = cell; 1620 mSelectedCell = cell;
1621 // if ( mSelectedCell ) 1621 // if ( mSelectedCell )
1622 // mSelectedCell->select(); 1622 // mSelectedCell->select();
1623 if ( !mSelectedCell ) 1623 if ( !mSelectedCell )
1624 emit incidenceSelected( 0 ); 1624 emit incidenceSelected( 0 );
1625 else 1625 else
1626 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 1626 emit incidenceSelected( mSelectedCell->selectedIncidence() );
1627} 1627}
1628 1628
1629void KOMonthView::processSelectionChange() 1629void KOMonthView::processSelectionChange()
1630{ 1630{
1631 QPtrList<Incidence> incidences = selectedIncidences(); 1631 QPtrList<Incidence> incidences = selectedIncidences();
1632 if (incidences.count() > 0) { 1632 if (incidences.count() > 0) {
1633 emit incidenceSelected( incidences.first() ); 1633 emit incidenceSelected( incidences.first() );
1634 } else { 1634 } else {
1635 emit incidenceSelected( 0 ); 1635 emit incidenceSelected( 0 );
1636 clearSelection(); 1636 clearSelection();
1637 } 1637 }
1638} 1638}
1639 1639
1640void KOMonthView::clearSelection() 1640void KOMonthView::clearSelection()
1641{ 1641{
1642 if ( mSelectedCell ) { 1642 if ( mSelectedCell ) {
1643 mSelectedCell->deselect(); 1643 mSelectedCell->deselect();
1644 mSelectedCell = 0; 1644 mSelectedCell = 0;
1645 } 1645 }
1646} 1646}
1647void KOMonthView::keyPressEvent ( QKeyEvent * e ) 1647void KOMonthView::keyPressEvent ( QKeyEvent * e )
1648{ 1648{
1649 //qDebug("KOMonthView::keyPressEvent "); 1649 //qDebug("KOMonthView::keyPressEvent ");
1650 switch(e->key()) { 1650 switch(e->key()) {
1651 case Key_Up: 1651 case Key_Up:
1652 { 1652 {
1653 if ( mShowWeekView ) { 1653 if ( mShowWeekView ) {
1654 mCellsW[0]->setFocus(); 1654 mCellsW[0]->setFocus();
1655 emit selectWeekNum ( currentWeek() - 1 ); 1655 emit selectWeekNum ( currentWeek() - 1 );
1656 } 1656 }
1657 else { 1657 else {
1658 mCells[0]->setFocus(); 1658 mCells[0]->setFocus();
1659 emit prevMonth(); 1659 emit prevMonth();
1660 } 1660 }
1661 } 1661 }
1662 e->accept(); 1662 e->accept();
1663 break; 1663 break;
1664 case Key_Down: 1664 case Key_Down:
1665 { 1665 {
1666 if ( mShowWeekView ) { 1666 if ( mShowWeekView ) {
1667 mCellsW[0]->setFocus(); 1667 mCellsW[0]->setFocus();
1668 emit selectWeekNum ( currentWeek() +1); 1668 emit selectWeekNum ( currentWeek() +1);
1669 } 1669 }
1670 else { 1670 else {
1671 mCells[0]->setFocus(); 1671 mCells[0]->setFocus();
1672 emit nextMonth(); 1672 emit nextMonth();
1673 } 1673 }
1674 1674
1675 } 1675 }
1676 e->accept(); 1676 e->accept();
1677 break; 1677 break;
1678 case Key_Return: 1678 case Key_Return:
1679 case Key_Enter: 1679 case Key_Enter:
1680 { 1680 {
1681 selectInternalWeekNum ( currentWeek() ); 1681 selectInternalWeekNum ( currentWeek() );
1682 } 1682 }
1683 e->accept(); 1683 e->accept();
1684 break; 1684 break;
1685 case Key_D: 1685 case Key_D:
1686 if ( mSelectedCell ) { 1686 if ( mSelectedCell ) {
1687 mSelectedCell->showDay(); 1687 mSelectedCell->showDay();
1688 e->accept(); 1688 e->accept();
1689 } else { 1689 } else {
1690 e->ignore(); 1690 e->ignore();
1691 } 1691 }
1692 break; 1692 break;
1693 default: 1693 default:
1694 e->ignore(); 1694 e->ignore();
1695 break; 1695 break;
1696 } 1696 }
1697} 1697}
diff --git a/korganizer/navigatorbar.cpp b/korganizer/navigatorbar.cpp
index 1b4ee52..06f5ef8 100644
--- a/korganizer/navigatorbar.cpp
+++ b/korganizer/navigatorbar.cpp
@@ -1,272 +1,272 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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 24
25#include <qstring.h> 25#include <qstring.h>
26#include <qtooltip.h> 26#include <qtooltip.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qframe.h> 29#include <qframe.h>
30#include <qlabel.h> 30#include <qlabel.h>
31#include <qpopupmenu.h> 31#include <qpopupmenu.h>
32#include <qapplication.h> 32#include <qapplication.h>
33 33
34#include <kdebug.h> 34#include <kdebug.h>
35#include <klocale.h> 35#include <klocale.h>
36#include <kglobal.h> 36#include <kglobal.h>
37#include <kiconloader.h> 37#include <kiconloader.h>
38#include "libkdepim/kdatepicker.h" 38#include "libkdepim/kdatepicker.h"
39#include <knotifyclient.h> 39#include <knotifyclient.h>
40#include "kdatetbl.h" 40#include "kdatetbl.h"
41 41
42#include "koglobals.h" 42#include "koglobals.h"
43#include <kglobalsettings.h> 43#include <kglobalsettings.h>
44#include "koprefs.h" 44#include "koprefs.h"
45#ifndef KORG_NOPLUGINS 45#ifndef KORG_NOPLUGINS
46#include "kocore.h" 46#include "kocore.h"
47#endif 47#endif
48 48
49#include <kcalendarsystem.h> 49#include <kcalendarsystem.h>
50 50
51#include "navigatorbar.h" 51#include "navigatorbar.h"
52 52
53NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name ) 53NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name )
54 : QWidget( parent, name ) 54 : QWidget( parent, name )
55{ 55{
56 QBoxLayout *topLayout = new QHBoxLayout( this ); 56 QBoxLayout *topLayout = new QHBoxLayout( this );
57 57
58 // Set up the control buttons and date label 58 // Set up the control buttons and date label
59 mCtrlFrame = new QFrame( this ); 59 mCtrlFrame = new QFrame( this );
60 mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised); 60 mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised);
61 mCtrlFrame->setLineWidth(1); 61 mCtrlFrame->setLineWidth(1);
62 62
63 topLayout->addWidget( mCtrlFrame ); 63 topLayout->addWidget( mCtrlFrame );
64 64
65 65
66 66
67 bool isRTL = KOGlobals::self()->reverseLayout(); 67 bool isRTL = KOGlobals::self()->reverseLayout();
68#ifndef DESKTOP_VERSION 68#ifndef DESKTOP_VERSION
69 bool isDesktop = false; 69 bool isDesktop = false;
70#else 70#else
71 bool isDesktop = true; 71 bool isDesktop = true;
72#endif 72#endif
73 if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) 73 if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 )
74 isDesktop = true; 74 isDesktop = true;
75 // Create backward navigation buttons 75 // Create backward navigation buttons
76 mPrevYear = new QPushButton( mCtrlFrame ); 76 mPrevYear = new QPushButton( mCtrlFrame );
77 mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); 77 mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) );
78 QToolTip::add( mPrevYear, i18n("Previous Year") ); 78 QToolTip::add( mPrevYear, i18n("Previous Year") );
79 79
80 mPrevMonth = new QPushButton( mCtrlFrame ); 80 mPrevMonth = new QPushButton( mCtrlFrame );
81 mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); 81 mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") );
82 QToolTip::add( mPrevMonth, i18n("Previous Month") ); 82 QToolTip::add( mPrevMonth, i18n("Previous Month") );
83 83
84 // Create forward navigation buttons 84 // Create forward navigation buttons
85 mNextMonth = new QPushButton( mCtrlFrame ); 85 mNextMonth = new QPushButton( mCtrlFrame );
86 mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); 86 mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") );
87 QToolTip::add( mNextMonth, i18n("Next Month") ); 87 QToolTip::add( mNextMonth, i18n("Next Month") );
88 88
89 mPrevWeek = new QPushButton( mCtrlFrame ); 89 mPrevWeek = new QPushButton( mCtrlFrame );
90 mPrevWeek->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); 90 mPrevWeek->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") );
91 QToolTip::add( mPrevWeek, i18n("Previous Week") ); 91 QToolTip::add( mPrevWeek, i18n("Previous Week") );
92 92
93 // Create forward navigation buttons 93 // Create forward navigation buttons
94 mNextWeek = new QPushButton( mCtrlFrame ); 94 mNextWeek = new QPushButton( mCtrlFrame );
95 mNextWeek->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); 95 mNextWeek->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") );
96 QToolTip::add( mNextWeek, i18n("Next Week") ); 96 QToolTip::add( mNextWeek, i18n("Next Week") );
97 97
98 mNextYear = new QPushButton( mCtrlFrame ); 98 mNextYear = new QPushButton( mCtrlFrame );
99 mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); 99 mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") );
100 QToolTip::add( mNextYear, i18n("Next Year") ); 100 QToolTip::add( mNextYear, i18n("Next Year") );
101 mSelectMonth = new QPushButton( mCtrlFrame ); 101 mSelectMonth = new QPushButton( mCtrlFrame );
102 // Create month name label 102 // Create month name label
103 //selectMonth->setFont( tfont ); 103 //selectMonth->setFont( tfont );
104 // selectMonth->setAlignment( AlignCenter ); 104 // selectMonth->setAlignment( AlignCenter );
105 //mDateLabel = new QLabel( selectMonth ); 105 //mDateLabel = new QLabel( selectMonth );
106 //mDateLabel->setFont( tfont ); 106 //mDateLabel->setFont( tfont );
107 //mDateLabel->setAlignment( AlignCenter ); 107 //mDateLabel->setAlignment( AlignCenter );
108 if ( QString ( name ) == QString("useBigPixmaps") ) { 108 if ( QString ( name ) == QString("useBigPixmaps") ) {
109 mNextMonth->setFlat( true); 109 mNextMonth->setFlat( true);
110 mNextWeek->setFlat( true); 110 mNextWeek->setFlat( true);
111 mNextYear->setFlat( true); 111 mNextYear->setFlat( true);
112 mSelectMonth->setFlat( true); 112 mSelectMonth->setFlat( true);
113 mPrevYear->setFlat( true); 113 mPrevYear->setFlat( true);
114 mPrevMonth->setFlat( true); 114 mPrevMonth->setFlat( true);
115 mPrevWeek->setFlat( true); 115 mPrevWeek->setFlat( true);
116 } else { 116 } else {
117 mPrevWeek->hide(); 117 mPrevWeek->hide();
118 mNextWeek->hide(); 118 mNextWeek->hide();
119 } 119 }
120 120
121 resetFont( font() ); 121 resetFont( font() );
122 122
123 123
124 // set up control frame layout 124 // set up control frame layout
125 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); 125 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 );
126 ctrlLayout->addWidget( mPrevYear, 3 ); 126 ctrlLayout->addWidget( mPrevYear, 3 );
127 ctrlLayout->addWidget( mPrevMonth, 3 ); 127 ctrlLayout->addWidget( mPrevMonth, 3 );
128 ctrlLayout->addWidget( mPrevWeek, 3 ); 128 ctrlLayout->addWidget( mPrevWeek, 3 );
129 //ctrlLayout->addStretch( 1 ); 129 //ctrlLayout->addStretch( 1 );
130 // ctrlLayout->addSpacing( 1 ); 130 // ctrlLayout->addSpacing( 1 );
131 // ctrlLayout->addWidget( mDateLabel ); 131 // ctrlLayout->addWidget( mDateLabel );
132 ctrlLayout->addWidget( mSelectMonth ); 132 ctrlLayout->addWidget( mSelectMonth );
133 // ctrlLayout->addSpacing( 1 ); 133 // ctrlLayout->addSpacing( 1 );
134 // ctrlLayout->addStretch( 1 ); 134 // ctrlLayout->addStretch( 1 );
135 ctrlLayout->addWidget( mNextWeek, 3 ); 135 ctrlLayout->addWidget( mNextWeek, 3 );
136 ctrlLayout->addWidget( mNextMonth, 3 ); 136 ctrlLayout->addWidget( mNextMonth, 3 );
137 ctrlLayout->addWidget( mNextYear, 3 ); 137 ctrlLayout->addWidget( mNextYear, 3 );
138 138
139 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); 139 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
140 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); 140 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
141 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); 141 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
142 connect( mPrevWeek, SIGNAL( clicked() ), SIGNAL( goPrevWeek() ) ); 142 connect( mPrevWeek, SIGNAL( clicked() ), SIGNAL( goPrevWeek() ) );
143 connect( mNextWeek, SIGNAL( clicked() ), SIGNAL( goNextWeek() ) ); 143 connect( mNextWeek, SIGNAL( clicked() ), SIGNAL( goNextWeek() ) );
144 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); 144 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
145 connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); 145 connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) );
146 mPrevYear->setFocusPolicy(NoFocus); 146 mPrevYear->setFocusPolicy(NoFocus);
147 mPrevMonth->setFocusPolicy(NoFocus); 147 mPrevMonth->setFocusPolicy(NoFocus);
148 mNextMonth->setFocusPolicy(NoFocus); 148 mNextMonth->setFocusPolicy(NoFocus);
149 mPrevWeek->setFocusPolicy(NoFocus); 149 mPrevWeek->setFocusPolicy(NoFocus);
150 mNextWeek->setFocusPolicy(NoFocus); 150 mNextWeek->setFocusPolicy(NoFocus);
151 mNextYear->setFocusPolicy(NoFocus); 151 mNextYear->setFocusPolicy(NoFocus);
152 mSelectMonth->setFocusPolicy(NoFocus); 152 mSelectMonth->setFocusPolicy(NoFocus);
153 setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); 153 setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) );
154 154
155} 155}
156 156
157NavigatorBar::~NavigatorBar() 157NavigatorBar::~NavigatorBar()
158{ 158{
159} 159}
160QSize NavigatorBar::sizeHint() const 160QSize NavigatorBar::sizeHint() const
161{ 161{
162 int wid = mCurrentMinWid ; 162 int wid = mCurrentMinWid ;
163 if ( mPrevYear->isVisible() ) 163 if ( mPrevYear->isVisible() )
164 wid += mCurrentButtonMinWid; 164 wid += mCurrentButtonMinWid;
165 if ( mPrevMonth->isVisible() ) 165 if ( mPrevMonth->isVisible() )
166 wid += mCurrentButtonMinWid; 166 wid += mCurrentButtonMinWid;
167 if ( mPrevWeek->isVisible() ) 167 if ( mPrevWeek->isVisible() )
168 wid += mCurrentButtonMinWid; 168 wid += mCurrentButtonMinWid;
169 if ( mNextMonth->isVisible() ) 169 if ( mNextMonth->isVisible() )
170 wid += mCurrentButtonMinWid; 170 wid += mCurrentButtonMinWid;
171 if ( mNextWeek->isVisible() ) 171 if ( mNextWeek->isVisible() )
172 wid += mCurrentButtonMinWid; 172 wid += mCurrentButtonMinWid;
173 if ( mNextYear->isVisible() ) 173 if ( mNextYear->isVisible() )
174 wid += mCurrentButtonMinWid; 174 wid += mCurrentButtonMinWid;
175 //qDebug("ret %d %d ", wid, mCurrentHei); 175 //qDebug("ret %d %d ", wid, mCurrentHei);
176 return QSize ( wid, mCurrentHei ); 176 return QSize ( wid, mCurrentHei );
177} 177}
178QSize NavigatorBar::sizeHintTwoButtons() const 178QSize NavigatorBar::sizeHintTwoButtons( int butNum ) const
179{ 179{
180 return QSize ( mCurrentMinWid + 2 * mCurrentButtonMinWid , mCurrentHei ); 180 return QSize ( mCurrentMinWid + butNum * mCurrentButtonMinWid , mCurrentHei );
181} 181}
182void NavigatorBar::resetFont ( QFont fo ) 182void NavigatorBar::resetFont ( QFont fo )
183{ 183{
184 184
185 QFont tfont = fo; 185 QFont tfont = fo;
186 if ( QApplication::desktop()->width() >= 480 ) 186 if ( QApplication::desktop()->width() >= 480 )
187 tfont.setPointSize(tfont.pointSize()+2); 187 tfont.setPointSize(tfont.pointSize()+2);
188 tfont.setBold(true); 188 tfont.setBold(true);
189 189
190 mSelectMonth->setFont( tfont ); 190 mSelectMonth->setFont( tfont );
191 // Set minimum width to width of widest month name label 191 // Set minimum width to width of widest month name label
192 int i; 192 int i;
193 int maxwidth = 0; 193 int maxwidth = 0;
194 QFontMetrics fm ( mSelectMonth->font() ); 194 QFontMetrics fm ( mSelectMonth->font() );
195 int width = fm.width("September '00" ); 195 int width = fm.width("September '00" );
196 maxwidth = width+2; 196 maxwidth = width+2;
197 int size = fm.height()+2; 197 int size = fm.height()+2;
198 if ( QApplication::desktop()->width() >= 480 ) { 198 if ( QApplication::desktop()->width() >= 480 ) {
199 size += 6; 199 size += 6;
200 maxwidth+= 6; 200 maxwidth+= 6;
201 } 201 }
202 mSelectMonth->setMinimumWidth( maxwidth ); 202 mSelectMonth->setMinimumWidth( maxwidth );
203 mSelectMonth->setFixedHeight( size ); 203 mSelectMonth->setFixedHeight( size );
204 mPrevYear->setFixedHeight( size ); 204 mPrevYear->setFixedHeight( size );
205 mPrevMonth->setFixedHeight( size ); 205 mPrevMonth->setFixedHeight( size );
206 mPrevWeek->setFixedHeight( size ); 206 mPrevWeek->setFixedHeight( size );
207 mNextMonth->setFixedHeight( size ); 207 mNextMonth->setFixedHeight( size );
208 mNextWeek->setFixedHeight( size ); 208 mNextWeek->setFixedHeight( size );
209 mNextYear->setFixedHeight ( size ); 209 mNextYear->setFixedHeight ( size );
210 mCurrentHei = size +2; 210 mCurrentHei = size +2;
211 mCurrentMinWid = maxwidth+2; 211 mCurrentMinWid = maxwidth+2;
212 mCurrentButtonMinWid = mPrevYear->sizeHint().width()+2; 212 mCurrentButtonMinWid = mPrevYear->sizeHint().width()+2;
213} 213}
214 214
215void NavigatorBar::showButtons( bool left, bool right ) 215void NavigatorBar::showButtons( bool left, bool right )
216{ 216{
217 if ( left ) { 217 if ( left ) {
218 mPrevYear->show(); 218 mPrevYear->show();
219 mPrevMonth->show(); 219 mPrevMonth->show();
220 } else { 220 } else {
221 mPrevYear->hide(); 221 mPrevYear->hide();
222 mPrevMonth->hide(); 222 mPrevMonth->hide();
223 } 223 }
224 224
225 if ( right ) { 225 if ( right ) {
226 mNextYear->show(); 226 mNextYear->show();
227 mNextMonth->show(); 227 mNextMonth->show();
228 } else { 228 } else {
229 mNextYear->hide(); 229 mNextYear->hide();
230 mNextMonth->hide(); 230 mNextMonth->hide();
231 } 231 }
232 if ( !left && !right ) { 232 if ( !left && !right ) {
233 //mSelectMonth->setMaximumWidth( 1024 ); 233 //mSelectMonth->setMaximumWidth( 1024 );
234 mSelectMonth->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); 234 mSelectMonth->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) );
235 } 235 }
236} 236}
237 237
238void NavigatorBar::selectMonth() 238void NavigatorBar::selectMonth()
239{ 239{
240 240
241 int month; 241 int month;
242 KPopupFrame* popup = new KPopupFrame(this); 242 KPopupFrame* popup = new KPopupFrame(this);
243 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); 243 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
244 // ----- 244 // -----
245 picker->resize(picker->sizeHint()); 245 picker->resize(picker->sizeHint());
246 popup->setMainWidget(picker); 246 popup->setMainWidget(picker);
247 picker->setFocus(); 247 picker->setFocus();
248 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 248 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
249 if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) 249 if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height()))))
250 { 250 {
251 month = picker->getResult(); 251 month = picker->getResult();
252 emit monthSelected ( month ); 252 emit monthSelected ( month );
253 } else { 253 } else {
254 KNotifyClient::beep(); 254 KNotifyClient::beep();
255 } 255 }
256 delete popup; 256 delete popup;
257} 257}
258void NavigatorBar::selectDates( const KCal::DateList &dateList ) 258void NavigatorBar::selectDates( const KCal::DateList &dateList )
259{ 259{
260 if (dateList.count() > 0) { 260 if (dateList.count() > 0) {
261 QDate date = dateList.first(); 261 QDate date = dateList.first();
262 262
263 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); 263 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
264 264
265 // compute the label at the top of the navigator 265 // compute the label at the top of the navigator
266 QString dtstr = i18n(calSys->monthName( date )) + " '" + 266 QString dtstr = i18n(calSys->monthName( date )) + " '" +
267 QString::number( calSys->year( date ) ).right(2); 267 QString::number( calSys->year( date ) ).right(2);
268 268
269 mSelectMonth->setText( dtstr ); 269 mSelectMonth->setText( dtstr );
270 } 270 }
271} 271}
272 272
diff --git a/korganizer/navigatorbar.h b/korganizer/navigatorbar.h
index bf6d173..9ccef14 100644
--- a/korganizer/navigatorbar.h
+++ b/korganizer/navigatorbar.h
@@ -1,76 +1,76 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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 NAVIGATORBAR_H 24#ifndef NAVIGATORBAR_H
25#define NAVIGATORBAR_H 25#define NAVIGATORBAR_H
26 26
27#include <libkcal/incidencebase.h> 27#include <libkcal/incidencebase.h>
28 28
29#include <qwidget.h> 29#include <qwidget.h>
30 30
31class QPushButton; 31class QPushButton;
32class QFrame; 32class QFrame;
33class QLabel; 33class QLabel;
34 34
35class NavigatorBar: public QWidget 35class NavigatorBar: public QWidget
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 public: 38 public:
39 NavigatorBar( const QDate & date, QWidget *parent = 0, const char *name = 0 ); 39 NavigatorBar( const QDate & date, QWidget *parent = 0, const char *name = 0 );
40 ~NavigatorBar(); 40 ~NavigatorBar();
41 void showButtons( bool left, bool right ); 41 void showButtons( bool left, bool right );
42 void resetFont ( QFont fo ); 42 void resetFont ( QFont fo );
43 QSize sizeHint() const; 43 QSize sizeHint() const;
44 QSize sizeHintTwoButtons() const; 44 QSize sizeHintTwoButtons( int butNum = 2 ) const;
45 45
46 public slots: 46 public slots:
47 void selectDates( const KCal::DateList & ); 47 void selectDates( const KCal::DateList & );
48 void selectMonth(); 48 void selectMonth();
49 49
50 signals: 50 signals:
51 void goNextMonth(); 51 void goNextMonth();
52 void goPrevMonth(); 52 void goPrevMonth();
53 void goNextWeek(); 53 void goNextWeek();
54 void goPrevWeek(); 54 void goPrevWeek();
55 void goNextYear(); 55 void goNextYear();
56 void goPrevYear(); 56 void goPrevYear();
57 void monthSelected( int ); 57 void monthSelected( int );
58 58
59 private: 59 private:
60 int mCurrentHei; 60 int mCurrentHei;
61 int mCurrentMinWid; 61 int mCurrentMinWid;
62 int mCurrentButtonMinWid; 62 int mCurrentButtonMinWid;
63 QFrame *mCtrlFrame; 63 QFrame *mCtrlFrame;
64 64
65 QPushButton *mPrevYear; 65 QPushButton *mPrevYear;
66 QPushButton *mPrevMonth; 66 QPushButton *mPrevMonth;
67 QPushButton *mNextMonth; 67 QPushButton *mNextMonth;
68 QPushButton *mPrevWeek; 68 QPushButton *mPrevWeek;
69 QPushButton *mNextWeek; 69 QPushButton *mNextWeek;
70 QPushButton *mNextYear; 70 QPushButton *mNextYear;
71 QPushButton *mSelectMonth; 71 QPushButton *mSelectMonth;
72 72
73 //QLabel *mDateLabel; 73 //QLabel *mDateLabel;
74}; 74};
75 75
76#endif 76#endif