summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 19:26:13 (UTC)
committer zautrix <zautrix>2004-09-12 19:26:13 (UTC)
commit5b434dd78f71bcea5e6067fc8ae0faaaea313f9d (patch) (unidiff)
treeed532e602a3b503b72a46ea18d40e3a5dc97aa3f
parentbc4153a99e205f43d0144e2e910730dd1a14d402 (diff)
downloadkdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.zip
kdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.tar.gz
kdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.tar.bz2
phone fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp23
-rw-r--r--libkcal/alarm.cpp16
-rw-r--r--libkcal/alarm.h2
-rw-r--r--libkcal/phoneformat.cpp58
4 files changed, 63 insertions, 36 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index cfd9290..d5d31e2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,2789 +1,2802 @@
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 66
67#include <libkcal/vcaldrag.h> 67#include <libkcal/vcaldrag.h>
68#include <libkcal/icaldrag.h> 68#include <libkcal/icaldrag.h>
69#include <libkcal/icalformat.h> 69#include <libkcal/icalformat.h>
70#include <libkcal/vcalformat.h> 70#include <libkcal/vcalformat.h>
71#include <libkcal/scheduler.h> 71#include <libkcal/scheduler.h>
72#include <libkcal/calendarlocal.h> 72#include <libkcal/calendarlocal.h>
73#include <libkcal/journal.h> 73#include <libkcal/journal.h>
74#include <libkcal/calfilter.h> 74#include <libkcal/calfilter.h>
75#include <libkcal/attendee.h> 75#include <libkcal/attendee.h>
76#include <libkcal/dndfactory.h> 76#include <libkcal/dndfactory.h>
77#include <libkcal/freebusy.h> 77#include <libkcal/freebusy.h>
78#include <libkcal/filestorage.h> 78#include <libkcal/filestorage.h>
79#include <libkcal/calendarresources.h> 79#include <libkcal/calendarresources.h>
80#include <libkcal/qtopiaformat.h> 80#include <libkcal/qtopiaformat.h>
81#include "../kalarmd/alarmdialog.h" 81#include "../kalarmd/alarmdialog.h"
82 82
83#ifndef DESKTOP_VERSION 83#ifndef DESKTOP_VERSION
84#include <libkcal/sharpformat.h> 84#include <libkcal/sharpformat.h>
85#endif 85#endif
86#include <libkcal/phoneformat.h> 86#include <libkcal/phoneformat.h>
87#ifndef KORG_NOMAIL 87#ifndef KORG_NOMAIL
88#include "komailclient.h" 88#include "komailclient.h"
89#endif 89#endif
90#ifndef KORG_NOPRINTER 90#ifndef KORG_NOPRINTER
91#include "calprinter.h" 91#include "calprinter.h"
92#endif 92#endif
93#ifndef KORG_NOPLUGINS 93#ifndef KORG_NOPLUGINS
94#include "kocore.h" 94#include "kocore.h"
95#endif 95#endif
96#include "koeventeditor.h" 96#include "koeventeditor.h"
97#include "kotodoeditor.h" 97#include "kotodoeditor.h"
98#include "koprefs.h" 98#include "koprefs.h"
99#include "koeventviewerdialog.h" 99#include "koeventviewerdialog.h"
100#include "publishdialog.h" 100#include "publishdialog.h"
101#include "kofilterview.h" 101#include "kofilterview.h"
102#include "koglobals.h" 102#include "koglobals.h"
103#include "koviewmanager.h" 103#include "koviewmanager.h"
104#include "koagendaview.h" 104#include "koagendaview.h"
105#include "kodialogmanager.h" 105#include "kodialogmanager.h"
106#include "outgoingdialog.h" 106#include "outgoingdialog.h"
107#include "incomingdialog.h" 107#include "incomingdialog.h"
108#include "statusdialog.h" 108#include "statusdialog.h"
109#include "kdatenavigator.h" 109#include "kdatenavigator.h"
110#include "kotodoview.h" 110#include "kotodoview.h"
111#include "datenavigator.h" 111#include "datenavigator.h"
112#include "resourceview.h" 112#include "resourceview.h"
113#include "navigatorbar.h" 113#include "navigatorbar.h"
114#include "searchdialog.h" 114#include "searchdialog.h"
115#include "mainwindow.h" 115#include "mainwindow.h"
116 116
117#include "calendarview.h" 117#include "calendarview.h"
118#ifndef DESKTOP_VERSION 118#ifndef DESKTOP_VERSION
119#include <qtopia/alarmserver.h> 119#include <qtopia/alarmserver.h>
120#endif 120#endif
121#ifndef _WIN32_ 121#ifndef _WIN32_
122#include <stdlib.h> 122#include <stdlib.h>
123#include <stdio.h> 123#include <stdio.h>
124#include <unistd.h> 124#include <unistd.h>
125#else 125#else
126#include <qprocess.h> 126#include <qprocess.h>
127#endif 127#endif
128using namespace KOrg; 128using namespace KOrg;
129using namespace KCal; 129using namespace KCal;
130extern int globalFlagBlockAgenda; 130extern int globalFlagBlockAgenda;
131extern int globalFlagBlockStartup; 131extern int globalFlagBlockStartup;
132 132
133 133
134 134
135class KOBeamPrefs : public QDialog 135class KOBeamPrefs : public QDialog
136{ 136{
137 public: 137 public:
138 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 138 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
139 QDialog( parent, name, true ) 139 QDialog( parent, name, true )
140 { 140 {
141 setCaption( i18n("Beam Options") ); 141 setCaption( i18n("Beam Options") );
142 QVBoxLayout* lay = new QVBoxLayout( this ); 142 QVBoxLayout* lay = new QVBoxLayout( this );
143 lay->setSpacing( 3 ); 143 lay->setSpacing( 3 );
144 lay->setMargin( 3 ); 144 lay->setMargin( 3 );
145 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 145 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
146 lay->addWidget( format ); 146 lay->addWidget( format );
147 format->setExclusive ( true ) ; 147 format->setExclusive ( true ) ;
148 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 148 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
149 lay->addWidget( time ); time->setExclusive ( true ) ; 149 lay->addWidget( time ); time->setExclusive ( true ) ;
150 vcal = new QRadioButton(" vCalendar ", format ); 150 vcal = new QRadioButton(" vCalendar ", format );
151 ical = new QRadioButton(" iCalendar ", format ); 151 ical = new QRadioButton(" iCalendar ", format );
152 vcal->setChecked( true ); 152 vcal->setChecked( true );
153 tz = new QRadioButton(i18n(" With timezone "), time ); 153 tz = new QRadioButton(i18n(" With timezone "), time );
154 local = new QRadioButton(i18n(" Local time "), time ); 154 local = new QRadioButton(i18n(" Local time "), time );
155 tz->setChecked( true ); 155 tz->setChecked( true );
156 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 156 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
157 lay->addWidget( ok ); 157 lay->addWidget( ok );
158 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 158 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
159 lay->addWidget( cancel ); 159 lay->addWidget( cancel );
160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
161 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 161 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
162 resize( 200, 200 ); 162 resize( 200, 200 );
163 } 163 }
164 164
165 bool beamVcal() { return vcal->isChecked(); } 165 bool beamVcal() { return vcal->isChecked(); }
166 bool beamLocal() { return local->isChecked(); } 166 bool beamLocal() { return local->isChecked(); }
167private: 167private:
168 QRadioButton* vcal, *ical, *local, *tz; 168 QRadioButton* vcal, *ical, *local, *tz;
169}; 169};
170class KOCatPrefs : public QDialog 170class KOCatPrefs : public QDialog
171{ 171{
172 public: 172 public:
173 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 173 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
174 QDialog( parent, name, true ) 174 QDialog( parent, name, true )
175 { 175 {
176 setCaption( i18n("Manage new Categories") ); 176 setCaption( i18n("Manage new Categories") );
177 QVBoxLayout* lay = new QVBoxLayout( this ); 177 QVBoxLayout* lay = new QVBoxLayout( this );
178 lay->setSpacing( 3 ); 178 lay->setSpacing( 3 );
179 lay->setMargin( 3 ); 179 lay->setMargin( 3 );
180 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 ); 180 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 );
181 lay->addWidget( lab ); 181 lay->addWidget( lab );
182 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 182 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
183 lay->addWidget( format ); 183 lay->addWidget( format );
184 format->setExclusive ( true ) ; 184 format->setExclusive ( true ) ;
185 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 185 addCatBut = new QRadioButton(i18n("Add to category list"), format );
186 new QRadioButton(i18n("Remove from Events/Todos"), format ); 186 new QRadioButton(i18n("Remove from Events/Todos"), format );
187 addCatBut->setChecked( true ); 187 addCatBut->setChecked( true );
188 QPushButton * ok = new QPushButton( i18n("OK"), this ); 188 QPushButton * ok = new QPushButton( i18n("OK"), this );
189 lay->addWidget( ok ); 189 lay->addWidget( ok );
190 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 190 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
191 lay->addWidget( cancel ); 191 lay->addWidget( cancel );
192 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 192 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
193 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 193 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
194 resize( 200, 200 ); 194 resize( 200, 200 );
195 } 195 }
196 196
197 bool addCat() { return addCatBut->isChecked(); } 197 bool addCat() { return addCatBut->isChecked(); }
198private: 198private:
199 QRadioButton* addCatBut; 199 QRadioButton* addCatBut;
200}; 200};
201 201
202 202
203 203
204CalendarView::CalendarView( CalendarResources *calendar, 204CalendarView::CalendarView( CalendarResources *calendar,
205 QWidget *parent, const char *name ) 205 QWidget *parent, const char *name )
206 : CalendarViewBase( parent, name ), 206 : CalendarViewBase( parent, name ),
207 mCalendar( calendar ), 207 mCalendar( calendar ),
208 mResourceManager( calendar->resourceManager() ) 208 mResourceManager( calendar->resourceManager() )
209{ 209{
210 210
211 mEventEditor = 0; 211 mEventEditor = 0;
212 mTodoEditor = 0; 212 mTodoEditor = 0;
213 213
214 init(); 214 init();
215} 215}
216 216
217CalendarView::CalendarView( Calendar *calendar, 217CalendarView::CalendarView( Calendar *calendar,
218 QWidget *parent, const char *name ) 218 QWidget *parent, const char *name )
219 : CalendarViewBase( parent, name ), 219 : CalendarViewBase( parent, name ),
220 mCalendar( calendar ), 220 mCalendar( calendar ),
221 mResourceManager( 0 ) 221 mResourceManager( 0 )
222{ 222{
223 223
224 mEventEditor = 0; 224 mEventEditor = 0;
225 mTodoEditor = 0; 225 mTodoEditor = 0;
226 init();} 226 init();}
227 227
228void CalendarView::init() 228void CalendarView::init()
229{ 229{
230 beamDialog = new KOBeamPrefs(); 230 beamDialog = new KOBeamPrefs();
231 mDatePickerMode = 0; 231 mDatePickerMode = 0;
232 mCurrentSyncDevice = ""; 232 mCurrentSyncDevice = "";
233 writeLocale(); 233 writeLocale();
234 mViewManager = new KOViewManager( this ); 234 mViewManager = new KOViewManager( this );
235 mDialogManager = new KODialogManager( this ); 235 mDialogManager = new KODialogManager( this );
236 mEventViewerDialog = 0; 236 mEventViewerDialog = 0;
237 mModified = false; 237 mModified = false;
238 mReadOnly = false; 238 mReadOnly = false;
239 mSelectedIncidence = 0; 239 mSelectedIncidence = 0;
240 mCalPrinter = 0; 240 mCalPrinter = 0;
241 mFilters.setAutoDelete(true); 241 mFilters.setAutoDelete(true);
242 242
243 mCalendar->registerObserver( this ); 243 mCalendar->registerObserver( this );
244 // TODO: Make sure that view is updated, when calendar is changed. 244 // TODO: Make sure that view is updated, when calendar is changed.
245 245
246 mStorage = new FileStorage( mCalendar ); 246 mStorage = new FileStorage( mCalendar );
247 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 247 mNavigator = new DateNavigator( this, "datevav", mViewManager );
248 248
249 QBoxLayout *topLayout = (QBoxLayout*)layout(); 249 QBoxLayout *topLayout = (QBoxLayout*)layout();
250#ifndef KORG_NOSPLITTER 250#ifndef KORG_NOSPLITTER
251 // create the main layout frames. 251 // create the main layout frames.
252 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 252 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
253 topLayout->addWidget(mPanner); 253 topLayout->addWidget(mPanner);
254 254
255 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 255 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
256 "CalendarView::LeftFrame"); 256 "CalendarView::LeftFrame");
257 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 257 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
258 258
259 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 259 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
260 "CalendarView::DateNavigator", QDate::currentDate() ); 260 "CalendarView::DateNavigator", QDate::currentDate() );
261 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 261 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
262 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 262 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
263 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 263 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
264 264
265#ifdef KORG_NORESOURCEVIEW 265#ifdef KORG_NORESOURCEVIEW
266 mResourceView = 0; 266 mResourceView = 0;
267#else 267#else
268 if ( mResourceManager ) { 268 if ( mResourceManager ) {
269 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 269 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
270 mResourceView->updateView(); 270 mResourceView->updateView();
271 connect( mResourceView, SIGNAL( resourcesChanged() ), 271 connect( mResourceView, SIGNAL( resourcesChanged() ),
272 SLOT( updateView() ) ); 272 SLOT( updateView() ) );
273 } else { 273 } else {
274 mResourceView = 0; 274 mResourceView = 0;
275 } 275 }
276#endif 276#endif
277 QWidget *rightBox = new QWidget( mPanner ); 277 QWidget *rightBox = new QWidget( mPanner );
278 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 278 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
279 279
280 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 280 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
281 rightLayout->addWidget( mNavigatorBar ); 281 rightLayout->addWidget( mNavigatorBar );
282 282
283 mRightFrame = new QWidgetStack( rightBox ); 283 mRightFrame = new QWidgetStack( rightBox );
284 rightLayout->addWidget( mRightFrame, 1 ); 284 rightLayout->addWidget( mRightFrame, 1 );
285 285
286 mLeftFrame = mLeftSplitter; 286 mLeftFrame = mLeftSplitter;
287#else 287#else
288 QWidget *mainBox = new QWidget( this ); 288 QWidget *mainBox = new QWidget( this );
289 QWidget *leftFrame = new QWidget( mainBox ); 289 QWidget *leftFrame = new QWidget( mainBox );
290 290
291 QBoxLayout * mainBoxLayout; 291 QBoxLayout * mainBoxLayout;
292 QBoxLayout * leftFrameLayout; 292 QBoxLayout * leftFrameLayout;
293 if ( KOPrefs::instance()->mVerticalScreen ) { 293 if ( KOPrefs::instance()->mVerticalScreen ) {
294 mainBoxLayout = new QVBoxLayout(mainBox); 294 mainBoxLayout = new QVBoxLayout(mainBox);
295 leftFrameLayout = new QHBoxLayout(leftFrame ); 295 leftFrameLayout = new QHBoxLayout(leftFrame );
296 } else { 296 } else {
297 mainBoxLayout = new QHBoxLayout(mainBox); 297 mainBoxLayout = new QHBoxLayout(mainBox);
298 leftFrameLayout = new QVBoxLayout(leftFrame ); 298 leftFrameLayout = new QVBoxLayout(leftFrame );
299 } 299 }
300 topLayout->addWidget( mainBox ); 300 topLayout->addWidget( mainBox );
301 mainBoxLayout->addWidget (leftFrame); 301 mainBoxLayout->addWidget (leftFrame);
302 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 302 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
303 "CalendarView::DateNavigator", QDate::currentDate()); 303 "CalendarView::DateNavigator", QDate::currentDate());
304 // mDateNavigator->blockSignals( true ); 304 // mDateNavigator->blockSignals( true );
305 leftFrameLayout->addWidget( mDateNavigator ); 305 leftFrameLayout->addWidget( mDateNavigator );
306 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 306 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
307 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); 307 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist");
308 308
309 if ( QApplication::desktop()->width() < 480 ) { 309 if ( QApplication::desktop()->width() < 480 ) {
310 leftFrameLayout->addWidget(mFilterView); 310 leftFrameLayout->addWidget(mFilterView);
311 leftFrameLayout->addWidget(mTodoList, 2 ); 311 leftFrameLayout->addWidget(mTodoList, 2 );
312 312
313 } else { 313 } else {
314 leftFrameLayout->addWidget(mTodoList,2 ); 314 leftFrameLayout->addWidget(mTodoList,2 );
315 leftFrameLayout->addWidget(mFilterView ); 315 leftFrameLayout->addWidget(mFilterView );
316 } 316 }
317 mFilterView->hide(); 317 mFilterView->hide();
318 QWidget *rightBox = new QWidget( mainBox ); 318 QWidget *rightBox = new QWidget( mainBox );
319 mainBoxLayout->addWidget ( rightBox, 10 ); 319 mainBoxLayout->addWidget ( rightBox, 10 );
320 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 320 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
321 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 321 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
322 mRightFrame = new QWidgetStack( rightBox ); 322 mRightFrame = new QWidgetStack( rightBox );
323 rightLayout->addWidget( mNavigatorBar ); 323 rightLayout->addWidget( mNavigatorBar );
324 rightLayout->addWidget( mRightFrame, 10 ); 324 rightLayout->addWidget( mRightFrame, 10 );
325 325
326 mLeftFrame = leftFrame; 326 mLeftFrame = leftFrame;
327 if ( KOPrefs::instance()->mVerticalScreen ) { 327 if ( KOPrefs::instance()->mVerticalScreen ) {
328 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 328 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
329 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 329 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
330 } else { 330 } else {
331 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 331 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
332 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 332 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
333 } 333 }
334 334
335 //qDebug("Calendarview Size %d %d ", width(), height()); 335 //qDebug("Calendarview Size %d %d ", width(), height());
336#endif 336#endif
337 337
338 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 338 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
339 SLOT( showDates( const KCal::DateList & ) ) ); 339 SLOT( showDates( const KCal::DateList & ) ) );
340 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 340 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
341 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 341 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
342 342
343 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 343 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
344 mNavigator, SLOT( selectPreviousYear() ) ); 344 mNavigator, SLOT( selectPreviousYear() ) );
345 connect( mNavigatorBar, SIGNAL( goNextYear() ), 345 connect( mNavigatorBar, SIGNAL( goNextYear() ),
346 mNavigator, SLOT( selectNextYear() ) ); 346 mNavigator, SLOT( selectNextYear() ) );
347 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 347 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
348 mNavigator, SLOT( selectPreviousMonth() ) ); 348 mNavigator, SLOT( selectPreviousMonth() ) );
349 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 349 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
350 mNavigator, SLOT( selectNextMonth() ) ); 350 mNavigator, SLOT( selectNextMonth() ) );
351 351
352 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 352 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
353 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 353 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
354 354
355 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 355 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
356 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 356 mNavigator, SLOT( selectWeek( const QDate & ) ) );
357 357
358 connect( mDateNavigator, SIGNAL( goPrevYear() ), 358 connect( mDateNavigator, SIGNAL( goPrevYear() ),
359 mNavigator, SLOT( selectPreviousYear() ) ); 359 mNavigator, SLOT( selectPreviousYear() ) );
360 connect( mDateNavigator, SIGNAL( goNextYear() ), 360 connect( mDateNavigator, SIGNAL( goNextYear() ),
361 mNavigator, SLOT( selectNextYear() ) ); 361 mNavigator, SLOT( selectNextYear() ) );
362 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 362 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
363 mNavigator, SLOT( selectPreviousMonth() ) ); 363 mNavigator, SLOT( selectPreviousMonth() ) );
364 connect( mDateNavigator, SIGNAL( goNextMonth() ), 364 connect( mDateNavigator, SIGNAL( goNextMonth() ),
365 mNavigator, SLOT( selectNextMonth() ) ); 365 mNavigator, SLOT( selectNextMonth() ) );
366 366
367 connect( mDateNavigator, SIGNAL( goPrevious() ), 367 connect( mDateNavigator, SIGNAL( goPrevious() ),
368 mNavigator, SLOT( selectPrevious() ) ); 368 mNavigator, SLOT( selectPrevious() ) );
369 connect( mDateNavigator, SIGNAL( goNext() ), 369 connect( mDateNavigator, SIGNAL( goNext() ),
370 mNavigator, SLOT( selectNext() ) ); 370 mNavigator, SLOT( selectNext() ) );
371 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 371 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
372 mNavigator, SLOT( slotMonthSelect( int ) ) ); 372 mNavigator, SLOT( slotMonthSelect( int ) ) );
373 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 373 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
374 mNavigator, SLOT( slotMonthSelect( int ) ) ); 374 mNavigator, SLOT( slotMonthSelect( int ) ) );
375 375
376 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 376 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
377 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 377 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
378 378
379 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 379 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
380 SLOT( eventAdded( Event *) ) ); 380 SLOT( eventAdded( Event *) ) );
381 381
382 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 382 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
383 383
384 connect( this, SIGNAL( configChanged() ), 384 connect( this, SIGNAL( configChanged() ),
385 mDateNavigator, SLOT( updateConfig() ) ); 385 mDateNavigator, SLOT( updateConfig() ) );
386 386
387 connect( mTodoList, SIGNAL( newTodoSignal() ), 387 connect( mTodoList, SIGNAL( newTodoSignal() ),
388 SLOT( newTodo() ) ); 388 SLOT( newTodo() ) );
389 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 389 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
390 SLOT( newSubTodo( Todo * ) ) ); 390 SLOT( newSubTodo( Todo * ) ) );
391 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 391 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
392 SLOT( editTodo( Todo * ) ) ); 392 SLOT( editTodo( Todo * ) ) );
393 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 393 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
394 SLOT( showTodo( Todo *) ) ); 394 SLOT( showTodo( Todo *) ) );
395 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
396 SLOT( deleteTodo( Todo *) ) ); 396 SLOT( deleteTodo( Todo *) ) );
397 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 397 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
398 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 398 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
399 SLOT( purgeCompleted() ) ); 399 SLOT( purgeCompleted() ) );
400 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 400 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
401 SIGNAL( todoModified( Todo *, int ) ) ); 401 SIGNAL( todoModified( Todo *, int ) ) );
402 402
403 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 403 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
404 this, SLOT ( cloneIncidence( Incidence * ) ) ); 404 this, SLOT ( cloneIncidence( Incidence * ) ) );
405 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 405 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
406 this, SLOT (cancelIncidence( Incidence * ) ) ); 406 this, SLOT (cancelIncidence( Incidence * ) ) );
407 407
408 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 408 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
409 this, SLOT ( moveIncidence( Incidence * ) ) ); 409 this, SLOT ( moveIncidence( Incidence * ) ) );
410 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 410 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
411 this, SLOT ( beamIncidence( Incidence * ) ) ); 411 this, SLOT ( beamIncidence( Incidence * ) ) );
412 412
413 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 413 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
414 this, SLOT ( todo_unsub( Todo * ) ) ); 414 this, SLOT ( todo_unsub( Todo * ) ) );
415 415
416 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 416 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
417 SLOT( updateTodo( Todo *, int ) ) ); 417 SLOT( updateTodo( Todo *, int ) ) );
418 connect( this, SIGNAL( todoModified( Todo *, int )), this, 418 connect( this, SIGNAL( todoModified( Todo *, int )), this,
419 SLOT( changeTodoDisplay( Todo *, int ) ) ); 419 SLOT( changeTodoDisplay( Todo *, int ) ) );
420 420
421 421
422 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 422 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
423 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 423 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
424 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 424 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
425 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 425 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
426 426
427 427
428 428
429 429
430 430
431 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 431 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
432 SLOT(checkClipboard())); 432 SLOT(checkClipboard()));
433 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 433 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
434 SLOT( processTodoListSelection( Incidence * ) ) ); 434 SLOT( processTodoListSelection( Incidence * ) ) );
435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
436 436
437 // kdDebug() << "CalendarView::CalendarView() done" << endl; 437 // kdDebug() << "CalendarView::CalendarView() done" << endl;
438 438
439 mDateFrame = new QVBox(0,0,WType_Popup); 439 mDateFrame = new QVBox(0,0,WType_Popup);
440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
442 mDateFrame->setLineWidth(3); 442 mDateFrame->setLineWidth(3);
443 mDateFrame->hide(); 443 mDateFrame->hide();
444 mDateFrame->setCaption( i18n( "Pick a date to display")); 444 mDateFrame->setCaption( i18n( "Pick a date to display"));
445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
446 446
447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
448 448
449 mEventEditor = mDialogManager->getEventEditor(); 449 mEventEditor = mDialogManager->getEventEditor();
450 mTodoEditor = mDialogManager->getTodoEditor(); 450 mTodoEditor = mDialogManager->getTodoEditor();
451 451
452 mFlagEditDescription = false; 452 mFlagEditDescription = false;
453 453
454 mSuspendTimer = new QTimer( this ); 454 mSuspendTimer = new QTimer( this );
455 mAlarmTimer = new QTimer( this ); 455 mAlarmTimer = new QTimer( this );
456 mRecheckAlarmTimer = new QTimer( this ); 456 mRecheckAlarmTimer = new QTimer( this );
457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
460 mAlarmDialog = new AlarmDialog( this ); 460 mAlarmDialog = new AlarmDialog( this );
461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
462 mAlarmDialog->setServerNotification( false ); 462 mAlarmDialog->setServerNotification( false );
463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
464} 464}
465 465
466 466
467CalendarView::~CalendarView() 467CalendarView::~CalendarView()
468{ 468{
469 // kdDebug() << "~CalendarView()" << endl; 469 // kdDebug() << "~CalendarView()" << endl;
470 //qDebug("CalendarView::~CalendarView() "); 470 //qDebug("CalendarView::~CalendarView() ");
471 delete mDialogManager; 471 delete mDialogManager;
472 delete mViewManager; 472 delete mViewManager;
473 delete mStorage; 473 delete mStorage;
474 delete mDateFrame ; 474 delete mDateFrame ;
475 delete beamDialog; 475 delete beamDialog;
476 //kdDebug() << "~CalendarView() done" << endl; 476 //kdDebug() << "~CalendarView() done" << endl;
477} 477}
478void CalendarView::timerAlarm() 478void CalendarView::timerAlarm()
479{ 479{
480 //qDebug("CalendarView::timerAlarm() "); 480 //qDebug("CalendarView::timerAlarm() ");
481 computeAlarm(mAlarmNotification ); 481 computeAlarm(mAlarmNotification );
482} 482}
483 483
484void CalendarView::suspendAlarm() 484void CalendarView::suspendAlarm()
485{ 485{
486 //qDebug(" CalendarView::suspendAlarm() "); 486 //qDebug(" CalendarView::suspendAlarm() ");
487 computeAlarm(mSuspendAlarmNotification ); 487 computeAlarm(mSuspendAlarmNotification );
488 488
489} 489}
490 490
491void CalendarView::startAlarm( QString mess , QString filename) 491void CalendarView::startAlarm( QString mess , QString filename)
492{ 492{
493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
495 495
496} 496}
497 497
498void CalendarView::checkNextTimerAlarm() 498void CalendarView::checkNextTimerAlarm()
499{ 499{
500 mCalendar->checkAlarmForIncidence( 0, true ); 500 mCalendar->checkAlarmForIncidence( 0, true );
501} 501}
502 502
503void CalendarView::computeAlarm( QString msg ) 503void CalendarView::computeAlarm( QString msg )
504{ 504{
505 505
506 QString mess = msg; 506 QString mess = msg;
507 QString mAlarmMessage = mess.mid( 9 ); 507 QString mAlarmMessage = mess.mid( 9 );
508 QString filename = MainWindow::resourcePath(); 508 QString filename = MainWindow::resourcePath();
509 filename += "koalarm.wav"; 509 filename += "koalarm.wav";
510 QString tempfilename; 510 QString tempfilename;
511 if ( mess.left( 13 ) == "suspend_alarm") { 511 if ( mess.left( 13 ) == "suspend_alarm") {
512 bool error = false; 512 bool error = false;
513 int len = mess.mid( 13 ).find("+++"); 513 int len = mess.mid( 13 ).find("+++");
514 if ( len < 2 ) 514 if ( len < 2 )
515 error = true; 515 error = true;
516 else { 516 else {
517 tempfilename = mess.mid( 13, len ); 517 tempfilename = mess.mid( 13, len );
518 if ( !QFile::exists( tempfilename ) ) 518 if ( !QFile::exists( tempfilename ) )
519 error = true; 519 error = true;
520 } 520 }
521 if ( ! error ) { 521 if ( ! error ) {
522 filename = tempfilename; 522 filename = tempfilename;
523 } 523 }
524 mAlarmMessage = mess.mid( 13+len+3 ); 524 mAlarmMessage = mess.mid( 13+len+3 );
525 //qDebug("suspend file %s ",tempfilename.latin1() ); 525 //qDebug("suspend file %s ",tempfilename.latin1() );
526 startAlarm( mAlarmMessage, filename); 526 startAlarm( mAlarmMessage, filename);
527 return; 527 return;
528 } 528 }
529 if ( mess.left( 11 ) == "timer_alarm") { 529 if ( mess.left( 11 ) == "timer_alarm") {
530 //mTimerTime = 0; 530 //mTimerTime = 0;
531 startAlarm( mess.mid( 11 ), filename ); 531 startAlarm( mess.mid( 11 ), filename );
532 return; 532 return;
533 } 533 }
534 if ( mess.left( 10 ) == "proc_alarm") { 534 if ( mess.left( 10 ) == "proc_alarm") {
535 bool error = false; 535 bool error = false;
536 int len = mess.mid( 10 ).find("+++"); 536 int len = mess.mid( 10 ).find("+++");
537 if ( len < 2 ) 537 if ( len < 2 )
538 error = true; 538 error = true;
539 else { 539 else {
540 tempfilename = mess.mid( 10, len ); 540 tempfilename = mess.mid( 10, len );
541 if ( !QFile::exists( tempfilename ) ) 541 if ( !QFile::exists( tempfilename ) )
542 error = true; 542 error = true;
543 } 543 }
544 if ( error ) { 544 if ( error ) {
545 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 545 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
546 mAlarmMessage += mess.mid( 10+len+3+9 ); 546 mAlarmMessage += mess.mid( 10+len+3+9 );
547 } else { 547 } else {
548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
549 //qDebug("-----system command %s ",tempfilename.latin1() ); 549 //qDebug("-----system command %s ",tempfilename.latin1() );
550#ifndef _WIN32_ 550#ifndef _WIN32_
551 if ( vfork () == 0 ) { 551 if ( vfork () == 0 ) {
552 execl ( tempfilename.latin1(), 0 ); 552 execl ( tempfilename.latin1(), 0 );
553 return; 553 return;
554 } 554 }
555#else 555#else
556 QProcess* p = new QProcess(); 556 QProcess* p = new QProcess();
557 p->addArgument( tempfilename.latin1() ); 557 p->addArgument( tempfilename.latin1() );
558 p->start(); 558 p->start();
559 return; 559 return;
560#endif 560#endif
561 561
562 return; 562 return;
563 } 563 }
564 564
565 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 565 //qDebug("+++++++system command %s ",tempfilename.latin1() );
566 } 566 }
567 if ( mess.left( 11 ) == "audio_alarm") { 567 if ( mess.left( 11 ) == "audio_alarm") {
568 bool error = false; 568 bool error = false;
569 int len = mess.mid( 11 ).find("+++"); 569 int len = mess.mid( 11 ).find("+++");
570 if ( len < 2 ) 570 if ( len < 2 )
571 error = true; 571 error = true;
572 else { 572 else {
573 tempfilename = mess.mid( 11, len ); 573 tempfilename = mess.mid( 11, len );
574 if ( !QFile::exists( tempfilename ) ) 574 if ( !QFile::exists( tempfilename ) )
575 error = true; 575 error = true;
576 } 576 }
577 if ( ! error ) { 577 if ( ! error ) {
578 filename = tempfilename; 578 filename = tempfilename;
579 } 579 }
580 mAlarmMessage = mess.mid( 11+len+3+9 ); 580 mAlarmMessage = mess.mid( 11+len+3+9 );
581 //qDebug("audio file command %s ",tempfilename.latin1() ); 581 //qDebug("audio file command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 9 ) == "cal_alarm") { 583 if ( mess.left( 9 ) == "cal_alarm") {
584 mAlarmMessage = mess.mid( 9 ) ; 584 mAlarmMessage = mess.mid( 9 ) ;
585 } 585 }
586 586
587 startAlarm( mAlarmMessage, filename ); 587 startAlarm( mAlarmMessage, filename );
588 588
589 589
590} 590}
591 591
592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
593{ 593{
594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
595 595
596 mSuspendAlarmNotification = noti; 596 mSuspendAlarmNotification = noti;
597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
599 mSuspendTimer->start( ms , true ); 599 mSuspendTimer->start( ms , true );
600 600
601} 601}
602 602
603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
604{ 604{
605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
607#ifndef DESKTOP_VERSION 607#ifndef DESKTOP_VERSION
608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
609#endif 609#endif
610 return; 610 return;
611 } 611 }
612 int maxSec; 612 int maxSec;
613 //maxSec = 5; //testing only 613 //maxSec = 5; //testing only
614 maxSec = 86400+3600; // one day+1hour 614 maxSec = 86400+3600; // one day+1hour
615 mAlarmNotification = noti; 615 mAlarmNotification = noti;
616 int sec = QDateTime::currentDateTime().secsTo( qdt ); 616 int sec = QDateTime::currentDateTime().secsTo( qdt );
617 if ( sec > maxSec ) { 617 if ( sec > maxSec ) {
618 mRecheckAlarmTimer->start( maxSec * 1000 ); 618 mRecheckAlarmTimer->start( maxSec * 1000 );
619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
620 return; 620 return;
621 } else { 621 } else {
622 mRecheckAlarmTimer->stop(); 622 mRecheckAlarmTimer->stop();
623 } 623 }
624 //qDebug("Alarm timer started with secs: %d ", sec); 624 //qDebug("Alarm timer started with secs: %d ", sec);
625 mAlarmTimer->start( sec *1000 , true ); 625 mAlarmTimer->start( sec *1000 , true );
626 626
627} 627}
628// called by mRecheckAlarmTimer to get next alarm 628// called by mRecheckAlarmTimer to get next alarm
629// we need this, because a QTimer has only a max range of 25 days 629// we need this, because a QTimer has only a max range of 25 days
630void CalendarView::recheckTimerAlarm() 630void CalendarView::recheckTimerAlarm()
631{ 631{
632 mAlarmTimer->stop(); 632 mAlarmTimer->stop();
633 mRecheckAlarmTimer->stop(); 633 mRecheckAlarmTimer->stop();
634 mCalendar->checkAlarmForIncidence( 0, true ); 634 mCalendar->checkAlarmForIncidence( 0, true );
635} 635}
636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
637{ 637{
638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
640#ifndef DESKTOP_VERSION 640#ifndef DESKTOP_VERSION
641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
642#endif 642#endif
643 return; 643 return;
644 } 644 }
645 mAlarmTimer->stop(); 645 mAlarmTimer->stop();
646} 646}
647void CalendarView::selectWeekNum ( int num ) 647void CalendarView::selectWeekNum ( int num )
648{ 648{
649 dateNavigator()->selectWeek( num ); 649 dateNavigator()->selectWeek( num );
650 mViewManager->showWeekView(); 650 mViewManager->showWeekView();
651} 651}
652KOViewManager *CalendarView::viewManager() 652KOViewManager *CalendarView::viewManager()
653{ 653{
654 return mViewManager; 654 return mViewManager;
655} 655}
656 656
657KODialogManager *CalendarView::dialogManager() 657KODialogManager *CalendarView::dialogManager()
658{ 658{
659 return mDialogManager; 659 return mDialogManager;
660} 660}
661 661
662QDate CalendarView::startDate() 662QDate CalendarView::startDate()
663{ 663{
664 DateList dates = mNavigator->selectedDates(); 664 DateList dates = mNavigator->selectedDates();
665 665
666 return dates.first(); 666 return dates.first();
667} 667}
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 730 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 if ( remCh ) 732 if ( remCh )
733 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 733 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
734 locCh = ( local->lastModified() > mLastCalendarSync ); 734 locCh = ( local->lastModified() > mLastCalendarSync );
735 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 735 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
736 if ( !remCh && ! locCh ) { 736 if ( !remCh && ! locCh ) {
737 qDebug("both not changed "); 737 qDebug("both not changed ");
738 lastSync = local->lastModified().addDays(1); 738 lastSync = local->lastModified().addDays(1);
739 } else { 739 } else {
740 if ( locCh ) { 740 if ( locCh ) {
741 qDebug("loc changed %d", local->revision() ); 741 qDebug("loc changed %d", local->revision() );
742 lastSync = local->lastModified().addDays( -1 ); 742 lastSync = local->lastModified().addDays( -1 );
743 if ( !remCh ) 743 if ( !remCh )
744 remote->setLastModified( lastSync.addDays( -1 ) ); 744 remote->setLastModified( lastSync.addDays( -1 ) );
745 } else { 745 } else {
746 qDebug(" not loc changed "); 746 qDebug(" not loc changed ");
747 lastSync = local->lastModified().addDays( 1 ); 747 lastSync = local->lastModified().addDays( 1 );
748 if ( remCh ) 748 if ( remCh )
749 remote->setLastModified( lastSync.addDays( 1 ) ); 749 remote->setLastModified( lastSync.addDays( 1 ) );
750 750
751 } 751 }
752 } 752 }
753 full = true; 753 full = true;
754 if ( mode < SYNC_PREF_ASK ) 754 if ( mode < SYNC_PREF_ASK )
755 mode = SYNC_PREF_ASK; 755 mode = SYNC_PREF_ASK;
756 } else { 756 } else {
757 if ( local->lastModified() == remote->lastModified() ) 757 if ( local->lastModified() == remote->lastModified() )
758 if ( local->revision() == remote->revision() ) 758 if ( local->revision() == remote->revision() )
759 return 0; 759 return 0;
760 760
761 } 761 }
762 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 762 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
763 763
764 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 764 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
765 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 765 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
766 //full = true; //debug only 766 //full = true; //debug only
767 if ( full ) { 767 if ( full ) {
768 bool equ = false; 768 bool equ = false;
769 if ( local->type() == "Event" ) { 769 if ( local->type() == "Event" ) {
770 equ = (*((Event*) local) == *((Event*) remote)); 770 equ = (*((Event*) local) == *((Event*) remote));
771 } 771 }
772 else if ( local->type() =="Todo" ) 772 else if ( local->type() =="Todo" )
773 equ = (*((Todo*) local) == (*(Todo*) remote)); 773 equ = (*((Todo*) local) == (*(Todo*) remote));
774 else if ( local->type() =="Journal" ) 774 else if ( local->type() =="Journal" )
775 equ = (*((Journal*) local) == *((Journal*) remote)); 775 equ = (*((Journal*) local) == *((Journal*) remote));
776 if ( equ ) { 776 if ( equ ) {
777 //qDebug("equal "); 777 //qDebug("equal ");
778 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 778 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
779 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 779 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
780 } 780 }
781 if ( mode < SYNC_PREF_FORCE_LOCAL ) 781 if ( mode < SYNC_PREF_FORCE_LOCAL )
782 return 0; 782 return 0;
783 783
784 }//else //debug only 784 }//else //debug only
785 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 785 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
786 } 786 }
787 int result; 787 int result;
788 bool localIsNew; 788 bool localIsNew;
789 qDebug("mLastCalendarSync %s lastsync %s --- local %s remote %s ",mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 789 qDebug("mLastCalendarSync %s lastsync %s --- local %s remote %s ",mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
790 790
791 if ( full && mode < SYNC_PREF_NEWEST ) 791 if ( full && mode < SYNC_PREF_NEWEST )
792 mode = SYNC_PREF_ASK; 792 mode = SYNC_PREF_ASK;
793 793
794 switch( mode ) { 794 switch( mode ) {
795 case SYNC_PREF_LOCAL: 795 case SYNC_PREF_LOCAL:
796 if ( lastSync > remote->lastModified() ) 796 if ( lastSync > remote->lastModified() )
797 return 1; 797 return 1;
798 if ( lastSync > local->lastModified() ) 798 if ( lastSync > local->lastModified() )
799 return 2; 799 return 2;
800 return 1; 800 return 1;
801 break; 801 break;
802 case SYNC_PREF_REMOTE: 802 case SYNC_PREF_REMOTE:
803 if ( lastSync > remote->lastModified() ) 803 if ( lastSync > remote->lastModified() )
804 return 1; 804 return 1;
805 if ( lastSync > local->lastModified() ) 805 if ( lastSync > local->lastModified() )
806 return 2; 806 return 2;
807 return 2; 807 return 2;
808 break; 808 break;
809 case SYNC_PREF_NEWEST: 809 case SYNC_PREF_NEWEST:
810 if ( local->lastModified() > remote->lastModified() ) 810 if ( local->lastModified() > remote->lastModified() )
811 return 1; 811 return 1;
812 else 812 else
813 return 2; 813 return 2;
814 break; 814 break;
815 case SYNC_PREF_ASK: 815 case SYNC_PREF_ASK:
816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
817 if ( lastSync > remote->lastModified() ) 817 if ( lastSync > remote->lastModified() )
818 return 1; 818 return 1;
819 if ( lastSync > local->lastModified() ) 819 if ( lastSync > local->lastModified() )
820 return 2; 820 return 2;
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
822 localIsNew = local->lastModified() >= remote->lastModified(); 822 localIsNew = local->lastModified() >= remote->lastModified();
823 if ( localIsNew ) 823 if ( localIsNew )
824 getEventViewerDialog()->setColorMode( 1 ); 824 getEventViewerDialog()->setColorMode( 1 );
825 else 825 else
826 getEventViewerDialog()->setColorMode( 2 ); 826 getEventViewerDialog()->setColorMode( 2 );
827 getEventViewerDialog()->setIncidence(local); 827 getEventViewerDialog()->setIncidence(local);
828 if ( localIsNew ) 828 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 2 ); 829 getEventViewerDialog()->setColorMode( 2 );
830 else 830 else
831 getEventViewerDialog()->setColorMode( 1 ); 831 getEventViewerDialog()->setColorMode( 1 );
832 getEventViewerDialog()->addIncidence(remote); 832 getEventViewerDialog()->addIncidence(remote);
833 getEventViewerDialog()->setColorMode( 0 ); 833 getEventViewerDialog()->setColorMode( 0 );
834 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 834 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
835 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 835 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
836 getEventViewerDialog()->showMe(); 836 getEventViewerDialog()->showMe();
837 result = getEventViewerDialog()->executeS( localIsNew ); 837 result = getEventViewerDialog()->executeS( localIsNew );
838 return result; 838 return result;
839 839
840 break; 840 break;
841 case SYNC_PREF_FORCE_LOCAL: 841 case SYNC_PREF_FORCE_LOCAL:
842 return 1; 842 return 1;
843 break; 843 break;
844 case SYNC_PREF_FORCE_REMOTE: 844 case SYNC_PREF_FORCE_REMOTE:
845 return 2; 845 return 2;
846 break; 846 break;
847 847
848 default: 848 default:
849 // SYNC_PREF_TAKE_BOTH not implemented 849 // SYNC_PREF_TAKE_BOTH not implemented
850 break; 850 break;
851 } 851 }
852 return 0; 852 return 0;
853} 853}
854Event* CalendarView::getLastSyncEvent() 854Event* CalendarView::getLastSyncEvent()
855{ 855{
856 Event* lse; 856 Event* lse;
857 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 857 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
858 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 858 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
859 if (!lse) { 859 if (!lse) {
860 lse = new Event(); 860 lse = new Event();
861 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 861 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
862 QString sum = ""; 862 QString sum = "";
863 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 863 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
864 sum = "E: "; 864 sum = "E: ";
865 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 865 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
866 lse->setDtStart( mLastCalendarSync ); 866 lse->setDtStart( mLastCalendarSync );
867 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 867 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
868 lse->setCategories( i18n("SyncEvent") ); 868 lse->setCategories( i18n("SyncEvent") );
869 lse->setReadOnly( true ); 869 lse->setReadOnly( true );
870 mCalendar->addEvent( lse ); 870 mCalendar->addEvent( lse );
871 } 871 }
872 872
873 return lse; 873 return lse;
874 874
875} 875}
876// probaly useless 876// probaly useless
877void CalendarView::setupExternSyncProfiles() 877void CalendarView::setupExternSyncProfiles()
878{ 878{
879 Event* lse; 879 Event* lse;
880 mExternLastSyncEvent.clear(); 880 mExternLastSyncEvent.clear();
881 int i; 881 int i;
882 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 882 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
883 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 883 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
884 if ( lse ) 884 if ( lse )
885 mExternLastSyncEvent.append( lse ); 885 mExternLastSyncEvent.append( lse );
886 else 886 else
887 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 887 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
888 } 888 }
889 889
890} 890}
891// we check, if the to delete event has a id for a profile 891// we check, if the to delete event has a id for a profile
892// if yes, we set this id in the profile to delete 892// if yes, we set this id in the profile to delete
893void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 893void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
894{ 894{
895 if ( lastSync.count() == 0 ) { 895 if ( lastSync.count() == 0 ) {
896 //qDebug(" lastSync.count() == 0"); 896 //qDebug(" lastSync.count() == 0");
897 return; 897 return;
898 } 898 }
899 if ( toDelete->type() == "Journal" ) 899 if ( toDelete->type() == "Journal" )
900 return; 900 return;
901 901
902 Event* eve = lastSync.first(); 902 Event* eve = lastSync.first();
903 903
904 while ( eve ) { 904 while ( eve ) {
905 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 905 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
906 if ( !id.isEmpty() ) { 906 if ( !id.isEmpty() ) {
907 QString des = eve->description(); 907 QString des = eve->description();
908 QString pref = "e"; 908 QString pref = "e";
909 if ( toDelete->type() == "Todo" ) 909 if ( toDelete->type() == "Todo" )
910 pref = "t"; 910 pref = "t";
911 des += pref+ id + ","; 911 des += pref+ id + ",";
912 eve->setReadOnly( false ); 912 eve->setReadOnly( false );
913 eve->setDescription( des ); 913 eve->setDescription( des );
914 //qDebug("setdes %s ", des.latin1()); 914 //qDebug("setdes %s ", des.latin1());
915 eve->setReadOnly( true ); 915 eve->setReadOnly( true );
916 } 916 }
917 eve = lastSync.next(); 917 eve = lastSync.next();
918 } 918 }
919 919
920} 920}
921void CalendarView::checkExternalId( Incidence * inc ) 921void CalendarView::checkExternalId( Incidence * inc )
922{ 922{
923 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 923 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
924 checkExternSyncEvent( lastSync, inc ); 924 checkExternSyncEvent( lastSync, inc );
925 925
926} 926}
927bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 927bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
928{ 928{
929 bool syncOK = true; 929 bool syncOK = true;
930 int addedEvent = 0; 930 int addedEvent = 0;
931 int addedEventR = 0; 931 int addedEventR = 0;
932 int deletedEventR = 0; 932 int deletedEventR = 0;
933 int deletedEventL = 0; 933 int deletedEventL = 0;
934 int changedLocal = 0; 934 int changedLocal = 0;
935 int changedRemote = 0; 935 int changedRemote = 0;
936 //QPtrList<Event> el = local->rawEvents(); 936 //QPtrList<Event> el = local->rawEvents();
937 Event* eventR; 937 Event* eventR;
938 QString uid; 938 QString uid;
939 int take; 939 int take;
940 Event* eventL; 940 Event* eventL;
941 Event* eventRSync; 941 Event* eventRSync;
942 Event* eventLSync; 942 Event* eventLSync;
943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
945 bool fullDateRange = false; 945 bool fullDateRange = false;
946 local->resetTempSyncStat(); 946 local->resetTempSyncStat();
947 mLastCalendarSync = QDateTime::currentDateTime(); 947 mLastCalendarSync = QDateTime::currentDateTime();
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 ) { 956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
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 ( fullDateRange ) 979 if ( fullDateRange )
980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
981 else 981 else
982 mLastCalendarSync = eventLSync->dtStart(); 982 mLastCalendarSync = eventLSync->dtStart();
983 // for resyncing if own file has changed 983 // for resyncing if own file has changed
984 if ( mCurrentSyncDevice == "deleteaftersync" ) { 984 if ( mCurrentSyncDevice == "deleteaftersync" ) {
985 mLastCalendarSync = loadedFileVersion; 985 mLastCalendarSync = loadedFileVersion;
986 qDebug("setting mLastCalendarSync "); 986 qDebug("setting mLastCalendarSync ");
987 } 987 }
988 //qDebug("*************************** "); 988 //qDebug("*************************** ");
989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
990 QPtrList<Incidence> er = remote->rawIncidences(); 990 QPtrList<Incidence> er = remote->rawIncidences();
991 Incidence* inR = er.first(); 991 Incidence* inR = er.first();
992 Incidence* inL; 992 Incidence* inL;
993 QProgressBar bar( er.count(),0 ); 993 QProgressBar bar( er.count(),0 );
994 bar.setCaption (i18n("Syncing - close to abort!") ); 994 bar.setCaption (i18n("Syncing - close to abort!") );
995 995
996 int w = 300; 996 int w = 300;
997 if ( QApplication::desktop()->width() < 320 ) 997 if ( QApplication::desktop()->width() < 320 )
998 w = 220; 998 w = 220;
999 int h = bar.sizeHint().height() ; 999 int h = bar.sizeHint().height() ;
1000 int dw = QApplication::desktop()->width(); 1000 int dw = QApplication::desktop()->width();
1001 int dh = QApplication::desktop()->height(); 1001 int dh = QApplication::desktop()->height();
1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1003 bar.show(); 1003 bar.show();
1004 int modulo = (er.count()/10)+1; 1004 int modulo = (er.count()/10)+1;
1005 int incCounter = 0; 1005 int incCounter = 0;
1006 while ( inR ) { 1006 while ( inR ) {
1007 if ( ! bar.isVisible() ) 1007 if ( ! bar.isVisible() )
1008 return false; 1008 return false;
1009 if ( incCounter % modulo == 0 ) 1009 if ( incCounter % modulo == 0 )
1010 bar.setProgress( incCounter ); 1010 bar.setProgress( incCounter );
1011 ++incCounter; 1011 ++incCounter;
1012 uid = inR->uid(); 1012 uid = inR->uid();
1013 bool skipIncidence = false; 1013 bool skipIncidence = false;
1014 if ( uid.left(15) == QString("last-syncEvent-") ) 1014 if ( uid.left(15) == QString("last-syncEvent-") )
1015 skipIncidence = true; 1015 skipIncidence = true;
1016 1016
1017 qApp->processEvents(); 1017 qApp->processEvents();
1018 if ( !skipIncidence ) { 1018 if ( !skipIncidence ) {
1019 inL = local->incidence( uid ); 1019 inL = local->incidence( uid );
1020 if ( inL ) { // maybe conflict - same uid in both calendars 1020 if ( inL ) { // maybe conflict - same uid in both calendars
1021 int maxrev = inL->revision(); 1021 int maxrev = inL->revision();
1022 if ( maxrev < inR->revision() ) 1022 if ( maxrev < inR->revision() )
1023 maxrev = inR->revision(); 1023 maxrev = inR->revision();
1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1025 //qDebug("take %d %s ", take, inL->summary().latin1()); 1025 //qDebug("take %d %s ", take, inL->summary().latin1());
1026 if ( take == 3 ) 1026 if ( take == 3 )
1027 return false; 1027 return false;
1028 if ( take == 1 ) {// take local 1028 if ( take == 1 ) {// take local
1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1030 remote->deleteIncidence( inR ); 1030 remote->deleteIncidence( inR );
1031 if ( inL->revision() < maxrev ) 1031 if ( inL->revision() < maxrev )
1032 inL->setRevision( maxrev ); 1032 inL->setRevision( maxrev );
1033 remote->addIncidence( inL->clone() ); 1033 remote->addIncidence( inL->clone() );
1034 ++changedRemote; 1034 ++changedRemote;
1035 } else { 1035 } else {
1036 if ( inR->revision() < maxrev ) 1036 if ( inR->revision() < maxrev )
1037 inR->setRevision( maxrev ); 1037 inR->setRevision( maxrev );
1038 local->deleteIncidence( inL ); 1038 local->deleteIncidence( inL );
1039 local->addIncidence( inR->clone() ); 1039 local->addIncidence( inR->clone() );
1040 ++changedLocal; 1040 ++changedLocal;
1041 } 1041 }
1042 } 1042 }
1043 } else { // no conflict 1043 } else { // no conflict
1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1045 QString des = eventLSync->description(); 1045 QString des = eventLSync->description();
1046 QString pref = "e"; 1046 QString pref = "e";
1047 if ( inR->type() == "Todo" ) 1047 if ( inR->type() == "Todo" )
1048 pref = "t"; 1048 pref = "t";
1049 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1049 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1050 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1050 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1051 //remote->deleteIncidence( inR ); 1051 //remote->deleteIncidence( inR );
1052 ++deletedEventR; 1052 ++deletedEventR;
1053 } else { 1053 } else {
1054 inR->setLastModified( modifiedCalendar ); 1054 inR->setLastModified( modifiedCalendar );
1055 local->addIncidence( inR->clone() ); 1055 local->addIncidence( inR->clone() );
1056 ++addedEvent; 1056 ++addedEvent;
1057 } 1057 }
1058 } else { 1058 } else {
1059 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1059 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 local->addIncidence( inR->clone() ); 1061 local->addIncidence( inR->clone() );
1062 ++addedEvent; 1062 ++addedEvent;
1063 } else { 1063 } else {
1064 checkExternSyncEvent(eventRSyncSharp, inR); 1064 checkExternSyncEvent(eventRSyncSharp, inR);
1065 remote->deleteIncidence( inR ); 1065 remote->deleteIncidence( inR );
1066 ++deletedEventR; 1066 ++deletedEventR;
1067 } 1067 }
1068 } 1068 }
1069 } 1069 }
1070 } 1070 }
1071 inR = er.next(); 1071 inR = er.next();
1072 } 1072 }
1073 QPtrList<Incidence> el = local->rawIncidences(); 1073 QPtrList<Incidence> el = local->rawIncidences();
1074 inL = el.first(); 1074 inL = el.first();
1075 modulo = (el.count()/10)+1; 1075 modulo = (el.count()/10)+1;
1076 bar.setCaption (i18n("Add / remove events") ); 1076 bar.setCaption (i18n("Add / remove events") );
1077 bar.setTotalSteps ( el.count() ) ; 1077 bar.setTotalSteps ( el.count() ) ;
1078 bar.show(); 1078 bar.show();
1079 incCounter = 0; 1079 incCounter = 0;
1080 1080
1081 while ( inL ) { 1081 while ( inL ) {
1082 1082
1083 qApp->processEvents(); 1083 qApp->processEvents();
1084 if ( ! bar.isVisible() ) 1084 if ( ! bar.isVisible() )
1085 return false; 1085 return false;
1086 if ( incCounter % modulo == 0 ) 1086 if ( incCounter % modulo == 0 )
1087 bar.setProgress( incCounter ); 1087 bar.setProgress( incCounter );
1088 ++incCounter; 1088 ++incCounter;
1089 uid = inL->uid(); 1089 uid = inL->uid();
1090 bool skipIncidence = false; 1090 bool skipIncidence = false;
1091 if ( uid.left(15) == QString("last-syncEvent-") ) 1091 if ( uid.left(15) == QString("last-syncEvent-") )
1092 skipIncidence = true; 1092 skipIncidence = true;
1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1094 skipIncidence = true; 1094 skipIncidence = true;
1095 if ( !skipIncidence ) { 1095 if ( !skipIncidence ) {
1096 inR = remote->incidence( uid ); 1096 inR = remote->incidence( uid );
1097 if ( ! inR ) { 1097 if ( ! inR ) {
1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1100 local->deleteIncidence( inL ); 1100 local->deleteIncidence( inL );
1101 ++deletedEventL; 1101 ++deletedEventL;
1102 } else { 1102 } else {
1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1104 inL->removeID(mCurrentSyncDevice ); 1104 inL->removeID(mCurrentSyncDevice );
1105 ++addedEventR; 1105 ++addedEventR;
1106 inL->setLastModified( modifiedCalendar ); 1106 inL->setLastModified( modifiedCalendar );
1107 remote->addIncidence( inL->clone() ); 1107 remote->addIncidence( inL->clone() );
1108 } 1108 }
1109 } 1109 }
1110 } else { 1110 } else {
1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1114 ++deletedEventL; 1114 ++deletedEventL;
1115 } else { 1115 } else {
1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1117 ++addedEventR; 1117 ++addedEventR;
1118 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1119 remote->addIncidence( inL->clone() ); 1119 remote->addIncidence( inL->clone() );
1120 } 1120 }
1121 } 1121 }
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125 inL = el.next(); 1125 inL = el.next();
1126 } 1126 }
1127 int delFut = 0;
1127 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1128 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1128 er = remote->rawIncidences(); 1129 er = remote->rawIncidences();
1129 inR = er.first(); 1130 inR = er.first();
1130 QDateTime dt; 1131 QDateTime dt;
1131 QDateTime cur = QDateTime::currentDateTime(); 1132 QDateTime cur = QDateTime::currentDateTime();
1132 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1133 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1133 while ( inR ) { 1134 while ( inR ) {
1134 if ( inR->type() == "Todo" ) { 1135 if ( inR->type() == "Todo" ) {
1135 Todo * t = (Todo*)inR; 1136 Todo * t = (Todo*)inR;
1136 if ( t->hasDueDate() ) 1137 if ( t->hasDueDate() )
1137 dt = t->dtDue(); 1138 dt = t->dtDue();
1138 else 1139 else
1139 dt = cur.addSecs( 62 ); 1140 dt = cur.addSecs( 62 );
1140 } 1141 }
1141 else dt = inR->dtStart(); 1142 else if (inR->type() == "Event" ) {
1142 if ( dt < cur || dt > end ) 1143 bool ok;
1144 dt = inR->getNextOccurence( cur, &ok );
1145 if ( !ok )
1146 dt = cur.addSecs( -62 );
1147 }
1148 else
1149 dt = inR->dtStart();
1150 if ( dt < cur || dt > end ) {
1143 remote->deleteIncidence( inR ); 1151 remote->deleteIncidence( inR );
1152 ++delFut;
1153 }
1144 inR = er.next(); 1154 inR = er.next();
1145 } 1155 }
1146 } 1156 }
1147 bar.hide(); 1157 bar.hide();
1148 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1158 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1149 eventLSync->setReadOnly( false ); 1159 eventLSync->setReadOnly( false );
1150 eventLSync->setDtStart( mLastCalendarSync ); 1160 eventLSync->setDtStart( mLastCalendarSync );
1151 eventRSync->setDtStart( mLastCalendarSync ); 1161 eventRSync->setDtStart( mLastCalendarSync );
1152 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1162 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1153 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1163 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1154 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1164 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1155 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1165 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1156 eventLSync->setReadOnly( true ); 1166 eventLSync->setReadOnly( true );
1157 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1167 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1158 remote->addEvent( eventRSync ); 1168 remote->addEvent( eventRSync );
1159 QString mes; 1169 QString mes;
1160 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 ); 1170 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 );
1171 QString delmess;
1172 if ( delFut ) {
1173 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1174 mes += delmess;
1175 }
1161 if ( KOPrefs::instance()->mShowSyncSummary ) { 1176 if ( KOPrefs::instance()->mShowSyncSummary ) {
1162 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1177 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1163 } 1178 }
1164 qDebug( mes ); 1179 qDebug( mes );
1165 mCalendar->checkAlarmForIncidence( 0, true ); 1180 mCalendar->checkAlarmForIncidence( 0, true );
1166 return syncOK; 1181 return syncOK;
1167} 1182}
1168 1183
1169void CalendarView::setSyncDevice( QString s ) 1184void CalendarView::setSyncDevice( QString s )
1170{ 1185{
1171 mCurrentSyncDevice= s; 1186 mCurrentSyncDevice= s;
1172} 1187}
1173void CalendarView::setSyncName( QString s ) 1188void CalendarView::setSyncName( QString s )
1174{ 1189{
1175 mCurrentSyncName= s; 1190 mCurrentSyncName= s;
1176} 1191}
1177bool CalendarView::syncCalendar(QString filename, int mode) 1192bool CalendarView::syncCalendar(QString filename, int mode)
1178{ 1193{
1179 mGlobalSyncMode = SYNC_MODE_NORMAL; 1194 mGlobalSyncMode = SYNC_MODE_NORMAL;
1180 CalendarLocal* calendar = new CalendarLocal(); 1195 CalendarLocal* calendar = new CalendarLocal();
1181 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1196 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1182 FileStorage* storage = new FileStorage( calendar ); 1197 FileStorage* storage = new FileStorage( calendar );
1183 bool syncOK = false; 1198 bool syncOK = false;
1184 storage->setFileName( filename ); 1199 storage->setFileName( filename );
1185 // qDebug("loading ... "); 1200 // qDebug("loading ... ");
1186 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1201 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1187 getEventViewerDialog()->setSyncMode( true ); 1202 getEventViewerDialog()->setSyncMode( true );
1188 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1203 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1189 getEventViewerDialog()->setSyncMode( false ); 1204 getEventViewerDialog()->setSyncMode( false );
1190 if ( syncOK ) { 1205 if ( syncOK ) {
1191 if ( KOPrefs::instance()->mWriteBackFile ) 1206 if ( KOPrefs::instance()->mWriteBackFile )
1192 { 1207 {
1193 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1208 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1194 storage->save(); 1209 storage->save();
1195 } 1210 }
1196 } 1211 }
1197 setModified( true ); 1212 setModified( true );
1198 } 1213 }
1199 delete storage; 1214 delete storage;
1200 delete calendar; 1215 delete calendar;
1201 if ( syncOK ) 1216 if ( syncOK )
1202 updateView(); 1217 updateView();
1203 return syncOK; 1218 return syncOK;
1204} 1219}
1205void CalendarView::syncPhone() 1220void CalendarView::syncPhone()
1206{ 1221{
1207 syncExternal( 1 ); 1222 syncExternal( 1 );
1208} 1223}
1209void CalendarView::syncExternal( int mode ) 1224void CalendarView::syncExternal( int mode )
1210{ 1225{
1211 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1226 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1212 //mCurrentSyncDevice = "sharp-DTM"; 1227 //mCurrentSyncDevice = "sharp-DTM";
1213 if ( KOPrefs::instance()->mAskForPreferences ) 1228 if ( KOPrefs::instance()->mAskForPreferences )
1214 edit_sync_options(); 1229 edit_sync_options();
1215 qApp->processEvents(); 1230 qApp->processEvents();
1216 CalendarLocal* calendar = new CalendarLocal(); 1231 CalendarLocal* calendar = new CalendarLocal();
1217 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1232 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1218 bool syncOK = false; 1233 bool syncOK = false;
1219 bool loadSuccess = false; 1234 bool loadSuccess = false;
1220 PhoneFormat* phoneFormat = 0; 1235 PhoneFormat* phoneFormat = 0;
1221#ifndef DESKTOP_VERSION 1236#ifndef DESKTOP_VERSION
1222 SharpFormat* sharpFormat = 0; 1237 SharpFormat* sharpFormat = 0;
1223 if ( mode == 0 ) { // sharp 1238 if ( mode == 0 ) { // sharp
1224 sharpFormat = new SharpFormat () ; 1239 sharpFormat = new SharpFormat () ;
1225 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1240 loadSuccess = sharpFormat->load( calendar, mCalendar );
1226 1241
1227 } else 1242 } else
1228#endif 1243#endif
1229 if ( mode == 1 ) { // phone 1244 if ( mode == 1 ) { // phone
1230 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1245 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1231 KOPrefs::instance()->mPhoneDevice, 1246 KOPrefs::instance()->mPhoneDevice,
1232 KOPrefs::instance()->mPhoneConnection, 1247 KOPrefs::instance()->mPhoneConnection,
1233 KOPrefs::instance()->mPhoneModel); 1248 KOPrefs::instance()->mPhoneModel);
1234 loadSuccess = phoneFormat->load( calendar,mCalendar); 1249 loadSuccess = phoneFormat->load( calendar,mCalendar);
1235 1250
1236 } else 1251 } else
1237 return; 1252 return;
1238 if ( loadSuccess ) { 1253 if ( loadSuccess ) {
1239 getEventViewerDialog()->setSyncMode( true ); 1254 getEventViewerDialog()->setSyncMode( true );
1240 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1255 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1241 getEventViewerDialog()->setSyncMode( false ); 1256 getEventViewerDialog()->setSyncMode( false );
1242 qApp->processEvents(); 1257 qApp->processEvents();
1243 if ( syncOK ) { 1258 if ( syncOK ) {
1244 if ( KOPrefs::instance()->mWriteBackFile ) 1259 if ( KOPrefs::instance()->mWriteBackFile )
1245 { 1260 {
1246 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1261 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1247 Incidence* inc = iL.first(); 1262 Incidence* inc = iL.first();
1248 /* obsolete
1249 while ( inc ) { 1263 while ( inc ) {
1250 inc->setZaurusStat( inc->revision () ); 1264 inc->removeID(mCurrentSyncDevice);
1251 inc = iL.next(); 1265 inc = iL.next();
1252 } 1266 }
1253 */
1254#ifndef DESKTOP_VERSION 1267#ifndef DESKTOP_VERSION
1255 if ( sharpFormat ) 1268 if ( sharpFormat )
1256 sharpFormat->save(calendar); 1269 sharpFormat->save(calendar);
1257#endif 1270#endif
1258 if ( phoneFormat ) 1271 if ( phoneFormat )
1259 phoneFormat->save(calendar); 1272 phoneFormat->save(calendar);
1260 iL = calendar->rawIncidences(); 1273 iL = calendar->rawIncidences();
1261 inc = iL.first(); 1274 inc = iL.first();
1262 Incidence* loc; 1275 Incidence* loc;
1263 while ( inc ) { 1276 while ( inc ) {
1264 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1277 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1265 loc = mCalendar->incidence(inc->uid() ); 1278 loc = mCalendar->incidence(inc->uid() );
1266 if ( loc ) { 1279 if ( loc ) {
1267 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1280 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1268 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1281 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1269 } 1282 }
1270 } 1283 }
1271 inc = iL.next(); 1284 inc = iL.next();
1272 } 1285 }
1273 Incidence* lse = getLastSyncEvent(); 1286 Incidence* lse = getLastSyncEvent();
1274 if ( lse ) { 1287 if ( lse ) {
1275 lse->setReadOnly( false ); 1288 lse->setReadOnly( false );
1276 lse->setDescription( "" ); 1289 lse->setDescription( "" );
1277 lse->setReadOnly( true ); 1290 lse->setReadOnly( true );
1278 } 1291 }
1279 } 1292 }
1280 } 1293 }
1281 setModified( true ); 1294 setModified( true );
1282 } else { 1295 } else {
1283 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1296 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1284 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1297 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1285 question, i18n("Ok")) ; 1298 question, i18n("Ok")) ;
1286 1299
1287 } 1300 }
1288 delete calendar; 1301 delete calendar;
1289 updateView(); 1302 updateView();
1290 return ;//syncOK; 1303 return ;//syncOK;
1291 1304
1292} 1305}
1293void CalendarView::syncSharp() 1306void CalendarView::syncSharp()
1294{ 1307{
1295 syncExternal( 0 ); 1308 syncExternal( 0 );
1296 1309
1297} 1310}
1298 1311
1299 1312
1300#include <kabc/stdaddressbook.h> 1313#include <kabc/stdaddressbook.h>
1301bool CalendarView::importBday() 1314bool CalendarView::importBday()
1302{ 1315{
1303 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1316 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1304 KABC::AddressBook::Iterator it; 1317 KABC::AddressBook::Iterator it;
1305 int count = 0; 1318 int count = 0;
1306 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1319 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1307 ++count; 1320 ++count;
1308 } 1321 }
1309 QProgressBar bar(count,0 ); 1322 QProgressBar bar(count,0 );
1310 int w = 300; 1323 int w = 300;
1311 if ( QApplication::desktop()->width() < 320 ) 1324 if ( QApplication::desktop()->width() < 320 )
1312 w = 220; 1325 w = 220;
1313 int h = bar.sizeHint().height() ; 1326 int h = bar.sizeHint().height() ;
1314 int dw = QApplication::desktop()->width(); 1327 int dw = QApplication::desktop()->width();
1315 int dh = QApplication::desktop()->height(); 1328 int dh = QApplication::desktop()->height();
1316 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1329 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1317 bar.show(); 1330 bar.show();
1318 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1331 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1319 qApp->processEvents(); 1332 qApp->processEvents();
1320 count = 0; 1333 count = 0;
1321 int addCount = 0; 1334 int addCount = 0;
1322 KCal::Attendee* a = 0; 1335 KCal::Attendee* a = 0;
1323 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1336 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1324 if ( ! bar.isVisible() ) 1337 if ( ! bar.isVisible() )
1325 return false; 1338 return false;
1326 bar.setProgress( count++ ); 1339 bar.setProgress( count++ );
1327 qApp->processEvents(); 1340 qApp->processEvents();
1328 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1341 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1329 if ( (*it).birthday().date().isValid() ){ 1342 if ( (*it).birthday().date().isValid() ){
1330 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1343 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1331 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1344 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1332 ++addCount; 1345 ++addCount;
1333 } 1346 }
1334 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1347 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1335 if ( anni.isValid() ){ 1348 if ( anni.isValid() ){
1336 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1349 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1337 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1350 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1338 ++addCount; 1351 ++addCount;
1339 } 1352 }
1340 } 1353 }
1341 updateView(); 1354 updateView();
1342 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1355 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1343 return true; 1356 return true;
1344} 1357}
1345 1358
1346bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1359bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1347{ 1360{
1348 //qDebug("addAnni "); 1361 //qDebug("addAnni ");
1349 Event * ev = new Event(); 1362 Event * ev = new Event();
1350 if ( a ) { 1363 if ( a ) {
1351 ev->addAttendee( a ); 1364 ev->addAttendee( a );
1352 } 1365 }
1353 QString kind; 1366 QString kind;
1354 if ( birthday ) 1367 if ( birthday )
1355 kind = i18n( "Birthday" ); 1368 kind = i18n( "Birthday" );
1356 else 1369 else
1357 kind = i18n( "Anniversary" ); 1370 kind = i18n( "Anniversary" );
1358 ev->setSummary( name + " - " + kind ); 1371 ev->setSummary( name + " - " + kind );
1359 ev->setOrganizer( "nobody@nowhere" ); 1372 ev->setOrganizer( "nobody@nowhere" );
1360 ev->setCategories( kind ); 1373 ev->setCategories( kind );
1361 ev->setDtStart( QDateTime(date) ); 1374 ev->setDtStart( QDateTime(date) );
1362 ev->setDtEnd( QDateTime(date) ); 1375 ev->setDtEnd( QDateTime(date) );
1363 ev->setFloats( true ); 1376 ev->setFloats( true );
1364 Recurrence * rec = ev->recurrence(); 1377 Recurrence * rec = ev->recurrence();
1365 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1378 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1366 rec->addYearlyNum( date.month() ); 1379 rec->addYearlyNum( date.month() );
1367 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1380 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1368 delete ev; 1381 delete ev;
1369 return false; 1382 return false;
1370 } 1383 }
1371 return true; 1384 return true;
1372 1385
1373} 1386}
1374bool CalendarView::importQtopia( const QString &categories, 1387bool CalendarView::importQtopia( const QString &categories,
1375 const QString &datebook, 1388 const QString &datebook,
1376 const QString &todolist ) 1389 const QString &todolist )
1377{ 1390{
1378 1391
1379 QtopiaFormat qtopiaFormat; 1392 QtopiaFormat qtopiaFormat;
1380 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1393 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1381 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1394 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1382 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1395 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1383 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1396 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1384 1397
1385 updateView(); 1398 updateView();
1386 return true; 1399 return true;
1387 1400
1388#if 0 1401#if 0
1389 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1402 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1390 mCurrentSyncDevice = "qtopia-XML"; 1403 mCurrentSyncDevice = "qtopia-XML";
1391 if ( KOPrefs::instance()->mAskForPreferences ) 1404 if ( KOPrefs::instance()->mAskForPreferences )
1392 edit_sync_options(); 1405 edit_sync_options();
1393 qApp->processEvents(); 1406 qApp->processEvents();
1394 CalendarLocal* calendar = new CalendarLocal(); 1407 CalendarLocal* calendar = new CalendarLocal();
1395 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1408 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1396 bool syncOK = false; 1409 bool syncOK = false;
1397 QtopiaFormat qtopiaFormat; 1410 QtopiaFormat qtopiaFormat;
1398 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1411 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1399 bool loadOk = true; 1412 bool loadOk = true;
1400 if ( !categories.isEmpty() ) 1413 if ( !categories.isEmpty() )
1401 loadOk = qtopiaFormat.load( calendar, categories ); 1414 loadOk = qtopiaFormat.load( calendar, categories );
1402 if ( loadOk && !datebook.isEmpty() ) 1415 if ( loadOk && !datebook.isEmpty() )
1403 loadOk = qtopiaFormat.load( calendar, datebook ); 1416 loadOk = qtopiaFormat.load( calendar, datebook );
1404 if ( loadOk && !todolist.isEmpty() ) 1417 if ( loadOk && !todolist.isEmpty() )
1405 loadOk = qtopiaFormat.load( calendar, todolist ); 1418 loadOk = qtopiaFormat.load( calendar, todolist );
1406 1419
1407 if ( loadOk ) { 1420 if ( loadOk ) {
1408 getEventViewerDialog()->setSyncMode( true ); 1421 getEventViewerDialog()->setSyncMode( true );
1409 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1422 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1410 getEventViewerDialog()->setSyncMode( false ); 1423 getEventViewerDialog()->setSyncMode( false );
1411 qApp->processEvents(); 1424 qApp->processEvents();
1412 if ( syncOK ) { 1425 if ( syncOK ) {
1413 if ( KOPrefs::instance()->mWriteBackFile ) 1426 if ( KOPrefs::instance()->mWriteBackFile )
1414 { 1427 {
1415 // write back XML file 1428 // write back XML file
1416 1429
1417 } 1430 }
1418 setModified( true ); 1431 setModified( true );
1419 } 1432 }
1420 } else { 1433 } else {
1421 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1434 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1422 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1435 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1423 question, i18n("Ok")) ; 1436 question, i18n("Ok")) ;
1424 } 1437 }
1425 delete calendar; 1438 delete calendar;
1426 updateView(); 1439 updateView();
1427 return syncOK; 1440 return syncOK;
1428 1441
1429 1442
1430#endif 1443#endif
1431 1444
1432} 1445}
1433 1446
1434void CalendarView::setSyncEventsReadOnly() 1447void CalendarView::setSyncEventsReadOnly()
1435{ 1448{
1436 Event * ev; 1449 Event * ev;
1437 QPtrList<Event> eL = mCalendar->rawEvents(); 1450 QPtrList<Event> eL = mCalendar->rawEvents();
1438 ev = eL.first(); 1451 ev = eL.first();
1439 while ( ev ) { 1452 while ( ev ) {
1440 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1453 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1441 ev->setReadOnly( true ); 1454 ev->setReadOnly( true );
1442 ev = eL.next(); 1455 ev = eL.next();
1443 } 1456 }
1444} 1457}
1445bool CalendarView::openCalendar(QString filename, bool merge) 1458bool CalendarView::openCalendar(QString filename, bool merge)
1446{ 1459{
1447 1460
1448 if (filename.isEmpty()) { 1461 if (filename.isEmpty()) {
1449 return false; 1462 return false;
1450 } 1463 }
1451 1464
1452 if (!QFile::exists(filename)) { 1465 if (!QFile::exists(filename)) {
1453 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1466 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1454 return false; 1467 return false;
1455 } 1468 }
1456 1469
1457 globalFlagBlockAgenda = 1; 1470 globalFlagBlockAgenda = 1;
1458 if (!merge) mCalendar->close(); 1471 if (!merge) mCalendar->close();
1459 1472
1460 mStorage->setFileName( filename ); 1473 mStorage->setFileName( filename );
1461 1474
1462 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { 1475 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) {
1463 if ( merge ) ;//setModified( true ); 1476 if ( merge ) ;//setModified( true );
1464 else { 1477 else {
1465 //setModified( true ); 1478 //setModified( true );
1466 mViewManager->setDocumentId( filename ); 1479 mViewManager->setDocumentId( filename );
1467 mDialogManager->setDocumentId( filename ); 1480 mDialogManager->setDocumentId( filename );
1468 mTodoList->setDocumentId( filename ); 1481 mTodoList->setDocumentId( filename );
1469 } 1482 }
1470 globalFlagBlockAgenda = 2; 1483 globalFlagBlockAgenda = 2;
1471 // if ( getLastSyncEvent() ) 1484 // if ( getLastSyncEvent() )
1472 // getLastSyncEvent()->setReadOnly( true ); 1485 // getLastSyncEvent()->setReadOnly( true );
1473 mCalendar->reInitAlarmSettings(); 1486 mCalendar->reInitAlarmSettings();
1474 setSyncEventsReadOnly(); 1487 setSyncEventsReadOnly();
1475 updateUnmanagedViews(); 1488 updateUnmanagedViews();
1476 updateView(); 1489 updateView();
1477 if ( filename != MainWindow::defaultFileName() ) 1490 if ( filename != MainWindow::defaultFileName() )
1478 saveCalendar( MainWindow::defaultFileName() ); 1491 saveCalendar( MainWindow::defaultFileName() );
1479 loadedFileVersion = QDateTime::currentDateTime(); 1492 loadedFileVersion = QDateTime::currentDateTime();
1480 return true; 1493 return true;
1481 } else { 1494 } else {
1482 // while failing to load, the calendar object could 1495 // while failing to load, the calendar object could
1483 // have become partially populated. Clear it out. 1496 // have become partially populated. Clear it out.
1484 if ( !merge ) mCalendar->close(); 1497 if ( !merge ) mCalendar->close();
1485 1498
1486 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1499 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1487 1500
1488 globalFlagBlockAgenda = 2; 1501 globalFlagBlockAgenda = 2;
1489 updateView(); 1502 updateView();
1490 } 1503 }
1491 return false; 1504 return false;
1492} 1505}
1493void CalendarView::setLoadedFileVersion(QDateTime dt) 1506void CalendarView::setLoadedFileVersion(QDateTime dt)
1494{ 1507{
1495 loadedFileVersion = dt; 1508 loadedFileVersion = dt;
1496} 1509}
1497bool CalendarView::checkFileChanged(QString fn) 1510bool CalendarView::checkFileChanged(QString fn)
1498{ 1511{
1499 QFileInfo finf ( fn ); 1512 QFileInfo finf ( fn );
1500 if ( !finf.exists() ) 1513 if ( !finf.exists() )
1501 return true; 1514 return true;
1502 QDateTime dt = finf.lastModified (); 1515 QDateTime dt = finf.lastModified ();
1503 if ( dt <= loadedFileVersion ) 1516 if ( dt <= loadedFileVersion )
1504 return false; 1517 return false;
1505 return true; 1518 return true;
1506 1519
1507} 1520}
1508bool CalendarView::checkFileVersion(QString fn) 1521bool CalendarView::checkFileVersion(QString fn)
1509{ 1522{
1510 QFileInfo finf ( fn ); 1523 QFileInfo finf ( fn );
1511 if ( !finf.exists() ) 1524 if ( !finf.exists() )
1512 return true; 1525 return true;
1513 QDateTime dt = finf.lastModified (); 1526 QDateTime dt = finf.lastModified ();
1514 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1527 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1515 //qDebug("file on disk version %s",dt.toString().latin1()); 1528 //qDebug("file on disk version %s",dt.toString().latin1());
1516 if ( dt <= loadedFileVersion ) 1529 if ( dt <= loadedFileVersion )
1517 return true; 1530 return true;
1518 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, false)) , 1531 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, false)) ,
1519 i18n("KO/Pi Warning"),i18n("Overwrite"), 1532 i18n("KO/Pi Warning"),i18n("Overwrite"),
1520 i18n("Sync+save")); 1533 i18n("Sync+save"));
1521 1534
1522 if ( km == KMessageBox::Cancel ) 1535 if ( km == KMessageBox::Cancel )
1523 return false; 1536 return false;
1524 if ( km == KMessageBox::Yes ) 1537 if ( km == KMessageBox::Yes )
1525 return true; 1538 return true;
1526 1539
1527 setSyncDevice("deleteaftersync" ); 1540 setSyncDevice("deleteaftersync" );
1528 KOPrefs::instance()->mAskForPreferences = true; 1541 KOPrefs::instance()->mAskForPreferences = true;
1529 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1542 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1530 KOPrefs::instance()->mWriteBackFile = false; 1543 KOPrefs::instance()->mWriteBackFile = false;
1531 KOPrefs::instance()->mWriteBackExistingOnly = false; 1544 KOPrefs::instance()->mWriteBackExistingOnly = false;
1532 KOPrefs::instance()->mShowSyncSummary = false; 1545 KOPrefs::instance()->mShowSyncSummary = false;
1533 syncCalendar( fn, 3 ); 1546 syncCalendar( fn, 3 );
1534 Event * e = getLastSyncEvent(); 1547 Event * e = getLastSyncEvent();
1535 mCalendar->deleteEvent ( e ); 1548 mCalendar->deleteEvent ( e );
1536 updateView(); 1549 updateView();
1537 return true; 1550 return true;
1538} 1551}
1539 1552
1540bool CalendarView::saveCalendar( QString filename ) 1553bool CalendarView::saveCalendar( QString filename )
1541{ 1554{
1542 1555
1543 // Store back all unsaved data into calendar object 1556 // Store back all unsaved data into calendar object
1544 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1557 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1545 if ( mViewManager->currentView() ) 1558 if ( mViewManager->currentView() )
1546 mViewManager->currentView()->flushView(); 1559 mViewManager->currentView()->flushView();
1547 1560
1548 //mStorage->setFileName( filename ); 1561 //mStorage->setFileName( filename );
1549 1562
1550 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1563 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1551 mStorage->setFileName( filename ); 1564 mStorage->setFileName( filename );
1552 bool success; 1565 bool success;
1553 success = mStorage->save(); 1566 success = mStorage->save();
1554 if ( !success ) { 1567 if ( !success ) {
1555 return false; 1568 return false;
1556 } 1569 }
1557 1570
1558 return true; 1571 return true;
1559} 1572}
1560 1573
1561void CalendarView::closeCalendar() 1574void CalendarView::closeCalendar()
1562{ 1575{
1563 1576
1564 // child windows no longer valid 1577 // child windows no longer valid
1565 emit closingDown(); 1578 emit closingDown();
1566 1579
1567 mCalendar->close(); 1580 mCalendar->close();
1568 setModified(false); 1581 setModified(false);
1569 updateView(); 1582 updateView();
1570} 1583}
1571 1584
1572void CalendarView::archiveCalendar() 1585void CalendarView::archiveCalendar()
1573{ 1586{
1574 mDialogManager->showArchiveDialog(); 1587 mDialogManager->showArchiveDialog();
1575} 1588}
1576 1589
1577 1590
1578void CalendarView::readSettings() 1591void CalendarView::readSettings()
1579{ 1592{
1580 1593
1581 1594
1582 // mViewManager->showAgendaView(); 1595 // mViewManager->showAgendaView();
1583 QString str; 1596 QString str;
1584 //qDebug("CalendarView::readSettings() "); 1597 //qDebug("CalendarView::readSettings() ");
1585 // read settings from the KConfig, supplying reasonable 1598 // read settings from the KConfig, supplying reasonable
1586 // defaults where none are to be found 1599 // defaults where none are to be found
1587 KConfig *config = KOGlobals::config(); 1600 KConfig *config = KOGlobals::config();
1588#ifndef KORG_NOSPLITTER 1601#ifndef KORG_NOSPLITTER
1589 config->setGroup("KOrganizer Geometry"); 1602 config->setGroup("KOrganizer Geometry");
1590 1603
1591 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1604 QValueList<int> sizes = config->readIntListEntry("Separator1");
1592 if (sizes.count() != 2) { 1605 if (sizes.count() != 2) {
1593 sizes << mDateNavigator->minimumSizeHint().width(); 1606 sizes << mDateNavigator->minimumSizeHint().width();
1594 sizes << 300; 1607 sizes << 300;
1595 } 1608 }
1596 mPanner->setSizes(sizes); 1609 mPanner->setSizes(sizes);
1597 1610
1598 sizes = config->readIntListEntry("Separator2"); 1611 sizes = config->readIntListEntry("Separator2");
1599 if ( ( mResourceView && sizes.count() == 4 ) || 1612 if ( ( mResourceView && sizes.count() == 4 ) ||
1600 ( !mResourceView && sizes.count() == 3 ) ) { 1613 ( !mResourceView && sizes.count() == 3 ) ) {
1601 mLeftSplitter->setSizes(sizes); 1614 mLeftSplitter->setSizes(sizes);
1602 } 1615 }
1603#endif 1616#endif
1604 globalFlagBlockAgenda = 1; 1617 globalFlagBlockAgenda = 1;
1605 mViewManager->showAgendaView(); 1618 mViewManager->showAgendaView();
1606 //mViewManager->readSettings( config ); 1619 //mViewManager->readSettings( config );
1607 mTodoList->restoreLayout(config,QString("Todo Layout")); 1620 mTodoList->restoreLayout(config,QString("Todo Layout"));
1608 readFilterSettings(config); 1621 readFilterSettings(config);
1609 config->setGroup( "Views" ); 1622 config->setGroup( "Views" );
1610 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1623 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1611 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1624 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1612 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1625 else if ( dateCount == 7 ) mNavigator->selectWeek();
1613 else mNavigator->selectDates( dateCount ); 1626 else mNavigator->selectDates( dateCount );
1614 // mViewManager->readSettings( config ); 1627 // mViewManager->readSettings( config );
1615 updateConfig(); 1628 updateConfig();
1616 globalFlagBlockAgenda = 2; 1629 globalFlagBlockAgenda = 2;
1617 mViewManager->readSettings( config ); 1630 mViewManager->readSettings( config );
1618#ifdef DESKTOP_VERSION 1631#ifdef DESKTOP_VERSION
1619 config->setGroup("WidgetLayout"); 1632 config->setGroup("WidgetLayout");
1620 QStringList list; 1633 QStringList list;
1621 list = config->readListEntry("MainLayout"); 1634 list = config->readListEntry("MainLayout");
1622 int x,y,w,h; 1635 int x,y,w,h;
1623 if ( ! list.isEmpty() ) { 1636 if ( ! list.isEmpty() ) {
1624 x = list[0].toInt(); 1637 x = list[0].toInt();
1625 y = list[1].toInt(); 1638 y = list[1].toInt();
1626 w = list[2].toInt(); 1639 w = list[2].toInt();
1627 h = list[3].toInt(); 1640 h = list[3].toInt();
1628 topLevelWidget()->setGeometry(x,y,w,h); 1641 topLevelWidget()->setGeometry(x,y,w,h);
1629 1642
1630 } else { 1643 } else {
1631 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1644 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1632 } 1645 }
1633 list = config->readListEntry("EditEventLayout"); 1646 list = config->readListEntry("EditEventLayout");
1634 if ( ! list.isEmpty() ) { 1647 if ( ! list.isEmpty() ) {
1635 x = list[0].toInt(); 1648 x = list[0].toInt();
1636 y = list[1].toInt(); 1649 y = list[1].toInt();
1637 w = list[2].toInt(); 1650 w = list[2].toInt();
1638 h = list[3].toInt(); 1651 h = list[3].toInt();
1639 mEventEditor->setGeometry(x,y,w,h); 1652 mEventEditor->setGeometry(x,y,w,h);
1640 1653
1641 } 1654 }
1642 list = config->readListEntry("EditTodoLayout"); 1655 list = config->readListEntry("EditTodoLayout");
1643 if ( ! list.isEmpty() ) { 1656 if ( ! list.isEmpty() ) {
1644 x = list[0].toInt(); 1657 x = list[0].toInt();
1645 y = list[1].toInt(); 1658 y = list[1].toInt();
1646 w = list[2].toInt(); 1659 w = list[2].toInt();
1647 h = list[3].toInt(); 1660 h = list[3].toInt();
1648 mTodoEditor->setGeometry(x,y,w,h); 1661 mTodoEditor->setGeometry(x,y,w,h);
1649 1662
1650 } 1663 }
1651 list = config->readListEntry("ViewerLayout"); 1664 list = config->readListEntry("ViewerLayout");
1652 if ( ! list.isEmpty() ) { 1665 if ( ! list.isEmpty() ) {
1653 x = list[0].toInt(); 1666 x = list[0].toInt();
1654 y = list[1].toInt(); 1667 y = list[1].toInt();
1655 w = list[2].toInt(); 1668 w = list[2].toInt();
1656 h = list[3].toInt(); 1669 h = list[3].toInt();
1657 getEventViewerDialog()->setGeometry(x,y,w,h); 1670 getEventViewerDialog()->setGeometry(x,y,w,h);
1658 } 1671 }
1659#endif 1672#endif
1660 1673
1661} 1674}
1662 1675
1663 1676
1664void CalendarView::writeSettings() 1677void CalendarView::writeSettings()
1665{ 1678{
1666 // kdDebug() << "CalendarView::writeSettings" << endl; 1679 // kdDebug() << "CalendarView::writeSettings" << endl;
1667 1680
1668 KConfig *config = KOGlobals::config(); 1681 KConfig *config = KOGlobals::config();
1669 1682
1670#ifndef KORG_NOSPLITTER 1683#ifndef KORG_NOSPLITTER
1671 config->setGroup("KOrganizer Geometry"); 1684 config->setGroup("KOrganizer Geometry");
1672 1685
1673 QValueList<int> list = mPanner->sizes(); 1686 QValueList<int> list = mPanner->sizes();
1674 config->writeEntry("Separator1",list); 1687 config->writeEntry("Separator1",list);
1675 1688
1676 list = mLeftSplitter->sizes(); 1689 list = mLeftSplitter->sizes();
1677 config->writeEntry("Separator2",list); 1690 config->writeEntry("Separator2",list);
1678#endif 1691#endif
1679 1692
1680 mViewManager->writeSettings( config ); 1693 mViewManager->writeSettings( config );
1681 mTodoList->saveLayout(config,QString("Todo Layout")); 1694 mTodoList->saveLayout(config,QString("Todo Layout"));
1682 mDialogManager->writeSettings( config ); 1695 mDialogManager->writeSettings( config );
1683 //KOPrefs::instance()->usrWriteConfig(); 1696 //KOPrefs::instance()->usrWriteConfig();
1684 KOPrefs::instance()->writeConfig(); 1697 KOPrefs::instance()->writeConfig();
1685 1698
1686 writeFilterSettings(config); 1699 writeFilterSettings(config);
1687 1700
1688 config->setGroup( "Views" ); 1701 config->setGroup( "Views" );
1689 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1702 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1690 1703
1691#ifdef DESKTOP_VERSION 1704#ifdef DESKTOP_VERSION
1692 config->setGroup("WidgetLayout"); 1705 config->setGroup("WidgetLayout");
1693 QStringList list ;//= config->readListEntry("MainLayout"); 1706 QStringList list ;//= config->readListEntry("MainLayout");
1694 int x,y,w,h; 1707 int x,y,w,h;
1695 QWidget* wid; 1708 QWidget* wid;
1696 wid = topLevelWidget(); 1709 wid = topLevelWidget();
1697 x = wid->geometry().x(); 1710 x = wid->geometry().x();
1698 y = wid->geometry().y(); 1711 y = wid->geometry().y();
1699 w = wid->width(); 1712 w = wid->width();
1700 h = wid->height(); 1713 h = wid->height();
1701 list.clear(); 1714 list.clear();
1702 list << QString::number( x ); 1715 list << QString::number( x );
1703 list << QString::number( y ); 1716 list << QString::number( y );
1704 list << QString::number( w ); 1717 list << QString::number( w );
1705 list << QString::number( h ); 1718 list << QString::number( h );
1706 config->writeEntry("MainLayout",list ); 1719 config->writeEntry("MainLayout",list );
1707 1720
1708 wid = mEventEditor; 1721 wid = mEventEditor;
1709 x = wid->geometry().x(); 1722 x = wid->geometry().x();
1710 y = wid->geometry().y(); 1723 y = wid->geometry().y();
1711 w = wid->width(); 1724 w = wid->width();
1712 h = wid->height(); 1725 h = wid->height();
1713 list.clear(); 1726 list.clear();
1714 list << QString::number( x ); 1727 list << QString::number( x );
1715 list << QString::number( y ); 1728 list << QString::number( y );
1716 list << QString::number( w ); 1729 list << QString::number( w );
1717 list << QString::number( h ); 1730 list << QString::number( h );
1718 config->writeEntry("EditEventLayout",list ); 1731 config->writeEntry("EditEventLayout",list );
1719 1732
1720 wid = mTodoEditor; 1733 wid = mTodoEditor;
1721 x = wid->geometry().x(); 1734 x = wid->geometry().x();
1722 y = wid->geometry().y(); 1735 y = wid->geometry().y();
1723 w = wid->width(); 1736 w = wid->width();
1724 h = wid->height(); 1737 h = wid->height();
1725 list.clear(); 1738 list.clear();
1726 list << QString::number( x ); 1739 list << QString::number( x );
1727 list << QString::number( y ); 1740 list << QString::number( y );
1728 list << QString::number( w ); 1741 list << QString::number( w );
1729 list << QString::number( h ); 1742 list << QString::number( h );
1730 config->writeEntry("EditTodoLayout",list ); 1743 config->writeEntry("EditTodoLayout",list );
1731 wid = getEventViewerDialog(); 1744 wid = getEventViewerDialog();
1732 x = wid->geometry().x(); 1745 x = wid->geometry().x();
1733 y = wid->geometry().y(); 1746 y = wid->geometry().y();
1734 w = wid->width(); 1747 w = wid->width();
1735 h = wid->height(); 1748 h = wid->height();
1736 list.clear(); 1749 list.clear();
1737 list << QString::number( x ); 1750 list << QString::number( x );
1738 list << QString::number( y ); 1751 list << QString::number( y );
1739 list << QString::number( w ); 1752 list << QString::number( w );
1740 list << QString::number( h ); 1753 list << QString::number( h );
1741 config->writeEntry("ViewerLayout",list ); 1754 config->writeEntry("ViewerLayout",list );
1742 wid = mDialogManager->getSearchDialog(); 1755 wid = mDialogManager->getSearchDialog();
1743 if ( wid ) { 1756 if ( wid ) {
1744 x = wid->geometry().x(); 1757 x = wid->geometry().x();
1745 y = wid->geometry().y(); 1758 y = wid->geometry().y();
1746 w = wid->width(); 1759 w = wid->width();
1747 h = wid->height(); 1760 h = wid->height();
1748 list.clear(); 1761 list.clear();
1749 list << QString::number( x ); 1762 list << QString::number( x );
1750 list << QString::number( y ); 1763 list << QString::number( y );
1751 list << QString::number( w ); 1764 list << QString::number( w );
1752 list << QString::number( h ); 1765 list << QString::number( h );
1753 config->writeEntry("SearchLayout",list ); 1766 config->writeEntry("SearchLayout",list );
1754 } 1767 }
1755#endif 1768#endif
1756 1769
1757 1770
1758 config->sync(); 1771 config->sync();
1759} 1772}
1760 1773
1761void CalendarView::readFilterSettings(KConfig *config) 1774void CalendarView::readFilterSettings(KConfig *config)
1762{ 1775{
1763 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1776 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1764 1777
1765 mFilters.clear(); 1778 mFilters.clear();
1766 1779
1767 config->setGroup("General"); 1780 config->setGroup("General");
1768 QStringList filterList = config->readListEntry("CalendarFilters"); 1781 QStringList filterList = config->readListEntry("CalendarFilters");
1769 1782
1770 QStringList::ConstIterator it = filterList.begin(); 1783 QStringList::ConstIterator it = filterList.begin();
1771 QStringList::ConstIterator end = filterList.end(); 1784 QStringList::ConstIterator end = filterList.end();
1772 while(it != end) { 1785 while(it != end) {
1773 // kdDebug() << " filter: " << (*it) << endl; 1786 // kdDebug() << " filter: " << (*it) << endl;
1774 1787
1775 CalFilter *filter; 1788 CalFilter *filter;
1776 filter = new CalFilter(*it); 1789 filter = new CalFilter(*it);
1777 config->setGroup("Filter_" + (*it)); 1790 config->setGroup("Filter_" + (*it));
1778 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1791 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1779 filter->setCriteria(config->readNumEntry("Criteria",0)); 1792 filter->setCriteria(config->readNumEntry("Criteria",0));
1780 filter->setCategoryList(config->readListEntry("CategoryList")); 1793 filter->setCategoryList(config->readListEntry("CategoryList"));
1781 mFilters.append(filter); 1794 mFilters.append(filter);
1782 1795
1783 ++it; 1796 ++it;
1784 } 1797 }
1785 1798
1786 if (mFilters.count() == 0) { 1799 if (mFilters.count() == 0) {
1787 CalFilter *filter = new CalFilter(i18n("Default")); 1800 CalFilter *filter = new CalFilter(i18n("Default"));
1788 mFilters.append(filter); 1801 mFilters.append(filter);
1789 } 1802 }
1790 mFilterView->updateFilters(); 1803 mFilterView->updateFilters();
1791 config->setGroup("FilterView"); 1804 config->setGroup("FilterView");
1792 1805
1793 mFilterView->blockSignals(true); 1806 mFilterView->blockSignals(true);
1794 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1807 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1795 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1808 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1796 mFilterView->blockSignals(false); 1809 mFilterView->blockSignals(false);
1797 // We do it manually to avoid it being done twice by the above calls 1810 // We do it manually to avoid it being done twice by the above calls
1798 updateFilter(); 1811 updateFilter();
1799} 1812}
1800 1813
1801void CalendarView::writeFilterSettings(KConfig *config) 1814void CalendarView::writeFilterSettings(KConfig *config)
1802{ 1815{
1803 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1816 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1804 1817
1805 QStringList filterList; 1818 QStringList filterList;
1806 1819
1807 CalFilter *filter = mFilters.first(); 1820 CalFilter *filter = mFilters.first();
1808 while(filter) { 1821 while(filter) {
1809 // kdDebug() << " fn: " << filter->name() << endl; 1822 // kdDebug() << " fn: " << filter->name() << endl;
1810 filterList << filter->name(); 1823 filterList << filter->name();
1811 config->setGroup("Filter_" + filter->name()); 1824 config->setGroup("Filter_" + filter->name());
1812 config->writeEntry("Criteria",filter->criteria()); 1825 config->writeEntry("Criteria",filter->criteria());
1813 config->writeEntry("CategoryList",filter->categoryList()); 1826 config->writeEntry("CategoryList",filter->categoryList());
1814 filter = mFilters.next(); 1827 filter = mFilters.next();
1815 } 1828 }
1816 config->setGroup("General"); 1829 config->setGroup("General");
1817 config->writeEntry("CalendarFilters",filterList); 1830 config->writeEntry("CalendarFilters",filterList);
1818 1831
1819 config->setGroup("FilterView"); 1832 config->setGroup("FilterView");
1820 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1833 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1821 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1834 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1822} 1835}
1823 1836
1824 1837
1825void CalendarView::goToday() 1838void CalendarView::goToday()
1826{ 1839{
1827 mNavigator->selectToday(); 1840 mNavigator->selectToday();
1828} 1841}
1829 1842
1830void CalendarView::goNext() 1843void CalendarView::goNext()
1831{ 1844{
1832 mNavigator->selectNext(); 1845 mNavigator->selectNext();
1833} 1846}
1834 1847
1835void CalendarView::goPrevious() 1848void CalendarView::goPrevious()
1836{ 1849{
1837 mNavigator->selectPrevious(); 1850 mNavigator->selectPrevious();
1838} 1851}
1839void CalendarView::goNextMonth() 1852void CalendarView::goNextMonth()
1840{ 1853{
1841 mNavigator->selectNextMonth(); 1854 mNavigator->selectNextMonth();
1842} 1855}
1843 1856
1844void CalendarView::goPreviousMonth() 1857void CalendarView::goPreviousMonth()
1845{ 1858{
1846 mNavigator->selectPreviousMonth(); 1859 mNavigator->selectPreviousMonth();
1847} 1860}
1848void CalendarView::writeLocale() 1861void CalendarView::writeLocale()
1849{ 1862{
1850 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1863 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1851 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1864 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1852 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1865 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1853 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1866 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1854 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1867 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1855 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1868 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1856 dummy = KOPrefs::instance()->mUserDateFormatShort; 1869 dummy = KOPrefs::instance()->mUserDateFormatShort;
1857 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1870 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1858 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1871 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1859 KOPrefs::instance()->mDaylightsavingStart, 1872 KOPrefs::instance()->mDaylightsavingStart,
1860 KOPrefs::instance()->mDaylightsavingEnd ); 1873 KOPrefs::instance()->mDaylightsavingEnd );
1861 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1874 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1862} 1875}
1863void CalendarView::updateConfig() 1876void CalendarView::updateConfig()
1864{ 1877{
1865 writeLocale(); 1878 writeLocale();
1866 if ( KOPrefs::instance()->mUseAppColors ) 1879 if ( KOPrefs::instance()->mUseAppColors )
1867 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1880 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1868 emit configChanged(); 1881 emit configChanged();
1869 mTodoList->updateConfig(); 1882 mTodoList->updateConfig();
1870 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1883 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1871 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1884 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1872 // To make the "fill window" configurations work 1885 // To make the "fill window" configurations work
1873 //mViewManager->raiseCurrentView(); 1886 //mViewManager->raiseCurrentView();
1874} 1887}
1875 1888
1876 1889
1877void CalendarView::eventChanged(Event *event) 1890void CalendarView::eventChanged(Event *event)
1878{ 1891{
1879 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1892 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1880 //updateUnmanagedViews(); 1893 //updateUnmanagedViews();
1881} 1894}
1882 1895
1883void CalendarView::eventAdded(Event *event) 1896void CalendarView::eventAdded(Event *event)
1884{ 1897{
1885 changeEventDisplay(event,KOGlobals::EVENTADDED); 1898 changeEventDisplay(event,KOGlobals::EVENTADDED);
1886} 1899}
1887 1900
1888void CalendarView::eventToBeDeleted(Event *) 1901void CalendarView::eventToBeDeleted(Event *)
1889{ 1902{
1890 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 1903 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
1891} 1904}
1892 1905
1893void CalendarView::eventDeleted() 1906void CalendarView::eventDeleted()
1894{ 1907{
1895 changeEventDisplay(0,KOGlobals::EVENTDELETED); 1908 changeEventDisplay(0,KOGlobals::EVENTDELETED);
1896} 1909}
1897void CalendarView::changeTodoDisplay(Todo *which, int action) 1910void CalendarView::changeTodoDisplay(Todo *which, int action)
1898{ 1911{
1899 changeIncidenceDisplay((Incidence *)which, action); 1912 changeIncidenceDisplay((Incidence *)which, action);
1900 mDateNavigator->updateView(); 1913 mDateNavigator->updateView();
1901 //mDialogManager->updateSearchDialog(); 1914 //mDialogManager->updateSearchDialog();
1902 1915
1903 if (which) { 1916 if (which) {
1904 mViewManager->currentView()->updateView(); 1917 mViewManager->currentView()->updateView();
1905 //mTodoList->updateView(); 1918 //mTodoList->updateView();
1906 } 1919 }
1907 1920
1908} 1921}
1909 1922
1910void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 1923void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
1911{ 1924{
1912 updateUnmanagedViews(); 1925 updateUnmanagedViews();
1913 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 1926 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
1914 if ( action == KOGlobals::EVENTDELETED ) { //delete 1927 if ( action == KOGlobals::EVENTDELETED ) { //delete
1915 mCalendar->checkAlarmForIncidence( 0, true ); 1928 mCalendar->checkAlarmForIncidence( 0, true );
1916 if ( mEventViewerDialog ) 1929 if ( mEventViewerDialog )
1917 mEventViewerDialog->hide(); 1930 mEventViewerDialog->hide();
1918 } 1931 }
1919 else 1932 else
1920 mCalendar->checkAlarmForIncidence( which , false ); 1933 mCalendar->checkAlarmForIncidence( which , false );
1921} 1934}
1922 1935
1923// most of the changeEventDisplays() right now just call the view's 1936// most of the changeEventDisplays() right now just call the view's
1924// total update mode, but they SHOULD be recoded to be more refresh-efficient. 1937// total update mode, but they SHOULD be recoded to be more refresh-efficient.
1925void CalendarView::changeEventDisplay(Event *which, int action) 1938void CalendarView::changeEventDisplay(Event *which, int action)
1926{ 1939{
1927 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 1940 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
1928 changeIncidenceDisplay((Incidence *)which, action); 1941 changeIncidenceDisplay((Incidence *)which, action);
1929 mDateNavigator->updateView(); 1942 mDateNavigator->updateView();
1930 //mDialogManager->updateSearchDialog(); 1943 //mDialogManager->updateSearchDialog();
1931 1944
1932 if (which) { 1945 if (which) {
1933 // If there is an event view visible update the display 1946 // If there is an event view visible update the display
1934 mViewManager->currentView()->changeEventDisplay(which,action); 1947 mViewManager->currentView()->changeEventDisplay(which,action);
1935 // TODO: check, if update needed 1948 // TODO: check, if update needed
1936 // if (which->getTodoStatus()) { 1949 // if (which->getTodoStatus()) {
1937 mTodoList->updateView(); 1950 mTodoList->updateView();
1938 // } 1951 // }
1939 } else { 1952 } else {
1940 mViewManager->currentView()->updateView(); 1953 mViewManager->currentView()->updateView();
1941 } 1954 }
1942} 1955}
1943 1956
1944 1957
1945void CalendarView::updateTodoViews() 1958void CalendarView::updateTodoViews()
1946{ 1959{
1947 1960
1948 mTodoList->updateView(); 1961 mTodoList->updateView();
1949 mViewManager->currentView()->updateView(); 1962 mViewManager->currentView()->updateView();
1950 1963
1951} 1964}
1952 1965
1953 1966
1954void CalendarView::updateView(const QDate &start, const QDate &end) 1967void CalendarView::updateView(const QDate &start, const QDate &end)
1955{ 1968{
1956 mTodoList->updateView(); 1969 mTodoList->updateView();
1957 mViewManager->updateView(start, end); 1970 mViewManager->updateView(start, end);
1958 //mDateNavigator->updateView(); 1971 //mDateNavigator->updateView();
1959} 1972}
1960 1973
1961void CalendarView::updateView() 1974void CalendarView::updateView()
1962{ 1975{
1963 DateList tmpList = mNavigator->selectedDates(); 1976 DateList tmpList = mNavigator->selectedDates();
1964 1977
1965 // We assume that the navigator only selects consecutive days. 1978 // We assume that the navigator only selects consecutive days.
1966 updateView( tmpList.first(), tmpList.last() ); 1979 updateView( tmpList.first(), tmpList.last() );
1967} 1980}
1968 1981
1969void CalendarView::updateUnmanagedViews() 1982void CalendarView::updateUnmanagedViews()
1970{ 1983{
1971 mDateNavigator->updateDayMatrix(); 1984 mDateNavigator->updateDayMatrix();
1972} 1985}
1973 1986
1974int CalendarView::msgItemDelete() 1987int CalendarView::msgItemDelete()
1975{ 1988{
1976 return KMessageBox::warningContinueCancel(this, 1989 return KMessageBox::warningContinueCancel(this,
1977 i18n("This item will be\npermanently deleted."), 1990 i18n("This item will be\npermanently deleted."),
1978 i18n("KO/Pi Confirmation"),i18n("Delete")); 1991 i18n("KO/Pi Confirmation"),i18n("Delete"));
1979} 1992}
1980 1993
1981 1994
1982void CalendarView::edit_cut() 1995void CalendarView::edit_cut()
1983{ 1996{
1984 Event *anEvent=0; 1997 Event *anEvent=0;
1985 1998
1986 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1999 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1987 2000
1988 if (mViewManager->currentView()->isEventView()) { 2001 if (mViewManager->currentView()->isEventView()) {
1989 if ( incidence && incidence->type() == "Event" ) { 2002 if ( incidence && incidence->type() == "Event" ) {
1990 anEvent = static_cast<Event *>(incidence); 2003 anEvent = static_cast<Event *>(incidence);
1991 } 2004 }
1992 } 2005 }
1993 2006
1994 if (!anEvent) { 2007 if (!anEvent) {
1995 KNotifyClient::beep(); 2008 KNotifyClient::beep();
1996 return; 2009 return;
1997 } 2010 }
1998 DndFactory factory( mCalendar ); 2011 DndFactory factory( mCalendar );
1999 factory.cutEvent(anEvent); 2012 factory.cutEvent(anEvent);
2000 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2013 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2001} 2014}
2002 2015
2003void CalendarView::edit_copy() 2016void CalendarView::edit_copy()
2004{ 2017{
2005 Event *anEvent=0; 2018 Event *anEvent=0;
2006 2019
2007 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2020 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2008 2021
2009 if (mViewManager->currentView()->isEventView()) { 2022 if (mViewManager->currentView()->isEventView()) {
2010 if ( incidence && incidence->type() == "Event" ) { 2023 if ( incidence && incidence->type() == "Event" ) {
2011 anEvent = static_cast<Event *>(incidence); 2024 anEvent = static_cast<Event *>(incidence);
2012 } 2025 }
2013 } 2026 }
2014 2027
2015 if (!anEvent) { 2028 if (!anEvent) {
2016 KNotifyClient::beep(); 2029 KNotifyClient::beep();
2017 return; 2030 return;
2018 } 2031 }
2019 DndFactory factory( mCalendar ); 2032 DndFactory factory( mCalendar );
2020 factory.copyEvent(anEvent); 2033 factory.copyEvent(anEvent);
2021} 2034}
2022 2035
2023void CalendarView::edit_paste() 2036void CalendarView::edit_paste()
2024{ 2037{
2025 QDate date = mNavigator->selectedDates().first(); 2038 QDate date = mNavigator->selectedDates().first();
2026 2039
2027 DndFactory factory( mCalendar ); 2040 DndFactory factory( mCalendar );
2028 Event *pastedEvent = factory.pasteEvent( date ); 2041 Event *pastedEvent = factory.pasteEvent( date );
2029 2042
2030 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2043 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2031} 2044}
2032 2045
2033void CalendarView::edit_options() 2046void CalendarView::edit_options()
2034{ 2047{
2035 mDialogManager->showOptionsDialog(); 2048 mDialogManager->showOptionsDialog();
2036 //writeSettings(); 2049 //writeSettings();
2037} 2050}
2038void CalendarView::edit_sync_options() 2051void CalendarView::edit_sync_options()
2039{ 2052{
2040 //mDialogManager->showSyncOptions(); 2053 //mDialogManager->showSyncOptions();
2041 //KOPrefs::instance()->mSyncAlgoPrefs 2054 //KOPrefs::instance()->mSyncAlgoPrefs
2042 QDialog dia( this, "dia", true ); 2055 QDialog dia( this, "dia", true );
2043 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2056 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2044 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2057 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2045 QVBoxLayout lay ( &dia ); 2058 QVBoxLayout lay ( &dia );
2046 lay.setSpacing( 2 ); 2059 lay.setSpacing( 2 );
2047 lay.setMargin( 3 ); 2060 lay.setMargin( 3 );
2048 lay.addWidget(&gr); 2061 lay.addWidget(&gr);
2049 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2062 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2050 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2063 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2051 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2064 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2052 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2065 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2053 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2066 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2054 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2067 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2055 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2068 //QRadioButton both( i18n("Take both on conflict"), &gr );
2056 QPushButton pb ( "OK", &dia); 2069 QPushButton pb ( "OK", &dia);
2057 lay.addWidget( &pb ); 2070 lay.addWidget( &pb );
2058 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2071 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2059 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { 2072 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2060 case 0: 2073 case 0:
2061 loc.setChecked( true); 2074 loc.setChecked( true);
2062 break; 2075 break;
2063 case 1: 2076 case 1:
2064 rem.setChecked( true ); 2077 rem.setChecked( true );
2065 break; 2078 break;
2066 case 2: 2079 case 2:
2067 newest.setChecked( true); 2080 newest.setChecked( true);
2068 break; 2081 break;
2069 case 3: 2082 case 3:
2070 ask.setChecked( true); 2083 ask.setChecked( true);
2071 break; 2084 break;
2072 case 4: 2085 case 4:
2073 f_loc.setChecked( true); 2086 f_loc.setChecked( true);
2074 break; 2087 break;
2075 case 5: 2088 case 5:
2076 f_rem.setChecked( true); 2089 f_rem.setChecked( true);
2077 break; 2090 break;
2078 case 6: 2091 case 6:
2079 // both.setChecked( true); 2092 // both.setChecked( true);
2080 break; 2093 break;
2081 default: 2094 default:
2082 break; 2095 break;
2083 } 2096 }
2084 if ( dia.exec() ) { 2097 if ( dia.exec() ) {
2085 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2098 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2086 } 2099 }
2087 2100
2088} 2101}
2089 2102
2090void CalendarView::slotSelectPickerDate( QDate d) 2103void CalendarView::slotSelectPickerDate( QDate d)
2091{ 2104{
2092 mDateFrame->hide(); 2105 mDateFrame->hide();
2093 if ( mDatePickerMode == 1 ) { 2106 if ( mDatePickerMode == 1 ) {
2094 mNavigator->slotDaySelect( d ); 2107 mNavigator->slotDaySelect( d );
2095 } else if ( mDatePickerMode == 2 ) { 2108 } else if ( mDatePickerMode == 2 ) {
2096 if ( mMoveIncidence->type() == "Todo" ) { 2109 if ( mMoveIncidence->type() == "Todo" ) {
2097 Todo * to = (Todo *) mMoveIncidence; 2110 Todo * to = (Todo *) mMoveIncidence;
2098 QTime tim; 2111 QTime tim;
2099 if ( to->hasDueDate() ) 2112 if ( to->hasDueDate() )
2100 tim = to->dtDue().time(); 2113 tim = to->dtDue().time();
2101 else { 2114 else {
2102 tim = QTime ( 0,0,0 ); 2115 tim = QTime ( 0,0,0 );
2103 to->setFloats( true ); 2116 to->setFloats( true );
2104 to->setHasDueDate( true ); 2117 to->setHasDueDate( true );
2105 } 2118 }
2106 QDateTime dt ( d,tim ); 2119 QDateTime dt ( d,tim );
2107 to->setDtDue( dt ); 2120 to->setDtDue( dt );
2108 todoChanged( to ); 2121 todoChanged( to );
2109 } else { 2122 } else {
2110 QTime tim = mMoveIncidence->dtStart().time(); 2123 QTime tim = mMoveIncidence->dtStart().time();
2111 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2124 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2112 QDateTime dt ( d,tim ); 2125 QDateTime dt ( d,tim );
2113 mMoveIncidence->setDtStart( dt ); 2126 mMoveIncidence->setDtStart( dt );
2114 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2127 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2115 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2128 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2116 } 2129 }
2117 2130
2118 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2131 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2119 } 2132 }
2120} 2133}
2121 2134
2122void CalendarView::removeCategories() 2135void CalendarView::removeCategories()
2123{ 2136{
2124 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2137 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2125 QStringList catList = KOPrefs::instance()->mCustomCategories; 2138 QStringList catList = KOPrefs::instance()->mCustomCategories;
2126 QStringList catIncList; 2139 QStringList catIncList;
2127 QStringList newCatList; 2140 QStringList newCatList;
2128 Incidence* inc = incList.first(); 2141 Incidence* inc = incList.first();
2129 int i; 2142 int i;
2130 int count = 0; 2143 int count = 0;
2131 while ( inc ) { 2144 while ( inc ) {
2132 newCatList.clear(); 2145 newCatList.clear();
2133 catIncList = inc->categories() ; 2146 catIncList = inc->categories() ;
2134 for( i = 0; i< catIncList.count(); ++i ) { 2147 for( i = 0; i< catIncList.count(); ++i ) {
2135 if ( catList.contains (catIncList[i])) 2148 if ( catList.contains (catIncList[i]))
2136 newCatList.append( catIncList[i] ); 2149 newCatList.append( catIncList[i] );
2137 } 2150 }
2138 newCatList.sort(); 2151 newCatList.sort();
2139 inc->setCategories( newCatList.join(",") ); 2152 inc->setCategories( newCatList.join(",") );
2140 inc = incList.next(); 2153 inc = incList.next();
2141 } 2154 }
2142} 2155}
2143 2156
2144int CalendarView::addCategories() 2157int CalendarView::addCategories()
2145{ 2158{
2146 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2159 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2147 QStringList catList = KOPrefs::instance()->mCustomCategories; 2160 QStringList catList = KOPrefs::instance()->mCustomCategories;
2148 QStringList catIncList; 2161 QStringList catIncList;
2149 Incidence* inc = incList.first(); 2162 Incidence* inc = incList.first();
2150 int i; 2163 int i;
2151 int count = 0; 2164 int count = 0;
2152 while ( inc ) { 2165 while ( inc ) {
2153 catIncList = inc->categories() ; 2166 catIncList = inc->categories() ;
2154 for( i = 0; i< catIncList.count(); ++i ) { 2167 for( i = 0; i< catIncList.count(); ++i ) {
2155 if ( !catList.contains (catIncList[i])) { 2168 if ( !catList.contains (catIncList[i])) {
2156 catList.append( catIncList[i] ); 2169 catList.append( catIncList[i] );
2157 //qDebug("add cat %s ", catIncList[i].latin1()); 2170 //qDebug("add cat %s ", catIncList[i].latin1());
2158 ++count; 2171 ++count;
2159 } 2172 }
2160 } 2173 }
2161 inc = incList.next(); 2174 inc = incList.next();
2162 } 2175 }
2163 catList.sort(); 2176 catList.sort();
2164 KOPrefs::instance()->mCustomCategories = catList; 2177 KOPrefs::instance()->mCustomCategories = catList;
2165 return count; 2178 return count;
2166} 2179}
2167 2180
2168void CalendarView::manageCategories() 2181void CalendarView::manageCategories()
2169{ 2182{
2170 KOCatPrefs* cp = new KOCatPrefs(); 2183 KOCatPrefs* cp = new KOCatPrefs();
2171 cp->show(); 2184 cp->show();
2172 int w =cp->sizeHint().width() ; 2185 int w =cp->sizeHint().width() ;
2173 int h = cp->sizeHint().height() ; 2186 int h = cp->sizeHint().height() ;
2174 int dw = QApplication::desktop()->width(); 2187 int dw = QApplication::desktop()->width();
2175 int dh = QApplication::desktop()->height(); 2188 int dh = QApplication::desktop()->height();
2176 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2189 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2177 if ( !cp->exec() ) { 2190 if ( !cp->exec() ) {
2178 delete cp; 2191 delete cp;
2179 return; 2192 return;
2180 } 2193 }
2181 int count = 0; 2194 int count = 0;
2182 if ( cp->addCat() ) { 2195 if ( cp->addCat() ) {
2183 count = addCategories(); 2196 count = addCategories();
2184 if ( count ) { 2197 if ( count ) {
2185 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2198 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2186 writeSettings(); 2199 writeSettings();
2187 } 2200 }
2188 } else { 2201 } else {
2189 removeCategories(); 2202 removeCategories();
2190 updateView(); 2203 updateView();
2191 } 2204 }
2192 delete cp; 2205 delete cp;
2193} 2206}
2194 2207
2195void CalendarView::beamIncidence(Incidence * Inc) 2208void CalendarView::beamIncidence(Incidence * Inc)
2196{ 2209{
2197 QPtrList<Incidence> delSel ; 2210 QPtrList<Incidence> delSel ;
2198 delSel.append(Inc); 2211 delSel.append(Inc);
2199 beamIncidenceList( delSel ); 2212 beamIncidenceList( delSel );
2200} 2213}
2201void CalendarView::beamCalendar() 2214void CalendarView::beamCalendar()
2202{ 2215{
2203 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2216 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2204 //qDebug("beamCalendar() "); 2217 //qDebug("beamCalendar() ");
2205 beamIncidenceList( delSel ); 2218 beamIncidenceList( delSel );
2206} 2219}
2207void CalendarView::beamFilteredCalendar() 2220void CalendarView::beamFilteredCalendar()
2208{ 2221{
2209 QPtrList<Incidence> delSel = mCalendar->incidences(); 2222 QPtrList<Incidence> delSel = mCalendar->incidences();
2210 //qDebug("beamFilteredCalendar() "); 2223 //qDebug("beamFilteredCalendar() ");
2211 beamIncidenceList( delSel ); 2224 beamIncidenceList( delSel );
2212} 2225}
2213void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2226void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2214{ 2227{
2215 if ( beamDialog->exec () == QDialog::Rejected ) 2228 if ( beamDialog->exec () == QDialog::Rejected )
2216 return; 2229 return;
2217 2230
2218 QString fn = "/tmp/kopibeamfile"; 2231 QString fn = "/tmp/kopibeamfile";
2219 QString mes; 2232 QString mes;
2220 bool createbup = true; 2233 bool createbup = true;
2221 if ( createbup ) { 2234 if ( createbup ) {
2222 QString description = "\n"; 2235 QString description = "\n";
2223 CalendarLocal* cal = new CalendarLocal(); 2236 CalendarLocal* cal = new CalendarLocal();
2224 if ( beamDialog->beamLocal() ) 2237 if ( beamDialog->beamLocal() )
2225 cal->setLocalTime(); 2238 cal->setLocalTime();
2226 else 2239 else
2227 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2240 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2228 Incidence *incidence = delSel.first(); 2241 Incidence *incidence = delSel.first();
2229 bool addText = false; 2242 bool addText = false;
2230 if ( delSel.count() < 10 ) 2243 if ( delSel.count() < 10 )
2231 addText = true; 2244 addText = true;
2232 else { 2245 else {
2233 description.sprintf(i18n(" %d items?"),delSel.count() ); 2246 description.sprintf(i18n(" %d items?"),delSel.count() );
2234 } 2247 }
2235 while ( incidence ) { 2248 while ( incidence ) {
2236 Incidence *in = incidence->clone(); 2249 Incidence *in = incidence->clone();
2237 if ( addText ) 2250 if ( addText )
2238 description += in->summary() + "\n"; 2251 description += in->summary() + "\n";
2239 cal->addIncidence( in ); 2252 cal->addIncidence( in );
2240 incidence = delSel.next(); 2253 incidence = delSel.next();
2241 } 2254 }
2242 if ( beamDialog->beamVcal() ) { 2255 if ( beamDialog->beamVcal() ) {
2243 fn += ".vcs"; 2256 fn += ".vcs";
2244 FileStorage storage( cal, fn, new VCalFormat ); 2257 FileStorage storage( cal, fn, new VCalFormat );
2245 storage.save(); 2258 storage.save();
2246 } else { 2259 } else {
2247 fn += ".ics"; 2260 fn += ".ics";
2248 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2261 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2249 storage.save(); 2262 storage.save();
2250 } 2263 }
2251 delete cal; 2264 delete cal;
2252 mes = i18n("KO/Pi: Ready for beaming"); 2265 mes = i18n("KO/Pi: Ready for beaming");
2253 setCaption(mes); 2266 setCaption(mes);
2254 2267
2255#ifndef DESKTOP_VERSION 2268#ifndef DESKTOP_VERSION
2256 Ir *ir = new Ir( this ); 2269 Ir *ir = new Ir( this );
2257 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2270 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2258 ir->send( fn, description, "text/x-vCalendar" ); 2271 ir->send( fn, description, "text/x-vCalendar" );
2259#endif 2272#endif
2260 } 2273 }
2261} 2274}
2262void CalendarView::beamDone( Ir *ir ) 2275void CalendarView::beamDone( Ir *ir )
2263{ 2276{
2264#ifndef DESKTOP_VERSION 2277#ifndef DESKTOP_VERSION
2265 delete ir; 2278 delete ir;
2266#endif 2279#endif
2267} 2280}
2268 2281
2269void CalendarView::moveIncidence(Incidence * inc ) 2282void CalendarView::moveIncidence(Incidence * inc )
2270{ 2283{
2271 if ( !inc ) return; 2284 if ( !inc ) return;
2272 // qDebug("showDatePickerForIncidence( ) "); 2285 // qDebug("showDatePickerForIncidence( ) ");
2273 if ( mDateFrame->isVisible() ) 2286 if ( mDateFrame->isVisible() )
2274 mDateFrame->hide(); 2287 mDateFrame->hide();
2275 else { 2288 else {
2276 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2289 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2277 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2290 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2278 int dw = QApplication::desktop()->width(); 2291 int dw = QApplication::desktop()->width();
2279 int dh = QApplication::desktop()->height(); 2292 int dh = QApplication::desktop()->height();
2280 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2293 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2281 mDateFrame->show(); 2294 mDateFrame->show();
2282 } 2295 }
2283 mDatePickerMode = 2; 2296 mDatePickerMode = 2;
2284 mMoveIncidence = inc ; 2297 mMoveIncidence = inc ;
2285 QDate da; 2298 QDate da;
2286 if ( mMoveIncidence->type() == "Todo" ) { 2299 if ( mMoveIncidence->type() == "Todo" ) {
2287 Todo * to = (Todo *) mMoveIncidence; 2300 Todo * to = (Todo *) mMoveIncidence;
2288 if ( to->hasDueDate() ) 2301 if ( to->hasDueDate() )
2289 da = to->dtDue().date(); 2302 da = to->dtDue().date();
2290 else 2303 else
2291 da = QDate::currentDate(); 2304 da = QDate::currentDate();
2292 } else { 2305 } else {
2293 da = mMoveIncidence->dtStart().date(); 2306 da = mMoveIncidence->dtStart().date();
2294 } 2307 }
2295 mDatePicker->setDate( da ); 2308 mDatePicker->setDate( da );
2296} 2309}
2297void CalendarView::showDatePicker( ) 2310void CalendarView::showDatePicker( )
2298{ 2311{
2299 //qDebug("CalendarView::showDatePicker( ) "); 2312 //qDebug("CalendarView::showDatePicker( ) ");
2300 if ( mDateFrame->isVisible() ) 2313 if ( mDateFrame->isVisible() )
2301 mDateFrame->hide(); 2314 mDateFrame->hide();
2302 else { 2315 else {
2303 int w =mDatePicker->sizeHint().width() ; 2316 int w =mDatePicker->sizeHint().width() ;
2304 int h = mDatePicker->sizeHint().height() ; 2317 int h = mDatePicker->sizeHint().height() ;
2305 int dw = QApplication::desktop()->width(); 2318 int dw = QApplication::desktop()->width();
2306 int dh = QApplication::desktop()->height(); 2319 int dh = QApplication::desktop()->height();
2307 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2320 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2308 mDateFrame->show(); 2321 mDateFrame->show();
2309 } 2322 }
2310 mDatePickerMode = 1; 2323 mDatePickerMode = 1;
2311 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2324 mDatePicker->setDate( mNavigator->selectedDates().first() );
2312} 2325}
2313 2326
2314void CalendarView::showEventEditor() 2327void CalendarView::showEventEditor()
2315{ 2328{
2316#ifdef DESKTOP_VERSION 2329#ifdef DESKTOP_VERSION
2317 mEventEditor->show(); 2330 mEventEditor->show();
2318#else 2331#else
2319 mEventEditor->showMaximized(); 2332 mEventEditor->showMaximized();
2320#endif 2333#endif
2321} 2334}
2322void CalendarView::showTodoEditor() 2335void CalendarView::showTodoEditor()
2323{ 2336{
2324#ifdef DESKTOP_VERSION 2337#ifdef DESKTOP_VERSION
2325 mTodoEditor->show(); 2338 mTodoEditor->show();
2326#else 2339#else
2327 mTodoEditor->showMaximized(); 2340 mTodoEditor->showMaximized();
2328#endif 2341#endif
2329} 2342}
2330void CalendarView::cancelIncidence(Incidence * inc ) 2343void CalendarView::cancelIncidence(Incidence * inc )
2331{ 2344{
2332 inc->setCancelled( ! inc->cancelled() ); 2345 inc->setCancelled( ! inc->cancelled() );
2333 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2346 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2334 updateView(); 2347 updateView();
2335} 2348}
2336void CalendarView::cloneIncidence(Incidence * orgInc ) 2349void CalendarView::cloneIncidence(Incidence * orgInc )
2337{ 2350{
2338 Incidence * newInc = orgInc->clone(); 2351 Incidence * newInc = orgInc->clone();
2339 newInc->recreate(); 2352 newInc->recreate();
2340 2353
2341 if ( newInc->type() == "Todo" ) { 2354 if ( newInc->type() == "Todo" ) {
2342 Todo* t = (Todo*) newInc; 2355 Todo* t = (Todo*) newInc;
2343 mTodoEditor->editTodo( t ); 2356 mTodoEditor->editTodo( t );
2344 showTodoEditor(); 2357 showTodoEditor();
2345 if ( mTodoEditor->exec() ) { 2358 if ( mTodoEditor->exec() ) {
2346 mCalendar->addTodo( t ); 2359 mCalendar->addTodo( t );
2347 updateView(); 2360 updateView();
2348 } else { 2361 } else {
2349 delete t; 2362 delete t;
2350 } 2363 }
2351 } 2364 }
2352 else { 2365 else {
2353 Event* e = (Event*) newInc; 2366 Event* e = (Event*) newInc;
2354 mEventEditor->editEvent( e ); 2367 mEventEditor->editEvent( e );
2355 showEventEditor(); 2368 showEventEditor();
2356 if ( mEventEditor->exec() ) { 2369 if ( mEventEditor->exec() ) {
2357 mCalendar->addEvent( e ); 2370 mCalendar->addEvent( e );
2358 updateView(); 2371 updateView();
2359 } else { 2372 } else {
2360 delete e; 2373 delete e;
2361 } 2374 }
2362 } 2375 }
2363} 2376}
2364 2377
2365void CalendarView::newEvent() 2378void CalendarView::newEvent()
2366{ 2379{
2367 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2380 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2368 KOAgendaView *aView = mViewManager->agendaView(); 2381 KOAgendaView *aView = mViewManager->agendaView();
2369 if (aView) { 2382 if (aView) {
2370 if (aView->selectionStart().isValid()) { 2383 if (aView->selectionStart().isValid()) {
2371 if (aView->selectedIsAllDay()) { 2384 if (aView->selectedIsAllDay()) {
2372 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2385 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2373 } else { 2386 } else {
2374 newEvent(aView->selectionStart(),aView->selectionEnd()); 2387 newEvent(aView->selectionStart(),aView->selectionEnd());
2375 } 2388 }
2376 return; 2389 return;
2377 } 2390 }
2378 } 2391 }
2379 2392
2380 QDate date = mNavigator->selectedDates().first(); 2393 QDate date = mNavigator->selectedDates().first();
2381 QDateTime current = QDateTime::currentDateTime(); 2394 QDateTime current = QDateTime::currentDateTime();
2382 if ( date <= current.date() ) { 2395 if ( date <= current.date() ) {
2383 int hour = current.time().hour() +1; 2396 int hour = current.time().hour() +1;
2384 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2397 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2385 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2398 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2386 } else 2399 } else
2387 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2400 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2388 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2401 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2389 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2402 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2390} 2403}
2391 2404
2392void CalendarView::newEvent(QDateTime fh) 2405void CalendarView::newEvent(QDateTime fh)
2393{ 2406{
2394 newEvent(fh, 2407 newEvent(fh,
2395 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2408 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2396} 2409}
2397 2410
2398void CalendarView::newEvent(QDate dt) 2411void CalendarView::newEvent(QDate dt)
2399{ 2412{
2400 newEvent(QDateTime(dt, QTime(0,0,0)), 2413 newEvent(QDateTime(dt, QTime(0,0,0)),
2401 QDateTime(dt, QTime(0,0,0)), true); 2414 QDateTime(dt, QTime(0,0,0)), true);
2402} 2415}
2403 2416
2404void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2417void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2405{ 2418{
2406 2419
2407 mEventEditor->newEvent(fromHint,toHint,allDay); 2420 mEventEditor->newEvent(fromHint,toHint,allDay);
2408 if ( mFilterView->filtersEnabled() ) { 2421 if ( mFilterView->filtersEnabled() ) {
2409 CalFilter *filter = mFilterView->selectedFilter(); 2422 CalFilter *filter = mFilterView->selectedFilter();
2410 if (filter && filter->showCategories()) { 2423 if (filter && filter->showCategories()) {
2411 mEventEditor->setCategories(filter->categoryList().join(",") ); 2424 mEventEditor->setCategories(filter->categoryList().join(",") );
2412 } 2425 }
2413 if ( filter ) 2426 if ( filter )
2414 mEventEditor->setSecrecy( filter->getSecrecy() ); 2427 mEventEditor->setSecrecy( filter->getSecrecy() );
2415 } 2428 }
2416 showEventEditor(); 2429 showEventEditor();
2417} 2430}
2418void CalendarView::todoAdded(Todo * t) 2431void CalendarView::todoAdded(Todo * t)
2419{ 2432{
2420 2433
2421 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2434 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2422 updateTodoViews(); 2435 updateTodoViews();
2423} 2436}
2424void CalendarView::todoChanged(Todo * t) 2437void CalendarView::todoChanged(Todo * t)
2425{ 2438{
2426 emit todoModified( t, 4 ); 2439 emit todoModified( t, 4 );
2427 // updateTodoViews(); 2440 // updateTodoViews();
2428} 2441}
2429void CalendarView::todoToBeDeleted(Todo *) 2442void CalendarView::todoToBeDeleted(Todo *)
2430{ 2443{
2431 //qDebug("todoToBeDeleted(Todo *) "); 2444 //qDebug("todoToBeDeleted(Todo *) ");
2432 updateTodoViews(); 2445 updateTodoViews();
2433} 2446}
2434void CalendarView::todoDeleted() 2447void CalendarView::todoDeleted()
2435{ 2448{
2436 //qDebug(" todoDeleted()"); 2449 //qDebug(" todoDeleted()");
2437 updateTodoViews(); 2450 updateTodoViews();
2438} 2451}
2439 2452
2440 2453
2441 2454
2442void CalendarView::newTodo() 2455void CalendarView::newTodo()
2443{ 2456{
2444 2457
2445 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2458 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2446 if ( mFilterView->filtersEnabled() ) { 2459 if ( mFilterView->filtersEnabled() ) {
2447 CalFilter *filter = mFilterView->selectedFilter(); 2460 CalFilter *filter = mFilterView->selectedFilter();
2448 if (filter && filter->showCategories()) { 2461 if (filter && filter->showCategories()) {
2449 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2462 mTodoEditor->setCategories(filter->categoryList().join(",") );
2450 } 2463 }
2451 if ( filter ) 2464 if ( filter )
2452 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2465 mTodoEditor->setSecrecy( filter->getSecrecy() );
2453 } 2466 }
2454 showTodoEditor(); 2467 showTodoEditor();
2455} 2468}
2456 2469
2457void CalendarView::newSubTodo() 2470void CalendarView::newSubTodo()
2458{ 2471{
2459 Todo *todo = selectedTodo(); 2472 Todo *todo = selectedTodo();
2460 if ( todo ) newSubTodo( todo ); 2473 if ( todo ) newSubTodo( todo );
2461} 2474}
2462 2475
2463void CalendarView::newSubTodo(Todo *parentEvent) 2476void CalendarView::newSubTodo(Todo *parentEvent)
2464{ 2477{
2465 2478
2466 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2479 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2467 showTodoEditor(); 2480 showTodoEditor();
2468} 2481}
2469 2482
2470void CalendarView::newFloatingEvent() 2483void CalendarView::newFloatingEvent()
2471{ 2484{
2472 DateList tmpList = mNavigator->selectedDates(); 2485 DateList tmpList = mNavigator->selectedDates();
2473 QDate date = tmpList.first(); 2486 QDate date = tmpList.first();
2474 2487
2475 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2488 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2476 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2489 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2477} 2490}
2478 2491
2479 2492
2480void CalendarView::editEvent( Event *event ) 2493void CalendarView::editEvent( Event *event )
2481{ 2494{
2482 2495
2483 if ( !event ) return; 2496 if ( !event ) return;
2484 if ( event->isReadOnly() ) { 2497 if ( event->isReadOnly() ) {
2485 showEvent( event ); 2498 showEvent( event );
2486 return; 2499 return;
2487 } 2500 }
2488 mEventEditor->editEvent( event , mFlagEditDescription); 2501 mEventEditor->editEvent( event , mFlagEditDescription);
2489 showEventEditor(); 2502 showEventEditor();
2490} 2503}
2491void CalendarView::editJournal( Journal *jour ) 2504void CalendarView::editJournal( Journal *jour )
2492{ 2505{
2493 if ( !jour ) return; 2506 if ( !jour ) return;
2494 mDialogManager->hideSearchDialog(); 2507 mDialogManager->hideSearchDialog();
2495 mViewManager->showJournalView(); 2508 mViewManager->showJournalView();
2496 mNavigator->slotDaySelect( jour->dtStart().date() ); 2509 mNavigator->slotDaySelect( jour->dtStart().date() );
2497} 2510}
2498void CalendarView::editTodo( Todo *todo ) 2511void CalendarView::editTodo( Todo *todo )
2499{ 2512{
2500 if ( !todo ) return; 2513 if ( !todo ) return;
2501 2514
2502 if ( todo->isReadOnly() ) { 2515 if ( todo->isReadOnly() ) {
2503 showTodo( todo ); 2516 showTodo( todo );
2504 return; 2517 return;
2505 } 2518 }
2506 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2519 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2507 showTodoEditor(); 2520 showTodoEditor();
2508 2521
2509} 2522}
2510 2523
2511KOEventViewerDialog* CalendarView::getEventViewerDialog() 2524KOEventViewerDialog* CalendarView::getEventViewerDialog()
2512{ 2525{
2513 if ( !mEventViewerDialog ) { 2526 if ( !mEventViewerDialog ) {
2514 mEventViewerDialog = new KOEventViewerDialog(this); 2527 mEventViewerDialog = new KOEventViewerDialog(this);
2515 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2528 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2516 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2529 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2517 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2530 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2518 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2531 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2519 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2532 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2520 viewManager(), SLOT( showAgendaView( bool ) ) ); 2533 viewManager(), SLOT( showAgendaView( bool ) ) );
2521 mEventViewerDialog->resize( 640, 480 ); 2534 mEventViewerDialog->resize( 640, 480 );
2522 2535
2523 } 2536 }
2524 return mEventViewerDialog; 2537 return mEventViewerDialog;
2525} 2538}
2526void CalendarView::showEvent(Event *event) 2539void CalendarView::showEvent(Event *event)
2527{ 2540{
2528 getEventViewerDialog()->setEvent(event); 2541 getEventViewerDialog()->setEvent(event);
2529 getEventViewerDialog()->showMe(); 2542 getEventViewerDialog()->showMe();
2530} 2543}
2531 2544
2532void CalendarView::showTodo(Todo *event) 2545void CalendarView::showTodo(Todo *event)
2533{ 2546{
2534 getEventViewerDialog()->setTodo(event); 2547 getEventViewerDialog()->setTodo(event);
2535 getEventViewerDialog()->showMe(); 2548 getEventViewerDialog()->showMe();
2536} 2549}
2537void CalendarView::showJournal( Journal *jour ) 2550void CalendarView::showJournal( Journal *jour )
2538{ 2551{
2539 getEventViewerDialog()->setJournal(jour); 2552 getEventViewerDialog()->setJournal(jour);
2540 getEventViewerDialog()->showMe(); 2553 getEventViewerDialog()->showMe();
2541 2554
2542} 2555}
2543// void CalendarView::todoModified (Todo *event, int changed) 2556// void CalendarView::todoModified (Todo *event, int changed)
2544// { 2557// {
2545// // if (mDialogList.find (event) != mDialogList.end ()) { 2558// // if (mDialogList.find (event) != mDialogList.end ()) {
2546// // kdDebug() << "Todo modified and open" << endl; 2559// // kdDebug() << "Todo modified and open" << endl;
2547// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2560// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2548// // temp->modified (changed); 2561// // temp->modified (changed);
2549 2562
2550// // } 2563// // }
2551 2564
2552// mViewManager->updateView(); 2565// mViewManager->updateView();
2553// } 2566// }
2554 2567
2555void CalendarView::appointment_show() 2568void CalendarView::appointment_show()
2556{ 2569{
2557 Event *anEvent = 0; 2570 Event *anEvent = 0;
2558 2571
2559 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2572 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2560 2573
2561 if (mViewManager->currentView()->isEventView()) { 2574 if (mViewManager->currentView()->isEventView()) {
2562 if ( incidence && incidence->type() == "Event" ) { 2575 if ( incidence && incidence->type() == "Event" ) {
2563 anEvent = static_cast<Event *>(incidence); 2576 anEvent = static_cast<Event *>(incidence);
2564 } 2577 }
2565 } 2578 }
2566 2579
2567 if (!anEvent) { 2580 if (!anEvent) {
2568 KNotifyClient::beep(); 2581 KNotifyClient::beep();
2569 return; 2582 return;
2570 } 2583 }
2571 2584
2572 showEvent(anEvent); 2585 showEvent(anEvent);
2573} 2586}
2574 2587
2575void CalendarView::appointment_edit() 2588void CalendarView::appointment_edit()
2576{ 2589{
2577 Event *anEvent = 0; 2590 Event *anEvent = 0;
2578 2591
2579 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2592 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2580 2593
2581 if (mViewManager->currentView()->isEventView()) { 2594 if (mViewManager->currentView()->isEventView()) {
2582 if ( incidence && incidence->type() == "Event" ) { 2595 if ( incidence && incidence->type() == "Event" ) {
2583 anEvent = static_cast<Event *>(incidence); 2596 anEvent = static_cast<Event *>(incidence);
2584 } 2597 }
2585 } 2598 }
2586 2599
2587 if (!anEvent) { 2600 if (!anEvent) {
2588 KNotifyClient::beep(); 2601 KNotifyClient::beep();
2589 return; 2602 return;
2590 } 2603 }
2591 2604
2592 editEvent(anEvent); 2605 editEvent(anEvent);
2593} 2606}
2594 2607
2595void CalendarView::appointment_delete() 2608void CalendarView::appointment_delete()
2596{ 2609{
2597 Event *anEvent = 0; 2610 Event *anEvent = 0;
2598 2611
2599 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2612 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2600 2613
2601 if (mViewManager->currentView()->isEventView()) { 2614 if (mViewManager->currentView()->isEventView()) {
2602 if ( incidence && incidence->type() == "Event" ) { 2615 if ( incidence && incidence->type() == "Event" ) {
2603 anEvent = static_cast<Event *>(incidence); 2616 anEvent = static_cast<Event *>(incidence);
2604 } 2617 }
2605 } 2618 }
2606 2619
2607 if (!anEvent) { 2620 if (!anEvent) {
2608 KNotifyClient::beep(); 2621 KNotifyClient::beep();
2609 return; 2622 return;
2610 } 2623 }
2611 2624
2612 deleteEvent(anEvent); 2625 deleteEvent(anEvent);
2613} 2626}
2614 2627
2615void CalendarView::todo_unsub(Todo *anTodo ) 2628void CalendarView::todo_unsub(Todo *anTodo )
2616{ 2629{
2617 // Todo *anTodo = selectedTodo(); 2630 // Todo *anTodo = selectedTodo();
2618 if (!anTodo) return; 2631 if (!anTodo) return;
2619 if (!anTodo->relatedTo()) return; 2632 if (!anTodo->relatedTo()) return;
2620 anTodo->relatedTo()->removeRelation(anTodo); 2633 anTodo->relatedTo()->removeRelation(anTodo);
2621 anTodo->setRelatedTo(0); 2634 anTodo->setRelatedTo(0);
2622 anTodo->updated(); 2635 anTodo->updated();
2623 anTodo->setRelatedToUid(""); 2636 anTodo->setRelatedToUid("");
2624 setModified(true); 2637 setModified(true);
2625 updateView(); 2638 updateView();
2626} 2639}
2627 2640
2628void CalendarView::deleteTodo(Todo *todo) 2641void CalendarView::deleteTodo(Todo *todo)
2629{ 2642{
2630 if (!todo) { 2643 if (!todo) {
2631 KNotifyClient::beep(); 2644 KNotifyClient::beep();
2632 return; 2645 return;
2633 } 2646 }
2634 if (KOPrefs::instance()->mConfirm) { 2647 if (KOPrefs::instance()->mConfirm) {
2635 switch (msgItemDelete()) { 2648 switch (msgItemDelete()) {
2636 case KMessageBox::Continue: // OK 2649 case KMessageBox::Continue: // OK
2637 if (!todo->relations().isEmpty()) { 2650 if (!todo->relations().isEmpty()) {
2638 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2651 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2639 i18n("Delete To-Do")); 2652 i18n("Delete To-Do"));
2640 } else { 2653 } else {
2641 checkExternalId( todo ); 2654 checkExternalId( todo );
2642 calendar()->deleteTodo(todo); 2655 calendar()->deleteTodo(todo);
2643 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2656 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2644 updateView(); 2657 updateView();
2645 } 2658 }
2646 break; 2659 break;
2647 } // switch 2660 } // switch
2648 } else { 2661 } else {
2649 if (!todo->relations().isEmpty()) { 2662 if (!todo->relations().isEmpty()) {
2650 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2663 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2651 i18n("Delete To-Do")); 2664 i18n("Delete To-Do"));
2652 } else { 2665 } else {
2653 checkExternalId( todo ); 2666 checkExternalId( todo );
2654 mCalendar->deleteTodo(todo); 2667 mCalendar->deleteTodo(todo);
2655 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2668 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2656 updateView(); 2669 updateView();
2657 } 2670 }
2658 } 2671 }
2659 emit updateSearchDialog(); 2672 emit updateSearchDialog();
2660} 2673}
2661void CalendarView::deleteJournal(Journal *jour) 2674void CalendarView::deleteJournal(Journal *jour)
2662{ 2675{
2663 if (!jour) { 2676 if (!jour) {
2664 KNotifyClient::beep(); 2677 KNotifyClient::beep();
2665 return; 2678 return;
2666 } 2679 }
2667 if (KOPrefs::instance()->mConfirm) { 2680 if (KOPrefs::instance()->mConfirm) {
2668 switch (msgItemDelete()) { 2681 switch (msgItemDelete()) {
2669 case KMessageBox::Continue: // OK 2682 case KMessageBox::Continue: // OK
2670 calendar()->deleteJournal(jour); 2683 calendar()->deleteJournal(jour);
2671 updateView(); 2684 updateView();
2672 break; 2685 break;
2673 } // switch 2686 } // switch
2674 } else { 2687 } else {
2675 calendar()->deleteJournal(jour);; 2688 calendar()->deleteJournal(jour);;
2676 updateView(); 2689 updateView();
2677 } 2690 }
2678 emit updateSearchDialog(); 2691 emit updateSearchDialog();
2679} 2692}
2680 2693
2681void CalendarView::deleteEvent(Event *anEvent) 2694void CalendarView::deleteEvent(Event *anEvent)
2682{ 2695{
2683 if (!anEvent) { 2696 if (!anEvent) {
2684 KNotifyClient::beep(); 2697 KNotifyClient::beep();
2685 return; 2698 return;
2686 } 2699 }
2687 2700
2688 if (anEvent->recurrence()->doesRecur()) { 2701 if (anEvent->recurrence()->doesRecur()) {
2689 QDate itemDate = mViewManager->currentSelectionDate(); 2702 QDate itemDate = mViewManager->currentSelectionDate();
2690 int km; 2703 int km;
2691 if (!itemDate.isValid()) { 2704 if (!itemDate.isValid()) {
2692 //kdDebug() << "Date Not Valid" << endl; 2705 //kdDebug() << "Date Not Valid" << endl;
2693 if (KOPrefs::instance()->mConfirm) { 2706 if (KOPrefs::instance()->mConfirm) {
2694 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2707 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2695 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2708 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2696 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2709 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2697 if ( km == KMessageBox::Continue ) 2710 if ( km == KMessageBox::Continue )
2698 km = KMessageBox::No; // No = all below 2711 km = KMessageBox::No; // No = all below
2699 } else 2712 } else
2700 km = KMessageBox::No; 2713 km = KMessageBox::No;
2701 } else { 2714 } else {
2702 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2715 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2703 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2716 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2704 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2717 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2705 i18n("KO/Pi Confirmation"),i18n("Current"), 2718 i18n("KO/Pi Confirmation"),i18n("Current"),
2706 i18n("All")); 2719 i18n("All"));
2707 } 2720 }
2708 switch(km) { 2721 switch(km) {
2709 2722
2710 case KMessageBox::No: // Continue // all 2723 case KMessageBox::No: // Continue // all
2711 //qDebug("KMessageBox::No "); 2724 //qDebug("KMessageBox::No ");
2712 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2725 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2713 schedule(Scheduler::Cancel,anEvent); 2726 schedule(Scheduler::Cancel,anEvent);
2714 2727
2715 checkExternalId( anEvent); 2728 checkExternalId( anEvent);
2716 mCalendar->deleteEvent(anEvent); 2729 mCalendar->deleteEvent(anEvent);
2717 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2730 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2718 break; 2731 break;
2719 2732
2720 // Disabled because it does not work 2733 // Disabled because it does not work
2721 //#if 0 2734 //#if 0
2722 case KMessageBox::Yes: // just this one 2735 case KMessageBox::Yes: // just this one
2723 //QDate qd = mNavigator->selectedDates().first(); 2736 //QDate qd = mNavigator->selectedDates().first();
2724 //if (!qd.isValid()) { 2737 //if (!qd.isValid()) {
2725 // kdDebug() << "no date selected, or invalid date" << endl; 2738 // kdDebug() << "no date selected, or invalid date" << endl;
2726 // KNotifyClient::beep(); 2739 // KNotifyClient::beep();
2727 // return; 2740 // return;
2728 //} 2741 //}
2729 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2742 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2730 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2743 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2731 anEvent->addExDate(itemDate); 2744 anEvent->addExDate(itemDate);
2732 int duration = anEvent->recurrence()->duration(); 2745 int duration = anEvent->recurrence()->duration();
2733 if ( duration > 0 ) { 2746 if ( duration > 0 ) {
2734 anEvent->recurrence()->setDuration( duration - 1 ); 2747 anEvent->recurrence()->setDuration( duration - 1 );
2735 } 2748 }
2736 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2749 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2737 } 2750 }
2738 break; 2751 break;
2739 //#endif 2752 //#endif
2740 } // switch 2753 } // switch
2741 } else { 2754 } else {
2742 if (KOPrefs::instance()->mConfirm) { 2755 if (KOPrefs::instance()->mConfirm) {
2743 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2756 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2744 i18n("\nAre you sure you want\nto delete this event?"), 2757 i18n("\nAre you sure you want\nto delete this event?"),
2745 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2758 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2746 case KMessageBox::Continue: // OK 2759 case KMessageBox::Continue: // OK
2747 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2760 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2748 schedule(Scheduler::Cancel,anEvent); 2761 schedule(Scheduler::Cancel,anEvent);
2749 checkExternalId( anEvent); 2762 checkExternalId( anEvent);
2750 mCalendar->deleteEvent(anEvent); 2763 mCalendar->deleteEvent(anEvent);
2751 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2764 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2752 break; 2765 break;
2753 } // switch 2766 } // switch
2754 } else { 2767 } else {
2755 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2768 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2756 schedule(Scheduler::Cancel,anEvent); 2769 schedule(Scheduler::Cancel,anEvent);
2757 checkExternalId( anEvent); 2770 checkExternalId( anEvent);
2758 mCalendar->deleteEvent(anEvent); 2771 mCalendar->deleteEvent(anEvent);
2759 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2772 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2760 } 2773 }
2761 } // if-else 2774 } // if-else
2762 emit updateSearchDialog(); 2775 emit updateSearchDialog();
2763} 2776}
2764 2777
2765bool CalendarView::deleteEvent(const QString &uid) 2778bool CalendarView::deleteEvent(const QString &uid)
2766{ 2779{
2767 Event *ev = mCalendar->event(uid); 2780 Event *ev = mCalendar->event(uid);
2768 if (ev) { 2781 if (ev) {
2769 deleteEvent(ev); 2782 deleteEvent(ev);
2770 return true; 2783 return true;
2771 } else { 2784 } else {
2772 return false; 2785 return false;
2773 } 2786 }
2774} 2787}
2775 2788
2776/*****************************************************************************/ 2789/*****************************************************************************/
2777 2790
2778void CalendarView::action_mail() 2791void CalendarView::action_mail()
2779{ 2792{
2780#ifndef KORG_NOMAIL 2793#ifndef KORG_NOMAIL
2781 KOMailClient mailClient; 2794 KOMailClient mailClient;
2782 2795
2783 Incidence *incidence = currentSelection(); 2796 Incidence *incidence = currentSelection();
2784 2797
2785 if (!incidence) { 2798 if (!incidence) {
2786 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2799 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2787 return; 2800 return;
2788 } 2801 }
2789 if(incidence->attendeeCount() == 0 ) { 2802 if(incidence->attendeeCount() == 0 ) {
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 07812c2..29e6205 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,407 +1,423 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kdebug.h> 22#include <kdebug.h>
23 23
24#include "incidence.h" 24#include "incidence.h"
25#include "todo.h" 25#include "todo.h"
26 26
27#include "alarm.h" 27#include "alarm.h"
28 28
29using namespace KCal; 29using namespace KCal;
30#include <qwidget.h> 30#include <qwidget.h>
31Alarm::Alarm(Incidence *parent) 31Alarm::Alarm(Incidence *parent)
32 : mParent(parent), 32 : mParent(parent),
33 mType(Audio), 33 mType(Audio),
34 mDescription(""), // to make operator==() not fail 34 mDescription(""), // to make operator==() not fail
35 mFile(""), // to make operator==() not fail 35 mFile(""), // to make operator==() not fail
36 mMailSubject(""), // to make operator==() not fail 36 mMailSubject(""), // to make operator==() not fail
37 mAlarmSnoozeTime(5), 37 mAlarmSnoozeTime(5),
38 mAlarmRepeatCount(0), 38 mAlarmRepeatCount(0),
39 mEndOffset(false), 39 mEndOffset(false),
40 mHasTime(false), 40 mHasTime(false),
41 mAlarmEnabled(false) 41 mAlarmEnabled(false)
42{ 42{
43 43
44} 44}
45 45
46Alarm::~Alarm() 46Alarm::~Alarm()
47{ 47{
48} 48}
49 49
50bool Alarm::operator==( const Alarm& rhs ) const 50bool Alarm::operator==( const Alarm& rhs ) const
51{ 51{
52 if ( mType != rhs.mType || 52 if ( mType != rhs.mType ||
53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || 53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
54 mAlarmRepeatCount != rhs.mAlarmRepeatCount || 54 mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
55 mAlarmEnabled != rhs.mAlarmEnabled || 55 mAlarmEnabled != rhs.mAlarmEnabled ||
56 mHasTime != rhs.mHasTime) 56 mHasTime != rhs.mHasTime)
57 return false; 57 return false;
58 58
59 if (mHasTime) { 59 if (mHasTime) {
60 if (mAlarmTime != rhs.mAlarmTime) 60 if (mAlarmTime != rhs.mAlarmTime)
61 return false; 61 return false;
62 } else { 62 } else {
63 if (mOffset != rhs.mOffset || 63 if (mOffset != rhs.mOffset ||
64 mEndOffset != rhs.mEndOffset) 64 mEndOffset != rhs.mEndOffset)
65 return false; 65 return false;
66 } 66 }
67 67
68 switch (mType) { 68 switch (mType) {
69 case Display: 69 case Display:
70 return mDescription == rhs.mDescription; 70 return mDescription == rhs.mDescription;
71 71
72 case Email: 72 case Email:
73 return mDescription == rhs.mDescription && 73 return mDescription == rhs.mDescription &&
74 mMailAttachFiles == rhs.mMailAttachFiles && 74 mMailAttachFiles == rhs.mMailAttachFiles &&
75 mMailAddresses == rhs.mMailAddresses && 75 mMailAddresses == rhs.mMailAddresses &&
76 mMailSubject == rhs.mMailSubject; 76 mMailSubject == rhs.mMailSubject;
77 77
78 case Procedure: 78 case Procedure:
79 return mFile == rhs.mFile && 79 return mFile == rhs.mFile &&
80 mDescription == rhs.mDescription; 80 mDescription == rhs.mDescription;
81 81
82 case Audio: 82 case Audio:
83 return mFile == rhs.mFile; 83 return mFile == rhs.mFile;
84 84
85 case Invalid: 85 case Invalid:
86 break; 86 break;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91void Alarm::setType(Alarm::Type type) 91void Alarm::setType(Alarm::Type type)
92{ 92{
93 if (type == mType) 93 if (type == mType)
94 return; 94 return;
95 95
96 switch (type) { 96 switch (type) {
97 case Display: 97 case Display:
98 mDescription = ""; 98 mDescription = "";
99 break; 99 break;
100 case Procedure: 100 case Procedure:
101 mFile = mDescription = ""; 101 mFile = mDescription = "";
102 break; 102 break;
103 case Audio: 103 case Audio:
104 mFile = ""; 104 mFile = "";
105 break; 105 break;
106 case Email: 106 case Email:
107 mMailSubject = mDescription = ""; 107 mMailSubject = mDescription = "";
108 mMailAddresses.clear(); 108 mMailAddresses.clear();
109 mMailAttachFiles.clear(); 109 mMailAttachFiles.clear();
110 break; 110 break;
111 case Invalid: 111 case Invalid:
112 break; 112 break;
113 default: 113 default:
114 return; 114 return;
115 } 115 }
116 mType = type; 116 mType = type;
117 mParent->updated(); 117 mParent->updated();
118} 118}
119 119
120Alarm::Type Alarm::type() const 120Alarm::Type Alarm::type() const
121{ 121{
122 return mType; 122 return mType;
123} 123}
124 124
125void Alarm::setAudioAlarm(const QString &audioFile) 125void Alarm::setAudioAlarm(const QString &audioFile)
126{ 126{
127 mType = Audio; 127 mType = Audio;
128 mFile = audioFile; 128 mFile = audioFile;
129 mParent->updated(); 129 mParent->updated();
130} 130}
131 131
132void Alarm::setAudioFile(const QString &audioFile) 132void Alarm::setAudioFile(const QString &audioFile)
133{ 133{
134 if (mType == Audio) { 134 if (mType == Audio) {
135 mFile = audioFile; 135 mFile = audioFile;
136 mParent->updated(); 136 mParent->updated();
137 } 137 }
138} 138}
139 139
140QString Alarm::audioFile() const 140QString Alarm::audioFile() const
141{ 141{
142 return (mType == Audio) ? mFile : QString::null; 142 return (mType == Audio) ? mFile : QString::null;
143} 143}
144 144
145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
146{ 146{
147 mType = Procedure; 147 mType = Procedure;
148 mFile = programFile; 148 mFile = programFile;
149 mDescription = arguments; 149 mDescription = arguments;
150 mParent->updated(); 150 mParent->updated();
151} 151}
152 152
153void Alarm::setProgramFile(const QString &programFile) 153void Alarm::setProgramFile(const QString &programFile)
154{ 154{
155 if (mType == Procedure) { 155 if (mType == Procedure) {
156 mFile = programFile; 156 mFile = programFile;
157 mParent->updated(); 157 mParent->updated();
158 } 158 }
159} 159}
160 160
161QString Alarm::programFile() const 161QString Alarm::programFile() const
162{ 162{
163 return (mType == Procedure) ? mFile : QString::null; 163 return (mType == Procedure) ? mFile : QString::null;
164} 164}
165 165
166void Alarm::setProgramArguments(const QString &arguments) 166void Alarm::setProgramArguments(const QString &arguments)
167{ 167{
168 if (mType == Procedure) { 168 if (mType == Procedure) {
169 mDescription = arguments; 169 mDescription = arguments;
170 mParent->updated(); 170 mParent->updated();
171 } 171 }
172} 172}
173 173
174QString Alarm::programArguments() const 174QString Alarm::programArguments() const
175{ 175{
176 return (mType == Procedure) ? mDescription : QString::null; 176 return (mType == Procedure) ? mDescription : QString::null;
177} 177}
178 178
179void Alarm::setEmailAlarm(const QString &subject, const QString &text, 179void Alarm::setEmailAlarm(const QString &subject, const QString &text,
180 const QValueList<Person> &addressees, const QStringList &attachments) 180 const QValueList<Person> &addressees, const QStringList &attachments)
181{ 181{
182 mType = Email; 182 mType = Email;
183 mMailSubject = subject; 183 mMailSubject = subject;
184 mDescription = text; 184 mDescription = text;
185 mMailAddresses = addressees; 185 mMailAddresses = addressees;
186 mMailAttachFiles = attachments; 186 mMailAttachFiles = attachments;
187 mParent->updated(); 187 mParent->updated();
188} 188}
189 189
190void Alarm::setMailAddress(const Person &mailAddress) 190void Alarm::setMailAddress(const Person &mailAddress)
191{ 191{
192 if (mType == Email) { 192 if (mType == Email) {
193 mMailAddresses.clear(); 193 mMailAddresses.clear();
194 mMailAddresses += mailAddress; 194 mMailAddresses += mailAddress;
195 mParent->updated(); 195 mParent->updated();
196 } 196 }
197} 197}
198 198
199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
200{ 200{
201 if (mType == Email) { 201 if (mType == Email) {
202 mMailAddresses = mailAddresses; 202 mMailAddresses = mailAddresses;
203 mParent->updated(); 203 mParent->updated();
204 } 204 }
205} 205}
206 206
207void Alarm::addMailAddress(const Person &mailAddress) 207void Alarm::addMailAddress(const Person &mailAddress)
208{ 208{
209 if (mType == Email) { 209 if (mType == Email) {
210 mMailAddresses += mailAddress; 210 mMailAddresses += mailAddress;
211 mParent->updated(); 211 mParent->updated();
212 } 212 }
213} 213}
214 214
215QValueList<Person> Alarm::mailAddresses() const 215QValueList<Person> Alarm::mailAddresses() const
216{ 216{
217 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 217 return (mType == Email) ? mMailAddresses : QValueList<Person>();
218} 218}
219 219
220void Alarm::setMailSubject(const QString &mailAlarmSubject) 220void Alarm::setMailSubject(const QString &mailAlarmSubject)
221{ 221{
222 if (mType == Email) { 222 if (mType == Email) {
223 mMailSubject = mailAlarmSubject; 223 mMailSubject = mailAlarmSubject;
224 mParent->updated(); 224 mParent->updated();
225 } 225 }
226} 226}
227 227
228QString Alarm::mailSubject() const 228QString Alarm::mailSubject() const
229{ 229{
230 return (mType == Email) ? mMailSubject : QString::null; 230 return (mType == Email) ? mMailSubject : QString::null;
231} 231}
232 232
233void Alarm::setMailAttachment(const QString &mailAttachFile) 233void Alarm::setMailAttachment(const QString &mailAttachFile)
234{ 234{
235 if (mType == Email) { 235 if (mType == Email) {
236 mMailAttachFiles.clear(); 236 mMailAttachFiles.clear();
237 mMailAttachFiles += mailAttachFile; 237 mMailAttachFiles += mailAttachFile;
238 mParent->updated(); 238 mParent->updated();
239 } 239 }
240} 240}
241 241
242void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 242void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
243{ 243{
244 if (mType == Email) { 244 if (mType == Email) {
245 mMailAttachFiles = mailAttachFiles; 245 mMailAttachFiles = mailAttachFiles;
246 mParent->updated(); 246 mParent->updated();
247 } 247 }
248} 248}
249 249
250void Alarm::addMailAttachment(const QString &mailAttachFile) 250void Alarm::addMailAttachment(const QString &mailAttachFile)
251{ 251{
252 if (mType == Email) { 252 if (mType == Email) {
253 mMailAttachFiles += mailAttachFile; 253 mMailAttachFiles += mailAttachFile;
254 mParent->updated(); 254 mParent->updated();
255 } 255 }
256} 256}
257 257
258QStringList Alarm::mailAttachments() const 258QStringList Alarm::mailAttachments() const
259{ 259{
260 return (mType == Email) ? mMailAttachFiles : QStringList(); 260 return (mType == Email) ? mMailAttachFiles : QStringList();
261} 261}
262 262
263void Alarm::setMailText(const QString &text) 263void Alarm::setMailText(const QString &text)
264{ 264{
265 if (mType == Email) { 265 if (mType == Email) {
266 mDescription = text; 266 mDescription = text;
267 mParent->updated(); 267 mParent->updated();
268 } 268 }
269} 269}
270 270
271QString Alarm::mailText() const 271QString Alarm::mailText() const
272{ 272{
273 return (mType == Email) ? mDescription : QString::null; 273 return (mType == Email) ? mDescription : QString::null;
274} 274}
275 275
276void Alarm::setDisplayAlarm(const QString &text) 276void Alarm::setDisplayAlarm(const QString &text)
277{ 277{
278 mType = Display; 278 mType = Display;
279 mDescription = text; 279 mDescription = text;
280 mParent->updated(); 280 mParent->updated();
281} 281}
282 282
283void Alarm::setText(const QString &text) 283void Alarm::setText(const QString &text)
284{ 284{
285 if (mType == Display) { 285 if (mType == Display) {
286 mDescription = text; 286 mDescription = text;
287 mParent->updated(); 287 mParent->updated();
288 } 288 }
289} 289}
290 290
291QString Alarm::text() const 291QString Alarm::text() const
292{ 292{
293 return (mType == Display) ? mDescription : QString::null; 293 return (mType == Display) ? mDescription : QString::null;
294} 294}
295 295
296void Alarm::setTime(const QDateTime &alarmTime) 296void Alarm::setTime(const QDateTime &alarmTime)
297{ 297{
298 mAlarmTime = alarmTime; 298 mAlarmTime = alarmTime;
299 mHasTime = true; 299 mHasTime = true;
300 300
301 mParent->updated(); 301 mParent->updated();
302} 302}
303int Alarm::offset()
304{
305 if ( hasTime() ) {
306 if (mParent->type()=="Todo") {
307 Todo *t = static_cast<Todo*>(mParent);
308 return t->dtDue().secsTo( mAlarmTime ) ;
309 } else
310 return mParent->dtStart().secsTo( mAlarmTime ) ;
311 }
312 else
313 {
314 return mOffset.asSeconds();
315 }
316
317}
318
303 319
304QDateTime Alarm::time() const 320QDateTime Alarm::time() const
305{ 321{
306 if ( hasTime() ) 322 if ( hasTime() )
307 return mAlarmTime; 323 return mAlarmTime;
308 else 324 else
309 { 325 {
310 if (mParent->type()=="Todo") { 326 if (mParent->type()=="Todo") {
311 Todo *t = static_cast<Todo*>(mParent); 327 Todo *t = static_cast<Todo*>(mParent);
312 return mOffset.end( t->dtDue() ); 328 return mOffset.end( t->dtDue() );
313 } else if (mEndOffset) { 329 } else if (mEndOffset) {
314 return mOffset.end( mParent->dtEnd() ); 330 return mOffset.end( mParent->dtEnd() );
315 } else { 331 } else {
316 return mOffset.end( mParent->dtStart() ); 332 return mOffset.end( mParent->dtStart() );
317 } 333 }
318 } 334 }
319} 335}
320 336
321bool Alarm::hasTime() const 337bool Alarm::hasTime() const
322{ 338{
323 return mHasTime; 339 return mHasTime;
324} 340}
325 341
326void Alarm::setSnoozeTime(int alarmSnoozeTime) 342void Alarm::setSnoozeTime(int alarmSnoozeTime)
327{ 343{
328 mAlarmSnoozeTime = alarmSnoozeTime; 344 mAlarmSnoozeTime = alarmSnoozeTime;
329 mParent->updated(); 345 mParent->updated();
330} 346}
331 347
332int Alarm::snoozeTime() const 348int Alarm::snoozeTime() const
333{ 349{
334 return mAlarmSnoozeTime; 350 return mAlarmSnoozeTime;
335} 351}
336 352
337void Alarm::setRepeatCount(int alarmRepeatCount) 353void Alarm::setRepeatCount(int alarmRepeatCount)
338{ 354{
339 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; 355 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
340 356
341 mAlarmRepeatCount = alarmRepeatCount; 357 mAlarmRepeatCount = alarmRepeatCount;
342 mParent->updated(); 358 mParent->updated();
343} 359}
344 360
345int Alarm::repeatCount() const 361int Alarm::repeatCount() const
346{ 362{
347 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; 363 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
348 return mAlarmRepeatCount; 364 return mAlarmRepeatCount;
349} 365}
350 366
351void Alarm::toggleAlarm() 367void Alarm::toggleAlarm()
352{ 368{
353 mAlarmEnabled = !mAlarmEnabled; 369 mAlarmEnabled = !mAlarmEnabled;
354 mParent->updated(); 370 mParent->updated();
355} 371}
356 372
357void Alarm::setEnabled(bool enable) 373void Alarm::setEnabled(bool enable)
358{ 374{
359 mAlarmEnabled = enable; 375 mAlarmEnabled = enable;
360 mParent->updated(); 376 mParent->updated();
361} 377}
362 378
363bool Alarm::enabled() const 379bool Alarm::enabled() const
364{ 380{
365 return mAlarmEnabled; 381 return mAlarmEnabled;
366} 382}
367 383
368void Alarm::setStartOffset( const Duration &offset ) 384void Alarm::setStartOffset( const Duration &offset )
369{ 385{
370 mOffset = offset; 386 mOffset = offset;
371 mEndOffset = false; 387 mEndOffset = false;
372 mHasTime = false; 388 mHasTime = false;
373 mParent->updated(); 389 mParent->updated();
374} 390}
375 391
376Duration Alarm::startOffset() const 392Duration Alarm::startOffset() const
377{ 393{
378 return (mHasTime || mEndOffset) ? 0 : mOffset; 394 return (mHasTime || mEndOffset) ? 0 : mOffset;
379} 395}
380 396
381bool Alarm::hasStartOffset() const 397bool Alarm::hasStartOffset() const
382{ 398{
383 return !mHasTime && !mEndOffset; 399 return !mHasTime && !mEndOffset;
384} 400}
385 401
386bool Alarm::hasEndOffset() const 402bool Alarm::hasEndOffset() const
387{ 403{
388 return !mHasTime && mEndOffset; 404 return !mHasTime && mEndOffset;
389} 405}
390 406
391void Alarm::setEndOffset( const Duration &offset ) 407void Alarm::setEndOffset( const Duration &offset )
392{ 408{
393 mOffset = offset; 409 mOffset = offset;
394 mEndOffset = true; 410 mEndOffset = true;
395 mHasTime = false; 411 mHasTime = false;
396 mParent->updated(); 412 mParent->updated();
397} 413}
398 414
399Duration Alarm::endOffset() const 415Duration Alarm::endOffset() const
400{ 416{
401 return (mHasTime || !mEndOffset) ? 0 : mOffset; 417 return (mHasTime || !mEndOffset) ? 0 : mOffset;
402} 418}
403 419
404void Alarm::setParent( Incidence *parent ) 420void Alarm::setParent( Incidence *parent )
405{ 421{
406 mParent = parent; 422 mParent = parent;
407} 423}
diff --git a/libkcal/alarm.h b/libkcal/alarm.h
index ae2eca3..682b626 100644
--- a/libkcal/alarm.h
+++ b/libkcal/alarm.h
@@ -1,245 +1,245 @@
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 KCAL_ALARM_H 21#ifndef KCAL_ALARM_H
22#define KCAL_ALARM_H 22#define KCAL_ALARM_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qvaluelist.h> 25#include <qvaluelist.h>
26 26
27#include "customproperties.h" 27#include "customproperties.h"
28#include "duration.h" 28#include "duration.h"
29#include "person.h" 29#include "person.h"
30 30
31namespace KCal { 31namespace KCal {
32 32
33class Incidence; 33class Incidence;
34 34
35/** 35/**
36 This class represents an alarm notification. 36 This class represents an alarm notification.
37*/ 37*/
38class Alarm : public CustomProperties 38class Alarm : public CustomProperties
39{ 39{
40 public: 40 public:
41 enum Type { Invalid, Display, Procedure, Email, Audio }; 41 enum Type { Invalid, Display, Procedure, Email, Audio };
42 typedef QValueList<Alarm *> List; 42 typedef QValueList<Alarm *> List;
43 43
44 /** Construct a new alarm with variables initialized to "sane" values. */ 44 /** Construct a new alarm with variables initialized to "sane" values. */
45 explicit Alarm(Incidence *parent); 45 explicit Alarm(Incidence *parent);
46 /** Destruct Alarm object. */ 46 /** Destruct Alarm object. */
47 ~Alarm(); 47 ~Alarm();
48 48
49 /** Compare this alarm with another one. */ 49 /** Compare this alarm with another one. */
50 bool operator==(const Alarm &) const; 50 bool operator==(const Alarm &) const;
51 bool operator!=(const Alarm &a) const { return !operator==(a); } 51 bool operator!=(const Alarm &a) const { return !operator==(a); }
52 52
53 /** Set the type of the alarm. 53 /** Set the type of the alarm.
54 If the specified type is different from the current type of the alarm, 54 If the specified type is different from the current type of the alarm,
55 the alarm's type-specific properties are initialised to null. 55 the alarm's type-specific properties are initialised to null.
56 @param type type of alarm. 56 @param type type of alarm.
57 */ 57 */
58 void setType(Type type); 58 void setType(Type type);
59 /** Return the type of the alarm */ 59 /** Return the type of the alarm */
60 Type type() const; 60 Type type() const;
61 61 int offset();
62 /** Set the alarm to be a display alarm. 62 /** Set the alarm to be a display alarm.
63 @param text text to display when the alarm is triggered. 63 @param text text to display when the alarm is triggered.
64 */ 64 */
65 void setDisplayAlarm(const QString &text); 65 void setDisplayAlarm(const QString &text);
66 /** Set the text to be displayed when the alarm is triggered. 66 /** Set the text to be displayed when the alarm is triggered.
67 Ignored if the alarm is not a display alarm. 67 Ignored if the alarm is not a display alarm.
68 */ 68 */
69 void setText(const QString &text); 69 void setText(const QString &text);
70 /** Return the text string that displays when the alarm is triggered. */ 70 /** Return the text string that displays when the alarm is triggered. */
71 QString text() const; 71 QString text() const;
72 72
73 /** Set the alarm to be an audio alarm. 73 /** Set the alarm to be an audio alarm.
74 @param audioFile optional file to play when the alarm is triggered. 74 @param audioFile optional file to play when the alarm is triggered.
75 */ 75 */
76 void setAudioAlarm(const QString &audioFile = QString::null); 76 void setAudioAlarm(const QString &audioFile = QString::null);
77 /** Set the file to play when the audio alarm is triggered. 77 /** Set the file to play when the audio alarm is triggered.
78 Ignored if the alarm is not an audio alarm. 78 Ignored if the alarm is not an audio alarm.
79 */ 79 */
80 void setAudioFile(const QString &audioFile); 80 void setAudioFile(const QString &audioFile);
81 /** Return the name of the audio file for the alarm. 81 /** Return the name of the audio file for the alarm.
82 @return The audio file for the alarm, or QString::null if not an audio alarm. 82 @return The audio file for the alarm, or QString::null if not an audio alarm.
83 */ 83 */
84 QString audioFile() const; 84 QString audioFile() const;
85 85
86 /** Set the alarm to be a procedure alarm. 86 /** Set the alarm to be a procedure alarm.
87 @param programFile program to execute when the alarm is triggered. 87 @param programFile program to execute when the alarm is triggered.
88 @param arguments arguments to supply to programFile. 88 @param arguments arguments to supply to programFile.
89 */ 89 */
90 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null); 90 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null);
91 /** Set the program file to execute when the alarm is triggered. 91 /** Set the program file to execute when the alarm is triggered.
92 Ignored if the alarm is not a procedure alarm. 92 Ignored if the alarm is not a procedure alarm.
93 */ 93 */
94 void setProgramFile(const QString &programFile); 94 void setProgramFile(const QString &programFile);
95 /** Return the name of the program file to execute when the alarm is triggered. 95 /** Return the name of the program file to execute when the alarm is triggered.
96 @return the program file name, or QString::null if not a procedure alarm. 96 @return the program file name, or QString::null if not a procedure alarm.
97 */ 97 */
98 QString programFile() const; 98 QString programFile() const;
99 /** Set the arguments to the program to execute when the alarm is triggered. 99 /** Set the arguments to the program to execute when the alarm is triggered.
100 Ignored if the alarm is not a procedure alarm. 100 Ignored if the alarm is not a procedure alarm.
101 */ 101 */
102 void setProgramArguments(const QString &arguments); 102 void setProgramArguments(const QString &arguments);
103 /** Return the arguments to the program to run when the alarm is triggered. 103 /** Return the arguments to the program to run when the alarm is triggered.
104 @return the program arguments, or QString::null if not a procedure alarm. 104 @return the program arguments, or QString::null if not a procedure alarm.
105 */ 105 */
106 QString programArguments() const; 106 QString programArguments() const;
107 107
108 /** Set the alarm to be an email alarm. 108 /** Set the alarm to be an email alarm.
109 @param subject subject line of email. 109 @param subject subject line of email.
110 @param text body of email. 110 @param text body of email.
111 @param addressees email addresses of recipient(s). 111 @param addressees email addresses of recipient(s).
112 @param attachments optional names of files to attach to the email. 112 @param attachments optional names of files to attach to the email.
113 */ 113 */
114 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees, 114 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees,
115 const QStringList &attachments = QStringList()); 115 const QStringList &attachments = QStringList());
116 116
117 /** Send mail to this address when the alarm is triggered. 117 /** Send mail to this address when the alarm is triggered.
118 Ignored if the alarm is not an email alarm. 118 Ignored if the alarm is not an email alarm.
119 */ 119 */
120 void setMailAddress(const Person &mailAlarmAddress); 120 void setMailAddress(const Person &mailAlarmAddress);
121 /** Send mail to these addresses when the alarm is triggered. 121 /** Send mail to these addresses when the alarm is triggered.
122 Ignored if the alarm is not an email alarm. 122 Ignored if the alarm is not an email alarm.
123 */ 123 */
124 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses); 124 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses);
125 /** Add this address to the list of addresses to send mail to when the alarm is triggered. 125 /** Add this address to the list of addresses to send mail to when the alarm is triggered.
126 Ignored if the alarm is not an email alarm. 126 Ignored if the alarm is not an email alarm.
127 */ 127 */
128 void addMailAddress(const Person &mailAlarmAddress); 128 void addMailAddress(const Person &mailAlarmAddress);
129 /** return the addresses to send mail to when an alarm goes off */ 129 /** return the addresses to send mail to when an alarm goes off */
130 QValueList<Person> mailAddresses() const; 130 QValueList<Person> mailAddresses() const;
131 131
132 /** Set the subject line of the mail. 132 /** Set the subject line of the mail.
133 Ignored if the alarm is not an email alarm. 133 Ignored if the alarm is not an email alarm.
134 */ 134 */
135 void setMailSubject(const QString &mailAlarmSubject); 135 void setMailSubject(const QString &mailAlarmSubject);
136 /** return the subject line of the mail */ 136 /** return the subject line of the mail */
137 QString mailSubject() const; 137 QString mailSubject() const;
138 138
139 /** Attach this filename to the email. 139 /** Attach this filename to the email.
140 Ignored if the alarm is not an email alarm. 140 Ignored if the alarm is not an email alarm.
141 */ 141 */
142 void setMailAttachment(const QString &mailAttachFile); 142 void setMailAttachment(const QString &mailAttachFile);
143 /** Attach these filenames to the email. 143 /** Attach these filenames to the email.
144 Ignored if the alarm is not an email alarm. 144 Ignored if the alarm is not an email alarm.
145 */ 145 */
146 void setMailAttachments(const QStringList &mailAttachFiles); 146 void setMailAttachments(const QStringList &mailAttachFiles);
147 /** Add this filename to the list of files to attach to the email. 147 /** Add this filename to the list of files to attach to the email.
148 Ignored if the alarm is not an email alarm. 148 Ignored if the alarm is not an email alarm.
149 */ 149 */
150 void addMailAttachment(const QString &mailAttachFile); 150 void addMailAttachment(const QString &mailAttachFile);
151 /** return the filenames to attach to the email */ 151 /** return the filenames to attach to the email */
152 QStringList mailAttachments() const; 152 QStringList mailAttachments() const;
153 153
154 /** Set the email body text. 154 /** Set the email body text.
155 Ignored if the alarm is not an email alarm. 155 Ignored if the alarm is not an email alarm.
156 */ 156 */
157 void setMailText(const QString &text); 157 void setMailText(const QString &text);
158 /** Return the email body text. 158 /** Return the email body text.
159 @return the body text, or QString::null if not an email alarm. 159 @return the body text, or QString::null if not an email alarm.
160 */ 160 */
161 QString mailText() const; 161 QString mailText() const;
162 162
163 /** set the time to trigger an alarm */ 163 /** set the time to trigger an alarm */
164 void setTime(const QDateTime &alarmTime); 164 void setTime(const QDateTime &alarmTime);
165 /** return the date/time when an alarm goes off */ 165 /** return the date/time when an alarm goes off */
166 QDateTime time() const; 166 QDateTime time() const;
167 /** Return true, if the alarm has an explicit date/time. */ 167 /** Return true, if the alarm has an explicit date/time. */
168 bool hasTime() const; 168 bool hasTime() const;
169 169
170 /** Set offset of alarm in time relative to the start of the event. */ 170 /** Set offset of alarm in time relative to the start of the event. */
171 void setStartOffset(const Duration &); 171 void setStartOffset(const Duration &);
172 /** Return offset of alarm in time relative to the start of the event. 172 /** Return offset of alarm in time relative to the start of the event.
173 * If the alarm's time is not defined in terms of an offset relative 173 * If the alarm's time is not defined in terms of an offset relative
174 * to the start of the event, returns zero. 174 * to the start of the event, returns zero.
175 */ 175 */
176 Duration startOffset() const; 176 Duration startOffset() const;
177 /** Return whether the alarm is defined in terms of an offset relative 177 /** Return whether the alarm is defined in terms of an offset relative
178 * to the start of the event. 178 * to the start of the event.
179 */ 179 */
180 bool hasStartOffset() const; 180 bool hasStartOffset() const;
181 181
182 /** Set offset of alarm in time relative to the end of the event. */ 182 /** Set offset of alarm in time relative to the end of the event. */
183 void setEndOffset(const Duration &); 183 void setEndOffset(const Duration &);
184 /** Return offset of alarm in time relative to the end of the event. 184 /** Return offset of alarm in time relative to the end of the event.
185 * If the alarm's time is not defined in terms of an offset relative 185 * If the alarm's time is not defined in terms of an offset relative
186 * to the end of the event, returns zero. 186 * to the end of the event, returns zero.
187 */ 187 */
188 Duration endOffset() const; 188 Duration endOffset() const;
189 /** Return whether the alarm is defined in terms of an offset relative 189 /** Return whether the alarm is defined in terms of an offset relative
190 * to the end of the event. 190 * to the end of the event.
191 */ 191 */
192 bool hasEndOffset() const; 192 bool hasEndOffset() const;
193 193
194 /** Set the interval between snoozes for the alarm. 194 /** Set the interval between snoozes for the alarm.
195 @param snoozeTime the time in minutes between snoozes. 195 @param snoozeTime the time in minutes between snoozes.
196 */ 196 */
197 void setSnoozeTime(int alarmSnoozeTime); 197 void setSnoozeTime(int alarmSnoozeTime);
198 /** Get how long the alarm snooze interval is. 198 /** Get how long the alarm snooze interval is.
199 @return the number of minutes between snoozes. 199 @return the number of minutes between snoozes.
200 */ 200 */
201 int snoozeTime() const; 201 int snoozeTime() const;
202 202
203 /** set how many times an alarm is to repeat itself (w/snoozes) */ 203 /** set how many times an alarm is to repeat itself (w/snoozes) */
204 void setRepeatCount(int alarmRepeatCount); 204 void setRepeatCount(int alarmRepeatCount);
205 /** get how many times an alarm repeats */ 205 /** get how many times an alarm repeats */
206 int repeatCount() const; 206 int repeatCount() const;
207 207
208 /** toggles the value of alarm to be either on or off. 208 /** toggles the value of alarm to be either on or off.
209 set's the alarm time to be x minutes before dtStart time. */ 209 set's the alarm time to be x minutes before dtStart time. */
210 void toggleAlarm(); 210 void toggleAlarm();
211 211
212 /** set the alarm enabled status */ 212 /** set the alarm enabled status */
213 void setEnabled(bool enable); 213 void setEnabled(bool enable);
214 /** get the alarm enabled status */ 214 /** get the alarm enabled status */
215 bool enabled() const; 215 bool enabled() const;
216 216
217 /** Set the alarm's parent incidence */ 217 /** Set the alarm's parent incidence */
218 void setParent( Incidence * ); 218 void setParent( Incidence * );
219 /** get the alarm's parent incidence */ 219 /** get the alarm's parent incidence */
220 Incidence *parent() const { return mParent; } 220 Incidence *parent() const { return mParent; }
221 221
222 private: 222 private:
223 Incidence *mParent; // the incidence which this alarm belongs to 223 Incidence *mParent; // the incidence which this alarm belongs to
224 Type mType; // type of alarm 224 Type mType; // type of alarm
225 QString mDescription; // text to display/email body/procedure arguments 225 QString mDescription; // text to display/email body/procedure arguments
226 QString mFile; // procedure program to run/optional audio file to play 226 QString mFile; // procedure program to run/optional audio file to play
227 QStringList mMailAttachFiles; // filenames to attach to email 227 QStringList mMailAttachFiles; // filenames to attach to email
228 QValueList<Person> mMailAddresses; // who to mail for reminder 228 QValueList<Person> mMailAddresses; // who to mail for reminder
229 QString mMailSubject; // subject of email 229 QString mMailSubject; // subject of email
230 230
231 int mAlarmSnoozeTime; // number of minutes after alarm to 231 int mAlarmSnoozeTime; // number of minutes after alarm to
232 // snooze before ringing again 232 // snooze before ringing again
233 int mAlarmRepeatCount; // number of times for alarm to repeat 233 int mAlarmRepeatCount; // number of times for alarm to repeat
234 // after the initial time 234 // after the initial time
235 235
236 QDateTime mAlarmTime; // time at which to trigger the alarm 236 QDateTime mAlarmTime; // time at which to trigger the alarm
237 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm 237 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm
238 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART 238 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART
239 bool mHasTime; // use mAlarmTime, not mOffset 239 bool mHasTime; // use mAlarmTime, not mOffset
240 bool mAlarmEnabled; 240 bool mAlarmEnabled;
241}; 241};
242 242
243} 243}
244 244
245#endif 245#endif
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6d0da5c..178a63e 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,637 +1,635 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38#include <kmessagebox.h> 38#include <kmessagebox.h>
39 39
40#include "calendar.h" 40#include "calendar.h"
41#include "alarm.h" 41#include "alarm.h"
42#include "recurrence.h" 42#include "recurrence.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44 44
45#include "phoneformat.h" 45#include "phoneformat.h"
46#include "syncdefines.h" 46#include "syncdefines.h"
47 47
48using namespace KCal; 48using namespace KCal;
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( ) { 52 PhoneParser( ) {
53 ; 53 ;
54 } 54 }
55 55
56 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 56 static QString dtToString( const QDateTime& dti, bool useTZ = false )
57 { 57 {
58 QString datestr; 58 QString datestr;
59 QString timestr; 59 QString timestr;
60 int offset = KGlobal::locale()->localTimeOffset( dti ); 60 int offset = KGlobal::locale()->localTimeOffset( dti );
61 QDateTime dt; 61 QDateTime dt;
62 if (useTZ) 62 if (useTZ)
63 dt = dti.addSecs ( -(offset*60)); 63 dt = dti.addSecs ( -(offset*60));
64 else 64 else
65 dt = dti; 65 dt = dti;
66 if(dt.date().isValid()){ 66 if(dt.date().isValid()){
67 const QDate& date = dt.date(); 67 const QDate& date = dt.date();
68 datestr.sprintf("%04d%02d%02d", 68 datestr.sprintf("%04d%02d%02d",
69 date.year(), date.month(), date.day()); 69 date.year(), date.month(), date.day());
70 } 70 }
71 if(dt.time().isValid()){ 71 if(dt.time().isValid()){
72 const QTime& time = dt.time(); 72 const QTime& time = dt.time();
73 timestr.sprintf("T%02d%02d%02d", 73 timestr.sprintf("T%02d%02d%02d",
74 time.hour(), time.minute(), time.second()); 74 time.hour(), time.minute(), time.second());
75 } 75 }
76 return datestr + timestr; 76 return datestr + timestr;
77 } 77 }
78 78
79 79
80}; 80};
81 81
82 82
83 83
84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
85{ 85{
86 mProfileName = profileName; 86 mProfileName = profileName;
87 mDevice = device; 87 mDevice = device;
88 mConnection = connection; 88 mConnection = connection;
89 mModel = model; 89 mModel = model;
90} 90}
91 91
92PhoneFormat::~PhoneFormat() 92PhoneFormat::~PhoneFormat()
93{ 93{
94} 94}
95#if 0 95#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 96int PhoneFormat::initDevice(GSM_StateMachine *s)
97{ 97{
98 GSM_ReadConfig(NULL, &s->Config[0], 0); 98 GSM_ReadConfig(NULL, &s->Config[0], 0);
99 s->ConfigNum = 1; 99 s->ConfigNum = 1;
100 GSM_Config *cfg = &s->Config[0]; 100 GSM_Config *cfg = &s->Config[0];
101 if ( ! mConnection.isEmpty() ) { 101 if ( ! mConnection.isEmpty() ) {
102 cfg->Connection = strdup(mConnection.latin1()); 102 cfg->Connection = strdup(mConnection.latin1());
103 cfg->DefaultConnection = false; 103 cfg->DefaultConnection = false;
104 qDebug("Connection set %s ", cfg->Connection ); 104 qDebug("Connection set %s ", cfg->Connection );
105 105
106 } 106 }
107 if ( ! mDevice.isEmpty() ) { 107 if ( ! mDevice.isEmpty() ) {
108 cfg->Device = strdup(mDevice.latin1()); 108 cfg->Device = strdup(mDevice.latin1());
109 cfg->DefaultDevice = false; 109 cfg->DefaultDevice = false;
110 qDebug("Device set %s ", cfg->Device); 110 qDebug("Device set %s ", cfg->Device);
111 111
112 } 112 }
113 if ( ! mModel.isEmpty() ) { 113 if ( ! mModel.isEmpty() ) {
114 strcpy(cfg->Model,mModel.latin1() ); 114 strcpy(cfg->Model,mModel.latin1() );
115 cfg->DefaultModel = false; 115 cfg->DefaultModel = false;
116 qDebug("Model set %s ",cfg->Model ); 116 qDebug("Model set %s ",cfg->Model );
117 } 117 }
118 int error=GSM_InitConnection(s,3); 118 int error=GSM_InitConnection(s,3);
119 return error; 119 return error;
120} 120}
121#endif 121#endif
122ulong PhoneFormat::getCsumTodo( Todo* todo ) 122ulong PhoneFormat::getCsumTodo( Todo* todo )
123{ 123{
124 QStringList attList; 124 QStringList attList;
125 if ( todo->hasDueDate() ) 125 if ( todo->hasDueDate() )
126 attList << PhoneParser::dtToString ( todo->dtDue() ); 126 attList << PhoneParser::dtToString ( todo->dtDue() );
127 attList << todo->summary(); 127 attList << todo->summary();
128 QString completedString = "no"; 128 QString completedString = "no";
129 if ( todo->isCompleted() ) 129 if ( todo->isCompleted() )
130 completedString = "yes"; 130 completedString = "yes";
131 attList << completedString; 131 attList << completedString;
132 int prio = todo->priority(); 132 int prio = todo->priority();
133 if( prio == 2 ) prio = 1; 133 if( prio == 2 ) prio = 1;
134 if (prio == 4 ) prio = 5 ; 134 if (prio == 4 ) prio = 5 ;
135 attList << QString::number( prio ); 135 attList << QString::number( prio );
136 QString alarmString = "na"; 136 QString alarmString = "na";
137 Alarm *alarm; 137 Alarm *alarm;
138 if ( todo->alarms().count() > 0 ) { 138 if ( todo->alarms().count() > 0 ) {
139 alarm = todo->alarms().first(); 139 alarm = todo->alarms().first();
140 if ( alarm->enabled() ) { 140 if ( alarm->enabled() ) {
141 alarmString = QString::number(alarm->startOffset().asSeconds() ); 141 alarmString = QString::number(alarm->offset() );
142 } 142 }
143 } 143 }
144 attList << alarmString; 144 attList << alarmString;
145 attList << todo->categoriesStr(); 145 attList << todo->categoriesStr();
146 attList << todo->secrecyStr(); 146 attList << todo->secrecyStr();
147 return PhoneFormat::getCsum(attList ); 147 return PhoneFormat::getCsum(attList );
148 148
149} 149}
150ulong PhoneFormat::getCsumEvent( Event* event ) 150ulong PhoneFormat::getCsumEvent( Event* event )
151{ 151{
152 QStringList attList; 152 QStringList attList;
153 attList << PhoneParser::dtToString ( event->dtStart() ); 153 attList << PhoneParser::dtToString ( event->dtStart() );
154 attList << PhoneParser::dtToString ( event->dtEnd() ); 154 attList << PhoneParser::dtToString ( event->dtEnd() );
155 attList << event->summary(); 155 attList << event->summary();
156 attList << event->location(); 156 attList << event->location();
157 QString alarmString = "na"; 157 QString alarmString = "na";
158 Alarm *alarm; 158 Alarm *alarm;
159 if ( event->alarms().count() > 0 ) { 159 if ( event->alarms().count() > 0 ) {
160 alarm = event->alarms().first(); 160 alarm = event->alarms().first();
161 if ( alarm->enabled() ) { 161 if ( alarm->enabled() ) {
162 alarmString = QString::number( alarm->startOffset().asSeconds() ); 162 alarmString = QString::number( alarm->offset() );
163 } 163 }
164 } 164 }
165 attList << alarmString; 165 attList << alarmString;
166 Recurrence* rec = event->recurrence(); 166 Recurrence* rec = event->recurrence();
167 QStringList list; 167 QStringList list;
168 bool writeEndDate = false; 168 bool writeEndDate = false;
169 switch ( rec->doesRecur() ) 169 switch ( rec->doesRecur() )
170 { 170 {
171 case Recurrence::rDaily: // 0 171 case Recurrence::rDaily: // 0
172 list.append( "0" ); 172 list.append( "0" );
173 list.append( QString::number( rec->frequency() ));//12 173 list.append( QString::number( rec->frequency() ));//12
174 list.append( "0" ); 174 list.append( "0" );
175 list.append( "0" ); 175 list.append( "0" );
176 writeEndDate = true; 176 writeEndDate = true;
177 break; 177 break;
178 case Recurrence::rWeekly:// 1 178 case Recurrence::rWeekly:// 1
179 list.append( "1" ); 179 list.append( "1" );
180 list.append( QString::number( rec->frequency()) );//12 180 list.append( QString::number( rec->frequency()) );//12
181 list.append( "0" ); 181 list.append( "0" );
182 { 182 {
183 int days = 0; 183 int days = 0;
184 QBitArray weekDays = rec->days(); 184 QBitArray weekDays = rec->days();
185 int i; 185 int i;
186 for( i = 1; i <= 7; ++i ) { 186 for( i = 1; i <= 7; ++i ) {
187 if ( weekDays[i-1] ) { 187 if ( weekDays[i-1] ) {
188 days += 1 << (i-1); 188 days += 1 << (i-1);
189 } 189 }
190 } 190 }
191 list.append( QString::number( days ) ); 191 list.append( QString::number( days ) );
192 } 192 }
193 //pending weekdays 193 //pending weekdays
194 writeEndDate = true; 194 writeEndDate = true;
195 195
196 break; 196 break;
197 case Recurrence::rMonthlyPos:// 2 197 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 198 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 199 list.append( QString::number( rec->frequency()) );//12
200 200
201 writeEndDate = true; 201 writeEndDate = true;
202 { 202 {
203 int count = 1; 203 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 204 QPtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 205 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 206 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 207 count = 5 - rmp.first()->rPos - 1;
208 else 208 else
209 count = rmp.first()->rPos - 1; 209 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 210 list.append( QString::number( count ) );
211 211
212 } 212 }
213 213
214 list.append( "0" ); 214 list.append( "0" );
215 break; 215 break;
216 case Recurrence::rMonthlyDay:// 3 216 case Recurrence::rMonthlyDay:// 3
217 list.append( "3" ); 217 list.append( "3" );
218 list.append( QString::number( rec->frequency()) );//12 218 list.append( QString::number( rec->frequency()) );//12
219 list.append( "0" ); 219 list.append( "0" );
220 list.append( "0" ); 220 list.append( "0" );
221 writeEndDate = true; 221 writeEndDate = true;
222 break; 222 break;
223 case Recurrence::rYearlyMonth://4 223 case Recurrence::rYearlyMonth://4
224 list.append( "4" ); 224 list.append( "4" );
225 list.append( QString::number( rec->frequency()) );//12 225 list.append( QString::number( rec->frequency()) );//12
226 list.append( "0" ); 226 list.append( "0" );
227 list.append( "0" ); 227 list.append( "0" );
228 writeEndDate = true; 228 writeEndDate = true;
229 break; 229 break;
230 230
231 default: 231 default:
232 list.append( "255" ); 232 list.append( "255" );
233 list.append( QString() ); 233 list.append( QString() );
234 list.append( "0" ); 234 list.append( "0" );
235 list.append( QString() ); 235 list.append( QString() );
236 list.append( "0" ); 236 list.append( "0" );
237 list.append( "20991231T000000" ); 237 list.append( "20991231T000000" );
238 break; 238 break;
239 } 239 }
240 if ( writeEndDate ) { 240 if ( writeEndDate ) {
241 241
242 if ( rec->endDate().isValid() ) { // 15 + 16 242 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 243 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 244 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 245 } else {
246 list.append( "0" ); 246 list.append( "0" );
247 list.append( "20991231T000000" ); 247 list.append( "20991231T000000" );
248 } 248 }
249 249
250 } 250 }
251 attList << list.join(""); 251 attList << list.join("");
252 attList << event->categoriesStr(); 252 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 253 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 254
255 attList << event->secrecyStr(); 255 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 256 return PhoneFormat::getCsum(attList );
257} 257}
258ulong PhoneFormat::getCsum( const QStringList & attList) 258ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 259{
260 int max = attList.count(); 260 int max = attList.count();
261 ulong cSum = 0; 261 ulong cSum = 0;
262 int j,k,i; 262 int j,k,i;
263 int add; 263 int add;
264 for ( i = 0; i < max ; ++i ) { 264 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 265 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 266 if ( ! s.isEmpty() ){
267 j = s.length(); 267 j = s.length();
268 for ( k = 0; k < j; ++k ) { 268 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 269 int mul = k +1;
270 add = s[k].unicode (); 270 add = s[k].unicode ();
271 if ( k < 16 ) 271 if ( k < 16 )
272 mul = mul * mul; 272 mul = mul * mul;
273 int ii = i+1; 273 int ii = i+1;
274 add = add * mul *ii*ii*ii; 274 add = add * mul *ii*ii*ii;
275 cSum += add; 275 cSum += add;
276 } 276 }
277 } 277 }
278 278
279 } 279 }
280 QString dump = attList.join(","); 280 //QString dump = attList.join(",");
281 qDebug("csum: %d %s", cSum,dump.latin1()); 281 //qDebug("csum: %d %s", cSum,dump.latin1());
282 282
283 return cSum; 283 return cSum;
284 284
285} 285}
286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
287#include <stdlib.h> 287#include <stdlib.h>
288#define DEBUGMODE false 288#define DEBUGMODE false
289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
290{ 290{
291 291
292 QString fileName; 292 QString fileName;
293#ifdef _WIN32_ 293#ifdef _WIN32_
294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
295#else 295#else
296 fileName = "/tmp/kdepimtemp.vcs"; 296 fileName = "/tmp/kdepimtemp.vcs";
297#endif 297#endif
298 QString command ="./kammu --backup " + fileName + " -yes" ; 298 QString command ="./kammu --backup " + fileName + " -yes" ;
299 int ret = system ( command.latin1() ); 299 int ret = system ( command.latin1() );
300 if ( ret != 0 ) { 300 if ( ret != 0 ) {
301 qDebug("Error::command returned %d", ret); 301 qDebug("Error::command returned %d", ret);
302 return false; 302 return false;
303 } 303 }
304 qDebug("Command returned %d", ret);
305 VCalFormat vfload; 304 VCalFormat vfload;
306 vfload.setLocalTime ( true ); 305 vfload.setLocalTime ( true );
307 qDebug("loading file ..."); 306 qDebug("loading file ...");
308 307
309 if ( ! vfload.load( calendar, fileName ) ) 308 if ( ! vfload.load( calendar, fileName ) )
310 return false; 309 return false;
311 QPtrList<Event> er = calendar->rawEvents(); 310 QPtrList<Event> er = calendar->rawEvents();
312 Event* ev = er.first(); 311 Event* ev = er.first();
313 qDebug("reading events... "); 312 qDebug("reading events... ");
314 while ( ev ) { 313 while ( ev ) {
315 QStringList cat = ev->categories(); 314 QStringList cat = ev->categories();
316 if ( cat.contains( "MeetingDEF" )) { 315 if ( cat.contains( "MeetingDEF" )) {
317 ev->setCategories( QStringList() ); 316 ev->setCategories( QStringList() );
318 } 317 }
319 int id = ev->pilotId(); 318 int id = ev->pilotId();
320 Event *event; 319 Event *event;
321 event = existingCal->event( mProfileName ,QString::number( id ) ); 320 event = existingCal->event( mProfileName ,QString::number( id ) );
322 if ( event ) { 321 if ( event ) {
323 event = (Event*)event->clone(); 322 event = (Event*)event->clone();
324 copyEvent( event, ev ); 323 copyEvent( event, ev );
325 calendar->deleteEvent( ev ); 324 calendar->deleteEvent( ev );
326 calendar->addEvent( event); 325 calendar->addEvent( event);
327 } 326 }
328 else 327 else
329 event = ev; 328 event = ev;
330 uint cSum; 329 uint cSum;
331 cSum = PhoneFormat::getCsumEvent( event ); 330 cSum = PhoneFormat::getCsumEvent( event );
332 event->setCsum( mProfileName, QString::number( cSum )); 331 event->setCsum( mProfileName, QString::number( cSum ));
333 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 332 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
334 event->setID( mProfileName,QString::number( id ) ); 333 event->setID( mProfileName,QString::number( id ) );
335 ev = er.next(); 334 ev = er.next();
336 } 335 }
337 { 336 {
338 qDebug("reading todos... "); 337 qDebug("reading todos... ");
339 QPtrList<Todo> tr = calendar->rawTodos(); 338 QPtrList<Todo> tr = calendar->rawTodos();
340 Todo* ev = tr.first(); 339 Todo* ev = tr.first();
341 while ( ev ) { 340 while ( ev ) {
342 341
343 QStringList cat = ev->categories(); 342 QStringList cat = ev->categories();
344 if ( cat.contains( "MeetingDEF" )) { 343 if ( cat.contains( "MeetingDEF" )) {
345 ev->setCategories( QStringList() ); 344 ev->setCategories( QStringList() );
346 } 345 }
347 int id = ev->pilotId(); 346 int id = ev->pilotId();
348 Todo *event; 347 Todo *event;
349 event = existingCal->todo( mProfileName ,QString::number( id ) ); 348 event = existingCal->todo( mProfileName ,QString::number( id ) );
350 if ( event ) { 349 if ( event ) {
351 qDebug("copy todo %s ", event->summary().latin1()); 350 //qDebug("copy todo %s ", event->summary().latin1());
352 351
353 event = (Todo*)event->clone(); 352 event = (Todo*)event->clone();
354 copyTodo( event, ev ); 353 copyTodo( event, ev );
355 calendar->deleteTodo( ev ); 354 calendar->deleteTodo( ev );
356 calendar->addTodo( event); 355 calendar->addTodo( event);
357 } 356 }
358 else 357 else
359 event = ev; 358 event = ev;
360 uint cSum; 359 uint cSum;
361 cSum = PhoneFormat::getCsumTodo( event ); 360 cSum = PhoneFormat::getCsumTodo( event );
362 event->setCsum( mProfileName, QString::number( cSum )); 361 event->setCsum( mProfileName, QString::number( cSum ));
363 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 362 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
364 event->setID( mProfileName,QString::number( id ) ); 363 event->setID( mProfileName,QString::number( id ) );
365 ev = tr.next(); 364 ev = tr.next();
366 } 365 }
367 } 366 }
368 return true; 367 return true;
369} 368}
370void PhoneFormat::copyEvent( Event* to, Event* from ) 369void PhoneFormat::copyEvent( Event* to, Event* from )
371{ 370{
372 if ( from->dtStart().isValid() ) 371 if ( from->dtStart().isValid() )
373 to->setDtStart( from->dtStart() ); 372 to->setDtStart( from->dtStart() );
374 if ( from->dtEnd().isValid() ) 373 if ( from->dtEnd().isValid() )
375 to->setDtEnd( from->dtEnd() ); 374 to->setDtEnd( from->dtEnd() );
376 if ( !from->location().isEmpty() ) 375 if ( !from->location().isEmpty() )
377 to->setLocation( from->location() ); 376 to->setLocation( from->location() );
378 if ( !from->description().isEmpty() ) 377 if ( !from->description().isEmpty() )
379 to->setDescription( from->description() ); 378 to->setDescription( from->description() );
380 if ( !from->summary().isEmpty() ) 379 if ( !from->summary().isEmpty() )
381 to->setSummary( from->summary() ); 380 to->setSummary( from->summary() );
382 381
383 QPtrListIterator<Alarm> it( from->alarms() ); 382 if ( from->alarms().count() ) {
384 if ( it.current() )
385 to->clearAlarms(); 383 to->clearAlarms();
386 const Alarm *a; 384 Alarm *a = from->alarms().first();
387 while( (a = it.current()) ) { 385 Alarm *b = to->newAlarm( );
388 Alarm *b = new Alarm( *a ); 386 b->setEnabled( a->enabled() );
389 b->setParent( to ); 387 if ( a->hasStartOffset() ) {
390 to->addAlarm( b ); 388 b->setStartOffset( a->startOffset() );
391 ++it; 389 }
390 if ( a->hasTime() )
391 b->setTime( a->time() );
392
392 } 393 }
393 QStringList cat = to->categories(); 394 QStringList cat = to->categories();
394 QStringList catFrom = from->categories(); 395 QStringList catFrom = from->categories();
395 QString nCat; 396 QString nCat;
396 int iii; 397 int iii;
397 for ( iii = 0; iii < catFrom.count();++iii ) { 398 for ( iii = 0; iii < catFrom.count();++iii ) {
398 nCat = catFrom[iii]; 399 nCat = catFrom[iii];
399 if ( !nCat.isEmpty() ) 400 if ( !nCat.isEmpty() )
400 if ( !cat.contains( nCat )) { 401 if ( !cat.contains( nCat )) {
401 cat << nCat; 402 cat << nCat;
402 } 403 }
403 } 404 }
404 to->setCategories( cat ); 405 to->setCategories( cat );
405 Recurrence * r = new Recurrence( *from->recurrence(),to); 406 Recurrence * r = new Recurrence( *from->recurrence(),to);
406 to->setRecurrence( r ) ; 407 to->setRecurrence( r ) ;
407 408
408 409
409} 410}
410void PhoneFormat::copyTodo( Todo* to, Todo* from ) 411void PhoneFormat::copyTodo( Todo* to, Todo* from )
411{ 412{
412 if ( from->dtStart().isValid() ) 413 if ( from->dtStart().isValid() )
413 to->setDtStart( from->dtStart() ); 414 to->setDtStart( from->dtStart() );
414 if ( from->dtDue().isValid() ) 415 if ( from->dtDue().isValid() )
415 to->setDtDue( from->dtDue() ); 416 to->setDtDue( from->dtDue() );
416 if ( !from->location().isEmpty() ) 417 if ( !from->location().isEmpty() )
417 to->setLocation( from->location() ); 418 to->setLocation( from->location() );
418 if ( !from->description().isEmpty() ) 419 if ( !from->description().isEmpty() )
419 to->setDescription( from->description() ); 420 to->setDescription( from->description() );
420 if ( !from->summary().isEmpty() ) 421 if ( !from->summary().isEmpty() )
421 to->setSummary( from->summary() ); 422 to->setSummary( from->summary() );
422 423
423 QPtrListIterator<Alarm> it( from->alarms() ); 424 if ( from->alarms().count() ) {
424 if ( it.current() )
425 to->clearAlarms(); 425 to->clearAlarms();
426 const Alarm *a; 426 Alarm *a = from->alarms().first();
427 while( (a = it.current()) ) { 427 Alarm *b = to->newAlarm( );
428 Alarm *b = new Alarm( *a ); 428 b->setEnabled( a->enabled() );
429 b->setParent( to ); 429 if ( a->hasStartOffset() )
430 to->addAlarm( b ); 430 b->setStartOffset( a->startOffset() );
431 ++it; 431 if ( a->hasTime() )
432 b->setTime( a->time() );
432 } 433 }
434
433 QStringList cat = to->categories(); 435 QStringList cat = to->categories();
434 QStringList catFrom = from->categories(); 436 QStringList catFrom = from->categories();
435 QString nCat; 437 QString nCat;
436 int iii; 438 int iii;
437 for ( iii = 0; iii < catFrom.count();++iii ) { 439 for ( iii = 0; iii < catFrom.count();++iii ) {
438 nCat = catFrom[iii]; 440 nCat = catFrom[iii];
439 if ( !nCat.isEmpty() ) 441 if ( !nCat.isEmpty() )
440 if ( !cat.contains( nCat )) { 442 if ( !cat.contains( nCat )) {
441 cat << nCat; 443 cat << nCat;
442 } 444 }
443 } 445 }
444 to->setCategories( cat ); 446 to->setCategories( cat );
445 if ( from->isCompleted() ) { 447 if ( from->isCompleted() ) {
446 to->setCompleted( true ); 448 to->setCompleted( true );
447 if( from->completed().isValid() ) 449 if( from->completed().isValid() )
448 to->setCompleted( from->completed() ); 450 to->setCompleted( from->completed() );
449 } else { 451 } else {
450 // set percentcomplete only, if to->isCompleted() 452 // set percentcomplete only, if to->isCompleted()
451 if ( to->isCompleted() ) 453 if ( to->isCompleted() )
452 to->setPercentComplete(from->percentComplete()); 454 to->setPercentComplete(from->percentComplete());
453 } 455 }
454 if( to->priority() == 2 && from->priority() == 1 ) 456 if( to->priority() == 2 && from->priority() == 1 )
455 ; //skip 457 ; //skip
456 else if (to->priority() == 4 && from->priority() == 5 ) 458 else if (to->priority() == 4 && from->priority() == 5 )
457 ; 459 ;
458 else 460 else
459 to->setPriority(from->priority()); 461 to->setPriority(from->priority());
460 462
461} 463}
462#include <qcstring.h> 464#include <qcstring.h>
463 465
464void PhoneFormat::afterSave( Incidence* inc) 466void PhoneFormat::afterSave( Incidence* inc)
465{ 467{
466 uint csum; 468 uint csum;
467 inc->removeID( mProfileName ); 469 inc->removeID( mProfileName );
468 if ( inc->type() == "Event") 470 if ( inc->type() == "Event")
469 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 471 csum = PhoneFormat::getCsumEvent( (Event*) inc );
470 else 472 else
471 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 473 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
472 inc->setCsum( mProfileName, QString::number( csum )); 474 inc->setCsum( mProfileName, QString::number( csum ));
473 475
474 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 476 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
475 477
476} 478}
477bool PhoneFormat::save( Calendar *calendar) 479bool PhoneFormat::save( Calendar *calendar)
478{ 480{
479 QLabel status ( i18n(" Opening device ..."), 0 ); 481 QLabel status ( i18n(" Opening device ..."), 0 );
480 int w = status.sizeHint().width()+20 ; 482 int w = status.sizeHint().width()+20 ;
481 if ( w < 200 ) w = 230; 483 if ( w < 200 ) w = 230;
482 int h = status.sizeHint().height()+20 ; 484 int h = status.sizeHint().height()+20 ;
483 int dw = QApplication::desktop()->width(); 485 int dw = QApplication::desktop()->width();
484 int dh = QApplication::desktop()->height(); 486 int dh = QApplication::desktop()->height();
485 status.setCaption(i18n("Writing to phone...") ); 487 status.setCaption(i18n("Writing to phone...") );
486 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 488 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
487 status.show(); 489 status.show();
488 status.raise(); 490 status.raise();
489 qApp->processEvents(); 491 qApp->processEvents();
490 QString message; 492 QString message;
491#ifdef _WIN32_ 493#ifdef _WIN32_
492 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 494 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
493#else 495#else
494 QString fileName = "/tmp/kdepimtemp.vcs"; 496 QString fileName = "/tmp/kdepimtemp.vcs";
495#endif 497#endif
496 498
497 // 1 remove events which should be deleted 499 // 1 remove events which should be deleted
498 QPtrList<Event> er = calendar->rawEvents(); 500 QPtrList<Event> er = calendar->rawEvents();
499 Event* ev = er.first(); 501 Event* ev = er.first();
500 while ( ev ) { 502 while ( ev ) {
501 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 503 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
502 calendar->deleteEvent( ev ); 504 calendar->deleteEvent( ev );
503 } else { 505 } else {
504 506
505 } 507 }
506 ev = er.next(); 508 ev = er.next();
507 } 509 }
508 // 2 remove todos which should be deleted 510 // 2 remove todos which should be deleted
509 QPtrList<Todo> tl = calendar->rawTodos(); 511 QPtrList<Todo> tl = calendar->rawTodos();
510 Todo* to = tl.first(); 512 Todo* to = tl.first();
511 while ( to ) { 513 while ( to ) {
512 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 514 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
513 calendar->deleteTodo( to ); 515 calendar->deleteTodo( to );
514 } else { 516 } else {
515 if ( to->isCompleted()) { 517 if ( to->isCompleted()) {
516 calendar->deleteTodo( to ); 518 calendar->deleteTodo( to );
517 } 519 }
518 } 520 }
519 to = tl.next(); 521 to = tl.next();
520 } 522 }
521 // 3 save file 523 // 3 save file
522 VCalFormat vfsave; 524 VCalFormat vfsave;
523 vfsave.setLocalTime ( true ); 525 vfsave.setLocalTime ( true );
524 if ( ! vfsave.save( calendar, fileName ) ) 526 if ( ! vfsave.save( calendar, fileName ) )
525 return false; 527 return false;
526 // 4 call kammu 528 // 4 call kammu
527 QString command ="./kammu --restore " + fileName ; 529 QString command ="./kammu --restore " + fileName ;
528 int ret; 530 int ret;
529 while ( (ret = system ( command.latin1())) != 0 ) { 531 while ( (ret = system ( command.latin1())) != 0 ) {
530 qDebug("Error S::command returned %d. asking users", ret); 532 qDebug("Error S::command returned %d. asking users", ret);
531 int retval = KMessageBox::warningContinueCancel(0, 533 int retval = KMessageBox::warningContinueCancel(0,
532 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); 534 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
533 if ( retval != KMessageBox::Continue ) 535 if ( retval != KMessageBox::Continue )
534 return false; 536 return false;
535 } 537 }
536 if ( ret != 0 ) { 538
537 qDebug("Error S::command returned %d", ret);
538 return false;
539 }
540 // 5 reread data 539 // 5 reread data
541 message = i18n(" Rereading all data ... "); 540 message = i18n(" Rereading all data ... ");
542 status.setText ( message ); 541 status.setText ( message );
543 qApp->processEvents(); 542 qApp->processEvents();
544 CalendarLocal* calendarTemp = new CalendarLocal(); 543 CalendarLocal* calendarTemp = new CalendarLocal();
545 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 544 calendarTemp->setTimeZoneId( calendar->timeZoneId());
546 if ( ! load( calendarTemp,calendar) ){ 545 if ( ! load( calendarTemp,calendar) ){
547 qDebug("error reloading calendar "); 546 qDebug("error reloading calendar ");
548 delete calendarTemp; 547 delete calendarTemp;
549 return false; 548 return false;
550 } 549 }
551 // 6 compare data 550 // 6 compare data
552 551
553//algo 6 compare event 552//algo 6 compare event
554 er = calendar->rawEvents(); 553 er = calendar->rawEvents();
555 ev = er.first(); 554 ev = er.first();
556 message = i18n(" Comparing event # "); 555 message = i18n(" Comparing event # ");
557 QPtrList<Event> er1 = calendarTemp->rawEvents(); 556 QPtrList<Event> er1 = calendarTemp->rawEvents();
558 Event* ev1; 557 Event* ev1;
559 int procCount = 0; 558 int procCount = 0;
560 while ( ev ) { 559 while ( ev ) {
561 //qDebug("event new ID %s",ev->summary().latin1()); 560 //qDebug("event new ID %s",ev->summary().latin1());
562 status.setText ( message + QString::number ( ++procCount ) ); 561 status.setText ( message + QString::number ( ++procCount ) );
563 qApp->processEvents(); 562 qApp->processEvents();
564 uint csum; 563 uint csum;
565 csum = PhoneFormat::getCsumEvent( ev ); 564 csum = PhoneFormat::getCsumEvent( ev );
566 QString cSum = QString::number( csum ); 565 QString cSum = QString::number( csum );
567 //ev->setCsum( mProfileName, cSum ); 566 //ev->setCsum( mProfileName, cSum );
568 //qDebug("Event cSum %s ", cSum.latin1()); 567 //qDebug("Event cSum %s ", cSum.latin1());
569 ev1 = er1.first(); 568 ev1 = er1.first();
570 while ( ev1 ) { 569 while ( ev1 ) {
571 if ( ev1->getCsum( mProfileName ) == cSum ) { 570 if ( ev1->getCsum( mProfileName ) == cSum ) {
572 er1.remove( ev1 ); 571 er1.remove( ev1 );
573 afterSave( ev ); 572 afterSave( ev );
574 ev->setID(mProfileName, ev1->getID(mProfileName) ); 573 ev->setID(mProfileName, ev1->getID(mProfileName) );
575 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 574 //qDebug("Event found on phone for %s ", ev->summary().latin1());
576 575
577 break; 576 break;
578 } 577 }
579 ev1 = er1.next(); 578 ev1 = er1.next();
580 } 579 }
581 if ( ! ev1 ) { 580 if ( ! ev1 ) {
582 ev->removeID(mProfileName); 581 // ev->removeID(mProfileName);
583 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 582 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
584 } 583 }
585 584
586 585
587 ev = er.next(); 586 ev = er.next();
588 } 587 }
589 //algo 6 compare todo 588 //algo 6 compare todo
590 tl = calendar->rawTodos(); 589 tl = calendar->rawTodos();
591 to = tl.first(); 590 to = tl.first();
592 procCount = 0; 591 procCount = 0;
593 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 592 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
594 Todo* to1 ; 593 Todo* to1 ;
595 message = i18n(" Comparing todo # "); 594 message = i18n(" Comparing todo # ");
596 while ( to ) { 595 while ( to ) {
597 qDebug("todo2 %d ", procCount);
598 status.setText ( message + QString::number ( ++procCount ) ); 596 status.setText ( message + QString::number ( ++procCount ) );
599 qApp->processEvents(); 597 qApp->processEvents();
600 uint csum; 598 uint csum;
601 csum = PhoneFormat::getCsumTodo( to ); 599 csum = PhoneFormat::getCsumTodo( to );
602 QString cSum = QString::number( csum ); 600 QString cSum = QString::number( csum );
603 //to->setCsum( mProfileName, cSum ); 601 //to->setCsum( mProfileName, cSum );
604 qDebug("Todo cSum %s ", cSum.latin1()); 602 //qDebug("Todo cSum %s ", cSum.latin1());
605 Todo* to1 = tl1.first(); 603 Todo* to1 = tl1.first();
606 while ( to1 ) { 604 while ( to1 ) {
607 if ( to1->getCsum( mProfileName ) == cSum ) { 605 if ( to1->getCsum( mProfileName ) == cSum ) {
608 tl1.remove( to1 ); 606 tl1.remove( to1 );
609 afterSave( to ); 607 afterSave( to );
610 to->setID(mProfileName, to1->getID(mProfileName) ); 608 to->setID(mProfileName, to1->getID(mProfileName) );
611 break; 609 break;
612 } 610 }
613 to1 = tl1.next(); 611 to1 = tl1.next();
614 } 612 }
615 if ( ! to1 ) { 613 if ( ! to1 ) {
616 to->removeID(mProfileName); 614 //to->removeID(mProfileName);
617 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 615 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
618 } 616 }
619 617
620 to = tl.next(); 618 to = tl.next();
621 } 619 }
622 delete calendarTemp; 620 delete calendarTemp;
623 return true; 621 return true;
624 622
625 623
626 624
627} 625}
628 626
629 627
630QString PhoneFormat::toString( Calendar * ) 628QString PhoneFormat::toString( Calendar * )
631{ 629{
632 return QString::null; 630 return QString::null;
633} 631}
634bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 632bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
635{ 633{
636 return false; 634 return false;
637} 635}