summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index d51187a..316826a 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,2816 +1,2846 @@
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( "Project1"); 911 root1->setSummary( "Project1");
912 root1->setPriority( 1 ); 912 root1->setPriority( 1 );
913 root1->setCategories( QString( "Cat_Pro1") ); 913 root1->setCategories( QString( "Cat_Pro1") );
914 root1->setDescription( "This is a test description of a root Project" ); 914 root1->setDescription( "This is a test description of a root Project" );
915 root1->setPercentComplete( 20 ); 915 root1->setPercentComplete( 20 );
916 updateView(); 916 updateView();
917 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); 917 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
918 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); 918 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
919 919
920 nt = new Todo; 920 nt = new Todo;
921 mCalendar->addTodo( nt ); 921 mCalendar->addTodo( nt );
922 nt->setSummary( "Planning Project1"); 922 nt->setSummary( "Planning Project1");
923 nt->setPriority( 1 ); 923 nt->setPriority( 1 );
924 nt->setDescription( "This is a test description of Planning Project1" ); 924 nt->setDescription( "This is a test description of Planning Project1" );
925 nt->setPercentComplete( 20 ); 925 nt->setPercentComplete( 20 );
926 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1") ); 926 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1") );
927 927
928 928
929 Todo * sub1 = nt; 929 Todo * sub1 = nt;
930 sub1->setRelatedTo( root1 ); 930 sub1->setRelatedTo( root1 );
931 931
932 nt = new Todo; 932 nt = new Todo;
933 mCalendar->addTodo( nt ); 933 mCalendar->addTodo( nt );
934 nt->setSummary( "Planning Project1: Lutz"); 934 nt->setSummary( "Planning Project1: Lutz");
935 nt->setPriority( 1 ); 935 nt->setPriority( 1 );
936 nt->setDescription( "This todo counts the actual work of a person on a project" ); 936 nt->setDescription( "This todo counts the actual work of a person on a project" );
937 nt->setPercentComplete( 20 ); 937 nt->setPercentComplete( 20 );
938 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Lutz") ); 938 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Lutz") );
939 Todo * workLutz11 = nt; 939 Todo * workLutz11 = nt;
940 workLutz11->setRelatedTo( sub1 ); 940 workLutz11->setRelatedTo( sub1 );
941 941
942 nt = new Todo; 942 nt = new Todo;
943 mCalendar->addTodo( nt ); 943 mCalendar->addTodo( nt );
944 nt->setSummary( "Planning Project1: Norbert"); 944 nt->setSummary( "Planning Project1: Norbert");
945 nt->setPriority( 1 ); 945 nt->setPriority( 1 );
946 nt->setDescription( "This todo counts the actual work of a person on a project" ); 946 nt->setDescription( "This todo counts the actual work of a person on a project" );
947 nt->setPercentComplete( 20 ); 947 nt->setPercentComplete( 20 );
948 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") ); 948 nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") );
949 Todo * workNorbert11 = nt; 949 Todo * workNorbert11 = nt;
950 workNorbert11->setRelatedTo( sub1 ); 950 workNorbert11->setRelatedTo( sub1 );
951 951
952 nt = new Todo; 952 nt = new Todo;
953 mCalendar->addTodo( nt ); 953 mCalendar->addTodo( nt );
954 nt->setSummary( "Work on 1"); 954 nt->setSummary( "Work on 1");
955 nt->setPriority( 1 ); 955 nt->setPriority( 1 );
956 nt->setDescription( "This is a test description of Work Project_1" ); 956 nt->setDescription( "This is a test description of Work Project_1" );
957 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") ); 957 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") );
958 nt->setPercentComplete( 20 ); 958 nt->setPercentComplete( 20 );
959 959
960 Todo * sub2 = nt; 960 Todo * sub2 = nt;
961 sub2->setRelatedTo( root1 ); 961 sub2->setRelatedTo( root1 );
962 962
963 963
964 nt = new Todo; 964 nt = new Todo;
965 mCalendar->addTodo( nt ); 965 mCalendar->addTodo( nt );
966 nt->setSummary( "Work on 1: Lutz"); 966 nt->setSummary( "Work on 1: Lutz");
967 nt->setPriority( 1 ); 967 nt->setPriority( 1 );
968 nt->setDescription( "This todo counts the actual work of a person on a project" ); 968 nt->setDescription( "This todo counts the actual work of a person on a project" );
969 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") ); 969 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") );
970 nt->setPercentComplete( 20 ); 970 nt->setPercentComplete( 20 );
971 Todo * workLutz12 = nt; 971 Todo * workLutz12 = nt;
972 workLutz12->setRelatedTo( sub2 ); 972 workLutz12->setRelatedTo( sub2 );
973 973
974 nt = new Todo; 974 nt = new Todo;
975 mCalendar->addTodo( nt ); 975 mCalendar->addTodo( nt );
976 nt->setSummary( "Work on 1: Norbert"); 976 nt->setSummary( "Work on 1: Norbert");
977 nt->setPriority( 1 ); 977 nt->setPriority( 1 );
978 nt->setDescription( "This todo counts the actual work of a person on a project" ); 978 nt->setDescription( "This todo counts the actual work of a person on a project" );
979 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") ); 979 nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") );
980 nt->setPercentComplete( 20 ); 980 nt->setPercentComplete( 20 );
981 Todo * workNorbert12 = nt; 981 Todo * workNorbert12 = nt;
982 workNorbert12->setRelatedTo( sub2 ); 982 workNorbert12->setRelatedTo( sub2 );
983 983
984 int secLenRunning = 7200; 984 int secLenRunning = 7200;
985 int secLenPausing = 3600 * 3; 985 int secLenPausing = 3600 * 3;
986 int dayInterval = 1; 986 int dayInterval = 1;
987 //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval ); 987 //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval );
988 createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 ); 988 createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 );
989 createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1); 989 createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1);
990 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3); 990 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3);
991 createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0); 991 createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0);
992 createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1); 992 createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1);
993 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3); 993 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3);
994 createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0); 994 createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0);
995 995
996 } 996 }
997 997
998 { 998 {
999 Todo * root1 = new Todo; 999 Todo * root1 = new Todo;
1000 mCalendar->addTodo( root1 ); 1000 mCalendar->addTodo( root1 );
1001 root1->setSummary( "Project2"); 1001 root1->setSummary( "Project2");
1002 root1->setPriority( 1 ); 1002 root1->setPriority( 1 );
1003 root1->setDescription( "This is a test description of a root Project 2" ); 1003 root1->setDescription( "This is a test description of a root Project 2" );
1004 root1->setPercentComplete( 20 ); 1004 root1->setPercentComplete( 20 );
1005 root1->setCategories( QString( "Cat_Pro2") ); 1005 root1->setCategories( QString( "Cat_Pro2") );
1006 updateView(); 1006 updateView();
1007 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); 1007 QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
1008 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); 1008 QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
1009 int secLenRunning = 7200; 1009 int secLenRunning = 7200;
1010 int secLenPausing = 3600 * 3; 1010 int secLenPausing = 3600 * 3;
1011 int dayInterval = 1; 1011 int dayInterval = 1;
1012 1012
1013 nt = new Todo; 1013 nt = new Todo;
1014 mCalendar->addTodo( nt ); 1014 mCalendar->addTodo( nt );
1015 nt->setSummary( "Planning Project2"); 1015 nt->setSummary( "Planning Project2");
1016 nt->setPriority( 1 ); 1016 nt->setPriority( 1 );
1017 nt->setDescription( "This is a test description of Planning_Project_2" ); 1017 nt->setDescription( "This is a test description of Planning_Project_2" );
1018 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") ); 1018 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") );
1019 nt->setPercentComplete( 20 ); 1019 nt->setPercentComplete( 20 );
1020 1020
1021 1021
1022 Todo * sub1 = nt; 1022 Todo * sub1 = nt;
1023 sub1->setRelatedTo( root1 ); 1023 sub1->setRelatedTo( root1 );
1024 1024
1025 nt = new Todo; 1025 nt = new Todo;
1026 mCalendar->addTodo( nt ); 1026 mCalendar->addTodo( nt );
1027 nt->setSummary( "Planning Project2: Lutz"); 1027 nt->setSummary( "Planning Project2: Lutz");
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->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") ); 1030 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") );
1031 nt->setPercentComplete( 20 ); 1031 nt->setPercentComplete( 20 );
1032 Todo * workLutz11 = nt; 1032 Todo * workLutz11 = nt;
1033 workLutz11->setRelatedTo( sub1 ); 1033 workLutz11->setRelatedTo( sub1 );
1034 1034
1035 nt = new Todo; 1035 nt = new Todo;
1036 mCalendar->addTodo( nt ); 1036 mCalendar->addTodo( nt );
1037 nt->setSummary( "Planning Project2: Norbert"); 1037 nt->setSummary( "Planning Project2: Norbert");
1038 nt->setPriority( 1 ); 1038 nt->setPriority( 1 );
1039 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1039 nt->setDescription( "This todo counts the actual work of a person on a project" );
1040 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") ); 1040 nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") );
1041 nt->setPercentComplete( 20 ); 1041 nt->setPercentComplete( 20 );
1042 Todo * workNorbert11 = nt; 1042 Todo * workNorbert11 = nt;
1043 workNorbert11->setRelatedTo( sub1 ); 1043 workNorbert11->setRelatedTo( sub1 );
1044 1044
1045 nt = new Todo; 1045 nt = new Todo;
1046 mCalendar->addTodo( nt ); 1046 mCalendar->addTodo( nt );
1047 nt->setSummary( "Work on 2"); 1047 nt->setSummary( "Work on 2");
1048 nt->setPriority( 1 ); 1048 nt->setPriority( 1 );
1049 nt->setDescription( "This is a test description of Work Project_2" ); 1049 nt->setDescription( "This is a test description of Work Project_2" );
1050 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") ); 1050 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") );
1051 nt->setPercentComplete( 20 ); 1051 nt->setPercentComplete( 20 );
1052 1052
1053 Todo * sub2 = nt; 1053 Todo * sub2 = nt;
1054 sub2->setRelatedTo( root1 ); 1054 sub2->setRelatedTo( root1 );
1055 1055
1056 1056
1057 nt = new Todo; 1057 nt = new Todo;
1058 mCalendar->addTodo( nt ); 1058 mCalendar->addTodo( nt );
1059 nt->setSummary( "Work on 2: Lutz"); 1059 nt->setSummary( "Work on 2: Lutz");
1060 nt->setPriority( 1 ); 1060 nt->setPriority( 1 );
1061 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1061 nt->setDescription( "This todo counts the actual work of a person on a project" );
1062 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") ); 1062 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") );
1063 nt->setPercentComplete( 20 ); 1063 nt->setPercentComplete( 20 );
1064 Todo * workLutz12 = nt; 1064 Todo * workLutz12 = nt;
1065 workLutz12->setRelatedTo( sub2 ); 1065 workLutz12->setRelatedTo( sub2 );
1066 1066
1067 nt = new Todo; 1067 nt = new Todo;
1068 mCalendar->addTodo( nt ); 1068 mCalendar->addTodo( nt );
1069 nt->setSummary( "Work on 2: Norbert"); 1069 nt->setSummary( "Work on 2: Norbert");
1070 nt->setPriority( 1 ); 1070 nt->setPriority( 1 );
1071 nt->setDescription( "This todo counts the actual work of a person on a project" ); 1071 nt->setDescription( "This todo counts the actual work of a person on a project" );
1072 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") ); 1072 nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") );
1073 nt->setPercentComplete( 20 ); 1073 nt->setPercentComplete( 20 );
1074 Todo * workNorbert12 = nt; 1074 Todo * workNorbert12 = nt;
1075 workNorbert12->setRelatedTo( sub2 ); 1075 workNorbert12->setRelatedTo( sub2 );
1076 createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 ); 1076 createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 );
1077 createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2); 1077 createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2);
1078 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7); 1078 createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7);
1079 createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0); 1079 createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0);
1080 createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1); 1080 createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1);
1081 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0); 1081 createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0);
1082 createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0); 1082 createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0);
1083 } 1083 }
1084 updateView(); 1084 updateView();
1085#endif 1085#endif
1086 1086
1087} 1087}
1088void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval ) 1088void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval )
1089{ 1089{
1090 static int ccc = 0; 1090 static int ccc = 0;
1091 ++ccc; 1091 ++ccc;
1092 QDateTime t_start = start; 1092 QDateTime t_start = start;
1093 runT->setPriority( 5 ); 1093 runT->setPriority( 5 );
1094 runT->setPercentComplete( 0 ); 1094 runT->setPercentComplete( 0 );
1095 int count = 0; 1095 int count = 0;
1096 int prio = 5; 1096 int prio = 5;
1097 int complete = 0; 1097 int complete = 0;
1098 while ( t_start < end ) { 1098 while ( t_start < end ) {
1099 ++count; 1099 ++count;
1100 if ( count > ccc ) { 1100 if ( count > ccc ) {
1101 count = 0; 1101 count = 0;
1102 --prio; 1102 --prio;
1103 if ( prio == 0 ) prio = 5; 1103 if ( prio == 0 ) prio = 5;
1104 complete += 20; 1104 complete += 20;
1105 if ( complete > 100 ) complete = 0; 1105 if ( complete > 100 ) complete = 0;
1106 runT->setPriority( prio ); 1106 runT->setPriority( prio );
1107 runT->setPercentComplete( complete ); 1107 runT->setPercentComplete( complete );
1108 } 1108 }
1109 runT->setRunning( true ); 1109 runT->setRunning( true );
1110 runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) ); 1110 runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) );
1111 if ( dayInterval ) 1111 if ( dayInterval )
1112 t_start = t_start.addDays( dayInterval ); 1112 t_start = t_start.addDays( dayInterval );
1113 else { 1113 else {
1114 t_start = t_start.addSecs( secLenRunning + secLenPausing ); 1114 t_start = t_start.addSecs( secLenRunning + secLenPausing );
1115 } 1115 }
1116 } 1116 }
1117} 1117}
1118 1118
1119void CalendarView::showDay( QDate d ) 1119void CalendarView::showDay( QDate d )
1120{ 1120{
1121 dateNavigator()->blockSignals( true ); 1121 dateNavigator()->blockSignals( true );
1122 dateNavigator()->selectDate( d ); 1122 dateNavigator()->selectDate( d );
1123 dateNavigator()->blockSignals( false ); 1123 dateNavigator()->blockSignals( false );
1124 mViewManager->showDayView(); 1124 mViewManager->showDayView();
1125 //dateNavigator()->selectDate( d ); 1125 //dateNavigator()->selectDate( d );
1126} 1126}
1127void CalendarView::timerAlarm() 1127void CalendarView::timerAlarm()
1128{ 1128{
1129 //qDebug("CalendarView::timerAlarm() "); 1129 //qDebug("CalendarView::timerAlarm() ");
1130 computeAlarm(mAlarmNotification ); 1130 computeAlarm(mAlarmNotification );
1131} 1131}
1132 1132
1133void CalendarView::suspendAlarm() 1133void CalendarView::suspendAlarm()
1134{ 1134{
1135 //qDebug(" CalendarView::suspendAlarm() "); 1135 //qDebug(" CalendarView::suspendAlarm() ");
1136 computeAlarm(mSuspendAlarmNotification ); 1136 computeAlarm(mSuspendAlarmNotification );
1137 1137
1138} 1138}
1139 1139
1140void CalendarView::startAlarm( QString mess , QString filename) 1140void CalendarView::startAlarm( QString mess , QString filename)
1141{ 1141{
1142 1142
1143 topLevelWidget()->showNormal(); 1143 topLevelWidget()->showNormal();
1144 topLevelWidget()->setActiveWindow(); 1144 topLevelWidget()->setActiveWindow();
1145 topLevelWidget()->raise(); 1145 topLevelWidget()->raise();
1146 1146
1147 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 1147 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
1148 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 1148 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
1149 1149
1150} 1150}
1151 1151
1152void CalendarView::checkNextTimerAlarm() 1152void CalendarView::checkNextTimerAlarm()
1153{ 1153{
1154 mCalendar->checkAlarmForIncidence( 0, true ); 1154 mCalendar->checkAlarmForIncidence( 0, true );
1155} 1155}
1156 1156
1157void CalendarView::computeAlarm( QString msg ) 1157void CalendarView::computeAlarm( QString msg )
1158{ 1158{
1159 1159
1160 QString mess = msg; 1160 QString mess = msg;
1161 QString mAlarmMessage = mess.mid( 9 ); 1161 QString mAlarmMessage = mess.mid( 9 );
1162 QString filename = MainWindow::resourcePath(); 1162 QString filename = MainWindow::resourcePath();
1163 filename += "koalarm.wav"; 1163 filename += "koalarm.wav";
1164 QString tempfilename; 1164 QString tempfilename;
1165 if ( mess.left( 13 ) == "suspend_alarm") { 1165 if ( mess.left( 13 ) == "suspend_alarm") {
1166 bool error = false; 1166 bool error = false;
1167 int len = mess.mid( 13 ).find("+++"); 1167 int len = mess.mid( 13 ).find("+++");
1168 if ( len < 2 ) 1168 if ( len < 2 )
1169 error = true; 1169 error = true;
1170 else { 1170 else {
1171 tempfilename = mess.mid( 13, len ); 1171 tempfilename = mess.mid( 13, len );
1172 if ( !QFile::exists( tempfilename ) ) 1172 if ( !QFile::exists( tempfilename ) )
1173 error = true; 1173 error = true;
1174 } 1174 }
1175 if ( ! error ) { 1175 if ( ! error ) {
1176 filename = tempfilename; 1176 filename = tempfilename;
1177 } 1177 }
1178 mAlarmMessage = mess.mid( 13+len+3 ); 1178 mAlarmMessage = mess.mid( 13+len+3 );
1179 //qDebug("suspend file %s ",tempfilename.latin1() ); 1179 //qDebug("suspend file %s ",tempfilename.latin1() );
1180 startAlarm( mAlarmMessage, filename); 1180 startAlarm( mAlarmMessage, filename);
1181 return; 1181 return;
1182 } 1182 }
1183 if ( mess.left( 11 ) == "timer_alarm") { 1183 if ( mess.left( 11 ) == "timer_alarm") {
1184 //mTimerTime = 0; 1184 //mTimerTime = 0;
1185 startAlarm( mess.mid( 11 ), filename ); 1185 startAlarm( mess.mid( 11 ), filename );
1186 return; 1186 return;
1187 } 1187 }
1188 if ( mess.left( 10 ) == "proc_alarm") { 1188 if ( mess.left( 10 ) == "proc_alarm") {
1189 bool error = false; 1189 bool error = false;
1190 int len = mess.mid( 10 ).find("+++"); 1190 int len = mess.mid( 10 ).find("+++");
1191 if ( len < 2 ) 1191 if ( len < 2 )
1192 error = true; 1192 error = true;
1193 else { 1193 else {
1194 tempfilename = mess.mid( 10, len ); 1194 tempfilename = mess.mid( 10, len );
1195 if ( !QFile::exists( tempfilename ) ) 1195 if ( !QFile::exists( tempfilename ) )
1196 error = true; 1196 error = true;
1197 } 1197 }
1198 if ( error ) { 1198 if ( error ) {
1199 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 1199 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
1200 mAlarmMessage += mess.mid( 10+len+3+9 ); 1200 mAlarmMessage += mess.mid( 10+len+3+9 );
1201 } else { 1201 } else {
1202 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 1202 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
1203 //qDebug("-----system command %s ",tempfilename.latin1() ); 1203 //qDebug("-----system command %s ",tempfilename.latin1() );
1204#ifndef _WIN32_ 1204#ifndef _WIN32_
1205 if ( vfork () == 0 ) { 1205 if ( vfork () == 0 ) {
1206 execl ( tempfilename.latin1(), 0 ); 1206 execl ( tempfilename.latin1(), 0 );
1207 return; 1207 return;
1208 } 1208 }
1209#else 1209#else
1210 QProcess* p = new QProcess(); 1210 QProcess* p = new QProcess();
1211 p->addArgument( tempfilename.latin1() ); 1211 p->addArgument( tempfilename.latin1() );
1212 p->start(); 1212 p->start();
1213 return; 1213 return;
1214#endif 1214#endif
1215 1215
1216 return; 1216 return;
1217 } 1217 }
1218 1218
1219 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1219 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1220 } 1220 }
1221 if ( mess.left( 11 ) == "audio_alarm") { 1221 if ( mess.left( 11 ) == "audio_alarm") {
1222 bool error = false; 1222 bool error = false;
1223 int len = mess.mid( 11 ).find("+++"); 1223 int len = mess.mid( 11 ).find("+++");
1224 if ( len < 2 ) 1224 if ( len < 2 )
1225 error = true; 1225 error = true;
1226 else { 1226 else {
1227 tempfilename = mess.mid( 11, len ); 1227 tempfilename = mess.mid( 11, len );
1228 if ( !QFile::exists( tempfilename ) ) 1228 if ( !QFile::exists( tempfilename ) )
1229 error = true; 1229 error = true;
1230 } 1230 }
1231 if ( ! error ) { 1231 if ( ! error ) {
1232 filename = tempfilename; 1232 filename = tempfilename;
1233 } 1233 }
1234 mAlarmMessage = mess.mid( 11+len+3+9 ); 1234 mAlarmMessage = mess.mid( 11+len+3+9 );
1235 //qDebug("audio file command %s ",tempfilename.latin1() ); 1235 //qDebug("audio file command %s ",tempfilename.latin1() );
1236 } 1236 }
1237 if ( mess.left( 9 ) == "cal_alarm") { 1237 if ( mess.left( 9 ) == "cal_alarm") {
1238 mAlarmMessage = mess.mid( 9 ) ; 1238 mAlarmMessage = mess.mid( 9 ) ;
1239 } 1239 }
1240 1240
1241 startAlarm( mAlarmMessage, filename ); 1241 startAlarm( mAlarmMessage, filename );
1242 1242
1243 1243
1244} 1244}
1245 1245
1246void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1246void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1247{ 1247{
1248 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1248 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1249 1249
1250 mSuspendAlarmNotification = noti; 1250 mSuspendAlarmNotification = noti;
1251 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1251 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1252 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1252 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1253 mSuspendTimer->start( ms , true ); 1253 mSuspendTimer->start( ms , true );
1254#ifdef DESKTOP_VERSION
1255 if ( QApplication::desktop()->width() < 1024 ) {
1256 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1257 //qDebug("nextsuspendalarm = \n%s ",mess.latin1() );
1258 QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm";
1259 QFile file( fn );
1260 if (!file.open( IO_WriteOnly ) ) {
1261 qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1262 } else {
1263 QTextStream ts( &file );
1264 ts << mess;
1265 file.close();
1266 }
1267 }
1268#endif
1254 1269
1255} 1270}
1256 1271
1257void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1272void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1258{ 1273{
1259 mNextAlarmDateTime = qdt; 1274 mNextAlarmDateTime = qdt;
1260 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1275 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1261 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1276 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1262#ifndef DESKTOP_VERSION 1277#ifndef DESKTOP_VERSION
1263 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1278 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1264#endif 1279#endif
1265 return; 1280 return;
1266 } 1281 }
1282#ifdef DESKTOP_VERSION
1283 if ( QApplication::desktop()->width() < 1024 ) {
1284 QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
1285 //qDebug("nextalarm = \n%s ",mess.latin1() );
1286 QString fn = QDir::homeDirPath() + "/.kopi_next_alarm";
1287 QFile file( fn );
1288 if (!file.open( IO_WriteOnly ) ) {
1289 qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
1290 } else {
1291 QTextStream ts( &file );
1292 ts << mess;
1293 file.close();
1294 }
1295 }
1296#endif
1267 int maxSec; 1297 int maxSec;
1268 //maxSec = 5; //testing only 1298 //maxSec = 5; //testing only
1269 maxSec = 86400+3600; // one day+1hour 1299 maxSec = 86400+3600; // one day+1hour
1270 mAlarmNotification = noti; 1300 mAlarmNotification = noti;
1271 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1301 int sec = QDateTime::currentDateTime().secsTo( qdt );
1272 if ( sec > maxSec ) { 1302 if ( sec > maxSec ) {
1273 mRecheckAlarmTimer->start( maxSec * 1000 ); 1303 mRecheckAlarmTimer->start( maxSec * 1000 );
1274 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1304 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1275 return; 1305 return;
1276 } else { 1306 } else {
1277 mRecheckAlarmTimer->stop(); 1307 mRecheckAlarmTimer->stop();
1278 } 1308 }
1279 //qDebug("Alarm timer started with secs: %d ", sec); 1309 //qDebug("Alarm timer started with secs: %d ", sec);
1280 mAlarmTimer->start( sec *1000 , true ); 1310 mAlarmTimer->start( sec * 1000 , true );
1281 1311
1282} 1312}
1283// called by mRecheckAlarmTimer to get next alarm 1313// called by mRecheckAlarmTimer to get next alarm
1284// we need this, because a QTimer has only a max range of 25 days 1314// we need this, because a QTimer has only a max range of 25 days
1285void CalendarView::recheckTimerAlarm() 1315void CalendarView::recheckTimerAlarm()
1286{ 1316{
1287 mAlarmTimer->stop(); 1317 mAlarmTimer->stop();
1288 mRecheckAlarmTimer->stop(); 1318 mRecheckAlarmTimer->stop();
1289 mCalendar->checkAlarmForIncidence( 0, true ); 1319 mCalendar->checkAlarmForIncidence( 0, true );
1290} 1320}
1291#ifndef DESKTOP_VERSION 1321#ifndef DESKTOP_VERSION
1292void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1322void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1293#else 1323#else
1294void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1324void CalendarView::removeAlarm(const QDateTime &, const QString & )
1295#endif 1325#endif
1296{ 1326{
1297 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1327 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1298 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1328 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1299#ifndef DESKTOP_VERSION 1329#ifndef DESKTOP_VERSION
1300 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1330 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1301#endif 1331#endif
1302 return; 1332 return;
1303 } 1333 }
1304 mAlarmTimer->stop(); 1334 mAlarmTimer->stop();
1305} 1335}
1306void CalendarView::selectWeekNum ( int num ) 1336void CalendarView::selectWeekNum ( int num )
1307{ 1337{
1308 dateNavigator()->blockSignals( true ); 1338 dateNavigator()->blockSignals( true );
1309 dateNavigator()->selectWeek( num ); 1339 dateNavigator()->selectWeek( num );
1310 dateNavigator()->blockSignals( false ); 1340 dateNavigator()->blockSignals( false );
1311 mViewManager->showWeekView(); 1341 mViewManager->showWeekView();
1312} 1342}
1313KOViewManager *CalendarView::viewManager() 1343KOViewManager *CalendarView::viewManager()
1314{ 1344{
1315 return mViewManager; 1345 return mViewManager;
1316} 1346}
1317 1347
1318KODialogManager *CalendarView::dialogManager() 1348KODialogManager *CalendarView::dialogManager()
1319{ 1349{
1320 return mDialogManager; 1350 return mDialogManager;
1321} 1351}
1322 1352
1323QDate CalendarView::startDate() 1353QDate CalendarView::startDate()
1324{ 1354{
1325 DateList dates = mNavigator->selectedDates(); 1355 DateList dates = mNavigator->selectedDates();
1326 1356
1327 return dates.first(); 1357 return dates.first();
1328} 1358}
1329 1359
1330QDate CalendarView::endDate() 1360QDate CalendarView::endDate()
1331{ 1361{
1332 DateList dates = mNavigator->selectedDates(); 1362 DateList dates = mNavigator->selectedDates();
1333 1363
1334 return dates.last(); 1364 return dates.last();
1335} 1365}
1336 1366
1337 1367
1338void CalendarView::createPrinter() 1368void CalendarView::createPrinter()
1339{ 1369{
1340#ifndef KORG_NOPRINTER 1370#ifndef KORG_NOPRINTER
1341 if (!mCalPrinter) { 1371 if (!mCalPrinter) {
1342 mCalPrinter = new CalPrinter(this, mCalendar); 1372 mCalPrinter = new CalPrinter(this, mCalendar);
1343 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1373 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1344 } 1374 }
1345#endif 1375#endif
1346} 1376}
1347 1377
1348 1378
1349//KOPrefs::instance()->mWriteBackFile 1379//KOPrefs::instance()->mWriteBackFile
1350//KOPrefs::instance()->mWriteBackExistingOnly 1380//KOPrefs::instance()->mWriteBackExistingOnly
1351 1381
1352// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1382// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1353// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1383// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1354// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1384// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1355// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1385// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1356// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1386// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1357// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1387// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1358 1388
1359int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1389int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1360{ 1390{
1361 1391
1362 // 0 equal 1392 // 0 equal
1363 // 1 take local 1393 // 1 take local
1364 // 2 take remote 1394 // 2 take remote
1365 // 3 cancel 1395 // 3 cancel
1366 QDateTime lastSync = mLastCalendarSync; 1396 QDateTime lastSync = mLastCalendarSync;
1367 QDateTime localMod = local->lastModified(); 1397 QDateTime localMod = local->lastModified();
1368 QDateTime remoteMod = remote->lastModified(); 1398 QDateTime remoteMod = remote->lastModified();
1369 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1399 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1370 bool remCh, locCh; 1400 bool remCh, locCh;
1371 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1401 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1372 //if ( remCh ) 1402 //if ( remCh )
1373 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1403 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1374 locCh = ( localMod > mLastCalendarSync ); 1404 locCh = ( localMod > mLastCalendarSync );
1375 if ( !remCh && ! locCh ) { 1405 if ( !remCh && ! locCh ) {
1376 //qDebug("both not changed "); 1406 //qDebug("both not changed ");
1377 lastSync = localMod.addDays(1); 1407 lastSync = localMod.addDays(1);
1378 if ( mode <= SYNC_PREF_ASK ) 1408 if ( mode <= SYNC_PREF_ASK )
1379 return 0; 1409 return 0;
1380 } else { 1410 } else {
1381 if ( locCh ) { 1411 if ( locCh ) {
1382 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1412 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1383 lastSync = localMod.addDays( -1 ); 1413 lastSync = localMod.addDays( -1 );
1384 if ( !remCh ) 1414 if ( !remCh )
1385 remoteMod = ( lastSync.addDays( -1 ) ); 1415 remoteMod = ( lastSync.addDays( -1 ) );
1386 } else { 1416 } else {
1387 //qDebug(" not loc changed "); 1417 //qDebug(" not loc changed ");
1388 lastSync = localMod.addDays( 1 ); 1418 lastSync = localMod.addDays( 1 );
1389 if ( remCh ) 1419 if ( remCh )
1390 remoteMod =( lastSync.addDays( 1 ) ); 1420 remoteMod =( lastSync.addDays( 1 ) );
1391 1421
1392 } 1422 }
1393 } 1423 }
1394 full = true; 1424 full = true;
1395 if ( mode < SYNC_PREF_ASK ) 1425 if ( mode < SYNC_PREF_ASK )
1396 mode = SYNC_PREF_ASK; 1426 mode = SYNC_PREF_ASK;
1397 } else { 1427 } else {
1398 if ( localMod == remoteMod ) 1428 if ( localMod == remoteMod )
1399 // if ( local->revision() == remote->revision() ) 1429 // if ( local->revision() == remote->revision() )
1400 return 0; 1430 return 0;
1401 1431
1402 } 1432 }
1403 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1433 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1404 1434
1405 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1435 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1406 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1436 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1407 //full = true; //debug only 1437 //full = true; //debug only
1408 if ( full ) { 1438 if ( full ) {
1409 bool equ = false; 1439 bool equ = false;
1410 if ( local->typeID() == eventID ) { 1440 if ( local->typeID() == eventID ) {
1411 equ = (*((Event*) local) == *((Event*) remote)); 1441 equ = (*((Event*) local) == *((Event*) remote));
1412 } 1442 }
1413 else if ( local->typeID() == todoID ) 1443 else if ( local->typeID() == todoID )
1414 equ = (*((Todo*) local) == (*(Todo*) remote)); 1444 equ = (*((Todo*) local) == (*(Todo*) remote));
1415 else if ( local->typeID() == journalID ) 1445 else if ( local->typeID() == journalID )
1416 equ = (*((Journal*) local) == *((Journal*) remote)); 1446 equ = (*((Journal*) local) == *((Journal*) remote));
1417 if ( equ ) { 1447 if ( equ ) {
1418 //qDebug("equal "); 1448 //qDebug("equal ");
1419 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1449 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1420 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1450 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1421 } 1451 }
1422 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1452 if ( mode < SYNC_PREF_FORCE_LOCAL )
1423 return 0; 1453 return 0;
1424 1454
1425 }//else //debug only 1455 }//else //debug only
1426 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1456 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1427 } 1457 }
1428 int result; 1458 int result;
1429 bool localIsNew; 1459 bool localIsNew;
1430 //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() ); 1460 //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() );
1431 1461
1432 1462
1433 // ************************************************ 1463 // ************************************************
1434 // ************************************************ 1464 // ************************************************
1435 // ************************************************ 1465 // ************************************************
1436 // We may have that lastSync > remoteMod AND lastSync > localMod 1466 // We may have that lastSync > remoteMod AND lastSync > localMod
1437 // BUT remoteMod != localMod 1467 // BUT remoteMod != localMod
1438 1468
1439 1469
1440 if ( full && mode < SYNC_PREF_NEWEST ) 1470 if ( full && mode < SYNC_PREF_NEWEST )
1441 mode = SYNC_PREF_ASK; 1471 mode = SYNC_PREF_ASK;
1442 1472
1443 switch( mode ) { 1473 switch( mode ) {
1444 case SYNC_PREF_LOCAL: 1474 case SYNC_PREF_LOCAL:
1445 if ( lastSync > remoteMod ) 1475 if ( lastSync > remoteMod )
1446 return 1; 1476 return 1;
1447 if ( lastSync > localMod ) 1477 if ( lastSync > localMod )
1448 return 2; 1478 return 2;
1449 return 1; 1479 return 1;
1450 break; 1480 break;
1451 case SYNC_PREF_REMOTE: 1481 case SYNC_PREF_REMOTE:
1452 if ( lastSync > localMod ) 1482 if ( lastSync > localMod )
1453 return 2; 1483 return 2;
1454 if ( lastSync > remoteMod ) 1484 if ( lastSync > remoteMod )
1455 return 1; 1485 return 1;
1456 return 2; 1486 return 2;
1457 break; 1487 break;
1458 case SYNC_PREF_NEWEST: 1488 case SYNC_PREF_NEWEST:
1459 if ( localMod >= remoteMod ) 1489 if ( localMod >= remoteMod )
1460 return 1; 1490 return 1;
1461 else 1491 else
1462 return 2; 1492 return 2;
1463 break; 1493 break;
1464 case SYNC_PREF_ASK: 1494 case SYNC_PREF_ASK:
1465 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1495 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1466 if ( lastSync > remoteMod && lastSync > localMod) 1496 if ( lastSync > remoteMod && lastSync > localMod)
1467 return 0; 1497 return 0;
1468 if ( lastSync > remoteMod ) 1498 if ( lastSync > remoteMod )
1469 return 1; 1499 return 1;
1470 if ( lastSync > localMod ) 1500 if ( lastSync > localMod )
1471 return 2; 1501 return 2;
1472 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1502 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1473 localIsNew = localMod >= remoteMod; 1503 localIsNew = localMod >= remoteMod;
1474 if ( localIsNew ) 1504 if ( localIsNew )
1475 getEventViewerDialog()->setColorMode( 1 ); 1505 getEventViewerDialog()->setColorMode( 1 );
1476 else 1506 else
1477 getEventViewerDialog()->setColorMode( 2 ); 1507 getEventViewerDialog()->setColorMode( 2 );
1478 getEventViewerDialog()->setIncidence(local); 1508 getEventViewerDialog()->setIncidence(local);
1479 if ( localIsNew ) 1509 if ( localIsNew )
1480 getEventViewerDialog()->setColorMode( 2 ); 1510 getEventViewerDialog()->setColorMode( 2 );
1481 else 1511 else
1482 getEventViewerDialog()->setColorMode( 1 ); 1512 getEventViewerDialog()->setColorMode( 1 );
1483 getEventViewerDialog()->addIncidence(remote); 1513 getEventViewerDialog()->addIncidence(remote);
1484 getEventViewerDialog()->setColorMode( 0 ); 1514 getEventViewerDialog()->setColorMode( 0 );
1485 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1515 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1486 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1516 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1487 getEventViewerDialog()->showMe(); 1517 getEventViewerDialog()->showMe();
1488 result = getEventViewerDialog()->executeS( localIsNew ); 1518 result = getEventViewerDialog()->executeS( localIsNew );
1489 return result; 1519 return result;
1490 1520
1491 break; 1521 break;
1492 case SYNC_PREF_FORCE_LOCAL: 1522 case SYNC_PREF_FORCE_LOCAL:
1493 return 1; 1523 return 1;
1494 break; 1524 break;
1495 case SYNC_PREF_FORCE_REMOTE: 1525 case SYNC_PREF_FORCE_REMOTE:
1496 return 2; 1526 return 2;
1497 break; 1527 break;
1498 1528
1499 default: 1529 default:
1500 // SYNC_PREF_TAKE_BOTH not implemented 1530 // SYNC_PREF_TAKE_BOTH not implemented
1501 break; 1531 break;
1502 } 1532 }
1503 return 0; 1533 return 0;
1504} 1534}
1505Event* CalendarView::getLastSyncEvent() 1535Event* CalendarView::getLastSyncEvent()
1506{ 1536{
1507 Event* lse; 1537 Event* lse;
1508 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1538 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1509 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1539 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1510 if (!lse) { 1540 if (!lse) {
1511 lse = new Event(); 1541 lse = new Event();
1512 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1542 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1513 QString sum = ""; 1543 QString sum = "";
1514 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1544 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1515 sum = "E: "; 1545 sum = "E: ";
1516 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1546 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1517 lse->setDtStart( mLastCalendarSync ); 1547 lse->setDtStart( mLastCalendarSync );
1518 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1548 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1519 lse->setCategories( i18n("SyncEvent") ); 1549 lse->setCategories( i18n("SyncEvent") );
1520 lse->setReadOnly( true ); 1550 lse->setReadOnly( true );
1521 mCalendar->addEvent( lse ); 1551 mCalendar->addEvent( lse );
1522 } 1552 }
1523 1553
1524 return lse; 1554 return lse;
1525 1555
1526} 1556}
1527 1557
1528// we check, if the to delete event has a id for a profile 1558// we check, if the to delete event has a id for a profile
1529// if yes, we set this id in the profile to delete 1559// if yes, we set this id in the profile to delete
1530void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1560void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1531{ 1561{
1532 if ( lastSync.count() == 0 ) { 1562 if ( lastSync.count() == 0 ) {
1533 //qDebug(" lastSync.count() == 0"); 1563 //qDebug(" lastSync.count() == 0");
1534 return; 1564 return;
1535 } 1565 }
1536 if ( toDelete->typeID() == journalID ) 1566 if ( toDelete->typeID() == journalID )
1537 return; 1567 return;
1538 1568
1539 Event* eve = lastSync.first(); 1569 Event* eve = lastSync.first();
1540 1570
1541 while ( eve ) { 1571 while ( eve ) {
1542 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1572 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1543 if ( !id.isEmpty() ) { 1573 if ( !id.isEmpty() ) {
1544 QString des = eve->description(); 1574 QString des = eve->description();
1545 QString pref = "e"; 1575 QString pref = "e";
1546 if ( toDelete->typeID() == todoID ) 1576 if ( toDelete->typeID() == todoID )
1547 pref = "t"; 1577 pref = "t";
1548 des += pref+ id + ","; 1578 des += pref+ id + ",";
1549 eve->setReadOnly( false ); 1579 eve->setReadOnly( false );
1550 eve->setDescription( des ); 1580 eve->setDescription( des );
1551 //qDebug("setdes %s ", des.latin1()); 1581 //qDebug("setdes %s ", des.latin1());
1552 eve->setReadOnly( true ); 1582 eve->setReadOnly( true );
1553 } 1583 }
1554 eve = lastSync.next(); 1584 eve = lastSync.next();
1555 } 1585 }
1556 1586
1557} 1587}
1558void CalendarView::checkExternalId( Incidence * inc ) 1588void CalendarView::checkExternalId( Incidence * inc )
1559{ 1589{
1560 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1590 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1561 checkExternSyncEvent( lastSync, inc ); 1591 checkExternSyncEvent( lastSync, inc );
1562 1592
1563} 1593}
1564bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1594bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1565{ 1595{
1566 bool syncOK = true; 1596 bool syncOK = true;
1567 int addedEvent = 0; 1597 int addedEvent = 0;
1568 int addedEventR = 0; 1598 int addedEventR = 0;
1569 int deletedEventR = 0; 1599 int deletedEventR = 0;
1570 int deletedEventL = 0; 1600 int deletedEventL = 0;
1571 int changedLocal = 0; 1601 int changedLocal = 0;
1572 int changedRemote = 0; 1602 int changedRemote = 0;
1573 int filteredIN = 0; 1603 int filteredIN = 0;
1574 int filteredOUT = 0; 1604 int filteredOUT = 0;
1575 //QPtrList<Event> el = local->rawEvents(); 1605 //QPtrList<Event> el = local->rawEvents();
1576 Event* eventR; 1606 Event* eventR;
1577 QString uid; 1607 QString uid;
1578 int take; 1608 int take;
1579 Event* eventRSync; 1609 Event* eventRSync;
1580 Event* eventLSync; 1610 Event* eventLSync;
1581 clearAllViews(); 1611 clearAllViews();
1582 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1612 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1583 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1613 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1584 bool fullDateRange = false; 1614 bool fullDateRange = false;
1585 local->resetTempSyncStat(); 1615 local->resetTempSyncStat();
1586 mLastCalendarSync = QDateTime::currentDateTime(); 1616 mLastCalendarSync = QDateTime::currentDateTime();
1587 if ( mSyncManager->syncWithDesktop() ) { 1617 if ( mSyncManager->syncWithDesktop() ) {
1588 remote->resetPilotStat(1); 1618 remote->resetPilotStat(1);
1589 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1619 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1590 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1620 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1591 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1621 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1592 } else { 1622 } else {
1593 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1623 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1594 } 1624 }
1595 } 1625 }
1596 QDateTime modifiedCalendar = mLastCalendarSync; 1626 QDateTime modifiedCalendar = mLastCalendarSync;
1597 eventLSync = getLastSyncEvent(); 1627 eventLSync = getLastSyncEvent();
1598 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1628 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1599 if ( eventR ) { 1629 if ( eventR ) {
1600 qDebug("last-syncEvent on remote found "); 1630 qDebug("last-syncEvent on remote found ");
1601 eventRSync = (Event*) eventR->clone(); 1631 eventRSync = (Event*) eventR->clone();
1602 remote->deleteEvent(eventR ); 1632 remote->deleteEvent(eventR );
1603 1633
1604 } else { 1634 } else {
1605 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1635 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1606 eventRSync = (Event*)eventLSync->clone(); 1636 eventRSync = (Event*)eventLSync->clone();
1607 } else { 1637 } else {
1608 fullDateRange = true; 1638 fullDateRange = true;
1609 eventRSync = new Event(); 1639 eventRSync = new Event();
1610 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1640 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1611 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1641 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1612 eventRSync->setDtStart( mLastCalendarSync ); 1642 eventRSync->setDtStart( mLastCalendarSync );
1613 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1643 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1614 eventRSync->setCategories( i18n("SyncEvent") ); 1644 eventRSync->setCategories( i18n("SyncEvent") );
1615 } 1645 }
1616 } 1646 }
1617 if ( eventLSync->dtStart() == mLastCalendarSync ) 1647 if ( eventLSync->dtStart() == mLastCalendarSync )
1618 fullDateRange = true; 1648 fullDateRange = true;
1619 1649
1620 if ( ! fullDateRange ) { 1650 if ( ! fullDateRange ) {
1621 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1651 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1622 1652
1623 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1653 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1624 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1654 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1625 fullDateRange = true; 1655 fullDateRange = true;
1626 } 1656 }
1627 } 1657 }
1628 if ( mSyncManager->syncWithDesktop() ) { 1658 if ( mSyncManager->syncWithDesktop() ) {
1629 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1659 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1630 } 1660 }
1631 if ( fullDateRange ) 1661 if ( fullDateRange )
1632 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1662 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1633 else 1663 else
1634 mLastCalendarSync = eventLSync->dtStart(); 1664 mLastCalendarSync = eventLSync->dtStart();
1635 // for resyncing if own file has changed 1665 // for resyncing if own file has changed
1636 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1666 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1637 mLastCalendarSync = loadedFileVersion; 1667 mLastCalendarSync = loadedFileVersion;
1638 //qDebug("setting mLastCalendarSync "); 1668 //qDebug("setting mLastCalendarSync ");
1639 } 1669 }
1640 //qDebug("*************************** "); 1670 //qDebug("*************************** ");
1641 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1671 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1642 QPtrList<Incidence> er = remote->rawIncidences(); 1672 QPtrList<Incidence> er = remote->rawIncidences();
1643 Incidence* inR = er.first(); 1673 Incidence* inR = er.first();
1644 Incidence* inL; 1674 Incidence* inL;
1645 QProgressBar bar( er.count(),0 ); 1675 QProgressBar bar( er.count(),0 );
1646 bar.setCaption (i18n("Syncing - close to abort!") ); 1676 bar.setCaption (i18n("Syncing - close to abort!") );
1647 1677
1648 // ************** setting up filter ************* 1678 // ************** setting up filter *************
1649 CalFilter *filterIN = 0; 1679 CalFilter *filterIN = 0;
1650 CalFilter *filterOUT = 0; 1680 CalFilter *filterOUT = 0;
1651 CalFilter *filter = mFilters.first(); 1681 CalFilter *filter = mFilters.first();
1652 while(filter) { 1682 while(filter) {
1653 if ( filter->name() == mSyncManager->mFilterInCal ) 1683 if ( filter->name() == mSyncManager->mFilterInCal )
1654 filterIN = filter; 1684 filterIN = filter;
1655 if ( filter->name() == mSyncManager->mFilterOutCal ) 1685 if ( filter->name() == mSyncManager->mFilterOutCal )
1656 filterOUT = filter; 1686 filterOUT = filter;
1657 filter = mFilters.next(); 1687 filter = mFilters.next();
1658 } 1688 }
1659 int w = 300; 1689 int w = 300;
1660 if ( QApplication::desktop()->width() < 320 ) 1690 if ( QApplication::desktop()->width() < 320 )
1661 w = 220; 1691 w = 220;
1662 int h = bar.sizeHint().height() ; 1692 int h = bar.sizeHint().height() ;
1663 int dw = QApplication::desktop()->width(); 1693 int dw = QApplication::desktop()->width();
1664 int dh = QApplication::desktop()->height(); 1694 int dh = QApplication::desktop()->height();
1665 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1695 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1666 bar.show(); 1696 bar.show();
1667 int modulo = (er.count()/10)+1; 1697 int modulo = (er.count()/10)+1;
1668 int incCounter = 0; 1698 int incCounter = 0;
1669 while ( inR ) { 1699 while ( inR ) {
1670 if ( ! bar.isVisible() ) 1700 if ( ! bar.isVisible() )
1671 return false; 1701 return false;
1672 if ( incCounter % modulo == 0 ) 1702 if ( incCounter % modulo == 0 )
1673 bar.setProgress( incCounter ); 1703 bar.setProgress( incCounter );
1674 ++incCounter; 1704 ++incCounter;
1675 uid = inR->uid(); 1705 uid = inR->uid();
1676 bool skipIncidence = false; 1706 bool skipIncidence = false;
1677 if ( uid.left(15) == QString("last-syncEvent-") ) 1707 if ( uid.left(15) == QString("last-syncEvent-") )
1678 skipIncidence = true; 1708 skipIncidence = true;
1679 QString idS; 1709 QString idS;
1680 qApp->processEvents(); 1710 qApp->processEvents();
1681 if ( !skipIncidence ) { 1711 if ( !skipIncidence ) {
1682 inL = local->incidenceForUid( uid , false ); 1712 inL = local->incidenceForUid( uid , false );
1683 if ( inL ) { // maybe conflict - same uid in both calendars 1713 if ( inL ) { // maybe conflict - same uid in both calendars
1684 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1714 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1685 //qDebug("take %d %s ", take, inL->summary().latin1()); 1715 //qDebug("take %d %s ", take, inL->summary().latin1());
1686 if ( take == 3 ) 1716 if ( take == 3 )
1687 return false; 1717 return false;
1688 if ( take == 1 ) {// take local ********************** 1718 if ( take == 1 ) {// take local **********************
1689 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1719 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1690 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1720 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1691 else 1721 else
1692 idS = inR->IDStr(); 1722 idS = inR->IDStr();
1693 int calID = inR->calID(); 1723 int calID = inR->calID();
1694 remote->deleteIncidence( inR ); 1724 remote->deleteIncidence( inR );
1695 inR = inL->clone(); 1725 inR = inL->clone();
1696 inR->setCalID( calID ); 1726 inR->setCalID( calID );
1697 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1727 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1698 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1728 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1699 inR->setIDStr( idS ); 1729 inR->setIDStr( idS );
1700 remote->addIncidence( inR ); 1730 remote->addIncidence( inR );
1701 if ( mSyncManager->syncWithDesktop() ) 1731 if ( mSyncManager->syncWithDesktop() )
1702 inR->setPilotId( 2 ); 1732 inR->setPilotId( 2 );
1703 ++changedRemote; 1733 ++changedRemote;
1704 } else {// take remote ********************** 1734 } else {// take remote **********************
1705 if ( !inL->isReadOnly() ) { 1735 if ( !inL->isReadOnly() ) {
1706 idS = inL->IDStr(); 1736 idS = inL->IDStr();
1707 int pid = inL->pilotId(); 1737 int pid = inL->pilotId();
1708 int calID = inL->calID(); 1738 int calID = inL->calID();
1709 local->deleteIncidence( inL ); 1739 local->deleteIncidence( inL );
1710 inL = inR->clone(); 1740 inL = inR->clone();
1711 inL->setCalID( calID ); 1741 inL->setCalID( calID );
1712 if ( mSyncManager->syncWithDesktop() ) 1742 if ( mSyncManager->syncWithDesktop() )
1713 inL->setPilotId( pid ); 1743 inL->setPilotId( pid );
1714 inL->setIDStr( idS ); 1744 inL->setIDStr( idS );
1715 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1745 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1716 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1746 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1717 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1747 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1718 } 1748 }
1719 local->addIncidence( inL ); 1749 local->addIncidence( inL );
1720 ++changedLocal; 1750 ++changedLocal;
1721 } 1751 }
1722 } 1752 }
1723 } 1753 }
1724 } else { // no conflict ********** add or delete remote 1754 } else { // no conflict ********** add or delete remote
1725 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1755 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1726 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1756 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1727 QString des = eventLSync->description(); 1757 QString des = eventLSync->description();
1728 QString pref = "e"; 1758 QString pref = "e";
1729 if ( inR->typeID() == todoID ) 1759 if ( inR->typeID() == todoID )
1730 pref = "t"; 1760 pref = "t";
1731 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1761 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1732 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1762 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1733 //remote->deleteIncidence( inR ); 1763 //remote->deleteIncidence( inR );
1734 ++deletedEventR; 1764 ++deletedEventR;
1735 } else { 1765 } else {
1736 inR->setLastModified( modifiedCalendar ); 1766 inR->setLastModified( modifiedCalendar );
1737 inL = inR->clone(); 1767 inL = inR->clone();
1738 inL->setIDStr( ":" ); 1768 inL->setIDStr( ":" );
1739 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1769 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1740 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1770 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1741 1771
1742 inL->setCalID( 0 );// add to default cal 1772 inL->setCalID( 0 );// add to default cal
1743 local->addIncidence( inL ); 1773 local->addIncidence( inL );
1744 ++addedEvent; 1774 ++addedEvent;
1745 1775
1746 } 1776 }
1747 } else { 1777 } else {
1748 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1778 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1749 inR->setLastModified( modifiedCalendar ); 1779 inR->setLastModified( modifiedCalendar );
1750 inL = inR->clone(); 1780 inL = inR->clone();
1751 inL->setIDStr( ":" ); 1781 inL->setIDStr( ":" );
1752 inL->setCalID( 0 );// add to default cal 1782 inL->setCalID( 0 );// add to default cal
1753 local->addIncidence( inL ); 1783 local->addIncidence( inL );
1754 ++addedEvent; 1784 ++addedEvent;
1755 1785
1756 } else { 1786 } else {
1757 checkExternSyncEvent(eventRSyncSharp, inR); 1787 checkExternSyncEvent(eventRSyncSharp, inR);
1758 remote->deleteIncidence( inR ); 1788 remote->deleteIncidence( inR );
1759 ++deletedEventR; 1789 ++deletedEventR;
1760 } 1790 }
1761 } 1791 }
1762 } else { 1792 } else {
1763 ++filteredIN; 1793 ++filteredIN;
1764 } 1794 }
1765 } 1795 }
1766 } 1796 }
1767 inR = er.next(); 1797 inR = er.next();
1768 } 1798 }
1769 QPtrList<Incidence> el = local->rawIncidences(); 1799 QPtrList<Incidence> el = local->rawIncidences();
1770 inL = el.first(); 1800 inL = el.first();
1771 modulo = (el.count()/10)+1; 1801 modulo = (el.count()/10)+1;
1772 bar.setCaption (i18n("Add / remove events") ); 1802 bar.setCaption (i18n("Add / remove events") );
1773 bar.setTotalSteps ( el.count() ) ; 1803 bar.setTotalSteps ( el.count() ) ;
1774 bar.show(); 1804 bar.show();
1775 incCounter = 0; 1805 incCounter = 0;
1776 1806
1777 while ( inL ) { 1807 while ( inL ) {
1778 1808
1779 qApp->processEvents(); 1809 qApp->processEvents();
1780 if ( ! bar.isVisible() ) 1810 if ( ! bar.isVisible() )
1781 return false; 1811 return false;
1782 if ( incCounter % modulo == 0 ) 1812 if ( incCounter % modulo == 0 )
1783 bar.setProgress( incCounter ); 1813 bar.setProgress( incCounter );
1784 ++incCounter; 1814 ++incCounter;
1785 uid = inL->uid(); 1815 uid = inL->uid();
1786 bool skipIncidence = false; 1816 bool skipIncidence = false;
1787 if ( uid.left(15) == QString("last-syncEvent-") ) 1817 if ( uid.left(15) == QString("last-syncEvent-") )
1788 skipIncidence = true; 1818 skipIncidence = true;
1789 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1819 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1790 skipIncidence = true; 1820 skipIncidence = true;
1791 if ( !skipIncidence ) { 1821 if ( !skipIncidence ) {
1792 inR = remote->incidenceForUid( uid , true ); 1822 inR = remote->incidenceForUid( uid , true );
1793 if ( ! inR ) { 1823 if ( ! inR ) {
1794 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1824 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1795 // no conflict ********** add or delete local 1825 // no conflict ********** add or delete local
1796 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1826 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1797 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1827 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1798 checkExternSyncEvent(eventLSyncSharp, inL); 1828 checkExternSyncEvent(eventLSyncSharp, inL);
1799 local->deleteIncidence( inL ); 1829 local->deleteIncidence( inL );
1800 ++deletedEventL; 1830 ++deletedEventL;
1801 } else { 1831 } else {
1802 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1832 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1803 inL->removeID(mCurrentSyncDevice ); 1833 inL->removeID(mCurrentSyncDevice );
1804 ++addedEventR; 1834 ++addedEventR;
1805 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1835 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1806 inL->setLastModified( modifiedCalendar ); 1836 inL->setLastModified( modifiedCalendar );
1807 inR = inL->clone(); 1837 inR = inL->clone();
1808 inR->setIDStr( ":" ); 1838 inR->setIDStr( ":" );
1809 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1839 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1810 inR->setCalID( 0 );// add to default cal 1840 inR->setCalID( 0 );// add to default cal
1811 remote->addIncidence( inR ); 1841 remote->addIncidence( inR );
1812 } 1842 }
1813 } 1843 }
1814 } else { 1844 } else {
1815 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1845 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1816 checkExternSyncEvent(eventLSyncSharp, inL); 1846 checkExternSyncEvent(eventLSyncSharp, inL);
1817 local->deleteIncidence( inL ); 1847 local->deleteIncidence( inL );
1818 ++deletedEventL; 1848 ++deletedEventL;
1819 } else { 1849 } else {
1820 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1850 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1821 ++addedEventR; 1851 ++addedEventR;
1822 inL->setLastModified( modifiedCalendar ); 1852 inL->setLastModified( modifiedCalendar );
1823 inR = inL->clone(); 1853 inR = inL->clone();
1824 inR->setIDStr( ":" ); 1854 inR->setIDStr( ":" );
1825 inR->setCalID( 0 );// add to default cal 1855 inR->setCalID( 0 );// add to default cal
1826 remote->addIncidence( inR ); 1856 remote->addIncidence( inR );
1827 } 1857 }
1828 } 1858 }
1829 } 1859 }
1830 } else { 1860 } else {
1831 ++filteredOUT; 1861 ++filteredOUT;
1832 } 1862 }
1833 } 1863 }
1834 } 1864 }
1835 inL = el.next(); 1865 inL = el.next();
1836 } 1866 }
1837 int delFut = 0; 1867 int delFut = 0;
1838 int remRem = 0; 1868 int remRem = 0;
1839 if ( mSyncManager->mWriteBackInFuture ) { 1869 if ( mSyncManager->mWriteBackInFuture ) {
1840 er = remote->rawIncidences(); 1870 er = remote->rawIncidences();
1841 remRem = er.count(); 1871 remRem = er.count();
1842 inR = er.first(); 1872 inR = er.first();
1843 QDateTime dt; 1873 QDateTime dt;
1844 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1874 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1845 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1875 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1846 while ( inR ) { 1876 while ( inR ) {
1847 if ( inR->typeID() == todoID ) { 1877 if ( inR->typeID() == todoID ) {
1848 Todo * t = (Todo*)inR; 1878 Todo * t = (Todo*)inR;
1849 if ( t->hasDueDate() ) 1879 if ( t->hasDueDate() )
1850 dt = t->dtDue(); 1880 dt = t->dtDue();
1851 else 1881 else
1852 dt = cur.addSecs( 62 ); 1882 dt = cur.addSecs( 62 );
1853 } 1883 }
1854 else if (inR->typeID() == eventID ) { 1884 else if (inR->typeID() == eventID ) {
1855 bool ok; 1885 bool ok;
1856 dt = inR->getNextOccurence( cur, &ok ); 1886 dt = inR->getNextOccurence( cur, &ok );
1857 if ( !ok ) 1887 if ( !ok )
1858 dt = cur.addSecs( -62 ); 1888 dt = cur.addSecs( -62 );
1859 } 1889 }
1860 else 1890 else
1861 dt = inR->dtStart(); 1891 dt = inR->dtStart();
1862 if ( dt < cur || dt > end ) { 1892 if ( dt < cur || dt > end ) {
1863 remote->deleteIncidence( inR ); 1893 remote->deleteIncidence( inR );
1864 ++delFut; 1894 ++delFut;
1865 } 1895 }
1866 inR = er.next(); 1896 inR = er.next();
1867 } 1897 }
1868 } 1898 }
1869 bar.hide(); 1899 bar.hide();
1870 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1900 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1871 eventLSync->setReadOnly( false ); 1901 eventLSync->setReadOnly( false );
1872 eventLSync->setDtStart( mLastCalendarSync ); 1902 eventLSync->setDtStart( mLastCalendarSync );
1873 eventRSync->setDtStart( mLastCalendarSync ); 1903 eventRSync->setDtStart( mLastCalendarSync );
1874 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1904 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1875 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1905 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1876 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1906 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1877 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1907 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1878 eventLSync->setReadOnly( true ); 1908 eventLSync->setReadOnly( true );
1879 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1909 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1880 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1910 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1881 remote->addEvent( eventRSync ); 1911 remote->addEvent( eventRSync );
1882 else 1912 else
1883 delete eventRSync; 1913 delete eventRSync;
1884 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1914 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1885 QString mes; 1915 QString mes;
1886 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 ); 1916 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 );
1887 QString delmess; 1917 QString delmess;
1888 if ( delFut ) { 1918 if ( delFut ) {
1889 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); 1919 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);
1890 mes += delmess; 1920 mes += delmess;
1891 } 1921 }
1892 mes = i18n("Local calendar changed!\n") +mes; 1922 mes = i18n("Local calendar changed!\n") +mes;
1893 mCalendar->checkAlarmForIncidence( 0, true ); 1923 mCalendar->checkAlarmForIncidence( 0, true );
1894 qDebug( mes ); 1924 qDebug( mes );
1895 if ( mSyncManager->mShowSyncSummary ) { 1925 if ( mSyncManager->mShowSyncSummary ) {
1896 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1926 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1897 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1927 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1898 qDebug("KO: WB cancelled "); 1928 qDebug("KO: WB cancelled ");
1899 mSyncManager->mWriteBackFile = false; 1929 mSyncManager->mWriteBackFile = false;
1900 return syncOK; 1930 return syncOK;
1901 } 1931 }
1902 } 1932 }
1903 return syncOK; 1933 return syncOK;
1904} 1934}
1905 1935
1906void CalendarView::setSyncDevice( QString s ) 1936void CalendarView::setSyncDevice( QString s )
1907{ 1937{
1908 mCurrentSyncDevice= s; 1938 mCurrentSyncDevice= s;
1909} 1939}
1910void CalendarView::setSyncName( QString s ) 1940void CalendarView::setSyncName( QString s )
1911{ 1941{
1912 mCurrentSyncName= s; 1942 mCurrentSyncName= s;
1913} 1943}
1914bool CalendarView::syncCalendar(QString filename, int mode) 1944bool CalendarView::syncCalendar(QString filename, int mode)
1915{ 1945{
1916 //qDebug("syncCalendar %s ", filename.latin1()); 1946 //qDebug("syncCalendar %s ", filename.latin1());
1917 mGlobalSyncMode = SYNC_MODE_NORMAL; 1947 mGlobalSyncMode = SYNC_MODE_NORMAL;
1918 CalendarLocal* calendar = new CalendarLocal(); 1948 CalendarLocal* calendar = new CalendarLocal();
1919 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1949 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1920 FileStorage* storage = new FileStorage( calendar ); 1950 FileStorage* storage = new FileStorage( calendar );
1921 bool syncOK = false; 1951 bool syncOK = false;
1922 storage->setFileName( filename ); 1952 storage->setFileName( filename );
1923 // qDebug("loading ... "); 1953 // qDebug("loading ... ");
1924 if ( storage->load() ) { 1954 if ( storage->load() ) {
1925 getEventViewerDialog()->setSyncMode( true ); 1955 getEventViewerDialog()->setSyncMode( true );
1926 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1956 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1927 getEventViewerDialog()->setSyncMode( false ); 1957 getEventViewerDialog()->setSyncMode( false );
1928 if ( syncOK ) { 1958 if ( syncOK ) {
1929 if ( mSyncManager->mWriteBackFile ) 1959 if ( mSyncManager->mWriteBackFile )
1930 { 1960 {
1931 storage->setSaveFormat( new ICalFormat() ); 1961 storage->setSaveFormat( new ICalFormat() );
1932 storage->save(); 1962 storage->save();
1933 } 1963 }
1934 } 1964 }
1935 setModified( true ); 1965 setModified( true );
1936 } 1966 }
1937 delete storage; 1967 delete storage;
1938 delete calendar; 1968 delete calendar;
1939 if ( syncOK ) 1969 if ( syncOK )
1940 updateView(); 1970 updateView();
1941 return syncOK; 1971 return syncOK;
1942} 1972}
1943 1973
1944void CalendarView::syncExternal( int mode ) 1974void CalendarView::syncExternal( int mode )
1945{ 1975{
1946 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1976 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1947 1977
1948 qApp->processEvents(); 1978 qApp->processEvents();
1949 CalendarLocal* calendar = new CalendarLocal(); 1979 CalendarLocal* calendar = new CalendarLocal();
1950 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1980 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1951 bool syncOK = false; 1981 bool syncOK = false;
1952 bool loadSuccess = false; 1982 bool loadSuccess = false;
1953 PhoneFormat* phoneFormat = 0; 1983 PhoneFormat* phoneFormat = 0;
1954 emit tempDisableBR(true); 1984 emit tempDisableBR(true);
1955#ifndef DESKTOP_VERSION 1985#ifndef DESKTOP_VERSION
1956 SharpFormat* sharpFormat = 0; 1986 SharpFormat* sharpFormat = 0;
1957 if ( mode == 0 ) { // sharp 1987 if ( mode == 0 ) { // sharp
1958 sharpFormat = new SharpFormat () ; 1988 sharpFormat = new SharpFormat () ;
1959 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1989 loadSuccess = sharpFormat->load( calendar, mCalendar );
1960 1990
1961 } else 1991 } else
1962#endif 1992#endif
1963 if ( mode == 1 ) { // phone 1993 if ( mode == 1 ) { // phone
1964 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1994 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1965 mSyncManager->mPhoneDevice, 1995 mSyncManager->mPhoneDevice,
1966 mSyncManager->mPhoneConnection, 1996 mSyncManager->mPhoneConnection,
1967 mSyncManager->mPhoneModel); 1997 mSyncManager->mPhoneModel);
1968 loadSuccess = phoneFormat->load( calendar,mCalendar); 1998 loadSuccess = phoneFormat->load( calendar,mCalendar);
1969 1999
1970 } else { 2000 } else {
1971 emit tempDisableBR(false); 2001 emit tempDisableBR(false);
1972 return; 2002 return;
1973 } 2003 }
1974 if ( loadSuccess ) { 2004 if ( loadSuccess ) {
1975 getEventViewerDialog()->setSyncMode( true ); 2005 getEventViewerDialog()->setSyncMode( true );
1976 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2006 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1977 getEventViewerDialog()->setSyncMode( false ); 2007 getEventViewerDialog()->setSyncMode( false );
1978 qApp->processEvents(); 2008 qApp->processEvents();
1979 if ( syncOK ) { 2009 if ( syncOK ) {
1980 if ( mSyncManager->mWriteBackFile ) 2010 if ( mSyncManager->mWriteBackFile )
1981 { 2011 {
1982 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 2012 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1983 Incidence* inc = iL.first(); 2013 Incidence* inc = iL.first();
1984 if ( phoneFormat ) { 2014 if ( phoneFormat ) {
1985 while ( inc ) { 2015 while ( inc ) {
1986 inc->removeID(mCurrentSyncDevice); 2016 inc->removeID(mCurrentSyncDevice);
1987 inc = iL.next(); 2017 inc = iL.next();
1988 } 2018 }
1989 } 2019 }
1990#ifndef DESKTOP_VERSION 2020#ifndef DESKTOP_VERSION
1991 if ( sharpFormat ) 2021 if ( sharpFormat )
1992 sharpFormat->save(calendar); 2022 sharpFormat->save(calendar);
1993#endif 2023#endif
1994 if ( phoneFormat ) 2024 if ( phoneFormat )
1995 phoneFormat->save(calendar); 2025 phoneFormat->save(calendar);
1996 iL = calendar->rawIncidences(); 2026 iL = calendar->rawIncidences();
1997 inc = iL.first(); 2027 inc = iL.first();
1998 Incidence* loc; 2028 Incidence* loc;
1999 while ( inc ) { 2029 while ( inc ) {
2000 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 2030 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
2001 loc = mCalendar->incidence(inc->uid() ); 2031 loc = mCalendar->incidence(inc->uid() );
2002 if ( loc ) { 2032 if ( loc ) {
2003 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 2033 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
2004 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 2034 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
2005 } 2035 }
2006 } 2036 }
2007 inc = iL.next(); 2037 inc = iL.next();
2008 } 2038 }
2009 Incidence* lse = getLastSyncEvent(); 2039 Incidence* lse = getLastSyncEvent();
2010 if ( lse ) { 2040 if ( lse ) {
2011 lse->setReadOnly( false ); 2041 lse->setReadOnly( false );
2012 lse->setDescription( "" ); 2042 lse->setDescription( "" );
2013 lse->setReadOnly( true ); 2043 lse->setReadOnly( true );
2014 } 2044 }
2015 } 2045 }
2016 } else { 2046 } else {
2017 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 2047 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
2018 } 2048 }
2019 setModified( true ); 2049 setModified( true );
2020 } else { 2050 } else {
2021 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 2051 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
2022 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 2052 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
2023 question, i18n("Ok")) ; 2053 question, i18n("Ok")) ;
2024 2054
2025 } 2055 }
2026 delete calendar; 2056 delete calendar;
2027 updateView(); 2057 updateView();
2028 emit tempDisableBR(false); 2058 emit tempDisableBR(false);
2029 return ;//syncOK; 2059 return ;//syncOK;
2030 2060
2031} 2061}
2032 2062
2033bool CalendarView::importBday() 2063bool CalendarView::importBday()
2034{ 2064{
2035#ifndef KORG_NOKABC 2065#ifndef KORG_NOKABC
2036 2066
2037#ifdef DESKTOP_VERSION 2067#ifdef DESKTOP_VERSION
2038 int curCal = mCalendar->defaultCalendar(); 2068 int curCal = mCalendar->defaultCalendar();
2039 int bd = mCalEditView->getBirtdayID(); 2069 int bd = mCalEditView->getBirtdayID();
2040 if ( bd == 0 ) 2070 if ( bd == 0 )
2041 return false; 2071 return false;
2042 mCalendar->setDefaultCalendar( bd ); 2072 mCalendar->setDefaultCalendar( bd );
2043 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 2073 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
2044 KABC::AddressBook::Iterator it; 2074 KABC::AddressBook::Iterator it;
2045 int count = 0; 2075 int count = 0;
2046 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2076 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2047 ++count; 2077 ++count;
2048 } 2078 }
2049 QProgressBar bar(count,0 ); 2079 QProgressBar bar(count,0 );
2050 int w = 300; 2080 int w = 300;
2051 if ( QApplication::desktop()->width() < 320 ) 2081 if ( QApplication::desktop()->width() < 320 )
2052 w = 220; 2082 w = 220;
2053 int h = bar.sizeHint().height() ; 2083 int h = bar.sizeHint().height() ;
2054 int dw = QApplication::desktop()->width(); 2084 int dw = QApplication::desktop()->width();
2055 int dh = QApplication::desktop()->height(); 2085 int dh = QApplication::desktop()->height();
2056 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2086 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2057 bar.show(); 2087 bar.show();
2058 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 2088 bar.setCaption (i18n("Reading addressbook - close to abort!") );
2059 qApp->processEvents(); 2089 qApp->processEvents();
2060 count = 0; 2090 count = 0;
2061 int addCount = 0; 2091 int addCount = 0;
2062 KCal::Attendee* a = 0; 2092 KCal::Attendee* a = 0;
2063 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 2093 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
2064 if ( ! bar.isVisible() ) 2094 if ( ! bar.isVisible() )
2065 return false; 2095 return false;
2066 bar.setProgress( count++ ); 2096 bar.setProgress( count++ );
2067 qApp->processEvents(); 2097 qApp->processEvents();
2068 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 2098 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
2069 if ( (*it).birthday().date().isValid() ){ 2099 if ( (*it).birthday().date().isValid() ){
2070 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2100 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2071 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 2101 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
2072 ++addCount; 2102 ++addCount;
2073 } 2103 }
2074 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 2104 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
2075 if ( anni.isValid() ){ 2105 if ( anni.isValid() ){
2076 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 2106 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
2077 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 2107 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
2078 ++addCount; 2108 ++addCount;
2079 } 2109 }
2080 } 2110 }
2081 mCalendar->setDefaultCalendar( curCal ); 2111 mCalendar->setDefaultCalendar( curCal );
2082 updateView(); 2112 updateView();
2083 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2113 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2084#else //DESKTOP_VERSION 2114#else //DESKTOP_VERSION
2085 2115
2086 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 2116 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
2087 // the result should now arrive through method insertBirthdays 2117 // the result should now arrive through method insertBirthdays
2088 2118
2089#endif //DESKTOP_VERSION 2119#endif //DESKTOP_VERSION
2090 2120
2091#endif //KORG_NOKABC 2121#endif //KORG_NOKABC
2092 2122
2093 2123
2094 return true; 2124 return true;
2095} 2125}
2096 2126
2097// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 2127// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
2098void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 2128void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
2099 const QStringList& anniversaryList, const QStringList& realNameList, 2129 const QStringList& anniversaryList, const QStringList& realNameList,
2100 const QStringList& emailList, const QStringList& assembledNameList, 2130 const QStringList& emailList, const QStringList& assembledNameList,
2101 const QStringList& uidList) 2131 const QStringList& uidList)
2102{ 2132{
2103 2133
2104 //qDebug("KO::CalendarView::insertBirthdays"); 2134 //qDebug("KO::CalendarView::insertBirthdays");
2105 if (uid == this->name()) 2135 if (uid == this->name())
2106 { 2136 {
2107 int curCal = mCalendar->defaultCalendar(); 2137 int curCal = mCalendar->defaultCalendar();
2108 int bd = mCalEditView->getBirtdayID(); 2138 int bd = mCalEditView->getBirtdayID();
2109 if ( bd == 0 ) 2139 if ( bd == 0 )
2110 return; 2140 return;
2111 mCalendar->setDefaultCalendar( bd ); 2141 mCalendar->setDefaultCalendar( bd );
2112 2142
2113 2143
2114 int count = birthdayList.count(); 2144 int count = birthdayList.count();
2115 int addCount = 0; 2145 int addCount = 0;
2116 KCal::Attendee* a = 0; 2146 KCal::Attendee* a = 0;
2117 2147
2118 //qDebug("CalView 1 %i", count); 2148 //qDebug("CalView 1 %i", count);
2119 2149
2120 QProgressBar bar(count,0 ); 2150 QProgressBar bar(count,0 );
2121 int w = 300; 2151 int w = 300;
2122 if ( QApplication::desktop()->width() < 320 ) 2152 if ( QApplication::desktop()->width() < 320 )
2123 w = 220; 2153 w = 220;
2124 int h = bar.sizeHint().height() ; 2154 int h = bar.sizeHint().height() ;
2125 int dw = QApplication::desktop()->width(); 2155 int dw = QApplication::desktop()->width();
2126 int dh = QApplication::desktop()->height(); 2156 int dh = QApplication::desktop()->height();
2127 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2157 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2128 bar.show(); 2158 bar.show();
2129 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 2159 bar.setCaption (i18n("inserting birthdays - close to abort!") );
2130 qApp->processEvents(); 2160 qApp->processEvents();
2131 2161
2132 QDate birthday; 2162 QDate birthday;
2133 QDate anniversary; 2163 QDate anniversary;
2134 QString realName; 2164 QString realName;
2135 QString email; 2165 QString email;
2136 QString assembledName; 2166 QString assembledName;
2137 QString uid; 2167 QString uid;
2138 bool ok = true; 2168 bool ok = true;
2139 for ( int i = 0; i < count; i++) 2169 for ( int i = 0; i < count; i++)
2140 { 2170 {
2141 if ( ! bar.isVisible() ) 2171 if ( ! bar.isVisible() )
2142 return; 2172 return;
2143 bar.setProgress( i ); 2173 bar.setProgress( i );
2144 qApp->processEvents(); 2174 qApp->processEvents();
2145 2175
2146 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 2176 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
2147 if (!ok) { 2177 if (!ok) {
2148 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 2178 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
2149 } 2179 }
2150 2180
2151 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 2181 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
2152 if (!ok) { 2182 if (!ok) {
2153 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 2183 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
2154 } 2184 }
2155 realName = realNameList[i]; 2185 realName = realNameList[i];
2156 email = emailList[i]; 2186 email = emailList[i];
2157 assembledName = assembledNameList[i]; 2187 assembledName = assembledNameList[i];
2158 uid = uidList[i]; 2188 uid = uidList[i];
2159 //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() ); 2189 //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() );
2160 2190
2161 if ( birthday.isValid() ){ 2191 if ( birthday.isValid() ){
2162 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2192 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2163 KCal::Attendee::ReqParticipant,uid) ; 2193 KCal::Attendee::ReqParticipant,uid) ;
2164 if ( addAnniversary( birthday, assembledName, a, true ) ) 2194 if ( addAnniversary( birthday, assembledName, a, true ) )
2165 ++addCount; 2195 ++addCount;
2166 } 2196 }
2167 2197
2168 if ( anniversary.isValid() ){ 2198 if ( anniversary.isValid() ){
2169 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 2199 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
2170 KCal::Attendee::ReqParticipant,uid) ; 2200 KCal::Attendee::ReqParticipant,uid) ;
2171 if ( addAnniversary( anniversary, assembledName, a, false ) ) 2201 if ( addAnniversary( anniversary, assembledName, a, false ) )
2172 ++addCount; 2202 ++addCount;
2173 } 2203 }
2174 } 2204 }
2175 2205
2176 mCalendar->setDefaultCalendar( curCal ); 2206 mCalendar->setDefaultCalendar( curCal );
2177 updateView(); 2207 updateView();
2178 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 2208 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
2179 2209
2180 } 2210 }
2181 2211
2182} 2212}
2183 2213
2184 2214
2185 2215
2186bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 2216bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
2187{ 2217{
2188 //qDebug("addAnni "); 2218 //qDebug("addAnni ");
2189 Event * ev = new Event(); 2219 Event * ev = new Event();
2190 ev->setOrganizer(KOPrefs::instance()->email()); 2220 ev->setOrganizer(KOPrefs::instance()->email());
2191 if ( a ) { 2221 if ( a ) {
2192 ev->addAttendee( a ); 2222 ev->addAttendee( a );
2193 } 2223 }
2194 QString kind; 2224 QString kind;
2195 if ( birthday ) { 2225 if ( birthday ) {
2196 kind = i18n( "Birthday" ); 2226 kind = i18n( "Birthday" );
2197 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 2227 ev->setSummary( name + " (" + QString::number(date.year()) +")");
2198 } 2228 }
2199 else { 2229 else {
2200 kind = i18n( "Anniversary" ); 2230 kind = i18n( "Anniversary" );
2201 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 2231 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
2202 } 2232 }
2203 ev->setCategories( kind ); 2233 ev->setCategories( kind );
2204 ev->setDtStart( QDateTime(date) ); 2234 ev->setDtStart( QDateTime(date) );
2205 ev->setDtEnd( QDateTime(date) ); 2235 ev->setDtEnd( QDateTime(date) );
2206 ev->setFloats( true ); 2236 ev->setFloats( true );
2207 Recurrence * rec = ev->recurrence(); 2237 Recurrence * rec = ev->recurrence();
2208 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 2238 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
2209 rec->addYearlyNum( date.month() ); 2239 rec->addYearlyNum( date.month() );
2210 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 2240 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
2211 delete ev; 2241 delete ev;
2212 return false; 2242 return false;
2213 } 2243 }
2214 return true; 2244 return true;
2215 2245
2216} 2246}
2217bool CalendarView::importQtopia( const QString &categories, 2247bool CalendarView::importQtopia( const QString &categories,
2218 const QString &datebook, 2248 const QString &datebook,
2219 const QString &todolist ) 2249 const QString &todolist )
2220{ 2250{
2221 2251
2222 QtopiaFormat qtopiaFormat; 2252 QtopiaFormat qtopiaFormat;
2223 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2253 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2224 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2254 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
2225 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2255 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
2226 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2256 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
2227 2257
2228 updateView(); 2258 updateView();
2229 return true; 2259 return true;
2230 2260
2231#if 0 2261#if 0
2232 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2262 mGlobalSyncMode = SYNC_MODE_QTOPIA;
2233 mCurrentSyncDevice = "qtopia-XML"; 2263 mCurrentSyncDevice = "qtopia-XML";
2234 if ( mSyncManager->mAskForPreferences ) 2264 if ( mSyncManager->mAskForPreferences )
2235 edit_sync_options(); 2265 edit_sync_options();
2236 qApp->processEvents(); 2266 qApp->processEvents();
2237 CalendarLocal* calendar = new CalendarLocal(); 2267 CalendarLocal* calendar = new CalendarLocal();
2238 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2268 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2239 bool syncOK = false; 2269 bool syncOK = false;
2240 QtopiaFormat qtopiaFormat; 2270 QtopiaFormat qtopiaFormat;
2241 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2271 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2242 bool loadOk = true; 2272 bool loadOk = true;
2243 if ( !categories.isEmpty() ) 2273 if ( !categories.isEmpty() )
2244 loadOk = qtopiaFormat.load( calendar, categories ); 2274 loadOk = qtopiaFormat.load( calendar, categories );
2245 if ( loadOk && !datebook.isEmpty() ) 2275 if ( loadOk && !datebook.isEmpty() )
2246 loadOk = qtopiaFormat.load( calendar, datebook ); 2276 loadOk = qtopiaFormat.load( calendar, datebook );
2247 if ( loadOk && !todolist.isEmpty() ) 2277 if ( loadOk && !todolist.isEmpty() )
2248 loadOk = qtopiaFormat.load( calendar, todolist ); 2278 loadOk = qtopiaFormat.load( calendar, todolist );
2249 2279
2250 if ( loadOk ) { 2280 if ( loadOk ) {
2251 getEventViewerDialog()->setSyncMode( true ); 2281 getEventViewerDialog()->setSyncMode( true );
2252 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2282 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2253 getEventViewerDialog()->setSyncMode( false ); 2283 getEventViewerDialog()->setSyncMode( false );
2254 qApp->processEvents(); 2284 qApp->processEvents();
2255 if ( syncOK ) { 2285 if ( syncOK ) {
2256 if ( mSyncManager->mWriteBackFile ) 2286 if ( mSyncManager->mWriteBackFile )
2257 { 2287 {
2258 // write back XML file 2288 // write back XML file
2259 2289
2260 } 2290 }
2261 setModified( true ); 2291 setModified( true );
2262 } 2292 }
2263 } else { 2293 } else {
2264 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2294 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2265 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2295 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2266 question, i18n("Ok")) ; 2296 question, i18n("Ok")) ;
2267 } 2297 }
2268 delete calendar; 2298 delete calendar;
2269 updateView(); 2299 updateView();
2270 return syncOK; 2300 return syncOK;
2271 2301
2272 2302
2273#endif 2303#endif
2274 2304
2275} 2305}
2276 2306
2277void CalendarView::setSyncEventsReadOnly() 2307void CalendarView::setSyncEventsReadOnly()
2278{ 2308{
2279 mCalendar->setSyncEventsReadOnly(); 2309 mCalendar->setSyncEventsReadOnly();
2280} 2310}
2281 2311
2282bool CalendarView::loadCalendars() 2312bool CalendarView::loadCalendars()
2283{ 2313{
2284 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2314 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2285 KopiCalendarFile * cal = calendars.first(); 2315 KopiCalendarFile * cal = calendars.first();
2286 mCalendar->setDefaultCalendar( 1 ); 2316 mCalendar->setDefaultCalendar( 1 );
2287 openCalendar( MainWindow::defaultFileName(), false ); 2317 openCalendar( MainWindow::defaultFileName(), false );
2288 cal = calendars.next(); 2318 cal = calendars.next();
2289 while ( cal ) { 2319 while ( cal ) {
2290 addCalendar( cal ); 2320 addCalendar( cal );
2291 cal = calendars.next(); 2321 cal = calendars.next();
2292 } 2322 }
2293 restoreCalendarSettings(); 2323 restoreCalendarSettings();
2294 return true; 2324 return true;
2295} 2325}
2296bool CalendarView::restoreCalendarSettings() 2326bool CalendarView::restoreCalendarSettings()
2297{ 2327{
2298 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2328 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2299 KopiCalendarFile * cal = calendars.first(); 2329 KopiCalendarFile * cal = calendars.first();
2300 while ( cal ) { 2330 while ( cal ) {
2301 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2331 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2302 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2332 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2303 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2333 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2304 if ( cal->isStandard ) 2334 if ( cal->isStandard )
2305 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2335 mCalendar->setDefaultCalendar( cal->mCalNumber );
2306 cal = calendars.next(); 2336 cal = calendars.next();
2307 } 2337 }
2308 setSyncEventsReadOnly(); 2338 setSyncEventsReadOnly();
2309 mCalendar->reInitAlarmSettings(); 2339 mCalendar->reInitAlarmSettings();
2310 updateUnmanagedViews(); 2340 updateUnmanagedViews();
2311 updateView(); 2341 updateView();
2312 return true; 2342 return true;
2313} 2343}
2314void CalendarView::addCalendarId( int id ) 2344void CalendarView::addCalendarId( int id )
2315{ 2345{
2316 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2346 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2317 if ( cal ) 2347 if ( cal )
2318 addCalendar( cal ); 2348 addCalendar( cal );
2319} 2349}
2320bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2350bool CalendarView::addCalendar( KopiCalendarFile * cal )
2321{ 2351{
2322 cal->mErrorOnLoad = false; 2352 cal->mErrorOnLoad = false;
2323 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2353 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2324 cal->mLoadDt = QDateTime::currentDateTime(); 2354 cal->mLoadDt = QDateTime::currentDateTime();
2325 return true; 2355 return true;
2326 } 2356 }
2327 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2357 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2328 cal->mErrorOnLoad = true; 2358 cal->mErrorOnLoad = true;
2329 return false; 2359 return false;
2330} 2360}
2331bool CalendarView::openCalendar(QString filename, bool merge) 2361bool CalendarView::openCalendar(QString filename, bool merge)
2332{ 2362{
2333 2363
2334 if (filename.isEmpty()) { 2364 if (filename.isEmpty()) {
2335 return false; 2365 return false;
2336 } 2366 }
2337 2367
2338 if (!QFile::exists(filename)) { 2368 if (!QFile::exists(filename)) {
2339 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2369 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2340 return false; 2370 return false;
2341 } 2371 }
2342 2372
2343 globalFlagBlockAgenda = 1; 2373 globalFlagBlockAgenda = 1;
2344 clearAllViews(); 2374 clearAllViews();
2345 if (!merge) { 2375 if (!merge) {
2346 mViewManager->setDocumentId( filename ); 2376 mViewManager->setDocumentId( filename );
2347 mCalendar->close(); 2377 mCalendar->close();
2348 } 2378 }
2349 mStorage->setFileName( filename ); 2379 mStorage->setFileName( filename );
2350 2380
2351 if ( mStorage->load() ) { 2381 if ( mStorage->load() ) {
2352 if ( merge ) ;//setModified( true ); 2382 if ( merge ) ;//setModified( true );
2353 else { 2383 else {
2354 //setModified( true ); 2384 //setModified( true );
2355 mViewManager->setDocumentId( filename ); 2385 mViewManager->setDocumentId( filename );
2356 mDialogManager->setDocumentId( filename ); 2386 mDialogManager->setDocumentId( filename );
2357 mTodoList->setDocumentId( filename ); 2387 mTodoList->setDocumentId( filename );
2358 } 2388 }
2359 globalFlagBlockAgenda = 2; 2389 globalFlagBlockAgenda = 2;
2360 // if ( getLastSyncEvent() ) 2390 // if ( getLastSyncEvent() )
2361 // getLastSyncEvent()->setReadOnly( true ); 2391 // getLastSyncEvent()->setReadOnly( true );
2362 mCalendar->reInitAlarmSettings(); 2392 mCalendar->reInitAlarmSettings();
2363 setSyncEventsReadOnly(); 2393 setSyncEventsReadOnly();
2364 updateUnmanagedViews(); 2394 updateUnmanagedViews();
2365 updateView(); 2395 updateView();
2366 if ( filename != MainWindow::defaultFileName() ) { 2396 if ( filename != MainWindow::defaultFileName() ) {
2367 saveCalendar( MainWindow::defaultFileName() ); 2397 saveCalendar( MainWindow::defaultFileName() );
2368 } else { 2398 } else {
2369 QFileInfo finf ( MainWindow::defaultFileName()); 2399 QFileInfo finf ( MainWindow::defaultFileName());
2370 if ( finf.exists() ) { 2400 if ( finf.exists() ) {
2371 setLoadedFileVersion( finf.lastModified () ); 2401 setLoadedFileVersion( finf.lastModified () );
2372 } 2402 }
2373 } 2403 }
2374 return true; 2404 return true;
2375 } else { 2405 } else {
2376 // while failing to load, the calendar object could 2406 // while failing to load, the calendar object could
2377 // have become partially populated. Clear it out. 2407 // have become partially populated. Clear it out.
2378 if ( !merge ) { 2408 if ( !merge ) {
2379 mCalendar->close(); 2409 mCalendar->close();
2380 mViewManager->setDocumentId( filename ); 2410 mViewManager->setDocumentId( filename );
2381 mDialogManager->setDocumentId( filename ); 2411 mDialogManager->setDocumentId( filename );
2382 mTodoList->setDocumentId( filename ); 2412 mTodoList->setDocumentId( filename );
2383 } 2413 }
2384 2414
2385 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2415 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2386 2416
2387 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2417 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2388 globalFlagBlockAgenda = 2; 2418 globalFlagBlockAgenda = 2;
2389 mCalendar->reInitAlarmSettings(); 2419 mCalendar->reInitAlarmSettings();
2390 setSyncEventsReadOnly(); 2420 setSyncEventsReadOnly();
2391 updateUnmanagedViews(); 2421 updateUnmanagedViews();
2392 updateView(); 2422 updateView();
2393 } 2423 }
2394 return false; 2424 return false;
2395} 2425}
2396void CalendarView::mergeFile( QString fn ) 2426void CalendarView::mergeFile( QString fn )
2397{ 2427{
2398 clearAllViews(); 2428 clearAllViews();
2399 mCalendar->mergeCalendarFile( fn ); 2429 mCalendar->mergeCalendarFile( fn );
2400 mCalendar->reInitAlarmSettings(); 2430 mCalendar->reInitAlarmSettings();
2401 setSyncEventsReadOnly(); 2431 setSyncEventsReadOnly();
2402 updateUnmanagedViews(); 2432 updateUnmanagedViews();
2403 updateView(); 2433 updateView();
2404} 2434}
2405void CalendarView::showOpenError() 2435void CalendarView::showOpenError()
2406{ 2436{
2407 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2437 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2408} 2438}
2409void CalendarView::setLoadedFileVersion(QDateTime dt) 2439void CalendarView::setLoadedFileVersion(QDateTime dt)
2410{ 2440{
2411 loadedFileVersion = dt; 2441 loadedFileVersion = dt;
2412} 2442}
2413bool CalendarView::checkFileChanged(QString fn) 2443bool CalendarView::checkFileChanged(QString fn)
2414{ 2444{
2415 QFileInfo finf ( fn ); 2445 QFileInfo finf ( fn );
2416 if ( !finf.exists() ) 2446 if ( !finf.exists() )
2417 return true; 2447 return true;
2418 QDateTime dt = finf.lastModified (); 2448 QDateTime dt = finf.lastModified ();
2419 if ( dt <= loadedFileVersion ) 2449 if ( dt <= loadedFileVersion )
2420 return false; 2450 return false;
2421 return true; 2451 return true;
2422 2452
2423} 2453}
2424void CalendarView::watchSavedFile() 2454void CalendarView::watchSavedFile()
2425{ 2455{
2426 QFileInfo finf ( MainWindow::defaultFileName()); 2456 QFileInfo finf ( MainWindow::defaultFileName());
2427 if ( !finf.exists() ) 2457 if ( !finf.exists() )
2428 return; 2458 return;
2429 QDateTime dt = finf.lastModified (); 2459 QDateTime dt = finf.lastModified ();
2430 if ( dt < loadedFileVersion ) { 2460 if ( dt < loadedFileVersion ) {
2431 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2461 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2432 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2462 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2433 return; 2463 return;
2434 } 2464 }
2435 loadedFileVersion = dt; 2465 loadedFileVersion = dt;
2436} 2466}
2437bool CalendarView::checkAllFileVersions() 2467bool CalendarView::checkAllFileVersions()
2438{ 2468{
2439 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2469 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2440 KopiCalendarFile * cal = calendars.first(); 2470 KopiCalendarFile * cal = calendars.first();
2441 mCalendar->setDefaultCalendar( 1 ); 2471 mCalendar->setDefaultCalendar( 1 );
2442 mCalendar->setDefaultCalendarEnabledOnly(); 2472 mCalendar->setDefaultCalendarEnabledOnly();
2443 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2473 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2444 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2474 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2445 restoreCalendarSettings(); 2475 restoreCalendarSettings();
2446 return false; 2476 return false;
2447 } 2477 }
2448 } 2478 }
2449 cal = calendars.next(); 2479 cal = calendars.next();
2450 QDateTime storeTemp = loadedFileVersion; 2480 QDateTime storeTemp = loadedFileVersion;
2451 while ( cal ) { 2481 while ( cal ) {
2452 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2482 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2453 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2483 mCalendar->setDefaultCalendar( cal->mCalNumber );
2454 mCalendar->setDefaultCalendarEnabledOnly(); 2484 mCalendar->setDefaultCalendarEnabledOnly();
2455 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2485 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2456 if ( !checkFileVersion(cal->mFileName )) { 2486 if ( !checkFileVersion(cal->mFileName )) {
2457 loadedFileVersion = storeTemp; 2487 loadedFileVersion = storeTemp;
2458 restoreCalendarSettings(); 2488 restoreCalendarSettings();
2459 return false; 2489 return false;
2460 } 2490 }
2461 } 2491 }
2462 cal = calendars.next(); 2492 cal = calendars.next();
2463 } 2493 }
2464 loadedFileVersion = storeTemp; 2494 loadedFileVersion = storeTemp;
2465 return true; 2495 return true;
2466} 2496}
2467bool CalendarView::checkFileVersion(QString fn) 2497bool CalendarView::checkFileVersion(QString fn)
2468{ 2498{
2469 QFileInfo finf ( fn ); 2499 QFileInfo finf ( fn );
2470 if ( !finf.exists() ) 2500 if ( !finf.exists() )
2471 return true; 2501 return true;
2472 QDateTime dt = finf.lastModified (); 2502 QDateTime dt = finf.lastModified ();
2473 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2503 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2474 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2504 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2475 if ( dt <= loadedFileVersion ) 2505 if ( dt <= loadedFileVersion )
2476 return true; 2506 return true;
2477 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)) , 2507 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)) ,
2478 i18n("KO/Pi Warning"),i18n("Overwrite"), 2508 i18n("KO/Pi Warning"),i18n("Overwrite"),
2479 i18n("Sync+save")); 2509 i18n("Sync+save"));
2480 2510
2481 if ( km == KMessageBox::Cancel ) 2511 if ( km == KMessageBox::Cancel )
2482 return false; 2512 return false;
2483 if ( km == KMessageBox::Yes ) 2513 if ( km == KMessageBox::Yes )
2484 return true; 2514 return true;
2485 2515
2486 setSyncDevice("deleteaftersync" ); 2516 setSyncDevice("deleteaftersync" );
2487 mSyncManager->mAskForPreferences = true; 2517 mSyncManager->mAskForPreferences = true;
2488 mSyncManager->mSyncAlgoPrefs = 3; 2518 mSyncManager->mSyncAlgoPrefs = 3;
2489 mSyncManager->mWriteBackFile = false; 2519 mSyncManager->mWriteBackFile = false;
2490 mSyncManager->mWriteBackExistingOnly = false; 2520 mSyncManager->mWriteBackExistingOnly = false;
2491 mSyncManager->mShowSyncSummary = false; 2521 mSyncManager->mShowSyncSummary = false;
2492 syncCalendar( fn, 3 ); 2522 syncCalendar( fn, 3 );
2493 Event * e = getLastSyncEvent(); 2523 Event * e = getLastSyncEvent();
2494 if ( e ) 2524 if ( e )
2495 mCalendar->deleteEvent( e ); 2525 mCalendar->deleteEvent( e );
2496 return true; 2526 return true;
2497} 2527}
2498bool CalendarView::saveCalendars() 2528bool CalendarView::saveCalendars()
2499{ 2529{
2500 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2530 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2501 KopiCalendarFile * cal = calendars.first(); 2531 KopiCalendarFile * cal = calendars.first();
2502 mCalendar->setDefaultCalendar( 1 ); 2532 mCalendar->setDefaultCalendar( 1 );
2503 mCalendar->setDefaultCalendarEnabledOnly(); 2533 mCalendar->setDefaultCalendarEnabledOnly();
2504 saveCalendar( MainWindow::defaultFileName() ); 2534 saveCalendar( MainWindow::defaultFileName() );
2505 cal = calendars.next(); 2535 cal = calendars.next();
2506 while ( cal ) { 2536 while ( cal ) {
2507 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2537 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2508 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2538 mCalendar->setDefaultCalendar( cal->mCalNumber );
2509 mCalendar->setDefaultCalendarEnabledOnly(); 2539 mCalendar->setDefaultCalendarEnabledOnly();
2510 if ( saveCalendar( cal->mFileName ) ) 2540 if ( saveCalendar( cal->mFileName ) )
2511 cal->mLoadDt = QDateTime::currentDateTime(); 2541 cal->mLoadDt = QDateTime::currentDateTime();
2512 } 2542 }
2513 cal = calendars.next(); 2543 cal = calendars.next();
2514 } 2544 }
2515 restoreCalendarSettings(); 2545 restoreCalendarSettings();
2516 return true; 2546 return true;
2517} 2547}
2518bool CalendarView::saveCalendar( QString filename ) 2548bool CalendarView::saveCalendar( QString filename )
2519{ 2549{
2520 2550
2521 // Store back all unsaved data into calendar object 2551 // Store back all unsaved data into calendar object
2522 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2552 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2523 if ( mViewManager->currentView() ) 2553 if ( mViewManager->currentView() )
2524 mViewManager->currentView()->flushView(); 2554 mViewManager->currentView()->flushView();
2525 2555
2526 2556
2527 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2557 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2528 mStorage->setSaveFormat( new ICalFormat() ); 2558 mStorage->setSaveFormat( new ICalFormat() );
2529 mStorage->setFileName( filename ); 2559 mStorage->setFileName( filename );
2530 bool success; 2560 bool success;
2531 success = mStorage->save(); 2561 success = mStorage->save();
2532 if ( !success ) { 2562 if ( !success ) {
2533 return false; 2563 return false;
2534 } 2564 }
2535 if ( filename == MainWindow::defaultFileName() ) { 2565 if ( filename == MainWindow::defaultFileName() ) {
2536 setLoadedFileVersion( lfv ); 2566 setLoadedFileVersion( lfv );
2537 watchSavedFile(); 2567 watchSavedFile();
2538 } 2568 }
2539 return true; 2569 return true;
2540} 2570}
2541 2571
2542void CalendarView::closeCalendar() 2572void CalendarView::closeCalendar()
2543{ 2573{
2544 2574
2545 // child windows no longer valid 2575 // child windows no longer valid
2546 clearAllViews(); 2576 clearAllViews();
2547 emit closingDown(); 2577 emit closingDown();
2548 2578
2549 mCalendar->close(); 2579 mCalendar->close();
2550 setModified(false); 2580 setModified(false);
2551 updateView(); 2581 updateView();
2552} 2582}
2553 2583
2554void CalendarView::archiveCalendar() 2584void CalendarView::archiveCalendar()
2555{ 2585{
2556 mDialogManager->showArchiveDialog(); 2586 mDialogManager->showArchiveDialog();
2557} 2587}
2558 2588
2559 2589
2560void CalendarView::readSettings() 2590void CalendarView::readSettings()
2561{ 2591{
2562 2592
2563 2593
2564 // mViewManager->showAgendaView(); 2594 // mViewManager->showAgendaView();
2565 QString str; 2595 QString str;
2566 //qDebug("CalendarView::readSettings() "); 2596 //qDebug("CalendarView::readSettings() ");
2567 // read settings from the KConfig, supplying reasonable 2597 // read settings from the KConfig, supplying reasonable
2568 // defaults where none are to be found 2598 // defaults where none are to be found
2569 KConfig *config = KOGlobals::config(); 2599 KConfig *config = KOGlobals::config();
2570#ifndef KORG_NOSPLITTER 2600#ifndef KORG_NOSPLITTER
2571 config->setGroup("KOrganizer Geometry"); 2601 config->setGroup("KOrganizer Geometry");
2572 2602
2573 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2603 QValueList<int> sizes = config->readIntListEntry("Separator1");
2574 if (sizes.count() != 2) { 2604 if (sizes.count() != 2) {
2575 sizes << mDateNavigator->minimumSizeHint().width(); 2605 sizes << mDateNavigator->minimumSizeHint().width();
2576 sizes << 300; 2606 sizes << 300;
2577 } 2607 }
2578 mPanner->setSizes(sizes); 2608 mPanner->setSizes(sizes);
2579 2609
2580 sizes = config->readIntListEntry("Separator2"); 2610 sizes = config->readIntListEntry("Separator2");
2581 if ( ( mResourceView && sizes.count() == 4 ) || 2611 if ( ( mResourceView && sizes.count() == 4 ) ||
2582 ( !mResourceView && sizes.count() == 3 ) ) { 2612 ( !mResourceView && sizes.count() == 3 ) ) {
2583 mLeftSplitter->setSizes(sizes); 2613 mLeftSplitter->setSizes(sizes);
2584 } 2614 }
2585#endif 2615#endif
2586 globalFlagBlockAgenda = 1; 2616 globalFlagBlockAgenda = 1;
2587 mViewManager->showAgendaView(); 2617 mViewManager->showAgendaView();
2588 //mViewManager->readSettings( config ); 2618 //mViewManager->readSettings( config );
2589 mTodoList->restoreLayout(config,QString("Todo Layout")); 2619 mTodoList->restoreLayout(config,QString("Todo Layout"));
2590 readFilterSettings(config); 2620 readFilterSettings(config);
2591 2621
2592#ifdef DESKTOP_VERSION 2622#ifdef DESKTOP_VERSION
2593 config->setGroup("WidgetLayout"); 2623 config->setGroup("WidgetLayout");
2594 QStringList list; 2624 QStringList list;
2595 list = config->readListEntry("MainLayout"); 2625 list = config->readListEntry("MainLayout");
2596 int x,y,w,h; 2626 int x,y,w,h;
2597 if ( ! list.isEmpty() ) { 2627 if ( ! list.isEmpty() ) {
2598 x = list[0].toInt(); 2628 x = list[0].toInt();
2599 y = list[1].toInt(); 2629 y = list[1].toInt();
2600 w = list[2].toInt(); 2630 w = list[2].toInt();
2601 h = list[3].toInt(); 2631 h = list[3].toInt();
2602 KApplication::testCoords( &x,&y,&w,&h ); 2632 KApplication::testCoords( &x,&y,&w,&h );
2603 topLevelWidget()->setGeometry(x,y,w,h); 2633 topLevelWidget()->setGeometry(x,y,w,h);
2604 2634
2605 } else { 2635 } else {
2606 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2636 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2607 } 2637 }
2608 list = config->readListEntry("EditEventLayout"); 2638 list = config->readListEntry("EditEventLayout");
2609 if ( ! list.isEmpty() ) { 2639 if ( ! list.isEmpty() ) {
2610 x = list[0].toInt(); 2640 x = list[0].toInt();
2611 y = list[1].toInt(); 2641 y = list[1].toInt();
2612 w = list[2].toInt(); 2642 w = list[2].toInt();
2613 h = list[3].toInt(); 2643 h = list[3].toInt();
2614 KApplication::testCoords( &x,&y,&w,&h ); 2644 KApplication::testCoords( &x,&y,&w,&h );
2615 mEventEditor->setGeometry(x,y,w,h); 2645 mEventEditor->setGeometry(x,y,w,h);
2616 2646
2617 } 2647 }
2618 list = config->readListEntry("EditTodoLayout"); 2648 list = config->readListEntry("EditTodoLayout");
2619 if ( ! list.isEmpty() ) { 2649 if ( ! list.isEmpty() ) {
2620 x = list[0].toInt(); 2650 x = list[0].toInt();
2621 y = list[1].toInt(); 2651 y = list[1].toInt();
2622 w = list[2].toInt(); 2652 w = list[2].toInt();
2623 h = list[3].toInt(); 2653 h = list[3].toInt();
2624 KApplication::testCoords( &x,&y,&w,&h ); 2654 KApplication::testCoords( &x,&y,&w,&h );
2625 mTodoEditor->setGeometry(x,y,w,h); 2655 mTodoEditor->setGeometry(x,y,w,h);
2626 2656
2627 } 2657 }
2628 list = config->readListEntry("ViewerLayout"); 2658 list = config->readListEntry("ViewerLayout");
2629 if ( ! list.isEmpty() ) { 2659 if ( ! list.isEmpty() ) {
2630 x = list[0].toInt(); 2660 x = list[0].toInt();
2631 y = list[1].toInt(); 2661 y = list[1].toInt();
2632 w = list[2].toInt(); 2662 w = list[2].toInt();
2633 h = list[3].toInt(); 2663 h = list[3].toInt();
2634 KApplication::testCoords( &x,&y,&w,&h ); 2664 KApplication::testCoords( &x,&y,&w,&h );
2635 getEventViewerDialog()->setGeometry(x,y,w,h); 2665 getEventViewerDialog()->setGeometry(x,y,w,h);
2636 } 2666 }
2637#endif 2667#endif
2638 config->setGroup( "Views" ); 2668 config->setGroup( "Views" );
2639 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2669 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2640 2670
2641 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2671 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2642 2672
2643 int resetval = 0; 2673 int resetval = 0;
2644 int maxVal = 0; 2674 int maxVal = 0;
2645 if (sizes.count() != 3) { 2675 if (sizes.count() != 3) {
2646 if ( KOPrefs::instance()->mVerticalScreen ) { 2676 if ( KOPrefs::instance()->mVerticalScreen ) {
2647 resetval = mDateNavigator->sizeHint().width()+2; 2677 resetval = mDateNavigator->sizeHint().width()+2;
2648 } else { 2678 } else {
2649 resetval = mDateNavigator->sizeHint().height()+2; 2679 resetval = mDateNavigator->sizeHint().height()+2;
2650 } 2680 }
2651 } 2681 }
2652 if ( resetval ) { 2682 if ( resetval ) {
2653 sizes.clear(); 2683 sizes.clear();
2654 if ( KOPrefs::instance()->mVerticalScreen ) { 2684 if ( KOPrefs::instance()->mVerticalScreen ) {
2655 maxVal = QApplication::desktop()->width() -10; 2685 maxVal = QApplication::desktop()->width() -10;
2656 } else { 2686 } else {
2657 maxVal = QApplication::desktop()->height()-10; 2687 maxVal = QApplication::desktop()->height()-10;
2658 } 2688 }
2659 sizes << resetval; 2689 sizes << resetval;
2660 if ( maxVal < resetval + resetval) 2690 if ( maxVal < resetval + resetval)
2661 resetval = maxVal - resetval; 2691 resetval = maxVal - resetval;
2662 sizes << resetval; 2692 sizes << resetval;
2663 sizes << 100; 2693 sizes << 100;
2664 } 2694 }
2665 mLeftFrame->setSizes(sizes); 2695 mLeftFrame->setSizes(sizes);
2666 sizes = config->readIntListEntry("Main Splitter Frame"); 2696 sizes = config->readIntListEntry("Main Splitter Frame");
2667 resetval = 0; 2697 resetval = 0;
2668 maxVal = 0; 2698 maxVal = 0;
2669 if (sizes.count() != 2) { 2699 if (sizes.count() != 2) {
2670 if ( !KOPrefs::instance()->mVerticalScreen ) { 2700 if ( !KOPrefs::instance()->mVerticalScreen ) {
2671 resetval = mDateNavigator->sizeHint().width()+2; 2701 resetval = mDateNavigator->sizeHint().width()+2;
2672 } else { 2702 } else {
2673 resetval = mDateNavigator->sizeHint().height()+2; 2703 resetval = mDateNavigator->sizeHint().height()+2;
2674 } 2704 }
2675 } 2705 }
2676 if ( resetval ) { 2706 if ( resetval ) {
2677 sizes.clear(); 2707 sizes.clear();
2678 if ( !KOPrefs::instance()->mVerticalScreen ) { 2708 if ( !KOPrefs::instance()->mVerticalScreen ) {
2679 maxVal = QApplication::desktop()->width() -10; 2709 maxVal = QApplication::desktop()->width() -10;
2680 } else { 2710 } else {
2681 maxVal = QApplication::desktop()->height()-10; 2711 maxVal = QApplication::desktop()->height()-10;
2682 } 2712 }
2683 sizes << resetval; 2713 sizes << resetval;
2684 if ( maxVal < resetval + resetval) 2714 if ( maxVal < resetval + resetval)
2685 resetval = maxVal - resetval; 2715 resetval = maxVal - resetval;
2686 sizes << resetval; 2716 sizes << resetval;
2687 } 2717 }
2688 mMainFrame->setSizes(sizes); 2718 mMainFrame->setSizes(sizes);
2689 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2719 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2690 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2720 else if ( dateCount == 7 ) mNavigator->selectWeek();
2691 else mNavigator->selectDates( dateCount ); 2721 else mNavigator->selectDates( dateCount );
2692 // mViewManager->readSettings( config ); 2722 // mViewManager->readSettings( config );
2693 updateConfig(); 2723 updateConfig();
2694 globalFlagBlockAgenda = 2; 2724 globalFlagBlockAgenda = 2;
2695 mViewManager->readSettings( config ); 2725 mViewManager->readSettings( config );
2696 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2726 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2697} 2727}
2698 2728
2699void CalendarView::checkSuspendAlarm() 2729void CalendarView::checkSuspendAlarm()
2700{ 2730{
2701 if ( mSuspendTimer->isActive() ) { 2731 if ( mSuspendTimer->isActive() ) {
2702 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2732 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2703 } 2733 }
2704} 2734}
2705void CalendarView::writeSettings() 2735void CalendarView::writeSettings()
2706{ 2736{
2707 // kdDebug() << "CalendarView::writeSettings" << endl; 2737 // kdDebug() << "CalendarView::writeSettings" << endl;
2708 2738
2709 KConfig *config = KOGlobals::config(); 2739 KConfig *config = KOGlobals::config();
2710 2740
2711 mViewManager->writeSettings( config ); 2741 mViewManager->writeSettings( config );
2712 mTodoList->saveLayout(config,QString("Todo Layout")); 2742 mTodoList->saveLayout(config,QString("Todo Layout"));
2713 mDialogManager->writeSettings( config ); 2743 mDialogManager->writeSettings( config );
2714 //KOPrefs::instance()->usrWriteConfig(); 2744 //KOPrefs::instance()->usrWriteConfig();
2715 KOPrefs::instance()->writeConfig(); 2745 KOPrefs::instance()->writeConfig();
2716 2746
2717 writeFilterSettings(config); 2747 writeFilterSettings(config);
2718 config->setGroup( "AppRun" ); 2748 config->setGroup( "AppRun" );
2719 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2749 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2720 int days = dt.daysTo( QDate::currentDate() ); 2750 int days = dt.daysTo( QDate::currentDate() );
2721 dt = dt.addDays( days ); 2751 dt = dt.addDays( days );
2722 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2752 int secs = dt.secsTo( QDateTime::currentDateTime() );
2723 config->writeEntry( "LatestProgramStopDays", days ); 2753 config->writeEntry( "LatestProgramStopDays", days );
2724 config->writeEntry( "LatestProgramStopSecs", secs ); 2754 config->writeEntry( "LatestProgramStopSecs", secs );
2725 //qDebug("KO: Writing stop time: %d ", secs); 2755 //qDebug("KO: Writing stop time: %d ", secs);
2726 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2756 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2727 //QDateTime latest = dt.addSecs ( secs ); 2757 //QDateTime latest = dt.addSecs ( secs );
2728 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2758 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2729 config->setGroup( "Views" ); 2759 config->setGroup( "Views" );
2730 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2760 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2731 2761
2732#if 0 2762#if 0
2733 qDebug("********************* "); 2763 qDebug("********************* ");
2734 qDebug("Testcode secsto "); 2764 qDebug("Testcode secsto ");
2735 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2765 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2736 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2766 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2737 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2767 int secsto = dt_nodaylight.secsTo( dt_daylight );
2738 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2768 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2739 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2769 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2740 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2770 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2741 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2771 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2742 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2772 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2743 qDebug("********************* testcode end"); 2773 qDebug("********************* testcode end");
2744 2774
2745#endif 2775#endif
2746 2776
2747 QValueList<int> listINT = mLeftFrame->sizes(); 2777 QValueList<int> listINT = mLeftFrame->sizes();
2748 config->writeEntry("Left Splitter Frame",listINT); 2778 config->writeEntry("Left Splitter Frame",listINT);
2749 QValueList<int> listINT2 = mMainFrame->sizes(); 2779 QValueList<int> listINT2 = mMainFrame->sizes();
2750 config->writeEntry("Main Splitter Frame",listINT2); 2780 config->writeEntry("Main Splitter Frame",listINT2);
2751#ifdef DESKTOP_VERSION 2781#ifdef DESKTOP_VERSION
2752 config->setGroup("WidgetLayout"); 2782 config->setGroup("WidgetLayout");
2753 QStringList list ;//= config->readListEntry("MainLayout"); 2783 QStringList list ;//= config->readListEntry("MainLayout");
2754 int x,y,w,h; 2784 int x,y,w,h;
2755 QWidget* wid; 2785 QWidget* wid;
2756 wid = topLevelWidget(); 2786 wid = topLevelWidget();
2757 x = wid->geometry().x(); 2787 x = wid->geometry().x();
2758 y = wid->geometry().y(); 2788 y = wid->geometry().y();
2759 w = wid->width(); 2789 w = wid->width();
2760 h = wid->height(); 2790 h = wid->height();
2761 list.clear(); 2791 list.clear();
2762 list << QString::number( x ); 2792 list << QString::number( x );
2763 list << QString::number( y ); 2793 list << QString::number( y );
2764 list << QString::number( w ); 2794 list << QString::number( w );
2765 list << QString::number( h ); 2795 list << QString::number( h );
2766 config->writeEntry("MainLayout",list ); 2796 config->writeEntry("MainLayout",list );
2767 2797
2768 wid = mEventEditor; 2798 wid = mEventEditor;
2769 x = wid->geometry().x(); 2799 x = wid->geometry().x();
2770 y = wid->geometry().y(); 2800 y = wid->geometry().y();
2771 w = wid->width(); 2801 w = wid->width();
2772 h = wid->height(); 2802 h = wid->height();
2773 list.clear(); 2803 list.clear();
2774 list << QString::number( x ); 2804 list << QString::number( x );
2775 list << QString::number( y ); 2805 list << QString::number( y );
2776 list << QString::number( w ); 2806 list << QString::number( w );
2777 list << QString::number( h ); 2807 list << QString::number( h );
2778 config->writeEntry("EditEventLayout",list ); 2808 config->writeEntry("EditEventLayout",list );
2779 2809
2780 wid = mTodoEditor; 2810 wid = mTodoEditor;
2781 x = wid->geometry().x(); 2811 x = wid->geometry().x();
2782 y = wid->geometry().y(); 2812 y = wid->geometry().y();
2783 w = wid->width(); 2813 w = wid->width();
2784 h = wid->height(); 2814 h = wid->height();
2785 list.clear(); 2815 list.clear();
2786 list << QString::number( x ); 2816 list << QString::number( x );
2787 list << QString::number( y ); 2817 list << QString::number( y );
2788 list << QString::number( w ); 2818 list << QString::number( w );
2789 list << QString::number( h ); 2819 list << QString::number( h );
2790 config->writeEntry("EditTodoLayout",list ); 2820 config->writeEntry("EditTodoLayout",list );
2791 wid = getEventViewerDialog(); 2821 wid = getEventViewerDialog();
2792 x = wid->geometry().x(); 2822 x = wid->geometry().x();
2793 y = wid->geometry().y(); 2823 y = wid->geometry().y();
2794 w = wid->width(); 2824 w = wid->width();
2795 h = wid->height(); 2825 h = wid->height();
2796 list.clear(); 2826 list.clear();
2797 list << QString::number( x ); 2827 list << QString::number( x );
2798 list << QString::number( y ); 2828 list << QString::number( y );
2799 list << QString::number( w ); 2829 list << QString::number( w );
2800 list << QString::number( h ); 2830 list << QString::number( h );
2801 config->writeEntry("ViewerLayout",list ); 2831 config->writeEntry("ViewerLayout",list );
2802 wid = mDialogManager->getSearchDialog(); 2832 wid = mDialogManager->getSearchDialog();
2803 if ( wid ) { 2833 if ( wid ) {
2804 x = wid->geometry().x(); 2834 x = wid->geometry().x();
2805 y = wid->geometry().y(); 2835 y = wid->geometry().y();
2806 w = wid->width(); 2836 w = wid->width();
2807 h = wid->height(); 2837 h = wid->height();
2808 list.clear(); 2838 list.clear();
2809 list << QString::number( x ); 2839 list << QString::number( x );
2810 list << QString::number( y ); 2840 list << QString::number( y );
2811 list << QString::number( w ); 2841 list << QString::number( w );
2812 list << QString::number( h ); 2842 list << QString::number( h );
2813 config->writeEntry("SearchLayout",list ); 2843 config->writeEntry("SearchLayout",list );
2814 } 2844 }
2815#endif 2845#endif
2816 2846