summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 427d71b..9674921 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4849 +1,4853 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (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 mNextAlarmDateTime = QDateTime::currentDateTime(); 369 mNextAlarmDateTime = QDateTime::currentDateTime();
370 setFocusPolicy (NoFocus ); 370 setFocusPolicy (NoFocus );
371 mViewerCallerIsSearchDialog = false; 371 mViewerCallerIsSearchDialog = false;
372 mBlockShowDates = false; 372 mBlockShowDates = false;
373 373
374 mDatePickerMode = 0; 374 mDatePickerMode = 0;
375 mCurrentSyncDevice = ""; 375 mCurrentSyncDevice = "";
376 mViewManager = new KOViewManager( this ); 376 mViewManager = new KOViewManager( this );
377 mDialogManager = new KODialogManager( this ); 377 mDialogManager = new KODialogManager( this );
378 mEventViewerDialog = 0; 378 mEventViewerDialog = 0;
379 mModified = false; 379 mModified = false;
380 mReadOnly = false; 380 mReadOnly = false;
381 mSelectedIncidence = 0; 381 mSelectedIncidence = 0;
382 mCalPrinter = 0; 382 mCalPrinter = 0;
383 mFilters.setAutoDelete(true); 383 mFilters.setAutoDelete(true);
384 384
385 mCalendar->registerObserver( this ); 385 mCalendar->registerObserver( this );
386 // TODO: Make sure that view is updated, when calendar is changed. 386 // TODO: Make sure that view is updated, when calendar is changed.
387 387
388 mStorage = new FileStorage( mCalendar ); 388 mStorage = new FileStorage( mCalendar );
389 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 389 mNavigator = new DateNavigator( this, "datevav", mViewManager );
390 390
391 QBoxLayout *topLayout = (QBoxLayout*)layout(); 391 QBoxLayout *topLayout = (QBoxLayout*)layout();
392#ifndef KORG_NOSPLITTER 392#ifndef KORG_NOSPLITTER
393 // create the main layout frames. 393 // create the main layout frames.
394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
395 topLayout->addWidget(mPanner); 395 topLayout->addWidget(mPanner);
396 396
397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
398 "CalendarView::LeftFrame"); 398 "CalendarView::LeftFrame");
399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
400 400
401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
402 "CalendarView::DateNavigator" ); 402 "CalendarView::DateNavigator" );
403 403
404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
406 mTodoList->setNavigator( mNavigator ); 406 mTodoList->setNavigator( mNavigator );
407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
408 408
409#ifdef KORG_NORESOURCEVIEW 409#ifdef KORG_NORESOURCEVIEW
410 mResourceView = 0; 410 mResourceView = 0;
411#else 411#else
412 if ( mResourceManager ) { 412 if ( mResourceManager ) {
413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
414 mResourceView->updateView(); 414 mResourceView->updateView();
415 connect( mResourceView, SIGNAL( resourcesChanged() ), 415 connect( mResourceView, SIGNAL( resourcesChanged() ),
416 SLOT( updateView() ) ); 416 SLOT( updateView() ) );
417 } else { 417 } else {
418 mResourceView = 0; 418 mResourceView = 0;
419 } 419 }
420#endif 420#endif
421 QWidget *rightBox = new QWidget( mPanner ); 421 QWidget *rightBox = new QWidget( mPanner );
422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
423 423
424 mRightFrame = new QWidgetStack( rightBox ); 424 mRightFrame = new QWidgetStack( rightBox );
425 rightLayout->addWidget( mRightFrame, 1 ); 425 rightLayout->addWidget( mRightFrame, 1 );
426 426
427 mLeftFrame = mLeftSplitter; 427 mLeftFrame = mLeftSplitter;
428#else 428#else
429 //QWidget *mainBox = new QWidget( this ); 429 //QWidget *mainBox = new QWidget( this );
430 //QWidget *leftFrame = new QWidget( mainBox ); 430 //QWidget *leftFrame = new QWidget( mainBox );
431 //QBoxLayout * mainBoxLayout; 431 //QBoxLayout * mainBoxLayout;
432 if ( KOPrefs::instance()->mVerticalScreen ) { 432 if ( KOPrefs::instance()->mVerticalScreen ) {
433 //mainBoxLayout = new QVBoxLayout(mainBox); 433 //mainBoxLayout = new QVBoxLayout(mainBox);
434 //leftFrameLayout = new QHBoxLayout(leftFrame ); 434 //leftFrameLayout = new QHBoxLayout(leftFrame );
435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
439 } else { 439 } else {
440 //mainBoxLayout = new QHBoxLayout(mainBox); 440 //mainBoxLayout = new QHBoxLayout(mainBox);
441 //leftFrameLayout = new QVBoxLayout(leftFrame ); 441 //leftFrameLayout = new QVBoxLayout(leftFrame );
442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
446 } 446 }
447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
448 //QBoxLayout * leftFrameLayout; 448 //QBoxLayout * leftFrameLayout;
449 topLayout->addWidget( mMainFrame ); 449 topLayout->addWidget( mMainFrame );
450#ifdef DESKTOP_VERSION 450#ifdef DESKTOP_VERSION
451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this ); 451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this );
452 topLayout->addWidget( mDateScrollBar ); 452 topLayout->addWidget( mDateScrollBar );
453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) ); 453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) );
454 if ( QApplication::desktop()->width() < 800 ) 454 if ( QApplication::desktop()->width() < 800 )
455 mDateScrollBar->hide(); 455 mDateScrollBar->hide();
456#endif 456#endif
457 //mainBoxLayout->addWidget (mLeftFrame); 457 //mainBoxLayout->addWidget (mLeftFrame);
458 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 458 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
459 "CalendarView::DateNavigator" ); 459 "CalendarView::DateNavigator" );
460#if 0 460#if 0
461 // FIXME 461 // FIXME
462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
463 "CalendarView::DateNavigator", QDate::currentDate()); 463 "CalendarView::DateNavigator", QDate::currentDate());
464#endif 464#endif
465 // mDateNavigator->blockSignals( true ); 465 // mDateNavigator->blockSignals( true );
466 //leftFrameLayout->addWidget( mDateNavigator ); 466 //leftFrameLayout->addWidget( mDateNavigator );
467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); 472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) );
473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); 474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); 478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() ));
479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
480 480
481 mTodoList->setNavigator( mNavigator ); 481 mTodoList->setNavigator( mNavigator );
482#if 0 482#if 0
483 if ( QApplication::desktop()->width() < 480 ) { 483 if ( QApplication::desktop()->width() < 480 ) {
484 leftFrameLayout->addWidget(mFilterView); 484 leftFrameLayout->addWidget(mFilterView);
485 leftFrameLayout->addWidget(mTodoList, 2 ); 485 leftFrameLayout->addWidget(mTodoList, 2 );
486 486
487 } else { 487 } else {
488 leftFrameLayout->addWidget(mTodoList,2 ); 488 leftFrameLayout->addWidget(mTodoList,2 );
489 leftFrameLayout->addWidget(mFilterView ); 489 leftFrameLayout->addWidget(mFilterView );
490 } 490 }
491#endif 491#endif
492 mFilterView->hide(); 492 mFilterView->hide();
493 mCalEditView->hide(); 493 mCalEditView->hide();
494 QWidget *rightBox = new QWidget( mMainFrame ); 494 QWidget *rightBox = new QWidget( mMainFrame );
495 //mainBoxLayout->addWidget ( rightBox, 10 ); 495 //mainBoxLayout->addWidget ( rightBox, 10 );
496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
497 mRightFrame = new QWidgetStack( rightBox ); 497 mRightFrame = new QWidgetStack( rightBox );
498 rightLayout->addWidget( mRightFrame, 10 ); 498 rightLayout->addWidget( mRightFrame, 10 );
499 499
500 //mLeftFrame = (QWidget *)leftFrame; 500 //mLeftFrame = (QWidget *)leftFrame;
501 if ( KOPrefs::instance()->mVerticalScreen ) { 501 if ( KOPrefs::instance()->mVerticalScreen ) {
502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
506 } else { 506 } else {
507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
510 } 510 }
511 if ( !KOPrefs::instance()->mShowDateNavigator) 511 if ( !KOPrefs::instance()->mShowDateNavigator)
512 mDateNavigator->hide(); 512 mDateNavigator->hide();
513 //qDebug("Calendarview Size %d %d ", width(), height()); 513 //qDebug("Calendarview Size %d %d ", width(), height());
514#endif 514#endif
515 515
516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
517 SLOT( showDates( const KCal::DateList & ) ) ); 517 SLOT( showDates( const KCal::DateList & ) ) );
518 518
519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
521 521
522 522
523 523
524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
525 mViewManager, SLOT( showMonth( const QDate & ) ) ); 525 mViewManager, SLOT( showMonth( const QDate & ) ) );
526 526
527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
528 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 528 mNavigator, SLOT( selectWeek( const QDate & ) ) );
529 529
530 connect( mDateNavigator, SIGNAL( goPrevYear() ), 530 connect( mDateNavigator, SIGNAL( goPrevYear() ),
531 mNavigator, SLOT( selectPreviousYear() ) ); 531 mNavigator, SLOT( selectPreviousYear() ) );
532 connect( mDateNavigator, SIGNAL( goNextYear() ), 532 connect( mDateNavigator, SIGNAL( goNextYear() ),
533 mNavigator, SLOT( selectNextYear() ) ); 533 mNavigator, SLOT( selectNextYear() ) );
534 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 534 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
535 mNavigator, SLOT( selectPreviousMonth() ) ); 535 mNavigator, SLOT( selectPreviousMonth() ) );
536 connect( mDateNavigator, SIGNAL( goNextMonth() ), 536 connect( mDateNavigator, SIGNAL( goNextMonth() ),
537 mNavigator, SLOT( selectNextMonth() ) ); 537 mNavigator, SLOT( selectNextMonth() ) );
538 538
539 connect( mDateNavigator, SIGNAL( goPrevious() ), 539 connect( mDateNavigator, SIGNAL( goPrevious() ),
540 mNavigator, SLOT( selectPrevious() ) ); 540 mNavigator, SLOT( selectPrevious() ) );
541 connect( mDateNavigator, SIGNAL( goNext() ), 541 connect( mDateNavigator, SIGNAL( goNext() ),
542 mNavigator, SLOT( selectNext() ) ); 542 mNavigator, SLOT( selectNext() ) );
543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
544 mNavigator, SLOT( slotMonthSelect( int ) ) ); 544 mNavigator, SLOT( slotMonthSelect( int ) ) );
545 545
546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
548#if 0 548#if 0
549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
550 SLOT( incidenceAdded( Incidence *) ) ); 550 SLOT( incidenceAdded( Incidence *) ) );
551#endif 551#endif
552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
553 553
554 connect( this, SIGNAL( configChanged() ), 554 connect( this, SIGNAL( configChanged() ),
555 mDateNavigator, SLOT( updateConfig() ) ); 555 mDateNavigator, SLOT( updateConfig() ) );
556 556
557 connect( mTodoList, SIGNAL( newTodoSignal() ), 557 connect( mTodoList, SIGNAL( newTodoSignal() ),
558 SLOT( newTodo() ) ); 558 SLOT( newTodo() ) );
559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
560 SLOT( newSubTodo( Todo * ) ) ); 560 SLOT( newSubTodo( Todo * ) ) );
561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
562 SLOT( editTodo( Todo * ) ) ); 562 SLOT( editTodo( Todo * ) ) );
563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
564 SLOT( showTodo( Todo *) ) ); 564 SLOT( showTodo( Todo *) ) );
565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
566 SLOT( deleteTodo( Todo *) ) ); 566 SLOT( deleteTodo( Todo *) ) );
567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
569 SLOT( purgeCompleted() ) ); 569 SLOT( purgeCompleted() ) );
570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
571 SIGNAL( todoModified( Todo *, int ) ) ); 571 SIGNAL( todoModified( Todo *, int ) ) );
572 572
573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
574 this, SLOT ( cloneIncidence( Incidence * ) ) ); 574 this, SLOT ( cloneIncidence( Incidence * ) ) );
575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
576 this, SLOT (cancelIncidence( Incidence * ) ) ); 576 this, SLOT (cancelIncidence( Incidence * ) ) );
577 577
578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
579 this, SLOT ( moveIncidence( Incidence * ) ) ); 579 this, SLOT ( moveIncidence( Incidence * ) ) );
580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
581 this, SLOT ( beamIncidence( Incidence * ) ) ); 581 this, SLOT ( beamIncidence( Incidence * ) ) );
582 582
583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
584 this, SLOT ( todo_unsub( Todo * ) ) ); 584 this, SLOT ( todo_unsub( Todo * ) ) );
585 585
586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
587 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 587 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
589 SLOT( updateTodo( Todo *, int ) ) ); 589 SLOT( updateTodo( Todo *, int ) ) );
590 connect( this, SIGNAL( todoModified( Todo *, int )), this, 590 connect( this, SIGNAL( todoModified( Todo *, int )), this,
591 SLOT( changeTodoDisplay( Todo *, int ) ) ); 591 SLOT( changeTodoDisplay( Todo *, int ) ) );
592 592
593 593
594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
598 598
599 599
600 600
601 601
602 602
603 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 603 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
604 SLOT(checkClipboard())); 604 SLOT(checkClipboard()));
605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
606 SLOT( processTodoListSelection( Incidence * ) ) ); 606 SLOT( processTodoListSelection( Incidence * ) ) );
607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
608 608
609 // kdDebug() << "CalendarView::CalendarView() done" << endl; 609 // kdDebug() << "CalendarView::CalendarView() done" << endl;
610 610
611 mDateFrame = new QVBox(0,0,WType_Popup); 611 mDateFrame = new QVBox(0,0,WType_Popup);
612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
614 mDateFrame->setLineWidth(3); 614 mDateFrame->setLineWidth(3);
615 mDateFrame->hide(); 615 mDateFrame->hide();
616 mDateFrame->setCaption( i18n( "Pick a date to display")); 616 mDateFrame->setCaption( i18n( "Pick a date to display"));
617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
618 618
619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
620 620
621 mEventEditor = mDialogManager->getEventEditor(); 621 mEventEditor = mDialogManager->getEventEditor();
622 mTodoEditor = mDialogManager->getTodoEditor(); 622 mTodoEditor = mDialogManager->getTodoEditor();
623 623
624 mFlagEditDescription = false; 624 mFlagEditDescription = false;
625 625
626 mSuspendTimer = new QTimer( this ); 626 mSuspendTimer = new QTimer( this );
627 mAlarmTimer = new QTimer( this ); 627 mAlarmTimer = new QTimer( this );
628 mRecheckAlarmTimer = new QTimer( this ); 628 mRecheckAlarmTimer = new QTimer( this );
629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
632 mAlarmDialog = new AlarmDialog( this ); 632 mAlarmDialog = new AlarmDialog( this );
633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
634 mAlarmDialog->setServerNotification( false ); 634 mAlarmDialog->setServerNotification( false );
635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
636 636
637 637
638#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
639//US listen for arriving address resultsets 639//US listen for arriving address resultsets
640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
642#endif 642#endif
643 mDateNavigator->setCalendar( mCalendar ); 643 mDateNavigator->setCalendar( mCalendar );
644} 644}
645 645
646 646
647CalendarView::~CalendarView() 647CalendarView::~CalendarView()
648{ 648{
649 // kdDebug() << "~CalendarView()" << endl; 649 // kdDebug() << "~CalendarView()" << endl;
650 //qDebug("CalendarView::~CalendarView() "); 650 //qDebug("CalendarView::~CalendarView() ");
651 delete mDialogManager; 651 delete mDialogManager;
652 delete mViewManager; 652 delete mViewManager;
653 delete mStorage; 653 delete mStorage;
654 delete mDateFrame ; 654 delete mDateFrame ;
655 delete mEventViewerDialog; 655 delete mEventViewerDialog;
656 //kdDebug() << "~CalendarView() done" << endl; 656 //kdDebug() << "~CalendarView() done" << endl;
657} 657}
658 658
659 659
660void CalendarView::nextConflict( bool all, bool allday ) 660void CalendarView::nextConflict( bool all, bool allday )
661{ 661{
662 static bool block = false; 662 static bool block = false;
663 if ( block ) return; 663 if ( block ) return;
664 block = true; 664 block = true;
665 QPtrList<Event> testlist = mCalendar->events(); 665 QPtrList<Event> testlist = mCalendar->events();
666 Event * test = testlist.first(); 666 Event * test = testlist.first();
667 while ( test ) { 667 while ( test ) {
668 test->setTagged( false ); 668 test->setTagged( false );
669 test = testlist.next(); 669 test = testlist.next();
670 } 670 }
671 QTime st ( 0,0,0); 671 QTime st ( 0,0,0);
672 if ( mViewManager->currentView() == mViewManager->agendaView() ) 672 if ( mViewManager->currentView() == mViewManager->agendaView() )
673 st = mViewManager->agendaView()->agenda()->getEndTime(); 673 st = mViewManager->agendaView()->agenda()->getEndTime();
674 //qDebug("time %s ", st.toString().latin1()); 674 //qDebug("time %s ", st.toString().latin1());
675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
676 QDateTime conflict; 676 QDateTime conflict;
677 QDateTime retVal; 677 QDateTime retVal;
678 bool found = false; 678 bool found = false;
679 Event * cE = 0; 679 Event * cE = 0;
680 Event * cE2 = 0; 680 Event * cE2 = 0;
681 QPtrList<Event> testlist2 = testlist; 681 QPtrList<Event> testlist2 = testlist;
682 test = testlist.first(); 682 test = testlist.first();
683 bool skip = false; 683 bool skip = false;
684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
685 //QTime tm; 685 //QTime tm;
686 //tm.start(); 686 //tm.start();
687 while ( test ) { 687 while ( test ) {
688 qApp->processEvents(); 688 qApp->processEvents();
689 skip = false; 689 skip = false;
690 if ( !all ) skip = ( allday != test->doesFloat() ); 690 if ( !all ) skip = ( allday != test->doesFloat() );
691 if ( !skip ) { 691 if ( !skip ) {
692 if ( found ) 692 if ( found )
693 skip = !test->matchTime( &startDT, &conflict ); 693 skip = !test->matchTime( &startDT, &conflict );
694 else 694 else
695 skip = !test->matchTime( &startDT, 0 ); 695 skip = !test->matchTime( &startDT, 0 );
696 } 696 }
697 if ( !skip ) { 697 if ( !skip ) {
698 Event * test2 = testlist2.first(); 698 Event * test2 = testlist2.first();
699 while ( test2 ) { 699 while ( test2 ) {
700 skip = test2->isTagged(); 700 skip = test2->isTagged();
701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); 701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() );
702 if ( !skip ) { 702 if ( !skip ) {
703 if ( found ) 703 if ( found )
704 skip = !test2->matchTime( &startDT, &conflict ); 704 skip = !test2->matchTime( &startDT, &conflict );
705 else 705 else
706 skip = !test2->matchTime( &startDT, 0 ); 706 skip = !test2->matchTime( &startDT, 0 );
707 } 707 }
708 if ( !skip ) { 708 if ( !skip ) {
709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
710 //qDebug("overlap "); 710 //qDebug("overlap ");
711 if ( ! found ) { 711 if ( ! found ) {
712 if ( retVal >= startDT ) { 712 if ( retVal >= startDT ) {
713 conflict = retVal; 713 conflict = retVal;
714 cE = test; 714 cE = test;
715 cE2 = test2; 715 cE2 = test2;
716 found = true; 716 found = true;
717 } 717 }
718 } else { 718 } else {
719 if ( retVal >= startDT && retVal < conflict ) { 719 if ( retVal >= startDT && retVal < conflict ) {
720 conflict = retVal; 720 conflict = retVal;
721 cE = test; 721 cE = test;
722 cE2 = test2; 722 cE2 = test2;
723 } 723 }
724 } 724 }
725 } 725 }
726 } 726 }
727 test2 = testlist2.next(); 727 test2 = testlist2.next();
728 } 728 }
729 } 729 }
730 test->setTagged( true ); 730 test->setTagged( true );
731 test = testlist.next(); 731 test = testlist.next();
732 } 732 }
733 //qDebug("Search time : %d", tm.elapsed()); 733 //qDebug("Search time : %d", tm.elapsed());
734 if ( found ) { 734 if ( found ) {
735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
736 mViewManager->showDayView(); 736 mViewManager->showDayView();
737 mNavigator->slotDaySelect( conflict.date() ); 737 mNavigator->slotDaySelect( conflict.date() );
738 int hour = conflict.time().hour(); 738 int hour = conflict.time().hour();
739 mViewManager->agendaView()->setStartHour( hour ); 739 mViewManager->agendaView()->setStartHour( hour );
740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
741 block = false; 741 block = false;
742 return; 742 return;
743 } 743 }
744 744
745 topLevelWidget()->setCaption( i18n("No conflict found") ); 745 topLevelWidget()->setCaption( i18n("No conflict found") );
746 qDebug("No conflict found "); 746 qDebug("No conflict found ");
747 block = false; 747 block = false;
748 return; 748 return;
749} 749}
750 750
751void CalendarView::conflictAll() 751void CalendarView::conflictAll()
752{ 752{
753 nextConflict ( true, true ); 753 nextConflict ( true, true );
754} 754}
755void CalendarView::conflictAllday() 755void CalendarView::conflictAllday()
756{ 756{
757 nextConflict ( false, true ); 757 nextConflict ( false, true );
758} 758}
759void CalendarView::conflictNotAll() 759void CalendarView::conflictNotAll()
760{ 760{
761 nextConflict ( false, false ); 761 nextConflict ( false, false );
762} 762}
763 763
764void CalendarView::setCalReadOnly( int id, bool readO ) 764void CalendarView::setCalReadOnly( int id, bool readO )
765{ 765{
766 if ( readO ) { 766 if ( readO ) {
767 emit save(); 767 emit save();
768 } 768 }
769 mCalendar->setReadOnly( id, readO ); 769 mCalendar->setReadOnly( id, readO );
770} 770}
771void CalendarView::setScrollBarStep(int val ) 771void CalendarView::setScrollBarStep(int val )
772{ 772{
773#ifdef DESKTOP_VERSION 773#ifdef DESKTOP_VERSION
774 mDateScrollBar->setLineStep ( val ); 774 mDateScrollBar->setLineStep ( val );
775#endif 775#endif
776} 776}
777void CalendarView::scrollBarValue(int val ) 777void CalendarView::scrollBarValue(int val )
778{ 778{
779#ifdef DESKTOP_VERSION 779#ifdef DESKTOP_VERSION
780 if ( QApplication::desktop()->width() < 800 ) return; 780 if ( QApplication::desktop()->width() < 800 ) return;
781 static bool block = false; 781 static bool block = false;
782 if ( block ) return; 782 if ( block ) return;
783 block = true; 783 block = true;
784 int count = mNavigator->selectedDates().count(); 784 int count = mNavigator->selectedDates().count();
785 int day = mNavigator->selectedDates().first().dayOfYear(); 785 int day = mNavigator->selectedDates().first().dayOfYear();
786 int stepdays = val; 786 int stepdays = val;
787 if ( mDateScrollBar->lineStep () <= count ) { 787 if ( mDateScrollBar->lineStep () <= count ) {
788 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 788 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
789 //qDebug("VAL %d ",val ); 789 //qDebug("VAL %d ",val );
790 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 790 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
791 stepdays = day+stepdays; 791 stepdays = day+stepdays;
792 if ( stepdays < 0 ) stepdays = 0; 792 if ( stepdays < 0 ) stepdays = 0;
793 } 793 }
794 if ( stepdays == day ) { 794 if ( stepdays == day ) {
795 block = false; 795 block = false;
796 return; 796 return;
797 } 797 }
798 int year = mNavigator->selectedDates().first().year(); 798 int year = mNavigator->selectedDates().first().year();
799 QDate d ( year,1,1 ); 799 QDate d ( year,1,1 );
800 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 800 mNavigator->selectDates( d.addDays( stepdays-1) , count );
801 block = false; 801 block = false;
802#endif 802#endif
803 803
804} 804}
805void CalendarView::updateView(const QDate &start, const QDate &end) 805void CalendarView::updateView(const QDate &start, const QDate &end)
806{ 806{
807#ifdef DESKTOP_VERSION 807#ifdef DESKTOP_VERSION
808 if ( ! mDateScrollBar->draggingSlider () ) { 808 if ( ! mDateScrollBar->draggingSlider () ) {
809 int dof = start.dayOfYear(); 809 int dof = start.dayOfYear();
810 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 810 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
811 if ( dof != mDateScrollBar->value() ) { 811 if ( dof != mDateScrollBar->value() ) {
812 mDateScrollBar->blockSignals( true ); 812 mDateScrollBar->blockSignals( true );
813 mDateScrollBar->setValue( start.dayOfYear()); 813 mDateScrollBar->setValue( start.dayOfYear());
814 mDateScrollBar->blockSignals( false ); 814 mDateScrollBar->blockSignals( false );
815 } 815 }
816 } 816 }
817#endif 817#endif
818 mTodoList->updateView(); 818 mTodoList->updateView();
819 mViewManager->updateView(start, end); 819 mViewManager->updateView(start, end);
820 //mDateNavigator->updateView(); 820 //mDateNavigator->updateView();
821} 821}
822 822
823 823
824 824
825void CalendarView::checkFiles() 825void CalendarView::checkFiles()
826{ 826{
827 QString message; 827 QString message;
828 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 828 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
829 KopiCalendarFile * cal = calendars.first(); 829 KopiCalendarFile * cal = calendars.first();
830 while ( cal ) { 830 while ( cal ) {
831 if ( cal->mErrorOnLoad ) { 831 if ( cal->mErrorOnLoad ) {
832 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 832 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
833 } 833 }
834 cal = calendars.next(); 834 cal = calendars.next();
835 } 835 }
836 if ( !message.isEmpty() ) { 836 if ( !message.isEmpty() ) {
837 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); 837 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);
838 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 838 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
839 } 839 }
840 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 840 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
841} 841}
842void CalendarView::checkAlarms() 842void CalendarView::checkAlarms()
843{ 843{
844 844
845 845
846 KConfig *config = KOGlobals::config(); 846 KConfig *config = KOGlobals::config();
847 config->setGroup( "AppRun" ); 847 config->setGroup( "AppRun" );
848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
849 int daysto = dt.daysTo( QDate::currentDate() ); 849 int daysto = dt.daysTo( QDate::currentDate() );
850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
851 dt = dt.addDays( days ); 851 dt = dt.addDays( days );
852 int secto = dt.secsTo( QDateTime::currentDateTime() ); 852 int secto = dt.secsTo( QDateTime::currentDateTime() );
853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
854 //qDebug("KO: Reading program stop %d ", secs); 854 //qDebug("KO: Reading program stop %d ", secs);
855 //secs -= ( 3600 * 24*3 ); // debug only 855 //secs -= ( 3600 * 24*3 ); // debug only
856 QDateTime latest = dt.addSecs ( secs ); 856 QDateTime latest = dt.addSecs ( secs );
857 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 857 qDebug("KO: Last termination on %s ", latest.toString().latin1());
858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
859 QPtrList<Incidence> el = mCalendar->rawIncidences(); 859 QPtrList<Incidence> el = mCalendar->rawIncidences();
860 QPtrList<Incidence> al; 860 QPtrList<Incidence> al;
861 Incidence* inL = el.first(); 861 Incidence* inL = el.first();
862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
864 while ( inL ) { 864 while ( inL ) {
865 bool ok = false; 865 bool ok = false;
866 int offset = 0; 866 int offset = 0;
867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
868 if ( ok ) { 868 if ( ok ) {
869 //qDebug("OK %s",next.toString().latin1()); 869 //qDebug("OK %s",next.toString().latin1());
870 if ( next < cur ) { 870 if ( next < cur ) {
871 al.append( inL ); 871 al.append( inL );
872 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 872 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
873 } 873 }
874 } 874 }
875 inL = el.next(); 875 inL = el.next();
876 } 876 }
877 if ( al.count() ) { 877 if ( al.count() ) {
878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
879 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 879 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
880 QVBoxLayout* lay = new QVBoxLayout( dia ); 880 QVBoxLayout* lay = new QVBoxLayout( dia );
881 lay->setSpacing( 0 ); 881 lay->setSpacing( 0 );
882 lay->setMargin( 0 ); 882 lay->setMargin( 0 );
883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
885 lay->addWidget( matb ); 885 lay->addWidget( matb );
886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
887 int wid = 210; 887 int wid = 210;
888 int x = QApplication::desktop()->width() - wid - 7; 888 int x = QApplication::desktop()->width() - wid - 7;
889 int y = QApplication::desktop()->height() - wid - 70; 889 int y = QApplication::desktop()->height() - wid - 70;
890 dia->setGeometry ( x,y,wid,wid); 890 dia->setGeometry ( x,y,wid,wid);
891 } else { 891 } else {
892 int si = 220; 892 int si = 220;
893 if ( QApplication::desktop()->width() > 470 ) 893 if ( QApplication::desktop()->width() > 470 )
894 si = 400; 894 si = 400;
895 dia->resize(si,si/2); 895 dia->resize(si,si/2);
896 } 896 }
897 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 897 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
898 dia->show(); 898 dia->show();
899 899
900 } 900 }
901} 901}
902void CalendarView::showDay( QDate d ) 902void CalendarView::showDay( QDate d )
903{ 903{
904 dateNavigator()->blockSignals( true ); 904 dateNavigator()->blockSignals( true );
905 dateNavigator()->selectDate( d ); 905 dateNavigator()->selectDate( d );
906 dateNavigator()->blockSignals( false ); 906 dateNavigator()->blockSignals( false );
907 mViewManager->showDayView(); 907 mViewManager->showDayView();
908 //dateNavigator()->selectDate( d ); 908 //dateNavigator()->selectDate( d );
909} 909}
910void CalendarView::timerAlarm() 910void CalendarView::timerAlarm()
911{ 911{
912 //qDebug("CalendarView::timerAlarm() "); 912 //qDebug("CalendarView::timerAlarm() ");
913 computeAlarm(mAlarmNotification ); 913 computeAlarm(mAlarmNotification );
914} 914}
915 915
916void CalendarView::suspendAlarm() 916void CalendarView::suspendAlarm()
917{ 917{
918 //qDebug(" CalendarView::suspendAlarm() "); 918 //qDebug(" CalendarView::suspendAlarm() ");
919 computeAlarm(mSuspendAlarmNotification ); 919 computeAlarm(mSuspendAlarmNotification );
920 920
921} 921}
922 922
923void CalendarView::startAlarm( QString mess , QString filename) 923void CalendarView::startAlarm( QString mess , QString filename)
924{ 924{
925 925
926 topLevelWidget()->showNormal(); 926 topLevelWidget()->showNormal();
927 topLevelWidget()->setActiveWindow(); 927 topLevelWidget()->setActiveWindow();
928 topLevelWidget()->raise(); 928 topLevelWidget()->raise();
929 929
930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
932 932
933} 933}
934 934
935void CalendarView::checkNextTimerAlarm() 935void CalendarView::checkNextTimerAlarm()
936{ 936{
937 mCalendar->checkAlarmForIncidence( 0, true ); 937 mCalendar->checkAlarmForIncidence( 0, true );
938} 938}
939 939
940void CalendarView::computeAlarm( QString msg ) 940void CalendarView::computeAlarm( QString msg )
941{ 941{
942 942
943 QString mess = msg; 943 QString mess = msg;
944 QString mAlarmMessage = mess.mid( 9 ); 944 QString mAlarmMessage = mess.mid( 9 );
945 QString filename = MainWindow::resourcePath(); 945 QString filename = MainWindow::resourcePath();
946 filename += "koalarm.wav"; 946 filename += "koalarm.wav";
947 QString tempfilename; 947 QString tempfilename;
948 if ( mess.left( 13 ) == "suspend_alarm") { 948 if ( mess.left( 13 ) == "suspend_alarm") {
949 bool error = false; 949 bool error = false;
950 int len = mess.mid( 13 ).find("+++"); 950 int len = mess.mid( 13 ).find("+++");
951 if ( len < 2 ) 951 if ( len < 2 )
952 error = true; 952 error = true;
953 else { 953 else {
954 tempfilename = mess.mid( 13, len ); 954 tempfilename = mess.mid( 13, len );
955 if ( !QFile::exists( tempfilename ) ) 955 if ( !QFile::exists( tempfilename ) )
956 error = true; 956 error = true;
957 } 957 }
958 if ( ! error ) { 958 if ( ! error ) {
959 filename = tempfilename; 959 filename = tempfilename;
960 } 960 }
961 mAlarmMessage = mess.mid( 13+len+3 ); 961 mAlarmMessage = mess.mid( 13+len+3 );
962 //qDebug("suspend file %s ",tempfilename.latin1() ); 962 //qDebug("suspend file %s ",tempfilename.latin1() );
963 startAlarm( mAlarmMessage, filename); 963 startAlarm( mAlarmMessage, filename);
964 return; 964 return;
965 } 965 }
966 if ( mess.left( 11 ) == "timer_alarm") { 966 if ( mess.left( 11 ) == "timer_alarm") {
967 //mTimerTime = 0; 967 //mTimerTime = 0;
968 startAlarm( mess.mid( 11 ), filename ); 968 startAlarm( mess.mid( 11 ), filename );
969 return; 969 return;
970 } 970 }
971 if ( mess.left( 10 ) == "proc_alarm") { 971 if ( mess.left( 10 ) == "proc_alarm") {
972 bool error = false; 972 bool error = false;
973 int len = mess.mid( 10 ).find("+++"); 973 int len = mess.mid( 10 ).find("+++");
974 if ( len < 2 ) 974 if ( len < 2 )
975 error = true; 975 error = true;
976 else { 976 else {
977 tempfilename = mess.mid( 10, len ); 977 tempfilename = mess.mid( 10, len );
978 if ( !QFile::exists( tempfilename ) ) 978 if ( !QFile::exists( tempfilename ) )
979 error = true; 979 error = true;
980 } 980 }
981 if ( error ) { 981 if ( error ) {
982 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 982 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
983 mAlarmMessage += mess.mid( 10+len+3+9 ); 983 mAlarmMessage += mess.mid( 10+len+3+9 );
984 } else { 984 } else {
985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
986 //qDebug("-----system command %s ",tempfilename.latin1() ); 986 //qDebug("-----system command %s ",tempfilename.latin1() );
987#ifndef _WIN32_ 987#ifndef _WIN32_
988 if ( vfork () == 0 ) { 988 if ( vfork () == 0 ) {
989 execl ( tempfilename.latin1(), 0 ); 989 execl ( tempfilename.latin1(), 0 );
990 return; 990 return;
991 } 991 }
992#else 992#else
993 QProcess* p = new QProcess(); 993 QProcess* p = new QProcess();
994 p->addArgument( tempfilename.latin1() ); 994 p->addArgument( tempfilename.latin1() );
995 p->start(); 995 p->start();
996 return; 996 return;
997#endif 997#endif
998 998
999 return; 999 return;
1000 } 1000 }
1001 1001
1002 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1002 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1003 } 1003 }
1004 if ( mess.left( 11 ) == "audio_alarm") { 1004 if ( mess.left( 11 ) == "audio_alarm") {
1005 bool error = false; 1005 bool error = false;
1006 int len = mess.mid( 11 ).find("+++"); 1006 int len = mess.mid( 11 ).find("+++");
1007 if ( len < 2 ) 1007 if ( len < 2 )
1008 error = true; 1008 error = true;
1009 else { 1009 else {
1010 tempfilename = mess.mid( 11, len ); 1010 tempfilename = mess.mid( 11, len );
1011 if ( !QFile::exists( tempfilename ) ) 1011 if ( !QFile::exists( tempfilename ) )
1012 error = true; 1012 error = true;
1013 } 1013 }
1014 if ( ! error ) { 1014 if ( ! error ) {
1015 filename = tempfilename; 1015 filename = tempfilename;
1016 } 1016 }
1017 mAlarmMessage = mess.mid( 11+len+3+9 ); 1017 mAlarmMessage = mess.mid( 11+len+3+9 );
1018 //qDebug("audio file command %s ",tempfilename.latin1() ); 1018 //qDebug("audio file command %s ",tempfilename.latin1() );
1019 } 1019 }
1020 if ( mess.left( 9 ) == "cal_alarm") { 1020 if ( mess.left( 9 ) == "cal_alarm") {
1021 mAlarmMessage = mess.mid( 9 ) ; 1021 mAlarmMessage = mess.mid( 9 ) ;
1022 } 1022 }
1023 1023
1024 startAlarm( mAlarmMessage, filename ); 1024 startAlarm( mAlarmMessage, filename );
1025 1025
1026 1026
1027} 1027}
1028 1028
1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1030{ 1030{
1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1032 1032
1033 mSuspendAlarmNotification = noti; 1033 mSuspendAlarmNotification = noti;
1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1036 mSuspendTimer->start( ms , true ); 1036 mSuspendTimer->start( ms , true );
1037 1037
1038} 1038}
1039 1039
1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1041{ 1041{
1042 mNextAlarmDateTime = qdt; 1042 mNextAlarmDateTime = qdt;
1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1045#ifndef DESKTOP_VERSION 1045#ifndef DESKTOP_VERSION
1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1047#endif 1047#endif
1048 return; 1048 return;
1049 } 1049 }
1050 int maxSec; 1050 int maxSec;
1051 //maxSec = 5; //testing only 1051 //maxSec = 5; //testing only
1052 maxSec = 86400+3600; // one day+1hour 1052 maxSec = 86400+3600; // one day+1hour
1053 mAlarmNotification = noti; 1053 mAlarmNotification = noti;
1054 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1054 int sec = QDateTime::currentDateTime().secsTo( qdt );
1055 if ( sec > maxSec ) { 1055 if ( sec > maxSec ) {
1056 mRecheckAlarmTimer->start( maxSec * 1000 ); 1056 mRecheckAlarmTimer->start( maxSec * 1000 );
1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1058 return; 1058 return;
1059 } else { 1059 } else {
1060 mRecheckAlarmTimer->stop(); 1060 mRecheckAlarmTimer->stop();
1061 } 1061 }
1062 //qDebug("Alarm timer started with secs: %d ", sec); 1062 //qDebug("Alarm timer started with secs: %d ", sec);
1063 mAlarmTimer->start( sec *1000 , true ); 1063 mAlarmTimer->start( sec *1000 , true );
1064 1064
1065} 1065}
1066// called by mRecheckAlarmTimer to get next alarm 1066// called by mRecheckAlarmTimer to get next alarm
1067// we need this, because a QTimer has only a max range of 25 days 1067// we need this, because a QTimer has only a max range of 25 days
1068void CalendarView::recheckTimerAlarm() 1068void CalendarView::recheckTimerAlarm()
1069{ 1069{
1070 mAlarmTimer->stop(); 1070 mAlarmTimer->stop();
1071 mRecheckAlarmTimer->stop(); 1071 mRecheckAlarmTimer->stop();
1072 mCalendar->checkAlarmForIncidence( 0, true ); 1072 mCalendar->checkAlarmForIncidence( 0, true );
1073} 1073}
1074#ifndef DESKTOP_VERSION 1074#ifndef DESKTOP_VERSION
1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1076#else 1076#else
1077void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1077void CalendarView::removeAlarm(const QDateTime &, const QString & )
1078#endif 1078#endif
1079{ 1079{
1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1082#ifndef DESKTOP_VERSION 1082#ifndef DESKTOP_VERSION
1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1084#endif 1084#endif
1085 return; 1085 return;
1086 } 1086 }
1087 mAlarmTimer->stop(); 1087 mAlarmTimer->stop();
1088} 1088}
1089void CalendarView::selectWeekNum ( int num ) 1089void CalendarView::selectWeekNum ( int num )
1090{ 1090{
1091 dateNavigator()->blockSignals( true ); 1091 dateNavigator()->blockSignals( true );
1092 dateNavigator()->selectWeek( num ); 1092 dateNavigator()->selectWeek( num );
1093 dateNavigator()->blockSignals( false ); 1093 dateNavigator()->blockSignals( false );
1094 mViewManager->showWeekView(); 1094 mViewManager->showWeekView();
1095} 1095}
1096KOViewManager *CalendarView::viewManager() 1096KOViewManager *CalendarView::viewManager()
1097{ 1097{
1098 return mViewManager; 1098 return mViewManager;
1099} 1099}
1100 1100
1101KODialogManager *CalendarView::dialogManager() 1101KODialogManager *CalendarView::dialogManager()
1102{ 1102{
1103 return mDialogManager; 1103 return mDialogManager;
1104} 1104}
1105 1105
1106QDate CalendarView::startDate() 1106QDate CalendarView::startDate()
1107{ 1107{
1108 DateList dates = mNavigator->selectedDates(); 1108 DateList dates = mNavigator->selectedDates();
1109 1109
1110 return dates.first(); 1110 return dates.first();
1111} 1111}
1112 1112
1113QDate CalendarView::endDate() 1113QDate CalendarView::endDate()
1114{ 1114{
1115 DateList dates = mNavigator->selectedDates(); 1115 DateList dates = mNavigator->selectedDates();
1116 1116
1117 return dates.last(); 1117 return dates.last();
1118} 1118}
1119 1119
1120 1120
1121void CalendarView::createPrinter() 1121void CalendarView::createPrinter()
1122{ 1122{
1123#ifndef KORG_NOPRINTER 1123#ifndef KORG_NOPRINTER
1124 if (!mCalPrinter) { 1124 if (!mCalPrinter) {
1125 mCalPrinter = new CalPrinter(this, mCalendar); 1125 mCalPrinter = new CalPrinter(this, mCalendar);
1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1127 } 1127 }
1128#endif 1128#endif
1129} 1129}
1130 1130
1131 1131
1132//KOPrefs::instance()->mWriteBackFile 1132//KOPrefs::instance()->mWriteBackFile
1133//KOPrefs::instance()->mWriteBackExistingOnly 1133//KOPrefs::instance()->mWriteBackExistingOnly
1134 1134
1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1141 1141
1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1143{ 1143{
1144 1144
1145 // 0 equal 1145 // 0 equal
1146 // 1 take local 1146 // 1 take local
1147 // 2 take remote 1147 // 2 take remote
1148 // 3 cancel 1148 // 3 cancel
1149 QDateTime lastSync = mLastCalendarSync; 1149 QDateTime lastSync = mLastCalendarSync;
1150 QDateTime localMod = local->lastModified(); 1150 QDateTime localMod = local->lastModified();
1151 QDateTime remoteMod = remote->lastModified(); 1151 QDateTime remoteMod = remote->lastModified();
1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1153 bool remCh, locCh; 1153 bool remCh, locCh;
1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1155 //if ( remCh ) 1155 //if ( remCh )
1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1157 locCh = ( localMod > mLastCalendarSync ); 1157 locCh = ( localMod > mLastCalendarSync );
1158 if ( !remCh && ! locCh ) { 1158 if ( !remCh && ! locCh ) {
1159 //qDebug("both not changed "); 1159 //qDebug("both not changed ");
1160 lastSync = localMod.addDays(1); 1160 lastSync = localMod.addDays(1);
1161 if ( mode <= SYNC_PREF_ASK ) 1161 if ( mode <= SYNC_PREF_ASK )
1162 return 0; 1162 return 0;
1163 } else { 1163 } else {
1164 if ( locCh ) { 1164 if ( locCh ) {
1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1166 lastSync = localMod.addDays( -1 ); 1166 lastSync = localMod.addDays( -1 );
1167 if ( !remCh ) 1167 if ( !remCh )
1168 remoteMod = ( lastSync.addDays( -1 ) ); 1168 remoteMod = ( lastSync.addDays( -1 ) );
1169 } else { 1169 } else {
1170 //qDebug(" not loc changed "); 1170 //qDebug(" not loc changed ");
1171 lastSync = localMod.addDays( 1 ); 1171 lastSync = localMod.addDays( 1 );
1172 if ( remCh ) 1172 if ( remCh )
1173 remoteMod =( lastSync.addDays( 1 ) ); 1173 remoteMod =( lastSync.addDays( 1 ) );
1174 1174
1175 } 1175 }
1176 } 1176 }
1177 full = true; 1177 full = true;
1178 if ( mode < SYNC_PREF_ASK ) 1178 if ( mode < SYNC_PREF_ASK )
1179 mode = SYNC_PREF_ASK; 1179 mode = SYNC_PREF_ASK;
1180 } else { 1180 } else {
1181 if ( localMod == remoteMod ) 1181 if ( localMod == remoteMod )
1182 // if ( local->revision() == remote->revision() ) 1182 // if ( local->revision() == remote->revision() )
1183 return 0; 1183 return 0;
1184 1184
1185 } 1185 }
1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1187 1187
1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1190 //full = true; //debug only 1190 //full = true; //debug only
1191 if ( full ) { 1191 if ( full ) {
1192 bool equ = false; 1192 bool equ = false;
1193 if ( local->typeID() == eventID ) { 1193 if ( local->typeID() == eventID ) {
1194 equ = (*((Event*) local) == *((Event*) remote)); 1194 equ = (*((Event*) local) == *((Event*) remote));
1195 } 1195 }
1196 else if ( local->typeID() == todoID ) 1196 else if ( local->typeID() == todoID )
1197 equ = (*((Todo*) local) == (*(Todo*) remote)); 1197 equ = (*((Todo*) local) == (*(Todo*) remote));
1198 else if ( local->typeID() == journalID ) 1198 else if ( local->typeID() == journalID )
1199 equ = (*((Journal*) local) == *((Journal*) remote)); 1199 equ = (*((Journal*) local) == *((Journal*) remote));
1200 if ( equ ) { 1200 if ( equ ) {
1201 //qDebug("equal "); 1201 //qDebug("equal ");
1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1204 } 1204 }
1205 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1205 if ( mode < SYNC_PREF_FORCE_LOCAL )
1206 return 0; 1206 return 0;
1207 1207
1208 }//else //debug only 1208 }//else //debug only
1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1210 } 1210 }
1211 int result; 1211 int result;
1212 bool localIsNew; 1212 bool localIsNew;
1213 //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() ); 1213 //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() );
1214 1214
1215 1215
1216 // ************************************************ 1216 // ************************************************
1217 // ************************************************ 1217 // ************************************************
1218 // ************************************************ 1218 // ************************************************
1219 // We may have that lastSync > remoteMod AND lastSync > localMod 1219 // We may have that lastSync > remoteMod AND lastSync > localMod
1220 // BUT remoteMod != localMod 1220 // BUT remoteMod != localMod
1221 1221
1222 1222
1223 if ( full && mode < SYNC_PREF_NEWEST ) 1223 if ( full && mode < SYNC_PREF_NEWEST )
1224 mode = SYNC_PREF_ASK; 1224 mode = SYNC_PREF_ASK;
1225 1225
1226 switch( mode ) { 1226 switch( mode ) {
1227 case SYNC_PREF_LOCAL: 1227 case SYNC_PREF_LOCAL:
1228 if ( lastSync > remoteMod ) 1228 if ( lastSync > remoteMod )
1229 return 1; 1229 return 1;
1230 if ( lastSync > localMod ) 1230 if ( lastSync > localMod )
1231 return 2; 1231 return 2;
1232 return 1; 1232 return 1;
1233 break; 1233 break;
1234 case SYNC_PREF_REMOTE: 1234 case SYNC_PREF_REMOTE:
1235 if ( lastSync > localMod ) 1235 if ( lastSync > localMod )
1236 return 2; 1236 return 2;
1237 if ( lastSync > remoteMod ) 1237 if ( lastSync > remoteMod )
1238 return 1; 1238 return 1;
1239 return 2; 1239 return 2;
1240 break; 1240 break;
1241 case SYNC_PREF_NEWEST: 1241 case SYNC_PREF_NEWEST:
1242 if ( localMod >= remoteMod ) 1242 if ( localMod >= remoteMod )
1243 return 1; 1243 return 1;
1244 else 1244 else
1245 return 2; 1245 return 2;
1246 break; 1246 break;
1247 case SYNC_PREF_ASK: 1247 case SYNC_PREF_ASK:
1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1249 if ( lastSync > remoteMod && lastSync > localMod) 1249 if ( lastSync > remoteMod && lastSync > localMod)
1250 return 0; 1250 return 0;
1251 if ( lastSync > remoteMod ) 1251 if ( lastSync > remoteMod )
1252 return 1; 1252 return 1;
1253 if ( lastSync > localMod ) 1253 if ( lastSync > localMod )
1254 return 2; 1254 return 2;
1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1256 localIsNew = localMod >= remoteMod; 1256 localIsNew = localMod >= remoteMod;
1257 if ( localIsNew ) 1257 if ( localIsNew )
1258 getEventViewerDialog()->setColorMode( 1 ); 1258 getEventViewerDialog()->setColorMode( 1 );
1259 else 1259 else
1260 getEventViewerDialog()->setColorMode( 2 ); 1260 getEventViewerDialog()->setColorMode( 2 );
1261 getEventViewerDialog()->setIncidence(local); 1261 getEventViewerDialog()->setIncidence(local);
1262 if ( localIsNew ) 1262 if ( localIsNew )
1263 getEventViewerDialog()->setColorMode( 2 ); 1263 getEventViewerDialog()->setColorMode( 2 );
1264 else 1264 else
1265 getEventViewerDialog()->setColorMode( 1 ); 1265 getEventViewerDialog()->setColorMode( 1 );
1266 getEventViewerDialog()->addIncidence(remote); 1266 getEventViewerDialog()->addIncidence(remote);
1267 getEventViewerDialog()->setColorMode( 0 ); 1267 getEventViewerDialog()->setColorMode( 0 );
1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1270 getEventViewerDialog()->showMe(); 1270 getEventViewerDialog()->showMe();
1271 result = getEventViewerDialog()->executeS( localIsNew ); 1271 result = getEventViewerDialog()->executeS( localIsNew );
1272 return result; 1272 return result;
1273 1273
1274 break; 1274 break;
1275 case SYNC_PREF_FORCE_LOCAL: 1275 case SYNC_PREF_FORCE_LOCAL:
1276 return 1; 1276 return 1;
1277 break; 1277 break;
1278 case SYNC_PREF_FORCE_REMOTE: 1278 case SYNC_PREF_FORCE_REMOTE:
1279 return 2; 1279 return 2;
1280 break; 1280 break;
1281 1281
1282 default: 1282 default:
1283 // SYNC_PREF_TAKE_BOTH not implemented 1283 // SYNC_PREF_TAKE_BOTH not implemented
1284 break; 1284 break;
1285 } 1285 }
1286 return 0; 1286 return 0;
1287} 1287}
1288Event* CalendarView::getLastSyncEvent() 1288Event* CalendarView::getLastSyncEvent()
1289{ 1289{
1290 Event* lse; 1290 Event* lse;
1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1293 if (!lse) { 1293 if (!lse) {
1294 lse = new Event(); 1294 lse = new Event();
1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1296 QString sum = ""; 1296 QString sum = "";
1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1298 sum = "E: "; 1298 sum = "E: ";
1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1300 lse->setDtStart( mLastCalendarSync ); 1300 lse->setDtStart( mLastCalendarSync );
1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1302 lse->setCategories( i18n("SyncEvent") ); 1302 lse->setCategories( i18n("SyncEvent") );
1303 lse->setReadOnly( true ); 1303 lse->setReadOnly( true );
1304 mCalendar->addEvent( lse ); 1304 mCalendar->addEvent( lse );
1305 } 1305 }
1306 1306
1307 return lse; 1307 return lse;
1308 1308
1309} 1309}
1310 1310
1311// we check, if the to delete event has a id for a profile 1311// we check, if the to delete event has a id for a profile
1312// if yes, we set this id in the profile to delete 1312// if yes, we set this id in the profile to delete
1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1314{ 1314{
1315 if ( lastSync.count() == 0 ) { 1315 if ( lastSync.count() == 0 ) {
1316 //qDebug(" lastSync.count() == 0"); 1316 //qDebug(" lastSync.count() == 0");
1317 return; 1317 return;
1318 } 1318 }
1319 if ( toDelete->typeID() == journalID ) 1319 if ( toDelete->typeID() == journalID )
1320 return; 1320 return;
1321 1321
1322 Event* eve = lastSync.first(); 1322 Event* eve = lastSync.first();
1323 1323
1324 while ( eve ) { 1324 while ( eve ) {
1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1326 if ( !id.isEmpty() ) { 1326 if ( !id.isEmpty() ) {
1327 QString des = eve->description(); 1327 QString des = eve->description();
1328 QString pref = "e"; 1328 QString pref = "e";
1329 if ( toDelete->typeID() == todoID ) 1329 if ( toDelete->typeID() == todoID )
1330 pref = "t"; 1330 pref = "t";
1331 des += pref+ id + ","; 1331 des += pref+ id + ",";
1332 eve->setReadOnly( false ); 1332 eve->setReadOnly( false );
1333 eve->setDescription( des ); 1333 eve->setDescription( des );
1334 //qDebug("setdes %s ", des.latin1()); 1334 //qDebug("setdes %s ", des.latin1());
1335 eve->setReadOnly( true ); 1335 eve->setReadOnly( true );
1336 } 1336 }
1337 eve = lastSync.next(); 1337 eve = lastSync.next();
1338 } 1338 }
1339 1339
1340} 1340}
1341void CalendarView::checkExternalId( Incidence * inc ) 1341void CalendarView::checkExternalId( Incidence * inc )
1342{ 1342{
1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1344 checkExternSyncEvent( lastSync, inc ); 1344 checkExternSyncEvent( lastSync, inc );
1345 1345
1346} 1346}
1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1348{ 1348{
1349 bool syncOK = true; 1349 bool syncOK = true;
1350 int addedEvent = 0; 1350 int addedEvent = 0;
1351 int addedEventR = 0; 1351 int addedEventR = 0;
1352 int deletedEventR = 0; 1352 int deletedEventR = 0;
1353 int deletedEventL = 0; 1353 int deletedEventL = 0;
1354 int changedLocal = 0; 1354 int changedLocal = 0;
1355 int changedRemote = 0; 1355 int changedRemote = 0;
1356 int filteredIN = 0; 1356 int filteredIN = 0;
1357 int filteredOUT = 0; 1357 int filteredOUT = 0;
1358 //QPtrList<Event> el = local->rawEvents(); 1358 //QPtrList<Event> el = local->rawEvents();
1359 Event* eventR; 1359 Event* eventR;
1360 QString uid; 1360 QString uid;
1361 int take; 1361 int take;
1362 Event* eventRSync; 1362 Event* eventRSync;
1363 Event* eventLSync; 1363 Event* eventLSync;
1364 clearAllViews(); 1364 clearAllViews();
1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1367 bool fullDateRange = false; 1367 bool fullDateRange = false;
1368 local->resetTempSyncStat(); 1368 local->resetTempSyncStat();
1369 mLastCalendarSync = QDateTime::currentDateTime(); 1369 mLastCalendarSync = QDateTime::currentDateTime();
1370 if ( mSyncManager->syncWithDesktop() ) { 1370 if ( mSyncManager->syncWithDesktop() ) {
1371 remote->resetPilotStat(1); 1371 remote->resetPilotStat(1);
1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1375 } else { 1375 } else {
1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1377 } 1377 }
1378 } 1378 }
1379 QDateTime modifiedCalendar = mLastCalendarSync; 1379 QDateTime modifiedCalendar = mLastCalendarSync;
1380 eventLSync = getLastSyncEvent(); 1380 eventLSync = getLastSyncEvent();
1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1382 if ( eventR ) { 1382 if ( eventR ) {
1383 qDebug("last-syncEvent on remote found "); 1383 qDebug("last-syncEvent on remote found ");
1384 eventRSync = (Event*) eventR->clone(); 1384 eventRSync = (Event*) eventR->clone();
1385 remote->deleteEvent(eventR ); 1385 remote->deleteEvent(eventR );
1386 1386
1387 } else { 1387 } else {
1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1389 eventRSync = (Event*)eventLSync->clone(); 1389 eventRSync = (Event*)eventLSync->clone();
1390 } else { 1390 } else {
1391 fullDateRange = true; 1391 fullDateRange = true;
1392 eventRSync = new Event(); 1392 eventRSync = new Event();
1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1395 eventRSync->setDtStart( mLastCalendarSync ); 1395 eventRSync->setDtStart( mLastCalendarSync );
1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1397 eventRSync->setCategories( i18n("SyncEvent") ); 1397 eventRSync->setCategories( i18n("SyncEvent") );
1398 } 1398 }
1399 } 1399 }
1400 if ( eventLSync->dtStart() == mLastCalendarSync ) 1400 if ( eventLSync->dtStart() == mLastCalendarSync )
1401 fullDateRange = true; 1401 fullDateRange = true;
1402 1402
1403 if ( ! fullDateRange ) { 1403 if ( ! fullDateRange ) {
1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1405 1405
1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1408 fullDateRange = true; 1408 fullDateRange = true;
1409 } 1409 }
1410 } 1410 }
1411 if ( mSyncManager->syncWithDesktop() ) { 1411 if ( mSyncManager->syncWithDesktop() ) {
1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1413 } 1413 }
1414 if ( fullDateRange ) 1414 if ( fullDateRange )
1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1416 else 1416 else
1417 mLastCalendarSync = eventLSync->dtStart(); 1417 mLastCalendarSync = eventLSync->dtStart();
1418 // for resyncing if own file has changed 1418 // for resyncing if own file has changed
1419 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1419 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1420 mLastCalendarSync = loadedFileVersion; 1420 mLastCalendarSync = loadedFileVersion;
1421 //qDebug("setting mLastCalendarSync "); 1421 //qDebug("setting mLastCalendarSync ");
1422 } 1422 }
1423 //qDebug("*************************** "); 1423 //qDebug("*************************** ");
1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1425 QPtrList<Incidence> er = remote->rawIncidences(); 1425 QPtrList<Incidence> er = remote->rawIncidences();
1426 Incidence* inR = er.first(); 1426 Incidence* inR = er.first();
1427 Incidence* inL; 1427 Incidence* inL;
1428 QProgressBar bar( er.count(),0 ); 1428 QProgressBar bar( er.count(),0 );
1429 bar.setCaption (i18n("Syncing - close to abort!") ); 1429 bar.setCaption (i18n("Syncing - close to abort!") );
1430 1430
1431 // ************** setting up filter ************* 1431 // ************** setting up filter *************
1432 CalFilter *filterIN = 0; 1432 CalFilter *filterIN = 0;
1433 CalFilter *filterOUT = 0; 1433 CalFilter *filterOUT = 0;
1434 CalFilter *filter = mFilters.first(); 1434 CalFilter *filter = mFilters.first();
1435 while(filter) { 1435 while(filter) {
1436 if ( filter->name() == mSyncManager->mFilterInCal ) 1436 if ( filter->name() == mSyncManager->mFilterInCal )
1437 filterIN = filter; 1437 filterIN = filter;
1438 if ( filter->name() == mSyncManager->mFilterOutCal ) 1438 if ( filter->name() == mSyncManager->mFilterOutCal )
1439 filterOUT = filter; 1439 filterOUT = filter;
1440 filter = mFilters.next(); 1440 filter = mFilters.next();
1441 } 1441 }
1442 int w = 300; 1442 int w = 300;
1443 if ( QApplication::desktop()->width() < 320 ) 1443 if ( QApplication::desktop()->width() < 320 )
1444 w = 220; 1444 w = 220;
1445 int h = bar.sizeHint().height() ; 1445 int h = bar.sizeHint().height() ;
1446 int dw = QApplication::desktop()->width(); 1446 int dw = QApplication::desktop()->width();
1447 int dh = QApplication::desktop()->height(); 1447 int dh = QApplication::desktop()->height();
1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1449 bar.show(); 1449 bar.show();
1450 int modulo = (er.count()/10)+1; 1450 int modulo = (er.count()/10)+1;
1451 int incCounter = 0; 1451 int incCounter = 0;
1452 while ( inR ) { 1452 while ( inR ) {
1453 if ( ! bar.isVisible() ) 1453 if ( ! bar.isVisible() )
1454 return false; 1454 return false;
1455 if ( incCounter % modulo == 0 ) 1455 if ( incCounter % modulo == 0 )
1456 bar.setProgress( incCounter ); 1456 bar.setProgress( incCounter );
1457 ++incCounter; 1457 ++incCounter;
1458 uid = inR->uid(); 1458 uid = inR->uid();
1459 bool skipIncidence = false; 1459 bool skipIncidence = false;
1460 if ( uid.left(15) == QString("last-syncEvent-") ) 1460 if ( uid.left(15) == QString("last-syncEvent-") )
1461 skipIncidence = true; 1461 skipIncidence = true;
1462 QString idS; 1462 QString idS;
1463 qApp->processEvents(); 1463 qApp->processEvents();
1464 if ( !skipIncidence ) { 1464 if ( !skipIncidence ) {
1465 inL = local->incidenceForUid( uid , false ); 1465 inL = local->incidenceForUid( uid , false );
1466 if ( inL ) { // maybe conflict - same uid in both calendars 1466 if ( inL ) { // maybe conflict - same uid in both calendars
1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1468 //qDebug("take %d %s ", take, inL->summary().latin1()); 1468 //qDebug("take %d %s ", take, inL->summary().latin1());
1469 if ( take == 3 ) 1469 if ( take == 3 )
1470 return false; 1470 return false;
1471 if ( take == 1 ) {// take local ********************** 1471 if ( take == 1 ) {// take local **********************
1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1474 else 1474 else
1475 idS = inR->IDStr(); 1475 idS = inR->IDStr();
1476 int calID = inR->calID(); 1476 int calID = inR->calID();
1477 remote->deleteIncidence( inR ); 1477 remote->deleteIncidence( inR );
1478 inR = inL->clone(); 1478 inR = inL->clone();
1479 inR->setCalID( calID ); 1479 inR->setCalID( calID );
1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1482 inR->setIDStr( idS ); 1482 inR->setIDStr( idS );
1483 remote->addIncidence( inR ); 1483 remote->addIncidence( inR );
1484 if ( mSyncManager->syncWithDesktop() ) 1484 if ( mSyncManager->syncWithDesktop() )
1485 inR->setPilotId( 2 ); 1485 inR->setPilotId( 2 );
1486 ++changedRemote; 1486 ++changedRemote;
1487 } else {// take remote ********************** 1487 } else {// take remote **********************
1488 if ( !inL->isReadOnly() ) { 1488 if ( !inL->isReadOnly() ) {
1489 idS = inL->IDStr(); 1489 idS = inL->IDStr();
1490 int pid = inL->pilotId(); 1490 int pid = inL->pilotId();
1491 int calID = inL->calID(); 1491 int calID = inL->calID();
1492 local->deleteIncidence( inL ); 1492 local->deleteIncidence( inL );
1493 inL = inR->clone(); 1493 inL = inR->clone();
1494 inL->setCalID( calID ); 1494 inL->setCalID( calID );
1495 if ( mSyncManager->syncWithDesktop() ) 1495 if ( mSyncManager->syncWithDesktop() )
1496 inL->setPilotId( pid ); 1496 inL->setPilotId( pid );
1497 inL->setIDStr( idS ); 1497 inL->setIDStr( idS );
1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1501 } 1501 }
1502 local->addIncidence( inL ); 1502 local->addIncidence( inL );
1503 ++changedLocal; 1503 ++changedLocal;
1504 } 1504 }
1505 } 1505 }
1506 } 1506 }
1507 } else { // no conflict ********** add or delete remote 1507 } else { // no conflict ********** add or delete remote
1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1510 QString des = eventLSync->description(); 1510 QString des = eventLSync->description();
1511 QString pref = "e"; 1511 QString pref = "e";
1512 if ( inR->typeID() == todoID ) 1512 if ( inR->typeID() == todoID )
1513 pref = "t"; 1513 pref = "t";
1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1516 //remote->deleteIncidence( inR ); 1516 //remote->deleteIncidence( inR );
1517 ++deletedEventR; 1517 ++deletedEventR;
1518 } else { 1518 } else {
1519 inR->setLastModified( modifiedCalendar ); 1519 inR->setLastModified( modifiedCalendar );
1520 inL = inR->clone(); 1520 inL = inR->clone();
1521 inL->setIDStr( ":" ); 1521 inL->setIDStr( ":" );
1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1524 1524
1525 inL->setCalID( 0 );// add to default cal 1525 inL->setCalID( 0 );// add to default cal
1526 local->addIncidence( inL ); 1526 local->addIncidence( inL );
1527 ++addedEvent; 1527 ++addedEvent;
1528 1528
1529 } 1529 }
1530 } else { 1530 } else {
1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1532 inR->setLastModified( modifiedCalendar ); 1532 inR->setLastModified( modifiedCalendar );
1533 inL = inR->clone(); 1533 inL = inR->clone();
1534 inL->setIDStr( ":" ); 1534 inL->setIDStr( ":" );
1535 inL->setCalID( 0 );// add to default cal 1535 inL->setCalID( 0 );// add to default cal
1536 local->addIncidence( inL ); 1536 local->addIncidence( inL );
1537 ++addedEvent; 1537 ++addedEvent;
1538 1538
1539 } else { 1539 } else {
1540 checkExternSyncEvent(eventRSyncSharp, inR); 1540 checkExternSyncEvent(eventRSyncSharp, inR);
1541 remote->deleteIncidence( inR ); 1541 remote->deleteIncidence( inR );
1542 ++deletedEventR; 1542 ++deletedEventR;
1543 } 1543 }
1544 } 1544 }
1545 } else { 1545 } else {
1546 ++filteredIN; 1546 ++filteredIN;
1547 } 1547 }
1548 } 1548 }
1549 } 1549 }
1550 inR = er.next(); 1550 inR = er.next();
1551 } 1551 }
1552 QPtrList<Incidence> el = local->rawIncidences(); 1552 QPtrList<Incidence> el = local->rawIncidences();
1553 inL = el.first(); 1553 inL = el.first();
1554 modulo = (el.count()/10)+1; 1554 modulo = (el.count()/10)+1;
1555 bar.setCaption (i18n("Add / remove events") ); 1555 bar.setCaption (i18n("Add / remove events") );
1556 bar.setTotalSteps ( el.count() ) ; 1556 bar.setTotalSteps ( el.count() ) ;
1557 bar.show(); 1557 bar.show();
1558 incCounter = 0; 1558 incCounter = 0;
1559 1559
1560 while ( inL ) { 1560 while ( inL ) {
1561 1561
1562 qApp->processEvents(); 1562 qApp->processEvents();
1563 if ( ! bar.isVisible() ) 1563 if ( ! bar.isVisible() )
1564 return false; 1564 return false;
1565 if ( incCounter % modulo == 0 ) 1565 if ( incCounter % modulo == 0 )
1566 bar.setProgress( incCounter ); 1566 bar.setProgress( incCounter );
1567 ++incCounter; 1567 ++incCounter;
1568 uid = inL->uid(); 1568 uid = inL->uid();
1569 bool skipIncidence = false; 1569 bool skipIncidence = false;
1570 if ( uid.left(15) == QString("last-syncEvent-") ) 1570 if ( uid.left(15) == QString("last-syncEvent-") )
1571 skipIncidence = true; 1571 skipIncidence = true;
1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1573 skipIncidence = true; 1573 skipIncidence = true;
1574 if ( !skipIncidence ) { 1574 if ( !skipIncidence ) {
1575 inR = remote->incidenceForUid( uid , true ); 1575 inR = remote->incidenceForUid( uid , true );
1576 if ( ! inR ) { 1576 if ( ! inR ) {
1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1578 // no conflict ********** add or delete local 1578 // no conflict ********** add or delete local
1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1581 checkExternSyncEvent(eventLSyncSharp, inL); 1581 checkExternSyncEvent(eventLSyncSharp, inL);
1582 local->deleteIncidence( inL ); 1582 local->deleteIncidence( inL );
1583 ++deletedEventL; 1583 ++deletedEventL;
1584 } else { 1584 } else {
1585 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1585 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1586 inL->removeID(mCurrentSyncDevice ); 1586 inL->removeID(mCurrentSyncDevice );
1587 ++addedEventR; 1587 ++addedEventR;
1588 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1588 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1589 inL->setLastModified( modifiedCalendar ); 1589 inL->setLastModified( modifiedCalendar );
1590 inR = inL->clone(); 1590 inR = inL->clone();
1591 inR->setIDStr( ":" ); 1591 inR->setIDStr( ":" );
1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1593 inR->setCalID( 0 );// add to default cal 1593 inR->setCalID( 0 );// add to default cal
1594 remote->addIncidence( inR ); 1594 remote->addIncidence( inR );
1595 } 1595 }
1596 } 1596 }
1597 } else { 1597 } else {
1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1599 checkExternSyncEvent(eventLSyncSharp, inL); 1599 checkExternSyncEvent(eventLSyncSharp, inL);
1600 local->deleteIncidence( inL ); 1600 local->deleteIncidence( inL );
1601 ++deletedEventL; 1601 ++deletedEventL;
1602 } else { 1602 } else {
1603 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1603 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1604 ++addedEventR; 1604 ++addedEventR;
1605 inL->setLastModified( modifiedCalendar ); 1605 inL->setLastModified( modifiedCalendar );
1606 inR = inL->clone(); 1606 inR = inL->clone();
1607 inR->setIDStr( ":" ); 1607 inR->setIDStr( ":" );
1608 inR->setCalID( 0 );// add to default cal 1608 inR->setCalID( 0 );// add to default cal
1609 remote->addIncidence( inR ); 1609 remote->addIncidence( inR );
1610 } 1610 }
1611 } 1611 }
1612 } 1612 }
1613 } else { 1613 } else {
1614 ++filteredOUT; 1614 ++filteredOUT;
1615 } 1615 }
1616 } 1616 }
1617 } 1617 }
1618 inL = el.next(); 1618 inL = el.next();
1619 } 1619 }
1620 int delFut = 0; 1620 int delFut = 0;
1621 int remRem = 0; 1621 int remRem = 0;
1622 if ( mSyncManager->mWriteBackInFuture ) { 1622 if ( mSyncManager->mWriteBackInFuture ) {
1623 er = remote->rawIncidences(); 1623 er = remote->rawIncidences();
1624 remRem = er.count(); 1624 remRem = er.count();
1625 inR = er.first(); 1625 inR = er.first();
1626 QDateTime dt; 1626 QDateTime dt;
1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1629 while ( inR ) { 1629 while ( inR ) {
1630 if ( inR->typeID() == todoID ) { 1630 if ( inR->typeID() == todoID ) {
1631 Todo * t = (Todo*)inR; 1631 Todo * t = (Todo*)inR;
1632 if ( t->hasDueDate() ) 1632 if ( t->hasDueDate() )
1633 dt = t->dtDue(); 1633 dt = t->dtDue();
1634 else 1634 else
1635 dt = cur.addSecs( 62 ); 1635 dt = cur.addSecs( 62 );
1636 } 1636 }
1637 else if (inR->typeID() == eventID ) { 1637 else if (inR->typeID() == eventID ) {
1638 bool ok; 1638 bool ok;
1639 dt = inR->getNextOccurence( cur, &ok ); 1639 dt = inR->getNextOccurence( cur, &ok );
1640 if ( !ok ) 1640 if ( !ok )
1641 dt = cur.addSecs( -62 ); 1641 dt = cur.addSecs( -62 );
1642 } 1642 }
1643 else 1643 else
1644 dt = inR->dtStart(); 1644 dt = inR->dtStart();
1645 if ( dt < cur || dt > end ) { 1645 if ( dt < cur || dt > end ) {
1646 remote->deleteIncidence( inR ); 1646 remote->deleteIncidence( inR );
1647 ++delFut; 1647 ++delFut;
1648 } 1648 }
1649 inR = er.next(); 1649 inR = er.next();
1650 } 1650 }
1651 } 1651 }
1652 bar.hide(); 1652 bar.hide();
1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1654 eventLSync->setReadOnly( false ); 1654 eventLSync->setReadOnly( false );
1655 eventLSync->setDtStart( mLastCalendarSync ); 1655 eventLSync->setDtStart( mLastCalendarSync );
1656 eventRSync->setDtStart( mLastCalendarSync ); 1656 eventRSync->setDtStart( mLastCalendarSync );
1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1661 eventLSync->setReadOnly( true ); 1661 eventLSync->setReadOnly( true );
1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1664 remote->addEvent( eventRSync ); 1664 remote->addEvent( eventRSync );
1665 else 1665 else
1666 delete eventRSync; 1666 delete eventRSync;
1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1668 QString mes; 1668 QString mes;
1669 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 ); 1669 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 );
1670 QString delmess; 1670 QString delmess;
1671 if ( delFut ) { 1671 if ( delFut ) {
1672 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); 1672 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);
1673 mes += delmess; 1673 mes += delmess;
1674 } 1674 }
1675 mes = i18n("Local calendar changed!\n") +mes; 1675 mes = i18n("Local calendar changed!\n") +mes;
1676 mCalendar->checkAlarmForIncidence( 0, true ); 1676 mCalendar->checkAlarmForIncidence( 0, true );
1677 qDebug( mes ); 1677 qDebug( mes );
1678 if ( mSyncManager->mShowSyncSummary ) { 1678 if ( mSyncManager->mShowSyncSummary ) {
1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1681 qDebug("KO: WB cancelled "); 1681 qDebug("KO: WB cancelled ");
1682 mSyncManager->mWriteBackFile = false; 1682 mSyncManager->mWriteBackFile = false;
1683 return syncOK; 1683 return syncOK;
1684 } 1684 }
1685 } 1685 }
1686 return syncOK; 1686 return syncOK;
1687} 1687}
1688 1688
1689void CalendarView::setSyncDevice( QString s ) 1689void CalendarView::setSyncDevice( QString s )
1690{ 1690{
1691 mCurrentSyncDevice= s; 1691 mCurrentSyncDevice= s;
1692} 1692}
1693void CalendarView::setSyncName( QString s ) 1693void CalendarView::setSyncName( QString s )
1694{ 1694{
1695 mCurrentSyncName= s; 1695 mCurrentSyncName= s;
1696} 1696}
1697bool CalendarView::syncCalendar(QString filename, int mode) 1697bool CalendarView::syncCalendar(QString filename, int mode)
1698{ 1698{
1699 //qDebug("syncCalendar %s ", filename.latin1()); 1699 //qDebug("syncCalendar %s ", filename.latin1());
1700 mGlobalSyncMode = SYNC_MODE_NORMAL; 1700 mGlobalSyncMode = SYNC_MODE_NORMAL;
1701 CalendarLocal* calendar = new CalendarLocal(); 1701 CalendarLocal* calendar = new CalendarLocal();
1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1703 FileStorage* storage = new FileStorage( calendar ); 1703 FileStorage* storage = new FileStorage( calendar );
1704 bool syncOK = false; 1704 bool syncOK = false;
1705 storage->setFileName( filename ); 1705 storage->setFileName( filename );
1706 // qDebug("loading ... "); 1706 // qDebug("loading ... ");
1707 if ( storage->load() ) { 1707 if ( storage->load() ) {
1708 getEventViewerDialog()->setSyncMode( true ); 1708 getEventViewerDialog()->setSyncMode( true );
1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1710 getEventViewerDialog()->setSyncMode( false ); 1710 getEventViewerDialog()->setSyncMode( false );
1711 if ( syncOK ) { 1711 if ( syncOK ) {
1712 if ( mSyncManager->mWriteBackFile ) 1712 if ( mSyncManager->mWriteBackFile )
1713 { 1713 {
1714 storage->setSaveFormat( new ICalFormat() ); 1714 storage->setSaveFormat( new ICalFormat() );
1715 storage->save(); 1715 storage->save();
1716 } 1716 }
1717 } 1717 }
1718 setModified( true ); 1718 setModified( true );
1719 } 1719 }
1720 delete storage; 1720 delete storage;
1721 delete calendar; 1721 delete calendar;
1722 if ( syncOK ) 1722 if ( syncOK )
1723 updateView(); 1723 updateView();
1724 return syncOK; 1724 return syncOK;
1725} 1725}
1726 1726
1727void CalendarView::syncExternal( int mode ) 1727void CalendarView::syncExternal( int mode )
1728{ 1728{
1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1730 1730
1731 qApp->processEvents(); 1731 qApp->processEvents();
1732 CalendarLocal* calendar = new CalendarLocal(); 1732 CalendarLocal* calendar = new CalendarLocal();
1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1734 bool syncOK = false; 1734 bool syncOK = false;
1735 bool loadSuccess = false; 1735 bool loadSuccess = false;
1736 PhoneFormat* phoneFormat = 0; 1736 PhoneFormat* phoneFormat = 0;
1737 emit tempDisableBR(true); 1737 emit tempDisableBR(true);
1738#ifndef DESKTOP_VERSION 1738#ifndef DESKTOP_VERSION
1739 SharpFormat* sharpFormat = 0; 1739 SharpFormat* sharpFormat = 0;
1740 if ( mode == 0 ) { // sharp 1740 if ( mode == 0 ) { // sharp
1741 sharpFormat = new SharpFormat () ; 1741 sharpFormat = new SharpFormat () ;
1742 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1742 loadSuccess = sharpFormat->load( calendar, mCalendar );
1743 1743
1744 } else 1744 } else
1745#endif 1745#endif
1746 if ( mode == 1 ) { // phone 1746 if ( mode == 1 ) { // phone
1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1748 mSyncManager->mPhoneDevice, 1748 mSyncManager->mPhoneDevice,
1749 mSyncManager->mPhoneConnection, 1749 mSyncManager->mPhoneConnection,
1750 mSyncManager->mPhoneModel); 1750 mSyncManager->mPhoneModel);
1751 loadSuccess = phoneFormat->load( calendar,mCalendar); 1751 loadSuccess = phoneFormat->load( calendar,mCalendar);
1752 1752
1753 } else { 1753 } else {
1754 emit tempDisableBR(false); 1754 emit tempDisableBR(false);
1755 return; 1755 return;
1756 } 1756 }
1757 if ( loadSuccess ) { 1757 if ( loadSuccess ) {
1758 getEventViewerDialog()->setSyncMode( true ); 1758 getEventViewerDialog()->setSyncMode( true );
1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1760 getEventViewerDialog()->setSyncMode( false ); 1760 getEventViewerDialog()->setSyncMode( false );
1761 qApp->processEvents(); 1761 qApp->processEvents();
1762 if ( syncOK ) { 1762 if ( syncOK ) {
1763 if ( mSyncManager->mWriteBackFile ) 1763 if ( mSyncManager->mWriteBackFile )
1764 { 1764 {
1765 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1765 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1766 Incidence* inc = iL.first(); 1766 Incidence* inc = iL.first();
1767 if ( phoneFormat ) { 1767 if ( phoneFormat ) {
1768 while ( inc ) { 1768 while ( inc ) {
1769 inc->removeID(mCurrentSyncDevice); 1769 inc->removeID(mCurrentSyncDevice);
1770 inc = iL.next(); 1770 inc = iL.next();
1771 } 1771 }
1772 } 1772 }
1773#ifndef DESKTOP_VERSION 1773#ifndef DESKTOP_VERSION
1774 if ( sharpFormat ) 1774 if ( sharpFormat )
1775 sharpFormat->save(calendar); 1775 sharpFormat->save(calendar);
1776#endif 1776#endif
1777 if ( phoneFormat ) 1777 if ( phoneFormat )
1778 phoneFormat->save(calendar); 1778 phoneFormat->save(calendar);
1779 iL = calendar->rawIncidences(); 1779 iL = calendar->rawIncidences();
1780 inc = iL.first(); 1780 inc = iL.first();
1781 Incidence* loc; 1781 Incidence* loc;
1782 while ( inc ) { 1782 while ( inc ) {
1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1784 loc = mCalendar->incidence(inc->uid() ); 1784 loc = mCalendar->incidence(inc->uid() );
1785 if ( loc ) { 1785 if ( loc ) {
1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1788 } 1788 }
1789 } 1789 }
1790 inc = iL.next(); 1790 inc = iL.next();
1791 } 1791 }
1792 Incidence* lse = getLastSyncEvent(); 1792 Incidence* lse = getLastSyncEvent();
1793 if ( lse ) { 1793 if ( lse ) {
1794 lse->setReadOnly( false ); 1794 lse->setReadOnly( false );
1795 lse->setDescription( "" ); 1795 lse->setDescription( "" );
1796 lse->setReadOnly( true ); 1796 lse->setReadOnly( true );
1797 } 1797 }
1798 } 1798 }
1799 } else { 1799 } else {
1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1801 } 1801 }
1802 setModified( true ); 1802 setModified( true );
1803 } else { 1803 } else {
1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1806 question, i18n("Ok")) ; 1806 question, i18n("Ok")) ;
1807 1807
1808 } 1808 }
1809 delete calendar; 1809 delete calendar;
1810 updateView(); 1810 updateView();
1811 emit tempDisableBR(false); 1811 emit tempDisableBR(false);
1812 return ;//syncOK; 1812 return ;//syncOK;
1813 1813
1814} 1814}
1815 1815
1816bool CalendarView::importBday() 1816bool CalendarView::importBday()
1817{ 1817{
1818#ifndef KORG_NOKABC 1818#ifndef KORG_NOKABC
1819 1819
1820#ifdef DESKTOP_VERSION 1820#ifdef DESKTOP_VERSION
1821 int curCal = mCalendar->defaultCalendar(); 1821 int curCal = mCalendar->defaultCalendar();
1822 int bd = mCalEditView->getBirtdayID(); 1822 int bd = mCalEditView->getBirtdayID();
1823 if ( bd == 0 ) 1823 if ( bd == 0 )
1824 return false; 1824 return false;
1825 mCalendar->setDefaultCalendar( bd ); 1825 mCalendar->setDefaultCalendar( bd );
1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1827 KABC::AddressBook::Iterator it; 1827 KABC::AddressBook::Iterator it;
1828 int count = 0; 1828 int count = 0;
1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1830 ++count; 1830 ++count;
1831 } 1831 }
1832 QProgressBar bar(count,0 ); 1832 QProgressBar bar(count,0 );
1833 int w = 300; 1833 int w = 300;
1834 if ( QApplication::desktop()->width() < 320 ) 1834 if ( QApplication::desktop()->width() < 320 )
1835 w = 220; 1835 w = 220;
1836 int h = bar.sizeHint().height() ; 1836 int h = bar.sizeHint().height() ;
1837 int dw = QApplication::desktop()->width(); 1837 int dw = QApplication::desktop()->width();
1838 int dh = QApplication::desktop()->height(); 1838 int dh = QApplication::desktop()->height();
1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1840 bar.show(); 1840 bar.show();
1841 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1841 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1842 qApp->processEvents(); 1842 qApp->processEvents();
1843 count = 0; 1843 count = 0;
1844 int addCount = 0; 1844 int addCount = 0;
1845 KCal::Attendee* a = 0; 1845 KCal::Attendee* a = 0;
1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1847 if ( ! bar.isVisible() ) 1847 if ( ! bar.isVisible() )
1848 return false; 1848 return false;
1849 bar.setProgress( count++ ); 1849 bar.setProgress( count++ );
1850 qApp->processEvents(); 1850 qApp->processEvents();
1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1852 if ( (*it).birthday().date().isValid() ){ 1852 if ( (*it).birthday().date().isValid() ){
1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1855 ++addCount; 1855 ++addCount;
1856 } 1856 }
1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1858 if ( anni.isValid() ){ 1858 if ( anni.isValid() ){
1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1861 ++addCount; 1861 ++addCount;
1862 } 1862 }
1863 } 1863 }
1864 mCalendar->setDefaultCalendar( curCal ); 1864 mCalendar->setDefaultCalendar( curCal );
1865 updateView(); 1865 updateView();
1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1867#else //DESKTOP_VERSION 1867#else //DESKTOP_VERSION
1868 1868
1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1870 // the result should now arrive through method insertBirthdays 1870 // the result should now arrive through method insertBirthdays
1871 1871
1872#endif //DESKTOP_VERSION 1872#endif //DESKTOP_VERSION
1873 1873
1874#endif //KORG_NOKABC 1874#endif //KORG_NOKABC
1875 1875
1876 1876
1877 return true; 1877 return true;
1878} 1878}
1879 1879
1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1882 const QStringList& anniversaryList, const QStringList& realNameList, 1882 const QStringList& anniversaryList, const QStringList& realNameList,
1883 const QStringList& emailList, const QStringList& assembledNameList, 1883 const QStringList& emailList, const QStringList& assembledNameList,
1884 const QStringList& uidList) 1884 const QStringList& uidList)
1885{ 1885{
1886 1886
1887 //qDebug("KO::CalendarView::insertBirthdays"); 1887 //qDebug("KO::CalendarView::insertBirthdays");
1888 if (uid == this->name()) 1888 if (uid == this->name())
1889 { 1889 {
1890 int curCal = mCalendar->defaultCalendar(); 1890 int curCal = mCalendar->defaultCalendar();
1891 int bd = mCalEditView->getBirtdayID(); 1891 int bd = mCalEditView->getBirtdayID();
1892 if ( bd == 0 ) 1892 if ( bd == 0 )
1893 return; 1893 return;
1894 mCalendar->setDefaultCalendar( bd ); 1894 mCalendar->setDefaultCalendar( bd );
1895 1895
1896 1896
1897 int count = birthdayList.count(); 1897 int count = birthdayList.count();
1898 int addCount = 0; 1898 int addCount = 0;
1899 KCal::Attendee* a = 0; 1899 KCal::Attendee* a = 0;
1900 1900
1901 //qDebug("CalView 1 %i", count); 1901 //qDebug("CalView 1 %i", count);
1902 1902
1903 QProgressBar bar(count,0 ); 1903 QProgressBar bar(count,0 );
1904 int w = 300; 1904 int w = 300;
1905 if ( QApplication::desktop()->width() < 320 ) 1905 if ( QApplication::desktop()->width() < 320 )
1906 w = 220; 1906 w = 220;
1907 int h = bar.sizeHint().height() ; 1907 int h = bar.sizeHint().height() ;
1908 int dw = QApplication::desktop()->width(); 1908 int dw = QApplication::desktop()->width();
1909 int dh = QApplication::desktop()->height(); 1909 int dh = QApplication::desktop()->height();
1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1911 bar.show(); 1911 bar.show();
1912 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1912 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1913 qApp->processEvents(); 1913 qApp->processEvents();
1914 1914
1915 QDate birthday; 1915 QDate birthday;
1916 QDate anniversary; 1916 QDate anniversary;
1917 QString realName; 1917 QString realName;
1918 QString email; 1918 QString email;
1919 QString assembledName; 1919 QString assembledName;
1920 QString uid; 1920 QString uid;
1921 bool ok = true; 1921 bool ok = true;
1922 for ( int i = 0; i < count; i++) 1922 for ( int i = 0; i < count; i++)
1923 { 1923 {
1924 if ( ! bar.isVisible() ) 1924 if ( ! bar.isVisible() )
1925 return; 1925 return;
1926 bar.setProgress( i ); 1926 bar.setProgress( i );
1927 qApp->processEvents(); 1927 qApp->processEvents();
1928 1928
1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1930 if (!ok) { 1930 if (!ok) {
1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1932 } 1932 }
1933 1933
1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1935 if (!ok) { 1935 if (!ok) {
1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1937 } 1937 }
1938 realName = realNameList[i]; 1938 realName = realNameList[i];
1939 email = emailList[i]; 1939 email = emailList[i];
1940 assembledName = assembledNameList[i]; 1940 assembledName = assembledNameList[i];
1941 uid = uidList[i]; 1941 uid = uidList[i];
1942 //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() ); 1942 //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() );
1943 1943
1944 if ( birthday.isValid() ){ 1944 if ( birthday.isValid() ){
1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1946 KCal::Attendee::ReqParticipant,uid) ; 1946 KCal::Attendee::ReqParticipant,uid) ;
1947 if ( addAnniversary( birthday, assembledName, a, true ) ) 1947 if ( addAnniversary( birthday, assembledName, a, true ) )
1948 ++addCount; 1948 ++addCount;
1949 } 1949 }
1950 1950
1951 if ( anniversary.isValid() ){ 1951 if ( anniversary.isValid() ){
1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1953 KCal::Attendee::ReqParticipant,uid) ; 1953 KCal::Attendee::ReqParticipant,uid) ;
1954 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1954 if ( addAnniversary( anniversary, assembledName, a, false ) )
1955 ++addCount; 1955 ++addCount;
1956 } 1956 }
1957 } 1957 }
1958 1958
1959 mCalendar->setDefaultCalendar( curCal ); 1959 mCalendar->setDefaultCalendar( curCal );
1960 updateView(); 1960 updateView();
1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1962 1962
1963 } 1963 }
1964 1964
1965} 1965}
1966 1966
1967 1967
1968 1968
1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1970{ 1970{
1971 //qDebug("addAnni "); 1971 //qDebug("addAnni ");
1972 Event * ev = new Event(); 1972 Event * ev = new Event();
1973 ev->setOrganizer(KOPrefs::instance()->email()); 1973 ev->setOrganizer(KOPrefs::instance()->email());
1974 if ( a ) { 1974 if ( a ) {
1975 ev->addAttendee( a ); 1975 ev->addAttendee( a );
1976 } 1976 }
1977 QString kind; 1977 QString kind;
1978 if ( birthday ) { 1978 if ( birthday ) {
1979 kind = i18n( "Birthday" ); 1979 kind = i18n( "Birthday" );
1980 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1980 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1981 } 1981 }
1982 else { 1982 else {
1983 kind = i18n( "Anniversary" ); 1983 kind = i18n( "Anniversary" );
1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1985 } 1985 }
1986 ev->setCategories( kind ); 1986 ev->setCategories( kind );
1987 ev->setDtStart( QDateTime(date) ); 1987 ev->setDtStart( QDateTime(date) );
1988 ev->setDtEnd( QDateTime(date) ); 1988 ev->setDtEnd( QDateTime(date) );
1989 ev->setFloats( true ); 1989 ev->setFloats( true );
1990 Recurrence * rec = ev->recurrence(); 1990 Recurrence * rec = ev->recurrence();
1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1992 rec->addYearlyNum( date.month() ); 1992 rec->addYearlyNum( date.month() );
1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1994 delete ev; 1994 delete ev;
1995 return false; 1995 return false;
1996 } 1996 }
1997 return true; 1997 return true;
1998 1998
1999} 1999}
2000bool CalendarView::importQtopia( const QString &categories, 2000bool CalendarView::importQtopia( const QString &categories,
2001 const QString &datebook, 2001 const QString &datebook,
2002 const QString &todolist ) 2002 const QString &todolist )
2003{ 2003{
2004 2004
2005 QtopiaFormat qtopiaFormat; 2005 QtopiaFormat qtopiaFormat;
2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2010 2010
2011 updateView(); 2011 updateView();
2012 return true; 2012 return true;
2013 2013
2014#if 0 2014#if 0
2015 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2015 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2016 mCurrentSyncDevice = "qtopia-XML"; 2016 mCurrentSyncDevice = "qtopia-XML";
2017 if ( mSyncManager->mAskForPreferences ) 2017 if ( mSyncManager->mAskForPreferences )
2018 edit_sync_options(); 2018 edit_sync_options();
2019 qApp->processEvents(); 2019 qApp->processEvents();
2020 CalendarLocal* calendar = new CalendarLocal(); 2020 CalendarLocal* calendar = new CalendarLocal();
2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2022 bool syncOK = false; 2022 bool syncOK = false;
2023 QtopiaFormat qtopiaFormat; 2023 QtopiaFormat qtopiaFormat;
2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2025 bool loadOk = true; 2025 bool loadOk = true;
2026 if ( !categories.isEmpty() ) 2026 if ( !categories.isEmpty() )
2027 loadOk = qtopiaFormat.load( calendar, categories ); 2027 loadOk = qtopiaFormat.load( calendar, categories );
2028 if ( loadOk && !datebook.isEmpty() ) 2028 if ( loadOk && !datebook.isEmpty() )
2029 loadOk = qtopiaFormat.load( calendar, datebook ); 2029 loadOk = qtopiaFormat.load( calendar, datebook );
2030 if ( loadOk && !todolist.isEmpty() ) 2030 if ( loadOk && !todolist.isEmpty() )
2031 loadOk = qtopiaFormat.load( calendar, todolist ); 2031 loadOk = qtopiaFormat.load( calendar, todolist );
2032 2032
2033 if ( loadOk ) { 2033 if ( loadOk ) {
2034 getEventViewerDialog()->setSyncMode( true ); 2034 getEventViewerDialog()->setSyncMode( true );
2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2036 getEventViewerDialog()->setSyncMode( false ); 2036 getEventViewerDialog()->setSyncMode( false );
2037 qApp->processEvents(); 2037 qApp->processEvents();
2038 if ( syncOK ) { 2038 if ( syncOK ) {
2039 if ( mSyncManager->mWriteBackFile ) 2039 if ( mSyncManager->mWriteBackFile )
2040 { 2040 {
2041 // write back XML file 2041 // write back XML file
2042 2042
2043 } 2043 }
2044 setModified( true ); 2044 setModified( true );
2045 } 2045 }
2046 } else { 2046 } else {
2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2049 question, i18n("Ok")) ; 2049 question, i18n("Ok")) ;
2050 } 2050 }
2051 delete calendar; 2051 delete calendar;
2052 updateView(); 2052 updateView();
2053 return syncOK; 2053 return syncOK;
2054 2054
2055 2055
2056#endif 2056#endif
2057 2057
2058} 2058}
2059 2059
2060void CalendarView::setSyncEventsReadOnly() 2060void CalendarView::setSyncEventsReadOnly()
2061{ 2061{
2062 mCalendar->setSyncEventsReadOnly(); 2062 mCalendar->setSyncEventsReadOnly();
2063} 2063}
2064 2064
2065bool CalendarView::loadCalendars() 2065bool CalendarView::loadCalendars()
2066{ 2066{
2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2068 KopiCalendarFile * cal = calendars.first(); 2068 KopiCalendarFile * cal = calendars.first();
2069 mCalendar->setDefaultCalendar( 1 ); 2069 mCalendar->setDefaultCalendar( 1 );
2070 openCalendar( MainWindow::defaultFileName(), false ); 2070 openCalendar( MainWindow::defaultFileName(), false );
2071 cal = calendars.next(); 2071 cal = calendars.next();
2072 while ( cal ) { 2072 while ( cal ) {
2073 addCalendar( cal ); 2073 addCalendar( cal );
2074 cal = calendars.next(); 2074 cal = calendars.next();
2075 } 2075 }
2076 restoreCalendarSettings(); 2076 restoreCalendarSettings();
2077 return true; 2077 return true;
2078} 2078}
2079bool CalendarView::restoreCalendarSettings() 2079bool CalendarView::restoreCalendarSettings()
2080{ 2080{
2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2082 KopiCalendarFile * cal = calendars.first(); 2082 KopiCalendarFile * cal = calendars.first();
2083 while ( cal ) { 2083 while ( cal ) {
2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2087 if ( cal->isStandard ) 2087 if ( cal->isStandard )
2088 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2088 mCalendar->setDefaultCalendar( cal->mCalNumber );
2089 cal = calendars.next(); 2089 cal = calendars.next();
2090 } 2090 }
2091 setSyncEventsReadOnly(); 2091 setSyncEventsReadOnly();
2092 mCalendar->reInitAlarmSettings(); 2092 mCalendar->reInitAlarmSettings();
2093 updateUnmanagedViews(); 2093 updateUnmanagedViews();
2094 updateView(); 2094 updateView();
2095 return true; 2095 return true;
2096} 2096}
2097void CalendarView::addCalendarId( int id ) 2097void CalendarView::addCalendarId( int id )
2098{ 2098{
2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2100 if ( cal ) 2100 if ( cal )
2101 addCalendar( cal ); 2101 addCalendar( cal );
2102} 2102}
2103bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2103bool CalendarView::addCalendar( KopiCalendarFile * cal )
2104{ 2104{
2105 cal->mErrorOnLoad = false; 2105 cal->mErrorOnLoad = false;
2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2107 cal->mLoadDt = QDateTime::currentDateTime(); 2107 cal->mLoadDt = QDateTime::currentDateTime();
2108 return true; 2108 return true;
2109 } 2109 }
2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2111 cal->mErrorOnLoad = true; 2111 cal->mErrorOnLoad = true;
2112 return false; 2112 return false;
2113} 2113}
2114bool CalendarView::openCalendar(QString filename, bool merge) 2114bool CalendarView::openCalendar(QString filename, bool merge)
2115{ 2115{
2116 2116
2117 if (filename.isEmpty()) { 2117 if (filename.isEmpty()) {
2118 return false; 2118 return false;
2119 } 2119 }
2120 2120
2121 if (!QFile::exists(filename)) { 2121 if (!QFile::exists(filename)) {
2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2123 return false; 2123 return false;
2124 } 2124 }
2125 2125
2126 globalFlagBlockAgenda = 1; 2126 globalFlagBlockAgenda = 1;
2127 clearAllViews(); 2127 clearAllViews();
2128 if (!merge) { 2128 if (!merge) {
2129 mViewManager->setDocumentId( filename ); 2129 mViewManager->setDocumentId( filename );
2130 mCalendar->close(); 2130 mCalendar->close();
2131 } 2131 }
2132 mStorage->setFileName( filename ); 2132 mStorage->setFileName( filename );
2133 2133
2134 if ( mStorage->load() ) { 2134 if ( mStorage->load() ) {
2135 if ( merge ) ;//setModified( true ); 2135 if ( merge ) ;//setModified( true );
2136 else { 2136 else {
2137 //setModified( true ); 2137 //setModified( true );
2138 mViewManager->setDocumentId( filename ); 2138 mViewManager->setDocumentId( filename );
2139 mDialogManager->setDocumentId( filename ); 2139 mDialogManager->setDocumentId( filename );
2140 mTodoList->setDocumentId( filename ); 2140 mTodoList->setDocumentId( filename );
2141 } 2141 }
2142 globalFlagBlockAgenda = 2; 2142 globalFlagBlockAgenda = 2;
2143 // if ( getLastSyncEvent() ) 2143 // if ( getLastSyncEvent() )
2144 // getLastSyncEvent()->setReadOnly( true ); 2144 // getLastSyncEvent()->setReadOnly( true );
2145 mCalendar->reInitAlarmSettings(); 2145 mCalendar->reInitAlarmSettings();
2146 setSyncEventsReadOnly(); 2146 setSyncEventsReadOnly();
2147 updateUnmanagedViews(); 2147 updateUnmanagedViews();
2148 updateView(); 2148 updateView();
2149 if ( filename != MainWindow::defaultFileName() ) { 2149 if ( filename != MainWindow::defaultFileName() ) {
2150 saveCalendar( MainWindow::defaultFileName() ); 2150 saveCalendar( MainWindow::defaultFileName() );
2151 } else { 2151 } else {
2152 QFileInfo finf ( MainWindow::defaultFileName()); 2152 QFileInfo finf ( MainWindow::defaultFileName());
2153 if ( finf.exists() ) { 2153 if ( finf.exists() ) {
2154 setLoadedFileVersion( finf.lastModified () ); 2154 setLoadedFileVersion( finf.lastModified () );
2155 } 2155 }
2156 } 2156 }
2157 return true; 2157 return true;
2158 } else { 2158 } else {
2159 // while failing to load, the calendar object could 2159 // while failing to load, the calendar object could
2160 // have become partially populated. Clear it out. 2160 // have become partially populated. Clear it out.
2161 if ( !merge ) { 2161 if ( !merge ) {
2162 mCalendar->close(); 2162 mCalendar->close();
2163 mViewManager->setDocumentId( filename ); 2163 mViewManager->setDocumentId( filename );
2164 mDialogManager->setDocumentId( filename ); 2164 mDialogManager->setDocumentId( filename );
2165 mTodoList->setDocumentId( filename ); 2165 mTodoList->setDocumentId( filename );
2166 } 2166 }
2167 2167
2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2169 2169
2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2171 globalFlagBlockAgenda = 2; 2171 globalFlagBlockAgenda = 2;
2172 mCalendar->reInitAlarmSettings(); 2172 mCalendar->reInitAlarmSettings();
2173 setSyncEventsReadOnly(); 2173 setSyncEventsReadOnly();
2174 updateUnmanagedViews(); 2174 updateUnmanagedViews();
2175 updateView(); 2175 updateView();
2176 } 2176 }
2177 return false; 2177 return false;
2178} 2178}
2179void CalendarView::mergeFile( QString fn ) 2179void CalendarView::mergeFile( QString fn )
2180{ 2180{
2181 clearAllViews(); 2181 clearAllViews();
2182 mCalendar->mergeCalendarFile( fn ); 2182 mCalendar->mergeCalendarFile( fn );
2183 mCalendar->reInitAlarmSettings(); 2183 mCalendar->reInitAlarmSettings();
2184 setSyncEventsReadOnly(); 2184 setSyncEventsReadOnly();
2185 updateUnmanagedViews(); 2185 updateUnmanagedViews();
2186 updateView(); 2186 updateView();
2187} 2187}
2188void CalendarView::showOpenError() 2188void CalendarView::showOpenError()
2189{ 2189{
2190 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2190 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2191} 2191}
2192void CalendarView::setLoadedFileVersion(QDateTime dt) 2192void CalendarView::setLoadedFileVersion(QDateTime dt)
2193{ 2193{
2194 loadedFileVersion = dt; 2194 loadedFileVersion = dt;
2195} 2195}
2196bool CalendarView::checkFileChanged(QString fn) 2196bool CalendarView::checkFileChanged(QString fn)
2197{ 2197{
2198 QFileInfo finf ( fn ); 2198 QFileInfo finf ( fn );
2199 if ( !finf.exists() ) 2199 if ( !finf.exists() )
2200 return true; 2200 return true;
2201 QDateTime dt = finf.lastModified (); 2201 QDateTime dt = finf.lastModified ();
2202 if ( dt <= loadedFileVersion ) 2202 if ( dt <= loadedFileVersion )
2203 return false; 2203 return false;
2204 return true; 2204 return true;
2205 2205
2206} 2206}
2207void CalendarView::watchSavedFile() 2207void CalendarView::watchSavedFile()
2208{ 2208{
2209 QFileInfo finf ( MainWindow::defaultFileName()); 2209 QFileInfo finf ( MainWindow::defaultFileName());
2210 if ( !finf.exists() ) 2210 if ( !finf.exists() )
2211 return; 2211 return;
2212 QDateTime dt = finf.lastModified (); 2212 QDateTime dt = finf.lastModified ();
2213 if ( dt < loadedFileVersion ) { 2213 if ( dt < loadedFileVersion ) {
2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2216 return; 2216 return;
2217 } 2217 }
2218 loadedFileVersion = dt; 2218 loadedFileVersion = dt;
2219} 2219}
2220bool CalendarView::checkAllFileVersions() 2220bool CalendarView::checkAllFileVersions()
2221{ 2221{
2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2223 KopiCalendarFile * cal = calendars.first(); 2223 KopiCalendarFile * cal = calendars.first();
2224 mCalendar->setDefaultCalendar( 1 ); 2224 mCalendar->setDefaultCalendar( 1 );
2225 mCalendar->setDefaultCalendarEnabledOnly(); 2225 mCalendar->setDefaultCalendarEnabledOnly();
2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2227 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2227 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2228 restoreCalendarSettings(); 2228 restoreCalendarSettings();
2229 return false; 2229 return false;
2230 } 2230 }
2231 } 2231 }
2232 cal = calendars.next(); 2232 cal = calendars.next();
2233 QDateTime storeTemp = loadedFileVersion; 2233 QDateTime storeTemp = loadedFileVersion;
2234 while ( cal ) { 2234 while ( cal ) {
2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2236 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2236 mCalendar->setDefaultCalendar( cal->mCalNumber );
2237 mCalendar->setDefaultCalendarEnabledOnly(); 2237 mCalendar->setDefaultCalendarEnabledOnly();
2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2239 if ( !checkFileVersion(cal->mFileName )) { 2239 if ( !checkFileVersion(cal->mFileName )) {
2240 loadedFileVersion = storeTemp; 2240 loadedFileVersion = storeTemp;
2241 restoreCalendarSettings(); 2241 restoreCalendarSettings();
2242 return false; 2242 return false;
2243 } 2243 }
2244 } 2244 }
2245 cal = calendars.next(); 2245 cal = calendars.next();
2246 } 2246 }
2247 loadedFileVersion = storeTemp; 2247 loadedFileVersion = storeTemp;
2248 return true; 2248 return true;
2249} 2249}
2250bool CalendarView::checkFileVersion(QString fn) 2250bool CalendarView::checkFileVersion(QString fn)
2251{ 2251{
2252 QFileInfo finf ( fn ); 2252 QFileInfo finf ( fn );
2253 if ( !finf.exists() ) 2253 if ( !finf.exists() )
2254 return true; 2254 return true;
2255 QDateTime dt = finf.lastModified (); 2255 QDateTime dt = finf.lastModified ();
2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2258 if ( dt <= loadedFileVersion ) 2258 if ( dt <= loadedFileVersion )
2259 return true; 2259 return true;
2260 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)) , 2260 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)) ,
2261 i18n("KO/Pi Warning"),i18n("Overwrite"), 2261 i18n("KO/Pi Warning"),i18n("Overwrite"),
2262 i18n("Sync+save")); 2262 i18n("Sync+save"));
2263 2263
2264 if ( km == KMessageBox::Cancel ) 2264 if ( km == KMessageBox::Cancel )
2265 return false; 2265 return false;
2266 if ( km == KMessageBox::Yes ) 2266 if ( km == KMessageBox::Yes )
2267 return true; 2267 return true;
2268 2268
2269 setSyncDevice("deleteaftersync" ); 2269 setSyncDevice("deleteaftersync" );
2270 mSyncManager->mAskForPreferences = true; 2270 mSyncManager->mAskForPreferences = true;
2271 mSyncManager->mSyncAlgoPrefs = 3; 2271 mSyncManager->mSyncAlgoPrefs = 3;
2272 mSyncManager->mWriteBackFile = false; 2272 mSyncManager->mWriteBackFile = false;
2273 mSyncManager->mWriteBackExistingOnly = false; 2273 mSyncManager->mWriteBackExistingOnly = false;
2274 mSyncManager->mShowSyncSummary = false; 2274 mSyncManager->mShowSyncSummary = false;
2275 syncCalendar( fn, 3 ); 2275 syncCalendar( fn, 3 );
2276 Event * e = getLastSyncEvent(); 2276 Event * e = getLastSyncEvent();
2277 if ( e ) 2277 if ( e )
2278 mCalendar->deleteEvent( e ); 2278 mCalendar->deleteEvent( e );
2279 return true; 2279 return true;
2280} 2280}
2281bool CalendarView::saveCalendars() 2281bool CalendarView::saveCalendars()
2282{ 2282{
2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2284 KopiCalendarFile * cal = calendars.first(); 2284 KopiCalendarFile * cal = calendars.first();
2285 mCalendar->setDefaultCalendar( 1 ); 2285 mCalendar->setDefaultCalendar( 1 );
2286 mCalendar->setDefaultCalendarEnabledOnly(); 2286 mCalendar->setDefaultCalendarEnabledOnly();
2287 saveCalendar( MainWindow::defaultFileName() ); 2287 saveCalendar( MainWindow::defaultFileName() );
2288 cal = calendars.next(); 2288 cal = calendars.next();
2289 while ( cal ) { 2289 while ( cal ) {
2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2291 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2291 mCalendar->setDefaultCalendar( cal->mCalNumber );
2292 mCalendar->setDefaultCalendarEnabledOnly(); 2292 mCalendar->setDefaultCalendarEnabledOnly();
2293 if ( saveCalendar( cal->mFileName ) ) 2293 if ( saveCalendar( cal->mFileName ) )
2294 cal->mLoadDt = QDateTime::currentDateTime(); 2294 cal->mLoadDt = QDateTime::currentDateTime();
2295 } 2295 }
2296 cal = calendars.next(); 2296 cal = calendars.next();
2297 } 2297 }
2298 restoreCalendarSettings(); 2298 restoreCalendarSettings();
2299 return true; 2299 return true;
2300} 2300}
2301bool CalendarView::saveCalendar( QString filename ) 2301bool CalendarView::saveCalendar( QString filename )
2302{ 2302{
2303 2303
2304 // Store back all unsaved data into calendar object 2304 // Store back all unsaved data into calendar object
2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2306 if ( mViewManager->currentView() ) 2306 if ( mViewManager->currentView() )
2307 mViewManager->currentView()->flushView(); 2307 mViewManager->currentView()->flushView();
2308 2308
2309 2309
2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2311 mStorage->setSaveFormat( new ICalFormat() ); 2311 mStorage->setSaveFormat( new ICalFormat() );
2312 mStorage->setFileName( filename ); 2312 mStorage->setFileName( filename );
2313 bool success; 2313 bool success;
2314 success = mStorage->save(); 2314 success = mStorage->save();
2315 if ( !success ) { 2315 if ( !success ) {
2316 return false; 2316 return false;
2317 } 2317 }
2318 if ( filename == MainWindow::defaultFileName() ) { 2318 if ( filename == MainWindow::defaultFileName() ) {
2319 setLoadedFileVersion( lfv ); 2319 setLoadedFileVersion( lfv );
2320 watchSavedFile(); 2320 watchSavedFile();
2321 } 2321 }
2322 return true; 2322 return true;
2323} 2323}
2324 2324
2325void CalendarView::closeCalendar() 2325void CalendarView::closeCalendar()
2326{ 2326{
2327 2327
2328 // child windows no longer valid 2328 // child windows no longer valid
2329 clearAllViews(); 2329 clearAllViews();
2330 emit closingDown(); 2330 emit closingDown();
2331 2331
2332 mCalendar->close(); 2332 mCalendar->close();
2333 setModified(false); 2333 setModified(false);
2334 updateView(); 2334 updateView();
2335} 2335}
2336 2336
2337void CalendarView::archiveCalendar() 2337void CalendarView::archiveCalendar()
2338{ 2338{
2339 mDialogManager->showArchiveDialog(); 2339 mDialogManager->showArchiveDialog();
2340} 2340}
2341 2341
2342 2342
2343void CalendarView::readSettings() 2343void CalendarView::readSettings()
2344{ 2344{
2345 2345
2346 2346
2347 // mViewManager->showAgendaView(); 2347 // mViewManager->showAgendaView();
2348 QString str; 2348 QString str;
2349 //qDebug("CalendarView::readSettings() "); 2349 //qDebug("CalendarView::readSettings() ");
2350 // read settings from the KConfig, supplying reasonable 2350 // read settings from the KConfig, supplying reasonable
2351 // defaults where none are to be found 2351 // defaults where none are to be found
2352 KConfig *config = KOGlobals::config(); 2352 KConfig *config = KOGlobals::config();
2353#ifndef KORG_NOSPLITTER 2353#ifndef KORG_NOSPLITTER
2354 config->setGroup("KOrganizer Geometry"); 2354 config->setGroup("KOrganizer Geometry");
2355 2355
2356 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2356 QValueList<int> sizes = config->readIntListEntry("Separator1");
2357 if (sizes.count() != 2) { 2357 if (sizes.count() != 2) {
2358 sizes << mDateNavigator->minimumSizeHint().width(); 2358 sizes << mDateNavigator->minimumSizeHint().width();
2359 sizes << 300; 2359 sizes << 300;
2360 } 2360 }
2361 mPanner->setSizes(sizes); 2361 mPanner->setSizes(sizes);
2362 2362
2363 sizes = config->readIntListEntry("Separator2"); 2363 sizes = config->readIntListEntry("Separator2");
2364 if ( ( mResourceView && sizes.count() == 4 ) || 2364 if ( ( mResourceView && sizes.count() == 4 ) ||
2365 ( !mResourceView && sizes.count() == 3 ) ) { 2365 ( !mResourceView && sizes.count() == 3 ) ) {
2366 mLeftSplitter->setSizes(sizes); 2366 mLeftSplitter->setSizes(sizes);
2367 } 2367 }
2368#endif 2368#endif
2369 globalFlagBlockAgenda = 1; 2369 globalFlagBlockAgenda = 1;
2370 mViewManager->showAgendaView(); 2370 mViewManager->showAgendaView();
2371 //mViewManager->readSettings( config ); 2371 //mViewManager->readSettings( config );
2372 mTodoList->restoreLayout(config,QString("Todo Layout")); 2372 mTodoList->restoreLayout(config,QString("Todo Layout"));
2373 readFilterSettings(config); 2373 readFilterSettings(config);
2374 2374
2375#ifdef DESKTOP_VERSION 2375#ifdef DESKTOP_VERSION
2376 config->setGroup("WidgetLayout"); 2376 config->setGroup("WidgetLayout");
2377 QStringList list; 2377 QStringList list;
2378 list = config->readListEntry("MainLayout"); 2378 list = config->readListEntry("MainLayout");
2379 int x,y,w,h; 2379 int x,y,w,h;
2380 if ( ! list.isEmpty() ) { 2380 if ( ! list.isEmpty() ) {
2381 x = list[0].toInt(); 2381 x = list[0].toInt();
2382 y = list[1].toInt(); 2382 y = list[1].toInt();
2383 w = list[2].toInt(); 2383 w = list[2].toInt();
2384 h = list[3].toInt(); 2384 h = list[3].toInt();
2385 KApplication::testCoords( &x,&y,&w,&h ); 2385 KApplication::testCoords( &x,&y,&w,&h );
2386 topLevelWidget()->setGeometry(x,y,w,h); 2386 topLevelWidget()->setGeometry(x,y,w,h);
2387 2387
2388 } else { 2388 } else {
2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2390 } 2390 }
2391 list = config->readListEntry("EditEventLayout"); 2391 list = config->readListEntry("EditEventLayout");
2392 if ( ! list.isEmpty() ) { 2392 if ( ! list.isEmpty() ) {
2393 x = list[0].toInt(); 2393 x = list[0].toInt();
2394 y = list[1].toInt(); 2394 y = list[1].toInt();
2395 w = list[2].toInt(); 2395 w = list[2].toInt();
2396 h = list[3].toInt(); 2396 h = list[3].toInt();
2397 KApplication::testCoords( &x,&y,&w,&h ); 2397 KApplication::testCoords( &x,&y,&w,&h );
2398 mEventEditor->setGeometry(x,y,w,h); 2398 mEventEditor->setGeometry(x,y,w,h);
2399 2399
2400 } 2400 }
2401 list = config->readListEntry("EditTodoLayout"); 2401 list = config->readListEntry("EditTodoLayout");
2402 if ( ! list.isEmpty() ) { 2402 if ( ! list.isEmpty() ) {
2403 x = list[0].toInt(); 2403 x = list[0].toInt();
2404 y = list[1].toInt(); 2404 y = list[1].toInt();
2405 w = list[2].toInt(); 2405 w = list[2].toInt();
2406 h = list[3].toInt(); 2406 h = list[3].toInt();
2407 KApplication::testCoords( &x,&y,&w,&h ); 2407 KApplication::testCoords( &x,&y,&w,&h );
2408 mTodoEditor->setGeometry(x,y,w,h); 2408 mTodoEditor->setGeometry(x,y,w,h);
2409 2409
2410 } 2410 }
2411 list = config->readListEntry("ViewerLayout"); 2411 list = config->readListEntry("ViewerLayout");
2412 if ( ! list.isEmpty() ) { 2412 if ( ! list.isEmpty() ) {
2413 x = list[0].toInt(); 2413 x = list[0].toInt();
2414 y = list[1].toInt(); 2414 y = list[1].toInt();
2415 w = list[2].toInt(); 2415 w = list[2].toInt();
2416 h = list[3].toInt(); 2416 h = list[3].toInt();
2417 KApplication::testCoords( &x,&y,&w,&h ); 2417 KApplication::testCoords( &x,&y,&w,&h );
2418 getEventViewerDialog()->setGeometry(x,y,w,h); 2418 getEventViewerDialog()->setGeometry(x,y,w,h);
2419 } 2419 }
2420#endif 2420#endif
2421 config->setGroup( "Views" ); 2421 config->setGroup( "Views" );
2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2423 2423
2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2425 2425
2426 int resetval = 0; 2426 int resetval = 0;
2427 int maxVal = 0; 2427 int maxVal = 0;
2428 if (sizes.count() != 3) { 2428 if (sizes.count() != 3) {
2429 if ( KOPrefs::instance()->mVerticalScreen ) { 2429 if ( KOPrefs::instance()->mVerticalScreen ) {
2430 resetval = mDateNavigator->sizeHint().width()+2; 2430 resetval = mDateNavigator->sizeHint().width()+2;
2431 } else { 2431 } else {
2432 resetval = mDateNavigator->sizeHint().height()+2; 2432 resetval = mDateNavigator->sizeHint().height()+2;
2433 } 2433 }
2434 } 2434 }
2435 if ( resetval ) { 2435 if ( resetval ) {
2436 sizes.clear(); 2436 sizes.clear();
2437 if ( KOPrefs::instance()->mVerticalScreen ) { 2437 if ( KOPrefs::instance()->mVerticalScreen ) {
2438 maxVal = QApplication::desktop()->width() -10; 2438 maxVal = QApplication::desktop()->width() -10;
2439 } else { 2439 } else {
2440 maxVal = QApplication::desktop()->height()-10; 2440 maxVal = QApplication::desktop()->height()-10;
2441 } 2441 }
2442 sizes << resetval; 2442 sizes << resetval;
2443 if ( maxVal < resetval + resetval) 2443 if ( maxVal < resetval + resetval)
2444 resetval = maxVal - resetval; 2444 resetval = maxVal - resetval;
2445 sizes << resetval; 2445 sizes << resetval;
2446 sizes << 100; 2446 sizes << 100;
2447 } 2447 }
2448 mLeftFrame->setSizes(sizes); 2448 mLeftFrame->setSizes(sizes);
2449 sizes = config->readIntListEntry("Main Splitter Frame"); 2449 sizes = config->readIntListEntry("Main Splitter Frame");
2450 resetval = 0; 2450 resetval = 0;
2451 maxVal = 0; 2451 maxVal = 0;
2452 if (sizes.count() != 2) { 2452 if (sizes.count() != 2) {
2453 if ( !KOPrefs::instance()->mVerticalScreen ) { 2453 if ( !KOPrefs::instance()->mVerticalScreen ) {
2454 resetval = mDateNavigator->sizeHint().width()+2; 2454 resetval = mDateNavigator->sizeHint().width()+2;
2455 } else { 2455 } else {
2456 resetval = mDateNavigator->sizeHint().height()+2; 2456 resetval = mDateNavigator->sizeHint().height()+2;
2457 } 2457 }
2458 } 2458 }
2459 if ( resetval ) { 2459 if ( resetval ) {
2460 sizes.clear(); 2460 sizes.clear();
2461 if ( !KOPrefs::instance()->mVerticalScreen ) { 2461 if ( !KOPrefs::instance()->mVerticalScreen ) {
2462 maxVal = QApplication::desktop()->width() -10; 2462 maxVal = QApplication::desktop()->width() -10;
2463 } else { 2463 } else {
2464 maxVal = QApplication::desktop()->height()-10; 2464 maxVal = QApplication::desktop()->height()-10;
2465 } 2465 }
2466 sizes << resetval; 2466 sizes << resetval;
2467 if ( maxVal < resetval + resetval) 2467 if ( maxVal < resetval + resetval)
2468 resetval = maxVal - resetval; 2468 resetval = maxVal - resetval;
2469 sizes << resetval; 2469 sizes << resetval;
2470 } 2470 }
2471 mMainFrame->setSizes(sizes); 2471 mMainFrame->setSizes(sizes);
2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2473 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2473 else if ( dateCount == 7 ) mNavigator->selectWeek();
2474 else mNavigator->selectDates( dateCount ); 2474 else mNavigator->selectDates( dateCount );
2475 // mViewManager->readSettings( config ); 2475 // mViewManager->readSettings( config );
2476 updateConfig(); 2476 updateConfig();
2477 globalFlagBlockAgenda = 2; 2477 globalFlagBlockAgenda = 2;
2478 mViewManager->readSettings( config ); 2478 mViewManager->readSettings( config );
2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2480} 2480}
2481 2481
2482void CalendarView::checkSuspendAlarm() 2482void CalendarView::checkSuspendAlarm()
2483{ 2483{
2484 if ( mSuspendTimer->isActive() ) { 2484 if ( mSuspendTimer->isActive() ) {
2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2486 } 2486 }
2487} 2487}
2488void CalendarView::writeSettings() 2488void CalendarView::writeSettings()
2489{ 2489{
2490 // kdDebug() << "CalendarView::writeSettings" << endl; 2490 // kdDebug() << "CalendarView::writeSettings" << endl;
2491 2491
2492 KConfig *config = KOGlobals::config(); 2492 KConfig *config = KOGlobals::config();
2493 2493
2494 mViewManager->writeSettings( config ); 2494 mViewManager->writeSettings( config );
2495 mTodoList->saveLayout(config,QString("Todo Layout")); 2495 mTodoList->saveLayout(config,QString("Todo Layout"));
2496 mDialogManager->writeSettings( config ); 2496 mDialogManager->writeSettings( config );
2497 //KOPrefs::instance()->usrWriteConfig(); 2497 //KOPrefs::instance()->usrWriteConfig();
2498 KOPrefs::instance()->writeConfig(); 2498 KOPrefs::instance()->writeConfig();
2499 2499
2500 writeFilterSettings(config); 2500 writeFilterSettings(config);
2501 config->setGroup( "AppRun" ); 2501 config->setGroup( "AppRun" );
2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2503 int days = dt.daysTo( QDate::currentDate() ); 2503 int days = dt.daysTo( QDate::currentDate() );
2504 dt = dt.addDays( days ); 2504 dt = dt.addDays( days );
2505 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2505 int secs = dt.secsTo( QDateTime::currentDateTime() );
2506 config->writeEntry( "LatestProgramStopDays", days ); 2506 config->writeEntry( "LatestProgramStopDays", days );
2507 config->writeEntry( "LatestProgramStopSecs", secs ); 2507 config->writeEntry( "LatestProgramStopSecs", secs );
2508 //qDebug("KO: Writing stop time: %d ", secs); 2508 //qDebug("KO: Writing stop time: %d ", secs);
2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2510 //QDateTime latest = dt.addSecs ( secs ); 2510 //QDateTime latest = dt.addSecs ( secs );
2511 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2511 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2512 config->setGroup( "Views" ); 2512 config->setGroup( "Views" );
2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2514 2514
2515#if 0 2515#if 0
2516 qDebug("********************* "); 2516 qDebug("********************* ");
2517 qDebug("Testcode secsto "); 2517 qDebug("Testcode secsto ");
2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2520 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2520 int secsto = dt_nodaylight.secsTo( dt_daylight );
2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2526 qDebug("********************* testcode end"); 2526 qDebug("********************* testcode end");
2527 2527
2528#endif 2528#endif
2529 2529
2530 QValueList<int> listINT = mLeftFrame->sizes(); 2530 QValueList<int> listINT = mLeftFrame->sizes();
2531 config->writeEntry("Left Splitter Frame",listINT); 2531 config->writeEntry("Left Splitter Frame",listINT);
2532 QValueList<int> listINT2 = mMainFrame->sizes(); 2532 QValueList<int> listINT2 = mMainFrame->sizes();
2533 config->writeEntry("Main Splitter Frame",listINT2); 2533 config->writeEntry("Main Splitter Frame",listINT2);
2534#ifdef DESKTOP_VERSION 2534#ifdef DESKTOP_VERSION
2535 config->setGroup("WidgetLayout"); 2535 config->setGroup("WidgetLayout");
2536 QStringList list ;//= config->readListEntry("MainLayout"); 2536 QStringList list ;//= config->readListEntry("MainLayout");
2537 int x,y,w,h; 2537 int x,y,w,h;
2538 QWidget* wid; 2538 QWidget* wid;
2539 wid = topLevelWidget(); 2539 wid = topLevelWidget();
2540 x = wid->geometry().x(); 2540 x = wid->geometry().x();
2541 y = wid->geometry().y(); 2541 y = wid->geometry().y();
2542 w = wid->width(); 2542 w = wid->width();
2543 h = wid->height(); 2543 h = wid->height();
2544 list.clear(); 2544 list.clear();
2545 list << QString::number( x ); 2545 list << QString::number( x );
2546 list << QString::number( y ); 2546 list << QString::number( y );
2547 list << QString::number( w ); 2547 list << QString::number( w );
2548 list << QString::number( h ); 2548 list << QString::number( h );
2549 config->writeEntry("MainLayout",list ); 2549 config->writeEntry("MainLayout",list );
2550 2550
2551 wid = mEventEditor; 2551 wid = mEventEditor;
2552 x = wid->geometry().x(); 2552 x = wid->geometry().x();
2553 y = wid->geometry().y(); 2553 y = wid->geometry().y();
2554 w = wid->width(); 2554 w = wid->width();
2555 h = wid->height(); 2555 h = wid->height();
2556 list.clear(); 2556 list.clear();
2557 list << QString::number( x ); 2557 list << QString::number( x );
2558 list << QString::number( y ); 2558 list << QString::number( y );
2559 list << QString::number( w ); 2559 list << QString::number( w );
2560 list << QString::number( h ); 2560 list << QString::number( h );
2561 config->writeEntry("EditEventLayout",list ); 2561 config->writeEntry("EditEventLayout",list );
2562 2562
2563 wid = mTodoEditor; 2563 wid = mTodoEditor;
2564 x = wid->geometry().x(); 2564 x = wid->geometry().x();
2565 y = wid->geometry().y(); 2565 y = wid->geometry().y();
2566 w = wid->width(); 2566 w = wid->width();
2567 h = wid->height(); 2567 h = wid->height();
2568 list.clear(); 2568 list.clear();
2569 list << QString::number( x ); 2569 list << QString::number( x );
2570 list << QString::number( y ); 2570 list << QString::number( y );
2571 list << QString::number( w ); 2571 list << QString::number( w );
2572 list << QString::number( h ); 2572 list << QString::number( h );
2573 config->writeEntry("EditTodoLayout",list ); 2573 config->writeEntry("EditTodoLayout",list );
2574 wid = getEventViewerDialog(); 2574 wid = getEventViewerDialog();
2575 x = wid->geometry().x(); 2575 x = wid->geometry().x();
2576 y = wid->geometry().y(); 2576 y = wid->geometry().y();
2577 w = wid->width(); 2577 w = wid->width();
2578 h = wid->height(); 2578 h = wid->height();
2579 list.clear(); 2579 list.clear();
2580 list << QString::number( x ); 2580 list << QString::number( x );
2581 list << QString::number( y ); 2581 list << QString::number( y );
2582 list << QString::number( w ); 2582 list << QString::number( w );
2583 list << QString::number( h ); 2583 list << QString::number( h );
2584 config->writeEntry("ViewerLayout",list ); 2584 config->writeEntry("ViewerLayout",list );
2585 wid = mDialogManager->getSearchDialog(); 2585 wid = mDialogManager->getSearchDialog();
2586 if ( wid ) { 2586 if ( wid ) {
2587 x = wid->geometry().x(); 2587 x = wid->geometry().x();
2588 y = wid->geometry().y(); 2588 y = wid->geometry().y();
2589 w = wid->width(); 2589 w = wid->width();
2590 h = wid->height(); 2590 h = wid->height();
2591 list.clear(); 2591 list.clear();
2592 list << QString::number( x ); 2592 list << QString::number( x );
2593 list << QString::number( y ); 2593 list << QString::number( y );
2594 list << QString::number( w ); 2594 list << QString::number( w );
2595 list << QString::number( h ); 2595 list << QString::number( h );
2596 config->writeEntry("SearchLayout",list ); 2596 config->writeEntry("SearchLayout",list );
2597 } 2597 }
2598#endif 2598#endif
2599 2599
2600 2600
2601 config->sync(); 2601 config->sync();
2602} 2602}
2603 2603
2604void CalendarView::readFilterSettings(KConfig *config) 2604void CalendarView::readFilterSettings(KConfig *config)
2605{ 2605{
2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2607 2607
2608 mFilters.clear(); 2608 mFilters.clear();
2609 2609
2610 config->setGroup("General"); 2610 config->setGroup("General");
2611 QStringList filterList = config->readListEntry("CalendarFilters"); 2611 QStringList filterList = config->readListEntry("CalendarFilters");
2612 2612
2613 QStringList::ConstIterator it = filterList.begin(); 2613 QStringList::ConstIterator it = filterList.begin();
2614 QStringList::ConstIterator end = filterList.end(); 2614 QStringList::ConstIterator end = filterList.end();
2615 while(it != end) { 2615 while(it != end) {
2616 // kdDebug() << " filter: " << (*it) << endl; 2616 // kdDebug() << " filter: " << (*it) << endl;
2617 2617
2618 CalFilter *filter; 2618 CalFilter *filter;
2619 filter = new CalFilter(*it); 2619 filter = new CalFilter(*it);
2620 config->setGroup("Filter_" + (*it).utf8()); 2620 config->setGroup("Filter_" + (*it).utf8());
2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2622 filter->setCriteria(config->readNumEntry("Criteria",0)); 2622 filter->setCriteria(config->readNumEntry("Criteria",0));
2623 filter->setCategoryList(config->readListEntry("CategoryList")); 2623 filter->setCategoryList(config->readListEntry("CategoryList"));
2624 mFilters.append(filter); 2624 mFilters.append(filter);
2625 2625
2626 ++it; 2626 ++it;
2627 } 2627 }
2628 2628
2629 if (mFilters.count() == 0) { 2629 if (mFilters.count() == 0) {
2630 CalFilter *filter = new CalFilter(i18n("Default")); 2630 CalFilter *filter = new CalFilter(i18n("Default"));
2631 mFilters.append(filter); 2631 mFilters.append(filter);
2632 } 2632 }
2633 mFilterView->updateFilters(); 2633 mFilterView->updateFilters();
2634 config->setGroup("FilterView"); 2634 config->setGroup("FilterView");
2635 2635
2636 mFilterView->blockSignals(true); 2636 mFilterView->blockSignals(true);
2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2639 mFilterView->blockSignals(false); 2639 mFilterView->blockSignals(false);
2640 // We do it manually to avoid it being done twice by the above calls 2640 // We do it manually to avoid it being done twice by the above calls
2641 updateFilter(); 2641 updateFilter();
2642} 2642}
2643 2643
2644void CalendarView::writeFilterSettings(KConfig *config) 2644void CalendarView::writeFilterSettings(KConfig *config)
2645{ 2645{
2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2647 2647
2648 QStringList filterList; 2648 QStringList filterList;
2649 2649
2650 CalFilter *filter = mFilters.first(); 2650 CalFilter *filter = mFilters.first();
2651 while(filter) { 2651 while(filter) {
2652 // kdDebug() << " fn: " << filter->name() << endl; 2652 // kdDebug() << " fn: " << filter->name() << endl;
2653 filterList << filter->name(); 2653 filterList << filter->name();
2654 config->setGroup("Filter_" + filter->name().utf8()); 2654 config->setGroup("Filter_" + filter->name().utf8());
2655 config->writeEntry("Criteria",filter->criteria()); 2655 config->writeEntry("Criteria",filter->criteria());
2656 config->writeEntry("CategoryList",filter->categoryList()); 2656 config->writeEntry("CategoryList",filter->categoryList());
2657 filter = mFilters.next(); 2657 filter = mFilters.next();
2658 } 2658 }
2659 config->setGroup("General"); 2659 config->setGroup("General");
2660 config->writeEntry("CalendarFilters",filterList); 2660 config->writeEntry("CalendarFilters",filterList);
2661 2661
2662 config->setGroup("FilterView"); 2662 config->setGroup("FilterView");
2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2665} 2665}
2666 2666
2667 2667
2668void CalendarView::goToday() 2668void CalendarView::goToday()
2669{ 2669{
2670 if ( mViewManager->currentView()->isMonthView() ) 2670 if ( mViewManager->currentView()->isMonthView() )
2671 mNavigator->selectTodayMonth(); 2671 mNavigator->selectTodayMonth();
2672 else 2672 else
2673 mNavigator->selectToday(); 2673 mNavigator->selectToday();
2674} 2674}
2675 2675
2676void CalendarView::goNext() 2676void CalendarView::goNext()
2677{ 2677{
2678 mNavigator->selectNext(); 2678 mNavigator->selectNext();
2679} 2679}
2680 2680
2681void CalendarView::goPrevious() 2681void CalendarView::goPrevious()
2682{ 2682{
2683 mNavigator->selectPrevious(); 2683 mNavigator->selectPrevious();
2684} 2684}
2685void CalendarView::goNextMonth() 2685void CalendarView::goNextMonth()
2686{ 2686{
2687 mNavigator->selectNextMonth(); 2687 mNavigator->selectNextMonth();
2688} 2688}
2689 2689
2690void CalendarView::goPreviousMonth() 2690void CalendarView::goPreviousMonth()
2691{ 2691{
2692 mNavigator->selectPreviousMonth(); 2692 mNavigator->selectPreviousMonth();
2693} 2693}
2694 2694
2695void CalendarView::updateConfig() 2695void CalendarView::updateConfig()
2696{ 2696{
2697 if ( KOPrefs::instance()->mUseAppColors ) 2697 if ( KOPrefs::instance()->mUseAppColors )
2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2699 emit configChanged(); 2699 emit configChanged();
2700 mTodoList->updateConfig(); 2700 mTodoList->updateConfig();
2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2703 // To make the "fill window" configurations work 2703 // To make the "fill window" configurations work
2704 //mViewManager->raiseCurrentView(); 2704 //mViewManager->raiseCurrentView();
2705} 2705}
2706 2706
2707 2707
2708void CalendarView::eventChanged(Event *event) 2708void CalendarView::eventChanged(Event *event)
2709{ 2709{
2710 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2710 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2711 //updateUnmanagedViews(); 2711 //updateUnmanagedViews();
2712} 2712}
2713 2713
2714void CalendarView::eventAdded(Event *event) 2714void CalendarView::eventAdded(Event *event)
2715{ 2715{
2716 changeEventDisplay(event,KOGlobals::EVENTADDED); 2716 changeEventDisplay(event,KOGlobals::EVENTADDED);
2717} 2717}
2718 2718
2719void CalendarView::eventToBeDeleted(Event *) 2719void CalendarView::eventToBeDeleted(Event *)
2720{ 2720{
2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2722} 2722}
2723 2723
2724void CalendarView::eventDeleted() 2724void CalendarView::eventDeleted()
2725{ 2725{
2726 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2726 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2727} 2727}
2728void CalendarView::changeTodoDisplay(Todo *which, int action) 2728void CalendarView::changeTodoDisplay(Todo *which, int action)
2729{ 2729{
2730 changeIncidenceDisplay((Incidence *)which, action); 2730 changeIncidenceDisplay((Incidence *)which, action);
2731 mDateNavigator->updateView(); //LR 2731 mDateNavigator->updateView(); //LR
2732 //mDialogManager->updateSearchDialog(); 2732 //mDialogManager->updateSearchDialog();
2733 2733
2734 if (which) { 2734 if (which) {
2735 mViewManager->updateWNview(); 2735 mViewManager->updateWNview();
2736 //mTodoList->updateView(); 2736 //mTodoList->updateView();
2737 } 2737 }
2738 2738
2739} 2739}
2740 2740
2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2742{ 2742{
2743 updateUnmanagedViews(); 2743 updateUnmanagedViews();
2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2745 if ( action == KOGlobals::EVENTDELETED ) { //delete 2745 if ( action == KOGlobals::EVENTDELETED ) { //delete
2746 mCalendar->checkAlarmForIncidence( 0, true ); 2746 mCalendar->checkAlarmForIncidence( 0, true );
2747 if ( mEventViewerDialog ) 2747 if ( mEventViewerDialog )
2748 mEventViewerDialog->hide(); 2748 mEventViewerDialog->hide();
2749 } 2749 }
2750 else 2750 else
2751 mCalendar->checkAlarmForIncidence( which , false ); 2751 mCalendar->checkAlarmForIncidence( which , false );
2752} 2752}
2753 2753
2754// most of the changeEventDisplays() right now just call the view's 2754// most of the changeEventDisplays() right now just call the view's
2755// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2755// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2756void CalendarView::changeEventDisplay(Event *which, int action) 2756void CalendarView::changeEventDisplay(Event *which, int action)
2757{ 2757{
2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2759 changeIncidenceDisplay((Incidence *)which, action); 2759 changeIncidenceDisplay((Incidence *)which, action);
2760 static bool clearallviews = false; 2760 static bool clearallviews = false;
2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2762 if ( clearallviews ) { 2762 if ( clearallviews ) {
2763 clearAllViews(); 2763 clearAllViews();
2764 clearallviews = false; 2764 clearallviews = false;
2765 } 2765 }
2766 return; 2766 return;
2767 } 2767 }
2768 clearallviews = true; 2768 clearallviews = true;
2769 mDateNavigator->updateView(); 2769 mDateNavigator->updateView();
2770 //mDialogManager->updateSearchDialog(); 2770 //mDialogManager->updateSearchDialog();
2771 if (which) { 2771 if (which) {
2772 // If there is an event view visible update the display 2772 // If there is an event view visible update the display
2773 mViewManager->currentView()->changeEventDisplay(which,action); 2773 mViewManager->currentView()->changeEventDisplay(which,action);
2774 // TODO: check, if update needed 2774 // TODO: check, if update needed
2775 // if (which->getTodoStatus()) { 2775 // if (which->getTodoStatus()) {
2776 mTodoList->updateView(); 2776 mTodoList->updateView();
2777 if ( action != KOGlobals::EVENTDELETED ) { 2777 if ( action != KOGlobals::EVENTDELETED ) {
2778 mConflictingEvent = which ; 2778 mConflictingEvent = which ;
2779 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2779 int time = 1000;
2780#ifdef DESKTOP_VERSION
2781 time = 500;
2782#endif
2783 QTimer::singleShot( time, this, SLOT ( checkConflictForEvent() ) );
2780 } 2784 }
2781 // } 2785 // }
2782 } else { 2786 } else {
2783 mViewManager->currentView()->updateView(); 2787 mViewManager->currentView()->updateView();
2784 } 2788 }
2785} 2789}
2786void CalendarView::checkConflictForEvent() 2790void CalendarView::checkConflictForEvent()
2787{ 2791{
2788 2792
2789 if (!KOPrefs::instance()->mConfirm) 2793 if (!KOPrefs::instance()->mConfirm)
2790 return; 2794 return;
2791 if ( ! mConflictingEvent ) return; 2795 if ( ! mConflictingEvent ) return;
2792 QDateTime current = QDateTime::currentDateTime(); 2796 QDateTime current = QDateTime::currentDateTime();
2793 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) { 2797 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) {
2794 mConflictingEvent = 0; 2798 mConflictingEvent = 0;
2795 return; 2799 return;
2796 } 2800 }
2797 QPtrList<Event> testlist = mCalendar->events(); 2801 QPtrList<Event> testlist = mCalendar->events();
2798 Event * test = testlist.first(); 2802 Event * test = testlist.first();
2799 QDateTime conflict; 2803 QDateTime conflict;
2800 QDateTime retVal; 2804 QDateTime retVal;
2801 bool found = false; 2805 bool found = false;
2802 Event * cE = 0; 2806 Event * cE = 0;
2803 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2807 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2804 while ( test ) { 2808 while ( test ) {
2805 qApp->processEvents(); 2809 qApp->processEvents();
2806 bool skip = false; 2810 bool skip = false;
2807 if ( found ) 2811 if ( found )
2808 skip = !test->matchTime( &current, &conflict ); 2812 skip = !test->matchTime( &current, &conflict );
2809 else 2813 else
2810 skip = !test->matchTime( &current, 0 ); 2814 skip = !test->matchTime( &current, 0 );
2811 if ( !skip && !test->doesFloat() ) { 2815 if ( !skip && !test->doesFloat() ) {
2812 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2816 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2813 if ( ! found ) { 2817 if ( ! found ) {
2814 conflict = retVal; 2818 conflict = retVal;
2815 cE = test; 2819 cE = test;
2816 } else { 2820 } else {
2817 if ( retVal < conflict ) { 2821 if ( retVal < conflict ) {
2818 conflict = retVal; 2822 conflict = retVal;
2819 cE = test; 2823 cE = test;
2820 } 2824 }
2821 } 2825 }
2822 found = true; 2826 found = true;
2823 } 2827 }
2824 } 2828 }
2825 test = testlist.next(); 2829 test = testlist.next();
2826 } 2830 }
2827 if ( found ) { 2831 if ( found ) {
2828 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2832 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2829 qApp->processEvents(); 2833 qApp->processEvents();
2830 int km = KMessageBox::warningContinueCancel(this,mess, 2834 int km = KMessageBox::warningContinueCancel(this,mess,
2831 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2835 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2832 if ( km != KMessageBox::Continue ) 2836 if ( km != KMessageBox::Continue )
2833 return; 2837 return;
2834 2838
2835 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2839 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2836 mViewManager->showDayView(); 2840 mViewManager->showDayView();
2837 mNavigator->slotDaySelect( conflict.date() ); 2841 mNavigator->slotDaySelect( conflict.date() );
2838 int hour = conflict.time().hour(); 2842 int hour = conflict.time().hour();
2839 mViewManager->agendaView()->setStartHour( hour ); 2843 mViewManager->agendaView()->setStartHour( hour );
2840 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2844 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2841 } else 2845 } else
2842 topLevelWidget()->setCaption( i18n("No conflict found") ); 2846 topLevelWidget()->setCaption( i18n("No conflict found") );
2843 mConflictingEvent = 0; 2847 mConflictingEvent = 0;
2844 return; 2848 return;
2845 2849
2846} 2850}
2847 2851
2848void CalendarView::updateTodoViews() 2852void CalendarView::updateTodoViews()
2849{ 2853{
2850 mTodoList->updateView(); 2854 mTodoList->updateView();
2851 mViewManager->currentView()->updateView(); 2855 mViewManager->currentView()->updateView();
2852 2856
2853} 2857}
2854 2858
2855 2859
2856 2860
2857void CalendarView::clearAllViews() 2861void CalendarView::clearAllViews()
2858{ 2862{
2859 mTodoList->clearList(); 2863 mTodoList->clearList();
2860 mViewManager->clearAllViews(); 2864 mViewManager->clearAllViews();
2861 SearchDialog * sd = mDialogManager->getSearchDialog(); 2865 SearchDialog * sd = mDialogManager->getSearchDialog();
2862 if ( sd ) { 2866 if ( sd ) {
2863 KOListView* kol = sd->listview(); 2867 KOListView* kol = sd->listview();
2864 if ( kol ) 2868 if ( kol )
2865 kol->clearList(); 2869 kol->clearList();
2866 } 2870 }
2867} 2871}
2868void CalendarView::updateView() 2872void CalendarView::updateView()
2869{ 2873{
2870 static bool clearallviews = false; 2874 static bool clearallviews = false;
2871 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2875 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2872 if ( clearallviews ) { 2876 if ( clearallviews ) {
2873 clearAllViews(); 2877 clearAllViews();
2874 clearallviews = false; 2878 clearallviews = false;
2875 } 2879 }
2876 return; 2880 return;
2877 } 2881 }
2878 clearallviews = true; 2882 clearallviews = true;
2879 DateList tmpList = mNavigator->selectedDates(); 2883 DateList tmpList = mNavigator->selectedDates();
2880 2884
2881 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2885 if ( KOPrefs::instance()->mHideNonStartedTodos )
2882 mTodoList->updateView(); 2886 mTodoList->updateView();
2883 // We assume that the navigator only selects consecutive days. 2887 // We assume that the navigator only selects consecutive days.
2884 updateView( tmpList.first(), tmpList.last() ); 2888 updateView( tmpList.first(), tmpList.last() );
2885} 2889}
2886 2890
2887void CalendarView::updateUnmanagedViews() 2891void CalendarView::updateUnmanagedViews()
2888{ 2892{
2889 mDateNavigator->updateDayMatrix(); 2893 mDateNavigator->updateDayMatrix();
2890} 2894}
2891 2895
2892int CalendarView::msgItemDelete(const QString name) 2896int CalendarView::msgItemDelete(const QString name)
2893{ 2897{
2894 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2898 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2895 i18n("This item will be\npermanently deleted."), 2899 i18n("This item will be\npermanently deleted."),
2896 i18n("KO/Pi Confirmation"),i18n("Delete")); 2900 i18n("KO/Pi Confirmation"),i18n("Delete"));
2897} 2901}
2898 2902
2899 2903
2900void CalendarView::edit_cut() 2904void CalendarView::edit_cut()
2901{ 2905{
2902 Event *anEvent=0; 2906 Event *anEvent=0;
2903 2907
2904 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2908 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2905 2909
2906 if (mViewManager->currentView()->isEventView()) { 2910 if (mViewManager->currentView()->isEventView()) {
2907 if ( incidence && incidence->typeID() == eventID ) { 2911 if ( incidence && incidence->typeID() == eventID ) {
2908 anEvent = static_cast<Event *>(incidence); 2912 anEvent = static_cast<Event *>(incidence);
2909 } 2913 }
2910 } 2914 }
2911 2915
2912 if (!anEvent) { 2916 if (!anEvent) {
2913 KNotifyClient::beep(); 2917 KNotifyClient::beep();
2914 return; 2918 return;
2915 } 2919 }
2916 DndFactory factory( mCalendar ); 2920 DndFactory factory( mCalendar );
2917 factory.cutIncidence(anEvent); 2921 factory.cutIncidence(anEvent);
2918 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2922 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2919} 2923}
2920 2924
2921void CalendarView::edit_copy() 2925void CalendarView::edit_copy()
2922{ 2926{
2923 Event *anEvent=0; 2927 Event *anEvent=0;
2924 2928
2925 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2929 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2926 2930
2927 if (mViewManager->currentView()->isEventView()) { 2931 if (mViewManager->currentView()->isEventView()) {
2928 if ( incidence && incidence->typeID() == eventID ) { 2932 if ( incidence && incidence->typeID() == eventID ) {
2929 anEvent = static_cast<Event *>(incidence); 2933 anEvent = static_cast<Event *>(incidence);
2930 } 2934 }
2931 } 2935 }
2932 2936
2933 if (!anEvent) { 2937 if (!anEvent) {
2934 KNotifyClient::beep(); 2938 KNotifyClient::beep();
2935 return; 2939 return;
2936 } 2940 }
2937 DndFactory factory( mCalendar ); 2941 DndFactory factory( mCalendar );
2938 factory.copyIncidence(anEvent); 2942 factory.copyIncidence(anEvent);
2939} 2943}
2940 2944
2941void CalendarView::edit_paste() 2945void CalendarView::edit_paste()
2942{ 2946{
2943 QDate date = mNavigator->selectedDates().first(); 2947 QDate date = mNavigator->selectedDates().first();
2944 2948
2945 DndFactory factory( mCalendar ); 2949 DndFactory factory( mCalendar );
2946 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2950 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2947 2951
2948 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2952 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2949} 2953}
2950void CalendarView::edit_global_options() 2954void CalendarView::edit_global_options()
2951{ 2955{
2952 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2956 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2953 emit save(); 2957 emit save();
2954 emit saveStopTimer(); 2958 emit saveStopTimer();
2955 mDialogManager->showGlobalOptionsDialog(); 2959 mDialogManager->showGlobalOptionsDialog();
2956 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2960 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2957 emit saveStopTimer(); 2961 emit saveStopTimer();
2958 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!"), 2962 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!"),
2959 i18n("Timezone settings"),i18n("Reload"))) { 2963 i18n("Timezone settings"),i18n("Reload"))) {
2960 qDebug("KO: TZ reload cancelled "); 2964 qDebug("KO: TZ reload cancelled ");
2961 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2965 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2962 return; 2966 return;
2963 } 2967 }
2964 qDebug("KO: Timezone change "); 2968 qDebug("KO: Timezone change ");
2965 loadCalendars(); 2969 loadCalendars();
2966 setModified(true); 2970 setModified(true);
2967 } 2971 }
2968 else 2972 else
2969 qDebug("KO: No tz change "); 2973 qDebug("KO: No tz change ");
2970} 2974}
2971void CalendarView::edit_options() 2975void CalendarView::edit_options()
2972{ 2976{
2973 mDialogManager->showOptionsDialog(); 2977 mDialogManager->showOptionsDialog();
2974} 2978}
2975 2979
2976 2980
2977void CalendarView::slotSelectPickerDate( QDate d) 2981void CalendarView::slotSelectPickerDate( QDate d)
2978{ 2982{
2979 mDateFrame->hide(); 2983 mDateFrame->hide();
2980 if ( mDatePickerMode == 1 ) { 2984 if ( mDatePickerMode == 1 ) {
2981 mNavigator->slotDaySelect( d ); 2985 mNavigator->slotDaySelect( d );
2982 } else if ( mDatePickerMode == 2 ) { 2986 } else if ( mDatePickerMode == 2 ) {
2983 if ( mMoveIncidence->typeID() == todoID ) { 2987 if ( mMoveIncidence->typeID() == todoID ) {
2984 Todo * to = (Todo *) mMoveIncidence; 2988 Todo * to = (Todo *) mMoveIncidence;
2985 QTime tim; 2989 QTime tim;
2986 int len = 0; 2990 int len = 0;
2987 if ( to->hasStartDate() && to->hasDueDate() ) 2991 if ( to->hasStartDate() && to->hasDueDate() )
2988 len = to->dtStart().secsTo( to->dtDue()); 2992 len = to->dtStart().secsTo( to->dtDue());
2989 if ( to->hasDueDate() ) 2993 if ( to->hasDueDate() )
2990 tim = to->dtDue().time(); 2994 tim = to->dtDue().time();
2991 else { 2995 else {
2992 tim = QTime ( 0,0,0 ); 2996 tim = QTime ( 0,0,0 );
2993 to->setFloats( true ); 2997 to->setFloats( true );
2994 to->setHasDueDate( true ); 2998 to->setHasDueDate( true );
2995 } 2999 }
2996 QDateTime dt ( d,tim ); 3000 QDateTime dt ( d,tim );
2997 to->setDtDue( dt ); 3001 to->setDtDue( dt );
2998 3002
2999 if ( to->hasStartDate() ) { 3003 if ( to->hasStartDate() ) {
3000 if ( len>0 ) 3004 if ( len>0 )
3001 to->setDtStart(to->dtDue().addSecs( -len )); 3005 to->setDtStart(to->dtDue().addSecs( -len ));
3002 else 3006 else
3003 if (to->dtStart() > to->dtDue() ) 3007 if (to->dtStart() > to->dtDue() )
3004 to->setDtStart(to->dtDue().addDays( -3 )); 3008 to->setDtStart(to->dtDue().addDays( -3 ));
3005 } 3009 }
3006 3010
3007 todoChanged( to ); 3011 todoChanged( to );
3008 } else if ( mMoveIncidence->typeID() == eventID ) { 3012 } else if ( mMoveIncidence->typeID() == eventID ) {
3009 if ( mMoveIncidence->doesRecur() ) { 3013 if ( mMoveIncidence->doesRecur() ) {
3010#if 0 3014#if 0
3011 // PENDING implement this 3015 // PENDING implement this
3012 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 3016 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
3013 mCalendar()->addIncidence( newInc ); 3017 mCalendar()->addIncidence( newInc );
3014 if ( mMoveIncidence->typeID() == todoID ) 3018 if ( mMoveIncidence->typeID() == todoID )
3015 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 3019 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
3016 else 3020 else
3017 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 3021 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
3018 mMoveIncidence = newInc; 3022 mMoveIncidence = newInc;
3019 3023
3020#endif 3024#endif
3021 } 3025 }
3022 QTime tim = mMoveIncidence->dtStart().time(); 3026 QTime tim = mMoveIncidence->dtStart().time();
3023 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 3027 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
3024 QDateTime dt ( d,tim ); 3028 QDateTime dt ( d,tim );
3025 mMoveIncidence->setDtStart( dt ); 3029 mMoveIncidence->setDtStart( dt );
3026 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 3030 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
3027 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 3031 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
3028 } else if ( mMoveIncidence->typeID() == journalID ) { 3032 } else if ( mMoveIncidence->typeID() == journalID ) {
3029 QTime tim = mMoveIncidence->dtStart().time(); 3033 QTime tim = mMoveIncidence->dtStart().time();
3030 QDateTime dt ( d,tim ); 3034 QDateTime dt ( d,tim );
3031 mMoveIncidence->setDtStart( dt ); 3035 mMoveIncidence->setDtStart( dt );
3032 updateView(); 3036 updateView();
3033 } 3037 }
3034 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3038 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3035 } 3039 }
3036} 3040}
3037 3041
3038void CalendarView::removeCategories() 3042void CalendarView::removeCategories()
3039{ 3043{
3040 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3044 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3041 QStringList catList = KOPrefs::instance()->mCustomCategories; 3045 QStringList catList = KOPrefs::instance()->mCustomCategories;
3042 QStringList catIncList; 3046 QStringList catIncList;
3043 QStringList newCatList; 3047 QStringList newCatList;
3044 Incidence* inc = incList.first(); 3048 Incidence* inc = incList.first();
3045 uint i; 3049 uint i;
3046 while ( inc ) { 3050 while ( inc ) {
3047 newCatList.clear(); 3051 newCatList.clear();
3048 catIncList = inc->categories() ; 3052 catIncList = inc->categories() ;
3049 for( i = 0; i< catIncList.count(); ++i ) { 3053 for( i = 0; i< catIncList.count(); ++i ) {
3050 if ( catList.contains (catIncList[i])) 3054 if ( catList.contains (catIncList[i]))
3051 newCatList.append( catIncList[i] ); 3055 newCatList.append( catIncList[i] );
3052 } 3056 }
3053 newCatList.sort(); 3057 newCatList.sort();
3054 inc->setCategories( newCatList.join(",") ); 3058 inc->setCategories( newCatList.join(",") );
3055 inc = incList.next(); 3059 inc = incList.next();
3056 } 3060 }
3057} 3061}
3058 3062
3059int CalendarView::addCategories() 3063int CalendarView::addCategories()
3060{ 3064{
3061 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3065 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3062 QStringList catList = KOPrefs::instance()->mCustomCategories; 3066 QStringList catList = KOPrefs::instance()->mCustomCategories;
3063 QStringList catIncList; 3067 QStringList catIncList;
3064 Incidence* inc = incList.first(); 3068 Incidence* inc = incList.first();
3065 uint i; 3069 uint i;
3066 int count = 0; 3070 int count = 0;
3067 while ( inc ) { 3071 while ( inc ) {
3068 catIncList = inc->categories() ; 3072 catIncList = inc->categories() ;
3069 for( i = 0; i< catIncList.count(); ++i ) { 3073 for( i = 0; i< catIncList.count(); ++i ) {
3070 if ( !catList.contains (catIncList[i])) { 3074 if ( !catList.contains (catIncList[i])) {
3071 catList.append( catIncList[i] ); 3075 catList.append( catIncList[i] );
3072 //qDebug("add cat %s ", catIncList[i].latin1()); 3076 //qDebug("add cat %s ", catIncList[i].latin1());
3073 ++count; 3077 ++count;
3074 } 3078 }
3075 } 3079 }
3076 inc = incList.next(); 3080 inc = incList.next();
3077 } 3081 }
3078 catList.sort(); 3082 catList.sort();
3079 KOPrefs::instance()->mCustomCategories = catList; 3083 KOPrefs::instance()->mCustomCategories = catList;
3080 return count; 3084 return count;
3081} 3085}
3082 3086
3083void CalendarView::editCategories() 3087void CalendarView::editCategories()
3084{ 3088{
3085 qDebug("CalendarView::editCategories() "); 3089 qDebug("CalendarView::editCategories() ");
3086 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3090 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3087 ced.exec(); 3091 ced.exec();
3088} 3092}
3089void CalendarView::manageCategories() 3093void CalendarView::manageCategories()
3090{ 3094{
3091 KOCatPrefs* cp = new KOCatPrefs(); 3095 KOCatPrefs* cp = new KOCatPrefs();
3092 cp->show(); 3096 cp->show();
3093 int w =cp->sizeHint().width() ; 3097 int w =cp->sizeHint().width() ;
3094 int h = cp->sizeHint().height() ; 3098 int h = cp->sizeHint().height() ;
3095 int dw = QApplication::desktop()->width(); 3099 int dw = QApplication::desktop()->width();
3096 int dh = QApplication::desktop()->height(); 3100 int dh = QApplication::desktop()->height();
3097 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3101 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3098 if ( !cp->exec() ) { 3102 if ( !cp->exec() ) {
3099 delete cp; 3103 delete cp;
3100 return; 3104 return;
3101 } 3105 }
3102 int count = 0; 3106 int count = 0;
3103 if ( cp->addCat() ) { 3107 if ( cp->addCat() ) {
3104 count = addCategories(); 3108 count = addCategories();
3105 if ( count ) { 3109 if ( count ) {
3106 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3110 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3107 writeSettings(); 3111 writeSettings();
3108 } else 3112 } else
3109 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3113 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3110 } else { 3114 } else {
3111 removeCategories(); 3115 removeCategories();
3112 updateView(); 3116 updateView();
3113 } 3117 }
3114 delete cp; 3118 delete cp;
3115} 3119}
3116 3120
3117void CalendarView::beamIncidence(Incidence * Inc) 3121void CalendarView::beamIncidence(Incidence * Inc)
3118{ 3122{
3119 QPtrList<Incidence> delSel ; 3123 QPtrList<Incidence> delSel ;
3120 delSel.append(Inc); 3124 delSel.append(Inc);
3121 beamIncidenceList( delSel ); 3125 beamIncidenceList( delSel );
3122} 3126}
3123void CalendarView::beamCalendar() 3127void CalendarView::beamCalendar()
3124{ 3128{
3125 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3129 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3126 //qDebug("beamCalendar() "); 3130 //qDebug("beamCalendar() ");
3127 beamIncidenceList( delSel ); 3131 beamIncidenceList( delSel );
3128} 3132}
3129void CalendarView::beamFilteredCalendar() 3133void CalendarView::beamFilteredCalendar()
3130{ 3134{
3131 QPtrList<Incidence> delSel = mCalendar->incidences(); 3135 QPtrList<Incidence> delSel = mCalendar->incidences();
3132 //qDebug("beamFilteredCalendar() "); 3136 //qDebug("beamFilteredCalendar() ");
3133 beamIncidenceList( delSel ); 3137 beamIncidenceList( delSel );
3134} 3138}
3135void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3139void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3136{ 3140{
3137 3141
3138 KOBeamPrefs beamDialog; 3142 KOBeamPrefs beamDialog;
3139 if ( beamDialog.exec () == QDialog::Rejected ) 3143 if ( beamDialog.exec () == QDialog::Rejected )
3140 return; 3144 return;
3141#ifdef DESKTOP_VERSION 3145#ifdef DESKTOP_VERSION
3142 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3146 QString fn = locateLocal( "tmp", "kopibeamfile" );
3143#else 3147#else
3144 QString fn = "/tmp/kopibeamfile"; 3148 QString fn = "/tmp/kopibeamfile";
3145#endif 3149#endif
3146 QString mes; 3150 QString mes;
3147 bool createbup = true; 3151 bool createbup = true;
3148 if ( createbup ) { 3152 if ( createbup ) {
3149 QString description = "\n"; 3153 QString description = "\n";
3150 CalendarLocal* cal = new CalendarLocal(); 3154 CalendarLocal* cal = new CalendarLocal();
3151 if ( beamDialog.beamLocal() ) 3155 if ( beamDialog.beamLocal() )
3152 cal->setLocalTime(); 3156 cal->setLocalTime();
3153 else 3157 else
3154 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3158 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3155 Incidence *incidence = delSel.first(); 3159 Incidence *incidence = delSel.first();
3156 bool addText = false; 3160 bool addText = false;
3157 if ( delSel.count() < 10 ) 3161 if ( delSel.count() < 10 )
3158 addText = true; 3162 addText = true;
3159 else { 3163 else {
3160 description.sprintf(i18n(" %d items?"),delSel.count() ); 3164 description.sprintf(i18n(" %d items?"),delSel.count() );
3161 } 3165 }
3162 while ( incidence ) { 3166 while ( incidence ) {
3163 Incidence *in = incidence->clone(); 3167 Incidence *in = incidence->clone();
3164 if ( ! in->summary().isEmpty() ) { 3168 if ( ! in->summary().isEmpty() ) {
3165 in->setDescription(""); 3169 in->setDescription("");
3166 } else { 3170 } else {
3167 in->setSummary( in->description().left(20)); 3171 in->setSummary( in->description().left(20));
3168 in->setDescription(""); 3172 in->setDescription("");
3169 } 3173 }
3170 if ( addText ) 3174 if ( addText )
3171 description += in->summary() + "\n"; 3175 description += in->summary() + "\n";
3172 cal->addIncidence( in ); 3176 cal->addIncidence( in );
3173 incidence = delSel.next(); 3177 incidence = delSel.next();
3174 } 3178 }
3175 if ( beamDialog.beamVcal() ) { 3179 if ( beamDialog.beamVcal() ) {
3176 fn += ".vcs"; 3180 fn += ".vcs";
3177 FileStorage storage( cal, fn, new VCalFormat ); 3181 FileStorage storage( cal, fn, new VCalFormat );
3178 storage.save(); 3182 storage.save();
3179 } else { 3183 } else {
3180 fn += ".ics"; 3184 fn += ".ics";
3181 FileStorage storage( cal, fn, new ICalFormat( ) ); 3185 FileStorage storage( cal, fn, new ICalFormat( ) );
3182 storage.save(); 3186 storage.save();
3183 } 3187 }
3184 delete cal; 3188 delete cal;
3185 mes = i18n("KO/Pi: Ready for beaming"); 3189 mes = i18n("KO/Pi: Ready for beaming");
3186 topLevelWidget()->setCaption(mes); 3190 topLevelWidget()->setCaption(mes);
3187 KApplication::convert2latin1( fn ); 3191 KApplication::convert2latin1( fn );
3188#ifndef DESKTOP_VERSION 3192#ifndef DESKTOP_VERSION
3189 Ir *ir = new Ir( this ); 3193 Ir *ir = new Ir( this );
3190 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3194 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3191 ir->send( fn, description, "text/x-vCalendar" ); 3195 ir->send( fn, description, "text/x-vCalendar" );
3192#endif 3196#endif
3193 } 3197 }
3194} 3198}
3195 3199
3196#ifndef DESKTOP_VERSION 3200#ifndef DESKTOP_VERSION
3197void CalendarView::beamDone( Ir *ir ) 3201void CalendarView::beamDone( Ir *ir )
3198{ 3202{
3199 delete ir; 3203 delete ir;
3200 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3204 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3201 topLevelWidget()->raise(); 3205 topLevelWidget()->raise();
3202} 3206}
3203#else 3207#else
3204void CalendarView::beamDone( Ir *){;} 3208void CalendarView::beamDone( Ir *){;}
3205#endif 3209#endif
3206void CalendarView::moveIncidence(Incidence * inc ) 3210void CalendarView::moveIncidence(Incidence * inc )
3207{ 3211{
3208 if ( !inc ) return; 3212 if ( !inc ) return;
3209 showDatePickerPopup(); 3213 showDatePickerPopup();
3210 mDatePickerMode = 2; 3214 mDatePickerMode = 2;
3211 mMoveIncidence = inc ; 3215 mMoveIncidence = inc ;
3212 QDate da; 3216 QDate da;
3213 if ( mMoveIncidence->typeID() == todoID ) { 3217 if ( mMoveIncidence->typeID() == todoID ) {
3214 Todo * to = (Todo *) mMoveIncidence; 3218 Todo * to = (Todo *) mMoveIncidence;
3215 if ( to->hasDueDate() ) 3219 if ( to->hasDueDate() )
3216 da = to->dtDue().date(); 3220 da = to->dtDue().date();
3217 else 3221 else
3218 da = QDate::currentDate(); 3222 da = QDate::currentDate();
3219 } else { 3223 } else {
3220 da = mMoveIncidence->dtStart().date(); 3224 da = mMoveIncidence->dtStart().date();
3221 } 3225 }
3222 //PENDING set date for recurring incidence to date of recurrence 3226 //PENDING set date for recurring incidence to date of recurrence
3223 //mMoveIncidenceOldDate; 3227 //mMoveIncidenceOldDate;
3224 mDatePicker->setDate( da ); 3228 mDatePicker->setDate( da );
3225} 3229}
3226void CalendarView::showDatePickerPopup() 3230void CalendarView::showDatePickerPopup()
3227{ 3231{
3228 if ( mDateFrame->isVisible() ) 3232 if ( mDateFrame->isVisible() )
3229 mDateFrame->hide(); 3233 mDateFrame->hide();
3230 else { 3234 else {
3231 int offX = 0, offY = 0; 3235 int offX = 0, offY = 0;
3232#ifdef DESKTOP_VERSION 3236#ifdef DESKTOP_VERSION
3233 int w =mDatePicker->sizeHint().width() ; 3237 int w =mDatePicker->sizeHint().width() ;
3234 int h = mDatePicker->sizeHint().height() ; 3238 int h = mDatePicker->sizeHint().height() ;
3235 int dw = topLevelWidget()->width(); 3239 int dw = topLevelWidget()->width();
3236 int dh = topLevelWidget()->height(); 3240 int dh = topLevelWidget()->height();
3237 offX = topLevelWidget()->x(); 3241 offX = topLevelWidget()->x();
3238 offY = topLevelWidget()->y(); 3242 offY = topLevelWidget()->y();
3239#else 3243#else
3240 int w =mDatePicker->sizeHint().width() ; 3244 int w =mDatePicker->sizeHint().width() ;
3241 int h = mDatePicker->sizeHint().height() ; 3245 int h = mDatePicker->sizeHint().height() ;
3242 int dw = QApplication::desktop()->width(); 3246 int dw = QApplication::desktop()->width();
3243 int dh = QApplication::desktop()->height(); 3247 int dh = QApplication::desktop()->height();
3244#endif 3248#endif
3245 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3249 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3246 mDateFrame->show(); 3250 mDateFrame->show();
3247 } 3251 }
3248} 3252}
3249void CalendarView::showDatePicker( ) 3253void CalendarView::showDatePicker( )
3250{ 3254{
3251 showDatePickerPopup(); 3255 showDatePickerPopup();
3252 mDatePickerMode = 1; 3256 mDatePickerMode = 1;
3253 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3257 mDatePicker->setDate( mNavigator->selectedDates().first() );
3254} 3258}
3255 3259
3256void CalendarView::showEventEditor() 3260void CalendarView::showEventEditor()
3257{ 3261{
3258#ifdef DESKTOP_VERSION 3262#ifdef DESKTOP_VERSION
3259 int x,y,w,h; 3263 int x,y,w,h;
3260 x = mEventEditor->geometry().x(); 3264 x = mEventEditor->geometry().x();
3261 y = mEventEditor->geometry().y(); 3265 y = mEventEditor->geometry().y();
3262 w = mEventEditor->width(); 3266 w = mEventEditor->width();
3263 h = mEventEditor->height(); 3267 h = mEventEditor->height();
3264 mEventEditor->show(); 3268 mEventEditor->show();
3265 mEventEditor->setGeometry(x,y,w,h); 3269 mEventEditor->setGeometry(x,y,w,h);
3266#else 3270#else
3267 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3271 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3268 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3272 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3269 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3273 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3270 qApp->processEvents(); 3274 qApp->processEvents();
3271 delete mEventEditor; 3275 delete mEventEditor;
3272 mEventEditor = mDialogManager->getEventEditor(); 3276 mEventEditor = mDialogManager->getEventEditor();
3273 topLevelWidget()->setCaption( i18n("") ); 3277 topLevelWidget()->setCaption( i18n("") );
3274 } 3278 }
3275 mEventEditor->showMaximized(); 3279 mEventEditor->showMaximized();
3276#endif 3280#endif
3277} 3281}
3278void CalendarView::showTodoEditor() 3282void CalendarView::showTodoEditor()
3279{ 3283{
3280#ifdef DESKTOP_VERSION 3284#ifdef DESKTOP_VERSION
3281 int x,y,w,h; 3285 int x,y,w,h;
3282 x = mTodoEditor->geometry().x(); 3286 x = mTodoEditor->geometry().x();
3283 y = mTodoEditor->geometry().y(); 3287 y = mTodoEditor->geometry().y();
3284 w = mTodoEditor->width(); 3288 w = mTodoEditor->width();
3285 h = mTodoEditor->height(); 3289 h = mTodoEditor->height();
3286 mTodoEditor->show(); 3290 mTodoEditor->show();
3287 mTodoEditor->setGeometry(x,y,w,h); 3291 mTodoEditor->setGeometry(x,y,w,h);
3288#else 3292#else
3289 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3293 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3290 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3294 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3291 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3295 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3292 qApp->processEvents(); 3296 qApp->processEvents();
3293 delete mTodoEditor; 3297 delete mTodoEditor;
3294 mTodoEditor = mDialogManager->getTodoEditor(); 3298 mTodoEditor = mDialogManager->getTodoEditor();
3295 topLevelWidget()->setCaption( i18n("") ); 3299 topLevelWidget()->setCaption( i18n("") );
3296 } 3300 }
3297 mTodoEditor->showMaximized(); 3301 mTodoEditor->showMaximized();
3298#endif 3302#endif
3299} 3303}
3300 3304
3301void CalendarView::cloneIncidence() 3305void CalendarView::cloneIncidence()
3302{ 3306{
3303 Incidence *incidence = currentSelection(); 3307 Incidence *incidence = currentSelection();
3304 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3308 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3305 if ( incidence ) { 3309 if ( incidence ) {
3306 cloneIncidence(incidence); 3310 cloneIncidence(incidence);
3307 } 3311 }
3308} 3312}
3309void CalendarView::moveIncidence() 3313void CalendarView::moveIncidence()
3310{ 3314{
3311 Incidence *incidence = currentSelection(); 3315 Incidence *incidence = currentSelection();
3312 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3316 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3313 if ( incidence ) { 3317 if ( incidence ) {
3314 moveIncidence(incidence); 3318 moveIncidence(incidence);
3315 } 3319 }
3316} 3320}
3317void CalendarView::beamIncidence() 3321void CalendarView::beamIncidence()
3318{ 3322{
3319 Incidence *incidence = currentSelection(); 3323 Incidence *incidence = currentSelection();
3320 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3324 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3321 if ( incidence ) { 3325 if ( incidence ) {
3322 beamIncidence(incidence); 3326 beamIncidence(incidence);
3323 } 3327 }
3324} 3328}
3325void CalendarView::toggleCancelIncidence() 3329void CalendarView::toggleCancelIncidence()
3326{ 3330{
3327 Incidence *incidence = currentSelection(); 3331 Incidence *incidence = currentSelection();
3328 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3332 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3329 if ( incidence ) { 3333 if ( incidence ) {
3330 cancelIncidence(incidence); 3334 cancelIncidence(incidence);
3331 } 3335 }
3332} 3336}
3333 3337
3334 3338
3335void CalendarView::cancelIncidence(Incidence * inc ) 3339void CalendarView::cancelIncidence(Incidence * inc )
3336{ 3340{
3337 inc->setCancelled( ! inc->cancelled() ); 3341 inc->setCancelled( ! inc->cancelled() );
3338 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3342 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3339 updateView(); 3343 updateView();
3340} 3344}
3341void CalendarView::cloneIncidence(Incidence * orgInc ) 3345void CalendarView::cloneIncidence(Incidence * orgInc )
3342{ 3346{
3343 Incidence * newInc = orgInc->clone(); 3347 Incidence * newInc = orgInc->clone();
3344 newInc->recreate(); 3348 newInc->recreate();
3345 3349
3346 if ( newInc->typeID() == todoID ) { 3350 if ( newInc->typeID() == todoID ) {
3347 Todo* t = (Todo*) newInc; 3351 Todo* t = (Todo*) newInc;
3348 bool cloneSub = false; 3352 bool cloneSub = false;
3349 if ( orgInc->relations().count() ) { 3353 if ( orgInc->relations().count() ) {
3350 int result = KMessageBox::warningYesNoCancel(this, 3354 int result = KMessageBox::warningYesNoCancel(this,
3351 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 ) ), 3355 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 ) ),
3352 i18n("Todo has subtodos"), 3356 i18n("Todo has subtodos"),
3353 i18n("Yes"), 3357 i18n("Yes"),
3354 i18n("No")); 3358 i18n("No"));
3355 3359
3356 if ( result == KMessageBox::Cancel ) { 3360 if ( result == KMessageBox::Cancel ) {
3357 delete t; 3361 delete t;
3358 return; 3362 return;
3359 } 3363 }
3360 if (result == KMessageBox::Yes) cloneSub = true; 3364 if (result == KMessageBox::Yes) cloneSub = true;
3361 } 3365 }
3362 showTodoEditor(); 3366 showTodoEditor();
3363 mTodoEditor->editTodo( t ); 3367 mTodoEditor->editTodo( t );
3364 if ( mTodoEditor->exec() ) { 3368 if ( mTodoEditor->exec() ) {
3365 if ( cloneSub ) { 3369 if ( cloneSub ) {
3366 orgInc->cloneRelations( t ); 3370 orgInc->cloneRelations( t );
3367 mCalendar->addIncidenceBranch( t ); 3371 mCalendar->addIncidenceBranch( t );
3368 updateView(); 3372 updateView();
3369 3373
3370 } else { 3374 } else {
3371 mCalendar->addTodo( t ); 3375 mCalendar->addTodo( t );
3372 updateView(); 3376 updateView();
3373 } 3377 }
3374 } else { 3378 } else {
3375 delete t; 3379 delete t;
3376 } 3380 }
3377 } 3381 }
3378 else if ( newInc->typeID() == eventID ) { 3382 else if ( newInc->typeID() == eventID ) {
3379 Event* e = (Event*) newInc; 3383 Event* e = (Event*) newInc;
3380 showEventEditor(); 3384 showEventEditor();
3381 mEventEditor->editEvent( e ); 3385 mEventEditor->editEvent( e );
3382 if ( mEventEditor->exec() ) { 3386 if ( mEventEditor->exec() ) {
3383 mCalendar->addEvent( e ); 3387 mCalendar->addEvent( e );
3384 updateView(); 3388 updateView();
3385 } else { 3389 } else {
3386 delete e; 3390 delete e;
3387 } 3391 }
3388 } if ( newInc->typeID() == journalID ) { 3392 } if ( newInc->typeID() == journalID ) {
3389 mCalendar->addJournal( (Journal*) newInc ); 3393 mCalendar->addJournal( (Journal*) newInc );
3390 editJournal( (Journal*) newInc ); 3394 editJournal( (Journal*) newInc );
3391 } 3395 }
3392 setActiveWindow(); 3396 setActiveWindow();
3393} 3397}
3394 3398
3395void CalendarView::newEvent() 3399void CalendarView::newEvent()
3396{ 3400{
3397 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3401 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3398 KOAgendaView *aView = mViewManager->agendaView(); 3402 KOAgendaView *aView = mViewManager->agendaView();
3399 if (aView) { 3403 if (aView) {
3400 if (aView->selectionStart().isValid()) { 3404 if (aView->selectionStart().isValid()) {
3401 if (aView->selectedIsAllDay()) { 3405 if (aView->selectedIsAllDay()) {
3402 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3406 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3403 } else { 3407 } else {
3404 newEvent(aView->selectionStart(),aView->selectionEnd()); 3408 newEvent(aView->selectionStart(),aView->selectionEnd());
3405 } 3409 }
3406 return; 3410 return;
3407 } 3411 }
3408 } 3412 }
3409 3413
3410 QDate date = mNavigator->selectedDates().first(); 3414 QDate date = mNavigator->selectedDates().first();
3411#if 0 3415#if 0
3412 QDateTime current = QDateTime::currentDateTime(); 3416 QDateTime current = QDateTime::currentDateTime();
3413 if ( date <= current.date() ) { 3417 if ( date <= current.date() ) {
3414 int hour = current.time().hour() +1; 3418 int hour = current.time().hour() +1;
3415 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3419 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3416 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3420 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3417 } else 3421 } else
3418#endif 3422#endif
3419 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3423 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3420 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3424 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3421 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3425 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3422} 3426}
3423 3427
3424void CalendarView::newEvent(QDateTime fh) 3428void CalendarView::newEvent(QDateTime fh)
3425{ 3429{
3426 newEvent(fh, 3430 newEvent(fh,
3427 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3431 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3428} 3432}
3429 3433
3430void CalendarView::newEvent(QDate dt) 3434void CalendarView::newEvent(QDate dt)
3431{ 3435{
3432 newEvent(QDateTime(dt, QTime(0,0,0)), 3436 newEvent(QDateTime(dt, QTime(0,0,0)),
3433 QDateTime(dt, QTime(0,0,0)), true); 3437 QDateTime(dt, QTime(0,0,0)), true);
3434} 3438}
3435void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3439void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3436{ 3440{
3437 newEvent(fromHint, toHint, false); 3441 newEvent(fromHint, toHint, false);
3438} 3442}
3439void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3443void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3440{ 3444{
3441 3445
3442 showEventEditor(); 3446 showEventEditor();
3443 mEventEditor->newEvent(fromHint,toHint,allDay); 3447 mEventEditor->newEvent(fromHint,toHint,allDay);
3444 if ( mFilterView->filtersEnabled() ) { 3448 if ( mFilterView->filtersEnabled() ) {
3445 CalFilter *filter = mFilterView->selectedFilter(); 3449 CalFilter *filter = mFilterView->selectedFilter();
3446 if (filter && filter->showCategories()) { 3450 if (filter && filter->showCategories()) {
3447 mEventEditor->setCategories(filter->categoryList().join(",") ); 3451 mEventEditor->setCategories(filter->categoryList().join(",") );
3448 } 3452 }
3449 if ( filter ) 3453 if ( filter )
3450 mEventEditor->setSecrecy( filter->getSecrecy() ); 3454 mEventEditor->setSecrecy( filter->getSecrecy() );
3451 } 3455 }
3452 mEventEditor->exec(); 3456 mEventEditor->exec();
3453 setActiveWindow(); 3457 setActiveWindow();
3454} 3458}
3455void CalendarView::todoAdded(Todo * t) 3459void CalendarView::todoAdded(Todo * t)
3456{ 3460{
3457 3461
3458 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3462 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3459 updateTodoViews(); 3463 updateTodoViews();
3460} 3464}
3461void CalendarView::todoChanged(Todo * t) 3465void CalendarView::todoChanged(Todo * t)
3462{ 3466{
3463 emit todoModified( t, 4 ); 3467 emit todoModified( t, 4 );
3464 // updateTodoViews(); 3468 // updateTodoViews();
3465} 3469}
3466void CalendarView::todoToBeDeleted(Todo *) 3470void CalendarView::todoToBeDeleted(Todo *)
3467{ 3471{
3468 //qDebug("todoToBeDeleted(Todo *) "); 3472 //qDebug("todoToBeDeleted(Todo *) ");
3469 updateTodoViews(); 3473 updateTodoViews();
3470} 3474}
3471void CalendarView::todoDeleted() 3475void CalendarView::todoDeleted()
3472{ 3476{
3473 //qDebug(" todoDeleted()"); 3477 //qDebug(" todoDeleted()");
3474 updateTodoViews(); 3478 updateTodoViews();
3475} 3479}
3476 3480
3477 3481
3478void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3482void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3479{ 3483{
3480 showTodoEditor(); 3484 showTodoEditor();
3481 mTodoEditor->newTodo(dt,0,allday); 3485 mTodoEditor->newTodo(dt,0,allday);
3482 if ( mFilterView->filtersEnabled() ) { 3486 if ( mFilterView->filtersEnabled() ) {
3483 CalFilter *filter = mFilterView->selectedFilter(); 3487 CalFilter *filter = mFilterView->selectedFilter();
3484 if (filter && filter->showCategories()) { 3488 if (filter && filter->showCategories()) {
3485 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3489 mTodoEditor->setCategories(filter->categoryList().join(",") );
3486 } 3490 }
3487 if ( filter ) 3491 if ( filter )
3488 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3492 mTodoEditor->setSecrecy( filter->getSecrecy() );
3489 } 3493 }
3490 mTodoEditor->exec(); 3494 mTodoEditor->exec();
3491 setActiveWindow(); 3495 setActiveWindow();
3492} 3496}
3493 3497
3494void CalendarView::newTodo() 3498void CalendarView::newTodo()
3495{ 3499{
3496 newTodoDateTime( QDateTime(),true ); 3500 newTodoDateTime( QDateTime(),true );
3497} 3501}
3498 3502
3499void CalendarView::newSubTodo() 3503void CalendarView::newSubTodo()
3500{ 3504{
3501 Todo *todo = selectedTodo(); 3505 Todo *todo = selectedTodo();
3502 if ( todo ) newSubTodo( todo ); 3506 if ( todo ) newSubTodo( todo );
3503} 3507}
3504 3508
3505void CalendarView::newSubTodo(Todo *parentEvent) 3509void CalendarView::newSubTodo(Todo *parentEvent)
3506{ 3510{
3507 3511
3508 showTodoEditor(); 3512 showTodoEditor();
3509 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3513 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3510 mTodoEditor->exec(); 3514 mTodoEditor->exec();
3511 setActiveWindow(); 3515 setActiveWindow();
3512} 3516}
3513 3517
3514void CalendarView::newFloatingEvent() 3518void CalendarView::newFloatingEvent()
3515{ 3519{
3516 DateList tmpList = mNavigator->selectedDates(); 3520 DateList tmpList = mNavigator->selectedDates();
3517 QDate date = tmpList.first(); 3521 QDate date = tmpList.first();
3518 3522
3519 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3523 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3520 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3524 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3521} 3525}
3522 3526
3523 3527
3524void CalendarView::editEvent( Event *event ) 3528void CalendarView::editEvent( Event *event )
3525{ 3529{
3526 3530
3527 if ( !event ) return; 3531 if ( !event ) return;
3528 if ( event->isReadOnly() ) { 3532 if ( event->isReadOnly() ) {
3529 showEvent( event ); 3533 showEvent( event );
3530 return; 3534 return;
3531 } 3535 }
3532 showEventEditor(); 3536 showEventEditor();
3533 mEventEditor->editEvent( event , mFlagEditDescription); 3537 mEventEditor->editEvent( event , mFlagEditDescription);
3534 mEventEditor->exec(); 3538 mEventEditor->exec();
3535 setActiveWindow(); 3539 setActiveWindow();
3536 3540
3537} 3541}
3538void CalendarView::editJournal( Journal *jour ) 3542void CalendarView::editJournal( Journal *jour )
3539{ 3543{
3540 if ( !jour ) return; 3544 if ( !jour ) return;
3541 mDialogManager->hideSearchDialog(); 3545 mDialogManager->hideSearchDialog();
3542 mViewManager->showJournalView(); 3546 mViewManager->showJournalView();
3543 mNavigator->slotDaySelect( jour->dtStart().date() ); 3547 mNavigator->slotDaySelect( jour->dtStart().date() );
3544} 3548}
3545void CalendarView::editTodo( Todo *todo ) 3549void CalendarView::editTodo( Todo *todo )
3546{ 3550{
3547 if ( !todo ) return; 3551 if ( !todo ) return;
3548 3552
3549 if ( todo->isReadOnly() ) { 3553 if ( todo->isReadOnly() ) {
3550 showTodo( todo ); 3554 showTodo( todo );
3551 return; 3555 return;
3552 } 3556 }
3553 showTodoEditor(); 3557 showTodoEditor();
3554 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3558 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3555 mTodoEditor->exec(); 3559 mTodoEditor->exec();
3556 setActiveWindow(); 3560 setActiveWindow();
3557 3561
3558} 3562}
3559 3563
3560KOEventViewerDialog* CalendarView::getEventViewerDialog() 3564KOEventViewerDialog* CalendarView::getEventViewerDialog()
3561{ 3565{
3562 if ( !mEventViewerDialog ) { 3566 if ( !mEventViewerDialog ) {
3563 mEventViewerDialog = new KOEventViewerDialog(0); 3567 mEventViewerDialog = new KOEventViewerDialog(0);
3564 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3568 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3565 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3569 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3566 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3570 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3567 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3571 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3568 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3572 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3569 viewManager(), SLOT( showAgendaView( bool ) ) ); 3573 viewManager(), SLOT( showAgendaView( bool ) ) );
3570 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3574 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3571 this, SLOT( slotViewerClosed() ) ); 3575 this, SLOT( slotViewerClosed() ) );
3572 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3576 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3573 this, SLOT( todoChanged(Todo *) ) ); 3577 this, SLOT( todoChanged(Todo *) ) );
3574 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3578 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3575 mEventViewerDialog->resize( 640, 480 ); 3579 mEventViewerDialog->resize( 640, 480 );
3576 3580
3577 } 3581 }
3578 return mEventViewerDialog; 3582 return mEventViewerDialog;
3579} 3583}
3580void CalendarView::showEvent(Event *event) 3584void CalendarView::showEvent(Event *event)
3581{ 3585{
3582 getEventViewerDialog()->setEvent(event); 3586 getEventViewerDialog()->setEvent(event);
3583 getEventViewerDialog()->showMe(); 3587 getEventViewerDialog()->showMe();
3584} 3588}
3585 3589
3586void CalendarView::showTodo(Todo *event) 3590void CalendarView::showTodo(Todo *event)
3587{ 3591{
3588 getEventViewerDialog()->setTodo(event); 3592 getEventViewerDialog()->setTodo(event);
3589 getEventViewerDialog()->showMe(); 3593 getEventViewerDialog()->showMe();
3590} 3594}
3591void CalendarView::showJournal( Journal *jour ) 3595void CalendarView::showJournal( Journal *jour )
3592{ 3596{
3593 getEventViewerDialog()->setJournal(jour); 3597 getEventViewerDialog()->setJournal(jour);
3594 getEventViewerDialog()->showMe(); 3598 getEventViewerDialog()->showMe();
3595 3599
3596} 3600}
3597// void CalendarView::todoModified (Todo *event, int changed) 3601// void CalendarView::todoModified (Todo *event, int changed)
3598// { 3602// {
3599// // if (mDialogList.find (event) != mDialogList.end ()) { 3603// // if (mDialogList.find (event) != mDialogList.end ()) {
3600// // kdDebug() << "Todo modified and open" << endl; 3604// // kdDebug() << "Todo modified and open" << endl;
3601// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3605// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3602// // temp->modified (changed); 3606// // temp->modified (changed);
3603 3607
3604// // } 3608// // }
3605 3609
3606// mViewManager->updateView(); 3610// mViewManager->updateView();
3607// } 3611// }
3608 3612
3609void CalendarView::appointment_show() 3613void CalendarView::appointment_show()
3610{ 3614{
3611 Event *anEvent = 0; 3615 Event *anEvent = 0;
3612 3616
3613 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3617 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3614 3618
3615 if (mViewManager->currentView()->isEventView()) { 3619 if (mViewManager->currentView()->isEventView()) {
3616 if ( incidence && incidence->typeID() == eventID ) { 3620 if ( incidence && incidence->typeID() == eventID ) {
3617 anEvent = static_cast<Event *>(incidence); 3621 anEvent = static_cast<Event *>(incidence);
3618 } 3622 }
3619 } 3623 }
3620 3624
3621 if (!anEvent) { 3625 if (!anEvent) {
3622 KNotifyClient::beep(); 3626 KNotifyClient::beep();
3623 return; 3627 return;
3624 } 3628 }
3625 3629
3626 showEvent(anEvent); 3630 showEvent(anEvent);
3627} 3631}
3628 3632
3629void CalendarView::appointment_edit() 3633void CalendarView::appointment_edit()
3630{ 3634{
3631 Event *anEvent = 0; 3635 Event *anEvent = 0;
3632 3636
3633 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3637 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3634 3638
3635 if (mViewManager->currentView()->isEventView()) { 3639 if (mViewManager->currentView()->isEventView()) {
3636 if ( incidence && incidence->typeID() == eventID ) { 3640 if ( incidence && incidence->typeID() == eventID ) {
3637 anEvent = static_cast<Event *>(incidence); 3641 anEvent = static_cast<Event *>(incidence);
3638 } 3642 }
3639 } 3643 }
3640 3644
3641 if (!anEvent) { 3645 if (!anEvent) {
3642 KNotifyClient::beep(); 3646 KNotifyClient::beep();
3643 return; 3647 return;
3644 } 3648 }
3645 3649
3646 editEvent(anEvent); 3650 editEvent(anEvent);
3647} 3651}
3648 3652
3649void CalendarView::appointment_delete() 3653void CalendarView::appointment_delete()
3650{ 3654{
3651 Event *anEvent = 0; 3655 Event *anEvent = 0;
3652 3656
3653 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3657 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3654 3658
3655 if (mViewManager->currentView()->isEventView()) { 3659 if (mViewManager->currentView()->isEventView()) {
3656 if ( incidence && incidence->typeID() == eventID ) { 3660 if ( incidence && incidence->typeID() == eventID ) {
3657 anEvent = static_cast<Event *>(incidence); 3661 anEvent = static_cast<Event *>(incidence);
3658 } 3662 }
3659 } 3663 }
3660 3664
3661 if (!anEvent) { 3665 if (!anEvent) {
3662 KNotifyClient::beep(); 3666 KNotifyClient::beep();
3663 return; 3667 return;
3664 } 3668 }
3665 3669
3666 deleteEvent(anEvent); 3670 deleteEvent(anEvent);
3667} 3671}
3668 3672
3669void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3673void CalendarView::todo_resub( Todo * parent, Todo * sub )
3670{ 3674{
3671 if (!sub) return; 3675 if (!sub) return;
3672 if ( sub->relatedTo() == parent ) 3676 if ( sub->relatedTo() == parent )
3673 return; 3677 return;
3674 sub->setRelatedTo(parent); 3678 sub->setRelatedTo(parent);
3675 sub->updated(); 3679 sub->updated();
3676 setModified(true); 3680 setModified(true);
3677 updateView(); 3681 updateView();
3678} 3682}
3679void CalendarView::todo_unsub(Todo *anTodo ) 3683void CalendarView::todo_unsub(Todo *anTodo )
3680{ 3684{
3681 todo_resub( 0, anTodo ); 3685 todo_resub( 0, anTodo );
3682} 3686}
3683 3687
3684void CalendarView::deleteTodo(Todo *todo) 3688void CalendarView::deleteTodo(Todo *todo)
3685{ 3689{
3686 if (!todo) { 3690 if (!todo) {
3687 KNotifyClient::beep(); 3691 KNotifyClient::beep();
3688 return; 3692 return;
3689 } 3693 }
3690 if (KOPrefs::instance()->mConfirm) { 3694 if (KOPrefs::instance()->mConfirm) {
3691 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3695 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3692 if (!todo->relations().isEmpty()) { 3696 if (!todo->relations().isEmpty()) {
3693 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3697 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3694 3698
3695 } 3699 }
3696 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3700 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3697 case KMessageBox::Continue: // OK 3701 case KMessageBox::Continue: // OK
3698 bool deleteT = false; 3702 bool deleteT = false;
3699 if (!todo->relations().isEmpty()) { 3703 if (!todo->relations().isEmpty()) {
3700 deleteT = removeCompletedSubTodos( todo ); 3704 deleteT = removeCompletedSubTodos( todo );
3701 } 3705 }
3702 // deleteT == true: todo already deleted in removeCompletedSubTodos 3706 // deleteT == true: todo already deleted in removeCompletedSubTodos
3703 if ( !deleteT ) { 3707 if ( !deleteT ) {
3704 checkExternalId( todo ); 3708 checkExternalId( todo );
3705 calendar()->deleteTodo(todo); 3709 calendar()->deleteTodo(todo);
3706 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3710 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3707 updateView(); 3711 updateView();
3708 } 3712 }
3709 break; 3713 break;
3710 } // switch 3714 } // switch
3711 } else { 3715 } else {
3712 checkExternalId( todo ); 3716 checkExternalId( todo );
3713 mCalendar->deleteTodo(todo); 3717 mCalendar->deleteTodo(todo);
3714 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3718 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3715 updateView(); 3719 updateView();
3716 } 3720 }
3717 3721
3718 emit updateSearchDialog(); 3722 emit updateSearchDialog();
3719} 3723}
3720void CalendarView::deleteJournal(Journal *jour) 3724void CalendarView::deleteJournal(Journal *jour)
3721{ 3725{
3722 if (!jour) { 3726 if (!jour) {
3723 KNotifyClient::beep(); 3727 KNotifyClient::beep();
3724 return; 3728 return;
3725 } 3729 }
3726 if (KOPrefs::instance()->mConfirm) { 3730 if (KOPrefs::instance()->mConfirm) {
3727 3731
3728 QString des; 3732 QString des;
3729 if ( !jour->summary().isEmpty() ) { 3733 if ( !jour->summary().isEmpty() ) {
3730 des = jour->summary(); 3734 des = jour->summary();
3731 } else { 3735 } else {
3732 des = jour->description().left(30); 3736 des = jour->description().left(30);
3733 des = des.simplifyWhiteSpace (); 3737 des = des.simplifyWhiteSpace ();
3734 des.replace (QRegExp ("\\n"),"" ); 3738 des.replace (QRegExp ("\\n"),"" );
3735 des.replace (QRegExp ("\\r"),"" ); 3739 des.replace (QRegExp ("\\r"),"" );
3736 } 3740 }
3737 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3741 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3738 case KMessageBox::Continue: // OK 3742 case KMessageBox::Continue: // OK
3739 calendar()->deleteJournal(jour); 3743 calendar()->deleteJournal(jour);
3740 updateView(); 3744 updateView();
3741 break; 3745 break;
3742 } // switch 3746 } // switch
3743 } else { 3747 } else {
3744 calendar()->deleteJournal(jour);; 3748 calendar()->deleteJournal(jour);;
3745 updateView(); 3749 updateView();
3746 } 3750 }
3747 emit updateSearchDialog(); 3751 emit updateSearchDialog();
3748} 3752}
3749 3753
3750void CalendarView::deleteEvent(Event *anEvent) 3754void CalendarView::deleteEvent(Event *anEvent)
3751{ 3755{
3752 if (!anEvent) { 3756 if (!anEvent) {
3753 KNotifyClient::beep(); 3757 KNotifyClient::beep();
3754 return; 3758 return;
3755 } 3759 }
3756 3760
3757 if (anEvent->recurrence()->doesRecur()) { 3761 if (anEvent->recurrence()->doesRecur()) {
3758 QDate itemDate = mViewManager->currentSelectionDate(); 3762 QDate itemDate = mViewManager->currentSelectionDate();
3759 int km; 3763 int km;
3760 if (!itemDate.isValid()) { 3764 if (!itemDate.isValid()) {
3761 //kdDebug() << "Date Not Valid" << endl; 3765 //kdDebug() << "Date Not Valid" << endl;
3762 if (KOPrefs::instance()->mConfirm) { 3766 if (KOPrefs::instance()->mConfirm) {
3763 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3767 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3764 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3768 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3765 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3769 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3766 if ( km == KMessageBox::Continue ) 3770 if ( km == KMessageBox::Continue )
3767 km = KMessageBox::No; // No = all below 3771 km = KMessageBox::No; // No = all below
3768 } else 3772 } else
3769 km = KMessageBox::No; 3773 km = KMessageBox::No;
3770 } else { 3774 } else {
3771 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3775 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3772 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3776 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3773 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3777 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3774 i18n("KO/Pi Confirmation"),i18n("Current"), 3778 i18n("KO/Pi Confirmation"),i18n("Current"),
3775 i18n("All")); 3779 i18n("All"));
3776 } 3780 }
3777 switch(km) { 3781 switch(km) {
3778 3782
3779 case KMessageBox::No: // Continue // all 3783 case KMessageBox::No: // Continue // all
3780 //qDebug("KMessageBox::No "); 3784 //qDebug("KMessageBox::No ");
3781 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3785 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3782 schedule(Scheduler::Cancel,anEvent); 3786 schedule(Scheduler::Cancel,anEvent);
3783 3787
3784 checkExternalId( anEvent); 3788 checkExternalId( anEvent);
3785 mCalendar->deleteEvent(anEvent); 3789 mCalendar->deleteEvent(anEvent);
3786 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3790 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3787 break; 3791 break;
3788 3792
3789 // Disabled because it does not work 3793 // Disabled because it does not work
3790 //#if 0 3794 //#if 0
3791 case KMessageBox::Yes: // just this one 3795 case KMessageBox::Yes: // just this one
3792 //QDate qd = mNavigator->selectedDates().first(); 3796 //QDate qd = mNavigator->selectedDates().first();
3793 //if (!qd.isValid()) { 3797 //if (!qd.isValid()) {
3794 // kdDebug() << "no date selected, or invalid date" << endl; 3798 // kdDebug() << "no date selected, or invalid date" << endl;
3795 // KNotifyClient::beep(); 3799 // KNotifyClient::beep();
3796 // return; 3800 // return;
3797 //} 3801 //}
3798 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3802 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3799 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3803 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3800 anEvent->addExDate(itemDate); 3804 anEvent->addExDate(itemDate);
3801 int duration = anEvent->recurrence()->duration(); 3805 int duration = anEvent->recurrence()->duration();
3802 if ( duration > 0 ) { 3806 if ( duration > 0 ) {
3803 anEvent->recurrence()->setDuration( duration - 1 ); 3807 anEvent->recurrence()->setDuration( duration - 1 );
3804 } 3808 }
3805 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3809 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3806 } 3810 }
3807 break; 3811 break;
3808 //#endif 3812 //#endif
3809 } // switch 3813 } // switch
3810 } else { 3814 } else {
3811 if (KOPrefs::instance()->mConfirm) { 3815 if (KOPrefs::instance()->mConfirm) {
3812 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3816 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3813 i18n("\nAre you sure you want\nto delete this event?"), 3817 i18n("\nAre you sure you want\nto delete this event?"),
3814 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3818 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3815 case KMessageBox::Continue: // OK 3819 case KMessageBox::Continue: // OK
3816 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3820 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3817 schedule(Scheduler::Cancel,anEvent); 3821 schedule(Scheduler::Cancel,anEvent);
3818 checkExternalId( anEvent); 3822 checkExternalId( anEvent);
3819 mCalendar->deleteEvent(anEvent); 3823 mCalendar->deleteEvent(anEvent);
3820 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3824 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3821 break; 3825 break;
3822 } // switch 3826 } // switch
3823 } else { 3827 } else {
3824 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3828 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3825 schedule(Scheduler::Cancel,anEvent); 3829 schedule(Scheduler::Cancel,anEvent);
3826 checkExternalId( anEvent); 3830 checkExternalId( anEvent);
3827 mCalendar->deleteEvent(anEvent); 3831 mCalendar->deleteEvent(anEvent);
3828 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3832 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3829 } 3833 }
3830 } // if-else 3834 } // if-else
3831 emit updateSearchDialog(); 3835 emit updateSearchDialog();
3832} 3836}
3833 3837
3834bool CalendarView::deleteEvent(const QString &uid) 3838bool CalendarView::deleteEvent(const QString &uid)
3835{ 3839{
3836 Event *ev = mCalendar->event(uid); 3840 Event *ev = mCalendar->event(uid);
3837 if (ev) { 3841 if (ev) {
3838 deleteEvent(ev); 3842 deleteEvent(ev);
3839 return true; 3843 return true;
3840 } else { 3844 } else {
3841 return false; 3845 return false;
3842 } 3846 }
3843} 3847}
3844 3848
3845/*****************************************************************************/ 3849/*****************************************************************************/
3846 3850
3847void CalendarView::action_mail() 3851void CalendarView::action_mail()
3848{ 3852{
3849#ifndef KORG_NOMAIL 3853#ifndef KORG_NOMAIL
3850 KOMailClient mailClient; 3854 KOMailClient mailClient;
3851 3855
3852 Incidence *incidence = currentSelection(); 3856 Incidence *incidence = currentSelection();
3853 3857
3854 if (!incidence) { 3858 if (!incidence) {
3855 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3859 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3856 return; 3860 return;
3857 } 3861 }
3858 if(incidence->attendeeCount() == 0 ) { 3862 if(incidence->attendeeCount() == 0 ) {
3859 KMessageBox::sorry(this, 3863 KMessageBox::sorry(this,
3860 i18n("Can't generate mail:\nNo attendees defined.\n")); 3864 i18n("Can't generate mail:\nNo attendees defined.\n"));
3861 return; 3865 return;
3862 } 3866 }
3863 3867
3864 CalendarLocal cal_tmp; 3868 CalendarLocal cal_tmp;
3865 Event *event = 0; 3869 Event *event = 0;
3866 Event *ev = 0; 3870 Event *ev = 0;
3867 if ( incidence && incidence->typeID() == eventID ) { 3871 if ( incidence && incidence->typeID() == eventID ) {
3868 event = static_cast<Event *>(incidence); 3872 event = static_cast<Event *>(incidence);
3869 ev = new Event(*event); 3873 ev = new Event(*event);
3870 cal_tmp.addEvent(ev); 3874 cal_tmp.addEvent(ev);
3871 } 3875 }
3872 ICalFormat mForm(); 3876 ICalFormat mForm();
3873 QString attachment = mForm.toString( &cal_tmp ); 3877 QString attachment = mForm.toString( &cal_tmp );
3874 if (ev) delete(ev); 3878 if (ev) delete(ev);
3875 3879
3876 mailClient.mailAttendees(currentSelection(), attachment); 3880 mailClient.mailAttendees(currentSelection(), attachment);
3877 3881
3878#endif 3882#endif
3879 3883
3880#if 0 3884#if 0
3881 Event *anEvent = 0; 3885 Event *anEvent = 0;
3882 if (mViewManager->currentView()->isEventView()) { 3886 if (mViewManager->currentView()->isEventView()) {
3883 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3887 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3884 } 3888 }
3885 3889
3886 if (!anEvent) { 3890 if (!anEvent) {
3887 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3891 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3888 return; 3892 return;
3889 } 3893 }
3890 if(anEvent->attendeeCount() == 0 ) { 3894 if(anEvent->attendeeCount() == 0 ) {
3891 KMessageBox::sorry(this, 3895 KMessageBox::sorry(this,
3892 i18n("Can't generate mail:\nNo attendees defined.\n")); 3896 i18n("Can't generate mail:\nNo attendees defined.\n"));
3893 return; 3897 return;
3894 } 3898 }
3895 3899
3896 mailobject.emailEvent(anEvent); 3900 mailobject.emailEvent(anEvent);
3897#endif 3901#endif
3898} 3902}
3899 3903
3900 3904
3901void CalendarView::schedule_publish(Incidence *incidence) 3905void CalendarView::schedule_publish(Incidence *incidence)
3902{ 3906{
3903 Event *event = 0; 3907 Event *event = 0;
3904 Todo *todo = 0; 3908 Todo *todo = 0;
3905 3909
3906 if (incidence == 0) { 3910 if (incidence == 0) {
3907 incidence = mViewManager->currentView()->selectedIncidences().first(); 3911 incidence = mViewManager->currentView()->selectedIncidences().first();
3908 if (incidence == 0) { 3912 if (incidence == 0) {
3909 incidence = mTodoList->selectedIncidences().first(); 3913 incidence = mTodoList->selectedIncidences().first();
3910 } 3914 }
3911 } 3915 }
3912 if ( incidence && incidence->typeID() == eventID ) { 3916 if ( incidence && incidence->typeID() == eventID ) {
3913 event = static_cast<Event *>(incidence); 3917 event = static_cast<Event *>(incidence);
3914 } else { 3918 } else {
3915 if ( incidence && incidence->typeID() == todoID ) { 3919 if ( incidence && incidence->typeID() == todoID ) {
3916 todo = static_cast<Todo *>(incidence); 3920 todo = static_cast<Todo *>(incidence);
3917 } 3921 }
3918 } 3922 }
3919 3923
3920 if (!event && !todo) { 3924 if (!event && !todo) {
3921 KMessageBox::sorry(this,i18n("No event selected.")); 3925 KMessageBox::sorry(this,i18n("No event selected."));
3922 return; 3926 return;
3923 } 3927 }
3924 3928
3925 PublishDialog *publishdlg = new PublishDialog(); 3929 PublishDialog *publishdlg = new PublishDialog();
3926 if (incidence->attendeeCount()>0) { 3930 if (incidence->attendeeCount()>0) {
3927 QPtrList<Attendee> attendees = incidence->attendees(); 3931 QPtrList<Attendee> attendees = incidence->attendees();
3928 attendees.first(); 3932 attendees.first();
3929 while ( attendees.current()!=0 ) { 3933 while ( attendees.current()!=0 ) {
3930 publishdlg->addAttendee(attendees.current()); 3934 publishdlg->addAttendee(attendees.current());
3931 attendees.next(); 3935 attendees.next();
3932 } 3936 }
3933 } 3937 }
3934 bool send = true; 3938 bool send = true;
3935 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3939 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3936 if ( publishdlg->exec() != QDialog::Accepted ) 3940 if ( publishdlg->exec() != QDialog::Accepted )
3937 send = false; 3941 send = false;
3938 } 3942 }
3939 if ( send ) { 3943 if ( send ) {
3940 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3944 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3941 if ( event ) { 3945 if ( event ) {
3942 Event *ev = new Event(*event); 3946 Event *ev = new Event(*event);
3943 ev->registerObserver(0); 3947 ev->registerObserver(0);
3944 ev->clearAttendees(); 3948 ev->clearAttendees();
3945 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3949 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3946 delete(ev); 3950 delete(ev);
3947 } 3951 }
3948 } else { 3952 } else {
3949 if ( todo ) { 3953 if ( todo ) {
3950 Todo *ev = new Todo(*todo); 3954 Todo *ev = new Todo(*todo);
3951 ev->registerObserver(0); 3955 ev->registerObserver(0);
3952 ev->clearAttendees(); 3956 ev->clearAttendees();
3953 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3957 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3954 delete(ev); 3958 delete(ev);
3955 } 3959 }
3956 } 3960 }
3957 } 3961 }
3958 } 3962 }
3959 delete publishdlg; 3963 delete publishdlg;
3960} 3964}
3961 3965
3962void CalendarView::schedule_request(Incidence *incidence) 3966void CalendarView::schedule_request(Incidence *incidence)
3963{ 3967{
3964 schedule(Scheduler::Request,incidence); 3968 schedule(Scheduler::Request,incidence);
3965} 3969}
3966 3970
3967void CalendarView::schedule_refresh(Incidence *incidence) 3971void CalendarView::schedule_refresh(Incidence *incidence)
3968{ 3972{
3969 schedule(Scheduler::Refresh,incidence); 3973 schedule(Scheduler::Refresh,incidence);
3970} 3974}
3971 3975
3972void CalendarView::schedule_cancel(Incidence *incidence) 3976void CalendarView::schedule_cancel(Incidence *incidence)
3973{ 3977{
3974 schedule(Scheduler::Cancel,incidence); 3978 schedule(Scheduler::Cancel,incidence);
3975} 3979}
3976 3980
3977void CalendarView::schedule_add(Incidence *incidence) 3981void CalendarView::schedule_add(Incidence *incidence)
3978{ 3982{
3979 schedule(Scheduler::Add,incidence); 3983 schedule(Scheduler::Add,incidence);
3980} 3984}
3981 3985
3982void CalendarView::schedule_reply(Incidence *incidence) 3986void CalendarView::schedule_reply(Incidence *incidence)
3983{ 3987{
3984 schedule(Scheduler::Reply,incidence); 3988 schedule(Scheduler::Reply,incidence);
3985} 3989}
3986 3990
3987void CalendarView::schedule_counter(Incidence *incidence) 3991void CalendarView::schedule_counter(Incidence *incidence)
3988{ 3992{
3989 schedule(Scheduler::Counter,incidence); 3993 schedule(Scheduler::Counter,incidence);
3990} 3994}
3991 3995
3992void CalendarView::schedule_declinecounter(Incidence *incidence) 3996void CalendarView::schedule_declinecounter(Incidence *incidence)
3993{ 3997{
3994 schedule(Scheduler::Declinecounter,incidence); 3998 schedule(Scheduler::Declinecounter,incidence);
3995} 3999}
3996 4000
3997void CalendarView::schedule_publish_freebusy(int daysToPublish) 4001void CalendarView::schedule_publish_freebusy(int daysToPublish)
3998{ 4002{
3999 QDateTime start = QDateTime::currentDateTime(); 4003 QDateTime start = QDateTime::currentDateTime();
4000 QDateTime end = start.addDays(daysToPublish); 4004 QDateTime end = start.addDays(daysToPublish);
4001 4005
4002 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 4006 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
4003 freebusy->setOrganizer(KOPrefs::instance()->email()); 4007 freebusy->setOrganizer(KOPrefs::instance()->email());
4004 4008
4005 4009
4006 PublishDialog *publishdlg = new PublishDialog(); 4010 PublishDialog *publishdlg = new PublishDialog();
4007 if ( publishdlg->exec() == QDialog::Accepted ) { 4011 if ( publishdlg->exec() == QDialog::Accepted ) {
4008 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4012 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4009 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 4013 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
4010 delete(freebusy); 4014 delete(freebusy);
4011 } 4015 }
4012 } 4016 }
4013 delete publishdlg; 4017 delete publishdlg;
4014} 4018}
4015 4019
4016void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 4020void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
4017{ 4021{
4018 Event *event = 0; 4022 Event *event = 0;
4019 Todo *todo = 0; 4023 Todo *todo = 0;
4020 4024
4021 if (incidence == 0) { 4025 if (incidence == 0) {
4022 incidence = mViewManager->currentView()->selectedIncidences().first(); 4026 incidence = mViewManager->currentView()->selectedIncidences().first();
4023 if (incidence == 0) { 4027 if (incidence == 0) {
4024 incidence = mTodoList->selectedIncidences().first(); 4028 incidence = mTodoList->selectedIncidences().first();
4025 } 4029 }
4026 } 4030 }
4027 if ( incidence && incidence->typeID() == eventID ) { 4031 if ( incidence && incidence->typeID() == eventID ) {
4028 event = static_cast<Event *>(incidence); 4032 event = static_cast<Event *>(incidence);
4029 } 4033 }
4030 if ( incidence && incidence->typeID() == todoID ) { 4034 if ( incidence && incidence->typeID() == todoID ) {
4031 todo = static_cast<Todo *>(incidence); 4035 todo = static_cast<Todo *>(incidence);
4032 } 4036 }
4033 4037
4034 if (!event && !todo) { 4038 if (!event && !todo) {
4035 KMessageBox::sorry(this,i18n("No event selected.")); 4039 KMessageBox::sorry(this,i18n("No event selected."));
4036 return; 4040 return;
4037 } 4041 }
4038 4042
4039 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4043 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
4040 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4044 KMessageBox::sorry(this,i18n("The event has no attendees."));
4041 return; 4045 return;
4042 } 4046 }
4043 4047
4044 Event *ev = 0; 4048 Event *ev = 0;
4045 if (event) ev = new Event(*event); 4049 if (event) ev = new Event(*event);
4046 Todo *to = 0; 4050 Todo *to = 0;
4047 if (todo) to = new Todo(*todo); 4051 if (todo) to = new Todo(*todo);
4048 4052
4049 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4053 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
4050 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4054 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4051 if (!me) { 4055 if (!me) {
4052 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4056 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4053 return; 4057 return;
4054 } 4058 }
4055 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4059 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4056 StatusDialog *statdlg = new StatusDialog(this); 4060 StatusDialog *statdlg = new StatusDialog(this);
4057 if (!statdlg->exec()==QDialog::Accepted) return; 4061 if (!statdlg->exec()==QDialog::Accepted) return;
4058 me->setStatus( statdlg->status() ); 4062 me->setStatus( statdlg->status() );
4059 delete(statdlg); 4063 delete(statdlg);
4060 } 4064 }
4061 Attendee *menew = new Attendee(*me); 4065 Attendee *menew = new Attendee(*me);
4062 if (ev) { 4066 if (ev) {
4063 ev->clearAttendees(); 4067 ev->clearAttendees();
4064 ev->addAttendee(menew,false); 4068 ev->addAttendee(menew,false);
4065 } else { 4069 } else {
4066 if (to) { 4070 if (to) {
4067 todo->clearAttendees(); 4071 todo->clearAttendees();
4068 todo->addAttendee(menew,false); 4072 todo->addAttendee(menew,false);
4069 } 4073 }
4070 } 4074 }
4071 } 4075 }
4072 4076
4073 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4077 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4074 if (ev) { 4078 if (ev) {
4075 if ( !dlg->addMessage(ev,method) ) delete(ev); 4079 if ( !dlg->addMessage(ev,method) ) delete(ev);
4076 } else { 4080 } else {
4077 if (to) { 4081 if (to) {
4078 if ( !dlg->addMessage(to,method) ) delete(to); 4082 if ( !dlg->addMessage(to,method) ) delete(to);
4079 } 4083 }
4080 } 4084 }
4081} 4085}
4082 4086
4083void CalendarView::openAddressbook() 4087void CalendarView::openAddressbook()
4084{ 4088{
4085 KRun::runCommand("kaddressbook"); 4089 KRun::runCommand("kaddressbook");
4086} 4090}
4087 4091
4088void CalendarView::setModified(bool modified) 4092void CalendarView::setModified(bool modified)
4089{ 4093{
4090 if ( modified ) 4094 if ( modified )
4091 emit signalmodified(); 4095 emit signalmodified();
4092 if (mModified != modified) { 4096 if (mModified != modified) {
4093 mModified = modified; 4097 mModified = modified;
4094 emit modifiedChanged(mModified); 4098 emit modifiedChanged(mModified);
4095 } 4099 }
4096} 4100}
4097 4101
4098bool CalendarView::isReadOnly() 4102bool CalendarView::isReadOnly()
4099{ 4103{
4100 return mReadOnly; 4104 return mReadOnly;
4101} 4105}
4102 4106
4103void CalendarView::setReadOnly(bool readOnly) 4107void CalendarView::setReadOnly(bool readOnly)
4104{ 4108{
4105 if (mReadOnly != readOnly) { 4109 if (mReadOnly != readOnly) {
4106 mReadOnly = readOnly; 4110 mReadOnly = readOnly;
4107 emit readOnlyChanged(mReadOnly); 4111 emit readOnlyChanged(mReadOnly);
4108 } 4112 }
4109} 4113}
4110 4114
4111bool CalendarView::isModified() 4115bool CalendarView::isModified()
4112{ 4116{
4113 return mModified; 4117 return mModified;
4114} 4118}
4115void CalendarView::slotprintSelInc() 4119void CalendarView::slotprintSelInc()
4116{ 4120{
4117 if ( currentSelection() == 0 ) { 4121 if ( currentSelection() == 0 ) {
4118 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4122 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4119 return; 4123 return;
4120 } 4124 }
4121 showIncidence(); 4125 showIncidence();
4122 getEventViewerDialog()->print(); 4126 getEventViewerDialog()->print();
4123 4127
4124} 4128}
4125void CalendarView::printSetup() 4129void CalendarView::printSetup()
4126{ 4130{
4127#ifndef KORG_NOPRINTER 4131#ifndef KORG_NOPRINTER
4128 createPrinter(); 4132 createPrinter();
4129 4133
4130 mCalPrinter->setupPrinter(); 4134 mCalPrinter->setupPrinter();
4131#endif 4135#endif
4132} 4136}
4133 4137
4134void CalendarView::print() 4138void CalendarView::print()
4135{ 4139{
4136#ifndef KORG_NOPRINTER 4140#ifndef KORG_NOPRINTER
4137 createPrinter(); 4141 createPrinter();
4138 4142
4139 DateList tmpDateList = mNavigator->selectedDates(); 4143 DateList tmpDateList = mNavigator->selectedDates();
4140 mCalPrinter->print(CalPrinter::Month, 4144 mCalPrinter->print(CalPrinter::Month,
4141 tmpDateList.first(), tmpDateList.last()); 4145 tmpDateList.first(), tmpDateList.last());
4142#endif 4146#endif
4143} 4147}
4144 4148
4145void CalendarView::printPreview() 4149void CalendarView::printPreview()
4146{ 4150{
4147#ifndef KORG_NOPRINTER 4151#ifndef KORG_NOPRINTER
4148 kdDebug() << "CalendarView::printPreview()" << endl; 4152 kdDebug() << "CalendarView::printPreview()" << endl;
4149 4153
4150 createPrinter(); 4154 createPrinter();
4151 4155
4152 DateList tmpDateList = mNavigator->selectedDates(); 4156 DateList tmpDateList = mNavigator->selectedDates();
4153 4157
4154 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4158 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4155 tmpDateList.last()); 4159 tmpDateList.last());
4156#endif 4160#endif
4157} 4161}
4158 4162
4159void CalendarView::exportICalendar() 4163void CalendarView::exportICalendar()
4160{ 4164{
4161 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4165 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4162 4166
4163 // Force correct extension 4167 // Force correct extension
4164 if (filename.right(4) != ".ics") filename += ".ics"; 4168 if (filename.right(4) != ".ics") filename += ".ics";
4165 4169
4166 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4170 FileStorage storage( mCalendar, filename, new ICalFormat() );
4167 storage.save(); 4171 storage.save();
4168} 4172}
4169 4173
4170bool CalendarView::exportVCalendar( QString filename ) 4174bool CalendarView::exportVCalendar( QString filename )
4171{ 4175{
4172 if (mCalendar->journals().count() > 0) { 4176 if (mCalendar->journals().count() > 0) {
4173 int result = KMessageBox::warningContinueCancel(this, 4177 int result = KMessageBox::warningContinueCancel(this,
4174 i18n("The journal entries can not be\nexported to a vCalendar file."), 4178 i18n("The journal entries can not be\nexported to a vCalendar file."),
4175 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4179 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4176 true); 4180 true);
4177 if (result != KMessageBox::Continue) return false; 4181 if (result != KMessageBox::Continue) return false;
4178 } 4182 }
4179 4183
4180 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4184 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4181 4185
4182 // Force correct extension 4186 // Force correct extension
4183 if (filename.right(4) != ".vcs") filename += ".vcs"; 4187 if (filename.right(4) != ".vcs") filename += ".vcs";
4184 4188
4185 FileStorage storage( mCalendar, filename, new VCalFormat ); 4189 FileStorage storage( mCalendar, filename, new VCalFormat );
4186 return storage.save(); 4190 return storage.save();
4187 4191
4188} 4192}
4189 4193
4190void CalendarView::eventUpdated(Incidence *) 4194void CalendarView::eventUpdated(Incidence *)
4191{ 4195{
4192 setModified(); 4196 setModified();
4193 // Don't call updateView here. The code, which has caused the update of the 4197 // Don't call updateView here. The code, which has caused the update of the
4194 // event is responsible for updating the view. 4198 // event is responsible for updating the view.
4195 // updateView(); 4199 // updateView();
4196} 4200}
4197 4201
4198void CalendarView::adaptNavigationUnits() 4202void CalendarView::adaptNavigationUnits()
4199{ 4203{
4200 if (mViewManager->currentView()->isEventView()) { 4204 if (mViewManager->currentView()->isEventView()) {
4201 int days = mViewManager->currentView()->currentDateCount(); 4205 int days = mViewManager->currentView()->currentDateCount();
4202 if (days == 1) { 4206 if (days == 1) {
4203 emit changeNavStringPrev(i18n("&Previous Day")); 4207 emit changeNavStringPrev(i18n("&Previous Day"));
4204 emit changeNavStringNext(i18n("&Next Day")); 4208 emit changeNavStringNext(i18n("&Next Day"));
4205 } else { 4209 } else {
4206 emit changeNavStringPrev(i18n("&Previous Week")); 4210 emit changeNavStringPrev(i18n("&Previous Week"));
4207 emit changeNavStringNext(i18n("&Next Week")); 4211 emit changeNavStringNext(i18n("&Next Week"));
4208 } 4212 }
4209 } 4213 }
4210} 4214}
4211 4215
4212void CalendarView::processMainViewSelection( Incidence *incidence ) 4216void CalendarView::processMainViewSelection( Incidence *incidence )
4213{ 4217{
4214 if ( incidence ) mTodoList->clearSelection(); 4218 if ( incidence ) mTodoList->clearSelection();
4215 processIncidenceSelection( incidence ); 4219 processIncidenceSelection( incidence );
4216} 4220}
4217 4221
4218void CalendarView::processTodoListSelection( Incidence *incidence ) 4222void CalendarView::processTodoListSelection( Incidence *incidence )
4219{ 4223{
4220 if ( incidence && mViewManager->currentView() ) { 4224 if ( incidence && mViewManager->currentView() ) {
4221 mViewManager->currentView()->clearSelection(); 4225 mViewManager->currentView()->clearSelection();
4222 } 4226 }
4223 processIncidenceSelection( incidence ); 4227 processIncidenceSelection( incidence );
4224} 4228}
4225 4229
4226void CalendarView::processIncidenceSelection( Incidence *incidence ) 4230void CalendarView::processIncidenceSelection( Incidence *incidence )
4227{ 4231{
4228 emit incidenceSelected( incidence ); 4232 emit incidenceSelected( incidence );
4229 if ( incidence == mSelectedIncidence ) return; 4233 if ( incidence == mSelectedIncidence ) return;
4230 mSelectedIncidence = incidence; 4234 mSelectedIncidence = incidence;
4231 4235
4232 if ( incidence && incidence->typeID() == eventID ) { 4236 if ( incidence && incidence->typeID() == eventID ) {
4233 Event *event = static_cast<Event *>( incidence ); 4237 Event *event = static_cast<Event *>( incidence );
4234 if ( event->organizer() == KOPrefs::instance()->email() ) { 4238 if ( event->organizer() == KOPrefs::instance()->email() ) {
4235 emit organizerEventsSelected( true ); 4239 emit organizerEventsSelected( true );
4236 } else { 4240 } else {
4237 emit organizerEventsSelected(false); 4241 emit organizerEventsSelected(false);
4238 } 4242 }
4239 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4243 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4240 KOPrefs::instance()->email() ) ) { 4244 KOPrefs::instance()->email() ) ) {
4241 emit groupEventsSelected( true ); 4245 emit groupEventsSelected( true );
4242 } else { 4246 } else {
4243 emit groupEventsSelected(false); 4247 emit groupEventsSelected(false);
4244 } 4248 }
4245 return; 4249 return;
4246 } else { 4250 } else {
4247 if ( incidence && incidence->typeID() == todoID ) { 4251 if ( incidence && incidence->typeID() == todoID ) {
4248 emit todoSelected( true ); 4252 emit todoSelected( true );
4249 Todo *event = static_cast<Todo *>( incidence ); 4253 Todo *event = static_cast<Todo *>( incidence );
4250 if ( event->organizer() == KOPrefs::instance()->email() ) { 4254 if ( event->organizer() == KOPrefs::instance()->email() ) {
4251 emit organizerEventsSelected( true ); 4255 emit organizerEventsSelected( true );
4252 } else { 4256 } else {
4253 emit organizerEventsSelected(false); 4257 emit organizerEventsSelected(false);
4254 } 4258 }
4255 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4259 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4256 KOPrefs::instance()->email() ) ) { 4260 KOPrefs::instance()->email() ) ) {
4257 emit groupEventsSelected( true ); 4261 emit groupEventsSelected( true );
4258 } else { 4262 } else {
4259 emit groupEventsSelected(false); 4263 emit groupEventsSelected(false);
4260 } 4264 }
4261 return; 4265 return;
4262 } else { 4266 } else {
4263 emit todoSelected( false ); 4267 emit todoSelected( false );
4264 emit organizerEventsSelected(false); 4268 emit organizerEventsSelected(false);
4265 emit groupEventsSelected(false); 4269 emit groupEventsSelected(false);
4266 } 4270 }
4267 return; 4271 return;
4268 } 4272 }
4269 4273
4270 /* if ( incidence && incidence->typeID() == todoID ) { 4274 /* if ( incidence && incidence->typeID() == todoID ) {
4271 emit todoSelected( true ); 4275 emit todoSelected( true );
4272 } else { 4276 } else {
4273 emit todoSelected( false ); 4277 emit todoSelected( false );
4274 }*/ 4278 }*/
4275} 4279}
4276 4280
4277 4281
4278void CalendarView::checkClipboard() 4282void CalendarView::checkClipboard()
4279{ 4283{
4280#ifndef KORG_NODND 4284#ifndef KORG_NODND
4281 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4285 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4282 emit pasteEnabled(true); 4286 emit pasteEnabled(true);
4283 } else { 4287 } else {
4284 emit pasteEnabled(false); 4288 emit pasteEnabled(false);
4285 } 4289 }
4286#endif 4290#endif
4287} 4291}
4288 4292
4289void CalendarView::showDates(const DateList &selectedDates) 4293void CalendarView::showDates(const DateList &selectedDates)
4290{ 4294{
4291 // kdDebug() << "CalendarView::selectDates()" << endl; 4295 // kdDebug() << "CalendarView::selectDates()" << endl;
4292 4296
4293 4297
4294 if ( !mBlockShowDates ) { 4298 if ( !mBlockShowDates ) {
4295 if ( mViewManager->currentView() ) { 4299 if ( mViewManager->currentView() ) {
4296 updateView( selectedDates.first(), selectedDates.last() ); 4300 updateView( selectedDates.first(), selectedDates.last() );
4297 } else { 4301 } else {
4298 mViewManager->showAgendaView(); 4302 mViewManager->showAgendaView();
4299 } 4303 }
4300 } 4304 }
4301 4305
4302 QDate date = selectedDates.first(); 4306 QDate date = selectedDates.first();
4303 if ( ! date.isValid() ) { 4307 if ( ! date.isValid() ) {
4304 topLevelWidget()->setCaption(""); 4308 topLevelWidget()->setCaption("");
4305 return; 4309 return;
4306 } 4310 }
4307 4311
4308 QString selDates; 4312 QString selDates;
4309 selDates = KGlobal::locale()->formatDate( date, true); 4313 selDates = KGlobal::locale()->formatDate( date, true);
4310 if (selectedDates.first() < selectedDates.last() ) 4314 if (selectedDates.first() < selectedDates.last() )
4311 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4315 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4312 else { 4316 else {
4313 QString addString; 4317 QString addString;
4314 if ( date == QDateTime::currentDateTime().date() ) 4318 if ( date == QDateTime::currentDateTime().date() )
4315 addString = i18n("Today"); 4319 addString = i18n("Today");
4316 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4320 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4317 addString = i18n("Tomorrow"); 4321 addString = i18n("Tomorrow");
4318 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4322 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4319 addString = i18n("Yesterday"); 4323 addString = i18n("Yesterday");
4320 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4324 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4321 addString = i18n("Day before yesterday"); 4325 addString = i18n("Day before yesterday");
4322 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4326 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4323 addString = i18n("Day after tomorrow"); 4327 addString = i18n("Day after tomorrow");
4324 if ( !addString.isEmpty() ) { 4328 if ( !addString.isEmpty() ) {
4325 topLevelWidget()->setCaption( addString+", " + selDates ); 4329 topLevelWidget()->setCaption( addString+", " + selDates );
4326 return; 4330 return;
4327 } 4331 }
4328 } 4332 }
4329 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4333 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4330 4334
4331} 4335}
4332 4336
4333QPtrList<CalFilter> CalendarView::filters() 4337QPtrList<CalFilter> CalendarView::filters()
4334{ 4338{
4335 return mFilters; 4339 return mFilters;
4336 4340
4337} 4341}
4338void CalendarView::editFilters() 4342void CalendarView::editFilters()
4339{ 4343{
4340 // kdDebug() << "CalendarView::editFilters()" << endl; 4344 // kdDebug() << "CalendarView::editFilters()" << endl;
4341 4345
4342 CalFilter *filter = mFilters.first(); 4346 CalFilter *filter = mFilters.first();
4343 while(filter) { 4347 while(filter) {
4344 filter = mFilters.next(); 4348 filter = mFilters.next();
4345 } 4349 }
4346 4350
4347 mDialogManager->showFilterEditDialog(&mFilters); 4351 mDialogManager->showFilterEditDialog(&mFilters);
4348 updateFilter(); 4352 updateFilter();
4349} 4353}
4350void CalendarView::toggleFilter() 4354void CalendarView::toggleFilter()
4351{ 4355{
4352 if ( mLeftFrame->isHidden() ) { 4356 if ( mLeftFrame->isHidden() ) {
4353 toggleExpand(); 4357 toggleExpand();
4354 showFilter( true ); 4358 showFilter( true );
4355 } else 4359 } else
4356 showFilter(! mCalEditView->isVisible()); 4360 showFilter(! mCalEditView->isVisible());
4357} 4361}
4358 4362
4359KOFilterView *CalendarView::filterView() 4363KOFilterView *CalendarView::filterView()
4360{ 4364{
4361 return mFilterView; 4365 return mFilterView;
4362} 4366}
4363void CalendarView::selectFilter( int fil ) 4367void CalendarView::selectFilter( int fil )
4364{ 4368{
4365 mFilterView->setSelectedFilter( fil ); 4369 mFilterView->setSelectedFilter( fil );
4366 updateUnmanagedViews(); 4370 updateUnmanagedViews();
4367} 4371}
4368void CalendarView::showFilter(bool visible) 4372void CalendarView::showFilter(bool visible)
4369{ 4373{
4370#if 1 4374#if 1
4371 if (visible) { 4375 if (visible) {
4372 mCalEditView->readConfig(); 4376 mCalEditView->readConfig();
4373 mCalEditView->show(); 4377 mCalEditView->show();
4374 QValueList<int> sizes; 4378 QValueList<int> sizes;
4375 sizes = mLeftFrame->sizes(); 4379 sizes = mLeftFrame->sizes();
4376 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4380 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4377 sizes.clear(); 4381 sizes.clear();
4378 sizes << 100; 4382 sizes << 100;
4379 sizes << 0; 4383 sizes << 0;
4380 sizes << 0; 4384 sizes << 0;
4381 sizes << 100; 4385 sizes << 100;
4382 mLeftFrame->setSizes(sizes); 4386 mLeftFrame->setSizes(sizes);
4383 } 4387 }
4384#if 0 4388#if 0
4385 sizes = mLeftFrame->sizes(); 4389 sizes = mLeftFrame->sizes();
4386 int ccc = 0; 4390 int ccc = 0;
4387 while ( ccc < sizes.count()) { 4391 while ( ccc < sizes.count()) {
4388 qDebug("size %d %d ", ccc, sizes[ccc]); 4392 qDebug("size %d %d ", ccc, sizes[ccc]);
4389 ++ccc; 4393 ++ccc;
4390 } 4394 }
4391#endif 4395#endif
4392 4396
4393 } 4397 }
4394 else { 4398 else {
4395 mCalEditView->hide(); 4399 mCalEditView->hide();
4396 } 4400 }
4397#else 4401#else
4398 if (visible) mFilterView->show(); 4402 if (visible) mFilterView->show();
4399 else mFilterView->hide(); 4403 else mFilterView->hide();
4400#endif 4404#endif
4401} 4405}
4402void CalendarView::toggleFilerEnabled( ) 4406void CalendarView::toggleFilerEnabled( )
4403{ 4407{
4404 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4408 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4405 if ( !mFilterView->filtersEnabled() ) 4409 if ( !mFilterView->filtersEnabled() )
4406 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4410 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4407 updateUnmanagedViews(); 4411 updateUnmanagedViews();
4408 4412
4409} 4413}
4410void CalendarView::updateFilter() 4414void CalendarView::updateFilter()
4411{ 4415{
4412 CalFilter *filter = mFilterView->selectedFilter(); 4416 CalFilter *filter = mFilterView->selectedFilter();
4413 if (filter) { 4417 if (filter) {
4414 QString mess; 4418 QString mess;
4415 if (mFilterView->filtersEnabled()) { 4419 if (mFilterView->filtersEnabled()) {
4416 mess = i18n("Filter selected: ")+filter->name(); 4420 mess = i18n("Filter selected: ")+filter->name();
4417 filter->setEnabled(true); 4421 filter->setEnabled(true);
4418 } 4422 }
4419 else filter->setEnabled(false); 4423 else filter->setEnabled(false);
4420 mCalendar->setFilter(filter); 4424 mCalendar->setFilter(filter);
4421 updateView(); 4425 updateView();
4422 if ( !mess.isEmpty() ) 4426 if ( !mess.isEmpty() )
4423 topLevelWidget()->setCaption( mess ); 4427 topLevelWidget()->setCaption( mess );
4424 4428
4425 } 4429 }
4426 emit filtersUpdated(); 4430 emit filtersUpdated();
4427} 4431}
4428 4432
4429void CalendarView::filterEdited() 4433void CalendarView::filterEdited()
4430{ 4434{
4431 mFilterView->updateFilters(); 4435 mFilterView->updateFilters();
4432 updateFilter(); 4436 updateFilter();
4433 writeSettings(); 4437 writeSettings();
4434} 4438}
4435 4439
4436 4440
4437void CalendarView::takeOverEvent() 4441void CalendarView::takeOverEvent()
4438{ 4442{
4439 Incidence *incidence = currentSelection(); 4443 Incidence *incidence = currentSelection();
4440 4444
4441 if (!incidence) return; 4445 if (!incidence) return;
4442 4446
4443 incidence->setOrganizer(KOPrefs::instance()->email()); 4447 incidence->setOrganizer(KOPrefs::instance()->email());
4444 incidence->recreate(); 4448 incidence->recreate();
4445 incidence->setReadOnly(false); 4449 incidence->setReadOnly(false);
4446 4450
4447 updateView(); 4451 updateView();
4448} 4452}
4449 4453
4450void CalendarView::takeOverCalendar() 4454void CalendarView::takeOverCalendar()
4451{ 4455{
4452 // TODO: Create Calendar::allIncidences() function and use it here 4456 // TODO: Create Calendar::allIncidences() function and use it here
4453 4457
4454 clearAllViews(); 4458 clearAllViews();
4455 QPtrList<Event> events = mCalendar->events(); 4459 QPtrList<Event> events = mCalendar->events();
4456 for(uint i=0; i<events.count(); ++i) { 4460 for(uint i=0; i<events.count(); ++i) {
4457 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 4461 events.at(i)->setOrganizer(KOPrefs::instance()->email());
4458 events.at(i)->recreate(); 4462 events.at(i)->recreate();
4459 events.at(i)->setReadOnly(false); 4463 events.at(i)->setReadOnly(false);
4460 } 4464 }
4461 4465
4462 QPtrList<Todo> todos = mCalendar->todos(); 4466 QPtrList<Todo> todos = mCalendar->todos();
4463 for(uint i=0; i<todos.count(); ++i) { 4467 for(uint i=0; i<todos.count(); ++i) {
4464 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 4468 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
4465 todos.at(i)->recreate(); 4469 todos.at(i)->recreate();
4466 todos.at(i)->setReadOnly(false); 4470 todos.at(i)->setReadOnly(false);
4467 } 4471 }
4468 4472
4469 QPtrList<Journal> journals = mCalendar->journals(); 4473 QPtrList<Journal> journals = mCalendar->journals();
4470 for(uint i=0; i<journals.count(); ++i) { 4474 for(uint i=0; i<journals.count(); ++i) {
4471 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 4475 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
4472 journals.at(i)->recreate(); 4476 journals.at(i)->recreate();
4473 journals.at(i)->setReadOnly(false); 4477 journals.at(i)->setReadOnly(false);
4474 } 4478 }
4475 4479
4476 updateView(); 4480 updateView();
4477} 4481}
4478 4482
4479void CalendarView::showIntro() 4483void CalendarView::showIntro()
4480{ 4484{
4481 kdDebug() << "To be implemented." << endl; 4485 kdDebug() << "To be implemented." << endl;
4482} 4486}
4483 4487
4484QWidgetStack *CalendarView::viewStack() 4488QWidgetStack *CalendarView::viewStack()
4485{ 4489{
4486 return mRightFrame; 4490 return mRightFrame;
4487} 4491}
4488 4492
4489QWidget *CalendarView::leftFrame() 4493QWidget *CalendarView::leftFrame()
4490{ 4494{
4491 return ( QWidget *)mLeftFrame; 4495 return ( QWidget *)mLeftFrame;
4492} 4496}
4493 4497
4494DateNavigator *CalendarView::dateNavigator() 4498DateNavigator *CalendarView::dateNavigator()
4495{ 4499{
4496 return mNavigator; 4500 return mNavigator;
4497} 4501}
4498 4502
4499KDateNavigator* CalendarView::dateNavigatorWidget() 4503KDateNavigator* CalendarView::dateNavigatorWidget()
4500{ 4504{
4501 return mDateNavigator->navigatorView(); 4505 return mDateNavigator->navigatorView();
4502} 4506}
4503void CalendarView::toggleDateNavigatorWidget() 4507void CalendarView::toggleDateNavigatorWidget()
4504{ 4508{
4505 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4509 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4506 4510
4507 if (!KOPrefs::instance()->mShowDateNavigator ) 4511 if (!KOPrefs::instance()->mShowDateNavigator )
4508 mDateNavigator->hide(); 4512 mDateNavigator->hide();
4509 else 4513 else
4510 mDateNavigator->show(); 4514 mDateNavigator->show();
4511} 4515}
4512void CalendarView::addView(KOrg::BaseView *view) 4516void CalendarView::addView(KOrg::BaseView *view)
4513{ 4517{
4514 mViewManager->addView(view); 4518 mViewManager->addView(view);
4515} 4519}
4516 4520
4517void CalendarView::showView(KOrg::BaseView *view) 4521void CalendarView::showView(KOrg::BaseView *view)
4518{ 4522{
4519 mViewManager->showView(view, mLeftFrame->isVisible()); 4523 mViewManager->showView(view, mLeftFrame->isVisible());
4520} 4524}
4521 4525
4522Incidence *CalendarView::currentSelection() 4526Incidence *CalendarView::currentSelection()
4523{ 4527{
4524 return mViewManager->currentSelection(); 4528 return mViewManager->currentSelection();
4525} 4529}
4526void CalendarView::toggleAllDaySize() 4530void CalendarView::toggleAllDaySize()
4527{ 4531{
4528 /* 4532 /*
4529 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4533 if ( KOPrefs::instance()->mAllDaySize > 47 )
4530 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4534 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4531 else 4535 else
4532 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4536 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4533 */ 4537 */
4534 viewManager()->agendaView()->toggleAllDay(); 4538 viewManager()->agendaView()->toggleAllDay();
4535} 4539}
4536void CalendarView::toggleExpand() 4540void CalendarView::toggleExpand()
4537{ 4541{
4538 // if ( mLeftFrame->isHidden() ) { 4542 // if ( mLeftFrame->isHidden() ) {
4539 // mLeftFrame->show(); 4543 // mLeftFrame->show();
4540 // emit calendarViewExpanded( false ); 4544 // emit calendarViewExpanded( false );
4541 // } else { 4545 // } else {
4542 // mLeftFrame->hide(); 4546 // mLeftFrame->hide();
4543 // emit calendarViewExpanded( true ); 4547 // emit calendarViewExpanded( true );
4544 // } 4548 // }
4545 //qDebug(" CalendarView::toggleExpand()"); 4549 //qDebug(" CalendarView::toggleExpand()");
4546 globalFlagBlockAgenda = 1; 4550 globalFlagBlockAgenda = 1;
4547 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4551 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4548 globalFlagBlockAgenda = 5; 4552 globalFlagBlockAgenda = 5;
4549 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4553 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4550 //mViewManager->showView( 0, true ); 4554 //mViewManager->showView( 0, true );
4551} 4555}
4552 4556
4553void CalendarView::calendarModified( bool modified, Calendar * ) 4557void CalendarView::calendarModified( bool modified, Calendar * )
4554{ 4558{
4555 setModified( modified ); 4559 setModified( modified );
4556} 4560}
4557 4561
4558Todo *CalendarView::selectedTodo() 4562Todo *CalendarView::selectedTodo()
4559{ 4563{
4560 Incidence *incidence = currentSelection(); 4564 Incidence *incidence = currentSelection();
4561 if ( incidence && incidence->typeID() == todoID ) { 4565 if ( incidence && incidence->typeID() == todoID ) {
4562 return static_cast<Todo *>( incidence ); 4566 return static_cast<Todo *>( incidence );
4563 } 4567 }
4564 4568
4565 incidence = mTodoList->selectedIncidences().first(); 4569 incidence = mTodoList->selectedIncidences().first();
4566 if ( incidence && incidence->typeID() == todoID ) { 4570 if ( incidence && incidence->typeID() == todoID ) {
4567 return static_cast<Todo *>( incidence ); 4571 return static_cast<Todo *>( incidence );
4568 } 4572 }
4569 4573
4570 return 0; 4574 return 0;
4571} 4575}
4572 4576
4573void CalendarView::showIncidence() 4577void CalendarView::showIncidence()
4574{ 4578{
4575 mViewerCallerIsSearchDialog = false; 4579 mViewerCallerIsSearchDialog = false;
4576 Incidence *incidence = currentSelection(); 4580 Incidence *incidence = currentSelection();
4577 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4581 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4578 if ( incidence ) { 4582 if ( incidence ) {
4579 ShowIncidenceVisitor v; 4583 ShowIncidenceVisitor v;
4580 v.act( incidence, this ); 4584 v.act( incidence, this );
4581 } 4585 }
4582} 4586}
4583void CalendarView::editIncidenceDescription() 4587void CalendarView::editIncidenceDescription()
4584{ 4588{
4585 mFlagEditDescription = true; 4589 mFlagEditDescription = true;
4586 editIncidence(); 4590 editIncidence();
4587 mFlagEditDescription = false; 4591 mFlagEditDescription = false;
4588} 4592}
4589void CalendarView::editIncidence() 4593void CalendarView::editIncidence()
4590{ 4594{
4591 // qDebug("editIncidence() "); 4595 // qDebug("editIncidence() ");
4592 Incidence *incidence = currentSelection(); 4596 Incidence *incidence = currentSelection();
4593 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4597 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4594 if ( incidence ) { 4598 if ( incidence ) {
4595 EditIncidenceVisitor v; 4599 EditIncidenceVisitor v;
4596 v.act( incidence, this ); 4600 v.act( incidence, this );
4597 } 4601 }
4598} 4602}
4599 4603
4600void CalendarView::deleteIncidence() 4604void CalendarView::deleteIncidence()
4601{ 4605{
4602 Incidence *incidence = currentSelection(); 4606 Incidence *incidence = currentSelection();
4603 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4607 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4604 if ( incidence ) { 4608 if ( incidence ) {
4605 deleteIncidence(incidence); 4609 deleteIncidence(incidence);
4606 } 4610 }
4607} 4611}
4608void CalendarView::showIncidence(QString uid) 4612void CalendarView::showIncidence(QString uid)
4609{ 4613{
4610 Incidence *inc = mCalendar->incidence( uid ); 4614 Incidence *inc = mCalendar->incidence( uid );
4611 if ( inc ) 4615 if ( inc )
4612 showIncidence( inc ); 4616 showIncidence( inc );
4613} 4617}
4614void CalendarView::showIncidence(Incidence *incidence) 4618void CalendarView::showIncidence(Incidence *incidence)
4615{ 4619{
4616 mViewerCallerIsSearchDialog = false; 4620 mViewerCallerIsSearchDialog = false;
4617 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4621 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4618 if ( sender() && mDialogManager->getSearchDialog() ) { 4622 if ( sender() && mDialogManager->getSearchDialog() ) {
4619 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4623 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4620 mViewerCallerIsSearchDialog = true; 4624 mViewerCallerIsSearchDialog = true;
4621 } 4625 }
4622 } 4626 }
4623 if ( incidence ) { 4627 if ( incidence ) {
4624 ShowIncidenceVisitor v; 4628 ShowIncidenceVisitor v;
4625 v.act( incidence, this ); 4629 v.act( incidence, this );
4626 } 4630 }
4627} 4631}
4628 4632
4629void CalendarView::editIncidence(Incidence *incidence) 4633void CalendarView::editIncidence(Incidence *incidence)
4630{ 4634{
4631 if ( incidence ) { 4635 if ( incidence ) {
4632 4636
4633 EditIncidenceVisitor v; 4637 EditIncidenceVisitor v;
4634 v.act( incidence, this ); 4638 v.act( incidence, this );
4635 4639
4636 } 4640 }
4637} 4641}
4638 4642
4639void CalendarView::deleteIncidence(Incidence *incidence) 4643void CalendarView::deleteIncidence(Incidence *incidence)
4640{ 4644{
4641 //qDebug(" CalendarView::deleteIncidence "); 4645 //qDebug(" CalendarView::deleteIncidence ");
4642 if ( incidence == 0 ) { 4646 if ( incidence == 0 ) {
4643 updateView(); 4647 updateView();
4644 emit updateSearchDialog(); 4648 emit updateSearchDialog();
4645 return; 4649 return;
4646 } 4650 }
4647 if ( incidence ) { 4651 if ( incidence ) {
4648 DeleteIncidenceVisitor v; 4652 DeleteIncidenceVisitor v;
4649 v.act( incidence, this ); 4653 v.act( incidence, this );
4650 } 4654 }
4651} 4655}
4652 4656
4653 4657
4654void CalendarView::lookForOutgoingMessages() 4658void CalendarView::lookForOutgoingMessages()
4655{ 4659{
4656 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4660 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4657 ogd->loadMessages(); 4661 ogd->loadMessages();
4658} 4662}
4659 4663
4660void CalendarView::lookForIncomingMessages() 4664void CalendarView::lookForIncomingMessages()
4661{ 4665{
4662 IncomingDialog *icd = mDialogManager->incomingDialog(); 4666 IncomingDialog *icd = mDialogManager->incomingDialog();
4663 icd->retrieve(); 4667 icd->retrieve();
4664} 4668}
4665 4669
4666bool CalendarView::removeCompletedSubTodos( Todo* t ) 4670bool CalendarView::removeCompletedSubTodos( Todo* t )
4667{ 4671{
4668 bool deleteTodo = true; 4672 bool deleteTodo = true;
4669 QPtrList<Incidence> subTodos; 4673 QPtrList<Incidence> subTodos;
4670 Incidence *aTodo; 4674 Incidence *aTodo;
4671 subTodos = t->relations(); 4675 subTodos = t->relations();
4672 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4676 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4673 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4677 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4674 deleteTodo = false; 4678 deleteTodo = false;
4675 } 4679 }
4676 if ( deleteTodo ) { 4680 if ( deleteTodo ) {
4677 if ( t->isCompleted() && !t->doesRecur()) { 4681 if ( t->isCompleted() && !t->doesRecur()) {
4678 checkExternalId( t ); 4682 checkExternalId( t );
4679 mCalendar->deleteTodo( t ); 4683 mCalendar->deleteTodo( t );
4680 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4684 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4681 } 4685 }
4682 else 4686 else
4683 deleteTodo = false; 4687 deleteTodo = false;
4684 } 4688 }
4685 return deleteTodo; 4689 return deleteTodo;
4686 4690
4687} 4691}
4688void CalendarView::purgeCompleted() 4692void CalendarView::purgeCompleted()
4689{ 4693{
4690 int result = KMessageBox::warningContinueCancel(this, 4694 int result = KMessageBox::warningContinueCancel(this,
4691 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4695 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4692 4696
4693 if (result == KMessageBox::Continue) { 4697 if (result == KMessageBox::Continue) {
4694 4698
4695 QPtrList<Todo> todoCal; 4699 QPtrList<Todo> todoCal;
4696 QPtrList<Todo> rootTodos; 4700 QPtrList<Todo> rootTodos;
4697 //QPtrList<Incidence> rel; 4701 //QPtrList<Incidence> rel;
4698 Todo *aTodo; 4702 Todo *aTodo;
4699 todoCal = calendar()->todos(); 4703 todoCal = calendar()->todos();
4700 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4704 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4701 if ( !aTodo->relatedTo() ) 4705 if ( !aTodo->relatedTo() )
4702 rootTodos.append( aTodo ); 4706 rootTodos.append( aTodo );
4703 } 4707 }
4704 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4708 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4705 removeCompletedSubTodos( aTodo ); 4709 removeCompletedSubTodos( aTodo );
4706 } 4710 }
4707 4711
4708 updateView(); 4712 updateView();
4709 } 4713 }
4710} 4714}
4711 4715
4712void CalendarView::slotCalendarChanged() 4716void CalendarView::slotCalendarChanged()
4713{ 4717{
4714 ; 4718 ;
4715} 4719}
4716 4720
4717void CalendarView::keyPressEvent ( QKeyEvent *e) 4721void CalendarView::keyPressEvent ( QKeyEvent *e)
4718{ 4722{
4719 //qDebug("CalendarView::keyPressEvent "); 4723 //qDebug("CalendarView::keyPressEvent ");
4720 e->ignore(); 4724 e->ignore();
4721} 4725}
4722 4726
4723 4727
4724bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4728bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4725{ 4729{
4726 4730
4727 if ( manager != mSyncManager) 4731 if ( manager != mSyncManager)
4728 qDebug("KO: Internal error-1. SyncManager mismatch "); 4732 qDebug("KO: Internal error-1. SyncManager mismatch ");
4729 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4733 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4730 qDebug("KO: SyncKDE request detected!"); 4734 qDebug("KO: SyncKDE request detected!");
4731 } 4735 }
4732 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4736 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4733 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4737 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4734 return syncCalendar( filename, mode ); 4738 return syncCalendar( filename, mode );
4735} 4739}
4736bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4740bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4737{ 4741{
4738 //mSyncManager = manager; 4742 //mSyncManager = manager;
4739 if ( manager != mSyncManager) 4743 if ( manager != mSyncManager)
4740 qDebug("KO: Internal error-2. SyncManager mismatch "); 4744 qDebug("KO: Internal error-2. SyncManager mismatch ");
4741 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4745 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4742 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4746 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4743 if ( resource == "sharp" ) 4747 if ( resource == "sharp" )
4744 syncExternal( 0 ); 4748 syncExternal( 0 );
4745 if ( resource == "phone" ) 4749 if ( resource == "phone" )
4746 syncExternal( 1 ); 4750 syncExternal( 1 );
4747 // pending setmodified 4751 // pending setmodified
4748 return true; 4752 return true;
4749} 4753}
4750void CalendarView::setSyncManager(KSyncManager* manager) 4754void CalendarView::setSyncManager(KSyncManager* manager)
4751{ 4755{
4752 mSyncManager = manager; 4756 mSyncManager = manager;
4753} 4757}
4754 4758
4755void CalendarView::removeSyncInfo( QString syncProfile) 4759void CalendarView::removeSyncInfo( QString syncProfile)
4756{ 4760{
4757 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4761 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4758 mCalendar->removeSyncInfo( syncProfile ); 4762 mCalendar->removeSyncInfo( syncProfile );
4759 4763
4760} 4764}
4761 4765
4762void CalendarView::undo_delete() 4766void CalendarView::undo_delete()
4763{ 4767{
4764 //qDebug("undo_delete() "); 4768 //qDebug("undo_delete() ");
4765 Incidence* undo = mCalendar->undoIncidence(); 4769 Incidence* undo = mCalendar->undoIncidence();
4766 if ( !undo ) { 4770 if ( !undo ) {
4767 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4771 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4768 i18n("KO/Pi")); 4772 i18n("KO/Pi"));
4769 return; 4773 return;
4770 } 4774 }
4771 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) + 4775 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) +
4772 i18n("\nAre you sure you want\nto restore this?"), 4776 i18n("\nAre you sure you want\nto restore this?"),
4773 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4777 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4774 mCalendar->undoDeleteIncidence(); 4778 mCalendar->undoDeleteIncidence();
4775 updateView(); 4779 updateView();
4776 } 4780 }
4777} 4781}
4778 4782
4779void CalendarView::slotViewerClosed() 4783void CalendarView::slotViewerClosed()
4780{ 4784{
4781 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4785 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4782} 4786}
4783 4787
4784void CalendarView::resetFocus() 4788void CalendarView::resetFocus()
4785{ 4789{
4786 if ( mViewerCallerIsSearchDialog ) { 4790 if ( mViewerCallerIsSearchDialog ) {
4787 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4791 if ( mDialogManager->getSearchDialog()->isVisible() ){
4788 mDialogManager->getSearchDialog()->raise(); 4792 mDialogManager->getSearchDialog()->raise();
4789 mDialogManager->getSearchDialog()->setActiveWindow(); 4793 mDialogManager->getSearchDialog()->setActiveWindow();
4790 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4794 mDialogManager->getSearchDialog()->listview()->resetFocus();
4791 } else 4795 } else
4792 mViewerCallerIsSearchDialog = false; 4796 mViewerCallerIsSearchDialog = false;
4793 } 4797 }
4794 if ( !mViewerCallerIsSearchDialog ) { 4798 if ( !mViewerCallerIsSearchDialog ) {
4795 //mViewManager->currentView()->setFocus(); 4799 //mViewManager->currentView()->setFocus();
4796 //qDebug("sssssssssssssssset focus "); 4800 //qDebug("sssssssssssssssset focus ");
4797 topLevelWidget()->raise(); 4801 topLevelWidget()->raise();
4798 setActiveWindow(); 4802 setActiveWindow();
4799 //setFocus(); 4803 //setFocus();
4800 } 4804 }
4801 mViewerCallerIsSearchDialog = false; 4805 mViewerCallerIsSearchDialog = false;
4802} 4806}
4803 4807
4804void CalendarView::showNextAlarms() 4808void CalendarView::showNextAlarms()
4805{ 4809{
4806 QString message; 4810 QString message;
4807 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4811 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4808 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4812 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4809 QString sum = mCalendar->nextSummary(); 4813 QString sum = mCalendar->nextSummary();
4810 QDateTime nextA = mNextAlarmDateTime; 4814 QDateTime nextA = mNextAlarmDateTime;
4811 QDateTime cur = QDateTime::currentDateTime(); 4815 QDateTime cur = QDateTime::currentDateTime();
4812 int secs = cur.secsTo( nextA ); 4816 int secs = cur.secsTo( nextA );
4813 int min = secs /60; 4817 int min = secs /60;
4814 int hours = min /60; 4818 int hours = min /60;
4815 min = min % 60; 4819 min = min % 60;
4816 int days = hours /24; 4820 int days = hours /24;
4817 hours = hours % 24; 4821 hours = hours % 24;
4818 4822
4819 //message = i18n("The next alarm is in:\n"); 4823 //message = i18n("The next alarm is in:\n");
4820 if ( days > 1 ) 4824 if ( days > 1 )
4821 message += i18n("%1 days\n").arg( days ); 4825 message += i18n("%1 days\n").arg( days );
4822 else if ( days == 1 ) 4826 else if ( days == 1 )
4823 message += i18n("1 day\n"); 4827 message += i18n("1 day\n");
4824 if ( hours > 1 ) 4828 if ( hours > 1 )
4825 message += i18n("%1 hours\n").arg( hours ); 4829 message += i18n("%1 hours\n").arg( hours );
4826 else if ( hours == 1 ) 4830 else if ( hours == 1 )
4827 message += i18n("1 hour\n"); 4831 message += i18n("1 hour\n");
4828 if ( min > 1 ) 4832 if ( min > 1 )
4829 message += i18n("%1 minutes\n").arg( min ); 4833 message += i18n("%1 minutes\n").arg( min );
4830 else if ( min == 1 ) 4834 else if ( min == 1 )
4831 message += i18n("1 minute\n"); 4835 message += i18n("1 minute\n");
4832 if ( message.isEmpty() ) 4836 if ( message.isEmpty() )
4833 message = i18n("The next alarm is in\nless than one minute!"); 4837 message = i18n("The next alarm is in\nless than one minute!");
4834 else 4838 else
4835 message = i18n("The next alarm is in:\n") + message; 4839 message = i18n("The next alarm is in:\n") + message;
4836 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4840 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4837 } else { 4841 } else {
4838 message = i18n("There is no next alarm."); 4842 message = i18n("There is no next alarm.");
4839 4843
4840 } 4844 }
4841#ifdef DESKTOP_VERSION 4845#ifdef DESKTOP_VERSION
4842 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4846 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4843 message += i18n("\nThe internal alarm notification is disabled!\n"); 4847 message += i18n("\nThe internal alarm notification is disabled!\n");
4844 message += i18n("Enable it in the settings menu, TAB alarm."); 4848 message += i18n("Enable it in the settings menu, TAB alarm.");
4845 } 4849 }
4846 4850
4847#endif 4851#endif
4848 KMessageBox::information( this, message); 4852 KMessageBox::information( this, message);
4849} 4853}