summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp5
-rw-r--r--libkdepim/ksyncmanager.cpp16
2 files changed, 15 insertions, 6 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index e4c067e..ea9607d 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3234 +1,3233 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130
130#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
131#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
132#endif 133#endif
133using namespace KOrg; 134using namespace KOrg;
134using namespace KCal; 135using namespace KCal;
135extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
136extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
137 138
138 139
139 140
140class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
141{ 142{
142 public: 143 public:
143 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
144 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
145 { 146 {
146 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
147 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
148 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
149 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
150 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
151 lay->addWidget( format ); 152 lay->addWidget( format );
152 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
153 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
154 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
155 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
156 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
157 vcal->setChecked( true ); 158 vcal->setChecked( true );
158 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
159 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
160 tz->setChecked( true );#ifdef DESKTOP_VERSION 161 tz->setChecked( true );
161#include <kabc/stdaddressbook.h>
162#endif
163 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
164 lay->addWidget( ok ); 163 lay->addWidget( ok );
165 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
166 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
167 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
168 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
169 resize( 200, 200 ); 168 resize( 200, 200 );
170 } 169 }
171 170
172 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
173 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
174private: 173private:
175 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
176}; 175};
177class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
178{ 177{
179 public: 178 public:
180 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
181 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
182 { 181 {
183 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
184 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
185 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
186 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
187 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
188 lay->addWidget( lab ); 187 lay->addWidget( lab );
189 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
190 lay->addWidget( format ); 189 lay->addWidget( format );
191 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
192 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
193 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
194 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
195 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
196 lay->addWidget( ok ); 195 lay->addWidget( ok );
197 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
198 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
199 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
200 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
201 resize( 200, 200 ); 200 resize( 200, 200 );
202 } 201 }
203 202
204 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
205private: 204private:
206 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
207}; 206};
208 207
209 208
210 209
211CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
212 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
213 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
214 mCalendar( calendar ), 213 mCalendar( calendar ),
215 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
216{ 215{
217 216
218 mEventEditor = 0; 217 mEventEditor = 0;
219 mTodoEditor = 0; 218 mTodoEditor = 0;
220 219
221 init(); 220 init();
222} 221}
223 222
224CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
225 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
226 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
227 mCalendar( calendar ), 226 mCalendar( calendar ),
228 mResourceManager( 0 ) 227 mResourceManager( 0 )
229{ 228{
230 229
231 mEventEditor = 0; 230 mEventEditor = 0;
232 mTodoEditor = 0; 231 mTodoEditor = 0;
233 init();} 232 init();}
234 233
235void CalendarView::init() 234void CalendarView::init()
236{ 235{
237 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
238 mDatePickerMode = 0; 237 mDatePickerMode = 0;
239 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
240 writeLocale(); 239 writeLocale();
241 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
242 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
243 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
244 mModified = false; 243 mModified = false;
245 mReadOnly = false; 244 mReadOnly = false;
246 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
247 mCalPrinter = 0; 246 mCalPrinter = 0;
248 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
249 248
250 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
251 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
252 251
253 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
254 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
255 254
256 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
257#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
258 // create the main layout frames. 257 // create the main layout frames.
259 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
260 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
261 260
262 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
263 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
264 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
265 264
266 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
267 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
268 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
269 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
270 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
271 270
272#ifdef KORG_NORESOURCEVIEW 271#ifdef KORG_NORESOURCEVIEW
273 mResourceView = 0; 272 mResourceView = 0;
274#else 273#else
275 if ( mResourceManager ) { 274 if ( mResourceManager ) {
276 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
277 mResourceView->updateView(); 276 mResourceView->updateView();
278 connect( mResourceView, SIGNAL( resourcesChanged() ), 277 connect( mResourceView, SIGNAL( resourcesChanged() ),
279 SLOT( updateView() ) ); 278 SLOT( updateView() ) );
280 } else { 279 } else {
281 mResourceView = 0; 280 mResourceView = 0;
282 } 281 }
283#endif 282#endif
284 QWidget *rightBox = new QWidget( mPanner ); 283 QWidget *rightBox = new QWidget( mPanner );
285 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
286 285
287 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
288 rightLayout->addWidget( mNavigatorBar ); 287 rightLayout->addWidget( mNavigatorBar );
289 288
290 mRightFrame = new QWidgetStack( rightBox ); 289 mRightFrame = new QWidgetStack( rightBox );
291 rightLayout->addWidget( mRightFrame, 1 ); 290 rightLayout->addWidget( mRightFrame, 1 );
292 291
293 mLeftFrame = mLeftSplitter; 292 mLeftFrame = mLeftSplitter;
294#else 293#else
295 QWidget *mainBox = new QWidget( this ); 294 QWidget *mainBox = new QWidget( this );
296 QWidget *leftFrame = new QWidget( mainBox ); 295 QWidget *leftFrame = new QWidget( mainBox );
297 296
298 QBoxLayout * mainBoxLayout; 297 QBoxLayout * mainBoxLayout;
299 QBoxLayout * leftFrameLayout; 298 QBoxLayout * leftFrameLayout;
300 if ( KOPrefs::instance()->mVerticalScreen ) { 299 if ( KOPrefs::instance()->mVerticalScreen ) {
301 mainBoxLayout = new QVBoxLayout(mainBox); 300 mainBoxLayout = new QVBoxLayout(mainBox);
302 leftFrameLayout = new QHBoxLayout(leftFrame ); 301 leftFrameLayout = new QHBoxLayout(leftFrame );
303 } else { 302 } else {
304 mainBoxLayout = new QHBoxLayout(mainBox); 303 mainBoxLayout = new QHBoxLayout(mainBox);
305 leftFrameLayout = new QVBoxLayout(leftFrame ); 304 leftFrameLayout = new QVBoxLayout(leftFrame );
306 } 305 }
307 topLayout->addWidget( mainBox ); 306 topLayout->addWidget( mainBox );
308 mainBoxLayout->addWidget (leftFrame); 307 mainBoxLayout->addWidget (leftFrame);
309 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
310 "CalendarView::DateNavigator", QDate::currentDate()); 309 "CalendarView::DateNavigator", QDate::currentDate());
311 // mDateNavigator->blockSignals( true ); 310 // mDateNavigator->blockSignals( true );
312 leftFrameLayout->addWidget( mDateNavigator ); 311 leftFrameLayout->addWidget( mDateNavigator );
313 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
314 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); 313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist");
315 314
316 if ( QApplication::desktop()->width() < 480 ) { 315 if ( QApplication::desktop()->width() < 480 ) {
317 leftFrameLayout->addWidget(mFilterView); 316 leftFrameLayout->addWidget(mFilterView);
318 leftFrameLayout->addWidget(mTodoList, 2 ); 317 leftFrameLayout->addWidget(mTodoList, 2 );
319 318
320 } else { 319 } else {
321 leftFrameLayout->addWidget(mTodoList,2 ); 320 leftFrameLayout->addWidget(mTodoList,2 );
322 leftFrameLayout->addWidget(mFilterView ); 321 leftFrameLayout->addWidget(mFilterView );
323 } 322 }
324 mFilterView->hide(); 323 mFilterView->hide();
325 QWidget *rightBox = new QWidget( mainBox ); 324 QWidget *rightBox = new QWidget( mainBox );
326 mainBoxLayout->addWidget ( rightBox, 10 ); 325 mainBoxLayout->addWidget ( rightBox, 10 );
327 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
328 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
329 mRightFrame = new QWidgetStack( rightBox ); 328 mRightFrame = new QWidgetStack( rightBox );
330 rightLayout->addWidget( mNavigatorBar ); 329 rightLayout->addWidget( mNavigatorBar );
331 rightLayout->addWidget( mRightFrame, 10 ); 330 rightLayout->addWidget( mRightFrame, 10 );
332 331
333 mLeftFrame = leftFrame; 332 mLeftFrame = leftFrame;
334 if ( KOPrefs::instance()->mVerticalScreen ) { 333 if ( KOPrefs::instance()->mVerticalScreen ) {
335 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
336 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
337 } else { 336 } else {
338 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
339 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
340 } 339 }
341 340
342 //qDebug("Calendarview Size %d %d ", width(), height()); 341 //qDebug("Calendarview Size %d %d ", width(), height());
343#endif 342#endif
344 343
345 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
346 SLOT( showDates( const KCal::DateList & ) ) ); 345 SLOT( showDates( const KCal::DateList & ) ) );
347 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
348 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
349 348
350 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 349 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
351 mNavigator, SLOT( selectPreviousYear() ) ); 350 mNavigator, SLOT( selectPreviousYear() ) );
352 connect( mNavigatorBar, SIGNAL( goNextYear() ), 351 connect( mNavigatorBar, SIGNAL( goNextYear() ),
353 mNavigator, SLOT( selectNextYear() ) ); 352 mNavigator, SLOT( selectNextYear() ) );
354 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
355 mNavigator, SLOT( selectPreviousMonth() ) ); 354 mNavigator, SLOT( selectPreviousMonth() ) );
356 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 355 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
357 mNavigator, SLOT( selectNextMonth() ) ); 356 mNavigator, SLOT( selectNextMonth() ) );
358 357
359 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
360 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
361 360
362 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
363 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 362 mNavigator, SLOT( selectWeek( const QDate & ) ) );
364 363
365 connect( mDateNavigator, SIGNAL( goPrevYear() ), 364 connect( mDateNavigator, SIGNAL( goPrevYear() ),
366 mNavigator, SLOT( selectPreviousYear() ) ); 365 mNavigator, SLOT( selectPreviousYear() ) );
367 connect( mDateNavigator, SIGNAL( goNextYear() ), 366 connect( mDateNavigator, SIGNAL( goNextYear() ),
368 mNavigator, SLOT( selectNextYear() ) ); 367 mNavigator, SLOT( selectNextYear() ) );
369 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 368 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
370 mNavigator, SLOT( selectPreviousMonth() ) ); 369 mNavigator, SLOT( selectPreviousMonth() ) );
371 connect( mDateNavigator, SIGNAL( goNextMonth() ), 370 connect( mDateNavigator, SIGNAL( goNextMonth() ),
372 mNavigator, SLOT( selectNextMonth() ) ); 371 mNavigator, SLOT( selectNextMonth() ) );
373 372
374 connect( mDateNavigator, SIGNAL( goPrevious() ), 373 connect( mDateNavigator, SIGNAL( goPrevious() ),
375 mNavigator, SLOT( selectPrevious() ) ); 374 mNavigator, SLOT( selectPrevious() ) );
376 connect( mDateNavigator, SIGNAL( goNext() ), 375 connect( mDateNavigator, SIGNAL( goNext() ),
377 mNavigator, SLOT( selectNext() ) ); 376 mNavigator, SLOT( selectNext() ) );
378 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
379 mNavigator, SLOT( slotMonthSelect( int ) ) ); 378 mNavigator, SLOT( slotMonthSelect( int ) ) );
380 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
381 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
382 381
383 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
384 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
385 384
386 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
387 SLOT( eventAdded( Event *) ) ); 386 SLOT( eventAdded( Event *) ) );
388 387
389 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
390 389
391 connect( this, SIGNAL( configChanged() ), 390 connect( this, SIGNAL( configChanged() ),
392 mDateNavigator, SLOT( updateConfig() ) ); 391 mDateNavigator, SLOT( updateConfig() ) );
393 392
394 connect( mTodoList, SIGNAL( newTodoSignal() ), 393 connect( mTodoList, SIGNAL( newTodoSignal() ),
395 SLOT( newTodo() ) ); 394 SLOT( newTodo() ) );
396 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
397 SLOT( newSubTodo( Todo * ) ) ); 396 SLOT( newSubTodo( Todo * ) ) );
398 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
399 SLOT( editTodo( Todo * ) ) ); 398 SLOT( editTodo( Todo * ) ) );
400 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
401 SLOT( showTodo( Todo *) ) ); 400 SLOT( showTodo( Todo *) ) );
402 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
403 SLOT( deleteTodo( Todo *) ) ); 402 SLOT( deleteTodo( Todo *) ) );
404 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
405 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
406 SLOT( purgeCompleted() ) ); 405 SLOT( purgeCompleted() ) );
407 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
408 SIGNAL( todoModified( Todo *, int ) ) ); 407 SIGNAL( todoModified( Todo *, int ) ) );
409 408
410 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
411 this, SLOT ( cloneIncidence( Incidence * ) ) ); 410 this, SLOT ( cloneIncidence( Incidence * ) ) );
412 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
413 this, SLOT (cancelIncidence( Incidence * ) ) ); 412 this, SLOT (cancelIncidence( Incidence * ) ) );
414 413
415 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
416 this, SLOT ( moveIncidence( Incidence * ) ) ); 415 this, SLOT ( moveIncidence( Incidence * ) ) );
417 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
418 this, SLOT ( beamIncidence( Incidence * ) ) ); 417 this, SLOT ( beamIncidence( Incidence * ) ) );
419 418
420 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
421 this, SLOT ( todo_unsub( Todo * ) ) ); 420 this, SLOT ( todo_unsub( Todo * ) ) );
422 421
423 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 422 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
424 SLOT( updateTodo( Todo *, int ) ) ); 423 SLOT( updateTodo( Todo *, int ) ) );
425 connect( this, SIGNAL( todoModified( Todo *, int )), this, 424 connect( this, SIGNAL( todoModified( Todo *, int )), this,
426 SLOT( changeTodoDisplay( Todo *, int ) ) ); 425 SLOT( changeTodoDisplay( Todo *, int ) ) );
427 426
428 427
429 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 428 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
430 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 429 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
431 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 430 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
432 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 431 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
433 432
434 433
435 434
436 435
437 436
438 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 437 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
439 SLOT(checkClipboard())); 438 SLOT(checkClipboard()));
440 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 439 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
441 SLOT( processTodoListSelection( Incidence * ) ) ); 440 SLOT( processTodoListSelection( Incidence * ) ) );
442 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 441 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
443 442
444 // kdDebug() << "CalendarView::CalendarView() done" << endl; 443 // kdDebug() << "CalendarView::CalendarView() done" << endl;
445 444
446 mDateFrame = new QVBox(0,0,WType_Popup); 445 mDateFrame = new QVBox(0,0,WType_Popup);
447 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 446 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
448 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 447 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
449 mDateFrame->setLineWidth(3); 448 mDateFrame->setLineWidth(3);
450 mDateFrame->hide(); 449 mDateFrame->hide();
451 mDateFrame->setCaption( i18n( "Pick a date to display")); 450 mDateFrame->setCaption( i18n( "Pick a date to display"));
452 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 451 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
453 452
454 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 453 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
455 454
456 mEventEditor = mDialogManager->getEventEditor(); 455 mEventEditor = mDialogManager->getEventEditor();
457 mTodoEditor = mDialogManager->getTodoEditor(); 456 mTodoEditor = mDialogManager->getTodoEditor();
458 457
459 mFlagEditDescription = false; 458 mFlagEditDescription = false;
460 459
461 mSuspendTimer = new QTimer( this ); 460 mSuspendTimer = new QTimer( this );
462 mAlarmTimer = new QTimer( this ); 461 mAlarmTimer = new QTimer( this );
463 mRecheckAlarmTimer = new QTimer( this ); 462 mRecheckAlarmTimer = new QTimer( this );
464 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 463 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
465 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 464 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
466 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 465 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
467 mAlarmDialog = new AlarmDialog( this ); 466 mAlarmDialog = new AlarmDialog( this );
468 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 467 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
469 mAlarmDialog->setServerNotification( false ); 468 mAlarmDialog->setServerNotification( false );
470 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 469 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
471 470
472 471
473#ifndef DESKTOP_VERSION 472#ifndef DESKTOP_VERSION
474//US listen for arriving address resultsets 473//US listen for arriving address resultsets
475 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 474 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
476 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 475 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
477#endif 476#endif
478 477
479} 478}
480 479
481 480
482CalendarView::~CalendarView() 481CalendarView::~CalendarView()
483{ 482{
484 // kdDebug() << "~CalendarView()" << endl; 483 // kdDebug() << "~CalendarView()" << endl;
485 //qDebug("CalendarView::~CalendarView() "); 484 //qDebug("CalendarView::~CalendarView() ");
486 delete mDialogManager; 485 delete mDialogManager;
487 delete mViewManager; 486 delete mViewManager;
488 delete mStorage; 487 delete mStorage;
489 delete mDateFrame ; 488 delete mDateFrame ;
490 delete beamDialog; 489 delete beamDialog;
491 //kdDebug() << "~CalendarView() done" << endl; 490 //kdDebug() << "~CalendarView() done" << endl;
492} 491}
493void CalendarView::timerAlarm() 492void CalendarView::timerAlarm()
494{ 493{
495 //qDebug("CalendarView::timerAlarm() "); 494 //qDebug("CalendarView::timerAlarm() ");
496 computeAlarm(mAlarmNotification ); 495 computeAlarm(mAlarmNotification );
497} 496}
498 497
499void CalendarView::suspendAlarm() 498void CalendarView::suspendAlarm()
500{ 499{
501 //qDebug(" CalendarView::suspendAlarm() "); 500 //qDebug(" CalendarView::suspendAlarm() ");
502 computeAlarm(mSuspendAlarmNotification ); 501 computeAlarm(mSuspendAlarmNotification );
503 502
504} 503}
505 504
506void CalendarView::startAlarm( QString mess , QString filename) 505void CalendarView::startAlarm( QString mess , QString filename)
507{ 506{
508 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 507 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
509 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 508 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
510 509
511} 510}
512 511
513void CalendarView::checkNextTimerAlarm() 512void CalendarView::checkNextTimerAlarm()
514{ 513{
515 mCalendar->checkAlarmForIncidence( 0, true ); 514 mCalendar->checkAlarmForIncidence( 0, true );
516} 515}
517 516
518void CalendarView::computeAlarm( QString msg ) 517void CalendarView::computeAlarm( QString msg )
519{ 518{
520 519
521 QString mess = msg; 520 QString mess = msg;
522 QString mAlarmMessage = mess.mid( 9 ); 521 QString mAlarmMessage = mess.mid( 9 );
523 QString filename = MainWindow::resourcePath(); 522 QString filename = MainWindow::resourcePath();
524 filename += "koalarm.wav"; 523 filename += "koalarm.wav";
525 QString tempfilename; 524 QString tempfilename;
526 if ( mess.left( 13 ) == "suspend_alarm") { 525 if ( mess.left( 13 ) == "suspend_alarm") {
527 bool error = false; 526 bool error = false;
528 int len = mess.mid( 13 ).find("+++"); 527 int len = mess.mid( 13 ).find("+++");
529 if ( len < 2 ) 528 if ( len < 2 )
530 error = true; 529 error = true;
531 else { 530 else {
532 tempfilename = mess.mid( 13, len ); 531 tempfilename = mess.mid( 13, len );
533 if ( !QFile::exists( tempfilename ) ) 532 if ( !QFile::exists( tempfilename ) )
534 error = true; 533 error = true;
535 } 534 }
536 if ( ! error ) { 535 if ( ! error ) {
537 filename = tempfilename; 536 filename = tempfilename;
538 } 537 }
539 mAlarmMessage = mess.mid( 13+len+3 ); 538 mAlarmMessage = mess.mid( 13+len+3 );
540 //qDebug("suspend file %s ",tempfilename.latin1() ); 539 //qDebug("suspend file %s ",tempfilename.latin1() );
541 startAlarm( mAlarmMessage, filename); 540 startAlarm( mAlarmMessage, filename);
542 return; 541 return;
543 } 542 }
544 if ( mess.left( 11 ) == "timer_alarm") { 543 if ( mess.left( 11 ) == "timer_alarm") {
545 //mTimerTime = 0; 544 //mTimerTime = 0;
546 startAlarm( mess.mid( 11 ), filename ); 545 startAlarm( mess.mid( 11 ), filename );
547 return; 546 return;
548 } 547 }
549 if ( mess.left( 10 ) == "proc_alarm") { 548 if ( mess.left( 10 ) == "proc_alarm") {
550 bool error = false; 549 bool error = false;
551 int len = mess.mid( 10 ).find("+++"); 550 int len = mess.mid( 10 ).find("+++");
552 if ( len < 2 ) 551 if ( len < 2 )
553 error = true; 552 error = true;
554 else { 553 else {
555 tempfilename = mess.mid( 10, len ); 554 tempfilename = mess.mid( 10, len );
556 if ( !QFile::exists( tempfilename ) ) 555 if ( !QFile::exists( tempfilename ) )
557 error = true; 556 error = true;
558 } 557 }
559 if ( error ) { 558 if ( error ) {
560 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 559 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
561 mAlarmMessage += mess.mid( 10+len+3+9 ); 560 mAlarmMessage += mess.mid( 10+len+3+9 );
562 } else { 561 } else {
563 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 562 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
564 //qDebug("-----system command %s ",tempfilename.latin1() ); 563 //qDebug("-----system command %s ",tempfilename.latin1() );
565#ifndef _WIN32_ 564#ifndef _WIN32_
566 if ( vfork () == 0 ) { 565 if ( vfork () == 0 ) {
567 execl ( tempfilename.latin1(), 0 ); 566 execl ( tempfilename.latin1(), 0 );
568 return; 567 return;
569 } 568 }
570#else 569#else
571 QProcess* p = new QProcess(); 570 QProcess* p = new QProcess();
572 p->addArgument( tempfilename.latin1() ); 571 p->addArgument( tempfilename.latin1() );
573 p->start(); 572 p->start();
574 return; 573 return;
575#endif 574#endif
576 575
577 return; 576 return;
578 } 577 }
579 578
580 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 579 //qDebug("+++++++system command %s ",tempfilename.latin1() );
581 } 580 }
582 if ( mess.left( 11 ) == "audio_alarm") { 581 if ( mess.left( 11 ) == "audio_alarm") {
583 bool error = false; 582 bool error = false;
584 int len = mess.mid( 11 ).find("+++"); 583 int len = mess.mid( 11 ).find("+++");
585 if ( len < 2 ) 584 if ( len < 2 )
586 error = true; 585 error = true;
587 else { 586 else {
588 tempfilename = mess.mid( 11, len ); 587 tempfilename = mess.mid( 11, len );
589 if ( !QFile::exists( tempfilename ) ) 588 if ( !QFile::exists( tempfilename ) )
590 error = true; 589 error = true;
591 } 590 }
592 if ( ! error ) { 591 if ( ! error ) {
593 filename = tempfilename; 592 filename = tempfilename;
594 } 593 }
595 mAlarmMessage = mess.mid( 11+len+3+9 ); 594 mAlarmMessage = mess.mid( 11+len+3+9 );
596 //qDebug("audio file command %s ",tempfilename.latin1() ); 595 //qDebug("audio file command %s ",tempfilename.latin1() );
597 } 596 }
598 if ( mess.left( 9 ) == "cal_alarm") { 597 if ( mess.left( 9 ) == "cal_alarm") {
599 mAlarmMessage = mess.mid( 9 ) ; 598 mAlarmMessage = mess.mid( 9 ) ;
600 } 599 }
601 600
602 startAlarm( mAlarmMessage, filename ); 601 startAlarm( mAlarmMessage, filename );
603 602
604 603
605} 604}
606 605
607void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 606void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
608{ 607{
609 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 608 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
610 609
611 mSuspendAlarmNotification = noti; 610 mSuspendAlarmNotification = noti;
612 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 611 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
613 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 612 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
614 mSuspendTimer->start( ms , true ); 613 mSuspendTimer->start( ms , true );
615 614
616} 615}
617 616
618void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 617void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
619{ 618{
620 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 619 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
621 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 620 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
622#ifndef DESKTOP_VERSION 621#ifndef DESKTOP_VERSION
623 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 622 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
624#endif 623#endif
625 return; 624 return;
626 } 625 }
627 int maxSec; 626 int maxSec;
628 //maxSec = 5; //testing only 627 //maxSec = 5; //testing only
629 maxSec = 86400+3600; // one day+1hour 628 maxSec = 86400+3600; // one day+1hour
630 mAlarmNotification = noti; 629 mAlarmNotification = noti;
631 int sec = QDateTime::currentDateTime().secsTo( qdt ); 630 int sec = QDateTime::currentDateTime().secsTo( qdt );
632 if ( sec > maxSec ) { 631 if ( sec > maxSec ) {
633 mRecheckAlarmTimer->start( maxSec * 1000 ); 632 mRecheckAlarmTimer->start( maxSec * 1000 );
634 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 633 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
635 return; 634 return;
636 } else { 635 } else {
637 mRecheckAlarmTimer->stop(); 636 mRecheckAlarmTimer->stop();
638 } 637 }
639 //qDebug("Alarm timer started with secs: %d ", sec); 638 //qDebug("Alarm timer started with secs: %d ", sec);
640 mAlarmTimer->start( sec *1000 , true ); 639 mAlarmTimer->start( sec *1000 , true );
641 640
642} 641}
643// called by mRecheckAlarmTimer to get next alarm 642// called by mRecheckAlarmTimer to get next alarm
644// we need this, because a QTimer has only a max range of 25 days 643// we need this, because a QTimer has only a max range of 25 days
645void CalendarView::recheckTimerAlarm() 644void CalendarView::recheckTimerAlarm()
646{ 645{
647 mAlarmTimer->stop(); 646 mAlarmTimer->stop();
648 mRecheckAlarmTimer->stop(); 647 mRecheckAlarmTimer->stop();
649 mCalendar->checkAlarmForIncidence( 0, true ); 648 mCalendar->checkAlarmForIncidence( 0, true );
650} 649}
651void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 650void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
652{ 651{
653 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 652 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
654 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 653 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
655#ifndef DESKTOP_VERSION 654#ifndef DESKTOP_VERSION
656 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 655 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
657#endif 656#endif
658 return; 657 return;
659 } 658 }
660 mAlarmTimer->stop(); 659 mAlarmTimer->stop();
661} 660}
662void CalendarView::selectWeekNum ( int num ) 661void CalendarView::selectWeekNum ( int num )
663{ 662{
664 dateNavigator()->selectWeek( num ); 663 dateNavigator()->selectWeek( num );
665 mViewManager->showWeekView(); 664 mViewManager->showWeekView();
666} 665}
667KOViewManager *CalendarView::viewManager() 666KOViewManager *CalendarView::viewManager()
668{ 667{
669 return mViewManager; 668 return mViewManager;
670} 669}
671 670
672KODialogManager *CalendarView::dialogManager() 671KODialogManager *CalendarView::dialogManager()
673{ 672{
674 return mDialogManager; 673 return mDialogManager;
675} 674}
676 675
677QDate CalendarView::startDate() 676QDate CalendarView::startDate()
678{ 677{
679 DateList dates = mNavigator->selectedDates(); 678 DateList dates = mNavigator->selectedDates();
680 679
681 return dates.first(); 680 return dates.first();
682} 681}
683 682
684QDate CalendarView::endDate() 683QDate CalendarView::endDate()
685{ 684{
686 DateList dates = mNavigator->selectedDates(); 685 DateList dates = mNavigator->selectedDates();
687 686
688 return dates.last(); 687 return dates.last();
689} 688}
690 689
691 690
692void CalendarView::createPrinter() 691void CalendarView::createPrinter()
693{ 692{
694#ifndef KORG_NOPRINTER 693#ifndef KORG_NOPRINTER
695 if (!mCalPrinter) { 694 if (!mCalPrinter) {
696 mCalPrinter = new CalPrinter(this, mCalendar); 695 mCalPrinter = new CalPrinter(this, mCalendar);
697 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 696 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
698 } 697 }
699#endif 698#endif
700} 699}
701 700
702void CalendarView::confSync() 701void CalendarView::confSync()
703{ 702{
704 static KSyncPrefsDialog* sp = 0; 703 static KSyncPrefsDialog* sp = 0;
705 if ( ! sp ) { 704 if ( ! sp ) {
706 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 705 sp = new KSyncPrefsDialog( this, "syncprefs", true );
707 } 706 }
708 sp->usrReadConfig(); 707 sp->usrReadConfig();
709#ifndef DESKTOP_VERSION 708#ifndef DESKTOP_VERSION
710 sp->showMaximized(); 709 sp->showMaximized();
711#else 710#else
712 sp->show(); 711 sp->show();
713#endif 712#endif
714 sp->exec(); 713 sp->exec();
715 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 714 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
716 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 715 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
717} 716}
718 717
719 718
720//KOPrefs::instance()->mWriteBackFile 719//KOPrefs::instance()->mWriteBackFile
721//KOPrefs::instance()->mWriteBackExistingOnly 720//KOPrefs::instance()->mWriteBackExistingOnly
722 721
723// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 722// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
724// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 723// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
725// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 724// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
726// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 725// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
727// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 726// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
728// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 727// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
729 728
730int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 729int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
731{ 730{
732 731
733 //void setZaurusId(int id); 732 //void setZaurusId(int id);
734 // int zaurusId() const; 733 // int zaurusId() const;
735 // void setZaurusUid(int id); 734 // void setZaurusUid(int id);
736 // int zaurusUid() const; 735 // int zaurusUid() const;
737 // void setZaurusStat(int id); 736 // void setZaurusStat(int id);
738 // int zaurusStat() const; 737 // int zaurusStat() const;
739 // 0 equal 738 // 0 equal
740 // 1 take local 739 // 1 take local
741 // 2 take remote 740 // 2 take remote
742 // 3 cancel 741 // 3 cancel
743 QDateTime lastSync = mLastCalendarSync; 742 QDateTime lastSync = mLastCalendarSync;
744 QDateTime localMod = local->lastModified(); 743 QDateTime localMod = local->lastModified();
745 QDateTime remoteMod = remote->lastModified(); 744 QDateTime remoteMod = remote->lastModified();
746 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 745 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
747 bool remCh, locCh; 746 bool remCh, locCh;
748 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 747 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
749 //if ( remCh ) 748 //if ( remCh )
750 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 749 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
751 locCh = ( localMod > mLastCalendarSync ); 750 locCh = ( localMod > mLastCalendarSync );
752 if ( !remCh && ! locCh ) { 751 if ( !remCh && ! locCh ) {
753 //qDebug("both not changed "); 752 //qDebug("both not changed ");
754 lastSync = localMod.addDays(1); 753 lastSync = localMod.addDays(1);
755 if ( mode <= SYNC_PREF_ASK ) 754 if ( mode <= SYNC_PREF_ASK )
756 return 0; 755 return 0;
757 } else { 756 } else {
758 if ( locCh ) { 757 if ( locCh ) {
759 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 758 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
760 lastSync = localMod.addDays( -1 ); 759 lastSync = localMod.addDays( -1 );
761 if ( !remCh ) 760 if ( !remCh )
762 remoteMod = ( lastSync.addDays( -1 ) ); 761 remoteMod = ( lastSync.addDays( -1 ) );
763 } else { 762 } else {
764 //qDebug(" not loc changed "); 763 //qDebug(" not loc changed ");
765 lastSync = localMod.addDays( 1 ); 764 lastSync = localMod.addDays( 1 );
766 if ( remCh ) 765 if ( remCh )
767 remoteMod =( lastSync.addDays( 1 ) ); 766 remoteMod =( lastSync.addDays( 1 ) );
768 767
769 } 768 }
770 } 769 }
771 full = true; 770 full = true;
772 if ( mode < SYNC_PREF_ASK ) 771 if ( mode < SYNC_PREF_ASK )
773 mode = SYNC_PREF_ASK; 772 mode = SYNC_PREF_ASK;
774 } else { 773 } else {
775 if ( localMod == remoteMod ) 774 if ( localMod == remoteMod )
776 if ( local->revision() == remote->revision() ) 775 if ( local->revision() == remote->revision() )
777 return 0; 776 return 0;
778 777
779 } 778 }
780 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 779 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
781 780
782 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 781 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
783 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 782 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
784 //full = true; //debug only 783 //full = true; //debug only
785 if ( full ) { 784 if ( full ) {
786 bool equ = false; 785 bool equ = false;
787 if ( local->type() == "Event" ) { 786 if ( local->type() == "Event" ) {
788 equ = (*((Event*) local) == *((Event*) remote)); 787 equ = (*((Event*) local) == *((Event*) remote));
789 } 788 }
790 else if ( local->type() =="Todo" ) 789 else if ( local->type() =="Todo" )
791 equ = (*((Todo*) local) == (*(Todo*) remote)); 790 equ = (*((Todo*) local) == (*(Todo*) remote));
792 else if ( local->type() =="Journal" ) 791 else if ( local->type() =="Journal" )
793 equ = (*((Journal*) local) == *((Journal*) remote)); 792 equ = (*((Journal*) local) == *((Journal*) remote));
794 if ( equ ) { 793 if ( equ ) {
795 //qDebug("equal "); 794 //qDebug("equal ");
796 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 795 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
797 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 796 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
798 } 797 }
799 if ( mode < SYNC_PREF_FORCE_LOCAL ) 798 if ( mode < SYNC_PREF_FORCE_LOCAL )
800 return 0; 799 return 0;
801 800
802 }//else //debug only 801 }//else //debug only
803 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 802 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
804 } 803 }
805 int result; 804 int result;
806 bool localIsNew; 805 bool localIsNew;
807 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 806 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
808 807
809 if ( full && mode < SYNC_PREF_NEWEST ) 808 if ( full && mode < SYNC_PREF_NEWEST )
810 mode = SYNC_PREF_ASK; 809 mode = SYNC_PREF_ASK;
811 810
812 switch( mode ) { 811 switch( mode ) {
813 case SYNC_PREF_LOCAL: 812 case SYNC_PREF_LOCAL:
814 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
815 return 1; 814 return 1;
816 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
817 return 2; 816 return 2;
818 return 1; 817 return 1;
819 break; 818 break;
820 case SYNC_PREF_REMOTE: 819 case SYNC_PREF_REMOTE:
821 if ( lastSync > remoteMod ) 820 if ( lastSync > remoteMod )
822 return 1; 821 return 1;
823 if ( lastSync > localMod ) 822 if ( lastSync > localMod )
824 return 2; 823 return 2;
825 return 2; 824 return 2;
826 break; 825 break;
827 case SYNC_PREF_NEWEST: 826 case SYNC_PREF_NEWEST:
828 if ( localMod > remoteMod ) 827 if ( localMod > remoteMod )
829 return 1; 828 return 1;
830 else 829 else
831 return 2; 830 return 2;
832 break; 831 break;
833 case SYNC_PREF_ASK: 832 case SYNC_PREF_ASK:
834 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 833 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
835 if ( lastSync > remoteMod ) 834 if ( lastSync > remoteMod )
836 return 1; 835 return 1;
837 if ( lastSync > localMod ) 836 if ( lastSync > localMod )
838 return 2; 837 return 2;
839 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 838 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
840 localIsNew = localMod >= remoteMod; 839 localIsNew = localMod >= remoteMod;
841 if ( localIsNew ) 840 if ( localIsNew )
842 getEventViewerDialog()->setColorMode( 1 ); 841 getEventViewerDialog()->setColorMode( 1 );
843 else 842 else
844 getEventViewerDialog()->setColorMode( 2 ); 843 getEventViewerDialog()->setColorMode( 2 );
845 getEventViewerDialog()->setIncidence(local); 844 getEventViewerDialog()->setIncidence(local);
846 if ( localIsNew ) 845 if ( localIsNew )
847 getEventViewerDialog()->setColorMode( 2 ); 846 getEventViewerDialog()->setColorMode( 2 );
848 else 847 else
849 getEventViewerDialog()->setColorMode( 1 ); 848 getEventViewerDialog()->setColorMode( 1 );
850 getEventViewerDialog()->addIncidence(remote); 849 getEventViewerDialog()->addIncidence(remote);
851 getEventViewerDialog()->setColorMode( 0 ); 850 getEventViewerDialog()->setColorMode( 0 );
852 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 851 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
853 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 852 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
854 getEventViewerDialog()->showMe(); 853 getEventViewerDialog()->showMe();
855 result = getEventViewerDialog()->executeS( localIsNew ); 854 result = getEventViewerDialog()->executeS( localIsNew );
856 return result; 855 return result;
857 856
858 break; 857 break;
859 case SYNC_PREF_FORCE_LOCAL: 858 case SYNC_PREF_FORCE_LOCAL:
860 return 1; 859 return 1;
861 break; 860 break;
862 case SYNC_PREF_FORCE_REMOTE: 861 case SYNC_PREF_FORCE_REMOTE:
863 return 2; 862 return 2;
864 break; 863 break;
865 864
866 default: 865 default:
867 // SYNC_PREF_TAKE_BOTH not implemented 866 // SYNC_PREF_TAKE_BOTH not implemented
868 break; 867 break;
869 } 868 }
870 return 0; 869 return 0;
871} 870}
872Event* CalendarView::getLastSyncEvent() 871Event* CalendarView::getLastSyncEvent()
873{ 872{
874 Event* lse; 873 Event* lse;
875 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 874 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
876 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 875 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
877 if (!lse) { 876 if (!lse) {
878 lse = new Event(); 877 lse = new Event();
879 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 878 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
880 QString sum = ""; 879 QString sum = "";
881 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 880 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
882 sum = "E: "; 881 sum = "E: ";
883 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 882 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
884 lse->setDtStart( mLastCalendarSync ); 883 lse->setDtStart( mLastCalendarSync );
885 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 884 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
886 lse->setCategories( i18n("SyncEvent") ); 885 lse->setCategories( i18n("SyncEvent") );
887 lse->setReadOnly( true ); 886 lse->setReadOnly( true );
888 mCalendar->addEvent( lse ); 887 mCalendar->addEvent( lse );
889 } 888 }
890 889
891 return lse; 890 return lse;
892 891
893} 892}
894 893
895// we check, if the to delete event has a id for a profile 894// we check, if the to delete event has a id for a profile
896// if yes, we set this id in the profile to delete 895// if yes, we set this id in the profile to delete
897void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 896void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
898{ 897{
899 if ( lastSync.count() == 0 ) { 898 if ( lastSync.count() == 0 ) {
900 //qDebug(" lastSync.count() == 0"); 899 //qDebug(" lastSync.count() == 0");
901 return; 900 return;
902 } 901 }
903 if ( toDelete->type() == "Journal" ) 902 if ( toDelete->type() == "Journal" )
904 return; 903 return;
905 904
906 Event* eve = lastSync.first(); 905 Event* eve = lastSync.first();
907 906
908 while ( eve ) { 907 while ( eve ) {
909 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 908 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
910 if ( !id.isEmpty() ) { 909 if ( !id.isEmpty() ) {
911 QString des = eve->description(); 910 QString des = eve->description();
912 QString pref = "e"; 911 QString pref = "e";
913 if ( toDelete->type() == "Todo" ) 912 if ( toDelete->type() == "Todo" )
914 pref = "t"; 913 pref = "t";
915 des += pref+ id + ","; 914 des += pref+ id + ",";
916 eve->setReadOnly( false ); 915 eve->setReadOnly( false );
917 eve->setDescription( des ); 916 eve->setDescription( des );
918 //qDebug("setdes %s ", des.latin1()); 917 //qDebug("setdes %s ", des.latin1());
919 eve->setReadOnly( true ); 918 eve->setReadOnly( true );
920 } 919 }
921 eve = lastSync.next(); 920 eve = lastSync.next();
922 } 921 }
923 922
924} 923}
925void CalendarView::checkExternalId( Incidence * inc ) 924void CalendarView::checkExternalId( Incidence * inc )
926{ 925{
927 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 926 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
928 checkExternSyncEvent( lastSync, inc ); 927 checkExternSyncEvent( lastSync, inc );
929 928
930} 929}
931bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 930bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
932{ 931{
933 bool syncOK = true; 932 bool syncOK = true;
934 int addedEvent = 0; 933 int addedEvent = 0;
935 int addedEventR = 0; 934 int addedEventR = 0;
936 int deletedEventR = 0; 935 int deletedEventR = 0;
937 int deletedEventL = 0; 936 int deletedEventL = 0;
938 int changedLocal = 0; 937 int changedLocal = 0;
939 int changedRemote = 0; 938 int changedRemote = 0;
940 //QPtrList<Event> el = local->rawEvents(); 939 //QPtrList<Event> el = local->rawEvents();
941 Event* eventR; 940 Event* eventR;
942 QString uid; 941 QString uid;
943 int take; 942 int take;
944 Event* eventL; 943 Event* eventL;
945 Event* eventRSync; 944 Event* eventRSync;
946 Event* eventLSync; 945 Event* eventLSync;
947 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 946 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
948 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 947 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
949 bool fullDateRange = false; 948 bool fullDateRange = false;
950 local->resetTempSyncStat(); 949 local->resetTempSyncStat();
951 mLastCalendarSync = QDateTime::currentDateTime(); 950 mLastCalendarSync = QDateTime::currentDateTime();
952 QDateTime modifiedCalendar = mLastCalendarSync;; 951 QDateTime modifiedCalendar = mLastCalendarSync;;
953 eventLSync = getLastSyncEvent(); 952 eventLSync = getLastSyncEvent();
954 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 953 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
955 if ( eventR ) { 954 if ( eventR ) {
956 eventRSync = (Event*) eventR->clone(); 955 eventRSync = (Event*) eventR->clone();
957 remote->deleteEvent(eventR ); 956 remote->deleteEvent(eventR );
958 957
959 } else { 958 } else {
960 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 959 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
961 eventRSync = (Event*)eventLSync->clone(); 960 eventRSync = (Event*)eventLSync->clone();
962 } else { 961 } else {
963 fullDateRange = true; 962 fullDateRange = true;
964 eventRSync = new Event(); 963 eventRSync = new Event();
965 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 964 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
966 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 965 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
967 eventRSync->setDtStart( mLastCalendarSync ); 966 eventRSync->setDtStart( mLastCalendarSync );
968 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 967 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
969 eventRSync->setCategories( i18n("SyncEvent") ); 968 eventRSync->setCategories( i18n("SyncEvent") );
970 } 969 }
971 } 970 }
972 if ( eventLSync->dtStart() == mLastCalendarSync ) 971 if ( eventLSync->dtStart() == mLastCalendarSync )
973 fullDateRange = true; 972 fullDateRange = true;
974 973
975 if ( ! fullDateRange ) { 974 if ( ! fullDateRange ) {
976 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 975 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
977 976
978 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 977 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
979 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 978 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
980 fullDateRange = true; 979 fullDateRange = true;
981 } 980 }
982 } 981 }
983 if ( fullDateRange ) 982 if ( fullDateRange )
984 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 983 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
985 else 984 else
986 mLastCalendarSync = eventLSync->dtStart(); 985 mLastCalendarSync = eventLSync->dtStart();
987 // for resyncing if own file has changed 986 // for resyncing if own file has changed
988 if ( mCurrentSyncDevice == "deleteaftersync" ) { 987 if ( mCurrentSyncDevice == "deleteaftersync" ) {
989 mLastCalendarSync = loadedFileVersion; 988 mLastCalendarSync = loadedFileVersion;
990 qDebug("setting mLastCalendarSync "); 989 qDebug("setting mLastCalendarSync ");
991 } 990 }
992 //qDebug("*************************** "); 991 //qDebug("*************************** ");
993 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 992 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
994 QPtrList<Incidence> er = remote->rawIncidences(); 993 QPtrList<Incidence> er = remote->rawIncidences();
995 Incidence* inR = er.first(); 994 Incidence* inR = er.first();
996 Incidence* inL; 995 Incidence* inL;
997 QProgressBar bar( er.count(),0 ); 996 QProgressBar bar( er.count(),0 );
998 bar.setCaption (i18n("Syncing - close to abort!") ); 997 bar.setCaption (i18n("Syncing - close to abort!") );
999 998
1000 int w = 300; 999 int w = 300;
1001 if ( QApplication::desktop()->width() < 320 ) 1000 if ( QApplication::desktop()->width() < 320 )
1002 w = 220; 1001 w = 220;
1003 int h = bar.sizeHint().height() ; 1002 int h = bar.sizeHint().height() ;
1004 int dw = QApplication::desktop()->width(); 1003 int dw = QApplication::desktop()->width();
1005 int dh = QApplication::desktop()->height(); 1004 int dh = QApplication::desktop()->height();
1006 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1005 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1007 bar.show(); 1006 bar.show();
1008 int modulo = (er.count()/10)+1; 1007 int modulo = (er.count()/10)+1;
1009 int incCounter = 0; 1008 int incCounter = 0;
1010 while ( inR ) { 1009 while ( inR ) {
1011 if ( ! bar.isVisible() ) 1010 if ( ! bar.isVisible() )
1012 return false; 1011 return false;
1013 if ( incCounter % modulo == 0 ) 1012 if ( incCounter % modulo == 0 )
1014 bar.setProgress( incCounter ); 1013 bar.setProgress( incCounter );
1015 ++incCounter; 1014 ++incCounter;
1016 uid = inR->uid(); 1015 uid = inR->uid();
1017 bool skipIncidence = false; 1016 bool skipIncidence = false;
1018 if ( uid.left(15) == QString("last-syncEvent-") ) 1017 if ( uid.left(15) == QString("last-syncEvent-") )
1019 skipIncidence = true; 1018 skipIncidence = true;
1020 QString idS; 1019 QString idS;
1021 qApp->processEvents(); 1020 qApp->processEvents();
1022 if ( !skipIncidence ) { 1021 if ( !skipIncidence ) {
1023 inL = local->incidence( uid ); 1022 inL = local->incidence( uid );
1024 if ( inL ) { // maybe conflict - same uid in both calendars 1023 if ( inL ) { // maybe conflict - same uid in both calendars
1025 int maxrev = inL->revision(); 1024 int maxrev = inL->revision();
1026 if ( maxrev < inR->revision() ) 1025 if ( maxrev < inR->revision() )
1027 maxrev = inR->revision(); 1026 maxrev = inR->revision();
1028 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1027 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1029 //qDebug("take %d %s ", take, inL->summary().latin1()); 1028 //qDebug("take %d %s ", take, inL->summary().latin1());
1030 if ( take == 3 ) 1029 if ( take == 3 )
1031 return false; 1030 return false;
1032 if ( take == 1 ) {// take local 1031 if ( take == 1 ) {// take local
1033 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1032 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1034 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1033 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1035 else 1034 else
1036 idS = inR->IDStr(); 1035 idS = inR->IDStr();
1037 remote->deleteIncidence( inR ); 1036 remote->deleteIncidence( inR );
1038 if ( inL->revision() < maxrev ) 1037 if ( inL->revision() < maxrev )
1039 inL->setRevision( maxrev ); 1038 inL->setRevision( maxrev );
1040 inR = inL->clone(); 1039 inR = inL->clone();
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1040 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1042 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1041 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1043 inR->setIDStr( idS ); 1042 inR->setIDStr( idS );
1044 remote->addIncidence( inR ); 1043 remote->addIncidence( inR );
1045 ++changedRemote; 1044 ++changedRemote;
1046 } else { 1045 } else {
1047 if ( inR->revision() < maxrev ) 1046 if ( inR->revision() < maxrev )
1048 inR->setRevision( maxrev ); 1047 inR->setRevision( maxrev );
1049 idS = inL->IDStr(); 1048 idS = inL->IDStr();
1050 local->deleteIncidence( inL ); 1049 local->deleteIncidence( inL );
1051 inL = inR->clone(); 1050 inL = inR->clone();
1052 inL->setIDStr( idS ); 1051 inL->setIDStr( idS );
1053 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1052 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1054 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1053 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1055 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1054 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1056 } 1055 }
1057 local->addIncidence( inL ); 1056 local->addIncidence( inL );
1058 ++changedLocal; 1057 ++changedLocal;
1059 } 1058 }
1060 } 1059 }
1061 } else { // no conflict 1060 } else { // no conflict
1062 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1061 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1063 QString des = eventLSync->description(); 1062 QString des = eventLSync->description();
1064 QString pref = "e"; 1063 QString pref = "e";
1065 if ( inR->type() == "Todo" ) 1064 if ( inR->type() == "Todo" )
1066 pref = "t"; 1065 pref = "t";
1067 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1066 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1068 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1067 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1069 //remote->deleteIncidence( inR ); 1068 //remote->deleteIncidence( inR );
1070 ++deletedEventR; 1069 ++deletedEventR;
1071 } else { 1070 } else {
1072 inR->setLastModified( modifiedCalendar ); 1071 inR->setLastModified( modifiedCalendar );
1073 inL = inR->clone(); 1072 inL = inR->clone();
1074 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1075 ++addedEvent; 1074 ++addedEvent;
1076 } 1075 }
1077 } else { 1076 } else {
1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1077 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1079 inR->setLastModified( modifiedCalendar ); 1078 inR->setLastModified( modifiedCalendar );
1080 local->addIncidence( inR->clone() ); 1079 local->addIncidence( inR->clone() );
1081 ++addedEvent; 1080 ++addedEvent;
1082 } else { 1081 } else {
1083 checkExternSyncEvent(eventRSyncSharp, inR); 1082 checkExternSyncEvent(eventRSyncSharp, inR);
1084 remote->deleteIncidence( inR ); 1083 remote->deleteIncidence( inR );
1085 ++deletedEventR; 1084 ++deletedEventR;
1086 } 1085 }
1087 } 1086 }
1088 } 1087 }
1089 } 1088 }
1090 inR = er.next(); 1089 inR = er.next();
1091 } 1090 }
1092 QPtrList<Incidence> el = local->rawIncidences(); 1091 QPtrList<Incidence> el = local->rawIncidences();
1093 inL = el.first(); 1092 inL = el.first();
1094 modulo = (el.count()/10)+1; 1093 modulo = (el.count()/10)+1;
1095 bar.setCaption (i18n("Add / remove events") ); 1094 bar.setCaption (i18n("Add / remove events") );
1096 bar.setTotalSteps ( el.count() ) ; 1095 bar.setTotalSteps ( el.count() ) ;
1097 bar.show(); 1096 bar.show();
1098 incCounter = 0; 1097 incCounter = 0;
1099 1098
1100 while ( inL ) { 1099 while ( inL ) {
1101 1100
1102 qApp->processEvents(); 1101 qApp->processEvents();
1103 if ( ! bar.isVisible() ) 1102 if ( ! bar.isVisible() )
1104 return false; 1103 return false;
1105 if ( incCounter % modulo == 0 ) 1104 if ( incCounter % modulo == 0 )
1106 bar.setProgress( incCounter ); 1105 bar.setProgress( incCounter );
1107 ++incCounter; 1106 ++incCounter;
1108 uid = inL->uid(); 1107 uid = inL->uid();
1109 bool skipIncidence = false; 1108 bool skipIncidence = false;
1110 if ( uid.left(15) == QString("last-syncEvent-") ) 1109 if ( uid.left(15) == QString("last-syncEvent-") )
1111 skipIncidence = true; 1110 skipIncidence = true;
1112 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1111 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1113 skipIncidence = true; 1112 skipIncidence = true;
1114 if ( !skipIncidence ) { 1113 if ( !skipIncidence ) {
1115 inR = remote->incidence( uid ); 1114 inR = remote->incidence( uid );
1116 if ( ! inR ) { 1115 if ( ! inR ) {
1117 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1116 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1118 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1117 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1119 checkExternSyncEvent(eventLSyncSharp, inL); 1118 checkExternSyncEvent(eventLSyncSharp, inL);
1120 local->deleteIncidence( inL ); 1119 local->deleteIncidence( inL );
1121 ++deletedEventL; 1120 ++deletedEventL;
1122 } else { 1121 } else {
1123 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1122 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1124 inL->removeID(mCurrentSyncDevice ); 1123 inL->removeID(mCurrentSyncDevice );
1125 ++addedEventR; 1124 ++addedEventR;
1126 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1125 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1127 inL->setLastModified( modifiedCalendar ); 1126 inL->setLastModified( modifiedCalendar );
1128 inR = inL->clone(); 1127 inR = inL->clone();
1129 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1128 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1130 remote->addIncidence( inR ); 1129 remote->addIncidence( inR );
1131 } 1130 }
1132 } 1131 }
1133 } else { 1132 } else {
1134 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1133 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1135 checkExternSyncEvent(eventLSyncSharp, inL); 1134 checkExternSyncEvent(eventLSyncSharp, inL);
1136 local->deleteIncidence( inL ); 1135 local->deleteIncidence( inL );
1137 ++deletedEventL; 1136 ++deletedEventL;
1138 } else { 1137 } else {
1139 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1138 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1140 ++addedEventR; 1139 ++addedEventR;
1141 inL->setLastModified( modifiedCalendar ); 1140 inL->setLastModified( modifiedCalendar );
1142 remote->addIncidence( inL->clone() ); 1141 remote->addIncidence( inL->clone() );
1143 } 1142 }
1144 } 1143 }
1145 } 1144 }
1146 } 1145 }
1147 } 1146 }
1148 inL = el.next(); 1147 inL = el.next();
1149 } 1148 }
1150 int delFut = 0; 1149 int delFut = 0;
1151 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1150 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1152 er = remote->rawIncidences(); 1151 er = remote->rawIncidences();
1153 inR = er.first(); 1152 inR = er.first();
1154 QDateTime dt; 1153 QDateTime dt;
1155 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1154 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1156 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); 1155 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 );
1157 while ( inR ) { 1156 while ( inR ) {
1158 if ( inR->type() == "Todo" ) { 1157 if ( inR->type() == "Todo" ) {
1159 Todo * t = (Todo*)inR; 1158 Todo * t = (Todo*)inR;
1160 if ( t->hasDueDate() ) 1159 if ( t->hasDueDate() )
1161 dt = t->dtDue(); 1160 dt = t->dtDue();
1162 else 1161 else
1163 dt = cur.addSecs( 62 ); 1162 dt = cur.addSecs( 62 );
1164 } 1163 }
1165 else if (inR->type() == "Event" ) { 1164 else if (inR->type() == "Event" ) {
1166 bool ok; 1165 bool ok;
1167 dt = inR->getNextOccurence( cur, &ok ); 1166 dt = inR->getNextOccurence( cur, &ok );
1168 if ( !ok ) 1167 if ( !ok )
1169 dt = cur.addSecs( -62 ); 1168 dt = cur.addSecs( -62 );
1170 } 1169 }
1171 else 1170 else
1172 dt = inR->dtStart(); 1171 dt = inR->dtStart();
1173 if ( dt < cur || dt > end ) { 1172 if ( dt < cur || dt > end ) {
1174 remote->deleteIncidence( inR ); 1173 remote->deleteIncidence( inR );
1175 ++delFut; 1174 ++delFut;
1176 } 1175 }
1177 inR = er.next(); 1176 inR = er.next();
1178 } 1177 }
1179 } 1178 }
1180 bar.hide(); 1179 bar.hide();
1181 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1180 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1182 eventLSync->setReadOnly( false ); 1181 eventLSync->setReadOnly( false );
1183 eventLSync->setDtStart( mLastCalendarSync ); 1182 eventLSync->setDtStart( mLastCalendarSync );
1184 eventRSync->setDtStart( mLastCalendarSync ); 1183 eventRSync->setDtStart( mLastCalendarSync );
1185 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1184 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1186 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1185 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1187 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1186 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1188 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1187 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1189 eventLSync->setReadOnly( true ); 1188 eventLSync->setReadOnly( true );
1190 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1189 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1191 remote->addEvent( eventRSync ); 1190 remote->addEvent( eventRSync );
1192 QString mes; 1191 QString mes;
1193 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 ); 1192 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 );
1194 QString delmess; 1193 QString delmess;
1195 if ( delFut ) { 1194 if ( delFut ) {
1196 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1195 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1197 mes += delmess; 1196 mes += delmess;
1198 } 1197 }
1199 if ( KOPrefs::instance()->mShowSyncSummary ) { 1198 if ( KOPrefs::instance()->mShowSyncSummary ) {
1200 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1199 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1201 } 1200 }
1202 qDebug( mes ); 1201 qDebug( mes );
1203 mCalendar->checkAlarmForIncidence( 0, true ); 1202 mCalendar->checkAlarmForIncidence( 0, true );
1204 return syncOK; 1203 return syncOK;
1205} 1204}
1206 1205
1207void CalendarView::setSyncDevice( QString s ) 1206void CalendarView::setSyncDevice( QString s )
1208{ 1207{
1209 mCurrentSyncDevice= s; 1208 mCurrentSyncDevice= s;
1210} 1209}
1211void CalendarView::setSyncName( QString s ) 1210void CalendarView::setSyncName( QString s )
1212{ 1211{
1213 mCurrentSyncName= s; 1212 mCurrentSyncName= s;
1214} 1213}
1215bool CalendarView::syncCalendar(QString filename, int mode) 1214bool CalendarView::syncCalendar(QString filename, int mode)
1216{ 1215{
1217 mGlobalSyncMode = SYNC_MODE_NORMAL; 1216 mGlobalSyncMode = SYNC_MODE_NORMAL;
1218 CalendarLocal* calendar = new CalendarLocal(); 1217 CalendarLocal* calendar = new CalendarLocal();
1219 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1218 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1220 FileStorage* storage = new FileStorage( calendar ); 1219 FileStorage* storage = new FileStorage( calendar );
1221 bool syncOK = false; 1220 bool syncOK = false;
1222 storage->setFileName( filename ); 1221 storage->setFileName( filename );
1223 // qDebug("loading ... "); 1222 // qDebug("loading ... ");
1224 if ( storage->load() ) { 1223 if ( storage->load() ) {
1225 getEventViewerDialog()->setSyncMode( true ); 1224 getEventViewerDialog()->setSyncMode( true );
1226 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1227 getEventViewerDialog()->setSyncMode( false ); 1226 getEventViewerDialog()->setSyncMode( false );
1228 if ( syncOK ) { 1227 if ( syncOK ) {
1229 if ( KOPrefs::instance()->mWriteBackFile ) 1228 if ( KOPrefs::instance()->mWriteBackFile )
1230 { 1229 {
1231 storage->setSaveFormat( new ICalFormat() ); 1230 storage->setSaveFormat( new ICalFormat() );
1232 storage->save(); 1231 storage->save();
1233 } 1232 }
1234 } 1233 }
1235 setModified( true ); 1234 setModified( true );
1236 } 1235 }
1237 delete storage; 1236 delete storage;
1238 delete calendar; 1237 delete calendar;
1239 if ( syncOK ) 1238 if ( syncOK )
1240 updateView(); 1239 updateView();
1241 return syncOK; 1240 return syncOK;
1242} 1241}
1243void CalendarView::syncPhone() 1242void CalendarView::syncPhone()
1244{ 1243{
1245 syncExternal( 1 ); 1244 syncExternal( 1 );
1246} 1245}
1247void CalendarView::syncExternal( int mode ) 1246void CalendarView::syncExternal( int mode )
1248{ 1247{
1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1248 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1250 //mCurrentSyncDevice = "sharp-DTM"; 1249 //mCurrentSyncDevice = "sharp-DTM";
1251 if ( KOPrefs::instance()->mAskForPreferences ) 1250 if ( KOPrefs::instance()->mAskForPreferences )
1252 edit_sync_options(); 1251 edit_sync_options();
1253 qApp->processEvents(); 1252 qApp->processEvents();
1254 CalendarLocal* calendar = new CalendarLocal(); 1253 CalendarLocal* calendar = new CalendarLocal();
1255 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1254 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1256 bool syncOK = false; 1255 bool syncOK = false;
1257 bool loadSuccess = false; 1256 bool loadSuccess = false;
1258 PhoneFormat* phoneFormat = 0; 1257 PhoneFormat* phoneFormat = 0;
1259#ifndef DESKTOP_VERSION 1258#ifndef DESKTOP_VERSION
1260 SharpFormat* sharpFormat = 0; 1259 SharpFormat* sharpFormat = 0;
1261 if ( mode == 0 ) { // sharp 1260 if ( mode == 0 ) { // sharp
1262 sharpFormat = new SharpFormat () ; 1261 sharpFormat = new SharpFormat () ;
1263 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1262 loadSuccess = sharpFormat->load( calendar, mCalendar );
1264 1263
1265 } else 1264 } else
1266#endif 1265#endif
1267 if ( mode == 1 ) { // phone 1266 if ( mode == 1 ) { // phone
1268 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1267 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1269 KOPrefs::instance()->mPhoneDevice, 1268 KOPrefs::instance()->mPhoneDevice,
1270 KOPrefs::instance()->mPhoneConnection, 1269 KOPrefs::instance()->mPhoneConnection,
1271 KOPrefs::instance()->mPhoneModel); 1270 KOPrefs::instance()->mPhoneModel);
1272 loadSuccess = phoneFormat->load( calendar,mCalendar); 1271 loadSuccess = phoneFormat->load( calendar,mCalendar);
1273 1272
1274 } else 1273 } else
1275 return; 1274 return;
1276 if ( loadSuccess ) { 1275 if ( loadSuccess ) {
1277 getEventViewerDialog()->setSyncMode( true ); 1276 getEventViewerDialog()->setSyncMode( true );
1278 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1277 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1279 getEventViewerDialog()->setSyncMode( false ); 1278 getEventViewerDialog()->setSyncMode( false );
1280 qApp->processEvents(); 1279 qApp->processEvents();
1281 if ( syncOK ) { 1280 if ( syncOK ) {
1282 if ( KOPrefs::instance()->mWriteBackFile ) 1281 if ( KOPrefs::instance()->mWriteBackFile )
1283 { 1282 {
1284 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1283 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1285 Incidence* inc = iL.first(); 1284 Incidence* inc = iL.first();
1286 if ( phoneFormat ) { 1285 if ( phoneFormat ) {
1287 while ( inc ) { 1286 while ( inc ) {
1288 inc->removeID(mCurrentSyncDevice); 1287 inc->removeID(mCurrentSyncDevice);
1289 inc = iL.next(); 1288 inc = iL.next();
1290 } 1289 }
1291 } 1290 }
1292#ifndef DESKTOP_VERSION 1291#ifndef DESKTOP_VERSION
1293 if ( sharpFormat ) 1292 if ( sharpFormat )
1294 sharpFormat->save(calendar); 1293 sharpFormat->save(calendar);
1295#endif 1294#endif
1296 if ( phoneFormat ) 1295 if ( phoneFormat )
1297 phoneFormat->save(calendar); 1296 phoneFormat->save(calendar);
1298 iL = calendar->rawIncidences(); 1297 iL = calendar->rawIncidences();
1299 inc = iL.first(); 1298 inc = iL.first();
1300 Incidence* loc; 1299 Incidence* loc;
1301 while ( inc ) { 1300 while ( inc ) {
1302 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1301 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1303 loc = mCalendar->incidence(inc->uid() ); 1302 loc = mCalendar->incidence(inc->uid() );
1304 if ( loc ) { 1303 if ( loc ) {
1305 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1304 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1306 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1305 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1307 } 1306 }
1308 } 1307 }
1309 inc = iL.next(); 1308 inc = iL.next();
1310 } 1309 }
1311 Incidence* lse = getLastSyncEvent(); 1310 Incidence* lse = getLastSyncEvent();
1312 if ( lse ) { 1311 if ( lse ) {
1313 lse->setReadOnly( false ); 1312 lse->setReadOnly( false );
1314 lse->setDescription( "" ); 1313 lse->setDescription( "" );
1315 lse->setReadOnly( true ); 1314 lse->setReadOnly( true );
1316 } 1315 }
1317 } 1316 }
1318 } 1317 }
1319 setModified( true ); 1318 setModified( true );
1320 } else { 1319 } else {
1321 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1320 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1322 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1321 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1323 question, i18n("Ok")) ; 1322 question, i18n("Ok")) ;
1324 1323
1325 } 1324 }
1326 delete calendar; 1325 delete calendar;
1327 updateView(); 1326 updateView();
1328 return ;//syncOK; 1327 return ;//syncOK;
1329 1328
1330} 1329}
1331void CalendarView::syncSharp() 1330void CalendarView::syncSharp()
1332{ 1331{
1333 syncExternal( 0 ); 1332 syncExternal( 0 );
1334 1333
1335} 1334}
1336 1335
1337 1336
1338bool CalendarView::importBday() 1337bool CalendarView::importBday()
1339{ 1338{
1340#ifndef KORG_NOKABC 1339#ifndef KORG_NOKABC
1341 1340
1342#ifdef DESKTOP_VERSION 1341#ifdef DESKTOP_VERSION
1343 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1342 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1344 KABC::AddressBook::Iterator it; 1343 KABC::AddressBook::Iterator it;
1345 int count = 0; 1344 int count = 0;
1346 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1345 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1347 ++count; 1346 ++count;
1348 } 1347 }
1349 QProgressBar bar(count,0 ); 1348 QProgressBar bar(count,0 );
1350 int w = 300; 1349 int w = 300;
1351 if ( QApplication::desktop()->width() < 320 ) 1350 if ( QApplication::desktop()->width() < 320 )
1352 w = 220; 1351 w = 220;
1353 int h = bar.sizeHint().height() ; 1352 int h = bar.sizeHint().height() ;
1354 int dw = QApplication::desktop()->width(); 1353 int dw = QApplication::desktop()->width();
1355 int dh = QApplication::desktop()->height(); 1354 int dh = QApplication::desktop()->height();
1356 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1355 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1357 bar.show(); 1356 bar.show();
1358 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1357 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1359 qApp->processEvents(); 1358 qApp->processEvents();
1360 count = 0; 1359 count = 0;
1361 int addCount = 0; 1360 int addCount = 0;
1362 KCal::Attendee* a = 0; 1361 KCal::Attendee* a = 0;
1363 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1362 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1364 if ( ! bar.isVisible() ) 1363 if ( ! bar.isVisible() )
1365 return false; 1364 return false;
1366 bar.setProgress( count++ ); 1365 bar.setProgress( count++ );
1367 qApp->processEvents(); 1366 qApp->processEvents();
1368 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1367 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1369 if ( (*it).birthday().date().isValid() ){ 1368 if ( (*it).birthday().date().isValid() ){
1370 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1369 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1371 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1370 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1372 ++addCount; 1371 ++addCount;
1373 } 1372 }
1374 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1373 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1375 if ( anni.isValid() ){ 1374 if ( anni.isValid() ){
1376 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1375 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1377 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1376 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1378 ++addCount; 1377 ++addCount;
1379 } 1378 }
1380 } 1379 }
1381 updateView(); 1380 updateView();
1382 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1381 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1383#else //DESKTOP_VERSION 1382#else //DESKTOP_VERSION
1384 1383
1385 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1384 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1386 // the result should now arrive through method insertBirthdays 1385 // the result should now arrive through method insertBirthdays
1387 1386
1388#endif //DESKTOP_VERSION 1387#endif //DESKTOP_VERSION
1389 1388
1390#endif //KORG_NOKABC 1389#endif //KORG_NOKABC
1391 1390
1392 1391
1393 return true; 1392 return true;
1394} 1393}
1395 1394
1396// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1395// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1397void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1396void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1398 const QStringList& anniversaryList, const QStringList& realNameList, 1397 const QStringList& anniversaryList, const QStringList& realNameList,
1399 const QStringList& emailList, const QStringList& assembledNameList, 1398 const QStringList& emailList, const QStringList& assembledNameList,
1400 const QStringList& uidList) 1399 const QStringList& uidList)
1401{ 1400{
1402 qDebug("CalendarView::insertBirthdays"); 1401 qDebug("CalendarView::insertBirthdays");
1403 if (uid == this->name()) 1402 if (uid == this->name())
1404 { 1403 {
1405 int count = birthdayList.count(); 1404 int count = birthdayList.count();
1406 int addCount = 0; 1405 int addCount = 0;
1407 KCal::Attendee* a = 0; 1406 KCal::Attendee* a = 0;
1408 1407
1409 qDebug("CalView 1 %i", count); 1408 qDebug("CalView 1 %i", count);
1410 1409
1411 QProgressBar bar(count,0 ); 1410 QProgressBar bar(count,0 );
1412 int w = 300; 1411 int w = 300;
1413 if ( QApplication::desktop()->width() < 320 ) 1412 if ( QApplication::desktop()->width() < 320 )
1414 w = 220; 1413 w = 220;
1415 int h = bar.sizeHint().height() ; 1414 int h = bar.sizeHint().height() ;
1416 int dw = QApplication::desktop()->width(); 1415 int dw = QApplication::desktop()->width();
1417 int dh = QApplication::desktop()->height(); 1416 int dh = QApplication::desktop()->height();
1418 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1417 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1419 bar.show(); 1418 bar.show();
1420 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1419 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1421 qApp->processEvents(); 1420 qApp->processEvents();
1422 1421
1423 QDate birthday; 1422 QDate birthday;
1424 QDate anniversary; 1423 QDate anniversary;
1425 QString realName; 1424 QString realName;
1426 QString email; 1425 QString email;
1427 QString assembledName; 1426 QString assembledName;
1428 QString uid; 1427 QString uid;
1429 bool ok = true; 1428 bool ok = true;
1430 for ( int i = 0; i < count; i++) 1429 for ( int i = 0; i < count; i++)
1431 { 1430 {
1432 if ( ! bar.isVisible() ) 1431 if ( ! bar.isVisible() )
1433 return; 1432 return;
1434 bar.setProgress( i ); 1433 bar.setProgress( i );
1435 qApp->processEvents(); 1434 qApp->processEvents();
1436 1435
1437 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1436 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1438 if (!ok) { 1437 if (!ok) {
1439 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1438 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1440 } 1439 }
1441 1440
1442 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1441 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1443 if (!ok) { 1442 if (!ok) {
1444 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1443 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1445 } 1444 }
1446 realName = realNameList[i]; 1445 realName = realNameList[i];
1447 email = emailList[i]; 1446 email = emailList[i];
1448 assembledName = assembledNameList[i]; 1447 assembledName = assembledNameList[i];
1449 uid = uidList[i]; 1448 uid = uidList[i];
1450 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1449 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1451 1450
1452 if ( birthday.isValid() ){ 1451 if ( birthday.isValid() ){
1453 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1452 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1454 KCal::Attendee::ReqParticipant,uid) ; 1453 KCal::Attendee::ReqParticipant,uid) ;
1455 if ( addAnniversary( birthday, assembledName, a, true ) ) 1454 if ( addAnniversary( birthday, assembledName, a, true ) )
1456 ++addCount; 1455 ++addCount;
1457 } 1456 }
1458 1457
1459 if ( anniversary.isValid() ){ 1458 if ( anniversary.isValid() ){
1460 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1459 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1461 KCal::Attendee::ReqParticipant,uid) ; 1460 KCal::Attendee::ReqParticipant,uid) ;
1462 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1461 if ( addAnniversary( anniversary, assembledName, a, false ) )
1463 ++addCount; 1462 ++addCount;
1464 } 1463 }
1465 } 1464 }
1466 1465
1467 updateView(); 1466 updateView();
1468 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1467 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1469 1468
1470 } 1469 }
1471 1470
1472} 1471}
1473 1472
1474 1473
1475 1474
1476bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1475bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1477{ 1476{
1478 //qDebug("addAnni "); 1477 //qDebug("addAnni ");
1479 Event * ev = new Event(); 1478 Event * ev = new Event();
1480 if ( a ) { 1479 if ( a ) {
1481 ev->addAttendee( a ); 1480 ev->addAttendee( a );
1482 } 1481 }
1483 QString kind; 1482 QString kind;
1484 if ( birthday ) 1483 if ( birthday )
1485 kind = i18n( "Birthday" ); 1484 kind = i18n( "Birthday" );
1486 else 1485 else
1487 kind = i18n( "Anniversary" ); 1486 kind = i18n( "Anniversary" );
1488 ev->setSummary( name + " - " + kind ); 1487 ev->setSummary( name + " - " + kind );
1489 ev->setOrganizer( "nobody@nowhere" ); 1488 ev->setOrganizer( "nobody@nowhere" );
1490 ev->setCategories( kind ); 1489 ev->setCategories( kind );
1491 ev->setDtStart( QDateTime(date) ); 1490 ev->setDtStart( QDateTime(date) );
1492 ev->setDtEnd( QDateTime(date) ); 1491 ev->setDtEnd( QDateTime(date) );
1493 ev->setFloats( true ); 1492 ev->setFloats( true );
1494 Recurrence * rec = ev->recurrence(); 1493 Recurrence * rec = ev->recurrence();
1495 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1494 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1496 rec->addYearlyNum( date.month() ); 1495 rec->addYearlyNum( date.month() );
1497 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1496 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1498 delete ev; 1497 delete ev;
1499 return false; 1498 return false;
1500 } 1499 }
1501 return true; 1500 return true;
1502 1501
1503} 1502}
1504bool CalendarView::importQtopia( const QString &categories, 1503bool CalendarView::importQtopia( const QString &categories,
1505 const QString &datebook, 1504 const QString &datebook,
1506 const QString &todolist ) 1505 const QString &todolist )
1507{ 1506{
1508 1507
1509 QtopiaFormat qtopiaFormat; 1508 QtopiaFormat qtopiaFormat;
1510 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1509 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1511 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1510 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1512 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1511 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1513 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1512 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1514 1513
1515 updateView(); 1514 updateView();
1516 return true; 1515 return true;
1517 1516
1518#if 0 1517#if 0
1519 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1518 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1520 mCurrentSyncDevice = "qtopia-XML"; 1519 mCurrentSyncDevice = "qtopia-XML";
1521 if ( KOPrefs::instance()->mAskForPreferences ) 1520 if ( KOPrefs::instance()->mAskForPreferences )
1522 edit_sync_options(); 1521 edit_sync_options();
1523 qApp->processEvents(); 1522 qApp->processEvents();
1524 CalendarLocal* calendar = new CalendarLocal(); 1523 CalendarLocal* calendar = new CalendarLocal();
1525 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1524 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1526 bool syncOK = false; 1525 bool syncOK = false;
1527 QtopiaFormat qtopiaFormat; 1526 QtopiaFormat qtopiaFormat;
1528 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1527 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1529 bool loadOk = true; 1528 bool loadOk = true;
1530 if ( !categories.isEmpty() ) 1529 if ( !categories.isEmpty() )
1531 loadOk = qtopiaFormat.load( calendar, categories ); 1530 loadOk = qtopiaFormat.load( calendar, categories );
1532 if ( loadOk && !datebook.isEmpty() ) 1531 if ( loadOk && !datebook.isEmpty() )
1533 loadOk = qtopiaFormat.load( calendar, datebook ); 1532 loadOk = qtopiaFormat.load( calendar, datebook );
1534 if ( loadOk && !todolist.isEmpty() ) 1533 if ( loadOk && !todolist.isEmpty() )
1535 loadOk = qtopiaFormat.load( calendar, todolist ); 1534 loadOk = qtopiaFormat.load( calendar, todolist );
1536 1535
1537 if ( loadOk ) { 1536 if ( loadOk ) {
1538 getEventViewerDialog()->setSyncMode( true ); 1537 getEventViewerDialog()->setSyncMode( true );
1539 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1538 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1540 getEventViewerDialog()->setSyncMode( false ); 1539 getEventViewerDialog()->setSyncMode( false );
1541 qApp->processEvents(); 1540 qApp->processEvents();
1542 if ( syncOK ) { 1541 if ( syncOK ) {
1543 if ( KOPrefs::instance()->mWriteBackFile ) 1542 if ( KOPrefs::instance()->mWriteBackFile )
1544 { 1543 {
1545 // write back XML file 1544 // write back XML file
1546 1545
1547 } 1546 }
1548 setModified( true ); 1547 setModified( true );
1549 } 1548 }
1550 } else { 1549 } else {
1551 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1550 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1552 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1551 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1553 question, i18n("Ok")) ; 1552 question, i18n("Ok")) ;
1554 } 1553 }
1555 delete calendar; 1554 delete calendar;
1556 updateView(); 1555 updateView();
1557 return syncOK; 1556 return syncOK;
1558 1557
1559 1558
1560#endif 1559#endif
1561 1560
1562} 1561}
1563 1562
1564void CalendarView::setSyncEventsReadOnly() 1563void CalendarView::setSyncEventsReadOnly()
1565{ 1564{
1566 Event * ev; 1565 Event * ev;
1567 QPtrList<Event> eL = mCalendar->rawEvents(); 1566 QPtrList<Event> eL = mCalendar->rawEvents();
1568 ev = eL.first(); 1567 ev = eL.first();
1569 while ( ev ) { 1568 while ( ev ) {
1570 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1569 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1571 ev->setReadOnly( true ); 1570 ev->setReadOnly( true );
1572 ev = eL.next(); 1571 ev = eL.next();
1573 } 1572 }
1574} 1573}
1575bool CalendarView::openCalendar(QString filename, bool merge) 1574bool CalendarView::openCalendar(QString filename, bool merge)
1576{ 1575{
1577 1576
1578 if (filename.isEmpty()) { 1577 if (filename.isEmpty()) {
1579 return false; 1578 return false;
1580 } 1579 }
1581 1580
1582 if (!QFile::exists(filename)) { 1581 if (!QFile::exists(filename)) {
1583 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1582 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1584 return false; 1583 return false;
1585 } 1584 }
1586 1585
1587 globalFlagBlockAgenda = 1; 1586 globalFlagBlockAgenda = 1;
1588 if (!merge) mCalendar->close(); 1587 if (!merge) mCalendar->close();
1589 1588
1590 mStorage->setFileName( filename ); 1589 mStorage->setFileName( filename );
1591 1590
1592 if ( mStorage->load() ) { 1591 if ( mStorage->load() ) {
1593 if ( merge ) ;//setModified( true ); 1592 if ( merge ) ;//setModified( true );
1594 else { 1593 else {
1595 //setModified( true ); 1594 //setModified( true );
1596 mViewManager->setDocumentId( filename ); 1595 mViewManager->setDocumentId( filename );
1597 mDialogManager->setDocumentId( filename ); 1596 mDialogManager->setDocumentId( filename );
1598 mTodoList->setDocumentId( filename ); 1597 mTodoList->setDocumentId( filename );
1599 } 1598 }
1600 globalFlagBlockAgenda = 2; 1599 globalFlagBlockAgenda = 2;
1601 // if ( getLastSyncEvent() ) 1600 // if ( getLastSyncEvent() )
1602 // getLastSyncEvent()->setReadOnly( true ); 1601 // getLastSyncEvent()->setReadOnly( true );
1603 mCalendar->reInitAlarmSettings(); 1602 mCalendar->reInitAlarmSettings();
1604 setSyncEventsReadOnly(); 1603 setSyncEventsReadOnly();
1605 updateUnmanagedViews(); 1604 updateUnmanagedViews();
1606 updateView(); 1605 updateView();
1607 setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 )); 1606 setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 ));
1608 if ( filename != MainWindow::defaultFileName() ) { 1607 if ( filename != MainWindow::defaultFileName() ) {
1609 saveCalendar( MainWindow::defaultFileName() ); 1608 saveCalendar( MainWindow::defaultFileName() );
1610 watchSavedFile(); 1609 watchSavedFile();
1611 } 1610 }
1612 return true; 1611 return true;
1613 } else { 1612 } else {
1614 // while failing to load, the calendar object could 1613 // while failing to load, the calendar object could
1615 // have become partially populated. Clear it out. 1614 // have become partially populated. Clear it out.
1616 if ( !merge ) { 1615 if ( !merge ) {
1617 mCalendar->close(); 1616 mCalendar->close();
1618 mViewManager->setDocumentId( filename ); 1617 mViewManager->setDocumentId( filename );
1619 mDialogManager->setDocumentId( filename ); 1618 mDialogManager->setDocumentId( filename );
1620 mTodoList->setDocumentId( filename ); 1619 mTodoList->setDocumentId( filename );
1621 } 1620 }
1622 1621
1623 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1622 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1624 1623
1625 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1624 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1626 globalFlagBlockAgenda = 2; 1625 globalFlagBlockAgenda = 2;
1627 mCalendar->reInitAlarmSettings(); 1626 mCalendar->reInitAlarmSettings();
1628 setSyncEventsReadOnly(); 1627 setSyncEventsReadOnly();
1629 updateUnmanagedViews(); 1628 updateUnmanagedViews();
1630 updateView(); 1629 updateView();
1631 } 1630 }
1632 return false; 1631 return false;
1633} 1632}
1634void CalendarView::showOpenError() 1633void CalendarView::showOpenError()
1635{ 1634{
1636 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1635 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1637} 1636}
1638void CalendarView::setLoadedFileVersion(QDateTime dt) 1637void CalendarView::setLoadedFileVersion(QDateTime dt)
1639{ 1638{
1640 loadedFileVersion = dt; 1639 loadedFileVersion = dt;
1641} 1640}
1642bool CalendarView::checkFileChanged(QString fn) 1641bool CalendarView::checkFileChanged(QString fn)
1643{ 1642{
1644 QFileInfo finf ( fn ); 1643 QFileInfo finf ( fn );
1645 if ( !finf.exists() ) 1644 if ( !finf.exists() )
1646 return true; 1645 return true;
1647 QDateTime dt = finf.lastModified (); 1646 QDateTime dt = finf.lastModified ();
1648 if ( dt <= loadedFileVersion ) 1647 if ( dt <= loadedFileVersion )
1649 return false; 1648 return false;
1650 return true; 1649 return true;
1651 1650
1652} 1651}
1653void CalendarView::watchSavedFile() 1652void CalendarView::watchSavedFile()
1654{ 1653{
1655 QFileInfo finf ( MainWindow::defaultFileName()); 1654 QFileInfo finf ( MainWindow::defaultFileName());
1656 if ( !finf.exists() ) 1655 if ( !finf.exists() )
1657 return; 1656 return;
1658 QDateTime dt = finf.lastModified (); 1657 QDateTime dt = finf.lastModified ();
1659 if ( dt < loadedFileVersion ) { 1658 if ( dt < loadedFileVersion ) {
1660 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1659 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1661 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1660 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1662 return; 1661 return;
1663 } 1662 }
1664 loadedFileVersion = dt; 1663 loadedFileVersion = dt;
1665} 1664}
1666 1665
1667bool CalendarView::checkFileVersion(QString fn) 1666bool CalendarView::checkFileVersion(QString fn)
1668{ 1667{
1669 QFileInfo finf ( fn ); 1668 QFileInfo finf ( fn );
1670 if ( !finf.exists() ) 1669 if ( !finf.exists() )
1671 return true; 1670 return true;
1672 QDateTime dt = finf.lastModified (); 1671 QDateTime dt = finf.lastModified ();
1673 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1672 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1674 //qDebug("file on disk version %s",dt.toString().latin1()); 1673 //qDebug("file on disk version %s",dt.toString().latin1());
1675 if ( dt <= loadedFileVersion ) 1674 if ( dt <= loadedFileVersion )
1676 return true; 1675 return true;
1677 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1676 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1678 i18n("KO/Pi Warning"),i18n("Overwrite"), 1677 i18n("KO/Pi Warning"),i18n("Overwrite"),
1679 i18n("Sync+save")); 1678 i18n("Sync+save"));
1680 1679
1681 if ( km == KMessageBox::Cancel ) 1680 if ( km == KMessageBox::Cancel )
1682 return false; 1681 return false;
1683 if ( km == KMessageBox::Yes ) 1682 if ( km == KMessageBox::Yes )
1684 return true; 1683 return true;
1685 1684
1686 setSyncDevice("deleteaftersync" ); 1685 setSyncDevice("deleteaftersync" );
1687 KOPrefs::instance()->mAskForPreferences = true; 1686 KOPrefs::instance()->mAskForPreferences = true;
1688 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1687 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1689 KOPrefs::instance()->mWriteBackFile = false; 1688 KOPrefs::instance()->mWriteBackFile = false;
1690 KOPrefs::instance()->mWriteBackExistingOnly = false; 1689 KOPrefs::instance()->mWriteBackExistingOnly = false;
1691 KOPrefs::instance()->mShowSyncSummary = false; 1690 KOPrefs::instance()->mShowSyncSummary = false;
1692 syncCalendar( fn, 3 ); 1691 syncCalendar( fn, 3 );
1693 Event * e = getLastSyncEvent(); 1692 Event * e = getLastSyncEvent();
1694 mCalendar->deleteEvent ( e ); 1693 mCalendar->deleteEvent ( e );
1695 updateView(); 1694 updateView();
1696 return true; 1695 return true;
1697} 1696}
1698 1697
1699bool CalendarView::saveCalendar( QString filename ) 1698bool CalendarView::saveCalendar( QString filename )
1700{ 1699{
1701 1700
1702 // Store back all unsaved data into calendar object 1701 // Store back all unsaved data into calendar object
1703 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1702 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1704 if ( mViewManager->currentView() ) 1703 if ( mViewManager->currentView() )
1705 mViewManager->currentView()->flushView(); 1704 mViewManager->currentView()->flushView();
1706 1705
1707 //mStorage->setFileName( filename ); 1706 //mStorage->setFileName( filename );
1708 1707
1709 mStorage->setSaveFormat( new ICalFormat() ); 1708 mStorage->setSaveFormat( new ICalFormat() );
1710 mStorage->setFileName( filename ); 1709 mStorage->setFileName( filename );
1711 bool success; 1710 bool success;
1712 success = mStorage->save(); 1711 success = mStorage->save();
1713 if ( !success ) { 1712 if ( !success ) {
1714 return false; 1713 return false;
1715 } 1714 }
1716 1715
1717 return true; 1716 return true;
1718} 1717}
1719 1718
1720void CalendarView::closeCalendar() 1719void CalendarView::closeCalendar()
1721{ 1720{
1722 1721
1723 // child windows no longer valid 1722 // child windows no longer valid
1724 emit closingDown(); 1723 emit closingDown();
1725 1724
1726 mCalendar->close(); 1725 mCalendar->close();
1727 setModified(false); 1726 setModified(false);
1728 updateView(); 1727 updateView();
1729} 1728}
1730 1729
1731void CalendarView::archiveCalendar() 1730void CalendarView::archiveCalendar()
1732{ 1731{
1733 mDialogManager->showArchiveDialog(); 1732 mDialogManager->showArchiveDialog();
1734} 1733}
1735 1734
1736 1735
1737void CalendarView::readSettings() 1736void CalendarView::readSettings()
1738{ 1737{
1739 1738
1740 1739
1741 // mViewManager->showAgendaView(); 1740 // mViewManager->showAgendaView();
1742 QString str; 1741 QString str;
1743 //qDebug("CalendarView::readSettings() "); 1742 //qDebug("CalendarView::readSettings() ");
1744 // read settings from the KConfig, supplying reasonable 1743 // read settings from the KConfig, supplying reasonable
1745 // defaults where none are to be found 1744 // defaults where none are to be found
1746 KConfig *config = KOGlobals::config(); 1745 KConfig *config = KOGlobals::config();
1747#ifndef KORG_NOSPLITTER 1746#ifndef KORG_NOSPLITTER
1748 config->setGroup("KOrganizer Geometry"); 1747 config->setGroup("KOrganizer Geometry");
1749 1748
1750 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1749 QValueList<int> sizes = config->readIntListEntry("Separator1");
1751 if (sizes.count() != 2) { 1750 if (sizes.count() != 2) {
1752 sizes << mDateNavigator->minimumSizeHint().width(); 1751 sizes << mDateNavigator->minimumSizeHint().width();
1753 sizes << 300; 1752 sizes << 300;
1754 } 1753 }
1755 mPanner->setSizes(sizes); 1754 mPanner->setSizes(sizes);
1756 1755
1757 sizes = config->readIntListEntry("Separator2"); 1756 sizes = config->readIntListEntry("Separator2");
1758 if ( ( mResourceView && sizes.count() == 4 ) || 1757 if ( ( mResourceView && sizes.count() == 4 ) ||
1759 ( !mResourceView && sizes.count() == 3 ) ) { 1758 ( !mResourceView && sizes.count() == 3 ) ) {
1760 mLeftSplitter->setSizes(sizes); 1759 mLeftSplitter->setSizes(sizes);
1761 } 1760 }
1762#endif 1761#endif
1763 globalFlagBlockAgenda = 1; 1762 globalFlagBlockAgenda = 1;
1764 mViewManager->showAgendaView(); 1763 mViewManager->showAgendaView();
1765 //mViewManager->readSettings( config ); 1764 //mViewManager->readSettings( config );
1766 mTodoList->restoreLayout(config,QString("Todo Layout")); 1765 mTodoList->restoreLayout(config,QString("Todo Layout"));
1767 readFilterSettings(config); 1766 readFilterSettings(config);
1768 config->setGroup( "Views" ); 1767 config->setGroup( "Views" );
1769 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1768 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1770 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1769 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1771 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1770 else if ( dateCount == 7 ) mNavigator->selectWeek();
1772 else mNavigator->selectDates( dateCount ); 1771 else mNavigator->selectDates( dateCount );
1773 // mViewManager->readSettings( config ); 1772 // mViewManager->readSettings( config );
1774 updateConfig(); 1773 updateConfig();
1775 globalFlagBlockAgenda = 2; 1774 globalFlagBlockAgenda = 2;
1776 mViewManager->readSettings( config ); 1775 mViewManager->readSettings( config );
1777#ifdef DESKTOP_VERSION 1776#ifdef DESKTOP_VERSION
1778 config->setGroup("WidgetLayout"); 1777 config->setGroup("WidgetLayout");
1779 QStringList list; 1778 QStringList list;
1780 list = config->readListEntry("MainLayout"); 1779 list = config->readListEntry("MainLayout");
1781 int x,y,w,h; 1780 int x,y,w,h;
1782 if ( ! list.isEmpty() ) { 1781 if ( ! list.isEmpty() ) {
1783 x = list[0].toInt(); 1782 x = list[0].toInt();
1784 y = list[1].toInt(); 1783 y = list[1].toInt();
1785 w = list[2].toInt(); 1784 w = list[2].toInt();
1786 h = list[3].toInt(); 1785 h = list[3].toInt();
1787 topLevelWidget()->setGeometry(x,y,w,h); 1786 topLevelWidget()->setGeometry(x,y,w,h);
1788 1787
1789 } else { 1788 } else {
1790 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1789 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1791 } 1790 }
1792 list = config->readListEntry("EditEventLayout"); 1791 list = config->readListEntry("EditEventLayout");
1793 if ( ! list.isEmpty() ) { 1792 if ( ! list.isEmpty() ) {
1794 x = list[0].toInt(); 1793 x = list[0].toInt();
1795 y = list[1].toInt(); 1794 y = list[1].toInt();
1796 w = list[2].toInt(); 1795 w = list[2].toInt();
1797 h = list[3].toInt(); 1796 h = list[3].toInt();
1798 mEventEditor->setGeometry(x,y,w,h); 1797 mEventEditor->setGeometry(x,y,w,h);
1799 1798
1800 } 1799 }
1801 list = config->readListEntry("EditTodoLayout"); 1800 list = config->readListEntry("EditTodoLayout");
1802 if ( ! list.isEmpty() ) { 1801 if ( ! list.isEmpty() ) {
1803 x = list[0].toInt(); 1802 x = list[0].toInt();
1804 y = list[1].toInt(); 1803 y = list[1].toInt();
1805 w = list[2].toInt(); 1804 w = list[2].toInt();
1806 h = list[3].toInt(); 1805 h = list[3].toInt();
1807 mTodoEditor->setGeometry(x,y,w,h); 1806 mTodoEditor->setGeometry(x,y,w,h);
1808 1807
1809 } 1808 }
1810 list = config->readListEntry("ViewerLayout"); 1809 list = config->readListEntry("ViewerLayout");
1811 if ( ! list.isEmpty() ) { 1810 if ( ! list.isEmpty() ) {
1812 x = list[0].toInt(); 1811 x = list[0].toInt();
1813 y = list[1].toInt(); 1812 y = list[1].toInt();
1814 w = list[2].toInt(); 1813 w = list[2].toInt();
1815 h = list[3].toInt(); 1814 h = list[3].toInt();
1816 getEventViewerDialog()->setGeometry(x,y,w,h); 1815 getEventViewerDialog()->setGeometry(x,y,w,h);
1817 } 1816 }
1818#endif 1817#endif
1819 1818
1820} 1819}
1821 1820
1822 1821
1823void CalendarView::writeSettings() 1822void CalendarView::writeSettings()
1824{ 1823{
1825 // kdDebug() << "CalendarView::writeSettings" << endl; 1824 // kdDebug() << "CalendarView::writeSettings" << endl;
1826 1825
1827 KConfig *config = KOGlobals::config(); 1826 KConfig *config = KOGlobals::config();
1828 1827
1829#ifndef KORG_NOSPLITTER 1828#ifndef KORG_NOSPLITTER
1830 config->setGroup("KOrganizer Geometry"); 1829 config->setGroup("KOrganizer Geometry");
1831 1830
1832 QValueList<int> list = mPanner->sizes(); 1831 QValueList<int> list = mPanner->sizes();
1833 config->writeEntry("Separator1",list); 1832 config->writeEntry("Separator1",list);
1834 1833
1835 list = mLeftSplitter->sizes(); 1834 list = mLeftSplitter->sizes();
1836 config->writeEntry("Separator2",list); 1835 config->writeEntry("Separator2",list);
1837#endif 1836#endif
1838 1837
1839 mViewManager->writeSettings( config ); 1838 mViewManager->writeSettings( config );
1840 mTodoList->saveLayout(config,QString("Todo Layout")); 1839 mTodoList->saveLayout(config,QString("Todo Layout"));
1841 mDialogManager->writeSettings( config ); 1840 mDialogManager->writeSettings( config );
1842 //KOPrefs::instance()->usrWriteConfig(); 1841 //KOPrefs::instance()->usrWriteConfig();
1843 KOPrefs::instance()->writeConfig(); 1842 KOPrefs::instance()->writeConfig();
1844 1843
1845 writeFilterSettings(config); 1844 writeFilterSettings(config);
1846 1845
1847 config->setGroup( "Views" ); 1846 config->setGroup( "Views" );
1848 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1847 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1849 1848
1850#ifdef DESKTOP_VERSION 1849#ifdef DESKTOP_VERSION
1851 config->setGroup("WidgetLayout"); 1850 config->setGroup("WidgetLayout");
1852 QStringList list ;//= config->readListEntry("MainLayout"); 1851 QStringList list ;//= config->readListEntry("MainLayout");
1853 int x,y,w,h; 1852 int x,y,w,h;
1854 QWidget* wid; 1853 QWidget* wid;
1855 wid = topLevelWidget(); 1854 wid = topLevelWidget();
1856 x = wid->geometry().x(); 1855 x = wid->geometry().x();
1857 y = wid->geometry().y(); 1856 y = wid->geometry().y();
1858 w = wid->width(); 1857 w = wid->width();
1859 h = wid->height(); 1858 h = wid->height();
1860 list.clear(); 1859 list.clear();
1861 list << QString::number( x ); 1860 list << QString::number( x );
1862 list << QString::number( y ); 1861 list << QString::number( y );
1863 list << QString::number( w ); 1862 list << QString::number( w );
1864 list << QString::number( h ); 1863 list << QString::number( h );
1865 config->writeEntry("MainLayout",list ); 1864 config->writeEntry("MainLayout",list );
1866 1865
1867 wid = mEventEditor; 1866 wid = mEventEditor;
1868 x = wid->geometry().x(); 1867 x = wid->geometry().x();
1869 y = wid->geometry().y(); 1868 y = wid->geometry().y();
1870 w = wid->width(); 1869 w = wid->width();
1871 h = wid->height(); 1870 h = wid->height();
1872 list.clear(); 1871 list.clear();
1873 list << QString::number( x ); 1872 list << QString::number( x );
1874 list << QString::number( y ); 1873 list << QString::number( y );
1875 list << QString::number( w ); 1874 list << QString::number( w );
1876 list << QString::number( h ); 1875 list << QString::number( h );
1877 config->writeEntry("EditEventLayout",list ); 1876 config->writeEntry("EditEventLayout",list );
1878 1877
1879 wid = mTodoEditor; 1878 wid = mTodoEditor;
1880 x = wid->geometry().x(); 1879 x = wid->geometry().x();
1881 y = wid->geometry().y(); 1880 y = wid->geometry().y();
1882 w = wid->width(); 1881 w = wid->width();
1883 h = wid->height(); 1882 h = wid->height();
1884 list.clear(); 1883 list.clear();
1885 list << QString::number( x ); 1884 list << QString::number( x );
1886 list << QString::number( y ); 1885 list << QString::number( y );
1887 list << QString::number( w ); 1886 list << QString::number( w );
1888 list << QString::number( h ); 1887 list << QString::number( h );
1889 config->writeEntry("EditTodoLayout",list ); 1888 config->writeEntry("EditTodoLayout",list );
1890 wid = getEventViewerDialog(); 1889 wid = getEventViewerDialog();
1891 x = wid->geometry().x(); 1890 x = wid->geometry().x();
1892 y = wid->geometry().y(); 1891 y = wid->geometry().y();
1893 w = wid->width(); 1892 w = wid->width();
1894 h = wid->height(); 1893 h = wid->height();
1895 list.clear(); 1894 list.clear();
1896 list << QString::number( x ); 1895 list << QString::number( x );
1897 list << QString::number( y ); 1896 list << QString::number( y );
1898 list << QString::number( w ); 1897 list << QString::number( w );
1899 list << QString::number( h ); 1898 list << QString::number( h );
1900 config->writeEntry("ViewerLayout",list ); 1899 config->writeEntry("ViewerLayout",list );
1901 wid = mDialogManager->getSearchDialog(); 1900 wid = mDialogManager->getSearchDialog();
1902 if ( wid ) { 1901 if ( wid ) {
1903 x = wid->geometry().x(); 1902 x = wid->geometry().x();
1904 y = wid->geometry().y(); 1903 y = wid->geometry().y();
1905 w = wid->width(); 1904 w = wid->width();
1906 h = wid->height(); 1905 h = wid->height();
1907 list.clear(); 1906 list.clear();
1908 list << QString::number( x ); 1907 list << QString::number( x );
1909 list << QString::number( y ); 1908 list << QString::number( y );
1910 list << QString::number( w ); 1909 list << QString::number( w );
1911 list << QString::number( h ); 1910 list << QString::number( h );
1912 config->writeEntry("SearchLayout",list ); 1911 config->writeEntry("SearchLayout",list );
1913 } 1912 }
1914#endif 1913#endif
1915 1914
1916 1915
1917 config->sync(); 1916 config->sync();
1918} 1917}
1919 1918
1920void CalendarView::readFilterSettings(KConfig *config) 1919void CalendarView::readFilterSettings(KConfig *config)
1921{ 1920{
1922 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1921 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1923 1922
1924 mFilters.clear(); 1923 mFilters.clear();
1925 1924
1926 config->setGroup("General"); 1925 config->setGroup("General");
1927 QStringList filterList = config->readListEntry("CalendarFilters"); 1926 QStringList filterList = config->readListEntry("CalendarFilters");
1928 1927
1929 QStringList::ConstIterator it = filterList.begin(); 1928 QStringList::ConstIterator it = filterList.begin();
1930 QStringList::ConstIterator end = filterList.end(); 1929 QStringList::ConstIterator end = filterList.end();
1931 while(it != end) { 1930 while(it != end) {
1932 // kdDebug() << " filter: " << (*it) << endl; 1931 // kdDebug() << " filter: " << (*it) << endl;
1933 1932
1934 CalFilter *filter; 1933 CalFilter *filter;
1935 filter = new CalFilter(*it); 1934 filter = new CalFilter(*it);
1936 config->setGroup("Filter_" + (*it)); 1935 config->setGroup("Filter_" + (*it));
1937 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1936 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1938 filter->setCriteria(config->readNumEntry("Criteria",0)); 1937 filter->setCriteria(config->readNumEntry("Criteria",0));
1939 filter->setCategoryList(config->readListEntry("CategoryList")); 1938 filter->setCategoryList(config->readListEntry("CategoryList"));
1940 mFilters.append(filter); 1939 mFilters.append(filter);
1941 1940
1942 ++it; 1941 ++it;
1943 } 1942 }
1944 1943
1945 if (mFilters.count() == 0) { 1944 if (mFilters.count() == 0) {
1946 CalFilter *filter = new CalFilter(i18n("Default")); 1945 CalFilter *filter = new CalFilter(i18n("Default"));
1947 mFilters.append(filter); 1946 mFilters.append(filter);
1948 } 1947 }
1949 mFilterView->updateFilters(); 1948 mFilterView->updateFilters();
1950 config->setGroup("FilterView"); 1949 config->setGroup("FilterView");
1951 1950
1952 mFilterView->blockSignals(true); 1951 mFilterView->blockSignals(true);
1953 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1952 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1954 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1953 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1955 mFilterView->blockSignals(false); 1954 mFilterView->blockSignals(false);
1956 // We do it manually to avoid it being done twice by the above calls 1955 // We do it manually to avoid it being done twice by the above calls
1957 updateFilter(); 1956 updateFilter();
1958} 1957}
1959 1958
1960void CalendarView::writeFilterSettings(KConfig *config) 1959void CalendarView::writeFilterSettings(KConfig *config)
1961{ 1960{
1962 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1961 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1963 1962
1964 QStringList filterList; 1963 QStringList filterList;
1965 1964
1966 CalFilter *filter = mFilters.first(); 1965 CalFilter *filter = mFilters.first();
1967 while(filter) { 1966 while(filter) {
1968 // kdDebug() << " fn: " << filter->name() << endl; 1967 // kdDebug() << " fn: " << filter->name() << endl;
1969 filterList << filter->name(); 1968 filterList << filter->name();
1970 config->setGroup("Filter_" + filter->name()); 1969 config->setGroup("Filter_" + filter->name());
1971 config->writeEntry("Criteria",filter->criteria()); 1970 config->writeEntry("Criteria",filter->criteria());
1972 config->writeEntry("CategoryList",filter->categoryList()); 1971 config->writeEntry("CategoryList",filter->categoryList());
1973 filter = mFilters.next(); 1972 filter = mFilters.next();
1974 } 1973 }
1975 config->setGroup("General"); 1974 config->setGroup("General");
1976 config->writeEntry("CalendarFilters",filterList); 1975 config->writeEntry("CalendarFilters",filterList);
1977 1976
1978 config->setGroup("FilterView"); 1977 config->setGroup("FilterView");
1979 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1978 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1980 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1979 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1981} 1980}
1982 1981
1983 1982
1984void CalendarView::goToday() 1983void CalendarView::goToday()
1985{ 1984{
1986 mNavigator->selectToday(); 1985 mNavigator->selectToday();
1987} 1986}
1988 1987
1989void CalendarView::goNext() 1988void CalendarView::goNext()
1990{ 1989{
1991 mNavigator->selectNext(); 1990 mNavigator->selectNext();
1992} 1991}
1993 1992
1994void CalendarView::goPrevious() 1993void CalendarView::goPrevious()
1995{ 1994{
1996 mNavigator->selectPrevious(); 1995 mNavigator->selectPrevious();
1997} 1996}
1998void CalendarView::goNextMonth() 1997void CalendarView::goNextMonth()
1999{ 1998{
2000 mNavigator->selectNextMonth(); 1999 mNavigator->selectNextMonth();
2001} 2000}
2002 2001
2003void CalendarView::goPreviousMonth() 2002void CalendarView::goPreviousMonth()
2004{ 2003{
2005 mNavigator->selectPreviousMonth(); 2004 mNavigator->selectPreviousMonth();
2006} 2005}
2007void CalendarView::writeLocale() 2006void CalendarView::writeLocale()
2008{ 2007{
2009 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2008 //KPimGlobalPrefs::instance()->setGlobalConfig();
2010#if 0 2009#if 0
2011 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2010 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2012 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2011 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2013 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2012 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2014 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2013 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2015 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2014 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2016 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2015 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2017 dummy = KOPrefs::instance()->mUserDateFormatShort; 2016 dummy = KOPrefs::instance()->mUserDateFormatShort;
2018 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2017 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2019 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2018 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2020 KOPrefs::instance()->mDaylightsavingStart, 2019 KOPrefs::instance()->mDaylightsavingStart,
2021 KOPrefs::instance()->mDaylightsavingEnd ); 2020 KOPrefs::instance()->mDaylightsavingEnd );
2022 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 2021 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
2023#endif 2022#endif
2024} 2023}
2025void CalendarView::updateConfig() 2024void CalendarView::updateConfig()
2026{ 2025{
2027 writeLocale(); 2026 writeLocale();
2028 if ( KOPrefs::instance()->mUseAppColors ) 2027 if ( KOPrefs::instance()->mUseAppColors )
2029 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2028 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2030 emit configChanged(); 2029 emit configChanged();
2031 mTodoList->updateConfig(); 2030 mTodoList->updateConfig();
2032 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2031 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2033 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2032 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2034 // To make the "fill window" configurations work 2033 // To make the "fill window" configurations work
2035 //mViewManager->raiseCurrentView(); 2034 //mViewManager->raiseCurrentView();
2036} 2035}
2037 2036
2038 2037
2039void CalendarView::eventChanged(Event *event) 2038void CalendarView::eventChanged(Event *event)
2040{ 2039{
2041 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2040 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2042 //updateUnmanagedViews(); 2041 //updateUnmanagedViews();
2043} 2042}
2044 2043
2045void CalendarView::eventAdded(Event *event) 2044void CalendarView::eventAdded(Event *event)
2046{ 2045{
2047 changeEventDisplay(event,KOGlobals::EVENTADDED); 2046 changeEventDisplay(event,KOGlobals::EVENTADDED);
2048} 2047}
2049 2048
2050void CalendarView::eventToBeDeleted(Event *) 2049void CalendarView::eventToBeDeleted(Event *)
2051{ 2050{
2052 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2051 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2053} 2052}
2054 2053
2055void CalendarView::eventDeleted() 2054void CalendarView::eventDeleted()
2056{ 2055{
2057 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2056 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2058} 2057}
2059void CalendarView::changeTodoDisplay(Todo *which, int action) 2058void CalendarView::changeTodoDisplay(Todo *which, int action)
2060{ 2059{
2061 changeIncidenceDisplay((Incidence *)which, action); 2060 changeIncidenceDisplay((Incidence *)which, action);
2062 mDateNavigator->updateView(); //LR 2061 mDateNavigator->updateView(); //LR
2063 //mDialogManager->updateSearchDialog(); 2062 //mDialogManager->updateSearchDialog();
2064 2063
2065 if (which) { 2064 if (which) {
2066 mViewManager->updateWNview(); 2065 mViewManager->updateWNview();
2067 //mTodoList->updateView(); 2066 //mTodoList->updateView();
2068 } 2067 }
2069 2068
2070} 2069}
2071 2070
2072void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2071void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2073{ 2072{
2074 updateUnmanagedViews(); 2073 updateUnmanagedViews();
2075 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2074 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2076 if ( action == KOGlobals::EVENTDELETED ) { //delete 2075 if ( action == KOGlobals::EVENTDELETED ) { //delete
2077 mCalendar->checkAlarmForIncidence( 0, true ); 2076 mCalendar->checkAlarmForIncidence( 0, true );
2078 if ( mEventViewerDialog ) 2077 if ( mEventViewerDialog )
2079 mEventViewerDialog->hide(); 2078 mEventViewerDialog->hide();
2080 } 2079 }
2081 else 2080 else
2082 mCalendar->checkAlarmForIncidence( which , false ); 2081 mCalendar->checkAlarmForIncidence( which , false );
2083} 2082}
2084 2083
2085// most of the changeEventDisplays() right now just call the view's 2084// most of the changeEventDisplays() right now just call the view's
2086// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2085// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2087void CalendarView::changeEventDisplay(Event *which, int action) 2086void CalendarView::changeEventDisplay(Event *which, int action)
2088{ 2087{
2089 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2088 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2090 changeIncidenceDisplay((Incidence *)which, action); 2089 changeIncidenceDisplay((Incidence *)which, action);
2091 mDateNavigator->updateView(); 2090 mDateNavigator->updateView();
2092 //mDialogManager->updateSearchDialog(); 2091 //mDialogManager->updateSearchDialog();
2093 2092
2094 if (which) { 2093 if (which) {
2095 // If there is an event view visible update the display 2094 // If there is an event view visible update the display
2096 mViewManager->currentView()->changeEventDisplay(which,action); 2095 mViewManager->currentView()->changeEventDisplay(which,action);
2097 // TODO: check, if update needed 2096 // TODO: check, if update needed
2098 // if (which->getTodoStatus()) { 2097 // if (which->getTodoStatus()) {
2099 mTodoList->updateView(); 2098 mTodoList->updateView();
2100 // } 2099 // }
2101 } else { 2100 } else {
2102 mViewManager->currentView()->updateView(); 2101 mViewManager->currentView()->updateView();
2103 } 2102 }
2104} 2103}
2105 2104
2106 2105
2107void CalendarView::updateTodoViews() 2106void CalendarView::updateTodoViews()
2108{ 2107{
2109 2108
2110 mTodoList->updateView(); 2109 mTodoList->updateView();
2111 mViewManager->currentView()->updateView(); 2110 mViewManager->currentView()->updateView();
2112 2111
2113} 2112}
2114 2113
2115 2114
2116void CalendarView::updateView(const QDate &start, const QDate &end) 2115void CalendarView::updateView(const QDate &start, const QDate &end)
2117{ 2116{
2118 mTodoList->updateView(); 2117 mTodoList->updateView();
2119 mViewManager->updateView(start, end); 2118 mViewManager->updateView(start, end);
2120 //mDateNavigator->updateView(); 2119 //mDateNavigator->updateView();
2121} 2120}
2122 2121
2123void CalendarView::updateView() 2122void CalendarView::updateView()
2124{ 2123{
2125 DateList tmpList = mNavigator->selectedDates(); 2124 DateList tmpList = mNavigator->selectedDates();
2126 2125
2127 // We assume that the navigator only selects consecutive days. 2126 // We assume that the navigator only selects consecutive days.
2128 updateView( tmpList.first(), tmpList.last() ); 2127 updateView( tmpList.first(), tmpList.last() );
2129} 2128}
2130 2129
2131void CalendarView::updateUnmanagedViews() 2130void CalendarView::updateUnmanagedViews()
2132{ 2131{
2133 mDateNavigator->updateDayMatrix(); 2132 mDateNavigator->updateDayMatrix();
2134} 2133}
2135 2134
2136int CalendarView::msgItemDelete() 2135int CalendarView::msgItemDelete()
2137{ 2136{
2138 return KMessageBox::warningContinueCancel(this, 2137 return KMessageBox::warningContinueCancel(this,
2139 i18n("This item will be\npermanently deleted."), 2138 i18n("This item will be\npermanently deleted."),
2140 i18n("KO/Pi Confirmation"),i18n("Delete")); 2139 i18n("KO/Pi Confirmation"),i18n("Delete"));
2141} 2140}
2142 2141
2143 2142
2144void CalendarView::edit_cut() 2143void CalendarView::edit_cut()
2145{ 2144{
2146 Event *anEvent=0; 2145 Event *anEvent=0;
2147 2146
2148 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2147 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2149 2148
2150 if (mViewManager->currentView()->isEventView()) { 2149 if (mViewManager->currentView()->isEventView()) {
2151 if ( incidence && incidence->type() == "Event" ) { 2150 if ( incidence && incidence->type() == "Event" ) {
2152 anEvent = static_cast<Event *>(incidence); 2151 anEvent = static_cast<Event *>(incidence);
2153 } 2152 }
2154 } 2153 }
2155 2154
2156 if (!anEvent) { 2155 if (!anEvent) {
2157 KNotifyClient::beep(); 2156 KNotifyClient::beep();
2158 return; 2157 return;
2159 } 2158 }
2160 DndFactory factory( mCalendar ); 2159 DndFactory factory( mCalendar );
2161 factory.cutEvent(anEvent); 2160 factory.cutEvent(anEvent);
2162 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2161 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2163} 2162}
2164 2163
2165void CalendarView::edit_copy() 2164void CalendarView::edit_copy()
2166{ 2165{
2167 Event *anEvent=0; 2166 Event *anEvent=0;
2168 2167
2169 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2168 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2170 2169
2171 if (mViewManager->currentView()->isEventView()) { 2170 if (mViewManager->currentView()->isEventView()) {
2172 if ( incidence && incidence->type() == "Event" ) { 2171 if ( incidence && incidence->type() == "Event" ) {
2173 anEvent = static_cast<Event *>(incidence); 2172 anEvent = static_cast<Event *>(incidence);
2174 } 2173 }
2175 } 2174 }
2176 2175
2177 if (!anEvent) { 2176 if (!anEvent) {
2178 KNotifyClient::beep(); 2177 KNotifyClient::beep();
2179 return; 2178 return;
2180 } 2179 }
2181 DndFactory factory( mCalendar ); 2180 DndFactory factory( mCalendar );
2182 factory.copyEvent(anEvent); 2181 factory.copyEvent(anEvent);
2183} 2182}
2184 2183
2185void CalendarView::edit_paste() 2184void CalendarView::edit_paste()
2186{ 2185{
2187 QDate date = mNavigator->selectedDates().first(); 2186 QDate date = mNavigator->selectedDates().first();
2188 2187
2189 DndFactory factory( mCalendar ); 2188 DndFactory factory( mCalendar );
2190 Event *pastedEvent = factory.pasteEvent( date ); 2189 Event *pastedEvent = factory.pasteEvent( date );
2191 2190
2192 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2191 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2193} 2192}
2194 2193
2195void CalendarView::edit_options() 2194void CalendarView::edit_options()
2196{ 2195{
2197 mDialogManager->showOptionsDialog(); 2196 mDialogManager->showOptionsDialog();
2198 //writeSettings(); 2197 //writeSettings();
2199} 2198}
2200void CalendarView::edit_sync_options() 2199void CalendarView::edit_sync_options()
2201{ 2200{
2202 //mDialogManager->showSyncOptions(); 2201 //mDialogManager->showSyncOptions();
2203 //KOPrefs::instance()->mSyncAlgoPrefs 2202 //KOPrefs::instance()->mSyncAlgoPrefs
2204 QDialog dia( this, "dia", true ); 2203 QDialog dia( this, "dia", true );
2205 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2204 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2206 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2205 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2207 QVBoxLayout lay ( &dia ); 2206 QVBoxLayout lay ( &dia );
2208 lay.setSpacing( 2 ); 2207 lay.setSpacing( 2 );
2209 lay.setMargin( 3 ); 2208 lay.setMargin( 3 );
2210 lay.addWidget(&gr); 2209 lay.addWidget(&gr);
2211 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2210 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2212 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2211 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2213 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2212 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2214 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2213 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2215 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2214 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2216 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2215 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2217 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2216 //QRadioButton both( i18n("Take both on conflict"), &gr );
2218 QPushButton pb ( "OK", &dia); 2217 QPushButton pb ( "OK", &dia);
2219 lay.addWidget( &pb ); 2218 lay.addWidget( &pb );
2220 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2219 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2221 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { 2220 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2222 case 0: 2221 case 0:
2223 loc.setChecked( true); 2222 loc.setChecked( true);
2224 break; 2223 break;
2225 case 1: 2224 case 1:
2226 rem.setChecked( true ); 2225 rem.setChecked( true );
2227 break; 2226 break;
2228 case 2: 2227 case 2:
2229 newest.setChecked( true); 2228 newest.setChecked( true);
2230 break; 2229 break;
2231 case 3: 2230 case 3:
2232 ask.setChecked( true); 2231 ask.setChecked( true);
2233 break; 2232 break;
2234 case 4: 2233 case 4:
2235 f_loc.setChecked( true); 2234 f_loc.setChecked( true);
2236 break; 2235 break;
2237 case 5: 2236 case 5:
2238 f_rem.setChecked( true); 2237 f_rem.setChecked( true);
2239 break; 2238 break;
2240 case 6: 2239 case 6:
2241 // both.setChecked( true); 2240 // both.setChecked( true);
2242 break; 2241 break;
2243 default: 2242 default:
2244 break; 2243 break;
2245 } 2244 }
2246 if ( dia.exec() ) { 2245 if ( dia.exec() ) {
2247 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2246 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2248 } 2247 }
2249 2248
2250} 2249}
2251 2250
2252void CalendarView::slotSelectPickerDate( QDate d) 2251void CalendarView::slotSelectPickerDate( QDate d)
2253{ 2252{
2254 mDateFrame->hide(); 2253 mDateFrame->hide();
2255 if ( mDatePickerMode == 1 ) { 2254 if ( mDatePickerMode == 1 ) {
2256 mNavigator->slotDaySelect( d ); 2255 mNavigator->slotDaySelect( d );
2257 } else if ( mDatePickerMode == 2 ) { 2256 } else if ( mDatePickerMode == 2 ) {
2258 if ( mMoveIncidence->type() == "Todo" ) { 2257 if ( mMoveIncidence->type() == "Todo" ) {
2259 Todo * to = (Todo *) mMoveIncidence; 2258 Todo * to = (Todo *) mMoveIncidence;
2260 QTime tim; 2259 QTime tim;
2261 if ( to->hasDueDate() ) 2260 if ( to->hasDueDate() )
2262 tim = to->dtDue().time(); 2261 tim = to->dtDue().time();
2263 else { 2262 else {
2264 tim = QTime ( 0,0,0 ); 2263 tim = QTime ( 0,0,0 );
2265 to->setFloats( true ); 2264 to->setFloats( true );
2266 to->setHasDueDate( true ); 2265 to->setHasDueDate( true );
2267 } 2266 }
2268 QDateTime dt ( d,tim ); 2267 QDateTime dt ( d,tim );
2269 to->setDtDue( dt ); 2268 to->setDtDue( dt );
2270 todoChanged( to ); 2269 todoChanged( to );
2271 } else { 2270 } else {
2272 QTime tim = mMoveIncidence->dtStart().time(); 2271 QTime tim = mMoveIncidence->dtStart().time();
2273 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2272 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2274 QDateTime dt ( d,tim ); 2273 QDateTime dt ( d,tim );
2275 mMoveIncidence->setDtStart( dt ); 2274 mMoveIncidence->setDtStart( dt );
2276 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2275 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2277 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2276 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2278 } 2277 }
2279 2278
2280 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2279 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2281 } 2280 }
2282} 2281}
2283 2282
2284void CalendarView::removeCategories() 2283void CalendarView::removeCategories()
2285{ 2284{
2286 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2285 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2287 QStringList catList = KOPrefs::instance()->mCustomCategories; 2286 QStringList catList = KOPrefs::instance()->mCustomCategories;
2288 QStringList catIncList; 2287 QStringList catIncList;
2289 QStringList newCatList; 2288 QStringList newCatList;
2290 Incidence* inc = incList.first(); 2289 Incidence* inc = incList.first();
2291 int i; 2290 int i;
2292 int count = 0; 2291 int count = 0;
2293 while ( inc ) { 2292 while ( inc ) {
2294 newCatList.clear(); 2293 newCatList.clear();
2295 catIncList = inc->categories() ; 2294 catIncList = inc->categories() ;
2296 for( i = 0; i< catIncList.count(); ++i ) { 2295 for( i = 0; i< catIncList.count(); ++i ) {
2297 if ( catList.contains (catIncList[i])) 2296 if ( catList.contains (catIncList[i]))
2298 newCatList.append( catIncList[i] ); 2297 newCatList.append( catIncList[i] );
2299 } 2298 }
2300 newCatList.sort(); 2299 newCatList.sort();
2301 inc->setCategories( newCatList.join(",") ); 2300 inc->setCategories( newCatList.join(",") );
2302 inc = incList.next(); 2301 inc = incList.next();
2303 } 2302 }
2304} 2303}
2305 2304
2306int CalendarView::addCategories() 2305int CalendarView::addCategories()
2307{ 2306{
2308 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2307 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2309 QStringList catList = KOPrefs::instance()->mCustomCategories; 2308 QStringList catList = KOPrefs::instance()->mCustomCategories;
2310 QStringList catIncList; 2309 QStringList catIncList;
2311 Incidence* inc = incList.first(); 2310 Incidence* inc = incList.first();
2312 int i; 2311 int i;
2313 int count = 0; 2312 int count = 0;
2314 while ( inc ) { 2313 while ( inc ) {
2315 catIncList = inc->categories() ; 2314 catIncList = inc->categories() ;
2316 for( i = 0; i< catIncList.count(); ++i ) { 2315 for( i = 0; i< catIncList.count(); ++i ) {
2317 if ( !catList.contains (catIncList[i])) { 2316 if ( !catList.contains (catIncList[i])) {
2318 catList.append( catIncList[i] ); 2317 catList.append( catIncList[i] );
2319 //qDebug("add cat %s ", catIncList[i].latin1()); 2318 //qDebug("add cat %s ", catIncList[i].latin1());
2320 ++count; 2319 ++count;
2321 } 2320 }
2322 } 2321 }
2323 inc = incList.next(); 2322 inc = incList.next();
2324 } 2323 }
2325 catList.sort(); 2324 catList.sort();
2326 KOPrefs::instance()->mCustomCategories = catList; 2325 KOPrefs::instance()->mCustomCategories = catList;
2327 return count; 2326 return count;
2328} 2327}
2329 2328
2330void CalendarView::manageCategories() 2329void CalendarView::manageCategories()
2331{ 2330{
2332 KOCatPrefs* cp = new KOCatPrefs(); 2331 KOCatPrefs* cp = new KOCatPrefs();
2333 cp->show(); 2332 cp->show();
2334 int w =cp->sizeHint().width() ; 2333 int w =cp->sizeHint().width() ;
2335 int h = cp->sizeHint().height() ; 2334 int h = cp->sizeHint().height() ;
2336 int dw = QApplication::desktop()->width(); 2335 int dw = QApplication::desktop()->width();
2337 int dh = QApplication::desktop()->height(); 2336 int dh = QApplication::desktop()->height();
2338 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2337 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2339 if ( !cp->exec() ) { 2338 if ( !cp->exec() ) {
2340 delete cp; 2339 delete cp;
2341 return; 2340 return;
2342 } 2341 }
2343 int count = 0; 2342 int count = 0;
2344 if ( cp->addCat() ) { 2343 if ( cp->addCat() ) {
2345 count = addCategories(); 2344 count = addCategories();
2346 if ( count ) { 2345 if ( count ) {
2347 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2346 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2348 writeSettings(); 2347 writeSettings();
2349 } 2348 }
2350 } else { 2349 } else {
2351 removeCategories(); 2350 removeCategories();
2352 updateView(); 2351 updateView();
2353 } 2352 }
2354 delete cp; 2353 delete cp;
2355} 2354}
2356 2355
2357void CalendarView::beamIncidence(Incidence * Inc) 2356void CalendarView::beamIncidence(Incidence * Inc)
2358{ 2357{
2359 QPtrList<Incidence> delSel ; 2358 QPtrList<Incidence> delSel ;
2360 delSel.append(Inc); 2359 delSel.append(Inc);
2361 beamIncidenceList( delSel ); 2360 beamIncidenceList( delSel );
2362} 2361}
2363void CalendarView::beamCalendar() 2362void CalendarView::beamCalendar()
2364{ 2363{
2365 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2364 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2366 //qDebug("beamCalendar() "); 2365 //qDebug("beamCalendar() ");
2367 beamIncidenceList( delSel ); 2366 beamIncidenceList( delSel );
2368} 2367}
2369void CalendarView::beamFilteredCalendar() 2368void CalendarView::beamFilteredCalendar()
2370{ 2369{
2371 QPtrList<Incidence> delSel = mCalendar->incidences(); 2370 QPtrList<Incidence> delSel = mCalendar->incidences();
2372 //qDebug("beamFilteredCalendar() "); 2371 //qDebug("beamFilteredCalendar() ");
2373 beamIncidenceList( delSel ); 2372 beamIncidenceList( delSel );
2374} 2373}
2375void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2374void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2376{ 2375{
2377 if ( beamDialog->exec () == QDialog::Rejected ) 2376 if ( beamDialog->exec () == QDialog::Rejected )
2378 return; 2377 return;
2379 2378
2380 QString fn = "/tmp/kopibeamfile"; 2379 QString fn = "/tmp/kopibeamfile";
2381 QString mes; 2380 QString mes;
2382 bool createbup = true; 2381 bool createbup = true;
2383 if ( createbup ) { 2382 if ( createbup ) {
2384 QString description = "\n"; 2383 QString description = "\n";
2385 CalendarLocal* cal = new CalendarLocal(); 2384 CalendarLocal* cal = new CalendarLocal();
2386 if ( beamDialog->beamLocal() ) 2385 if ( beamDialog->beamLocal() )
2387 cal->setLocalTime(); 2386 cal->setLocalTime();
2388 else 2387 else
2389 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2388 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2390 Incidence *incidence = delSel.first(); 2389 Incidence *incidence = delSel.first();
2391 bool addText = false; 2390 bool addText = false;
2392 if ( delSel.count() < 10 ) 2391 if ( delSel.count() < 10 )
2393 addText = true; 2392 addText = true;
2394 else { 2393 else {
2395 description.sprintf(i18n(" %d items?"),delSel.count() ); 2394 description.sprintf(i18n(" %d items?"),delSel.count() );
2396 } 2395 }
2397 while ( incidence ) { 2396 while ( incidence ) {
2398 Incidence *in = incidence->clone(); 2397 Incidence *in = incidence->clone();
2399 if ( addText ) 2398 if ( addText )
2400 description += in->summary() + "\n"; 2399 description += in->summary() + "\n";
2401 cal->addIncidence( in ); 2400 cal->addIncidence( in );
2402 incidence = delSel.next(); 2401 incidence = delSel.next();
2403 } 2402 }
2404 if ( beamDialog->beamVcal() ) { 2403 if ( beamDialog->beamVcal() ) {
2405 fn += ".vcs"; 2404 fn += ".vcs";
2406 FileStorage storage( cal, fn, new VCalFormat ); 2405 FileStorage storage( cal, fn, new VCalFormat );
2407 storage.save(); 2406 storage.save();
2408 } else { 2407 } else {
2409 fn += ".ics"; 2408 fn += ".ics";
2410 FileStorage storage( cal, fn, new ICalFormat( ) ); 2409 FileStorage storage( cal, fn, new ICalFormat( ) );
2411 storage.save(); 2410 storage.save();
2412 } 2411 }
2413 delete cal; 2412 delete cal;
2414 mes = i18n("KO/Pi: Ready for beaming"); 2413 mes = i18n("KO/Pi: Ready for beaming");
2415 setCaption(mes); 2414 setCaption(mes);
2416 2415
2417#ifndef DESKTOP_VERSION 2416#ifndef DESKTOP_VERSION
2418 Ir *ir = new Ir( this ); 2417 Ir *ir = new Ir( this );
2419 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2418 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2420 ir->send( fn, description, "text/x-vCalendar" ); 2419 ir->send( fn, description, "text/x-vCalendar" );
2421#endif 2420#endif
2422 } 2421 }
2423} 2422}
2424void CalendarView::beamDone( Ir *ir ) 2423void CalendarView::beamDone( Ir *ir )
2425{ 2424{
2426#ifndef DESKTOP_VERSION 2425#ifndef DESKTOP_VERSION
2427 delete ir; 2426 delete ir;
2428#endif 2427#endif
2429} 2428}
2430 2429
2431void CalendarView::moveIncidence(Incidence * inc ) 2430void CalendarView::moveIncidence(Incidence * inc )
2432{ 2431{
2433 if ( !inc ) return; 2432 if ( !inc ) return;
2434 // qDebug("showDatePickerForIncidence( ) "); 2433 // qDebug("showDatePickerForIncidence( ) ");
2435 if ( mDateFrame->isVisible() ) 2434 if ( mDateFrame->isVisible() )
2436 mDateFrame->hide(); 2435 mDateFrame->hide();
2437 else { 2436 else {
2438 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2437 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2439 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2438 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2440 int dw = QApplication::desktop()->width(); 2439 int dw = QApplication::desktop()->width();
2441 int dh = QApplication::desktop()->height(); 2440 int dh = QApplication::desktop()->height();
2442 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2441 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2443 mDateFrame->show(); 2442 mDateFrame->show();
2444 } 2443 }
2445 mDatePickerMode = 2; 2444 mDatePickerMode = 2;
2446 mMoveIncidence = inc ; 2445 mMoveIncidence = inc ;
2447 QDate da; 2446 QDate da;
2448 if ( mMoveIncidence->type() == "Todo" ) { 2447 if ( mMoveIncidence->type() == "Todo" ) {
2449 Todo * to = (Todo *) mMoveIncidence; 2448 Todo * to = (Todo *) mMoveIncidence;
2450 if ( to->hasDueDate() ) 2449 if ( to->hasDueDate() )
2451 da = to->dtDue().date(); 2450 da = to->dtDue().date();
2452 else 2451 else
2453 da = QDate::currentDate(); 2452 da = QDate::currentDate();
2454 } else { 2453 } else {
2455 da = mMoveIncidence->dtStart().date(); 2454 da = mMoveIncidence->dtStart().date();
2456 } 2455 }
2457 mDatePicker->setDate( da ); 2456 mDatePicker->setDate( da );
2458} 2457}
2459void CalendarView::showDatePicker( ) 2458void CalendarView::showDatePicker( )
2460{ 2459{
2461 //qDebug("CalendarView::showDatePicker( ) "); 2460 //qDebug("CalendarView::showDatePicker( ) ");
2462 if ( mDateFrame->isVisible() ) 2461 if ( mDateFrame->isVisible() )
2463 mDateFrame->hide(); 2462 mDateFrame->hide();
2464 else { 2463 else {
2465 int w =mDatePicker->sizeHint().width() ; 2464 int w =mDatePicker->sizeHint().width() ;
2466 int h = mDatePicker->sizeHint().height() ; 2465 int h = mDatePicker->sizeHint().height() ;
2467 int dw = QApplication::desktop()->width(); 2466 int dw = QApplication::desktop()->width();
2468 int dh = QApplication::desktop()->height(); 2467 int dh = QApplication::desktop()->height();
2469 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2468 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2470 mDateFrame->show(); 2469 mDateFrame->show();
2471 } 2470 }
2472 mDatePickerMode = 1; 2471 mDatePickerMode = 1;
2473 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2472 mDatePicker->setDate( mNavigator->selectedDates().first() );
2474} 2473}
2475 2474
2476void CalendarView::showEventEditor() 2475void CalendarView::showEventEditor()
2477{ 2476{
2478#ifdef DESKTOP_VERSION 2477#ifdef DESKTOP_VERSION
2479 mEventEditor->show(); 2478 mEventEditor->show();
2480#else 2479#else
2481 mEventEditor->showMaximized(); 2480 mEventEditor->showMaximized();
2482#endif 2481#endif
2483} 2482}
2484void CalendarView::showTodoEditor() 2483void CalendarView::showTodoEditor()
2485{ 2484{
2486#ifdef DESKTOP_VERSION 2485#ifdef DESKTOP_VERSION
2487 mTodoEditor->show(); 2486 mTodoEditor->show();
2488#else 2487#else
2489 mTodoEditor->showMaximized(); 2488 mTodoEditor->showMaximized();
2490#endif 2489#endif
2491} 2490}
2492 2491
2493void CalendarView::cloneIncidence() 2492void CalendarView::cloneIncidence()
2494{ 2493{
2495 Incidence *incidence = currentSelection(); 2494 Incidence *incidence = currentSelection();
2496 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2495 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2497 if ( incidence ) { 2496 if ( incidence ) {
2498 cloneIncidence(incidence); 2497 cloneIncidence(incidence);
2499 } 2498 }
2500} 2499}
2501void CalendarView::moveIncidence() 2500void CalendarView::moveIncidence()
2502{ 2501{
2503 Incidence *incidence = currentSelection(); 2502 Incidence *incidence = currentSelection();
2504 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2503 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2505 if ( incidence ) { 2504 if ( incidence ) {
2506 moveIncidence(incidence); 2505 moveIncidence(incidence);
2507 } 2506 }
2508} 2507}
2509void CalendarView::beamIncidence() 2508void CalendarView::beamIncidence()
2510{ 2509{
2511 Incidence *incidence = currentSelection(); 2510 Incidence *incidence = currentSelection();
2512 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2511 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2513 if ( incidence ) { 2512 if ( incidence ) {
2514 beamIncidence(incidence); 2513 beamIncidence(incidence);
2515 } 2514 }
2516} 2515}
2517void CalendarView::toggleCancelIncidence() 2516void CalendarView::toggleCancelIncidence()
2518{ 2517{
2519 Incidence *incidence = currentSelection(); 2518 Incidence *incidence = currentSelection();
2520 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2519 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2521 if ( incidence ) { 2520 if ( incidence ) {
2522 cancelIncidence(incidence); 2521 cancelIncidence(incidence);
2523 } 2522 }
2524} 2523}
2525 2524
2526 2525
2527void CalendarView::cancelIncidence(Incidence * inc ) 2526void CalendarView::cancelIncidence(Incidence * inc )
2528{ 2527{
2529 inc->setCancelled( ! inc->cancelled() ); 2528 inc->setCancelled( ! inc->cancelled() );
2530 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2529 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2531 updateView(); 2530 updateView();
2532} 2531}
2533void CalendarView::cloneIncidence(Incidence * orgInc ) 2532void CalendarView::cloneIncidence(Incidence * orgInc )
2534{ 2533{
2535 Incidence * newInc = orgInc->clone(); 2534 Incidence * newInc = orgInc->clone();
2536 newInc->recreate(); 2535 newInc->recreate();
2537 2536
2538 if ( newInc->type() == "Todo" ) { 2537 if ( newInc->type() == "Todo" ) {
2539 Todo* t = (Todo*) newInc; 2538 Todo* t = (Todo*) newInc;
2540 mTodoEditor->editTodo( t ); 2539 mTodoEditor->editTodo( t );
2541 showTodoEditor(); 2540 showTodoEditor();
2542 if ( mTodoEditor->exec() ) { 2541 if ( mTodoEditor->exec() ) {
2543 mCalendar->addTodo( t ); 2542 mCalendar->addTodo( t );
2544 updateView(); 2543 updateView();
2545 } else { 2544 } else {
2546 delete t; 2545 delete t;
2547 } 2546 }
2548 } 2547 }
2549 else { 2548 else {
2550 Event* e = (Event*) newInc; 2549 Event* e = (Event*) newInc;
2551 mEventEditor->editEvent( e ); 2550 mEventEditor->editEvent( e );
2552 showEventEditor(); 2551 showEventEditor();
2553 if ( mEventEditor->exec() ) { 2552 if ( mEventEditor->exec() ) {
2554 mCalendar->addEvent( e ); 2553 mCalendar->addEvent( e );
2555 updateView(); 2554 updateView();
2556 } else { 2555 } else {
2557 delete e; 2556 delete e;
2558 } 2557 }
2559 } 2558 }
2560} 2559}
2561 2560
2562void CalendarView::newEvent() 2561void CalendarView::newEvent()
2563{ 2562{
2564 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2563 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2565 KOAgendaView *aView = mViewManager->agendaView(); 2564 KOAgendaView *aView = mViewManager->agendaView();
2566 if (aView) { 2565 if (aView) {
2567 if (aView->selectionStart().isValid()) { 2566 if (aView->selectionStart().isValid()) {
2568 if (aView->selectedIsAllDay()) { 2567 if (aView->selectedIsAllDay()) {
2569 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2568 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2570 } else { 2569 } else {
2571 newEvent(aView->selectionStart(),aView->selectionEnd()); 2570 newEvent(aView->selectionStart(),aView->selectionEnd());
2572 } 2571 }
2573 return; 2572 return;
2574 } 2573 }
2575 } 2574 }
2576 2575
2577 QDate date = mNavigator->selectedDates().first(); 2576 QDate date = mNavigator->selectedDates().first();
2578 QDateTime current = QDateTime::currentDateTime(); 2577 QDateTime current = QDateTime::currentDateTime();
2579 if ( date <= current.date() ) { 2578 if ( date <= current.date() ) {
2580 int hour = current.time().hour() +1; 2579 int hour = current.time().hour() +1;
2581 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2580 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2582 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2581 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2583 } else 2582 } else
2584 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2583 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2585 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2584 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2586 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2585 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2587} 2586}
2588 2587
2589void CalendarView::newEvent(QDateTime fh) 2588void CalendarView::newEvent(QDateTime fh)
2590{ 2589{
2591 newEvent(fh, 2590 newEvent(fh,
2592 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2591 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2593} 2592}
2594 2593
2595void CalendarView::newEvent(QDate dt) 2594void CalendarView::newEvent(QDate dt)
2596{ 2595{
2597 newEvent(QDateTime(dt, QTime(0,0,0)), 2596 newEvent(QDateTime(dt, QTime(0,0,0)),
2598 QDateTime(dt, QTime(0,0,0)), true); 2597 QDateTime(dt, QTime(0,0,0)), true);
2599} 2598}
2600 2599
2601void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2600void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2602{ 2601{
2603 2602
2604 mEventEditor->newEvent(fromHint,toHint,allDay); 2603 mEventEditor->newEvent(fromHint,toHint,allDay);
2605 if ( mFilterView->filtersEnabled() ) { 2604 if ( mFilterView->filtersEnabled() ) {
2606 CalFilter *filter = mFilterView->selectedFilter(); 2605 CalFilter *filter = mFilterView->selectedFilter();
2607 if (filter && filter->showCategories()) { 2606 if (filter && filter->showCategories()) {
2608 mEventEditor->setCategories(filter->categoryList().join(",") ); 2607 mEventEditor->setCategories(filter->categoryList().join(",") );
2609 } 2608 }
2610 if ( filter ) 2609 if ( filter )
2611 mEventEditor->setSecrecy( filter->getSecrecy() ); 2610 mEventEditor->setSecrecy( filter->getSecrecy() );
2612 } 2611 }
2613 showEventEditor(); 2612 showEventEditor();
2614} 2613}
2615void CalendarView::todoAdded(Todo * t) 2614void CalendarView::todoAdded(Todo * t)
2616{ 2615{
2617 2616
2618 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2617 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2619 updateTodoViews(); 2618 updateTodoViews();
2620} 2619}
2621void CalendarView::todoChanged(Todo * t) 2620void CalendarView::todoChanged(Todo * t)
2622{ 2621{
2623 emit todoModified( t, 4 ); 2622 emit todoModified( t, 4 );
2624 // updateTodoViews(); 2623 // updateTodoViews();
2625} 2624}
2626void CalendarView::todoToBeDeleted(Todo *) 2625void CalendarView::todoToBeDeleted(Todo *)
2627{ 2626{
2628 //qDebug("todoToBeDeleted(Todo *) "); 2627 //qDebug("todoToBeDeleted(Todo *) ");
2629 updateTodoViews(); 2628 updateTodoViews();
2630} 2629}
2631void CalendarView::todoDeleted() 2630void CalendarView::todoDeleted()
2632{ 2631{
2633 //qDebug(" todoDeleted()"); 2632 //qDebug(" todoDeleted()");
2634 updateTodoViews(); 2633 updateTodoViews();
2635} 2634}
2636 2635
2637 2636
2638 2637
2639void CalendarView::newTodo() 2638void CalendarView::newTodo()
2640{ 2639{
2641 2640
2642 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2641 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2643 if ( mFilterView->filtersEnabled() ) { 2642 if ( mFilterView->filtersEnabled() ) {
2644 CalFilter *filter = mFilterView->selectedFilter(); 2643 CalFilter *filter = mFilterView->selectedFilter();
2645 if (filter && filter->showCategories()) { 2644 if (filter && filter->showCategories()) {
2646 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2645 mTodoEditor->setCategories(filter->categoryList().join(",") );
2647 } 2646 }
2648 if ( filter ) 2647 if ( filter )
2649 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2648 mTodoEditor->setSecrecy( filter->getSecrecy() );
2650 } 2649 }
2651 showTodoEditor(); 2650 showTodoEditor();
2652} 2651}
2653 2652
2654void CalendarView::newSubTodo() 2653void CalendarView::newSubTodo()
2655{ 2654{
2656 Todo *todo = selectedTodo(); 2655 Todo *todo = selectedTodo();
2657 if ( todo ) newSubTodo( todo ); 2656 if ( todo ) newSubTodo( todo );
2658} 2657}
2659 2658
2660void CalendarView::newSubTodo(Todo *parentEvent) 2659void CalendarView::newSubTodo(Todo *parentEvent)
2661{ 2660{
2662 2661
2663 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2662 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2664 showTodoEditor(); 2663 showTodoEditor();
2665} 2664}
2666 2665
2667void CalendarView::newFloatingEvent() 2666void CalendarView::newFloatingEvent()
2668{ 2667{
2669 DateList tmpList = mNavigator->selectedDates(); 2668 DateList tmpList = mNavigator->selectedDates();
2670 QDate date = tmpList.first(); 2669 QDate date = tmpList.first();
2671 2670
2672 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2671 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2673 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2672 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2674} 2673}
2675 2674
2676 2675
2677void CalendarView::editEvent( Event *event ) 2676void CalendarView::editEvent( Event *event )
2678{ 2677{
2679 2678
2680 if ( !event ) return; 2679 if ( !event ) return;
2681 if ( event->isReadOnly() ) { 2680 if ( event->isReadOnly() ) {
2682 showEvent( event ); 2681 showEvent( event );
2683 return; 2682 return;
2684 } 2683 }
2685 mEventEditor->editEvent( event , mFlagEditDescription); 2684 mEventEditor->editEvent( event , mFlagEditDescription);
2686 showEventEditor(); 2685 showEventEditor();
2687} 2686}
2688void CalendarView::editJournal( Journal *jour ) 2687void CalendarView::editJournal( Journal *jour )
2689{ 2688{
2690 if ( !jour ) return; 2689 if ( !jour ) return;
2691 mDialogManager->hideSearchDialog(); 2690 mDialogManager->hideSearchDialog();
2692 mViewManager->showJournalView(); 2691 mViewManager->showJournalView();
2693 mNavigator->slotDaySelect( jour->dtStart().date() ); 2692 mNavigator->slotDaySelect( jour->dtStart().date() );
2694} 2693}
2695void CalendarView::editTodo( Todo *todo ) 2694void CalendarView::editTodo( Todo *todo )
2696{ 2695{
2697 if ( !todo ) return; 2696 if ( !todo ) return;
2698 2697
2699 if ( todo->isReadOnly() ) { 2698 if ( todo->isReadOnly() ) {
2700 showTodo( todo ); 2699 showTodo( todo );
2701 return; 2700 return;
2702 } 2701 }
2703 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2702 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2704 showTodoEditor(); 2703 showTodoEditor();
2705 2704
2706} 2705}
2707 2706
2708KOEventViewerDialog* CalendarView::getEventViewerDialog() 2707KOEventViewerDialog* CalendarView::getEventViewerDialog()
2709{ 2708{
2710 if ( !mEventViewerDialog ) { 2709 if ( !mEventViewerDialog ) {
2711 mEventViewerDialog = new KOEventViewerDialog(this); 2710 mEventViewerDialog = new KOEventViewerDialog(this);
2712 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2711 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2713 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2712 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2714 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2713 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2715 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2714 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2716 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2715 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2717 viewManager(), SLOT( showAgendaView( bool ) ) ); 2716 viewManager(), SLOT( showAgendaView( bool ) ) );
2718 mEventViewerDialog->resize( 640, 480 ); 2717 mEventViewerDialog->resize( 640, 480 );
2719 2718
2720 } 2719 }
2721 return mEventViewerDialog; 2720 return mEventViewerDialog;
2722} 2721}
2723void CalendarView::showEvent(Event *event) 2722void CalendarView::showEvent(Event *event)
2724{ 2723{
2725 getEventViewerDialog()->setEvent(event); 2724 getEventViewerDialog()->setEvent(event);
2726 getEventViewerDialog()->showMe(); 2725 getEventViewerDialog()->showMe();
2727} 2726}
2728 2727
2729void CalendarView::showTodo(Todo *event) 2728void CalendarView::showTodo(Todo *event)
2730{ 2729{
2731 getEventViewerDialog()->setTodo(event); 2730 getEventViewerDialog()->setTodo(event);
2732 getEventViewerDialog()->showMe(); 2731 getEventViewerDialog()->showMe();
2733} 2732}
2734void CalendarView::showJournal( Journal *jour ) 2733void CalendarView::showJournal( Journal *jour )
2735{ 2734{
2736 getEventViewerDialog()->setJournal(jour); 2735 getEventViewerDialog()->setJournal(jour);
2737 getEventViewerDialog()->showMe(); 2736 getEventViewerDialog()->showMe();
2738 2737
2739} 2738}
2740// void CalendarView::todoModified (Todo *event, int changed) 2739// void CalendarView::todoModified (Todo *event, int changed)
2741// { 2740// {
2742// // if (mDialogList.find (event) != mDialogList.end ()) { 2741// // if (mDialogList.find (event) != mDialogList.end ()) {
2743// // kdDebug() << "Todo modified and open" << endl; 2742// // kdDebug() << "Todo modified and open" << endl;
2744// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2743// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2745// // temp->modified (changed); 2744// // temp->modified (changed);
2746 2745
2747// // } 2746// // }
2748 2747
2749// mViewManager->updateView(); 2748// mViewManager->updateView();
2750// } 2749// }
2751 2750
2752void CalendarView::appointment_show() 2751void CalendarView::appointment_show()
2753{ 2752{
2754 Event *anEvent = 0; 2753 Event *anEvent = 0;
2755 2754
2756 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2755 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2757 2756
2758 if (mViewManager->currentView()->isEventView()) { 2757 if (mViewManager->currentView()->isEventView()) {
2759 if ( incidence && incidence->type() == "Event" ) { 2758 if ( incidence && incidence->type() == "Event" ) {
2760 anEvent = static_cast<Event *>(incidence); 2759 anEvent = static_cast<Event *>(incidence);
2761 } 2760 }
2762 } 2761 }
2763 2762
2764 if (!anEvent) { 2763 if (!anEvent) {
2765 KNotifyClient::beep(); 2764 KNotifyClient::beep();
2766 return; 2765 return;
2767 } 2766 }
2768 2767
2769 showEvent(anEvent); 2768 showEvent(anEvent);
2770} 2769}
2771 2770
2772void CalendarView::appointment_edit() 2771void CalendarView::appointment_edit()
2773{ 2772{
2774 Event *anEvent = 0; 2773 Event *anEvent = 0;
2775 2774
2776 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2775 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2777 2776
2778 if (mViewManager->currentView()->isEventView()) { 2777 if (mViewManager->currentView()->isEventView()) {
2779 if ( incidence && incidence->type() == "Event" ) { 2778 if ( incidence && incidence->type() == "Event" ) {
2780 anEvent = static_cast<Event *>(incidence); 2779 anEvent = static_cast<Event *>(incidence);
2781 } 2780 }
2782 } 2781 }
2783 2782
2784 if (!anEvent) { 2783 if (!anEvent) {
2785 KNotifyClient::beep(); 2784 KNotifyClient::beep();
2786 return; 2785 return;
2787 } 2786 }
2788 2787
2789 editEvent(anEvent); 2788 editEvent(anEvent);
2790} 2789}
2791 2790
2792void CalendarView::appointment_delete() 2791void CalendarView::appointment_delete()
2793{ 2792{
2794 Event *anEvent = 0; 2793 Event *anEvent = 0;
2795 2794
2796 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2795 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2797 2796
2798 if (mViewManager->currentView()->isEventView()) { 2797 if (mViewManager->currentView()->isEventView()) {
2799 if ( incidence && incidence->type() == "Event" ) { 2798 if ( incidence && incidence->type() == "Event" ) {
2800 anEvent = static_cast<Event *>(incidence); 2799 anEvent = static_cast<Event *>(incidence);
2801 } 2800 }
2802 } 2801 }
2803 2802
2804 if (!anEvent) { 2803 if (!anEvent) {
2805 KNotifyClient::beep(); 2804 KNotifyClient::beep();
2806 return; 2805 return;
2807 } 2806 }
2808 2807
2809 deleteEvent(anEvent); 2808 deleteEvent(anEvent);
2810} 2809}
2811 2810
2812void CalendarView::todo_unsub(Todo *anTodo ) 2811void CalendarView::todo_unsub(Todo *anTodo )
2813{ 2812{
2814 // Todo *anTodo = selectedTodo(); 2813 // Todo *anTodo = selectedTodo();
2815 if (!anTodo) return; 2814 if (!anTodo) return;
2816 if (!anTodo->relatedTo()) return; 2815 if (!anTodo->relatedTo()) return;
2817 anTodo->relatedTo()->removeRelation(anTodo); 2816 anTodo->relatedTo()->removeRelation(anTodo);
2818 anTodo->setRelatedTo(0); 2817 anTodo->setRelatedTo(0);
2819 anTodo->updated(); 2818 anTodo->updated();
2820 anTodo->setRelatedToUid(""); 2819 anTodo->setRelatedToUid("");
2821 setModified(true); 2820 setModified(true);
2822 updateView(); 2821 updateView();
2823} 2822}
2824 2823
2825void CalendarView::deleteTodo(Todo *todo) 2824void CalendarView::deleteTodo(Todo *todo)
2826{ 2825{
2827 if (!todo) { 2826 if (!todo) {
2828 KNotifyClient::beep(); 2827 KNotifyClient::beep();
2829 return; 2828 return;
2830 } 2829 }
2831 if (KOPrefs::instance()->mConfirm) { 2830 if (KOPrefs::instance()->mConfirm) {
2832 switch (msgItemDelete()) { 2831 switch (msgItemDelete()) {
2833 case KMessageBox::Continue: // OK 2832 case KMessageBox::Continue: // OK
2834 if (!todo->relations().isEmpty()) { 2833 if (!todo->relations().isEmpty()) {
2835 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2834 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2836 i18n("Delete To-Do")); 2835 i18n("Delete To-Do"));
2837 } else { 2836 } else {
2838 checkExternalId( todo ); 2837 checkExternalId( todo );
2839 calendar()->deleteTodo(todo); 2838 calendar()->deleteTodo(todo);
2840 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2839 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2841 updateView(); 2840 updateView();
2842 } 2841 }
2843 break; 2842 break;
2844 } // switch 2843 } // switch
2845 } else { 2844 } else {
2846 if (!todo->relations().isEmpty()) { 2845 if (!todo->relations().isEmpty()) {
2847 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2846 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2848 i18n("Delete To-Do")); 2847 i18n("Delete To-Do"));
2849 } else { 2848 } else {
2850 checkExternalId( todo ); 2849 checkExternalId( todo );
2851 mCalendar->deleteTodo(todo); 2850 mCalendar->deleteTodo(todo);
2852 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2851 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2853 updateView(); 2852 updateView();
2854 } 2853 }
2855 } 2854 }
2856 emit updateSearchDialog(); 2855 emit updateSearchDialog();
2857} 2856}
2858void CalendarView::deleteJournal(Journal *jour) 2857void CalendarView::deleteJournal(Journal *jour)
2859{ 2858{
2860 if (!jour) { 2859 if (!jour) {
2861 KNotifyClient::beep(); 2860 KNotifyClient::beep();
2862 return; 2861 return;
2863 } 2862 }
2864 if (KOPrefs::instance()->mConfirm) { 2863 if (KOPrefs::instance()->mConfirm) {
2865 switch (msgItemDelete()) { 2864 switch (msgItemDelete()) {
2866 case KMessageBox::Continue: // OK 2865 case KMessageBox::Continue: // OK
2867 calendar()->deleteJournal(jour); 2866 calendar()->deleteJournal(jour);
2868 updateView(); 2867 updateView();
2869 break; 2868 break;
2870 } // switch 2869 } // switch
2871 } else { 2870 } else {
2872 calendar()->deleteJournal(jour);; 2871 calendar()->deleteJournal(jour);;
2873 updateView(); 2872 updateView();
2874 } 2873 }
2875 emit updateSearchDialog(); 2874 emit updateSearchDialog();
2876} 2875}
2877 2876
2878void CalendarView::deleteEvent(Event *anEvent) 2877void CalendarView::deleteEvent(Event *anEvent)
2879{ 2878{
2880 if (!anEvent) { 2879 if (!anEvent) {
2881 KNotifyClient::beep(); 2880 KNotifyClient::beep();
2882 return; 2881 return;
2883 } 2882 }
2884 2883
2885 if (anEvent->recurrence()->doesRecur()) { 2884 if (anEvent->recurrence()->doesRecur()) {
2886 QDate itemDate = mViewManager->currentSelectionDate(); 2885 QDate itemDate = mViewManager->currentSelectionDate();
2887 int km; 2886 int km;
2888 if (!itemDate.isValid()) { 2887 if (!itemDate.isValid()) {
2889 //kdDebug() << "Date Not Valid" << endl; 2888 //kdDebug() << "Date Not Valid" << endl;
2890 if (KOPrefs::instance()->mConfirm) { 2889 if (KOPrefs::instance()->mConfirm) {
2891 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2890 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2892 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2891 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2893 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2892 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2894 if ( km == KMessageBox::Continue ) 2893 if ( km == KMessageBox::Continue )
2895 km = KMessageBox::No; // No = all below 2894 km = KMessageBox::No; // No = all below
2896 } else 2895 } else
2897 km = KMessageBox::No; 2896 km = KMessageBox::No;
2898 } else { 2897 } else {
2899 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2898 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2900 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2899 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2901 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2900 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2902 i18n("KO/Pi Confirmation"),i18n("Current"), 2901 i18n("KO/Pi Confirmation"),i18n("Current"),
2903 i18n("All")); 2902 i18n("All"));
2904 } 2903 }
2905 switch(km) { 2904 switch(km) {
2906 2905
2907 case KMessageBox::No: // Continue // all 2906 case KMessageBox::No: // Continue // all
2908 //qDebug("KMessageBox::No "); 2907 //qDebug("KMessageBox::No ");
2909 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2908 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2910 schedule(Scheduler::Cancel,anEvent); 2909 schedule(Scheduler::Cancel,anEvent);
2911 2910
2912 checkExternalId( anEvent); 2911 checkExternalId( anEvent);
2913 mCalendar->deleteEvent(anEvent); 2912 mCalendar->deleteEvent(anEvent);
2914 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2913 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2915 break; 2914 break;
2916 2915
2917 // Disabled because it does not work 2916 // Disabled because it does not work
2918 //#if 0 2917 //#if 0
2919 case KMessageBox::Yes: // just this one 2918 case KMessageBox::Yes: // just this one
2920 //QDate qd = mNavigator->selectedDates().first(); 2919 //QDate qd = mNavigator->selectedDates().first();
2921 //if (!qd.isValid()) { 2920 //if (!qd.isValid()) {
2922 // kdDebug() << "no date selected, or invalid date" << endl; 2921 // kdDebug() << "no date selected, or invalid date" << endl;
2923 // KNotifyClient::beep(); 2922 // KNotifyClient::beep();
2924 // return; 2923 // return;
2925 //} 2924 //}
2926 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2925 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2927 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2926 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2928 anEvent->addExDate(itemDate); 2927 anEvent->addExDate(itemDate);
2929 int duration = anEvent->recurrence()->duration(); 2928 int duration = anEvent->recurrence()->duration();
2930 if ( duration > 0 ) { 2929 if ( duration > 0 ) {
2931 anEvent->recurrence()->setDuration( duration - 1 ); 2930 anEvent->recurrence()->setDuration( duration - 1 );
2932 } 2931 }
2933 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2932 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2934 } 2933 }
2935 break; 2934 break;
2936 //#endif 2935 //#endif
2937 } // switch 2936 } // switch
2938 } else { 2937 } else {
2939 if (KOPrefs::instance()->mConfirm) { 2938 if (KOPrefs::instance()->mConfirm) {
2940 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2939 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2941 i18n("\nAre you sure you want\nto delete this event?"), 2940 i18n("\nAre you sure you want\nto delete this event?"),
2942 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2941 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2943 case KMessageBox::Continue: // OK 2942 case KMessageBox::Continue: // OK
2944 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2943 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2945 schedule(Scheduler::Cancel,anEvent); 2944 schedule(Scheduler::Cancel,anEvent);
2946 checkExternalId( anEvent); 2945 checkExternalId( anEvent);
2947 mCalendar->deleteEvent(anEvent); 2946 mCalendar->deleteEvent(anEvent);
2948 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2947 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2949 break; 2948 break;
2950 } // switch 2949 } // switch
2951 } else { 2950 } else {
2952 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2951 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2953 schedule(Scheduler::Cancel,anEvent); 2952 schedule(Scheduler::Cancel,anEvent);
2954 checkExternalId( anEvent); 2953 checkExternalId( anEvent);
2955 mCalendar->deleteEvent(anEvent); 2954 mCalendar->deleteEvent(anEvent);
2956 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2955 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2957 } 2956 }
2958 } // if-else 2957 } // if-else
2959 emit updateSearchDialog(); 2958 emit updateSearchDialog();
2960} 2959}
2961 2960
2962bool CalendarView::deleteEvent(const QString &uid) 2961bool CalendarView::deleteEvent(const QString &uid)
2963{ 2962{
2964 Event *ev = mCalendar->event(uid); 2963 Event *ev = mCalendar->event(uid);
2965 if (ev) { 2964 if (ev) {
2966 deleteEvent(ev); 2965 deleteEvent(ev);
2967 return true; 2966 return true;
2968 } else { 2967 } else {
2969 return false; 2968 return false;
2970 } 2969 }
2971} 2970}
2972 2971
2973/*****************************************************************************/ 2972/*****************************************************************************/
2974 2973
2975void CalendarView::action_mail() 2974void CalendarView::action_mail()
2976{ 2975{
2977#ifndef KORG_NOMAIL 2976#ifndef KORG_NOMAIL
2978 KOMailClient mailClient; 2977 KOMailClient mailClient;
2979 2978
2980 Incidence *incidence = currentSelection(); 2979 Incidence *incidence = currentSelection();
2981 2980
2982 if (!incidence) { 2981 if (!incidence) {
2983 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2982 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2984 return; 2983 return;
2985 } 2984 }
2986 if(incidence->attendeeCount() == 0 ) { 2985 if(incidence->attendeeCount() == 0 ) {
2987 KMessageBox::sorry(this, 2986 KMessageBox::sorry(this,
2988 i18n("Can't generate mail:\nNo attendees defined.\n")); 2987 i18n("Can't generate mail:\nNo attendees defined.\n"));
2989 return; 2988 return;
2990 } 2989 }
2991 2990
2992 CalendarLocal cal_tmp; 2991 CalendarLocal cal_tmp;
2993 Event *event = 0; 2992 Event *event = 0;
2994 Event *ev = 0; 2993 Event *ev = 0;
2995 if ( incidence && incidence->type() == "Event" ) { 2994 if ( incidence && incidence->type() == "Event" ) {
2996 event = static_cast<Event *>(incidence); 2995 event = static_cast<Event *>(incidence);
2997 ev = new Event(*event); 2996 ev = new Event(*event);
2998 cal_tmp.addEvent(ev); 2997 cal_tmp.addEvent(ev);
2999 } 2998 }
3000 ICalFormat mForm(); 2999 ICalFormat mForm();
3001 QString attachment = mForm.toString( &cal_tmp ); 3000 QString attachment = mForm.toString( &cal_tmp );
3002 if (ev) delete(ev); 3001 if (ev) delete(ev);
3003 3002
3004 mailClient.mailAttendees(currentSelection(), attachment); 3003 mailClient.mailAttendees(currentSelection(), attachment);
3005 3004
3006#endif 3005#endif
3007 3006
3008#if 0 3007#if 0
3009 Event *anEvent = 0; 3008 Event *anEvent = 0;
3010 if (mViewManager->currentView()->isEventView()) { 3009 if (mViewManager->currentView()->isEventView()) {
3011 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3010 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3012 } 3011 }
3013 3012
3014 if (!anEvent) { 3013 if (!anEvent) {
3015 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3014 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3016 return; 3015 return;
3017 } 3016 }
3018 if(anEvent->attendeeCount() == 0 ) { 3017 if(anEvent->attendeeCount() == 0 ) {
3019 KMessageBox::sorry(this, 3018 KMessageBox::sorry(this,
3020 i18n("Can't generate mail:\nNo attendees defined.\n")); 3019 i18n("Can't generate mail:\nNo attendees defined.\n"));
3021 return; 3020 return;
3022 } 3021 }
3023 3022
3024 mailobject.emailEvent(anEvent); 3023 mailobject.emailEvent(anEvent);
3025#endif 3024#endif
3026} 3025}
3027 3026
3028 3027
3029void CalendarView::schedule_publish(Incidence *incidence) 3028void CalendarView::schedule_publish(Incidence *incidence)
3030{ 3029{
3031 Event *event = 0; 3030 Event *event = 0;
3032 Todo *todo = 0; 3031 Todo *todo = 0;
3033 3032
3034 if (incidence == 0) { 3033 if (incidence == 0) {
3035 incidence = mViewManager->currentView()->selectedIncidences().first(); 3034 incidence = mViewManager->currentView()->selectedIncidences().first();
3036 if (incidence == 0) { 3035 if (incidence == 0) {
3037 incidence = mTodoList->selectedIncidences().first(); 3036 incidence = mTodoList->selectedIncidences().first();
3038 } 3037 }
3039 } 3038 }
3040 if ( incidence && incidence->type() == "Event" ) { 3039 if ( incidence && incidence->type() == "Event" ) {
3041 event = static_cast<Event *>(incidence); 3040 event = static_cast<Event *>(incidence);
3042 } else { 3041 } else {
3043 if ( incidence && incidence->type() == "Todo" ) { 3042 if ( incidence && incidence->type() == "Todo" ) {
3044 todo = static_cast<Todo *>(incidence); 3043 todo = static_cast<Todo *>(incidence);
3045 } 3044 }
3046 } 3045 }
3047 3046
3048 if (!event && !todo) { 3047 if (!event && !todo) {
3049 KMessageBox::sorry(this,i18n("No event selected.")); 3048 KMessageBox::sorry(this,i18n("No event selected."));
3050 return; 3049 return;
3051 } 3050 }
3052 3051
3053 PublishDialog *publishdlg = new PublishDialog(); 3052 PublishDialog *publishdlg = new PublishDialog();
3054 if (incidence->attendeeCount()>0) { 3053 if (incidence->attendeeCount()>0) {
3055 QPtrList<Attendee> attendees = incidence->attendees(); 3054 QPtrList<Attendee> attendees = incidence->attendees();
3056 attendees.first(); 3055 attendees.first();
3057 while ( attendees.current()!=0 ) { 3056 while ( attendees.current()!=0 ) {
3058 publishdlg->addAttendee(attendees.current()); 3057 publishdlg->addAttendee(attendees.current());
3059 attendees.next(); 3058 attendees.next();
3060 } 3059 }
3061 } 3060 }
3062 bool send = true; 3061 bool send = true;
3063 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3062 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3064 if ( publishdlg->exec() != QDialog::Accepted ) 3063 if ( publishdlg->exec() != QDialog::Accepted )
3065 send = false; 3064 send = false;
3066 } 3065 }
3067 if ( send ) { 3066 if ( send ) {
3068 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3067 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3069 if ( event ) { 3068 if ( event ) {
3070 Event *ev = new Event(*event); 3069 Event *ev = new Event(*event);
3071 ev->registerObserver(0); 3070 ev->registerObserver(0);
3072 ev->clearAttendees(); 3071 ev->clearAttendees();
3073 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3072 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3074 delete(ev); 3073 delete(ev);
3075 } 3074 }
3076 } else { 3075 } else {
3077 if ( todo ) { 3076 if ( todo ) {
3078 Todo *ev = new Todo(*todo); 3077 Todo *ev = new Todo(*todo);
3079 ev->registerObserver(0); 3078 ev->registerObserver(0);
3080 ev->clearAttendees(); 3079 ev->clearAttendees();
3081 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3080 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3082 delete(ev); 3081 delete(ev);
3083 } 3082 }
3084 } 3083 }
3085 } 3084 }
3086 } 3085 }
3087 delete publishdlg; 3086 delete publishdlg;
3088} 3087}
3089 3088
3090void CalendarView::schedule_request(Incidence *incidence) 3089void CalendarView::schedule_request(Incidence *incidence)
3091{ 3090{
3092 schedule(Scheduler::Request,incidence); 3091 schedule(Scheduler::Request,incidence);
3093} 3092}
3094 3093
3095void CalendarView::schedule_refresh(Incidence *incidence) 3094void CalendarView::schedule_refresh(Incidence *incidence)
3096{ 3095{
3097 schedule(Scheduler::Refresh,incidence); 3096 schedule(Scheduler::Refresh,incidence);
3098} 3097}
3099 3098
3100void CalendarView::schedule_cancel(Incidence *incidence) 3099void CalendarView::schedule_cancel(Incidence *incidence)
3101{ 3100{
3102 schedule(Scheduler::Cancel,incidence); 3101 schedule(Scheduler::Cancel,incidence);
3103} 3102}
3104 3103
3105void CalendarView::schedule_add(Incidence *incidence) 3104void CalendarView::schedule_add(Incidence *incidence)
3106{ 3105{
3107 schedule(Scheduler::Add,incidence); 3106 schedule(Scheduler::Add,incidence);
3108} 3107}
3109 3108
3110void CalendarView::schedule_reply(Incidence *incidence) 3109void CalendarView::schedule_reply(Incidence *incidence)
3111{ 3110{
3112 schedule(Scheduler::Reply,incidence); 3111 schedule(Scheduler::Reply,incidence);
3113} 3112}
3114 3113
3115void CalendarView::schedule_counter(Incidence *incidence) 3114void CalendarView::schedule_counter(Incidence *incidence)
3116{ 3115{
3117 schedule(Scheduler::Counter,incidence); 3116 schedule(Scheduler::Counter,incidence);
3118} 3117}
3119 3118
3120void CalendarView::schedule_declinecounter(Incidence *incidence) 3119void CalendarView::schedule_declinecounter(Incidence *incidence)
3121{ 3120{
3122 schedule(Scheduler::Declinecounter,incidence); 3121 schedule(Scheduler::Declinecounter,incidence);
3123} 3122}
3124 3123
3125void CalendarView::schedule_publish_freebusy(int daysToPublish) 3124void CalendarView::schedule_publish_freebusy(int daysToPublish)
3126{ 3125{
3127 QDateTime start = QDateTime::currentDateTime(); 3126 QDateTime start = QDateTime::currentDateTime();
3128 QDateTime end = start.addDays(daysToPublish); 3127 QDateTime end = start.addDays(daysToPublish);
3129 3128
3130 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3129 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3131 freebusy->setOrganizer(KOPrefs::instance()->email()); 3130 freebusy->setOrganizer(KOPrefs::instance()->email());
3132 3131
3133 3132
3134 PublishDialog *publishdlg = new PublishDialog(); 3133 PublishDialog *publishdlg = new PublishDialog();
3135 if ( publishdlg->exec() == QDialog::Accepted ) { 3134 if ( publishdlg->exec() == QDialog::Accepted ) {
3136 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3135 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3137 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3136 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3138 delete(freebusy); 3137 delete(freebusy);
3139 } 3138 }
3140 } 3139 }
3141 delete publishdlg; 3140 delete publishdlg;
3142} 3141}
3143 3142
3144void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3143void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3145{ 3144{
3146 Event *event = 0; 3145 Event *event = 0;
3147 Todo *todo = 0; 3146 Todo *todo = 0;
3148 3147
3149 if (incidence == 0) { 3148 if (incidence == 0) {
3150 incidence = mViewManager->currentView()->selectedIncidences().first(); 3149 incidence = mViewManager->currentView()->selectedIncidences().first();
3151 if (incidence == 0) { 3150 if (incidence == 0) {
3152 incidence = mTodoList->selectedIncidences().first(); 3151 incidence = mTodoList->selectedIncidences().first();
3153 } 3152 }
3154 } 3153 }
3155 if ( incidence && incidence->type() == "Event" ) { 3154 if ( incidence && incidence->type() == "Event" ) {
3156 event = static_cast<Event *>(incidence); 3155 event = static_cast<Event *>(incidence);
3157 } 3156 }
3158 if ( incidence && incidence->type() == "Todo" ) { 3157 if ( incidence && incidence->type() == "Todo" ) {
3159 todo = static_cast<Todo *>(incidence); 3158 todo = static_cast<Todo *>(incidence);
3160 } 3159 }
3161 3160
3162 if (!event && !todo) { 3161 if (!event && !todo) {
3163 KMessageBox::sorry(this,i18n("No event selected.")); 3162 KMessageBox::sorry(this,i18n("No event selected."));
3164 return; 3163 return;
3165 } 3164 }
3166 3165
3167 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3166 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3168 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3167 KMessageBox::sorry(this,i18n("The event has no attendees."));
3169 return; 3168 return;
3170 } 3169 }
3171 3170
3172 Event *ev = 0; 3171 Event *ev = 0;
3173 if (event) ev = new Event(*event); 3172 if (event) ev = new Event(*event);
3174 Todo *to = 0; 3173 Todo *to = 0;
3175 if (todo) to = new Todo(*todo); 3174 if (todo) to = new Todo(*todo);
3176 3175
3177 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3176 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3178 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3177 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3179 if (!me) { 3178 if (!me) {
3180 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3179 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3181 return; 3180 return;
3182 } 3181 }
3183 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3182 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3184 StatusDialog *statdlg = new StatusDialog(this); 3183 StatusDialog *statdlg = new StatusDialog(this);
3185 if (!statdlg->exec()==QDialog::Accepted) return; 3184 if (!statdlg->exec()==QDialog::Accepted) return;
3186 me->setStatus( statdlg->status() ); 3185 me->setStatus( statdlg->status() );
3187 delete(statdlg); 3186 delete(statdlg);
3188 } 3187 }
3189 Attendee *menew = new Attendee(*me); 3188 Attendee *menew = new Attendee(*me);
3190 if (ev) { 3189 if (ev) {
3191 ev->clearAttendees(); 3190 ev->clearAttendees();
3192 ev->addAttendee(menew,false); 3191 ev->addAttendee(menew,false);
3193 } else { 3192 } else {
3194 if (to) { 3193 if (to) {
3195 todo->clearAttendees(); 3194 todo->clearAttendees();
3196 todo->addAttendee(menew,false); 3195 todo->addAttendee(menew,false);
3197 } 3196 }
3198 } 3197 }
3199 } 3198 }
3200 3199
3201 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3200 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3202 if (ev) { 3201 if (ev) {
3203 if ( !dlg->addMessage(ev,method) ) delete(ev); 3202 if ( !dlg->addMessage(ev,method) ) delete(ev);
3204 } else { 3203 } else {
3205 if (to) { 3204 if (to) {
3206 if ( !dlg->addMessage(to,method) ) delete(to); 3205 if ( !dlg->addMessage(to,method) ) delete(to);
3207 } 3206 }
3208 } 3207 }
3209} 3208}
3210 3209
3211void CalendarView::openAddressbook() 3210void CalendarView::openAddressbook()
3212{ 3211{
3213 KRun::runCommand("kaddressbook"); 3212 KRun::runCommand("kaddressbook");
3214} 3213}
3215 3214
3216void CalendarView::setModified(bool modified) 3215void CalendarView::setModified(bool modified)
3217{ 3216{
3218 if ( modified ) 3217 if ( modified )
3219 emit signalmodified(); 3218 emit signalmodified();
3220 if (mModified != modified) { 3219 if (mModified != modified) {
3221 mModified = modified; 3220 mModified = modified;
3222 emit modifiedChanged(mModified); 3221 emit modifiedChanged(mModified);
3223 } 3222 }
3224} 3223}
3225 3224
3226bool CalendarView::isReadOnly() 3225bool CalendarView::isReadOnly()
3227{ 3226{
3228 return mReadOnly; 3227 return mReadOnly;
3229} 3228}
3230 3229
3231void CalendarView::setReadOnly(bool readOnly) 3230void CalendarView::setReadOnly(bool readOnly)
3232{ 3231{
3233 if (mReadOnly != readOnly) { 3232 if (mReadOnly != readOnly) {
3234 mReadOnly = readOnly; 3233 mReadOnly = readOnly;
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index ea543dd..b360644 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,1159 +1,1169 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51 51
52#include <klocale.h> 52#include <klocale.h>
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kconfig.h> 54#include <kconfig.h>
55#include <kfiledialog.h> 55#include <kfiledialog.h>
56 56
57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
59{ 59{
60 mServerSocket = 0; 60 mServerSocket = 0;
61 bar = new QProgressBar ( 1, 0 ); 61 bar = new QProgressBar ( 1, 0 );
62 bar->setCaption (""); 62 bar->setCaption ("");
63 63
64 int w = 300; 64 int w = 300;
65 if ( QApplication::desktop()->width() < 320 ) 65 if ( QApplication::desktop()->width() < 320 )
66 w = 220; 66 w = 220;
67 int h = bar->sizeHint().height() ; 67 int h = bar->sizeHint().height() ;
68 int dw = QApplication::desktop()->width(); 68 int dw = QApplication::desktop()->width();
69 int dh = QApplication::desktop()->height(); 69 int dh = QApplication::desktop()->height();
70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
71 71
72} 72}
73 73
74KSyncManager::~KSyncManager() 74KSyncManager::~KSyncManager()
75{ 75{
76 delete bar; 76 delete bar;
77} 77}
78 78
79//LR ok 79//LR ok
80void KSyncManager::fillSyncMenu() 80void KSyncManager::fillSyncMenu()
81{ 81{
82 if ( mSyncMenu->count() ) 82 if ( mSyncMenu->count() )
83 mSyncMenu->clear(); 83 mSyncMenu->clear();
84 84
85 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 85 mSyncMenu->insertItem( i18n("Configure..."), 0 );
86 mSyncMenu->insertSeparator(); 86 mSyncMenu->insertSeparator();
87 if ( mServerSocket == 0 ) { 87 if ( mServerSocket == 0 ) {
88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
89 } else { 89 } else {
90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
91 } 91 }
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
94 mSyncMenu->insertSeparator(); 94 mSyncMenu->insertSeparator();
95 95
96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
97 config.setGroup("General"); 97 config.setGroup("General");
98 QStringList prof = config.readListEntry("SyncProfileNames"); 98 QStringList prof = config.readListEntry("SyncProfileNames");
99 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 99 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
100 if ( prof.count() < 2 ) { 100 if ( prof.count() < 2 ) {
101 prof.clear(); 101 prof.clear();
102 prof << i18n("Sharp_DTM"); 102 prof << i18n("Sharp_DTM");
103 prof << i18n("Local_file"); 103 prof << i18n("Local_file");
104 KSyncProfile* temp = new KSyncProfile (); 104 KSyncProfile* temp = new KSyncProfile ();
105 temp->setName( prof[0] ); 105 temp->setName( prof[0] );
106 temp->writeConfig(&config); 106 temp->writeConfig(&config);
107 temp->setName( prof[1] ); 107 temp->setName( prof[1] );
108 temp->writeConfig(&config); 108 temp->writeConfig(&config);
109 config.setGroup("General"); 109 config.setGroup("General");
110 config.writeEntry("SyncProfileNames",prof); 110 config.writeEntry("SyncProfileNames",prof);
111 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 111 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
112 config.sync(); 112 config.sync();
113 delete temp; 113 delete temp;
114 } 114 }
115 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 115 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
116 mSyncProfileNames = prof; 116 mSyncProfileNames = prof;
117 unsigned int i; 117 unsigned int i;
118 for ( i = 0; i < prof.count(); ++i ) { 118 for ( i = 0; i < prof.count(); ++i ) {
119 mSyncMenu->insertItem( prof[i], 1000+i ); 119 mSyncMenu->insertItem( prof[i], 1000+i );
120 if ( i == 2 ) 120 if ( i == 2 )
121 mSyncMenu->insertSeparator(); 121 mSyncMenu->insertSeparator();
122 } 122 }
123 QDir app_dir; 123 QDir app_dir;
124 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 124 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
125 if ( mTargetApp == PWMPI) { 125 if ( mTargetApp == PWMPI) {
126 mSyncMenu->removeItem( 1000 ); 126 mSyncMenu->removeItem( 1000 );
127 } 127 }
128 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 128 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
129 mSyncMenu->setItemEnabled( 1000, false ); 129 mSyncMenu->setItemEnabled( 1000, false );
130 } 130 }
131} 131}
132 132
133void KSyncManager::slotSyncMenu( int action ) 133void KSyncManager::slotSyncMenu( int action )
134{ 134{
135 //qDebug("syncaction %d ", action); 135 //qDebug("syncaction %d ", action);
136 if ( action == 0 ) { 136 if ( action == 0 ) {
137 137
138 // seems to be a Qt2 event handling bug 138 // seems to be a Qt2 event handling bug
139 // syncmenu.clear causes a segfault at first time 139 // syncmenu.clear causes a segfault at first time
140 // when we call it after the main event loop, it is ok 140 // when we call it after the main event loop, it is ok
141 // same behaviour when calling OM/Pi via QCOP for the first time 141 // same behaviour when calling OM/Pi via QCOP for the first time
142 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 142 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
143 //confSync(); 143 //confSync();
144 144
145 return; 145 return;
146 } 146 }
147 if ( action == 1 ) { 147 if ( action == 1 ) {
148 multiSync( true ); 148 multiSync( true );
149 return; 149 return;
150 } 150 }
151 if ( action == 2 ) { 151 if ( action == 2 ) {
152 enableQuick(); 152 enableQuick();
153 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 153 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
154 return; 154 return;
155 } 155 }
156 if ( action == 3 ) { 156 if ( action == 3 ) {
157 delete mServerSocket; 157 delete mServerSocket;
158 mServerSocket = 0; 158 mServerSocket = 0;
159 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 159 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
160 return; 160 return;
161 } 161 }
162 162
163 if (blockSave()) 163 if (blockSave())
164 return; 164 return;
165 165
166 setBlockSave(true); 166 setBlockSave(true);
167 167
168 mCurrentSyncProfile = action - 1000 ; 168 mCurrentSyncProfile = action - 1000 ;
169 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 169 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
170 mCurrentSyncName = mLocalMachineName ; 170 mCurrentSyncName = mLocalMachineName ;
171 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 171 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
172 KSyncProfile* temp = new KSyncProfile (); 172 KSyncProfile* temp = new KSyncProfile ();
173 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 173 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
174 temp->readConfig(&config); 174 temp->readConfig(&config);
175 mAskForPreferences = temp->getAskForPreferences(); 175 mAskForPreferences = temp->getAskForPreferences();
176 mSyncAlgoPrefs = temp->getSyncPrefs(); 176 mSyncAlgoPrefs = temp->getSyncPrefs();
177 mWriteBackFile = temp->getWriteBackFile(); 177 mWriteBackFile = temp->getWriteBackFile();
178 mWriteBackExistingOnly = temp->getWriteBackExisting(); 178 mWriteBackExistingOnly = temp->getWriteBackExisting();
179 mWriteBackInFuture = 0; 179 mWriteBackInFuture = 0;
180 if ( temp->getWriteBackFuture() ) 180 if ( temp->getWriteBackFuture() )
181 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 181 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
182 mShowSyncSummary = temp->getShowSummaryAfterSync(); 182 mShowSyncSummary = temp->getShowSummaryAfterSync();
183 if ( action == 1000 ) { 183 if ( action == 1000 ) {
184 syncSharp(); 184 syncSharp();
185 185
186 } else if ( action == 1001 ) { 186 } else if ( action == 1001 ) {
187 syncLocalFile(); 187 syncLocalFile();
188 188
189 } else if ( action == 1002 ) { 189 } else if ( action == 1002 ) {
190 quickSyncLocalFile(); 190 quickSyncLocalFile();
191 191
192 } else if ( action >= 1003 ) { 192 } else if ( action >= 1003 ) {
193 if ( temp->getIsLocalFileSync() ) { 193 if ( temp->getIsLocalFileSync() ) {
194 switch(mTargetApp) 194 switch(mTargetApp)
195 { 195 {
196 case (KAPI): 196 case (KAPI):
197 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 197 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
198 mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 198 mLastSyncedLocalFile = temp->getRemoteFileNameAB();
199 break; 199 break;
200 case (KOPI): 200 case (KOPI):
201 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 201 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
202 mLastSyncedLocalFile = temp->getRemoteFileName(); 202 mLastSyncedLocalFile = temp->getRemoteFileName();
203 break; 203 break;
204 case (PWMPI): 204 case (PWMPI):
205 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 205 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
206 mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 206 mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
207 break; 207 break;
208 default: 208 default:
209 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 209 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
210 break; 210 break;
211 211
212 } 212 }
213 } else { 213 } else {
214 if ( temp->getIsPhoneSync() ) { 214 if ( temp->getIsPhoneSync() ) {
215 mPhoneDevice = temp->getPhoneDevice( ) ; 215 mPhoneDevice = temp->getPhoneDevice( ) ;
216 mPhoneConnection = temp->getPhoneConnection( ); 216 mPhoneConnection = temp->getPhoneConnection( );
217 mPhoneModel = temp->getPhoneModel( ); 217 mPhoneModel = temp->getPhoneModel( );
218 syncPhone(); 218 syncPhone();
219 } else if ( temp->getIsPiSync() ) { 219 } else if ( temp->getIsPiSync() ) {
220 mPassWordPiSync = temp->getRemotePw(); 220 if ( mTargetApp == KAPI ) {
221 mActiveSyncPort = temp->getRemotePort(); 221 mPassWordPiSync = temp->getRemotePwAB();
222 mActiveSyncIP = temp->getRemoteIP(); 222 mActiveSyncPort = temp->getRemotePortAB();
223 mActiveSyncIP = temp->getRemoteIPAB();
224 } else if ( mTargetApp == KOPI ) {
225 mPassWordPiSync = temp->getRemotePw();
226 mActiveSyncPort = temp->getRemotePort();
227 mActiveSyncIP = temp->getRemoteIP();
228 } else {
229 mPassWordPiSync = temp->getRemotePwPWM();
230 mActiveSyncPort = temp->getRemotePortPWM();
231 mActiveSyncIP = temp->getRemoteIPPWM();
232 }
223 syncPi(); 233 syncPi();
224 } 234 }
225 syncRemote( temp ); 235 syncRemote( temp );
226 236
227 } 237 }
228 } 238 }
229 delete temp; 239 delete temp;
230 setBlockSave(false); 240 setBlockSave(false);
231} 241}
232void KSyncManager::enableQuick() 242void KSyncManager::enableQuick()
233{ 243{
234 QDialog dia ( 0, "input-dialog", true ); 244 QDialog dia ( 0, "input-dialog", true );
235 QLineEdit lab ( &dia ); 245 QLineEdit lab ( &dia );
236 QVBoxLayout lay( &dia ); 246 QVBoxLayout lay( &dia );
237 lab.setText( mPrefs->mPassiveSyncPort ); 247 lab.setText( mPrefs->mPassiveSyncPort );
238 lay.setMargin(7); 248 lay.setMargin(7);
239 lay.setSpacing(7); 249 lay.setSpacing(7);
240 int po = 9197+mTargetApp; 250 int po = 9197+mTargetApp;
241 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 251 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
242 lay.addWidget( &label); 252 lay.addWidget( &label);
243 lay.addWidget( &lab); 253 lay.addWidget( &lab);
244 254
245 QLineEdit lepw ( &dia ); 255 QLineEdit lepw ( &dia );
246 lepw.setText( mPrefs->mPassiveSyncPw ); 256 lepw.setText( mPrefs->mPassiveSyncPw );
247 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 257 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
248 lay.addWidget( &label2); 258 lay.addWidget( &label2);
249 lay.addWidget( &lepw); 259 lay.addWidget( &lepw);
250 dia.setFixedSize( 230,80 ); 260 dia.setFixedSize( 230,80 );
251 dia.setCaption( i18n("Enter port for Pi-Sync") ); 261 dia.setCaption( i18n("Enter port for Pi-Sync") );
252 QPushButton pb ( "OK", &dia); 262 QPushButton pb ( "OK", &dia);
253 lay.addWidget( &pb ); 263 lay.addWidget( &pb );
254 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 264 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
255 dia.show(); 265 dia.show();
256 if ( ! dia.exec() ) 266 if ( ! dia.exec() )
257 return; 267 return;
258 dia.hide(); 268 dia.hide();
259 qApp->processEvents(); 269 qApp->processEvents();
260 mPrefs->mPassiveSyncPw = lepw.text(); 270 mPrefs->mPassiveSyncPw = lepw.text();
261 mPrefs->mPassiveSyncPort = lab.text(); 271 mPrefs->mPassiveSyncPort = lab.text();
262 bool ok; 272 bool ok;
263 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 273 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
264 if ( ! ok ) { 274 if ( ! ok ) {
265 KMessageBox::information( 0, i18n("No valid port")); 275 KMessageBox::information( 0, i18n("No valid port"));
266 return; 276 return;
267 } 277 }
268 //qDebug("port %d ", port); 278 //qDebug("port %d ", port);
269 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 279 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
270 mServerSocket->setFileName( defaultFileName() ); 280 mServerSocket->setFileName( defaultFileName() );
271 //qDebug("connected "); 281 //qDebug("connected ");
272 if ( !mServerSocket->ok() ) { 282 if ( !mServerSocket->ok() ) {
273 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 283 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
274 delete mServerSocket; 284 delete mServerSocket;
275 mServerSocket = 0; 285 mServerSocket = 0;
276 return; 286 return;
277 } 287 }
278 //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); 288 //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) );
279 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 289 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
280 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 290 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
281} 291}
282 292
283void KSyncManager::syncLocalFile() 293void KSyncManager::syncLocalFile()
284{ 294{
285 295
286 QString fn =mLastSyncedLocalFile; 296 QString fn =mLastSyncedLocalFile;
287 QString ext; 297 QString ext;
288 298
289 switch(mTargetApp) 299 switch(mTargetApp)
290 { 300 {
291 case (KAPI): 301 case (KAPI):
292 ext = "(*.vcf)"; 302 ext = "(*.vcf)";
293 break; 303 break;
294 case (KOPI): 304 case (KOPI):
295 ext = "(*.ics/*.vcs)"; 305 ext = "(*.ics/*.vcs)";
296 break; 306 break;
297 case (PWMPI): 307 case (PWMPI):
298 ext = "(*.pwm)"; 308 ext = "(*.pwm)";
299 break; 309 break;
300 default: 310 default:
301 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 311 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
302 break; 312 break;
303 313
304 } 314 }
305 315
306 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 316 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
307 if ( fn == "" ) 317 if ( fn == "" )
308 return; 318 return;
309 if ( syncWithFile( fn, false ) ) { 319 if ( syncWithFile( fn, false ) ) {
310 qDebug("syncLocalFile() successful "); 320 qDebug("syncLocalFile() successful ");
311 } 321 }
312 322
313} 323}
314bool KSyncManager::syncWithFile( QString fn , bool quick ) 324bool KSyncManager::syncWithFile( QString fn , bool quick )
315{ 325{
316 bool ret = false; 326 bool ret = false;
317 QFileInfo info; 327 QFileInfo info;
318 info.setFile( fn ); 328 info.setFile( fn );
319 QString mess; 329 QString mess;
320 bool loadbup = true; 330 bool loadbup = true;
321 if ( !info. exists() ) { 331 if ( !info. exists() ) {
322 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 332 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
323 int result = QMessageBox::warning( mParent, i18n("Warning!"), 333 int result = QMessageBox::warning( mParent, i18n("Warning!"),
324 mess ); 334 mess );
325 return ret; 335 return ret;
326 } 336 }
327 int result = 0; 337 int result = 0;
328 if ( !quick ) { 338 if ( !quick ) {
329 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 339 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
330 result = QMessageBox::warning( mParent, i18n("Warning!"), 340 result = QMessageBox::warning( mParent, i18n("Warning!"),
331 mess, 341 mess,
332 i18n("Sync"), i18n("Cancel"), 0, 342 i18n("Sync"), i18n("Cancel"), 0,
333 0, 1 ); 343 0, 1 );
334 if ( result ) 344 if ( result )
335 return false; 345 return false;
336 } 346 }
337 if ( mAskForPreferences ) 347 if ( mAskForPreferences )
338 edit_sync_options(); 348 edit_sync_options();
339 if ( result == 0 ) { 349 if ( result == 0 ) {
340 //qDebug("Now sycing ... "); 350 //qDebug("Now sycing ... ");
341 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 351 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
342 mParent->setCaption( i18n("Synchronization successful") ); 352 mParent->setCaption( i18n("Synchronization successful") );
343 else 353 else
344 mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 354 mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
345 if ( ! quick ) 355 if ( ! quick )
346 mLastSyncedLocalFile = fn; 356 mLastSyncedLocalFile = fn;
347 } 357 }
348 return ret; 358 return ret;
349} 359}
350void KSyncManager::quickSyncLocalFile() 360void KSyncManager::quickSyncLocalFile()
351{ 361{
352 362
353 if ( syncWithFile( mLastSyncedLocalFile, false ) ) { 363 if ( syncWithFile( mLastSyncedLocalFile, false ) ) {
354 qDebug("quick syncLocalFile() successful "); 364 qDebug("quick syncLocalFile() successful ");
355 365
356 } 366 }
357} 367}
358void KSyncManager::multiSync( bool askforPrefs ) 368void KSyncManager::multiSync( bool askforPrefs )
359{ 369{
360 if (blockSave()) 370 if (blockSave())
361 return; 371 return;
362 setBlockSave(true); 372 setBlockSave(true);
363 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 373 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
364 if ( QMessageBox::information( mParent, i18n("Sync"), 374 if ( QMessageBox::information( mParent, i18n("Sync"),
365 question, 375 question,
366 i18n("Yes"), i18n("No"), 376 i18n("Yes"), i18n("No"),
367 0, 0 ) != 0 ) { 377 0, 0 ) != 0 ) {
368 setBlockSave(false); 378 setBlockSave(false);
369 mParent->setCaption(i18n("Aborted! Nothing synced!")); 379 mParent->setCaption(i18n("Aborted! Nothing synced!"));
370 return; 380 return;
371 } 381 }
372 mCurrentSyncDevice = i18n("Multiple profiles") ; 382 mCurrentSyncDevice = i18n("Multiple profiles") ;
373 mSyncAlgoPrefs = mRingSyncAlgoPrefs; 383 mSyncAlgoPrefs = mRingSyncAlgoPrefs;
374 if ( askforPrefs ) { 384 if ( askforPrefs ) {
375 edit_sync_options(); 385 edit_sync_options();
376 mRingSyncAlgoPrefs = mSyncAlgoPrefs; 386 mRingSyncAlgoPrefs = mSyncAlgoPrefs;
377 } 387 }
378 mParent->setCaption(i18n("Multiple sync started.") ); 388 mParent->setCaption(i18n("Multiple sync started.") );
379 qApp->processEvents(); 389 qApp->processEvents();
380 int num = ringSync() ; 390 int num = ringSync() ;
381 if ( num > 1 ) 391 if ( num > 1 )
382 ringSync(); 392 ringSync();
383 setBlockSave(false); 393 setBlockSave(false);
384 if ( num ) 394 if ( num )
385 emit save(); 395 emit save();
386 if ( num ) 396 if ( num )
387 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 397 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
388 else 398 else
389 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 399 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
390 return; 400 return;
391} 401}
392int KSyncManager::ringSync() 402int KSyncManager::ringSync()
393{ 403{
394 int syncedProfiles = 0; 404 int syncedProfiles = 0;
395 unsigned int i; 405 unsigned int i;
396 QTime timer; 406 QTime timer;
397 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 407 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
398 QStringList syncProfileNames = mSyncProfileNames; 408 QStringList syncProfileNames = mSyncProfileNames;
399 KSyncProfile* temp = new KSyncProfile (); 409 KSyncProfile* temp = new KSyncProfile ();
400 mAskForPreferences = false; 410 mAskForPreferences = false;
401 for ( i = 0; i < syncProfileNames.count(); ++i ) { 411 for ( i = 0; i < syncProfileNames.count(); ++i ) {
402 mCurrentSyncProfile = i; 412 mCurrentSyncProfile = i;
403 temp->setName(syncProfileNames[mCurrentSyncProfile]); 413 temp->setName(syncProfileNames[mCurrentSyncProfile]);
404 temp->readConfig(&config); 414 temp->readConfig(&config);
405 415
406 QString includeInRingSync; 416 QString includeInRingSync;
407 switch(mTargetApp) 417 switch(mTargetApp)
408 { 418 {
409 case (KAPI): 419 case (KAPI):
410 includeInRingSync = temp->getIncludeInRingSyncAB(); 420 includeInRingSync = temp->getIncludeInRingSyncAB();
411 break; 421 break;
412 case (KOPI): 422 case (KOPI):
413 includeInRingSync = temp->getIncludeInRingSync(); 423 includeInRingSync = temp->getIncludeInRingSync();
414 break; 424 break;
415 case (PWMPI): 425 case (PWMPI):
416 includeInRingSync = temp->getIncludeInRingSyncPWM(); 426 includeInRingSync = temp->getIncludeInRingSyncPWM();
417 break; 427 break;
418 default: 428 default:
419 qDebug("KSyncManager::ringSync: invalid apptype selected"); 429 qDebug("KSyncManager::ringSync: invalid apptype selected");
420 break; 430 break;
421 431
422 } 432 }
423 433
424 434
425 if ( includeInRingSync && ( i < 1 || i > 2 )) { 435 if ( includeInRingSync && ( i < 1 || i > 2 )) {
426 mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 436 mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
427 ++syncedProfiles; 437 ++syncedProfiles;
428 // mAskForPreferences = temp->getAskForPreferences(); 438 // mAskForPreferences = temp->getAskForPreferences();
429 mWriteBackFile = temp->getWriteBackFile(); 439 mWriteBackFile = temp->getWriteBackFile();
430 mWriteBackExistingOnly = temp->getWriteBackExisting(); 440 mWriteBackExistingOnly = temp->getWriteBackExisting();
431 mWriteBackInFuture = 0; 441 mWriteBackInFuture = 0;
432 if ( temp->getWriteBackFuture() ) 442 if ( temp->getWriteBackFuture() )
433 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 443 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
434 mShowSyncSummary = false; 444 mShowSyncSummary = false;
435 mCurrentSyncDevice = syncProfileNames[i] ; 445 mCurrentSyncDevice = syncProfileNames[i] ;
436 mCurrentSyncName = mLocalMachineName; 446 mCurrentSyncName = mLocalMachineName;
437 if ( i == 0 ) { 447 if ( i == 0 ) {
438 syncSharp(); 448 syncSharp();
439 } else { 449 } else {
440 if ( temp->getIsLocalFileSync() ) { 450 if ( temp->getIsLocalFileSync() ) {
441 switch(mTargetApp) 451 switch(mTargetApp)
442 { 452 {
443 case (KAPI): 453 case (KAPI):
444 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 454 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
445 mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 455 mLastSyncedLocalFile = temp->getRemoteFileNameAB();
446 break; 456 break;
447 case (KOPI): 457 case (KOPI):
448 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 458 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
449 mLastSyncedLocalFile = temp->getRemoteFileName(); 459 mLastSyncedLocalFile = temp->getRemoteFileName();
450 break; 460 break;
451 case (PWMPI): 461 case (PWMPI):
452 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 462 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
453 mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 463 mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
454 break; 464 break;
455 default: 465 default:
456 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 466 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
457 break; 467 break;
458 } 468 }
459 } else { 469 } else {
460 if ( temp->getIsPhoneSync() ) { 470 if ( temp->getIsPhoneSync() ) {
461 mPhoneDevice = temp->getPhoneDevice( ) ; 471 mPhoneDevice = temp->getPhoneDevice( ) ;
462 mPhoneConnection = temp->getPhoneConnection( ); 472 mPhoneConnection = temp->getPhoneConnection( );
463 mPhoneModel = temp->getPhoneModel( ); 473 mPhoneModel = temp->getPhoneModel( );
464 syncPhone(); 474 syncPhone();
465 } else 475 } else
466 syncRemote( temp, false ); 476 syncRemote( temp, false );
467 477
468 } 478 }
469 } 479 }
470 timer.start(); 480 timer.start();
471 mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); 481 mParent->setCaption(i18n("Multiple sync in progress ... please wait!") );
472 while ( timer.elapsed () < 2000 ) { 482 while ( timer.elapsed () < 2000 ) {
473 qApp->processEvents(); 483 qApp->processEvents();
474#ifndef _WIN32_ 484#ifndef _WIN32_
475 sleep (1); 485 sleep (1);
476#endif 486#endif
477 } 487 }
478 488
479 } 489 }
480 490
481 } 491 }
482 delete temp; 492 delete temp;
483 return syncedProfiles; 493 return syncedProfiles;
484} 494}
485 495
486void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 496void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
487{ 497{
488 QString question; 498 QString question;
489 if ( ask ) { 499 if ( ask ) {
490 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 500 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
491 if ( QMessageBox::information( mParent, i18n("Sync"), 501 if ( QMessageBox::information( mParent, i18n("Sync"),
492 question, 502 question,
493 i18n("Yes"), i18n("No"), 503 i18n("Yes"), i18n("No"),
494 0, 0 ) != 0 ) 504 0, 0 ) != 0 )
495 return; 505 return;
496 } 506 }
497 507
498 QString preCommand; 508 QString preCommand;
499 QString localTempFile; 509 QString localTempFile;
500 QString postCommand; 510 QString postCommand;
501 511
502 switch(mTargetApp) 512 switch(mTargetApp)
503 { 513 {
504 case (KAPI): 514 case (KAPI):
505 preCommand = prof->getPreSyncCommandAB(); 515 preCommand = prof->getPreSyncCommandAB();
506 postCommand = prof->getPostSyncCommandAB(); 516 postCommand = prof->getPostSyncCommandAB();
507 localTempFile = prof->getLocalTempFileAB(); 517 localTempFile = prof->getLocalTempFileAB();
508 break; 518 break;
509 case (KOPI): 519 case (KOPI):
510 preCommand = prof->getPreSyncCommand(); 520 preCommand = prof->getPreSyncCommand();
511 postCommand = prof->getPostSyncCommand(); 521 postCommand = prof->getPostSyncCommand();
512 localTempFile = prof->getLocalTempFile(); 522 localTempFile = prof->getLocalTempFile();
513 break; 523 break;
514 case (PWMPI): 524 case (PWMPI):
515 preCommand = prof->getPreSyncCommandPWM(); 525 preCommand = prof->getPreSyncCommandPWM();
516 postCommand = prof->getPostSyncCommandPWM(); 526 postCommand = prof->getPostSyncCommandPWM();
517 localTempFile = prof->getLocalTempFilePWM(); 527 localTempFile = prof->getLocalTempFilePWM();
518 break; 528 break;
519 default: 529 default:
520 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 530 qDebug("KSyncManager::syncRemote: invalid apptype selected");
521 break; 531 break;
522 } 532 }
523 533
524 534
525 int fi; 535 int fi;
526 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 536 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
527 QString pwd = getPassword(); 537 QString pwd = getPassword();
528 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 538 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
529 539
530 } 540 }
531 int maxlen = 30; 541 int maxlen = 30;
532 if ( QApplication::desktop()->width() > 320 ) 542 if ( QApplication::desktop()->width() > 320 )
533 maxlen += 25; 543 maxlen += 25;
534 mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); 544 mParent->setCaption ( i18n( "Copy remote file to local machine..." ) );
535 int fileSize = 0; 545 int fileSize = 0;
536 int result = system ( preCommand ); 546 int result = system ( preCommand );
537 // 0 : okay 547 // 0 : okay
538 // 256: no such file or dir 548 // 256: no such file or dir
539 // 549 //
540 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 550 qDebug("KO: Remote copy result(0 = okay): %d ",result );
541 if ( result != 0 ) { 551 if ( result != 0 ) {
542 unsigned int len = maxlen; 552 unsigned int len = maxlen;
543 while ( len < preCommand.length() ) { 553 while ( len < preCommand.length() ) {
544 preCommand.insert( len , "\n" ); 554 preCommand.insert( len , "\n" );
545 len += maxlen +2; 555 len += maxlen +2;
546 } 556 }
547 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 557 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
548 QMessageBox::information( mParent, i18n("Sync - ERROR"), 558 QMessageBox::information( mParent, i18n("Sync - ERROR"),
549 question, 559 question,
550 i18n("Okay!")) ; 560 i18n("Okay!")) ;
551 mParent->setCaption (""); 561 mParent->setCaption ("");
552 return; 562 return;
553 } 563 }
554 mParent->setCaption ( i18n( "Copying succeed." ) ); 564 mParent->setCaption ( i18n( "Copying succeed." ) );
555 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 565 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
556 566
557 567
558 568
559 if ( syncWithFile( localTempFile, true ) ) { 569 if ( syncWithFile( localTempFile, true ) ) {
560// Event* e = mView->getLastSyncEvent(); 570// Event* e = mView->getLastSyncEvent();
561// e->setReadOnly( false ); 571// e->setReadOnly( false );
562// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 572// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
563// e->setReadOnly( true ); 573// e->setReadOnly( true );
564 if ( mWriteBackFile ) { 574 if ( mWriteBackFile ) {
565 int fi; 575 int fi;
566 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 576 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
567 QString pwd = getPassword(); 577 QString pwd = getPassword();
568 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 578 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
569 579
570 } 580 }
571 mParent->setCaption ( i18n( "Writing back file ..." ) ); 581 mParent->setCaption ( i18n( "Writing back file ..." ) );
572 result = system ( postCommand ); 582 result = system ( postCommand );
573 qDebug("Writing back file result: %d ", result); 583 qDebug("Writing back file result: %d ", result);
574 if ( result != 0 ) { 584 if ( result != 0 ) {
575 mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 585 mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
576 return; 586 return;
577 } else { 587 } else {
578 mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 588 mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) );
579 } 589 }
580 } 590 }
581 } 591 }
582 return; 592 return;
583} 593}
584 594
585void KSyncManager::edit_sync_options() 595void KSyncManager::edit_sync_options()
586{ 596{
587 //mDialogManager->showSyncOptions(); 597 //mDialogManager->showSyncOptions();
588 //mSyncAlgoPrefs 598 //mSyncAlgoPrefs
589 QDialog dia( mParent, "dia", true ); 599 QDialog dia( mParent, "dia", true );
590 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 600 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
591 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 601 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
592 QVBoxLayout lay ( &dia ); 602 QVBoxLayout lay ( &dia );
593 lay.setSpacing( 2 ); 603 lay.setSpacing( 2 );
594 lay.setMargin( 3 ); 604 lay.setMargin( 3 );
595 lay.addWidget(&gr); 605 lay.addWidget(&gr);
596 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 606 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
597 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 607 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
598 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 608 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
599 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 609 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
600 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 610 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
601 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 611 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
602 //QRadioButton both( i18n("Take both on conflict"), &gr ); 612 //QRadioButton both( i18n("Take both on conflict"), &gr );
603 QPushButton pb ( "OK", &dia); 613 QPushButton pb ( "OK", &dia);
604 lay.addWidget( &pb ); 614 lay.addWidget( &pb );
605 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 615 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
606 switch ( mSyncAlgoPrefs ) { 616 switch ( mSyncAlgoPrefs ) {
607 case 0: 617 case 0:
608 loc.setChecked( true); 618 loc.setChecked( true);
609 break; 619 break;
610 case 1: 620 case 1:
611 rem.setChecked( true ); 621 rem.setChecked( true );
612 break; 622 break;
613 case 2: 623 case 2:
614 newest.setChecked( true); 624 newest.setChecked( true);
615 break; 625 break;
616 case 3: 626 case 3:
617 ask.setChecked( true); 627 ask.setChecked( true);
618 break; 628 break;
619 case 4: 629 case 4:
620 f_loc.setChecked( true); 630 f_loc.setChecked( true);
621 break; 631 break;
622 case 5: 632 case 5:
623 f_rem.setChecked( true); 633 f_rem.setChecked( true);
624 break; 634 break;
625 case 6: 635 case 6:
626 // both.setChecked( true); 636 // both.setChecked( true);
627 break; 637 break;
628 default: 638 default:
629 break; 639 break;
630 } 640 }
631 if ( dia.exec() ) { 641 if ( dia.exec() ) {
632 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 642 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
633 } 643 }
634 644
635 645
636} 646}
637QString KSyncManager::getPassword( ) 647QString KSyncManager::getPassword( )
638{ 648{
639 QString retfile = ""; 649 QString retfile = "";
640 QDialog dia ( mParent, "input-dialog", true ); 650 QDialog dia ( mParent, "input-dialog", true );
641 QLineEdit lab ( &dia ); 651 QLineEdit lab ( &dia );
642 lab.setEchoMode( QLineEdit::Password ); 652 lab.setEchoMode( QLineEdit::Password );
643 QVBoxLayout lay( &dia ); 653 QVBoxLayout lay( &dia );
644 lay.setMargin(7); 654 lay.setMargin(7);
645 lay.setSpacing(7); 655 lay.setSpacing(7);
646 lay.addWidget( &lab); 656 lay.addWidget( &lab);
647 dia.setFixedSize( 230,50 ); 657 dia.setFixedSize( 230,50 );
648 dia.setCaption( i18n("Enter password") ); 658 dia.setCaption( i18n("Enter password") );
649 QPushButton pb ( "OK", &dia); 659 QPushButton pb ( "OK", &dia);
650 lay.addWidget( &pb ); 660 lay.addWidget( &pb );
651 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 661 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
652 dia.show(); 662 dia.show();
653 int res = dia.exec(); 663 int res = dia.exec();
654 if ( res ) 664 if ( res )
655 retfile = lab.text(); 665 retfile = lab.text();
656 dia.hide(); 666 dia.hide();
657 qApp->processEvents(); 667 qApp->processEvents();
658 return retfile; 668 return retfile;
659 669
660} 670}
661 671
662 672
663void KSyncManager::confSync() 673void KSyncManager::confSync()
664{ 674{
665 static KSyncPrefsDialog* sp = 0; 675 static KSyncPrefsDialog* sp = 0;
666 if ( ! sp ) { 676 if ( ! sp ) {
667 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 677 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
668 } 678 }
669 sp->usrReadConfig(); 679 sp->usrReadConfig();
670#ifndef DESKTOP_VERSION 680#ifndef DESKTOP_VERSION
671 sp->showMaximized(); 681 sp->showMaximized();
672#else 682#else
673 sp->show(); 683 sp->show();
674#endif 684#endif
675 sp->exec(); 685 sp->exec();
676 mSyncProfileNames = sp->getSyncProfileNames(); 686 mSyncProfileNames = sp->getSyncProfileNames();
677 mLocalMachineName = sp->getLocalMachineName (); 687 mLocalMachineName = sp->getLocalMachineName ();
678 fillSyncMenu(); 688 fillSyncMenu();
679} 689}
680 690
681void KSyncManager::syncSharp() 691void KSyncManager::syncSharp()
682{ 692{
683 if ( ! syncExternalApplication("sharp") ) 693 if ( ! syncExternalApplication("sharp") )
684 qDebug("ERROR sync sharp ");; 694 qDebug("ERROR sync sharp ");;
685} 695}
686 696
687bool KSyncManager::syncExternalApplication(QString resource) 697bool KSyncManager::syncExternalApplication(QString resource)
688{ 698{
689 699
690 emit save(); 700 emit save();
691 701
692 if ( mAskForPreferences ) 702 if ( mAskForPreferences )
693 edit_sync_options(); 703 edit_sync_options();
694 704
695 qDebug("sync %s", resource.latin1()); 705 qDebug("sync %s", resource.latin1());
696 706
697 bool syncOK = mImplementation->syncExternal(this, resource); 707 bool syncOK = mImplementation->syncExternal(this, resource);
698 708
699 return syncOK; 709 return syncOK;
700 710
701} 711}
702 712
703void KSyncManager::syncPhone() 713void KSyncManager::syncPhone()
704{ 714{
705 emit save(); 715 emit save();
706 716
707 qDebug("pending syncPhone(); "); 717 qDebug("pending syncPhone(); ");
708 //mView->syncPhone(); 718 //mView->syncPhone();
709 719
710} 720}
711 721
712void KSyncManager::showProgressBar(int percentage, QString caption, int total) 722void KSyncManager::showProgressBar(int percentage, QString caption, int total)
713{ 723{
714 if (!bar->isVisible()) 724 if (!bar->isVisible())
715 { 725 {
716 bar->setCaption (caption); 726 bar->setCaption (caption);
717 bar->setTotalSteps ( total ) ; 727 bar->setTotalSteps ( total ) ;
718 728
719 bar->show(); 729 bar->show();
720 } 730 }
721 731
722 bar->setProgress( percentage ); 732 bar->setProgress( percentage );
723} 733}
724 734
725void KSyncManager::hideProgressBar() 735void KSyncManager::hideProgressBar()
726{ 736{
727 bar->hide(); 737 bar->hide();
728} 738}
729 739
730bool KSyncManager::isProgressBarCanceled() 740bool KSyncManager::isProgressBarCanceled()
731{ 741{
732 return !bar->isVisible(); 742 return !bar->isVisible();
733} 743}
734 744
735QString KSyncManager::syncFileName() 745QString KSyncManager::syncFileName()
736{ 746{
737 747
738 QString fn = "tempfile"; 748 QString fn = "tempfile";
739 switch(mTargetApp) 749 switch(mTargetApp)
740 { 750 {
741 case (KAPI): 751 case (KAPI):
742 fn = "addressbook.vcf"; 752 fn = "addressbook.vcf";
743 break; 753 break;
744 case (KOPI): 754 case (KOPI):
745 fn = "synccalendar.ics"; 755 fn = "synccalendar.ics";
746 break; 756 break;
747 case (PWMPI): 757 case (PWMPI):
748 fn = "manager.pwm"; 758 fn = "manager.pwm";
749 break; 759 break;
750 default: 760 default:
751 break; 761 break;
752 } 762 }
753#ifdef _WIN32_ 763#ifdef _WIN32_
754 return locateLocal( "tmp", fn ); 764 return locateLocal( "tmp", fn );
755#else 765#else
756 return (QString( "/tmp/" )+ fn ); 766 return (QString( "/tmp/" )+ fn );
757#endif 767#endif
758} 768}
759 769
760void KSyncManager::syncPi() 770void KSyncManager::syncPi()
761{ 771{
762 qApp->processEvents(); 772 qApp->processEvents();
763 bool ok; 773 bool ok;
764 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
765 if ( ! ok ) { 775 if ( ! ok ) {
766 mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 776 mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
767 return; 777 return;
768 } 778 }
769 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
770 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
771 mParent->setCaption( i18n("Sending request for remote file ...") ); 781 mParent->setCaption( i18n("Sending request for remote file ...") );
772 commandSocket->readFile( syncFileName() ); 782 commandSocket->readFile( syncFileName() );
773} 783}
774 784
775void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
776{ 786{
777 qDebug("MainWindow::deleteCommandSocket %d", state); 787 qDebug("MainWindow::deleteCommandSocket %d", state);
778 788
779 //enum { success, errorW, errorR, quiet }; 789 //enum { success, errorW, errorR, quiet };
780 if ( state == KCommandSocket::errorR ) { 790 if ( state == KCommandSocket::errorR ) {
781 mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); 791 mParent->setCaption( i18n("ERROR: Receiving remote file failed.") );
782 delete s; 792 delete s;
783 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 793 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
784 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 794 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
785 commandSocket->sendStop(); 795 commandSocket->sendStop();
786 return; 796 return;
787 797
788 } else if ( state == KCommandSocket::errorW ) { 798 } else if ( state == KCommandSocket::errorW ) {
789 mParent->setCaption( i18n("ERROR:Writing back file failed.") ); 799 mParent->setCaption( i18n("ERROR:Writing back file failed.") );
790 800
791 } else if ( state == KCommandSocket::successR ) { 801 } else if ( state == KCommandSocket::successR ) {
792 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 802 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
793 803
794 } else if ( state == KCommandSocket::successW ) { 804 } else if ( state == KCommandSocket::successW ) {
795 mParent->setCaption( i18n("Pi-Sync succesful!") ); 805 mParent->setCaption( i18n("Pi-Sync succesful!") );
796 } 806 }
797 807
798 delete s; 808 delete s;
799} 809}
800 810
801void KSyncManager::readFileFromSocket() 811void KSyncManager::readFileFromSocket()
802{ 812{
803 QString fileName = syncFileName(); 813 QString fileName = syncFileName();
804 mParent->setCaption( i18n("Remote file saved to temp file.") ); 814 mParent->setCaption( i18n("Remote file saved to temp file.") );
805 if ( ! syncWithFile( fileName , true ) ) { 815 if ( ! syncWithFile( fileName , true ) ) {
806 mParent->setCaption( i18n("Syncing failed.") ); 816 mParent->setCaption( i18n("Syncing failed.") );
807 qDebug("Syncing failed "); 817 qDebug("Syncing failed ");
808 return; 818 return;
809 } 819 }
810 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 820 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
811 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 821 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
812 if ( mWriteBackFile ) 822 if ( mWriteBackFile )
813 commandSocket->writeFile( fileName ); 823 commandSocket->writeFile( fileName );
814 else { 824 else {
815 commandSocket->sendStop(); 825 commandSocket->sendStop();
816 mParent->setCaption( i18n("Pi-Sync succesful!") ); 826 mParent->setCaption( i18n("Pi-Sync succesful!") );
817 } 827 }
818} 828}
819 829
820 830
821 831
822 832
823 833
824 834
825 835
826 836
827 837
828 838
829 839
830 840
831 841
832 842
833 843
834 844
835 845
836 846
837 847
838 848
839 849
840 850
841 851
842KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 852KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
843{ 853{
844 mPassWord = pw; 854 mPassWord = pw;
845 mSocket = 0; 855 mSocket = 0;
846 mSyncActionDialog = 0; 856 mSyncActionDialog = 0;
847 blockRC = false; 857 blockRC = false;
848}; 858};
849 859
850void KServerSocket::newConnection ( int socket ) 860void KServerSocket::newConnection ( int socket )
851{ 861{
852 // qDebug("KServerSocket:New connection %d ", socket); 862 // qDebug("KServerSocket:New connection %d ", socket);
853 if ( mSocket ) { 863 if ( mSocket ) {
854 qDebug("KServerSocket::newConnection Socket deleted! "); 864 qDebug("KServerSocket::newConnection Socket deleted! ");
855 delete mSocket; 865 delete mSocket;
856 mSocket = 0; 866 mSocket = 0;
857 } 867 }
858 mSocket = new QSocket( this ); 868 mSocket = new QSocket( this );
859 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 869 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
860 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 870 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
861 mSocket->setSocket( socket ); 871 mSocket->setSocket( socket );
862} 872}
863 873
864void KServerSocket::discardClient() 874void KServerSocket::discardClient()
865{ 875{
866 //qDebug(" KServerSocket::discardClient()"); 876 //qDebug(" KServerSocket::discardClient()");
867 if ( mSocket ) { 877 if ( mSocket ) {
868 delete mSocket; 878 delete mSocket;
869 mSocket = 0; 879 mSocket = 0;
870 } 880 }
871 //emit endConnect(); 881 //emit endConnect();
872} 882}
873void KServerSocket::readClient() 883void KServerSocket::readClient()
874{ 884{
875 if ( blockRC ) 885 if ( blockRC )
876 return; 886 return;
877 if ( mSocket == 0 ) { 887 if ( mSocket == 0 ) {
878 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 888 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
879 return; 889 return;
880 } 890 }
881 qDebug("KServerSocket readClient()"); 891 qDebug("KServerSocket readClient()");
882 if ( mSocket->canReadLine() ) { 892 if ( mSocket->canReadLine() ) {
883 QString line = mSocket->readLine(); 893 QString line = mSocket->readLine();
884 qDebug("KServerSocket readline: %s ", line.latin1()); 894 qDebug("KServerSocket readline: %s ", line.latin1());
885 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 895 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
886 if ( tokens[0] == "GET" ) { 896 if ( tokens[0] == "GET" ) {
887 if ( tokens[1] == mPassWord ) 897 if ( tokens[1] == mPassWord )
888 //emit sendFile( mSocket ); 898 //emit sendFile( mSocket );
889 send_file(); 899 send_file();
890 else { 900 else {
891 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 901 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
892 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 902 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
893 } 903 }
894 } 904 }
895 if ( tokens[0] == "PUT" ) { 905 if ( tokens[0] == "PUT" ) {
896 if ( tokens[1] == mPassWord ) { 906 if ( tokens[1] == mPassWord ) {
897 //emit getFile( mSocket ); 907 //emit getFile( mSocket );
898 blockRC = true; 908 blockRC = true;
899 get_file(); 909 get_file();
900 } 910 }
901 else { 911 else {
902 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 912 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
903 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 913 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
904 } 914 }
905 } 915 }
906 if ( tokens[0] == "STOP" ) { 916 if ( tokens[0] == "STOP" ) {
907 //emit endConnect(); 917 //emit endConnect();
908 end_connect(); 918 end_connect();
909 } 919 }
910 } 920 }
911} 921}
912void KServerSocket::end_connect() 922void KServerSocket::end_connect()
913{ 923{
914 delete mSyncActionDialog; 924 delete mSyncActionDialog;
915 mSyncActionDialog = 0; 925 mSyncActionDialog = 0;
916} 926}
917void KServerSocket::send_file() 927void KServerSocket::send_file()
918{ 928{
919 //qDebug("MainWindow::sendFile(QSocket* s) "); 929 //qDebug("MainWindow::sendFile(QSocket* s) ");
920 if ( mSyncActionDialog ) 930 if ( mSyncActionDialog )
921 delete mSyncActionDialog; 931 delete mSyncActionDialog;
922 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 932 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
923 mSyncActionDialog->setCaption(i18n("Received sync request")); 933 mSyncActionDialog->setCaption(i18n("Received sync request"));
924 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 934 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
925 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 935 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
926 lay->addWidget( label); 936 lay->addWidget( label);
927 lay->setMargin(7); 937 lay->setMargin(7);
928 lay->setSpacing(7); 938 lay->setSpacing(7);
929 mSyncActionDialog->setFixedSize( 230, 120); 939 mSyncActionDialog->setFixedSize( 230, 120);
930 mSyncActionDialog->show(); 940 mSyncActionDialog->show();
931 qDebug("KSS::saving ... "); 941 qDebug("KSS::saving ... ");
932 emit request_file(); 942 emit request_file();
933 qApp->processEvents(); 943 qApp->processEvents();
934 QString fileName = mFileName; 944 QString fileName = mFileName;
935 QFile file( fileName ); 945 QFile file( fileName );
936 if (!file.open( IO_ReadOnly ) ) { 946 if (!file.open( IO_ReadOnly ) ) {
937 delete mSyncActionDialog; 947 delete mSyncActionDialog;
938 mSyncActionDialog = 0; 948 mSyncActionDialog = 0;
939 qDebug("KSS::error open file "); 949 qDebug("KSS::error open file ");
940 mSocket->close(); 950 mSocket->close();
941 if ( mSocket->state() == QSocket::Idle ) 951 if ( mSocket->state() == QSocket::Idle )
942 QTimer::singleShot( 10, this , SLOT ( discardClient())); 952 QTimer::singleShot( 10, this , SLOT ( discardClient()));
943 return ; 953 return ;
944 954
945 } 955 }
946 mSyncActionDialog->setCaption( i18n("Sending file...") ); 956 mSyncActionDialog->setCaption( i18n("Sending file...") );
947 QTextStream ts( &file ); 957 QTextStream ts( &file );
948 ts.setCodec( QTextCodec::codecForName("utf8") ); 958 ts.setCodec( QTextCodec::codecForName("utf8") );
949 QTextStream os( mSocket ); 959 QTextStream os( mSocket );
950 os.setCodec( QTextCodec::codecForName("utf8") ); 960 os.setCodec( QTextCodec::codecForName("utf8") );
951 //os.setEncoding( QTextStream::UnicodeUTF8 ); 961 //os.setEncoding( QTextStream::UnicodeUTF8 );
952 while ( ! ts.atEnd() ) { 962 while ( ! ts.atEnd() ) {
953 os << ts.readLine() << "\n"; 963 os << ts.readLine() << "\n";
954 } 964 }
955 //os << ts.read(); 965 //os << ts.read();
956 file.close(); 966 file.close();
957 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 967 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
958 mSocket->close(); 968 mSocket->close();
959 if ( mSocket->state() == QSocket::Idle ) 969 if ( mSocket->state() == QSocket::Idle )
960 QTimer::singleShot( 10, this , SLOT ( discardClient())); 970 QTimer::singleShot( 10, this , SLOT ( discardClient()));
961} 971}
962void KServerSocket::get_file() 972void KServerSocket::get_file()
963{ 973{
964 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 974 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
965 975
966 piTime.start(); 976 piTime.start();
967 piFileString = ""; 977 piFileString = "";
968 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 978 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
969} 979}
970 980
971 981
972void KServerSocket::readBackFileFromSocket() 982void KServerSocket::readBackFileFromSocket()
973{ 983{
974 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 984 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
975 while ( mSocket->canReadLine () ) { 985 while ( mSocket->canReadLine () ) {
976 piTime.restart(); 986 piTime.restart();
977 QString line = mSocket->readLine (); 987 QString line = mSocket->readLine ();
978 piFileString += line; 988 piFileString += line;
979 //qDebug("readline: %s ", line.latin1()); 989 //qDebug("readline: %s ", line.latin1());
980 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 990 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
981 991
982 } 992 }
983 if ( piTime.elapsed () < 3000 ) { 993 if ( piTime.elapsed () < 3000 ) {
984 // wait for more 994 // wait for more
985 //qDebug("waitformore "); 995 //qDebug("waitformore ");
986 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 996 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
987 return; 997 return;
988 } 998 }
989 QString fileName = mFileName; 999 QString fileName = mFileName;
990 QFile file ( fileName ); 1000 QFile file ( fileName );
991 if (!file.open( IO_WriteOnly ) ) { 1001 if (!file.open( IO_WriteOnly ) ) {
992 delete mSyncActionDialog; 1002 delete mSyncActionDialog;
993 mSyncActionDialog = 0; 1003 mSyncActionDialog = 0;
994 qDebug("error open cal file "); 1004 qDebug("error open cal file ");
995 piFileString = ""; 1005 piFileString = "";
996 emit file_received( false ); 1006 emit file_received( false );
997 blockRC = false; 1007 blockRC = false;
998 return ; 1008 return ;
999 1009
1000 } 1010 }
1001 1011
1002 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1012 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1003 QTextStream ts ( &file ); 1013 QTextStream ts ( &file );
1004 ts.setCodec( QTextCodec::codecForName("utf8") ); 1014 ts.setCodec( QTextCodec::codecForName("utf8") );
1005 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1015 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1006 ts << piFileString; 1016 ts << piFileString;
1007 mSocket->close(); 1017 mSocket->close();
1008 if ( mSocket->state() == QSocket::Idle ) 1018 if ( mSocket->state() == QSocket::Idle )
1009 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1019 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1010 file.close(); 1020 file.close();
1011 delete mSyncActionDialog; 1021 delete mSyncActionDialog;
1012 mSyncActionDialog = 0; 1022 mSyncActionDialog = 0;
1013 piFileString = ""; 1023 piFileString = "";
1014 blockRC = false; 1024 blockRC = false;
1015 emit file_received( true ); 1025 emit file_received( true );
1016 1026
1017} 1027}
1018 1028
1019KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1029KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1020{ 1030{
1021 mPassWord = password; 1031 mPassWord = password;
1022 mSocket = 0; 1032 mSocket = 0;
1023 mPort = port; 1033 mPort = port;
1024 mHost = host; 1034 mHost = host;
1025 1035
1026 mRetVal = quiet; 1036 mRetVal = quiet;
1027 mTimerSocket = new QTimer ( this ); 1037 mTimerSocket = new QTimer ( this );
1028 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1038 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1029} 1039}
1030void KCommandSocket::readFile( QString fn ) 1040void KCommandSocket::readFile( QString fn )
1031{ 1041{
1032 if ( !mSocket ) { 1042 if ( !mSocket ) {
1033 mSocket = new QSocket( this ); 1043 mSocket = new QSocket( this );
1034 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1044 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1035 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1045 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1036 } 1046 }
1037 mFileString = ""; 1047 mFileString = "";
1038 mFileName = fn; 1048 mFileName = fn;
1039 mFirst = true; 1049 mFirst = true;
1040 mSocket->connectToHost( mHost, mPort ); 1050 mSocket->connectToHost( mHost, mPort );
1041 QTextStream os( mSocket ); 1051 QTextStream os( mSocket );
1042 os.setEncoding( QTextStream::UnicodeUTF8 ); 1052 os.setEncoding( QTextStream::UnicodeUTF8 );
1043 os << "GET " << mPassWord << "\r\n"; 1053 os << "GET " << mPassWord << "\r\n";
1044 mTimerSocket->start( 10000 ); 1054 mTimerSocket->start( 10000 );
1045} 1055}
1046 1056
1047void KCommandSocket::writeFile( QString fileName ) 1057void KCommandSocket::writeFile( QString fileName )
1048{ 1058{
1049 if ( !mSocket ) { 1059 if ( !mSocket ) {
1050 mSocket = new QSocket( this ); 1060 mSocket = new QSocket( this );
1051 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1061 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1052 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1062 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1053 } 1063 }
1054 mFileName = fileName ; 1064 mFileName = fileName ;
1055 mSocket->connectToHost( mHost, mPort ); 1065 mSocket->connectToHost( mHost, mPort );
1056} 1066}
1057void KCommandSocket::writeFileToSocket() 1067void KCommandSocket::writeFileToSocket()
1058{ 1068{
1059 QFile file2( mFileName ); 1069 QFile file2( mFileName );
1060 if (!file2.open( IO_ReadOnly ) ) { 1070 if (!file2.open( IO_ReadOnly ) ) {
1061 mRetVal= errorW; 1071 mRetVal= errorW;
1062 mSocket->close(); 1072 mSocket->close();
1063 if ( mSocket->state() == QSocket::Idle ) 1073 if ( mSocket->state() == QSocket::Idle )
1064 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1074 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1065 return ; 1075 return ;
1066 } 1076 }
1067 QTextStream ts2( &file2 ); 1077 QTextStream ts2( &file2 );
1068 ts2.setCodec( QTextCodec::codecForName("utf8") ); 1078 ts2.setCodec( QTextCodec::codecForName("utf8") );
1069 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1070 os2.setCodec( QTextCodec::codecForName("utf8") ); 1080 os2.setCodec( QTextCodec::codecForName("utf8") );
1071 os2 << "PUT " << mPassWord << "\r\n";; 1081 os2 << "PUT " << mPassWord << "\r\n";;
1072 while ( ! ts2.atEnd() ) { 1082 while ( ! ts2.atEnd() ) {
1073 os2 << ts2.readLine() << "\n"; 1083 os2 << ts2.readLine() << "\n";
1074 } 1084 }
1075 mRetVal= successW; 1085 mRetVal= successW;
1076 file2.close(); 1086 file2.close();
1077 mSocket->close(); 1087 mSocket->close();
1078 if ( mSocket->state() == QSocket::Idle ) 1088 if ( mSocket->state() == QSocket::Idle )
1079 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1080} 1090}
1081void KCommandSocket::sendStop() 1091void KCommandSocket::sendStop()
1082{ 1092{
1083 if ( !mSocket ) { 1093 if ( !mSocket ) {
1084 mSocket = new QSocket( this ); 1094 mSocket = new QSocket( this );
1085 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1086 } 1096 }
1087 mSocket->connectToHost( mHost, mPort ); 1097 mSocket->connectToHost( mHost, mPort );
1088 QTextStream os2( mSocket ); 1098 QTextStream os2( mSocket );
1089 os2.setCodec( QTextCodec::codecForName("utf8") ); 1099 os2.setCodec( QTextCodec::codecForName("utf8") );
1090 os2 << "STOP\r\n"; 1100 os2 << "STOP\r\n";
1091 mSocket->close(); 1101 mSocket->close();
1092 if ( mSocket->state() == QSocket::Idle ) 1102 if ( mSocket->state() == QSocket::Idle )
1093 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1094} 1104}
1095 1105
1096void KCommandSocket::startReadFileFromSocket() 1106void KCommandSocket::startReadFileFromSocket()
1097{ 1107{
1098 if ( ! mFirst ) 1108 if ( ! mFirst )
1099 return; 1109 return;
1100 mFirst = false; 1110 mFirst = false;
1101 mTimerSocket->stop(); 1111 mTimerSocket->stop();
1102 mFileString = ""; 1112 mFileString = "";
1103 mTime.start(); 1113 mTime.start();
1104 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1105 1115
1106} 1116}
1107void KCommandSocket::readFileFromSocket() 1117void KCommandSocket::readFileFromSocket()
1108{ 1118{
1109 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1110 while ( mSocket->canReadLine () ) { 1120 while ( mSocket->canReadLine () ) {
1111 mTime.restart(); 1121 mTime.restart();
1112 QString line = mSocket->readLine (); 1122 QString line = mSocket->readLine ();
1113 mFileString += line; 1123 mFileString += line;
1114 //qDebug("readline: %s ", line.latin1()); 1124 //qDebug("readline: %s ", line.latin1());
1115 } 1125 }
1116 if ( mTime.elapsed () < 3000 ) { 1126 if ( mTime.elapsed () < 3000 ) {
1117 // wait for more 1127 // wait for more
1118 //qDebug("waitformore "); 1128 //qDebug("waitformore ");
1119 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1120 return; 1130 return;
1121 } 1131 }
1122 QString fileName = mFileName; 1132 QString fileName = mFileName;
1123 QFile file ( fileName ); 1133 QFile file ( fileName );
1124 if (!file.open( IO_WriteOnly ) ) { 1134 if (!file.open( IO_WriteOnly ) ) {
1125 mFileString = ""; 1135 mFileString = "";
1126 mRetVal = errorR; 1136 mRetVal = errorR;
1127 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1128 deleteSocket(); 1138 deleteSocket();
1129 return ; 1139 return ;
1130 1140
1131 } 1141 }
1132 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1133 QTextStream ts ( &file ); 1143 QTextStream ts ( &file );
1134 ts.setCodec( QTextCodec::codecForName("utf8") ); 1144 ts.setCodec( QTextCodec::codecForName("utf8") );
1135 ts << mFileString; 1145 ts << mFileString;
1136 file.close(); 1146 file.close();
1137 mFileString = ""; 1147 mFileString = "";
1138 mRetVal = successR; 1148 mRetVal = successR;
1139 mSocket->close(); 1149 mSocket->close();
1140 // if state is not idle, deleteSocket(); is called via 1150 // if state is not idle, deleteSocket(); is called via
1141 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1142 if ( mSocket->state() == QSocket::Idle ) 1152 if ( mSocket->state() == QSocket::Idle )
1143 deleteSocket(); 1153 deleteSocket();
1144} 1154}
1145 1155
1146void KCommandSocket::deleteSocket() 1156void KCommandSocket::deleteSocket()
1147{ 1157{
1148 if ( mTimerSocket->isActive () ) { 1158 if ( mTimerSocket->isActive () ) {
1149 mTimerSocket->stop(); 1159 mTimerSocket->stop();
1150 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1160 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1151 mRetVal = errorR; 1161 mRetVal = errorR;
1152 } 1162 }
1153 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1163 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1154 if ( mSocket) 1164 if ( mSocket)
1155 delete mSocket; 1165 delete mSocket;
1156 mSocket = 0; 1166 mSocket = 0;
1157 emit commandFinished( this, mRetVal ); 1167 emit commandFinished( this, mRetVal );
1158} 1168}
1159 1169