summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a9d42f0..28649d9 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,1864 +1,1868 @@
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 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 840 static bool firstTime = true;
841 if ( firstTime ) {
842 firstTime = false;
843 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
844 }
841} 845}
842void CalendarView::checkAlarms() 846void CalendarView::checkAlarms()
843{ 847{
844 848
845 849
846 KConfig *config = KOGlobals::config(); 850 KConfig *config = KOGlobals::config();
847 config->setGroup( "AppRun" ); 851 config->setGroup( "AppRun" );
848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 852 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
849 int daysto = dt.daysTo( QDate::currentDate() ); 853 int daysto = dt.daysTo( QDate::currentDate() );
850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 854 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
851 dt = dt.addDays( days ); 855 dt = dt.addDays( days );
852 int secto = dt.secsTo( QDateTime::currentDateTime() ); 856 int secto = dt.secsTo( QDateTime::currentDateTime() );
853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 857 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
854 //qDebug("KO: Reading program stop %d ", secs); 858 //qDebug("KO: Reading program stop %d ", secs);
855 //secs -= ( 3600 * 24*3 ); // debug only 859 //secs -= ( 3600 * 24*3 ); // debug only
856 QDateTime latest = dt.addSecs ( secs ); 860 QDateTime latest = dt.addSecs ( secs );
857 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 861 qDebug("KO: Last termination on %s ", latest.toString().latin1());
858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 862 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
859 QPtrList<Incidence> el = mCalendar->rawIncidences(); 863 QPtrList<Incidence> el = mCalendar->rawIncidences();
860 QPtrList<Incidence> al; 864 QPtrList<Incidence> al;
861 Incidence* inL = el.first(); 865 Incidence* inL = el.first();
862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 866 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 867 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
864 while ( inL ) { 868 while ( inL ) {
865 bool ok = false; 869 bool ok = false;
866 int offset = 0; 870 int offset = 0;
867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 871 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
868 if ( ok ) { 872 if ( ok ) {
869 //qDebug("OK %s",next.toString().latin1()); 873 //qDebug("OK %s",next.toString().latin1());
870 if ( next < cur ) { 874 if ( next < cur ) {
871 al.append( inL ); 875 al.append( inL );
872 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 876 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
873 } 877 }
874 } 878 }
875 inL = el.next(); 879 inL = el.next();
876 } 880 }
877 if ( al.count() ) { 881 if ( al.count() ) {
878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 882 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
879 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 883 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
880 QVBoxLayout* lay = new QVBoxLayout( dia ); 884 QVBoxLayout* lay = new QVBoxLayout( dia );
881 lay->setSpacing( 0 ); 885 lay->setSpacing( 0 );
882 lay->setMargin( 0 ); 886 lay->setMargin( 0 );
883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 887 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 888 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
885 lay->addWidget( matb ); 889 lay->addWidget( matb );
886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 890 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
887 int wid = 210; 891 int wid = 210;
888 int x = QApplication::desktop()->width() - wid - 7; 892 int x = QApplication::desktop()->width() - wid - 7;
889 int y = QApplication::desktop()->height() - wid - 70; 893 int y = QApplication::desktop()->height() - wid - 70;
890 dia->setGeometry ( x,y,wid,wid); 894 dia->setGeometry ( x,y,wid,wid);
891 } else { 895 } else {
892 int si = 220; 896 int si = 220;
893 if ( QApplication::desktop()->width() > 470 ) 897 if ( QApplication::desktop()->width() > 470 )
894 si = 400; 898 si = 400;
895 dia->resize(si,si/2); 899 dia->resize(si,si/2);
896 } 900 }
897 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 901 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
898 dia->show(); 902 dia->show();
899 903
900 } 904 }
901} 905}
902void CalendarView::showDay( QDate d ) 906void CalendarView::showDay( QDate d )
903{ 907{
904 dateNavigator()->blockSignals( true ); 908 dateNavigator()->blockSignals( true );
905 dateNavigator()->selectDate( d ); 909 dateNavigator()->selectDate( d );
906 dateNavigator()->blockSignals( false ); 910 dateNavigator()->blockSignals( false );
907 mViewManager->showDayView(); 911 mViewManager->showDayView();
908 //dateNavigator()->selectDate( d ); 912 //dateNavigator()->selectDate( d );
909} 913}
910void CalendarView::timerAlarm() 914void CalendarView::timerAlarm()
911{ 915{
912 //qDebug("CalendarView::timerAlarm() "); 916 //qDebug("CalendarView::timerAlarm() ");
913 computeAlarm(mAlarmNotification ); 917 computeAlarm(mAlarmNotification );
914} 918}
915 919
916void CalendarView::suspendAlarm() 920void CalendarView::suspendAlarm()
917{ 921{
918 //qDebug(" CalendarView::suspendAlarm() "); 922 //qDebug(" CalendarView::suspendAlarm() ");
919 computeAlarm(mSuspendAlarmNotification ); 923 computeAlarm(mSuspendAlarmNotification );
920 924
921} 925}
922 926
923void CalendarView::startAlarm( QString mess , QString filename) 927void CalendarView::startAlarm( QString mess , QString filename)
924{ 928{
925 929
926 topLevelWidget()->showNormal(); 930 topLevelWidget()->showNormal();
927 topLevelWidget()->setActiveWindow(); 931 topLevelWidget()->setActiveWindow();
928 topLevelWidget()->raise(); 932 topLevelWidget()->raise();
929 933
930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 934 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 935 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
932 936
933} 937}
934 938
935void CalendarView::checkNextTimerAlarm() 939void CalendarView::checkNextTimerAlarm()
936{ 940{
937 mCalendar->checkAlarmForIncidence( 0, true ); 941 mCalendar->checkAlarmForIncidence( 0, true );
938} 942}
939 943
940void CalendarView::computeAlarm( QString msg ) 944void CalendarView::computeAlarm( QString msg )
941{ 945{
942 946
943 QString mess = msg; 947 QString mess = msg;
944 QString mAlarmMessage = mess.mid( 9 ); 948 QString mAlarmMessage = mess.mid( 9 );
945 QString filename = MainWindow::resourcePath(); 949 QString filename = MainWindow::resourcePath();
946 filename += "koalarm.wav"; 950 filename += "koalarm.wav";
947 QString tempfilename; 951 QString tempfilename;
948 if ( mess.left( 13 ) == "suspend_alarm") { 952 if ( mess.left( 13 ) == "suspend_alarm") {
949 bool error = false; 953 bool error = false;
950 int len = mess.mid( 13 ).find("+++"); 954 int len = mess.mid( 13 ).find("+++");
951 if ( len < 2 ) 955 if ( len < 2 )
952 error = true; 956 error = true;
953 else { 957 else {
954 tempfilename = mess.mid( 13, len ); 958 tempfilename = mess.mid( 13, len );
955 if ( !QFile::exists( tempfilename ) ) 959 if ( !QFile::exists( tempfilename ) )
956 error = true; 960 error = true;
957 } 961 }
958 if ( ! error ) { 962 if ( ! error ) {
959 filename = tempfilename; 963 filename = tempfilename;
960 } 964 }
961 mAlarmMessage = mess.mid( 13+len+3 ); 965 mAlarmMessage = mess.mid( 13+len+3 );
962 //qDebug("suspend file %s ",tempfilename.latin1() ); 966 //qDebug("suspend file %s ",tempfilename.latin1() );
963 startAlarm( mAlarmMessage, filename); 967 startAlarm( mAlarmMessage, filename);
964 return; 968 return;
965 } 969 }
966 if ( mess.left( 11 ) == "timer_alarm") { 970 if ( mess.left( 11 ) == "timer_alarm") {
967 //mTimerTime = 0; 971 //mTimerTime = 0;
968 startAlarm( mess.mid( 11 ), filename ); 972 startAlarm( mess.mid( 11 ), filename );
969 return; 973 return;
970 } 974 }
971 if ( mess.left( 10 ) == "proc_alarm") { 975 if ( mess.left( 10 ) == "proc_alarm") {
972 bool error = false; 976 bool error = false;
973 int len = mess.mid( 10 ).find("+++"); 977 int len = mess.mid( 10 ).find("+++");
974 if ( len < 2 ) 978 if ( len < 2 )
975 error = true; 979 error = true;
976 else { 980 else {
977 tempfilename = mess.mid( 10, len ); 981 tempfilename = mess.mid( 10, len );
978 if ( !QFile::exists( tempfilename ) ) 982 if ( !QFile::exists( tempfilename ) )
979 error = true; 983 error = true;
980 } 984 }
981 if ( error ) { 985 if ( error ) {
982 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 986 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
983 mAlarmMessage += mess.mid( 10+len+3+9 ); 987 mAlarmMessage += mess.mid( 10+len+3+9 );
984 } else { 988 } else {
985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 989 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
986 //qDebug("-----system command %s ",tempfilename.latin1() ); 990 //qDebug("-----system command %s ",tempfilename.latin1() );
987#ifndef _WIN32_ 991#ifndef _WIN32_
988 if ( vfork () == 0 ) { 992 if ( vfork () == 0 ) {
989 execl ( tempfilename.latin1(), 0 ); 993 execl ( tempfilename.latin1(), 0 );
990 return; 994 return;
991 } 995 }
992#else 996#else
993 QProcess* p = new QProcess(); 997 QProcess* p = new QProcess();
994 p->addArgument( tempfilename.latin1() ); 998 p->addArgument( tempfilename.latin1() );
995 p->start(); 999 p->start();
996 return; 1000 return;
997#endif 1001#endif
998 1002
999 return; 1003 return;
1000 } 1004 }
1001 1005
1002 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1006 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1003 } 1007 }
1004 if ( mess.left( 11 ) == "audio_alarm") { 1008 if ( mess.left( 11 ) == "audio_alarm") {
1005 bool error = false; 1009 bool error = false;
1006 int len = mess.mid( 11 ).find("+++"); 1010 int len = mess.mid( 11 ).find("+++");
1007 if ( len < 2 ) 1011 if ( len < 2 )
1008 error = true; 1012 error = true;
1009 else { 1013 else {
1010 tempfilename = mess.mid( 11, len ); 1014 tempfilename = mess.mid( 11, len );
1011 if ( !QFile::exists( tempfilename ) ) 1015 if ( !QFile::exists( tempfilename ) )
1012 error = true; 1016 error = true;
1013 } 1017 }
1014 if ( ! error ) { 1018 if ( ! error ) {
1015 filename = tempfilename; 1019 filename = tempfilename;
1016 } 1020 }
1017 mAlarmMessage = mess.mid( 11+len+3+9 ); 1021 mAlarmMessage = mess.mid( 11+len+3+9 );
1018 //qDebug("audio file command %s ",tempfilename.latin1() ); 1022 //qDebug("audio file command %s ",tempfilename.latin1() );
1019 } 1023 }
1020 if ( mess.left( 9 ) == "cal_alarm") { 1024 if ( mess.left( 9 ) == "cal_alarm") {
1021 mAlarmMessage = mess.mid( 9 ) ; 1025 mAlarmMessage = mess.mid( 9 ) ;
1022 } 1026 }
1023 1027
1024 startAlarm( mAlarmMessage, filename ); 1028 startAlarm( mAlarmMessage, filename );
1025 1029
1026 1030
1027} 1031}
1028 1032
1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1033void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1030{ 1034{
1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1035 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1032 1036
1033 mSuspendAlarmNotification = noti; 1037 mSuspendAlarmNotification = noti;
1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1038 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1039 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1036 mSuspendTimer->start( ms , true ); 1040 mSuspendTimer->start( ms , true );
1037 1041
1038} 1042}
1039 1043
1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1044void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1041{ 1045{
1042 mNextAlarmDateTime = qdt; 1046 mNextAlarmDateTime = qdt;
1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1047 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1048 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1045#ifndef DESKTOP_VERSION 1049#ifndef DESKTOP_VERSION
1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1050 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1047#endif 1051#endif
1048 return; 1052 return;
1049 } 1053 }
1050 int maxSec; 1054 int maxSec;
1051 //maxSec = 5; //testing only 1055 //maxSec = 5; //testing only
1052 maxSec = 86400+3600; // one day+1hour 1056 maxSec = 86400+3600; // one day+1hour
1053 mAlarmNotification = noti; 1057 mAlarmNotification = noti;
1054 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1058 int sec = QDateTime::currentDateTime().secsTo( qdt );
1055 if ( sec > maxSec ) { 1059 if ( sec > maxSec ) {
1056 mRecheckAlarmTimer->start( maxSec * 1000 ); 1060 mRecheckAlarmTimer->start( maxSec * 1000 );
1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1061 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1058 return; 1062 return;
1059 } else { 1063 } else {
1060 mRecheckAlarmTimer->stop(); 1064 mRecheckAlarmTimer->stop();
1061 } 1065 }
1062 //qDebug("Alarm timer started with secs: %d ", sec); 1066 //qDebug("Alarm timer started with secs: %d ", sec);
1063 mAlarmTimer->start( sec *1000 , true ); 1067 mAlarmTimer->start( sec *1000 , true );
1064 1068
1065} 1069}
1066// called by mRecheckAlarmTimer to get next alarm 1070// called by mRecheckAlarmTimer to get next alarm
1067// we need this, because a QTimer has only a max range of 25 days 1071// we need this, because a QTimer has only a max range of 25 days
1068void CalendarView::recheckTimerAlarm() 1072void CalendarView::recheckTimerAlarm()
1069{ 1073{
1070 mAlarmTimer->stop(); 1074 mAlarmTimer->stop();
1071 mRecheckAlarmTimer->stop(); 1075 mRecheckAlarmTimer->stop();
1072 mCalendar->checkAlarmForIncidence( 0, true ); 1076 mCalendar->checkAlarmForIncidence( 0, true );
1073} 1077}
1074#ifndef DESKTOP_VERSION 1078#ifndef DESKTOP_VERSION
1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1079void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1076#else 1080#else
1077void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1081void CalendarView::removeAlarm(const QDateTime &, const QString & )
1078#endif 1082#endif
1079{ 1083{
1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1084 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1085 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1082#ifndef DESKTOP_VERSION 1086#ifndef DESKTOP_VERSION
1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1087 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1084#endif 1088#endif
1085 return; 1089 return;
1086 } 1090 }
1087 mAlarmTimer->stop(); 1091 mAlarmTimer->stop();
1088} 1092}
1089void CalendarView::selectWeekNum ( int num ) 1093void CalendarView::selectWeekNum ( int num )
1090{ 1094{
1091 dateNavigator()->blockSignals( true ); 1095 dateNavigator()->blockSignals( true );
1092 dateNavigator()->selectWeek( num ); 1096 dateNavigator()->selectWeek( num );
1093 dateNavigator()->blockSignals( false ); 1097 dateNavigator()->blockSignals( false );
1094 mViewManager->showWeekView(); 1098 mViewManager->showWeekView();
1095} 1099}
1096KOViewManager *CalendarView::viewManager() 1100KOViewManager *CalendarView::viewManager()
1097{ 1101{
1098 return mViewManager; 1102 return mViewManager;
1099} 1103}
1100 1104
1101KODialogManager *CalendarView::dialogManager() 1105KODialogManager *CalendarView::dialogManager()
1102{ 1106{
1103 return mDialogManager; 1107 return mDialogManager;
1104} 1108}
1105 1109
1106QDate CalendarView::startDate() 1110QDate CalendarView::startDate()
1107{ 1111{
1108 DateList dates = mNavigator->selectedDates(); 1112 DateList dates = mNavigator->selectedDates();
1109 1113
1110 return dates.first(); 1114 return dates.first();
1111} 1115}
1112 1116
1113QDate CalendarView::endDate() 1117QDate CalendarView::endDate()
1114{ 1118{
1115 DateList dates = mNavigator->selectedDates(); 1119 DateList dates = mNavigator->selectedDates();
1116 1120
1117 return dates.last(); 1121 return dates.last();
1118} 1122}
1119 1123
1120 1124
1121void CalendarView::createPrinter() 1125void CalendarView::createPrinter()
1122{ 1126{
1123#ifndef KORG_NOPRINTER 1127#ifndef KORG_NOPRINTER
1124 if (!mCalPrinter) { 1128 if (!mCalPrinter) {
1125 mCalPrinter = new CalPrinter(this, mCalendar); 1129 mCalPrinter = new CalPrinter(this, mCalendar);
1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1130 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1127 } 1131 }
1128#endif 1132#endif
1129} 1133}
1130 1134
1131 1135
1132//KOPrefs::instance()->mWriteBackFile 1136//KOPrefs::instance()->mWriteBackFile
1133//KOPrefs::instance()->mWriteBackExistingOnly 1137//KOPrefs::instance()->mWriteBackExistingOnly
1134 1138
1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1139// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1140// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1141// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1142// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1143// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1144// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1141 1145
1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1146int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1143{ 1147{
1144 1148
1145 // 0 equal 1149 // 0 equal
1146 // 1 take local 1150 // 1 take local
1147 // 2 take remote 1151 // 2 take remote
1148 // 3 cancel 1152 // 3 cancel
1149 QDateTime lastSync = mLastCalendarSync; 1153 QDateTime lastSync = mLastCalendarSync;
1150 QDateTime localMod = local->lastModified(); 1154 QDateTime localMod = local->lastModified();
1151 QDateTime remoteMod = remote->lastModified(); 1155 QDateTime remoteMod = remote->lastModified();
1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1156 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1153 bool remCh, locCh; 1157 bool remCh, locCh;
1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1158 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1155 //if ( remCh ) 1159 //if ( remCh )
1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1160 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1157 locCh = ( localMod > mLastCalendarSync ); 1161 locCh = ( localMod > mLastCalendarSync );
1158 if ( !remCh && ! locCh ) { 1162 if ( !remCh && ! locCh ) {
1159 //qDebug("both not changed "); 1163 //qDebug("both not changed ");
1160 lastSync = localMod.addDays(1); 1164 lastSync = localMod.addDays(1);
1161 if ( mode <= SYNC_PREF_ASK ) 1165 if ( mode <= SYNC_PREF_ASK )
1162 return 0; 1166 return 0;
1163 } else { 1167 } else {
1164 if ( locCh ) { 1168 if ( locCh ) {
1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1169 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1166 lastSync = localMod.addDays( -1 ); 1170 lastSync = localMod.addDays( -1 );
1167 if ( !remCh ) 1171 if ( !remCh )
1168 remoteMod = ( lastSync.addDays( -1 ) ); 1172 remoteMod = ( lastSync.addDays( -1 ) );
1169 } else { 1173 } else {
1170 //qDebug(" not loc changed "); 1174 //qDebug(" not loc changed ");
1171 lastSync = localMod.addDays( 1 ); 1175 lastSync = localMod.addDays( 1 );
1172 if ( remCh ) 1176 if ( remCh )
1173 remoteMod =( lastSync.addDays( 1 ) ); 1177 remoteMod =( lastSync.addDays( 1 ) );
1174 1178
1175 } 1179 }
1176 } 1180 }
1177 full = true; 1181 full = true;
1178 if ( mode < SYNC_PREF_ASK ) 1182 if ( mode < SYNC_PREF_ASK )
1179 mode = SYNC_PREF_ASK; 1183 mode = SYNC_PREF_ASK;
1180 } else { 1184 } else {
1181 if ( localMod == remoteMod ) 1185 if ( localMod == remoteMod )
1182 // if ( local->revision() == remote->revision() ) 1186 // if ( local->revision() == remote->revision() )
1183 return 0; 1187 return 0;
1184 1188
1185 } 1189 }
1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1190 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1187 1191
1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1192 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1193 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1190 //full = true; //debug only 1194 //full = true; //debug only
1191 if ( full ) { 1195 if ( full ) {
1192 bool equ = false; 1196 bool equ = false;
1193 if ( local->typeID() == eventID ) { 1197 if ( local->typeID() == eventID ) {
1194 equ = (*((Event*) local) == *((Event*) remote)); 1198 equ = (*((Event*) local) == *((Event*) remote));
1195 } 1199 }
1196 else if ( local->typeID() == todoID ) 1200 else if ( local->typeID() == todoID )
1197 equ = (*((Todo*) local) == (*(Todo*) remote)); 1201 equ = (*((Todo*) local) == (*(Todo*) remote));
1198 else if ( local->typeID() == journalID ) 1202 else if ( local->typeID() == journalID )
1199 equ = (*((Journal*) local) == *((Journal*) remote)); 1203 equ = (*((Journal*) local) == *((Journal*) remote));
1200 if ( equ ) { 1204 if ( equ ) {
1201 //qDebug("equal "); 1205 //qDebug("equal ");
1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1206 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1207 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1204 } 1208 }
1205 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1209 if ( mode < SYNC_PREF_FORCE_LOCAL )
1206 return 0; 1210 return 0;
1207 1211
1208 }//else //debug only 1212 }//else //debug only
1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1213 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1210 } 1214 }
1211 int result; 1215 int result;
1212 bool localIsNew; 1216 bool localIsNew;
1213 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1217 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1214 1218
1215 1219
1216 // ************************************************ 1220 // ************************************************
1217 // ************************************************ 1221 // ************************************************
1218 // ************************************************ 1222 // ************************************************
1219 // We may have that lastSync > remoteMod AND lastSync > localMod 1223 // We may have that lastSync > remoteMod AND lastSync > localMod
1220 // BUT remoteMod != localMod 1224 // BUT remoteMod != localMod
1221 1225
1222 1226
1223 if ( full && mode < SYNC_PREF_NEWEST ) 1227 if ( full && mode < SYNC_PREF_NEWEST )
1224 mode = SYNC_PREF_ASK; 1228 mode = SYNC_PREF_ASK;
1225 1229
1226 switch( mode ) { 1230 switch( mode ) {
1227 case SYNC_PREF_LOCAL: 1231 case SYNC_PREF_LOCAL:
1228 if ( lastSync > remoteMod ) 1232 if ( lastSync > remoteMod )
1229 return 1; 1233 return 1;
1230 if ( lastSync > localMod ) 1234 if ( lastSync > localMod )
1231 return 2; 1235 return 2;
1232 return 1; 1236 return 1;
1233 break; 1237 break;
1234 case SYNC_PREF_REMOTE: 1238 case SYNC_PREF_REMOTE:
1235 if ( lastSync > localMod ) 1239 if ( lastSync > localMod )
1236 return 2; 1240 return 2;
1237 if ( lastSync > remoteMod ) 1241 if ( lastSync > remoteMod )
1238 return 1; 1242 return 1;
1239 return 2; 1243 return 2;
1240 break; 1244 break;
1241 case SYNC_PREF_NEWEST: 1245 case SYNC_PREF_NEWEST:
1242 if ( localMod >= remoteMod ) 1246 if ( localMod >= remoteMod )
1243 return 1; 1247 return 1;
1244 else 1248 else
1245 return 2; 1249 return 2;
1246 break; 1250 break;
1247 case SYNC_PREF_ASK: 1251 case SYNC_PREF_ASK:
1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1252 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1249 if ( lastSync > remoteMod && lastSync > localMod) 1253 if ( lastSync > remoteMod && lastSync > localMod)
1250 return 0; 1254 return 0;
1251 if ( lastSync > remoteMod ) 1255 if ( lastSync > remoteMod )
1252 return 1; 1256 return 1;
1253 if ( lastSync > localMod ) 1257 if ( lastSync > localMod )
1254 return 2; 1258 return 2;
1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1259 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1256 localIsNew = localMod >= remoteMod; 1260 localIsNew = localMod >= remoteMod;
1257 if ( localIsNew ) 1261 if ( localIsNew )
1258 getEventViewerDialog()->setColorMode( 1 ); 1262 getEventViewerDialog()->setColorMode( 1 );
1259 else 1263 else
1260 getEventViewerDialog()->setColorMode( 2 ); 1264 getEventViewerDialog()->setColorMode( 2 );
1261 getEventViewerDialog()->setIncidence(local); 1265 getEventViewerDialog()->setIncidence(local);
1262 if ( localIsNew ) 1266 if ( localIsNew )
1263 getEventViewerDialog()->setColorMode( 2 ); 1267 getEventViewerDialog()->setColorMode( 2 );
1264 else 1268 else
1265 getEventViewerDialog()->setColorMode( 1 ); 1269 getEventViewerDialog()->setColorMode( 1 );
1266 getEventViewerDialog()->addIncidence(remote); 1270 getEventViewerDialog()->addIncidence(remote);
1267 getEventViewerDialog()->setColorMode( 0 ); 1271 getEventViewerDialog()->setColorMode( 0 );
1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1272 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1273 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1270 getEventViewerDialog()->showMe(); 1274 getEventViewerDialog()->showMe();
1271 result = getEventViewerDialog()->executeS( localIsNew ); 1275 result = getEventViewerDialog()->executeS( localIsNew );
1272 return result; 1276 return result;
1273 1277
1274 break; 1278 break;
1275 case SYNC_PREF_FORCE_LOCAL: 1279 case SYNC_PREF_FORCE_LOCAL:
1276 return 1; 1280 return 1;
1277 break; 1281 break;
1278 case SYNC_PREF_FORCE_REMOTE: 1282 case SYNC_PREF_FORCE_REMOTE:
1279 return 2; 1283 return 2;
1280 break; 1284 break;
1281 1285
1282 default: 1286 default:
1283 // SYNC_PREF_TAKE_BOTH not implemented 1287 // SYNC_PREF_TAKE_BOTH not implemented
1284 break; 1288 break;
1285 } 1289 }
1286 return 0; 1290 return 0;
1287} 1291}
1288Event* CalendarView::getLastSyncEvent() 1292Event* CalendarView::getLastSyncEvent()
1289{ 1293{
1290 Event* lse; 1294 Event* lse;
1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1295 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1296 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1293 if (!lse) { 1297 if (!lse) {
1294 lse = new Event(); 1298 lse = new Event();
1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1299 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1296 QString sum = ""; 1300 QString sum = "";
1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1301 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1298 sum = "E: "; 1302 sum = "E: ";
1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1303 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1300 lse->setDtStart( mLastCalendarSync ); 1304 lse->setDtStart( mLastCalendarSync );
1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1305 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1302 lse->setCategories( i18n("SyncEvent") ); 1306 lse->setCategories( i18n("SyncEvent") );
1303 lse->setReadOnly( true ); 1307 lse->setReadOnly( true );
1304 mCalendar->addEvent( lse ); 1308 mCalendar->addEvent( lse );
1305 } 1309 }
1306 1310
1307 return lse; 1311 return lse;
1308 1312
1309} 1313}
1310 1314
1311// we check, if the to delete event has a id for a profile 1315// we check, if the to delete event has a id for a profile
1312// if yes, we set this id in the profile to delete 1316// if yes, we set this id in the profile to delete
1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1317void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1314{ 1318{
1315 if ( lastSync.count() == 0 ) { 1319 if ( lastSync.count() == 0 ) {
1316 //qDebug(" lastSync.count() == 0"); 1320 //qDebug(" lastSync.count() == 0");
1317 return; 1321 return;
1318 } 1322 }
1319 if ( toDelete->typeID() == journalID ) 1323 if ( toDelete->typeID() == journalID )
1320 return; 1324 return;
1321 1325
1322 Event* eve = lastSync.first(); 1326 Event* eve = lastSync.first();
1323 1327
1324 while ( eve ) { 1328 while ( eve ) {
1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1329 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1326 if ( !id.isEmpty() ) { 1330 if ( !id.isEmpty() ) {
1327 QString des = eve->description(); 1331 QString des = eve->description();
1328 QString pref = "e"; 1332 QString pref = "e";
1329 if ( toDelete->typeID() == todoID ) 1333 if ( toDelete->typeID() == todoID )
1330 pref = "t"; 1334 pref = "t";
1331 des += pref+ id + ","; 1335 des += pref+ id + ",";
1332 eve->setReadOnly( false ); 1336 eve->setReadOnly( false );
1333 eve->setDescription( des ); 1337 eve->setDescription( des );
1334 //qDebug("setdes %s ", des.latin1()); 1338 //qDebug("setdes %s ", des.latin1());
1335 eve->setReadOnly( true ); 1339 eve->setReadOnly( true );
1336 } 1340 }
1337 eve = lastSync.next(); 1341 eve = lastSync.next();
1338 } 1342 }
1339 1343
1340} 1344}
1341void CalendarView::checkExternalId( Incidence * inc ) 1345void CalendarView::checkExternalId( Incidence * inc )
1342{ 1346{
1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1347 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1344 checkExternSyncEvent( lastSync, inc ); 1348 checkExternSyncEvent( lastSync, inc );
1345 1349
1346} 1350}
1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1351bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1348{ 1352{
1349 bool syncOK = true; 1353 bool syncOK = true;
1350 int addedEvent = 0; 1354 int addedEvent = 0;
1351 int addedEventR = 0; 1355 int addedEventR = 0;
1352 int deletedEventR = 0; 1356 int deletedEventR = 0;
1353 int deletedEventL = 0; 1357 int deletedEventL = 0;
1354 int changedLocal = 0; 1358 int changedLocal = 0;
1355 int changedRemote = 0; 1359 int changedRemote = 0;
1356 int filteredIN = 0; 1360 int filteredIN = 0;
1357 int filteredOUT = 0; 1361 int filteredOUT = 0;
1358 //QPtrList<Event> el = local->rawEvents(); 1362 //QPtrList<Event> el = local->rawEvents();
1359 Event* eventR; 1363 Event* eventR;
1360 QString uid; 1364 QString uid;
1361 int take; 1365 int take;
1362 Event* eventRSync; 1366 Event* eventRSync;
1363 Event* eventLSync; 1367 Event* eventLSync;
1364 clearAllViews(); 1368 clearAllViews();
1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1369 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1370 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1367 bool fullDateRange = false; 1371 bool fullDateRange = false;
1368 local->resetTempSyncStat(); 1372 local->resetTempSyncStat();
1369 mLastCalendarSync = QDateTime::currentDateTime(); 1373 mLastCalendarSync = QDateTime::currentDateTime();
1370 if ( mSyncManager->syncWithDesktop() ) { 1374 if ( mSyncManager->syncWithDesktop() ) {
1371 remote->resetPilotStat(1); 1375 remote->resetPilotStat(1);
1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1376 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1377 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1378 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1375 } else { 1379 } else {
1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1380 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1377 } 1381 }
1378 } 1382 }
1379 QDateTime modifiedCalendar = mLastCalendarSync; 1383 QDateTime modifiedCalendar = mLastCalendarSync;
1380 eventLSync = getLastSyncEvent(); 1384 eventLSync = getLastSyncEvent();
1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1385 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1382 if ( eventR ) { 1386 if ( eventR ) {
1383 qDebug("last-syncEvent on remote found "); 1387 qDebug("last-syncEvent on remote found ");
1384 eventRSync = (Event*) eventR->clone(); 1388 eventRSync = (Event*) eventR->clone();
1385 remote->deleteEvent(eventR ); 1389 remote->deleteEvent(eventR );
1386 1390
1387 } else { 1391 } else {
1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1392 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1389 eventRSync = (Event*)eventLSync->clone(); 1393 eventRSync = (Event*)eventLSync->clone();
1390 } else { 1394 } else {
1391 fullDateRange = true; 1395 fullDateRange = true;
1392 eventRSync = new Event(); 1396 eventRSync = new Event();
1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1397 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1398 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1395 eventRSync->setDtStart( mLastCalendarSync ); 1399 eventRSync->setDtStart( mLastCalendarSync );
1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1400 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1397 eventRSync->setCategories( i18n("SyncEvent") ); 1401 eventRSync->setCategories( i18n("SyncEvent") );
1398 } 1402 }
1399 } 1403 }
1400 if ( eventLSync->dtStart() == mLastCalendarSync ) 1404 if ( eventLSync->dtStart() == mLastCalendarSync )
1401 fullDateRange = true; 1405 fullDateRange = true;
1402 1406
1403 if ( ! fullDateRange ) { 1407 if ( ! fullDateRange ) {
1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1408 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1405 1409
1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1410 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1411 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1408 fullDateRange = true; 1412 fullDateRange = true;
1409 } 1413 }
1410 } 1414 }
1411 if ( mSyncManager->syncWithDesktop() ) { 1415 if ( mSyncManager->syncWithDesktop() ) {
1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1416 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1413 } 1417 }
1414 if ( fullDateRange ) 1418 if ( fullDateRange )
1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1419 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1416 else 1420 else
1417 mLastCalendarSync = eventLSync->dtStart(); 1421 mLastCalendarSync = eventLSync->dtStart();
1418 // for resyncing if own file has changed 1422 // for resyncing if own file has changed
1419 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1423 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1420 mLastCalendarSync = loadedFileVersion; 1424 mLastCalendarSync = loadedFileVersion;
1421 //qDebug("setting mLastCalendarSync "); 1425 //qDebug("setting mLastCalendarSync ");
1422 } 1426 }
1423 //qDebug("*************************** "); 1427 //qDebug("*************************** ");
1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1428 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1425 QPtrList<Incidence> er = remote->rawIncidences(); 1429 QPtrList<Incidence> er = remote->rawIncidences();
1426 Incidence* inR = er.first(); 1430 Incidence* inR = er.first();
1427 Incidence* inL; 1431 Incidence* inL;
1428 QProgressBar bar( er.count(),0 ); 1432 QProgressBar bar( er.count(),0 );
1429 bar.setCaption (i18n("Syncing - close to abort!") ); 1433 bar.setCaption (i18n("Syncing - close to abort!") );
1430 1434
1431 // ************** setting up filter ************* 1435 // ************** setting up filter *************
1432 CalFilter *filterIN = 0; 1436 CalFilter *filterIN = 0;
1433 CalFilter *filterOUT = 0; 1437 CalFilter *filterOUT = 0;
1434 CalFilter *filter = mFilters.first(); 1438 CalFilter *filter = mFilters.first();
1435 while(filter) { 1439 while(filter) {
1436 if ( filter->name() == mSyncManager->mFilterInCal ) 1440 if ( filter->name() == mSyncManager->mFilterInCal )
1437 filterIN = filter; 1441 filterIN = filter;
1438 if ( filter->name() == mSyncManager->mFilterOutCal ) 1442 if ( filter->name() == mSyncManager->mFilterOutCal )
1439 filterOUT = filter; 1443 filterOUT = filter;
1440 filter = mFilters.next(); 1444 filter = mFilters.next();
1441 } 1445 }
1442 int w = 300; 1446 int w = 300;
1443 if ( QApplication::desktop()->width() < 320 ) 1447 if ( QApplication::desktop()->width() < 320 )
1444 w = 220; 1448 w = 220;
1445 int h = bar.sizeHint().height() ; 1449 int h = bar.sizeHint().height() ;
1446 int dw = QApplication::desktop()->width(); 1450 int dw = QApplication::desktop()->width();
1447 int dh = QApplication::desktop()->height(); 1451 int dh = QApplication::desktop()->height();
1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1452 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1449 bar.show(); 1453 bar.show();
1450 int modulo = (er.count()/10)+1; 1454 int modulo = (er.count()/10)+1;
1451 int incCounter = 0; 1455 int incCounter = 0;
1452 while ( inR ) { 1456 while ( inR ) {
1453 if ( ! bar.isVisible() ) 1457 if ( ! bar.isVisible() )
1454 return false; 1458 return false;
1455 if ( incCounter % modulo == 0 ) 1459 if ( incCounter % modulo == 0 )
1456 bar.setProgress( incCounter ); 1460 bar.setProgress( incCounter );
1457 ++incCounter; 1461 ++incCounter;
1458 uid = inR->uid(); 1462 uid = inR->uid();
1459 bool skipIncidence = false; 1463 bool skipIncidence = false;
1460 if ( uid.left(15) == QString("last-syncEvent-") ) 1464 if ( uid.left(15) == QString("last-syncEvent-") )
1461 skipIncidence = true; 1465 skipIncidence = true;
1462 QString idS; 1466 QString idS;
1463 qApp->processEvents(); 1467 qApp->processEvents();
1464 if ( !skipIncidence ) { 1468 if ( !skipIncidence ) {
1465 inL = local->incidenceForUid( uid , false ); 1469 inL = local->incidenceForUid( uid , false );
1466 if ( inL ) { // maybe conflict - same uid in both calendars 1470 if ( inL ) { // maybe conflict - same uid in both calendars
1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1471 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1468 //qDebug("take %d %s ", take, inL->summary().latin1()); 1472 //qDebug("take %d %s ", take, inL->summary().latin1());
1469 if ( take == 3 ) 1473 if ( take == 3 )
1470 return false; 1474 return false;
1471 if ( take == 1 ) {// take local ********************** 1475 if ( take == 1 ) {// take local **********************
1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1476 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1477 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1474 else 1478 else
1475 idS = inR->IDStr(); 1479 idS = inR->IDStr();
1476 int calID = inR->calID(); 1480 int calID = inR->calID();
1477 remote->deleteIncidence( inR ); 1481 remote->deleteIncidence( inR );
1478 inR = inL->clone(); 1482 inR = inL->clone();
1479 inR->setCalID( calID ); 1483 inR->setCalID( calID );
1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1484 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1485 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1482 inR->setIDStr( idS ); 1486 inR->setIDStr( idS );
1483 remote->addIncidence( inR ); 1487 remote->addIncidence( inR );
1484 if ( mSyncManager->syncWithDesktop() ) 1488 if ( mSyncManager->syncWithDesktop() )
1485 inR->setPilotId( 2 ); 1489 inR->setPilotId( 2 );
1486 ++changedRemote; 1490 ++changedRemote;
1487 } else {// take remote ********************** 1491 } else {// take remote **********************
1488 if ( !inL->isReadOnly() ) { 1492 if ( !inL->isReadOnly() ) {
1489 idS = inL->IDStr(); 1493 idS = inL->IDStr();
1490 int pid = inL->pilotId(); 1494 int pid = inL->pilotId();
1491 int calID = inL->calID(); 1495 int calID = inL->calID();
1492 local->deleteIncidence( inL ); 1496 local->deleteIncidence( inL );
1493 inL = inR->clone(); 1497 inL = inR->clone();
1494 inL->setCalID( calID ); 1498 inL->setCalID( calID );
1495 if ( mSyncManager->syncWithDesktop() ) 1499 if ( mSyncManager->syncWithDesktop() )
1496 inL->setPilotId( pid ); 1500 inL->setPilotId( pid );
1497 inL->setIDStr( idS ); 1501 inL->setIDStr( idS );
1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1502 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1503 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1504 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1501 } 1505 }
1502 local->addIncidence( inL ); 1506 local->addIncidence( inL );
1503 ++changedLocal; 1507 ++changedLocal;
1504 } 1508 }
1505 } 1509 }
1506 } 1510 }
1507 } else { // no conflict ********** add or delete remote 1511 } else { // no conflict ********** add or delete remote
1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1512 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1513 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1510 QString des = eventLSync->description(); 1514 QString des = eventLSync->description();
1511 QString pref = "e"; 1515 QString pref = "e";
1512 if ( inR->typeID() == todoID ) 1516 if ( inR->typeID() == todoID )
1513 pref = "t"; 1517 pref = "t";
1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1518 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1519 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1516 //remote->deleteIncidence( inR ); 1520 //remote->deleteIncidence( inR );
1517 ++deletedEventR; 1521 ++deletedEventR;
1518 } else { 1522 } else {
1519 inR->setLastModified( modifiedCalendar ); 1523 inR->setLastModified( modifiedCalendar );
1520 inL = inR->clone(); 1524 inL = inR->clone();
1521 inL->setIDStr( ":" ); 1525 inL->setIDStr( ":" );
1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1526 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1527 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1524 1528
1525 inL->setCalID( 0 );// add to default cal 1529 inL->setCalID( 0 );// add to default cal
1526 local->addIncidence( inL ); 1530 local->addIncidence( inL );
1527 ++addedEvent; 1531 ++addedEvent;
1528 1532
1529 } 1533 }
1530 } else { 1534 } else {
1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1535 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1532 inR->setLastModified( modifiedCalendar ); 1536 inR->setLastModified( modifiedCalendar );
1533 inL = inR->clone(); 1537 inL = inR->clone();
1534 inL->setIDStr( ":" ); 1538 inL->setIDStr( ":" );
1535 inL->setCalID( 0 );// add to default cal 1539 inL->setCalID( 0 );// add to default cal
1536 local->addIncidence( inL ); 1540 local->addIncidence( inL );
1537 ++addedEvent; 1541 ++addedEvent;
1538 1542
1539 } else { 1543 } else {
1540 checkExternSyncEvent(eventRSyncSharp, inR); 1544 checkExternSyncEvent(eventRSyncSharp, inR);
1541 remote->deleteIncidence( inR ); 1545 remote->deleteIncidence( inR );
1542 ++deletedEventR; 1546 ++deletedEventR;
1543 } 1547 }
1544 } 1548 }
1545 } else { 1549 } else {
1546 ++filteredIN; 1550 ++filteredIN;
1547 } 1551 }
1548 } 1552 }
1549 } 1553 }
1550 inR = er.next(); 1554 inR = er.next();
1551 } 1555 }
1552 QPtrList<Incidence> el = local->rawIncidences(); 1556 QPtrList<Incidence> el = local->rawIncidences();
1553 inL = el.first(); 1557 inL = el.first();
1554 modulo = (el.count()/10)+1; 1558 modulo = (el.count()/10)+1;
1555 bar.setCaption (i18n("Add / remove events") ); 1559 bar.setCaption (i18n("Add / remove events") );
1556 bar.setTotalSteps ( el.count() ) ; 1560 bar.setTotalSteps ( el.count() ) ;
1557 bar.show(); 1561 bar.show();
1558 incCounter = 0; 1562 incCounter = 0;
1559 1563
1560 while ( inL ) { 1564 while ( inL ) {
1561 1565
1562 qApp->processEvents(); 1566 qApp->processEvents();
1563 if ( ! bar.isVisible() ) 1567 if ( ! bar.isVisible() )
1564 return false; 1568 return false;
1565 if ( incCounter % modulo == 0 ) 1569 if ( incCounter % modulo == 0 )
1566 bar.setProgress( incCounter ); 1570 bar.setProgress( incCounter );
1567 ++incCounter; 1571 ++incCounter;
1568 uid = inL->uid(); 1572 uid = inL->uid();
1569 bool skipIncidence = false; 1573 bool skipIncidence = false;
1570 if ( uid.left(15) == QString("last-syncEvent-") ) 1574 if ( uid.left(15) == QString("last-syncEvent-") )
1571 skipIncidence = true; 1575 skipIncidence = true;
1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1576 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1573 skipIncidence = true; 1577 skipIncidence = true;
1574 if ( !skipIncidence ) { 1578 if ( !skipIncidence ) {
1575 inR = remote->incidenceForUid( uid , true ); 1579 inR = remote->incidenceForUid( uid , true );
1576 if ( ! inR ) { 1580 if ( ! inR ) {
1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1581 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1578 // no conflict ********** add or delete local 1582 // no conflict ********** add or delete local
1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1583 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1584 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1581 checkExternSyncEvent(eventLSyncSharp, inL); 1585 checkExternSyncEvent(eventLSyncSharp, inL);
1582 local->deleteIncidence( inL ); 1586 local->deleteIncidence( inL );
1583 ++deletedEventL; 1587 ++deletedEventL;
1584 } else { 1588 } else {
1585 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1589 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1586 inL->removeID(mCurrentSyncDevice ); 1590 inL->removeID(mCurrentSyncDevice );
1587 ++addedEventR; 1591 ++addedEventR;
1588 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1592 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1589 inL->setLastModified( modifiedCalendar ); 1593 inL->setLastModified( modifiedCalendar );
1590 inR = inL->clone(); 1594 inR = inL->clone();
1591 inR->setIDStr( ":" ); 1595 inR->setIDStr( ":" );
1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1596 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1593 inR->setCalID( 0 );// add to default cal 1597 inR->setCalID( 0 );// add to default cal
1594 remote->addIncidence( inR ); 1598 remote->addIncidence( inR );
1595 } 1599 }
1596 } 1600 }
1597 } else { 1601 } else {
1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1602 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1599 checkExternSyncEvent(eventLSyncSharp, inL); 1603 checkExternSyncEvent(eventLSyncSharp, inL);
1600 local->deleteIncidence( inL ); 1604 local->deleteIncidence( inL );
1601 ++deletedEventL; 1605 ++deletedEventL;
1602 } else { 1606 } else {
1603 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1607 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1604 ++addedEventR; 1608 ++addedEventR;
1605 inL->setLastModified( modifiedCalendar ); 1609 inL->setLastModified( modifiedCalendar );
1606 inR = inL->clone(); 1610 inR = inL->clone();
1607 inR->setIDStr( ":" ); 1611 inR->setIDStr( ":" );
1608 inR->setCalID( 0 );// add to default cal 1612 inR->setCalID( 0 );// add to default cal
1609 remote->addIncidence( inR ); 1613 remote->addIncidence( inR );
1610 } 1614 }
1611 } 1615 }
1612 } 1616 }
1613 } else { 1617 } else {
1614 ++filteredOUT; 1618 ++filteredOUT;
1615 } 1619 }
1616 } 1620 }
1617 } 1621 }
1618 inL = el.next(); 1622 inL = el.next();
1619 } 1623 }
1620 int delFut = 0; 1624 int delFut = 0;
1621 int remRem = 0; 1625 int remRem = 0;
1622 if ( mSyncManager->mWriteBackInFuture ) { 1626 if ( mSyncManager->mWriteBackInFuture ) {
1623 er = remote->rawIncidences(); 1627 er = remote->rawIncidences();
1624 remRem = er.count(); 1628 remRem = er.count();
1625 inR = er.first(); 1629 inR = er.first();
1626 QDateTime dt; 1630 QDateTime dt;
1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1631 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1632 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1629 while ( inR ) { 1633 while ( inR ) {
1630 if ( inR->typeID() == todoID ) { 1634 if ( inR->typeID() == todoID ) {
1631 Todo * t = (Todo*)inR; 1635 Todo * t = (Todo*)inR;
1632 if ( t->hasDueDate() ) 1636 if ( t->hasDueDate() )
1633 dt = t->dtDue(); 1637 dt = t->dtDue();
1634 else 1638 else
1635 dt = cur.addSecs( 62 ); 1639 dt = cur.addSecs( 62 );
1636 } 1640 }
1637 else if (inR->typeID() == eventID ) { 1641 else if (inR->typeID() == eventID ) {
1638 bool ok; 1642 bool ok;
1639 dt = inR->getNextOccurence( cur, &ok ); 1643 dt = inR->getNextOccurence( cur, &ok );
1640 if ( !ok ) 1644 if ( !ok )
1641 dt = cur.addSecs( -62 ); 1645 dt = cur.addSecs( -62 );
1642 } 1646 }
1643 else 1647 else
1644 dt = inR->dtStart(); 1648 dt = inR->dtStart();
1645 if ( dt < cur || dt > end ) { 1649 if ( dt < cur || dt > end ) {
1646 remote->deleteIncidence( inR ); 1650 remote->deleteIncidence( inR );
1647 ++delFut; 1651 ++delFut;
1648 } 1652 }
1649 inR = er.next(); 1653 inR = er.next();
1650 } 1654 }
1651 } 1655 }
1652 bar.hide(); 1656 bar.hide();
1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1657 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1654 eventLSync->setReadOnly( false ); 1658 eventLSync->setReadOnly( false );
1655 eventLSync->setDtStart( mLastCalendarSync ); 1659 eventLSync->setDtStart( mLastCalendarSync );
1656 eventRSync->setDtStart( mLastCalendarSync ); 1660 eventRSync->setDtStart( mLastCalendarSync );
1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1661 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1662 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1663 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1664 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1661 eventLSync->setReadOnly( true ); 1665 eventLSync->setReadOnly( true );
1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1666 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1667 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1664 remote->addEvent( eventRSync ); 1668 remote->addEvent( eventRSync );
1665 else 1669 else
1666 delete eventRSync; 1670 delete eventRSync;
1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1671 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1668 QString mes; 1672 QString mes;
1669 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1673 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1670 QString delmess; 1674 QString delmess;
1671 if ( delFut ) { 1675 if ( delFut ) {
1672 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1676 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1673 mes += delmess; 1677 mes += delmess;
1674 } 1678 }
1675 mes = i18n("Local calendar changed!\n") +mes; 1679 mes = i18n("Local calendar changed!\n") +mes;
1676 mCalendar->checkAlarmForIncidence( 0, true ); 1680 mCalendar->checkAlarmForIncidence( 0, true );
1677 qDebug( mes ); 1681 qDebug( mes );
1678 if ( mSyncManager->mShowSyncSummary ) { 1682 if ( mSyncManager->mShowSyncSummary ) {
1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1683 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1684 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1681 qDebug("KO: WB cancelled "); 1685 qDebug("KO: WB cancelled ");
1682 mSyncManager->mWriteBackFile = false; 1686 mSyncManager->mWriteBackFile = false;
1683 return syncOK; 1687 return syncOK;
1684 } 1688 }
1685 } 1689 }
1686 return syncOK; 1690 return syncOK;
1687} 1691}
1688 1692
1689void CalendarView::setSyncDevice( QString s ) 1693void CalendarView::setSyncDevice( QString s )
1690{ 1694{
1691 mCurrentSyncDevice= s; 1695 mCurrentSyncDevice= s;
1692} 1696}
1693void CalendarView::setSyncName( QString s ) 1697void CalendarView::setSyncName( QString s )
1694{ 1698{
1695 mCurrentSyncName= s; 1699 mCurrentSyncName= s;
1696} 1700}
1697bool CalendarView::syncCalendar(QString filename, int mode) 1701bool CalendarView::syncCalendar(QString filename, int mode)
1698{ 1702{
1699 //qDebug("syncCalendar %s ", filename.latin1()); 1703 //qDebug("syncCalendar %s ", filename.latin1());
1700 mGlobalSyncMode = SYNC_MODE_NORMAL; 1704 mGlobalSyncMode = SYNC_MODE_NORMAL;
1701 CalendarLocal* calendar = new CalendarLocal(); 1705 CalendarLocal* calendar = new CalendarLocal();
1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1706 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1703 FileStorage* storage = new FileStorage( calendar ); 1707 FileStorage* storage = new FileStorage( calendar );
1704 bool syncOK = false; 1708 bool syncOK = false;
1705 storage->setFileName( filename ); 1709 storage->setFileName( filename );
1706 // qDebug("loading ... "); 1710 // qDebug("loading ... ");
1707 if ( storage->load() ) { 1711 if ( storage->load() ) {
1708 getEventViewerDialog()->setSyncMode( true ); 1712 getEventViewerDialog()->setSyncMode( true );
1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1713 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1710 getEventViewerDialog()->setSyncMode( false ); 1714 getEventViewerDialog()->setSyncMode( false );
1711 if ( syncOK ) { 1715 if ( syncOK ) {
1712 if ( mSyncManager->mWriteBackFile ) 1716 if ( mSyncManager->mWriteBackFile )
1713 { 1717 {
1714 storage->setSaveFormat( new ICalFormat() ); 1718 storage->setSaveFormat( new ICalFormat() );
1715 storage->save(); 1719 storage->save();
1716 } 1720 }
1717 } 1721 }
1718 setModified( true ); 1722 setModified( true );
1719 } 1723 }
1720 delete storage; 1724 delete storage;
1721 delete calendar; 1725 delete calendar;
1722 if ( syncOK ) 1726 if ( syncOK )
1723 updateView(); 1727 updateView();
1724 return syncOK; 1728 return syncOK;
1725} 1729}
1726 1730
1727void CalendarView::syncExternal( int mode ) 1731void CalendarView::syncExternal( int mode )
1728{ 1732{
1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1733 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1730 1734
1731 qApp->processEvents(); 1735 qApp->processEvents();
1732 CalendarLocal* calendar = new CalendarLocal(); 1736 CalendarLocal* calendar = new CalendarLocal();
1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1737 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1734 bool syncOK = false; 1738 bool syncOK = false;
1735 bool loadSuccess = false; 1739 bool loadSuccess = false;
1736 PhoneFormat* phoneFormat = 0; 1740 PhoneFormat* phoneFormat = 0;
1737 emit tempDisableBR(true); 1741 emit tempDisableBR(true);
1738#ifndef DESKTOP_VERSION 1742#ifndef DESKTOP_VERSION
1739 SharpFormat* sharpFormat = 0; 1743 SharpFormat* sharpFormat = 0;
1740 if ( mode == 0 ) { // sharp 1744 if ( mode == 0 ) { // sharp
1741 sharpFormat = new SharpFormat () ; 1745 sharpFormat = new SharpFormat () ;
1742 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1746 loadSuccess = sharpFormat->load( calendar, mCalendar );
1743 1747
1744 } else 1748 } else
1745#endif 1749#endif
1746 if ( mode == 1 ) { // phone 1750 if ( mode == 1 ) { // phone
1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1751 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1748 mSyncManager->mPhoneDevice, 1752 mSyncManager->mPhoneDevice,
1749 mSyncManager->mPhoneConnection, 1753 mSyncManager->mPhoneConnection,
1750 mSyncManager->mPhoneModel); 1754 mSyncManager->mPhoneModel);
1751 loadSuccess = phoneFormat->load( calendar,mCalendar); 1755 loadSuccess = phoneFormat->load( calendar,mCalendar);
1752 1756
1753 } else { 1757 } else {
1754 emit tempDisableBR(false); 1758 emit tempDisableBR(false);
1755 return; 1759 return;
1756 } 1760 }
1757 if ( loadSuccess ) { 1761 if ( loadSuccess ) {
1758 getEventViewerDialog()->setSyncMode( true ); 1762 getEventViewerDialog()->setSyncMode( true );
1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1763 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1760 getEventViewerDialog()->setSyncMode( false ); 1764 getEventViewerDialog()->setSyncMode( false );
1761 qApp->processEvents(); 1765 qApp->processEvents();
1762 if ( syncOK ) { 1766 if ( syncOK ) {
1763 if ( mSyncManager->mWriteBackFile ) 1767 if ( mSyncManager->mWriteBackFile )
1764 { 1768 {
1765 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1769 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1766 Incidence* inc = iL.first(); 1770 Incidence* inc = iL.first();
1767 if ( phoneFormat ) { 1771 if ( phoneFormat ) {
1768 while ( inc ) { 1772 while ( inc ) {
1769 inc->removeID(mCurrentSyncDevice); 1773 inc->removeID(mCurrentSyncDevice);
1770 inc = iL.next(); 1774 inc = iL.next();
1771 } 1775 }
1772 } 1776 }
1773#ifndef DESKTOP_VERSION 1777#ifndef DESKTOP_VERSION
1774 if ( sharpFormat ) 1778 if ( sharpFormat )
1775 sharpFormat->save(calendar); 1779 sharpFormat->save(calendar);
1776#endif 1780#endif
1777 if ( phoneFormat ) 1781 if ( phoneFormat )
1778 phoneFormat->save(calendar); 1782 phoneFormat->save(calendar);
1779 iL = calendar->rawIncidences(); 1783 iL = calendar->rawIncidences();
1780 inc = iL.first(); 1784 inc = iL.first();
1781 Incidence* loc; 1785 Incidence* loc;
1782 while ( inc ) { 1786 while ( inc ) {
1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1787 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1784 loc = mCalendar->incidence(inc->uid() ); 1788 loc = mCalendar->incidence(inc->uid() );
1785 if ( loc ) { 1789 if ( loc ) {
1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1790 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1791 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1788 } 1792 }
1789 } 1793 }
1790 inc = iL.next(); 1794 inc = iL.next();
1791 } 1795 }
1792 Incidence* lse = getLastSyncEvent(); 1796 Incidence* lse = getLastSyncEvent();
1793 if ( lse ) { 1797 if ( lse ) {
1794 lse->setReadOnly( false ); 1798 lse->setReadOnly( false );
1795 lse->setDescription( "" ); 1799 lse->setDescription( "" );
1796 lse->setReadOnly( true ); 1800 lse->setReadOnly( true );
1797 } 1801 }
1798 } 1802 }
1799 } else { 1803 } else {
1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1804 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1801 } 1805 }
1802 setModified( true ); 1806 setModified( true );
1803 } else { 1807 } else {
1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1808 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1809 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1806 question, i18n("Ok")) ; 1810 question, i18n("Ok")) ;
1807 1811
1808 } 1812 }
1809 delete calendar; 1813 delete calendar;
1810 updateView(); 1814 updateView();
1811 emit tempDisableBR(false); 1815 emit tempDisableBR(false);
1812 return ;//syncOK; 1816 return ;//syncOK;
1813 1817
1814} 1818}
1815 1819
1816bool CalendarView::importBday() 1820bool CalendarView::importBday()
1817{ 1821{
1818#ifndef KORG_NOKABC 1822#ifndef KORG_NOKABC
1819 1823
1820#ifdef DESKTOP_VERSION 1824#ifdef DESKTOP_VERSION
1821 int curCal = mCalendar->defaultCalendar(); 1825 int curCal = mCalendar->defaultCalendar();
1822 int bd = mCalEditView->getBirtdayID(); 1826 int bd = mCalEditView->getBirtdayID();
1823 if ( bd == 0 ) 1827 if ( bd == 0 )
1824 return false; 1828 return false;
1825 mCalendar->setDefaultCalendar( bd ); 1829 mCalendar->setDefaultCalendar( bd );
1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1830 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1827 KABC::AddressBook::Iterator it; 1831 KABC::AddressBook::Iterator it;
1828 int count = 0; 1832 int count = 0;
1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1833 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1830 ++count; 1834 ++count;
1831 } 1835 }
1832 QProgressBar bar(count,0 ); 1836 QProgressBar bar(count,0 );
1833 int w = 300; 1837 int w = 300;
1834 if ( QApplication::desktop()->width() < 320 ) 1838 if ( QApplication::desktop()->width() < 320 )
1835 w = 220; 1839 w = 220;
1836 int h = bar.sizeHint().height() ; 1840 int h = bar.sizeHint().height() ;
1837 int dw = QApplication::desktop()->width(); 1841 int dw = QApplication::desktop()->width();
1838 int dh = QApplication::desktop()->height(); 1842 int dh = QApplication::desktop()->height();
1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1843 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1840 bar.show(); 1844 bar.show();
1841 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1845 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1842 qApp->processEvents(); 1846 qApp->processEvents();
1843 count = 0; 1847 count = 0;
1844 int addCount = 0; 1848 int addCount = 0;
1845 KCal::Attendee* a = 0; 1849 KCal::Attendee* a = 0;
1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1850 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1847 if ( ! bar.isVisible() ) 1851 if ( ! bar.isVisible() )
1848 return false; 1852 return false;
1849 bar.setProgress( count++ ); 1853 bar.setProgress( count++ );
1850 qApp->processEvents(); 1854 qApp->processEvents();
1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1855 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1852 if ( (*it).birthday().date().isValid() ){ 1856 if ( (*it).birthday().date().isValid() ){
1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1857 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1858 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1855 ++addCount; 1859 ++addCount;
1856 } 1860 }
1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1861 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1858 if ( anni.isValid() ){ 1862 if ( anni.isValid() ){
1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1863 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1864 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1861 ++addCount; 1865 ++addCount;
1862 } 1866 }
1863 } 1867 }
1864 mCalendar->setDefaultCalendar( curCal ); 1868 mCalendar->setDefaultCalendar( curCal );