summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp8
-rw-r--r--libkcal/phoneformat.cpp341
-rw-r--r--libkcal/phoneformat.h13
3 files changed, 168 insertions, 194 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index d6ead37..547d02b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3543 +1,3541 @@
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 locCh = ( local->lastModified() > mLastCalendarSync ); 732 locCh = ( local->lastModified() > mLastCalendarSync );
733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
734 if ( !remCh && ! locCh ) { 734 if ( !remCh && ! locCh ) {
735 //qDebug("both not changed "); 735 //qDebug("both not changed ");
736 lastSync = local->lastModified().addDays(1); 736 lastSync = local->lastModified().addDays(1);
737 } else { 737 } else {
738 if ( locCh ) { 738 if ( locCh ) {
739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); 739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() );
740 lastSync = local->lastModified().addDays( -1 ); 740 lastSync = local->lastModified().addDays( -1 );
741 if ( !remCh ) 741 if ( !remCh )
742 remote->setLastModified( lastSync.addDays( -1 ) ); 742 remote->setLastModified( lastSync.addDays( -1 ) );
743 } else { 743 } else {
744 //qDebug(" not loc changed "); 744 //qDebug(" not loc changed ");
745 lastSync = local->lastModified().addDays( 1 ); 745 lastSync = local->lastModified().addDays( 1 );
746 if ( remCh ) 746 if ( remCh )
747 remote->setLastModified( lastSync.addDays( 1 ) ); 747 remote->setLastModified( lastSync.addDays( 1 ) );
748 748
749 } 749 }
750 } 750 }
751 full = true; 751 full = true;
752 if ( mode < SYNC_PREF_ASK ) 752 if ( mode < SYNC_PREF_ASK )
753 mode = SYNC_PREF_ASK; 753 mode = SYNC_PREF_ASK;
754 } else { 754 } else {
755 if ( local->lastModified() == remote->lastModified() ) 755 if ( local->lastModified() == remote->lastModified() )
756 if ( local->revision() == remote->revision() ) 756 if ( local->revision() == remote->revision() )
757 return 0; 757 return 0;
758 758
759 } 759 }
760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
761 761
762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
764 //full = true; //debug only 764 //full = true; //debug only
765 if ( full ) { 765 if ( full ) {
766 bool equ = false; 766 bool equ = false;
767 if ( local->type() == "Event" ) { 767 if ( local->type() == "Event" ) {
768 equ = (*((Event*) local) == *((Event*) remote)); 768 equ = (*((Event*) local) == *((Event*) remote));
769 } 769 }
770 else if ( local->type() =="Todo" ) 770 else if ( local->type() =="Todo" )
771 equ = (*((Todo*) local) == (*(Todo*) remote)); 771 equ = (*((Todo*) local) == (*(Todo*) remote));
772 else if ( local->type() =="Journal" ) 772 else if ( local->type() =="Journal" )
773 equ = (*((Journal*) local) == *((Journal*) remote)); 773 equ = (*((Journal*) local) == *((Journal*) remote));
774 if ( equ ) { 774 if ( equ ) {
775 //qDebug("equal "); 775 //qDebug("equal ");
776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
778 } 778 }
779 if ( mode < SYNC_PREF_FORCE_LOCAL ) 779 if ( mode < SYNC_PREF_FORCE_LOCAL )
780 return 0; 780 return 0;
781 781
782 }//else //debug only 782 }//else //debug only
783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
784 } 784 }
785 int result; 785 int result;
786 bool localIsNew; 786 bool localIsNew;
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remote->lastModified() ) 792 if ( lastSync > remote->lastModified() )
793 return 1; 793 return 1;
794 if ( lastSync > local->lastModified() ) 794 if ( lastSync > local->lastModified() )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remote->lastModified() ) 799 if ( lastSync > remote->lastModified() )
800 return 1; 800 return 1;
801 if ( lastSync > local->lastModified() ) 801 if ( lastSync > local->lastModified() )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( local->lastModified() > remote->lastModified() ) 806 if ( local->lastModified() > remote->lastModified() )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
813 if ( lastSync > remote->lastModified() ) 813 if ( lastSync > remote->lastModified() )
814 return 1; 814 return 1;
815 if ( lastSync > local->lastModified() ) 815 if ( lastSync > local->lastModified() )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
818 localIsNew = local->lastModified() > remote->lastModified(); 818 localIsNew = local->lastModified() > remote->lastModified();
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872// probaly useless 872// probaly useless
873void CalendarView::setupExternSyncProfiles() 873void CalendarView::setupExternSyncProfiles()
874{ 874{
875 Event* lse; 875 Event* lse;
876 mExternLastSyncEvent.clear(); 876 mExternLastSyncEvent.clear();
877 int i; 877 int i;
878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
880 if ( lse ) 880 if ( lse )
881 mExternLastSyncEvent.append( lse ); 881 mExternLastSyncEvent.append( lse );
882 else 882 else
883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
884 } 884 }
885 885
886} 886}
887// we check, if the to delete event has a id for a profile 887// we check, if the to delete event has a id for a profile
888// if yes, we set this id in the profile to delete 888// if yes, we set this id in the profile to delete
889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
890{ 890{
891 if ( lastSync.count() == 0 ) { 891 if ( lastSync.count() == 0 ) {
892 //qDebug(" lastSync.count() == 0"); 892 //qDebug(" lastSync.count() == 0");
893 return; 893 return;
894 } 894 }
895 if ( toDelete->type() == "Journal" ) 895 if ( toDelete->type() == "Journal" )
896 return; 896 return;
897 897
898 Event* eve = lastSync.first(); 898 Event* eve = lastSync.first();
899 899
900 while ( eve ) { 900 while ( eve ) {
901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
902 if ( !id.isEmpty() ) { 902 if ( !id.isEmpty() ) {
903 QString des = eve->description(); 903 QString des = eve->description();
904 QString pref = "e"; 904 QString pref = "e";
905 if ( toDelete->type() == "Todo" ) 905 if ( toDelete->type() == "Todo" )
906 pref = "t"; 906 pref = "t";
907 des += pref+ id + ","; 907 des += pref+ id + ",";
908 eve->setReadOnly( false ); 908 eve->setReadOnly( false );
909 eve->setDescription( des ); 909 eve->setDescription( des );
910 //qDebug("setdes %s ", des.latin1()); 910 //qDebug("setdes %s ", des.latin1());
911 eve->setReadOnly( true ); 911 eve->setReadOnly( true );
912 } 912 }
913 eve = lastSync.next(); 913 eve = lastSync.next();
914 } 914 }
915 915
916} 916}
917void CalendarView::checkExternalId( Incidence * inc ) 917void CalendarView::checkExternalId( Incidence * inc )
918{ 918{
919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
920 checkExternSyncEvent( lastSync, inc ); 920 checkExternSyncEvent( lastSync, inc );
921 921
922} 922}
923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
924{ 924{
925 bool syncOK = true; 925 bool syncOK = true;
926 int addedEvent = 0; 926 int addedEvent = 0;
927 int addedEventR = 0; 927 int addedEventR = 0;
928 int deletedEventR = 0; 928 int deletedEventR = 0;
929 int deletedEventL = 0; 929 int deletedEventL = 0;
930 int changedLocal = 0; 930 int changedLocal = 0;
931 int changedRemote = 0; 931 int changedRemote = 0;
932 //QPtrList<Event> el = local->rawEvents(); 932 //QPtrList<Event> el = local->rawEvents();
933 Event* eventR; 933 Event* eventR;
934 QString uid; 934 QString uid;
935 int take; 935 int take;
936 Event* eventL; 936 Event* eventL;
937 Event* eventRSync; 937 Event* eventRSync;
938 Event* eventLSync; 938 Event* eventLSync;
939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
941 bool fullDateRange = false; 941 bool fullDateRange = false;
942 mLastCalendarSync = QDateTime::currentDateTime(); 942 mLastCalendarSync = QDateTime::currentDateTime();
943 QDateTime modifiedCalendar = mLastCalendarSync;; 943 QDateTime modifiedCalendar = mLastCalendarSync;;
944 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 944 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
945 if ( eventR ) { 945 if ( eventR ) {
946 eventRSync = (Event*) eventR->clone(); 946 eventRSync = (Event*) eventR->clone();
947 remote->deleteEvent(eventR ); 947 remote->deleteEvent(eventR );
948 948
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 eventLSync = getLastSyncEvent(); 958 eventLSync = getLastSyncEvent();
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( fullDateRange ) 970 if ( fullDateRange )
971 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 971 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
972 else 972 else
973 mLastCalendarSync = eventLSync->dtStart(); 973 mLastCalendarSync = eventLSync->dtStart();
974 // for resyncing if own file has changed 974 // for resyncing if own file has changed
975 if ( mCurrentSyncDevice == "deleteaftersync" ) { 975 if ( mCurrentSyncDevice == "deleteaftersync" ) {
976 mLastCalendarSync = loadedFileVersion; 976 mLastCalendarSync = loadedFileVersion;
977 qDebug("setting mLastCalendarSync "); 977 qDebug("setting mLastCalendarSync ");
978 } 978 }
979 //qDebug("*************************** "); 979 //qDebug("*************************** ");
980 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 980 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
981 QPtrList<Incidence> er = remote->rawIncidences(); 981 QPtrList<Incidence> er = remote->rawIncidences();
982 Incidence* inR = er.first(); 982 Incidence* inR = er.first();
983 Incidence* inL; 983 Incidence* inL;
984 QProgressBar bar( er.count(),0 ); 984 QProgressBar bar( er.count(),0 );
985 bar.setCaption (i18n("Syncing - close to abort!") ); 985 bar.setCaption (i18n("Syncing - close to abort!") );
986 986
987 int w = 300; 987 int w = 300;
988 if ( QApplication::desktop()->width() < 320 ) 988 if ( QApplication::desktop()->width() < 320 )
989 w = 220; 989 w = 220;
990 int h = bar.sizeHint().height() ; 990 int h = bar.sizeHint().height() ;
991 int dw = QApplication::desktop()->width(); 991 int dw = QApplication::desktop()->width();
992 int dh = QApplication::desktop()->height(); 992 int dh = QApplication::desktop()->height();
993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
994 bar.show(); 994 bar.show();
995 int modulo = (er.count()/10)+1; 995 int modulo = (er.count()/10)+1;
996 int incCounter = 0; 996 int incCounter = 0;
997 while ( inR ) { 997 while ( inR ) {
998 if ( ! bar.isVisible() ) 998 if ( ! bar.isVisible() )
999 return false; 999 return false;
1000 if ( incCounter % modulo == 0 ) 1000 if ( incCounter % modulo == 0 )
1001 bar.setProgress( incCounter ); 1001 bar.setProgress( incCounter );
1002 ++incCounter; 1002 ++incCounter;
1003 uid = inR->uid(); 1003 uid = inR->uid();
1004 bool skipIncidence = false; 1004 bool skipIncidence = false;
1005 if ( uid.left(15) == QString("last-syncEvent-") ) 1005 if ( uid.left(15) == QString("last-syncEvent-") )
1006 skipIncidence = true; 1006 skipIncidence = true;
1007 1007
1008 qApp->processEvents(); 1008 qApp->processEvents();
1009 if ( !skipIncidence ) { 1009 if ( !skipIncidence ) {
1010 inL = local->incidence( uid ); 1010 inL = local->incidence( uid );
1011 if ( inL ) { // maybe conflict - same uid in both calendars 1011 if ( inL ) { // maybe conflict - same uid in both calendars
1012 int maxrev = inL->revision(); 1012 int maxrev = inL->revision();
1013 if ( maxrev < inR->revision() ) 1013 if ( maxrev < inR->revision() )
1014 maxrev = inR->revision(); 1014 maxrev = inR->revision();
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local
1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1021 remote->deleteIncidence( inR ); 1021 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1022 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1023 inL->setRevision( maxrev );
1024 remote->addIncidence( inL->clone() ); 1024 remote->addIncidence( inL->clone() );
1025 ++changedRemote; 1025 ++changedRemote;
1026 } else { 1026 } else {
1027 if ( inR->revision() < maxrev ) 1027 if ( inR->revision() < maxrev )
1028 inR->setRevision( maxrev ); 1028 inR->setRevision( maxrev );
1029 local->deleteIncidence( inL ); 1029 local->deleteIncidence( inL );
1030 local->addIncidence( inR->clone() ); 1030 local->addIncidence( inR->clone() );
1031 ++changedLocal; 1031 ++changedLocal;
1032 } 1032 }
1033 } 1033 }
1034 } else { // no conflict 1034 } else { // no conflict
1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1036 QString des = eventLSync->description(); 1036 QString des = eventLSync->description();
1037 QString pref = "e"; 1037 QString pref = "e";
1038 if ( inR->type() == "Todo" ) 1038 if ( inR->type() == "Todo" )
1039 pref = "t"; 1039 pref = "t";
1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1042 //remote->deleteIncidence( inR ); 1042 //remote->deleteIncidence( inR );
1043 ++deletedEventR; 1043 ++deletedEventR;
1044 } else { 1044 } else {
1045 inR->setLastModified( modifiedCalendar ); 1045 inR->setLastModified( modifiedCalendar );
1046 local->addIncidence( inR->clone() ); 1046 local->addIncidence( inR->clone() );
1047 ++addedEvent; 1047 ++addedEvent;
1048 } 1048 }
1049 } else { 1049 } else {
1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1051 inR->setLastModified( modifiedCalendar ); 1051 inR->setLastModified( modifiedCalendar );
1052 local->addIncidence( inR->clone() ); 1052 local->addIncidence( inR->clone() );
1053 ++addedEvent; 1053 ++addedEvent;
1054 } else { 1054 } else {
1055 checkExternSyncEvent(eventRSyncSharp, inR); 1055 checkExternSyncEvent(eventRSyncSharp, inR);
1056 remote->deleteIncidence( inR ); 1056 remote->deleteIncidence( inR );
1057 ++deletedEventR; 1057 ++deletedEventR;
1058 } 1058 }
1059 } 1059 }
1060 } 1060 }
1061 } 1061 }
1062 inR = er.next(); 1062 inR = er.next();
1063 } 1063 }
1064 QPtrList<Incidence> el = local->rawIncidences(); 1064 QPtrList<Incidence> el = local->rawIncidences();
1065 inL = el.first(); 1065 inL = el.first();
1066 modulo = (el.count()/10)+1; 1066 modulo = (el.count()/10)+1;
1067 bar.setCaption (i18n("Add / remove events") ); 1067 bar.setCaption (i18n("Add / remove events") );
1068 bar.setTotalSteps ( el.count() ) ; 1068 bar.setTotalSteps ( el.count() ) ;
1069 bar.show(); 1069 bar.show();
1070 incCounter = 0; 1070 incCounter = 0;
1071 1071
1072 while ( inL ) { 1072 while ( inL ) {
1073 1073
1074 qApp->processEvents(); 1074 qApp->processEvents();
1075 if ( ! bar.isVisible() ) 1075 if ( ! bar.isVisible() )
1076 return false; 1076 return false;
1077 if ( incCounter % modulo == 0 ) 1077 if ( incCounter % modulo == 0 )
1078 bar.setProgress( incCounter ); 1078 bar.setProgress( incCounter );
1079 ++incCounter; 1079 ++incCounter;
1080 uid = inL->uid(); 1080 uid = inL->uid();
1081 bool skipIncidence = false; 1081 bool skipIncidence = false;
1082 if ( uid.left(15) == QString("last-syncEvent-") ) 1082 if ( uid.left(15) == QString("last-syncEvent-") )
1083 skipIncidence = true; 1083 skipIncidence = true;
1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1085 skipIncidence = true; 1085 skipIncidence = true;
1086 if ( !skipIncidence ) { 1086 if ( !skipIncidence ) {
1087 inR = remote->incidence( uid ); 1087 inR = remote->incidence( uid );
1088 if ( ! inR ) { 1088 if ( ! inR ) {
1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1091 local->deleteIncidence( inL ); 1091 local->deleteIncidence( inL );
1092 ++deletedEventL; 1092 ++deletedEventL;
1093 } else { 1093 } else {
1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1095 inL->removeID(mCurrentSyncDevice ); 1095 inL->removeID(mCurrentSyncDevice );
1096 ++addedEventR; 1096 ++addedEventR;
1097 inL->setLastModified( modifiedCalendar ); 1097 inL->setLastModified( modifiedCalendar );
1098 remote->addIncidence( inL->clone() ); 1098 remote->addIncidence( inL->clone() );
1099 } 1099 }
1100 } 1100 }
1101 } else { 1101 } else {
1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1103 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1104 local->deleteIncidence( inL );
1105 ++deletedEventL; 1105 ++deletedEventL;
1106 } else { 1106 } else {
1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1108 ++addedEventR; 1108 ++addedEventR;
1109 inL->setLastModified( modifiedCalendar ); 1109 inL->setLastModified( modifiedCalendar );
1110 remote->addIncidence( inL->clone() ); 1110 remote->addIncidence( inL->clone() );
1111 } 1111 }
1112 } 1112 }
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 inL = el.next(); 1116 inL = el.next();
1117 } 1117 }
1118 1118
1119 bar.hide(); 1119 bar.hide();
1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1121 eventLSync->setReadOnly( false ); 1121 eventLSync->setReadOnly( false );
1122 eventLSync->setDtStart( mLastCalendarSync ); 1122 eventLSync->setDtStart( mLastCalendarSync );
1123 eventRSync->setDtStart( mLastCalendarSync ); 1123 eventRSync->setDtStart( mLastCalendarSync );
1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1128 eventLSync->setReadOnly( true ); 1128 eventLSync->setReadOnly( true );
1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1130 remote->addEvent( eventRSync ); 1130 remote->addEvent( eventRSync );
1131 QString mes; 1131 QString mes;
1132 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 ); 1132 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 );
1133 if ( KOPrefs::instance()->mShowSyncSummary ) { 1133 if ( KOPrefs::instance()->mShowSyncSummary ) {
1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1135 } 1135 }
1136 qDebug( mes ); 1136 qDebug( mes );
1137 mCalendar->checkAlarmForIncidence( 0, true ); 1137 mCalendar->checkAlarmForIncidence( 0, true );
1138 return syncOK; 1138 return syncOK;
1139} 1139}
1140 1140
1141void CalendarView::setSyncDevice( QString s ) 1141void CalendarView::setSyncDevice( QString s )
1142{ 1142{
1143 mCurrentSyncDevice= s; 1143 mCurrentSyncDevice= s;
1144} 1144}
1145void CalendarView::setSyncName( QString s ) 1145void CalendarView::setSyncName( QString s )
1146{ 1146{
1147 mCurrentSyncName= s; 1147 mCurrentSyncName= s;
1148} 1148}
1149bool CalendarView::syncCalendar(QString filename, int mode) 1149bool CalendarView::syncCalendar(QString filename, int mode)
1150{ 1150{
1151 mGlobalSyncMode = SYNC_MODE_NORMAL; 1151 mGlobalSyncMode = SYNC_MODE_NORMAL;
1152 CalendarLocal* calendar = new CalendarLocal(); 1152 CalendarLocal* calendar = new CalendarLocal();
1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1154 FileStorage* storage = new FileStorage( calendar ); 1154 FileStorage* storage = new FileStorage( calendar );
1155 bool syncOK = false; 1155 bool syncOK = false;
1156 storage->setFileName( filename ); 1156 storage->setFileName( filename );
1157 // qDebug("loading ... "); 1157 // qDebug("loading ... ");
1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1159 getEventViewerDialog()->setSyncMode( true ); 1159 getEventViewerDialog()->setSyncMode( true );
1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1161 getEventViewerDialog()->setSyncMode( false ); 1161 getEventViewerDialog()->setSyncMode( false );
1162 if ( syncOK ) { 1162 if ( syncOK ) {
1163 if ( KOPrefs::instance()->mWriteBackFile ) 1163 if ( KOPrefs::instance()->mWriteBackFile )
1164 { 1164 {
1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1166 storage->save(); 1166 storage->save();
1167 } 1167 }
1168 } 1168 }
1169 setModified( true ); 1169 setModified( true );
1170 } 1170 }
1171 delete storage; 1171 delete storage;
1172 delete calendar; 1172 delete calendar;
1173 if ( syncOK ) 1173 if ( syncOK )
1174 updateView(); 1174 updateView();
1175 return syncOK; 1175 return syncOK;
1176} 1176}
1177void CalendarView::syncPhone() 1177void CalendarView::syncPhone()
1178{ 1178{
1179 syncExternal( 1 ); 1179 syncExternal( 1 );
1180} 1180}
1181void CalendarView::syncExternal( int mode ) 1181void CalendarView::syncExternal( int mode )
1182{ 1182{
1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1184 //mCurrentSyncDevice = "sharp-DTM"; 1184 //mCurrentSyncDevice = "sharp-DTM";
1185 if ( KOPrefs::instance()->mAskForPreferences ) 1185 if ( KOPrefs::instance()->mAskForPreferences )
1186 edit_sync_options(); 1186 edit_sync_options();
1187 qApp->processEvents(); 1187 qApp->processEvents();
1188 CalendarLocal* calendar = new CalendarLocal(); 1188 CalendarLocal* calendar = new CalendarLocal();
1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1190 bool syncOK = false; 1190 bool syncOK = false;
1191 bool loadSuccess = false; 1191 bool loadSuccess = false;
1192 PhoneFormat* phoneFormat = 0; 1192 PhoneFormat* phoneFormat = 0;
1193#ifndef DESKTOP_VERSION 1193#ifndef DESKTOP_VERSION
1194 SharpFormat* sharpFormat = 0; 1194 SharpFormat* sharpFormat = 0;
1195 if ( mode == 0 ) { // sharp 1195 if ( mode == 0 ) { // sharp
1196 sharpFormat = new SharpFormat () ; 1196 sharpFormat = new SharpFormat () ;
1197 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1197 loadSuccess = sharpFormat->load( calendar, mCalendar );
1198 1198
1199 } else 1199 } else
1200#endif 1200#endif
1201 if ( mode == 1 ) { // phone 1201 if ( mode == 1 ) { // phone
1202 phoneFormat = new PhoneFormat (); 1202 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1203 loadSuccess = phoneFormat->load( calendar,
1204 mCalendar,
1205 mCurrentSyncDevice,
1206 KOPrefs::instance()->mPhoneDevice, 1203 KOPrefs::instance()->mPhoneDevice,
1207 KOPrefs::instance()->mPhoneConnection, 1204 KOPrefs::instance()->mPhoneConnection,
1208 KOPrefs::instance()->mPhoneModel); 1205 KOPrefs::instance()->mPhoneModel);
1206 loadSuccess = phoneFormat->load( calendar,mCalendar);
1209 1207
1210 } else 1208 } else
1211 return; 1209 return;
1212 if ( loadSuccess ) { 1210 if ( loadSuccess ) {
1213 getEventViewerDialog()->setSyncMode( true ); 1211 getEventViewerDialog()->setSyncMode( true );
1214 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1212 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1215 getEventViewerDialog()->setSyncMode( false ); 1213 getEventViewerDialog()->setSyncMode( false );
1216 qApp->processEvents(); 1214 qApp->processEvents();
1217 if ( syncOK ) { 1215 if ( syncOK ) {
1218 if ( KOPrefs::instance()->mWriteBackFile ) 1216 if ( KOPrefs::instance()->mWriteBackFile )
1219 { 1217 {
1220 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1218 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1221 Incidence* inc = iL.first(); 1219 Incidence* inc = iL.first();
1222 /* obsolete 1220 /* obsolete
1223 while ( inc ) { 1221 while ( inc ) {
1224 inc->setZaurusStat( inc->revision () ); 1222 inc->setZaurusStat( inc->revision () );
1225 inc = iL.next(); 1223 inc = iL.next();
1226 } 1224 }
1227 */ 1225 */
1228#ifndef DESKTOP_VERSION 1226#ifndef DESKTOP_VERSION
1229 if ( sharpFormat ) 1227 if ( sharpFormat )
1230 sharpFormat->save(calendar); 1228 sharpFormat->save(calendar);
1231#endif 1229#endif
1232 if ( phoneFormat ) 1230 if ( phoneFormat )
1233 phoneFormat->save(calendar); 1231 phoneFormat->save(calendar);
1234 iL = calendar->rawIncidences(); 1232 iL = calendar->rawIncidences();
1235 inc = iL.first(); 1233 inc = iL.first();
1236 Incidence* loc; 1234 Incidence* loc;
1237 while ( inc ) { 1235 while ( inc ) {
1238 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1236 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1239 loc = mCalendar->incidence(inc->uid() ); 1237 loc = mCalendar->incidence(inc->uid() );
1240 if ( loc ) { 1238 if ( loc ) {
1241 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1239 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1242 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1240 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1243 } 1241 }
1244 } 1242 }
1245 inc = iL.next(); 1243 inc = iL.next();
1246 } 1244 }
1247 Incidence* lse = getLastSyncEvent(); 1245 Incidence* lse = getLastSyncEvent();
1248 if ( lse ) { 1246 if ( lse ) {
1249 lse->setReadOnly( false ); 1247 lse->setReadOnly( false );
1250 lse->setDescription( "" ); 1248 lse->setDescription( "" );
1251 lse->setReadOnly( true ); 1249 lse->setReadOnly( true );
1252 } 1250 }
1253 } 1251 }
1254 } 1252 }
1255 setModified( true ); 1253 setModified( true );
1256 } else { 1254 } else {
1257 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1255 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1258 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1256 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1259 question, i18n("Ok")) ; 1257 question, i18n("Ok")) ;
1260 1258
1261 } 1259 }
1262 delete calendar; 1260 delete calendar;
1263 updateView(); 1261 updateView();
1264 return ;//syncOK; 1262 return ;//syncOK;
1265 1263
1266} 1264}
1267void CalendarView::syncSharp() 1265void CalendarView::syncSharp()
1268{ 1266{
1269 syncExternal( 0 ); 1267 syncExternal( 0 );
1270 1268
1271} 1269}
1272 1270
1273 1271
1274#include <kabc/stdaddressbook.h> 1272#include <kabc/stdaddressbook.h>
1275bool CalendarView::importBday() 1273bool CalendarView::importBday()
1276{ 1274{
1277 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1275 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1278 KABC::AddressBook::Iterator it; 1276 KABC::AddressBook::Iterator it;
1279 int count = 0; 1277 int count = 0;
1280 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1278 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1281 ++count; 1279 ++count;
1282 } 1280 }
1283 QProgressBar bar(count,0 ); 1281 QProgressBar bar(count,0 );
1284 int w = 300; 1282 int w = 300;
1285 if ( QApplication::desktop()->width() < 320 ) 1283 if ( QApplication::desktop()->width() < 320 )
1286 w = 220; 1284 w = 220;
1287 int h = bar.sizeHint().height() ; 1285 int h = bar.sizeHint().height() ;
1288 int dw = QApplication::desktop()->width(); 1286 int dw = QApplication::desktop()->width();
1289 int dh = QApplication::desktop()->height(); 1287 int dh = QApplication::desktop()->height();
1290 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1288 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1291 bar.show(); 1289 bar.show();
1292 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1290 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1293 qApp->processEvents(); 1291 qApp->processEvents();
1294 count = 0; 1292 count = 0;
1295 int addCount = 0; 1293 int addCount = 0;
1296 KCal::Attendee* a = 0; 1294 KCal::Attendee* a = 0;
1297 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1295 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1298 if ( ! bar.isVisible() ) 1296 if ( ! bar.isVisible() )
1299 return false; 1297 return false;
1300 bar.setProgress( count++ ); 1298 bar.setProgress( count++ );
1301 qApp->processEvents(); 1299 qApp->processEvents();
1302 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1300 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1303 if ( (*it).birthday().date().isValid() ){ 1301 if ( (*it).birthday().date().isValid() ){
1304 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1302 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1305 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1303 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1306 ++addCount; 1304 ++addCount;
1307 } 1305 }
1308 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1306 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1309 if ( anni.isValid() ){ 1307 if ( anni.isValid() ){
1310 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1308 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1311 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1309 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1312 ++addCount; 1310 ++addCount;
1313 } 1311 }
1314 } 1312 }
1315 updateView(); 1313 updateView();
1316 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1314 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1317 return true; 1315 return true;
1318} 1316}
1319 1317
1320bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1318bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1321{ 1319{
1322 //qDebug("addAnni "); 1320 //qDebug("addAnni ");
1323 Event * ev = new Event(); 1321 Event * ev = new Event();
1324 if ( a ) { 1322 if ( a ) {
1325 ev->addAttendee( a ); 1323 ev->addAttendee( a );
1326 } 1324 }
1327 QString kind; 1325 QString kind;
1328 if ( birthday ) 1326 if ( birthday )
1329 kind = i18n( "Birthday" ); 1327 kind = i18n( "Birthday" );
1330 else 1328 else
1331 kind = i18n( "Anniversary" ); 1329 kind = i18n( "Anniversary" );
1332 ev->setSummary( name + " - " + kind ); 1330 ev->setSummary( name + " - " + kind );
1333 ev->setOrganizer( "nobody@nowhere" ); 1331 ev->setOrganizer( "nobody@nowhere" );
1334 ev->setCategories( kind ); 1332 ev->setCategories( kind );
1335 ev->setDtStart( QDateTime(date) ); 1333 ev->setDtStart( QDateTime(date) );
1336 ev->setDtEnd( QDateTime(date) ); 1334 ev->setDtEnd( QDateTime(date) );
1337 ev->setFloats( true ); 1335 ev->setFloats( true );
1338 Recurrence * rec = ev->recurrence(); 1336 Recurrence * rec = ev->recurrence();
1339 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1337 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1340 rec->addYearlyNum( date.month() ); 1338 rec->addYearlyNum( date.month() );
1341 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1339 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1342 delete ev; 1340 delete ev;
1343 return false; 1341 return false;
1344 } 1342 }
1345 return true; 1343 return true;
1346 1344
1347} 1345}
1348bool CalendarView::importQtopia( const QString &categories, 1346bool CalendarView::importQtopia( const QString &categories,
1349 const QString &datebook, 1347 const QString &datebook,
1350 const QString &todolist ) 1348 const QString &todolist )
1351{ 1349{
1352 1350
1353 QtopiaFormat qtopiaFormat; 1351 QtopiaFormat qtopiaFormat;
1354 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1352 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1355 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1353 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1356 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1354 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1357 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1355 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1358 1356
1359 updateView(); 1357 updateView();
1360 return true; 1358 return true;
1361 1359
1362#if 0 1360#if 0
1363 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1361 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1364 mCurrentSyncDevice = "qtopia-XML"; 1362 mCurrentSyncDevice = "qtopia-XML";
1365 if ( KOPrefs::instance()->mAskForPreferences ) 1363 if ( KOPrefs::instance()->mAskForPreferences )
1366 edit_sync_options(); 1364 edit_sync_options();
1367 qApp->processEvents(); 1365 qApp->processEvents();
1368 CalendarLocal* calendar = new CalendarLocal(); 1366 CalendarLocal* calendar = new CalendarLocal();
1369 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1367 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1370 bool syncOK = false; 1368 bool syncOK = false;
1371 QtopiaFormat qtopiaFormat; 1369 QtopiaFormat qtopiaFormat;
1372 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1370 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1373 bool loadOk = true; 1371 bool loadOk = true;
1374 if ( !categories.isEmpty() ) 1372 if ( !categories.isEmpty() )
1375 loadOk = qtopiaFormat.load( calendar, categories ); 1373 loadOk = qtopiaFormat.load( calendar, categories );
1376 if ( loadOk && !datebook.isEmpty() ) 1374 if ( loadOk && !datebook.isEmpty() )
1377 loadOk = qtopiaFormat.load( calendar, datebook ); 1375 loadOk = qtopiaFormat.load( calendar, datebook );
1378 if ( loadOk && !todolist.isEmpty() ) 1376 if ( loadOk && !todolist.isEmpty() )
1379 loadOk = qtopiaFormat.load( calendar, todolist ); 1377 loadOk = qtopiaFormat.load( calendar, todolist );
1380 1378
1381 if ( loadOk ) { 1379 if ( loadOk ) {
1382 getEventViewerDialog()->setSyncMode( true ); 1380 getEventViewerDialog()->setSyncMode( true );
1383 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1381 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1384 getEventViewerDialog()->setSyncMode( false ); 1382 getEventViewerDialog()->setSyncMode( false );
1385 qApp->processEvents(); 1383 qApp->processEvents();
1386 if ( syncOK ) { 1384 if ( syncOK ) {
1387 if ( KOPrefs::instance()->mWriteBackFile ) 1385 if ( KOPrefs::instance()->mWriteBackFile )
1388 { 1386 {
1389 // write back XML file 1387 // write back XML file
1390 1388
1391 } 1389 }
1392 setModified( true ); 1390 setModified( true );
1393 } 1391 }
1394 } else { 1392 } else {
1395 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1393 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1396 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1394 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1397 question, i18n("Ok")) ; 1395 question, i18n("Ok")) ;
1398 } 1396 }
1399 delete calendar; 1397 delete calendar;
1400 updateView(); 1398 updateView();
1401 return syncOK; 1399 return syncOK;
1402 1400
1403 1401
1404#endif 1402#endif
1405 1403
1406} 1404}
1407 1405
1408void CalendarView::setSyncEventsReadOnly() 1406void CalendarView::setSyncEventsReadOnly()
1409{ 1407{
1410 Event * ev; 1408 Event * ev;
1411 QPtrList<Event> eL = mCalendar->rawEvents(); 1409 QPtrList<Event> eL = mCalendar->rawEvents();
1412 ev = eL.first(); 1410 ev = eL.first();
1413 while ( ev ) { 1411 while ( ev ) {
1414 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1412 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1415 ev->setReadOnly( true ); 1413 ev->setReadOnly( true );
1416 ev = eL.next(); 1414 ev = eL.next();
1417 } 1415 }
1418} 1416}
1419bool CalendarView::openCalendar(QString filename, bool merge) 1417bool CalendarView::openCalendar(QString filename, bool merge)
1420{ 1418{
1421 1419
1422 if (filename.isEmpty()) { 1420 if (filename.isEmpty()) {
1423 return false; 1421 return false;
1424 } 1422 }
1425 1423
1426 if (!QFile::exists(filename)) { 1424 if (!QFile::exists(filename)) {
1427 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1425 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1428 return false; 1426 return false;
1429 } 1427 }
1430 1428
1431 globalFlagBlockAgenda = 1; 1429 globalFlagBlockAgenda = 1;
1432 if (!merge) mCalendar->close(); 1430 if (!merge) mCalendar->close();
1433 1431
1434 mStorage->setFileName( filename ); 1432 mStorage->setFileName( filename );
1435 1433
1436 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { 1434 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) {
1437 if ( merge ) ;//setModified( true ); 1435 if ( merge ) ;//setModified( true );
1438 else { 1436 else {
1439 //setModified( true ); 1437 //setModified( true );
1440 mViewManager->setDocumentId( filename ); 1438 mViewManager->setDocumentId( filename );
1441 mDialogManager->setDocumentId( filename ); 1439 mDialogManager->setDocumentId( filename );
1442 mTodoList->setDocumentId( filename ); 1440 mTodoList->setDocumentId( filename );
1443 } 1441 }
1444 globalFlagBlockAgenda = 2; 1442 globalFlagBlockAgenda = 2;
1445 // if ( getLastSyncEvent() ) 1443 // if ( getLastSyncEvent() )
1446 // getLastSyncEvent()->setReadOnly( true ); 1444 // getLastSyncEvent()->setReadOnly( true );
1447 mCalendar->reInitAlarmSettings(); 1445 mCalendar->reInitAlarmSettings();
1448 setSyncEventsReadOnly(); 1446 setSyncEventsReadOnly();
1449 updateUnmanagedViews(); 1447 updateUnmanagedViews();
1450 updateView(); 1448 updateView();
1451 if ( filename != MainWindow::defaultFileName() ) 1449 if ( filename != MainWindow::defaultFileName() )
1452 saveCalendar( MainWindow::defaultFileName() ); 1450 saveCalendar( MainWindow::defaultFileName() );
1453 loadedFileVersion = QDateTime::currentDateTime(); 1451 loadedFileVersion = QDateTime::currentDateTime();
1454 return true; 1452 return true;
1455 } else { 1453 } else {
1456 // while failing to load, the calendar object could 1454 // while failing to load, the calendar object could
1457 // have become partially populated. Clear it out. 1455 // have become partially populated. Clear it out.
1458 if ( !merge ) mCalendar->close(); 1456 if ( !merge ) mCalendar->close();
1459 1457
1460 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1458 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1461 1459
1462 globalFlagBlockAgenda = 2; 1460 globalFlagBlockAgenda = 2;
1463 updateView(); 1461 updateView();
1464 } 1462 }
1465 return false; 1463 return false;
1466} 1464}
1467void CalendarView::setLoadedFileVersion(QDateTime dt) 1465void CalendarView::setLoadedFileVersion(QDateTime dt)
1468{ 1466{
1469 loadedFileVersion = dt; 1467 loadedFileVersion = dt;
1470} 1468}
1471bool CalendarView::checkFileChanged(QString fn) 1469bool CalendarView::checkFileChanged(QString fn)
1472{ 1470{
1473 QFileInfo finf ( fn ); 1471 QFileInfo finf ( fn );
1474 if ( !finf.exists() ) 1472 if ( !finf.exists() )
1475 return true; 1473 return true;
1476 QDateTime dt = finf.lastModified (); 1474 QDateTime dt = finf.lastModified ();
1477 if ( dt <= loadedFileVersion ) 1475 if ( dt <= loadedFileVersion )
1478 return false; 1476 return false;
1479 return true; 1477 return true;
1480 1478
1481} 1479}
1482bool CalendarView::checkFileVersion(QString fn) 1480bool CalendarView::checkFileVersion(QString fn)
1483{ 1481{
1484 QFileInfo finf ( fn ); 1482 QFileInfo finf ( fn );
1485 if ( !finf.exists() ) 1483 if ( !finf.exists() )
1486 return true; 1484 return true;
1487 QDateTime dt = finf.lastModified (); 1485 QDateTime dt = finf.lastModified ();
1488 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1486 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1489 //qDebug("file on disk version %s",dt.toString().latin1()); 1487 //qDebug("file on disk version %s",dt.toString().latin1());
1490 if ( dt <= loadedFileVersion ) 1488 if ( dt <= loadedFileVersion )
1491 return true; 1489 return true;
1492 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)) , 1490 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)) ,
1493 i18n("KO/Pi Warning"),i18n("Overwrite"), 1491 i18n("KO/Pi Warning"),i18n("Overwrite"),
1494 i18n("Sync+save")); 1492 i18n("Sync+save"));
1495 1493
1496 if ( km == KMessageBox::Cancel ) 1494 if ( km == KMessageBox::Cancel )
1497 return false; 1495 return false;
1498 if ( km == KMessageBox::Yes ) 1496 if ( km == KMessageBox::Yes )
1499 return true; 1497 return true;
1500 1498
1501 setSyncDevice("deleteaftersync" ); 1499 setSyncDevice("deleteaftersync" );
1502 KOPrefs::instance()->mAskForPreferences = true; 1500 KOPrefs::instance()->mAskForPreferences = true;
1503 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1501 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1504 KOPrefs::instance()->mWriteBackFile = false; 1502 KOPrefs::instance()->mWriteBackFile = false;
1505 KOPrefs::instance()->mWriteBackExistingOnly = false; 1503 KOPrefs::instance()->mWriteBackExistingOnly = false;
1506 KOPrefs::instance()->mShowSyncSummary = false; 1504 KOPrefs::instance()->mShowSyncSummary = false;
1507 syncCalendar( fn, 3 ); 1505 syncCalendar( fn, 3 );
1508 Event * e = getLastSyncEvent(); 1506 Event * e = getLastSyncEvent();
1509 mCalendar->deleteEvent ( e ); 1507 mCalendar->deleteEvent ( e );
1510 updateView(); 1508 updateView();
1511 return true; 1509 return true;
1512} 1510}
1513 1511
1514bool CalendarView::saveCalendar( QString filename ) 1512bool CalendarView::saveCalendar( QString filename )
1515{ 1513{
1516 1514
1517 // Store back all unsaved data into calendar object 1515 // Store back all unsaved data into calendar object
1518 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1516 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1519 if ( mViewManager->currentView() ) 1517 if ( mViewManager->currentView() )
1520 mViewManager->currentView()->flushView(); 1518 mViewManager->currentView()->flushView();
1521 1519
1522 //mStorage->setFileName( filename ); 1520 //mStorage->setFileName( filename );
1523 1521
1524 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1522 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1525 mStorage->setFileName( filename ); 1523 mStorage->setFileName( filename );
1526 bool success; 1524 bool success;
1527 success = mStorage->save(); 1525 success = mStorage->save();
1528 if ( !success ) { 1526 if ( !success ) {
1529 return false; 1527 return false;
1530 } 1528 }
1531 1529
1532 return true; 1530 return true;
1533} 1531}
1534 1532
1535void CalendarView::closeCalendar() 1533void CalendarView::closeCalendar()
1536{ 1534{
1537 1535
1538 // child windows no longer valid 1536 // child windows no longer valid
1539 emit closingDown(); 1537 emit closingDown();
1540 1538
1541 mCalendar->close(); 1539 mCalendar->close();
1542 setModified(false); 1540 setModified(false);
1543 updateView(); 1541 updateView();
1544} 1542}
1545 1543
1546void CalendarView::archiveCalendar() 1544void CalendarView::archiveCalendar()
1547{ 1545{
1548 mDialogManager->showArchiveDialog(); 1546 mDialogManager->showArchiveDialog();
1549} 1547}
1550 1548
1551 1549
1552void CalendarView::readSettings() 1550void CalendarView::readSettings()
1553{ 1551{
1554 1552
1555 1553
1556 // mViewManager->showAgendaView(); 1554 // mViewManager->showAgendaView();
1557 QString str; 1555 QString str;
1558 //qDebug("CalendarView::readSettings() "); 1556 //qDebug("CalendarView::readSettings() ");
1559 // read settings from the KConfig, supplying reasonable 1557 // read settings from the KConfig, supplying reasonable
1560 // defaults where none are to be found 1558 // defaults where none are to be found
1561 KConfig *config = KOGlobals::config(); 1559 KConfig *config = KOGlobals::config();
1562#ifndef KORG_NOSPLITTER 1560#ifndef KORG_NOSPLITTER
1563 config->setGroup("KOrganizer Geometry"); 1561 config->setGroup("KOrganizer Geometry");
1564 1562
1565 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1563 QValueList<int> sizes = config->readIntListEntry("Separator1");
1566 if (sizes.count() != 2) { 1564 if (sizes.count() != 2) {
1567 sizes << mDateNavigator->minimumSizeHint().width(); 1565 sizes << mDateNavigator->minimumSizeHint().width();
1568 sizes << 300; 1566 sizes << 300;
1569 } 1567 }
1570 mPanner->setSizes(sizes); 1568 mPanner->setSizes(sizes);
1571 1569
1572 sizes = config->readIntListEntry("Separator2"); 1570 sizes = config->readIntListEntry("Separator2");
1573 if ( ( mResourceView && sizes.count() == 4 ) || 1571 if ( ( mResourceView && sizes.count() == 4 ) ||
1574 ( !mResourceView && sizes.count() == 3 ) ) { 1572 ( !mResourceView && sizes.count() == 3 ) ) {
1575 mLeftSplitter->setSizes(sizes); 1573 mLeftSplitter->setSizes(sizes);
1576 } 1574 }
1577#endif 1575#endif
1578 globalFlagBlockAgenda = 1; 1576 globalFlagBlockAgenda = 1;
1579 mViewManager->showAgendaView(); 1577 mViewManager->showAgendaView();
1580 //mViewManager->readSettings( config ); 1578 //mViewManager->readSettings( config );
1581 mTodoList->restoreLayout(config,QString("Todo Layout")); 1579 mTodoList->restoreLayout(config,QString("Todo Layout"));
1582 readFilterSettings(config); 1580 readFilterSettings(config);
1583 config->setGroup( "Views" ); 1581 config->setGroup( "Views" );
1584 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1582 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1585 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1583 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1586 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1584 else if ( dateCount == 7 ) mNavigator->selectWeek();
1587 else mNavigator->selectDates( dateCount ); 1585 else mNavigator->selectDates( dateCount );
1588 // mViewManager->readSettings( config ); 1586 // mViewManager->readSettings( config );
1589 updateConfig(); 1587 updateConfig();
1590 globalFlagBlockAgenda = 2; 1588 globalFlagBlockAgenda = 2;
1591 mViewManager->readSettings( config ); 1589 mViewManager->readSettings( config );
1592#ifdef DESKTOP_VERSION 1590#ifdef DESKTOP_VERSION
1593 config->setGroup("WidgetLayout"); 1591 config->setGroup("WidgetLayout");
1594 QStringList list; 1592 QStringList list;
1595 list = config->readListEntry("MainLayout"); 1593 list = config->readListEntry("MainLayout");
1596 int x,y,w,h; 1594 int x,y,w,h;
1597 if ( ! list.isEmpty() ) { 1595 if ( ! list.isEmpty() ) {
1598 x = list[0].toInt(); 1596 x = list[0].toInt();
1599 y = list[1].toInt(); 1597 y = list[1].toInt();
1600 w = list[2].toInt(); 1598 w = list[2].toInt();
1601 h = list[3].toInt(); 1599 h = list[3].toInt();
1602 topLevelWidget()->setGeometry(x,y,w,h); 1600 topLevelWidget()->setGeometry(x,y,w,h);
1603 1601
1604 } else { 1602 } else {
1605 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1603 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1606 } 1604 }
1607 list = config->readListEntry("EditEventLayout"); 1605 list = config->readListEntry("EditEventLayout");
1608 if ( ! list.isEmpty() ) { 1606 if ( ! list.isEmpty() ) {
1609 x = list[0].toInt(); 1607 x = list[0].toInt();
1610 y = list[1].toInt(); 1608 y = list[1].toInt();
1611 w = list[2].toInt(); 1609 w = list[2].toInt();
1612 h = list[3].toInt(); 1610 h = list[3].toInt();
1613 mEventEditor->setGeometry(x,y,w,h); 1611 mEventEditor->setGeometry(x,y,w,h);
1614 1612
1615 } 1613 }
1616 list = config->readListEntry("EditTodoLayout"); 1614 list = config->readListEntry("EditTodoLayout");
1617 if ( ! list.isEmpty() ) { 1615 if ( ! list.isEmpty() ) {
1618 x = list[0].toInt(); 1616 x = list[0].toInt();
1619 y = list[1].toInt(); 1617 y = list[1].toInt();
1620 w = list[2].toInt(); 1618 w = list[2].toInt();
1621 h = list[3].toInt(); 1619 h = list[3].toInt();
1622 mTodoEditor->setGeometry(x,y,w,h); 1620 mTodoEditor->setGeometry(x,y,w,h);
1623 1621
1624 } 1622 }
1625 list = config->readListEntry("ViewerLayout"); 1623 list = config->readListEntry("ViewerLayout");
1626 if ( ! list.isEmpty() ) { 1624 if ( ! list.isEmpty() ) {
1627 x = list[0].toInt(); 1625 x = list[0].toInt();
1628 y = list[1].toInt(); 1626 y = list[1].toInt();
1629 w = list[2].toInt(); 1627 w = list[2].toInt();
1630 h = list[3].toInt(); 1628 h = list[3].toInt();
1631 getEventViewerDialog()->setGeometry(x,y,w,h); 1629 getEventViewerDialog()->setGeometry(x,y,w,h);
1632 } 1630 }
1633#endif 1631#endif
1634 1632
1635} 1633}
1636 1634
1637 1635
1638void CalendarView::writeSettings() 1636void CalendarView::writeSettings()
1639{ 1637{
1640 // kdDebug() << "CalendarView::writeSettings" << endl; 1638 // kdDebug() << "CalendarView::writeSettings" << endl;
1641 1639
1642 KConfig *config = KOGlobals::config(); 1640 KConfig *config = KOGlobals::config();
1643 1641
1644#ifndef KORG_NOSPLITTER 1642#ifndef KORG_NOSPLITTER
1645 config->setGroup("KOrganizer Geometry"); 1643 config->setGroup("KOrganizer Geometry");
1646 1644
1647 QValueList<int> list = mPanner->sizes(); 1645 QValueList<int> list = mPanner->sizes();
1648 config->writeEntry("Separator1",list); 1646 config->writeEntry("Separator1",list);
1649 1647
1650 list = mLeftSplitter->sizes(); 1648 list = mLeftSplitter->sizes();
1651 config->writeEntry("Separator2",list); 1649 config->writeEntry("Separator2",list);
1652#endif 1650#endif
1653 1651
1654 mViewManager->writeSettings( config ); 1652 mViewManager->writeSettings( config );
1655 mTodoList->saveLayout(config,QString("Todo Layout")); 1653 mTodoList->saveLayout(config,QString("Todo Layout"));
1656 mDialogManager->writeSettings( config ); 1654 mDialogManager->writeSettings( config );
1657 //KOPrefs::instance()->usrWriteConfig(); 1655 //KOPrefs::instance()->usrWriteConfig();
1658 KOPrefs::instance()->writeConfig(); 1656 KOPrefs::instance()->writeConfig();
1659 1657
1660 writeFilterSettings(config); 1658 writeFilterSettings(config);
1661 1659
1662 config->setGroup( "Views" ); 1660 config->setGroup( "Views" );
1663 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1661 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1664 1662
1665#ifdef DESKTOP_VERSION 1663#ifdef DESKTOP_VERSION
1666 config->setGroup("WidgetLayout"); 1664 config->setGroup("WidgetLayout");
1667 QStringList list ;//= config->readListEntry("MainLayout"); 1665 QStringList list ;//= config->readListEntry("MainLayout");
1668 int x,y,w,h; 1666 int x,y,w,h;
1669 QWidget* wid; 1667 QWidget* wid;
1670 wid = topLevelWidget(); 1668 wid = topLevelWidget();
1671 x = wid->geometry().x(); 1669 x = wid->geometry().x();
1672 y = wid->geometry().y(); 1670 y = wid->geometry().y();
1673 w = wid->width(); 1671 w = wid->width();
1674 h = wid->height(); 1672 h = wid->height();
1675 list.clear(); 1673 list.clear();
1676 list << QString::number( x ); 1674 list << QString::number( x );
1677 list << QString::number( y ); 1675 list << QString::number( y );
1678 list << QString::number( w ); 1676 list << QString::number( w );
1679 list << QString::number( h ); 1677 list << QString::number( h );
1680 config->writeEntry("MainLayout",list ); 1678 config->writeEntry("MainLayout",list );
1681 1679
1682 wid = mEventEditor; 1680 wid = mEventEditor;
1683 x = wid->geometry().x(); 1681 x = wid->geometry().x();
1684 y = wid->geometry().y(); 1682 y = wid->geometry().y();
1685 w = wid->width(); 1683 w = wid->width();
1686 h = wid->height(); 1684 h = wid->height();
1687 list.clear(); 1685 list.clear();
1688 list << QString::number( x ); 1686 list << QString::number( x );
1689 list << QString::number( y ); 1687 list << QString::number( y );
1690 list << QString::number( w ); 1688 list << QString::number( w );
1691 list << QString::number( h ); 1689 list << QString::number( h );
1692 config->writeEntry("EditEventLayout",list ); 1690 config->writeEntry("EditEventLayout",list );
1693 1691
1694 wid = mTodoEditor; 1692 wid = mTodoEditor;
1695 x = wid->geometry().x(); 1693 x = wid->geometry().x();
1696 y = wid->geometry().y(); 1694 y = wid->geometry().y();
1697 w = wid->width(); 1695 w = wid->width();
1698 h = wid->height(); 1696 h = wid->height();
1699 list.clear(); 1697 list.clear();
1700 list << QString::number( x ); 1698 list << QString::number( x );
1701 list << QString::number( y ); 1699 list << QString::number( y );
1702 list << QString::number( w ); 1700 list << QString::number( w );
1703 list << QString::number( h ); 1701 list << QString::number( h );
1704 config->writeEntry("EditTodoLayout",list ); 1702 config->writeEntry("EditTodoLayout",list );
1705 wid = getEventViewerDialog(); 1703 wid = getEventViewerDialog();
1706 x = wid->geometry().x(); 1704 x = wid->geometry().x();
1707 y = wid->geometry().y(); 1705 y = wid->geometry().y();
1708 w = wid->width(); 1706 w = wid->width();
1709 h = wid->height(); 1707 h = wid->height();
1710 list.clear(); 1708 list.clear();
1711 list << QString::number( x ); 1709 list << QString::number( x );
1712 list << QString::number( y ); 1710 list << QString::number( y );
1713 list << QString::number( w ); 1711 list << QString::number( w );
1714 list << QString::number( h ); 1712 list << QString::number( h );
1715 config->writeEntry("ViewerLayout",list ); 1713 config->writeEntry("ViewerLayout",list );
1716 wid = mDialogManager->getSearchDialog(); 1714 wid = mDialogManager->getSearchDialog();
1717 if ( wid ) { 1715 if ( wid ) {
1718 x = wid->geometry().x(); 1716 x = wid->geometry().x();
1719 y = wid->geometry().y(); 1717 y = wid->geometry().y();
1720 w = wid->width(); 1718 w = wid->width();
1721 h = wid->height(); 1719 h = wid->height();
1722 list.clear(); 1720 list.clear();
1723 list << QString::number( x ); 1721 list << QString::number( x );
1724 list << QString::number( y ); 1722 list << QString::number( y );
1725 list << QString::number( w ); 1723 list << QString::number( w );
1726 list << QString::number( h ); 1724 list << QString::number( h );
1727 config->writeEntry("SearchLayout",list ); 1725 config->writeEntry("SearchLayout",list );
1728 } 1726 }
1729#endif 1727#endif
1730 1728
1731 1729
1732 config->sync(); 1730 config->sync();
1733} 1731}
1734 1732
1735void CalendarView::readFilterSettings(KConfig *config) 1733void CalendarView::readFilterSettings(KConfig *config)
1736{ 1734{
1737 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1735 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1738 1736
1739 mFilters.clear(); 1737 mFilters.clear();
1740 1738
1741 config->setGroup("General"); 1739 config->setGroup("General");
1742 QStringList filterList = config->readListEntry("CalendarFilters"); 1740 QStringList filterList = config->readListEntry("CalendarFilters");
1743 1741
1744 QStringList::ConstIterator it = filterList.begin(); 1742 QStringList::ConstIterator it = filterList.begin();
1745 QStringList::ConstIterator end = filterList.end(); 1743 QStringList::ConstIterator end = filterList.end();
1746 while(it != end) { 1744 while(it != end) {
1747 // kdDebug() << " filter: " << (*it) << endl; 1745 // kdDebug() << " filter: " << (*it) << endl;
1748 1746
1749 CalFilter *filter; 1747 CalFilter *filter;
1750 filter = new CalFilter(*it); 1748 filter = new CalFilter(*it);
1751 config->setGroup("Filter_" + (*it)); 1749 config->setGroup("Filter_" + (*it));
1752 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1750 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1753 filter->setCriteria(config->readNumEntry("Criteria",0)); 1751 filter->setCriteria(config->readNumEntry("Criteria",0));
1754 filter->setCategoryList(config->readListEntry("CategoryList")); 1752 filter->setCategoryList(config->readListEntry("CategoryList"));
1755 mFilters.append(filter); 1753 mFilters.append(filter);
1756 1754
1757 ++it; 1755 ++it;
1758 } 1756 }
1759 1757
1760 if (mFilters.count() == 0) { 1758 if (mFilters.count() == 0) {
1761 CalFilter *filter = new CalFilter(i18n("Default")); 1759 CalFilter *filter = new CalFilter(i18n("Default"));
1762 mFilters.append(filter); 1760 mFilters.append(filter);
1763 } 1761 }
1764 mFilterView->updateFilters(); 1762 mFilterView->updateFilters();
1765 config->setGroup("FilterView"); 1763 config->setGroup("FilterView");
1766 1764
1767 mFilterView->blockSignals(true); 1765 mFilterView->blockSignals(true);
1768 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1766 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1769 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1767 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1770 mFilterView->blockSignals(false); 1768 mFilterView->blockSignals(false);
1771 // We do it manually to avoid it being done twice by the above calls 1769 // We do it manually to avoid it being done twice by the above calls
1772 updateFilter(); 1770 updateFilter();
1773} 1771}
1774 1772
1775void CalendarView::writeFilterSettings(KConfig *config) 1773void CalendarView::writeFilterSettings(KConfig *config)
1776{ 1774{
1777 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1775 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1778 1776
1779 QStringList filterList; 1777 QStringList filterList;
1780 1778
1781 CalFilter *filter = mFilters.first(); 1779 CalFilter *filter = mFilters.first();
1782 while(filter) { 1780 while(filter) {
1783 // kdDebug() << " fn: " << filter->name() << endl; 1781 // kdDebug() << " fn: " << filter->name() << endl;
1784 filterList << filter->name(); 1782 filterList << filter->name();
1785 config->setGroup("Filter_" + filter->name()); 1783 config->setGroup("Filter_" + filter->name());
1786 config->writeEntry("Criteria",filter->criteria()); 1784 config->writeEntry("Criteria",filter->criteria());
1787 config->writeEntry("CategoryList",filter->categoryList()); 1785 config->writeEntry("CategoryList",filter->categoryList());
1788 filter = mFilters.next(); 1786 filter = mFilters.next();
1789 } 1787 }
1790 config->setGroup("General"); 1788 config->setGroup("General");
1791 config->writeEntry("CalendarFilters",filterList); 1789 config->writeEntry("CalendarFilters",filterList);
1792 1790
1793 config->setGroup("FilterView"); 1791 config->setGroup("FilterView");
1794 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1792 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1795 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1793 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1796} 1794}
1797 1795
1798 1796
1799void CalendarView::goToday() 1797void CalendarView::goToday()
1800{ 1798{
1801 mNavigator->selectToday(); 1799 mNavigator->selectToday();
1802} 1800}
1803 1801
1804void CalendarView::goNext() 1802void CalendarView::goNext()
1805{ 1803{
1806 mNavigator->selectNext(); 1804 mNavigator->selectNext();
1807} 1805}
1808 1806
1809void CalendarView::goPrevious() 1807void CalendarView::goPrevious()
1810{ 1808{
1811 mNavigator->selectPrevious(); 1809 mNavigator->selectPrevious();
1812} 1810}
1813void CalendarView::goNextMonth() 1811void CalendarView::goNextMonth()
1814{ 1812{
1815 mNavigator->selectNextMonth(); 1813 mNavigator->selectNextMonth();
1816} 1814}
1817 1815
1818void CalendarView::goPreviousMonth() 1816void CalendarView::goPreviousMonth()
1819{ 1817{
1820 mNavigator->selectPreviousMonth(); 1818 mNavigator->selectPreviousMonth();
1821} 1819}
1822void CalendarView::writeLocale() 1820void CalendarView::writeLocale()
1823{ 1821{
1824 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1822 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1825 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1823 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1826 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1824 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1827 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1825 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1828 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1826 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1829 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1827 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1830 dummy = KOPrefs::instance()->mUserDateFormatShort; 1828 dummy = KOPrefs::instance()->mUserDateFormatShort;
1831 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1829 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1832 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1830 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1833 KOPrefs::instance()->mDaylightsavingStart, 1831 KOPrefs::instance()->mDaylightsavingStart,
1834 KOPrefs::instance()->mDaylightsavingEnd ); 1832 KOPrefs::instance()->mDaylightsavingEnd );
1835 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1833 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1836} 1834}
1837void CalendarView::updateConfig() 1835void CalendarView::updateConfig()
1838{ 1836{
1839 writeLocale(); 1837 writeLocale();
1840 if ( KOPrefs::instance()->mUseAppColors ) 1838 if ( KOPrefs::instance()->mUseAppColors )
1841 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1839 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1842 emit configChanged(); 1840 emit configChanged();
1843 mTodoList->updateConfig(); 1841 mTodoList->updateConfig();
1844 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1842 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1845 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1843 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1846 // To make the "fill window" configurations work 1844 // To make the "fill window" configurations work
1847 //mViewManager->raiseCurrentView(); 1845 //mViewManager->raiseCurrentView();
1848} 1846}
1849 1847
1850 1848
1851void CalendarView::eventChanged(Event *event) 1849void CalendarView::eventChanged(Event *event)
1852{ 1850{
1853 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1851 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1854 //updateUnmanagedViews(); 1852 //updateUnmanagedViews();
1855} 1853}
1856 1854
1857void CalendarView::eventAdded(Event *event) 1855void CalendarView::eventAdded(Event *event)
1858{ 1856{
1859 changeEventDisplay(event,KOGlobals::EVENTADDED); 1857 changeEventDisplay(event,KOGlobals::EVENTADDED);
1860} 1858}
1861 1859
1862void CalendarView::eventToBeDeleted(Event *) 1860void CalendarView::eventToBeDeleted(Event *)
1863{ 1861{
1864 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 1862 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
1865} 1863}
1866 1864
1867void CalendarView::eventDeleted() 1865void CalendarView::eventDeleted()
1868{ 1866{
1869 changeEventDisplay(0,KOGlobals::EVENTDELETED); 1867 changeEventDisplay(0,KOGlobals::EVENTDELETED);
1870} 1868}
1871void CalendarView::changeTodoDisplay(Todo *which, int action) 1869void CalendarView::changeTodoDisplay(Todo *which, int action)
1872{ 1870{
1873 changeIncidenceDisplay((Incidence *)which, action); 1871 changeIncidenceDisplay((Incidence *)which, action);
1874} 1872}
1875 1873
1876void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 1874void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
1877{ 1875{
1878 updateUnmanagedViews(); 1876 updateUnmanagedViews();
1879 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 1877 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
1880 if ( action == KOGlobals::EVENTDELETED ) { //delete 1878 if ( action == KOGlobals::EVENTDELETED ) { //delete
1881 mCalendar->checkAlarmForIncidence( 0, true ); 1879 mCalendar->checkAlarmForIncidence( 0, true );
1882 if ( mEventViewerDialog ) 1880 if ( mEventViewerDialog )
1883 mEventViewerDialog->hide(); 1881 mEventViewerDialog->hide();
1884 } 1882 }
1885 else 1883 else
1886 mCalendar->checkAlarmForIncidence( which , false ); 1884 mCalendar->checkAlarmForIncidence( which , false );
1887} 1885}
1888 1886
1889// most of the changeEventDisplays() right now just call the view's 1887// most of the changeEventDisplays() right now just call the view's
1890// total update mode, but they SHOULD be recoded to be more refresh-efficient. 1888// total update mode, but they SHOULD be recoded to be more refresh-efficient.
1891void CalendarView::changeEventDisplay(Event *which, int action) 1889void CalendarView::changeEventDisplay(Event *which, int action)
1892{ 1890{
1893 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 1891 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
1894 changeIncidenceDisplay((Incidence *)which, action); 1892 changeIncidenceDisplay((Incidence *)which, action);
1895 mDateNavigator->updateView(); 1893 mDateNavigator->updateView();
1896 //mDialogManager->updateSearchDialog(); 1894 //mDialogManager->updateSearchDialog();
1897 1895
1898 if (which) { 1896 if (which) {
1899 // If there is an event view visible update the display 1897 // If there is an event view visible update the display
1900 mViewManager->currentView()->changeEventDisplay(which,action); 1898 mViewManager->currentView()->changeEventDisplay(which,action);
1901 // TODO: check, if update needed 1899 // TODO: check, if update needed
1902 // if (which->getTodoStatus()) { 1900 // if (which->getTodoStatus()) {
1903 mTodoList->updateView(); 1901 mTodoList->updateView();
1904 // } 1902 // }
1905 } else { 1903 } else {
1906 mViewManager->currentView()->updateView(); 1904 mViewManager->currentView()->updateView();
1907 } 1905 }
1908} 1906}
1909 1907
1910 1908
1911void CalendarView::updateTodoViews() 1909void CalendarView::updateTodoViews()
1912{ 1910{
1913 1911
1914 mTodoList->updateView(); 1912 mTodoList->updateView();
1915 mViewManager->currentView()->updateView(); 1913 mViewManager->currentView()->updateView();
1916 1914
1917} 1915}
1918 1916
1919 1917
1920void CalendarView::updateView(const QDate &start, const QDate &end) 1918void CalendarView::updateView(const QDate &start, const QDate &end)
1921{ 1919{
1922 mTodoList->updateView(); 1920 mTodoList->updateView();
1923 mViewManager->updateView(start, end); 1921 mViewManager->updateView(start, end);
1924 //mDateNavigator->updateView(); 1922 //mDateNavigator->updateView();
1925} 1923}
1926 1924
1927void CalendarView::updateView() 1925void CalendarView::updateView()
1928{ 1926{
1929 DateList tmpList = mNavigator->selectedDates(); 1927 DateList tmpList = mNavigator->selectedDates();
1930 1928
1931 // We assume that the navigator only selects consecutive days. 1929 // We assume that the navigator only selects consecutive days.
1932 updateView( tmpList.first(), tmpList.last() ); 1930 updateView( tmpList.first(), tmpList.last() );
1933} 1931}
1934 1932
1935void CalendarView::updateUnmanagedViews() 1933void CalendarView::updateUnmanagedViews()
1936{ 1934{
1937 mDateNavigator->updateDayMatrix(); 1935 mDateNavigator->updateDayMatrix();
1938} 1936}
1939 1937
1940int CalendarView::msgItemDelete() 1938int CalendarView::msgItemDelete()
1941{ 1939{
1942 return KMessageBox::warningContinueCancel(this, 1940 return KMessageBox::warningContinueCancel(this,
1943 i18n("This item will be\npermanently deleted."), 1941 i18n("This item will be\npermanently deleted."),
1944 i18n("KO/Pi Confirmation"),i18n("Delete")); 1942 i18n("KO/Pi Confirmation"),i18n("Delete"));
1945} 1943}
1946 1944
1947 1945
1948void CalendarView::edit_cut() 1946void CalendarView::edit_cut()
1949{ 1947{
1950 Event *anEvent=0; 1948 Event *anEvent=0;
1951 1949
1952 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1950 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1953 1951
1954 if (mViewManager->currentView()->isEventView()) { 1952 if (mViewManager->currentView()->isEventView()) {
1955 if ( incidence && incidence->type() == "Event" ) { 1953 if ( incidence && incidence->type() == "Event" ) {
1956 anEvent = static_cast<Event *>(incidence); 1954 anEvent = static_cast<Event *>(incidence);
1957 } 1955 }
1958 } 1956 }
1959 1957
1960 if (!anEvent) { 1958 if (!anEvent) {
1961 KNotifyClient::beep(); 1959 KNotifyClient::beep();
1962 return; 1960 return;
1963 } 1961 }
1964 DndFactory factory( mCalendar ); 1962 DndFactory factory( mCalendar );
1965 factory.cutEvent(anEvent); 1963 factory.cutEvent(anEvent);
1966 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 1964 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
1967} 1965}
1968 1966
1969void CalendarView::edit_copy() 1967void CalendarView::edit_copy()
1970{ 1968{
1971 Event *anEvent=0; 1969 Event *anEvent=0;
1972 1970
1973 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1971 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1974 1972
1975 if (mViewManager->currentView()->isEventView()) { 1973 if (mViewManager->currentView()->isEventView()) {
1976 if ( incidence && incidence->type() == "Event" ) { 1974 if ( incidence && incidence->type() == "Event" ) {
1977 anEvent = static_cast<Event *>(incidence); 1975 anEvent = static_cast<Event *>(incidence);
1978 } 1976 }
1979 } 1977 }
1980 1978
1981 if (!anEvent) { 1979 if (!anEvent) {
1982 KNotifyClient::beep(); 1980 KNotifyClient::beep();
1983 return; 1981 return;
1984 } 1982 }
1985 DndFactory factory( mCalendar ); 1983 DndFactory factory( mCalendar );
1986 factory.copyEvent(anEvent); 1984 factory.copyEvent(anEvent);
1987} 1985}
1988 1986
1989void CalendarView::edit_paste() 1987void CalendarView::edit_paste()
1990{ 1988{
1991 QDate date = mNavigator->selectedDates().first(); 1989 QDate date = mNavigator->selectedDates().first();
1992 1990
1993 DndFactory factory( mCalendar ); 1991 DndFactory factory( mCalendar );
1994 Event *pastedEvent = factory.pasteEvent( date ); 1992 Event *pastedEvent = factory.pasteEvent( date );
1995 1993
1996 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 1994 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
1997} 1995}
1998 1996
1999void CalendarView::edit_options() 1997void CalendarView::edit_options()
2000{ 1998{
2001 mDialogManager->showOptionsDialog(); 1999 mDialogManager->showOptionsDialog();
2002 //writeSettings(); 2000 //writeSettings();
2003} 2001}
2004void CalendarView::edit_sync_options() 2002void CalendarView::edit_sync_options()
2005{ 2003{
2006 //mDialogManager->showSyncOptions(); 2004 //mDialogManager->showSyncOptions();
2007 //KOPrefs::instance()->mSyncAlgoPrefs 2005 //KOPrefs::instance()->mSyncAlgoPrefs
2008 QDialog dia( this, "dia", true ); 2006 QDialog dia( this, "dia", true );
2009 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2007 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2010 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2008 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2011 QVBoxLayout lay ( &dia ); 2009 QVBoxLayout lay ( &dia );
2012 lay.setSpacing( 2 ); 2010 lay.setSpacing( 2 );
2013 lay.setMargin( 3 ); 2011 lay.setMargin( 3 );
2014 lay.addWidget(&gr); 2012 lay.addWidget(&gr);
2015 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2013 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2016 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2014 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2017 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2015 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2018 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2016 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2019 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2017 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2020 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2018 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2021 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2019 //QRadioButton both( i18n("Take both on conflict"), &gr );
2022 QPushButton pb ( "OK", &dia); 2020 QPushButton pb ( "OK", &dia);
2023 lay.addWidget( &pb ); 2021 lay.addWidget( &pb );
2024 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2022 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2025 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { 2023 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2026 case 0: 2024 case 0:
2027 loc.setChecked( true); 2025 loc.setChecked( true);
2028 break; 2026 break;
2029 case 1: 2027 case 1:
2030 rem.setChecked( true ); 2028 rem.setChecked( true );
2031 break; 2029 break;
2032 case 2: 2030 case 2:
2033 newest.setChecked( true); 2031 newest.setChecked( true);
2034 break; 2032 break;
2035 case 3: 2033 case 3:
2036 ask.setChecked( true); 2034 ask.setChecked( true);
2037 break; 2035 break;
2038 case 4: 2036 case 4:
2039 f_loc.setChecked( true); 2037 f_loc.setChecked( true);
2040 break; 2038 break;
2041 case 5: 2039 case 5:
2042 f_rem.setChecked( true); 2040 f_rem.setChecked( true);
2043 break; 2041 break;
2044 case 6: 2042 case 6:
2045 // both.setChecked( true); 2043 // both.setChecked( true);
2046 break; 2044 break;
2047 default: 2045 default:
2048 break; 2046 break;
2049 } 2047 }
2050 if ( dia.exec() ) { 2048 if ( dia.exec() ) {
2051 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2049 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2052 } 2050 }
2053 2051
2054} 2052}
2055 2053
2056void CalendarView::slotSelectPickerDate( QDate d) 2054void CalendarView::slotSelectPickerDate( QDate d)
2057{ 2055{
2058 mDateFrame->hide(); 2056 mDateFrame->hide();
2059 if ( mDatePickerMode == 1 ) { 2057 if ( mDatePickerMode == 1 ) {
2060 mNavigator->slotDaySelect( d ); 2058 mNavigator->slotDaySelect( d );
2061 } else if ( mDatePickerMode == 2 ) { 2059 } else if ( mDatePickerMode == 2 ) {
2062 if ( mMoveIncidence->type() == "Todo" ) { 2060 if ( mMoveIncidence->type() == "Todo" ) {
2063 Todo * to = (Todo *) mMoveIncidence; 2061 Todo * to = (Todo *) mMoveIncidence;
2064 QTime tim; 2062 QTime tim;
2065 if ( to->hasDueDate() ) 2063 if ( to->hasDueDate() )
2066 tim = to->dtDue().time(); 2064 tim = to->dtDue().time();
2067 else { 2065 else {
2068 tim = QTime ( 0,0,0 ); 2066 tim = QTime ( 0,0,0 );
2069 to->setFloats( true ); 2067 to->setFloats( true );
2070 to->setHasDueDate( true ); 2068 to->setHasDueDate( true );
2071 } 2069 }
2072 QDateTime dt ( d,tim ); 2070 QDateTime dt ( d,tim );
2073 to->setDtDue( dt ); 2071 to->setDtDue( dt );
2074 todoChanged( to ); 2072 todoChanged( to );
2075 } else { 2073 } else {
2076 QTime tim = mMoveIncidence->dtStart().time(); 2074 QTime tim = mMoveIncidence->dtStart().time();
2077 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2075 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2078 QDateTime dt ( d,tim ); 2076 QDateTime dt ( d,tim );
2079 mMoveIncidence->setDtStart( dt ); 2077 mMoveIncidence->setDtStart( dt );
2080 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2078 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2081 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2079 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2082 } 2080 }
2083 2081
2084 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2082 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2085 } 2083 }
2086} 2084}
2087 2085
2088void CalendarView::removeCategories() 2086void CalendarView::removeCategories()
2089{ 2087{
2090 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2088 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2091 QStringList catList = KOPrefs::instance()->mCustomCategories; 2089 QStringList catList = KOPrefs::instance()->mCustomCategories;
2092 QStringList catIncList; 2090 QStringList catIncList;
2093 QStringList newCatList; 2091 QStringList newCatList;
2094 Incidence* inc = incList.first(); 2092 Incidence* inc = incList.first();
2095 int i; 2093 int i;
2096 int count = 0; 2094 int count = 0;
2097 while ( inc ) { 2095 while ( inc ) {
2098 newCatList.clear(); 2096 newCatList.clear();
2099 catIncList = inc->categories() ; 2097 catIncList = inc->categories() ;
2100 for( i = 0; i< catIncList.count(); ++i ) { 2098 for( i = 0; i< catIncList.count(); ++i ) {
2101 if ( catList.contains (catIncList[i])) 2099 if ( catList.contains (catIncList[i]))
2102 newCatList.append( catIncList[i] ); 2100 newCatList.append( catIncList[i] );
2103 } 2101 }
2104 newCatList.sort(); 2102 newCatList.sort();
2105 inc->setCategories( newCatList.join(",") ); 2103 inc->setCategories( newCatList.join(",") );
2106 inc = incList.next(); 2104 inc = incList.next();
2107 } 2105 }
2108} 2106}
2109 2107
2110int CalendarView::addCategories() 2108int CalendarView::addCategories()
2111{ 2109{
2112 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2110 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2113 QStringList catList = KOPrefs::instance()->mCustomCategories; 2111 QStringList catList = KOPrefs::instance()->mCustomCategories;
2114 QStringList catIncList; 2112 QStringList catIncList;
2115 Incidence* inc = incList.first(); 2113 Incidence* inc = incList.first();
2116 int i; 2114 int i;
2117 int count = 0; 2115 int count = 0;
2118 while ( inc ) { 2116 while ( inc ) {
2119 catIncList = inc->categories() ; 2117 catIncList = inc->categories() ;
2120 for( i = 0; i< catIncList.count(); ++i ) { 2118 for( i = 0; i< catIncList.count(); ++i ) {
2121 if ( !catList.contains (catIncList[i])) { 2119 if ( !catList.contains (catIncList[i])) {
2122 catList.append( catIncList[i] ); 2120 catList.append( catIncList[i] );
2123 //qDebug("add cat %s ", catIncList[i].latin1()); 2121 //qDebug("add cat %s ", catIncList[i].latin1());
2124 ++count; 2122 ++count;
2125 } 2123 }
2126 } 2124 }
2127 inc = incList.next(); 2125 inc = incList.next();
2128 } 2126 }
2129 catList.sort(); 2127 catList.sort();
2130 KOPrefs::instance()->mCustomCategories = catList; 2128 KOPrefs::instance()->mCustomCategories = catList;
2131 return count; 2129 return count;
2132} 2130}
2133 2131
2134void CalendarView::manageCategories() 2132void CalendarView::manageCategories()
2135{ 2133{
2136 KOCatPrefs* cp = new KOCatPrefs(); 2134 KOCatPrefs* cp = new KOCatPrefs();
2137 cp->show(); 2135 cp->show();
2138 int w =cp->sizeHint().width() ; 2136 int w =cp->sizeHint().width() ;
2139 int h = cp->sizeHint().height() ; 2137 int h = cp->sizeHint().height() ;
2140 int dw = QApplication::desktop()->width(); 2138 int dw = QApplication::desktop()->width();
2141 int dh = QApplication::desktop()->height(); 2139 int dh = QApplication::desktop()->height();
2142 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2140 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2143 if ( !cp->exec() ) { 2141 if ( !cp->exec() ) {
2144 delete cp; 2142 delete cp;
2145 return; 2143 return;
2146 } 2144 }
2147 int count = 0; 2145 int count = 0;
2148 if ( cp->addCat() ) { 2146 if ( cp->addCat() ) {
2149 count = addCategories(); 2147 count = addCategories();
2150 if ( count ) { 2148 if ( count ) {
2151 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2149 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2152 writeSettings(); 2150 writeSettings();
2153 } 2151 }
2154 } else { 2152 } else {
2155 removeCategories(); 2153 removeCategories();
2156 updateView(); 2154 updateView();
2157 } 2155 }
2158 delete cp; 2156 delete cp;
2159} 2157}
2160 2158
2161void CalendarView::beamIncidence(Incidence * Inc) 2159void CalendarView::beamIncidence(Incidence * Inc)
2162{ 2160{
2163 QPtrList<Incidence> delSel ; 2161 QPtrList<Incidence> delSel ;
2164 delSel.append(Inc); 2162 delSel.append(Inc);
2165 beamIncidenceList( delSel ); 2163 beamIncidenceList( delSel );
2166} 2164}
2167void CalendarView::beamCalendar() 2165void CalendarView::beamCalendar()
2168{ 2166{
2169 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2167 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2170 //qDebug("beamCalendar() "); 2168 //qDebug("beamCalendar() ");
2171 beamIncidenceList( delSel ); 2169 beamIncidenceList( delSel );
2172} 2170}
2173void CalendarView::beamFilteredCalendar() 2171void CalendarView::beamFilteredCalendar()
2174{ 2172{
2175 QPtrList<Incidence> delSel = mCalendar->incidences(); 2173 QPtrList<Incidence> delSel = mCalendar->incidences();
2176 //qDebug("beamFilteredCalendar() "); 2174 //qDebug("beamFilteredCalendar() ");
2177 beamIncidenceList( delSel ); 2175 beamIncidenceList( delSel );
2178} 2176}
2179void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2177void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2180{ 2178{
2181 if ( beamDialog->exec () == QDialog::Rejected ) 2179 if ( beamDialog->exec () == QDialog::Rejected )
2182 return; 2180 return;
2183 2181
2184 QString fn = "/tmp/kopibeamfile"; 2182 QString fn = "/tmp/kopibeamfile";
2185 QString mes; 2183 QString mes;
2186 bool createbup = true; 2184 bool createbup = true;
2187 if ( createbup ) { 2185 if ( createbup ) {
2188 QString description = "\n"; 2186 QString description = "\n";
2189 CalendarLocal* cal = new CalendarLocal(); 2187 CalendarLocal* cal = new CalendarLocal();
2190 if ( beamDialog->beamLocal() ) 2188 if ( beamDialog->beamLocal() )
2191 cal->setLocalTime(); 2189 cal->setLocalTime();
2192 else 2190 else
2193 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2191 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2194 Incidence *incidence = delSel.first(); 2192 Incidence *incidence = delSel.first();
2195 bool addText = false; 2193 bool addText = false;
2196 if ( delSel.count() < 10 ) 2194 if ( delSel.count() < 10 )
2197 addText = true; 2195 addText = true;
2198 else { 2196 else {
2199 description.sprintf(i18n(" %d items?"),delSel.count() ); 2197 description.sprintf(i18n(" %d items?"),delSel.count() );
2200 } 2198 }
2201 while ( incidence ) { 2199 while ( incidence ) {
2202 Incidence *in = incidence->clone(); 2200 Incidence *in = incidence->clone();
2203 if ( addText ) 2201 if ( addText )
2204 description += in->summary() + "\n"; 2202 description += in->summary() + "\n";
2205 cal->addIncidence( in ); 2203 cal->addIncidence( in );
2206 incidence = delSel.next(); 2204 incidence = delSel.next();
2207 } 2205 }
2208 if ( beamDialog->beamVcal() ) { 2206 if ( beamDialog->beamVcal() ) {
2209 fn += ".vcs"; 2207 fn += ".vcs";
2210 FileStorage storage( cal, fn, new VCalFormat ); 2208 FileStorage storage( cal, fn, new VCalFormat );
2211 storage.save(); 2209 storage.save();
2212 } else { 2210 } else {
2213 fn += ".ics"; 2211 fn += ".ics";
2214 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2212 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2215 storage.save(); 2213 storage.save();
2216 } 2214 }
2217 delete cal; 2215 delete cal;
2218 mes = i18n("KO/Pi: Ready for beaming"); 2216 mes = i18n("KO/Pi: Ready for beaming");
2219 setCaption(mes); 2217 setCaption(mes);
2220 2218
2221#ifndef DESKTOP_VERSION 2219#ifndef DESKTOP_VERSION
2222 Ir *ir = new Ir( this ); 2220 Ir *ir = new Ir( this );
2223 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2221 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2224 ir->send( fn, description, "text/x-vCalendar" ); 2222 ir->send( fn, description, "text/x-vCalendar" );
2225#endif 2223#endif
2226 } 2224 }
2227} 2225}
2228void CalendarView::beamDone( Ir *ir ) 2226void CalendarView::beamDone( Ir *ir )
2229{ 2227{
2230#ifndef DESKTOP_VERSION 2228#ifndef DESKTOP_VERSION
2231 delete ir; 2229 delete ir;
2232#endif 2230#endif
2233} 2231}
2234 2232
2235void CalendarView::moveIncidence(Incidence * inc ) 2233void CalendarView::moveIncidence(Incidence * inc )
2236{ 2234{
2237 if ( !inc ) return; 2235 if ( !inc ) return;
2238 // qDebug("showDatePickerForIncidence( ) "); 2236 // qDebug("showDatePickerForIncidence( ) ");
2239 if ( mDateFrame->isVisible() ) 2237 if ( mDateFrame->isVisible() )
2240 mDateFrame->hide(); 2238 mDateFrame->hide();
2241 else { 2239 else {
2242 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2240 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2243 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2241 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2244 int dw = QApplication::desktop()->width(); 2242 int dw = QApplication::desktop()->width();
2245 int dh = QApplication::desktop()->height(); 2243 int dh = QApplication::desktop()->height();
2246 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2244 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2247 mDateFrame->show(); 2245 mDateFrame->show();
2248 } 2246 }
2249 mDatePickerMode = 2; 2247 mDatePickerMode = 2;
2250 mMoveIncidence = inc ; 2248 mMoveIncidence = inc ;
2251 QDate da; 2249 QDate da;
2252 if ( mMoveIncidence->type() == "Todo" ) { 2250 if ( mMoveIncidence->type() == "Todo" ) {
2253 Todo * to = (Todo *) mMoveIncidence; 2251 Todo * to = (Todo *) mMoveIncidence;
2254 if ( to->hasDueDate() ) 2252 if ( to->hasDueDate() )
2255 da = to->dtDue().date(); 2253 da = to->dtDue().date();
2256 else 2254 else
2257 da = QDate::currentDate(); 2255 da = QDate::currentDate();
2258 } else { 2256 } else {
2259 da = mMoveIncidence->dtStart().date(); 2257 da = mMoveIncidence->dtStart().date();
2260 } 2258 }
2261 mDatePicker->setDate( da ); 2259 mDatePicker->setDate( da );
2262} 2260}
2263void CalendarView::showDatePicker( ) 2261void CalendarView::showDatePicker( )
2264{ 2262{
2265 //qDebug("CalendarView::showDatePicker( ) "); 2263 //qDebug("CalendarView::showDatePicker( ) ");
2266 if ( mDateFrame->isVisible() ) 2264 if ( mDateFrame->isVisible() )
2267 mDateFrame->hide(); 2265 mDateFrame->hide();
2268 else { 2266 else {
2269 int w =mDatePicker->sizeHint().width() ; 2267 int w =mDatePicker->sizeHint().width() ;
2270 int h = mDatePicker->sizeHint().height() ; 2268 int h = mDatePicker->sizeHint().height() ;
2271 int dw = QApplication::desktop()->width(); 2269 int dw = QApplication::desktop()->width();
2272 int dh = QApplication::desktop()->height(); 2270 int dh = QApplication::desktop()->height();
2273 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2271 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2274 mDateFrame->show(); 2272 mDateFrame->show();
2275 } 2273 }
2276 mDatePickerMode = 1; 2274 mDatePickerMode = 1;
2277 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2275 mDatePicker->setDate( mNavigator->selectedDates().first() );
2278} 2276}
2279 2277
2280void CalendarView::showEventEditor() 2278void CalendarView::showEventEditor()
2281{ 2279{
2282#ifdef DESKTOP_VERSION 2280#ifdef DESKTOP_VERSION
2283 mEventEditor->show(); 2281 mEventEditor->show();
2284#else 2282#else
2285 mEventEditor->showMaximized(); 2283 mEventEditor->showMaximized();
2286#endif 2284#endif
2287} 2285}
2288void CalendarView::showTodoEditor() 2286void CalendarView::showTodoEditor()
2289{ 2287{
2290#ifdef DESKTOP_VERSION 2288#ifdef DESKTOP_VERSION
2291 mTodoEditor->show(); 2289 mTodoEditor->show();
2292#else 2290#else
2293 mTodoEditor->showMaximized(); 2291 mTodoEditor->showMaximized();
2294#endif 2292#endif
2295} 2293}
2296void CalendarView::cancelIncidence(Incidence * inc ) 2294void CalendarView::cancelIncidence(Incidence * inc )
2297{ 2295{
2298 inc->setCancelled( ! inc->cancelled() ); 2296 inc->setCancelled( ! inc->cancelled() );
2299 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2297 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2300 updateView(); 2298 updateView();
2301} 2299}
2302void CalendarView::cloneIncidence(Incidence * orgInc ) 2300void CalendarView::cloneIncidence(Incidence * orgInc )
2303{ 2301{
2304 Incidence * newInc = orgInc->clone(); 2302 Incidence * newInc = orgInc->clone();
2305 newInc->recreate(); 2303 newInc->recreate();
2306 2304
2307 if ( newInc->type() == "Todo" ) { 2305 if ( newInc->type() == "Todo" ) {
2308 Todo* t = (Todo*) newInc; 2306 Todo* t = (Todo*) newInc;
2309 mTodoEditor->editTodo( t ); 2307 mTodoEditor->editTodo( t );
2310 showTodoEditor(); 2308 showTodoEditor();
2311 if ( mTodoEditor->exec() ) { 2309 if ( mTodoEditor->exec() ) {
2312 mCalendar->addTodo( t ); 2310 mCalendar->addTodo( t );
2313 updateView(); 2311 updateView();
2314 } else { 2312 } else {
2315 delete t; 2313 delete t;
2316 } 2314 }
2317 } 2315 }
2318 else { 2316 else {
2319 Event* e = (Event*) newInc; 2317 Event* e = (Event*) newInc;
2320 mEventEditor->editEvent( e ); 2318 mEventEditor->editEvent( e );
2321 showEventEditor(); 2319 showEventEditor();
2322 if ( mEventEditor->exec() ) { 2320 if ( mEventEditor->exec() ) {
2323 mCalendar->addEvent( e ); 2321 mCalendar->addEvent( e );
2324 updateView(); 2322 updateView();
2325 } else { 2323 } else {
2326 delete e; 2324 delete e;
2327 } 2325 }
2328 } 2326 }
2329} 2327}
2330 2328
2331void CalendarView::newEvent() 2329void CalendarView::newEvent()
2332{ 2330{
2333 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2331 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2334 KOAgendaView *aView = mViewManager->agendaView(); 2332 KOAgendaView *aView = mViewManager->agendaView();
2335 if (aView) { 2333 if (aView) {
2336 if (aView->selectionStart().isValid()) { 2334 if (aView->selectionStart().isValid()) {
2337 if (aView->selectedIsAllDay()) { 2335 if (aView->selectedIsAllDay()) {
2338 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2336 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2339 } else { 2337 } else {
2340 newEvent(aView->selectionStart(),aView->selectionEnd()); 2338 newEvent(aView->selectionStart(),aView->selectionEnd());
2341 } 2339 }
2342 return; 2340 return;
2343 } 2341 }
2344 } 2342 }
2345 2343
2346 QDate date = mNavigator->selectedDates().first(); 2344 QDate date = mNavigator->selectedDates().first();
2347 QDateTime current = QDateTime::currentDateTime(); 2345 QDateTime current = QDateTime::currentDateTime();
2348 if ( date <= current.date() ) { 2346 if ( date <= current.date() ) {
2349 int hour = current.time().hour() +1; 2347 int hour = current.time().hour() +1;
2350 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2348 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2351 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2349 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2352 } else 2350 } else
2353 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2351 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2354 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2352 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2355 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2353 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2356} 2354}
2357 2355
2358void CalendarView::newEvent(QDateTime fh) 2356void CalendarView::newEvent(QDateTime fh)
2359{ 2357{
2360 newEvent(fh, 2358 newEvent(fh,
2361 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2359 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2362} 2360}
2363 2361
2364void CalendarView::newEvent(QDate dt) 2362void CalendarView::newEvent(QDate dt)
2365{ 2363{
2366 newEvent(QDateTime(dt, QTime(0,0,0)), 2364 newEvent(QDateTime(dt, QTime(0,0,0)),
2367 QDateTime(dt, QTime(0,0,0)), true); 2365 QDateTime(dt, QTime(0,0,0)), true);
2368} 2366}
2369 2367
2370void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2368void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2371{ 2369{
2372 2370
2373 mEventEditor->newEvent(fromHint,toHint,allDay); 2371 mEventEditor->newEvent(fromHint,toHint,allDay);
2374 if ( mFilterView->filtersEnabled() ) { 2372 if ( mFilterView->filtersEnabled() ) {
2375 CalFilter *filter = mFilterView->selectedFilter(); 2373 CalFilter *filter = mFilterView->selectedFilter();
2376 if (filter && filter->showCategories()) { 2374 if (filter && filter->showCategories()) {
2377 mEventEditor->setCategories(filter->categoryList().join(",") ); 2375 mEventEditor->setCategories(filter->categoryList().join(",") );
2378 } 2376 }
2379 if ( filter ) 2377 if ( filter )
2380 mEventEditor->setSecrecy( filter->getSecrecy() ); 2378 mEventEditor->setSecrecy( filter->getSecrecy() );
2381 } 2379 }
2382 showEventEditor(); 2380 showEventEditor();
2383} 2381}
2384void CalendarView::todoAdded(Todo * t) 2382void CalendarView::todoAdded(Todo * t)
2385{ 2383{
2386 2384
2387 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2385 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2388 updateTodoViews(); 2386 updateTodoViews();
2389} 2387}
2390void CalendarView::todoChanged(Todo * t) 2388void CalendarView::todoChanged(Todo * t)
2391{ 2389{
2392 emit todoModified( t, 4 ); 2390 emit todoModified( t, 4 );
2393 // updateTodoViews(); 2391 // updateTodoViews();
2394} 2392}
2395void CalendarView::todoToBeDeleted(Todo *) 2393void CalendarView::todoToBeDeleted(Todo *)
2396{ 2394{
2397 //qDebug("todoToBeDeleted(Todo *) "); 2395 //qDebug("todoToBeDeleted(Todo *) ");
2398 updateTodoViews(); 2396 updateTodoViews();
2399} 2397}
2400void CalendarView::todoDeleted() 2398void CalendarView::todoDeleted()
2401{ 2399{
2402 //qDebug(" todoDeleted()"); 2400 //qDebug(" todoDeleted()");
2403 updateTodoViews(); 2401 updateTodoViews();
2404} 2402}
2405 2403
2406 2404
2407 2405
2408void CalendarView::newTodo() 2406void CalendarView::newTodo()
2409{ 2407{
2410 2408
2411 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2409 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2412 if ( mFilterView->filtersEnabled() ) { 2410 if ( mFilterView->filtersEnabled() ) {
2413 CalFilter *filter = mFilterView->selectedFilter(); 2411 CalFilter *filter = mFilterView->selectedFilter();
2414 if (filter && filter->showCategories()) { 2412 if (filter && filter->showCategories()) {
2415 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2413 mTodoEditor->setCategories(filter->categoryList().join(",") );
2416 } 2414 }
2417 if ( filter ) 2415 if ( filter )
2418 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2416 mTodoEditor->setSecrecy( filter->getSecrecy() );
2419 } 2417 }
2420 showTodoEditor(); 2418 showTodoEditor();
2421} 2419}
2422 2420
2423void CalendarView::newSubTodo() 2421void CalendarView::newSubTodo()
2424{ 2422{
2425 Todo *todo = selectedTodo(); 2423 Todo *todo = selectedTodo();
2426 if ( todo ) newSubTodo( todo ); 2424 if ( todo ) newSubTodo( todo );
2427} 2425}
2428 2426
2429void CalendarView::newSubTodo(Todo *parentEvent) 2427void CalendarView::newSubTodo(Todo *parentEvent)
2430{ 2428{
2431 2429
2432 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2430 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2433 showTodoEditor(); 2431 showTodoEditor();
2434} 2432}
2435 2433
2436void CalendarView::newFloatingEvent() 2434void CalendarView::newFloatingEvent()
2437{ 2435{
2438 DateList tmpList = mNavigator->selectedDates(); 2436 DateList tmpList = mNavigator->selectedDates();
2439 QDate date = tmpList.first(); 2437 QDate date = tmpList.first();
2440 2438
2441 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2439 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2442 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2440 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2443} 2441}
2444 2442
2445 2443
2446void CalendarView::editEvent( Event *event ) 2444void CalendarView::editEvent( Event *event )
2447{ 2445{
2448 2446
2449 if ( !event ) return; 2447 if ( !event ) return;
2450 if ( event->isReadOnly() ) { 2448 if ( event->isReadOnly() ) {
2451 showEvent( event ); 2449 showEvent( event );
2452 return; 2450 return;
2453 } 2451 }
2454 mEventEditor->editEvent( event , mFlagEditDescription); 2452 mEventEditor->editEvent( event , mFlagEditDescription);
2455 showEventEditor(); 2453 showEventEditor();
2456} 2454}
2457void CalendarView::editJournal( Journal *jour ) 2455void CalendarView::editJournal( Journal *jour )
2458{ 2456{
2459 if ( !jour ) return; 2457 if ( !jour ) return;
2460 mDialogManager->hideSearchDialog(); 2458 mDialogManager->hideSearchDialog();
2461 mViewManager->showJournalView(); 2459 mViewManager->showJournalView();
2462 mNavigator->slotDaySelect( jour->dtStart().date() ); 2460 mNavigator->slotDaySelect( jour->dtStart().date() );
2463} 2461}
2464void CalendarView::editTodo( Todo *todo ) 2462void CalendarView::editTodo( Todo *todo )
2465{ 2463{
2466 if ( !todo ) return; 2464 if ( !todo ) return;
2467 2465
2468 if ( todo->isReadOnly() ) { 2466 if ( todo->isReadOnly() ) {
2469 showTodo( todo ); 2467 showTodo( todo );
2470 return; 2468 return;
2471 } 2469 }
2472 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2470 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2473 showTodoEditor(); 2471 showTodoEditor();
2474 2472
2475} 2473}
2476 2474
2477KOEventViewerDialog* CalendarView::getEventViewerDialog() 2475KOEventViewerDialog* CalendarView::getEventViewerDialog()
2478{ 2476{
2479 if ( !mEventViewerDialog ) { 2477 if ( !mEventViewerDialog ) {
2480 mEventViewerDialog = new KOEventViewerDialog(this); 2478 mEventViewerDialog = new KOEventViewerDialog(this);
2481 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2479 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2482 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2480 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2483 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2481 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2484 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2482 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2485 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2483 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2486 viewManager(), SLOT( showAgendaView( bool ) ) ); 2484 viewManager(), SLOT( showAgendaView( bool ) ) );
2487 mEventViewerDialog->resize( 640, 480 ); 2485 mEventViewerDialog->resize( 640, 480 );
2488 2486
2489 } 2487 }
2490 return mEventViewerDialog; 2488 return mEventViewerDialog;
2491} 2489}
2492void CalendarView::showEvent(Event *event) 2490void CalendarView::showEvent(Event *event)
2493{ 2491{
2494 getEventViewerDialog()->setEvent(event); 2492 getEventViewerDialog()->setEvent(event);
2495 getEventViewerDialog()->showMe(); 2493 getEventViewerDialog()->showMe();
2496} 2494}
2497 2495
2498void CalendarView::showTodo(Todo *event) 2496void CalendarView::showTodo(Todo *event)
2499{ 2497{
2500 getEventViewerDialog()->setTodo(event); 2498 getEventViewerDialog()->setTodo(event);
2501 getEventViewerDialog()->showMe(); 2499 getEventViewerDialog()->showMe();
2502} 2500}
2503void CalendarView::showJournal( Journal *jour ) 2501void CalendarView::showJournal( Journal *jour )
2504{ 2502{
2505 getEventViewerDialog()->setJournal(jour); 2503 getEventViewerDialog()->setJournal(jour);
2506 getEventViewerDialog()->showMe(); 2504 getEventViewerDialog()->showMe();
2507 2505
2508} 2506}
2509// void CalendarView::todoModified (Todo *event, int changed) 2507// void CalendarView::todoModified (Todo *event, int changed)
2510// { 2508// {
2511// // if (mDialogList.find (event) != mDialogList.end ()) { 2509// // if (mDialogList.find (event) != mDialogList.end ()) {
2512// // kdDebug() << "Todo modified and open" << endl; 2510// // kdDebug() << "Todo modified and open" << endl;
2513// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2511// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2514// // temp->modified (changed); 2512// // temp->modified (changed);
2515 2513
2516// // } 2514// // }
2517 2515
2518// mViewManager->updateView(); 2516// mViewManager->updateView();
2519// } 2517// }
2520 2518
2521void CalendarView::appointment_show() 2519void CalendarView::appointment_show()
2522{ 2520{
2523 Event *anEvent = 0; 2521 Event *anEvent = 0;
2524 2522
2525 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2523 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2526 2524
2527 if (mViewManager->currentView()->isEventView()) { 2525 if (mViewManager->currentView()->isEventView()) {
2528 if ( incidence && incidence->type() == "Event" ) { 2526 if ( incidence && incidence->type() == "Event" ) {
2529 anEvent = static_cast<Event *>(incidence); 2527 anEvent = static_cast<Event *>(incidence);
2530 } 2528 }
2531 } 2529 }
2532 2530
2533 if (!anEvent) { 2531 if (!anEvent) {
2534 KNotifyClient::beep(); 2532 KNotifyClient::beep();
2535 return; 2533 return;
2536 } 2534 }
2537 2535
2538 showEvent(anEvent); 2536 showEvent(anEvent);
2539} 2537}
2540 2538
2541void CalendarView::appointment_edit() 2539void CalendarView::appointment_edit()
2542{ 2540{
2543 Event *anEvent = 0; 2541 Event *anEvent = 0;
2544 2542
2545 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2543 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2546 2544
2547 if (mViewManager->currentView()->isEventView()) { 2545 if (mViewManager->currentView()->isEventView()) {
2548 if ( incidence && incidence->type() == "Event" ) { 2546 if ( incidence && incidence->type() == "Event" ) {
2549 anEvent = static_cast<Event *>(incidence); 2547 anEvent = static_cast<Event *>(incidence);
2550 } 2548 }
2551 } 2549 }
2552 2550
2553 if (!anEvent) { 2551 if (!anEvent) {
2554 KNotifyClient::beep(); 2552 KNotifyClient::beep();
2555 return; 2553 return;
2556 } 2554 }
2557 2555
2558 editEvent(anEvent); 2556 editEvent(anEvent);
2559} 2557}
2560 2558
2561void CalendarView::appointment_delete() 2559void CalendarView::appointment_delete()
2562{ 2560{
2563 Event *anEvent = 0; 2561 Event *anEvent = 0;
2564 2562
2565 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2563 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2566 2564
2567 if (mViewManager->currentView()->isEventView()) { 2565 if (mViewManager->currentView()->isEventView()) {
2568 if ( incidence && incidence->type() == "Event" ) { 2566 if ( incidence && incidence->type() == "Event" ) {
2569 anEvent = static_cast<Event *>(incidence); 2567 anEvent = static_cast<Event *>(incidence);
2570 } 2568 }
2571 } 2569 }
2572 2570
2573 if (!anEvent) { 2571 if (!anEvent) {
2574 KNotifyClient::beep(); 2572 KNotifyClient::beep();
2575 return; 2573 return;
2576 } 2574 }
2577 2575
2578 deleteEvent(anEvent); 2576 deleteEvent(anEvent);
2579} 2577}
2580 2578
2581void CalendarView::todo_unsub(Todo *anTodo ) 2579void CalendarView::todo_unsub(Todo *anTodo )
2582{ 2580{
2583 // Todo *anTodo = selectedTodo(); 2581 // Todo *anTodo = selectedTodo();
2584 if (!anTodo) return; 2582 if (!anTodo) return;
2585 if (!anTodo->relatedTo()) return; 2583 if (!anTodo->relatedTo()) return;
2586 anTodo->relatedTo()->removeRelation(anTodo); 2584 anTodo->relatedTo()->removeRelation(anTodo);
2587 anTodo->setRelatedTo(0); 2585 anTodo->setRelatedTo(0);
2588 anTodo->updated(); 2586 anTodo->updated();
2589 anTodo->setRelatedToUid(""); 2587 anTodo->setRelatedToUid("");
2590 setModified(true); 2588 setModified(true);
2591 updateView(); 2589 updateView();
2592} 2590}
2593 2591
2594void CalendarView::deleteTodo(Todo *todo) 2592void CalendarView::deleteTodo(Todo *todo)
2595{ 2593{
2596 if (!todo) { 2594 if (!todo) {
2597 KNotifyClient::beep(); 2595 KNotifyClient::beep();
2598 return; 2596 return;
2599 } 2597 }
2600 if (KOPrefs::instance()->mConfirm) { 2598 if (KOPrefs::instance()->mConfirm) {
2601 switch (msgItemDelete()) { 2599 switch (msgItemDelete()) {
2602 case KMessageBox::Continue: // OK 2600 case KMessageBox::Continue: // OK
2603 if (!todo->relations().isEmpty()) { 2601 if (!todo->relations().isEmpty()) {
2604 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2602 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2605 i18n("Delete To-Do")); 2603 i18n("Delete To-Do"));
2606 } else { 2604 } else {
2607 checkExternalId( todo ); 2605 checkExternalId( todo );
2608 calendar()->deleteTodo(todo); 2606 calendar()->deleteTodo(todo);
2609 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2607 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2610 updateView(); 2608 updateView();
2611 } 2609 }
2612 break; 2610 break;
2613 } // switch 2611 } // switch
2614 } else { 2612 } else {
2615 if (!todo->relations().isEmpty()) { 2613 if (!todo->relations().isEmpty()) {
2616 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2614 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2617 i18n("Delete To-Do")); 2615 i18n("Delete To-Do"));
2618 } else { 2616 } else {
2619 checkExternalId( todo ); 2617 checkExternalId( todo );
2620 mCalendar->deleteTodo(todo); 2618 mCalendar->deleteTodo(todo);
2621 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2619 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2622 updateView(); 2620 updateView();
2623 } 2621 }
2624 } 2622 }
2625 emit updateSearchDialog(); 2623 emit updateSearchDialog();
2626} 2624}
2627void CalendarView::deleteJournal(Journal *jour) 2625void CalendarView::deleteJournal(Journal *jour)
2628{ 2626{
2629 if (!jour) { 2627 if (!jour) {
2630 KNotifyClient::beep(); 2628 KNotifyClient::beep();
2631 return; 2629 return;
2632 } 2630 }
2633 if (KOPrefs::instance()->mConfirm) { 2631 if (KOPrefs::instance()->mConfirm) {
2634 switch (msgItemDelete()) { 2632 switch (msgItemDelete()) {
2635 case KMessageBox::Continue: // OK 2633 case KMessageBox::Continue: // OK
2636 calendar()->deleteJournal(jour); 2634 calendar()->deleteJournal(jour);
2637 updateView(); 2635 updateView();
2638 break; 2636 break;
2639 } // switch 2637 } // switch
2640 } else { 2638 } else {
2641 calendar()->deleteJournal(jour);; 2639 calendar()->deleteJournal(jour);;
2642 updateView(); 2640 updateView();
2643 } 2641 }
2644 emit updateSearchDialog(); 2642 emit updateSearchDialog();
2645} 2643}
2646 2644
2647void CalendarView::deleteEvent(Event *anEvent) 2645void CalendarView::deleteEvent(Event *anEvent)
2648{ 2646{
2649 if (!anEvent) { 2647 if (!anEvent) {
2650 KNotifyClient::beep(); 2648 KNotifyClient::beep();
2651 return; 2649 return;
2652 } 2650 }
2653 2651
2654 if (anEvent->recurrence()->doesRecur()) { 2652 if (anEvent->recurrence()->doesRecur()) {
2655 QDate itemDate = mViewManager->currentSelectionDate(); 2653 QDate itemDate = mViewManager->currentSelectionDate();
2656 int km; 2654 int km;
2657 if (!itemDate.isValid()) { 2655 if (!itemDate.isValid()) {
2658 //kdDebug() << "Date Not Valid" << endl; 2656 //kdDebug() << "Date Not Valid" << endl;
2659 if (KOPrefs::instance()->mConfirm) { 2657 if (KOPrefs::instance()->mConfirm) {
2660 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2658 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2661 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2659 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2662 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2660 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2663 if ( km == KMessageBox::Continue ) 2661 if ( km == KMessageBox::Continue )
2664 km = KMessageBox::No; // No = all below 2662 km = KMessageBox::No; // No = all below
2665 } else 2663 } else
2666 km = KMessageBox::No; 2664 km = KMessageBox::No;
2667 } else { 2665 } else {
2668 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2666 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2669 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2667 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2670 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2668 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2671 i18n("KO/Pi Confirmation"),i18n("Current"), 2669 i18n("KO/Pi Confirmation"),i18n("Current"),
2672 i18n("All")); 2670 i18n("All"));
2673 } 2671 }
2674 switch(km) { 2672 switch(km) {
2675 2673
2676 case KMessageBox::No: // Continue // all 2674 case KMessageBox::No: // Continue // all
2677 //qDebug("KMessageBox::No "); 2675 //qDebug("KMessageBox::No ");
2678 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2676 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2679 schedule(Scheduler::Cancel,anEvent); 2677 schedule(Scheduler::Cancel,anEvent);
2680 2678
2681 checkExternalId( anEvent); 2679 checkExternalId( anEvent);
2682 mCalendar->deleteEvent(anEvent); 2680 mCalendar->deleteEvent(anEvent);
2683 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2681 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2684 break; 2682 break;
2685 2683
2686 // Disabled because it does not work 2684 // Disabled because it does not work
2687 //#if 0 2685 //#if 0
2688 case KMessageBox::Yes: // just this one 2686 case KMessageBox::Yes: // just this one
2689 //QDate qd = mNavigator->selectedDates().first(); 2687 //QDate qd = mNavigator->selectedDates().first();
2690 //if (!qd.isValid()) { 2688 //if (!qd.isValid()) {
2691 // kdDebug() << "no date selected, or invalid date" << endl; 2689 // kdDebug() << "no date selected, or invalid date" << endl;
2692 // KNotifyClient::beep(); 2690 // KNotifyClient::beep();
2693 // return; 2691 // return;
2694 //} 2692 //}
2695 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2693 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2696 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2694 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2697 anEvent->addExDate(itemDate); 2695 anEvent->addExDate(itemDate);
2698 int duration = anEvent->recurrence()->duration(); 2696 int duration = anEvent->recurrence()->duration();
2699 if ( duration > 0 ) { 2697 if ( duration > 0 ) {
2700 anEvent->recurrence()->setDuration( duration - 1 ); 2698 anEvent->recurrence()->setDuration( duration - 1 );
2701 } 2699 }
2702 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2700 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2703 } 2701 }
2704 break; 2702 break;
2705 //#endif 2703 //#endif
2706 } // switch 2704 } // switch
2707 } else { 2705 } else {
2708 if (KOPrefs::instance()->mConfirm) { 2706 if (KOPrefs::instance()->mConfirm) {
2709 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2707 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2710 i18n("\nAre you sure you want\nto delete this event?"), 2708 i18n("\nAre you sure you want\nto delete this event?"),
2711 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2709 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2712 case KMessageBox::Continue: // OK 2710 case KMessageBox::Continue: // OK
2713 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2711 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2714 schedule(Scheduler::Cancel,anEvent); 2712 schedule(Scheduler::Cancel,anEvent);
2715 checkExternalId( anEvent); 2713 checkExternalId( anEvent);
2716 mCalendar->deleteEvent(anEvent); 2714 mCalendar->deleteEvent(anEvent);
2717 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2715 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2718 break; 2716 break;
2719 } // switch 2717 } // switch
2720 } else { 2718 } else {
2721 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2719 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2722 schedule(Scheduler::Cancel,anEvent); 2720 schedule(Scheduler::Cancel,anEvent);
2723 checkExternalId( anEvent); 2721 checkExternalId( anEvent);
2724 mCalendar->deleteEvent(anEvent); 2722 mCalendar->deleteEvent(anEvent);
2725 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2723 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2726 } 2724 }
2727 } // if-else 2725 } // if-else
2728 emit updateSearchDialog(); 2726 emit updateSearchDialog();
2729} 2727}
2730 2728
2731bool CalendarView::deleteEvent(const QString &uid) 2729bool CalendarView::deleteEvent(const QString &uid)
2732{ 2730{
2733 Event *ev = mCalendar->event(uid); 2731 Event *ev = mCalendar->event(uid);
2734 if (ev) { 2732 if (ev) {
2735 deleteEvent(ev); 2733 deleteEvent(ev);
2736 return true; 2734 return true;
2737 } else { 2735 } else {
2738 return false; 2736 return false;
2739 } 2737 }
2740} 2738}
2741 2739
2742/*****************************************************************************/ 2740/*****************************************************************************/
2743 2741
2744void CalendarView::action_mail() 2742void CalendarView::action_mail()
2745{ 2743{
2746#ifndef KORG_NOMAIL 2744#ifndef KORG_NOMAIL
2747 KOMailClient mailClient; 2745 KOMailClient mailClient;
2748 2746
2749 Incidence *incidence = currentSelection(); 2747 Incidence *incidence = currentSelection();
2750 2748
2751 if (!incidence) { 2749 if (!incidence) {
2752 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2750 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2753 return; 2751 return;
2754 } 2752 }
2755 if(incidence->attendeeCount() == 0 ) { 2753 if(incidence->attendeeCount() == 0 ) {
2756 KMessageBox::sorry(this, 2754 KMessageBox::sorry(this,
2757 i18n("Can't generate mail:\nNo attendees defined.\n")); 2755 i18n("Can't generate mail:\nNo attendees defined.\n"));
2758 return; 2756 return;
2759 } 2757 }
2760 2758
2761 CalendarLocal cal_tmp; 2759 CalendarLocal cal_tmp;
2762 Event *event = 0; 2760 Event *event = 0;
2763 Event *ev = 0; 2761 Event *ev = 0;
2764 if ( incidence && incidence->type() == "Event" ) { 2762 if ( incidence && incidence->type() == "Event" ) {
2765 event = static_cast<Event *>(incidence); 2763 event = static_cast<Event *>(incidence);
2766 ev = new Event(*event); 2764 ev = new Event(*event);
2767 cal_tmp.addEvent(ev); 2765 cal_tmp.addEvent(ev);
2768 } 2766 }
2769 ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); 2767 ICalFormat mForm( KOPrefs::instance()->mUseQuicksave);
2770 QString attachment = mForm.toString( &cal_tmp ); 2768 QString attachment = mForm.toString( &cal_tmp );
2771 if (ev) delete(ev); 2769 if (ev) delete(ev);
2772 2770
2773 mailClient.mailAttendees(currentSelection(), attachment); 2771 mailClient.mailAttendees(currentSelection(), attachment);
2774 2772
2775#endif 2773#endif
2776 2774
2777#if 0 2775#if 0
2778 Event *anEvent = 0; 2776 Event *anEvent = 0;
2779 if (mViewManager->currentView()->isEventView()) { 2777 if (mViewManager->currentView()->isEventView()) {
2780 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2778 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2781 } 2779 }
2782 2780
2783 if (!anEvent) { 2781 if (!anEvent) {
2784 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2782 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2785 return; 2783 return;
2786 } 2784 }
2787 if(anEvent->attendeeCount() == 0 ) { 2785 if(anEvent->attendeeCount() == 0 ) {
2788 KMessageBox::sorry(this, 2786 KMessageBox::sorry(this,
2789 i18n("Can't generate mail:\nNo attendees defined.\n")); 2787 i18n("Can't generate mail:\nNo attendees defined.\n"));
2790 return; 2788 return;
2791 } 2789 }
2792 2790
2793 mailobject.emailEvent(anEvent); 2791 mailobject.emailEvent(anEvent);
2794#endif 2792#endif
2795} 2793}
2796 2794
2797 2795
2798void CalendarView::schedule_publish(Incidence *incidence) 2796void CalendarView::schedule_publish(Incidence *incidence)
2799{ 2797{
2800 Event *event = 0; 2798 Event *event = 0;
2801 Todo *todo = 0; 2799 Todo *todo = 0;
2802 2800
2803 if (incidence == 0) { 2801 if (incidence == 0) {
2804 incidence = mViewManager->currentView()->selectedIncidences().first(); 2802 incidence = mViewManager->currentView()->selectedIncidences().first();
2805 if (incidence == 0) { 2803 if (incidence == 0) {
2806 incidence = mTodoList->selectedIncidences().first(); 2804 incidence = mTodoList->selectedIncidences().first();
2807 } 2805 }
2808 } 2806 }
2809 if ( incidence && incidence->type() == "Event" ) { 2807 if ( incidence && incidence->type() == "Event" ) {
2810 event = static_cast<Event *>(incidence); 2808 event = static_cast<Event *>(incidence);
2811 } else { 2809 } else {
2812 if ( incidence && incidence->type() == "Todo" ) { 2810 if ( incidence && incidence->type() == "Todo" ) {
2813 todo = static_cast<Todo *>(incidence); 2811 todo = static_cast<Todo *>(incidence);
2814 } 2812 }
2815 } 2813 }
2816 2814
2817 if (!event && !todo) { 2815 if (!event && !todo) {
2818 KMessageBox::sorry(this,i18n("No event selected.")); 2816 KMessageBox::sorry(this,i18n("No event selected."));
2819 return; 2817 return;
2820 } 2818 }
2821 2819
2822 PublishDialog *publishdlg = new PublishDialog(); 2820 PublishDialog *publishdlg = new PublishDialog();
2823 if (incidence->attendeeCount()>0) { 2821 if (incidence->attendeeCount()>0) {
2824 QPtrList<Attendee> attendees = incidence->attendees(); 2822 QPtrList<Attendee> attendees = incidence->attendees();
2825 attendees.first(); 2823 attendees.first();
2826 while ( attendees.current()!=0 ) { 2824 while ( attendees.current()!=0 ) {
2827 publishdlg->addAttendee(attendees.current()); 2825 publishdlg->addAttendee(attendees.current());
2828 attendees.next(); 2826 attendees.next();
2829 } 2827 }
2830 } 2828 }
2831 bool send = true; 2829 bool send = true;
2832 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 2830 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
2833 if ( publishdlg->exec() != QDialog::Accepted ) 2831 if ( publishdlg->exec() != QDialog::Accepted )
2834 send = false; 2832 send = false;
2835 } 2833 }
2836 if ( send ) { 2834 if ( send ) {
2837 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2835 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2838 if ( event ) { 2836 if ( event ) {
2839 Event *ev = new Event(*event); 2837 Event *ev = new Event(*event);
2840 ev->registerObserver(0); 2838 ev->registerObserver(0);
2841 ev->clearAttendees(); 2839 ev->clearAttendees();
2842 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2840 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2843 delete(ev); 2841 delete(ev);
2844 } 2842 }
2845 } else { 2843 } else {
2846 if ( todo ) { 2844 if ( todo ) {
2847 Todo *ev = new Todo(*todo); 2845 Todo *ev = new Todo(*todo);
2848 ev->registerObserver(0); 2846 ev->registerObserver(0);
2849 ev->clearAttendees(); 2847 ev->clearAttendees();
2850 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2848 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2851 delete(ev); 2849 delete(ev);
2852 } 2850 }
2853 } 2851 }
2854 } 2852 }
2855 } 2853 }
2856 delete publishdlg; 2854 delete publishdlg;
2857} 2855}
2858 2856
2859void CalendarView::schedule_request(Incidence *incidence) 2857void CalendarView::schedule_request(Incidence *incidence)
2860{ 2858{
2861 schedule(Scheduler::Request,incidence); 2859 schedule(Scheduler::Request,incidence);
2862} 2860}
2863 2861
2864void CalendarView::schedule_refresh(Incidence *incidence) 2862void CalendarView::schedule_refresh(Incidence *incidence)
2865{ 2863{
2866 schedule(Scheduler::Refresh,incidence); 2864 schedule(Scheduler::Refresh,incidence);
2867} 2865}
2868 2866
2869void CalendarView::schedule_cancel(Incidence *incidence) 2867void CalendarView::schedule_cancel(Incidence *incidence)
2870{ 2868{
2871 schedule(Scheduler::Cancel,incidence); 2869 schedule(Scheduler::Cancel,incidence);
2872} 2870}
2873 2871
2874void CalendarView::schedule_add(Incidence *incidence) 2872void CalendarView::schedule_add(Incidence *incidence)
2875{ 2873{
2876 schedule(Scheduler::Add,incidence); 2874 schedule(Scheduler::Add,incidence);
2877} 2875}
2878 2876
2879void CalendarView::schedule_reply(Incidence *incidence) 2877void CalendarView::schedule_reply(Incidence *incidence)
2880{ 2878{
2881 schedule(Scheduler::Reply,incidence); 2879 schedule(Scheduler::Reply,incidence);
2882} 2880}
2883 2881
2884void CalendarView::schedule_counter(Incidence *incidence) 2882void CalendarView::schedule_counter(Incidence *incidence)
2885{ 2883{
2886 schedule(Scheduler::Counter,incidence); 2884 schedule(Scheduler::Counter,incidence);
2887} 2885}
2888 2886
2889void CalendarView::schedule_declinecounter(Incidence *incidence) 2887void CalendarView::schedule_declinecounter(Incidence *incidence)
2890{ 2888{
2891 schedule(Scheduler::Declinecounter,incidence); 2889 schedule(Scheduler::Declinecounter,incidence);
2892} 2890}
2893 2891
2894void CalendarView::schedule_publish_freebusy(int daysToPublish) 2892void CalendarView::schedule_publish_freebusy(int daysToPublish)
2895{ 2893{
2896 QDateTime start = QDateTime::currentDateTime(); 2894 QDateTime start = QDateTime::currentDateTime();
2897 QDateTime end = start.addDays(daysToPublish); 2895 QDateTime end = start.addDays(daysToPublish);
2898 2896
2899 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 2897 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
2900 freebusy->setOrganizer(KOPrefs::instance()->email()); 2898 freebusy->setOrganizer(KOPrefs::instance()->email());
2901 2899
2902 2900
2903 PublishDialog *publishdlg = new PublishDialog(); 2901 PublishDialog *publishdlg = new PublishDialog();
2904 if ( publishdlg->exec() == QDialog::Accepted ) { 2902 if ( publishdlg->exec() == QDialog::Accepted ) {
2905 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2903 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2906 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 2904 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
2907 delete(freebusy); 2905 delete(freebusy);
2908 } 2906 }
2909 } 2907 }
2910 delete publishdlg; 2908 delete publishdlg;
2911} 2909}
2912 2910
2913void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 2911void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
2914{ 2912{
2915 Event *event = 0; 2913 Event *event = 0;
2916 Todo *todo = 0; 2914 Todo *todo = 0;
2917 2915
2918 if (incidence == 0) { 2916 if (incidence == 0) {
2919 incidence = mViewManager->currentView()->selectedIncidences().first(); 2917 incidence = mViewManager->currentView()->selectedIncidences().first();
2920 if (incidence == 0) { 2918 if (incidence == 0) {
2921 incidence = mTodoList->selectedIncidences().first(); 2919 incidence = mTodoList->selectedIncidences().first();
2922 } 2920 }
2923 } 2921 }
2924 if ( incidence && incidence->type() == "Event" ) { 2922 if ( incidence && incidence->type() == "Event" ) {
2925 event = static_cast<Event *>(incidence); 2923 event = static_cast<Event *>(incidence);
2926 } 2924 }
2927 if ( incidence && incidence->type() == "Todo" ) { 2925 if ( incidence && incidence->type() == "Todo" ) {
2928 todo = static_cast<Todo *>(incidence); 2926 todo = static_cast<Todo *>(incidence);
2929 } 2927 }
2930 2928
2931 if (!event && !todo) { 2929 if (!event && !todo) {
2932 KMessageBox::sorry(this,i18n("No event selected.")); 2930 KMessageBox::sorry(this,i18n("No event selected."));
2933 return; 2931 return;
2934 } 2932 }
2935 2933
2936 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 2934 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
2937 KMessageBox::sorry(this,i18n("The event has no attendees.")); 2935 KMessageBox::sorry(this,i18n("The event has no attendees."));
2938 return; 2936 return;
2939 } 2937 }
2940 2938
2941 Event *ev = 0; 2939 Event *ev = 0;
2942 if (event) ev = new Event(*event); 2940 if (event) ev = new Event(*event);
2943 Todo *to = 0; 2941 Todo *to = 0;
2944 if (todo) to = new Todo(*todo); 2942 if (todo) to = new Todo(*todo);
2945 2943
2946 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 2944 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
2947 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 2945 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
2948 if (!me) { 2946 if (!me) {
2949 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 2947 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
2950 return; 2948 return;
2951 } 2949 }
2952 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 2950 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
2953 StatusDialog *statdlg = new StatusDialog(this); 2951 StatusDialog *statdlg = new StatusDialog(this);
2954 if (!statdlg->exec()==QDialog::Accepted) return; 2952 if (!statdlg->exec()==QDialog::Accepted) return;
2955 me->setStatus( statdlg->status() ); 2953 me->setStatus( statdlg->status() );
2956 delete(statdlg); 2954 delete(statdlg);
2957 } 2955 }
2958 Attendee *menew = new Attendee(*me); 2956 Attendee *menew = new Attendee(*me);
2959 if (ev) { 2957 if (ev) {
2960 ev->clearAttendees(); 2958 ev->clearAttendees();
2961 ev->addAttendee(menew,false); 2959 ev->addAttendee(menew,false);
2962 } else { 2960 } else {
2963 if (to) { 2961 if (to) {
2964 todo->clearAttendees(); 2962 todo->clearAttendees();
2965 todo->addAttendee(menew,false); 2963 todo->addAttendee(menew,false);
2966 } 2964 }
2967 } 2965 }
2968 } 2966 }
2969 2967
2970 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2968 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2971 if (ev) { 2969 if (ev) {
2972 if ( !dlg->addMessage(ev,method) ) delete(ev); 2970 if ( !dlg->addMessage(ev,method) ) delete(ev);
2973 } else { 2971 } else {
2974 if (to) { 2972 if (to) {
2975 if ( !dlg->addMessage(to,method) ) delete(to); 2973 if ( !dlg->addMessage(to,method) ) delete(to);
2976 } 2974 }
2977 } 2975 }
2978} 2976}
2979 2977
2980void CalendarView::openAddressbook() 2978void CalendarView::openAddressbook()
2981{ 2979{
2982 KRun::runCommand("kaddressbook"); 2980 KRun::runCommand("kaddressbook");
2983} 2981}
2984 2982
2985void CalendarView::setModified(bool modified) 2983void CalendarView::setModified(bool modified)
2986{ 2984{
2987 if ( modified ) 2985 if ( modified )
2988 emit signalmodified(); 2986 emit signalmodified();
2989 if (mModified != modified) { 2987 if (mModified != modified) {
2990 mModified = modified; 2988 mModified = modified;
2991 emit modifiedChanged(mModified); 2989 emit modifiedChanged(mModified);
2992 } 2990 }
2993} 2991}
2994 2992
2995bool CalendarView::isReadOnly() 2993bool CalendarView::isReadOnly()
2996{ 2994{
2997 return mReadOnly; 2995 return mReadOnly;
2998} 2996}
2999 2997
3000void CalendarView::setReadOnly(bool readOnly) 2998void CalendarView::setReadOnly(bool readOnly)
3001{ 2999{
3002 if (mReadOnly != readOnly) { 3000 if (mReadOnly != readOnly) {
3003 mReadOnly = readOnly; 3001 mReadOnly = readOnly;
3004 emit readOnlyChanged(mReadOnly); 3002 emit readOnlyChanged(mReadOnly);
3005 } 3003 }
3006} 3004}
3007 3005
3008bool CalendarView::isModified() 3006bool CalendarView::isModified()
3009{ 3007{
3010 return mModified; 3008 return mModified;
3011} 3009}
3012 3010
3013void CalendarView::printSetup() 3011void CalendarView::printSetup()
3014{ 3012{
3015#ifndef KORG_NOPRINTER 3013#ifndef KORG_NOPRINTER
3016 createPrinter(); 3014 createPrinter();
3017 3015
3018 mCalPrinter->setupPrinter(); 3016 mCalPrinter->setupPrinter();
3019#endif 3017#endif
3020} 3018}
3021 3019
3022void CalendarView::print() 3020void CalendarView::print()
3023{ 3021{
3024#ifndef KORG_NOPRINTER 3022#ifndef KORG_NOPRINTER
3025 createPrinter(); 3023 createPrinter();
3026 3024
3027 DateList tmpDateList = mNavigator->selectedDates(); 3025 DateList tmpDateList = mNavigator->selectedDates();
3028 mCalPrinter->print(CalPrinter::Month, 3026 mCalPrinter->print(CalPrinter::Month,
3029 tmpDateList.first(), tmpDateList.last()); 3027 tmpDateList.first(), tmpDateList.last());
3030#endif 3028#endif
3031} 3029}
3032 3030
3033void CalendarView::printPreview() 3031void CalendarView::printPreview()
3034{ 3032{
3035#ifndef KORG_NOPRINTER 3033#ifndef KORG_NOPRINTER
3036 kdDebug() << "CalendarView::printPreview()" << endl; 3034 kdDebug() << "CalendarView::printPreview()" << endl;
3037 3035
3038 createPrinter(); 3036 createPrinter();
3039 3037
3040 DateList tmpDateList = mNavigator->selectedDates(); 3038 DateList tmpDateList = mNavigator->selectedDates();
3041 3039
3042 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3040 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3043 tmpDateList.last()); 3041 tmpDateList.last());
3044#endif 3042#endif
3045} 3043}
3046 3044
3047void CalendarView::exportICalendar() 3045void CalendarView::exportICalendar()
3048{ 3046{
3049 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3047 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3050 3048
3051 // Force correct extension 3049 // Force correct extension
3052 if (filename.right(4) != ".ics") filename += ".ics"; 3050 if (filename.right(4) != ".ics") filename += ".ics";
3053 3051
3054 FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 3052 FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
3055 storage.save(); 3053 storage.save();
3056} 3054}
3057 3055
3058bool CalendarView::exportVCalendar( QString filename ) 3056bool CalendarView::exportVCalendar( QString filename )
3059{ 3057{
3060 if (mCalendar->journals().count() > 0) { 3058 if (mCalendar->journals().count() > 0) {
3061 int result = KMessageBox::warningContinueCancel(this, 3059 int result = KMessageBox::warningContinueCancel(this,
3062 i18n("The journal entries can not be\nexported to a vCalendar file."), 3060 i18n("The journal entries can not be\nexported to a vCalendar file."),
3063 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3061 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3064 true); 3062 true);
3065 if (result != KMessageBox::Continue) return false; 3063 if (result != KMessageBox::Continue) return false;
3066 } 3064 }
3067 3065
3068 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3066 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3069 3067
3070 // Force correct extension 3068 // Force correct extension
3071 if (filename.right(4) != ".vcs") filename += ".vcs"; 3069 if (filename.right(4) != ".vcs") filename += ".vcs";
3072 3070
3073 FileStorage storage( mCalendar, filename, new VCalFormat ); 3071 FileStorage storage( mCalendar, filename, new VCalFormat );
3074 return storage.save(); 3072 return storage.save();
3075 3073
3076} 3074}
3077 3075
3078void CalendarView::eventUpdated(Incidence *) 3076void CalendarView::eventUpdated(Incidence *)
3079{ 3077{
3080 setModified(); 3078 setModified();
3081 // Don't call updateView here. The code, which has caused the update of the 3079 // Don't call updateView here. The code, which has caused the update of the
3082 // event is responsible for updating the view. 3080 // event is responsible for updating the view.
3083 // updateView(); 3081 // updateView();
3084} 3082}
3085 3083
3086void CalendarView::adaptNavigationUnits() 3084void CalendarView::adaptNavigationUnits()
3087{ 3085{
3088 if (mViewManager->currentView()->isEventView()) { 3086 if (mViewManager->currentView()->isEventView()) {
3089 int days = mViewManager->currentView()->currentDateCount(); 3087 int days = mViewManager->currentView()->currentDateCount();
3090 if (days == 1) { 3088 if (days == 1) {
3091 emit changeNavStringPrev(i18n("&Previous Day")); 3089 emit changeNavStringPrev(i18n("&Previous Day"));
3092 emit changeNavStringNext(i18n("&Next Day")); 3090 emit changeNavStringNext(i18n("&Next Day"));
3093 } else { 3091 } else {
3094 emit changeNavStringPrev(i18n("&Previous Week")); 3092 emit changeNavStringPrev(i18n("&Previous Week"));
3095 emit changeNavStringNext(i18n("&Next Week")); 3093 emit changeNavStringNext(i18n("&Next Week"));
3096 } 3094 }
3097 } 3095 }
3098} 3096}
3099 3097
3100void CalendarView::processMainViewSelection( Incidence *incidence ) 3098void CalendarView::processMainViewSelection( Incidence *incidence )
3101{ 3099{
3102 if ( incidence ) mTodoList->clearSelection(); 3100 if ( incidence ) mTodoList->clearSelection();
3103 processIncidenceSelection( incidence ); 3101 processIncidenceSelection( incidence );
3104} 3102}
3105 3103
3106void CalendarView::processTodoListSelection( Incidence *incidence ) 3104void CalendarView::processTodoListSelection( Incidence *incidence )
3107{ 3105{
3108 if ( incidence && mViewManager->currentView() ) { 3106 if ( incidence && mViewManager->currentView() ) {
3109 mViewManager->currentView()->clearSelection(); 3107 mViewManager->currentView()->clearSelection();
3110 } 3108 }
3111 processIncidenceSelection( incidence ); 3109 processIncidenceSelection( incidence );
3112} 3110}
3113 3111
3114void CalendarView::processIncidenceSelection( Incidence *incidence ) 3112void CalendarView::processIncidenceSelection( Incidence *incidence )
3115{ 3113{
3116 if ( incidence == mSelectedIncidence ) return; 3114 if ( incidence == mSelectedIncidence ) return;
3117 3115
3118 mSelectedIncidence = incidence; 3116 mSelectedIncidence = incidence;
3119 3117
3120 emit incidenceSelected( mSelectedIncidence ); 3118 emit incidenceSelected( mSelectedIncidence );
3121 3119
3122 if ( incidence && incidence->type() == "Event" ) { 3120 if ( incidence && incidence->type() == "Event" ) {
3123 Event *event = static_cast<Event *>( incidence ); 3121 Event *event = static_cast<Event *>( incidence );
3124 if ( event->organizer() == KOPrefs::instance()->email() ) { 3122 if ( event->organizer() == KOPrefs::instance()->email() ) {
3125 emit organizerEventsSelected( true ); 3123 emit organizerEventsSelected( true );
3126 } else { 3124 } else {
3127 emit organizerEventsSelected(false); 3125 emit organizerEventsSelected(false);
3128 } 3126 }
3129 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3127 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3130 KOPrefs::instance()->email() ) ) { 3128 KOPrefs::instance()->email() ) ) {
3131 emit groupEventsSelected( true ); 3129 emit groupEventsSelected( true );
3132 } else { 3130 } else {
3133 emit groupEventsSelected(false); 3131 emit groupEventsSelected(false);
3134 } 3132 }
3135 return; 3133 return;
3136 } else { 3134 } else {
3137 if ( incidence && incidence->type() == "Todo" ) { 3135 if ( incidence && incidence->type() == "Todo" ) {
3138 emit todoSelected( true ); 3136 emit todoSelected( true );
3139 Todo *event = static_cast<Todo *>( incidence ); 3137 Todo *event = static_cast<Todo *>( incidence );
3140 if ( event->organizer() == KOPrefs::instance()->email() ) { 3138 if ( event->organizer() == KOPrefs::instance()->email() ) {
3141 emit organizerEventsSelected( true ); 3139 emit organizerEventsSelected( true );
3142 } else { 3140 } else {
3143 emit organizerEventsSelected(false); 3141 emit organizerEventsSelected(false);
3144 } 3142 }
3145 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3143 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3146 KOPrefs::instance()->email() ) ) { 3144 KOPrefs::instance()->email() ) ) {
3147 emit groupEventsSelected( true ); 3145 emit groupEventsSelected( true );
3148 } else { 3146 } else {
3149 emit groupEventsSelected(false); 3147 emit groupEventsSelected(false);
3150 } 3148 }
3151 return; 3149 return;
3152 } else { 3150 } else {
3153 emit todoSelected( false ); 3151 emit todoSelected( false );
3154 emit organizerEventsSelected(false); 3152 emit organizerEventsSelected(false);
3155 emit groupEventsSelected(false); 3153 emit groupEventsSelected(false);
3156 } 3154 }
3157 return; 3155 return;
3158 } 3156 }
3159 3157
3160 /* if ( incidence && incidence->type() == "Todo" ) { 3158 /* if ( incidence && incidence->type() == "Todo" ) {
3161 emit todoSelected( true ); 3159 emit todoSelected( true );
3162 } else { 3160 } else {
3163 emit todoSelected( false ); 3161 emit todoSelected( false );
3164 }*/ 3162 }*/
3165} 3163}
3166 3164
3167 3165
3168void CalendarView::checkClipboard() 3166void CalendarView::checkClipboard()
3169{ 3167{
3170#ifndef KORG_NODND 3168#ifndef KORG_NODND
3171 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3169 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3172 emit pasteEnabled(true); 3170 emit pasteEnabled(true);
3173 } else { 3171 } else {
3174 emit pasteEnabled(false); 3172 emit pasteEnabled(false);
3175 } 3173 }
3176#endif 3174#endif
3177} 3175}
3178 3176
3179void CalendarView::showDates(const DateList &selectedDates) 3177void CalendarView::showDates(const DateList &selectedDates)
3180{ 3178{
3181 // kdDebug() << "CalendarView::selectDates()" << endl; 3179 // kdDebug() << "CalendarView::selectDates()" << endl;
3182 3180
3183 if ( mViewManager->currentView() ) { 3181 if ( mViewManager->currentView() ) {
3184 updateView( selectedDates.first(), selectedDates.last() ); 3182 updateView( selectedDates.first(), selectedDates.last() );
3185 } else { 3183 } else {
3186 mViewManager->showAgendaView(); 3184 mViewManager->showAgendaView();
3187 } 3185 }
3188 3186
3189 QString selDates; 3187 QString selDates;
3190 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3188 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3191 if (selectedDates.first() < selectedDates.last() ) 3189 if (selectedDates.first() < selectedDates.last() )
3192 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3190 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3193 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3191 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3194 3192
3195} 3193}
3196 3194
3197QPtrList<CalFilter> CalendarView::filters() 3195QPtrList<CalFilter> CalendarView::filters()
3198{ 3196{
3199 return mFilters; 3197 return mFilters;
3200 3198
3201} 3199}
3202void CalendarView::editFilters() 3200void CalendarView::editFilters()
3203{ 3201{
3204 // kdDebug() << "CalendarView::editFilters()" << endl; 3202 // kdDebug() << "CalendarView::editFilters()" << endl;
3205 3203
3206 CalFilter *filter = mFilters.first(); 3204 CalFilter *filter = mFilters.first();
3207 while(filter) { 3205 while(filter) {
3208 kdDebug() << " Filter: " << filter->name() << endl; 3206 kdDebug() << " Filter: " << filter->name() << endl;
3209 filter = mFilters.next(); 3207 filter = mFilters.next();
3210 } 3208 }
3211 3209
3212 mDialogManager->showFilterEditDialog(&mFilters); 3210 mDialogManager->showFilterEditDialog(&mFilters);
3213} 3211}
3214void CalendarView::toggleFilter() 3212void CalendarView::toggleFilter()
3215{ 3213{
3216 showFilter(! mFilterView->isVisible()); 3214 showFilter(! mFilterView->isVisible());
3217} 3215}
3218 3216
3219KOFilterView *CalendarView::filterView() 3217KOFilterView *CalendarView::filterView()
3220{ 3218{
3221 return mFilterView; 3219 return mFilterView;
3222} 3220}
3223void CalendarView::selectFilter( int fil ) 3221void CalendarView::selectFilter( int fil )
3224{ 3222{
3225 mFilterView->setSelectedFilter( fil ); 3223 mFilterView->setSelectedFilter( fil );
3226} 3224}
3227void CalendarView::showFilter(bool visible) 3225void CalendarView::showFilter(bool visible)
3228{ 3226{
3229 if (visible) mFilterView->show(); 3227 if (visible) mFilterView->show();
3230 else mFilterView->hide(); 3228 else mFilterView->hide();
3231} 3229}
3232void CalendarView::toggleFilerEnabled( ) 3230void CalendarView::toggleFilerEnabled( )
3233{ 3231{
3234 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3232 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3235 if ( !mFilterView->filtersEnabled() ) 3233 if ( !mFilterView->filtersEnabled() )
3236 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3234 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3237 3235
3238} 3236}
3239void CalendarView::updateFilter() 3237void CalendarView::updateFilter()
3240{ 3238{
3241 CalFilter *filter = mFilterView->selectedFilter(); 3239 CalFilter *filter = mFilterView->selectedFilter();
3242 if (filter) { 3240 if (filter) {
3243 if (mFilterView->filtersEnabled()) { 3241 if (mFilterView->filtersEnabled()) {
3244 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3242 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3245 filter->setEnabled(true); 3243 filter->setEnabled(true);
3246 } 3244 }
3247 else filter->setEnabled(false); 3245 else filter->setEnabled(false);
3248 mCalendar->setFilter(filter); 3246 mCalendar->setFilter(filter);
3249 updateView(); 3247 updateView();
3250 } 3248 }
3251} 3249}
3252 3250
3253void CalendarView::filterEdited() 3251void CalendarView::filterEdited()
3254{ 3252{
3255 mFilterView->updateFilters(); 3253 mFilterView->updateFilters();
3256 updateFilter(); 3254 updateFilter();
3257 writeSettings(); 3255 writeSettings();
3258} 3256}
3259 3257
3260 3258
3261void CalendarView::takeOverEvent() 3259void CalendarView::takeOverEvent()
3262{ 3260{
3263 Incidence *incidence = currentSelection(); 3261 Incidence *incidence = currentSelection();
3264 3262
3265 if (!incidence) return; 3263 if (!incidence) return;
3266 3264
3267 incidence->setOrganizer(KOPrefs::instance()->email()); 3265 incidence->setOrganizer(KOPrefs::instance()->email());
3268 incidence->recreate(); 3266 incidence->recreate();
3269 incidence->setReadOnly(false); 3267 incidence->setReadOnly(false);
3270 3268
3271 updateView(); 3269 updateView();
3272} 3270}
3273 3271
3274void CalendarView::takeOverCalendar() 3272void CalendarView::takeOverCalendar()
3275{ 3273{
3276 // TODO: Create Calendar::allIncidences() function and use it here 3274 // TODO: Create Calendar::allIncidences() function and use it here
3277 3275
3278 QPtrList<Event> events = mCalendar->events(); 3276 QPtrList<Event> events = mCalendar->events();
3279 for(uint i=0; i<events.count(); ++i) { 3277 for(uint i=0; i<events.count(); ++i) {
3280 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3278 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3281 events.at(i)->recreate(); 3279 events.at(i)->recreate();
3282 events.at(i)->setReadOnly(false); 3280 events.at(i)->setReadOnly(false);
3283 } 3281 }
3284 3282
3285 QPtrList<Todo> todos = mCalendar->todos(); 3283 QPtrList<Todo> todos = mCalendar->todos();
3286 for(uint i=0; i<todos.count(); ++i) { 3284 for(uint i=0; i<todos.count(); ++i) {
3287 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3285 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3288 todos.at(i)->recreate(); 3286 todos.at(i)->recreate();
3289 todos.at(i)->setReadOnly(false); 3287 todos.at(i)->setReadOnly(false);
3290 } 3288 }
3291 3289
3292 QPtrList<Journal> journals = mCalendar->journals(); 3290 QPtrList<Journal> journals = mCalendar->journals();
3293 for(uint i=0; i<journals.count(); ++i) { 3291 for(uint i=0; i<journals.count(); ++i) {
3294 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3292 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3295 journals.at(i)->recreate(); 3293 journals.at(i)->recreate();
3296 journals.at(i)->setReadOnly(false); 3294 journals.at(i)->setReadOnly(false);
3297 } 3295 }
3298 3296
3299 updateView(); 3297 updateView();
3300} 3298}
3301 3299
3302void CalendarView::showIntro() 3300void CalendarView::showIntro()
3303{ 3301{
3304 kdDebug() << "To be implemented." << endl; 3302 kdDebug() << "To be implemented." << endl;
3305} 3303}
3306 3304
3307QWidgetStack *CalendarView::viewStack() 3305QWidgetStack *CalendarView::viewStack()
3308{ 3306{
3309 return mRightFrame; 3307 return mRightFrame;
3310} 3308}
3311 3309
3312QWidget *CalendarView::leftFrame() 3310QWidget *CalendarView::leftFrame()
3313{ 3311{
3314 return mLeftFrame; 3312 return mLeftFrame;
3315} 3313}
3316 3314
3317DateNavigator *CalendarView::dateNavigator() 3315DateNavigator *CalendarView::dateNavigator()
3318{ 3316{
3319 return mNavigator; 3317 return mNavigator;
3320} 3318}
3321 3319
3322KDateNavigator* CalendarView::dateNavigatorWidget() 3320KDateNavigator* CalendarView::dateNavigatorWidget()
3323{ 3321{
3324 return mDateNavigator; 3322 return mDateNavigator;
3325} 3323}
3326void CalendarView::toggleDateNavigatorWidget() 3324void CalendarView::toggleDateNavigatorWidget()
3327{ 3325{
3328 if (mDateNavigator->isVisible()) 3326 if (mDateNavigator->isVisible())
3329 mDateNavigator->hide(); 3327 mDateNavigator->hide();
3330 else 3328 else
3331 mDateNavigator->show(); 3329 mDateNavigator->show();
3332} 3330}
3333void CalendarView::addView(KOrg::BaseView *view) 3331void CalendarView::addView(KOrg::BaseView *view)
3334{ 3332{
3335 mViewManager->addView(view); 3333 mViewManager->addView(view);
3336} 3334}
3337 3335
3338void CalendarView::showView(KOrg::BaseView *view) 3336void CalendarView::showView(KOrg::BaseView *view)
3339{ 3337{
3340 mViewManager->showView(view, mLeftFrame->isVisible()); 3338 mViewManager->showView(view, mLeftFrame->isVisible());
3341} 3339}
3342 3340
3343Incidence *CalendarView::currentSelection() 3341Incidence *CalendarView::currentSelection()
3344{ 3342{
3345 return mViewManager->currentSelection(); 3343 return mViewManager->currentSelection();
3346} 3344}
3347void CalendarView::toggleAllDaySize() 3345void CalendarView::toggleAllDaySize()
3348{ 3346{
3349 /* 3347 /*
3350 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3348 if ( KOPrefs::instance()->mAllDaySize > 47 )
3351 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3349 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3352 else 3350 else
3353 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3351 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3354 */ 3352 */
3355 viewManager()->agendaView()->toggleAllDay(); 3353 viewManager()->agendaView()->toggleAllDay();
3356} 3354}
3357void CalendarView::toggleExpand() 3355void CalendarView::toggleExpand()
3358{ 3356{
3359 // if ( mLeftFrame->isHidden() ) { 3357 // if ( mLeftFrame->isHidden() ) {
3360 // mLeftFrame->show(); 3358 // mLeftFrame->show();
3361 // emit calendarViewExpanded( false ); 3359 // emit calendarViewExpanded( false );
3362 // } else { 3360 // } else {
3363 // mLeftFrame->hide(); 3361 // mLeftFrame->hide();
3364 // emit calendarViewExpanded( true ); 3362 // emit calendarViewExpanded( true );
3365 // } 3363 // }
3366 3364
3367 globalFlagBlockAgenda = 1; 3365 globalFlagBlockAgenda = 1;
3368 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3366 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3369 globalFlagBlockAgenda = 5; 3367 globalFlagBlockAgenda = 5;
3370 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3368 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3371 //mViewManager->showView( 0, true ); 3369 //mViewManager->showView( 0, true );
3372} 3370}
3373 3371
3374void CalendarView::calendarModified( bool modified, Calendar * ) 3372void CalendarView::calendarModified( bool modified, Calendar * )
3375{ 3373{
3376 setModified( modified ); 3374 setModified( modified );
3377} 3375}
3378 3376
3379Todo *CalendarView::selectedTodo() 3377Todo *CalendarView::selectedTodo()
3380{ 3378{
3381 Incidence *incidence = currentSelection(); 3379 Incidence *incidence = currentSelection();
3382 if ( incidence && incidence->type() == "Todo" ) { 3380 if ( incidence && incidence->type() == "Todo" ) {
3383 return static_cast<Todo *>( incidence ); 3381 return static_cast<Todo *>( incidence );
3384 } 3382 }
3385 3383
3386 incidence = mTodoList->selectedIncidences().first(); 3384 incidence = mTodoList->selectedIncidences().first();
3387 if ( incidence && incidence->type() == "Todo" ) { 3385 if ( incidence && incidence->type() == "Todo" ) {
3388 return static_cast<Todo *>( incidence ); 3386 return static_cast<Todo *>( incidence );
3389 } 3387 }
3390 3388
3391 return 0; 3389 return 0;
3392} 3390}
3393 3391
3394void CalendarView::dialogClosing(Incidence *in) 3392void CalendarView::dialogClosing(Incidence *in)
3395{ 3393{
3396 // mDialogList.remove(in); 3394 // mDialogList.remove(in);
3397} 3395}
3398 3396
3399void CalendarView::showIncidence() 3397void CalendarView::showIncidence()
3400{ 3398{
3401 Incidence *incidence = currentSelection(); 3399 Incidence *incidence = currentSelection();
3402 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3400 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3403 if ( incidence ) { 3401 if ( incidence ) {
3404 ShowIncidenceVisitor v; 3402 ShowIncidenceVisitor v;
3405 v.act( incidence, this ); 3403 v.act( incidence, this );
3406 } 3404 }
3407} 3405}
3408void CalendarView::editIncidenceDescription() 3406void CalendarView::editIncidenceDescription()
3409{ 3407{
3410 mFlagEditDescription = true; 3408 mFlagEditDescription = true;
3411 editIncidence(); 3409 editIncidence();
3412 mFlagEditDescription = false; 3410 mFlagEditDescription = false;
3413} 3411}
3414void CalendarView::editIncidence() 3412void CalendarView::editIncidence()
3415{ 3413{
3416 // qDebug("editIncidence() "); 3414 // qDebug("editIncidence() ");
3417 Incidence *incidence = currentSelection(); 3415 Incidence *incidence = currentSelection();
3418 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3416 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3419 if ( incidence ) { 3417 if ( incidence ) {
3420 EditIncidenceVisitor v; 3418 EditIncidenceVisitor v;
3421 v.act( incidence, this ); 3419 v.act( incidence, this );
3422 } 3420 }
3423} 3421}
3424 3422
3425void CalendarView::deleteIncidence() 3423void CalendarView::deleteIncidence()
3426{ 3424{
3427 Incidence *incidence = currentSelection(); 3425 Incidence *incidence = currentSelection();
3428 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3426 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3429 if ( incidence ) { 3427 if ( incidence ) {
3430 deleteIncidence(incidence); 3428 deleteIncidence(incidence);
3431 } 3429 }
3432} 3430}
3433 3431
3434void CalendarView::showIncidence(Incidence *incidence) 3432void CalendarView::showIncidence(Incidence *incidence)
3435{ 3433{
3436 if ( incidence ) { 3434 if ( incidence ) {
3437 ShowIncidenceVisitor v; 3435 ShowIncidenceVisitor v;
3438 v.act( incidence, this ); 3436 v.act( incidence, this );
3439 } 3437 }
3440} 3438}
3441 3439
3442void CalendarView::editIncidence(Incidence *incidence) 3440void CalendarView::editIncidence(Incidence *incidence)
3443{ 3441{
3444 if ( incidence ) { 3442 if ( incidence ) {
3445 3443
3446 EditIncidenceVisitor v; 3444 EditIncidenceVisitor v;
3447 v.act( incidence, this ); 3445 v.act( incidence, this );
3448 3446
3449 } 3447 }
3450} 3448}
3451 3449
3452void CalendarView::deleteIncidence(Incidence *incidence) 3450void CalendarView::deleteIncidence(Incidence *incidence)
3453{ 3451{
3454 //qDebug(" CalendarView::deleteIncidence "); 3452 //qDebug(" CalendarView::deleteIncidence ");
3455 if ( incidence ) { 3453 if ( incidence ) {
3456 DeleteIncidenceVisitor v; 3454 DeleteIncidenceVisitor v;
3457 v.act( incidence, this ); 3455 v.act( incidence, this );
3458 } 3456 }
3459} 3457}
3460 3458
3461 3459
3462void CalendarView::lookForOutgoingMessages() 3460void CalendarView::lookForOutgoingMessages()
3463{ 3461{
3464 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3462 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3465 ogd->loadMessages(); 3463 ogd->loadMessages();
3466} 3464}
3467 3465
3468void CalendarView::lookForIncomingMessages() 3466void CalendarView::lookForIncomingMessages()
3469{ 3467{
3470 IncomingDialog *icd = mDialogManager->incomingDialog(); 3468 IncomingDialog *icd = mDialogManager->incomingDialog();
3471 icd->retrieve(); 3469 icd->retrieve();
3472} 3470}
3473 3471
3474bool CalendarView::removeCompletedSubTodos( Todo* t ) 3472bool CalendarView::removeCompletedSubTodos( Todo* t )
3475{ 3473{
3476 bool deleteTodo = true; 3474 bool deleteTodo = true;
3477 QPtrList<Incidence> subTodos; 3475 QPtrList<Incidence> subTodos;
3478 Incidence *aTodo; 3476 Incidence *aTodo;
3479 subTodos = t->relations(); 3477 subTodos = t->relations();
3480 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3478 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3481 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3479 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3482 deleteTodo = false; 3480 deleteTodo = false;
3483 } 3481 }
3484 if ( deleteTodo ) { 3482 if ( deleteTodo ) {
3485 if ( t->isCompleted() ) { 3483 if ( t->isCompleted() ) {
3486 checkExternalId( t ); 3484 checkExternalId( t );
3487 mCalendar->deleteTodo( t ); 3485 mCalendar->deleteTodo( t );
3488 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3486 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3489 } 3487 }
3490 else 3488 else
3491 deleteTodo = false; 3489 deleteTodo = false;
3492 } 3490 }
3493 return deleteTodo; 3491 return deleteTodo;
3494 3492
3495} 3493}
3496void CalendarView::purgeCompleted() 3494void CalendarView::purgeCompleted()
3497{ 3495{
3498 int result = KMessageBox::warningContinueCancel(this, 3496 int result = KMessageBox::warningContinueCancel(this,
3499 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3497 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3500 3498
3501 if (result == KMessageBox::Continue) { 3499 if (result == KMessageBox::Continue) {
3502 3500
3503 QPtrList<Todo> todoCal; 3501 QPtrList<Todo> todoCal;
3504 QPtrList<Todo> rootTodos; 3502 QPtrList<Todo> rootTodos;
3505 //QPtrList<Incidence> rel; 3503 //QPtrList<Incidence> rel;
3506 Todo *aTodo;//, *rTodo; 3504 Todo *aTodo;//, *rTodo;
3507 Incidence *rIncidence; 3505 Incidence *rIncidence;
3508 bool childDelete = false; 3506 bool childDelete = false;
3509 bool deletedOne = true; 3507 bool deletedOne = true;
3510 todoCal = calendar()->todos(); 3508 todoCal = calendar()->todos();
3511 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3509 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3512 if ( !aTodo->relatedTo() ) 3510 if ( !aTodo->relatedTo() )
3513 rootTodos.append( aTodo ); 3511 rootTodos.append( aTodo );
3514 } 3512 }
3515 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3513 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3516 removeCompletedSubTodos( aTodo ); 3514 removeCompletedSubTodos( aTodo );
3517 } 3515 }
3518 3516
3519 updateView(); 3517 updateView();
3520 } 3518 }
3521} 3519}
3522 3520
3523void CalendarView::slotCalendarChanged() 3521void CalendarView::slotCalendarChanged()
3524{ 3522{
3525 ; 3523 ;
3526} 3524}
3527 3525
3528NavigatorBar *CalendarView::navigatorBar() 3526NavigatorBar *CalendarView::navigatorBar()
3529{ 3527{
3530 return mNavigatorBar; 3528 return mNavigatorBar;
3531} 3529}
3532 3530
3533 3531
3534 3532
3535void CalendarView::keyPressEvent ( QKeyEvent *e) 3533void CalendarView::keyPressEvent ( QKeyEvent *e)
3536{ 3534{
3537 //qDebug(" alendarView::keyPressEvent "); 3535 //qDebug(" alendarView::keyPressEvent ");
3538 e->ignore(); 3536 e->ignore();
3539} 3537}
3540 3538
3541//#include "calendarview.moc" 3539//#include "calendarview.moc"
3542 3540
3543//#include "calendarviewbase.moc" 3541//#include "calendarviewbase.moc"
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 596148e..b8fed47 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,1186 +1,1159 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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 <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 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
53 ; 53 ;
54 } 54 }
55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
56 { 56 {
57 57
58 int id = ToDo->Location; 58 int id = ToDo->Location;
59 Todo *todo; 59 Todo *todo;
60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
61 if (todo ) 61 if (todo )
62 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
63 else 63 else
64 todo = new Todo; 64 todo = new Todo;
65 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
67 int priority; 67 int priority;
68 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
69 case GSM_Priority_Low : priority = 1; break; 69 case GSM_Priority_Low : priority = 1; break;
70 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
71 case GSM_Priority_High : priority = 5; break; 71 case GSM_Priority_High : priority = 5; break;
72 default :priority = 3 ;break; 72 default :priority = 3 ;break;
73 } 73 }
74 todo->setPriority( priority ); 74 todo->setPriority( priority );
75 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
76 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
77 int j; 77 int j;
78 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
79 bool alarm = false; 79 bool alarm = false;
80 QDateTime alarmDt; 80 QDateTime alarmDt;
81 GSM_Category Category; 81 GSM_Category Category;
82 int error; 82 int error;
83 QString completedString = "no"; 83 QString completedString = "no";
84 for (j=0;j<ToDo->EntriesNum;j++) { 84 for (j=0;j<ToDo->EntriesNum;j++) {
85 85
86 //qDebug(" for todo %d",ToDo->Location ); 86 //qDebug(" for todo %d",ToDo->Location );
87 switch (ToDo->Entries[j].EntryType) { 87 switch (ToDo->Entries[j].EntryType) {
88 case TODO_END_DATETIME: 88 case TODO_END_DATETIME:
89 dtp = &ToDo->Entries[j].Date ; 89 dtp = &ToDo->Entries[j].Date ;
90 todo->setDtDue (fromGSM ( dtp )); 90 todo->setDtDue (fromGSM ( dtp ));
91 break; 91 break;
92 case TODO_COMPLETED: 92 case TODO_COMPLETED:
93 if ( ToDo->Entries[j].Number == 1 ) { 93 if ( ToDo->Entries[j].Number == 1 ) {
94 todo->setCompleted( true ); 94 todo->setCompleted( true );
95 completedString = "yes"; 95 completedString = "yes";
96 } 96 }
97 else { 97 else {
98 todo->setCompleted( false ); 98 todo->setCompleted( false );
99 } 99 }
100 break; 100 break;
101 case TODO_ALARM_DATETIME: 101 case TODO_ALARM_DATETIME:
102 dtp = &ToDo->Entries[j].Date ; 102 dtp = &ToDo->Entries[j].Date ;
103 alarm = true; 103 alarm = true;
104 alarmDt = fromGSM ( dtp ); 104 alarmDt = fromGSM ( dtp );
105 break; 105 break;
106 case TODO_SILENT_ALARM_DATETIME: 106 case TODO_SILENT_ALARM_DATETIME:
107 dtp = &ToDo->Entries[j].Date ; 107 dtp = &ToDo->Entries[j].Date ;
108 alarm = true; 108 alarm = true;
109 alarmDt = fromGSM ( dtp ); 109 alarmDt = fromGSM ( dtp );
110 break; 110 break;
111 case TODO_TEXT: 111 case TODO_TEXT:
112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
114 break; 114 break;
115 case TODO_PRIVATE: 115 case TODO_PRIVATE:
116 if ( ToDo->Entries[j].Number == 1 ) 116 if ( ToDo->Entries[j].Number == 1 )
117 todo->setSecrecy( Incidence::SecrecyPrivate ); 117 todo->setSecrecy( Incidence::SecrecyPrivate );
118 else 118 else
119 todo->setSecrecy( Incidence::SecrecyPublic ); 119 todo->setSecrecy( Incidence::SecrecyPublic );
120 break; 120 break;
121 case TODO_CATEGORY: 121 case TODO_CATEGORY:
122 Category.Location = ToDo->Entries[j].Number; 122 Category.Location = ToDo->Entries[j].Number;
123 Category.Type = Category_ToDo; 123 Category.Type = Category_ToDo;
124 error=Phone->GetCategory(s, &Category); 124 error=Phone->GetCategory(s, &Category);
125 if (error == ERR_NONE) { 125 if (error == ERR_NONE) {
126 QStringList cat = todo->categories(); 126 QStringList cat = todo->categories();
127 QString nCat = QString ( (const char*)Category.Name ); 127 QString nCat = QString ( (const char*)Category.Name );
128 if ( !nCat.isEmpty() ) 128 if ( !nCat.isEmpty() )
129 if ( !cat.contains( nCat )) { 129 if ( !cat.contains( nCat )) {
130 cat << nCat; 130 cat << nCat;
131 todo->setCategories( cat ); 131 todo->setCategories( cat );
132 } 132 }
133 } 133 }
134 break; 134 break;
135 case TODO_CONTACTID: 135 case TODO_CONTACTID:
136#if 0 136#if 0
137 // not supported 137 // not supported
138 entry.Location = ToDo->Entries[j].Number; 138 entry.Location = ToDo->Entries[j].Number;
139 entry.MemoryType = MEM_ME; 139 entry.MemoryType = MEM_ME;
140 error=Phone->GetMemory(s, &entry); 140 error=Phone->GetMemory(s, &entry);
141 if (error == ERR_NONE) { 141 if (error == ERR_NONE) {
142 name = GSM_PhonebookGetEntryName(&entry); 142 name = GSM_PhonebookGetEntryName(&entry);
143 if (name != NULL) { 143 if (name != NULL) {
144 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); 144 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
145 } else { 145 } else {
146 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 146 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
147 } 147 }
148 } else { 148 } else {
149 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 149 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
150 } 150 }
151#endif 151#endif
152 break; 152 break;
153 case TODO_PHONE: 153 case TODO_PHONE:
154#if 0 154#if 0
155 // not supported 155 // not supported
156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
157#endif 157#endif
158 break; 158 break;
159 } 159 }
160 } 160 }
161 QString alarmString = "na"; 161 QString alarmString = "na";
162 if ( alarm ) { 162 if ( alarm ) {
163 Alarm *alarm; 163 Alarm *alarm;
164 if ( todo->alarms().count() > 0 ) 164 if ( todo->alarms().count() > 0 )
165 alarm = todo->alarms().first(); 165 alarm = todo->alarms().first();
166 else { 166 else {
167 alarm = new Alarm( todo ); 167 alarm = new Alarm( todo );
168 todo->addAlarm( alarm ); 168 todo->addAlarm( alarm );
169 } 169 }
170 alarm->setType( Alarm::Audio ); 170 alarm->setType( Alarm::Audio );
171 alarm->setEnabled( true ); 171 alarm->setEnabled( true );
172 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 172 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
173 alarm->setStartOffset( -alarmOffset ); 173 alarm->setStartOffset( -alarmOffset );
174 alarmString = QString::number( alarmOffset ); 174 alarmString = QString::number( alarmOffset );
175 } else { 175 } else {
176 Alarm *alarm; 176 Alarm *alarm;
177 if ( todo->alarms().count() > 0 ) { 177 if ( todo->alarms().count() > 0 ) {
178 alarm = todo->alarms().first(); 178 alarm = todo->alarms().first();
179 alarm->setType( Alarm::Audio ); 179 alarm->setType( Alarm::Audio );
180 alarm->setStartOffset( -60*15 ); 180 alarm->setStartOffset( -60*15 );
181 alarm->setEnabled( false ); 181 alarm->setEnabled( false );
182 } 182 }
183 } 183 }
184 // csum ***************************************** 184 // csum *****************************************
185 QStringList attList; 185 QStringList attList;
186 uint cSum; 186 uint cSum;
187 if ( todo->hasDueDate() ) 187 if ( todo->hasDueDate() )
188 attList << dtToString ( todo->dtDue() ); 188 attList << dtToString ( todo->dtDue() );
189 attList << QString::number( id ); 189 attList << QString::number( id );
190 attList << todo->summary(); 190 attList << todo->summary();
191 attList << completedString; 191 attList << completedString;
192 attList << QString::number( todo->priority() ); 192 attList << QString::number( todo->priority() );
193 attList << alarmString; 193 attList << alarmString;
194 attList << todo->categoriesStr(); 194 attList << todo->categoriesStr();
195 attList << todo->secrecyStr(); 195 attList << todo->secrecyStr();
196 cSum = PhoneFormat::getCsum(attList ); 196 cSum = PhoneFormat::getCsum(attList );
197 todo->setCsum( mProfileName, QString::number( cSum )); 197 todo->setCsum( mProfileName, QString::number( cSum ));
198 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
198 mCalendar->addTodo( todo); 199 mCalendar->addTodo( todo);
199 200
200 return true; 201 return true;
201 } 202 }
202 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 203 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
203 { 204 {
204 205
205 int id = Note->Location; 206 int id = Note->Location;
206 Event *event; 207 Event *event;
207 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 208 event = existingCalendar->event( mProfileName ,QString::number( id ) );
208 if ( event ) 209 if ( event )
209 event = (Event*)event->clone(); 210 event = (Event*)event->clone();
210 else 211 else
211 event = new Event; 212 event = new Event;
212 event->setID( mProfileName,QString::number( id ) ); 213 event->setID( mProfileName,QString::number( id ) );
213 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 214 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
214 215
215 216
216 int i = 0; 217 int i = 0;
217 bool repeating = false; 218 bool repeating = false;
218 int repeat_dayofweek = -1; 219 int repeat_dayofweek = -1;
219 int repeat_day = -1; 220 int repeat_day = -1;
220 int repeat_weekofmonth = -1; 221 int repeat_weekofmonth = -1;
221 int repeat_month = -1; 222 int repeat_month = -1;
222 int repeat_frequency = -1; 223 int repeat_frequency = -1;
223 int rec_type = -1; 224 int rec_type = -1;
224 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 225 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
225 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 226 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
226 GSM_DateTime* dtp; 227 GSM_DateTime* dtp;
227 bool alarm = false; 228 bool alarm = false;
228 QDateTime alarmDt; 229 QDateTime alarmDt;
229 repeat_startdate.Day= 0; 230 repeat_startdate.Day= 0;
230 repeat_stopdate.Day = 0; 231 repeat_stopdate.Day = 0;
231 for (i=0;i<Note->EntriesNum;i++) { 232 for (i=0;i<Note->EntriesNum;i++) {
232 233
233 //qDebug(" for ev"); 234 //qDebug(" for ev");
234 switch (Note->Entries[i].EntryType) { 235 switch (Note->Entries[i].EntryType) {
235 case CAL_START_DATETIME: 236 case CAL_START_DATETIME:
236 dtp = &Note->Entries[i].Date ; 237 dtp = &Note->Entries[i].Date ;
237 if ( dtp->Hour > 24 ) { 238 if ( dtp->Hour > 24 ) {
238 event->setFloats( true ); 239 event->setFloats( true );
239 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 240 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
240 } else { 241 } else {
241 event->setDtStart (fromGSM ( dtp )); 242 event->setDtStart (fromGSM ( dtp ));
242 243
243 } 244 }
244 break; 245 break;
245 case CAL_END_DATETIME: 246 case CAL_END_DATETIME:
246 dtp = &Note->Entries[i].Date ; 247 dtp = &Note->Entries[i].Date ;
247 if ( dtp->Hour > 24 ) { 248 if ( dtp->Hour > 24 ) {
248 event->setFloats( true ); 249 event->setFloats( true );
249 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 250 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
250 } else { 251 } else {
251 event->setDtEnd (fromGSM ( dtp )); 252 event->setDtEnd (fromGSM ( dtp ));
252 } 253 }
253 break; 254 break;
254 case CAL_ALARM_DATETIME: 255 case CAL_ALARM_DATETIME:
255 dtp = &Note->Entries[i].Date ; 256 dtp = &Note->Entries[i].Date ;
256 alarm = true; 257 alarm = true;
257 alarmDt = fromGSM ( dtp ); 258 alarmDt = fromGSM ( dtp );
258 break; 259 break;
259 case CAL_SILENT_ALARM_DATETIME: 260 case CAL_SILENT_ALARM_DATETIME:
260 dtp = &Note->Entries[i].Date ; 261 dtp = &Note->Entries[i].Date ;
261 alarm = true; 262 alarm = true;
262 alarmDt = fromGSM ( dtp ); 263 alarmDt = fromGSM ( dtp );
263 break; 264 break;
264 case CAL_RECURRANCE: 265 case CAL_RECURRANCE:
265 rec_type = Note->Entries[i].Number; 266 rec_type = Note->Entries[i].Number;
266 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 267 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
267 break; 268 break;
268 case CAL_TEXT: 269 case CAL_TEXT:
269 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); 270 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
270 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); 271 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
271 break; 272 break;
272 case CAL_LOCATION: 273 case CAL_LOCATION:
273 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); 274 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
274 break; 275 break;
275 case CAL_PHONE: 276 case CAL_PHONE:
276 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 277 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
277 break; 278 break;
278 case CAL_PRIVATE: 279 case CAL_PRIVATE:
279 if ( Note->Entries[i].Number == 1 ) 280 if ( Note->Entries[i].Number == 1 )
280 event->setSecrecy( Incidence::SecrecyPrivate ); 281 event->setSecrecy( Incidence::SecrecyPrivate );
281 else 282 else
282 event->setSecrecy( Incidence::SecrecyPublic ); 283 event->setSecrecy( Incidence::SecrecyPublic );
283 284
284 break; 285 break;
285 case CAL_CONTACTID: 286 case CAL_CONTACTID:
286#if 0 287#if 0
287 entry.Location = Note->Entries[i].Number; 288 entry.Location = Note->Entries[i].Number;
288 entry.MemoryType = MEM_ME; 289 entry.MemoryType = MEM_ME;
289 error=Phone->GetMemory(&s, &entry); 290 error=Phone->GetMemory(&s, &entry);
290 if (error == ERR_NONE) { 291 if (error == ERR_NONE) {
291 name = GSM_PhonebookGetEntryName(&entry); 292 name = GSM_PhonebookGetEntryName(&entry);
292 if (name != NULL) { 293 if (name != NULL) {
293 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 294 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
294 } else { 295 } else {
295 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 296 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
296 } 297 }
297 } else { 298 } else {
298 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 299 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
299 } 300 }
300#endif 301#endif
301 break; 302 break;
302 case CAL_REPEAT_DAYOFWEEK: 303 case CAL_REPEAT_DAYOFWEEK:
303 repeat_dayofweek = Note->Entries[i].Number; 304 repeat_dayofweek = Note->Entries[i].Number;
304 repeating = true; 305 repeating = true;
305 break; 306 break;
306 case CAL_REPEAT_DAY: 307 case CAL_REPEAT_DAY:
307 repeat_day = Note->Entries[i].Number; 308 repeat_day = Note->Entries[i].Number;
308 repeating = true; 309 repeating = true;
309 break; 310 break;
310 case CAL_REPEAT_WEEKOFMONTH: 311 case CAL_REPEAT_WEEKOFMONTH:
311 repeat_weekofmonth = Note->Entries[i].Number; 312 repeat_weekofmonth = Note->Entries[i].Number;
312 repeating = true; 313 repeating = true;
313 break; 314 break;
314 case CAL_REPEAT_MONTH: 315 case CAL_REPEAT_MONTH:
315 repeat_month = Note->Entries[i].Number; 316 repeat_month = Note->Entries[i].Number;
316 repeating = true; 317 repeating = true;
317 break; 318 break;
318 case CAL_REPEAT_FREQUENCY: 319 case CAL_REPEAT_FREQUENCY:
319 repeat_frequency = Note->Entries[i].Number; 320 repeat_frequency = Note->Entries[i].Number;
320 repeating = true; 321 repeating = true;
321 break; 322 break;
322 case CAL_REPEAT_STARTDATE: 323 case CAL_REPEAT_STARTDATE:
323 repeat_startdate = Note->Entries[i].Date; 324 repeat_startdate = Note->Entries[i].Date;
324 repeating = true; 325 repeating = true;
325 break; 326 break;
326 case CAL_REPEAT_STOPDATE: 327 case CAL_REPEAT_STOPDATE:
327 repeat_stopdate = Note->Entries[i].Date; 328 repeat_stopdate = Note->Entries[i].Date;
328 repeating = true; 329 repeating = true;
329 break; 330 break;
330 } 331 }
331 } 332 }
332#if 0 333#if 0
333 event->setDescription( attList[4] ); 334 event->setDescription( attList[4] );
334 bool repeating = false; 335 bool repeating = false;
335 int repeat_dayofweek = -1; 336 int repeat_dayofweek = -1;
336 int repeat_day = -1; 337 int repeat_day = -1;
337 int repeat_weekofmonth = -1; 338 int repeat_weekofmonth = -1;
338 int repeat_month = -1; 339 int repeat_month = -1;
339 int repeat_frequency = -1; 340 int repeat_frequency = -1;
340 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 341 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
341 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 342 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
342 343
343#endif 344#endif
344 345
345 QString recurString = "no"; 346 QString recurString = "no";
346 if ( repeating && repeat_frequency != -1) { 347 if ( repeating && repeat_frequency != -1) {
347 recurString = "y"; 348 recurString = "y";
348 if ( repeat_dayofweek >= 0 ) 349 if ( repeat_dayofweek >= 0 )
349 recurString += "dow" + QString::number (repeat_dayofweek); 350 recurString += "dow" + QString::number (repeat_dayofweek);
350 if ( repeat_day >= 0 ) 351 if ( repeat_day >= 0 )
351 recurString += "d" + QString::number (repeat_day); 352 recurString += "d" + QString::number (repeat_day);
352 if ( repeat_weekofmonth >= 0 ) 353 if ( repeat_weekofmonth >= 0 )
353 recurString += "w" + QString::number (repeat_weekofmonth); 354 recurString += "w" + QString::number (repeat_weekofmonth);
354 if ( repeat_month >= 0 ) 355 if ( repeat_month >= 0 )
355 recurString += "m" + QString::number ( repeat_month ); 356 recurString += "m" + QString::number ( repeat_month );
356 if ( repeat_frequency >= 0 ) 357 if ( repeat_frequency >= 0 )
357 recurString += "f" + QString::number (repeat_frequency ); 358 recurString += "f" + QString::number (repeat_frequency );
358 359
359 int rtype = 0; 360 int rtype = 0;
360 // qDebug("recurs "); 361 // qDebug("recurs ");
361 QDate startDate, endDate; 362 QDate startDate, endDate;
362 if ( repeat_startdate.Day > 0 ) { 363 if ( repeat_startdate.Day > 0 ) {
363 startDate = datefromGSM ( &repeat_startdate ); 364 startDate = datefromGSM ( &repeat_startdate );
364 event->setDtStart(QDateTime ( startDate, event->dtStart().time())); 365 event->setDtStart(QDateTime ( startDate, event->dtStart().time()));
365 } else { 366 } else {
366 startDate = event->dtStart().date(); 367 startDate = event->dtStart().date();
367 } 368 }
368 int freq = repeat_frequency; 369 int freq = repeat_frequency;
369 bool hasEndDate = false; 370 bool hasEndDate = false;
370 if ( repeat_stopdate.Day > 0 ) { 371 if ( repeat_stopdate.Day > 0 ) {
371 endDate = datefromGSM ( &repeat_stopdate ); 372 endDate = datefromGSM ( &repeat_stopdate );
372 hasEndDate = true; 373 hasEndDate = true;
373 } 374 }
374 375
375 uint weekDaysNum = repeat_dayofweek ; 376 uint weekDaysNum = repeat_dayofweek ;
376 // 1 == monday, 7 == sunday 377 // 1 == monday, 7 == sunday
377 QBitArray weekDays( 7 ); 378 QBitArray weekDays( 7 );
378 int i; 379 int i;
379 int bb = 1; 380 int bb = 1;
380 for( i = 1; i <= 7; ++i ) { 381 for( i = 1; i <= 7; ++i ) {
381 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 382 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
382 bb = 2 << (i-1); 383 bb = 2 << (i-1);
383 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 384 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
384 } 385 }
385 // qDebug("next "); 386 // qDebug("next ");
386 int pos = 0; 387 int pos = 0;
387 Recurrence *r = event->recurrence(); 388 Recurrence *r = event->recurrence();
388 /* 389 /*
389 0 daily; 390 0 daily;
390 1 weekly;x 391 1 weekly;x
391 2 monthpos;x 392 2 monthpos;x
392 3 monthlyday; 393 3 monthlyday;
393 4 rYearlyMont 394 4 rYearlyMont
394 bool repeating = false; 395 bool repeating = false;
395 int repeat_dayofweek = -1; 396 int repeat_dayofweek = -1;
396 int repeat_day = -1; 397 int repeat_day = -1;
397 int repeat_weekofmonth = -1; 398 int repeat_weekofmonth = -1;
398 int repeat_month = -1; 399 int repeat_month = -1;
399 int repeat_frequency = -1; 400 int repeat_frequency = -1;
400 */ 401 */
401 int dayOfWeek = startDate.dayOfWeek(); 402 int dayOfWeek = startDate.dayOfWeek();
402 if ( repeat_weekofmonth >= 0 ) { 403 if ( repeat_weekofmonth >= 0 ) {
403 rtype = 2; // ************************ 2 MonthlyPos 404 rtype = 2; // ************************ 2 MonthlyPos
404 pos = repeat_weekofmonth; 405 pos = repeat_weekofmonth;
405 if ( repeat_dayofweek >= 0 ) 406 if ( repeat_dayofweek >= 0 )
406 dayOfWeek = repeat_dayofweek; 407 dayOfWeek = repeat_dayofweek;
407 if (repeat_month > 0) { 408 if (repeat_month > 0) {
408 if ( repeat_month != event->dtStart().date().month() ) { 409 if ( repeat_month != event->dtStart().date().month() ) {
409 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); 410 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() );
410 event->setDtStart(QDateTime ( date , event->dtStart().time()) ); 411 event->setDtStart(QDateTime ( date , event->dtStart().time()) );
411 } 412 }
412 if ( freq == 1 ) 413 if ( freq == 1 )
413 freq = 12; 414 freq = 12;
414 } 415 }
415 } else if ( repeat_dayofweek >= 0 ) { 416 } else if ( repeat_dayofweek >= 0 ) {
416 rtype = 1;// ************************ 1 Weekly 417 rtype = 1;// ************************ 1 Weekly
417 } else if ( repeat_day >= 0 ) { 418 } else if ( repeat_day >= 0 ) {
418 if ( repeat_month > 0) { 419 if ( repeat_month > 0) {
419 rtype = 4; 420 rtype = 4;
420 } else { 421 } else {
421 rtype = 3; 422 rtype = 3;
422 } 423 }
423 } else { 424 } else {
424 rtype = 0 ; 425 rtype = 0 ;
425 } 426 }
426 427
427 if ( rtype == 0 ) { 428 if ( rtype == 0 ) {
428 if ( hasEndDate ) r->setDaily( freq, endDate ); 429 if ( hasEndDate ) r->setDaily( freq, endDate );
429 else r->setDaily( freq, -1 ); 430 else r->setDaily( freq, -1 );
430 } else if ( rtype == 1 ) { 431 } else if ( rtype == 1 ) {
431 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 432 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
432 else r->setWeekly( freq, weekDays, -1 ); 433 else r->setWeekly( freq, weekDays, -1 );
433 } else if ( rtype == 3 ) { 434 } else if ( rtype == 3 ) {
434 if ( hasEndDate ) 435 if ( hasEndDate )
435 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 436 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
436 else 437 else
437 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 438 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
438 r->addMonthlyDay( startDate.day() ); 439 r->addMonthlyDay( startDate.day() );
439 } else if ( rtype == 2 ) { 440 } else if ( rtype == 2 ) {
440 if ( hasEndDate ) 441 if ( hasEndDate )
441 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 442 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
442 else 443 else
443 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 444 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
444 QBitArray days( 7 ); 445 QBitArray days( 7 );
445 days.fill( false ); 446 days.fill( false );
446 days.setBit( dayOfWeek - 1 ); 447 days.setBit( dayOfWeek - 1 );
447 r->addMonthlyPos( pos, days ); 448 r->addMonthlyPos( pos, days );
448 } else if ( rtype == 4 ) { 449 } else if ( rtype == 4 ) {
449 if ( hasEndDate ) 450 if ( hasEndDate )
450 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 451 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
451 else 452 else
452 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 453 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
453 r->addYearlyNum( startDate.month() ); 454 r->addYearlyNum( startDate.month() );
454 } 455 }
455 } else { 456 } else {
456 event->recurrence()->unsetRecurs(); 457 event->recurrence()->unsetRecurs();
457 } 458 }
458 459
459 QStringList categoryList; 460 QStringList categoryList;
460 categoryList << getCategory( Note ); 461 categoryList << getCategory( Note );
461 event->setCategories( categoryList ); 462 event->setCategories( categoryList );
462 QString alarmString = "na"; 463 QString alarmString = "na";
463 // strange 0 semms to mean: alarm enabled 464 // strange 0 semms to mean: alarm enabled
464 if ( alarm ) { 465 if ( alarm ) {
465 Alarm *alarm; 466 Alarm *alarm;
466 if ( event->alarms().count() > 0 ) 467 if ( event->alarms().count() > 0 )
467 alarm = event->alarms().first(); 468 alarm = event->alarms().first();
468 else { 469 else {
469 alarm = new Alarm( event ); 470 alarm = new Alarm( event );
470 event->addAlarm( alarm ); 471 event->addAlarm( alarm );
471 } 472 }
472 alarm->setType( Alarm::Audio ); 473 alarm->setType( Alarm::Audio );
473 alarm->setEnabled( true ); 474 alarm->setEnabled( true );
474 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 475 int alarmOffset = alarmDt.secsTo( event->dtStart() );
475 alarm->setStartOffset( -alarmOffset ); 476 alarm->setStartOffset( -alarmOffset );
476 alarmString = QString::number( alarmOffset ); 477 alarmString = QString::number( alarmOffset );
477 } else { 478 } else {
478 Alarm *alarm; 479 Alarm *alarm;
479 if ( event->alarms().count() > 0 ) { 480 if ( event->alarms().count() > 0 ) {
480 alarm = event->alarms().first(); 481 alarm = event->alarms().first();
481 alarm->setType( Alarm::Audio ); 482 alarm->setType( Alarm::Audio );
482 alarm->setStartOffset( -60*15 ); 483 alarm->setStartOffset( -60*15 );
483 alarm->setEnabled( false ); 484 alarm->setEnabled( false );
484 } 485 }
485 } 486 }
486 // csum ***************************************** 487 // csum *****************************************
487 QStringList attList; 488 QStringList attList;
488 uint cSum; 489 uint cSum;
489 attList << dtToString ( event->dtStart() ); 490 attList << dtToString ( event->dtStart() );
490 attList << dtToString ( event->dtEnd() ); 491 attList << dtToString ( event->dtEnd() );
491 attList << QString::number( id ); 492 attList << QString::number( id );
492 attList << event->summary(); 493 attList << event->summary();
493 attList << event->location(); 494 attList << event->location();
494 attList << alarmString; 495 attList << alarmString;
495 attList << recurString; 496 attList << recurString;
496 attList << event->categoriesStr(); 497 attList << event->categoriesStr();
497 attList << event->secrecyStr(); 498 attList << event->secrecyStr();
498 cSum = PhoneFormat::getCsum(attList ); 499 cSum = PhoneFormat::getCsum(attList );
499 event->setCsum( mProfileName, QString::number( cSum )); 500 event->setCsum( mProfileName, QString::number( cSum ));
501 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
500 mCalendar->addEvent( event); 502 mCalendar->addEvent( event);
501 503
502 return true; 504 return true;
503 } 505 }
504 506
505 507
506 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 508 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) {
507 QDateTime dt; 509 QDateTime dt;
508 int y,m,t,h,min,sec; 510 int y,m,t,h,min,sec;
509 y = dtp->Year; 511 y = dtp->Year;
510 m = dtp->Month; 512 m = dtp->Month;
511 t = dtp->Day; 513 t = dtp->Day;
512 h = dtp->Hour; 514 h = dtp->Hour;
513 min = dtp->Minute; 515 min = dtp->Minute;
514 sec = dtp->Second; 516 sec = dtp->Second;
515 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 517 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
516 // dtp->Timezone: offset in hours 518 // dtp->Timezone: offset in hours
517 int offset = KGlobal::locale()->localTimeOffset( dt ); 519 int offset = KGlobal::locale()->localTimeOffset( dt );
518 if ( useTz ) 520 if ( useTz )
519 dt = dt.addSecs ( offset*60); 521 dt = dt.addSecs ( offset*60);
520 return dt; 522 return dt;
521 523
522 } 524 }
523 525
524 QString dtToString( const QDateTime& dti, bool useTZ = false ) 526 QString dtToString( const QDateTime& dti, bool useTZ = false )
525 { 527 {
526 QString datestr; 528 QString datestr;
527 QString timestr; 529 QString timestr;
528 int offset = KGlobal::locale()->localTimeOffset( dti ); 530 int offset = KGlobal::locale()->localTimeOffset( dti );
529 QDateTime dt; 531 QDateTime dt;
530 if (useTZ) 532 if (useTZ)
531 dt = dti.addSecs ( -(offset*60)); 533 dt = dti.addSecs ( -(offset*60));
532 else 534 else
533 dt = dti; 535 dt = dti;
534 if(dt.date().isValid()){ 536 if(dt.date().isValid()){
535 const QDate& date = dt.date(); 537 const QDate& date = dt.date();
536 datestr.sprintf("%04d%02d%02d", 538 datestr.sprintf("%04d%02d%02d",
537 date.year(), date.month(), date.day()); 539 date.year(), date.month(), date.day());
538 } 540 }
539 if(dt.time().isValid()){ 541 if(dt.time().isValid()){
540 const QTime& time = dt.time(); 542 const QTime& time = dt.time();
541 timestr.sprintf("T%02d%02d%02d", 543 timestr.sprintf("T%02d%02d%02d",
542 time.hour(), time.minute(), time.second()); 544 time.hour(), time.minute(), time.second());
543 } 545 }
544 return datestr + timestr; 546 return datestr + timestr;
545 } 547 }
546 QDate datefromGSM ( GSM_DateTime*dtp ) { 548 QDate datefromGSM ( GSM_DateTime*dtp ) {
547 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 549 return QDate ( dtp->Year, dtp->Month, dtp->Day );
548 } 550 }
549 QString getCategory( GSM_CalendarEntry*Note) 551 QString getCategory( GSM_CalendarEntry*Note)
550 { 552 {
551 QString CATEGORY; 553 QString CATEGORY;
552 switch (Note->Type) { 554 switch (Note->Type) {
553 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 555 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
554 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 556 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
555 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 557 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
556 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 558 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
557 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 559 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
558 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 560 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
559 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 561 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
560 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 562 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
561 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 563 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
562 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 564 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
563 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 565 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
564 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 566 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
565 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 567 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
566 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 568 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
567 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 569 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
568 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 570 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
569 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 571 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
570 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 572 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
571 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 573 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
572 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 574 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
573 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 575 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
574 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 576 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
575 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 577 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
576 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 578 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
577 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 579 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
578 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 580 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
579 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 581 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
580 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 582 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
581 default : CATEGORY = QString(""); 583 default : CATEGORY = QString("");
582 } 584 }
583 585
584 return CATEGORY; 586 return CATEGORY;
585 } 587 }
586 588
587protected: 589protected:
588private: 590private:
589 Calendar *mCalendar; 591 Calendar *mCalendar;
590 QString mProfileName ; 592 QString mProfileName ;
591}; 593};
592 594
593 595
594PhoneFormat::PhoneFormat() 596PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
595{ 597{
596 ; 598 mProfileName = profileName;
599 mDevice = device;
600 mConnection = connection;
601 mModel = model;
597} 602}
598 603
599PhoneFormat::~PhoneFormat() 604PhoneFormat::~PhoneFormat()
600{ 605{
601} 606}
607int PhoneFormat::initDevice(GSM_StateMachine *s)
608{
609 GSM_ReadConfig(NULL, &s->Config[0], 0);
610 s->ConfigNum = 1;
611 GSM_Config *cfg = &s->Config[0];
612 if ( ! mConnection.isEmpty() ) {
613 cfg->Connection = strdup(mConnection.latin1());
614 cfg->DefaultConnection = false;
615 qDebug("Connection set %s ", cfg->Connection );
616
617 }
618 if ( ! mDevice.isEmpty() ) {
619 cfg->Device = strdup(mDevice.latin1());
620 cfg->DefaultDevice = false;
621 qDebug("Device set %s ", cfg->Device);
622
623 }
624 if ( ! mModel.isEmpty() ) {
625 strcpy(cfg->Model,mModel.latin1() );
626 cfg->DefaultModel = false;
627 qDebug("Model set %s ",cfg->Model );
628 }
629 int error=GSM_InitConnection(s,3);
630 return error;
631}
602ulong PhoneFormat::getCsum( const QStringList & attList) 632ulong PhoneFormat::getCsum( const QStringList & attList)
603{ 633{
604 int max = attList.count() -1; 634 int max = attList.count() -1;
605 ulong cSum = 0; 635 ulong cSum = 0;
606 int j,k,i; 636 int j,k,i;
607 int add; 637 int add;
608 for ( i = 1; i < max ; ++i ) { 638 for ( i = 1; i < max ; ++i ) {
609 QString s = attList[i]; 639 QString s = attList[i];
610 if ( ! s.isEmpty() ){ 640 if ( ! s.isEmpty() ){
611 j = s.length(); 641 j = s.length();
612 for ( k = 0; k < j; ++k ) { 642 for ( k = 0; k < j; ++k ) {
613 int mul = k +1; 643 int mul = k +1;
614 add = s[k].unicode (); 644 add = s[k].unicode ();
615 if ( k < 16 ) 645 if ( k < 16 )
616 mul = mul * mul; 646 mul = mul * mul;
617 add = add * mul *i*i*i; 647 add = add * mul *i*i*i;
618 cSum += add; 648 cSum += add;
619 } 649 }
620 } 650 }
621 } 651 }
622 return cSum; 652 return cSum;
623 653
624} 654}
625//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 655//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
626#include <stdlib.h> 656#include <stdlib.h>
627#define DEBUGMODE false 657#define DEBUGMODE false
628bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) 658bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
629{ 659{
630 mProfileName = profileName;
631 GSM_StateMachines; 660 GSM_StateMachines;
632 qDebug(" load "); 661 qDebug(" load ");
633 s.opened = false; 662 s.opened = false;
634 s.msg = NULL; 663 s.msg = NULL;
635 s.ConfigNum = 0; 664 s.ConfigNum = 0;
636#if 0 665#if 0
637 static char*cp; 666 static char*cp;
638 static INI_Section *cfg = NULL; 667 static INI_Section *cfg = NULL;
639 cfg=GSM_FindGammuRC(); 668 cfg=GSM_FindGammuRC();
640 int i; 669 int i;
641 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 670 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
642 if (cfg!=NULL) { 671 if (cfg!=NULL) {
643 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); 672 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
644 if (cp) di.coding = cp; 673 if (cp) di.coding = cp;
645 674
646 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); 675 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
647 if (s.Config[i].Localize) { 676 if (s.Config[i].Localize) {
648 s.msg=INI_ReadFile(s.Config[i].Localize, true); 677 s.msg=INI_ReadFile(s.Config[i].Localize, true);
649 } else { 678 } else {
650#if !defined(WIN32) && defined(LOCALE_PATH) 679#if !defined(WIN32) && defined(LOCALE_PATH)
651 locale = setlocale(LC_MESSAGES, NULL); 680 locale = setlocale(LC_MESSAGES, NULL);
652 if (locale != NULL) { 681 if (locale != NULL) {
653 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 682 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
654 LOCALE_PATH, 683 LOCALE_PATH,
655 tolower(locale[0]), 684 tolower(locale[0]),
656 tolower(locale[1])); 685 tolower(locale[1]));
657 s.msg = INI_ReadFile(locale_file, true); 686 s.msg = INI_ReadFile(locale_file, true);
658 } 687 }
659#endif 688#endif
660 } 689 }
661 } 690 }
662 691
663 /* Wanted user specific configuration? */ 692 /* Wanted user specific configuration? */
664 693
665 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 694 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
666 695
667 s.ConfigNum++; 696 s.ConfigNum++;
668 697
669 /* We want to use only one file descriptor for global and state machine debug output */ 698 /* We want to use only one file descriptor for global and state machine debug output */
670 s.Config[i].UseGlobalDebugFile = true; 699 s.Config[i].UseGlobalDebugFile = true;
671 700
672 701
673 702
674 /* We wanted to read just user specified configuration. */ 703 /* We wanted to read just user specified configuration. */
675 {break;} 704 {break;}
676 } 705 }
677 706
678#endif 707#endif
679 setlocale(LC_ALL, ""); 708 int error=initDevice(&s);
680 GSM_ReadConfig(NULL, &s.Config[0], 0);
681 s.ConfigNum = 1;
682 GSM_Config *cfg = &s.Config[0];
683 if ( ! connection.isEmpty() ) {
684 cfg->Connection = strdup(connection.latin1());
685 cfg->DefaultConnection = false;
686 qDebug("Connection set %s ", cfg->Connection );
687
688 }
689 if ( ! device.isEmpty() ) {
690 cfg->Device = strdup(device.latin1());
691 cfg->DefaultDevice = false;
692 qDebug("Device set %s ", cfg->Device);
693
694 }
695 if ( ! model.isEmpty() ) {
696 strcpy(cfg->Model,model.latin1() );
697 cfg->DefaultModel = false;
698 qDebug("Model set %s ",cfg->Model );
699
700
701 }
702 int error=GSM_InitConnection(&s,3);
703 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 709 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
704 if ( error != ERR_NONE ) 710 if ( error != ERR_NONE )
705 return false; 711 return false;
706 GSM_Phone_Functions*Phone; 712 GSM_Phone_Functions*Phone;
707 GSM_CalendarEntrynote; 713 GSM_CalendarEntrynote;
708 bool start = true; 714 bool start = true;
709 Phone=s.Phone.Functions; 715 Phone=s.Phone.Functions;
710 bool gshutdown = false; 716 bool gshutdown = false;
711 PhoneParser handler( calendar, profileName ); 717 PhoneParser handler( calendar, mProfileName );
712 int ccc = 0; 718 int ccc = 0;
713 qDebug("Debug: only 10 calender items are downloaded "); 719 qDebug("Debug: only 10 calender items are downloaded ");
714 while (!gshutdown && ccc++ < 10) { 720 while (!gshutdown && ccc++ < 10) {
715 721
716 qDebug("readEvent %d ", ccc); 722 qDebug("readEvent %d ", ccc);
717 error=Phone->GetNextCalendar(&s,&note,start); 723 error=Phone->GetNextCalendar(&s,&note,start);
718 if (error == ERR_EMPTY) break; 724 if (error == ERR_EMPTY) break;
719 start = false; 725 start = false;
720 handler.readEvent( existingCal, &note ); 726 handler.readEvent( existingCal, &note );
721 } 727 }
722 728
723 start = true; 729 start = true;
724 GSM_ToDoEntry ToDo; 730 GSM_ToDoEntry ToDo;
725 ccc = 0; 731 ccc = 0;
726 while (!gshutdown) { 732 while (!gshutdown) {
727 error = Phone->GetNextToDo(&s, &ToDo, start); 733 error = Phone->GetNextToDo(&s, &ToDo, start);
728 if (error == ERR_EMPTY) break; 734 if (error == ERR_EMPTY) break;
729 start = false; 735 start = false;
730 qDebug("ReadTodo %d ", ++ccc); 736 qDebug("ReadTodo %d ", ++ccc);
731 handler.readTodo( existingCal, &ToDo, &s); 737 handler.readTodo( existingCal, &ToDo, &s);
732 738
733 } 739 }
734 740
735 error=GSM_TerminateConnection(&s); 741 error=GSM_TerminateConnection(&s);
736 742
737 return true; 743 return true;
738} 744}
745void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note )
746{
739 747
740bool PhoneFormat::save( Calendar *calendar) 748}
749void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
741{ 750{
742#if 0 751#if 0
743 QLabel status ( i18n("Processing/adding events ..."), 0 ); 752 QStringList list;
753 list.append( QString::number( todo->zaurusId() ) );
754 list.append( todo->categories().join(",") );
755
756 if ( todo->hasStartDate() ) {
757 list.append( dtToString( todo->dtStart()) );
758 } else
759 list.append( QString() );
760
761 if ( todo->hasDueDate() ) {
762 QTime tim;
763 if ( todo->doesFloat()) {
764 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
765 } else {
766 list.append( dtToString(todo->dtDue() ) );
767 }
768 } else
769 list.append( QString() );
770
771 if ( todo->isCompleted() ) {
772 list.append( dtToString( todo->completed()) );
773 list.append( "0" ); // yes 0 == completed
774 } else {
775 list.append( dtToString( todo->completed()) );
776 list.append( "1" );
777 }
778 list.append( QString::number( todo->priority() ));
779 if( ! todo->summary().isEmpty() )
780 list.append( todo->summary() );
781 else
782 list.append( "" );
783 if (! todo->description().isEmpty() )
784 list.append( todo->description() );
785 else
786 list.append( "" );
787 for(QStringList::Iterator it=list.begin();
788 it!=list.end(); ++it){
789 QString& s = (*it);
790 s.replace(QRegExp("\""), "\"\"");
791 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
792 s.prepend('\"');
793 s.append('\"');
794 } else if(s.isEmpty() && !s.isNull()){
795 s = "\"\"";
796 }
797 }
798 return list.join(",");
799#endif
800}
801bool PhoneFormat::save( Calendar *calendar)
802{
803 GSM_StateMachines;
804 qDebug(" save ");
805 s.opened = false;
806 s.msg = NULL;
807 s.ConfigNum = 0;
808 QLabel status ( i18n("Writing data. Opening device ..."), 0 );
744 int w = status.sizeHint().width()+20 ; 809 int w = status.sizeHint().width()+20 ;
745 if ( w < 200 ) w = 200; 810 if ( w < 200 ) w = 200;
746 int h = status.sizeHint().height()+20 ; 811 int h = status.sizeHint().height()+20 ;
747 int dw = QApplication::desktop()->width(); 812 int dw = QApplication::desktop()->width();
748 int dh = QApplication::desktop()->height(); 813 int dh = QApplication::desktop()->height();
749 status.setCaption(i18n("Writing DTM Data") ); 814 status.setCaption(i18n("Writing DTM Data") );
750 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 815 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
751 status.show(); 816 status.show();
752 status.raise(); 817 status.raise();
753 qApp->processEvents(); 818 qApp->processEvents();
754 bool debug = DEBUGMODE; 819
755 QString codec = "utf8"; 820 int error=initDevice(&s);
756 QString answer; 821 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
757 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 822 if ( error != ERR_NONE )
758 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 823 return false;
759 QString command; 824 GSM_Phone_Functions*Phone;
760 QPtrList<Event> er = calendar->rawEvents(); 825 GSM_CalendarEntryNote;
761 Event* ev = er.first(); 826 bool start = true;
762 QString fileName = "/tmp/kopitempout"; 827 Phone=s.Phone.Functions;
763 int i = 0; 828 bool gshutdown = false;
764 QString changeString = ePrefix; 829 QPtrList<Event> er = calendar->rawEvents();
765 QString deleteString = ePrefix; 830 Event* ev = er.first();
766 bool deleteEnt = false;
767 bool changeEnt = false;
768 QString message = i18n("Processing event # "); 831 QString message = i18n("Processing event # ");
769 int procCount = 0; 832 int procCount = 0;
770 while ( ev ) { 833 while ( ev ) {
771 //qDebug("i %d ", ++i); 834 //qDebug("i %d ", ++i);
772 if ( true /*ev->zaurusStat() != -2*/ ) { 835 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
836
773 status.setText ( message + QString::number ( ++procCount ) ); 837 status.setText ( message + QString::number ( ++procCount ) );
774 qApp->processEvents(); 838 qApp->processEvents();
775 QString eString = getEventString( ev ); 839 event2GSM( ev, &Note );
776 if (/* ev->zaurusStat() == -3 */ true) { // delete 840 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
777 // deleting empty strings does not work. 841 error = Phone->DeleteCalendar(&s, &Note);
778 // we write first and x and then delete the record with the x
779 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
780 changeString += eString + "\n";
781 deleteString += eString + "\n";
782 deleteEnt = true;
783 changeEnt = true;
784 } 842 }
785 else if ( /*ev->zaurusId() == -1*/true ) { // add new 843 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
786 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 844 // we have to do this later after deleting
787 system ( command.utf8() ); 845
788 QFile file( fileName );
789 if (!file.open( IO_ReadOnly ) ) {
790 return false;
791
792 }
793 QTextStream ts( &file );
794 ts.setCodec( QTextCodec::codecForName("utf8") );
795 answer = ts.read();
796 file.close();
797 //qDebug("answer \n%s ", answer.latin1());
798 getNumFromRecord( answer, ev ) ;
799
800 } 846 }
801 else { // change existing 847 else { // change existing
802 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 848 error = Phone->AddCalendar(&s, &Note);
803 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
804 changeString += eString + "\n";
805 changeEnt = true;
806
807 } 849 }
808 } 850 }
809 ev = er.next(); 851 ev = er.next();
810 } 852 }
811 status.setText ( i18n("Changing events ...") ); 853 ev = er.first();
812 qApp->processEvents(); 854 // pending get empty slots
813 //qDebug("changing... "); 855 while ( ev ) {
814 if ( changeEnt ) { 856 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
815 QFile file( fileName ); 857 if ( ev->getID(mProfileName).isEmpty() ) {
816 if (!file.open( IO_WriteOnly ) ) { 858 status.setText ( message + QString::number ( ++procCount ) );
817 return false; 859 qApp->processEvents();
818 860 int newID ;//= pending
819 } 861 ev->setID(mProfileName, QString::number( newID ));
820 QTextStream ts( &file ); 862 event2GSM( ev, &Note );
821 ts.setCodec( QTextCodec::codecForName("utf8") ); 863 error = Phone->AddCalendar(&s, &Note);
822 ts << changeString ; 864 }
823 file.close(); 865 }
824 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 866 ev = er.next();
825 system ( command.latin1() );
826 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
827
828 }
829 status.setText ( i18n("Deleting events ...") );
830 qApp->processEvents();
831 //qDebug("deleting... ");
832 if ( deleteEnt ) {
833 QFile file( fileName );
834 if (!file.open( IO_WriteOnly ) ) {
835 return false;
836
837 }
838 QTextStream ts( &file );
839 ts.setCodec( QTextCodec::codecForName("utf8") );
840 ts << deleteString;
841 file.close();
842 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
843 system ( command.latin1() );
844 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
845 } 867 }
846 868 GSM_ToDoEntry ToDoEntry;
847
848 changeString = tPrefix;
849 deleteString = tPrefix;
850 status.setText ( i18n("Processing todos ...") );
851 qApp->processEvents();
852 QPtrList<Todo> tl = calendar->rawTodos(); 869 QPtrList<Todo> tl = calendar->rawTodos();
853 Todo* to = tl.first(); 870 Todo* to = tl.first();
854 i = 0; 871
855 message = i18n("Processing todo # "); 872 message = i18n("Processing todo # ");
856 procCount = 0; 873 procCount = 0;
857 while ( to ) { 874 while ( to ) {
858 if ( true /*to->zaurusStat() != -2 */) { 875 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
859 status.setText ( message + QString::number ( ++procCount ) ); 876 status.setText ( message + QString::number ( ++procCount ) );
860 qApp->processEvents(); 877 qApp->processEvents();
861 QString eString = getTodoString( to ); 878 todo2GSM( to, &ToDoEntry );
862 if ( /*to->zaurusStat() == -3*/true ) { // delete 879 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
863 // deleting empty strings does not work. 880 error=Phone->DeleteToDo(&s,&ToDoEntry);
864 // we write first and x and then delete the record with the x
865 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
866 changeString += eString + "\n";
867 deleteString += eString + "\n";
868 deleteEnt = true;
869 changeEnt = true;
870 } 881 }
871 else if ( true /*to->zaurusId() == -1*/ ) { // add new 882 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
872 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 883 ;
873 system ( command.utf8() );
874 QFile file( fileName );
875 if (!file.open( IO_ReadOnly ) ) {
876 return false;
877
878 }
879 QTextStream ts( &file );
880 ts.setCodec( QTextCodec::codecForName("utf8") );
881 answer = ts.read();
882 file.close();
883 //qDebug("answer \n%s ", answer.latin1());
884 getNumFromRecord( answer, to ) ;
885
886 } 884 }
887 else { // change existing 885 else { // change existing
888 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 886 error=Phone->AddToDo(&s,&ToDoEntry);
889 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
890 changeString += eString + "\n";
891 changeEnt = true;
892
893 } 887 }
894 } 888 }
895
896 to = tl.next(); 889 to = tl.next();
897 } 890 }
898 status.setText ( i18n("Changing todos ...") ); 891
899 qApp->processEvents(); 892 // pending get empty slots
900 //qDebug("changing... "); 893 to = tl.first();
901 if ( changeEnt ) { 894 while ( to ) {
902 QFile file( fileName ); 895 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
903 if (!file.open( IO_WriteOnly ) ) { 896 if ( to->getID(mProfileName).isEmpty() ) {
904 return false; 897 status.setText ( message + QString::number ( ++procCount ) );
905 898 qApp->processEvents();
906 } 899 int newID ;//= pending
907 QTextStream ts( &file ); 900 to->setID(mProfileName, QString::number( newID ));
908 ts.setCodec( QTextCodec::codecForName("utf8") ); 901 todo2GSM( to, &ToDoEntry );
909 ts << changeString ; 902 error=Phone->AddToDo(&s,&ToDoEntry);
910 file.close(); 903 }
911 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 904 }
912 system ( command.latin1() ); 905 to = tl.next();
913 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
914
915 }
916 status.setText ( i18n("Deleting todos ...") );
917 qApp->processEvents();
918 //qDebug("deleting... ");
919 if ( deleteEnt ) {
920 QFile file( fileName );
921 if (!file.open( IO_WriteOnly ) ) {
922 return false;
923
924 }
925 QTextStream ts( &file );
926 ts.setCodec( QTextCodec::codecForName("utf8") );
927 ts << deleteString;
928 file.close();
929 command = "db2file todo -d -c " + codec+ " < "+ fileName;
930 system ( command.latin1() );
931 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
932 } 906 }
933#endif
934 return true; 907 return true;
935} 908}
936QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 909QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
937{ 910{
938 QString datestr; 911 QString datestr;
939 QString timestr; 912 QString timestr;
940 int offset = KGlobal::locale()->localTimeOffset( dti ); 913 int offset = KGlobal::locale()->localTimeOffset( dti );
941 QDateTime dt; 914 QDateTime dt;
942 if (useTZ) 915 if (useTZ)
943 dt = dti.addSecs ( -(offset*60)); 916 dt = dti.addSecs ( -(offset*60));
944 else 917 else
945 dt = dti; 918 dt = dti;
946 if(dt.date().isValid()){ 919 if(dt.date().isValid()){
947 const QDate& date = dt.date(); 920 const QDate& date = dt.date();
948 datestr.sprintf("%04d%02d%02d", 921 datestr.sprintf("%04d%02d%02d",
949 date.year(), date.month(), date.day()); 922 date.year(), date.month(), date.day());
950 } 923 }
951 if(dt.time().isValid()){ 924 if(dt.time().isValid()){
952 const QTime& time = dt.time(); 925 const QTime& time = dt.time();
953 timestr.sprintf("T%02d%02d%02d", 926 timestr.sprintf("T%02d%02d%02d",
954 time.hour(), time.minute(), time.second()); 927 time.hour(), time.minute(), time.second());
955 } 928 }
956 return datestr + timestr; 929 return datestr + timestr;
957} 930}
958QString PhoneFormat::getEventString( Event* event ) 931QString PhoneFormat::getEventString( Event* event )
959{ 932{
960#if 0 933#if 0
961 QStringList list; 934 QStringList list;
962 list.append( QString::number(event->zaurusId() ) ); 935 list.append( QString::number(event->zaurusId() ) );
963 list.append( event->categories().join(",") ); 936 list.append( event->categories().join(",") );
964 if ( !event->summary().isEmpty() ) 937 if ( !event->summary().isEmpty() )
965 list.append( event->summary() ); 938 list.append( event->summary() );
966 else 939 else
967 list.append("" ); 940 list.append("" );
968 if ( !event->location().isEmpty() ) 941 if ( !event->location().isEmpty() )
969 list.append( event->location() ); 942 list.append( event->location() );
970 else 943 else
971 list.append("" ); 944 list.append("" );
972 if ( !event->description().isEmpty() ) 945 if ( !event->description().isEmpty() )
973 list.append( event->description() ); 946 list.append( event->description() );
974 else 947 else
975 list.append( "" ); 948 list.append( "" );
976 if ( event->doesFloat () ) { 949 if ( event->doesFloat () ) {
977 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 950 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
978 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 951 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
979 list.append( "1" ); 952 list.append( "1" );
980 953
981 } 954 }
982 else { 955 else {
983 list.append( dtToString( event->dtStart()) ); 956 list.append( dtToString( event->dtStart()) );
984 list.append( dtToString( event->dtEnd()) ); //6 957 list.append( dtToString( event->dtEnd()) ); //6
985 list.append( "0" ); 958 list.append( "0" );
986 } 959 }
987 bool noAlarm = true; 960 bool noAlarm = true;
988 if ( event->alarms().count() > 0 ) { 961 if ( event->alarms().count() > 0 ) {
989 Alarm * al = event->alarms().first(); 962 Alarm * al = event->alarms().first();
990 if ( al->enabled() ) { 963 if ( al->enabled() ) {
991 noAlarm = false; 964 noAlarm = false;
992 list.append( "0" ); // yes, 0 == alarm 965 list.append( "0" ); // yes, 0 == alarm
993 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 966 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
994 if ( al->type() == Alarm::Audio ) 967 if ( al->type() == Alarm::Audio )
995 list.append( "1" ); // type audio 968 list.append( "1" ); // type audio
996 else 969 else
997 list.append( "0" ); // type silent 970 list.append( "0" ); // type silent
998 } 971 }
999 } 972 }
1000 if ( noAlarm ) { 973 if ( noAlarm ) {
1001 list.append( "1" ); // yes, 1 == no alarm 974 list.append( "1" ); // yes, 1 == no alarm
1002 list.append( "0" ); // no alarm offset 975 list.append( "0" ); // no alarm offset
1003 list.append( "1" ); // type 976 list.append( "1" ); // type
1004 } 977 }
1005 // next is: 11 978 // next is: 11
1006 // next is: 11-16 are recurrence 979 // next is: 11-16 are recurrence
1007 Recurrence* rec = event->recurrence(); 980 Recurrence* rec = event->recurrence();
1008 981
1009 bool writeEndDate = false; 982 bool writeEndDate = false;
1010 switch ( rec->doesRecur() ) 983 switch ( rec->doesRecur() )
1011 { 984 {
1012 case Recurrence::rDaily: // 0 985 case Recurrence::rDaily: // 0
1013 list.append( "0" ); 986 list.append( "0" );
1014 list.append( QString::number( rec->frequency() ));//12 987 list.append( QString::number( rec->frequency() ));//12
1015 list.append( "0" ); 988 list.append( "0" );
1016 list.append( "0" ); 989 list.append( "0" );
1017 writeEndDate = true; 990 writeEndDate = true;
1018 break; 991 break;
1019 case Recurrence::rWeekly:// 1 992 case Recurrence::rWeekly:// 1
1020 list.append( "1" ); 993 list.append( "1" );
1021 list.append( QString::number( rec->frequency()) );//12 994 list.append( QString::number( rec->frequency()) );//12
1022 list.append( "0" ); 995 list.append( "0" );
1023 { 996 {
1024 int days = 0; 997 int days = 0;
1025 QBitArray weekDays = rec->days(); 998 QBitArray weekDays = rec->days();
1026 int i; 999 int i;
1027 for( i = 1; i <= 7; ++i ) { 1000 for( i = 1; i <= 7; ++i ) {
1028 if ( weekDays[i-1] ) { 1001 if ( weekDays[i-1] ) {
1029 days += 1 << (i-1); 1002 days += 1 << (i-1);
1030 } 1003 }
1031 } 1004 }
1032 list.append( QString::number( days ) ); 1005 list.append( QString::number( days ) );
1033 } 1006 }
1034 //pending weekdays 1007 //pending weekdays
1035 writeEndDate = true; 1008 writeEndDate = true;
1036 1009
1037 break; 1010 break;
1038 case Recurrence::rMonthlyPos:// 2 1011 case Recurrence::rMonthlyPos:// 2
1039 list.append( "2" ); 1012 list.append( "2" );
1040 list.append( QString::number( rec->frequency()) );//12 1013 list.append( QString::number( rec->frequency()) );//12
1041 1014
1042 writeEndDate = true; 1015 writeEndDate = true;
1043 { 1016 {
1044 int count = 1; 1017 int count = 1;
1045 QPtrList<Recurrence::rMonthPos> rmp; 1018 QPtrList<Recurrence::rMonthPos> rmp;
1046 rmp = rec->monthPositions(); 1019 rmp = rec->monthPositions();
1047 if ( rmp.first()->negative ) 1020 if ( rmp.first()->negative )
1048 count = 5 - rmp.first()->rPos - 1; 1021 count = 5 - rmp.first()->rPos - 1;
1049 else 1022 else
1050 count = rmp.first()->rPos - 1; 1023 count = rmp.first()->rPos - 1;
1051 list.append( QString::number( count ) ); 1024 list.append( QString::number( count ) );
1052 1025
1053 } 1026 }
1054 1027
1055 list.append( "0" ); 1028 list.append( "0" );
1056 break; 1029 break;
1057 case Recurrence::rMonthlyDay:// 3 1030 case Recurrence::rMonthlyDay:// 3
1058 list.append( "3" ); 1031 list.append( "3" );
1059 list.append( QString::number( rec->frequency()) );//12 1032 list.append( QString::number( rec->frequency()) );//12
1060 list.append( "0" ); 1033 list.append( "0" );
1061 list.append( "0" ); 1034 list.append( "0" );
1062 writeEndDate = true; 1035 writeEndDate = true;
1063 break; 1036 break;
1064 case Recurrence::rYearlyMonth://4 1037 case Recurrence::rYearlyMonth://4
1065 list.append( "4" ); 1038 list.append( "4" );
1066 list.append( QString::number( rec->frequency()) );//12 1039 list.append( QString::number( rec->frequency()) );//12
1067 list.append( "0" ); 1040 list.append( "0" );
1068 list.append( "0" ); 1041 list.append( "0" );
1069 writeEndDate = true; 1042 writeEndDate = true;
1070 break; 1043 break;
1071 1044
1072 default: 1045 default:
1073 list.append( "255" ); 1046 list.append( "255" );
1074 list.append( QString() ); 1047 list.append( QString() );
1075 list.append( "0" ); 1048 list.append( "0" );
1076 list.append( QString() ); 1049 list.append( QString() );
1077 list.append( "0" ); 1050 list.append( "0" );
1078 list.append( "20991231T000000" ); 1051 list.append( "20991231T000000" );
1079 break; 1052 break;
1080 } 1053 }
1081 if ( writeEndDate ) { 1054 if ( writeEndDate ) {
1082 1055
1083 if ( rec->endDate().isValid() ) { // 15 + 16 1056 if ( rec->endDate().isValid() ) { // 15 + 16
1084 list.append( "1" ); 1057 list.append( "1" );
1085 list.append( dtToString( rec->endDate()) ); 1058 list.append( dtToString( rec->endDate()) );
1086 } else { 1059 } else {
1087 list.append( "0" ); 1060 list.append( "0" );
1088 list.append( "20991231T000000" ); 1061 list.append( "20991231T000000" );
1089 } 1062 }
1090 1063
1091 } 1064 }
1092 if ( event->doesFloat () ) { 1065 if ( event->doesFloat () ) {
1093 list.append( dtToString( event->dtStart(), false ).left( 8 )); 1066 list.append( dtToString( event->dtStart(), false ).left( 8 ));
1094 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 1067 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
1095 1068
1096 } 1069 }
1097 else { 1070 else {
1098 list.append( QString() ); 1071 list.append( QString() );
1099 list.append( QString() ); 1072 list.append( QString() );
1100 1073
1101 } 1074 }
1102 if (event->dtStart().date() == event->dtEnd().date() ) 1075 if (event->dtStart().date() == event->dtEnd().date() )
1103 list.append( "0" ); 1076 list.append( "0" );
1104 else 1077 else
1105 list.append( "1" ); 1078 list.append( "1" );
1106 1079
1107 1080
1108 for(QStringList::Iterator it=list.begin(); 1081 for(QStringList::Iterator it=list.begin();
1109 it!=list.end(); ++it){ 1082 it!=list.end(); ++it){
1110 QString& s = (*it); 1083 QString& s = (*it);
1111 s.replace(QRegExp("\""), "\"\""); 1084 s.replace(QRegExp("\""), "\"\"");
1112 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1085 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1113 s.prepend('\"'); 1086 s.prepend('\"');
1114 s.append('\"'); 1087 s.append('\"');
1115 } else if(s.isEmpty() && !s.isNull()){ 1088 } else if(s.isEmpty() && !s.isNull()){
1116 s = "\"\""; 1089 s = "\"\"";
1117 } 1090 }
1118 } 1091 }
1119 return list.join(","); 1092 return list.join(",");
1120#endif 1093#endif
1121 return QString(); 1094 return QString();
1122 1095
1123} 1096}
1124QString PhoneFormat::getTodoString( Todo* todo ) 1097QString PhoneFormat::getTodoString( Todo* todo )
1125{ 1098{
1126#if 0 1099#if 0
1127 QStringList list; 1100 QStringList list;
1128 list.append( QString::number( todo->zaurusId() ) ); 1101 list.append( QString::number( todo->zaurusId() ) );
1129 list.append( todo->categories().join(",") ); 1102 list.append( todo->categories().join(",") );
1130 1103
1131 if ( todo->hasStartDate() ) { 1104 if ( todo->hasStartDate() ) {
1132 list.append( dtToString( todo->dtStart()) ); 1105 list.append( dtToString( todo->dtStart()) );
1133 } else 1106 } else
1134 list.append( QString() ); 1107 list.append( QString() );
1135 1108
1136 if ( todo->hasDueDate() ) { 1109 if ( todo->hasDueDate() ) {
1137 QTime tim; 1110 QTime tim;
1138 if ( todo->doesFloat()) { 1111 if ( todo->doesFloat()) {
1139 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 1112 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
1140 } else { 1113 } else {
1141 list.append( dtToString(todo->dtDue() ) ); 1114 list.append( dtToString(todo->dtDue() ) );
1142 } 1115 }
1143 } else 1116 } else
1144 list.append( QString() ); 1117 list.append( QString() );
1145 1118
1146 if ( todo->isCompleted() ) { 1119 if ( todo->isCompleted() ) {
1147 list.append( dtToString( todo->completed()) ); 1120 list.append( dtToString( todo->completed()) );
1148 list.append( "0" ); // yes 0 == completed 1121 list.append( "0" ); // yes 0 == completed
1149 } else { 1122 } else {
1150 list.append( dtToString( todo->completed()) ); 1123 list.append( dtToString( todo->completed()) );
1151 list.append( "1" ); 1124 list.append( "1" );
1152 } 1125 }
1153 list.append( QString::number( todo->priority() )); 1126 list.append( QString::number( todo->priority() ));
1154 if( ! todo->summary().isEmpty() ) 1127 if( ! todo->summary().isEmpty() )
1155 list.append( todo->summary() ); 1128 list.append( todo->summary() );
1156 else 1129 else
1157 list.append( "" ); 1130 list.append( "" );
1158 if (! todo->description().isEmpty() ) 1131 if (! todo->description().isEmpty() )
1159 list.append( todo->description() ); 1132 list.append( todo->description() );
1160 else 1133 else
1161 list.append( "" ); 1134 list.append( "" );
1162 for(QStringList::Iterator it=list.begin(); 1135 for(QStringList::Iterator it=list.begin();
1163 it!=list.end(); ++it){ 1136 it!=list.end(); ++it){
1164 QString& s = (*it); 1137 QString& s = (*it);
1165 s.replace(QRegExp("\""), "\"\""); 1138 s.replace(QRegExp("\""), "\"\"");
1166 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1139 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1167 s.prepend('\"'); 1140 s.prepend('\"');
1168 s.append('\"'); 1141 s.append('\"');
1169 } else if(s.isEmpty() && !s.isNull()){ 1142 } else if(s.isEmpty() && !s.isNull()){
1170 s = "\"\""; 1143 s = "\"\"";
1171 } 1144 }
1172 } 1145 }
1173 return list.join(","); 1146 return list.join(",");
1174#endif 1147#endif
1175 return QString(); 1148 return QString();
1176} 1149}
1177 1150
1178 1151
1179QString PhoneFormat::toString( Calendar * ) 1152QString PhoneFormat::toString( Calendar * )
1180{ 1153{
1181 return QString::null; 1154 return QString::null;
1182} 1155}
1183bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 1156bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
1184{ 1157{
1185 return false; 1158 return false;
1186} 1159}
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 8d4e200..1472880 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -1,60 +1,63 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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#ifndef PHONEFORMAT_H 21#ifndef PHONEFORMAT_H
22#define PHONEFORMAT_H 22#define PHONEFORMAT_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25 25
26#include "scheduler.h" 26#include "scheduler.h"
27 27
28#include "calformat.h" 28#include "calformat.h"
29extern "C" { 29extern "C" {
30#include "../gammu/emb/common/gammu.h" 30#include "../gammu/emb/common/gammu.h"
31} 31}
32
33namespace KCal { 32namespace KCal {
34 33
35/** 34/**
36 This class implements the calendar format used by Phone. 35 This class implements the calendar format used by Phone.
37*/ 36*/
38 37 class Event;
38 class Todo;
39class PhoneFormat : public QObject { 39class PhoneFormat : public QObject {
40 public: 40 public:
41 /** Create new iCalendar format. */ 41 /** Create new iCalendar format. */
42 PhoneFormat(); 42 PhoneFormat(QString profileName, QString device,QString connection, QString model);
43 virtual ~PhoneFormat(); 43 virtual ~PhoneFormat();
44 44
45 bool load( Calendar * ,Calendar *, QString profileName, QString device,QString connection, QString model ); 45 bool load( Calendar * ,Calendar * );
46 bool save( Calendar * ); 46 bool save( Calendar * );
47 bool fromString( Calendar *, const QString & ); 47 bool fromString( Calendar *, const QString & );
48 QString toString( Calendar * ); 48 QString toString( Calendar * );
49 static ulong getCsum( const QStringList & ); 49 static ulong getCsum( const QStringList & );
50 50
51 private: 51 private:
52 void event2GSM( Event* ev, GSM_CalendarEntry*Note );
53 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
54 int initDevice(GSM_StateMachine *s);
52 QString getEventString( Event* ); 55 QString getEventString( Event* );
53 QString getTodoString( Todo* ); 56 QString getTodoString( Todo* );
54 QString dtToGSM( const QDateTime& dt, bool useTZ = true ); 57 QString dtToGSM( const QDateTime& dt, bool useTZ = true );
55 QString mProfileName; 58 QString mProfileName, mDevice, mConnection, mModel;
56}; 59};
57 60
58} 61}
59 62
60#endif 63#endif