summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp44
-rw-r--r--libkcal/calendarlocal.cpp27
2 files changed, 41 insertions, 30 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1800cf2..8385bcc 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,5273 +1,5275 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) savecale1997, 1998, 1999 7 Copyright (c) savecale1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "koagenda.h" 107#include "koagenda.h"
108#include "kodialogmanager.h" 108#include "kodialogmanager.h"
109#include "outgoingdialog.h" 109#include "outgoingdialog.h"
110#include "incomingdialog.h" 110#include "incomingdialog.h"
111#include "datenavigatorcontainer.h" 111#include "datenavigatorcontainer.h"
112#include "statusdialog.h" 112#include "statusdialog.h"
113#include "kdatenavigator.h" 113#include "kdatenavigator.h"
114#include "kotodoview.h" 114#include "kotodoview.h"
115#include "datenavigator.h" 115#include "datenavigator.h"
116#include "resourceview.h" 116#include "resourceview.h"
117#include "navigatorbar.h" 117#include "navigatorbar.h"
118#include "searchdialog.h" 118#include "searchdialog.h"
119#include "mainwindow.h" 119#include "mainwindow.h"
120#include "categoryeditdialog.h" 120#include "categoryeditdialog.h"
121 121
122#include "calendarview.h" 122#include "calendarview.h"
123#ifndef DESKTOP_VERSION 123#ifndef DESKTOP_VERSION
124#include <qtopia/alarmserver.h> 124#include <qtopia/alarmserver.h>
125#endif 125#endif
126#ifndef _WIN32_ 126#ifndef _WIN32_
127#include <stdlib.h> 127#include <stdlib.h>
128#include <stdio.h> 128#include <stdio.h>
129#include <unistd.h> 129#include <unistd.h>
130#else 130#else
131#include <qprocess.h> 131#include <qprocess.h>
132#endif 132#endif
133 133
134#ifdef DESKTOP_VERSION 134#ifdef DESKTOP_VERSION
135#include <kabc/stdaddressbook.h> 135#include <kabc/stdaddressbook.h>
136#endif 136#endif
137using namespace KOrg; 137using namespace KOrg;
138using namespace KCal; 138using namespace KCal;
139extern int globalFlagBlockAgenda; 139extern int globalFlagBlockAgenda;
140extern int globalFlagBlockStartup; 140extern int globalFlagBlockStartup;
141 141
142 142
143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
144 144
145{ 145{
146 mAlarms = alarms; 146 mAlarms = alarms;
147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
148 QString mText = "<table width=\"100%\">\n"; 148 QString mText = "<table width=\"100%\">\n";
149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
150#ifdef DESKTOP_VERSION 150#ifdef DESKTOP_VERSION
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
152#else 152#else
153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
154#endif 154#endif
155 // mText += "<img src=\""; 155 // mText += "<img src=\"";
156 // mText += ipath; 156 // mText += ipath;
157 // mText += "\">"; 157 // mText += "\">";
158 //mEventDate = QDate::currentDate(); 158 //mEventDate = QDate::currentDate();
159#ifdef DESKTOP_VERSION 159#ifdef DESKTOP_VERSION
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
161#else 161#else
162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
163#endif 163#endif
164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
165 165
166 Incidence * inc = getNextInc( start ); 166 Incidence * inc = getNextInc( start );
167 int time = 0; 167 int time = 0;
168 //mText += "<table>"; 168 //mText += "<table>";
169 while ( inc ) { 169 while ( inc ) {
170 QDateTime dt ; 170 QDateTime dt ;
171 QString tempText = "<a "; 171 QString tempText = "<a ";
172 bool ok; 172 bool ok;
173 dt = inc->getNextOccurence( start, &ok ); 173 dt = inc->getNextOccurence( start, &ok );
174 if ( !ok ) continue; 174 if ( !ok ) continue;
175 if ( inc->typeID() == eventID ) { 175 if ( inc->typeID() == eventID ) {
176 tempText += "href=\"event:"; 176 tempText += "href=\"event:";
177 } else if ( inc->typeID() == todoID ) { 177 } else if ( inc->typeID() == todoID ) {
178 tempText += "href=\"todo:"; 178 tempText += "href=\"todo:";
179 } 179 }
180 tempText += inc->uid() + "\">"; 180 tempText += inc->uid() + "\">";
181 if ( inc->typeID() == todoID ) 181 if ( inc->typeID() == todoID )
182 tempText += i18n("Todo: "); 182 tempText += i18n("Todo: ");
183 if ( inc->summary().length() > 0 ) 183 if ( inc->summary().length() > 0 )
184 tempText += inc->summary(); 184 tempText += inc->summary();
185 else 185 else
186 tempText += i18n("-no summary-"); 186 tempText += i18n("-no summary-");
187 QString timestr; 187 QString timestr;
188 if (!inc->doesFloat()) 188 if (!inc->doesFloat())
189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
190 else 190 else
191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
192 if ( dt.date() < QDate::currentDate() && time == 0 ) { 192 if ( dt.date() < QDate::currentDate() && time == 0 ) {
193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
194 mText += "<table>"; 194 mText += "<table>";
195 time = 1; 195 time = 1;
196 } 196 }
197 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 197 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
198 if ( time > 0 ) 198 if ( time > 0 )
199 mText +="</table>"; 199 mText +="</table>";
200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
201 mText += "<table>"; 201 mText += "<table>";
202 time = 2; 202 time = 2;
203 203
204 } 204 }
205 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 205 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
206 if ( time > 0 ) 206 if ( time > 0 )
207 mText +="</table>"; 207 mText +="</table>";
208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
209 mText += "<table>"; 209 mText += "<table>";
210 time = 3; 210 time = 3;
211 } 211 }
212 mText +="<tr><td><b>"; 212 mText +="<tr><td><b>";
213 mText += timestr; 213 mText += timestr;
214 mText += "</b></td><td>"; 214 mText += "</b></td><td>";
215 mText += tempText; 215 mText += tempText;
216 mText += "</td></tr>\n"; 216 mText += "</td></tr>\n";
217 inc = getNextInc( start ); 217 inc = getNextInc( start );
218 } 218 }
219 mText +="</table>"; 219 mText +="</table>";
220 setText( mText ); 220 setText( mText );
221} 221}
222 222
223MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 223MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
224{ 224{
225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
226} 226}
227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
228{ 228{
229 QDateTime dt ; 229 QDateTime dt ;
230 Incidence * retInc; 230 Incidence * retInc;
231 Incidence * inc = mAlarms.first(); 231 Incidence * inc = mAlarms.first();
232 if ( inc == 0 ) 232 if ( inc == 0 )
233 return 0; 233 return 0;
234 bool ok; 234 bool ok;
235 dt = inc->getNextOccurence( start, &ok ); 235 dt = inc->getNextOccurence( start, &ok );
236 if ( ! ok ) return 0; 236 if ( ! ok ) return 0;
237 QDateTime dtn ; 237 QDateTime dtn ;
238 retInc = inc; 238 retInc = inc;
239 inc = mAlarms.next(); 239 inc = mAlarms.next();
240 while ( inc ) { 240 while ( inc ) {
241 dtn = inc->getNextOccurence( start, &ok ); 241 dtn = inc->getNextOccurence( start, &ok );
242 if ( ! ok ) return 0; 242 if ( ! ok ) return 0;
243 if ( dtn < dt ) { 243 if ( dtn < dt ) {
244 dt = dtn; 244 dt = dtn;
245 retInc = inc; 245 retInc = inc;
246 } 246 }
247 inc = mAlarms.next(); 247 inc = mAlarms.next();
248 } 248 }
249 mAlarms.remove( retInc ); 249 mAlarms.remove( retInc );
250 return retInc; 250 return retInc;
251 251
252} 252}
253void MissedAlarmTextBrowser::setSource(const QString & n) 253void MissedAlarmTextBrowser::setSource(const QString & n)
254{ 254{
255 if (n.startsWith("event:")) { 255 if (n.startsWith("event:")) {
256#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
257 emit showIncidence(n.mid(8)); 257 emit showIncidence(n.mid(8));
258#else 258#else
259 emit showIncidence(n.mid(6)); 259 emit showIncidence(n.mid(6));
260#endif 260#endif
261 return; 261 return;
262 } else if (n.startsWith("todo:")) { 262 } else if (n.startsWith("todo:")) {
263#ifdef DESKTOP_VERSION 263#ifdef DESKTOP_VERSION
264 emit showIncidence(n.mid(7)); 264 emit showIncidence(n.mid(7));
265#else 265#else
266 emit showIncidence(n.mid(5)); 266 emit showIncidence(n.mid(5));
267#endif 267#endif
268 return; 268 return;
269 } 269 }
270} 270}
271 271
272 272
273class KOBeamPrefs : public QDialog 273class KOBeamPrefs : public QDialog
274{ 274{
275 public: 275 public:
276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
277 QDialog( parent, name, true ) 277 QDialog( parent, name, true )
278 { 278 {
279 setCaption( i18n("Beam Options") ); 279 setCaption( i18n("Beam Options") );
280 QVBoxLayout* lay = new QVBoxLayout( this ); 280 QVBoxLayout* lay = new QVBoxLayout( this );
281 lay->setSpacing( 3 ); 281 lay->setSpacing( 3 );
282 lay->setMargin( 3 ); 282 lay->setMargin( 3 );
283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
284 lay->addWidget( format ); 284 lay->addWidget( format );
285 format->setExclusive ( true ) ; 285 format->setExclusive ( true ) ;
286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
287 lay->addWidget( time ); time->setExclusive ( true ) ; 287 lay->addWidget( time ); time->setExclusive ( true ) ;
288 vcal = new QRadioButton(" vCalendar ", format ); 288 vcal = new QRadioButton(" vCalendar ", format );
289 ical = new QRadioButton(" iCalendar ", format ); 289 ical = new QRadioButton(" iCalendar ", format );
290 vcal->setChecked( true ); 290 vcal->setChecked( true );
291 tz = new QRadioButton(i18n(" With timezone "), time ); 291 tz = new QRadioButton(i18n(" With timezone "), time );
292 local = new QRadioButton(i18n(" Local time "), time ); 292 local = new QRadioButton(i18n(" Local time "), time );
293 tz->setChecked( true ); 293 tz->setChecked( true );
294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
295 lay->addWidget( ok ); 295 lay->addWidget( ok );
296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
297 lay->addWidget( cancel ); 297 lay->addWidget( cancel );
298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
300 resize( 200, 200 ); 300 resize( 200, 200 );
301 } 301 }
302 302
303 bool beamVcal() { return vcal->isChecked(); } 303 bool beamVcal() { return vcal->isChecked(); }
304 bool beamLocal() { return local->isChecked(); } 304 bool beamLocal() { return local->isChecked(); }
305private: 305private:
306 QRadioButton* vcal, *ical, *local, *tz; 306 QRadioButton* vcal, *ical, *local, *tz;
307}; 307};
308class KOCatPrefs : public QDialog 308class KOCatPrefs : public QDialog
309{ 309{
310 public: 310 public:
311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
312 QDialog( parent, name, true ) 312 QDialog( parent, name, true )
313 { 313 {
314 setCaption( i18n("Manage new Categories") ); 314 setCaption( i18n("Manage new Categories") );
315 QVBoxLayout* lay = new QVBoxLayout( this ); 315 QVBoxLayout* lay = new QVBoxLayout( this );
316 lay->setSpacing( 3 ); 316 lay->setSpacing( 3 );
317 lay->setMargin( 3 ); 317 lay->setMargin( 3 );
318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this ); 318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this );
319 lay->addWidget( lab ); 319 lay->addWidget( lab );
320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
321 lay->addWidget( format ); 321 lay->addWidget( format );
322 format->setExclusive ( true ) ; 322 format->setExclusive ( true ) ;
323 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 323 addCatBut = new QRadioButton(i18n("Add to category list"), format );
324 new QRadioButton(i18n("Remove from Events/Todos"), format ); 324 new QRadioButton(i18n("Remove from Events/Todos"), format );
325 addCatBut->setChecked( true ); 325 addCatBut->setChecked( true );
326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this ); 326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this );
327 lay->addWidget( ok ); 327 lay->addWidget( ok );
328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
329 lay->addWidget( cancel ); 329 lay->addWidget( cancel );
330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
332 resize( 200, 200 ); 332 resize( 200, 200 );
333 } 333 }
334 334
335 bool addCat() { return addCatBut->isChecked(); } 335 bool addCat() { return addCatBut->isChecked(); }
336private: 336private:
337 QRadioButton* addCatBut; 337 QRadioButton* addCatBut;
338}; 338};
339 339
340 340
341 341
342CalendarView::CalendarView( CalendarResources *calendar, 342CalendarView::CalendarView( CalendarResources *calendar,
343 QWidget *parent, const char *name ) 343 QWidget *parent, const char *name )
344 : CalendarViewBase( parent, name ), 344 : CalendarViewBase( parent, name ),
345 mCalendar( calendar ), 345 mCalendar( calendar ),
346 mResourceManager( calendar->resourceManager() ) 346 mResourceManager( calendar->resourceManager() )
347{ 347{
348 348
349 mEventEditor = 0; 349 mEventEditor = 0;
350 mTodoEditor = 0; 350 mTodoEditor = 0;
351 351
352 init(); 352 init();
353} 353}
354 354
355CalendarView::CalendarView( Calendar *calendar, 355CalendarView::CalendarView( Calendar *calendar,
356 QWidget *parent, const char *name ) 356 QWidget *parent, const char *name )
357 : CalendarViewBase( parent, name ), 357 : CalendarViewBase( parent, name ),
358 mCalendar( calendar ), 358 mCalendar( calendar ),
359 mResourceManager( 0 ) 359 mResourceManager( 0 )
360{ 360{
361 361
362 mEventEditor = 0; 362 mEventEditor = 0;
363 mTodoEditor = 0; 363 mTodoEditor = 0;
364 init(); 364 init();
365} 365}
366 366
367void CalendarView::init() 367void CalendarView::init()
368{ 368{
369 mMultiResourceSync = false; 369 mMultiResourceSync = false;
370 flag_blockConflict = false; 370 flag_blockConflict = false;
371 flag_blockScrollBar = false; 371 flag_blockScrollBar = false;
372 flag_checkFileFirsttime = true; 372 flag_checkFileFirsttime = true;
373 flag_clearallviewsEventDisplay = false; 373 flag_clearallviewsEventDisplay = false;
374 flag_clearallviewsupdateView = false; 374 flag_clearallviewsupdateView = false;
375 mNextAlarmDateTime = QDateTime::currentDateTime(); 375 mNextAlarmDateTime = QDateTime::currentDateTime();
376 setFocusPolicy (NoFocus ); 376 setFocusPolicy (NoFocus );
377 mViewerCallerIsSearchDialog = false; 377 mViewerCallerIsSearchDialog = false;
378 mBlockShowDates = false; 378 mBlockShowDates = false;
379 mConflictingEvent = 0; 379 mConflictingEvent = 0;
380 mDatePickerMode = 0; 380 mDatePickerMode = 0;
381 mCurrentSyncDevice = ""; 381 mCurrentSyncDevice = "";
382 mViewManager = new KOViewManager( this ); 382 mViewManager = new KOViewManager( this );
383 mDialogManager = new KODialogManager( this ); 383 mDialogManager = new KODialogManager( this );
384 mEventViewerDialog = 0; 384 mEventViewerDialog = 0;
385 mModified = false; 385 mModified = false;
386 mReadOnly = false; 386 mReadOnly = false;
387 mSelectedIncidence = 0; 387 mSelectedIncidence = 0;
388 mCalPrinter = 0; 388 mCalPrinter = 0;
389 mFilters.setAutoDelete(true); 389 mFilters.setAutoDelete(true);
390 390
391 mCalendar->registerObserver( this ); 391 mCalendar->registerObserver( this );
392 // TODO: Make sure that view is updated, when calendar is changed. 392 // TODO: Make sure that view is updated, when calendar is changed.
393 393
394 mStorage = new FileStorage( mCalendar ); 394 mStorage = new FileStorage( mCalendar );
395 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 395 mNavigator = new DateNavigator( this, "datevav", mViewManager );
396 396
397 QBoxLayout *topLayout = (QBoxLayout*)layout(); 397 QBoxLayout *topLayout = (QBoxLayout*)layout();
398#ifndef KORG_NOSPLITTER 398#ifndef KORG_NOSPLITTER
399 // create the main layout frames. 399 // create the main layout frames.
400 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 400 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
401 topLayout->addWidget(mPanner); 401 topLayout->addWidget(mPanner);
402 402
403 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 403 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
404 "CalendarView::LeftFrame"); 404 "CalendarView::LeftFrame");
405 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 405 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
406 406
407 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 407 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
408 "CalendarView::DateNavigator" ); 408 "CalendarView::DateNavigator" );
409 409
410 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 410 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
411 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 411 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
412 mTodoList->setNavigator( mNavigator ); 412 mTodoList->setNavigator( mNavigator );
413 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 413 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
414 414
415#ifdef KORG_NORESOURCEVIEW 415#ifdef KORG_NORESOURCEVIEW
416 mResourceView = 0; 416 mResourceView = 0;
417#else 417#else
418 if ( mResourceManager ) { 418 if ( mResourceManager ) {
419 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 419 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
420 mResourceView->updateView(); 420 mResourceView->updateView();
421 connect( mResourceView, SIGNAL( resourcesChanged() ), 421 connect( mResourceView, SIGNAL( resourcesChanged() ),
422 SLOT( updateView() ) ); 422 SLOT( updateView() ) );
423 } else { 423 } else {
424 mResourceView = 0; 424 mResourceView = 0;
425 } 425 }
426#endif 426#endif
427 QWidget *rightBox = new QWidget( mPanner ); 427 QWidget *rightBox = new QWidget( mPanner );
428 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 428 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
429 429
430 mRightFrame = new QWidgetStack( rightBox ); 430 mRightFrame = new QWidgetStack( rightBox );
431 rightLayout->addWidget( mRightFrame, 1 ); 431 rightLayout->addWidget( mRightFrame, 1 );
432 432
433 mLeftFrame = mLeftSplitter; 433 mLeftFrame = mLeftSplitter;
434#else 434#else
435 //QWidget *mainBox = new QWidget( this ); 435 //QWidget *mainBox = new QWidget( this );
436 //QWidget *leftFrame = new QWidget( mainBox ); 436 //QWidget *leftFrame = new QWidget( mainBox );
437 //QBoxLayout * mainBoxLayout; 437 //QBoxLayout * mainBoxLayout;
438 if ( KOPrefs::instance()->mVerticalScreen ) { 438 if ( KOPrefs::instance()->mVerticalScreen ) {
439 //mainBoxLayout = new QVBoxLayout(mainBox); 439 //mainBoxLayout = new QVBoxLayout(mainBox);
440 //leftFrameLayout = new QHBoxLayout(leftFrame ); 440 //leftFrameLayout = new QHBoxLayout(leftFrame );
441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
445 } else { 445 } else {
446 //mainBoxLayout = new QHBoxLayout(mainBox); 446 //mainBoxLayout = new QHBoxLayout(mainBox);
447 //leftFrameLayout = new QVBoxLayout(leftFrame ); 447 //leftFrameLayout = new QVBoxLayout(leftFrame );
448 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 448 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
449 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 449 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
450 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 450 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
451 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 451 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
452 } 452 }
453 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 453 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
454 //QBoxLayout * leftFrameLayout; 454 //QBoxLayout * leftFrameLayout;
455 topLayout->addWidget( mMainFrame ); 455 topLayout->addWidget( mMainFrame );
456#ifdef DESKTOP_VERSION 456#ifdef DESKTOP_VERSION
457 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this ); 457 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this );
458 topLayout->addWidget( mDateScrollBar ); 458 topLayout->addWidget( mDateScrollBar );
459 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) ); 459 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) );
460 if ( QApplication::desktop()->width() < 800 ) 460 if ( QApplication::desktop()->width() < 800 )
461 mDateScrollBar->hide(); 461 mDateScrollBar->hide();
462#endif 462#endif
463 //mainBoxLayout->addWidget (mLeftFrame); 463 //mainBoxLayout->addWidget (mLeftFrame);
464 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 464 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
465 "CalendarView::DateNavigator" ); 465 "CalendarView::DateNavigator" );
466#if 0 466#if 0
467 // FIXME 467 // FIXME
468 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 468 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
469 "CalendarView::DateNavigator", QDate::currentDate()); 469 "CalendarView::DateNavigator", QDate::currentDate());
470#endif 470#endif
471 // mDateNavigator->blockSignals( true ); 471 // mDateNavigator->blockSignals( true );
472 //leftFrameLayout->addWidget( mDateNavigator ); 472 //leftFrameLayout->addWidget( mDateNavigator );
473 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 473 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
474 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 474 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
475 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 475 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
476 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 476 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
477 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 477 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
478 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); 478 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) );
479 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 479 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
480 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); 480 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
481 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 481 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
482 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 482 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
483 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 483 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
484 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); 484 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() ));
485 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 485 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
486 connect( mCalEditView, SIGNAL( requestCalendarInfo( int ) ),this, SLOT( displayCalendarInfo( int ) ) ); 486 connect( mCalEditView, SIGNAL( requestCalendarInfo( int ) ),this, SLOT( displayCalendarInfo( int ) ) );
487 487
488 488
489 mTodoList->setNavigator( mNavigator ); 489 mTodoList->setNavigator( mNavigator );
490#if 0 490#if 0
491 if ( QApplication::desktop()->width() < 480 ) { 491 if ( QApplication::desktop()->width() < 480 ) {
492 leftFrameLayout->addWidget(mFilterView); 492 leftFrameLayout->addWidget(mFilterView);
493 leftFrameLayout->addWidget(mTodoList, 2 ); 493 leftFrameLayout->addWidget(mTodoList, 2 );
494 494
495 } else { 495 } else {
496 leftFrameLayout->addWidget(mTodoList,2 ); 496 leftFrameLayout->addWidget(mTodoList,2 );
497 leftFrameLayout->addWidget(mFilterView ); 497 leftFrameLayout->addWidget(mFilterView );
498 } 498 }
499#endif 499#endif
500 mFilterView->hide(); 500 mFilterView->hide();
501 mCalEditView->hide(); 501 mCalEditView->hide();
502 QWidget *rightBox = new QWidget( mMainFrame ); 502 QWidget *rightBox = new QWidget( mMainFrame );
503 //mainBoxLayout->addWidget ( rightBox, 10 ); 503 //mainBoxLayout->addWidget ( rightBox, 10 );
504 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 504 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
505 mRightFrame = new QWidgetStack( rightBox ); 505 mRightFrame = new QWidgetStack( rightBox );
506 rightLayout->addWidget( mRightFrame, 10 ); 506 rightLayout->addWidget( mRightFrame, 10 );
507 507
508 //mLeftFrame = (QWidget *)leftFrame; 508 //mLeftFrame = (QWidget *)leftFrame;
509 if ( KOPrefs::instance()->mVerticalScreen ) { 509 if ( KOPrefs::instance()->mVerticalScreen ) {
510 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 510 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
511 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 511 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
512 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 512 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
513 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 513 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
514 } else { 514 } else {
515 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 515 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
516 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 516 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
517 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 517 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
518 } 518 }
519 if ( !KOPrefs::instance()->mShowDateNavigator) 519 if ( !KOPrefs::instance()->mShowDateNavigator)
520 mDateNavigator->hide(); 520 mDateNavigator->hide();
521 //qDebug("Calendarview Size %d %d ", width(), height()); 521 //qDebug("Calendarview Size %d %d ", width(), height());
522#endif 522#endif
523 523
524 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 524 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
525 SLOT( showDates( const KCal::DateList & ) ) ); 525 SLOT( showDates( const KCal::DateList & ) ) );
526 526
527 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 527 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
528 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 528 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
529 529
530 530
531 531
532 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 532 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
533 mViewManager, SLOT( showMonth( const QDate & ) ) ); 533 mViewManager, SLOT( showMonth( const QDate & ) ) );
534 534
535 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 535 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
536 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 536 mNavigator, SLOT( selectWeek( const QDate & ) ) );
537 537
538 connect( mDateNavigator, SIGNAL( goPrevYear() ), 538 connect( mDateNavigator, SIGNAL( goPrevYear() ),
539 mNavigator, SLOT( selectPreviousYear() ) ); 539 mNavigator, SLOT( selectPreviousYear() ) );
540 connect( mDateNavigator, SIGNAL( goNextYear() ), 540 connect( mDateNavigator, SIGNAL( goNextYear() ),
541 mNavigator, SLOT( selectNextYear() ) ); 541 mNavigator, SLOT( selectNextYear() ) );
542 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 542 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
543 mNavigator, SLOT( selectPreviousMonth() ) ); 543 mNavigator, SLOT( selectPreviousMonth() ) );
544 connect( mDateNavigator, SIGNAL( goNextMonth() ), 544 connect( mDateNavigator, SIGNAL( goNextMonth() ),
545 mNavigator, SLOT( selectNextMonth() ) ); 545 mNavigator, SLOT( selectNextMonth() ) );
546 546
547 connect( mDateNavigator, SIGNAL( goPrevious() ), 547 connect( mDateNavigator, SIGNAL( goPrevious() ),
548 mNavigator, SLOT( selectPrevious() ) ); 548 mNavigator, SLOT( selectPrevious() ) );
549 connect( mDateNavigator, SIGNAL( goNext() ), 549 connect( mDateNavigator, SIGNAL( goNext() ),
550 mNavigator, SLOT( selectNext() ) ); 550 mNavigator, SLOT( selectNext() ) );
551 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 551 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
552 mNavigator, SLOT( slotMonthSelect( int ) ) ); 552 mNavigator, SLOT( slotMonthSelect( int ) ) );
553 553
554 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 554 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
555 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 555 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
556#if 0 556#if 0
557 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 557 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
558 SLOT( incidenceAdded( Incidence *) ) ); 558 SLOT( incidenceAdded( Incidence *) ) );
559#endif 559#endif
560 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 560 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
561 561
562 connect( this, SIGNAL( configChanged() ), 562 connect( this, SIGNAL( configChanged() ),
563 mDateNavigator, SLOT( updateConfig() ) ); 563 mDateNavigator, SLOT( updateConfig() ) );
564 564
565 connect( mTodoList, SIGNAL( newTodoSignal() ), 565 connect( mTodoList, SIGNAL( newTodoSignal() ),
566 SLOT( newTodo() ) ); 566 SLOT( newTodo() ) );
567 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 567 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
568 SLOT( newSubTodo( Todo * ) ) ); 568 SLOT( newSubTodo( Todo * ) ) );
569 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 569 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
570 SLOT( editTodo( Todo * ) ) ); 570 SLOT( editTodo( Todo * ) ) );
571 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 571 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
572 SLOT( showTodo( Todo *) ) ); 572 SLOT( showTodo( Todo *) ) );
573 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 573 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
574 SLOT( deleteTodo( Todo *) ) ); 574 SLOT( deleteTodo( Todo *) ) );
575 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 575 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
576 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 576 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
577 SLOT( purgeCompleted() ) ); 577 SLOT( purgeCompleted() ) );
578 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 578 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
579 SIGNAL( todoModified( Todo *, int ) ) ); 579 SIGNAL( todoModified( Todo *, int ) ) );
580 580
581 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 581 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
582 this, SLOT ( cloneIncidence( Incidence * ) ) ); 582 this, SLOT ( cloneIncidence( Incidence * ) ) );
583 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 583 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
584 this, SLOT (cancelIncidence( Incidence * ) ) ); 584 this, SLOT (cancelIncidence( Incidence * ) ) );
585 585
586 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 586 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
587 this, SLOT ( moveIncidence( Incidence * ) ) ); 587 this, SLOT ( moveIncidence( Incidence * ) ) );
588 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 588 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
589 this, SLOT ( beamIncidence( Incidence * ) ) ); 589 this, SLOT ( beamIncidence( Incidence * ) ) );
590 590
591 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 591 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
592 this, SLOT ( todo_unsub( Todo * ) ) ); 592 this, SLOT ( todo_unsub( Todo * ) ) );
593 593
594 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 594 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
595 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 595 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
596 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 596 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
597 SLOT( updateTodo( Todo *, int ) ) ); 597 SLOT( updateTodo( Todo *, int ) ) );
598 connect( this, SIGNAL( todoModified( Todo *, int )), this, 598 connect( this, SIGNAL( todoModified( Todo *, int )), this,
599 SLOT( changeTodoDisplay( Todo *, int ) ) ); 599 SLOT( changeTodoDisplay( Todo *, int ) ) );
600 600
601 601
602 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 602 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
603 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 603 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
604 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 604 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
605 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 605 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
606 606
607 607
608 608
609 609
610 610
611 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 611 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
612 SLOT(checkClipboard())); 612 SLOT(checkClipboard()));
613 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 613 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
614 SLOT( processTodoListSelection( Incidence * ) ) ); 614 SLOT( processTodoListSelection( Incidence * ) ) );
615 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 615 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
616 616
617 // kdDebug() << "CalendarView::CalendarView() done" << endl; 617 // kdDebug() << "CalendarView::CalendarView() done" << endl;
618 618
619 mDateFrame = new QVBox(0,0,WType_Popup); 619 mDateFrame = new QVBox(0,0,WType_Popup);
620 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 620 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
621 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 621 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
622 mDateFrame->setLineWidth(3); 622 mDateFrame->setLineWidth(3);
623 mDateFrame->hide(); 623 mDateFrame->hide();
624 mDateFrame->setCaption( i18n( "Pick a date to display")); 624 mDateFrame->setCaption( i18n( "Pick a date to display"));
625 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 625 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
626 626
627 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 627 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
628 628
629 mEventEditor = mDialogManager->getEventEditor(); 629 mEventEditor = mDialogManager->getEventEditor();
630 mTodoEditor = mDialogManager->getTodoEditor(); 630 mTodoEditor = mDialogManager->getTodoEditor();
631 631
632 mFlagEditDescription = false; 632 mFlagEditDescription = false;
633 633
634 mSuspendTimer = new QTimer( this ); 634 mSuspendTimer = new QTimer( this );
635 mAlarmTimer = new QTimer( this ); 635 mAlarmTimer = new QTimer( this );
636 mRecheckAlarmTimer = new QTimer( this ); 636 mRecheckAlarmTimer = new QTimer( this );
637 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 637 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
638 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 638 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
639 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 639 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
640 mAlarmDialog = new AlarmDialog( this ); 640 mAlarmDialog = new AlarmDialog( this );
641 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 641 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
642 mAlarmDialog->setServerNotification( false ); 642 mAlarmDialog->setServerNotification( false );
643 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 643 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
644 644
645 645
646#ifndef DESKTOP_VERSION 646#ifndef DESKTOP_VERSION
647//US listen for arriving address resultsets 647//US listen for arriving address resultsets
648 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 648 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
649 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 649 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
650#endif 650#endif
651 mDateNavigator->setCalendar( mCalendar ); 651 mDateNavigator->setCalendar( mCalendar );
652} 652}
653 653
654 654
655CalendarView::~CalendarView() 655CalendarView::~CalendarView()
656{ 656{
657 // kdDebug() << "~CalendarView()" << endl; 657 // kdDebug() << "~CalendarView()" << endl;
658 //qDebug("CalendarView::~CalendarView() "); 658 //qDebug("CalendarView::~CalendarView() ");
659 delete mDialogManager; 659 delete mDialogManager;
660 delete mViewManager; 660 delete mViewManager;
661 delete mStorage; 661 delete mStorage;
662 delete mDateFrame ; 662 delete mDateFrame ;
663 delete mEventViewerDialog; 663 delete mEventViewerDialog;
664 //kdDebug() << "~CalendarView() done" << endl; 664 //kdDebug() << "~CalendarView() done" << endl;
665} 665}
666 666
667 667
668void CalendarView::nextConflict( bool all, bool allday ) 668void CalendarView::nextConflict( bool all, bool allday )
669{ 669{
670 if ( flag_blockConflict ) return; 670 if ( flag_blockConflict ) return;
671 flag_blockConflict = true; 671 flag_blockConflict = true;
672 QPtrList<Event> testlist = mCalendar->events(); 672 QPtrList<Event> testlist = mCalendar->events();
673 Event * test = testlist.first(); 673 Event * test = testlist.first();
674 while ( test ) { 674 while ( test ) {
675 test->setTagged( false ); 675 test->setTagged( false );
676 test = testlist.next(); 676 test = testlist.next();
677 } 677 }
678 QTime st ( 0,0,0); 678 QTime st ( 0,0,0);
679 if ( mViewManager->currentView() == mViewManager->agendaView() ) 679 if ( mViewManager->currentView() == mViewManager->agendaView() )
680 st = mViewManager->agendaView()->agenda()->getEndTime(); 680 st = mViewManager->agendaView()->agenda()->getEndTime();
681 //qDebug("time %s ", st.toString().latin1()); 681 //qDebug("time %s ", st.toString().latin1());
682 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 682 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
683 QDateTime conflict; 683 QDateTime conflict;
684 QDateTime retVal; 684 QDateTime retVal;
685 bool found = false; 685 bool found = false;
686 Event * cE = 0; 686 Event * cE = 0;
687 Event * cE2 = 0; 687 Event * cE2 = 0;
688 QPtrList<Event> testlist2 = testlist; 688 QPtrList<Event> testlist2 = testlist;
689 test = testlist.first(); 689 test = testlist.first();
690 bool skip = false; 690 bool skip = false;
691 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 691 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
692 //QTime tm; 692 //QTime tm;
693 //tm.start(); 693 //tm.start();
694 while ( test ) { 694 while ( test ) {
695 qApp->processEvents(); 695 qApp->processEvents();
696 skip = false; 696 skip = false;
697 if ( !all ) skip = ( allday != test->doesFloat() ); 697 if ( !all ) skip = ( allday != test->doesFloat() );
698 if ( !skip ) { 698 if ( !skip ) {
699 if ( found ) 699 if ( found )
700 skip = !test->matchTime( &startDT, &conflict ); 700 skip = !test->matchTime( &startDT, &conflict );
701 else 701 else
702 skip = !test->matchTime( &startDT, 0 ); 702 skip = !test->matchTime( &startDT, 0 );
703 } 703 }
704 if ( !skip ) { 704 if ( !skip ) {
705 Event * test2 = testlist2.first(); 705 Event * test2 = testlist2.first();
706 while ( test2 ) { 706 while ( test2 ) {
707 skip = test2->isTagged(); 707 skip = test2->isTagged();
708 if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); 708 if ( !skip && !all ) skip = ( allday != test2->doesFloat() );
709 if ( !skip ) { 709 if ( !skip ) {
710 if ( found ) 710 if ( found )
711 skip = !test2->matchTime( &startDT, &conflict ); 711 skip = !test2->matchTime( &startDT, &conflict );
712 else 712 else
713 skip = !test2->matchTime( &startDT, 0 ); 713 skip = !test2->matchTime( &startDT, 0 );
714 } 714 }
715 if ( !skip ) { 715 if ( !skip ) {
716 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 716 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
717 //qDebug("overlap "); 717 //qDebug("overlap ");
718 if ( ! found ) { 718 if ( ! found ) {
719 if ( retVal >= startDT ) { 719 if ( retVal >= startDT ) {
720 conflict = retVal; 720 conflict = retVal;
721 cE = test; 721 cE = test;
722 cE2 = test2; 722 cE2 = test2;
723 found = true; 723 found = true;
724 } 724 }
725 } else { 725 } else {
726 if ( retVal >= startDT && retVal < conflict ) { 726 if ( retVal >= startDT && retVal < conflict ) {
727 conflict = retVal; 727 conflict = retVal;
728 cE = test; 728 cE = test;
729 cE2 = test2; 729 cE2 = test2;
730 } 730 }
731 } 731 }
732 } 732 }
733 } 733 }
734 test2 = testlist2.next(); 734 test2 = testlist2.next();
735 } 735 }
736 } 736 }
737 test->setTagged( true ); 737 test->setTagged( true );
738 test = testlist.next(); 738 test = testlist.next();
739 } 739 }
740 //qDebug("Search time : %d", tm.elapsed()); 740 //qDebug("Search time : %d", tm.elapsed());
741 if ( found ) { 741 if ( found ) {
742 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 742 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
743 mViewManager->showDayView(); 743 mViewManager->showDayView();
744 mNavigator->slotDaySelect( conflict.date() ); 744 mNavigator->slotDaySelect( conflict.date() );
745 int hour = conflict.time().hour(); 745 int hour = conflict.time().hour();
746 mViewManager->agendaView()->setStartHour( hour ); 746 mViewManager->agendaView()->setStartHour( hour );
747 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 747 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
748 flag_blockConflict = false; 748 flag_blockConflict = false;
749 return; 749 return;
750 } 750 }
751 751
752 topLevelWidget()->setCaption( i18n("No conflict found") ); 752 topLevelWidget()->setCaption( i18n("No conflict found") );
753 //qDebug("No conflict found "); 753 //qDebug("No conflict found ");
754 flag_blockConflict = false; 754 flag_blockConflict = false;
755 return; 755 return;
756} 756}
757 757
758void CalendarView::conflictAll() 758void CalendarView::conflictAll()
759{ 759{
760 nextConflict ( true, true ); 760 nextConflict ( true, true );
761} 761}
762void CalendarView::conflictAllday() 762void CalendarView::conflictAllday()
763{ 763{
764 nextConflict ( false, true ); 764 nextConflict ( false, true );
765} 765}
766void CalendarView::conflictNotAll() 766void CalendarView::conflictNotAll()
767{ 767{
768 nextConflict ( false, false ); 768 nextConflict ( false, false );
769} 769}
770 770
771void CalendarView::setCalReadOnly( int id, bool readO ) 771void CalendarView::setCalReadOnly( int id, bool readO )
772{ 772{
773 if ( readO ) { 773 if ( readO ) {
774 emit save(); 774 emit save();
775 } 775 }
776 mCalendar->setReadOnly( id, readO ); 776 mCalendar->setReadOnly( id, readO );
777} 777}
778void CalendarView::setScrollBarStep(int val ) 778void CalendarView::setScrollBarStep(int val )
779{ 779{
780#ifdef DESKTOP_VERSION 780#ifdef DESKTOP_VERSION
781 mDateScrollBar->setLineStep ( val ); 781 mDateScrollBar->setLineStep ( val );
782#else 782#else
783 Q_UNUSED( val ); 783 Q_UNUSED( val );
784#endif 784#endif
785} 785}
786void CalendarView::scrollBarValue(int val ) 786void CalendarView::scrollBarValue(int val )
787{ 787{
788#ifdef DESKTOP_VERSION 788#ifdef DESKTOP_VERSION
789 if ( QApplication::desktop()->width() < 800 ) return; 789 if ( QApplication::desktop()->width() < 800 ) return;
790 if ( flag_blockScrollBar ) return; 790 if ( flag_blockScrollBar ) return;
791 flag_blockScrollBar = true; 791 flag_blockScrollBar = true;
792 int count = mNavigator->selectedDates().count(); 792 int count = mNavigator->selectedDates().count();
793 int day = mNavigator->selectedDates().first().dayOfYear(); 793 int day = mNavigator->selectedDates().first().dayOfYear();
794 int stepdays = val; 794 int stepdays = val;
795 if ( mDateScrollBar->lineStep () <= count ) { 795 if ( mDateScrollBar->lineStep () <= count ) {
796 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 796 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
797 //qDebug("VAL %d ",val ); 797 //qDebug("VAL %d ",val );
798 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 798 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
799 stepdays = day+stepdays; 799 stepdays = day+stepdays;
800 if ( stepdays < 0 ) stepdays = 0; 800 if ( stepdays < 0 ) stepdays = 0;
801 } 801 }
802 if ( stepdays == day ) { 802 if ( stepdays == day ) {
803 flag_blockScrollBar = false; 803 flag_blockScrollBar = false;
804 return; 804 return;
805 } 805 }
806 int year = mNavigator->selectedDates().first().year(); 806 int year = mNavigator->selectedDates().first().year();
807 QDate d ( year,1,1 ); 807 QDate d ( year,1,1 );
808 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 808 mNavigator->selectDates( d.addDays( stepdays-1) , count );
809 flag_blockScrollBar = false; 809 flag_blockScrollBar = false;
810#else 810#else
811 Q_UNUSED( val ); 811 Q_UNUSED( val );
812#endif 812#endif
813 813
814} 814}
815void CalendarView::updateView(const QDate &start, const QDate &end) 815void CalendarView::updateView(const QDate &start, const QDate &end)
816{ 816{
817#ifdef DESKTOP_VERSION 817#ifdef DESKTOP_VERSION
818 if ( ! mDateScrollBar->draggingSlider () ) { 818 if ( ! mDateScrollBar->draggingSlider () ) {
819 int dof = start.dayOfYear(); 819 int dof = start.dayOfYear();
820 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 820 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
821 if ( dof != mDateScrollBar->value() ) { 821 if ( dof != mDateScrollBar->value() ) {
822 mDateScrollBar->blockSignals( true ); 822 mDateScrollBar->blockSignals( true );
823 mDateScrollBar->setValue( start.dayOfYear()); 823 mDateScrollBar->setValue( start.dayOfYear());
824 mDateScrollBar->blockSignals( false ); 824 mDateScrollBar->blockSignals( false );
825 } 825 }
826 } 826 }
827#endif 827#endif
828 mTodoList->updateView(); 828 mTodoList->updateView();
829 mViewManager->updateView(start, end); 829 mViewManager->updateView(start, end);
830 //mDateNavigator->updateView(); 830 //mDateNavigator->updateView();
831} 831}
832 832
833 833
834 834
835void CalendarView::checkFiles() 835void CalendarView::checkFiles()
836{ 836{
837 QString message; 837 QString message;
838 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 838 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
839 KopiCalendarFile * cal = calendars.first(); 839 KopiCalendarFile * cal = calendars.first();
840 while ( cal ) { 840 while ( cal ) {
841 if ( cal->mErrorOnLoad ) { 841 if ( cal->mErrorOnLoad ) {
842 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 842 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
843 } 843 }
844 cal = calendars.next(); 844 cal = calendars.next();
845 } 845 }
846 if ( !message.isEmpty() ) { 846 if ( !message.isEmpty() ) {
847 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); 847 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0);
848 KMessageBox::error(this,message, i18n("Loading of calendar(s) failed")); 848 KMessageBox::error(this,message, i18n("Loading of calendar(s) failed"));
849 } 849 }
850 if ( flag_checkFileFirsttime ) { 850 if ( flag_checkFileFirsttime ) {
851 flag_checkFileFirsttime = false; 851 flag_checkFileFirsttime = false;
852 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 852 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
853 } 853 }
854} 854}
855void CalendarView::checkAlarms() 855void CalendarView::checkAlarms()
856{ 856{
857 KConfig *config = KOGlobals::config(); 857 KConfig *config = KOGlobals::config();
858 config->setGroup( "AppRun" ); 858 config->setGroup( "AppRun" );
859 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 859 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
860 int daysto = dt.daysTo( QDate::currentDate() ); 860 int daysto = dt.daysTo( QDate::currentDate() );
861 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 861 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
862 dt = dt.addDays( days ); 862 dt = dt.addDays( days );
863 int secto = dt.secsTo( QDateTime::currentDateTime() ); 863 int secto = dt.secsTo( QDateTime::currentDateTime() );
864 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 864 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
865 //qDebug("KO: Reading program stop %d ", secs); 865 //qDebug("KO: Reading program stop %d ", secs);
866 //secs -= ( 3600 * 24*3 ); // debug only 866 //secs -= ( 3600 * 24*3 ); // debug only
867 QDateTime latest = dt.addSecs ( secs ); 867 QDateTime latest = dt.addSecs ( secs );
868 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 868 qDebug("KO: Last termination on %s ", latest.toString().latin1());
869 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 869 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
870 QPtrList<Incidence> el = mCalendar->rawIncidences(); 870 QPtrList<Incidence> el = mCalendar->rawIncidences();
871 QPtrList<Incidence> al; 871 QPtrList<Incidence> al;
872 Incidence* inL = el.first(); 872 Incidence* inL = el.first();
873 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 873 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
874 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 874 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
875 while ( inL ) { 875 while ( inL ) {
876 bool ok = false; 876 bool ok = false;
877 int offset = 0; 877 int offset = 0;
878 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 878 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
879 if ( ok ) { 879 if ( ok ) {
880 //qDebug("OK %s",next.toString().latin1()); 880 //qDebug("OK %s",next.toString().latin1());
881 if ( next < cur ) { 881 if ( next < cur ) {
882 al.append( inL ); 882 al.append( inL );
883 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 883 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
884 } 884 }
885 } 885 }
886 inL = el.next(); 886 inL = el.next();
887 } 887 }
888 if ( al.count() ) { 888 if ( al.count() ) {
889 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 889 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
890 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 890 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
891 QVBoxLayout* lay = new QVBoxLayout( dia ); 891 QVBoxLayout* lay = new QVBoxLayout( dia );
892 lay->setSpacing( 0 ); 892 lay->setSpacing( 0 );
893 lay->setMargin( 0 ); 893 lay->setMargin( 0 );
894 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 894 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
895 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 895 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
896 lay->addWidget( matb ); 896 lay->addWidget( matb );
897 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 897 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
898 int wid = 210; 898 int wid = 210;
899 int x = QApplication::desktop()->width() - wid - 7; 899 int x = QApplication::desktop()->width() - wid - 7;
900 int y = QApplication::desktop()->height() - wid - 70; 900 int y = QApplication::desktop()->height() - wid - 70;
901 dia->setGeometry ( x,y,wid,wid); 901 dia->setGeometry ( x,y,wid,wid);
902 } else { 902 } else {
903 int si = 220; 903 int si = 220;
904 if ( QApplication::desktop()->width() > 470 ) 904 if ( QApplication::desktop()->width() > 470 )
905 si = 400; 905 si = 400;
906 dia->resize(si,si/2); 906 dia->resize(si,si/2);
907 } 907 }
908 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 908 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
909 dia->show(); 909 dia->show();
910 910
911 } 911 }
912#if 0 912#if 0
913 // for creating timetracker test data 913 // for creating timetracker test data
914 qDebug("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCc "); 914 qDebug("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCc ");
915 Todo * nt; 915 Todo * nt;
916 mCalendar->close(); 916 mCalendar->close();
917 { 917 {
918 Todo * root1 = new Todo; 918 Todo * root1 = new Todo;
919 mCalendar->addTodo( root1 ); 919 mCalendar->addTodo( root1 );
920 root1->setSummary( "Project1"); 920 root1->setSummary( "Project1");
921 root1->setPriority( 1 ); 921 root1->setPriority( 1 );
922 root1->setCategories( QString( "Cat_Pro1") ); 922 root1->setCategories( QString( "Cat_Pro1") );
923 root1->setDescription( "This is a test description of a root Project" ); 923 root1->setDescription( "This is a test description of a root Project" );
924 root1->setPercentComplete( 20 ); 924 root1->setPercentComplete( 20 );
925 updateView(); 925 updateView();
926 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); 926 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
927 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); 927 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
928 928
929 nt = new Todo; 929 nt = new Todo;
930 mCalendar->addTodo( nt ); 930 mCalendar->addTodo( nt );
931 nt->setSummary( "Planning Project1"); 931 nt->setSummary( "Planning Project1");
932 nt->setPriority( 1 ); 932 nt->setPriority( 1 );
933 nt->setDescription( "This is a test description of Planning Project1" ); 933 nt->setDescription( "This is a test description of Planning Project1" );
934 nt->setPercentComplete( 20 ); 934 nt->setPercentComplete( 20 );
935 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1") ); 935 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1") );
936 936
937 937
938 Todo * sub1 = nt; 938 Todo * sub1 = nt;
939 sub1->setRelatedTo( root1 ); 939 sub1->setRelatedTo( root1 );
940 940
941 nt = new Todo; 941 nt = new Todo;
942 mCalendar->addTodo( nt ); 942 mCalendar->addTodo( nt );
943 nt->setSummary( "Planning Project1: Lutz"); 943 nt->setSummary( "Planning Project1: Lutz");
944 nt->setPriority( 1 ); 944 nt->setPriority( 1 );
945 nt->setDescription( "This todo counts the actual work of a person on a project" ); 945 nt->setDescription( "This todo counts the actual work of a person on a project" );
946 nt->setPercentComplete( 20 ); 946 nt->setPercentComplete( 20 );
947 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Lutz") ); 947 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Lutz") );
948 Todo * workLutz11 = nt; 948 Todo * workLutz11 = nt;
949 workLutz11->setRelatedTo( sub1 ); 949 workLutz11->setRelatedTo( sub1 );
950 950
951 nt = new Todo; 951 nt = new Todo;
952 mCalendar->addTodo( nt ); 952 mCalendar->addTodo( nt );
953 nt->setSummary( "Planning Project1: Norbert"); 953 nt->setSummary( "Planning Project1: Norbert");
954 nt->setPriority( 1 ); 954 nt->setPriority( 1 );
955 nt->setDescription( "This todo counts the actual work of a person on a project" ); 955 nt->setDescription( "This todo counts the actual work of a person on a project" );
956 nt->setPercentComplete( 20 ); 956 nt->setPercentComplete( 20 );
957 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") ); 957 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") );
958 Todo * workNorbert11 = nt; 958 Todo * workNorbert11 = nt;
959 workNorbert11->setRelatedTo( sub1 ); 959 workNorbert11->setRelatedTo( sub1 );
960 960
961 nt = new Todo; 961 nt = new Todo;
962 mCalendar->addTodo( nt ); 962 mCalendar->addTodo( nt );
963 nt->setSummary( "Work on 1"); 963 nt->setSummary( "Work on 1");
964 nt->setPriority( 1 ); 964 nt->setPriority( 1 );
965 nt->setDescription( "This is a test description of Work Project_1" ); 965 nt->setDescription( "This is a test description of Work Project_1" );
966 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") ); 966 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") );
967 nt->setPercentComplete( 20 ); 967 nt->setPercentComplete( 20 );
968 968
969 Todo * sub2 = nt; 969 Todo * sub2 = nt;
970 sub2->setRelatedTo( root1 ); 970 sub2->setRelatedTo( root1 );
971 971
972 972
973 nt = new Todo; 973 nt = new Todo;
974 mCalendar->addTodo( nt ); 974 mCalendar->addTodo( nt );
975 nt->setSummary( "Work on 1: Lutz"); 975 nt->setSummary( "Work on 1: Lutz");
976 nt->setPriority( 1 ); 976 nt->setPriority( 1 );
977 nt->setDescription( "This todo counts the actual work of a person on a project" ); 977 nt->setDescription( "This todo counts the actual work of a person on a project" );
978 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") ); 978 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") );
979 nt->setPercentComplete( 20 ); 979 nt->setPercentComplete( 20 );
980 Todo * workLutz12 = nt; 980 Todo * workLutz12 = nt;
981 workLutz12->setRelatedTo( sub2 ); 981 workLutz12->setRelatedTo( sub2 );
982 982
983 nt = new Todo; 983 nt = new Todo;
984 mCalendar->addTodo( nt ); 984 mCalendar->addTodo( nt );
985 nt->setSummary( "Work on 1: Norbert"); 985 nt->setSummary( "Work on 1: Norbert");
986 nt->setPriority( 1 ); 986 nt->setPriority( 1 );
987 nt->setDescription( "This todo counts the actual work of a person on a project" ); 987 nt->setDescription( "This todo counts the actual work of a person on a project" );
988 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") ); 988 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") );
989 nt->setPercentComplete( 20 ); 989 nt->setPercentComplete( 20 );
990 Todo * workNorbert12 = nt; 990 Todo * workNorbert12 = nt;
991 workNorbert12->setRelatedTo( sub2 ); 991 workNorbert12->setRelatedTo( sub2 );
992 992
993 int secLenRunning = 7200; 993 int secLenRunning = 7200;
994 int secLenPausing = 3600 * 3; 994 int secLenPausing = 3600 * 3;
995 int dayInterval = 1; 995 int dayInterval = 1;
996 //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval ); 996 //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval );
997 createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 ); 997 createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 );
998 createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1); 998 createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1);
999 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3); 999 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3);
1000 createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0); 1000 createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0);
1001 createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1); 1001 createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1);
1002 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3); 1002 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3);
1003 createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0); 1003 createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0);
1004 1004
1005 } 1005 }
1006 1006
1007 { 1007 {
1008 Todo * root1 = new Todo; 1008 Todo * root1 = new Todo;
1009 mCalendar->addTodo( root1 ); 1009 mCalendar->addTodo( root1 );
1010 root1->setSummary( "Project2"); 1010 root1->setSummary( "Project2");
1011 root1->setPriority( 1 ); 1011 root1->setPriority( 1 );
1012 root1->setDescription( "This is a test description of a root Project 2" ); 1012 root1->setDescription( "This is a test description of a root Project 2" );
1013 root1->setPercentComplete( 20 ); 1013 root1->setPercentComplete( 20 );
1014 root1->setCategories( QString( "Cat_Pro2") ); 1014 root1->setCategories( QString( "Cat_Pro2") );
1015 updateView(); 1015 updateView();
1016 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); 1016 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
1017 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); 1017 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
1018 int secLenRunning = 7200; 1018 int secLenRunning = 7200;
1019 int secLenPausing = 3600 * 3; 1019 int secLenPausing = 3600 * 3;
1020 int dayInterval = 1; 1020 int dayInterval = 1;
1021 1021
1022 nt = new Todo; 1022 nt = new Todo;
1023 mCalendar->addTodo( nt ); 1023 mCalendar->addTodo( nt );
1024 nt->setSummary( "Planning Project2"); 1024 nt->setSummary( "Planning Project2");
1025 nt->setPriority( 1 ); 1025 nt->setPriority( 1 );
1026 nt->setDescription( "This is a test description of Planning_Project_2" ); 1026 nt->setDescription( "This is a test description of Planning_Project_2" );
1027 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") ); 1027 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") );
1028 nt->setPercentComplete( 20 ); 1028 nt->setPercentComplete( 20 );
1029 1029
1030 1030
1031 Todo * sub1 = nt; 1031 Todo * sub1 = nt;
1032 sub1->setRelatedTo( root1 ); 1032 sub1->setRelatedTo( root1 );
1033 1033
1034 nt = new Todo; 1034 nt = new Todo;
1035 mCalendar->addTodo( nt ); 1035 mCalendar->addTodo( nt );
1036 nt->setSummary( "Planning Project2: Lutz"); 1036 nt->setSummary( "Planning Project2: Lutz");
1037 nt->setPriority( 1 ); 1037 nt->setPriority( 1 );
1038 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1038 nt->setDescription( "This todo counts the actual work of a person on a project" );
1039 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") ); 1039 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") );
1040 nt->setPercentComplete( 20 ); 1040 nt->setPercentComplete( 20 );
1041 Todo * workLutz11 = nt; 1041 Todo * workLutz11 = nt;
1042 workLutz11->setRelatedTo( sub1 ); 1042 workLutz11->setRelatedTo( sub1 );
1043 1043
1044 nt = new Todo; 1044 nt = new Todo;
1045 mCalendar->addTodo( nt ); 1045 mCalendar->addTodo( nt );
1046 nt->setSummary( "Planning Project2: Norbert"); 1046 nt->setSummary( "Planning Project2: Norbert");
1047 nt->setPriority( 1 ); 1047 nt->setPriority( 1 );
1048 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1048 nt->setDescription( "This todo counts the actual work of a person on a project" );
1049 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") ); 1049 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") );
1050 nt->setPercentComplete( 20 ); 1050 nt->setPercentComplete( 20 );
1051 Todo * workNorbert11 = nt; 1051 Todo * workNorbert11 = nt;
1052 workNorbert11->setRelatedTo( sub1 ); 1052 workNorbert11->setRelatedTo( sub1 );
1053 1053
1054 nt = new Todo; 1054 nt = new Todo;
1055 mCalendar->addTodo( nt ); 1055 mCalendar->addTodo( nt );
1056 nt->setSummary( "Work on 2"); 1056 nt->setSummary( "Work on 2");
1057 nt->setPriority( 1 ); 1057 nt->setPriority( 1 );
1058 nt->setDescription( "This is a test description of Work Project_2" ); 1058 nt->setDescription( "This is a test description of Work Project_2" );
1059 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") ); 1059 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") );
1060 nt->setPercentComplete( 20 ); 1060 nt->setPercentComplete( 20 );
1061 1061
1062 Todo * sub2 = nt; 1062 Todo * sub2 = nt;
1063 sub2->setRelatedTo( root1 ); 1063 sub2->setRelatedTo( root1 );
1064 1064
1065 1065
1066 nt = new Todo; 1066 nt = new Todo;
1067 mCalendar->addTodo( nt ); 1067 mCalendar->addTodo( nt );
1068 nt->setSummary( "Work on 2: Lutz"); 1068 nt->setSummary( "Work on 2: Lutz");
1069 nt->setPriority( 1 ); 1069 nt->setPriority( 1 );
1070 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1070 nt->setDescription( "This todo counts the actual work of a person on a project" );
1071 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") ); 1071 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") );
1072 nt->setPercentComplete( 20 ); 1072 nt->setPercentComplete( 20 );
1073 Todo * workLutz12 = nt; 1073 Todo * workLutz12 = nt;
1074 workLutz12->setRelatedTo( sub2 ); 1074 workLutz12->setRelatedTo( sub2 );
1075 1075
1076 nt = new Todo; 1076 nt = new Todo;
1077 mCalendar->addTodo( nt ); 1077 mCalendar->addTodo( nt );
1078 nt->setSummary( "Work on 2: Norbert"); 1078 nt->setSummary( "Work on 2: Norbert");
1079 nt->setPriority( 1 ); 1079 nt->setPriority( 1 );
1080 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1080 nt->setDescription( "This todo counts the actual work of a person on a project" );
1081 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") ); 1081 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") );
1082 nt->setPercentComplete( 20 ); 1082 nt->setPercentComplete( 20 );
1083 Todo * workNorbert12 = nt; 1083 Todo * workNorbert12 = nt;
1084 workNorbert12->setRelatedTo( sub2 ); 1084 workNorbert12->setRelatedTo( sub2 );
1085 createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 ); 1085 createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 );
1086 createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2); 1086 createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2);
1087 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7); 1087 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7);
1088 createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0); 1088 createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0);
1089 createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1); 1089 createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1);
1090 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0); 1090 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0);
1091 createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0); 1091 createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0);
1092 } 1092 }
1093 updateView(); 1093 updateView();
1094#endif 1094#endif
1095 1095
1096} 1096}
1097void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval ) 1097void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval )
1098{ 1098{
1099 static int ccc = 0; 1099 static int ccc = 0;
1100 ++ccc; 1100 ++ccc;
1101 QDateTime t_start = start; 1101 QDateTime t_start = start;
1102 runT->setPriority( 5 ); 1102 runT->setPriority( 5 );
1103 runT->setPercentComplete( 0 ); 1103 runT->setPercentComplete( 0 );
1104 int count = 0; 1104 int count = 0;
1105 int prio = 5; 1105 int prio = 5;
1106 int complete = 0; 1106 int complete = 0;
1107 while ( t_start < end ) { 1107 while ( t_start < end ) {
1108 ++count; 1108 ++count;
1109 if ( count > ccc ) { 1109 if ( count > ccc ) {
1110 count = 0; 1110 count = 0;
1111 --prio; 1111 --prio;
1112 if ( prio == 0 ) prio = 5; 1112 if ( prio == 0 ) prio = 5;
1113 complete += 20; 1113 complete += 20;
1114 if ( complete > 100 ) complete = 0; 1114 if ( complete > 100 ) complete = 0;
1115 runT->setPriority( prio ); 1115 runT->setPriority( prio );
1116 runT->setPercentComplete( complete ); 1116 runT->setPercentComplete( complete );
1117 } 1117 }
1118 runT->setRunning( true ); 1118 runT->setRunning( true );
1119 runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) ); 1119 runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) );
1120 if ( dayInterval ) 1120 if ( dayInterval )
1121 t_start = t_start.addDays( dayInterval ); 1121 t_start = t_start.addDays( dayInterval );
1122 else { 1122 else {
1123 t_start = t_start.addSecs( secLenRunning + secLenPausing ); 1123 t_start = t_start.addSecs( secLenRunning + secLenPausing );
1124 } 1124 }
1125 } 1125 }
1126} 1126}
1127 1127
1128void CalendarView::showDay( QDate d ) 1128void CalendarView::showDay( QDate d )
1129{ 1129{
1130 dateNavigator()->blockSignals( true ); 1130 dateNavigator()->blockSignals( true );
1131 dateNavigator()->selectDate( d ); 1131 dateNavigator()->selectDate( d );
1132 dateNavigator()->blockSignals( false ); 1132 dateNavigator()->blockSignals( false );
1133 mViewManager->showDayView(); 1133 mViewManager->showDayView();
1134 //dateNavigator()->selectDate( d ); 1134 //dateNavigator()->selectDate( d );
1135} 1135}
1136void CalendarView::timerAlarm() 1136void CalendarView::timerAlarm()
1137{ 1137{
1138 //qDebug("CalendarView::timerAlarm() "); 1138 //qDebug("CalendarView::timerAlarm() ");
1139 computeAlarm(mAlarmNotification ); 1139 computeAlarm(mAlarmNotification );
1140} 1140}
1141 1141
1142void CalendarView::suspendAlarm() 1142void CalendarView::suspendAlarm()
1143{ 1143{
1144 //qDebug(" CalendarView::suspendAlarm() "); 1144 //qDebug(" CalendarView::suspendAlarm() ");
1145 computeAlarm(mSuspendAlarmNotification ); 1145 computeAlarm(mSuspendAlarmNotification );
1146 1146
1147} 1147}
1148 1148
1149void CalendarView::startAlarm( QString mess , QString filename) 1149void CalendarView::startAlarm( QString mess , QString filename)
1150{ 1150{
1151 1151
1152 topLevelWidget()->showNormal(); 1152 topLevelWidget()->showNormal();
1153 topLevelWidget()->setActiveWindow(); 1153 topLevelWidget()->setActiveWindow();
1154 topLevelWidget()->raise(); 1154 topLevelWidget()->raise();
1155 1155
1156 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 1156 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
1157 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 1157 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
1158 1158
1159} 1159}
1160 1160
1161void CalendarView::checkNextTimerAlarm() 1161void CalendarView::checkNextTimerAlarm()
1162{ 1162{
1163 mCalendar->checkAlarmForIncidence( 0, true ); 1163 mCalendar->checkAlarmForIncidence( 0, true );
1164} 1164}
1165 1165
1166void CalendarView::computeAlarm( QString msg ) 1166void CalendarView::computeAlarm( QString msg )
1167{ 1167{
1168 1168
1169 QString mess = msg; 1169 QString mess = msg;
1170 QString mAlarmMessage = mess.mid( 9 ); 1170 QString mAlarmMessage = mess.mid( 9 );
1171 QString filename = MainWindow::resourcePath(); 1171 QString filename = MainWindow::resourcePath();
1172 filename += "koalarm.wav"; 1172 filename += "koalarm.wav";
1173 QString tempfilename; 1173 QString tempfilename;
1174 if ( mess.left( 13 ) == "suspend_alarm") { 1174 if ( mess.left( 13 ) == "suspend_alarm") {
1175 bool error = false; 1175 bool error = false;
1176 int len = mess.mid( 13 ).find("+++"); 1176 int len = mess.mid( 13 ).find("+++");
1177 if ( len < 2 ) 1177 if ( len < 2 )
1178 error = true; 1178 error = true;
1179 else { 1179 else {
1180 tempfilename = mess.mid( 13, len ); 1180 tempfilename = mess.mid( 13, len );
1181 if ( !QFile::exists( tempfilename ) ) 1181 if ( !QFile::exists( tempfilename ) )
1182 error = true; 1182 error = true;
1183 } 1183 }
1184 if ( ! error ) { 1184 if ( ! error ) {
1185 filename = tempfilename; 1185 filename = tempfilename;
1186 } 1186 }
1187 mAlarmMessage = mess.mid( 13+len+3 ); 1187 mAlarmMessage = mess.mid( 13+len+3 );
1188 //qDebug("suspend file %s ",tempfilename.latin1() ); 1188 //qDebug("suspend file %s ",tempfilename.latin1() );
1189 startAlarm( mAlarmMessage, filename); 1189 startAlarm( mAlarmMessage, filename);
1190 return; 1190 return;
1191 } 1191 }
1192 if ( mess.left( 11 ) == "timer_alarm") { 1192 if ( mess.left( 11 ) == "timer_alarm") {
1193 //mTimerTime = 0; 1193 //mTimerTime = 0;
1194 startAlarm( mess.mid( 11 ), filename ); 1194 startAlarm( mess.mid( 11 ), filename );
1195 return; 1195 return;
1196 } 1196 }
1197 if ( mess.left( 10 ) == "proc_alarm") { 1197 if ( mess.left( 10 ) == "proc_alarm") {
1198 bool error = false; 1198 bool error = false;
1199 int len = mess.mid( 10 ).find("+++"); 1199 int len = mess.mid( 10 ).find("+++");
1200 if ( len < 2 ) 1200 if ( len < 2 )
1201 error = true; 1201 error = true;
1202 else { 1202 else {
1203 tempfilename = mess.mid( 10, len ); 1203 tempfilename = mess.mid( 10, len );
1204 if ( !QFile::exists( tempfilename ) ) 1204 if ( !QFile::exists( tempfilename ) )
1205 error = true; 1205 error = true;
1206 } 1206 }
1207 if ( error ) { 1207 if ( error ) {
1208 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 1208 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
1209 mAlarmMessage += mess.mid( 10+len+3+9 ); 1209 mAlarmMessage += mess.mid( 10+len+3+9 );
1210 } else { 1210 } else {
1211 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 1211 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
1212 //qDebug("-----system command %s ",tempfilename.latin1() ); 1212 //qDebug("-----system command %s ",tempfilename.latin1() );
1213#ifndef _WIN32_ 1213#ifndef _WIN32_
1214 if ( vfork () == 0 ) { 1214 if ( vfork () == 0 ) {
1215 execl ( tempfilename.latin1(), 0 ); 1215 execl ( tempfilename.latin1(), 0 );
1216 return; 1216 return;
1217 } 1217 }
1218#else 1218#else
1219 QProcess* p = new QProcess(); 1219 QProcess* p = new QProcess();
1220 p->addArgument( tempfilename.latin1() ); 1220 p->addArgument( tempfilename.latin1() );
1221 p->start(); 1221 p->start();
1222 return; 1222 return;
1223#endif 1223#endif
1224 1224
1225 return; 1225 return;
1226 } 1226 }
1227 1227
1228 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1228 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1229 } 1229 }
1230 if ( mess.left( 11 ) == "audio_alarm") { 1230 if ( mess.left( 11 ) == "audio_alarm") {
1231 bool error = false; 1231 bool error = false;
1232 int len = mess.mid( 11 ).find("+++"); 1232 int len = mess.mid( 11 ).find("+++");
1233 if ( len < 2 ) 1233 if ( len < 2 )
1234 error = true; 1234 error = true;
1235 else { 1235 else {
1236 tempfilename = mess.mid( 11, len ); 1236 tempfilename = mess.mid( 11, len );
1237 if ( !QFile::exists( tempfilename ) ) 1237 if ( !QFile::exists( tempfilename ) )
1238 error = true; 1238 error = true;
1239 } 1239 }
1240 if ( ! error ) { 1240 if ( ! error ) {
1241 filename = tempfilename; 1241 filename = tempfilename;
1242 } 1242 }
1243 mAlarmMessage = mess.mid( 11+len+3+9 ); 1243 mAlarmMessage = mess.mid( 11+len+3+9 );
1244 //qDebug("audio file command %s ",tempfilename.latin1() ); 1244 //qDebug("audio file command %s ",tempfilename.latin1() );
1245 } 1245 }
1246 if ( mess.left( 9 ) == "cal_alarm") { 1246 if ( mess.left( 9 ) == "cal_alarm") {
1247 mAlarmMessage = mess.mid( 9 ) ; 1247 mAlarmMessage = mess.mid( 9 ) ;
1248 } 1248 }
1249 1249
1250 startAlarm( mAlarmMessage, filename ); 1250 startAlarm( mAlarmMessage, filename );
1251 1251
1252 1252
1253} 1253}
1254 1254
1255void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1255void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1256{ 1256{
1257 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1257 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1258 1258
1259 mSuspendAlarmNotification = noti; 1259 mSuspendAlarmNotification = noti;
1260 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1260 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1261 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1261 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1262 mSuspendTimer->start( ms , true ); 1262 mSuspendTimer->start( ms , true );
1263#ifdef DESKTOP_VERSION 1263#ifdef DESKTOP_VERSION
1264 if ( QApplication::desktop()->width() < 1024 ) { 1264 if ( QApplication::desktop()->width() < 1024 ) {
1265 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; 1265 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1266 //qDebug("nextsuspendalarm = \n%s ",mess.latin1() ); 1266 //qDebug("nextsuspendalarm = \n%s ",mess.latin1() );
1267 QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm"; 1267 QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm";
1268 QFile file( fn ); 1268 QFile file( fn );
1269 if (!file.open( IO_WriteOnly ) ) { 1269 if (!file.open( IO_WriteOnly ) ) {
1270 qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); 1270 qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1271 } else { 1271 } else {
1272 QTextStream ts( &file ); 1272 QTextStream ts( &file );
1273 ts << mess; 1273 ts << mess;
1274 file.close(); 1274 file.close();
1275 } 1275 }
1276 } 1276 }
1277#endif 1277#endif
1278 1278
1279} 1279}
1280 1280
1281void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1281void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1282{ 1282{
1283 mNextAlarmDateTime = qdt; 1283 mNextAlarmDateTime = qdt;
1284 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1284 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1285 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1285 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1286#ifndef DESKTOP_VERSION 1286#ifndef DESKTOP_VERSION
1287 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1287 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1288#endif 1288#endif
1289 return; 1289 return;
1290 } 1290 }
1291#ifdef DESKTOP_VERSION 1291#ifdef DESKTOP_VERSION
1292 if ( QApplication::desktop()->width() < 1024 ) { 1292 if ( QApplication::desktop()->width() < 1024 ) {
1293 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; 1293 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1294 //qDebug("nextalarm = \n%s ",mess.latin1() ); 1294 //qDebug("nextalarm = \n%s ",mess.latin1() );
1295 QString fn = QDir::homeDirPath() + "/.kopi_next_alarm"; 1295 QString fn = QDir::homeDirPath() + "/.kopi_next_alarm";
1296 QFile file( fn ); 1296 QFile file( fn );
1297 if (!file.open( IO_WriteOnly ) ) { 1297 if (!file.open( IO_WriteOnly ) ) {
1298 qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); 1298 qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1299 } else { 1299 } else {
1300 QTextStream ts( &file ); 1300 QTextStream ts( &file );
1301 ts << mess; 1301 ts << mess;
1302 file.close(); 1302 file.close();
1303 } 1303 }
1304 } 1304 }
1305#endif 1305#endif
1306 int maxSec; 1306 int maxSec;
1307 //maxSec = 5; //testing only 1307 //maxSec = 5; //testing only
1308 maxSec = 86400+3600; // one day+1hour 1308 maxSec = 86400+3600; // one day+1hour
1309 mAlarmNotification = noti; 1309 mAlarmNotification = noti;
1310 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1310 int sec = QDateTime::currentDateTime().secsTo( qdt );
1311 if ( sec > maxSec ) { 1311 if ( sec > maxSec ) {
1312 mRecheckAlarmTimer->start( maxSec * 1000 ); 1312 mRecheckAlarmTimer->start( maxSec * 1000 );
1313 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1313 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1314 return; 1314 return;
1315 } else { 1315 } else {
1316 mRecheckAlarmTimer->stop(); 1316 mRecheckAlarmTimer->stop();
1317 } 1317 }
1318 //qDebug("Alarm timer started with secs: %d ", sec); 1318 //qDebug("Alarm timer started with secs: %d ", sec);
1319 mAlarmTimer->start( sec * 1000 , true ); 1319 mAlarmTimer->start( sec * 1000 , true );
1320 1320
1321} 1321}
1322// called by mRecheckAlarmTimer to get next alarm 1322// called by mRecheckAlarmTimer to get next alarm
1323// we need this, because a QTimer has only a max range of 25 days 1323// we need this, because a QTimer has only a max range of 25 days
1324void CalendarView::recheckTimerAlarm() 1324void CalendarView::recheckTimerAlarm()
1325{ 1325{
1326 mAlarmTimer->stop(); 1326 mAlarmTimer->stop();
1327 mRecheckAlarmTimer->stop(); 1327 mRecheckAlarmTimer->stop();
1328 mCalendar->checkAlarmForIncidence( 0, true ); 1328 mCalendar->checkAlarmForIncidence( 0, true );
1329} 1329}
1330#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1331void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1331void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1332#else 1332#else
1333void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1333void CalendarView::removeAlarm(const QDateTime &, const QString & )
1334#endif 1334#endif
1335{ 1335{
1336 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1336 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1337 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1337 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1338#ifndef DESKTOP_VERSION 1338#ifndef DESKTOP_VERSION
1339 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1339 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1340#endif 1340#endif
1341 return; 1341 return;
1342 } 1342 }
1343 mAlarmTimer->stop(); 1343 mAlarmTimer->stop();
1344} 1344}
1345void CalendarView::selectWeekNum ( int num ) 1345void CalendarView::selectWeekNum ( int num )
1346{ 1346{
1347 dateNavigator()->blockSignals( true ); 1347 dateNavigator()->blockSignals( true );
1348 dateNavigator()->selectWeek( num ); 1348 dateNavigator()->selectWeek( num );
1349 dateNavigator()->blockSignals( false ); 1349 dateNavigator()->blockSignals( false );
1350 mViewManager->showWeekView(); 1350 mViewManager->showWeekView();
1351} 1351}
1352KOViewManager *CalendarView::viewManager() 1352KOViewManager *CalendarView::viewManager()
1353{ 1353{
1354 return mViewManager; 1354 return mViewManager;
1355} 1355}
1356 1356
1357KODialogManager *CalendarView::dialogManager() 1357KODialogManager *CalendarView::dialogManager()
1358{ 1358{
1359 return mDialogManager; 1359 return mDialogManager;
1360} 1360}
1361 1361
1362QDate CalendarView::startDate() 1362QDate CalendarView::startDate()
1363{ 1363{
1364 DateList dates = mNavigator->selectedDates(); 1364 DateList dates = mNavigator->selectedDates();
1365 1365
1366 return dates.first(); 1366 return dates.first();
1367} 1367}
1368 1368
1369QDate CalendarView::endDate() 1369QDate CalendarView::endDate()
1370{ 1370{
1371 DateList dates = mNavigator->selectedDates(); 1371 DateList dates = mNavigator->selectedDates();
1372 1372
1373 return dates.last(); 1373 return dates.last();
1374} 1374}
1375 1375
1376 1376
1377void CalendarView::createPrinter() 1377void CalendarView::createPrinter()
1378{ 1378{
1379#ifndef KORG_NOPRINTER 1379#ifndef KORG_NOPRINTER
1380 if (!mCalPrinter) { 1380 if (!mCalPrinter) {
1381 mCalPrinter = new CalPrinter(this, mCalendar); 1381 mCalPrinter = new CalPrinter(this, mCalendar);
1382 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1382 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1383 } 1383 }
1384#endif 1384#endif
1385} 1385}
1386 1386
1387 1387
1388//KOPrefs::instance()->mWriteBackFile 1388//KOPrefs::instance()->mWriteBackFile
1389//KOPrefs::instance()->mWriteBackExistingOnly 1389//KOPrefs::instance()->mWriteBackExistingOnly
1390 1390
1391// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1391// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1392// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1392// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1393// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1393// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1394// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1394// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1395// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1395// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1396// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1396// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1397 1397
1398int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1398int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1399{ 1399{
1400 1400
1401 // 0 equal 1401 // 0 equal
1402 // 1 take local 1402 // 1 take local
1403 // 2 take remote 1403 // 2 take remote
1404 // 3 cancel 1404 // 3 cancel
1405 QDateTime lastSync = mLastCalendarSync; 1405 QDateTime lastSync = mLastCalendarSync;
1406 QDateTime localMod = local->lastModified(); 1406 QDateTime localMod = local->lastModified();
1407 QDateTime remoteMod = remote->lastModified(); 1407 QDateTime remoteMod = remote->lastModified();
1408 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1408 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1409 bool remCh, locCh; 1409 bool remCh, locCh;
1410 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1410 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1411 //if ( remCh ) 1411 //if ( remCh )
1412 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1412 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1413 locCh = ( localMod > mLastCalendarSync ); 1413 locCh = ( localMod > mLastCalendarSync );
1414 if ( !remCh && ! locCh ) { 1414 if ( !remCh && ! locCh ) {
1415 //qDebug("both not changed "); 1415 //qDebug("both not changed ");
1416 lastSync = localMod.addDays(1); 1416 lastSync = localMod.addDays(1);
1417 if ( mode <= SYNC_PREF_ASK ) 1417 if ( mode <= SYNC_PREF_ASK )
1418 return 0; 1418 return 0;
1419 } else { 1419 } else {
1420 if ( locCh ) { 1420 if ( locCh ) {
1421 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1421 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1422 lastSync = localMod.addDays( -1 ); 1422 lastSync = localMod.addDays( -1 );
1423 if ( !remCh ) 1423 if ( !remCh )
1424 remoteMod = ( lastSync.addDays( -1 ) ); 1424 remoteMod = ( lastSync.addDays( -1 ) );
1425 } else { 1425 } else {
1426 //qDebug(" not loc changed "); 1426 //qDebug(" not loc changed ");
1427 lastSync = localMod.addDays( 1 ); 1427 lastSync = localMod.addDays( 1 );
1428 if ( remCh ) 1428 if ( remCh )
1429 remoteMod =( lastSync.addDays( 1 ) ); 1429 remoteMod =( lastSync.addDays( 1 ) );
1430 1430
1431 } 1431 }
1432 } 1432 }
1433 full = true; 1433 full = true;
1434 if ( mode < SYNC_PREF_ASK ) 1434 if ( mode < SYNC_PREF_ASK )
1435 mode = SYNC_PREF_ASK; 1435 mode = SYNC_PREF_ASK;
1436 } else { 1436 } else {
1437 if ( localMod == remoteMod ) 1437 if ( localMod == remoteMod )
1438 // if ( local->revision() == remote->revision() ) 1438 // if ( local->revision() == remote->revision() )
1439 return 0; 1439 return 0;
1440 1440
1441 } 1441 }
1442 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1442 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1443 1443
1444 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1444 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1445 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1445 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1446 //full = true; //debug only 1446 //full = true; //debug only
1447 if ( full ) { 1447 if ( full ) {
1448 bool equ = false; 1448 bool equ = false;
1449 if ( local->typeID() == eventID ) { 1449 if ( local->typeID() == eventID ) {
1450 equ = (*((Event*) local) == *((Event*) remote)); 1450 equ = (*((Event*) local) == *((Event*) remote));
1451 } 1451 }
1452 else if ( local->typeID() == todoID ) 1452 else if ( local->typeID() == todoID )
1453 equ = (*((Todo*) local) == (*(Todo*) remote)); 1453 equ = (*((Todo*) local) == (*(Todo*) remote));
1454 else if ( local->typeID() == journalID ) 1454 else if ( local->typeID() == journalID )
1455 equ = (*((Journal*) local) == *((Journal*) remote)); 1455 equ = (*((Journal*) local) == *((Journal*) remote));
1456 if ( equ ) { 1456 if ( equ ) {
1457 //qDebug("equal "); 1457 //qDebug("equal ");
1458 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1458 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1459 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1459 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1460 } 1460 }
1461 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1461 if ( mode < SYNC_PREF_FORCE_LOCAL )
1462 return 0; 1462 return 0;
1463 1463
1464 }//else //debug only 1464 }//else //debug only
1465 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1465 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1466 } 1466 }
1467 int result; 1467 int result;
1468 bool localIsNew; 1468 bool localIsNew;
1469 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1469 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1470 1470
1471 1471
1472 // ************************************************ 1472 // ************************************************
1473 // ************************************************ 1473 // ************************************************
1474 // ************************************************ 1474 // ************************************************
1475 // We may have that lastSync > remoteMod AND lastSync > localMod 1475 // We may have that lastSync > remoteMod AND lastSync > localMod
1476 // BUT remoteMod != localMod 1476 // BUT remoteMod != localMod
1477 1477
1478 1478
1479 if ( full && mode < SYNC_PREF_NEWEST ) 1479 if ( full && mode < SYNC_PREF_NEWEST )
1480 mode = SYNC_PREF_ASK; 1480 mode = SYNC_PREF_ASK;
1481 1481
1482 switch( mode ) { 1482 switch( mode ) {
1483 case SYNC_PREF_LOCAL: 1483 case SYNC_PREF_LOCAL:
1484 if ( lastSync > remoteMod ) 1484 if ( lastSync > remoteMod )
1485 return 1; 1485 return 1;
1486 if ( lastSync > localMod ) 1486 if ( lastSync > localMod )
1487 return 2; 1487 return 2;
1488 return 1; 1488 return 1;
1489 break; 1489 break;
1490 case SYNC_PREF_REMOTE: 1490 case SYNC_PREF_REMOTE:
1491 if ( lastSync > localMod ) 1491 if ( lastSync > localMod )
1492 return 2; 1492 return 2;
1493 if ( lastSync > remoteMod ) 1493 if ( lastSync > remoteMod )
1494 return 1; 1494 return 1;
1495 return 2; 1495 return 2;
1496 break; 1496 break;
1497 case SYNC_PREF_NEWEST: 1497 case SYNC_PREF_NEWEST:
1498 if ( localMod >= remoteMod ) 1498 if ( localMod >= remoteMod )
1499 return 1; 1499 return 1;
1500 else 1500 else
1501 return 2; 1501 return 2;
1502 break; 1502 break;
1503 case SYNC_PREF_ASK: 1503 case SYNC_PREF_ASK:
1504 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1504 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1505 if ( lastSync > remoteMod && lastSync > localMod) 1505 if ( lastSync > remoteMod && lastSync > localMod)
1506 return 0; 1506 return 0;
1507 if ( lastSync > remoteMod ) 1507 if ( lastSync > remoteMod )
1508 return 1; 1508 return 1;
1509 if ( lastSync > localMod ) 1509 if ( lastSync > localMod )
1510 return 2; 1510 return 2;
1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1511 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1512 localIsNew = localMod >= remoteMod; 1512 localIsNew = localMod >= remoteMod;
1513 if ( localIsNew ) 1513 if ( localIsNew )
1514 getEventViewerDialog()->setColorMode( 1 ); 1514 getEventViewerDialog()->setColorMode( 1 );
1515 else 1515 else
1516 getEventViewerDialog()->setColorMode( 2 ); 1516 getEventViewerDialog()->setColorMode( 2 );
1517 getEventViewerDialog()->setIncidence(local); 1517 getEventViewerDialog()->setIncidence(local);
1518 if ( localIsNew ) 1518 if ( localIsNew )
1519 getEventViewerDialog()->setColorMode( 2 ); 1519 getEventViewerDialog()->setColorMode( 2 );
1520 else 1520 else
1521 getEventViewerDialog()->setColorMode( 1 ); 1521 getEventViewerDialog()->setColorMode( 1 );
1522 getEventViewerDialog()->addIncidence(remote); 1522 getEventViewerDialog()->addIncidence(remote);
1523 getEventViewerDialog()->setColorMode( 0 ); 1523 getEventViewerDialog()->setColorMode( 0 );
1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1524 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1525 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1526 getEventViewerDialog()->showMe(); 1526 getEventViewerDialog()->showMe();
1527 result = getEventViewerDialog()->executeS( localIsNew ); 1527 result = getEventViewerDialog()->executeS( localIsNew );
1528 return result; 1528 return result;
1529 1529
1530 break; 1530 break;
1531 case SYNC_PREF_FORCE_LOCAL: 1531 case SYNC_PREF_FORCE_LOCAL:
1532 return 1; 1532 return 1;
1533 break; 1533 break;
1534 case SYNC_PREF_FORCE_REMOTE: 1534 case SYNC_PREF_FORCE_REMOTE:
1535 return 2; 1535 return 2;
1536 break; 1536 break;
1537 1537
1538 default: 1538 default:
1539 // SYNC_PREF_TAKE_BOTH not implemented 1539 // SYNC_PREF_TAKE_BOTH not implemented
1540 break; 1540 break;
1541 } 1541 }
1542 return 0; 1542 return 0;
1543} 1543}
1544Event* CalendarView::getLastSyncEvent() 1544Event* CalendarView::getLastSyncEvent()
1545{ 1545{
1546 Event* lse; 1546 Event* lse;
1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1547 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1548 mCalendar->setSyncEventsEnabled(); 1548 mCalendar->setSyncEventsEnabled();
1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1549 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1550 if (!lse) { 1550 if (!lse) {
1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); 1551 qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() );
1552 lse = new Event(); 1552 lse = new Event();
1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1553 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1554 QString sum = ""; 1554 QString sum = "";
1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1555 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1556 sum = "E: "; 1556 sum = "E: ";
1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1557 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1558 lse->setDtStart( mLastCalendarSync ); 1558 lse->setDtStart( mLastCalendarSync );
1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1559 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1560 lse->setCategories( i18n("SyncEvent") ); 1560 lse->setCategories( i18n("SyncEvent") );
1561 lse->setReadOnly( true ); 1561 lse->setReadOnly( true );
1562 lse->setCalID( 1 ); 1562 lse->setCalID( 1 );
1563 mCalendar->addEvent( lse ); 1563 mCalendar->addEvent( lse );
1564 } else 1564 } else
1565 qDebug("KO: Last Syncevent on local found"); 1565 qDebug("KO: Last Syncevent on local found");
1566 1566
1567 return lse; 1567 return lse;
1568 1568
1569} 1569}
1570 1570
1571// we check, if the to delete event has a id for a profile 1571// we check, if the to delete event has a id for a profile
1572// if yes, we set this id in the profile to delete 1572// if yes, we set this id in the profile to delete
1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1573void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1574{ 1574{
1575 if ( lastSync.count() == 0 ) { 1575 if ( lastSync.count() == 0 ) {
1576 //qDebug(" lastSync.count() == 0"); 1576 //qDebug(" lastSync.count() == 0");
1577 return; 1577 return;
1578 } 1578 }
1579 if ( toDelete->typeID() == journalID ) 1579 if ( toDelete->typeID() == journalID )
1580 return; 1580 return;
1581 1581
1582 Event* eve = lastSync.first(); 1582 Event* eve = lastSync.first();
1583 1583
1584 while ( eve ) { 1584 while ( eve ) {
1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1585 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1586 if ( !id.isEmpty() ) { 1586 if ( !id.isEmpty() ) {
1587 QString des = eve->description(); 1587 QString des = eve->description();
1588 QString pref = "e"; 1588 QString pref = "e";
1589 if ( toDelete->typeID() == todoID ) 1589 if ( toDelete->typeID() == todoID )
1590 pref = "t"; 1590 pref = "t";
1591 des += pref+ id + ","; 1591 des += pref+ id + ",";
1592 eve->setReadOnly( false ); 1592 eve->setReadOnly( false );
1593 eve->setDescription( des ); 1593 eve->setDescription( des );
1594 //qDebug("setdes %s ", des.latin1()); 1594 //qDebug("setdes %s ", des.latin1());
1595 eve->setReadOnly( true ); 1595 eve->setReadOnly( true );
1596 } 1596 }
1597 eve = lastSync.next(); 1597 eve = lastSync.next();
1598 } 1598 }
1599 1599
1600} 1600}
1601void CalendarView::checkExternalId( Incidence * inc ) 1601void CalendarView::checkExternalId( Incidence * inc )
1602{ 1602{
1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1603 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1604 checkExternSyncEvent( lastSync, inc ); 1604 checkExternSyncEvent( lastSync, inc );
1605 1605
1606} 1606}
1607// SSSSSSSSSSSSSSSSSSSSSS 1607// SSSSSSSSSSSSSSSSSSSSSS
1608bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1608bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1609{ 1609{
1610 1610
1611 bool syncOK = true; 1611 bool syncOK = true;
1612 int addedEvent = 0; 1612 int addedEvent = 0;
1613 int addedEventR = 0; 1613 int addedEventR = 0;
1614 int deletedEventR = 0; 1614 int deletedEventR = 0;
1615 int deletedEventL = 0; 1615 int deletedEventL = 0;
1616 int changedLocal = 0; 1616 int changedLocal = 0;
1617 int changedRemote = 0; 1617 int changedRemote = 0;
1618 int filteredIN = 0; 1618 int filteredIN = 0;
1619 int filteredOUT = 0; 1619 int filteredOUT = 0;
1620 //QPtrList<Event> el = local->rawEvents(); 1620 //QPtrList<Event> el = local->rawEvents();
1621 Event* eventR; 1621 Event* eventR;
1622 QString uid; 1622 QString uid;
1623 int take; 1623 int take;
1624 Event* eventRSync; 1624 Event* eventRSync;
1625 Event* eventLSync; 1625 Event* eventLSync;
1626 clearAllViews(); 1626 clearAllViews();
1627 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1627 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1628 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1628 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1629 bool fullDateRange = false; 1629 bool fullDateRange = false;
1630 local->resetTempSyncStat(); 1630 local->resetTempSyncStat();
1631 mLastCalendarSync = QDateTime::currentDateTime(); 1631 mLastCalendarSync = QDateTime::currentDateTime();
1632 if ( mSyncManager->syncWithDesktop() ) { 1632 if ( mSyncManager->syncWithDesktop() ) {
1633 remote->resetPilotStat(1); 1633 remote->resetPilotStat(1);
1634 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1634 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1635 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1635 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1636 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1636 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1637 } else { 1637 } else {
1638 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1638 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1639 } 1639 }
1640 } 1640 }
1641 QDateTime modifiedCalendar = mLastCalendarSync; 1641 QDateTime modifiedCalendar = mLastCalendarSync;
1642 eventLSync = getLastSyncEvent(); 1642 eventLSync = getLastSyncEvent();
1643 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1643 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1644 if ( eventR ) { 1644 if ( eventR ) {
1645 qDebug("KO: Last-syncEvent on remote found "); 1645 qDebug("KO: Last-syncEvent on remote found ");
1646 eventRSync = (Event*) eventR->clone(); 1646 eventRSync = (Event*) eventR->clone();
1647 remote->deleteEvent(eventR ); 1647 remote->deleteEvent(eventR );
1648 1648
1649 } else { 1649 } else {
1650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1651 eventRSync = (Event*)eventLSync->clone(); 1651 eventRSync = (Event*)eventLSync->clone();
1652 } else { 1652 } else {
1653 fullDateRange = true; 1653 fullDateRange = true;
1654 eventRSync = new Event(); 1654 eventRSync = new Event();
1655 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1655 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1656 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1656 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1657 eventRSync->setDtStart( mLastCalendarSync ); 1657 eventRSync->setDtStart( mLastCalendarSync );
1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1659 eventRSync->setCategories( i18n("SyncEvent") ); 1659 eventRSync->setCategories( i18n("SyncEvent") );
1660 } 1660 }
1661 } 1661 }
1662 if ( eventLSync->dtStart() == mLastCalendarSync ) 1662 if ( eventLSync->dtStart() == mLastCalendarSync )
1663 fullDateRange = true; 1663 fullDateRange = true;
1664 1664
1665 if ( ! fullDateRange ) { 1665 if ( ! fullDateRange ) {
1666 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1666 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1667 1667
1668 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1668 qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1669 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1669 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1670 fullDateRange = true; 1670 fullDateRange = true;
1671 } 1671 }
1672 } 1672 }
1673 if ( mSyncManager->syncWithDesktop() ) { 1673 if ( mSyncManager->syncWithDesktop() ) {
1674 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1674 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1675 } 1675 }
1676 if ( fullDateRange ) 1676 if ( fullDateRange )
1677 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1677 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1678 else 1678 else
1679 mLastCalendarSync = eventLSync->dtStart(); 1679 mLastCalendarSync = eventLSync->dtStart();
1680 // for resyncing if own file has changed 1680 // for resyncing if own file has changed
1681 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1681 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1682 mLastCalendarSync = loadedFileVersion; 1682 mLastCalendarSync = loadedFileVersion;
1683 //qDebug("setting mLastCalendarSync "); 1683 //qDebug("setting mLastCalendarSync ");
1684 } 1684 }
1685 //qDebug("*************************** "); 1685 //qDebug("*************************** ");
1686 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1686 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1687 QPtrList<Incidence> er = remote->rawIncidences(); 1687 QPtrList<Incidence> er = remote->rawIncidences();
1688 Incidence* inR = er.first(); 1688 Incidence* inR = er.first();
1689 Incidence* inL; 1689 Incidence* inL;
1690 QProgressBar bar( er.count(),0 ); 1690 QProgressBar bar( er.count(),0 );
1691 bar.setCaption (i18n("Syncing - close to abort!") ); 1691 bar.setCaption (i18n("Syncing - close to abort!") );
1692 1692
1693 // ************** setting up filter ************* 1693 // ************** setting up filter *************
1694 CalFilter *filterIN = 0; 1694 CalFilter *filterIN = 0;
1695 CalFilter *filterOUT = 0; 1695 CalFilter *filterOUT = 0;
1696 CalFilter *filter = mFilters.first(); 1696 CalFilter *filter = mFilters.first();
1697 while(filter) { 1697 while(filter) {
1698 if ( filter->name() == mSyncManager->mFilterInCal ) 1698 if ( filter->name() == mSyncManager->mFilterInCal )
1699 filterIN = filter; 1699 filterIN = filter;
1700 if ( filter->name() == mSyncManager->mFilterOutCal ) 1700 if ( filter->name() == mSyncManager->mFilterOutCal )
1701 filterOUT = filter; 1701 filterOUT = filter;
1702 filter = mFilters.next(); 1702 filter = mFilters.next();
1703 } 1703 }
1704 int w = 300; 1704 int w = 300;
1705 if ( QApplication::desktop()->width() < 320 ) 1705 if ( QApplication::desktop()->width() < 320 )
1706 w = 220; 1706 w = 220;
1707 int h = bar.sizeHint().height() ; 1707 int h = bar.sizeHint().height() ;
1708 int dw = QApplication::desktop()->width(); 1708 int dw = QApplication::desktop()->width();
1709 int dh = QApplication::desktop()->height(); 1709 int dh = QApplication::desktop()->height();
1710 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1710 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1711 bar.show(); 1711 bar.show();
1712 int modulo = (er.count()/10)+1; 1712 int modulo = (er.count()/10)+1;
1713 int incCounter = 0; 1713 int incCounter = 0;
1714 while ( inR ) { 1714 while ( inR ) {
1715 if ( ! bar.isVisible() ) 1715 if ( ! bar.isVisible() )
1716 return false; 1716 return false;
1717 if ( incCounter % modulo == 0 ) 1717 if ( incCounter % modulo == 0 )
1718 bar.setProgress( incCounter ); 1718 bar.setProgress( incCounter );
1719 ++incCounter; 1719 ++incCounter;
1720 uid = inR->uid(); 1720 uid = inR->uid();
1721 bool skipIncidence = false; 1721 bool skipIncidence = false;
1722 if ( uid.left(15) == QString("last-syncEvent-") ) 1722 if ( uid.left(15) == QString("last-syncEvent-") )
1723 skipIncidence = true; 1723 skipIncidence = true;
1724 QString idS; 1724 QString idS;
1725 qApp->processEvents(); 1725 qApp->processEvents();
1726 if ( !skipIncidence ) { 1726 if ( !skipIncidence ) {
1727 int hasCalId = 0; 1727 int hasCalId = 0;
1728 inL = local->incidenceForUid( uid , false , true, &hasCalId ); 1728 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1729 if ( hasCalId && !inL ) 1729 if ( hasCalId && !inL )
1730 inL = local->incidenceForUid( uid , false , true, &hasCalId ); 1730 inL = local->incidenceForUid( uid , false , true, &hasCalId );
1731 else 1731 else
1732 hasCalId = 0; 1732 hasCalId = 0;
1733 if ( inL ) { // maybe conflict - same uid in both calendars 1733 if ( inL ) { // maybe conflict - same uid in both calendars
1734 if ( hasCalId ) 1734
1735 qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1());
1736 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1735 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1737 //qDebug("take %d %s ", take, inL->summary().latin1()); 1736 //qDebug("take %d %s ", take, inL->summary().latin1());
1738 if ( take == 3 ) 1737 if ( take == 3 )
1739 return false; 1738 return false;
1740 if ( take == 1 ) {// take local ********************** 1739 if ( take == 1 ) {// take local **********************
1741 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1740 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1742 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1741 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1743 else 1742 else
1744 idS = inR->IDStr(); 1743 idS = inR->IDStr();
1745 int calID = inR->calID(); 1744 int calID = inR->calID();
1746 remote->deleteIncidence( inR ); 1745 remote->deleteIncidence( inR );
1747 inR = inL->clone(); 1746 if ( !hasCalId ) {
1748 inR->setCalID_block( calID ); 1747 inR = inL->clone();
1749 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1748 inR->setCalID_block( calID );
1750 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1749 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1751 inR->setIDStr( idS ); 1750 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1752 remote->addIncidence( inR ); 1751 inR->setIDStr( idS );
1753 if ( mSyncManager->syncWithDesktop() ) 1752 remote->addIncidence( inR );
1754 inR->setPilotId( 2 ); 1753 if ( mSyncManager->syncWithDesktop() )
1755 ++changedRemote; 1754 inR->setPilotId( 2 );
1755 ++changedRemote;
1756 } else
1757 ++deletedEventR;
1756 } else {// take remote ********************** 1758 } else {// take remote **********************
1757 if ( !inL->isReadOnly() ) { 1759 if ( !inL->isReadOnly() ) {
1758 idS = inL->IDStr(); 1760 idS = inL->IDStr();
1759 int pid = inL->pilotId(); 1761 int pid = inL->pilotId();
1760 int calID = inL->calID(); 1762 int calID = inL->calID();
1761 if ( hasCalId ) 1763 if ( hasCalId )
1762 calID = hasCalId; 1764 calID = 0;// add to default calendar
1763 local->deleteIncidence( inL ); 1765 local->deleteIncidence( inL );
1764 inL = inR->clone(); 1766 inL = inR->clone();
1765 inL->setCalID_block( calID ); 1767 inL->setCalID_block( calID );
1766 if ( mSyncManager->syncWithDesktop() ) 1768 if ( mSyncManager->syncWithDesktop() )
1767 inL->setPilotId( pid ); 1769 inL->setPilotId( pid );
1768 inL->setIDStr( idS ); 1770 inL->setIDStr( idS );
1769 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1771 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1770 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1772 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1771 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1773 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1772 } 1774 }
1773 local->addIncidence( inL ); 1775 local->addIncidence( inL );
1774 ++changedLocal; 1776 ++changedLocal;
1775 } 1777 }
1776 } 1778 }
1777 } else { 1779 } else {
1778 // take == 0; events equal 1780 // take == 0; events equal
1779 if ( hasCalId ) 1781 if ( hasCalId ) {
1780 qDebug("EV EQUALLLL **************************** "); 1782 qDebug("KO: Changing Cal id %d to %d for : %s ", hasCalId, local->defaultCalendar(),inL->summary().latin1());
1783 inL->setCalID( local->defaultCalendar() );
1784 }
1781 1785
1782 } 1786 }
1787
1788
1783 } else { // no conflict ********** add or delete remote 1789 } else { // no conflict ********** add or delete remote
1784 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1790 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1785 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1786 QString des = eventLSync->description(); 1792 QString des = eventLSync->description();
1787 QString pref = "e"; 1793 QString pref = "e";
1788 if ( inR->typeID() == todoID ) 1794 if ( inR->typeID() == todoID )
1789 pref = "t"; 1795 pref = "t";
1790 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1796 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1791 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1797 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1792 //remote->deleteIncidence( inR ); 1798 //remote->deleteIncidence( inR );
1793 ++deletedEventR; 1799 ++deletedEventR;
1794 } else { 1800 } else {
1795 inR->setLastModified( modifiedCalendar ); 1801 inR->setLastModified( modifiedCalendar );
1796 inL = inR->clone(); 1802 inL = inR->clone();
1797 inL->setIDStr( ":" ); 1803 inL->setIDStr( ":" );
1798 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1804 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1799 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1805 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1800 1806
1801 inL->setCalID_block( 0 );// add to default cal 1807 inL->setCalID_block( 0 );// add to default cal
1802 local->addIncidence( inL ); 1808 local->addIncidence( inL );
1803 ++addedEvent; 1809 ++addedEvent;
1804 1810
1805 } 1811 }
1806 } else { 1812 } else {
1807 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1813 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1808 inR->setLastModified( modifiedCalendar ); 1814 inR->setLastModified( modifiedCalendar );
1809 inL = inR->clone(); 1815 inL = inR->clone();
1810 inL->setIDStr( ":" ); 1816 inL->setIDStr( ":" );
1811 inL->setCalID_block( 0 );// add to default cal 1817 inL->setCalID_block( 0 );// add to default cal
1812 local->addIncidence( inL ); 1818 local->addIncidence( inL );
1813 ++addedEvent; 1819 ++addedEvent;
1814 1820
1815 } else { 1821 } else {
1816 checkExternSyncEvent(eventRSyncSharp, inR); 1822 checkExternSyncEvent(eventRSyncSharp, inR);
1817 remote->deleteIncidence( inR ); 1823 remote->deleteIncidence( inR );
1818 ++deletedEventR; 1824 ++deletedEventR;
1819 } 1825 }
1820 } 1826 }
1821 } else { 1827 } else {
1822 ++filteredIN; 1828 ++filteredIN;
1823 } 1829 }
1824 } 1830 }
1825 } 1831 }
1826 inR = er.next(); 1832 inR = er.next();
1827 } 1833 }
1828 QPtrList<Incidence> el = local->rawIncidences(); 1834 QPtrList<Incidence> el = local->rawIncidences();
1829 inL = el.first(); 1835 inL = el.first();
1830 modulo = (el.count()/10)+1; 1836 modulo = (el.count()/10)+1;
1831 bar.setCaption (i18n("Add / remove events") ); 1837 bar.setCaption (i18n("Add / remove events") );
1832 bar.setTotalSteps ( el.count() ) ; 1838 bar.setTotalSteps ( el.count() ) ;
1833 bar.show(); 1839 bar.show();
1834 incCounter = 0; 1840 incCounter = 0;
1835 1841
1836 while ( inL ) { 1842 while ( inL ) {
1837 1843
1838 qApp->processEvents(); 1844 qApp->processEvents();
1839 if ( ! bar.isVisible() ) 1845 if ( ! bar.isVisible() )
1840 return false; 1846 return false;
1841 if ( incCounter % modulo == 0 ) 1847 if ( incCounter % modulo == 0 )
1842 bar.setProgress( incCounter ); 1848 bar.setProgress( incCounter );
1843 ++incCounter; 1849 ++incCounter;
1844 uid = inL->uid(); 1850 uid = inL->uid();
1845 bool skipIncidence = false; 1851 bool skipIncidence = false;
1846 if ( uid.left(15) == QString("last-syncEvent-") ) 1852 if ( uid.left(15) == QString("last-syncEvent-") )
1847 skipIncidence = true; 1853 skipIncidence = true;
1848 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1854 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1849 skipIncidence = true; 1855 skipIncidence = true;
1850 if ( !skipIncidence ) { 1856 if ( !skipIncidence ) {
1851 inR = remote->incidenceForUid( uid , true, true ); 1857 inR = remote->incidenceForUid( uid , true, true );
1852 if ( ! inR ) { 1858 if ( ! inR ) {
1853 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1859 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1854 // no conflict ********** add or delete local 1860 // no conflict ********** add or delete local
1855 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1861 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1856 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1862 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1857 checkExternSyncEvent(eventLSyncSharp, inL); 1863 checkExternSyncEvent(eventLSyncSharp, inL);
1858 local->deleteIncidence( inL ); 1864 local->deleteIncidence( inL );
1859 ++deletedEventL; 1865 ++deletedEventL;
1860 } else { 1866 } else {
1861 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1867 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1862 inL->removeID(mCurrentSyncDevice ); 1868 inL->removeID(mCurrentSyncDevice );
1863 ++addedEventR; 1869 ++addedEventR;
1864 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1870 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1865 inL->setLastModified( modifiedCalendar ); 1871 inL->setLastModified( modifiedCalendar );
1866 inR = inL->clone(); 1872 inR = inL->clone();
1867 inR->setIDStr( ":" ); 1873 inR->setIDStr( ":" );
1868 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1874 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1869 inR->setCalID_block( 0 );// add to default cal 1875 inR->setCalID_block( 0 );// add to default cal
1870 remote->addIncidence( inR ); 1876 remote->addIncidence( inR );
1871 } 1877 }
1872 } 1878 }
1873 } else { 1879 } else {
1874 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1880 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1875 checkExternSyncEvent(eventLSyncSharp, inL); 1881 checkExternSyncEvent(eventLSyncSharp, inL);
1876 local->deleteIncidence( inL ); 1882 local->deleteIncidence( inL );
1877 ++deletedEventL; 1883 ++deletedEventL;
1878 } else { 1884 } else {
1879 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1885 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1880 ++addedEventR; 1886 ++addedEventR;
1881 inL->setLastModified( modifiedCalendar ); 1887 inL->setLastModified( modifiedCalendar );
1882 inR = inL->clone(); 1888 inR = inL->clone();
1883 inR->setIDStr( ":" ); 1889 inR->setIDStr( ":" );
1884 inR->setCalID_block( 0 );// add to default cal 1890 inR->setCalID_block( 0 );// add to default cal
1885 remote->addIncidence( inR ); 1891 remote->addIncidence( inR );
1886 } 1892 }
1887 } 1893 }
1888 } 1894 }
1889 } else { 1895 } else {
1890 ++filteredOUT; 1896 ++filteredOUT;
1891 } 1897 }
1892 } 1898 }
1893 } 1899 }
1894 inL = el.next(); 1900 inL = el.next();
1895 } 1901 }
1896 int delFut = 0; 1902 int delFut = 0;
1897 int remRem = 0; 1903 int remRem = 0;
1898 if ( mSyncManager->mWriteBackInFuture ) { 1904 if ( mSyncManager->mWriteBackInFuture ) {
1899 er = remote->rawIncidences(); 1905 er = remote->rawIncidences();
1900 remRem = er.count(); 1906 remRem = er.count();
1901 inR = er.first(); 1907 inR = er.first();
1902 QDateTime dt; 1908 QDateTime dt;
1903 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1909 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1904 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1910 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1905 while ( inR ) { 1911 while ( inR ) {
1906 if ( inR->typeID() == todoID ) { 1912 if ( inR->typeID() == todoID ) {
1907 Todo * t = (Todo*)inR; 1913 Todo * t = (Todo*)inR;
1908 if ( t->hasDueDate() ) 1914 if ( t->hasDueDate() )
1909 dt = t->dtDue(); 1915 dt = t->dtDue();
1910 else 1916 else
1911 dt = cur.addSecs( 62 ); 1917 dt = cur.addSecs( 62 );
1912 } 1918 }
1913 else if (inR->typeID() == eventID ) { 1919 else if (inR->typeID() == eventID ) {
1914 bool ok; 1920 bool ok;
1915 dt = inR->getNextOccurence( cur, &ok ); 1921 dt = inR->getNextOccurence( cur, &ok );
1916 if ( !ok ) 1922 if ( !ok )
1917 dt = cur.addSecs( -62 ); 1923 dt = cur.addSecs( -62 );
1918 } 1924 }
1919 else 1925 else
1920 dt = inR->dtStart(); 1926 dt = inR->dtStart();
1921 if ( dt < cur || dt > end ) { 1927 if ( dt < cur || dt > end ) {
1922 remote->deleteIncidence( inR ); 1928 remote->deleteIncidence( inR );
1923 ++delFut; 1929 ++delFut;
1924 } 1930 }
1925 inR = er.next(); 1931 inR = er.next();
1926 } 1932 }
1927 } 1933 }
1928 bar.hide(); 1934 bar.hide();
1929 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1935 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1930 if ( mMultiResourceSync ) { 1936 if ( mMultiResourceSync ) {
1931 remote->removeSyncInfo( "" ); //all 1937 remote->removeSyncInfo( "" ); //all
1932 qDebug("KO: Remoing all sync info on remote "); 1938 qDebug("KO: Remoing all sync info on remote ");
1933 } else { 1939 } else {
1934 eventLSync->setReadOnly( false ); 1940 eventLSync->setReadOnly( false );
1935 eventLSync->setDtStart( mLastCalendarSync ); 1941 eventLSync->setDtStart( mLastCalendarSync );
1936 eventRSync->setDtStart( mLastCalendarSync ); 1942 eventRSync->setDtStart( mLastCalendarSync );
1937 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1943 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1938 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1944 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1939 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1945 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1940 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1946 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1941 eventLSync->setReadOnly( true ); 1947 eventLSync->setReadOnly( true );
1942 } 1948 }
1943 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1949 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1944 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... 1950 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal...
1945 remote->addEvent( eventRSync ); 1951 remote->addEvent( eventRSync );
1946 else 1952 else
1947 delete eventRSync; 1953 delete eventRSync;
1948 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1954 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1949 QString mes; 1955 QString mes;
1950 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1956 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1951 QString delmess; 1957 QString delmess;
1952 if ( delFut ) { 1958 if ( delFut ) {
1953 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1959 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1954 mes += delmess; 1960 mes += delmess;
1955 } 1961 }
1956 mes = i18n("Local calendar changed!\n") +mes; 1962 mes = i18n("Local calendar changed!\n") +mes;
1957 mCalendar->checkAlarmForIncidence( 0, true ); 1963 mCalendar->checkAlarmForIncidence( 0, true );
1958 qDebug( mes ); 1964 qDebug( mes );
1959 if ( mSyncManager->mShowSyncSummary ) { 1965 if ( mSyncManager->mShowSyncSummary ) {
1960 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1966 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1961 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1967 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1962 qDebug("KO: WB cancelled "); 1968 qDebug("KO: WB cancelled ");
1963 mSyncManager->mWriteBackFile = false; 1969 mSyncManager->mWriteBackFile = false;
1964 return syncOK; 1970 return syncOK;
1965 } 1971 }
1966 } 1972 }
1967 return syncOK; 1973 return syncOK;
1968} 1974}
1969 1975
1970void CalendarView::setSyncDevice( QString s ) 1976void CalendarView::setSyncDevice( QString s )
1971{ 1977{
1972 mCurrentSyncDevice= s; 1978 mCurrentSyncDevice= s;
1973} 1979}
1974void CalendarView::setSyncName( QString s ) 1980void CalendarView::setSyncName( QString s )
1975{ 1981{
1976 mCurrentSyncName= s; 1982 mCurrentSyncName= s;
1977} 1983}
1978bool CalendarView::syncCalendar(QString filename, int mode) 1984bool CalendarView::syncCalendar(QString filename, int mode)
1979{ 1985{
1980 //qDebug("syncCalendar %s ", filename.latin1()); 1986 //qDebug("syncCalendar %s ", filename.latin1());
1981 mGlobalSyncMode = SYNC_MODE_NORMAL; 1987 mGlobalSyncMode = SYNC_MODE_NORMAL;
1982 CalendarLocal* calendar = new CalendarLocal(); 1988 CalendarLocal* calendar = new CalendarLocal();
1983 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1989 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1984 FileStorage* storage = new FileStorage( calendar ); 1990 FileStorage* storage = new FileStorage( calendar );
1985 bool syncOK = false; 1991 bool syncOK = false;
1986 storage->setFileName( filename ); 1992 storage->setFileName( filename );
1987 // qDebug("loading ... "); 1993 // qDebug("loading ... ");
1988 if ( storage->load() ) { 1994 if ( storage->load() ) {
1989 getEventViewerDialog()->setSyncMode( true ); 1995 getEventViewerDialog()->setSyncMode( true );
1990 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1996 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1991 getEventViewerDialog()->setSyncMode( false ); 1997 getEventViewerDialog()->setSyncMode( false );
1992 if ( syncOK ) { 1998 if ( syncOK ) {
1993 if ( mSyncManager->mWriteBackFile ) 1999 if ( mSyncManager->mWriteBackFile )
1994 { 2000 {
1995 storage->setSaveFormat( new ICalFormat() ); 2001 storage->setSaveFormat( new ICalFormat() );
1996 storage->save(); 2002 storage->save();
1997 } 2003 }
1998 } 2004 }
1999 setModified( true ); 2005 setModified( true );
2000 } 2006 }
2001 delete storage; 2007 delete storage;
2002 delete calendar; 2008 delete calendar;
2003 if ( syncOK ) 2009 if ( syncOK )
2004 updateView(); 2010 updateView();
2005 return syncOK; 2011 return syncOK;
2006} 2012}
2007 2013
2008void CalendarView::syncExternal( int mode ) 2014void CalendarView::syncExternal( int mode )
2009{ 2015{
2010 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2016 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2011 qApp->processEvents(); 2017 qApp->processEvents();
2012 CalendarLocal* calendar = new CalendarLocal(); 2018 CalendarLocal* calendar = new CalendarLocal();
2013 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2019 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2014 bool syncOK = false; 2020 bool syncOK = false;
2015 bool loadSuccess = false; 2021 bool loadSuccess = false;
2016 PhoneFormat* phoneFormat = 0; 2022 PhoneFormat* phoneFormat = 0;
2017 emit tempDisableBR(true); 2023 emit tempDisableBR(true);
2018#ifndef DESKTOP_VERSION 2024#ifndef DESKTOP_VERSION
2019 SharpFormat* sharpFormat = 0; 2025 SharpFormat* sharpFormat = 0;
2020 if ( mode == 0 ) { // sharp 2026 if ( mode == 0 ) { // sharp
2021 sharpFormat = new SharpFormat () ; 2027 sharpFormat = new SharpFormat () ;
2022 loadSuccess = sharpFormat->load( calendar, mCalendar ); 2028 loadSuccess = sharpFormat->load( calendar, mCalendar );
2023 2029
2024 } else 2030 } else
2025#endif 2031#endif
2026 if ( mode == 1 ) { // phone 2032 if ( mode == 1 ) { // phone
2027 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 2033 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
2028 mSyncManager->mPhoneDevice, 2034 mSyncManager->mPhoneDevice,
2029 mSyncManager->mPhoneConnection, 2035 mSyncManager->mPhoneConnection,
2030 mSyncManager->mPhoneModel); 2036 mSyncManager->mPhoneModel);
2031 loadSuccess = phoneFormat->load( calendar,mCalendar); 2037 loadSuccess = phoneFormat->load( calendar,mCalendar);
2032 2038
2033 } else { 2039 } else {
2034 emit tempDisableBR(false); 2040 emit tempDisableBR(false);
2035 return; 2041 return;
2036 } 2042 }
2037 if ( loadSuccess ) { 2043 if ( loadSuccess ) {
2038 getEventViewerDialog()->setSyncMode( true ); 2044 getEventViewerDialog()->setSyncMode( true );
2039 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2045 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2040 getEventViewerDialog()->setSyncMode( false ); 2046 getEventViewerDialog()->setSyncMode( false );
2041 qApp->processEvents(); 2047 qApp->processEvents();
2042 if ( syncOK ) { 2048 if ( syncOK ) {
2043 if ( mSyncManager->mWriteBackFile ) 2049 if ( mSyncManager->mWriteBackFile )
2044 { 2050 {
2045 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 2051 QPtrList<Incidence> iL = mCalendar->rawIncidences();
2046 Incidence* inc = iL.first(); 2052 Incidence* inc = iL.first();
2047 if ( phoneFormat ) { 2053 if ( phoneFormat ) {
2048 while ( inc ) { 2054 while ( inc ) {
2049 inc->removeID(mCurrentSyncDevice); 2055 inc->removeID(mCurrentSyncDevice);
2050 inc = iL.next(); 2056 inc = iL.next();
2051 } 2057 }
2052 } 2058 }
2053#ifndef DESKTOP_VERSION 2059#ifndef DESKTOP_VERSION
2054 if ( sharpFormat ) 2060 if ( sharpFormat )
2055 sharpFormat->save(calendar); 2061 sharpFormat->save(calendar);
2056#endif 2062#endif
2057 if ( phoneFormat ) 2063 if ( phoneFormat )
2058 phoneFormat->save(calendar); 2064 phoneFormat->save(calendar);
2059 iL = calendar->rawIncidences(); 2065 iL = calendar->rawIncidences();
2060 inc = iL.first(); 2066 inc = iL.first();
2061 Incidence* loc; 2067 Incidence* loc;
2062 while ( inc ) { 2068 while ( inc ) {
2063 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 2069 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
2064 loc = mCalendar->incidence(inc->uid() ); 2070 loc = mCalendar->incidence(inc->uid() );
2065 if ( loc ) { 2071 if ( loc ) {
2066 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 2072 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
2067 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 2073 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
2068 } 2074 }
2069 } 2075 }
2070 inc = iL.next(); 2076 inc = iL.next();
2071 } 2077 }
2072 Incidence* lse = getLastSyncEvent(); 2078 Incidence* lse = getLastSyncEvent();
2073 if ( lse ) { 2079 if ( lse ) {
2074 lse->setReadOnly( false ); 2080 lse->setReadOnly( false );
2075 lse->setDescription( "" ); 2081 lse->setDescription( "" );
2076 lse->setReadOnly( true ); 2082 lse->setReadOnly( true );
2077 } 2083 }
2078 } 2084 }
2079 } else { 2085 } else {
2080 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 2086 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
2081 } 2087 }
2082 setModified( true ); 2088 setModified( true );
2083 } else { 2089 } else {
2084 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 2090 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
2085 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 2091 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
2086 question, i18n("Ok")) ; 2092 question, i18n("Ok")) ;
2087 2093
2088 } 2094 }
2089 delete calendar; 2095 delete calendar;
2090 updateView(); 2096 updateView();
2091 emit tempDisableBR(false); 2097 emit tempDisableBR(false);
2092 return ;//syncOK; 2098 return ;//syncOK;
2093 2099
2094} 2100}
2095 2101
2096bool CalendarView::importBday() 2102bool CalendarView::importBday()
2097{ 2103{
2098#ifndef KORG_NOKABC 2104#ifndef KORG_NOKABC
2099 2105
2100#ifdef DESKTOP_VERSION 2106#ifdef DESKTOP_VERSION
2101 int curCal = mCalendar->defaultCalendar(); 2107 int curCal = mCalendar->defaultCalendar();
2102 int bd = mCalEditView->getBirtdayID(); 2108 int bd = mCalEditView->getBirtdayID();
2103 if ( bd == 0 ) 2109 if ( bd == 0 )
2104 return false; 2110 return false;
2105 mCalendar->setDefaultCalendar( bd ); 2111 mCalendar->setDefaultCalendar( bd );
2106 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 2112 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
2107 KABC::AddressBook::Iterator it; 2113 KABC::AddressBook::Iterator it;
2108 int count = 0; 2114 int count = 0;
2109 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2115 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2110 ++count; 2116 ++count;
2111 } 2117 }
2112 QProgressBar bar(count,0 ); 2118 QProgressBar bar(count,0 );
2113 int w = 300; 2119 int w = 300;
2114 if ( QApplication::desktop()->width() < 320 ) 2120 if ( QApplication::desktop()->width() < 320 )
2115 w = 220; 2121 w = 220;
2116 int h = bar.sizeHint().height() ; 2122 int h = bar.sizeHint().height() ;
2117 int dw = QApplication::desktop()->width(); 2123 int dw = QApplication::desktop()->width();
2118 int dh = QApplication::desktop()->height(); 2124 int dh = QApplication::desktop()->height();
2119 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2125 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2120 bar.show(); 2126 bar.show();
2121 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 2127 bar.setCaption (i18n("Reading addressbook - close to abort!") );
2122 qApp->processEvents(); 2128 qApp->processEvents();
2123 count = 0; 2129 count = 0;
2124 int addCount = 0; 2130 int addCount = 0;
2125 KCal::Attendee* a = 0; 2131 KCal::Attendee* a = 0;
2126 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2132 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2127 if ( ! bar.isVisible() ) 2133 if ( ! bar.isVisible() )
2128 return false; 2134 return false;
2129 bar.setProgress( count++ ); 2135 bar.setProgress( count++ );
2130 qApp->processEvents(); 2136 qApp->processEvents();
2131 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 2137 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
2132 if ( (*it).birthday().date().isValid() ){ 2138 if ( (*it).birthday().date().isValid() ){
2133 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2139 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2134 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 2140 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
2135 ++addCount; 2141 ++addCount;
2136 } 2142 }
2137 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 2143 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
2138 if ( anni.isValid() ){ 2144 if ( anni.isValid() ){
2139 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2145 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2140 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 2146 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
2141 ++addCount; 2147 ++addCount;
2142 } 2148 }
2143 } 2149 }
2144 mCalendar->setDefaultCalendar( curCal ); 2150 mCalendar->setDefaultCalendar( curCal );
2145 updateView(); 2151 updateView();
2146 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2152 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2147#else //DESKTOP_VERSION 2153#else //DESKTOP_VERSION
2148 2154
2149 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 2155 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
2150 // the result should now arrive through method insertBirthdays 2156 // the result should now arrive through method insertBirthdays
2151 2157
2152#endif //DESKTOP_VERSION 2158#endif //DESKTOP_VERSION
2153 2159
2154#endif //KORG_NOKABC 2160#endif //KORG_NOKABC
2155 2161
2156 2162
2157 return true; 2163 return true;
2158} 2164}
2159 2165
2160// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 2166// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
2161void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 2167void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
2162 const QStringList& anniversaryList, const QStringList& realNameList, 2168 const QStringList& anniversaryList, const QStringList& realNameList,
2163 const QStringList& emailList, const QStringList& assembledNameList, 2169 const QStringList& emailList, const QStringList& assembledNameList,
2164 const QStringList& uidList) 2170 const QStringList& uidList)
2165{ 2171{
2166 2172
2167 //qDebug("KO::CalendarView::insertBirthdays"); 2173 //qDebug("KO::CalendarView::insertBirthdays");
2168 if (uid == this->name()) 2174 if (uid == this->name())
2169 { 2175 {
2170 int curCal = mCalendar->defaultCalendar(); 2176 int curCal = mCalendar->defaultCalendar();
2171 int bd = mCalEditView->getBirtdayID(); 2177 int bd = mCalEditView->getBirtdayID();
2172 if ( bd == 0 ) 2178 if ( bd == 0 )
2173 return; 2179 return;
2174 mCalendar->setDefaultCalendar( bd ); 2180 mCalendar->setDefaultCalendar( bd );
2175 2181
2176 2182
2177 int count = birthdayList.count(); 2183 int count = birthdayList.count();
2178 int addCount = 0; 2184 int addCount = 0;
2179 KCal::Attendee* a = 0; 2185 KCal::Attendee* a = 0;
2180 2186
2181 //qDebug("CalView 1 %i", count); 2187 //qDebug("CalView 1 %i", count);
2182 2188
2183 QProgressBar bar(count,0 ); 2189 QProgressBar bar(count,0 );
2184 int w = 300; 2190 int w = 300;
2185 if ( QApplication::desktop()->width() < 320 ) 2191 if ( QApplication::desktop()->width() < 320 )
2186 w = 220; 2192 w = 220;
2187 int h = bar.sizeHint().height() ; 2193 int h = bar.sizeHint().height() ;
2188 int dw = QApplication::desktop()->width(); 2194 int dw = QApplication::desktop()->width();
2189 int dh = QApplication::desktop()->height(); 2195 int dh = QApplication::desktop()->height();
2190 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2196 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2191 bar.show(); 2197 bar.show();
2192 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 2198 bar.setCaption (i18n("inserting birthdays - close to abort!") );
2193 qApp->processEvents(); 2199 qApp->processEvents();
2194 2200
2195 QDate birthday; 2201 QDate birthday;
2196 QDate anniversary; 2202 QDate anniversary;
2197 QString realName; 2203 QString realName;
2198 QString email; 2204 QString email;
2199 QString assembledName; 2205 QString assembledName;
2200 QString uid; 2206 QString uid;
2201 bool ok = true; 2207 bool ok = true;
2202 for ( int i = 0; i < count; i++) 2208 for ( int i = 0; i < count; i++)
2203 { 2209 {
2204 if ( ! bar.isVisible() ) 2210 if ( ! bar.isVisible() )
2205 return; 2211 return;
2206 bar.setProgress( i ); 2212 bar.setProgress( i );
2207 qApp->processEvents(); 2213 qApp->processEvents();
2208 2214
2209 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 2215 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
2210 if (!ok) { 2216 if (!ok) {
2211 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 2217 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
2212 } 2218 }
2213 2219
2214 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 2220 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
2215 if (!ok) { 2221 if (!ok) {
2216 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 2222 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
2217 } 2223 }
2218 realName = realNameList[i]; 2224 realName = realNameList[i];
2219 email = emailList[i]; 2225 email = emailList[i];
2220 assembledName = assembledNameList[i]; 2226 assembledName = assembledNameList[i];
2221 uid = uidList[i]; 2227 uid = uidList[i];
2222 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 2228 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
2223 2229
2224 if ( birthday.isValid() ){ 2230 if ( birthday.isValid() ){
2225 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2231 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2226 KCal::Attendee::ReqParticipant,uid) ; 2232 KCal::Attendee::ReqParticipant,uid) ;
2227 if ( addAnniversary( birthday, assembledName, a, true ) ) 2233 if ( addAnniversary( birthday, assembledName, a, true ) )
2228 ++addCount; 2234 ++addCount;
2229 } 2235 }
2230 2236
2231 if ( anniversary.isValid() ){ 2237 if ( anniversary.isValid() ){
2232 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2238 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2233 KCal::Attendee::ReqParticipant,uid) ; 2239 KCal::Attendee::ReqParticipant,uid) ;
2234 if ( addAnniversary( anniversary, assembledName, a, false ) ) 2240 if ( addAnniversary( anniversary, assembledName, a, false ) )
2235 ++addCount; 2241 ++addCount;
2236 } 2242 }
2237 } 2243 }
2238 2244
2239 mCalendar->setDefaultCalendar( curCal ); 2245 mCalendar->setDefaultCalendar( curCal );
2240 updateView(); 2246 updateView();
2241 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2247 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2242 2248
2243 } 2249 }
2244 2250
2245} 2251}
2246 2252
2247 2253
2248 2254
2249bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 2255bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
2250{ 2256{
2251 //qDebug("addAnni "); 2257 //qDebug("addAnni ");
2252 Event * ev = new Event(); 2258 Event * ev = new Event();
2253 ev->setOrganizer(KOPrefs::instance()->email()); 2259 ev->setOrganizer(KOPrefs::instance()->email());
2254 if ( a ) { 2260 if ( a ) {
2255 ev->addAttendee( a ); 2261 ev->addAttendee( a );
2256 } 2262 }
2257 QString kind; 2263 QString kind;
2258 if ( birthday ) { 2264 if ( birthday ) {
2259 kind = i18n( "Birthday" ); 2265 kind = i18n( "Birthday" );
2260 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 2266 ev->setSummary( name + " (" + QString::number(date.year()) +")");
2261 } 2267 }
2262 else { 2268 else {
2263 kind = i18n( "Anniversary" ); 2269 kind = i18n( "Anniversary" );
2264 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 2270 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
2265 } 2271 }
2266 ev->setCategories( kind ); 2272 ev->setCategories( kind );
2267 ev->setDtStart( QDateTime(date) ); 2273 ev->setDtStart( QDateTime(date) );
2268 ev->setDtEnd( QDateTime(date) ); 2274 ev->setDtEnd( QDateTime(date) );
2269 ev->setFloats( true ); 2275 ev->setFloats( true );
2270 Recurrence * rec = ev->recurrence(); 2276 Recurrence * rec = ev->recurrence();
2271 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 2277 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
2272 rec->addYearlyNum( date.month() ); 2278 rec->addYearlyNum( date.month() );
2273 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 2279 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
2274 delete ev; 2280 delete ev;
2275 return false; 2281 return false;
2276 } 2282 }
2277 return true; 2283 return true;
2278 2284
2279} 2285}
2280bool CalendarView::importQtopia( const QString &categories, 2286bool CalendarView::importQtopia( const QString &categories,
2281 const QString &datebook, 2287 const QString &datebook,
2282 const QString &todolist ) 2288 const QString &todolist )
2283{ 2289{
2284 2290
2285 QtopiaFormat qtopiaFormat; 2291 QtopiaFormat qtopiaFormat;
2286 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2292 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2287 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2293 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2288 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2294 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2289 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2295 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2290 2296
2291 updateView(); 2297 updateView();
2292 return true; 2298 return true;
2293 2299
2294#if 0 2300#if 0
2295 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2301 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2296 mCurrentSyncDevice = "qtopia-XML"; 2302 mCurrentSyncDevice = "qtopia-XML";
2297 if ( mSyncManager->mAskForPreferences ) 2303 if ( mSyncManager->mAskForPreferences )
2298 edit_sync_options(); 2304 edit_sync_options();
2299 qApp->processEvents(); 2305 qApp->processEvents();
2300 CalendarLocal* calendar = new CalendarLocal(); 2306 CalendarLocal* calendar = new CalendarLocal();
2301 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2307 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2302 bool syncOK = false; 2308 bool syncOK = false;
2303 QtopiaFormat qtopiaFormat; 2309 QtopiaFormat qtopiaFormat;
2304 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2310 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2305 bool loadOk = true; 2311 bool loadOk = true;
2306 if ( !categories.isEmpty() ) 2312 if ( !categories.isEmpty() )
2307 loadOk = qtopiaFormat.load( calendar, categories ); 2313 loadOk = qtopiaFormat.load( calendar, categories );
2308 if ( loadOk && !datebook.isEmpty() ) 2314 if ( loadOk && !datebook.isEmpty() )
2309 loadOk = qtopiaFormat.load( calendar, datebook ); 2315 loadOk = qtopiaFormat.load( calendar, datebook );
2310 if ( loadOk && !todolist.isEmpty() ) 2316 if ( loadOk && !todolist.isEmpty() )
2311 loadOk = qtopiaFormat.load( calendar, todolist ); 2317 loadOk = qtopiaFormat.load( calendar, todolist );
2312 2318
2313 if ( loadOk ) { 2319 if ( loadOk ) {
2314 getEventViewerDialog()->setSyncMode( true ); 2320 getEventViewerDialog()->setSyncMode( true );
2315 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2321 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2316 getEventViewerDialog()->setSyncMode( false ); 2322 getEventViewerDialog()->setSyncMode( false );
2317 qApp->processEvents(); 2323 qApp->processEvents();
2318 if ( syncOK ) { 2324 if ( syncOK ) {
2319 if ( mSyncManager->mWriteBackFile ) 2325 if ( mSyncManager->mWriteBackFile )
2320 { 2326 {
2321 // write back XML file 2327 // write back XML file
2322 2328
2323 } 2329 }
2324 setModified( true ); 2330 setModified( true );
2325 } 2331 }
2326 } else { 2332 } else {
2327 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2333 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2328 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2334 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2329 question, i18n("Ok")) ; 2335 question, i18n("Ok")) ;
2330 } 2336 }
2331 delete calendar; 2337 delete calendar;
2332 updateView(); 2338 updateView();
2333 return syncOK; 2339 return syncOK;
2334 2340
2335 2341
2336#endif 2342#endif
2337 2343
2338} 2344}
2339 2345
2340void CalendarView::setSyncEventsReadOnly() 2346void CalendarView::setSyncEventsReadOnly()
2341{ 2347{
2342 mCalendar->setSyncEventsReadOnly(); 2348 mCalendar->setSyncEventsReadOnly();
2343} 2349}
2344 2350
2345bool CalendarView::loadCalendars() 2351bool CalendarView::loadCalendars()
2346{ 2352{
2347 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2353 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2348 KopiCalendarFile * cal = calendars.first(); 2354 KopiCalendarFile * cal = calendars.first();
2349 mCalendar->setDefaultCalendar( 1 ); 2355 mCalendar->setDefaultCalendar( 1 );
2350 openCalendar( MainWindow::defaultFileName(), false ); 2356 openCalendar( MainWindow::defaultFileName(), false );
2351 cal = calendars.next(); 2357 cal = calendars.next();
2352 while ( cal ) { 2358 while ( cal ) {
2353 addCalendar( cal ); 2359 addCalendar( cal );
2354 cal = calendars.next(); 2360 cal = calendars.next();
2355 } 2361 }
2356 restoreCalendarSettings(); 2362 restoreCalendarSettings();
2357 return true; 2363 return true;
2358} 2364}
2359bool CalendarView::restoreCalendarSettings() 2365bool CalendarView::restoreCalendarSettings()
2360{ 2366{
2361 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2367 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2362 KopiCalendarFile * cal = calendars.first(); 2368 KopiCalendarFile * cal = calendars.first();
2363 while ( cal ) { 2369 while ( cal ) {
2364 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2370 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2365 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2371 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2366 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2372 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2367 if ( cal->isStandard ) 2373 if ( cal->isStandard )
2368 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2374 mCalendar->setDefaultCalendar( cal->mCalNumber );
2369 cal = calendars.next(); 2375 cal = calendars.next();
2370 } 2376 }
2371 setSyncEventsReadOnly(); 2377 setSyncEventsReadOnly();
2372 mCalendar->reInitAlarmSettings(); 2378 mCalendar->reInitAlarmSettings();
2373 updateUnmanagedViews(); 2379 updateUnmanagedViews();
2374 updateView(); 2380 updateView();
2375 return true; 2381 return true;
2376} 2382}
2377void CalendarView::addCalendarId( int id ) 2383void CalendarView::addCalendarId( int id )
2378{ 2384{
2379 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2385 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2380 if ( cal ) 2386 if ( cal )
2381 addCalendar( cal ); 2387 addCalendar( cal );
2382} 2388}
2383bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2389bool CalendarView::addCalendar( KopiCalendarFile * cal )
2384{ 2390{
2385 cal->mErrorOnLoad = false; 2391 cal->mErrorOnLoad = false;
2386 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2392 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2387 cal->mLoadDt = QDateTime::currentDateTime(); 2393 cal->mLoadDt = QDateTime::currentDateTime();
2388 return true; 2394 return true;
2389 } 2395 }
2390 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2396 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2391 cal->mErrorOnLoad = true; 2397 cal->mErrorOnLoad = true;
2392 return false; 2398 return false;
2393} 2399}
2394bool CalendarView::openCalendar(QString filename, bool merge) 2400bool CalendarView::openCalendar(QString filename, bool merge)
2395{ 2401{
2396 2402
2397 if (filename.isEmpty()) { 2403 if (filename.isEmpty()) {
2398 return false; 2404 return false;
2399 } 2405 }
2400 2406
2401 if (!QFile::exists(filename)) { 2407 if (!QFile::exists(filename)) {
2402 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2408 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2403 return false; 2409 return false;
2404 } 2410 }
2405 2411
2406 globalFlagBlockAgenda = 1; 2412 globalFlagBlockAgenda = 1;
2407 clearAllViews(); 2413 clearAllViews();
2408 if (!merge) { 2414 if (!merge) {
2409 mViewManager->setDocumentId( filename ); 2415 mViewManager->setDocumentId( filename );
2410 mCalendar->close(); 2416 mCalendar->close();
2411 } 2417 }
2412 mStorage->setFileName( filename ); 2418 mStorage->setFileName( filename );
2413 2419
2414 if ( mStorage->load() ) { 2420 if ( mStorage->load() ) {
2415 if ( merge ) ;//setModified( true ); 2421 if ( merge ) ;//setModified( true );
2416 else { 2422 else {
2417 //setModified( true ); 2423 //setModified( true );
2418 mViewManager->setDocumentId( filename ); 2424 mViewManager->setDocumentId( filename );
2419 mDialogManager->setDocumentId( filename ); 2425 mDialogManager->setDocumentId( filename );
2420 mTodoList->setDocumentId( filename ); 2426 mTodoList->setDocumentId( filename );
2421 } 2427 }
2422 globalFlagBlockAgenda = 2; 2428 globalFlagBlockAgenda = 2;
2423 // if ( getLastSyncEvent() ) 2429 // if ( getLastSyncEvent() )
2424 // getLastSyncEvent()->setReadOnly( true ); 2430 // getLastSyncEvent()->setReadOnly( true );
2425 mCalendar->reInitAlarmSettings(); 2431 mCalendar->reInitAlarmSettings();
2426 setSyncEventsReadOnly(); 2432 setSyncEventsReadOnly();
2427 //updateUnmanagedViews(); 2433 //updateUnmanagedViews();
2428 //updateView(); 2434 //updateView();
2429 if ( filename != MainWindow::defaultFileName() ) { 2435 if ( filename != MainWindow::defaultFileName() ) {
2430 saveCalendar( MainWindow::defaultFileName() ); 2436 saveCalendar( MainWindow::defaultFileName() );
2431 } else { 2437 } else {
2432 QFileInfo finf ( MainWindow::defaultFileName()); 2438 QFileInfo finf ( MainWindow::defaultFileName());
2433 if ( finf.exists() ) { 2439 if ( finf.exists() ) {
2434 setLoadedFileVersion( finf.lastModified () ); 2440 setLoadedFileVersion( finf.lastModified () );
2435 } 2441 }
2436 } 2442 }
2437 return true; 2443 return true;
2438 } else { 2444 } else {
2439 // while failing to load, the calendar object could 2445 // while failing to load, the calendar object could
2440 // have become partially populated. Clear it out. 2446 // have become partially populated. Clear it out.
2441 if ( !merge ) { 2447 if ( !merge ) {
2442 mCalendar->close(); 2448 mCalendar->close();
2443 mViewManager->setDocumentId( filename ); 2449 mViewManager->setDocumentId( filename );
2444 mDialogManager->setDocumentId( filename ); 2450 mDialogManager->setDocumentId( filename );
2445 mTodoList->setDocumentId( filename ); 2451 mTodoList->setDocumentId( filename );
2446 } 2452 }
2447 2453
2448 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2454 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2449 2455
2450 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2456 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2451 globalFlagBlockAgenda = 2; 2457 globalFlagBlockAgenda = 2;
2452 mCalendar->reInitAlarmSettings(); 2458 mCalendar->reInitAlarmSettings();
2453 setSyncEventsReadOnly(); 2459 setSyncEventsReadOnly();
2454 updateUnmanagedViews(); 2460 updateUnmanagedViews();
2455 updateView(); 2461 updateView();
2456 } 2462 }
2457 return false; 2463 return false;
2458} 2464}
2459void CalendarView::mergeFile( QString fn ) 2465void CalendarView::mergeFile( QString fn )
2460{ 2466{
2461 clearAllViews(); 2467 clearAllViews();
2462 mCalendar->mergeCalendarFile( fn ); 2468 mCalendar->mergeCalendarFile( fn );
2463 mCalendar->reInitAlarmSettings(); 2469 mCalendar->reInitAlarmSettings();
2464 setSyncEventsReadOnly(); 2470 setSyncEventsReadOnly();
2465 updateUnmanagedViews(); 2471 updateUnmanagedViews();
2466 updateView(); 2472 updateView();
2467} 2473}
2468void CalendarView::mergeFileResource( QString fn ,QString resource ) 2474void CalendarView::mergeFileResource( QString fn ,QString resource )
2469{ 2475{
2470 2476
2471 if ( resource == "ALL" ) { 2477 if ( resource == "ALL" ) {
2472 mCalendar->setAllCalendarEnabled( true ); 2478 mCalendar->setAllCalendarEnabled( true );
2473 mergeFile( fn ); 2479 mergeFile( fn );
2474 restoreCalendarSettings(); 2480 restoreCalendarSettings();
2475 return; 2481 return;
2476 } 2482 }
2477 2483
2478 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); 2484 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
2479 if ( !exclusiveResource ) { 2485 if ( !exclusiveResource ) {
2480 qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); 2486 qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() );
2481 return; 2487 return;
2482 } 2488 }
2483 clearAllViews(); 2489 clearAllViews();
2484 mCalendar->setCalendarRemove( exclusiveResource ); 2490 mCalendar->setCalendarRemove( exclusiveResource );
2485 int def = mCalendar->defaultCalendar();
2486 mCalendar->setDefaultCalendar(exclusiveResource); 2491 mCalendar->setDefaultCalendar(exclusiveResource);
2492 mCalendar->setAllCalendarEnabled( true );
2487 if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { 2493 if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) {
2488 qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); 2494 qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() );
2489 } 2495 }
2490 mCalendar->setDefaultCalendar( def ); 2496 restoreCalendarSettings();
2491 mCalendar->reInitAlarmSettings();
2492 setSyncEventsReadOnly();
2493 updateUnmanagedViews();
2494 updateView();
2495} 2497}
2496void CalendarView::showOpenError() 2498void CalendarView::showOpenError()
2497{ 2499{
2498 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2500 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2499} 2501}
2500void CalendarView::setLoadedFileVersion(QDateTime dt) 2502void CalendarView::setLoadedFileVersion(QDateTime dt)
2501{ 2503{
2502 loadedFileVersion = dt; 2504 loadedFileVersion = dt;
2503} 2505}
2504bool CalendarView::checkFileChanged(QString fn) 2506bool CalendarView::checkFileChanged(QString fn)
2505{ 2507{
2506 QFileInfo finf ( fn ); 2508 QFileInfo finf ( fn );
2507 if ( !finf.exists() ) 2509 if ( !finf.exists() )
2508 return true; 2510 return true;
2509 QDateTime dt = finf.lastModified (); 2511 QDateTime dt = finf.lastModified ();
2510 if ( dt <= loadedFileVersion ) 2512 if ( dt <= loadedFileVersion )
2511 return false; 2513 return false;
2512 return true; 2514 return true;
2513 2515
2514} 2516}
2515void CalendarView::watchSavedFile() 2517void CalendarView::watchSavedFile()
2516{ 2518{
2517 QFileInfo finf ( MainWindow::defaultFileName()); 2519 QFileInfo finf ( MainWindow::defaultFileName());
2518 if ( !finf.exists() ) 2520 if ( !finf.exists() )
2519 return; 2521 return;
2520 QDateTime dt = finf.lastModified (); 2522 QDateTime dt = finf.lastModified ();
2521 if ( dt < loadedFileVersion ) { 2523 if ( dt < loadedFileVersion ) {
2522 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2524 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2523 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2525 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2524 return; 2526 return;
2525 } 2527 }
2526 loadedFileVersion = dt; 2528 loadedFileVersion = dt;
2527} 2529}
2528bool CalendarView::checkAllFileVersions() 2530bool CalendarView::checkAllFileVersions()
2529{ 2531{
2530 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2532 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2531 KopiCalendarFile * cal = calendars.first(); 2533 KopiCalendarFile * cal = calendars.first();
2532 mCalendar->setDefaultCalendar( 1 ); 2534 mCalendar->setDefaultCalendar( 1 );
2533 mCalendar->setDefaultCalendarEnabledOnly(); 2535 mCalendar->setDefaultCalendarEnabledOnly();
2534 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2536 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2535 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2537 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2536 restoreCalendarSettings(); 2538 restoreCalendarSettings();
2537 return false; 2539 return false;
2538 } 2540 }
2539 } 2541 }
2540 cal = calendars.next(); 2542 cal = calendars.next();
2541 QDateTime storeTemp = loadedFileVersion; 2543 QDateTime storeTemp = loadedFileVersion;
2542 while ( cal ) { 2544 while ( cal ) {
2543 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2545 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2544 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2546 mCalendar->setDefaultCalendar( cal->mCalNumber );
2545 mCalendar->setDefaultCalendarEnabledOnly(); 2547 mCalendar->setDefaultCalendarEnabledOnly();
2546 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2548 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2547 if ( !checkFileVersion(cal->mFileName )) { 2549 if ( !checkFileVersion(cal->mFileName )) {
2548 loadedFileVersion = storeTemp; 2550 loadedFileVersion = storeTemp;
2549 restoreCalendarSettings(); 2551 restoreCalendarSettings();
2550 return false; 2552 return false;
2551 } 2553 }
2552 } 2554 }
2553 cal = calendars.next(); 2555 cal = calendars.next();
2554 } 2556 }
2555 loadedFileVersion = storeTemp; 2557 loadedFileVersion = storeTemp;
2556 return true; 2558 return true;
2557} 2559}
2558bool CalendarView::checkFileVersion(QString fn) 2560bool CalendarView::checkFileVersion(QString fn)
2559{ 2561{
2560 QFileInfo finf ( fn ); 2562 QFileInfo finf ( fn );
2561 if ( !finf.exists() ) 2563 if ( !finf.exists() )
2562 return true; 2564 return true;
2563 QDateTime dt = finf.lastModified (); 2565 QDateTime dt = finf.lastModified ();
2564 //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2566 //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2565 //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2567 //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2566 if ( dt <= loadedFileVersion ) 2568 if ( dt <= loadedFileVersion )
2567 return true; 2569 return true;
2568 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2570 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2569 i18n("KO/Pi Warning"),i18n("Overwrite"), 2571 i18n("KO/Pi Warning"),i18n("Overwrite"),
2570 i18n("Sync+save")); 2572 i18n("Sync+save"));
2571 2573
2572 if ( km == KMessageBox::Cancel ) 2574 if ( km == KMessageBox::Cancel )
2573 return false; 2575 return false;
2574 if ( km == KMessageBox::Yes ) 2576 if ( km == KMessageBox::Yes )
2575 return true; 2577 return true;
2576 2578
2577 setSyncDevice("deleteaftersync" ); 2579 setSyncDevice("deleteaftersync" );
2578 mSyncManager->mAskForPreferences = true; 2580 mSyncManager->mAskForPreferences = true;
2579 mSyncManager->mSyncAlgoPrefs = 3; 2581 mSyncManager->mSyncAlgoPrefs = 3;
2580 mSyncManager->mWriteBackFile = false; 2582 mSyncManager->mWriteBackFile = false;
2581 mSyncManager->mWriteBackExistingOnly = false; 2583 mSyncManager->mWriteBackExistingOnly = false;
2582 mSyncManager->mShowSyncSummary = false; 2584 mSyncManager->mShowSyncSummary = false;
2583 mMultiResourceSync = false; 2585 mMultiResourceSync = false;
2584 syncCalendar( fn, 3 ); 2586 syncCalendar( fn, 3 );
2585 Event * e = getLastSyncEvent(); 2587 Event * e = getLastSyncEvent();
2586 if ( e ) 2588 if ( e )
2587 mCalendar->deleteEvent( e ); 2589 mCalendar->deleteEvent( e );
2588 return true; 2590 return true;
2589} 2591}
2590bool CalendarView::saveCalendars() 2592bool CalendarView::saveCalendars()
2591{ 2593{
2592 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2594 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2593 KopiCalendarFile * cal = calendars.first(); 2595 KopiCalendarFile * cal = calendars.first();
2594 mCalendar->setDefaultCalendar( 1 ); 2596 mCalendar->setDefaultCalendar( 1 );
2595 mCalendar->setDefaultCalendarEnabledOnly(); 2597 mCalendar->setDefaultCalendarEnabledOnly();
2596 QString saveError; 2598 QString saveError;
2597 if ( !saveCalendar( MainWindow::defaultFileName() ) ) 2599 if ( !saveCalendar( MainWindow::defaultFileName() ) )
2598 saveError = cal->mName +"\n"; 2600 saveError = cal->mName +"\n";
2599 cal = calendars.next(); 2601 cal = calendars.next();
2600 while ( cal ) { 2602 while ( cal ) {
2601 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2603 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2602 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2604 mCalendar->setDefaultCalendar( cal->mCalNumber );
2603 mCalendar->setDefaultCalendarEnabledOnly(); 2605 mCalendar->setDefaultCalendarEnabledOnly();
2604 if ( saveCalendar( cal->mFileName ) ) 2606 if ( saveCalendar( cal->mFileName ) )
2605 cal->mLoadDt = QDateTime::currentDateTime(); 2607 cal->mLoadDt = QDateTime::currentDateTime();
2606 else 2608 else
2607 saveError += cal->mName + "\n"; 2609 saveError += cal->mName + "\n";
2608 } 2610 }
2609 cal = calendars.next(); 2611 cal = calendars.next();
2610 } 2612 }
2611 restoreCalendarSettings(); 2613 restoreCalendarSettings();
2612 //saveError = "test error"; 2614 //saveError = "test error";
2613 if ( !saveError.isEmpty() ) { 2615 if ( !saveError.isEmpty() ) {
2614 saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; 2616 saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError;
2615 KMessageBox::error(this, saveError, i18n("Error saving data")); 2617 KMessageBox::error(this, saveError, i18n("Error saving data"));
2616 return false; 2618 return false;
2617 } 2619 }
2618 return true; 2620 return true;
2619} 2621}
2620bool CalendarView::saveCalendarResource(QString filename, QString resource) 2622bool CalendarView::saveCalendarResource(QString filename, QString resource)
2621{ 2623{
2622 if ( resource == "ALL" ) { 2624 if ( resource == "ALL" ) {
2623 mCalendar->setAllCalendarEnabled( true ); 2625 mCalendar->setAllCalendarEnabled( true );
2624 bool retval = saveCalendar( filename ); 2626 bool retval = saveCalendar( filename );
2625 restoreCalendarSettings(); 2627 restoreCalendarSettings();
2626 return retval; 2628 return retval;
2627 } 2629 }
2628 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); 2630 int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
2629 if ( !exclusiveResource ) { 2631 if ( !exclusiveResource ) {
2630 qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() ); 2632 qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() );
2631 return false; 2633 return false;
2632 } 2634 }
2633 mCalendar->setDefaultCalendar( exclusiveResource ); 2635 mCalendar->setDefaultCalendar( exclusiveResource );
2634 mCalendar->setDefaultCalendarEnabledOnly(); 2636 mCalendar->setDefaultCalendarEnabledOnly();
2635 mCalendar->setSyncEventsEnabled(); 2637 mCalendar->setSyncEventsEnabled();
2636 bool res = saveCalendar( filename ); 2638 bool res = saveCalendar( filename );
2637 restoreCalendarSettings(); 2639 restoreCalendarSettings();
2638 return res; 2640 return res;
2639 2641
2640} 2642}
2641bool CalendarView::saveCalendar( QString filename ) 2643bool CalendarView::saveCalendar( QString filename )
2642{ 2644{
2643 2645
2644 // Store back all unsaved data into calendar object 2646 // Store back all unsaved data into calendar object
2645 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2647 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2646 if ( mViewManager->currentView() ) 2648 if ( mViewManager->currentView() )
2647 mViewManager->currentView()->flushView(); 2649 mViewManager->currentView()->flushView();
2648 2650
2649 2651
2650 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2652 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2651 mStorage->setSaveFormat( new ICalFormat() ); 2653 mStorage->setSaveFormat( new ICalFormat() );
2652 mStorage->setFileName( filename ); 2654 mStorage->setFileName( filename );
2653 bool success; 2655 bool success;
2654 success = mStorage->save(); 2656 success = mStorage->save();
2655 if ( !success ) { 2657 if ( !success ) {
2656 return false; 2658 return false;
2657 } 2659 }
2658 if ( filename == MainWindow::defaultFileName() ) { 2660 if ( filename == MainWindow::defaultFileName() ) {
2659 setLoadedFileVersion( lfv ); 2661 setLoadedFileVersion( lfv );
2660 watchSavedFile(); 2662 watchSavedFile();
2661 } 2663 }
2662 return true; 2664 return true;
2663} 2665}
2664 2666
2665void CalendarView::closeCalendar() 2667void CalendarView::closeCalendar()
2666{ 2668{
2667 2669
2668 // child windows no longer valid 2670 // child windows no longer valid
2669 clearAllViews(); 2671 clearAllViews();
2670 emit closingDown(); 2672 emit closingDown();
2671 2673
2672 mCalendar->close(); 2674 mCalendar->close();
2673 setModified(false); 2675 setModified(false);
2674 updateView(); 2676 updateView();
2675} 2677}
2676 2678
2677void CalendarView::archiveCalendar() 2679void CalendarView::archiveCalendar()
2678{ 2680{
2679 mDialogManager->showArchiveDialog(); 2681 mDialogManager->showArchiveDialog();
2680} 2682}
2681 2683
2682 2684
2683void CalendarView::readSettings() 2685void CalendarView::readSettings()
2684{ 2686{
2685 2687
2686 2688
2687 // mViewManager->showAgendaView(); 2689 // mViewManager->showAgendaView();
2688 QString str; 2690 QString str;
2689 //qDebug("CalendarView::readSettings() "); 2691 //qDebug("CalendarView::readSettings() ");
2690 // read settings from the KConfig, supplying reasonable 2692 // read settings from the KConfig, supplying reasonable
2691 // defaults where none are to be found 2693 // defaults where none are to be found
2692 KConfig *config = KOGlobals::config(); 2694 KConfig *config = KOGlobals::config();
2693#ifndef KORG_NOSPLITTER 2695#ifndef KORG_NOSPLITTER
2694 config->setGroup("KOrganizer Geometry"); 2696 config->setGroup("KOrganizer Geometry");
2695 2697
2696 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2698 QValueList<int> sizes = config->readIntListEntry("Separator1");
2697 if (sizes.count() != 2) { 2699 if (sizes.count() != 2) {
2698 sizes << mDateNavigator->minimumSizeHint().width(); 2700 sizes << mDateNavigator->minimumSizeHint().width();
2699 sizes << 300; 2701 sizes << 300;
2700 } 2702 }
2701 mPanner->setSizes(sizes); 2703 mPanner->setSizes(sizes);
2702 2704
2703 sizes = config->readIntListEntry("Separator2"); 2705 sizes = config->readIntListEntry("Separator2");
2704 if ( ( mResourceView && sizes.count() == 4 ) || 2706 if ( ( mResourceView && sizes.count() == 4 ) ||
2705 ( !mResourceView && sizes.count() == 3 ) ) { 2707 ( !mResourceView && sizes.count() == 3 ) ) {
2706 mLeftSplitter->setSizes(sizes); 2708 mLeftSplitter->setSizes(sizes);
2707 } 2709 }
2708#endif 2710#endif
2709 globalFlagBlockAgenda = 1; 2711 globalFlagBlockAgenda = 1;
2710 mViewManager->showAgendaView(); 2712 mViewManager->showAgendaView();
2711 //mViewManager->readSettings( config ); 2713 //mViewManager->readSettings( config );
2712 mTodoList->restoreLayout(config,QString("Todo Layout")); 2714 mTodoList->restoreLayout(config,QString("Todo Layout"));
2713 readFilterSettings(config); 2715 readFilterSettings(config);
2714 2716
2715#ifdef DESKTOP_VERSION 2717#ifdef DESKTOP_VERSION
2716 config->setGroup("WidgetLayout"); 2718 config->setGroup("WidgetLayout");
2717 QStringList list; 2719 QStringList list;
2718 list = config->readListEntry("MainLayout"); 2720 list = config->readListEntry("MainLayout");
2719 int x,y,w,h; 2721 int x,y,w,h;
2720 if ( ! list.isEmpty() ) { 2722 if ( ! list.isEmpty() ) {
2721 x = list[0].toInt(); 2723 x = list[0].toInt();
2722 y = list[1].toInt(); 2724 y = list[1].toInt();
2723 w = list[2].toInt(); 2725 w = list[2].toInt();
2724 h = list[3].toInt(); 2726 h = list[3].toInt();
2725 KApplication::testCoords( &x,&y,&w,&h ); 2727 KApplication::testCoords( &x,&y,&w,&h );
2726 topLevelWidget()->setGeometry(x,y,w,h); 2728 topLevelWidget()->setGeometry(x,y,w,h);
2727 2729
2728 } else { 2730 } else {
2729 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2731 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2730 } 2732 }
2731 list = config->readListEntry("EditEventLayout"); 2733 list = config->readListEntry("EditEventLayout");
2732 if ( ! list.isEmpty() ) { 2734 if ( ! list.isEmpty() ) {
2733 x = list[0].toInt(); 2735 x = list[0].toInt();
2734 y = list[1].toInt(); 2736 y = list[1].toInt();
2735 w = list[2].toInt(); 2737 w = list[2].toInt();
2736 h = list[3].toInt(); 2738 h = list[3].toInt();
2737 KApplication::testCoords( &x,&y,&w,&h ); 2739 KApplication::testCoords( &x,&y,&w,&h );
2738 mEventEditor->setGeometry(x,y,w,h); 2740 mEventEditor->setGeometry(x,y,w,h);
2739 2741
2740 } 2742 }
2741 list = config->readListEntry("EditTodoLayout"); 2743 list = config->readListEntry("EditTodoLayout");
2742 if ( ! list.isEmpty() ) { 2744 if ( ! list.isEmpty() ) {
2743 x = list[0].toInt(); 2745 x = list[0].toInt();
2744 y = list[1].toInt(); 2746 y = list[1].toInt();
2745 w = list[2].toInt(); 2747 w = list[2].toInt();
2746 h = list[3].toInt(); 2748 h = list[3].toInt();
2747 KApplication::testCoords( &x,&y,&w,&h ); 2749 KApplication::testCoords( &x,&y,&w,&h );
2748 mTodoEditor->setGeometry(x,y,w,h); 2750 mTodoEditor->setGeometry(x,y,w,h);
2749 2751
2750 } 2752 }
2751 list = config->readListEntry("ViewerLayout"); 2753 list = config->readListEntry("ViewerLayout");
2752 if ( ! list.isEmpty() ) { 2754 if ( ! list.isEmpty() ) {
2753 x = list[0].toInt(); 2755 x = list[0].toInt();
2754 y = list[1].toInt(); 2756 y = list[1].toInt();
2755 w = list[2].toInt(); 2757 w = list[2].toInt();
2756 h = list[3].toInt(); 2758 h = list[3].toInt();
2757 KApplication::testCoords( &x,&y,&w,&h ); 2759 KApplication::testCoords( &x,&y,&w,&h );
2758 getEventViewerDialog()->setGeometry(x,y,w,h); 2760 getEventViewerDialog()->setGeometry(x,y,w,h);
2759 } 2761 }
2760#endif 2762#endif
2761 config->setGroup( "Views" ); 2763 config->setGroup( "Views" );
2762 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2764 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2763 2765
2764 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2766 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2765 2767
2766 int resetval = 0; 2768 int resetval = 0;
2767 int maxVal = 0; 2769 int maxVal = 0;
2768 if (sizes.count() != 3) { 2770 if (sizes.count() != 3) {
2769 if ( KOPrefs::instance()->mVerticalScreen ) { 2771 if ( KOPrefs::instance()->mVerticalScreen ) {
2770 resetval = mDateNavigator->sizeHint().width()+2; 2772 resetval = mDateNavigator->sizeHint().width()+2;
2771 } else { 2773 } else {
2772 resetval = mDateNavigator->sizeHint().height()+2; 2774 resetval = mDateNavigator->sizeHint().height()+2;
2773 } 2775 }
2774 } 2776 }
2775 if ( resetval ) { 2777 if ( resetval ) {
2776 sizes.clear(); 2778 sizes.clear();
2777 if ( KOPrefs::instance()->mVerticalScreen ) { 2779 if ( KOPrefs::instance()->mVerticalScreen ) {
2778 maxVal = QApplication::desktop()->width() -10; 2780 maxVal = QApplication::desktop()->width() -10;
2779 } else { 2781 } else {
2780 maxVal = QApplication::desktop()->height()-10; 2782 maxVal = QApplication::desktop()->height()-10;
2781 } 2783 }
2782 sizes << resetval; 2784 sizes << resetval;
2783 if ( maxVal < resetval + resetval) 2785 if ( maxVal < resetval + resetval)
2784 resetval = maxVal - resetval; 2786 resetval = maxVal - resetval;
2785 sizes << resetval; 2787 sizes << resetval;
2786 sizes << 100; 2788 sizes << 100;
2787 } 2789 }
2788 mLeftFrame->setSizes(sizes); 2790 mLeftFrame->setSizes(sizes);
2789 sizes = config->readIntListEntry("Main Splitter Frame"); 2791 sizes = config->readIntListEntry("Main Splitter Frame");
2790 resetval = 0; 2792 resetval = 0;
2791 maxVal = 0; 2793 maxVal = 0;
2792 if (sizes.count() != 2) { 2794 if (sizes.count() != 2) {
2793 if ( !KOPrefs::instance()->mVerticalScreen ) { 2795 if ( !KOPrefs::instance()->mVerticalScreen ) {
2794 resetval = mDateNavigator->sizeHint().width()+2; 2796 resetval = mDateNavigator->sizeHint().width()+2;
2795 } else { 2797 } else {
2796 resetval = mDateNavigator->sizeHint().height()+2; 2798 resetval = mDateNavigator->sizeHint().height()+2;
2797 } 2799 }
2798 } 2800 }
2799 if ( resetval ) { 2801 if ( resetval ) {
2800 sizes.clear(); 2802 sizes.clear();
2801 if ( !KOPrefs::instance()->mVerticalScreen ) { 2803 if ( !KOPrefs::instance()->mVerticalScreen ) {
2802 maxVal = QApplication::desktop()->width() -10; 2804 maxVal = QApplication::desktop()->width() -10;
2803 } else { 2805 } else {
2804 maxVal = QApplication::desktop()->height()-10; 2806 maxVal = QApplication::desktop()->height()-10;
2805 } 2807 }
2806 sizes << resetval; 2808 sizes << resetval;
2807 if ( maxVal < resetval + resetval) 2809 if ( maxVal < resetval + resetval)
2808 resetval = maxVal - resetval; 2810 resetval = maxVal - resetval;
2809 sizes << resetval; 2811 sizes << resetval;
2810 } 2812 }
2811 mMainFrame->setSizes(sizes); 2813 mMainFrame->setSizes(sizes);
2812 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2814 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2813 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2815 else if ( dateCount == 7 ) mNavigator->selectWeek();
2814 else mNavigator->selectDates( dateCount ); 2816 else mNavigator->selectDates( dateCount );
2815 // mViewManager->readSettings( config ); 2817 // mViewManager->readSettings( config );
2816 updateConfig(); 2818 updateConfig();
2817 globalFlagBlockAgenda = 2; 2819 globalFlagBlockAgenda = 2;
2818 mViewManager->readSettings( config ); 2820 mViewManager->readSettings( config );
2819 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2821 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2820} 2822}
2821 2823
2822void CalendarView::checkSuspendAlarm() 2824void CalendarView::checkSuspendAlarm()
2823{ 2825{
2824 if ( mSuspendTimer->isActive() ) { 2826 if ( mSuspendTimer->isActive() ) {
2825 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2827 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2826 } 2828 }
2827} 2829}
2828void CalendarView::writeSettings() 2830void CalendarView::writeSettings()
2829{ 2831{
2830 // kdDebug() << "CalendarView::writeSettings" << endl; 2832 // kdDebug() << "CalendarView::writeSettings" << endl;
2831 2833
2832 KConfig *config = KOGlobals::config(); 2834 KConfig *config = KOGlobals::config();
2833 2835
2834 mViewManager->writeSettings( config ); 2836 mViewManager->writeSettings( config );
2835 mTodoList->saveLayout(config,QString("Todo Layout")); 2837 mTodoList->saveLayout(config,QString("Todo Layout"));
2836 mDialogManager->writeSettings( config ); 2838 mDialogManager->writeSettings( config );
2837 //KOPrefs::instance()->usrWriteConfig(); 2839 //KOPrefs::instance()->usrWriteConfig();
2838 KOPrefs::instance()->writeConfig(); 2840 KOPrefs::instance()->writeConfig();
2839 2841
2840 writeFilterSettings(config); 2842 writeFilterSettings(config);
2841 config->setGroup( "AppRun" ); 2843 config->setGroup( "AppRun" );
2842 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2844 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2843 int days = dt.daysTo( QDate::currentDate() ); 2845 int days = dt.daysTo( QDate::currentDate() );
2844 dt = dt.addDays( days ); 2846 dt = dt.addDays( days );
2845 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2847 int secs = dt.secsTo( QDateTime::currentDateTime() );
2846 config->writeEntry( "LatestProgramStopDays", days ); 2848 config->writeEntry( "LatestProgramStopDays", days );
2847 config->writeEntry( "LatestProgramStopSecs", secs ); 2849 config->writeEntry( "LatestProgramStopSecs", secs );
2848 //qDebug("KO: Writing stop time: %d ", secs); 2850 //qDebug("KO: Writing stop time: %d ", secs);
2849 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2851 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2850 //QDateTime latest = dt.addSecs ( secs ); 2852 //QDateTime latest = dt.addSecs ( secs );
2851 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2853 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2852 config->setGroup( "Views" ); 2854 config->setGroup( "Views" );
2853 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2855 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2854 2856
2855#if 0 2857#if 0
2856 qDebug("********************* "); 2858 qDebug("********************* ");
2857 qDebug("Testcode secsto "); 2859 qDebug("Testcode secsto ");
2858 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2860 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2859 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2861 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2860 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2862 int secsto = dt_nodaylight.secsTo( dt_daylight );
2861 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2863 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2862 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2864 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2863 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2865 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2864 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2866 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2865 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2867 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2866 qDebug("********************* testcode end"); 2868 qDebug("********************* testcode end");
2867 2869
2868#endif 2870#endif
2869 2871
2870 QValueList<int> listINT = mLeftFrame->sizes(); 2872 QValueList<int> listINT = mLeftFrame->sizes();
2871 config->writeEntry("Left Splitter Frame",listINT); 2873 config->writeEntry("Left Splitter Frame",listINT);
2872 QValueList<int> listINT2 = mMainFrame->sizes(); 2874 QValueList<int> listINT2 = mMainFrame->sizes();
2873 config->writeEntry("Main Splitter Frame",listINT2); 2875 config->writeEntry("Main Splitter Frame",listINT2);
2874#ifdef DESKTOP_VERSION 2876#ifdef DESKTOP_VERSION
2875 config->setGroup("WidgetLayout"); 2877 config->setGroup("WidgetLayout");
2876 QStringList list ;//= config->readListEntry("MainLayout"); 2878 QStringList list ;//= config->readListEntry("MainLayout");
2877 int x,y,w,h; 2879 int x,y,w,h;
2878 QWidget* wid; 2880 QWidget* wid;
2879 wid = topLevelWidget(); 2881 wid = topLevelWidget();
2880 x = wid->geometry().x(); 2882 x = wid->geometry().x();
2881 y = wid->geometry().y(); 2883 y = wid->geometry().y();
2882 w = wid->width(); 2884 w = wid->width();
2883 h = wid->height(); 2885 h = wid->height();
2884 list.clear(); 2886 list.clear();
2885 list << QString::number( x ); 2887 list << QString::number( x );
2886 list << QString::number( y ); 2888 list << QString::number( y );
2887 list << QString::number( w ); 2889 list << QString::number( w );
2888 list << QString::number( h ); 2890 list << QString::number( h );
2889 config->writeEntry("MainLayout",list ); 2891 config->writeEntry("MainLayout",list );
2890 2892
2891 wid = mEventEditor; 2893 wid = mEventEditor;
2892 x = wid->geometry().x(); 2894 x = wid->geometry().x();
2893 y = wid->geometry().y(); 2895 y = wid->geometry().y();
2894 w = wid->width(); 2896 w = wid->width();
2895 h = wid->height(); 2897 h = wid->height();
2896 list.clear(); 2898 list.clear();
2897 list << QString::number( x ); 2899 list << QString::number( x );
2898 list << QString::number( y ); 2900 list << QString::number( y );
2899 list << QString::number( w ); 2901 list << QString::number( w );
2900 list << QString::number( h ); 2902 list << QString::number( h );
2901 config->writeEntry("EditEventLayout",list ); 2903 config->writeEntry("EditEventLayout",list );
2902 2904
2903 wid = mTodoEditor; 2905 wid = mTodoEditor;
2904 x = wid->geometry().x(); 2906 x = wid->geometry().x();
2905 y = wid->geometry().y(); 2907 y = wid->geometry().y();
2906 w = wid->width(); 2908 w = wid->width();
2907 h = wid->height(); 2909 h = wid->height();
2908 list.clear(); 2910 list.clear();
2909 list << QString::number( x ); 2911 list << QString::number( x );
2910 list << QString::number( y ); 2912 list << QString::number( y );
2911 list << QString::number( w ); 2913 list << QString::number( w );
2912 list << QString::number( h ); 2914 list << QString::number( h );
2913 config->writeEntry("EditTodoLayout",list ); 2915 config->writeEntry("EditTodoLayout",list );
2914 wid = getEventViewerDialog(); 2916 wid = getEventViewerDialog();
2915 x = wid->geometry().x(); 2917 x = wid->geometry().x();
2916 y = wid->geometry().y(); 2918 y = wid->geometry().y();
2917 w = wid->width(); 2919 w = wid->width();
2918 h = wid->height(); 2920 h = wid->height();
2919 list.clear(); 2921 list.clear();
2920 list << QString::number( x ); 2922 list << QString::number( x );
2921 list << QString::number( y ); 2923 list << QString::number( y );
2922 list << QString::number( w ); 2924 list << QString::number( w );
2923 list << QString::number( h ); 2925 list << QString::number( h );
2924 config->writeEntry("ViewerLayout",list ); 2926 config->writeEntry("ViewerLayout",list );
2925 wid = mDialogManager->getSearchDialog(); 2927 wid = mDialogManager->getSearchDialog();
2926 if ( wid ) { 2928 if ( wid ) {
2927 x = wid->geometry().x(); 2929 x = wid->geometry().x();
2928 y = wid->geometry().y(); 2930 y = wid->geometry().y();
2929 w = wid->width(); 2931 w = wid->width();
2930 h = wid->height(); 2932 h = wid->height();
2931 list.clear(); 2933 list.clear();
2932 list << QString::number( x ); 2934 list << QString::number( x );
2933 list << QString::number( y ); 2935 list << QString::number( y );
2934 list << QString::number( w ); 2936 list << QString::number( w );
2935 list << QString::number( h ); 2937 list << QString::number( h );
2936 config->writeEntry("SearchLayout",list ); 2938 config->writeEntry("SearchLayout",list );
2937 } 2939 }
2938#endif 2940#endif
2939 2941
2940 2942
2941 config->sync(); 2943 config->sync();
2942} 2944}
2943 2945
2944void CalendarView::readFilterSettings(KConfig *config) 2946void CalendarView::readFilterSettings(KConfig *config)
2945{ 2947{
2946 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2948 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2947 2949
2948 mFilters.clear(); 2950 mFilters.clear();
2949 2951
2950 config->setGroup("General"); 2952 config->setGroup("General");
2951 QStringList filterList = config->readListEntry("CalendarFilters"); 2953 QStringList filterList = config->readListEntry("CalendarFilters");
2952 2954
2953 QStringList::ConstIterator it = filterList.begin(); 2955 QStringList::ConstIterator it = filterList.begin();
2954 QStringList::ConstIterator end = filterList.end(); 2956 QStringList::ConstIterator end = filterList.end();
2955 while(it != end) { 2957 while(it != end) {
2956 // kdDebug() << " filter: " << (*it) << endl; 2958 // kdDebug() << " filter: " << (*it) << endl;
2957 2959
2958 CalFilter *filter; 2960 CalFilter *filter;
2959 filter = new CalFilter(*it); 2961 filter = new CalFilter(*it);
2960 config->setGroup("Filter_" + (*it).utf8()); 2962 config->setGroup("Filter_" + (*it).utf8());
2961 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2963 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2962 filter->setCriteria(config->readNumEntry("Criteria",0)); 2964 filter->setCriteria(config->readNumEntry("Criteria",0));
2963 filter->setCategoryList(config->readListEntry("CategoryList")); 2965 filter->setCategoryList(config->readListEntry("CategoryList"));
2964 mFilters.append(filter); 2966 mFilters.append(filter);
2965 2967
2966 ++it; 2968 ++it;
2967 } 2969 }
2968 2970
2969 if (mFilters.count() == 0) { 2971 if (mFilters.count() == 0) {
2970 CalFilter *filter = new CalFilter(i18n("Default")); 2972 CalFilter *filter = new CalFilter(i18n("Default"));
2971 mFilters.append(filter); 2973 mFilters.append(filter);
2972 } 2974 }
2973 mFilterView->updateFilters(); 2975 mFilterView->updateFilters();
2974 config->setGroup("FilterView"); 2976 config->setGroup("FilterView");
2975 2977
2976 mFilterView->blockSignals(true); 2978 mFilterView->blockSignals(true);
2977 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2979 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2978 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2980 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2979 mFilterView->blockSignals(false); 2981 mFilterView->blockSignals(false);
2980 // We do it manually to avoid it being done twice by the above calls 2982 // We do it manually to avoid it being done twice by the above calls
2981 updateFilter(); 2983 updateFilter();
2982} 2984}
2983 2985
2984void CalendarView::writeFilterSettings(KConfig *config) 2986void CalendarView::writeFilterSettings(KConfig *config)
2985{ 2987{
2986 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2988 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2987 2989
2988 QStringList filterList; 2990 QStringList filterList;
2989 2991
2990 CalFilter *filter = mFilters.first(); 2992 CalFilter *filter = mFilters.first();
2991 while(filter) { 2993 while(filter) {
2992 // kdDebug() << " fn: " << filter->name() << endl; 2994 // kdDebug() << " fn: " << filter->name() << endl;
2993 filterList << filter->name(); 2995 filterList << filter->name();
2994 config->setGroup("Filter_" + filter->name().utf8()); 2996 config->setGroup("Filter_" + filter->name().utf8());
2995 config->writeEntry("Criteria",filter->criteria()); 2997 config->writeEntry("Criteria",filter->criteria());
2996 config->writeEntry("CategoryList",filter->categoryList()); 2998 config->writeEntry("CategoryList",filter->categoryList());
2997 filter = mFilters.next(); 2999 filter = mFilters.next();
2998 } 3000 }
2999 config->setGroup("General"); 3001 config->setGroup("General");
3000 config->writeEntry("CalendarFilters",filterList); 3002 config->writeEntry("CalendarFilters",filterList);
3001 3003
3002 config->setGroup("FilterView"); 3004 config->setGroup("FilterView");
3003 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 3005 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
3004 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 3006 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
3005} 3007}
3006 3008
3007 3009
3008void CalendarView::goToday() 3010void CalendarView::goToday()
3009{ 3011{
3010 if ( mViewManager->currentView()->isMonthView() ) 3012 if ( mViewManager->currentView()->isMonthView() )
3011 mNavigator->selectTodayMonth(); 3013 mNavigator->selectTodayMonth();
3012 else 3014 else
3013 mNavigator->selectToday(); 3015 mNavigator->selectToday();
3014} 3016}
3015 3017
3016void CalendarView::goNext() 3018void CalendarView::goNext()
3017{ 3019{
3018 mNavigator->selectNext(); 3020 mNavigator->selectNext();
3019} 3021}
3020 3022
3021void CalendarView::goPrevious() 3023void CalendarView::goPrevious()
3022{ 3024{
3023 mNavigator->selectPrevious(); 3025 mNavigator->selectPrevious();
3024} 3026}
3025void CalendarView::goNextMonth() 3027void CalendarView::goNextMonth()
3026{ 3028{
3027 mNavigator->selectNextMonth(); 3029 mNavigator->selectNextMonth();
3028} 3030}
3029 3031
3030void CalendarView::goPreviousMonth() 3032void CalendarView::goPreviousMonth()
3031{ 3033{
3032 mNavigator->selectPreviousMonth(); 3034 mNavigator->selectPreviousMonth();
3033} 3035}
3034 3036
3035void CalendarView::updateConfig() 3037void CalendarView::updateConfig()
3036{ 3038{
3037 if ( KOPrefs::instance()->mUseAppColors ) 3039 if ( KOPrefs::instance()->mUseAppColors )
3038 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 3040 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
3039 emit configChanged(); 3041 emit configChanged();
3040 mTodoList->updateConfig(); 3042 mTodoList->updateConfig();
3041 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 3043 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
3042 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3044 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3043 // To make the "fill window" configurations work 3045 // To make the "fill window" configurations work
3044 //mViewManager->raiseCurrentView(); 3046 //mViewManager->raiseCurrentView();
3045} 3047}
3046 3048
3047 3049
3048void CalendarView::eventChanged(Event *event) 3050void CalendarView::eventChanged(Event *event)
3049{ 3051{
3050 changeEventDisplay(event,KOGlobals::EVENTEDITED); 3052 changeEventDisplay(event,KOGlobals::EVENTEDITED);
3051 //updateUnmanagedViews(); 3053 //updateUnmanagedViews();
3052} 3054}
3053 3055
3054void CalendarView::eventAdded(Event *event) 3056void CalendarView::eventAdded(Event *event)
3055{ 3057{
3056 changeEventDisplay(event,KOGlobals::EVENTADDED); 3058 changeEventDisplay(event,KOGlobals::EVENTADDED);
3057} 3059}
3058 3060
3059void CalendarView::eventToBeDeleted(Event *) 3061void CalendarView::eventToBeDeleted(Event *)
3060{ 3062{
3061 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 3063 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
3062} 3064}
3063 3065
3064void CalendarView::eventDeleted() 3066void CalendarView::eventDeleted()
3065{ 3067{
3066 changeEventDisplay(0,KOGlobals::EVENTDELETED); 3068 changeEventDisplay(0,KOGlobals::EVENTDELETED);
3067} 3069}
3068void CalendarView::changeTodoDisplay(Todo *which, int action) 3070void CalendarView::changeTodoDisplay(Todo *which, int action)
3069{ 3071{
3070 changeIncidenceDisplay((Incidence *)which, action); 3072 changeIncidenceDisplay((Incidence *)which, action);
3071 mDateNavigator->updateView(); //LR 3073 mDateNavigator->updateView(); //LR
3072 //mDialogManager->updateSearchDialog(); 3074 //mDialogManager->updateSearchDialog();
3073 3075
3074 if (which) { 3076 if (which) {
3075 mViewManager->updateWNview(); 3077 mViewManager->updateWNview();
3076 //mTodoList->updateView(); 3078 //mTodoList->updateView();
3077 } 3079 }
3078 3080
3079} 3081}
3080 3082
3081void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 3083void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
3082{ 3084{
3083 updateUnmanagedViews(); 3085 updateUnmanagedViews();
3084 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 3086 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
3085 if ( action == KOGlobals::EVENTDELETED ) { //delete 3087 if ( action == KOGlobals::EVENTDELETED ) { //delete
3086 mCalendar->checkAlarmForIncidence( 0, true ); 3088 mCalendar->checkAlarmForIncidence( 0, true );
3087 if ( mEventViewerDialog ) 3089 if ( mEventViewerDialog )
3088 mEventViewerDialog->hide(); 3090 mEventViewerDialog->hide();
3089 } 3091 }
3090 else 3092 else
3091 mCalendar->checkAlarmForIncidence( which , false ); 3093 mCalendar->checkAlarmForIncidence( which , false );
3092} 3094}
3093 3095
3094// most of the changeEventDisplays() right now just call the view's 3096// most of the changeEventDisplays() right now just call the view's
3095// total update mode, but they SHOULD be recoded to be more refresh-efficient. 3097// total update mode, but they SHOULD be recoded to be more refresh-efficient.
3096void CalendarView::changeEventDisplay(Event *which, int action) 3098void CalendarView::changeEventDisplay(Event *which, int action)
3097{ 3099{
3098 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 3100 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
3099 changeIncidenceDisplay((Incidence *)which, action); 3101 changeIncidenceDisplay((Incidence *)which, action);
3100 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 3102 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
3101 if ( flag_clearallviewsEventDisplay ) { 3103 if ( flag_clearallviewsEventDisplay ) {
3102 clearAllViews(); 3104 clearAllViews();
3103 flag_clearallviewsEventDisplay = false; 3105 flag_clearallviewsEventDisplay = false;
3104 } 3106 }
3105 return; 3107 return;
3106 } 3108 }
3107 flag_clearallviewsEventDisplay = true; 3109 flag_clearallviewsEventDisplay = true;
3108 mDateNavigator->updateView(); 3110 mDateNavigator->updateView();
3109 //mDialogManager->updateSearchDialog(); 3111 //mDialogManager->updateSearchDialog();
3110 if (which) { 3112 if (which) {
3111 // If there is an event view visible update the display 3113 // If there is an event view visible update the display
3112 mViewManager->currentView()->changeEventDisplay(which,action); 3114 mViewManager->currentView()->changeEventDisplay(which,action);
3113 // TODO: check, if update needed 3115 // TODO: check, if update needed
3114 // if (which->getTodoStatus()) { 3116 // if (which->getTodoStatus()) {
3115 mTodoList->updateView(); 3117 mTodoList->updateView();
3116 if ( action != KOGlobals::EVENTDELETED && KOPrefs::instance()->mDetectConflicts ) { 3118 if ( action != KOGlobals::EVENTDELETED && KOPrefs::instance()->mDetectConflicts ) {
3117 mConflictingEvent = which ; 3119 mConflictingEvent = which ;
3118 int time = 1000; 3120 int time = 1000;
3119#ifdef DESKTOP_VERSION 3121#ifdef DESKTOP_VERSION
3120 time = 500; 3122 time = 500;
3121#endif 3123#endif
3122 bool checkC = false; 3124 bool checkC = false;
3123 if ( mConflictingEvent->doesFloat() ) { 3125 if ( mConflictingEvent->doesFloat() ) {
3124 checkC = KOPrefs::instance()->mCheckConflictsAllDayAllDay 3126 checkC = KOPrefs::instance()->mCheckConflictsAllDayAllDay
3125 || KOPrefs::instance()->mCheckConflictsAllDayNonAD; 3127 || KOPrefs::instance()->mCheckConflictsAllDayNonAD;
3126 } else { 3128 } else {
3127 checkC = KOPrefs::instance()->mCheckConflictsNonADAllDay 3129 checkC = KOPrefs::instance()->mCheckConflictsNonADAllDay
3128 || KOPrefs::instance()->mCheckConflictsNonADNonAD; 3130 || KOPrefs::instance()->mCheckConflictsNonADNonAD;
3129 } 3131 }
3130 if ( !KOPrefs::instance()->mIncludeFree && mConflictingEvent->transparency() == KCal::Event::Transparent ) 3132 if ( !KOPrefs::instance()->mIncludeFree && mConflictingEvent->transparency() == KCal::Event::Transparent )
3131 checkC = false; 3133 checkC = false;
3132 if ( checkC ) 3134 if ( checkC )
3133 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) ); 3135 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) );
3134 } 3136 }
3135 // } 3137 // }
3136 } else { 3138 } else {
3137 mViewManager->currentView()->updateView(); 3139 mViewManager->currentView()->updateView();
3138 } 3140 }
3139} 3141}
3140void CalendarView::checkConflictForEvent() 3142void CalendarView::checkConflictForEvent()
3141{ 3143{
3142 3144
3143 if (!KOPrefs::instance()->mConfirm) 3145 if (!KOPrefs::instance()->mConfirm)
3144 return; 3146 return;
3145 if ( ! mConflictingEvent ) return; 3147 if ( ! mConflictingEvent ) return;
3146 Event * conflictingEvent = mConflictingEvent; 3148 Event * conflictingEvent = mConflictingEvent;
3147 mConflictingEvent = 0; 3149 mConflictingEvent = 0;
3148 QDateTime current = QDateTime::currentDateTime(); 3150 QDateTime current = QDateTime::currentDateTime();
3149 if ( ! conflictingEvent->matchTime( &current, 0 ) ) { 3151 if ( ! conflictingEvent->matchTime( &current, 0 ) ) {
3150 return; 3152 return;
3151 } 3153 }
3152 CalFilter *filterIN = 0; 3154 CalFilter *filterIN = 0;
3153 CalFilter *filterALL = 0; 3155 CalFilter *filterALL = 0;
3154 CalFilter *filter = mFilters.first(); 3156 CalFilter *filter = mFilters.first();
3155 while(filter) { 3157 while(filter) {
3156 if ( filter->name() == KOPrefs::instance()->mFilterConflictEditItem) 3158 if ( filter->name() == KOPrefs::instance()->mFilterConflictEditItem)
3157 filterIN = filter; 3159 filterIN = filter;
3158 if ( filter->name() == KOPrefs::instance()->mFilterConflictAllItem ) 3160 if ( filter->name() == KOPrefs::instance()->mFilterConflictAllItem )
3159 filterALL = filter; 3161 filterALL = filter;
3160 filter = mFilters.next(); 3162 filter = mFilters.next();
3161 } 3163 }
3162 if ( filterIN ) { 3164 if ( filterIN ) {
3163 if ( !filterIN->filterCalendarItem( conflictingEvent ) ) { 3165 if ( !filterIN->filterCalendarItem( conflictingEvent ) ) {
3164 return; 3166 return;
3165 } 3167 }
3166 } 3168 }
3167 QPtrList<Event> testlist = mCalendar->events(); 3169 QPtrList<Event> testlist = mCalendar->events();
3168 Event * test = testlist.first(); 3170 Event * test = testlist.first();
3169 QDateTime conflict; 3171 QDateTime conflict;
3170 QDateTime retVal; 3172 QDateTime retVal;
3171 bool found = false; 3173 bool found = false;
3172 Event * cE = 0; 3174 Event * cE = 0;
3173 bool chAD = KOPrefs::instance()->mCheckConflictsAllDayAllDay; 3175 bool chAD = KOPrefs::instance()->mCheckConflictsAllDayAllDay;
3174 bool chNad = KOPrefs::instance()->mCheckConflictsAllDayNonAD; 3176 bool chNad = KOPrefs::instance()->mCheckConflictsAllDayNonAD;
3175 if ( !conflictingEvent->doesFloat() ) { 3177 if ( !conflictingEvent->doesFloat() ) {
3176 chAD = KOPrefs::instance()->mCheckConflictsNonADAllDay; 3178 chAD = KOPrefs::instance()->mCheckConflictsNonADAllDay;
3177 chNad = KOPrefs::instance()->mCheckConflictsNonADNonAD; 3179 chNad = KOPrefs::instance()->mCheckConflictsNonADNonAD;
3178 } 3180 }
3179 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 3181 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
3180 while ( test ) { 3182 while ( test ) {
3181 qApp->processEvents(); 3183 qApp->processEvents();
3182 bool skip = ( test->doesFloat() && !chAD ) || ( !test->doesFloat() && !chNad ); 3184 bool skip = ( test->doesFloat() && !chAD ) || ( !test->doesFloat() && !chNad );
3183 3185
3184 if ( !skip ) { 3186 if ( !skip ) {
3185 if ( !KOPrefs::instance()->mIncludeFree && test->transparency() == KCal::Event::Transparent ) 3187 if ( !KOPrefs::instance()->mIncludeFree && test->transparency() == KCal::Event::Transparent )
3186 skip = true; 3188 skip = true;
3187 } 3189 }
3188 if ( !skip ) { 3190 if ( !skip ) {
3189 if ( filterALL ) { 3191 if ( filterALL ) {
3190 if ( !filterALL->filterCalendarItem( test ) ) { 3192 if ( !filterALL->filterCalendarItem( test ) ) {
3191 skip = true; 3193 skip = true;
3192 } 3194 }
3193 } 3195 }
3194 if ( !skip ) { 3196 if ( !skip ) {
3195 if ( found ) 3197 if ( found )
3196 skip = !test->matchTime( &current, &conflict ); 3198 skip = !test->matchTime( &current, &conflict );
3197 else 3199 else
3198 skip = !test->matchTime( &current, 0 ); 3200 skip = !test->matchTime( &current, 0 );
3199 if ( !skip ) { 3201 if ( !skip ) {
3200 if ( conflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 3202 if ( conflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
3201 if ( ! found ) { 3203 if ( ! found ) {
3202 conflict = retVal; 3204 conflict = retVal;
3203 cE = test; 3205 cE = test;
3204 } else { 3206 } else {
3205 if ( retVal < conflict ) { 3207 if ( retVal < conflict ) {
3206 conflict = retVal; 3208 conflict = retVal;
3207 cE = test; 3209 cE = test;
3208 } 3210 }
3209 } 3211 }
3210 found = true; 3212 found = true;
3211 } 3213 }
3212 } 3214 }
3213 } 3215 }
3214 } 3216 }
3215 test = testlist.next(); 3217 test = testlist.next();
3216 } 3218 }
3217 topLevelWidget()->setCaption( i18n("KO/Pi") ); 3219 topLevelWidget()->setCaption( i18n("KO/Pi") );
3218 if ( found ) { 3220 if ( found ) {
3219 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( conflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 3221 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( conflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
3220 qApp->processEvents(); 3222 qApp->processEvents();
3221 int km = KMessageBox::warningContinueCancel(this,mess, 3223 int km = KMessageBox::warningContinueCancel(this,mess,
3222 i18n("KO/Pi Conflict detected"),i18n("Show date"),i18n("No problem!")); 3224 i18n("KO/Pi Conflict detected"),i18n("Show date"),i18n("No problem!"));
3223 if ( km != KMessageBox::Continue ) { 3225 if ( km != KMessageBox::Continue ) {
3224 return; 3226 return;
3225 } 3227 }
3226 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 3228 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
3227 mViewManager->showDayView(); 3229 mViewManager->showDayView();
3228 mNavigator->slotDaySelect( conflict.date() ); 3230 mNavigator->slotDaySelect( conflict.date() );
3229 int hour = conflict.time().hour(); 3231 int hour = conflict.time().hour();
3230 mViewManager->agendaView()->setStartHour( hour ); 3232 mViewManager->agendaView()->setStartHour( hour );
3231 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( conflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 3233 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( conflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
3232 } else 3234 } else
3233 topLevelWidget()->setCaption( i18n("No conflict found") ); 3235 topLevelWidget()->setCaption( i18n("No conflict found") );
3234 return; 3236 return;
3235 3237
3236} 3238}
3237 3239
3238void CalendarView::updateTodoViews() 3240void CalendarView::updateTodoViews()
3239{ 3241{
3240 mTodoList->updateView(); 3242 mTodoList->updateView();
3241 mViewManager->currentView()->updateView(); 3243 mViewManager->currentView()->updateView();
3242 3244
3243} 3245}
3244 3246
3245 3247
3246 3248
3247void CalendarView::clearAllViews() 3249void CalendarView::clearAllViews()
3248{ 3250{
3249 mTodoList->clearList(); 3251 mTodoList->clearList();
3250 mViewManager->clearAllViews(); 3252 mViewManager->clearAllViews();
3251 SearchDialog * sd = mDialogManager->getSearchDialog(); 3253 SearchDialog * sd = mDialogManager->getSearchDialog();
3252 if ( sd ) { 3254 if ( sd ) {
3253 KOListView* kol = sd->listview(); 3255 KOListView* kol = sd->listview();
3254 if ( kol ) 3256 if ( kol )
3255 kol->clearList(); 3257 kol->clearList();
3256 } 3258 }
3257} 3259}
3258void CalendarView::updateView() 3260void CalendarView::updateView()
3259{ 3261{
3260 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 3262 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
3261 if ( flag_clearallviewsupdateView ) { 3263 if ( flag_clearallviewsupdateView ) {
3262 clearAllViews(); 3264 clearAllViews();
3263 flag_clearallviewsupdateView = false; 3265 flag_clearallviewsupdateView = false;
3264 } 3266 }
3265 return; 3267 return;
3266 } 3268 }
3267 flag_clearallviewsupdateView = true; 3269 flag_clearallviewsupdateView = true;
3268 DateList tmpList = mNavigator->selectedDates(); 3270 DateList tmpList = mNavigator->selectedDates();
3269 3271
3270 if ( KOPrefs::instance()->mHideNonStartedTodos ) 3272 if ( KOPrefs::instance()->mHideNonStartedTodos )
3271 mTodoList->updateView(); 3273 mTodoList->updateView();
3272 // We assume that the navigator only selects consecutive days. 3274 // We assume that the navigator only selects consecutive days.
3273 updateView( tmpList.first(), tmpList.last() ); 3275 updateView( tmpList.first(), tmpList.last() );
3274} 3276}
3275 3277
3276void CalendarView::updateUnmanagedViews() 3278void CalendarView::updateUnmanagedViews()
3277{ 3279{
3278 mDateNavigator->updateDayMatrix(); 3280 mDateNavigator->updateDayMatrix();
3279} 3281}
3280 3282
3281int CalendarView::msgItemDelete(const QString name) 3283int CalendarView::msgItemDelete(const QString name)
3282{ 3284{
3283 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 3285 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
3284 i18n("This item will be\npermanently deleted."), 3286 i18n("This item will be\npermanently deleted."),
3285 i18n("KO/Pi Confirmation"),i18n("Delete")); 3287 i18n("KO/Pi Confirmation"),i18n("Delete"));
3286} 3288}
3287 3289
3288 3290
3289void CalendarView::edit_cut() 3291void CalendarView::edit_cut()
3290{ 3292{
3291 Event *anEvent=0; 3293 Event *anEvent=0;
3292 3294
3293 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3295 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3294 3296
3295 if (mViewManager->currentView()->isEventView()) { 3297 if (mViewManager->currentView()->isEventView()) {
3296 if ( incidence && incidence->typeID() == eventID ) { 3298 if ( incidence && incidence->typeID() == eventID ) {
3297 anEvent = static_cast<Event *>(incidence); 3299 anEvent = static_cast<Event *>(incidence);
3298 } 3300 }
3299 } 3301 }
3300 3302
3301 if (!anEvent) { 3303 if (!anEvent) {
3302 KNotifyClient::beep(); 3304 KNotifyClient::beep();
3303 return; 3305 return;
3304 } 3306 }
3305 DndFactory factory( mCalendar ); 3307 DndFactory factory( mCalendar );
3306 factory.cutIncidence(anEvent); 3308 factory.cutIncidence(anEvent);
3307 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3309 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3308} 3310}
3309 3311
3310void CalendarView::edit_copy() 3312void CalendarView::edit_copy()
3311{ 3313{
3312 Event *anEvent=0; 3314 Event *anEvent=0;
3313 3315
3314 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3316 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3315 3317
3316 if (mViewManager->currentView()->isEventView()) { 3318 if (mViewManager->currentView()->isEventView()) {
3317 if ( incidence && incidence->typeID() == eventID ) { 3319 if ( incidence && incidence->typeID() == eventID ) {
3318 anEvent = static_cast<Event *>(incidence); 3320 anEvent = static_cast<Event *>(incidence);
3319 } 3321 }
3320 } 3322 }
3321 3323
3322 if (!anEvent) { 3324 if (!anEvent) {
3323 KNotifyClient::beep(); 3325 KNotifyClient::beep();
3324 return; 3326 return;
3325 } 3327 }
3326 DndFactory factory( mCalendar ); 3328 DndFactory factory( mCalendar );
3327 factory.copyIncidence(anEvent); 3329 factory.copyIncidence(anEvent);
3328} 3330}
3329 3331
3330void CalendarView::edit_paste() 3332void CalendarView::edit_paste()
3331{ 3333{
3332 QDate date = mNavigator->selectedDates().first(); 3334 QDate date = mNavigator->selectedDates().first();
3333 3335
3334 DndFactory factory( mCalendar ); 3336 DndFactory factory( mCalendar );
3335 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 3337 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
3336 3338
3337 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 3339 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
3338} 3340}
3339void CalendarView::edit_global_options() 3341void CalendarView::edit_global_options()
3340{ 3342{
3341 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 3343 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
3342 emit save(); 3344 emit save();
3343 emit saveStopTimer(); 3345 emit saveStopTimer();
3344 mDialogManager->showGlobalOptionsDialog(); 3346 mDialogManager->showGlobalOptionsDialog();
3345 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 3347 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
3346 emit saveStopTimer(); 3348 emit saveStopTimer();
3347 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 3349 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
3348 i18n("Timezone settings"),i18n("Reload"))) { 3350 i18n("Timezone settings"),i18n("Reload"))) {
3349 qDebug("KO: TZ reload cancelled "); 3351 qDebug("KO: TZ reload cancelled ");
3350 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3352 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3351 return; 3353 return;
3352 } 3354 }
3353 qDebug("KO: Timezone change "); 3355 qDebug("KO: Timezone change ");
3354 loadCalendars(); 3356 loadCalendars();
3355 setModified(true); 3357 setModified(true);
3356 } 3358 }
3357 else 3359 else
3358 qDebug("KO: No tz change "); 3360 qDebug("KO: No tz change ");
3359} 3361}
3360void CalendarView::edit_options() 3362void CalendarView::edit_options()
3361{ 3363{
3362 mDialogManager->showOptionsDialog(); 3364 mDialogManager->showOptionsDialog();
3363} 3365}
3364 3366
3365 3367
3366void CalendarView::slotSelectPickerDate( QDate d) 3368void CalendarView::slotSelectPickerDate( QDate d)
3367{ 3369{
3368 mDateFrame->hide(); 3370 mDateFrame->hide();
3369 if ( mDatePickerMode == 1 ) { 3371 if ( mDatePickerMode == 1 ) {
3370 mNavigator->slotDaySelect( d ); 3372 mNavigator->slotDaySelect( d );
3371 } else if ( mDatePickerMode == 2 ) { 3373 } else if ( mDatePickerMode == 2 ) {
3372 if ( mMoveIncidence->typeID() == todoID ) { 3374 if ( mMoveIncidence->typeID() == todoID ) {
3373 Todo * to = (Todo *) mMoveIncidence; 3375 Todo * to = (Todo *) mMoveIncidence;
3374 QTime tim; 3376 QTime tim;
3375 int len = 0; 3377 int len = 0;
3376 if ( to->hasStartDate() && to->hasDueDate() ) 3378 if ( to->hasStartDate() && to->hasDueDate() )
3377 len = to->dtStart().secsTo( to->dtDue()); 3379 len = to->dtStart().secsTo( to->dtDue());
3378 if ( to->hasDueDate() ) 3380 if ( to->hasDueDate() )
3379 tim = to->dtDue().time(); 3381 tim = to->dtDue().time();
3380 else { 3382 else {
3381 tim = QTime ( 0,0,0 ); 3383 tim = QTime ( 0,0,0 );
3382 to->setFloats( true ); 3384 to->setFloats( true );
3383 to->setHasDueDate( true ); 3385 to->setHasDueDate( true );
3384 } 3386 }
3385 QDateTime dt ( d,tim ); 3387 QDateTime dt ( d,tim );
3386 to->setDtDue( dt ); 3388 to->setDtDue( dt );
3387 3389
3388 if ( to->hasStartDate() ) { 3390 if ( to->hasStartDate() ) {
3389 if ( len>0 ) 3391 if ( len>0 )
3390 to->setDtStart(to->dtDue().addSecs( -len )); 3392 to->setDtStart(to->dtDue().addSecs( -len ));
3391 else 3393 else
3392 if (to->dtStart() > to->dtDue() ) 3394 if (to->dtStart() > to->dtDue() )
3393 to->setDtStart(to->dtDue().addDays( -3 )); 3395 to->setDtStart(to->dtDue().addDays( -3 ));
3394 } 3396 }
3395 3397
3396 todoChanged( to ); 3398 todoChanged( to );
3397 } else if ( mMoveIncidence->typeID() == eventID ) { 3399 } else if ( mMoveIncidence->typeID() == eventID ) {
3398 if ( mMoveIncidence->doesRecur() ) { 3400 if ( mMoveIncidence->doesRecur() ) {
3399#if 0 3401#if 0
3400 // PENDING implement this 3402 // PENDING implement this
3401 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 3403 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
3402 mCalendar()->addIncidence( newInc ); 3404 mCalendar()->addIncidence( newInc );
3403 if ( mMoveIncidence->typeID() == todoID ) 3405 if ( mMoveIncidence->typeID() == todoID )
3404 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 3406 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
3405 else 3407 else
3406 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 3408 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
3407 mMoveIncidence = newInc; 3409 mMoveIncidence = newInc;
3408 3410
3409#endif 3411#endif
3410 } 3412 }
3411 QTime tim = mMoveIncidence->dtStart().time(); 3413 QTime tim = mMoveIncidence->dtStart().time();
3412 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 3414 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
3413 QDateTime dt ( d,tim ); 3415 QDateTime dt ( d,tim );
3414 mMoveIncidence->setDtStart( dt ); 3416 mMoveIncidence->setDtStart( dt );
3415 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 3417 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
3416 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 3418 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
3417 } else if ( mMoveIncidence->typeID() == journalID ) { 3419 } else if ( mMoveIncidence->typeID() == journalID ) {
3418 QTime tim = mMoveIncidence->dtStart().time(); 3420 QTime tim = mMoveIncidence->dtStart().time();
3419 QDateTime dt ( d,tim ); 3421 QDateTime dt ( d,tim );
3420 mMoveIncidence->setDtStart( dt ); 3422 mMoveIncidence->setDtStart( dt );
3421 updateView(); 3423 updateView();
3422 } 3424 }
3423 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3425 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3424 } 3426 }
3425} 3427}
3426 3428
3427void CalendarView::removeCategories() 3429void CalendarView::removeCategories()
3428{ 3430{
3429 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3431 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3430 QStringList catList = KOPrefs::instance()->mCustomCategories; 3432 QStringList catList = KOPrefs::instance()->mCustomCategories;
3431 QStringList catIncList; 3433 QStringList catIncList;
3432 QStringList newCatList; 3434 QStringList newCatList;
3433 Incidence* inc = incList.first(); 3435 Incidence* inc = incList.first();
3434 uint i; 3436 uint i;
3435 while ( inc ) { 3437 while ( inc ) {
3436 newCatList.clear(); 3438 newCatList.clear();
3437 catIncList = inc->categories() ; 3439 catIncList = inc->categories() ;
3438 for( i = 0; i< catIncList.count(); ++i ) { 3440 for( i = 0; i< catIncList.count(); ++i ) {
3439 if ( catList.contains (catIncList[i])) 3441 if ( catList.contains (catIncList[i]))
3440 newCatList.append( catIncList[i] ); 3442 newCatList.append( catIncList[i] );
3441 } 3443 }
3442 newCatList.sort(); 3444 newCatList.sort();
3443 inc->setCategories( newCatList.join(",") ); 3445 inc->setCategories( newCatList.join(",") );
3444 inc = incList.next(); 3446 inc = incList.next();
3445 } 3447 }
3446} 3448}
3447 3449
3448int CalendarView::addCategories() 3450int CalendarView::addCategories()
3449{ 3451{
3450 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3452 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3451 QStringList catList = KOPrefs::instance()->mCustomCategories; 3453 QStringList catList = KOPrefs::instance()->mCustomCategories;
3452 QStringList catIncList; 3454 QStringList catIncList;
3453 Incidence* inc = incList.first(); 3455 Incidence* inc = incList.first();
3454 uint i; 3456 uint i;
3455 int count = 0; 3457 int count = 0;
3456 while ( inc ) { 3458 while ( inc ) {
3457 catIncList = inc->categories() ; 3459 catIncList = inc->categories() ;
3458 for( i = 0; i< catIncList.count(); ++i ) { 3460 for( i = 0; i< catIncList.count(); ++i ) {
3459 if ( !catList.contains (catIncList[i])) { 3461 if ( !catList.contains (catIncList[i])) {
3460 catList.append( catIncList[i] ); 3462 catList.append( catIncList[i] );
3461 //qDebug("add cat %s ", catIncList[i].latin1()); 3463 //qDebug("add cat %s ", catIncList[i].latin1());
3462 ++count; 3464 ++count;
3463 } 3465 }
3464 } 3466 }
3465 inc = incList.next(); 3467 inc = incList.next();
3466 } 3468 }
3467 catList.sort(); 3469 catList.sort();
3468 KOPrefs::instance()->mCustomCategories = catList; 3470 KOPrefs::instance()->mCustomCategories = catList;
3469 return count; 3471 return count;
3470} 3472}
3471 3473
3472void CalendarView::editCategories() 3474void CalendarView::editCategories()
3473{ 3475{
3474 qDebug("CalendarView::editCategories() "); 3476 qDebug("CalendarView::editCategories() ");
3475 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3477 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3476 ced.exec(); 3478 ced.exec();
3477} 3479}
3478void CalendarView::manageCategories() 3480void CalendarView::manageCategories()
3479{ 3481{
3480 KOCatPrefs* cp = new KOCatPrefs(); 3482 KOCatPrefs* cp = new KOCatPrefs();
3481 cp->show(); 3483 cp->show();
3482 int w =cp->sizeHint().width() ; 3484 int w =cp->sizeHint().width() ;
3483 int h = cp->sizeHint().height() ; 3485 int h = cp->sizeHint().height() ;
3484 int dw = QApplication::desktop()->width(); 3486 int dw = QApplication::desktop()->width();
3485 int dh = QApplication::desktop()->height(); 3487 int dh = QApplication::desktop()->height();
3486 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3488 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3487 if ( !cp->exec() ) { 3489 if ( !cp->exec() ) {
3488 delete cp; 3490 delete cp;
3489 return; 3491 return;
3490 } 3492 }
3491 int count = 0; 3493 int count = 0;
3492 if ( cp->addCat() ) { 3494 if ( cp->addCat() ) {
3493 count = addCategories(); 3495 count = addCategories();
3494 if ( count ) { 3496 if ( count ) {
3495 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3497 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3496 writeSettings(); 3498 writeSettings();
3497 } else 3499 } else
3498 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3500 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3499 } else { 3501 } else {
3500 removeCategories(); 3502 removeCategories();
3501 updateView(); 3503 updateView();
3502 } 3504 }
3503 delete cp; 3505 delete cp;
3504} 3506}
3505 3507
3506void CalendarView::beamIncidence(Incidence * Inc) 3508void CalendarView::beamIncidence(Incidence * Inc)
3507{ 3509{
3508 QPtrList<Incidence> delSel ; 3510 QPtrList<Incidence> delSel ;
3509 delSel.append(Inc); 3511 delSel.append(Inc);
3510 beamIncidenceList( delSel ); 3512 beamIncidenceList( delSel );
3511} 3513}
3512void CalendarView::beamCalendar() 3514void CalendarView::beamCalendar()
3513{ 3515{
3514 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3516 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3515 //qDebug("beamCalendar() "); 3517 //qDebug("beamCalendar() ");
3516 beamIncidenceList( delSel ); 3518 beamIncidenceList( delSel );
3517} 3519}
3518void CalendarView::beamFilteredCalendar() 3520void CalendarView::beamFilteredCalendar()
3519{ 3521{
3520 QPtrList<Incidence> delSel = mCalendar->incidences(); 3522 QPtrList<Incidence> delSel = mCalendar->incidences();
3521 //qDebug("beamFilteredCalendar() "); 3523 //qDebug("beamFilteredCalendar() ");
3522 beamIncidenceList( delSel ); 3524 beamIncidenceList( delSel );
3523} 3525}
3524void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3526void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3525{ 3527{
3526 3528
3527 KOBeamPrefs beamDialog; 3529 KOBeamPrefs beamDialog;
3528 if ( beamDialog.exec () == QDialog::Rejected ) 3530 if ( beamDialog.exec () == QDialog::Rejected )
3529 return; 3531 return;
3530#ifdef DESKTOP_VERSION 3532#ifdef DESKTOP_VERSION
3531 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3533 QString fn = locateLocal( "tmp", "kopibeamfile" );
3532#else 3534#else
3533 QString fn = "/tmp/kopibeamfile"; 3535 QString fn = "/tmp/kopibeamfile";
3534#endif 3536#endif
3535 QString mes; 3537 QString mes;
3536 bool createbup = true; 3538 bool createbup = true;
3537 if ( createbup ) { 3539 if ( createbup ) {
3538 QString description = "\n"; 3540 QString description = "\n";
3539 CalendarLocal* cal = new CalendarLocal(); 3541 CalendarLocal* cal = new CalendarLocal();
3540 if ( beamDialog.beamLocal() ) 3542 if ( beamDialog.beamLocal() )
3541 cal->setLocalTime(); 3543 cal->setLocalTime();
3542 else 3544 else
3543 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3545 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3544 Incidence *incidence = delSel.first(); 3546 Incidence *incidence = delSel.first();
3545 bool addText = false; 3547 bool addText = false;
3546 if ( delSel.count() < 10 ) 3548 if ( delSel.count() < 10 )
3547 addText = true; 3549 addText = true;
3548 else { 3550 else {
3549 description.sprintf(i18n(" %d items?"),delSel.count() ); 3551 description.sprintf(i18n(" %d items?"),delSel.count() );
3550 } 3552 }
3551 while ( incidence ) { 3553 while ( incidence ) {
3552 Incidence *in = incidence->clone(); 3554 Incidence *in = incidence->clone();
3553 if ( ! in->summary().isEmpty() ) { 3555 if ( ! in->summary().isEmpty() ) {
3554 in->setDescription(""); 3556 in->setDescription("");
3555 } else { 3557 } else {
3556 in->setSummary( in->description().left(20)); 3558 in->setSummary( in->description().left(20));
3557 in->setDescription(""); 3559 in->setDescription("");
3558 } 3560 }
3559 if ( addText ) 3561 if ( addText )
3560 description += in->summary() + "\n"; 3562 description += in->summary() + "\n";
3561 cal->addIncidence( in ); 3563 cal->addIncidence( in );
3562 incidence = delSel.next(); 3564 incidence = delSel.next();
3563 } 3565 }
3564 if ( beamDialog.beamVcal() ) { 3566 if ( beamDialog.beamVcal() ) {
3565 fn += ".vcs"; 3567 fn += ".vcs";
3566 FileStorage storage( cal, fn, new VCalFormat ); 3568 FileStorage storage( cal, fn, new VCalFormat );
3567 storage.save(); 3569 storage.save();
3568 } else { 3570 } else {
3569 fn += ".ics"; 3571 fn += ".ics";
3570 FileStorage storage( cal, fn, new ICalFormat( ) ); 3572 FileStorage storage( cal, fn, new ICalFormat( ) );
3571 storage.save(); 3573 storage.save();
3572 } 3574 }
3573 delete cal; 3575 delete cal;
3574 mes = i18n("KO/Pi: Ready for beaming"); 3576 mes = i18n("KO/Pi: Ready for beaming");
3575 topLevelWidget()->setCaption(mes); 3577 topLevelWidget()->setCaption(mes);
3576 KApplication::convert2latin1( fn ); 3578 KApplication::convert2latin1( fn );
3577#ifndef DESKTOP_VERSION 3579#ifndef DESKTOP_VERSION
3578 Ir *ir = new Ir( this ); 3580 Ir *ir = new Ir( this );
3579 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3581 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3580 ir->send( fn, description, "text/x-vCalendar" ); 3582 ir->send( fn, description, "text/x-vCalendar" );
3581#endif 3583#endif
3582 } 3584 }
3583} 3585}
3584 3586
3585#ifndef DESKTOP_VERSION 3587#ifndef DESKTOP_VERSION
3586void CalendarView::beamDone( Ir *ir ) 3588void CalendarView::beamDone( Ir *ir )
3587{ 3589{
3588 delete ir; 3590 delete ir;
3589 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3591 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3590 topLevelWidget()->raise(); 3592 topLevelWidget()->raise();
3591} 3593}
3592#else 3594#else
3593void CalendarView::beamDone( Ir *){;} 3595void CalendarView::beamDone( Ir *){;}
3594#endif 3596#endif
3595void CalendarView::moveIncidence(Incidence * inc ) 3597void CalendarView::moveIncidence(Incidence * inc )
3596{ 3598{
3597 if ( !inc ) return; 3599 if ( !inc ) return;
3598 showDatePickerPopup(); 3600 showDatePickerPopup();
3599 mDatePickerMode = 2; 3601 mDatePickerMode = 2;
3600 mMoveIncidence = inc ; 3602 mMoveIncidence = inc ;
3601 QDate da; 3603 QDate da;
3602 if ( mMoveIncidence->typeID() == todoID ) { 3604 if ( mMoveIncidence->typeID() == todoID ) {
3603 Todo * to = (Todo *) mMoveIncidence; 3605 Todo * to = (Todo *) mMoveIncidence;
3604 if ( to->hasDueDate() ) 3606 if ( to->hasDueDate() )
3605 da = to->dtDue().date(); 3607 da = to->dtDue().date();
3606 else 3608 else
3607 da = QDate::currentDate(); 3609 da = QDate::currentDate();
3608 } else { 3610 } else {
3609 da = mMoveIncidence->dtStart().date(); 3611 da = mMoveIncidence->dtStart().date();
3610 } 3612 }
3611 //PENDING set date for recurring incidence to date of recurrence 3613 //PENDING set date for recurring incidence to date of recurrence
3612 //mMoveIncidenceOldDate; 3614 //mMoveIncidenceOldDate;
3613 mDatePicker->setDate( da ); 3615 mDatePicker->setDate( da );
3614} 3616}
3615void CalendarView::showDatePickerPopup() 3617void CalendarView::showDatePickerPopup()
3616{ 3618{
3617 if ( mDateFrame->isVisible() ) 3619 if ( mDateFrame->isVisible() )
3618 mDateFrame->hide(); 3620 mDateFrame->hide();
3619 else { 3621 else {
3620 int offX = 0, offY = 0; 3622 int offX = 0, offY = 0;
3621#ifdef DESKTOP_VERSION 3623#ifdef DESKTOP_VERSION
3622 int w =mDatePicker->sizeHint().width() ; 3624 int w =mDatePicker->sizeHint().width() ;
3623 int h = mDatePicker->sizeHint().height() ; 3625 int h = mDatePicker->sizeHint().height() ;
3624 int dw = topLevelWidget()->width(); 3626 int dw = topLevelWidget()->width();
3625 int dh = topLevelWidget()->height(); 3627 int dh = topLevelWidget()->height();
3626 offX = topLevelWidget()->x(); 3628 offX = topLevelWidget()->x();
3627 offY = topLevelWidget()->y(); 3629 offY = topLevelWidget()->y();
3628#else 3630#else
3629 int w =mDatePicker->sizeHint().width() ; 3631 int w =mDatePicker->sizeHint().width() ;
3630 int h = mDatePicker->sizeHint().height() ; 3632 int h = mDatePicker->sizeHint().height() ;
3631 int dw = QApplication::desktop()->width(); 3633 int dw = QApplication::desktop()->width();
3632 int dh = QApplication::desktop()->height(); 3634 int dh = QApplication::desktop()->height();
3633#endif 3635#endif
3634 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3636 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3635 mDateFrame->show(); 3637 mDateFrame->show();
3636 } 3638 }
3637} 3639}
3638void CalendarView::showDatePicker( ) 3640void CalendarView::showDatePicker( )
3639{ 3641{
3640 showDatePickerPopup(); 3642 showDatePickerPopup();
3641 mDatePickerMode = 1; 3643 mDatePickerMode = 1;
3642 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3644 mDatePicker->setDate( mNavigator->selectedDates().first() );
3643} 3645}
3644 3646
3645void CalendarView::showEventEditor() 3647void CalendarView::showEventEditor()
3646{ 3648{
3647#ifdef DESKTOP_VERSION 3649#ifdef DESKTOP_VERSION
3648 int x,y,w,h; 3650 int x,y,w,h;
3649 x = mEventEditor->geometry().x(); 3651 x = mEventEditor->geometry().x();
3650 y = mEventEditor->geometry().y(); 3652 y = mEventEditor->geometry().y();
3651 w = mEventEditor->width(); 3653 w = mEventEditor->width();
3652 h = mEventEditor->height(); 3654 h = mEventEditor->height();
3653 mEventEditor->show(); 3655 mEventEditor->show();
3654 mEventEditor->setGeometry(x,y,w,h); 3656 mEventEditor->setGeometry(x,y,w,h);
3655#else 3657#else
3656 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3658 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3657 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3659 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3658 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3660 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3659 qApp->processEvents(); 3661 qApp->processEvents();
3660 delete mEventEditor; 3662 delete mEventEditor;
3661 mEventEditor = mDialogManager->getEventEditor(); 3663 mEventEditor = mDialogManager->getEventEditor();
3662 topLevelWidget()->setCaption( i18n("") ); 3664 topLevelWidget()->setCaption( i18n("") );
3663 } 3665 }
3664 mEventEditor->showMaximized(); 3666 mEventEditor->showMaximized();
3665#endif 3667#endif
3666} 3668}
3667void CalendarView::showTodoEditor() 3669void CalendarView::showTodoEditor()
3668{ 3670{
3669#ifdef DESKTOP_VERSION 3671#ifdef DESKTOP_VERSION
3670 int x,y,w,h; 3672 int x,y,w,h;
3671 x = mTodoEditor->geometry().x(); 3673 x = mTodoEditor->geometry().x();
3672 y = mTodoEditor->geometry().y(); 3674 y = mTodoEditor->geometry().y();
3673 w = mTodoEditor->width(); 3675 w = mTodoEditor->width();
3674 h = mTodoEditor->height(); 3676 h = mTodoEditor->height();
3675 mTodoEditor->show(); 3677 mTodoEditor->show();
3676 mTodoEditor->setGeometry(x,y,w,h); 3678 mTodoEditor->setGeometry(x,y,w,h);
3677#else 3679#else
3678 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3680 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3679 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3681 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3680 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3682 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3681 qApp->processEvents(); 3683 qApp->processEvents();
3682 delete mTodoEditor; 3684 delete mTodoEditor;
3683 mTodoEditor = mDialogManager->getTodoEditor(); 3685 mTodoEditor = mDialogManager->getTodoEditor();
3684 topLevelWidget()->setCaption( i18n("") ); 3686 topLevelWidget()->setCaption( i18n("") );
3685 } 3687 }
3686 mTodoEditor->showMaximized(); 3688 mTodoEditor->showMaximized();
3687#endif 3689#endif
3688} 3690}
3689 3691
3690void CalendarView::cloneIncidence() 3692void CalendarView::cloneIncidence()
3691{ 3693{
3692 Incidence *incidence = currentSelection(); 3694 Incidence *incidence = currentSelection();
3693 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3695 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3694 if ( incidence ) { 3696 if ( incidence ) {
3695 cloneIncidence(incidence); 3697 cloneIncidence(incidence);
3696 } 3698 }
3697} 3699}
3698void CalendarView::moveIncidence() 3700void CalendarView::moveIncidence()
3699{ 3701{
3700 Incidence *incidence = currentSelection(); 3702 Incidence *incidence = currentSelection();
3701 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3703 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3702 if ( incidence ) { 3704 if ( incidence ) {
3703 moveIncidence(incidence); 3705 moveIncidence(incidence);
3704 } 3706 }
3705} 3707}
3706void CalendarView::beamIncidence() 3708void CalendarView::beamIncidence()
3707{ 3709{
3708 Incidence *incidence = currentSelection(); 3710 Incidence *incidence = currentSelection();
3709 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3711 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3710 if ( incidence ) { 3712 if ( incidence ) {
3711 beamIncidence(incidence); 3713 beamIncidence(incidence);
3712 } 3714 }
3713} 3715}
3714void CalendarView::toggleCancelIncidence() 3716void CalendarView::toggleCancelIncidence()
3715{ 3717{
3716 Incidence *incidence = currentSelection(); 3718 Incidence *incidence = currentSelection();
3717 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3719 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3718 if ( incidence ) { 3720 if ( incidence ) {
3719 cancelIncidence(incidence); 3721 cancelIncidence(incidence);
3720 } 3722 }
3721} 3723}
3722 3724
3723 3725
3724void CalendarView::cancelIncidence(Incidence * inc ) 3726void CalendarView::cancelIncidence(Incidence * inc )
3725{ 3727{
3726 inc->setCancelled( ! inc->cancelled() ); 3728 inc->setCancelled( ! inc->cancelled() );
3727 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3729 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3728 updateView(); 3730 updateView();
3729} 3731}
3730void CalendarView::cloneIncidence(Incidence * orgInc ) 3732void CalendarView::cloneIncidence(Incidence * orgInc )
3731{ 3733{
3732 Incidence * newInc = orgInc->clone(); 3734 Incidence * newInc = orgInc->clone();
3733 newInc->recreate(); 3735 newInc->recreate();
3734 3736
3735 if ( newInc->typeID() == todoID ) { 3737 if ( newInc->typeID() == todoID ) {
3736 Todo* t = (Todo*) newInc; 3738 Todo* t = (Todo*) newInc;
3737 bool cloneSub = false; 3739 bool cloneSub = false;
3738 if ( orgInc->relations().count() ) { 3740 if ( orgInc->relations().count() ) {
3739 int result = KMessageBox::warningYesNoCancel(this, 3741 int result = KMessageBox::warningYesNoCancel(this,
3740 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3742 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3741 i18n("Todo has subtodos"), 3743 i18n("Todo has subtodos"),
3742 i18n("Yes"), 3744 i18n("Yes"),
3743 i18n("No")); 3745 i18n("No"));
3744 3746
3745 if ( result == KMessageBox::Cancel ) { 3747 if ( result == KMessageBox::Cancel ) {
3746 delete t; 3748 delete t;
3747 return; 3749 return;
3748 } 3750 }
3749 if (result == KMessageBox::Yes) cloneSub = true; 3751 if (result == KMessageBox::Yes) cloneSub = true;
3750 } 3752 }
3751 showTodoEditor(); 3753 showTodoEditor();
3752 mTodoEditor->editTodo( t ); 3754 mTodoEditor->editTodo( t );
3753 if ( mTodoEditor->exec() ) { 3755 if ( mTodoEditor->exec() ) {
3754 if ( cloneSub ) { 3756 if ( cloneSub ) {
3755 orgInc->cloneRelations( t ); 3757 orgInc->cloneRelations( t );
3756 mCalendar->addIncidenceBranch( t ); 3758 mCalendar->addIncidenceBranch( t );
3757 updateView(); 3759 updateView();
3758 3760
3759 } else { 3761 } else {
3760 mCalendar->addTodo( t ); 3762 mCalendar->addTodo( t );
3761 updateView(); 3763 updateView();
3762 } 3764 }
3763 } else { 3765 } else {
3764 delete t; 3766 delete t;
3765 } 3767 }
3766 } 3768 }
3767 else if ( newInc->typeID() == eventID ) { 3769 else if ( newInc->typeID() == eventID ) {
3768 Event* e = (Event*) newInc; 3770 Event* e = (Event*) newInc;
3769 showEventEditor(); 3771 showEventEditor();
3770 mEventEditor->editEvent( e ); 3772 mEventEditor->editEvent( e );
3771 if ( mEventEditor->exec() ) { 3773 if ( mEventEditor->exec() ) {
3772 mCalendar->addEvent( e ); 3774 mCalendar->addEvent( e );
3773 updateView(); 3775 updateView();
3774 } else { 3776 } else {
3775 delete e; 3777 delete e;
3776 } 3778 }
3777 } else if ( newInc->typeID() == journalID ) { 3779 } else if ( newInc->typeID() == journalID ) {
3778 mCalendar->addJournal( (Journal*) newInc ); 3780 mCalendar->addJournal( (Journal*) newInc );
3779 editJournal( (Journal*) newInc ); 3781 editJournal( (Journal*) newInc );
3780 } 3782 }
3781 setActiveWindow(); 3783 setActiveWindow();
3782} 3784}
3783 3785
3784void CalendarView::newEvent() 3786void CalendarView::newEvent()
3785{ 3787{
3786 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3788 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3787 KOAgendaView *aView = mViewManager->agendaView(); 3789 KOAgendaView *aView = mViewManager->agendaView();
3788 if (aView) { 3790 if (aView) {
3789 if (aView->selectionStart().isValid()) { 3791 if (aView->selectionStart().isValid()) {
3790 if (aView->selectedIsAllDay()) { 3792 if (aView->selectedIsAllDay()) {
3791 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3793 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3792 } else { 3794 } else {
3793 newEvent(aView->selectionStart(),aView->selectionEnd()); 3795 newEvent(aView->selectionStart(),aView->selectionEnd());
3794 } 3796 }
3795 return; 3797 return;
3796 } 3798 }
3797 } 3799 }
3798 3800
3799 QDate date = mNavigator->selectedDates().first(); 3801 QDate date = mNavigator->selectedDates().first();
3800#if 0 3802#if 0
3801 QDateTime current = QDateTime::currentDateTime(); 3803 QDateTime current = QDateTime::currentDateTime();
3802 if ( date <= current.date() ) { 3804 if ( date <= current.date() ) {
3803 int hour = current.time().hour() +1; 3805 int hour = current.time().hour() +1;
3804 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3806 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3805 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3807 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3806 } else 3808 } else
3807#endif 3809#endif
3808 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3810 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3809 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3811 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3810 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3812 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3811} 3813}
3812 3814
3813void CalendarView::newEvent(QDateTime fh) 3815void CalendarView::newEvent(QDateTime fh)
3814{ 3816{
3815 newEvent(fh, 3817 newEvent(fh,
3816 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3818 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3817} 3819}
3818 3820
3819void CalendarView::newEvent(QDate dt) 3821void CalendarView::newEvent(QDate dt)
3820{ 3822{
3821 newEvent(QDateTime(dt, QTime(0,0,0)), 3823 newEvent(QDateTime(dt, QTime(0,0,0)),
3822 QDateTime(dt, QTime(0,0,0)), true); 3824 QDateTime(dt, QTime(0,0,0)), true);
3823} 3825}
3824void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3826void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3825{ 3827{
3826 newEvent(fromHint, toHint, false); 3828 newEvent(fromHint, toHint, false);
3827} 3829}
3828void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3830void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3829{ 3831{
3830 3832
3831 showEventEditor(); 3833 showEventEditor();
3832 mEventEditor->newEvent(fromHint,toHint,allDay); 3834 mEventEditor->newEvent(fromHint,toHint,allDay);
3833 if ( mFilterView->filtersEnabled() ) { 3835 if ( mFilterView->filtersEnabled() ) {
3834 CalFilter *filter = mFilterView->selectedFilter(); 3836 CalFilter *filter = mFilterView->selectedFilter();
3835 if (filter && filter->showCategories()) { 3837 if (filter && filter->showCategories()) {
3836 mEventEditor->setCategories(filter->categoryList().join(",") ); 3838 mEventEditor->setCategories(filter->categoryList().join(",") );
3837 } 3839 }
3838 if ( filter ) 3840 if ( filter )
3839 mEventEditor->setSecrecy( filter->getSecrecy() ); 3841 mEventEditor->setSecrecy( filter->getSecrecy() );
3840 } 3842 }
3841 mEventEditor->exec(); 3843 mEventEditor->exec();
3842 setActiveWindow(); 3844 setActiveWindow();
3843} 3845}
3844void CalendarView::todoAdded(Todo * t) 3846void CalendarView::todoAdded(Todo * t)
3845{ 3847{
3846 3848
3847 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3849 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3848 updateTodoViews(); 3850 updateTodoViews();
3849} 3851}
3850void CalendarView::todoChanged(Todo * t) 3852void CalendarView::todoChanged(Todo * t)
3851{ 3853{
3852 emit todoModified( t, 4 ); 3854 emit todoModified( t, 4 );
3853 // updateTodoViews(); 3855 // updateTodoViews();
3854} 3856}
3855void CalendarView::todoToBeDeleted(Todo *) 3857void CalendarView::todoToBeDeleted(Todo *)
3856{ 3858{
3857 //qDebug("todoToBeDeleted(Todo *) "); 3859 //qDebug("todoToBeDeleted(Todo *) ");
3858 updateTodoViews(); 3860 updateTodoViews();
3859} 3861}
3860void CalendarView::todoDeleted() 3862void CalendarView::todoDeleted()
3861{ 3863{
3862 //qDebug(" todoDeleted()"); 3864 //qDebug(" todoDeleted()");
3863 updateTodoViews(); 3865 updateTodoViews();
3864} 3866}
3865 3867
3866 3868
3867void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3869void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3868{ 3870{
3869 showTodoEditor(); 3871 showTodoEditor();
3870 mTodoEditor->newTodo(dt,0,allday); 3872 mTodoEditor->newTodo(dt,0,allday);
3871 if ( mFilterView->filtersEnabled() ) { 3873 if ( mFilterView->filtersEnabled() ) {
3872 CalFilter *filter = mFilterView->selectedFilter(); 3874 CalFilter *filter = mFilterView->selectedFilter();
3873 if (filter && filter->showCategories()) { 3875 if (filter && filter->showCategories()) {
3874 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3876 mTodoEditor->setCategories(filter->categoryList().join(",") );
3875 } 3877 }
3876 if ( filter ) 3878 if ( filter )
3877 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3879 mTodoEditor->setSecrecy( filter->getSecrecy() );
3878 } 3880 }
3879 mTodoEditor->exec(); 3881 mTodoEditor->exec();
3880 setActiveWindow(); 3882 setActiveWindow();
3881} 3883}
3882 3884
3883void CalendarView::newTodo() 3885void CalendarView::newTodo()
3884{ 3886{
3885 newTodoDateTime( QDateTime(),true ); 3887 newTodoDateTime( QDateTime(),true );
3886} 3888}
3887 3889
3888void CalendarView::newSubTodo() 3890void CalendarView::newSubTodo()
3889{ 3891{
3890 Todo *todo = selectedTodo(); 3892 Todo *todo = selectedTodo();
3891 if ( todo ) newSubTodo( todo ); 3893 if ( todo ) newSubTodo( todo );
3892} 3894}
3893 3895
3894void CalendarView::newSubTodo(Todo *parentEvent) 3896void CalendarView::newSubTodo(Todo *parentEvent)
3895{ 3897{
3896 3898
3897 showTodoEditor(); 3899 showTodoEditor();
3898 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3900 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3899 mTodoEditor->exec(); 3901 mTodoEditor->exec();
3900 setActiveWindow(); 3902 setActiveWindow();
3901} 3903}
3902 3904
3903void CalendarView::newFloatingEvent() 3905void CalendarView::newFloatingEvent()
3904{ 3906{
3905 DateList tmpList = mNavigator->selectedDates(); 3907 DateList tmpList = mNavigator->selectedDates();
3906 QDate date = tmpList.first(); 3908 QDate date = tmpList.first();
3907 3909
3908 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3910 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3909 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3911 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3910} 3912}
3911 3913
3912 3914
3913void CalendarView::editEvent( Event *event ) 3915void CalendarView::editEvent( Event *event )
3914{ 3916{
3915 3917
3916 if ( !event ) return; 3918 if ( !event ) return;
3917 if ( event->isReadOnly() ) { 3919 if ( event->isReadOnly() ) {
3918 showEvent( event ); 3920 showEvent( event );
3919 return; 3921 return;
3920 } 3922 }
3921 showEventEditor(); 3923 showEventEditor();
3922 mEventEditor->editEvent( event , mFlagEditDescription); 3924 mEventEditor->editEvent( event , mFlagEditDescription);
3923 mEventEditor->exec(); 3925 mEventEditor->exec();
3924 setActiveWindow(); 3926 setActiveWindow();
3925 3927
3926} 3928}
3927void CalendarView::editJournal( Journal *jour ) 3929void CalendarView::editJournal( Journal *jour )
3928{ 3930{
3929 if ( !jour ) return; 3931 if ( !jour ) return;
3930 mDialogManager->hideSearchDialog(); 3932 mDialogManager->hideSearchDialog();
3931 mViewManager->showJournalView(); 3933 mViewManager->showJournalView();
3932 mNavigator->slotDaySelect( jour->dtStart().date() ); 3934 mNavigator->slotDaySelect( jour->dtStart().date() );
3933} 3935}
3934void CalendarView::editTodo( Todo *todo ) 3936void CalendarView::editTodo( Todo *todo )
3935{ 3937{
3936 if ( !todo ) return; 3938 if ( !todo ) return;
3937 3939
3938 if ( todo->isReadOnly() ) { 3940 if ( todo->isReadOnly() ) {
3939 showTodo( todo ); 3941 showTodo( todo );
3940 return; 3942 return;
3941 } 3943 }
3942 showTodoEditor(); 3944 showTodoEditor();
3943 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3945 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3944 mTodoEditor->exec(); 3946 mTodoEditor->exec();
3945 setActiveWindow(); 3947 setActiveWindow();
3946 3948
3947} 3949}
3948 3950
3949KOEventViewerDialog* CalendarView::getEventViewerDialog() 3951KOEventViewerDialog* CalendarView::getEventViewerDialog()
3950{ 3952{
3951 if ( !mEventViewerDialog ) { 3953 if ( !mEventViewerDialog ) {
3952 mEventViewerDialog = new KOEventViewerDialog(0); 3954 mEventViewerDialog = new KOEventViewerDialog(0);
3953 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3955 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3954 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3956 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3955 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3957 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3956 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3958 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3957 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3959 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3958 viewManager(), SLOT( showAgendaView( bool ) ) ); 3960 viewManager(), SLOT( showAgendaView( bool ) ) );
3959 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3961 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3960 this, SLOT( slotViewerClosed() ) ); 3962 this, SLOT( slotViewerClosed() ) );
3961 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3963 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3962 this, SLOT( todoChanged(Todo *) ) ); 3964 this, SLOT( todoChanged(Todo *) ) );
3963 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3965 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3964 mEventViewerDialog->resize( 640, 480 ); 3966 mEventViewerDialog->resize( 640, 480 );
3965 3967
3966 } 3968 }
3967 return mEventViewerDialog; 3969 return mEventViewerDialog;
3968} 3970}
3969void CalendarView::showEvent(Event *event) 3971void CalendarView::showEvent(Event *event)
3970{ 3972{
3971 getEventViewerDialog()->setEvent(event); 3973 getEventViewerDialog()->setEvent(event);
3972 getEventViewerDialog()->showMe(); 3974 getEventViewerDialog()->showMe();
3973} 3975}
3974 3976
3975void CalendarView::showTodo(Todo *event) 3977void CalendarView::showTodo(Todo *event)
3976{ 3978{
3977 getEventViewerDialog()->setTodo(event); 3979 getEventViewerDialog()->setTodo(event);
3978 getEventViewerDialog()->showMe(); 3980 getEventViewerDialog()->showMe();
3979} 3981}
3980void CalendarView::showJournal( Journal *jour ) 3982void CalendarView::showJournal( Journal *jour )
3981{ 3983{
3982 getEventViewerDialog()->setJournal(jour); 3984 getEventViewerDialog()->setJournal(jour);
3983 getEventViewerDialog()->showMe(); 3985 getEventViewerDialog()->showMe();
3984 3986
3985} 3987}
3986// void CalendarView::todoModified (Todo *event, int changed) 3988// void CalendarView::todoModified (Todo *event, int changed)
3987// { 3989// {
3988// // if (mDialogList.find (event) != mDialogList.end ()) { 3990// // if (mDialogList.find (event) != mDialogList.end ()) {
3989// // kdDebug() << "Todo modified and open" << endl; 3991// // kdDebug() << "Todo modified and open" << endl;
3990// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3992// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3991// // temp->modified (changed); 3993// // temp->modified (changed);
3992 3994
3993// // } 3995// // }
3994 3996
3995// mViewManager->updateView(); 3997// mViewManager->updateView();
3996// } 3998// }
3997 3999
3998void CalendarView::appointment_show() 4000void CalendarView::appointment_show()
3999{ 4001{
4000 Event *anEvent = 0; 4002 Event *anEvent = 0;
4001 4003
4002 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 4004 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
4003 4005
4004 if (mViewManager->currentView()->isEventView()) { 4006 if (mViewManager->currentView()->isEventView()) {
4005 if ( incidence && incidence->typeID() == eventID ) { 4007 if ( incidence && incidence->typeID() == eventID ) {
4006 anEvent = static_cast<Event *>(incidence); 4008 anEvent = static_cast<Event *>(incidence);
4007 } 4009 }
4008 } 4010 }
4009 4011
4010 if (!anEvent) { 4012 if (!anEvent) {
4011 KNotifyClient::beep(); 4013 KNotifyClient::beep();
4012 return; 4014 return;
4013 } 4015 }
4014 4016
4015 showEvent(anEvent); 4017 showEvent(anEvent);
4016} 4018}
4017 4019
4018void CalendarView::appointment_edit() 4020void CalendarView::appointment_edit()
4019{ 4021{
4020 Event *anEvent = 0; 4022 Event *anEvent = 0;
4021 4023
4022 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 4024 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
4023 4025
4024 if (mViewManager->currentView()->isEventView()) { 4026 if (mViewManager->currentView()->isEventView()) {
4025 if ( incidence && incidence->typeID() == eventID ) { 4027 if ( incidence && incidence->typeID() == eventID ) {
4026 anEvent = static_cast<Event *>(incidence); 4028 anEvent = static_cast<Event *>(incidence);
4027 } 4029 }
4028 } 4030 }
4029 4031
4030 if (!anEvent) { 4032 if (!anEvent) {
4031 KNotifyClient::beep(); 4033 KNotifyClient::beep();
4032 return; 4034 return;
4033 } 4035 }
4034 4036
4035 editEvent(anEvent); 4037 editEvent(anEvent);
4036} 4038}
4037 4039
4038void CalendarView::appointment_delete() 4040void CalendarView::appointment_delete()
4039{ 4041{
4040 Event *anEvent = 0; 4042 Event *anEvent = 0;
4041 4043
4042 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 4044 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
4043 4045
4044 if (mViewManager->currentView()->isEventView()) { 4046 if (mViewManager->currentView()->isEventView()) {
4045 if ( incidence && incidence->typeID() == eventID ) { 4047 if ( incidence && incidence->typeID() == eventID ) {
4046 anEvent = static_cast<Event *>(incidence); 4048 anEvent = static_cast<Event *>(incidence);
4047 } 4049 }
4048 } 4050 }
4049 4051
4050 if (!anEvent) { 4052 if (!anEvent) {
4051 KNotifyClient::beep(); 4053 KNotifyClient::beep();
4052 return; 4054 return;
4053 } 4055 }
4054 4056
4055 deleteEvent(anEvent); 4057 deleteEvent(anEvent);
4056} 4058}
4057 4059
4058void CalendarView::todo_resub( Todo * parent, Todo * sub ) 4060void CalendarView::todo_resub( Todo * parent, Todo * sub )
4059{ 4061{
4060 if (!sub) return; 4062 if (!sub) return;
4061 if ( sub->relatedTo() == parent ) 4063 if ( sub->relatedTo() == parent )
4062 return; 4064 return;
4063 sub->setRelatedTo(parent); 4065 sub->setRelatedTo(parent);
4064 sub->updated(); 4066 sub->updated();
4065 setModified(true); 4067 setModified(true);
4066 updateView(); 4068 updateView();
4067} 4069}
4068void CalendarView::todo_unsub(Todo *anTodo ) 4070void CalendarView::todo_unsub(Todo *anTodo )
4069{ 4071{
4070 todo_resub( 0, anTodo ); 4072 todo_resub( 0, anTodo );
4071} 4073}
4072 4074
4073void CalendarView::deleteTodo(Todo *todo) 4075void CalendarView::deleteTodo(Todo *todo)
4074{ 4076{
4075 if (!todo) { 4077 if (!todo) {
4076 KNotifyClient::beep(); 4078 KNotifyClient::beep();
4077 return; 4079 return;
4078 } 4080 }
4079 if (KOPrefs::instance()->mConfirm) { 4081 if (KOPrefs::instance()->mConfirm) {
4080 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 4082 QString text = KGlobal::formatMessage ( todo->summary(),0 );
4081 if (!todo->relations().isEmpty()) { 4083 if (!todo->relations().isEmpty()) {
4082 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 4084 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
4083 4085
4084 } 4086 }
4085 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 4087 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
4086 case KMessageBox::Continue: // OK 4088 case KMessageBox::Continue: // OK
4087 bool deleteT = false; 4089 bool deleteT = false;
4088 if (!todo->relations().isEmpty()) { 4090 if (!todo->relations().isEmpty()) {
4089 deleteT = removeCompletedSubTodos( todo ); 4091 deleteT = removeCompletedSubTodos( todo );
4090 } 4092 }
4091 // deleteT == true: todo already deleted in removeCompletedSubTodos 4093 // deleteT == true: todo already deleted in removeCompletedSubTodos
4092 if ( !deleteT ) { 4094 if ( !deleteT ) {
4093 checkExternalId( todo ); 4095 checkExternalId( todo );
4094 calendar()->deleteTodo(todo); 4096 calendar()->deleteTodo(todo);
4095 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 4097 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
4096 } 4098 }
4097 updateView(); 4099 updateView();
4098 break; 4100 break;
4099 } // switch 4101 } // switch
4100 } else { 4102 } else {
4101 checkExternalId( todo ); 4103 checkExternalId( todo );
4102 mCalendar->deleteTodo(todo); 4104 mCalendar->deleteTodo(todo);
4103 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 4105 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
4104 updateView(); 4106 updateView();
4105 } 4107 }
4106 4108
4107 emit updateSearchDialog(); 4109 emit updateSearchDialog();
4108} 4110}
4109void CalendarView::deleteJournal(Journal *jour) 4111void CalendarView::deleteJournal(Journal *jour)
4110{ 4112{
4111 if (!jour) { 4113 if (!jour) {
4112 KNotifyClient::beep(); 4114 KNotifyClient::beep();
4113 return; 4115 return;
4114 } 4116 }
4115 if (KOPrefs::instance()->mConfirm) { 4117 if (KOPrefs::instance()->mConfirm) {
4116 4118
4117 QString des; 4119 QString des;
4118 if ( !jour->summary().isEmpty() ) { 4120 if ( !jour->summary().isEmpty() ) {
4119 des = jour->summary(); 4121 des = jour->summary();
4120 } else { 4122 } else {
4121 des = jour->description().left(30); 4123 des = jour->description().left(30);
4122 des = des.simplifyWhiteSpace (); 4124 des = des.simplifyWhiteSpace ();
4123 des.replace (QRegExp ("\\n"),"" ); 4125 des.replace (QRegExp ("\\n"),"" );
4124 des.replace (QRegExp ("\\r"),"" ); 4126 des.replace (QRegExp ("\\r"),"" );
4125 } 4127 }
4126 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 4128 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
4127 case KMessageBox::Continue: // OK 4129 case KMessageBox::Continue: // OK
4128 calendar()->deleteJournal(jour); 4130 calendar()->deleteJournal(jour);
4129 updateView(); 4131 updateView();
4130 break; 4132 break;
4131 } // switch 4133 } // switch
4132 } else { 4134 } else {
4133 calendar()->deleteJournal(jour);; 4135 calendar()->deleteJournal(jour);;
4134 updateView(); 4136 updateView();
4135 } 4137 }
4136 emit updateSearchDialog(); 4138 emit updateSearchDialog();
4137} 4139}
4138 4140
4139void CalendarView::deleteEvent(Event *anEvent) 4141void CalendarView::deleteEvent(Event *anEvent)
4140{ 4142{
4141 if (!anEvent) { 4143 if (!anEvent) {
4142 KNotifyClient::beep(); 4144 KNotifyClient::beep();
4143 return; 4145 return;
4144 } 4146 }
4145 4147
4146 if (anEvent->doesRecur()) { 4148 if (anEvent->doesRecur()) {
4147 QDate itemDate = mViewManager->currentSelectionDate(); 4149 QDate itemDate = mViewManager->currentSelectionDate();
4148 int km; 4150 int km;
4149 if (!itemDate.isValid()) { 4151 if (!itemDate.isValid()) {
4150 //kdDebug() << "Date Not Valid" << endl; 4152 //kdDebug() << "Date Not Valid" << endl;
4151 if (KOPrefs::instance()->mConfirm) { 4153 if (KOPrefs::instance()->mConfirm) {
4152 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 4154 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
4153 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 4155 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
4154 i18n("KO/Pi Confirmation"),i18n("Delete All")); 4156 i18n("KO/Pi Confirmation"),i18n("Delete All"));
4155 if ( km == KMessageBox::Continue ) 4157 if ( km == KMessageBox::Continue )
4156 km = KMessageBox::No; // No = all below 4158 km = KMessageBox::No; // No = all below
4157 } else 4159 } else
4158 km = KMessageBox::No; 4160 km = KMessageBox::No;
4159 } else { 4161 } else {
4160 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 4162 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
4161 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 4163 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
4162 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 4164 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
4163 i18n("KO/Pi Confirmation"),i18n("Current"), 4165 i18n("KO/Pi Confirmation"),i18n("Current"),
4164 i18n("All")); 4166 i18n("All"));
4165 } 4167 }
4166 switch(km) { 4168 switch(km) {
4167 4169
4168 case KMessageBox::No: // Continue // all 4170 case KMessageBox::No: // Continue // all
4169 //qDebug("KMessageBox::No "); 4171 //qDebug("KMessageBox::No ");
4170 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 4172 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
4171 schedule(Scheduler::Cancel,anEvent); 4173 schedule(Scheduler::Cancel,anEvent);
4172 4174
4173 checkExternalId( anEvent); 4175 checkExternalId( anEvent);
4174 mCalendar->deleteEvent(anEvent); 4176 mCalendar->deleteEvent(anEvent);
4175 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 4177 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
4176 break; 4178 break;
4177 4179
4178 // Disabled because it does not work 4180 // Disabled because it does not work
4179 //#if 0 4181 //#if 0
4180 case KMessageBox::Yes: // just this one 4182 case KMessageBox::Yes: // just this one
4181 //QDate qd = mNavigator->selectedDates().first(); 4183 //QDate qd = mNavigator->selectedDates().first();
4182 //if (!qd.isValid()) { 4184 //if (!qd.isValid()) {
4183 // kdDebug() << "no date selected, or invalid date" << endl; 4185 // kdDebug() << "no date selected, or invalid date" << endl;
4184 // KNotifyClient::beep(); 4186 // KNotifyClient::beep();
4185 // return; 4187 // return;
4186 //} 4188 //}
4187 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 4189 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
4188 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 4190 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
4189 anEvent->addExDate(itemDate); 4191 anEvent->addExDate(itemDate);
4190 int duration = anEvent->recurrence()->duration(); 4192 int duration = anEvent->recurrence()->duration();
4191 if ( duration > 0 ) { 4193 if ( duration > 0 ) {
4192 anEvent->recurrence()->setDuration( duration - 1 ); 4194 anEvent->recurrence()->setDuration( duration - 1 );
4193 } 4195 }
4194 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 4196 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
4195 } 4197 }
4196 break; 4198 break;
4197 //#endif 4199 //#endif
4198 } // switch 4200 } // switch
4199 } else { 4201 } else {
4200 if (KOPrefs::instance()->mConfirm) { 4202 if (KOPrefs::instance()->mConfirm) {
4201 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 4203 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
4202 i18n("\nAre you sure you want\nto delete this event?"), 4204 i18n("\nAre you sure you want\nto delete this event?"),
4203 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 4205 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
4204 case KMessageBox::Continue: // OK 4206 case KMessageBox::Continue: // OK
4205 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 4207 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
4206 schedule(Scheduler::Cancel,anEvent); 4208 schedule(Scheduler::Cancel,anEvent);
4207 checkExternalId( anEvent); 4209 checkExternalId( anEvent);
4208 mCalendar->deleteEvent(anEvent); 4210 mCalendar->deleteEvent(anEvent);
4209 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 4211 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
4210 break; 4212 break;
4211 } // switch 4213 } // switch
4212 } else { 4214 } else {
4213 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 4215 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
4214 schedule(Scheduler::Cancel,anEvent); 4216 schedule(Scheduler::Cancel,anEvent);
4215 checkExternalId( anEvent); 4217 checkExternalId( anEvent);
4216 mCalendar->deleteEvent(anEvent); 4218 mCalendar->deleteEvent(anEvent);
4217 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 4219 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
4218 } 4220 }
4219 } // if-else 4221 } // if-else
4220 emit updateSearchDialog(); 4222 emit updateSearchDialog();
4221} 4223}
4222 4224
4223bool CalendarView::deleteEvent(const QString &uid) 4225bool CalendarView::deleteEvent(const QString &uid)
4224{ 4226{
4225 Event *ev = mCalendar->event(uid); 4227 Event *ev = mCalendar->event(uid);
4226 if (ev) { 4228 if (ev) {
4227 deleteEvent(ev); 4229 deleteEvent(ev);
4228 return true; 4230 return true;
4229 } else { 4231 } else {
4230 return false; 4232 return false;
4231 } 4233 }
4232} 4234}
4233 4235
4234/*****************************************************************************/ 4236/*****************************************************************************/
4235 4237
4236void CalendarView::action_mail() 4238void CalendarView::action_mail()
4237{ 4239{
4238#ifndef KORG_NOMAIL 4240#ifndef KORG_NOMAIL
4239 KOMailClient mailClient; 4241 KOMailClient mailClient;
4240 4242
4241 Incidence *incidence = currentSelection(); 4243 Incidence *incidence = currentSelection();
4242 4244
4243 if (!incidence) { 4245 if (!incidence) {
4244 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 4246 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
4245 return; 4247 return;
4246 } 4248 }
4247 if(incidence->attendeeCount() == 0 ) { 4249 if(incidence->attendeeCount() == 0 ) {
4248 KMessageBox::sorry(this, 4250 KMessageBox::sorry(this,
4249 i18n("Can't generate mail:\nNo attendees defined.\n")); 4251 i18n("Can't generate mail:\nNo attendees defined.\n"));
4250 return; 4252 return;
4251 } 4253 }
4252 4254
4253 CalendarLocal cal_tmp; 4255 CalendarLocal cal_tmp;
4254 Event *event = 0; 4256 Event *event = 0;
4255 Event *ev = 0; 4257 Event *ev = 0;
4256 if ( incidence && incidence->typeID() == eventID ) { 4258 if ( incidence && incidence->typeID() == eventID ) {
4257 event = static_cast<Event *>(incidence); 4259 event = static_cast<Event *>(incidence);
4258 ev = new Event(*event); 4260 ev = new Event(*event);
4259 cal_tmp.addEvent(ev); 4261 cal_tmp.addEvent(ev);
4260 } 4262 }
4261 ICalFormat mForm(); 4263 ICalFormat mForm();
4262 QString attachment = mForm.toString( &cal_tmp ); 4264 QString attachment = mForm.toString( &cal_tmp );
4263 if (ev) delete(ev); 4265 if (ev) delete(ev);
4264 4266
4265 mailClient.mailAttendees(currentSelection(), attachment); 4267 mailClient.mailAttendees(currentSelection(), attachment);
4266 4268
4267#endif 4269#endif
4268 4270
4269#if 0 4271#if 0
4270 Event *anEvent = 0; 4272 Event *anEvent = 0;
4271 if (mViewManager->currentView()->isEventView()) { 4273 if (mViewManager->currentView()->isEventView()) {
4272 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 4274 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
4273 } 4275 }
4274 4276
4275 if (!anEvent) { 4277 if (!anEvent) {
4276 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 4278 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
4277 return; 4279 return;
4278 } 4280 }
4279 if(anEvent->attendeeCount() == 0 ) { 4281 if(anEvent->attendeeCount() == 0 ) {
4280 KMessageBox::sorry(this, 4282 KMessageBox::sorry(this,
4281 i18n("Can't generate mail:\nNo attendees defined.\n")); 4283 i18n("Can't generate mail:\nNo attendees defined.\n"));
4282 return; 4284 return;
4283 } 4285 }
4284 4286
4285 mailobject.emailEvent(anEvent); 4287 mailobject.emailEvent(anEvent);
4286#endif 4288#endif
4287} 4289}
4288 4290
4289 4291
4290void CalendarView::schedule_publish(Incidence *incidence) 4292void CalendarView::schedule_publish(Incidence *incidence)
4291{ 4293{
4292 Event *event = 0; 4294 Event *event = 0;
4293 Todo *todo = 0; 4295 Todo *todo = 0;
4294 4296
4295 if (incidence == 0) { 4297 if (incidence == 0) {
4296 incidence = mViewManager->currentView()->selectedIncidences().first(); 4298 incidence = mViewManager->currentView()->selectedIncidences().first();
4297 if (incidence == 0) { 4299 if (incidence == 0) {
4298 incidence = mTodoList->selectedIncidences().first(); 4300 incidence = mTodoList->selectedIncidences().first();
4299 } 4301 }
4300 } 4302 }
4301 if ( incidence && incidence->typeID() == eventID ) { 4303 if ( incidence && incidence->typeID() == eventID ) {
4302 event = static_cast<Event *>(incidence); 4304 event = static_cast<Event *>(incidence);
4303 } else { 4305 } else {
4304 if ( incidence && incidence->typeID() == todoID ) { 4306 if ( incidence && incidence->typeID() == todoID ) {
4305 todo = static_cast<Todo *>(incidence); 4307 todo = static_cast<Todo *>(incidence);
4306 } 4308 }
4307 } 4309 }
4308 4310
4309 if (!event && !todo) { 4311 if (!event && !todo) {
4310 KMessageBox::sorry(this,i18n("No event selected.")); 4312 KMessageBox::sorry(this,i18n("No event selected."));
4311 return; 4313 return;
4312 } 4314 }
4313 4315
4314 PublishDialog *publishdlg = new PublishDialog(); 4316 PublishDialog *publishdlg = new PublishDialog();
4315 if (incidence->attendeeCount()>0) { 4317 if (incidence->attendeeCount()>0) {
4316 QPtrList<Attendee> attendees = incidence->attendees(); 4318 QPtrList<Attendee> attendees = incidence->attendees();
4317 attendees.first(); 4319 attendees.first();
4318 while ( attendees.current()!=0 ) { 4320 while ( attendees.current()!=0 ) {
4319 publishdlg->addAttendee(attendees.current()); 4321 publishdlg->addAttendee(attendees.current());
4320 attendees.next(); 4322 attendees.next();
4321 } 4323 }
4322 } 4324 }
4323 bool send = true; 4325 bool send = true;
4324 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 4326 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
4325 if ( publishdlg->exec() != QDialog::Accepted ) 4327 if ( publishdlg->exec() != QDialog::Accepted )
4326 send = false; 4328 send = false;
4327 } 4329 }
4328 if ( send ) { 4330 if ( send ) {
4329 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4331 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4330 if ( event ) { 4332 if ( event ) {
4331 Event *ev = new Event(*event); 4333 Event *ev = new Event(*event);
4332 ev->registerObserver(0); 4334 ev->registerObserver(0);
4333 ev->clearAttendees(); 4335 ev->clearAttendees();
4334 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 4336 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
4335 delete(ev); 4337 delete(ev);
4336 } 4338 }
4337 } else { 4339 } else {
4338 if ( todo ) { 4340 if ( todo ) {
4339 Todo *ev = new Todo(*todo); 4341 Todo *ev = new Todo(*todo);
4340 ev->registerObserver(0); 4342 ev->registerObserver(0);
4341 ev->clearAttendees(); 4343 ev->clearAttendees();
4342 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 4344 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
4343 delete(ev); 4345 delete(ev);
4344 } 4346 }
4345 } 4347 }
4346 } 4348 }
4347 } 4349 }
4348 delete publishdlg; 4350 delete publishdlg;
4349} 4351}
4350 4352
4351void CalendarView::schedule_request(Incidence *incidence) 4353void CalendarView::schedule_request(Incidence *incidence)
4352{ 4354{
4353 schedule(Scheduler::Request,incidence); 4355 schedule(Scheduler::Request,incidence);
4354} 4356}
4355 4357
4356void CalendarView::schedule_refresh(Incidence *incidence) 4358void CalendarView::schedule_refresh(Incidence *incidence)
4357{ 4359{
4358 schedule(Scheduler::Refresh,incidence); 4360 schedule(Scheduler::Refresh,incidence);
4359} 4361}
4360 4362
4361void CalendarView::schedule_cancel(Incidence *incidence) 4363void CalendarView::schedule_cancel(Incidence *incidence)
4362{ 4364{
4363 schedule(Scheduler::Cancel,incidence); 4365 schedule(Scheduler::Cancel,incidence);
4364} 4366}
4365 4367
4366void CalendarView::schedule_add(Incidence *incidence) 4368void CalendarView::schedule_add(Incidence *incidence)
4367{ 4369{
4368 schedule(Scheduler::Add,incidence); 4370 schedule(Scheduler::Add,incidence);
4369} 4371}
4370 4372
4371void CalendarView::schedule_reply(Incidence *incidence) 4373void CalendarView::schedule_reply(Incidence *incidence)
4372{ 4374{
4373 schedule(Scheduler::Reply,incidence); 4375 schedule(Scheduler::Reply,incidence);
4374} 4376}
4375 4377
4376void CalendarView::schedule_counter(Incidence *incidence) 4378void CalendarView::schedule_counter(Incidence *incidence)
4377{ 4379{
4378 schedule(Scheduler::Counter,incidence); 4380 schedule(Scheduler::Counter,incidence);
4379} 4381}
4380 4382
4381void CalendarView::schedule_declinecounter(Incidence *incidence) 4383void CalendarView::schedule_declinecounter(Incidence *incidence)
4382{ 4384{
4383 schedule(Scheduler::Declinecounter,incidence); 4385 schedule(Scheduler::Declinecounter,incidence);
4384} 4386}
4385 4387
4386void CalendarView::schedule_publish_freebusy(int daysToPublish) 4388void CalendarView::schedule_publish_freebusy(int daysToPublish)
4387{ 4389{
4388 QDateTime start = QDateTime::currentDateTime(); 4390 QDateTime start = QDateTime::currentDateTime();
4389 QDateTime end = start.addDays(daysToPublish); 4391 QDateTime end = start.addDays(daysToPublish);
4390 4392
4391 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 4393 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
4392 freebusy->setOrganizer(KOPrefs::instance()->email()); 4394 freebusy->setOrganizer(KOPrefs::instance()->email());
4393 4395
4394 4396
4395 PublishDialog *publishdlg = new PublishDialog(); 4397 PublishDialog *publishdlg = new PublishDialog();
4396 if ( publishdlg->exec() == QDialog::Accepted ) { 4398 if ( publishdlg->exec() == QDialog::Accepted ) {
4397 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4399 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4398 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 4400 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
4399 delete(freebusy); 4401 delete(freebusy);
4400 } 4402 }
4401 } 4403 }
4402 delete publishdlg; 4404 delete publishdlg;
4403} 4405}
4404 4406
4405void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 4407void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
4406{ 4408{
4407 Event *event = 0; 4409 Event *event = 0;
4408 Todo *todo = 0; 4410 Todo *todo = 0;
4409 4411
4410 if (incidence == 0) { 4412 if (incidence == 0) {
4411 incidence = mViewManager->currentView()->selectedIncidences().first(); 4413 incidence = mViewManager->currentView()->selectedIncidences().first();
4412 if (incidence == 0) { 4414 if (incidence == 0) {
4413 incidence = mTodoList->selectedIncidences().first(); 4415 incidence = mTodoList->selectedIncidences().first();
4414 } 4416 }
4415 } 4417 }
4416 if ( incidence && incidence->typeID() == eventID ) { 4418 if ( incidence && incidence->typeID() == eventID ) {
4417 event = static_cast<Event *>(incidence); 4419 event = static_cast<Event *>(incidence);
4418 } 4420 }
4419 if ( incidence && incidence->typeID() == todoID ) { 4421 if ( incidence && incidence->typeID() == todoID ) {
4420 todo = static_cast<Todo *>(incidence); 4422 todo = static_cast<Todo *>(incidence);
4421 } 4423 }
4422 4424
4423 if (!event && !todo) { 4425 if (!event && !todo) {
4424 KMessageBox::sorry(this,i18n("No event selected.")); 4426 KMessageBox::sorry(this,i18n("No event selected."));
4425 return; 4427 return;
4426 } 4428 }
4427 4429
4428 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4430 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
4429 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4431 KMessageBox::sorry(this,i18n("The event has no attendees."));
4430 return; 4432 return;
4431 } 4433 }
4432 4434
4433 Event *ev = 0; 4435 Event *ev = 0;
4434 if (event) ev = new Event(*event); 4436 if (event) ev = new Event(*event);
4435 Todo *to = 0; 4437 Todo *to = 0;
4436 if (todo) to = new Todo(*todo); 4438 if (todo) to = new Todo(*todo);
4437 4439
4438 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4440 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
4439 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4441 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4440 if (!me) { 4442 if (!me) {
4441 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4443 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4442 return; 4444 return;
4443 } 4445 }
4444 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4446 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4445 StatusDialog *statdlg = new StatusDialog(this); 4447 StatusDialog *statdlg = new StatusDialog(this);
4446 if (!statdlg->exec()==QDialog::Accepted) return; 4448 if (!statdlg->exec()==QDialog::Accepted) return;
4447 me->setStatus( statdlg->status() ); 4449 me->setStatus( statdlg->status() );
4448 delete(statdlg); 4450 delete(statdlg);
4449 } 4451 }
4450 Attendee *menew = new Attendee(*me); 4452 Attendee *menew = new Attendee(*me);
4451 if (ev) { 4453 if (ev) {
4452 ev->clearAttendees(); 4454 ev->clearAttendees();
4453 ev->addAttendee(menew,false); 4455 ev->addAttendee(menew,false);
4454 } else { 4456 } else {
4455 if (to) { 4457 if (to) {
4456 todo->clearAttendees(); 4458 todo->clearAttendees();
4457 todo->addAttendee(menew,false); 4459 todo->addAttendee(menew,false);
4458 } 4460 }
4459 } 4461 }
4460 } 4462 }
4461 4463
4462 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4464 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4463 if (ev) { 4465 if (ev) {
4464 if ( !dlg->addMessage(ev,method) ) delete(ev); 4466 if ( !dlg->addMessage(ev,method) ) delete(ev);
4465 } else { 4467 } else {
4466 if (to) { 4468 if (to) {
4467 if ( !dlg->addMessage(to,method) ) delete(to); 4469 if ( !dlg->addMessage(to,method) ) delete(to);
4468 } 4470 }
4469 } 4471 }
4470} 4472}
4471 4473
4472void CalendarView::openAddressbook() 4474void CalendarView::openAddressbook()
4473{ 4475{
4474 KRun::runCommand("kaddressbook"); 4476 KRun::runCommand("kaddressbook");
4475} 4477}
4476 4478
4477void CalendarView::setModified(bool modified) 4479void CalendarView::setModified(bool modified)
4478{ 4480{
4479 //qDebug("CalendarView::setModified %d ", modified); 4481 //qDebug("CalendarView::setModified %d ", modified);
4480 if ( modified ) 4482 if ( modified )
4481 emit signalmodified(); 4483 emit signalmodified();
4482 mModified = modified; 4484 mModified = modified;
4483 if ( mModified ) 4485 if ( mModified )
4484 emit modifiedChanged(mModified); 4486 emit modifiedChanged(mModified);
4485 4487
4486} 4488}
4487 4489
4488bool CalendarView::isReadOnly() 4490bool CalendarView::isReadOnly()
4489{ 4491{
4490 return mReadOnly; 4492 return mReadOnly;
4491} 4493}
4492 4494
4493void CalendarView::setReadOnly(bool readOnly) 4495void CalendarView::setReadOnly(bool readOnly)
4494{ 4496{
4495 if (mReadOnly != readOnly) { 4497 if (mReadOnly != readOnly) {
4496 mReadOnly = readOnly; 4498 mReadOnly = readOnly;
4497 emit readOnlyChanged(mReadOnly); 4499 emit readOnlyChanged(mReadOnly);
4498 } 4500 }
4499} 4501}
4500 4502
4501bool CalendarView::isModified() 4503bool CalendarView::isModified()
4502{ 4504{
4503 return mModified; 4505 return mModified;
4504} 4506}
4505void CalendarView::slotprintSelInc() 4507void CalendarView::slotprintSelInc()
4506{ 4508{
4507 if ( currentSelection() == 0 ) { 4509 if ( currentSelection() == 0 ) {
4508 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4510 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4509 return; 4511 return;
4510 } 4512 }
4511 showIncidence(); 4513 showIncidence();
4512 getEventViewerDialog()->print(); 4514 getEventViewerDialog()->print();
4513 4515
4514} 4516}
4515void CalendarView::printSetup() 4517void CalendarView::printSetup()
4516{ 4518{
4517#ifndef KORG_NOPRINTER 4519#ifndef KORG_NOPRINTER
4518 createPrinter(); 4520 createPrinter();
4519 4521
4520 mCalPrinter->setupPrinter(); 4522 mCalPrinter->setupPrinter();
4521#endif 4523#endif
4522} 4524}
4523 4525
4524void CalendarView::print() 4526void CalendarView::print()
4525{ 4527{
4526#ifndef KORG_NOPRINTER 4528#ifndef KORG_NOPRINTER
4527 createPrinter(); 4529 createPrinter();
4528 4530
4529 DateList tmpDateList = mNavigator->selectedDates(); 4531 DateList tmpDateList = mNavigator->selectedDates();
4530 mCalPrinter->print(CalPrinter::Month, 4532 mCalPrinter->print(CalPrinter::Month,
4531 tmpDateList.first(), tmpDateList.last()); 4533 tmpDateList.first(), tmpDateList.last());
4532#endif 4534#endif
4533} 4535}
4534 4536
4535void CalendarView::printPreview() 4537void CalendarView::printPreview()
4536{ 4538{
4537#ifndef KORG_NOPRINTER 4539#ifndef KORG_NOPRINTER
4538 kdDebug() << "CalendarView::printPreview()" << endl; 4540 kdDebug() << "CalendarView::printPreview()" << endl;
4539 4541
4540 createPrinter(); 4542 createPrinter();
4541 4543
4542 DateList tmpDateList = mNavigator->selectedDates(); 4544 DateList tmpDateList = mNavigator->selectedDates();
4543 4545
4544 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4546 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4545 tmpDateList.last()); 4547 tmpDateList.last());
4546#endif 4548#endif
4547} 4549}
4548bool CalendarView::exportICalendar( QString filename ) 4550bool CalendarView::exportICalendar( QString filename )
4549{ 4551{
4550 // Force correct extension 4552 // Force correct extension
4551 if (filename.right(4) != ".ics") filename += ".ics"; 4553 if (filename.right(4) != ".ics") filename += ".ics";
4552 4554
4553 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4555 FileStorage storage( mCalendar, filename, new ICalFormat() );
4554 return storage.save(); 4556 return storage.save();
4555} 4557}
4556 4558
4557bool CalendarView::exportICalendar() 4559bool CalendarView::exportICalendar()
4558{ 4560{
4559 return exportICalendar( KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this) ); 4561 return exportICalendar( KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this) );
4560} 4562}
4561 4563
4562bool CalendarView::exportVCalendar( QString filename ) 4564bool CalendarView::exportVCalendar( QString filename )
4563{ 4565{
4564 if (mCalendar->journals().count() > 0) { 4566 if (mCalendar->journals().count() > 0) {
4565 int result = KMessageBox::warningContinueCancel(this, 4567 int result = KMessageBox::warningContinueCancel(this,
4566 i18n("The journal entries can not be\nexported to a vCalendar file."), 4568 i18n("The journal entries can not be\nexported to a vCalendar file."),
4567 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4569 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4568 true); 4570 true);
4569 if (result != KMessageBox::Continue) return false; 4571 if (result != KMessageBox::Continue) return false;
4570 } 4572 }
4571 4573
4572 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4574 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4573 4575
4574 // Force correct extension 4576 // Force correct extension
4575 if (filename.right(4) != ".vcs") filename += ".vcs"; 4577 if (filename.right(4) != ".vcs") filename += ".vcs";
4576 4578
4577 FileStorage storage( mCalendar, filename, new VCalFormat ); 4579 FileStorage storage( mCalendar, filename, new VCalFormat );
4578 return storage.save(); 4580 return storage.save();
4579 4581
4580} 4582}
4581 4583
4582void CalendarView::eventUpdated(Incidence *) 4584void CalendarView::eventUpdated(Incidence *)
4583{ 4585{
4584 setModified(); 4586 setModified();
4585 // Don't call updateView here. The code, which has caused the update of the 4587 // Don't call updateView here. The code, which has caused the update of the
4586 // event is responsible for updating the view. 4588 // event is responsible for updating the view.
4587 // updateView(); 4589 // updateView();
4588} 4590}
4589 4591
4590void CalendarView::adaptNavigationUnits() 4592void CalendarView::adaptNavigationUnits()
4591{ 4593{
4592 if (mViewManager->currentView()->isEventView()) { 4594 if (mViewManager->currentView()->isEventView()) {
4593 int days = mViewManager->currentView()->currentDateCount(); 4595 int days = mViewManager->currentView()->currentDateCount();
4594 if (days == 1) { 4596 if (days == 1) {
4595 emit changeNavStringPrev(i18n("&Previous Day")); 4597 emit changeNavStringPrev(i18n("&Previous Day"));
4596 emit changeNavStringNext(i18n("&Next Day")); 4598 emit changeNavStringNext(i18n("&Next Day"));
4597 } else { 4599 } else {
4598 emit changeNavStringPrev(i18n("&Previous Week")); 4600 emit changeNavStringPrev(i18n("&Previous Week"));
4599 emit changeNavStringNext(i18n("&Next Week")); 4601 emit changeNavStringNext(i18n("&Next Week"));
4600 } 4602 }
4601 } 4603 }
4602} 4604}
4603 4605
4604void CalendarView::processMainViewSelection( Incidence *incidence ) 4606void CalendarView::processMainViewSelection( Incidence *incidence )
4605{ 4607{
4606 if ( incidence ) mTodoList->clearSelection(); 4608 if ( incidence ) mTodoList->clearSelection();
4607 processIncidenceSelection( incidence ); 4609 processIncidenceSelection( incidence );
4608} 4610}
4609 4611
4610void CalendarView::processTodoListSelection( Incidence *incidence ) 4612void CalendarView::processTodoListSelection( Incidence *incidence )
4611{ 4613{
4612 if ( incidence && mViewManager->currentView() ) { 4614 if ( incidence && mViewManager->currentView() ) {
4613 mViewManager->currentView()->clearSelection(); 4615 mViewManager->currentView()->clearSelection();
4614 } 4616 }
4615 processIncidenceSelection( incidence ); 4617 processIncidenceSelection( incidence );
4616} 4618}
4617 4619
4618void CalendarView::processIncidenceSelection( Incidence *incidence ) 4620void CalendarView::processIncidenceSelection( Incidence *incidence )
4619{ 4621{
4620 emit incidenceSelected( incidence ); 4622 emit incidenceSelected( incidence );
4621 if ( incidence == mSelectedIncidence ) return; 4623 if ( incidence == mSelectedIncidence ) return;
4622 mSelectedIncidence = incidence; 4624 mSelectedIncidence = incidence;
4623 4625
4624 if ( incidence && incidence->typeID() == eventID ) { 4626 if ( incidence && incidence->typeID() == eventID ) {
4625 Event *event = static_cast<Event *>( incidence ); 4627 Event *event = static_cast<Event *>( incidence );
4626 if ( event->organizer() == KOPrefs::instance()->email() ) { 4628 if ( event->organizer() == KOPrefs::instance()->email() ) {
4627 emit organizerEventsSelected( true ); 4629 emit organizerEventsSelected( true );
4628 } else { 4630 } else {
4629 emit organizerEventsSelected(false); 4631 emit organizerEventsSelected(false);
4630 } 4632 }
4631 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4633 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4632 KOPrefs::instance()->email() ) ) { 4634 KOPrefs::instance()->email() ) ) {
4633 emit groupEventsSelected( true ); 4635 emit groupEventsSelected( true );
4634 } else { 4636 } else {
4635 emit groupEventsSelected(false); 4637 emit groupEventsSelected(false);
4636 } 4638 }
4637 return; 4639 return;
4638 } else { 4640 } else {
4639 if ( incidence && incidence->typeID() == todoID ) { 4641 if ( incidence && incidence->typeID() == todoID ) {
4640 emit todoSelected( true ); 4642 emit todoSelected( true );
4641 Todo *event = static_cast<Todo *>( incidence ); 4643 Todo *event = static_cast<Todo *>( incidence );
4642 if ( event->organizer() == KOPrefs::instance()->email() ) { 4644 if ( event->organizer() == KOPrefs::instance()->email() ) {
4643 emit organizerEventsSelected( true ); 4645 emit organizerEventsSelected( true );
4644 } else { 4646 } else {
4645 emit organizerEventsSelected(false); 4647 emit organizerEventsSelected(false);
4646 } 4648 }
4647 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4649 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4648 KOPrefs::instance()->email() ) ) { 4650 KOPrefs::instance()->email() ) ) {
4649 emit groupEventsSelected( true ); 4651 emit groupEventsSelected( true );
4650 } else { 4652 } else {
4651 emit groupEventsSelected(false); 4653 emit groupEventsSelected(false);
4652 } 4654 }
4653 return; 4655 return;
4654 } else { 4656 } else {
4655 emit todoSelected( false ); 4657 emit todoSelected( false );
4656 emit organizerEventsSelected(false); 4658 emit organizerEventsSelected(false);
4657 emit groupEventsSelected(false); 4659 emit groupEventsSelected(false);
4658 } 4660 }
4659 return; 4661 return;
4660 } 4662 }
4661 4663
4662 /* if ( incidence && incidence->typeID() == todoID ) { 4664 /* if ( incidence && incidence->typeID() == todoID ) {
4663 emit todoSelected( true ); 4665 emit todoSelected( true );
4664 } else { 4666 } else {
4665 emit todoSelected( false ); 4667 emit todoSelected( false );
4666 }*/ 4668 }*/
4667} 4669}
4668 4670
4669 4671
4670void CalendarView::checkClipboard() 4672void CalendarView::checkClipboard()
4671{ 4673{
4672#ifndef KORG_NODND 4674#ifndef KORG_NODND
4673 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4675 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4674 emit pasteEnabled(true); 4676 emit pasteEnabled(true);
4675 } else { 4677 } else {
4676 emit pasteEnabled(false); 4678 emit pasteEnabled(false);
4677 } 4679 }
4678#endif 4680#endif
4679} 4681}
4680 4682
4681void CalendarView::showDates(const DateList &selectedDates) 4683void CalendarView::showDates(const DateList &selectedDates)
4682{ 4684{
4683 // kdDebug() << "CalendarView::selectDates()" << endl; 4685 // kdDebug() << "CalendarView::selectDates()" << endl;
4684 4686
4685 4687
4686 if ( !mBlockShowDates ) { 4688 if ( !mBlockShowDates ) {
4687 if ( mViewManager->currentView() ) { 4689 if ( mViewManager->currentView() ) {
4688 updateView( selectedDates.first(), selectedDates.last() ); 4690 updateView( selectedDates.first(), selectedDates.last() );
4689 } else { 4691 } else {
4690 mViewManager->showAgendaView(); 4692 mViewManager->showAgendaView();
4691 } 4693 }
4692 } 4694 }
4693 4695
4694 QDate date = selectedDates.first(); 4696 QDate date = selectedDates.first();
4695 if ( ! date.isValid() ) { 4697 if ( ! date.isValid() ) {
4696 topLevelWidget()->setCaption(""); 4698 topLevelWidget()->setCaption("");
4697 return; 4699 return;
4698 } 4700 }
4699 4701
4700 QString selDates; 4702 QString selDates;
4701 selDates = KGlobal::locale()->formatDate( date, true); 4703 selDates = KGlobal::locale()->formatDate( date, true);
4702 if (selectedDates.first() < selectedDates.last() ) 4704 if (selectedDates.first() < selectedDates.last() )
4703 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4705 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4704 else { 4706 else {
4705 QString addString; 4707 QString addString;
4706 if ( date == QDateTime::currentDateTime().date() ) 4708 if ( date == QDateTime::currentDateTime().date() )
4707 addString = i18n("Today"); 4709 addString = i18n("Today");
4708 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4710 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4709 addString = i18n("Tomorrow"); 4711 addString = i18n("Tomorrow");
4710 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4712 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4711 addString = i18n("Yesterday"); 4713 addString = i18n("Yesterday");
4712 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4714 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4713 addString = i18n("Day before yesterday"); 4715 addString = i18n("Day before yesterday");
4714 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4716 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4715 addString = i18n("Day after tomorrow"); 4717 addString = i18n("Day after tomorrow");
4716 if ( !addString.isEmpty() ) { 4718 if ( !addString.isEmpty() ) {
4717 topLevelWidget()->setCaption( addString+", " + selDates ); 4719 topLevelWidget()->setCaption( addString+", " + selDates );
4718 return; 4720 return;
4719 } 4721 }
4720 } 4722 }
4721 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4723 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4722 4724
4723} 4725}
4724 4726
4725QPtrList<CalFilter> CalendarView::filters() 4727QPtrList<CalFilter> CalendarView::filters()
4726{ 4728{
4727 return mFilters; 4729 return mFilters;
4728 4730
4729} 4731}
4730void CalendarView::editFilters() 4732void CalendarView::editFilters()
4731{ 4733{
4732 // kdDebug() << "CalendarView::editFilters()" << endl; 4734 // kdDebug() << "CalendarView::editFilters()" << endl;
4733 4735
4734 CalFilter *filter = mFilters.first(); 4736 CalFilter *filter = mFilters.first();
4735 while(filter) { 4737 while(filter) {
4736 filter = mFilters.next(); 4738 filter = mFilters.next();
4737 } 4739 }
4738 4740
4739 mDialogManager->showFilterEditDialog(&mFilters); 4741 mDialogManager->showFilterEditDialog(&mFilters);
4740 updateFilter(); 4742 updateFilter();
4741} 4743}
4742void CalendarView::toggleFilter() 4744void CalendarView::toggleFilter()
4743{ 4745{
4744 if ( mLeftFrame->isHidden() ) { 4746 if ( mLeftFrame->isHidden() ) {
4745 toggleExpand(); 4747 toggleExpand();
4746 showFilter( true ); 4748 showFilter( true );
4747 } else 4749 } else
4748 showFilter(! mCalEditView->isVisible()); 4750 showFilter(! mCalEditView->isVisible());
4749} 4751}
4750 4752
4751KOFilterView *CalendarView::filterView() 4753KOFilterView *CalendarView::filterView()
4752{ 4754{
4753 return mFilterView; 4755 return mFilterView;
4754} 4756}
4755void CalendarView::selectFilter( int fil ) 4757void CalendarView::selectFilter( int fil )
4756{ 4758{
4757 mFilterView->setSelectedFilter( fil ); 4759 mFilterView->setSelectedFilter( fil );
4758 updateUnmanagedViews(); 4760 updateUnmanagedViews();
4759} 4761}
4760void CalendarView::showFilter(bool visible) 4762void CalendarView::showFilter(bool visible)
4761{ 4763{
4762#if 1 4764#if 1
4763 if (visible) { 4765 if (visible) {
4764 mCalEditView->readConfig(); 4766 mCalEditView->readConfig();
4765 mCalEditView->show(); 4767 mCalEditView->show();
4766 QValueList<int> sizes; 4768 QValueList<int> sizes;
4767 sizes = mLeftFrame->sizes(); 4769 sizes = mLeftFrame->sizes();
4768 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4770 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4769 sizes.clear(); 4771 sizes.clear();
4770 sizes << 100; 4772 sizes << 100;
4771 sizes << 0; 4773 sizes << 0;
4772 sizes << 0; 4774 sizes << 0;
4773 sizes << 100; 4775 sizes << 100;
4774 mLeftFrame->setSizes(sizes); 4776 mLeftFrame->setSizes(sizes);
4775 } 4777 }
4776#if 0 4778#if 0
4777 sizes = mLeftFrame->sizes(); 4779 sizes = mLeftFrame->sizes();
4778 int ccc = 0; 4780 int ccc = 0;
4779 while ( ccc < sizes.count()) { 4781 while ( ccc < sizes.count()) {
4780 qDebug("size %d %d ", ccc, sizes[ccc]); 4782 qDebug("size %d %d ", ccc, sizes[ccc]);
4781 ++ccc; 4783 ++ccc;
4782 } 4784 }
4783#endif 4785#endif
4784 4786
4785 } 4787 }
4786 else { 4788 else {
4787 mCalEditView->hide(); 4789 mCalEditView->hide();
4788 } 4790 }
4789#else 4791#else
4790 if (visible) mFilterView->show(); 4792 if (visible) mFilterView->show();
4791 else mFilterView->hide(); 4793 else mFilterView->hide();
4792#endif 4794#endif
4793} 4795}
4794void CalendarView::toggleFilerEnabled( ) 4796void CalendarView::toggleFilerEnabled( )
4795{ 4797{
4796 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4798 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4797 if ( !mFilterView->filtersEnabled() ) 4799 if ( !mFilterView->filtersEnabled() )
4798 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4800 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4799 updateUnmanagedViews(); 4801 updateUnmanagedViews();
4800 4802
4801} 4803}
4802void CalendarView::updateFilter() 4804void CalendarView::updateFilter()
4803{ 4805{
4804 CalFilter *filter = mFilterView->selectedFilter(); 4806 CalFilter *filter = mFilterView->selectedFilter();
4805 if (filter) { 4807 if (filter) {
4806 QString mess; 4808 QString mess;
4807 if (mFilterView->filtersEnabled()) { 4809 if (mFilterView->filtersEnabled()) {
4808 mess = i18n("Filter selected: ")+filter->name(); 4810 mess = i18n("Filter selected: ")+filter->name();
4809 filter->setEnabled(true); 4811 filter->setEnabled(true);
4810 } 4812 }
4811 else filter->setEnabled(false); 4813 else filter->setEnabled(false);
4812 mCalendar->setFilter(filter); 4814 mCalendar->setFilter(filter);
4813 updateView(); 4815 updateView();
4814 if ( !mess.isEmpty() ) 4816 if ( !mess.isEmpty() )
4815 topLevelWidget()->setCaption( mess ); 4817 topLevelWidget()->setCaption( mess );
4816 4818
4817 } 4819 }
4818 emit filtersUpdated(); 4820 emit filtersUpdated();
4819} 4821}
4820 4822
4821void CalendarView::filterEdited() 4823void CalendarView::filterEdited()
4822{ 4824{
4823 mFilterView->updateFilters(); 4825 mFilterView->updateFilters();
4824 updateFilter(); 4826 updateFilter();
4825 writeSettings(); 4827 writeSettings();
4826} 4828}
4827 4829
4828 4830
4829void CalendarView::takeOverEvent() 4831void CalendarView::takeOverEvent()
4830{ 4832{
4831 Incidence *incidence = currentSelection(); 4833 Incidence *incidence = currentSelection();
4832 4834
4833 if (!incidence) return; 4835 if (!incidence) return;
4834 4836
4835 incidence->setOrganizer(KOPrefs::instance()->email()); 4837 incidence->setOrganizer(KOPrefs::instance()->email());
4836 incidence->recreate(); 4838 incidence->recreate();
4837 incidence->setReadOnly(false); 4839 incidence->setReadOnly(false);
4838 4840
4839 updateView(); 4841 updateView();
4840} 4842}
4841 4843
4842void CalendarView::takeOverCalendar() 4844void CalendarView::takeOverCalendar()
4843{ 4845{
4844 // TODO: Create Calendar::allIncidences() function and use it here 4846 // TODO: Create Calendar::allIncidences() function and use it here
4845 4847
4846 clearAllViews(); 4848 clearAllViews();
4847 QPtrList<Event> events = mCalendar->events(); 4849 QPtrList<Event> events = mCalendar->events();
4848 for(uint i=0; i<events.count(); ++i) { 4850 for(uint i=0; i<events.count(); ++i) {
4849 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 4851 events.at(i)->setOrganizer(KOPrefs::instance()->email());
4850 events.at(i)->recreate(); 4852 events.at(i)->recreate();
4851 events.at(i)->setReadOnly(false); 4853 events.at(i)->setReadOnly(false);
4852 } 4854 }
4853 4855
4854 QPtrList<Todo> todos = mCalendar->todos(); 4856 QPtrList<Todo> todos = mCalendar->todos();
4855 for(uint i=0; i<todos.count(); ++i) { 4857 for(uint i=0; i<todos.count(); ++i) {
4856 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 4858 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
4857 todos.at(i)->recreate(); 4859 todos.at(i)->recreate();
4858 todos.at(i)->setReadOnly(false); 4860 todos.at(i)->setReadOnly(false);
4859 } 4861 }
4860 4862
4861 QPtrList<Journal> journals = mCalendar->journals(); 4863 QPtrList<Journal> journals = mCalendar->journals();
4862 for(uint i=0; i<journals.count(); ++i) { 4864 for(uint i=0; i<journals.count(); ++i) {
4863 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 4865 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
4864 journals.at(i)->recreate(); 4866 journals.at(i)->recreate();
4865 journals.at(i)->setReadOnly(false); 4867 journals.at(i)->setReadOnly(false);
4866 } 4868 }
4867 4869
4868 updateView(); 4870 updateView();
4869} 4871}
4870 4872
4871void CalendarView::showIntro() 4873void CalendarView::showIntro()
4872{ 4874{
4873 kdDebug() << "To be implemented." << endl; 4875 kdDebug() << "To be implemented." << endl;
4874} 4876}
4875 4877
4876QWidgetStack *CalendarView::viewStack() 4878QWidgetStack *CalendarView::viewStack()
4877{ 4879{
4878 return mRightFrame; 4880 return mRightFrame;
4879} 4881}
4880 4882
4881QWidget *CalendarView::leftFrame() 4883QWidget *CalendarView::leftFrame()
4882{ 4884{
4883 return ( QWidget *)mLeftFrame; 4885 return ( QWidget *)mLeftFrame;
4884} 4886}
4885 4887
4886DateNavigator *CalendarView::dateNavigator() 4888DateNavigator *CalendarView::dateNavigator()
4887{ 4889{
4888 return mNavigator; 4890 return mNavigator;
4889} 4891}
4890 4892
4891KDateNavigator* CalendarView::dateNavigatorWidget() 4893KDateNavigator* CalendarView::dateNavigatorWidget()
4892{ 4894{
4893 return mDateNavigator->navigatorView(); 4895 return mDateNavigator->navigatorView();
4894} 4896}
4895void CalendarView::toggleDateNavigatorWidget() 4897void CalendarView::toggleDateNavigatorWidget()
4896{ 4898{
4897 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4899 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4898 4900
4899 if (!KOPrefs::instance()->mShowDateNavigator ) 4901 if (!KOPrefs::instance()->mShowDateNavigator )
4900 mDateNavigator->hide(); 4902 mDateNavigator->hide();
4901 else 4903 else
4902 mDateNavigator->show(); 4904 mDateNavigator->show();
4903} 4905}
4904void CalendarView::addView(KOrg::BaseView *view) 4906void CalendarView::addView(KOrg::BaseView *view)
4905{ 4907{
4906 mViewManager->addView(view); 4908 mViewManager->addView(view);
4907} 4909}
4908 4910
4909void CalendarView::showView(KOrg::BaseView *view) 4911void CalendarView::showView(KOrg::BaseView *view)
4910{ 4912{
4911 mViewManager->showView(view, mLeftFrame->isVisible()); 4913 mViewManager->showView(view, mLeftFrame->isVisible());
4912} 4914}
4913 4915
4914Incidence *CalendarView::currentSelection() 4916Incidence *CalendarView::currentSelection()
4915{ 4917{
4916 return mViewManager->currentSelection(); 4918 return mViewManager->currentSelection();
4917} 4919}
4918void CalendarView::toggleAllDaySize() 4920void CalendarView::toggleAllDaySize()
4919{ 4921{
4920 /* 4922 /*
4921 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4923 if ( KOPrefs::instance()->mAllDaySize > 47 )
4922 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4924 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4923 else 4925 else
4924 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4926 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4925 */ 4927 */
4926 viewManager()->agendaView()->toggleAllDay(); 4928 viewManager()->agendaView()->toggleAllDay();
4927} 4929}
4928void CalendarView::toggleExpand() 4930void CalendarView::toggleExpand()
4929{ 4931{
4930 // if ( mLeftFrame->isHidden() ) { 4932 // if ( mLeftFrame->isHidden() ) {
4931 // mLeftFrame->show(); 4933 // mLeftFrame->show();
4932 // emit calendarViewExpanded( false ); 4934 // emit calendarViewExpanded( false );
4933 // } else { 4935 // } else {
4934 // mLeftFrame->hide(); 4936 // mLeftFrame->hide();
4935 // emit calendarViewExpanded( true ); 4937 // emit calendarViewExpanded( true );
4936 // } 4938 // }
4937 //qDebug(" CalendarView::toggleExpand()"); 4939 //qDebug(" CalendarView::toggleExpand()");
4938 globalFlagBlockAgenda = 1; 4940 globalFlagBlockAgenda = 1;
4939 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4941 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4940 globalFlagBlockAgenda = 5; 4942 globalFlagBlockAgenda = 5;
4941 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4943 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4942 //mViewManager->showView( 0, true ); 4944 //mViewManager->showView( 0, true );
4943} 4945}
4944 4946
4945void CalendarView::calendarModified( bool modified, Calendar * ) 4947void CalendarView::calendarModified( bool modified, Calendar * )
4946{ 4948{
4947 setModified( modified ); 4949 setModified( modified );
4948} 4950}
4949 4951
4950Todo *CalendarView::selectedTodo() 4952Todo *CalendarView::selectedTodo()
4951{ 4953{
4952 Incidence *incidence = currentSelection(); 4954 Incidence *incidence = currentSelection();
4953 if ( incidence && incidence->typeID() == todoID ) { 4955 if ( incidence && incidence->typeID() == todoID ) {
4954 return static_cast<Todo *>( incidence ); 4956 return static_cast<Todo *>( incidence );
4955 } 4957 }
4956 4958
4957 incidence = mTodoList->selectedIncidences().first(); 4959 incidence = mTodoList->selectedIncidences().first();
4958 if ( incidence && incidence->typeID() == todoID ) { 4960 if ( incidence && incidence->typeID() == todoID ) {
4959 return static_cast<Todo *>( incidence ); 4961 return static_cast<Todo *>( incidence );
4960 } 4962 }
4961 4963
4962 return 0; 4964 return 0;
4963} 4965}
4964 4966
4965void CalendarView::showIncidence() 4967void CalendarView::showIncidence()
4966{ 4968{
4967 mViewerCallerIsSearchDialog = false; 4969 mViewerCallerIsSearchDialog = false;
4968 Incidence *incidence = currentSelection(); 4970 Incidence *incidence = currentSelection();
4969 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4971 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4970 if ( incidence ) { 4972 if ( incidence ) {
4971 ShowIncidenceVisitor v; 4973 ShowIncidenceVisitor v;
4972 v.act( incidence, this ); 4974 v.act( incidence, this );
4973 } 4975 }
4974} 4976}
4975void CalendarView::editIncidenceDescription() 4977void CalendarView::editIncidenceDescription()
4976{ 4978{
4977 mFlagEditDescription = true; 4979 mFlagEditDescription = true;
4978 editIncidence(); 4980 editIncidence();
4979 mFlagEditDescription = false; 4981 mFlagEditDescription = false;
4980} 4982}
4981void CalendarView::editIncidence() 4983void CalendarView::editIncidence()
4982{ 4984{
4983 // qDebug("editIncidence() "); 4985 // qDebug("editIncidence() ");
4984 Incidence *incidence = currentSelection(); 4986 Incidence *incidence = currentSelection();
4985 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4987 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4986 if ( incidence ) { 4988 if ( incidence ) {
4987 EditIncidenceVisitor v; 4989 EditIncidenceVisitor v;
4988 v.act( incidence, this ); 4990 v.act( incidence, this );
4989 } 4991 }
4990} 4992}
4991 4993
4992void CalendarView::deleteIncidence() 4994void CalendarView::deleteIncidence()
4993{ 4995{
4994 Incidence *incidence = currentSelection(); 4996 Incidence *incidence = currentSelection();
4995 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4997 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4996 if ( incidence ) { 4998 if ( incidence ) {
4997 deleteIncidence(incidence); 4999 deleteIncidence(incidence);
4998 } 5000 }
4999} 5001}
5000void CalendarView::showIncidence(QString uid) 5002void CalendarView::showIncidence(QString uid)
5001{ 5003{
5002 Incidence *inc = mCalendar->incidence( uid ); 5004 Incidence *inc = mCalendar->incidence( uid );
5003 if ( inc ) 5005 if ( inc )
5004 showIncidence( inc ); 5006 showIncidence( inc );
5005} 5007}
5006void CalendarView::showIncidence(Incidence *incidence) 5008void CalendarView::showIncidence(Incidence *incidence)
5007{ 5009{
5008 mViewerCallerIsSearchDialog = false; 5010 mViewerCallerIsSearchDialog = false;
5009 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 5011 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
5010 if ( sender() && mDialogManager->getSearchDialog() ) { 5012 if ( sender() && mDialogManager->getSearchDialog() ) {
5011 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 5013 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
5012 mViewerCallerIsSearchDialog = true; 5014 mViewerCallerIsSearchDialog = true;
5013 } 5015 }
5014 } 5016 }
5015 if ( incidence ) { 5017 if ( incidence ) {
5016 ShowIncidenceVisitor v; 5018 ShowIncidenceVisitor v;
5017 v.act( incidence, this ); 5019 v.act( incidence, this );
5018 } 5020 }
5019} 5021}
5020 5022
5021void CalendarView::editIncidence(Incidence *incidence) 5023void CalendarView::editIncidence(Incidence *incidence)
5022{ 5024{
5023 if ( incidence ) { 5025 if ( incidence ) {
5024 5026
5025 EditIncidenceVisitor v; 5027 EditIncidenceVisitor v;
5026 v.act( incidence, this ); 5028 v.act( incidence, this );
5027 5029
5028 } 5030 }
5029} 5031}
5030 5032
5031void CalendarView::deleteIncidence(Incidence *incidence) 5033void CalendarView::deleteIncidence(Incidence *incidence)
5032{ 5034{
5033 //qDebug(" CalendarView::deleteIncidence "); 5035 //qDebug(" CalendarView::deleteIncidence ");
5034 if ( incidence == 0 ) { 5036 if ( incidence == 0 ) {
5035 updateView(); 5037 updateView();
5036 emit updateSearchDialog(); 5038 emit updateSearchDialog();
5037 return; 5039 return;
5038 } 5040 }
5039 if ( incidence ) { 5041 if ( incidence ) {
5040 DeleteIncidenceVisitor v; 5042 DeleteIncidenceVisitor v;
5041 v.act( incidence, this ); 5043 v.act( incidence, this );
5042 } 5044 }
5043} 5045}
5044 5046
5045 5047
5046void CalendarView::lookForOutgoingMessages() 5048void CalendarView::lookForOutgoingMessages()
5047{ 5049{
5048 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 5050 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
5049 ogd->loadMessages(); 5051 ogd->loadMessages();
5050} 5052}
5051 5053
5052void CalendarView::lookForIncomingMessages() 5054void CalendarView::lookForIncomingMessages()
5053{ 5055{
5054 IncomingDialog *icd = mDialogManager->incomingDialog(); 5056 IncomingDialog *icd = mDialogManager->incomingDialog();
5055 icd->retrieve(); 5057 icd->retrieve();
5056} 5058}
5057 5059
5058bool CalendarView::removeCompletedSubTodos( Todo* t ) 5060bool CalendarView::removeCompletedSubTodos( Todo* t )
5059{ 5061{
5060 bool deleteTodo = true; 5062 bool deleteTodo = true;
5061 QPtrList<Incidence> subTodos; 5063 QPtrList<Incidence> subTodos;
5062 Incidence *aTodo; 5064 Incidence *aTodo;
5063 subTodos = t->relations(); 5065 subTodos = t->relations();
5064 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 5066 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
5065 if (! removeCompletedSubTodos( (Todo*) aTodo )) 5067 if (! removeCompletedSubTodos( (Todo*) aTodo ))
5066 deleteTodo = false; 5068 deleteTodo = false;
5067 } 5069 }
5068 if ( deleteTodo ) { 5070 if ( deleteTodo ) {
5069 if ( t->isCompleted() && !t->doesRecur()) { 5071 if ( t->isCompleted() && !t->doesRecur()) {
5070 checkExternalId( t ); 5072 checkExternalId( t );
5071 mCalendar->deleteTodo( t ); 5073 mCalendar->deleteTodo( t );
5072 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 5074 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
5073 } 5075 }
5074 else 5076 else
5075 deleteTodo = false; 5077 deleteTodo = false;
5076 } 5078 }
5077 return deleteTodo; 5079 return deleteTodo;
5078 5080
5079} 5081}
5080void CalendarView::purgeCompleted() 5082void CalendarView::purgeCompleted()
5081{ 5083{
5082 int result = KMessageBox::warningContinueCancel(this, 5084 int result = KMessageBox::warningContinueCancel(this,
5083 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 5085 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
5084 5086
5085 if (result == KMessageBox::Continue) { 5087 if (result == KMessageBox::Continue) {
5086 5088
5087 QPtrList<Todo> todoCal; 5089 QPtrList<Todo> todoCal;
5088 QPtrList<Todo> rootTodos; 5090 QPtrList<Todo> rootTodos;
5089 //QPtrList<Incidence> rel; 5091 //QPtrList<Incidence> rel;
5090 Todo *aTodo; 5092 Todo *aTodo;
5091 todoCal = calendar()->todos(); 5093 todoCal = calendar()->todos();
5092 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 5094 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
5093 if ( !aTodo->relatedTo() ) 5095 if ( !aTodo->relatedTo() )
5094 rootTodos.append( aTodo ); 5096 rootTodos.append( aTodo );
5095 } 5097 }
5096 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 5098 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
5097 removeCompletedSubTodos( aTodo ); 5099 removeCompletedSubTodos( aTodo );
5098 } 5100 }
5099 5101
5100 updateView(); 5102 updateView();
5101 } 5103 }
5102} 5104}
5103 5105
5104void CalendarView::slotCalendarChanged() 5106void CalendarView::slotCalendarChanged()
5105{ 5107{
5106 ; 5108 ;
5107} 5109}
5108 5110
5109void CalendarView::keyPressEvent ( QKeyEvent *e) 5111void CalendarView::keyPressEvent ( QKeyEvent *e)
5110{ 5112{
5111 //qDebug("CalendarView::keyPressEvent "); 5113 //qDebug("CalendarView::keyPressEvent ");
5112 e->ignore(); 5114 e->ignore();
5113} 5115}
5114 5116
5115void CalendarView::multiResourceSyncStart( bool start ) 5117void CalendarView::multiResourceSyncStart( bool start )
5116{ 5118{
5117 mMultiResourceSync = start; 5119 mMultiResourceSync = start;
5118 5120
5119} 5121}
5120bool CalendarView::sync(KSyncManager* manager, QString filename, int mode,QString resource) 5122bool CalendarView::sync(KSyncManager* manager, QString filename, int mode,QString resource)
5121{ 5123{
5122 5124
5123 if ( manager != mSyncManager) 5125 if ( manager != mSyncManager)
5124 qDebug("KO: Internal error-1. SyncManager mismatch "); 5126 qDebug("KO: Internal error-1. SyncManager mismatch ");
5125 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 5127 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
5126 qDebug("KO: SyncKDE request detected!"); 5128 qDebug("KO: SyncKDE request detected!");
5127 } 5129 }
5128 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 5130 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
5129 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 5131 mCurrentSyncName = mSyncManager->getCurrentSyncName();
5130 if ( !resource.isEmpty() ) { 5132 if ( !resource.isEmpty() ) {
5131 int exclusiveSyncResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); 5133 int exclusiveSyncResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
5132 qDebug( "KO: Sync request for resource: %s", resource.latin1() ); 5134 qDebug( "KO: Sync request for resource: %s", resource.latin1() );
5133 5135
5134 if ( !exclusiveSyncResource ) { 5136 if ( !exclusiveSyncResource ) {
5135 qDebug( "KO: Requested sync resource not found: %s", resource.latin1() ); 5137 qDebug( "KO: Requested sync resource not found: %s", resource.latin1() );
5136 return false; 5138 return false;
5137 } 5139 }
5138 mCalendar->setDefaultCalendar( exclusiveSyncResource ); 5140 mCalendar->setDefaultCalendar( exclusiveSyncResource );
5139 mCalendar->setDefaultCalendarEnabledOnly(); 5141 mCalendar->setDefaultCalendarEnabledOnly();
5140 } 5142 }
5141 bool result = syncCalendar( filename, mode ); 5143 bool result = syncCalendar( filename, mode );
5142 if ( !resource.isEmpty() ) 5144 if ( !resource.isEmpty() )
5143 restoreCalendarSettings(); 5145 restoreCalendarSettings();
5144 return result; 5146 return result;
5145} 5147}
5146bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 5148bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
5147{ 5149{
5148 //mSyncManager = manager; 5150 //mSyncManager = manager;
5149 if ( manager != mSyncManager) 5151 if ( manager != mSyncManager)
5150 qDebug("KO: Internal error-2. SyncManager mismatch "); 5152 qDebug("KO: Internal error-2. SyncManager mismatch ");
5151 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 5153 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
5152 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 5154 mCurrentSyncName = mSyncManager->getCurrentSyncName();
5153 if ( resource == "sharp" ) 5155 if ( resource == "sharp" )
5154 syncExternal( 0 ); 5156 syncExternal( 0 );
5155 if ( resource == "phone" ) 5157 if ( resource == "phone" )
5156 syncExternal( 1 ); 5158 syncExternal( 1 );
5157 // pending setmodified 5159 // pending setmodified
5158 return true; 5160 return true;
5159} 5161}
5160void CalendarView::setSyncManager(KSyncManager* manager) 5162void CalendarView::setSyncManager(KSyncManager* manager)
5161{ 5163{
5162 mSyncManager = manager; 5164 mSyncManager = manager;
5163} 5165}
5164 5166
5165void CalendarView::removeSyncInfo( QString syncProfile) 5167void CalendarView::removeSyncInfo( QString syncProfile)
5166{ 5168{
5167 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 5169 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
5168 mCalendar->removeSyncInfo( syncProfile ); 5170 mCalendar->removeSyncInfo( syncProfile );
5169 5171
5170} 5172}
5171 5173
5172void CalendarView::undo_delete() 5174void CalendarView::undo_delete()
5173{ 5175{
5174 //qDebug("undo_delete() "); 5176 //qDebug("undo_delete() ");
5175 Incidence* undo = mCalendar->undoIncidence(); 5177 Incidence* undo = mCalendar->undoIncidence();
5176 if ( !undo ) { 5178 if ( !undo ) {
5177 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 5179 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
5178 i18n("KO/Pi")); 5180 i18n("KO/Pi"));
5179 return; 5181 return;
5180 } 5182 }
5181 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) + 5183 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) +
5182 i18n("\nAre you sure you want\nto restore this?"), 5184 i18n("\nAre you sure you want\nto restore this?"),
5183 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 5185 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
5184 mCalendar->undoDeleteIncidence(); 5186 mCalendar->undoDeleteIncidence();
5185 updateView(); 5187 updateView();
5186 } 5188 }
5187} 5189}
5188 5190
5189void CalendarView::slotViewerClosed() 5191void CalendarView::slotViewerClosed()
5190{ 5192{
5191 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 5193 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
5192} 5194}
5193 5195
5194void CalendarView::resetFocus() 5196void CalendarView::resetFocus()
5195{ 5197{
5196 if ( mViewerCallerIsSearchDialog ) { 5198 if ( mViewerCallerIsSearchDialog ) {
5197 if ( mDialogManager->getSearchDialog()->isVisible() ){ 5199 if ( mDialogManager->getSearchDialog()->isVisible() ){
5198 mDialogManager->getSearchDialog()->raise(); 5200 mDialogManager->getSearchDialog()->raise();
5199 mDialogManager->getSearchDialog()->setActiveWindow(); 5201 mDialogManager->getSearchDialog()->setActiveWindow();
5200 mDialogManager->getSearchDialog()->listview()->resetFocus(); 5202 mDialogManager->getSearchDialog()->listview()->resetFocus();
5201 } else 5203 } else
5202 mViewerCallerIsSearchDialog = false; 5204 mViewerCallerIsSearchDialog = false;
5203 } 5205 }
5204 if ( !mViewerCallerIsSearchDialog ) { 5206 if ( !mViewerCallerIsSearchDialog ) {
5205 //mViewManager->currentView()->setFocus(); 5207 //mViewManager->currentView()->setFocus();
5206 //qDebug("sssssssssssssssset focus "); 5208 //qDebug("sssssssssssssssset focus ");
5207 topLevelWidget()->raise(); 5209 topLevelWidget()->raise();
5208 setActiveWindow(); 5210 setActiveWindow();
5209 //setFocus(); 5211 //setFocus();
5210 } 5212 }
5211 mViewerCallerIsSearchDialog = false; 5213 mViewerCallerIsSearchDialog = false;
5212} 5214}
5213 5215
5214void CalendarView::showNextAlarms() 5216void CalendarView::showNextAlarms()
5215{ 5217{
5216 QString message; 5218 QString message;
5217 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 5219 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
5218 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 5220 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
5219 QString sum = mCalendar->nextSummary(); 5221 QString sum = mCalendar->nextSummary();
5220 QDateTime nextA = mNextAlarmDateTime; 5222 QDateTime nextA = mNextAlarmDateTime;
5221 QDateTime cur = QDateTime::currentDateTime(); 5223 QDateTime cur = QDateTime::currentDateTime();
5222 int secs = cur.secsTo( nextA ); 5224 int secs = cur.secsTo( nextA );
5223 int min = secs /60; 5225 int min = secs /60;
5224 int hours = min /60; 5226 int hours = min /60;
5225 min = min % 60; 5227 min = min % 60;
5226 int days = hours /24; 5228 int days = hours /24;
5227 hours = hours % 24; 5229 hours = hours % 24;
5228 5230
5229 //message = i18n("The next alarm is in:\n"); 5231 //message = i18n("The next alarm is in:\n");
5230 if ( days > 1 ) 5232 if ( days > 1 )
5231 message += i18n("%1 days\n").arg( days ); 5233 message += i18n("%1 days\n").arg( days );
5232 else if ( days == 1 ) 5234 else if ( days == 1 )
5233 message += i18n("1 day\n"); 5235 message += i18n("1 day\n");
5234 if ( hours > 1 ) 5236 if ( hours > 1 )
5235 message += i18n("%1 hours\n").arg( hours ); 5237 message += i18n("%1 hours\n").arg( hours );
5236 else if ( hours == 1 ) 5238 else if ( hours == 1 )
5237 message += i18n("1 hour\n"); 5239 message += i18n("1 hour\n");
5238 if ( min > 1 ) 5240 if ( min > 1 )
5239 message += i18n("%1 minutes\n").arg( min ); 5241 message += i18n("%1 minutes\n").arg( min );
5240 else if ( min == 1 ) 5242 else if ( min == 1 )
5241 message += i18n("1 minute\n"); 5243 message += i18n("1 minute\n");
5242 if ( message.isEmpty() ) 5244 if ( message.isEmpty() )
5243 message = i18n("The next alarm is in\nless than one minute!"); 5245 message = i18n("The next alarm is in\nless than one minute!");
5244 else 5246 else
5245 message = i18n("The next alarm is in:\n") + message; 5247 message = i18n("The next alarm is in:\n") + message;
5246 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 5248 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
5247 } else { 5249 } else {
5248 message = i18n("There is no next alarm."); 5250 message = i18n("There is no next alarm.");
5249 5251
5250 } 5252 }
5251#ifdef DESKTOP_VERSION 5253#ifdef DESKTOP_VERSION
5252 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 5254 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
5253 message += i18n("\nThe internal alarm notification is disabled!\n"); 5255 message += i18n("\nThe internal alarm notification is disabled!\n");
5254 message += i18n("Enable it in the settings menu, TAB alarm."); 5256 message += i18n("Enable it in the settings menu, TAB alarm.");
5255 } 5257 }
5256 5258
5257#endif 5259#endif
5258 KMessageBox::information( this, message); 5260 KMessageBox::information( this, message);
5259} 5261}
5260 5262
5261void CalendarView::displayCalendarInfo( int id ) 5263void CalendarView::displayCalendarInfo( int id )
5262{ 5264{
5263 int e, t,j; 5265 int e, t,j;
5264 KopiCalendarFile * kkf = KOPrefs::instance()->getCalendar( id ); 5266 KopiCalendarFile * kkf = KOPrefs::instance()->getCalendar( id );
5265 QString name = kkf->mName; 5267 QString name = kkf->mName;
5266 mCalendar->getIncidenceCount( id, e, t, j ); 5268 mCalendar->getIncidenceCount( id, e, t, j );
5267 QString file = KGlobal::formatMessage ( kkf->mFileName ,0 ); 5269 QString file = KGlobal::formatMessage ( kkf->mFileName ,0 );
5268 QString mess = i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file); 5270 QString mess = i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file);
5269 mess += i18n("<br>The calendar contains<br><b>%1 events<br>%2 todos<br>%3 journals</b>").arg( e ).arg( t ).arg( j ); 5271 mess += i18n("<br>The calendar contains<br><b>%1 events<br>%2 todos<br>%3 journals</b>").arg( e ).arg( t ).arg( j );
5270 KMessageBox::information( this, mess ); 5272 KMessageBox::information( this, mess );
5271 5273
5272 5274
5273} 5275}
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 980663f..8a5a76f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,1140 +1,1149 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) 83Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup )
84{ 84{
85 85
86 int calID = 0; 86 int calID = 0;
87 if ( isDup && *isDup > 0 ) 87 if ( isDup && *isDup > 0 )
88 calID = *isDup; 88 calID = *isDup;
89 Todo *todo;; 89 Todo *todo;;
90 Todo *retVal = 0; 90 Todo *retVal = 0;
91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 91 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
92 if ( todo->uid() == uid ) { 92 if ( todo->uid() == uid ) {
93 if( calID ) { 93 if( calID ) {
94 if ( todo->calID() != calID ) 94 if ( todo->calID() != calID )
95 continue; 95 continue;
96 } 96 }
97 else { 97 else {
98 if ( enabledOnly ) { 98 if ( enabledOnly ) {
99 if ( !todo->calEnabled() ) { 99 if ( !todo->calEnabled() ) {
100 if ( isDup ) 100 if ( isDup )
101 *isDup = todo->calID(); 101 *isDup = todo->calID();
102 continue; 102 continue;
103 } 103 }
104 } 104 }
105 } 105 }
106 if ( doNotCheckDuplicates ) return todo; 106 if ( doNotCheckDuplicates ) return todo;
107 if ( retVal ) { 107 if ( retVal ) {
108 if ( retVal->calID() > todo->calID() ) { 108 if ( retVal->calID() > todo->calID() ) {
109 if ( isDup ) 109 if ( isDup )
110 *isDup = retVal->calID(); 110 *isDup = retVal->calID();
111 retVal = todo; 111 retVal = todo;
112 } 112 }
113 } else { 113 } else {
114 retVal = todo; 114 retVal = todo;
115 } 115 }
116 } 116 }
117 } 117 }
118 return retVal; 118 return retVal;
119} 119}
120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup 120//if ( isDup) and * isDup == 0: store duplicate found cal id in isDup
121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly 121//if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly
122 122
123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) 123Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup )
124{ 124{
125 int calID = 0; 125 int calID = 0;
126 if ( isDup && *isDup > 0 ) 126 if ( isDup && *isDup > 0 )
127 calID = *isDup; 127 calID = *isDup;
128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); 128 Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup );
129 if ( retVal ) return retVal; 129 if ( retVal ) return retVal;
130 Event *event; 130 Event *event;
131 for ( event = mEventList.first(); event; event = mEventList.next() ) { 131 for ( event = mEventList.first(); event; event = mEventList.next() ) {
132 if ( event->uid() == uid ) { 132 if ( event->uid() == uid ) {
133 if( calID ) { 133 if( calID ) {
134 if ( event->calID() != calID ) 134 if ( event->calID() != calID )
135 continue; 135 continue;
136 } 136 }
137 else { 137 else {
138 if ( enabledOnly ) { 138 if ( enabledOnly ) {
139 if ( !event->calEnabled() ) { 139 if ( !event->calEnabled() ) {
140 if ( isDup ) 140 if ( isDup )
141 *isDup =event->calID() ; 141 *isDup =event->calID() ;
142 continue; 142 continue;
143 } 143 }
144 } 144 }
145 } 145 }
146 if ( doNotCheckDuplicates ) return event; 146 if ( doNotCheckDuplicates ) return event;
147 if ( retVal ) { 147 if ( retVal ) {
148 if ( retVal->calID() > event->calID() ) { 148 if ( retVal->calID() > event->calID() ) {
149 if ( isDup ) 149 if ( isDup )
150 *isDup = retVal->calID(); 150 *isDup = retVal->calID();
151 retVal = event; 151 retVal = event;
152 } 152 }
153 } else { 153 } else {
154 retVal = event; 154 retVal = event;
155 } 155 }
156 } 156 }
157 } 157 }
158 if ( retVal ) return retVal; 158 if ( retVal ) return retVal;
159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 159 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
160 if ( it->uid() == uid ) { 160 if ( it->uid() == uid ) {
161 if( calID ) { 161 if( calID ) {
162 if ( event->calID() != calID ) 162 if ( event->calID() != calID )
163 continue; 163 continue;
164 } 164 }
165 else { 165 else {
166 if ( enabledOnly ) { 166 if ( enabledOnly ) {
167 if ( !it->calEnabled() ) { 167 if ( !it->calEnabled() ) {
168 if ( isDup ) 168 if ( isDup )
169 *isDup = it->calID(); 169 *isDup = it->calID();
170 continue; 170 continue;
171 } 171 }
172 } 172 }
173 } 173 }
174 if ( doNotCheckDuplicates ) return it; 174 if ( doNotCheckDuplicates ) return it;
175 if ( retVal ) { 175 if ( retVal ) {
176 if ( retVal->calID() > it->calID() ) { 176 if ( retVal->calID() > it->calID() ) {
177 if ( isDup ) 177 if ( isDup )
178 *isDup = retVal->calID(); 178 *isDup = retVal->calID();
179 retVal = it; 179 retVal = it;
180 } 180 }
181 } else { 181 } else {
182 retVal = it; 182 retVal = it;
183 } 183 }
184 } 184 }
185 return retVal; 185 return retVal;
186} 186}
187 187
188bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
189{ 189{
190 // 1 look for raw inc in local 190 // 1 look for raw inc in local
191 // if inc not in remote, delete in local 191 // if inc not in remote, delete in local
192 // 2 look for raw inc in remote 192 // 2 look for raw inc in remote
193 // if inc in local, replace it 193 // if inc in local, replace it
194 // if not in local, add it to default calendar 194 // if not in local, add it to default calendar
195 QPtrList<Incidence> localInc = rawIncidences(); 195 QPtrList<Incidence> localInc = rawIncidences();
196 Incidence* inL = localInc.first(); 196 Incidence* inL = localInc.first();
197 while ( inL ) { 197 while ( inL ) {
198 if ( ! inL->isReadOnly () ) 198 if ( ! inL->isReadOnly () )
199 if ( !remote->incidenceForUid( inL->uid(), true )) 199 if ( !remote->incidenceForUid( inL->uid(), true ))
200 deleteIncidence( inL ); 200 deleteIncidence( inL );
201 inL = localInc.next(); 201 inL = localInc.next();
202 } 202 }
203 QPtrList<Incidence> er = remote->rawIncidences(); 203 QPtrList<Incidence> er = remote->rawIncidences();
204 Incidence* inR = er.first(); 204 Incidence* inR = er.first();
205 while ( inR ) { 205 while ( inR ) {
206 inL = incidenceForUid( inR->uid(),false ); 206 inL = incidenceForUid( inR->uid(),false );
207 if ( inL ) { 207 if ( inL ) {
208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
209 int calID = inL->calID(); 209 int calID = inL->calID();
210 deleteIncidence( inL ); 210 deleteIncidence( inL );
211 inL = inR->clone(); 211 inL = inR->clone();
212 inL->setCalID_block( calID ); 212 inL->setCalID_block( calID );
213 addIncidence( inL ); 213 addIncidence( inL );
214 } 214 }
215 } else { 215 } else {
216 inL = inR->clone(); 216 inL = inR->clone();
217 inL->setCalID_block( 0 );// add to default cal 217 inL->setCalID_block( 0 );// add to default cal
218 addIncidence( inL ); 218 addIncidence( inL );
219 } 219 }
220 inR = er.next(); 220 inR = er.next();
221 } 221 }
222 return true; 222 return true;
223} 223}
224 224
225 225
226bool CalendarLocal::addCalendarFile( QString name, int id ) 226bool CalendarLocal::addCalendarFile( QString name, int id )
227{ 227{
228 CalendarLocal calendar( timeZoneId() ); 228 CalendarLocal calendar( timeZoneId() );
229 calendar.setDefaultCalendar( id ); 229 calendar.setDefaultCalendar( id );
230 if ( calendar.load( name ) ) { 230 if ( calendar.load( name ) ) {
231 addCalendar( &calendar ); 231 addCalendar( &calendar );
232 return true; 232 return true;
233 } 233 }
234 return false; 234 return false;
235} 235}
236void CalendarLocal::setSyncEventsEnabled() 236void CalendarLocal::setSyncEventsEnabled()
237{ 237{
238 Event * ev; 238 Event * ev;
239 ev = mEventList.first(); 239 ev = mEventList.first();
240 while ( ev ) { 240 while ( ev ) {
241 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 241 if ( ev->uid().left(15) == QString("last-syncEvent-") )
242 ev->setCalEnabled( true ); 242 ev->setCalEnabled( true );
243 ev = mEventList.next(); 243 ev = mEventList.next();
244 } 244 }
245} 245}
246void CalendarLocal::setSyncEventsReadOnly() 246void CalendarLocal::setSyncEventsReadOnly()
247{ 247{
248 Event * ev; 248 Event * ev;
249 ev = mEventList.first(); 249 ev = mEventList.first();
250 while ( ev ) { 250 while ( ev ) {
251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
252 ev->setReadOnly( true ); 252 ev->setReadOnly( true );
253 } 253 }
254 ev = mEventList.next(); 254 ev = mEventList.next();
255 } 255 }
256} 256}
257 257
258void CalendarLocal::addCalendar( Calendar* cal ) 258void CalendarLocal::addCalendar( Calendar* cal )
259{ 259{
260 cal->setDontDeleteIncidencesOnClose(); 260 cal->setDontDeleteIncidencesOnClose();
261 setSyncEventsEnabled(); 261 setSyncEventsEnabled();
262 QPtrList<Incidence> incList;
262 { 263 {
263 QPtrList<Event> EventList = cal->rawEvents(); 264 QPtrList<Event> EventList = cal->rawEvents();
264 QPtrList<Event> el;
265 Event * ev = EventList.first(); 265 Event * ev = EventList.first();
266 while ( ev ) { 266 while ( ev ) {
267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
268 Event * se = event( ev->uid() );
269 if ( se )
270 el.append( se );
271 ev->setCalID_block( 1 ); 268 ev->setCalID_block( 1 );
272 } 269 }
270 Event * se = event( ev->uid() );
271 if ( se )
272 incList.append( se );
273 ev->unRegisterObserver( cal ); 273 ev->unRegisterObserver( cal );
274 ev->registerObserver( this ); 274 ev->registerObserver( this );
275 mEventList.append( ev ); 275 mEventList.append( ev );
276 ev = EventList.next(); 276 ev = EventList.next();
277 } 277 }
278 for ( ev = el.first(); ev; ev = el.next() ) { 278
279 deleteIncidence ( ev );
280 }
281 } 279 }
282 { 280 {
283 281
284 QPtrList<Todo> TodoList = cal->rawTodos(); 282 QPtrList<Todo> TodoList = cal->rawTodos();
285 Todo * ev = TodoList.first(); 283 Todo * ev = TodoList.first();
286 while ( ev ) { 284 while ( ev ) {
287 ev->resetRelatedTo(); 285 ev->resetRelatedTo();
288 ev = TodoList.next(); 286 ev = TodoList.next();
289 } 287 }
290 //TodoList = cal->rawTodos(); 288 //TodoList = cal->rawTodos();
291 ev = TodoList.first(); 289 ev = TodoList.first();
292 while ( ev ) { 290 while ( ev ) {
291 Todo * se = todo( ev->uid() );
292 if ( se )
293 incList.append( se );
293 ev->unRegisterObserver( cal ); 294 ev->unRegisterObserver( cal );
294 ev->registerObserver( this ); 295 ev->registerObserver( this );
295 mTodoList.append( ev ); 296 mTodoList.append( ev );
296 setupRelations( ev ); 297 setupRelations( ev );
297 ev = TodoList.next(); 298 ev = TodoList.next();
298 } 299 }
299 } 300 }
300 { 301 {
301 QPtrList<Journal> JournalList = cal->journals(); 302 QPtrList<Journal> JournalList = cal->journals();
302 Journal * ev = JournalList.first(); 303 Journal * ev = JournalList.first();
303 while ( ev ) { 304 while ( ev ) {
305 Journal * se = journal( ev->uid() );
306 if ( se )
307 incList.append( se );
304 ev->unRegisterObserver( cal ); 308 ev->unRegisterObserver( cal );
305 ev->registerObserver( this ); 309 ev->registerObserver( this );
306 mJournalList.append( ev ); 310 mJournalList.append( ev );
307 ev = JournalList.next(); 311 ev = JournalList.next();
308 } 312 }
309 } 313 }
314 {
315 for (Incidence * ev = incList.first(); ev; ev = incList.next() ) {
316 deleteIncidence ( ev );
317 }
318 }
310 setModified( true ); 319 setModified( true );
311} 320}
312bool CalendarLocal::load( const QString &fileName ) 321bool CalendarLocal::load( const QString &fileName )
313{ 322{
314 FileStorage storage( this, fileName ); 323 FileStorage storage( this, fileName );
315 return storage.load(); 324 return storage.load();
316} 325}
317 326
318bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 327bool CalendarLocal::save( const QString &fileName, CalFormat *format )
319{ 328{
320 FileStorage storage( this, fileName, format ); 329 FileStorage storage( this, fileName, format );
321 return storage.save(); 330 return storage.save();
322} 331}
323 332
324void CalendarLocal::stopAllTodos() 333void CalendarLocal::stopAllTodos()
325{ 334{
326 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 335 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
327 it->setRunning( false ); 336 it->setRunning( false );
328 337
329} 338}
330void CalendarLocal::close() 339void CalendarLocal::close()
331{ 340{
332 341
333 Todo * i; 342 Todo * i;
334 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 343 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
335 344
336 mEventList.setAutoDelete( true ); 345 mEventList.setAutoDelete( true );
337 mTodoList.setAutoDelete( true ); 346 mTodoList.setAutoDelete( true );
338 mJournalList.setAutoDelete( true ); 347 mJournalList.setAutoDelete( true );
339 348
340 mEventList.clear(); 349 mEventList.clear();
341 mTodoList.clear(); 350 mTodoList.clear();
342 mJournalList.clear(); 351 mJournalList.clear();
343 352
344 mEventList.setAutoDelete( false ); 353 mEventList.setAutoDelete( false );
345 mTodoList.setAutoDelete( false ); 354 mTodoList.setAutoDelete( false );
346 mJournalList.setAutoDelete( false ); 355 mJournalList.setAutoDelete( false );
347 356
348 setModified( false ); 357 setModified( false );
349} 358}
350 359
351bool CalendarLocal::addAnniversaryNoDup( Event *event ) 360bool CalendarLocal::addAnniversaryNoDup( Event *event )
352{ 361{
353 QString cat; 362 QString cat;
354 bool isBirthday = true; 363 bool isBirthday = true;
355 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 364 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
356 isBirthday = false; 365 isBirthday = false;
357 cat = i18n( "Anniversary" ); 366 cat = i18n( "Anniversary" );
358 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 367 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
359 isBirthday = true; 368 isBirthday = true;
360 cat = i18n( "Birthday" ); 369 cat = i18n( "Birthday" );
361 } else { 370 } else {
362 qDebug("addAnniversaryNoDup called without fitting category! "); 371 qDebug("addAnniversaryNoDup called without fitting category! ");
363 return false; 372 return false;
364 } 373 }
365 Event * eve; 374 Event * eve;
366 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 375 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
367 if ( !(eve->categories().contains( cat ) )) 376 if ( !(eve->categories().contains( cat ) ))
368 continue; 377 continue;
369 // now we have an event with fitting category 378 // now we have an event with fitting category
370 if ( eve->dtStart().date() != event->dtStart().date() ) 379 if ( eve->dtStart().date() != event->dtStart().date() )
371 continue; 380 continue;
372 // now we have an event with fitting category+date 381 // now we have an event with fitting category+date
373 if ( eve->summary() != event->summary() ) 382 if ( eve->summary() != event->summary() )
374 continue; 383 continue;
375 // now we have an event with fitting category+date+summary 384 // now we have an event with fitting category+date+summary
376 return false; 385 return false;
377 } 386 }
378 return addEvent( event ); 387 return addEvent( event );
379 388
380} 389}
381bool CalendarLocal::addEventNoDup( Event *event ) 390bool CalendarLocal::addEventNoDup( Event *event )
382{ 391{
383 Event * eve; 392 Event * eve;
384 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 393 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
385 if ( *eve == *event ) { 394 if ( *eve == *event ) {
386 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 395 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
387 return false; 396 return false;
388 } 397 }
389 } 398 }
390 return addEvent( event ); 399 return addEvent( event );
391} 400}
392 401
393bool CalendarLocal::addEvent( Event *event ) 402bool CalendarLocal::addEvent( Event *event )
394{ 403{
395 insertEvent( event ); 404 insertEvent( event );
396 405
397 event->registerObserver( this ); 406 event->registerObserver( this );
398 407
399 setModified( true ); 408 setModified( true );
400 if ( event->calID() == 0 ) 409 if ( event->calID() == 0 )
401 event->setCalID_block( mDefaultCalendar ); 410 event->setCalID_block( mDefaultCalendar );
402 event->setCalEnabled( true ); 411 event->setCalEnabled( true );
403 412
404 return true; 413 return true;
405} 414}
406 415
407void CalendarLocal::deleteEvent( Event *event ) 416void CalendarLocal::deleteEvent( Event *event )
408{ 417{
409 clearUndo(event); 418 clearUndo(event);
410 if ( mEventList.removeRef( event ) ) { 419 if ( mEventList.removeRef( event ) ) {
411 setModified( true ); 420 setModified( true );
412 } 421 }
413} 422}
414 423
415 424
416Event *CalendarLocal::event( const QString &uid ) 425Event *CalendarLocal::event( const QString &uid )
417{ 426{
418 Event *event; 427 Event *event;
419 Event *retVal = 0; 428 Event *retVal = 0;
420 for ( event = mEventList.first(); event; event = mEventList.next() ) { 429 for ( event = mEventList.first(); event; event = mEventList.next() ) {
421 if ( event->calEnabled() && event->uid() == uid ) { 430 if ( event->calEnabled() && event->uid() == uid ) {
422 if ( retVal ) { 431 if ( retVal ) {
423 if ( retVal->calID() > event->calID() ) { 432 if ( retVal->calID() > event->calID() ) {
424 retVal = event; 433 retVal = event;
425 } 434 }
426 } else { 435 } else {
427 retVal = event; 436 retVal = event;
428 } 437 }
429 } 438 }
430 } 439 }
431 return retVal; 440 return retVal;
432} 441}
433bool CalendarLocal::addTodoNoDup( Todo *todo ) 442bool CalendarLocal::addTodoNoDup( Todo *todo )
434{ 443{
435 Todo * eve; 444 Todo * eve;
436 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 445 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
437 if ( *eve == *todo ) { 446 if ( *eve == *todo ) {
438 //qDebug("duplicate todo found! not inserted! "); 447 //qDebug("duplicate todo found! not inserted! ");
439 return false; 448 return false;
440 } 449 }
441 } 450 }
442 return addTodo( todo ); 451 return addTodo( todo );
443} 452}
444bool CalendarLocal::addTodo( Todo *todo ) 453bool CalendarLocal::addTodo( Todo *todo )
445{ 454{
446 mTodoList.append( todo ); 455 mTodoList.append( todo );
447 456
448 todo->registerObserver( this ); 457 todo->registerObserver( this );
449 458
450 // Set up subtask relations 459 // Set up subtask relations
451 setupRelations( todo ); 460 setupRelations( todo );
452 461
453 setModified( true ); 462 setModified( true );
454 if ( todo->calID() == 0 ) 463 if ( todo->calID() == 0 )
455 todo->setCalID_block( mDefaultCalendar ); 464 todo->setCalID_block( mDefaultCalendar );
456 todo->setCalEnabled( true ); 465 todo->setCalEnabled( true );
457 return true; 466 return true;
458} 467}
459 468
460void CalendarLocal::deleteTodo( Todo *todo ) 469void CalendarLocal::deleteTodo( Todo *todo )
461{ 470{
462 QString uid = todo->uid(); 471 QString uid = todo->uid();
463 // Handle orphaned children 472 // Handle orphaned children
464 removeRelations( todo ); 473 removeRelations( todo );
465 clearUndo(todo); 474 clearUndo(todo);
466 475
467 if ( mTodoList.removeRef( todo ) ) { 476 if ( mTodoList.removeRef( todo ) ) {
468 setModified( true ); 477 setModified( true );
469 } 478 }
470 Todo* dup = todoForUid( uid ); 479 Todo* dup = todoForUid( uid );
471 if ( dup ) 480 if ( dup )
472 setupRelations( dup ); 481 setupRelations( dup );
473} 482}
474 483
475QPtrList<Todo> CalendarLocal::rawTodos() 484QPtrList<Todo> CalendarLocal::rawTodos()
476{ 485{
477 QPtrList<Todo> el; 486 QPtrList<Todo> el;
478 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 487 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
479 if ( it->calEnabled() ) el.append( it ); 488 if ( it->calEnabled() ) el.append( it );
480 return el; 489 return el;
481} 490}
482Todo *CalendarLocal::todo( QString syncProf, QString id ) 491Todo *CalendarLocal::todo( QString syncProf, QString id )
483{ 492{
484 Todo *todo; 493 Todo *todo;
485 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 494 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
486 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 495 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
487 } 496 }
488 497
489 return 0; 498 return 0;
490} 499}
491void CalendarLocal::removeSyncInfo( QString syncProfile) 500void CalendarLocal::removeSyncInfo( QString syncProfile)
492{ 501{
493 QPtrList<Incidence> all = rawIncidences() ; 502 QPtrList<Incidence> all = rawIncidences() ;
494 Incidence *inc; 503 Incidence *inc;
495 for ( inc = all.first(); inc; inc = all.next() ) { 504 for ( inc = all.first(); inc; inc = all.next() ) {
496 inc->removeID( syncProfile ); 505 inc->removeID( syncProfile );
497 } 506 }
498 if ( syncProfile.isEmpty() ) { 507 if ( syncProfile.isEmpty() ) {
499 QPtrList<Event> el; 508 QPtrList<Event> el;
500 Event *todo; 509 Event *todo;
501 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 510 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
502 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 511 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
503 el.append( todo ); 512 el.append( todo );
504 } 513 }
505 for ( todo = el.first(); todo; todo = el.next() ) { 514 for ( todo = el.first(); todo; todo = el.next() ) {
506 deleteIncidence ( todo ); 515 deleteIncidence ( todo );
507 } 516 }
508 } else { 517 } else {
509 Event *lse = event( "last-syncEvent-"+ syncProfile); 518 Event *lse = event( "last-syncEvent-"+ syncProfile);
510 if ( lse ) 519 if ( lse )
511 deleteIncidence ( lse ); 520 deleteIncidence ( lse );
512 } 521 }
513} 522}
514QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 523QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
515{ 524{
516 QPtrList<Event> el; 525 QPtrList<Event> el;
517 Event *todo; 526 Event *todo;
518 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 527 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
519 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 528 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
520 if ( todo->summary().left(3) == "E: " ) 529 if ( todo->summary().left(3) == "E: " )
521 el.append( todo ); 530 el.append( todo );
522 } 531 }
523 532
524 return el; 533 return el;
525 534
526} 535}
527Event *CalendarLocal::event( QString syncProf, QString id ) 536Event *CalendarLocal::event( QString syncProf, QString id )
528{ 537{
529 Event *todo; 538 Event *todo;
530 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 539 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
531 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 540 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
532 } 541 }
533 542
534 return 0; 543 return 0;
535} 544}
536Todo *CalendarLocal::todo( const QString &uid ) 545Todo *CalendarLocal::todo( const QString &uid )
537{ 546{
538 Todo *todo; 547 Todo *todo;
539 Todo *retVal = 0; 548 Todo *retVal = 0;
540 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 549 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
541 if ( todo->calEnabled() && todo->uid() == uid ) { 550 if ( todo->calEnabled() && todo->uid() == uid ) {
542 if ( retVal ) { 551 if ( retVal ) {
543 if ( retVal->calID() > todo->calID() ) { 552 if ( retVal->calID() > todo->calID() ) {
544 retVal = todo; 553 retVal = todo;
545 } 554 }
546 } else { 555 } else {
547 retVal = todo; 556 retVal = todo;
548 } 557 }
549 } 558 }
550 } 559 }
551 return retVal; 560 return retVal;
552} 561}
553void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) 562void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
554{ 563{
555 events = 0; 564 events = 0;
556 todos = 0; 565 todos = 0;
557 journals = 0; 566 journals = 0;
558 { 567 {
559 Todo *todo; 568 Todo *todo;
560 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 569 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
561 if ( todo->calID() == calId ) 570 if ( todo->calID() == calId )
562 ++todos; 571 ++todos;
563 } 572 }
564 } 573 }
565 { 574 {
566 Event *todo; 575 Event *todo;
567 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 576 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
568 if ( todo->calID() == calId ) 577 if ( todo->calID() == calId )
569 ++events; 578 ++events;
570 579
571 } 580 }
572 } 581 }
573 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 582 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
574 if ( it->calID() == calId ) ++journals; 583 if ( it->calID() == calId ) ++journals;
575 584
576} 585}
577QString CalendarLocal::nextSummary() const 586QString CalendarLocal::nextSummary() const
578{ 587{
579 return mNextSummary; 588 return mNextSummary;
580} 589}
581QDateTime CalendarLocal::nextAlarmEventDateTime() const 590QDateTime CalendarLocal::nextAlarmEventDateTime() const
582{ 591{
583 return mNextAlarmEventDateTime; 592 return mNextAlarmEventDateTime;
584} 593}
585void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 594void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
586{ 595{
587 //mNextAlarmIncidence 596 //mNextAlarmIncidence
588 //mNextAlarmDateTime 597 //mNextAlarmDateTime
589 //return mNextSummary; 598 //return mNextSummary;
590 //return mNextAlarmEventDateTime; 599 //return mNextAlarmEventDateTime;
591 bool newNextAlarm = false; 600 bool newNextAlarm = false;
592 bool computeNextAlarm = false; 601 bool computeNextAlarm = false;
593 bool ok; 602 bool ok;
594 int offset; 603 int offset;
595 QDateTime nextA; 604 QDateTime nextA;
596 // QString nextSum; 605 // QString nextSum;
597 //QDateTime nextEvent; 606 //QDateTime nextEvent;
598 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 607 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
599 computeNextAlarm = true; 608 computeNextAlarm = true;
600 } else { 609 } else {
601 if ( ! deleted ) { 610 if ( ! deleted ) {
602 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 611 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
603 if ( ok ) { 612 if ( ok ) {
604 if ( nextA < mNextAlarmDateTime ) { 613 if ( nextA < mNextAlarmDateTime ) {
605 deRegisterAlarm(); 614 deRegisterAlarm();
606 mNextAlarmDateTime = nextA; 615 mNextAlarmDateTime = nextA;
607 mNextSummary = incidence->summary(); 616 mNextSummary = incidence->summary();
608 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 617 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
609 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 618 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
610 newNextAlarm = true; 619 newNextAlarm = true;
611 mNextAlarmIncidence = incidence; 620 mNextAlarmIncidence = incidence;
612 } else { 621 } else {
613 if ( incidence == mNextAlarmIncidence ) { 622 if ( incidence == mNextAlarmIncidence ) {
614 computeNextAlarm = true; 623 computeNextAlarm = true;
615 } 624 }
616 } 625 }
617 } else { 626 } else {
618 if ( mNextAlarmIncidence == incidence ) { 627 if ( mNextAlarmIncidence == incidence ) {
619 computeNextAlarm = true; 628 computeNextAlarm = true;
620 } 629 }
621 } 630 }
622 } else { // deleted 631 } else { // deleted
623 if ( incidence == mNextAlarmIncidence ) { 632 if ( incidence == mNextAlarmIncidence ) {
624 computeNextAlarm = true; 633 computeNextAlarm = true;
625 } 634 }
626 } 635 }
627 } 636 }
628 if ( computeNextAlarm ) { 637 if ( computeNextAlarm ) {
629 deRegisterAlarm(); 638 deRegisterAlarm();
630 nextA = nextAlarm( 1000 ); 639 nextA = nextAlarm( 1000 );
631 if (! mNextAlarmIncidence ) { 640 if (! mNextAlarmIncidence ) {
632 return; 641 return;
633 } 642 }
634 newNextAlarm = true; 643 newNextAlarm = true;
635 } 644 }
636 if ( newNextAlarm ) 645 if ( newNextAlarm )
637 registerAlarm(); 646 registerAlarm();
638} 647}
639QString CalendarLocal:: getAlarmNotification() 648QString CalendarLocal:: getAlarmNotification()
640{ 649{
641 QString ret; 650 QString ret;
642 // this should not happen 651 // this should not happen
643 if (! mNextAlarmIncidence ) 652 if (! mNextAlarmIncidence )
644 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 653 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
645 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 654 Alarm* alarm = mNextAlarmIncidence->alarms().first();
646 if ( alarm->type() == Alarm::Procedure ) { 655 if ( alarm->type() == Alarm::Procedure ) {
647 ret = "proc_alarm" + alarm->programFile()+"+++"; 656 ret = "proc_alarm" + alarm->programFile()+"+++";
648 } else { 657 } else {
649 ret = "audio_alarm" +alarm->audioFile() +"+++"; 658 ret = "audio_alarm" +alarm->audioFile() +"+++";
650 } 659 }
651 ret += "cal_alarm"+ mNextSummary.left( 25 ); 660 ret += "cal_alarm"+ mNextSummary.left( 25 );
652 if ( mNextSummary.length() > 25 ) 661 if ( mNextSummary.length() > 25 )
653 ret += "\n" + mNextSummary.mid(25, 25 ); 662 ret += "\n" + mNextSummary.mid(25, 25 );
654 ret+= "\n"+mNextAlarmEventDateTimeString; 663 ret+= "\n"+mNextAlarmEventDateTimeString;
655 return ret; 664 return ret;
656} 665}
657void CalendarLocal::registerAlarm() 666void CalendarLocal::registerAlarm()
658{ 667{
659 mLastAlarmNotificationString = getAlarmNotification(); 668 mLastAlarmNotificationString = getAlarmNotification();
660 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 669 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
661 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 670 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
662// #ifndef DESKTOP_VERSION 671// #ifndef DESKTOP_VERSION
663// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 672// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
664// #endif 673// #endif
665} 674}
666void CalendarLocal::deRegisterAlarm() 675void CalendarLocal::deRegisterAlarm()
667{ 676{
668 if ( mLastAlarmNotificationString.isNull() ) 677 if ( mLastAlarmNotificationString.isNull() )
669 return; 678 return;
670 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 679 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
671 680
672 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 681 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
673 mNextAlarmEventDateTime = QDateTime(); 682 mNextAlarmEventDateTime = QDateTime();
674// #ifndef DESKTOP_VERSION 683// #ifndef DESKTOP_VERSION
675// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 684// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
676// #endif 685// #endif
677} 686}
678 687
679QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 688QPtrList<Todo> CalendarLocal::todos( const QDate &date )
680{ 689{
681 QPtrList<Todo> todos; 690 QPtrList<Todo> todos;
682 691
683 Todo *todo; 692 Todo *todo;
684 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 693 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
685 if ( !todo->calEnabled() ) continue; 694 if ( !todo->calEnabled() ) continue;
686 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 695 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
687 todos.append( todo ); 696 todos.append( todo );
688 } 697 }
689 } 698 }
690 699
691 filter()->apply( &todos ); 700 filter()->apply( &todos );
692 return todos; 701 return todos;
693} 702}
694void CalendarLocal::reInitAlarmSettings() 703void CalendarLocal::reInitAlarmSettings()
695{ 704{
696 if ( !mNextAlarmIncidence ) { 705 if ( !mNextAlarmIncidence ) {
697 nextAlarm( 1000 ); 706 nextAlarm( 1000 );
698 } 707 }
699 deRegisterAlarm(); 708 deRegisterAlarm();
700 mNextAlarmIncidence = 0; 709 mNextAlarmIncidence = 0;
701 checkAlarmForIncidence( 0, false ); 710 checkAlarmForIncidence( 0, false );
702 711
703} 712}
704 713
705 714
706 715
707QDateTime CalendarLocal::nextAlarm( int daysTo ) 716QDateTime CalendarLocal::nextAlarm( int daysTo )
708{ 717{
709 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 718 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
710 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 719 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
711 QDateTime next; 720 QDateTime next;
712 Event *e; 721 Event *e;
713 bool ok; 722 bool ok;
714 bool found = false; 723 bool found = false;
715 int offset; 724 int offset;
716 mNextAlarmIncidence = 0; 725 mNextAlarmIncidence = 0;
717 for( e = mEventList.first(); e; e = mEventList.next() ) { 726 for( e = mEventList.first(); e; e = mEventList.next() ) {
718 if ( !e->calEnabled() ) continue; 727 if ( !e->calEnabled() ) continue;
719 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 728 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
720 if ( ok ) { 729 if ( ok ) {
721 if ( next < nextA ) { 730 if ( next < nextA ) {
722 nextA = next; 731 nextA = next;
723 found = true; 732 found = true;
724 mNextSummary = e->summary(); 733 mNextSummary = e->summary();
725 mNextAlarmEventDateTime = next.addSecs(offset ) ; 734 mNextAlarmEventDateTime = next.addSecs(offset ) ;
726 mNextAlarmIncidence = (Incidence *) e; 735 mNextAlarmIncidence = (Incidence *) e;
727 } 736 }
728 } 737 }
729 } 738 }
730 Todo *t; 739 Todo *t;
731 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 740 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
732 if ( !t->calEnabled() ) continue; 741 if ( !t->calEnabled() ) continue;
733 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 742 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
734 if ( ok ) { 743 if ( ok ) {
735 if ( next < nextA ) { 744 if ( next < nextA ) {
736 nextA = next; 745 nextA = next;
737 found = true; 746 found = true;
738 mNextSummary = t->summary(); 747 mNextSummary = t->summary();
739 mNextAlarmEventDateTime = next.addSecs(offset ); 748 mNextAlarmEventDateTime = next.addSecs(offset );
740 mNextAlarmIncidence = (Incidence *) t; 749 mNextAlarmIncidence = (Incidence *) t;
741 } 750 }
742 } 751 }
743 } 752 }
744 if ( mNextAlarmIncidence ) { 753 if ( mNextAlarmIncidence ) {
745 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 754 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
746 mNextAlarmDateTime = nextA; 755 mNextAlarmDateTime = nextA;
747 } 756 }
748 return nextA; 757 return nextA;
749} 758}
750Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 759Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
751{ 760{
752 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 761 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
753} 762}
754 763
755Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 764Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
756{ 765{
757 766
758 Alarm::List alarms; 767 Alarm::List alarms;
759 768
760 Event *e; 769 Event *e;
761 770
762 for( e = mEventList.first(); e; e = mEventList.next() ) { 771 for( e = mEventList.first(); e; e = mEventList.next() ) {
763 if ( !e->calEnabled() ) continue; 772 if ( !e->calEnabled() ) continue;
764 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 773 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
765 else appendAlarms( alarms, e, from, to ); 774 else appendAlarms( alarms, e, from, to );
766 } 775 }
767 776
768 Todo *t; 777 Todo *t;
769 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 778 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
770 if ( !t->calEnabled() ) continue; 779 if ( !t->calEnabled() ) continue;
771 appendAlarms( alarms, t, from, to ); 780 appendAlarms( alarms, t, from, to );
772 } 781 }
773 782
774 return alarms; 783 return alarms;
775} 784}
776 785
777void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 786void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
778 const QDateTime &from, const QDateTime &to ) 787 const QDateTime &from, const QDateTime &to )
779{ 788{
780 QPtrList<Alarm> alarmList = incidence->alarms(); 789 QPtrList<Alarm> alarmList = incidence->alarms();
781 Alarm *alarm; 790 Alarm *alarm;
782 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 791 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
783// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 792// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
784// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 793// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
785 if ( alarm->enabled() ) { 794 if ( alarm->enabled() ) {
786 if ( alarm->time() >= from && alarm->time() <= to ) { 795 if ( alarm->time() >= from && alarm->time() <= to ) {
787 alarms.append( alarm ); 796 alarms.append( alarm );
788 } 797 }
789 } 798 }
790 } 799 }
791} 800}
792 801
793void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 802void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
794 Incidence *incidence, 803 Incidence *incidence,
795 const QDateTime &from, 804 const QDateTime &from,
796 const QDateTime &to ) 805 const QDateTime &to )
797{ 806{
798 807
799 QPtrList<Alarm> alarmList = incidence->alarms(); 808 QPtrList<Alarm> alarmList = incidence->alarms();
800 Alarm *alarm; 809 Alarm *alarm;
801 QDateTime qdt; 810 QDateTime qdt;
802 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 811 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
803 if (incidence->recursOn(from.date())) { 812 if (incidence->recursOn(from.date())) {
804 qdt.setTime(alarm->time().time()); 813 qdt.setTime(alarm->time().time());
805 qdt.setDate(from.date()); 814 qdt.setDate(from.date());
806 } 815 }
807 else qdt = alarm->time(); 816 else qdt = alarm->time();
808 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 817 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
809 if ( alarm->enabled() ) { 818 if ( alarm->enabled() ) {
810 if ( qdt >= from && qdt <= to ) { 819 if ( qdt >= from && qdt <= to ) {
811 alarms.append( alarm ); 820 alarms.append( alarm );
812 } 821 }
813 } 822 }
814 } 823 }
815} 824}
816 825
817 826
818/****************************** PROTECTED METHODS ****************************/ 827/****************************** PROTECTED METHODS ****************************/
819 828
820// after changes are made to an event, this should be called. 829// after changes are made to an event, this should be called.
821void CalendarLocal::update( IncidenceBase *incidence ) 830void CalendarLocal::update( IncidenceBase *incidence )
822{ 831{
823 incidence->setSyncStatus( Event::SYNCMOD ); 832 incidence->setSyncStatus( Event::SYNCMOD );
824 incidence->setLastModified( QDateTime::currentDateTime() ); 833 incidence->setLastModified( QDateTime::currentDateTime() );
825 // we should probably update the revision number here, 834 // we should probably update the revision number here,
826 // or internally in the Event itself when certain things change. 835 // or internally in the Event itself when certain things change.
827 // need to verify with ical documentation. 836 // need to verify with ical documentation.
828 837
829 setModified( true ); 838 setModified( true );
830} 839}
831 840
832void CalendarLocal::insertEvent( Event *event ) 841void CalendarLocal::insertEvent( Event *event )
833{ 842{
834 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 843 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
835} 844}
836 845
837 846
838QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 847QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
839{ 848{
840 QPtrList<Event> eventList; 849 QPtrList<Event> eventList;
841 850
842 Event *event; 851 Event *event;
843 for( event = mEventList.first(); event; event = mEventList.next() ) { 852 for( event = mEventList.first(); event; event = mEventList.next() ) {
844 if ( !event->calEnabled() ) continue; 853 if ( !event->calEnabled() ) continue;
845 if ( event->doesRecur() ) { 854 if ( event->doesRecur() ) {
846 if ( event->isMultiDay() ) { 855 if ( event->isMultiDay() ) {
847 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 856 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
848 int i; 857 int i;
849 for ( i = 0; i <= extraDays; i++ ) { 858 for ( i = 0; i <= extraDays; i++ ) {
850 if ( event->recursOn( qd.addDays( -i ) ) ) { 859 if ( event->recursOn( qd.addDays( -i ) ) ) {
851 eventList.append( event ); 860 eventList.append( event );
852 break; 861 break;
853 } 862 }
854 } 863 }
855 } else { 864 } else {
856 if ( event->recursOn( qd ) ) 865 if ( event->recursOn( qd ) )
857 eventList.append( event ); 866 eventList.append( event );
858 } 867 }
859 } else { 868 } else {
860 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 869 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
861 eventList.append( event ); 870 eventList.append( event );
862 } 871 }
863 } 872 }
864 } 873 }
865 874
866 if ( !sorted ) { 875 if ( !sorted ) {
867 return eventList; 876 return eventList;
868 } 877 }
869 878
870 // kdDebug(5800) << "Sorting events for date\n" << endl; 879 // kdDebug(5800) << "Sorting events for date\n" << endl;
871 // now, we have to sort it based on dtStart.time() 880 // now, we have to sort it based on dtStart.time()
872 QPtrList<Event> eventListSorted; 881 QPtrList<Event> eventListSorted;
873 Event *sortEvent; 882 Event *sortEvent;
874 for ( event = eventList.first(); event; event = eventList.next() ) { 883 for ( event = eventList.first(); event; event = eventList.next() ) {
875 sortEvent = eventListSorted.first(); 884 sortEvent = eventListSorted.first();
876 int i = 0; 885 int i = 0;
877 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 886 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
878 { 887 {
879 i++; 888 i++;
880 sortEvent = eventListSorted.next(); 889 sortEvent = eventListSorted.next();
881 } 890 }
882 eventListSorted.insert( i, event ); 891 eventListSorted.insert( i, event );
883 } 892 }
884 return eventListSorted; 893 return eventListSorted;
885} 894}
886 895
887 896
888QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 897QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
889 bool inclusive ) 898 bool inclusive )
890{ 899{
891 Event *event = 0; 900 Event *event = 0;
892 901
893 QPtrList<Event> eventList; 902 QPtrList<Event> eventList;
894 903
895 // Get non-recurring events 904 // Get non-recurring events
896 for( event = mEventList.first(); event; event = mEventList.next() ) { 905 for( event = mEventList.first(); event; event = mEventList.next() ) {
897 if ( !event->calEnabled() ) continue; 906 if ( !event->calEnabled() ) continue;
898 if ( event->doesRecur() ) { 907 if ( event->doesRecur() ) {
899 QDate rStart = event->dtStart().date(); 908 QDate rStart = event->dtStart().date();
900 bool found = false; 909 bool found = false;
901 if ( inclusive ) { 910 if ( inclusive ) {
902 if ( rStart >= start && rStart <= end ) { 911 if ( rStart >= start && rStart <= end ) {
903 // Start date of event is in range. Now check for end date. 912 // Start date of event is in range. Now check for end date.
904 // if duration is negative, event recurs forever, so do not include it. 913 // if duration is negative, event recurs forever, so do not include it.
905 if ( event->recurrence()->duration() == 0 ) { // End date set 914 if ( event->recurrence()->duration() == 0 ) { // End date set
906 QDate rEnd = event->recurrence()->endDate(); 915 QDate rEnd = event->recurrence()->endDate();
907 if ( rEnd >= start && rEnd <= end ) { // End date within range 916 if ( rEnd >= start && rEnd <= end ) { // End date within range
908 found = true; 917 found = true;
909 } 918 }
910 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 919 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
911 // TODO: Calculate end date from duration. Should be done in Event 920 // TODO: Calculate end date from duration. Should be done in Event
912 // For now exclude all events with a duration. 921 // For now exclude all events with a duration.
913 } 922 }
914 } 923 }
915 } else { 924 } else {
916 bool founOne; 925 bool founOne;
917 QDate next = event->getNextOccurence( start, &founOne ).date(); 926 QDate next = event->getNextOccurence( start, &founOne ).date();
918 if ( founOne ) { 927 if ( founOne ) {
919 if ( next <= end ) { 928 if ( next <= end ) {
920 found = true; 929 found = true;
921 } 930 }
922 } 931 }
923 932
924 /* 933 /*
925 // crap !!! 934 // crap !!!
926 if ( rStart <= end ) { // Start date not after range 935 if ( rStart <= end ) { // Start date not after range
927 if ( rStart >= start ) { // Start date within range 936 if ( rStart >= start ) { // Start date within range
928 found = true; 937 found = true;
929 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 938 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
930 found = true; 939 found = true;
931 } else if ( event->recurrence()->duration() == 0 ) { // End date set 940 } else if ( event->recurrence()->duration() == 0 ) { // End date set
932 QDate rEnd = event->recurrence()->endDate(); 941 QDate rEnd = event->recurrence()->endDate();
933 if ( rEnd >= start && rEnd <= end ) { // End date within range 942 if ( rEnd >= start && rEnd <= end ) { // End date within range
934 found = true; 943 found = true;
935 } 944 }
936 } else { // Duration set 945 } else { // Duration set
937 // TODO: Calculate end date from duration. Should be done in Event 946 // TODO: Calculate end date from duration. Should be done in Event
938 // For now include all events with a duration. 947 // For now include all events with a duration.
939 found = true; 948 found = true;
940 } 949 }
941 } 950 }
942 */ 951 */
943 952
944 } 953 }
945 954
946 if ( found ) eventList.append( event ); 955 if ( found ) eventList.append( event );
947 } else { 956 } else {
948 QDate s = event->dtStart().date(); 957 QDate s = event->dtStart().date();
949 QDate e = event->dtEnd().date(); 958 QDate e = event->dtEnd().date();
950 959
951 if ( inclusive ) { 960 if ( inclusive ) {
952 if ( s >= start && e <= end ) { 961 if ( s >= start && e <= end ) {
953 eventList.append( event ); 962 eventList.append( event );
954 } 963 }
955 } else { 964 } else {
956 if ( ( e >= start && s <= end ) ) { 965 if ( ( e >= start && s <= end ) ) {
957 eventList.append( event ); 966 eventList.append( event );
958 } 967 }
959 } 968 }
960 } 969 }
961 } 970 }
962 971
963 return eventList; 972 return eventList;
964} 973}
965 974
966QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 975QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
967{ 976{
968 return rawEventsForDate( qdt.date() ); 977 return rawEventsForDate( qdt.date() );
969} 978}
970 979
971QPtrList<Event> CalendarLocal::rawEvents() 980QPtrList<Event> CalendarLocal::rawEvents()
972{ 981{
973 QPtrList<Event> el; 982 QPtrList<Event> el;
974 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 983 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
975 if ( it->calEnabled() ) el.append( it ); 984 if ( it->calEnabled() ) el.append( it );
976 return el; 985 return el;
977} 986}
978 987
979bool CalendarLocal::addJournal(Journal *journal) 988bool CalendarLocal::addJournal(Journal *journal)
980{ 989{
981 mJournalList.append(journal); 990 mJournalList.append(journal);
982 991
983 journal->registerObserver( this ); 992 journal->registerObserver( this );
984 993
985 setModified( true ); 994 setModified( true );
986 if ( journal->calID() == 0 ) 995 if ( journal->calID() == 0 )
987 journal->setCalID_block( mDefaultCalendar ); 996 journal->setCalID_block( mDefaultCalendar );
988 journal->setCalEnabled( true ); 997 journal->setCalEnabled( true );
989 return true; 998 return true;
990} 999}
991 1000
992void CalendarLocal::deleteJournal( Journal *journal ) 1001void CalendarLocal::deleteJournal( Journal *journal )
993{ 1002{
994 clearUndo(journal); 1003 clearUndo(journal);
995 if ( mJournalList.removeRef(journal) ) { 1004 if ( mJournalList.removeRef(journal) ) {
996 setModified( true ); 1005 setModified( true );
997 } 1006 }
998} 1007}
999 1008
1000QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 1009QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
1001{ 1010{
1002 QPtrList<Journal> el; 1011 QPtrList<Journal> el;
1003 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1012 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1004 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 1013 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
1005 return el; 1014 return el;
1006} 1015}
1007Journal *CalendarLocal::journal( const QDate &date ) 1016Journal *CalendarLocal::journal( const QDate &date )
1008{ 1017{
1009// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 1018// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
1010 1019
1011 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1020 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1012 if ( it->calEnabled() && it->dtStart().date() == date ) 1021 if ( it->calEnabled() && it->dtStart().date() == date )
1013 return it; 1022 return it;
1014 1023
1015 return 0; 1024 return 0;
1016} 1025}
1017 1026
1018Journal *CalendarLocal::journal( const QString &uid ) 1027Journal *CalendarLocal::journal( const QString &uid )
1019{ 1028{
1020 Journal * retVal = 0; 1029 Journal * retVal = 0;
1021 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1030 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1022 if ( it->calEnabled() && it->uid() == uid ) { 1031 if ( it->calEnabled() && it->uid() == uid ) {
1023 if ( retVal ) { 1032 if ( retVal ) {
1024 if ( retVal->calID() > it->calID() ) { 1033 if ( retVal->calID() > it->calID() ) {
1025 retVal = it; 1034 retVal = it;
1026 } 1035 }
1027 } else { 1036 } else {
1028 retVal = it; 1037 retVal = it;
1029 } 1038 }
1030 } 1039 }
1031 return retVal; 1040 return retVal;
1032} 1041}
1033 1042
1034QPtrList<Journal> CalendarLocal::journals() 1043QPtrList<Journal> CalendarLocal::journals()
1035{ 1044{
1036 QPtrList<Journal> el; 1045 QPtrList<Journal> el;
1037 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1046 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1038 if ( it->calEnabled() ) el.append( it ); 1047 if ( it->calEnabled() ) el.append( it );
1039 return el; 1048 return el;
1040} 1049}
1041void CalendarLocal::setCalendarRemove( int id ) 1050void CalendarLocal::setCalendarRemove( int id )
1042{ 1051{
1043 1052
1044 { 1053 {
1045 QPtrList<Event> EventList = mEventList; 1054 QPtrList<Event> EventList = mEventList;
1046 Event * ev = EventList.first(); 1055 Event * ev = EventList.first();
1047 while ( ev ) { 1056 while ( ev ) {
1048 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) 1057 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") )
1049 deleteEvent( ev ); 1058 deleteEvent( ev );
1050 ev = EventList.next(); 1059 ev = EventList.next();
1051 } 1060 }
1052 } 1061 }
1053 { 1062 {
1054 1063
1055 QPtrList<Todo> TodoList = mTodoList; 1064 QPtrList<Todo> TodoList = mTodoList;
1056 Todo * ev = TodoList.first(); 1065 Todo * ev = TodoList.first();
1057 while ( ev ) { 1066 while ( ev ) {
1058 if ( ev->calID() == id ) 1067 if ( ev->calID() == id )
1059 deleteTodo( ev ); 1068 deleteTodo( ev );
1060 ev = TodoList.next(); 1069 ev = TodoList.next();
1061 } 1070 }
1062 } 1071 }
1063 { 1072 {
1064 QPtrList<Journal> JournalList = mJournalList; 1073 QPtrList<Journal> JournalList = mJournalList;
1065 Journal * ev = JournalList.first(); 1074 Journal * ev = JournalList.first();
1066 while ( ev ) { 1075 while ( ev ) {
1067 if ( ev->calID() == id ) 1076 if ( ev->calID() == id )
1068 deleteJournal( ev ); 1077 deleteJournal( ev );
1069 ev = JournalList.next(); 1078 ev = JournalList.next();
1070 } 1079 }
1071 } 1080 }
1072 1081
1073 clearUndo(0); 1082 clearUndo(0);
1074 1083
1075} 1084}
1076 1085
1077void CalendarLocal::setAllCalendarEnabled( bool enable ) 1086void CalendarLocal::setAllCalendarEnabled( bool enable )
1078{ 1087{
1079 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1088 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1080 it->setCalEnabled( enable ); 1089 it->setCalEnabled( enable );
1081 1090
1082 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1091 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1083 it->setCalEnabled( enable ); 1092 it->setCalEnabled( enable );
1084 1093
1085 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1094 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1086 it->setCalEnabled( enable ); 1095 it->setCalEnabled( enable );
1087 1096
1088 1097
1089} 1098}
1090void CalendarLocal::setCalendarEnabled( int id, bool enable ) 1099void CalendarLocal::setCalendarEnabled( int id, bool enable )
1091{ 1100{
1092 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1101 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1093 if ( it->calID() == id ) it->setCalEnabled( enable ); 1102 if ( it->calID() == id ) it->setCalEnabled( enable );
1094 1103
1095 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1104 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1096 if ( it->calID() == id ) it->setCalEnabled( enable ); 1105 if ( it->calID() == id ) it->setCalEnabled( enable );
1097 1106
1098 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1107 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1099 if ( it->calID() == id ) it->setCalEnabled( enable ); 1108 if ( it->calID() == id ) it->setCalEnabled( enable );
1100 1109
1101} 1110}
1102 1111
1103void CalendarLocal::setReadOnly( int id, bool enable ) 1112void CalendarLocal::setReadOnly( int id, bool enable )
1104{ 1113{
1105 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1106 if ( it->calID() == id ) it->setReadOnly( enable ); 1115 if ( it->calID() == id ) it->setReadOnly( enable );
1107 1116
1108 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1117 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1109 if ( it->calID() == id ) it->setReadOnly( enable ); 1118 if ( it->calID() == id ) it->setReadOnly( enable );
1110 1119
1111 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1120 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1112 if ( it->calID() == id ) it->setReadOnly( enable ); 1121 if ( it->calID() == id ) it->setReadOnly( enable );
1113 1122
1114} 1123}
1115 1124
1116void CalendarLocal::setAlarmEnabled( int id, bool enable ) 1125void CalendarLocal::setAlarmEnabled( int id, bool enable )
1117{ 1126{
1118 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1127 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1119 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1128 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1120 1129
1121 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1130 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1122 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1131 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1123 1132
1124 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1133 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1125 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1134 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1126 reInitAlarmSettings(); 1135 reInitAlarmSettings();
1127 1136
1128} 1137}
1129void CalendarLocal::setDefaultCalendarEnabledOnly() 1138void CalendarLocal::setDefaultCalendarEnabledOnly()
1130{ 1139{
1131 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1140 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1132 it->setCalEnabled( it->calID() == mDefaultCalendar ); 1141 it->setCalEnabled( it->calID() == mDefaultCalendar );
1133 1142
1134 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1143 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1135 it->setCalEnabled( it->calID() == mDefaultCalendar); 1144 it->setCalEnabled( it->calID() == mDefaultCalendar);
1136 1145
1137 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1146 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1138 it->setCalEnabled( it->calID() == mDefaultCalendar); 1147 it->setCalEnabled( it->calID() == mDefaultCalendar);
1139 1148
1140} 1149}