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