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