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