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