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