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