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